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<