pub struct UsbBus<USB> { /* private fields */ }
Expand description
USB peripheral driver for STM32 microcontrollers.
Implementations§
Source§impl<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.
Sourcepub fn suspend_low_power_mode(&self) -> bool
pub fn suspend_low_power_mode(&self) -> bool
Enter suspend low-power mode
This should be used when in suspend mode if low-power mode needs to be entered during suspend (bus-powered device). Application should call this when it is ready to decrease power consumption to meet power consumption requirements of the USB suspend condition (e.g. disable system clocks or reduce their frequency). When wake up event is received low power mode will be automatically disabled.
Will not enter low-power mode if not in suspend state. Returns true
if entered.
Sourcepub fn remote_wakeup(&self, resume: bool)
pub fn remote_wakeup(&self, resume: bool)
Set/clear remote wakeup bit
Allows to modify CNTR.RESUME bit from device to perform remote wake up from suspend
(e.g. on keyboard/mouse input). To perform remote wake up: when a condition is met
during suspend mode, use this method with true
to set the RESUME bit. Then, after
waiting between 1-15 ms (see reference manual) call it again with false
to clear
the bit.
This method will not set the bit if device is not suspended because performing remote wake up in other mode is invalid and host will most likely disable such a device.
Trait Implementations§
Source§impl<USB> UsbBus for UsbBus<USB>where
USB: UsbPeripheral,
impl<USB> UsbBus for UsbBus<USB>where
USB: UsbPeripheral,
Source§fn 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>
Source§fn enable(&mut self)
fn enable(&mut self)
Source§fn reset(&self)
fn reset(&self)
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 set_device_address(&self, addr: u8)
fn set_device_address(&self, addr: u8)
addr
.Source§fn poll(&self) -> PollResult
fn poll(&self) -> PollResult
PollResult
struct for more information.Source§fn write(&self, ep_addr: EndpointAddress, buf: &[u8]) -> Result<usize, UsbError>
fn write(&self, ep_addr: EndpointAddress, buf: &[u8]) -> Result<usize, UsbError>
Source§fn read(
&self,
ep_addr: EndpointAddress,
buf: &mut [u8],
) -> Result<usize, UsbError>
fn read( &self, ep_addr: EndpointAddress, buf: &mut [u8], ) -> Result<usize, UsbError>
Source§fn set_stalled(&self, ep_addr: EndpointAddress, stalled: bool)
fn set_stalled(&self, ep_addr: EndpointAddress, stalled: bool)
Source§fn is_stalled(&self, ep_addr: EndpointAddress) -> bool
fn is_stalled(&self, ep_addr: EndpointAddress) -> bool
Source§fn suspend(&self)
fn suspend(&self)
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)
fn resume(&self)
Source§fn force_reset(&self) -> Result<(), UsbError>
fn force_reset(&self) -> Result<(), UsbError>
Source§const QUIRK_SET_ADDRESS_BEFORE_STATUS: bool = false
const QUIRK_SET_ADDRESS_BEFORE_STATUS: bool = false
set_device_address
must be called before accepting the corresponding
control transfer, not after. Read more