@@ -39,6 +39,7 @@ static xSemaphoreHandle tinyusb_hid_device_input_sem = NULL;
39
39
static xSemaphoreHandle tinyusb_hid_device_input_mutex = NULL ;
40
40
41
41
static bool tinyusb_hid_is_initialized = false ;
42
+ static hid_interface_protocol_enum_t tinyusb_interface_protocol = HID_ITF_PROTOCOL_NONE;
42
43
static uint8_t tinyusb_loaded_hid_devices_num = 0 ;
43
44
static uint16_t tinyusb_hid_device_descriptor_len = 0 ;
44
45
static uint8_t * tinyusb_hid_device_descriptor = NULL ;
@@ -173,7 +174,7 @@ static bool tinyusb_load_enabled_hid_devices(){
173
174
174
175
esp_hid_report_map_t *hid_report_map = esp_hid_parse_report_map (tinyusb_hid_device_descriptor, tinyusb_hid_device_descriptor_len);
175
176
if (hid_report_map){
176
- log_d (" Loaded HID Desriptor with the following reports:" );
177
+ log_d (" Loaded HID Descriptor with the following reports:" );
177
178
for (uint8_t i=0 ; i<hid_report_map->reports_len ; i++){
178
179
if (hid_report_map->reports [i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT){
179
180
log_d (" ID: %3u, Type: %7s, Size: %2u, Usage: %8s" ,
@@ -201,14 +202,15 @@ extern "C" uint16_t tusb_hid_load_descriptor(uint8_t * dst, uint8_t * itf)
201
202
tinyusb_hid_is_initialized = true ;
202
203
203
204
uint8_t str_index = tinyusb_add_string_descriptor (" TinyUSB HID" );
204
- uint8_t ep_in = tinyusb_get_free_in_endpoint ();
205
+ // For keyboard boot protocol, we've already called tinyusb_enable_interface2(reserve_endpoints=true)
206
+ uint8_t ep_in = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_in_endpoint ();
205
207
TU_VERIFY (ep_in != 0 );
206
- uint8_t ep_out = tinyusb_get_free_out_endpoint ();
208
+ uint8_t ep_out = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_out_endpoint ();
207
209
TU_VERIFY (ep_out != 0 );
208
210
uint8_t descriptor[TUD_HID_INOUT_DESC_LEN] = {
209
211
// HID Input & Output descriptor
210
212
// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
211
- TUD_HID_INOUT_DESCRIPTOR (*itf, str_index, HID_ITF_PROTOCOL_NONE , tinyusb_hid_device_descriptor_len, ep_out, (uint8_t )(0x80 | ep_in), 64 , 1 )
213
+ TUD_HID_INOUT_DESCRIPTOR (*itf, str_index, tinyusb_interface_protocol , tinyusb_hid_device_descriptor_len, ep_out, (uint8_t )(0x80 | ep_in), 64 , 1 )
212
214
};
213
215
*itf+=1 ;
214
216
memcpy (dst, descriptor, TUD_HID_INOUT_DESC_LEN);
@@ -275,14 +277,15 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
275
277
}
276
278
}
277
279
278
- USBHID::USBHID (){
280
+ USBHID::USBHID (hid_interface_protocol_enum_t itf_protocol ){
279
281
if (!tinyusb_hid_devices_is_initialized){
280
282
tinyusb_hid_devices_is_initialized = true ;
281
283
for (uint8_t i=0 ; i<USB_HID_DEVICES_MAX; i++){
282
284
memset (&tinyusb_hid_devices[i], 0 , sizeof (tinyusb_hid_device_t ));
283
285
}
284
286
tinyusb_hid_devices_num = 0 ;
285
- tinyusb_enable_interface (USB_INTERFACE_HID, TUD_HID_INOUT_DESC_LEN, tusb_hid_load_descriptor);
287
+ tinyusb_interface_protocol = itf_protocol;
288
+ tinyusb_enable_interface2 (USB_INTERFACE_HID, TUD_HID_INOUT_DESC_LEN, tusb_hid_load_descriptor, itf_protocol == HID_ITF_PROTOCOL_KEYBOARD);
286
289
}
287
290
}
288
291
@@ -327,11 +330,16 @@ bool USBHID::SendReport(uint8_t id, const void* data, size_t len, uint32_t timeo
327
330
return false ;
328
331
}
329
332
333
+ // If we're configured to support boot protocol, and the host has requested boot protocol, prevent
334
+ // sending of report ID, by passing report ID of 0 to tud_hid_n_report().
335
+ uint8_t effective_id = ((tinyusb_interface_protocol != HID_ITF_PROTOCOL_NONE) &&
336
+ (tud_hid_n_get_protocol (0 ) == HID_PROTOCOL_BOOT)) ? 0 : id;
337
+
330
338
bool res = ready ();
331
339
if (!res){
332
340
log_e (" not ready" );
333
341
} else {
334
- res = tud_hid_n_report (0 , id , data, len);
342
+ res = tud_hid_n_report (0 , effective_id , data, len);
335
343
if (!res){
336
344
log_e (" report %u failed" , id);
337
345
} else {
0 commit comments