Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / BoschSensortec / BMI270-Sensor-API / bmi270_maximum_fifo.c
blobc97e4bdd8b1255191f52cba5007c9c551024f47a
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"
45 /***************************************************************************/
47 /*! Global Variable
48 ****************************************************************************/
50 /*! @name Global array that stores the configuration file of BMI270 */
51 const uint8_t bmi270_maximum_fifo_config_file[] = {
52 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x1a, 0x00, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00,
53 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0x90, 0x32, 0x21, 0x2e, 0x59, 0xf5,
54 0x10, 0x30, 0x21, 0x2e, 0x6a, 0xf5, 0x1a, 0x24, 0x22, 0x00, 0x80, 0x2e, 0x3b, 0x00, 0xc8, 0x2e, 0x44, 0x47, 0x22,
55 0x00, 0x37, 0x00, 0xa4, 0x00, 0xff, 0x0f, 0xd1, 0x00, 0x07, 0xad, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1,
56 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00,
57 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x11, 0x24, 0xfc, 0xf5, 0x80, 0x30, 0x40, 0x42, 0x50, 0x50, 0x00, 0x30, 0x12, 0x24, 0xeb,
59 0x00, 0x03, 0x30, 0x00, 0x2e, 0xc1, 0x86, 0x5a, 0x0e, 0xfb, 0x2f, 0x21, 0x2e, 0xfc, 0xf5, 0x13, 0x24, 0x63, 0xf5,
60 0xe0, 0x3c, 0x48, 0x00, 0x22, 0x30, 0xf7, 0x80, 0xc2, 0x42, 0xe1, 0x7f, 0x3a, 0x25, 0xfc, 0x86, 0xf0, 0x7f, 0x41,
61 0x33, 0x98, 0x2e, 0xc2, 0xc4, 0xd6, 0x6f, 0xf1, 0x30, 0xf1, 0x08, 0xc4, 0x6f, 0x11, 0x24, 0xff, 0x03, 0x12, 0x24,
62 0x00, 0xfc, 0x61, 0x09, 0xa2, 0x08, 0x36, 0xbe, 0x2a, 0xb9, 0x13, 0x24, 0x38, 0x00, 0x64, 0xbb, 0xd1, 0xbe, 0x94,
63 0x0a, 0x71, 0x08, 0xd5, 0x42, 0x21, 0xbd, 0x91, 0xbc, 0xd2, 0x42, 0xc1, 0x42, 0x00, 0xb2, 0xfe, 0x82, 0x05, 0x2f,
64 0x50, 0x30, 0x21, 0x2e, 0x21, 0xf2, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0xf0, 0x6f, 0x02, 0x30, 0x02, 0x42, 0x20,
65 0x26, 0xe0, 0x6f, 0x02, 0x31, 0x03, 0x40, 0x9a, 0x0a, 0x02, 0x42, 0xf0, 0x37, 0x05, 0x2e, 0x5e, 0xf7, 0x10, 0x08,
66 0x12, 0x24, 0x1e, 0xf2, 0x80, 0x42, 0x83, 0x84, 0xf1, 0x7f, 0x0a, 0x25, 0x13, 0x30, 0x83, 0x42, 0x3b, 0x82, 0xf0,
67 0x6f, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x00, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x3e, 0x84,
68 0x00, 0x40, 0x40, 0x42, 0x7e, 0x82, 0xe1, 0x7f, 0xf2, 0x7f, 0x98, 0x2e, 0x6a, 0xd6, 0x21, 0x30, 0x23, 0x2e, 0x61,
69 0xf5, 0xeb, 0x2c, 0xe1, 0x6f
72 // The rest of this is not needed, avoid compiler errors due to pedantic settings
73 #if false
75 /*! @name Global array that stores the feature input configuration of BMI270 */
76 const struct bmi2_feature_config bmi270_maximum_fifo_feat_in[BMI270_MAXIMUM_FIFO_MAX_FEAT_IN] = {
80 /*! @name Global array that stores the feature output configuration */
81 const struct bmi2_feature_config bmi270_maximum_fifo_feat_out[BMI270_MAXIMUM_FIFO_MAX_FEAT_OUT] = {
85 /******************************************************************************/
87 /*! Local Function Prototypes
88 ******************************************************************************/
90 /*!
91 * @brief This internal API is used to validate the device pointer for
92 * null conditions.
94 * @param[in] dev : Structure instance of bmi2_dev.
96 * @return Result of API execution status
97 * @retval 0 -> Success
98 * @retval < 0 -> Fail
100 static int8_t null_ptr_check(const struct bmi2_dev *dev);
102 /***************************************************************************/
104 /*! User Interface Definitions
105 ****************************************************************************/
108 * @brief This API:
109 * 1) updates the device structure with address of the configuration file.
110 * 2) Initializes BMI270 sensor.
111 * 3) Writes the configuration file.
112 * 4) Updates the feature offset parameters in the device structure.
113 * 5) Updates the maximum number of pages, in the device structure.
115 int8_t bmi270_maximum_fifo_init(struct bmi2_dev *dev)
117 /* Variable to define result */
118 int8_t rslt;
120 /* Null-pointer check */
121 rslt = null_ptr_check(dev);
123 if (rslt == BMI2_OK)
125 /* Assign chip id of BMI270 */
126 dev->chip_id = BMI270_MAXIMUM_FIFO_CHIP_ID;
128 dev->config_size = sizeof(bmi270_maximum_fifo_config_file);
130 /* Enable the variant specific features if any */
131 dev->variant_feature = BMI2_GYRO_CROSS_SENS_ENABLE | BMI2_MAXIMUM_FIFO_VARIANT;
133 /* An extra dummy byte is read during SPI read */
134 if (dev->intf == BMI2_SPI_INTF)
136 dev->dummy_byte = 1;
138 else
140 dev->dummy_byte = 0;
143 /* If configuration file pointer is not assigned any address */
144 if (!dev->config_file_ptr)
146 /* Give the address of the configuration file array to
147 * the device pointer
149 dev->config_file_ptr = bmi270_maximum_fifo_config_file;
152 /* Initialize BMI2 sensor */
153 rslt = bmi2_sec_init(dev);
155 if (rslt == BMI2_OK)
157 /* Assign the offsets of the feature input
158 * configuration to the device structure
160 dev->feat_config = bmi270_maximum_fifo_feat_in;
162 /* Assign the offsets of the feature output to
163 * the device structure
165 dev->feat_output = bmi270_maximum_fifo_feat_out;
167 /* Assign the maximum number of pages to the
168 * device structure
170 dev->page_max = BMI270_MAXIMUM_FIFO_MAX_PAGE_NUM;
172 /* Assign maximum number of input sensors/
173 * features to device structure
175 dev->input_sens = BMI270_MAXIMUM_FIFO_MAX_FEAT_IN;
177 /* Assign maximum number of output sensors/
178 * features to device structure
180 dev->out_sens = BMI270_MAXIMUM_FIFO_MAX_FEAT_OUT;
182 /* Get the gyroscope cross axis sensitivity */
183 rslt = bmi2_get_gyro_cross_sense(dev);
187 return rslt;
190 /***************************************************************************/
192 /*! Local Function Definitions
193 ****************************************************************************/
196 * @brief This internal API is used to validate the device structure pointer for
197 * null conditions.
199 static int8_t null_ptr_check(const struct bmi2_dev *dev)
201 /* Variable to define result */
202 int8_t rslt = BMI2_OK;
204 if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL))
206 /* Device structure pointer is not valid */
207 rslt = BMI2_E_NULL_PTR;
210 return rslt;
212 #endif