Skip to content

Commit

Permalink
boards: apollo3: lora_things_plus: Add rainfall sensor
Browse files Browse the repository at this point in the history
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
  • Loading branch information
alistair23 committed Nov 12, 2024
1 parent 77b936f commit aa75a3b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions boards/apollo3/lora_things_plus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ atecc508a = []
# If the sensor is attached via the I2C Qwiic connecter you should
# enable this feature.
chirp_i2c_moisture = []

# This feature enables support for the DFRobot Rainfall Sensor.
# https://wiki.dfrobot.com/SKU_SEN0575_Gravity_Rainfall_Sensor
dfrobot_i2c_rainfall = []
5 changes: 5 additions & 0 deletions boards/apollo3/lora_things_plus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ test-atecc508a:
test-chirp_i2c_moisture:
$(Q)OBJCOPY=${OBJCOPY} PORT=$(PORT) $(CARGO) test $(NO_RUN) \
--bin $(PLATFORM) --release --features chirp_i2c_moisture

.PHONY: test-dfrobot_i2c_rainfall
test-dfrobot_i2c_rainfall:
$(Q)OBJCOPY=${OBJCOPY} PORT=$(PORT) $(CARGO) test $(NO_RUN) \
--bin $(PLATFORM) --release --features dfrobot_i2c_rainfall
45 changes: 44 additions & 1 deletion boards/apollo3/lora_things_plus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use {
kernel::hil::rng::Rng,
};

#[cfg(feature = "chirp_i2c_moisture")]
#[cfg(any(feature = "chirp_i2c_moisture", feature = "dfrobot_i2c_rainfall"))]
use capsules_core::virtualizers::virtual_i2c::MuxI2C;

/// Support routines for debugging I/O.
Expand Down Expand Up @@ -135,6 +135,9 @@ const LORA_GPIO_DRIVER_NUM: usize = capsules_core::driver::NUM::LoRaPhyGPIO as u
type ChirpI2cMoistureType = components::chirp_i2c_moisture::ChirpI2cMoistureComponentType<
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, apollo3::iom::Iom<'static>>,
>;
type DFRobotRainFallType = components::dfrobot_rainfall_sensor::DFRobotRainFallSensorComponentType<
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, apollo3::iom::Iom<'static>>,
>;
type BME280Sensor = components::bme280::Bme280ComponentType<
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, apollo3::iom::Iom<'static>>,
>;
Expand Down Expand Up @@ -182,6 +185,7 @@ struct LoRaThingsPlus {
humidity: &'static HumidityDriver,
air_quality: &'static capsules_extra::air_quality::AirQualitySensor<'static>,
moisture: Option<&'static components::moisture::MoistureComponentType<ChirpI2cMoistureType>>,
rainfall: Option<&'static components::rainfall::RainFallComponentType<DFRobotRainFallType>>,
rng: Option<
&'static capsules_core::rng::RngDriver<
'static,
Expand Down Expand Up @@ -300,6 +304,28 @@ unsafe fn setup_chirp_i2c_moisture(
moisture
}

#[cfg(feature = "dfrobot_i2c_rainfall")]
unsafe fn setup_dfrobot_i2c_rainfall(
board_kernel: &'static kernel::Kernel,
_memory_allocation_cap: &dyn capabilities::MemoryAllocationCapability,
mux_i2c: &'static MuxI2C<'static, apollo3::iom::Iom<'static>>,
) -> &'static components::rainfall::RainFallComponentType<DFRobotRainFallType> {
let dfrobot_rainfall =
components::dfrobot_rainfall_sensor::DFRobotRainFallSensorComponent::new(mux_i2c, 0x1D)
.finalize(components::dfrobot_rainfall_sensor_component_static!(
apollo3::iom::Iom<'static>
));

let rainfall = components::rainfall::RainFallComponent::new(
board_kernel,
capsules_extra::rainfall::DRIVER_NUM,
dfrobot_rainfall,
)
.finalize(components::rainfall_component_static!(DFRobotRainFallType));

rainfall
}

/// Mapping of integer syscalls to objects that implement syscalls.
impl SyscallDriverLookup for LoRaThingsPlus {
fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
Expand Down Expand Up @@ -334,6 +360,13 @@ impl SyscallDriverLookup for LoRaThingsPlus {
f(None)
}
}
capsules_extra::rainfall::DRIVER_NUM => {
if let Some(rainfall) = self.rainfall {
f(Some(rainfall))
} else {
f(None)
}
}
_ => f(None),
}
}
Expand Down Expand Up @@ -547,6 +580,15 @@ unsafe fn setup() -> (
#[cfg(not(feature = "chirp_i2c_moisture"))]
let moisture = None;

#[cfg(feature = "dfrobot_i2c_rainfall")]
let rainfall = Some(setup_dfrobot_i2c_rainfall(
board_kernel,
&memory_allocation_cap,
mux_i2c,
));
#[cfg(not(feature = "dfrobot_i2c_rainfall"))]
let rainfall = None;

#[cfg(feature = "atecc508a")]
let rng = Some(setup_atecc508a(
board_kernel,
Expand Down Expand Up @@ -797,6 +839,7 @@ unsafe fn setup() -> (
humidity,
air_quality,
moisture,
rainfall,
rng,
scheduler,
systick,
Expand Down

0 comments on commit aa75a3b

Please sign in to comment.