Skip to content

Commit 344896e

Browse files
facchinmcmaglie
authored andcommitted
Fix HID derived libraries and add automatic setupUSB() weak hook
1 parent feaa14f commit 344896e

File tree

5 files changed

+563
-114
lines changed

5 files changed

+563
-114
lines changed

libraries/Keyboard/Keyboard.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
*/
2121

22-
#if defined(USBCON)
22+
#if 1
2323

2424
#include "HID.h"
2525
#include "Keyboard.h"
@@ -47,6 +47,39 @@ void Keyboard_::sendReport(KeyReport* keys)
4747
HID_SendReport(2,keys,sizeof(KeyReport));
4848
}
4949

50+
const u8 _hidReportDescriptor[] PROGMEM = {
51+
52+
// Keyboard
53+
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47
54+
0x09, 0x06, // USAGE (Keyboard)
55+
0xa1, 0x01, // COLLECTION (Application)
56+
0x85, 0x02, // REPORT_ID (2)
57+
0x05, 0x07, // USAGE_PAGE (Keyboard)
58+
59+
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
60+
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
61+
0x15, 0x00, // LOGICAL_MINIMUM (0)
62+
0x25, 0x01, // LOGICAL_MAXIMUM (1)
63+
0x75, 0x01, // REPORT_SIZE (1)
64+
65+
0x95, 0x08, // REPORT_COUNT (8)
66+
0x81, 0x02, // INPUT (Data,Var,Abs)
67+
0x95, 0x01, // REPORT_COUNT (1)
68+
0x75, 0x08, // REPORT_SIZE (8)
69+
0x81, 0x03, // INPUT (Cnst,Var,Abs)
70+
71+
0x95, 0x06, // REPORT_COUNT (6)
72+
0x75, 0x08, // REPORT_SIZE (8)
73+
0x15, 0x00, // LOGICAL_MINIMUM (0)
74+
0x25, 0x65, // LOGICAL_MAXIMUM (101)
75+
0x05, 0x07, // USAGE_PAGE (Keyboard)
76+
77+
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
78+
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
79+
0x81, 0x00, // INPUT (Data,Ary,Abs)
80+
0xc0, // END_COLLECTION
81+
};
82+
5083
extern
5184
const uint8_t _asciimap[128] PROGMEM;
5285

@@ -184,6 +217,14 @@ const uint8_t _asciimap[128] =
184217
0 // DEL
185218
};
186219

220+
size_t getsizeof_hidReportDescriptor() {
221+
return sizeof(_hidReportDescriptor);
222+
}
223+
224+
void WEAK setupUSB() {
225+
HID.begin();
226+
}
227+
187228
uint8_t USBPutChar(uint8_t c);
188229

189230
// press() adds the specified key (printing, non-printing, or modifier)

libraries/Keyboard/Keyboard.h

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,14 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
*/
2121

22-
#if defined(USBCON)
22+
#if 1
23+
24+
#include "HID.h"
2325

2426
//================================================================================
2527
//================================================================================
2628
// Keyboard
2729

28-
extern const u8 _hidReportDescriptor[] PROGMEM;
29-
const u8 _hidReportDescriptor[] = {
30-
31-
// Keyboard
32-
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47
33-
0x09, 0x06, // USAGE (Keyboard)
34-
0xa1, 0x01, // COLLECTION (Application)
35-
0x85, 0x02, // REPORT_ID (2)
36-
0x05, 0x07, // USAGE_PAGE (Keyboard)
37-
38-
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
39-
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
40-
0x15, 0x00, // LOGICAL_MINIMUM (0)
41-
0x25, 0x01, // LOGICAL_MAXIMUM (1)
42-
0x75, 0x01, // REPORT_SIZE (1)
43-
44-
0x95, 0x08, // REPORT_COUNT (8)
45-
0x81, 0x02, // INPUT (Data,Var,Abs)
46-
0x95, 0x01, // REPORT_COUNT (1)
47-
0x75, 0x08, // REPORT_SIZE (8)
48-
0x81, 0x03, // INPUT (Cnst,Var,Abs)
49-
50-
0x95, 0x06, // REPORT_COUNT (6)
51-
0x75, 0x08, // REPORT_SIZE (8)
52-
0x15, 0x00, // LOGICAL_MINIMUM (0)
53-
0x25, 0x65, // LOGICAL_MAXIMUM (101)
54-
0x05, 0x07, // USAGE_PAGE (Keyboard)
55-
56-
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
57-
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
58-
0x81, 0x00, // INPUT (Data,Ary,Abs)
59-
0xc0, // END_COLLECTION
60-
};
61-
6230
#define KEY_LEFT_CTRL 0x80
6331
#define KEY_LEFT_SHIFT 0x81
6432
#define KEY_LEFT_ALT 0x82

libraries/Mouse/Mouse.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ Mouse_ Mouse;
6666
//================================================================================
6767
// Mouse
6868

69+
void WEAK setupUSB() {
70+
HID.begin();
71+
}
72+
6973
Mouse_::Mouse_(void) : _buttons(0)
7074
{
7175
}

0 commit comments

Comments
 (0)