use num_enum::{FromPrimitive, IntoPrimitive};
use super::RegisterOffset;
use emc230x_macros::RegisterOffset;
bitfield::bitfield! {
#[derive(Clone, Copy, RegisterOffset)]
#[register(offset = 0x02, default = 0x2B)]
pub struct FanConfiguration1(u8);
impl Debug;
pub enagx, set_enagx: 7;
pub u8, from into Range, rngx, set_rngx: 6, 5;
pub u8, from into Edges, edgx, set_edgx: 4, 3;
pub u8, from into UpdateTime, udtx, set_udtx: 2, 0;
}
#[derive(Clone, Copy, Debug, FromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum Range {
Rpm500 = 0b00,
#[default]
Rpm1000 = 0b01,
Rpm2000 = 0b10,
Rpm4000 = 0b11,
}
impl Range {
pub fn min_rpm(&self) -> u16 {
match self {
Range::Rpm500 => 500,
Range::Rpm1000 => 1000,
Range::Rpm2000 => 2000,
Range::Rpm4000 => 4000,
}
}
pub fn tach_count_multiplier(&self) -> u8 {
match self {
Range::Rpm500 => 1,
Range::Rpm1000 => 2,
Range::Rpm2000 => 4,
Range::Rpm4000 => 8,
}
}
}
#[derive(Clone, Copy, Debug, FromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum Edges {
Sample3 = 0b00,
#[default]
Sample5 = 0b01,
Sample7 = 0b10,
Sample9 = 0b11,
}
impl Edges {
pub fn num_edges(&self) -> u8 {
match self {
Edges::Sample3 => 3,
Edges::Sample5 => 5,
Edges::Sample7 => 7,
Edges::Sample9 => 9,
}
}
pub fn poles(&self) -> u8 {
match self {
Edges::Sample9 => 4,
Edges::Sample7 => 3,
Edges::Sample5 => 2,
Edges::Sample3 => 1,
}
}
pub fn tach_multiplier(&self) -> f64 {
match self {
Edges::Sample9 => 2.0,
Edges::Sample7 => 1.5,
Edges::Sample5 => 1.0,
Edges::Sample3 => 0.5,
}
}
}
#[derive(Clone, Copy, Debug, FromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum UpdateTime {
UpdateTime100ms = 0b000,
UpdateTime200ms = 0b001,
UpdateTime300ms = 0b010,
#[default]
UpdateTime400ms = 0b011,
UpdateTime500ms = 0b100,
UpdateTime800ms = 0b101,
UpdateTime1200ms = 0b110,
UpdateTime1600ms = 0b111,
}
impl UpdateTime {
pub fn millis(&self) -> u16 {
match self {
UpdateTime::UpdateTime100ms => 100,
UpdateTime::UpdateTime200ms => 200,
UpdateTime::UpdateTime300ms => 300,
UpdateTime::UpdateTime400ms => 400,
UpdateTime::UpdateTime500ms => 500,
UpdateTime::UpdateTime800ms => 800,
UpdateTime::UpdateTime1200ms => 1200,
UpdateTime::UpdateTime1600ms => 1600,
}
}
}