Skip to content

Commit 59a867b

Browse files
committed
Use contructor to create USB peripheral
This follows the standards established by other peripheral APIs, and prevents the user from messing with the USB peripheral or the pins after initialization.
1 parent f36f97e commit 59a867b

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

examples/usb_serial.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ fn main() -> ! {
2020

2121
let gpioa = dp.GPIOA.split(&mut rcc);
2222

23-
let usb = USB {
24-
usb: dp.USB,
25-
pin_dm: gpioa.pa11,
26-
pin_dp: gpioa.pa12,
27-
};
23+
let usb = USB::new(dp.USB, gpioa.pa11, gpioa.pa12);
2824
let usb_bus = UsbBus::new(usb);
2925

3026
let mut serial = SerialPort::new(&usb_bus);

src/usb.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@ use crate::gpio::gpioa::{PA11, PA12};
1919
use crate::gpio::{Floating, Input};
2020
pub use stm32_usbd::UsbBus;
2121

22-
pub struct USB {
23-
pub usb: pac::USB,
24-
pub pin_dm: PA11<Input<Floating>>,
25-
pub pin_dp: PA12<Input<Floating>>,
22+
23+
pub struct USB(());
24+
25+
impl USB {
26+
pub fn new(
27+
_: pac::USB,
28+
_dm: PA11<Input<Floating>>,
29+
_dp: PA12<Input<Floating>>,
30+
)
31+
-> Self
32+
{
33+
Self(())
34+
}
2635
}
2736

2837
unsafe impl Sync for USB {}

0 commit comments

Comments
 (0)