imxrt_usbd/lib.rs
1//! A USB driver for i.MX RT processors
2//!
3//! `imxrt-usbd` provides a [`usb-device`] USB bus implementation, allowing you
4//! to add USB device features to your embedded Rust program. See each module
5//! for usage and examples.
6//!
7//! # General guidance
8//!
9//! The driver does not configure any of the CCM or CCM_ANALOG registers. You are
10//! responsible for configuring these peripherals for proper USB functionality. See
11//! the `imxrt-usbd` hardware examples to see different ways of configuring PLLs and
12//! clocks.
13//!
14//! You, or something in your dependency hierarchy, must enable an `imxrt-ral`
15//! chip feature; otherwise, this package will not build.
16//!
17//! [`usb-device`]: https://crates.io/crates/usb-device
18//!
19//! # Debugging features
20//!
21//! Enable the `defmt` feature to activate internal logging using defmt.
22//!
23//! # Example
24//!
25//! ```no_run
26//! use imxrt_ral as ral;
27//! use imxrt_usbd::{BusAdapter, Instances};
28//!
29//! static EP_MEMORY: imxrt_usbd::EndpointMemory<1024> = imxrt_usbd::EndpointMemory::new();
30//! static EP_STATE: imxrt_usbd::EndpointState = imxrt_usbd::EndpointState::max_endpoints();
31//!
32//! let instances = Instances {
33//! usb: unsafe { ral::usb::USB::instance() },
34//! usbnc: unsafe { ral::usbnc::USBNC::instance() },
35//! usbphy: unsafe { ral::usbphy::USBPHY::instance() },
36//! };
37//!
38//! let bus_adapter = BusAdapter::new(
39//! instances,
40//! &EP_MEMORY,
41//! &EP_STATE,
42//! );
43//! ```
44
45#![no_std]
46#![warn(unsafe_op_in_unsafe_fn)]
47
48#[macro_use]
49mod log;
50
51mod buffer;
52mod bus;
53mod cache;
54mod driver;
55mod endpoint;
56mod qh;
57mod ral;
58mod state;
59mod td;
60mod vcell;
61
62pub use buffer::EndpointMemory;
63pub use bus::{BusAdapter, Speed};
64pub mod gpt;
65pub use state::{EndpointState, MAX_ENDPOINTS};
66
67/// Aggregate of `imxrt-ral` USB peripheral instances.
68///
69/// This takes ownership of USB peripheral instances for a given USB
70/// controller. The const generic `N` ensures that all instances refer
71/// to the same USB peripheral (e.g., USB1 or USB2).
72pub struct Instances<const N: u8> {
73 /// USB core registers.
74 pub usb: imxrt_ral::usb::Instance<N>,
75 /// USB non-core registers.
76 pub usbnc: imxrt_ral::usbnc::Instance<N>,
77 /// USBPHY registers.
78 pub usbphy: imxrt_ral::usbphy::Instance<N>,
79}