USB CDC (Virtual COM Port) interface.
More...
#include <cdc.hpp>
|
| 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 bool | write_byte (uint8_t byte) |
| | Write single byte.
|
| |
| static size_t | read (uint8_t *data, size_t max_len) |
| | Read data from USB serial (non-blocking)
|
| |
| static int | read_byte () |
| | Read single byte.
|
| |
| static size_t | available () |
| | Get number of bytes available to read.
|
| |
| 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 void | flush () |
| | Flush TX buffer.
|
| |
USB CDC (Virtual COM Port) interface.
Static class providing serial I/O over USB CDC. All operations are non-blocking unless noted.
- Note
- read/available/connected are ISR-safe (TinyUSB buffer ops). write/puts/write_byte are NOT ISR-safe — may call tud_task(). flush() is NOT ISR-safe — blocks until TX complete.
Definition at line 37 of file cdc.hpp.
◆ available()
| size_t sbl::usb::CdcSerial::available |
( |
| ) |
|
|
static |
Get number of bytes available to read.
- Returns
- Bytes available in receive buffer
Definition at line 92 of file cdc.cpp.
◆ connected()
| bool sbl::usb::CdcSerial::connected |
( |
| ) |
|
|
static |
Check if host has terminal connected (DTR set)
Returns true when a host terminal has opened the port and set DTR. This is more reliable than just checking tud_ready() which only indicates USB enumeration, not that a terminal is actually listening.
- Returns
- true if host terminal is connected
Definition at line 96 of file cdc.cpp.
◆ flush()
| void sbl::usb::CdcSerial::flush |
( |
| ) |
|
|
static |
Flush TX buffer.
Blocks until all pending data is sent or timeout.
Definition at line 119 of file cdc.cpp.
◆ just_connected()
| bool sbl::usb::CdcSerial::just_connected |
( |
| ) |
|
|
static |
Check if a terminal just connected (DTR rising edge)
Returns true exactly once per DTR low→high transition. Use this to send boot banners or one-time status messages when a terminal opens the port.
- Returns
- true once per new connection
Definition at line 100 of file cdc.cpp.
References sbl::usb::ready(), s_dtr_rose, and s_last_ready.
◆ puts()
| size_t sbl::usb::CdcSerial::puts |
( |
const char * |
str | ) |
|
|
static |
◆ read()
| size_t sbl::usb::CdcSerial::read |
( |
uint8_t * |
data, |
|
|
size_t |
max_len |
|
) |
| |
|
static |
Read data from USB serial (non-blocking)
- Parameters
-
| data | Buffer to read into |
| max_len | Maximum bytes to read |
- Returns
- Number of bytes read
Definition at line 78 of file cdc.cpp.
◆ read_byte()
| int sbl::usb::CdcSerial::read_byte |
( |
| ) |
|
|
static |
Read single byte.
- Returns
- Byte read, or -1 if none available
Definition at line 85 of file cdc.cpp.
◆ write()
| size_t sbl::usb::CdcSerial::write |
( |
const uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
|
static |
Write data to USB serial (non-blocking)
May call tud_task() internally to flush — NOT ISR-safe.
- Parameters
-
| data | Pointer to data buffer |
| len | Number of bytes to write |
- Returns
- Number of bytes written (may be less than len if buffer full)
Definition at line 26 of file cdc.cpp.
Referenced by puts().
◆ write_byte()
| bool sbl::usb::CdcSerial::write_byte |
( |
uint8_t |
byte | ) |
|
|
static |
Write single byte.
- Parameters
-
- Returns
- true if byte was written, false if buffer full
Definition at line 62 of file cdc.cpp.
The documentation for this class was generated from the following files: