-
Notifications
You must be signed in to change notification settings - Fork 26
/
bma400_defs.h
1441 lines (1176 loc) · 48.4 KB
/
bma400_defs.h
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
/**
* Copyright (c) 2024 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bma400_defs.h
* @date 2024-05-10
* @version v1.5.10
*
*/
/*! @cond DOXYGEN_BMA400_DEFS_H_ */
#ifndef BMA400_DEFS_H_
#define BMA400_DEFS_H_
#ifdef __KERNEL__
#include <linux/types.h>
#include <linux/kernel.h>
#else
#include <stdint.h>
#include <stddef.h>
#endif
#if !defined(UINT8_C) && !defined(INT8_C)
#define INT8_C(x) S8_C(x)
#define UINT8_C(x) U8_C(x)
#endif
#if !defined(UINT16_C) && !defined(INT16_C)
#define INT16_C(x) S16_C(x)
#define UINT16_C(x) U16_C(x)
#endif
#if !defined(INT32_C) && !defined(UINT32_C)
#define INT32_C(x) S32_C(x)
#define UINT32_C(x) U32_C(x)
#endif
#if !defined(INT64_C) && !defined(UINT64_C)
#define INT64_C(x) S64_C(x)
#define UINT64_C(x) U64_C(x)
#endif
/* C standard macros */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *) 0)
#endif
#endif
#ifndef TRUE
#define TRUE UINT8_C(1)
#endif
#ifndef FALSE
#define FALSE UINT8_C(0)
#endif
/*!
* BMA400_INTF_RET_TYPE is the read/write interface return type which can be overwritten by the build system.
* The default is set to int8_t.
*/
#ifndef BMA400_INTF_RET_TYPE
#define BMA400_INTF_RET_TYPE int8_t
#endif
/*!
* BMA400_INTF_RET_SUCCESS is the success return value read/write interface return type which can be
* overwritten by the build system. The default is set to 0.
*/
#ifndef BMA400_INTF_RET_SUCCESS
#define BMA400_INTF_RET_SUCCESS INT8_C(0)
#endif
/* API success code */
#define BMA400_OK INT8_C(0)
/* API error codes */
#define BMA400_E_NULL_PTR INT8_C(-1)
#define BMA400_E_COM_FAIL INT8_C(-2)
#define BMA400_E_DEV_NOT_FOUND INT8_C(-3)
#define BMA400_E_INVALID_CONFIG INT8_C(-4)
/* API warning codes */
#define BMA400_W_SELF_TEST_FAIL INT8_C(1)
/* CHIP ID VALUE */
#define BMA400_CHIP_ID UINT8_C(0x90)
/* BMA400 I2C address macros */
#define BMA400_I2C_ADDRESS_SDO_LOW UINT8_C(0x14)
#define BMA400_I2C_ADDRESS_SDO_HIGH UINT8_C(0x15)
/* Maximum read length */
#define BMA400_MAX_LEN UINT8_C(128)
/* Power mode configurations */
#define BMA400_MODE_NORMAL UINT8_C(0x02)
#define BMA400_MODE_SLEEP UINT8_C(0x00)
#define BMA400_MODE_LOW_POWER UINT8_C(0x01)
/* Enable / Disable macros */
#define BMA400_DISABLE UINT8_C(0)
#define BMA400_ENABLE UINT8_C(1)
/* Data/sensortime selection macros */
#define BMA400_DATA_ONLY UINT8_C(0x00)
#define BMA400_DATA_SENSOR_TIME UINT8_C(0x01)
/* ODR configurations */
#define BMA400_ODR_12_5HZ UINT8_C(0x05)
#define BMA400_ODR_25HZ UINT8_C(0x06)
#define BMA400_ODR_50HZ UINT8_C(0x07)
#define BMA400_ODR_100HZ UINT8_C(0x08)
#define BMA400_ODR_200HZ UINT8_C(0x09)
#define BMA400_ODR_400HZ UINT8_C(0x0A)
#define BMA400_ODR_800HZ UINT8_C(0x0B)
/* Accel Range configuration */
#define BMA400_RANGE_2G UINT8_C(0x00)
#define BMA400_RANGE_4G UINT8_C(0x01)
#define BMA400_RANGE_8G UINT8_C(0x02)
#define BMA400_RANGE_16G UINT8_C(0x03)
/* Accel Axes selection settings for
* DATA SAMPLING, WAKEUP, ORIENTATION CHANGE,
* GEN1, GEN2 , ACTIVITY CHANGE
*/
#define BMA400_AXIS_X_EN UINT8_C(0x01)
#define BMA400_AXIS_Y_EN UINT8_C(0x02)
#define BMA400_AXIS_Z_EN UINT8_C(0x04)
#define BMA400_AXIS_XYZ_EN UINT8_C(0x07)
/* Accel filter(data_src_reg) selection settings */
#define BMA400_DATA_SRC_ACCEL_FILT_1 UINT8_C(0x00)
#define BMA400_DATA_SRC_ACCEL_FILT_2 UINT8_C(0x01)
#define BMA400_DATA_SRC_ACCEL_FILT_LP UINT8_C(0x02)
/* Accel OSR (OSR,OSR_LP) settings */
#define BMA400_ACCEL_OSR_SETTING_0 UINT8_C(0x00)
#define BMA400_ACCEL_OSR_SETTING_1 UINT8_C(0x01)
#define BMA400_ACCEL_OSR_SETTING_2 UINT8_C(0x02)
#define BMA400_ACCEL_OSR_SETTING_3 UINT8_C(0x03)
/* Accel filt1_bw settings */
/* Accel filt1_bw = 0.48 * ODR */
#define BMA400_ACCEL_FILT1_BW_0 UINT8_C(0x00)
/* Accel filt1_bw = 0.24 * ODR */
#define BMA400_ACCEL_FILT1_BW_1 UINT8_C(0x01)
/* Auto wake-up timeout value of 10.24s */
#define BMA400_TIMEOUT_MAX_AUTO_WAKEUP UINT16_C(0x0FFF)
/* Auto low power timeout value of 10.24s */
#define BMA400_TIMEOUT_MAX_AUTO_LP UINT16_C(0x0FFF)
/* Reference Update macros */
#define BMA400_UPDATE_MANUAL UINT8_C(0x00)
#define BMA400_UPDATE_ONE_TIME UINT8_C(0x01)
#define BMA400_UPDATE_EVERY_TIME UINT8_C(0x02)
#define BMA400_UPDATE_LP_EVERY_TIME UINT8_C(0x03)
/* Reference Update macros for orient interrupts */
#define BMA400_ORIENT_REFU_ACC_FILT_2 UINT8_C(0x01)
#define BMA400_ORIENT_REFU_ACC_FILT_LP UINT8_C(0x02)
/* Number of samples needed for Auto-wakeup interrupt evaluation */
#define BMA400_SAMPLE_COUNT_1 UINT8_C(0x00)
#define BMA400_SAMPLE_COUNT_2 UINT8_C(0x01)
#define BMA400_SAMPLE_COUNT_3 UINT8_C(0x02)
#define BMA400_SAMPLE_COUNT_4 UINT8_C(0x03)
#define BMA400_SAMPLE_COUNT_5 UINT8_C(0x04)
#define BMA400_SAMPLE_COUNT_6 UINT8_C(0x05)
#define BMA400_SAMPLE_COUNT_7 UINT8_C(0x06)
#define BMA400_SAMPLE_COUNT_8 UINT8_C(0x07)
/* Auto low power configurations */
/* Auto low power timeout disabled */
#define BMA400_AUTO_LP_TIMEOUT_DISABLE UINT8_C(0x00)
/* Auto low power entered on drdy interrupt */
#define BMA400_AUTO_LP_DRDY_TRIGGER UINT8_C(0x01)
/* Auto low power entered on GEN1 interrupt */
#define BMA400_AUTO_LP_GEN1_TRIGGER UINT8_C(0x02)
/* Auto low power entered on timeout of threshold value */
#define BMA400_AUTO_LP_TIMEOUT_EN UINT8_C(0x04)
/* Auto low power entered on timeout of threshold value
* but reset on activity detection
*/
#define BMA400_AUTO_LP_TIME_RESET_EN UINT8_C(0x08)
/* TAP INTERRUPT CONFIG MACROS */
/* Axes select for TAP interrupt */
#define BMA400_TAP_X_AXIS_EN UINT8_C(0x02)
#define BMA400_TAP_Y_AXIS_EN UINT8_C(0x01)
#define BMA400_TAP_Z_AXIS_EN UINT8_C(0x00)
/* TAP tics_th setting */
/* Maximum time between upper and lower peak of a tap, in data samples
* this time depends on the mechanics of the device tapped onto
* default = 12 samples
*/
/* Configures 6 data samples for high-low tap signal change time */
#define BMA400_TICS_TH_6_DATA_SAMPLES UINT8_C(0x00)
/* Configures 9 data samples for high-low tap signal change time */
#define BMA400_TICS_TH_9_DATA_SAMPLES UINT8_C(0x01)
/* Configures 12 data samples for high-low tap signal change time */
#define BMA400_TICS_TH_12_DATA_SAMPLES UINT8_C(0x02)
/* Configures 18 data samples for high-low tap signal change time */
#define BMA400_TICS_TH_18_DATA_SAMPLES UINT8_C(0x03)
/* TAP Sensitivity setting */
/* It modifies the threshold for minimum TAP amplitude */
/* BMA400_TAP_SENSITIVITY_0 correspond to highest sensitivity */
#define BMA400_TAP_SENSITIVITY_0 UINT8_C(0x00)
#define BMA400_TAP_SENSITIVITY_1 UINT8_C(0x01)
#define BMA400_TAP_SENSITIVITY_2 UINT8_C(0x02)
#define BMA400_TAP_SENSITIVITY_3 UINT8_C(0x03)
#define BMA400_TAP_SENSITIVITY_4 UINT8_C(0x04)
#define BMA400_TAP_SENSITIVITY_5 UINT8_C(0x05)
#define BMA400_TAP_SENSITIVITY_6 UINT8_C(0x06)
/* BMA400_TAP_SENSITIVITY_7 correspond to lowest sensitivity */
#define BMA400_TAP_SENSITIVITY_7 UINT8_C(0x07)
/* BMA400 TAP - quiet settings */
/* Quiet refers to minimum quiet time before and after double tap,
* in the data samples This time also defines the longest time interval
* between two taps so that they are considered as double tap
*/
/* Configures 60 data samples quiet time between single or double taps */
#define BMA400_QUIET_60_DATA_SAMPLES UINT8_C(0x00)
/* Configures 80 data samples quiet time between single or double taps */
#define BMA400_QUIET_80_DATA_SAMPLES UINT8_C(0x01)
/* Configures 100 data samples quiet time between single or double taps */
#define BMA400_QUIET_100_DATA_SAMPLES UINT8_C(0x02)
/* Configures 120 data samples quiet time between single or double taps */
#define BMA400_QUIET_120_DATA_SAMPLES UINT8_C(0x03)
/* BMA400 TAP - quiet_dt settings */
/* quiet_dt refers to Minimum time between the two taps of a
* double tap, in data samples
*/
/* Configures 4 data samples minimum time between double taps */
#define BMA400_QUIET_DT_4_DATA_SAMPLES UINT8_C(0x00)
/* Configures 8 data samples minimum time between double taps */
#define BMA400_QUIET_DT_8_DATA_SAMPLES UINT8_C(0x01)
/* Configures 12 data samples minimum time between double taps */
#define BMA400_QUIET_DT_12_DATA_SAMPLES UINT8_C(0x02)
/* Configures 16 data samples minimum time between double taps */
#define BMA400_QUIET_DT_16_DATA_SAMPLES UINT8_C(0x03)
/* ACTIVITY CHANGE CONFIG MACROS */
/* Data source for activity change detection */
#define BMA400_DATA_SRC_ACC_FILT1 UINT8_C(0x00)
#define BMA400_DATA_SRC_ACC_FILT2 UINT8_C(0x01)
/* Number of samples to evaluate for activity change detection */
#define BMA400_ACT_CH_SAMPLE_CNT_32 UINT8_C(0x00)
#define BMA400_ACT_CH_SAMPLE_CNT_64 UINT8_C(0x01)
#define BMA400_ACT_CH_SAMPLE_CNT_128 UINT8_C(0x02)
#define BMA400_ACT_CH_SAMPLE_CNT_256 UINT8_C(0x03)
#define BMA400_ACT_CH_SAMPLE_CNT_512 UINT8_C(0x04)
/* Interrupt pin configuration macros */
#define BMA400_INT_PUSH_PULL_ACTIVE_0 UINT8_C(0x00)
#define BMA400_INT_PUSH_PULL_ACTIVE_1 UINT8_C(0x01)
#define BMA400_INT_OPEN_DRIVE_ACTIVE_0 UINT8_C(0x02)
#define BMA400_INT_OPEN_DRIVE_ACTIVE_1 UINT8_C(0x03)
/* Interrupt Assertion status macros */
#define BMA400_ASSERTED_WAKEUP_INT UINT16_C(0x0001)
#define BMA400_ASSERTED_ORIENT_CH UINT16_C(0x0002)
#define BMA400_ASSERTED_GEN1_INT UINT16_C(0x0004)
#define BMA400_ASSERTED_GEN2_INT UINT16_C(0x0008)
#define BMA400_ASSERTED_INT_OVERRUN UINT16_C(0x0010)
#define BMA400_ASSERTED_FIFO_FULL_INT UINT16_C(0x0020)
#define BMA400_ASSERTED_FIFO_WM_INT UINT16_C(0x0040)
#define BMA400_ASSERTED_DRDY_INT UINT16_C(0x0080)
#define BMA400_ASSERTED_STEP_INT UINT16_C(0x0300)
#define BMA400_ASSERTED_S_TAP_INT UINT16_C(0x0400)
#define BMA400_ASSERTED_D_TAP_INT UINT16_C(0x0800)
#define BMA400_ASSERTED_ACT_CH_X UINT16_C(0x2000)
#define BMA400_ASSERTED_ACT_CH_Y UINT16_C(0x4000)
#define BMA400_ASSERTED_ACT_CH_Z UINT16_C(0x8000)
/* Generic interrupt criterion_sel configuration macros */
#define BMA400_ACTIVITY_INT UINT8_C(0x01)
#define BMA400_INACTIVITY_INT UINT8_C(0x00)
/* Generic interrupt axes evaluation logic configuration macros */
#define BMA400_ALL_AXES_INT UINT8_C(0x01)
#define BMA400_ANY_AXES_INT UINT8_C(0x00)
/* Generic interrupt hysteresis configuration macros */
#define BMA400_HYST_0_MG UINT8_C(0x00)
#define BMA400_HYST_24_MG UINT8_C(0x01)
#define BMA400_HYST_48_MG UINT8_C(0x02)
#define BMA400_HYST_96_MG UINT8_C(0x03)
/* BMA400 Register Address */
#define BMA400_REG_CHIP_ID UINT8_C(0x00)
#define BMA400_REG_STATUS UINT8_C(0x03)
#define BMA400_REG_ACCEL_DATA UINT8_C(0x04)
#define BMA400_REG_INT_STAT0 UINT8_C(0x0E)
#define BMA400_REG_TEMP_DATA UINT8_C(0x11)
#define BMA400_REG_FIFO_LENGTH UINT8_C(0x12)
#define BMA400_REG_FIFO_DATA UINT8_C(0x14)
#define BMA400_REG_STEP_CNT_0 UINT8_C(0x15)
#define BMA400_REG_ACCEL_CONFIG_0 UINT8_C(0x19)
#define BMA400_REG_ACCEL_CONFIG_1 UINT8_C(0x1A)
#define BMA400_REG_ACCEL_CONFIG_2 UINT8_C(0x1B)
#define BMA400_REG_INT_CONF_0 UINT8_C(0x1F)
#define BMA400_REG_INT_12_IO_CTRL UINT8_C(0x24)
#define BMA400_REG_INT_MAP UINT8_C(0x21)
#define BMA400_REG_FIFO_CONFIG_0 UINT8_C(0x26)
#define BMA400_REG_FIFO_READ_EN UINT8_C(0x29)
#define BMA400_REG_AUTO_LOW_POW_0 UINT8_C(0x2A)
#define BMA400_REG_AUTO_LOW_POW_1 UINT8_C(0x2B)
#define BMA400_REG_AUTOWAKEUP_0 UINT8_C(0x2C)
#define BMA400_REG_AUTOWAKEUP_1 UINT8_C(0x2D)
#define BMA400_REG_WAKEUP_INT_CONF_0 UINT8_C(0x2F)
#define BMA400_REG_ORIENTCH_INT_CONFIG UINT8_C(0x35)
#define BMA400_REG_GEN1_INT_CONFIG UINT8_C(0x3F)
#define BMA400_REG_GEN2_INT_CONFIG UINT8_C(0x4A)
#define BMA400_REG_ACT_CH_CONFIG_0 UINT8_C(0x55)
#define BMA400_REG_TAP_CONFIG UINT8_C(0x57)
#define BMA400_REG_SELF_TEST UINT8_C(0x7D)
#define BMA400_REG_COMMAND UINT8_C(0x7E)
/* BMA400 Command register */
#define BMA400_SOFT_RESET_CMD UINT8_C(0xB6)
#define BMA400_FIFO_FLUSH_CMD UINT8_C(0xB0)
/* BMA400 Delay definitions */
#define BMA400_DELAY_US_SOFT_RESET UINT8_C(5000)
#define BMA400_DELAY_US_SELF_TEST UINT8_C(7000)
#define BMA400_DELAY_US_SELF_TEST_DATA_READ UINT8_C(50000)
/* Interface selection macro */
#define BMA400_SPI_WR_MASK UINT8_C(0x7F)
#define BMA400_SPI_RD_MASK UINT8_C(0x80)
/* UTILITY MACROS */
#define BMA400_SET_LOW_BYTE UINT16_C(0x00FF)
#define BMA400_SET_HIGH_BYTE UINT16_C(0xFF00)
/* Interrupt mapping selection */
#define BMA400_DATA_READY_INT_MAP UINT8_C(0x01)
#define BMA400_FIFO_WM_INT_MAP UINT8_C(0x02)
#define BMA400_FIFO_FULL_INT_MAP UINT8_C(0x03)
#define BMA400_GEN2_INT_MAP UINT8_C(0x04)
#define BMA400_GEN1_INT_MAP UINT8_C(0x05)
#define BMA400_ORIENT_CH_INT_MAP UINT8_C(0x06)
#define BMA400_WAKEUP_INT_MAP UINT8_C(0x07)
#define BMA400_ACT_CH_INT_MAP UINT8_C(0x08)
#define BMA400_TAP_INT_MAP UINT8_C(0x09)
#define BMA400_STEP_INT_MAP UINT8_C(0x0A)
#define BMA400_INT_OVERRUN_MAP UINT8_C(0x0B)
/* BMA400 FIFO configurations */
#define BMA400_FIFO_AUTO_FLUSH UINT8_C(0x01)
#define BMA400_FIFO_STOP_ON_FULL UINT8_C(0x02)
#define BMA400_FIFO_TIME_EN UINT8_C(0x04)
#define BMA400_FIFO_DATA_SRC UINT8_C(0x08)
#define BMA400_FIFO_8_BIT_EN UINT8_C(0x10)
#define BMA400_FIFO_X_EN UINT8_C(0x20)
#define BMA400_FIFO_Y_EN UINT8_C(0x40)
#define BMA400_FIFO_Z_EN UINT8_C(0x80)
/* BMA400 FIFO data configurations */
#define BMA400_FIFO_EN_X UINT8_C(0x01)
#define BMA400_FIFO_EN_Y UINT8_C(0x02)
#define BMA400_FIFO_EN_Z UINT8_C(0x04)
#define BMA400_FIFO_EN_XY UINT8_C(0x03)
#define BMA400_FIFO_EN_YZ UINT8_C(0x06)
#define BMA400_FIFO_EN_XZ UINT8_C(0x05)
#define BMA400_FIFO_EN_XYZ UINT8_C(0x07)
/* BMA400 Self test configurations */
#define BMA400_SELF_TEST_DISABLE UINT8_C(0x00)
#define BMA400_SELF_TEST_ENABLE_POSITIVE UINT8_C(0x07)
#define BMA400_SELF_TEST_ENABLE_NEGATIVE UINT8_C(0x0F)
/* BMA400 FIFO data masks */
#define BMA400_FIFO_HEADER_MASK UINT8_C(0x3E)
#define BMA400_FIFO_BYTES_OVERREAD UINT8_C(100)
#define BMA400_AWIDTH_MASK UINT8_C(0xEF)
#define BMA400_FIFO_DATA_EN_MASK UINT8_C(0x0E)
/* BMA400 Step status field - Activity status */
#define BMA400_STILL_ACT UINT8_C(0x00)
#define BMA400_WALK_ACT UINT8_C(0x01)
#define BMA400_RUN_ACT UINT8_C(0x02)
/* It is inserted when FIFO_CONFIG0.fifo_data_src
* is changed during the FIFO read
*/
#define BMA400_FIFO_CONF0_CHANGE UINT8_C(0x01)
/* It is inserted when ACC_CONFIG0.filt1_bw
* is changed during the FIFO read
*/
#define BMA400_ACCEL_CONF0_CHANGE UINT8_C(0x02)
/* It is inserted when ACC_CONFIG1.acc_range
* acc_odr or osr is changed during the FIFO read
*/
#define BMA400_ACCEL_CONF1_CHANGE UINT8_C(0x04)
/* Accel width setting either 12/8 bit mode */
#define BMA400_12_BIT_FIFO_DATA UINT8_C(0x01)
#define BMA400_8_BIT_FIFO_DATA UINT8_C(0x00)
/* BMA400 FIFO header configurations */
#define BMA400_FIFO_SENSOR_TIME UINT8_C(0xA0)
#define BMA400_FIFO_EMPTY_FRAME UINT8_C(0x80)
#define BMA400_FIFO_CONTROL_FRAME UINT8_C(0x48)
#define BMA400_FIFO_XYZ_ENABLE UINT8_C(0x8E)
#define BMA400_FIFO_X_ENABLE UINT8_C(0x82)
#define BMA400_FIFO_Y_ENABLE UINT8_C(0x84)
#define BMA400_FIFO_Z_ENABLE UINT8_C(0x88)
#define BMA400_FIFO_XY_ENABLE UINT8_C(0x86)
#define BMA400_FIFO_YZ_ENABLE UINT8_C(0x8C)
#define BMA400_FIFO_XZ_ENABLE UINT8_C(0x8A)
/* BMA400 bit mask definitions */
#define BMA400_POWER_MODE_STATUS_MSK UINT8_C(0x06)
#define BMA400_POWER_MODE_STATUS_POS UINT8_C(1)
#define BMA400_POWER_MODE_MSK UINT8_C(0x03)
#define BMA400_ACCEL_ODR_MSK UINT8_C(0x0F)
#define BMA400_ACCEL_RANGE_MSK UINT8_C(0xC0)
#define BMA400_ACCEL_RANGE_POS UINT8_C(6)
#define BMA400_DATA_FILTER_MSK UINT8_C(0x0C)
#define BMA400_DATA_FILTER_POS UINT8_C(2)
#define BMA400_OSR_MSK UINT8_C(0x30)
#define BMA400_OSR_POS UINT8_C(4)
#define BMA400_OSR_LP_MSK UINT8_C(0x60)
#define BMA400_OSR_LP_POS UINT8_C(5)
#define BMA400_FILT_1_BW_MSK UINT8_C(0x80)
#define BMA400_FILT_1_BW_POS UINT8_C(7)
#define BMA400_WAKEUP_TIMEOUT_MSK UINT8_C(0x04)
#define BMA400_WAKEUP_TIMEOUT_POS UINT8_C(2)
#define BMA400_WAKEUP_THRES_LSB_MSK UINT16_C(0x000F)
#define BMA400_WAKEUP_THRES_MSB_MSK UINT16_C(0x0FF0)
#define BMA400_WAKEUP_THRES_MSB_POS UINT8_C(4)
#define BMA400_WAKEUP_TIMEOUT_THRES_MSK UINT8_C(0xF0)
#define BMA400_WAKEUP_TIMEOUT_THRES_POS UINT8_C(4)
#define BMA400_WAKEUP_INTERRUPT_MSK UINT8_C(0x02)
#define BMA400_WAKEUP_INTERRUPT_POS UINT8_C(1)
#define BMA400_AUTO_LOW_POW_MSK UINT8_C(0x0F)
#define BMA400_AUTO_LP_THRES_MSK UINT16_C(0x0FF0)
#define BMA400_AUTO_LP_THRES_POS UINT8_C(4)
#define BMA400_AUTO_LP_THRES_LSB_MSK UINT16_C(0x000F)
#define BMA400_WKUP_REF_UPDATE_MSK UINT8_C(0x03)
#define BMA400_AUTO_LP_TIMEOUT_LSB_MSK UINT8_C(0xF0)
#define BMA400_AUTO_LP_TIMEOUT_LSB_POS UINT8_C(4)
#define BMA400_SAMPLE_COUNT_MSK UINT8_C(0x1C)
#define BMA400_SAMPLE_COUNT_POS UINT8_C(2)
#define BMA400_WAKEUP_EN_AXES_MSK UINT8_C(0xE0)
#define BMA400_WAKEUP_EN_AXES_POS UINT8_C(5)
#define BMA400_TAP_AXES_EN_MSK UINT8_C(0x18)
#define BMA400_TAP_AXES_EN_POS UINT8_C(3)
#define BMA400_TAP_QUIET_DT_MSK UINT8_C(0x30)
#define BMA400_TAP_QUIET_DT_POS UINT8_C(4)
#define BMA400_TAP_QUIET_MSK UINT8_C(0x0C)
#define BMA400_TAP_QUIET_POS UINT8_C(2)
#define BMA400_TAP_TICS_TH_MSK UINT8_C(0x03)
#define BMA400_TAP_SENSITIVITY_MSK UINT8_C(0X07)
#define BMA400_ACT_CH_AXES_EN_MSK UINT8_C(0xE0)
#define BMA400_ACT_CH_AXES_EN_POS UINT8_C(5)
#define BMA400_ACT_CH_DATA_SRC_MSK UINT8_C(0x10)
#define BMA400_ACT_CH_DATA_SRC_POS UINT8_C(4)
#define BMA400_ACT_CH_NPTS_MSK UINT8_C(0x0F)
#define BMA400_INT_AXES_EN_MSK UINT8_C(0xE0)
#define BMA400_INT_AXES_EN_POS UINT8_C(5)
#define BMA400_INT_DATA_SRC_MSK UINT8_C(0x10)
#define BMA400_INT_DATA_SRC_POS UINT8_C(4)
#define BMA400_INT_REFU_MSK UINT8_C(0x0C)
#define BMA400_INT_REFU_POS UINT8_C(2)
#define BMA400_INT_HYST_MSK UINT8_C(0x03)
#define BMA400_GEN_INT_COMB_MSK UINT8_C(0x01)
#define BMA400_GEN_INT_CRITERION_MSK UINT8_C(0x02)
#define BMA400_GEN_INT_CRITERION_POS UINT8_C(0x01)
#define BMA400_INT_PIN1_CONF_MSK UINT8_C(0x06)
#define BMA400_INT_PIN1_CONF_POS UINT8_C(1)
#define BMA400_INT_PIN2_CONF_MSK UINT8_C(0x60)
#define BMA400_INT_PIN2_CONF_POS UINT8_C(5)
#define BMA400_INT_STATUS_MSK UINT8_C(0xE0)
#define BMA400_INT_STATUS_POS UINT8_C(5)
#define BMA400_EN_DRDY_MSK UINT8_C(0x80)
#define BMA400_EN_DRDY_POS UINT8_C(7)
#define BMA400_EN_FIFO_WM_MSK UINT8_C(0x40)
#define BMA400_EN_FIFO_WM_POS UINT8_C(6)
#define BMA400_EN_FIFO_FULL_MSK UINT8_C(0x20)
#define BMA400_EN_FIFO_FULL_POS UINT8_C(5)
#define BMA400_EN_INT_OVERRUN_MSK UINT8_C(0x10)
#define BMA400_EN_INT_OVERRUN_POS UINT8_C(4)
#define BMA400_EN_GEN2_MSK UINT8_C(0x08)
#define BMA400_EN_GEN2_POS UINT8_C(3)
#define BMA400_EN_GEN1_MSK UINT8_C(0x04)
#define BMA400_EN_GEN1_POS UINT8_C(2)
#define BMA400_EN_ORIENT_CH_MSK UINT8_C(0x02)
#define BMA400_EN_ORIENT_CH_POS UINT8_C(1)
#define BMA400_EN_LATCH_MSK UINT8_C(0x80)
#define BMA400_EN_LATCH_POS UINT8_C(7)
#define BMA400_EN_ACTCH_MSK UINT8_C(0x10)
#define BMA400_EN_ACTCH_POS UINT8_C(4)
#define BMA400_EN_D_TAP_MSK UINT8_C(0x08)
#define BMA400_EN_D_TAP_POS UINT8_C(3)
#define BMA400_EN_S_TAP_MSK UINT8_C(0x04)
#define BMA400_EN_S_TAP_POS UINT8_C(2)
#define BMA400_EN_STEP_INT_MSK UINT8_C(0x01)
#define BMA400_STEP_MAP_INT2_MSK UINT8_C(0x10)
#define BMA400_STEP_MAP_INT2_POS UINT8_C(4)
#define BMA400_EN_WAKEUP_INT_MSK UINT8_C(0x01)
#define BMA400_TAP_MAP_INT1_MSK UINT8_C(0x04)
#define BMA400_TAP_MAP_INT1_POS UINT8_C(2)
#define BMA400_TAP_MAP_INT2_MSK UINT8_C(0x40)
#define BMA400_TAP_MAP_INT2_POS UINT8_C(6)
#define BMA400_ACTCH_MAP_INT1_MSK UINT8_C(0x08)
#define BMA400_ACTCH_MAP_INT1_POS UINT8_C(3)
#define BMA400_ACTCH_MAP_INT2_MSK UINT8_C(0x80)
#define BMA400_ACTCH_MAP_INT2_POS UINT8_C(7)
#define BMA400_FIFO_BYTES_CNT_MSK UINT8_C(0x07)
#define BMA400_FIFO_TIME_EN_MSK UINT8_C(0x04)
#define BMA400_FIFO_TIME_EN_POS UINT8_C(2)
#define BMA400_FIFO_AXES_EN_MSK UINT8_C(0xE0)
#define BMA400_FIFO_AXES_EN_POS UINT8_C(5)
#define BMA400_FIFO_8_BIT_EN_MSK UINT8_C(0x10)
#define BMA400_FIFO_8_BIT_EN_POS UINT8_C(4)
/* Macro to SET and GET BITS of a register */
#define BMA400_SET_BITS(reg_data, bitname, data) \
((reg_data & ~(bitname##_MSK)) | \
((data << bitname##_POS) & bitname##_MSK))
#define BMA400_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
(bitname##_POS))
#define BMA400_SET_BITS_POS_0(reg_data, bitname, data) \
((reg_data & ~(bitname##_MSK)) | \
(data & bitname##_MSK))
#define BMA400_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
#define BMA400_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname##_MSK))
#define BMA400_GET_LSB(var) (uint8_t)(var & BMA400_SET_LOW_BYTE)
#define BMA400_GET_MSB(var) (uint8_t)((var & BMA400_SET_HIGH_BYTE) >> 8)
/* Macros used for Self test */
/*
* Derivation of values obtained by :
* Signal_Diff = ( (LSB/g value based on Accel Range) * (Minimum difference signal value) ) / 1000
*/
/* Self-test: Resulting minimum difference signal for BMA400 with Range 4G */
#define BMA400_ST_ACC_X_AXIS_SIGNAL_DIFF UINT16_C(768)
#define BMA400_ST_ACC_Y_AXIS_SIGNAL_DIFF UINT16_C(614)
#define BMA400_ST_ACC_Z_AXIS_SIGNAL_DIFF UINT16_C(128)
/*
* Interface selection enums
*/
enum bma400_intf {
/* SPI interface */
BMA400_SPI_INTF,
/* I2C interface */
BMA400_I2C_INTF
};
/********************************************************* */
/*! Function Pointers */
/********************************************************* */
/*!
* @brief Bus communication function pointer which should be mapped to
* the platform specific read functions of the user
*
* @param[in] reg_addr : 8bit register address of the sensor
* @param[out] reg_data : Data from the specified address
* @param[in] length : Length of the reg_data array
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
* for interface related callbacks
* @retval 0 for Success
* @retval Non-zero for Failure
*/
typedef BMA400_INTF_RET_TYPE (*bma400_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
void *intf_ptr);
/*!
* @brief Bus communication function pointer which should be mapped to
* the platform specific write functions of the user
*
* @param[in] reg_addr : 8bit register address of the sensor
* @param[out] reg_data : Data to the specified address
* @param[in] length : Length of the reg_data array
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
* for interface related callbacks
* @retval 0 for Success
* @retval Non-zero for Failure
*
*/
typedef BMA400_INTF_RET_TYPE (*bma400_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
void *intf_ptr);
/*!
* @brief Delay function pointer which should be mapped to
* delay function of the user
*
* @param period - The time period in microseconds
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
* for interface related callbacks
*/
typedef void (*bma400_delay_us_fptr_t)(uint32_t period, void *intf_ptr);
/*
* Sensor selection enums
*/
enum bma400_sensor {
BMA400_ACCEL,
BMA400_TAP_INT,
BMA400_ACTIVITY_CHANGE_INT,
BMA400_GEN1_INT,
BMA400_GEN2_INT,
BMA400_ORIENT_CHANGE_INT,
BMA400_STEP_COUNTER_INT
};
/*
* Interrupt channel selection enums
*/
enum bma400_int_chan {
BMA400_UNMAP_INT_PIN,
BMA400_INT_CHANNEL_1,
BMA400_INT_CHANNEL_2,
BMA400_MAP_BOTH_INT_PINS
};
/*
* Interrupt pin hardware configurations
*/
struct bma400_int_pin_conf
{
/* Interrupt channel selection enums */
enum bma400_int_chan int_chan;
/* Interrupt pin configuration
* Assignable Macros :
* - BMA400_INT_PUSH_PULL_ACTIVE_0
* - BMA400_INT_PUSH_PULL_ACTIVE_1
* - BMA400_INT_OPEN_DRIVE_ACTIVE_0
* - BMA400_INT_OPEN_DRIVE_ACTIVE_1
*/
uint8_t pin_conf;
};
/*
* Accel basic configuration
*/
struct bma400_acc_conf
{
/* Output data rate
* Assignable macros :
* - BMA400_ODR_12_5HZ - BMA400_ODR_25HZ - BMA400_ODR_50HZ
* - BMA400_ODR_100HZ - BMA400_ODR_200HZ - BMA400_ODR_400HZ
* - BMA400_ODR_800HZ
*/
uint8_t odr;
/* Range of sensor
* Assignable macros :
* - BMA400_2G_RANGE - BMA400_8G_RANGE
* - BMA400_4G_RANGE - BMA400_16G_RANGE
*/
uint8_t range;
/* Filter setting for data source
* Assignable Macros :
* - BMA400_DATA_SRC_ACCEL_FILT_1
* - BMA400_DATA_SRC_ACCEL_FILT_2
* - BMA400_DATA_SRC_ACCEL_FILT_LP
*/
uint8_t data_src;
/* Assignable Macros for osr and osr_lp:
* - BMA400_ACCEL_OSR_SETTING_0 - BMA400_ACCEL_OSR_SETTING_2
* - BMA400_ACCEL_OSR_SETTING_1 - BMA400_ACCEL_OSR_SETTING_3
*/
/* OSR setting for data source */
uint8_t osr;
/* OSR setting for low power mode */
uint8_t osr_lp;
/* Filter 1 Bandwidth
* Assignable macros :
* - BMA400_ACCEL_FILT1_BW_0
* - BMA400_ACCEL_FILT1_BW_1
*/
uint8_t filt1_bw;
/* Interrupt channel to be mapped */
enum bma400_int_chan int_chan;
};
/*
* Tap interrupt configurations
*/
struct bma400_tap_conf
{
/* Axes enabled to sense tap setting
* Assignable macros :
* - BMA400_X_AXIS_EN_TAP
* - BMA400_Y_AXIS_EN_TAP
* - BMA400_Z_AXIS_EN_TAP
*/
uint8_t axes_sel;
/* TAP sensitivity settings modifies the threshold
* for minimum TAP amplitude
* Assignable macros :
* - BMA400_TAP_SENSITIVITY_0 - BMA400_TAP_SENSITIVITY_4
* - BMA400_TAP_SENSITIVITY_1 - BMA400_TAP_SENSITIVITY_5
* - BMA400_TAP_SENSITIVITY_2 - BMA400_TAP_SENSITIVITY_6
* - BMA400_TAP_SENSITIVITY_3 - BMA400_TAP_SENSITIVITY_7
*
* @note :
* - BMA400_TAP_SENSITIVITY_0 correspond to highest sensitivity
* - BMA400_TAP_SENSITIVITY_7 correspond to lowest sensitivity
*/
uint8_t sensitivity;
/* TAP tics_th setting is the maximum time between upper and lower
* peak of a tap, in data samples, This time depends on the
* mechanics of the device tapped onto default = 12 samples
* Assignable macros :
* - BMA400_TICS_TH_6_DATA_SAMPLES
* - BMA400_TICS_TH_9_DATA_SAMPLES
* - BMA400_TICS_TH_12_DATA_SAMPLES
* - BMA400_TICS_TH_18_DATA_SAMPLES
*/
uint8_t tics_th;
/* BMA400 TAP - quiet settings to configure minimum quiet time
* before and after double tap, in the data samples.
* This time also defines the longest time interval between two
* taps so that they are considered as double tap
* Assignable macros :
* - BMA400_QUIET_60_DATA_SAMPLES
* - BMA400_QUIET_80_DATA_SAMPLES
* - BMA400_QUIET_100_DATA_SAMPLES
* - BMA400_QUIET_120_DATA_SAMPLES
*/
uint8_t quiet;
/* BMA400 TAP - quiet_dt settings
* quiet_dt refers to Minimum time between the two taps of a
* double tap, in data samples
* Assignable macros :
* - BMA400_QUIET_DT_4_DATA_SAMPLES
* - BMA400_QUIET_DT_8_DATA_SAMPLES
* - BMA400_QUIET_DT_12_DATA_SAMPLES
* - BMA400_QUIET_DT_16_DATA_SAMPLES
*/
uint8_t quiet_dt;
/* Interrupt channel to be mapped */
enum bma400_int_chan int_chan;
};
/*
* Activity change interrupt configurations
*/
struct bma400_act_ch_conf
{
/* Threshold for activity change (8 mg/LSB) */
uint8_t act_ch_thres;
/* Axes enabled to sense activity change
* Assignable macros :
* - BMA400_X_AXIS_EN
* - BMA400_Y_AXIS_EN
* - BMA400_Z_AXIS_EN
* - BMA400_XYZ_AXIS_EN
*/
uint8_t axes_sel;
/* Data Source for activity change
* Assignable macros :
* - BMA400_DATA_SRC_ACC_FILT1
* - BMA400_DATA_SRC_ACC_FILT2
*/
uint8_t data_source;
/* Sample count for sensing act_ch
* Assignable macros :
* - BMA400_ACT_CH_SAMPLE_CNT_32
* - BMA400_ACT_CH_SAMPLE_CNT_64
* - BMA400_ACT_CH_SAMPLE_CNT_128
* - BMA400_ACT_CH_SAMPLE_CNT_256
* - BMA400_ACT_CH_SAMPLE_CNT_512
*/
uint8_t act_ch_ntps;
/* Interrupt channel to be mapped */
enum bma400_int_chan int_chan;
};
/*
* Generic interrupt configurations
*/
struct bma400_gen_int_conf
{
/* Threshold for the gen1 interrupt (1 LSB = 8mg)
* if gen_int_thres = 10, then threshold = 10 * 8 = 80mg
*/
uint8_t gen_int_thres;
/* Duration for which the condition has to persist until
* interrupt can be triggered
* duration is measured in data samples of selected data source
*/
uint16_t gen_int_dur;
/* Enable axes to sense for the gen1 interrupt
* Assignable macros :
* - BMA400_X_AXIS_EN
* - BMA400_Y_AXIS_EN
* - BMA400_Z_AXIS_EN
* - BMA400_XYZ_AXIS_EN
*/
uint8_t axes_sel;
/* Data source to sense for the gen1 interrupt
* Assignable macros :
* - BMA400_DATA_SRC_ACC_FILT1
* - BMA400_DATA_SRC_ACC_FILT2
*/
uint8_t data_src;
/* Activity/Inactivity selection macros
* Assignable macros :
* - BMA400_ACTIVITY_INT
* - BMA400_INACTIVITY_INT
*/
uint8_t criterion_sel;
/* Axes selection logic macros
* Assignable macros :
* - BMA400_ALL_AXES_INT
* - BMA400_ANY_AXES_INT
*/
uint8_t evaluate_axes;
/* Reference x,y,z values updates
* Assignable macros :
* - BMA400_MANUAL_UPDATE
* - BMA400_ONE_TIME_UPDATE
* - BMA400_EVERY_TIME_UPDATE
* - BMA400_LP_EVERY_TIME_UPDATE
*/
uint8_t ref_update;
/* Hysteresis value
* Higher the hysteresis value, Lower the value of noise
* Assignable macros :
* - BMA400_HYST_0_MG
* - BMA400_HYST_24_MG
* - BMA400_HYST_48_MG
* - BMA400_HYST_96_MG
*/
uint8_t hysteresis;
/* Threshold value for x axes */
uint16_t int_thres_ref_x;
/* Threshold value for y axes */
uint16_t int_thres_ref_y;
/* Threshold value for z axes */
uint16_t int_thres_ref_z;
/* Interrupt channel to be mapped */
enum bma400_int_chan int_chan;
};
/*
* Orient interrupt configurations