diff options
| author | Zachery Littell <[email protected]> | 2020-10-02 16:02:00 -0500 |
|---|---|---|
| committer | Zachery Littell <[email protected]> | 2020-10-02 16:02:00 -0500 |
| commit | 081af79009dc40ab41be9976d22629c7d251a50d (patch) | |
| tree | 9b5b5234b65a158694885b8f338449f2dc7f14a9 /src | |
| parent | 34775d909da5de2585821bf31370040d1fbb5f4a (diff) | |
fix simple pull request comments. Implement descriptor index hack.
Diffstat (limited to 'src')
| -rw-r--r-- | src/class/hid/hid_device.c | 20 | ||||
| -rw-r--r-- | src/class/hid/hid_device.h | 5 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index b4c75e3fb..9e1c5fd33 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -67,12 +67,21 @@ static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num) return NULL; } +static inline uint8_t get_descindex_by_itfnum(uint8_t itf_num) +{ + for (uint8_t i=0; i < CFG_TUD_HID; i++ ) + { + if ( itf_num == _hidd_itf[i].itf_num ) return i; + } + + return 0; +} + //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ bool tud_hid_n_ready(uint8_t itf) { - //uint8_t const itf = 0; uint8_t const ep_in = _hidd_itf[itf].ep_in; return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in); } @@ -80,7 +89,6 @@ bool tud_hid_n_ready(uint8_t itf) bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len) { uint8_t const rhport = 0; - //uint8_t const itf = 0; hidd_interface_t * p_hid = &_hidd_itf[itf]; // claim endpoint @@ -106,7 +114,6 @@ bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_ bool tud_hid_n_boot_mode(uint8_t itf) { - //uint8_t itf = 0; return _hidd_itf[itf].boot_mode; } @@ -237,7 +244,12 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request } else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT) { - uint8_t const * desc_report = tud_hid_descriptor_report_cb((uint8_t) request->wIndex); + #if CFG_TUD_HID>1 + uint8_t const calculated_desc_index = get_descindex_by_itfnum((uint8_t) request->wIndex); + uint8_t const * desc_report = tud_hid_descriptor_report_cb(calculated_desc_index); + #else + uint8_t const * desc_report = tud_hid_descriptor_report_cb(); + #endif tud_control_xfer(rhport, request, (void*) desc_report, p_hid->report_desc_len); } else diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 1873c4f09..30d99ce47 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -86,8 +86,11 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 // Invoked when received GET HID REPORT DESCRIPTOR request // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete -// TODO Talk about this change... because it is breaking. Might be better way to handle. +#if CFG_TUD_HID>1 uint8_t const * tud_hid_descriptor_report_cb(uint8_t desc_index); +#else +uint8_t const * tud_hid_descriptor_report_cb(void); +#endif // Invoked when received GET_REPORT control request // Application must fill buffer report's content and return its length. |
