From 60b8a6df837a31bc9783cf34a98bcda9917b7ba6 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sun, 17 Feb 2019 14:18:23 -0500 Subject: Add XInput device and config descriptors --- cores/arduino/xinput/USB_XInput_Descriptors.cpp | 207 ++++++++++++++++++++++++ cores/arduino/xinput/USB_XInput_Descriptors.h | 46 ++++++ 2 files changed, 253 insertions(+) create mode 100644 cores/arduino/xinput/USB_XInput_Descriptors.cpp create mode 100644 cores/arduino/xinput/USB_XInput_Descriptors.h (limited to 'cores/arduino/xinput') diff --git a/cores/arduino/xinput/USB_XInput_Descriptors.cpp b/cores/arduino/xinput/USB_XInput_Descriptors.cpp new file mode 100644 index 0000000..c9acd02 --- /dev/null +++ b/cores/arduino/xinput/USB_XInput_Descriptors.cpp @@ -0,0 +1,207 @@ +/* + * Project Arduino XInput - AVR Core + * @author David Madison + * @link github.com/dmadison/ArduinoXInput_AVR + * @license MIT - Copyright (c) 2019 David Madison + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include "USB_XInput_Descriptors.h" + +#if defined(USBCON) + +const DeviceDescriptor USB_DeviceDescriptor = { + 0x12, // bLength (18) + 0x01, // bDescriptorType (DEVICE) + USB_VERSION, // bcdUSB (2.0) + 0xFF, // bDeviceClass + 0xFF, // bDeviceSubClass + 0xFF, // bDeviceProtocol + 0x40, // bMaxPacketSize0 + USB_VID, // idEVendor + USB_PID, // idProduct + 0x114, // bcdDevice + IMANUFACTURER, // iManufacturer + IPRODUCT, // iProduct + ISERIAL, // iSerialNumber + 0x01, // bNumConfigurations +}; + +const u8 USB_ConfigDescriptor[] = { + // Configuration Descriptor + 0x09, // bLength + 0x02, // bDescriptorType (CONFIGURATION) + 0x99, 0x00, // wTotalLength (153) + 0x04, // bNumInterfaces + 0x01, // bConfigurationValue + 0x00, // iConfiguration + 0xA0, // bmAttributes + 0xFA, // bMaxPower + + /* ---------------------------------------------------- */ + // Interface 0: Control Data + 0x09, // bLength + 0x04, // bDescriptorType (INTERFACE) + 0x00, // bInterfaceNumber + 0x00, // bAlternateSetting + 0x02, // bNumEndpoints + 0xFF, // bInterfaceClass + 0x5D, // bInterfaceSubClass + 0x01, // bInterfaceProtocol + 0x00, // iInterface + + // Unknown Descriptor (If0) + 0x11, // bLength + 0x21, // bDescriptorType + 0x00, 0x01, 0x01, 0x25, // ??? + 0x81, // bEndpointAddress (IN, 1) + 0x14, // bMaxDataSize + 0x00, 0x00, 0x00, 0x00, 0x13, // ??? + 0x01, // bEndpointAddress (OUT, 1) + 0x08, // bMaxDataSize + 0x00, 0x00, // ??? + + // Endpoint 1: Control Data Out + 0x07, // bLength + 0x05, // bDescriptorType (ENDPOINT) + 0x81, // bEndpointAddress (IN, 1) + 0x03, // bmAttributes + 0x20, 0x00, // wMaxPacketSize + 0x04, // bInterval + + // Endpoint 1: Control Data In + 0x07, // bLength + 0x05, // bDescriptorType (ENDPOINT) + 0x01, // bEndpointAddress (OUT, 1) + 0x03, // bmAttributes + 0x20, 0x00, // wMaxPacketSize + 0x08, // bInterval + + /* ---------------------------------------------------- */ + // Interface 1: Headset (and Expansion Port?) + 0x09, // bLength + 0x04, // bDescriptorType (INTERFACE) + 0x01, // bInterfaceNumber + 0x00, // bAlternateSetting + 0x04, // bNumEndpoints + 0xFF, // bInterfaceClass + 0x5D, // bInterfaceSubClass + 0x03, // bInterfaceProtocol + 0x00, // iInterface + + // Unknown Descriptor (If1) + 0x1B, // bLength + 0x21, // bDescriptorType + 0x00, 0x01, 0x01, 0x01, // ??? + 0x82, // bEndpointAddress (IN, 2) + 0x40, // bMaxDataSize + 0x01, // ??? + 0x02, // bEndpointAddress (OUT, 2) + 0x20, // bMaxDataSize + 0x16, // ??? + 0x83, // bEndpointAddress (IN, 3) + 0x00, // bMaxDataSize + 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, // ??? + 0x03, // bEndpointAddress (OUT, 3) + 0x00, // bMaxDataSize + 0x00, 0x00, 0x00, 0x00, 0x00, // ??? + + // Endpoint 2: Microphone Data Out + 0x07, // bLength + 0x05, // bDescriptorType (ENDPOINT) + 0x82, // bEndpointAddress (IN, 2) + 0x03, // bmAttributes + 0x20, 0x00, // wMaxPacketSize + 0x02, // bInterval + + // Endpoint 2: Headset Audio In + 0x07, // bLength + 0x05, // bDescriptorType (ENDPOINT) + 0x02, // bEndpointAddress (OUT, 2) + 0x03, // bmAttributes + 0x20, 0x00, // wMaxPacketSize + 0x04, // bInterval + + // Endpoint 3: Unknown, Out + 0x07, // bLength + 0x05, // bDescriptorType (ENDPOINT) + 0x83, // bEndpointAddress (IN, 3) + 0x03, // bmAttributes + 0x20, 0x00, // wMaxPacketSize + 0x40, // bInterval + + // Endpoint 3: Unknown, In + 0x07, // bLength + 0x05, // bDescriptorType (ENDPOINT) + 0x03, // bEndpointAddress (OUT, 3) + 0x03, // bmAttributes + 0x20, 0x00, // wMaxPacketSize + 0x10, // bInterval + + /* ---------------------------------------------------- */ + // Interface 2: Unknown + 0x09, // bLength + 0x04, // bDescriptorType (INTERFACE) + 0x02, // bInterfaceNumber + 0x00, // bAlternateSetting + 0x01, // bNumEndpoints + 0xFF, // bInterfaceClass + 0x5D, // bInterfaceSubClass + 0x02, // bInterfaceProtocol + 0x00, // iInterface + + // Unknown Descriptor (If2) + 0x09, // bLength + 0x21, // bDescriptorType + 0x00, 0x01, 0x01, 0x22, // ??? + 0x84, // bEndpointAddress (IN, 4) + 0x07, // bMaxDataSize + 0x00, // ??? + + // Endpoint 4: Unknown, Out + 0x07, // bLength + 0x05, // bDescriptorType (ENDPOINT) + 0x84, // bEndpointAddress (IN, 4) + 0x03, // bmAttributes + 0x20, 0x00, // wMaxPacketSize + 0x10, // bInterval + + /* ---------------------------------------------------- */ + // Interface 3: Security Method + 0x09, // bLength + 0x04, // bDescriptorType (INTERFACE) + 0x03, // bInterfaceNumber + 0x00, // bAlternateSetting + 0x00, // bNumEndpoints + 0xFF, // bInterfaceClass + 0xFD, // bInterfaceSubClass + 0x13, // bInterfaceProtocol + 0x04, // iInterface + + // Unknown Descriptor (If3) + 0x06, // bLength + 0x41, // bDescriptorType + 0x00, 0x01, 0x01, 0x03, // ??? +}; + +const u16 USB_ConfigDescriptorSize = sizeof(USB_ConfigDescriptor); + +#endif /* if defined(USBCON) */ diff --git a/cores/arduino/xinput/USB_XInput_Descriptors.h b/cores/arduino/xinput/USB_XInput_Descriptors.h new file mode 100644 index 0000000..e8c3c24 --- /dev/null +++ b/cores/arduino/xinput/USB_XInput_Descriptors.h @@ -0,0 +1,46 @@ +/* + * Project Arduino XInput - AVR Core + * @author David Madison + * @link github.com/dmadison/ArduinoXInput_AVR + * @license MIT - Copyright (c) 2019 David Madison + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include "USBAPI.h" + +#ifndef USB_XINPUT_DESCRIPTORS_H +#define USB_XINPUT_DESCRIPTORS_H + +#if defined(USBCON) + +extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; +extern const u8 USB_ConfigDescriptor[] PROGMEM; +extern const u16 USB_ConfigDescriptorSize PROGMEM; + +#undef USB_VID +#define USB_VID 0x045E + +#undef USB_PID +#define USB_PID 0x028E + +#endif /* if defined(USBCON) */ + +#endif /* ifndef USB_XINPUT_DESCRIPTORS_H */ -- 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/xinput/USB_XInput_Descriptors.cpp | 3 +++ cores/arduino/xinput/USB_XInput_Descriptors.h | 9 +++++++++ 2 files changed, 12 insertions(+) (limited to 'cores/arduino/xinput') diff --git a/cores/arduino/xinput/USB_XInput_Descriptors.cpp b/cores/arduino/xinput/USB_XInput_Descriptors.cpp index c9acd02..af8b573 100644 --- a/cores/arduino/xinput/USB_XInput_Descriptors.cpp +++ b/cores/arduino/xinput/USB_XInput_Descriptors.cpp @@ -204,4 +204,7 @@ const u8 USB_ConfigDescriptor[] = { const u16 USB_ConfigDescriptorSize = sizeof(USB_ConfigDescriptor); +const u8 STRING_SERIAL[] = "Arduino XInput AVR"; +const u8 STRING_SECURITY[] = "Xbox Security Method 3, Version 1.00, \xA9 2005 Microsoft Corporation. All rights reserved."; + #endif /* if defined(USBCON) */ diff --git a/cores/arduino/xinput/USB_XInput_Descriptors.h b/cores/arduino/xinput/USB_XInput_Descriptors.h index e8c3c24..8cb19df 100644 --- a/cores/arduino/xinput/USB_XInput_Descriptors.h +++ b/cores/arduino/xinput/USB_XInput_Descriptors.h @@ -31,10 +31,19 @@ #if defined(USBCON) +// Device Descriptor extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; + +// Config Descriptor extern const u8 USB_ConfigDescriptor[] PROGMEM; extern const u16 USB_ConfigDescriptorSize PROGMEM; +// String Descriptors +extern const u8 STRING_SERIAL[] PROGMEM; +extern const u8 STRING_SECURITY[] PROGMEM; + +#define ISECURITY 4 + #undef USB_VID #define USB_VID 0x045E -- cgit v1.2.3-18-g5258 From 5b5ddcf165f8dfa601abd28af1c73a6fcfedae98 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sun, 17 Feb 2019 22:47:15 -0500 Subject: Modify endpoint numbers to be sequential Easier for the AVR to deal with the memory if the in/out numbers aren't paired. --- cores/arduino/xinput/USB_XInput_Descriptors.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'cores/arduino/xinput') diff --git a/cores/arduino/xinput/USB_XInput_Descriptors.cpp b/cores/arduino/xinput/USB_XInput_Descriptors.cpp index af8b573..ef9b9d8 100644 --- a/cores/arduino/xinput/USB_XInput_Descriptors.cpp +++ b/cores/arduino/xinput/USB_XInput_Descriptors.cpp @@ -75,7 +75,7 @@ const u8 USB_ConfigDescriptor[] = { 0x81, // bEndpointAddress (IN, 1) 0x14, // bMaxDataSize 0x00, 0x00, 0x00, 0x00, 0x13, // ??? - 0x01, // bEndpointAddress (OUT, 1) + 0x02, // bEndpointAddress (OUT, 2) 0x08, // bMaxDataSize 0x00, 0x00, // ??? @@ -90,7 +90,7 @@ const u8 USB_ConfigDescriptor[] = { // Endpoint 1: Control Data In 0x07, // bLength 0x05, // bDescriptorType (ENDPOINT) - 0x01, // bEndpointAddress (OUT, 1) + 0x02, // bEndpointAddress (OUT, 2) 0x03, // bmAttributes 0x20, 0x00, // wMaxPacketSize 0x08, // bInterval @@ -111,23 +111,23 @@ const u8 USB_ConfigDescriptor[] = { 0x1B, // bLength 0x21, // bDescriptorType 0x00, 0x01, 0x01, 0x01, // ??? - 0x82, // bEndpointAddress (IN, 2) + 0x83, // bEndpointAddress (IN, 3) 0x40, // bMaxDataSize 0x01, // ??? - 0x02, // bEndpointAddress (OUT, 2) + 0x04, // bEndpointAddress (OUT, 4) 0x20, // bMaxDataSize 0x16, // ??? - 0x83, // bEndpointAddress (IN, 3) + 0x85, // bEndpointAddress (IN, 5) 0x00, // bMaxDataSize 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, // ??? - 0x03, // bEndpointAddress (OUT, 3) + 0x05, // bEndpointAddress (OUT, 5) 0x00, // bMaxDataSize 0x00, 0x00, 0x00, 0x00, 0x00, // ??? // Endpoint 2: Microphone Data Out 0x07, // bLength 0x05, // bDescriptorType (ENDPOINT) - 0x82, // bEndpointAddress (IN, 2) + 0x83, // bEndpointAddress (IN, 3) 0x03, // bmAttributes 0x20, 0x00, // wMaxPacketSize 0x02, // bInterval @@ -135,7 +135,7 @@ const u8 USB_ConfigDescriptor[] = { // Endpoint 2: Headset Audio In 0x07, // bLength 0x05, // bDescriptorType (ENDPOINT) - 0x02, // bEndpointAddress (OUT, 2) + 0x04, // bEndpointAddress (OUT, 4) 0x03, // bmAttributes 0x20, 0x00, // wMaxPacketSize 0x04, // bInterval @@ -143,7 +143,7 @@ const u8 USB_ConfigDescriptor[] = { // Endpoint 3: Unknown, Out 0x07, // bLength 0x05, // bDescriptorType (ENDPOINT) - 0x83, // bEndpointAddress (IN, 3) + 0x85, // bEndpointAddress (IN, 5) 0x03, // bmAttributes 0x20, 0x00, // wMaxPacketSize 0x40, // bInterval @@ -151,7 +151,7 @@ const u8 USB_ConfigDescriptor[] = { // Endpoint 3: Unknown, In 0x07, // bLength 0x05, // bDescriptorType (ENDPOINT) - 0x03, // bEndpointAddress (OUT, 3) + 0x05, // bEndpointAddress (OUT, 5) 0x03, // bmAttributes 0x20, 0x00, // wMaxPacketSize 0x10, // bInterval @@ -172,14 +172,14 @@ const u8 USB_ConfigDescriptor[] = { 0x09, // bLength 0x21, // bDescriptorType 0x00, 0x01, 0x01, 0x22, // ??? - 0x84, // bEndpointAddress (IN, 4) + 0x86, // bEndpointAddress (IN, 6) 0x07, // bMaxDataSize 0x00, // ??? // Endpoint 4: Unknown, Out 0x07, // bLength 0x05, // bDescriptorType (ENDPOINT) - 0x84, // bEndpointAddress (IN, 4) + 0x86, // bEndpointAddress (IN, 6) 0x03, // bmAttributes 0x20, 0x00, // wMaxPacketSize 0x10, // bInterval -- cgit v1.2.3-18-g5258 From 697a840e1b23a06f595bc2dbd75bcaacb9a1a8ad Mon Sep 17 00:00:00 2001 From: David Madison Date: Tue, 19 Feb 2019 12:41:46 -0500 Subject: Add XInput endpoint number defines --- cores/arduino/xinput/USB_XInput_Descriptors.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cores/arduino/xinput') diff --git a/cores/arduino/xinput/USB_XInput_Descriptors.h b/cores/arduino/xinput/USB_XInput_Descriptors.h index 8cb19df..21697fb 100644 --- a/cores/arduino/xinput/USB_XInput_Descriptors.h +++ b/cores/arduino/xinput/USB_XInput_Descriptors.h @@ -44,6 +44,10 @@ extern const u8 STRING_SECURITY[] PROGMEM; #define ISECURITY 4 +// Endpoint Numbers +#define XINPUT_TX_ENDPOINT 1 +#define XINPUT_RX_ENDPOINT 2 + #undef USB_VID #define USB_VID 0x045E -- cgit v1.2.3-18-g5258 From 058af1724d130745167f670272630ed2811d1317 Mon Sep 17 00:00:00 2001 From: David Madison Date: Tue, 19 Feb 2019 12:50:10 -0500 Subject: Change VID and PID in boards.txt Better to set these where intended so they can be easily overridden if need be. --- cores/arduino/xinput/USB_XInput_Descriptors.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'cores/arduino/xinput') diff --git a/cores/arduino/xinput/USB_XInput_Descriptors.h b/cores/arduino/xinput/USB_XInput_Descriptors.h index 21697fb..976fe56 100644 --- a/cores/arduino/xinput/USB_XInput_Descriptors.h +++ b/cores/arduino/xinput/USB_XInput_Descriptors.h @@ -48,12 +48,6 @@ extern const u8 STRING_SECURITY[] PROGMEM; #define XINPUT_TX_ENDPOINT 1 #define XINPUT_RX_ENDPOINT 2 -#undef USB_VID -#define USB_VID 0x045E - -#undef USB_PID -#define USB_PID 0x028E - #endif /* if defined(USBCON) */ #endif /* ifndef USB_XINPUT_DESCRIPTORS_H */ -- cgit v1.2.3-18-g5258 From a7b370bf9657dccc9038d6611ea289d996b53621 Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 21 Feb 2019 10:55:11 -0500 Subject: Add XInput USB API --- cores/arduino/xinput/USB_XInput_API.cpp | 57 +++++++++++++++++++++++++++++++++ cores/arduino/xinput/USB_XInput_API.h | 51 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 cores/arduino/xinput/USB_XInput_API.cpp create mode 100644 cores/arduino/xinput/USB_XInput_API.h (limited to 'cores/arduino/xinput') diff --git a/cores/arduino/xinput/USB_XInput_API.cpp b/cores/arduino/xinput/USB_XInput_API.cpp new file mode 100644 index 0000000..27a6670 --- /dev/null +++ b/cores/arduino/xinput/USB_XInput_API.cpp @@ -0,0 +1,57 @@ +/* + * Project Arduino XInput - AVR Core + * @author David Madison + * @link github.com/dmadison/ArduinoXInput_AVR + * @license MIT - Copyright (c) 2019 David Madison + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include "USB_XInput_API.h" + +#ifdef USB_XINPUT + +void (*XInputUSB::RecvCallback)(void) = nullptr; + +boolean XInputUSB::connected() { + return true; // Need to implement +} + +int XInputUSB::available() { + return USB_Available(XINPUT_RX_ENDPOINT); +} + +int XInputUSB::recv(void *buffer, uint8_t nbytes) { + return USB_Recv(XINPUT_RX_ENDPOINT, buffer, nbytes); +} + +int XInputUSB::send(const void *buffer, uint8_t nbytes) { + int result = USB_Send(XINPUT_TX_ENDPOINT, buffer, nbytes); + if (result > 0) { + USB_Flush(XINPUT_TX_ENDPOINT); + } + return result; +} + +void XInputUSB::setRecvCallback(void(*callback)(void)) { + XInputUSB::RecvCallback = callback; +} + +#endif /* ifdef USB_XINPUT */ diff --git a/cores/arduino/xinput/USB_XInput_API.h b/cores/arduino/xinput/USB_XInput_API.h new file mode 100644 index 0000000..0a8fa43 --- /dev/null +++ b/cores/arduino/xinput/USB_XInput_API.h @@ -0,0 +1,51 @@ +/* + * Project Arduino XInput - AVR Core + * @author David Madison + * @link github.com/dmadison/ArduinoXInput_AVR + * @license MIT - Copyright (c) 2019 David Madison + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include "USBAPI.h" + +#ifndef USB_XINPUT_API_H +#define USB_XINPUT_API_H + +#ifdef USBCON + +#define USB_XINPUT + +class XInputUSB { +public: + // API + static bool connected(void); + static int available(void); + static int recv(void *buffer, uint8_t nbytes); + static int send(const void *buffer, uint8_t nbytes); + static void setRecvCallback(void(*callback)(void)); + + // Non-API Data + static void (*RecvCallback)(void); +}; + +#endif /* if defined(USBCON) */ + +#endif /* ifndef USB_XINPUT_API_H */ -- cgit v1.2.3-18-g5258 From 1580d392e9662b25161c88681e1e274526109921 Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 21 Feb 2019 15:07:53 -0500 Subject: Add USB connected API support Returns true if the device USB is configured. Although will still return true if the device has been configured and the USB data pins disconnected... --- cores/arduino/xinput/USB_XInput_API.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino/xinput') diff --git a/cores/arduino/xinput/USB_XInput_API.cpp b/cores/arduino/xinput/USB_XInput_API.cpp index 27a6670..678692d 100644 --- a/cores/arduino/xinput/USB_XInput_API.cpp +++ b/cores/arduino/xinput/USB_XInput_API.cpp @@ -31,7 +31,7 @@ void (*XInputUSB::RecvCallback)(void) = nullptr; boolean XInputUSB::connected() { - return true; // Need to implement + return USBDevice.configured(); } int XInputUSB::available() { -- cgit v1.2.3-18-g5258