Rev Author Line No. Line
3471 miho 1 /*
2 * usbasp.c - part of USBasp
3 *
4 * Autor..........: Thomas Fischl <tfischl@gmx.de>
5 * Description....: Definitions and macros for usbasp
6 * Licence........: GNU GPL v2 (see Readme.txt)
7 * Creation Date..: 2009-02-28
8 * Last change....: 2009-02-28
9 */
10  
11 #ifndef USBASP_H_
12 #define USBASP_H_
13  
3472 miho 14 /* PORTS Definitions */
15 #define LED_RED_PORT C
16 #define LED_RED_BIT 0
17 #define LED_GREEN_PORT C
18 #define LED_GREEN_BIT 1
19 #define CLKSW_PORT D
20 #define CLKSW_BIT 0
21 #define PORTB_UNUSED_MASK (1<<PB1 | 1<<PB0)
22 #define PORTC_UNUSED_MASK (1<<PC5 | 1<<PC4 | 1<<PC3 | 1<<PC2)
23 #define PORTD_UNUSED_MASK (1<<PD7 | 1<<PD6 | 1<<PD5 | 1<<PD3 | 1<<PD1)
24  
3471 miho 25 /* USB function call identifiers */
26 #define USBASP_FUNC_CONNECT 1
27 #define USBASP_FUNC_DISCONNECT 2
28 #define USBASP_FUNC_TRANSMIT 3
29 #define USBASP_FUNC_READFLASH 4
30 #define USBASP_FUNC_ENABLEPROG 5
31 #define USBASP_FUNC_WRITEFLASH 6
32 #define USBASP_FUNC_READEEPROM 7
33 #define USBASP_FUNC_WRITEEEPROM 8
34 #define USBASP_FUNC_SETLONGADDRESS 9
35 #define USBASP_FUNC_SETISPSCK 10
36 #define USBASP_FUNC_TPI_CONNECT 11
37 #define USBASP_FUNC_TPI_DISCONNECT 12
38 #define USBASP_FUNC_TPI_RAWREAD 13
39 #define USBASP_FUNC_TPI_RAWWRITE 14
40 #define USBASP_FUNC_TPI_READBLOCK 15
41 #define USBASP_FUNC_TPI_WRITEBLOCK 16
42 #define USBASP_FUNC_GETCAPABILITIES 127
43  
44 /* USBASP capabilities */
45 #define USBASP_CAP_0_TPI 0x01
46  
47 /* programming state */
48 #define PROG_STATE_IDLE 0
49 #define PROG_STATE_WRITEFLASH 1
50 #define PROG_STATE_READFLASH 2
51 #define PROG_STATE_READEEPROM 3
52 #define PROG_STATE_WRITEEEPROM 4
53 #define PROG_STATE_TPI_READ 5
54 #define PROG_STATE_TPI_WRITE 6
55  
56 /* Block mode flags */
57 #define PROG_BLOCKFLAG_FIRST 1
58 #define PROG_BLOCKFLAG_LAST 2
59  
60 /* ISP SCK speed identifiers */
61 #define USBASP_ISP_SCK_AUTO 0
62 #define USBASP_ISP_SCK_0_5 1 /* 500 Hz */
63 #define USBASP_ISP_SCK_1 2 /* 1 kHz */
64 #define USBASP_ISP_SCK_2 3 /* 2 kHz */
65 #define USBASP_ISP_SCK_4 4 /* 4 kHz */
66 #define USBASP_ISP_SCK_8 5 /* 8 kHz */
67 #define USBASP_ISP_SCK_16 6 /* 16 kHz */
68 #define USBASP_ISP_SCK_32 7 /* 32 kHz */
69 #define USBASP_ISP_SCK_93_75 8 /* 93.75 kHz */
70 #define USBASP_ISP_SCK_187_5 9 /* 187.5 kHz */
71 #define USBASP_ISP_SCK_375 10 /* 375 kHz */
72 #define USBASP_ISP_SCK_750 11 /* 750 kHz */
73 #define USBASP_ISP_SCK_1500 12 /* 1.5 MHz */
74  
3472 miho 75 /* Macros for Port (enables to easily define IO signals) */
76 #define GLUE(A,B) A##B
77 #define DDR(PORT_LETTER) GLUE(DDR, PORT_LETTER) // Makes DDRC from DDR(C) etc.
78 #define PORT(PORT_LETTER) GLUE(PORT,PORT_LETTER) // Makes PORTC from PORT(C)
79 #define PIN(PORT_LETTER) GLUE(PIN, PORT_LETTER) // Makes PINC from PIN(C)
80  
3471 miho 81 /* macros for gpio functions */
3472 miho 82 #define ledRedOn() PORT(LED_RED_PORT) &= ~(1 << LED_RED_BIT) // Active L
83 #define ledRedOff() PORT(LED_RED_PORT) |= (1 << LED_RED_BIT)
84 #define ledGreenOn() PORT(LED_GREEN_PORT) &= ~(1 << LED_GREEN_BIT) // Active L
85 #define ledGreenOff() PORT(LED_GREEN_PORT) |= (1 << LED_GREEN_BIT)
86 #define ledInit() DDR(LED_RED_PORT) |= (1 << LED_RED_BIT),\
87 DDR(LED_GREEN_PORT) |= (1 << LED_GREEN_BIT) // Outputs
88 #define clkswInit() DDR(CLKSW_PORT) &= ~(1 << CLKSW_BIT),\
89 PORT(CLKSW_PORT) |= (1 << CLKSW_BIT) // Input with PullUp
3471 miho 90  
91 #endif /* USBASP_H_ */