aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/usb
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-stm32/src/usb
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/usb')
-rw-r--r--embassy-stm32/src/usb/otg.rs76
-rw-r--r--embassy-stm32/src/usb/usb.rs23
2 files changed, 46 insertions, 53 deletions
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs
index d3c7978e4..51429b8cc 100644
--- a/embassy-stm32/src/usb/otg.rs
+++ b/embassy-stm32/src/usb/otg.rs
@@ -1,6 +1,6 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use embassy_hal_internal::{into_ref, Peripheral}; 3use embassy_hal_internal::PeripheralType;
4use embassy_usb_driver::{EndpointAddress, EndpointAllocError, EndpointType, Event, Unsupported}; 4use embassy_usb_driver::{EndpointAddress, EndpointAllocError, EndpointType, Event, Unsupported};
5use embassy_usb_synopsys_otg::otg_v1::vals::Dspd; 5use embassy_usb_synopsys_otg::otg_v1::vals::Dspd;
6use embassy_usb_synopsys_otg::otg_v1::Otg; 6use embassy_usb_synopsys_otg::otg_v1::Otg;
@@ -11,9 +11,9 @@ use embassy_usb_synopsys_otg::{
11}; 11};
12 12
13use crate::gpio::{AfType, OutputType, Speed}; 13use crate::gpio::{AfType, OutputType, Speed};
14use crate::interrupt;
15use crate::interrupt::typelevel::Interrupt; 14use crate::interrupt::typelevel::Interrupt;
16use crate::rcc::{self, RccPeripheral}; 15use crate::rcc::{self, RccPeripheral};
16use crate::{interrupt, Peri};
17 17
18const MAX_EP_COUNT: usize = 9; 18const MAX_EP_COUNT: usize = 9;
19 19
@@ -32,8 +32,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
32 32
33macro_rules! config_ulpi_pins { 33macro_rules! config_ulpi_pins {
34 ($($pin:ident),*) => { 34 ($($pin:ident),*) => {
35 into_ref!($($pin),*); 35 critical_section::with(|_| {
36 critical_section::with(|_| {
37 $( 36 $(
38 $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); 37 $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
39 )* 38 )*
@@ -62,15 +61,13 @@ impl<'d, T: Instance> Driver<'d, T> {
62 /// Must be large enough to fit all OUT endpoint max packet sizes. 61 /// Must be large enough to fit all OUT endpoint max packet sizes.
63 /// Endpoint allocation will fail if it is too small. 62 /// Endpoint allocation will fail if it is too small.
64 pub fn new_fs( 63 pub fn new_fs(
65 _peri: impl Peripheral<P = T> + 'd, 64 _peri: Peri<'d, T>,
66 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 65 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
67 dp: impl Peripheral<P = impl DpPin<T>> + 'd, 66 dp: Peri<'d, impl DpPin<T>>,
68 dm: impl Peripheral<P = impl DmPin<T>> + 'd, 67 dm: Peri<'d, impl DmPin<T>>,
69 ep_out_buffer: &'d mut [u8], 68 ep_out_buffer: &'d mut [u8],
70 config: Config, 69 config: Config,
71 ) -> Self { 70 ) -> Self {
72 into_ref!(dp, dm);
73
74 dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); 71 dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
75 dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); 72 dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
76 73
@@ -100,17 +97,16 @@ impl<'d, T: Instance> Driver<'d, T> {
100 /// Must be large enough to fit all OUT endpoint max packet sizes. 97 /// Must be large enough to fit all OUT endpoint max packet sizes.
101 /// Endpoint allocation will fail if it is too small. 98 /// Endpoint allocation will fail if it is too small.
102 pub fn new_hs( 99 pub fn new_hs(
103 _peri: impl Peripheral<P = T> + 'd, 100 _peri: Peri<'d, T>,
104 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 101 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
105 _dp: impl Peripheral<P = impl DpPin<T>> + 'd, 102 _dp: Peri<'d, impl DpPin<T>>,
106 _dm: impl Peripheral<P = impl DmPin<T>> + 'd, 103 _dm: Peri<'d, impl DmPin<T>>,
107 ep_out_buffer: &'d mut [u8], 104 ep_out_buffer: &'d mut [u8],
108 config: Config, 105 config: Config,
109 ) -> Self { 106 ) -> Self {
110 // For STM32U5 High speed pins need to be left in analog mode 107 // For STM32U5 High speed pins need to be left in analog mode
111 #[cfg(not(all(stm32u5, peri_usb_otg_hs)))] 108 #[cfg(not(all(stm32u5, peri_usb_otg_hs)))]
112 { 109 {
113 into_ref!(_dp, _dm);
114 _dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); 110 _dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
115 _dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); 111 _dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
116 } 112 }
@@ -139,20 +135,20 @@ impl<'d, T: Instance> Driver<'d, T> {
139 /// Must be large enough to fit all OUT endpoint max packet sizes. 135 /// Must be large enough to fit all OUT endpoint max packet sizes.
140 /// Endpoint allocation will fail if it is too small. 136 /// Endpoint allocation will fail if it is too small.
141 pub fn new_fs_ulpi( 137 pub fn new_fs_ulpi(
142 _peri: impl Peripheral<P = T> + 'd, 138 _peri: Peri<'d, T>,
143 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 139 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
144 ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd, 140 ulpi_clk: Peri<'d, impl UlpiClkPin<T>>,
145 ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd, 141 ulpi_dir: Peri<'d, impl UlpiDirPin<T>>,
146 ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd, 142 ulpi_nxt: Peri<'d, impl UlpiNxtPin<T>>,
147 ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd, 143 ulpi_stp: Peri<'d, impl UlpiStpPin<T>>,
148 ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd, 144 ulpi_d0: Peri<'d, impl UlpiD0Pin<T>>,
149 ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd, 145 ulpi_d1: Peri<'d, impl UlpiD1Pin<T>>,
150 ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd, 146 ulpi_d2: Peri<'d, impl UlpiD2Pin<T>>,
151 ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd, 147 ulpi_d3: Peri<'d, impl UlpiD3Pin<T>>,
152 ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd, 148 ulpi_d4: Peri<'d, impl UlpiD4Pin<T>>,
153 ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd, 149 ulpi_d5: Peri<'d, impl UlpiD5Pin<T>>,
154 ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd, 150 ulpi_d6: Peri<'d, impl UlpiD6Pin<T>>,
155 ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd, 151 ulpi_d7: Peri<'d, impl UlpiD7Pin<T>>,
156 ep_out_buffer: &'d mut [u8], 152 ep_out_buffer: &'d mut [u8],
157 config: Config, 153 config: Config,
158 ) -> Self { 154 ) -> Self {
@@ -185,20 +181,20 @@ impl<'d, T: Instance> Driver<'d, T> {
185 /// Must be large enough to fit all OUT endpoint max packet sizes. 181 /// Must be large enough to fit all OUT endpoint max packet sizes.
186 /// Endpoint allocation will fail if it is too small. 182 /// Endpoint allocation will fail if it is too small.
187 pub fn new_hs_ulpi( 183 pub fn new_hs_ulpi(
188 _peri: impl Peripheral<P = T> + 'd, 184 _peri: Peri<'d, T>,
189 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 185 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
190 ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd, 186 ulpi_clk: Peri<'d, impl UlpiClkPin<T>>,
191 ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd, 187 ulpi_dir: Peri<'d, impl UlpiDirPin<T>>,
192 ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd, 188 ulpi_nxt: Peri<'d, impl UlpiNxtPin<T>>,
193 ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd, 189 ulpi_stp: Peri<'d, impl UlpiStpPin<T>>,
194 ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd, 190 ulpi_d0: Peri<'d, impl UlpiD0Pin<T>>,
195 ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd, 191 ulpi_d1: Peri<'d, impl UlpiD1Pin<T>>,
196 ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd, 192 ulpi_d2: Peri<'d, impl UlpiD2Pin<T>>,
197 ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd, 193 ulpi_d3: Peri<'d, impl UlpiD3Pin<T>>,
198 ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd, 194 ulpi_d4: Peri<'d, impl UlpiD4Pin<T>>,
199 ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd, 195 ulpi_d5: Peri<'d, impl UlpiD5Pin<T>>,
200 ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd, 196 ulpi_d6: Peri<'d, impl UlpiD6Pin<T>>,
201 ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd, 197 ulpi_d7: Peri<'d, impl UlpiD7Pin<T>>,
202 ep_out_buffer: &'d mut [u8], 198 ep_out_buffer: &'d mut [u8],
203 config: Config, 199 config: Config,
204 ) -> Self { 200 ) -> Self {
@@ -411,7 +407,7 @@ trait SealedInstance {
411 407
412/// USB instance trait. 408/// USB instance trait.
413#[allow(private_bounds)] 409#[allow(private_bounds)]
414pub trait Instance: SealedInstance + RccPeripheral + 'static { 410pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static {
415 /// Interrupt for this USB instance. 411 /// Interrupt for this USB instance.
416 type Interrupt: interrupt::typelevel::Interrupt; 412 type Interrupt: interrupt::typelevel::Interrupt;
417} 413}
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index 6682374d3..0b878915a 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -5,7 +5,7 @@ use core::marker::PhantomData;
5use core::sync::atomic::{AtomicBool, Ordering}; 5use core::sync::atomic::{AtomicBool, Ordering};
6use core::task::Poll; 6use core::task::Poll;
7 7
8use embassy_hal_internal::into_ref; 8use embassy_hal_internal::PeripheralType;
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10use embassy_usb_driver as driver; 10use embassy_usb_driver as driver;
11use embassy_usb_driver::{ 11use embassy_usb_driver::{
@@ -16,7 +16,7 @@ use crate::pac::usb::regs;
16use crate::pac::usb::vals::{EpType, Stat}; 16use crate::pac::usb::vals::{EpType, Stat};
17use crate::pac::USBRAM; 17use crate::pac::USBRAM;
18use crate::rcc::RccPeripheral; 18use crate::rcc::RccPeripheral;
19use crate::{interrupt, Peripheral}; 19use crate::{interrupt, Peri};
20 20
21/// Interrupt handler. 21/// Interrupt handler.
22pub struct InterruptHandler<T: Instance> { 22pub struct InterruptHandler<T: Instance> {
@@ -290,13 +290,12 @@ impl<'d, T: Instance> Driver<'d, T> {
290 /// Create a new USB driver with start-of-frame (SOF) output. 290 /// Create a new USB driver with start-of-frame (SOF) output.
291 #[cfg(not(stm32l1))] 291 #[cfg(not(stm32l1))]
292 pub fn new_with_sof( 292 pub fn new_with_sof(
293 _usb: impl Peripheral<P = T> + 'd, 293 _usb: Peri<'d, T>,
294 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 294 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
295 dp: impl Peripheral<P = impl DpPin<T>> + 'd, 295 dp: Peri<'d, impl DpPin<T>>,
296 dm: impl Peripheral<P = impl DmPin<T>> + 'd, 296 dm: Peri<'d, impl DmPin<T>>,
297 sof: impl Peripheral<P = impl SofPin<T>> + 'd, 297 sof: Peri<'d, impl SofPin<T>>,
298 ) -> Self { 298 ) -> Self {
299 into_ref!(sof);
300 { 299 {
301 use crate::gpio::{AfType, OutputType, Speed}; 300 use crate::gpio::{AfType, OutputType, Speed};
302 sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); 301 sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
@@ -307,13 +306,11 @@ impl<'d, T: Instance> Driver<'d, T> {
307 306
308 /// Create a new USB driver. 307 /// Create a new USB driver.
309 pub fn new( 308 pub fn new(
310 _usb: impl Peripheral<P = T> + 'd, 309 _usb: Peri<'d, T>,
311 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 310 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
312 dp: impl Peripheral<P = impl DpPin<T>> + 'd, 311 dp: Peri<'d, impl DpPin<T>>,
313 dm: impl Peripheral<P = impl DmPin<T>> + 'd, 312 dm: Peri<'d, impl DmPin<T>>,
314 ) -> Self { 313 ) -> Self {
315 into_ref!(dp, dm);
316
317 super::common_init::<T>(); 314 super::common_init::<T>();
318 315
319 let regs = T::regs(); 316 let regs = T::regs();
@@ -1236,7 +1233,7 @@ trait SealedInstance {
1236 1233
1237/// USB instance trait. 1234/// USB instance trait.
1238#[allow(private_bounds)] 1235#[allow(private_bounds)]
1239pub trait Instance: SealedInstance + RccPeripheral + 'static { 1236pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static {
1240 /// Interrupt for this USB instance. 1237 /// Interrupt for this USB instance.
1241 type Interrupt: interrupt::typelevel::Interrupt; 1238 type Interrupt: interrupt::typelevel::Interrupt;
1242} 1239}