commit 11f93b19cc46f445531145b197bb7ef8cce26cf6
parent 1fd341eb6445264cb3dffec83cfc22192a7a7c4e
Author: Louis Burda <quent.burda@gmail.com>
Date: Wed, 28 Dec 2022 00:37:12 +0100
stash getting hid keyboard proto working
Diffstat:
3 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/src/hid.c b/src/hid.c
@@ -367,7 +367,7 @@ send_keyboard_report(void)
if (memcmp(&keyboard_report, &keyboard_report_prev,
sizeof(keyboard_report))) {
- tud_hid_keyboard_report(REPORT_ID_KEYBOARD,
+ tud_hid_n_keyboard_report(INST_HID_KBD, REPORT_ID_NONE,
keyboard_report.mods, keyboard_report.codes);
memcpy(&keyboard_report_prev, &keyboard_report,
sizeof(keyboard_report));
@@ -431,8 +431,7 @@ send_mouse_report(void)
sent = false;
if (memcmp(&mouse_report, &mouse_report_prev,
sizeof(mouse_report))) {
- tud_hid_mouse_report(REPORT_ID_KEYBOARD,
- mouse_report.btns,
+ tud_hid_mouse_report(REPORT_ID_NONE, mouse_report.btns,
mouse_report.x, mouse_report.y,
mouse_report.h, mouse_report.v);
memcpy(&mouse_report_prev, &mouse_report,
@@ -471,8 +470,6 @@ bool
send_hid_report(int id)
{
switch (id) {
- case REPORT_ID_KEYBOARD:
- return send_keyboard_report();
case REPORT_ID_CONSUMER:
return send_consumer_report();
case REPORT_ID_SYSTEM:
@@ -582,13 +579,13 @@ hid_send_macro(const uint32_t *keysyms, uint cnt)
process_keydown(keysyms[i], mx, my);
}
- while (!tud_hid_ready())
+ while (!tud_hid_n_ready(INST_HID_KBD))
tud_task();
send_next_hid_report(REPORT_ID_MIN);
if (IS_MACRO_PRESS(keysyms[i])) {
memcpy(&keyboard_report, &tmp, sizeof(keyboard_report));
- while (!tud_hid_ready())
+ while (!tud_hid_n_ready(INST_HID_KBD))
tud_task();
send_next_hid_report(REPORT_ID_MIN);
}
@@ -596,7 +593,7 @@ hid_send_macro(const uint32_t *keysyms, uint cnt)
memset(&keyboard_report, 0, sizeof(keyboard_report));
send_next_hid_report(REPORT_ID_MIN);
- while (!tud_hid_ready())
+ while (!tud_hid_n_ready(INST_HID_KBD))
tud_task();
macro_running = false;
@@ -606,7 +603,7 @@ void
hid_task(void)
{
update_report();
- if (tud_hid_ready())
- send_next_hid_report(REPORT_ID_MIN);
+ if (tud_hid_n_ready(INST_HID_KBD))
+ send_keyboard_report();
}
diff --git a/src/hid.h b/src/hid.h
@@ -7,16 +7,23 @@
#define MACRO_HOLD_MAX 32
-#define REPORT_ID_MIN REPORT_ID_KEYBOARD
+#define REPORT_ID_NONE 0
+
+#define REPORT_ID_MIN 1
+
enum {
- REPORT_ID_KEYBOARD = 1,
- REPORT_ID_CONSUMER,
+ REPORT_ID_CONSUMER = REPORT_ID_MIN,
REPORT_ID_SYSTEM,
REPORT_ID_MOUSE,
REPORT_ID_GAMEPAD,
REPORT_ID_MAX
};
+enum {
+ INST_HID_KBD,
+ INST_HID_MISC
+};
+
void hid_init(void);
void hid_force_release(uint x, uint y);
void hid_switch_layer_with_key(uint8_t layer, uint x, uint y);
diff --git a/src/usb_descriptors.c b/src/usb_descriptors.c
@@ -8,11 +8,11 @@
/* same VID/PID with different interface can cause issues! */
-#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
+#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (2 * (n)))
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) \
| _PID_MAP(HID, 2) | _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4))
-#define USB_VID 0xC0FF
+#define USB_VID 0x1523
#define USB_BCD 0x0200
#define CONFIG_TOTAL_LEN \
@@ -27,7 +27,7 @@
enum {
ITF_NUM_CDC,
ITF_NUM_CDC_DATA,
- ITF_NUM_HID,
+ ITF_NUM_HID_KBD,
ITF_NUM_TOTAL
};
@@ -53,8 +53,11 @@ tusb_desc_device_t const desc_device = {
.bNumConfigurations = 0x01
};
-uint8_t const desc_hid_report[] = {
- TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID_KEYBOARD)),
+uint8_t const desc_hid_kbd_report[] = {
+ TUD_HID_REPORT_DESC_KEYBOARD()
+};
+
+uint8_t const desc_hid_misc_report[] = {
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE)),
TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(REPORT_ID_CONSUMER)),
TUD_HID_REPORT_DESC_SYSTEM_CONTROL(HID_REPORT_ID(REPORT_ID_SYSTEM)),
@@ -74,8 +77,8 @@ uint8_t const desc_fs_configuration[] = {
/* Interface number, string index, protocol, report descriptor len,
* EP In address, size & polling interval */
- TUD_HID_DESCRIPTOR(ITF_NUM_HID, 5, HID_ITF_PROTOCOL_NONE,
- sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 1)
+ TUD_HID_DESCRIPTOR(ITF_NUM_HID_KBD, 0, HID_ITF_PROTOCOL_KEYBOARD,
+ sizeof(desc_hid_kbd_report), EPNUM_HID, 8, 1)
};
#if TUD_OPT_HIGH_SPEED
@@ -92,8 +95,8 @@ uint8_t const desc_hs_configuration[] = {
/* Interface number, string index, protocol, report descriptor len,
* EP In address, size & polling interval */
- TUD_HID_DESCRIPTOR(ITF_NUM_HID, 5, HID_ITF_PROTOCOL_NONE,
- sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 1)
+ TUD_HID_DESCRIPTOR(ITF_NUM_HID_KBD, 0, HID_ITF_PROTOCOL_KEYBOARD,
+ sizeof(desc_hid_kbd_report), EPNUM_HID, 8, 1)
};
uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
@@ -115,12 +118,11 @@ tusb_desc_device_qualifier_t const desc_device_qualifier =
#endif
char const *string_desc_arr[] = {
- [0] = "\x09\x04\x09\x00", /* bCountryCode: Germany */
+ [0] = "\x07\x04", /* LangID: German (0x0407) */
[1] = "TinyUSB", /* Manufacturer */
[2] = "TinyUSB Device", /* Product */
[3] = "123456", /* Serials, should use chip ID */
[4] = "SXKBD CDC",
- [5] = "SXKBD HID"
};
static uint16_t _desc_str[32];
@@ -137,7 +139,7 @@ uint8_t const *
tud_hid_descriptor_report_cb(uint8_t itf)
{
(void) itf;
- return desc_hid_report;
+ return desc_hid_kbd_report;
}
/* Invoked on GET CONFIGURATION DESCRIPTOR */
@@ -164,8 +166,8 @@ tud_descriptor_string_cb(uint8_t index, uint16_t langid)
(void) langid;
if (index == 0) {
- memcpy(&_desc_str[1], string_desc_arr[0], 4);
- chr_count = 2;
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
} else {
if (index >= ARRLEN(string_desc_arr))
return NULL;