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