kernel/hil/
analog_comparator.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//! Interface for direct control of the analog comparators.
6
7use crate::ErrorCode;
8
9// Author: Danilo Verhaert <verhaert@cs.stanford.edu>
10// Last modified August 9th, 2018
11
12pub trait AnalogComparator<'a> {
13    /// The chip-dependent type of an analog comparator channel.
14    type Channel;
15
16    /// Do a single comparison of two inputs, depending on the AC chosen. Output
17    /// will be True (1) when one is higher than the other, and False (0)
18    /// otherwise.  Specifically, the output is True when Vp > Vn (Vin positive
19    /// > Vin negative), and False if Vp < Vn.
20    fn comparison(&self, channel: &Self::Channel) -> bool;
21
22    /// Start interrupt-based comparison for the chosen channel (e.g. channel 1
23    /// for AC1). This will make it listen and send an interrupt as soon as
24    /// Vp > Vn.
25    fn start_comparing(&self, channel: &Self::Channel) -> Result<(), ErrorCode>;
26
27    /// Stop interrupt-based comparison for the chosen channel.
28    fn stop_comparing(&self, channel: &Self::Channel) -> Result<(), ErrorCode>;
29
30    fn set_client(&self, client: &'a dyn Client);
31}
32
33pub trait Client {
34    /// Fires when handle_interrupt is called, returning the channel on which
35    /// the interrupt occurred.
36    fn fired(&self, _: usize);
37}