Skip to content

Commit 0f9c756

Browse files
committed
Fix tud_vendor_rx_cb
1 parent 6635f45 commit 0f9c756

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

main/usb_device.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,19 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
347347

348348
void tud_vendor_rx_cb(uint8_t itf, uint8_t const* buffer, uint16_t bufsize) {
349349
(void)itf;
350-
351-
badgelink_rxdata_cb(buffer, bufsize);
352-
// tud_vendor_write(buffer, bufsize);
353-
// tud_vendor_write_flush();
354-
355-
// if using RX buffered is enabled, we need to flush the buffer to make room for new data
356-
#if CFG_TUD_VENDOR_RX_BUFSIZE > 0
357-
tud_vendor_read_flush();
358-
#endif
350+
(void)buffer;
351+
(void)bufsize;
352+
353+
// Vendor class is configured in buffered FIFO mode (CFG_TUD_VENDOR_RX_BUFSIZE > 0),
354+
// so the buffer/bufsize arguments above are always NULL/0; the received data must be
355+
// pulled out of the RX FIFO instead.
356+
357+
uint8_t rx_buf[64];
358+
uint32_t available;
359+
while ((available = tud_vendor_available()) > 0) {
360+
uint32_t read = tud_vendor_read(rx_buf, sizeof(rx_buf));
361+
badgelink_rxdata_cb(rx_buf, read);
362+
}
359363
}
360364

361365
void usb_send_data(uint8_t const* data, size_t len) {

0 commit comments

Comments
 (0)