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 66 67 68 69 70
//! Interfacing the MPU9250 //! //! ``` //! //! #![deny(unsafe_code)] //! #![deny(warnings)] //! #![no_std] //! //! extern crate cortex_m; //! extern crate mpu9250; //! extern crate panic_abort; //! extern crate stm32f103xx_hal as hal; //! //! use cortex_m::asm; //! use hal::delay::Delay; //! use hal::prelude::*; //! use hal::spi::Spi; //! use hal::stm32f103xx; //! use mpu9250::Mpu9250; //! //! fn main() { //! let cp = cortex_m::Peripherals::take().unwrap(); //! let dp = stm32f103xx::Peripherals::take().unwrap(); //! //! let mut flash = dp.FLASH.constrain(); //! let mut rcc = dp.RCC.constrain(); //! //! let clocks = rcc.cfgr.freeze(&mut flash.acr); //! //! let mut afio = dp.AFIO.constrain(&mut rcc.apb2); //! //! let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); //! // let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); //! //! let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl); //! //! // SPI1 //! let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); //! let miso = gpioa.pa6; //! let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); //! //! // SPI2 //! // let sck = gpiob.pb13.into_alternate_push_pull(&mut gpiob.crh); //! // let miso = gpiob.pb14; //! // let mosi = gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh); //! //! let spi = Spi::spi1( //! dp.SPI1, //! (sck, miso, mosi), //! &mut afio.mapr, //! mpu9250::MODE, //! 1.mhz(), //! clocks, //! &mut rcc.apb2, //! ); //! //! let mut delay = Delay::new(cp.SYST, clocks); //! //! let mut mpu9250 = Mpu9250::marg(spi, nss, &mut delay).unwrap(); //! //! // sanity checks //! assert_eq!(mpu9250.who_am_i().unwrap(), 0x71); //! assert_eq!(mpu9250.ak8963_who_am_i().unwrap(), 0x48); //! //! let _a = mpu9250.all().unwrap(); //! //! asm::bkpt(); //! } //! ``` // Auto-generated. Do not modify.