Skip to content

Commit 2fc9fbe

Browse files
authored
Merge pull request hathach#2340 from hathach/hid-set-protocol-pr
Hid set protocol pr
2 parents 02017a8 + f469250 commit 2fc9fbe

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/class/hid/hid_host.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ typedef struct
6767
CFG_TUH_MEM_SECTION
6868
tu_static hidh_interface_t _hidh_itf[CFG_TUH_HID];
6969

70+
tu_static uint8_t _hidh_default_protocol = HID_PROTOCOL_BOOT;
71+
7072
//--------------------------------------------------------------------+
7173
// Helper
7274
//--------------------------------------------------------------------+
@@ -211,6 +213,10 @@ static void set_protocol_complete(tuh_xfer_t* xfer)
211213
}
212214
}
213215

216+
void tuh_hid_set_default_protocol(uint8_t protocol) {
217+
_hidh_default_protocol = protocol;
218+
}
219+
214220
static bool _hidh_set_protocol(uint8_t daddr, uint8_t itf_num, uint8_t protocol, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
215221
{
216222
TU_LOG_DRV("HID Set Protocol = %d\r\n", protocol);
@@ -521,7 +527,7 @@ bool hidh_open(uint8_t rhport, uint8_t daddr, tusb_desc_interface_t const *desc_
521527
p_hid->report_desc_len = tu_unaligned_read16(&desc_hid->wReportLength);
522528

523529
// Per HID Specs: default is Report protocol, though we will force Boot protocol when set_config
524-
p_hid->protocol_mode = HID_PROTOCOL_BOOT;
530+
p_hid->protocol_mode = _hidh_default_protocol;
525531
if ( HID_SUBCLASS_BOOT == desc_itf->bInterfaceSubClass )
526532
{
527533
p_hid->itf_protocol = desc_itf->bInterfaceProtocol;
@@ -591,7 +597,7 @@ static void process_set_config(tuh_xfer_t* xfer)
591597
break;
592598

593599
case CONFIG_SET_PROTOCOL:
594-
_hidh_set_protocol(daddr, p_hid->itf_num, HID_PROTOCOL_BOOT, process_set_config, CONFIG_GET_REPORT_DESC);
600+
_hidh_set_protocol(daddr, p_hid->itf_num, _hidh_default_protocol, process_set_config, CONFIG_GET_REPORT_DESC);
595601
break;
596602

597603
case CONFIG_GET_REPORT_DESC:

src/class/hid/hid_host.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* reports_info_arr,
9797
// Application can use set_protocol() to switch back to Report protocol.
9898
uint8_t tuh_hid_get_protocol(uint8_t dev_addr, uint8_t idx);
9999

100+
// Device by default is enumerated in Boot protocol for simplicity. Application
101+
// can use this to modify the default protocol for next enumeration.
102+
void tuh_hid_set_default_protocol(uint8_t protocol);
103+
100104
// Set protocol to HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
101105
// This function is only supported by Boot interface (tuh_n_hid_interface_protocol() != NONE)
102106
bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t idx, uint8_t protocol);

0 commit comments

Comments
 (0)