From 8e0f035c9b0755e443cd0a3834fad855d367c545 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Fri, 16 Sep 2011 14:32:25 -0400 Subject: added automatic one-shot TX and RX LED control for sketch USB --- cores/arduino/USBCore.cpp | 54 +++++++++++++++++++--------------------- variants/leonardo/pins_arduino.h | 5 ++++ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index af4fca9..398bc73 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -30,6 +30,11 @@ #define EP_TYPE_ISOCHRONOUS_IN 0x41 #define EP_TYPE_ISOCHRONOUS_OUT 0x40 +/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */ +#define TX_RX_LED_PULSE_MS 100 +volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */ +volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */ + //================================================================== //================================================================== @@ -108,11 +113,17 @@ void Recv(volatile u8* data, u8 count) { while (count--) *data++ = UEDATX; + + RXLED1; // light the RX LED + RxLEDPulse = TX_RX_LED_PULSE_MS; } static inline u8 Recv8() { - return UEDATX; + RXLED1; // light the RX LED + RxLEDPulse = TX_RX_LED_PULSE_MS; + + return UEDATX; } static inline void Send8(u8 d) @@ -206,13 +217,13 @@ u8 USB_Available(u8 ep) return FifoByteCount(); } -// Non Blocking recieve +// Non Blocking receive // Return number of bytes read int USB_Recv(u8 ep, void* d, int len) { if (!_usbConfiguration || len < 0) return -1; - + LockEP lock(ep); u8 n = FifoByteCount(); len = min(n,len); @@ -222,7 +233,7 @@ int USB_Recv(u8 ep, void* d, int len) *dst++ = Recv8(); if (len && !FifoByteCount()) // release empty buffer ReleaseRX(); - + return len; } @@ -289,6 +300,8 @@ int USB_Send(u8 ep, const void* d, int len) ReleaseTX(); } } + TXLED1; // light the TX LED + TxLEDPulse = TX_RX_LED_PULSE_MS; return r; } @@ -306,11 +319,6 @@ const u8 _initEndpoints[] = #ifdef HID_ENABLED EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT #endif - -#ifdef MSC_ENABLED - EP_TYPE_BULK_OUT, // MSC_ENDPOINT_OUT - EP_TYPE_BULK_IN, // MSC_ENDPOINT_IN -#endif }; #define EP_SINGLE_64 0x32 // EP0 @@ -350,11 +358,6 @@ bool ClassInterfaceRequest(Setup& setup) return CDC_Setup(setup); #endif -#ifdef MSC_ENABLED - if (MSC_INTERFACE == i) - return MSC_Setup(setup); -#endif - #ifdef HID_ENABLED if (HID_INTERFACE == i) return HID_Setup(setup); @@ -425,9 +428,6 @@ int SendInterfaces() total += HID_GetInterface(&interfaces); #endif -#ifdef MSC_ENABLED - total += MSC_GetInterface(&interfaces); -#endif return interfaces; } @@ -504,8 +504,6 @@ ISR(USB_COM_vect) Recv((u8*)&setup,8); ClearSetupInt(); - //printHex((u8*)&setup,8); - u8 requestType = setup.bmRequestType; if (requestType & REQUEST_DEVICETOHOST) WaitIN(); @@ -596,12 +594,18 @@ ISR(USB_GEN_vect) UEIENX = 1 << RXSTPE; // Enable interrupts for ep0 } - // Start of Frame + // Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too if (udint & (1< #define ARDUINO_MODEL_USB_PID 0x0034 +#define TX_RX_LED_INIT DDRE |= (1<<6), DDRB |= (1<<0) +#define TXLED0 PORTE |= (1<<6) +#define TXLED1 PORTE &= ~(1<<6) +#define RXLED0 PORTB |= (1<<0) +#define RXLED1 PORTB &= ~(1<<0) // Map SPI port to 'new' pins D14..D17 // D14 PB0 RXLED,SS/PCINT0 -- cgit v1.2.3-18-g5258