Struct usbd_serial::CdcAcmClass
source · 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 aWouldBlock
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 aWouldBlock
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>
impl<'a, B: UsbBus> CdcAcmClass<'a, B>
sourcepub fn new<'alloc: 'a>(
alloc: &'alloc UsbBusAllocator<B>,
max_packet_size: u16
) -> CdcAcmClass<'a, B>
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.
sourcepub 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>
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.
sourcepub fn max_packet_size(&self) -> u16
pub fn max_packet_size(&self) -> u16
Gets the maximum packet size in bytes.
sourcepub fn line_coding(&self) -> &LineCoding
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.
sourcepub fn write_packet(&mut self, data: &[u8]) -> Result<usize>
pub fn write_packet(&mut self, data: &[u8]) -> Result<usize>
Writes a single packet into the IN endpoint.
sourcepub fn read_packet(&mut self, data: &mut [u8]) -> Result<usize>
pub fn read_packet(&mut self, data: &mut [u8]) -> Result<usize>
Reads a single packet from the OUT endpoint.
sourcepub fn write_ep(&self) -> &EndpointIn<'a, B>
pub fn write_ep(&self) -> &EndpointIn<'a, B>
Gets the IN endpoint.
sourcepub fn write_ep_mut(&mut self) -> &mut EndpointIn<'a, B>
pub fn write_ep_mut(&mut self) -> &mut EndpointIn<'a, B>
Mutably gets the IN endpoint.
sourcepub fn read_ep(&self) -> &EndpointOut<'a, B>
pub fn read_ep(&self) -> &EndpointOut<'a, B>
Gets the OUT endpoint.
sourcepub fn read_ep_mut(&mut self) -> &mut EndpointOut<'a, B>
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>
impl<B: UsbBus> UsbClass<B> for CdcAcmClass<'_, B>
source§fn get_configuration_descriptors(
&self,
writer: &mut DescriptorWriter<'_>
) -> Result<()>
fn get_configuration_descriptors( &self, writer: &mut DescriptorWriter<'_> ) -> Result<()>
writer
. The configuration descriptor itself will be written by
UsbDevice and shouldn’t be written by classes. Read moresource§fn get_string(&self, index: StringIndex, _lang_id: LangID) -> Option<&str>
fn get_string(&self, index: StringIndex, _lang_id: LangID) -> Option<&str>
source§fn control_in(&mut self, xfer: ControlIn<'_, '_, '_, B>)
fn control_in(&mut self, xfer: ControlIn<'_, '_, '_, B>)
source§fn control_out(&mut self, xfer: ControlOut<'_, '_, '_, B>)
fn control_out(&mut self, xfer: ControlOut<'_, '_, '_, B>)
source§fn get_bos_descriptors(
&self,
writer: &mut BosWriter<'_, '_>
) -> Result<(), UsbError>
fn get_bos_descriptors( &self, writer: &mut BosWriter<'_, '_> ) -> Result<(), UsbError>
writer
. The BOS descriptor itself will be written by
UsbDevice and shouldn’t be written by classes.source§fn endpoint_setup(&mut self, addr: EndpointAddress)
fn endpoint_setup(&mut self, addr: EndpointAddress)
addr
has received a SETUP packet. Implementing this
shouldn’t be necessary in most cases, but is provided for completeness’ sake. Read moresource§fn endpoint_out(&mut self, addr: EndpointAddress)
fn endpoint_out(&mut self, addr: EndpointAddress)
addr
has received data (OUT packet). Read moresource§fn endpoint_in_complete(&mut self, addr: EndpointAddress)
fn endpoint_in_complete(&mut self, addr: EndpointAddress)
addr
has completed transmitting data (IN packet). Read more