pub enum ConvAvg {
Avg1x = 0x00,
Avg2x = 0x01,
Avg4x = 0x02,
Avg8x = 0x03,
Avg16x = 0x04,
Avg32x = 0x05,
}
pub enum MagTempco {
CurrentSensor = 0x00,
NdBFe = 0x01,
Ceramic = 0x03,
}
pub enum OperatingMode {
Configuration = 0x00,
Standby = 0x01,
Active = 0x02,
ActiveTrigger = 0x03,
WakeupAndSleep = 0x04,
Sleep = 0x05,
DeepSleep = 0x06,
}
pub enum TRate {
SameRate = 0x00,
OncePerConvSet = 0x01,
}
pub struct DeviceConfig {
config: u16,
}
impl DeviceConfig {
pub fn new() -> Self {
let config = 0x00;
DeviceConfig { config }
}
pub fn form_u16(config: u16) -> Self {
DeviceConfig { config }
}
pub fn to_u16(&self) -> u16 {
self.config
}
pub fn set_conv_avg(mut self, conv_avg: ConvAvg) -> Self {
self.config = self.config & !(0b111 << 12) | ((conv_avg as u16) << 12);
self
}
pub fn set_mag_tempco(mut self, mag_tempco: MagTempco) -> Self {
self.config = self.config & !(0b11 << 8) | ((mag_tempco as u16) << 8);
self
}
pub fn set_operating_mode(mut self, operating_mode: OperatingMode) -> Self {
self.config = self.config & !(0b111 << 4) | ((operating_mode as u16) << 4);
self
}
pub fn set_t_en(mut self, t_en: bool) -> Self {
self.config = self.config & !(0b1 << 3) | ((t_en as u16) << 3);
self
}
pub fn set_t_rate(mut self, t_rate: TRate) -> Self {
self.config = self.config & !(0b1 << 2) | ((t_rate as u16) << 2);
self
}
pub fn set_t_limit_check_en(mut self, t_limit_check_en: bool) -> Self {
self.config = self.config & !(0b1 << 1) | ((t_limit_check_en as u16) << 1);
self
}
pub fn set_t_comp_en(mut self, comp_en: bool) -> Self {
self.config = self.config & !(0b1) | (comp_en as u16);
self
}
}
impl Default for DeviceConfig {
fn default() -> Self {
DeviceConfig::new()
}
}