iis2dlpc-rs 2.0.0

Driver for the IIS2DLPC ultra-low-power three-axis accelerometer with selectable full scale, multiple power modes, FIFO, and advanced motion detection.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
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;

/// IIS2DLPC Register Map.
///
/// This enum represents the memory-mapped registers of the IIS2DLPC sensor. Each variant corresponds to a specific register address.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq)]
pub enum Reg {
    /// Temperature output register (low byte).
    OutTL = 0x0D,

    /// Temperature output register (high byte).
    OutTH = 0x0E,

    /// Who Am I register.
    ///
    /// This register is read-only and contains the device ID. Default value: `0x44`.
    WhoAmI = 0x0F,

    /// Control register 1.
    Ctrl1 = 0x20,

    /// Control register 2.
    Ctrl2 = 0x21,

    /// Control register 3.
    Ctrl3 = 0x22,

    /// Control register 4 for INT1 pad control.
    Ctrl4Int1PadCtrl = 0x23,

    /// Control register 5 for INT2 pad control.
    Ctrl5Int2PadCtrl = 0x24,

    /// Control register 6.
    Ctrl6 = 0x25,

    /// Temperature output register (8-bit resolution).
    OutT = 0x26,

    /// Status register.
    Status = 0x27,

    /// X-axis output register (low byte).
    OutXL = 0x28,

    /// X-axis output register (high byte).
    OutXH = 0x29,

    /// Y-axis output register (low byte).
    OutYL = 0x2A,

    /// Y-axis output register (high byte).
    OutYH = 0x2B,

    /// Z-axis output register (low byte).
    OutZL = 0x2C,

    /// Z-axis output register (high byte).
    OutZH = 0x2D,

    /// FIFO control register.
    FifoCtrl = 0x2E,

    /// FIFO samples register.
    FifoSamples = 0x2F,

    /// TAP threshold configuration for the X-axis.
    TapThsX = 0x30,

    /// TAP threshold configuration for the Y-axis.
    TapThsY = 0x31,

    /// TAP threshold configuration for the Z-axis.
    TapThsZ = 0x32,

    /// Interrupt duration configuration.
    IntDur = 0x33,

    /// Wakeup threshold configuration.
    WakeUpThs = 0x34,

    /// Wakeup duration configuration.
    WakeUpDur = 0x35,

    /// Free-fall configuration.
    FreeFall = 0x36,

    /// Status duplicate register.
    StatusDup = 0x37,

    /// Wakeup source register.
    WakeUpSrc = 0x38,

    /// Tap source register.
    TapSrc = 0x39,

    /// 6D source register.
    SixdSrc = 0x3A,

    /// All interrupt source register.
    AllIntSrc = 0x3B,

    /// X-axis user offset register.
    XOfsUsr = 0x3C,

    /// Y-axis user offset register.
    YOfsUsr = 0x3D,

    /// Z-axis user offset register.
    ZOfsUsr = 0x3E,

    /// Control register 7.
    Ctrl7 = 0x3F,
}

/// Temperature output register (12-bit resolution, read-only).
///
/// The `OutT` register contains the raw temperature sensor output as a 12-bit two's complement value.
/// The temperature data is left-justified within the 16-bit register.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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,
    /// Temperature sensor output value.
    #[bits(12, access = RO, default = 0)]
    pub temp: i16,
}

/// Control register 1 (R/W).
///
/// The `CTRL1` register is used to configure the operating mode, low-power mode, and output data rate (ODR) of the IIS2DLPC sensor.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Low-power mode selection.
    ///
    /// Configures the low-power mode.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub lp_mode: u8,

    /// Mode selection.
    ///
    /// Configures the operating mode of the sensor.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub mode: u8,

    /// Output data rate (ODR) selection.
    ///
    /// Configures the output data rate and power mode.
    ///
    /// Default value: `0`.
    #[bits(4, default = 0)]
    pub odr: u8,
}

/// Control register 2 (R/W).
///
/// The `CTRL2` register is used to configure the SPI interface mode, I²C disable, address increment, block data update, and other settings.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// SPI serial interface mode selection.
    ///
    /// Configures the SPI interface mode:
    /// * `0`: 4-wire interface.
    /// * `1`: 3-wire interface.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub sim: u8,

    /// I²C disable.
    ///
    /// Disables the I²C communication protocol:
    /// * `0`: SPI and I²C interfaces enabled.
    /// * `1`: I²C mode disabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub i2c_disable: u8,

    /// Register address auto-increment.
    ///
    /// Enables automatic increment of the register address during multiple byte access:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `1`.
    #[bits(1, default = 1)]
    pub if_add_inc: u8,

    /// Block data update.
    ///
    /// Configures the update behavior of output registers:
    /// * `0`: Continuous update.
    /// * `1`: Output registers not updated until MSB and LSB are read.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub bdu: u8,

    /// Disconnect CS pull-up.
    ///
    /// Configures the pull-up resistor on the CS pin:
    /// * `0`: Pull-up connected to CS pin.
    /// * `1`: Pull-up disconnected from CS pin.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub cs_pu_disc: u8,

    #[bits(1, access = RO, default = 0)]
    not_used_01: u8,

    /// Soft reset.
    ///
    /// Resets all control registers:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub soft_reset: u8,

    /// Boot.
    ///
    /// Retrieves the correct trimming parameters from nonvolatile memory:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub boot: u8,
}

