-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbmp3xx_data_structure.py
executable file
·1146 lines (1099 loc) · 35 KB
/
bmp3xx_data_structure.py
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
"""
Information needed to build the BMP3XX data structure.
It contains the dicts with the args needed to create the
Containers (Registers, Frames) and the InfoUnits of the Sensor.
These lists are imported at Sensor initialization.
Accurate information here is crucial for correct function of the driver.
The InfoUnits must have a ``container`` arg that is a string that
*exactly* matches the string ``name`` of a Register or Frame, that 'points'
to the container where the InfoUnit is.
The pack method of the InfoUnit translate de human-readable value of a InfoUnit into the value
that needs to be stored in the Register. The unpack method does the reverse operation.
Most time the methods are simple an can be represented with lambda functions inside the dict.
Other times the conversion is a little more involved and the function needs to be
declared outside the dict and referenced.
Another reason to declare the function outside the the dict is it's shared among
several InfoUnit and thus it can be reused.
In any case, these functions (including lambdas inside dicts) will behave like
bound methods of the corresponding InfoUnit time and **must** be defined with
``self`` as the first argument, as any bound method.
The second argument passed is always the value of the Container where the InfoUnit lives.
The Container and Sensor attributes can be accessed by ``self.container`` and ``self.sensor``.
"""
import math
from micropython import const
try:
from typing import Any
except ImportError:
pass
#########################
###### REGISTERS
#########################
REGISTERS = (
{
"name": const("REG_CHIP_ID"),
"container_type": const("data"),
"address": const(0x00),
"permission": const("RO"),
"size_bytes": const(1),
"help": const("chip id register, 1 byte"),
},
{
"name": const("REG_REV_ID"),
"container_type": const("data"),
"address": const(0x01),
"permission": const("RO"),
"size_bytes": const(1),
"help": const("ASIC revision, 1 byte"),
},
{
"name": const("REG_ERR_REG"),
"container_type": const("data"),
"address": const(0x02),
"permission": const("RO"),
"size_bytes": const(1),
"help": const("Error Register, 1 byte"),
},
{
"name": const("REG_STATUS"),
"container_type": const("data"),
"address": const(0x03),
"permission": const("RO"),
"size_bytes": const(1),
"help": const("Status Register (command, pressure and temp ready), 1 byte"),
},
{
"name": const("REG_DATA_PRESS_AND_TEMP"),
"container_type": const("data"),
"address": const(0x04),
"permission": const("RO"),
"size_bytes": const(6),
"help": const("ASIC revision, 1 byte"),
},
{
"name": const("REG_SENSORTIME"),
"container_type": const("data"),
"address": const(0x0C),
"permission": const("RO"),
"size_bytes": const(3),
"help": const("Sensortime register, 3 bytes"),
},
{
"name": const("REG_EVENT"),
"container_type": const("data"),
"address": const(0x10),
"permission": const("RO"),
"size_bytes": const(1),
"help": const("Event register, 1 byte"),
},
{
"name": const("REG_INT_STATUS"),
"container_type": const("data"),
"address": const(0x11),
"permission": const("RO"),
"size_bytes": const(1),
"help": const("Interruption status register, 1 byte"),
},
{
"name": const("REG_FIFO_LENGTH"),
"container_type": const("data"),
"address": const(0x12),
"permission": const("RO"),
"size_bytes": const(2),
"help": const("FIFO length register, 2 bytes"),
},
{
"name": const("REG_FIFO_DATA"),
"container_type": const("data"),
"address": const(0x14),
"permission": const("RO"),
# Burst read of 7 bytes allows frame by frame access to FIFO dato, though not recommended as primary way to access FIFO
"size_bytes": const(7),
"help": const("FIFO data register, 1 byte"),
},
{
"name": const("REG_FIFO_WTM"),
"container_type": const("config"),
"address": const(0x15),
"permission": const("RW"),
"size_bytes": const(2),
"help": const("fifo watermark level, 2 bytes (only lower 9 bits in use)"),
},
{
"name": const("REG_FIFO_CONFIG_1"),
"container_type": const("config"),
"address": const(0x17),
"permission": const("RW"),
"size_bytes": const(1),
"help": const("fifo config 1, 1 bytes (only lower 5 bits in use)"),
},
{
"name": const("REG_FIFO_CONFIG_2"),
"container_type": const("config"),
"address": const(0x18),
"permission": const("RW"),
"size_bytes": const(1),
"help": const("fifo config 2, 1 byte"),
},
{
"name": const("REG_INT_CTRL"),
"container_type": const("config"),
"address": const(0x19),
"permission": const("RW"),
"size_bytes": const(1),
"help": const("Interrupt control, 1 byte"),
},
{
"name": const("REG_IF_CONF"),
"container_type": const("config"),
"address": const(0x1A),
"permission": const("RW"),
"size_bytes": const(1),
"help": const("Serial Interface configuration, 1 byte"),
},
{
"name": const("REG_PWR_CTRL"),
"container_type": const("config"),
"address": const(0x1B),
"permission": const("RW"),
"size_bytes": const(1),
"help": const(
"controls sensor mode (sleep, forced, normal) and enables/disables press and temp sensors"
),
},
{
"name": const("REG_OSR"),
"container_type": const("config"),
"address": const(0x1C),
"permission": const("RW"),
"size_bytes": const(1),
"help": const("Oversampling register, 1 byte"),
},
{
"name": const("REG_ODR"),
"container_type": const("config"),
"address": const(0x1D),
"permission": const("RW"),
"size_bytes": const(1),
"help": const("Output Data Rate register, 1 byte"),
},
{
"name": const("REG_CONFIG"),
"container_type": const("config"),
"address": const(0x1F),
"permission": const("RW"),
"size_bytes": const(1),
"help": const("Config register, mainly IIR filter setting, 1 byte"),
},
{
"name": const("REG_CMD"),
"container_type": const("command"),
"address": const(0x7E),
"permission": const("WO"),
"size_bytes": const(1),
"help": const("Command register. NOP, FIFO_FLUSH, SOFTRESET"),
},
)
#########################
###### FRAMES
#########################
FRAMES = (
{
"name": const("FRAME_PRESS_AND_TEMP"),
"header": const(0x94),
"size_bytes": const(7),
"representation": const("B"),
"error_count": const(0),
"container_type": const("data"),
"help": "Frame containing pressure and temperature information",
},
{
"name": const("FRAME_TEMP"),
"header": const(0x90),
"size_bytes": const(4),
"representation": const("T"),
"error_count": const(0),
"container_type": const("data"),
"help": "Frame containing temperature information",
},
{
"name": const("FRAME_PRESS"),
"header": const(0x84),
"size_bytes": const(4),
"representation": const("P"),
"error_count": const(0),
"container_type": const("data"),
"help": "Frame containing pressure information",
},
{
"name": const("FRAME_SENSORTIME"),
"header": const(0xA0),
"size_bytes": const(4),
"representation": const("S"),
"error_count": const(0),
"container_type": const("data"),
"help": "Frame containing sensortime information",
},
{
"name": const("FRAME_CONFIG_CHANGE"),
"header": const(0x48),
"size_bytes": const(2),
"representation": const("C"),
"error_count": const(0),
"container_type": const("data"),
"help": "Frame inserted to indicate a change in FIFO configuration",
},
{
"name": const("FRAME_ERROR"),
"header": const(0x44),
"size_bytes": const(2),
"representation": const("X"),
"error_count": const(1),
"container_type": const("data"),
"help": "Error frame",
},
{
"name": const("FRAME_EMPTY"),
"header": const(0x80),
"size_bytes": const(2),
"representation": const("0"),
"error_count": const(0),
"container_type": const("data"),
"help": "Empty frame, inserted when burst read is longer than actual FIFO length",
},
)
##############################
###### Pack/unpack methods for Info Units
##############################
def bypass(self, value):
"""Does nothing, human-readable value is same as InfoUnit content,
can be used for both pack and unpack"""
return value
def int_to_bytes(self, value: int):
return value.to_bytes(self.size_bytes, self.sensor.endianness)
def bytes_to_int(self, content: bytes):
return int.from_bytes(content, self.sensor.endianness)
def pack_log2(self, value: int) -> int:
"""Pack value into log2(value)"""
return int(math.log2(value))
def unpack_log2(self, value: int) -> int:
"""Unpacks value 2**value"""
return 2**value
def compensate_readings(self, value: int) -> Any:
"""Sorts out the different ways in which adc values can arrive,
calls the function that calculate compensated reading in the correct way
and return the requested information.
Although the way the compensating is done is always the same, the ADC
values inside the InfoUnits do not come in the same position.
Args:
value (int): InfoUnit value
Raises:
Exception: If the InfoUnit in question is not supported by this method
Returns:
Any: (press, temp) tuple or press or temp alone depending on the InfoUnit
"""
if self.name == "press_and_temp":
adc_press = value & 0xFFFFFF
adc_temp = value >> 24 & 0xFFFFFF
return calculate_compensated_readings(self, (adc_press, adc_temp))
elif self.name == "press":
adc_press = value & 0xFFFFFF
adc_temp = value >> 24 & 0xFFFFFF
return calculate_compensated_readings(self, (adc_press, adc_temp))[0]
elif self.name == "temp":
adc_press = value & 0xFFFFFF
adc_temp = value >> 24 & 0xFFFFFF
return calculate_compensated_readings(self, (adc_press, adc_temp))[1]
elif self.name == "frameiu_press_and_temp":
# values come reversed in the frame
adc_press = value >> 24 & 0xFFFFFF
adc_temp = value & 0xFFFFFF
return calculate_compensated_readings(self, (adc_press, adc_temp))
elif self.name == "frameiu_temp":
# only temperature, pass 0 as pressure and return only temp
adc_press = 0.0
adc_temp = value & 0xFFFFFF
return calculate_compensated_readings(self, (adc_press, adc_temp))[1]
elif self.name == "frameiu_press":
# only pressure, pass 'standard temperature' and return only pressure
# 8.43692e6 is just an approx. adc_temp value for ~25C,
# needed for calculating pressure compensated value
adc_press = value & 0xFFFFFF
adc_temp = 8.43692e6
return calculate_compensated_readings(self, (adc_press, adc_temp))[0]
elif self.name == "altitude":
adc_press = value & 0xFFFFFF
adc_temp = value >> 24 & 0xFFFFFF
pressure = calculate_compensated_readings(self, (adc_press, adc_temp))[0]
return 44307.69 * (1 - (pressure / self.sensor._sea_level_pressure) ** 0.190284)
else:
raise Exception(
f"Unimplemented method for this type of InfoUnit: IU: {self.name}, Type: {self.iu_type}"
)
def calculate_compensated_readings(self, adc_values: tuple) -> tuple:
"""Resturns pressure (Pa) and temperature (C) compensated values from adc raw reads
adc_values is a tuple containing pressure and temp adc values (adc_press, adc_temp)
Needs to access calibration info stored in the sensor.
Args:
adc_values (tuple): (adc_press, adc_temp)
Returns:
tuple: compensated (press, temp), Pascals (Pa) and Celsius (C)
"""
adc_press, adc_temp = adc_values
# Datasheet 8.5
T1, T2, T3 = self.sensor._temp_calib
pd1 = adc_temp - T1
pd2 = pd1 * T2
temp = pd2 + (pd1 * pd1) * T3
# Datasheet 8.6
P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11 = self.sensor._pressure_calib
pd1 = P6 * temp
pd2 = P7 * temp**2.0
pd3 = P8 * temp**3.0
po1 = P5 + pd1 + pd2 + pd3
pd1 = P2 * temp
pd2 = P3 * temp**2.0
pd3 = P4 * temp**3.0
po2 = adc_press * (P1 + pd1 + pd2 + pd3)
pd1 = adc_press**2.0
pd2 = P9 + P10 * temp
pd3 = pd1 * pd2
pd4 = pd3 + P11 * adc_press**3.0
pressure = po1 + po2 + pd4
return (pressure, temp)
def parse_single_fifo_frame(self, frame_content: int) -> Any:
"""
Parses the content of a single FIFO frame and returns the corresponding values.
Caller should carefully check returned values as they can change depending on the type of frame received
"""
frame_header = frame_content & self.sensor.frame_header_mask
frame_data = frame_content >> self.sensor.frame_header_size * 8
sensor_frames = self.sensor._sensor_frames
if frame_header in sensor_frames:
frame = sensor_frames[frame_header]
return frame.read(frame_data)
else:
return "Invalid header"
##############################
###### Info units in Registers
##############################
INFO_UNITS = (
{
"name": const("chip_id"),
"iu_type": const("data"),
"container": "REG_CHIP_ID",
"size_bits": const(8),
"shift": const(0),
"unpack": bypass,
"help": const("Chip ID stored in NVM"),
},
{
"name": const("rev_id"),
"iu_type": const("data"),
"container": "REG_REV_ID",
"size_bits": const(8),
"shift": const(0),
"unpack": bypass,
"help": const("ASIC mask revision (minor)"),
},
{
"name": const("fatal_err"),
"iu_type": const("data"),
"container": "REG_ERR_REG",
"size_bits": const(1),
"shift": const(0),
"unpack": bypass,
"help": const("Fatal error bit"),
},
{
"name": const("cmd_err"),
"iu_type": const("data"),
"container": "REG_ERR_REG",
"size_bits": const(1),
"shift": const(1),
"unpack": bypass,
"help": const("Command error bit"),
},
{
"name": const("conf_err"),
"iu_type": const("data"),
"container": "REG_ERR_REG",
"size_bits": const(1),
"shift": const(2),
"unpack": bypass,
"help": const("Configuration error bit"),
},
{
"name": const("cmd_rdy"),
"iu_type": const("data"),
"container": "REG_STATUS",
"size_bits": const(1),
"shift": const(4),
"unpack": bypass,
"help": const("Command ready bit, 1 if ready to accept new command"),
},
{
"name": const("drdy_press"),
"iu_type": const("data"),
"container": "REG_STATUS",
"size_bits": const(1),
"shift": const(5),
"unpack": bypass,
"help": const("Pressure data ready bit, 1 if pressure data is ready to be read."),
},
{
"name": const("drdy_temp"),
"iu_type": const("data"),
"container": "REG_STATUS",
"size_bits": const(1),
"shift": const(6),
"unpack": bypass,
"help": const(
"Temperature data ready bit, 1 if temperature data is ready to be read."
),
},
{
"name": const("press_and_temp"),
"iu_type": const("data"),
"container": "REG_DATA_PRESS_AND_TEMP",
"size_bits": const(48),
"shift": const(0),
"unpack": compensate_readings,
"help": const("Pressure (Pa) and temperature (C) compensated values."),
},
{
"name": const("press"),
"iu_type": const("data"),
"container": "REG_DATA_PRESS_AND_TEMP",
"size_bits": const(48),
"shift": const(0),
"unpack": compensate_readings,
"help": const("Pressure (Pa) compensated value."),
},
{
"name": const("temp"),
"iu_type": const("data"),
"container": "REG_DATA_PRESS_AND_TEMP",
"size_bits": const(48),
"shift": const(0),
"unpack": compensate_readings,
"help": const("Temperature (C) compensated value."),
},
{
"name": const("press_and_temp_adc"),
"iu_type": const("data"),
"container": "REG_DATA_PRESS_AND_TEMP",
"size_bits": const(48),
"shift": const(0),
"unpack": lambda self, content: (
content & 0x000000FFFFFF,
content >> 24 & 0x000000FFFFFF,
),
"help": const("Pressure and temperature ADC raw values."),
},
{
# Derivative InfoUnit, does not exist in the sensor
"name": const("altitude"),
"iu_type": const("data"),
"container": "REG_DATA_PRESS_AND_TEMP",
"size_bits": const(48),
"shift": const(0),
"unpack": compensate_readings,
"help": const(
"Altitude in meters. Should calibrate sensor before reading altitude."
),
},
{
"name": const("sensortime"),
"iu_type": const("data"),
"container": "REG_SENSORTIME",
"size_bits": const(24),
"shift": const(0),
"unpack": lambda self, content: content & 0xFFFFFF,
"help": const("Sensor Time"),
},
{
"name": const("por_detected"),
"iu_type": const("data"),
"container": "REG_EVENT",
"size_bits": const(1),
"shift": const(0),
"unpack": bypass,
"help": const("1 after device power up or softreset. Cleared on read"),
},
{
"name": const("itf_act_pt"),
"iu_type": const("data"),
"container": "REG_EVENT",
"size_bits": const(1),
"shift": const(1),
"unpack": bypass,
"help": const(
"1 when serial interface transaction occurs during a pressure or temperature conversion. Cleared on read"
),
},
{
"name": const("fwm_int"),
"iu_type": const("data"),
"container": "REG_INT_STATUS",
"size_bits": const(1),
"shift": const(0),
"unpack": bypass,
"help": const("FIFO watermark interrupt status"),
},
{
"name": const("ffull_int"),
"iu_type": const("data"),
"container": "REG_INT_STATUS",
"size_bits": const(1),
"shift": const(1),
"unpack": bypass,
"help": const("FIFO full interrupt status"),
},
{
"name": const("drdy"),
"iu_type": const("data"),
"container": "REG_INT_STATUS",
"size_bits": const(1),
"shift": const(3),
"unpack": bypass,
"help": const("Data Ready interrupt status"),
},
{
"name": const("fifo_length"),
"iu_type": const("data"),
"container": "REG_FIFO_LENGTH",
"size_bits": const(9),
"shift": const(0),
"unpack": bypass,
"help": const("FIFO length in bytes 0-511 (9-bits)"),
},
{
"name": const("fifo_data"),
"iu_type": const("data"),
"container": "REG_FIFO_DATA",
"size_bits": const(7 * 8),
"shift": const(0),
"unpack": parse_single_fifo_frame,
"help": const(
"FIFO 7 bytes of raw data (frames), should not be primary FIFO data access"
),
},
{
"name": const("fifo_water_mark"),
"iu_type": const("config"),
"container": "REG_FIFO_WTM",
"default": const(255),
"size_bits": const(9),
"shift": const(0),
"allowed": range(512),
"pack": bypass,
"unpack": bypass,
"help": const("FIFO watermark level in bytes 0-511 (9-bit)"),
},
{
"name": const("fifo_mode"),
"iu_type": const("config"),
"container": "REG_FIFO_CONFIG_1",
"default": const(0),
"size_bits": const(1),
"shift": const(0),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enables/Disables (1/0) FIFO"),
},
{
"name": const("fifo_stop_on_full"),
"iu_type": const("config"),
"container": "REG_FIFO_CONFIG_1",
"default": const(0),
"size_bits": const(1),
"shift": const(1),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const(
"FIFO full behavior, 0: discard old samples, 1: discard new samples"
),
},
{
"name": const("fifo_time_en"),
"iu_type": const("config"),
"container": "REG_FIFO_CONFIG_1",
"default": const(0),
"size_bits": const(1),
"shift": const(2),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable return of sensortime frames in FIFO reads"),
},
{
"name": const("fifo_press_en"),
"iu_type": const("config"),
"container": "REG_FIFO_CONFIG_1",
"default": const(1),
"size_bits": const(1),
"shift": const(3),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable return of pressure frames in FIFO reads"),
},
{
"name": const("fifo_temp_en"),
"iu_type": const("config"),
"container": "REG_FIFO_CONFIG_1",
"default": const(1),
"size_bits": const(1),
"shift": const(4),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable return of temperature frames in FIFO reads"),
},
{
"name": const("fifo_subsampling"),
"iu_type": const("config"),
"container": "REG_FIFO_CONFIG_2",
"default": const(1),
"size_bits": const(3),
"shift": const(0),
"allowed": (1, 2, 4, 8, 16, 32, 64, 128),
"pack": pack_log2,
"unpack": unpack_log2,
"help": const("FIFO subsampling factor (human readable). Datasheet 3.6.2"),
},
{
"name": const("data_select"),
"iu_type": const("config"),
"container": "REG_FIFO_CONFIG_2",
"default": const("unfiltered"),
"size_bits": const(2),
"shift": const(3),
"allowed": ("filtered", "unfiltered"),
"pack": lambda self, value: {"filtered": 1, "unfiltered": 0}.get(value),
"unpack": lambda self, content: {
1: "filtered",
0: "unfiltered",
2: "unfiltered",
3: "unfiltered",
}.get(content),
"help": const("FIFO data source (human readable), filtered or unfiltered"),
},
{
"name": const("int_od"),
"iu_type": const("config"),
"container": "REG_INT_CTRL",
"default": const("push-pull"),
"size_bits": const(1),
"shift": const(0),
"allowed": ("push-pull", "open-drain"),
"pack": lambda self, value: {"push-pull": 0, "open-drain": 1}.get(value),
"unpack": lambda self, content: {0: "push-pull", 1: "open-drain"}.get(content),
"help": const("Interrupt output type (human readable), push-pull or open-drain"),
},
{
"name": const("int_level"),
"iu_type": const("config"),
"container": "REG_INT_CTRL",
"default": const(1),
"size_bits": const(1),
"shift": const(1),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Interrupt active level 1: high, 0: low"),
},
{
"name": const("int_latch"),
"iu_type": const("config"),
"container": "REG_INT_CTRL",
"default": const(0),
"size_bits": const(1),
"shift": const(2),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const(
"Enable interrupt latching for INT pin and INT_STATUS register. Datasheet 3.7.2"
),
},
{
"name": const("fwtm_en"),
"iu_type": const("config"),
"container": "REG_INT_CTRL",
"default": const(0),
"size_bits": const(1),
"shift": const(3),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const(
"Enable FIFO watermark level reached interrupt (INT pin and INT_STATUS)"
),
},
{
"name": const("ffull_en"),
"iu_type": const("config"),
"container": "REG_INT_CTRL",
"default": const(0),
"size_bits": const(1),
"shift": const(4),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable FIFO full interrupt (INT pin and INT_STATUS)"),
},
{
"name": const("int_ds"),
"iu_type": const("config"),
"container": "REG_INT_CTRL",
"default": const(0),
"size_bits": const(1),
"shift": const(5),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("int_ds 0: low, 1: high"),
},
{
"name": const("drdy_en"),
"iu_type": const("config"),
"container": "REG_INT_CTRL",
"default": const(0),
"size_bits": const(1),
"shift": const(6),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable data ready interrupt (INT pin and INT_STATUS)"),
},
{
"name": const("spi3"),
"iu_type": const("config"),
"container": "REG_IF_CONF",
"default": const("spi4"),
"size_bits": const(1),
"shift": const(0),
"allowed": ("spi3", "spi4"),
"pack": lambda self, value: {"spi4": 0, "spi3": 1}.get(value),
"unpack": lambda self, content: {0: "spi4", 1: "spi3"}.get(content),
"help": const(
"Configure spi interface mode (human readable), spi4 or spi3 for 4-wire and 3-wire configurations"
),
},
{
"name": const("i2c_wdt_en"),
"iu_type": const("config"),
"container": "REG_IF_CONF",
"default": const(0),
"size_bits": const(1),
"shift": const(1),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable i2c watchdog timer"),
},
{
"name": const("i2c_wdt_sel"),
"iu_type": const("config"),
"container": "REG_IF_CONF",
"default": const("wdt_short"),
"size_bits": const(1),
"shift": const(2),
"allowed": ("wdt_short", "wdt_long"),
"pack": lambda self, value: {"wdt_short": 0, "wdt_long": 1}.get(value),
"unpack": lambda self, content: {0: "wdt_short", 1: "wdt_long"}.get(content),
"help": const(
"I2c watchdog timer select (human readable): wdt_short: 1.25ms or wdt_long: 40ms"
),
},
{
"name": const("press_en"),
"iu_type": const("config"),
"container": "REG_PWR_CTRL",
"default": const(1),
"size_bits": const(1),
"shift": const(0),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable/Disable (1/0) pressure sensor"),
},
{
"name": const("temp_en"),
"iu_type": const("config"),
"container": "REG_PWR_CTRL",
"default": const(1),
"size_bits": const(1),
"shift": const(1),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("Enable/Disable (1/0) temperature sensor"),
},
{
"name": const("mode"),
"iu_type": const("config"),
"container": "REG_PWR_CTRL",
"default": const("sleep"),
"size_bits": const(2),
"shift": const(4),
"allowed": ("sleep", "forced", "normal"),
"pack": lambda self, value: {"sleep": 0, "forced": 1, "normal": 3}.get(value),
"unpack": lambda self, content: {
0: "sleep",
1: "forced",
2: "forced",
3: "normal",
}.get(content),
"help": const("Controls sensor power mode: sleep, forced, normal"),
},
{
"name": const("osr_p"),
"iu_type": const("config"),
"container": "REG_OSR",
"default": const(2),
"size_bits": const(3),
"shift": const(0),
"allowed": (1, 2, 4, 8, 16, 32),
"pack": pack_log2,
"unpack": unpack_log2,
"help": const("Pressure oversampling (human readable). Datasheet 3.4.4"),
},
{
"name": const("osr_t"),
"iu_type": const("config"),
"container": "REG_OSR",
"default": const(1),
"size_bits": const(3),
"shift": const(3),
"allowed": (1, 2, 4, 8, 16, 32),
"pack": pack_log2,
"unpack": unpack_log2,
"help": const("Temperature oversampling (human readable). Datasheet 3.4.4"),
},
{
"name": const("odr_sel"),
"iu_type": const("config"),
"container": "REG_ODR",
"default": const(10),
"size_bits": const(5),
"shift": const(0),
"allowed": (
5,
10,
20,
40,
80,
160,
320,
640,
1280,
5120,
10240,
20480,
40960,
81920,
163840,
327680,
655360,
),
"pack": lambda self, value: int(math.log2(value / 5)),
"unpack": lambda self, content: 2**content * 5,
"help": const(
"Output data rate (human readable). Sampling period in ms, which is more natural for event loops. Datasheet 4.3.20"
),
},
{
"name": const("short_in"),
"iu_type": const("config"),
"container": "REG_CONFIG",
"default": const(0),
"size_bits": const(1),
"shift": const(0),
"allowed": (0, 1),
"pack": bypass,
"unpack": bypass,
"help": const("short_in"),
},
{
"name": const("iir_filter"),
"iu_type": const("config"),
"container": "REG_CONFIG",
"default": const(0),
"size_bits": const(3),
"shift": const(1),
"allowed": (0, 2, 4, 8, 16, 32, 64, 128),
"pack": lambda self, value: int(math.log2(value)) if value > 0 else 0,
"unpack": lambda self, content: int(2**content) if content > 0 else 0,
"help": const("IIR filter coefficient (human readable). Datasheet 3.4.3"),
},
{
"name": const("cmd"),
"iu_type": const("config"),
"container": "REG_CMD",
"default": const("nop"),
"size_bits": const(8),
"shift": const(0),
"allowed": ("nop", "fifo_flush", "softreset"),
"pack": lambda self, value: {
"nop": 0,
"fifo_flush": 0xB0,
"softreset": 0xB6,
}.get(value),
# This register cannot be reliably read
"unpack": lambda self, content: "nop",
"help": const("Receives a command to execute"),
},
##############################
###### Info units in Frames
##############################
{