mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-01 10:20:38 +00:00
Implemented tuh_hid_send_report
This commit is contained in:
parent
be21413361
commit
f6774d5611
@ -274,7 +274,49 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance)
|
||||
// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
|
||||
//}
|
||||
|
||||
//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
|
||||
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len)
|
||||
{
|
||||
TU_LOG2("HID Send Report %d\r\n", report_id);
|
||||
|
||||
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||
|
||||
if (hid_itf->ep_out == 0)
|
||||
{
|
||||
// This HID does not have an out endpoint (other than control)
|
||||
return false;
|
||||
}
|
||||
else if (len > CFG_TUH_HID_EPOUT_BUFSIZE
|
||||
|| (report_id != 0 && len > (CFG_TUH_HID_EPOUT_BUFSIZE - 1)))
|
||||
{
|
||||
// ep_out buffer is not large enough to hold contents
|
||||
return false;
|
||||
}
|
||||
|
||||
// claim endpoint
|
||||
TU_VERIFY( usbh_edpt_claim(dev_addr, hid_itf->ep_out) );
|
||||
|
||||
if (report_id == 0)
|
||||
{
|
||||
// No report ID in transmission
|
||||
memcpy(&hid_itf->epout_buf[0], report, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
hid_itf->epout_buf[0] = report_id;
|
||||
memcpy(&hid_itf->epout_buf[1], report, len);
|
||||
++len; // 1 more byte for report_id
|
||||
}
|
||||
|
||||
TU_LOG3_MEM(hid_itf->epout_buf, len, 2);
|
||||
|
||||
if ( !usbh_edpt_xfer(dev_addr, hid_itf->ep_out, hid_itf->epout_buf, len) )
|
||||
{
|
||||
usbh_edpt_release(dev_addr, hid_itf->ep_out);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBH API
|
||||
|
@ -106,7 +106,7 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance);
|
||||
|
||||
// Send report using interrupt endpoint
|
||||
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
|
||||
//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
|
||||
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Callbacks (Weak is optional)
|
||||
|
Loading…
x
Reference in New Issue
Block a user