lis2dw12_i2c/registers.rs
1use bilge::prelude::*;
2
3pub const WHO_AM_I_EXPECTED: u8 = 0x44;
4
5#[repr(u8)]
6#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
7pub enum Register {
8 TempOutLow = 0x0D, // OUT_T_L
9 TempOutHigh = 0x0E, // OUT_T_H
10 WhoAmI = 0x0F, // WHO_AM_I
11 Control1 = 0x20, // CTRL1
12 Control2 = 0x21, // CTRL2
13 Control3 = 0x22, // CTRL3
14 Control4Interrupt1 = 0x23, // CTRL4_INT1_PAD_CTRL
15 Control5Interrupt2 = 0x24, // CTRL5_INT2_PAD_CTRL
16 Control6 = 0x25, // CTRL6
17 TempOut = 0x26, // OUT_T
18 Status = 0x27, // STATUS
19 XOutLow = 0x28, // OUT_X_L
20 XOutHigh = 0x29, // OUT_X_H
21 YOutLow = 0x2A, // OUT_Y_L
22 YOutHigh = 0x2B, // OUT_Y_H
23 ZOutLow = 0x2C, // OUT_Z_L
24 ZOutHigh = 0x2D, // OUT_Z_H
25 FifoControl = 0x2E, // FIFO_CTRL
26 FifoSamples = 0x2F, // FIFO_SAMPLES
27 TapThresholdX = 0x30, // TAP_THS_X
28 TapThresholdY = 0x31, // TAP_THS_Y
29 TapThresholdZ = 0x32, // TAP_THS_Z
30 InterruptDuration = 0x33, // INT_DUR
31 WakeUpThreshold = 0x34, // WAKE_UP_THS
32 WakeUpDuration = 0x35, // WAKE_UP_DUR
33 FreeFall = 0x36, // FREE_FALL
34 EventStatus = 0x37, // STATUS_DUP
35 WakeUpSource = 0x38, // WAKE_UP_SRC
36 TapSource = 0x39, // TAP_SRC
37 SixDimSource = 0x3A, // SIXD_SRC
38 AllInterruptSource = 0x3B, // ALL_INT_SRC
39 XOffsetUser = 0x3C, // X_OFS_USR
40 YOffsetUser = 0x3D, // Y_OFS_USR
41 ZOffsetUser = 0x3E, // Z_OFS_USR
42 Control7 = 0x3F, // CTRL7
43}
44
45#[bitsize(1)]
46#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
47pub enum Reserved0 {
48 #[fallback]
49 Res0 = 0b0,
50}
51
52/// Control Register 1 (0x20 R/W)
53/// ODR3 ODR2 ODR1 ODR0 MODE1 MODE0 LP_MODE1 LP_MODE0
54#[bitsize(8)]
55#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
56pub struct ControlReg1 {
57 /// Low-power mode selection
58 pub low_power_mode: Control1LowPowerMode,
59
60 /// Mode and resolution selection
61 pub mode: Control1ModeSelect,
62
63 /// Power mode / Data Rate Configuration
64 pub data_rate: Control1DataRate,
65}
66
67#[bitsize(4)]
68#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
69pub enum Control1DataRate {
70 PowerDown = 0b0000, // Power down
71 Hi12p5Lo1p6Hz = 0b0001, // High-Performance: 12.5 Hz, Low-Power: 1.6 Hz
72 HiLo12p5Hz = 0b0010, // 12.5 Hz
73 HiLo25Hz = 0b0011, // 25 Hz
74 HiLo50Hz = 0b0100, // 50 Hz
75 HiLo100Hz = 0b0101, // 100 Hz
76 HiLo200Hz = 0b0110, // 200 Hz
77 Hi400Lo200Hz = 0b0111, // High-Performance: 400 Hz, Low-Power: 200 Hz
78 Hi800Lo200Hz = 0b1000, // High-Performance: 800 Hz, Low-Power: 200 Hz
79 Hi1600Lo200Hz = 0b1001, // High-Performance: 1600 Hz, Low-Power: 200 Hz
80 #[fallback]
81 Unused,
82}
83
84#[bitsize(2)]
85#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
86pub enum Control1ModeSelect {
87 LowPower = 0b00, // 12/14 bit resolution
88 HighPerformance = 0b01, // 14 bit resolution
89 OnDemand = 0b10, // 12/14 bit resolution
90 Unused = 0b11,
91}
92
93#[bitsize(2)]
94#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
95pub enum Control1LowPowerMode {
96 LowPower1 = 0b00, // 12 bit resolution
97 LowPower2 = 0b01, // 14 bit resolution
98 LowPower3 = 0b10, // 14 bit resolution
99 LowPower4 = 0b11, // 14 bit resolution
100}
101
102/// Control Register 2 (0x21 R/W)
103/// BOOT SOFT_RESET RES0 CS_PU_DISC BDU IF_ADD_INC I2C_DISABLE SIM
104#[bitsize(8)]
105#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
106pub struct ControlReg2 {
107 // SPI serial interface mode selection
108 // 0: 4-wire interface; 1: 3-wire interface
109 pub sim: bool,
110
111 // Disable I2C communication protocol
112 // 0: SPI and I2C interfaces enabled; 1: I2C mode disabled)
113 pub i2c_disable: bool,
114
115 // Register address automatically incremented during multiple byte access with a serial interface
116 // Default: 1
117 pub if_add_inc: bool,
118
119 // Block Data Update
120 // 0: continuous update; 1: output registers not updated until MSB and LSB read
121 pub bdu: bool,
122
123 // Disconnect CS pull-up
124 pub cs_pu_disc: bool,
125
126 // This bit must be set to 0 for the correct operation of the device
127 pub res0: Reserved0,
128
129 // Soft reset acts as reset for all control registers, then goes to 0
130 pub soft_reset: bool,
131
132 // Boot enables retrieving the correct trimming parameters from nonvolatile memory into
133 // registers where trimming parameters are stored.
134 // Once the operation is over, this bit automatically returns to 0
135 pub boot: bool,
136}
137
138/// Control Register 3 (0x22 R/W)
139/// ST1 ST0 PP_OD LIR H_LACTIVE RES0 SLP_MODE_SEL SLP_MODE_1
140#[bitsize(8)]
141#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
142pub struct ControlReg3 {
143 // Single data conversion on-demand mode enable.
144 // When SLP_MODE_SEL = 1 and this bit is set to 1 logic, single data conversion on-demand mode starts.
145 // When accelerometer data are available in the registers, this bit is set to 0 automatically and
146 // the device is ready for another triggered session
147 pub slp_mode_1: bool,
148
149 // Single data conversion on demand mode selection
150 // 0: enabled with external trigger on INT2
151 // 1: enabled by I2C/SPI writing SLP_MODE_1 to 1
152 pub slp_mode_sel: bool,
153
154 // Reserved 0
155 pub res0: Reserved0,
156
157 // Interrupt active high (0) or low (1)
158 pub active_hi_lo: bool,
159
160 // Latched interrupt. Switches between latched (1 logic) and pulsed (0 logic) mode for function
161 // source signals and interrupts routed to pins (wake-up, single/double-tap)
162 pub lir: bool,
163
164 // Push-Pull or Open-Drain selection on interrupt pad
165 pub pp_od: bool,
166
167 // Enables self-test
168 pub self_test: Control3SelfTest,
169}
170
171#[bitsize(2)]
172#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
173pub enum Control3SelfTest {
174 NormalMode = 0b00, // Self test disabled
175 PositiveSign = 0b01, // Positive sign self test
176 NegativeSign = 0b10, // Negative sign self test
177 Unused = 0b11,
178}
179
180/// Control Register 4 Interrupt 1 Pad Control (0x23 R/W)
181/// INT1_6D INT1_SINGLE_TAP INT1_WU INT1_FF INT1_TAP INT1_DIFF5 INT1_FTH INT1_DRDY
182#[bitsize(8)]
183#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
184pub struct ControlReg4Int1Pad {
185 // Data-ready is routed to INT1 pad
186 // 0: Disabled 1: Enabled
187 pub int1_drdy: bool,
188
189 // FIFO threshold interrupt is routed to INT1 pad
190 // 0: Disabled 1: Enabled
191 pub int1_fth: bool,
192
193 // FIFO full recognition is routed to INT1 pad
194 // 0: Disabled 1: Enabled
195 pub int1_diff5: bool,
196
197 // Double-tap recognition is routed to INT1 pad
198 // 0: Disabled 1: Enabled
199 pub int1_tap: bool,
200
201 // Free-fall recognition is routed to INT1 pad
202 // 0: Disabled 1: Enabled
203 pub int1_ff: bool,
204
205 // Wake-up recognition is routed to INT1 pad
206 // 0: Disabled 1: Enabled
207 pub int1_wu: bool,
208
209 // Single-tap recognition is routed to INT1 pad
210 // 0: Disabled 1: Enabled
211 pub int1_single_tap: bool,
212
213 // 6D recognition is routed to INT1 pad
214 // 0: Disabled 1: Enabled
215 pub int1_6d: bool,
216}
217
218/// Control Register 5 Interrupt 2 Pad Control (0x24 R/W)
219/// INT2_SLEEP_STATE INT2_SLEEP_CHG INT2_BOOT INT2_DRDY_T INT2_OVR INT2_DIFF5 INT2_FTH INT2_DRDY
220#[bitsize(8)]
221#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
222pub struct ControlReg5Int2Pad {
223 // Data-ready is routed to INT2 pad
224 // 0: Disabled 1: Enabled
225 pub int2_drdy: bool,
226
227 // FIFO threshold interrupt is routed to INT2 pad
228 // 0: Disabled 1: Enabled
229 pub int2_fth: bool,
230
231 // FIFO full recognition is routed to INT2 pad
232 // 0: Disabled 1: Enabled
233 pub int2_diff5: bool,
234
235 // FIFO overrun interrupt is routed to INT2 pad
236 // 0: Disabled 1: Enabled
237 pub int2_ovr: bool,
238
239 // Temperature data-ready is routed to INT2 pad
240 // 0: Disabled 1: Enabled
241 pub int2_drdy_t: bool,
242
243 // Boot state routed to INT2 pad
244 // 0: Disabled 1: Enabled
245 pub int2_boot: bool,
246
247 // Sleep change status routed to INT2 pad
248 // 0: Disabled 1: Enabled
249 pub int2_sleep_change: bool,
250
251 // Enables routing SLEEP_STATE to INT2 pad
252 // 0: Disabled 1: Enabled
253 pub int2_sleep_state: bool,
254}
255
256/// Control Register 6 (0x25 R/W)
257/// BW_FILT1 BW_FILT0 FS1 FS0 FDS LOW_NOISE 0 0
258#[bitsize(8)]
259#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
260pub struct ControlReg6 {
261 // Reserved 0
262 pub res0: [Reserved0; 2],
263
264 // Low-noise configuration
265 // 0: Disabled 1: Enabled
266 pub low_noise: bool,
267
268 // Filtered data type selection
269 // 0: Low-pass filter path selected 1: High-pass filter path selected
270 pub fds: bool,
271
272 // Full-scale selection
273 pub fs: Control6FullScale,
274
275 // Bandwidth/Digital filtering cutoff selection
276 pub bw_filt: Control6BandwidthSelection,
277}
278
279#[bitsize(2)]
280#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
281pub enum Control6BandwidthSelection {
282 ODRdiv2 = 0b00, // ODR/2 (up to ODR = 800 Hz, 400 Hz when ODR = 1600 Hz)
283 ODRdiv4 = 0b01, // ODR/4 (HP/LP)
284 ODRdiv10 = 0b10, // ODR/4 (HP/LP)
285 ODRdiv20 = 0b11, // ODR/4 (HP/LP)
286}
287
288#[bitsize(2)]
289#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
290pub enum Control6FullScale {
291 Scale2g = 0b00, // +- 2g
292 Scale4g = 0b01, // +- 4g
293 Scale8g = 0b10, // +- 8g
294 Scale16g = 0b11, // +- 16g
295}
296
297/// Status Register (0x27 R)
298/// FIFO_THS WU_IA SLEEP_STATE DOUBLE_TAP SINGLE_TAP 6D_IA FF_IA DRDY
299#[bitsize(8)]
300#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
301pub struct StatusReg {
302 // Data-ready status
303 // 0: not ready 1: X-, Y- and Z-axis new data available
304 pub drdy: bool,
305
306 // Free-fall event detection status
307 // 0: free-fall event not detected 1: free-fall event detected
308 pub ff_ia: bool,
309
310 // Source of change in position portrait/landscape/face-up/face-down
311 // 0: no event detected 1: a change in position detected
312 pub sixd_ia: bool,
313
314 // Single-tap event status
315 // 0: single-tap event not detected 1: single-tap event detected
316 pub single_tap: bool,
317
318 // Double-tap event status
319 // 0: double-tap event not detected 1: double-tap event detected
320 pub double_tap: bool,
321
322 // Sleep event status
323 // 0: sleep event not detected 1: sleep event detected
324 pub sleep_state: bool,
325
326 // Wake-up event detection status
327 // 0: wake-up event not detected 1: wake-up event detected
328 pub wu_ia: bool,
329
330 // FIFO threshold status flag
331 // 0: FIFO filling is lower than threshold level
332 // 1: FIFO filling is equal to or higher than the threshold level
333 pub fifo_ths: bool,
334}
335
336/// FIFO Control Register (0x2E R/W)
337/// FMode2 FMode1 FMode0 FTH4 FTH3 FTH2 FTH1 FTH0
338#[bitsize(8)]
339#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
340pub struct FifoControlReg {
341 // FIFO threshold level setting
342 pub fth: u5,
343
344 // FIFO mode selection bits. Default: 000
345 pub fmode: FifoControlModeSelect,
346}
347
348#[bitsize(3)]
349#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
350pub enum FifoControlModeSelect {
351 #[fallback]
352 Bypass = 0b000, // Bypass mode: FIFO turned off
353 Fifo = 0b001, // FIFO mode: Stops collecting data when FIFO is full
354 ContinuousToFifo = 0b011, // Continuous-to-FIFO: stream mode until trigger is deasserted, then FIFO mode
355 BypassToContinuous = 0b100, // Bypass-to-continuous: bypass mode until trigger is deasserted, then FIFO mode
356 Continuous = 0b110, // Continuous mode: If the FIFO is full, the new sample overwrites the older sample
357}
358
359/// FIFO Samples Control Register (0x2F R)
360/// FIFO_FTH FIFO_OVR Diff5 Diff4 Diff3 Diff2 Diff1 Diff0
361#[bitsize(8)]
362#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
363pub struct FifoSamplesControlReg {
364 // Represents the number of unread samples stored in FIFO.
365 // (000000 = FIFO empty; 100000 = FIFO full, 32 unread samples)
366 pub diff: u6,
367
368 // FIFO overrun status
369 // 0: FIFO is not completely filled
370 // 1: FIFO is completely filled and at least one sample has been overwritten
371 pub fifo_ovr: bool,
372
373 // FIFO threshold status flag
374 // 0: FIFO filling is lower than threshold level
375 // 1: FIFO filling is equal to or higher than the threshold level
376 pub fifo_fth: bool,
377}
378
379/// Tap Threshold X (0x30 R/W)
380/// Enables 4D configuration and configures TAP threshold
381/// 4D_EN 6D_THS1 6D_THS0 TAP_THSX_4 TAP_THSX_3 TAP_THSX_2 TAP_THSX_1 TAP_THSX_0
382#[bitsize(8)]
383#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
384pub struct TapThresholdXReg {
385 // Threshold for TAP recognition @ +- 2g on X direction
386 pub tap_thsx: u5,
387
388 // Thresholds for 4D/6D function @ FS = +-2 g
389 pub ths_6d: TapX6dThresholdDecoding,
390
391 // Enables 4D detection portrait/landscape position
392 // 0: no position detected;
393 // 1: portrait/landscape detection and face-up/face-down position enabled
394 pub en_4d: bool,
395}
396
397/// Threshold setting for 4D/6D function @ +- 2g
398#[bitsize(2)]
399#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
400pub enum TapX6dThresholdDecoding {
401 Ths6Decoding80deg = 0b00, // Threshold decoding 6: 80 degrees
402 Ths11Decoding70deg = 0b01, // Threshold decoding 11: 70 degrees
403 Ths16Decoding60deg = 0b10, // Threshold decoding 16: 60 degrees
404 Ths21Decoding50deg = 0b11, // Threshold decoding 21: 50 degrees
405}
406
407/// Tap Threshold Y (0x31 R/W)
408/// TAP_PRIOR_2 TAP_PRIOR_1 TAP_PRIOR_0 TAP_THSY_4 TAP_THSY_3 TAP_THSY_2 TAP_THSY_1 TAP_THSY_0
409#[bitsize(8)]
410#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
411pub struct TapThresholdYReg {
412 // Threshold for TAP recognition @ +- 2g on Y direction
413 pub tap_thsy: u5,
414
415 // Selection of priority axis for tap detection
416 pub tap_prior: TapYTapPriority,
417}
418
419#[bitsize(3)]
420#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
421pub enum TapYTapPriority {
422 PriXYZ = 0b000,
423 PriYXZ = 0b001,
424 PriXZY = 0b010,
425 PriZYX = 0b011,
426 PriXYZ1 = 0b100,
427 PriYZX = 0b101,
428 PriZXY = 0b110,
429 PriZYX1 = 0b111,
430}
431
432/// Tap Threshold Z (0x32 R/W)
433/// TAP_X_EN TAP_Y_EN TAP_Z_EN TAP_THSZ_4 TAP_THSZ_3 TAP_THSZ_2 TAP_THSZ_1 TAP_THSZ_0
434#[bitsize(8)]
435#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
436pub struct TapThresholdZReg {
437 // Threshold for TAP recognition @ +- 2g on Z direction
438 pub tap_thsz: u5,
439
440 // Enables Z direction in tap recognition
441 // 0: disabled 1: enabled
442 pub tap_z_en: bool,
443
444 // Enables Y direction in tap recognition
445 // 0: disabled 1: enabled
446 pub tap_y_en: bool,
447
448 // Enables X direction in tap recognition
449 // 0: disabled 1: enabled
450 pub tap_x_en: bool,
451}
452
453/// Interrupt Duration (0x33 R/W)
454/// LATENCY3 LATENCY2 LATENCY1 LATENCY0 QUIET1 QUIET0 SHOCK1 SHOCK0
455#[bitsize(8)]
456#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
457pub struct InterruptDurationReg {
458 // Maximum duration of overthreshold event: this register represents the maximum time of an overthreshold
459 // signal detection to be recognized as a tap event.
460 // Default value is SHOCK[1:0] = 00 (which is 4 * 1/ODR)
461 // 1 LSB = 8 *1/ODR
462 pub shock: u2,
463
464 // Expected quiet time after a tap detection: this register represents the time after the first detected tap in which
465 // there must not be any overthreshold event.
466 // Default value is QUIET[1:0] = 00 (which is 2 * 1/ODR)
467 // 1 LSB = 4 * 1/ODR
468 pub quiet: u2,
469
470 // Duration of maximum time gap for double-tap recognition. When double-tap recognition is enabled, this
471 // register expresses the maximum time between two successive detected taps to determine a double-tap event.
472 // Default value is LATENCY[3:0] = 0000 (which is 16 * 1/ODR)
473 // 1 LSB = 32 * 1/ODR
474 pub latency: u4,
475}
476
477/// Wake-up Threshold (0x34 R/W)
478/// SINGLE_DOUBLE_TAP SLEEP_ON WK_THS5 WK_THS4 WK_THS3 WK_THS2 WK_THS1 WK_THS0
479#[bitsize(8)]
480#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
481pub struct WakeUpThresholdReg {
482 // Wake-up threshold, 6-bit unsigned 1 LSB = 1/64 of FS. Default value: 000000
483 pub wk_ths: u6,
484
485 // Enables sleep (inactivity). Default value: 0
486 // 0: sleep disabled; 1: sleep enabled
487 pub sleep_on: bool,
488
489 // Enables single/double-tap event. Default value: 0
490 // 0: only single-tap event is enabled 1: single and double-tap events are enabled
491 pub single_double_tap: bool,
492}
493
494/// Wake-up Duration (0x35 R/W)
495/// Wake-up and sleep duration configuration register
496/// FF_DUR5 WAKE_DUR1 WAKE_DUR0 STATIONARY SLEEP_DUR3 SLEEP_DUR2 SLEEP_DUR1 SLEEP_DUR0
497#[bitsize(8)]
498#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
499pub struct WakeUpDurationReg {
500 // Duration to go in sleep mode
501 // Default value is SLEEP_ DUR[3:0] = 0000 (which is 16 * 1/ODR)
502 // 1 LSB = 512 * 1/ODR
503 pub sleep_mode: u4,
504
505 // Enables stationary detection / motion detection with no automatic ODR change when detecting stationary state
506 // 0: disabled; 1: enabled
507 pub stationary: bool,
508
509 // Wake-up duration. 1 LSB = 1 *1/ODR
510 pub wake_dur: u2,
511
512 // Free-fall duration. In conjunction with FF_DUR [4:0] bit in the FREE_FALL (36h) register.
513 // 1 LSB = 1 * 1/ODR
514 pub ff_dur5: u1,
515}
516
517/// Free Fall (0x36 R/W)
518/// Free-fall duration and threshold configuration register
519/// FF_DUR4 FF_DUR3 FF_DUR2 FF_DUR1 FF_DUR0 FF_THS2 FF_THS1 FF_THS0
520#[bitsize(8)]
521#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
522pub struct FreeFallReg {
523 // Free-fall threshold @ FS = ±2 g
524 pub ff_ths: FreeFallThresholdDecoding,
525
526 // Free-fall duration. In conjunction with FF_DUR5 bit in the WAKE_UP_DUR (35h) register.
527 // 1 LSB = 1 * 1/ODR
528 pub ff_dur: u5,
529}
530
531#[bitsize(3)]
532#[derive(Copy, Clone, Debug, FromBits, PartialEq, PartialOrd)]
533pub enum FreeFallThresholdDecoding {
534 FfLsb5 = 0b000,
535 FfLsb7 = 0b001,
536 FfLsb8 = 0b010,
537 FfLsb10 = 0b011,
538 FfLsb11 = 0b100,
539 FfLsb13 = 0b101,
540 FfLsb15 = 0b110,
541 FfLsb16 = 0b111,
542}
543
544/// Event Detection Status Register (0x37 R)
545/// OVR DRDY_T SLEEP_STATE_IA DOUBLE_TAP SINGLE_TAP 6D_IA FF_IA DRDY
546#[bitsize(8)]
547#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
548pub struct StatusDupReg {
549 // Data-ready status
550 // 0: not ready 1: X-, Y- and Z-axis new data available
551 pub drdy: bool,
552
553 // Free-fall event detection status
554 // 0: free-fall event not detected 1: free-fall event detected
555 pub ff_ia: bool,
556
557 // Source of change in position portrait/landscape/face-up/face-down
558 // 0: no event detected 1: a change in position detected
559 pub sixd_ia: bool,
560
561 // Single-tap event status
562 // 0: single-tap event not detected 1: single-tap event detected
563 pub single_tap: bool,
564
565 // Double-tap event status
566 // 0: double-tap event not detected 1: double-tap event detected
567 pub double_tap: bool,
568
569 // Sleep event status
570 // 0: sleep event not detected 1: sleep event detected
571 pub sleep_state_ia: bool,
572
573 // Temperature status
574 // 0: data not available; 1: a new set of data is available
575 pub drdy_t: bool,
576
577 // FIFO overrun status flag
578 // 0: FIFO is not completely filled
579 // 1: FIFO is completely filled and at least one sample has been overwritten
580 pub ovr: bool,
581}
582
583/// Wake-up Source (0x38 R)
584/// 0 0 FF_IA SLEEP_STATE IA WU_IA X_WU Y_WU Z_WU
585#[bitsize(8)]
586#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
587pub struct WakeUpSourceReg {
588 // Wake-up event detection status on Z-axis
589 // 0: wake-up event on Z not detected; 1: wake-up event on Z-axis is detected
590 pub z_wu: bool,
591
592 // Wake-up event detection status on Y-axis
593 // 0: wake-up event on Y not detected; 1: wake-up event on Y-axis is detected
594 pub y_wu: bool,
595
596 // Wake-up event detection status on X-axis
597 // 0: wake-up event on X not detected; 1: wake-up event on X-axis is detected
598 pub x_wu: bool,
599
600 // Wake-up event detection status
601 // 0: wake-up event not detected; 1: wake-up event is detected
602 pub wu_ia: bool,
603
604 // Sleep event status
605 // 0: sleep event not detected 1: sleep event detected
606 pub sleep_state_ia: bool,
607
608 // Free-fall event detection status
609 // 0: free-fall event not detected 1: free-fall event detected
610 pub ff_ia: bool,
611
612 // Reserved 0
613 pub res0: [Reserved0; 2],
614}
615
616/// Tap Source (0x39 R)
617/// 0 TAP_IA SINGLE_TAP DOUBLE_TAP TAP_SIGN X_TAP Y_TAP Z_TAP
618#[bitsize(8)]
619#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
620pub struct TapSourceReg {
621 // Reserved 0
622 pub res0: Reserved0,
623
624 // Tap event detection status on Z-axis
625 // 0: tap event on Z not detected 1: tap event on Z-axis is detected
626 pub z_tap: bool,
627
628 // Tap event detection status on Y-axis
629 // 0: tap event on Y not detected 1: tap event on Y-axis is detected
630 pub y_tap: bool,
631
632 // Tap event detection status on X-axis
633 // 0: tap event on X not detected 1: tap event on X-axis is detected
634 pub x_tap: bool,
635
636 // Sign of acceleration detected by tap event
637 // 0: positive sign of acceleration detected 1: negative sign of acceleration detected
638 pub tap_sign: bool,
639
640 // Double-tap event status
641 // 0: double-tap event not detected 1: double-tap event detected
642 pub double_tap: bool,
643
644 // Single-tap event status
645 // 0: single-tap event not detected 1: single-tap event detected
646 pub single_tap: bool,
647
648 // Tap event status
649 // 0: tap event not detected; 1: tap event detected
650 pub tap_ia: bool,
651}
652
653/// 6D Source (0x3A R)
654/// 0 6D_IA ZH ZL YH YL XH XL
655#[bitsize(8)]
656#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
657pub struct SixDSourceReg {
658 // XL over threshold
659 // 0: XL does not exceed the threshold 1: XL is over the threshold
660 pub xl: bool,
661
662 // XH over threshold
663 // 0: XH does not exceed the threshold 1: XH is over the threshold
664 pub xh: bool,
665
666 // YL over threshold
667 // 0: YL does not exceed the threshold 1: YL is over the threshold
668 pub yl: bool,
669
670 // YH over threshold
671 // 0: YH does not exceed the threshold 1: YH is over the threshold
672 pub yh: bool,
673
674 // ZL over threshold
675 // 0: ZL does not exceed the threshold 1: ZL is over the threshold
676 pub zl: bool,
677
678 // ZH over threshold
679 // 0: ZH does not exceed the threshold 1: ZH is over the threshold
680 pub zh: bool,
681
682 // Source of change in position portrait/landscape/face-up/face-down
683 // 0: no event detected; 1: a change in position is detected
684 pub sixd_ia: bool,
685
686 // Reserved 0
687 pub res0: Reserved0,
688}
689
690/// All Interrupt Source (0x3B R)
691/// Reading this register, all related interrupt function flags routed to the INT pads are reset simultaneously.
692/// 0 0 SLEEP_CHANGE_IA 6D_IA DOUBLE_TAP SINGLE_TAP WU_IA FF_IA
693#[bitsize(8)]
694#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
695pub struct AllInterruptSourceReg {
696 // Free-fall event detection status
697 // 0: free-fall event not detected 1: free-fall event detected
698 pub ff_ia: bool,
699
700 // Wake-up event detection status
701 // 0: wake-up event not detected 1: wake-up event detected
702 pub wu_ia: bool,
703
704 // Single-tap event status
705 // 0: single-tap event not detected 1: single-tap event detected
706 pub single_tap: bool,
707
708 // Double-tap event status
709 // 0: double-tap event not detected 1: double-tap event detected
710 pub double_tap: bool,
711
712 // Source of change in position portrait/landscape/face-up/face-down
713 // 0: no event detected 1: a change in position is detected
714 pub sixd_ia: bool,
715
716 // Sleep change status
717 // 0: sleep change not detected 1: sleep change detected
718 pub sleep_change_ia: bool,
719
720 // Reserved 0
721 pub res0: [Reserved0; 2],
722}
723
724/// Control Register 7 (0x3F R/W)
725/// DRDY_PULSED INT2_ON_INT1 INTERRUPTS_ENABLE USR_OFF_ON_OUT USR_OFF_ON_WU USR_OFF_W HP_REF_MODE LPASS_ON6D
726#[bitsize(8)]
727#[derive(DebugBits, FromBits, PartialEq, Clone, Copy)]
728pub struct ControlReg7 {
729 // 0: ODR/2 low-pass filtered data sent to 6D interrupt function (default)
730 // 1: LPF2 output data sent to 6D interrupt function
731 pub lpass_on6d: bool,
732
733 // Enables high-pass filter reference mode
734 // 0: high-pass filter reference mode disabled (default)
735 // 1: high-pass filter reference mode enabled
736 pub hp_ref_mode: bool,
737
738 // Selects the weight of the user offset words specified by
739 // X_OFS_USR_[7:0], Y_OFS_USR_[7:0], and Z_OFS_USR_[7:0] bits
740 // (0: 977 µg/LSB; 1: 15.6 mg/LSB)
741 pub usr_off_w: bool,
742
743 // Enables application of user offset value on accelerometer data for wake-up function only
744 pub usr_off_on_wu: bool,
745
746 // Enables application of user offset value in accelerometer output data registers
747 // FDS bit in CTRL6 (25h) must be set to 0 logic (low-pass path selected)
748 pub usr_off_on_out: bool,
749
750 // Enables interrupts
751 pub interrupts_enable: bool,
752
753 // Signal routing
754 // 1: all signals available only on INT2 are routed to INT1
755 pub int2_on_int1: bool,
756
757 // Switches between latched and pulsed mode for data ready interrupt
758 // 0: latched mode is used; 1: pulsed mode enabled for data-ready
759 pub drdy_pulsed: bool,
760}