diff options
Diffstat (limited to 'tmk_core/protocol/vusb')
| -rw-r--r-- | tmk_core/protocol/vusb/main.c | 42 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/sendchar_usart.c | 12 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usbdrv/oddebug.c | 22 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usbdrv/oddebug.h | 114 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usbdrv/usbconfig-prototype.h | 86 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usbdrv/usbdrv.c | 673 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usbdrv/usbdrv.h | 487 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 498 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.h | 3 |
9 files changed, 937 insertions, 1000 deletions
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index 86c2188c8..f8322d94a 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c | |||
| @@ -21,19 +21,16 @@ | |||
| 21 | #include "uart.h" | 21 | #include "uart.h" |
| 22 | #include "debug.h" | 22 | #include "debug.h" |
| 23 | 23 | ||
| 24 | |||
| 25 | #define UART_BAUD_RATE 115200 | 24 | #define UART_BAUD_RATE 115200 |
| 26 | 25 | ||
| 27 | |||
| 28 | /* This is from main.c of USBaspLoader */ | 26 | /* This is from main.c of USBaspLoader */ |
| 29 | static void initForUsbConnectivity(void) | 27 | static void initForUsbConnectivity(void) { |
| 30 | { | ||
| 31 | uint8_t i = 0; | 28 | uint8_t i = 0; |
| 32 | 29 | ||
| 33 | usbInit(); | 30 | usbInit(); |
| 34 | /* enforce USB re-enumerate: */ | 31 | /* enforce USB re-enumerate: */ |
| 35 | usbDeviceDisconnect(); /* do this while interrupts are disabled */ | 32 | usbDeviceDisconnect(); /* do this while interrupts are disabled */ |
| 36 | while(--i){ /* fake USB disconnect for > 250 ms */ | 33 | while (--i) { /* fake USB disconnect for > 250 ms */ |
| 37 | wdt_reset(); | 34 | wdt_reset(); |
| 38 | _delay_ms(1); | 35 | _delay_ms(1); |
| 39 | } | 36 | } |
| @@ -41,8 +38,7 @@ static void initForUsbConnectivity(void) | |||
| 41 | sei(); | 38 | sei(); |
| 42 | } | 39 | } |
| 43 | 40 | ||
| 44 | int main(void) | 41 | int main(void) { |
| 45 | { | ||
| 46 | bool suspended = false; | 42 | bool suspended = false; |
| 47 | #if USB_COUNT_SOF | 43 | #if USB_COUNT_SOF |
| 48 | uint16_t last_timer = timer_read(); | 44 | uint16_t last_timer = timer_read(); |
| @@ -68,26 +64,26 @@ int main(void) | |||
| 68 | while (1) { | 64 | while (1) { |
| 69 | #if USB_COUNT_SOF | 65 | #if USB_COUNT_SOF |
| 70 | if (usbSofCount != 0) { | 66 | if (usbSofCount != 0) { |
| 71 | suspended = false; | 67 | suspended = false; |
| 72 | usbSofCount = 0; | 68 | usbSofCount = 0; |
| 73 | last_timer = timer_read(); | 69 | last_timer = timer_read(); |
| 74 | } else { | 70 | } else { |
| 75 | // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) | 71 | // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) |
| 76 | if (timer_elapsed(last_timer) > 5) { | 72 | if (timer_elapsed(last_timer) > 5) { |
| 77 | suspended = true; | 73 | suspended = true; |
| 78 | /* | 74 | /* |
| 79 | uart_putchar('S'); | 75 | uart_putchar('S'); |
| 80 | _delay_ms(1); | 76 | _delay_ms(1); |
| 81 | cli(); | 77 | cli(); |
| 82 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); | 78 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); |
| 83 | sleep_enable(); | 79 | sleep_enable(); |
| 84 | sleep_bod_disable(); | 80 | sleep_bod_disable(); |
| 85 | sei(); | 81 | sei(); |
| 86 | sleep_cpu(); | 82 | sleep_cpu(); |
| 87 | sleep_disable(); | 83 | sleep_disable(); |
| 88 | _delay_ms(10); | 84 | _delay_ms(10); |
| 89 | uart_putchar('W'); | 85 | uart_putchar('W'); |
| 90 | */ | 86 | */ |
| 91 | } | 87 | } |
| 92 | } | 88 | } |
| 93 | #endif | 89 | #endif |
diff --git a/tmk_core/protocol/vusb/sendchar_usart.c b/tmk_core/protocol/vusb/sendchar_usart.c index 8d24f87d1..42bd9ee36 100644 --- a/tmk_core/protocol/vusb/sendchar_usart.c +++ b/tmk_core/protocol/vusb/sendchar_usart.c | |||
| @@ -6,18 +6,14 @@ | |||
| 6 | #include "oddebug.h" | 6 | #include "oddebug.h" |
| 7 | #include "sendchar.h" | 7 | #include "sendchar.h" |
| 8 | 8 | ||
| 9 | |||
| 10 | #if DEBUG_LEVEL > 0 | 9 | #if DEBUG_LEVEL > 0 |
| 11 | /* from oddebug.c */ | 10 | /* from oddebug.c */ |
| 12 | int8_t sendchar(uint8_t c) | 11 | int8_t sendchar(uint8_t c) { |
| 13 | { | 12 | while (!(ODDBG_USR & (1 << ODDBG_UDRE))) |
| 14 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ | 13 | ; /* wait for data register empty */ |
| 15 | ODDBG_UDR = c; | 14 | ODDBG_UDR = c; |
| 16 | return 1; | 15 | return 1; |
| 17 | } | 16 | } |
| 18 | #else | 17 | #else |
| 19 | int8_t sendchar(uint8_t c) | 18 | int8_t sendchar(uint8_t c) { return 1; } |
| 20 | { | ||
| 21 | return 1; | ||
| 22 | } | ||
| 23 | #endif | 19 | #endif |
diff --git a/tmk_core/protocol/vusb/usbdrv/oddebug.c b/tmk_core/protocol/vusb/usbdrv/oddebug.c index 945457c1f..bcd28ff01 100644 --- a/tmk_core/protocol/vusb/usbdrv/oddebug.c +++ b/tmk_core/protocol/vusb/usbdrv/oddebug.c | |||
| @@ -12,34 +12,30 @@ | |||
| 12 | 12 | ||
| 13 | #if DEBUG_LEVEL > 0 | 13 | #if DEBUG_LEVEL > 0 |
| 14 | 14 | ||
| 15 | #warning "Never compile production devices with debugging enabled" | 15 | # warning "Never compile production devices with debugging enabled" |
| 16 | 16 | ||
| 17 | static void uartPutc(char c) | 17 | static void uartPutc(char c) { |
| 18 | { | 18 | while (!(ODDBG_USR & (1 << ODDBG_UDRE))) |
| 19 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ | 19 | ; /* wait for data register empty */ |
| 20 | ODDBG_UDR = c; | 20 | ODDBG_UDR = c; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | static uchar hexAscii(uchar h) | 23 | static uchar hexAscii(uchar h) { |
| 24 | { | ||
| 25 | h &= 0xf; | 24 | h &= 0xf; |
| 26 | if(h >= 10) | 25 | if (h >= 10) h += 'a' - (uchar)10 - '0'; |
| 27 | h += 'a' - (uchar)10 - '0'; | ||
| 28 | h += '0'; | 26 | h += '0'; |
| 29 | return h; | 27 | return h; |
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | static void printHex(uchar c) | 30 | static void printHex(uchar c) { |
| 33 | { | ||
| 34 | uartPutc(hexAscii(c >> 4)); | 31 | uartPutc(hexAscii(c >> 4)); |
| 35 | uartPutc(hexAscii(c)); | 32 | uartPutc(hexAscii(c)); |
| 36 | } | 33 | } |
| 37 | 34 | ||
| 38 | void odDebug(uchar prefix, uchar *data, uchar len) | 35 | void odDebug(uchar prefix, uchar *data, uchar len) { |
| 39 | { | ||
| 40 | printHex(prefix); | 36 | printHex(prefix); |
| 41 | uartPutc(':'); | 37 | uartPutc(':'); |
| 42 | while(len--){ | 38 | while (len--) { |
| 43 | uartPutc(' '); | 39 | uartPutc(' '); |
| 44 | printHex(*data++); | 40 | printHex(*data++); |
| 45 | } | 41 | } |
diff --git a/tmk_core/protocol/vusb/usbdrv/oddebug.h b/tmk_core/protocol/vusb/usbdrv/oddebug.h index d61309daa..f93f33879 100644 --- a/tmk_core/protocol/vusb/usbdrv/oddebug.h +++ b/tmk_core/protocol/vusb/usbdrv/oddebug.h | |||
| @@ -23,39 +23,38 @@ A debug log consists of a label ('prefix') to indicate which debug log created | |||
| 23 | the output and a memory block to dump in hex ('data' and 'len'). | 23 | the output and a memory block to dump in hex ('data' and 'len'). |
| 24 | */ | 24 | */ |
| 25 | 25 | ||
| 26 | |||
| 27 | #ifndef F_CPU | 26 | #ifndef F_CPU |
| 28 | # define F_CPU 12000000 /* 12 MHz */ | 27 | # define F_CPU 12000000 /* 12 MHz */ |
| 29 | #endif | 28 | #endif |
| 30 | 29 | ||
| 31 | /* make sure we have the UART defines: */ | 30 | /* make sure we have the UART defines: */ |
| 32 | #include "usbportability.h" | 31 | #include "usbportability.h" |
| 33 | 32 | ||
| 34 | #ifndef uchar | 33 | #ifndef uchar |
| 35 | # define uchar unsigned char | 34 | # define uchar unsigned char |
| 36 | #endif | 35 | #endif |
| 37 | 36 | ||
| 38 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */ | 37 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */ |
| 39 | # warning "Debugging disabled because device has no UART" | 38 | # warning "Debugging disabled because device has no UART" |
| 40 | # undef DEBUG_LEVEL | 39 | # undef DEBUG_LEVEL |
| 41 | #endif | 40 | #endif |
| 42 | 41 | ||
| 43 | #ifndef DEBUG_LEVEL | 42 | #ifndef DEBUG_LEVEL |
| 44 | # define DEBUG_LEVEL 0 | 43 | # define DEBUG_LEVEL 0 |
| 45 | #endif | 44 | #endif |
| 46 | 45 | ||
| 47 | /* ------------------------------------------------------------------------- */ | 46 | /* ------------------------------------------------------------------------- */ |
| 48 | 47 | ||
| 49 | #if DEBUG_LEVEL > 0 | 48 | #if DEBUG_LEVEL > 0 |
| 50 | # define DBG1(prefix, data, len) odDebug(prefix, data, len) | 49 | # define DBG1(prefix, data, len) odDebug(prefix, data, len) |
| 51 | #else | 50 | #else |
| 52 | # define DBG1(prefix, data, len) | 51 | # define DBG1(prefix, data, len) |
| 53 | #endif | 52 | #endif |
| 54 | 53 | ||
| 55 | #if DEBUG_LEVEL > 1 | 54 | #if DEBUG_LEVEL > 1 |
| 56 | # define DBG2(prefix, data, len) odDebug(prefix, data, len) | 55 | # define DBG2(prefix, data, len) odDebug(prefix, data, len) |
| 57 | #else | 56 | #else |
| 58 | # define DBG2(prefix, data, len) | 57 | # define DBG2(prefix, data, len) |
| 59 | #endif | 58 | #endif |
| 60 | 59 | ||
| 61 | /* ------------------------------------------------------------------------- */ | 60 | /* ------------------------------------------------------------------------- */ |
| @@ -65,57 +64,56 @@ extern void odDebug(uchar prefix, uchar *data, uchar len); | |||
| 65 | 64 | ||
| 66 | /* Try to find our control registers; ATMEL likes to rename these */ | 65 | /* Try to find our control registers; ATMEL likes to rename these */ |
| 67 | 66 | ||
| 68 | #if defined UBRR | 67 | # if defined UBRR |
| 69 | # define ODDBG_UBRR UBRR | 68 | # define ODDBG_UBRR UBRR |
| 70 | #elif defined UBRRL | 69 | # elif defined UBRRL |
| 71 | # define ODDBG_UBRR UBRRL | 70 | # define ODDBG_UBRR UBRRL |
| 72 | #elif defined UBRR0 | 71 | # elif defined UBRR0 |
| 73 | # define ODDBG_UBRR UBRR0 | 72 | # define ODDBG_UBRR UBRR0 |
| 74 | #elif defined UBRR0L | 73 | # elif defined UBRR0L |
| 75 | # define ODDBG_UBRR UBRR0L | 74 | # define ODDBG_UBRR UBRR0L |
| 76 | #endif | 75 | # endif |
| 77 | 76 | ||
| 78 | #if defined UCR | 77 | # if defined UCR |
| 79 | # define ODDBG_UCR UCR | 78 | # define ODDBG_UCR UCR |
| 80 | #elif defined UCSRB | 79 | # elif defined UCSRB |
| 81 | # define ODDBG_UCR UCSRB | 80 | # define ODDBG_UCR UCSRB |
| 82 | #elif defined UCSR0B | 81 | # elif defined UCSR0B |
| 83 | # define ODDBG_UCR UCSR0B | 82 | # define ODDBG_UCR UCSR0B |
| 84 | #endif | 83 | # endif |
| 85 | 84 | ||
| 86 | #if defined TXEN | 85 | # if defined TXEN |
| 87 | # define ODDBG_TXEN TXEN | 86 | # define ODDBG_TXEN TXEN |
| 88 | #else | 87 | # else |
| 89 | # define ODDBG_TXEN TXEN0 | 88 | # define ODDBG_TXEN TXEN0 |
| 90 | #endif | 89 | # endif |
| 91 | 90 | ||
| 92 | #if defined USR | 91 | # if defined USR |
| 93 | # define ODDBG_USR USR | 92 | # define ODDBG_USR USR |
| 94 | #elif defined UCSRA | 93 | # elif defined UCSRA |
| 95 | # define ODDBG_USR UCSRA | 94 | # define ODDBG_USR UCSRA |
| 96 | #elif defined UCSR0A | 95 | # elif defined UCSR0A |
| 97 | # define ODDBG_USR UCSR0A | 96 | # define ODDBG_USR UCSR0A |
| 98 | #endif | 97 | # endif |
| 99 | 98 | ||
| 100 | #if defined UDRE | 99 | # if defined UDRE |
| 101 | # define ODDBG_UDRE UDRE | 100 | # define ODDBG_UDRE UDRE |
| 102 | #else | 101 | # else |
| 103 | # define ODDBG_UDRE UDRE0 | 102 | # define ODDBG_UDRE UDRE0 |
| 104 | #endif | 103 | # endif |
| 105 | 104 | ||
| 106 | #if defined UDR | 105 | # if defined UDR |
| 107 | # define ODDBG_UDR UDR | 106 | # define ODDBG_UDR UDR |
| 108 | #elif defined UDR0 | 107 | # elif defined UDR0 |
| 109 | # define ODDBG_UDR UDR0 | 108 | # define ODDBG_UDR UDR0 |
| 110 | #endif | 109 | # endif |
| 111 | 110 | ||
| 112 | static inline void odDebugInit(void) | 111 | static inline void odDebugInit(void) { |
| 113 | { | 112 | ODDBG_UCR |= (1 << ODDBG_TXEN); |
| 114 | ODDBG_UCR |= (1<<ODDBG_TXEN); | ||
| 115 | ODDBG_UBRR = F_CPU / (19200 * 16L) - 1; | 113 | ODDBG_UBRR = F_CPU / (19200 * 16L) - 1; |
| 116 | } | 114 | } |
| 117 | #else | 115 | #else |
| 118 | # define odDebugInit() | 116 | # define odDebugInit() |
| 119 | #endif | 117 | #endif |
| 120 | 118 | ||
| 121 | /* ------------------------------------------------------------------------- */ | 119 | /* ------------------------------------------------------------------------- */ |
diff --git a/tmk_core/protocol/vusb/usbdrv/usbconfig-prototype.h b/tmk_core/protocol/vusb/usbdrv/usbconfig-prototype.h index 847710e2a..020ea5147 100644 --- a/tmk_core/protocol/vusb/usbdrv/usbconfig-prototype.h +++ b/tmk_core/protocol/vusb/usbdrv/usbconfig-prototype.h | |||
| @@ -26,15 +26,15 @@ section at the end of this file). | |||
| 26 | 26 | ||
| 27 | /* ---------------------------- Hardware Config ---------------------------- */ | 27 | /* ---------------------------- Hardware Config ---------------------------- */ |
| 28 | 28 | ||
| 29 | #define USB_CFG_IOPORTNAME D | 29 | #define USB_CFG_IOPORTNAME D |
| 30 | /* This is the port where the USB bus is connected. When you configure it to | 30 | /* This is the port where the USB bus is connected. When you configure it to |
| 31 | * "B", the registers PORTB, PINB and DDRB will be used. | 31 | * "B", the registers PORTB, PINB and DDRB will be used. |
| 32 | */ | 32 | */ |
| 33 | #define USB_CFG_DMINUS_BIT 4 | 33 | #define USB_CFG_DMINUS_BIT 4 |
| 34 | /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. | 34 | /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. |
| 35 | * This may be any bit in the port. | 35 | * This may be any bit in the port. |
| 36 | */ | 36 | */ |
| 37 | #define USB_CFG_DPLUS_BIT 2 | 37 | #define USB_CFG_DPLUS_BIT 2 |
| 38 | /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. | 38 | /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. |
| 39 | * This may be any bit in the port. Please note that D+ must also be connected | 39 | * This may be any bit in the port. Please note that D+ must also be connected |
| 40 | * to interrupt pin INT0! [You can also use other interrupts, see section | 40 | * to interrupt pin INT0! [You can also use other interrupts, see section |
| @@ -43,7 +43,7 @@ section at the end of this file). | |||
| 43 | * interrupt, the USB interrupt will also be triggered at Start-Of-Frame | 43 | * interrupt, the USB interrupt will also be triggered at Start-Of-Frame |
| 44 | * markers every millisecond.] | 44 | * markers every millisecond.] |
| 45 | */ | 45 | */ |
| 46 | #define USB_CFG_CLOCK_KHZ (F_CPU/1000) | 46 | #define USB_CFG_CLOCK_KHZ (F_CPU / 1000) |
| 47 | /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, | 47 | /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, |
| 48 | * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code | 48 | * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code |
| 49 | * require no crystal, they tolerate +/- 1% deviation from the nominal | 49 | * require no crystal, they tolerate +/- 1% deviation from the nominal |
| @@ -52,7 +52,7 @@ section at the end of this file). | |||
| 52 | * Since F_CPU should be defined to your actual clock rate anyway, you should | 52 | * Since F_CPU should be defined to your actual clock rate anyway, you should |
| 53 | * not need to modify this setting. | 53 | * not need to modify this setting. |
| 54 | */ | 54 | */ |
| 55 | #define USB_CFG_CHECK_CRC 0 | 55 | #define USB_CFG_CHECK_CRC 0 |
| 56 | /* Define this to 1 if you want that the driver checks integrity of incoming | 56 | /* Define this to 1 if you want that the driver checks integrity of incoming |
| 57 | * data packets (CRC checks). CRC checks cost quite a bit of code size and are | 57 | * data packets (CRC checks). CRC checks cost quite a bit of code size and are |
| 58 | * currently only available for 18 MHz crystal clock. You must choose | 58 | * currently only available for 18 MHz crystal clock. You must choose |
| @@ -75,18 +75,18 @@ section at the end of this file). | |||
| 75 | 75 | ||
| 76 | /* --------------------------- Functional Range ---------------------------- */ | 76 | /* --------------------------- Functional Range ---------------------------- */ |
| 77 | 77 | ||
| 78 | #define USB_CFG_HAVE_INTRIN_ENDPOINT 0 | 78 | #define USB_CFG_HAVE_INTRIN_ENDPOINT 0 |
| 79 | /* Define this to 1 if you want to compile a version with two endpoints: The | 79 | /* Define this to 1 if you want to compile a version with two endpoints: The |
| 80 | * default control endpoint 0 and an interrupt-in endpoint (any other endpoint | 80 | * default control endpoint 0 and an interrupt-in endpoint (any other endpoint |
| 81 | * number). | 81 | * number). |
| 82 | */ | 82 | */ |
| 83 | #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 | 83 | #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 |
| 84 | /* Define this to 1 if you want to compile a version with three endpoints: The | 84 | /* Define this to 1 if you want to compile a version with three endpoints: The |
| 85 | * default control endpoint 0, an interrupt-in endpoint 3 (or the number | 85 | * default control endpoint 0, an interrupt-in endpoint 3 (or the number |
| 86 | * configured below) and a catch-all default interrupt-in endpoint as above. | 86 | * configured below) and a catch-all default interrupt-in endpoint as above. |
| 87 | * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. | 87 | * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. |
| 88 | */ | 88 | */ |
| 89 | #define USB_CFG_EP3_NUMBER 3 | 89 | #define USB_CFG_EP3_NUMBER 3 |
| 90 | /* If the so-called endpoint 3 is used, it can now be configured to any other | 90 | /* If the so-called endpoint 3 is used, it can now be configured to any other |
| 91 | * endpoint number (except 0) with this macro. Default if undefined is 3. | 91 | * endpoint number (except 0) with this macro. Default if undefined is 3. |
| 92 | */ | 92 | */ |
| @@ -96,13 +96,13 @@ section at the end of this file). | |||
| 96 | * Since the token is toggled BEFORE sending any data, the first packet is | 96 | * Since the token is toggled BEFORE sending any data, the first packet is |
| 97 | * sent with the oposite value of this configuration! | 97 | * sent with the oposite value of this configuration! |
| 98 | */ | 98 | */ |
| 99 | #define USB_CFG_IMPLEMENT_HALT 0 | 99 | #define USB_CFG_IMPLEMENT_HALT 0 |
| 100 | /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature | 100 | /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature |
| 101 | * for endpoint 1 (interrupt endpoint). Although you may not need this feature, | 101 | * for endpoint 1 (interrupt endpoint). Although you may not need this feature, |
| 102 | * it is required by the standard. We have made it a config option because it | 102 | * it is required by the standard. We have made it a config option because it |
| 103 | * bloats the code considerably. | 103 | * bloats the code considerably. |
| 104 | */ | 104 | */ |
| 105 | #define USB_CFG_SUPPRESS_INTR_CODE 0 | 105 | #define USB_CFG_SUPPRESS_INTR_CODE 0 |
| 106 | /* Define this to 1 if you want to declare interrupt-in endpoints, but don't | 106 | /* Define this to 1 if you want to declare interrupt-in endpoints, but don't |
| 107 | * want to send any data over them. If this macro is defined to 1, functions | 107 | * want to send any data over them. If this macro is defined to 1, functions |
| 108 | * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if | 108 | * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if |
| @@ -110,48 +110,48 @@ section at the end of this file). | |||
| 110 | * (e.g. HID), but never want to send any data. This option saves a couple | 110 | * (e.g. HID), but never want to send any data. This option saves a couple |
| 111 | * of bytes in flash memory and the transmit buffers in RAM. | 111 | * of bytes in flash memory and the transmit buffers in RAM. |
| 112 | */ | 112 | */ |
| 113 | #define USB_CFG_INTR_POLL_INTERVAL 10 | 113 | #define USB_CFG_INTR_POLL_INTERVAL 10 |
| 114 | /* If you compile a version with endpoint 1 (interrupt-in), this is the poll | 114 | /* If you compile a version with endpoint 1 (interrupt-in), this is the poll |
| 115 | * interval. The value is in milliseconds and must not be less than 10 ms for | 115 | * interval. The value is in milliseconds and must not be less than 10 ms for |
| 116 | * low speed devices. | 116 | * low speed devices. |
| 117 | */ | 117 | */ |
| 118 | #define USB_CFG_IS_SELF_POWERED 0 | 118 | #define USB_CFG_IS_SELF_POWERED 0 |
| 119 | /* Define this to 1 if the device has its own power supply. Set it to 0 if the | 119 | /* Define this to 1 if the device has its own power supply. Set it to 0 if the |
| 120 | * device is powered from the USB bus. | 120 | * device is powered from the USB bus. |
| 121 | */ | 121 | */ |
| 122 | #define USB_CFG_MAX_BUS_POWER 100 | 122 | #define USB_CFG_MAX_BUS_POWER 100 |
| 123 | /* Set this variable to the maximum USB bus power consumption of your device. | 123 | /* Set this variable to the maximum USB bus power consumption of your device. |
| 124 | * The value is in milliamperes. [It will be divided by two since USB | 124 | * The value is in milliamperes. [It will be divided by two since USB |
| 125 | * communicates power requirements in units of 2 mA.] | 125 | * communicates power requirements in units of 2 mA.] |
| 126 | */ | 126 | */ |
| 127 | #define USB_CFG_IMPLEMENT_FN_WRITE 0 | 127 | #define USB_CFG_IMPLEMENT_FN_WRITE 0 |
| 128 | /* Set this to 1 if you want usbFunctionWrite() to be called for control-out | 128 | /* Set this to 1 if you want usbFunctionWrite() to be called for control-out |
| 129 | * transfers. Set it to 0 if you don't need it and want to save a couple of | 129 | * transfers. Set it to 0 if you don't need it and want to save a couple of |
| 130 | * bytes. | 130 | * bytes. |
| 131 | */ | 131 | */ |
| 132 | #define USB_CFG_IMPLEMENT_FN_READ 0 | 132 | #define USB_CFG_IMPLEMENT_FN_READ 0 |
| 133 | /* Set this to 1 if you need to send control replies which are generated | 133 | /* Set this to 1 if you need to send control replies which are generated |
| 134 | * "on the fly" when usbFunctionRead() is called. If you only want to send | 134 | * "on the fly" when usbFunctionRead() is called. If you only want to send |
| 135 | * data from a static buffer, set it to 0 and return the data from | 135 | * data from a static buffer, set it to 0 and return the data from |
| 136 | * usbFunctionSetup(). This saves a couple of bytes. | 136 | * usbFunctionSetup(). This saves a couple of bytes. |
| 137 | */ | 137 | */ |
| 138 | #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 | 138 | #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 |
| 139 | /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. | 139 | /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. |
| 140 | * You must implement the function usbFunctionWriteOut() which receives all | 140 | * You must implement the function usbFunctionWriteOut() which receives all |
| 141 | * interrupt/bulk data sent to any endpoint other than 0. The endpoint number | 141 | * interrupt/bulk data sent to any endpoint other than 0. The endpoint number |
| 142 | * can be found in 'usbRxToken'. | 142 | * can be found in 'usbRxToken'. |
| 143 | */ | 143 | */ |
| 144 | #define USB_CFG_HAVE_FLOWCONTROL 0 | 144 | #define USB_CFG_HAVE_FLOWCONTROL 0 |
| 145 | /* Define this to 1 if you want flowcontrol over USB data. See the definition | 145 | /* Define this to 1 if you want flowcontrol over USB data. See the definition |
| 146 | * of the macros usbDisableAllRequests() and usbEnableAllRequests() in | 146 | * of the macros usbDisableAllRequests() and usbEnableAllRequests() in |
| 147 | * usbdrv.h. | 147 | * usbdrv.h. |
| 148 | */ | 148 | */ |
| 149 | #define USB_CFG_DRIVER_FLASH_PAGE 0 | 149 | #define USB_CFG_DRIVER_FLASH_PAGE 0 |
| 150 | /* If the device has more than 64 kBytes of flash, define this to the 64 k page | 150 | /* If the device has more than 64 kBytes of flash, define this to the 64 k page |
| 151 | * where the driver's constants (descriptors) are located. Or in other words: | 151 | * where the driver's constants (descriptors) are located. Or in other words: |
| 152 | * Define this to 1 for boot loaders on the ATMega128. | 152 | * Define this to 1 for boot loaders on the ATMega128. |
| 153 | */ | 153 | */ |
| 154 | #define USB_CFG_LONG_TRANSFERS 0 | 154 | #define USB_CFG_LONG_TRANSFERS 0 |
| 155 | /* Define this to 1 if you want to send/receive blocks of more than 254 bytes | 155 | /* Define this to 1 if you want to send/receive blocks of more than 254 bytes |
| 156 | * in a single control-in or control-out transfer. Note that the capability | 156 | * in a single control-in or control-out transfer. Note that the capability |
| 157 | * for long transfers increases the driver size. | 157 | * for long transfers increases the driver size. |
| @@ -172,7 +172,7 @@ section at the end of this file). | |||
| 172 | /* This macro (if defined) is executed when a USB SET_ADDRESS request was | 172 | /* This macro (if defined) is executed when a USB SET_ADDRESS request was |
| 173 | * received. | 173 | * received. |
| 174 | */ | 174 | */ |
| 175 | #define USB_COUNT_SOF 0 | 175 | #define USB_COUNT_SOF 0 |
| 176 | /* define this macro to 1 if you need the global variable "usbSofCount" which | 176 | /* define this macro to 1 if you need the global variable "usbSofCount" which |
| 177 | * counts SOF packets. This feature requires that the hardware interrupt is | 177 | * counts SOF packets. This feature requires that the hardware interrupt is |
| 178 | * connected to D- instead of D+. | 178 | * connected to D- instead of D+. |
| @@ -196,7 +196,7 @@ section at the end of this file). | |||
| 196 | * Please note that Start Of Frame detection works only if D- is wired to the | 196 | * Please note that Start Of Frame detection works only if D- is wired to the |
| 197 | * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! | 197 | * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! |
| 198 | */ | 198 | */ |
| 199 | #define USB_CFG_CHECK_DATA_TOGGLING 0 | 199 | #define USB_CFG_CHECK_DATA_TOGGLING 0 |
| 200 | /* define this macro to 1 if you want to filter out duplicate data packets | 200 | /* define this macro to 1 if you want to filter out duplicate data packets |
| 201 | * sent by the host. Duplicates occur only as a consequence of communication | 201 | * sent by the host. Duplicates occur only as a consequence of communication |
| 202 | * errors, when the host does not receive an ACK. Please note that you need to | 202 | * errors, when the host does not receive an ACK. Please note that you need to |
| @@ -204,11 +204,11 @@ section at the end of this file). | |||
| 204 | * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable | 204 | * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable |
| 205 | * for each control- and out-endpoint to check for duplicate packets. | 205 | * for each control- and out-endpoint to check for duplicate packets. |
| 206 | */ | 206 | */ |
| 207 | #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 | 207 | #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 |
| 208 | /* define this macro to 1 if you want the function usbMeasureFrameLength() | 208 | /* define this macro to 1 if you want the function usbMeasureFrameLength() |
| 209 | * compiled in. This function can be used to calibrate the AVR's RC oscillator. | 209 | * compiled in. This function can be used to calibrate the AVR's RC oscillator. |
| 210 | */ | 210 | */ |
| 211 | #define USB_USE_FAST_CRC 0 | 211 | #define USB_USE_FAST_CRC 0 |
| 212 | /* The assembler module has two implementations for the CRC algorithm. One is | 212 | /* The assembler module has two implementations for the CRC algorithm. One is |
| 213 | * faster, the other is smaller. This CRC routine is only used for transmitted | 213 | * faster, the other is smaller. This CRC routine is only used for transmitted |
| 214 | * messages where timing is not critical. The faster routine needs 31 cycles | 214 | * messages where timing is not critical. The faster routine needs 31 cycles |
| @@ -219,7 +219,7 @@ section at the end of this file). | |||
| 219 | 219 | ||
| 220 | /* -------------------------- Device Description --------------------------- */ | 220 | /* -------------------------- Device Description --------------------------- */ |
| 221 | 221 | ||
| 222 | #define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ | 222 | #define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ |
| 223 | /* USB vendor ID for the device, low byte first. If you have registered your | 223 | /* USB vendor ID for the device, low byte first. If you have registered your |
| 224 | * own Vendor ID, define it here. Otherwise you may use one of obdev's free | 224 | * own Vendor ID, define it here. Otherwise you may use one of obdev's free |
| 225 | * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! | 225 | * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! |
| @@ -228,7 +228,7 @@ section at the end of this file). | |||
| 228 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand | 228 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand |
| 229 | * the implications! | 229 | * the implications! |
| 230 | */ | 230 | */ |
| 231 | #define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x05dc = 1500 */ | 231 | #define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x05dc = 1500 */ |
| 232 | /* This is the ID of the product, low byte first. It is interpreted in the | 232 | /* This is the ID of the product, low byte first. It is interpreted in the |
| 233 | * scope of the vendor ID. If you have registered your own VID with usb.org | 233 | * scope of the vendor ID. If you have registered your own VID with usb.org |
| 234 | * or if you have licensed a PID from somebody else, define it here. Otherwise | 234 | * or if you have licensed a PID from somebody else, define it here. Otherwise |
| @@ -239,10 +239,10 @@ section at the end of this file). | |||
| 239 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand | 239 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand |
| 240 | * the implications! | 240 | * the implications! |
| 241 | */ | 241 | */ |
| 242 | #define USB_CFG_DEVICE_VERSION 0x00, 0x01 | 242 | #define USB_CFG_DEVICE_VERSION 0x00, 0x01 |
| 243 | /* Version number of the device: Minor number first, then major number. | 243 | /* Version number of the device: Minor number first, then major number. |
| 244 | */ | 244 | */ |
| 245 | #define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' | 245 | #define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' |
| 246 | #define USB_CFG_VENDOR_NAME_LEN 8 | 246 | #define USB_CFG_VENDOR_NAME_LEN 8 |
| 247 | /* These two values define the vendor name returned by the USB device. The name | 247 | /* These two values define the vendor name returned by the USB device. The name |
| 248 | * must be given as a list of characters under single quotes. The characters | 248 | * must be given as a list of characters under single quotes. The characters |
| @@ -252,7 +252,7 @@ section at the end of this file). | |||
| 252 | * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for | 252 | * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for |
| 253 | * details. | 253 | * details. |
| 254 | */ | 254 | */ |
| 255 | #define USB_CFG_DEVICE_NAME 'T', 'e', 'm', 'p', 'l', 'a', 't', 'e' | 255 | #define USB_CFG_DEVICE_NAME 'T', 'e', 'm', 'p', 'l', 'a', 't', 'e' |
| 256 | #define USB_CFG_DEVICE_NAME_LEN 8 | 256 | #define USB_CFG_DEVICE_NAME_LEN 8 |
| 257 | /* Same as above for the device name. If you don't want a device name, undefine | 257 | /* Same as above for the device name. If you don't want a device name, undefine |
| 258 | * the macros. See the file USB-IDs-for-free.txt before you assign a name if | 258 | * the macros. See the file USB-IDs-for-free.txt before you assign a name if |
| @@ -267,14 +267,14 @@ section at the end of this file). | |||
| 267 | * to fine tune control over USB descriptors such as the string descriptor | 267 | * to fine tune control over USB descriptors such as the string descriptor |
| 268 | * for the serial number. | 268 | * for the serial number. |
| 269 | */ | 269 | */ |
| 270 | #define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */ | 270 | #define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */ |
| 271 | #define USB_CFG_DEVICE_SUBCLASS 0 | 271 | #define USB_CFG_DEVICE_SUBCLASS 0 |
| 272 | /* See USB specification if you want to conform to an existing device class. | 272 | /* See USB specification if you want to conform to an existing device class. |
| 273 | * Class 0xff is "vendor specific". | 273 | * Class 0xff is "vendor specific". |
| 274 | */ | 274 | */ |
| 275 | #define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ | 275 | #define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ |
| 276 | #define USB_CFG_INTERFACE_SUBCLASS 0 | 276 | #define USB_CFG_INTERFACE_SUBCLASS 0 |
| 277 | #define USB_CFG_INTERFACE_PROTOCOL 0 | 277 | #define USB_CFG_INTERFACE_PROTOCOL 0 |
| 278 | /* See USB specification if you want to conform to an existing device class or | 278 | /* See USB specification if you want to conform to an existing device class or |
| 279 | * protocol. The following classes must be set at interface level: | 279 | * protocol. The following classes must be set at interface level: |
| 280 | * HID class is 3, no subclass and protocol required (but may be useful!) | 280 | * HID class is 3, no subclass and protocol required (but may be useful!) |
| @@ -345,16 +345,16 @@ section at the end of this file). | |||
| 345 | * }; | 345 | * }; |
| 346 | */ | 346 | */ |
| 347 | 347 | ||
| 348 | #define USB_CFG_DESCR_PROPS_DEVICE 0 | 348 | #define USB_CFG_DESCR_PROPS_DEVICE 0 |
| 349 | #define USB_CFG_DESCR_PROPS_CONFIGURATION 0 | 349 | #define USB_CFG_DESCR_PROPS_CONFIGURATION 0 |
| 350 | #define USB_CFG_DESCR_PROPS_STRINGS 0 | 350 | #define USB_CFG_DESCR_PROPS_STRINGS 0 |
| 351 | #define USB_CFG_DESCR_PROPS_STRING_0 0 | 351 | #define USB_CFG_DESCR_PROPS_STRING_0 0 |
| 352 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 | 352 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 |
| 353 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 | 353 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 |
| 354 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 | 354 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 |
| 355 | #define USB_CFG_DESCR_PROPS_HID 0 | 355 | #define USB_CFG_DESCR_PROPS_HID 0 |
| 356 | #define USB_CFG_DESCR_PROPS_HID_REPORT 0 | 356 | #define USB_CFG_DESCR_PROPS_HID_REPORT 0 |
| 357 | #define USB_CFG_DESCR_PROPS_UNKNOWN 0 | 357 | #define USB_CFG_DESCR_PROPS_UNKNOWN 0 |
| 358 | 358 | ||
| 359 | /* ----------------------- Optional MCU Description ------------------------ */ | 359 | /* ----------------------- Optional MCU Description ------------------------ */ |
| 360 | 360 | ||
diff --git a/tmk_core/protocol/vusb/usbdrv/usbdrv.c b/tmk_core/protocol/vusb/usbdrv/usbdrv.c index 30cdc9dcf..f69198b1b 100644 --- a/tmk_core/protocol/vusb/usbdrv/usbdrv.c +++ b/tmk_core/protocol/vusb/usbdrv/usbdrv.c | |||
| @@ -21,36 +21,36 @@ documentation of the entire driver. | |||
| 21 | /* ------------------------------------------------------------------------- */ | 21 | /* ------------------------------------------------------------------------- */ |
| 22 | 22 | ||
| 23 | /* raw USB registers / interface to assembler code: */ | 23 | /* raw USB registers / interface to assembler code: */ |
| 24 | uchar usbRxBuf[2*USB_BUFSIZE]; /* raw RX buffer: PID, 8 bytes data, 2 bytes CRC */ | 24 | uchar usbRxBuf[2 * USB_BUFSIZE]; /* raw RX buffer: PID, 8 bytes data, 2 bytes CRC */ |
| 25 | uchar usbInputBufOffset; /* offset in usbRxBuf used for low level receiving */ | 25 | uchar usbInputBufOffset; /* offset in usbRxBuf used for low level receiving */ |
| 26 | uchar usbDeviceAddr; /* assigned during enumeration, defaults to 0 */ | 26 | uchar usbDeviceAddr; /* assigned during enumeration, defaults to 0 */ |
| 27 | uchar usbNewDeviceAddr; /* device ID which should be set after status phase */ | 27 | uchar usbNewDeviceAddr; /* device ID which should be set after status phase */ |
| 28 | uchar usbConfiguration; /* currently selected configuration. Administered by driver, but not used */ | 28 | uchar usbConfiguration; /* currently selected configuration. Administered by driver, but not used */ |
| 29 | volatile schar usbRxLen; /* = 0; number of bytes in usbRxBuf; 0 means free, -1 for flow control */ | 29 | volatile schar usbRxLen; /* = 0; number of bytes in usbRxBuf; 0 means free, -1 for flow control */ |
| 30 | uchar usbCurrentTok; /* last token received or endpoint number for last OUT token if != 0 */ | 30 | uchar usbCurrentTok; /* last token received or endpoint number for last OUT token if != 0 */ |
| 31 | uchar usbRxToken; /* token for data we received; or endpont number for last OUT */ | 31 | uchar usbRxToken; /* token for data we received; or endpont number for last OUT */ |
| 32 | volatile uchar usbTxLen = USBPID_NAK; /* number of bytes to transmit with next IN token or handshake token */ | 32 | volatile uchar usbTxLen = USBPID_NAK; /* number of bytes to transmit with next IN token or handshake token */ |
| 33 | uchar usbTxBuf[USB_BUFSIZE];/* data to transmit with next IN, free if usbTxLen contains handshake token */ | 33 | uchar usbTxBuf[USB_BUFSIZE]; /* data to transmit with next IN, free if usbTxLen contains handshake token */ |
| 34 | #if USB_COUNT_SOF | 34 | #if USB_COUNT_SOF |
| 35 | volatile uchar usbSofCount; /* incremented by assembler module every SOF */ | 35 | volatile uchar usbSofCount; /* incremented by assembler module every SOF */ |
| 36 | #endif | 36 | #endif |
| 37 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE | 37 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE |
| 38 | usbTxStatus_t usbTxStatus1; | 38 | usbTxStatus_t usbTxStatus1; |
| 39 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 | 39 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 |
| 40 | usbTxStatus_t usbTxStatus3; | 40 | usbTxStatus_t usbTxStatus3; |
| 41 | # endif | 41 | # endif |
| 42 | #endif | 42 | #endif |
| 43 | #if USB_CFG_CHECK_DATA_TOGGLING | 43 | #if USB_CFG_CHECK_DATA_TOGGLING |
| 44 | uchar usbCurrentDataToken;/* when we check data toggling to ignore duplicate packets */ | 44 | uchar usbCurrentDataToken; /* when we check data toggling to ignore duplicate packets */ |
| 45 | #endif | 45 | #endif |
| 46 | 46 | ||
| 47 | /* USB status registers / not shared with asm code */ | 47 | /* USB status registers / not shared with asm code */ |
| 48 | uchar *usbMsgPtr; /* data to transmit next -- ROM or RAM address */ | 48 | uchar * usbMsgPtr; /* data to transmit next -- ROM or RAM address */ |
| 49 | static usbMsgLen_t usbMsgLen = USB_NO_MSG; /* remaining number of bytes */ | 49 | static usbMsgLen_t usbMsgLen = USB_NO_MSG; /* remaining number of bytes */ |
| 50 | static uchar usbMsgFlags; /* flag values see below */ | 50 | static uchar usbMsgFlags; /* flag values see below */ |
| 51 | 51 | ||
| 52 | #define USB_FLG_MSGPTR_IS_ROM (1<<6) | 52 | #define USB_FLG_MSGPTR_IS_ROM (1 << 6) |
| 53 | #define USB_FLG_USE_USER_RW (1<<7) | 53 | #define USB_FLG_USE_USER_RW (1 << 7) |
| 54 | 54 | ||
| 55 | /* | 55 | /* |
| 56 | optimizing hints: | 56 | optimizing hints: |
| @@ -64,196 +64,174 @@ optimizing hints: | |||
| 64 | 64 | ||
| 65 | #if USB_CFG_DESCR_PROPS_STRINGS == 0 | 65 | #if USB_CFG_DESCR_PROPS_STRINGS == 0 |
| 66 | 66 | ||
| 67 | #if USB_CFG_DESCR_PROPS_STRING_0 == 0 | 67 | # if USB_CFG_DESCR_PROPS_STRING_0 == 0 |
| 68 | #undef USB_CFG_DESCR_PROPS_STRING_0 | 68 | # undef USB_CFG_DESCR_PROPS_STRING_0 |
| 69 | #define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) | 69 | # define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) |
| 70 | const PROGMEM char usbDescriptorString0[] = { /* language descriptor */ | 70 | const PROGMEM char usbDescriptorString0[] = { |
| 71 | /* language descriptor */ | ||
| 71 | 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ | 72 | 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ |
| 72 | 3, /* descriptor type */ | 73 | 3, /* descriptor type */ |
| 73 | 0x09, 0x04, /* language index (0x0409 = US-English) */ | 74 | 0x09, 0x04, /* language index (0x0409 = US-English) */ |
| 74 | }; | 75 | }; |
| 75 | #endif | 76 | # endif |
| 76 | 77 | ||
| 77 | #if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN | 78 | # if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN |
| 78 | #undef USB_CFG_DESCR_PROPS_STRING_VENDOR | 79 | # undef USB_CFG_DESCR_PROPS_STRING_VENDOR |
| 79 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) | 80 | # define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) |
| 80 | const PROGMEM int usbDescriptorStringVendor[] = { | 81 | const PROGMEM int usbDescriptorStringVendor[] = {USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), USB_CFG_VENDOR_NAME}; |
| 81 | USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), | 82 | # endif |
| 82 | USB_CFG_VENDOR_NAME | ||
| 83 | }; | ||
| 84 | #endif | ||
| 85 | 83 | ||
| 86 | #if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN | 84 | # if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN |
| 87 | #undef USB_CFG_DESCR_PROPS_STRING_PRODUCT | 85 | # undef USB_CFG_DESCR_PROPS_STRING_PRODUCT |
| 88 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice) | 86 | # define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice) |
| 89 | const PROGMEM int usbDescriptorStringDevice[] = { | 87 | const PROGMEM int usbDescriptorStringDevice[] = {USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), USB_CFG_DEVICE_NAME}; |
| 90 | USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), | 88 | # endif |
| 91 | USB_CFG_DEVICE_NAME | ||
| 92 | }; | ||
| 93 | #endif | ||
| 94 | 89 | ||
| 95 | #if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN | 90 | # if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN |
| 96 | #undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER | 91 | # undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER |
| 97 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER sizeof(usbDescriptorStringSerialNumber) | 92 | # define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER sizeof(usbDescriptorStringSerialNumber) |
| 98 | const PROGMEM int usbDescriptorStringSerialNumber[] = { | 93 | const PROGMEM int usbDescriptorStringSerialNumber[] = {USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN), USB_CFG_SERIAL_NUMBER}; |
| 99 | USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN), | 94 | # endif |
| 100 | USB_CFG_SERIAL_NUMBER | ||
| 101 | }; | ||
| 102 | #endif | ||
| 103 | 95 | ||
| 104 | #endif /* USB_CFG_DESCR_PROPS_STRINGS == 0 */ | 96 | #endif /* USB_CFG_DESCR_PROPS_STRINGS == 0 */ |
| 105 | 97 | ||
| 106 | /* --------------------------- Device Descriptor --------------------------- */ | 98 | /* --------------------------- Device Descriptor --------------------------- */ |
| 107 | 99 | ||
| 108 | #if USB_CFG_DESCR_PROPS_DEVICE == 0 | 100 | #if USB_CFG_DESCR_PROPS_DEVICE == 0 |
| 109 | #undef USB_CFG_DESCR_PROPS_DEVICE | 101 | # undef USB_CFG_DESCR_PROPS_DEVICE |
| 110 | #define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice) | 102 | # define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice) |
| 111 | const PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */ | 103 | const PROGMEM char usbDescriptorDevice[] = { |
| 112 | 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ | 104 | /* USB device descriptor */ |
| 113 | USBDESCR_DEVICE, /* descriptor type */ | 105 | 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ |
| 114 | 0x10, 0x01, /* USB version supported */ | 106 | USBDESCR_DEVICE, /* descriptor type */ |
| 115 | USB_CFG_DEVICE_CLASS, | 107 | 0x10, 0x01, /* USB version supported */ |
| 116 | USB_CFG_DEVICE_SUBCLASS, | 108 | USB_CFG_DEVICE_CLASS, USB_CFG_DEVICE_SUBCLASS, 0, /* protocol */ |
| 117 | 0, /* protocol */ | 109 | 8, /* max packet size */ |
| 118 | 8, /* max packet size */ | ||
| 119 | /* the following two casts affect the first byte of the constant only, but | 110 | /* the following two casts affect the first byte of the constant only, but |
| 120 | * that's sufficient to avoid a warning with the default values. | 111 | * that's sufficient to avoid a warning with the default values. |
| 121 | */ | 112 | */ |
| 122 | (char)USB_CFG_VENDOR_ID,/* 2 bytes */ | 113 | (char)USB_CFG_VENDOR_ID, /* 2 bytes */ |
| 123 | (char)USB_CFG_DEVICE_ID,/* 2 bytes */ | 114 | (char)USB_CFG_DEVICE_ID, /* 2 bytes */ |
| 124 | USB_CFG_DEVICE_VERSION, /* 2 bytes */ | 115 | USB_CFG_DEVICE_VERSION, /* 2 bytes */ |
| 125 | USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 : 0, /* manufacturer string index */ | 116 | USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 : 0, /* manufacturer string index */ |
| 126 | USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0, /* product string index */ | 117 | USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0, /* product string index */ |
| 127 | USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 ? 3 : 0, /* serial number string index */ | 118 | USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 ? 3 : 0, /* serial number string index */ |
| 128 | 1, /* number of configurations */ | 119 | 1, /* number of configurations */ |
| 129 | }; | 120 | }; |
| 130 | #endif | 121 | #endif |
| 131 | 122 | ||
| 132 | /* ----------------------- Configuration Descriptor ------------------------ */ | 123 | /* ----------------------- Configuration Descriptor ------------------------ */ |
| 133 | 124 | ||
| 134 | #if USB_CFG_DESCR_PROPS_HID_REPORT != 0 && USB_CFG_DESCR_PROPS_HID == 0 | 125 | #if USB_CFG_DESCR_PROPS_HID_REPORT != 0 && USB_CFG_DESCR_PROPS_HID == 0 |
| 135 | #undef USB_CFG_DESCR_PROPS_HID | 126 | # undef USB_CFG_DESCR_PROPS_HID |
| 136 | #define USB_CFG_DESCR_PROPS_HID 9 /* length of HID descriptor in config descriptor below */ | 127 | # define USB_CFG_DESCR_PROPS_HID 9 /* length of HID descriptor in config descriptor below */ |
| 137 | #endif | 128 | #endif |
| 138 | 129 | ||
| 139 | #if USB_CFG_DESCR_PROPS_CONFIGURATION == 0 | 130 | #if USB_CFG_DESCR_PROPS_CONFIGURATION == 0 |
| 140 | #undef USB_CFG_DESCR_PROPS_CONFIGURATION | 131 | # undef USB_CFG_DESCR_PROPS_CONFIGURATION |
| 141 | #define USB_CFG_DESCR_PROPS_CONFIGURATION sizeof(usbDescriptorConfiguration) | 132 | # define USB_CFG_DESCR_PROPS_CONFIGURATION sizeof(usbDescriptorConfiguration) |
| 142 | PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ | 133 | PROGMEM char usbDescriptorConfiguration[] = { |
| 143 | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ | 134 | /* USB configuration descriptor */ |
| 144 | USBDESCR_CONFIG, /* descriptor type */ | 135 | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ |
| 145 | 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + | 136 | USBDESCR_CONFIG, /* descriptor type */ |
| 146 | (USB_CFG_DESCR_PROPS_HID & 0xff), 0, | 137 | 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + (USB_CFG_DESCR_PROPS_HID & 0xff), 0, |
| 147 | /* total length of data returned (including inlined descriptors) */ | 138 | /* total length of data returned (including inlined descriptors) */ |
| 148 | 1, /* number of interfaces in this configuration */ | 139 | 1, /* number of interfaces in this configuration */ |
| 149 | 1, /* index of this configuration */ | 140 | 1, /* index of this configuration */ |
| 150 | 0, /* configuration name string index */ | 141 | 0, /* configuration name string index */ |
| 151 | #if USB_CFG_IS_SELF_POWERED | 142 | # if USB_CFG_IS_SELF_POWERED |
| 152 | (1 << 7) | USBATTR_SELFPOWER, /* attributes */ | 143 | (1 << 7) | USBATTR_SELFPOWER, /* attributes */ |
| 153 | #else | 144 | # else |
| 154 | (1 << 7), /* attributes */ | 145 | (1 << 7), /* attributes */ |
| 155 | #endif | 146 | # endif |
| 156 | USB_CFG_MAX_BUS_POWER/2, /* max USB current in 2mA units */ | 147 | USB_CFG_MAX_BUS_POWER / 2, /* max USB current in 2mA units */ |
| 157 | /* interface descriptor follows inline: */ | 148 | /* interface descriptor follows inline: */ |
| 158 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ | 149 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ |
| 159 | USBDESCR_INTERFACE, /* descriptor type */ | 150 | USBDESCR_INTERFACE, /* descriptor type */ |
| 160 | 0, /* index of this interface */ | 151 | 0, /* index of this interface */ |
| 161 | 0, /* alternate setting for this interface */ | 152 | 0, /* alternate setting for this interface */ |
| 162 | USB_CFG_HAVE_INTRIN_ENDPOINT + USB_CFG_HAVE_INTRIN_ENDPOINT3, /* endpoints excl 0: number of endpoint descriptors to follow */ | 153 | USB_CFG_HAVE_INTRIN_ENDPOINT + USB_CFG_HAVE_INTRIN_ENDPOINT3, /* endpoints excl 0: number of endpoint descriptors to follow */ |
| 163 | USB_CFG_INTERFACE_CLASS, | 154 | USB_CFG_INTERFACE_CLASS, USB_CFG_INTERFACE_SUBCLASS, USB_CFG_INTERFACE_PROTOCOL, 0, /* string index for interface */ |
| 164 | USB_CFG_INTERFACE_SUBCLASS, | 155 | # if (USB_CFG_DESCR_PROPS_HID & 0xff) /* HID descriptor */ |
| 165 | USB_CFG_INTERFACE_PROTOCOL, | 156 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ |
| 166 | 0, /* string index for interface */ | 157 | USBDESCR_HID, /* descriptor type: HID */ |
| 167 | #if (USB_CFG_DESCR_PROPS_HID & 0xff) /* HID descriptor */ | 158 | 0x01, 0x01, /* BCD representation of HID version */ |
| 168 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ | 159 | 0x00, /* target country code */ |
| 169 | USBDESCR_HID, /* descriptor type: HID */ | 160 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ |
| 170 | 0x01, 0x01, /* BCD representation of HID version */ | 161 | 0x22, /* descriptor type: report */ |
| 171 | 0x00, /* target country code */ | 162 | USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 0, /* total length of report descriptor */ |
| 172 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ | 163 | # endif |
| 173 | 0x22, /* descriptor type: report */ | 164 | # if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */ |
| 174 | USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 0, /* total length of report descriptor */ | 165 | 7, /* sizeof(usbDescrEndpoint) */ |
| 175 | #endif | 166 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ |
| 176 | #if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */ | 167 | (char)0x81, /* IN endpoint number 1 */ |
| 177 | 7, /* sizeof(usbDescrEndpoint) */ | 168 | 0x03, /* attrib: Interrupt endpoint */ |
| 178 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ | 169 | 8, 0, /* maximum packet size */ |
| 179 | (char)0x81, /* IN endpoint number 1 */ | 170 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ |
| 180 | 0x03, /* attrib: Interrupt endpoint */ | 171 | # endif |
| 181 | 8, 0, /* maximum packet size */ | 172 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* endpoint descriptor for endpoint 3 */ |
| 182 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ | 173 | 7, /* sizeof(usbDescrEndpoint) */ |
| 183 | #endif | 174 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ |
| 184 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* endpoint descriptor for endpoint 3 */ | ||
| 185 | 7, /* sizeof(usbDescrEndpoint) */ | ||
| 186 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ | ||
| 187 | (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */ | 175 | (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */ |
| 188 | 0x03, /* attrib: Interrupt endpoint */ | 176 | 0x03, /* attrib: Interrupt endpoint */ |
| 189 | 8, 0, /* maximum packet size */ | 177 | 8, 0, /* maximum packet size */ |
| 190 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ | 178 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ |
| 191 | #endif | 179 | # endif |
| 192 | }; | 180 | }; |
| 193 | #endif | 181 | #endif |
| 194 | 182 | ||
| 195 | /* ------------------------------------------------------------------------- */ | 183 | /* ------------------------------------------------------------------------- */ |
| 196 | 184 | ||
| 197 | static inline void usbResetDataToggling(void) | 185 | static inline void usbResetDataToggling(void) { |
| 198 | { | ||
| 199 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE | 186 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE |
| 200 | USB_SET_DATATOKEN1(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */ | 187 | USB_SET_DATATOKEN1(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */ |
| 201 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 | 188 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 |
| 202 | USB_SET_DATATOKEN3(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */ | 189 | USB_SET_DATATOKEN3(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */ |
| 203 | # endif | 190 | # endif |
| 204 | #endif | 191 | #endif |
| 205 | } | 192 | } |
| 206 | 193 | ||
| 207 | static inline void usbResetStall(void) | 194 | static inline void usbResetStall(void) { |
| 208 | { | ||
| 209 | #if USB_CFG_IMPLEMENT_HALT && USB_CFG_HAVE_INTRIN_ENDPOINT | 195 | #if USB_CFG_IMPLEMENT_HALT && USB_CFG_HAVE_INTRIN_ENDPOINT |
| 210 | usbTxLen1 = USBPID_NAK; | 196 | usbTxLen1 = USBPID_NAK; |
| 211 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 | 197 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 |
| 212 | usbTxLen3 = USBPID_NAK; | 198 | usbTxLen3 = USBPID_NAK; |
| 213 | #endif | 199 | # endif |
| 214 | #endif | 200 | #endif |
| 215 | } | 201 | } |
| 216 | 202 | ||
| 217 | /* ------------------------------------------------------------------------- */ | 203 | /* ------------------------------------------------------------------------- */ |
| 218 | 204 | ||
| 219 | #if !USB_CFG_SUPPRESS_INTR_CODE | 205 | #if !USB_CFG_SUPPRESS_INTR_CODE |
| 220 | #if USB_CFG_HAVE_INTRIN_ENDPOINT | 206 | # if USB_CFG_HAVE_INTRIN_ENDPOINT |
| 221 | static void usbGenericSetInterrupt(uchar *data, uchar len, usbTxStatus_t *txStatus) | 207 | static void usbGenericSetInterrupt(uchar *data, uchar len, usbTxStatus_t *txStatus) { |
| 222 | { | 208 | uchar *p; |
| 223 | uchar *p; | 209 | char i; |
| 224 | char i; | 210 | |
| 225 | 211 | # if USB_CFG_IMPLEMENT_HALT | |
| 226 | #if USB_CFG_IMPLEMENT_HALT | 212 | if (usbTxLen1 == USBPID_STALL) return; |
| 227 | if(usbTxLen1 == USBPID_STALL) | 213 | # endif |
| 228 | return; | 214 | if (txStatus->len & 0x10) { /* packet buffer was empty */ |
| 229 | #endif | ||
| 230 | if(txStatus->len & 0x10){ /* packet buffer was empty */ | ||
| 231 | txStatus->buffer[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* toggle token */ | 215 | txStatus->buffer[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* toggle token */ |
| 232 | }else{ | 216 | } else { |
| 233 | txStatus->len = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */ | 217 | txStatus->len = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */ |
| 234 | } | 218 | } |
| 235 | p = txStatus->buffer + 1; | 219 | p = txStatus->buffer + 1; |
| 236 | i = len; | 220 | i = len; |
| 237 | do{ /* if len == 0, we still copy 1 byte, but that's no problem */ | 221 | do { /* if len == 0, we still copy 1 byte, but that's no problem */ |
| 238 | *p++ = *data++; | 222 | *p++ = *data++; |
| 239 | }while(--i > 0); /* loop control at the end is 2 bytes shorter than at beginning */ | 223 | } while (--i > 0); /* loop control at the end is 2 bytes shorter than at beginning */ |
| 240 | usbCrc16Append(&txStatus->buffer[1], len); | 224 | usbCrc16Append(&txStatus->buffer[1], len); |
| 241 | txStatus->len = len + 4; /* len must be given including sync byte */ | 225 | txStatus->len = len + 4; /* len must be given including sync byte */ |
| 242 | DBG2(0x21 + (((int)txStatus >> 3) & 3), txStatus->buffer, len + 3); | 226 | DBG2(0x21 + (((int)txStatus >> 3) & 3), txStatus->buffer, len + 3); |
| 243 | } | 227 | } |
| 244 | 228 | ||
| 245 | USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len) | 229 | USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len) { usbGenericSetInterrupt(data, len, &usbTxStatus1); } |
| 246 | { | 230 | # endif |
| 247 | usbGenericSetInterrupt(data, len, &usbTxStatus1); | ||
| 248 | } | ||
| 249 | #endif | ||
| 250 | 231 | ||
| 251 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 | 232 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 |
| 252 | USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) | 233 | USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) { usbGenericSetInterrupt(data, len, &usbTxStatus3); } |
| 253 | { | 234 | # endif |
| 254 | usbGenericSetInterrupt(data, len, &usbTxStatus3); | ||
| 255 | } | ||
| 256 | #endif | ||
| 257 | #endif /* USB_CFG_SUPPRESS_INTR_CODE */ | 235 | #endif /* USB_CFG_SUPPRESS_INTR_CODE */ |
| 258 | 236 | ||
| 259 | /* ------------------ utilities for code following below ------------------- */ | 237 | /* ------------------ utilities for code following below ------------------- */ |
| @@ -264,26 +242,58 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) | |||
| 264 | * cases. | 242 | * cases. |
| 265 | */ | 243 | */ |
| 266 | #if USB_CFG_USE_SWITCH_STATEMENT | 244 | #if USB_CFG_USE_SWITCH_STATEMENT |
| 267 | # define SWITCH_START(cmd) switch(cmd){{ | 245 | # define SWITCH_START(cmd) \ |
| 268 | # define SWITCH_CASE(value) }break; case (value):{ | 246 | switch (cmd) { \ |
| 269 | # define SWITCH_CASE2(v1,v2) }break; case (v1): case(v2):{ | 247 | { |
| 270 | # define SWITCH_CASE3(v1,v2,v3) }break; case (v1): case(v2): case(v3):{ | 248 | # define SWITCH_CASE(value) \ |
| 271 | # define SWITCH_DEFAULT }break; default:{ | 249 | } \ |
| 272 | # define SWITCH_END }} | 250 | break; \ |
| 251 | case (value): { | ||
| 252 | # define SWITCH_CASE2(v1, v2) \ | ||
| 253 | } \ | ||
| 254 | break; \ | ||
| 255 | case (v1): \ | ||
| 256 | case (v2): { | ||
| 257 | # define SWITCH_CASE3(v1, v2, v3) \ | ||
| 258 | } \ | ||
| 259 | break; \ | ||
| 260 | case (v1): \ | ||
| 261 | case (v2): \ | ||
| 262 | case (v3): { | ||
| 263 | # define SWITCH_DEFAULT \ | ||
| 264 | } \ | ||
| 265 | break; \ | ||
| 266 | default: { | ||
| 267 | # define SWITCH_END \ | ||
| 268 | } \ | ||
| 269 | } | ||
| 273 | #else | 270 | #else |
| 274 | # define SWITCH_START(cmd) {uchar _cmd = cmd; if(0){ | 271 | # define SWITCH_START(cmd) \ |
| 275 | # define SWITCH_CASE(value) }else if(_cmd == (value)){ | 272 | { \ |
| 276 | # define SWITCH_CASE2(v1,v2) }else if(_cmd == (v1) || _cmd == (v2)){ | 273 | uchar _cmd = cmd; \ |
| 277 | # define SWITCH_CASE3(v1,v2,v3) }else if(_cmd == (v1) || _cmd == (v2) || (_cmd == v3)){ | 274 | if (0) { |
| 278 | # define SWITCH_DEFAULT }else{ | 275 | # define SWITCH_CASE(value) \ |
| 279 | # define SWITCH_END }} | 276 | } \ |
| 277 | else if (_cmd == (value)) { | ||
| 278 | # define SWITCH_CASE2(v1, v2) \ | ||
| 279 | } \ | ||
| 280 | else if (_cmd == (v1) || _cmd == (v2)) { | ||
| 281 | # define SWITCH_CASE3(v1, v2, v3) \ | ||
| 282 | } \ | ||
| 283 | else if (_cmd == (v1) || _cmd == (v2) || (_cmd == v3)) { | ||
| 284 | # define SWITCH_DEFAULT \ | ||
| 285 | } \ | ||
| 286 | else { | ||
| 287 | # define SWITCH_END \ | ||
| 288 | } \ | ||
| 289 | } | ||
| 280 | #endif | 290 | #endif |
| 281 | 291 | ||
| 282 | #ifndef USB_RX_USER_HOOK | 292 | #ifndef USB_RX_USER_HOOK |
| 283 | #define USB_RX_USER_HOOK(data, len) | 293 | # define USB_RX_USER_HOOK(data, len) |
| 284 | #endif | 294 | #endif |
| 285 | #ifndef USB_SET_ADDRESS_HOOK | 295 | #ifndef USB_SET_ADDRESS_HOOK |
| 286 | #define USB_SET_ADDRESS_HOOK() | 296 | # define USB_SET_ADDRESS_HOOK() |
| 287 | #endif | 297 | #endif |
| 288 | 298 | ||
| 289 | /* ------------------------------------------------------------------------- */ | 299 | /* ------------------------------------------------------------------------- */ |
| @@ -293,62 +303,59 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) | |||
| 293 | * This may cause problems with undefined symbols if compiled without | 303 | * This may cause problems with undefined symbols if compiled without |
| 294 | * optimizing! | 304 | * optimizing! |
| 295 | */ | 305 | */ |
| 296 | #define GET_DESCRIPTOR(cfgProp, staticName) \ | 306 | #define GET_DESCRIPTOR(cfgProp, staticName) \ |
| 297 | if(cfgProp){ \ | 307 | if (cfgProp) { \ |
| 298 | if((cfgProp) & USB_PROP_IS_RAM) \ | 308 | if ((cfgProp)&USB_PROP_IS_RAM) flags = 0; \ |
| 299 | flags = 0; \ | 309 | if ((cfgProp)&USB_PROP_IS_DYNAMIC) { \ |
| 300 | if((cfgProp) & USB_PROP_IS_DYNAMIC){ \ | 310 | len = usbFunctionDescriptor(rq); \ |
| 301 | len = usbFunctionDescriptor(rq); \ | 311 | } else { \ |
| 302 | }else{ \ | 312 | len = USB_PROP_LENGTH(cfgProp); \ |
| 303 | len = USB_PROP_LENGTH(cfgProp); \ | 313 | usbMsgPtr = (uchar *)(staticName); \ |
| 304 | usbMsgPtr = (uchar *)(staticName); \ | 314 | } \ |
| 305 | } \ | ||
| 306 | } | 315 | } |
| 307 | 316 | ||
| 308 | /* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used | 317 | /* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used |
| 309 | * internally for all types of descriptors. | 318 | * internally for all types of descriptors. |
| 310 | */ | 319 | */ |
| 311 | static inline usbMsgLen_t usbDriverDescriptor(usbRequest_t *rq) | 320 | static inline usbMsgLen_t usbDriverDescriptor(usbRequest_t *rq) { |
| 312 | { | 321 | usbMsgLen_t len = 0; |
| 313 | usbMsgLen_t len = 0; | 322 | uchar flags = USB_FLG_MSGPTR_IS_ROM; |
| 314 | uchar flags = USB_FLG_MSGPTR_IS_ROM; | ||
| 315 | 323 | ||
| 316 | SWITCH_START(rq->wValue.bytes[1]) | 324 | SWITCH_START(rq->wValue.bytes[1]) |
| 317 | SWITCH_CASE(USBDESCR_DEVICE) /* 1 */ | 325 | SWITCH_CASE(USBDESCR_DEVICE) /* 1 */ |
| 318 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice) | 326 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice) |
| 319 | SWITCH_CASE(USBDESCR_CONFIG) /* 2 */ | 327 | SWITCH_CASE(USBDESCR_CONFIG) /* 2 */ |
| 320 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration) | 328 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration) |
| 321 | SWITCH_CASE(USBDESCR_STRING) /* 3 */ | 329 | SWITCH_CASE(USBDESCR_STRING) /* 3 */ |
| 322 | #if USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC | 330 | #if USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC |
| 323 | if(USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM) | 331 | if (USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM) flags = 0; |
| 324 | flags = 0; | 332 | len = usbFunctionDescriptor(rq); |
| 333 | #else /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ | ||
| 334 | SWITCH_START(rq->wValue.bytes[0]) | ||
| 335 | SWITCH_CASE(0) | ||
| 336 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0) | ||
| 337 | SWITCH_CASE(1) | ||
| 338 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor) | ||
| 339 | SWITCH_CASE(2) | ||
| 340 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice) | ||
| 341 | SWITCH_CASE(3) | ||
| 342 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber) | ||
| 343 | SWITCH_DEFAULT | ||
| 344 | if (USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC) { | ||
| 325 | len = usbFunctionDescriptor(rq); | 345 | len = usbFunctionDescriptor(rq); |
| 326 | #else /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ | 346 | } |
| 327 | SWITCH_START(rq->wValue.bytes[0]) | 347 | SWITCH_END |
| 328 | SWITCH_CASE(0) | 348 | #endif /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ |
| 329 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0) | 349 | #if USB_CFG_DESCR_PROPS_HID_REPORT /* only support HID descriptors if enabled */ |
| 330 | SWITCH_CASE(1) | 350 | SWITCH_CASE(USBDESCR_HID) /* 0x21 */ |
| 331 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor) | 351 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18) |
| 332 | SWITCH_CASE(2) | 352 | SWITCH_CASE(USBDESCR_HID_REPORT) /* 0x22 */ |
| 333 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice) | 353 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport) |
| 334 | SWITCH_CASE(3) | ||
| 335 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber) | ||
| 336 | SWITCH_DEFAULT | ||
| 337 | if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){ | ||
| 338 | len = usbFunctionDescriptor(rq); | ||
| 339 | } | ||
| 340 | SWITCH_END | ||
| 341 | #endif /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ | ||
| 342 | #if USB_CFG_DESCR_PROPS_HID_REPORT /* only support HID descriptors if enabled */ | ||
| 343 | SWITCH_CASE(USBDESCR_HID) /* 0x21 */ | ||
| 344 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18) | ||
| 345 | SWITCH_CASE(USBDESCR_HID_REPORT)/* 0x22 */ | ||
| 346 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport) | ||
| 347 | #endif | 354 | #endif |
| 348 | SWITCH_DEFAULT | 355 | SWITCH_DEFAULT |
| 349 | if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){ | 356 | if (USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC) { |
| 350 | len = usbFunctionDescriptor(rq); | 357 | len = usbFunctionDescriptor(rq); |
| 351 | } | 358 | } |
| 352 | SWITCH_END | 359 | SWITCH_END |
| 353 | usbMsgFlags = flags; | 360 | usbMsgFlags = flags; |
| 354 | return len; | 361 | return len; |
| @@ -359,56 +366,53 @@ uchar flags = USB_FLG_MSGPTR_IS_ROM; | |||
| 359 | /* usbDriverSetup() is similar to usbFunctionSetup(), but it's used for | 366 | /* usbDriverSetup() is similar to usbFunctionSetup(), but it's used for |
| 360 | * standard requests instead of class and custom requests. | 367 | * standard requests instead of class and custom requests. |
| 361 | */ | 368 | */ |
| 362 | static inline usbMsgLen_t usbDriverSetup(usbRequest_t *rq) | 369 | static inline usbMsgLen_t usbDriverSetup(usbRequest_t *rq) { |
| 363 | { | 370 | uchar len = 0, *dataPtr = usbTxBuf + 9; /* there are 2 bytes free space at the end of the buffer */ |
| 364 | uchar len = 0, *dataPtr = usbTxBuf + 9; /* there are 2 bytes free space at the end of the buffer */ | 371 | uchar value = rq->wValue.bytes[0]; |
| 365 | uchar value = rq->wValue.bytes[0]; | ||
| 366 | #if USB_CFG_IMPLEMENT_HALT | 372 | #if USB_CFG_IMPLEMENT_HALT |
| 367 | uchar index = rq->wIndex.bytes[0]; | 373 | uchar index = rq->wIndex.bytes[0]; |
| 368 | #endif | 374 | #endif |
| 369 | 375 | ||
| 370 | dataPtr[0] = 0; /* default reply common to USBRQ_GET_STATUS and USBRQ_GET_INTERFACE */ | 376 | dataPtr[0] = 0; /* default reply common to USBRQ_GET_STATUS and USBRQ_GET_INTERFACE */ |
| 371 | SWITCH_START(rq->bRequest) | 377 | SWITCH_START(rq->bRequest) |
| 372 | SWITCH_CASE(USBRQ_GET_STATUS) /* 0 */ | 378 | SWITCH_CASE(USBRQ_GET_STATUS) /* 0 */ |
| 373 | uchar recipient = rq->bmRequestType & USBRQ_RCPT_MASK; /* assign arith ops to variables to enforce byte size */ | 379 | uchar recipient = rq->bmRequestType & USBRQ_RCPT_MASK; /* assign arith ops to variables to enforce byte size */ |
| 374 | if(USB_CFG_IS_SELF_POWERED && recipient == USBRQ_RCPT_DEVICE) | 380 | if (USB_CFG_IS_SELF_POWERED && recipient == USBRQ_RCPT_DEVICE) dataPtr[0] = USB_CFG_IS_SELF_POWERED; |
| 375 | dataPtr[0] = USB_CFG_IS_SELF_POWERED; | ||
| 376 | #if USB_CFG_IMPLEMENT_HALT | 381 | #if USB_CFG_IMPLEMENT_HALT |
| 377 | if(recipient == USBRQ_RCPT_ENDPOINT && index == 0x81) /* request status for endpoint 1 */ | 382 | if (recipient == USBRQ_RCPT_ENDPOINT && index == 0x81) /* request status for endpoint 1 */ |
| 378 | dataPtr[0] = usbTxLen1 == USBPID_STALL; | 383 | dataPtr[0] = usbTxLen1 == USBPID_STALL; |
| 379 | #endif | 384 | #endif |
| 380 | dataPtr[1] = 0; | 385 | dataPtr[1] = 0; |
| 381 | len = 2; | 386 | len = 2; |
| 382 | #if USB_CFG_IMPLEMENT_HALT | 387 | #if USB_CFG_IMPLEMENT_HALT |
| 383 | SWITCH_CASE2(USBRQ_CLEAR_FEATURE, USBRQ_SET_FEATURE) /* 1, 3 */ | 388 | SWITCH_CASE2(USBRQ_CLEAR_FEATURE, USBRQ_SET_FEATURE) /* 1, 3 */ |
| 384 | if(value == 0 && index == 0x81){ /* feature 0 == HALT for endpoint == 1 */ | 389 | if (value == 0 && index == 0x81) { /* feature 0 == HALT for endpoint == 1 */ |
| 385 | usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL; | 390 | usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL; |
| 386 | usbResetDataToggling(); | 391 | usbResetDataToggling(); |
| 387 | } | 392 | } |
| 388 | #endif | 393 | #endif |
| 389 | SWITCH_CASE(USBRQ_SET_ADDRESS) /* 5 */ | 394 | SWITCH_CASE(USBRQ_SET_ADDRESS) /* 5 */ |
| 390 | usbNewDeviceAddr = value; | 395 | usbNewDeviceAddr = value; |
| 391 | USB_SET_ADDRESS_HOOK(); | 396 | USB_SET_ADDRESS_HOOK(); |
| 392 | SWITCH_CASE(USBRQ_GET_DESCRIPTOR) /* 6 */ | 397 | SWITCH_CASE(USBRQ_GET_DESCRIPTOR) /* 6 */ |
| 393 | len = usbDriverDescriptor(rq); | 398 | len = usbDriverDescriptor(rq); |
| 394 | goto skipMsgPtrAssignment; | 399 | goto skipMsgPtrAssignment; |
| 395 | SWITCH_CASE(USBRQ_GET_CONFIGURATION) /* 8 */ | 400 | SWITCH_CASE(USBRQ_GET_CONFIGURATION) /* 8 */ |
| 396 | dataPtr = &usbConfiguration; /* send current configuration value */ | 401 | dataPtr = &usbConfiguration; /* send current configuration value */ |
| 397 | len = 1; | 402 | len = 1; |
| 398 | SWITCH_CASE(USBRQ_SET_CONFIGURATION) /* 9 */ | 403 | SWITCH_CASE(USBRQ_SET_CONFIGURATION) /* 9 */ |
| 399 | usbConfiguration = value; | 404 | usbConfiguration = value; |
| 400 | usbResetStall(); | 405 | usbResetStall(); |
| 401 | SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */ | 406 | SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */ |
| 402 | len = 1; | 407 | len = 1; |
| 403 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE | 408 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE |
| 404 | SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */ | 409 | SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */ |
| 405 | usbResetDataToggling(); | 410 | usbResetDataToggling(); |
| 406 | usbResetStall(); | 411 | usbResetStall(); |
| 407 | #endif | 412 | #endif |
| 408 | SWITCH_DEFAULT /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */ | 413 | SWITCH_DEFAULT /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */ |
| 409 | /* Should we add an optional hook here? */ | 414 | /* Should we add an optional hook here? */ |
| 410 | SWITCH_END | 415 | SWITCH_END usbMsgPtr = dataPtr; |
| 411 | usbMsgPtr = dataPtr; | ||
| 412 | skipMsgPtrAssignment: | 416 | skipMsgPtrAssignment: |
| 413 | return len; | 417 | return len; |
| 414 | } | 418 | } |
| @@ -419,65 +423,64 @@ skipMsgPtrAssignment: | |||
| 419 | * routine. It distinguishes between SETUP and DATA packets and processes | 423 | * routine. It distinguishes between SETUP and DATA packets and processes |
| 420 | * them accordingly. | 424 | * them accordingly. |
| 421 | */ | 425 | */ |
| 422 | static inline void usbProcessRx(uchar *data, uchar len) | 426 | static inline void usbProcessRx(uchar *data, uchar len) { |
| 423 | { | 427 | usbRequest_t *rq = (void *)data; |
| 424 | usbRequest_t *rq = (void *)data; | 428 | |
| 425 | 429 | /* usbRxToken can be: | |
| 426 | /* usbRxToken can be: | 430 | * 0x2d 00101101 (USBPID_SETUP for setup data) |
| 427 | * 0x2d 00101101 (USBPID_SETUP for setup data) | 431 | * 0xe1 11100001 (USBPID_OUT: data phase of setup transfer) |
| 428 | * 0xe1 11100001 (USBPID_OUT: data phase of setup transfer) | 432 | * 0...0x0f for OUT on endpoint X |
| 429 | * 0...0x0f for OUT on endpoint X | 433 | */ |
| 430 | */ | ||
| 431 | DBG2(0x10 + (usbRxToken & 0xf), data, len + 2); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */ | 434 | DBG2(0x10 + (usbRxToken & 0xf), data, len + 2); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */ |
| 432 | USB_RX_USER_HOOK(data, len) | 435 | USB_RX_USER_HOOK(data, len) |
| 433 | #if USB_CFG_IMPLEMENT_FN_WRITEOUT | 436 | #if USB_CFG_IMPLEMENT_FN_WRITEOUT |
| 434 | if(usbRxToken < 0x10){ /* OUT to endpoint != 0: endpoint number in usbRxToken */ | 437 | if (usbRxToken < 0x10) { /* OUT to endpoint != 0: endpoint number in usbRxToken */ |
| 435 | usbFunctionWriteOut(data, len); | 438 | usbFunctionWriteOut(data, len); |
| 436 | return; | 439 | return; |
| 437 | } | 440 | } |
| 438 | #endif | 441 | #endif |
| 439 | if(usbRxToken == (uchar)USBPID_SETUP){ | 442 | if (usbRxToken == (uchar)USBPID_SETUP) { |
| 440 | if(len != 8) /* Setup size must be always 8 bytes. Ignore otherwise. */ | 443 | if (len != 8) /* Setup size must be always 8 bytes. Ignore otherwise. */ |
| 441 | return; | 444 | return; |
| 442 | usbMsgLen_t replyLen; | 445 | usbMsgLen_t replyLen; |
| 443 | usbTxBuf[0] = USBPID_DATA0; /* initialize data toggling */ | 446 | usbTxBuf[0] = USBPID_DATA0; /* initialize data toggling */ |
| 444 | usbTxLen = USBPID_NAK; /* abort pending transmit */ | 447 | usbTxLen = USBPID_NAK; /* abort pending transmit */ |
| 445 | usbMsgFlags = 0; | 448 | usbMsgFlags = 0; |
| 446 | uchar type = rq->bmRequestType & USBRQ_TYPE_MASK; | 449 | uchar type = rq->bmRequestType & USBRQ_TYPE_MASK; |
| 447 | if(type != USBRQ_TYPE_STANDARD){ /* standard requests are handled by driver */ | 450 | if (type != USBRQ_TYPE_STANDARD) { /* standard requests are handled by driver */ |
| 448 | replyLen = usbFunctionSetup(data); | 451 | replyLen = usbFunctionSetup(data); |
| 449 | }else{ | 452 | } else { |
| 450 | replyLen = usbDriverSetup(rq); | 453 | replyLen = usbDriverSetup(rq); |
| 451 | } | 454 | } |
| 452 | #if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE | 455 | #if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE |
| 453 | if(replyLen == USB_NO_MSG){ /* use user-supplied read/write function */ | 456 | if (replyLen == USB_NO_MSG) { /* use user-supplied read/write function */ |
| 454 | /* do some conditioning on replyLen, but on IN transfers only */ | 457 | /* do some conditioning on replyLen, but on IN transfers only */ |
| 455 | if((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE){ | 458 | if ((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE) { |
| 456 | if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */ | 459 | if (sizeof(replyLen) < sizeof(rq->wLength.word)) { /* help compiler with optimizing */ |
| 457 | replyLen = rq->wLength.bytes[0]; | 460 | replyLen = rq->wLength.bytes[0]; |
| 458 | }else{ | 461 | } else { |
| 459 | replyLen = rq->wLength.word; | 462 | replyLen = rq->wLength.word; |
| 460 | } | 463 | } |
| 461 | } | 464 | } |
| 462 | usbMsgFlags = USB_FLG_USE_USER_RW; | 465 | usbMsgFlags = USB_FLG_USE_USER_RW; |
| 463 | }else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */ | 466 | } else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */ |
| 464 | #endif | 467 | #endif |
| 465 | if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */ | 468 | if (sizeof(replyLen) < sizeof(rq->wLength.word)) { /* help compiler with optimizing */ |
| 466 | if(!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0]) /* limit length to max */ | 469 | if (!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0]) /* limit length to max */ |
| 467 | replyLen = rq->wLength.bytes[0]; | 470 | replyLen = rq->wLength.bytes[0]; |
| 468 | }else{ | 471 | } else { |
| 469 | if(replyLen > rq->wLength.word) /* limit length to max */ | 472 | if (replyLen > rq->wLength.word) /* limit length to max */ |
| 470 | replyLen = rq->wLength.word; | 473 | replyLen = rq->wLength.word; |
| 471 | } | 474 | } |
| 472 | usbMsgLen = replyLen; | 475 | usbMsgLen = replyLen; |
| 473 | }else{ /* usbRxToken must be USBPID_OUT, which means data phase of setup (control-out) */ | 476 | } else { /* usbRxToken must be USBPID_OUT, which means data phase of setup (control-out) */ |
| 474 | #if USB_CFG_IMPLEMENT_FN_WRITE | 477 | #if USB_CFG_IMPLEMENT_FN_WRITE |
| 475 | if(usbMsgFlags & USB_FLG_USE_USER_RW){ | 478 | if (usbMsgFlags & USB_FLG_USE_USER_RW) { |
| 476 | uchar rval = usbFunctionWrite(data, len); | 479 | uchar rval = usbFunctionWrite(data, len); |
| 477 | if(rval == 0xff){ /* an error occurred */ | 480 | if (rval == 0xff) { /* an error occurred */ |
| 478 | usbTxLen = USBPID_STALL; | 481 | usbTxLen = USBPID_STALL; |
| 479 | }else if(rval != 0){ /* This was the final package */ | 482 | } else if (rval != 0) { /* This was the final package */ |
| 480 | usbMsgLen = 0; /* answer with a zero-sized data packet */ | 483 | usbMsgLen = 0; /* answer with a zero-sized data packet */ |
| 481 | } | 484 | } |
| 482 | } | 485 | } |
| 483 | #endif | 486 | #endif |
| @@ -489,26 +492,25 @@ usbRequest_t *rq = (void *)data; | |||
| 489 | /* This function is similar to usbFunctionRead(), but it's also called for | 492 | /* This function is similar to usbFunctionRead(), but it's also called for |
| 490 | * data handled automatically by the driver (e.g. descriptor reads). | 493 | * data handled automatically by the driver (e.g. descriptor reads). |
| 491 | */ | 494 | */ |
| 492 | static uchar usbDeviceRead(uchar *data, uchar len) | 495 | static uchar usbDeviceRead(uchar *data, uchar len) { |
| 493 | { | 496 | if (len > 0) { /* don't bother app with 0 sized reads */ |
| 494 | if(len > 0){ /* don't bother app with 0 sized reads */ | ||
| 495 | #if USB_CFG_IMPLEMENT_FN_READ | 497 | #if USB_CFG_IMPLEMENT_FN_READ |
| 496 | if(usbMsgFlags & USB_FLG_USE_USER_RW){ | 498 | if (usbMsgFlags & USB_FLG_USE_USER_RW) { |
| 497 | len = usbFunctionRead(data, len); | 499 | len = usbFunctionRead(data, len); |
| 498 | }else | 500 | } else |
| 499 | #endif | 501 | #endif |
| 500 | { | 502 | { |
| 501 | uchar i = len, *r = usbMsgPtr; | 503 | uchar i = len, *r = usbMsgPtr; |
| 502 | if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */ | 504 | if (usbMsgFlags & USB_FLG_MSGPTR_IS_ROM) { /* ROM data */ |
| 503 | do{ | 505 | do { |
| 504 | uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */ | 506 | uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */ |
| 505 | *data++ = c; | 507 | *data++ = c; |
| 506 | r++; | 508 | r++; |
| 507 | }while(--i); | 509 | } while (--i); |
| 508 | }else{ /* RAM data */ | 510 | } else { /* RAM data */ |
| 509 | do{ | 511 | do { |
| 510 | *data++ = *r++; | 512 | *data++ = *r++; |
| 511 | }while(--i); | 513 | } while (--i); |
| 512 | } | 514 | } |
| 513 | usbMsgPtr = r; | 515 | usbMsgPtr = r; |
| 514 | } | 516 | } |
| @@ -521,39 +523,36 @@ static uchar usbDeviceRead(uchar *data, uchar len) | |||
| 521 | /* usbBuildTxBlock() is called when we have data to transmit and the | 523 | /* usbBuildTxBlock() is called when we have data to transmit and the |
| 522 | * interrupt routine's transmit buffer is empty. | 524 | * interrupt routine's transmit buffer is empty. |
| 523 | */ | 525 | */ |
| 524 | static inline void usbBuildTxBlock(void) | 526 | static inline void usbBuildTxBlock(void) { |
| 525 | { | 527 | usbMsgLen_t wantLen; |
| 526 | usbMsgLen_t wantLen; | 528 | uchar len; |
| 527 | uchar len; | ||
| 528 | 529 | ||
| 529 | wantLen = usbMsgLen; | 530 | wantLen = usbMsgLen; |
| 530 | if(wantLen > 8) | 531 | if (wantLen > 8) wantLen = 8; |
| 531 | wantLen = 8; | ||
| 532 | usbMsgLen -= wantLen; | 532 | usbMsgLen -= wantLen; |
| 533 | usbTxBuf[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* DATA toggling */ | 533 | usbTxBuf[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* DATA toggling */ |
| 534 | len = usbDeviceRead(usbTxBuf + 1, wantLen); | 534 | len = usbDeviceRead(usbTxBuf + 1, wantLen); |
| 535 | if(len <= 8){ /* valid data packet */ | 535 | if (len <= 8) { /* valid data packet */ |
| 536 | usbCrc16Append(&usbTxBuf[1], len); | 536 | usbCrc16Append(&usbTxBuf[1], len); |
| 537 | len += 4; /* length including sync byte */ | 537 | len += 4; /* length including sync byte */ |
| 538 | if(len < 12) /* a partial package identifies end of message */ | 538 | if (len < 12) /* a partial package identifies end of message */ |
| 539 | usbMsgLen = USB_NO_MSG; | 539 | usbMsgLen = USB_NO_MSG; |
| 540 | }else{ | 540 | } else { |
| 541 | len = USBPID_STALL; /* stall the endpoint */ | 541 | len = USBPID_STALL; /* stall the endpoint */ |
| 542 | usbMsgLen = USB_NO_MSG; | 542 | usbMsgLen = USB_NO_MSG; |
| 543 | } | 543 | } |
| 544 | usbTxLen = len; | 544 | usbTxLen = len; |
| 545 | DBG2(0x20, usbTxBuf, len-1); | 545 | DBG2(0x20, usbTxBuf, len - 1); |
| 546 | } | 546 | } |
| 547 | 547 | ||
| 548 | /* ------------------------------------------------------------------------- */ | 548 | /* ------------------------------------------------------------------------- */ |
| 549 | 549 | ||
| 550 | static inline void usbHandleResetHook(uchar notResetState) | 550 | static inline void usbHandleResetHook(uchar notResetState) { |
| 551 | { | ||
| 552 | #ifdef USB_RESET_HOOK | 551 | #ifdef USB_RESET_HOOK |
| 553 | static uchar wasReset; | 552 | static uchar wasReset; |
| 554 | uchar isReset = !notResetState; | 553 | uchar isReset = !notResetState; |
| 555 | 554 | ||
| 556 | if(wasReset != isReset){ | 555 | if (wasReset != isReset) { |
| 557 | USB_RESET_HOOK(isReset); | 556 | USB_RESET_HOOK(isReset); |
| 558 | wasReset = isReset; | 557 | wasReset = isReset; |
| 559 | } | 558 | } |
| @@ -562,40 +561,39 @@ uchar isReset = !notResetState; | |||
| 562 | 561 | ||
| 563 | /* ------------------------------------------------------------------------- */ | 562 | /* ------------------------------------------------------------------------- */ |
| 564 | 563 | ||
| 565 | USB_PUBLIC void usbPoll(void) | 564 | USB_PUBLIC void usbPoll(void) { |
| 566 | { | 565 | schar len; |
| 567 | schar len; | 566 | uchar i; |
| 568 | uchar i; | ||
| 569 | 567 | ||
| 570 | len = usbRxLen - 3; | 568 | len = usbRxLen - 3; |
| 571 | if(len >= 0){ | 569 | if (len >= 0) { |
| 572 | /* We could check CRC16 here -- but ACK has already been sent anyway. If you | 570 | /* We could check CRC16 here -- but ACK has already been sent anyway. If you |
| 573 | * need data integrity checks with this driver, check the CRC in your app | 571 | * need data integrity checks with this driver, check the CRC in your app |
| 574 | * code and report errors back to the host. Since the ACK was already sent, | 572 | * code and report errors back to the host. Since the ACK was already sent, |
| 575 | * retries must be handled on application level. | 573 | * retries must be handled on application level. |
| 576 | * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3); | 574 | * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3); |
| 577 | */ | 575 | */ |
| 578 | usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len); | 576 | usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len); |
| 579 | #if USB_CFG_HAVE_FLOWCONTROL | 577 | #if USB_CFG_HAVE_FLOWCONTROL |
| 580 | if(usbRxLen > 0) /* only mark as available if not inactivated */ | 578 | if (usbRxLen > 0) /* only mark as available if not inactivated */ |
| 581 | usbRxLen = 0; | 579 | usbRxLen = 0; |
| 582 | #else | 580 | #else |
| 583 | usbRxLen = 0; /* mark rx buffer as available */ | 581 | usbRxLen = 0; /* mark rx buffer as available */ |
| 584 | #endif | 582 | #endif |
| 585 | } | 583 | } |
| 586 | if(usbTxLen & 0x10){ /* transmit system idle */ | 584 | if (usbTxLen & 0x10) { /* transmit system idle */ |
| 587 | if(usbMsgLen != USB_NO_MSG){ /* transmit data pending? */ | 585 | if (usbMsgLen != USB_NO_MSG) { /* transmit data pending? */ |
| 588 | usbBuildTxBlock(); | 586 | usbBuildTxBlock(); |
| 589 | } | 587 | } |
| 590 | } | 588 | } |
| 591 | for(i = 20; i > 0; i--){ | 589 | for (i = 20; i > 0; i--) { |
| 592 | uchar usbLineStatus = USBIN & USBMASK; | 590 | uchar usbLineStatus = USBIN & USBMASK; |
| 593 | if(usbLineStatus != 0) /* SE0 has ended */ | 591 | if (usbLineStatus != 0) /* SE0 has ended */ |
| 594 | goto isNotReset; | 592 | goto isNotReset; |
| 595 | } | 593 | } |
| 596 | /* RESET condition, called multiple times during reset */ | 594 | /* RESET condition, called multiple times during reset */ |
| 597 | usbNewDeviceAddr = 0; | 595 | usbNewDeviceAddr = 0; |
| 598 | usbDeviceAddr = 0; | 596 | usbDeviceAddr = 0; |
| 599 | usbResetStall(); | 597 | usbResetStall(); |
| 600 | DBG1(0xff, 0, 0); | 598 | DBG1(0xff, 0, 0); |
| 601 | isNotReset: | 599 | isNotReset: |
| @@ -604,8 +602,7 @@ isNotReset: | |||
| 604 | 602 | ||
| 605 | /* ------------------------------------------------------------------------- */ | 603 | /* ------------------------------------------------------------------------- */ |
| 606 | 604 | ||
| 607 | USB_PUBLIC void usbInit(void) | 605 | USB_PUBLIC void usbInit(void) { |
| 608 | { | ||
| 609 | #if USB_INTR_CFG_SET != 0 | 606 | #if USB_INTR_CFG_SET != 0 |
| 610 | USB_INTR_CFG |= USB_INTR_CFG_SET; | 607 | USB_INTR_CFG |= USB_INTR_CFG_SET; |
| 611 | #endif | 608 | #endif |
| @@ -616,9 +613,9 @@ USB_PUBLIC void usbInit(void) | |||
| 616 | usbResetDataToggling(); | 613 | usbResetDataToggling(); |
| 617 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE | 614 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE |
| 618 | usbTxLen1 = USBPID_NAK; | 615 | usbTxLen1 = USBPID_NAK; |
| 619 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 | 616 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 |
| 620 | usbTxLen3 = USBPID_NAK; | 617 | usbTxLen3 = USBPID_NAK; |
| 621 | #endif | 618 | # endif |
| 622 | #endif | 619 | #endif |
| 623 | } | 620 | } |
| 624 | 621 | ||
diff --git a/tmk_core/protocol/vusb/usbdrv/usbdrv.h b/tmk_core/protocol/vusb/usbdrv/usbdrv.h index 42fe16372..88a1bce76 100644 --- a/tmk_core/protocol/vusb/usbdrv/usbdrv.h +++ b/tmk_core/protocol/vusb/usbdrv/usbdrv.h | |||
| @@ -122,7 +122,7 @@ USB messages, even if they address another (low-speed) device on the same bus. | |||
| 122 | /* --------------------------- Module Interface ---------------------------- */ | 122 | /* --------------------------- Module Interface ---------------------------- */ |
| 123 | /* ------------------------------------------------------------------------- */ | 123 | /* ------------------------------------------------------------------------- */ |
| 124 | 124 | ||
| 125 | #define USBDRV_VERSION 20100715 | 125 | #define USBDRV_VERSION 20100715 |
| 126 | /* This define uniquely identifies a driver version. It is a decimal number | 126 | /* This define uniquely identifies a driver version. It is a decimal number |
| 127 | * constructed from the driver's release date in the form YYYYMMDD. If the | 127 | * constructed from the driver's release date in the form YYYYMMDD. If the |
| 128 | * driver's behavior or interface changes, you can use this constant to | 128 | * driver's behavior or interface changes, you can use this constant to |
| @@ -130,9 +130,8 @@ USB messages, even if they address another (low-speed) device on the same bus. | |||
| 130 | * older than 2006-01-25. | 130 | * older than 2006-01-25. |
| 131 | */ | 131 | */ |
| 132 | 132 | ||
| 133 | |||
| 134 | #ifndef USB_PUBLIC | 133 | #ifndef USB_PUBLIC |
| 135 | #define USB_PUBLIC | 134 | # define USB_PUBLIC |
| 136 | #endif | 135 | #endif |
| 137 | /* USB_PUBLIC is used as declaration attribute for all functions exported by | 136 | /* USB_PUBLIC is used as declaration attribute for all functions exported by |
| 138 | * the USB driver. The default is no attribute (see above). You may define it | 137 | * the USB driver. The default is no attribute (see above). You may define it |
| @@ -142,28 +141,28 @@ USB messages, even if they address another (low-speed) device on the same bus. | |||
| 142 | */ | 141 | */ |
| 143 | 142 | ||
| 144 | #ifndef __ASSEMBLER__ | 143 | #ifndef __ASSEMBLER__ |
| 145 | #ifndef uchar | 144 | # ifndef uchar |
| 146 | #define uchar unsigned char | 145 | # define uchar unsigned char |
| 147 | #endif | 146 | # endif |
| 148 | #ifndef schar | 147 | # ifndef schar |
| 149 | #define schar signed char | 148 | # define schar signed char |
| 150 | #endif | 149 | # endif |
| 151 | /* shortcuts for well defined 8 bit integer types */ | 150 | /* shortcuts for well defined 8 bit integer types */ |
| 152 | 151 | ||
| 153 | #if USB_CFG_LONG_TRANSFERS /* if more than 254 bytes transfer size required */ | 152 | # if USB_CFG_LONG_TRANSFERS /* if more than 254 bytes transfer size required */ |
| 154 | # define usbMsgLen_t unsigned | 153 | # define usbMsgLen_t unsigned |
| 155 | #else | 154 | # else |
| 156 | # define usbMsgLen_t uchar | 155 | # define usbMsgLen_t uchar |
| 157 | #endif | 156 | # endif |
| 158 | /* usbMsgLen_t is the data type used for transfer lengths. By default, it is | 157 | /* usbMsgLen_t is the data type used for transfer lengths. By default, it is |
| 159 | * defined to uchar, allowing a maximum of 254 bytes (255 is reserved for | 158 | * defined to uchar, allowing a maximum of 254 bytes (255 is reserved for |
| 160 | * USB_NO_MSG below). If the usbconfig.h defines USB_CFG_LONG_TRANSFERS to 1, | 159 | * USB_NO_MSG below). If the usbconfig.h defines USB_CFG_LONG_TRANSFERS to 1, |
| 161 | * a 16 bit data type is used, allowing up to 16384 bytes (the rest is used | 160 | * a 16 bit data type is used, allowing up to 16384 bytes (the rest is used |
| 162 | * for flags in the descriptor configuration). | 161 | * for flags in the descriptor configuration). |
| 163 | */ | 162 | */ |
| 164 | #define USB_NO_MSG ((usbMsgLen_t)-1) /* constant meaning "no message" */ | 163 | # define USB_NO_MSG ((usbMsgLen_t)-1) /* constant meaning "no message" */ |
| 165 | 164 | ||
| 166 | struct usbRequest; /* forward declaration */ | 165 | struct usbRequest; /* forward declaration */ |
| 167 | 166 | ||
| 168 | USB_PUBLIC void usbInit(void); | 167 | USB_PUBLIC void usbInit(void); |
| 169 | /* This function must be called before interrupts are enabled and the main | 168 | /* This function must be called before interrupts are enabled and the main |
| @@ -216,7 +215,7 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq); | |||
| 216 | * usbFunctionSetup() above, but it is called only to request USB descriptor | 215 | * usbFunctionSetup() above, but it is called only to request USB descriptor |
| 217 | * data. See the documentation of usbFunctionSetup() above for more info. | 216 | * data. See the documentation of usbFunctionSetup() above for more info. |
| 218 | */ | 217 | */ |
| 219 | #if USB_CFG_HAVE_INTRIN_ENDPOINT | 218 | # if USB_CFG_HAVE_INTRIN_ENDPOINT |
| 220 | USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len); | 219 | USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len); |
| 221 | /* This function sets the message which will be sent during the next interrupt | 220 | /* This function sets the message which will be sent during the next interrupt |
| 222 | * IN transfer. The message is copied to an internal buffer and must not exceed | 221 | * IN transfer. The message is copied to an internal buffer and must not exceed |
| @@ -224,19 +223,19 @@ USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len); | |||
| 224 | * interrupt status to the host. | 223 | * interrupt status to the host. |
| 225 | * If you need to transfer more bytes, use a control read after the interrupt. | 224 | * If you need to transfer more bytes, use a control read after the interrupt. |
| 226 | */ | 225 | */ |
| 227 | #define usbInterruptIsReady() (usbTxLen1 & 0x10) | 226 | # define usbInterruptIsReady() (usbTxLen1 & 0x10) |
| 228 | /* This macro indicates whether the last interrupt message has already been | 227 | /* This macro indicates whether the last interrupt message has already been |
| 229 | * sent. If you set a new interrupt message before the old was sent, the | 228 | * sent. If you set a new interrupt message before the old was sent, the |
| 230 | * message already buffered will be lost. | 229 | * message already buffered will be lost. |
| 231 | */ | 230 | */ |
| 232 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 | 231 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 |
| 233 | USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len); | 232 | USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len); |
| 234 | #define usbInterruptIsReady3() (usbTxLen3 & 0x10) | 233 | # define usbInterruptIsReady3() (usbTxLen3 & 0x10) |
| 235 | /* Same as above for endpoint 3 */ | 234 | /* Same as above for endpoint 3 */ |
| 236 | #endif | 235 | # endif |
| 237 | #endif /* USB_CFG_HAVE_INTRIN_ENDPOINT */ | 236 | # endif /* USB_CFG_HAVE_INTRIN_ENDPOINT */ |
| 238 | #if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* simplified interface for backward compatibility */ | 237 | # if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* simplified interface for backward compatibility */ |
| 239 | #define usbHidReportDescriptor usbDescriptorHidReport | 238 | # define usbHidReportDescriptor usbDescriptorHidReport |
| 240 | /* should be declared as: PROGMEM char usbHidReportDescriptor[]; */ | 239 | /* should be declared as: PROGMEM char usbHidReportDescriptor[]; */ |
| 241 | /* If you implement an HID device, you need to provide a report descriptor. | 240 | /* If you implement an HID device, you need to provide a report descriptor. |
| 242 | * The HID report descriptor syntax is a bit complex. If you understand how | 241 | * The HID report descriptor syntax is a bit complex. If you understand how |
| @@ -244,8 +243,8 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len); | |||
| 244 | * Descriptor Tool from usb.org, see http://www.usb.org/developers/hidpage/. | 243 | * Descriptor Tool from usb.org, see http://www.usb.org/developers/hidpage/. |
| 245 | * Otherwise you should probably start with a working example. | 244 | * Otherwise you should probably start with a working example. |
| 246 | */ | 245 | */ |
| 247 | #endif /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */ | 246 | # endif /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */ |
| 248 | #if USB_CFG_IMPLEMENT_FN_WRITE | 247 | # if USB_CFG_IMPLEMENT_FN_WRITE |
| 249 | USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len); | 248 | USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len); |
| 250 | /* This function is called by the driver to provide a control transfer's | 249 | /* This function is called by the driver to provide a control transfer's |
| 251 | * payload data (control-out). It is called in chunks of up to 8 bytes. The | 250 | * payload data (control-out). It is called in chunks of up to 8 bytes. The |
| @@ -262,8 +261,8 @@ USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len); | |||
| 262 | * In order to get usbFunctionWrite() called, define USB_CFG_IMPLEMENT_FN_WRITE | 261 | * In order to get usbFunctionWrite() called, define USB_CFG_IMPLEMENT_FN_WRITE |
| 263 | * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. | 262 | * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. |
| 264 | */ | 263 | */ |
| 265 | #endif /* USB_CFG_IMPLEMENT_FN_WRITE */ | 264 | # endif /* USB_CFG_IMPLEMENT_FN_WRITE */ |
| 266 | #if USB_CFG_IMPLEMENT_FN_READ | 265 | # if USB_CFG_IMPLEMENT_FN_READ |
| 267 | USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len); | 266 | USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len); |
| 268 | /* This function is called by the driver to ask the application for a control | 267 | /* This function is called by the driver to ask the application for a control |
| 269 | * transfer's payload data (control-in). It is called in chunks of up to 8 | 268 | * transfer's payload data (control-in). It is called in chunks of up to 8 |
| @@ -274,26 +273,24 @@ USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len); | |||
| 274 | * In order to get usbFunctionRead() called, define USB_CFG_IMPLEMENT_FN_READ | 273 | * In order to get usbFunctionRead() called, define USB_CFG_IMPLEMENT_FN_READ |
| 275 | * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. | 274 | * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. |
| 276 | */ | 275 | */ |
| 277 | #endif /* USB_CFG_IMPLEMENT_FN_READ */ | 276 | # endif /* USB_CFG_IMPLEMENT_FN_READ */ |
| 278 | 277 | ||
| 279 | extern uchar usbRxToken; /* may be used in usbFunctionWriteOut() below */ | 278 | extern uchar usbRxToken; /* may be used in usbFunctionWriteOut() below */ |
| 280 | #if USB_CFG_IMPLEMENT_FN_WRITEOUT | 279 | # if USB_CFG_IMPLEMENT_FN_WRITEOUT |
| 281 | USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len); | 280 | USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len); |
| 282 | /* This function is called by the driver when data is received on an interrupt- | 281 | /* This function is called by the driver when data is received on an interrupt- |
| 283 | * or bulk-out endpoint. The endpoint number can be found in the global | 282 | * or bulk-out endpoint. The endpoint number can be found in the global |
| 284 | * variable usbRxToken. You must define USB_CFG_IMPLEMENT_FN_WRITEOUT to 1 in | 283 | * variable usbRxToken. You must define USB_CFG_IMPLEMENT_FN_WRITEOUT to 1 in |
| 285 | * usbconfig.h to get this function called. | 284 | * usbconfig.h to get this function called. |
| 286 | */ | 285 | */ |
| 287 | #endif /* USB_CFG_IMPLEMENT_FN_WRITEOUT */ | 286 | # endif /* USB_CFG_IMPLEMENT_FN_WRITEOUT */ |
| 288 | #ifdef USB_CFG_PULLUP_IOPORTNAME | 287 | # ifdef USB_CFG_PULLUP_IOPORTNAME |
| 289 | #define usbDeviceConnect() ((USB_PULLUP_DDR |= (1<<USB_CFG_PULLUP_BIT)), \ | 288 | # define usbDeviceConnect() ((USB_PULLUP_DDR |= (1 << USB_CFG_PULLUP_BIT)), (USB_PULLUP_OUT |= (1 << USB_CFG_PULLUP_BIT))) |
| 290 | (USB_PULLUP_OUT |= (1<<USB_CFG_PULLUP_BIT))) | 289 | # define usbDeviceDisconnect() ((USB_PULLUP_DDR &= ~(1 << USB_CFG_PULLUP_BIT)), (USB_PULLUP_OUT &= ~(1 << USB_CFG_PULLUP_BIT))) |
| 291 | #define usbDeviceDisconnect() ((USB_PULLUP_DDR &= ~(1<<USB_CFG_PULLUP_BIT)), \ | 290 | # else /* USB_CFG_PULLUP_IOPORTNAME */ |
| 292 | (USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT))) | 291 | # define usbDeviceConnect() (USBDDR &= ~(1 << USBMINUS)) |
| 293 | #else /* USB_CFG_PULLUP_IOPORTNAME */ | 292 | # define usbDeviceDisconnect() (USBDDR |= (1 << USBMINUS)) |
| 294 | #define usbDeviceConnect() (USBDDR &= ~(1<<USBMINUS)) | 293 | # endif /* USB_CFG_PULLUP_IOPORTNAME */ |
| 295 | #define usbDeviceDisconnect() (USBDDR |= (1<<USBMINUS)) | ||
| 296 | #endif /* USB_CFG_PULLUP_IOPORTNAME */ | ||
| 297 | /* The macros usbDeviceConnect() and usbDeviceDisconnect() (intended to look | 294 | /* The macros usbDeviceConnect() and usbDeviceDisconnect() (intended to look |
| 298 | * like a function) connect resp. disconnect the device from the host's USB. | 295 | * like a function) connect resp. disconnect the device from the host's USB. |
| 299 | * If the constants USB_CFG_PULLUP_IOPORT and USB_CFG_PULLUP_BIT are defined | 296 | * If the constants USB_CFG_PULLUP_IOPORT and USB_CFG_PULLUP_BIT are defined |
| @@ -307,7 +304,7 @@ USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len); | |||
| 307 | * or use cli() to disable interrupts globally. | 304 | * or use cli() to disable interrupts globally. |
| 308 | */ | 305 | */ |
| 309 | extern unsigned usbCrc16(unsigned data, uchar len); | 306 | extern unsigned usbCrc16(unsigned data, uchar len); |
| 310 | #define usbCrc16(data, len) usbCrc16((unsigned)(data), len) | 307 | # define usbCrc16(data, len) usbCrc16((unsigned)(data), len) |
| 311 | /* This function calculates the binary complement of the data CRC used in | 308 | /* This function calculates the binary complement of the data CRC used in |
| 312 | * USB data packets. The value is used to build raw transmit packets. | 309 | * USB data packets. The value is used to build raw transmit packets. |
| 313 | * You may want to use this function for data checksums or to verify received | 310 | * You may want to use this function for data checksums or to verify received |
| @@ -315,12 +312,12 @@ extern unsigned usbCrc16(unsigned data, uchar len); | |||
| 315 | * tiny memory model. | 312 | * tiny memory model. |
| 316 | */ | 313 | */ |
| 317 | extern unsigned usbCrc16Append(unsigned data, uchar len); | 314 | extern unsigned usbCrc16Append(unsigned data, uchar len); |
| 318 | #define usbCrc16Append(data, len) usbCrc16Append((unsigned)(data), len) | 315 | # define usbCrc16Append(data, len) usbCrc16Append((unsigned)(data), len) |
| 319 | /* This function is equivalent to usbCrc16() above, except that it appends | 316 | /* This function is equivalent to usbCrc16() above, except that it appends |
| 320 | * the 2 bytes CRC (lowbyte first) in the 'data' buffer after reading 'len' | 317 | * the 2 bytes CRC (lowbyte first) in the 'data' buffer after reading 'len' |
| 321 | * bytes. | 318 | * bytes. |
| 322 | */ | 319 | */ |
| 323 | #if USB_CFG_HAVE_MEASURE_FRAME_LENGTH | 320 | # if USB_CFG_HAVE_MEASURE_FRAME_LENGTH |
| 324 | extern unsigned usbMeasureFrameLength(void); | 321 | extern unsigned usbMeasureFrameLength(void); |
| 325 | /* This function MUST be called IMMEDIATELY AFTER USB reset and measures 1/7 of | 322 | /* This function MUST be called IMMEDIATELY AFTER USB reset and measures 1/7 of |
| 326 | * the number of CPU cycles during one USB frame minus one low speed bit | 323 | * the number of CPU cycles during one USB frame minus one low speed bit |
| @@ -329,59 +326,58 @@ extern unsigned usbMeasureFrameLength(void); | |||
| 329 | * calling this function. | 326 | * calling this function. |
| 330 | * This can be used to calibrate the AVR's RC oscillator. | 327 | * This can be used to calibrate the AVR's RC oscillator. |
| 331 | */ | 328 | */ |
| 332 | #endif | 329 | # endif |
| 333 | extern uchar usbConfiguration; | 330 | extern uchar usbConfiguration; |
| 334 | /* This value contains the current configuration set by the host. The driver | 331 | /* This value contains the current configuration set by the host. The driver |
| 335 | * allows setting and querying of this variable with the USB SET_CONFIGURATION | 332 | * allows setting and querying of this variable with the USB SET_CONFIGURATION |
| 336 | * and GET_CONFIGURATION requests, but does not use it otherwise. | 333 | * and GET_CONFIGURATION requests, but does not use it otherwise. |
| 337 | * You may want to reflect the "configured" status with a LED on the device or | 334 | * You may want to reflect the "configured" status with a LED on the device or |
| 338 | * switch on high power parts of the circuit only if the device is configured. | 335 | * switch on high power parts of the circuit only if the device is configured. |
| 339 | */ | 336 | */ |
| 340 | #if USB_COUNT_SOF | 337 | # if USB_COUNT_SOF |
| 341 | extern volatile uchar usbSofCount; | 338 | extern volatile uchar usbSofCount; |
| 342 | /* This variable is incremented on every SOF packet. It is only available if | 339 | /* This variable is incremented on every SOF packet. It is only available if |
| 343 | * the macro USB_COUNT_SOF is defined to a value != 0. | 340 | * the macro USB_COUNT_SOF is defined to a value != 0. |
| 344 | */ | 341 | */ |
| 345 | #endif | 342 | # endif |
| 346 | #if USB_CFG_CHECK_DATA_TOGGLING | 343 | # if USB_CFG_CHECK_DATA_TOGGLING |
| 347 | extern uchar usbCurrentDataToken; | 344 | extern uchar usbCurrentDataToken; |
| 348 | /* This variable can be checked in usbFunctionWrite() and usbFunctionWriteOut() | 345 | /* This variable can be checked in usbFunctionWrite() and usbFunctionWriteOut() |
| 349 | * to ignore duplicate packets. | 346 | * to ignore duplicate packets. |
| 350 | */ | 347 | */ |
| 351 | #endif | 348 | # endif |
| 352 | 349 | ||
| 353 | #define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8)) | 350 | # define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2 * (stringLength) + 2) | (3 << 8)) |
| 354 | /* This macro builds a descriptor header for a string descriptor given the | 351 | /* This macro builds a descriptor header for a string descriptor given the |
| 355 | * string's length. See usbdrv.c for an example how to use it. | 352 | * string's length. See usbdrv.c for an example how to use it. |
| 356 | */ | 353 | */ |
| 357 | #if USB_CFG_HAVE_FLOWCONTROL | 354 | # if USB_CFG_HAVE_FLOWCONTROL |
| 358 | extern volatile schar usbRxLen; | 355 | extern volatile schar usbRxLen; |
| 359 | #define usbDisableAllRequests() usbRxLen = -1 | 356 | # define usbDisableAllRequests() usbRxLen = -1 |
| 360 | /* Must be called from usbFunctionWrite(). This macro disables all data input | 357 | /* Must be called from usbFunctionWrite(). This macro disables all data input |
| 361 | * from the USB interface. Requests from the host are answered with a NAK | 358 | * from the USB interface. Requests from the host are answered with a NAK |
| 362 | * while they are disabled. | 359 | * while they are disabled. |
| 363 | */ | 360 | */ |
| 364 | #define usbEnableAllRequests() usbRxLen = 0 | 361 | # define usbEnableAllRequests() usbRxLen = 0 |
| 365 | /* May only be called if requests are disabled. This macro enables input from | 362 | /* May only be called if requests are disabled. This macro enables input from |
| 366 | * the USB interface after it has been disabled with usbDisableAllRequests(). | 363 | * the USB interface after it has been disabled with usbDisableAllRequests(). |
| 367 | */ | 364 | */ |
| 368 | #define usbAllRequestsAreDisabled() (usbRxLen < 0) | 365 | # define usbAllRequestsAreDisabled() (usbRxLen < 0) |
| 369 | /* Use this macro to find out whether requests are disabled. It may be needed | 366 | /* Use this macro to find out whether requests are disabled. It may be needed |
| 370 | * to ensure that usbEnableAllRequests() is never called when requests are | 367 | * to ensure that usbEnableAllRequests() is never called when requests are |
| 371 | * enabled. | 368 | * enabled. |
| 372 | */ | 369 | */ |
| 373 | #endif | 370 | # endif |
| 374 | 371 | ||
| 375 | #define USB_SET_DATATOKEN1(token) usbTxBuf1[0] = token | 372 | # define USB_SET_DATATOKEN1(token) usbTxBuf1[0] = token |
| 376 | #define USB_SET_DATATOKEN3(token) usbTxBuf3[0] = token | 373 | # define USB_SET_DATATOKEN3(token) usbTxBuf3[0] = token |
| 377 | /* These two macros can be used by application software to reset data toggling | 374 | /* These two macros can be used by application software to reset data toggling |
| 378 | * for interrupt-in endpoints 1 and 3. Since the token is toggled BEFORE | 375 | * for interrupt-in endpoints 1 and 3. Since the token is toggled BEFORE |
| 379 | * sending data, you must set the opposite value of the token which should come | 376 | * sending data, you must set the opposite value of the token which should come |
| 380 | * first. | 377 | * first. |
| 381 | */ | 378 | */ |
| 382 | 379 | ||
| 383 | #endif /* __ASSEMBLER__ */ | 380 | #endif /* __ASSEMBLER__ */ |
| 384 | |||
| 385 | 381 | ||
| 386 | /* ------------------------------------------------------------------------- */ | 382 | /* ------------------------------------------------------------------------- */ |
| 387 | /* ----------------- Definitions for Descriptor Properties ----------------- */ | 383 | /* ----------------- Definitions for Descriptor Properties ----------------- */ |
| @@ -390,57 +386,57 @@ extern volatile schar usbRxLen; | |||
| 390 | * about the various methods to define USB descriptors. If you do nothing, | 386 | * about the various methods to define USB descriptors. If you do nothing, |
| 391 | * the default descriptors will be used. | 387 | * the default descriptors will be used. |
| 392 | */ | 388 | */ |
| 393 | #define USB_PROP_IS_DYNAMIC (1 << 14) | 389 | #define USB_PROP_IS_DYNAMIC (1 << 14) |
| 394 | /* If this property is set for a descriptor, usbFunctionDescriptor() will be | 390 | /* If this property is set for a descriptor, usbFunctionDescriptor() will be |
| 395 | * used to obtain the particular descriptor. Data directly returned via | 391 | * used to obtain the particular descriptor. Data directly returned via |
| 396 | * usbMsgPtr are FLASH data by default, combine (OR) with USB_PROP_IS_RAM to | 392 | * usbMsgPtr are FLASH data by default, combine (OR) with USB_PROP_IS_RAM to |
| 397 | * return RAM data. | 393 | * return RAM data. |
| 398 | */ | 394 | */ |
| 399 | #define USB_PROP_IS_RAM (1 << 15) | 395 | #define USB_PROP_IS_RAM (1 << 15) |
| 400 | /* If this property is set for a descriptor, the data is read from RAM | 396 | /* If this property is set for a descriptor, the data is read from RAM |
| 401 | * memory instead of Flash. The property is used for all methods to provide | 397 | * memory instead of Flash. The property is used for all methods to provide |
| 402 | * external descriptors. | 398 | * external descriptors. |
| 403 | */ | 399 | */ |
| 404 | #define USB_PROP_LENGTH(len) ((len) & 0x3fff) | 400 | #define USB_PROP_LENGTH(len) ((len)&0x3fff) |
| 405 | /* If a static external descriptor is used, this is the total length of the | 401 | /* If a static external descriptor is used, this is the total length of the |
| 406 | * descriptor in bytes. | 402 | * descriptor in bytes. |
| 407 | */ | 403 | */ |
| 408 | 404 | ||
| 409 | /* all descriptors which may have properties: */ | 405 | /* all descriptors which may have properties: */ |
| 410 | #ifndef USB_CFG_DESCR_PROPS_DEVICE | 406 | #ifndef USB_CFG_DESCR_PROPS_DEVICE |
| 411 | #define USB_CFG_DESCR_PROPS_DEVICE 0 | 407 | # define USB_CFG_DESCR_PROPS_DEVICE 0 |
| 412 | #endif | 408 | #endif |
| 413 | #ifndef USB_CFG_DESCR_PROPS_CONFIGURATION | 409 | #ifndef USB_CFG_DESCR_PROPS_CONFIGURATION |
| 414 | #define USB_CFG_DESCR_PROPS_CONFIGURATION 0 | 410 | # define USB_CFG_DESCR_PROPS_CONFIGURATION 0 |
| 415 | #endif | 411 | #endif |
| 416 | #ifndef USB_CFG_DESCR_PROPS_STRINGS | 412 | #ifndef USB_CFG_DESCR_PROPS_STRINGS |
| 417 | #define USB_CFG_DESCR_PROPS_STRINGS 0 | 413 | # define USB_CFG_DESCR_PROPS_STRINGS 0 |
| 418 | #endif | 414 | #endif |
| 419 | #ifndef USB_CFG_DESCR_PROPS_STRING_0 | 415 | #ifndef USB_CFG_DESCR_PROPS_STRING_0 |
| 420 | #define USB_CFG_DESCR_PROPS_STRING_0 0 | 416 | # define USB_CFG_DESCR_PROPS_STRING_0 0 |
| 421 | #endif | 417 | #endif |
| 422 | #ifndef USB_CFG_DESCR_PROPS_STRING_VENDOR | 418 | #ifndef USB_CFG_DESCR_PROPS_STRING_VENDOR |
| 423 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 | 419 | # define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 |
| 424 | #endif | 420 | #endif |
| 425 | #ifndef USB_CFG_DESCR_PROPS_STRING_PRODUCT | 421 | #ifndef USB_CFG_DESCR_PROPS_STRING_PRODUCT |
| 426 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 | 422 | # define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 |
| 427 | #endif | 423 | #endif |
| 428 | #ifndef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER | 424 | #ifndef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER |
| 429 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 | 425 | # define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 |
| 430 | #endif | 426 | #endif |
| 431 | #ifndef USB_CFG_DESCR_PROPS_HID | 427 | #ifndef USB_CFG_DESCR_PROPS_HID |
| 432 | #define USB_CFG_DESCR_PROPS_HID 0 | 428 | # define USB_CFG_DESCR_PROPS_HID 0 |
| 433 | #endif | 429 | #endif |
| 434 | #if !(USB_CFG_DESCR_PROPS_HID_REPORT) | 430 | #if !(USB_CFG_DESCR_PROPS_HID_REPORT) |
| 435 | # undef USB_CFG_DESCR_PROPS_HID_REPORT | 431 | # undef USB_CFG_DESCR_PROPS_HID_REPORT |
| 436 | # if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* do some backward compatibility tricks */ | 432 | # if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* do some backward compatibility tricks */ |
| 437 | # define USB_CFG_DESCR_PROPS_HID_REPORT USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH | 433 | # define USB_CFG_DESCR_PROPS_HID_REPORT USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH |
| 438 | # else | 434 | # else |
| 439 | # define USB_CFG_DESCR_PROPS_HID_REPORT 0 | 435 | # define USB_CFG_DESCR_PROPS_HID_REPORT 0 |
| 440 | # endif | 436 | # endif |
| 441 | #endif | 437 | #endif |
| 442 | #ifndef USB_CFG_DESCR_PROPS_UNKNOWN | 438 | #ifndef USB_CFG_DESCR_PROPS_UNKNOWN |
| 443 | #define USB_CFG_DESCR_PROPS_UNKNOWN 0 | 439 | # define USB_CFG_DESCR_PROPS_UNKNOWN 0 |
| 444 | #endif | 440 | #endif |
| 445 | 441 | ||
| 446 | /* ------------------ forward declaration of descriptors ------------------- */ | 442 | /* ------------------ forward declaration of descriptors ------------------- */ |
| @@ -449,46 +445,46 @@ extern volatile schar usbRxLen; | |||
| 449 | */ | 445 | */ |
| 450 | #ifndef __ASSEMBLER__ | 446 | #ifndef __ASSEMBLER__ |
| 451 | extern | 447 | extern |
| 452 | #if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM) | 448 | # if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM) |
| 453 | PROGMEM | 449 | PROGMEM |
| 454 | #endif | 450 | # endif |
| 455 | const char usbDescriptorDevice[]; | 451 | const char usbDescriptorDevice[]; |
| 456 | 452 | ||
| 457 | extern | 453 | extern |
| 458 | #if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM) | 454 | # if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM) |
| 459 | PROGMEM | 455 | PROGMEM |
| 460 | #endif | 456 | # endif |
| 461 | const char usbDescriptorConfiguration[]; | 457 | const char usbDescriptorConfiguration[]; |
| 462 | 458 | ||
| 463 | extern | 459 | extern |
| 464 | #if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM) | 460 | # if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM) |
| 465 | PROGMEM | 461 | PROGMEM |
| 466 | #endif | 462 | # endif |
| 467 | const char usbDescriptorHidReport[]; | 463 | const char usbDescriptorHidReport[]; |
| 468 | 464 | ||
| 469 | extern | 465 | extern |
| 470 | #if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM) | 466 | # if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM) |
| 471 | PROGMEM | 467 | PROGMEM |
| 472 | #endif | 468 | # endif |
| 473 | const char usbDescriptorString0[]; | 469 | const char usbDescriptorString0[]; |
| 474 | 470 | ||
| 475 | extern | 471 | extern |
| 476 | #if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM) | 472 | # if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM) |
| 477 | PROGMEM | 473 | PROGMEM |
| 478 | #endif | 474 | # endif |
| 479 | const int usbDescriptorStringVendor[]; | 475 | const int usbDescriptorStringVendor[]; |
| 480 | 476 | ||
| 481 | extern | 477 | extern |
| 482 | #if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM) | 478 | # if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM) |
| 483 | PROGMEM | 479 | PROGMEM |
| 484 | #endif | 480 | # endif |
| 485 | const int usbDescriptorStringDevice[]; | 481 | const int usbDescriptorStringDevice[]; |
| 486 | 482 | ||
| 487 | extern | 483 | extern |
| 488 | #if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM) | 484 | # if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM) |
| 489 | PROGMEM | 485 | PROGMEM |
| 490 | #endif | 486 | # endif |
| 491 | const int usbDescriptorStringSerialNumber[]; | 487 | const int usbDescriptorStringSerialNumber[]; |
| 492 | 488 | ||
| 493 | #endif /* __ASSEMBLER__ */ | 489 | #endif /* __ASSEMBLER__ */ |
| 494 | 490 | ||
| @@ -496,12 +492,12 @@ const int usbDescriptorStringSerialNumber[]; | |||
| 496 | /* ------------------------ General Purpose Macros ------------------------- */ | 492 | /* ------------------------ General Purpose Macros ------------------------- */ |
| 497 | /* ------------------------------------------------------------------------- */ | 493 | /* ------------------------------------------------------------------------- */ |
| 498 | 494 | ||
| 499 | #define USB_CONCAT(a, b) a ## b | 495 | #define USB_CONCAT(a, b) a##b |
| 500 | #define USB_CONCAT_EXPANDED(a, b) USB_CONCAT(a, b) | 496 | #define USB_CONCAT_EXPANDED(a, b) USB_CONCAT(a, b) |
| 501 | 497 | ||
| 502 | #define USB_OUTPORT(name) USB_CONCAT(PORT, name) | 498 | #define USB_OUTPORT(name) USB_CONCAT(PORT, name) |
| 503 | #define USB_INPORT(name) USB_CONCAT(PIN, name) | 499 | #define USB_INPORT(name) USB_CONCAT(PIN, name) |
| 504 | #define USB_DDRPORT(name) USB_CONCAT(DDR, name) | 500 | #define USB_DDRPORT(name) USB_CONCAT(DDR, name) |
| 505 | /* The double-define trick above lets us concatenate strings which are | 501 | /* The double-define trick above lets us concatenate strings which are |
| 506 | * defined by macros. | 502 | * defined by macros. |
| 507 | */ | 503 | */ |
| @@ -511,7 +507,7 @@ const int usbDescriptorStringSerialNumber[]; | |||
| 511 | /* ------------------------------------------------------------------------- */ | 507 | /* ------------------------------------------------------------------------- */ |
| 512 | 508 | ||
| 513 | #if !defined __ASSEMBLER__ && (!defined USB_CFG_VENDOR_ID || !defined USB_CFG_DEVICE_ID) | 509 | #if !defined __ASSEMBLER__ && (!defined USB_CFG_VENDOR_ID || !defined USB_CFG_DEVICE_ID) |
| 514 | #warning "You should define USB_CFG_VENDOR_ID and USB_CFG_DEVICE_ID in usbconfig.h" | 510 | # warning "You should define USB_CFG_VENDOR_ID and USB_CFG_DEVICE_ID in usbconfig.h" |
| 515 | /* If the user has not defined IDs, we default to obdev's free IDs. | 511 | /* If the user has not defined IDs, we default to obdev's free IDs. |
| 516 | * See USB-IDs-for-free.txt for details. | 512 | * See USB-IDs-for-free.txt for details. |
| 517 | */ | 513 | */ |
| @@ -519,96 +515,96 @@ const int usbDescriptorStringSerialNumber[]; | |||
| 519 | 515 | ||
| 520 | /* make sure we have a VID and PID defined, byte order is lowbyte, highbyte */ | 516 | /* make sure we have a VID and PID defined, byte order is lowbyte, highbyte */ |
| 521 | #ifndef USB_CFG_VENDOR_ID | 517 | #ifndef USB_CFG_VENDOR_ID |
| 522 | # define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ | 518 | # define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ |
| 523 | #endif | 519 | #endif |
| 524 | 520 | ||
| 525 | #ifndef USB_CFG_DEVICE_ID | 521 | #ifndef USB_CFG_DEVICE_ID |
| 526 | # if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH | 522 | # if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH |
| 527 | # define USB_CFG_DEVICE_ID 0xdf, 0x05 /* = 0x5df = 1503, shared PID for HIDs */ | 523 | # define USB_CFG_DEVICE_ID 0xdf, 0x05 /* = 0x5df = 1503, shared PID for HIDs */ |
| 528 | # elif USB_CFG_INTERFACE_CLASS == 2 | 524 | # elif USB_CFG_INTERFACE_CLASS == 2 |
| 529 | # define USB_CFG_DEVICE_ID 0xe1, 0x05 /* = 0x5e1 = 1505, shared PID for CDC Modems */ | 525 | # define USB_CFG_DEVICE_ID 0xe1, 0x05 /* = 0x5e1 = 1505, shared PID for CDC Modems */ |
| 530 | # else | 526 | # else |
| 531 | # define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x5dc = 1500, obdev's free PID */ | 527 | # define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x5dc = 1500, obdev's free PID */ |
| 532 | # endif | 528 | # endif |
| 533 | #endif | 529 | #endif |
| 534 | 530 | ||
| 535 | /* Derive Output, Input and DataDirection ports from port names */ | 531 | /* Derive Output, Input and DataDirection ports from port names */ |
| 536 | #ifndef USB_CFG_IOPORTNAME | 532 | #ifndef USB_CFG_IOPORTNAME |
| 537 | #error "You must define USB_CFG_IOPORTNAME in usbconfig.h, see usbconfig-prototype.h" | 533 | # error "You must define USB_CFG_IOPORTNAME in usbconfig.h, see usbconfig-prototype.h" |
| 538 | #endif | 534 | #endif |
| 539 | 535 | ||
| 540 | #define USBOUT USB_OUTPORT(USB_CFG_IOPORTNAME) | 536 | #define USBOUT USB_OUTPORT(USB_CFG_IOPORTNAME) |
| 541 | #define USB_PULLUP_OUT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) | 537 | #define USB_PULLUP_OUT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) |
| 542 | #define USBIN USB_INPORT(USB_CFG_IOPORTNAME) | 538 | #define USBIN USB_INPORT(USB_CFG_IOPORTNAME) |
| 543 | #define USBDDR USB_DDRPORT(USB_CFG_IOPORTNAME) | 539 | #define USBDDR USB_DDRPORT(USB_CFG_IOPORTNAME) |
| 544 | #define USB_PULLUP_DDR USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME) | 540 | #define USB_PULLUP_DDR USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME) |
| 545 | 541 | ||
| 546 | #define USBMINUS USB_CFG_DMINUS_BIT | 542 | #define USBMINUS USB_CFG_DMINUS_BIT |
| 547 | #define USBPLUS USB_CFG_DPLUS_BIT | 543 | #define USBPLUS USB_CFG_DPLUS_BIT |
| 548 | #define USBIDLE (1<<USB_CFG_DMINUS_BIT) /* value representing J state */ | 544 | #define USBIDLE (1 << USB_CFG_DMINUS_BIT) /* value representing J state */ |
| 549 | #define USBMASK ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT)) /* mask for USB I/O bits */ | 545 | #define USBMASK ((1 << USB_CFG_DPLUS_BIT) | (1 << USB_CFG_DMINUS_BIT)) /* mask for USB I/O bits */ |
| 550 | 546 | ||
| 551 | /* defines for backward compatibility with older driver versions: */ | 547 | /* defines for backward compatibility with older driver versions: */ |
| 552 | #define USB_CFG_IOPORT USB_OUTPORT(USB_CFG_IOPORTNAME) | 548 | #define USB_CFG_IOPORT USB_OUTPORT(USB_CFG_IOPORTNAME) |
| 553 | #ifdef USB_CFG_PULLUP_IOPORTNAME | 549 | #ifdef USB_CFG_PULLUP_IOPORTNAME |
| 554 | #define USB_CFG_PULLUP_IOPORT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) | 550 | # define USB_CFG_PULLUP_IOPORT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) |
| 555 | #endif | 551 | #endif |
| 556 | 552 | ||
| 557 | #ifndef USB_CFG_EP3_NUMBER /* if not defined in usbconfig.h */ | 553 | #ifndef USB_CFG_EP3_NUMBER /* if not defined in usbconfig.h */ |
| 558 | #define USB_CFG_EP3_NUMBER 3 | 554 | # define USB_CFG_EP3_NUMBER 3 |
| 559 | #endif | 555 | #endif |
| 560 | 556 | ||
| 561 | #ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3 | 557 | #ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3 |
| 562 | #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 | 558 | # define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 |
| 563 | #endif | 559 | #endif |
| 564 | 560 | ||
| 565 | #define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC */ | 561 | #define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC */ |
| 566 | 562 | ||
| 567 | /* ----- Try to find registers and bits responsible for ext interrupt 0 ----- */ | 563 | /* ----- Try to find registers and bits responsible for ext interrupt 0 ----- */ |
| 568 | 564 | ||
| 569 | #ifndef USB_INTR_CFG /* allow user to override our default */ | 565 | #ifndef USB_INTR_CFG /* allow user to override our default */ |
| 570 | # if defined EICRA | 566 | # if defined EICRA |
| 571 | # define USB_INTR_CFG EICRA | 567 | # define USB_INTR_CFG EICRA |
| 572 | # else | 568 | # else |
| 573 | # define USB_INTR_CFG MCUCR | 569 | # define USB_INTR_CFG MCUCR |
| 574 | # endif | 570 | # endif |
| 575 | #endif | 571 | #endif |
| 576 | #ifndef USB_INTR_CFG_SET /* allow user to override our default */ | 572 | #ifndef USB_INTR_CFG_SET /* allow user to override our default */ |
| 577 | # if defined(USB_COUNT_SOF) || defined(USB_SOF_HOOK) | 573 | # if defined(USB_COUNT_SOF) || defined(USB_SOF_HOOK) |
| 578 | # define USB_INTR_CFG_SET (1 << ISC01) /* cfg for falling edge */ | 574 | # define USB_INTR_CFG_SET (1 << ISC01) /* cfg for falling edge */ |
| 579 | /* If any SOF logic is used, the interrupt must be wired to D- where | 575 | /* If any SOF logic is used, the interrupt must be wired to D- where |
| 580 | * we better trigger on falling edge | 576 | * we better trigger on falling edge |
| 581 | */ | 577 | */ |
| 582 | # else | 578 | # else |
| 583 | # define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */ | 579 | # define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */ |
| 584 | # endif | 580 | # endif |
| 585 | #endif | 581 | #endif |
| 586 | #ifndef USB_INTR_CFG_CLR /* allow user to override our default */ | 582 | #ifndef USB_INTR_CFG_CLR /* allow user to override our default */ |
| 587 | # define USB_INTR_CFG_CLR 0 /* no bits to clear */ | 583 | # define USB_INTR_CFG_CLR 0 /* no bits to clear */ |
| 588 | #endif | 584 | #endif |
| 589 | 585 | ||
| 590 | #ifndef USB_INTR_ENABLE /* allow user to override our default */ | 586 | #ifndef USB_INTR_ENABLE /* allow user to override our default */ |
| 591 | # if defined GIMSK | 587 | # if defined GIMSK |
| 592 | # define USB_INTR_ENABLE GIMSK | 588 | # define USB_INTR_ENABLE GIMSK |
| 593 | # elif defined EIMSK | 589 | # elif defined EIMSK |
| 594 | # define USB_INTR_ENABLE EIMSK | 590 | # define USB_INTR_ENABLE EIMSK |
| 595 | # else | 591 | # else |
| 596 | # define USB_INTR_ENABLE GICR | 592 | # define USB_INTR_ENABLE GICR |
| 597 | # endif | 593 | # endif |
| 598 | #endif | 594 | #endif |
| 599 | #ifndef USB_INTR_ENABLE_BIT /* allow user to override our default */ | 595 | #ifndef USB_INTR_ENABLE_BIT /* allow user to override our default */ |
| 600 | # define USB_INTR_ENABLE_BIT INT0 | 596 | # define USB_INTR_ENABLE_BIT INT0 |
| 601 | #endif | 597 | #endif |
| 602 | 598 | ||
| 603 | #ifndef USB_INTR_PENDING /* allow user to override our default */ | 599 | #ifndef USB_INTR_PENDING /* allow user to override our default */ |
| 604 | # if defined EIFR | 600 | # if defined EIFR |
| 605 | # define USB_INTR_PENDING EIFR | 601 | # define USB_INTR_PENDING EIFR |
| 606 | # else | 602 | # else |
| 607 | # define USB_INTR_PENDING GIFR | 603 | # define USB_INTR_PENDING GIFR |
| 608 | # endif | 604 | # endif |
| 609 | #endif | 605 | #endif |
| 610 | #ifndef USB_INTR_PENDING_BIT /* allow user to override our default */ | 606 | #ifndef USB_INTR_PENDING_BIT /* allow user to override our default */ |
| 611 | # define USB_INTR_PENDING_BIT INTF0 | 607 | # define USB_INTR_PENDING_BIT INTF0 |
| 612 | #endif | 608 | #endif |
| 613 | 609 | ||
| 614 | /* | 610 | /* |
| @@ -628,46 +624,45 @@ at90s1200, attiny11, attiny12, attiny15, attiny28: these have no RAM | |||
| 628 | /* ------------------------------------------------------------------------- */ | 624 | /* ------------------------------------------------------------------------- */ |
| 629 | 625 | ||
| 630 | /* USB Token values */ | 626 | /* USB Token values */ |
| 631 | #define USBPID_SETUP 0x2d | 627 | #define USBPID_SETUP 0x2d |
| 632 | #define USBPID_OUT 0xe1 | 628 | #define USBPID_OUT 0xe1 |
| 633 | #define USBPID_IN 0x69 | 629 | #define USBPID_IN 0x69 |
| 634 | #define USBPID_DATA0 0xc3 | 630 | #define USBPID_DATA0 0xc3 |
| 635 | #define USBPID_DATA1 0x4b | 631 | #define USBPID_DATA1 0x4b |
| 636 | 632 | ||
| 637 | #define USBPID_ACK 0xd2 | 633 | #define USBPID_ACK 0xd2 |
| 638 | #define USBPID_NAK 0x5a | 634 | #define USBPID_NAK 0x5a |
| 639 | #define USBPID_STALL 0x1e | 635 | #define USBPID_STALL 0x1e |
| 640 | 636 | ||
| 641 | #ifndef USB_INITIAL_DATATOKEN | 637 | #ifndef USB_INITIAL_DATATOKEN |
| 642 | #define USB_INITIAL_DATATOKEN USBPID_DATA1 | 638 | # define USB_INITIAL_DATATOKEN USBPID_DATA1 |
| 643 | #endif | 639 | #endif |
| 644 | 640 | ||
| 645 | #ifndef __ASSEMBLER__ | 641 | #ifndef __ASSEMBLER__ |
| 646 | 642 | ||
| 647 | typedef struct usbTxStatus{ | 643 | typedef struct usbTxStatus { |
| 648 | volatile uchar len; | 644 | volatile uchar len; |
| 649 | uchar buffer[USB_BUFSIZE]; | 645 | uchar buffer[USB_BUFSIZE]; |
| 650 | }usbTxStatus_t; | 646 | } usbTxStatus_t; |
| 651 | 647 | ||
| 652 | extern usbTxStatus_t usbTxStatus1, usbTxStatus3; | 648 | extern usbTxStatus_t usbTxStatus1, usbTxStatus3; |
| 653 | #define usbTxLen1 usbTxStatus1.len | 649 | # define usbTxLen1 usbTxStatus1.len |
| 654 | #define usbTxBuf1 usbTxStatus1.buffer | 650 | # define usbTxBuf1 usbTxStatus1.buffer |
| 655 | #define usbTxLen3 usbTxStatus3.len | 651 | # define usbTxLen3 usbTxStatus3.len |
| 656 | #define usbTxBuf3 usbTxStatus3.buffer | 652 | # define usbTxBuf3 usbTxStatus3.buffer |
| 657 | 653 | ||
| 658 | 654 | typedef union usbWord { | |
| 659 | typedef union usbWord{ | 655 | unsigned word; |
| 660 | unsigned word; | 656 | uchar bytes[2]; |
| 661 | uchar bytes[2]; | 657 | } usbWord_t; |
| 662 | }usbWord_t; | 658 | |
| 663 | 659 | typedef struct usbRequest { | |
| 664 | typedef struct usbRequest{ | 660 | uchar bmRequestType; |
| 665 | uchar bmRequestType; | 661 | uchar bRequest; |
| 666 | uchar bRequest; | 662 | usbWord_t wValue; |
| 667 | usbWord_t wValue; | 663 | usbWord_t wIndex; |
| 668 | usbWord_t wIndex; | 664 | usbWord_t wLength; |
| 669 | usbWord_t wLength; | 665 | } usbRequest_t; |
| 670 | }usbRequest_t; | ||
| 671 | /* This structure matches the 8 byte setup request */ | 666 | /* This structure matches the 8 byte setup request */ |
| 672 | #endif | 667 | #endif |
| 673 | 668 | ||
| @@ -679,56 +674,56 @@ typedef struct usbRequest{ | |||
| 679 | */ | 674 | */ |
| 680 | 675 | ||
| 681 | /* USB setup recipient values */ | 676 | /* USB setup recipient values */ |
| 682 | #define USBRQ_RCPT_MASK 0x1f | 677 | #define USBRQ_RCPT_MASK 0x1f |
| 683 | #define USBRQ_RCPT_DEVICE 0 | 678 | #define USBRQ_RCPT_DEVICE 0 |
| 684 | #define USBRQ_RCPT_INTERFACE 1 | 679 | #define USBRQ_RCPT_INTERFACE 1 |
| 685 | #define USBRQ_RCPT_ENDPOINT 2 | 680 | #define USBRQ_RCPT_ENDPOINT 2 |
| 686 | 681 | ||
| 687 | /* USB request type values */ | 682 | /* USB request type values */ |
| 688 | #define USBRQ_TYPE_MASK 0x60 | 683 | #define USBRQ_TYPE_MASK 0x60 |
| 689 | #define USBRQ_TYPE_STANDARD (0<<5) | 684 | #define USBRQ_TYPE_STANDARD (0 << 5) |
| 690 | #define USBRQ_TYPE_CLASS (1<<5) | 685 | #define USBRQ_TYPE_CLASS (1 << 5) |
| 691 | #define USBRQ_TYPE_VENDOR (2<<5) | 686 | #define USBRQ_TYPE_VENDOR (2 << 5) |
| 692 | 687 | ||
| 693 | /* USB direction values: */ | 688 | /* USB direction values: */ |
| 694 | #define USBRQ_DIR_MASK 0x80 | 689 | #define USBRQ_DIR_MASK 0x80 |
| 695 | #define USBRQ_DIR_HOST_TO_DEVICE (0<<7) | 690 | #define USBRQ_DIR_HOST_TO_DEVICE (0 << 7) |
| 696 | #define USBRQ_DIR_DEVICE_TO_HOST (1<<7) | 691 | #define USBRQ_DIR_DEVICE_TO_HOST (1 << 7) |
| 697 | 692 | ||
| 698 | /* USB Standard Requests */ | 693 | /* USB Standard Requests */ |
| 699 | #define USBRQ_GET_STATUS 0 | 694 | #define USBRQ_GET_STATUS 0 |
| 700 | #define USBRQ_CLEAR_FEATURE 1 | 695 | #define USBRQ_CLEAR_FEATURE 1 |
| 701 | #define USBRQ_SET_FEATURE 3 | 696 | #define USBRQ_SET_FEATURE 3 |
| 702 | #define USBRQ_SET_ADDRESS 5 | 697 | #define USBRQ_SET_ADDRESS 5 |
| 703 | #define USBRQ_GET_DESCRIPTOR 6 | 698 | #define USBRQ_GET_DESCRIPTOR 6 |
| 704 | #define USBRQ_SET_DESCRIPTOR 7 | 699 | #define USBRQ_SET_DESCRIPTOR 7 |
| 705 | #define USBRQ_GET_CONFIGURATION 8 | 700 | #define USBRQ_GET_CONFIGURATION 8 |
| 706 | #define USBRQ_SET_CONFIGURATION 9 | 701 | #define USBRQ_SET_CONFIGURATION 9 |
| 707 | #define USBRQ_GET_INTERFACE 10 | 702 | #define USBRQ_GET_INTERFACE 10 |
| 708 | #define USBRQ_SET_INTERFACE 11 | 703 | #define USBRQ_SET_INTERFACE 11 |
| 709 | #define USBRQ_SYNCH_FRAME 12 | 704 | #define USBRQ_SYNCH_FRAME 12 |
| 710 | 705 | ||
| 711 | /* USB descriptor constants */ | 706 | /* USB descriptor constants */ |
| 712 | #define USBDESCR_DEVICE 1 | 707 | #define USBDESCR_DEVICE 1 |
| 713 | #define USBDESCR_CONFIG 2 | 708 | #define USBDESCR_CONFIG 2 |
| 714 | #define USBDESCR_STRING 3 | 709 | #define USBDESCR_STRING 3 |
| 715 | #define USBDESCR_INTERFACE 4 | 710 | #define USBDESCR_INTERFACE 4 |
| 716 | #define USBDESCR_ENDPOINT 5 | 711 | #define USBDESCR_ENDPOINT 5 |
| 717 | #define USBDESCR_HID 0x21 | 712 | #define USBDESCR_HID 0x21 |
| 718 | #define USBDESCR_HID_REPORT 0x22 | 713 | #define USBDESCR_HID_REPORT 0x22 |
| 719 | #define USBDESCR_HID_PHYS 0x23 | 714 | #define USBDESCR_HID_PHYS 0x23 |
| 720 | 715 | ||
| 721 | //#define USBATTR_BUSPOWER 0x80 // USB 1.1 does not define this value any more | 716 | //#define USBATTR_BUSPOWER 0x80 // USB 1.1 does not define this value any more |
| 722 | #define USBATTR_SELFPOWER 0x40 | 717 | #define USBATTR_SELFPOWER 0x40 |
| 723 | #define USBATTR_REMOTEWAKE 0x20 | 718 | #define USBATTR_REMOTEWAKE 0x20 |
| 724 | 719 | ||
| 725 | /* USB HID Requests */ | 720 | /* USB HID Requests */ |
| 726 | #define USBRQ_HID_GET_REPORT 0x01 | 721 | #define USBRQ_HID_GET_REPORT 0x01 |
| 727 | #define USBRQ_HID_GET_IDLE 0x02 | 722 | #define USBRQ_HID_GET_IDLE 0x02 |
| 728 | #define USBRQ_HID_GET_PROTOCOL 0x03 | 723 | #define USBRQ_HID_GET_PROTOCOL 0x03 |
| 729 | #define USBRQ_HID_SET_REPORT 0x09 | 724 | #define USBRQ_HID_SET_REPORT 0x09 |
| 730 | #define USBRQ_HID_SET_IDLE 0x0a | 725 | #define USBRQ_HID_SET_IDLE 0x0a |
| 731 | #define USBRQ_HID_SET_PROTOCOL 0x0b | 726 | #define USBRQ_HID_SET_PROTOCOL 0x0b |
| 732 | 727 | ||
| 733 | /* ------------------------------------------------------------------------- */ | 728 | /* ------------------------------------------------------------------------- */ |
| 734 | 729 | ||
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 60e48c3a9..3719b7aa0 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c | |||
| @@ -29,36 +29,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 29 | #include "bootloader.h" | 29 | #include "bootloader.h" |
| 30 | #include <util/delay.h> | 30 | #include <util/delay.h> |
| 31 | 31 | ||
| 32 | |||
| 33 | static uint8_t vusb_keyboard_leds = 0; | 32 | static uint8_t vusb_keyboard_leds = 0; |
| 34 | static uint8_t vusb_idle_rate = 0; | 33 | static uint8_t vusb_idle_rate = 0; |
| 35 | 34 | ||
| 36 | /* Keyboard report send buffer */ | 35 | /* Keyboard report send buffer */ |
| 37 | #define KBUF_SIZE 16 | 36 | #define KBUF_SIZE 16 |
| 38 | static report_keyboard_t kbuf[KBUF_SIZE]; | 37 | static report_keyboard_t kbuf[KBUF_SIZE]; |
| 39 | static uint8_t kbuf_head = 0; | 38 | static uint8_t kbuf_head = 0; |
| 40 | static uint8_t kbuf_tail = 0; | 39 | static uint8_t kbuf_tail = 0; |
| 41 | 40 | ||
| 42 | typedef struct { | 41 | typedef struct { |
| 43 | uint8_t modifier; | 42 | uint8_t modifier; |
| 44 | uint8_t reserved; | 43 | uint8_t reserved; |
| 45 | uint8_t keycode[6]; | 44 | uint8_t keycode[6]; |
| 46 | } keyboard_report_t; | 45 | } keyboard_report_t; |
| 47 | 46 | ||
| 48 | static keyboard_report_t keyboard_report; // sent to PC | 47 | static keyboard_report_t keyboard_report; // sent to PC |
| 49 | 48 | ||
| 50 | #define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10 | 49 | #define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10 |
| 51 | 50 | ||
| 52 | /* transfer keyboard report from buffer */ | 51 | /* transfer keyboard report from buffer */ |
| 53 | void vusb_transfer_keyboard(void) | 52 | void vusb_transfer_keyboard(void) { |
| 54 | { | ||
| 55 | for (int i = 0; i < VUSB_TRANSFER_KEYBOARD_MAX_TRIES; i++) { | 53 | for (int i = 0; i < VUSB_TRANSFER_KEYBOARD_MAX_TRIES; i++) { |
| 56 | if (usbInterruptIsReady()) { | 54 | if (usbInterruptIsReady()) { |
| 57 | if (kbuf_head != kbuf_tail) { | 55 | if (kbuf_head != kbuf_tail) { |
| 58 | usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t)); | 56 | usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t)); |
| 59 | kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE; | 57 | kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE; |
| 60 | if (debug_keyboard) { | 58 | if (debug_keyboard) { |
| 61 | print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("]("); | 59 | print("V-USB: kbuf["); |
| 60 | pdec(kbuf_tail); | ||
| 61 | print("->"); | ||
| 62 | pdec(kbuf_head); | ||
| 63 | print("]("); | ||
| 62 | phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail)); | 64 | phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail)); |
| 63 | print(")\n"); | 65 | print(")\n"); |
| 64 | } | 66 | } |
| @@ -70,39 +72,26 @@ void vusb_transfer_keyboard(void) | |||
| 70 | } | 72 | } |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | |||
| 74 | /*------------------------------------------------------------------* | 75 | /*------------------------------------------------------------------* |
| 75 | * Host driver | 76 | * Host driver |
| 76 | *------------------------------------------------------------------*/ | 77 | *------------------------------------------------------------------*/ |
| 77 | static uint8_t keyboard_leds(void); | 78 | static uint8_t keyboard_leds(void); |
| 78 | static void send_keyboard(report_keyboard_t *report); | 79 | static void send_keyboard(report_keyboard_t *report); |
| 79 | static void send_mouse(report_mouse_t *report); | 80 | static void send_mouse(report_mouse_t *report); |
| 80 | static void send_system(uint16_t data); | 81 | static void send_system(uint16_t data); |
| 81 | static void send_consumer(uint16_t data); | 82 | static void send_consumer(uint16_t data); |
| 82 | |||
| 83 | static host_driver_t driver = { | ||
| 84 | keyboard_leds, | ||
| 85 | send_keyboard, | ||
| 86 | send_mouse, | ||
| 87 | send_system, | ||
| 88 | send_consumer | ||
| 89 | }; | ||
| 90 | 83 | ||
| 91 | host_driver_t *vusb_driver(void) | 84 | static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; |
| 92 | { | ||
| 93 | return &driver; | ||
| 94 | } | ||
| 95 | 85 | ||
| 96 | static uint8_t keyboard_leds(void) { | 86 | host_driver_t *vusb_driver(void) { return &driver; } |
| 97 | return vusb_keyboard_leds; | 87 | |
| 98 | } | 88 | static uint8_t keyboard_leds(void) { return vusb_keyboard_leds; } |
| 99 | 89 | ||
| 100 | static void send_keyboard(report_keyboard_t *report) | 90 | static void send_keyboard(report_keyboard_t *report) { |
| 101 | { | ||
| 102 | uint8_t next = (kbuf_head + 1) % KBUF_SIZE; | 91 | uint8_t next = (kbuf_head + 1) % KBUF_SIZE; |
| 103 | if (next != kbuf_tail) { | 92 | if (next != kbuf_tail) { |
| 104 | kbuf[kbuf_head] = *report; | 93 | kbuf[kbuf_head] = *report; |
| 105 | kbuf_head = next; | 94 | kbuf_head = next; |
| 106 | } else { | 95 | } else { |
| 107 | debug("kbuf: full\n"); | 96 | debug("kbuf: full\n"); |
| 108 | } | 97 | } |
| @@ -112,119 +101,97 @@ static void send_keyboard(report_keyboard_t *report) | |||
| 112 | vusb_transfer_keyboard(); | 101 | vusb_transfer_keyboard(); |
| 113 | } | 102 | } |
| 114 | 103 | ||
| 115 | |||
| 116 | typedef struct { | 104 | typedef struct { |
| 117 | uint8_t report_id; | 105 | uint8_t report_id; |
| 118 | report_mouse_t report; | 106 | report_mouse_t report; |
| 119 | } __attribute__ ((packed)) vusb_mouse_report_t; | 107 | } __attribute__((packed)) vusb_mouse_report_t; |
| 120 | 108 | ||
| 121 | static void send_mouse(report_mouse_t *report) | 109 | static void send_mouse(report_mouse_t *report) { |
| 122 | { | 110 | vusb_mouse_report_t r = {.report_id = REPORT_ID_MOUSE, .report = *report}; |
| 123 | vusb_mouse_report_t r = { | ||
| 124 | .report_id = REPORT_ID_MOUSE, | ||
| 125 | .report = *report | ||
| 126 | }; | ||
| 127 | if (usbInterruptIsReady3()) { | 111 | if (usbInterruptIsReady3()) { |
| 128 | usbSetInterrupt3((void *)&r, sizeof(vusb_mouse_report_t)); | 112 | usbSetInterrupt3((void *)&r, sizeof(vusb_mouse_report_t)); |
| 129 | } | 113 | } |
| 130 | } | 114 | } |
| 131 | 115 | ||
| 132 | |||
| 133 | typedef struct { | 116 | typedef struct { |
| 134 | uint8_t report_id; | 117 | uint8_t report_id; |
| 135 | uint16_t usage; | 118 | uint16_t usage; |
| 136 | } __attribute__ ((packed)) report_extra_t; | 119 | } __attribute__((packed)) report_extra_t; |
| 137 | 120 | ||
| 138 | static void send_system(uint16_t data) | 121 | static void send_system(uint16_t data) { |
| 139 | { | ||
| 140 | static uint16_t last_data = 0; | 122 | static uint16_t last_data = 0; |
| 141 | if (data == last_data) return; | 123 | if (data == last_data) return; |
| 142 | last_data = data; | 124 | last_data = data; |
| 143 | 125 | ||
| 144 | report_extra_t report = { | 126 | report_extra_t report = {.report_id = REPORT_ID_SYSTEM, .usage = data}; |
| 145 | .report_id = REPORT_ID_SYSTEM, | ||
| 146 | .usage = data | ||
| 147 | }; | ||
| 148 | if (usbInterruptIsReady3()) { | 127 | if (usbInterruptIsReady3()) { |
| 149 | usbSetInterrupt3((void *)&report, sizeof(report)); | 128 | usbSetInterrupt3((void *)&report, sizeof(report)); |
| 150 | } | 129 | } |
| 151 | } | 130 | } |
| 152 | 131 | ||
| 153 | static void send_consumer(uint16_t data) | 132 | static void send_consumer(uint16_t data) { |
| 154 | { | ||
| 155 | static uint16_t last_data = 0; | 133 | static uint16_t last_data = 0; |
| 156 | if (data == last_data) return; | 134 | if (data == last_data) return; |
| 157 | last_data = data; | 135 | last_data = data; |
| 158 | 136 | ||
| 159 | report_extra_t report = { | 137 | report_extra_t report = {.report_id = REPORT_ID_CONSUMER, .usage = data}; |
| 160 | .report_id = REPORT_ID_CONSUMER, | ||
| 161 | .usage = data | ||
| 162 | }; | ||
| 163 | if (usbInterruptIsReady3()) { | 138 | if (usbInterruptIsReady3()) { |
| 164 | usbSetInterrupt3((void *)&report, sizeof(report)); | 139 | usbSetInterrupt3((void *)&report, sizeof(report)); |
| 165 | } | 140 | } |
| 166 | } | 141 | } |
| 167 | 142 | ||
| 168 | |||
| 169 | |||
| 170 | /*------------------------------------------------------------------* | 143 | /*------------------------------------------------------------------* |
| 171 | * Request from host * | 144 | * Request from host * |
| 172 | *------------------------------------------------------------------*/ | 145 | *------------------------------------------------------------------*/ |
| 173 | static struct { | 146 | static struct { |
| 174 | uint16_t len; | 147 | uint16_t len; |
| 175 | enum { | 148 | enum { NONE, BOOTLOADER, SET_LED } kind; |
| 176 | NONE, | ||
| 177 | BOOTLOADER, | ||
| 178 | SET_LED | ||
| 179 | } kind; | ||
| 180 | } last_req; | 149 | } last_req; |
| 181 | 150 | ||
| 182 | usbMsgLen_t usbFunctionSetup(uchar data[8]) | 151 | usbMsgLen_t usbFunctionSetup(uchar data[8]) { |
| 183 | { | 152 | usbRequest_t *rq = (void *)data; |
| 184 | usbRequest_t *rq = (void *)data; | ||
| 185 | 153 | ||
| 186 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */ | 154 | if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ |
| 187 | if(rq->bRequest == USBRQ_HID_GET_REPORT){ | 155 | if (rq->bRequest == USBRQ_HID_GET_REPORT) { |
| 188 | debug("GET_REPORT:"); | 156 | debug("GET_REPORT:"); |
| 189 | /* we only have one report type, so don't look at wValue */ | 157 | /* we only have one report type, so don't look at wValue */ |
| 190 | usbMsgPtr = (void *)&keyboard_report; | 158 | usbMsgPtr = (void *)&keyboard_report; |
| 191 | return sizeof(keyboard_report); | 159 | return sizeof(keyboard_report); |
| 192 | }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ | 160 | } else if (rq->bRequest == USBRQ_HID_GET_IDLE) { |
| 193 | debug("GET_IDLE: "); | 161 | debug("GET_IDLE: "); |
| 194 | //debug_hex(vusb_idle_rate); | 162 | // debug_hex(vusb_idle_rate); |
| 195 | usbMsgPtr = &vusb_idle_rate; | 163 | usbMsgPtr = &vusb_idle_rate; |
| 196 | return 1; | 164 | return 1; |
| 197 | }else if(rq->bRequest == USBRQ_HID_SET_IDLE){ | 165 | } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { |
| 198 | vusb_idle_rate = rq->wValue.bytes[1]; | 166 | vusb_idle_rate = rq->wValue.bytes[1]; |
| 199 | debug("SET_IDLE: "); | 167 | debug("SET_IDLE: "); |
| 200 | debug_hex(vusb_idle_rate); | 168 | debug_hex(vusb_idle_rate); |
| 201 | }else if(rq->bRequest == USBRQ_HID_SET_REPORT){ | 169 | } else if (rq->bRequest == USBRQ_HID_SET_REPORT) { |
| 202 | debug("SET_REPORT: "); | 170 | debug("SET_REPORT: "); |
| 203 | // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) | 171 | // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) |
| 204 | if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) { | 172 | if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) { |
| 205 | debug("SET_LED: "); | 173 | debug("SET_LED: "); |
| 206 | last_req.kind = SET_LED; | 174 | last_req.kind = SET_LED; |
| 207 | last_req.len = rq->wLength.word; | 175 | last_req.len = rq->wLength.word; |
| 208 | #ifdef BOOTLOADER_SIZE | 176 | #ifdef BOOTLOADER_SIZE |
| 209 | } else if(rq->wValue.word == 0x0301) { | 177 | } else if (rq->wValue.word == 0x0301) { |
| 210 | last_req.kind = BOOTLOADER; | 178 | last_req.kind = BOOTLOADER; |
| 211 | last_req.len = rq->wLength.word; | 179 | last_req.len = rq->wLength.word; |
| 212 | #endif | 180 | #endif |
| 213 | } | 181 | } |
| 214 | return USB_NO_MSG; // to get data in usbFunctionWrite | 182 | return USB_NO_MSG; // to get data in usbFunctionWrite |
| 215 | } else { | 183 | } else { |
| 216 | debug("UNKNOWN:"); | 184 | debug("UNKNOWN:"); |
| 217 | } | 185 | } |
| 218 | }else{ | 186 | } else { |
| 219 | debug("VENDOR:"); | 187 | debug("VENDOR:"); |
| 220 | /* no vendor specific requests implemented */ | 188 | /* no vendor specific requests implemented */ |
| 221 | } | 189 | } |
| 222 | debug("\n"); | 190 | debug("\n"); |
| 223 | return 0; /* default for not implemented requests: return no data back to host */ | 191 | return 0; /* default for not implemented requests: return no data back to host */ |
| 224 | } | 192 | } |
| 225 | 193 | ||
| 226 | uchar usbFunctionWrite(uchar *data, uchar len) | 194 | uchar usbFunctionWrite(uchar *data, uchar len) { |
| 227 | { | ||
| 228 | if (last_req.len == 0) { | 195 | if (last_req.len == 0) { |
| 229 | return -1; | 196 | return -1; |
| 230 | } | 197 | } |
| @@ -234,7 +201,7 @@ uchar usbFunctionWrite(uchar *data, uchar len) | |||
| 234 | debug_hex(data[0]); | 201 | debug_hex(data[0]); |
| 235 | debug("\n"); | 202 | debug("\n"); |
| 236 | vusb_keyboard_leds = data[0]; | 203 | vusb_keyboard_leds = data[0]; |
| 237 | last_req.len = 0; | 204 | last_req.len = 0; |
| 238 | return 1; | 205 | return 1; |
| 239 | break; | 206 | break; |
| 240 | case BOOTLOADER: | 207 | case BOOTLOADER: |
| @@ -250,8 +217,6 @@ uchar usbFunctionWrite(uchar *data, uchar len) | |||
| 250 | return 1; | 217 | return 1; |
| 251 | } | 218 | } |
| 252 | 219 | ||
| 253 | |||
| 254 | |||
| 255 | /*------------------------------------------------------------------* | 220 | /*------------------------------------------------------------------* |
| 256 | * Descriptors * | 221 | * Descriptors * |
| 257 | *------------------------------------------------------------------*/ | 222 | *------------------------------------------------------------------*/ |
| @@ -262,38 +227,38 @@ uchar usbFunctionWrite(uchar *data, uchar len) | |||
| 262 | * from an example in HID spec appendix | 227 | * from an example in HID spec appendix |
| 263 | */ | 228 | */ |
| 264 | const PROGMEM uchar keyboard_hid_report[] = { | 229 | const PROGMEM uchar keyboard_hid_report[] = { |
| 265 | 0x05, 0x01, // Usage Page (Generic Desktop), | 230 | 0x05, 0x01, // Usage Page (Generic Desktop), |
| 266 | 0x09, 0x06, // Usage (Keyboard), | 231 | 0x09, 0x06, // Usage (Keyboard), |
| 267 | 0xA1, 0x01, // Collection (Application), | 232 | 0xA1, 0x01, // Collection (Application), |
| 268 | 0x75, 0x01, // Report Size (1), | 233 | 0x75, 0x01, // Report Size (1), |
| 269 | 0x95, 0x08, // Report Count (8), | 234 | 0x95, 0x08, // Report Count (8), |
| 270 | 0x05, 0x07, // Usage Page (Key Codes), | 235 | 0x05, 0x07, // Usage Page (Key Codes), |
| 271 | 0x19, 0xE0, // Usage Minimum (224), | 236 | 0x19, 0xE0, // Usage Minimum (224), |
| 272 | 0x29, 0xE7, // Usage Maximum (231), | 237 | 0x29, 0xE7, // Usage Maximum (231), |
| 273 | 0x15, 0x00, // Logical Minimum (0), | 238 | 0x15, 0x00, // Logical Minimum (0), |
| 274 | 0x25, 0x01, // Logical Maximum (1), | 239 | 0x25, 0x01, // Logical Maximum (1), |
| 275 | 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte | 240 | 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte |
| 276 | 0x95, 0x01, // Report Count (1), | 241 | 0x95, 0x01, // Report Count (1), |
| 277 | 0x75, 0x08, // Report Size (8), | 242 | 0x75, 0x08, // Report Size (8), |
| 278 | 0x81, 0x03, // Input (Constant), ;Reserved byte | 243 | 0x81, 0x03, // Input (Constant), ;Reserved byte |
| 279 | 0x95, 0x05, // Report Count (5), | 244 | 0x95, 0x05, // Report Count (5), |
| 280 | 0x75, 0x01, // Report Size (1), | 245 | 0x75, 0x01, // Report Size (1), |
| 281 | 0x05, 0x08, // Usage Page (LEDs), | 246 | 0x05, 0x08, // Usage Page (LEDs), |
| 282 | 0x19, 0x01, // Usage Minimum (1), | 247 | 0x19, 0x01, // Usage Minimum (1), |
| 283 | 0x29, 0x05, // Usage Maximum (5), | 248 | 0x29, 0x05, // Usage Maximum (5), |
| 284 | 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report | 249 | 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report |
| 285 | 0x95, 0x01, // Report Count (1), | 250 | 0x95, 0x01, // Report Count (1), |
| 286 | 0x75, 0x03, // Report Size (3), | 251 | 0x75, 0x03, // Report Size (3), |
| 287 | 0x91, 0x03, // Output (Constant), ;LED report padding | 252 | 0x91, 0x03, // Output (Constant), ;LED report padding |
| 288 | 0x95, 0x06, // Report Count (6), | 253 | 0x95, 0x06, // Report Count (6), |
| 289 | 0x75, 0x08, // Report Size (8), | 254 | 0x75, 0x08, // Report Size (8), |
| 290 | 0x15, 0x00, // Logical Minimum (0), | 255 | 0x15, 0x00, // Logical Minimum (0), |
| 291 | 0x26, 0xFF, 0x00, // Logical Maximum(255), | 256 | 0x26, 0xFF, 0x00, // Logical Maximum(255), |
| 292 | 0x05, 0x07, // Usage Page (Key Codes), | 257 | 0x05, 0x07, // Usage Page (Key Codes), |
| 293 | 0x19, 0x00, // Usage Minimum (0), | 258 | 0x19, 0x00, // Usage Minimum (0), |
| 294 | 0x29, 0xFF, // Usage Maximum (255), | 259 | 0x29, 0xFF, // Usage Maximum (255), |
| 295 | 0x81, 0x00, // Input (Data, Array), | 260 | 0x81, 0x00, // Input (Data, Array), |
| 296 | 0xc0 // End Collection | 261 | 0xc0 // End Collection |
| 297 | }; | 262 | }; |
| 298 | 263 | ||
| 299 | /* | 264 | /* |
| @@ -306,196 +271,191 @@ const PROGMEM uchar keyboard_hid_report[] = { | |||
| 306 | */ | 271 | */ |
| 307 | const PROGMEM uchar mouse_hid_report[] = { | 272 | const PROGMEM uchar mouse_hid_report[] = { |
| 308 | /* mouse */ | 273 | /* mouse */ |
| 309 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) | 274 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) |
| 310 | 0x09, 0x02, // USAGE (Mouse) | 275 | 0x09, 0x02, // USAGE (Mouse) |
| 311 | 0xa1, 0x01, // COLLECTION (Application) | 276 | 0xa1, 0x01, // COLLECTION (Application) |
| 312 | 0x85, REPORT_ID_MOUSE, // REPORT_ID (1) | 277 | 0x85, REPORT_ID_MOUSE, // REPORT_ID (1) |
| 313 | 0x09, 0x01, // USAGE (Pointer) | 278 | 0x09, 0x01, // USAGE (Pointer) |
| 314 | 0xa1, 0x00, // COLLECTION (Physical) | 279 | 0xa1, 0x00, // COLLECTION (Physical) |
| 315 | // ---------------------------- Buttons | 280 | // ---------------------------- Buttons |
| 316 | 0x05, 0x09, // USAGE_PAGE (Button) | 281 | 0x05, 0x09, // USAGE_PAGE (Button) |
| 317 | 0x19, 0x01, // USAGE_MINIMUM (Button 1) | 282 | 0x19, 0x01, // USAGE_MINIMUM (Button 1) |
| 318 | 0x29, 0x05, // USAGE_MAXIMUM (Button 5) | 283 | 0x29, 0x05, // USAGE_MAXIMUM (Button 5) |
| 319 | 0x15, 0x00, // LOGICAL_MINIMUM (0) | 284 | 0x15, 0x00, // LOGICAL_MINIMUM (0) |
| 320 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) | 285 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) |
| 321 | 0x75, 0x01, // REPORT_SIZE (1) | 286 | 0x75, 0x01, // REPORT_SIZE (1) |
| 322 | 0x95, 0x05, // REPORT_COUNT (5) | 287 | 0x95, 0x05, // REPORT_COUNT (5) |
| 323 | 0x81, 0x02, // INPUT (Data,Var,Abs) | 288 | 0x81, 0x02, // INPUT (Data,Var,Abs) |
| 324 | 0x75, 0x03, // REPORT_SIZE (3) | 289 | 0x75, 0x03, // REPORT_SIZE (3) |
| 325 | 0x95, 0x01, // REPORT_COUNT (1) | 290 | 0x95, 0x01, // REPORT_COUNT (1) |
| 326 | 0x81, 0x03, // INPUT (Cnst,Var,Abs) | 291 | 0x81, 0x03, // INPUT (Cnst,Var,Abs) |
| 327 | // ---------------------------- X,Y position | 292 | // ---------------------------- X,Y position |
| 328 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) | 293 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) |
| 329 | 0x09, 0x30, // USAGE (X) | 294 | 0x09, 0x30, // USAGE (X) |
| 330 | 0x09, 0x31, // USAGE (Y) | 295 | 0x09, 0x31, // USAGE (Y) |
| 331 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) | 296 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) |
| 332 | 0x25, 0x7f, // LOGICAL_MAXIMUM (127) | 297 | 0x25, 0x7f, // LOGICAL_MAXIMUM (127) |
| 333 | 0x75, 0x08, // REPORT_SIZE (8) | 298 | 0x75, 0x08, // REPORT_SIZE (8) |
| 334 | 0x95, 0x02, // REPORT_COUNT (2) | 299 | 0x95, 0x02, // REPORT_COUNT (2) |
| 335 | 0x81, 0x06, // INPUT (Data,Var,Rel) | 300 | 0x81, 0x06, // INPUT (Data,Var,Rel) |
| 336 | // ---------------------------- Vertical wheel | 301 | // ---------------------------- Vertical wheel |
| 337 | 0x09, 0x38, // USAGE (Wheel) | 302 | 0x09, 0x38, // USAGE (Wheel) |
| 338 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) | 303 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) |
| 339 | 0x25, 0x7f, // LOGICAL_MAXIMUM (127) | 304 | 0x25, 0x7f, // LOGICAL_MAXIMUM (127) |
| 340 | 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical | 305 | 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical |
| 341 | 0x45, 0x00, // PHYSICAL_MAXIMUM (0) | 306 | 0x45, 0x00, // PHYSICAL_MAXIMUM (0) |
| 342 | 0x75, 0x08, // REPORT_SIZE (8) | 307 | 0x75, 0x08, // REPORT_SIZE (8) |
| 343 | 0x95, 0x01, // REPORT_COUNT (1) | 308 | 0x95, 0x01, // REPORT_COUNT (1) |
| 344 | 0x81, 0x06, // INPUT (Data,Var,Rel) | 309 | 0x81, 0x06, // INPUT (Data,Var,Rel) |
| 345 | // ---------------------------- Horizontal wheel | 310 | // ---------------------------- Horizontal wheel |
| 346 | 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) | 311 | 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) |
| 347 | 0x0a, 0x38, 0x02, // USAGE (AC Pan) | 312 | 0x0a, 0x38, 0x02, // USAGE (AC Pan) |
| 348 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) | 313 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) |
| 349 | 0x25, 0x7f, // LOGICAL_MAXIMUM (127) | 314 | 0x25, 0x7f, // LOGICAL_MAXIMUM (127) |
| 350 | 0x75, 0x08, // REPORT_SIZE (8) | 315 | 0x75, 0x08, // REPORT_SIZE (8) |
| 351 | 0x95, 0x01, // REPORT_COUNT (1) | 316 | 0x95, 0x01, // REPORT_COUNT (1) |
| 352 | 0x81, 0x06, // INPUT (Data,Var,Rel) | 317 | 0x81, 0x06, // INPUT (Data,Var,Rel) |
| 353 | 0xc0, // END_COLLECTION | 318 | 0xc0, // END_COLLECTION |
| 354 | 0xc0, // END_COLLECTION | 319 | 0xc0, // END_COLLECTION |
| 355 | /* system control */ | 320 | /* system control */ |
| 356 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) | 321 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) |
| 357 | 0x09, 0x80, // USAGE (System Control) | 322 | 0x09, 0x80, // USAGE (System Control) |
| 358 | 0xa1, 0x01, // COLLECTION (Application) | 323 | 0xa1, 0x01, // COLLECTION (Application) |
| 359 | 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) | 324 | 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) |
| 360 | 0x15, 0x01, // LOGICAL_MINIMUM (0x1) | 325 | 0x15, 0x01, // LOGICAL_MINIMUM (0x1) |
| 361 | 0x26, 0xb7, 0x00, // LOGICAL_MAXIMUM (0xb7) | 326 | 0x26, 0xb7, 0x00, // LOGICAL_MAXIMUM (0xb7) |
| 362 | 0x19, 0x01, // USAGE_MINIMUM (0x1) | 327 | 0x19, 0x01, // USAGE_MINIMUM (0x1) |
| 363 | 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) | 328 | 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) |
| 364 | 0x75, 0x10, // REPORT_SIZE (16) | 329 | 0x75, 0x10, // REPORT_SIZE (16) |
| 365 | 0x95, 0x01, // REPORT_COUNT (1) | 330 | 0x95, 0x01, // REPORT_COUNT (1) |
| 366 | 0x81, 0x00, // INPUT (Data,Array,Abs) | 331 | 0x81, 0x00, // INPUT (Data,Array,Abs) |
| 367 | 0xc0, // END_COLLECTION | 332 | 0xc0, // END_COLLECTION |
| 368 | /* consumer */ | 333 | /* consumer */ |
| 369 | 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) | 334 | 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) |
| 370 | 0x09, 0x01, // USAGE (Consumer Control) | 335 | 0x09, 0x01, // USAGE (Consumer Control) |
| 371 | 0xa1, 0x01, // COLLECTION (Application) | 336 | 0xa1, 0x01, // COLLECTION (Application) |
| 372 | 0x85, REPORT_ID_CONSUMER, // REPORT_ID (3) | 337 | 0x85, REPORT_ID_CONSUMER, // REPORT_ID (3) |
| 373 | 0x15, 0x01, // LOGICAL_MINIMUM (0x1) | 338 | 0x15, 0x01, // LOGICAL_MINIMUM (0x1) |
| 374 | 0x26, 0x9c, 0x02, // LOGICAL_MAXIMUM (0x29c) | 339 | 0x26, 0x9c, 0x02, // LOGICAL_MAXIMUM (0x29c) |
| 375 | 0x19, 0x01, // USAGE_MINIMUM (0x1) | 340 | 0x19, 0x01, // USAGE_MINIMUM (0x1) |
| 376 | 0x2a, 0x9c, 0x02, // USAGE_MAXIMUM (0x29c) | 341 | 0x2a, 0x9c, 0x02, // USAGE_MAXIMUM (0x29c) |
| 377 | 0x75, 0x10, // REPORT_SIZE (16) | 342 | 0x75, 0x10, // REPORT_SIZE (16) |
| 378 | 0x95, 0x01, // REPORT_COUNT (1) | 343 | 0x95, 0x01, // REPORT_COUNT (1) |
| 379 | 0x81, 0x00, // INPUT (Data,Array,Abs) | 344 | 0x81, 0x00, // INPUT (Data,Array,Abs) |
| 380 | 0xc0, // END_COLLECTION | 345 | 0xc0, // END_COLLECTION |
| 381 | }; | 346 | }; |
| 382 | 347 | ||
| 383 | 348 | /* | |
| 384 | /* | ||
| 385 | * Descriptor for compite device: Keyboard + Mouse | 349 | * Descriptor for compite device: Keyboard + Mouse |
| 386 | * | 350 | * |
| 387 | * contains: device, interface, HID and endpoint descriptors | 351 | * contains: device, interface, HID and endpoint descriptors |
| 388 | */ | 352 | */ |
| 389 | #if USB_CFG_DESCR_PROPS_CONFIGURATION | 353 | #if USB_CFG_DESCR_PROPS_CONFIGURATION |
| 390 | const PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ | 354 | const PROGMEM char usbDescriptorConfiguration[] = { |
| 391 | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ | 355 | /* USB configuration descriptor */ |
| 392 | USBDESCR_CONFIG, /* descriptor type */ | 356 | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ |
| 357 | USBDESCR_CONFIG, /* descriptor type */ | ||
| 393 | 9 + (9 + 9 + 7) + (9 + 9 + 7), 0, | 358 | 9 + (9 + 9 + 7) + (9 + 9 + 7), 0, |
| 394 | //18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + 9, 0, | 359 | // 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + 9, 0, |
| 395 | /* total length of data returned (including inlined descriptors) */ | 360 | /* total length of data returned (including inlined descriptors) */ |
| 396 | 2, /* number of interfaces in this configuration */ | 361 | 2, /* number of interfaces in this configuration */ |
| 397 | 1, /* index of this configuration */ | 362 | 1, /* index of this configuration */ |
| 398 | 0, /* configuration name string index */ | 363 | 0, /* configuration name string index */ |
| 399 | #if USB_CFG_IS_SELF_POWERED | 364 | # if USB_CFG_IS_SELF_POWERED |
| 400 | (1 << 7) | USBATTR_SELFPOWER, /* attributes */ | 365 | (1 << 7) | USBATTR_SELFPOWER, /* attributes */ |
| 401 | #else | 366 | # else |
| 402 | (1 << 7), /* attributes */ | 367 | (1 << 7), /* attributes */ |
| 403 | #endif | 368 | # endif |
| 404 | USB_CFG_MAX_BUS_POWER/2, /* max USB current in 2mA units */ | 369 | USB_CFG_MAX_BUS_POWER / 2, /* max USB current in 2mA units */ |
| 405 | 370 | ||
| 406 | /* | 371 | /* |
| 407 | * Keyboard interface | 372 | * Keyboard interface |
| 408 | */ | 373 | */ |
| 409 | /* Interface descriptor */ | 374 | /* Interface descriptor */ |
| 410 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ | 375 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ |
| 411 | USBDESCR_INTERFACE, /* descriptor type */ | 376 | USBDESCR_INTERFACE, /* descriptor type */ |
| 412 | 0, /* index of this interface */ | 377 | 0, /* index of this interface */ |
| 413 | 0, /* alternate setting for this interface */ | 378 | 0, /* alternate setting for this interface */ |
| 414 | USB_CFG_HAVE_INTRIN_ENDPOINT, /* endpoints excl 0: number of endpoint descriptors to follow */ | 379 | USB_CFG_HAVE_INTRIN_ENDPOINT, /* endpoints excl 0: number of endpoint descriptors to follow */ |
| 415 | USB_CFG_INTERFACE_CLASS, | 380 | USB_CFG_INTERFACE_CLASS, USB_CFG_INTERFACE_SUBCLASS, USB_CFG_INTERFACE_PROTOCOL, 0, /* string index for interface */ |
| 416 | USB_CFG_INTERFACE_SUBCLASS, | ||
| 417 | USB_CFG_INTERFACE_PROTOCOL, | ||
| 418 | 0, /* string index for interface */ | ||
| 419 | /* HID descriptor */ | 381 | /* HID descriptor */ |
| 420 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ | 382 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ |
| 421 | USBDESCR_HID, /* descriptor type: HID */ | 383 | USBDESCR_HID, /* descriptor type: HID */ |
| 422 | 0x01, 0x01, /* BCD representation of HID version */ | 384 | 0x01, 0x01, /* BCD representation of HID version */ |
| 423 | 0x00, /* target country code */ | 385 | 0x00, /* target country code */ |
| 424 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ | 386 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ |
| 425 | 0x22, /* descriptor type: report */ | 387 | 0x22, /* descriptor type: report */ |
| 426 | sizeof(keyboard_hid_report), 0, /* total length of report descriptor */ | 388 | sizeof(keyboard_hid_report), 0, /* total length of report descriptor */ |
| 427 | /* Endpoint descriptor */ | 389 | /* Endpoint descriptor */ |
| 428 | #if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */ | 390 | # if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */ |
| 429 | 7, /* sizeof(usbDescrEndpoint) */ | 391 | 7, /* sizeof(usbDescrEndpoint) */ |
| 430 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ | 392 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ |
| 431 | (char)0x81, /* IN endpoint number 1 */ | 393 | (char)0x81, /* IN endpoint number 1 */ |
| 432 | 0x03, /* attrib: Interrupt endpoint */ | 394 | 0x03, /* attrib: Interrupt endpoint */ |
| 433 | 8, 0, /* maximum packet size */ | 395 | 8, 0, /* maximum packet size */ |
| 434 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ | 396 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ |
| 435 | #endif | 397 | # endif |
| 436 | 398 | ||
| 437 | /* | 399 | /* |
| 438 | * Mouse interface | 400 | * Mouse interface |
| 439 | */ | 401 | */ |
| 440 | /* Interface descriptor */ | 402 | /* Interface descriptor */ |
| 441 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ | 403 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ |
| 442 | USBDESCR_INTERFACE, /* descriptor type */ | 404 | USBDESCR_INTERFACE, /* descriptor type */ |
| 443 | 1, /* index of this interface */ | 405 | 1, /* index of this interface */ |
| 444 | 0, /* alternate setting for this interface */ | 406 | 0, /* alternate setting for this interface */ |
| 445 | USB_CFG_HAVE_INTRIN_ENDPOINT3, /* endpoints excl 0: number of endpoint descriptors to follow */ | 407 | USB_CFG_HAVE_INTRIN_ENDPOINT3, /* endpoints excl 0: number of endpoint descriptors to follow */ |
| 446 | 0x03, /* CLASS: HID */ | 408 | 0x03, /* CLASS: HID */ |
| 447 | 0, /* SUBCLASS: none */ | 409 | 0, /* SUBCLASS: none */ |
| 448 | 0, /* PROTOCOL: none */ | 410 | 0, /* PROTOCOL: none */ |
| 449 | 0, /* string index for interface */ | 411 | 0, /* string index for interface */ |
| 450 | /* HID descriptor */ | 412 | /* HID descriptor */ |
| 451 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ | 413 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ |
| 452 | USBDESCR_HID, /* descriptor type: HID */ | 414 | USBDESCR_HID, /* descriptor type: HID */ |
| 453 | 0x01, 0x01, /* BCD representation of HID version */ | 415 | 0x01, 0x01, /* BCD representation of HID version */ |
| 454 | 0x00, /* target country code */ | 416 | 0x00, /* target country code */ |
| 455 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ | 417 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ |
| 456 | 0x22, /* descriptor type: report */ | 418 | 0x22, /* descriptor type: report */ |
| 457 | sizeof(mouse_hid_report), 0, /* total length of report descriptor */ | 419 | sizeof(mouse_hid_report), 0, /* total length of report descriptor */ |
| 458 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* endpoint descriptor for endpoint 3 */ | 420 | # if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* endpoint descriptor for endpoint 3 */ |
| 459 | /* Endpoint descriptor */ | 421 | /* Endpoint descriptor */ |
| 460 | 7, /* sizeof(usbDescrEndpoint) */ | 422 | 7, /* sizeof(usbDescrEndpoint) */ |
| 461 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ | 423 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ |
| 462 | (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */ | 424 | (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */ |
| 463 | 0x03, /* attrib: Interrupt endpoint */ | 425 | 0x03, /* attrib: Interrupt endpoint */ |
| 464 | 8, 0, /* maximum packet size */ | 426 | 8, 0, /* maximum packet size */ |
| 465 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ | 427 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ |
| 466 | #endif | 428 | # endif |
| 467 | }; | 429 | }; |
| 468 | #endif | 430 | #endif |
| 469 | 431 | ||
| 470 | 432 | USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) { | |
| 471 | USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) | ||
| 472 | { | ||
| 473 | usbMsgLen_t len = 0; | 433 | usbMsgLen_t len = 0; |
| 474 | 434 | ||
| 475 | /* | 435 | /* |
| 476 | debug("usbFunctionDescriptor: "); | 436 | debug("usbFunctionDescriptor: "); |
| 477 | debug_hex(rq->bmRequestType); debug(" "); | 437 | debug_hex(rq->bmRequestType); debug(" "); |
| 478 | debug_hex(rq->bRequest); debug(" "); | 438 | debug_hex(rq->bRequest); debug(" "); |
| 479 | debug_hex16(rq->wValue.word); debug(" "); | 439 | debug_hex16(rq->wValue.word); debug(" "); |
| 480 | debug_hex16(rq->wIndex.word); debug(" "); | 440 | debug_hex16(rq->wIndex.word); debug(" "); |
| 481 | debug_hex16(rq->wLength.word); debug("\n"); | 441 | debug_hex16(rq->wLength.word); debug("\n"); |
| 482 | */ | 442 | */ |
| 483 | switch (rq->wValue.bytes[1]) { | 443 | switch (rq->wValue.bytes[1]) { |
| 484 | #if USB_CFG_DESCR_PROPS_CONFIGURATION | 444 | #if USB_CFG_DESCR_PROPS_CONFIGURATION |
| 485 | case USBDESCR_CONFIG: | 445 | case USBDESCR_CONFIG: |
| 486 | usbMsgPtr = (unsigned char *)usbDescriptorConfiguration; | 446 | usbMsgPtr = (unsigned char *)usbDescriptorConfiguration; |
| 487 | len = sizeof(usbDescriptorConfiguration); | 447 | len = sizeof(usbDescriptorConfiguration); |
| 488 | break; | 448 | break; |
| 489 | #endif | 449 | #endif |
| 490 | case USBDESCR_HID: | 450 | case USBDESCR_HID: |
| 491 | switch (rq->wValue.bytes[0]) { | 451 | switch (rq->wValue.bytes[0]) { |
| 492 | case 0: | 452 | case 0: |
| 493 | usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + 9); | 453 | usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + 9); |
| 494 | len = 9; | 454 | len = 9; |
| 495 | break; | 455 | break; |
| 496 | case 1: | 456 | case 1: |
| 497 | usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + (9 + 9 + 7) + 9); | 457 | usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + (9 + 9 + 7) + 9); |
| 498 | len = 9; | 458 | len = 9; |
| 499 | break; | 459 | break; |
| 500 | } | 460 | } |
| 501 | break; | 461 | break; |
| @@ -504,15 +464,15 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) | |||
| 504 | switch (rq->wIndex.word) { | 464 | switch (rq->wIndex.word) { |
| 505 | case 0: | 465 | case 0: |
| 506 | usbMsgPtr = (unsigned char *)keyboard_hid_report; | 466 | usbMsgPtr = (unsigned char *)keyboard_hid_report; |
| 507 | len = sizeof(keyboard_hid_report); | 467 | len = sizeof(keyboard_hid_report); |
| 508 | break; | 468 | break; |
| 509 | case 1: | 469 | case 1: |
| 510 | usbMsgPtr = (unsigned char *)mouse_hid_report; | 470 | usbMsgPtr = (unsigned char *)mouse_hid_report; |
| 511 | len = sizeof(mouse_hid_report); | 471 | len = sizeof(mouse_hid_report); |
| 512 | break; | 472 | break; |
| 513 | } | 473 | } |
| 514 | break; | 474 | break; |
| 515 | } | 475 | } |
| 516 | //debug("desc len: "); debug_hex(len); debug("\n"); | 476 | // debug("desc len: "); debug_hex(len); debug("\n"); |
| 517 | return len; | 477 | return len; |
| 518 | } | 478 | } |
diff --git a/tmk_core/protocol/vusb/vusb.h b/tmk_core/protocol/vusb/vusb.h index 5accf233b..7e3f8c394 100644 --- a/tmk_core/protocol/vusb/vusb.h +++ b/tmk_core/protocol/vusb/vusb.h | |||
| @@ -20,8 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 20 | 20 | ||
| 21 | #include "host_driver.h" | 21 | #include "host_driver.h" |
| 22 | 22 | ||
| 23 | |||
| 24 | host_driver_t *vusb_driver(void); | 23 | host_driver_t *vusb_driver(void); |
| 25 | void vusb_transfer_keyboard(void); | 24 | void vusb_transfer_keyboard(void); |
| 26 | 25 | ||
| 27 | #endif | 26 | #endif |
