From d7de810644213f29a917fd947b7012d91e108567 Mon Sep 17 00:00:00 2001 From: Steven James Date: Fri, 26 Jul 2019 18:24:58 -0400 Subject: [PATCH 1/2] Add availableForWrite method to Serial. --- cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp | 5 +++++ cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h | 1 + .../tinyusb/src/class/cdc/cdc_device.c | 5 +++++ .../tinyusb/src/class/cdc/cdc_device.h | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp index 49ff27c98..d21b0f06a 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp +++ b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp @@ -125,6 +125,11 @@ size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size) return size - remain; } +size_t Adafruit_USBD_CDC::availableForWrite(void) +{ + return tud_cdc_availableForWrite(); +} + extern "C" { diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h index 5d315e9d5..505005c86 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h @@ -50,6 +50,7 @@ class Adafruit_USBD_CDC : public Stream, Adafruit_USBD_Interface size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); } + size_t availableForWrite(void); operator bool(); }; diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c index 464936793..e48d34605 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c @@ -190,6 +190,11 @@ bool tud_cdc_n_write_flush (uint8_t itf) return true; } +uint32_t tud_cdc_n_availableForWrite (uint8_t itf) +{ + return CFG_TUD_CDC_TX_BUFSIZE - tu_fifo_count(&_cdcd_itf[itf].tx_ff); +} + //--------------------------------------------------------------------+ // USBD Driver API diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h index 8d09094a0..159e8ad7e 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h @@ -66,6 +66,7 @@ uint32_t tud_cdc_n_write_char (uint8_t itf, char ch); uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bufsize); uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str); bool tud_cdc_n_write_flush (uint8_t itf); +uint32_t tud_cdc_n_availableForWrite (uint8_t itf); //--------------------------------------------------------------------+ // Application API (Interface0) @@ -85,6 +86,7 @@ static inline uint32_t tud_cdc_write_char (char ch); static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize); static inline uint32_t tud_cdc_write_str (char const* str); static inline bool tud_cdc_write_flush (void); +static inline uint32_t tud_cdc_availableForWrite(void); //--------------------------------------------------------------------+ // Application Callback API (weak is optional) @@ -170,6 +172,11 @@ static inline bool tud_cdc_write_flush (void) return tud_cdc_n_write_flush(0); } +static inline uint32_t tud_cdc_availableForWrite(void) +{ + return tud_cdc_n_availableForWrite(0); +} + /** @} */ /** @} */ From 4eca9f88f732f71b7dd0abee16689f6384dab7aa Mon Sep 17 00:00:00 2001 From: Steven James Date: Sat, 27 Jul 2019 14:44:26 -0400 Subject: [PATCH 2/2] Use tu_fifo_remaining instead of tu_fifo_count rename low level CDC functions to tud_cdc_n_write_available and tud_cdc_write_available --- cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp | 2 +- .../tinyusb/src/class/cdc/cdc_device.c | 4 ++-- .../tinyusb/src/class/cdc/cdc_device.h | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp index d21b0f06a..f3916d065 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp +++ b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp @@ -127,7 +127,7 @@ size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size) size_t Adafruit_USBD_CDC::availableForWrite(void) { - return tud_cdc_availableForWrite(); + return tud_cdc_write_available(); } extern "C" diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c index e48d34605..1cb987b50 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c @@ -190,9 +190,9 @@ bool tud_cdc_n_write_flush (uint8_t itf) return true; } -uint32_t tud_cdc_n_availableForWrite (uint8_t itf) +uint32_t tud_cdc_n_write_available (uint8_t itf) { - return CFG_TUD_CDC_TX_BUFSIZE - tu_fifo_count(&_cdcd_itf[itf].tx_ff); + return tu_fifo_remaining(&_cdcd_itf[itf].tx_ff); } diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h index 159e8ad7e..f113578bf 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h @@ -66,7 +66,7 @@ uint32_t tud_cdc_n_write_char (uint8_t itf, char ch); uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bufsize); uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str); bool tud_cdc_n_write_flush (uint8_t itf); -uint32_t tud_cdc_n_availableForWrite (uint8_t itf); +uint32_t tud_cdc_n_write_available (uint8_t itf); //--------------------------------------------------------------------+ // Application API (Interface0) @@ -86,7 +86,7 @@ static inline uint32_t tud_cdc_write_char (char ch); static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize); static inline uint32_t tud_cdc_write_str (char const* str); static inline bool tud_cdc_write_flush (void); -static inline uint32_t tud_cdc_availableForWrite(void); +static inline uint32_t tud_cdc_write_available (void); //--------------------------------------------------------------------+ // Application Callback API (weak is optional) @@ -172,9 +172,9 @@ static inline bool tud_cdc_write_flush (void) return tud_cdc_n_write_flush(0); } -static inline uint32_t tud_cdc_availableForWrite(void) +static inline uint32_t tud_cdc_write_available(void) { - return tud_cdc_n_availableForWrite(0); + return tud_cdc_n_write_available(0); } /** @} */