14static bool last_ready =
false;
15static volatile bool dtr_rose =
false;
17extern "C" void tud_cdc_line_state_cb(uint8_t itf,
bool dtr,
bool rts) {
33 while (written < len) {
34 size_t avail = tud_cdc_write_available();
37 tud_cdc_write_flush();
39 avail = tud_cdc_write_available();
45 size_t to_write = (len - written) < avail ? (len - written) : avail;
46 size_t n = tud_cdc_write(data + written, to_write);
54 tud_cdc_write_flush();
62 return write(
reinterpret_cast<const uint8_t*
>(str), strlen(str));
70 if (tud_cdc_write_available() == 0) {
71 tud_cdc_write_flush();
73 if (tud_cdc_write_available() == 0) {
78 return tud_cdc_write_char(
byte) == 1;
82 if (!tud_cdc_available()) {
85 return tud_cdc_read(data, max_len);
89 if (!tud_cdc_available()) {
92 return tud_cdc_read_char();
100 bool ready = tud_ready();
103 if (
ready && !last_ready) {
119 tud_cdc_write_flush();
122 for (
int i = 0; i < 1000; i++) {
124 if (tud_cdc_write_available() == CFG_TUD_CDC_TX_BUFSIZE) {
128 for (
volatile int j = 0; j < 1000; j++) {}
USB CDC (Virtual COM Port) interface.
static size_t write(const uint8_t *data, size_t len)
Write data to USB serial (non-blocking)
static size_t puts(const char *str)
Write null-terminated string.
static void flush()
Flush TX buffer.
static size_t available()
Get number of bytes available to read.
static size_t read(uint8_t *data, size_t max_len)
Read data from USB serial (non-blocking)
static bool write_byte(uint8_t byte)
Write single byte.
static bool connected()
Check if host has terminal connected (DTR set)
static bool just_connected()
Check if a terminal just connected (DTR rising edge)
static int read_byte()
Read single byte.
bool ready()
Check if USB is enumerated and ready.