Skip to content
Snippets Groups Projects
Commit ba02d346 authored by Sandeep Mistry's avatar Sandeep Mistry
Browse files

Add USB transfer RX/TX LED blinking

Only enabled if PIN_LED_TXL or PIN_LED_RXL is defined
parent dd6890a3
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,14 @@ ...@@ -28,6 +28,14 @@
USBDevice_SAMD21G18x usbd; USBDevice_SAMD21G18x usbd;
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
#define TX_RX_LED_PULSE_MS 100
#ifdef PIN_LED_TXL
static volatile uint8_t txLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
#endif
#ifdef PIN_LED_RXL
static volatile uint8_t rxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
#endif
static char isRemoteWakeUpEnabled = 0; static char isRemoteWakeUpEnabled = 0;
static char isEndpointHalt = 0; static char isEndpointHalt = 0;
...@@ -273,6 +281,18 @@ void USBDeviceClass::handleEndpoint(uint8_t ep) ...@@ -273,6 +281,18 @@ void USBDeviceClass::handleEndpoint(uint8_t ep)
void USBDeviceClass::init() void USBDeviceClass::init()
{ {
#ifdef PIN_LED_TXL
txLEDPulse = 0;
pinMode(PIN_LED_TXL, OUTPUT);
digitalWrite(PIN_LED_TXL, HIGH);
#endif
#ifdef PIN_LED_RXL
rxLEDPulse = 0;
pinMode(PIN_LED_RXL, OUTPUT);
digitalWrite(PIN_LED_RXL, HIGH);
#endif
// Enable USB clock // Enable USB clock
PM->APBBMASK.reg |= PM_APBBMASK_USB; PM->APBBMASK.reg |= PM_APBBMASK_USB;
...@@ -522,6 +542,11 @@ uint32_t USBDeviceClass::recv(uint32_t ep, void *_data, uint32_t len) ...@@ -522,6 +542,11 @@ uint32_t USBDeviceClass::recv(uint32_t ep, void *_data, uint32_t len)
if (available(ep) < len) if (available(ep) < len)
len = available(ep); len = available(ep);
#ifdef PIN_LED_RXL
digitalWrite(PIN_LED_RXL, LOW);
rxLEDPulse = TX_RX_LED_PULSE_MS;
#endif
armRecv(ep); armRecv(ep);
usbd.epBank0DisableTransferComplete(ep); usbd.epBank0DisableTransferComplete(ep);
...@@ -620,6 +645,11 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) ...@@ -620,6 +645,11 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
} }
#endif #endif
#ifdef PIN_LED_TXL
digitalWrite(PIN_LED_TXL, LOW);
txLEDPulse = TX_RX_LED_PULSE_MS;
#endif
// Flash area // Flash area
while (len != 0) while (len != 0)
{ {
...@@ -826,6 +856,17 @@ void USBDeviceClass::ISRHandler() ...@@ -826,6 +856,17 @@ void USBDeviceClass::ISRHandler()
if (usbd.isStartOfFrameInterrupt()) if (usbd.isStartOfFrameInterrupt())
{ {
usbd.ackStartOfFrameInterrupt(); usbd.ackStartOfFrameInterrupt();
// check whether the one-shot period has elapsed. if so, turn off the LED
#ifdef PIN_LED_TXL
if (txLEDPulse && !(--txLEDPulse))
digitalWrite(PIN_LED_TXL, HIGH);
#endif
#ifdef PIN_LED_RXL
if (rxLEDPulse && !(--rxLEDPulse))
digitalWrite(PIN_LED_RXL, HIGH);
#endif
} }
// Endpoint 0 Received Setup interrupt // Endpoint 0 Received Setup interrupt
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment