Skip to content

Commit c7e79e8

Browse files
committed
Fix HID derived libraries and add automatic setupUSB() weak hook
1 parent ace0f18 commit c7e79e8

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
@@ -1,4 +1,4 @@
1-
#if defined(USBCON)
1+
#if 1
22

33
#include "HID.h"
44
#include "Keyboard.h"
@@ -26,6 +26,39 @@ void Keyboard_::sendReport(KeyReport* keys)
2626
HID_SendReport(2,keys,sizeof(KeyReport));
2727
}
2828

29+
const u8 _hidReportDescriptor[] PROGMEM = {
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+
2962
extern
3063
const uint8_t _asciimap[128] PROGMEM;
3164

@@ -163,6 +196,14 @@ const uint8_t _asciimap[128] =
163196
0 // DEL
164197
};
165198

199+
size_t getsizeof_hidReportDescriptor() {
200+
return sizeof(_hidReportDescriptor);
201+
}
202+
203+
void WEAK setupUSB() {
204+
HID.begin();
205+
}
206+
166207
uint8_t USBPutChar(uint8_t c);
167208

168209
// 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
@@ -1,43 +1,11 @@
1-
#if defined(USBCON)
1+
#if 1
2+
3+
#include "HID.h"
24

35
//================================================================================
46
//================================================================================
57
// Keyboard
68

7-
extern const u8 _hidReportDescriptor[] PROGMEM;
8-
const u8 _hidReportDescriptor[] = {
9-
10-
// Keyboard
11-
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47
12-
0x09, 0x06, // USAGE (Keyboard)
13-
0xa1, 0x01, // COLLECTION (Application)
14-
0x85, 0x02, // REPORT_ID (2)
15-
0x05, 0x07, // USAGE_PAGE (Keyboard)
16-
17-
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
18-
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
19-
0x15, 0x00, // LOGICAL_MINIMUM (0)
20-
0x25, 0x01, // LOGICAL_MAXIMUM (1)
21-
0x75, 0x01, // REPORT_SIZE (1)
22-
23-
0x95, 0x08, // REPORT_COUNT (8)
24-
0x81, 0x02, // INPUT (Data,Var,Abs)
25-
0x95, 0x01, // REPORT_COUNT (1)
26-
0x75, 0x08, // REPORT_SIZE (8)
27-
0x81, 0x03, // INPUT (Cnst,Var,Abs)
28-
29-
0x95, 0x06, // REPORT_COUNT (6)
30-
0x75, 0x08, // REPORT_SIZE (8)
31-
0x15, 0x00, // LOGICAL_MINIMUM (0)
32-
0x25, 0x65, // LOGICAL_MAXIMUM (101)
33-
0x05, 0x07, // USAGE_PAGE (Keyboard)
34-
35-
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
36-
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
37-
0x81, 0x00, // INPUT (Data,Ary,Abs)
38-
0xc0, // END_COLLECTION
39-
};
40-
419
#define KEY_LEFT_CTRL 0x80
4210
#define KEY_LEFT_SHIFT 0x81
4311
#define KEY_LEFT_ALT 0x82

libraries/Mouse/Mouse.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Mouse_ Mouse;
4545
//================================================================================
4646
// Mouse
4747

48+
void WEAK setupUSB() {
49+
HID.begin();
50+
}
51+
4852
Mouse_::Mouse_(void) : _buttons(0)
4953
{
5054
}

0 commit comments

Comments
 (0)