ilps22qs_rs/register/main.rs
1use super::super::{
2 BusOperation, DelayNs, Error, Ilps22qs, RegisterOperation, SensorOperation, bisync,
3 register::OnState,
4};
5
6use bitfield_struct::bitfield;
7use derive_more::TryFrom;
8use st_mem_bank_macro::register;
9
10/// Represents the register addresses for device configuration and data retrieval.
11#[repr(u8)]
12#[derive(Clone, Copy, PartialEq)]
13pub enum Reg {
14 /// Address for the interrupt configuration register.
15 InterruptCfg = 0x0B,
16 /// Address for the low threshold register.
17 ThsPL = 0x0C,
18 /// Address for the high threshold register.
19 ThsPH = 0x0D,
20 /// Address for the interface control register.
21 IfCtrl = 0x0E,
22 /// Address for the device identification register.
23 WhoAmI = 0x0F,
24 /// Address for the control register 1.
25 CtrlReg1 = 0x10,
26 /// Address for the control register 2.
27 CtrlReg2 = 0x11,
28 /// Address for the control register 3.
29 CtrlReg3 = 0x12,
30 /// Address for the FIFO control register.
31 FifoCtrl = 0x14,
32 /// Address for the FIFO watermark register.
33 FifoWtm = 0x15,
34 /// Address for the low reference register.
35 RefPL = 0x16,
36 /// Address for the high reference register.
37 RefPH = 0x17,
38 /// Address for the I3C interface control register.
39 I3cIfCtrl = 0x19,
40 /// Address for the low pressure offset register.
41 RpdsL = 0x1A,
42 /// Address for the high pressure offset register.
43 RpdsH = 0x1B,
44 /// Address for the interrupt source register.
45 IntSource = 0x24,
46 /// Address for the FIFO status register 1.
47 FifoStatus1 = 0x25,
48 /// Address for the FIFO status register 2.
49 FifoStatus2 = 0x26,
50 /// Address for the status register.
51 Status = 0x27,
52 /// Address for the pressure output XL register.
53 PressOutXl = 0x28,
54 /// Address for the pressure output L register.
55 PressOutL = 0x29,
56 /// Address for the pressure output H register.
57 PressOutH = 0x2A,
58 /// Address for the temperature output L register.
59 TempOutL = 0x2B,
60 /// Address for the temperature output H register.
61 TempOutH = 0x2C,
62 /// Address for disabling the analog hub.
63 AnalogicHubDisable = 0x5F,
64 /// Address for the FIFO data output pressure XL register.
65 FifoDataOutPressXl = 0x78,
66 /// Address for the FIFO data output pressure L register.
67 FifoDataOutPressL = 0x79,
68 /// Address for the FIFO data output pressure H register.
69 FifoDataOutPressH = 0x7A,
70}
71
72/// Interrupt mode configuration register.
73///
74/// Configuration options:
75/// * `phe` (1 bit): Enable interrupt generation on pressure high event.
76/// * `ple` (1 bit): Enable interrupt generation on pressure low event.
77/// * `lir` (1 bit): Latch interrupt request to the [`Reg1::IntSource`] register.
78/// * `reset_az` (1 bit): Reset AUTOZERO function.
79/// * `autozero` (1 bit): Enable AUTOZERO function.
80/// * `reset_arp` (1 bit): Reset AUTOREFP function.
81/// * `autorefp` (1 bit): Enable AUTOREFP function.
82///
83/// # Bit Order
84///
85/// The bit order for this struct can be configured using the `bit_order_msb` feature:
86/// * `Msb`: Most significant bit first.
87/// * `Lsb`: Least significant bit first (default).
88#[register(address = Reg::InterruptCfg, access_type = "Ilps22qs<B, T, OnState>")]
89#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
90#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
91pub struct InterruptCfg {
92 #[bits(1)]
93 pub phe: u8,
94 #[bits(1)]
95 pub ple: u8,
96 #[bits(1)]
97 pub lir: u8,
98 #[bits(1, access = RO)]
99 not_used_01: u8,
100 #[bits(1)]
101 pub reset_az: u8,
102 #[bits(1)]
103 pub autozero: u8,
104 #[bits(1)]
105 pub reset_arp: u8,
106 #[bits(1)]
107 pub autorefp: u8,
108}
109
110/// User-defined threshold value for pressure interrupt event.
111///
112/// # Configuration options:
113/// * `ths`: This register contains the threshold value for pressure interrupt
114/// generation.
115///
116/// # Bit Order
117///
118/// The bit order for this struct can be configured using the `bit_order_msb` feature:
119/// * `Msb`: Most significant bit first.
120/// * `Lsb`: Least significant bit first (default).
121#[register(address = Reg::ThsPL, access_type = "Ilps22qs<B, T, OnState>")]
122#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
123#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
124pub struct ThsP {
125 #[bits(15)]
126 pub ths: u16,
127 #[bits(1, access = RO)]
128 not_used_01: u8,
129}
130
131/// Interface control register.
132///
133/// # Configuration options:
134/// * `cs_pu_dis` (1 bit): Disable pull-up on CS pin.
135/// * `sda_pu_en` (1 bit): Enable pull-up on the SDA pin.
136/// * `en_spi_read` (1 bit): Enable SPI read mode. This bit must be set to 1 before using the
137/// 3-wire SPI interface.
138/// * `i2c_i3c_dis` (1 bit): Disable I2C and I3C digital interfaces.
139///
140/// # Bit Order
141///
142/// The bit order for this struct can be configured using the `bit_order_msb` feature:
143/// * `Msb`: Most significant bit first.
144/// * `Lsb`: Least significant bit first (default).
145#[register(address = Reg::IfCtrl, access_type = "Ilps22qs<B, T, OnState>")]
146#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
147#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
148pub struct IfCtrl {
149 #[bits(1, access = RO)]
150 not_used_01: u8,
151 #[bits(1)]
152 pub cs_pu_dis: u8,
153 #[bits(2, access = RO)]
154 not_used_02: u8,
155 #[bits(1)]
156 pub sda_pu_en: u8,
157 #[bits(1)]
158 pub en_spi_read: u8,
159 #[bits(1)]
160 pub i2c_i3c_dis: u8,
161 #[bits(1, access = RO)]
162 not_used_03: u8,
163}
164
165/// Control register 1.
166///
167/// Configuration options:
168/// * `avg` (3 bits): Average selection.
169/// * `odr` (4 bits): Output data rate selection.
170///
171/// The bit order for this struct can be configured using the `bit_order_msb` feature:
172/// * `Msb`: Most significant bit first.
173/// * `Lsb`: Least significant bit first (default).
174#[register(address = Reg::CtrlReg1, access_type = "Ilps22qs<B, T, OnState>")]
175#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
176#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
177pub struct CtrlReg1 {
178 #[bits(3)]
179 pub avg: u8,
180 #[bits(4)]
181 pub odr: u8,
182 #[bits(1, access = RO)]
183 not_used_01: u8,
184}
185
186/// Control register 2.
187///
188/// Configuration options:
189/// * `oneshot` (1 bit): Enables one-shot mode.
190/// * `swreset` (1 bit): Software reset. The bit is self-cleared when the reset is completed.
191/// * `bdu` (1 bit): Block data update.
192/// * `en_lpfp` (1 bit): Enables low-pass filter on pressure data.
193/// * `lfpf_cfg` (1 bit): Low-pass filter configuration.
194/// * `fs_mode` (1 bit): Full-scale selection.
195/// * `boot` (1 bit): Reboots memory content.
196///
197/// The bit order for this struct can be configured using the `bit_order_msb` feature:
198/// * `Msb`: Most significant bit first.
199/// * `Lsb`: Least significant bit first (default).
200#[register(address = Reg::CtrlReg2, access_type = "Ilps22qs<B, T, OnState>")]
201#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
202#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
203pub struct CtrlReg2 {
204 #[bits(1)]
205 pub oneshot: u8,
206 #[bits(1, access = RO)]
207 not_used_01: u8,
208 #[bits(1)]
209 pub swreset: u8,
210 #[bits(1)]
211 pub bdu: u8,
212 #[bits(1)]
213 pub en_lpfp: u8,
214 #[bits(1)]
215 pub lfpf_cfg: u8,
216 #[bits(1)]
217 pub fs_mode: u8,
218 #[bits(1)]
219 pub boot: u8,
220}
221
222/// Control register 3.
223///
224/// Configuration options:
225/// * `if_add_inc` (1 bit): Register address automatically incremented during a multiple byte
226/// access with a serial interface (I2C or SPI).
227/// * `ah_qvar_p_auto_en` (1 bit): Enables AH/Qvar and pressure hardware interleaved mode.
228/// * `ah_qvar_en` (1 bit): Enables AH (analog hub)/Qvar functions.
229///
230/// The bit order for this struct can be configured using the `bit_order_msb` feature:
231/// * `Msb`: Most significant bit first.
232/// * `Lsb`: Least significant bit first (default).
233#[register(address = Reg::CtrlReg3, access_type = "Ilps22qs<B, T, OnState>")]
234#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
235#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
236pub struct CtrlReg3 {
237 #[bits(1)]
238 pub if_add_inc: u8,
239 #[bits(4, access = RO)]
240 not_used_01: u8,
241 #[bits(1)]
242 pub ah_qvar_p_auto_en: u8,
243 #[bits(1, access = RO)]
244 not_used_02: u8,
245 #[bits(1)]
246 pub ah_qvar_en: u8,
247}
248
249/// FIFO control register.
250///
251/// Configuration options:
252/// * `f_mode` (2 bits): Selects triggered FIFO modes.
253/// * `trig_modes` (1 bit): Enables triggered FIFO modes.
254/// * `stop_on_wtm` (1 bit): Stop-on-FIFO watermark. Enables FIFO watermark level use.
255/// * `ah_qvar_p_fifo_en` (1 bit): Enables AH/Qvar and pressure hardware interleaved mode in FIFO
256/// buffer.
257///
258/// The bit order for this struct can be configured using the `bit_order_msb` feature:
259/// * `Msb`: Most significant bit first.
260/// * `Lsb`: Least significant bit first (default).
261#[register(address = Reg::FifoCtrl, access_type = "Ilps22qs<B, T, OnState>")]
262#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
263#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
264pub struct FifoCtrl {
265 #[bits(2)]
266 pub f_mode: u8,
267 #[bits(1)]
268 pub trig_modes: u8,
269 #[bits(1)]
270 pub stop_on_wtm: u8,
271 #[bits(1)]
272 pub ah_qvar_p_fifo_en: u8,
273 #[bits(3, access = RO)]
274 not_used_01: u8,
275}
276
277/// FIFO threshold setting register.
278///
279/// Configuration options:
280/// * `wtm` (7 bits): FIFO threshold. Watermark level setting.
281///
282/// The bit order for this struct can be configured using the `bit_order_msb` feature:
283/// * `Msb`: Most significant bit first.
284/// * `Lsb`: Least significant bit first (default).
285#[register(address = Reg::FifoWtm, access_type = "Ilps22qs<B, T, OnState>")]
286#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
287#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
288pub struct FifoWtm {
289 #[bits(7)]
290 pub wtm: u8,
291 #[bits(1, access = RO)]
292 not_used_01: u8,
293}
294
295/// Reference pressure data.
296///
297/// Configuration options:
298/// `refp`: This register contains the reference pressure value.
299///
300/// The bit order for this struct can be configured using the `bit_order_msb` feature:
301/// * `Msb`: Most significant bit first.
302/// * `Lsb`: Least significant bit first (default).
303#[register(address = Reg::RefPL, access_type = "Ilps22qs<B, T, OnState>")]
304#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
305#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
306pub struct RefP {
307 #[bits(16, access = RO)]
308 pub refp: u16,
309}
310
311/// Control register.
312///
313/// Configuration options:
314/// * `asf_on` (1 bits): Enable anti-spike filters.
315///
316/// The bit order for this struct can be configured using the `bit_order_msb` feature:
317/// * `Msb`: Most significant bit first.
318/// * `Lsb`: Least significant bit first (default).
319#[register(address = Reg::I3cIfCtrl, access_type = "Ilps22qs<B, T, OnState>")]
320#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
321#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
322pub struct I3cIfCtrl {
323 #[bits(5, access = RO)]
324 not_used_02: u8,
325 #[bits(1)]
326 pub asf_on: u8,
327 #[bits(2, access = RO)]
328 not_used_01: u8,
329}
330
331/// Pressure offset register.
332///
333/// This register contains the offset pressure value used for one-point calibration (OPC) after soldering.
334/// The offset value is a 16-bit signed integer expressed in two's complement format. It is composed of
335/// the RPDS_H and RPDS_L registers and is added directly to the compensated pressure data to improve accuracy.
336///
337/// # Fields
338///
339/// * `rpds` - The pressure offset calibration value as a 16-bit signed integer (read-only).
340#[register(address = Reg::RpdsL, access_type = "Ilps22qs<B, T, OnState>")]
341#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
342#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
343pub struct Rpds {
344 #[bits(16, access = RO)]
345 pub rpds: i16,
346}
347
348/// Interrupt source (read only) register for differential pressure. A read at this address clear
349/// the register itself.
350///
351/// Configuration options:
352/// * `ph` (1 bit): Differential pressure High.
353/// * `pl` (1 bit): Differential pressure Low.
354/// * `ia` (1 bit): Interrupt active.
355/// * `boot_on` (1 bit): Indication that Boot (reboot) phase is running.
356///
357/// The bit order for this struct can be configured using the `bit_order_msb` feature:
358/// * `Msb`: Most significant bit first.
359/// * `Lsb`: Least significant bit first (default).
360#[register(address = Reg::IntSource, access_type = "Ilps22qs<B, T, OnState>")]
361#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
362#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
363pub struct IntSource {
364 #[bits(1, access = RO)]
365 pub ph: u8,
366 #[bits(1, access = RO)]
367 pub pl: u8,
368 #[bits(1, access = RO)]
369 pub ia: u8,
370 #[bits(4, access = RO)]
371 not_used_01: u8,
372 #[bits(1, access = RO)]
373 pub boot_on: u8,
374}
375
376/// FIFO status register (read only).
377///
378/// Configuration options:
379/// * `fss` (8 bits): FIFO stored data level, number of unread samples stored in FIFO.
380///
381/// The bit order for this struct can be configured using the `bit_order_msb` feature:
382/// * `Msb`: Most significant bit first.
383/// * `Lsb`: Least significant bit first (default).
384#[register(address = Reg::FifoStatus1, access_type = "Ilps22qs<B, T, OnState>")]
385#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
386#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
387pub struct FifoStatus1 {
388 #[bits(8, access = RO)]
389 pub fss: u8,
390}
391
392/// FIFO status register (read only).
393///
394/// Configuration options:
395/// * `fifo_full_ia` (1 bit): FIFO full status.
396/// * `fifo_ovr_ia` (1 bit): FIFO overrun status.
397/// * `fifo_wtm_ia` (1 bit): FIFO threshold (watermark) status.
398///
399/// The bit order for this struct can be configured using the `bit_order_msb` feature:
400/// * `Msb`: Most significant bit first.
401/// * `Lsb`: Least significant bit first (default).
402#[register(address = Reg::FifoStatus2, access_type = "Ilps22qs<B, T, OnState>")]
403#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
404#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
405pub struct FifoStatus2 {
406 #[bits(5, access = RO)]
407 not_used_01: u8,
408 #[bits(1, access = RO)]
409 pub fifo_full_ia: u8,
410 #[bits(1, access = RO)]
411 pub fifo_ovr_ia: u8,
412 #[bits(1, access = RO)]
413 pub fifo_wtm_ia: u8,
414}
415
416/// Status register (read only).
417///
418/// This register is updated every ODR cycle.
419///
420/// Configuration options:
421/// * `p_da` (1 bit): Pressure data available.
422/// * `t_da` (1 bit): Temperature data available.
423/// * `p_or` (1 bit): Pressure data overrun.
424/// * `t_or` (1 bit): Temperature data overrun.
425///
426/// The bit order for this struct can be configured using the `bit_order_msb` feature:
427/// * `Msb`: Most significant bit first.
428/// * `Lsb`: Least significant bit first (default).
429#[register(address = Reg::Status, access_type = "Ilps22qs<B, T, OnState>")]
430#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
431#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
432pub struct Status {
433 #[bits(1, access = RO)]
434 pub p_da: u8,
435 #[bits(1, access = RO)]
436 pub t_da: u8,
437 #[bits(2, access = RO)]
438 not_used_01: u8,
439 #[bits(1, access = RO)]
440 pub p_or: u8,
441 #[bits(1, access = RO)]
442 pub t_or: u8,
443 #[bits(2, access = RO)]
444 not_used_02: u8,
445}
446
447/// Pressure output register.
448///
449/// This register contains the raw pressure output value from the sensor. The value is a 24-bit signed integer
450/// expressed in two's complement format, representing the measured pressure. It is composed of three registers:
451/// PRESS_OUT_H, PRESS_OUT_L, and PRESS_OUT_XL. The pressure output value is provided as the difference between
452/// the measured pressure and the offset stored in the RPDS registers.
453///
454/// # Fields
455///
456/// * `pout` - The raw pressure output value as a 32-bit signed integer (read-only).
457#[register(address = Reg::PressOutXl, access_type = "Ilps22qs<B, T, OnState>")]
458#[cfg_attr(feature = "bit_order_msb", bitfield(u32, order = Msb))]
459#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u32, order = Lsb))]
460pub struct PressOut {
461 #[offset_before(8)]
462 #[bits(32, access = RO)]
463 pub pout: i32,
464}
465
466/// Temperature output register.
467///
468/// This register contains the raw temperature output value from the sensor. The value is a 16-bit signed integer
469/// expressed in two's complement format, representing the measured temperature in units of 0.01 °C.
470///
471/// # Fields
472///
473/// * `tout` - The raw temperature output value as a 16-bit signed integer (read-only).
474#[register(address = Reg::TempOutL, access_type = "Ilps22qs<B, T, OnState>")]
475#[cfg_attr(feature = "bit_order_msb", bitfield(u16, order = Msb))]
476#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u16, order = Lsb))]
477pub struct TempOut {
478 #[bits(16, access = RO)]
479 pub tout: i16,
480}
481
482/// FIFO pressure data output register.
483///
484/// This register contains the raw pressure data stored in the FIFO buffer. The value is a 24-bit signed integer
485/// expressed in two's complement format, representing the pressure measurement. It is composed of three registers:
486/// FIFO_DATA_OUT_PRESS_H, FIFO_DATA_OUT_PRESS_L, and FIFO_DATA_OUT_PRESS_XL. The data is read-only and updated
487/// as new samples are stored in the FIFO.
488///
489/// # Fields
490///
491/// * `fifo_p` - The raw FIFO pressure output value as a 32-bit signed integer (read-only).
492#[register(address = Reg::FifoDataOutPressXl, access_type = "Ilps22qs<B, T, OnState>")]
493#[cfg_attr(feature = "bit_order_msb", bitfield(u32, order = Msb))]
494#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u32, order = Lsb))]
495pub struct FifoDataOutPress {
496 #[offset_before(8)]
497 #[bits(32, access = RO)]
498 pub fifo_p: i32,
499}
500
501/// Device identification register.
502///
503/// This register contains the "Who am I" identification value of the device. It is used to verify the presence
504/// and correct communication with the sensor. The value is fixed and read-only.
505///
506/// # Fields
507///
508/// * `whoami` - The device identification value as an 8-bit unsigned integer (read-only).
509#[register(address = Reg::WhoAmI, access_type = "Ilps22qs<B, T, OnState>")]
510#[cfg_attr(feature = "bit_order_msb", bitfield(u8, order = Msb))]
511#[cfg_attr(not(feature = "bit_order_msb"), bitfield(u8, order = Lsb))]
512pub struct WhoAmI {
513 #[bits(8, access = RO)]
514 pub whoami: u8,
515}
516
517/// The `BusMode` struct represents the configuration settings for the communication interface and filter mode of the device.
518///
519/// This struct is used to specify and retrieve the desired bus operating mode, including the type of communication interface
520/// and the filter settings.
521pub struct BusMode {
522 /// The communication interface type.
523 pub interface: Interface,
524 /// The filter settings for the communication interface.
525 pub filter: Filter,
526}
527
528/// The `Stat` struct represents the comprehensive status information of the device.
529///
530/// This struct is used to store various status indicators that provide detailed insights into the device's
531/// current operational state. It includes information about reset status, boot status, data readiness,
532/// measurement completion, and reference operations.
533pub struct Stat {
534 /// Software reset status.
535 pub sw_reset: u8,
536 /// Boot status.
537 pub boot: u8,
538 /// Data readiness for pressure.
539 pub drdy_pres: u8,
540 /// Data readiness for temperature.
541 pub drdy_temp: u8,
542 /// Overrun status for pressure data.
543 pub ovr_pres: u8,
544 /// Overrun status for temperature data.
545 pub ovr_temp: u8,
546 /// Measurement completion status.
547 pub end_meas: u8,
548 /// Reference operation completion status.
549 pub ref_done: u8,
550}
551
552/// The `PinConf` struct represents the electrical configuration settings for the device's configurable pins.
553///
554/// This struct is used to specify and retrieve the desired electrical settings for the device's pins,
555/// such as enabling or disabling pull-up resistors.
556pub struct PinConf {
557 /// Indicates whether the pull-up resistor for the SDA pin is enabled.
558 pub sda_pull_up: u8,
559 /// Indicates whether the pull-up resistor for the CS pin is enabled.
560 pub cs_pull_up: u8,
561}
562
563/// Represents the status of all interrupt sources for a device.
564///
565/// The `AllSources` struct provides detailed information about various interrupt conditions
566/// that can occur in the device. It includes indicators for data readiness, pressure thresholds,
567/// and FIFO conditions.
568pub struct AllSources {
569 /// Data readiness indicator for pressure measurements.
570 pub drdy_pres: u8,
571 /// Data readiness indicator for temperature measurements.
572 pub drdy_temp: u8,
573 /// Indicator for over-pressure condition.
574 pub over_pres: u8,
575 /// Indicator for under-pressure condition.
576 pub under_pres: u8,
577 /// Indicator for pressure threshold condition.
578 pub thrsld_pres: u8,
579 /// Indicator for FIFO full condition.
580 pub fifo_full: u8,
581 /// Indicator for FIFO overrun condition.
582 pub fifo_ovr: u8,
583 /// Indicator for FIFO threshold condition.
584 pub fifo_th: u8,
585}
586
587/// Represents the sensor conversion parameters.
588///
589/// The `Md` struct encapsulates various settings related to sensor conversion, including output data rate (ODR),
590/// averaging, low-pass filter settings, full-scale mode, and interleaved mode configuration. These parameters
591/// are crucial for configuring the sensor's data processing and acquisition behavior.
592#[derive(Default)]
593pub struct Md {
594 /// Specifies whether interleaved mode is enabled.
595 pub interleaved_mode: u8,
596 /// Represents the full-scale mode setting, which determines the pressure range.
597 pub fs: Fs,
598 /// Specifies the output data rate setting, which affects the frequency of data acquisition.
599 pub odr: Odr,
600 /// Represents the averaging setting, which determines the number of samples used for averaging.
601 pub avg: Avg,
602 /// Specifies the low-pass filter setting, which affects the filtering of sensor data.
603 pub lpf: Lpf,
604}
605
606/// Represents AH/QVAR data retrieved from the sensor.
607///
608/// It includes both raw and processed values, allowing for comprehensive analysis and application-specific processing.
609pub struct AhQvarData {
610 /// The converted AH/QVAR value in millivolts (mV)
611 pub mv: f32,
612 /// The least significant byte (LSB) of the AH/QVAR data
613 pub lsb: i32,
614 /// The raw AH/QVAR data value
615 pub raw: i32,
616}
617
618/// Represents the FIFO operation mode settings for the device.
619///
620/// The `FifoMd` struct encapsulates the configuration parameters for the FIFO (First-In, First-Out)
621/// operation mode.
622pub struct FifoMd {
623 /// Specifies the FIFO operation mode
624 pub operation: Operation,
625 /// Defines the watermark level for the FIFO buffer
626 pub watermark: u8,
627}
628
629/// Represents data retrieved from the FIFO buffer.
630///
631/// The `FifoData` struct encapsulates the processed data from the FIFO buffer, including both raw and
632/// converted values. It supports the representation of pressure and AH/QVAR data, depending on the
633/// sensor configuration.
634#[derive(Default, Clone, Copy)]
635pub struct FifoData {
636 /// The converted pressure value in hectopascals (hPa)
637 pub hpa: f32,
638 /// The least significant byte (LSB) of the AH/QVAR data
639 pub lsb: i32,
640 /// The raw data value
641 pub raw: i32,
642}
643
644/// Represents the configuration parameters for interrupt thresholds.
645///
646/// The `IntThMd` struct encapsulates the settings for the device's wake-up and wake-up-to-sleep
647/// threshold events, which are based on pressure levels.
648pub struct IntThMd {
649 /// Specifies the pressure threshold value that triggers interrupt events.
650 pub threshold: u16,
651 /// Indicates whether an over-threshold event is enabled
652 pub over_th: u8,
653 /// Indicates whether an under-threshold event is enabled (0 or 1).
654 pub under_th: u8,
655}
656
657/// Represents the reference mode settings for wake-up and wake-up-to-sleep functionality.
658///
659/// The `RefMd` struct encapsulates the configuration parameters for managing reference pressure levels,
660/// which are used to trigger wake-up and sleep events.
661pub struct RefMd {
662 /// Specifies how reference pressure levels are applied.
663 pub apply_ref: ApplyRef,
664 /// Indicates whether the device should obtain reference pressure levels, influencing how reference configurations are managed
665 pub get_ref: u8,
666}
667
668/// Represents pressure data retrieved from the sensor.
669///
670/// The `Pressure` struct encapsulates both raw and processed pressure data, providing a meaningful
671/// representation in hectopascals (hPa) for applications that require pressure measurements.
672#[derive(Clone, Copy, Default)]
673pub struct Pressure {
674 /// The converted pressure value in hectopascals (hPa).
675 pub hpa: f32,
676 /// The raw pressure data value.
677 pub raw: i32,
678}
679
680/// Represents temperature data retrieved from the sensor.
681///
682/// The `Heat` struct encapsulates both raw and processed temperature data, providing a meaningful
683/// representation in degrees Celsius (°C) for applications that require temperature measurements.
684#[derive(Clone, Copy, Default)]
685pub struct Heat {
686 /// The converted temperature value in degrees Celsius (°C).
687 pub deg_c: f32,
688 /// The raw temperature data value.
689 pub raw: i16,
690}
691
692/// Represents AH/QVAR data retrieved from the sensor.
693///
694/// The `AhQvar` struct encapsulates the least significant byte (LSB) of the AH/QVAR data, used for
695/// detailed data analysis in advanced sensing applications.
696#[derive(Clone, Copy, Default)]
697pub struct AhQvar {
698 /// The least significant byte (LSB) of the AH/QVAR data.
699 pub lsb: i32,
700}
701
702/// Represents the complete set of sensor data, including pressure, temperature, and AH/QVAR measurements.
703///
704/// The `Data` struct aggregates the processed sensor data, providing a comprehensive view of the
705/// sensor's output for applications that require multiple data types.
706#[derive(Clone, Copy, Default)]
707pub struct Data {
708 /// Contains the processed pressure data, including both raw and converted values.
709 pub pressure: Pressure,
710 /// Contains the processed temperature data, including both raw and converted values.
711 pub heat: Heat,
712 /// Contains the processed AH/QVAR data, focusing on the least significant byte (LSB).
713 pub ah_qvar: AhQvar,
714}
715
716/// Represents the communication interface mode for the device.
717#[repr(u8)]
718#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
719#[try_from(repr)]
720pub enum Interface {
721 /// The interface mode is selected by hardware configuration.
722 #[default]
723 SelByHw = 0x00,
724 /// The device operates in 3-wire SPI mode.
725 Spi3w = 0x03,
726}
727
728/// Represents the filter mode for the device's communication interface.
729#[repr(u8)]
730#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
731#[try_from(repr)]
732pub enum Filter {
733 /// The filter mode is automatically managed by the device.
734 #[default]
735 Auto = 0x00,
736 /// The filter is always active, providing continuous signal filtering.
737 AlwaysOn = 0x01,
738}
739
740/// Represents the initialization settings for the device.
741#[repr(u8)]
742#[derive(Clone, Copy, PartialEq)]
743pub enum Init {
744 /// Prepares the device for normal operation, ensuring it is ready to perform measurements.
745 DrvRdy = 0x00,
746 /// Initiates a boot procedure, typically used to restart the device and reload configuration settings.
747 Boot = 0x01,
748 /// Performs a software reset of the device, restoring it to its default state.
749 Reset = 0x02,
750}
751
752/// Represents the full-scale mode settings for the sensor.
753#[repr(u8)]
754#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
755#[try_from(repr)]
756pub enum Fs {
757 /// Full-scale mode set to 1260 hectopascals (hPa), suitable for standard pressure measurements.
758 #[default]
759 _1260hpa = 0x00,
760 /// Full-scale mode set to 4060 hectopascals (hPa), suitable for high-pressure measurements.
761 _4060hpa = 0x01,
762}
763
764/// Represents the output data rate (ODR) settings for the sensor.
765#[repr(u8)]
766#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
767#[try_from(repr)]
768pub enum Odr {
769 /// Performs a single measurement on demand, suitable for applications requiring precise, on-demand data.
770 #[default]
771 OneShot = 0x00,
772 /// Sets the data acquisition rate to 1 Hz.
773 _1hz = 0x01,
774 /// Sets the data acquisition rate to 4 Hz.
775 _4hz = 0x02,
776 /// Sets the data acquisition rate to 10 Hz.
777 _10hz = 0x03,
778 /// Sets the data acquisition rate to 25 Hz.
779 _25hz = 0x04,
780 /// Sets the data acquisition rate to 50 Hz.
781 _50hz = 0x05,
782 /// Sets the data acquisition rate to 75 Hz.
783 _75hz = 0x06,
784 /// Sets the data acquisition rate to 100 Hz.
785 _100hz = 0x07,
786 /// Sets the data acquisition rate to 200 Hz.
787 _200hz = 0x08,
788}
789
790/// Represents the averaging settings for the sensor.
791#[repr(u8)]
792#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
793#[try_from(repr)]
794pub enum Avg {
795 /// Averages 4 samples.
796 #[default]
797 _4 = 0,
798 /// Averages 8 samples.
799 _8 = 1,
800 /// Averages 16 samples.
801 _16 = 2,
802 /// Averages 32 samples.
803 _32 = 3,
804 /// Averages 64 samples.
805 _64 = 4,
806 /// Averages 128 samples.
807 _128 = 5,
808 /// Averages 256 samples.
809 _256 = 6,
810 /// Averages 512 samples.
811 _512 = 7,
812}
813
814/// Represents the low-pass filter settings for the sensor.
815#[repr(u8)]
816#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
817#[try_from(repr)]
818pub enum Lpf {
819 /// Disables the low-pass filter, allowing all frequencies to pass through.
820 #[default]
821 Disable = 0,
822 /// Applies a low-pass filter with a cutoff frequency at one-fourth of the output data rate (ODR).
823 OdrDiv4 = 1,
824 /// Applies a low-pass filter with a cutoff frequency at one-ninth of the output data rate (ODR).
825 OdrDiv9 = 3,
826}
827
828/// Represents the FIFO operation modes for the device.
829#[repr(u8)]
830#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
831#[try_from(repr)]
832pub enum Operation {
833 /// The FIFO buffer is bypassed.
834 #[default]
835 Bypass = 0,
836 /// Data is stored in the FIFO buffer.
837 Fifo = 1,
838 /// Data is streamed directly.
839 Stream = 2,
840 /// Data is streamed and then stored in the FIFO buffer.
841 StreamToFifo = 7,
842 /// The device transitions from bypass mode to stream mode.
843 BypassToStream = 6,
844 /// The device transitions from bypass mode to FIFO mode.
845 BypassToFifo = 5,
846}
847
848/// Represents the application of reference pressure levels for wake-up and wake-up-to-sleep functionality.
849#[repr(u8)]
850#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
851#[try_from(repr)]
852pub enum ApplyRef {
853 /// Applies reference pressure levels to both output and interrupt signals.
854 OutAndInterrupt = 0,
855 /// Applies reference pressure levels only to interrupt signals.
856 OnlyInterrupt = 1,
857 /// Resets reference configurations, clearing any previously set reference levels.
858 #[default]
859 RstRefs = 2,
860}