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

Packet level implementation of a CDC-ACM serial port.

This class can be used directly and it has the least overhead due to directly reading and writing USB packets with no intermediate buffers, but it will not act like a stream-like serial port. The following constraints must be followed if you use this class directly:

  • read_packet must be called with a buffer large enough to hold max_packet_size bytes, and the method will return a WouldBlock error if there is no packet to be read.
  • write_packet must not be called with a buffer larger than max_packet_size bytes, and the method will return a WouldBlock error if the previous packet has not been sent yet.
  • If you write a packet that is exactly max_packet_size bytes long, it won’t be processed by the host operating system until a subsequent shorter packet is sent. A zero-length packet (ZLP) can be sent if there is no other data to send. This is because USB bulk transactions must be terminated with a short packet, even if the bulk endpoint is used for stream-like data.

Implementations§

source§

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

source

pub fn new<'alloc: 'a>( alloc: &'alloc UsbBusAllocator<B>, max_packet_size: u16 ) -> CdcAcmClass<'a, B>

Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64.

source

pub fn new_with_interface_names<'alloc: 'a>( alloc: &'alloc UsbBusAllocator<B>, max_packet_size: u16, comm_if_name: Option<&'static str>, data_if_name: Option<&'static str> ) -> CdcAcmClass<'a, B>

Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64. Additionally, this lets you specify optional names for the CDC interfaces, to better organize composite devices.

source

pub fn max_packet_size(&self) -> u16

Gets the maximum packet size in bytes.

source

pub fn line_coding(&self) -> &LineCoding

Gets the current line coding. The line coding contains information that’s mainly relevant for USB to UART serial port emulators, and can be ignored if not relevant.

source

pub fn dtr(&self) -> bool

Gets the DTR (data terminal ready) state

source

pub fn rts(&self) -> bool

Gets the RTS (request to send) state

source

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

Writes a single packet into the IN endpoint.

source

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

Reads a single packet from the OUT endpoint.

source

pub fn write_ep(&self) -> &EndpointIn<'a, B>

Gets the IN endpoint.

source

pub fn write_ep_mut(&mut self) -> &mut EndpointIn<'a, B>

Mutably gets the IN endpoint.

source

pub fn read_ep(&self) -> &EndpointOut<'a, B>

Gets the OUT endpoint.

source

pub fn read_ep_mut(&mut self) -> &mut EndpointOut<'a, B>

Mutably gets the OUT endpoint.

Trait Implementations§

source§

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

source§

fn get_configuration_descriptors( &self, writer: &mut DescriptorWriter<'_> ) -> Result<()>

Called when a GET_DESCRIPTOR request is received for a configuration descriptor. When called, the implementation should write its interface, endpoint and any extra class descriptors into writer. The configuration descriptor itself will be written by UsbDevice and shouldn’t be written by classes. Read more
source§

fn get_string(&self, index: StringIndex, _lang_id: LangID) -> Option<&str>

Gets a class-specific string descriptor. Read more
source§

fn reset(&mut self)

Called after a USB reset after the bus reset sequence is complete.
source§

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

Called when a control request is received with direction DeviceToHost. Read more
source§

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

Called when a control request is received with direction HostToDevice. Read more
source§

fn get_bos_descriptors( &self, writer: &mut BosWriter<'_, '_> ) -> Result<(), UsbError>

Called when a GET_DESCRIPTOR request is received for a BOS descriptor. When called, the implementation should write its blobs such as capability descriptors into writer. The BOS descriptor itself will be written by UsbDevice and shouldn’t be written by classes.
source§

fn poll(&mut self)

Called whenever the UsbDevice is polled.
source§

fn endpoint_setup(&mut self, addr: EndpointAddress)

Called when endpoint with address addr has received a SETUP packet. Implementing this shouldn’t be necessary in most cases, but is provided for completeness’ sake. Read more
source§

fn endpoint_out(&mut self, addr: EndpointAddress)

Called when endpoint with address addr has received data (OUT packet). Read more
source§

fn endpoint_in_complete(&mut self, addr: EndpointAddress)

Called when endpoint with address addr has completed transmitting data (IN packet). Read more
source§

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

Called when the interfaces alternate setting state is requested. Read more
source§

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

Called when the interfaces alternate setting state is altered. Read more

Auto Trait Implementations§

§

impl<'a, B> RefUnwindSafe for CdcAcmClass<'a, B>

§

impl<'a, B> Send for CdcAcmClass<'a, B>

§

impl<'a, B> Sync for CdcAcmClass<'a, B>

§

impl<'a, B> Unpin for CdcAcmClass<'a, B>

§

impl<'a, B> UnwindSafe for CdcAcmClass<'a, B>

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>,

§

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>,

§

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.