components/
sound_pressure.rs1use capsules_extra::sound_pressure::SoundPressureSensor;
15use core::mem::MaybeUninit;
16use kernel::capabilities;
17use kernel::component::Component;
18use kernel::create_capability;
19use kernel::hil;
20
21#[macro_export]
22macro_rules! sound_pressure_component_static {
23 () => {{
24 kernel::static_buf!(capsules_extra::sound_pressure::SoundPressureSensor<'static>)
25 };};
26}
27
28pub struct SoundPressureComponent<S: 'static + hil::sensors::SoundPressure<'static>> {
29 board_kernel: &'static kernel::Kernel,
30 driver_num: usize,
31 sound_sensor: &'static S,
32}
33
34impl<S: 'static + hil::sensors::SoundPressure<'static>> SoundPressureComponent<S> {
35 pub fn new(
36 board_kernel: &'static kernel::Kernel,
37 driver_num: usize,
38 sound_sensor: &'static S,
39 ) -> SoundPressureComponent<S> {
40 SoundPressureComponent {
41 board_kernel,
42 driver_num,
43 sound_sensor,
44 }
45 }
46}
47
48impl<S: 'static + hil::sensors::SoundPressure<'static>> Component for SoundPressureComponent<S> {
49 type StaticInput = &'static mut MaybeUninit<SoundPressureSensor<'static>>;
50 type Output = &'static SoundPressureSensor<'static>;
51
52 fn finalize(self, s: Self::StaticInput) -> Self::Output {
53 let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
54
55 let sound_pressure = s.write(SoundPressureSensor::new(
56 self.sound_sensor,
57 self.board_kernel.create_grant(self.driver_num, &grant_cap),
58 ));
59
60 hil::sensors::SoundPressure::set_client(self.sound_sensor, sound_pressure);
61 sound_pressure
62 }
63}