use super::super::{
BusOperation, DelayNs, Error, Ilps22qs, 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 {
InterruptCfg = 0x0B,
ThsPL = 0x0C,
ThsPH = 0x0D,
IfCtrl = 0x0E,
WhoAmI = 0x0F,
CtrlReg1 = 0x10,
CtrlReg2 = 0x11,
CtrlReg3 = 0x12,
FifoCtrl = 0x14,
FifoWtm = 0x15,
RefPL = 0x16,
RefPH = 0x17,
I3cIfCtrl = 0x19,
RpdsL = 0x1A,
RpdsH = 0x1B,
IntSource = 0x24,
FifoStatus1 = 0x25,
FifoStatus2 = 0x26,
Status = 0x27,
PressOutXl = 0x28,
PressOutL = 0x29,
PressOutH = 0x2A,
TempOutL = 0x2B,
TempOutH = 0x2C,
AnalogicHubDisable = 0x5F,
FifoDataOutPressXl = 0x78,
FifoDataOutPressL = 0x79,
FifoDataOutPressH = 0x7A,
}
#[register(address = Reg::InterruptCfg, access_type = "Ilps22qs<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 InterruptCfg {
#[bits(1)]
pub phe: u8,
#[bits(1)]
pub ple: u8,
#[bits(1)]
pub lir: u8,
#[bits(1, access = RO)]
not_used_01: u8,
#[bits(1)]
pub reset_az: u8,
#[bits(1)]
pub autozero: u8,
#[bits(1)]
pub reset_arp: u8,
#[bits(1)]
pub autorefp: u8,
}
#[register(address = Reg::ThsPL, access_type = "Ilps22qs<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 ThsP {
#[bits(15)]
pub ths: u16,
#[bits(1, access = RO)]
not_used_01: u8,
}
#[register(address = Reg::IfCtrl, access_type = "Ilps22qs<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 IfCtrl {
#[bits(1, access = RO)]
not_used_01: u8,
#[bits(1)]
pub cs_pu_dis: u8,
#[bits(2, access = RO)]
not_used_02: u8,
#[bits(1)]
pub sda_pu_en: u8,
#[bits(1)]
pub en_spi_read: u8,
#[bits(1)]
pub i2c_i3c_dis: u8,
#[bits(1, access = RO)]
not_used_03: u8,
}
#[register(address = Reg::CtrlReg1, access_type = "Ilps22qs<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 CtrlReg1 {
#[bits(3)]
pub avg: u8,
#[bits(4)]
pub odr: u8,
#[bits(1, access = RO)]
not_used_01: u8,
}
#[register(address = Reg::CtrlReg2, access_type = "Ilps22qs<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 CtrlReg2 {
#[bits(1)]
pub oneshot: u8,
#[bits(1, access = RO)]
not_used_01: u8,
#[bits(1)]
pub swreset: u8,
#[bits(1)]
pub bdu: u8,
#[bits(1)]
pub en_lpfp: u8,
#[bits(1)]
pub lfpf_cfg: u8,
#[bits(1)]
pub fs_mode: u8,
#[bits(1)]
pub boot: u8,
}
#[register(address = Reg::CtrlReg3, access_type = "Ilps22qs<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 CtrlReg3 {
#[bits(1)]
pub if_add_inc: u8,
#[bits(4, access = RO)]
not_used_01: u8,
#[bits(1)]
pub ah_qvar_p_auto_en: u8,
#[bits(1, access = RO)]
not_used_02: u8,
#[bits(1)]
pub ah_qvar_en: u8,
}
#[register(address = Reg::FifoCtrl, access_type = "Ilps22qs<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(2)]
pub f_mode: u8,
#[bits(1)]
pub trig_modes: u8,
#[bits(1)]
pub stop_on_wtm: u8,
#[bits(1)]
pub ah_qvar_p_fifo_en: u8,
#[bits(3, access = RO)]
not_used_01: u8,
}
#[register(address = Reg::FifoWtm, access_type = "Ilps22qs<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 FifoWtm {
#[bits(7)]
pub wtm: u8,
#[bits(1, access = RO)]
not_used_01: u8,
}
#[register(address = Reg::RefPL, access_type = "Ilps22qs<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 RefP {
#[bits(16, access = RO)]
pub refp: u16,
}
#[register(address = Reg::I3cIfCtrl, access_type = "Ilps22qs<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 I3cIfCtrl {
#[bits(5, access = RO)]
not_used_02: u8,
#[bits(1)]
pub asf_on: u8,
#[bits(2, access = RO)]
not_used_01: u8,
}
#[register(address = Reg::RpdsL, access_type = "Ilps22qs<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 Rpds {
#[bits(16, access = RO)]
pub rpds: i16,
}
#[register(address = Reg::IntSource, access_type = "Ilps22qs<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 IntSource {
#[bits(1, access = RO)]
pub ph: u8,
#[bits(1, access = RO)]
pub pl: u8,
#[bits(1, access = RO)]
pub ia: u8,
#[bits(4, access = RO)]
not_used_01: u8,
#[bits(1, access = RO)]
pub boot_on: u8,
}
#[register(address = Reg::FifoStatus1, access_type = "Ilps22qs<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 FifoStatus1 {
#[bits(8, access = RO)]
pub fss: u8,
}
#[register(address = Reg::FifoStatus2, access_type = "Ilps22qs<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 FifoStatus2 {
#[bits(5, access = RO)]
not_used_01: u8,
#[bits(1, access = RO)]
pub fifo_full_ia: u8,
#[bits(1, access = RO)]
pub fifo_ovr_ia: u8,
#[bits(1, access = RO)]
pub fifo_wtm_ia: u8,
}
#[register(address = Reg::Status, access_type = "Ilps22qs<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, access = RO)]
pub p_da: u8,
#[bits(1, access = RO)]
pub t_da: u8,
#[bits(2, access = RO)]
not_used_01: u8,
#[bits(1, access = RO)]
pub p_or: u8,
#[bits(1, access = RO)]
pub t_or: u8,
#[bits(2, access = RO)]
not_used_02: u8,
}
#[register(address = Reg::PressOutXl, access_type = "Ilps22qs<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u32, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u32, order = Lsb))]
pub struct PressOut {
#[offset_before(8)]
#[bits(32, access = RO)]
pub pout: i32,
}
#[register(address = Reg::TempOutL, access_type = "Ilps22qs<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 TempOut {
#[bits(16, access = RO)]
pub tout: i16,
}
#[register(address = Reg::FifoDataOutPressXl, access_type = "Ilps22qs<B, T, OnState>")]
#[cfg_attr(feature = "bit_order_msb", bitfield(u32, order = Msb))]
#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u32, order = Lsb))]
pub struct FifoDataOutPress {
#[offset_before(8)]
#[bits(32, access = RO)]
pub fifo_p: i32,
}
#[register(address = Reg::WhoAmI, access_type = "Ilps22qs<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 WhoAmI {
#[bits(8, access = RO)]
pub whoami: u8,
}
pub struct BusMode {
pub interface: Interface,
pub filter: Filter,
}
pub struct Stat {
pub sw_reset: u8,
pub boot: u8,
pub drdy_pres: u8,
pub drdy_temp: u8,
pub ovr_pres: u8,
pub ovr_temp: u8,
pub end_meas: u8,
pub ref_done: u8,
}
pub struct PinConf {
pub sda_pull_up: u8,
pub cs_pull_up: u8,
}
pub struct AllSources {
pub drdy_pres: u8,
pub drdy_temp: u8,
pub over_pres: u8,
pub under_pres: u8,
pub thrsld_pres: u8,
pub fifo_full: u8,
pub fifo_ovr: u8,
pub fifo_th: u8,
}
#[derive(Default)]
pub struct Md {
pub interleaved_mode: u8,
pub fs: Fs,
pub odr: Odr,
pub avg: Avg,
pub lpf: Lpf,
}
pub struct AhQvarData {
pub mv: f32,
pub lsb: i32,
pub raw: i32,
}
pub struct FifoMd {
pub operation: Operation,
pub watermark: u8,
}
#[derive(Default, Clone, Copy)]
pub struct FifoData {
pub hpa: f32,
pub lsb: i32,
pub raw: i32,
}
pub struct IntThMd {
pub threshold: u16,
pub over_th: u8,
pub under_th: u8,
}
pub struct RefMd {
pub apply_ref: ApplyRef,
pub get_ref: u8,
}
#[derive(Clone, Copy, Default)]
pub struct Pressure {
pub hpa: f32,
pub raw: i32,
}
#[derive(Clone, Copy, Default)]
pub struct Heat {
pub deg_c: f32,
pub raw: i16,
}
#[derive(Clone, Copy, Default)]
pub struct AhQvar {
pub lsb: i32,
}
#[derive(Clone, Copy, Default)]
pub struct Data {
pub pressure: Pressure,
pub heat: Heat,
pub ah_qvar: AhQvar,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Interface {
#[default]
SelByHw = 0x00,
Spi3w = 0x03,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Filter {
#[default]
Auto = 0x00,
AlwaysOn = 0x01,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq)]
pub enum Init {
DrvRdy = 0x00,
Boot = 0x01,
Reset = 0x02,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Fs {
#[default]
_1260hpa = 0x00,
_4060hpa = 0x01,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Odr {
#[default]
OneShot = 0x00,
_1hz = 0x01,
_4hz = 0x02,
_10hz = 0x03,
_25hz = 0x04,
_50hz = 0x05,
_75hz = 0x06,
_100hz = 0x07,
_200hz = 0x08,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Avg {
#[default]
_4 = 0,
_8 = 1,
_16 = 2,
_32 = 3,
_64 = 4,
_128 = 5,
_256 = 6,
_512 = 7,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Lpf {
#[default]
Disable = 0,
OdrDiv4 = 1,
OdrDiv9 = 3,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Operation {
#[default]
Bypass = 0,
Fifo = 1,
Stream = 2,
StreamToFifo = 7,
BypassToStream = 6,
BypassToFifo = 5,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum ApplyRef {
OutAndInterrupt = 0,
OnlyInterrupt = 1,
#[default]
RstRefs = 2,
}