2
2
//!
3
3
//! The STM32L4 series only supports the full-speed peripheral.
4
4
5
- use crate :: rcc:: { Enable , Reset } ;
6
- use crate :: stm32;
7
-
8
- use crate :: gpio:: {
9
- gpioa:: { PA11 , PA12 } ,
10
- Alternate , PushPull ,
11
- } ;
12
- use crate :: time:: Hertz ;
13
-
14
5
pub use synopsys_usb_otg:: UsbBus ;
15
6
use synopsys_usb_otg:: UsbPeripheral ;
16
7
17
- pub struct USB {
18
- pub usb_global : stm32:: OTG_FS_GLOBAL ,
19
- pub usb_device : stm32:: OTG_FS_DEVICE ,
20
- pub usb_pwrclk : stm32:: OTG_FS_PWRCLK ,
8
+ use crate :: {
9
+ gpio:: {
10
+ gpioa:: { PA11 , PA12 } ,
11
+ Alternate , PushPull ,
12
+ } ,
13
+ pac,
14
+ pwr:: Pwr ,
15
+ rcc:: { Clocks , Enable , Reset } ,
16
+ time:: Hertz ,
17
+ } ;
18
+
19
+ pub struct Usb {
20
+ usb_global : pac:: OTG_FS_GLOBAL ,
21
+ usb_device : pac:: OTG_FS_DEVICE ,
22
+ usb_pwrclk : pac:: OTG_FS_PWRCLK ,
21
23
// TODO: check type
22
- pub pin_dm : PA11 < Alternate < PushPull , 10 > > ,
23
- pub pin_dp : PA12 < Alternate < PushPull , 10 > > ,
24
- pub hclk : Hertz ,
24
+ pin_dm : PA11 < Alternate < PushPull , 10 > > ,
25
+ pin_dp : PA12 < Alternate < PushPull , 10 > > ,
26
+ hclk : Hertz ,
27
+ }
28
+
29
+ impl Usb {
30
+ pub fn new (
31
+ global : pac:: OTG_FS_GLOBAL ,
32
+ device : pac:: OTG_FS_DEVICE ,
33
+ pwrclk : pac:: OTG_FS_PWRCLK ,
34
+ dm : PA11 < Alternate < PushPull , 10 > > ,
35
+ dp : PA12 < Alternate < PushPull , 10 > > ,
36
+ pwr : & mut Pwr ,
37
+ clocks : Clocks ,
38
+ ) -> Self {
39
+ pwr. cr2 . reg ( ) . modify ( |_, w| w. usv ( ) . set_bit ( ) ) ;
40
+
41
+ Self {
42
+ usb_global : global,
43
+ usb_device : device,
44
+ usb_pwrclk : pwrclk,
45
+ pin_dm : dm,
46
+ pin_dp : dp,
47
+ hclk : clocks. hclk ( ) ,
48
+ }
49
+ }
25
50
}
26
51
27
- unsafe impl Sync for USB { }
52
+ unsafe impl Sync for Usb { }
28
53
29
- unsafe impl UsbPeripheral for USB {
30
- const REGISTERS : * const ( ) = stm32 :: OTG_FS_GLOBAL :: ptr ( ) as * const ( ) ;
54
+ unsafe impl UsbPeripheral for Usb {
55
+ const REGISTERS : * const ( ) = pac :: OTG_FS_GLOBAL :: ptr ( ) as * const ( ) ;
31
56
32
57
const HIGH_SPEED : bool = false ;
33
58
const FIFO_DEPTH_WORDS : usize = 320 ;
@@ -37,10 +62,10 @@ unsafe impl UsbPeripheral for USB {
37
62
fn enable ( ) {
38
63
cortex_m:: interrupt:: free ( |_| unsafe {
39
64
// Enable USB peripheral
40
- stm32 :: OTG_FS_GLOBAL :: enable_unchecked ( ) ;
65
+ pac :: OTG_FS_GLOBAL :: enable_unchecked ( ) ;
41
66
42
67
// Reset USB peripheral
43
- stm32 :: OTG_FS_GLOBAL :: reset_unchecked ( ) ;
68
+ pac :: OTG_FS_GLOBAL :: reset_unchecked ( ) ;
44
69
} ) ;
45
70
}
46
71
@@ -49,4 +74,4 @@ unsafe impl UsbPeripheral for USB {
49
74
}
50
75
}
51
76
52
- pub type UsbBusType = UsbBus < USB > ;
77
+ pub type UsbBusType = UsbBus < Usb > ;
0 commit comments