From 3912775ccbd5547899554f5f4064411091cd7878 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 27 Sep 2022 12:23:16 +0200 Subject: [PATCH] Fix writting large packets. Signed-off-by: Pol Henarejos --- src/usb/hid/hid.c | 6 +++--- src/usb/usb.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/usb/hid/hid.c b/src/usb/hid/hid.c index 32820b3..192d50d 100644 --- a/src/usb/hid/hid.c +++ b/src/usb/hid/hid.c @@ -95,7 +95,7 @@ void hid_write(uint16_t size) { uint16_t send_buffer_size = 0; void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, /*uint16_t*/ uint8_t len) { - uint8_t seq = report[4] & TYPE_MASK ? 0 : report[4]+1; + uint8_t seq = report[4] & TYPE_MASK ? 0 : report[4] + 1; if (send_buffer_size > 0) { ctap_resp->cid = ctap_req->cid; ctap_resp->cont.seq = seq; @@ -106,8 +106,8 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, /*uint1 } int driver_write(const uint8_t *buffer, size_t buffer_size) { - int ret = tud_hid_report(0, buffer, buffer_size); - return ret; + tud_hid_report(0, buffer, buffer_size); + return MIN(64, buffer_size); } size_t driver_read(uint8_t *buffer, size_t buffer_size) { diff --git a/src/usb/usb.c b/src/usb/usb.c index 058e6af..2e3810c 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -54,7 +54,7 @@ uint32_t usb_write_offset(uint16_t len, uint16_t offset) { w = driver_write(tx_buffer+offset, MIN(len, pkt_max)); w_len -= w; tx_r_offset += w; - return w; + return MIN(w_len, pkt_max); } size_t usb_rx(const uint8_t *buffer, size_t len) { @@ -182,9 +182,9 @@ void usb_task() { // printf("\r\n ------ M = %lu\r\n",m); if (has_m) { if (m == EV_EXEC_FINISHED) { + timeout_stop(); driver_exec_finished(finished_data_size); led_set_blink(BLINK_MOUNTED); - timeout_stop(); } else if (m == EV_PRESS_BUTTON) { uint32_t flag = wait_button() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;