diff --git a/stm32g071b-disco-firmware/Cargo.lock b/stm32g071b-disco-firmware/Cargo.lock index 48e44d6..93e2c9d 100644 --- a/stm32g071b-disco-firmware/Cargo.lock +++ b/stm32g071b-disco-firmware/Cargo.lock @@ -396,17 +396,6 @@ dependencies = [ "embedded-hal 1.0.0", ] -[[package]] -name = "embedded-hal-bus" -version = "0.2.0" -source = "git+https://github.com/sjoerdsimons/embedded-hal?branch=i2c-ref-async+fix-armv6-build#5ad98915d5c178f8cee08f34f2820c4e4e255d84" -dependencies = [ - "critical-section", - "embedded-hal 1.0.0", - "embedded-hal-async", - "portable-atomic", -] - [[package]] name = "embedded-hal-nb" version = "1.0.0" @@ -625,12 +614,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "portable-atomic" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" - [[package]] name = "proc-bitfield" version = "0.3.1" @@ -781,13 +764,13 @@ dependencies = [ "cortex-m-rt", "defmt", "defmt-rtt", + "embassy-embedded-hal", "embassy-executor", "embassy-futures 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "embassy-stm32", "embassy-sync", "embassy-time", "embedded-hal 1.0.0", - "embedded-hal-bus", "embedded-io-async", "ina226", "minicbor", diff --git a/stm32g071b-disco-firmware/Cargo.toml b/stm32g071b-disco-firmware/Cargo.toml index 160ab90..8449a0b 100644 --- a/stm32g071b-disco-firmware/Cargo.toml +++ b/stm32g071b-disco-firmware/Cargo.toml @@ -12,14 +12,13 @@ cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.4" defmt = "0.3.6" defmt-rtt = "0.4.0" +embassy-embedded-hal = { git = "https://github.com/embassy-rs/embassy", version = "0.1.0" } embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"], git = "https://github.com/embassy-rs/embassy" } embassy-futures = "0.1.1" embassy-stm32 = { version = "0.1.0", features = ["stm32g071rb", "defmt", "memory-x", "time-driver-any", "exti"] , git = "https://github.com/embassy-rs/embassy" } embassy-sync = { git = "https://github.com/embassy-rs/embassy", version = "0.5.0" } embassy-time = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy" } embedded-hal = "1.0.0" -embedded-hal-bus = { version = "0.2.0", features = ["async"], git = "https://github.com/sjoerdsimons/embedded-hal", branch = "i2c-ref-async+fix-armv6-build" } -#embedded-hal-bus = { version = "0.2.0", features = ["async"], path = "../../embedded-hal/embedded-hal-bus" } embedded-io-async = "0.6.1" ina226 = { version = "0.2.0", features = ["async"], git = "https://github.com/sjoerdsimons/ina226", branch = "asyncify" } minicbor = "0.24.0" diff --git a/stm32g071b-disco-firmware/src/main.rs b/stm32g071b-disco-firmware/src/main.rs index aab5a45..e0e6cae 100644 --- a/stm32g071b-disco-firmware/src/main.rs +++ b/stm32g071b-disco-firmware/src/main.rs @@ -1,11 +1,10 @@ #![no_main] #![no_std] -use core::cell::RefCell; - use analyzer_cbor::AnalyserData; use byteorder::{ByteOrder, LittleEndian}; use defmt::info; use defmt_rtt as _; +use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice; use embassy_executor::Spawner; use embassy_futures::select::select_array; use embassy_stm32::{ @@ -20,7 +19,7 @@ use embassy_stm32::{ ucpd::{self, CcSel}, usart::{self, BufferedUart}, }; -use embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, channel::Channel}; +use embassy_sync::{blocking_mutex::raw::{NoopRawMutex, ThreadModeRawMutex}, channel::Channel, mutex::Mutex}; use embassy_time::Timer; use embedded_io_async::Write; use minicbor::encode::write::Cursor; @@ -101,17 +100,16 @@ async fn serial_output(uart: USART3, tx: PC11, rx: PC10) { #[embassy_executor::task] async fn sensor_monitor(i2c: I2c<'static, peripherals::I2C1, Async>) { - let i2c = RefCell::new(i2c); - let mut vbus = ina226::INA226::new(embedded_hal_bus::i2c::RefCellDevice::new(&i2c), 0x40); - + let i2c: Mutex = Mutex::new(i2c); + let mut vbus = ina226::INA226::new(I2cDevice::new(&i2c), 0x40); vbus.callibrate(0.015, 5.0) .await .expect("Failed to calibrate vbus"); - let mut cc1 = ina226::INA226::new(embedded_hal_bus::i2c::RefCellDevice::new(&i2c), 0x41); + let mut cc1 = ina226::INA226::new(I2cDevice::new(&i2c), 0x41); cc1.callibrate(0.015, 5.0) .await .expect("Failed to calibrate cc1"); - let mut cc2 = ina226::INA226::new(embedded_hal_bus::i2c::RefCellDevice::new(&i2c), 0x42); + let mut cc2 = ina226::INA226::new(I2cDevice::new(&i2c), 0x42); cc2.callibrate(0.015, 5.0) .await .expect("Failed to calibrate cc2");