mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
add PluggableUSB module
This commit is contained in:
parent
1f534eac35
commit
1aec25b855
86
hardware/arduino/avr/cores/arduino/PluggableUSB.cpp
Normal file
86
hardware/arduino/avr/cores/arduino/PluggableUSB.cpp
Normal file
@ -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) */
|
55
hardware/arduino/avr/cores/arduino/PluggableUSB.h
Normal file
55
hardware/arduino/avr/cores/arduino/PluggableUSB.h
Normal file
@ -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
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "USBAPI.h"
|
#include "USBAPI.h"
|
||||||
|
#include "PluggableUSB.h"
|
||||||
|
|
||||||
#if defined(USBCON)
|
#if defined(USBCON)
|
||||||
|
|
||||||
@ -323,8 +324,14 @@ u8 _initEndpoints[] =
|
|||||||
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
|
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HID_ENABLED
|
#ifdef PLUGGABLE_USB_ENABLED
|
||||||
EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT
|
//allocate 6 endpoints and remove const so they can be changed by the user
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -365,9 +372,8 @@ bool ClassInterfaceRequest(Setup& setup)
|
|||||||
return CDC_Setup(setup);
|
return CDC_Setup(setup);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HID_ENABLED
|
#ifdef PLUGGABLE_USB_ENABLED
|
||||||
if (HID_INTERFACE == i)
|
return PUSB_Setup(setup, i);
|
||||||
return HID_Setup(setup);
|
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -447,8 +453,8 @@ int SendInterfaces()
|
|||||||
total = CDC_GetInterface(&interfaces);
|
total = CDC_GetInterface(&interfaces);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HID_ENABLED
|
#ifdef PLUGGABLE_USB_ENABLED
|
||||||
total += HID_GetInterface(&interfaces);
|
PUSB_GetInterface(&interfaces);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return interfaces;
|
return interfaces;
|
||||||
@ -477,14 +483,17 @@ u8 _cdcComposite = 0;
|
|||||||
static
|
static
|
||||||
bool SendDescriptor(Setup& setup)
|
bool SendDescriptor(Setup& setup)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
u8 t = setup.wValueH;
|
u8 t = setup.wValueH;
|
||||||
if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
|
if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
|
||||||
return SendConfiguration(setup.wLength);
|
return SendConfiguration(setup.wLength);
|
||||||
|
|
||||||
InitControl(setup.wLength);
|
InitControl(setup.wLength);
|
||||||
#ifdef HID_ENABLED
|
#ifdef PLUGGABLE_USB_ENABLED
|
||||||
if (HID_REPORT_DESCRIPTOR_TYPE == t)
|
ret = PUSB_GetDescriptor(t);
|
||||||
return HID_GetDescriptor(t);
|
if (ret != 0) {
|
||||||
|
return (ret > 0 ? true : false);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const u8* desc_addr = 0;
|
const u8* desc_addr = 0;
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#ifndef __USBCORE_H__
|
#ifndef __USBCORE_H__
|
||||||
#define __USBCORE_H__
|
#define __USBCORE_H__
|
||||||
|
|
||||||
|
#include "USBAPI.h"
|
||||||
|
|
||||||
// Standard requests
|
// Standard requests
|
||||||
#define GET_STATUS 0
|
#define GET_STATUS 0
|
||||||
#define CLEAR_FEATURE 1
|
#define CLEAR_FEATURE 1
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define CDC_ENABLED
|
#define CDC_ENABLED
|
||||||
#define HID_ENABLED
|
#define PLUGGABLE_USB_ENABLED
|
||||||
|
|
||||||
|
|
||||||
#ifdef CDC_ENABLED
|
#ifdef CDC_ENABLED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user