Rev 3471 Rev 3472
1 /* 1 /*
2 * usbasp.c - part of USBasp 2 * usbasp.c - part of USBasp
3 * 3 *
4 * Autor..........: Thomas Fischl <tfischl@gmx.de> 4 * Autor..........: Thomas Fischl <tfischl@gmx.de>
5 * Description....: Definitions and macros for usbasp 5 * Description....: Definitions and macros for usbasp
6 * Licence........: GNU GPL v2 (see Readme.txt) 6 * Licence........: GNU GPL v2 (see Readme.txt)
7 * Creation Date..: 2009-02-28 7 * Creation Date..: 2009-02-28
8 * Last change....: 2009-02-28 8 * Last change....: 2009-02-28
9 */ 9 */
10   10  
11 #ifndef USBASP_H_ 11 #ifndef USBASP_H_
12 #define USBASP_H_ 12 #define USBASP_H_
13   13  
-   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  
14 /* USB function call identifiers */ 25 /* USB function call identifiers */
15 #define USBASP_FUNC_CONNECT 1 26 #define USBASP_FUNC_CONNECT 1
16 #define USBASP_FUNC_DISCONNECT 2 27 #define USBASP_FUNC_DISCONNECT 2
17 #define USBASP_FUNC_TRANSMIT 3 28 #define USBASP_FUNC_TRANSMIT 3
18 #define USBASP_FUNC_READFLASH 4 29 #define USBASP_FUNC_READFLASH 4
19 #define USBASP_FUNC_ENABLEPROG 5 30 #define USBASP_FUNC_ENABLEPROG 5
20 #define USBASP_FUNC_WRITEFLASH 6 31 #define USBASP_FUNC_WRITEFLASH 6
21 #define USBASP_FUNC_READEEPROM 7 32 #define USBASP_FUNC_READEEPROM 7
22 #define USBASP_FUNC_WRITEEEPROM 8 33 #define USBASP_FUNC_WRITEEEPROM 8
23 #define USBASP_FUNC_SETLONGADDRESS 9 34 #define USBASP_FUNC_SETLONGADDRESS 9
24 #define USBASP_FUNC_SETISPSCK 10 35 #define USBASP_FUNC_SETISPSCK 10
25 #define USBASP_FUNC_TPI_CONNECT 11 36 #define USBASP_FUNC_TPI_CONNECT 11
26 #define USBASP_FUNC_TPI_DISCONNECT 12 37 #define USBASP_FUNC_TPI_DISCONNECT 12
27 #define USBASP_FUNC_TPI_RAWREAD 13 38 #define USBASP_FUNC_TPI_RAWREAD 13
28 #define USBASP_FUNC_TPI_RAWWRITE 14 39 #define USBASP_FUNC_TPI_RAWWRITE 14
29 #define USBASP_FUNC_TPI_READBLOCK 15 40 #define USBASP_FUNC_TPI_READBLOCK 15
30 #define USBASP_FUNC_TPI_WRITEBLOCK 16 41 #define USBASP_FUNC_TPI_WRITEBLOCK 16
31 #define USBASP_FUNC_GETCAPABILITIES 127 42 #define USBASP_FUNC_GETCAPABILITIES 127
32   43  
33 /* USBASP capabilities */ 44 /* USBASP capabilities */
34 #define USBASP_CAP_0_TPI 0x01 45 #define USBASP_CAP_0_TPI 0x01
35   46  
36 /* programming state */ 47 /* programming state */
37 #define PROG_STATE_IDLE 0 48 #define PROG_STATE_IDLE 0
38 #define PROG_STATE_WRITEFLASH 1 49 #define PROG_STATE_WRITEFLASH 1
39 #define PROG_STATE_READFLASH 2 50 #define PROG_STATE_READFLASH 2
40 #define PROG_STATE_READEEPROM 3 51 #define PROG_STATE_READEEPROM 3
41 #define PROG_STATE_WRITEEEPROM 4 52 #define PROG_STATE_WRITEEEPROM 4
42 #define PROG_STATE_TPI_READ 5 53 #define PROG_STATE_TPI_READ 5
43 #define PROG_STATE_TPI_WRITE 6 54 #define PROG_STATE_TPI_WRITE 6
44   55  
45 /* Block mode flags */ 56 /* Block mode flags */
46 #define PROG_BLOCKFLAG_FIRST 1 57 #define PROG_BLOCKFLAG_FIRST 1
47 #define PROG_BLOCKFLAG_LAST 2 58 #define PROG_BLOCKFLAG_LAST 2
48   59  
49 /* ISP SCK speed identifiers */ 60 /* ISP SCK speed identifiers */
50 #define USBASP_ISP_SCK_AUTO 0 61 #define USBASP_ISP_SCK_AUTO 0
51 #define USBASP_ISP_SCK_0_5 1 /* 500 Hz */ 62 #define USBASP_ISP_SCK_0_5 1 /* 500 Hz */
52 #define USBASP_ISP_SCK_1 2 /* 1 kHz */ 63 #define USBASP_ISP_SCK_1 2 /* 1 kHz */
53 #define USBASP_ISP_SCK_2 3 /* 2 kHz */ 64 #define USBASP_ISP_SCK_2 3 /* 2 kHz */
54 #define USBASP_ISP_SCK_4 4 /* 4 kHz */ 65 #define USBASP_ISP_SCK_4 4 /* 4 kHz */
55 #define USBASP_ISP_SCK_8 5 /* 8 kHz */ 66 #define USBASP_ISP_SCK_8 5 /* 8 kHz */
56 #define USBASP_ISP_SCK_16 6 /* 16 kHz */ 67 #define USBASP_ISP_SCK_16 6 /* 16 kHz */
57 #define USBASP_ISP_SCK_32 7 /* 32 kHz */ 68 #define USBASP_ISP_SCK_32 7 /* 32 kHz */
58 #define USBASP_ISP_SCK_93_75 8 /* 93.75 kHz */ 69 #define USBASP_ISP_SCK_93_75 8 /* 93.75 kHz */
59 #define USBASP_ISP_SCK_187_5 9 /* 187.5 kHz */ 70 #define USBASP_ISP_SCK_187_5 9 /* 187.5 kHz */
60 #define USBASP_ISP_SCK_375 10 /* 375 kHz */ 71 #define USBASP_ISP_SCK_375 10 /* 375 kHz */
61 #define USBASP_ISP_SCK_750 11 /* 750 kHz */ 72 #define USBASP_ISP_SCK_750 11 /* 750 kHz */
62 #define USBASP_ISP_SCK_1500 12 /* 1.5 MHz */ 73 #define USBASP_ISP_SCK_1500 12 /* 1.5 MHz */
63   74  
-   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  
64 /* macros for gpio functions */ 81 /* macros for gpio functions */
65 #define ledRedOn() PORTC &= ~(1 << PC1) 82 #define ledRedOn() PORT(LED_RED_PORT) &= ~(1 << LED_RED_BIT) // Active L
66 #define ledRedOff() PORTC |= (1 << PC1) 83 #define ledRedOff() PORT(LED_RED_PORT) |= (1 << LED_RED_BIT)
67 #define ledGreenOn() PORTC &= ~(1 << PC0) 84 #define ledGreenOn() PORT(LED_GREEN_PORT) &= ~(1 << LED_GREEN_BIT) // Active L
68 #define ledGreenOff() PORTC |= (1 << PC0) 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
69   90  
70 #endif /* USBASP_H_ */ 91 #endif /* USBASP_H_ */