From 5c4f40d71f0a45f5d8896e29026fca980d01bbdd Mon Sep 17 00:00:00 2001 From: Alex Martens Date: Sun, 29 Oct 2023 17:02:51 -0700 Subject: [PATCH] Add EH1 to BME280 example --- examples/bme280.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/bme280.rs b/examples/bme280.rs index f016324..e610dad 100644 --- a/examples/bme280.rs +++ b/examples/bme280.rs @@ -7,7 +7,8 @@ //! * https://www.adafruit.com/product/4399 //! * https://www.adafruit.com/product/4472 -use eh0::prelude::*; +use eh0::blocking::i2c::WriteRead; +use eh1::i2c::I2c; use ftdi_embedded_hal as hal; fn main() { @@ -27,15 +28,22 @@ fn main() { let hal = hal::FtHal::init_default(device).unwrap(); let mut i2c = hal.i2c().unwrap(); + // ID register is constant + const BME280_CHIP_ID: u8 = 0x60; + let mut buf: [u8; 1] = [0]; const BME280_ADDR: u8 = 0b1110111; const BME280_CHIP_ID_ADDR: u8 = 0xD0; - println!("Reading chip ID from BME280"); - i2c.write_read(BME280_ADDR, &[BME280_CHIP_ID_ADDR], &mut buf) + + println!("Reading chip ID from BME280 with embedded-hal v0.2"); + WriteRead::write_read(&mut i2c, BME280_ADDR, &[BME280_CHIP_ID_ADDR], &mut buf) .expect("Failed to read from BME280"); + assert_eq!(buf[0], BME280_CHIP_ID); + println!("Chip ID ok from embedded-hal v0.2"); - // ID register is constant - const BME280_CHIP_ID: u8 = 0x60; + println!("Reading chip ID from BME280 with embedded-hal v1"); + I2c::write_read(&mut i2c, BME280_ADDR, &[BME280_CHIP_ID_ADDR], &mut buf) + .expect("Failed to read from BME280"); assert_eq!(buf[0], BME280_CHIP_ID); - println!("Chip ID ok"); + println!("Chip ID ok from embedded-hal v1"); }