/// Control register 3 (R/W).
///
/// The `CTRL3` register is used to configure interrupt polarity, interrupt latching, push-pull/open-drain selection, self-test mode, and single data conversion on demand mode.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Single data conversion on demand mode configuration.
    ///
    /// This field combines two subfields:
    /// - `slp_mode_sel`: Determines the trigger source for single data conversion:
    ///   - `0`: External trigger on INT2.
    ///   - `1`: Triggered by writing `slp_mode_1` to `1` via I²C/SPI.
    /// - `slp_mode_1`: Starts the single data conversion on demand mode when set to `1`.
    ///   This bit is automatically reset to `0` when the data is available, and the device is ready for another triggered session.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub slp_mode: u8,

    #[bits(1, access = RO, default = 0)]
    not_used_01: u8,

    /// Interrupt active level.
    ///
    /// Configures the active level of interrupts:
    /// * `0`: Active high.
    /// * `1`: Active low.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub h_lactive: u8,

    /// Latched interrupt.
    ///
    /// Configures the interrupt mode:
    /// * `0`: Pulsed mode.
    /// * `1`: Latched mode.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub lir: u8,

    /// Push-pull/open-drain selection.
    ///
    /// Configures the interrupt pad type:
    /// * `0`: Push-pull.
    /// * `1`: Open-drain.
    #[bits(1, default = 0)]
    pub pp_od: u8,

    /// Self-test mode selection.
    ///
    /// Configures the self-test mode. Refer to the datasheet for the available self-test modes.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub st: u8,
}

/// Control register 4 (R/W).
///
/// The `CTRL4_INT1_PAD_CTRL` register is used to configure the interrupt signals routed to the INT1 pad.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Data-ready interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_drdy: u8,

    /// FIFO threshold interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_fth: u8,

    /// FIFO full interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_diff5: u8,

    /// Double-tap interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_tap: u8,

    /// Free-fall interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_ff: u8,

    /// Wakeup interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_wu: u8,

    /// Single-tap interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_single_tap: u8,

    /// 6D recognition interrupt routed to INT1 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int1_6d: u8,
}

/// Control register 5 (R/W).
///
/// The `CTRL5_INT2_PAD_CTRL` register is used to configure the interrupt signals routed to the INT2 pad.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Data-ready interrupt routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_drdy: u8,

    /// FIFO threshold interrupt routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_fth: u8,

    /// FIFO full interrupt routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_diff5: u8,

    /// FIFO overrun interrupt routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_ovr: u8,

    /// Temperature data-ready interrupt routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_drdy_t: u8,

    /// Boot status routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_boot: u8,

    /// Sleep change status routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_sleep_chg: u8,

    /// Sleep state status routed to INT2 pad.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_sleep_state: u8,
}

/// Control register 6 (R/W).
///
/// The `CTRL6` register is used to configure the low-noise mode, filter settings, full-scale selection, and bandwidth selection.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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,

    /// Low-noise mode enable.
    ///
    /// Configures the low-noise mode:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub low_noise: u8,

    /// Filtered data selection.
    ///
    /// Configures the data path:
    /// * `0`: Low-pass filter path selected.
    /// * `1`: High-pass filter path selected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub fds: u8,

    /// Full-scale selection.
    ///
    /// Configures the measurement range:
    /// * `00`: ±2 g.
    /// * `01`: ±4 g.
    /// * `10`: ±8 g.
    /// * `11`: ±16 g.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub fs: u8,

    /// Bandwidth selection.
    ///
    /// Configures the bandwidth of the filter:
    /// * `00`: ODR/2.
    /// * `01`: ODR/4.
    /// * `10`: ODR/10.
    /// * `11`: ODR/20.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub bw_filt: u8,
}

/// Status register (R).
///
/// The `STATUS` register provides the status of various events detected by the IIS2DLPC sensor.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Data-ready status.
    ///
    /// Indicates whether new data is available:
    /// * `0`: Not ready.
    /// * `1`: X-, Y-, and Z-axis new data available.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub drdy: u8,

    /// Free-fall event detection status.
    ///
    /// Indicates whether a free-fall event has been detected:
    /// * `0`: Free-fall event not detected.
    /// * `1`: Free-fall event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub ff_ia: u8,

    /// 6D recognition event status.
    ///
    /// Indicates whether a change in position (portrait/landscape/face-up/face-down) has been detected:
    /// * `0`: No event detected.
    /// * `1`: A change in position detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub six_d_ia: u8,

    /// Single-tap event status.
    ///
    /// Indicates whether a single-tap event has been detected:
    /// * `0`: Single-tap event not detected.
    /// * `1`: Single-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub single_tap: u8,

    /// Double-tap event status.
    ///
    /// Indicates whether a double-tap event has been detected:
    /// * `0`: Double-tap event not detected.
    /// * `1`: Double-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub double_tap: u8,

    /// Sleep state status.
    ///
    /// Indicates whether the device is in a sleep state:
    /// * `0`: Sleep event not detected.
    /// * `1`: Sleep event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub sleep_state: u8,

    /// Wakeup event detection status.
    ///
    /// Indicates whether a wakeup event has been detected:
    /// * `0`: Wakeup event not detected.
    /// * `1`: Wakeup event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub wu_ia: u8,

    /// FIFO threshold status.
    ///
    /// Indicates whether the FIFO filling is equal to or higher than the threshold level:
    /// * `0`: FIFO filling is lower than the threshold level.
    /// * `1`: FIFO filling is equal to or higher than the threshold level.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub fifo_ths: u8,
}

