use crate::units::energy::Volt;
use super::{Channel, GPIOError, GPIOPortType};
pub trait AnalogInputChannel: Channel {
fn read_raw(&self) -> u32;
fn read_volts_instant(&self) -> Volt;
fn read_volts(&self) -> Volt;
fn voltage_range(&self) -> (Volt, Volt);
}
pub type AnalogInput = Box<dyn AnalogInputChannel>;
pub trait AnalogOutputChannel: Channel {
fn write_raw(&mut self, value: u32);
fn write_volts(&mut self, value: Volt);
fn voltage_range(&self) -> (Volt, Volt);
}
pub type AnalogOutput = Box<dyn AnalogOutputChannel>;
pub trait AnalogBiChannel: AnalogInputChannel + AnalogOutputChannel {}
pub type AnalogBi = Box<dyn AnalogBiChannel>;
impl<T: AnalogInputChannel + AnalogOutputChannel> AnalogBiChannel for T {}
#[allow(clippy::missing_errors_doc)]
pub fn inside_analog_range(port: u8, volts: Volt) -> Result<(), GPIOError> {
if (0.0..=5.0).contains(&volts.value()) {
Ok(())
} else {
Err(GPIOError::ValueOutOfRange(
volts,
GPIOPortType::Analog,
port,
))
}
}