|
1 |
| -/* |
| 1 | +/* |
2 | 2 | * The MIT License (MIT)
|
3 | 3 | *
|
4 | 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org)
|
@@ -274,7 +274,49 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance)
|
274 | 274 | // return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
|
275 | 275 | //}
|
276 | 276 |
|
277 |
| -//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len); |
| 277 | +bool tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len) |
| 278 | +{ |
| 279 | + TU_LOG2("HID Send Report %d\r\n", report_id); |
| 280 | + |
| 281 | + hidh_interface_t* hid_itf = get_instance(dev_addr, instance); |
| 282 | + |
| 283 | + if (hid_itf->ep_out == 0) |
| 284 | + { |
| 285 | + // This HID does not have an out endpoint (other than control) |
| 286 | + return false; |
| 287 | + } |
| 288 | + else if (len > CFG_TUH_HID_EPOUT_BUFSIZE |
| 289 | + || (report_id != 0 && len > (CFG_TUH_HID_EPOUT_BUFSIZE - 1))) |
| 290 | + { |
| 291 | + // ep_out buffer is not large enough to hold contents |
| 292 | + return false; |
| 293 | + } |
| 294 | + |
| 295 | + // claim endpoint |
| 296 | + TU_VERIFY( usbh_edpt_claim(dev_addr, hid_itf->ep_out) ); |
| 297 | + |
| 298 | + if (report_id == 0) |
| 299 | + { |
| 300 | + // No report ID in transmission |
| 301 | + memcpy(&hid_itf->epout_buf[0], report, len); |
| 302 | + } |
| 303 | + else |
| 304 | + { |
| 305 | + hid_itf->epout_buf[0] = report_id; |
| 306 | + memcpy(&hid_itf->epout_buf[1], report, len); |
| 307 | + ++len; // 1 more byte for report_id |
| 308 | + } |
| 309 | + |
| 310 | + TU_LOG3_MEM(hid_itf->epout_buf, len, 2); |
| 311 | + |
| 312 | + if ( !usbh_edpt_xfer(dev_addr, hid_itf->ep_out, hid_itf->epout_buf, len) ) |
| 313 | + { |
| 314 | + usbh_edpt_release(dev_addr, hid_itf->ep_out); |
| 315 | + return false; |
| 316 | + } |
| 317 | + |
| 318 | + return true; |
| 319 | +} |
278 | 320 |
|
279 | 321 | //--------------------------------------------------------------------+
|
280 | 322 | // USBH API
|
@@ -349,7 +391,7 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
|
349 | 391 | hidh_device_t* hid_dev = get_dev(dev_addr);
|
350 | 392 | TU_ASSERT(hid_dev->inst_count < CFG_TUH_HID, 0);
|
351 | 393 |
|
352 |
| - hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count); |
| 394 | + hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count); |
353 | 395 |
|
354 | 396 | //------------- Endpoint Descriptors -------------//
|
355 | 397 | p_desc = tu_desc_next(p_desc);
|
|
0 commit comments