Skip to content

Commit 0672cb8

Browse files
committed
add Adafruit_USBD_CDC::ignoreFlowControl
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.
1 parent 05686e7 commit 0672cb8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/arduino/Adafruit_USBD_CDC.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ void Adafruit_USBD_CDC::end(void) {
118118
_instance = INVALID_INSTANCE;
119119
}
120120

121+
void Adafruit_USBD_CDC::ignoreFlowControl(bool ignore) {
122+
_ignoreFlowControl = ignore;
123+
}
124+
121125
uint32_t Adafruit_USBD_CDC::baud(void) {
122126
if (!isValid()) {
123127
return 0;
@@ -243,7 +247,7 @@ size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size) {
243247
}
244248

245249
size_t remain = size;
246-
while (remain && tud_cdc_n_connected(_instance)) {
250+
while (remain && (tud_cdc_n_connected(_instance) || _ignoreFlowControl)) {
247251
size_t wrcount = tud_cdc_n_write(_instance, buffer, remain);
248252
remain -= wrcount;
249253
buffer += wrcount;

src/arduino/Adafruit_USBD_CDC.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface {
5454
void begin(uint32_t baud, uint8_t config);
5555
void end(void);
5656

57+
// In some cases, the target application will not assert
58+
// the DTR virtual line, thus preventing writing operations
59+
// to succeed. For this reason, the
60+
// Adafruit_USBD_CDC::ignoreFlowControl() method disables the
61+
// connection’s state verification, enabling the program to
62+
// write on the port, even though the data might be lost.
63+
void ignoreFlowControl(bool ignore = true);
64+
5765
// return line coding set by host
5866
uint32_t baud(void);
5967
uint8_t stopbits(void);
@@ -90,6 +98,8 @@ class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface {
9098

9199
uint8_t _instance;
92100

101+
bool _ignoreFlowControl = false;
102+
93103
bool isValid(void) { return _instance != INVALID_INSTANCE; }
94104
};
95105

0 commit comments

Comments
 (0)