From 77b936f9be32f8ca25b9b0d98f8954e20bb503d7 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Fri, 8 Nov 2024 14:56:58 +1000 Subject: [PATCH] Revert "boards: apollo3: Remove soil moisture tests" This reverts commit 695612ba79cdae3c4618d677187036d7b8f58746. --- boards/apollo3/lora_things_plus/src/main.rs | 8 ++++++ .../src/tests/environmental_sensors.rs | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/boards/apollo3/lora_things_plus/src/main.rs b/boards/apollo3/lora_things_plus/src/main.rs index ec80771ca9..bb586dbfcf 100644 --- a/boards/apollo3/lora_things_plus/src/main.rs +++ b/boards/apollo3/lora_things_plus/src/main.rs @@ -116,6 +116,13 @@ static mut BME280: Option< static mut CCS811: Option<&'static capsules_extra::ccs811::Ccs811<'static>> = None; #[cfg(feature = "atecc508a")] static mut ATECC508A: Option<&'static capsules_extra::atecc508a::Atecc508a<'static>> = None; +#[cfg(feature = "chirp_i2c_moisture")] +static mut CHIRP_I2C_MOISTURE: Option< + &'static capsules_extra::chirp_i2c_moisture::ChirpI2cMoisture< + 'static, + capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, apollo3::iom::Iom<'static>>, + >, +> = None; /// Dummy buffer that causes the linker to reserve enough space for the stack. #[no_mangle] @@ -281,6 +288,7 @@ unsafe fn setup_chirp_i2c_moisture( components::chirp_i2c_moisture::ChirpI2cMoistureComponent::new(mux_i2c, 0x20).finalize( components::chirp_i2c_moisture_component_static!(apollo3::iom::Iom<'static>), ); + CHIRP_I2C_MOISTURE = Some(chirp_moisture); let moisture = components::moisture::MoistureComponent::new( board_kernel, diff --git a/boards/apollo3/lora_things_plus/src/tests/environmental_sensors.rs b/boards/apollo3/lora_things_plus/src/tests/environmental_sensors.rs index f7344325bc..3bfb597115 100644 --- a/boards/apollo3/lora_things_plus/src/tests/environmental_sensors.rs +++ b/boards/apollo3/lora_things_plus/src/tests/environmental_sensors.rs @@ -9,9 +9,13 @@ //! (https://www.sparkfun.com/products/14348). use crate::tests::run_kernel_op; +#[cfg(feature = "chirp_i2c_moisture")] +use crate::CHIRP_I2C_MOISTURE; use crate::{BME280, CCS811}; use core::cell::Cell; use kernel::debug; +#[cfg(feature = "chirp_i2c_moisture")] +use kernel::hil::sensors::MoistureDriver; use kernel::hil::sensors::{ AirQualityClient, AirQualityDriver, HumidityClient, HumidityDriver, MoistureClient, TemperatureClient, TemperatureDriver, @@ -98,6 +102,29 @@ impl<'a> AirQualityClient for SensorTestCallback { static CALLBACK: SensorTestCallback = SensorTestCallback::new(); +#[cfg(feature = "chirp_i2c_moisture")] +#[test_case] +fn run_chirp_i2c_moisture() { + debug!("check run Chirp I2C Moisture Sensor... "); + run_kernel_op(100); + + let chirp = unsafe { CHIRP_I2C_MOISTURE.unwrap() }; + + // Make sure the device is ready for us. + run_kernel_op(1000); + + MoistureDriver::set_client(chirp, &CALLBACK); + CALLBACK.reset(); + + chirp.read_moisture().unwrap(); + + run_kernel_op(10_000); + assert_eq!(CALLBACK.moisture_done.get(), true); + + debug!(" [ok]"); + run_kernel_op(100); +} + #[test_case] fn run_bme280_temperature() { debug!("check run BME280 Temperature... ");