-
Notifications
You must be signed in to change notification settings - Fork 5
/
bmi3.c
9032 lines (7454 loc) · 305 KB
/
bmi3.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) 2023 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 bmi3.c
* @date 2023-02-17
* @version v2.1.0
*
*/
/******************************************************************************/
/*! @name Header Files */
/******************************************************************************/
#include "bmi3.h"
#ifdef __KERNEL__
#include <linux/types.h>
#include <linux/kernel.h>
#else
#include "stdio.h"
#endif
/***************************************************************************/
/*! Static Variable
****************************************************************************/
/*! Array to store config array code */
static uint8_t bmi3_config_array_code[] = {
0x48, 0x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a1, 0x32, 0x98, 0x2e, 0x80, 0x03, 0x00, 0x30, 0x21, 0x2e, 0xda, 0x03, 0x0b, 0x2d,
0x0a, 0x2c, 0x00, 0x30, 0x98, 0x2e, 0x71, 0x03, 0xf4, 0x6f, 0x21, 0x2e, 0xdb, 0x03, 0x00, 0x43, 0x10, 0x30, 0x21,
0x2e, 0xda, 0x03, 0xeb, 0x6f, 0xe0, 0x5f, 0xb8, 0x2e, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/*! Array to store config array table */
static uint8_t bmi3_config_array_table[] = {
0x05, 0x02, 0x0c, 0x00, 0x99, 0x02, 0x97, 0x02, 0x8f, 0x02, 0x6e, 0x02, 0x00, 0x00, 0x80, 0x02, 0xaf, 0x02, 0xea,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x02
};
/*! Array to store config version */
static uint8_t bmi3_config_version[] = {
0xad, 0x00, 0x01, 0x00, 0x08, 0x08
};
/******************************************************************************/
/*! Local Function Prototypes
******************************************************************************/
/*!
* @brief This internal API sets accelerometer configurations like ODR, accel mode,
* bandwidth, averaging samples and range.
*
* @param[in,out] config : Structure instance of bmi3_accel_config.
* @param[in,out] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_accel_config(struct bmi3_accel_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API validates bandwidth and averaging samples of the
* accelerometer set by the user.
*
* @param[in, out] bandwidth : Pointer to bandwidth value set by the user.
* @param[in, out] acc_mode : Pointer to accel mode set by the user.
* @param[in, out] avg_num : Pointer to average samples set by the user.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @note dev->info contains two warnings: BMI3_I_MIN_VALUE and BMI3_I_MAX_VALUE
*
* @return 0 -> Success
* @return < 0 -> Fail
* @return > 0 -> Warning
*
*/
static int8_t validate_bw_avg_acc_mode(uint8_t *bandwidth, uint8_t *acc_mode, uint8_t *avg_num, struct bmi3_dev *dev);
/*!
* @brief This internal API validates ODR and range of the accelerometer set by
* the user.
*
* @param[in, out] odr : Pointer to ODR value set by the user.
* @param[in, out] range : Pointer to range value set by the user.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @note dev->info contains two warnings: BMI3_I_MIN_VALUE and BMI3_I_MAX_VALUE
*
* @return 0 -> Success
* @return < 0 -> Fail
* @return > 0 -> Warning
*/
static int8_t validate_acc_odr_range(uint8_t *odr, uint8_t *range, struct bmi3_dev *dev);
/*!
* @brief This internal API is used to check the boundary conditions.
*
* @param[in,out] val : Pointer to the value to be validated.
* @param[in] min : Minimum value.
* @param[in] max : Maximum value.
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t check_boundary_val(uint8_t *val, uint8_t min, uint8_t max, struct bmi3_dev *dev);
/*!
* @brief This internal API gets accelerometer configurations like ODR, accel mode,
* bandwidth, averaging samples and range.
*
* @param[out] config : Structure instance of bmi3_accel_config.
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_accel_config(struct bmi3_accel_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets the accelerometer data from the register.
*
* @param[out] data : Structure instance of sensor_data.
* @param[in] reg_addr : Register address where data is stored.
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_accel_sensor_data(struct bmi3_sens_axes_data *data, uint8_t reg_addr, struct bmi3_dev *dev);
/*!
* @brief This internal API sets gyroscope configurations like ODR, gyro mode,
* bandwidth, averaging samples and range.
*
* @param[in] config : Structure instance of bmi3_gyro_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_gyro_config(struct bmi3_gyro_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API validates bandwidth and averaging samples of the
* gyroscope set by the user.
*
* @param[in, out] bandwidth : Pointer to bandwidth value set by the user.
* @param[in, out] gyr_mode : Pointer to gyro mode set by the user.
* @param[in, out] avg_num : Pointer to average samples set by the user.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @note dev->info contains two warnings: BMI3_I_MIN_VALUE and BMI3_I_MAX_VALUE
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t validate_bw_avg_gyr_mode(uint8_t *bandwidth,
uint8_t *gyr_mode,
const uint8_t *avg_num,
struct bmi3_dev *dev);
/*!
* @brief This internal API validates ODR and range of the gyroscope set by
* the user.
*
* @param[in, out] odr : Pointer to ODR value set by the user.
* @param[in, out] range : Pointer to range value set by the user.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @note dev->info contains two warnings: BMI3_I_MIN_VALUE and BMI3_I_MAX_VALUE
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t validate_gyr_odr_range(uint8_t *odr, uint8_t *range, struct bmi3_dev *dev);
/*!
* @brief This internal API gets the gyroscope data from the register.
*
* @param[out] data : Structure instance of bmi3_sens_axes_data.
* @param[in] reg_addr : Register address where data is stored.
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_gyro_sensor_data(struct bmi3_sens_axes_data *data, uint8_t reg_addr, struct bmi3_dev *dev);
/*!
* @brief This internal API gets the step counter data from the register.
*
* @param[out] step_count : Variable to get step counter data.
* @param[in] reg_addr : Register address where data is stored.
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_step_counter_sensor_data(uint32_t *step_count, uint8_t reg_addr, struct bmi3_dev *dev);
/*!
* @brief This internal API gets the orientation output data from the register.
*
* @param[out] orient_out : Structure instance of bmi3_orientation_output.
* @param[in] reg_addr : Register address where data is stored.
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_orient_output_data(struct bmi3_orientation_output *orient_out, uint8_t reg_addr,
struct bmi3_dev *dev);
/*!
* @brief This internal API gets gyroscope configurations like ODR, gyro mode,
* bandwidth, averaging samples and range.
*
* @param[out] config : Structure instance of bmi3_gyro_config.
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_gyro_config(struct bmi3_gyro_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets the accelerometer data.
*
* @param[out] data : Structure instance of bmi3_sens_axes_data.
* @param[in] reg_data : Data stored in the register.
*
* @return None
*
* @retval None
*/
static void get_acc_data(struct bmi3_sens_axes_data *data, const uint16_t *reg_data);
/*!
* @brief This internal API gets the gyroscope data.
*
* @param[out] data : Structure instance of bmi3_sens_axes_data.
* @param[in] reg_data : Data stored in the register.
*
* @return None
*
* @retval None
*/
static void get_gyr_data(struct bmi3_sens_axes_data *data, const uint16_t *reg_data);
/*!
* @brief This internal API is used to validate the device pointer for
* null conditions.
*
* @param[in] dev : Structure instance of bmi3_dev.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t null_ptr_check(const struct bmi3_dev *dev);
/*!
* @brief This internal API is used to set the feature.
*
* @param[in] dev : Structure instance of bmi3_dev.
* @param[in] enable : Structure instance of bmi3_feature_enable.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_feature_enable(const struct bmi3_feature_enable *enable, struct bmi3_dev *dev);
/*!
* @brief This internal API is used to get the feature.
*
* @param[in] dev : Structure instance of bmi3_dev.
* @param[in] enable : Structure instance of bmi3_feature_enable.
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_feature_enable(struct bmi3_feature_enable *enable, struct bmi3_dev *dev);
/*!
* @brief This internal API gets any-motion configurations like slope_thres,
* duration, hysteresis, accel ref up and wait time.
*
* @param[out] config : Structure instance of bmi3_any_motion_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_any_motion_config |
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* | Minimum slope of acceleration signal for
* | motion detection.
* slope_thres | Default value = 10, Range = 0 to 4095, Unit = 1.953mg.
* |
* -------------------------|---------------------------------------------------
* accel reference up | Mode of the acceleration reference update
* -------------------------|---------------------------------------------------
* | Hysteresis for the slope of the acceleration
* hysteresis | signal. Default value = 2, Range = 0 to 1023,
* | Unit = 1.953mg.
* -------------------------|---------------------------------------------------
* | Defines the number of consecutive data points for
* | which the threshold condition must be respected,
* | for interrupt assertion.
* duration | unit is 20ms, range
* | Default value is 10 = 2000ms.
* -------------------------|---------------------------------------------------
* |
* wait time | Wait time for clearing the event after slope
* | is below threshold. Default value = 3, Range = 0 to 7, Unit =
* | 20ms.
* -----------------------------------------------------------------------------
*
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_any_motion_config(struct bmi3_any_motion_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API sets any-motion configurations like slope threshold,
* duration, hysteresis, accel ref up and wait time.
*
* @param[in] config : Structure instance of bmi3_any_motion_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_any_motion_config |
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* | Minimum slope of acceleration signal for
* | motion detection.
* slope_thres | Default value = 10, Range = 0 to 4095, Unit = 1.953mg.
* |
* -------------------------|---------------------------------------------------
* accel reference up | Mode of the acceleration reference update
* -------------------------|---------------------------------------------------
* | Hysteresis for the slope of the acceleration
* hysteresis | signal. Default value = 2, Range = 0 to 1023,
* | Unit = 1.953mg.
* -------------------------|---------------------------------------------------
* | Defines the number of consecutive data points for
* | which the threshold condition must be respected,
* | for interrupt assertion.
* duration | unit is 20ms, range
* | Default value is 10 = 2000ms.
* -------------------------|---------------------------------------------------
* |
* wait time | Wait time for clearing the event after slope
* | is below threshold. Default value = 3, Range = 0 to 7, Unit =
* | 20ms.
* -----------------------------------------------------------------------------
*
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_any_motion_config(const struct bmi3_any_motion_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets no-motion configurations like slope threshold,
* duration, hysteresis, accel ref up and wait time.
*
* @param[out] config : Structure instance of bmi3_no_motion_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_no_motion_config |
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* | Minimum slope of acceleration signal for
* | motion detection.
* slope_thres | Default value = 10, Range = 0 to 4095, Unit = 1.953mg.
* |
* -------------------------|---------------------------------------------------
* accel reference up | Mode of the acceleration reference update
* -------------------------|---------------------------------------------------
* | Hysteresis for the slope of the acceleration
* hysteresis | signal. Default value = 2, Range = 0 to 1023,
* | Unit = 1.953mg.
* -------------------------|---------------------------------------------------
* | Defines the number of consecutive data points for
* | which the threshold condition must be respected,
* | for interrupt assertion.
* duration | unit is 20ms, range
* | Default value is 10 = 2000ms.
* -------------------------|---------------------------------------------------
* |
* wait time | Wait time for clearing the event after slope
* | is below threshold. Default value = 3, Range = 0 to 7, Unit =
* | 20ms.
* -----------------------------------------------------------------------------
*
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_no_motion_config(struct bmi3_no_motion_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API sets no-motion configurations like slope threshold,
* duration, hysteresis, accel ref up and wait time.
*
* @param[in] config : Structure instance of bmi3_no_motion_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_no_motion_config |
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* | Minimum slope of acceleration signal for
* | motion detection.
* slope_thres | Default value = 10, Range = 0 to 4095, Unit = 1.953mg.
* |
* -------------------------|---------------------------------------------------
* accel reference up | Mode of the acceleration reference update
* -------------------------|---------------------------------------------------
* | Hysteresis for the slope of the acceleration
* hysteresis | signal. Default value = 2, Range = 0 to 1023,
* | Unit = 1.953mg.
* -------------------------|---------------------------------------------------
* | Defines the number of consecutive data points for
* | which the threshold condition must be respected,
* | for interrupt assertion.
* duration | unit is 20ms, range
* | Default value is 10 = 2000ms.
* -------------------------|---------------------------------------------------
* |
* wait time | Wait time for clearing the event after slope
* | is below threshold. Default value = 3, Range = 0 to 7, Unit =
* | 20ms.
* -----------------------------------------------------------------------------
*
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_no_motion_config(const struct bmi3_no_motion_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets flat configurations like theta, blocking,
* hold-time, hysteresis, and slope threshold.
*
* @param[out] config : Structure instance of bmi3_flat_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_flat_config |
* Structure parameters| Description
*--------------------------|--------------------------------------------------
* | Theta angle, used for detecting flat
* | position.
* theta | Theta = 64 * (tan(angle)^2);
* | Default value is 8, equivalent to 20 degrees angle
* -------------------------|---------------------------------------------------
* | Hysteresis for Theta Flat detection.
* hysteresis | Default value is 9 = 2.5 degrees, corresponding
* | to the default Theta angle of 20 degrees.
* -------------------------|---------------------------------------------------
* | Sets the blocking mode. If blocking is set, no
* | Flat interrupt will be triggered.
* blocking | Default value is 2, the most restrictive blocking
* | mode.
* -------------------------|---------------------------------------------------
* | Holds the duration in 50Hz samples for which the
* | condition has to be respected.
* hold-time | Default value is 32 = 640 m-sec.
* | Range is 0 to 5.1 sec.
* -------------------------|---------------------------------------------------
* | Minimum slope between consecutive acceleration
* slope_thres | samples to prevent the change of flat status during
* | large movement. Default value is 0xcd = 400.365mg,
* | Range = 498.015mg, Unit = 1.953mg.
* -------------------------|---------------------------------------------------
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_flat_config(struct bmi3_flat_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API sets flat configurations like theta, blocking,
* hold-time, hysteresis, and slope threshold.
*
* @param[in] config : Structure instance of bmi3_flat_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_flat_config |
* Structure parameters| Description
*--------------------------|--------------------------------------------------
* | Theta angle, used for detecting flat
* | position.
* theta | Theta = 64 * (tan(angle)^2);
* | Default value is 8, equivalent to 20 degrees angle
* -------------------------|---------------------------------------------------
* | Hysteresis for Theta Flat detection.
* hysteresis | Default value is 9 = 2.5 degrees, corresponding
* | to the default Theta angle of 20 degrees.
* -------------------------|---------------------------------------------------
* | Sets the blocking mode. If blocking is set, no
* | Flat interrupt will be triggered.
* blocking | Default value is 2, the most restrictive blocking
* | mode.
* -------------------------|---------------------------------------------------
* | Holds the duration in 50Hz samples for which the
* | condition has to be respected.
* hold-time | Default value is 32 = 640 m-sec.
* | Range is 0 to 5.1 sec.
* -------------------------|---------------------------------------------------
* | Minimum slope between consecutive acceleration
* slope_threshold | samples to prevent the change of flat status during
* | large movement. Default value is 0xcd = 400.365mg,
* | Range = 498.015mg, Unit = 1.953mg.
* -------------------------|---------------------------------------------------
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_flat_config(const struct bmi3_flat_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets sig-motion configurations like block-size,
* peak_2_peak_min, mcr_min, peak_2_peak_max and mcr_max parameters.
*
* @param[out] config : Structure instance of bmi3_sig_motion_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
*----------------------------------------------------------------------------
* bmi3_sig_motion_config |
* Structure parameters | Description
* -------------------------|---------------------------------------------------
* | Defines the duration after which the significant
* block_size | motion interrupt is triggered. It is expressed in
* | 50 Hz samples (20 ms). Default value is 0xFA=5sec.
*--------------------------|---------------------------------------------------
* | Minimum value of the peak to peak acceleration
* peak_2_peak_min | magnitude. Default value 0x26 = 74.214mg, Range = 0 to 1023,
* | Unit = 1.953mg
*--------------------------|---------------------------------------------------
* | Minimum number of mean crossing per second in accel
* mcr_min | magnitude. Default value = 17, Range = 0 to 63.
*--------------------------|---------------------------------------------------
* | Maximum value of the peak to peak acceleration
* peak_2_peak_max | magnitude. Default value 0x253 = 1162.035mg, Range = 0 to 1023,
* | Unit = 1.953mg
*--------------------------|---------------------------------------------------
* | Maximum number of mean crossing per second in accel
* mcr_max | magnitude. Default value = 17, Range = 0 to 63.
*--------------------------|---------------------------------------------------
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_sig_motion_config(struct bmi3_sig_motion_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API sets sig-motion configurations like block-size,
* peak_2_peak_min, mcr_min, peak_2_peak_max and mcr_max parameters.
*
* @param[in] config : Structure instance of bmi3_sig_motion_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
*----------------------------------------------------------------------------
* bmi3_sig_motion_config |
* Structure parameters | Description
* -------------------------|---------------------------------------------------
* | Defines the duration after which the significant
* block_size | motion interrupt is triggered. It is expressed in
* | 50 Hz samples (20 ms). Default value is 0xFA=5sec.
*--------------------------|---------------------------------------------------
* | Minimum value of the peak to peak acceleration
* peak_2_peak_min | magnitude. Default value 0x26 = 74.214mg, Range = 0 to 1023,
* | Unit = 1.953mg
*--------------------------|---------------------------------------------------
* | Minimum number of mean crossing per second in accel
* mcr_min | magnitude. Default value = 17, Range = 0 to 63.
*--------------------------|---------------------------------------------------
* | Maximum value of the peak to peak acceleration
* peak_2_peak_max | magnitude. Default value 0x253 = 1162.035mg, Range = 0 to 1023,
* | Unit = 1.953mg
*--------------------------|---------------------------------------------------
* | Maximum number of mean crossing per second in accel
* mcr_max | magnitude. Default value = 17, Range = 0 to 63.
*--------------------------|---------------------------------------------------
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_sig_motion_config(const struct bmi3_sig_motion_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets the latch mode from register address
*
* @param[out] int_cfg : Structure instance of bmi3_int_pin_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_latch_mode(struct bmi3_int_pin_config *int_cfg, struct bmi3_dev *dev);
/*!
* @brief This internal API sets the latch mode to register address
*
* @param[out] int_cfg : Structure instance of bmi3_int_pin_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_latch_mode(const struct bmi3_int_pin_config *int_cfg, struct bmi3_dev *dev);
/*!
* @brief This internal API gets tilt configurations like segment size, minimum tilt angle
* and beta accel mean.
*
* @param[out] config : Structure instance of bmi3_tilt_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_tilt_config |
* Structure parameters | Description
*------------------------- |--------------------------------------------------
* | Duration for which the acceleration vector is
* | averaged to be reference vector. Default value = 100, Range = 0
* segment size | to 255, Unit = 20ms.
* ------------------------ |---------------------------------------------------
* | Minimum angle by which the device shall be
* | tilted for event detection.
* minimum tilt angle | Angle is computed as 256 * cos(angle).
* | Default value = 210, Range = 0 to 255.
* ------------------------ |---------------------------------------------------
* | Exponential smoothing coefficient for
* beta accel mean | computing low-pass mean of acceleration vector.
* | Coefficient is computed as beta * 65536.
* | Default value = 61545, Range = 0 to 65535.
* ------------------------ |---------------------------------------------------
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_tilt_config(struct bmi3_tilt_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API sets tilt configurations like segment size, minimum tilt angle
* and beta accel mean.
*
* @param[in] config : Structure instance of bmi3_tilt_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi3_tilt_config |
* Structure parameters | Description
*------------------------- |--------------------------------------------------
* | Duration for which the acceleration vector is
* | averaged to be reference vector. Default value = 100, Range = 0
* segment size | to 255, Unit = 20ms.
* ------------------------ |---------------------------------------------------
* | Minimum angle by which the device shall be
* | tilted for event detection.
* minimum tilt angle | Angle is computed as 256 * cos(angle).
* | Default value = 210, Range = 0 to 255.
* ------------------------ |---------------------------------------------------
* | Exponential smoothing coefficient for
* beta accel mean | computing low-pass mean of acceleration vector.
* | Coefficient is computed as beta * 65536.
* | Default value = 61545, Range = 0 to 65535.
* ------------------------ |---------------------------------------------------
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_tilt_config(const struct bmi3_tilt_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets orientation configurations like upside/down
* enable, symmetrical modes, blocking mode, theta, hysteresis, slope threshold and
* hold time configuration.
*
* @param[out] config : Structure instance of bmi3_orientation_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*-----------------------------------------------------------------------------
* bmi3_orientation_config|
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* upside/down | Enables upside/down detection, if set to 1.
* detection |
* -------------------------|---------------------------------------------------
* | Sets the mode:
* mode | Values 0 or 3 - symmetrical.
* | Value 1 - high asymmetrical
* | Value 2 - low asymmetrical
* -------------------------|---------------------------------------------------
* | Enable - no orientation interrupt will be set.
* blocking | Default value: 3, the most restrictive blocking.
* -------------------------|---------------------------------------------------
* | Threshold angle used in blocking mode.
* theta | Theta = 64 * (tan(angle)^2)
* | Default value: 39, range 0 to 63.
* -------------------------|---------------------------------------------------
* | Hysteresis of acceleration in orientation change
* hysteresis | change detection.
* | Default value = 32, range 0 to 255, unit = 1.93mg.
* -------------------------|---------------------------------------------------
* | Minimum duration the device shall be in new orientation
* hold_time | for change detection. default value = 5, range 0 to 255,
* | unit = 20ms.
* -------------------------|---------------------------------------------------
* | Minimum slope between consecutive acceleration samples to
* slope_thres | prevent the change of orientation during large movement.
* | Default value = 205, range = 0 t0 255, uint = 1.953mg.
* -------------------------|---------------------------------------------------
*
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_orientation_config(struct bmi3_orientation_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API sets orientation configurations like upside/down
* enable, symmetrical modes, blocking mode, theta, hysteresis, slope threshold and
* hold time configuration.
*
* @param[in] config : Structure instance of bmi3_orientation_config.
* @param[in, out] dev : Structure instance of bmi3_dev.
*
* @verbatim
*-----------------------------------------------------------------------------
* bmi3_orientation_config|
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* upside/down | Enables upside/down detection, if set to 1.
* detection |
* -------------------------|---------------------------------------------------
* | Sets the mode:
* mode | Values 0 or 3 - symmetrical.
* | Value 1 - high asymmetrical
* | Value 2 - low asymmetrical
* -------------------------|---------------------------------------------------
* | Enable - no orientation interrupt will be set.
* blocking | Default value: 3, the most restrictive blocking.
* -------------------------|---------------------------------------------------
* | Threshold angle used in blocking mode.
* theta | Theta = 64 * (tan(angle)^2)
* | Default value: 39, range 0 to 63.
* -------------------------|---------------------------------------------------
* | Hysteresis of acceleration in orientation change
* hysteresis | change detection.
* | Default value = 32, range 0 to 255, unit = 1.93mg.
* -------------------------|---------------------------------------------------
* | Minimum duration the device shall be in new orientation
* hold_time | for change detection. default value = 5, range 0 to 255,
* | unit = 20ms.
* -------------------------|---------------------------------------------------
* | Minimum slope between consecutive acceleration samples to
* slope_thres | prevent the change of orientation during large movement.
* | Default value = 205, range = 0 t0 255, uint = 1.953mg.
* -------------------------|---------------------------------------------------
*
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t set_orientation_config(const struct bmi3_orientation_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API gets step counter/detector/activity configurations.
*
* @param[out] config : Structure instance of bmi3_step_counter_config.
* @param[in] dev : Structure instance of bmi3_dev.
*
*---------------------------------------------------------------------------
* bmi3_step_counter_config|
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* | The Step-counter will trigger output every time
* | the number of steps are counted. Holds implicitly
* water-mark level | a 20x factor, so the range is 0 to 20460,
* | with resolution of 20 steps. If 0 output disabled.
* -------------------------|---------------------------------------------------
* reset counter | Flag to reset the counted steps.
* -------------------------|---------------------------------------------------
* step_counter_params | 1 - 19 step_counter parameters for different settings.
* -------------------------|---------------------------------------------------
* | Switch between the devices.
* | value 0 = Smart phone
* sc_12_res | value 1 = Wrist wearable
* | value 2 = Hearable
* -------------------------|---------------------------------------------------
* @endverbatim
*
* @return Result of API execution status
*
* @return 0 -> Success
* @return < 0 -> Fail
*
*/
static int8_t get_step_config(struct bmi3_step_counter_config *config, struct bmi3_dev *dev);
/*!
* @brief This internal API sets step counter/detector/activity configurations.
*
* @param[in] config : Structure instance of bmi3_step_counter_config.
* @param[in] dev : Structure instance of bmi3_dev.
*
*---------------------------------------------------------------------------
* bmi3_step_counter_config|
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* | The Step-counter will trigger output every time
* | the number of steps are counted. Holds implicitly
* water-mark level | a 20x factor, so the range is 0 to 20460,
* | with resolution of 20 steps. If 0 output disabled.