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,
impl<'dev, 'd, A, M> Cp210xPort<'dev, 'd, A, M>where
A: UsbHostAllocator<'d>,
M: RawMutex,
Sourcepub async fn enable(&mut self) -> Result<(), Cp210xError>
pub async fn enable(&mut self) -> Result<(), Cp210xError>
Enable the UART interface.
Issues IFC_ENABLE(1).
Sourcepub async fn disable(&mut self) -> Result<(), Cp210xError>
pub async fn disable(&mut self) -> Result<(), Cp210xError>
Disable the UART interface.
Issues IFC_ENABLE(0).
Sourcepub async fn set_baud_rate(&mut self, baud: u32) -> Result<(), Cp210xError>
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.
Sourcepub async fn baud_rate(&mut self) -> Result<u32, Cp210xError>
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.
Sourcepub async fn set_line_coding(
&mut self,
coding: &LineCoding,
) -> Result<(), Cp210xError>
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.
Sourcepub async fn line_coding(&mut self) -> Result<LineCoding, Cp210xError>
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.
Sourcepub async fn set_control_line_state(
&mut self,
dtr: bool,
rts: bool,
) -> Result<(), Cp210xError>
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.
Sourcepub async fn modem_status(&mut self) -> Result<ModemStatus, Cp210xError>
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.
Sourcepub async fn set_break(&mut self, asserted: bool) -> Result<(), Cp210xError>
pub async fn set_break(&mut self, asserted: bool) -> Result<(), Cp210xError>
Assert or release a break condition on TX.
Issues SET_BREAK.
Sourcepub async fn purge(&mut self, mask: PurgeMask) -> Result<(), Cp210xError>
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.
Sourcepub async fn set_flow_control(
&mut self,
fc: &FlowControl,
) -> Result<(), Cp210xError>
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.
Sourcepub async fn set_flow_control_raw(
&mut self,
raw: &[u8; 16],
) -> Result<(), Cp210xError>
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.
Sourcepub async fn flow_control(&mut self) -> Result<FlowControl, Cp210xError>
pub async fn flow_control(&mut self) -> Result<FlowControl, Cp210xError>
Read the flow-control configuration.
Issues GET_FLOW.
Trait Implementations§
Source§impl<'dev, 'd, A, M> ErrorType for Cp210xPort<'dev, 'd, A, M>where
A: UsbHostAllocator<'d>,
M: RawMutex,
impl<'dev, 'd, A, M> ErrorType for Cp210xPort<'dev, 'd, A, M>where
A: UsbHostAllocator<'d>,
M: RawMutex,
Source§type Error = Cp210xError
type Error = Cp210xError
Source§impl<'dev, 'd, A, M> Read for Cp210xPort<'dev, 'd, A, M>where
A: UsbHostAllocator<'d>,
M: RawMutex,
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>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read more