Skip to content

Commit c081392

Browse files
committed
otg new
1 parent be85012 commit c081392

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

examples/analog-stopwatch-with-spi-ssd1306.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ fn draw_seconds_hand(seconds: u32) -> impl Iterator<Item = Pixel<BinaryColor>> {
395395
// Add a fancy circle near the end of the hand
396396
let decoration = Circle::new(decoration_position, 3).into_styled(decoration_style);
397397

398-
hand.pixels().chain(decoration.pixels().into_iter())
398+
hand.pixels().chain(decoration.pixels())
399399
}
400400

401401
#[exception]

examples/usb-serial-irq.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ fn main() -> ! {
3636

3737
let gpioa = dp.GPIOA.split();
3838

39-
let usb = USB {
40-
usb_global: dp.OTG_FS_GLOBAL,
41-
usb_device: dp.OTG_FS_DEVICE,
42-
usb_pwrclk: dp.OTG_FS_PWRCLK,
43-
pin_dm: gpioa.pa11.into(),
44-
pin_dp: gpioa.pa12.into(),
45-
hclk: clocks.hclk(),
46-
};
39+
let usb = USB::new(
40+
(dp.OTG_FS_GLOBAL, dp.OTG_FS_DEVICE, dp.OTG_FS_PWRCLK),
41+
(gpioa.pa11, gpioa.pa12),
42+
&clocks,
43+
);
4744

4845
*USB_BUS = Some(stm32f4xx_hal::otg_fs::UsbBusType::new(usb, EP_MEMORY));
4946
let usb_bus = USB_BUS.as_ref().unwrap();

examples/usb-serial-poll.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ fn main() -> ! {
2727

2828
let gpioa = dp.GPIOA.split();
2929

30-
let usb = USB {
31-
usb_global: dp.OTG_FS_GLOBAL,
32-
usb_device: dp.OTG_FS_DEVICE,
33-
usb_pwrclk: dp.OTG_FS_PWRCLK,
34-
pin_dm: gpioa.pa11.into(),
35-
pin_dp: gpioa.pa12.into(),
36-
hclk: clocks.hclk(),
37-
};
30+
let usb = USB::new(
31+
(dp.OTG_FS_GLOBAL, dp.OTG_FS_DEVICE, dp.OTG_FS_PWRCLK),
32+
(gpioa.pa11, gpioa.pa12),
33+
&clocks,
34+
);
3835

3936
let usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY });
4037

src/otg_fs.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::pac;
77

88
use crate::gpio::alt::otg_fs as alt;
9-
use crate::rcc::{Enable, Reset};
9+
use crate::rcc::{Clocks, Enable, Reset};
1010
use fugit::HertzU32 as Hertz;
1111

1212
pub use synopsys_usb_otg::UsbBus;
@@ -21,6 +21,23 @@ pub struct USB {
2121
pub hclk: Hertz,
2222
}
2323

24+
impl USB {
25+
pub fn new(
26+
periphs: (pac::OTG_FS_GLOBAL, pac::OTG_FS_DEVICE, pac::OTG_FS_PWRCLK),
27+
pins: (impl Into<alt::Dm>, impl Into<alt::Dp>),
28+
clocks: &Clocks,
29+
) -> Self {
30+
Self {
31+
usb_global: periphs.0,
32+
usb_device: periphs.1,
33+
usb_pwrclk: periphs.2,
34+
pin_dm: pins.0.into(),
35+
pin_dp: pins.1.into(),
36+
hclk: clocks.hclk(),
37+
}
38+
}
39+
}
40+
2441
unsafe impl Sync for USB {}
2542

2643
unsafe impl UsbPeripheral for USB {

src/otg_hs.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use crate::pac;
1010

1111
use crate::gpio::alt::otg_hs as alt;
12-
use crate::rcc::{Enable, Reset};
12+
use crate::rcc::{Clocks, Enable, Reset};
1313
use fugit::HertzU32 as Hertz;
1414

1515
pub use synopsys_usb_otg::UsbBus;
@@ -24,6 +24,23 @@ pub struct USB {
2424
pub hclk: Hertz,
2525
}
2626

27+
impl USB {
28+
pub fn new(
29+
periphs: (pac::OTG_HS_GLOBAL, pac::OTG_HS_DEVICE, pac::OTG_HS_PWRCLK),
30+
pins: (impl Into<alt::Dm>, impl Into<alt::Dp>),
31+
clocks: &Clocks,
32+
) -> Self {
33+
Self {
34+
usb_global: periphs.0,
35+
usb_device: periphs.1,
36+
usb_pwrclk: periphs.2,
37+
pin_dm: pins.0.into(),
38+
pin_dp: pins.1.into(),
39+
hclk: clocks.hclk(),
40+
}
41+
}
42+
}
43+
2744
unsafe impl Sync for USB {}
2845

2946
unsafe impl UsbPeripheral for USB {

0 commit comments

Comments
 (0)