Skip to content

Commit 75010af

Browse files
Remove unnecessary xSemaphoreTake() of USBHID semaphore
The HID semaphore allows USBHID::SendReport() to wait for the completion of report sending. There seemed to be an extra call to xSemaphoreTake() of this semaphore that served no purpose. With this extra call, occasionally, the following would happening: 1. USBHID::SendReport() would send a report by calling tud_hid_n_report(). 2. The send would complete and (presumably on another thread) tud_hid_report_complete_cb() would be called and it would xSemaphoreGive() the semaphore. 3. In USBHID::SendReport(), the extra xSemaphoreTake(sem, 0) would succeed, taking the semaphore. 4. On the next line, xSemaphoreTake(sem, timeout_ms ...) would timeout because the semaphore was already taken by the previous line of code. The result would be waiting timeout_ms for no reason. The fix is to eliminate the extra unnecessary call to xSemaphoreTake().
1 parent c93bf11 commit 75010af

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

libraries/USB/src/USBHID.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ bool USBHID::SendReport(uint8_t id, const void* data, size_t len, uint32_t timeo
335335
if(!res){
336336
log_e("report %u failed", id);
337337
} else {
338-
xSemaphoreTake(tinyusb_hid_device_input_sem, 0);
339338
if(xSemaphoreTake(tinyusb_hid_device_input_sem, timeout_ms / portTICK_PERIOD_MS) != pdTRUE){
340339
log_e("report %u wait failed", id);
341340
res = false;

0 commit comments

Comments
 (0)