1use capsules_extra::moisture::MoistureSensor;
19use core::mem::MaybeUninit;
20use kernel::capabilities;
21use kernel::component::Component;
22use kernel::create_capability;
23use kernel::hil;
24
25#[macro_export]
26macro_rules! moisture_component_static {
27 ($H: ty $(,)?) => {{
28 kernel::static_buf!(capsules_extra::moisture::MoistureSensor<'static, $H>)
29 };};
30}
31
32pub type MoistureComponentType<H> = capsules_extra::moisture::MoistureSensor<'static, H>;
33
34pub struct MoistureComponent<T: 'static + hil::sensors::MoistureDriver<'static>> {
35 board_kernel: &'static kernel::Kernel,
36 driver_num: usize,
37 sensor: &'static T,
38}
39
40impl<T: 'static + hil::sensors::MoistureDriver<'static>> MoistureComponent<T> {
41 pub fn new(
42 board_kernel: &'static kernel::Kernel,
43 driver_num: usize,
44 sensor: &'static T,
45 ) -> MoistureComponent<T> {
46 MoistureComponent {
47 board_kernel,
48 driver_num,
49 sensor,
50 }
51 }
52}
53
54impl<T: 'static + hil::sensors::MoistureDriver<'static>> Component for MoistureComponent<T> {
55 type StaticInput = &'static mut MaybeUninit<MoistureSensor<'static, T>>;
56 type Output = &'static MoistureSensor<'static, T>;
57
58 fn finalize(self, s: Self::StaticInput) -> Self::Output {
59 let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
60
61 let moisture = s.write(MoistureSensor::new(
62 self.sensor,
63 self.board_kernel.create_grant(self.driver_num, &grant_cap),
64 ));
65
66 hil::sensors::MoistureDriver::set_client(self.sensor, moisture);
67 moisture
68 }
69}