Skip to content

Commit d1a9181

Browse files
facchinmcmaglie
authored andcommitted
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!
1 parent 85d2448 commit d1a9181

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

Keyboard.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,13 @@
2121

2222
#if 1
2323

24-
#include "HID.h"
2524
#include "Keyboard.h"
2625

2726
//================================================================================
2827
//================================================================================
2928
// Keyboard
3029

31-
Keyboard_ Keyboard;
32-
33-
Keyboard_::Keyboard_(void)
34-
{
35-
}
36-
37-
void Keyboard_::begin(void)
38-
{
39-
}
40-
41-
void Keyboard_::end(void)
42-
{
43-
}
44-
45-
void Keyboard_::sendReport(KeyReport* keys)
46-
{
47-
HID.SendReport(2,keys,sizeof(KeyReport));
48-
}
49-
50-
const u8 _hidReportDescriptor[] PROGMEM = {
30+
static const u8 _hidReportDescriptor[] PROGMEM = {
5131

5232
// Keyboard
5333
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47
@@ -80,6 +60,29 @@ const u8 _hidReportDescriptor[] PROGMEM = {
8060
0xc0, // END_COLLECTION
8161
};
8262

63+
Keyboard_::Keyboard_(void)
64+
{
65+
static HID_Descriptor cb = {
66+
.length = sizeof(_hidReportDescriptor),
67+
.descriptor = _hidReportDescriptor,
68+
};
69+
static HIDDescriptorListNode node(&cb);
70+
HID.AppendDescriptor(&node);
71+
}
72+
73+
void Keyboard_::begin(void)
74+
{
75+
}
76+
77+
void Keyboard_::end(void)
78+
{
79+
}
80+
81+
void Keyboard_::sendReport(KeyReport* keys)
82+
{
83+
HID.SendReport(2,keys,sizeof(KeyReport));
84+
}
85+
8386
extern
8487
const uint8_t _asciimap[128] PROGMEM;
8588

@@ -217,9 +220,6 @@ const uint8_t _asciimap[128] =
217220
0 // DEL
218221
};
219222

220-
size_t getsizeof_hidReportDescriptor() {
221-
return sizeof(_hidReportDescriptor);
222-
}
223223

224224
uint8_t USBPutChar(uint8_t c);
225225

Keyboard.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#ifndef KEYBOARD_h
2323
#define KEYBOARD_h
2424

25-
#if defined(_USING_HID)
25+
#if 0 //defined(_USING_HID)
2626

2727
#error "Can only attach one submodule to HID module"
2828

@@ -90,10 +90,10 @@ class Keyboard_ : public Print
9090
Keyboard_(void);
9191
void begin(void);
9292
void end(void);
93-
virtual size_t write(uint8_t k);
94-
virtual size_t press(uint8_t k);
95-
virtual size_t release(uint8_t k);
96-
virtual void releaseAll(void);
93+
size_t write(uint8_t k);
94+
size_t press(uint8_t k);
95+
size_t release(uint8_t k);
96+
void releaseAll(void);
9797
};
9898
extern Keyboard_ Keyboard;
9999
extern HID_ HID;

0 commit comments

Comments
 (0)