use super::super::{
BusOperation, DelayNs, Error, Iis2dlpc, RegisterOperation, SensorOperation, bisync,
register::OnState,
};
use bitfield_struct::bitfield;
use derive_more::TryFrom;
use st_mem_bank_macro::register;
#[repr(u8)]
#[derive(Clone, Copy, PartialEq)]
pub enum Reg {
OutTL = 0x0D,
OutTH = 0x0E,
WhoAmI = 0x0F,
Ctrl1 = 0x20,
Ctrl2 = 0x21,
Ctrl3 = 0x22,
Ctrl4Int1PadCtrl = 0x23,
Ctrl5Int2PadCtrl = 0x24,
Ctrl6 = 0x25,
OutT = 0x26,
Status = 0x27,
OutXL = 0x28,
OutXH = 0x29,
OutYL = 0x2A,
OutYH = 0x2B,
OutZL = 0x2C,
OutZH = 0x2D,
FifoCtrl = 0x2E,
FifoSamples = 0x2F,
TapThsX = 0x30,
TapThsY = 0x31,
TapThsZ = 0x32,
IntDur = 0x33,
WakeUpThs = 0x34,
WakeUpDur = 0x35,
FreeFall = 0x36,
StatusDup = 0x37,
WakeUpSrc = 0x38,
TapSrc = 0x39,
SixdSrc = 0x3A,
AllIntSrc = 0x3B,
XOfsUsr = 0x3C,
YOfsUsr = 0x3D,
ZOfsUsr = 0x3E,
Ctrl7 = 0x3F,
}
#[register(address = Reg::OutTL, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
pub struct OutT {
#[bits(4, access = RO, default = 0)]
not_used: u8,
#[bits(12, access = RO, default = 0)]
pub temp: i16,
}
#[register(address = Reg::Ctrl1, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Ctrl1 {
#[bits(2, default = 0)]
pub lp_mode: u8,
#[bits(2, default = 0)]
pub mode: u8,
#[bits(4, default = 0)]
pub odr: u8,
}
#[register(address = Reg::Ctrl2, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Ctrl2 {
#[bits(1, default = 0)]
pub sim: u8,
#[bits(1, default = 0)]
pub i2c_disable: u8,
#[bits(1, default = 1)]
pub if_add_inc: u8,
#[bits(1, default = 0)]
pub bdu: u8,
#[bits(1, default = 0)]
pub cs_pu_disc: u8,
#[bits(1, access = RO, default = 0)]
not_used_01: u8,
#[bits(1, default = 0)]
pub soft_reset: u8,
#[bits(1, default = 0)]
pub boot: u8,
}
#[register(address = Reg::Ctrl3, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Ctrl3 {
#[bits(2, default = 0)]
pub slp_mode: u8,
#[bits(1, access = RO, default = 0)]
not_used_01: u8,
#[bits(1, default = 0)]
pub h_lactive: u8,
#[bits(1, default = 0)]
pub lir: u8,
#[bits(1, default = 0)]
pub pp_od: u8,
#[bits(2, default = 0)]
pub st: u8,
}
#[register(address = Reg::Ctrl4Int1PadCtrl, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Ctrl4Int1PadCtrl {
#[bits(1, default = 0)]
pub int1_drdy: u8,
#[bits(1, default = 0)]
pub int1_fth: u8,
#[bits(1, default = 0)]
pub int1_diff5: u8,
#[bits(1, default = 0)]
pub int1_tap: u8,
#[bits(1, default = 0)]
pub int1_ff: u8,
#[bits(1, default = 0)]
pub int1_wu: u8,
#[bits(1, default = 0)]
pub int1_single_tap: u8,
#[bits(1, default = 0)]
pub int1_6d: u8,
}
#[register(address = Reg::Ctrl5Int2PadCtrl, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Ctrl5Int2PadCtrl {
#[bits(1, default = 0)]
pub int2_drdy: u8,
#[bits(1, default = 0)]
pub int2_fth: u8,
#[bits(1, default = 0)]
pub int2_diff5: u8,
#[bits(1, default = 0)]
pub int2_ovr: u8,
#[bits(1, default = 0)]
pub int2_drdy_t: u8,
#[bits(1, default = 0)]
pub int2_boot: u8,
#[bits(1, default = 0)]
pub int2_sleep_chg: u8,
#[bits(1, default = 0)]
pub int2_sleep_state: u8,
}
#[register(address = Reg::Ctrl6, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Ctrl6 {
#[bits(2, access = RO, default = 0)]
not_used_01: u8,
#[bits(1, default = 0)]
pub low_noise: u8,
#[bits(1, default = 0)]
pub fds: u8,
#[bits(2, default = 0)]
pub fs: u8,
#[bits(2, default = 0)]
pub bw_filt: u8,
}
#[register(address = Reg::Status, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Status {
#[bits(1, default = 0, access = RO)]
pub drdy: u8,
#[bits(1, default = 0, access = RO)]
pub ff_ia: u8,
#[bits(1, default = 0, access = RO)]
pub six_d_ia: u8,
#[bits(1, default = 0, access = RO)]
pub single_tap: u8,
#[bits(1, default = 0, access = RO)]
pub double_tap: u8,
#[bits(1, default = 0, access = RO)]
pub sleep_state: u8,
#[bits(1, default = 0, access = RO)]
pub wu_ia: u8,
#[bits(1, default = 0, access = RO)]
pub fifo_ths: u8,
}
#[register(address = Reg::OutXL, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
pub struct OutX {
#[bits(2, access = RO, default = 0)]
not_used: u8,
#[bits(14, access = RO, default = 0)]
pub x: i16,
}
#[register(address = Reg::OutYL, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
pub struct OutY {
#[bits(2, access = RO, default = 0)]
not_used: u8,
#[bits(14, access = RO, default = 0)]
pub y: i16,
}
#[register(address = Reg::OutZL, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
pub struct OutZ {
#[bits(2, access = RO, default = 0)]
not_used: u8,
#[bits(14, access = RO, default = 0)]
pub z: i16,
}
#[register(address = Reg::FifoCtrl, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct FifoCtrl {
#[bits(5, default = 0)]
pub fth: u8,
#[bits(3, default = 0)]
pub fmode: u8,
}
#[register(address = Reg::FifoSamples, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct FifoSamples {
#[bits(6, default = 0, access = RO)]
pub diff: u8,
#[bits(1, default = 0, access = RO)]
pub fifo_ovr: u8,
#[bits(1, default = 0, access = RO)]
pub fifo_fth: u8,
}
#[register(address = Reg::TapThsX, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct TapThsX {
#[bits(5, default = 0)]
pub tap_thsx: u8,
#[bits(2, default = 0)]
pub six_d_ths: u8,
#[bits(1, default = 0)]
pub four_d_en: u8,
}
#[register(address = Reg::TapThsY, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct TapThsY {
#[bits(5, default = 0)]
pub tap_thsy: u8,
#[bits(3, default = 0)]
pub tap_prior: u8,
}
#[register(address = Reg::TapThsZ, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct TapThsZ {
#[bits(5, default = 0)]
pub tap_thsz: u8,
#[bits(1, default = 0)]
pub tap_z_en: u8,
#[bits(1, default = 0)]
pub tap_y_en: u8,
#[bits(1, default = 0)]
pub tap_x_en: u8,
}
#[register(address = Reg::IntDur, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct IntDur {
#[bits(2, default = 0)]
pub shock: u8,
#[bits(2, default = 0)]
pub quiet: u8,
#[bits(4, default = 0)]
pub latency: u8,
}
#[register(address = Reg::WakeUpThs, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct WakeUpThs {
#[bits(6, default = 0)]
pub wk_ths: u8,
#[bits(1, default = 0)]
pub sleep_on: u8,
#[bits(1, default = 0)]
pub single_double_tap: u8,
}
#[register(address = Reg::WakeUpDur, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct WakeUpDur {
#[bits(4, default = 0)]
pub sleep_dur: u8,
#[bits(1, default = 0)]
pub stationary: u8,
#[bits(2, default = 0)]
pub wake_dur: u8,
#[bits(1, default = 0)]
pub ff_dur: u8,
}
#[register(address = Reg::FreeFall, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct FreeFall {
#[bits(3, default = 0)]
pub ff_ths: u8,
#[bits(5, default = 0)]
pub ff_dur: u8,
}
#[register(address = Reg::StatusDup, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct StatusDup {
#[bits(1, default = 0, access = RO)]
pub drdy: u8,
#[bits(1, default = 0, access = RO)]
pub ff_ia: u8,
#[bits(1, default = 0, access = RO)]
pub six_d_ia: u8,
#[bits(1, default = 0, access = RO)]
pub single_tap: u8,
#[bits(1, default = 0, access = RO)]
pub double_tap: u8,
#[bits(1, default = 0, access = RO)]
pub sleep_state_ia: u8,
#[bits(1, default = 0, access = RO)]
pub drdy_t: u8,
#[bits(1, default = 0, access = RO)]
pub ovr: u8,
}
#[register(address = Reg::WakeUpSrc, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct WakeUpSrc {
#[bits(1, default = 0, access = RO)]
pub z_wu: u8,
#[bits(1, default = 0, access = RO)]
pub y_wu: u8,
#[bits(1, default = 0, access = RO)]
pub x_wu: u8,
#[bits(1, default = 0, access = RO)]
pub wu_ia: u8,
#[bits(1, default = 0, access = RO)]
pub sleep_state_ia: u8,
#[bits(1, default = 0, access = RO)]
pub ff_ia: u8,
#[bits(2, access = RO, default = 0)]
not_used_01: u8,
}
#[register(address = Reg::TapSrc, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct TapSrc {
#[bits(1, default = 0, access = RO)]
pub z_tap: u8,
#[bits(1, default = 0, access = RO)]
pub y_tap: u8,
#[bits(1, default = 0, access = RO)]
pub x_tap: u8,
#[bits(1, default = 0, access = RO)]
pub tap_sign: u8,
#[bits(1, default = 0, access = RO)]
pub double_tap: u8,
#[bits(1, default = 0, access = RO)]
pub single_tap: u8,
#[bits(1, default = 0, access = RO)]
pub tap_ia: u8,
#[bits(1, access = RO, default = 0)]
not_used_01: u8,
}
#[register(address = Reg::SixdSrc, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct SixdSrc {
#[bits(1, default = 0, access = RO)]
pub xl: u8,
#[bits(1, default = 0, access = RO)]
pub xh: u8,
#[bits(1, default = 0, access = RO)]
pub yl: u8,
#[bits(1, default = 0, access = RO)]
pub yh: u8,
#[bits(1, default = 0, access = RO)]
pub zl: u8,
#[bits(1, default = 0, access = RO)]
pub zh: u8,
#[bits(1, default = 0, access = RO)]
pub six_d_ia: u8,
#[bits(1, access = RO, default = 0)]
not_used_01: u8,
}
#[register(address = Reg::AllIntSrc, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct AllIntSrc {
#[bits(1, default = 0, access = RO)]
pub ff_ia: u8,
#[bits(1, default = 0, access = RO)]
pub wu_ia: u8,
#[bits(1, default = 0, access = RO)]
pub single_tap: u8,
#[bits(1, default = 0, access = RO)]
pub double_tap: u8,
#[bits(1, default = 0, access = RO)]
pub six_d_ia: u8,
#[bits(1, default = 0, access = RO)]
pub sleep_change_ia: u8,
#[bits(2, access = RO, default = 0)]
not_used_01: u8,
}
#[register(address = Reg::XOfsUsr, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct XOfsUsr {
#[bits(8, default = 0)]
pub x_ofs_usr: i8,
}
#[register(address = Reg::YOfsUsr, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct YOfsUsr {
#[bits(8, default = 0)]
pub y_ofs_usr: i8,
}
#[register(address = Reg::ZOfsUsr, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct ZOfsUsr {
#[bits(8, default = 0)]
pub z_ofs_usr: i8,
}
#[register(address = Reg::Ctrl7, access_type = "Iis2dlpc<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
pub struct Ctrl7 {
#[bits(1, default = 0)]
pub lpass_on6d: u8,
#[bits(1, default = 0)]
pub hp_ref_mode: u8,
#[bits(1, default = 0)]
pub usr_off_w: u8,
#[bits(1, default = 0)]
pub usr_off_on_wu: u8,
#[bits(1, default = 0)]
pub usr_off_on_out: u8,
#[bits(1, default = 0)]
pub interrupts_enable: u8,
#[bits(1, default = 0)]
pub int2_on_int1: u8,
#[bits(1, default = 0)]
pub drdy_pulsed: u8,
}
pub struct AllSources {
pub status_dup: StatusDup,
pub wake_up_src: WakeUpSrc,
pub tap_src: TapSrc,
pub sixd_src: SixdSrc,
pub all_int_src: AllIntSrc,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Mode {
HighPerformance = 0x04,
ContLowPwr4 = 0x03,
ContLowPwr3 = 0x02,
ContLowPwr2 = 0x01,
#[default]
ContLowPwr12bit = 0x00,
SingleLowPwr4 = 0x0B,
SingleLowPwr3 = 0x0A,
SingleLowPwr2 = 0x09,
SingleLowPwr12bit = 0x08,
HighPerformanceLowNoise = 0x14,
ContLowPwrLowNoise4 = 0x13,
ContLowPwrLowNoise3 = 0x12,
ContLowPwrLowNoise2 = 0x11,
ContLowPwrLowNoise12bit = 0x10,
SingleLowPwrLowNoise4 = 0x1B,
SingleLowPwrLowNoise3 = 0x1A,
SingleLowPwrLowNoise2 = 0x19,
SingleLowLowNoisePwr12bit = 0x18,
}
impl Mode {
pub fn new(mode: u8, lp_mode: u8, low_noise: u8) -> Self {
Self::try_from((low_noise << 4) + (mode << 2) + lp_mode).unwrap_or_default()
}
pub fn mode(&self) -> u8 {
(*self as u8 & 0x0C) >> 2
}
pub fn lp_mode(&self) -> u8 {
*self as u8 & 0x3
}
pub fn low_noise(&self) -> u8 {
(*self as u8 & 0x10) >> 4
}
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Odr {
#[default]
Off = 0x00,
_1_6hzLpOnly = 0x01,
_12_5hz = 0x02,
_25hz = 0x03,
_50hz = 0x04,
_100hz = 0x05,
_200hz = 0x06,
_400hz = 0x07,
_800hz = 0x08,
_1_6khz = 0x09,
SetSwTrig = 0x12,
SetPinTrig = 0x22,
}
impl Odr {
pub fn new(odr: u8, slp_mode: u8) -> Self {
Self::try_from((slp_mode << 4) + odr).unwrap_or_default()
}
pub fn odr(&self) -> u8 {
*self as u8 & 0xF
}
pub fn slp_mode(&self) -> u8 {
(*self as u8 & 0x30) >> 4
}
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Fs {
#[default]
_2g = 0,
_4g = 1,
_8g = 2,
_16g = 3,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum UsrOffW {
#[default]
_977ugLsb = 0,
_15_6mgLsb = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum St {
#[default]
Disable = 0,
Positive = 1,
Negative = 2,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum DrdyPulsed {
#[default]
Latched = 0,
Pulsed = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Fds {
#[default]
LpfOnOut = 0x00,
UserOffsetOnOut = 0x01,
HighPassOnOut = 0x10,
}
impl Fds {
pub fn new(fds: u8, usr_off_on_out: u8) -> Self {
Self::try_from((fds << 4) + usr_off_on_out).unwrap_or_default()
}
pub fn fds(&self) -> u8 {
((*self as u8) & 0x10) >> 4
}
pub fn usr_off_on_out(&self) -> u8 {
*self as u8 & 0x01
}
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum BwFilt {
#[default]
OdrDiv2 = 0,
OdrDiv4 = 1,
OdrDiv10 = 2,
OdrDiv20 = 3,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Sim {
#[default]
Spi4Wire = 0,
Spi3Wire = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum I2cDisable {
#[default]
I2cEnable = 0,
I2cDisable = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum CsPuDisc {
#[default]
PullUpConnect = 0,
PullUpDisconnect = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum HLactive {
#[default]
ActiveHigh = 0,
ActiveLow = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Lir {
#[default]
Pulsed = 0,
Latched = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum PpOd {
#[default]
PushPull = 0,
OpenDrain = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum UsrOffOnWu {
#[default]
HpFeed = 0,
UserOffsetFeed = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum SleepOn {
#[default]
NoDetection = 0,
ActInact = 1,
StatMotion = 3,
}
impl SleepOn {
pub fn new(sleep_on: u8, stationary: u8) -> Self {
Self::try_from((stationary << 1) + sleep_on).unwrap_or_default()
}
pub fn sleep_on(&self) -> u8 {
(*self as u8) & 0x01
}
pub fn stationary(&self) -> u8 {
((*self as u8) & 0x02) >> 1
}
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum TapPrior {
#[default]
Xyz = 0,
Yxz = 1,
Xzy = 2,
Zyx = 3,
Yzx = 5,
Zxy = 6,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum SingleDoubleTap {
#[default]
OnlySingle = 0,
BothSingleDouble = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum LpassOn6d {
#[default]
OdrDiv2Feed = 0,
Lpf2Feed = 1,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum FfThs {
#[default]
_5Lsb = 0,
_7Lsb = 1,
_8Lsb = 2,
_10Lsb = 3,
_11Lsb = 4,
_13Lsb = 5,
_15Lsb = 6,
_16Lsb = 7,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Fmode {
#[default]
BypassMode = 0,
FifoMode = 1,
StreamToFifoMode = 3,
BypassToStreamMode = 4,
StreamMode = 6,
}