atomvm_gleam/usb_cdc

Types

Options for open / open_default.

Currently unused by the AtomVM USB CDC drivers; pass default_config. Reserved for future driver options.

pub type Config {
  Config
}

Constructors

  • Config

Errors from the USB CDC driver.

pub type Error {
  Failed
  NotSupported
  Badarg
  Timeout
  Ealready
  Other(String)
}

Constructors

  • Failed
  • NotSupported
  • Badarg
  • Timeout
  • Ealready
  • Other(String)

USB CDC ACM driver wrappers for AtomVM (ESP32 / RP2 / STM32).

Peripheral name strings accepted by open differ by platform:

  • ESP32: CDC interface id such as "CDC0" or "USB0" (default CDC 0 when using open_default).
  • RP2 / STM32: the name is ignored (single CDC interface); prefer open_default.

Upstream (same export shape on each platform): ESP32, RP2, STM32. Implements the uart_hal behaviour over USB CDC. Opaque USB CDC driver handle (port() from usb_cdc:open/1 / open/2).

pub type UsbCdc

Values

pub fn close(usb: UsbCdc) -> Result(Nil, Error)

Close the USB CDC driver.

See usb_cdc:close/1.

pub fn default_config() -> Config

Empty config (driver defaults).

pub fn error_to_string(error: Error) -> String

Format an Error for logging.

pub fn open(
  name: String,
  config: Config,
) -> Result(UsbCdc, Error)

Open a named USB CDC interface ("CDC0" / "USB0" on ESP32).

On RP2 and STM32 the name is ignored (single CDC interface).

See usb_cdc:open/2 on ESP32, RP2, STM32.

pub fn open_default(config: Config) -> Result(UsbCdc, Error)

Open the default USB CDC interface with the given options.

On ESP32 this opens CDC interface 0 when no peripheral is specified. On RP2 / STM32 this opens the single CDC interface.

See usb_cdc:open/1 on ESP32, RP2, STM32.

pub fn read(
  usb: UsbCdc,
  timeout_ms: Int,
) -> Result(BitArray, Error)

Read available data, waiting up to timeout_ms.

See usb_cdc:read/2.

pub fn read_blocking(usb: UsbCdc) -> Result(BitArray, Error)

Read data, blocking until bytes are available.

See usb_cdc:read/1.

pub fn write(usb: UsbCdc, data: BitArray) -> Result(Nil, Error)

Write data to the USB CDC interface.

See usb_cdc:write/2.

✨ Search Document