Skip to content

Commit

Permalink
Revert "Fix and improvement"
Browse files Browse the repository at this point in the history
  • Loading branch information
RockyZeroFour authored Sep 19, 2024
1 parent b868293 commit a558293
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 52 deletions.
51 changes: 8 additions & 43 deletions src/class/hid/hid_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
}

Expand Down Expand Up @@ -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];
Expand Down
6 changes: 0 additions & 6 deletions src/class/hid/hid_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 0 additions & 3 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit a558293

Please sign in to comment.