Trait imxrt_usbd::Peripherals [−][src]
A type that owns all USB register blocks
An implementation of Peripherals
is expected to own the USB1
or USB2 registers. This includes
- USB core registers
- USB PHY registers
- USB non-core registers
- USB analog registers
When an instance of Peripherals
exists, you must make sure that
nothing else, other than the owner of the Peripherals
object,
accesses those registers.
Safety
Peripherals
should only be implemented on a type that
owns the various register blocks required for all USB
operation. Incorrect usage, or failure to ensure exclusive
ownership, could lead to data races and incorrect USB functionality.
By implementing this trait, you ensure that the Instance
identifier is valid for your chip. Not all i.MX RT peripherals
have a USB2 peripheral instance, so you must ensure that the
implementation is correct for your chip.
Example
A safe implementation of Peripherals
that works with the
imxrt-ral
register access layer. Assume that ral
is
shorthand for imxrt_ral
, like
use imxrt_ral as ral;
use ral::usb; struct Peripherals { _usb: ral::usb::Instance, _phy: ral::usbphy::Instance, _nc: ral::usbnc::Instance, _analog: ral::usb_analog::Instance, } impl Peripherals { /// Panics if the instances are already taken fn usb1() -> Peripherals { Self { _usb: ral::usb::USB1::take().unwrap(), _phy: ral::usbphy::USBPHY1::take().unwrap(), _nc: ral::usbnc::USBNC1::take().unwrap(), _analog: ral::usb_analog::USB_ANALOG::take().unwrap(), } } } // This implementation is safe, because a `Peripherals` object // owns the four imxrt-ral instances, which are // guaranteed to be singletons. Given this approach, no one else // can safely access the USB registers. unsafe impl imxrt_usbd::Peripherals for Peripherals { fn instance(&self) -> imxrt_usbd::Instance { imxrt_usbd::Instance::USB1 } } let peripherals = Peripherals::usb1(); let bus = imxrt_usbd::full_speed::BusAdapter::new( peripherals, // Rest of setup... );
Required methods
fn instance(&self) -> Instance
[src]
Returns the instance identifier for the core registers
Warning: some i.MX RT peripherals have only one USB peripheral,
USB1. The behavior is undefined if you return Instance::USB2
on
one of these systems.