Skip to content

Commit

Permalink
fix: compile error in chapter 14
Browse files Browse the repository at this point in the history
  • Loading branch information
dzvon committed May 27, 2021
1 parent f307c49 commit 1d23f14
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/14-i2c/auxiliary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ name = "aux14"
version = "0.1.0"

[dependencies]
cortex-m = "=0.5.6"
cortex-m = "0.6.3"
cortex-m-rt = "0.6.3"
panic-itm = "0.4.0"
stm32f3-discovery = "0.6.0"

[dependencies.f3]
features = ["rt"]
version = "0.6.1"
[dependencies.stm32f3]
version = "0.12.1"
features = ["stm32f303", "rt"]
14 changes: 7 additions & 7 deletions src/14-i2c/auxiliary/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ extern crate panic_itm; // panic handler

pub use cortex_m::{asm::bkpt, iprint, iprintln};
pub use cortex_m_rt::entry;
pub use f3::hal::{delay::Delay, prelude, stm32f30x::i2c1};
pub use stm32f3_discovery::stm32f3xx_hal::{delay::Delay, prelude, stm32::i2c1};

use cortex_m::peripheral::ITM;
use f3::{
hal::{
use stm32f3_discovery::{
lsm303dlhc::Lsm303dlhc,
stm32f3xx_hal::{
i2c::I2c,
prelude::*,
stm32f30x::{self, I2C1},
stm32::{self, I2C1},
},
Lsm303dlhc,
};

pub fn init() -> (&'static i2c1::RegisterBlock, Delay, ITM) {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32f30x::Peripherals::take().unwrap();
let dp = stm32::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
Expand All @@ -32,7 +32,7 @@ pub fn init() -> (&'static i2c1::RegisterBlock, Delay, ITM) {
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(dp.I2C1, (scl, sda), 400.khz(), clocks, &mut rcc.apb1);
let i2c = I2c::new(dp.I2C1, (scl, sda), 400.khz(), clocks, &mut rcc.apb1);

Lsm303dlhc::new(i2c).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions src/14-i2c/read-several-registers.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Putting it all together inside a loop alongside a delay to reduce the data throu
use aux14::{entry, iprint, iprintln, prelude::*};

// Slave address
const MAGNETOMETER: u8 = 0b001_1110;
const MAGNETOMETER: u16 = 0b0011_1100;

// Addresses of the magnetometer's registers
const OUT_X_H_M: u8 = 0x03;
Expand All @@ -68,7 +68,7 @@ fn main() -> ! {
// Broadcast the MAGNETOMETER address with the R/W bit set to Write
i2c1.cr2.write(|w| {
w.start().set_bit();
w.sadd1().bits(MAGNETOMETER);
w.sadd().bits(MAGNETOMETER);
w.rd_wrn().clear_bit();
w.nbytes().bits(1);
w.autoend().clear_bit()
Expand Down
2 changes: 1 addition & 1 deletion src/14-i2c/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use aux14::{entry, iprint, iprintln, prelude::*};

// Slave address
const MAGNETOMETER: u8 = 0b001_1110;
const MAGNETOMETER: u16 = 0b0011_1100;

// Addresses of the magnetometer's registers
const OUT_X_H_M: u8 = 0x03;
Expand Down
4 changes: 2 additions & 2 deletions src/14-i2c/the-solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use aux14::{entry, iprint, iprintln, prelude::*};

// Slave address
const MAGNETOMETER: u8 = 0b001_1110;
const MAGNETOMETER: u16 = 0b0011_1100;

// Addresses of the magnetometer's registers
const OUT_X_H_M: u8 = 0x03;
Expand All @@ -26,7 +26,7 @@ fn main() -> ! {
// Broadcast the MAGNETOMETER address with the R/W bit set to Write
i2c1.cr2.write(|w| {
w.start().set_bit();
w.sadd1().bits(MAGNETOMETER);
w.sadd().bits(MAGNETOMETER);
w.rd_wrn().clear_bit();
w.nbytes().bits(1);
w.autoend().clear_bit()
Expand Down

0 comments on commit 1d23f14

Please sign in to comment.