comparison Output/pjrcUSB/arm/usb_dev.c @ 439:68e19d7c953e

Adding proper remote wake-up support - Maintains a sleep state variable (may be able to use as a signal in the future) - On the first keypress, hold the RESUME signal for 10 ms (spec says between 1 and 15 ms) - Removed some messages that were affecting sleep state
author Jacob Alexander <haata@kiibohd.com>
date Tue, 17 May 2016 01:18:14 -0700
parents f10c2dad7f55
children 56237ba5da6f
comparison
equal deleted inserted replaced
438:f10c2dad7f55 439:68e19d7c953e
169 static uint8_t reply_buffer[8]; 169 static uint8_t reply_buffer[8];
170 170
171 static uint8_t power_neg_delay; 171 static uint8_t power_neg_delay;
172 static uint32_t power_neg_time; 172 static uint32_t power_neg_time;
173 173
174 static uint8_t usb_dev_sleep = 0;
175
174 176
175 177
176 // ----- Functions ----- 178 // ----- Functions -----
177 179
178 static void endpoint0_stall() 180 static void endpoint0_stall()
975 //#define index(endpoint, tx, odd) (((endpoint) << 2) | ((tx) << 1) | (odd)) 977 //#define index(endpoint, tx, odd) (((endpoint) << 2) | ((tx) << 1) | (odd))
976 //#define stat2bufferdescriptor(stat) (table + ((stat) >> 2)) 978 //#define stat2bufferdescriptor(stat) (table + ((stat) >> 2))
977 979
978 void usb_tx( uint32_t endpoint, usb_packet_t *packet ) 980 void usb_tx( uint32_t endpoint, usb_packet_t *packet )
979 { 981 {
982 // If we have been sleeping, try to wake up host
983 if ( usb_dev_sleep )
984 {
985 // Force wake-up for 10 ms
986 // According to the USB Spec a device must hold resume for at least 1 ms but no more than 15 ms
987 USB0_CTL |= USB_CTL_RESUME;
988 delay(10);
989 USB0_CTL &= ~(USB_CTL_RESUME);
990 }
991
980 // Since we are transmitting data, USB will be brought out of sleep/suspend 992 // Since we are transmitting data, USB will be brought out of sleep/suspend
981 // if it's in that state 993 // if it's in that state
982 // Use the currently set descriptor value 994 // Use the currently set descriptor value
983 Output_update_usb_current( *usb_bMaxPower * 2 ); 995 Output_update_usb_current( *usb_bMaxPower * 2 );
984 996
1255 USB0_INTEN = USB_INTEN_TOKDNEEN | 1267 USB0_INTEN = USB_INTEN_TOKDNEEN |
1256 USB_INTEN_SOFTOKEN | 1268 USB_INTEN_SOFTOKEN |
1257 USB_INTEN_STALLEN | 1269 USB_INTEN_STALLEN |
1258 USB_INTEN_ERROREN | 1270 USB_INTEN_ERROREN |
1259 USB_INTEN_USBRSTEN | 1271 USB_INTEN_USBRSTEN |
1272 USB_INTEN_RESUMEEN |
1260 USB_INTEN_SLEEPEN; 1273 USB_INTEN_SLEEPEN;
1261 1274
1262 // is this necessary? 1275 // is this necessary?
1263 USB0_CTL = USB_CTL_USBENSOFEN; 1276 USB0_CTL = USB_CTL_USBENSOFEN;
1264 return; 1277 return;
1283 1296
1284 // USB Host signalling device to enter 'sleep' state 1297 // USB Host signalling device to enter 'sleep' state
1285 // The USB Module triggers this interrupt when it detects the bus has been idle for 3 ms 1298 // The USB Module triggers this interrupt when it detects the bus has been idle for 3 ms
1286 if ( (status & USB_ISTAT_SLEEP /* 10 */ ) ) 1299 if ( (status & USB_ISTAT_SLEEP /* 10 */ ) )
1287 { 1300 {
1288 info_print("Host has requested USB sleep/suspend state"); 1301 //info_print("Host has requested USB sleep/suspend state");
1289 Output_update_usb_current( 100 ); // Set to 100 mA 1302 Output_update_usb_current( 100 ); // Set to 100 mA
1290 USB0_ISTAT = USB_ISTAT_SLEEP; 1303 usb_dev_sleep = 1;
1304 USB0_ISTAT |= USB_ISTAT_SLEEP;
1305 }
1306
1307 // On USB Resume, unset the usb_dev_sleep so we don't keep sending resume signals
1308 if ( (status & USB_ISTAT_RESUME /* 20 */ ) )
1309 {
1310 //info_print("Host has woken-up/resumed from sleep/suspend state");
1311 Output_update_usb_current( *usb_bMaxPower * 2 );
1312 usb_dev_sleep = 0;
1313 USB0_ISTAT |= USB_ISTAT_RESUME;
1291 } 1314 }
1292 } 1315 }
1293 1316
1294 1317
1295 1318
1344 USB0_CONTROL = USB_CONTROL_DPPULLUPNONOTG; 1367 USB0_CONTROL = USB_CONTROL_DPPULLUPNONOTG;
1345 1368
1346 // Do not check for power negotiation delay until Get Configuration Descriptor 1369 // Do not check for power negotiation delay until Get Configuration Descriptor
1347 power_neg_delay = 0; 1370 power_neg_delay = 0;
1348 1371
1372 // During initialization host isn't sleeping
1373 usb_dev_sleep = 0;
1374
1349 return 1; 1375 return 1;
1350 } 1376 }
1351 1377
1352 // return 0 if the USB is not configured, or the configuration 1378 // return 0 if the USB is not configured, or the configuration
1353 // number selected by the HOST 1379 // number selected by the HOST