-
-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathTUCompositeHID.cpp
More file actions
32 lines (25 loc) · 896 Bytes
/
TUCompositeHID.cpp
File metadata and controls
32 lines (25 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "TUCompositeHID.hpp"
#include <Adafruit_TinyUSB.h>
#define HID_DESCRIPTOR_BUFSIZE 1024U
namespace TUCompositeHID {
uint8_t _hid_report_desc[HID_DESCRIPTOR_BUFSIZE] = {};
size_t _current_descriptor_len = 0;
Adafruit_USBD_HID _usb_hid = Adafruit_USBD_HID(
_hid_report_desc,
_current_descriptor_len,
HID_ITF_PROTOCOL_NONE,
1,
false
);
bool addDescriptor(const uint8_t *descriptor, size_t descriptor_len) {
if (_current_descriptor_len + descriptor_len > HID_DESCRIPTOR_BUFSIZE) {
return false;
}
for (size_t i = 0; i < descriptor_len; i++) {
_hid_report_desc[_current_descriptor_len + i] = descriptor[i];
}
_current_descriptor_len += descriptor_len;
_usb_hid.setReportDescriptor(_hid_report_desc, _current_descriptor_len);
return true;
}
}