/// X-axis accelerometer output register (14-bit resolution, read-only).
///
/// The `OutX` register contains the raw acceleration data for the X-axis as a 14-bit two's complement value.
/// The data is left-justified within the 16-bit register, with 2 unused bits.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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,
    /// Raw acceleration data for the X-axis.
    #[bits(14, access = RO, default = 0)]
    pub x: i16,
}

/// Y-axis accelerometer output register (14-bit resolution, read-only).
///
/// The `OutY` register contains the raw acceleration data for the Y-axis as a 14-bit two's complement value.
/// The data is left-justified within the 16-bit register, with 2 unused bits.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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,
    /// Raw acceleration data for the Y-axis.
    #[bits(14, access = RO, default = 0)]
    pub y: i16,
}

/// Z-axis accelerometer output register (14-bit resolution, read-only).
///
/// The `OutZ` register contains the raw acceleration data for the Z-axis as a 14-bit two's complement value.
/// The data is left-justified within the 16-bit register, with 2 unused bits.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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,
    /// Raw acceleration data for the Z-axis.
    #[bits(14, access = RO, default = 0)]
    pub z: i16,
}

/// FIFO control register (R/W).
///
/// The `FIFO_CTRL` register is used to configure the FIFO threshold level and mode.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// FIFO threshold level.
    ///
    /// Configures the FIFO threshold level. The value is a 5-bit unsigned integer.
    ///
    /// Default value: `0`.
    #[bits(5, default = 0)]
    pub fth: u8,

    /// FIFO mode selection.
    ///
    /// Configures the FIFO operating mode:
    /// * `000`: Bypass mode.
    /// * `001`: FIFO mode.
    /// * `011`: Continuous-to-FIFO mode.
    /// * `100`: Bypass-to-Continuous mode.
    /// * `110`: Continuous mode.
    ///
    /// Default value: `0`.
    #[bits(3, default = 0)]
    pub fmode: u8,
}

/// FIFO samples register (R).
///
/// The `FIFO_SAMPLES` register provides the status of the FIFO, including the number of unread samples and overflow/threshold flags.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Number of unread samples in FIFO.
    ///
    /// Represents the number of unread samples stored in the FIFO. The value is a 6-bit unsigned integer.
    ///
    /// Default value: `0`.
    #[bits(6, default = 0, access = RO)]
    pub diff: u8,

    /// FIFO overrun status.
    ///
    /// Indicates whether the FIFO is full and at least one sample has been overwritten:
    /// * `0`: FIFO is not completely filled.
    /// * `1`: FIFO is completely filled and at least one sample has been overwritten.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub fifo_ovr: u8,

    /// FIFO threshold status.
    ///
    /// Indicates whether the FIFO filling is equal to or higher than the threshold level:
    /// * `0`: FIFO filling is lower than the threshold level.
    /// * `1`: FIFO filling is equal to or higher than the threshold level.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub fifo_fth: u8,
}

/// TAP threshold configuration for the X-axis (R/W).
///
/// The `TAP_THS_X` register is used to configure the tap threshold for the X-axis, 6D threshold, and 4D detection enable.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Tap threshold for the X-axis.
    ///
    /// Default value: `0`.
    #[bits(5, default = 0)]
    pub tap_thsx: u8,

    /// 6D threshold.
    ///
    /// Configures the threshold for 6D detection.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub six_d_ths: u8,

    /// 4D detection enable.
    ///
    /// Enables 4D detection:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub four_d_en: u8,
}

/// TAP threshold configuration for the Y-axis (R/W).
///
/// The `TAP_THS_Y` register is used to configure the tap threshold for the Y-axis and the axis priority for tap detection.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Tap threshold for the Y-axis.
    ///
    /// Default value: `0`.
    #[bits(5, default = 0)]
    pub tap_thsy: u8,

    /// Axis priority for tap detection.
    ///
    /// Configures the priority of axes for tap detection.
    ///
    /// Default value: `0`.
    #[bits(3, default = 0)]
    pub tap_prior: u8,
}

/// TAP threshold configuration for the Z-axis (R/W).
///
/// The `TAP_THS_Z` register is used to configure the tap threshold for the Z-axis and enable tap detection on specific axes.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Tap threshold for the Z-axis.
    ///
    /// Default value: `0`.
    #[bits(5, default = 0)]
    pub tap_thsz: u8,

    /// Enable tap detection on the Z-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub tap_z_en: u8,

    /// Enable tap detection on the Y-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub tap_y_en: u8,

    /// Enable tap detection on the X-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub tap_x_en: u8,
}

/// Interrupt duration configuration (R/W).
///
/// The `INT_DUR` register is used to configure the shock, quiet, and latency durations for tap detection.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Shock duration.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub shock: u8,

    /// Quiet duration.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub quiet: u8,

    /// Latency duration.
    ///
    /// Default value: `0`.
    #[bits(4, default = 0)]
    pub latency: u8,
}

/// Wakeup threshold configuration (R/W).
///
/// The `WAKE_UP_THS` register is used to configure the wakeup threshold, sleep enable, and single/double-tap enable.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Wakeup threshold.
    ///
    /// Default value: `0`.
    #[bits(6, default = 0)]
    pub wk_ths: u8,

    /// Sleep enable.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub sleep_on: u8,

    /// Single/double-tap enable.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub single_double_tap: u8,
}

