Skip to content

Commit e5820e8

Browse files
committed
reenable mpu9250
1 parent 51321ac commit e5820e8

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ panic-itm = "0.4.2"
6060
cortex-m-rtic = "1.1.3"
6161
cortex-m-semihosting = "0.5.0"
6262
heapless = "0.7.16"
63-
mfrc522 = "0.5.0"
63+
mfrc522 = { version = "0.7.0", features = ["eh02"] }
64+
mpu9250 = "0.25.0"
6465
usb-device = "0.2.8"
6566
usbd-serial = "0.1.1"
6667

examples/mfrc522.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use panic_itm as _;
77
use cortex_m::iprintln;
88

99
use cortex_m_rt::entry;
10-
use mfrc522::Mfrc522;
10+
use mfrc522::{comm::eh02::spi::SpiInterface, Mfrc522};
1111
use stm32f1xx_hal::{
1212
pac,
1313
prelude::*,
@@ -44,7 +44,8 @@ fn main() -> ! {
4444
);
4545

4646
let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
47-
let mut mfrc522 = Mfrc522::new(spi).with_nss(nss).init().unwrap();
47+
let itf = SpiInterface::new(spi).with_nss(nss);
48+
let mut mfrc522 = Mfrc522::new(itf).init().unwrap();
4849

4950
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
5051
led.set_high();

examples/mpu9250.rs.disabled renamed to examples/mpu9250.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,22 @@
55
#![no_main]
66
#![no_std]
77

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 _;
139

1410
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;
1912
use mpu9250::Mpu9250;
20-
use rt::{entry, exception, ExceptionFrame};
13+
use stm32f1xx_hal as hal;
14+
15+
use hal::{pac, prelude::*, spi::Spi};
2116

2217
#[entry]
2318
fn main() -> ! {
2419
let cp = cortex_m::Peripherals::take().unwrap();
25-
let dp = stm32f103xx::Peripherals::take().unwrap();
20+
let dp = pac::Peripherals::take().unwrap();
2621

2722
let mut flash = dp.FLASH.constrain();
28-
let mut rcc = dp.RCC.constrain();
23+
let rcc = dp.RCC.constrain();
2924

3025
let clocks = rcc.cfgr.freeze(&mut flash.acr);
3126

@@ -46,36 +41,25 @@ fn main() -> ! {
4641
// let miso = gpiob.pb14;
4742
// let mosi = gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh);
4843

49-
let spi = Spi::spi1(
44+
let spi = Spi::new(
5045
dp.SPI1,
51-
(sck, miso, mosi),
52-
&mut afio.mapr,
53-
mpu9250::MODE,
46+
(sck, miso, mosi, &mut afio.mapr),
47+
mpu9250::MODE.into(),
5448
1.MHz(),
55-
clocks,
49+
&clocks,
5650
);
5751

58-
let mut delay = Delay::new(cp.SYST, &clocks);
52+
let mut delay = cp.SYST.delay(&clocks);
5953

60-
let mut mpu9250 = Mpu9250::marg(spi, nss, &mut delay).unwrap();
54+
let mut mpu9250 = Mpu9250::marg_default(spi, nss, &mut delay).unwrap();
6155

6256
// sanity checks
6357
assert_eq!(mpu9250.who_am_i().unwrap(), 0x71);
6458
assert_eq!(mpu9250.ak8963_who_am_i().unwrap(), 0x48);
6559

66-
let _a = mpu9250.all().unwrap();
60+
let _a = mpu9250.all::<[f32; 3]>().unwrap();
6761

6862
asm::bkpt();
6963

7064
loop {}
7165
}
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

Comments
 (0)