Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / accgyro / accgyro_bmi270_maximum_fifo.c
blob96100ffab2b3074285968c2bea3bfd7bae8f989f
1 /**
2 * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
4 * BSD-3-Clause
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * @file bmi270_maximum_fifo.c
34 * @date 2020-11-04
35 * @version v2.63.1
39 /***************************************************************************/
41 /*! Header files
42 ****************************************************************************/
43 //#include "bmi270_maximum_fifo.h"
44 #include "platform.h"
46 /***************************************************************************/
48 /*! Global Variable
49 ****************************************************************************/
51 /*! @name Global array that stores the configuration file of BMI270 */
52 const uint8_t bmi270_maximum_fifo_config_file[] = {
53 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x1a, 0x00, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00,
54 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0x90, 0x32, 0x21, 0x2e, 0x59, 0xf5,
55 0x10, 0x30, 0x21, 0x2e, 0x6a, 0xf5, 0x1a, 0x24, 0x22, 0x00, 0x80, 0x2e, 0x3b, 0x00, 0xc8, 0x2e, 0x44, 0x47, 0x22,
56 0x00, 0x37, 0x00, 0xa4, 0x00, 0xff, 0x0f, 0xd1, 0x00, 0x07, 0xad, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1,
57 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00,
58 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x11, 0x24, 0xfc, 0xf5, 0x80, 0x30, 0x40, 0x42, 0x50, 0x50, 0x00, 0x30, 0x12, 0x24, 0xeb,
60 0x00, 0x03, 0x30, 0x00, 0x2e, 0xc1, 0x86, 0x5a, 0x0e, 0xfb, 0x2f, 0x21, 0x2e, 0xfc, 0xf5, 0x13, 0x24, 0x63, 0xf5,
61 0xe0, 0x3c, 0x48, 0x00, 0x22, 0x30, 0xf7, 0x80, 0xc2, 0x42, 0xe1, 0x7f, 0x3a, 0x25, 0xfc, 0x86, 0xf0, 0x7f, 0x41,
62 0x33, 0x98, 0x2e, 0xc2, 0xc4, 0xd6, 0x6f, 0xf1, 0x30, 0xf1, 0x08, 0xc4, 0x6f, 0x11, 0x24, 0xff, 0x03, 0x12, 0x24,
63 0x00, 0xfc, 0x61, 0x09, 0xa2, 0x08, 0x36, 0xbe, 0x2a, 0xb9, 0x13, 0x24, 0x38, 0x00, 0x64, 0xbb, 0xd1, 0xbe, 0x94,
64 0x0a, 0x71, 0x08, 0xd5, 0x42, 0x21, 0xbd, 0x91, 0xbc, 0xd2, 0x42, 0xc1, 0x42, 0x00, 0xb2, 0xfe, 0x82, 0x05, 0x2f,
65 0x50, 0x30, 0x21, 0x2e, 0x21, 0xf2, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0xf0, 0x6f, 0x02, 0x30, 0x02, 0x42, 0x20,
66 0x26, 0xe0, 0x6f, 0x02, 0x31, 0x03, 0x40, 0x9a, 0x0a, 0x02, 0x42, 0xf0, 0x37, 0x05, 0x2e, 0x5e, 0xf7, 0x10, 0x08,
67 0x12, 0x24, 0x1e, 0xf2, 0x80, 0x42, 0x83, 0x84, 0xf1, 0x7f, 0x0a, 0x25, 0x13, 0x30, 0x83, 0x42, 0x3b, 0x82, 0xf0,
68 0x6f, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x00, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x3e, 0x84,
69 0x00, 0x40, 0x40, 0x42, 0x7e, 0x82, 0xe1, 0x7f, 0xf2, 0x7f, 0x98, 0x2e, 0x6a, 0xd6, 0x21, 0x30, 0x23, 0x2e, 0x61,
70 0xf5, 0xeb, 0x2c, 0xe1, 0x6f
73 // The rest of this is not needed, avoid compiler errors due to pedantic settings
74 #if false
76 /*! @name Global array that stores the feature input configuration of BMI270 */
77 const struct bmi2_feature_config bmi270_maximum_fifo_feat_in[BMI270_MAXIMUM_FIFO_MAX_FEAT_IN] = {
81 /*! @name Global array that stores the feature output configuration */
82 const struct bmi2_feature_config bmi270_maximum_fifo_feat_out[BMI270_MAXIMUM_FIFO_MAX_FEAT_OUT] = {
86 /******************************************************************************/
88 /*! Local Function Prototypes
89 ******************************************************************************/
91 /*!
92 * @brief This internal API is used to validate the device pointer for
93 * null conditions.
95 * @param[in] dev : Structure instance of bmi2_dev.
97 * @return Result of API execution status
98 * @retval 0 -> Success
99 * @retval < 0 -> Fail
101 static int8_t null_ptr_check(const struct bmi2_dev *dev);
103 /***************************************************************************/
105 /*! User Interface Definitions
106 ****************************************************************************/
109 * @brief This API:
110 * 1) updates the device structure with address of the configuration file.
111 * 2) Initializes BMI270 sensor.
112 * 3) Writes the configuration file.
113 * 4) Updates the feature offset parameters in the device structure.
114 * 5) Updates the maximum number of pages, in the device structure.
116 int8_t bmi270_maximum_fifo_init(struct bmi2_dev *dev)
118 /* Variable to define result */
119 int8_t rslt;
121 /* Null-pointer check */
122 rslt = null_ptr_check(dev);
124 if (rslt == BMI2_OK)
126 /* Assign chip id of BMI270 */
127 dev->chip_id = BMI270_MAXIMUM_FIFO_CHIP_ID;
129 dev->config_size = sizeof(bmi270_maximum_fifo_config_file);
131 /* Enable the variant specific features if any */
132 dev->variant_feature = BMI2_GYRO_CROSS_SENS_ENABLE | BMI2_MAXIMUM_FIFO_VARIANT;
134 /* An extra dummy byte is read during SPI read */
135 if (dev->intf == BMI2_SPI_INTF)
137 dev->dummy_byte = 1;
139 else
141 dev->dummy_byte = 0;
144 /* If configuration file pointer is not assigned any address */
145 if (!dev->config_file_ptr)
147 /* Give the address of the configuration file array to
148 * the device pointer
150 dev->config_file_ptr = bmi270_maximum_fifo_config_file;
153 /* Initialize BMI2 sensor */
154 rslt = bmi2_sec_init(dev);
156 if (rslt == BMI2_OK)
158 /* Assign the offsets of the feature input
159 * configuration to the device structure
161 dev->feat_config = bmi270_maximum_fifo_feat_in;
163 /* Assign the offsets of the feature output to
164 * the device structure
166 dev->feat_output = bmi270_maximum_fifo_feat_out;
168 /* Assign the maximum number of pages to the
169 * device structure
171 dev->page_max = BMI270_MAXIMUM_FIFO_MAX_PAGE_NUM;
173 /* Assign maximum number of input sensors/
174 * features to device structure
176 dev->input_sens = BMI270_MAXIMUM_FIFO_MAX_FEAT_IN;
178 /* Assign maximum number of output sensors/
179 * features to device structure
181 dev->out_sens = BMI270_MAXIMUM_FIFO_MAX_FEAT_OUT;
183 /* Get the gyroscope cross axis sensitivity */
184 rslt = bmi2_get_gyro_cross_sense(dev);
188 return rslt;
191 /***************************************************************************/
193 /*! Local Function Definitions
194 ****************************************************************************/
197 * @brief This internal API is used to validate the device structure pointer for
198 * null conditions.
200 static int8_t null_ptr_check(const struct bmi2_dev *dev)
202 /* Variable to define result */
203 int8_t rslt = BMI2_OK;
205 if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL))
207 /* Device structure pointer is not valid */
208 rslt = BMI2_E_NULL_PTR;
211 return rslt;
213 #endif