/// Wakeup duration configuration (R/W).
///
/// The `WAKE_UP_DUR` register is used to configure the sleep duration, stationary detection, wakeup duration, and free-fall duration.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Sleep duration.
    ///
    /// Default value: `0`.
    #[bits(4, default = 0)]
    pub sleep_dur: u8,

    /// Stationary detection enable.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub stationary: u8,

    /// Wakeup duration.
    ///
    /// Default value: `0`.
    #[bits(2, default = 0)]
    pub wake_dur: u8,

    /// Free-fall duration.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub ff_dur: u8,
}

/// Free-fall configuration (R/W).
///
/// The `FREE_FALL` register is used to configure the free-fall threshold and duration.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Free-fall threshold.
    ///
    /// Default value: `0`.
    #[bits(3, default = 0)]
    pub ff_ths: u8,

    /// Free-fall duration.
    ///
    /// Default value: `0`.
    #[bits(5, default = 0)]
    pub ff_dur: u8,
}

/// Status duplicate register (R).
///
/// The `STATUS_DUP` register provides the status of various events detected by the IIS2DLPC sensor, including data-ready, free-fall, 6D recognition, and tap events.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Data-ready status.
    ///
    /// Indicates whether new data is available:
    /// * `0`: Not ready.
    /// * `1`: X-, Y-, and Z-axis new data available.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub drdy: u8,

    /// Free-fall event detection status.
    ///
    /// Indicates whether a free-fall event has been detected:
    /// * `0`: Free-fall event not detected.
    /// * `1`: Free-fall event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub ff_ia: u8,

    /// 6D recognition event status.
    ///
    /// Indicates whether a change in position (portrait/landscape/face-up/face-down) has been detected:
    /// * `0`: No event detected.
    /// * `1`: A change in position detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub six_d_ia: u8,

    /// Single-tap event status.
    ///
    /// Indicates whether a single-tap event has been detected:
    /// * `0`: Single-tap event not detected.
    /// * `1`: Single-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub single_tap: u8,

    /// Double-tap event status.
    ///
    /// Indicates whether a double-tap event has been detected:
    /// * `0`: Double-tap event not detected.
    /// * `1`: Double-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub double_tap: u8,

    /// Sleep state status.
    ///
    /// Indicates whether the device is in a sleep state:
    /// * `0`: Sleep event not detected.
    /// * `1`: Sleep event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub sleep_state_ia: u8,

    /// Temperature data-ready status.
    ///
    /// Indicates whether new temperature data is available:
    /// * `0`: Data not available.
    /// * `1`: A new set of data is available.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub drdy_t: u8,

    /// FIFO overrun status.
    ///
    /// Indicates whether the FIFO is full and at least one sample has been overwritten:
    /// * `0`: FIFO is not completely filled.
    /// * `1`: FIFO is completely filled and at least one sample has been overwritten.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub ovr: u8,
}

/// Wakeup source register (R).
///
/// The `WAKE_UP_SRC` register provides the status of wakeup events, including axis-specific wakeup detection and free-fall events.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Wakeup event detection status on the Z-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub z_wu: u8,

    /// Wakeup event detection status on the Y-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub y_wu: u8,

    /// Wakeup event detection status on the X-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub x_wu: u8,

    /// Wakeup event detection status.
    ///
    /// Indicates whether a wakeup event has been detected:
    /// * `0`: Wakeup event not detected.
    /// * `1`: Wakeup event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub wu_ia: u8,

    /// Sleep state status.
    ///
    /// Indicates whether the device is in a sleep state:
    /// * `0`: Sleep event not detected.
    /// * `1`: Sleep event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub sleep_state_ia: u8,

    /// Free-fall event detection status.
    ///
    /// Indicates whether a free-fall event has been detected:
    /// * `0`: Free-fall event not detected.
    /// * `1`: Free-fall event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub ff_ia: u8,

    #[bits(2, access = RO, default = 0)]
    not_used_01: u8,
}

/// Tap source register (R).
///
/// The `TAP_SRC` register provides the status of tap events, including axis-specific tap detection and tap sign.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Tap event detection status on the Z-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub z_tap: u8,

    /// Tap event detection status on the Y-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub y_tap: u8,

    /// Tap event detection status on the X-axis.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub x_tap: u8,

    /// Sign of acceleration detected by the tap event.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub tap_sign: u8,

    /// Double-tap event status.
    ///
    /// Indicates whether a double-tap event has been detected:
    /// * `0`: Double-tap event not detected.
    /// * `1`: Double-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub double_tap: u8,

    /// Single-tap event status.
    ///
    /// Indicates whether a single-tap event has been detected:
    /// * `0`: Single-tap event not detected.
    /// * `1`: Single-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub single_tap: u8,

    /// Tap event status.
    ///
    /// Indicates whether a tap event has been detected:
    /// * `0`: Tap event not detected.
    /// * `1`: Tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub tap_ia: u8,

    #[bits(1, access = RO, default = 0)]
    not_used_01: u8,
}

/// 6D source register (R).
///
/// The `SIXD_SRC` register provides the status of 6D orientation detection, including axis-specific thresholds and 6D event detection.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// X-axis low threshold status.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub xl: u8,

    /// X-axis high threshold status.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub xh: u8,

    /// Y-axis low threshold status.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub yl: u8,

    /// Y-axis high threshold status.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub yh: u8,

    /// Z-axis low threshold status.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub zl: u8,

    /// Z-axis high threshold status.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub zh: u8,

    /// 6D event detection status.
    ///
    /// Indicates whether a 6D orientation event has been detected:
    /// * `0`: No event detected.
    /// * `1`: 6D event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub six_d_ia: u8,

    #[bits(1, access = RO, default = 0)]
    not_used_01: u8,
}

