-
Notifications
You must be signed in to change notification settings - Fork 54
/
bmi2.c
11705 lines (9898 loc) · 366 KB
/
bmi2.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 bmi2.c
* @date 2023-05-03
* @version v2.86.1
*
*/
/******************************************************************************/
/*! @name Header Files */
/******************************************************************************/
#include "bmi2.h"
/***************************************************************************/
/*! Local structures
****************************************************************************/
/*! @name Structure to define the difference in accelerometer values */
struct bmi2_selftest_delta_limit
{
/*! X data */
int32_t x;
/*! Y data */
int32_t y;
/*! Z data */
int32_t z;
};
/*! @name Structure to store temporary accelerometer/gyroscope values */
struct bmi2_foc_temp_value
{
/*! X data */
int32_t x;
/*! Y data */
int32_t y;
/*! Z data */
int32_t z;
};
/*! @name Structure to store accelerometer data deviation from ideal value */
struct bmi2_offset_delta
{
/*! X axis */
int16_t x;
/*! Y axis */
int16_t y;
/*! Z axis */
int16_t z;
};
/*! @name Structure to store accelerometer offset values */
struct bmi2_accel_offset
{
/*! offset X data */
uint8_t x;
/*! offset Y data */
uint8_t y;
/*! offset Z data */
uint8_t z;
};
/******************************************************************************/
/*! Local Function Prototypes
******************************************************************************/
/*!
* @brief This internal API writes the configuration file.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t write_config_file(struct bmi2_dev *dev);
/*!
* @brief This internal API enables/disables the loading of the configuration
* file.
*
* @param[in] enable : To enable/disable configuration load.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_config_load(uint8_t enable, struct bmi2_dev *dev);
/*!
* @brief This internal API loads the configuration file.
*
* @param[in] config_data : Pointer to the configuration file.
* @param[in] index : Variable to define array index.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t upload_file(const uint8_t *config_data, uint16_t index, uint16_t write_len, struct bmi2_dev *dev);
/*!
* @brief This internal API sets accelerometer configurations like ODR,
* bandwidth, performance mode and g-range.
*
* @param[in,out] config : Structure instance of bmi2_accel_config.
* @param[in,out] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_accel_config(struct bmi2_accel_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API validates bandwidth and performance mode of the
* accelerometer set by the user.
*
* @param[in, out] bandwidth : Pointer to bandwidth value set by the user.
* @param[in, out] perf_mode : Pointer to performance mode set by the user.
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @note dev->info contains two warnings: BMI2_I_MIN_VALUE and BMI2_I_MAX_VALUE
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t validate_bw_perf_mode(uint8_t *bandwidth, uint8_t *perf_mode, struct bmi2_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 bmi2_dev.
*
* @note dev->info contains two warnings: BMI2_I_MIN_VALUE and BMI2_I_MAX_VALUE
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t validate_odr_range(uint8_t *odr, uint8_t *range, struct bmi2_dev *dev);
/*!
* @brief This internal API sets gyroscope configurations like ODR, bandwidth,
* low power/high performance mode, performance mode and range.
*
* @param[in,out] config : Structure instance of bmi2_gyro_config.
* @param[in,out] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_gyro_config(struct bmi2_gyro_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API validates bandwidth, performance mode, low power/
* high performance mode, ODR, and range set by the user.
*
* @param[in] config : Structure instance of bmi2_gyro_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note dev->info contains two warnings: BMI2_I_MIN_VALUE and BMI2_I_MAX_VALUE
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t validate_gyro_config(struct bmi2_gyro_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API shows the error status when illegal sensor
* configuration is set.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t cfg_error_status(struct bmi2_dev *dev);
/*!
* @brief This internal API:
* 1) Enables/Disables auxiliary interface.
* 2) Sets auxiliary interface configurations like I2C address, manual/auto
* mode enable, manual burst read length, AUX burst read length and AUX read
* address.
* 3)It maps/un-maps data interrupts to that of hardware interrupt line.
*
* @param[in] config : Structure instance of bmi2_aux_config.
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_aux_config(struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API sets gyroscope user-gain configurations like gain
* update value for x, y and z-axis.
*
* @param[in] config : Structure instance of bmi2_gyro_user_gain_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi2_gyro_user_gain_config|
* Structure parameters | Description
*--------------------------|--------------------------------------------------
* ratio_x | Gain update value for x-axis
* -------------------------|---------------------------------------------------
* ratio_y | Gain update value for y-axis
* -------------------------|---------------------------------------------------
* ratio_z | Gain update value for z-axis
* @endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_gyro_user_gain_config(const struct bmi2_gyro_user_gain_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API enables/disables auxiliary interface.
*
* @param[in] config : Structure instance of bmi2_aux_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_aux_interface(const struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API sets auxiliary configurations like manual/auto mode
* FCU write command enable and read burst length for both data and manual mode.
*
* @param[in] config : Structure instance of bmi2_aux_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note Auxiliary sensor should not be busy when configuring aux_i2c_addr,
* man_rd_burst_len, aux_rd_burst_len and aux_rd_addr.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t config_aux_interface(const struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API triggers read out offset and sets ODR of the
* auxiliary sensor.
*
* @param[in] config : Structure instance of bmi2_aux_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t config_aux(const struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API validates auxiliary configuration set by the user.
*
* @param[in, out] config : Structure instance of bmi2_aux_config.
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @note dev->info contains two warnings: BMI2_I_MIN_VALUE and BMI2_I_MAX_VALUE
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t validate_aux_config(struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API gets accelerometer configurations like ODR,
* bandwidth, performance mode and g-range.
*
* @param[out] config : Structure instance of bmi2_accel_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_accel_config(struct bmi2_accel_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API gets gyroscope configurations like ODR, bandwidth,
* low power/ high performance mode, performance mode and range.
*
* @param[out] config : Structure instance of bmi2_gyro_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_gyro_config(struct bmi2_gyro_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API:
* 1) Gets the status of auxiliary interface enable.
* 2) Gets auxiliary interface configurations like I2C address, manual/auto
* mode enable, manual burst read length, AUX burst read length and AUX read
* address.
* 3) Gets ODR and offset.
*
* @param[out] config : Structure instance of bmi2_aux_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_aux_config(struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API gets gyroscope user-gain configurations like gain
* update value for x, y and z-axis.
*
* @param[out] config : Structure instance of bmi2_gyro_user_gain_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @verbatim
*----------------------------------------------------------------------------
* bmi2_gyro_user_gain_config|
* Structure parameters | Description
*-------------------------|--------------------------------------------------
* ratio_x | Gain update value for x-axis
* ------------------------|---------------------------------------------------
* ratio_y | Gain update value for y-axis
* ------------------------|---------------------------------------------------
* ratio_z | Gain update value for z-axis
*
* @endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_gyro_gain_update_config(struct bmi2_gyro_user_gain_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API gets the enable status of auxiliary interface.
*
* @param[out] config : Structure instance of bmi2_aux_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_aux_interface(struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API gets auxiliary configurations like manual/auto mode
* FCU write command enable and read burst length for both data and manual mode.
*
* @param[out] config : Structure instance of bmi2_aux_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_aux_interface_config(struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API gets read out offset and ODR of the auxiliary
* sensor.
*
* @param[out] config : Structure instance of bmi2_aux_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_aux_cfg(struct bmi2_aux_config *config, struct bmi2_dev *dev);
/*!
* @brief This internal API gets the saturation status for the gyroscope user
* gain update.
*
* @param[out] user_gain_stat : Stores the saturation status of the axes.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_gyro_gain_update_status(struct bmi2_gyr_user_gain_status *user_gain, struct bmi2_dev *dev);
/*!
* @brief This internal API is used to extract the output feature configuration
* details like page and start address from the look-up table.
*
* @param[out] feat_output : Structure that stores output feature
* configurations.
* @param[in] type : Type of feature or sensor.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Returns the feature found flag.
*
* @retval BMI2_FALSE : Feature not found
* BMI2_TRUE : Feature found
*/
static uint8_t extract_output_feat_config(struct bmi2_feature_config *feat_output,
uint8_t type,
const struct bmi2_dev *dev);
/*!
* @brief This internal API gets the cross sensitivity coefficient between
* gyroscope's X and Z axes.
*
* @param[out] cross_sense : Pointer to the stored cross sensitivity
* coefficient.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t get_gyro_cross_sense(int16_t *cross_sense, struct bmi2_dev *dev);
/*!
* @brief This internal API parses the accelerometer/gyroscope data.
*
* @param[out] data : Structure instance of bmi2_sens_axes_data.
* @param[in] reg_data : Data stored in the register.
*
* @return None
*
* @retval None
*/
static void get_acc_gyr_data(struct bmi2_sens_axes_data *data, const uint8_t *reg_data);
/*!
* @brief This internal API gets the re-mapped accelerometer/gyroscope data.
*
* @param[out] data : Structure instance of bmi2_sens_axes_data.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return None
*
* @retval None
*/
static void get_remapped_data(struct bmi2_sens_axes_data *data, const struct bmi2_dev *dev);
/*!
* @brief This internal API reads the user-defined bytes of data from the given
* register address of auxiliary sensor in manual mode.
*
* @param[in] reg_addr : AUX address from where data is read.
* @param[out] aux_data : Pointer to the stored auxiliary data.
* @param[in] len : Total bytes to be read.
* @param[in] burst_len : Bytes of data to be read in bursts.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t read_aux_data(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, uint8_t burst_len, struct bmi2_dev *dev);
/*!
* @brief This internal API checks the busy status of auxiliary sensor and sets
* the auxiliary register addresses when not busy.
*
* @param[in] reg_addr : Address in which AUX register address is
* set.
* @param[in] reg_data : Auxiliary register address to be set when AUX is
* not busy.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t set_if_aux_not_busy(uint8_t reg_addr, uint8_t reg_data, struct bmi2_dev *dev);
/*!
* @brief his internal API maps the actual burst read length with that of the
* register value set by user.
*
* @param[out] len : Actual burst length.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t map_read_len(uint8_t *len, const struct bmi2_dev *dev);
/*!
* @brief This internal API writes AUX write address and the user-defined bytes
* of data to the AUX sensor in manual mode.
*
* @note Change of BMI2_AUX_WR_ADDR is only allowed if AUX is not busy.
*
* @param[in] reg_addr : AUX address in which data is to be written.
* @param[in] reg_data : Data to be written
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note Change of BMI2_AUX_WR_ADDR is only allowed if AUX is not busy.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t write_aux_data(uint8_t reg_addr, uint8_t reg_data, struct bmi2_dev *dev);
/*!
* @brief This internal API maps/unmaps feature interrupts to that of interrupt
* pins.
*
* @param[in] int_pin : Interrupt pin selected.
* @param[in] feat_int : Type of feature interrupt to be mapped.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t map_feat_int(uint8_t *reg_data_array, enum bmi2_hw_int_pin int_pin, uint8_t int_mask);
/*!
* @brief This internal API computes the number of bytes of accelerometer FIFO
* data which is to be parsed in header-less mode.
*
* @param[out] start_idx : The start index for parsing data.
* @param[out] len : Number of bytes to be parsed.
* @param[out] skip_length : Number of bytes to skip if dummy frame is obtained
* @param[in] acc_count : Number of accelerometer frames to be read.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t parse_fifo_accel_len(uint16_t *start_idx,
uint16_t *len,
uint8_t *skip_length,
const uint16_t *acc_count,
const struct bmi2_fifo_frame *fifo);
/*!
* @brief This internal API is used to parse accelerometer data from the FIFO
* data in header mode.
*
* @param[out] acc : Structure instance of bmi2_sens_axes_data where
* the parsed accelerometer data bytes are stored.
* @param[in] accel_length : Number of accelerometer frames (x,y,z data).
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t extract_accel_header_mode(struct bmi2_sens_axes_data *acc,
uint16_t *accel_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse accelerometer data from the FIFO
* data in headerless mode.
*
* @param[out] acc : Structure instance of bmi2_sens_axes_data where
* the parsed accelerometer data bytes are stored.
* @param[in] accel_length : Number of accelerometer frames (x,y,z data).
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t extract_accel_headerless_mode(struct bmi2_sens_axes_data *acc,
uint16_t *accel_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to skip dummy frames in FIFO headerless mode
*
* @param[in] dummy_frame_header : Dummy frame header byte value in FIFO headerless mode
*
* ----------------------------------|--------------------
* dummy_frame_header | Applicable to
* ----------------------------------|--------------------
* BMI2_FIFO_HEADERLESS_DUMMY_ACC | ACCEL
* BMI2_FIFO_HEADERLESS_DUMMY_GYR | GYRO
* BMI2_FIFO_HEADERLESS_DUMMY_AUX | AUX
* ----------------------------------|--------------------
*
* @param[in] data_index : Index value of number of bytes parsed.
* @param[in] skip_length : Number of bytes to skip if dummy frame is obtained
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t check_dummy_frame(uint8_t dummy_frame_header,
uint16_t *data_index,
uint8_t skip_length,
const struct bmi2_fifo_frame *fifo);
/*!
* @brief This internal API is used to parse the accelerometer data from the
* FIFO data in header mode. It updates the current data
* byte to be parsed.
*
* @param[in,out] acc : Structure instance of bmi2_sens_axes_data where
* where the parsed data bytes are stored.
* @param[in,out] idx : Index value of number of bytes parsed.
* @param[in,out] acc_idx : Index value of accelerometer data (x,y,z axes)
* frame to be parsed.
* @param[in] frame : Either data is enabled by user in header-less
* mode or header frame value in header mode.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t unpack_accel_header_frame(struct bmi2_sens_axes_data *acc,
uint16_t *idx,
uint16_t *acc_idx,
uint8_t frame,
const struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse the accelerometer data from the
* FIFO data in header-less mode. It updates the current data
* byte to be parsed.
*
* @param[in,out] acc : Structure instance of bmi2_sens_axes_data where
* where the parsed data bytes are stored.
* @param[in,out] idx : Index value of number of bytes parsed.
* @param[in,out] acc_idx : Index value of accelerometer data (x,y,z axes)
* frame to be parsed.
* @param[in] frame : Either data is enabled by user in header-less
* mode or header frame value in header mode.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t unpack_accel_headerless_frame(struct bmi2_sens_axes_data *acc,
uint16_t *idx,
uint16_t *acc_idx,
uint8_t frame,
const struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse accelerometer data from the FIFO
* data.
*
* @param[out] acc : Structure instance of bmi2_sens_axes_data
* where the parsed data bytes are stored.
* @param[in] data_start_index : Index value of the accelerometer data bytes
* which is to be parsed from the FIFO data.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return None
* @retval None
*/
static void unpack_accel_data(struct bmi2_sens_axes_data *acc,
uint16_t data_start_index,
const struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API computes the number of bytes of gyroscope FIFO data
* which is to be parsed in header-less mode.
*
* @param[out] start_idx : The start index for parsing data.
* @param[out] len : Number of bytes to be parsed.
* @param[out] skip_length : Number of bytes to skip if dummy frame is obtained
* @param[in] gyr_count : Number of gyroscope frames to be read.
* @param[in] frame : Either data enabled by user in header-less
* mode or header frame value in header mode.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t parse_fifo_gyro_len(uint16_t *start_idx,
uint16_t *len,
uint8_t *skip_length,
const uint16_t *gyr_count,
const struct bmi2_fifo_frame *fifo);
/*!
* @brief This internal API is used to parse the gyroscope data from the FIFO
* data in header mode It updates the current data byte to
* be parsed.
*
* @param[in,out] gyr : Structure instance of bmi2_sens_axes_data.
* @param[in,out] idx : Index value of number of bytes parsed
* @param[in,out] gyr_idx : Index value of gyroscope data (x,y,z axes)
* frame to be parsed.
* @param[in] frame : Either data is enabled by user in header-less
* mode or header frame value in header mode.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t unpack_gyro_header_frame(struct bmi2_sens_axes_data *gyr,
uint16_t *idx,
uint16_t *gyr_idx,
uint8_t frame,
const struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse the gyroscope data from the FIFO
* data in header-less mode It updates the current data byte to
* be parsed.
*
* @param[in,out] gyr : Structure instance of bmi2_sens_axes_data.
* @param[in,out] idx : Index value of number of bytes parsed
* @param[in,out] gyr_idx : Index value of gyroscope data (x,y,z axes)
* frame to be parsed.
* @param[in] frame : Either data is enabled by user in header-less
* mode or header frame value in header mode.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t unpack_gyro_headerless_frame(struct bmi2_sens_axes_data *gyr,
uint16_t *idx,
uint16_t *gyr_idx,
uint8_t frame,
const struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse gyroscope data from the FIFO data.
*
* @param[out] gyr : Structure instance of bmi2_sens_axes_data where
* the parsed gyroscope data bytes are stored.
* @param[in] data_start_index : Index value of the gyroscope data bytes
* which is to be parsed from the FIFO data.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return None
* @retval None
*/
static void unpack_gyro_data(struct bmi2_sens_axes_data *gyr,
uint16_t data_start_index,
const struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse the gyroscope data from the
* FIFO data in header mode.
*
* @param[out] gyr : Structure instance of bmi2_sens_axes_data where
* the parsed gyroscope data bytes are stored.
* @param[in] gyro_length : Number of gyroscope frames (x,y,z data).
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t extract_gyro_header_mode(struct bmi2_sens_axes_data *gyr,
uint16_t *gyro_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse gyroscope data from the FIFO
* data in headerless mode.
*
* @param[out] gyr : Structure instance of bmi2_sens_axes_data where
* the parsed gyroscope data bytes are stored.
* @param[in] gyro_length : Number of gyroscope frames (x,y,z data).
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t extract_gyro_headerless_mode(struct bmi2_sens_axes_data *gyr,
uint16_t *gyro_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This API computes the number of bytes of auxiliary FIFO data
* which is to be parsed in header-less mode.
*
* @param[out] start_idx : The start index for parsing data.
* @param[out] len : Number of bytes to be parsed.
* @param[out] skip_length : Number of bytes to skip if dummy frame is obtained
* @param[in] aux_count : Number of accelerometer frames to be read.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t parse_fifo_aux_len(uint16_t *start_idx,
uint16_t *len,
uint8_t *skip_length,
const uint16_t *aux_count,
const struct bmi2_fifo_frame *fifo);
/*!
* @brief This API is used to parse auxiliary data from the FIFO data.
*
* @param[out] aux : Pointer to buffer where the parsed auxiliary data
* bytes are stored.
* @param[in] aux_length : Number of auxiliary frames (x,y,z data).
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t extract_aux_header_mode(struct bmi2_aux_fifo_data *aux,
uint16_t *aux_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This internal API is used to parse auxiliary data from the FIFO
* data in headerless mode.
*
* @param[out] aux : Structure instance of bmi2_sens_axes_data where
* the parsed auxiliary data bytes are stored.
* @param[in] aux_length : Number of auxiliary frames (x,y,z data).
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t extract_aux_headerless_mode(struct bmi2_aux_fifo_data *aux,
uint16_t *aux_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This API is used to parse the auxiliary data from the FIFO data in
* both header and header-less mode. It updates the current data byte to be
* parsed.
*
* @param[out] aux : Pointer to structure where the parsed auxiliary data
* bytes are stored.
* @param[in,out] idx : Index value of number of bytes parsed
* @param[in,out] aux_idx : Index value of auxiliary data (x,y,z axes)
* frame to be parsed
* @param[in] frame : Either data is enabled by user in header-less
* mode or header frame value in header mode.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t unpack_aux_frame(struct bmi2_aux_fifo_data *aux,
uint16_t *idx,
uint16_t *aux_idx,
uint8_t frame,
const struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* @brief This API is used to parse auxiliary data from the FIFO data.
*
* @param[out] aux : Pointer to structure where the parsed
* auxiliary data bytes are stored.
* @param[in] data_start_index : Index value of the auxiliary data bytes which
* is to be parsed from the FIFO data.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
*
* @return None
* @retval None
*/
static void unpack_aux_data(struct bmi2_aux_fifo_data *aux,
uint16_t data_start_index,
const struct bmi2_fifo_frame *fifo);
/*!
* @brief This internal API is used to reset the FIFO related configurations
* in the FIFO frame structure for the next FIFO read.
*
* @param[in, out] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
static int8_t reset_fifo_frame_structure(struct bmi2_fifo_frame *fifo, struct bmi2_dev *dev);
/*!
* @brief This internal API checks whether the FIFO data read is an empty frame.
* If empty frame, index is moved to the last byte.
*
* @param[in,out] data_index : The index of the current data to be parsed from
* FIFO data.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
*
* @return Result of API execution status
*
* @retval BMI2_OK - Success.
* @retval BMI2_W_FIFO_EMPTY - Warning : FIFO is empty
* @retval BMI2_W_PARTIAL_READ - Warning : There are more frames to be read
*/
static int8_t check_empty_fifo(uint16_t *data_index, const struct bmi2_fifo_frame *fifo);
/*!
* @brief This internal API is used to move the data index ahead of the
* current frame length parameter when unnecessary FIFO data appears while
* extracting the user specified data.
*
* @param[in,out] data_index : Index of the FIFO data which is to be
* moved ahead of the current frame length
* @param[in] current_frame_length : Number of bytes in the current frame.
* @param[in] fifo : Structure instance of bmi2_fifo_frame.
*
* @return Result of API execution status