diff options
| author | sommersoft <sommersoft@gmail.com> | 2018-03-24 00:55:48 +0000 |
|---|---|---|
| committer | sommersoft <sommersoft@gmail.com> | 2018-03-24 00:55:48 +0000 |
| commit | ef16109c5dbde3136ae901b55525eb59f1d1fb4f (patch) | |
| tree | 902f29013e3d9150e8cf8d89829ba306f4edbcc8 | |
| parent | f237657e5ebc592c2a8f37546c19a421ee5f37f8 (diff) | |
updated with requested changes
| -rw-r--r-- | ports/atmel-samd/usb.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/ports/atmel-samd/usb.c b/ports/atmel-samd/usb.c index 6148c56ae..af70be99a 100644 --- a/ports/atmel-samd/usb.c +++ b/ports/atmel-samd/usb.c @@ -102,12 +102,13 @@ static void init_hardware(void) { #endif } -COMPILER_ALIGNED(4) uint8_t cdc_packet_buffer[64]; +#define CDC_BULKOUT_SIZE CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ +COMPILER_ALIGNED(4) uint8_t cdc_packet_buffer[CDC_BULKOUT_SIZE]; static volatile bool pending_read; static int32_t start_read(void) { pending_read = true; - int32_t result = cdcdf_acm_read(cdc_packet_buffer, 64); + int32_t result = cdcdf_acm_read(cdc_packet_buffer, CDC_BULKOUT_SIZE); if (result != ERR_NONE) { pending_read = false; } @@ -151,14 +152,6 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u } atomic_leave_critical(&flags); - // Trigger a follow up read if we have space. - /*if (usb_rx_count < USB_RX_BUF_SIZE - 64) { - int32_t result = start_read(); - if (result != ERR_NONE) { - return true; - } - }*/ - /* No error. */ return false; } @@ -247,7 +240,7 @@ static bool cdc_enabled(void) { bool usb_bytes_available(void) { // Check if the buffer has data, but not enough // space to hold another read. - if (usb_rx_count > 64) { + if (usb_rx_count > CDC_BULKOUT_SIZE) { return usb_rx_count > 0; } // Buffer has enough room @@ -277,11 +270,6 @@ int usb_read(void) { } CRITICAL_SECTION_LEAVE(); - // Trigger a new read because we just cleared some space. - /*if (!pending_read && usb_rx_count == USB_RX_BUF_SIZE - 1) { - start_read(); - }*/ - return data; } @@ -328,12 +316,10 @@ bool usb_connected(void) { // Poll for input if keyboard interrupts are enabled, // so that we can check for the interrupt char. read_complete() does the checking. +// also make sure we have enough room in the local buffer void usb_cdc_background() { // - if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read) { - // Make sure we have space in the buffer - if (usb_rx_count < 64) { - start_read(); - } + if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read && usb_rx_count < CDC_BULKOUT_SIZE) { + start_read(); } } |