/// All interrupt source register (R).
///
/// The `ALL_INT_SRC` register provides the status of all interrupt events, including free-fall, wakeup, tap, and 6D events.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Free-fall event detection status.
    ///
    /// Indicates whether a free-fall event has been detected:
    /// * `0`: Free-fall event not detected.
    /// * `1`: Free-fall event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub ff_ia: u8,

    /// Wakeup event detection status.
    ///
    /// Indicates whether a wakeup event has been detected:
    /// * `0`: Wakeup event not detected.
    /// * `1`: Wakeup event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub wu_ia: u8,

    /// Single-tap event detection status.
    ///
    /// Indicates whether a single-tap event has been detected:
    /// * `0`: Single-tap event not detected.
    /// * `1`: Single-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub single_tap: u8,

    /// Double-tap event detection status.
    ///
    /// Indicates whether a double-tap event has been detected:
    /// * `0`: Double-tap event not detected.
    /// * `1`: Double-tap event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub double_tap: u8,

    /// 6D event detection status.
    ///
    /// Indicates whether a 6D orientation event has been detected:
    /// * `0`: No event detected.
    /// * `1`: 6D event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub six_d_ia: u8,

    /// Sleep change event detection status.
    ///
    /// Indicates whether a sleep change event has been detected:
    /// * `0`: Sleep change event not detected.
    /// * `1`: Sleep change event detected.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0, access = RO)]
    pub sleep_change_ia: u8,

    #[bits(2, access = RO, default = 0)]
    not_used_01: u8,
}

/// User offset register for the X-axis (read/write).
///
/// The `XOfsUsr` register allows the user to apply a signed offset correction to the X-axis acceleration data.
/// The offset value is an 8-bit two's complement number.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// User offset value for the X-axis.
    #[bits(8, default = 0)]
    pub x_ofs_usr: i8,
}

/// User offset register for the Y-axis (read/write).
///
/// The `YOfsUsr` register allows the user to apply a signed offset correction to the Y-axis acceleration data.
/// The offset value is an 8-bit two's complement number.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// User offset value for the Y-axis.
    #[bits(8, default = 0)]
    pub y_ofs_usr: i8,
}

/// User offset register for the Z-axis (read/write).
///
/// The `ZOfsUsr` register allows the user to apply a signed offset correction to the Z-axis acceleration data.
/// The offset value is an 8-bit two's complement number.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// User offset value for the Z-axis.
    #[bits(8, default = 0)]
    pub z_ofs_usr: i8,
}

/// Control register 7 (R/W).
///
/// The `CTRL7` register is used to configure various features, including high-pass filter reference mode, user offset application, and interrupt routing.
///
/// The bit order for this struct can be configured using the `bit_order_msb` feature:
/// * `Msb`: Most significant bit first.
/// * `Lsb`: Least significant bit first (default).
#[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 {
    /// Low-pass filter data sent to 6D function.
    ///
    /// Configures the data sent to the 6D interrupt function:
    /// * `0`: ODR/2 low-pass filtered data.
    /// * `1`: LPF2 output data.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub lpass_on6d: u8,

    /// High-pass filter reference mode enable.
    ///
    /// Configures the high-pass filter reference mode:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub hp_ref_mode: u8,

    /// User offset weight selection.
    ///
    /// Configures the weight of the user offset:
    /// * `0`: 977 μg/LSB.
    /// * `1`: 15.6 mg/LSB.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub usr_off_w: u8,

    /// User offset application for wakeup function.
    ///
    /// Enables the application of user offset for wakeup detection:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub usr_off_on_wu: u8,

    /// User offset application for output data.
    ///
    /// Enables the application of user offset for output data:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub usr_off_on_out: u8,

    /// Interrupts enable.
    ///
    /// Enables interrupts:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub interrupts_enable: u8,

    /// INT2 signal routing to INT1.
    ///
    /// Routes all signals available on INT2 to INT1:
    /// * `0`: Disabled.
    /// * `1`: Enabled.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub int2_on_int1: u8,

    /// Data-ready interrupt mode.
    ///
    /// Configures the data-ready interrupt mode:
    /// * `0`: Latched mode.
    /// * `1`: Pulsed mode.
    ///
    /// Default value: `0`.
    #[bits(1, default = 0)]
    pub drdy_pulsed: u8,
}

/// All interrupt and status sources.
///
/// This struct aggregates the status and interrupt source registers of the IIS2DLPC sensor.
/// It provides a comprehensive view of the device's current status and interrupt events.
pub struct AllSources {
    /// Status duplicate register.
    ///
    /// Contains information about various events such as data-ready, free-fall detection, and tap detection.
    pub status_dup: StatusDup,

    /// Wake-up source register.
    ///
    /// Contains information about wake-up events, including axis-specific wake-up detection.
    pub wake_up_src: WakeUpSrc,

    /// Tap source register.
    ///
    /// Contains information about tap events, including axis-specific tap detection and tap type (single or double).
    pub tap_src: TapSrc,

    /// 6D source register.
    ///
    /// Contains information about 6D orientation events, including axis-specific thresholds and event detection.
    pub sixd_src: SixdSrc,

    /// All interrupt source register.
    ///
    /// Contains a summary of all interrupt events routed to the INT pads.
    pub all_int_src: AllIntSrc,
}

