Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add availableForWrite method to Serial. #311

Merged
merged 2 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_write_available();
}

extern "C"
{

Expand Down
1 change: 1 addition & 0 deletions cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ bool tud_cdc_n_write_flush (uint8_t itf)
return true;
}

uint32_t tud_cdc_n_write_available (uint8_t itf)
{
return tu_fifo_remaining(&_cdcd_itf[itf].tx_ff);
}


//--------------------------------------------------------------------+
// USBD Driver API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_write_available (uint8_t itf);

//--------------------------------------------------------------------+
// Application API (Interface0)
Expand All @@ -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_write_available (void);

//--------------------------------------------------------------------+
// Application Callback API (weak is optional)
Expand Down Expand Up @@ -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_write_available(void)
{
return tud_cdc_n_write_available(0);
}

/** @} */
/** @} */

Expand Down