From 3d61f6e37ef3084627cdeb2b81e1545fe7ef0271 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 2 Jul 2015 12:12:15 +0200 Subject: 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! --- libraries/HID/HID.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'libraries/HID/HID.h') diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index d3a9982..c7608eb 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -42,16 +42,27 @@ #define HID_REPORT_DESCRIPTOR_TYPE 0x22 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 +typedef struct __attribute__((packed)) { + u8 length; + const void* descriptor; +} HID_Descriptor; + +class HIDDescriptorListNode { +public: + HIDDescriptorListNode *next = NULL; + const HID_Descriptor * cb; + HIDDescriptorListNode(const HID_Descriptor *ncb) {cb = ncb;} +}; + class HID_ { public: HID_(void); int begin(void); void SendReport(uint8_t id, const void* data, int len); + void AppendDescriptor(HIDDescriptorListNode* node); }; -extern HID_ HID; - typedef struct { u8 len; // 9 @@ -77,11 +88,6 @@ typedef struct #define D_HIDREPORT(_descriptorLength) \ { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } -extern const u8 _hidReportDescriptor[] PROGMEM; - -// MUST be declared by the module -size_t getsizeof_hidReportDescriptor(); - #define WEAK __attribute__ ((weak)) #endif -- cgit v1.2.3-18-g5258