-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathbmi088_anymotiona.c
1618 lines (1370 loc) · 53.8 KB
/
bmi088_anymotiona.c
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 bmi088_anymotiona.c
* @date 2024-07-29
* @version v1.9.0
*
*/
/*! \file bmi088_anymotiona.c
* \brief Sensor Driver for BMI088_ANYMOTION family of sensors */
/****************************************************************************/
/**\name Header files
****************************************************************************/
#include <stdio.h>
#include "bmi088_anymotion.h"
/****************************************************************************/
/** \name Macros
****************************************************************************/
/**\name Value of LSB_PER_G = (power(2, BMI088_ANYMOTION_16_BIT_RESOLUTION) / (2 * range)) */
#define LSB_PER_G UINT32_C(1365) /* for the 16-bit resolution and 24g range */
/****************************************************************************/
/**\name Local structures
****************************************************************************/
/*!
* @brief Accel self-test diff xyz data structure
*/
struct bmi088_anymotion_selftest_delta_limit
{
/*! Accel X data */
int16_t x;
/*! Accel Y data */
int16_t y;
/*! Accel Z data */
int16_t z;
};
/**\name Feature configuration file */
const uint8_t bmi088_anymotion_config_file[] = {
0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00,
0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x44, 0x00, 0x80, 0x2e, 0xe4, 0x01, 0xb0, 0xf0,
0x10, 0x30, 0x21, 0x2e, 0x16, 0xf0, 0x80, 0x2e, 0x9f, 0x00, 0x19, 0x50, 0x41, 0x30, 0x01, 0x42, 0x3c, 0x82, 0x01,
0x2e, 0x42, 0x00, 0x42, 0x40, 0x42, 0x42, 0x02, 0x30, 0x17, 0x56, 0x25, 0x2e, 0x42, 0x00, 0x03, 0x0a, 0x49, 0x82,
0xc0, 0x2e, 0x40, 0x42, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4,
0x5b, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e,
0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0xfd, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x70, 0x50, 0xd0, 0x7f, 0xf5, 0x7f, 0xe4, 0x7f, 0x34, 0x30, 0x01, 0x2e, 0x01, 0xf0, 0x0e, 0xbc,
0x8e, 0xba, 0x92, 0x7f, 0xc1, 0x7f, 0xbb, 0x7f, 0xa3, 0x7f, 0xa5, 0x04, 0x05, 0x52, 0x07, 0x50, 0x98, 0x2e, 0x94,
0x00, 0x11, 0x30, 0x23, 0x2e, 0x29, 0x00, 0x01, 0x31, 0x23, 0x2e, 0xb8, 0xf0, 0xe4, 0x6f, 0xd0, 0x6f, 0xf5, 0x6f,
0xc1, 0x6f, 0x92, 0x6f, 0xa3, 0x6f, 0xbb, 0x6f, 0x90, 0x5f, 0xc8, 0x2e, 0x98, 0x2e, 0xa8, 0x00, 0x20, 0x26, 0x98,
0x2e, 0x90, 0x00, 0x01, 0x2e, 0x40, 0xf0, 0x21, 0x2e, 0x41, 0x00, 0x10, 0x30, 0x21, 0x2e, 0x59, 0xf0, 0x98, 0x2e,
0xa3, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x01, 0x2e, 0x29, 0x00, 0x00, 0xb2, 0x0b, 0x2f, 0x00, 0x30, 0x21,
0x2e, 0x29, 0x00, 0x05, 0x50, 0x98, 0x2e, 0x9e, 0x01, 0x20, 0x30, 0x21, 0x2e, 0x5f, 0xf0, 0x05, 0x50, 0x98, 0x2e,
0x11, 0x01, 0x98, 0x2e, 0xa3, 0x00, 0x01, 0x2e, 0x42, 0x00, 0x01, 0x30, 0x21, 0x2e, 0x5e, 0xf0, 0x23, 0x2e, 0x42,
0x00, 0xe3, 0x2d, 0x00, 0x31, 0xc0, 0x2e, 0x21, 0x2e, 0xba, 0xf0, 0x43, 0x86, 0x25, 0x40, 0x04, 0x40, 0xd8, 0xbe,
0x2c, 0x0b, 0x22, 0x11, 0x54, 0x42, 0x03, 0x80, 0x4b, 0x0e, 0xf6, 0x2f, 0xb8, 0x2e, 0x1a, 0x24, 0x30, 0x00, 0x80,
0x2e, 0x65, 0x00, 0x01, 0x2e, 0x55, 0xf0, 0xc0, 0x2e, 0x21, 0x2e, 0x55, 0xf0, 0x15, 0x50, 0x41, 0x30, 0x02, 0x40,
0x51, 0x0a, 0x01, 0x42, 0x18, 0x82, 0x09, 0x50, 0x60, 0x42, 0x70, 0x3c, 0x0b, 0x54, 0x42, 0x42, 0x69, 0x82, 0x82,
0x32, 0x43, 0x40, 0x18, 0x08, 0x02, 0x0a, 0x40, 0x42, 0x42, 0x80, 0x02, 0x3f, 0x01, 0x40, 0x10, 0x50, 0x4a, 0x08,
0xfb, 0x7f, 0x11, 0x42, 0x0b, 0x31, 0x0b, 0x42, 0x3e, 0x80, 0xf1, 0x30, 0x01, 0x42, 0x00, 0x2e, 0x01, 0x2e, 0x40,
0xf0, 0x1e, 0xb2, 0x01, 0x2f, 0x1a, 0x90, 0x20, 0x2f, 0x03, 0x30, 0x0f, 0x50, 0x0d, 0x54, 0xd4, 0x33, 0x06, 0x30,
0x13, 0x52, 0xf5, 0x32, 0x1d, 0x1a, 0xe3, 0x22, 0x18, 0x1a, 0x11, 0x58, 0xe3, 0x22, 0x04, 0x30, 0xd5, 0x40, 0xb5,
0x0d, 0xe1, 0xbe, 0x6f, 0xbb, 0x80, 0x91, 0xa9, 0x0d, 0x01, 0x89, 0xb5, 0x23, 0x10, 0xa1, 0xf7, 0x2f, 0xda, 0x0e,
0xd4, 0x33, 0xeb, 0x2f, 0x01, 0x2e, 0x2f, 0x00, 0x70, 0x1a, 0x00, 0x30, 0x21, 0x30, 0x02, 0x2c, 0x08, 0x22, 0x30,
0x30, 0x00, 0xb2, 0x06, 0x2f, 0x21, 0x2e, 0x59, 0xf0, 0x98, 0x2e, 0xa3, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e,
0xfb, 0x6f, 0xf0, 0x5f, 0xb8, 0x2e, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0xaa,
0x00, 0x05, 0xe0, 0x2a, 0x00, 0x89, 0xf0, 0xaf, 0x00, 0xff, 0x00, 0xff, 0xb7, 0x00, 0x02, 0x00, 0xb0, 0x05, 0x80,
0xb1, 0xf0, 0x80, 0x00, 0x59, 0xf0, 0x40, 0x1c, 0x88, 0x00, 0x3e, 0x00, 0x88, 0x00, 0x09, 0x2e, 0x01, 0x01, 0x0b,
0x2e, 0x00, 0x01, 0x42, 0xbd, 0xaf, 0xb9, 0xc1, 0xbc, 0x54, 0xbf, 0x1f, 0xb9, 0xef, 0xbb, 0xcf, 0xb8, 0x9a, 0x0b,
0x10, 0x50, 0xc0, 0xb3, 0xb1, 0x0b, 0x77, 0x2f, 0x80, 0xb3, 0x75, 0x2f, 0x0f, 0x2e, 0x43, 0x00, 0x01, 0x8c, 0xc0,
0x91, 0x13, 0x2f, 0xc1, 0x83, 0x23, 0x2e, 0x43, 0x00, 0x00, 0x40, 0x21, 0x2e, 0x3d, 0x00, 0x1f, 0x50, 0x91, 0x41,
0x11, 0x42, 0x01, 0x30, 0x82, 0x41, 0x02, 0x42, 0xf0, 0x5f, 0x23, 0x2e, 0x2d, 0x00, 0x23, 0x2e, 0x2e, 0x00, 0x23,
0x2e, 0x40, 0x00, 0xb8, 0x2e, 0xd5, 0xbe, 0xc3, 0xbf, 0x55, 0xba, 0xc0, 0xb2, 0xf3, 0xba, 0x07, 0x30, 0x03, 0x30,
0x09, 0x2f, 0xf0, 0x7f, 0x00, 0x2e, 0x00, 0x40, 0x07, 0x2e, 0x3d, 0x00, 0x03, 0x04, 0x00, 0xa8, 0xf8, 0x04, 0xc3,
0x22, 0xf0, 0x6f, 0x80, 0xb2, 0x07, 0x2f, 0x82, 0x41, 0x0f, 0x2e, 0x3e, 0x00, 0x97, 0x04, 0x07, 0x30, 0x80, 0xa8,
0xfa, 0x05, 0xd7, 0x23, 0x40, 0xb2, 0x01, 0x30, 0x02, 0x30, 0x0a, 0x2f, 0x02, 0x84, 0xf7, 0x7f, 0x00, 0x2e, 0x82,
0x40, 0x0f, 0x2e, 0x3f, 0x00, 0x97, 0x04, 0x80, 0xa8, 0xca, 0x05, 0x97, 0x22, 0xf7, 0x6f, 0x5c, 0x0f, 0x0f, 0x2f,
0x7c, 0x0f, 0x0d, 0x2f, 0x54, 0x0f, 0x0b, 0x2f, 0x05, 0x2e, 0x2e, 0x00, 0x81, 0x84, 0x23, 0x2e, 0x2d, 0x00, 0x55,
0x0e, 0x25, 0x2e, 0x2e, 0x00, 0x0e, 0x2f, 0x23, 0x2e, 0x40, 0x00, 0x0c, 0x2d, 0x07, 0x2e, 0x2d, 0x00, 0x12, 0x30,
0xda, 0x28, 0x23, 0x2e, 0x2e, 0x00, 0x5d, 0x0e, 0x27, 0x2e, 0x2d, 0x00, 0x01, 0x2f, 0x25, 0x2e, 0x40, 0x00, 0x03,
0x2e, 0x40, 0x00, 0x40, 0xb2, 0x12, 0x2f, 0x00, 0x40, 0x21, 0x2e, 0x3d, 0x00, 0x1f, 0x50, 0x91, 0x41, 0x11, 0x42,
0x21, 0x30, 0x82, 0x41, 0x02, 0x42, 0x00, 0x2e, 0x01, 0x2e, 0x42, 0x00, 0x01, 0x0a, 0x21, 0x2e, 0x42, 0x00, 0x03,
0x2d, 0x00, 0x30, 0x21, 0x2e, 0x43, 0x00, 0xf0, 0x5f, 0xb8, 0x2e, 0x60, 0x50, 0x03, 0x2e, 0x0e, 0x01, 0xe0, 0x7f,
0xf1, 0x7f, 0xdb, 0x7f, 0x30, 0x30, 0x21, 0x54, 0x0a, 0x1a, 0x28, 0x2f, 0x1a, 0x25, 0x7a, 0x82, 0x00, 0x30, 0x43,
0x30, 0x32, 0x30, 0x05, 0x30, 0x04, 0x30, 0xf6, 0x6f, 0xf2, 0x09, 0xfc, 0x13, 0xc2, 0xab, 0xb3, 0x09, 0xef, 0x23,
0x80, 0xb3, 0xe6, 0x6f, 0xb7, 0x01, 0x00, 0x2e, 0x8b, 0x41, 0x4b, 0x42, 0x03, 0x2f, 0x46, 0x40, 0x86, 0x17, 0x81,
0x8d, 0x46, 0x42, 0x41, 0x8b, 0x23, 0xbd, 0xb3, 0xbd, 0x03, 0x89, 0x41, 0x82, 0x07, 0x0c, 0x43, 0xa3, 0xe6, 0x2f,
0xe1, 0x6f, 0xa2, 0x6f, 0x52, 0x42, 0x00, 0x2e, 0xb2, 0x6f, 0x52, 0x42, 0x00, 0x2e, 0xc2, 0x6f, 0x42, 0x42, 0x03,
0xb2, 0x06, 0x2f, 0x01, 0x2e, 0x59, 0xf0, 0x01, 0x32, 0x01, 0x0a, 0x21, 0x2e, 0x59, 0xf0, 0x06, 0x2d, 0x01, 0x2e,
0x59, 0xf0, 0xf1, 0x3d, 0x01, 0x08, 0x21, 0x2e, 0x59, 0xf0, 0xdb, 0x6f, 0xa0, 0x5f, 0xb8, 0x2e, 0x00, 0x2e, 0x10,
0x24, 0xfa, 0x01, 0x11, 0x24, 0x00, 0x0c, 0x12, 0x24, 0x80, 0x2e, 0x13, 0x24, 0x18, 0x00, 0x12, 0x42, 0x13, 0x42,
0x41, 0x1a, 0xfb, 0x2f, 0x10, 0x24, 0x50, 0x39, 0x11, 0x24, 0x21, 0x2e, 0x21, 0x2e, 0x10, 0x00, 0x23, 0x2e, 0x11,
0x00, 0x80, 0x2e, 0x10, 0x00
};
/****************************************************************************/
/*! Static Function Declarations
****************************************************************************/
/*!
* @brief This API is used to validate the device structure pointer for
* null conditions.
*
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t null_ptr_check(const struct bmi08_dev *dev);
/*!
* @brief This API configures the pins which fire the interrupt signal when any interrupt occurs.
*
* @param[in] int_config : Structure instance of bmi08_accel_int_channel_cfg.
* @param[in] int_type : Enumerator instance of bmi088_anymotion_accel_int_types.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_int_pin_config(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev);
/*!
* @brief This API sets the anymotion interrupt for accel sensor
*
* @param[in] int_config : Structure instance of bmi08_accel_int_channel_cfg.
* @param[in] int_type : Enumerator instance of bmi088_anymotion_accel_int_types.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_accel_anymotion_int(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev);
/*!
* @brief This API sets error interrupt for accel sensor
*
* @param[in] int_config : Structure instance of bmi08_accel_int_channel_cfg.
* @param[in] int_type : Enumerator instance of bmi088_anymotion_accel_int_types.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_accel_err_int(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev);
/*!
* @brief This internal API gets the re-mapped x, y and z axes from the sensor.
*
* @param[out] remap : Structure that stores local copy of re-mapped axes.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_remap_axes(struct bmi08_axes_remap *remap, struct bmi08_dev *dev);
/*!
* @brief This internal API sets the re-mapped x, y and z axes in the sensor.
*
* @param[in] remap : Structure that stores local copy of re-mapped axes.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_remap_axes(const struct bmi08_axes_remap *remap, struct bmi08_dev *dev);
/*!
* @brief This internal API gets the re-mapped accelerometer.
*
* @param[out] data : Structure instance of bmi08_sensor_data.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return None
*
* @retval None
*/
static void get_remapped_data(struct bmi08_sensor_data *data, const struct bmi08_dev *dev);
/*!
* @brief This internal API is to store re-mapped axis and sign values
* in device structure
*
* @param[in] remap_axis : Value of re-mapped axis
* @param[out] axis : Re-mapped axis value stored in device structure
* @param[out] sign : Re-mapped axis sign stored in device structure
*
* @return None
*
* @retval None
*/
static void assign_remap_axis(uint8_t remap_axis, uint8_t *axis, uint8_t *sign);
/*!
* @brief This internal API is to receive re-mapped axis and sign values
* in device structure
*
* @param[in] remap_axis : Re-mapped axis value
* @param[in] remap_sign : Re-mapped axis sign value
* @param[out] axis : Re-mapped axis stored in local structure
*
* @return None
*
* @retval None
*/
static void receive_remap_axis(uint8_t remap_axis, uint8_t remap_sign, uint8_t *axis);
/*!
* @brief This API performs the pre-requisites needed to perform the self-test
*
* @param[in] dev : structure instance of bmi08_dev
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t enable_self_test(struct bmi08_dev *dev);
/*!
* @brief This API reads the accel data with the positive excitation
*
* @param[out] accel_pos : Structure pointer to store accel data
* for positive excitation
* @param[in] dev : structure instance of bmi08_dev
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t positive_excited_accel(struct bmi08_sensor_data *accel_pos, struct bmi08_dev *dev);
/*!
* @brief This API reads the accel data with the negative excitation
*
* @param[out] accel_neg : Structure pointer to store accel data
* for negative excitation
* @param[in] dev : structure instance of bmi08_dev
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t negative_excited_accel(struct bmi08_sensor_data *accel_neg, struct bmi08_dev *dev);
/*!
* @brief This API validates the self-test results
*
* @param[in] accel_pos : Structure pointer to store accel data
* for positive excitation
* @param[in] accel_neg : Structure pointer to store accel data
* for negative excitation
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t validate_accel_self_test(const struct bmi08_sensor_data *accel_pos,
const struct bmi08_sensor_data *accel_neg);
/*!
* @brief This API converts lsb value of axes to mg for self-test
*
* @param[in] accel_data_diff : Pointer variable used to pass accel difference
* values in g
*
* @param[out] accel_data_diff_mg : Pointer variable used to store accel
* difference values in mg
*
* @return None
*/
static void convert_lsb_g(const struct bmi088_anymotion_selftest_delta_limit *accel_data_diff,
struct bmi088_anymotion_selftest_delta_limit *accel_data_diff_mg);
/*!
* @brief This API sets the FIFO watermark interrupt for accel sensor
*
* @param[in] int_config : Structure instance of bmi08_accel_int_channel_cfg.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*
*/
static int8_t set_fifo_wm_int(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev);
/*!
* @brief This API sets the data ready interrupt for accel sensor
*
* @param[in] int_config : Structure instance of bmi08_accel_int_channel_cfg.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*
*/
static int8_t set_accel_data_ready_int(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev);
/*!
* @brief This API reads the data from the given register address of accel sensor.
*
* @param[in] reg_addr : Register address from where the data to be read
* @param[out] reg_data : Pointer to data buffer to store the read data.
* @param[in] len : No. of bytes of data to be read.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*
*/
static int8_t get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmi08_dev *dev);
/*!
* @brief This API sets the FIFO full interrupt for accel sensor
*
* @param[in] int_config : Structure instance of bmi08_accel_int_channel_cfg.
* @param[in] dev : Structure instance of bmi08_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*
*/
static int8_t set_fifo_full_int(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev);
/****************************************************************************/
/**\name Function definitions
****************************************************************************/
/*!
* @brief This API is the entry point for accel sensor.
* It performs the selection of I2C/SPI read mechanism according to the
* selected interface and reads the chip-id of accel sensor.
*/
int8_t bmi088_anymotion_init(struct bmi08_dev *dev)
{
int8_t rslt;
rslt = bmi08a_init(dev);
if (rslt == BMI08_OK)
{
/* Structure to define the default values for axes re-mapping */
struct bmi08_axes_remap axes_remap = {
.x_axis = BMI088_ANYMOTION_MAP_X_AXIS, .x_axis_sign = BMI088_ANYMOTION_MAP_POSITIVE,
.y_axis = BMI088_ANYMOTION_MAP_Y_AXIS, .y_axis_sign = BMI088_ANYMOTION_MAP_POSITIVE,
.z_axis = BMI088_ANYMOTION_MAP_Z_AXIS, .z_axis_sign = BMI088_ANYMOTION_MAP_POSITIVE
};
/* Check for chip id validity */
if ((dev->accel_chip_id == BMI088_ANYMOTION_ACCEL_CHIP_ID_PRIM) ||
(dev->accel_chip_id == BMI088_ANYMOTION_ACCEL_CHIP_ID_SEC))
{
/* Set the default values for axis
* re-mapping in the device structure
*/
dev->remap = axes_remap;
/* Assign stream file */
dev->config_file_ptr = bmi088_anymotion_config_file;
}
else
{
rslt = BMI08_E_DEV_NOT_FOUND;
}
}
return rslt;
}
/*!
* @brief This API sets the output data rate, range and bandwidth
* of accel sensor.
*/
int8_t bmi088_anymotion_set_meas_conf(struct bmi08_dev *dev)
{
int8_t rslt;
uint8_t data = { 0 };
uint8_t range;
uint8_t is_range_invalid = FALSE;
/* Check validity of ODR and BW */
rslt = bmi08a_set_meas_conf(dev);
/* Proceed if null check is fine */
if (rslt == BMI08_OK)
{
range = dev->accel_cfg.range;
/* Check for valid Range */
if (range > BMI088_ANYMOTION_ACCEL_RANGE_24G)
{
/* Updating the status */
is_range_invalid = TRUE;
}
/* If Range is valid, write it to accel config registers */
if (!is_range_invalid)
{
/* Read accel config. register */
rslt = bmi08a_get_set_regs(BMI08_REG_ACCEL_RANGE, &data, BMI08_REG_ACCEL_RANGE_LENGTH, dev, GET_FUNC);
if (rslt == BMI08_OK)
{
/* Update data with current range values */
data = BMI08_SET_BITS_POS_0(data, BMI08_ACCEL_RANGE, range);
/* Write accel range to register */
rslt = bmi08a_get_set_regs(BMI08_REG_ACCEL_RANGE, &data, BMI08_REG_ACCEL_RANGE_LENGTH, dev, SET_FUNC);
}
}
else
{
/* Invalid configuration present in ODR, BW, Range */
rslt = BMI08_E_INVALID_CONFIG;
}
}
return rslt;
}
/*!
* @brief This API reads the accel data from the sensor,
* store it in the bmi08_sensor_data structure instance
* passed by the user.
*/
int8_t bmi088_anymotion_get_data(struct bmi08_sensor_data *accel, struct bmi08_dev *dev)
{
int8_t rslt;
uint8_t data[6];
uint8_t lsb, msb;
uint16_t msblsb;
/* Proceed if null check is fine */
if (accel != NULL)
{
/* Read accel sensor data */
rslt = bmi08a_get_set_regs(BMI08_REG_ACCEL_X_LSB, data, BMI08_REG_ACCEL_X_LSB_LENGHT, dev, GET_FUNC);
if (rslt == BMI08_OK)
{
lsb = data[0];
msb = data[1];
msblsb = (msb << 8) | lsb;
accel->x = ((int16_t) msblsb); /* Data in X axis */
lsb = data[2];
msb = data[3];
msblsb = (msb << 8) | lsb;
accel->y = ((int16_t) msblsb); /* Data in Y axis */
lsb = data[4];
msb = data[5];
msblsb = (msb << 8) | lsb;
accel->z = ((int16_t) msblsb); /* Data in Z axis */
/* Get the re-mapped accelerometer data */
get_remapped_data(accel, dev);
}
}
else
{
rslt = BMI08_E_NULL_PTR;
}
return rslt;
}
/*!
* @brief This API configures the necessary accel interrupt
* based on the user settings in the bmi088_anymotion_int_cfg
* structure instance.
*/
int8_t bmi088_anymotion_set_int_config(const struct bmi08_accel_int_channel_cfg *int_config,
enum bmi088_anymotion_accel_int_types int_type,
struct bmi08_dev *dev)
{
int8_t rslt;
/* Proceed if null check is fine */
if (int_config != NULL)
{
switch (int_type)
{
case BMI088_ANYMOTION_ACCEL_DATA_RDY_INT:
rslt = set_accel_data_ready_int(int_config, dev);
break;
case BMI088_ANYMOTION_ACCEL_INT_FIFO_WM:
rslt = set_fifo_wm_int(int_config, dev);
break;
case BMI088_ANYMOTION_ACCEL_INT_FIFO_FULL:
rslt = set_fifo_full_int(int_config, dev);
break;
case BMI088_ANYMOTION_ANYMOTION_INT:
/* Anymotion interrupt */
rslt = set_accel_anymotion_int(int_config, dev);
break;
case BMI088_ANYMOTION_ERROR_INT:
/* Error interrupt */
rslt = set_accel_err_int(int_config, dev);
break;
default:
rslt = BMI08_E_INVALID_CONFIG;
break;
}
}
else
{
rslt = BMI08_E_NULL_PTR;
}
return rslt;
}
/*!
* @brief This API is used to enable/disable and configure the anymotion
* feature.
*/
int8_t bmi088_anymotion_configure_anymotion(struct bmi088_anymotion_anymotion_cfg anymotion_cfg, struct bmi08_dev *dev)
{
int8_t rslt;
uint16_t data[BMI088_ANYMOTION_ACCEL_ANYMOTION_LEN];
/* Check for null pointer in the device structure */
rslt = null_ptr_check(dev);
/* Proceed if null check is fine */
if (rslt == BMI08_OK)
{
/* Enable data synchronization */
data[0] = (anymotion_cfg.threshold & BMI088_ANYMOTION_ACCEL_ANYMOTION_THRESHOLD_MASK);
data[0] |=
((anymotion_cfg.enable << BMI088_ANYMOTION_ACCEL_ANYMOTION_SEL_SHIFT) &
BMI088_ANYMOTION_ACCEL_ANYMOTION_SEL_MASK);
data[1] = (anymotion_cfg.duration & BMI088_ANYMOTION_ACCEL_ANYMOTION_DURATION_MASK);
data[1] |=
((anymotion_cfg.x_en << BMI088_ANYMOTION_ACCEL_ANYMOTION_X_EN_SHIFT) &
BMI088_ANYMOTION_ACCEL_ANYMOTION_X_EN_MASK);
data[1] |=
((anymotion_cfg.y_en << BMI088_ANYMOTION_ACCEL_ANYMOTION_Y_EN_SHIFT) &
BMI088_ANYMOTION_ACCEL_ANYMOTION_Y_EN_MASK);
data[1] |=
((anymotion_cfg.z_en << BMI088_ANYMOTION_ACCEL_ANYMOTION_Z_EN_SHIFT) &
BMI088_ANYMOTION_ACCEL_ANYMOTION_Z_EN_MASK);
rslt = bmi08a_write_feature_config(BMI088_ANYMOTION_ACCEL_ANYMOTION_ADR,
&data[0],
BMI088_ANYMOTION_ACCEL_ANYMOTION_LEN,
dev);
}
return rslt;
}
/*!
* @brief This API gets the re-mapped x, y and z axes from the sensor and
* updates the values in the device structure.
*/
int8_t bmi088_anymotion_get_remap_axes(struct bmi088_anymotion_remap *remapped_axis, struct bmi08_dev *dev)
{
/* Variable to define error */
int8_t rslt;
/* Null-pointer check */
rslt = null_ptr_check(dev);
if ((rslt == BMI08_OK) && (remapped_axis != NULL))
{
/* Get the re-mapped axes from the sensor */
rslt = get_remap_axes(&dev->remap, dev);
if (rslt == BMI08_OK)
{
/* Store the receive re-mapped axis and sign from device structure */
receive_remap_axis(dev->remap.x_axis, dev->remap.x_axis_sign, &remapped_axis->x);
receive_remap_axis(dev->remap.y_axis, dev->remap.y_axis_sign, &remapped_axis->y);
receive_remap_axis(dev->remap.z_axis, dev->remap.z_axis_sign, &remapped_axis->z);
}
}
else
{
rslt = BMI08_E_NULL_PTR;
}
return rslt;
}
/*!
* @brief This API sets the re-mapped x, y and z axes to the sensor and
* updates the them in the device structure.
*/
int8_t bmi088_anymotion_set_remap_axes(const struct bmi088_anymotion_remap *remapped_axis, struct bmi08_dev *dev)
{
/* Variable to define error */
int8_t rslt;
/* Variable to store all the re-mapped axes */
uint8_t remap_axes = 0;
/* Null-pointer check */
rslt = null_ptr_check(dev);
if ((rslt == BMI08_OK) && (remapped_axis != NULL))
{
/* Check whether all the axes are re-mapped */
remap_axes = remapped_axis->x | remapped_axis->y | remapped_axis->z;
/* If all the axes are re-mapped */
if ((remap_axes & BMI088_ANYMOTION_AXIS_MASK) == BMI088_ANYMOTION_AXIS_MASK)
{
/* Store the value of re-mapped in device structure */
assign_remap_axis(remapped_axis->x, &dev->remap.x_axis, &dev->remap.x_axis_sign);
assign_remap_axis(remapped_axis->y, &dev->remap.y_axis, &dev->remap.y_axis_sign);
assign_remap_axis(remapped_axis->z, &dev->remap.z_axis, &dev->remap.z_axis_sign);
/* Set the re-mapped axes in the sensor */
rslt = set_remap_axes(&dev->remap, dev);
}
else
{
rslt = BMI088_ANYMOTION_E_REMAP_ERROR;
}
}
else
{
rslt = BMI08_E_NULL_PTR;
}
return rslt;
}
/*!
* @brief This API is used to get the config file major and minor information.
*/
int8_t bmi088_anymotion_get_version_config(uint16_t *config_major, uint16_t *config_minor, struct bmi08_dev *dev)
{
/* Initialize configuration file */
uint8_t feature_config[BMI088_ANYMOTION_FEATURE_SIZE] = { 0 };
/* Update index to config file version */
uint8_t index = BMI088_ANYMOTION_ADDR_CONFIG_ID_START;
/* Variable to define LSB */
uint8_t lsb = 0;
/* Variable to define MSB */
uint8_t msb = 0;
/* Variable to define LSB and MSB */
uint16_t lsb_msb = 0;
/* Result of api are returned to this variable */
int8_t rslt;
if ((config_major != NULL) && (config_minor != NULL))
{
/* Get config file identification from the sensor */
rslt = bmi08a_get_set_regs(BMI08_REG_ACCEL_FEATURE_CFG,
(uint8_t *)feature_config,
BMI088_ANYMOTION_FEATURE_SIZE,
dev,
GET_FUNC);
if (rslt == BMI08_OK)
{
/* Get word to calculate config file identification */
lsb = feature_config[index++];
msb = feature_config[index++];
lsb_msb = (uint16_t)(msb << 8 | lsb);
/* Get major and minor version */
*config_major = BMI08_GET_BITS(lsb_msb, BMI088_ANYMOTION_CONFIG_MAJOR);
*config_minor = BMI08_GET_BITS_POS_0(lsb, BMI088_ANYMOTION_CONFIG_MINOR);
}
}
else
{
rslt = BMI08_E_NULL_PTR;
}
return rslt;
}
/*!
* @brief This API checks whether the self-test functionality of the sensor
* is working or not.
*/
int8_t bmi088_anymotion_perform_selftest(struct bmi08_dev *dev)
{
int8_t rslt;
int8_t self_test_rslt = 0;
struct bmi08_sensor_data accel_pos, accel_neg;
/* Check for null pointer in the device structure */
rslt = null_ptr_check(dev);
/* Proceed if null check is fine */
if (rslt == BMI08_OK)
{
/* Pre-requisites for self-test */
rslt = enable_self_test(dev);
if (rslt == BMI08_OK)
{
rslt = positive_excited_accel(&accel_pos, dev);
if (rslt == BMI08_OK)
{
rslt = negative_excited_accel(&accel_neg, dev);
if (rslt == BMI08_OK)
{
/* Validate the self-test result */
rslt = validate_accel_self_test(&accel_pos, &accel_neg);
/* Store the status of self-test result */
self_test_rslt = rslt;
/* Perform soft-reset */
rslt = bmi08a_soft_reset(dev);
/* Check to ensure bus operations are success */
if (rslt == BMI08_OK)
{
/* Restore self_test_rslt as return value */
rslt = self_test_rslt;
}
}
}
}
}
return rslt;
}
/*!
* @brief This internal API gets accel feature interrupt status
*/
int8_t bmi088_anymotion_get_feat_int_status(uint8_t *int_status, struct bmi08_dev *dev)
{
int8_t rslt;
uint8_t status = 0;
if (int_status != NULL)
{
rslt =
bmi08a_get_set_regs(BMI08_REG_ACCEL_INT_STAT_0, &status, BMI08_REG_ACCEL_INT_STATUS_LENGTH, dev, GET_FUNC);
if (rslt == BMI08_OK)
{
(*int_status) = status;
}
}
else
{
rslt = BMI08_E_NULL_PTR;
}
return rslt;
}
/*****************************************************************************/
/* Static function definition */
/*! @cond DOXYGEN_SUPRESS */
/* Suppressing doxygen warnings triggered for same static function names present across various sensor variant
* directories */
/*!
* @brief This API is used to validate the device structure pointer for
* null conditions.
*/
static int8_t null_ptr_check(const struct bmi08_dev *dev)
{
int8_t rslt;
if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL) ||
(dev->intf_ptr_accel == NULL))
{
/* Device structure pointer is not valid */
rslt = BMI08_E_NULL_PTR;
}
else
{
/* Device structure is fine */
rslt = BMI08_OK;
}
return rslt;
}
/*!
* @brief This API configures the pins which fire the
* interrupt signal when any interrupt occurs.
*/
static int8_t set_int_pin_config(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev)
{
int8_t rslt;
uint8_t reg_addr = 0, data, is_channel_invalid = FALSE;
switch (int_config->int_channel)
{
case BMI08_INT_CHANNEL_1:
/* Update reg_addr based on channel inputs */
reg_addr = BMI08_REG_ACCEL_INT1_IO_CONF;
break;
case BMI08_INT_CHANNEL_2:
/* Update reg_addr based on channel inputs */
reg_addr = BMI08_REG_ACCEL_INT2_IO_CONF;
break;
default:
is_channel_invalid = TRUE;
break;
}
if (!is_channel_invalid)
{
/* Read interrupt pin configuration register */
rslt = bmi08a_get_set_regs(reg_addr, &data, BMI08_REG_INT_CFG_LENGTH, dev, GET_FUNC);
if (rslt == BMI08_OK)
{
/* Update data with user configured bmi088_anymotion_int_cfg structure */
data = BMI08_SET_BITS(data, BMI08_ACCEL_INT_LVL, int_config->int_pin_cfg.lvl);
data = BMI08_SET_BITS(data, BMI08_ACCEL_INT_OD, int_config->int_pin_cfg.output_mode);
data = BMI08_SET_BITS(data, BMI08_ACCEL_INT_IO, int_config->int_pin_cfg.enable_int_pin);
data = BMI08_SET_BIT_VAL_0(data, BMI08_ACCEL_INT_IN);
/* Write to interrupt pin configuration register */
rslt = bmi08a_get_set_regs(reg_addr, &data, BMI08_REG_INT_CFG_LENGTH, dev, SET_FUNC);
}
}
else
{
rslt = BMI08_E_INVALID_INPUT;
}
return rslt;
}
/*!
* @brief This API sets the anymotion interrupt for accel sensor
*/
static int8_t set_accel_anymotion_int(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev)
{
int8_t rslt;
uint8_t data, reg_addr = 0;
/* Check for null pointer in the device structure */
rslt = null_ptr_check(dev);
if (rslt == BMI08_OK)
{
data = BMI088_ANYMOTION_ACCEL_ANY_MOT_INT_DISABLE;
switch (int_config->int_channel)
{
case BMI08_INT_CHANNEL_1:
reg_addr = BMI08_REG_ACCEL_INT1_MAP;
break;
case BMI08_INT_CHANNEL_2:
reg_addr = BMI08_REG_ACCEL_INT2_MAP;
break;
default:
rslt = BMI08_E_INVALID_INPUT;
break;
}
if (rslt == BMI08_OK)
{
rslt = bmi08a_get_set_regs(reg_addr, &data, BMI08_REG_ACCEL_INT_MAP_DATA_LENGTH, dev, GET_FUNC);
if (int_config->int_pin_cfg.enable_int_pin == BMI08_ENABLE)
{
/* Interrupt B mapped to INT1/INT2 */
data |= BMI088_ANYMOTION_ACCEL_ANY_MOT_INT_ENABLE;
}
else
{
data &= ~BMI088_ANYMOTION_ACCEL_ANY_MOT_INT_ENABLE;
}
if (rslt == BMI08_OK)
{
/* Write to interrupt map register */
rslt = bmi08a_get_set_regs(reg_addr, &data, BMI08_REG_ACCEL_INT_MAP_DATA_LENGTH, dev, SET_FUNC);
}
if (rslt == BMI08_OK)
{
/* Set input interrupt configuration */
rslt = set_int_pin_config(int_config, dev);
}
}
}
return rslt;
}
/*!
* @brief This API sets error interrupt for accel sensor
*/
static int8_t set_accel_err_int(const struct bmi08_accel_int_channel_cfg *int_config, struct bmi08_dev *dev)
{
int8_t rslt;
uint8_t data, reg_addr = 0;
/* Check for null pointer in the device structure*/
rslt = null_ptr_check(dev);
if (rslt == BMI08_OK)
{
data = BMI088_ANYMOTION_ACCEL_ERR_INT_DISABLE;
switch (int_config->int_channel)
{
case BMI08_INT_CHANNEL_1:
reg_addr = BMI08_REG_ACCEL_INT1_MAP;
break;
case BMI08_INT_CHANNEL_2:
reg_addr = BMI08_REG_ACCEL_INT2_MAP;
break;
default:
rslt = BMI08_E_INVALID_INPUT;
break;
}
if (rslt == BMI08_OK)
{
rslt = bmi08a_get_set_regs(reg_addr, &data, BMI08_REG_ACCEL_INT_MAP_DATA_LENGTH, dev, GET_FUNC);
if (int_config->int_pin_cfg.enable_int_pin == BMI08_ENABLE)
{
/* Interrupt B mapped to INT1/INT2 */
data |= BMI088_ANYMOTION_ACCEL_ERR_INT_ENABLE;
}
else
{
data &= ~BMI088_ANYMOTION_ACCEL_ERR_INT_ENABLE;
}
if (rslt == BMI08_OK)