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 Adafruit_USBD_CDC::ignoreFlowControl #459

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion src/arduino/Adafruit_USBD_CDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ void Adafruit_USBD_CDC::end(void) {
_instance = INVALID_INSTANCE;
}

#ifdef ARDUINO_ARCH_RP2040
void Adafruit_USBD_CDC::ignoreFlowControl(bool ignore) {
_ignoreFlowControl = ignore;
}
#endif

uint32_t Adafruit_USBD_CDC::baud(void) {
if (!isValid()) {
return 0;
Expand Down Expand Up @@ -243,7 +249,12 @@ size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size) {
}

size_t remain = size;
while (remain && tud_cdc_n_connected(_instance)) {
#ifdef ARDUINO_ARCH_RP2040
while (remain && (tud_cdc_n_connected(_instance) || _ignoreFlowControl))
#else
while (remain && tud_cdc_n_connected(_instance))
#endif
{
size_t wrcount = tud_cdc_n_write(_instance, buffer, remain);
remain -= wrcount;
buffer += wrcount;
Expand Down
14 changes: 14 additions & 0 deletions src/arduino/Adafruit_USBD_CDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface {
void begin(uint32_t baud, uint8_t config);
void end(void);

#ifdef ARDUINO_ARCH_RP2040
// In some cases, the target application will not assert
// the DTR virtual line, thus preventing writing operations
// to succeed. For this reason, the
// Adafruit_USBD_CDC::ignoreFlowControl() method disables the
// connection’s state verification, enabling the program to
// write on the port, even though the data might be lost.
void ignoreFlowControl(bool ignore = true);
#endif

// return line coding set by host
uint32_t baud(void);
uint8_t stopbits(void);
Expand Down Expand Up @@ -90,6 +100,10 @@ class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface {

uint8_t _instance;

#ifdef ARDUINO_ARCH_RP2040
bool _ignoreFlowControl = false;
#endif

bool isValid(void) { return _instance != INVALID_INSTANCE; }
};

Expand Down
Loading