Skip to content

Commit

Permalink
Proper status for recevied data
Browse files Browse the repository at this point in the history
- When data is received it's properly tagged as as output data
- New callback in the case an error occured when on Out packet
  • Loading branch information
RockyZeroFour committed Feb 19, 2024
1 parent 1513d53 commit 476994e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/class/hid/hid_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,25 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
}
TU_ASSERT(instance < CFG_TUD_HID);

// Check if there was a problem
if (XFER_RESULT_SUCCESS != result)
{
// Inform application about the issue
if (tud_hid_report_issue_cb)
{
tud_hid_report_issue_cb(instance, ep_addr, result, xferred_bytes);
}

// Allow a new transfer to be received if issue happened on an OUT endpoint
if (ep_addr == p_hid->ep_out)
{
// Prepare the OUT endpoint to be able to receive a new transfer
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
}

return true;
}

// Sent report successfully
if (ep_addr == p_hid->ep_in)
{
Expand All @@ -404,10 +423,10 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
tud_hid_report_complete_cb(instance, p_hid->epin_buf, (uint16_t) xferred_bytes);
}
}
// Received report
// Received report successfully
else if (ep_addr == p_hid->ep_out)
{
tud_hid_set_report_cb(instance, 0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, (uint16_t) xferred_bytes);
tud_hid_set_report_cb(instance, 0, HID_REPORT_TYPE_OUTPUT, p_hid->epout_buf, (uint16_t) xferred_bytes);
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
}

Expand Down
2 changes: 2 additions & 0 deletions src/class/hid/hid_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate);
// Note: For composite reports, report[0] is report ID
TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint16_t len);

// Invoked when a transfer wasn't successful
TU_ATTR_WEAK void tud_hid_report_issue_cb(uint8_t instance, uint8_t ep_addr, xfer_result_t result, uint16_t xferred_bytes);

//--------------------------------------------------------------------+
// Inline Functions
Expand Down

0 comments on commit 476994e

Please sign in to comment.