/// Accelerometer operating modes.
///
/// This enum represents the various operating modes of the IIS2DLPC accelerometer. Each mode is associated with specific configurations for:
/// - `mode`: Operating mode.
/// - `lp_mode`: Low-power mode configuration.
/// - `low_noise`: Low-noise mode configuration.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Mode {
    /// High-performance mode.
    HighPerformance = 0x04,

    /// Continuous low-power mode 4.
    ContLowPwr4 = 0x03,

    /// Continuous low-power mode 3.
    ContLowPwr3 = 0x02,

    /// Continuous low-power mode 2.
    ContLowPwr2 = 0x01,

    /// Continuous low-power mode with 12-bit resolution (default).
    #[default]
    ContLowPwr12bit = 0x00,
    /// Single low-power mode 4.
    SingleLowPwr4 = 0x0B,
    /// Single low-power mode 3.
    SingleLowPwr3 = 0x0A,
    /// Single low-power mode 2.
    SingleLowPwr2 = 0x09,
    /// Single low-power mode with 12-bit resolution.
    SingleLowPwr12bit = 0x08,
    /// High-performance mode with low noise.
    HighPerformanceLowNoise = 0x14,
    /// Continuous low-power mode 4 with low noise.
    ContLowPwrLowNoise4 = 0x13,
    /// Continuous low-power mode 3 with low noise.
    ContLowPwrLowNoise3 = 0x12,
    /// Continuous low-power mode 2 with low noise.
    ContLowPwrLowNoise2 = 0x11,
    /// Continuous low-power mode with 12-bit resolution and low noise.
    ContLowPwrLowNoise12bit = 0x10,
    /// Single low-power mode 4 with low noise.
    SingleLowPwrLowNoise4 = 0x1B,
    /// Single low-power mode 3 with low noise.
    SingleLowPwrLowNoise3 = 0x1A,
    /// Single low-power mode 2 with low noise.
    SingleLowPwrLowNoise2 = 0x19,
    /// Single low-power mode with 12-bit resolution and low noise.
    SingleLowLowNoisePwr12bit = 0x18,
}

impl Mode {
    /// Create a new `Mode` instance.
    ///
    /// This function constructs a `Mode` instance from the given `mode`, `lp_mode`, and `low_noise` values.
    ///
    /// ### Arguments
    /// - `mode`: The operating mode value.
    /// - `lp_mode`: The low-power mode configuration value.
    /// - `low_noise`: The low-noise mode configuration value.
    ///
    /// ### Returns
    /// - A `Mode` instance corresponding to the provided values.
    /// - Defaults to `ContLowPwr12bit` if the provided values do not match a valid mode.
    pub fn new(mode: u8, lp_mode: u8, low_noise: u8) -> Self {
        // low_noise | mode1 | mode2 | lp_mode1 | lp_mode2 |
        Self::try_from((low_noise << 4) + (mode << 2) + lp_mode).unwrap_or_default()
    }

    /// Get the `mode` value.
    ///
    /// Extracts the `mode` field from the `Mode` instance.
    ///
    /// ### Returns
    /// - The `mode` value as a `u8`.
    pub fn mode(&self) -> u8 {
        (*self as u8 & 0x0C) >> 2
    }

    /// Get the `lp_mode` value.
    ///
    /// Extracts the `lp_mode` field from the `Mode` instance.
    ///
    /// ### Returns
    /// - The `lp_mode` value as a `u8`.
    pub fn lp_mode(&self) -> u8 {
        *self as u8 & 0x3
    }

    /// Get the `low_noise` value.
    ///
    /// Extracts the `low_noise` field from the `Mode` instance.
    ///
    /// ### Returns
    /// - The `low_noise` value as a `u8`.
    pub fn low_noise(&self) -> u8 {
        (*self as u8 & 0x10) >> 4
    }
}

/// Accelerometer output data rates (ODR).
///
/// This enum represents the various output data rates supported by the IIS2DLPC accelerometer. Each variant corresponds to a specific ODR configuration.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Odr {
    /// Accelerometer off (default).
    #[default]
    Off = 0x00,

    /// Accelerometer ODR: 1.6 Hz (low-power only).
    _1_6hzLpOnly = 0x01,

    /// Accelerometer ODR: 12.5 Hz.
    _12_5hz = 0x02,

    /// Accelerometer ODR: 25 Hz.
    _25hz = 0x03,

    /// Accelerometer ODR: 50 Hz.
    _50hz = 0x04,

    /// Accelerometer ODR: 100 Hz.
    _100hz = 0x05,

    /// Accelerometer ODR: 200 Hz.
    _200hz = 0x06,

    /// Accelerometer ODR: 400 Hz.
    _400hz = 0x07,

    /// Accelerometer ODR: 800 Hz.
    _800hz = 0x08,

    /// Accelerometer ODR: 1.6 kHz.
    _1_6khz = 0x09,

    /// Accelerometer ODR: Software trigger.
    SetSwTrig = 0x12,

    /// Accelerometer ODR: Pin trigger.
    SetPinTrig = 0x22,
}

impl Odr {
    /// Create a new `Odr` instance.
    ///
    /// This function constructs an `Odr` instance from the given `odr` and `slp_mode` values.
    ///
    /// ### Arguments
    /// - `odr`: The output data rate value.
    /// - `slp_mode`: The sleep mode configuration value.
    ///
    /// ### Returns
    /// - An `Odr` instance corresponding to the provided values.
    /// - Defaults to `XlOdrOff` if the provided values do not match a valid ODR.
    pub fn new(odr: u8, slp_mode: u8) -> Self {
        Self::try_from((slp_mode << 4) + odr).unwrap_or_default()
    }

