diff options
author | Martino Facchin <m.facchin@arduino.cc> | 2015-07-02 12:12:15 +0200 |
---|---|---|
committer | Cristian Maglie <c.maglie@arduino.cc> | 2015-07-16 13:13:52 +0200 |
commit | 3d61f6e37ef3084627cdeb2b81e1545fe7ef0271 (patch) | |
tree | 43aff6c389d61efe48e4104d9e6890d06b766024 /libraries/HID/HID.cpp | |
parent | b0bdb476942ea105463fd8fdbc076d2b104a7176 (diff) |
allow HID submodules to create runtime descriptors
with this PR you can add
\#include Keyboard.h
\#include Mouse.h
\#include HID.h
in the top of the sketch and you will expose a Mouse+Keyboard
From the library pow, simply add
static HID_Descriptor cb = {
.length = sizeof(_hidReportDescriptor),
.descriptor = _hidReportDescriptor,
};
static HIDDescriptorListNode node(&cb);
HID.AppendDescriptor(&node);
in the class' constructor and you are done!
Diffstat (limited to 'libraries/HID/HID.cpp')
-rw-r--r-- | libraries/HID/HID.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index f18e069..ba379c2 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -44,6 +44,9 @@ static u8 HID_INTERFACE; HIDDescriptor _hidInterface; +static HIDDescriptorListNode* rootNode = NULL; +static uint8_t sizeof_hidReportDescriptor = 0; +static uint8_t modules_count = 0; //================================================================================ //================================================================================ // Driver @@ -54,18 +57,45 @@ u8 _hid_idle = 1; int HID_GetInterface(u8* interfaceNum) { interfaceNum[0] += 1; // uses 1 + _hidInterface = + { + D_INTERFACE(HID_INTERFACE,1,3,0,0), + D_HIDREPORT(sizeof_hidReportDescriptor), + D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) + }; return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); } int HID_GetDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { - return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,getsizeof_hidReportDescriptor()); + HIDDescriptorListNode* current = rootNode; + int total = 0; + while(current != NULL) { + total += USB_SendControl(TRANSFER_PGM,current->cb->descriptor,current->cb->length); + current = current->next; + } + return total; } else { return 0; } } +void HID_::AppendDescriptor(HIDDescriptorListNode *node) +{ + if (modules_count == 0) { + rootNode = node; + } else { + HIDDescriptorListNode *current = rootNode; + while(current->next != NULL) { + current = current->next; + } + current->next = node; + } + modules_count++; + sizeof_hidReportDescriptor += node->cb->length; +} + void HID_::SendReport(u8 id, const void* data, int len) { USB_Send(HID_TX, &id, 1); @@ -129,13 +159,6 @@ HID_::HID_(void) static PUSBListNode node(&cb); HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE); - - _hidInterface = - { - D_INTERFACE(HID_INTERFACE,1,3,0,0), - D_HIDREPORT(getsizeof_hidReportDescriptor()), - D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) - }; } int HID_::begin(void) |