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
//! Interfacing the on-board LSM303DLHC (accelerometer + compass)
//!
//! ```
//! #![deny(unsafe_code)]
//! #![deny(warnings)]
//! #![no_std]
//! #![no_main]
//!
//! #[macro_use(entry, exception)]
//! extern crate cortex_m_rt as rt;
//! extern crate cortex_m;
//! extern crate f3;
//! extern crate panic_semihosting;
//!
//! use cortex_m::asm;
//! use f3::hal::i2c::I2c;
//! use f3::hal::prelude::*;
//! use f3::hal::stm32f30x;
//! use f3::Lsm303dlhc;
//! use rt::ExceptionFrame;
//!
//! entry!(main);
//!
//! fn main() -> ! {
//! let p = stm32f30x::Peripherals::take().unwrap();
//!
//! let mut flash = p.FLASH.constrain();
//! let mut rcc = p.RCC.constrain();
//!
//! // TRY the other clock configuration
//! let clocks = rcc.cfgr.freeze(&mut flash.acr);
//! // let clocks = rcc.cfgr.sysclk(64.mhz()).pclk1(32.mhz()).freeze(&mut flash.acr);
//!
//! // The `Lsm303dlhc` abstraction exposed by the `f3` crate requires a specific pin configuration
//! // to be used and won't accept any configuration other than the one used here. Trying to use a
//! // different pin configuration will result in a compiler error.
//! let mut gpiob = p.GPIOB.split(&mut rcc.ahb);
//! let scl = gpiob.pb6.into_af4(&mut gpiob.moder, &mut gpiob.afrl);
//! let sda = gpiob.pb7.into_af4(&mut gpiob.moder, &mut gpiob.afrl);
//!
//! let i2c = I2c::i2c1(p.I2C1, (scl, sda), 400.khz(), clocks, &mut rcc.apb1);
//!
//! let mut lsm303dlhc = Lsm303dlhc::new(i2c).unwrap();
//!
//! let _accel = lsm303dlhc.accel().unwrap();
//! let _mag = lsm303dlhc.mag().unwrap();
//! let _temp = lsm303dlhc.temp().unwrap();
//!
//! // when you reach this breakpoint you'll be able to inspect the variables `_accel`, `_mag` and
//! // `_temp` which contain the accelerometer, compass (magnetometer) and temperature sensor
//! // readings
//! asm::bkpt();
//!
//! loop {}
//! }
//!
//! exception!(HardFault, hard_fault);
//!
//! fn hard_fault(ef: &ExceptionFrame) -> ! {
//! panic!("{:#?}", ef);
//! }
//!
//! exception!(*, default_handler);
//!
//! fn default_handler(irqn: i16) {
//! panic!("Unhandled exception (IRQn = {})", irqn);
//! }
//! ```
// Auto-generated. Do not modify.