avr_tester/pins/
analog_pin.rs

1use crate::*;
2
3/// Provides access to an analog pin, e.g. `ADC1`.
4pub struct AnalogPin<'a> {
5    avr: &'a mut AvrTester,
6    pin: u32,
7}
8
9impl<'a> AnalogPin<'a> {
10    pub(crate) fn new(avr: &'a mut AvrTester, pin: u32) -> Self {
11        Self { avr, pin }
12    }
13
14    /// Applies `voltage` millivolts to this ADC.
15    pub fn set_mv(&mut self, voltage: u32) {
16        self.avr.sim().set_analog_pin(self.pin as _, voltage);
17    }
18}
19
20/// Asynchronous equivalent of [`AnalogPin`].
21///
22/// See [`avr_rt()`] for more details.
23pub struct AnalogPinAsync {
24    pin: u32,
25}
26
27impl AnalogPinAsync {
28    pub(crate) fn new(pin: u32) -> Self {
29        Self { pin }
30    }
31
32    /// Asynchronous equivalent of [`AnalogPin::set_mv()`].
33    pub fn set_mv(&self, voltage: u32) {
34        ComponentRuntime::with(|rt| {
35            rt.sim().set_analog_pin(self.pin as _, voltage);
36        });
37    }
38}