-
Notifications
You must be signed in to change notification settings - Fork 747
Soil Moisture Sensor Support #4144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a88fb42
kernel: hil: sensor: Add moisture sensor
alistair23 c3de842
capsules: moisture: Add a userspace moisture sensor
alistair23 9721575
boards: components: moisture: Initial commit
alistair23 1f929c4
capsules: chirp_i2c_moisture: Initial commit
alistair23 ec5b2b6
boards: components: chirp_i2c_moisture: Initial commit
alistair23 56d53aa
boards: apollo3: lora_things_plus: Add soil moisture sensor
alistair23 9366f95
boards/apollo3: Cleanup test linker copying
alistair23 9d84bc1
boards: apollo3: Remove soil moisture tests
alistair23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Licensed under the Apache License, Version 2.0 or the MIT License. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Copyright Tock Contributors 2022. | ||
|
||
//! Components for the Chirp I2C Moisture Sensor. | ||
//! <https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/> | ||
//! | ||
//! Usage | ||
//! ----- | ||
//! ```rust | ||
//! let chirp_moisture = | ||
//! components::chirp_i2c_moisture::ChirpI2cMoistureComponent::new(mux_i2c, 0x20).finalize( | ||
//! components::chirp_i2c_moisture_component_static!(apollo3::iom::Iom<'static>), | ||
//! ); | ||
//! | ||
//! let moisture = components::moisture::MoistureComponent::new( | ||
//! board_kernel, | ||
//! capsules_extra::moisture::DRIVER_NUM, | ||
//! chirp_moisture, | ||
//! ) | ||
//! .finalize(components::moisture_component_static!(ChirpI2cMoistureType)); | ||
//! ``` | ||
|
||
use capsules_core::virtualizers::virtual_i2c::{I2CDevice, MuxI2C}; | ||
use capsules_extra::chirp_i2c_moisture::{ChirpI2cMoisture, BUFFER_SIZE}; | ||
use core::mem::MaybeUninit; | ||
use kernel::component::Component; | ||
use kernel::hil::i2c; | ||
|
||
// Setup static space for the objects. | ||
#[macro_export] | ||
macro_rules! chirp_i2c_moisture_component_static { | ||
($I:ty $(,)?) => {{ | ||
let i2c_device = | ||
kernel::static_buf!(capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, $I>); | ||
let i2c_buffer = kernel::static_buf!([u8; capsules_extra::chirp_i2c_moisture::BUFFER_SIZE]); | ||
let chirp_i2c_moisture = kernel::static_buf!( | ||
capsules_extra::chirp_i2c_moisture::ChirpI2cMoisture< | ||
'static, | ||
capsules_core::virtualizers::virtual_i2c::I2CDevice<$I>, | ||
> | ||
); | ||
|
||
(i2c_device, i2c_buffer, chirp_i2c_moisture) | ||
};}; | ||
} | ||
|
||
pub type ChirpI2cMoistureComponentType<I> = | ||
capsules_extra::chirp_i2c_moisture::ChirpI2cMoisture<'static, I>; | ||
|
||
pub struct ChirpI2cMoistureComponent<I: 'static + i2c::I2CMaster<'static>> { | ||
i2c_mux: &'static MuxI2C<'static, I>, | ||
i2c_address: u8, | ||
} | ||
|
||
impl<I: 'static + i2c::I2CMaster<'static>> ChirpI2cMoistureComponent<I> { | ||
pub fn new(i2c: &'static MuxI2C<'static, I>, i2c_address: u8) -> Self { | ||
ChirpI2cMoistureComponent { | ||
i2c_mux: i2c, | ||
i2c_address, | ||
} | ||
} | ||
} | ||
|
||
impl<I: 'static + i2c::I2CMaster<'static>> Component for ChirpI2cMoistureComponent<I> { | ||
type StaticInput = ( | ||
&'static mut MaybeUninit<I2CDevice<'static, I>>, | ||
&'static mut MaybeUninit<[u8; BUFFER_SIZE]>, | ||
&'static mut MaybeUninit<ChirpI2cMoisture<'static, I2CDevice<'static, I>>>, | ||
); | ||
type Output = &'static ChirpI2cMoisture<'static, I2CDevice<'static, I>>; | ||
|
||
fn finalize(self, s: Self::StaticInput) -> Self::Output { | ||
let chirp_i2c_moisture_i2c = s.0.write(I2CDevice::new(self.i2c_mux, self.i2c_address)); | ||
let i2c_buffer = s.1.write([0; BUFFER_SIZE]); | ||
|
||
let chirp_i2c_moisture = | ||
s.2.write(ChirpI2cMoisture::new(chirp_i2c_moisture_i2c, i2c_buffer)); | ||
|
||
chirp_i2c_moisture_i2c.set_client(chirp_i2c_moisture); | ||
chirp_i2c_moisture.initialise(); | ||
chirp_i2c_moisture | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed under the Apache License, Version 2.0 or the MIT License. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Copyright Tock Contributors 2022. | ||
|
||
//! Component for any moisture sensor. | ||
//! | ||
//! Usage | ||
//! ----- | ||
//! ```rust | ||
//! let moisture = components::moisture::MoistureComponent::new( | ||
//! board_kernel, | ||
//! capsules_extra::moisture::DRIVER_NUM, | ||
//! chirp_moisture, | ||
//! ) | ||
//! .finalize(components::moisture_component_static!(ChirpI2cMoistureType)); | ||
//! ``` | ||
|
||
use capsules_extra::moisture::MoistureSensor; | ||
use core::mem::MaybeUninit; | ||
use kernel::capabilities; | ||
use kernel::component::Component; | ||
use kernel::create_capability; | ||
use kernel::hil; | ||
|
||
#[macro_export] | ||
macro_rules! moisture_component_static { | ||
($H: ty $(,)?) => {{ | ||
kernel::static_buf!(capsules_extra::moisture::MoistureSensor<'static, $H>) | ||
};}; | ||
} | ||
|
||
pub type MoistureComponentType<H> = capsules_extra::moisture::MoistureSensor<'static, H>; | ||
|
||
pub struct MoistureComponent<T: 'static + hil::sensors::MoistureDriver<'static>> { | ||
board_kernel: &'static kernel::Kernel, | ||
driver_num: usize, | ||
sensor: &'static T, | ||
} | ||
|
||
impl<T: 'static + hil::sensors::MoistureDriver<'static>> MoistureComponent<T> { | ||
pub fn new( | ||
board_kernel: &'static kernel::Kernel, | ||
driver_num: usize, | ||
sensor: &'static T, | ||
) -> MoistureComponent<T> { | ||
MoistureComponent { | ||
board_kernel, | ||
driver_num, | ||
sensor, | ||
} | ||
} | ||
} | ||
|
||
impl<T: 'static + hil::sensors::MoistureDriver<'static>> Component for MoistureComponent<T> { | ||
type StaticInput = &'static mut MaybeUninit<MoistureSensor<'static, T>>; | ||
type Output = &'static MoistureSensor<'static, T>; | ||
|
||
fn finalize(self, s: Self::StaticInput) -> Self::Output { | ||
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability); | ||
|
||
let moisture = s.write(MoistureSensor::new( | ||
self.sensor, | ||
self.board_kernel.create_grant(self.driver_num, &grant_cap), | ||
)); | ||
|
||
hil::sensors::MoistureDriver::set_client(self.sensor, moisture); | ||
moisture | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.