mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
[PUSB] Selected interface and endpoint are now part of PUSBListNode
The method int8_t PluggableUSB::addFunction(PUSBListNode *, uint8_t *) has been changed to bool PluggableUSB::plug(PUSBListNode *node) since both EP and Interfaces are now saved directly into node
This commit is contained in:
parent
5e14b1fe37
commit
8f259c8a80
@ -68,10 +68,10 @@ bool PluggableUSB_::setup(USBSetup& setup, u8 j)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int8_t PluggableUSB_::addFunction(PUSBListNode *node, u8* interface)
|
||||
bool PluggableUSB_::plug(PUSBListNode *node)
|
||||
{
|
||||
if (modules_count >= MAX_MODULES) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (modules_count == 0) {
|
||||
@ -84,14 +84,15 @@ int8_t PluggableUSB_::addFunction(PUSBListNode *node, u8* interface)
|
||||
current->next = node;
|
||||
}
|
||||
|
||||
*interface = lastIf;
|
||||
node->pluggedInterface = lastIf;
|
||||
node->pluggedEndpoint = lastEp;
|
||||
lastIf += node->numInterfaces;
|
||||
for ( u8 i = 0; i< node->numEndpoints; i++) {
|
||||
for (uint8_t i=0; i<node->numEndpoints; i++) {
|
||||
_initEndpoints[lastEp] = node->endpointType[i];
|
||||
lastEp++;
|
||||
}
|
||||
modules_count++;
|
||||
return lastEp - node->numEndpoints;
|
||||
return true;
|
||||
// restart USB layer???
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,22 @@ public:
|
||||
int8_t numInterfaces;
|
||||
uint8_t *endpointType;
|
||||
|
||||
inline uint8_t interface() const { return pluggedInterface; }
|
||||
inline int8_t endpoint() const { return pluggedEndpoint; }
|
||||
|
||||
protected:
|
||||
uint8_t pluggedInterface;
|
||||
int8_t pluggedEndpoint;
|
||||
|
||||
public:
|
||||
PUSBListNode *next = NULL;
|
||||
|
||||
friend class PluggableUSB_;
|
||||
};
|
||||
|
||||
class PluggableUSB_ {
|
||||
public:
|
||||
static int8_t addFunction(PUSBListNode *node, u8 *interface);
|
||||
static bool plug(PUSBListNode *node);
|
||||
static int getInterface(u8* interfaceNum);
|
||||
static int getDescriptor(int8_t t);
|
||||
static bool setup(USBSetup& setup, u8 i);
|
||||
|
@ -23,14 +23,10 @@
|
||||
|
||||
HID_ HID;
|
||||
|
||||
static uint8_t HID_ENDPOINT_INT;
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// HID Interface
|
||||
|
||||
static uint8_t HID_INTERFACE;
|
||||
|
||||
HIDDescriptor _hidInterface;
|
||||
|
||||
static HIDDescriptorListNode* rootNode = NULL;
|
||||
@ -50,9 +46,9 @@ int HID_GetInterface(uint8_t* interfaceNum)
|
||||
interfaceNum[0] += 1; // uses 1
|
||||
_hidInterface =
|
||||
{
|
||||
D_INTERFACE(HID_INTERFACE,1,3,0,0),
|
||||
D_INTERFACE(HID.interface(), 1, 3, 0, 0),
|
||||
D_HIDREPORT(sizeof_hidReportDescriptor),
|
||||
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,USB_EP_SIZE,0x01)
|
||||
D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
|
||||
};
|
||||
return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface));
|
||||
}
|
||||
@ -89,13 +85,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)
|
||||
|
||||
void HID_::SendReport(u8 id, const void* data, int len)
|
||||
{
|
||||
USB_Send(HID_TX, &id, 1);
|
||||
USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
|
||||
USB_Send(HID.endpoint(), &id, 1);
|
||||
USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len);
|
||||
}
|
||||
|
||||
bool HID_Setup(USBSetup& setup, uint8_t i)
|
||||
{
|
||||
if (HID_INTERFACE != i) {
|
||||
if (HID.interface() != i) {
|
||||
return false;
|
||||
} else {
|
||||
uint8_t r = setup.bRequest;
|
||||
@ -141,7 +137,7 @@ HID_::HID_(void)
|
||||
numInterfaces = 1;
|
||||
endpointType = epType;
|
||||
|
||||
HID_ENDPOINT_INT = PluggableUSB.addFunction(this, &HID_INTERFACE);
|
||||
PluggableUSB.plug(this);
|
||||
}
|
||||
|
||||
int HID_::begin(void)
|
||||
|
@ -83,8 +83,6 @@ typedef struct
|
||||
EndpointDescriptor in;
|
||||
} HIDDescriptor;
|
||||
|
||||
#define HID_TX HID_ENDPOINT_INT
|
||||
|
||||
#define D_HIDREPORT(_descriptorLength) \
|
||||
{ 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength & 0xFF, _descriptorLength >> 8 }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user