mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
added automatic one-shot TX and RX LED control for sketch USB
This commit is contained in:
parent
6b7d24edb0
commit
667da698d7
@ -30,6 +30,11 @@
|
|||||||
#define EP_TYPE_ISOCHRONOUS_IN 0x41
|
#define EP_TYPE_ISOCHRONOUS_IN 0x41
|
||||||
#define EP_TYPE_ISOCHRONOUS_OUT 0x40
|
#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--)
|
while (count--)
|
||||||
*data++ = UEDATX;
|
*data++ = UEDATX;
|
||||||
|
|
||||||
|
RXLED1; // light the RX LED
|
||||||
|
RxLEDPulse = TX_RX_LED_PULSE_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u8 Recv8()
|
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)
|
static inline void Send8(u8 d)
|
||||||
@ -206,13 +217,13 @@ u8 USB_Available(u8 ep)
|
|||||||
return FifoByteCount();
|
return FifoByteCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non Blocking recieve
|
// Non Blocking receive
|
||||||
// Return number of bytes read
|
// Return number of bytes read
|
||||||
int USB_Recv(u8 ep, void* d, int len)
|
int USB_Recv(u8 ep, void* d, int len)
|
||||||
{
|
{
|
||||||
if (!_usbConfiguration || len < 0)
|
if (!_usbConfiguration || len < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
LockEP lock(ep);
|
LockEP lock(ep);
|
||||||
u8 n = FifoByteCount();
|
u8 n = FifoByteCount();
|
||||||
len = min(n,len);
|
len = min(n,len);
|
||||||
@ -222,7 +233,7 @@ int USB_Recv(u8 ep, void* d, int len)
|
|||||||
*dst++ = Recv8();
|
*dst++ = Recv8();
|
||||||
if (len && !FifoByteCount()) // release empty buffer
|
if (len && !FifoByteCount()) // release empty buffer
|
||||||
ReleaseRX();
|
ReleaseRX();
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,6 +300,8 @@ int USB_Send(u8 ep, const void* d, int len)
|
|||||||
ReleaseTX();
|
ReleaseTX();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TXLED1; // light the TX LED
|
||||||
|
TxLEDPulse = TX_RX_LED_PULSE_MS;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,11 +319,6 @@ const u8 _initEndpoints[] =
|
|||||||
#ifdef HID_ENABLED
|
#ifdef HID_ENABLED
|
||||||
EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT
|
EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT
|
||||||
#endif
|
#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
|
#define EP_SINGLE_64 0x32 // EP0
|
||||||
@ -350,11 +358,6 @@ bool ClassInterfaceRequest(Setup& setup)
|
|||||||
return CDC_Setup(setup);
|
return CDC_Setup(setup);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MSC_ENABLED
|
|
||||||
if (MSC_INTERFACE == i)
|
|
||||||
return MSC_Setup(setup);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HID_ENABLED
|
#ifdef HID_ENABLED
|
||||||
if (HID_INTERFACE == i)
|
if (HID_INTERFACE == i)
|
||||||
return HID_Setup(setup);
|
return HID_Setup(setup);
|
||||||
@ -425,9 +428,6 @@ int SendInterfaces()
|
|||||||
total += HID_GetInterface(&interfaces);
|
total += HID_GetInterface(&interfaces);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MSC_ENABLED
|
|
||||||
total += MSC_GetInterface(&interfaces);
|
|
||||||
#endif
|
|
||||||
return interfaces;
|
return interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,8 +504,6 @@ ISR(USB_COM_vect)
|
|||||||
Recv((u8*)&setup,8);
|
Recv((u8*)&setup,8);
|
||||||
ClearSetupInt();
|
ClearSetupInt();
|
||||||
|
|
||||||
//printHex((u8*)&setup,8);
|
|
||||||
|
|
||||||
u8 requestType = setup.bmRequestType;
|
u8 requestType = setup.bmRequestType;
|
||||||
if (requestType & REQUEST_DEVICETOHOST)
|
if (requestType & REQUEST_DEVICETOHOST)
|
||||||
WaitIN();
|
WaitIN();
|
||||||
@ -596,12 +594,18 @@ ISR(USB_GEN_vect)
|
|||||||
UEIENX = 1 << RXSTPE; // Enable interrupts for ep0
|
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<<SOFI))
|
if (udint & (1<<SOFI))
|
||||||
{
|
{
|
||||||
#ifdef CDC_ENABLED
|
#ifdef CDC_ENABLED
|
||||||
USB_Flush(CDC_TX); // Send a tx frame if found
|
USB_Flush(CDC_TX); // Send a tx frame if found
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// check whether the one-shot period has elapsed. if so, turn off the LED
|
||||||
|
if (TxLEDPulse && !(--TxLEDPulse))
|
||||||
|
TXLED0;
|
||||||
|
if (RxLEDPulse && !(--RxLEDPulse))
|
||||||
|
RXLED0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,6 +638,8 @@ void USB_::attach()
|
|||||||
USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock
|
USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock
|
||||||
UDIEN = (1<<EORSTE)|(1<<SOFE); // Enable interrupts for EOR (End of Reset) and SOF (start of frame)
|
UDIEN = (1<<EORSTE)|(1<<SOFE); // Enable interrupts for EOR (End of Reset) and SOF (start of frame)
|
||||||
UDCON = 0; // enable attach resistor
|
UDCON = 0; // enable attach resistor
|
||||||
|
|
||||||
|
TX_RX_LED_INIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USB_::detach()
|
void USB_::detach()
|
||||||
@ -649,14 +655,6 @@ bool USB_::configured()
|
|||||||
|
|
||||||
void USB_::poll()
|
void USB_::poll()
|
||||||
{
|
{
|
||||||
#ifdef MSC_ENABLED
|
|
||||||
if (!_usbConfiguration)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Service disk
|
|
||||||
if (USB_Available(MSC_RX))
|
|
||||||
MSC_Data(MSC_RX,MSC_TX);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* if defined(USBCON) */
|
#endif /* if defined(USBCON) */
|
@ -28,6 +28,11 @@
|
|||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#define ARDUINO_MODEL_USB_PID 0x0034
|
#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
|
// Map SPI port to 'new' pins D14..D17
|
||||||
// D14 PB0 RXLED,SS/PCINT0
|
// D14 PB0 RXLED,SS/PCINT0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user