Skip to content

[PluggableHID] 3rd round of API improvement (WIP) #3931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hardware/arduino/avr/cores/arduino/PluggableUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ int PluggableUSB_::getInterface(uint8_t* interfaceCount)
return sent;
}

int PluggableUSB_::getDescriptor(int8_t type)
int PluggableUSB_::getDescriptor(USBSetup& setup)
{
PUSBListNode* node;
for (node = rootNode; node; node = node->next) {
int ret = node->getDescriptor(type);
int ret = node->getDescriptor(setup);
// ret!=0 -> request has been processed
if (ret)
return ret;
}
return 0;
}

bool PluggableUSB_::setup(USBSetup& setup, uint8_t interfaceNum)
bool PluggableUSB_::setup(USBSetup& setup)
{
PUSBListNode* node;
for (node = rootNode; node; node = node->next) {
if (node->setup(setup, interfaceNum)) {
if (node->setup(setup)) {
return true;
}
}
Expand Down
19 changes: 8 additions & 11 deletions hardware/arduino/avr/cores/arduino/PluggableUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,20 @@

class PUSBListNode {
public:
PUSBListNode(int8_t numEps, int8_t numIfs, uint8_t *epType) :
PUSBListNode(uint8_t numEps, uint8_t numIfs, uint8_t *epType) :
numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType)
{ }

inline uint8_t interface() const { return pluggedInterface; }
inline int8_t endpoint() const { return pluggedEndpoint; }

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 getDescriptor(int8_t t) = 0;
virtual int getDescriptor(USBSetup& setup) = 0;

uint8_t pluggedInterface;
int8_t pluggedEndpoint;
uint8_t pluggedEndpoint;

const int8_t numEndpoints;
const int8_t numInterfaces;
const uint8_t numEndpoints;
const uint8_t numInterfaces;
const uint8_t *endpointType;

PUSBListNode *next = NULL;
Expand All @@ -56,8 +53,8 @@ class PluggableUSB_ {
PluggableUSB_();
bool plug(PUSBListNode *node);
int getInterface(uint8_t* interfaceCount);
int getDescriptor(int8_t type);
bool setup(USBSetup& setup, uint8_t interfaceNum);
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

private:
uint8_t lastIf;
Expand Down
4 changes: 2 additions & 2 deletions hardware/arduino/avr/cores/arduino/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ bool ClassInterfaceRequest(USBSetup& setup)
return CDC_Setup(setup);

#ifdef PLUGGABLE_USB_ENABLED
return PluggableUSB().setup(setup, i);
return PluggableUSB().setup(setup);
#endif
return false;
}
Expand Down Expand Up @@ -476,7 +476,7 @@ bool SendDescriptor(USBSetup& setup)

InitControl(setup.wLength);
#ifdef PLUGGABLE_USB_ENABLED
ret = PluggableUSB().getDescriptor(t);
ret = PluggableUSB().getDescriptor(setup);
if (ret != 0) {
return (ret > 0 ? true : false);
}
Expand Down
40 changes: 21 additions & 19 deletions hardware/arduino/avr/libraries/HID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,28 @@ int HID_::getInterface(uint8_t* interfaceCount)
{
*interfaceCount += 1; // uses 1
HIDDescriptor hidInterface = {
D_INTERFACE(interface(), 1, 3, 0, 0),
D_INTERFACE(pluggedInterface, 1, 3, 0, 0),
D_HIDREPORT(descriptorSize),
D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
};
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
}

int HID_::getDescriptor(int8_t type)
int HID_::getDescriptor(USBSetup& setup)
{
if (HID_REPORT_DESCRIPTOR_TYPE == type) {
int total = 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;
if (pluggedInterface != setup.wIndex) {
return 0;
}

// Ignored
return 0;
int total = 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)
Expand All @@ -72,13 +71,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)

void HID_::SendReport(uint8_t id, const void* data, int len)
{
USB_Send(endpoint(), &id, 1);
USB_Send(endpoint() | TRANSFER_RELEASE, data, len);
USB_Send(pluggedEndpoint, &id, 1);
USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
}

bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
bool HID_::setup(USBSetup& setup)
{
if (interface() != interfaceNum) {
if (pluggedInterface != setup.wIndex) {
return false;
}

Expand Down Expand Up @@ -107,6 +106,9 @@ bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
idle = setup.wValueL;
return true;
}
if (request == HID_SET_REPORT)
{
}
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions hardware/arduino/avr/libraries/HID/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class HID_ : public PUSBListNode
protected:
// Implementation of the PUSBListNode
int getInterface(uint8_t* interfaceCount);
int getDescriptor(int8_t type);
bool setup(USBSetup& setup, uint8_t interfaceNum);
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

private:
uint8_t epType[1];
Expand Down