CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
usb_cdc.h File Reference
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

bool usb_cdc_init (void)
bool usb_cdc_start (void)
 Starts USB CDC runtime (or triggers re-enumeration in early-debug mode).
bool usb_cdc_ready (void)
 Returns whether USB CDC is connected and ready.
size_t usb_cdc_write (const uint8_t *data, size_t len)
 Writes byte buffer to USB CDC endpoint.
size_t usb_cdc_print (const char *str)
 Writes null-terminated string to USB CDC.
size_t usb_cdc_read (uint8_t *data, size_t len)
 Reads bytes from USB CDC endpoint.
int usb_cdc_getchar (void)
 Reads one character from USB CDC stream.
size_t usb_cdc_available (void)
 Returns number of bytes available for read.
void usb_cdc_flush (void)
 Flushes pending USB CDC writes.

Function Documentation

◆ usb_cdc_available()

size_t usb_cdc_available ( void )

Returns number of bytes available for read.

Check if data is available to read

Returns
Number of bytes available
Pending byte count.

Definition at line 268 of file usb_cdc.cpp.

References g_usb_started.

◆ usb_cdc_flush()

void usb_cdc_flush ( void )

Flushes pending USB CDC writes.

Flush TX buffer (blocking)

Definition at line 276 of file usb_cdc.cpp.

References g_usb_started.

◆ usb_cdc_getchar()

int usb_cdc_getchar ( void )

Reads one character from USB CDC stream.

Get single character from USB CDC (non-blocking)

Returns
Character or -1 if no data
Character value or -1 if unavailable.

Definition at line 254 of file usb_cdc.cpp.

References g_usb_started.

◆ usb_cdc_init()

bool usb_cdc_init ( void )

USB CDC Serial Interface

Provides serial console via TinyUSB CDC. Initialize USB subsystem with CDC serial Behavior depends on CONFIG_USB_EARLY_DEBUG:

  • If enabled: Starts USB immediately (for debug logs during boot)
  • If disabled: Only prepares USB, call usb_cdc_start() after modules loaded
    Returns
    true if successful

Definition at line 129 of file usb_cdc.cpp.

References g_usb_prepared, LOG_E, LOG_I, TAG, usb_hid_init(), and usb_start_stack().

Referenced by initCoreServices().

◆ usb_cdc_print()

size_t usb_cdc_print ( const char * str)

Writes null-terminated string to USB CDC.

Write string to USB CDC

Parameters
strNull-terminated string
Returns
Number of bytes written
Parameters
strString to write.
Returns
Number of bytes written.

Definition at line 234 of file usb_cdc.cpp.

References usb_cdc_write().

◆ usb_cdc_read()

size_t usb_cdc_read ( uint8_t * data,
size_t len )

Reads bytes from USB CDC endpoint.

Read data from USB CDC (non-blocking)

Parameters
dataBuffer for received data
lenMaximum bytes to read
Returns
Number of bytes read (0 if no data)
Parameters
dataOutput buffer.
lenMaximum bytes to read.
Returns
Number of bytes read.

Definition at line 245 of file usb_cdc.cpp.

References g_usb_started.

◆ usb_cdc_ready()

bool usb_cdc_ready ( void )

Returns whether USB CDC is connected and ready.

Check if USB CDC is ready for I/O

Returns
true if connected and ready
true if host CDC connection is active.

Definition at line 196 of file usb_cdc.cpp.

References g_usb_started.

◆ usb_cdc_start()

bool usb_cdc_start ( void )

Starts USB CDC runtime (or triggers re-enumeration in early-debug mode).

Start USB stack (only needed when CONFIG_USB_EARLY_DEBUG is disabled) Call this after all modules have registered their USB interfaces.

Returns
true if successful
true if USB is running after call.

Definition at line 166 of file usb_cdc.cpp.

References g_usb_prepared, g_usb_started, LOG_I, TAG, and usb_start_stack().

Referenced by startApp().

◆ usb_cdc_write()

size_t usb_cdc_write ( const uint8_t * data,
size_t len )

Writes byte buffer to USB CDC endpoint.

Write data to USB CDC

Parameters
dataData to write
lenData length
Returns
Number of bytes written
Parameters
dataData buffer.
lenNumber of bytes to write.
Returns
Number of bytes written.

Definition at line 206 of file usb_cdc.cpp.

References g_usb_started.

Referenced by host_usb_cdc_write(), and usb_cdc_print().