use super::super::{
BusOperation, DelayNs, Error, Lps22df, 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,
CtrlReg4 = 0x13,
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,
FifoDataOutPressXl = 0x78,
FifoDataOutPressL = 0x79,
FifoDataOutPressH = 0x7A,
}
#[register(address = Reg::InterruptCfg, access_type = "Lps22df<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)]
pub 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 = "Lps22df<B, T, OnState>", override_type = u16)]
#[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)]
pub not_used_01: u8,
}
#[register(address = Reg::IfCtrl, access_type = "Lps22df<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)]
pub not_used_01: u8,
#[bits(1)]
pub cs_pu_dis: u8,
#[bits(1)]
pub int_pd_dis: u8,
#[bits(1)]
pub sdo_pu_en: u8,
#[bits(1)]
pub sda_pu_en: u8,
#[bits(1)]
pub sim: u8,
#[bits(1)]
pub i2c_i3c_dis: u8,
#[bits(1)]
pub int_en_i3c: u8,
}
#[register(address = Reg::WhoAmI, access_type = "Lps22df<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)]
pub id: u8,
}
#[register(address = Reg::CtrlReg1, access_type = "Lps22df<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)]
pub not_used_01: u8,
}
#[register(address = Reg::CtrlReg2, access_type = "Lps22df<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)]
pub 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, access = RO)]
pub not_used_02: u8,
#[bits(1)]
pub boot: u8,
}
#[register(address = Reg::CtrlReg3, access_type = "Lps22df<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(1)]
pub pp_od: u8,
#[bits(1, access = RO)]
pub not_used_02: u8,
#[bits(1)]
pub int_h_l: u8,
#[bits(4, access = RO)]
pub not_used_01: u8,
}
#[register(address = Reg::CtrlReg4, access_type = "Lps22df<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 CtrlReg4 {
#[bits(1)]
pub int_f_ovr: u8,
#[bits(1)]
pub int_f_wtm: u8,
#[bits(1)]
pub int_f_full: u8,
#[bits(1, access = RO)]
pub not_used_02: u8,
#[bits(1)]
pub int_en: u8,
#[bits(1)]
pub drdy: u8,
#[bits(1)]
pub drdy_pls: u8,
#[bits(1, access = RO)]
pub not_used_01: u8,
}
#[register(address = Reg::FifoCtrl, access_type = "Lps22df<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(4, access = RO)]
pub not_used_01: u8,
}
#[register(address = Reg::FifoWtm, access_type = "Lps22df<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)]
pub not_used_01: u8,
}
#[register(address = Reg::RefPL, access_type = "Lps22df<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)]
pub refp: i16,
}
#[register(address = Reg::I3cIfCtrl, access_type = "Lps22df<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(2)]
pub i3c_bus_avb_sel: u8,
#[bits(3, access = RO)]
pub not_used_02: u8,
#[bits(1)]
pub asf_on: u8,
#[bits(2, access = RO)]
pub not_used_01: u8,
}
#[register(address = Reg::RpdsL, access_type = "Lps22df<B, T, OnState>", override_type = u16)]
#[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)]
pub offset: i16,
}
#[register(address = Reg::IntSource, access_type = "Lps22df<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)]
pub ph: u8,
#[bits(1)]
pub pl: u8,
#[bits(1)]
pub ia: u8,
#[bits(4, access = RO)]
pub not_used_01: u8,
#[bits(1)]
pub boot_on: u8,
}
#[register(address = Reg::FifoStatus1, access_type = "Lps22df<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)]
pub fss: u8,
}
#[register(address = Reg::FifoStatus2, access_type = "Lps22df<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)]
pub not_used_01: u8,
#[bits(1)]
pub fifo_full_ia: u8,
#[bits(1)]
pub fifo_ovr_ia: u8,
#[bits(1)]
pub fifo_wtm_ia: u8,
}
#[register(address = Reg::Status, access_type = "Lps22df<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)]
pub p_da: u8,
#[bits(1)]
pub t_da: u8,
#[bits(2, access = RO)]
pub not_used_01: u8,
#[bits(1)]
pub p_or: u8,
#[bits(1)]
pub t_or: u8,
#[bits(2, access = RO)]
pub not_used_02: u8,
}
#[register(address = Reg::PressOutXl, access_type = "Lps22df<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)]
pub pressure: i32,
}
#[register(address = Reg::TempOutL, access_type = "Lps22df<B, T, OnState>", override_type = u16)]
#[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)]
pub temp_c: i16,
}
#[register(address = Reg::FifoDataOutPressXl, access_type = "Lps22df<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)]
pub pressure: i32,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Interface {
#[default]
SelByHw = 0x00,
Spi4w = 0x02,
Spi3w = 0x03,
IntPinOnI3c = 0x04,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Filter {
#[default]
FilterAuto = 0x00,
FilterAlwaysOn = 0x01,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum I3cIbiTime {
#[default]
Ibi50us = 0x0,
Ibi2us = 0x1,
Ibi1ms = 0x2,
Ibi25ms = 0x3,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, TryFrom)]
#[try_from(repr)]
pub enum Init {
DrvRdy = 0x00,
Boot = 0x01,
Reset = 0x02,
}
#[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 LowPassFilter {
#[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, TryFrom)]
#[try_from(repr)]
pub enum ApplyRef {
OutAndInterrupt = 0,
OnlyInterrupt = 1,
RstRefs = 2,
}
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum FifoEvent {
#[default]
Wtm = 0x0,
Full = 0x1,
}
#[derive(Default)]
pub struct BusMode {
pub interface: Interface,
pub filter: Filter,
pub i3c_ibi_time: I3cIbiTime,
}
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 int_push_pull: u8,
pub int_pull_down: u8,
pub sdo_pull_up: u8,
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 odr: Odr,
pub avg: Avg,
pub lpf: LowPassFilter,
}
#[derive(Copy, Clone)]
pub struct FifoData {
pub hpa: f32,
pub raw: i32,
}
pub struct IntMode {
pub int_latched: u8,
pub active_low: u8,
pub drdy_latched: u8,
}
#[derive(Default)]
pub struct PinIntRoute {
pub drdy_pres: u8,
pub fifo_th: u8,
pub fifo_ovr: u8,
pub fifo_full: u8,
}
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(Copy, Clone)]
pub struct Pressure {
pub hpa: f32,
pub raw: i32, }
#[derive(Copy, Clone)]
pub struct Heat {
pub deg_c: f32,
pub raw: i16,
}
#[derive(Copy, Clone)]
pub struct Data {
pub pressure: Pressure,
pub heat: Heat,
}