embassy-usb-host

Crates

git

Versions

default

Flavors

Cp210xPort

Struct Cp210xPort 

Source
pub struct Cp210xPort<'dev, 'd, A, M = NoopRawMutex>
where A: UsbHostAllocator<'d>, M: RawMutex,
{ /* private fields */ }
Expand description

A single UART port on a Cp210xDevice.

Owns the bulk IN/OUT pipes for one interface and borrows the device for control requests.

Implementations§

Source§

impl<'dev, 'd, A, M> Cp210xPort<'dev, 'd, A, M>
where A: UsbHostAllocator<'d>, M: RawMutex,

Source

pub fn interface(&self) -> u8

USB interface number this port is bound to.

Source

pub async fn enable(&mut self) -> Result<(), Cp210xError>

Enable the UART interface.

Issues IFC_ENABLE(1).

Source

pub async fn disable(&mut self) -> Result<(), Cp210xError>

Disable the UART interface.

Issues IFC_ENABLE(0).

Source

pub async fn set_baud_rate(&mut self, baud: u32) -> Result<(), Cp210xError>

Program the UART baud rate in bauds per second.

Issues SET_BAUDRATE, or SET_BAUDDIV with a rounded divisor of the 3.6864 MHz baud-rate generator clock on legacy firmware that stalls the modern request (CP2101, early CP2102/3). The flavour is probed on the first baud-rate call and cached on the device.

Source

pub async fn baud_rate(&mut self) -> Result<u32, Cp210xError>

Read the UART baud rate in bauds per second.

Issues GET_BAUDRATE, falling back to GET_BAUDDIV (divided out through the 3.6864 MHz baud-rate generator clock) on legacy firmware that stalls the modern request.

Source

pub async fn set_line_coding( &mut self, coding: &LineCoding, ) -> Result<(), Cp210xError>

Program baud rate, data/stop bits and parity.

Issues SET_LINE_CTL followed by set_baud_rate.

§Cancellation

Not cancel-safe: dropping the future between the two control transfers leaves the device with the new framing but the old baud rate. Re-issue the full line coding before resuming data transfer.

Source

pub async fn line_coding(&mut self) -> Result<LineCoding, Cp210xError>

Read baud rate, data/stop bits and parity.

Issues GET_LINE_CTL followed by baud_rate.

Source

pub async fn set_control_line_state( &mut self, dtr: bool, rts: bool, ) -> Result<(), Cp210xError>

Drive DTR and RTS to the given levels.

Issues SET_MHS asserting both DTR and RTS masks, overriding any DtrMode::FlowControl or RtsMode::FlowControl setting until the next flow-control event.

Source

pub async fn modem_status(&mut self) -> Result<ModemStatus, Cp210xError>

Read the modem status lines.

Issues GET_MDMSTS. Reserved bits 2 and 3 of the response are discarded.

Source

pub async fn set_break(&mut self, asserted: bool) -> Result<(), Cp210xError>

Assert or release a break condition on TX.

Issues SET_BREAK.

Source

pub async fn purge(&mut self, mask: PurgeMask) -> Result<(), Cp210xError>

Clear the selected TX and/or RX queues.

Issues PURGE with the given mask. On CP2102N this also clears the current SET_FLOW configuration; re-apply flow control afterwards if needed.

Source

pub async fn set_flow_control( &mut self, fc: &FlowControl, ) -> Result<(), Cp210xError>

Apply a flow-control configuration.

Issues SET_FLOW. For bits not covered by FlowControl, use set_flow_control_raw.

Source

pub async fn set_flow_control_raw( &mut self, raw: &[u8; 16], ) -> Result<(), Cp210xError>

Apply a raw flow-control configuration.

Issues SET_FLOW with the given payload. Layout is little-endian ulControlHandshake | ulFlowReplace | ulXonLimit | ulXoffLimit (4 B each); see AN571 Tables 9–11.

Source

pub async fn flow_control(&mut self) -> Result<FlowControl, Cp210xError>

Read the flow-control configuration.

Issues GET_FLOW.

Source

pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Cp210xError>

Read bytes from the UART receive stream.

§Cancellation

Not cancel-safe: bytes already received from the device but not yet copied into buf are lost if the future is dropped.

Source

pub async fn write(&mut self, data: &[u8]) -> Result<usize, Cp210xError>

Write bytes to the UART transmit stream.

§Cancellation

Not cancel-safe: the remote may observe partial data if the future is dropped mid-transfer.

Trait Implementations§

Source§

impl<'dev, 'd, A, M> ErrorType for Cp210xPort<'dev, 'd, A, M>
where A: UsbHostAllocator<'d>, M: RawMutex,

Source§

type Error = Cp210xError

Error type of all the IO operations on this type.
Source§

impl<'dev, 'd, A, M> Read for Cp210xPort<'dev, 'd, A, M>
where A: UsbHostAllocator<'d>, M: RawMutex,

Source§

async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
Source§

impl<'dev, 'd, A, M> Write for Cp210xPort<'dev, 'd, A, M>
where A: UsbHostAllocator<'d>, M: RawMutex,

Source§

async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

async fn flush(&mut self) -> Result<(), Self::Error>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Source§

async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more

Auto Trait Implementations§

§

impl<'dev, 'd, A, M> Freeze for Cp210xPort<'dev, 'd, A, M>
where <A as UsbHostAllocator<'d>>::Pipe<Bulk, In>: Freeze, <A as UsbHostAllocator<'d>>::Pipe<Bulk, Out>: Freeze,

§

impl<'dev, 'd, A, M = NoopRawMutex> !RefUnwindSafe for Cp210xPort<'dev, 'd, A, M>

§

impl<'dev, 'd, A, M> Send for Cp210xPort<'dev, 'd, A, M>
where <A as UsbHostAllocator<'d>>::Pipe<Bulk, In>: Send, <A as UsbHostAllocator<'d>>::Pipe<Bulk, Out>: Send, A: Sync, M: Sync, <A as UsbHostAllocator<'d>>::Pipe<Control, InOut>: Send,

§

impl<'dev, 'd, A, M> Sync for Cp210xPort<'dev, 'd, A, M>
where <A as UsbHostAllocator<'d>>::Pipe<Bulk, In>: Sync, <A as UsbHostAllocator<'d>>::Pipe<Bulk, Out>: Sync, A: Sync, M: Sync, <A as UsbHostAllocator<'d>>::Pipe<Control, InOut>: Send,

§

impl<'dev, 'd, A, M> Unpin for Cp210xPort<'dev, 'd, A, M>
where <A as UsbHostAllocator<'d>>::Pipe<Bulk, In>: Unpin, <A as UsbHostAllocator<'d>>::Pipe<Bulk, Out>: Unpin,

§

impl<'dev, 'd, A, M = NoopRawMutex> !UnwindSafe for Cp210xPort<'dev, 'd, A, M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.