    /// Get the `odr` value.
    ///
    /// Extracts the `odr` field from the `Odr` instance.
    ///
    /// ### Returns
    /// - The `odr` value as a `u8`.
    pub fn odr(&self) -> u8 {
        *self as u8 & 0xF
    }

    /// Get the `slp_mode` value.
    ///
    /// Extracts the `slp_mode` field from the `Odr` instance.
    ///
    /// ### Returns
    /// - The `slp_mode` value as a `u8`.
    pub fn slp_mode(&self) -> u8 {
        (*self as u8 & 0x30) >> 4
    }
}

/// Accelerometer full-scale selection.
///
/// This enum represents the full-scale range of the accelerometer, which determines the maximum measurable acceleration.
/// The full-scale range is configured in the `CTRL6` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Fs {
    /// ±2g full-scale range (default).
    #[default]
    _2g = 0,

    /// ±4g full-scale range.
    _4g = 1,

    /// ±8g full-scale range.
    _8g = 2,

    /// ±16g full-scale range.
    _16g = 3,
}

/// User offset weight configuration.
///
/// This enum represents the weight of the user offset bits in the `X_OFS_USR`, `Y_OFS_USR`, and `Z_OFS_USR` registers.
/// The weight determines the scaling factor applied to the user offset values.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum UsrOffW {
    /// 977 μg/LSB (default).
    #[default]
    _977ugLsb = 0,

    /// 15.6 mg/LSB.
    _15_6mgLsb = 1,
}

/// Sensor self-test configuration.
///
/// This enum represents the self-test modes for the IIS2DLPC sensor.
/// The self-test mode is configured in the `CTRL3` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum St {
    /// Self-test disabled (default).
    #[default]
    Disable = 0,

    /// Positive sign self-test.
    Positive = 1,

    /// Negative sign self-test.
    Negative = 2,
}

/// Data-ready interrupt mode configuration.
///
/// This enum represents the data-ready interrupt mode for the IIS2DLPC sensor.
/// The mode is configured in the `CTRL7` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum DrdyPulsed {
    /// Latched mode (default).
    #[default]
    Latched = 0,

    /// Pulsed mode.
    Pulsed = 1,
}

/// Accelerometer filtering path configuration.
///
/// This enum represents the filtering path options for accelerometer outputs.
/// The filtering path is configured in the `CTRL6` and `CTRL7` registers.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Fds {
    /// Low-pass filter on output (default).
    #[default]
    LpfOnOut = 0x00,

    /// User offset on output.
    UserOffsetOnOut = 0x01,

    /// High-pass filter on output.
    HighPassOnOut = 0x10,
}

impl Fds {
    /// Create a new `Fds` instance.
    ///
    /// This function constructs an `Fds` instance from the given `fds` and `usr_off_on_out` values.
    ///
    /// ### Arguments
    /// - `fds`: The filtering path configuration value.
    /// - `usr_off_on_out`: The user offset application value.
    ///
    /// ### Returns
    /// - An `Fds` instance corresponding to the provided values.
    /// - Defaults to `LpfOnOut` if the provided values do not match a valid configuration.
    pub fn new(fds: u8, usr_off_on_out: u8) -> Self {
        Self::try_from((fds << 4) + usr_off_on_out).unwrap_or_default()
    }

    /// Get the `fds` value.
    ///
    /// Extracts the `fds` field from the `Fds` instance.
    ///
    /// ### Returns
    /// - The `fds` value as a `u8`.
    pub fn fds(&self) -> u8 {
        ((*self as u8) & 0x10) >> 4
    }

    /// Get the `usr_off_on_out` value.
    ///
    /// Extracts the `usr_off_on_out` field from the `Fds` instance.
    ///
    /// ### Returns
    /// - The `usr_off_on_out` value as a `u8`.
    pub fn usr_off_on_out(&self) -> u8 {
        *self as u8 & 0x01
    }
}

/// Accelerometer cutoff filter frequency configuration.
///
/// This enum represents the cutoff frequency options for the accelerometer's low-pass or high-pass filter.
/// The cutoff frequency is configured in the `CTRL6` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum BwFilt {
    /// ODR/2 (default).
    #[default]
    OdrDiv2 = 0,

    /// ODR/4.
    OdrDiv4 = 1,

    /// ODR/10.
    OdrDiv10 = 2,

    /// ODR/20.
    OdrDiv20 = 3,
}

/// SPI serial interface mode configuration.
///
/// This enum represents the SPI serial interface modes for the IIS2DLPC sensor.
/// The mode is configured in the `CTRL2` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Sim {
    /// 4-wire SPI mode (default).
    #[default]
    Spi4Wire = 0,

    /// 3-wire SPI mode.
    Spi3Wire = 1,
}

/// I²C interface configuration.
///
/// This enum represents the enable/disable states of the I²C interface for the IIS2DLPC sensor.
/// The state is configured in the `CTRL2` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum I2cDisable {
    /// Enable the I²C interface (default).
    #[default]
    I2cEnable = 0,

    /// Disable the I²C interface.
    I2cDisable = 1,
}

/// CS pull-up resistor configuration.
///
/// This enum represents the configuration of the CS pull-up resistor for the IIS2DLPC sensor.
/// The configuration is set in the `CTRL2` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum CsPuDisc {
    /// Connect the pull-up resistor (default).
    #[default]
    PullUpConnect = 0,

    /// Disconnect the pull-up resistor.
    PullUpDisconnect = 1,
}

/// Interrupt active level configuration.
///
/// This enum represents the active level configuration for interrupts.
/// The configuration is set in the `CTRL3` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum HLactive {
    /// Active high (default).
    #[default]
    ActiveHigh = 0,

    /// Active low.
    ActiveLow = 1,
}

