embassy-usb-host

Crates

git

Versions

default

Flavors

Module cp210x

Module cp210x 

Source
Expand description

Silicon Labs CP210x USB ↔ UART bridge driver.

Implements the AN571 protocol: vendor-class bulk data transport (one bulk IN + one bulk OUT per interface) plus vendor-interface control requests for line coding, flow control, modem signalling and break. Covers single- and multi-port parts.

A Cp210xDevice owns the device-level control pipe on endpoint 0. Each UART interface is then opened as a Cp210xPort that borrows the device; control requests from all ports are serialized through the shared control pipe.

Cp210xDevice::new guards the control pipe with a NoopRawMutex, which is free but !Sync; use it for single-port parts or whenever the device stays in one task. For multi-port parts driven concurrently, use Cp210xDevice::new_with_raw_mutex with a Sync raw mutex such as CriticalSectionRawMutex.

§Example

use embassy_usb_host::class::vcp::cp210x::{Cp210xDevice, LineCoding, Parity, StopBits, id};

if enum_info.device_desc.vendor_id != id::VID_SILABS {
    continue;
}

let device = Cp210xDevice::new(&bus, &enum_info)?;
let mut port = device.port(&config_buf[..config_len], 0)?;
port.enable().await?;
port.set_line_coding(&LineCoding {
    baud_rate: 115200,
    data_bits: 8,
    parity: Parity::None,
    stop_bits: StopBits::One,
}).await?;
port.set_control_line_state(true, true).await?;

let mut buf = [0u8; 64];
let n = port.read(&mut buf).await?;
port.write(&buf[..n]).await?;

Modules§

id
Silicon Labs VID and CP210x PIDs.

Structs§

Cp210xDevice
CP210x device — owns the shared control pipe on endpoint 0.
Cp210xInfo
Descriptor-located info for a single CP210x interface.
Cp210xPort
A single UART port on a Cp210xDevice.
FlowControl
Flow-control configuration (AN571 Tables 9–11).
LineCoding
Serial line parameters.
ModemStatus
Modem status byte returned by GET_MDMSTS (AN571 §5.10).
PurgeMask
Bitmask passed to Cp210xPort::purge (AN571 §5.27).

Enums§

Cp210xError
CP210x host driver error.
DtrMode
DTR output mode (AN571 Table 10, SERIAL_DTR_MASK).
Parity
Parity setting.
RtsMode
RTS output mode (AN571 Table 11, SERIAL_RTS_MASK).
StopBits
Number of stop bits.

Functions§

find_cp210x
Return the nth (0-indexed) vendor-class interface in config_desc that exposes a bulk IN + bulk OUT endpoint pair.