Rev 3332 Rev 3333
Line 1... Line 1...
1 // ====================================================================== 1 // ======================================================================
2 // Common definitions for the USB driver 2 // Common definitions for the USB driver
3 // 3 //
4 // Copyright (C) 2006 Dick Streefland 4 // Copyright 2006-2010 Dick Streefland
5 // 5 //
6 // This is free software, licensed under the terms of the GNU General 6 // This is free software, licensed under the terms of the GNU General
7 // Public License as published by the Free Software Foundation. 7 // Public License as published by the Free Software Foundation.
8 // ====================================================================== 8 // ======================================================================
9   9  
Line 17... Line 17...
17 #define CAT2(a,b) CAT2EXP(a, b) 17 #define CAT2(a,b) CAT2EXP(a, b)
18 #define CAT2EXP(a,b) a ## b 18 #define CAT2EXP(a,b) a ## b
19 #define CAT3(a,b,c) CAT3EXP(a, b, c) 19 #define CAT3(a,b,c) CAT3EXP(a, b, c)
20 #define CAT3EXP(a,b,c) a ## b ## c 20 #define CAT3EXP(a,b,c) a ## b ## c
21   21  
22 // I/O Ports 22 // I/O Ports for USB
23 #define USB_IN CAT2(PIN, USBTINY_PORT) 23 #define USB_IN CAT2(PIN, USBTINY_PORT)
24 #define USB_OUT CAT2(PORT, USBTINY_PORT) 24 #define USB_OUT CAT2(PORT, USBTINY_PORT)
25 #define USB_DDR CAT2(DDR, USBTINY_PORT) 25 #define USB_DDR CAT2(DDR, USBTINY_PORT)
26   26  
27 // I/O bit masks 27 // I/O bit masks for USB
28 #define USB_MASK_DMINUS (1 << (USBTINY_DMINUS)) 28 #define USB_MASK_DMINUS (1 << (USBTINY_DMINUS))
29 #define USB_MASK_DPLUS (1 << (USBTINY_DPLUS)) 29 #define USB_MASK_DPLUS (1 << (USBTINY_DPLUS))
30 #define USB_MASK (USB_MASK_DMINUS | USB_MASK_DPLUS) 30 #define USB_MASK (USB_MASK_DMINUS | USB_MASK_DPLUS)
31   31  
32 // Interrupt configuration 32 // Interrupt configuration
Line 34... Line 34...
34 # define USB_INT_CONFIG EICRA 34 # define USB_INT_CONFIG EICRA
35 #else 35 #else
36 # define USB_INT_CONFIG MCUCR 36 # define USB_INT_CONFIG MCUCR
37 #endif 37 #endif
38 #define USB_INT_CONFIG_SET ((1 << CAT3(ISC,USBTINY_INT,1)) | (1 << CAT3(ISC,USBTINY_INT,0))) 38 #define USB_INT_CONFIG_SET ((1 << CAT3(ISC,USBTINY_INT,1)) | (1 << CAT3(ISC,USBTINY_INT,0)))
39 #if defined SIG_INT0 -  
40 # define USB_INT_VECTOR CAT2(SIG_INT, USBTINY_INT) 39 #define USB_INT_VECTOR CAT3(INT, USBTINY_INT, _vect)
41 #else -  
42 # define USB_INT_VECTOR CAT2(SIG_INTERRUPT, USBTINY_INT) -  
43 #endif -  
44   40  
45 // Interrupt enable 41 // Interrupt enable
46 #if defined GIMSK 42 #if defined GIMSK
47 # define USB_INT_ENABLE GIMSK 43 # define USB_INT_ENABLE GIMSK
48 #elif defined EIMSK 44 #elif defined EIMSK
Line 57... Line 53...
57 # define USB_INT_PENDING EIFR 53 # define USB_INT_PENDING EIFR
58 #else 54 #else
59 # define USB_INT_PENDING GIFR 55 # define USB_INT_PENDING GIFR
60 #endif 56 #endif
61 #define USB_INT_PENDING_BIT CAT2(INTF,USBTINY_INT) 57 #define USB_INT_PENDING_BIT CAT2(INTF,USBTINY_INT)
-   58 #if defined INF0 && ! defined INTF0
-   59 # define INTF0 INF0 // fix for incorrect definition in iotn13.h
-   60 #endif
62   61  
63 // USB PID values 62 // USB PID values
64 #define USB_PID_SETUP 0x2d 63 #define USB_PID_SETUP 0x2d
65 #define USB_PID_OUT 0xe1 64 #define USB_PID_OUT 0xe1
66 #define USB_PID_IN 0x69 65 #define USB_PID_IN 0x69
Line 70... Line 69...
70 #define USB_PID_NAK 0x5a 69 #define USB_PID_NAK 0x5a
71 #define USB_PID_STALL 0x1e 70 #define USB_PID_STALL 0x1e
72   71  
73 // Various constants 72 // Various constants
74 #define USB_BUFSIZE 11 // PID + data + CRC 73 #define USB_BUFSIZE 11 // PID + data + CRC
-   74  
-   75 // Bit manipulation macros
-   76 #define BIT_CLR(reg,bit) { (reg) &= ~ _BV(bit); }
-   77 #define BIT_SET(reg,bit) { (reg) |= _BV(bit); }
-   78 #define BIT_TST(reg,bit) (((reg) & _BV(bit)) != 0)
-   79  
-   80 // I/O port manipulation macros
-   81 #define DDR_CLR(p,b) BIT_CLR(DDR ## p, b)
-   82 #define DDR_SET(p,b) BIT_SET(DDR ## p, b)
-   83 #define PORT_CLR(p,b) BIT_CLR(PORT ## p, b)
-   84 #define PORT_SET(p,b) BIT_SET(PORT ## p, b)
-   85 #define PORT_TST(p,b) BIT_TST(PORT ## p, b)
-   86 #define PIN_TST(p,b) BIT_TST(PIN ## p, b)
-   87 #define PIN_SET(p,b) BIT_SET(PIN ## p, b)
-   88  
-   89 // Macros that can be used with an argument of the form (port,bit)
-   90 #define INPUT(bit) DDR_CLR bit
-   91 #define OUTPUT(bit) DDR_SET bit
-   92 #define CLR(bit) PORT_CLR bit
-   93 #define SET(bit) PORT_SET bit
-   94 #define ISSET(bit) PORT_TST bit
-   95 #define TST(bit) PIN_TST bit
-   96 #define TOGGLE(bit) PIN_SET bit