Struct stm32l4xx_hal::usb::UsbBus
source · [−]pub struct UsbBus<USB> { /* private fields */ }
Expand description
USB peripheral driver for STM32 microcontrollers.
Implementations
sourceimpl<USB> UsbBus<USB> where
USB: UsbPeripheral,
impl<USB> UsbBus<USB> where
USB: UsbPeripheral,
sourcepub fn new(peripheral: USB) -> UsbBusAllocator<UsbBus<USB>>
pub fn new(peripheral: USB) -> UsbBusAllocator<UsbBus<USB>>
Constructs a new USB peripheral driver.
pub fn free(self) -> USB
sourcepub fn force_reenumeration<F>(&self, disconnect: F) where
F: FnOnce(),
pub fn force_reenumeration<F>(&self, disconnect: F) where
F: FnOnce(),
Simulates a disconnect from the USB bus, causing the host to reset and re-enumerate the device.
Mostly used for development. By calling this at the start of your program ensures that the host re-enumerates your device after a new program has been flashed.
disconnect
parameter is used to provide a custom disconnect function.
This function will be called with USB peripheral powered down
and interrupts disabled.
It should perform disconnect in a platform-specific way.
Trait Implementations
sourceimpl<USB> UsbBus for UsbBus<USB> where
USB: UsbPeripheral,
impl<USB> UsbBus for UsbBus<USB> where
USB: UsbPeripheral,
sourcefn alloc_ep(
&mut self,
ep_dir: UsbDirection,
ep_addr: Option<EndpointAddress>,
ep_type: EndpointType,
max_packet_size: u16,
_interval: u8
) -> Result<EndpointAddress, UsbError>
fn alloc_ep(
&mut self,
ep_dir: UsbDirection,
ep_addr: Option<EndpointAddress>,
ep_type: EndpointType,
max_packet_size: u16,
_interval: u8
) -> Result<EndpointAddress, UsbError>
sourcefn enable(&mut self)
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. Read more
sourcefn reset(&self)
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. Read more
sourcefn set_device_address(&self, addr: u8)
fn set_device_address(&self, addr: u8)
Sets the device USB address to addr
.
sourcefn poll(&self) -> PollResult
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. Read more
sourcefn write(&self, ep_addr: EndpointAddress, buf: &[u8]) -> Result<usize, UsbError>
fn write(&self, ep_addr: EndpointAddress, buf: &[u8]) -> Result<usize, UsbError>
Writes a single packet of data to the specified endpoint and returns number of bytes actually written. Read more
sourcefn read(
&self,
ep_addr: EndpointAddress,
buf: &mut [u8]
) -> Result<usize, UsbError>
fn read(
&self,
ep_addr: EndpointAddress,
buf: &mut [u8]
) -> Result<usize, UsbError>
Reads a single packet of data from the specified endpoint and returns the actual length of the packet. Read more
sourcefn set_stalled(&self, ep_addr: EndpointAddress, stalled: bool)
fn set_stalled(&self, ep_addr: 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. Read more
sourcefn is_stalled(&self, ep_addr: EndpointAddress) -> bool
fn is_stalled(&self, ep_addr: EndpointAddress) -> bool
Gets whether the STALL condition is set for an endpoint.
sourcefn suspend(&self)
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. Read more
sourcefn resume(&self)
fn resume(&self)
Resumes from suspend mode. This may only be called after the peripheral has been previously suspended. Read more
fn force_reset(&self) -> Result<(), UsbError>
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
const QUIRK_SET_ADDRESS_BEFORE_STATUS: bool
const QUIRK_SET_ADDRESS_BEFORE_STATUS: bool
Indicates that set_device_address
must be called before accepting the corresponding
control transfer, not after. Read more
Auto Trait Implementations
impl<USB> !RefUnwindSafe for UsbBus<USB>
impl<USB> Send for UsbBus<USB> where
USB: Send,
impl<USB> Sync for UsbBus<USB> where
USB: Send + Sync,
impl<USB> Unpin for UsbBus<USB> where
USB: Unpin,
impl<USB> !UnwindSafe for UsbBus<USB>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more