diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index ca90a9547c..ca08907928 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -60,59 +60,28 @@ typedef struct CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID]; -//--------------------------------------------------------------------+ -// APPLICATION API -//--------------------------------------------------------------------+ -uint8_t tud_hid_get_instance(uint8_t itf_num) +/*------------- Helpers -------------*/ +static inline uint8_t get_index_by_itfnum(uint8_t itf_num) { - // Search for the interface - for (uint8_t i=0; i < CFG_TUD_HID; i++ ) + for (uint8_t i=0; i < CFG_TUD_HID; i++ ) { - // Skip current instance if that isn't assigned yet - if (0 == _hidd_itf[i].ep_in && 0 == _hidd_itf[i].ep_out) - { - continue; - } - - if (itf_num == _hidd_itf[i].itf_num) - { - return i; - } + if ( itf_num == _hidd_itf[i].itf_num ) return i; } return 0xFF; } -uint8_t tud_hid_get_itf_num(uint8_t instance) -{ - // Abort if an invalid instance number was given - if (CFG_TUD_HID <= instance) - { - return 0xFF; - } - - // Abort if the instance hasn't a valid interface assigned yet - if (0 == _hidd_itf[instance].ep_in && 0 == _hidd_itf[instance].ep_out) - { - return 0xFF; - } - - // Return the interface number - return _hidd_itf[instance].itf_num; -} - +//--------------------------------------------------------------------+ +// APPLICATION API +//--------------------------------------------------------------------+ bool tud_hid_n_ready(uint8_t instance) { - TU_VERIFY( CFG_TUD_HID > instance ); - uint8_t const ep_in = _hidd_itf[instance].ep_in; return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in); } bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint16_t len) { - TU_VERIFY( CFG_TUD_HID > instance ); - uint8_t const rhport = 0; hidd_interface_t * p_hid = &_hidd_itf[instance]; @@ -139,15 +108,11 @@ bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, u uint8_t tud_hid_n_interface_protocol(uint8_t instance) { - TU_VERIFY( CFG_TUD_HID > instance, 0xFF ); - return _hidd_itf[instance].itf_protocol; } uint8_t tud_hid_n_get_protocol(uint8_t instance) { - TU_VERIFY( CFG_TUD_HID > instance, 0xFF ); - return _hidd_itf[instance].protocol_mode; } @@ -276,7 +241,7 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t { TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE); - uint8_t const hid_itf = tud_hid_get_instance((uint8_t) request->wIndex); + uint8_t const hid_itf = get_index_by_itfnum((uint8_t) request->wIndex); TU_VERIFY(hid_itf < CFG_TUD_HID); hidd_interface_t* p_hid = &_hidd_itf[hid_itf]; diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 801d5fda12..12023d6ea1 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -52,12 +52,6 @@ // CFG_TUD_HID > 1 //--------------------------------------------------------------------+ -// Returns the instance of the given interface or 0xFF if not available -uint8_t tud_hid_get_instance(uint8_t itf_num); - -// Returns the interface number of the given instance or 0xFF if not available -uint8_t tud_hid_get_itf_num(uint8_t instance); - // Check if the interface is ready to use bool tud_hid_n_ready(uint8_t instance); diff --git a/src/device/usbd.c b/src/device/usbd.c index ec4e021874..99647c140b 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -1280,9 +1280,6 @@ bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr) // TU_VERIFY(tud_ready()); uint8_t const epnum = tu_edpt_number(ep_addr); - - TU_ASSERT( 0 < epnum && CFG_TUD_ENDPPOINT_MAX > epnum ); - uint8_t const dir = tu_edpt_dir(ep_addr); tu_edpt_state_t* ep_state = &_usbd_dev.ep_status[epnum][dir];