Skip to main content

CdcAcm

Struct CdcAcm 

Source
pub struct CdcAcm<'a, B: UsbBus> { /* private fields */ }
Expand description

CDC ACM virtual serial port class.

Construct with CdcAcm::new, passing the UsbBusAllocator.

Implementations§

Source§

impl<'a, B: UsbBus> CdcAcm<'a, B>

Source

pub fn new(alloc: &'a UsbBusAllocator<B>) -> Self

Create a CDC ACM instance, allocating the required endpoints and interfaces.

Bulk endpoints use the bus’s UsbBus::MAX_PACKET_SIZE (64 bytes on full-speed buses, 512 on high-speed ones).

Source

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

Read received bytes from the host into buf.

Returns the number of bytes read, or UsbError::WouldBlock when no data is available.

Source

pub fn write(&self, data: &[u8]) -> UsbResult<usize>

Write one packet to the host.

Returns the number of bytes actually written, or UsbError::WouldBlock when the previous packet has not yet been sent.

A bulk transfer ends on a short packet. When data is exactly the maximum packet size the class sends the terminating zero-length packet itself, from the next UsbClass::poll; the caller does not have to.

Source

pub fn write_all(&self, data: &[u8], budget: u32) -> usize

Queue data, splitting it into endpoint-sized packets.

While the endpoint is busy the call spins, spending one unit of budget per attempt; the budget bounds the time spent waiting for a host that is not collecting. Returns the number of bytes queued.

As with write, a payload that ends on a full packet is terminated with a zero-length packet from the next UsbClass::poll; an empty data queues nothing but that terminator, flushing a previously queued full packet.

Source

pub fn communication_interface(&self) -> InterfaceNumber

The communication interface number.

Source

pub fn data_interface(&self) -> InterfaceNumber

The data interface number.

Source

pub fn dtr(&self) -> bool

true if the host has opened the serial port (DTR set).

Source

pub fn rts(&self) -> bool

true if the host has asserted RTS.

Source

pub fn port_open(&self) -> bool

true if the device is configured and the host has opened the serial port.

Source

pub fn configured(&self) -> bool

true if the device has been configured by the host.

Source

pub fn line_coding(&self) -> LineCoding

Returns the current line coding (baud rate, data bits, etc.).

Trait Implementations§

Source§

impl<B: UsbBus> UsbClass<B> for CdcAcm<'_, B>

Source§

fn poll(&mut self)

Terminate a transfer that ended on a full-size packet.

The host keeps a bulk IN transfer open until it sees a short packet, so a full packet on its own is not delivered to the application yet (Linux cdc_acm, for example, hands an URB over only once it is full).

Source§

fn configuration_descriptors( &self, w: &mut DescriptorWriter<'_>, ) -> UsbResult<()>

Append this class’s interface and endpoint descriptors.
Source§

fn control_in(&mut self, xfer: ControlIn<'_, B>)

Handle a control IN transfer. Accept, reject, or pass (drop without acting).
Source§

fn control_out(&mut self, xfer: ControlOut<'_, B>)

Handle a control OUT transfer. Accept, reject, or pass (drop without acting).
Source§

fn configure(&mut self)

Called when the host sends SET_CONFIGURATION(1).
Source§

fn deconfigure(&mut self)

Called when the host sends SET_CONFIGURATION(0) or on reset.
Source§

fn reset(&mut self)

Called after a USB bus reset.
Source§

fn string(&self, index: StringIndex, lang_id: u16) -> Option<&str>

Return the string for a previously allocated StringIndex, or None.
Source§

fn endpoint_out(&mut self, addr: EndpointAddress)

Called when endpoint addr received an OUT packet.
Source§

fn endpoint_in_complete(&mut self, addr: EndpointAddress)

Called when endpoint addr completed an IN transfer.
Source§

fn endpoint_setup(&mut self, addr: EndpointAddress)

Called when endpoint addr received a SETUP packet (non-EP0 control).
Source§

fn alt_setting(&mut self, interface: InterfaceNumber) -> Option<u8>

Return the current alternate setting for interface, or None.
Source§

fn set_alt_setting(&mut self, interface: InterfaceNumber, alt: u8) -> bool

Set the alternate setting for interface. Return true if handled.

Auto Trait Implementations§

§

impl<'a, B> !Freeze for CdcAcm<'a, B>

§

impl<'a, B> !RefUnwindSafe for CdcAcm<'a, B>

§

impl<'a, B> !Sync for CdcAcm<'a, B>

§

impl<'a, B> Forget for CdcAcm<'a, B>

§

impl<'a, B> Move for CdcAcm<'a, B>

§

impl<'a, B> Send for CdcAcm<'a, B>
where Endpoint<'a, B, In>: Send, Endpoint<'a, B, Out>: Send,

§

impl<'a, B> Unpin for CdcAcm<'a, B>
where Endpoint<'a, B, In>: Unpin, Endpoint<'a, B, Out>: Unpin,

§

impl<'a, B> UnsafeUnpin for CdcAcm<'a, B>
where Endpoint<'a, B, In>: UnsafeUnpin, Endpoint<'a, B, Out>: UnsafeUnpin,

§

impl<'a, B> UnwindSafe for CdcAcm<'a, B>
where Endpoint<'a, B, In>: UnwindSafe, Endpoint<'a, B, Out>: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.