Mercurial > louis > kiibohd-controller
comparison Output/pjrcUSB/arm/usb_dev.c @ 326:05a09eda53fb
Inital Remote Wakeup Support
Not working yet...
author | Rowan Decker <Smasher816@gmail.com> |
---|---|
date | Sun, 08 Mar 2015 22:35:55 -0700 |
parents | ac842066568a |
children | f7b14e25ca5b |
comparison
equal
deleted
inserted
replaced
306:f158dfa0fa85 | 326:05a09eda53fb |
---|---|
49 //#define UART_DEBUG 1 | 49 //#define UART_DEBUG 1 |
50 // Debug Unknown USB requests, usually what you want to debug USB issues | 50 // Debug Unknown USB requests, usually what you want to debug USB issues |
51 //#define UART_DEBUG_UNKNOWN 1 | 51 //#define UART_DEBUG_UNKNOWN 1 |
52 | 52 |
53 | 53 |
54 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0 | 54 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0 |
55 #define TX_STATE_BOTH_FREE_ODD_FIRST 1 | 55 #define TX_STATE_BOTH_FREE_ODD_FIRST 1 |
56 #define TX_STATE_EVEN_FREE 2 | 56 #define TX_STATE_EVEN_FREE 2 |
57 #define TX_STATE_ODD_FREE 3 | 57 #define TX_STATE_ODD_FREE 3 |
58 #define TX_STATE_NONE_FREE_EVEN_FIRST 4 | 58 #define TX_STATE_NONE_FREE_EVEN_FIRST 4 |
59 #define TX_STATE_NONE_FREE_ODD_FIRST 5 | 59 #define TX_STATE_NONE_FREE_ODD_FIRST 5 |
60 | 60 |
61 #define BDT_OWN 0x80 | 61 #define BDT_OWN 0x80 |
62 #define BDT_DATA1 0x40 | 62 #define BDT_DATA1 0x40 |
63 #define BDT_DATA0 0x00 | 63 #define BDT_DATA0 0x00 |
64 #define BDT_DTS 0x08 | 64 #define BDT_DTS 0x08 |
65 #define BDT_STALL 0x04 | 65 #define BDT_STALL 0x04 |
66 | 66 |
67 #define TX 1 | 67 #define TX 1 |
68 #define RX 0 | 68 #define RX 0 |
69 #define ODD 1 | 69 #define ODD 1 |
70 #define EVEN 0 | 70 #define EVEN 0 |
71 #define DATA0 0 | 71 #define DATA0 0 |
72 #define DATA1 1 | 72 #define DATA1 1 |
73 | 73 |
74 | 74 |
75 #define GET_STATUS 0 | 75 #define GET_STATUS 0 |
76 #define CLEAR_FEATURE 1 | 76 #define CLEAR_FEATURE 1 |
77 #define SET_FEATURE 3 | 77 #define SET_FEATURE 3 |
78 #define SET_ADDRESS 5 | 78 #define SET_ADDRESS 5 |
79 #define GET_DESCRIPTOR 6 | 79 #define GET_DESCRIPTOR 6 |
80 #define SET_DESCRIPTOR 7 | 80 #define SET_DESCRIPTOR 7 |
81 #define GET_CONFIGURATION 8 | 81 #define GET_CONFIGURATION 8 |
82 #define SET_CONFIGURATION 9 | 82 #define SET_CONFIGURATION 9 |
83 #define GET_INTERFACE 10 | 83 #define GET_INTERFACE 10 |
84 #define SET_INTERFACE 11 | 84 #define SET_INTERFACE 11 |
85 #define SYNCH_FRAME 12 | 85 #define SYNCH_FRAME 12 |
86 | 86 |
87 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0 | 87 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0 |
88 #define TX_STATE_BOTH_FREE_ODD_FIRST 1 | 88 #define TX_STATE_BOTH_FREE_ODD_FIRST 1 |
89 #define TX_STATE_EVEN_FREE 2 | 89 #define TX_STATE_EVEN_FREE 2 |
90 #define TX_STATE_ODD_FREE 3 | 90 #define TX_STATE_ODD_FREE 3 |
91 #define TX_STATE_NONE_FREE 4 | 91 #define TX_STATE_NONE_FREE 4 |
92 | 92 |
93 | 93 |
94 | 94 |
95 | 95 |
96 | 96 |
97 // ----- Macros ----- | 97 // ----- Macros ----- |
98 | 98 |
99 #define BDT_PID(n) (((n) >> 2) & 15) | 99 #define BDT_PID(n) (((n) >> 2) & 15) |
100 | 100 |
101 #define BDT_DESC(count, data) (BDT_OWN | BDT_DTS \ | 101 #define BDT_DESC(count, data) (BDT_OWN | BDT_DTS \ |
102 | ((data) ? BDT_DATA1 : BDT_DATA0) \ | 102 | ((data) ? BDT_DATA1 : BDT_DATA0) \ |
103 | ((count) << 16)) | 103 | ((count) << 16)) |
104 | 104 |
105 #define index(endpoint, tx, odd) (((endpoint) << 2) | ((tx) << 1) | (odd)) | 105 #define index(endpoint, tx, odd) (((endpoint) << 2) | ((tx) << 1) | (odd)) |
106 #define stat2bufferdescriptor(stat) (table + ((stat) >> 2)) | 106 #define stat2bufferdescriptor(stat) (table + ((stat) >> 2)) |
165 volatile uint8_t usb_configuration = 0; | 165 volatile uint8_t usb_configuration = 0; |
166 volatile uint8_t usb_reboot_timer = 0; | 166 volatile uint8_t usb_reboot_timer = 0; |
167 | 167 |
168 static uint8_t reply_buffer[8]; | 168 static uint8_t reply_buffer[8]; |
169 | 169 |
170 volatile uint8_t remote_wakeup_enabled = 0; | |
170 | 171 |
171 | 172 |
172 // ----- Functions ----- | 173 // ----- Functions ----- |
173 | 174 |
174 static void endpoint0_stall() | 175 static void endpoint0_stall() |
292 reply_buffer[0] = usb_configuration; | 293 reply_buffer[0] = usb_configuration; |
293 datalen = 1; | 294 datalen = 1; |
294 data = reply_buffer; | 295 data = reply_buffer; |
295 break; | 296 break; |
296 case 0x0080: // GET_STATUS (device) | 297 case 0x0080: // GET_STATUS (device) |
297 reply_buffer[0] = 0; | 298 //I think this is the corrent endianess |
299 reply_buffer[0] = (remote_wakeup_enabled)<<1; | |
298 reply_buffer[1] = 0; | 300 reply_buffer[1] = 0; |
299 datalen = 2; | 301 datalen = 2; |
300 data = reply_buffer; | 302 data = reply_buffer; |
301 break; | 303 break; |
302 case 0x0082: // GET_STATUS (endpoint) | 304 case 0x0082: // GET_STATUS (endpoint) |
312 reply_buffer[0] = 1; | 314 reply_buffer[0] = 1; |
313 data = reply_buffer; | 315 data = reply_buffer; |
314 datalen = 2; | 316 datalen = 2; |
315 break; | 317 break; |
316 case 0x0100: // CLEAR_FEATURE (device) | 318 case 0x0100: // CLEAR_FEATURE (device) |
319 //Disable DEVICE_REMOTE_WAKEUP feature | |
320 if (setup.wValue == 0x01) { | |
321 remote_wakeup_enabled = 0; | |
322 } | |
323 break; | |
317 case 0x0101: // CLEAR_FEATURE (interface) | 324 case 0x0101: // CLEAR_FEATURE (interface) |
318 // TODO: Currently ignoring, perhaps useful? -HaaTa | 325 // TODO: Currently ignoring, perhaps useful? -HaaTa |
319 endpoint0_stall(); | 326 endpoint0_stall(); |
320 return; | 327 return; |
321 case 0x0102: // CLEAR_FEATURE (interface) | 328 case 0x0102: // CLEAR_FEATURE (interface) |
332 // FIXME: Clearing causes keyboard to freeze, likely an invalid clear | 339 // FIXME: Clearing causes keyboard to freeze, likely an invalid clear |
333 // XXX: Ignoring seems to work, though this may not be the ideal behaviour -HaaTa | 340 // XXX: Ignoring seems to work, though this may not be the ideal behaviour -HaaTa |
334 endpoint0_stall(); | 341 endpoint0_stall(); |
335 return; | 342 return; |
336 case 0x0300: // SET_FEATURE (device) | 343 case 0x0300: // SET_FEATURE (device) |
344 //Enable DEVICE_REMOTE_WAKEUP feature | |
345 if (setup.wValue == 0x01) { | |
346 remote_wakeup_enabled = 1; | |
347 } | |
348 break; | |
337 case 0x0301: // SET_FEATURE (interface) | 349 case 0x0301: // SET_FEATURE (interface) |
338 // TODO: Currently ignoring, perhaps useful? -HaaTa | 350 // TODO: Currently ignoring, perhaps useful? -HaaTa |
339 endpoint0_stall(); | 351 endpoint0_stall(); |
340 return; | 352 return; |
341 case 0x0302: // SET_FEATURE (endpoint) | 353 case 0x0302: // SET_FEATURE (endpoint) |
934 serial_print(((uint32_t)b & 8) ? ", odd" : ", even"); | 946 serial_print(((uint32_t)b & 8) ? ", odd" : ", even"); |
935 serial_print(", count:"); | 947 serial_print(", count:"); |
936 serial_phex(b->desc >> 16); | 948 serial_phex(b->desc >> 16); |
937 serial_print("\n"); | 949 serial_print("\n"); |
938 #endif | 950 #endif |
939 endpoint--; // endpoint is index to zero-based arrays | 951 endpoint--; // endpoint is index to zero-based arrays |
940 | 952 |
941 if ( stat & 0x08 ) | 953 if ( stat & 0x08 ) |
942 { // transmit | 954 { // transmit |
943 usb_free( packet ); | 955 usb_free( packet ); |
944 packet = tx_first[ endpoint ]; | 956 packet = tx_first[ endpoint ]; |
1106 if ( (status & USB_ISTAT_SLEEP /* 10 */ ) ) | 1118 if ( (status & USB_ISTAT_SLEEP /* 10 */ ) ) |
1107 { | 1119 { |
1108 //serial_print("sleep\n"); | 1120 //serial_print("sleep\n"); |
1109 USB0_ISTAT = USB_ISTAT_SLEEP; | 1121 USB0_ISTAT = USB_ISTAT_SLEEP; |
1110 } | 1122 } |
1123 | |
1124 if ( (status & USB_ISTAT_RESUME /* 20 */ ) ) { | |
1125 //serial_print("resume\n"); | |
1126 USB0_ISTAT = USB_ISTAT_RESUME; | |
1127 } | |
1111 } | 1128 } |
1112 | 1129 |
1113 | 1130 |
1114 | 1131 |
1115 uint8_t usb_init() | 1132 uint8_t usb_init() |
1119 #endif | 1136 #endif |
1120 | 1137 |
1121 // If no USB cable is attached, do not initialize usb | 1138 // If no USB cable is attached, do not initialize usb |
1122 // XXX Test -HaaTa | 1139 // XXX Test -HaaTa |
1123 //if ( USB0_OTGISTAT & USB_OTGSTAT_ID ) | 1140 //if ( USB0_OTGISTAT & USB_OTGSTAT_ID ) |
1124 // return 0; | 1141 // return 0; |
1125 | 1142 |
1126 // Clear out endpoints table | 1143 // Clear out endpoints table |
1127 for ( int i = 0; i <= NUM_ENDPOINTS * 4; i++ ) | 1144 for ( int i = 0; i <= NUM_ENDPOINTS * 4; i++ ) |
1128 { | 1145 { |
1129 table[i].desc = 0; | 1146 table[i].desc = 0; |