Skip to main content

UsbBus

Struct UsbBus 

Source
pub struct UsbBus { /* private fields */ }

Implementations§

Source§

impl UsbBus

Source

pub fn new( _clock: &UsbClock, pm: &mut Pm, dm_pad: impl AnyPin<Id = PA24>, dp_pad: impl AnyPin<Id = PA25>, _usb: Usb, ) -> Self

Source§

impl UsbBus

Source

pub fn enable_sof_interrupt(&self)

Enables the Start Of Frame (SOF) interrupt

Source

pub fn disable_sof_interrupt(&self)

Disables the Start Of Frame (SOF) interrupt

Source

pub fn check_sof_interrupt(&self) -> bool

Checks, and clears if set, the Start Of Frame (SOF) interrupt flag

Source

pub fn configure_out_endpoint_multipacket_rx( &self, ep: EndpointAddress, size: u16, ) -> Result<(), UsbError>

Configures the Multi-Packet-Rx feature of the USB peripheral.

This allows for the USB Peripheral to ACK multiple incomming packets in hardware, and then only fire an interrupt once the buffer is full. This will reduce the number of USB interrupts, especially when dealing with BULK endpoints.

The default behaviour of the endpoint is to trigger an interrupt as soon as any amount of data is received (size = 0).

The Buffer size can be configured using the HAL’s feature flags:

Feature flagEndpoint buffer sizeMax number of hardware ACK packets
usb-buffer-1k641
usb-buffer-2k1282
usb-buffer-4k2564
usb-buffer-8k5128
usb-buffer-16k102416

NOTE: Above table assumes a 64 byte packet size (USB FS Standard)

§Requirements
  1. size is less than the allocated buffer of the endpoint.
  2. size is a multiple of the endpoints packet size.
  3. The provided ep is an OUT endpoint.
§Notes
  • For IN endpoints, multi-packet transfer is automatically handled without any user input.
  • If less than size bytes are received by the endpoint, then it will NOT fire an interrupt.
  • ZLP packets still result in an interrupt being fired, regardless of the endpoints received data length

Trait Implementations§

Source§

impl UsbBus for UsbBus

Source§

fn enable(&mut self)

Enables and initializes the USB peripheral. Soon after enabling the device will be reset, so there is no need to perform a USB reset in this method.
Source§

fn reset(&self)

Called when the host resets the device. This will be soon called after poll returns PollResult::Reset. This method should reset the state of all endpoints and peripheral flags back to a state suitable for enumeration, as well as ensure that all endpoints previously allocated with alloc_ep are initialized as specified.
Source§

fn suspend(&self)

Causes the USB peripheral to enter USB suspend mode, lowering power consumption and preparing to detect a USB wakeup event. This will be called after poll returns PollResult::Suspend. The device will continue be polled, and it shall return a value other than Suspend from poll when it no longer detects the suspend condition.
Source§

fn resume(&self)

Resumes from suspend mode. This may only be called after the peripheral has been previously suspended.
Source§

fn alloc_ep( &mut self, dir: UsbDirection, addr: Option<EndpointAddress>, ep_type: EndpointType, max_packet_size: u16, interval: u8, ) -> UsbResult<EndpointAddress>

Allocates an endpoint and specified endpoint parameters. This method is called by the device and class implementations to allocate endpoints, and can only be called before enable is called. Read more
Source§

fn set_device_address(&self, addr: u8)

Sets the device USB address to addr.
Source§

fn poll(&self) -> PollResult

Gets information about events and incoming data. Usually called in a loop or from an interrupt handler. See the PollResult struct for more information.
Source§

fn write(&self, ep: EndpointAddress, buf: &[u8]) -> UsbResult<usize>

Writes a single packet of data to the specified endpoint and returns number of bytes actually written. Read more
Source§

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

Reads a single packet of data from the specified endpoint and returns the actual length of the packet. Read more
Source§

fn set_stalled(&self, ep: EndpointAddress, stalled: bool)

Sets or clears the STALL condition for an endpoint. If the endpoint is an OUT endpoint, it should be prepared to receive data again.
Source§

fn is_stalled(&self, ep: EndpointAddress) -> bool

Gets whether the STALL condition is set for an endpoint.
Source§

fn force_reset(&self) -> Result<(), UsbError>

Simulates a disconnect from the USB bus, causing the host to reset and re-enumerate the device. Read more
Source§

const QUIRK_SET_ADDRESS_BEFORE_STATUS: bool = false

Indicates that set_device_address must be called before accepting the corresponding control transfer, not after. Read more

Auto Trait Implementations§

§

impl !Freeze for UsbBus

§

impl !RefUnwindSafe for UsbBus

§

impl !UnwindSafe for UsbBus

§

impl Send for UsbBus

§

impl Sync for UsbBus

§

impl Unpin for UsbBus

§

impl UnsafeUnpin for UsbBus

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> Same for T

Source§

type Output = T

Should always be Self
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.