@@ -40,6 +40,7 @@ static SemaphoreHandle_t tinyusb_hid_device_input_sem = NULL;
40
40
static SemaphoreHandle_t tinyusb_hid_device_input_mutex = NULL ;
41
41
42
42
static bool tinyusb_hid_is_initialized = false ;
43
+ static hid_interface_protocol_enum_t tinyusb_interface_protocol = HID_ITF_PROTOCOL_NONE;
43
44
static uint8_t tinyusb_loaded_hid_devices_num = 0 ;
44
45
static uint16_t tinyusb_hid_device_descriptor_len = 0 ;
45
46
static uint8_t * tinyusb_hid_device_descriptor = NULL ;
@@ -174,7 +175,7 @@ static bool tinyusb_load_enabled_hid_devices(){
174
175
175
176
esp_hid_report_map_t *hid_report_map = esp_hid_parse_report_map (tinyusb_hid_device_descriptor, tinyusb_hid_device_descriptor_len);
176
177
if (hid_report_map){
177
- log_d (" Loaded HID Desriptor with the following reports:" );
178
+ log_d (" Loaded HID Descriptor with the following reports:" );
178
179
for (uint8_t i=0 ; i<hid_report_map->reports_len ; i++){
179
180
if (hid_report_map->reports [i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT){
180
181
log_d (" ID: %3u, Type: %7s, Size: %2u, Usage: %8s" ,
@@ -202,14 +203,15 @@ extern "C" uint16_t tusb_hid_load_descriptor(uint8_t * dst, uint8_t * itf)
202
203
tinyusb_hid_is_initialized = true ;
203
204
204
205
uint8_t str_index = tinyusb_add_string_descriptor (" TinyUSB HID" );
205
- uint8_t ep_in = tinyusb_get_free_in_endpoint ();
206
+ // For keyboard boot protocol, we've already called tinyusb_enable_interface2(reserve_endpoints=true)
207
+ uint8_t ep_in = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_in_endpoint ();
206
208
TU_VERIFY (ep_in != 0 );
207
- uint8_t ep_out = tinyusb_get_free_out_endpoint ();
209
+ uint8_t ep_out = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_out_endpoint ();
208
210
TU_VERIFY (ep_out != 0 );
209
211
uint8_t descriptor[TUD_HID_INOUT_DESC_LEN] = {
210
212
// HID Input & Output descriptor
211
213
// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
212
- 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 )
214
+ TUD_HID_INOUT_DESCRIPTOR (*itf, str_index, tinyusb_interface_protocol , tinyusb_hid_device_descriptor_len, ep_out, (uint8_t )(0x80 | ep_in), 64 , 1 )
213
215
};
214
216
*itf+=1 ;
215
217
memcpy (dst, descriptor, TUD_HID_INOUT_DESC_LEN);
@@ -276,14 +278,15 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
276
278
}
277
279
}
278
280
279
- USBHID::USBHID (){
281
+ USBHID::USBHID (hid_interface_protocol_enum_t itf_protocol ){
280
282
if (!tinyusb_hid_devices_is_initialized){
281
283
tinyusb_hid_devices_is_initialized = true ;
282
284
for (uint8_t i=0 ; i<USB_HID_DEVICES_MAX; i++){
283
285
memset (&tinyusb_hid_devices[i], 0 , sizeof (tinyusb_hid_device_t ));
284
286
}
285
287
tinyusb_hid_devices_num = 0 ;
286
- tinyusb_enable_interface (USB_INTERFACE_HID, TUD_HID_INOUT_DESC_LEN, tusb_hid_load_descriptor);
288
+ tinyusb_interface_protocol = itf_protocol;
289
+ tinyusb_enable_interface2 (USB_INTERFACE_HID, TUD_HID_INOUT_DESC_LEN, tusb_hid_load_descriptor, itf_protocol == HID_ITF_PROTOCOL_KEYBOARD);
287
290
}
288
291
}
289
292
@@ -342,6 +345,11 @@ bool USBHID::SendReport(uint8_t id, const void* data, size_t len, uint32_t timeo
342
345
return false ;
343
346
}
344
347
348
+ // If we're configured to support boot protocol, and the host has requested boot protocol, prevent
349
+ // sending of report ID, by passing report ID of 0 to tud_hid_n_report().
350
+ uint8_t effective_id = ((tinyusb_interface_protocol != HID_ITF_PROTOCOL_NONE) &&
351
+ (tud_hid_n_get_protocol (0 ) == HID_PROTOCOL_BOOT)) ? 0 : id;
352
+
345
353
bool res = ready ();
346
354
if (!res){
347
355
log_e (" not ready" );
@@ -352,7 +360,7 @@ bool USBHID::SendReport(uint8_t id, const void* data, size_t len, uint32_t timeo
352
360
// we can wait for it to be given after calling tud_hid_n_report().
353
361
xSemaphoreTake (tinyusb_hid_device_input_sem, 0 );
354
362
355
- res = tud_hid_n_report (0 , id , data, len);
363
+ res = tud_hid_n_report (0 , effective_id , data, len);
356
364
if (!res){
357
365
log_e (" report %u failed" , id);
358
366
} else {
0 commit comments