From fbad822c99b957b513b018cb135b41051f93cc11 Mon Sep 17 00:00:00 2001 From: David Madison Date: Fri, 15 Feb 2019 13:54:21 -0500 Subject: Fix warning related to disabling Pluggable HID Unused if pluggable USB is not enabled. Should submit a PR to fix this in the main repo... --- cores/arduino/USBCore.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 81f689d..b5a2be3 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -496,14 +496,13 @@ bool SendConfiguration(int maxlen) static bool SendDescriptor(USBSetup& setup) { - int ret; u8 t = setup.wValueH; if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t) return SendConfiguration(setup.wLength); InitControl(setup.wLength); #ifdef PLUGGABLE_USB_ENABLED - ret = PluggableUSB().getDescriptor(setup); + int ret = PluggableUSB().getDescriptor(setup); if (ret != 0) { return (ret > 0 ? true : false); } -- cgit v1.2.3-18-g5258 From 3364c6f736a77e60f26273af0bb021f4507dd1b9 Mon Sep 17 00:00:00 2001 From: David Madison Date: Fri, 15 Feb 2019 14:44:45 -0500 Subject: Removed USB CDC Serial This will compile but will NOT enumerate properly without a config descriptor. You've been warned... --- cores/arduino/USBCore.cpp | 54 ++++++----------------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index b5a2be3..6146954 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -327,12 +327,10 @@ int USB_Send(u8 ep, const void* d, int len) u8 _initEndpoints[USB_ENDPOINTS] = { - 0, // Control Endpoint - - EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM - EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT - EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN - + 0, // Control Endpoint + // EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM + // EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT + // EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN // Following endpoints are automatically initialized to 0 }; @@ -369,21 +367,6 @@ void InitEndpoints() UERST = 0; } -// Handle CLASS_INTERFACE requests -static -bool ClassInterfaceRequest(USBSetup& setup) -{ - u8 i = setup.wIndex; - - if (CDC_ACM_INTERFACE == i) - return CDC_Setup(setup); - -#ifdef PLUGGABLE_USB_ENABLED - return PluggableUSB().setup(setup); -#endif - return false; -} - static int _cmark; static int _cend; void InitControl(int end) @@ -462,34 +445,14 @@ int USB_RecvControl(void* d, int len) return len; } -static u8 SendInterfaces() -{ - u8 interfaces = 0; - - CDC_GetInterface(&interfaces); - -#ifdef PLUGGABLE_USB_ENABLED - PluggableUSB().getInterface(&interfaces); -#endif - - return interfaces; -} - // Construct a dynamic configuration descriptor // This really needs dynamic endpoint allocation etc // TODO static bool SendConfiguration(int maxlen) { - // Count and measure interfaces - InitControl(0); - u8 interfaces = SendInterfaces(); - ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces); - - // Now send them - InitControl(maxlen); - USB_SendControl(0,&config,sizeof(ConfigDescriptor)); - SendInterfaces(); + // InitControl(maxlen); + // USB_SendControl( * Config Descriptor Here * ); return true; } @@ -632,8 +595,7 @@ ISR(USB_COM_vect) } else { - InitControl(setup.wLength); // Max length of transfer - ok = ClassInterfaceRequest(setup); + ok = true; } if (ok) @@ -754,8 +716,6 @@ ISR(USB_GEN_vect) // Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too if (udint & (1< Date: Sun, 17 Feb 2019 14:18:23 -0500 Subject: Add XInput device and config descriptors --- cores/arduino/USBCore.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 6146954..f2f5540 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -34,7 +34,6 @@ volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */ extern const u16 STRING_LANGUAGE[] PROGMEM; extern const u8 STRING_PRODUCT[] PROGMEM; extern const u8 STRING_MANUFACTURER[] PROGMEM; -extern const DeviceDescriptor USB_DeviceDescriptorIAD PROGMEM; const u16 STRING_LANGUAGE[2] = { (3<<8) | (2+2), @@ -65,13 +64,6 @@ const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT; const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER; - -#define DEVICE_CLASS 0x02 - -// DEVICE DESCRIPTOR -const DeviceDescriptor USB_DeviceDescriptorIAD = - D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1); - //================================================================== //================================================================== @@ -451,8 +443,8 @@ int USB_RecvControl(void* d, int len) static bool SendConfiguration(int maxlen) { - // InitControl(maxlen); - // USB_SendControl( * Config Descriptor Here * ); + InitControl(maxlen); + USB_SendControl(TRANSFER_PGM, &USB_ConfigDescriptor, USB_ConfigDescriptorSize); return true; } @@ -474,7 +466,7 @@ bool SendDescriptor(USBSetup& setup) const u8* desc_addr = 0; if (USB_DEVICE_DESCRIPTOR_TYPE == t) { - desc_addr = (const u8*)&USB_DeviceDescriptorIAD; + desc_addr = (const u8*) &USB_DeviceDescriptor; } else if (USB_STRING_DESCRIPTOR_TYPE == t) { -- cgit v1.2.3-18-g5258 From a326a6ed8ee990acd8452adb2733a7c5f8a9963c Mon Sep 17 00:00:00 2001 From: David Madison Date: Sun, 17 Feb 2019 17:05:16 -0500 Subject: Add XInput string descriptors --- cores/arduino/USBCore.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index f2f5540..f239999 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -484,8 +484,13 @@ bool SendDescriptor(USBSetup& setup) char name[ISERIAL_MAX_LEN]; PluggableUSB().getShortName(name); return USB_SendStringDescriptor((uint8_t*)name, strlen(name), 0); +#else + return USB_SendStringDescriptor(STRING_SERIAL, strlen((char*)STRING_SERIAL), TRANSFER_PGM); #endif } + else if (setup.wValueL == ISECURITY) { + return USB_SendStringDescriptor(STRING_SECURITY, strlen((char*)STRING_SECURITY), TRANSFER_PGM); + } else return false; } -- cgit v1.2.3-18-g5258 From 905158b7844c5e346439d18f856a7a9a59f467ab Mon Sep 17 00:00:00 2001 From: David Madison Date: Sun, 17 Feb 2019 22:58:02 -0500 Subject: Allocate XInput endpoint memory --- cores/arduino/USBCore.cpp | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index f239999..8794250 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -317,46 +317,49 @@ int USB_Send(u8 ep, const void* d, int len) return r; } -u8 _initEndpoints[USB_ENDPOINTS] = -{ - 0, // Control Endpoint - // EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM - // EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT - // EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN - // Following endpoints are automatically initialized to 0 -}; - #define EP_SINGLE_64 0x32 // EP0 #define EP_DOUBLE_64 0x36 // Other endpoints #define EP_SINGLE_16 0x12 -static +static inline +u8 BankSizeMask(const uint8_t nbytes) +{ + uint8_t mask = 0; + for (uint8_t size = 8; size < 64; size <<= 1) { + if (nbytes <= size) break; + mask++; + } + + return (mask << EPSIZE0); +} + +static inline void InitEP(u8 index, u8 type, u8 size) { - UENUM = index; - UECONX = (1<= USB_ENDPOINTS) return false; + uint8_t size = ((1 << ALLOC) | ((nbanks > 1) ? (1 << EPBK0) : 0) | BankSizeMask(banksize)); + InitEP(index, type, size); + return UESTA0X & (1 << CFGOK); // Success } static void InitEndpoints() { - for (u8 i = 1; i < sizeof(_initEndpoints) && _initEndpoints[i] != 0; i++) - { - UENUM = i; - UECONX = (1< Date: Thu, 21 Feb 2019 11:42:06 -0500 Subject: Add USB receive callback to USB ISR Using the OUT endpoint interrupt --- cores/arduino/USBCore.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 8794250..f2a2365 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -360,6 +360,9 @@ void InitEndpoints() UERST = 0x7E; // Reset endpoints UERST = 0; // End reset + + SetEP(XINPUT_RX_ENDPOINT); // Select XInput RX endpoint (OUT) + UEIENX |= (1 << RXOUTE); // Enable received "OUT" interrupt } static int _cmark; @@ -506,9 +509,17 @@ bool SendDescriptor(USBSetup& setup) return true; } -// Endpoint 0 interrupt +// Endpoint interrupt ISR(USB_COM_vect) { + SetEP(XINPUT_RX_ENDPOINT); // Select XInput RX endpoint (OUT) + if (UEINTX & (1 << RXOUTI)) { // If data received... + UEINTX &= ~(1 << RXOUTI); // Clear interrupt flag + if (XInputUSB::RecvCallback != nullptr) { + XInputUSB::RecvCallback(); // Call callback function if it exists + } + } + SetEP(0); if (!ReceivedSetupInt()) return; -- cgit v1.2.3-18-g5258 From a4453c563cedb1c57dd10d189aa792b8e84d3feb Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 21 Feb 2019 13:24:07 -0500 Subject: Use endpoint number defines for ep allocation --- cores/arduino/USBCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index f2a2365..aa52243 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -354,8 +354,8 @@ bool InitEPSize(const u8 index, const u8 type, const u8 nbanks, const u8 banksiz static void InitEndpoints() { - InitEPSize(1, EP_TYPE_INTERRUPT_IN, 1, 32); // Control Data Send - InitEPSize(2, EP_TYPE_INTERRUPT_OUT, 1, 32); // Control Data Receive + InitEPSize(XINPUT_TX_ENDPOINT, EP_TYPE_INTERRUPT_IN, 1, 32); // Control Data Send + InitEPSize(XINPUT_RX_ENDPOINT, EP_TYPE_INTERRUPT_OUT, 1, 32); // Control Data Receive InitEPSize(5, EP_TYPE_INTERRUPT_IN, 1, 32); // Expansion Interface NACK (avoid config reset) UERST = 0x7E; // Reset endpoints -- cgit v1.2.3-18-g5258 From fc18d5330ee7f3b7dc3ebc3f7e12a876464182ad Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 21 Feb 2019 13:27:40 -0500 Subject: Change receive endpoint to double-banked No reason not to take advantage of this feature, although with the interrupt in place I doubt it will be useful. --- cores/arduino/USBCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index aa52243..6e820a1 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -355,7 +355,7 @@ static void InitEndpoints() { InitEPSize(XINPUT_TX_ENDPOINT, EP_TYPE_INTERRUPT_IN, 1, 32); // Control Data Send - InitEPSize(XINPUT_RX_ENDPOINT, EP_TYPE_INTERRUPT_OUT, 1, 32); // Control Data Receive + InitEPSize(XINPUT_RX_ENDPOINT, EP_TYPE_INTERRUPT_OUT, 2, 32); // Control Data Receive InitEPSize(5, EP_TYPE_INTERRUPT_IN, 1, 32); // Expansion Interface NACK (avoid config reset) UERST = 0x7E; // Reset endpoints -- cgit v1.2.3-18-g5258