Skip to main content

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    () => {{ kernel::static_buf!(capsules_extra::dac::Dac<'static>) }};
22}
23
24pub struct DacComponent {
25    dac: &'static dyn hil::dac::DacChannel,
26}
27
28impl DacComponent {
29    pub fn new(dac: &'static dyn hil::dac::DacChannel) -> Self {
30        Self { dac }
31    }
32}
33
34impl Component for DacComponent {
35    type StaticInput = &'static mut MaybeUninit<Dac<'static>>;
36    type Output = &'static Dac<'static>;
37
38    fn finalize(self, s: Self::StaticInput) -> Self::Output {
39        s.write(Dac::new(self.dac))
40    }
41}