/// Interrupt latching configuration.
///
/// This enum represents the latching behavior of interrupts.
/// The configuration is set in the `CTRL3` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Lir {
    /// Pulsed interrupt mode (default).
    #[default]
    Pulsed = 0,

    /// Latched interrupt mode.
    Latched = 1,
}

/// Interrupt pad type configuration.
///
/// This enum represents the type of interrupt pad configuration.
/// The configuration is set in the `CTRL3` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum PpOd {
    /// Push-pull configuration (default).
    #[default]
    PushPull = 0,

    /// Open-drain configuration.
    OpenDrain = 1,
}

/// Data source for the wake-up interrupt function.
///
/// This enum represents the data source options for the wake-up interrupt function.
/// The data source is configured in the `CTRL7` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum UsrOffOnWu {
    /// High-pass filtered data (default).
    #[default]
    HpFeed = 0,

    /// User offset data.
    UserOffsetFeed = 1,
}

/// Activity/inactivity or stationary/motion detection configuration.
///
/// This enum represents the detection modes for activity/inactivity or stationary/motion.
/// The configuration is set in the `WAKE_UP_THS` and `WAKE_UP_DUR` registers.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum SleepOn {
    /// No detection (default).
    #[default]
    NoDetection = 0,

    /// Detect activity/inactivity.
    ActInact = 1,

    /// Detect stationary/motion.
    StatMotion = 3,
}

impl SleepOn {
    /// Create a new `SleepOn` instance.
    ///
    /// This function constructs a `SleepOn` instance from the given `sleep_on` and `stationary` values.
    ///
    /// ### Arguments
    /// - `sleep_on`: The activity/inactivity detection configuration value.
    /// - `stationary`: The stationary/motion detection configuration value.
    ///
    /// ### Returns
    /// - A `SleepOn` instance corresponding to the provided values.
    /// - Defaults to `NoDetection` if the provided values do not match a valid configuration.
    pub fn new(sleep_on: u8, stationary: u8) -> Self {
        Self::try_from((stationary << 1) + sleep_on).unwrap_or_default()
    }

    /// Get the `sleep_on` value.
    ///
    /// Extracts the `sleep_on` field from the `SleepOn` instance.
    ///
    /// ### Returns
    /// - The `sleep_on` value as a `u8`.
    pub fn sleep_on(&self) -> u8 {
        (*self as u8) & 0x01
    }

    /// Get the `stationary` value.
    ///
    /// Extracts the `stationary` field from the `SleepOn` instance.
    ///
    /// ### Returns
    /// - The `stationary` value as a `u8`.
    pub fn stationary(&self) -> u8 {
        ((*self as u8) & 0x02) >> 1
    }
}

/// Axis priority for tap detection.
///
/// This enum represents the axis priority for tap detection.
/// The priority is configured in the `TAP_THS_Y` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum TapPrior {
    /// X > Y > Z (default).
    #[default]
    Xyz = 0,

    /// Y > X > Z.
    Yxz = 1,

    /// X > Z > Y.
    Xzy = 2,

    /// Z > Y > X.
    Zyx = 3,

    /// Y > Z > X.
    Yzx = 5,

    /// Z > X > Y.
    Zxy = 6,
}

/// Single/double-tap event detection mode.
///
/// This enum represents the detection mode for single- and double-tap events.
/// The mode is configured in the `WAKE_UP_THS` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum SingleDoubleTap {
    /// Detect only single-tap events (default).
    #[default]
    OnlySingle = 0,

    /// Detect both single- and double-tap events.
    BothSingleDouble = 1,
}

/// Data source for the 6D interrupt function.
///
/// This enum represents the data source options for the 6D interrupt function.
/// The data source is configured in the `CTRL7` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum LpassOn6d {
    /// ODR/2 low-pass filtered data (default).
    #[default]
    OdrDiv2Feed = 0,

    /// LPF2 output data.
    Lpf2Feed = 1,
}

/// Free-fall threshold configuration.
///
/// This enum represents the free-fall threshold options for the IIS2DLPC sensor.
/// The threshold is configured in the `FREE_FALL` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum FfThs {
    /// 5 LSB @ ±2g (default).
    #[default]
    _5Lsb = 0,

    /// 7 LSB @ ±2g.
    _7Lsb = 1,

    /// 8 LSB @ ±2g.
    _8Lsb = 2,

    /// 10 LSB @ ±2g.
    _10Lsb = 3,

    /// 11 LSB @ ±2g.
    _11Lsb = 4,

    /// 13 LSB @ ±2g.
    _13Lsb = 5,

    /// 15 LSB @ ±2g.
    _15Lsb = 6,

    /// 16 LSB @ ±2g.
    _16Lsb = 7,
}

/// FIFO mode configuration.
///
/// This enum represents the FIFO operating modes for the IIS2DLPC sensor.
/// The mode is configured in the `FIFO_CTRL` register.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Default, TryFrom)]
#[try_from(repr)]
pub enum Fmode {
    /// Bypass mode (default).
    #[default]
    BypassMode = 0,

    /// FIFO mode: Stops collecting data when FIFO is full.
    FifoMode = 1,

    /// Stream-to-FIFO mode: Stream mode until a trigger event, then FIFO mode.
    StreamToFifoMode = 3,

    /// Bypass-to-Stream mode: Bypass mode until a trigger event, then stream mode.
    BypassToStreamMode = 4,

    /// Stream mode: Continuously updates FIFO, overwriting old data when full.
    StreamMode = 6,
}