|
11 | 11 | use crate::pac::{RCC, USB};
|
12 | 12 | use stm32_usbd::UsbPeripheral;
|
13 | 13 |
|
| 14 | +use crate::gpio; |
14 | 15 | use crate::gpio::gpioa::{PA11, PA12};
|
15 |
| -use crate::gpio::{PushPull, AF14}; |
16 | 16 | pub use stm32_usbd::UsbBus;
|
17 | 17 |
|
| 18 | +/// Trait implemented by all pins that can be the "D-" pin for the USB peripheral |
| 19 | +pub trait DmPin: crate::private::Sealed {} |
| 20 | + |
| 21 | +/// Trait implemented by all pins that can be the "D+" pin for the USB peripheral |
| 22 | +pub trait DpPin: crate::private::Sealed {} |
| 23 | + |
| 24 | +#[cfg(any(feature = "stm32f303xb", feature = "stm32f303xc"))] |
| 25 | +impl DmPin for PA11<gpio::AF14<gpio::PushPull>> {} |
| 26 | + |
| 27 | +#[cfg(any(feature = "stm32f303xb", feature = "stm32f303xc"))] |
| 28 | +impl DpPin for PA12<gpio::AF14<gpio::PushPull>> {} |
| 29 | + |
| 30 | +#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))] |
| 31 | +impl<Mode> DmPin for PA11<Mode> {} |
| 32 | + |
| 33 | +#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))] |
| 34 | +impl<Mode> DpPin for PA12<Mode> {} |
| 35 | + |
18 | 36 | /// USB Peripheral
|
19 | 37 | ///
|
20 | 38 | /// Constructs the peripheral, which
|
21 | 39 | /// than gets passed to the [`UsbBus`].
|
22 |
| -pub struct Peripheral { |
| 40 | +pub struct Peripheral<Dm: DmPin, Dp: DpPin> { |
23 | 41 | /// USB Register Block
|
24 | 42 | pub usb: USB,
|
25 | 43 | /// Data Negativ Pin
|
26 |
| - pub pin_dm: PA11<AF14<PushPull>>, |
| 44 | + pub pin_dm: Dm, |
27 | 45 | /// Data Positiv Pin
|
28 |
| - pub pin_dp: PA12<AF14<PushPull>>, |
| 46 | + pub pin_dp: Dp, |
29 | 47 | }
|
30 | 48 |
|
31 |
| -unsafe impl Sync for Peripheral {} |
| 49 | +unsafe impl<Dm: DmPin, Dp: DpPin> Sync for Peripheral<Dm, Dp> {} |
32 | 50 |
|
33 |
| -unsafe impl UsbPeripheral for Peripheral { |
| 51 | +unsafe impl<Dm: DmPin + Send, Dp: DpPin + Send> UsbPeripheral for Peripheral<Dm, Dp> { |
34 | 52 | const REGISTERS: *const () = USB::ptr() as *const ();
|
35 | 53 | const DP_PULL_UP_FEATURE: bool = false;
|
36 | 54 | const EP_MEMORY: *const () = 0x4000_6000 as _;
|
@@ -65,7 +83,10 @@ unsafe impl UsbPeripheral for Peripheral {
|
65 | 83 | }
|
66 | 84 |
|
67 | 85 | /// Type of the UsbBus
|
68 |
| -/// |
69 |
| -/// As this MCU family has only USB peripheral, |
70 |
| -/// this is the only possible concrete type construction. |
71 |
| -pub type UsbBusType = UsbBus<Peripheral>; |
| 86 | +#[cfg(any(feature = "stm32f303xb", feature = "stm32f303xc"))] |
| 87 | +pub type UsbBusType<Dm = PA11<gpio::AF14<gpio::PushPull>>, Dp = PA12<gpio::AF14<gpio::PushPull>>> = |
| 88 | + UsbBus<Peripheral<Dm, Dp>>; |
| 89 | + |
| 90 | +/// Type of the UsbBus |
| 91 | +#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))] |
| 92 | +pub type UsbBusType<Dm = PA11<gpio::Input>, Dp = PA12<gpio::Input>> = UsbBus<Peripheral<Dm, Dp>>; |
0 commit comments