diff --git a/Cargo.lock b/Cargo.lock index 7114b4a..8c3a629 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,6 +120,7 @@ source = "git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f70631 dependencies = [ "cfg-if", "critical-section", + "defmt", "embedded-io-async", "futures-util", "heapless", @@ -312,6 +313,7 @@ dependencies = [ name = "hyped_i2c" version = "0.1.0" dependencies = [ + "embassy-sync", "heapless", ] @@ -328,6 +330,7 @@ dependencies = [ name = "hyped_sensors" version = "0.1.0" dependencies = [ + "embassy-sync", "heapless", "hyped_core", "hyped_gpio_input", @@ -338,20 +341,10 @@ dependencies = [ name = "hyped_spi" version = "0.1.0" dependencies = [ + "embassy-sync", "heapless", ] -[[package]] -name = "hyped_state_machine" -version = "0.1.0" -dependencies = [ - "defmt", - "embassy-net", - "heapless", - "hyped_core", - "rust-mqtt", -] - [[package]] name = "indexmap" version = "2.6.0" @@ -364,9 +357,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "7a73e9fe3c49d7afb2ace819fa181a287ce54a0983eda4e0eb05c22f82ffe534" [[package]] name = "libm" @@ -562,18 +555,18 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -676,9 +669,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "version_check" diff --git a/boards/stm32f767zi/Cargo.lock b/boards/stm32f767zi/Cargo.lock index 6980a7d..4d89fab 100644 --- a/boards/stm32f767zi/Cargo.lock +++ b/boards/stm32f767zi/Cargo.lock @@ -185,7 +185,7 @@ source = "git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f70631 dependencies = [ "defmt", "embassy-futures", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-time", "embedded-hal 0.2.7", "embedded-hal 1.0.0", @@ -244,7 +244,7 @@ dependencies = [ "defmt", "document-features", "embassy-net-driver", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-time", "embedded-io-async", "embedded-nal-async", @@ -278,7 +278,7 @@ dependencies = [ "embassy-futures", "embassy-hal-internal", "embassy-net-driver", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-time", "embassy-time-driver", "embassy-usb-driver", @@ -318,19 +318,6 @@ dependencies = [ "heapless", ] -[[package]] -name = "embassy-sync" -version = "0.6.0" -source = "git+https://github.com/embassy-rs/embassy#9555259c57a07338792cfe0fdd363a59616a8062" -dependencies = [ - "cfg-if", - "critical-section", - "defmt", - "embedded-io-async", - "futures-util", - "heapless", -] - [[package]] name = "embassy-time" version = "0.3.2" @@ -376,7 +363,7 @@ version = "0.1.0" source = "git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7#1c466b81e6af6b34b1f706318cc0870a459550b7" dependencies = [ "critical-section", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-usb-driver", ] @@ -558,7 +545,7 @@ dependencies = [ "embassy-futures", "embassy-net", "embassy-stm32", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy)", + "embassy-sync", "embassy-time", "embedded-hal 0.2.7", "embedded-storage", @@ -606,6 +593,7 @@ dependencies = [ name = "hyped_i2c" version = "0.1.0" dependencies = [ + "embassy-sync", "heapless", ] @@ -621,6 +609,7 @@ dependencies = [ name = "hyped_sensors" version = "0.1.0" dependencies = [ + "embassy-sync", "heapless", "hyped_core", "hyped_gpio_input", diff --git a/boards/stm32f767zi/Cargo.toml b/boards/stm32f767zi/Cargo.toml index 42aec3a..3aac42e 100644 --- a/boards/stm32f767zi/Cargo.toml +++ b/boards/stm32f767zi/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] embassy-stm32 = { version = "0.1.0", features = ["defmt", "stm32f767zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] , git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} -embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy"} +embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} embassy-executor = { version = "0.6.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} embassy-time = { version = "0.3.1", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} embassy-net = { version = "0.4.0", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} diff --git a/boards/stm32f767zi/src/io.rs b/boards/stm32f767zi/src/io.rs index 468c6b5..61e79fd 100644 --- a/boards/stm32f767zi/src/io.rs +++ b/boards/stm32f767zi/src/io.rs @@ -1,6 +1,8 @@ +use core::cell::RefCell; use embassy_stm32::adc::{Adc, AnyAdcChannel, Instance}; use embassy_stm32::gpio::Input; use embassy_stm32::{i2c::I2c, mode::Blocking}; +use embassy_sync::blocking_mutex::{raw::CriticalSectionRawMutex, Mutex}; use hyped_adc::HypedAdc; use hyped_adc_derive::HypedAdc; @@ -22,5 +24,5 @@ pub struct Stm32f767ziGpioInput { #[derive(HypedI2c)] pub struct Stm32f767ziI2c<'d> { - i2c: I2c<'d, Blocking>, + i2c: Mutex>>, } diff --git a/boards/stm32f767zi/src/tasks/temperature.rs b/boards/stm32f767zi/src/tasks/temperature.rs index 3fd3860..3bfa190 100644 --- a/boards/stm32f767zi/src/tasks/temperature.rs +++ b/boards/stm32f767zi/src/tasks/temperature.rs @@ -1,14 +1,22 @@ use crate::io::Stm32f767ziI2c; +use core::cell::RefCell; use defmt_rtt as _; use embassy_stm32::i2c::I2c; use embassy_stm32::time::Hertz; +use embassy_sync::blocking_mutex::Mutex; use hyped_sensors::temperature::{Status, Temperature, TemperatureAddresses}; /// Test task that just reads the temperature from the sensor and prints it to the console #[embassy_executor::task] pub async fn read_temp() -> ! { let p = embassy_stm32::init(Default::default()); - let i2c = I2c::new_blocking(p.I2C1, p.PB8, p.PB9, Hertz(100_000), Default::default()); + let i2c = Mutex::new(RefCell::new(I2c::new_blocking( + p.I2C1, + p.PB8, + p.PB9, + Hertz(100_000), + Default::default(), + ))); let mut hyped_i2c = Stm32f767ziI2c::new(i2c); let mut temperature_sensor = Temperature::new(&mut hyped_i2c, TemperatureAddresses::Address3f) diff --git a/boards/stm32l476rg/Cargo.lock b/boards/stm32l476rg/Cargo.lock index 19b1fbb..0640936 100644 --- a/boards/stm32l476rg/Cargo.lock +++ b/boards/stm32l476rg/Cargo.lock @@ -185,7 +185,7 @@ source = "git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f70631 dependencies = [ "defmt", "embassy-futures", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-time", "embedded-hal 0.2.7", "embedded-hal 1.0.0", @@ -244,7 +244,7 @@ dependencies = [ "defmt", "document-features", "embassy-net-driver", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-time", "embedded-io-async", "embedded-nal-async", @@ -278,7 +278,7 @@ dependencies = [ "embassy-futures", "embassy-hal-internal", "embassy-net-driver", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-time", "embassy-time-driver", "embassy-usb-driver", @@ -318,19 +318,6 @@ dependencies = [ "heapless", ] -[[package]] -name = "embassy-sync" -version = "0.6.0" -source = "git+https://github.com/embassy-rs/embassy#9555259c57a07338792cfe0fdd363a59616a8062" -dependencies = [ - "cfg-if", - "critical-section", - "defmt", - "embedded-io-async", - "futures-util", - "heapless", -] - [[package]] name = "embassy-time" version = "0.3.2" @@ -376,7 +363,7 @@ version = "0.1.0" source = "git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7#1c466b81e6af6b34b1f706318cc0870a459550b7" dependencies = [ "critical-section", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=1c466b81e6af6b34b1f706318cc0870a459550b7)", + "embassy-sync", "embassy-usb-driver", ] @@ -558,7 +545,7 @@ dependencies = [ "embassy-futures", "embassy-net", "embassy-stm32", - "embassy-sync 0.6.0 (git+https://github.com/embassy-rs/embassy)", + "embassy-sync", "embassy-time", "embedded-hal 0.2.7", "embedded-storage", @@ -606,6 +593,7 @@ dependencies = [ name = "hyped_i2c" version = "0.1.0" dependencies = [ + "embassy-sync", "heapless", ] @@ -621,6 +609,7 @@ dependencies = [ name = "hyped_sensors" version = "0.1.0" dependencies = [ + "embassy-sync", "heapless", "hyped_core", "hyped_gpio_input", diff --git a/boards/stm32l476rg/Cargo.toml b/boards/stm32l476rg/Cargo.toml index 370664f..b572e82 100644 --- a/boards/stm32l476rg/Cargo.toml +++ b/boards/stm32l476rg/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] embassy-stm32 = { version = "0.1.0", features = ["defmt", "stm32l476rg", "memory-x", "unstable-pac", "time-driver-any", "exti"] , git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} -embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy"} +embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} embassy-executor = { version = "0.6.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} embassy-time = { version = "0.3.1", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} embassy-net = { version = "0.4.0", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} diff --git a/boards/stm32l476rg/src/io.rs b/boards/stm32l476rg/src/io.rs index f886a3f..c88c79e 100644 --- a/boards/stm32l476rg/src/io.rs +++ b/boards/stm32l476rg/src/io.rs @@ -1,6 +1,9 @@ +use core::cell::RefCell; + use embassy_stm32::adc::{Adc, AnyAdcChannel, Instance}; use embassy_stm32::gpio::Input; use embassy_stm32::{i2c::I2c, mode::Blocking}; +use embassy_sync::blocking_mutex::{raw::CriticalSectionRawMutex, Mutex}; use hyped_adc::HypedAdc; use hyped_adc_derive::HypedAdc; @@ -22,5 +25,5 @@ pub struct Stm32l476rgGpioInput { #[derive(HypedI2c)] pub struct Stm32l476rgI2c<'d> { - i2c: I2c<'d, Blocking>, + i2c: Mutex>>, } diff --git a/boards/stm32l476rg/src/tasks/temperature.rs b/boards/stm32l476rg/src/tasks/temperature.rs index c439111..7d39b36 100644 --- a/boards/stm32l476rg/src/tasks/temperature.rs +++ b/boards/stm32l476rg/src/tasks/temperature.rs @@ -1,14 +1,22 @@ use crate::io::Stm32l476rgI2c; +use core::cell::RefCell; use defmt_rtt as _; use embassy_stm32::i2c::I2c; use embassy_stm32::time::Hertz; +use embassy_sync::blocking_mutex::Mutex; use hyped_sensors::temperature::{Status, Temperature, TemperatureAddresses}; /// Test task that just reads the temperature from the sensor and prints it to the console #[embassy_executor::task] pub async fn read_temp() -> ! { let p = embassy_stm32::init(Default::default()); - let i2c = I2c::new_blocking(p.I2C1, p.PB8, p.PB9, Hertz(100_000), Default::default()); + let i2c = Mutex::new(RefCell::new(I2c::new_blocking( + p.I2C1, + p.PB8, + p.PB9, + Hertz(100_000), + Default::default(), + ))); let mut hyped_i2c = Stm32l476rgI2c::new(i2c); let mut temperature_sensor = Temperature::new(&mut hyped_i2c, TemperatureAddresses::Address3f) diff --git a/lib/io/hyped_i2c/Cargo.toml b/lib/io/hyped_i2c/Cargo.toml index bec8a24..a984674 100644 --- a/lib/io/hyped_i2c/Cargo.toml +++ b/lib/io/hyped_i2c/Cargo.toml @@ -4,4 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -heapless = "0.8.0" \ No newline at end of file +heapless = "0.8.0" +embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} diff --git a/lib/io/hyped_i2c/hyped_i2c_derive/src/lib.rs b/lib/io/hyped_i2c/hyped_i2c_derive/src/lib.rs index 602891f..d69dc24 100644 --- a/lib/io/hyped_i2c/hyped_i2c_derive/src/lib.rs +++ b/lib/io/hyped_i2c/hyped_i2c_derive/src/lib.rs @@ -19,9 +19,13 @@ fn impl_hyped_i2c(ast: &syn::DeriveInput) -> TokenStream { /// Read a byte from a register on a device fn read_byte(&mut self, device_address: u8, register_address: u8) -> Option { let mut read = [0]; - let result = - self.i2c - .blocking_write_read(device_address, [register_address].as_ref(), &mut read); + let result = self.i2c.lock(|i2c| { + i2c.borrow_mut().blocking_write_read( + device_address, + [register_address].as_ref(), + &mut read, + ) + }); match result { Ok(_) => Some(read[0]), Err(_) => None, @@ -35,9 +39,10 @@ fn impl_hyped_i2c(ast: &syn::DeriveInput) -> TokenStream { register_address: u8, data: u8, ) -> Result<(), I2cError> { - let result = self - .i2c - .blocking_write(device_address, [register_address, data].as_ref()); + let result = self.i2c.lock(|i2c| { + i2c.borrow_mut() + .blocking_write(device_address, [register_address, data].as_ref()) + }); match result { Ok(_) => Ok(()), Err(e) => Err(match e { @@ -55,7 +60,7 @@ fn impl_hyped_i2c(ast: &syn::DeriveInput) -> TokenStream { impl #impl_generics #name #ty_generics { /// Create a new instance of our I2C implementation for the STM32L476RG - pub fn new(i2c: I2c<'d, Blocking>) -> Self { + pub fn new(i2c: Mutex>>) -> Self { Self { i2c } } } diff --git a/lib/io/hyped_i2c/src/lib.rs b/lib/io/hyped_i2c/src/lib.rs index 530602c..a4e03c4 100644 --- a/lib/io/hyped_i2c/src/lib.rs +++ b/lib/io/hyped_i2c/src/lib.rs @@ -26,24 +26,29 @@ pub trait HypedI2c { } pub mod mock_i2c { + use core::cell::RefCell; + use embassy_sync::blocking_mutex::{raw::CriticalSectionRawMutex, Mutex}; use heapless::FnvIndexMap; /// A fixed-size map of I2C values, indexed by device address and register address type I2cValues = FnvIndexMap<(u8, u8), Option, 16>; /// A mock I2C instance which can be used for testing - pub struct MockI2c { - values: I2cValues, + pub struct MockI2c<'a> { + values: &'a Mutex>, writes: I2cValues, } - impl crate::HypedI2c for MockI2c { + impl crate::HypedI2c for MockI2c<'_> { /// Reads a byte by looking up the device address and register address in the map fn read_byte(&mut self, device_address: u8, register_address: u8) -> Option { - self.values - .get(&(device_address, register_address)) - .copied() - .unwrap() + self.values.lock(|values| { + values + .borrow() + .get(&(device_address, register_address)) + .copied() + .unwrap() + }) } /// Writes a byte to the map so that it can be read later to check the value @@ -63,8 +68,8 @@ pub mod mock_i2c { } } - impl MockI2c { - pub fn new(values: I2cValues) -> MockI2c { + impl MockI2c<'_> { + pub fn new(values: &Mutex>) -> MockI2c { MockI2c { values, writes: I2cValues::new(), diff --git a/lib/io/hyped_spi/Cargo.toml b/lib/io/hyped_spi/Cargo.toml index c9773b7..4d0f5bf 100644 --- a/lib/io/hyped_spi/Cargo.toml +++ b/lib/io/hyped_spi/Cargo.toml @@ -4,4 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -heapless = "0.8.0" \ No newline at end of file +heapless = "0.8.0" +embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} diff --git a/lib/sensors/Cargo.toml b/lib/sensors/Cargo.toml index 52dc817..3690b51 100644 --- a/lib/sensors/Cargo.toml +++ b/lib/sensors/Cargo.toml @@ -5,7 +5,11 @@ edition = "2021" [dependencies] heapless = "0.8.0" - +embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} hyped_core = { path = "../core" } hyped_i2c = { path = "../io/hyped_i2c" } -hyped_gpio_input = { path = "../io/hyped_gpio_input" } \ No newline at end of file +hyped_gpio_input = { path = "../io/hyped_gpio_input" } + +[dev-dependencies] +# Fix from: https://github.com/embassy-rs/embassy/pull/2727 +embassy-sync = { version = "0.6.0", features = ["defmt", "std"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"} diff --git a/lib/sensors/src/temperature.rs b/lib/sensors/src/temperature.rs index 3b66881..a7f9c05 100644 --- a/lib/sensors/src/temperature.rs +++ b/lib/sensors/src/temperature.rs @@ -7,7 +7,7 @@ use hyped_i2c::{HypedI2c, I2cError}; /// The temperature is read from the sensor and converted to a floating point value in degrees Celsius. /// /// Data sheet: https://www.st.com/resource/en/datasheet/stts22h.pdf -pub struct Temperature<'a, T: HypedI2c + 'a> { +pub struct Temperature<'a, T: HypedI2c> { i2c: &'a mut T, device_address: u8, } @@ -39,6 +39,7 @@ impl<'a, T: HypedI2c> Temperature<'a, T> { return None; } }; + let temperature_low_byte = match self.i2c.read_byte(self.device_address, STTS22H_DATA_TEMP_L) { Some(byte) => byte, @@ -126,20 +127,23 @@ const TWO_POWER_16: f32 = 65536.0; #[cfg(test)] mod tests { + use core::cell::RefCell; + use super::*; + use embassy_sync::blocking_mutex::Mutex; use heapless::FnvIndexMap; use hyped_i2c::mock_i2c::MockI2c; #[test] fn test_write_config() { - let i2c_values = FnvIndexMap::new(); - let mut i2c = MockI2c::new(i2c_values); - let _ = Temperature::new(&mut i2c, TemperatureAddresses::Address3f); - assert_eq!( - i2c.get_writes() - .get(&(TemperatureAddresses::Address3f as u8, STTS22H_CTRL)), - Some(&Some(STTS22H_CONFIG_SETTINGS)) - ); + let i2c_values = Mutex::new(RefCell::new(FnvIndexMap::new())); + let mut i2c = MockI2c::new(&i2c_values); + let _ = Temperature::new(&mut i2c, TemperatureAddresses::Address3f).unwrap(); + let i2c_value = i2c + .get_writes() + .get(&(TemperatureAddresses::Address3f as u8, STTS22H_CTRL)) + .cloned(); + assert_eq!(i2c_value, Some(Some(STTS22H_CONFIG_SETTINGS))); } #[test] @@ -153,7 +157,8 @@ mod tests { (TemperatureAddresses::Address3f as u8, STTS22H_DATA_TEMP_L), Some(0x00), ); - let mut i2c = MockI2c::new(i2c_values); + let i2c_values = Mutex::new(RefCell::new(i2c_values)); + let mut i2c = MockI2c::new(&i2c_values); let mut temperature = Temperature::new(&mut i2c, TemperatureAddresses::Address3f).unwrap(); assert_eq!(temperature.read(), Some(0.0)); } @@ -169,7 +174,8 @@ mod tests { (TemperatureAddresses::Address3f as u8, STTS22H_DATA_TEMP_L), Some(0xc4), ); - let mut i2c = MockI2c::new(i2c_values); + let i2c_values = Mutex::new(RefCell::new(i2c_values)); + let mut i2c = MockI2c::new(&i2c_values); let mut temperature = Temperature::new(&mut i2c, TemperatureAddresses::Address3f).unwrap(); assert_eq!(temperature.read(), Some(25.0)); } @@ -185,7 +191,8 @@ mod tests { (TemperatureAddresses::Address3f as u8, STTS22H_DATA_TEMP_L), Some(0x18), ); - let mut i2c = MockI2c::new(i2c_values); + let i2c_values = Mutex::new(RefCell::new(i2c_values)); + let mut i2c = MockI2c::new(&i2c_values); let mut temperature = Temperature::new(&mut i2c, TemperatureAddresses::Address3f).unwrap(); assert_eq!(temperature.read(), Some(-10.0)); } @@ -197,7 +204,8 @@ mod tests { (TemperatureAddresses::Address3f as u8, STTS22H_STATUS), Some(STTS22H_STATUS_BUSY), ); - let mut i2c = MockI2c::new(i2c_values); + let i2c_values = Mutex::new(RefCell::new(i2c_values)); + let mut i2c = MockI2c::new(&i2c_values); let mut temperature = Temperature::new(&mut i2c, TemperatureAddresses::Address3f).unwrap(); assert_eq!(temperature.check_status(), Status::Busy); } @@ -209,7 +217,8 @@ mod tests { (TemperatureAddresses::Address3f as u8, STTS22H_STATUS), Some(STTS22H_TEMP_OVER_UPPER_LIMIT), ); - let mut i2c = MockI2c::new(i2c_values); + let i2c_values = Mutex::new(RefCell::new(i2c_values)); + let mut i2c: MockI2c<'_> = MockI2c::new(&i2c_values); let mut temperature = Temperature::new(&mut i2c, TemperatureAddresses::Address3f).unwrap(); assert_eq!(temperature.check_status(), Status::TempOverUpperLimit); } @@ -221,7 +230,8 @@ mod tests { (TemperatureAddresses::Address3f as u8, STTS22H_STATUS), Some(STTS22H_TEMP_UNDER_LOWER_LIMIT), ); - let mut i2c = MockI2c::new(i2c_values); + let i2c_values = Mutex::new(RefCell::new(i2c_values)); + let mut i2c: MockI2c<'_> = MockI2c::new(&i2c_values); let mut temperature = Temperature::new(&mut i2c, TemperatureAddresses::Address3f).unwrap(); assert_eq!(temperature.check_status(), Status::TempUnderLowerLimit); }