#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LineFreq {
Hz50,
Hz60,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PgaGain {
X1 = 0x00,
X2 = 0x15,
X4 = 0x2A,
}
impl PgaGain {
pub const fn mmode1(self) -> u16 {
self as u16
}
}
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Config {
pub voltage_gain: [u16; 3],
pub current_gain: [u16; 3],
pub line_freq_hz: LineFreq,
pub pga_gain: PgaGain,
pub sag_peak_det_cfg: u16,
pub pl_constant_high: u16,
pub pl_constant_low: u16,
pub zx_config: u16,
pub mmode0_base: u16,
pub pstart_threshold: u16,
pub qstart_threshold: u16,
pub sstart_threshold: u16,
pub pphase_threshold: u16,
pub qphase_threshold: u16,
pub post_reset_delay_ms: u32,
}
impl Default for Config {
fn default() -> Self {
Self::new()
}
}
impl Config {
pub const fn new() -> Self {
Self {
voltage_gain: [1, 1, 1],
current_gain: [1, 1, 1],
line_freq_hz: LineFreq::Hz50,
pga_gain: PgaGain::X1,
sag_peak_det_cfg: 0xFF3F,
pl_constant_high: 0x0861,
pl_constant_low: 0xC468,
zx_config: 0xD654,
mmode0_base: 0x87,
pstart_threshold: 0x1D4C,
qstart_threshold: 0x1D4C,
sstart_threshold: 0x1D4C,
pphase_threshold: 0x02EE,
qphase_threshold: 0x02EE,
post_reset_delay_ms: 6,
}
}
pub const fn with_voltage_gain(mut self, gain: [u16; 3]) -> Self {
self.voltage_gain = gain;
self
}
pub const fn with_current_gain(mut self, gain: [u16; 3]) -> Self {
self.current_gain = gain;
self
}
pub const fn with_line_freq(mut self, freq: LineFreq) -> Self {
self.line_freq_hz = freq;
self
}
pub const fn with_pga_gain(mut self, gain: PgaGain) -> Self {
self.pga_gain = gain;
self
}
pub const fn with_post_reset_delay_ms(mut self, delay_ms: u32) -> Self {
self.post_reset_delay_ms = delay_ms;
self
}
}