components/
dac.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Component for Digital to Analog Converters (DAC).
6//!
7//! Usage
8//! -----
9//! ```rust
10//! let dac = components::dac::DacComponent::new(&peripherals.dac)
11//!      .finalize(components::dac_component_static!());
12//! ```
13
14use capsules_extra::dac::Dac;
15use core::mem::MaybeUninit;
16use kernel::component::Component;
17use kernel::hil;
18
19#[macro_export]
20macro_rules! dac_component_static {
21    () => {{
22        kernel::static_buf!(capsules_extra::dac::Dac<'static>)
23    };};
24}
25
26pub struct DacComponent {
27    dac: &'static dyn hil::dac::DacChannel,
28}
29
30impl DacComponent {
31    pub fn new(dac: &'static dyn hil::dac::DacChannel) -> Self {
32        Self { dac }
33    }
34}
35
36impl Component for DacComponent {
37    type StaticInput = &'static mut MaybeUninit<Dac<'static>>;
38    type Output = &'static Dac<'static>;
39
40    fn finalize(self, s: Self::StaticInput) -> Self::Output {
41        s.write(Dac::new(self.dac))
42    }
43}