use num_derive::FromPrimitive;
#[cfg(test)]
use proptest_derive::Arbitrary;
mod conversion;
pub mod error;
#[cfg(test)]
mod test;
#[derive(Debug, PartialEq, Eq, Copy, Clone, FromPrimitive)]
#[cfg_attr(test, derive(Arbitrary))]
#[repr(u8)]
pub enum PowerMode {
Nom = 0b00,
Lpm1 = 0b01,
Lpm2 = 0b10,
Lpm3 = 0b11,
}
#[derive(Debug, PartialEq, Eq, Copy, Clone, FromPrimitive)]
#[cfg_attr(test, derive(Arbitrary))]
#[repr(u8)]
pub enum Hysteresis {
Off = 0b00,
Lsb1 = 0b01,
Lsb2 = 0b10,
Lsb3 = 0b11,
}
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[cfg_attr(test, derive(Arbitrary))]
#[repr(u8)]
pub enum OutputStage {
Analog = 0b00,
ReducedAnalog = 0b01,
DigitalPwm = 0b10,
}
#[derive(Debug, PartialEq, Eq, Copy, Clone, FromPrimitive)]
#[cfg_attr(test, derive(Arbitrary))]
#[repr(u8)]
pub enum PwmFreq {
PwmF1 = 0b00,
PwmF2 = 0b01,
PwmF3 = 0b10,
PwmF4 = 0b11,
}
impl PwmFreq {
pub const fn to_hz(&self) -> usize {
match self {
Self::PwmF1 => 115,
Self::PwmF2 => 230,
Self::PwmF3 => 460,
Self::PwmF4 => 920,
}
}
}
#[derive(Debug, PartialEq, Eq, Copy, Clone, FromPrimitive)]
#[cfg_attr(test, derive(Arbitrary))]
#[repr(u8)]
pub enum SlowFilterMode {
X16 = 0b00,
X8 = 0b01,
X4 = 0b10,
X2 = 0b11,
}
#[derive(Debug, PartialEq, Eq, Copy, Clone, FromPrimitive)]
#[cfg_attr(test, derive(Arbitrary))]
#[repr(u8)]
pub enum FastFilterThreshold {
SlowFilterOnly = 0b000,
Lsb6 = 0b001,
Lsb7 = 0b010,
Lsb9 = 0b011,
Lsb18 = 0b100,
Lsb21 = 0b101,
Lsb24 = 0b110,
Lsb10 = 0b111,
}
#[derive(Debug, PartialEq, Eq, Copy, Clone, FromPrimitive)]
#[cfg_attr(test, derive(Arbitrary))]
#[repr(u8)]
pub enum WatchdogState {
Off = 0,
On = 1,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct Configuration {
pub power_mode: PowerMode,
pub hysteresis: Hysteresis,
pub output_stage: OutputStage,
pub pwm_frequency: PwmFreq,
pub slow_filter: SlowFilterMode,
pub fast_filter_threshold: FastFilterThreshold,
pub watchdog_state: WatchdogState,
}