File tree Expand file tree Collapse file tree 2 files changed +25
-16
lines changed Expand file tree Collapse file tree 2 files changed +25
-16
lines changed Original file line number Diff line number Diff line change 5
5
extern crate panic_semihosting;
6
6
7
7
use cortex_m_rt:: entry;
8
- use stm32l0xx_hal:: usb:: { Peripheral , UsbBus } ;
8
+ use stm32l0xx_hal:: usb:: { USB , UsbBus } ;
9
9
use stm32l0xx_hal:: { pac, prelude:: * , rcc, syscfg:: SYSCFG } ;
10
10
use usb_device:: prelude:: * ;
11
11
use usbd_serial:: { SerialPort , USB_CLASS_CDC } ;
@@ -16,15 +16,11 @@ fn main() -> ! {
16
16
17
17
let mut rcc = dp. RCC . freeze ( rcc:: Config :: hsi16 ( ) ) ;
18
18
let mut syscfg = SYSCFG :: new ( dp. SYSCFG , & mut rcc) ;
19
- rcc. enable_hsi48 ( & mut syscfg, dp. CRS ) ;
19
+ let hsi48 = rcc. enable_hsi48 ( & mut syscfg, dp. CRS ) ;
20
20
21
21
let gpioa = dp. GPIOA . split ( & mut rcc) ;
22
22
23
- let usb = Peripheral {
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 , hsi48) ;
28
24
let usb_bus = UsbBus :: new ( usb) ;
29
25
30
26
let mut serial = SerialPort :: new ( & usb_bus) ;
Original file line number Diff line number Diff line change 12
12
//! Please check out the USB examples in the `examples/` directory to see how it
13
13
//! fits together.
14
14
15
- use crate :: stm32:: { RCC , USB } ;
15
+ use crate :: {
16
+ pac:: { self , RCC } ,
17
+ rcc:: HSI48 ,
18
+ } ;
16
19
use stm32_usbd:: UsbPeripheral ;
17
20
18
21
use crate :: gpio:: gpioa:: { PA11 , PA12 } ;
19
22
use crate :: gpio:: { Floating , Input } ;
20
23
pub use stm32_usbd:: UsbBus ;
21
24
22
- pub struct Peripheral {
23
- pub usb : USB ,
24
- pub pin_dm : PA11 < Input < Floating > > ,
25
- pub pin_dp : PA12 < Input < Floating > > ,
25
+
26
+ pub struct USB ( ( ) ) ;
27
+
28
+ impl USB {
29
+ pub fn new (
30
+ _: pac:: USB ,
31
+ _dm : PA11 < Input < Floating > > ,
32
+ _dp : PA12 < Input < Floating > > ,
33
+ _: HSI48 ,
34
+ )
35
+ -> Self
36
+ {
37
+ Self ( ( ) )
38
+ }
26
39
}
27
40
28
- unsafe impl Sync for Peripheral { }
41
+ unsafe impl Sync for USB { }
29
42
30
- unsafe impl UsbPeripheral for Peripheral {
31
- const REGISTERS : * const ( ) = USB :: ptr ( ) as * const ( ) ;
43
+ unsafe impl UsbPeripheral for USB {
44
+ const REGISTERS : * const ( ) = pac :: USB :: ptr ( ) as * const ( ) ;
32
45
const DP_PULL_UP_FEATURE : bool = true ;
33
46
const EP_MEMORY : * const ( ) = 0x4000_6000 as _ ;
34
47
const EP_MEMORY_SIZE : usize = 1024 ;
@@ -53,4 +66,4 @@ unsafe impl UsbPeripheral for Peripheral {
53
66
}
54
67
}
55
68
56
- pub type UsbBusType = UsbBus < Peripheral > ;
69
+ pub type UsbBusType = UsbBus < USB > ;
You can’t perform that action at this time.
0 commit comments