mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
[PUSB] Made getDescriptor() and setup() more flexible
Alternatively we can only pass the wIndex to getDescriptor but I suggest to just pass the pointer aka reference of the whole setup. In guess (havent tested this) that this results in more or less the code size but its a) idential with the other functions and b) we late have more flexibility here. The Code got a quick SerialKeyboard.ino test
This commit is contained in:
parent
6151972b74
commit
0f9f63f2a5
@ -38,11 +38,11 @@ int PluggableUSB_::getInterface(uint8_t* interfaceCount)
|
|||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PluggableUSB_::getDescriptor(int8_t type)
|
int PluggableUSB_::getDescriptor(USBSetup& setup)
|
||||||
{
|
{
|
||||||
PUSBListNode* node;
|
PUSBListNode* node;
|
||||||
for (node = rootNode; node; node = node->next) {
|
for (node = rootNode; node; node = node->next) {
|
||||||
int ret = node->getDescriptor(type);
|
int ret = node->getDescriptor(setup);
|
||||||
// ret!=0 -> request has been processed
|
// ret!=0 -> request has been processed
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
@ -50,11 +50,11 @@ int PluggableUSB_::getDescriptor(int8_t type)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluggableUSB_::setup(USBSetup& setup, uint8_t interfaceNum)
|
bool PluggableUSB_::setup(USBSetup& setup)
|
||||||
{
|
{
|
||||||
PUSBListNode* node;
|
PUSBListNode* node;
|
||||||
for (node = rootNode; node; node = node->next) {
|
for (node = rootNode; node; node = node->next) {
|
||||||
if (node->setup(setup, interfaceNum)) {
|
if (node->setup(setup)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ public:
|
|||||||
inline uint8_t endpoint() const { return pluggedEndpoint; }
|
inline uint8_t endpoint() const { return pluggedEndpoint; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool setup(USBSetup& setup, uint8_t interfaceNum) = 0;
|
virtual bool setup(USBSetup& setup) = 0;
|
||||||
virtual int getInterface(uint8_t* interfaceCount) = 0;
|
virtual int getInterface(uint8_t* interfaceCount) = 0;
|
||||||
virtual int getDescriptor(int8_t t) = 0;
|
virtual int getDescriptor(USBSetup& setup) = 0;
|
||||||
|
|
||||||
uint8_t pluggedInterface;
|
uint8_t pluggedInterface;
|
||||||
uint8_t pluggedEndpoint;
|
uint8_t pluggedEndpoint;
|
||||||
@ -56,8 +56,8 @@ public:
|
|||||||
PluggableUSB_();
|
PluggableUSB_();
|
||||||
bool plug(PUSBListNode *node);
|
bool plug(PUSBListNode *node);
|
||||||
int getInterface(uint8_t* interfaceCount);
|
int getInterface(uint8_t* interfaceCount);
|
||||||
int getDescriptor(int8_t type);
|
int getDescriptor(USBSetup& setup);
|
||||||
bool setup(USBSetup& setup, uint8_t interfaceNum);
|
bool setup(USBSetup& setup);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t lastIf;
|
uint8_t lastIf;
|
||||||
|
@ -362,7 +362,7 @@ bool ClassInterfaceRequest(USBSetup& setup)
|
|||||||
return CDC_Setup(setup);
|
return CDC_Setup(setup);
|
||||||
|
|
||||||
#ifdef PLUGGABLE_USB_ENABLED
|
#ifdef PLUGGABLE_USB_ENABLED
|
||||||
return PluggableUSB().setup(setup, i);
|
return PluggableUSB().setup(setup);
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ bool SendDescriptor(USBSetup& setup)
|
|||||||
|
|
||||||
InitControl(setup.wLength);
|
InitControl(setup.wLength);
|
||||||
#ifdef PLUGGABLE_USB_ENABLED
|
#ifdef PLUGGABLE_USB_ENABLED
|
||||||
ret = PluggableUSB().getDescriptor(t);
|
ret = PluggableUSB().getDescriptor(setup);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return (ret > 0 ? true : false);
|
return (ret > 0 ? true : false);
|
||||||
}
|
}
|
||||||
|
@ -38,22 +38,21 @@ int HID_::getInterface(uint8_t* interfaceCount)
|
|||||||
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
|
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
|
||||||
}
|
}
|
||||||
|
|
||||||
int HID_::getDescriptor(int8_t type)
|
int HID_::getDescriptor(USBSetup& setup)
|
||||||
{
|
{
|
||||||
if (HID_REPORT_DESCRIPTOR_TYPE == type) {
|
if (interface() != setup.wIndex) {
|
||||||
int total = 0;
|
return 0;
|
||||||
HIDDescriptorListNode* node;
|
|
||||||
for (node = rootNode; node; node = node->next) {
|
|
||||||
int res = USB_SendControl(TRANSFER_PGM, node->data, node->length);
|
|
||||||
if (res == -1)
|
|
||||||
return -1;
|
|
||||||
total += res;
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignored
|
int total = 0;
|
||||||
return 0;
|
HIDDescriptorListNode* node;
|
||||||
|
for (node = rootNode; node; node = node->next) {
|
||||||
|
int res = USB_SendControl(TRANSFER_PGM, node->data, node->length);
|
||||||
|
if (res == -1)
|
||||||
|
return -1;
|
||||||
|
total += res;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
|
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
|
||||||
@ -76,9 +75,9 @@ void HID_::SendReport(uint8_t id, const void* data, int len)
|
|||||||
USB_Send(endpoint() | TRANSFER_RELEASE, data, len);
|
USB_Send(endpoint() | TRANSFER_RELEASE, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
|
bool HID_::setup(USBSetup& setup)
|
||||||
{
|
{
|
||||||
if (interface() != interfaceNum) {
|
if (interface() != setup.wIndex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
// Implementation of the PUSBListNode
|
// Implementation of the PUSBListNode
|
||||||
int getInterface(uint8_t* interfaceCount);
|
int getInterface(uint8_t* interfaceCount);
|
||||||
int getDescriptor(int8_t type);
|
int getDescriptor(USBSetup& setup);
|
||||||
bool setup(USBSetup& setup, uint8_t interfaceNum);
|
bool setup(USBSetup& setup);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t epType[1];
|
uint8_t epType[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user