esp-hal/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs
Scott Mabin f32565b4af
Embassy enable thread and interrupt by default, enable embassy when building docs (#1485)
* Remove interrupt and thread executor embassy features

* Reserve sw interrupt 3 (4) instead of 0 for multicore systems with the embassy feature enabled

* Remove uneeded #[feature()] from examples

* Fix HIL tests

* Add thread mode context id and fix up examples

* improve embassy module docs

* changelog

* fixup hil tests

* Fixup usb examples
2024-05-02 15:58:04 +00:00

72 lines
1.9 KiB
Rust

//! Embassy "async" vesrion of ead calibration data from BMP180 sensor
//!
//! This example dumps the calibration data from a BMP180 sensor by reading by reading
//! with the direct I2C API and the embedded-hal-async I2C API.
//!
//! //! Folowing pins are used:
//! SDA GPIO4
//! SCL GPIO5
//!
//! Depending on your target and the board you are using you have to change the
//! pins.
//!
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: async embassy embassy-time-timg0 embassy-generic-timers
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
embassy::{self},
gpio::Io,
i2c::I2C,
peripherals::Peripherals,
prelude::*,
system::SystemControl,
timer::timg::TimerGroup,
};
#[main]
async fn main(_spawner: Spawner) {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks);
embassy::init(&clocks, timg0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut i2c = I2C::new_async(
peripherals.I2C0,
io.pins.gpio4,
io.pins.gpio5,
400.kHz(),
&clocks,
);
loop {
let mut data = [0u8; 22];
i2c.write_read(0x77, &[0xaa], &mut data).await.unwrap();
esp_println::println!("direct: {:02x?}", data);
read_data(&mut i2c).await;
Timer::after(Duration::from_millis(1000)).await;
}
}
async fn read_data<I2C>(i2c: &mut I2C)
where
I2C: embedded_hal_async::i2c::I2c,
{
let mut data = [0u8; 22];
i2c.write_read(0x77, &[0xaa], &mut data).await.unwrap();
esp_println::println!("embedded_hal: {:02x?}", data);
}