|
28 | 28 |
|
29 | 29 | USBDevice_SAMD21G18x usbd; |
30 | 30 |
|
| 31 | +/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */ |
| 32 | +#define TX_RX_LED_PULSE_MS 100 |
| 33 | +#ifdef PIN_LED_TXL |
| 34 | +static volatile uint8_t txLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */ |
| 35 | +#endif |
| 36 | +#ifdef PIN_LED_RXL |
| 37 | +static volatile uint8_t rxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */ |
| 38 | +#endif |
31 | 39 | static char isRemoteWakeUpEnabled = 0; |
32 | 40 | static char isEndpointHalt = 0; |
33 | 41 |
|
@@ -273,6 +281,18 @@ void USBDeviceClass::handleEndpoint(uint8_t ep) |
273 | 281 |
|
274 | 282 | void USBDeviceClass::init() |
275 | 283 | { |
| 284 | +#ifdef PIN_LED_TXL |
| 285 | + txLEDPulse = 0; |
| 286 | + pinMode(PIN_LED_TXL, OUTPUT); |
| 287 | + digitalWrite(PIN_LED_TXL, HIGH); |
| 288 | +#endif |
| 289 | + |
| 290 | +#ifdef PIN_LED_RXL |
| 291 | + rxLEDPulse = 0; |
| 292 | + pinMode(PIN_LED_RXL, OUTPUT); |
| 293 | + digitalWrite(PIN_LED_RXL, HIGH); |
| 294 | +#endif |
| 295 | + |
276 | 296 | // Enable USB clock |
277 | 297 | PM->APBBMASK.reg |= PM_APBBMASK_USB; |
278 | 298 |
|
@@ -522,6 +542,11 @@ uint32_t USBDeviceClass::recv(uint32_t ep, void *_data, uint32_t len) |
522 | 542 | if (available(ep) < len) |
523 | 543 | len = available(ep); |
524 | 544 |
|
| 545 | +#ifdef PIN_LED_RXL |
| 546 | + digitalWrite(PIN_LED_RXL, LOW); |
| 547 | + rxLEDPulse = TX_RX_LED_PULSE_MS; |
| 548 | +#endif |
| 549 | + |
525 | 550 | armRecv(ep); |
526 | 551 |
|
527 | 552 | usbd.epBank0DisableTransferComplete(ep); |
@@ -620,6 +645,11 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) |
620 | 645 | } |
621 | 646 | #endif |
622 | 647 |
|
| 648 | +#ifdef PIN_LED_TXL |
| 649 | + digitalWrite(PIN_LED_TXL, LOW); |
| 650 | + txLEDPulse = TX_RX_LED_PULSE_MS; |
| 651 | +#endif |
| 652 | + |
623 | 653 | // Flash area |
624 | 654 | while (len != 0) |
625 | 655 | { |
@@ -826,6 +856,17 @@ void USBDeviceClass::ISRHandler() |
826 | 856 | if (usbd.isStartOfFrameInterrupt()) |
827 | 857 | { |
828 | 858 | usbd.ackStartOfFrameInterrupt(); |
| 859 | + |
| 860 | + // check whether the one-shot period has elapsed. if so, turn off the LED |
| 861 | +#ifdef PIN_LED_TXL |
| 862 | + if (txLEDPulse && !(--txLEDPulse)) |
| 863 | + digitalWrite(PIN_LED_TXL, HIGH); |
| 864 | +#endif |
| 865 | + |
| 866 | +#ifdef PIN_LED_RXL |
| 867 | + if (rxLEDPulse && !(--rxLEDPulse)) |
| 868 | + digitalWrite(PIN_LED_RXL, HIGH); |
| 869 | +#endif |
829 | 870 | } |
830 | 871 |
|
831 | 872 | // Endpoint 0 Received Setup interrupt |
|
0 commit comments