Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
sbl::usb::CdcSerial Class Reference

USB CDC (Virtual COM Port) interface. More...

#include <cdc.hpp>

Collaboration diagram for sbl::usb::CdcSerial:

Static Public Member Functions

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.
 

Detailed Description

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.

Member Function Documentation

◆ 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.

Here is the call graph for this function:

◆ puts()

size_t sbl::usb::CdcSerial::puts ( const char *  str)
static

Write null-terminated string.

Parameters
strString to write
Returns
Number of bytes written

Definition at line 57 of file cdc.cpp.

References write().

Referenced by sbl::usb::CdcOutput::write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read()

size_t sbl::usb::CdcSerial::read ( uint8_t *  data,
size_t  max_len 
)
static

Read data from USB serial (non-blocking)

Parameters
dataBuffer to read into
max_lenMaximum 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
dataPointer to data buffer
lenNumber 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().

Here is the caller graph for this function:

◆ write_byte()

bool sbl::usb::CdcSerial::write_byte ( uint8_t  byte)
static

Write single byte.

Parameters
byteByte to write
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: