From 2df5a5367f6b8a6649d39d3ba7ebc0af56db9ad2 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 May 2021 13:12:33 +0700 Subject: [PATCH] update hid host get/set protocol to match device --- src/class/hid/hid_device.h | 2 +- src/class/hid/hid_host.c | 12 ++++++------ src/class/hid/hid_host.h | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index bccfb8d4..bfaa35f7 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -57,7 +57,7 @@ // Check if the interface is ready to use bool tud_hid_n_ready(uint8_t instance); -// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible value +// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values uint8_t tud_hid_n_interface_protocol(uint8_t instance); // Get current active protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 8d60ceb7..62e6c4b7 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -57,8 +57,8 @@ typedef struct uint16_t epin_size; uint16_t epout_size; - uint8_t boot_interface; // None, Keyboard, Mouse - bool boot_mode; // Boot or Report protocol + uint8_t itf_protocol; // None, Keyboard, Mouse + bool boot_mode; // Boot or Report protocol uint8_t epin_buf[CFG_TUH_HID_EP_BUFSIZE]; uint8_t epout_buf[CFG_TUH_HID_EP_BUFSIZE]; @@ -102,16 +102,16 @@ bool tuh_n_hid_n_mounted(uint8_t dev_addr, uint8_t instance) uint8_t tuh_n_hid_n_interface_protocol(uint8_t dev_addr, uint8_t instance) { hidh_interface_t* hid_itf = get_instance(dev_addr, instance); - return hid_itf->boot_interface; + return hid_itf->itf_protocol; } bool tuh_n_hid_n_get_protocol(uint8_t dev_addr, uint8_t instance) { hidh_interface_t* hid_itf = get_instance(dev_addr, instance); - return hid_itf->boot_mode; + return hid_itf->boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT; } -//bool tuh_n_hid_n_set_protocol(uint8_t dev_addr, uint8_t instance, bool boot_mode) +// bool tuh_n_hid_n_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol) //{ // //} @@ -212,7 +212,7 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de hid_itf->boot_mode = false; // default is report mode if ( HID_SUBCLASS_BOOT == desc_itf->bInterfaceSubClass ) { - hid_itf->boot_interface = desc_itf->bInterfaceProtocol; + hid_itf->itf_protocol = desc_itf->bInterfaceProtocol; if ( HID_ITF_PROTOCOL_KEYBOARD == desc_itf->bInterfaceProtocol) { diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h index 87b86c90..677c8c9d 100644 --- a/src/class/hid/hid_host.h +++ b/src/class/hid/hid_host.h @@ -74,16 +74,16 @@ uint8_t tuh_n_hid_instance_count(uint8_t dev_addr); // Check if HID instance is mounted bool tuh_n_hid_n_mounted(uint8_t dev_addr, uint8_t instance); -// Get boot interface protocol check out hid_protocol_type_t for possible value +// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values uint8_t tuh_n_hid_n_interface_protocol(uint8_t dev_addr, uint8_t instance); -// Get current protocol mode: Boot (true) or Report (false) -// By HID spec, device will be initialized in Report mode +// Get current active protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) +// Note: as HID spec, device will be initialized in Report mode bool tuh_n_hid_n_get_protocol(uint8_t dev_addr, uint8_t instance); -// Set protocol to Boot or Report mode. +// Set protocol to HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) // This function is only supported by Boot interface tuh_n_hid_n_boot_interface() -bool tuh_n_hid_n_set_protocol(uint8_t dev_addr, uint8_t instance, bool boot_mode); +bool tuh_n_hid_n_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol); // Parse report descriptor into array of report_info struct and return number of reports. // If return 0, this is a ingle report, otherwise it is composite report with 1st byte as ID.