Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::usb::CdcSerial Class Reference

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

Detailed Description

USB CDC (Virtual COM Port) interface.

Static class providing serial I/O over USB CDC. All operations are non-blocking unless noted.

Context
read(), available() and connected() only read TinyUSB's CDC state and do not call tud_task(). write(), puts() and write_byte() are not ISR-safe: they may call tud_task(). flush() is not ISR-safe: it blocks until TX completes or times out.

Definition at line 44 of file cdc.hpp.

#include <cdc.hpp>

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.
 

Member Function Documentation

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

Context
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 27 of file cdc.cpp.

Referenced by puts().

◆ 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 58 of file cdc.cpp.

References write().

◆ 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 65 of file cdc.cpp.

◆ 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 81 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 88 of file cdc.cpp.

◆ available()

size_t sbl::usb::CdcSerial::available ( )
static

Get number of bytes available to read.

Returns
Bytes available in receive buffer

Definition at line 95 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 97 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 99 of file cdc.cpp.

References sbl::usb::ready().

◆ flush()

void sbl::usb::CdcSerial::flush ( )
static

Flush TX buffer.

Blocks until all pending data is sent or timeout.

Definition at line 118 of file cdc.cpp.


The documentation for this class was generated from the following files: