5
5
#![ no_main]
6
6
#![ no_std]
7
7
8
- extern crate cortex_m;
9
- extern crate cortex_m_rt as rt;
10
- extern crate mpu9250;
11
- extern crate panic_semihosting;
12
- extern crate stm32f1xx_hal as hal;
8
+ use panic_halt as _;
13
9
14
10
use cortex_m:: asm;
15
- use hal::delay::Delay;
16
- use hal::prelude::*;
17
- use hal::spi::Spi;
18
- use hal::stm32f103xx;
11
+ use cortex_m_rt:: entry;
19
12
use mpu9250:: Mpu9250 ;
20
- use rt::{entry, exception, ExceptionFrame};
13
+ use stm32f1xx_hal as hal;
14
+
15
+ use hal:: { pac, prelude:: * , spi:: Spi } ;
21
16
22
17
#[ entry]
23
18
fn main ( ) -> ! {
24
19
let cp = cortex_m:: Peripherals :: take ( ) . unwrap ( ) ;
25
- let dp = stm32f103xx ::Peripherals::take().unwrap();
20
+ let dp = pac :: Peripherals :: take ( ) . unwrap ( ) ;
26
21
27
22
let mut flash = dp. FLASH . constrain ( ) ;
28
- let mut rcc = dp.RCC.constrain();
23
+ let rcc = dp. RCC . constrain ( ) ;
29
24
30
25
let clocks = rcc. cfgr . freeze ( & mut flash. acr ) ;
31
26
@@ -46,36 +41,25 @@ fn main() -> ! {
46
41
// let miso = gpiob.pb14;
47
42
// let mosi = gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh);
48
43
49
- let spi = Spi::spi1 (
44
+ let spi = Spi :: new (
50
45
dp. SPI1 ,
51
- (sck, miso, mosi),
52
- &mut afio.mapr,
53
- mpu9250::MODE,
46
+ ( sck, miso, mosi, & mut afio. mapr ) ,
47
+ mpu9250:: MODE . into ( ) ,
54
48
1 . MHz ( ) ,
55
- clocks,
49
+ & clocks,
56
50
) ;
57
51
58
- let mut delay = Delay::new( cp.SYST, &clocks);
52
+ let mut delay = cp. SYST . delay ( & clocks) ;
59
53
60
- let mut mpu9250 = Mpu9250::marg (spi, nss, &mut delay).unwrap();
54
+ let mut mpu9250 = Mpu9250 :: marg_default ( spi, nss, & mut delay) . unwrap ( ) ;
61
55
62
56
// sanity checks
63
57
assert_eq ! ( mpu9250. who_am_i( ) . unwrap( ) , 0x71 ) ;
64
58
assert_eq ! ( mpu9250. ak8963_who_am_i( ) . unwrap( ) , 0x48 ) ;
65
59
66
- let _a = mpu9250.all().unwrap();
60
+ let _a = mpu9250. all :: < [ f32 ; 3 ] > ( ) . unwrap ( ) ;
67
61
68
62
asm:: bkpt ( ) ;
69
63
70
64
loop { }
71
65
}
72
-
73
- #[exception]
74
- fn HardFault(ef: &ExceptionFrame) -> ! {
75
- panic!("{:#?}", ef);
76
- }
77
-
78
- #[exception]
79
- fn DefaultHandler(irqn: i16) {
80
- panic!("Unhandled exception (IRQn = {})", irqn);
81
- }
0 commit comments