diff options
Diffstat (limited to 'cores/arduino')
-rw-r--r-- | cores/arduino/PluggableUSB.cpp | 86 | ||||
-rw-r--r-- | cores/arduino/PluggableUSB.h | 55 | ||||
-rw-r--r-- | cores/arduino/USBCore.cpp | 29 | ||||
-rw-r--r-- | cores/arduino/USBCore.h | 2 | ||||
-rw-r--r-- | cores/arduino/USBDesc.h | 2 |
5 files changed, 163 insertions, 11 deletions
diff --git a/cores/arduino/PluggableUSB.cpp b/cores/arduino/PluggableUSB.cpp new file mode 100644 index 0000000..e389c35 --- /dev/null +++ b/cores/arduino/PluggableUSB.cpp @@ -0,0 +1,86 @@ +/* + PluggableUSB.cpp + Copyright (c) 2015 Arduino LLC + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "USBAPI.h" +#include "PluggableUSB.h" + +#if defined(USBCON) +#ifdef PLUGGABLE_USB_ENABLED + +#define MAX_MODULES 6 + +static u8 startIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; +static u8 firstEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; + +static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; +static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; + +extern u8 _initEndpoints[]; + +PUSBCallbacks cbs[MAX_MODULES]; +u8 modules_count = 0; + +int PUSB_GetInterface(u8* interfaceNum) +{ + int ret = 0; + for (u8 i=0; i<modules_count; i++) { + ret = cbs[i].getInterface(interfaceNum); + } + return ret; +} + +int PUSB_GetDescriptor(int t) +{ + int ret = 0; + for (u8 i=0; i<modules_count && ret == 0; i++) { + ret = cbs[i].getDescriptor(t); + } + return ret; +} + +bool PUSB_Setup(Setup& setup, u8 j) +{ + bool ret = false; + for (u8 i=0; i<modules_count && ret == false; i++) { + ret = cbs[i].setup(setup, j); + } + return ret; +} + +int PUSB_AddFunction(PUSBCallbacks *cb, u8* interface) +{ + if (modules_count >= MAX_MODULES) { + return 0; + } + cbs[modules_count] = *cb; + + *interface = lastIf; + lastIf++; + for ( u8 i = 0; i< cb->numEndpoints; i++) { + _initEndpoints[lastEp] = cb->endpointType[i]; + lastEp++; + } + modules_count++; + return lastEp-1; + // restart USB layer??? +} + +#endif + +#endif /* if defined(USBCON) */
\ No newline at end of file diff --git a/cores/arduino/PluggableUSB.h b/cores/arduino/PluggableUSB.h new file mode 100644 index 0000000..7b3722c --- /dev/null +++ b/cores/arduino/PluggableUSB.h @@ -0,0 +1,55 @@ +/* + PluggableUSB.h + Copyright (c) 2015 Arduino LLC + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef PUSB_h +#define PUSB_h + +#include "USBAPI.h" +#include <stdint.h> + +#if defined(USBCON) + +typedef struct +{ + bool (*setup)(Setup& setup, u8 i); + int (*getInterface)(u8* interfaceNum); + int (*getDescriptor)(int t); + int numEndpoints; + u8 endpointType[6]; +} PUSBCallbacks; + +typedef struct +{ + u8 interface; + u8 firstEndpoint; +} PUSBReturn; + +int PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface); + +int PUSB_GetInterface(u8* interfaceNum); + +int PUSB_GetDescriptor(int t); + +bool PUSB_Setup(Setup& setup, u8 i); + +void PUSB_Begin(); + +#endif + +#endif diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index a866d95..16e4a05 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -17,6 +17,7 @@ */ #include "USBAPI.h" +#include "PluggableUSB.h" #if defined(USBCON) @@ -323,8 +324,14 @@ u8 _initEndpoints[] = EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN #endif -#ifdef HID_ENABLED - EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT +#ifdef PLUGGABLE_USB_ENABLED + //allocate 6 endpoints and remove const so they can be changed by the user + 0, + 0, + 0, + 0, + 0, + 0, #endif }; @@ -365,9 +372,8 @@ bool ClassInterfaceRequest(Setup& setup) return CDC_Setup(setup); #endif -#ifdef HID_ENABLED - if (HID_INTERFACE == i) - return HID_Setup(setup); +#ifdef PLUGGABLE_USB_ENABLED + return PUSB_Setup(setup, i); #endif return false; } @@ -447,8 +453,8 @@ int SendInterfaces() total = CDC_GetInterface(&interfaces); #endif -#ifdef HID_ENABLED - total += HID_GetInterface(&interfaces); +#ifdef PLUGGABLE_USB_ENABLED + PUSB_GetInterface(&interfaces); #endif return interfaces; @@ -477,14 +483,17 @@ u8 _cdcComposite = 0; static bool SendDescriptor(Setup& setup) { + int ret; u8 t = setup.wValueH; if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t) return SendConfiguration(setup.wLength); InitControl(setup.wLength); -#ifdef HID_ENABLED - if (HID_REPORT_DESCRIPTOR_TYPE == t) - return HID_GetDescriptor(t); +#ifdef PLUGGABLE_USB_ENABLED + ret = PUSB_GetDescriptor(t); + if (ret != 0) { + return (ret > 0 ? true : false); + } #endif const u8* desc_addr = 0; diff --git a/cores/arduino/USBCore.h b/cores/arduino/USBCore.h index bee5a3e..cd2191c 100644 --- a/cores/arduino/USBCore.h +++ b/cores/arduino/USBCore.h @@ -18,6 +18,8 @@ #ifndef __USBCORE_H__ #define __USBCORE_H__ +#include "USBAPI.h" + // Standard requests #define GET_STATUS 0 #define CLEAR_FEATURE 1 diff --git a/cores/arduino/USBDesc.h b/cores/arduino/USBDesc.h index b3defa5..3a98f9d 100644 --- a/cores/arduino/USBDesc.h +++ b/cores/arduino/USBDesc.h @@ -17,7 +17,7 @@ */ #define CDC_ENABLED -#define HID_ENABLED +#define PLUGGABLE_USB_ENABLED #ifdef CDC_ENABLED |