-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_class.rs
65 lines (53 loc) · 1.49 KB
/
test_class.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![no_std]
#![no_main]
extern crate panic_semihosting;
use cortex_m_rt::entry;
#[cfg(feature = "fs")]
use stm32f4xx_hal::otg_fs::{UsbBus, USB};
#[cfg(feature = "hs")]
use stm32f4xx_hal::otg_hs::{UsbBus, USB};
use stm32f4xx_hal::{pac, prelude::*};
use usb_device::test_class::TestClass;
static mut EP_MEMORY: [u32; 1024] = [0; 1024];
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();
let clocks = rcc
.cfgr
.use_hse(8.MHz())
.sysclk(48.MHz())
.pclk1(24.MHz())
.require_pll48clk()
.freeze();
#[cfg(feature = "fs")]
let gpioa = dp.GPIOA.split();
#[cfg(feature = "hs")]
let gpiob = dp.GPIOB.split();
#[cfg(feature = "fs")]
let usb = USB {
usb_global: dp.OTG_FS_GLOBAL,
usb_device: dp.OTG_FS_DEVICE,
usb_pwrclk: dp.OTG_FS_PWRCLK,
pin_dm: gpioa.pa11.into(),
pin_dp: gpioa.pa12.into(),
hclk: clocks.hclk(),
};
#[cfg(feature = "hs")]
let usb = USB {
usb_global: dp.OTG_HS_GLOBAL,
usb_device: dp.OTG_HS_DEVICE,
usb_pwrclk: dp.OTG_HS_PWRCLK,
pin_dm: gpiob.pb14.into(),
pin_dp: gpiob.pb15.into(),
hclk: clocks.hclk(),
};
let usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY });
let mut test = TestClass::new(&usb_bus);
let mut usb_dev = { test.make_device(&usb_bus) };
loop {
if usb_dev.poll(&mut [&mut test]) {
test.poll();
}
}
}