diff options
Diffstat (limited to 'cores/arduino')
-rw-r--r-- | cores/arduino/USBCore.cpp | 87 | ||||
-rw-r--r-- | cores/arduino/USBDesc.h | 37 |
2 files changed, 50 insertions, 74 deletions
diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 9ce2e00..398bc73 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -30,11 +30,17 @@ #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 */ + //================================================================== //================================================================== extern const u16 STRING_LANGUAGE[] PROGMEM; -extern const u16 STRING_SERIAL[] PROGMEM; +extern const u16 STRING_IPRODUCT[] PROGMEM; +extern const u16 STRING_IMANUFACTURER[] PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM; @@ -43,16 +49,18 @@ const u16 STRING_LANGUAGE[2] = { 0x0409 // English }; -#if 0 -const u16 STRING_PRODUCT[] = { - (3<<8) | (2+2*10), - PRODUCT_NAME -}; +const u16 STRING_IPRODUCT[17] = { + (3<<8) | (2+2*16), +#if USB_PID == USB_PID_LEONARDO + 'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o' +#elif USB_PID == USB_PID_MICRO + 'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' ' #endif +}; -const u16 STRING_SERIAL[13] = { - (3<<8) | (2+2*12), - MSC_DISK_SERIAL +const u16 STRING_IMANUFACTURER[12] = { + (3<<8) | (2+2*11), + 'A','r','d','u','i','n','o',' ','L','L','C' }; #ifdef CDC_ENABLED @@ -63,10 +71,10 @@ const u16 STRING_SERIAL[13] = { // DEVICE DESCRIPTOR const DeviceDescriptor USB_DeviceDescriptor = - D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,0,IPRODUCT,ISERIAL,1); + D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); const DeviceDescriptor USB_DeviceDescriptorA = - D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,0,IPRODUCT,ISERIAL,1); + D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); //================================================================== //================================================================== @@ -105,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) @@ -203,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); @@ -219,7 +233,7 @@ int USB_Recv(u8 ep, void* d, int len) *dst++ = Recv8(); if (len && !FifoByteCount()) // release empty buffer ReleaseRX(); - + return len; } @@ -286,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; } @@ -303,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 @@ -347,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); @@ -422,9 +428,6 @@ int SendInterfaces() total += HID_GetInterface(&interfaces); #endif -#ifdef MSC_ENABLED - total += MSC_GetInterface(&interfaces); -#endif return interfaces; } @@ -473,8 +476,12 @@ bool SendDescriptor(Setup& setup) { if (setup.wValueL == 0) desc_addr = (const u8*)&STRING_LANGUAGE; - if (setup.wValueL == ISERIAL) - desc_addr = (const u8*)&STRING_SERIAL; + else if (setup.wValueL == IPRODUCT) + desc_addr = (const u8*)&STRING_IPRODUCT; + else if (setup.wValueL == IMANUFACTURER) + desc_addr = (const u8*)&STRING_IMANUFACTURER; + else + return false; } if (desc_addr == 0) @@ -497,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(); @@ -589,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<<SOFI)) { #ifdef CDC_ENABLED USB_Flush(CDC_TX); // Send a tx frame if found #endif + + // check whether the one-shot period has elapsed. if so, turn off the LED + if (TxLEDPulse && !(--TxLEDPulse)) + TXLED0; + if (RxLEDPulse && !(--RxLEDPulse)) + RXLED0; } } @@ -627,6 +638,8 @@ void USB_::attach() 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) UDCON = 0; // enable attach resistor + + TX_RX_LED_INIT; } void USB_::detach() @@ -642,14 +655,6 @@ bool USB_::configured() 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) */
\ No newline at end of file diff --git a/cores/arduino/USBDesc.h b/cores/arduino/USBDesc.h index 7d767d1..549ed9e 100644 --- a/cores/arduino/USBDesc.h +++ b/cores/arduino/USBDesc.h @@ -18,7 +18,6 @@ #define CDC_ENABLED #define HID_ENABLED -//#define MSC_ENABLED #ifdef CDC_ENABLED @@ -37,14 +36,6 @@ #define HID_ENPOINT_COUNT 0 #endif -#ifdef MSC_ENABLED -#define MSC_INTERFACE_COUNT 1 -#define MSC_ENPOINT_COUNT 2 -#else -#define MSC_INTERFACE_COUNT 0 -#define MSC_ENPOINT_COUNT 0 -#endif - #define CDC_ACM_INTERFACE 0 // CDC ACM #define CDC_DATA_INTERFACE 1 // CDC Data #define CDC_FIRST_ENDPOINT 1 @@ -56,11 +47,6 @@ #define HID_FIRST_ENDPOINT (CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT) #define HID_ENDPOINT_INT (HID_FIRST_ENDPOINT) -#define MSC_INTERFACE (HID_INTERFACE + HID_INTERFACE_COUNT) // MSC Interface -#define MSC_FIRST_ENDPOINT (HID_FIRST_ENDPOINT + HID_ENPOINT_COUNT) -#define MSC_ENDPOINT_OUT (MSC_FIRST_ENDPOINT) -#define MSC_ENDPOINT_IN (MSC_FIRST_ENDPOINT+1) - #define INTERFACE_COUNT (MSC_INTERFACE + MSC_INTERFACE_COUNT) #ifdef CDC_ENABLED @@ -72,25 +58,10 @@ #define HID_TX HID_ENDPOINT_INT #endif -#ifdef MSC_ENABLED -#define MSC_RX MSC_ENDPOINT_OUT -#define MSC_TX MSC_ENDPOINT_IN -#endif - - -#define IMANUFACTURER 0 -#define IPRODUCT 0 -#define ISERIAL 1 // Only need this for MSC - - -#define WRITABLE_DIRECTORY // undef saved 56 + 512 RAM - -#define FAT_DISK_LABEL 'b','o','o','t','l','o','a','d','e','r',' ' // 11 chars (undef saves 12) -#define FAT_FILE_NAME 'F','I','R','M','W','A','R','E','B','I','N' // 11 chars -#define MSC_DISK_SERIAL '0','0','0','0','0','0','0','0','1','7','0','1' // 12 chars - +#define IMANUFACTURER 1 +#define IPRODUCT 2 +#define USB_PID_LEONARDO 0x0034 +#define USB_PID_MICRO 0x0035 #define USB_VID 0x2341 // arduino LLC vid #define USB_PID ARDUINO_MODEL_USB_PID -#define FAT_OEM_NAME 'l','e','o','n','a','r','d','o' // 8 chars -#define PRODUCT_NAME 'A','r','d','u','i','n','o','l','l','c' // 10 |