Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BNO055.cpp
00001 /* 00002 * 00003 **************************************************************************** 00004 * Copyright (C) 2015 - 2016 Bosch Sensortec GmbH 00005 * 00006 * File : bno055.c 00007 * 00008 * Date : 2016/03/14 00009 * 00010 * Revision : 2.0.3 $ 00011 * 00012 * Usage: Sensor Driver file for BNO055 sensor 00013 * 00014 **************************************************************************** 00015 * \section License 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * 00020 * Redistributions of source code must retain the above copyright 00021 * notice, this list of conditions and the following disclaimer. 00022 * 00023 * Redistributions in binary form must reproduce the above copyright 00024 * notice, this list of conditions and the following disclaimer in the 00025 * documentation and/or other materials provided with the distribution. 00026 * 00027 * Neither the name of the copyright holder nor the names of the 00028 * contributors may be used to endorse or promote products derived from 00029 * this software without specific prior written permission. 00030 * 00031 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00032 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00033 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00034 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00035 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER 00036 * OR CONTRIBUTORS BE LIABLE FOR ANY 00037 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 00038 * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, 00039 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00040 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00041 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00042 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00043 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00044 * ANY WAY OUT OF THE USE OF THIS 00045 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00046 * 00047 * The information provided is believed to be accurate and reliable. 00048 * The copyright holder assumes no responsibility 00049 * for the consequences of use 00050 * of such information nor for any infringement of patents or 00051 * other rights of third parties which may result from its use. 00052 * No license is granted by implication or otherwise under any patent or 00053 * patent rights of the copyright holder. 00054 **************************************************************************/ 00055 00056 /*********************************************************/ 00057 /* INCLUDES */ 00058 /*******************************************************/ 00059 #include "BNO055.h" 00060 /*! file <BNO055 > 00061 brief <Sensor driver for BNO055> */ 00062 /* STRUCTURE DEFINITIONS */ 00063 /*static*/ struct bno055_t *p_bno055; 00064 00065 /* LOCAL FUNCTIONS */ 00066 /*! 00067 * @brief 00068 * This API is used for initialize 00069 * bus read, bus write function pointers,device 00070 * address,accel revision id, gyro revision id 00071 * mag revision id, software revision id, boot loader 00072 * revision id and page id 00073 * 00074 * @param bno055 - structure pointer 00075 * 00076 * 00077 * @return results of bus communication function 00078 * @retval 0 -> BNO055_SUCCESS 00079 * @retval 1 -> BNO055_ERROR 00080 * 00081 * @note While changing the parameter of the bno055_t 00082 * consider the following point: 00083 * Changing the reference value of the parameter 00084 * will changes the local copy or local reference 00085 * make sure your changes will not 00086 * affect the reference value of the parameter 00087 * (Better case don't change the reference value of the parameter) 00088 */ 00089 BNO055_RETURN_FUNCTION_TYPE bno055_init(struct bno055_t *bno055) 00090 { 00091 /* Variable used to return value of 00092 communication routine*/ 00093 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00094 u8 data_u8 = BNO055_INIT_VALUE; 00095 u8 bno055_page_zero_u8 = BNO055_PAGE_ZERO; 00096 /* Array holding the Software revision id 00097 */ 00098 u8 a_SW_ID_u8[BNO055_REV_ID_SIZE] = { 00099 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 00100 /* stuct parameters are assign to bno055*/ 00101 p_bno055 = bno055; 00102 /* Write the default page as zero*/ 00103 com_rslt = p_bno055->BNO055_BUS_WRITE_FUNC 00104 (p_bno055->dev_addr, 00105 BNO055_PAGE_ID_REG, &bno055_page_zero_u8, BNO055_GEN_READ_WRITE_LENGTH); 00106 /* Read the chip id of the sensor from page 00107 zero 0x00 register*/ 00108 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 00109 (p_bno055->dev_addr, 00110 BNO055_CHIP_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00111 p_bno055->chip_id = data_u8; 00112 /* Read the accel revision id from page 00113 zero 0x01 register*/ 00114 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 00115 (p_bno055->dev_addr, 00116 BNO055_ACCEL_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00117 p_bno055->accel_rev_id = data_u8; 00118 /* Read the mag revision id from page 00119 zero 0x02 register*/ 00120 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 00121 (p_bno055->dev_addr, 00122 BNO055_MAG_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00123 p_bno055->mag_rev_id = data_u8; 00124 /* Read the gyro revision id from page 00125 zero 0x02 register*/ 00126 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 00127 (p_bno055->dev_addr, 00128 BNO055_GYRO_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00129 p_bno055->gyro_rev_id = data_u8; 00130 /* Read the boot loader revision from page 00131 zero 0x06 register*/ 00132 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 00133 (p_bno055->dev_addr, 00134 BNO055_BL_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00135 p_bno055->bl_rev_id = data_u8; 00136 /* Read the software revision id from page 00137 zero 0x04 and 0x05 register( 2 bytes of data)*/ 00138 com_rslt += p_bno055->BNO055_BUS_READ_FUNC(p_bno055->dev_addr, 00139 BNO055_SW_REV_ID_LSB_REG, 00140 a_SW_ID_u8, BNO055_LSB_MSB_READ_LENGTH); 00141 a_SW_ID_u8[BNO055_SW_ID_LSB] = BNO055_GET_BITSLICE( 00142 a_SW_ID_u8[BNO055_SW_ID_LSB], 00143 BNO055_SW_REV_ID_LSB); 00144 p_bno055->sw_rev_id = (u16) 00145 ((((u32)((u8)a_SW_ID_u8[BNO055_SW_ID_MSB])) << 00146 BNO055_SHIFT_EIGHT_BITS) | (a_SW_ID_u8[BNO055_SW_ID_LSB])); 00147 /* Read the page id from the register 0x07*/ 00148 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 00149 (p_bno055->dev_addr, 00150 BNO055_PAGE_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00151 p_bno055->page_id = data_u8; 00152 00153 return com_rslt; 00154 } 00155 /*! 00156 * @brief 00157 * This API gives data to the given register and 00158 * the data is written in the corresponding register address 00159 * 00160 * @param addr_u8 : Address of the register 00161 * @param data_u8 : Data to be written to the register 00162 * @param len_u8 : Length of the Data 00163 * 00164 * @return results of bus communication function 00165 * @retval 0 -> BNO055_SUCCESS 00166 * @retval 1 -> BNO055_ERROR 00167 * 00168 * 00169 */ 00170 BNO055_RETURN_FUNCTION_TYPE bno055_write_register(u8 addr_u8, 00171 u8 *data_u8, u8 len_u8) 00172 { 00173 /* Variable used to return value of 00174 communication routine*/ 00175 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00176 /* Check the struct p_bno055 is empty */ 00177 if (p_bno055 == BNO055_INIT_VALUE) { 00178 return BNO055_E_NULL_PTR; 00179 } else { 00180 /* Write the values of respective given register */ 00181 com_rslt = p_bno055->BNO055_BUS_WRITE_FUNC 00182 (p_bno055->dev_addr, addr_u8, data_u8, len_u8); 00183 } 00184 return com_rslt; 00185 } 00186 /*! 00187 * @brief This API reads the data from 00188 * the given register address 00189 * 00190 * @param addr_u8 : Address of the register 00191 * @param data_u8 : address of the variable, 00192 * read value will be kept 00193 * @param len_u8 : Length of the data 00194 * 00195 * 00196 * @return results of bus communication function 00197 * @retval 0 -> BNO055_SUCCESS 00198 * @retval 1 -> BNO055_ERROR 00199 * 00200 */ 00201 BNO055_RETURN_FUNCTION_TYPE bno055_read_register(u8 addr_u8, 00202 u8 *data_u8, u8 len_u8) 00203 { 00204 /* Variable used to return value of 00205 communication routine*/ 00206 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00207 /* Check the struct p_bno055 is empty */ 00208 if (p_bno055 == BNO055_INIT_VALUE) { 00209 return BNO055_E_NULL_PTR; 00210 } else { 00211 /* Read the value from given register*/ 00212 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00213 (p_bno055->dev_addr, addr_u8, data_u8, len_u8); 00214 } 00215 return com_rslt; 00216 } 00217 /*! 00218 * @brief This API reads chip id 00219 * from register 0x00 it is a byte of data 00220 * 00221 * 00222 * @param chip_id_u8 : The chip id value 0xA0 00223 * 00224 * @return results of bus communication function 00225 * @retval 0 -> BNO055_SUCCESS 00226 * @retval 1 -> BNO055_ERROR 00227 */ 00228 BNO055_RETURN_FUNCTION_TYPE bno055_read_chip_id(u8 *chip_id_u8) 00229 { 00230 /* Variable used to return value of 00231 communication routine*/ 00232 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00233 u8 data_u8 = BNO055_INIT_VALUE; 00234 s8 stat_s8 = BNO055_ERROR; 00235 /* Check the struct p_bno055 is empty */ 00236 if (p_bno055 == BNO055_INIT_VALUE) { 00237 return BNO055_E_NULL_PTR; 00238 } else { 00239 /*condition check for page, chip id is 00240 available in the page zero*/ 00241 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00242 /* Write the page zero*/ 00243 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00244 if ((stat_s8 == BNO055_SUCCESS) || 00245 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00246 /* Read the chip id*/ 00247 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00248 (p_bno055->dev_addr, 00249 BNO055_CHIP_ID_REG, &data_u8, 00250 BNO055_GEN_READ_WRITE_LENGTH); 00251 *chip_id_u8 = data_u8; 00252 } else { 00253 com_rslt = BNO055_ERROR; 00254 } 00255 } 00256 return com_rslt; 00257 } 00258 /*! 00259 * @brief This API reads software revision id 00260 * from register 0x04 and 0x05 it is a two byte of data 00261 * 00262 * @param sw_id_u8 : The SW revision id 00263 * 00264 * @return results of bus communication function 00265 * @retval 0 -> BNO055_SUCCESS 00266 * @retval 1 -> BNO055_ERROR 00267 * 00268 * 00269 */ 00270 BNO055_RETURN_FUNCTION_TYPE bno055_read_sw_rev_id(u16 *sw_id_u8) 00271 { 00272 /* Variable used to return value of 00273 communication routine*/ 00274 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00275 /* array having the software revision id 00276 data_u8[0] - LSB 00277 data_u8[1] - MSB*/ 00278 u8 data_u8[BNO055_REV_ID_SIZE] = {BNO055_INIT_VALUE, 00279 BNO055_INIT_VALUE}; 00280 s8 stat_s8 = BNO055_ERROR; 00281 /* Check the struct p_bno055 is empty*/ 00282 if (p_bno055 == BNO055_INIT_VALUE) { 00283 return BNO055_E_NULL_PTR; 00284 } else { 00285 /*condition check for page, chip id is 00286 available in the page zero*/ 00287 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00288 /* Write the page zero*/ 00289 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00290 if ((stat_s8 == BNO055_SUCCESS) || 00291 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00292 /* Read the two byte value of software 00293 revision id*/ 00294 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00295 (p_bno055->dev_addr, 00296 BNO055_SW_REV_ID_LSB_REG, 00297 data_u8, BNO055_LSB_MSB_READ_LENGTH); 00298 data_u8[BNO055_SW_ID_LSB] = 00299 BNO055_GET_BITSLICE(data_u8[BNO055_SW_ID_LSB], 00300 BNO055_SW_REV_ID_LSB); 00301 *sw_id_u8 = (u16) 00302 ((((u32)((u8)data_u8[BNO055_SW_ID_MSB])) << 00303 BNO055_SHIFT_EIGHT_BITS) 00304 | (data_u8[BNO055_SW_ID_LSB])); 00305 } else { 00306 com_rslt = BNO055_ERROR; 00307 } 00308 } 00309 return com_rslt; 00310 } 00311 /*! 00312 * @brief This API reads page id 00313 * from register 0x07 it is a byte of data 00314 * 00315 * 00316 * @param page_id_u8 : The value of page id 00317 * 00318 * BNO055_PAGE_ZERO -> 0x00 00319 * BNO055_PAGE_ONE -> 0x01 00320 * 00321 * @return results of bus communication function 00322 * @retval 0 -> BNO055_SUCCESS 00323 * @retval 1 -> BNO055_ERROR 00324 * 00325 * 00326 */ 00327 BNO055_RETURN_FUNCTION_TYPE bno055_read_page_id(u8 *page_id_u8) 00328 { 00329 /* Variable used to return value of 00330 communication routine*/ 00331 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00332 u8 data_u8 = BNO055_INIT_VALUE; 00333 /* Check the struct p_bno055 is empty */ 00334 if (p_bno055 == BNO055_INIT_VALUE) { 00335 return BNO055_E_NULL_PTR; 00336 } else { 00337 /* Read the page id form 0x07*/ 00338 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00339 (p_bno055->dev_addr, 00340 BNO055_PAGE_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00341 if (com_rslt == BNO055_SUCCESS) { 00342 data_u8 = BNO055_GET_BITSLICE(data_u8, 00343 BNO055_PAGE_ID); 00344 *page_id_u8 = data_u8; 00345 p_bno055->page_id = data_u8; 00346 } else { 00347 com_rslt = BNO055_ERROR; 00348 } 00349 } 00350 return com_rslt; 00351 } 00352 /*! 00353 * @brief This API used to write 00354 * the page id register 0x07 00355 * 00356 * @param page_id_u8 : The value of page id 00357 * 00358 * BNO055_PAGE_ZERO -> 0x00 00359 * BNO055_PAGE_ONE -> 0x01 00360 * 00361 * @return results of bus communication function 00362 * @retval 0 -> BNO055_SUCCESS 00363 * @retval 1 -> BNO055_ERROR 00364 * 00365 * 00366 */ 00367 BNO055_RETURN_FUNCTION_TYPE bno055_write_page_id(u8 page_id_u8) 00368 { 00369 /* Variable used to return value of 00370 communication routine*/ 00371 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00372 u8 data_u8r = BNO055_INIT_VALUE; 00373 /* Check the struct p_bno055 is empty */ 00374 if (p_bno055 == BNO055_INIT_VALUE) { 00375 return BNO055_E_NULL_PTR; 00376 } else { 00377 /* Read the current page*/ 00378 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00379 (p_bno055->dev_addr, 00380 BNO055_PAGE_ID_REG, &data_u8r, 00381 BNO055_GEN_READ_WRITE_LENGTH); 00382 /* Check condition for communication BNO055_SUCCESS*/ 00383 if (com_rslt == BNO055_SUCCESS) { 00384 data_u8r = BNO055_SET_BITSLICE(data_u8r, 00385 BNO055_PAGE_ID, page_id_u8); 00386 /* Write the page id*/ 00387 com_rslt += p_bno055->BNO055_BUS_WRITE_FUNC 00388 (p_bno055->dev_addr, 00389 BNO055_PAGE_ID_REG, 00390 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 00391 if (com_rslt == BNO055_SUCCESS) 00392 p_bno055->page_id = page_id_u8; 00393 } else { 00394 com_rslt = BNO055_ERROR; 00395 } 00396 } 00397 return com_rslt; 00398 } 00399 /*! 00400 * @brief This API reads accel revision id 00401 * from register 0x01 it is a byte of value 00402 * 00403 * @param accel_rev_id_u8 : The accel revision id 0xFB 00404 * 00405 * @return results of bus communication function 00406 * @retval 0 -> BNO055_SUCCESS 00407 * @retval 1 -> BNO055_ERROR 00408 * 00409 * 00410 */ 00411 BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_rev_id( 00412 u8 *accel_rev_id_u8) 00413 { 00414 /* Variable used to return value of 00415 communication routine*/ 00416 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00417 u8 data_u8 = BNO055_INIT_VALUE; 00418 s8 stat_s8 = BNO055_ERROR; 00419 /* Check the struct p_bno055 is empty */ 00420 if (p_bno055 == BNO055_INIT_VALUE) { 00421 return BNO055_E_NULL_PTR; 00422 } else { 00423 /*condition check for page, chip id is 00424 available in the page zero*/ 00425 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00426 /* Write the page zero*/ 00427 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00428 if ((stat_s8 == BNO055_SUCCESS) || 00429 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00430 /* Read the accel revision id */ 00431 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00432 (p_bno055->dev_addr, 00433 BNO055_ACCEL_REV_ID_REG, 00434 &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00435 *accel_rev_id_u8 = data_u8; 00436 } else { 00437 com_rslt = BNO055_ERROR; 00438 } 00439 } 00440 return com_rslt; 00441 } 00442 /*! 00443 * @brief This API reads mag revision id 00444 * from register 0x02 it is a byte of value 00445 * 00446 * @param mag_rev_id_u8 : The mag revision id 0x32 00447 * 00448 * @return results of bus communication function 00449 * @retval 0 -> BNO055_SUCCESS 00450 * @retval 1 -> BNO055_ERROR 00451 * 00452 * 00453 */ 00454 BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_rev_id( 00455 u8 *mag_rev_id_u8) 00456 { 00457 /* Variable used to return value of 00458 communication routine*/ 00459 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00460 u8 data_u8 = BNO055_INIT_VALUE; 00461 s8 stat_s8 = BNO055_ERROR; 00462 /* Check the struct p_bno055 is empty */ 00463 if (p_bno055 == BNO055_INIT_VALUE) { 00464 return BNO055_E_NULL_PTR; 00465 } else { 00466 /*condition check for page, chip id is 00467 available in the page zero*/ 00468 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00469 /* Write the page zero*/ 00470 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00471 if ((stat_s8 == BNO055_SUCCESS) || 00472 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00473 /* Read the mag revision id */ 00474 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00475 (p_bno055->dev_addr, 00476 BNO055_MAG_REV_ID_REG, 00477 &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00478 *mag_rev_id_u8 = data_u8; 00479 } else { 00480 com_rslt = BNO055_ERROR; 00481 } 00482 } 00483 return com_rslt; 00484 } 00485 /*! 00486 * @brief This API reads gyro revision id 00487 * from register 0x03 it is a byte of value 00488 * 00489 * @param gyro_rev_id_u8 : The gyro revision id 0xF0 00490 * 00491 * 00492 * 00493 * @return results of bus communication function 00494 * @retval 0 -> BNO055_SUCCESS 00495 * @retval 1 -> BNO055_ERROR 00496 * 00497 * 00498 */ 00499 BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_rev_id( 00500 u8 *gyro_rev_id_u8) 00501 { 00502 /* Variable used to return value of 00503 communication routine*/ 00504 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00505 u8 data_u8 = BNO055_INIT_VALUE; 00506 s8 stat_s8 = BNO055_ERROR; 00507 /* Check the struct p_bno055 is empty */ 00508 if (p_bno055 == BNO055_INIT_VALUE) { 00509 return BNO055_E_NULL_PTR; 00510 } else { 00511 /*condition check for page, chip id is 00512 available in the page zero*/ 00513 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00514 /* Write the page zero*/ 00515 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00516 if ((stat_s8 == BNO055_SUCCESS) || 00517 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00518 /* Read the gyro revision id */ 00519 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00520 (p_bno055->dev_addr, 00521 BNO055_GYRO_REV_ID_REG, 00522 &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00523 *gyro_rev_id_u8 = data_u8; 00524 } else { 00525 com_rslt = BNO055_ERROR; 00526 } 00527 } 00528 return com_rslt; 00529 } 00530 /*! 00531 * @brief This API used to read boot loader revision id 00532 * from register 0x06 it is a byte of value 00533 * 00534 * @param bl_rev_id_u8 : The boot loader revision id 00535 * 00536 * 00537 * @return results of bus communication function 00538 * @retval 0 -> BNO055_SUCCESS 00539 * @retval 1 -> BNO055_ERROR 00540 * 00541 * 00542 */ 00543 BNO055_RETURN_FUNCTION_TYPE bno055_read_bl_rev_id( 00544 u8 *bl_rev_id_u8) 00545 { 00546 /* Variable used to return value of 00547 communication routine*/ 00548 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00549 u8 data_u8 = BNO055_INIT_VALUE; 00550 s8 stat_s8 = BNO055_ERROR; 00551 /* Check the struct p_bno055 is empty */ 00552 if (p_bno055 == BNO055_INIT_VALUE) { 00553 return BNO055_E_NULL_PTR; 00554 } else { 00555 /*condition check for page, chip id is 00556 available in the page zero*/ 00557 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00558 /* Write the page zero*/ 00559 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00560 if ((stat_s8 == BNO055_SUCCESS) || 00561 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00562 /* Read the boot loader revision id */ 00563 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00564 (p_bno055->dev_addr, 00565 BNO055_BL_REV_ID_REG, 00566 &data_u8, BNO055_GEN_READ_WRITE_LENGTH); 00567 *bl_rev_id_u8 = data_u8; 00568 } else { 00569 com_rslt = BNO055_ERROR; 00570 } 00571 } 00572 return com_rslt; 00573 } 00574 /*! 00575 * @brief This API reads acceleration data X values 00576 * from register 0x08 and 0x09 it is a two byte data 00577 * 00578 * 00579 * 00580 * 00581 * @param accel_x_s16 : The X raw data 00582 * 00583 * 00584 * 00585 * @return results of bus communication function 00586 * @retval 0 -> BNO055_SUCCESS 00587 * @retval 1 -> BNO055_ERROR 00588 * 00589 * 00590 */ 00591 BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_x(s16 *accel_x_s16) 00592 { 00593 /* Variable used to return value of 00594 communication routine*/ 00595 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00596 /* Array holding the accel x value 00597 data_u8[BNO055_SENSOR_DATA_LSB] - x-LSB 00598 data_u8[BNO055_SENSOR_DATA_MSB] - x-MSB 00599 */ 00600 u8 data_u8[BNO055_ACCEL_DATA_SIZE] = {BNO055_INIT_VALUE, 00601 BNO055_INIT_VALUE}; 00602 s8 stat_s8 = BNO055_ERROR; 00603 /* Check the struct p_bno055 is empty */ 00604 if (p_bno055 == BNO055_INIT_VALUE) { 00605 return BNO055_E_NULL_PTR; 00606 } else { 00607 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00608 /* Write the page zero*/ 00609 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00610 if ((stat_s8 == BNO055_SUCCESS) || 00611 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00612 /* Read the accel x axis two byte value*/ 00613 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00614 (p_bno055->dev_addr, 00615 BNO055_ACCEL_DATA_X_LSB_VALUEX_REG, 00616 data_u8, BNO055_LSB_MSB_READ_LENGTH); 00617 data_u8[BNO055_SENSOR_DATA_LSB] = 00618 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 00619 BNO055_ACCEL_DATA_X_LSB_VALUEX); 00620 data_u8[BNO055_SENSOR_DATA_MSB] = 00621 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 00622 BNO055_ACCEL_DATA_X_MSB_VALUEX); 00623 *accel_x_s16 = (s16)((((s32) 00624 (s8)(data_u8[BNO055_SENSOR_DATA_MSB])) << 00625 (BNO055_SHIFT_EIGHT_BITS)) 00626 | (data_u8[BNO055_SENSOR_DATA_LSB])); 00627 } else { 00628 com_rslt = BNO055_ERROR; 00629 } 00630 } 00631 return com_rslt; 00632 } 00633 /*! 00634 * @brief This API reads acceleration data Y values 00635 * from register 0x0A and 0x0B it is a two byte data 00636 * 00637 * 00638 * 00639 * 00640 * @param accel_y_s16 : The Y raw data 00641 * 00642 * 00643 * 00644 * @return results of bus communication function 00645 * @retval 0 -> BNO055_SUCCESS 00646 * @retval 1 -> BNO055_ERROR 00647 * 00648 * 00649 */ 00650 BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_y(s16 *accel_y_s16) 00651 { 00652 /* Variable used to return value of 00653 communication routine*/ 00654 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00655 /* Array holding the accel y value 00656 data_u8[BNO055_SENSOR_DATA_LSB] - y-LSB 00657 data_u8[BNO055_SENSOR_DATA_MSB] - y-MSB 00658 */ 00659 u8 data_u8[BNO055_ACCEL_DATA_SIZE] = {BNO055_INIT_VALUE, 00660 BNO055_INIT_VALUE}; 00661 s8 stat_s8 = BNO055_ERROR; 00662 /* Check the struct p_bno055 is empty */ 00663 if (p_bno055 == BNO055_INIT_VALUE) { 00664 return BNO055_E_NULL_PTR; 00665 } else { 00666 /*condition check for page, chip id is 00667 available in the page zero*/ 00668 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00669 /* Write the page zero*/ 00670 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00671 if ((stat_s8 == BNO055_SUCCESS) || 00672 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00673 /* Read the accel y axis two byte value*/ 00674 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00675 (p_bno055->dev_addr, 00676 BNO055_ACCEL_DATA_Y_LSB_VALUEY_REG, 00677 data_u8, BNO055_LSB_MSB_READ_LENGTH); 00678 data_u8[BNO055_SENSOR_DATA_LSB] = 00679 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 00680 BNO055_ACCEL_DATA_Y_LSB_VALUEY); 00681 data_u8[BNO055_SENSOR_DATA_MSB] = 00682 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 00683 BNO055_ACCEL_DATA_Y_MSB_VALUEY); 00684 *accel_y_s16 = (s16)((((s32) 00685 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 00686 BNO055_SHIFT_EIGHT_BITS) | 00687 (data_u8[BNO055_SENSOR_DATA_LSB])); 00688 } else { 00689 com_rslt = BNO055_ERROR; 00690 } 00691 } 00692 return com_rslt; 00693 } 00694 /*! 00695 * @brief This API reads acceleration data z values 00696 * from register 0x0C and 0x0D it is a two byte data 00697 * 00698 * 00699 * 00700 * 00701 * @param accel_z_s16 : The z raw data 00702 * 00703 * 00704 * 00705 * @return results of bus communication function 00706 * @retval 0 -> BNO055_SUCCESS 00707 * @retval 1 -> BNO055_ERROR 00708 * 00709 * 00710 */ 00711 BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_z(s16 *accel_z_s16) 00712 { 00713 /* Variable used to return value of 00714 communication routine*/ 00715 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00716 /* Array holding the accel z value 00717 data_u8[BNO055_SENSOR_DATA_LSB] - z-LSB 00718 data_u8[BNO055_SENSOR_DATA_MSB] - z-MSB 00719 */ 00720 u8 data_u8[BNO055_ACCEL_DATA_SIZE] = {BNO055_INIT_VALUE, 00721 BNO055_INIT_VALUE}; 00722 s8 stat_s8 = BNO055_ERROR; 00723 /* Check the struct p_bno055 is empty */ 00724 if (p_bno055 == BNO055_INIT_VALUE) { 00725 return BNO055_E_NULL_PTR; 00726 } else { 00727 /*condition check for page, chip id is 00728 available in the page zero*/ 00729 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00730 /* Write the page zero*/ 00731 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00732 if ((stat_s8 == BNO055_SUCCESS) || 00733 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00734 /* Read the accel z axis two byte value*/ 00735 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00736 (p_bno055->dev_addr, 00737 BNO055_ACCEL_DATA_Z_LSB_VALUEZ_REG, 00738 data_u8, BNO055_LSB_MSB_READ_LENGTH); 00739 data_u8[BNO055_SENSOR_DATA_LSB] = 00740 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 00741 BNO055_ACCEL_DATA_Z_LSB_VALUEZ); 00742 data_u8[BNO055_SENSOR_DATA_MSB] = 00743 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 00744 BNO055_ACCEL_DATA_Z_MSB_VALUEZ); 00745 *accel_z_s16 = (s16)((((s32) 00746 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 00747 BNO055_SHIFT_EIGHT_BITS) | 00748 (data_u8[BNO055_SENSOR_DATA_LSB])); 00749 } else { 00750 com_rslt = BNO055_ERROR; 00751 } 00752 } 00753 return com_rslt; 00754 } 00755 /*! 00756 * @brief This API reads acceleration data xyz values 00757 * from register 0x08 to 0x0D it is a six byte data 00758 * 00759 * 00760 * @param accel : The value of accel xyz data 00761 * 00762 * Parameter | result 00763 * --------- | ----------------- 00764 * x | The accel x data 00765 * y | The accel y data 00766 * z | The accel z data 00767 * 00768 * 00769 * 00770 * @return results of bus communication function 00771 * @retval 0 -> BNO055_SUCCESS 00772 * @retval 1 -> BNO055_ERROR 00773 * 00774 */ 00775 BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_xyz( 00776 struct bno055_accel_t *accel) 00777 { 00778 /* Variable used to return value of 00779 communication routine*/ 00780 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00781 /* Array holding the accel xyz value 00782 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] - x->LSB 00783 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] - x->MSB 00784 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] - y->MSB 00785 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] - y->MSB 00786 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] - z->MSB 00787 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] - z->MSB 00788 */ 00789 u8 data_u8[BNO055_ACCEL_XYZ_DATA_SIZE] = { 00790 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 00791 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 00792 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 00793 s8 stat_s8 = BNO055_ERROR; 00794 /* Check the struct p_bno055 is empty */ 00795 if (p_bno055 == BNO055_INIT_VALUE) { 00796 return BNO055_E_NULL_PTR; 00797 } else { 00798 /*condition check for page, chip id is 00799 available in the page zero*/ 00800 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00801 /* Write the page zero*/ 00802 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00803 if ((stat_s8 == BNO055_SUCCESS) || 00804 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00805 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00806 (p_bno055->dev_addr, 00807 BNO055_ACCEL_DATA_X_LSB_VALUEX_REG, 00808 data_u8, BNO055_ACCEL_XYZ_DATA_SIZE); 00809 /* Data X*/ 00810 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] = 00811 BNO055_GET_BITSLICE( 00812 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB], 00813 BNO055_ACCEL_DATA_X_LSB_VALUEX); 00814 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] = 00815 BNO055_GET_BITSLICE( 00816 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB], 00817 BNO055_ACCEL_DATA_X_MSB_VALUEX); 00818 accel->x = (s16)((((s32) 00819 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB])) << 00820 BNO055_SHIFT_EIGHT_BITS) 00821 | (data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB])); 00822 /* Data Y*/ 00823 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] = 00824 BNO055_GET_BITSLICE( 00825 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB], 00826 BNO055_ACCEL_DATA_Y_LSB_VALUEY); 00827 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] = 00828 BNO055_GET_BITSLICE( 00829 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB], 00830 BNO055_ACCEL_DATA_Y_MSB_VALUEY); 00831 accel->y = (s16)((((s32) 00832 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB])) << 00833 BNO055_SHIFT_EIGHT_BITS) 00834 | (data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB])); 00835 /* Data Z*/ 00836 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] = 00837 BNO055_GET_BITSLICE( 00838 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB], 00839 BNO055_ACCEL_DATA_Z_LSB_VALUEZ); 00840 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] = 00841 BNO055_GET_BITSLICE( 00842 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB], 00843 BNO055_ACCEL_DATA_Z_MSB_VALUEZ); 00844 accel->z = (s16)((((s32) 00845 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB])) << 00846 BNO055_SHIFT_EIGHT_BITS) 00847 | (data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB])); 00848 } else { 00849 com_rslt = BNO055_ERROR; 00850 } 00851 } 00852 return com_rslt; 00853 } 00854 /*! 00855 * @brief This API reads mag data x values 00856 * from register 0x0E and 0x0F it is a two byte data 00857 * 00858 * 00859 * 00860 * 00861 * @param mag_x_s16 : The x raw data 00862 * 00863 * 00864 * 00865 * @return results of bus communication function 00866 * @retval 0 -> BNO055_SUCCESS 00867 * @retval 1 -> BNO055_ERROR 00868 * 00869 * 00870 * 00871 */ 00872 BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_x(s16 *mag_x_s16) 00873 { 00874 /* Variable used to return value of 00875 communication routine*/ 00876 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00877 /* Array holding the mag x value 00878 data_u8[BNO055_SENSOR_DATA_LSB] - x->LSB 00879 data_u8[BNO055_SENSOR_DATA_MSB] - x->MSB 00880 */ 00881 u8 data_u8[BNO055_MAG_DATA_SIZE] = {BNO055_INIT_VALUE, 00882 BNO055_INIT_VALUE}; 00883 s8 stat_s8 = BNO055_ERROR; 00884 /* Check the struct p_bno055 is empty */ 00885 if (p_bno055 == BNO055_INIT_VALUE) { 00886 return BNO055_E_NULL_PTR; 00887 } else { 00888 /*condition check for page, chip id is 00889 available in the page zero*/ 00890 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00891 /* Write the page zero*/ 00892 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00893 if ((stat_s8 == BNO055_SUCCESS) || 00894 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00895 /*Read the mag x two bytes of data */ 00896 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00897 (p_bno055->dev_addr, 00898 BNO055_MAG_DATA_X_LSB_VALUEX_REG, 00899 data_u8, BNO055_LSB_MSB_READ_LENGTH); 00900 data_u8[BNO055_SENSOR_DATA_LSB] = 00901 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 00902 BNO055_MAG_DATA_X_LSB_VALUEX); 00903 data_u8[BNO055_SENSOR_DATA_MSB] = 00904 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 00905 BNO055_MAG_DATA_X_MSB_VALUEX); 00906 *mag_x_s16 = (s16)((((s32) 00907 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 00908 BNO055_SHIFT_EIGHT_BITS) | ( 00909 data_u8[BNO055_SENSOR_DATA_LSB])); 00910 } else { 00911 com_rslt = BNO055_ERROR; 00912 } 00913 } 00914 return com_rslt; 00915 } 00916 /*! 00917 * @brief This API reads mag data y values 00918 * from register 0x10 and 0x11 it is a two byte data 00919 * 00920 * 00921 * 00922 * 00923 * @param mag_y_s16 : The y raw data 00924 * 00925 * 00926 * 00927 * @return results of bus communication function 00928 * @retval 0 -> BNO055_SUCCESS 00929 * @retval 1 -> BNO055_ERROR 00930 * 00931 * 00932 */ 00933 BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_y(s16 *mag_y_s16) 00934 { 00935 /* Variable used to return value of 00936 communication routine*/ 00937 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 00938 /* Array holding the mag y value 00939 data_u8[BNO055_SENSOR_DATA_LSB] - y->LSB 00940 data_u8[BNO055_SENSOR_DATA_MSB] - y->MSB 00941 */ 00942 u8 data_u8[BNO055_MAG_DATA_SIZE] = { 00943 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 00944 s8 stat_s8 = BNO055_ERROR; 00945 /* Check the struct p_bno055 is empty */ 00946 if (p_bno055 == BNO055_INIT_VALUE) { 00947 return BNO055_E_NULL_PTR; 00948 } else { 00949 /*condition check for page, chip id is 00950 available in the page zero*/ 00951 if (p_bno055->page_id != BNO055_PAGE_ZERO) 00952 /* Write the page zero*/ 00953 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 00954 if ((stat_s8 == BNO055_SUCCESS) || 00955 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 00956 /*Read the mag y two bytes of data */ 00957 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 00958 (p_bno055->dev_addr, 00959 BNO055_MAG_DATA_Y_LSB_VALUEY_REG, 00960 data_u8, BNO055_LSB_MSB_READ_LENGTH); 00961 data_u8[BNO055_SENSOR_DATA_LSB] = 00962 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 00963 BNO055_MAG_DATA_Y_LSB_VALUEY); 00964 data_u8[BNO055_SENSOR_DATA_MSB] = 00965 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 00966 BNO055_MAG_DATA_Y_MSB_VALUEY); 00967 *mag_y_s16 = (s16)((((s32) 00968 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 00969 BNO055_SHIFT_EIGHT_BITS) | 00970 (data_u8[BNO055_SENSOR_DATA_LSB])); 00971 } else { 00972 com_rslt = BNO055_ERROR; 00973 } 00974 } 00975 return com_rslt; 00976 } 00977 /*! 00978 * @brief This API reads mag data z values 00979 * from register 0x12 and 0x13 it is a two byte data 00980 * 00981 * 00982 * 00983 * 00984 * @param mag_z_s16 : The z raw data 00985 * 00986 * 00987 * 00988 * @return results of bus communication function 00989 * @retval 0 -> BNO055_SUCCESS 00990 * @retval 1 -> BNO055_ERROR 00991 * 00992 * 00993 * 00994 */ 00995 BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_z(s16 *mag_z_s16) 00996 { 00997 /* Variable used to return value of 00998 communication routine*/ 00999 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01000 /* Array holding the mag z value 01001 data_u8[BNO055_SENSOR_DATA_LSB] - z->LSB 01002 data_u8[BNO055_SENSOR_DATA_MSB] - z->MSB 01003 */ 01004 u8 data_u8[BNO055_MAG_DATA_SIZE] = { 01005 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01006 s8 stat_s8 = BNO055_ERROR; 01007 /* Check the struct p_bno055 is empty */ 01008 if (p_bno055 == BNO055_INIT_VALUE) { 01009 return BNO055_E_NULL_PTR; 01010 } else { 01011 /*condition check for page, chip id is 01012 available in the page zero*/ 01013 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01014 /* Write the page zero*/ 01015 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01016 if ((stat_s8 == BNO055_SUCCESS) || 01017 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01018 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01019 (p_bno055->dev_addr, 01020 BNO055_MAG_DATA_Z_LSB_VALUEZ_REG, 01021 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01022 /*Read the mag z two bytes of data */ 01023 data_u8[BNO055_SENSOR_DATA_LSB] = 01024 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 01025 BNO055_MAG_DATA_Z_LSB_VALUEZ); 01026 data_u8[BNO055_SENSOR_DATA_MSB] = 01027 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 01028 BNO055_MAG_DATA_Z_MSB_VALUEZ); 01029 *mag_z_s16 = (s16)((((s32) 01030 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 01031 BNO055_SHIFT_EIGHT_BITS) 01032 | (data_u8[BNO055_SENSOR_DATA_LSB])); 01033 } else { 01034 com_rslt = BNO055_ERROR; 01035 } 01036 } 01037 return com_rslt; 01038 } 01039 /*! 01040 * @brief This API reads mag data xyz values 01041 * from register 0x0E to 0x13 it is a six byte data 01042 * 01043 * 01044 * @param mag : The mag xyz values 01045 * 01046 * Parameter | result 01047 * --------- | ----------------- 01048 * x | The mag x data 01049 * y | The mag y data 01050 * z | The mag z data 01051 * 01052 * 01053 * 01054 * @return results of bus communication function 01055 * @retval 0 -> BNO055_SUCCESS 01056 * @retval 1 -> BNO055_ERROR 01057 * 01058 */ 01059 BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_xyz(struct bno055_mag_t *mag) 01060 { 01061 /* Variable used to return value of 01062 communication routine*/ 01063 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01064 /* Array holding the mag xyz value 01065 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] - x->LSB 01066 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] - x->MSB 01067 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] - y->MSB 01068 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] - y->MSB 01069 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] - z->MSB 01070 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] - z->MSB 01071 */ 01072 u8 data_u8[BNO055_MAG_XYZ_DATA_SIZE] = { 01073 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01074 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01075 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01076 s8 stat_s8 = BNO055_ERROR; 01077 /* Check the struct p_bno055 is empty */ 01078 if (p_bno055 == BNO055_INIT_VALUE) { 01079 return BNO055_E_NULL_PTR; 01080 } else { 01081 /*condition check for page, chip id is 01082 available in the page zero*/ 01083 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01084 /* Write the page zero*/ 01085 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01086 if ((stat_s8 == BNO055_SUCCESS) || 01087 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01088 /*Read the six byte value of mag xyz*/ 01089 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01090 (p_bno055->dev_addr, 01091 BNO055_MAG_DATA_X_LSB_VALUEX_REG, 01092 data_u8, BNO055_MAG_XYZ_DATA_SIZE); 01093 /* Data X*/ 01094 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] = 01095 BNO055_GET_BITSLICE( 01096 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB], 01097 BNO055_MAG_DATA_X_LSB_VALUEX); 01098 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] = 01099 BNO055_GET_BITSLICE( 01100 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB], 01101 BNO055_MAG_DATA_X_MSB_VALUEX); 01102 mag->x = (s16)((((s32) 01103 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB])) << 01104 BNO055_SHIFT_EIGHT_BITS) | 01105 (data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB])); 01106 /* Data Y*/ 01107 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] = 01108 BNO055_GET_BITSLICE( 01109 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB], 01110 BNO055_MAG_DATA_Y_LSB_VALUEY); 01111 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] = 01112 BNO055_GET_BITSLICE( 01113 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB], 01114 BNO055_MAG_DATA_Y_MSB_VALUEY); 01115 mag->y = (s16)((((s32) 01116 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB])) << 01117 BNO055_SHIFT_EIGHT_BITS) | 01118 (data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB])); 01119 /* Data Z*/ 01120 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] = 01121 BNO055_GET_BITSLICE( 01122 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB], 01123 BNO055_MAG_DATA_Z_LSB_VALUEZ); 01124 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] = 01125 BNO055_GET_BITSLICE( 01126 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB], 01127 BNO055_MAG_DATA_Z_MSB_VALUEZ); 01128 mag->z = (s16)((((s32) 01129 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB])) << 01130 BNO055_SHIFT_EIGHT_BITS) 01131 | (data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB])); 01132 } else { 01133 com_rslt = BNO055_ERROR; 01134 } 01135 } 01136 return com_rslt; 01137 } 01138 /*! 01139 * @brief This API reads gyro data x values 01140 * from register 0x14 and 0x15 it is a two byte data 01141 * 01142 * 01143 * 01144 * 01145 * @param gyro_x_s16 : The x raw data 01146 * 01147 * 01148 * 01149 * @return results of bus communication function 01150 * @retval 0 -> BNO055_SUCCESS 01151 * @retval 1 -> BNO055_ERROR 01152 * 01153 * 01154 */ 01155 BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_x(s16 *gyro_x_s16) 01156 { 01157 /* Variable used to return value of 01158 communication routine*/ 01159 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01160 u8 data_u8[BNO055_GYRO_DATA_SIZE] = { 01161 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01162 s8 stat_s8 = BNO055_ERROR; 01163 /* Check the struct p_bno055 is empty */ 01164 if (p_bno055 == BNO055_INIT_VALUE) { 01165 return BNO055_E_NULL_PTR; 01166 } else { 01167 /*condition check for page, chip id is 01168 available in the page zero*/ 01169 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01170 /* Write the page zero*/ 01171 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01172 if ((stat_s8 == BNO055_SUCCESS) || 01173 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01174 /* Read the gyro 16 bit x value*/ 01175 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01176 (p_bno055->dev_addr, 01177 BNO055_GYRO_DATA_X_LSB_VALUEX_REG, 01178 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01179 data_u8[BNO055_SENSOR_DATA_LSB] = 01180 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 01181 BNO055_GYRO_DATA_X_LSB_VALUEX); 01182 data_u8[BNO055_SENSOR_DATA_MSB] = 01183 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 01184 BNO055_GYRO_DATA_X_MSB_VALUEX); 01185 *gyro_x_s16 = (s16)((((s32) 01186 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 01187 BNO055_SHIFT_EIGHT_BITS) | 01188 (data_u8[BNO055_SENSOR_DATA_LSB])); 01189 } else { 01190 com_rslt = BNO055_ERROR; 01191 } 01192 } 01193 return com_rslt; 01194 } 01195 /*! 01196 * @brief This API reads gyro data y values 01197 * from register 0x16 and 0x17 it is a two byte data 01198 * 01199 * 01200 * 01201 * 01202 * @param gyro_y_s16 : The y raw data 01203 * 01204 * 01205 * 01206 * @return results of bus communication function 01207 * @retval 0 -> BNO055_SUCCESS 01208 * @retval 1 -> BNO055_ERROR 01209 * 01210 * 01211 */ 01212 BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_y(s16 *gyro_y_s16) 01213 { 01214 /* Variable used to return value of 01215 communication routine*/ 01216 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01217 u8 data_u8[BNO055_GYRO_DATA_SIZE] = { 01218 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01219 s8 stat_s8 = BNO055_ERROR; 01220 /* Check the struct p_bno055 is empty */ 01221 if (p_bno055 == BNO055_INIT_VALUE) { 01222 return BNO055_E_NULL_PTR; 01223 } else { 01224 /*condition check for page, chip id is 01225 available in the page zero*/ 01226 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01227 /* Write the page zero*/ 01228 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01229 if ((stat_s8 == BNO055_SUCCESS) || 01230 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01231 /* Read the value of gyro y */ 01232 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01233 (p_bno055->dev_addr, 01234 BNO055_GYRO_DATA_Y_LSB_VALUEY_REG, 01235 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01236 data_u8[BNO055_SENSOR_DATA_LSB] = 01237 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 01238 BNO055_GYRO_DATA_Y_LSB_VALUEY); 01239 data_u8[BNO055_SENSOR_DATA_MSB] = 01240 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 01241 BNO055_GYRO_DATA_Y_MSB_VALUEY); 01242 *gyro_y_s16 = (s16)((((s32) 01243 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 01244 BNO055_SHIFT_EIGHT_BITS) 01245 | (data_u8[BNO055_SENSOR_DATA_LSB])); 01246 } else { 01247 com_rslt = BNO055_ERROR; 01248 } 01249 } 01250 return com_rslt; 01251 } 01252 /*! 01253 * @brief This API reads gyro data z values 01254 * from register 0x18 and 0x19 it is a two byte data 01255 * 01256 * @param gyro_z_s16 : The z raw data 01257 * 01258 * @return results of bus communication function 01259 * @retval 0 -> BNO055_SUCCESS 01260 * @retval 1 -> BNO055_ERROR 01261 * 01262 * 01263 */ 01264 BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_z(s16 *gyro_z_s16) 01265 { 01266 /* Variable used to return value of 01267 communication routine*/ 01268 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01269 u8 data_u8[BNO055_GYRO_DATA_SIZE] = { 01270 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01271 s8 stat_s8 = BNO055_ERROR; 01272 /* Check the struct p_bno055 is empty */ 01273 if (p_bno055 == BNO055_INIT_VALUE) { 01274 return BNO055_E_NULL_PTR; 01275 } else { 01276 /*condition check for page, chip id is 01277 available in the page zero*/ 01278 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01279 /* Write the page zero*/ 01280 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01281 if ((stat_s8 == BNO055_SUCCESS) || 01282 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01283 /* Read the gyro z 16 bit value*/ 01284 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01285 (p_bno055->dev_addr, 01286 BNO055_GYRO_DATA_Z_LSB_VALUEZ_REG, 01287 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01288 data_u8[BNO055_SENSOR_DATA_LSB] = 01289 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 01290 BNO055_GYRO_DATA_Z_LSB_VALUEZ); 01291 data_u8[BNO055_SENSOR_DATA_MSB] = 01292 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 01293 BNO055_GYRO_DATA_Z_MSB_VALUEZ); 01294 *gyro_z_s16 = (s16)((((s32) 01295 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 01296 BNO055_SHIFT_EIGHT_BITS) 01297 | (data_u8[BNO055_SENSOR_DATA_LSB])); 01298 } else { 01299 com_rslt = BNO055_ERROR; 01300 } 01301 } 01302 return com_rslt; 01303 } 01304 /*! 01305 * @brief This API reads gyro data xyz values 01306 * from register 0x14 to 0x19 it is a six byte data 01307 * 01308 * 01309 * @param gyro : The value of gyro xyz data's 01310 * 01311 * Parameter | result 01312 * --------- | ----------------- 01313 * x | The gyro x data 01314 * y | The gyro y data 01315 * z | The gyro z data 01316 * 01317 * 01318 * 01319 * @return results of bus communication function 01320 * @retval 0 -> BNO055_SUCCESS 01321 * @retval 1 -> BNO055_ERROR 01322 * 01323 */ 01324 BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_xyz(struct bno055_gyro_t *gyro) 01325 { 01326 /* Variable used to return value of 01327 communication routine*/ 01328 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01329 /* Array holding the gyro xyz value 01330 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] - x->LSB 01331 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] - x->MSB 01332 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] - y->MSB 01333 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] - y->MSB 01334 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] - z->MSB 01335 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] - z->MSB 01336 */ 01337 u8 data_u8[BNO055_GYRO_XYZ_DATA_SIZE] = { 01338 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01339 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01340 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01341 s8 stat_s8 = BNO055_ERROR; 01342 /* Check the struct p_bno055 is empty */ 01343 if (p_bno055 == BNO055_INIT_VALUE) { 01344 return BNO055_E_NULL_PTR; 01345 } else { 01346 /*condition check for page, chip id is 01347 available in the page zero*/ 01348 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01349 /* Write the page zero*/ 01350 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01351 if ((stat_s8 == BNO055_SUCCESS) || 01352 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01353 /* Read the six bytes data of gyro xyz*/ 01354 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01355 (p_bno055->dev_addr, 01356 BNO055_GYRO_DATA_X_LSB_VALUEX_REG, 01357 data_u8, BNO055_GYRO_XYZ_DATA_SIZE); 01358 /* Data x*/ 01359 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] = 01360 BNO055_GET_BITSLICE( 01361 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB], 01362 BNO055_GYRO_DATA_X_LSB_VALUEX); 01363 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] = 01364 BNO055_GET_BITSLICE( 01365 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB], 01366 BNO055_GYRO_DATA_X_MSB_VALUEX); 01367 gyro->x = (s16)((((s32) 01368 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB])) << 01369 BNO055_SHIFT_EIGHT_BITS) | 01370 (data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB])); 01371 /* Data y*/ 01372 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] = 01373 BNO055_GET_BITSLICE( 01374 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB], 01375 BNO055_GYRO_DATA_Y_LSB_VALUEY); 01376 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] = 01377 BNO055_GET_BITSLICE( 01378 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB], 01379 BNO055_GYRO_DATA_Y_MSB_VALUEY); 01380 gyro->y = (s16)((((s32) 01381 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB])) << 01382 BNO055_SHIFT_EIGHT_BITS) 01383 | (data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB])); 01384 /* Data z*/ 01385 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] = 01386 BNO055_GET_BITSLICE( 01387 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB], 01388 BNO055_GYRO_DATA_Z_LSB_VALUEZ); 01389 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] = 01390 BNO055_GET_BITSLICE( 01391 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB], 01392 BNO055_GYRO_DATA_Z_MSB_VALUEZ); 01393 gyro->z = (s16)((((s32) 01394 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB])) << 01395 BNO055_SHIFT_EIGHT_BITS) 01396 | (data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB])); 01397 } else { 01398 com_rslt = BNO055_ERROR; 01399 } 01400 } 01401 return com_rslt; 01402 } 01403 /*! 01404 * @brief This API reads gyro data z values 01405 * from register 0x1A and 0x1B it is a two byte data 01406 * 01407 * @param euler_h_s16 : The raw h data 01408 * 01409 * @return results of bus communication function 01410 * @retval 0 -> BNO055_SUCCESS 01411 * @retval 1 -> BNO055_ERROR 01412 * 01413 */ 01414 BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_h(s16 *euler_h_s16) 01415 { 01416 /* Variable used to return value of 01417 communication routine*/ 01418 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01419 /* Array holding the Euler h value 01420 data_u8[BNO055_SENSOR_DATA_EULER_LSB] - h->LSB 01421 data_u8[BNO055_SENSOR_DATA_EULER_MSB] - h->MSB 01422 */ 01423 u8 data_u8[BNO055_EULER_DATA_SIZE] = { 01424 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01425 s8 stat_s8 = BNO055_ERROR; 01426 /* Check the struct p_bno055 is empty */ 01427 if (p_bno055 == BNO055_INIT_VALUE) { 01428 return BNO055_E_NULL_PTR; 01429 } else { 01430 /*condition check for page, chip id is 01431 available in the page zero*/ 01432 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01433 /* Write the page zero*/ 01434 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01435 if ((stat_s8 == BNO055_SUCCESS) || 01436 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01437 /* Read the eulre heading data*/ 01438 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01439 (p_bno055->dev_addr, 01440 BNO055_EULER_H_LSB_VALUEH_REG, 01441 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01442 data_u8[BNO055_SENSOR_DATA_EULER_LSB] = 01443 BNO055_GET_BITSLICE( 01444 data_u8[BNO055_SENSOR_DATA_EULER_LSB], 01445 BNO055_EULER_H_LSB_VALUEH); 01446 data_u8[BNO055_SENSOR_DATA_EULER_MSB] = 01447 BNO055_GET_BITSLICE( 01448 data_u8[BNO055_SENSOR_DATA_EULER_MSB], 01449 BNO055_EULER_H_MSB_VALUEH); 01450 *euler_h_s16 = (s16)((((s32) 01451 ((s8)data_u8[BNO055_SENSOR_DATA_EULER_MSB])) << 01452 BNO055_SHIFT_EIGHT_BITS) | 01453 (data_u8[BNO055_SENSOR_DATA_EULER_LSB])); 01454 } else { 01455 com_rslt = BNO055_ERROR; 01456 } 01457 } 01458 return com_rslt; 01459 } 01460 /*! 01461 * @brief This API reads Euler data r values 01462 * from register 0x1C and 0x1D it is a two byte data 01463 * 01464 * @param euler_r_s16 : The raw r data 01465 * 01466 * @return results of bus communication function 01467 * @retval 0 -> BNO055_SUCCESS 01468 * @retval 1 -> BNO055_ERROR 01469 * 01470 */ 01471 BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_r(s16 *euler_r_s16) 01472 { 01473 /* Variable used to return value of 01474 communication routine*/ 01475 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01476 /* Array holding the Euler r value 01477 data_u8[BNO055_SENSOR_DATA_EULER_LSB] - r->LSB 01478 data_u8[BNO055_SENSOR_DATA_EULER_MSB] - r->MSB 01479 */ 01480 u8 data_u8[BNO055_EULER_DATA_SIZE] = { 01481 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01482 s8 stat_s8 = BNO055_ERROR; 01483 /* Check the struct p_bno055 is empty */ 01484 if (p_bno055 == BNO055_INIT_VALUE) { 01485 return BNO055_E_NULL_PTR; 01486 } else { 01487 /*condition check for page, chip id is 01488 available in the page zero*/ 01489 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01490 /* Write the page zero*/ 01491 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01492 if ((stat_s8 == BNO055_SUCCESS) || 01493 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01494 /* Read the Euler roll data*/ 01495 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01496 (p_bno055->dev_addr, 01497 BNO055_EULER_R_LSB_VALUER_REG, 01498 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01499 data_u8[BNO055_SENSOR_DATA_EULER_LSB] = 01500 BNO055_GET_BITSLICE( 01501 data_u8[BNO055_SENSOR_DATA_EULER_LSB], 01502 BNO055_EULER_R_LSB_VALUER); 01503 data_u8[BNO055_SENSOR_DATA_EULER_MSB] = 01504 BNO055_GET_BITSLICE( 01505 data_u8[BNO055_SENSOR_DATA_EULER_MSB], 01506 BNO055_EULER_R_MSB_VALUER); 01507 *euler_r_s16 = (s16)((((s32) 01508 ((s8)data_u8[BNO055_SENSOR_DATA_EULER_MSB])) << 01509 BNO055_SHIFT_EIGHT_BITS) 01510 | (data_u8[BNO055_SENSOR_DATA_EULER_LSB])); 01511 } else { 01512 com_rslt = BNO055_ERROR; 01513 } 01514 } 01515 return com_rslt; 01516 } 01517 /*! 01518 * @brief This API reads Euler data p values 01519 * from register 0x1E and 0x1F it is a two byte data 01520 * 01521 * @param euler_p_s16 : The raw p data 01522 * 01523 * @return results of bus communication function 01524 * @retval 0 -> BNO055_SUCCESS 01525 * @retval 1 -> BNO055_ERROR 01526 * 01527 * 01528 */ 01529 BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_p(s16 *euler_p_s16) 01530 { 01531 /* Variable used to return value of 01532 communication routine*/ 01533 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01534 /* Array holding the Euler p value 01535 data_u8[BNO055_SENSOR_DATA_EULER_LSB] - p->LSB 01536 data_u8[BNO055_SENSOR_DATA_EULER_MSB] - p->MSB 01537 */ 01538 u8 data_u8[BNO055_EULER_DATA_SIZE] = { 01539 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01540 s8 stat_s8 = BNO055_ERROR; 01541 /* Check the struct p_bno055 is empty */ 01542 if (p_bno055 == BNO055_INIT_VALUE) { 01543 return BNO055_E_NULL_PTR; 01544 } else { 01545 /*condition check for page, chip id is 01546 available in the page zero*/ 01547 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01548 /* Write the page zero*/ 01549 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01550 if ((stat_s8 == BNO055_SUCCESS) || 01551 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01552 /* Read the Euler p data*/ 01553 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01554 (p_bno055->dev_addr, 01555 BNO055_EULER_P_LSB_VALUEP_REG, 01556 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01557 data_u8[BNO055_SENSOR_DATA_EULER_LSB] = 01558 BNO055_GET_BITSLICE( 01559 data_u8[BNO055_SENSOR_DATA_EULER_LSB], 01560 BNO055_EULER_P_LSB_VALUEP); 01561 data_u8[BNO055_SENSOR_DATA_EULER_MSB] = 01562 BNO055_GET_BITSLICE( 01563 data_u8[BNO055_SENSOR_DATA_EULER_MSB], 01564 BNO055_EULER_P_MSB_VALUEP); 01565 *euler_p_s16 = (s16)((((s32) 01566 ((s8)data_u8[BNO055_SENSOR_DATA_EULER_MSB])) << 01567 BNO055_SHIFT_EIGHT_BITS) 01568 | (data_u8[BNO055_SENSOR_DATA_EULER_LSB])); 01569 } else { 01570 com_rslt = BNO055_ERROR; 01571 } 01572 } 01573 return com_rslt; 01574 } 01575 /*! 01576 * @brief This API reads Euler data hrp values 01577 * from register 0x1A to 0x1F it is a six byte data 01578 * 01579 * 01580 * @param euler : The Euler hrp data's 01581 * 01582 * Parameter | result 01583 * --------- | ----------------- 01584 * h | The Euler h data 01585 * r | The Euler r data 01586 * p | The Euler p data 01587 * 01588 * 01589 * @return results of bus communication function 01590 * @retval 0 -> BNO055_SUCCESS 01591 * @retval 1 -> BNO055_ERROR 01592 * 01593 */ 01594 BNO055_RETURN_FUNCTION_TYPE bno055_read_euler_hrp( 01595 struct bno055_euler_t *euler) 01596 { 01597 /* Variable used to return value of 01598 communication routine*/ 01599 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01600 /* Array holding the Euler hrp value 01601 data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_LSB] - h->LSB 01602 data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_MSB] - h->MSB 01603 data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_LSB] - r->MSB 01604 data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_MSB] - r->MSB 01605 data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_LSB] - p->MSB 01606 data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_MSB] - p->MSB 01607 */ 01608 u8 data_u8[BNO055_EULER_HRP_DATA_SIZE] = { 01609 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01610 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01611 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01612 s8 stat_s8 = BNO055_ERROR; 01613 /* Check the struct p_bno055 is empty */ 01614 if (p_bno055 == BNO055_INIT_VALUE) { 01615 return BNO055_E_NULL_PTR; 01616 } else { 01617 /*condition check for page, chip id is 01618 available in the page zero*/ 01619 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01620 /* Write the page zero*/ 01621 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01622 if ((stat_s8 == BNO055_SUCCESS) || 01623 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01624 /* Read the six byte of Euler hrp data*/ 01625 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01626 (p_bno055->dev_addr, 01627 BNO055_EULER_H_LSB_VALUEH_REG, 01628 data_u8, BNO055_EULER_HRP_DATA_SIZE); 01629 /* Data h*/ 01630 data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_LSB] = 01631 BNO055_GET_BITSLICE( 01632 data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_LSB], 01633 BNO055_EULER_H_LSB_VALUEH); 01634 data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_MSB] = 01635 BNO055_GET_BITSLICE( 01636 data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_MSB], 01637 BNO055_EULER_H_MSB_VALUEH); 01638 euler->h = (s16)((((s32) 01639 ((s8)data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_MSB])) << 01640 BNO055_SHIFT_EIGHT_BITS) | 01641 (data_u8[BNO055_SENSOR_DATA_EULER_HRP_H_LSB])); 01642 /* Data r*/ 01643 data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_LSB] = 01644 BNO055_GET_BITSLICE( 01645 data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_LSB], 01646 BNO055_EULER_R_LSB_VALUER); 01647 data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_MSB] = 01648 BNO055_GET_BITSLICE( 01649 data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_MSB], 01650 BNO055_EULER_R_MSB_VALUER); 01651 euler->r = (s16)((((s32) 01652 ((s8)data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_MSB])) << 01653 BNO055_SHIFT_EIGHT_BITS) 01654 | (data_u8[BNO055_SENSOR_DATA_EULER_HRP_R_LSB])); 01655 /* Data p*/ 01656 data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_LSB] = 01657 BNO055_GET_BITSLICE( 01658 data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_LSB], 01659 BNO055_EULER_P_LSB_VALUEP); 01660 data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_MSB] = 01661 BNO055_GET_BITSLICE( 01662 data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_MSB], 01663 BNO055_EULER_P_MSB_VALUEP); 01664 euler->p = (s16)((((s32) 01665 ((s8)data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_MSB])) << 01666 BNO055_SHIFT_EIGHT_BITS) 01667 | (data_u8[BNO055_SENSOR_DATA_EULER_HRP_P_LSB])); 01668 } else { 01669 com_rslt = BNO055_ERROR; 01670 } 01671 } 01672 return com_rslt; 01673 } 01674 /*! 01675 * @brief This API reads quaternion data w values 01676 * from register 0x20 and 0x21 it is a two byte data 01677 * 01678 * @param quaternion_w_s16 : The raw w data 01679 * 01680 * @return results of bus communication function 01681 * @retval 0 -> BNO055_SUCCESS 01682 * @retval 1 -> BNO055_ERROR 01683 * 01684 * 01685 */ 01686 BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_w( 01687 s16 *quaternion_w_s16) 01688 { 01689 /* Variable used to return value of 01690 communication routine*/ 01691 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01692 /* Array holding the Quaternion w value 01693 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] - w->LSB 01694 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] - w->MSB 01695 */ 01696 u8 data_u8[BNO055_QUATERNION_DATA_SIZE] = { 01697 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01698 s8 stat_s8 = BNO055_ERROR; 01699 /* Check the struct p_bno055 is empty */ 01700 if (p_bno055 == BNO055_INIT_VALUE) { 01701 return BNO055_E_NULL_PTR; 01702 } else { 01703 /*condition check for page, chip id is 01704 available in the page zero*/ 01705 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01706 /* Write the page zero*/ 01707 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01708 if ((stat_s8 == BNO055_SUCCESS) || 01709 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01710 /* Read the two byte value 01711 of quaternion w data*/ 01712 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01713 (p_bno055->dev_addr, 01714 BNO055_QUATERNION_DATA_W_LSB_VALUEW_REG, 01715 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01716 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] = 01717 BNO055_GET_BITSLICE( 01718 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB], 01719 BNO055_QUATERNION_DATA_W_LSB_VALUEW); 01720 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] = 01721 BNO055_GET_BITSLICE( 01722 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB], 01723 BNO055_QUATERNION_DATA_W_MSB_VALUEW); 01724 *quaternion_w_s16 = (s16)((((s32) 01725 ((s8)data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB])) << 01726 BNO055_SHIFT_EIGHT_BITS) 01727 | (data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB])); 01728 } else { 01729 com_rslt = BNO055_ERROR; 01730 } 01731 } 01732 return com_rslt; 01733 } 01734 /*! 01735 * @brief This API reads quaternion data x values 01736 * from register 0x22 and 0x23 it is a two byte data 01737 * 01738 * @param quaternion_x_s16 : The raw x data 01739 * 01740 * @return results of bus communication function 01741 * @retval 0 -> BNO055_SUCCESS 01742 * @retval 1 -> BNO055_ERROR 01743 * 01744 * 01745 */ 01746 BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_x( 01747 s16 *quaternion_x_s16) 01748 { 01749 /* Variable used to return value of 01750 communication routine*/ 01751 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01752 /* Array holding the quaternion x value 01753 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] - x->LSB 01754 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] - x->MSB 01755 */ 01756 u8 data_u8[BNO055_QUATERNION_DATA_SIZE] = {BNO055_INIT_VALUE, 01757 BNO055_INIT_VALUE}; 01758 s8 stat_s8 = BNO055_ERROR; 01759 /* Check the struct p_bno055 is empty */ 01760 if (p_bno055 == BNO055_INIT_VALUE) { 01761 return BNO055_E_NULL_PTR; 01762 } else { 01763 /*condition check for page, chip id is 01764 available in the page zero*/ 01765 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01766 /* Write the page zero*/ 01767 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01768 if ((stat_s8 == BNO055_SUCCESS) || 01769 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01770 /* Read the two byte value 01771 of quaternion x data*/ 01772 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01773 (p_bno055->dev_addr, 01774 BNO055_QUATERNION_DATA_X_LSB_VALUEX_REG, 01775 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01776 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] = 01777 BNO055_GET_BITSLICE( 01778 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB], 01779 BNO055_QUATERNION_DATA_X_LSB_VALUEX); 01780 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] = 01781 BNO055_GET_BITSLICE( 01782 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB], 01783 BNO055_QUATERNION_DATA_X_MSB_VALUEX); 01784 *quaternion_x_s16 = (s16)((((s32) 01785 ((s8)data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB])) << 01786 BNO055_SHIFT_EIGHT_BITS) | 01787 (data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB])); 01788 } else { 01789 com_rslt = BNO055_ERROR; 01790 } 01791 } 01792 return com_rslt; 01793 } 01794 /*! 01795 * @brief This API reads quaternion data y values 01796 * from register 0x24 and 0x25 it is a two byte data 01797 * 01798 * @param quaternion_y_s16 : The raw y data 01799 * 01800 * @return results of bus communication function 01801 * @retval 0 -> BNO055_SUCCESS 01802 * @retval 1 -> BNO055_ERROR 01803 * 01804 * 01805 */ 01806 BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_y( 01807 s16 *quaternion_y_s16) 01808 { 01809 /* Variable used to return value of 01810 communication routine*/ 01811 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01812 /* Array holding the quaternion y value 01813 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] - y->LSB 01814 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] - y->MSB 01815 */ 01816 u8 data_u8[BNO055_QUATERNION_DATA_SIZE] = {BNO055_INIT_VALUE, 01817 BNO055_INIT_VALUE}; 01818 s8 stat_s8 = BNO055_ERROR; 01819 /* Check the struct p_bno055 is empty */ 01820 if (p_bno055 == BNO055_INIT_VALUE) { 01821 return BNO055_E_NULL_PTR; 01822 } else { 01823 /*condition check for page, chip id is 01824 available in the page zero*/ 01825 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01826 /* Write the page zero*/ 01827 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01828 if ((stat_s8 == BNO055_SUCCESS) || 01829 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01830 /* Read the two byte value 01831 of quaternion y data*/ 01832 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01833 (p_bno055->dev_addr, 01834 BNO055_QUATERNION_DATA_Y_LSB_VALUEY_REG, 01835 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01836 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] = 01837 BNO055_GET_BITSLICE( 01838 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB], 01839 BNO055_QUATERNION_DATA_Y_LSB_VALUEY); 01840 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] = 01841 BNO055_GET_BITSLICE 01842 (data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB], 01843 BNO055_QUATERNION_DATA_Y_MSB_VALUEY); 01844 *quaternion_y_s16 = (s16)((((s32) 01845 ((s8)data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB])) << 01846 BNO055_SHIFT_EIGHT_BITS) 01847 | (data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB])); 01848 } else { 01849 com_rslt = BNO055_ERROR; 01850 } 01851 } 01852 return com_rslt; 01853 } 01854 /*! 01855 * @brief This API reads quaternion data z values 01856 * from register 0x26 and 0x27 it is a two byte data 01857 * 01858 * @param quaternion_z_s16 : The raw z data 01859 * 01860 * @return results of bus communication function 01861 * @retval 0 -> BNO055_SUCCESS 01862 * @retval 1 -> BNO055_ERROR 01863 * 01864 * 01865 */ 01866 BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_z( 01867 s16 *quaternion_z_s16) 01868 { 01869 /* Variable used to return value of 01870 communication routine*/ 01871 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01872 /* Array holding the quaternion z value 01873 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] - z->LSB 01874 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] - z->MSB 01875 */ 01876 u8 data_u8[BNO055_QUATERNION_DATA_SIZE] = { 01877 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01878 s8 stat_s8 = BNO055_ERROR; 01879 /* Check the struct p_bno055 is empty */ 01880 if (p_bno055 == BNO055_INIT_VALUE) { 01881 return BNO055_E_NULL_PTR; 01882 } else { 01883 /*condition check for page, chip id is 01884 available in the page zero*/ 01885 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01886 /* Write the page zero*/ 01887 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01888 if ((stat_s8 == BNO055_SUCCESS) || 01889 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01890 /* Read the two byte value 01891 of quaternion z data*/ 01892 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01893 (p_bno055->dev_addr, 01894 BNO055_QUATERNION_DATA_Z_LSB_VALUEZ_REG, 01895 data_u8, BNO055_LSB_MSB_READ_LENGTH); 01896 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB] = 01897 BNO055_GET_BITSLICE( 01898 data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB], 01899 BNO055_QUATERNION_DATA_Z_LSB_VALUEZ); 01900 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB] = 01901 BNO055_GET_BITSLICE( 01902 data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB], 01903 BNO055_QUATERNION_DATA_Z_MSB_VALUEZ); 01904 *quaternion_z_s16 = (s16)((((s32) 01905 ((s8)data_u8[BNO055_SENSOR_DATA_QUATERNION_MSB])) << 01906 BNO055_SHIFT_EIGHT_BITS) 01907 | (data_u8[BNO055_SENSOR_DATA_QUATERNION_LSB])); 01908 } else { 01909 com_rslt = BNO055_ERROR; 01910 } 01911 } 01912 return com_rslt; 01913 } 01914 /*! 01915 * @brief This API reads Quaternion data wxyz values 01916 * from register 0x20 to 0x27 it is a six byte data 01917 * 01918 * 01919 * @param quaternion : The value of quaternion wxyz data's 01920 * 01921 * Parameter | result 01922 * --------- | ----------------- 01923 * w | The quaternion w data 01924 * x | The quaternion x data 01925 * y | The quaternion y data 01926 * z | The quaternion z data 01927 * 01928 * 01929 * 01930 * @return results of bus communication function 01931 * @retval 0 -> BNO055_SUCCESS 01932 * @retval 1 -> BNO055_ERROR 01933 * 01934 */ 01935 BNO055_RETURN_FUNCTION_TYPE bno055_read_quaternion_wxyz( 01936 struct bno055_quaternion_t *quaternion) 01937 { 01938 /* Variable used to return value of 01939 communication routine*/ 01940 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 01941 /* Array holding the quaternion wxyz value 01942 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_LSB] - w->LSB 01943 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_MSB] - w->MSB 01944 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_LSB] - x->LSB 01945 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_MSB] - x->MSB 01946 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_LSB] - y->MSB 01947 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_MSB] - y->MSB 01948 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_LSB] - z->MSB 01949 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_MSB] - z->MSB 01950 */ 01951 u8 data_u8[BNO055_QUATERNION_WXYZ_DATA_SIZE] = { 01952 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01953 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01954 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 01955 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 01956 s8 stat_s8 = BNO055_ERROR; 01957 /* Check the struct p_bno055 is empty */ 01958 if (p_bno055 == BNO055_INIT_VALUE) { 01959 return BNO055_E_NULL_PTR; 01960 } else { 01961 /*condition check for page, chip id is 01962 available in the page zero*/ 01963 if (p_bno055->page_id != BNO055_PAGE_ZERO) 01964 /* Write the page zero*/ 01965 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 01966 if ((stat_s8 == BNO055_SUCCESS) || 01967 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 01968 /* Read the eight byte value 01969 of quaternion wxyz data*/ 01970 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 01971 (p_bno055->dev_addr, 01972 BNO055_QUATERNION_DATA_W_LSB_VALUEW_REG, 01973 data_u8, BNO055_QUATERNION_WXYZ_DATA_SIZE); 01974 /* Data W*/ 01975 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_LSB] = 01976 BNO055_GET_BITSLICE( 01977 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_LSB], 01978 BNO055_QUATERNION_DATA_W_LSB_VALUEW); 01979 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_MSB] = 01980 BNO055_GET_BITSLICE( 01981 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_MSB], 01982 BNO055_QUATERNION_DATA_W_MSB_VALUEW); 01983 quaternion->w = (s16)((((s32)((s8) 01984 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_MSB])) << 01985 BNO055_SHIFT_EIGHT_BITS) | 01986 (data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_W_LSB])); 01987 /* Data X*/ 01988 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_LSB] = 01989 BNO055_GET_BITSLICE( 01990 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_LSB], 01991 BNO055_QUATERNION_DATA_X_LSB_VALUEX); 01992 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_MSB] = 01993 BNO055_GET_BITSLICE( 01994 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_MSB], 01995 BNO055_QUATERNION_DATA_X_MSB_VALUEX); 01996 quaternion->x = (s16)((((s32)((s8) 01997 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_MSB])) << 01998 BNO055_SHIFT_EIGHT_BITS) | 01999 (data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_X_LSB])); 02000 /* Data Y*/ 02001 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_LSB] = 02002 BNO055_GET_BITSLICE( 02003 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_LSB], 02004 BNO055_QUATERNION_DATA_Y_LSB_VALUEY); 02005 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_MSB] = 02006 BNO055_GET_BITSLICE( 02007 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_MSB], 02008 BNO055_QUATERNION_DATA_Y_MSB_VALUEY); 02009 quaternion->y = (s16)((((s32)((s8) 02010 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_MSB])) << 02011 BNO055_SHIFT_EIGHT_BITS) | 02012 (data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Y_LSB])); 02013 /* Data Z*/ 02014 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_LSB] = 02015 BNO055_GET_BITSLICE( 02016 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_LSB], 02017 BNO055_QUATERNION_DATA_Z_LSB_VALUEZ); 02018 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_MSB] = 02019 BNO055_GET_BITSLICE( 02020 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_MSB], 02021 BNO055_QUATERNION_DATA_Z_MSB_VALUEZ); 02022 quaternion->z = (s16)((((s32)((s8) 02023 data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_MSB])) << 02024 BNO055_SHIFT_EIGHT_BITS) | 02025 (data_u8[BNO055_SENSOR_DATA_QUATERNION_WXYZ_Z_LSB])); 02026 } else { 02027 com_rslt = BNO055_ERROR; 02028 } 02029 } 02030 return com_rslt; 02031 } 02032 /*! 02033 * @brief This API reads Linear accel data x values 02034 * from register 0x29 and 0x2A it is a two byte data 02035 * 02036 * @param linear_accel_x_s16 : The raw x data 02037 * 02038 * @return results of bus communication function 02039 * @retval 0 -> BNO055_SUCCESS 02040 * @retval 1 -> BNO055_ERROR 02041 * 02042 * 02043 */ 02044 BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_x( 02045 s16 *linear_accel_x_s16) 02046 { 02047 /* Variable used to return value of 02048 communication routine*/ 02049 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02050 /* Array holding the linear accel x value 02051 data_u8[BNO055_SENSOR_DATA_LSB] - x->LSB 02052 data_u8[BNO055_SENSOR_DATA_MSB] - x->MSB 02053 */ 02054 u8 data_u8[BNO055_ACCEL_DATA_SIZE] = { 02055 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02056 s8 stat_s8 = BNO055_ERROR; 02057 /* Check the struct p_bno055 is empty */ 02058 if (p_bno055 == BNO055_INIT_VALUE) { 02059 return BNO055_E_NULL_PTR; 02060 } else { 02061 /*condition check for page, chip id is 02062 available in the page zero*/ 02063 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02064 /* Write the page zero*/ 02065 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02066 if ((stat_s8 == BNO055_SUCCESS) || 02067 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02068 /* Read the two byte value 02069 of linear accel x data*/ 02070 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02071 (p_bno055->dev_addr, 02072 BNO055_LINEAR_ACCEL_DATA_X_LSB_VALUEX_REG, 02073 data_u8, BNO055_LSB_MSB_READ_LENGTH); 02074 data_u8[BNO055_SENSOR_DATA_LSB] = 02075 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 02076 BNO055_LINEAR_ACCEL_DATA_X_LSB_VALUEX); 02077 data_u8[BNO055_SENSOR_DATA_MSB] = 02078 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 02079 BNO055_LINEAR_ACCEL_DATA_X_MSB_VALUEX); 02080 *linear_accel_x_s16 = (s16)((((s32) 02081 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 02082 BNO055_SHIFT_EIGHT_BITS) 02083 | (data_u8[BNO055_SENSOR_DATA_LSB])); 02084 } else { 02085 com_rslt = BNO055_ERROR; 02086 } 02087 } 02088 return com_rslt; 02089 } 02090 /*! 02091 * @brief This API reads Linear accel data x values 02092 * from register 0x2B and 0x2C it is a two byte data 02093 * 02094 * @param linear_accel_y_s16 : The raw y data 02095 * 02096 * @return results of bus communication function 02097 * @retval 0 -> BNO055_SUCCESS 02098 * @retval 1 -> BNO055_ERROR 02099 * 02100 * 02101 */ 02102 BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_y( 02103 s16 *linear_accel_y_s16) 02104 { 02105 /* Variable used to return value of 02106 communication routine*/ 02107 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02108 /* Array holding the linear accel y value 02109 data_u8[BNO055_SENSOR_DATA_LSB] - y->LSB 02110 data_u8[BNO055_SENSOR_DATA_MSB] - y->MSB 02111 */ 02112 u8 data_u8[BNO055_ACCEL_DATA_SIZE] = { 02113 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02114 s8 stat_s8 = BNO055_ERROR; 02115 /* Check the struct p_bno055 is empty */ 02116 if (p_bno055 == BNO055_INIT_VALUE) { 02117 return BNO055_E_NULL_PTR; 02118 } else { 02119 /*condition check for page, chip id is 02120 available in the page zero*/ 02121 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02122 /* Write the page zero*/ 02123 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02124 if ((stat_s8 == BNO055_SUCCESS) || 02125 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02126 /* Read the two byte value 02127 of linear accel y data*/ 02128 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02129 (p_bno055->dev_addr, 02130 BNO055_LINEAR_ACCEL_DATA_Y_LSB_VALUEY_REG, 02131 data_u8, BNO055_LSB_MSB_READ_LENGTH); 02132 data_u8[BNO055_SENSOR_DATA_LSB] = 02133 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 02134 BNO055_LINEAR_ACCEL_DATA_Y_LSB_VALUEY); 02135 data_u8[BNO055_SENSOR_DATA_MSB] = 02136 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 02137 BNO055_LINEAR_ACCEL_DATA_Y_MSB_VALUEY); 02138 *linear_accel_y_s16 = (s16)((((s32) 02139 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 02140 BNO055_SHIFT_EIGHT_BITS) | ( 02141 data_u8[BNO055_SENSOR_DATA_LSB])); 02142 } else { 02143 com_rslt = BNO055_ERROR; 02144 } 02145 } 02146 return com_rslt; 02147 } 02148 /*! 02149 * @brief This API reads Linear accel data x values 02150 * from register 0x2C and 0x2D it is a two byte data 02151 * 02152 * @param linear_accel_z_s16 : The raw z data 02153 * 02154 * @return results of bus communication function 02155 * @retval 0 -> BNO055_SUCCESS 02156 * @retval 1 -> BNO055_ERROR 02157 * 02158 * 02159 */ 02160 BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_z( 02161 s16 *linear_accel_z_s16) 02162 { 02163 /* Variable used to return value of 02164 communication routine*/ 02165 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02166 /* Array holding the linear accel z value 02167 data_u8[BNO055_SENSOR_DATA_LSB] - z->LSB 02168 data_u8[BNO055_SENSOR_DATA_MSB] - z->MSB 02169 */ 02170 u8 data_u8[BNO055_ACCEL_DATA_SIZE] = { 02171 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02172 s8 stat_s8 = BNO055_ERROR; 02173 /* Check the struct p_bno055 is empty */ 02174 if (p_bno055 == BNO055_INIT_VALUE) { 02175 return BNO055_E_NULL_PTR; 02176 } else { 02177 /*condition check for page, chip id is 02178 available in the page zero*/ 02179 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02180 /* Write the page zero*/ 02181 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02182 if ((stat_s8 == BNO055_SUCCESS) || 02183 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02184 /* Read the two byte value 02185 of linear accel z data*/ 02186 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02187 (p_bno055->dev_addr, 02188 BNO055_LINEAR_ACCEL_DATA_Z_LSB_VALUEZ_REG, 02189 data_u8, BNO055_LSB_MSB_READ_LENGTH); 02190 data_u8[BNO055_SENSOR_DATA_LSB] = 02191 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 02192 BNO055_LINEAR_ACCEL_DATA_Z_LSB_VALUEZ); 02193 data_u8[BNO055_SENSOR_DATA_MSB] = 02194 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 02195 BNO055_LINEAR_ACCEL_DATA_Z_MSB_VALUEZ); 02196 *linear_accel_z_s16 = (s16)((((s32) 02197 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 02198 BNO055_SHIFT_EIGHT_BITS) | ( 02199 data_u8[BNO055_SENSOR_DATA_LSB])); 02200 } else { 02201 com_rslt = BNO055_ERROR; 02202 } 02203 } 02204 return com_rslt; 02205 } 02206 /*! 02207 * @brief This API reads Linear accel data xyz values 02208 * from register 0x28 to 0x2D it is a six byte data 02209 * 02210 * 02211 * @param linear_accel : The value of linear accel xyz data's 02212 * 02213 * Parameter | result 02214 * --------- | ----------------- 02215 * x | The linear accel x data 02216 * y | The linear accel y data 02217 * z | The linear accel z data 02218 * 02219 * 02220 * @return results of bus communication function 02221 * @retval 0 -> BNO055_SUCCESS 02222 * @retval 1 -> BNO055_ERROR 02223 */ 02224 BNO055_RETURN_FUNCTION_TYPE bno055_read_linear_accel_xyz( 02225 struct bno055_linear_accel_t *linear_accel) 02226 { 02227 /* Variable used to return value of 02228 communication routine*/ 02229 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02230 /* Array holding the linear accel xyz value 02231 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] - x->LSB 02232 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] - x->MSB 02233 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] - y->MSB 02234 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] - y->MSB 02235 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] - z->MSB 02236 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] - z->MSB 02237 */ 02238 u8 data_u8[BNO055_ACCEL_XYZ_DATA_SIZE] = { 02239 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 02240 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 02241 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02242 s8 stat_s8 = BNO055_ERROR; 02243 /* Check the struct p_bno055 is empty */ 02244 if (p_bno055 == BNO055_INIT_VALUE) { 02245 return BNO055_E_NULL_PTR; 02246 } else { 02247 /*condition check for page, chip id is 02248 available in the page zero*/ 02249 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02250 /* Write the page zero*/ 02251 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02252 if ((stat_s8 == BNO055_SUCCESS) || 02253 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02254 /* Read the six byte value 02255 of linear accel xyz data*/ 02256 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02257 (p_bno055->dev_addr, 02258 BNO055_LINEAR_ACCEL_DATA_X_LSB_VALUEX_REG, 02259 data_u8, BNO055_ACCEL_XYZ_DATA_SIZE); 02260 /* Data x*/ 02261 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] = 02262 BNO055_GET_BITSLICE( 02263 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB], 02264 BNO055_LINEAR_ACCEL_DATA_X_LSB_VALUEX); 02265 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] = 02266 BNO055_GET_BITSLICE( 02267 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB], 02268 BNO055_LINEAR_ACCEL_DATA_X_MSB_VALUEX); 02269 linear_accel->x = (s16)((((s32) 02270 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB])) << 02271 BNO055_SHIFT_EIGHT_BITS) 02272 | (data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB])); 02273 /* Data y*/ 02274 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] = 02275 BNO055_GET_BITSLICE( 02276 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB], 02277 BNO055_LINEAR_ACCEL_DATA_Y_LSB_VALUEY); 02278 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] = 02279 BNO055_GET_BITSLICE( 02280 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB], 02281 BNO055_LINEAR_ACCEL_DATA_Y_MSB_VALUEY); 02282 linear_accel->y = (s16)((((s32) 02283 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB])) << 02284 BNO055_SHIFT_EIGHT_BITS) 02285 | (data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB])); 02286 /* Data z*/ 02287 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] = 02288 BNO055_GET_BITSLICE( 02289 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB], 02290 BNO055_LINEAR_ACCEL_DATA_Z_LSB_VALUEZ); 02291 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] = 02292 BNO055_GET_BITSLICE( 02293 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB], 02294 BNO055_LINEAR_ACCEL_DATA_Z_MSB_VALUEZ); 02295 linear_accel->z = (s16)((((s32) 02296 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB])) << 02297 BNO055_SHIFT_EIGHT_BITS) 02298 | (data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB])); 02299 } else { 02300 com_rslt = BNO055_ERROR; 02301 } 02302 } 02303 return com_rslt; 02304 } 02305 /*! 02306 * @brief This API reads gravity data x values 02307 * from register 0x2E and 0x2F it is a two byte data 02308 * 02309 * @param gravity_x_s16 : The raw x data 02310 * 02311 * @return results of bus communication function 02312 * @retval 0 -> BNO055_SUCCESS 02313 * @retval 1 -> BNO055_ERROR 02314 * 02315 * 02316 */ 02317 BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_x( 02318 s16 *gravity_x_s16) 02319 { 02320 /* Variable used to return value of 02321 communication routine*/ 02322 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02323 /* Array holding the gravity x value 02324 data_u8[BNO055_SENSOR_DATA_LSB] - x->LSB 02325 data_u8[BNO055_SENSOR_DATA_MSB] - x->MSB 02326 */ 02327 u8 data_u8[BNO055_GRAVITY_DATA_SIZE] = { 02328 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02329 s8 stat_s8 = BNO055_ERROR; 02330 /* Check the struct p_bno055 is empty */ 02331 if (p_bno055 == BNO055_INIT_VALUE) { 02332 return BNO055_E_NULL_PTR; 02333 } else { 02334 /*condition check for page, chip id is 02335 available in the page zero*/ 02336 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02337 /* Write the page zero*/ 02338 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02339 if ((stat_s8 == BNO055_SUCCESS) || 02340 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02341 /* Read the two byte value 02342 of gravity x data*/ 02343 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02344 (p_bno055->dev_addr, 02345 BNO055_GRAVITY_DATA_X_LSB_VALUEX_REG, 02346 data_u8, BNO055_LSB_MSB_READ_LENGTH); 02347 data_u8[BNO055_SENSOR_DATA_LSB] = 02348 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 02349 BNO055_GRAVITY_DATA_X_LSB_VALUEX); 02350 data_u8[BNO055_SENSOR_DATA_MSB] = 02351 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 02352 BNO055_GRAVITY_DATA_X_MSB_VALUEX); 02353 *gravity_x_s16 = (s16)((((s32) 02354 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 02355 BNO055_SHIFT_EIGHT_BITS) 02356 | (data_u8[BNO055_SENSOR_DATA_LSB])); 02357 } else { 02358 com_rslt = BNO055_ERROR; 02359 } 02360 } 02361 return com_rslt; 02362 } 02363 /*! 02364 * @brief This API reads gravity data y values 02365 * from register 0x30 and 0x31 it is a two byte data 02366 * 02367 * @param gravity_y_s16 : The raw y data 02368 * 02369 * @return results of bus communication function 02370 * @retval 0 -> BNO055_SUCCESS 02371 * @retval 1 -> BNO055_ERROR 02372 * 02373 * 02374 */ 02375 BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_y( 02376 s16 *gravity_y_s16) 02377 { 02378 /* Variable used to return value of 02379 communication routine*/ 02380 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02381 /* Array holding the gravity y value 02382 data_u8[BNO055_SENSOR_DATA_LSB] - y->LSB 02383 data_u8[BNO055_SENSOR_DATA_MSB] - y->MSB 02384 */ 02385 u8 data_u8[BNO055_GRAVITY_DATA_SIZE] = { 02386 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02387 s8 stat_s8 = BNO055_ERROR; 02388 /* Check the struct p_bno055 is empty */ 02389 if (p_bno055 == BNO055_INIT_VALUE) { 02390 return BNO055_E_NULL_PTR; 02391 } else { 02392 /*condition check for page, chip id is 02393 available in the page zero*/ 02394 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02395 /* Write the page zero*/ 02396 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02397 if ((stat_s8 == BNO055_SUCCESS) || 02398 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02399 /* Read the two byte value 02400 of gravity y data*/ 02401 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02402 (p_bno055->dev_addr, 02403 BNO055_GRAVITY_DATA_Y_LSB_VALUEY_REG, 02404 data_u8, BNO055_LSB_MSB_READ_LENGTH); 02405 data_u8[BNO055_SENSOR_DATA_LSB] = 02406 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 02407 BNO055_GRAVITY_DATA_Y_LSB_VALUEY); 02408 data_u8[BNO055_SENSOR_DATA_MSB] = 02409 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 02410 BNO055_GRAVITY_DATA_Y_MSB_VALUEY); 02411 *gravity_y_s16 = (s16)((((s32) 02412 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 02413 BNO055_SHIFT_EIGHT_BITS) 02414 | (data_u8[BNO055_SENSOR_DATA_LSB])); 02415 } else { 02416 com_rslt = BNO055_ERROR; 02417 } 02418 } 02419 return com_rslt; 02420 } 02421 /*! 02422 * @brief This API reads gravity data z values 02423 * from register 0x32 and 0x33 it is a two byte data 02424 * 02425 * @param gravity_z_s16 : The raw z data 02426 * 02427 * @return results of bus communication function 02428 * @retval 0 -> BNO055_SUCCESS 02429 * @retval 1 -> BNO055_ERROR 02430 * 02431 * 02432 */ 02433 BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_z( 02434 s16 *gravity_z_s16) 02435 { 02436 /* Variable used to return value of 02437 communication routine*/ 02438 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02439 /* Array holding the gravity z value 02440 data_u8[BNO055_SENSOR_DATA_LSB] - z->LSB 02441 data_u8[BNO055_SENSOR_DATA_MSB] - z->MSB 02442 */ 02443 u8 data_u8[BNO055_GRAVITY_DATA_SIZE] = { 02444 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02445 s8 stat_s8 = BNO055_ERROR; 02446 /* Check the struct p_bno055 is empty */ 02447 if (p_bno055 == BNO055_INIT_VALUE) { 02448 return BNO055_E_NULL_PTR; 02449 } else { 02450 /*condition check for page, chip id is 02451 available in the page zero*/ 02452 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02453 /* Write the page zero*/ 02454 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02455 if ((stat_s8 == BNO055_SUCCESS) || 02456 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02457 /* Read the two byte value 02458 of gravity z data*/ 02459 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02460 (p_bno055->dev_addr, 02461 BNO055_GRAVITY_DATA_Z_LSB_VALUEZ_REG, 02462 data_u8, BNO055_LSB_MSB_READ_LENGTH); 02463 data_u8[BNO055_SENSOR_DATA_LSB] = 02464 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_LSB], 02465 BNO055_GRAVITY_DATA_Z_LSB_VALUEZ); 02466 data_u8[BNO055_SENSOR_DATA_MSB] = 02467 BNO055_GET_BITSLICE(data_u8[BNO055_SENSOR_DATA_MSB], 02468 BNO055_GRAVITY_DATA_Z_MSB_VALUEZ); 02469 *gravity_z_s16 = (s16)((((s32) 02470 ((s8)data_u8[BNO055_SENSOR_DATA_MSB])) << 02471 BNO055_SHIFT_EIGHT_BITS) 02472 | (data_u8[BNO055_SENSOR_DATA_LSB])); 02473 } else { 02474 com_rslt = BNO055_ERROR; 02475 } 02476 } 02477 return com_rslt; 02478 } 02479 /*! 02480 * @brief This API reads gravity data xyz values 02481 * from register 0x2E to 0x33 it is a six byte data 02482 * 02483 * 02484 * @param gravity : The value of gravity xyz data's 02485 * 02486 * Parameter | result 02487 * --------- | ----------------- 02488 * x | The gravity x data 02489 * y | The gravity y data 02490 * z | The gravity z data 02491 * 02492 * 02493 * @return results of bus communication function 02494 * @retval 0 -> BNO055_SUCCESS 02495 * @retval 1 -> BNO055_ERROR 02496 * 02497 */ 02498 BNO055_RETURN_FUNCTION_TYPE bno055_read_gravity_xyz( 02499 struct bno055_gravity_t *gravity) 02500 { 02501 /* Variable used to return value of 02502 communication routine*/ 02503 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02504 /* Array holding the gravity xyz value 02505 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] - x->LSB 02506 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] - x->MSB 02507 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] - y->MSB 02508 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] - y->MSB 02509 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] - z->MSB 02510 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] - z->MSB 02511 */ 02512 u8 data_u8[BNO055_GRAVITY_XYZ_DATA_SIZE] = { 02513 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 02514 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 02515 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02516 s8 stat_s8 = BNO055_ERROR; 02517 /* Check the struct p_bno055 is empty */ 02518 if (p_bno055 == BNO055_INIT_VALUE) { 02519 return BNO055_E_NULL_PTR; 02520 } else { 02521 /*condition check for page, chip id is 02522 available in the page zero*/ 02523 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02524 /* Write the page zero*/ 02525 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02526 if ((stat_s8 == BNO055_SUCCESS) || 02527 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02528 /* Read the six byte value 02529 of gravity xyz data*/ 02530 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02531 (p_bno055->dev_addr, 02532 BNO055_GRAVITY_DATA_X_LSB_VALUEX_REG, 02533 data_u8, BNO055_GRAVITY_XYZ_DATA_SIZE); 02534 /* Data x*/ 02535 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB] = 02536 BNO055_GET_BITSLICE( 02537 data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB], 02538 BNO055_GRAVITY_DATA_X_LSB_VALUEX); 02539 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB] = 02540 BNO055_GET_BITSLICE( 02541 data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB], 02542 BNO055_GRAVITY_DATA_X_MSB_VALUEX); 02543 gravity->x = (s16)(((s32) 02544 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_X_MSB]) << 02545 BNO055_SHIFT_EIGHT_BITS) | 02546 (data_u8[BNO055_SENSOR_DATA_XYZ_X_LSB])); 02547 /* Data y*/ 02548 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB] = 02549 BNO055_GET_BITSLICE( 02550 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB], 02551 BNO055_GRAVITY_DATA_Y_LSB_VALUEY); 02552 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB] = 02553 BNO055_GET_BITSLICE( 02554 data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB], 02555 BNO055_GRAVITY_DATA_Y_MSB_VALUEY); 02556 gravity->y = (s16)((((s32) 02557 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Y_MSB])) << 02558 BNO055_SHIFT_EIGHT_BITS) | ( 02559 data_u8[BNO055_SENSOR_DATA_XYZ_Y_LSB])); 02560 /* Data z*/ 02561 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB] = 02562 BNO055_GET_BITSLICE( 02563 data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB], 02564 BNO055_GRAVITY_DATA_Z_LSB_VALUEZ); 02565 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB] = 02566 BNO055_GET_BITSLICE( 02567 data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB], 02568 BNO055_GRAVITY_DATA_Z_MSB_VALUEZ); 02569 gravity->z = (s16)((((s32) 02570 ((s8)data_u8[BNO055_SENSOR_DATA_XYZ_Z_MSB])) << 02571 BNO055_SHIFT_EIGHT_BITS) 02572 | (data_u8[BNO055_SENSOR_DATA_XYZ_Z_LSB])); 02573 } else { 02574 com_rslt = BNO055_ERROR; 02575 } 02576 } 02577 return com_rslt; 02578 } 02579 /*! 02580 * @brief This API reads temperature values 02581 * from register 0x33 it is a byte data 02582 * 02583 * @param temp_s8 : The raw temperature data 02584 * 02585 * @return results of bus communication function 02586 * @retval 0 -> BNO055_SUCCESS 02587 * @retval 1 -> BNO055_ERROR 02588 * 02589 * 02590 */ 02591 BNO055_RETURN_FUNCTION_TYPE bno055_read_temp_data(s8 *temp_s8) 02592 { 02593 /* Variable used to return value of 02594 communication routine*/ 02595 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02596 u8 data_u8 = BNO055_INIT_VALUE; 02597 s8 stat_s8 = BNO055_ERROR; 02598 /* Check the struct p_bno055 is empty */ 02599 if (p_bno055 == BNO055_INIT_VALUE) { 02600 return BNO055_E_NULL_PTR; 02601 } else { 02602 /*condition check for page, chip id is 02603 available in the page zero*/ 02604 if (p_bno055->page_id != BNO055_PAGE_ZERO) 02605 /* Write the page zero*/ 02606 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 02607 if ((stat_s8 == BNO055_SUCCESS) || 02608 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 02609 /* Read the raw temperature data */ 02610 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 02611 (p_bno055->dev_addr, 02612 BNO055_TEMP_REG, &data_u8, 02613 BNO055_GEN_READ_WRITE_LENGTH); 02614 *temp_s8 = data_u8; 02615 } else { 02616 com_rslt = BNO055_ERROR; 02617 } 02618 } 02619 return com_rslt; 02620 } 02621 #ifdef BNO055_FLOAT_ENABLE 02622 /*! 02623 * @brief This API is used to convert the accel x raw data 02624 * to meterpersecseq output as float 02625 * 02626 * @param accel_x_f : The accel x meterpersecseq data 02627 * 02628 * 02629 * 02630 * @return results of bus communication function 02631 * @retval 0 -> BNO055_SUCCESS 02632 * @retval 1 -> BNO055_ERROR 02633 * 02634 * 02635 */ 02636 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_x_msq( 02637 float *accel_x_f) 02638 { 02639 /* Variable used to return value of 02640 communication routine*/ 02641 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02642 s16 reg_accel_x_s16 = BNO055_INIT_VALUE; 02643 float data_f = BNO055_INIT_VALUE; 02644 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02645 /* Read the current accel unit and set the 02646 unit as m/s2 if the unit is in mg*/ 02647 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02648 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 02649 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 02650 if (com_rslt == BNO055_SUCCESS) { 02651 /* Read the accel raw x data*/ 02652 com_rslt += bno055_read_accel_x(®_accel_x_s16); 02653 p_bno055->delay_msec(BNO055_GEN_READ_WRITE_LENGTH); 02654 if (com_rslt == BNO055_SUCCESS) { 02655 /* Convert the raw accel x to m/s2*/ 02656 data_f = 02657 (float)(reg_accel_x_s16/BNO055_ACCEL_DIV_MSQ); 02658 *accel_x_f = data_f; 02659 } else { 02660 com_rslt = BNO055_ERROR; 02661 } 02662 } else { 02663 com_rslt = BNO055_ERROR; 02664 } 02665 return com_rslt; 02666 } 02667 /*! 02668 * @brief This API is used to convert the accel x raw data 02669 * to millig output as float 02670 * 02671 * @param accel_x_f : The accel x millig data 02672 * 02673 * 02674 * 02675 * @return results of bus communication function 02676 * @retval 0 -> BNO055_SUCCESS 02677 * @retval 1 -> BNO055_ERROR 02678 * 02679 * 02680 * 02681 */ 02682 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_x_mg( 02683 float *accel_x_f) 02684 { 02685 /* Variable used to return value of 02686 communication routine*/ 02687 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02688 s16 reg_accel_x_s16 = BNO055_INIT_VALUE; 02689 float data_f = BNO055_INIT_VALUE; 02690 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02691 /* Read the current accel unit and set the 02692 unit as mg if the unit is in m/s2*/ 02693 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02694 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 02695 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 02696 if (com_rslt == BNO055_SUCCESS) { 02697 /* Read the accel raw x data*/ 02698 com_rslt += bno055_read_accel_x(®_accel_x_s16); 02699 if (com_rslt == BNO055_SUCCESS) { 02700 /* Convert the raw accel x to m/s2*/ 02701 data_f = 02702 (float)(reg_accel_x_s16/BNO055_ACCEL_DIV_MG); 02703 *accel_x_f = data_f; 02704 } else { 02705 com_rslt = BNO055_ERROR; 02706 } 02707 } else { 02708 com_rslt = BNO055_ERROR; 02709 } 02710 return com_rslt; 02711 } 02712 /*! 02713 * @brief This API is used to convert the accel x raw data 02714 * to meterpersecseq output as float 02715 * 02716 * @param accel_y_f : The accel y meterpersecseq data 02717 * 02718 * 02719 * 02720 * @return results of bus communication function 02721 * @retval 0 -> BNO055_SUCCESS 02722 * @retval 1 -> BNO055_ERROR 02723 * 02724 * 02725 */ 02726 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_y_msq( 02727 float *accel_y_f) 02728 { 02729 /* Variable used to return value of 02730 communication routine*/ 02731 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02732 s16 reg_accel_y_s16 = BNO055_INIT_VALUE; 02733 float data_f = BNO055_INIT_VALUE; 02734 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02735 /* Read the current accel unit and set the 02736 unit as m/s2 if the unit is in mg*/ 02737 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02738 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 02739 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 02740 if (com_rslt == BNO055_SUCCESS) { 02741 com_rslt += bno055_read_accel_y(®_accel_y_s16); 02742 p_bno055->delay_msec(BNO055_GEN_READ_WRITE_LENGTH); 02743 if (com_rslt == BNO055_SUCCESS) { 02744 /* Convert the raw accel y to m/s2*/ 02745 data_f = 02746 (float)(reg_accel_y_s16/BNO055_ACCEL_DIV_MSQ); 02747 *accel_y_f = data_f; 02748 } else { 02749 com_rslt = BNO055_ERROR; 02750 } 02751 } else { 02752 com_rslt = BNO055_ERROR; 02753 } 02754 return com_rslt; 02755 } 02756 /*! 02757 * @brief This API is used to convert the accel y raw data 02758 * to millig output as float 02759 * 02760 * @param accel_y_f : The accel y millig data 02761 * 02762 * 02763 * 02764 * @return results of bus communication function 02765 * @retval 0 -> BNO055_SUCCESS 02766 * @retval 1 -> BNO055_ERROR 02767 * 02768 */ 02769 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_y_mg( 02770 float *accel_y_f) 02771 { 02772 /* Variable used to return value of 02773 communication routine*/ 02774 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02775 s16 reg_accel_y_s16 = BNO055_INIT_VALUE; 02776 float data = BNO055_INIT_VALUE; 02777 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02778 /* Read the current accel unit and set the 02779 unit as mg if the unit is in m/s2*/ 02780 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02781 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 02782 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 02783 if (com_rslt == BNO055_SUCCESS) { 02784 /* Read the accel raw z data*/ 02785 com_rslt += bno055_read_accel_y(®_accel_y_s16); 02786 if (com_rslt == BNO055_SUCCESS) { 02787 /* Convert the raw accel z to mg*/ 02788 data = (float)( 02789 reg_accel_y_s16/BNO055_ACCEL_DIV_MG); 02790 *accel_y_f = data; 02791 } else { 02792 com_rslt = BNO055_ERROR; 02793 } 02794 } else { 02795 com_rslt = BNO055_ERROR; 02796 } 02797 return com_rslt; 02798 } 02799 /*! 02800 * @brief This API is used to convert the accel z raw data 02801 * to meterpersecseq output as float 02802 * 02803 * @param accel_z_f : The accel z meterpersecseq data 02804 * 02805 * 02806 * 02807 * @return results of bus communication function 02808 * @retval 0 -> BNO055_SUCCESS 02809 * @retval 1 -> BNO055_ERROR 02810 * 02811 * 02812 */ 02813 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_z_msq( 02814 float *accel_z_f) 02815 { 02816 /* Variable used to return value of 02817 communication routine*/ 02818 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02819 s16 reg_accel_z_s16 = BNO055_INIT_VALUE; 02820 float data_f = BNO055_INIT_VALUE; 02821 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02822 /* Read the current accel unit and set the 02823 unit as m/s2 if the unit is in mg*/ 02824 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02825 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 02826 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 02827 if (com_rslt == BNO055_SUCCESS) { 02828 /* Read the accel raw z data*/ 02829 com_rslt += bno055_read_accel_z(®_accel_z_s16); 02830 p_bno055->delay_msec(BNO055_GEN_READ_WRITE_LENGTH); 02831 if (com_rslt == BNO055_SUCCESS) { 02832 /* Convert the raw accel z to m/s2*/ 02833 data_f = 02834 (float)(reg_accel_z_s16/BNO055_ACCEL_DIV_MSQ); 02835 *accel_z_f = data_f; 02836 } else { 02837 com_rslt = BNO055_ERROR; 02838 } 02839 } else { 02840 com_rslt = BNO055_ERROR; 02841 } 02842 return com_rslt; 02843 } 02844 /*! 02845 * @brief This API is used to convert the accel z raw data 02846 * to millig output as float 02847 * 02848 * @param accel_z_f : The accel z millig data 02849 * 02850 * 02851 * 02852 * @return results of bus communication function 02853 * @retval 0 -> BNO055_SUCCESS 02854 * @retval 1 -> BNO055_ERROR 02855 * 02856 * 02857 */ 02858 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_z_mg( 02859 float *accel_z_f) 02860 { 02861 /* Variable used to return value of 02862 communication routine*/ 02863 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02864 s16 reg_accel_z_s16 = BNO055_INIT_VALUE; 02865 float data_f = BNO055_INIT_VALUE; 02866 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02867 /* Read the current accel unit and set the 02868 unit as mg if the unit is in m/s2 */ 02869 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02870 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 02871 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 02872 if (com_rslt == BNO055_SUCCESS) { 02873 /* Read the accel raw z data*/ 02874 com_rslt += bno055_read_accel_z(®_accel_z_s16); 02875 if (com_rslt == BNO055_SUCCESS) { 02876 /* Convert the raw accel x to mg*/ 02877 data_f = 02878 (float)(reg_accel_z_s16/BNO055_ACCEL_DIV_MG); 02879 *accel_z_f = data_f; 02880 } else { 02881 com_rslt = BNO055_ERROR; 02882 } 02883 } else { 02884 com_rslt = BNO055_ERROR; 02885 } 02886 return com_rslt; 02887 } 02888 /*! 02889 * @brief This API is used to convert the accel xyz raw data 02890 * to meterpersecseq output as float 02891 * 02892 * @param accel_xyz : The meterpersecseq data of accel xyz 02893 * 02894 * Parameter | result 02895 * --------- | ----------------- 02896 * x | meterpersecseq data of accel 02897 * y | meterpersecseq data of accel 02898 * z | meterpersecseq data of accel 02899 * 02900 * @return results of bus communication function 02901 * @retval 0 -> BNO055_SUCCESS 02902 * @retval 1 -> BNO055_ERROR 02903 * 02904 * 02905 */ 02906 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_xyz_msq( 02907 struct bno055_accel_float_t *accel_xyz) 02908 { 02909 /* Variable used to return value of 02910 communication routine*/ 02911 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02912 struct bno055_accel_t reg_accel_xyz = { 02913 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02914 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02915 /* Read the current accel unit and set the 02916 unit as m/s2 if the unit is in mg*/ 02917 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02918 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 02919 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 02920 if (com_rslt == BNO055_SUCCESS) { 02921 /* Read the accel raw xyz data*/ 02922 com_rslt += bno055_read_accel_xyz(®_accel_xyz); 02923 if (com_rslt == BNO055_SUCCESS) { 02924 /* Convert the accel raw xyz to meterpersecseq*/ 02925 accel_xyz->x = 02926 (float)(reg_accel_xyz.x/BNO055_ACCEL_DIV_MSQ); 02927 accel_xyz->y = 02928 (float)(reg_accel_xyz.y/BNO055_ACCEL_DIV_MSQ); 02929 accel_xyz->z = 02930 (float)(reg_accel_xyz.z/BNO055_ACCEL_DIV_MSQ); 02931 } else { 02932 com_rslt = BNO055_ERROR; 02933 } 02934 } else { 02935 com_rslt = BNO055_ERROR; 02936 } 02937 return com_rslt; 02938 } 02939 /*! 02940 * @brief This API is used to convert the accel xyz raw data 02941 * to millig output as float 02942 * 02943 * @param accel_xyz : The millig data of accel xyz 02944 * 02945 * Parameter | result 02946 * --------- | ----------------- 02947 * x | millig data of accel 02948 * y | millig data of accel 02949 * z | millig data of accel 02950 * 02951 * 02952 * @return results of bus communication function 02953 * @retval 0 -> BNO055_SUCCESS 02954 * @retval 1 -> BNO055_ERROR 02955 * 02956 * 02957 */ 02958 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_accel_xyz_mg( 02959 struct bno055_accel_float_t *accel_xyz) 02960 { 02961 /* Variable used to return value of 02962 communication routine*/ 02963 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 02964 struct bno055_accel_t reg_accel_xyz = { 02965 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 02966 u8 accel_unit_u8 = BNO055_INIT_VALUE; 02967 /* Read the current accel unit and set the 02968 unit as mg if the unit is in m/s2*/ 02969 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 02970 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 02971 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 02972 if (com_rslt == BNO055_SUCCESS) { 02973 /* Read the accel raw y data*/ 02974 com_rslt += bno055_read_accel_xyz(®_accel_xyz); 02975 if (com_rslt == BNO055_SUCCESS) { 02976 /*Convert the accel raw xyz to millig */ 02977 accel_xyz->x = 02978 (float)(reg_accel_xyz.x/BNO055_ACCEL_DIV_MG); 02979 accel_xyz->y = 02980 (float)(reg_accel_xyz.y/BNO055_ACCEL_DIV_MG); 02981 accel_xyz->z = 02982 (float)(reg_accel_xyz.z/BNO055_ACCEL_DIV_MG); 02983 } else { 02984 com_rslt = BNO055_ERROR; 02985 } 02986 } else { 02987 com_rslt = BNO055_ERROR; 02988 } 02989 return com_rslt; 02990 } 02991 /*! 02992 * @brief This API is used to convert the mag x raw data 02993 * to microTesla output as float 02994 * 02995 * @param mag_x_f : The mag x microTesla data 02996 * 02997 * 02998 * 02999 * @return results of bus communication function 03000 * @retval 0 -> BNO055_SUCCESS 03001 * @retval 1 -> BNO055_ERROR 03002 * 03003 * 03004 */ 03005 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_mag_x_uT( 03006 float *mag_x_f) 03007 { 03008 /* Variable used to return value of 03009 communication routine*/ 03010 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03011 s16 reg_mag_x_s16 = BNO055_INIT_VALUE; 03012 float data_f = BNO055_INIT_VALUE; 03013 /* Read raw mag x data */ 03014 com_rslt = bno055_read_mag_x(®_mag_x_s16); 03015 if (com_rslt == BNO055_SUCCESS) { 03016 /* Convert the raw mag x to microTesla*/ 03017 data_f = (float)(reg_mag_x_s16/BNO055_MAG_DIV_UT); 03018 *mag_x_f = data_f; 03019 } else { 03020 com_rslt = BNO055_ERROR; 03021 } 03022 return com_rslt; 03023 } 03024 /*! 03025 * @brief This API is used to convert the mag y raw data 03026 * to microTesla output as float 03027 * 03028 * @param mag_y_f : The mag y microTesla data 03029 * 03030 * 03031 * 03032 * @return results of bus communication function 03033 * @retval 0 -> BNO055_SUCCESS 03034 * @retval 1 -> BNO055_ERROR 03035 * 03036 */ 03037 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_mag_y_uT( 03038 float *mag_y_f) 03039 { 03040 /* Variable used to return value of 03041 communication routine*/ 03042 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03043 s16 reg_mag_y_s16 = BNO055_INIT_VALUE; 03044 float data_f = BNO055_INIT_VALUE; 03045 /* Read raw mag y data */ 03046 com_rslt = bno055_read_mag_y(®_mag_y_s16); 03047 if (com_rslt == BNO055_SUCCESS) { 03048 /* Convert the raw mag y to microTesla*/ 03049 data_f = (float)(reg_mag_y_s16/BNO055_MAG_DIV_UT); 03050 *mag_y_f = data_f; 03051 } else { 03052 com_rslt = BNO055_ERROR; 03053 } 03054 return com_rslt; 03055 } 03056 /*! 03057 * @brief This API is used to convert the mag z raw data 03058 * to microTesla output as float 03059 * 03060 * @param mag_z_f : The mag z microTesla data 03061 * 03062 * 03063 * 03064 * @return results of bus communication function 03065 * @retval 0 -> BNO055_SUCCESS 03066 * @retval 1 -> BNO055_ERROR 03067 * 03068 */ 03069 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_mag_z_uT( 03070 float *mag_z_f) 03071 { 03072 /* Variable used to return value of 03073 communication routine*/ 03074 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03075 s16 reg_mag_z_s16 = BNO055_INIT_VALUE; 03076 float data_f = BNO055_INIT_VALUE; 03077 /* Read raw mag z data */ 03078 com_rslt = bno055_read_mag_z(®_mag_z_s16); 03079 if (com_rslt == BNO055_SUCCESS) { 03080 /* Convert the raw mag z to microTesla*/ 03081 data_f = (float)(reg_mag_z_s16/BNO055_MAG_DIV_UT); 03082 *mag_z_f = data_f; 03083 } else { 03084 com_rslt = BNO055_ERROR; 03085 } 03086 return com_rslt; 03087 } 03088 /*! 03089 * @brief This API is used to convert the mag yz raw data 03090 * to microTesla output as float 03091 * 03092 * @param mag_xyz_data : The microTesla data of mag xyz 03093 * 03094 * Parameter | result 03095 * --------- | ----------------- 03096 * x | microTesla data of mag 03097 * y | microTesla data of mag 03098 * z | microTesla data of mag 03099 * 03100 * 03101 * @return results of bus communication function 03102 * @retval 0 -> BNO055_SUCCESS 03103 * @retval 1 -> BNO055_ERROR 03104 * 03105 */ 03106 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_mag_xyz_uT( 03107 struct bno055_mag_float_t *mag_xyz_data) 03108 { 03109 /* Variable used to return value of 03110 communication routine*/ 03111 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03112 struct bno055_mag_t mag_xyz = { 03113 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 03114 /* Read raw mag x data */ 03115 com_rslt = bno055_read_mag_xyz(&mag_xyz); 03116 if (com_rslt == BNO055_SUCCESS) { 03117 /* Convert mag raw xyz to microTesla*/ 03118 mag_xyz_data->x = (float)(mag_xyz.x/BNO055_MAG_DIV_UT); 03119 mag_xyz_data->y = (float)(mag_xyz.y/BNO055_MAG_DIV_UT); 03120 mag_xyz_data->z = (float)(mag_xyz.z/BNO055_MAG_DIV_UT); 03121 } else { 03122 com_rslt = BNO055_ERROR; 03123 } 03124 03125 return com_rslt; 03126 } 03127 /*! 03128 * @brief This API is used to convert the gyro x raw data 03129 * to dps output as float 03130 * 03131 * @param gyro_x_f : The gyro x dps float data 03132 * 03133 * 03134 * 03135 * @return results of bus communication function 03136 * @retval 0 -> BNO055_SUCCESS 03137 * @retval 1 -> BNO055_ERROR 03138 */ 03139 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_x_dps( 03140 float *gyro_x_f) 03141 { 03142 /* Variable used to return value of 03143 communication routine*/ 03144 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03145 s16 reg_gyro_x_s16 = BNO055_INIT_VALUE; 03146 float data_f = BNO055_INIT_VALUE; 03147 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03148 /* Read the current gyro unit and set the 03149 unit as dps if the unit is in rps */ 03150 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03151 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 03152 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 03153 if (com_rslt == BNO055_SUCCESS) { 03154 /* Read gyro raw x data */ 03155 com_rslt += bno055_read_gyro_x(®_gyro_x_s16); 03156 if (com_rslt == BNO055_SUCCESS) { 03157 /* Convert the raw gyro x to dps*/ 03158 data_f = 03159 (float)(reg_gyro_x_s16/BNO055_GYRO_DIV_DPS); 03160 *gyro_x_f = data_f; 03161 } else { 03162 com_rslt = BNO055_ERROR; 03163 } 03164 } else { 03165 com_rslt = BNO055_ERROR; 03166 } 03167 return com_rslt; 03168 } 03169 /*! 03170 * @brief This API is used to convert the gyro x raw data 03171 * to rps output as float 03172 * 03173 * @param gyro_x_f : The gyro x dps float data 03174 * 03175 * 03176 * 03177 * @return results of bus communication function 03178 * @retval 0 -> BNO055_SUCCESS 03179 * @retval 1 -> BNO055_ERROR 03180 * 03181 */ 03182 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_x_rps( 03183 float *gyro_x_f) 03184 { 03185 /* Variable used to return value of 03186 communication routine*/ 03187 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03188 s16 reg_gyro_x_s16 = BNO055_INIT_VALUE; 03189 float data_f = BNO055_INIT_VALUE; 03190 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03191 /* Read the current gyro unit and set the 03192 unit as rps if the unit is in dps */ 03193 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03194 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 03195 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 03196 if (com_rslt == BNO055_SUCCESS) { 03197 /* Read gyro raw x data */ 03198 com_rslt += bno055_read_gyro_x(®_gyro_x_s16); 03199 if (com_rslt == BNO055_SUCCESS) { 03200 /* Convert the raw gyro x to rps*/ 03201 data_f = 03202 (float)(reg_gyro_x_s16/BNO055_GYRO_DIV_RPS); 03203 *gyro_x_f = data_f; 03204 } else { 03205 com_rslt = BNO055_ERROR; 03206 } 03207 } else { 03208 com_rslt = BNO055_ERROR; 03209 } 03210 return com_rslt; 03211 } 03212 /*! 03213 * @brief This API is used to convert the gyro y raw data 03214 * to dps output as float 03215 * 03216 * @param gyro_y_f : The gyro y dps float data 03217 * 03218 * 03219 * 03220 * @return results of bus communication function 03221 * @retval 0 -> BNO055_SUCCESS 03222 * @retval 1 -> BNO055_ERROR 03223 * 03224 */ 03225 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_y_dps( 03226 float *gyro_y_f) 03227 { 03228 /* Variable used to return value of 03229 communication routine*/ 03230 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03231 s16 reg_gyro_y_s16 = BNO055_INIT_VALUE; 03232 float data_f = BNO055_INIT_VALUE; 03233 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03234 /* Read the current gyro unit and set the 03235 unit as dps if the unit is in rps */ 03236 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03237 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 03238 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 03239 if (com_rslt == BNO055_SUCCESS) { 03240 /* Read gyro raw y data */ 03241 com_rslt += bno055_read_gyro_y(®_gyro_y_s16); 03242 if (com_rslt == BNO055_SUCCESS) { 03243 /* Convert the raw gyro x to dps*/ 03244 data_f = 03245 (float)(reg_gyro_y_s16/BNO055_GYRO_DIV_DPS); 03246 *gyro_y_f = data_f; 03247 } else { 03248 com_rslt = BNO055_ERROR; 03249 } 03250 } else { 03251 com_rslt = BNO055_ERROR; 03252 } 03253 return com_rslt; 03254 } 03255 /*! 03256 * @brief This API is used to convert the gyro y raw data 03257 * to rps output as float 03258 * 03259 * @param gyro_y_f : The gyro y dps float data 03260 * 03261 * 03262 * 03263 * @return results of bus communication function 03264 * @retval 0 -> BNO055_SUCCESS 03265 * @retval 1 -> BNO055_ERROR 03266 * 03267 * 03268 */ 03269 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_y_rps( 03270 float *gyro_y_f) 03271 { 03272 /* Variable used to return value of 03273 communication routine*/ 03274 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03275 s16 reg_gyro_y_s16 = BNO055_INIT_VALUE; 03276 float data_f = BNO055_INIT_VALUE; 03277 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03278 /* Read the current gyro unit and set the 03279 unit as rps if the unit is in dps */ 03280 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03281 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 03282 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 03283 if (com_rslt == BNO055_SUCCESS) { 03284 /* Read gyro raw y data */ 03285 com_rslt += bno055_read_gyro_y(®_gyro_y_s16); 03286 if (com_rslt == BNO055_SUCCESS) { 03287 /* Convert the raw gyro x to rps*/ 03288 data_f = 03289 (float)(reg_gyro_y_s16/BNO055_GYRO_DIV_RPS); 03290 *gyro_y_f = data_f; 03291 } else { 03292 com_rslt = BNO055_ERROR; 03293 } 03294 } else { 03295 com_rslt = BNO055_ERROR; 03296 } 03297 return com_rslt; 03298 } 03299 /*! 03300 * @brief This API is used to convert the gyro z raw data 03301 * to dps output as float 03302 * 03303 * @param gyro_z_f : The gyro z dps float data 03304 * 03305 * 03306 * 03307 * @return results of bus communication function 03308 * @retval 0 -> BNO055_SUCCESS 03309 * @retval 1 -> BNO055_ERROR 03310 * 03311 */ 03312 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_z_dps( 03313 float *gyro_z_f) 03314 { 03315 /* Variable used to return value of 03316 communication routine*/ 03317 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03318 s16 reg_gyro_z_s16 = BNO055_INIT_VALUE; 03319 float data_f = BNO055_INIT_VALUE; 03320 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03321 /* Read the current gyro unit and set the 03322 unit as dps if the unit is in rps */ 03323 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03324 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 03325 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 03326 if (com_rslt == BNO055_SUCCESS) { 03327 /* Read gyro raw z data */ 03328 com_rslt += bno055_read_gyro_z(®_gyro_z_s16); 03329 if (com_rslt == BNO055_SUCCESS) { 03330 /* Convert the raw gyro x to dps*/ 03331 data_f = 03332 (float)(reg_gyro_z_s16/BNO055_GYRO_DIV_DPS); 03333 *gyro_z_f = data_f; 03334 } else { 03335 com_rslt = BNO055_ERROR; 03336 } 03337 } else { 03338 com_rslt = BNO055_ERROR; 03339 } 03340 return com_rslt; 03341 } 03342 /*! 03343 * @brief This API is used to convert the gyro z raw data 03344 * to rps output as float 03345 * 03346 * @param gyro_z_f : The gyro z rps float data 03347 * 03348 * 03349 * 03350 * @return results of bus communication function 03351 * @retval 0 -> BNO055_SUCCESS 03352 * @retval 1 -> BNO055_ERROR 03353 * 03354 */ 03355 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_z_rps( 03356 float *gyro_z_f) 03357 { 03358 /* Variable used to return value of 03359 communication routine*/ 03360 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03361 s16 reg_gyro_z_s16 = BNO055_INIT_VALUE; 03362 float data_f = BNO055_INIT_VALUE; 03363 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03364 /* Read the current gyro unit and set the 03365 unit as rps if the unit is in dps */ 03366 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03367 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 03368 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 03369 if (com_rslt == BNO055_SUCCESS) { 03370 /* Read gyro raw x data */ 03371 com_rslt += bno055_read_gyro_z(®_gyro_z_s16); 03372 if (com_rslt == BNO055_SUCCESS) { 03373 /* Convert the raw gyro x to rps*/ 03374 data_f = 03375 (float)(reg_gyro_z_s16/BNO055_GYRO_DIV_RPS); 03376 *gyro_z_f = data_f; 03377 } else { 03378 com_rslt = BNO055_ERROR; 03379 } 03380 } else { 03381 com_rslt = BNO055_ERROR; 03382 } 03383 return com_rslt; 03384 } 03385 /*! 03386 * @brief This API is used to convert the gyro xyz raw data 03387 * to dps output as float 03388 * 03389 * @param gyro_xyz_data : The dps data of gyro xyz 03390 * 03391 * Parameter | result 03392 * --------- | ----------------- 03393 * x | dps data of gyro 03394 * y | dps data of gyro 03395 * z | dps data of gyro 03396 * 03397 * 03398 * @return results of bus communication function 03399 * @retval 0 -> BNO055_SUCCESS 03400 * @retval 1 -> BNO055_ERROR 03401 * 03402 * 03403 */ 03404 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_xyz_dps( 03405 struct bno055_gyro_float_t *gyro_xyz_data) 03406 { 03407 /* Variable used to return value of 03408 communication routine*/ 03409 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03410 struct bno055_gyro_t gyro_xyz = { 03411 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 03412 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03413 /* Read the current gyro unit and set the 03414 unit as dps if the unit is in rps */ 03415 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03416 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 03417 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 03418 if (com_rslt == BNO055_SUCCESS) { 03419 /* Read gyro raw xyz data */ 03420 com_rslt += bno055_read_gyro_xyz(&gyro_xyz); 03421 if (com_rslt == BNO055_SUCCESS) { 03422 /* Convert gyro raw xyz to dps*/ 03423 gyro_xyz_data->x = 03424 (float)(gyro_xyz.x/BNO055_GYRO_DIV_DPS); 03425 gyro_xyz_data->y = 03426 (float)(gyro_xyz.y/BNO055_GYRO_DIV_DPS); 03427 gyro_xyz_data->z = 03428 (float)(gyro_xyz.z/BNO055_GYRO_DIV_DPS); 03429 } else { 03430 com_rslt = BNO055_ERROR; 03431 } 03432 } else { 03433 com_rslt = BNO055_ERROR; 03434 } 03435 return com_rslt; 03436 } 03437 /*! 03438 * @brief This API is used to convert the gyro xyz raw data 03439 * to rps output as float 03440 * 03441 * @param gyro_xyz_data : The rps data of gyro xyz 03442 * 03443 * Parameter | result 03444 * --------- | ----------------- 03445 * x | rps data of gyro 03446 * y | rps data of gyro 03447 * z | rps data of gyro 03448 * 03449 * 03450 * @return results of bus communication function 03451 * @retval 0 -> BNO055_SUCCESS 03452 * @retval 1 -> BNO055_ERROR 03453 * 03454 * 03455 */ 03456 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gyro_xyz_rps( 03457 struct bno055_gyro_float_t *gyro_xyz_data) 03458 { 03459 /* Variable used to return value of 03460 communication routine*/ 03461 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03462 struct bno055_gyro_t gyro_xyz = {BNO055_INIT_VALUE, 03463 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 03464 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 03465 /* Read the current gyro unit and set the 03466 unit as rps if the unit is in dps */ 03467 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 03468 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 03469 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 03470 if (com_rslt == BNO055_SUCCESS) { 03471 /* Read gyro raw xyz data */ 03472 com_rslt += bno055_read_gyro_xyz(&gyro_xyz); 03473 if (com_rslt == BNO055_SUCCESS) { 03474 /* Convert gyro raw xyz to rps*/ 03475 gyro_xyz_data->x = 03476 (float)(gyro_xyz.x/BNO055_GYRO_DIV_RPS); 03477 gyro_xyz_data->y = 03478 (float)(gyro_xyz.y/BNO055_GYRO_DIV_RPS); 03479 gyro_xyz_data->z = 03480 (float)(gyro_xyz.z/BNO055_GYRO_DIV_RPS); 03481 } else { 03482 com_rslt = BNO055_ERROR; 03483 } 03484 } else { 03485 com_rslt = BNO055_ERROR; 03486 } 03487 return com_rslt; 03488 } 03489 /*! 03490 * @brief This API is used to convert the Euler h raw data 03491 * to degree output as float 03492 * 03493 * @param euler_h_f : The float value of Euler h degree 03494 * 03495 * @return results of bus communication function 03496 * @retval 0 -> BNO055_SUCCESS 03497 * @retval 1 -> BNO055_ERROR 03498 * 03499 * 03500 */ 03501 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_h_deg( 03502 float *euler_h_f) 03503 { 03504 /* Variable used to return value of 03505 communication routine*/ 03506 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03507 s16 reg_euler_h_s16 = BNO055_INIT_VALUE; 03508 float data_f = BNO055_INIT_VALUE; 03509 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03510 /* Read the current Euler unit and set the 03511 unit as degree if the unit is in radians */ 03512 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03513 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 03514 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 03515 if (com_rslt == BNO055_SUCCESS) { 03516 /* Read Euler raw h data*/ 03517 com_rslt += bno055_read_euler_h(®_euler_h_s16); 03518 if (com_rslt == BNO055_SUCCESS) { 03519 /* Convert raw Euler h data to degree*/ 03520 data_f = 03521 (float)(reg_euler_h_s16/BNO055_EULER_DIV_DEG); 03522 *euler_h_f = data_f; 03523 } else { 03524 com_rslt = BNO055_ERROR; 03525 } 03526 } else { 03527 com_rslt = BNO055_ERROR; 03528 } 03529 return com_rslt; 03530 } 03531 /*! 03532 * @brief This API is used to convert the Euler h raw data 03533 * to radians output as float 03534 * 03535 * @param euler_h_f : The float value of Euler h radians 03536 * 03537 * @return results of bus communication function 03538 * @retval 0 -> BNO055_SUCCESS 03539 * @retval 1 -> BNO055_ERROR 03540 * 03541 * 03542 */ 03543 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_h_rad( 03544 float *euler_h_f) 03545 { 03546 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03547 s16 reg_euler_h_s16 = BNO055_INIT_VALUE; 03548 float data_f = BNO055_INIT_VALUE; 03549 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03550 03551 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03552 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 03553 /* Read the current Euler unit and set the 03554 unit as radians if the unit is in degree */ 03555 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 03556 if (com_rslt == BNO055_SUCCESS) { 03557 /* Read Euler raw h data*/ 03558 com_rslt += bno055_read_euler_h(®_euler_h_s16); 03559 if (com_rslt == BNO055_SUCCESS) { 03560 /* Convert raw Euler h data to degree*/ 03561 data_f = 03562 (float)(reg_euler_h_s16/BNO055_EULER_DIV_RAD); 03563 *euler_h_f = data_f; 03564 } else { 03565 com_rslt = BNO055_ERROR; 03566 } 03567 } else { 03568 com_rslt = BNO055_ERROR; 03569 } 03570 return com_rslt; 03571 } 03572 /*! 03573 * @brief This API is used to convert the Euler r raw data 03574 * to degree output as float 03575 * 03576 * @param euler_r_f : The float value of Euler r degree 03577 * 03578 * @return results of bus communication function 03579 * @retval 0 -> BNO055_SUCCESS 03580 * @retval 1 -> BNO055_ERROR 03581 * 03582 */ 03583 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_r_deg( 03584 float *euler_r_f) 03585 { 03586 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03587 s16 reg_euler_r = BNO055_INIT_VALUE; 03588 float data_f = BNO055_INIT_VALUE; 03589 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03590 /* Read the current Euler unit and set the 03591 unit as degree if the unit is in radians */ 03592 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03593 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 03594 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 03595 if (com_rslt == BNO055_SUCCESS) { 03596 /* Read Euler raw r data*/ 03597 com_rslt += bno055_read_euler_r(®_euler_r); 03598 if (com_rslt == BNO055_SUCCESS) { 03599 /* Convert raw Euler r data to degree*/ 03600 data_f = (float)( 03601 reg_euler_r/BNO055_EULER_DIV_DEG); 03602 *euler_r_f = data_f; 03603 } else { 03604 com_rslt = BNO055_ERROR; 03605 } 03606 } else { 03607 com_rslt = BNO055_ERROR; 03608 } 03609 return com_rslt; 03610 } 03611 /*! 03612 * @brief This API is used to convert the Euler r raw data 03613 * to radians output as float 03614 * 03615 * @param euler_r_f : The float value of Euler r radians 03616 * 03617 * @return results of bus communication function 03618 * @retval 0 -> BNO055_SUCCESS 03619 * @retval 1 -> BNO055_ERROR 03620 * 03621 */ 03622 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_r_rad( 03623 float *euler_r_f) 03624 { 03625 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03626 s16 reg_euler_r_f = BNO055_INIT_VALUE; 03627 float data_f = BNO055_INIT_VALUE; 03628 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03629 /* Read the current Euler unit and set the 03630 unit as radians if the unit is in degree */ 03631 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03632 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 03633 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 03634 if (com_rslt == BNO055_SUCCESS) { 03635 /* Read Euler raw r data*/ 03636 com_rslt += bno055_read_euler_r(®_euler_r_f); 03637 if (com_rslt == BNO055_SUCCESS) { 03638 /* Convert raw Euler r data to radians*/ 03639 data_f = 03640 (float)(reg_euler_r_f/BNO055_EULER_DIV_RAD); 03641 *euler_r_f = data_f; 03642 } else { 03643 com_rslt = BNO055_ERROR; 03644 } 03645 } else { 03646 com_rslt = BNO055_ERROR; 03647 } 03648 return com_rslt; 03649 } 03650 /*! 03651 * @brief This API is used to convert the Euler p raw data 03652 * to degree output as float 03653 * 03654 * @param euler_p_f : The float value of Euler p degree 03655 * 03656 * @return results of bus communication function 03657 * @retval 0 -> BNO055_SUCCESS 03658 * @retval 1 -> BNO055_ERROR 03659 * 03660 */ 03661 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_p_deg( 03662 float *euler_p_f) 03663 { 03664 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03665 s16 reg_euler_p_f = BNO055_INIT_VALUE; 03666 float data_f = BNO055_INIT_VALUE; 03667 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03668 /* Read the current Euler unit and set the 03669 unit as degree if the unit is in radians */ 03670 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03671 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 03672 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 03673 if (com_rslt == BNO055_SUCCESS) { 03674 /* Read Euler raw p data*/ 03675 com_rslt += bno055_read_euler_p(®_euler_p_f); 03676 if (com_rslt == BNO055_SUCCESS) { 03677 /* Convert raw Euler p data to degree*/ 03678 data_f = 03679 (float)(reg_euler_p_f/BNO055_EULER_DIV_DEG); 03680 *euler_p_f = data_f; 03681 } else { 03682 com_rslt = BNO055_ERROR; 03683 } 03684 } else { 03685 com_rslt = BNO055_ERROR; 03686 } 03687 return com_rslt; 03688 } 03689 /*! 03690 * @brief This API is used to convert the Euler p raw data 03691 * to radians output as float 03692 * 03693 * @param euler_p_f : The float value of Euler p radians 03694 * 03695 * @return results of bus communication function 03696 * @retval 0 -> BNO055_SUCCESS 03697 * @retval 1 -> BNO055_ERROR 03698 * 03699 * 03700 */ 03701 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_p_rad( 03702 float *euler_p_f) 03703 { 03704 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03705 s16 reg_euler_p_f = BNO055_INIT_VALUE; 03706 float data_f = BNO055_INIT_VALUE; 03707 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03708 /* Read the current Euler unit and set the 03709 unit as radians if the unit is in degree */ 03710 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03711 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 03712 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 03713 if (com_rslt == BNO055_SUCCESS) { 03714 /* Read Euler raw r data*/ 03715 com_rslt += bno055_read_euler_p(®_euler_p_f); 03716 if (com_rslt == BNO055_SUCCESS) { 03717 /* Convert raw Euler r data to radians*/ 03718 data_f = 03719 (float)(reg_euler_p_f/BNO055_EULER_DIV_RAD); 03720 *euler_p_f = data_f; 03721 } else { 03722 com_rslt = BNO055_ERROR; 03723 } 03724 } else { 03725 com_rslt = BNO055_ERROR; 03726 } 03727 return com_rslt; 03728 } 03729 /*! 03730 * @brief This API is used to convert the Euler hrp raw data 03731 * to degree output as float 03732 * 03733 * @param euler_hpr : The degree data of Euler hrp 03734 * 03735 * Parameter | result 03736 * --------- | ----------------- 03737 * h | degree data of Euler 03738 * r | degree data of Euler 03739 * p | degree data of Euler 03740 * 03741 * 03742 * @return results of bus communication function 03743 * @retval 0 -> BNO055_SUCCESS 03744 * @retval 1 -> BNO055_ERROR 03745 * 03746 */ 03747 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_hpr_deg( 03748 struct bno055_euler_float_t *euler_hpr) 03749 { 03750 /* Variable used to return value of 03751 communication routine*/ 03752 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03753 struct bno055_euler_t reg_euler = {BNO055_INIT_VALUE, 03754 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 03755 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03756 /* Read the current Euler unit and set the 03757 unit as degree if the unit is in radians */ 03758 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03759 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 03760 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 03761 if (com_rslt == BNO055_SUCCESS) { 03762 /* Read Euler raw hrp data*/ 03763 com_rslt += bno055_read_euler_hrp(®_euler); 03764 if (com_rslt == BNO055_SUCCESS) { 03765 /* Convert raw Euler hrp to degree*/ 03766 euler_hpr->h = 03767 (float)(reg_euler.h/BNO055_EULER_DIV_DEG); 03768 euler_hpr->p = 03769 (float)(reg_euler.p/BNO055_EULER_DIV_DEG); 03770 euler_hpr->r = 03771 (float)(reg_euler.r/BNO055_EULER_DIV_DEG); 03772 } else { 03773 com_rslt = BNO055_ERROR; 03774 } 03775 } else { 03776 com_rslt = BNO055_ERROR; 03777 } 03778 return com_rslt; 03779 } 03780 /*! 03781 * @brief This API is used to convert the Euler xyz raw data 03782 * to radians output as float 03783 * 03784 * @param euler_hpr : The radians data of Euler hrp 03785 * 03786 * Parameter | result 03787 * --------- | ----------------- 03788 * h | radians data of Euler 03789 * r | radians data of Euler 03790 * p | radians data of Euler 03791 * 03792 * 03793 * @return results of bus communication function 03794 * @retval 0 -> BNO055_SUCCESS 03795 * @retval 1 -> BNO055_ERROR 03796 * 03797 */ 03798 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_euler_hpr_rad( 03799 struct bno055_euler_float_t *euler_hpr) 03800 { 03801 /* Variable used to return value of 03802 communication routine*/ 03803 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03804 struct bno055_euler_t reg_euler = {BNO055_INIT_VALUE, 03805 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 03806 u8 euler_unit_u8 = BNO055_INIT_VALUE; 03807 /* Read the current Euler unit and set the 03808 unit as radians if the unit is in degree */ 03809 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 03810 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 03811 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 03812 if (com_rslt == BNO055_SUCCESS) { 03813 /* Read Euler raw hrp data*/ 03814 com_rslt += bno055_read_euler_hrp(®_euler); 03815 if (com_rslt == BNO055_SUCCESS) { 03816 /* Convert raw hrp to radians */ 03817 euler_hpr->h = 03818 (float)(reg_euler.h/BNO055_EULER_DIV_RAD); 03819 euler_hpr->p = 03820 (float)(reg_euler.p/BNO055_EULER_DIV_RAD); 03821 euler_hpr->r = 03822 (float)(reg_euler.r/BNO055_EULER_DIV_RAD); 03823 } else { 03824 com_rslt = BNO055_ERROR; 03825 } 03826 } else { 03827 com_rslt = BNO055_ERROR; 03828 } 03829 return com_rslt; 03830 } 03831 /*! 03832 * @brief This API is used to convert the linear 03833 * accel x raw data to meterpersecseq output as float 03834 * 03835 * @param linear_accel_x_f : The float value of linear accel x meterpersecseq 03836 * 03837 * @return results of bus communication function 03838 * @retval 0 -> BNO055_SUCCESS 03839 * @retval 1 -> BNO055_ERROR 03840 */ 03841 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_linear_accel_x_msq( 03842 float *linear_accel_x_f) 03843 { 03844 /* Variable used to return value of 03845 communication routine*/ 03846 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03847 s16 reg_linear_accel_x_s16 = BNO055_INIT_VALUE; 03848 float data_f = BNO055_INIT_VALUE; 03849 /* Read the raw x of linear accel */ 03850 com_rslt = bno055_read_linear_accel_x(®_linear_accel_x_s16); 03851 if (com_rslt == BNO055_SUCCESS) { 03852 /* Convert the raw linear accel x to m/s2*/ 03853 data_f = 03854 (float)(reg_linear_accel_x_s16/BNO055_LINEAR_ACCEL_DIV_MSQ); 03855 *linear_accel_x_f = data_f; 03856 } else { 03857 com_rslt = BNO055_ERROR; 03858 } 03859 return com_rslt; 03860 } 03861 /*! 03862 * @brief This API is used to convert the linear 03863 * accel y raw data to meterpersecseq output as float 03864 * 03865 * @param linear_accel_y_f : The float value of linear accel y meterpersecseq 03866 * 03867 * @return results of bus communication function 03868 * @retval 0 -> BNO055_SUCCESS 03869 * @retval 1 -> BNO055_ERROR 03870 */ 03871 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_linear_accel_y_msq( 03872 float *linear_accel_y_f) 03873 { 03874 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03875 s16 reg_linear_accel_y = BNO055_INIT_VALUE; 03876 float data_f = BNO055_INIT_VALUE; 03877 /* Read the raw y of linear accel */ 03878 com_rslt = bno055_read_linear_accel_y(®_linear_accel_y); 03879 if (com_rslt == BNO055_SUCCESS) { 03880 /* Convert the raw linear accel x to m/s2*/ 03881 data_f = (float) 03882 (reg_linear_accel_y/BNO055_LINEAR_ACCEL_DIV_MSQ); 03883 *linear_accel_y_f = data_f; 03884 } else { 03885 com_rslt = BNO055_ERROR; 03886 } 03887 return com_rslt; 03888 } 03889 /*! 03890 * @brief This API is used to convert the linear 03891 * accel z raw data to meterpersecseq output as float 03892 * 03893 * @param linear_accel_z_f : The float value of linear accel z meterpersecseq 03894 * 03895 * @return results of bus communication function 03896 * @retval 0 -> BNO055_SUCCESS 03897 * @retval 1 -> BNO055_ERROR 03898 * 03899 */ 03900 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_linear_accel_z_msq( 03901 float *linear_accel_z_f) 03902 { 03903 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03904 s16 reg_linear_accel_z = BNO055_INIT_VALUE; 03905 float data_f = BNO055_INIT_VALUE; 03906 /* Read the raw x of linear accel */ 03907 com_rslt = bno055_read_linear_accel_z(®_linear_accel_z); 03908 if (com_rslt == BNO055_SUCCESS) { 03909 /* Convert the raw linear accel z to m/s2*/ 03910 data_f = (float) 03911 (reg_linear_accel_z/BNO055_LINEAR_ACCEL_DIV_MSQ); 03912 *linear_accel_z_f = data_f; 03913 } else { 03914 com_rslt = BNO055_ERROR; 03915 } 03916 return com_rslt; 03917 } 03918 /*! 03919 * @brief This API is used to convert the linear accel xyz raw data 03920 * to meterpersecseq output as float 03921 * 03922 * @param linear_accel_xyz : The meterpersecseq data of linear accel xyz 03923 * 03924 * Parameter | result 03925 * --------- | ----------------- 03926 * x | meterpersecseq data of linear accel 03927 * y | meterpersecseq data of linear accel 03928 * z | meterpersecseq data of linear accel 03929 * 03930 * 03931 * @return results of bus communication function 03932 * @retval 0 -> BNO055_SUCCESS 03933 * @retval 1 -> BNO055_ERROR 03934 * 03935 * 03936 */ 03937 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_linear_accel_xyz_msq( 03938 struct bno055_linear_accel_float_t *linear_accel_xyz) 03939 { 03940 /* Variable used to return value of 03941 communication routine*/ 03942 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03943 struct bno055_linear_accel_t reg_linear_accel = { 03944 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 03945 /* Read the raw x of linear accel */ 03946 com_rslt = bno055_read_linear_accel_xyz(®_linear_accel); 03947 if (com_rslt == BNO055_SUCCESS) { 03948 linear_accel_xyz->x = 03949 (float)(reg_linear_accel.x/BNO055_LINEAR_ACCEL_DIV_MSQ); 03950 linear_accel_xyz->y = 03951 (float)(reg_linear_accel.y/BNO055_LINEAR_ACCEL_DIV_MSQ); 03952 linear_accel_xyz->z = 03953 (float)(reg_linear_accel.z/BNO055_LINEAR_ACCEL_DIV_MSQ); 03954 } else { 03955 com_rslt = BNO055_ERROR; 03956 } 03957 return com_rslt; 03958 } 03959 /*! 03960 * @brief This API is used to convert the gravity 03961 * x raw data to meterpersecseq output as float 03962 * 03963 * @param gravity_x_f : The float value of gravity x meterpersecseq 03964 * 03965 * @return results of bus communication function 03966 * @retval 0 -> BNO055_SUCCESS 03967 * @retval 1 -> BNO055_ERROR 03968 * 03969 * 03970 */ 03971 BNO055_RETURN_FUNCTION_TYPE bno055_convert_gravity_float_x_msq( 03972 float *gravity_x_f) 03973 { 03974 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 03975 s16 reg_gravity_x_s16 = BNO055_INIT_VALUE; 03976 float data_f = BNO055_INIT_VALUE; 03977 /* Read raw gravity of x*/ 03978 com_rslt = bno055_read_gravity_x(®_gravity_x_s16); 03979 if (com_rslt == BNO055_SUCCESS) { 03980 /* Convert the raw gravity x to m/s2*/ 03981 data_f = (float)(reg_gravity_x_s16/BNO055_GRAVITY_DIV_MSQ); 03982 *gravity_x_f = data_f; 03983 } else { 03984 com_rslt = BNO055_ERROR; 03985 } 03986 return com_rslt; 03987 } 03988 /*! 03989 * @brief This API is used to convert the gravity 03990 * y raw data to meterpersecseq output as float 03991 * 03992 * @param gravity_y_f : The float value of gravity y meterpersecseq 03993 * 03994 * @return results of bus communication function 03995 * @retval 0 -> BNO055_SUCCESS 03996 * @retval 1 -> BNO055_ERROR 03997 * 03998 * 03999 */ 04000 BNO055_RETURN_FUNCTION_TYPE bno055_convert_gravity_float_y_msq( 04001 float *gravity_y_f) 04002 { 04003 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04004 s16 reg_gravity_y_s16 = BNO055_INIT_VALUE; 04005 float data_f = BNO055_INIT_VALUE; 04006 /* Read raw gravity of y*/ 04007 com_rslt = bno055_read_gravity_y(®_gravity_y_s16); 04008 if (com_rslt == BNO055_SUCCESS) { 04009 /* Convert the raw gravity y to m/s2*/ 04010 data_f = (float)(reg_gravity_y_s16/BNO055_GRAVITY_DIV_MSQ); 04011 *gravity_y_f = data_f; 04012 } else { 04013 com_rslt = BNO055_ERROR; 04014 } 04015 return com_rslt; 04016 } 04017 /*! 04018 * @brief This API is used to convert the gravity 04019 * z raw data to meterpersecseq output as float 04020 * 04021 * @param gravity_z_f : The float value of gravity z meterpersecseq 04022 * 04023 * @return results of bus communication function 04024 * @retval 0 -> BNO055_SUCCESS 04025 * @retval 1 -> BNO055_ERROR 04026 * 04027 */ 04028 BNO055_RETURN_FUNCTION_TYPE bno055_convert_gravity_float_z_msq( 04029 float *gravity_z_f) 04030 { 04031 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04032 s16 reg_gravity_z_s16 = BNO055_INIT_VALUE; 04033 float data_f = BNO055_INIT_VALUE; 04034 /* Read raw gravity of z */ 04035 com_rslt = bno055_read_gravity_z(®_gravity_z_s16); 04036 if (com_rslt == BNO055_SUCCESS) { 04037 /* Convert the raw gravity z to m/s2*/ 04038 data_f = (float)(reg_gravity_z_s16/BNO055_GRAVITY_DIV_MSQ); 04039 *gravity_z_f = data_f; 04040 } else { 04041 com_rslt = BNO055_ERROR; 04042 } 04043 return com_rslt; 04044 } 04045 /*! 04046 * @brief This API is used to convert the gravity xyz raw data 04047 * to meterpersecseq output as float 04048 * 04049 * @param gravity_xyz : The meterpersecseq data of gravity xyz 04050 * 04051 * Parameter | result 04052 * --------- | ----------------- 04053 * x | meterpersecseq data of gravity 04054 * y | meterpersecseq data of gravity 04055 * z | meterpersecseq data of gravity 04056 * 04057 * 04058 * @return results of bus communication function 04059 * @retval 0 -> BNO055_SUCCESS 04060 * @retval 1 -> BNO055_ERROR 04061 * 04062 * 04063 */ 04064 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_gravity_xyz_msq( 04065 struct bno055_gravity_float_t *gravity_xyz) 04066 { 04067 /* Variable used to return value of 04068 communication routine*/ 04069 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04070 struct bno055_gravity_t reg_gravity_xyz = { 04071 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 04072 /* Read raw gravity of xyz */ 04073 com_rslt = bno055_read_gravity_xyz(®_gravity_xyz); 04074 if (com_rslt == BNO055_SUCCESS) { 04075 /* Convert raw gravity xyz to meterpersecseq */ 04076 gravity_xyz->x = 04077 (float)(reg_gravity_xyz.x/BNO055_GRAVITY_DIV_MSQ); 04078 gravity_xyz->y = 04079 (float)(reg_gravity_xyz.y/BNO055_GRAVITY_DIV_MSQ); 04080 gravity_xyz->z = 04081 (float)(reg_gravity_xyz.z/BNO055_GRAVITY_DIV_MSQ); 04082 } else { 04083 com_rslt = BNO055_ERROR; 04084 } 04085 return com_rslt; 04086 } 04087 /*! 04088 * @brief This API is used to convert the temperature 04089 * data to Fahrenheit output as float 04090 * 04091 * @param temp_f : The float value of temperature Fahrenheit 04092 * 04093 * @return results of bus communication function 04094 * @retval 0 -> BNO055_SUCCESS 04095 * @retval 1 -> BNO055_ERROR 04096 * 04097 * 04098 */ 04099 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_temp_fahrenheit( 04100 float *temp_f) 04101 { 04102 /* Variable used to return value of 04103 communication routine*/ 04104 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04105 s8 reg_temp_s8 = BNO055_INIT_VALUE; 04106 float data_f = BNO055_INIT_VALUE; 04107 u8 temp_unit_u8 = BNO055_INIT_VALUE; 04108 /* Read the current temperature unit and set the 04109 unit as Fahrenheit if the unit is in Celsius */ 04110 com_rslt = bno055_get_temp_unit(&temp_unit_u8); 04111 if (temp_unit_u8 != BNO055_TEMP_UNIT_FAHRENHEIT) 04112 com_rslt += bno055_set_temp_unit(BNO055_TEMP_UNIT_FAHRENHEIT); 04113 if (com_rslt == BNO055_SUCCESS) { 04114 /* Read the raw temperature data */ 04115 com_rslt += bno055_read_temp_data(®_temp_s8); 04116 if (com_rslt == BNO055_SUCCESS) { 04117 /* Convert raw temperature data to Fahrenheit*/ 04118 data_f = (float) 04119 (reg_temp_s8/BNO055_TEMP_DIV_FAHRENHEIT); 04120 *temp_f = data_f; 04121 } else { 04122 com_rslt = BNO055_ERROR; 04123 } 04124 } else { 04125 com_rslt = BNO055_ERROR; 04126 } 04127 return com_rslt; 04128 } 04129 /*! 04130 * @brief This API is used to convert the temperature 04131 * data to Celsius output as float 04132 * 04133 * @param temp_f : The float value of temperature Celsius 04134 * 04135 * @return results of bus communication function 04136 * @retval 0 -> BNO055_SUCCESS 04137 * @retval 1 -> BNO055_ERROR 04138 * 04139 * 04140 * 04141 */ 04142 BNO055_RETURN_FUNCTION_TYPE bno055_convert_float_temp_celsius( 04143 float *temp_f) 04144 { 04145 /* Variable used to return value of 04146 communication routine*/ 04147 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04148 s8 reg_temp_s8 = BNO055_INIT_VALUE; 04149 float data_f = BNO055_INIT_VALUE; 04150 u8 temp_unit_u8 = BNO055_INIT_VALUE; 04151 /* Read the current temperature unit and set the 04152 unit as Fahrenheit if the unit is in Celsius */ 04153 com_rslt = bno055_get_temp_unit(&temp_unit_u8); 04154 if (temp_unit_u8 != BNO055_TEMP_UNIT_CELSIUS) 04155 com_rslt += bno055_set_temp_unit(BNO055_TEMP_UNIT_CELSIUS); 04156 if (com_rslt == BNO055_SUCCESS) { 04157 /* Read the raw temperature data */ 04158 com_rslt += bno055_read_temp_data(®_temp_s8); 04159 if (com_rslt == BNO055_SUCCESS) { 04160 /* Convert raw temperature data to Fahrenheit*/ 04161 data_f = 04162 (float)(reg_temp_s8/BNO055_TEMP_DIV_CELSIUS); 04163 *temp_f = data_f; 04164 } else { 04165 com_rslt = BNO055_ERROR; 04166 } 04167 } else { 04168 com_rslt = BNO055_ERROR; 04169 } 04170 return com_rslt; 04171 } 04172 #endif 04173 #ifdef BNO055_DOUBLE_ENABLE 04174 /*! 04175 * @brief This API is used to convert the accel x raw data 04176 * to meterpersecseq output as double 04177 * 04178 * @param accel_x_d : The accel x meterpersecseq data 04179 * 04180 * 04181 * 04182 * @return results of bus communication function 04183 * @retval 0 -> BNO055_SUCCESS 04184 * @retval 1 -> BNO055_ERROR 04185 * 04186 * 04187 */ 04188 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_x_msq( 04189 double *accel_x_d) 04190 { 04191 /* Variable used to return value of 04192 communication routine*/ 04193 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04194 s16 reg_accel_x_s16 = BNO055_INIT_VALUE; 04195 double data_f = BNO055_INIT_VALUE; 04196 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04197 /* Read the current accel unit and set the 04198 unit as m/s2 if the unit is in mg*/ 04199 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04200 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 04201 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 04202 if (com_rslt == BNO055_SUCCESS) { 04203 /* Read the accel raw y data*/ 04204 com_rslt += bno055_read_accel_x(®_accel_x_s16); 04205 if (com_rslt == BNO055_SUCCESS) { 04206 /* Convert the raw x to m/s2 */ 04207 data_f = 04208 (double)(reg_accel_x_s16/BNO055_ACCEL_DIV_MSQ); 04209 *accel_x_d = data_f; 04210 } else { 04211 com_rslt = BNO055_ERROR; 04212 } 04213 } else { 04214 com_rslt = BNO055_ERROR; 04215 } 04216 return com_rslt; 04217 } 04218 /*! 04219 * @brief This API is used to convert the accel x raw data 04220 * to millig output as double 04221 * 04222 * @param accel_x_d : The accel x millig data 04223 * 04224 * 04225 * 04226 * @return results of bus communication function 04227 * @retval 0 -> BNO055_SUCCESS 04228 * @retval 1 -> BNO055_ERROR 04229 * 04230 * 04231 * 04232 */ 04233 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_x_mg( 04234 double *accel_x_d) 04235 { 04236 /* Variable used to return value of 04237 communication routine*/ 04238 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04239 s16 reg_accel_x_s16 = BNO055_INIT_VALUE; 04240 double data_f = BNO055_INIT_VALUE; 04241 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04242 /* Read the current accel unit and set the 04243 unit as mg if the unit is in m/s2*/ 04244 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04245 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 04246 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 04247 if (com_rslt == BNO055_SUCCESS) { 04248 /* Read the accel raw y data*/ 04249 com_rslt += bno055_read_accel_x(®_accel_x_s16); 04250 if (com_rslt == BNO055_SUCCESS) { 04251 /* Convert the raw x to mg */ 04252 data_f = 04253 (double)(reg_accel_x_s16/BNO055_ACCEL_DIV_MG); 04254 *accel_x_d = data_f; 04255 } else { 04256 com_rslt = BNO055_ERROR; 04257 } 04258 } else { 04259 com_rslt = BNO055_ERROR; 04260 } 04261 return com_rslt; 04262 } 04263 /*! 04264 * @brief This API is used to convert the accel y raw data 04265 * to meterpersecseq output as double 04266 * 04267 * @param accel_y_d : The accel y meterpersecseq data 04268 * 04269 * 04270 * 04271 * @return results of bus communication function 04272 * @retval 0 -> BNO055_SUCCESS 04273 * @retval 1 -> BNO055_ERROR 04274 * 04275 * 04276 * 04277 */ 04278 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_y_msq( 04279 double *accel_y_d) 04280 { 04281 /* Variable used to return value of 04282 communication routine*/ 04283 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04284 s16 reg_accel_y_s16 = BNO055_INIT_VALUE; 04285 double data_f = BNO055_INIT_VALUE; 04286 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04287 /* Read the current accel unit and set the 04288 unit as m/s2 if the unit is in mg*/ 04289 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04290 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 04291 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 04292 if (com_rslt == BNO055_SUCCESS) { 04293 /* Read the accel raw y data*/ 04294 com_rslt += bno055_read_accel_y(®_accel_y_s16); 04295 if (com_rslt == BNO055_SUCCESS) { 04296 /* Convert the raw x to m/s2 */ 04297 data_f = 04298 (double)(reg_accel_y_s16/BNO055_ACCEL_DIV_MSQ); 04299 *accel_y_d = data_f; 04300 } else { 04301 com_rslt = BNO055_ERROR; 04302 } 04303 } else { 04304 com_rslt = BNO055_ERROR; 04305 } 04306 return com_rslt; 04307 } 04308 /*! 04309 * @brief This API is used to convert the accel y raw data 04310 * to millig output as double 04311 * 04312 * @param accel_y_d : The accel y millig data 04313 * 04314 * 04315 * 04316 * @return results of bus communication function 04317 * @retval 0 -> BNO055_SUCCESS 04318 * @retval 1 -> BNO055_ERROR 04319 * 04320 * 04321 */ 04322 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_y_mg( 04323 double *accel_y_d) 04324 { 04325 /* Variable used to return value of 04326 communication routine*/ 04327 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04328 s16 reg_accel_y_s16 = BNO055_INIT_VALUE; 04329 double data_d = BNO055_INIT_VALUE; 04330 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04331 /* Read the current accel unit and set the 04332 unit as mg if the unit is in m/s2*/ 04333 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04334 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 04335 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 04336 if (com_rslt == BNO055_SUCCESS) { 04337 /* Read the accel raw y data*/ 04338 com_rslt += bno055_read_accel_y(®_accel_y_s16); 04339 if (com_rslt == BNO055_SUCCESS) { 04340 /* Convert the raw y to mg */ 04341 data_d = 04342 (double)(reg_accel_y_s16/BNO055_ACCEL_DIV_MG); 04343 *accel_y_d = data_d; 04344 } else { 04345 com_rslt = BNO055_ERROR; 04346 } 04347 } else { 04348 com_rslt = BNO055_ERROR; 04349 } 04350 return com_rslt; 04351 } 04352 /*! 04353 * @brief This API is used to convert the accel z raw data 04354 * to meterpersecseq output as double 04355 * 04356 * @param accel_z_d : The accel z meterpersecseq data 04357 * 04358 * 04359 * 04360 * @return results of bus communication function 04361 * @retval 0 -> BNO055_SUCCESS 04362 * @retval 1 -> BNO055_ERROR 04363 */ 04364 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_z_msq( 04365 double *accel_z_d) 04366 { 04367 /* Variable used to return value of 04368 communication routine*/ 04369 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04370 s16 reg_accel_z_s16 = BNO055_INIT_VALUE; 04371 double data_d = BNO055_INIT_VALUE; 04372 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04373 /* Read the current accel unit and set the 04374 unit as m/s2 if the unit is in mg*/ 04375 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04376 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 04377 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 04378 if (com_rslt == BNO055_SUCCESS) { 04379 /* Read the accel raw z data*/ 04380 com_rslt += bno055_read_accel_z(®_accel_z_s16); 04381 if (com_rslt == BNO055_SUCCESS) { 04382 /* Convert the raw z to m/s2 */ 04383 data_d = 04384 (double)(reg_accel_z_s16/BNO055_ACCEL_DIV_MSQ); 04385 *accel_z_d = data_d; 04386 } else { 04387 com_rslt = BNO055_ERROR; 04388 } 04389 } else { 04390 com_rslt = BNO055_ERROR; 04391 } 04392 return com_rslt; 04393 } 04394 /*! 04395 * @brief This API is used to convert the accel z raw data 04396 * to millig output as double 04397 * 04398 * @param accel_z_d : The accel z millig data 04399 * 04400 * 04401 * 04402 * @return results of bus communication function 04403 * @retval 0 -> BNO055_SUCCESS 04404 * @retval 1 -> BNO055_ERROR 04405 * 04406 */ 04407 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_z_mg( 04408 double *accel_z_d) 04409 { 04410 /* Variable used to return value of 04411 communication routine*/ 04412 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04413 s16 reg_accel_z_s16 = BNO055_INIT_VALUE; 04414 double data_d = BNO055_INIT_VALUE; 04415 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04416 /* Read the current accel unit and set the 04417 unit as mg if the unit is in m/s2*/ 04418 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04419 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 04420 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 04421 if (com_rslt == BNO055_SUCCESS) { 04422 /* Read the accel raw z data*/ 04423 com_rslt += bno055_read_accel_z(®_accel_z_s16); 04424 if (com_rslt == BNO055_SUCCESS) { 04425 /* Convert the raw z to mg */ 04426 data_d = 04427 (double)(reg_accel_z_s16/BNO055_ACCEL_DIV_MG); 04428 *accel_z_d = data_d; 04429 } else { 04430 com_rslt = BNO055_ERROR; 04431 } 04432 } else { 04433 com_rslt = BNO055_ERROR; 04434 } 04435 return com_rslt; 04436 } 04437 /*! 04438 * @brief This API is used to convert the accel xyz raw data 04439 * to meterpersecseq output as double 04440 * 04441 * @param accel_xyz : The meterpersecseq data of accel xyz 04442 * 04443 * Parameter | result 04444 * --------- | ----------------- 04445 * x | meterpersecseq data of accel 04446 * y | meterpersecseq data of accel 04447 * z | meterpersecseq data of accel 04448 * 04449 * 04450 * @return results of bus communication function 04451 * @retval 0 -> BNO055_SUCCESS 04452 * @retval 1 -> BNO055_ERROR 04453 * 04454 * 04455 */ 04456 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_xyz_msq( 04457 struct bno055_accel_double_t *accel_xyz) 04458 { 04459 /* Variable used to return value of 04460 communication routine*/ 04461 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04462 struct bno055_accel_t reg_accel_xyz = { 04463 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 04464 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04465 /* Read the current accel unit and set the 04466 unit as m/s2 if the unit is in mg*/ 04467 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04468 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MSQ) 04469 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MSQ); 04470 if (com_rslt == BNO055_SUCCESS) { 04471 /* Read the accel raw xyz data*/ 04472 com_rslt += bno055_read_accel_xyz(®_accel_xyz); 04473 if (com_rslt == BNO055_SUCCESS) { 04474 /* Convert raw xyz to m/s2*/ 04475 accel_xyz->x = 04476 (double)(reg_accel_xyz.x/BNO055_ACCEL_DIV_MSQ); 04477 accel_xyz->y = 04478 (double)(reg_accel_xyz.y/BNO055_ACCEL_DIV_MSQ); 04479 accel_xyz->z = 04480 (double)(reg_accel_xyz.z/BNO055_ACCEL_DIV_MSQ); 04481 } else { 04482 com_rslt = BNO055_ERROR; 04483 } 04484 } else { 04485 com_rslt = BNO055_ERROR; 04486 } 04487 return com_rslt; 04488 } 04489 /*! 04490 * @brief This API is used to convert the accel xyz raw data 04491 * to millig output as double 04492 * 04493 * @param accel_xyz : The millig data of accel xyz 04494 * 04495 * Parameter | result 04496 * --------- | ----------------- 04497 * x | millig data of accel 04498 * y | millig data of accel 04499 * z | millig data of accel 04500 * 04501 * 04502 * @return results of bus communication function 04503 * @retval 0 -> BNO055_SUCCESS 04504 * @retval 1 -> BNO055_ERROR 04505 * 04506 */ 04507 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_accel_xyz_mg( 04508 struct bno055_accel_double_t *accel_xyz) 04509 { 04510 /* Variable used to return value of 04511 communication routine*/ 04512 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04513 struct bno055_accel_t reg_accel_xyz = { 04514 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 04515 u8 accel_unit_u8 = BNO055_INIT_VALUE; 04516 /* Read the current accel unit and set the 04517 unit as m/s2 if the unit is in mg*/ 04518 com_rslt = bno055_get_accel_unit(&accel_unit_u8); 04519 if (accel_unit_u8 != BNO055_ACCEL_UNIT_MG) 04520 com_rslt += bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG); 04521 if (com_rslt == BNO055_SUCCESS) { 04522 /* Read the accel raw xyz data*/ 04523 com_rslt += bno055_read_accel_xyz(®_accel_xyz); 04524 if (com_rslt == BNO055_SUCCESS) { 04525 /* Convert raw xyz to mg*/ 04526 accel_xyz->x = 04527 (double)(reg_accel_xyz.x/BNO055_ACCEL_DIV_MG); 04528 accel_xyz->y = 04529 (double)(reg_accel_xyz.y/BNO055_ACCEL_DIV_MG); 04530 accel_xyz->z = 04531 (double)(reg_accel_xyz.z/BNO055_ACCEL_DIV_MG); 04532 } else { 04533 com_rslt = BNO055_ERROR; 04534 } 04535 } else { 04536 com_rslt = BNO055_ERROR; 04537 } 04538 return com_rslt; 04539 } 04540 /*! 04541 * @brief This API is used to convert the mag x raw data 04542 * to microTesla output as double 04543 * 04544 * @param mag_x_d : The mag x microTesla data 04545 * 04546 * 04547 * 04548 * @return results of bus communication function 04549 * @retval 0 -> BNO055_SUCCESS 04550 * @retval 1 -> BNO055_ERROR 04551 * 04552 * 04553 * 04554 */ 04555 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_mag_x_uT( 04556 double *mag_x_d) 04557 { 04558 /* Variable used to return value of 04559 communication routine*/ 04560 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04561 s16 reg_mag_x_s16 = BNO055_INIT_VALUE; 04562 double data_d = BNO055_INIT_VALUE; 04563 /* Read raw mag x data */ 04564 com_rslt = bno055_read_mag_x(®_mag_x_s16); 04565 if (com_rslt == BNO055_SUCCESS) { 04566 /* Convert raw mag x to microTesla */ 04567 data_d = (double)(reg_mag_x_s16/BNO055_MAG_DIV_UT); 04568 *mag_x_d = data_d; 04569 } else { 04570 com_rslt = BNO055_ERROR; 04571 } 04572 return com_rslt; 04573 } 04574 /*! 04575 * @brief This API is used to convert the mag y raw data 04576 * to microTesla output as double 04577 * 04578 * @param mag_y_d : The mag y microTesla data 04579 * 04580 * 04581 * 04582 * @return results of bus communication function 04583 * @retval 0 -> BNO055_SUCCESS 04584 * @retval 1 -> BNO055_ERROR 04585 * 04586 * 04587 */ 04588 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_mag_y_uT( 04589 double *mag_y_d) 04590 { 04591 /* Variable used to return value of 04592 communication routine*/ 04593 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04594 s16 reg_mag_y_s16 = BNO055_INIT_VALUE; 04595 double data_d = BNO055_INIT_VALUE; 04596 /* Read raw mag y data */ 04597 com_rslt = bno055_read_mag_y(®_mag_y_s16); 04598 if (com_rslt == BNO055_SUCCESS) { 04599 /* Convert raw mag y to microTesla */ 04600 data_d = (double)(reg_mag_y_s16/BNO055_MAG_DIV_UT); 04601 *mag_y_d = data_d; 04602 } else { 04603 com_rslt = BNO055_ERROR; 04604 } 04605 return com_rslt; 04606 } 04607 /*! 04608 * @brief This API is used to convert the mag z raw data 04609 * to microTesla output as double 04610 * 04611 * @param mag_z_d : The mag z microTesla data 04612 * 04613 * 04614 * 04615 * @return results of bus communication function 04616 * @retval 0 -> BNO055_SUCCESS 04617 * @retval 1 -> BNO055_ERROR 04618 * 04619 * 04620 */ 04621 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_mag_z_uT( 04622 double *mag_z_d) 04623 { 04624 /* Variable used to return value of 04625 communication routine*/ 04626 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04627 s16 reg_mag_z_s16 = BNO055_INIT_VALUE; 04628 double data_d = BNO055_INIT_VALUE; 04629 /* Read raw mag x */ 04630 com_rslt = bno055_read_mag_z(®_mag_z_s16); 04631 if (com_rslt == BNO055_SUCCESS) { 04632 /* Convert raw mag x to microTesla */ 04633 data_d = (double)(reg_mag_z_s16/BNO055_MAG_DIV_UT); 04634 *mag_z_d = data_d; 04635 } else { 04636 com_rslt = BNO055_ERROR; 04637 } 04638 return com_rslt; 04639 } 04640 /*! 04641 * @brief This API is used to convert the mag yz raw data 04642 * to microTesla output as double 04643 * 04644 * @param mag_xyz : The microTesla data of mag xyz 04645 * 04646 * Parameter | result 04647 * --------- | ----------------- 04648 * x | microTesla data of mag 04649 * y | microTesla data of mag 04650 * z | microTesla data of mag 04651 * 04652 * 04653 * @return results of bus communication function 04654 * @retval 0 -> BNO055_SUCCESS 04655 * @retval 1 -> BNO055_ERROR 04656 * 04657 */ 04658 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_mag_xyz_uT( 04659 struct bno055_mag_double_t *mag_xyz) 04660 { 04661 /* Variable used to return value of 04662 communication routine*/ 04663 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04664 struct bno055_mag_t reg_mag_xyz = { 04665 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 04666 /* Read raw mag xyz data */ 04667 com_rslt = bno055_read_mag_xyz(®_mag_xyz); 04668 if (com_rslt == BNO055_SUCCESS) { 04669 /* Convert raw mag xyz to microTesla*/ 04670 mag_xyz->x = 04671 (double)(reg_mag_xyz.x/BNO055_MAG_DIV_UT); 04672 mag_xyz->y = 04673 (double)(reg_mag_xyz.y/BNO055_MAG_DIV_UT); 04674 mag_xyz->z = 04675 (double)(reg_mag_xyz.z/BNO055_MAG_DIV_UT); 04676 } else { 04677 com_rslt = BNO055_ERROR; 04678 } 04679 04680 return com_rslt; 04681 } 04682 /*! 04683 * @brief This API is used to convert the gyro x raw data 04684 * to dps output as double 04685 * 04686 * @param gyro_x_d : The gyro x dps double data 04687 * 04688 * 04689 * 04690 * @return results of bus communication function 04691 * @retval 0 -> BNO055_SUCCESS 04692 * @retval 1 -> BNO055_ERROR 04693 * 04694 * 04695 */ 04696 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_x_dps( 04697 double *gyro_x_d) 04698 { 04699 /* Variable used to return value of 04700 communication routine*/ 04701 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04702 s16 reg_gyro_x_s16 = BNO055_INIT_VALUE; 04703 double data_d = BNO055_INIT_VALUE; 04704 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 04705 /* Read the current gyro unit and set the 04706 unit as dps if the unit is in rps */ 04707 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 04708 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 04709 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 04710 if (com_rslt == BNO055_SUCCESS) { 04711 /* Read gyro raw x data */ 04712 com_rslt += bno055_read_gyro_x(®_gyro_x_s16); 04713 if (com_rslt == BNO055_SUCCESS) { 04714 /* Convert raw gyro x to dps */ 04715 data_d = 04716 (double)(reg_gyro_x_s16/BNO055_GYRO_DIV_DPS); 04717 *gyro_x_d = data_d; 04718 } else { 04719 com_rslt = BNO055_ERROR; 04720 } 04721 } else { 04722 com_rslt = BNO055_ERROR; 04723 } 04724 return com_rslt; 04725 } 04726 /*! 04727 * @brief This API is used to convert the gyro x raw data 04728 * to rps output as double 04729 * 04730 * @param gyro_x_d : The gyro x dps double data 04731 * 04732 * 04733 * 04734 * @return results of bus communication function 04735 * @retval 0 -> BNO055_SUCCESS 04736 * @retval 1 -> BNO055_ERROR 04737 * 04738 * 04739 */ 04740 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_x_rps( 04741 double *gyro_x_d) 04742 { 04743 /* Variable used to return value of 04744 communication routine*/ 04745 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04746 s16 reg_gyro_x_s16 = BNO055_INIT_VALUE; 04747 double data_d = BNO055_INIT_VALUE; 04748 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 04749 /* Read the current gyro unit and set the 04750 unit as rps if the unit is in dps */ 04751 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 04752 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 04753 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 04754 if (com_rslt == BNO055_SUCCESS) { 04755 /* Read gyro raw x data */ 04756 com_rslt += bno055_read_gyro_x(®_gyro_x_s16); 04757 if (com_rslt == BNO055_SUCCESS) { 04758 /* Convert raw gyro x to rps */ 04759 data_d = 04760 (double)(reg_gyro_x_s16/BNO055_GYRO_DIV_RPS); 04761 *gyro_x_d = data_d; 04762 } else { 04763 com_rslt = BNO055_ERROR; 04764 } 04765 } else { 04766 com_rslt = BNO055_ERROR; 04767 } 04768 return com_rslt; 04769 } 04770 /*! 04771 * @brief This API is used to convert the gyro y raw data 04772 * to dps output as double 04773 * 04774 * @param gyro_y_d : The gyro y dps double data 04775 * 04776 * 04777 * 04778 * @return results of bus communication function 04779 * @retval 0 -> BNO055_SUCCESS 04780 * @retval 1 -> BNO055_ERROR 04781 * 04782 * 04783 */ 04784 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_y_dps( 04785 double *gyro_y_d) 04786 { 04787 /* Variable used to return value of 04788 communication routine*/ 04789 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04790 s16 reg_gyro_y_s16 = BNO055_INIT_VALUE; 04791 double data_d = BNO055_INIT_VALUE; 04792 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 04793 /* Read the current gyro unit and set the 04794 unit as dps if the unit is in rps */ 04795 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 04796 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 04797 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 04798 if (com_rslt == BNO055_SUCCESS) { 04799 /* Read gyro raw y data */ 04800 com_rslt += bno055_read_gyro_y(®_gyro_y_s16); 04801 if (com_rslt == BNO055_SUCCESS) { 04802 /* Convert raw gyro y to dps */ 04803 data_d = 04804 (double)(reg_gyro_y_s16/BNO055_GYRO_DIV_DPS); 04805 *gyro_y_d = data_d; 04806 } else { 04807 com_rslt = BNO055_ERROR; 04808 } 04809 } else { 04810 com_rslt = BNO055_ERROR; 04811 } 04812 return com_rslt; 04813 } 04814 /*! 04815 * @brief This API is used to convert the gyro y raw data 04816 * to rps output as double 04817 * 04818 * @param gyro_y_d : The gyro y dps double data 04819 * 04820 * 04821 * 04822 * @return results of bus communication function 04823 * @retval 0 -> BNO055_SUCCESS 04824 * @retval 1 -> BNO055_ERROR 04825 * 04826 * 04827 */ 04828 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_y_rps( 04829 double *gyro_y_d) 04830 { 04831 /* Variable used to return value of 04832 communication routine*/ 04833 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04834 s16 reg_gyro_y_s16 = BNO055_INIT_VALUE; 04835 double data_d = BNO055_INIT_VALUE; 04836 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 04837 /* Read the current gyro unit and set the 04838 unit as rps if the unit is in dps */ 04839 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 04840 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 04841 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 04842 if (com_rslt == BNO055_SUCCESS) { 04843 /* Read gyro raw y data */ 04844 com_rslt += bno055_read_gyro_y(®_gyro_y_s16); 04845 if (com_rslt == BNO055_SUCCESS) { 04846 /* Convert raw gyro y to rps */ 04847 data_d = 04848 (double)(reg_gyro_y_s16/BNO055_GYRO_DIV_RPS); 04849 *gyro_y_d = data_d; 04850 } else { 04851 com_rslt = BNO055_ERROR; 04852 } 04853 } else { 04854 com_rslt = BNO055_ERROR; 04855 } 04856 return com_rslt; 04857 } 04858 /*! 04859 * @brief This API is used to convert the gyro z raw data 04860 * to dps output as double 04861 * 04862 * @param gyro_z_d : The gyro z dps double data 04863 * 04864 * 04865 * 04866 * @return results of bus communication function 04867 * @retval 0 -> BNO055_SUCCESS 04868 * @retval 1 -> BNO055_ERROR 04869 * 04870 * 04871 */ 04872 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_z_dps( 04873 double *gyro_z_d) 04874 { 04875 /* Variable used to return value of 04876 communication routine*/ 04877 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04878 s16 reg_gyro_z_s16 = BNO055_INIT_VALUE; 04879 double data_d = BNO055_INIT_VALUE; 04880 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 04881 /* Read the current gyro unit and set the 04882 unit as dps if the unit is in rps */ 04883 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 04884 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 04885 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 04886 if (com_rslt == BNO055_SUCCESS) { 04887 /* Read gyro raw z data */ 04888 com_rslt += bno055_read_gyro_z(®_gyro_z_s16); 04889 if (com_rslt == BNO055_SUCCESS) { 04890 /* Convert raw gyro z to dps */ 04891 data_d = 04892 (double)(reg_gyro_z_s16/BNO055_GYRO_DIV_DPS); 04893 *gyro_z_d = data_d; 04894 } else { 04895 com_rslt = BNO055_ERROR; 04896 } 04897 } else { 04898 com_rslt = BNO055_ERROR; 04899 } 04900 return com_rslt; 04901 } 04902 /*! 04903 * @brief This API is used to convert the gyro z raw data 04904 * to rps output as double 04905 * 04906 * @param gyro_z_d : The gyro z rps double data 04907 * 04908 * 04909 * 04910 * @return results of bus communication function 04911 * @retval 0 -> BNO055_SUCCESS 04912 * @retval 1 -> BNO055_ERROR 04913 * 04914 * 04915 */ 04916 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_z_rps( 04917 double *gyro_z_d) 04918 { 04919 /* Variable used to return value of 04920 communication routine*/ 04921 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04922 s16 reg_gyro_z_s16 = BNO055_INIT_VALUE; 04923 double data_d = BNO055_INIT_VALUE; 04924 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 04925 /* Read the current gyro unit and set the 04926 unit as rps if the unit is in dps */ 04927 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 04928 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 04929 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 04930 if (com_rslt == BNO055_SUCCESS) { 04931 /* Read gyro raw x data */ 04932 com_rslt += bno055_read_gyro_z(®_gyro_z_s16); 04933 if (com_rslt == BNO055_SUCCESS) { 04934 /* Convert raw gyro x to rps */ 04935 data_d = 04936 (double)(reg_gyro_z_s16/BNO055_GYRO_DIV_RPS); 04937 *gyro_z_d = data_d; 04938 } else { 04939 com_rslt = BNO055_ERROR; 04940 } 04941 } else { 04942 com_rslt = BNO055_ERROR; 04943 } 04944 return com_rslt; 04945 } 04946 /*! 04947 * @brief This API is used to convert the gyro xyz raw data 04948 * to dps output as double 04949 * 04950 * @param gyro_xyz : The dps data of gyro xyz 04951 * 04952 * Parameter | result 04953 * --------- | ----------------- 04954 * x | dps data of gyro 04955 * y | dps data of gyro 04956 * z | dps data of gyro 04957 * 04958 * 04959 * @return results of bus communication function 04960 * @retval 0 -> BNO055_SUCCESS 04961 * @retval 1 -> BNO055_ERROR 04962 * 04963 */ 04964 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_xyz_dps( 04965 struct bno055_gyro_double_t *gyro_xyz) 04966 { 04967 /* Variable used to return value of 04968 communication routine*/ 04969 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 04970 struct bno055_gyro_t reg_gyro_xyz = { 04971 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 04972 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 04973 /* Read the current gyro unit and set the 04974 unit as dps if the unit is in rps */ 04975 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 04976 if (gyro_unit_u8 != BNO055_GYRO_UNIT_DPS) 04977 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS); 04978 if (com_rslt == BNO055_SUCCESS) { 04979 /* Read gyro raw xyz data */ 04980 com_rslt += bno055_read_gyro_xyz(®_gyro_xyz); 04981 if (com_rslt == BNO055_SUCCESS) { 04982 /* Convert gyro raw xyz to dps*/ 04983 gyro_xyz->x = 04984 (double)(reg_gyro_xyz.x/BNO055_GYRO_DIV_DPS); 04985 gyro_xyz->y = 04986 (double)(reg_gyro_xyz.y/BNO055_GYRO_DIV_DPS); 04987 gyro_xyz->z = 04988 (double)(reg_gyro_xyz.z/BNO055_GYRO_DIV_DPS); 04989 } else { 04990 com_rslt = BNO055_ERROR; 04991 } 04992 } else { 04993 com_rslt = BNO055_ERROR; 04994 } 04995 return com_rslt; 04996 } 04997 /*! 04998 * @brief This API is used to convert the gyro xyz raw data 04999 * to rps output as double 05000 * 05001 * @param gyro_xyz : The rps data of gyro xyz 05002 * 05003 * Parameter | result 05004 * --------- | ----------------- 05005 * x | rps data of gyro 05006 * y | rps data of gyro 05007 * z | rps data of gyro 05008 * 05009 * 05010 * @return results of bus communication function 05011 * @retval 0 -> BNO055_SUCCESS 05012 * @retval 1 -> BNO055_ERROR 05013 * 05014 */ 05015 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gyro_xyz_rps( 05016 struct bno055_gyro_double_t *gyro_xyz) 05017 { 05018 /* Variable used to return value of 05019 communication routine*/ 05020 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05021 struct bno055_gyro_t reg_gyro_xyz = { 05022 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 05023 u8 gyro_unit_u8 = BNO055_INIT_VALUE; 05024 /* Read the current gyro unit and set the 05025 unit as rps if the unit is in dps */ 05026 com_rslt = bno055_get_gyro_unit(&gyro_unit_u8); 05027 if (gyro_unit_u8 != BNO055_GYRO_UNIT_RPS) 05028 com_rslt += bno055_set_gyro_unit(BNO055_GYRO_UNIT_RPS); 05029 if (com_rslt == BNO055_SUCCESS) { 05030 /* Read gyro raw x data */ 05031 com_rslt += bno055_read_gyro_xyz(®_gyro_xyz); 05032 if (com_rslt == BNO055_SUCCESS) { 05033 /* Convert the raw gyro xyz to rps*/ 05034 gyro_xyz->x = 05035 (double)(reg_gyro_xyz.x/BNO055_GYRO_DIV_RPS); 05036 gyro_xyz->y = 05037 (double)(reg_gyro_xyz.y/BNO055_GYRO_DIV_RPS); 05038 gyro_xyz->z = 05039 (double)(reg_gyro_xyz.z/BNO055_GYRO_DIV_RPS); 05040 } else { 05041 com_rslt = BNO055_ERROR; 05042 } 05043 } else { 05044 com_rslt = BNO055_ERROR; 05045 } 05046 return com_rslt; 05047 } 05048 /*! 05049 * @brief This API is used to convert the Euler h raw data 05050 * to degree output as double 05051 * 05052 * @param euler_h_d : The double value of Euler h degree 05053 * 05054 * @return results of bus communication function 05055 * @retval 0 -> BNO055_SUCCESS 05056 * @retval 1 -> BNO055_ERROR 05057 * 05058 * 05059 */ 05060 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_h_deg( 05061 double *euler_h_d) 05062 { 05063 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05064 s16 reg_euler_h_s16 = BNO055_INIT_VALUE; 05065 double data_d = BNO055_INIT_VALUE; 05066 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05067 /* Read the current Euler unit and set the 05068 unit as degree if the unit is in radians */ 05069 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05070 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 05071 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 05072 if (com_rslt == BNO055_SUCCESS) { 05073 /* Read Euler raw h data*/ 05074 com_rslt += bno055_read_euler_h(®_euler_h_s16); 05075 if (com_rslt == BNO055_SUCCESS) { 05076 /* Convert raw Euler h to degree */ 05077 data_d = 05078 (double)(reg_euler_h_s16/BNO055_EULER_DIV_DEG); 05079 *euler_h_d = data_d; 05080 } else { 05081 com_rslt = BNO055_ERROR; 05082 } 05083 } else { 05084 com_rslt = BNO055_ERROR; 05085 } 05086 return com_rslt; 05087 } 05088 /*! 05089 * @brief This API is used to convert the Euler h raw data 05090 * to radians output as double 05091 * 05092 * @param euler_h_d : The double value of Euler h radians 05093 * 05094 * @return results of bus communication function 05095 * @retval 0 -> BNO055_SUCCESS 05096 * @retval 1 -> BNO055_ERROR 05097 * 05098 * 05099 */ 05100 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_h_rad( 05101 double *euler_h_d) 05102 { 05103 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05104 s16 reg_euler_h_s16 = BNO055_INIT_VALUE; 05105 double data_d = BNO055_INIT_VALUE; 05106 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05107 /* Read the current Euler unit and set the 05108 unit as radians if the unit is in degree */ 05109 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05110 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 05111 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 05112 if (com_rslt == BNO055_SUCCESS) { 05113 /* Read Euler raw h data*/ 05114 com_rslt += bno055_read_euler_h(®_euler_h_s16); 05115 if (com_rslt == BNO055_SUCCESS) { 05116 /* Convert raw Euler h to radians */ 05117 data_d = 05118 (double)(reg_euler_h_s16/BNO055_EULER_DIV_RAD); 05119 *euler_h_d = data_d; 05120 } else { 05121 com_rslt = BNO055_ERROR; 05122 } 05123 } else { 05124 com_rslt = BNO055_ERROR; 05125 } 05126 return com_rslt; 05127 } 05128 /*! 05129 * @brief This API is used to convert the Euler r raw data 05130 * to degree output as double 05131 * 05132 * @param euler_r_d : The double value of Euler r degree 05133 * 05134 * @return results of bus communication function 05135 * @retval 0 -> BNO055_SUCCESS 05136 * @retval 1 -> BNO055_ERROR 05137 * 05138 * 05139 */ 05140 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_r_deg( 05141 double *euler_r_d) 05142 { 05143 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05144 s16 reg_euler_r_s16 = BNO055_INIT_VALUE; 05145 double data_d = BNO055_INIT_VALUE; 05146 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05147 /* Read the current Euler unit and set the 05148 unit as degree if the unit is in radians */ 05149 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05150 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 05151 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 05152 if (com_rslt == BNO055_SUCCESS) { 05153 /* Read Euler raw r data*/ 05154 com_rslt += bno055_read_euler_r(®_euler_r_s16); 05155 if (com_rslt == BNO055_SUCCESS) { 05156 /* Convert raw Euler r to degree */ 05157 data_d = 05158 (double)(reg_euler_r_s16/BNO055_EULER_DIV_DEG); 05159 *euler_r_d = data_d; 05160 } else { 05161 com_rslt = BNO055_ERROR; 05162 } 05163 } else { 05164 com_rslt = BNO055_ERROR; 05165 } 05166 return com_rslt; 05167 } 05168 /*! 05169 * @brief This API is used to convert the Euler r raw data 05170 * to radians output as double 05171 * 05172 * @param euler_r_d : The double value of Euler r radians 05173 * 05174 * @return results of bus communication function 05175 * @retval 0 -> BNO055_SUCCESS 05176 * @retval 1 -> BNO055_ERROR 05177 * 05178 * 05179 */ 05180 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_r_rad( 05181 double *euler_r_d) 05182 { 05183 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05184 s16 reg_euler_r_s16 = BNO055_INIT_VALUE; 05185 double data_d = BNO055_INIT_VALUE; 05186 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05187 /* Read the current Euler unit and set the 05188 unit as radians if the unit is in degree */ 05189 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05190 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 05191 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 05192 if (com_rslt == BNO055_SUCCESS) { 05193 /* Read Euler raw r data*/ 05194 com_rslt += bno055_read_euler_r(®_euler_r_s16); 05195 if (com_rslt == BNO055_SUCCESS) { 05196 /* Convert raw Euler r to radians */ 05197 data_d = 05198 (double)(reg_euler_r_s16/BNO055_EULER_DIV_RAD); 05199 *euler_r_d = data_d; 05200 } else { 05201 com_rslt = BNO055_ERROR; 05202 } 05203 } else { 05204 com_rslt = BNO055_ERROR; 05205 } 05206 return com_rslt; 05207 } 05208 /*! 05209 * @brief This API is used to convert the Euler p raw data 05210 * to degree output as double 05211 * 05212 * @param euler_p_d : The double value of Euler p degree 05213 * 05214 * @return results of bus communication function 05215 * @retval 0 -> BNO055_SUCCESS 05216 * @retval 1 -> BNO055_ERROR 05217 * 05218 * 05219 */ 05220 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_p_deg( 05221 double *euler_p_d) 05222 { 05223 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05224 s16 reg_euler_p_s16 = BNO055_INIT_VALUE; 05225 double data_d = BNO055_INIT_VALUE; 05226 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05227 /* Read the current Euler unit and set the 05228 unit as degree if the unit is in radians */ 05229 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05230 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 05231 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 05232 if (com_rslt == BNO055_SUCCESS) { 05233 /* Read Euler raw p data*/ 05234 com_rslt += bno055_read_euler_p(®_euler_p_s16); 05235 if (com_rslt == BNO055_SUCCESS) { 05236 /* Convert raw Euler p to degree*/ 05237 data_d = 05238 (double)(reg_euler_p_s16/BNO055_EULER_DIV_DEG); 05239 *euler_p_d = data_d; 05240 } else { 05241 com_rslt = BNO055_ERROR; 05242 } 05243 } else { 05244 com_rslt = BNO055_ERROR; 05245 } 05246 return com_rslt; 05247 } 05248 /*! 05249 * @brief This API is used to convert the Euler p raw data 05250 * to radians output as double 05251 * 05252 * @param euler_p_d : The double value of Euler p radians 05253 * 05254 * @return results of bus communication function 05255 * @retval 0 -> BNO055_SUCCESS 05256 * @retval 1 -> BNO055_ERROR 05257 * 05258 * 05259 */ 05260 05261 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_p_rad( 05262 double *euler_p_d) 05263 { 05264 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05265 s16 reg_euler_p_s16 = BNO055_INIT_VALUE; 05266 double data_d = BNO055_INIT_VALUE; 05267 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05268 /* Read the current Euler unit and set the 05269 unit as radians if the unit is in degree */ 05270 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05271 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 05272 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 05273 if (com_rslt == BNO055_SUCCESS) { 05274 /* Read Euler raw p data*/ 05275 com_rslt += bno055_read_euler_p(®_euler_p_s16); 05276 if (com_rslt == BNO055_SUCCESS) { 05277 /* Convert raw p to radians*/ 05278 data_d = 05279 (double)(reg_euler_p_s16/BNO055_EULER_DIV_RAD); 05280 *euler_p_d = data_d; 05281 } else { 05282 com_rslt = BNO055_ERROR; 05283 } 05284 } else { 05285 com_rslt = BNO055_ERROR; 05286 } 05287 return com_rslt; 05288 } 05289 /*! 05290 * @brief This API is used to convert the Euler hpr raw data 05291 * to degree output as double 05292 * 05293 * @param euler_hpr : The degree data of Euler hpr 05294 * 05295 * Parameter | result 05296 * --------- | ----------------- 05297 * h | degree data of Euler 05298 * r | degree data of Euler 05299 * p | degree data of Euler 05300 * 05301 * 05302 * @return results of bus communication function 05303 * @retval 0 -> BNO055_SUCCESS 05304 * @retval 1 -> BNO055_ERROR 05305 * 05306 */ 05307 05308 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_hpr_deg( 05309 struct bno055_euler_double_t *euler_hpr) 05310 { 05311 /* Variable used to return value of 05312 communication routine*/ 05313 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05314 struct bno055_euler_t reg_euler = {BNO055_INIT_VALUE, 05315 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 05316 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05317 /* Read the current Euler unit and set the 05318 unit as degree if the unit is in radians */ 05319 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05320 if (euler_unit_u8 != BNO055_EULER_UNIT_DEG) 05321 com_rslt += bno055_set_euler_unit(BNO055_EULER_UNIT_DEG); 05322 if (com_rslt == BNO055_SUCCESS) { 05323 /* Read Euler raw h data*/ 05324 com_rslt += bno055_read_euler_hrp(®_euler); 05325 if (com_rslt == BNO055_SUCCESS) { 05326 /* Convert raw Euler hrp to degree*/ 05327 euler_hpr->h = 05328 (double)(reg_euler.h/BNO055_EULER_DIV_DEG); 05329 euler_hpr->p = 05330 (double)(reg_euler.p/BNO055_EULER_DIV_DEG); 05331 euler_hpr->r = 05332 (double)(reg_euler.r/BNO055_EULER_DIV_DEG); 05333 } else { 05334 com_rslt = BNO055_ERROR; 05335 } 05336 } else { 05337 com_rslt = BNO055_ERROR; 05338 } 05339 return com_rslt; 05340 } 05341 /*! 05342 * @brief This API is used to convert the Euler hpr raw data 05343 * to radians output as double 05344 * 05345 * @param euler_hpr : The radians data of Euler hpr 05346 * 05347 * Parameter | result 05348 * --------- | ----------------- 05349 * h | radians data of Euler 05350 * r | radians data of Euler 05351 * p | radians data of Euler 05352 * 05353 * 05354 * @return results of bus communication function 05355 * @retval 0 -> BNO055_SUCCESS 05356 * @retval 1 -> BNO055_ERROR 05357 * 05358 */ 05359 05360 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_euler_hpr_rad( 05361 struct bno055_euler_double_t *euler_hpr) 05362 { 05363 /* Variable used to return value of 05364 communication routine*/ 05365 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05366 struct bno055_euler_t reg_euler = {BNO055_INIT_VALUE, 05367 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 05368 u8 euler_unit_u8 = BNO055_INIT_VALUE; 05369 /* Read the current Euler unit and set the 05370 unit as radians if the unit is in degree */ 05371 com_rslt = bno055_get_euler_unit(&euler_unit_u8); 05372 if (euler_unit_u8 != BNO055_EULER_UNIT_RAD) 05373 com_rslt = bno055_set_euler_unit(BNO055_EULER_UNIT_RAD); 05374 if (com_rslt == BNO055_SUCCESS) { 05375 /* Read the raw hrp */ 05376 com_rslt = bno055_read_euler_hrp(®_euler); 05377 if (com_rslt == BNO055_SUCCESS) { 05378 /* Convert raw Euler hrp to radians*/ 05379 euler_hpr->h = 05380 (double)(reg_euler.h/BNO055_EULER_DIV_RAD); 05381 euler_hpr->p = 05382 (double)(reg_euler.p/BNO055_EULER_DIV_RAD); 05383 euler_hpr->r = 05384 (double)(reg_euler.r/BNO055_EULER_DIV_RAD); 05385 } else { 05386 com_rslt = BNO055_ERROR; 05387 } 05388 } else { 05389 com_rslt = BNO055_ERROR; 05390 } 05391 return com_rslt; 05392 } 05393 /*! 05394 * @brief This API is used to convert the linear 05395 * accel x raw data to meterpersecseq output as double 05396 * 05397 * @param linear_accel_x_d : The double value of 05398 * linear accel x meterpersecseq 05399 * 05400 * @return results of bus communication function 05401 * @retval 0 -> BNO055_SUCCESS 05402 * @retval 1 -> BNO055_ERROR 05403 * 05404 * 05405 */ 05406 05407 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_linear_accel_x_msq( 05408 double *linear_accel_x_d) 05409 { 05410 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05411 s16 reg_linear_accel_x_s16 = BNO055_INIT_VALUE; 05412 double data_d = BNO055_INIT_VALUE; 05413 /* Read the raw x of linear accel */ 05414 com_rslt = bno055_read_linear_accel_x(®_linear_accel_x_s16); 05415 if (com_rslt == BNO055_SUCCESS) { 05416 /* Convert the raw x to m/s2 */ 05417 data_d = (double) 05418 (reg_linear_accel_x_s16/BNO055_LINEAR_ACCEL_DIV_MSQ); 05419 *linear_accel_x_d = data_d; 05420 } else { 05421 com_rslt = BNO055_ERROR; 05422 } 05423 return com_rslt; 05424 } 05425 /*! 05426 * @brief This API is used to convert the linear 05427 * accel y raw data to meterpersecseq output as double 05428 * 05429 * @param linear_accel_y_d : The double value of 05430 * linear accel y meterpersecseq 05431 * 05432 * @return results of bus communication function 05433 * @retval 0 -> BNO055_SUCCESS 05434 * @retval 1 -> BNO055_ERROR 05435 * 05436 * 05437 */ 05438 05439 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_linear_accel_y_msq( 05440 double *linear_accel_y_d) 05441 { 05442 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05443 s16 reg_linear_accel_y_s16 = BNO055_INIT_VALUE; 05444 double data_d = BNO055_INIT_VALUE; 05445 /* Read the raw x of linear accel */ 05446 com_rslt = bno055_read_linear_accel_y(®_linear_accel_y_s16); 05447 if (com_rslt == BNO055_SUCCESS) { 05448 /* Convert the raw y to m/s2 */ 05449 data_d = (double) 05450 (reg_linear_accel_y_s16/BNO055_LINEAR_ACCEL_DIV_MSQ); 05451 *linear_accel_y_d = data_d; 05452 } else { 05453 com_rslt = BNO055_ERROR; 05454 } 05455 return com_rslt; 05456 } 05457 /*! 05458 * @brief This API is used to convert the linear 05459 * accel z raw data to meterpersecseq output as double 05460 * 05461 * @param linear_accel_z_d : The double value of 05462 * linear accel z meterpersecseq 05463 * 05464 * @return results of bus communication function 05465 * @retval 0 -> BNO055_SUCCESS 05466 * @retval 1 -> BNO055_ERROR 05467 * 05468 * 05469 */ 05470 05471 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_linear_accel_z_msq( 05472 double *linear_accel_z_d) 05473 { 05474 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05475 s16 reg_linear_accel_z_s16 = BNO055_INIT_VALUE; 05476 double data_d = BNO055_INIT_VALUE; 05477 /* Read the raw x of linear accel */ 05478 com_rslt = bno055_read_linear_accel_z(®_linear_accel_z_s16); 05479 if (com_rslt == BNO055_SUCCESS) { 05480 /* Convert the raw z to m/s2 */ 05481 data_d = 05482 (double)(reg_linear_accel_z_s16/BNO055_LINEAR_ACCEL_DIV_MSQ); 05483 *linear_accel_z_d = data_d; 05484 } else { 05485 com_rslt = BNO055_ERROR; 05486 } 05487 return com_rslt; 05488 } 05489 /*! 05490 * @brief This API is used to convert the linear accel xyz raw data 05491 * to meterpersecseq output as double 05492 * 05493 * @param linear_accel_xyz : The meterpersecseq data of linear accel xyz 05494 * 05495 * Parameter | result 05496 * --------- | ----------------- 05497 * x | meterpersecseq data of linear accel 05498 * y | meterpersecseq data of linear accel 05499 * z | meterpersecseq data of linear accel 05500 * 05501 * 05502 * @return results of bus communication function 05503 * @retval 0 -> BNO055_SUCCESS 05504 * @retval 1 -> BNO055_ERROR 05505 * 05506 */ 05507 05508 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_linear_accel_xyz_msq( 05509 struct bno055_linear_accel_double_t *linear_accel_xyz) 05510 { 05511 /* Variable used to return value of 05512 communication routine*/ 05513 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05514 struct bno055_linear_accel_t reg_linear_accel_xyz = { 05515 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 05516 /* Read the raw xyz of linear accel */ 05517 com_rslt = bno055_read_linear_accel_xyz(®_linear_accel_xyz); 05518 if (com_rslt == BNO055_SUCCESS) { 05519 /* Convert the raw xyz of linear accel to m/s2 */ 05520 linear_accel_xyz->x = 05521 (double)(reg_linear_accel_xyz.x/BNO055_LINEAR_ACCEL_DIV_MSQ); 05522 linear_accel_xyz->y = 05523 (double)(reg_linear_accel_xyz.y/BNO055_LINEAR_ACCEL_DIV_MSQ); 05524 linear_accel_xyz->z = 05525 (double)(reg_linear_accel_xyz.z/BNO055_LINEAR_ACCEL_DIV_MSQ); 05526 } else { 05527 com_rslt = BNO055_ERROR; 05528 } 05529 return com_rslt; 05530 } 05531 /*! 05532 * @brief This API is used to convert the gravity 05533 * x raw data to meterpersecseq output as double 05534 * 05535 * @param gravity_x_d : The double value of gravity x meterpersecseq 05536 * 05537 * @return results of bus communication function 05538 * @retval 0 -> BNO055_SUCCESS 05539 * @retval 1 -> BNO055_ERROR 05540 * 05541 * 05542 */ 05543 BNO055_RETURN_FUNCTION_TYPE bno055_convert_gravity_double_x_msq( 05544 double *gravity_x_d) 05545 { 05546 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05547 s16 reg_gravity_x_s16 = BNO055_INIT_VALUE; 05548 double data_d = BNO055_INIT_VALUE; 05549 /* Read raw gravity of x*/ 05550 com_rslt = bno055_read_gravity_x(®_gravity_x_s16); 05551 if (com_rslt == BNO055_SUCCESS) { 05552 /* Convert raw gravity of x to m/s2 */ 05553 data_d = 05554 (double)(reg_gravity_x_s16/BNO055_GRAVITY_DIV_MSQ); 05555 *gravity_x_d = data_d; 05556 } else { 05557 com_rslt = BNO055_ERROR; 05558 } 05559 return com_rslt; 05560 } 05561 /*! 05562 * @brief This API is used to convert the gravity 05563 * y raw data to meterpersecseq output as double 05564 * 05565 * @param gravity_y_d : The double value of gravity y meterpersecseq 05566 * 05567 * @return results of bus communication function 05568 * @retval 0 -> BNO055_SUCCESS 05569 * @retval 1 -> BNO055_ERROR 05570 * 05571 * 05572 */ 05573 BNO055_RETURN_FUNCTION_TYPE bno055_convert_gravity_double_y_msq( 05574 double *gravity_y_d) 05575 { 05576 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05577 s16 reg_gravity_y_s16 = BNO055_INIT_VALUE; 05578 double data_d = BNO055_INIT_VALUE; 05579 /* Read raw gravity of y */ 05580 com_rslt = bno055_read_gravity_y(®_gravity_y_s16); 05581 if (com_rslt == BNO055_SUCCESS) { 05582 /* convert raw gravity of y to m/s2 */ 05583 data_d = 05584 (double)(reg_gravity_y_s16/BNO055_GRAVITY_DIV_MSQ); 05585 *gravity_y_d = data_d; 05586 } else { 05587 com_rslt += BNO055_ERROR; 05588 } 05589 return com_rslt; 05590 } 05591 /*! 05592 * @brief This API is used to convert the gravity 05593 * z raw data to meterpersecseq output as double 05594 * 05595 * @param gravity_z_d : The double value of gravity z meterpersecseq 05596 * 05597 * @return results of bus communication function 05598 * @retval 0 -> BNO055_SUCCESS 05599 * @retval 1 -> BNO055_ERROR 05600 * 05601 * 05602 */ 05603 BNO055_RETURN_FUNCTION_TYPE bno055_convert_gravity_double_z_msq( 05604 double *gravity_z_d) 05605 { 05606 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05607 s16 reg_gravity_z_s16 = BNO055_INIT_VALUE; 05608 double data_d = BNO055_INIT_VALUE; 05609 /* Read raw gravity of z */ 05610 com_rslt = bno055_read_gravity_z(®_gravity_z_s16); 05611 if (com_rslt == BNO055_SUCCESS) { 05612 /* Convert raw gravity of z to m/s2 */ 05613 data_d = 05614 (double)(reg_gravity_z_s16/BNO055_GRAVITY_DIV_MSQ); 05615 *gravity_z_d = data_d; 05616 } else { 05617 com_rslt += BNO055_ERROR; 05618 } 05619 return com_rslt; 05620 } 05621 /*! 05622 * @brief This API is used to convert the gravity xyz raw data 05623 * to meterpersecseq output as double 05624 * 05625 * @param gravity_xyz : The meterpersecseq data of gravity xyz 05626 * 05627 * Parameter | result 05628 * --------- | ----------------- 05629 * x | meterpersecseq data of gravity 05630 * y | meterpersecseq data of gravity 05631 * z | meterpersecseq data of gravity 05632 * 05633 * 05634 * @return results of bus communication function 05635 * @retval 0 -> BNO055_SUCCESS 05636 * @retval 1 -> BNO055_ERROR 05637 * 05638 */ 05639 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_gravity_xyz_msq( 05640 struct bno055_gravity_double_t *gravity_xyz) 05641 { 05642 /* Variable used to return value of 05643 communication routine*/ 05644 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05645 struct bno055_gravity_t reg_gravity_xyz = { 05646 BNO055_INIT_VALUE, BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 05647 /* Read raw gravity of xyz */ 05648 com_rslt = bno055_read_gravity_xyz(®_gravity_xyz); 05649 if (com_rslt == BNO055_SUCCESS) { 05650 /* Convert raw gravity of xyz to m/s2 */ 05651 gravity_xyz->x = 05652 (double)(reg_gravity_xyz.x/BNO055_GRAVITY_DIV_MSQ); 05653 gravity_xyz->y = 05654 (double)(reg_gravity_xyz.y/BNO055_GRAVITY_DIV_MSQ); 05655 gravity_xyz->z = 05656 (double)(reg_gravity_xyz.z/BNO055_GRAVITY_DIV_MSQ); 05657 } else { 05658 com_rslt += BNO055_ERROR; 05659 } 05660 return com_rslt; 05661 } 05662 /*! 05663 * @brief This API is used to convert the temperature 05664 * data to Fahrenheit output as double 05665 * 05666 * @param temp_d : The double value of temperature Fahrenheit 05667 * 05668 * @return results of bus communication function 05669 * @retval 0 -> BNO055_SUCCESS 05670 * @retval 1 -> BNO055_ERROR 05671 * 05672 * 05673 */ 05674 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_temp_fahrenheit( 05675 double *temp_d) 05676 { 05677 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05678 s8 reg_temp_s8 = BNO055_INIT_VALUE; 05679 double data_d = BNO055_INIT_VALUE; 05680 u8 temp_unit_u8 = BNO055_INIT_VALUE; 05681 /* Read the current temperature unit and set the 05682 unit as Fahrenheit if the unit is in Celsius */ 05683 com_rslt = bno055_get_temp_unit(&temp_unit_u8); 05684 if (temp_unit_u8 != BNO055_TEMP_UNIT_FAHRENHEIT) 05685 com_rslt += bno055_set_temp_unit(BNO055_TEMP_UNIT_FAHRENHEIT); 05686 if (com_rslt == BNO055_SUCCESS) { 05687 /* Read the raw temperature data */ 05688 com_rslt += bno055_read_temp_data(®_temp_s8); 05689 if (com_rslt == BNO055_SUCCESS) { 05690 /* Convert raw temperature data to Fahrenheit*/ 05691 data_d = (double)(reg_temp_s8/ 05692 BNO055_TEMP_DIV_FAHRENHEIT); 05693 *temp_d = data_d; 05694 } else { 05695 com_rslt += BNO055_ERROR; 05696 } 05697 } else { 05698 com_rslt += BNO055_ERROR; 05699 } 05700 return com_rslt; 05701 } 05702 /*! 05703 * @brief This API is used to convert the temperature 05704 * data to Celsius output as double 05705 * 05706 * @param temp_d : The double value of temperature Celsius 05707 * 05708 * @return results of bus communication function 05709 * @retval 0 -> BNO055_SUCCESS 05710 * @retval 1 -> BNO055_ERROR 05711 * 05712 * 05713 */ 05714 BNO055_RETURN_FUNCTION_TYPE bno055_convert_double_temp_celsius( 05715 double *temp_d) 05716 { 05717 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05718 s8 reg_temp_s8 = BNO055_INIT_VALUE; 05719 double data_d = BNO055_INIT_VALUE; 05720 u8 temp_unit_u8 = BNO055_INIT_VALUE; 05721 /* Read the current temperature unit and set the 05722 unit as Fahrenheit if the unit is in Celsius */ 05723 com_rslt = bno055_get_temp_unit(&temp_unit_u8); 05724 if (temp_unit_u8 != BNO055_TEMP_UNIT_CELSIUS) 05725 com_rslt += bno055_set_temp_unit(BNO055_TEMP_UNIT_CELSIUS); 05726 if (com_rslt == BNO055_SUCCESS) { 05727 /* Read the raw temperature data */ 05728 com_rslt += bno055_read_temp_data(®_temp_s8); 05729 if (com_rslt == BNO055_SUCCESS) { 05730 /* Convert raw temperature data to Fahrenheit*/ 05731 data_d = 05732 (double)(reg_temp_s8/BNO055_TEMP_DIV_CELSIUS); 05733 *temp_d = data_d; 05734 } else { 05735 com_rslt += BNO055_ERROR; 05736 } 05737 } else { 05738 com_rslt += BNO055_ERROR; 05739 } 05740 return com_rslt; 05741 } 05742 #endif 05743 /*! 05744 * @brief This API used to read 05745 * mag calibration status from register from 0x35 bit 0 and 1 05746 * 05747 * @param mag_calib_u8 : The value of mag calib status 05748 * 05749 * 05750 * @return results of bus communication function 05751 * @retval 0 -> BNO055_SUCCESS 05752 * @retval 1 -> BNO055_ERROR 05753 * 05754 */ 05755 BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_calib_stat( 05756 u8 *mag_calib_u8) 05757 { 05758 /* Variable used to return value of 05759 communication routine*/ 05760 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05761 u8 data_u8r = BNO055_INIT_VALUE; 05762 s8 stat_s8 = BNO055_ERROR; 05763 /* Check the struct p_bno055 is empty */ 05764 if (p_bno055 == BNO055_INIT_VALUE) { 05765 return BNO055_E_NULL_PTR; 05766 } else { 05767 /*condition check for page, mag calib 05768 available in the page zero*/ 05769 if (p_bno055->page_id != BNO055_PAGE_ZERO) 05770 /* Write the page zero*/ 05771 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 05772 if ((stat_s8 == BNO055_SUCCESS) || 05773 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 05774 /* Read the mag calib stat_s8 */ 05775 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 05776 (p_bno055->dev_addr, 05777 BNO055_MAG_CALIB_STAT_REG, 05778 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 05779 *mag_calib_u8 = 05780 BNO055_GET_BITSLICE(data_u8r, 05781 BNO055_MAG_CALIB_STAT); 05782 } else { 05783 com_rslt = BNO055_ERROR; 05784 } 05785 } 05786 return com_rslt; 05787 } 05788 /*! 05789 * @brief This API used to read 05790 * accel calibration status from register from 0x35 bit 2 and 3 05791 * 05792 * @param accel_calib_u8 : The value of accel calib status 05793 * 05794 * 05795 * @return results of bus communication function 05796 * @retval 0 -> BNO055_SUCCESS 05797 * @retval 1 -> BNO055_ERROR 05798 * 05799 */ 05800 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_calib_stat( 05801 u8 *accel_calib_u8) 05802 { 05803 /* Variable used to return value of 05804 communication routine*/ 05805 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05806 u8 data_u8r = BNO055_INIT_VALUE; 05807 s8 stat_s8 = BNO055_ERROR; 05808 /* Check the struct p_bno055 is empty*/ 05809 if (p_bno055 == BNO055_INIT_VALUE) { 05810 return BNO055_E_NULL_PTR; 05811 } else { 05812 /*condition check for page, accel calib 05813 available in the page zero*/ 05814 if (p_bno055->page_id != BNO055_PAGE_ZERO) 05815 /* Write the page zero*/ 05816 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 05817 if ((stat_s8 == BNO055_SUCCESS) || 05818 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 05819 /* Read the accel calib stat_s8 */ 05820 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 05821 (p_bno055->dev_addr, 05822 BNO055_ACCEL_CALIB_STAT_REG, 05823 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 05824 *accel_calib_u8 = 05825 BNO055_GET_BITSLICE(data_u8r, 05826 BNO055_ACCEL_CALIB_STAT); 05827 } else { 05828 com_rslt = BNO055_ERROR; 05829 } 05830 } 05831 return com_rslt; 05832 } 05833 /*! 05834 * @brief This API used to read 05835 * gyro calibration status from register from 0x35 bit 4 and 5 05836 * 05837 * @param gyro_calib_u8 : The value of gyro calib status 05838 * 05839 * 05840 * @return results of bus communication function 05841 * @retval 0 -> BNO055_SUCCESS 05842 * @retval 1 -> BNO055_ERROR 05843 * 05844 */ 05845 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_calib_stat( 05846 u8 *gyro_calib_u8) 05847 { 05848 /* Variable used to return value of 05849 communication routine*/ 05850 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05851 u8 data_u8r = BNO055_INIT_VALUE; 05852 s8 stat_s8 = BNO055_ERROR; 05853 /* Check the struct p_bno055 is empty */ 05854 if (p_bno055 == BNO055_INIT_VALUE) { 05855 return BNO055_E_NULL_PTR; 05856 } else { 05857 /*condition check for page, gyro calib 05858 available in the page zero*/ 05859 if (p_bno055->page_id != BNO055_PAGE_ZERO) 05860 /* Write the page zero*/ 05861 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 05862 if ((stat_s8 == BNO055_SUCCESS) || 05863 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 05864 /* Read the gyro calib status */ 05865 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 05866 (p_bno055->dev_addr, 05867 BNO055_GYRO_CALIB_STAT_REG, 05868 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 05869 *gyro_calib_u8 = 05870 BNO055_GET_BITSLICE(data_u8r, 05871 BNO055_GYRO_CALIB_STAT); 05872 } else { 05873 com_rslt = BNO055_ERROR; 05874 } 05875 } 05876 return com_rslt; 05877 } 05878 /*! 05879 * @brief This API used to read 05880 * system calibration status from register from 0x35 bit 6 and 7 05881 * 05882 * @param sys_calib_u8 : The value of system calib status 05883 * 05884 * 05885 * @return results of bus communication function 05886 * @retval 0 -> BNO055_SUCCESS 05887 * @retval 1 -> BNO055_ERROR 05888 * 05889 */ 05890 BNO055_RETURN_FUNCTION_TYPE bno055_get_sys_calib_stat( 05891 u8 *sys_calib_u8) 05892 { 05893 /* Variable used to return value of 05894 communication routine*/ 05895 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05896 u8 data_u8r = BNO055_INIT_VALUE; 05897 s8 stat_s8 = BNO055_ERROR; 05898 /* Check the struct p_bno055 is empty*/ 05899 if (p_bno055 == BNO055_INIT_VALUE) { 05900 return BNO055_E_NULL_PTR; 05901 } else { 05902 /*condition check for page,system calib 05903 available in the page zero*/ 05904 if (p_bno055->page_id != BNO055_PAGE_ZERO) 05905 /* Write the page zero*/ 05906 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 05907 if ((stat_s8 == BNO055_SUCCESS) || 05908 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 05909 /* Read the system calib */ 05910 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 05911 (p_bno055->dev_addr, 05912 BNO055_SYS_CALIB_STAT_REG, 05913 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 05914 *sys_calib_u8 = 05915 BNO055_GET_BITSLICE(data_u8r, BNO055_SYS_CALIB_STAT); 05916 } else { 05917 com_rslt = BNO055_ERROR; 05918 } 05919 } 05920 return com_rslt; 05921 } 05922 /*! 05923 * @brief This API used to read 05924 * all calibration status from register from 0x35 05925 * 05926 * @param all_calib_u8 : The value of system calib status 05927 * 05928 * 05929 * @return results of bus communication function 05930 * @retval 0 -> BNO055_SUCCESS 05931 * @retval 1 -> BNO055_ERROR 05932 * 05933 */ 05934 BNO055_RETURN_FUNCTION_TYPE bno055_get_all_calib_stat( 05935 u8 *all_calib_u8) 05936 { 05937 /* Variable used to return value of 05938 communication routine*/ 05939 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05940 u8 data_u8r = BNO055_INIT_VALUE; 05941 s8 stat_s8 = BNO055_ERROR; 05942 /* Check the struct p_bno055 is empty*/ 05943 if (p_bno055 == BNO055_INIT_VALUE) { 05944 return BNO055_E_NULL_PTR; 05945 } else { 05946 /*condition check for page,system calib 05947 available in the page zero*/ 05948 if (p_bno055->page_id != BNO055_PAGE_ZERO) 05949 /* Write the page zero*/ 05950 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 05951 if ((stat_s8 == BNO055_SUCCESS) || 05952 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 05953 /* Read the system calib */ 05954 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 05955 (p_bno055->dev_addr, 05956 BNO055_ALL_CALIB_STAT_REG, 05957 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 05958 *all_calib_u8 = 05959 BNO055_GET_BITSLICE(data_u8r, BNO055_ALL_CALIB_STAT); 05960 } else { 05961 com_rslt = BNO055_ERROR; 05962 } 05963 } 05964 return com_rslt; 05965 } 05966 /*! 05967 * @brief This API used to read 05968 * self test of accel from register from 0x36 bit 0 05969 * 05970 * @param selftest_accel_u8 : The value of self test of accel 05971 * 05972 * selftest_accel_u8 | result 05973 * -------------------- | --------------------- 05974 * 0x00 | indicates test failed 05975 * 0x01 | indicated test passed 05976 * 05977 * @return results of bus communication function 05978 * @retval 0 -> BNO055_SUCCESS 05979 * @retval 1 -> BNO055_ERROR 05980 * 05981 */ 05982 BNO055_RETURN_FUNCTION_TYPE bno055_get_selftest_accel( 05983 u8 *selftest_accel_u8) 05984 { 05985 /* Variable used to return value of 05986 communication routine*/ 05987 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 05988 u8 data_u8r = BNO055_INIT_VALUE; 05989 s8 stat_s8 = BNO055_ERROR; 05990 /* Check the struct p_bno055 is empty */ 05991 if (p_bno055 == BNO055_INIT_VALUE) { 05992 return BNO055_E_NULL_PTR; 05993 } else { 05994 /*condition check for page, accel self test is 05995 available in the page zero*/ 05996 if (p_bno055->page_id != BNO055_PAGE_ZERO) 05997 /* Write the page zero*/ 05998 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 05999 if ((stat_s8 == BNO055_SUCCESS) || 06000 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06001 /* Read the accel self test */ 06002 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06003 (p_bno055->dev_addr, 06004 BNO055_SELFTEST_ACCEL_REG, 06005 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06006 *selftest_accel_u8 = 06007 BNO055_GET_BITSLICE(data_u8r, 06008 BNO055_SELFTEST_ACCEL); 06009 } else { 06010 com_rslt = BNO055_ERROR; 06011 } 06012 } 06013 return com_rslt; 06014 } 06015 /*! 06016 * @brief This API used to read 06017 * self test of mag from register from 0x36 bit 1 06018 * 06019 * @param selftest_mag_u8 : The value of self test of mag 06020 * 06021 * selftest_mag_u8 | result 06022 * -------------------- | --------------------- 06023 * 0x00 | indicates test failed 06024 * 0x01 | indicated test passed 06025 * 06026 * @return results of bus communication function 06027 * @retval 0 -> BNO055_SUCCESS 06028 * @retval 1 -> BNO055_ERROR 06029 * 06030 */ 06031 BNO055_RETURN_FUNCTION_TYPE bno055_get_selftest_mag( 06032 u8 *selftest_mag_u8) 06033 { 06034 /* Variable used to return value of 06035 communication routine*/ 06036 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06037 u8 data_u8r = BNO055_INIT_VALUE; 06038 s8 stat_s8 = BNO055_ERROR; 06039 /* Check the struct p_bno055 is empty */ 06040 if (p_bno055 == BNO055_INIT_VALUE) { 06041 return BNO055_E_NULL_PTR; 06042 } else { 06043 /*condition check for page, self test of mag is 06044 available in the page zero*/ 06045 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06046 /* Write the page zero*/ 06047 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06048 if ((stat_s8 == BNO055_SUCCESS) || 06049 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06050 /* Read the mag self test */ 06051 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06052 (p_bno055->dev_addr, 06053 BNO055_SELFTEST_MAG_REG, &data_u8r, 06054 BNO055_GEN_READ_WRITE_LENGTH); 06055 *selftest_mag_u8 = 06056 BNO055_GET_BITSLICE(data_u8r, BNO055_SELFTEST_MAG); 06057 } else { 06058 com_rslt = BNO055_ERROR; 06059 } 06060 } 06061 return com_rslt; 06062 } 06063 /*! 06064 * @brief This API used to read 06065 * self test of gyro from register from 0x36 bit 2 06066 * 06067 * @param selftest_gyro_u8 : The value of self test of gyro 06068 * 06069 * selftest_gyro_u8 | result 06070 * -------------------- | --------------------- 06071 * 0x00 | indicates test failed 06072 * 0x01 | indicated test passed 06073 * 06074 * @return results of bus communication function 06075 * @retval 0 -> BNO055_SUCCESS 06076 * @retval 1 -> BNO055_ERROR 06077 * 06078 */ 06079 BNO055_RETURN_FUNCTION_TYPE bno055_get_selftest_gyro( 06080 u8 *selftest_gyro_u8) 06081 { 06082 /* Variable used to return value of 06083 communication routine*/ 06084 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06085 u8 data_u8r = BNO055_INIT_VALUE; 06086 s8 stat_s8 = BNO055_ERROR; 06087 /* Check the struct p_bno055 is empty */ 06088 if (p_bno055 == BNO055_INIT_VALUE) { 06089 return BNO055_E_NULL_PTR; 06090 } else { 06091 /*condition check for page self test of gyro is 06092 available in the page zero*/ 06093 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06094 /* Write the page zero*/ 06095 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06096 if ((stat_s8 == BNO055_SUCCESS) || 06097 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06098 /* Read the gyro self test */ 06099 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06100 (p_bno055->dev_addr, 06101 BNO055_SELFTEST_GYRO_REG, &data_u8r, 06102 BNO055_GEN_READ_WRITE_LENGTH); 06103 *selftest_gyro_u8 = 06104 BNO055_GET_BITSLICE(data_u8r, BNO055_SELFTEST_GYRO); 06105 } else { 06106 com_rslt = BNO055_ERROR; 06107 } 06108 } 06109 return com_rslt; 06110 } 06111 /*! 06112 * @brief This API used to read 06113 * self test of micro controller from register from 0x36 bit 3 06114 * 06115 * @param selftest_mcu_u8 : The value of self test of micro controller 06116 * 06117 * selftest_mcu_u8 | result 06118 * -------------------- | --------------------- 06119 * 0x00 | indicates test failed 06120 * 0x01 | indicated test passed 06121 * 06122 * @return results of bus communication function 06123 * @retval 0 -> BNO055_SUCCESS 06124 * @retval 1 -> BNO055_ERROR 06125 * 06126 */ 06127 BNO055_RETURN_FUNCTION_TYPE bno055_get_selftest_mcu( 06128 u8 *selftest_mcu_u8) 06129 { 06130 /* Variable used to return value of 06131 communication routine*/ 06132 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06133 u8 data_u8r = BNO055_INIT_VALUE; 06134 s8 stat_s8 = BNO055_ERROR; 06135 /* Check the struct p_bno055 is empty */ 06136 if (p_bno055 == BNO055_INIT_VALUE) { 06137 return BNO055_E_NULL_PTR; 06138 } else { 06139 /*condition check for page self test of micro controller 06140 is available in the page zero*/ 06141 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06142 /* Write the page zero*/ 06143 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06144 if ((stat_s8 == BNO055_SUCCESS) || 06145 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06146 /* Read the self test of micro controller*/ 06147 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06148 (p_bno055->dev_addr, 06149 BNO055_SELFTEST_MCU_REG, &data_u8r, 06150 BNO055_GEN_READ_WRITE_LENGTH); 06151 *selftest_mcu_u8 = 06152 BNO055_GET_BITSLICE(data_u8r, BNO055_SELFTEST_MCU); 06153 } else { 06154 com_rslt = BNO055_ERROR; 06155 } 06156 } 06157 return com_rslt; 06158 } 06159 /*! 06160 * @brief This API used to read the stat_s8 of 06161 * gyro anymotion interrupt from register from 0x37 bit 2 06162 * 06163 * @param gyro_any_motion_u8 : The value of gyro anymotion interrupt 06164 * 06165 * gyro_any_motion_u8 | result 06166 * -------------------- | --------------------- 06167 * 0x00 | indicates no interrupt triggered 06168 * 0x01 | indicates interrupt triggered 06169 * 06170 * @return results of bus communication function 06171 * @retval 0 -> BNO055_SUCCESS 06172 * @retval 1 -> BNO055_ERROR 06173 * 06174 * @note Gyro anymotion interrupt can be BNO055_BIT_ENABLE 06175 * by the following APIs 06176 * 06177 * bno055_set_intr_mask_gyro_any_motion() 06178 * 06179 * bno055_set_intr_gyro_any_motion() 06180 * 06181 */ 06182 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_stat_gyro_any_motion( 06183 u8 *gyro_any_motion_u8) 06184 { 06185 /* Variable used to return value of 06186 communication routine*/ 06187 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06188 u8 data_u8r = BNO055_INIT_VALUE; 06189 s8 stat_s8 = BNO055_ERROR; 06190 /* Check the struct p_bno055 is empty */ 06191 if (p_bno055 == BNO055_INIT_VALUE) { 06192 return BNO055_E_NULL_PTR; 06193 } else { 06194 /*condition check for page, gyro anymotion interrupt 06195 status is available in the page zero*/ 06196 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06197 /* Write the page zero*/ 06198 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06199 if ((stat_s8 == BNO055_SUCCESS) || 06200 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06201 /* Read the gyro anymotion interrupt stat_s8*/ 06202 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06203 (p_bno055->dev_addr, 06204 BNO055_INTR_STAT_GYRO_ANY_MOTION_REG, 06205 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06206 *gyro_any_motion_u8 = 06207 BNO055_GET_BITSLICE(data_u8r, 06208 BNO055_INTR_STAT_GYRO_ANY_MOTION); 06209 } else { 06210 com_rslt = BNO055_ERROR; 06211 } 06212 } 06213 return com_rslt; 06214 } 06215 /*! 06216 * @brief This API used to read the stat_s8 of 06217 * gyro highrate interrupt from register from 0x37 bit 3 06218 * 06219 * @param gyro_highrate_u8 : The value of gyro highrate interrupt 06220 * 06221 * gyro_highrate_u8 | result 06222 * ------------------- | --------------------- 06223 * 0x00 | indicates no interrupt triggered 06224 * 0x01 | indicates interrupt triggered 06225 * 06226 * @return results of bus communication function 06227 * @retval 0 -> BNO055_SUCCESS 06228 * @retval 1 -> BNO055_ERROR 06229 * 06230 * @note Gyro highrate interrupt can be configured 06231 * by the following APIs 06232 * 06233 * bno055_set_intr_mask_gyro_highrate() 06234 * 06235 * bno055_set_intr_gyro_highrate() 06236 */ 06237 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_stat_gyro_highrate( 06238 u8 *gyro_highrate_u8) 06239 { 06240 /* Variable used to return value of 06241 communication routine*/ 06242 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06243 u8 data_u8r = BNO055_INIT_VALUE; 06244 s8 stat_s8 = BNO055_ERROR; 06245 /* Check the struct p_bno055 is empty */ 06246 if (p_bno055 == BNO055_INIT_VALUE) { 06247 return BNO055_E_NULL_PTR; 06248 } else { 06249 /*condition check for page, gyro highrate is 06250 available in the page zero*/ 06251 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06252 /* Write the page zero*/ 06253 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06254 if ((stat_s8 == BNO055_SUCCESS) || 06255 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06256 /* Read the gyro highrate interrupt stat_s8*/ 06257 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06258 (p_bno055->dev_addr, 06259 BNO055_INTR_STAT_GYRO_HIGHRATE_REG, 06260 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06261 *gyro_highrate_u8 = 06262 BNO055_GET_BITSLICE(data_u8r, 06263 BNO055_INTR_STAT_GYRO_HIGHRATE); 06264 } else { 06265 com_rslt = BNO055_ERROR; 06266 } 06267 } 06268 return com_rslt; 06269 } 06270 /*! 06271 * @brief This API used to read the stat_s8 of 06272 * accel highg interrupt from register from 0x37 bit 5 06273 * 06274 * @param accel_high_g_u8 : The value of accel highg interrupt 06275 * 06276 * accel_high_g_u8 | result 06277 * ------------------- | --------------------- 06278 * 0x00 | indicates no interrupt triggered 06279 * 0x01 | indicates interrupt triggered 06280 * 06281 * @return results of bus communication function 06282 * @retval 0 -> BNO055_SUCCESS 06283 * @retval 1 -> BNO055_ERROR 06284 * 06285 * @note Accel highg interrupt can be configured 06286 * by the following APIs 06287 * 06288 * bno055_set_intr_mask_accel_high_g() 06289 * 06290 * bno055_set_intr_accel_high_g() 06291 * 06292 */ 06293 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_stat_accel_high_g( 06294 u8 *accel_high_g_u8) 06295 { 06296 /* Variable used to return value of 06297 communication routine*/ 06298 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06299 u8 data_u8r = BNO055_INIT_VALUE; 06300 s8 stat_s8 = BNO055_ERROR; 06301 /* Check the struct p_bno055 is empty */ 06302 if (p_bno055 == BNO055_INIT_VALUE) { 06303 return BNO055_E_NULL_PTR; 06304 } else { 06305 /*condition check for page, accel highg is 06306 available in the page zero*/ 06307 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06308 /* Write the page zero*/ 06309 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06310 if ((stat_s8 == BNO055_SUCCESS) || 06311 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06312 /* Read the accel highg interrupt stat_s8 */ 06313 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06314 (p_bno055->dev_addr, 06315 BNO055_INTR_STAT_ACCEL_HIGH_G_REG, 06316 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06317 *accel_high_g_u8 = 06318 BNO055_GET_BITSLICE(data_u8r, 06319 BNO055_INTR_STAT_ACCEL_HIGH_G); 06320 } else { 06321 com_rslt = BNO055_ERROR; 06322 } 06323 } 06324 return com_rslt; 06325 } 06326 /*! 06327 * @brief This API used to read the stat_s8 of 06328 * accel anymotion interrupt from register from 0x37 bit 6 06329 * 06330 * @param accel_any_motion_u8 : The value of accel anymotion interrupt 06331 * 06332 * accel_any_motion_u8 | result 06333 * ------------------- | --------------------- 06334 * 0x00 | indicates no interrupt triggered 06335 * 0x01 | indicates interrupt triggered 06336 * 06337 * @return results of bus communication function 06338 * @retval 0 -> BNO055_SUCCESS 06339 * @retval 1 -> BNO055_ERROR 06340 * 06341 * @note Accel anymotion interrupt can be configured 06342 * by the following APIs 06343 * 06344 * bno055_set_intr_mask_accel_any_motion() 06345 * 06346 * bno055_set_intr_accel_any_motion() 06347 */ 06348 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_stat_accel_any_motion( 06349 u8 *accel_any_motion_u8) 06350 { 06351 /* Variable used to return value of 06352 communication routine*/ 06353 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06354 u8 data_u8r = BNO055_INIT_VALUE; 06355 s8 stat_s8 = BNO055_ERROR; 06356 /* Check the struct p_bno055 is empty */ 06357 if (p_bno055 == BNO055_INIT_VALUE) { 06358 return BNO055_E_NULL_PTR; 06359 } else { 06360 /*condition check for page, accel anymotion is 06361 available in the page zero*/ 06362 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06363 /* Write the page zero*/ 06364 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06365 if ((stat_s8 == BNO055_SUCCESS) || 06366 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06367 /* Read the accel anymotion interrupt stat_s8 */ 06368 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06369 (p_bno055->dev_addr, 06370 BNO055_INTR_STAT_ACCEL_ANY_MOTION_REG, 06371 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06372 *accel_any_motion_u8 = 06373 BNO055_GET_BITSLICE(data_u8r, 06374 BNO055_INTR_STAT_ACCEL_ANY_MOTION); 06375 } else { 06376 com_rslt = BNO055_ERROR; 06377 } 06378 } 06379 return com_rslt; 06380 } 06381 /*! 06382 * @brief This API used to read the stat_s8 of 06383 * accel nomotion/slowmotion interrupt from register from 0x37 bit 6 06384 * 06385 * @param accel_no_motion_u8 : The value of accel 06386 * nomotion/slowmotion interrupt 06387 * 06388 * accel_no_motion_u8 | result 06389 * ------------------- | --------------------- 06390 * 0x00 | indicates no interrupt triggered 06391 * 0x01 | indicates interrupt triggered 06392 * 06393 * @return results of bus communication function 06394 * @retval 0 -> BNO055_SUCCESS 06395 * @retval 1 -> BNO055_ERROR 06396 * 06397 * @note Accel nomotion/slowmotion interrupt can be configured 06398 * by the following APIs 06399 * 06400 * bno055_set_intr_mask_accel_nomotion() 06401 * 06402 * bno055_set_intr_accel_nomotion() 06403 */ 06404 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_stat_accel_no_motion( 06405 u8 *accel_no_motion_u8) 06406 { 06407 /* Variable used to return value of 06408 communication routine*/ 06409 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06410 u8 data_u8r = BNO055_INIT_VALUE; 06411 s8 stat_s8 = BNO055_ERROR; 06412 /* Check the struct p_bno055 is empty */ 06413 if (p_bno055 == BNO055_INIT_VALUE) { 06414 return BNO055_E_NULL_PTR; 06415 } else { 06416 /*condition check for page, accel 06417 nomotion/slowmotion interrupt 06418 is available in the page zero*/ 06419 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06420 /* Write the page zero*/ 06421 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06422 if ((stat_s8 == BNO055_SUCCESS) || 06423 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06424 /* Read the stat_s8 of accel 06425 nomotion/slowmotion interrupt*/ 06426 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06427 (p_bno055->dev_addr, 06428 BNO055_INTR_STAT_ACCEL_NO_MOTION_REG, 06429 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06430 *accel_no_motion_u8 = 06431 BNO055_GET_BITSLICE(data_u8r, 06432 BNO055_INTR_STAT_ACCEL_NO_MOTION); 06433 } else { 06434 com_rslt = BNO055_ERROR; 06435 } 06436 } 06437 return com_rslt; 06438 } 06439 /*! 06440 * @brief This API is used to read status of main clock 06441 * from the register 0x38 bit 0 06442 * 06443 * @param stat_main_clk_u8 : the status of main clock 06444 * 06445 * 06446 * @return results of bus communication function 06447 * @retval 0 -> BNO055_SUCCESS 06448 * @retval 1 -> BNO055_ERROR 06449 * 06450 */ 06451 BNO055_RETURN_FUNCTION_TYPE bno055_get_stat_main_clk( 06452 u8 *stat_main_clk_u8) 06453 { 06454 /* Variable used to return value of 06455 communication routine*/ 06456 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06457 u8 data_u8r = BNO055_INIT_VALUE; 06458 s8 stat_s8 = BNO055_ERROR; 06459 /* Check the struct p_bno055 is empty */ 06460 if (p_bno055 == BNO055_INIT_VALUE) { 06461 return BNO055_E_NULL_PTR; 06462 } else { 06463 /*condition check for page, status of main clk is 06464 available in the page zero*/ 06465 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06466 /* Write the page zero*/ 06467 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06468 if ((stat_s8 == BNO055_SUCCESS) || 06469 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06470 /* Read the status of main clk */ 06471 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06472 (p_bno055->dev_addr, 06473 BNO055_SYS_MAIN_CLK_REG, 06474 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06475 *stat_main_clk_u8 = 06476 BNO055_GET_BITSLICE(data_u8r, BNO055_SYS_MAIN_CLK); 06477 } else { 06478 com_rslt = BNO055_ERROR; 06479 } 06480 } 06481 return com_rslt; 06482 } 06483 /*! 06484 * @brief This API is used to read system status 06485 * code from the register 0x39 it is a byte of data 06486 * 06487 * @param sys_stat_u8 : the status of system 06488 * 06489 * 06490 * @return results of bus communication function 06491 * @retval 0 -> BNO055_SUCCESS 06492 * @retval 1 -> BNO055_ERROR 06493 * 06494 */ 06495 BNO055_RETURN_FUNCTION_TYPE bno055_get_sys_stat_code( 06496 u8 *sys_stat_u8) 06497 { 06498 /* Variable used to return value of 06499 communication routine*/ 06500 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06501 u8 data_u8r = BNO055_INIT_VALUE; 06502 s8 stat_s8 = BNO055_ERROR; 06503 /* Check the struct p_bno055 is empty */ 06504 if (p_bno055 == BNO055_INIT_VALUE) { 06505 return BNO055_E_NULL_PTR; 06506 } else { 06507 /*condition check for page, the status of system is 06508 available in the page zero*/ 06509 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06510 /* Write the page zero*/ 06511 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06512 if ((stat_s8 == BNO055_SUCCESS) || 06513 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06514 /* Read the the status of system*/ 06515 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06516 (p_bno055->dev_addr, 06517 BNO055_SYS_STAT_CODE_REG, 06518 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06519 *sys_stat_u8 = 06520 BNO055_GET_BITSLICE(data_u8r, 06521 BNO055_SYS_STAT_CODE); 06522 } else { 06523 com_rslt = BNO055_ERROR; 06524 } 06525 } 06526 return com_rslt; 06527 } 06528 /*! 06529 * @brief This API is used to read system BNO055_ERROR 06530 * code from the register 0x3A it is a byte of data 06531 * 06532 * @param sys_error_u8 : The value of system BNO055_ERROR code 06533 * 06534 * 06535 * @return results of bus communication function 06536 * @retval 0 -> BNO055_SUCCESS 06537 * @retval 1 -> BNO055_ERROR 06538 * 06539 * 06540 */ 06541 BNO055_RETURN_FUNCTION_TYPE bno055_get_sys_error_code( 06542 u8 *sys_error_u8) 06543 { 06544 /* Variable used to return value of 06545 communication routine*/ 06546 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06547 u8 data_u8r = BNO055_INIT_VALUE; 06548 s8 stat_s8 = BNO055_ERROR; 06549 /* Check the struct p_bno055 is empty */ 06550 if (p_bno055 == BNO055_INIT_VALUE) { 06551 return BNO055_E_NULL_PTR; 06552 } else { 06553 /*condition check for page, system BNO055_ERROR code is 06554 available in the page zero*/ 06555 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06556 /* Write the page zero*/ 06557 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06558 if ((stat_s8 == BNO055_SUCCESS) || 06559 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06560 /* Read the system BNO055_ERROR code*/ 06561 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06562 (p_bno055->dev_addr, 06563 BNO055_SYS_ERROR_CODE_REG, 06564 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06565 *sys_error_u8 = 06566 BNO055_GET_BITSLICE(data_u8r, 06567 BNO055_SYS_ERROR_CODE); 06568 } else { 06569 com_rslt = BNO055_ERROR; 06570 } 06571 } 06572 return com_rslt; 06573 } 06574 /*! 06575 * @brief This API used to read the accel unit 06576 * from register from 0x3B bit 0 06577 * 06578 * @param accel_unit_u8 : The value of accel unit 06579 * 06580 * accel_unit_u8 | result 06581 * ------------- | --------------- 06582 * 0x00 | BNO055_ACCEL_UNIT_MSQ 06583 * 0x01 | BNO055_ACCEL_UNIT_MG 06584 * 06585 * @return results of bus communication function 06586 * @retval 0 -> BNO055_SUCCESS 06587 * @retval 1 -> BNO055_ERROR 06588 * 06589 */ 06590 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_unit( 06591 u8 *accel_unit_u8) 06592 { 06593 /* Variable used to return value of 06594 communication routine*/ 06595 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06596 u8 data_u8r = BNO055_INIT_VALUE; 06597 s8 stat_s8 = BNO055_ERROR; 06598 /* Check the struct p_bno055 is empty */ 06599 if (p_bno055 == BNO055_INIT_VALUE) { 06600 return BNO055_E_NULL_PTR; 06601 } else { 06602 /*condition check for page, accel unit is 06603 available in the page zero*/ 06604 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06605 /* Write the page zero*/ 06606 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06607 if ((stat_s8 == BNO055_SUCCESS) || 06608 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06609 /* Read the accel unit */ 06610 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06611 (p_bno055->dev_addr, 06612 BNO055_ACCEL_UNIT_REG, 06613 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06614 *accel_unit_u8 = 06615 BNO055_GET_BITSLICE(data_u8r, BNO055_ACCEL_UNIT); 06616 } else { 06617 com_rslt = BNO055_ERROR; 06618 } 06619 } 06620 return com_rslt; 06621 } 06622 /*! 06623 * @brief This API used to write the accel unit 06624 * from register from 0x3B bit 0 06625 * 06626 * @param accel_unit_u8 : The value of accel unit 06627 * 06628 * accel_unit_u8 | result 06629 * ------------- | --------------- 06630 * 0x00 | BNO055_ACCEL_UNIT_MSQ 06631 * 0x01 | BNO055_ACCEL_UNIT_MG 06632 * 06633 * @return results of bus communication function 06634 * @retval 0 -> BNO055_SUCCESS 06635 * @retval 1 -> BNO055_ERROR 06636 * 06637 * 06638 */ 06639 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_unit( 06640 u8 accel_unit_u8) 06641 { 06642 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06643 u8 data_u8r = BNO055_INIT_VALUE; 06644 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 06645 s8 stat_s8 = BNO055_ERROR; 06646 /* Check the struct p_bno055 is empty */ 06647 if (p_bno055 == BNO055_INIT_VALUE) { 06648 return BNO055_E_NULL_PTR; 06649 } else { 06650 /* The write operation effective only if the operation 06651 mode is in config mode, this part of code is checking the 06652 current operation mode and set the config mode */ 06653 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 06654 if (stat_s8 == BNO055_SUCCESS) { 06655 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 06656 stat_s8 += bno055_set_operation_mode 06657 (BNO055_OPERATION_MODE_CONFIG); 06658 if (stat_s8 == BNO055_SUCCESS) { 06659 /* Write the accel unit */ 06660 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06661 (p_bno055->dev_addr, 06662 BNO055_ACCEL_UNIT_REG, 06663 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06664 if (com_rslt == BNO055_SUCCESS) { 06665 data_u8r = 06666 BNO055_SET_BITSLICE(data_u8r, 06667 BNO055_ACCEL_UNIT, accel_unit_u8); 06668 com_rslt += 06669 p_bno055->BNO055_BUS_WRITE_FUNC 06670 (p_bno055->dev_addr, 06671 BNO055_ACCEL_UNIT_REG, 06672 &data_u8r, 06673 BNO055_GEN_READ_WRITE_LENGTH); 06674 } 06675 } else { 06676 com_rslt = BNO055_ERROR; 06677 } 06678 } else { 06679 com_rslt = BNO055_ERROR; 06680 } 06681 } 06682 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 06683 /* set the operation mode 06684 of previous operation mode*/ 06685 com_rslt += bno055_set_operation_mode 06686 (prev_opmode_u8); 06687 return com_rslt; 06688 } 06689 /*! 06690 * @brief This API used to read the gyro unit 06691 * from register from 0x3B bit 1 06692 * 06693 * @param gyro_unit_u8 : The value of accel unit 06694 * 06695 * gyro_unit_u8 | result 06696 * ------------- | ----------- 06697 * 0x00 | BNO055_GYRO_UNIT_DPS 06698 * 0x01 | BNO055_GYRO_UNIT_RPS 06699 * 06700 * @return results of bus communication function 06701 * @retval 0 -> BNO055_SUCCESS 06702 * @retval 1 -> BNO055_ERROR 06703 * 06704 * 06705 */ 06706 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_unit( 06707 u8 *gyro_unit_u8) 06708 { 06709 /* Variable used to return value of 06710 communication routine*/ 06711 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06712 u8 data_u8r = BNO055_INIT_VALUE; 06713 s8 stat_s8 = BNO055_ERROR; 06714 /* Check the struct p_bno055 is empty */ 06715 if (p_bno055 == BNO055_INIT_VALUE) { 06716 return BNO055_E_NULL_PTR; 06717 } else { 06718 /*condition check for page, gyro unit is 06719 available in the page zero*/ 06720 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06721 /* Write the page zero*/ 06722 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06723 if ((stat_s8 == BNO055_SUCCESS) || 06724 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06725 /* Read the gyro unit */ 06726 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06727 (p_bno055->dev_addr, 06728 BNO055_GYRO_UNIT_REG, 06729 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06730 *gyro_unit_u8 = 06731 BNO055_GET_BITSLICE(data_u8r, BNO055_GYRO_UNIT); 06732 } else { 06733 com_rslt = BNO055_ERROR; 06734 } 06735 } 06736 return com_rslt; 06737 } 06738 /*! 06739 * @brief This API used to write the gyro unit 06740 * from register from 0x3B bit 1 06741 * 06742 * @param gyro_unit_u8 : The value of accel unit 06743 * 06744 * gyro_unit_u8 | result 06745 * ------------- | ----------- 06746 * 0x00 | BNO055_GYRO_UNIT_DPS 06747 * 0x01 | BNO055_GYRO_UNIT_RPS 06748 * 06749 * @return results of bus communication function 06750 * @retval 0 -> BNO055_SUCCESS 06751 * @retval 1 -> BNO055_ERROR 06752 * 06753 * 06754 */ 06755 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_unit(u8 gyro_unit_u8) 06756 { 06757 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06758 u8 data_u8r = BNO055_INIT_VALUE; 06759 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 06760 s8 stat_s8 = BNO055_ERROR; 06761 /* Check the struct p_bno055 is empty */ 06762 if (p_bno055 == BNO055_INIT_VALUE) { 06763 return BNO055_E_NULL_PTR; 06764 } else { 06765 /* The write operation effective only if the operation 06766 mode is in config mode, this part of code is checking the 06767 current operation mode and set the config mode */ 06768 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 06769 if (stat_s8 == BNO055_SUCCESS) { 06770 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 06771 stat_s8 += bno055_set_operation_mode 06772 (BNO055_OPERATION_MODE_CONFIG); 06773 if (stat_s8 == BNO055_SUCCESS) { 06774 /* Write the gyro unit */ 06775 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06776 (p_bno055->dev_addr, 06777 BNO055_GYRO_UNIT_REG, 06778 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06779 if (com_rslt == BNO055_SUCCESS) { 06780 data_u8r = 06781 BNO055_SET_BITSLICE(data_u8r, 06782 BNO055_GYRO_UNIT, gyro_unit_u8); 06783 com_rslt += 06784 p_bno055->BNO055_BUS_WRITE_FUNC 06785 (p_bno055->dev_addr, 06786 BNO055_GYRO_UNIT_REG, 06787 &data_u8r, 06788 BNO055_GEN_READ_WRITE_LENGTH); 06789 } 06790 } else { 06791 com_rslt = BNO055_ERROR; 06792 } 06793 } else { 06794 com_rslt = BNO055_ERROR; 06795 } 06796 } 06797 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 06798 /* set the operation mode 06799 of previous operation mode*/ 06800 com_rslt += bno055_set_operation_mode 06801 (prev_opmode_u8); 06802 return com_rslt; 06803 } 06804 /*! 06805 * @brief This API used to read the Euler unit 06806 * from register from 0x3B bit 2 06807 * 06808 * @param euler_unit_u8 : The value of accel unit 06809 * 06810 * euler_unit_u8 | result 06811 * -------------- | ----------- 06812 * 0x00 | BNO055_EULER_UNIT_DEG 06813 * 0x01 | BNO055_EULER_UNIT_RAD 06814 * 06815 * @return results of bus communication function 06816 * @retval 0 -> BNO055_SUCCESS 06817 * @retval 1 -> BNO055_ERROR 06818 * 06819 * 06820 */ 06821 BNO055_RETURN_FUNCTION_TYPE bno055_get_euler_unit( 06822 u8 *euler_unit_u8) 06823 { 06824 /* Variable used to return value of 06825 communication routine*/ 06826 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06827 u8 data_u8r = BNO055_INIT_VALUE; 06828 s8 stat_s8 = BNO055_ERROR; 06829 /* Check the struct p_bno055 is empty */ 06830 if (p_bno055 == BNO055_INIT_VALUE) { 06831 return BNO055_E_NULL_PTR; 06832 } else { 06833 /*condition check for page, Euler unit is 06834 available in the page zero*/ 06835 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06836 /* Write the page zero*/ 06837 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06838 if ((stat_s8 == BNO055_SUCCESS) || 06839 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06840 /* Read the Euler unit */ 06841 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06842 (p_bno055->dev_addr, 06843 BNO055_EULER_UNIT_REG, 06844 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06845 *euler_unit_u8 = 06846 BNO055_GET_BITSLICE(data_u8r, 06847 BNO055_EULER_UNIT); 06848 } else { 06849 com_rslt = BNO055_ERROR; 06850 } 06851 } 06852 return com_rslt; 06853 } 06854 /*! 06855 * @brief This API used to write the Euler unit 06856 * from register from 0x3B bit 2 06857 * 06858 * @param euler_unit_u8 : The value of Euler unit 06859 * 06860 * euler_unit_u8 | result 06861 * -------------- | ----------- 06862 * 0x00 | BNO055_EULER_UNIT_DEG 06863 * 0x01 | BNO055_EULER_UNIT_RAD 06864 * 06865 * @return results of bus communication function 06866 * @retval 0 -> BNO055_SUCCESS 06867 * @retval 1 -> BNO055_ERROR 06868 * 06869 * 06870 */ 06871 BNO055_RETURN_FUNCTION_TYPE bno055_set_euler_unit(u8 euler_unit_u8) 06872 { 06873 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06874 u8 data_u8r = BNO055_INIT_VALUE; 06875 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 06876 s8 stat_s8 = BNO055_ERROR; 06877 /* Check the struct p_bno055 is empty */ 06878 if (p_bno055 == BNO055_INIT_VALUE) { 06879 return BNO055_E_NULL_PTR; 06880 } else { 06881 /* The write operation effective only if the operation 06882 mode is in config mode, this part of code is checking the 06883 current operation mode and set the config mode */ 06884 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 06885 if (stat_s8 == BNO055_SUCCESS) { 06886 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 06887 stat_s8 += bno055_set_operation_mode 06888 (BNO055_OPERATION_MODE_CONFIG); 06889 if (stat_s8 == BNO055_SUCCESS) { 06890 /* Write the Euler unit*/ 06891 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06892 (p_bno055->dev_addr, 06893 BNO055_EULER_UNIT_REG, 06894 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06895 if (com_rslt == BNO055_SUCCESS) { 06896 data_u8r = 06897 BNO055_SET_BITSLICE(data_u8r, 06898 BNO055_EULER_UNIT, euler_unit_u8); 06899 com_rslt += 06900 p_bno055->BNO055_BUS_WRITE_FUNC 06901 (p_bno055->dev_addr, 06902 BNO055_EULER_UNIT_REG, 06903 &data_u8r, 06904 BNO055_GEN_READ_WRITE_LENGTH); 06905 } 06906 } else { 06907 com_rslt = BNO055_ERROR; 06908 } 06909 } else { 06910 com_rslt = BNO055_ERROR; 06911 } 06912 } 06913 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 06914 /* set the operation mode 06915 of previous operation mode*/ 06916 com_rslt += bno055_set_operation_mode 06917 (prev_opmode_u8); 06918 return com_rslt; 06919 } 06920 /*! 06921 * @brief This API used to write the tilt unit 06922 * from register from 0x3B bit 3 06923 * 06924 * @param tilt_unit_u8 : The value of tilt unit 06925 * 06926 * tilt_unit_u8 | result 06927 * --------------- | --------- 06928 * 0x00 | degrees 06929 * 0x01 | radians 06930 * 06931 * @return results of bus communication function 06932 * @retval 0 -> BNO055_SUCCESS 06933 * @retval 1 -> BNO055_ERROR 06934 * 06935 * 06936 */ 06937 BNO055_RETURN_FUNCTION_TYPE bno055_get_tilt_unit( 06938 u8 *tilt_unit_u8) 06939 { 06940 /* Variable used to return value of 06941 communication routine*/ 06942 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06943 u8 data_u8r = BNO055_INIT_VALUE; 06944 s8 stat_s8 = BNO055_ERROR; 06945 /* Check the struct p_bno055 is empty */ 06946 if (p_bno055 == BNO055_INIT_VALUE) { 06947 return BNO055_E_NULL_PTR; 06948 } else { 06949 /*condition check for page, chip id is 06950 available in the page zero*/ 06951 if (p_bno055->page_id != BNO055_PAGE_ZERO) 06952 /* Write the page zero*/ 06953 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 06954 if ((stat_s8 == BNO055_SUCCESS) || 06955 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 06956 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 06957 (p_bno055->dev_addr, 06958 BNO055_TILT_UNIT_REG, 06959 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 06960 *tilt_unit_u8 = 06961 BNO055_GET_BITSLICE(data_u8r, BNO055_TILT_UNIT); 06962 } else { 06963 com_rslt = BNO055_ERROR; 06964 } 06965 } 06966 return com_rslt; 06967 } 06968 /*! 06969 * @brief This API used to write the tilt unit 06970 * from register from 0x3B bit 3 06971 * 06972 * @param tilt_unit_u8 : The value of tilt unit 06973 * 06974 * tilt_unit_u8 | result 06975 * --------------- | --------- 06976 * 0x00 | degrees 06977 * 0x01 | radians 06978 * 06979 * @return results of bus communication function 06980 * @retval 0 -> BNO055_SUCCESS 06981 * @retval 1 -> BNO055_ERROR 06982 * 06983 * 06984 * 06985 * \return Communication results 06986 * 06987 * 06988 */ 06989 BNO055_RETURN_FUNCTION_TYPE bno055_set_tilt_unit(u8 tilt_unit_u8) 06990 { 06991 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 06992 u8 data_u8r = BNO055_INIT_VALUE; 06993 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 06994 s8 stat_s8 = BNO055_ERROR; 06995 /* Check the struct p_bno055 is empty */ 06996 if (p_bno055 == BNO055_INIT_VALUE) { 06997 return BNO055_E_NULL_PTR; 06998 } else { 06999 /* The write operation effective only if the operation 07000 mode is in config mode, this part of code is checking the 07001 current operation mode and set the config mode */ 07002 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 07003 if (stat_s8 == BNO055_SUCCESS) { 07004 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07005 stat_s8 += bno055_set_operation_mode 07006 (BNO055_OPERATION_MODE_CONFIG); 07007 if (stat_s8 == BNO055_SUCCESS) { 07008 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07009 (p_bno055->dev_addr, 07010 BNO055_TILT_UNIT_REG, 07011 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07012 if (com_rslt == BNO055_SUCCESS) { 07013 data_u8r = 07014 BNO055_SET_BITSLICE(data_u8r, 07015 BNO055_TILT_UNIT, tilt_unit_u8); 07016 com_rslt += 07017 p_bno055->BNO055_BUS_WRITE_FUNC 07018 (p_bno055->dev_addr, 07019 BNO055_TILT_UNIT_REG, 07020 &data_u8r, 07021 BNO055_GEN_READ_WRITE_LENGTH); 07022 } 07023 } else { 07024 com_rslt = BNO055_ERROR; 07025 } 07026 } else { 07027 com_rslt = BNO055_ERROR; 07028 } 07029 } 07030 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07031 /* set the operation mode 07032 of previous operation mode*/ 07033 com_rslt += bno055_set_operation_mode 07034 (prev_opmode_u8); 07035 return com_rslt; 07036 } 07037 /*! 07038 * @brief This API used to read the temperature unit 07039 * from register from 0x3B bit 4 07040 * 07041 * @param temp_unit_u8 : The value of temperature unit 07042 * 07043 * temp_unit_u8 | result 07044 * ----------- | -------------- 07045 * 0x00 | BNO055_TEMP_UNIT_CELSIUS 07046 * 0x01 | BNO055_TEMP_UNIT_FAHRENHEIT 07047 * 07048 * @return results of bus communication function 07049 * @retval 0 -> BNO055_SUCCESS 07050 * @retval 1 -> BNO055_ERROR 07051 * 07052 */ 07053 BNO055_RETURN_FUNCTION_TYPE bno055_get_temp_unit( 07054 u8 *temp_unit_u8) 07055 { 07056 /* Variable used to return value of 07057 communication routine*/ 07058 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07059 u8 data_u8r = BNO055_INIT_VALUE; 07060 s8 stat_s8 = BNO055_ERROR; 07061 /* Check the struct p_bno055 is empty */ 07062 if (p_bno055 == BNO055_INIT_VALUE) { 07063 return BNO055_E_NULL_PTR; 07064 } else { 07065 /*condition check for page, temperature unit is 07066 available in the page zero*/ 07067 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07068 /* Write the page zero*/ 07069 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07070 if ((stat_s8 == BNO055_SUCCESS) || 07071 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07072 /* Read the temperature unit */ 07073 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07074 (p_bno055->dev_addr, 07075 BNO055_TEMP_UNIT_REG, 07076 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07077 *temp_unit_u8 = 07078 BNO055_GET_BITSLICE(data_u8r, 07079 BNO055_TEMP_UNIT); 07080 } else { 07081 com_rslt = BNO055_ERROR; 07082 } 07083 } 07084 return com_rslt; 07085 } 07086 /*! 07087 * @brief This API used to write the temperature unit 07088 * from register from 0x3B bit 4 07089 * 07090 * @param temp_unit_u8 : The value of temperature unit 07091 * 07092 * temp_unit_u8 | result 07093 * ----------- | -------------- 07094 * 0x00 | BNO055_TEMP_UNIT_CELSIUS 07095 * 0x01 | BNO055_TEMP_UNIT_FAHRENHEIT 07096 * 07097 * @return results of bus communication function 07098 * @retval 0 -> BNO055_SUCCESS 07099 * @retval 1 -> BNO055_ERROR 07100 * 07101 * 07102 */ 07103 BNO055_RETURN_FUNCTION_TYPE bno055_set_temp_unit( 07104 u8 temp_unit_u8) 07105 { 07106 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07107 u8 data_u8r = BNO055_INIT_VALUE; 07108 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 07109 s8 stat_s8 = BNO055_ERROR; 07110 /* Check the struct p_bno055 is empty */ 07111 if (p_bno055 == BNO055_INIT_VALUE) { 07112 return BNO055_E_NULL_PTR; 07113 } else { 07114 /* The write operation effective only if the operation 07115 mode is in config mode, this part of code is checking the 07116 current operation mode and set the config mode */ 07117 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 07118 if (stat_s8 == BNO055_SUCCESS) { 07119 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07120 stat_s8 += bno055_set_operation_mode 07121 (BNO055_OPERATION_MODE_CONFIG); 07122 if (stat_s8 == BNO055_SUCCESS) { 07123 /* Write the temperature unit */ 07124 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07125 (p_bno055->dev_addr, 07126 BNO055_TEMP_UNIT_REG, 07127 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07128 if (com_rslt == BNO055_SUCCESS) { 07129 data_u8r = 07130 BNO055_SET_BITSLICE(data_u8r, 07131 BNO055_TEMP_UNIT, 07132 temp_unit_u8); 07133 com_rslt += 07134 p_bno055->BNO055_BUS_WRITE_FUNC 07135 (p_bno055->dev_addr, 07136 BNO055_TEMP_UNIT_REG, 07137 &data_u8r, 07138 BNO055_GEN_READ_WRITE_LENGTH); 07139 } 07140 } else { 07141 com_rslt = BNO055_ERROR; 07142 } 07143 } else { 07144 com_rslt = BNO055_ERROR; 07145 } 07146 } 07147 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07148 /* set the operation mode 07149 of previous operation mode*/ 07150 com_rslt += bno055_set_operation_mode 07151 (prev_opmode_u8); 07152 return com_rslt; 07153 } 07154 /*! 07155 * @brief This API used to read the current selected orientation mode 07156 * from register from 0x3B bit 7 07157 * 07158 * @param data_output_format_u8 : The value of data output format 07159 * 07160 * data_output_format_u8 | result 07161 * -------------------- | -------- 07162 * 0x00 | Windows 07163 * 0x01 | Android 07164 * 07165 * @return results of bus communication function 07166 * @retval 0 -> BNO055_SUCCESS 07167 * @retval 1 -> BNO055_ERROR 07168 * 07169 */ 07170 BNO055_RETURN_FUNCTION_TYPE bno055_get_data_output_format( 07171 u8 *data_output_format_u8) 07172 { 07173 /* Variable used to return value of 07174 communication routine*/ 07175 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07176 u8 data_u8r = BNO055_INIT_VALUE; 07177 s8 stat_s8 = BNO055_ERROR; 07178 /* Check the struct p_bno055 is empty */ 07179 if (p_bno055 == BNO055_INIT_VALUE) { 07180 return BNO055_E_NULL_PTR; 07181 } else { 07182 /*condition check for page, data output format is 07183 available in the page zero*/ 07184 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07185 /* Write the page zero*/ 07186 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07187 if ((stat_s8 == BNO055_SUCCESS) || 07188 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07189 /* Read the data output format */ 07190 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07191 (p_bno055->dev_addr, 07192 BNO055_DATA_OUTPUT_FORMAT_REG, 07193 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07194 *data_output_format_u8 = 07195 BNO055_GET_BITSLICE(data_u8r, 07196 BNO055_DATA_OUTPUT_FORMAT); 07197 } else { 07198 com_rslt = BNO055_ERROR; 07199 } 07200 } 07201 return com_rslt; 07202 } 07203 /*! 07204 * @brief This API used to write the current selected orientation mode 07205 * from register from 0x3B bit 7 07206 * 07207 * @param data_output_format_u8 : The value of data output format 07208 * 07209 * data_output_format_u8 | result 07210 * -------------------- | -------- 07211 * 0x00 | Windows 07212 * 0x01 | Android 07213 * 07214 * @return results of bus communication function 07215 * @retval 0 -> BNO055_SUCCESS 07216 * @retval 1 -> BNO055_ERROR 07217 * 07218 * 07219 */ 07220 BNO055_RETURN_FUNCTION_TYPE bno055_set_data_output_format( 07221 u8 data_output_format_u8) 07222 { 07223 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07224 u8 data_u8r = BNO055_INIT_VALUE; 07225 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 07226 s8 stat_s8 = BNO055_ERROR; 07227 /* Check the struct p_bno055 is empty */ 07228 if (p_bno055 == BNO055_INIT_VALUE) { 07229 return BNO055_E_NULL_PTR; 07230 } else { 07231 /* The write operation effective only if the operation 07232 mode is in config mode, this part of code is checking the 07233 current operation mode and set the config mode */ 07234 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 07235 if (stat_s8 == BNO055_SUCCESS) { 07236 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07237 stat_s8 += bno055_set_operation_mode 07238 (BNO055_OPERATION_MODE_CONFIG); 07239 if (stat_s8 == BNO055_SUCCESS) { 07240 /* Write the data output format */ 07241 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07242 (p_bno055->dev_addr, 07243 BNO055_DATA_OUTPUT_FORMAT_REG, 07244 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07245 if (com_rslt == BNO055_SUCCESS) { 07246 data_u8r = 07247 BNO055_SET_BITSLICE(data_u8r, 07248 BNO055_DATA_OUTPUT_FORMAT, 07249 data_output_format_u8); 07250 com_rslt += 07251 p_bno055->BNO055_BUS_WRITE_FUNC 07252 (p_bno055->dev_addr, 07253 BNO055_DATA_OUTPUT_FORMAT_REG, 07254 &data_u8r, 07255 BNO055_GEN_READ_WRITE_LENGTH); 07256 } 07257 } else { 07258 com_rslt = BNO055_ERROR; 07259 } 07260 } else { 07261 com_rslt = BNO055_ERROR; 07262 } 07263 } 07264 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07265 /* set the operation mode 07266 of previous operation mode*/ 07267 com_rslt += bno055_set_operation_mode 07268 (prev_opmode_u8); 07269 return com_rslt; 07270 } 07271 /*! @brief This API used to read the operation mode 07272 * from register from 0x3D bit 0 to 3 07273 * 07274 * @param operation_mode_u8 : The value of operation mode 07275 * 07276 * operation_mode_u8 | result | comments 07277 * ----------|----------------------------|---------------------------- 07278 * 0x00 | BNO055_OPERATION_MODE_CONFIG | Configuration mode 07279 * 0x01 | BNO055_OPERATION_MODE_ACCONLY | Reads accel data alone 07280 * 0x02 | BNO055_OPERATION_MODE_MAGONLY | Reads mag data alone 07281 * 0x03 | BNO055_OPERATION_MODE_GYRONLY | Reads gyro data alone 07282 * 0x04 | BNO055_OPERATION_MODE_ACCMAG | Reads accel and mag data 07283 * 0x05 | BNO055_OPERATION_MODE_ACCGYRO | Reads accel and gyro data 07284 * 0x06 | BNO055_OPERATION_MODE_MAGGYRO | Reads accel and mag data 07285 * 0x07 | OPERATION_MODE_ANY_MOTION | Reads accel mag and gyro data 07286 * 0x08 | BNO055_OPERATION_MODE_IMUPLUS | Inertial measurement unit 07287 * - | - | Reads accel,gyro and fusion data 07288 * 0x09 | BNO055_OPERATION_MODE_COMPASS | Reads accel, mag data 07289 * - | - | and fusion data 07290 * 0x0A | BNO055_OPERATION_MODE_M4G | Reads accel, mag data 07291 * - | - | and fusion data 07292 * 0x0B | BNO055_OPERATION_MODE_NDOF_FMC_OFF| Nine degrees of freedom with 07293 * - | - | fast magnetic calibration 07294 * - | - | Reads accel,mag, gyro 07295 * - | - | and fusion data 07296 * 0x0C | BNO055_OPERATION_MODE_NDOF | Nine degrees of freedom 07297 * - | - | Reads accel,mag, gyro 07298 * - | - | and fusion data 07299 * 07300 * @return results of bus communication function 07301 * @retval 0 -> BNO055_SUCCESS 07302 * @retval 1 -> BNO055_ERROR 07303 * 07304 * @note In the config mode, all sensor and fusion data 07305 * becomes zero and it is mainly derived 07306 * to configure the various settings of the BNO 07307 * 07308 */ 07309 BNO055_RETURN_FUNCTION_TYPE bno055_get_operation_mode( 07310 u8 *operation_mode_u8) 07311 { 07312 /* Variable used to return value of 07313 communication routine*/ 07314 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07315 u8 data_u8r = BNO055_INIT_VALUE; 07316 s8 stat_s8 = BNO055_ERROR; 07317 /* Check the struct p_bno055 is empty */ 07318 if (p_bno055 == BNO055_INIT_VALUE) { 07319 return BNO055_E_NULL_PTR; 07320 } else { 07321 /*condition check for page, operation mode is 07322 available in the page zero*/ 07323 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07324 /* Write the page zero*/ 07325 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07326 if ((stat_s8 == BNO055_SUCCESS) || 07327 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07328 /* Read the value of operation mode*/ 07329 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07330 (p_bno055->dev_addr, 07331 BNO055_OPERATION_MODE_REG, 07332 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07333 *operation_mode_u8 = 07334 BNO055_GET_BITSLICE(data_u8r, 07335 BNO055_OPERATION_MODE); 07336 } else { 07337 com_rslt = BNO055_ERROR; 07338 } 07339 } 07340 return com_rslt; 07341 } 07342 /*! @brief This API used to write the operation mode 07343 * from register from 0x3D bit 0 to 3 07344 * 07345 * @param operation_mode_u8 : The value of operation mode 07346 * 07347 * operation_mode_u8 | result | comments 07348 * ---------|-----------------------------------|-------------------------- 07349 * 0x00 | BNO055_OPERATION_MODE_CONFIG | Configuration mode 07350 * 0x01 | BNO055_OPERATION_MODE_ACCONLY | Reads accel data alone 07351 * 0x02 | BNO055_OPERATION_MODE_MAGONLY | Reads mag data alone 07352 * 0x03 | BNO055_OPERATION_MODE_GYRONLY | Reads gyro data alone 07353 * 0x04 | BNO055_OPERATION_MODE_ACCMAG | Reads accel and mag data 07354 * 0x05 | BNO055_OPERATION_MODE_ACCGYRO | Reads accel and gyro data 07355 * 0x06 | BNO055_OPERATION_MODE_MAGGYRO | Reads accel and mag data 07356 * 0x07 | OPERATION_MODE_ANY_MOTION | Reads accel mag and 07357 * | - | gyro data 07358 * 0x08 | BNO055_OPERATION_MODE_IMUPLUS | Inertial measurement unit 07359 * - | | Reads accel,gyro and 07360 * | - | fusion data 07361 * 0x09 | BNO055_OPERATION_MODE_COMPASS | Reads accel, mag data 07362 * - | - | and fusion data 07363 * 0x0A | BNO055_OPERATION_MODE_M4G | Reads accel, mag data 07364 * - | - | and fusion data 07365 * 0x0B | BNO055_OPERATION_MODE_NDOF_FMC_OFF| Nine degrees of freedom with 07366 * - | - | fast magnetic calibration 07367 * - | - | Reads accel,mag, gyro 07368 * - | - | and fusion data 07369 * 0x0C | BNO055_OPERATION_MODE_NDOF | Nine degrees of freedom 07370 * - | - | Reads accel,mag, gyro 07371 * - | - | and fusion data 07372 * 07373 * @return results of bus communication function 07374 * @retval 0 -> BNO055_SUCCESS 07375 * @retval 1 -> BNO055_ERROR 07376 * 07377 * @note In the config mode, all sensor and fusion data 07378 * becomes zero and it is mainly derived 07379 * to configure the various settings of the BNO 07380 * 07381 */ 07382 BNO055_RETURN_FUNCTION_TYPE bno055_set_operation_mode(u8 operation_mode_u8) 07383 { 07384 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07385 u8 data_u8r = BNO055_INIT_VALUE; 07386 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 07387 s8 stat_s8 = BNO055_ERROR; 07388 /* Check the struct p_bno055 is empty */ 07389 if (p_bno055 == BNO055_INIT_VALUE) { 07390 return BNO055_E_NULL_PTR; 07391 } else { 07392 /* The write operation effective only if the operation 07393 mode is in config mode, this part of code is checking the 07394 current operation mode and set the config mode */ 07395 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 07396 if (stat_s8 == BNO055_SUCCESS) { 07397 /* If the previous operation mode is config it is 07398 directly write the operation mode */ 07399 if (prev_opmode_u8 == BNO055_OPERATION_MODE_CONFIG) { 07400 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07401 (p_bno055->dev_addr, 07402 BNO055_OPERATION_MODE_REG, 07403 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07404 if (com_rslt == BNO055_SUCCESS) { 07405 data_u8r = 07406 BNO055_SET_BITSLICE(data_u8r, 07407 BNO055_OPERATION_MODE, 07408 operation_mode_u8); 07409 com_rslt += 07410 p_bno055->BNO055_BUS_WRITE_FUNC 07411 (p_bno055->dev_addr, 07412 BNO055_OPERATION_MODE_REG, 07413 &data_u8r, 07414 BNO055_GEN_READ_WRITE_LENGTH); 07415 /* Config mode to other 07416 operation mode switching 07417 required delay of 600ms*/ 07418 p_bno055->delay_msec( 07419 BNO055_MODE_SWITCHING_DELAY); 07420 } 07421 } else { 07422 /* If the previous operation 07423 mode is not config it is 07424 write the config mode */ 07425 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07426 (p_bno055->dev_addr, 07427 BNO055_OPERATION_MODE_REG, 07428 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07429 if (com_rslt == BNO055_SUCCESS) { 07430 data_u8r = 07431 BNO055_SET_BITSLICE(data_u8r, 07432 BNO055_OPERATION_MODE, 07433 BNO055_OPERATION_MODE_CONFIG); 07434 com_rslt += bno055_write_register( 07435 BNO055_OPERATION_MODE_REG, 07436 &data_u8r, 07437 BNO055_GEN_READ_WRITE_LENGTH); 07438 /* other mode to config mode switching 07439 required delay of 20ms*/ 07440 p_bno055->delay_msec( 07441 BNO055_CONFIG_MODE_SWITCHING_DELAY); 07442 } 07443 /* Write the operation mode */ 07444 if (operation_mode_u8 != 07445 BNO055_OPERATION_MODE_CONFIG) { 07446 com_rslt = 07447 p_bno055->BNO055_BUS_READ_FUNC 07448 (p_bno055->dev_addr, 07449 BNO055_OPERATION_MODE_REG, 07450 &data_u8r, 07451 BNO055_GEN_READ_WRITE_LENGTH); 07452 if (com_rslt == BNO055_SUCCESS) { 07453 data_u8r = BNO055_SET_BITSLICE 07454 (data_u8r, 07455 BNO055_OPERATION_MODE, 07456 operation_mode_u8); 07457 com_rslt += 07458 p_bno055->BNO055_BUS_WRITE_FUNC 07459 (p_bno055->dev_addr, 07460 BNO055_OPERATION_MODE_REG, 07461 &data_u8r, 07462 BNO055_GEN_READ_WRITE_LENGTH); 07463 /* Config mode to other 07464 operation mode switching 07465 required delay of 600ms*/ 07466 p_bno055->delay_msec( 07467 BNO055_MODE_SWITCHING_DELAY); 07468 } 07469 } 07470 } 07471 } else { 07472 com_rslt = BNO055_ERROR; 07473 } 07474 } 07475 return com_rslt; 07476 } 07477 /*! @brief This API used to read the power mode 07478 * from register from 0x3E bit 0 to 1 07479 * 07480 * @param power_mode_u8 : The value of power mode 07481 * 07482 * power_mode_u8| result | comments 07483 * ---------|---------------------------|------------------------------------- 07484 * 0x00 |BNO055_POWER_MODE_NORMAL | In the NORMAL mode the register 07485 * - | - | map and the internal peripherals 07486 * - | - | of the MCU are always 07487 * - | - | operative in this mode 07488 * 0x01 |BNO055_POWER_MODE_LOWPOWER | This is first level of power 07489 * | - | saving mode 07490 * 0x02 |BNO055_POWER_MODE_SUSPEND | In suspend mode the system is 07491 * - | - | paused and all the sensors and 07492 * - | - | the micro controller are 07493 * - | - | put into sleep mode. 07494 * 07495 * @return results of bus communication function 07496 * @retval 0 -> BNO055_SUCCESS 07497 * @retval 1 -> BNO055_ERROR 07498 * 07499 * @note For detailed about LOWPOWER mode 07500 * refer data sheet 3.4.2 07501 * 07502 */ 07503 BNO055_RETURN_FUNCTION_TYPE bno055_get_power_mode( 07504 u8 *power_mode_u8) 07505 { 07506 /* Variable used to return value of 07507 communication routine*/ 07508 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07509 u8 data_u8r = BNO055_INIT_VALUE; 07510 s8 stat_s8 = BNO055_ERROR; 07511 /* Check the struct p_bno055 is empty */ 07512 if (p_bno055 == BNO055_INIT_VALUE) { 07513 return BNO055_E_NULL_PTR; 07514 } else { 07515 /*condition check for page, power mode is 07516 available in the page zero*/ 07517 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07518 /* Write the page zero*/ 07519 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07520 if ((stat_s8 == BNO055_SUCCESS) || 07521 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07522 /* Read the value of power mode */ 07523 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07524 (p_bno055->dev_addr, 07525 BNO055_POWER_MODE_REG, 07526 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07527 *power_mode_u8 = 07528 BNO055_GET_BITSLICE(data_u8r, 07529 BNO055_POWER_MODE); 07530 } else { 07531 com_rslt = BNO055_ERROR; 07532 } 07533 } 07534 return com_rslt; 07535 } 07536 /*! @brief This API used to write the power mode 07537 * from register from 0x3E bit 0 to 1 07538 * 07539 * @param power_mode_u8 : The value of power mode 07540 * 07541 * 07542 * power_mode_u8| result | comments 07543 * -------|----------------------------|--------------------------------- 07544 * 0x00 | BNO055_POWER_MODE_NORMAL | In the NORMAL mode the register 07545 * - | - | map and the internal peripherals 07546 * - | - | of the MCU are always 07547 * - | - | operative in this mode 07548 * 0x01 | BNO055_POWER_MODE_LOWPOWER | This is first level of power 07549 * | - | saving mode 07550 * 0x02 | BNO055_POWER_MODE_SUSPEND | In suspend mode the system is 07551 * - | - | paused and all the sensors and 07552 * - | - | the micro controller are 07553 * - | - | put into sleep mode. 07554 * 07555 * @return results of bus communication function 07556 * @retval 0 -> BNO055_SUCCESS 07557 * @retval 1 -> BNO055_ERROR 07558 * 07559 * @note For detailed about LOWPOWER mode 07560 * refer data sheet 3.4.2 07561 * 07562 */ 07563 BNO055_RETURN_FUNCTION_TYPE bno055_set_power_mode(u8 power_mode_u8) 07564 { 07565 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07566 u8 data_u8r = BNO055_INIT_VALUE; 07567 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 07568 s8 stat_s8 = BNO055_ERROR; 07569 /* Check the struct p_bno055 is empty */ 07570 if (p_bno055 == BNO055_INIT_VALUE) { 07571 return BNO055_E_NULL_PTR; 07572 } else { 07573 /* The write operation effective only if the operation 07574 mode is in config mode, this part of code is checking the 07575 current operation mode and set the config mode */ 07576 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 07577 if (stat_s8 == BNO055_SUCCESS) { 07578 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07579 stat_s8 += bno055_set_operation_mode 07580 (BNO055_OPERATION_MODE_CONFIG); 07581 if (stat_s8 == BNO055_SUCCESS) { 07582 /* Write the value of power mode */ 07583 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07584 (p_bno055->dev_addr, 07585 BNO055_POWER_MODE_REG, 07586 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07587 if (com_rslt == BNO055_SUCCESS) { 07588 data_u8r = 07589 BNO055_SET_BITSLICE(data_u8r, 07590 BNO055_POWER_MODE, power_mode_u8); 07591 com_rslt += 07592 p_bno055->BNO055_BUS_WRITE_FUNC 07593 (p_bno055->dev_addr, 07594 BNO055_POWER_MODE_REG, 07595 &data_u8r, 07596 BNO055_GEN_READ_WRITE_LENGTH); 07597 } 07598 } else { 07599 com_rslt = BNO055_ERROR; 07600 } 07601 } else { 07602 com_rslt = BNO055_ERROR; 07603 } 07604 } 07605 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 07606 /* set the operation mode 07607 of previous operation mode*/ 07608 com_rslt += bno055_set_operation_mode 07609 (prev_opmode_u8); 07610 return com_rslt; 07611 } 07612 /*! 07613 * @brief This API used to read the reset interrupt 07614 * from register from 0x3F bit 6 07615 * It resets all the interrupt bit and interrupt output 07616 * 07617 * @param intr_rst_u8 : The value of reset interrupt 07618 * 07619 * intr_rst_u8 | result 07620 * ------------ |---------- 07621 * 0x01 | BNO055_BIT_ENABLE 07622 * 0x00 | BNO055_BIT_DISABLE 07623 * 07624 * @return results of bus communication function 07625 * @retval 0 -> BNO055_SUCCESS 07626 * @retval 1 -> BNO055_ERROR 07627 * 07628 */ 07629 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_rst( 07630 u8 *intr_rst_u8) 07631 { 07632 /* Variable used to return value of 07633 communication routine*/ 07634 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07635 u8 data_u8r = BNO055_INIT_VALUE; 07636 s8 stat_s8 = BNO055_ERROR; 07637 /* Check the struct p_bno055 is empty */ 07638 if (p_bno055 == BNO055_INIT_VALUE) { 07639 return BNO055_E_NULL_PTR; 07640 } else { 07641 /*condition check for page, reset interrupt is 07642 available in the page zero*/ 07643 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07644 /* Write the page zero*/ 07645 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07646 if ((stat_s8 == BNO055_SUCCESS) || 07647 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07648 /* Read the value of reset interrupt*/ 07649 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07650 (p_bno055->dev_addr, 07651 BNO055_INTR_RST_REG, 07652 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07653 *intr_rst_u8 = 07654 BNO055_GET_BITSLICE(data_u8r, BNO055_INTR_RST); 07655 } else { 07656 com_rslt = BNO055_ERROR; 07657 } 07658 } 07659 return com_rslt; 07660 } 07661 /*! 07662 * @brief This API used to write the reset interrupt 07663 * from register from 0x3F bit 6 07664 * It resets all the interrupt bit and interrupt output 07665 * 07666 * @param intr_rst_u8 : The value of reset interrupt 07667 * 07668 * intr_rst_u8 | result 07669 * -------------- |---------- 07670 * 0x01 | BNO055_BIT_ENABLE 07671 * 0x00 | BNO055_BIT_DISABLE 07672 * 07673 * @return results of bus communication function 07674 * @retval 0 -> BNO055_SUCCESS 07675 * @retval 1 -> BNO055_ERROR 07676 * 07677 */ 07678 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_rst(u8 intr_rst_u8) 07679 { 07680 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07681 u8 data_u8r = BNO055_INIT_VALUE; 07682 s8 stat_s8 = BNO055_ERROR; 07683 /* Check the struct p_bno055 is empty */ 07684 if (p_bno055 == BNO055_INIT_VALUE) { 07685 return BNO055_E_NULL_PTR; 07686 } else { 07687 /*condition check for page, reset interrupt 07688 available in the page zero*/ 07689 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07690 /* Write the page zero*/ 07691 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07692 if ((stat_s8 == BNO055_SUCCESS) || 07693 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07694 /* Write the value of reset interrupt */ 07695 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07696 (p_bno055->dev_addr, 07697 BNO055_INTR_RST_REG, 07698 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07699 if (com_rslt == BNO055_SUCCESS) { 07700 data_u8r = 07701 BNO055_SET_BITSLICE(data_u8r, 07702 BNO055_INTR_RST, intr_rst_u8); 07703 com_rslt += 07704 p_bno055->BNO055_BUS_WRITE_FUNC 07705 (p_bno055->dev_addr, 07706 BNO055_INTR_RST_REG, 07707 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07708 } 07709 } else { 07710 com_rslt = BNO055_ERROR; 07711 } 07712 } 07713 return com_rslt; 07714 } 07715 /*! 07716 * @brief This API used to read the clk source 07717 * from register from 0x3F bit 7 07718 * 07719 * @param clk_src_u8 : The value of clk source 07720 * 07721 * clk_src_u8 | result 07722 * -------------- |---------- 07723 * 0x01 | BNO055_BIT_ENABLE 07724 * 0x00 | BNO055_BIT_DISABLE 07725 * 07726 * @return results of bus communication function 07727 * @retval 0 -> BNO055_SUCCESS 07728 * @retval 1 -> BNO055_ERROR 07729 * 07730 */ 07731 BNO055_RETURN_FUNCTION_TYPE bno055_get_clk_src( 07732 u8 *clk_src_u8) 07733 { 07734 /* Variable used to return value of 07735 communication routine*/ 07736 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07737 u8 data_u8r = BNO055_INIT_VALUE; 07738 s8 stat_s8 = BNO055_ERROR; 07739 /* Check the struct p_bno055 is empty */ 07740 if (p_bno055 == BNO055_INIT_VALUE) { 07741 return BNO055_E_NULL_PTR; 07742 } else { 07743 /*condition check for page, clk source is 07744 available in the page zero*/ 07745 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07746 /* Write the page zero*/ 07747 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07748 if ((stat_s8 == BNO055_SUCCESS) || 07749 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07750 /* Read the value of clk source */ 07751 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07752 (p_bno055->dev_addr, 07753 BNO055_CLK_SRC_REG, 07754 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07755 *clk_src_u8 = 07756 BNO055_GET_BITSLICE(data_u8r, BNO055_CLK_SRC); 07757 } else { 07758 com_rslt = BNO055_ERROR; 07759 } 07760 } 07761 return com_rslt; 07762 } 07763 /*! 07764 * @brief This API used to write the clk source 07765 * from register from 0x3F bit 7 07766 * 07767 * @param clk_src_u8 : The value of clk source 07768 * 07769 * clk_src_u8 | result 07770 * -------------- |---------- 07771 * 0x01 | BNO055_BIT_ENABLE 07772 * 0x00 | BNO055_BIT_DISABLE 07773 * 07774 * @return results of bus communication function 07775 * @retval 0 -> BNO055_SUCCESS 07776 * @retval 1 -> BNO055_ERROR 07777 * 07778 */ 07779 BNO055_RETURN_FUNCTION_TYPE bno055_set_clk_src(u8 clk_src_u8) 07780 { 07781 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07782 u8 data_u8r = BNO055_INIT_VALUE; 07783 s8 stat_s8 = BNO055_ERROR; 07784 /* Check the struct p_bno055 is empty */ 07785 if (p_bno055 == BNO055_INIT_VALUE) { 07786 return BNO055_E_NULL_PTR; 07787 } else { 07788 /*condition check for page, clk source is 07789 available in the page zero*/ 07790 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07791 /* Write the page zero*/ 07792 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07793 if ((stat_s8 == BNO055_SUCCESS) || 07794 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07795 /* Write the value of clk source */ 07796 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07797 (p_bno055->dev_addr, 07798 BNO055_CLK_SRC_REG, 07799 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07800 if (com_rslt == BNO055_SUCCESS) { 07801 data_u8r = 07802 BNO055_SET_BITSLICE(data_u8r, 07803 BNO055_CLK_SRC, clk_src_u8); 07804 com_rslt += 07805 p_bno055->BNO055_BUS_WRITE_FUNC 07806 (p_bno055->dev_addr, 07807 BNO055_CLK_SRC_REG, 07808 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07809 } 07810 } else { 07811 com_rslt = BNO055_ERROR; 07812 } 07813 } 07814 return com_rslt; 07815 } 07816 /*! 07817 * @brief This API used to read the reset system 07818 * from register from 0x3F bit 5 07819 * 07820 * @param sys_rst_u8 : The value of reset system 07821 * 07822 * sys_rst_u8 | result 07823 * -------------- |---------- 07824 * 0x01 | BNO055_BIT_ENABLE 07825 * 0x00 | BNO055_BIT_DISABLE 07826 * 07827 * @return results of bus communication function 07828 * @retval 0 -> BNO055_SUCCESS 07829 * @retval 1 -> BNO055_ERROR 07830 * 07831 * @note It resets the whole system 07832 */ 07833 BNO055_RETURN_FUNCTION_TYPE bno055_get_sys_rst( 07834 u8 *sys_rst_u8) 07835 { 07836 /* Variable used to return value of 07837 communication routine*/ 07838 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07839 u8 data_u8r = BNO055_INIT_VALUE; 07840 s8 stat_s8 = BNO055_ERROR; 07841 /* Check the struct p_bno055 is empty */ 07842 if (p_bno055 == BNO055_INIT_VALUE) { 07843 return BNO055_E_NULL_PTR; 07844 } else { 07845 /*condition check for page, reset system is 07846 available in the page zero*/ 07847 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07848 /* Write the page zero*/ 07849 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07850 if ((stat_s8 == BNO055_SUCCESS) || 07851 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07852 /* Read the value of reset system */ 07853 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07854 (p_bno055->dev_addr, 07855 BNO055_SYS_RST_REG, 07856 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07857 *sys_rst_u8 = 07858 BNO055_GET_BITSLICE(data_u8r, 07859 BNO055_SYS_RST); 07860 } else { 07861 com_rslt = BNO055_ERROR; 07862 } 07863 } 07864 return com_rslt; 07865 } 07866 /*! 07867 * @brief This API used to write the reset system 07868 * from register from 0x3F bit 5 07869 * 07870 * @param sys_rst_u8 : The value of reset system 07871 * 07872 * sys_rst_u8 | result 07873 * -------------- |---------- 07874 * 0x01 | BNO055_BIT_ENABLE 07875 * 0x00 | BNO055_BIT_DISABLE 07876 * 07877 * @return results of bus communication function 07878 * @retval 0 -> BNO055_SUCCESS 07879 * @retval 1 -> BNO055_ERROR 07880 * 07881 * @note It resets the whole system 07882 */ 07883 BNO055_RETURN_FUNCTION_TYPE bno055_set_sys_rst(u8 sys_rst_u8) 07884 { 07885 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07886 u8 data_u8r = BNO055_INIT_VALUE; 07887 s8 stat_s8 = BNO055_ERROR; 07888 /* Check the struct p_bno055 is empty */ 07889 if (p_bno055 == BNO055_INIT_VALUE) { 07890 return BNO055_E_NULL_PTR; 07891 } else { 07892 /*condition check for page, reset system is 07893 available in the page zero*/ 07894 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07895 /* Write the page zero*/ 07896 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07897 if ((stat_s8 == BNO055_SUCCESS) || 07898 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07899 /* Write the value of reset system */ 07900 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07901 (p_bno055->dev_addr, 07902 BNO055_SYS_RST_REG, 07903 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07904 if (com_rslt == BNO055_SUCCESS) { 07905 data_u8r = 07906 BNO055_SET_BITSLICE(data_u8r, 07907 BNO055_SYS_RST, sys_rst_u8); 07908 com_rslt = 07909 p_bno055->BNO055_BUS_WRITE_FUNC 07910 (p_bno055->dev_addr, 07911 BNO055_SYS_RST_REG, 07912 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07913 } 07914 } else { 07915 com_rslt = BNO055_ERROR; 07916 } 07917 } 07918 return com_rslt; 07919 } 07920 /*! 07921 * @brief This API used to read the self test 07922 * from register from 0x3F bit 0 07923 * 07924 * @param selftest_u8 : The value of self test 07925 * 07926 * selftest_u8 | result 07927 * -------------- |---------- 07928 * 0x01 | BNO055_BIT_ENABLE 07929 * 0x00 | BNO055_BIT_DISABLE 07930 * 07931 * @return results of bus communication function 07932 * @retval 0 -> BNO055_SUCCESS 07933 * @retval 1 -> BNO055_ERROR 07934 * 07935 * @note It triggers the self test 07936 */ 07937 BNO055_RETURN_FUNCTION_TYPE bno055_get_selftest( 07938 u8 *selftest_u8) 07939 { 07940 /* Variable used to return value of 07941 communication routine*/ 07942 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07943 u8 data_u8r = BNO055_INIT_VALUE; 07944 s8 stat_s8 = BNO055_ERROR; 07945 /* Check the struct p_bno055 is empty */ 07946 if (p_bno055 == BNO055_INIT_VALUE) { 07947 return BNO055_E_NULL_PTR; 07948 } else { 07949 /*condition check for page, self test is 07950 available in the page zero*/ 07951 if (p_bno055->page_id != BNO055_PAGE_ZERO) 07952 /* Write the page zero*/ 07953 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 07954 if ((stat_s8 == BNO055_SUCCESS) || 07955 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 07956 /* Read the value of self test */ 07957 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 07958 (p_bno055->dev_addr, 07959 BNO055_SELFTEST_REG, 07960 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 07961 *selftest_u8 = 07962 BNO055_GET_BITSLICE(data_u8r, 07963 BNO055_SELFTEST); 07964 } else { 07965 com_rslt = BNO055_ERROR; 07966 } 07967 } 07968 return com_rslt; 07969 } 07970 /*! 07971 * @brief This API used to write the self test 07972 * from register from 0x3F bit 0 07973 * 07974 * @param selftest_u8 : The value of self test 07975 * 07976 * selftest_u8 | result 07977 * -------------- |---------- 07978 * 0x01 | BNO055_BIT_ENABLE 07979 * 0x00 | BNO055_BIT_DISABLE 07980 * 07981 * @return results of bus communication function 07982 * @retval 0 -> BNO055_SUCCESS 07983 * @retval 1 -> BNO055_ERROR 07984 * 07985 * @note It triggers the self test 07986 * 07987 * 07988 */ 07989 BNO055_RETURN_FUNCTION_TYPE bno055_set_selftest(u8 selftest_u8) 07990 { 07991 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 07992 u8 data_u8r = BNO055_INIT_VALUE; 07993 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 07994 s8 stat_s8 = BNO055_ERROR; 07995 /* Check the struct p_bno055 is empty */ 07996 if (p_bno055 == BNO055_INIT_VALUE) { 07997 return BNO055_E_NULL_PTR; 07998 } else { 07999 /* The write operation effective only if the operation 08000 mode is in config mode, this part of code is checking the 08001 current operation mode and set the config mode */ 08002 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 08003 if (stat_s8 == BNO055_SUCCESS) { 08004 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08005 stat_s8 += bno055_set_operation_mode 08006 (BNO055_OPERATION_MODE_CONFIG); 08007 if (stat_s8 == BNO055_SUCCESS) { 08008 /* Write the value of self test */ 08009 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08010 (p_bno055->dev_addr, 08011 BNO055_SELFTEST_REG, 08012 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08013 if (com_rslt == BNO055_SUCCESS) { 08014 data_u8r = 08015 BNO055_SET_BITSLICE(data_u8r, 08016 BNO055_SELFTEST, 08017 selftest_u8); 08018 com_rslt += 08019 p_bno055->BNO055_BUS_WRITE_FUNC 08020 (p_bno055->dev_addr, 08021 BNO055_SELFTEST_REG, 08022 &data_u8r, 08023 BNO055_GEN_READ_WRITE_LENGTH); 08024 } 08025 } else { 08026 com_rslt = BNO055_ERROR; 08027 } 08028 } else { 08029 com_rslt = BNO055_ERROR; 08030 } 08031 } 08032 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08033 /* set the operation mode 08034 of previous operation mode*/ 08035 com_rslt += bno055_set_operation_mode 08036 (prev_opmode_u8); 08037 return com_rslt; 08038 } 08039 /*! 08040 * @brief This API used to read the temperature source 08041 * from register from 0x40 bit 0 and 1 08042 * 08043 * @param temp_source_u8 : The value of selected temperature source 08044 * 08045 * temp_source_u8 | result 08046 * ---------------- |--------------- 08047 * 0x00 | BNO055_ACCEL_TEMP_EN 08048 * 0X01 | BNO055_GYRO_TEMP_EN 08049 * 0X03 | BNO055_MCU_TEMP_EN 08050 * 08051 * @return results of bus communication function 08052 * @retval 0 -> BNO055_SUCCESS 08053 * @retval 1 -> BNO055_ERROR 08054 * 08055 */ 08056 BNO055_RETURN_FUNCTION_TYPE bno055_get_temp_source( 08057 u8 *temp_source_u8) 08058 { 08059 /* Variable used to return value of 08060 communication routine*/ 08061 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08062 u8 data_u8r = BNO055_INIT_VALUE; 08063 s8 stat_s8 = BNO055_ERROR; 08064 /* Check the struct p_bno055 is empty */ 08065 if (p_bno055 == BNO055_INIT_VALUE) { 08066 return BNO055_E_NULL_PTR; 08067 } else { 08068 /*condition check for page, temperature source is 08069 available in the page zero*/ 08070 if (p_bno055->page_id != BNO055_PAGE_ZERO) 08071 /* Write the page zero*/ 08072 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 08073 if ((stat_s8 == BNO055_SUCCESS) || 08074 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 08075 /* Read the value of temperature source */ 08076 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08077 (p_bno055->dev_addr, 08078 BNO055_TEMP_SOURCE_REG, 08079 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08080 *temp_source_u8 = 08081 BNO055_GET_BITSLICE(data_u8r, 08082 BNO055_TEMP_SOURCE); 08083 } else { 08084 com_rslt = BNO055_ERROR; 08085 } 08086 } 08087 return com_rslt; 08088 } 08089 /*! 08090 * @brief This API used to write the temperature source 08091 * from register from 0x40 bit 0 and 1 08092 * 08093 * @param temp_source_u8 : The value of selected temperature source 08094 * 08095 * temp_source_u8 | result 08096 * ---------------- |--------------- 08097 * 0x00 | BNO055_ACCEL_TEMP_EN 08098 * 0X01 | BNO055_GYRO_TEMP_EN 08099 * 0X03 | BNO055_MCU_TEMP_EN 08100 * 08101 * @return results of bus communication function 08102 * @retval 0 -> BNO055_SUCCESS 08103 * @retval 1 -> BNO055_ERROR 08104 * 08105 */ 08106 BNO055_RETURN_FUNCTION_TYPE bno055_set_temp_source(u8 temp_source_u8) 08107 { 08108 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08109 u8 data_u8r = BNO055_INIT_VALUE; 08110 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 08111 s8 stat_s8 = BNO055_ERROR; 08112 /* Check the struct p_bno055 is empty */ 08113 if (p_bno055 == BNO055_INIT_VALUE) { 08114 return BNO055_E_NULL_PTR; 08115 } else { 08116 /* The write operation effective only if the operation 08117 mode is in config mode, this part of code is checking the 08118 current operation mode and set the config mode */ 08119 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 08120 if (stat_s8 == BNO055_SUCCESS) { 08121 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08122 stat_s8 += bno055_set_operation_mode 08123 (BNO055_OPERATION_MODE_CONFIG); 08124 if (stat_s8 == BNO055_SUCCESS) { 08125 /* Write the value of temperature source*/ 08126 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08127 (p_bno055->dev_addr, 08128 BNO055_TEMP_SOURCE_REG, 08129 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08130 if (com_rslt == BNO055_SUCCESS) { 08131 data_u8r = 08132 BNO055_SET_BITSLICE(data_u8r, 08133 BNO055_TEMP_SOURCE, temp_source_u8); 08134 com_rslt += 08135 p_bno055->BNO055_BUS_WRITE_FUNC 08136 (p_bno055->dev_addr, 08137 BNO055_TEMP_SOURCE_REG, 08138 &data_u8r, 08139 BNO055_GEN_READ_WRITE_LENGTH); 08140 } 08141 } else { 08142 com_rslt = BNO055_ERROR; 08143 } 08144 } else { 08145 com_rslt = BNO055_ERROR; 08146 } 08147 } 08148 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08149 /* set the operation mode 08150 of previous operation mode*/ 08151 com_rslt += bno055_set_operation_mode 08152 (prev_opmode_u8); 08153 return com_rslt; 08154 } 08155 /*! 08156 * @brief This API used to read the axis remap value 08157 * from register from 0x41 bit 0 and 5 08158 * 08159 * @param remap_axis_u8 : The value of axis remapping 08160 * 08161 * remap_axis_u8 | result | comments 08162 * ------------|-------------------|------------ 08163 * 0X21 | BNO055_REMAP_X_Y | Z=Z;X=Y;Y=X 08164 * 0X18 | BNO055_REMAP_Y_Z | X=X;Y=Z;Z=Y 08165 * 0X06 | BNO055_REMAP_Z_X | Y=Y;X=Z;Z=X 08166 * 0X12 | BNO055_REMAP_X_Y_Z_TYPE0 | X=Z;Y=X;Z=Y 08167 * 0X09 | BNO055_REMAP_X_Y_Z_TYPE1 | X=Y;Y=Z;Z=X 08168 * 0X24 | BNO055_DEFAULT_AXIS | X=X;Y=Y;Z=Z 08169 * 08170 * @return results of bus communication function 08171 * @retval 0 -> BNO055_SUCCESS 08172 * @retval 1 -> BNO055_ERROR 08173 * 08174 * @note : For axis sign remap refer the following APIs 08175 * x-axis : 08176 * 08177 * bno055_set_x_remap_sign() 08178 * 08179 * y-axis : 08180 * 08181 * bno055_set_y_remap_sign() 08182 * 08183 * z-axis : 08184 * 08185 * bno055_set_z_remap_sign() 08186 * 08187 */ 08188 BNO055_RETURN_FUNCTION_TYPE bno055_get_axis_remap_value( 08189 u8 *remap_axis_u8) 08190 { 08191 /* Variable used to return value of 08192 communication routine*/ 08193 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08194 u8 data_u8r = BNO055_INIT_VALUE; 08195 s8 stat_s8 = BNO055_ERROR; 08196 /* Check the struct p_bno055 is empty */ 08197 if (p_bno055 == BNO055_INIT_VALUE) { 08198 return BNO055_E_NULL_PTR; 08199 } else { 08200 /*condition check for page, axis remap is 08201 available in the page zero*/ 08202 if (p_bno055->page_id != BNO055_PAGE_ZERO) 08203 /* Write the page zero*/ 08204 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 08205 if ((stat_s8 == BNO055_SUCCESS) || 08206 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 08207 /* Read the value of axis remap*/ 08208 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08209 (p_bno055->dev_addr, 08210 BNO055_REMAP_AXIS_VALUE_REG, 08211 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08212 *remap_axis_u8 = 08213 BNO055_GET_BITSLICE(data_u8r, 08214 BNO055_REMAP_AXIS_VALUE); 08215 } else { 08216 com_rslt = BNO055_ERROR; 08217 } 08218 } 08219 return com_rslt; 08220 } 08221 /*! 08222 * @brief This API used to write the axis remap value 08223 * from register from 0x41 bit 0 and 5 08224 * 08225 * @param remap_axis_u8 : The value of axis remapping 08226 * 08227 * remap_axis_u8 | result | comments 08228 * ------------|-------------------|------------ 08229 * 0X21 | BNO055_REMAP_X_Y | Z=Z;X=Y;Y=X 08230 * 0X18 | BNO055_REMAP_Y_Z | X=X;Y=Z;Z=Y 08231 * 0X06 | BNO055_REMAP_Z_X | Y=Y;X=Z;Z=X 08232 * 0X12 | BNO055_REMAP_X_Y_Z_TYPE0 | X=Z;Y=X;Z=Y 08233 * 0X09 | BNO055_REMAP_X_Y_Z_TYPE1 | X=Y;Y=Z;Z=X 08234 * 0X24 | BNO055_DEFAULT_AXIS | X=X;Y=Y;Z=Z 08235 * 08236 * @return results of bus communication function 08237 * @retval 0 -> BNO055_SUCCESS 08238 * @retval 1 -> BNO055_ERROR 08239 * 08240 * @note : For axis sign remap refer the following APIs 08241 * x-axis : 08242 * 08243 * bno055_set_x_remap_sign() 08244 * 08245 * y-axis : 08246 * 08247 * bno055_set_y_remap_sign() 08248 * 08249 * z-axis : 08250 * 08251 * bno055_set_z_remap_sign() 08252 * 08253 */ 08254 BNO055_RETURN_FUNCTION_TYPE bno055_set_axis_remap_value( 08255 u8 remap_axis_u8) 08256 { 08257 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08258 u8 data_u8r = BNO055_INIT_VALUE; 08259 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 08260 s8 stat_s8 = BNO055_ERROR; 08261 /* Check the struct p_bno055 is empty */ 08262 if (p_bno055 == BNO055_INIT_VALUE) { 08263 return BNO055_E_NULL_PTR; 08264 } else { 08265 /* The write operation effective only if the operation 08266 mode is in config mode, this part of code is checking the 08267 current operation mode and set the config mode */ 08268 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 08269 if (stat_s8 == BNO055_SUCCESS) { 08270 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08271 stat_s8 += bno055_set_operation_mode 08272 (BNO055_OPERATION_MODE_CONFIG); 08273 /* Write the value of axis remap */ 08274 if (stat_s8 == BNO055_SUCCESS) { 08275 switch (remap_axis_u8) { 08276 case BNO055_REMAP_X_Y: 08277 case BNO055_REMAP_Y_Z: 08278 case BNO055_REMAP_Z_X: 08279 case BNO055_REMAP_X_Y_Z_TYPE0: 08280 case BNO055_REMAP_X_Y_Z_TYPE1: 08281 case BNO055_DEFAULT_AXIS: 08282 com_rslt = 08283 p_bno055->BNO055_BUS_READ_FUNC 08284 (p_bno055->dev_addr, 08285 BNO055_REMAP_AXIS_VALUE_REG, 08286 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08287 if (com_rslt == BNO055_SUCCESS) { 08288 data_u8r = BNO055_SET_BITSLICE 08289 (data_u8r, 08290 BNO055_REMAP_AXIS_VALUE, 08291 remap_axis_u8); 08292 com_rslt += 08293 p_bno055->BNO055_BUS_WRITE_FUNC 08294 (p_bno055->dev_addr, 08295 BNO055_REMAP_AXIS_VALUE_REG, 08296 &data_u8r, 08297 BNO055_GEN_READ_WRITE_LENGTH); 08298 } 08299 break; 08300 default: 08301 /* Write the default axis remap value */ 08302 com_rslt = 08303 p_bno055->BNO055_BUS_READ_FUNC 08304 (p_bno055->dev_addr, 08305 BNO055_REMAP_AXIS_VALUE_REG, 08306 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08307 if (com_rslt == BNO055_SUCCESS) { 08308 data_u8r = BNO055_SET_BITSLICE 08309 (data_u8r, 08310 BNO055_REMAP_AXIS_VALUE, 08311 BNO055_DEFAULT_AXIS); 08312 com_rslt += 08313 p_bno055->BNO055_BUS_WRITE_FUNC 08314 (p_bno055->dev_addr, 08315 BNO055_REMAP_AXIS_VALUE_REG, 08316 &data_u8r, 08317 BNO055_GEN_READ_WRITE_LENGTH); 08318 } 08319 break; 08320 } 08321 } else { 08322 com_rslt = BNO055_ERROR; 08323 } 08324 } else { 08325 com_rslt = BNO055_ERROR; 08326 } 08327 } 08328 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08329 /* set the operation mode 08330 of previous operation mode*/ 08331 com_rslt += bno055_set_operation_mode 08332 (prev_opmode_u8); 08333 return com_rslt; 08334 } 08335 /*! 08336 * @brief This API used to read the x-axis remap 08337 * sign from register from 0x42 bit 2 08338 * 08339 * @param remap_x_sign_u8 : The value of x-axis remap sign 08340 * 08341 * remap_x_sign_u8 | result 08342 * ------------------- |-------------------- 08343 * 0X00 | BNO055_REMAP_AXIS_POSITIVE 08344 * 0X01 | BNO055_REMAP_AXIS_NEGATIVE 08345 * 08346 * @return results of bus communication function 08347 * @retval 0 -> BNO055_SUCCESS 08348 * @retval 1 -> BNO055_ERROR 08349 * 08350 */ 08351 BNO055_RETURN_FUNCTION_TYPE bno055_get_remap_x_sign( 08352 u8 *remap_x_sign_u8) 08353 { 08354 /* Variable used to return value of 08355 communication routine*/ 08356 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08357 u8 data_u8r = BNO055_INIT_VALUE; 08358 s8 stat_s8 = BNO055_ERROR; 08359 /* Check the struct p_bno055 is empty */ 08360 if (p_bno055 == BNO055_INIT_VALUE) { 08361 return BNO055_E_NULL_PTR; 08362 } else { 08363 /*condition check for page, x-axis remap sign is 08364 available in the page zero*/ 08365 if (p_bno055->page_id != BNO055_PAGE_ZERO) 08366 /* Write the page zero*/ 08367 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 08368 if ((stat_s8 == BNO055_SUCCESS) || 08369 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 08370 /* Read the value of x-axis remap sign */ 08371 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08372 (p_bno055->dev_addr, 08373 BNO055_REMAP_X_SIGN_REG, 08374 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08375 *remap_x_sign_u8 = 08376 BNO055_GET_BITSLICE(data_u8r, 08377 BNO055_REMAP_X_SIGN); 08378 } else { 08379 com_rslt = BNO055_ERROR; 08380 } 08381 } 08382 return com_rslt; 08383 } 08384 /*! 08385 * @brief This API used to write the x-axis remap 08386 * sign from register from 0x42 bit 2 08387 * 08388 * @param remap_x_sign_u8 : The value of x-axis remap sign 08389 * 08390 * remap_x_sign_u8 | result 08391 * ------------------- |-------------------- 08392 * 0X00 | BNO055_REMAP_AXIS_POSITIVE 08393 * 0X01 | BNO055_REMAP_AXIS_NEGATIVE 08394 * 08395 * @return results of bus communication function 08396 * @retval 0 -> BNO055_SUCCESS 08397 * @retval 1 -> BNO055_ERROR 08398 * 08399 */ 08400 BNO055_RETURN_FUNCTION_TYPE bno055_set_remap_x_sign( 08401 u8 remap_x_sign_u8) 08402 { 08403 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08404 u8 data_u8r = BNO055_INIT_VALUE; 08405 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 08406 s8 stat_s8 = BNO055_ERROR; 08407 /* Check the struct p_bno055 is empty */ 08408 if (p_bno055 == BNO055_INIT_VALUE) { 08409 return BNO055_E_NULL_PTR; 08410 } else { 08411 /* The write operation effective only if the operation 08412 mode is in config mode, this part of code is checking the 08413 current operation mode and set the config mode */ 08414 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 08415 if (stat_s8 == BNO055_SUCCESS) { 08416 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08417 stat_s8 += bno055_set_operation_mode 08418 (BNO055_OPERATION_MODE_CONFIG); 08419 if (stat_s8 == BNO055_SUCCESS) { 08420 /* Write the value of x-axis remap */ 08421 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08422 (p_bno055->dev_addr, 08423 BNO055_REMAP_X_SIGN_REG, 08424 &data_u8r, 08425 BNO055_GEN_READ_WRITE_LENGTH); 08426 if (com_rslt == BNO055_SUCCESS) { 08427 data_u8r = 08428 BNO055_SET_BITSLICE(data_u8r, 08429 BNO055_REMAP_X_SIGN, 08430 remap_x_sign_u8); 08431 com_rslt += 08432 p_bno055->BNO055_BUS_WRITE_FUNC 08433 (p_bno055->dev_addr, 08434 BNO055_REMAP_X_SIGN_REG, 08435 &data_u8r, 08436 BNO055_GEN_READ_WRITE_LENGTH); 08437 } 08438 } else { 08439 com_rslt = BNO055_ERROR; 08440 } 08441 } else { 08442 com_rslt = BNO055_ERROR; 08443 } 08444 } 08445 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08446 /* set the operation mode 08447 of previous operation mode*/ 08448 com_rslt += bno055_set_operation_mode 08449 (prev_opmode_u8); 08450 return com_rslt; 08451 } 08452 /*! 08453 * @brief This API used to read the y-axis remap 08454 * sign from register from 0x42 bit 1 08455 * 08456 * @param remap_y_sign_u8 : The value of y-axis remap sign 08457 * 08458 * remap_y_sign_u8 | result 08459 * ------------------- |-------------------- 08460 * 0X00 | BNO055_REMAP_AXIS_POSITIVE 08461 * 0X01 | BNO055_REMAP_AXIS_NEGATIVE 08462 * 08463 * @return results of bus communication function 08464 * @retval 0 -> BNO055_SUCCESS 08465 * @retval 1 -> BNO055_ERROR 08466 * 08467 */ 08468 BNO055_RETURN_FUNCTION_TYPE bno055_get_remap_y_sign( 08469 u8 *remap_y_sign_u8) 08470 { 08471 /* Variable used to return value of 08472 communication routine*/ 08473 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08474 u8 data_u8r = BNO055_INIT_VALUE; 08475 s8 stat_s8 = BNO055_ERROR; 08476 /* Check the struct p_bno055 is empty */ 08477 if (p_bno055 == BNO055_INIT_VALUE) { 08478 return BNO055_E_NULL_PTR; 08479 } else { 08480 /*condition check for page, y-axis remap sign is 08481 available in the page zero*/ 08482 if (p_bno055->page_id != BNO055_PAGE_ZERO) 08483 /* Write the page zero*/ 08484 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 08485 if ((stat_s8 == BNO055_SUCCESS) || 08486 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 08487 /* Read the value of y-axis remap sign*/ 08488 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08489 (p_bno055->dev_addr, 08490 BNO055_REMAP_Y_SIGN_REG, 08491 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08492 *remap_y_sign_u8 = 08493 BNO055_GET_BITSLICE(data_u8r, 08494 BNO055_REMAP_Y_SIGN); 08495 } else { 08496 com_rslt = BNO055_ERROR; 08497 } 08498 } 08499 return com_rslt; 08500 } 08501 /*! 08502 * @brief This API used to write the y-axis remap 08503 * sign from register from 0x42 bit 1 08504 * 08505 * @param remap_y_sign_u8 : The value of y-axis remap sign 08506 * 08507 * remap_y_sign_u8 | result 08508 * ------------------- |-------------------- 08509 * 0X00 | BNO055_REMAP_AXIS_POSITIVE 08510 * 0X01 | BNO055_REMAP_AXIS_NEGATIVE 08511 * 08512 * @return results of bus communication function 08513 * @retval 0 -> BNO055_SUCCESS 08514 * @retval 1 -> BNO055_ERROR 08515 * 08516 */ 08517 BNO055_RETURN_FUNCTION_TYPE bno055_set_remap_y_sign( 08518 u8 remap_y_sign_u8) 08519 { 08520 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08521 u8 data_u8r = BNO055_INIT_VALUE; 08522 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 08523 s8 stat_s8 = BNO055_ERROR; 08524 /* Check the struct p_bno055 is empty */ 08525 if (p_bno055 == BNO055_INIT_VALUE) { 08526 return BNO055_E_NULL_PTR; 08527 } else { 08528 /* The write operation effective only if the operation 08529 mode is in config mode, this part of code is checking the 08530 current operation mode and set the config mode */ 08531 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 08532 if (stat_s8 == BNO055_SUCCESS) { 08533 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08534 stat_s8 += bno055_set_operation_mode 08535 (BNO055_OPERATION_MODE_CONFIG); 08536 if (stat_s8 == BNO055_SUCCESS) { 08537 /* Write the value of y-axis remap sign*/ 08538 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08539 (p_bno055->dev_addr, 08540 BNO055_REMAP_Y_SIGN_REG, 08541 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08542 if (com_rslt == BNO055_SUCCESS) { 08543 data_u8r = 08544 BNO055_SET_BITSLICE(data_u8r, 08545 BNO055_REMAP_Y_SIGN, 08546 remap_y_sign_u8); 08547 com_rslt += 08548 p_bno055->BNO055_BUS_WRITE_FUNC 08549 (p_bno055->dev_addr, 08550 BNO055_REMAP_Y_SIGN_REG, 08551 &data_u8r, 08552 BNO055_GEN_READ_WRITE_LENGTH); 08553 } 08554 } else { 08555 com_rslt = BNO055_ERROR; 08556 } 08557 } else { 08558 com_rslt = BNO055_ERROR; 08559 } 08560 } 08561 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08562 /* set the operation mode 08563 of previous operation mode*/ 08564 com_rslt += bno055_set_operation_mode 08565 (prev_opmode_u8); 08566 return com_rslt; 08567 } 08568 /*! 08569 * @brief This API used to read the z-axis remap 08570 * sign from register from 0x42 bit 0 08571 * 08572 * @param remap_z_sign_u8 : The value of z-axis remap sign 08573 * 08574 * remap_z_sign_u8 | result 08575 * ------------------- |-------------------- 08576 * 0X00 | BNO055_REMAP_AXIS_POSITIVE 08577 * 0X01 | BNO055_REMAP_AXIS_NEGATIVE 08578 * 08579 * @return results of bus communication function 08580 * @retval 0 -> BNO055_SUCCESS 08581 * @retval 1 -> BNO055_ERROR 08582 * 08583 */ 08584 BNO055_RETURN_FUNCTION_TYPE bno055_get_remap_z_sign( 08585 u8 *remap_z_sign_u8) 08586 { 08587 /* Variable used to return value of 08588 communication routine*/ 08589 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08590 u8 data_u8r = BNO055_INIT_VALUE; 08591 s8 stat_s8 = BNO055_ERROR; 08592 /* Check the struct p_bno055 is empty */ 08593 if (p_bno055 == BNO055_INIT_VALUE) { 08594 return BNO055_E_NULL_PTR; 08595 } else { 08596 /*condition check for page, z-axis remap sign is 08597 available in the page zero*/ 08598 if (p_bno055->page_id != BNO055_PAGE_ZERO) 08599 /* Write the page zero*/ 08600 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 08601 if ((stat_s8 == BNO055_SUCCESS) || 08602 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 08603 /* Read the value of z-axis remap sign*/ 08604 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08605 (p_bno055->dev_addr, 08606 BNO055_REMAP_Z_SIGN_REG, 08607 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08608 *remap_z_sign_u8 = 08609 BNO055_GET_BITSLICE(data_u8r, 08610 BNO055_REMAP_Z_SIGN); 08611 } else { 08612 com_rslt = BNO055_ERROR; 08613 } 08614 } 08615 return com_rslt; 08616 } 08617 /*! 08618 * @brief This API used to write the z-axis remap 08619 * sign from register from 0x42 bit 0 08620 * 08621 * @param remap_z_sign_u8 : The value of z-axis remap sign 08622 * 08623 * remap_z_sign_u8 | result 08624 * ------------------- |-------------------- 08625 * 0X00 | BNO055_REMAP_AXIS_POSITIVE 08626 * 0X01 | BNO055_REMAP_AXIS_NEGATIVE 08627 * 08628 * @return results of bus communication function 08629 * @retval 0 -> BNO055_SUCCESS 08630 * @retval 1 -> BNO055_ERROR 08631 * 08632 */ 08633 BNO055_RETURN_FUNCTION_TYPE bno055_set_remap_z_sign( 08634 u8 remap_z_sign_u8) 08635 { 08636 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08637 u8 data_u8r = BNO055_INIT_VALUE; 08638 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 08639 s8 stat_s8 = BNO055_ERROR; 08640 /* Check the struct p_bno055 is empty */ 08641 if (p_bno055 == BNO055_INIT_VALUE) { 08642 return BNO055_E_NULL_PTR; 08643 } else { 08644 /* The write operation effective only if the operation 08645 mode is in config mode, this part of code is checking the 08646 current operation mode and set the config mode */ 08647 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 08648 if (stat_s8 == BNO055_SUCCESS) { 08649 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08650 stat_s8 += bno055_set_operation_mode 08651 (BNO055_OPERATION_MODE_CONFIG); 08652 if (stat_s8 == BNO055_SUCCESS) { 08653 /* Write the value of z-axis remap sign*/ 08654 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08655 (p_bno055->dev_addr, 08656 BNO055_REMAP_Z_SIGN_REG, 08657 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 08658 if (com_rslt == BNO055_SUCCESS) { 08659 data_u8r = 08660 BNO055_SET_BITSLICE(data_u8r, 08661 BNO055_REMAP_Z_SIGN, 08662 remap_z_sign_u8); 08663 com_rslt += 08664 p_bno055->BNO055_BUS_WRITE_FUNC 08665 (p_bno055->dev_addr, 08666 BNO055_REMAP_Z_SIGN_REG, 08667 &data_u8r, 08668 BNO055_GEN_READ_WRITE_LENGTH); 08669 } 08670 } else { 08671 com_rslt = BNO055_ERROR; 08672 } 08673 } else { 08674 com_rslt = BNO055_ERROR; 08675 } 08676 } 08677 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08678 /* set the operation mode 08679 of previous operation mode*/ 08680 com_rslt += bno055_set_operation_mode 08681 (prev_opmode_u8); 08682 return com_rslt; 08683 } 08684 /*! 08685 * @brief This API is used to read soft iron calibration matrix 08686 * from the register 0x43 to 0x53 it is a 18 bytes of data 08687 * 08688 * @param sic_matrix : The value of soft iron calibration matrix 08689 * 08690 * sic_matrix | result 08691 * --------------------|---------------------------------- 08692 * sic_0 | soft iron calibration matrix zero 08693 * sic_1 | soft iron calibration matrix one 08694 * sic_2 | soft iron calibration matrix two 08695 * sic_3 | soft iron calibration matrix three 08696 * sic_4 | soft iron calibration matrix four 08697 * sic_5 | soft iron calibration matrix five 08698 * sic_6 | soft iron calibration matrix six 08699 * sic_7 | soft iron calibration matrix seven 08700 * sic_8 | soft iron calibration matrix eight 08701 * 08702 * 08703 * @return results of bus communication function 08704 * @retval 0 -> BNO055_SUCCESS 08705 * @retval 1 -> BNO055_ERROR 08706 * 08707 * @note : Each soft iron calibration matrix range from -32768 to +32767 08708 */ 08709 BNO055_RETURN_FUNCTION_TYPE bno055_read_sic_matrix( 08710 struct bno055_sic_matrix_t *sic_matrix) 08711 { 08712 /* Variable used to return value of 08713 communication routine*/ 08714 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08715 /* Array holding the soft iron calibration matrix values 08716 data_u8[BNO055_SOFT_IRON_CALIB_0_LSB] - sic_0->LSB 08717 data_u8[BNO055_SOFT_IRON_CALIB_0_MSB] - sic_0->MSB 08718 data_u8[BNO055_SOFT_IRON_CALIB_1_LSB] - sic_1->LSB 08719 data_u8[BNO055_SOFT_IRON_CALIB_1_MSB] - sic_1->MSB 08720 data_u8[BNO055_SOFT_IRON_CALIB_2_LSB] - sic_2->LSB 08721 data_u8[BNO055_SOFT_IRON_CALIB_2_MSB] - sic_2->MSB 08722 data_u8[BNO055_SOFT_IRON_CALIB_3_LSB] - sic_3->LSB 08723 data_u8[BNO055_SOFT_IRON_CALIB_3_MSB] - sic_3->MSB 08724 data_u8[BNO055_SOFT_IRON_CALIB_4_LSB] - sic_4->LSB 08725 data_u8[BNO055_SOFT_IRON_CALIB_4_MSB] - sic_4->MSB 08726 data_u8[BNO055_SOFT_IRON_CALIB_5_LSB] - sic_5->LSB 08727 data_u8[BNO055_SOFT_IRON_CALIB_5_MSB] - sic_5->MSB 08728 data_u8[BNO055_SOFT_IRON_CALIB_6_LSB] - sic_6->LSB 08729 data_u8[BNO055_SOFT_IRON_CALIB_6_MSB] - sic_6->MSB 08730 data_u8[BNO055_SOFT_IRON_CALIB_7_LSB] - sic_7->LSB 08731 data_u8[BNO055_SOFT_IRON_CALIB_7_MSB] - sic_7->MSB 08732 data_u8[BNO055_SOFT_IRON_CALIB_8_LSB] - sic_8->LSB 08733 data_u8[BNO055_SOFT_IRON_CALIB_8_MSB] - sic_8->MSB 08734 */ 08735 u8 data_u8[BNO055_SOFT_IRON_CALIBRATION_MATRIX_SIZE] = { 08736 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08737 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08738 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08739 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08740 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08741 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08742 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08743 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 08744 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 08745 s8 stat_s8 = BNO055_ERROR; 08746 /* Check the struct p_bno055 is empty */ 08747 if (p_bno055 == BNO055_INIT_VALUE) { 08748 return BNO055_E_NULL_PTR; 08749 } else { 08750 /*condition check for page, soft iron calibration matrix is 08751 available in the page zero*/ 08752 if (p_bno055->page_id != BNO055_PAGE_ZERO) 08753 /* Write the page zero*/ 08754 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 08755 if ((stat_s8 == BNO055_SUCCESS) || 08756 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 08757 /* Read soft iron calibration matrix value 08758 it is eighteen bytes of data */ 08759 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 08760 (p_bno055->dev_addr, 08761 BNO055_SIC_MATRIX_0_LSB_REG, 08762 data_u8, BNO055_SOFT_IRON_CALIBRATION_MATRIX_SIZE); 08763 if (com_rslt == BNO055_SUCCESS) { 08764 /*soft iron calibration matrix zero*/ 08765 data_u8[BNO055_SOFT_IRON_CALIB_0_LSB] = 08766 BNO055_GET_BITSLICE( 08767 data_u8[BNO055_SOFT_IRON_CALIB_0_LSB], 08768 BNO055_SIC_MATRIX_0_LSB); 08769 data_u8[BNO055_SOFT_IRON_CALIB_0_MSB] = 08770 BNO055_GET_BITSLICE( 08771 data_u8[BNO055_SOFT_IRON_CALIB_0_MSB], 08772 BNO055_SIC_MATRIX_0_MSB); 08773 sic_matrix->sic_0 = (s16)((((s32) 08774 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_0_MSB])) << 08775 (BNO055_SHIFT_EIGHT_BITS)) 08776 | (data_u8[BNO055_SOFT_IRON_CALIB_0_LSB])); 08777 08778 /*soft iron calibration matrix one*/ 08779 data_u8[BNO055_SOFT_IRON_CALIB_1_LSB] = 08780 BNO055_GET_BITSLICE( 08781 data_u8[BNO055_SOFT_IRON_CALIB_1_LSB], 08782 BNO055_SIC_MATRIX_1_LSB); 08783 data_u8[BNO055_SOFT_IRON_CALIB_1_MSB] = 08784 BNO055_GET_BITSLICE( 08785 data_u8[BNO055_SOFT_IRON_CALIB_1_MSB], 08786 BNO055_SIC_MATRIX_1_MSB); 08787 sic_matrix->sic_1 = (s16)((((s32) 08788 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_1_MSB])) << 08789 (BNO055_SHIFT_EIGHT_BITS)) 08790 | (data_u8[BNO055_SOFT_IRON_CALIB_1_LSB])); 08791 08792 /*soft iron calibration matrix two*/ 08793 data_u8[BNO055_SOFT_IRON_CALIB_2_LSB] = 08794 BNO055_GET_BITSLICE( 08795 data_u8[BNO055_SOFT_IRON_CALIB_2_LSB], 08796 BNO055_SIC_MATRIX_2_LSB); 08797 data_u8[BNO055_SOFT_IRON_CALIB_2_MSB] = 08798 BNO055_GET_BITSLICE( 08799 data_u8[BNO055_SOFT_IRON_CALIB_2_MSB], 08800 BNO055_SIC_MATRIX_2_MSB); 08801 sic_matrix->sic_2 = (s16)((((s32) 08802 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_2_MSB])) << 08803 (BNO055_SHIFT_EIGHT_BITS)) 08804 | (data_u8[BNO055_SOFT_IRON_CALIB_2_LSB])); 08805 08806 /*soft iron calibration matrix three*/ 08807 data_u8[BNO055_SOFT_IRON_CALIB_3_LSB] = 08808 BNO055_GET_BITSLICE( 08809 data_u8[BNO055_SOFT_IRON_CALIB_3_LSB], 08810 BNO055_SIC_MATRIX_3_LSB); 08811 data_u8[BNO055_SOFT_IRON_CALIB_3_MSB] = 08812 BNO055_GET_BITSLICE( 08813 data_u8[BNO055_SOFT_IRON_CALIB_3_MSB], 08814 BNO055_SIC_MATRIX_3_LSB); 08815 sic_matrix->sic_3 = (s16)((((s32) 08816 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_3_MSB])) << 08817 (BNO055_SHIFT_EIGHT_BITS)) | 08818 (data_u8[BNO055_SOFT_IRON_CALIB_3_LSB])); 08819 08820 /*soft iron calibration matrix four*/ 08821 data_u8[BNO055_SOFT_IRON_CALIB_4_LSB] = 08822 BNO055_GET_BITSLICE( 08823 data_u8[BNO055_SOFT_IRON_CALIB_4_LSB], 08824 BNO055_SIC_MATRIX_4_LSB); 08825 data_u8[BNO055_SOFT_IRON_CALIB_4_MSB] = 08826 BNO055_GET_BITSLICE( 08827 data_u8[BNO055_SOFT_IRON_CALIB_4_MSB], 08828 BNO055_SIC_MATRIX_4_LSB); 08829 sic_matrix->sic_4 = (s16)((((s32) 08830 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_4_MSB])) << 08831 (BNO055_SHIFT_EIGHT_BITS)) | 08832 (data_u8[BNO055_SOFT_IRON_CALIB_4_LSB])); 08833 08834 /*soft iron calibration matrix five*/ 08835 data_u8[BNO055_SOFT_IRON_CALIB_5_LSB] = 08836 BNO055_GET_BITSLICE( 08837 data_u8[BNO055_SOFT_IRON_CALIB_5_LSB], 08838 BNO055_SIC_MATRIX_5_LSB); 08839 data_u8[BNO055_SOFT_IRON_CALIB_5_MSB] = 08840 BNO055_GET_BITSLICE( 08841 data_u8[BNO055_SOFT_IRON_CALIB_5_MSB], 08842 BNO055_SIC_MATRIX_5_LSB); 08843 sic_matrix->sic_5 = (s16)((((s32) 08844 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_5_MSB])) << 08845 (BNO055_SHIFT_EIGHT_BITS)) | 08846 (data_u8[BNO055_SOFT_IRON_CALIB_5_LSB])); 08847 08848 /*soft iron calibration matrix six*/ 08849 data_u8[BNO055_SOFT_IRON_CALIB_6_LSB] = 08850 BNO055_GET_BITSLICE( 08851 data_u8[BNO055_SOFT_IRON_CALIB_6_LSB], 08852 BNO055_SIC_MATRIX_6_LSB); 08853 data_u8[BNO055_SOFT_IRON_CALIB_6_MSB] = 08854 BNO055_GET_BITSLICE( 08855 data_u8[BNO055_SOFT_IRON_CALIB_6_MSB], 08856 BNO055_SIC_MATRIX_6_LSB); 08857 sic_matrix->sic_6 = (s16)((((s32) 08858 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_6_MSB])) << 08859 (BNO055_SHIFT_EIGHT_BITS)) | 08860 (data_u8[BNO055_SOFT_IRON_CALIB_6_LSB])); 08861 08862 /*soft iron calibration matrix seven*/ 08863 data_u8[BNO055_SOFT_IRON_CALIB_7_LSB] = 08864 BNO055_GET_BITSLICE( 08865 data_u8[BNO055_SOFT_IRON_CALIB_7_LSB], 08866 BNO055_SIC_MATRIX_7_LSB); 08867 data_u8[BNO055_SOFT_IRON_CALIB_7_MSB] = 08868 BNO055_GET_BITSLICE( 08869 data_u8[BNO055_SOFT_IRON_CALIB_7_MSB], 08870 BNO055_SIC_MATRIX_7_LSB); 08871 sic_matrix->sic_7 = (s16)((((s32) 08872 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_7_MSB])) << 08873 (BNO055_SHIFT_EIGHT_BITS)) | 08874 (data_u8[BNO055_SOFT_IRON_CALIB_7_LSB])); 08875 08876 /*soft iron calibration matrix eight*/ 08877 data_u8[BNO055_SOFT_IRON_CALIB_8_LSB] = 08878 BNO055_GET_BITSLICE( 08879 data_u8[BNO055_SOFT_IRON_CALIB_8_LSB], 08880 BNO055_SIC_MATRIX_8_LSB); 08881 data_u8[BNO055_SOFT_IRON_CALIB_8_MSB] = 08882 BNO055_GET_BITSLICE( 08883 data_u8[BNO055_SOFT_IRON_CALIB_8_MSB], 08884 BNO055_SIC_MATRIX_8_LSB); 08885 sic_matrix->sic_8 = (s16)((((s32) 08886 (s8)(data_u8[BNO055_SOFT_IRON_CALIB_8_MSB])) << 08887 (BNO055_SHIFT_EIGHT_BITS)) | 08888 (data_u8[BNO055_SOFT_IRON_CALIB_8_LSB])); 08889 } else { 08890 com_rslt = BNO055_ERROR; 08891 } 08892 } else { 08893 com_rslt = BNO055_ERROR; 08894 } 08895 } 08896 return com_rslt; 08897 } 08898 /*! 08899 * @brief This API is used to write soft iron calibration matrix 08900 * from the register 0x43 to 0x53 it is a 18 bytes of data 08901 * 08902 * @param sic_matrix : The value of soft iron calibration matrix 08903 * 08904 * sic_matrix | result 08905 * --------------------|---------------------------------- 08906 * sic_0 | soft iron calibration matrix zero 08907 * sic_1 | soft iron calibration matrix one 08908 * sic_2 | soft iron calibration matrix two 08909 * sic_3 | soft iron calibration matrix three 08910 * sic_4 | soft iron calibration matrix four 08911 * sic_5 | soft iron calibration matrix five 08912 * sic_6 | soft iron calibration matrix six 08913 * sic_7 | soft iron calibration matrix seven 08914 * sic_8 | soft iron calibration matrix eight 08915 * 08916 * 08917 * @return results of bus communication function 08918 * @retval 0 -> BNO055_SUCCESS 08919 * @retval 1 -> BNO055_ERROR 08920 * 08921 * @note : Each soft iron calibration matrix range from -32768 to +32767 08922 */ 08923 BNO055_RETURN_FUNCTION_TYPE bno055_write_sic_matrix( 08924 struct bno055_sic_matrix_t *sic_matrix) 08925 { 08926 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 08927 u8 data1_u8r = BNO055_INIT_VALUE; 08928 u8 data2_u8r = BNO055_INIT_VALUE; 08929 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 08930 s8 stat_s8 = BNO055_ERROR; 08931 /* Check the struct p_bno055 is empty */ 08932 if (p_bno055 == BNO055_INIT_VALUE) { 08933 return BNO055_E_NULL_PTR; 08934 } else { 08935 /* The write operation effective only if the operation 08936 mode is in config mode, this part of code is checking the 08937 current operation mode and set the config mode */ 08938 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 08939 if (stat_s8 == BNO055_SUCCESS) { 08940 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 08941 stat_s8 += bno055_set_operation_mode 08942 (BNO055_OPERATION_MODE_CONFIG); 08943 if (stat_s8 == BNO055_SUCCESS) { 08944 /* write soft iron calibration 08945 matrix zero value*/ 08946 com_rslt = 08947 p_bno055->BNO055_BUS_READ_FUNC 08948 (p_bno055->dev_addr, 08949 BNO055_SIC_MATRIX_0_LSB_REG, 08950 &data2_u8r, 08951 BNO055_GEN_READ_WRITE_LENGTH); 08952 if (com_rslt == BNO055_SUCCESS) { 08953 data1_u8r = ((s8) 08954 (sic_matrix->sic_0 08955 & BNO055_SIC_HEX_0_0_F_F_DATA)); 08956 data2_u8r = 08957 BNO055_SET_BITSLICE(data2_u8r, 08958 BNO055_SIC_MATRIX_0_LSB, 08959 data1_u8r); 08960 com_rslt += 08961 p_bno055->BNO055_BUS_WRITE_FUNC 08962 (p_bno055->dev_addr, 08963 BNO055_SIC_MATRIX_0_LSB_REG, 08964 &data2_u8r, 08965 BNO055_GEN_READ_WRITE_LENGTH); 08966 } 08967 08968 com_rslt += 08969 p_bno055->BNO055_BUS_READ_FUNC 08970 (p_bno055->dev_addr, 08971 BNO055_SIC_MATRIX_0_MSB_REG, 08972 &data2_u8r, 08973 BNO055_GEN_READ_WRITE_LENGTH); 08974 if (com_rslt == BNO055_SUCCESS) { 08975 data1_u8r = ((s8) 08976 (sic_matrix->sic_0 >> 08977 BNO055_SHIFT_EIGHT_BITS) 08978 & BNO055_SIC_HEX_0_0_F_F_DATA); 08979 data2_u8r = 08980 BNO055_SET_BITSLICE(data2_u8r, 08981 BNO055_SIC_MATRIX_0_MSB, 08982 data1_u8r); 08983 com_rslt += 08984 p_bno055->BNO055_BUS_WRITE_FUNC 08985 (p_bno055->dev_addr, 08986 BNO055_SIC_MATRIX_0_MSB_REG, 08987 &data2_u8r, 08988 BNO055_GEN_READ_WRITE_LENGTH); 08989 } 08990 08991 /* write soft iron calibration 08992 matrix one value*/ 08993 com_rslt += 08994 p_bno055->BNO055_BUS_READ_FUNC 08995 (p_bno055->dev_addr, 08996 BNO055_SIC_MATRIX_1_LSB_REG, 08997 &data2_u8r, 08998 BNO055_GEN_READ_WRITE_LENGTH); 08999 if (com_rslt == BNO055_SUCCESS) { 09000 data1_u8r = ((s8) 09001 (sic_matrix->sic_1 09002 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09003 data2_u8r = 09004 BNO055_SET_BITSLICE(data2_u8r, 09005 BNO055_SIC_MATRIX_1_LSB, 09006 data1_u8r); 09007 com_rslt += 09008 p_bno055->BNO055_BUS_WRITE_FUNC 09009 (p_bno055->dev_addr, 09010 BNO055_SIC_MATRIX_1_LSB_REG, 09011 &data2_u8r, 09012 BNO055_GEN_READ_WRITE_LENGTH); 09013 } 09014 09015 com_rslt += 09016 p_bno055->BNO055_BUS_READ_FUNC 09017 (p_bno055->dev_addr, 09018 BNO055_SIC_MATRIX_1_MSB_REG, 09019 &data2_u8r, 09020 BNO055_GEN_READ_WRITE_LENGTH); 09021 if (com_rslt == BNO055_SUCCESS) { 09022 data1_u8r = ((s8) 09023 (sic_matrix->sic_1 >> 09024 BNO055_SHIFT_EIGHT_BITS) 09025 & BNO055_SIC_HEX_0_0_F_F_DATA); 09026 data2_u8r = 09027 BNO055_SET_BITSLICE(data2_u8r, 09028 BNO055_SIC_MATRIX_1_MSB, 09029 data1_u8r); 09030 com_rslt += 09031 p_bno055->BNO055_BUS_WRITE_FUNC 09032 (p_bno055->dev_addr, 09033 BNO055_SIC_MATRIX_1_MSB_REG, 09034 &data2_u8r, 09035 BNO055_GEN_READ_WRITE_LENGTH); 09036 } 09037 09038 /* write soft iron calibration 09039 matrix two value*/ 09040 com_rslt += 09041 p_bno055->BNO055_BUS_READ_FUNC 09042 (p_bno055->dev_addr, 09043 BNO055_SIC_MATRIX_2_LSB_REG, 09044 &data2_u8r, 09045 BNO055_GEN_READ_WRITE_LENGTH); 09046 if (com_rslt == BNO055_SUCCESS) { 09047 data1_u8r = ((s8) 09048 (sic_matrix->sic_2 09049 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09050 data2_u8r = 09051 BNO055_SET_BITSLICE(data2_u8r, 09052 BNO055_SIC_MATRIX_2_LSB, 09053 data1_u8r); 09054 com_rslt += 09055 p_bno055->BNO055_BUS_WRITE_FUNC 09056 (p_bno055->dev_addr, 09057 BNO055_SIC_MATRIX_2_LSB_REG, 09058 &data2_u8r, 09059 BNO055_GEN_READ_WRITE_LENGTH); 09060 } 09061 09062 com_rslt += 09063 p_bno055->BNO055_BUS_READ_FUNC 09064 (p_bno055->dev_addr, 09065 BNO055_SIC_MATRIX_2_MSB_REG, 09066 &data2_u8r, 09067 BNO055_GEN_READ_WRITE_LENGTH); 09068 if (com_rslt == BNO055_SUCCESS) { 09069 data1_u8r = ((s8) 09070 (sic_matrix->sic_2 >> 09071 BNO055_SHIFT_EIGHT_BITS) 09072 & BNO055_SIC_HEX_0_0_F_F_DATA); 09073 data2_u8r = 09074 BNO055_SET_BITSLICE(data2_u8r, 09075 BNO055_SIC_MATRIX_2_MSB, 09076 data1_u8r); 09077 com_rslt += 09078 p_bno055->BNO055_BUS_WRITE_FUNC 09079 (p_bno055->dev_addr, 09080 BNO055_SIC_MATRIX_2_MSB_REG, 09081 &data2_u8r, 09082 BNO055_GEN_READ_WRITE_LENGTH); 09083 } 09084 09085 /* write soft iron calibration 09086 matrix three value*/ 09087 com_rslt += 09088 p_bno055->BNO055_BUS_READ_FUNC 09089 (p_bno055->dev_addr, 09090 BNO055_SIC_MATRIX_3_LSB_REG, 09091 &data2_u8r, 09092 BNO055_GEN_READ_WRITE_LENGTH); 09093 if (com_rslt == BNO055_SUCCESS) { 09094 data1_u8r = ((s8) 09095 (sic_matrix->sic_3 09096 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09097 data2_u8r = 09098 BNO055_SET_BITSLICE(data2_u8r, 09099 BNO055_SIC_MATRIX_3_LSB, 09100 data1_u8r); 09101 com_rslt += 09102 p_bno055->BNO055_BUS_WRITE_FUNC 09103 (p_bno055->dev_addr, 09104 BNO055_SIC_MATRIX_3_LSB_REG, 09105 &data2_u8r, 09106 BNO055_GEN_READ_WRITE_LENGTH); 09107 } 09108 09109 com_rslt += 09110 p_bno055->BNO055_BUS_READ_FUNC 09111 (p_bno055->dev_addr, 09112 BNO055_SIC_MATRIX_3_MSB_REG, 09113 &data2_u8r, 09114 BNO055_GEN_READ_WRITE_LENGTH); 09115 if (com_rslt == BNO055_SUCCESS) { 09116 data1_u8r = ((s8) 09117 (sic_matrix->sic_3 >> 09118 BNO055_SHIFT_EIGHT_BITS) 09119 & BNO055_SIC_HEX_0_0_F_F_DATA); 09120 data2_u8r = 09121 BNO055_SET_BITSLICE(data2_u8r, 09122 BNO055_SIC_MATRIX_3_MSB, 09123 data1_u8r); 09124 com_rslt += 09125 p_bno055->BNO055_BUS_WRITE_FUNC 09126 (p_bno055->dev_addr, 09127 BNO055_SIC_MATRIX_3_MSB_REG, 09128 &data2_u8r, 09129 BNO055_GEN_READ_WRITE_LENGTH); 09130 } 09131 09132 /* write soft iron calibration 09133 matrix four value*/ 09134 com_rslt += 09135 p_bno055->BNO055_BUS_READ_FUNC 09136 (p_bno055->dev_addr, 09137 BNO055_SIC_MATRIX_4_LSB_REG, 09138 &data2_u8r, 09139 BNO055_GEN_READ_WRITE_LENGTH); 09140 if (com_rslt == BNO055_SUCCESS) { 09141 data1_u8r = ((s8) 09142 (sic_matrix->sic_4 09143 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09144 data2_u8r = 09145 BNO055_SET_BITSLICE(data2_u8r, 09146 BNO055_SIC_MATRIX_4_LSB, 09147 data1_u8r); 09148 com_rslt += 09149 p_bno055->BNO055_BUS_WRITE_FUNC 09150 (p_bno055->dev_addr, 09151 BNO055_SIC_MATRIX_4_LSB_REG, 09152 &data2_u8r, 09153 BNO055_GEN_READ_WRITE_LENGTH); 09154 } 09155 09156 com_rslt += 09157 p_bno055->BNO055_BUS_READ_FUNC 09158 (p_bno055->dev_addr, 09159 BNO055_SIC_MATRIX_4_MSB_REG, 09160 &data2_u8r, 09161 BNO055_GEN_READ_WRITE_LENGTH); 09162 if (com_rslt == BNO055_SUCCESS) { 09163 data1_u8r = ((s8) 09164 (sic_matrix->sic_4 >> 09165 BNO055_SHIFT_EIGHT_BITS) 09166 & BNO055_SIC_HEX_0_0_F_F_DATA); 09167 data2_u8r = 09168 BNO055_SET_BITSLICE(data2_u8r, 09169 BNO055_SIC_MATRIX_4_MSB, 09170 data1_u8r); 09171 com_rslt += 09172 p_bno055->BNO055_BUS_WRITE_FUNC 09173 (p_bno055->dev_addr, 09174 BNO055_SIC_MATRIX_4_MSB_REG, 09175 &data2_u8r, 09176 BNO055_GEN_READ_WRITE_LENGTH); 09177 } 09178 09179 /* write soft iron calibration 09180 matrix five value*/ 09181 com_rslt += 09182 p_bno055->BNO055_BUS_READ_FUNC 09183 (p_bno055->dev_addr, 09184 BNO055_SIC_MATRIX_5_LSB_REG, 09185 &data2_u8r, 09186 BNO055_GEN_READ_WRITE_LENGTH); 09187 if (com_rslt == BNO055_SUCCESS) { 09188 data1_u8r = ((s8) 09189 (sic_matrix->sic_5 09190 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09191 data2_u8r = 09192 BNO055_SET_BITSLICE(data2_u8r, 09193 BNO055_SIC_MATRIX_5_LSB, 09194 data1_u8r); 09195 com_rslt += 09196 p_bno055->BNO055_BUS_WRITE_FUNC 09197 (p_bno055->dev_addr, 09198 BNO055_SIC_MATRIX_5_LSB_REG, 09199 &data2_u8r, 09200 BNO055_GEN_READ_WRITE_LENGTH); 09201 } 09202 09203 com_rslt += 09204 p_bno055->BNO055_BUS_READ_FUNC 09205 (p_bno055->dev_addr, 09206 BNO055_SIC_MATRIX_5_MSB_REG, 09207 &data2_u8r, 09208 BNO055_GEN_READ_WRITE_LENGTH); 09209 if (com_rslt == BNO055_SUCCESS) { 09210 data1_u8r = ((s8) 09211 (sic_matrix->sic_5 >> 09212 BNO055_SHIFT_EIGHT_BITS) 09213 & BNO055_SIC_HEX_0_0_F_F_DATA); 09214 data2_u8r = 09215 BNO055_SET_BITSLICE(data2_u8r, 09216 BNO055_SIC_MATRIX_5_MSB, 09217 data1_u8r); 09218 com_rslt += 09219 p_bno055->BNO055_BUS_WRITE_FUNC 09220 (p_bno055->dev_addr, 09221 BNO055_SIC_MATRIX_5_MSB_REG, 09222 &data2_u8r, 09223 BNO055_GEN_READ_WRITE_LENGTH); 09224 } 09225 09226 /* write soft iron calibration 09227 matrix six value*/ 09228 com_rslt += 09229 p_bno055->BNO055_BUS_READ_FUNC 09230 (p_bno055->dev_addr, 09231 BNO055_SIC_MATRIX_6_LSB_REG, 09232 &data2_u8r, 09233 BNO055_GEN_READ_WRITE_LENGTH); 09234 if (com_rslt == BNO055_SUCCESS) { 09235 data1_u8r = ((s8) 09236 (sic_matrix->sic_6 09237 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09238 data2_u8r = 09239 BNO055_SET_BITSLICE(data2_u8r, 09240 BNO055_SIC_MATRIX_6_LSB, 09241 data1_u8r); 09242 com_rslt += 09243 p_bno055->BNO055_BUS_WRITE_FUNC 09244 (p_bno055->dev_addr, 09245 BNO055_SIC_MATRIX_6_LSB_REG, 09246 &data2_u8r, 09247 BNO055_GEN_READ_WRITE_LENGTH); 09248 } 09249 09250 com_rslt += 09251 p_bno055->BNO055_BUS_READ_FUNC 09252 (p_bno055->dev_addr, 09253 BNO055_SIC_MATRIX_6_MSB_REG, 09254 &data2_u8r, 09255 BNO055_GEN_READ_WRITE_LENGTH); 09256 if (com_rslt == BNO055_SUCCESS) { 09257 data1_u8r = ((s8) 09258 (sic_matrix->sic_6 >> 09259 BNO055_SHIFT_EIGHT_BITS) 09260 & BNO055_SIC_HEX_0_0_F_F_DATA); 09261 data2_u8r = 09262 BNO055_SET_BITSLICE(data2_u8r, 09263 BNO055_SIC_MATRIX_6_MSB, 09264 data1_u8r); 09265 com_rslt += 09266 p_bno055->BNO055_BUS_WRITE_FUNC 09267 (p_bno055->dev_addr, 09268 BNO055_SIC_MATRIX_6_MSB_REG, 09269 &data2_u8r, 09270 BNO055_GEN_READ_WRITE_LENGTH); 09271 } 09272 09273 /* write soft iron calibration 09274 matrix seven value*/ 09275 com_rslt += 09276 p_bno055->BNO055_BUS_READ_FUNC 09277 (p_bno055->dev_addr, 09278 BNO055_SIC_MATRIX_7_LSB_REG, 09279 &data2_u8r, 09280 BNO055_GEN_READ_WRITE_LENGTH); 09281 if (com_rslt == BNO055_SUCCESS) { 09282 data1_u8r = ((s8) 09283 (sic_matrix->sic_7 09284 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09285 data2_u8r = 09286 BNO055_SET_BITSLICE(data2_u8r, 09287 BNO055_SIC_MATRIX_7_LSB, 09288 data1_u8r); 09289 com_rslt += 09290 p_bno055->BNO055_BUS_WRITE_FUNC 09291 (p_bno055->dev_addr, 09292 BNO055_SIC_MATRIX_7_LSB_REG, 09293 &data2_u8r, 09294 BNO055_GEN_READ_WRITE_LENGTH); 09295 } 09296 09297 com_rslt += 09298 p_bno055->BNO055_BUS_READ_FUNC 09299 (p_bno055->dev_addr, 09300 BNO055_SIC_MATRIX_7_MSB_REG, 09301 &data2_u8r, 09302 BNO055_GEN_READ_WRITE_LENGTH); 09303 if (com_rslt == BNO055_SUCCESS) { 09304 data1_u8r = ((s8) 09305 (sic_matrix->sic_7 >> 09306 BNO055_SHIFT_EIGHT_BITS) 09307 & BNO055_SIC_HEX_0_0_F_F_DATA); 09308 data2_u8r = 09309 BNO055_SET_BITSLICE(data2_u8r, 09310 BNO055_SIC_MATRIX_7_MSB, 09311 data1_u8r); 09312 com_rslt += 09313 p_bno055->BNO055_BUS_WRITE_FUNC 09314 (p_bno055->dev_addr, 09315 BNO055_SIC_MATRIX_7_MSB_REG, 09316 &data2_u8r, 09317 BNO055_GEN_READ_WRITE_LENGTH); 09318 } 09319 09320 /* write soft iron calibration 09321 matrix eight value*/ 09322 com_rslt += 09323 p_bno055->BNO055_BUS_READ_FUNC 09324 (p_bno055->dev_addr, 09325 BNO055_SIC_MATRIX_8_LSB_REG, 09326 &data2_u8r, 09327 BNO055_GEN_READ_WRITE_LENGTH); 09328 if (com_rslt == BNO055_SUCCESS) { 09329 data1_u8r = ((s8) 09330 (sic_matrix->sic_8 09331 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09332 data2_u8r = 09333 BNO055_SET_BITSLICE(data2_u8r, 09334 BNO055_SIC_MATRIX_8_LSB, 09335 data1_u8r); 09336 com_rslt += 09337 p_bno055->BNO055_BUS_WRITE_FUNC 09338 (p_bno055->dev_addr, 09339 BNO055_SIC_MATRIX_8_LSB_REG, 09340 &data2_u8r, 09341 BNO055_GEN_READ_WRITE_LENGTH); 09342 } 09343 09344 com_rslt += 09345 p_bno055->BNO055_BUS_READ_FUNC 09346 (p_bno055->dev_addr, 09347 BNO055_SIC_MATRIX_8_MSB_REG, 09348 &data2_u8r, 09349 BNO055_GEN_READ_WRITE_LENGTH); 09350 if (com_rslt == BNO055_SUCCESS) { 09351 data1_u8r = ((s8) 09352 (sic_matrix->sic_8 >> 09353 BNO055_SHIFT_EIGHT_BITS) 09354 & BNO055_SIC_HEX_0_0_F_F_DATA); 09355 data2_u8r = 09356 BNO055_SET_BITSLICE(data2_u8r, 09357 BNO055_SIC_MATRIX_8_MSB, 09358 data1_u8r); 09359 com_rslt += 09360 p_bno055->BNO055_BUS_WRITE_FUNC 09361 (p_bno055->dev_addr, 09362 BNO055_SIC_MATRIX_8_MSB_REG, 09363 &data2_u8r, 09364 BNO055_GEN_READ_WRITE_LENGTH); 09365 } 09366 } else { 09367 com_rslt = BNO055_ERROR; 09368 } 09369 } else { 09370 com_rslt = BNO055_ERROR; 09371 } 09372 } 09373 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 09374 /* set the operation mode 09375 of previous operation mode*/ 09376 com_rslt += bno055_set_operation_mode 09377 (prev_opmode_u8); 09378 return com_rslt; 09379 } 09380 /*! 09381 * @brief This API is used to read accel offset and accel radius 09382 * offset form register 0x55 to 0x5A and radius form 0x67 and 0x68 09383 * 09384 * @param accel_offset : The value of accel offset and radius 09385 * 09386 * bno055_accel_offset_t | result 09387 * ------------------- | ---------------- 09388 * x | accel offset x 09389 * y | accel offset y 09390 * z | accel offset z 09391 * r | accel offset r 09392 * 09393 * 09394 * @return results of bus communication function 09395 * @retval 0 -> BNO055_SUCCESS 09396 * @retval 1 -> BNO055_ERROR 09397 * 09398 * @note The range of the accel offset varies based on 09399 * the G-range of accel sensor. 09400 * 09401 * accel G range | offset range 09402 * --------------- | -------------- 09403 * BNO055_ACCEL_RANGE_2G | +/-2000 09404 * BNO055_ACCEL_RANGE_4G | +/-4000 09405 * BNO055_ACCEL_RANGE_8G | +/-8000 09406 * BNO055_ACCEL_RANGE_16G | +/-16000 09407 * 09408 * accel G range can be configured by using the 09409 * bno055_set_accel_range() API 09410 */ 09411 BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_offset( 09412 struct bno055_accel_offset_t *accel_offset) 09413 { 09414 /* Variable used to return value of 09415 communication routine*/ 09416 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 09417 /* Array holding the accel offset values 09418 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB] - offset x->LSB 09419 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB] - offset x->MSB 09420 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB] - offset y->LSB 09421 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB] - offset y->MSB 09422 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB] - offset z->LSB 09423 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB] - offset z->MSB 09424 */ 09425 u8 data_u8[BNO055_ACCEL_OFFSET_ARRAY] = { 09426 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 09427 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 09428 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 09429 s8 stat_s8 = BNO055_ERROR; 09430 /* Check the struct p_bno055 is empty */ 09431 if (p_bno055 == BNO055_INIT_VALUE) { 09432 return BNO055_E_NULL_PTR; 09433 } else { 09434 /*condition check for page, accel offset is 09435 available in the page zero*/ 09436 if (p_bno055->page_id != BNO055_PAGE_ZERO) 09437 /* Write the page zero*/ 09438 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 09439 if ((stat_s8 == BNO055_SUCCESS) || 09440 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 09441 /* Read accel offset value it is six bytes of data*/ 09442 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 09443 (p_bno055->dev_addr, 09444 BNO055_ACCEL_OFFSET_X_LSB_REG, 09445 data_u8, BNO055_ACCEL_OFFSET_ARRAY); 09446 if (com_rslt == BNO055_SUCCESS) { 09447 /* Read accel x offset value*/ 09448 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB] = 09449 BNO055_GET_BITSLICE( 09450 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB], 09451 BNO055_ACCEL_OFFSET_X_LSB); 09452 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB] = 09453 BNO055_GET_BITSLICE( 09454 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB], 09455 BNO055_ACCEL_OFFSET_X_MSB); 09456 accel_offset->x = (s16)((((s32)(s8) 09457 (data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB])) << 09458 (BNO055_SHIFT_EIGHT_BITS)) | 09459 (data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB])); 09460 09461 /* Read accel y offset value*/ 09462 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB] = 09463 BNO055_GET_BITSLICE( 09464 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB], 09465 BNO055_ACCEL_OFFSET_Y_LSB); 09466 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB] = 09467 BNO055_GET_BITSLICE( 09468 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB], 09469 BNO055_ACCEL_OFFSET_Y_MSB); 09470 accel_offset->y = (s16)((((s32)(s8) 09471 (data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB])) << 09472 (BNO055_SHIFT_EIGHT_BITS)) 09473 | (data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB])); 09474 09475 /* Read accel z offset value*/ 09476 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB] = 09477 BNO055_GET_BITSLICE( 09478 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB], 09479 BNO055_ACCEL_OFFSET_Z_LSB); 09480 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB] = 09481 BNO055_GET_BITSLICE( 09482 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB], 09483 BNO055_ACCEL_OFFSET_Z_MSB); 09484 accel_offset->z = (s16)((((s32)(s8) 09485 (data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB])) << 09486 (BNO055_SHIFT_EIGHT_BITS)) | 09487 (data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB])); 09488 09489 /* Read accel radius value 09490 it is two bytes of data*/ 09491 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 09492 (p_bno055->dev_addr, 09493 BNO055_ACCEL_RADIUS_LSB_REG, 09494 data_u8, 09495 BNO055_LSB_MSB_READ_LENGTH); 09496 /* Array holding the accel radius values 09497 data_u8[BNO055_OFFSET_RADIUS_LSB] - radius->LSB 09498 data_u8[BNO055_OFFSET_RADIUS_MSB] - radius->MSB 09499 */ 09500 if (com_rslt == BNO055_SUCCESS) { 09501 data_u8[BNO055_OFFSET_RADIUS_LSB] = 09502 BNO055_GET_BITSLICE( 09503 data_u8[BNO055_OFFSET_RADIUS_LSB], 09504 BNO055_ACCEL_RADIUS_LSB); 09505 data_u8[BNO055_OFFSET_RADIUS_MSB] = 09506 BNO055_GET_BITSLICE( 09507 data_u8[BNO055_OFFSET_RADIUS_MSB], 09508 BNO055_ACCEL_RADIUS_MSB); 09509 accel_offset->r = (s16)((((s32)(s8) 09510 (data_u8[BNO055_OFFSET_RADIUS_MSB])) << 09511 (BNO055_SHIFT_EIGHT_BITS)) | 09512 (data_u8[BNO055_OFFSET_RADIUS_LSB])); 09513 } else { 09514 com_rslt = BNO055_ERROR; 09515 } 09516 } else { 09517 com_rslt = BNO055_ERROR; 09518 } 09519 } else { 09520 com_rslt = BNO055_ERROR; 09521 } 09522 } 09523 return com_rslt; 09524 } 09525 /*! 09526 * @brief This API is used to write accel offset and accel radius 09527 * offset form register 0x55 to 0x5A and radius form 0x67 and 0x68 09528 * 09529 * @param accel_offset : The value of accel offset and radius 09530 * 09531 * bno055_accel_offset_t | result 09532 * ------------------- | ---------------- 09533 * x | accel offset x 09534 * y | accel offset y 09535 * z | accel offset z 09536 * r | accel offset r 09537 * 09538 * 09539 * @return results of bus communication function 09540 * @retval 0 -> BNO055_SUCCESS 09541 * @retval 1 -> BNO055_ERROR 09542 * 09543 * @note The range of the accel offset varies based on 09544 * the G-range of accel sensor. 09545 * 09546 * accel G range | offset range 09547 * --------------- | -------------- 09548 * BNO055_ACCEL_RANGE_2G | +/-2000 09549 * BNO055_ACCEL_RANGE_4G | +/-4000 09550 * BNO055_ACCEL_RANGE_8G | +/-8000 09551 * BNO055_ACCEL_RANGE_16G | +/-16000 09552 * 09553 * accel G range can be configured by using the 09554 * bno055_set_accel_range() API 09555 */ 09556 BNO055_RETURN_FUNCTION_TYPE bno055_write_accel_offset( 09557 struct bno055_accel_offset_t *accel_offset) 09558 { 09559 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 09560 u8 data1_u8r = BNO055_INIT_VALUE; 09561 u8 data2_u8r = BNO055_INIT_VALUE; 09562 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 09563 s8 stat_s8 = BNO055_ERROR; 09564 /* Check the struct p_bno055 is empty */ 09565 if (p_bno055 == BNO055_INIT_VALUE) { 09566 return BNO055_E_NULL_PTR; 09567 } else { 09568 /* The write operation effective only if the operation 09569 mode is in config mode, this part of code is checking the 09570 current operation mode and set the config mode */ 09571 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 09572 if (stat_s8 == BNO055_SUCCESS) { 09573 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 09574 stat_s8 += bno055_set_operation_mode 09575 (BNO055_OPERATION_MODE_CONFIG); 09576 if (stat_s8 == BNO055_SUCCESS) { 09577 /* write accel offset x value*/ 09578 com_rslt = 09579 p_bno055->BNO055_BUS_READ_FUNC 09580 (p_bno055->dev_addr, 09581 BNO055_ACCEL_OFFSET_X_LSB_REG, 09582 &data2_u8r, 09583 BNO055_GEN_READ_WRITE_LENGTH); 09584 if (com_rslt == BNO055_SUCCESS) { 09585 data1_u8r = ((s8) 09586 (accel_offset->x 09587 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09588 data2_u8r = 09589 BNO055_SET_BITSLICE(data2_u8r, 09590 BNO055_ACCEL_OFFSET_X_LSB, 09591 data1_u8r); 09592 com_rslt += 09593 p_bno055->BNO055_BUS_WRITE_FUNC 09594 (p_bno055->dev_addr, 09595 BNO055_ACCEL_OFFSET_X_LSB_REG, 09596 &data2_u8r, 09597 BNO055_GEN_READ_WRITE_LENGTH); 09598 } 09599 09600 com_rslt += 09601 p_bno055->BNO055_BUS_READ_FUNC 09602 (p_bno055->dev_addr, 09603 BNO055_ACCEL_OFFSET_X_MSB_REG, 09604 &data2_u8r, 09605 BNO055_GEN_READ_WRITE_LENGTH); 09606 if (com_rslt == BNO055_SUCCESS) { 09607 data1_u8r = ((s8) 09608 (accel_offset->x >> 09609 BNO055_SHIFT_EIGHT_BITS) 09610 & BNO055_SIC_HEX_0_0_F_F_DATA); 09611 data2_u8r = 09612 BNO055_SET_BITSLICE(data2_u8r, 09613 BNO055_ACCEL_OFFSET_X_MSB, 09614 data1_u8r); 09615 com_rslt += 09616 p_bno055->BNO055_BUS_WRITE_FUNC 09617 (p_bno055->dev_addr, 09618 BNO055_ACCEL_OFFSET_X_MSB_REG, 09619 &data2_u8r, 09620 BNO055_GEN_READ_WRITE_LENGTH); 09621 } 09622 09623 /* write accel offset y value*/ 09624 com_rslt += 09625 p_bno055->BNO055_BUS_READ_FUNC 09626 (p_bno055->dev_addr, 09627 BNO055_ACCEL_OFFSET_Y_LSB_REG, 09628 &data2_u8r, 09629 BNO055_GEN_READ_WRITE_LENGTH); 09630 if (com_rslt == BNO055_SUCCESS) { 09631 data1_u8r = ((s8) 09632 (accel_offset->y 09633 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09634 data2_u8r = 09635 BNO055_SET_BITSLICE(data2_u8r, 09636 BNO055_ACCEL_OFFSET_Y_LSB, 09637 data1_u8r); 09638 com_rslt += 09639 p_bno055->BNO055_BUS_WRITE_FUNC 09640 (p_bno055->dev_addr, 09641 BNO055_ACCEL_OFFSET_Y_LSB_REG, 09642 &data2_u8r, 09643 BNO055_GEN_READ_WRITE_LENGTH); 09644 } 09645 09646 com_rslt += 09647 p_bno055->BNO055_BUS_READ_FUNC 09648 (p_bno055->dev_addr, 09649 BNO055_ACCEL_OFFSET_Y_MSB_REG, 09650 &data2_u8r, 09651 BNO055_GEN_READ_WRITE_LENGTH); 09652 if (com_rslt == BNO055_SUCCESS) { 09653 data1_u8r = ((s8) 09654 (accel_offset->y >> 09655 BNO055_SHIFT_EIGHT_BITS) 09656 & BNO055_SIC_HEX_0_0_F_F_DATA); 09657 data2_u8r = 09658 BNO055_SET_BITSLICE(data2_u8r, 09659 BNO055_ACCEL_OFFSET_Y_MSB, 09660 data1_u8r); 09661 com_rslt += 09662 p_bno055->BNO055_BUS_WRITE_FUNC 09663 (p_bno055->dev_addr, 09664 BNO055_ACCEL_OFFSET_Y_MSB_REG, 09665 &data2_u8r, 09666 BNO055_GEN_READ_WRITE_LENGTH); 09667 } 09668 /* write accel offset z value*/ 09669 com_rslt += 09670 p_bno055->BNO055_BUS_READ_FUNC 09671 (p_bno055->dev_addr, 09672 BNO055_ACCEL_OFFSET_Z_LSB_REG, 09673 &data2_u8r, 09674 BNO055_GEN_READ_WRITE_LENGTH); 09675 if (com_rslt == BNO055_SUCCESS) { 09676 data1_u8r = ((s8) 09677 (accel_offset->z 09678 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09679 data2_u8r = 09680 BNO055_SET_BITSLICE(data2_u8r, 09681 BNO055_ACCEL_OFFSET_Z_LSB, 09682 data1_u8r); 09683 com_rslt += 09684 p_bno055->BNO055_BUS_WRITE_FUNC 09685 (p_bno055->dev_addr, 09686 BNO055_ACCEL_OFFSET_Z_LSB_REG, 09687 &data2_u8r, 09688 BNO055_GEN_READ_WRITE_LENGTH); 09689 } 09690 09691 com_rslt += 09692 p_bno055->BNO055_BUS_READ_FUNC 09693 (p_bno055->dev_addr, 09694 BNO055_ACCEL_OFFSET_Z_MSB_REG, 09695 &data2_u8r, 09696 BNO055_GEN_READ_WRITE_LENGTH); 09697 if (com_rslt == BNO055_SUCCESS) { 09698 data1_u8r = ((s8) 09699 (accel_offset->z >> 09700 BNO055_SHIFT_EIGHT_BITS) 09701 & BNO055_SIC_HEX_0_0_F_F_DATA); 09702 data2_u8r = 09703 BNO055_SET_BITSLICE(data2_u8r, 09704 BNO055_ACCEL_OFFSET_Z_MSB, 09705 data1_u8r); 09706 com_rslt += 09707 p_bno055->BNO055_BUS_WRITE_FUNC 09708 (p_bno055->dev_addr, 09709 BNO055_ACCEL_OFFSET_Z_MSB_REG, 09710 &data2_u8r, 09711 BNO055_GEN_READ_WRITE_LENGTH); 09712 } 09713 09714 /*write accel radius value*/ 09715 com_rslt += 09716 p_bno055->BNO055_BUS_READ_FUNC 09717 (p_bno055->dev_addr, 09718 BNO055_ACCEL_RADIUS_LSB_REG, 09719 &data2_u8r, 09720 BNO055_GEN_READ_WRITE_LENGTH); 09721 if (com_rslt == BNO055_SUCCESS) { 09722 data1_u8r = ((s8) 09723 (accel_offset->r 09724 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09725 data2_u8r = 09726 BNO055_SET_BITSLICE(data2_u8r, 09727 BNO055_ACCEL_RADIUS_LSB, 09728 data1_u8r); 09729 com_rslt = 09730 p_bno055->BNO055_BUS_WRITE_FUNC 09731 (p_bno055->dev_addr, 09732 BNO055_ACCEL_RADIUS_LSB_REG, 09733 &data2_u8r, 09734 BNO055_GEN_READ_WRITE_LENGTH); 09735 } 09736 09737 com_rslt += 09738 p_bno055->BNO055_BUS_READ_FUNC 09739 (p_bno055->dev_addr, 09740 BNO055_ACCEL_RADIUS_MSB_REG, 09741 &data2_u8r, 09742 BNO055_GEN_READ_WRITE_LENGTH); 09743 if (com_rslt == BNO055_SUCCESS) { 09744 data1_u8r = ((s8) 09745 (accel_offset->r >> 09746 BNO055_SHIFT_EIGHT_BITS) 09747 & BNO055_SIC_HEX_0_0_F_F_DATA); 09748 data2_u8r = 09749 BNO055_SET_BITSLICE(data2_u8r, 09750 BNO055_ACCEL_RADIUS_MSB, 09751 data1_u8r); 09752 com_rslt = 09753 p_bno055->BNO055_BUS_WRITE_FUNC 09754 (p_bno055->dev_addr, 09755 BNO055_ACCEL_RADIUS_MSB_REG, 09756 &data2_u8r, 09757 BNO055_GEN_READ_WRITE_LENGTH); 09758 } 09759 } else { 09760 com_rslt = BNO055_ERROR; 09761 } 09762 } else { 09763 com_rslt = BNO055_ERROR; 09764 } 09765 } 09766 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 09767 /* set the operation mode 09768 of previous operation mode*/ 09769 com_rslt += bno055_set_operation_mode 09770 (prev_opmode_u8); 09771 return com_rslt; 09772 } 09773 09774 /*! 09775 * @brief This API is used to read mag offset 09776 * offset form register 0x69 to 0x6A 09777 * 09778 * @param mag_offset : The value of mag offset and radius 09779 * 09780 * bno055_mag_offset_t | result 09781 * ------------------- | ---------------- 09782 * x | mag offset x 09783 * y | mag offset y 09784 * z | mag offset z 09785 * r | mag radius r 09786 * 09787 * 09788 * @return results of bus communication function 09789 * @retval 0 -> BNO055_SUCCESS 09790 * @retval 1 -> BNO055_ERROR 09791 * 09792 * @note The range of the magnetometer offset is +/-6400 in LSB 09793 */ 09794 09795 BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_offset( 09796 struct bno055_mag_offset_t *mag_offset) 09797 { 09798 /* Variable used to return value of 09799 communication routine*/ 09800 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 09801 /* Array holding the mag offset values 09802 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB] - offset x->LSB 09803 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB] - offset x->MSB 09804 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB] - offset y->LSB 09805 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB] - offset y->MSB 09806 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB] - offset z->LSB 09807 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB] - offset z->MSB 09808 */ 09809 u8 data_u8[BNO055_MAG_OFFSET_ARRAY] = { 09810 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 09811 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 09812 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 09813 s8 stat_s8 = BNO055_ERROR; 09814 /* Check the struct p_bno055 is empty */ 09815 if (p_bno055 == BNO055_INIT_VALUE) { 09816 return BNO055_E_NULL_PTR; 09817 } else { 09818 /*condition check for page, mag offset is 09819 available in the page zero*/ 09820 if (p_bno055->page_id != BNO055_PAGE_ZERO) 09821 /* Write the page zero*/ 09822 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 09823 if ((stat_s8 == BNO055_SUCCESS) || 09824 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 09825 /* Read mag offset value it the six bytes of data */ 09826 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 09827 (p_bno055->dev_addr, 09828 BNO055_MAG_OFFSET_X_LSB_REG, 09829 data_u8, BNO055_MAG_OFFSET_ARRAY); 09830 if (com_rslt == BNO055_SUCCESS) { 09831 /* Read mag x offset value*/ 09832 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB] = 09833 BNO055_GET_BITSLICE( 09834 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB], 09835 BNO055_MAG_OFFSET_X_LSB); 09836 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB] = 09837 BNO055_GET_BITSLICE( 09838 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB], 09839 BNO055_MAG_OFFSET_X_MSB); 09840 mag_offset->x = (s16)((((s32)(s8) 09841 (data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB])) << 09842 (BNO055_SHIFT_EIGHT_BITS)) | 09843 (data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB])); 09844 09845 /* Read mag y offset value*/ 09846 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB] = 09847 BNO055_GET_BITSLICE( 09848 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB], 09849 BNO055_MAG_OFFSET_Y_LSB); 09850 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB] = 09851 BNO055_GET_BITSLICE( 09852 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB], 09853 BNO055_MAG_OFFSET_Y_MSB); 09854 mag_offset->y = (s16)((((s32)(s8) 09855 (data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB])) << 09856 (BNO055_SHIFT_EIGHT_BITS)) 09857 | (data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB])); 09858 09859 /* Read mag z offset value*/ 09860 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB] = 09861 BNO055_GET_BITSLICE( 09862 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB], 09863 BNO055_MAG_OFFSET_Z_LSB); 09864 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB] = 09865 BNO055_GET_BITSLICE( 09866 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB], 09867 BNO055_MAG_OFFSET_Z_MSB); 09868 mag_offset->z = (s16)((((s32)(s8) 09869 (data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB])) << 09870 (BNO055_SHIFT_EIGHT_BITS)) 09871 | (data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB])); 09872 09873 /* Read mag radius value 09874 it the two bytes of data */ 09875 com_rslt += p_bno055->BNO055_BUS_READ_FUNC 09876 (p_bno055->dev_addr, 09877 BNO055_MAG_RADIUS_LSB_REG, 09878 data_u8, 09879 BNO055_LSB_MSB_READ_LENGTH); 09880 if (com_rslt == BNO055_SUCCESS) { 09881 /* Array holding the mag radius values 09882 data_u8[BNO055_OFFSET_RADIUS_LSB] - 09883 radius->LSB 09884 data_u8[BNO055_OFFSET_RADIUS_MSB] - 09885 radius->MSB 09886 */ 09887 data_u8[BNO055_OFFSET_RADIUS_LSB] = 09888 BNO055_GET_BITSLICE( 09889 data_u8[BNO055_OFFSET_RADIUS_LSB], 09890 BNO055_MAG_RADIUS_LSB); 09891 data_u8[BNO055_OFFSET_RADIUS_MSB] = 09892 BNO055_GET_BITSLICE( 09893 data_u8[BNO055_OFFSET_RADIUS_MSB], 09894 BNO055_MAG_RADIUS_MSB); 09895 mag_offset->r = (s16)((((s32)(s8) 09896 (data_u8[BNO055_OFFSET_RADIUS_MSB])) << 09897 (BNO055_SHIFT_EIGHT_BITS)) | 09898 (data_u8[BNO055_OFFSET_RADIUS_LSB])); 09899 } else { 09900 com_rslt = BNO055_ERROR; 09901 } 09902 } else { 09903 com_rslt = BNO055_ERROR; 09904 } 09905 } else { 09906 com_rslt = BNO055_ERROR; 09907 } 09908 } 09909 return com_rslt; 09910 } 09911 09912 /*! 09913 * @brief This API is used to read mag offset 09914 * offset form register 0x69 to 0x6A 09915 * 09916 * @param mag_offset : The value of mag offset and radius 09917 * 09918 * bno055_mag_offset_t | result 09919 * ------------------- | ---------------- 09920 * x | mag offset x 09921 * y | mag offset y 09922 * z | mag offset z 09923 * r | mag radius r 09924 * 09925 * 09926 * @return results of bus communication function 09927 * @retval 0 -> BNO055_SUCCESS 09928 * @retval 1 -> BNO055_ERROR 09929 * 09930 * @note The range of the magnetometer offset is +/-6400 in LSB 09931 */ 09932 BNO055_RETURN_FUNCTION_TYPE bno055_write_mag_offset( 09933 struct bno055_mag_offset_t *mag_offset) 09934 { 09935 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 09936 u8 data1_u8r = BNO055_INIT_VALUE; 09937 u8 data2_u8r = BNO055_INIT_VALUE; 09938 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 09939 s8 stat_s8 = BNO055_ERROR; 09940 /* Check the struct p_bno055 is empty */ 09941 if (p_bno055 == BNO055_INIT_VALUE) { 09942 return BNO055_E_NULL_PTR; 09943 } else { 09944 /* The write operation effective only if the operation 09945 mode is in config mode, this part of code is checking the 09946 current operation mode and set the config mode */ 09947 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 09948 if (stat_s8 == BNO055_SUCCESS) { 09949 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 09950 stat_s8 += bno055_set_operation_mode 09951 (BNO055_OPERATION_MODE_CONFIG); 09952 if (stat_s8 == BNO055_SUCCESS) { 09953 /* write Mag offset x value*/ 09954 com_rslt = 09955 p_bno055->BNO055_BUS_READ_FUNC 09956 (p_bno055->dev_addr, 09957 BNO055_MAG_OFFSET_X_LSB_REG, 09958 &data2_u8r, 09959 BNO055_GEN_READ_WRITE_LENGTH); 09960 if (com_rslt == BNO055_SUCCESS) { 09961 data1_u8r = ((s8) 09962 (mag_offset->x 09963 & BNO055_SIC_HEX_0_0_F_F_DATA)); 09964 data2_u8r = 09965 BNO055_SET_BITSLICE(data2_u8r, 09966 BNO055_MAG_OFFSET_X_LSB, 09967 data1_u8r); 09968 com_rslt += 09969 p_bno055->BNO055_BUS_WRITE_FUNC 09970 (p_bno055->dev_addr, 09971 BNO055_MAG_OFFSET_X_LSB_REG, 09972 &data2_u8r, 09973 BNO055_GEN_READ_WRITE_LENGTH); 09974 } 09975 09976 com_rslt += 09977 p_bno055->BNO055_BUS_READ_FUNC 09978 (p_bno055->dev_addr, 09979 BNO055_MAG_OFFSET_X_MSB_REG, 09980 &data2_u8r, 09981 BNO055_GEN_READ_WRITE_LENGTH); 09982 if (com_rslt == BNO055_SUCCESS) { 09983 data1_u8r = ((s8) 09984 (mag_offset->x >> 09985 BNO055_SHIFT_EIGHT_BITS) 09986 & BNO055_SIC_HEX_0_0_F_F_DATA); 09987 data2_u8r = 09988 BNO055_SET_BITSLICE(data2_u8r, 09989 BNO055_MAG_OFFSET_X_MSB, 09990 data1_u8r); 09991 com_rslt += 09992 p_bno055->BNO055_BUS_WRITE_FUNC 09993 (p_bno055->dev_addr, 09994 BNO055_MAG_OFFSET_X_MSB_REG, 09995 &data2_u8r, 09996 BNO055_GEN_READ_WRITE_LENGTH); 09997 } 09998 09999 /* write Mag offset y value*/ 10000 com_rslt += 10001 p_bno055->BNO055_BUS_READ_FUNC 10002 (p_bno055->dev_addr, 10003 BNO055_MAG_OFFSET_Y_LSB_REG, 10004 &data2_u8r, 10005 BNO055_GEN_READ_WRITE_LENGTH); 10006 if (com_rslt == BNO055_SUCCESS) { 10007 data1_u8r = ((s8) 10008 (mag_offset->y & 10009 BNO055_SIC_HEX_0_0_F_F_DATA)); 10010 data2_u8r = 10011 BNO055_SET_BITSLICE(data2_u8r, 10012 BNO055_MAG_OFFSET_Y_LSB, 10013 data1_u8r); 10014 com_rslt += 10015 p_bno055->BNO055_BUS_WRITE_FUNC 10016 (p_bno055->dev_addr, 10017 BNO055_MAG_OFFSET_Y_LSB_REG, 10018 &data2_u8r, 10019 BNO055_GEN_READ_WRITE_LENGTH); 10020 } 10021 10022 com_rslt += 10023 p_bno055->BNO055_BUS_READ_FUNC 10024 (p_bno055->dev_addr, 10025 BNO055_MAG_OFFSET_Y_MSB_REG, 10026 &data2_u8r, 10027 BNO055_GEN_READ_WRITE_LENGTH); 10028 if (com_rslt == BNO055_SUCCESS) { 10029 data1_u8r = ((s8) 10030 (mag_offset->y >> 10031 BNO055_SHIFT_EIGHT_BITS) 10032 & BNO055_SIC_HEX_0_0_F_F_DATA); 10033 data2_u8r = 10034 BNO055_SET_BITSLICE(data2_u8r, 10035 BNO055_MAG_OFFSET_Y_MSB, 10036 data1_u8r); 10037 com_rslt += 10038 p_bno055->BNO055_BUS_WRITE_FUNC 10039 (p_bno055->dev_addr, 10040 BNO055_MAG_OFFSET_Y_MSB_REG, 10041 &data2_u8r, 10042 BNO055_GEN_READ_WRITE_LENGTH); 10043 } 10044 /* write Mag offset z value*/ 10045 com_rslt += 10046 p_bno055->BNO055_BUS_READ_FUNC 10047 (p_bno055->dev_addr, 10048 BNO055_MAG_OFFSET_Z_LSB_REG, 10049 &data2_u8r, 10050 BNO055_GEN_READ_WRITE_LENGTH); 10051 if (com_rslt == BNO055_SUCCESS) { 10052 data1_u8r = ((s8) 10053 (mag_offset->z & 10054 BNO055_SIC_HEX_0_0_F_F_DATA)); 10055 data2_u8r = 10056 BNO055_SET_BITSLICE(data2_u8r, 10057 BNO055_MAG_OFFSET_Z_LSB, 10058 data1_u8r); 10059 com_rslt += 10060 p_bno055->BNO055_BUS_WRITE_FUNC 10061 (p_bno055->dev_addr, 10062 BNO055_MAG_OFFSET_Z_LSB_REG, 10063 &data2_u8r, 10064 BNO055_GEN_READ_WRITE_LENGTH); 10065 } 10066 10067 com_rslt += 10068 p_bno055->BNO055_BUS_READ_FUNC 10069 (p_bno055->dev_addr, 10070 BNO055_MAG_OFFSET_Z_MSB_REG, 10071 &data2_u8r, 10072 BNO055_GEN_READ_WRITE_LENGTH); 10073 if (com_rslt == BNO055_SUCCESS) { 10074 data1_u8r = ((s8) 10075 (mag_offset->z >> 10076 BNO055_SHIFT_EIGHT_BITS) 10077 & BNO055_SIC_HEX_0_0_F_F_DATA); 10078 data2_u8r = 10079 BNO055_SET_BITSLICE(data2_u8r, 10080 BNO055_MAG_OFFSET_Z_MSB, 10081 data1_u8r); 10082 com_rslt += 10083 p_bno055->BNO055_BUS_WRITE_FUNC 10084 (p_bno055->dev_addr, 10085 BNO055_MAG_OFFSET_Z_MSB_REG, 10086 &data2_u8r, 10087 BNO055_GEN_READ_WRITE_LENGTH); 10088 } 10089 10090 /* write Mag radius value*/ 10091 com_rslt += 10092 p_bno055->BNO055_BUS_READ_FUNC 10093 (p_bno055->dev_addr, 10094 BNO055_MAG_RADIUS_LSB_REG, 10095 &data2_u8r, 10096 BNO055_GEN_READ_WRITE_LENGTH); 10097 if (com_rslt == BNO055_SUCCESS) { 10098 data1_u8r = ((s8) 10099 (mag_offset->r & 10100 BNO055_SIC_HEX_0_0_F_F_DATA)); 10101 data2_u8r = 10102 BNO055_SET_BITSLICE(data2_u8r, 10103 BNO055_MAG_RADIUS_LSB, 10104 data1_u8r); 10105 com_rslt += 10106 p_bno055->BNO055_BUS_WRITE_FUNC 10107 (p_bno055->dev_addr, 10108 BNO055_MAG_RADIUS_LSB_REG, 10109 &data2_u8r, 10110 BNO055_GEN_READ_WRITE_LENGTH); 10111 } 10112 10113 com_rslt += 10114 p_bno055->BNO055_BUS_READ_FUNC 10115 (p_bno055->dev_addr, 10116 BNO055_MAG_RADIUS_MSB_REG, 10117 &data2_u8r, 10118 BNO055_GEN_READ_WRITE_LENGTH); 10119 if (com_rslt == BNO055_SUCCESS) { 10120 data1_u8r = ((s8) 10121 (mag_offset->r >> 10122 BNO055_SHIFT_EIGHT_BITS) 10123 & BNO055_SIC_HEX_0_0_F_F_DATA); 10124 data2_u8r = 10125 BNO055_SET_BITSLICE(data2_u8r, 10126 BNO055_MAG_RADIUS_MSB, 10127 data1_u8r); 10128 com_rslt += 10129 p_bno055->BNO055_BUS_WRITE_FUNC 10130 (p_bno055->dev_addr, 10131 BNO055_MAG_RADIUS_MSB_REG, 10132 &data2_u8r, 10133 BNO055_GEN_READ_WRITE_LENGTH); 10134 } 10135 } else { 10136 com_rslt = BNO055_ERROR; 10137 } 10138 } else { 10139 com_rslt = BNO055_ERROR; 10140 } 10141 } 10142 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10143 /* set the operation mode 10144 of previous operation mode*/ 10145 com_rslt += bno055_set_operation_mode 10146 (prev_opmode_u8); 10147 return com_rslt; 10148 } 10149 /*! 10150 * @brief This API is used to read gyro offset 10151 * offset form register 0x61 to 0x66 10152 * 10153 * @param gyro_offset : The value of gyro offset 10154 * 10155 * bno055_gyro_offset_t | result 10156 * ------------------- | ---------------- 10157 * x | gyro offset x 10158 * y | gyro offset y 10159 * z | gyro offset z 10160 * 10161 * 10162 * @return results of bus communication function 10163 * @retval 0 -> BNO055_SUCCESS 10164 * @retval 1 -> BNO055_ERROR 10165 * 10166 * @note The range of the gyro offset varies based on 10167 * the range of gyro sensor 10168 * 10169 * gyro G range | offset range 10170 * -------------------- | ------------ 10171 * BNO055_GYRO_RANGE_2000DPS | +/-32000 10172 * BNO055_GYRO_RANGE_1000DPS | +/-16000 10173 * BNO055_GYRO_RANGE_500DPS | +/-8000 10174 * BNO055_GYRO_RANGE_250DPS | +/-4000 10175 * BNO055_GYRO_RANGE_125DPS | +/-2000 10176 * 10177 * Gyro range can be configured by using the 10178 * bno055_set_gyro_range() API 10179 */ 10180 BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_offset( 10181 struct bno055_gyro_offset_t *gyro_offset) 10182 { 10183 /* Variable used to return value of 10184 communication routine*/ 10185 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10186 /* Array holding the gyro offset values 10187 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB] - offset x->LSB 10188 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB] - offset x->MSB 10189 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB] - offset y->LSB 10190 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB] - offset y->MSB 10191 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB] - offset z->LSB 10192 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB] - offset z->MSB 10193 */ 10194 u8 data_u8[BNO055_GYRO_OFFSET_ARRAY] = { 10195 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 10196 BNO055_INIT_VALUE, BNO055_INIT_VALUE, 10197 BNO055_INIT_VALUE, BNO055_INIT_VALUE}; 10198 s8 stat_s8 = BNO055_ERROR; 10199 /* Check the struct p_bno055 is empty */ 10200 if (p_bno055 == BNO055_INIT_VALUE) { 10201 return BNO055_E_NULL_PTR; 10202 } else { 10203 /*condition check for page, gyro offset is 10204 available in the page zero*/ 10205 if (p_bno055->page_id != BNO055_PAGE_ZERO) 10206 /* Write the page zero*/ 10207 stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO); 10208 if ((stat_s8 == BNO055_SUCCESS) || 10209 (p_bno055->page_id == BNO055_PAGE_ZERO)) { 10210 /* Read gyro offset value it the six bytes of data*/ 10211 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 10212 (p_bno055->dev_addr, 10213 BNO055_GYRO_OFFSET_X_LSB_REG, 10214 data_u8, BNO055_GYRO_OFFSET_ARRAY); 10215 if (com_rslt == BNO055_SUCCESS) { 10216 /* Read gyro x offset value*/ 10217 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB] = 10218 BNO055_GET_BITSLICE( 10219 data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB], 10220 BNO055_GYRO_OFFSET_X_LSB); 10221 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB] = 10222 BNO055_GET_BITSLICE( 10223 data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB], 10224 BNO055_GYRO_OFFSET_X_MSB); 10225 gyro_offset->x = (s16)((((s32)(s8) 10226 (data_u8[BNO055_SENSOR_OFFSET_DATA_X_MSB])) << 10227 (BNO055_SHIFT_EIGHT_BITS)) | 10228 (data_u8[BNO055_SENSOR_OFFSET_DATA_X_LSB])); 10229 10230 /* Read gyro y offset value*/ 10231 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB] = 10232 BNO055_GET_BITSLICE( 10233 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB], 10234 BNO055_GYRO_OFFSET_Y_LSB); 10235 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB] = 10236 BNO055_GET_BITSLICE( 10237 data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB], 10238 BNO055_GYRO_OFFSET_Y_MSB); 10239 gyro_offset->y = (s16)((((s32)(s8) 10240 (data_u8[BNO055_SENSOR_OFFSET_DATA_Y_MSB])) << 10241 (BNO055_SHIFT_EIGHT_BITS)) | 10242 (data_u8[BNO055_SENSOR_OFFSET_DATA_Y_LSB])); 10243 10244 /* Read gyro z offset value*/ 10245 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB] = 10246 BNO055_GET_BITSLICE( 10247 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB], 10248 BNO055_GYRO_OFFSET_Z_LSB); 10249 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB] = 10250 BNO055_GET_BITSLICE( 10251 data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB], 10252 BNO055_GYRO_OFFSET_Z_MSB); 10253 gyro_offset->z = (s16)((((s32)(s8) 10254 (data_u8[BNO055_SENSOR_OFFSET_DATA_Z_MSB])) << 10255 (BNO055_SHIFT_EIGHT_BITS)) | 10256 (data_u8[BNO055_SENSOR_OFFSET_DATA_Z_LSB])); 10257 } else { 10258 com_rslt = BNO055_ERROR; 10259 } 10260 } else { 10261 com_rslt = BNO055_ERROR; 10262 } 10263 } 10264 return com_rslt; 10265 } 10266 /*! 10267 * @brief This API is used to read gyro offset 10268 * offset form register 0x61 to 0x66 10269 * 10270 * @param gyro_offset : The value of gyro offset 10271 * 10272 * bno055_gyro_offset_t | result 10273 * ------------------- | ---------------- 10274 * x | gyro offset x 10275 * y | gyro offset y 10276 * z | gyro offset z 10277 * 10278 * 10279 * @return results of bus communication function 10280 * @retval 0 -> BNO055_SUCCESS 10281 * @retval 1 -> BNO055_ERROR 10282 * 10283 * @note The range of the gyro offset varies based on 10284 * the range of gyro sensor 10285 * 10286 * gyro G range | offset range 10287 * -------------------- | ------------ 10288 * BNO055_GYRO_RANGE_2000DPS | +/-32000 10289 * BNO055_GYRO_RANGE_1000DPS | +/-16000 10290 * BNO055_GYRO_RANGE_500DPS | +/-8000 10291 * BNO055_GYRO_RANGE_250DPS | +/-4000 10292 * BNO055_GYRO_RANGE_125DPS | +/-2000 10293 * 10294 * Gyro range can be configured by using the 10295 * bno055_set_gyro_range() API 10296 */ 10297 BNO055_RETURN_FUNCTION_TYPE bno055_write_gyro_offset( 10298 struct bno055_gyro_offset_t *gyro_offset) 10299 { 10300 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10301 u8 data1_u8r = BNO055_INIT_VALUE; 10302 u8 data2_u8r = BNO055_INIT_VALUE; 10303 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 10304 s8 stat_s8 = BNO055_ERROR; 10305 /* Check the struct p_bno055 is empty */ 10306 if (p_bno055 == BNO055_INIT_VALUE) { 10307 return BNO055_E_NULL_PTR; 10308 } else { 10309 /* The write operation effective only if the operation 10310 mode is in config mode, this part of code is checking the 10311 current operation mode and set the config mode */ 10312 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 10313 if (stat_s8 == BNO055_SUCCESS) { 10314 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10315 stat_s8 += bno055_set_operation_mode 10316 (BNO055_OPERATION_MODE_CONFIG); 10317 if (stat_s8 == BNO055_SUCCESS) { 10318 /* write gryo offset x value*/ 10319 com_rslt = 10320 p_bno055->BNO055_BUS_READ_FUNC 10321 (p_bno055->dev_addr, 10322 BNO055_GYRO_OFFSET_X_LSB_REG, 10323 &data2_u8r, 10324 BNO055_GEN_READ_WRITE_LENGTH); 10325 if (com_rslt == BNO055_SUCCESS) { 10326 data1_u8r = ((s8) 10327 (gyro_offset->x 10328 & BNO055_SIC_HEX_0_0_F_F_DATA)); 10329 data2_u8r = 10330 BNO055_SET_BITSLICE(data2_u8r, 10331 BNO055_GYRO_OFFSET_X_LSB, 10332 data1_u8r); 10333 com_rslt += 10334 p_bno055->BNO055_BUS_WRITE_FUNC 10335 (p_bno055->dev_addr, 10336 BNO055_GYRO_OFFSET_X_LSB_REG, 10337 &data2_u8r, 10338 BNO055_GEN_READ_WRITE_LENGTH); 10339 } 10340 10341 com_rslt += 10342 p_bno055->BNO055_BUS_READ_FUNC 10343 (p_bno055->dev_addr, 10344 BNO055_GYRO_OFFSET_X_MSB_REG, 10345 &data2_u8r, 10346 BNO055_GEN_READ_WRITE_LENGTH); 10347 if (com_rslt == BNO055_SUCCESS) { 10348 data1_u8r = ((s8) 10349 (gyro_offset->x >> 10350 BNO055_SHIFT_EIGHT_BITS) 10351 & BNO055_SIC_HEX_0_0_F_F_DATA); 10352 data2_u8r = 10353 BNO055_SET_BITSLICE(data2_u8r, 10354 BNO055_GYRO_OFFSET_X_MSB, 10355 data1_u8r); 10356 com_rslt += 10357 p_bno055->BNO055_BUS_WRITE_FUNC 10358 (p_bno055->dev_addr, 10359 BNO055_GYRO_OFFSET_X_MSB_REG, 10360 &data2_u8r, 10361 BNO055_GEN_READ_WRITE_LENGTH); 10362 } 10363 10364 /* write gryo offset y value*/ 10365 com_rslt += 10366 p_bno055->BNO055_BUS_READ_FUNC 10367 (p_bno055->dev_addr, 10368 BNO055_GYRO_OFFSET_Y_LSB_REG, 10369 &data2_u8r, 10370 BNO055_GEN_READ_WRITE_LENGTH); 10371 if (com_rslt == BNO055_SUCCESS) { 10372 data1_u8r = ((s8) 10373 (gyro_offset->y 10374 & BNO055_SIC_HEX_0_0_F_F_DATA)); 10375 data2_u8r = 10376 BNO055_SET_BITSLICE(data2_u8r, 10377 BNO055_GYRO_OFFSET_Y_LSB, 10378 data1_u8r); 10379 com_rslt += 10380 p_bno055->BNO055_BUS_WRITE_FUNC 10381 (p_bno055->dev_addr, 10382 BNO055_GYRO_OFFSET_Y_LSB_REG, 10383 &data2_u8r, 10384 BNO055_GEN_READ_WRITE_LENGTH); 10385 } 10386 10387 com_rslt += 10388 p_bno055->BNO055_BUS_READ_FUNC 10389 (p_bno055->dev_addr, 10390 BNO055_GYRO_OFFSET_Y_MSB_REG, 10391 &data2_u8r, 10392 BNO055_GEN_READ_WRITE_LENGTH); 10393 if (com_rslt == BNO055_SUCCESS) { 10394 data1_u8r = ((s8) 10395 (gyro_offset->y >> 10396 BNO055_SHIFT_EIGHT_BITS) 10397 & BNO055_SIC_HEX_0_0_F_F_DATA); 10398 data2_u8r = 10399 BNO055_SET_BITSLICE(data2_u8r, 10400 BNO055_GYRO_OFFSET_Y_MSB, 10401 data1_u8r); 10402 com_rslt += 10403 p_bno055->BNO055_BUS_WRITE_FUNC 10404 (p_bno055->dev_addr, 10405 BNO055_GYRO_OFFSET_Y_MSB_REG, 10406 &data2_u8r, 10407 BNO055_GEN_READ_WRITE_LENGTH); 10408 } 10409 /* write gryo offset z value*/ 10410 com_rslt += 10411 p_bno055->BNO055_BUS_READ_FUNC 10412 (p_bno055->dev_addr, 10413 BNO055_GYRO_OFFSET_Z_LSB_REG, 10414 &data2_u8r, 10415 BNO055_GEN_READ_WRITE_LENGTH); 10416 if (com_rslt == BNO055_SUCCESS) { 10417 data1_u8r = ((s8) 10418 (gyro_offset->z 10419 & BNO055_SIC_HEX_0_0_F_F_DATA)); 10420 data2_u8r = 10421 BNO055_SET_BITSLICE(data2_u8r, 10422 BNO055_GYRO_OFFSET_Z_LSB, 10423 data1_u8r); 10424 com_rslt += 10425 p_bno055->BNO055_BUS_WRITE_FUNC 10426 (p_bno055->dev_addr, 10427 BNO055_GYRO_OFFSET_Z_LSB_REG, 10428 &data2_u8r, 10429 BNO055_GEN_READ_WRITE_LENGTH); 10430 } 10431 10432 com_rslt += 10433 p_bno055->BNO055_BUS_READ_FUNC 10434 (p_bno055->dev_addr, 10435 BNO055_GYRO_OFFSET_Z_MSB_REG, 10436 &data2_u8r, 10437 BNO055_GEN_READ_WRITE_LENGTH); 10438 if (com_rslt == BNO055_SUCCESS) { 10439 data1_u8r = ((s8) 10440 (gyro_offset->z >> 10441 BNO055_SHIFT_EIGHT_BITS) 10442 & BNO055_SIC_HEX_0_0_F_F_DATA); 10443 data2_u8r = 10444 BNO055_SET_BITSLICE(data2_u8r, 10445 BNO055_GYRO_OFFSET_Z_MSB, 10446 data1_u8r); 10447 com_rslt += 10448 p_bno055->BNO055_BUS_WRITE_FUNC 10449 (p_bno055->dev_addr, 10450 BNO055_GYRO_OFFSET_Z_MSB_REG, 10451 &data2_u8r, 10452 BNO055_GEN_READ_WRITE_LENGTH); 10453 } 10454 } else { 10455 com_rslt = BNO055_ERROR; 10456 } 10457 } else { 10458 com_rslt = BNO055_ERROR; 10459 } 10460 } 10461 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10462 /* set the operation mode 10463 of previous operation mode*/ 10464 com_rslt += bno055_set_operation_mode 10465 (prev_opmode_u8); 10466 return com_rslt; 10467 } 10468 /********************************************************/ 10469 /************** PAGE1 Functions *********************/ 10470 /********************************************************/ 10471 /*! 10472 * @brief This API used to read the accel range 10473 * from page one register from 0x08 bit 0 and 1 10474 * 10475 * @param accel_range_u8 : The value of accel range 10476 * accel_range_u8 | result 10477 * ----------------- | -------------- 10478 * 0x00 | BNO055_ACCEL_RANGE_2G 10479 * 0x01 | BNO055_ACCEL_RANGE_4G 10480 * 0x02 | BNO055_ACCEL_RANGE_8G 10481 * 0x03 | BNO055_ACCEL_RANGE_16G 10482 * 10483 * @return results of bus communication function 10484 * @retval 0 -> BNO055_SUCCESS 10485 * @retval 1 -> BNO055_ERROR 10486 * 10487 * 10488 */ 10489 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_range( 10490 u8 *accel_range_u8) 10491 { 10492 /* Variable used to return value of 10493 communication routine*/ 10494 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10495 u8 data_u8r = BNO055_INIT_VALUE; 10496 s8 stat_s8 = BNO055_ERROR; 10497 /* Check the struct p_bno055 is empty */ 10498 if (p_bno055 == BNO055_INIT_VALUE) { 10499 return BNO055_E_NULL_PTR; 10500 } else { 10501 /*condition check for page, accel range is 10502 available in the page one*/ 10503 if (p_bno055->page_id != BNO055_PAGE_ONE) 10504 /* Write page as one */ 10505 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10506 if ((stat_s8 == BNO055_SUCCESS) || 10507 (p_bno055->page_id == BNO055_PAGE_ONE)) { 10508 /* Read the value of accel g range */ 10509 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 10510 (p_bno055->dev_addr, 10511 BNO055_ACCEL_RANGE_REG, 10512 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 10513 *accel_range_u8 = 10514 BNO055_GET_BITSLICE(data_u8r, 10515 BNO055_ACCEL_RANGE); 10516 } else { 10517 com_rslt = BNO055_ERROR; 10518 } 10519 } 10520 return com_rslt; 10521 } 10522 /*! 10523 * @brief This API used to write the accel range 10524 * from page one register from 0x08 bit 0 and 1 10525 * 10526 * @param accel_range_u8 : The value of accel range 10527 * 10528 * accel_range_u8 | result 10529 * ----------------- | -------------- 10530 * 0x00 | BNO055_ACCEL_RANGE_2G 10531 * 0x01 | BNO055_ACCEL_RANGE_4G 10532 * 0x02 | BNO055_ACCEL_RANGE_8G 10533 * 0x03 | BNO055_ACCEL_RANGE_16G 10534 * 10535 * @return results of bus communication function 10536 * @retval 0 -> BNO055_SUCCESS 10537 * @retval 1 -> BNO055_ERROR 10538 * 10539 * 10540 */ 10541 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_range( 10542 u8 accel_range_u8) 10543 { 10544 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10545 u8 data_u8r = BNO055_INIT_VALUE; 10546 s8 stat_s8 = BNO055_ERROR; 10547 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 10548 s8 pg_stat_s8 = BNO055_ERROR; 10549 /* Check the struct p_bno055 is empty */ 10550 if (p_bno055 == BNO055_INIT_VALUE) { 10551 return BNO055_E_NULL_PTR; 10552 } else { 10553 /* The write operation effective only if the operation 10554 mode is in config mode, this part of code is checking the 10555 current operation mode and set the config mode */ 10556 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 10557 if (stat_s8 == BNO055_SUCCESS) { 10558 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10559 stat_s8 += bno055_set_operation_mode 10560 (BNO055_OPERATION_MODE_CONFIG); 10561 if (stat_s8 == BNO055_SUCCESS) { 10562 /* Write page as one */ 10563 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10564 if (pg_stat_s8 == BNO055_SUCCESS) { 10565 if (accel_range_u8 < BNO055_ACCEL_RANGE) { 10566 /* Write the value of accel range*/ 10567 com_rslt = 10568 p_bno055->BNO055_BUS_READ_FUNC 10569 (p_bno055->dev_addr, 10570 BNO055_ACCEL_RANGE_REG, 10571 &data_u8r, 10572 BNO055_GEN_READ_WRITE_LENGTH); 10573 if (com_rslt == BNO055_SUCCESS) { 10574 data_u8r = BNO055_SET_BITSLICE 10575 (data_u8r, 10576 BNO055_ACCEL_RANGE, 10577 accel_range_u8); 10578 com_rslt += 10579 p_bno055->BNO055_BUS_WRITE_FUNC 10580 (p_bno055->dev_addr, 10581 BNO055_ACCEL_RANGE_REG, 10582 &data_u8r, 10583 BNO055_GEN_READ_WRITE_LENGTH); 10584 } 10585 } else { 10586 com_rslt = BNO055_OUT_OF_RANGE; 10587 } 10588 } else { 10589 com_rslt = BNO055_ERROR; 10590 } 10591 } else { 10592 com_rslt = BNO055_ERROR; 10593 } 10594 } else { 10595 com_rslt = BNO055_ERROR; 10596 } 10597 } 10598 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10599 /* set the operation mode of 10600 previous operation mode*/ 10601 com_rslt += bno055_set_operation_mode 10602 (prev_opmode_u8); 10603 return com_rslt; 10604 } 10605 /*! 10606 * @brief This API used to read the accel bandwidth 10607 * from page one register from 0x08 bit 2 to 4 10608 * 10609 * @param accel_bw_u8 : The value of accel bandwidth 10610 * 10611 * accel_bw_u8 | result 10612 * ----------------- | --------------- 10613 * 0x00 | BNO055_ACCEL_BW_7_81HZ 10614 * 0x01 | BNO055_ACCEL_BW_15_63HZ 10615 * 0x02 | BNO055_ACCEL_BW_31_25HZ 10616 * 0x03 | BNO055_ACCEL_BW_62_5HZ 10617 * 0x04 | BNO055_ACCEL_BW_125HZ 10618 * 0x05 | BNO055_ACCEL_BW_250HZ 10619 * 0x06 | BNO055_ACCEL_BW_500HZ 10620 * 0x07 | BNO055_ACCEL_BW_1000HZ 10621 * 10622 * @return results of bus communication function 10623 * @retval 0 -> BNO055_SUCCESS 10624 * @retval 1 -> BNO055_ERROR 10625 * 10626 * 10627 */ 10628 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_bw( 10629 u8 *accel_bw_u8) 10630 { 10631 /* Variable used to return value of 10632 communication routine*/ 10633 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10634 u8 data_u8r = BNO055_INIT_VALUE; 10635 s8 stat_s8 = BNO055_ERROR; 10636 /* Check the struct p_bno055 is empty */ 10637 if (p_bno055 == BNO055_INIT_VALUE) { 10638 return BNO055_E_NULL_PTR; 10639 } else { 10640 /*condition check for page, accel bandwidth is 10641 available in the page one*/ 10642 if (p_bno055->page_id != BNO055_PAGE_ONE) 10643 /* Write page as one */ 10644 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10645 if ((stat_s8 == BNO055_SUCCESS) || 10646 (p_bno055->page_id == BNO055_PAGE_ONE)) { 10647 /* Read the value of accel bandwidth */ 10648 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 10649 (p_bno055->dev_addr, 10650 BNO055_ACCEL_BW_REG, 10651 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 10652 *accel_bw_u8 = 10653 BNO055_GET_BITSLICE(data_u8r, 10654 BNO055_ACCEL_BW); 10655 } else { 10656 com_rslt = BNO055_ERROR; 10657 } 10658 } 10659 return com_rslt; 10660 } 10661 /*! 10662 * @brief This API used to write the accel bandwidth 10663 * from page one register from 0x08 bit 2 to 4 10664 * 10665 * @param accel_bw_u8 : The value of accel bandwidth 10666 * 10667 * accel_bw_u8 | result 10668 * ----------------- | --------------- 10669 * 0x00 | BNO055_ACCEL_BW_7_81HZ 10670 * 0x01 | BNO055_ACCEL_BW_15_63HZ 10671 * 0x02 | BNO055_ACCEL_BW_31_25HZ 10672 * 0x03 | BNO055_ACCEL_BW_62_5HZ 10673 * 0x04 | BNO055_ACCEL_BW_125HZ 10674 * 0x05 | BNO055_ACCEL_BW_250HZ 10675 * 0x06 | BNO055_ACCEL_BW_500HZ 10676 * 0x07 | BNO055_ACCEL_BW_1000HZ 10677 * 10678 * @return results of bus communication function 10679 * @retval 0 -> BNO055_SUCCESS 10680 * @retval 1 -> BNO055_ERROR 10681 * 10682 * 10683 */ 10684 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_bw( 10685 u8 accel_bw_u8) 10686 { 10687 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10688 u8 data_u8r = BNO055_INIT_VALUE; 10689 s8 stat_s8 = BNO055_ERROR; 10690 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 10691 s8 pg_stat_s8 = BNO055_ERROR; 10692 /* Check the struct p_bno055 is empty */ 10693 if (p_bno055 == BNO055_INIT_VALUE) { 10694 return BNO055_E_NULL_PTR; 10695 } else { 10696 /* The write operation effective only if the operation 10697 mode is in config mode, this part of code is checking the 10698 current operation mode and set the config mode */ 10699 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 10700 if (stat_s8 == BNO055_SUCCESS) { 10701 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10702 stat_s8 += bno055_set_operation_mode 10703 (BNO055_OPERATION_MODE_CONFIG); 10704 if (stat_s8 == BNO055_SUCCESS) { 10705 /* Write page as one */ 10706 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10707 if (pg_stat_s8 == BNO055_SUCCESS) { 10708 if (accel_bw_u8 < 10709 BNO055_ACCEL_GYRO_BW_RANGE) { 10710 /* Write the accel */ 10711 com_rslt = 10712 p_bno055->BNO055_BUS_READ_FUNC 10713 (p_bno055->dev_addr, 10714 BNO055_ACCEL_BW_REG, 10715 &data_u8r, 10716 BNO055_GEN_READ_WRITE_LENGTH); 10717 if (com_rslt == BNO055_SUCCESS) { 10718 data_u8r = BNO055_SET_BITSLICE 10719 (data_u8r, BNO055_ACCEL_BW, 10720 accel_bw_u8); 10721 com_rslt += 10722 p_bno055->BNO055_BUS_WRITE_FUNC 10723 (p_bno055->dev_addr, 10724 BNO055_ACCEL_BW_REG, 10725 &data_u8r, 10726 BNO055_GEN_READ_WRITE_LENGTH); 10727 } 10728 } else { 10729 com_rslt = BNO055_OUT_OF_RANGE; 10730 } 10731 } else { 10732 com_rslt = BNO055_ERROR; 10733 } 10734 } else { 10735 com_rslt = BNO055_ERROR; 10736 } 10737 } else { 10738 com_rslt = BNO055_ERROR; 10739 } 10740 } 10741 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10742 /* set the operation mode of 10743 previous operation mode*/ 10744 com_rslt += bno055_set_operation_mode 10745 (prev_opmode_u8); 10746 return com_rslt; 10747 } 10748 /*! 10749 * @brief This API used to read the accel power mode 10750 * from page one register from 0x08 bit 5 to 7 10751 * 10752 * @param accel_power_mode_u8 : The value of accel power mode 10753 * accel_power_mode_u8 | result 10754 * ----------------- | ------------- 10755 * 0x00 | BNO055_ACCEL_NORMAL 10756 * 0x01 | BNO055_ACCEL_SUSPEND 10757 * 0x02 | BNO055_ACCEL_LOWPOWER_1 10758 * 0x03 | BNO055_ACCEL_STANDBY 10759 * 0x04 | BNO055_ACCEL_LOWPOWER_2 10760 * 0x05 | BNO055_ACCEL_DEEPSUSPEND 10761 * 10762 * @return results of bus communication function 10763 * @retval 0 -> BNO055_SUCCESS 10764 * @retval 1 -> BNO055_ERROR 10765 * 10766 * 10767 */ 10768 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_power_mode( 10769 u8 *accel_power_mode_u8) 10770 { 10771 /* Variable used to return value of 10772 communication routine*/ 10773 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10774 u8 data_u8r = BNO055_INIT_VALUE; 10775 s8 stat_s8 = BNO055_ERROR; 10776 /* Check the struct p_bno055 is empty */ 10777 if (p_bno055 == BNO055_INIT_VALUE) { 10778 return BNO055_E_NULL_PTR; 10779 } else { 10780 /*condition check for page, accel power mode is 10781 available in the page one*/ 10782 if (p_bno055->page_id != BNO055_PAGE_ONE) 10783 /* Write page as one */ 10784 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10785 if ((stat_s8 == BNO055_SUCCESS) || 10786 (p_bno055->page_id == BNO055_PAGE_ONE)) { 10787 /* Read the value of accel bandwidth */ 10788 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 10789 (p_bno055->dev_addr, 10790 BNO055_ACCEL_POWER_MODE_REG, 10791 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 10792 *accel_power_mode_u8 = 10793 BNO055_GET_BITSLICE(data_u8r, 10794 BNO055_ACCEL_POWER_MODE); 10795 } else { 10796 com_rslt = BNO055_ERROR; 10797 } 10798 } 10799 return com_rslt; 10800 } 10801 /*! 10802 * @brief This API used to write the accel power mode 10803 * from page one register from 0x08 bit 5 to 7 10804 * 10805 * @param accel_power_mode_u8 : The value of accel power mode 10806 * accel_power_mode_u8 | result 10807 * ----------------- | ------------- 10808 * 0x00 | BNO055_ACCEL_NORMAL 10809 * 0x01 | BNO055_ACCEL_SUSPEND 10810 * 0x02 | BNO055_ACCEL_LOWPOWER_1 10811 * 0x03 | BNO055_ACCEL_STANDBY 10812 * 0x04 | BNO055_ACCEL_LOWPOWER_2 10813 * 0x05 | BNO055_ACCEL_DEEPSUSPEND 10814 * 10815 * @return results of bus communication function 10816 * @retval 0 -> BNO055_SUCCESS 10817 * @retval 1 -> BNO055_ERROR 10818 * 10819 * 10820 */ 10821 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_power_mode( 10822 u8 accel_power_mode_u8) 10823 { 10824 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10825 u8 data_u8r = BNO055_INIT_VALUE; 10826 s8 stat_s8 = BNO055_ERROR; 10827 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 10828 s8 pg_stat_s8 = BNO055_ERROR; 10829 /* Check the struct p_bno055 is empty */ 10830 if (p_bno055 == BNO055_INIT_VALUE) { 10831 return BNO055_E_NULL_PTR; 10832 } else { 10833 /* The write operation effective only if the operation 10834 mode is in config mode, this part of code is checking the 10835 current operation mode and set the config mode */ 10836 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 10837 if (stat_s8 == BNO055_SUCCESS) { 10838 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10839 stat_s8 += bno055_set_operation_mode 10840 (BNO055_OPERATION_MODE_CONFIG); 10841 if (stat_s8 == BNO055_SUCCESS) { 10842 /* Write page as one */ 10843 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10844 if (pg_stat_s8 == BNO055_SUCCESS) { 10845 if (accel_power_mode_u8 < 10846 BNO055_ACCEL_POWER_MODE_RANGE) { 10847 /* Write the value of accel bandwidth*/ 10848 com_rslt = 10849 p_bno055->BNO055_BUS_READ_FUNC 10850 (p_bno055->dev_addr, 10851 BNO055_ACCEL_POWER_MODE_REG, 10852 &data_u8r, 10853 BNO055_GEN_READ_WRITE_LENGTH); 10854 if (com_rslt == BNO055_SUCCESS) { 10855 data_u8r = BNO055_SET_BITSLICE 10856 (data_u8r, 10857 BNO055_ACCEL_POWER_MODE, 10858 accel_power_mode_u8); 10859 com_rslt += 10860 p_bno055->BNO055_BUS_WRITE_FUNC 10861 (p_bno055->dev_addr, 10862 BNO055_ACCEL_POWER_MODE_REG, 10863 &data_u8r, 10864 BNO055_GEN_READ_WRITE_LENGTH); 10865 } 10866 } else { 10867 com_rslt = BNO055_OUT_OF_RANGE; 10868 } 10869 } else { 10870 com_rslt = BNO055_ERROR; 10871 } 10872 } else { 10873 com_rslt = BNO055_ERROR; 10874 } 10875 } else { 10876 com_rslt = BNO055_ERROR; 10877 } 10878 } 10879 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10880 /* set the operation mode of 10881 previous operation mode*/ 10882 com_rslt += bno055_set_operation_mode 10883 (prev_opmode_u8); 10884 return com_rslt; 10885 } 10886 /*! 10887 * @brief This API used to read the mag output data rate 10888 * from page one register from 0x09 bit 0 to 2 10889 * 10890 * @param mag_data_output_rate_u8 : The value of mag output data rate 10891 * 10892 * mag_data_output_rate_u8 | result 10893 * ---------------------- |---------------------- 10894 * 0x00 | MAG_DATA_OUTPUT_RATE_2HZ 10895 * 0x01 | MAG_DATA_OUTPUT_RATE_6HZ 10896 * 0x02 | MAG_DATA_OUTPUT_RATE_8HZ 10897 * 0x03 | MAG_DATA_OUTPUT_RATE_10HZ 10898 * 0x04 | MAG_DATA_OUTPUT_RATE_15HZ 10899 * 0x05 | MAG_DATA_OUTPUT_RATE_20HZ 10900 * 0x06 | MAG_DATA_OUTPUT_RATE_25HZ 10901 * 0x07 | MAG_DATA_OUTPUT_RATE_30HZ 10902 * 10903 * @return results of bus communication function 10904 * @retval 0 -> BNO055_SUCCESS 10905 * @retval 1 -> BNO055_ERROR 10906 * 10907 * 10908 */ 10909 BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_data_output_rate( 10910 u8 *mag_data_output_rate_u8) 10911 { 10912 /* Variable used to return value of 10913 communication routine*/ 10914 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10915 u8 data_u8r = BNO055_INIT_VALUE; 10916 s8 stat_s8 = BNO055_ERROR; 10917 /* Check the struct p_bno055 is empty */ 10918 if (p_bno055 == BNO055_INIT_VALUE) { 10919 return BNO055_E_NULL_PTR; 10920 } else { 10921 /*condition check for page, output data rate 10922 available in the page one*/ 10923 if (p_bno055->page_id != BNO055_PAGE_ONE) 10924 /* Write page as one */ 10925 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10926 if ((stat_s8 == BNO055_SUCCESS) || 10927 (p_bno055->page_id == BNO055_PAGE_ONE)) { 10928 /* Read the mag output data rate*/ 10929 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 10930 (p_bno055->dev_addr, 10931 BNO055_MAG_DATA_OUTPUT_RATE_REG, 10932 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 10933 *mag_data_output_rate_u8 = 10934 BNO055_GET_BITSLICE(data_u8r, 10935 BNO055_MAG_DATA_OUTPUT_RATE); 10936 } else { 10937 com_rslt = BNO055_ERROR; 10938 } 10939 } 10940 return com_rslt; 10941 } 10942 /*! 10943 * @brief This API used to write the mag output data rate 10944 * from page one register from 0x09 bit 0 to 2 10945 * 10946 * @param mag_data_output_rate_u8 : The value of mag output data rate 10947 * 10948 * mag_data_output_rate_u8 | result 10949 * ---------------------- |---------------------- 10950 * 0x00 | MAG_DATA_OUTPUT_RATE_2HZ 10951 * 0x01 | MAG_DATA_OUTPUT_RATE_6HZ 10952 * 0x02 | MAG_DATA_OUTPUT_RATE_8HZ 10953 * 0x03 | MAG_DATA_OUTPUT_RATE_10HZ 10954 * 0x04 | MAG_DATA_OUTPUT_RATE_15HZ 10955 * 0x05 | MAG_DATA_OUTPUT_RATE_20HZ 10956 * 0x06 | MAG_DATA_OUTPUT_RATE_25HZ 10957 * 0x07 | MAG_DATA_OUTPUT_RATE_30HZ 10958 * 10959 * @return results of bus communication function 10960 * @retval 0 -> BNO055_SUCCESS 10961 * @retval 1 -> BNO055_ERROR 10962 * 10963 * 10964 */ 10965 BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_data_output_rate( 10966 u8 mag_data_output_rate_u8) 10967 { 10968 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 10969 u8 data_u8r = BNO055_INIT_VALUE; 10970 s8 stat_s8 = BNO055_ERROR; 10971 s8 pg_stat_s8 = BNO055_ERROR; 10972 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 10973 /* Check the struct p_bno055 is empty */ 10974 if (p_bno055 == BNO055_INIT_VALUE) { 10975 return BNO055_E_NULL_PTR; 10976 } else { 10977 /* The write operation effective only if the operation 10978 mode is in config mode, this part of code is checking the 10979 current operation mode and set the config mode */ 10980 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 10981 if (stat_s8 == BNO055_SUCCESS) { 10982 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 10983 stat_s8 += bno055_set_operation_mode 10984 (BNO055_OPERATION_MODE_CONFIG); 10985 if (stat_s8 == BNO055_SUCCESS) { 10986 /* Write page as one */ 10987 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 10988 if (pg_stat_s8 == BNO055_SUCCESS) { 10989 if (mag_data_output_rate_u8 10990 < BNO055_MAG_OUTPUT_RANGE) { 10991 /* Write the value of 10992 mag output data rate*/ 10993 com_rslt = 10994 p_bno055->BNO055_BUS_READ_FUNC 10995 (p_bno055->dev_addr, 10996 BNO055_MAG_DATA_OUTPUT_RATE_REG, 10997 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 10998 if (com_rslt == BNO055_SUCCESS) { 10999 data_u8r = BNO055_SET_BITSLICE 11000 (data_u8r, 11001 BNO055_MAG_DATA_OUTPUT_RATE, 11002 mag_data_output_rate_u8); 11003 com_rslt += 11004 p_bno055->BNO055_BUS_WRITE_FUNC 11005 (p_bno055->dev_addr, 11006 BNO055_MAG_DATA_OUTPUT_RATE_REG, 11007 &data_u8r, 11008 BNO055_GEN_READ_WRITE_LENGTH); 11009 } 11010 } else { 11011 com_rslt = BNO055_OUT_OF_RANGE; 11012 } 11013 } else { 11014 com_rslt = BNO055_ERROR; 11015 } 11016 } else { 11017 com_rslt = BNO055_ERROR; 11018 } 11019 } else { 11020 com_rslt = BNO055_ERROR; 11021 } 11022 } 11023 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11024 /* set the operation mode of 11025 previous operation mode*/ 11026 com_rslt += bno055_set_operation_mode 11027 (prev_opmode_u8); 11028 return com_rslt; 11029 } 11030 /*! 11031 * @brief This API used to read the mag operation mode 11032 * from page one register from 0x09 bit 3 to 4 11033 * 11034 * @param mag_operation_mode_u8 : The value of mag operation mode 11035 * 11036 * mag_operation_mode_u8 | result 11037 * ------------------------- |-------------------------- 11038 * 0x00 | MAG_OPR_MODE_LOWPOWER 11039 * 0x01 | MAG_OPR_MODE_REGULAR 11040 * 0x02 | MAG_OPR_MODE_ENHANCED_REGULAR 11041 * 0x03 | MAG_OPR_MODE_HIGH_ACCURACY 11042 * 11043 * @return results of bus communication function 11044 * @retval 0 -> BNO055_SUCCESS 11045 * @retval 1 -> BNO055_ERROR 11046 * 11047 * 11048 */ 11049 BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_operation_mode( 11050 u8 *mag_operation_mode_u8) 11051 { 11052 /* Variable used to return value of 11053 communication routine*/ 11054 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11055 u8 data_u8r = BNO055_INIT_VALUE; 11056 s8 stat_s8 = BNO055_ERROR; 11057 /* Check the struct p_bno055 is empty */ 11058 if (p_bno055 == BNO055_INIT_VALUE) { 11059 return BNO055_E_NULL_PTR; 11060 } else { 11061 /*condition check for page, mag operation mode is 11062 available in the page one*/ 11063 if (p_bno055->page_id != BNO055_PAGE_ONE) 11064 /* Write page as one */ 11065 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11066 if ((stat_s8 == BNO055_SUCCESS) || 11067 (p_bno055->page_id == BNO055_PAGE_ONE)) { 11068 /* Read the value of mag operation mode*/ 11069 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11070 (p_bno055->dev_addr, 11071 BNO055_MAG_OPERATION_MODE_REG, 11072 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11073 *mag_operation_mode_u8 = 11074 BNO055_GET_BITSLICE(data_u8r, 11075 BNO055_MAG_OPERATION_MODE); 11076 } else { 11077 com_rslt = BNO055_ERROR; 11078 } 11079 } 11080 return com_rslt; 11081 } 11082 /*! 11083 * @brief This API used to write the mag operation mode 11084 * from page one register from 0x09 bit 3 to 4 11085 * 11086 * @param mag_operation_mode_u8 : The value of mag operation mode 11087 * 11088 * mag_operation_mode_u8 | result 11089 * ------------------------- |-------------------------- 11090 * 0x00 | MAG_OPR_MODE_LOWPOWER 11091 * 0x01 | MAG_OPR_MODE_REGULAR 11092 * 0x02 | MAG_OPR_MODE_ENHANCED_REGULAR 11093 * 0x03 | MAG_OPR_MODE_HIGH_ACCURACY 11094 * 11095 * @return results of bus communication function 11096 * @retval 0 -> BNO055_SUCCESS 11097 * @retval 1 -> BNO055_ERROR 11098 * 11099 * 11100 */ 11101 BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_operation_mode( 11102 u8 mag_operation_mode_u8) 11103 { 11104 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11105 u8 data_u8r = BNO055_INIT_VALUE; 11106 s8 stat_s8 = BNO055_ERROR; 11107 s8 pg_stat_s8 = BNO055_ERROR; 11108 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 11109 /* Check the struct p_bno055 is empty */ 11110 if (p_bno055 == BNO055_INIT_VALUE) { 11111 return BNO055_E_NULL_PTR; 11112 } else { 11113 /* The write operation effective only if the operation 11114 mode is in config mode, this part of code is checking the 11115 current operation mode and set the config mode */ 11116 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 11117 if (stat_s8 == BNO055_SUCCESS) { 11118 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11119 stat_s8 += bno055_set_operation_mode 11120 (BNO055_OPERATION_MODE_CONFIG); 11121 if (stat_s8 == BNO055_SUCCESS) { 11122 /* Write page as one */ 11123 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11124 if (pg_stat_s8 == BNO055_SUCCESS) { 11125 if (mag_operation_mode_u8 11126 < BNO055_MAG_OPR_MODE_RANGE) { 11127 /* Write the value 11128 of mag operation mode*/ 11129 com_rslt = 11130 p_bno055->BNO055_BUS_READ_FUNC 11131 (p_bno055->dev_addr, 11132 BNO055_MAG_OPERATION_MODE_REG, 11133 &data_u8r, 11134 BNO055_GEN_READ_WRITE_LENGTH); 11135 if (com_rslt == BNO055_SUCCESS) { 11136 data_u8r = BNO055_SET_BITSLICE 11137 (data_u8r, 11138 BNO055_MAG_OPERATION_MODE, 11139 mag_operation_mode_u8); 11140 com_rslt += 11141 p_bno055->BNO055_BUS_WRITE_FUNC 11142 (p_bno055->dev_addr, 11143 BNO055_MAG_OPERATION_MODE_REG, 11144 &data_u8r, 11145 BNO055_GEN_READ_WRITE_LENGTH); 11146 } 11147 } else { 11148 com_rslt = BNO055_OUT_OF_RANGE; 11149 } 11150 } else { 11151 com_rslt = BNO055_ERROR; 11152 } 11153 } else { 11154 com_rslt = BNO055_ERROR; 11155 } 11156 } else { 11157 com_rslt = BNO055_ERROR; 11158 } 11159 } 11160 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11161 /* set the operation mode of 11162 previous operation mode*/ 11163 com_rslt += bno055_set_operation_mode 11164 (prev_opmode_u8); 11165 return com_rslt; 11166 } 11167 /*! 11168 * @brief This API used to read the mag power mode 11169 * from page one register from 0x09 bit 4 to 6 11170 * 11171 * @param mag_power_mode_u8 : The value of mag power mode 11172 * 11173 * mag_power_mode_u8 | result 11174 * --------------------|----------------- 11175 * 0x00 | BNO055_MAG_POWER_MODE_NORMAL 11176 * 0x01 | BNO055_MAG_POWER_MODE_SLEEP 11177 * 0x02 | BNO055_MAG_POWER_MODE_SUSPEND 11178 * 0x03 | BNO055_MAG_POWER_MODE_FORCE_MODE 11179 * 11180 * @return results of bus communication function 11181 * @retval 0 -> BNO055_SUCCESS 11182 * @retval 1 -> BNO055_ERROR 11183 * 11184 * 11185 */ 11186 BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_power_mode( 11187 u8 *mag_power_mode_u8) 11188 { 11189 /* Variable used to return value of 11190 communication routine*/ 11191 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11192 u8 data_u8r = BNO055_INIT_VALUE; 11193 s8 stat_s8 = BNO055_ERROR; 11194 /* Check the struct p_bno055 is empty */ 11195 if (p_bno055 == BNO055_INIT_VALUE) { 11196 return BNO055_E_NULL_PTR; 11197 } else { 11198 /*condition check for page, mag power mode is 11199 available in the page one*/ 11200 if (p_bno055->page_id != BNO055_PAGE_ONE) 11201 /* Write page as one */ 11202 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11203 if ((stat_s8 == BNO055_SUCCESS) || 11204 (p_bno055->page_id == BNO055_PAGE_ONE)) { 11205 /* Read the value of mag power mode */ 11206 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11207 (p_bno055->dev_addr, 11208 BNO055_MAG_POWER_MODE_REG, 11209 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11210 *mag_power_mode_u8 = 11211 BNO055_GET_BITSLICE(data_u8r, 11212 BNO055_MAG_POWER_MODE); 11213 } else { 11214 com_rslt = BNO055_ERROR; 11215 } 11216 } 11217 return com_rslt; 11218 } 11219 /*! 11220 * @brief This API used to write the mag power mode 11221 * from page one register from 0x09 bit 4 to 6 11222 * 11223 * @param mag_power_mode_u8 : The value of mag power mode 11224 * 11225 * mag_power_mode_u8 | result 11226 * --------------------|----------------- 11227 * 0x00 | BNO055_MAG_POWER_MODE_NORMAL 11228 * 0x01 | BNO055_MAG_POWER_MODE_SLEEP 11229 * 0x02 | BNO055_MAG_POWER_MODE_SUSPEND 11230 * 0x03 | BNO055_MAG_POWER_MODE_FORCE_MODE 11231 * 11232 * @return results of bus communication function 11233 * @retval 0 -> BNO055_SUCCESS 11234 * @retval 1 -> BNO055_ERROR 11235 * 11236 * 11237 */ 11238 BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_power_mode( 11239 u8 mag_power_mode_u8) 11240 { 11241 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11242 u8 data_u8r = BNO055_INIT_VALUE; 11243 s8 stat_s8 = BNO055_ERROR; 11244 s8 pg_stat_s8 = BNO055_ERROR; 11245 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 11246 /* Check the struct p_bno055 is empty */ 11247 if (p_bno055 == BNO055_INIT_VALUE) { 11248 return BNO055_E_NULL_PTR; 11249 } else { 11250 /* The write operation effective only if the operation 11251 mode is in config mode, this part of code is checking the 11252 current operation mode and set the config mode */ 11253 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 11254 if (stat_s8 == BNO055_SUCCESS) { 11255 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11256 stat_s8 += bno055_set_operation_mode( 11257 BNO055_OPERATION_MODE_CONFIG); 11258 if (stat_s8 == BNO055_SUCCESS) { 11259 /* Write page as one */ 11260 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11261 if (pg_stat_s8 == BNO055_SUCCESS) { 11262 if (mag_power_mode_u8 < 11263 BNO055_MAG_POWER_MODE_RANGE) { 11264 /* Write the value of mag power mode*/ 11265 com_rslt = 11266 p_bno055->BNO055_BUS_READ_FUNC 11267 (p_bno055->dev_addr, 11268 BNO055_MAG_POWER_MODE_REG, 11269 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11270 if (com_rslt == BNO055_SUCCESS) { 11271 data_u8r = BNO055_SET_BITSLICE 11272 (data_u8r, 11273 BNO055_MAG_POWER_MODE, 11274 mag_power_mode_u8); 11275 com_rslt += 11276 p_bno055->BNO055_BUS_WRITE_FUNC 11277 (p_bno055->dev_addr, 11278 BNO055_MAG_POWER_MODE_REG, 11279 &data_u8r, 11280 BNO055_GEN_READ_WRITE_LENGTH); 11281 } 11282 } else { 11283 com_rslt = BNO055_OUT_OF_RANGE; 11284 } 11285 } else { 11286 com_rslt = BNO055_ERROR; 11287 } 11288 } else { 11289 com_rslt = BNO055_ERROR; 11290 } 11291 } else { 11292 com_rslt = BNO055_ERROR; 11293 } 11294 } 11295 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11296 /* set the operation mode of 11297 previous operation mode*/ 11298 com_rslt += bno055_set_operation_mode 11299 (prev_opmode_u8); 11300 return com_rslt; 11301 } 11302 /*! 11303 * @brief This API used to read the gyro range 11304 * from page one register from 0x0A bit 0 to 3 11305 * 11306 * @param gyro_range_u8 : The value of gyro range 11307 * 11308 * gyro_range_u8 | result 11309 * --------------------|----------------- 11310 * 0x00 | BNO055_GYRO_RANGE_2000DPS 11311 * 0x01 | BNO055_GYRO_RANGE_1000DPS 11312 * 0x02 | BNO055_GYRO_RANGE_500DPS 11313 * 0x03 | BNO055_GYRO_RANGE_250DPS 11314 * 0x04 | BNO055_GYRO_RANGE_125DPS 11315 * 11316 * @return results of bus communication function 11317 * @retval 0 -> BNO055_SUCCESS 11318 * @retval 1 -> BNO055_ERROR 11319 * 11320 * 11321 */ 11322 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_range( 11323 u8 *gyro_range_u8) 11324 { 11325 /* Variable used to return value of 11326 communication routine*/ 11327 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11328 u8 data_u8r = BNO055_INIT_VALUE; 11329 s8 stat_s8 = BNO055_ERROR; 11330 /* Check the struct p_bno055 is empty */ 11331 if (p_bno055 == BNO055_INIT_VALUE) { 11332 return BNO055_E_NULL_PTR; 11333 } else { 11334 /*condition check for page, gyro range is 11335 available in the page one*/ 11336 if (p_bno055->page_id != BNO055_PAGE_ONE) 11337 /* Write page as one */ 11338 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11339 if ((stat_s8 == BNO055_SUCCESS) || 11340 (p_bno055->page_id == BNO055_PAGE_ONE)) { 11341 /* Read the value of gyro range */ 11342 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11343 (p_bno055->dev_addr, 11344 BNO055_GYRO_RANGE_REG, 11345 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11346 *gyro_range_u8 = 11347 BNO055_GET_BITSLICE(data_u8r, 11348 BNO055_GYRO_RANGE); 11349 } else { 11350 com_rslt = BNO055_ERROR; 11351 } 11352 } 11353 return com_rslt; 11354 } 11355 /*! 11356 * @brief This API used to write the gyro range 11357 * from page one register from 0x0A bit 0 to 3 11358 * 11359 * @param gyro_range_u8 : The value of gyro range 11360 * 11361 * gyro_range_u8 | result 11362 * --------------------|----------------- 11363 * 0x00 | BNO055_GYRO_RANGE_2000DPS 11364 * 0x01 | BNO055_GYRO_RANGE_1000DPS 11365 * 0x02 | BNO055_GYRO_RANGE_500DPS 11366 * 0x03 | BNO055_GYRO_RANGE_250DPS 11367 * 0x04 | BNO055_GYRO_RANGE_125DPS 11368 * 11369 * @return results of bus communication function 11370 * @retval 0 -> BNO055_SUCCESS 11371 * @retval 1 -> BNO055_ERROR 11372 * 11373 * 11374 */ 11375 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_range( 11376 u8 gyro_range_u8) 11377 { 11378 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11379 u8 data_u8r = BNO055_INIT_VALUE; 11380 s8 stat_s8 = BNO055_ERROR; 11381 s8 pg_stat_s8 = BNO055_ERROR; 11382 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 11383 /* Check the struct p_bno055 is empty */ 11384 if (p_bno055 == BNO055_INIT_VALUE) { 11385 return BNO055_E_NULL_PTR; 11386 } else { 11387 /* The write operation effective only if the operation 11388 mode is in config mode, this part of code is checking the 11389 current operation mode and set the config mode */ 11390 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 11391 if (stat_s8 == BNO055_SUCCESS) { 11392 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11393 stat_s8 += bno055_set_operation_mode 11394 (BNO055_OPERATION_MODE_CONFIG); 11395 if (stat_s8 == BNO055_SUCCESS) { 11396 /* Write page as one */ 11397 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11398 if (pg_stat_s8 == BNO055_SUCCESS) { 11399 if (gyro_range_u8 < BNO055_GYRO_RANGE) { 11400 /* Write the value of gyro range*/ 11401 com_rslt = 11402 p_bno055->BNO055_BUS_READ_FUNC 11403 (p_bno055->dev_addr, 11404 BNO055_GYRO_RANGE_REG, 11405 &data_u8r, 11406 BNO055_GEN_READ_WRITE_LENGTH); 11407 if (com_rslt == BNO055_SUCCESS) { 11408 data_u8r = BNO055_SET_BITSLICE 11409 (data_u8r, 11410 BNO055_GYRO_RANGE, 11411 gyro_range_u8); 11412 com_rslt += 11413 p_bno055->BNO055_BUS_WRITE_FUNC 11414 (p_bno055->dev_addr, 11415 BNO055_GYRO_RANGE_REG, 11416 &data_u8r, 11417 BNO055_GEN_READ_WRITE_LENGTH); 11418 } 11419 } else { 11420 com_rslt = BNO055_OUT_OF_RANGE; 11421 } 11422 } else { 11423 com_rslt = BNO055_ERROR; 11424 } 11425 } else { 11426 com_rslt = BNO055_ERROR; 11427 } 11428 } else { 11429 com_rslt = BNO055_ERROR; 11430 } 11431 } 11432 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11433 /* set the operation mode of 11434 previous operation mode*/ 11435 com_rslt += bno055_set_operation_mode 11436 (prev_opmode_u8); 11437 return com_rslt; 11438 } 11439 /*! 11440 * @brief This API used to read the gyro bandwidth 11441 * from page one register from 0x0A bit 3 to 5 11442 * 11443 * @param gyro_bw_u8 : The value of gyro bandwidth 11444 * 11445 * gyro_bw_u8 | result 11446 * --------------------|----------------- 11447 * 0x00 | BNO055_GYRO_BW_523HZ 11448 * 0x01 | BNO055_GYRO_BW_230HZ 11449 * 0x02 | BNO055_GYRO_BW_116HZ 11450 * 0x03 | BNO055_GYRO_BW_47HZ 11451 * 0x04 | BNO055_GYRO_BW_23HZ 11452 * 0x05 | BNO055_GYRO_BW_12HZ 11453 * 0x06 | BNO055_GYRO_BW_64HZ 11454 * 0x07 | BNO055_GYRO_BW_32HZ 11455 * 11456 * @return results of bus communication function 11457 * @retval 0 -> BNO055_SUCCESS 11458 * @retval 1 -> BNO055_ERROR 11459 * 11460 * 11461 */ 11462 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_bw( 11463 u8 *gyro_bw_u8) 11464 { 11465 /* Variable used to return value of 11466 communication routine*/ 11467 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11468 u8 data_u8r = BNO055_INIT_VALUE; 11469 s8 stat_s8 = BNO055_ERROR; 11470 /* Check the struct p_bno055 is empty */ 11471 if (p_bno055 == BNO055_INIT_VALUE) { 11472 return BNO055_E_NULL_PTR; 11473 } else { 11474 /*condition check for page, gyro bandwidth is 11475 available in the page one*/ 11476 if (p_bno055->page_id != BNO055_PAGE_ONE) 11477 /* Write page as one */ 11478 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11479 if ((stat_s8 == BNO055_SUCCESS) || 11480 (p_bno055->page_id == BNO055_PAGE_ONE)) { 11481 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11482 (p_bno055->dev_addr, 11483 BNO055_GYRO_BW_REG, 11484 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11485 *gyro_bw_u8 = 11486 BNO055_GET_BITSLICE(data_u8r, 11487 BNO055_GYRO_BW); 11488 } else { 11489 com_rslt = BNO055_ERROR; 11490 } 11491 } 11492 return com_rslt; 11493 } 11494 /*! 11495 * @brief This API used to write the gyro bandwidth 11496 * from page one register from 0x0A bit 3 to 5 11497 * 11498 * @param gyro_bw_u8 : The value of gyro bandwidth 11499 * 11500 * gyro_bw_u8 | result 11501 * --------------------|----------------- 11502 * 0x00 | BNO055_GYRO_BW_523HZ 11503 * 0x01 | BNO055_GYRO_BW_230HZ 11504 * 0x02 | BNO055_GYRO_BW_116HZ 11505 * 0x03 | BNO055_GYRO_BW_47HZ 11506 * 0x04 | BNO055_GYRO_BW_23HZ 11507 * 0x05 | BNO055_GYRO_BW_12HZ 11508 * 0x06 | BNO055_GYRO_BW_64HZ 11509 * 0x07 | BNO055_GYRO_BW_32HZ 11510 * 11511 * @return results of bus communication function 11512 * @retval 0 -> BNO055_SUCCESS 11513 * @retval 1 -> BNO055_ERROR 11514 * 11515 * 11516 */ 11517 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_bw( 11518 u8 gyro_bw_u8) 11519 { 11520 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11521 u8 data_u8r = BNO055_INIT_VALUE; 11522 s8 stat_s8 = BNO055_ERROR; 11523 u8 gyro_opmode = BNO055_INIT_VALUE; 11524 u8 gyro_auto_sleep_durn = BNO055_INIT_VALUE; 11525 s8 pg_stat_s8 = BNO055_ERROR; 11526 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 11527 /* Check the struct p_bno055 is empty */ 11528 if (p_bno055 == BNO055_INIT_VALUE) { 11529 return BNO055_E_NULL_PTR; 11530 } else { 11531 /* The write operation effective only if the operation 11532 mode is in config mode, this part of code is checking the 11533 current operation mode and set the config mode */ 11534 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 11535 if (stat_s8 == BNO055_SUCCESS) { 11536 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11537 stat_s8 += bno055_set_operation_mode 11538 (BNO055_OPERATION_MODE_CONFIG); 11539 if (stat_s8 == BNO055_SUCCESS) { 11540 /* Write page as one */ 11541 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11542 if (pg_stat_s8 == BNO055_SUCCESS) { 11543 /* Write the value of gyro bandwidth */ 11544 if ((gyro_bw_u8 == BNO055_INIT_VALUE || 11545 gyro_bw_u8 > BNO055_INIT_VALUE) && 11546 gyro_bw_u8 < BNO055_ACCEL_GYRO_BW_RANGE) { 11547 switch (gyro_bw_u8) { 11548 case BNO055_GYRO_BW_523HZ: 11549 gyro_bw_u8 = BNO055_GYRO_BW_523HZ; 11550 break; 11551 case BNO055_GYRO_BW_230HZ: 11552 gyro_bw_u8 = BNO055_GYRO_BW_230HZ; 11553 break; 11554 case BNO055_GYRO_BW_116HZ: 11555 gyro_bw_u8 = BNO055_GYRO_BW_116HZ; 11556 break; 11557 case BNO055_GYRO_BW_47HZ: 11558 gyro_bw_u8 = BNO055_GYRO_BW_47HZ; 11559 break; 11560 case BNO055_GYRO_BW_23HZ: 11561 gyro_bw_u8 = BNO055_GYRO_BW_23HZ; 11562 break; 11563 case BNO055_GYRO_BW_12HZ: 11564 gyro_bw_u8 = BNO055_GYRO_BW_12HZ; 11565 break; 11566 case BNO055_GYRO_BW_64HZ: 11567 gyro_bw_u8 = BNO055_GYRO_BW_64HZ; 11568 break; 11569 case BNO055_GYRO_BW_32HZ: 11570 gyro_bw_u8 = BNO055_GYRO_BW_32HZ; 11571 break; 11572 default: 11573 break; 11574 } 11575 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11576 (p_bno055->dev_addr, 11577 BNO055_GYRO_BW_REG, 11578 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11579 if (com_rslt == BNO055_SUCCESS) { 11580 data_u8r = BNO055_SET_BITSLICE 11581 (data_u8r, 11582 BNO055_GYRO_BW, 11583 gyro_bw_u8); 11584 com_rslt += 11585 p_bno055->BNO055_BUS_WRITE_FUNC 11586 (p_bno055->dev_addr, 11587 BNO055_GYRO_BW_REG, 11588 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11589 } 11590 com_rslt = bno055_get_gyro_power_mode 11591 (&gyro_opmode); 11592 if (com_rslt == BNO055_SUCCESS) { 11593 if (gyro_opmode == 11594 BNO055_GYRO_POWER_MODE_ADVANCE_POWERSAVE) { 11595 com_rslt += 11596 bno055_get_gyro_auto_sleep_durn 11597 (&gyro_auto_sleep_durn); 11598 if (com_rslt == BNO055_SUCCESS) { 11599 com_rslt += 11600 bno055_gyro_set_auto_sleep_durn 11601 (gyro_auto_sleep_durn, 11602 gyro_bw_u8); 11603 } 11604 } 11605 } 11606 } else { 11607 com_rslt = BNO055_OUT_OF_RANGE; 11608 } 11609 } else { 11610 com_rslt = BNO055_ERROR; 11611 } 11612 } else { 11613 com_rslt = BNO055_ERROR; 11614 } 11615 } else { 11616 com_rslt = BNO055_ERROR; 11617 } 11618 } 11619 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11620 /* set the operation mode of 11621 previous operation mode*/ 11622 com_rslt += bno055_set_operation_mode 11623 (prev_opmode_u8); 11624 return com_rslt; 11625 } 11626 /*! 11627 * @brief This API used to read the gyro power mode 11628 * from page one register from 0x0B bit 0 to 2 11629 * 11630 * @param gyro_power_mode_u8 : The value of gyro power mode 11631 * 11632 * gyro_power_mode_u8 | result 11633 * ----------------------|---------------------------- 11634 * 0x00 | GYRO_OPR_MODE_NORMAL 11635 * 0x01 | GYRO_OPR_MODE_FASTPOWERUP 11636 * 0x02 | GYRO_OPR_MODE_DEEPSUSPEND 11637 * 0x03 | GYRO_OPR_MODE_SUSPEND 11638 * 0x04 | GYRO_OPR_MODE_ADVANCE_POWERSAVE 11639 * 11640 * @return results of bus communication function 11641 * @retval 0 -> BNO055_SUCCESS 11642 * @retval 1 -> BNO055_ERROR 11643 * 11644 * 11645 */ 11646 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_power_mode( 11647 u8 *gyro_power_mode_u8) 11648 { 11649 /* Variable used to return value of 11650 communication routine*/ 11651 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11652 u8 data_u8r = BNO055_INIT_VALUE; 11653 s8 stat_s8 = BNO055_ERROR; 11654 /* Check the struct p_bno055 is empty */ 11655 if (p_bno055 == BNO055_INIT_VALUE) { 11656 return BNO055_E_NULL_PTR; 11657 } else { 11658 /*condition check for page, gyro power mode is 11659 available in the page one*/ 11660 if (p_bno055->page_id != BNO055_PAGE_ONE) 11661 /* Write page as one */ 11662 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11663 if ((stat_s8 == BNO055_SUCCESS) || 11664 (p_bno055->page_id == BNO055_PAGE_ONE)) { 11665 /* Write the value of gyro power mode*/ 11666 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11667 (p_bno055->dev_addr, 11668 BNO055_GYRO_POWER_MODE_REG, 11669 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11670 *gyro_power_mode_u8 = 11671 BNO055_GET_BITSLICE(data_u8r, 11672 BNO055_GYRO_POWER_MODE); 11673 } else { 11674 com_rslt = BNO055_ERROR; 11675 } 11676 } 11677 return com_rslt; 11678 } 11679 /*! 11680 * @brief This API used to write the gyro power mode 11681 * from page one register from 0x0B bit 0 to 2 11682 * 11683 * @param gyro_power_mode_u8 : The value of gyro power mode 11684 * 11685 * gyro_power_mode_u8 | result 11686 * ----------------------|---------------------------- 11687 * 0x00 | GYRO_OPR_MODE_NORMAL 11688 * 0x01 | GYRO_OPR_MODE_FASTPOWERUP 11689 * 0x02 | GYRO_OPR_MODE_DEEPSUSPEND 11690 * 0x03 | GYRO_OPR_MODE_SUSPEND 11691 * 0x04 | GYRO_OPR_MODE_ADVANCE_POWERSAVE 11692 * 11693 * @return results of bus communication function 11694 * @retval 0 -> BNO055_SUCCESS 11695 * @retval 1 -> BNO055_ERROR 11696 * 11697 * 11698 */ 11699 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_power_mode( 11700 u8 gyro_power_mode_u8) 11701 { 11702 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11703 u8 data_u8r = BNO055_INIT_VALUE; 11704 s8 stat_s8 = BNO055_ERROR; 11705 u8 gyro_auto_sleep_durn = BNO055_INIT_VALUE; 11706 u8 gyro_bw_u8 = BNO055_INIT_VALUE; 11707 s8 pg_stat_s8 = BNO055_ERROR; 11708 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 11709 /* Check the struct p_bno055 is empty */ 11710 if (p_bno055 == BNO055_INIT_VALUE) { 11711 return BNO055_E_NULL_PTR; 11712 } else { 11713 /* The write operation effective only if the operation 11714 mode is in config mode, this part of code is checking the 11715 current operation mode and set the config mode */ 11716 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 11717 if (stat_s8 == BNO055_SUCCESS) { 11718 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11719 stat_s8 += bno055_set_operation_mode 11720 (BNO055_OPERATION_MODE_CONFIG); 11721 if (stat_s8 == BNO055_SUCCESS) { 11722 /* Write page as one */ 11723 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11724 if (pg_stat_s8 == BNO055_SUCCESS) { 11725 /* Write the value of power mode*/ 11726 if ((gyro_power_mode_u8 == BNO055_INIT_VALUE || 11727 gyro_power_mode_u8 > BNO055_INIT_VALUE) && 11728 gyro_power_mode_u8 < BNO055_GYRO_RANGE) { 11729 switch (gyro_power_mode_u8) { 11730 case BNO055_GYRO_POWER_MODE_NORMAL: 11731 gyro_power_mode_u8 = 11732 BNO055_GYRO_POWER_MODE_NORMAL; 11733 break; 11734 case BNO055_GYRO_POWER_MODE_FASTPOWERUP: 11735 gyro_power_mode_u8 = 11736 BNO055_GYRO_POWER_MODE_FASTPOWERUP; 11737 break; 11738 case BNO055_GYRO_POWER_MODE_DEEPSUSPEND: 11739 gyro_power_mode_u8 = 11740 BNO055_GYRO_POWER_MODE_DEEPSUSPEND; 11741 break; 11742 case BNO055_GYRO_POWER_MODE_SUSPEND: 11743 gyro_power_mode_u8 = 11744 BNO055_GYRO_POWER_MODE_SUSPEND; 11745 break; 11746 case BNO055_GYRO_POWER_MODE_ADVANCE_POWERSAVE: 11747 com_rslt = bno055_get_gyro_bw 11748 (&gyro_bw_u8); 11749 com_rslt += bno055_get_gyro_auto_sleep_durn 11750 (&gyro_auto_sleep_durn); 11751 if (com_rslt == BNO055_SUCCESS) 11752 bno055_gyro_set_auto_sleep_durn 11753 (gyro_auto_sleep_durn, 11754 gyro_bw_u8); 11755 com_rslt += 11756 bno055_write_page_id(BNO055_PAGE_ONE); 11757 gyro_power_mode_u8 = 11758 BNO055_GYRO_POWER_MODE_ADVANCE_POWERSAVE; 11759 break; 11760 default: 11761 break; 11762 } 11763 com_rslt = 11764 p_bno055->BNO055_BUS_READ_FUNC 11765 (p_bno055->dev_addr, 11766 BNO055_GYRO_POWER_MODE_REG, 11767 &data_u8r, 11768 BNO055_GEN_READ_WRITE_LENGTH); 11769 if (com_rslt == BNO055_SUCCESS) { 11770 data_u8r = BNO055_SET_BITSLICE 11771 (data_u8r, 11772 BNO055_GYRO_POWER_MODE, 11773 gyro_power_mode_u8); 11774 com_rslt += 11775 p_bno055->BNO055_BUS_WRITE_FUNC 11776 (p_bno055->dev_addr, 11777 BNO055_GYRO_POWER_MODE_REG, 11778 &data_u8r, 11779 BNO055_GEN_READ_WRITE_LENGTH); 11780 } 11781 } else { 11782 com_rslt = BNO055_OUT_OF_RANGE; 11783 } 11784 } else { 11785 com_rslt = BNO055_ERROR; 11786 } 11787 } else { 11788 com_rslt = BNO055_ERROR; 11789 } 11790 } else { 11791 com_rslt = BNO055_ERROR; 11792 } 11793 } 11794 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11795 /* set the operation mode of 11796 previous operation mode*/ 11797 com_rslt += bno055_set_operation_mode 11798 (prev_opmode_u8); 11799 return com_rslt; 11800 } 11801 /*! 11802 * @brief This API used to read the accel sleep mode 11803 * from page one register from 0x0C bit 0 11804 * 11805 * @param sleep_tmr_u8 : The value of accel sleep mode 11806 * 11807 * sleep_tmr_u8 | result 11808 * ----------------- |------------------------------------ 11809 * 0x00 | enable EventDrivenSampling(EDT) 11810 * 0x01 | enable Equidistant sampling mode(EST) 11811 * 11812 * @return results of bus communication function 11813 * @retval 0 -> BNO055_SUCCESS 11814 * @retval 1 -> BNO055_ERROR 11815 * 11816 * 11817 */ 11818 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_sleep_tmr_mode( 11819 u8 *sleep_tmr_u8) 11820 { 11821 /* Variable used to return value of 11822 communication routine*/ 11823 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11824 u8 data_u8r = BNO055_INIT_VALUE; 11825 s8 stat_s8 = BNO055_ERROR; 11826 /* Check the struct p_bno055 is empty */ 11827 if (p_bno055 == BNO055_INIT_VALUE) { 11828 return BNO055_E_NULL_PTR; 11829 } else { 11830 /*condition check for page, accel sleep mode is 11831 available in the page one*/ 11832 if (p_bno055->page_id != BNO055_PAGE_ONE) 11833 /* Write page as one */ 11834 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11835 if ((stat_s8 == BNO055_SUCCESS) || 11836 (p_bno055->page_id == BNO055_PAGE_ONE)) { 11837 /* read the value of accel sleep mode */ 11838 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11839 (p_bno055->dev_addr, 11840 BNO055_ACCEL_SLEEP_MODE_REG, 11841 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11842 *sleep_tmr_u8 = 11843 BNO055_GET_BITSLICE(data_u8r, 11844 BNO055_ACCEL_SLEEP_MODE); 11845 } else { 11846 com_rslt = BNO055_ERROR; 11847 } 11848 } 11849 return com_rslt; 11850 } 11851 /*! 11852 * @brief This API used to write the accel sleep mode 11853 * from page one register from 0x0C bit 0 11854 * 11855 * @param sleep_tmr_u8 : The value of accel sleep mode 11856 * 11857 * sleep_tmr_u8 | result 11858 * ----------------- |------------------------------------ 11859 * 0x00 | enable EventDrivenSampling(EDT) 11860 * 0x01 | enable Equidistant sampling mode(EST) 11861 * 11862 * @return results of bus communication function 11863 * @retval 0 -> BNO055_SUCCESS 11864 * @retval 1 -> BNO055_ERROR 11865 * 11866 * 11867 */ 11868 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_sleep_tmr_mode( 11869 u8 sleep_tmr_u8) 11870 { 11871 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11872 u8 data_u8r = BNO055_INIT_VALUE; 11873 s8 stat_s8 = BNO055_ERROR; 11874 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 11875 s8 pg_stat_s8 = BNO055_ERROR; 11876 /* Check the struct p_bno055 is empty */ 11877 if (p_bno055 == BNO055_INIT_VALUE) { 11878 return BNO055_E_NULL_PTR; 11879 } else { 11880 /* The write operation effective only if the operation 11881 mode is in config mode, this part of code is checking the 11882 current operation mode and set the config mode */ 11883 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 11884 if (stat_s8 == BNO055_SUCCESS) { 11885 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11886 stat_s8 += bno055_set_operation_mode 11887 (BNO055_OPERATION_MODE_CONFIG); 11888 if (stat_s8 == BNO055_SUCCESS) { 11889 /* Write page as one */ 11890 pg_stat_s8 = bno055_write_page_id( 11891 BNO055_PAGE_ONE); 11892 if (pg_stat_s8 == BNO055_SUCCESS) { 11893 if (sleep_tmr_u8 < 11894 BNO055_ACCEL_SLEEP_MODE_RANGE) { 11895 /*Write the value 11896 of accel sleep mode*/ 11897 com_rslt = 11898 p_bno055->BNO055_BUS_READ_FUNC 11899 (p_bno055->dev_addr, 11900 BNO055_ACCEL_SLEEP_MODE_REG, 11901 &data_u8r, 11902 BNO055_GEN_READ_WRITE_LENGTH); 11903 if (com_rslt == BNO055_SUCCESS) { 11904 data_u8r = BNO055_SET_BITSLICE 11905 (data_u8r, 11906 BNO055_ACCEL_SLEEP_MODE, 11907 sleep_tmr_u8); 11908 com_rslt += 11909 p_bno055->BNO055_BUS_WRITE_FUNC 11910 (p_bno055->dev_addr, 11911 BNO055_ACCEL_SLEEP_MODE_REG, 11912 &data_u8r, 11913 BNO055_GEN_READ_WRITE_LENGTH); 11914 } 11915 } else { 11916 com_rslt = BNO055_OUT_OF_RANGE; 11917 } 11918 } else { 11919 com_rslt = BNO055_ERROR; 11920 } 11921 } else { 11922 com_rslt = BNO055_ERROR; 11923 } 11924 } else { 11925 com_rslt = BNO055_ERROR; 11926 } 11927 } 11928 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 11929 /* set the operation mode of 11930 previous operation mode*/ 11931 com_rslt += bno055_set_operation_mode 11932 (prev_opmode_u8); 11933 return com_rslt; 11934 } 11935 /*! 11936 * @brief This API used to read the accel sleep duration 11937 * from page one register from 0x0C bit 1 to 4 11938 * 11939 * @param sleep_durn_u8 : The value of accel sleep duration 11940 * 11941 * sleep_durn_u8 | result 11942 * ---------------- |----------------------------- 11943 * 0x05 | BNO055_ACCEL_SLEEP_DURN_0_5MS 11944 * 0x06 | BNO055_ACCEL_SLEEP_DURN_1MS 11945 * 0x07 | BNO055_ACCEL_SLEEP_DURN_2MS 11946 * 0x08 | BNO055_ACCEL_SLEEP_DURN_4MS 11947 * 0x09 | BNO055_ACCEL_SLEEP_DURN_6MS 11948 * 0x0A | BNO055_ACCEL_SLEEP_DURN_10MS 11949 * 0x0B | BNO055_ACCEL_SLEEP_DURN_25MS 11950 * 0x0C | BNO055_ACCEL_SLEEP_DURN_50MS 11951 * 0x0D | BNO055_ACCEL_SLEEP_DURN_100MS 11952 * 0x0E | BNO055_ACCEL_SLEEP_DURN_500MS 11953 * 0x0F | BNO055_ACCEL_SLEEP_DURN_1S 11954 * 11955 * @return results of bus communication function 11956 * @retval 0 -> BNO055_SUCCESS 11957 * @retval 1 -> BNO055_ERROR 11958 * 11959 * 11960 */ 11961 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_sleep_durn( 11962 u8 *sleep_durn_u8) 11963 { 11964 /* Variable used to return value of 11965 communication routine*/ 11966 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 11967 u8 data_u8r = BNO055_INIT_VALUE; 11968 s8 stat_s8 = BNO055_ERROR; 11969 /* Check the struct p_bno055 is empty */ 11970 if (p_bno055 == BNO055_INIT_VALUE) { 11971 return BNO055_E_NULL_PTR; 11972 } else { 11973 /*condition check for page, accel sleep duration 11974 available in the page one*/ 11975 if (p_bno055->page_id != BNO055_PAGE_ONE) 11976 /* Write page as one */ 11977 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 11978 if ((stat_s8 == BNO055_SUCCESS) || 11979 (p_bno055->page_id == BNO055_PAGE_ONE)) { 11980 /* Read the value of accel sleep duration */ 11981 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 11982 (p_bno055->dev_addr, 11983 BNO055_ACCEL_SLEEP_DURN_REG, 11984 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 11985 *sleep_durn_u8 = 11986 BNO055_GET_BITSLICE(data_u8r, 11987 BNO055_ACCEL_SLEEP_DURN); 11988 } else { 11989 com_rslt = BNO055_ERROR; 11990 } 11991 } 11992 return com_rslt; 11993 } 11994 /*! 11995 * @brief This API used to write the accel sleep duration 11996 * from page one register from 0x0C bit 1 to 4 11997 * 11998 * @param sleep_durn_u8 : The value of accel sleep duration 11999 * 12000 * sleep_durn_u8 | result 12001 * ---------------|----------------------------- 12002 * 0x05 | BNO055_ACCEL_SLEEP_DURN_0_5MS 12003 * 0x06 | BNO055_ACCEL_SLEEP_DURN_1MS 12004 * 0x07 | BNO055_ACCEL_SLEEP_DURN_2MS 12005 * 0x08 | BNO055_ACCEL_SLEEP_DURN_4MS 12006 * 0x09 | BNO055_ACCEL_SLEEP_DURN_6MS 12007 * 0x0A | BNO055_ACCEL_SLEEP_DURN_10MS 12008 * 0x0B | BNO055_ACCEL_SLEEP_DURN_25MS 12009 * 0x0C | BNO055_ACCEL_SLEEP_DURN_50MS 12010 * 0x0D | BNO055_ACCEL_SLEEP_DURN_100MS 12011 * 0x0E | BNO055_ACCEL_SLEEP_DURN_500MS 12012 * 0x0F | BNO055_ACCEL_SLEEP_DURN_1S 12013 * 12014 * @return results of bus communication function 12015 * @retval 0 -> BNO055_SUCCESS 12016 * @retval 1 -> BNO055_ERROR 12017 * 12018 * 12019 */ 12020 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_sleep_durn( 12021 u8 sleep_durn_u8) 12022 { 12023 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12024 u8 data_u8r = BNO055_INIT_VALUE; 12025 s8 stat_s8 = BNO055_ERROR; 12026 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 12027 s8 pg_stat_s8 = BNO055_ERROR; 12028 /* Check the struct p_bno055 is empty */ 12029 if (p_bno055 == BNO055_INIT_VALUE) { 12030 return BNO055_E_NULL_PTR; 12031 } else { 12032 /* The write operation effective only if the operation 12033 mode is in config mode, this part of code is checking the 12034 current operation mode and set the config mode */ 12035 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 12036 if (stat_s8 == BNO055_SUCCESS) { 12037 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12038 stat_s8 += bno055_set_operation_mode 12039 (BNO055_OPERATION_MODE_CONFIG); 12040 if (stat_s8 == BNO055_SUCCESS) { 12041 /* Write page as one */ 12042 pg_stat_s8 = bno055_write_page_id( 12043 BNO055_PAGE_ONE); 12044 if (pg_stat_s8 == BNO055_SUCCESS) { 12045 if (sleep_durn_u8 < 12046 BNO055_ACCEL_SLEEP_DURATION_RANGE) { 12047 /* Write the accel 12048 sleep duration*/ 12049 com_rslt = 12050 p_bno055->BNO055_BUS_READ_FUNC 12051 (p_bno055->dev_addr, 12052 BNO055_ACCEL_SLEEP_DURN_REG, 12053 &data_u8r, 12054 BNO055_GEN_READ_WRITE_LENGTH); 12055 if (com_rslt == BNO055_SUCCESS) { 12056 data_u8r = BNO055_SET_BITSLICE 12057 (data_u8r, 12058 BNO055_ACCEL_SLEEP_DURN, 12059 sleep_durn_u8); 12060 com_rslt += 12061 p_bno055->BNO055_BUS_WRITE_FUNC 12062 (p_bno055->dev_addr, 12063 BNO055_ACCEL_SLEEP_DURN_REG, 12064 &data_u8r, 12065 BNO055_GEN_READ_WRITE_LENGTH); 12066 } 12067 } else { 12068 com_rslt = BNO055_OUT_OF_RANGE; 12069 } 12070 } else { 12071 com_rslt = BNO055_ERROR; 12072 } 12073 } else { 12074 com_rslt = BNO055_ERROR; 12075 } 12076 } else { 12077 com_rslt = BNO055_ERROR; 12078 } 12079 } 12080 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12081 /* set the operation mode of 12082 previous operation mode*/ 12083 com_rslt += bno055_set_operation_mode 12084 (prev_opmode_u8); 12085 return com_rslt; 12086 } 12087 /*! 12088 * @brief This API used to write the gyro sleep duration 12089 * from page one register from 0x0D bit 0 to 2 12090 * 12091 * @param sleep_durn_u8 : The value of gyro sleep duration 12092 * 12093 * @return results of bus communication function 12094 * @retval 0 -> BNO055_SUCCESS 12095 * @retval 1 -> BNO055_ERROR 12096 * 12097 * 12098 */ 12099 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_sleep_durn(u8 *sleep_durn_u8) 12100 { 12101 /* Variable used to return value of 12102 communication routine*/ 12103 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12104 u8 data_u8r = BNO055_INIT_VALUE; 12105 s8 stat_s8 = BNO055_ERROR; 12106 /* Check the struct p_bno055 is empty */ 12107 if (p_bno055 == BNO055_INIT_VALUE) { 12108 return BNO055_E_NULL_PTR; 12109 } else { 12110 /*condition check for page, accel range is 12111 available in the page one*/ 12112 if (p_bno055->page_id != BNO055_PAGE_ONE) 12113 /* Write page as one */ 12114 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12115 if ((stat_s8 == BNO055_SUCCESS) || 12116 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12117 /* Read the gyro sleep duration */ 12118 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12119 (p_bno055->dev_addr, 12120 BNO055_GYRO_SLEEP_DURN_REG, 12121 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12122 *sleep_durn_u8 = 12123 BNO055_GET_BITSLICE(data_u8r, 12124 BNO055_GYRO_SLEEP_DURN); 12125 } else { 12126 com_rslt = BNO055_ERROR; 12127 } 12128 } 12129 return com_rslt; 12130 } 12131 /*! 12132 * @brief This API used to write the gyro sleep duration 12133 * from page one register from 0x0D bit 0 to 2 12134 * 12135 * @param sleep_durn_u8 : The value of gyro sleep duration 12136 * 12137 * @return results of bus communication function 12138 * @retval 0 -> BNO055_SUCCESS 12139 * @retval 1 -> BNO055_ERROR 12140 * 12141 * 12142 */ 12143 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_sleep_durn(u8 sleep_durn_u8) 12144 { 12145 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12146 u8 data_u8r = BNO055_INIT_VALUE; 12147 s8 stat_s8 = BNO055_ERROR; 12148 s8 pg_stat_s8 = BNO055_ERROR; 12149 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 12150 /* Check the struct p_bno055 is empty */ 12151 if (p_bno055 == BNO055_INIT_VALUE) { 12152 return BNO055_E_NULL_PTR; 12153 } else { 12154 /* The write operation effective only if the operation 12155 mode is in config mode, this part of code is checking the 12156 current operation mode and set the config mode */ 12157 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 12158 if (stat_s8 == BNO055_SUCCESS) { 12159 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12160 stat_s8 += bno055_set_operation_mode 12161 (BNO055_OPERATION_MODE_CONFIG); 12162 if (stat_s8 == BNO055_SUCCESS) { 12163 /* Write page as one */ 12164 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12165 if (pg_stat_s8 == BNO055_SUCCESS) { 12166 if (sleep_durn_u8 < 12167 BNO055_GYRO_AUTO_SLEEP_DURATION_RANGE) { 12168 com_rslt = 12169 p_bno055->BNO055_BUS_READ_FUNC 12170 (p_bno055->dev_addr, 12171 BNO055_GYRO_SLEEP_DURN_REG, 12172 &data_u8r, 12173 BNO055_GEN_READ_WRITE_LENGTH); 12174 if (com_rslt == BNO055_SUCCESS) { 12175 /* Write the gyro 12176 sleep duration */ 12177 data_u8r = BNO055_SET_BITSLICE 12178 (data_u8r, 12179 BNO055_GYRO_SLEEP_DURN, 12180 sleep_durn_u8); 12181 com_rslt += 12182 p_bno055->BNO055_BUS_WRITE_FUNC 12183 (p_bno055->dev_addr, 12184 BNO055_GYRO_SLEEP_DURN_REG, 12185 &data_u8r, 12186 BNO055_GEN_READ_WRITE_LENGTH); 12187 } 12188 } else { 12189 com_rslt = BNO055_OUT_OF_RANGE; 12190 } 12191 } else { 12192 com_rslt = BNO055_ERROR; 12193 } 12194 } else { 12195 com_rslt = BNO055_ERROR; 12196 } 12197 } else { 12198 com_rslt = BNO055_ERROR; 12199 } 12200 } 12201 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12202 /* set the operation mode of 12203 previous operation mode*/ 12204 com_rslt += bno055_set_operation_mode 12205 (prev_opmode_u8); 12206 return com_rslt; 12207 } 12208 /*! 12209 * @brief This API used to read the gyro auto sleep duration 12210 * from page one register from 0x0D bit 3 to 5 12211 * 12212 * @param auto_sleep_durn_u8 : The value of gyro auto sleep duration 12213 * 12214 * @return results of bus communication function 12215 * @retval 0 -> BNO055_SUCCESS 12216 * @retval 1 -> BNO055_ERROR 12217 * 12218 * 12219 */ 12220 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_auto_sleep_durn( 12221 u8 *auto_sleep_durn_u8) 12222 { 12223 /* Variable used to return value of 12224 communication routine*/ 12225 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12226 u8 data_u8r = BNO055_INIT_VALUE; 12227 s8 stat_s8 = BNO055_ERROR; 12228 /* Check the struct p_bno055 is empty */ 12229 if (p_bno055 == BNO055_INIT_VALUE) { 12230 return BNO055_E_NULL_PTR; 12231 } else { 12232 /*condition check for page, accel range is 12233 available in the page one*/ 12234 if (p_bno055->page_id != BNO055_PAGE_ONE) 12235 /* Write page as one */ 12236 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12237 if ((stat_s8 == BNO055_SUCCESS) || 12238 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12239 /* Read the value of gyro auto sleep duration */ 12240 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12241 (p_bno055->dev_addr, 12242 BNO055_GYRO_AUTO_SLEEP_DURN_REG, 12243 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12244 *auto_sleep_durn_u8 = 12245 BNO055_GET_BITSLICE(data_u8r, 12246 BNO055_GYRO_AUTO_SLEEP_DURN); 12247 } else { 12248 com_rslt = BNO055_ERROR; 12249 } 12250 } 12251 return com_rslt; 12252 } 12253 /*! 12254 * @brief This API used to write the gyro auto sleep duration 12255 * from page one register from 0x0D bit 3 to 5 12256 * 12257 * @param auto_sleep_durn_u8 : The value of gyro auto sleep duration 12258 * @param bw : The value of gyro bandwidth 12259 * 12260 * @return results of bus communication function 12261 * @retval 0 -> BNO055_SUCCESS 12262 * @retval 1 -> BNO055_ERROR 12263 * 12264 * 12265 */ 12266 BNO055_RETURN_FUNCTION_TYPE bno055_gyro_set_auto_sleep_durn( 12267 u8 auto_sleep_durn_u8, u8 bw) 12268 { 12269 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12270 u8 data_u8r = BNO055_INIT_VALUE; 12271 s8 stat_s8 = BNO055_ERROR; 12272 u8 auto_sleep_durn_u8r; 12273 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 12274 s8 pg_stat_s8 = BNO055_ERROR; 12275 /* Check the struct p_bno055 is empty */ 12276 if (p_bno055 == BNO055_INIT_VALUE) { 12277 return BNO055_E_NULL_PTR; 12278 } else { 12279 /* The write operation effective only if the operation 12280 mode is in config mode, this part of code is checking the 12281 current operation mode and set the config mode */ 12282 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 12283 if (stat_s8 == BNO055_SUCCESS) { 12284 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12285 stat_s8 += bno055_set_operation_mode 12286 (BNO055_OPERATION_MODE_CONFIG); 12287 if (stat_s8 == BNO055_SUCCESS) { 12288 /* Write page as one */ 12289 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12290 if (pg_stat_s8 == BNO055_SUCCESS) { 12291 /* Write the value of gyro sleep duration */ 12292 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12293 (p_bno055->dev_addr, 12294 BNO055_GYRO_AUTO_SLEEP_DURN_REG, 12295 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12296 if (auto_sleep_durn_u8 < 12297 BNO055_GYRO_AUTO_SLEEP_DURATION_RANGE) { 12298 switch (bw) { 12299 case BNO055_GYRO_BW_523HZ: 12300 if (auto_sleep_durn_u8 > 12301 BNO055_GYRO_4MS_AUTOSLPDUR) 12302 auto_sleep_durn_u8r = 12303 auto_sleep_durn_u8; 12304 else 12305 auto_sleep_durn_u8r = 12306 BNO055_GYRO_4MS_AUTOSLPDUR; 12307 break; 12308 case BNO055_GYRO_BW_230HZ: 12309 if (auto_sleep_durn_u8 > 12310 BNO055_GYRO_4MS_AUTOSLPDUR) 12311 auto_sleep_durn_u8r = 12312 auto_sleep_durn_u8; 12313 else 12314 auto_sleep_durn_u8r = 12315 BNO055_GYRO_4MS_AUTOSLPDUR; 12316 break; 12317 case BNO055_GYRO_BW_116HZ: 12318 if (auto_sleep_durn_u8 > 12319 BNO055_GYRO_4MS_AUTOSLPDUR) 12320 auto_sleep_durn_u8r = 12321 auto_sleep_durn_u8; 12322 else 12323 auto_sleep_durn_u8r = 12324 BNO055_GYRO_4MS_AUTOSLPDUR; 12325 break; 12326 case BNO055_GYRO_BW_47HZ: 12327 if (auto_sleep_durn_u8 > 12328 BNO055_GYRO_5MS_AUTOSLPDUR) 12329 auto_sleep_durn_u8r = 12330 auto_sleep_durn_u8; 12331 else 12332 auto_sleep_durn_u8r = 12333 BNO055_GYRO_5MS_AUTOSLPDUR; 12334 break; 12335 case BNO055_GYRO_BW_23HZ: 12336 if (auto_sleep_durn_u8 > 12337 BNO055_GYRO_10MS_AUTOSLPDUR) 12338 auto_sleep_durn_u8r = 12339 auto_sleep_durn_u8; 12340 else 12341 auto_sleep_durn_u8r = 12342 BNO055_GYRO_10MS_AUTOSLPDUR; 12343 break; 12344 case BNO055_GYRO_BW_12HZ: 12345 if (auto_sleep_durn_u8 > 12346 BNO055_GYRO_20MS_AUTOSLPDUR) 12347 auto_sleep_durn_u8r = 12348 auto_sleep_durn_u8; 12349 else 12350 auto_sleep_durn_u8r = 12351 BNO055_GYRO_20MS_AUTOSLPDUR; 12352 break; 12353 case BNO055_GYRO_BW_64HZ: 12354 if (auto_sleep_durn_u8 > 12355 BNO055_GYRO_10MS_AUTOSLPDUR) 12356 auto_sleep_durn_u8r = 12357 auto_sleep_durn_u8; 12358 else 12359 auto_sleep_durn_u8r = 12360 BNO055_GYRO_10MS_AUTOSLPDUR; 12361 break; 12362 case BNO055_GYRO_BW_32HZ: 12363 if (auto_sleep_durn_u8 > 12364 BNO055_GYRO_20MS_AUTOSLPDUR) 12365 auto_sleep_durn_u8r = 12366 auto_sleep_durn_u8; 12367 else 12368 auto_sleep_durn_u8r = 12369 BNO055_GYRO_20MS_AUTOSLPDUR; 12370 break; 12371 default: 12372 if (auto_sleep_durn_u8 > 12373 BNO055_GYRO_4MS_AUTOSLPDUR) 12374 auto_sleep_durn_u8r = 12375 auto_sleep_durn_u8; 12376 else 12377 auto_sleep_durn_u8r = 12378 BNO055_GYRO_4MS_AUTOSLPDUR; 12379 break; 12380 } 12381 if (com_rslt == BNO055_SUCCESS) { 12382 data_u8r = BNO055_SET_BITSLICE 12383 (data_u8r, 12384 BNO055_GYRO_AUTO_SLEEP_DURN, 12385 auto_sleep_durn_u8r); 12386 com_rslt += 12387 p_bno055->BNO055_BUS_WRITE_FUNC 12388 (p_bno055->dev_addr, 12389 BNO055_GYRO_AUTO_SLEEP_DURN_REG, 12390 &data_u8r, 12391 BNO055_GEN_READ_WRITE_LENGTH); 12392 } 12393 } else { 12394 com_rslt = BNO055_OUT_OF_RANGE; 12395 } 12396 } else { 12397 com_rslt = BNO055_ERROR; 12398 } 12399 } else { 12400 com_rslt = BNO055_ERROR; 12401 } 12402 } else { 12403 com_rslt = BNO055_ERROR; 12404 } 12405 } 12406 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12407 /* set the operation mode of 12408 previous operation mode*/ 12409 com_rslt += bno055_set_operation_mode 12410 (prev_opmode_u8); 12411 return com_rslt; 12412 } 12413 /*! 12414 * @brief This API used to read the mag sleep mode 12415 * from page one register from 0x0E bit 0 12416 * 12417 * @param sleep_mode_u8 : The value of mag sleep mode 12418 * 12419 * @return results of bus communication function 12420 * @retval 0 -> BNO055_SUCCESS 12421 * @retval 1 -> BNO055_ERROR 12422 * 12423 * 12424 */ 12425 BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_sleep_mode( 12426 u8 *sleep_mode_u8) 12427 { 12428 /* Variable used to return value of 12429 communication routine*/ 12430 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12431 u8 data_u8r = BNO055_INIT_VALUE; 12432 s8 stat_s8 = BNO055_ERROR; 12433 /* Check the struct p_bno055 is empty */ 12434 if (p_bno055 == BNO055_INIT_VALUE) { 12435 return BNO055_E_NULL_PTR; 12436 } else { 12437 /*condition check for page,mag sleep mode is 12438 available in the page one*/ 12439 if (p_bno055->page_id != BNO055_PAGE_ONE) 12440 /* Write page as one */ 12441 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12442 if ((stat_s8 == BNO055_SUCCESS) || 12443 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12444 /* Read the value of mag sleep mode*/ 12445 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12446 (p_bno055->dev_addr, 12447 BNO055_MAG_SLEEP_MODE_REG, 12448 &data_u8r, 12449 BNO055_GEN_READ_WRITE_LENGTH); 12450 *sleep_mode_u8 = 12451 BNO055_GET_BITSLICE(data_u8r, 12452 BNO055_MAG_SLEEP_MODE); 12453 } else { 12454 com_rslt = BNO055_ERROR; 12455 } 12456 } 12457 return com_rslt; 12458 } 12459 /*! 12460 * @brief This API used to write the mag sleep mode 12461 * from page one register from 0x0E bit 0 12462 * 12463 * @param sleep_mode_u8 : The value of mag sleep mode 12464 * 12465 * @return results of bus communication function 12466 * @retval 0 -> BNO055_SUCCESS 12467 * @retval 1 -> BNO055_ERROR 12468 * 12469 * 12470 */ 12471 BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_sleep_mode( 12472 u8 sleep_mode_u8) 12473 { 12474 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12475 u8 data_u8r = BNO055_INIT_VALUE; 12476 s8 stat_s8 = BNO055_ERROR; 12477 s8 pg_stat_s8 = BNO055_ERROR; 12478 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 12479 /* Check the struct p_bno055 is empty */ 12480 if (p_bno055 == BNO055_INIT_VALUE) { 12481 return BNO055_E_NULL_PTR; 12482 } else { 12483 /* The write operation effective only if the operation 12484 mode is in config mode, this part of code is checking the 12485 current operation mode and set the config mode */ 12486 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 12487 if (stat_s8 == BNO055_SUCCESS) { 12488 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12489 stat_s8 += bno055_set_operation_mode 12490 (BNO055_OPERATION_MODE_CONFIG); 12491 if (stat_s8 == BNO055_SUCCESS) { 12492 /* Write page as one */ 12493 pg_stat_s8 = bno055_write_page_id( 12494 BNO055_PAGE_ONE); 12495 if (pg_stat_s8 == BNO055_SUCCESS) { 12496 com_rslt = 12497 p_bno055->BNO055_BUS_READ_FUNC 12498 (p_bno055->dev_addr, 12499 BNO055_MAG_SLEEP_MODE_REG, 12500 &data_u8r, 12501 BNO055_GEN_READ_WRITE_LENGTH); 12502 if (com_rslt == BNO055_SUCCESS) { 12503 /* Write the value 12504 of mag sleep mode*/ 12505 data_u8r = 12506 BNO055_SET_BITSLICE(data_u8r, 12507 BNO055_MAG_SLEEP_MODE, 12508 sleep_mode_u8); 12509 com_rslt += 12510 p_bno055->BNO055_BUS_WRITE_FUNC 12511 (p_bno055->dev_addr, 12512 BNO055_MAG_SLEEP_MODE_REG, 12513 &data_u8r, 12514 BNO055_GEN_READ_WRITE_LENGTH); 12515 } 12516 } else { 12517 com_rslt = BNO055_ERROR; 12518 } 12519 } else { 12520 com_rslt = BNO055_ERROR; 12521 } 12522 } else { 12523 com_rslt = BNO055_ERROR; 12524 } 12525 } 12526 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12527 /* set the operation mode of 12528 previous operation mode*/ 12529 com_rslt += bno055_set_operation_mode 12530 (prev_opmode_u8); 12531 return com_rslt; 12532 } 12533 /*! 12534 * @brief This API used to read the mag sleep duration 12535 * from page one register from 0x0E bit 1 to 4 12536 * 12537 * @param sleep_durn_u8 : The value of mag sleep duration 12538 * 12539 * @return results of bus communication function 12540 * @retval 0 -> BNO055_SUCCESS 12541 * @retval 1 -> BNO055_ERROR 12542 * 12543 * 12544 */ 12545 BNO055_RETURN_FUNCTION_TYPE bno055_get_mag_sleep_durn( 12546 u8 *sleep_durn_u8) 12547 { 12548 /* Variable used to return value of 12549 communication routine*/ 12550 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12551 u8 data_u8r = BNO055_INIT_VALUE; 12552 s8 stat_s8 = BNO055_ERROR; 12553 /* Check the struct p_bno055 is empty */ 12554 if (p_bno055 == BNO055_INIT_VALUE) { 12555 return BNO055_E_NULL_PTR; 12556 } else { 12557 /*condition check for page,mag sleep duration is 12558 available in the page one*/ 12559 if (p_bno055->page_id != BNO055_PAGE_ONE) 12560 /* Write page as one */ 12561 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12562 if ((stat_s8 == BNO055_SUCCESS) || 12563 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12564 /* Read the value of mag sleep duration*/ 12565 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12566 (p_bno055->dev_addr, 12567 BNO055_MAG_SLEEP_DURN_REG, 12568 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12569 *sleep_durn_u8 = 12570 BNO055_GET_BITSLICE(data_u8r, 12571 BNO055_MAG_SLEEP_DURN); 12572 } else { 12573 com_rslt = BNO055_ERROR; 12574 } 12575 } 12576 return com_rslt; 12577 } 12578 /*! 12579 * @brief This API used to write the mag sleep duration 12580 * from page one register from 0x0E bit 1 to 4 12581 * 12582 * @param sleep_durn_u8 : The value of mag sleep duration 12583 * 12584 * @return results of bus communication function 12585 * @retval 0 -> BNO055_SUCCESS 12586 * @retval 1 -> BNO055_ERROR 12587 * 12588 * 12589 */ 12590 BNO055_RETURN_FUNCTION_TYPE bno055_set_mag_sleep_durn( 12591 u8 sleep_durn_u8) 12592 { 12593 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12594 u8 data_u8r = BNO055_INIT_VALUE; 12595 s8 stat_s8 = BNO055_ERROR; 12596 s8 pg_stat_s8 = BNO055_ERROR; 12597 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 12598 /* Check the struct p_bno055 is empty */ 12599 if (p_bno055 == BNO055_INIT_VALUE) { 12600 return BNO055_E_NULL_PTR; 12601 } else { 12602 /* The write operation effective only if the operation 12603 mode is in config mode, this part of code is checking the 12604 current operation mode and set the config mode */ 12605 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 12606 if (stat_s8 == BNO055_SUCCESS) { 12607 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12608 stat_s8 += bno055_set_operation_mode 12609 (BNO055_OPERATION_MODE_CONFIG); 12610 if (stat_s8 == BNO055_SUCCESS) { 12611 /* Write page as one */ 12612 pg_stat_s8 = bno055_write_page_id( 12613 BNO055_PAGE_ONE); 12614 if (pg_stat_s8 == BNO055_SUCCESS) { 12615 com_rslt = 12616 p_bno055->BNO055_BUS_READ_FUNC 12617 (p_bno055->dev_addr, 12618 BNO055_MAG_SLEEP_DURN_REG, 12619 &data_u8r, 12620 BNO055_GEN_READ_WRITE_LENGTH); 12621 if (com_rslt == BNO055_SUCCESS) { 12622 /* Write the value of 12623 mag sleep duration */ 12624 data_u8r = 12625 BNO055_SET_BITSLICE(data_u8r, 12626 BNO055_MAG_SLEEP_DURN, 12627 sleep_durn_u8); 12628 com_rslt += 12629 p_bno055->BNO055_BUS_WRITE_FUNC 12630 (p_bno055->dev_addr, 12631 BNO055_MAG_SLEEP_DURN_REG, 12632 &data_u8r, 12633 BNO055_GEN_READ_WRITE_LENGTH); 12634 } 12635 } else { 12636 com_rslt = BNO055_ERROR; 12637 } 12638 } else { 12639 com_rslt = BNO055_ERROR; 12640 } 12641 } else { 12642 com_rslt = BNO055_ERROR; 12643 } 12644 } 12645 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 12646 /* set the operation mode of 12647 previous operation mode*/ 12648 com_rslt += bno055_set_operation_mode 12649 (prev_opmode_u8); 12650 return com_rslt; 12651 } 12652 /*! 12653 * @brief This API used to read the gyro anymotion interrupt mask 12654 * from page one register from 0x0F bit 2 12655 * 12656 * @param gyro_any_motion_u8 : The value of gyro anymotion interrupt mask 12657 * gyro_any_motion_u8 | result 12658 * -------------------- |------------ 12659 * 0x01 | BNO055_BIT_ENABLE 12660 * 0x00 | BNO055_BIT_DISABLE 12661 * 12662 * @return results of bus communication function 12663 * @retval 0 -> BNO055_SUCCESS 12664 * @retval 1 -> BNO055_ERROR 12665 * 12666 * @note While enabling the gyro anymotion interrupt 12667 * configure the following settings 12668 * 12669 * Axis: 12670 * bno055_set_gyro_any_motion_axis_enable() 12671 * 12672 * Filter setting: 12673 * bno055_set_gyro_any_motion_filter() 12674 * 12675 * Threshold : 12676 * 12677 * bno055_set_gyro_any_motion_thres() 12678 * 12679 * Slope samples : 12680 * 12681 * bno055_set_gyro_any_motion_slope_samples() 12682 * 12683 * Awake duration : 12684 * 12685 * bno055_set_gyro_any_motion_awake_durn() 12686 * 12687 */ 12688 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_mask_gyro_any_motion( 12689 u8 *gyro_any_motion_u8) 12690 { 12691 /* Variable used to return value of 12692 communication routine*/ 12693 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12694 u8 data_u8r = BNO055_INIT_VALUE; 12695 s8 stat_s8 = BNO055_ERROR; 12696 /* Check the struct p_bno055 is empty */ 12697 if (p_bno055 == BNO055_INIT_VALUE) { 12698 return BNO055_E_NULL_PTR; 12699 } else { 12700 /*condition check for page, gyro anymotion interrupt mask is 12701 available in the page one*/ 12702 if (p_bno055->page_id != BNO055_PAGE_ONE) 12703 /* Write page as one */ 12704 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12705 if ((stat_s8 == BNO055_SUCCESS) || 12706 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12707 /* Read the value of gyro anymotion interrupt mask*/ 12708 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12709 (p_bno055->dev_addr, 12710 BNO055_GYRO_ANY_MOTION_INTR_MASK_REG, 12711 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12712 *gyro_any_motion_u8 = 12713 BNO055_GET_BITSLICE(data_u8r, 12714 BNO055_GYRO_ANY_MOTION_INTR_MASK); 12715 } else { 12716 com_rslt = BNO055_ERROR; 12717 } 12718 } 12719 return com_rslt; 12720 } 12721 /*! 12722 * @brief This API used to write the gyro anymotion interrupt mask 12723 * from page one register from 0x0F bit 2 12724 * 12725 * @param gyro_any_motion_u8 : The value of gyro anymotion interrupt mask 12726 * gyro_any_motion_u8 | result 12727 * -------------------- |------------ 12728 * 0x01 | BNO055_BIT_ENABLE 12729 * 0x00 | BNO055_BIT_DISABLE 12730 * 12731 * @return results of bus communication function 12732 * @retval 0 -> BNO055_SUCCESS 12733 * @retval 1 -> BNO055_ERROR 12734 * 12735 * @note While enabling the gyro anymotion interrupt 12736 * configure the following settings 12737 * 12738 * Axis: 12739 * bno055_set_gyro_any_motion_axis_enable() 12740 * 12741 * Filter setting: 12742 * bno055_set_gyro_any_motion_filter() 12743 * 12744 * Threshold : 12745 * 12746 * bno055_set_gyro_any_motion_thres() 12747 * 12748 * Slope samples : 12749 * 12750 * bno055_set_gyro_any_motion_slope_samples() 12751 * 12752 * Awake duration : 12753 * 12754 * bno055_set_gyro_any_motion_awake_durn() 12755 * 12756 */ 12757 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_mask_gyro_any_motion( 12758 u8 gyro_any_motion_u8) 12759 { 12760 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12761 u8 data_u8r = BNO055_INIT_VALUE; 12762 s8 stat_s8 = BNO055_ERROR; 12763 /* Check the struct p_bno055 is empty */ 12764 if (p_bno055 == BNO055_INIT_VALUE) { 12765 return BNO055_E_NULL_PTR; 12766 } else { 12767 /*condition check for page, accel range is 12768 available in the page one*/ 12769 if (p_bno055->page_id != BNO055_PAGE_ONE) 12770 /* Write page as one */ 12771 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12772 if ((stat_s8 == BNO055_SUCCESS) || 12773 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12774 /* Write the value of gyro anymotion interrupt mask*/ 12775 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12776 (p_bno055->dev_addr, 12777 BNO055_GYRO_ANY_MOTION_INTR_MASK_REG, 12778 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12779 if (com_rslt == BNO055_SUCCESS) { 12780 data_u8r = 12781 BNO055_SET_BITSLICE(data_u8r, 12782 BNO055_GYRO_ANY_MOTION_INTR_MASK, 12783 gyro_any_motion_u8); 12784 com_rslt += 12785 p_bno055->BNO055_BUS_WRITE_FUNC 12786 (p_bno055->dev_addr, 12787 BNO055_GYRO_ANY_MOTION_INTR_MASK_REG, 12788 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12789 } 12790 } else { 12791 com_rslt = BNO055_ERROR; 12792 } 12793 } 12794 return com_rslt; 12795 } 12796 /*! 12797 * @brief This API used to read the gyro highrate interrupt mask 12798 * from page one register from 0x0F bit 3 12799 * 12800 * @param gyro_highrate_u8 : The value of gyro highrate interrupt mask 12801 * gyro_highrate_u8 | result 12802 * -------------------- |------------ 12803 * 0x01 | BNO055_BIT_ENABLE 12804 * 0x00 | BNO055_BIT_DISABLE 12805 * 12806 * @return results of bus communication function 12807 * @retval 0 -> BNO055_SUCCESS 12808 * @retval 1 -> BNO055_ERROR 12809 * 12810 * @note While enabling the gyro highrate interrupt 12811 * configure the below settings by using 12812 * the following API 12813 * 12814 * Axis : 12815 * 12816 * bno055_set_gyro_highrate_axis_enable() 12817 * 12818 * Filter : 12819 * 12820 * bno055_set_gyro_highrate_filter() 12821 * 12822 * Threshold : 12823 * 12824 * bno055_get_gyro_highrate_x_thres() 12825 * 12826 * bno055_get_gyro_highrate_y_thres() 12827 * 12828 * bno055_get_gyro_highrate_z_thres() 12829 * 12830 * Hysteresis : 12831 * 12832 * bno055_set_gyro_highrate_x_hyst() 12833 * 12834 * bno055_set_gyro_highrate_y_hyst() 12835 * 12836 * bno055_set_gyro_highrate_z_hyst() 12837 * 12838 * Duration : 12839 * 12840 * bno055_set_gyro_highrate_x_durn() 12841 * 12842 * bno055_set_gyro_highrate_y_durn() 12843 * 12844 * bno055_set_gyro_highrate_z_durn() 12845 * 12846 */ 12847 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_mask_gyro_highrate( 12848 u8 *gyro_highrate_u8) 12849 { 12850 /* Variable used to return value of 12851 communication routine*/ 12852 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12853 u8 data_u8r = BNO055_INIT_VALUE; 12854 s8 stat_s8 = BNO055_ERROR; 12855 /* Check the struct p_bno055 is empty */ 12856 if (p_bno055 == BNO055_INIT_VALUE) { 12857 return BNO055_E_NULL_PTR; 12858 } else { 12859 /*condition check for page, gyro highrate interrupt mask is 12860 available in the page one*/ 12861 if (p_bno055->page_id != BNO055_PAGE_ONE) 12862 /* Write page as one */ 12863 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12864 if ((stat_s8 == BNO055_SUCCESS) || 12865 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12866 /* Read the value of gyro highrate interrupt mask*/ 12867 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12868 (p_bno055->dev_addr, 12869 BNO055_GYRO_HIGHRATE_INTR_MASK_REG, 12870 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12871 *gyro_highrate_u8 = 12872 BNO055_GET_BITSLICE(data_u8r, 12873 BNO055_GYRO_HIGHRATE_INTR_MASK); 12874 } else { 12875 com_rslt = BNO055_ERROR; 12876 } 12877 } 12878 return com_rslt; 12879 } 12880 /*! 12881 * @brief This API used to write the gyro highrate interrupt mask 12882 * from page one register from 0x0F bit 3 12883 * 12884 * @param gyro_highrate_u8 : The value of gyro highrate interrupt mask 12885 * gyro_highrate_u8 | result 12886 * -------------------- |------------ 12887 * 0x01 | BNO055_BIT_ENABLE 12888 * 0x00 | BNO055_BIT_DISABLE 12889 * 12890 * @return results of bus communication function 12891 * @retval 0 -> BNO055_SUCCESS 12892 * @retval 1 -> BNO055_ERROR 12893 * 12894 * @note While enabling the gyro highrate interrupt 12895 * configure the below settings by using 12896 * the following APIs 12897 * 12898 * Axis : 12899 * 12900 * bno055_set_gyro_highrate_axis_enable() 12901 * 12902 * Filter : 12903 * 12904 * bno055_set_gyro_highrate_filter() 12905 * 12906 * Threshold : 12907 * 12908 * bno055_get_gyro_highrate_x_thres() 12909 * 12910 * bno055_get_gyro_highrate_y_thres() 12911 * 12912 * bno055_get_gyro_highrate_z_thres() 12913 * 12914 * Hysteresis : 12915 * 12916 * bno055_set_gyro_highrate_x_hyst() 12917 * 12918 * bno055_set_gyro_highrate_y_hyst() 12919 * 12920 * bno055_set_gyro_highrate_z_hyst() 12921 * 12922 * Duration : 12923 * 12924 * bno055_set_gyro_highrate_x_durn() 12925 * 12926 * bno055_set_gyro_highrate_y_durn() 12927 * 12928 * bno055_set_gyro_highrate_z_durn() 12929 * 12930 */ 12931 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_mask_gyro_highrate( 12932 u8 gyro_highrate_u8) 12933 { 12934 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 12935 u8 data_u8r = BNO055_INIT_VALUE; 12936 s8 stat_s8 = BNO055_ERROR; 12937 /* Check the struct p_bno055 is empty */ 12938 if (p_bno055 == BNO055_INIT_VALUE) { 12939 return BNO055_E_NULL_PTR; 12940 } else { 12941 /*condition check for page, gyro highrate interrupt mask is 12942 available in the page one*/ 12943 if (p_bno055->page_id != BNO055_PAGE_ONE) 12944 /* Write page as one */ 12945 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 12946 if ((stat_s8 == BNO055_SUCCESS) || 12947 (p_bno055->page_id == BNO055_PAGE_ONE)) { 12948 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 12949 (p_bno055->dev_addr, 12950 BNO055_GYRO_HIGHRATE_INTR_MASK_REG, 12951 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12952 if (com_rslt == BNO055_SUCCESS) { 12953 /* Write the value of gyro 12954 highrate interrupt mask*/ 12955 data_u8r = 12956 BNO055_SET_BITSLICE(data_u8r, 12957 BNO055_GYRO_HIGHRATE_INTR_MASK, 12958 gyro_highrate_u8); 12959 com_rslt += 12960 p_bno055->BNO055_BUS_WRITE_FUNC 12961 (p_bno055->dev_addr, 12962 BNO055_GYRO_HIGHRATE_INTR_MASK_REG, 12963 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 12964 } 12965 } else { 12966 com_rslt = BNO055_ERROR; 12967 } 12968 } 12969 return com_rslt; 12970 } 12971 /*! 12972 * @brief This API used to read the accel highg interrupt mask 12973 * from page one register from 0x0F bit 5 12974 * 12975 * @param accel_high_g_u8 : The value of accel highg interrupt mask 12976 * accel_high_g_u8 | result 12977 * -------------------- |------------ 12978 * 0x01 | BNO055_BIT_ENABLE 12979 * 0x00 | BNO055_BIT_DISABLE 12980 * 12981 * @return results of bus communication function 12982 * @retval 0 -> BNO055_SUCCESS 12983 * @retval 1 -> BNO055_ERROR 12984 * 12985 * @note While enabling the accel highg interrupt 12986 * configure the below settings by using 12987 * the following APIs 12988 * 12989 * Axis : 12990 * 12991 * bno055_set_accel_high_g_axis_enable() 12992 * 12993 * Threshold : 12994 * 12995 * bno055_set_accel_high_g_thres() 12996 * 12997 * Duration : 12998 * 12999 * bno055_set_accel_high_g_durn() 13000 * 13001 */ 13002 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_mask_accel_high_g( 13003 u8 *accel_high_g_u8) 13004 { 13005 /* Variable used to return value of 13006 communication routine*/ 13007 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13008 u8 data_u8r = BNO055_INIT_VALUE; 13009 s8 stat_s8 = BNO055_ERROR; 13010 /* Check the struct p_bno055 is empty */ 13011 if (p_bno055 == BNO055_INIT_VALUE) { 13012 return BNO055_E_NULL_PTR; 13013 } else { 13014 /*condition check for page, accel highg interrupt mask is 13015 available in the page one*/ 13016 if (p_bno055->page_id != BNO055_PAGE_ONE) 13017 /* Write page as one */ 13018 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13019 if ((stat_s8 == BNO055_SUCCESS) || 13020 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13021 /* Read the value of accel highg interrupt mask*/ 13022 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13023 (p_bno055->dev_addr, 13024 BNO055_ACCEL_HIGH_G_INTR_MASK_REG, 13025 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13026 *accel_high_g_u8 = 13027 BNO055_GET_BITSLICE(data_u8r, 13028 BNO055_ACCEL_HIGH_G_INTR_MASK); 13029 } else { 13030 com_rslt = BNO055_ERROR; 13031 } 13032 } 13033 return com_rslt; 13034 } 13035 /*! 13036 * @brief This API used to write the accel highg interrupt mask 13037 * from page one register from 0x0F bit 5 13038 * 13039 * @param accel_high_g_u8 : The value of accel highg interrupt mask 13040 * accel_high_g_u8 | result 13041 * -------------------- |------------ 13042 * 0x01 | BNO055_BIT_ENABLE 13043 * 0x00 | BNO055_BIT_DISABLE 13044 * 13045 * @return results of bus communication function 13046 * @retval 0 -> BNO055_SUCCESS 13047 * @retval 1 -> BNO055_ERROR 13048 * 13049 * @note While enabling the accel highg interrupt 13050 * configure the below settings by using 13051 * the following APIs 13052 * 13053 * Axis : 13054 * 13055 * bno055_set_accel_high_g_axis_enable() 13056 * 13057 * Threshold : 13058 * 13059 * bno055_set_accel_high_g_thres() 13060 * 13061 * Duration : 13062 * 13063 * bno055_set_accel_high_g_durn() 13064 * 13065 */ 13066 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_mask_accel_high_g( 13067 u8 accel_high_g_u8) 13068 { 13069 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13070 u8 data_u8r = BNO055_INIT_VALUE; 13071 s8 stat_s8 = BNO055_ERROR; 13072 /* Check the struct p_bno055 is empty */ 13073 if (p_bno055 == BNO055_INIT_VALUE) { 13074 return BNO055_E_NULL_PTR; 13075 } else { 13076 /*condition check for page, accel highg interrupt mask is 13077 available in the page one*/ 13078 if (p_bno055->page_id != BNO055_PAGE_ONE) 13079 /* Write page as one */ 13080 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13081 if ((stat_s8 == BNO055_SUCCESS) || 13082 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13083 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13084 (p_bno055->dev_addr, 13085 BNO055_ACCEL_HIGH_G_INTR_MASK_REG, 13086 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13087 if (com_rslt == BNO055_SUCCESS) { 13088 /* Write the value of accel 13089 highg interrupt mask*/ 13090 data_u8r = 13091 BNO055_SET_BITSLICE(data_u8r, 13092 BNO055_ACCEL_HIGH_G_INTR_MASK, 13093 accel_high_g_u8); 13094 com_rslt += 13095 p_bno055->BNO055_BUS_WRITE_FUNC 13096 (p_bno055->dev_addr, 13097 BNO055_ACCEL_HIGH_G_INTR_MASK_REG, 13098 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13099 } 13100 } else { 13101 com_rslt = BNO055_ERROR; 13102 } 13103 } 13104 return com_rslt; 13105 } 13106 /*! 13107 * @brief This API used to read the accel anymotion interrupt mask 13108 * from page one register from 0x0F bit 6 13109 * 13110 * @param accel_any_motion_u8 : The value of accel anymotion interrupt mask 13111 * accel_any_motion_u8 | result 13112 * -------------------- |------------ 13113 * 0x01 | BNO055_BIT_ENABLE 13114 * 0x00 | BNO055_BIT_DISABLE 13115 * 13116 * @return results of bus communication function 13117 * @retval 0 -> BNO055_SUCCESS 13118 * @retval 1 -> BNO055_ERROR 13119 * 13120 * @note While enabling the accel highg interrupt 13121 * configure the below settings by using 13122 * the following APIs 13123 * 13124 * Axis : 13125 * 13126 * bno055_set_accel_high_g_axis_enable() 13127 * 13128 * Threshold : 13129 * 13130 * bno055_set_accel_high_g_thres() 13131 * 13132 * Duration : 13133 * 13134 * bno055_set_accel_high_g_durn() 13135 * 13136 */ 13137 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_mask_accel_any_motion( 13138 u8 *accel_any_motion_u8) 13139 { 13140 /* Variable used to return value of 13141 communication routine*/ 13142 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13143 u8 data_u8r = BNO055_INIT_VALUE; 13144 s8 stat_s8 = BNO055_ERROR; 13145 /* Check the struct p_bno055 is empty */ 13146 if (p_bno055 == BNO055_INIT_VALUE) { 13147 return BNO055_E_NULL_PTR; 13148 } else { 13149 /*condition check for page, accel anymotion interrupt mask is 13150 available in the page one*/ 13151 if (p_bno055->page_id != BNO055_PAGE_ONE) 13152 /* Write page as one */ 13153 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13154 if ((stat_s8 == BNO055_SUCCESS) || 13155 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13156 /* The value of accel anymotion interrupt mask*/ 13157 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13158 (p_bno055->dev_addr, 13159 BNO055_ACCEL_ANY_MOTION_INTR_MASK_REG, 13160 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13161 *accel_any_motion_u8 = 13162 BNO055_GET_BITSLICE(data_u8r, 13163 BNO055_ACCEL_ANY_MOTION_INTR_MASK); 13164 } else { 13165 com_rslt = BNO055_ERROR; 13166 } 13167 } 13168 return com_rslt; 13169 } 13170 /*! 13171 * @brief This API used to write the accel anymotion interrupt mask 13172 * from page one register from 0x0F bit 6 13173 * 13174 * @param accel_any_motion_u8 : The value of accel anymotion interrupt mask 13175 * accel_any_motion_u8 | result 13176 * -------------------- |------------ 13177 * 0x01 | BNO055_BIT_ENABLE 13178 * 0x00 | BNO055_BIT_DISABLE 13179 * 13180 * @return results of bus communication function 13181 * @retval 0 -> BNO055_SUCCESS 13182 * @retval 1 -> BNO055_ERROR 13183 * 13184 * @note While enabling the accel anymotion interrupt 13185 * configure the following settings 13186 * 13187 * Axis: 13188 * 13189 * bno055_set_accel_any_motion_no_motion_axis_enable() 13190 * 13191 * Duration: 13192 * 13193 * bno055_set_accel_any_motion_durn() 13194 * 13195 * Threshold: 13196 * 13197 * bno055_set_accel_any_motion_thres() 13198 * 13199 */ 13200 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_mask_accel_any_motion( 13201 u8 accel_any_motion_u8) 13202 { 13203 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13204 u8 data_u8r = BNO055_INIT_VALUE; 13205 s8 stat_s8 = BNO055_ERROR; 13206 /* Check the struct p_bno055 is empty */ 13207 if (p_bno055 == BNO055_INIT_VALUE) { 13208 return BNO055_E_NULL_PTR; 13209 } else { 13210 /*condition check for page, accel anymotion interrupt mask is 13211 available in the page one*/ 13212 if (p_bno055->page_id != BNO055_PAGE_ONE) 13213 /* Write page as one */ 13214 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13215 if ((stat_s8 == BNO055_SUCCESS) || 13216 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13217 /* Write the value of accel anymotion interrupt mask*/ 13218 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13219 (p_bno055->dev_addr, 13220 BNO055_ACCEL_ANY_MOTION_INTR_MASK_REG, 13221 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13222 if (com_rslt == BNO055_SUCCESS) { 13223 data_u8r = 13224 BNO055_SET_BITSLICE(data_u8r, 13225 BNO055_ACCEL_ANY_MOTION_INTR_MASK, 13226 accel_any_motion_u8); 13227 com_rslt += 13228 p_bno055->BNO055_BUS_WRITE_FUNC 13229 (p_bno055->dev_addr, 13230 BNO055_ACCEL_ANY_MOTION_INTR_MASK_REG, 13231 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13232 } 13233 } else { 13234 com_rslt = BNO055_ERROR; 13235 } 13236 } 13237 return com_rslt; 13238 } 13239 /*! 13240 * @brief This API used to read the accel nomotion interrupt mask 13241 * from page one register from 0x0F bit 7 13242 * 13243 * @param accel_nomotion_u8 : The value of accel nomotion interrupt mask 13244 * accel_nomotion_u8 | result 13245 * -------------------- |------------ 13246 * 0x01 | BNO055_BIT_ENABLE 13247 * 0x00 | BNO055_BIT_DISABLE 13248 * 13249 * @return results of bus communication function 13250 * @retval 0 -> BNO055_SUCCESS 13251 * 13252 * @note While enabling the accel anymotion interrupt 13253 * configure the following settings 13254 * 13255 * Axis: 13256 * 13257 * bno055_set_accel_any_motion_no_motion_axis_enable() 13258 * 13259 * Duration: 13260 * 13261 * bno055_set_accel_any_motion_durn() 13262 * 13263 * Threshold: 13264 * 13265 * bno055_set_accel_any_motion_thres()) 13266 * 13267 */ 13268 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_mask_accel_no_motion( 13269 u8 *accel_nomotion_u8) 13270 { 13271 /* Variable used to return value of 13272 communication routine*/ 13273 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13274 u8 data_u8r = BNO055_INIT_VALUE; 13275 s8 stat_s8 = BNO055_ERROR; 13276 /* Check the struct p_bno055 is empty */ 13277 if (p_bno055 == BNO055_INIT_VALUE) { 13278 return BNO055_E_NULL_PTR; 13279 } else { 13280 /*condition check for page, accel nomotion interrupt mask is 13281 available in the page one*/ 13282 if (p_bno055->page_id != BNO055_PAGE_ONE) 13283 /* Write page as one */ 13284 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13285 if ((stat_s8 == BNO055_SUCCESS) || 13286 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13287 /* Read the value of accel nomotion interrupt mask*/ 13288 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13289 (p_bno055->dev_addr, 13290 BNO055_ACCEL_NO_MOTION_INTR_MASK_REG, 13291 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13292 *accel_nomotion_u8 = 13293 BNO055_GET_BITSLICE(data_u8r, 13294 BNO055_ACCEL_NO_MOTION_INTR_MASK); 13295 } else { 13296 com_rslt = BNO055_ERROR; 13297 } 13298 } 13299 return com_rslt; 13300 } 13301 /*! 13302 * @brief This API used to write the accel nomotion interrupt mask 13303 * from page one register from 0x0F bit 7 13304 * 13305 * @param accel_nomotion_u8 : The value of accel nomotion interrupt mask 13306 * accel_nomotion_u8 | result 13307 * -------------------- |------------ 13308 * 0x01 | BNO055_BIT_ENABLE 13309 * 0x00 | BNO055_BIT_DISABLE 13310 * 13311 * @return results of bus communication function 13312 * @retval 0 -> BNO055_SUCCESS 13313 * @retval 1 -> BNO055_ERROR 13314 * 13315 * @note While enabling the accel nomotion interrupt 13316 * configure the following settings 13317 * 13318 * Axis: 13319 * 13320 * bno055_set_accel_any_motion_no_motion_axis_enable() 13321 * 13322 * Threshold : 13323 * 13324 * bno055_set_accel_slow_no_motion_thres() 13325 * 13326 * Duration : 13327 * 13328 * bno055_set_accel_slow_no_motion_durn() 13329 * 13330 * Slow/no motion enable: 13331 * 13332 * bno055_set_accel_slow_no_motion_enable() 13333 * 13334 */ 13335 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_mask_accel_no_motion( 13336 u8 accel_nomotion_u8) 13337 { 13338 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13339 u8 data_u8r = BNO055_INIT_VALUE; 13340 s8 stat_s8 = BNO055_ERROR; 13341 /* Check the struct p_bno055 is empty */ 13342 if (p_bno055 == BNO055_INIT_VALUE) { 13343 return BNO055_E_NULL_PTR; 13344 } else { 13345 /*condition check for page, accel 13346 nomotion interrupt mask is 13347 available in the page one*/ 13348 if (p_bno055->page_id != BNO055_PAGE_ONE) 13349 /* Write page as one */ 13350 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13351 if ((stat_s8 == BNO055_SUCCESS) || 13352 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13353 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13354 (p_bno055->dev_addr, 13355 BNO055_ACCEL_NO_MOTION_INTR_MASK_REG, 13356 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13357 if (com_rslt == BNO055_SUCCESS) { 13358 /* Write the value of accel 13359 nomotion interrupt mask*/ 13360 data_u8r = 13361 BNO055_SET_BITSLICE(data_u8r, 13362 BNO055_ACCEL_NO_MOTION_INTR_MASK, 13363 accel_nomotion_u8); 13364 com_rslt += 13365 p_bno055->BNO055_BUS_WRITE_FUNC 13366 (p_bno055->dev_addr, 13367 BNO055_ACCEL_NO_MOTION_INTR_MASK_REG, 13368 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13369 } 13370 } else { 13371 com_rslt = BNO055_ERROR; 13372 } 13373 } 13374 return com_rslt; 13375 } 13376 /*! 13377 * @brief This API used to read the gyro anymotion interrupt 13378 * from page one register from 0x10 bit 2 13379 * 13380 * @param gyro_any_motion_u8 : The value of gyro anymotion interrupt 13381 * gyro_any_motion_u8 | result 13382 * -------------------- |------------ 13383 * 0x01 | BNO055_BIT_ENABLE 13384 * 0x00 | BNO055_BIT_DISABLE 13385 * 13386 * @return results of bus communication function 13387 * @retval 0 -> BNO055_SUCCESS 13388 * @retval 1 -> BNO055_ERROR 13389 * 13390 * @note While enabling the gyro anymotion interrupt 13391 * configure the following settings 13392 * 13393 * Axis: 13394 * bno055_set_gyro_any_motion_axis_enable() 13395 * 13396 * Filter setting: 13397 * bno055_set_gyro_any_motion_filter() 13398 * 13399 * Threshold : 13400 * 13401 * bno055_set_gyro_any_motion_thres() 13402 * 13403 * Slope samples : 13404 * 13405 * bno055_set_gyro_any_motion_slope_samples() 13406 * 13407 * Awake duration : 13408 * 13409 * bno055_set_gyro_any_motion_awake_durn() 13410 */ 13411 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_gyro_any_motion( 13412 u8 *gyro_any_motion_u8) 13413 { 13414 /* Variable used to return value of 13415 communication routine*/ 13416 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13417 u8 data_u8r = BNO055_INIT_VALUE; 13418 s8 stat_s8 = BNO055_ERROR; 13419 /* Check the struct p_bno055 is empty */ 13420 if (p_bno055 == BNO055_INIT_VALUE) { 13421 return BNO055_E_NULL_PTR; 13422 } else { 13423 /*condition check for page, gyro anymotion interrupt is 13424 available in the page one*/ 13425 if (p_bno055->page_id != BNO055_PAGE_ONE) 13426 /* Write page as one */ 13427 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13428 if ((stat_s8 == BNO055_SUCCESS) || 13429 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13430 /* Read the value of gyro anymotion interrupt */ 13431 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13432 (p_bno055->dev_addr, 13433 BNO055_GYRO_ANY_MOTION_INTR_REG, 13434 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13435 *gyro_any_motion_u8 = 13436 BNO055_GET_BITSLICE(data_u8r, 13437 BNO055_GYRO_ANY_MOTION_INTR); 13438 } else { 13439 com_rslt = BNO055_ERROR; 13440 } 13441 } 13442 return com_rslt; 13443 } 13444 /*! 13445 * @brief This API used to write the gyro anymotion interrupt 13446 * from page one register from 0x10 bit 2 13447 * 13448 * @param gyro_any_motion_u8 : The value of gyro anymotion interrupt 13449 * gyro_any_motion_u8 | result 13450 * -------------------- |------------ 13451 * 0x01 | BNO055_BIT_ENABLE 13452 * 0x00 | BNO055_BIT_DISABLE 13453 * 13454 * @return results of bus communication function 13455 * @retval 0 -> BNO055_SUCCESS 13456 * @retval 1 -> BNO055_ERROR 13457 * 13458 * @note While enabling the gyro anymotion interrupt 13459 * configure the following settings 13460 * 13461 * Axis: 13462 * bno055_set_gyro_any_motion_axis_enable() 13463 * 13464 * Filter setting: 13465 * bno055_set_gyro_any_motion_filter() 13466 * 13467 * Threshold : 13468 * 13469 * bno055_set_gyro_any_motion_thres() 13470 * 13471 * Slope samples : 13472 * 13473 * bno055_set_gyro_any_motion_slope_samples() 13474 * 13475 * Awake duration : 13476 * 13477 * bno055_set_gyro_any_motion_awake_durn() 13478 */ 13479 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_gyro_any_motion( 13480 u8 gyro_any_motion_u8) 13481 { 13482 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13483 u8 data_u8r = BNO055_INIT_VALUE; 13484 s8 stat_s8 = BNO055_ERROR; 13485 /* Check the struct p_bno055 is empty */ 13486 if (p_bno055 == BNO055_INIT_VALUE) { 13487 return BNO055_E_NULL_PTR; 13488 } else { 13489 /*condition check for page, gyro anymotion interrupt is 13490 available in the page one*/ 13491 if (p_bno055->page_id != BNO055_PAGE_ONE) 13492 /* Write page as one */ 13493 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13494 if ((stat_s8 == BNO055_SUCCESS) || 13495 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13496 /* Write the value of gyro anymotion interrupt */ 13497 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13498 (p_bno055->dev_addr, 13499 BNO055_GYRO_ANY_MOTION_INTR_REG, 13500 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13501 if (com_rslt == BNO055_SUCCESS) { 13502 data_u8r = 13503 BNO055_SET_BITSLICE(data_u8r, 13504 BNO055_GYRO_ANY_MOTION_INTR, 13505 gyro_any_motion_u8); 13506 com_rslt += 13507 p_bno055->BNO055_BUS_WRITE_FUNC 13508 (p_bno055->dev_addr, 13509 BNO055_GYRO_ANY_MOTION_INTR_REG, 13510 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13511 } 13512 } else { 13513 com_rslt = BNO055_ERROR; 13514 } 13515 } 13516 return com_rslt; 13517 } 13518 /*! 13519 * @brief This API used to read the gyro highrate interrupt 13520 * from page one register from 0x10 bit 3 13521 * 13522 * @param gyro_highrate_u8 : The value of gyro highrate interrupt 13523 * gyro_highrate_u8 | result 13524 * -------------------- |------------ 13525 * 0x01 | BNO055_BIT_ENABLE 13526 * 0x00 | BNO055_BIT_DISABLE 13527 * 13528 * @return results of bus communication function 13529 * @retval 0 -> BNO055_SUCCESS 13530 * @retval 1 -> BNO055_ERROR 13531 * 13532 * @note While enabling the gyro highrate interrupt 13533 * configure the below settings by using 13534 * the following APIs 13535 * 13536 * Axis : 13537 * 13538 * bno055_set_gyro_highrate_axis_enable() 13539 * 13540 * Filter : 13541 * 13542 * bno055_set_gyro_highrate_filter() 13543 * 13544 * Threshold : 13545 * 13546 * bno055_get_gyro_highrate_x_thres() 13547 * 13548 * bno055_get_gyro_highrate_y_thres() 13549 * 13550 * bno055_get_gyro_highrate_z_thres() 13551 * 13552 * Hysteresis : 13553 * 13554 * bno055_set_gyro_highrate_x_hyst() 13555 * 13556 * bno055_set_gyro_highrate_y_hyst() 13557 * 13558 * bno055_set_gyro_highrate_z_hyst() 13559 * 13560 * Duration : 13561 * 13562 * bno055_set_gyro_highrate_x_durn() 13563 * 13564 * bno055_set_gyro_highrate_y_durn() 13565 * 13566 * bno055_set_gyro_highrate_z_durn() 13567 * 13568 */ 13569 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_gyro_highrate( 13570 u8 *gyro_highrate_u8) 13571 { 13572 /* Variable used to return value of 13573 communication routine*/ 13574 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13575 u8 data_u8r = BNO055_INIT_VALUE; 13576 s8 stat_s8 = BNO055_ERROR; 13577 /* Check the struct p_bno055 is empty */ 13578 if (p_bno055 == BNO055_INIT_VALUE) { 13579 return BNO055_E_NULL_PTR; 13580 } else { 13581 /*condition check for page, gyro highrate interrupt is 13582 available in the page one*/ 13583 if (p_bno055->page_id != BNO055_PAGE_ONE) 13584 /* Write page as one */ 13585 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13586 if ((stat_s8 == BNO055_SUCCESS) || 13587 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13588 /* Read the value of gyro highrate interrupt */ 13589 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13590 (p_bno055->dev_addr, 13591 BNO055_GYRO_HIGHRATE_INTR_REG, 13592 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13593 *gyro_highrate_u8 = 13594 BNO055_GET_BITSLICE(data_u8r, 13595 BNO055_GYRO_HIGHRATE_INTR); 13596 } else { 13597 com_rslt = BNO055_ERROR; 13598 } 13599 } 13600 return com_rslt; 13601 } 13602 /*! 13603 * @brief This API used to write the gyro highrate interrupt 13604 * from page one register from 0x10 bit 3 13605 * 13606 * @param gyro_highrate_u8 : The value of gyro highrate interrupt 13607 * gyro_highrate_u8 | result 13608 * -------------------- |------------ 13609 * 0x01 | BNO055_BIT_ENABLE 13610 * 0x00 | BNO055_BIT_DISABLE 13611 * 13612 * @return results of bus communication function 13613 * @retval 0 -> BNO055_SUCCESS 13614 * @retval 1 -> BNO055_ERROR 13615 * 13616 * @note While enabling the gyro highrate interrupt 13617 * configure the below settings by using 13618 * the following APIs 13619 * 13620 * Axis : 13621 * 13622 * bno055_set_gyro_highrate_axis_enable() 13623 * 13624 * Filter : 13625 * 13626 * bno055_set_gyro_highrate_filter() 13627 * 13628 * Threshold : 13629 * 13630 * bno055_get_gyro_highrate_x_thres() 13631 * 13632 * bno055_get_gyro_highrate_y_thres() 13633 * 13634 * bno055_get_gyro_highrate_z_thres() 13635 * 13636 * Hysteresis : 13637 * 13638 * bno055_set_gyro_highrate_x_hyst() 13639 * 13640 * bno055_set_gyro_highrate_y_hyst() 13641 * 13642 * bno055_set_gyro_highrate_z_hyst() 13643 * 13644 * Duration : 13645 * 13646 * bno055_set_gyro_highrate_x_durn() 13647 * 13648 * bno055_set_gyro_highrate_y_durn() 13649 * 13650 * bno055_set_gyro_highrate_z_durn() 13651 * 13652 */ 13653 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_gyro_highrate( 13654 u8 gyro_highrate_u8) 13655 { 13656 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13657 u8 data_u8r = BNO055_INIT_VALUE; 13658 s8 stat_s8 = BNO055_ERROR; 13659 /* Check the struct p_bno055 is empty */ 13660 if (p_bno055 == BNO055_INIT_VALUE) { 13661 return BNO055_E_NULL_PTR; 13662 } else { 13663 /*condition check for page, gyro highrate interrupt is 13664 available in the page one*/ 13665 if (p_bno055->page_id != BNO055_PAGE_ONE) 13666 /* Write page as one */ 13667 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13668 if ((stat_s8 == BNO055_SUCCESS) || 13669 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13670 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13671 (p_bno055->dev_addr, 13672 BNO055_GYRO_HIGHRATE_INTR_REG, 13673 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13674 if (com_rslt == BNO055_SUCCESS) { 13675 /* Write the value of gyro highrate interrupt */ 13676 data_u8r = 13677 BNO055_SET_BITSLICE(data_u8r, 13678 BNO055_GYRO_HIGHRATE_INTR, gyro_highrate_u8); 13679 com_rslt += 13680 p_bno055->BNO055_BUS_WRITE_FUNC 13681 (p_bno055->dev_addr, 13682 BNO055_GYRO_HIGHRATE_INTR_REG, 13683 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13684 } 13685 } else { 13686 com_rslt = BNO055_ERROR; 13687 } 13688 } 13689 return com_rslt; 13690 } 13691 /*! 13692 * @brief This API used to read the accel highg interrupt 13693 * from page one register from 0x10 bit 5 13694 * 13695 * @param accel_high_g_u8 : The value of accel highg interrupt 13696 * accel_high_g_u8 | result 13697 * -------------------- |------------ 13698 * 0x01 | BNO055_BIT_ENABLE 13699 * 0x00 | BNO055_BIT_DISABLE 13700 * 13701 * @return results of bus communication function 13702 * @retval 0 -> BNO055_SUCCESS 13703 * @retval 1 -> BNO055_ERROR 13704 * 13705 * @note While enabling the accel highg interrupt 13706 * configure the below settings by using 13707 * the following APIs 13708 * 13709 * Axis : 13710 * 13711 * bno055_set_accel_high_g_axis_enable() 13712 * 13713 * Threshold : 13714 * 13715 * bno055_set_accel_high_g_thres() 13716 * 13717 * Duration : 13718 * 13719 * bno055_set_accel_high_g_durn() 13720 * 13721 */ 13722 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_accel_high_g( 13723 u8 *accel_high_g_u8) 13724 { 13725 /* Variable used to return value of 13726 communication routine*/ 13727 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13728 u8 data_u8r = BNO055_INIT_VALUE; 13729 s8 stat_s8 = BNO055_ERROR; 13730 /* Check the struct p_bno055 is empty */ 13731 if (p_bno055 == BNO055_INIT_VALUE) { 13732 return BNO055_E_NULL_PTR; 13733 } else { 13734 /*condition check for page, accel highg interrupt is 13735 available in the page one*/ 13736 if (p_bno055->page_id != BNO055_PAGE_ONE) 13737 /* Write page as one */ 13738 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13739 if ((stat_s8 == BNO055_SUCCESS) || 13740 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13741 /* Read the value of accel highg interrupt*/ 13742 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13743 (p_bno055->dev_addr, 13744 BNO055_ACCEL_HIGH_G_INTR_REG, 13745 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13746 *accel_high_g_u8 = 13747 BNO055_GET_BITSLICE(data_u8r, 13748 BNO055_ACCEL_HIGH_G_INTR); 13749 } else { 13750 com_rslt = BNO055_ERROR; 13751 } 13752 } 13753 return com_rslt; 13754 } 13755 /*! 13756 * @brief This API used to write the accel highg interrupt 13757 * from page one register from 0x10 bit 5 13758 * 13759 * @param accel_high_g_u8 : The value of accel highg interrupt 13760 * accel_high_g_u8 | result 13761 * -------------------- |------------ 13762 * 0x01 | BNO055_BIT_ENABLE 13763 * 0x00 | BNO055_BIT_DISABLE 13764 * 13765 * @return results of bus communication function 13766 * @retval 0 -> BNO055_SUCCESS 13767 * @retval 1 -> BNO055_ERROR 13768 * 13769 * @note While enabling the accel highg interrupt 13770 * configure the below settings by using 13771 * the following APIs 13772 * 13773 * Axis : 13774 * 13775 * bno055_set_accel_high_g_axis_enable() 13776 * 13777 * Threshold : 13778 * 13779 * bno055_set_accel_high_g_thres() 13780 * 13781 * Duration : 13782 * 13783 * bno055_set_accel_high_g_durn() 13784 * 13785 */ 13786 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_accel_high_g( 13787 u8 accel_high_g_u8) 13788 { 13789 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13790 u8 data_u8r = BNO055_INIT_VALUE; 13791 s8 stat_s8 = BNO055_ERROR; 13792 /* Check the struct p_bno055 is empty */ 13793 if (p_bno055 == BNO055_INIT_VALUE) { 13794 return BNO055_E_NULL_PTR; 13795 } else { 13796 /*condition check for page, accel highg interrupt is 13797 available in the page one*/ 13798 if (p_bno055->page_id != BNO055_PAGE_ONE) 13799 /* Write page as one */ 13800 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13801 if ((stat_s8 == BNO055_SUCCESS) || 13802 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13803 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13804 (p_bno055->dev_addr, 13805 BNO055_ACCEL_HIGH_G_INTR_REG, 13806 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13807 if (com_rslt == BNO055_SUCCESS) { 13808 /* Write the value of accel highg interrupt*/ 13809 data_u8r = 13810 BNO055_SET_BITSLICE(data_u8r, 13811 BNO055_ACCEL_HIGH_G_INTR, 13812 accel_high_g_u8); 13813 com_rslt += 13814 p_bno055->BNO055_BUS_WRITE_FUNC 13815 (p_bno055->dev_addr, 13816 BNO055_ACCEL_HIGH_G_INTR_REG, 13817 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13818 } 13819 } else { 13820 com_rslt = BNO055_ERROR; 13821 } 13822 } 13823 return com_rslt; 13824 } 13825 /*! 13826 * @brief This API used to read the accel anymotion interrupt 13827 * from page one register from 0x10 bit 6 13828 * 13829 * @param accel_any_motion_u8 : The value of accel anymotion interrupt 13830 * accel_any_motion_u8 | result 13831 * -------------------- |------------ 13832 * 0x01 | BNO055_BIT_ENABLE 13833 * 0x00 | BNO055_BIT_DISABLE 13834 * 13835 * @return results of bus communication function 13836 * @retval 0 -> BNO055_SUCCESS 13837 * @retval 1 -> BNO055_ERROR 13838 * 13839 * @note While enabling the accel anymotion interrupt 13840 * configure the following settings 13841 * 13842 * Axis: 13843 * 13844 * bno055_set_accel_any_motion_no_motion_axis_enable() 13845 * 13846 * Duration: 13847 * 13848 * bno055_set_accel_any_motion_durn() 13849 * 13850 * Threshold: 13851 * 13852 * bno055_set_accel_any_motion_thres() 13853 * 13854 */ 13855 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_accel_any_motion( 13856 u8 *accel_any_motion_u8) 13857 { 13858 /* Variable used to return value of 13859 communication routine*/ 13860 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13861 u8 data_u8r = BNO055_INIT_VALUE; 13862 s8 stat_s8 = BNO055_ERROR; 13863 /* Check the struct p_bno055 is empty */ 13864 if (p_bno055 == BNO055_INIT_VALUE) { 13865 return BNO055_E_NULL_PTR; 13866 } else { 13867 /*condition check for page, accel anymotion interrupt is 13868 available in the page one*/ 13869 if (p_bno055->page_id != BNO055_PAGE_ONE) 13870 /* Write page as one */ 13871 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13872 if ((stat_s8 == BNO055_SUCCESS) || 13873 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13874 /* Read the value of accel anymotion interrupt */ 13875 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13876 (p_bno055->dev_addr, 13877 BNO055_ACCEL_ANY_MOTION_INTR_REG, 13878 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13879 *accel_any_motion_u8 = 13880 BNO055_GET_BITSLICE(data_u8r, 13881 BNO055_ACCEL_ANY_MOTION_INTR); 13882 } else { 13883 com_rslt = BNO055_ERROR; 13884 } 13885 } 13886 return com_rslt; 13887 } 13888 /*! 13889 * @brief This API used to write the accel anymotion interrupt 13890 * from page one register from 0x10 bit 6 13891 * 13892 * @param accel_any_motion_u8 : The value of accel anymotion interrupt 13893 * accel_any_motion_u8 | result 13894 * -------------------- |------------ 13895 * 0x01 | BNO055_BIT_ENABLE 13896 * 0x00 | BNO055_BIT_DISABLE 13897 * 13898 * @return results of bus communication function 13899 * @retval 0 -> BNO055_SUCCESS 13900 * @retval 1 -> BNO055_ERROR 13901 * 13902 * @note While enabling the accel anymotion interrupt 13903 * configure the following settings 13904 * 13905 * Axis: 13906 * 13907 * bno055_set_accel_any_motion_no_motion_axis_enable() 13908 * 13909 * Duration: 13910 * 13911 * bno055_set_accel_any_motion_durn() 13912 * 13913 * Threshold: 13914 * 13915 * bno055_set_accel_any_motion_thres() 13916 * 13917 */ 13918 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_accel_any_motion( 13919 u8 accel_any_motion_u8) 13920 { 13921 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13922 u8 data_u8r = BNO055_INIT_VALUE; 13923 s8 stat_s8 = BNO055_ERROR; 13924 /* Check the struct p_bno055 is empty */ 13925 if (p_bno055 == BNO055_INIT_VALUE) { 13926 return BNO055_E_NULL_PTR; 13927 } else { 13928 /*condition check for page, accel range is 13929 available in the page one*/ 13930 if (p_bno055->page_id != BNO055_PAGE_ONE) 13931 /* Write page as one */ 13932 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 13933 if ((stat_s8 == BNO055_SUCCESS) || 13934 (p_bno055->page_id == BNO055_PAGE_ONE)) { 13935 /* Write the value of accel anymotion interrupt */ 13936 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 13937 (p_bno055->dev_addr, 13938 BNO055_ACCEL_ANY_MOTION_INTR_REG, 13939 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13940 if (com_rslt == BNO055_SUCCESS) { 13941 data_u8r = 13942 BNO055_SET_BITSLICE(data_u8r, 13943 BNO055_ACCEL_ANY_MOTION_INTR, 13944 accel_any_motion_u8); 13945 com_rslt += 13946 p_bno055->BNO055_BUS_WRITE_FUNC 13947 (p_bno055->dev_addr, 13948 BNO055_ACCEL_ANY_MOTION_INTR_REG, 13949 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 13950 } 13951 } else { 13952 com_rslt = BNO055_ERROR; 13953 } 13954 } 13955 return com_rslt; 13956 } 13957 /*! 13958 * @brief This API used to read the accel nomotion interrupt 13959 * from page one register from 0x10 bit 6 13960 * 13961 * @param accel_nomotion_u8 : The value of accel nomotion interrupt 13962 * accel_nomotion_u8 | result 13963 * -------------------- |------------ 13964 * 0x01 | BNO055_BIT_ENABLE 13965 * 0x00 | BNO055_BIT_DISABLE 13966 * 13967 * @return results of bus communication function 13968 * @retval 0 -> BNO055_SUCCESS 13969 * @retval 1 -> BNO055_ERROR 13970 * 13971 * @note While enabling the accel nomotion interrupt 13972 * configure the following settings 13973 * 13974 * Axis: 13975 * 13976 * bno055_set_accel_any_motion_no_motion_axis_enable() 13977 * 13978 * Threshold : 13979 * 13980 * bno055_set_accel_slow_no_motion_thres() 13981 * 13982 * Duration : 13983 * 13984 * bno055_set_accel_slow_no_motion_durn() 13985 * 13986 * Slow/no motion enable: 13987 * 13988 * bno055_set_accel_slow_no_motion_enable() 13989 * 13990 */ 13991 BNO055_RETURN_FUNCTION_TYPE bno055_get_intr_accel_no_motion( 13992 u8 *accel_nomotion_u8) 13993 { 13994 /* Variable used to return value of 13995 communication routine*/ 13996 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 13997 u8 data_u8r = BNO055_INIT_VALUE; 13998 s8 stat_s8 = BNO055_ERROR; 13999 /* Check the struct p_bno055 is empty */ 14000 if (p_bno055 == BNO055_INIT_VALUE) { 14001 return BNO055_E_NULL_PTR; 14002 } else { 14003 /*condition check for page, accel nomotion interrupt is 14004 available in the page one*/ 14005 if (p_bno055->page_id != BNO055_PAGE_ONE) 14006 /* Write page as one */ 14007 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14008 if ((stat_s8 == BNO055_SUCCESS) || 14009 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14010 /* Read the value of accel nomotion interrupt*/ 14011 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14012 (p_bno055->dev_addr, 14013 BNO055_ACCEL_NO_MOTION_INTR_REG, 14014 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14015 *accel_nomotion_u8 = 14016 BNO055_GET_BITSLICE(data_u8r, 14017 BNO055_ACCEL_NO_MOTION_INTR); 14018 } else { 14019 com_rslt = BNO055_ERROR; 14020 } 14021 } 14022 return com_rslt; 14023 } 14024 /*! 14025 * @brief This API used to write the accel nomotion interrupt 14026 * from page one register from 0x10 bit 6 14027 * 14028 * @param accel_nomotion_u8 : The value of accel nomotion interrupt 14029 * accel_nomotion_u8 | result 14030 * -------------------- |------------ 14031 * 0x01 | BNO055_BIT_ENABLE 14032 * 0x00 | BNO055_BIT_DISABLE 14033 * 14034 * @return results of bus communication function 14035 * @retval 0 -> BNO055_SUCCESS 14036 * @retval 1 -> BNO055_ERROR 14037 * 14038 * @note While enabling the accel nomotion interrupt 14039 * configure the following settings 14040 * 14041 * Axis: 14042 * 14043 * bno055_set_accel_any_motion_no_motion_axis_enable() 14044 * 14045 * Threshold : 14046 * 14047 * bno055_set_accel_slow_no_motion_thres() 14048 * 14049 * Duration : 14050 * 14051 * bno055_set_accel_slow_no_motion_durn() 14052 * 14053 * Slow/no motion enable: 14054 * 14055 * bno055_set_accel_slow_no_motion_enable() 14056 * 14057 */ 14058 BNO055_RETURN_FUNCTION_TYPE bno055_set_intr_accel_no_motion( 14059 u8 accel_nomotion_u8) 14060 { 14061 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14062 u8 data_u8r = BNO055_INIT_VALUE; 14063 s8 stat_s8 = BNO055_ERROR; 14064 /* Check the struct p_bno055 is empty */ 14065 if (p_bno055 == BNO055_INIT_VALUE) { 14066 return BNO055_E_NULL_PTR; 14067 } else { 14068 /*condition check for page, 14069 accel nomotion interrupt is 14070 available in the page one*/ 14071 if (p_bno055->page_id != BNO055_PAGE_ONE) 14072 /* Write page as one */ 14073 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14074 if ((stat_s8 == BNO055_SUCCESS) || 14075 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14076 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14077 (p_bno055->dev_addr, 14078 BNO055_ACCEL_NO_MOTION_INTR_REG, 14079 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14080 if (com_rslt == BNO055_SUCCESS) { 14081 /* Write the value of 14082 accel nomotion interrupt */ 14083 data_u8r = BNO055_SET_BITSLICE(data_u8r, 14084 BNO055_ACCEL_NO_MOTION_INTR, 14085 accel_nomotion_u8); 14086 com_rslt += p_bno055->BNO055_BUS_WRITE_FUNC 14087 (p_bno055->dev_addr, 14088 BNO055_ACCEL_NO_MOTION_INTR_REG, 14089 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14090 } 14091 } else { 14092 com_rslt = BNO055_ERROR; 14093 } 14094 } 14095 return com_rslt; 14096 } 14097 /*! 14098 * @brief This API used to read the accel any motion threshold 14099 * from page one register from 0x11 bit 0 to 7 14100 * 14101 * @param accel_any_motion_thres_u8 : The value of any motion threshold 14102 * accel_any_motion_thres_u8 | result 14103 * ------------------------ | ------------- 14104 * 0x01 | BNO055_BIT_ENABLE 14105 * 0x00 | BNO055_BIT_DISABLE 14106 * 14107 * @return results of bus communication function 14108 * @retval 0 -> BNO055_SUCCESS 14109 * @retval 1 -> BNO055_ERROR 14110 * 14111 * @note Accel anymotion threshold dependent on the 14112 * range values 14113 * 14114 * accel_range_u8 | threshold | LSB 14115 * ------------- | ------------- | --------- 14116 * 2g | 3.19mg | 1LSB 14117 * 4g | 7.81mg | 1LSB 14118 * 8g | 15.63mg | 1LSB 14119 * 16g | 31.25mg | 1LSB 14120 * 14121 */ 14122 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_any_motion_thres( 14123 u8 *accel_any_motion_thres_u8) 14124 { 14125 /* Variable used to return value of 14126 communication routine*/ 14127 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14128 u8 data_u8r = BNO055_INIT_VALUE; 14129 s8 stat_s8 = BNO055_ERROR; 14130 /* Check the struct p_bno055 is empty */ 14131 if (p_bno055 == BNO055_INIT_VALUE) { 14132 return BNO055_E_NULL_PTR; 14133 } else { 14134 /*condition check for page, accel any motion threshold is 14135 available in the page one*/ 14136 if (p_bno055->page_id != BNO055_PAGE_ONE) 14137 /* Write page as one */ 14138 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14139 if ((stat_s8 == BNO055_SUCCESS) || 14140 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14141 /* Read the value of accel any motion threshold */ 14142 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14143 (p_bno055->dev_addr, 14144 BNO055_ACCEL_ANY_MOTION_THRES_REG, 14145 &data_u8r, 14146 BNO055_GEN_READ_WRITE_LENGTH); 14147 *accel_any_motion_thres_u8 = 14148 BNO055_GET_BITSLICE(data_u8r, 14149 BNO055_ACCEL_ANY_MOTION_THRES); 14150 } else { 14151 com_rslt = BNO055_ERROR; 14152 } 14153 } 14154 return com_rslt; 14155 } 14156 /*! 14157 * @brief This API used to write the accel any motion threshold 14158 * from page one register from 0x11 bit 0 to 7 14159 * 14160 * @param accel_any_motion_thres_u8 : The value of any motion threshold 14161 * accel_any_motion_thres_u8 | result 14162 * ------------------------ | ------------- 14163 * 0x01 | BNO055_BIT_ENABLE 14164 * 0x00 | BNO055_BIT_DISABLE 14165 * 14166 * @return results of bus communication function 14167 * @retval 0 -> BNO055_SUCCESS 14168 * @retval 1 -> BNO055_ERROR 14169 * 14170 * @note Accel anymotion threshold dependent on the 14171 * range values 14172 * 14173 * accel_range_u8 | threshold | LSB 14174 * ------------- | ------------- | --------- 14175 * 2g | 3.19mg | 1LSB 14176 * 4g | 7.81mg | 1LSB 14177 * 8g | 15.63mg | 1LSB 14178 * 16g | 31.25mg | 1LSB 14179 * 14180 */ 14181 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_any_motion_thres( 14182 u8 accel_any_motion_thres_u8) 14183 { 14184 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14185 u8 data_u8r = BNO055_INIT_VALUE; 14186 s8 stat_s8 = BNO055_ERROR; 14187 s8 pg_stat_s8 = BNO055_ERROR; 14188 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 14189 /* Check the struct p_bno055 is empty */ 14190 if (p_bno055 == BNO055_INIT_VALUE) { 14191 return BNO055_E_NULL_PTR; 14192 } else { 14193 /* The write operation effective only if the operation 14194 mode is in config mode, this part of code is checking the 14195 current operation mode and set the config mode */ 14196 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 14197 if (stat_s8 == BNO055_SUCCESS) { 14198 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14199 stat_s8 += bno055_set_operation_mode 14200 (BNO055_OPERATION_MODE_CONFIG); 14201 if (stat_s8 == BNO055_SUCCESS) { 14202 /* Write page as one */ 14203 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14204 if (pg_stat_s8 == BNO055_SUCCESS) { 14205 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14206 (p_bno055->dev_addr, 14207 BNO055_ACCEL_ANY_MOTION_THRES_REG, 14208 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14209 if (com_rslt == BNO055_SUCCESS) { 14210 /* Write the value of 14211 accel any motion threshold*/ 14212 data_u8r = 14213 BNO055_SET_BITSLICE(data_u8r, 14214 BNO055_ACCEL_ANY_MOTION_THRES, 14215 accel_any_motion_thres_u8); 14216 com_rslt += 14217 p_bno055->BNO055_BUS_WRITE_FUNC 14218 (p_bno055->dev_addr, 14219 BNO055_ACCEL_ANY_MOTION_THRES_REG, 14220 &data_u8r, 14221 BNO055_GEN_READ_WRITE_LENGTH); 14222 } 14223 } else { 14224 com_rslt = BNO055_ERROR; 14225 } 14226 } else { 14227 com_rslt = BNO055_ERROR; 14228 } 14229 } else { 14230 com_rslt = BNO055_ERROR; 14231 } 14232 } 14233 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14234 /* set the operation mode of 14235 previous operation mode*/ 14236 com_rslt += bno055_set_operation_mode 14237 (prev_opmode_u8); 14238 return com_rslt; 14239 } 14240 /*! 14241 * @brief This API used to read the accel anymotion duration 14242 * from page one register from 0x12 bit 0 to 1 14243 * 14244 * @param accel_any_motion_durn_u8 : The value of accel anymotion duration 14245 * accel_any_motion_durn_u8 | result 14246 * ------------------------- | ------------- 14247 * 0x01 | BNO055_BIT_ENABLE 14248 * 0x00 | BNO055_BIT_DISABLE 14249 * 14250 * @return results of bus communication function 14251 * @retval 0 -> BNO055_SUCCESS 14252 * @retval 1 -> BNO055_ERROR 14253 * 14254 * 14255 */ 14256 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_any_motion_durn( 14257 u8 *accel_any_motion_durn_u8) 14258 { 14259 /* Variable used to return value of 14260 communication routine*/ 14261 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14262 u8 data_u8r = BNO055_INIT_VALUE; 14263 s8 stat_s8 = BNO055_ERROR; 14264 /* Check the struct p_bno055 is empty */ 14265 if (p_bno055 == BNO055_INIT_VALUE) { 14266 return BNO055_E_NULL_PTR; 14267 } else { 14268 /*condition check for page, accel anymotion duration is 14269 available in the page one*/ 14270 if (p_bno055->page_id != BNO055_PAGE_ONE) 14271 /* Write page as one */ 14272 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14273 if ((stat_s8 == BNO055_SUCCESS) || 14274 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14275 /* Read the value of accel anymotion duration */ 14276 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14277 (p_bno055->dev_addr, 14278 BNO055_ACCEL_ANY_MOTION_DURN_SET_REG, 14279 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14280 *accel_any_motion_durn_u8 = 14281 BNO055_GET_BITSLICE(data_u8r, 14282 BNO055_ACCEL_ANY_MOTION_DURN_SET); 14283 } else { 14284 com_rslt = BNO055_ERROR; 14285 } 14286 } 14287 return com_rslt; 14288 } 14289 /*! 14290 * @brief This API used to write the accel anymotion duration 14291 * from page one register from 0x12 bit 0 to 1 14292 * 14293 * @param accel_any_motion_durn_u8 : The value of accel anymotion duration 14294 * 14295 * accel_any_motion_durn_u8 | result 14296 * ------------------------- | ------------- 14297 * 0x01 | BNO055_BIT_ENABLE 14298 * 0x00 | BNO055_BIT_DISABLE 14299 * 14300 * @return results of bus communication function 14301 * @retval 0 -> BNO055_SUCCESS 14302 * @retval 1 -> BNO055_ERROR 14303 * 14304 * 14305 */ 14306 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_any_motion_durn( 14307 u8 accel_any_motion_durn_u8) 14308 { 14309 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14310 u8 data_u8r = BNO055_INIT_VALUE; 14311 s8 stat_s8 = BNO055_ERROR; 14312 s8 pg_stat_s8 = BNO055_ERROR; 14313 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 14314 /* Check the struct p_bno055 is empty */ 14315 if (p_bno055 == BNO055_INIT_VALUE) { 14316 return BNO055_E_NULL_PTR; 14317 } else { 14318 /* The write operation effective only if the operation 14319 mode is in config mode, this part of code is checking the 14320 current operation mode and set the config mode */ 14321 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 14322 if (stat_s8 == BNO055_SUCCESS) { 14323 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14324 stat_s8 += bno055_set_operation_mode 14325 (BNO055_OPERATION_MODE_CONFIG); 14326 if (stat_s8 == BNO055_SUCCESS) { 14327 /* Write page as one */ 14328 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14329 if (pg_stat_s8 == BNO055_SUCCESS) { 14330 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14331 (p_bno055->dev_addr, 14332 BNO055_ACCEL_ANY_MOTION_DURN_SET_REG, 14333 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14334 if (com_rslt == BNO055_SUCCESS) { 14335 /* Write the value of 14336 accel anymotion duration*/ 14337 data_u8r = 14338 BNO055_SET_BITSLICE(data_u8r, 14339 BNO055_ACCEL_ANY_MOTION_DURN_SET, 14340 accel_any_motion_durn_u8); 14341 com_rslt += 14342 p_bno055->BNO055_BUS_WRITE_FUNC 14343 (p_bno055->dev_addr, 14344 BNO055_ACCEL_ANY_MOTION_DURN_SET_REG, 14345 &data_u8r, 14346 BNO055_GEN_READ_WRITE_LENGTH); 14347 } 14348 } else { 14349 com_rslt = BNO055_ERROR; 14350 } 14351 } else { 14352 com_rslt = BNO055_ERROR; 14353 } 14354 } else { 14355 com_rslt = BNO055_ERROR; 14356 } 14357 } 14358 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14359 /* set the operation mode of 14360 previous operation mode*/ 14361 com_rslt += bno055_set_operation_mode 14362 (prev_opmode_u8); 14363 return com_rslt; 14364 } 14365 /*! 14366 * @brief This API used to read the accel anymotion enable 14367 * from page one register from 0x12 bit 2 to 4 14368 * 14369 * @param data_u8 : The value of accel anymotion enable 14370 * data_u8 | result 14371 * ------------ | ------------- 14372 * 0x01 | BNO055_BIT_ENABLE 14373 * 0x00 | BNO055_BIT_DISABLE 14374 * @param channel_u8 : The value of accel anymotion axis selection 14375 * channel_u8 | value 14376 * -------------------------- | ---------- 14377 * BNO055_ACCEL_ANY_MOTION_NO_MOTION_X_AXIS | 0 14378 * BNO055_ACCEL_ANY_MOTION_NO_MOTION_Y_AXIS | 1 14379 * BNO055_ACCEL_ANY_MOTION_NO_MOTION_Y_AXIS | 2 14380 * 14381 * @return results of bus communication function 14382 * @retval 0 -> BNO055_SUCCESS 14383 * @retval 1 -> BNO055_ERROR 14384 * 14385 * 14386 */ 14387 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_any_motion_no_motion_axis_enable( 14388 u8 channel_u8, u8 *data_u8) 14389 { 14390 /* Variable used to return value of 14391 communication routine*/ 14392 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14393 u8 data_u8r = BNO055_INIT_VALUE; 14394 s8 stat_s8 = BNO055_ERROR; 14395 /* Check the struct p_bno055 is empty */ 14396 if (p_bno055 == BNO055_INIT_VALUE) { 14397 return BNO055_E_NULL_PTR; 14398 } else { 14399 /*condition check for page, accel anymotion enable is 14400 available in the page one*/ 14401 if (p_bno055->page_id != BNO055_PAGE_ONE) 14402 /* Write page as one */ 14403 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14404 if ((stat_s8 == BNO055_SUCCESS) || 14405 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14406 switch (channel_u8) { 14407 case BNO055_ACCEL_ANY_MOTION_NO_MOTION_X_AXIS: 14408 /* Read the value of accel anymotion x enable*/ 14409 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14410 (p_bno055->dev_addr, 14411 BNO055_ACCEL_ANY_MOTION_X_AXIS_REG, 14412 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14413 *data_u8 = 14414 BNO055_GET_BITSLICE(data_u8r, 14415 BNO055_ACCEL_ANY_MOTION_X_AXIS); 14416 break; 14417 case BNO055_ACCEL_ANY_MOTION_NO_MOTION_Y_AXIS: 14418 /* Read the value of accel anymotion y enable*/ 14419 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14420 (p_bno055->dev_addr, 14421 BNO055_ACCEL_ANY_MOTION_Y_AXIS_REG, 14422 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14423 *data_u8 = 14424 BNO055_GET_BITSLICE(data_u8r, 14425 BNO055_ACCEL_ANY_MOTION_Y_AXIS); 14426 break; 14427 case BNO055_ACCEL_ANY_MOTION_NO_MOTION_Z_AXIS: 14428 /* Read the value of accel anymotion z enable*/ 14429 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14430 (p_bno055->dev_addr, 14431 BNO055_ACCEL_ANY_MOTION_Z_AXIS_REG, 14432 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14433 *data_u8 = 14434 BNO055_GET_BITSLICE(data_u8r, 14435 BNO055_ACCEL_ANY_MOTION_Z_AXIS); 14436 break; 14437 default: 14438 com_rslt = BNO055_OUT_OF_RANGE; 14439 break; 14440 } 14441 } else { 14442 com_rslt = BNO055_ERROR; 14443 } 14444 } 14445 return com_rslt; 14446 } 14447 /*! 14448 * @brief This API used to write the accel anymotion enable 14449 * from page one register from 0x12 bit 2 to 4 14450 * 14451 * @param data_u8 : The value of accel anymotion enable 14452 * data_u8 | result 14453 * ------------ | ------------- 14454 * 0x01 | BNO055_BIT_ENABLE 14455 * 0x00 | BNO055_BIT_DISABLE 14456 * @param channel_u8 : The value of accel anymotion axis selection 14457 * channel_u8 | value 14458 * -------------------------- | ---------- 14459 * BNO055_ACCEL_ANY_MOTION_NO_MOTION_X_AXIS | 0 14460 * BNO055_ACCEL_ANY_MOTION_NO_MOTION_Y_AXIS | 1 14461 * BNO055_ACCEL_ANY_MOTION_NO_MOTION_Y_AXIS | 2 14462 * 14463 * @return results of bus communication function 14464 * @retval 0 -> BNO055_SUCCESS 14465 * @retval 1 -> BNO055_ERROR 14466 * 14467 * 14468 */ 14469 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_any_motion_no_motion_axis_enable( 14470 u8 channel_u8, u8 data_u8) 14471 { 14472 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14473 u8 data_u8r = BNO055_INIT_VALUE; 14474 s8 stat_s8 = BNO055_ERROR; 14475 s8 pg_stat_s8 = BNO055_ERROR; 14476 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 14477 /* Check the struct p_bno055 is empty */ 14478 if (p_bno055 == BNO055_INIT_VALUE) { 14479 return BNO055_E_NULL_PTR; 14480 } else { 14481 /* The write operation effective only if the operation 14482 mode is in config mode, this part of code is checking the 14483 current operation mode and set the config mode */ 14484 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 14485 if (stat_s8 == BNO055_SUCCESS) { 14486 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14487 stat_s8 += bno055_set_operation_mode 14488 (BNO055_OPERATION_MODE_CONFIG); 14489 if (stat_s8 == BNO055_SUCCESS) { 14490 /* Write page as one */ 14491 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14492 if (pg_stat_s8 == BNO055_SUCCESS) { 14493 switch (channel_u8) { 14494 case BNO055_ACCEL_ANY_MOTION_NO_MOTION_X_AXIS: 14495 /* Write the value of 14496 accel anymotion x enable*/ 14497 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14498 (p_bno055->dev_addr, 14499 BNO055_ACCEL_ANY_MOTION_X_AXIS_REG, 14500 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14501 if (com_rslt == BNO055_SUCCESS) { 14502 data_u8r = BNO055_SET_BITSLICE 14503 (data_u8r, 14504 BNO055_ACCEL_ANY_MOTION_X_AXIS, 14505 data_u8); 14506 com_rslt += 14507 p_bno055->BNO055_BUS_WRITE_FUNC 14508 (p_bno055->dev_addr, 14509 BNO055_ACCEL_ANY_MOTION_X_AXIS_REG, 14510 &data_u8r, 14511 BNO055_GEN_READ_WRITE_LENGTH); 14512 } 14513 break; 14514 case BNO055_ACCEL_ANY_MOTION_NO_MOTION_Y_AXIS: 14515 /* Write the value of 14516 accel anymotion y enable*/ 14517 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14518 (p_bno055->dev_addr, 14519 BNO055_ACCEL_ANY_MOTION_Y_AXIS_REG, 14520 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14521 if (com_rslt == BNO055_SUCCESS) { 14522 data_u8r = BNO055_SET_BITSLICE 14523 (data_u8r, 14524 BNO055_ACCEL_ANY_MOTION_Y_AXIS, 14525 data_u8); 14526 com_rslt += 14527 p_bno055->BNO055_BUS_WRITE_FUNC 14528 (p_bno055->dev_addr, 14529 BNO055_ACCEL_ANY_MOTION_Y_AXIS_REG, 14530 &data_u8r, 14531 BNO055_GEN_READ_WRITE_LENGTH); 14532 } 14533 break; 14534 case BNO055_ACCEL_ANY_MOTION_NO_MOTION_Z_AXIS: 14535 /* Write the value of 14536 accel anymotion z enable*/ 14537 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14538 (p_bno055->dev_addr, 14539 BNO055_ACCEL_ANY_MOTION_Z_AXIS_REG, 14540 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14541 if (com_rslt == BNO055_SUCCESS) { 14542 data_u8r = BNO055_SET_BITSLICE 14543 (data_u8r, 14544 BNO055_ACCEL_ANY_MOTION_Z_AXIS, 14545 data_u8); 14546 com_rslt += 14547 p_bno055->BNO055_BUS_WRITE_FUNC 14548 (p_bno055->dev_addr, 14549 BNO055_ACCEL_ANY_MOTION_Z_AXIS_REG, 14550 &data_u8r, 14551 BNO055_GEN_READ_WRITE_LENGTH); 14552 } 14553 break; 14554 default: 14555 com_rslt = BNO055_OUT_OF_RANGE; 14556 break; 14557 } 14558 } else { 14559 com_rslt = BNO055_ERROR; 14560 } 14561 } else { 14562 com_rslt = BNO055_ERROR; 14563 } 14564 } else { 14565 com_rslt = BNO055_ERROR; 14566 } 14567 } 14568 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14569 /* set the operation mode of 14570 previous operation mode*/ 14571 com_rslt += bno055_set_operation_mode 14572 (prev_opmode_u8); 14573 return com_rslt; 14574 } 14575 /*! 14576 * @brief This API used to read the accel highg enable 14577 * from page one register from 0x12 bit 5 to 7 14578 * 14579 * @param data_u8 : The value of accel highg enable 14580 * data_u8| result 14581 * ------------ | ------------- 14582 * 0x01 | BNO055_BIT_ENABLE 14583 * 0x00 | BNO055_BIT_DISABLE 14584 * @param channel_u8 : The value of accel highg axis selection 14585 * channel_u8 | value 14586 * -------------------------- | ---------- 14587 * BNO055_ACCEL_HIGH_G_X_AXIS | 0 14588 * BNO055_ACCEL_HIGH_G_Y_AXIS | 1 14589 * BNO055_ACCEL_HIGH_G_Z_AXIS | 2 14590 * 14591 * @return results of bus communication function 14592 * @retval 0 -> BNO055_SUCCESS 14593 * @retval 1 -> BNO055_ERROR 14594 * 14595 * 14596 */ 14597 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_high_g_axis_enable( 14598 u8 channel_u8, u8 *data_u8) 14599 { 14600 /* Variable used to return value of 14601 communication routine*/ 14602 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14603 u8 data_u8r = BNO055_INIT_VALUE; 14604 s8 stat_s8 = BNO055_ERROR; 14605 /* Check the struct p_bno055 is empty */ 14606 if (p_bno055 == BNO055_INIT_VALUE) { 14607 return BNO055_E_NULL_PTR; 14608 } else { 14609 /*condition check for page, accel highg enable is 14610 available in the page one*/ 14611 if (p_bno055->page_id != BNO055_PAGE_ONE) 14612 /* Write page as one */ 14613 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14614 if ((stat_s8 == BNO055_SUCCESS) || 14615 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14616 switch (channel_u8) { 14617 case BNO055_ACCEL_HIGH_G_X_AXIS: 14618 /* Read the value of accel x highg enable*/ 14619 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14620 (p_bno055->dev_addr, 14621 BNO055_ACCEL_HIGH_G_X_AXIS_REG, 14622 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14623 *data_u8 = 14624 BNO055_GET_BITSLICE(data_u8r, 14625 BNO055_ACCEL_HIGH_G_X_AXIS); 14626 break; 14627 case BNO055_ACCEL_HIGH_G_Y_AXIS: 14628 /* Read the value of accel y highg enable*/ 14629 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14630 (p_bno055->dev_addr, 14631 BNO055_ACCEL_HIGH_G_Y_AXIS_REG, 14632 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14633 *data_u8 = 14634 BNO055_GET_BITSLICE(data_u8r, 14635 BNO055_ACCEL_HIGH_G_Y_AXIS); 14636 break; 14637 case BNO055_ACCEL_HIGH_G_Z_AXIS: 14638 /* Read the value of accel z highg enable*/ 14639 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14640 (p_bno055->dev_addr, 14641 BNO055_ACCEL_HIGH_G_Z_AXIS_REG, 14642 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14643 *data_u8 = 14644 BNO055_GET_BITSLICE(data_u8r, 14645 BNO055_ACCEL_HIGH_G_Z_AXIS); 14646 break; 14647 default: 14648 com_rslt = BNO055_OUT_OF_RANGE; 14649 break; 14650 } 14651 } else { 14652 com_rslt = BNO055_ERROR; 14653 } 14654 } 14655 return com_rslt; 14656 } 14657 /*! 14658 * @brief This API used to write the accel highg enable 14659 * from page one register from 0x12 bit 5 to 7 14660 * 14661 * @param data_u8 : The value of accel highg enable 14662 * data_u8| result 14663 * ------------ | ------------- 14664 * 0x01 | BNO055_BIT_ENABLE 14665 * 0x00 | BNO055_BIT_DISABLE 14666 * @param channel_u8 : The value of accel highg axis selection 14667 * channel_u8 | value 14668 * -------------------------- | ---------- 14669 * BNO055_ACCEL_HIGH_G_X_AXIS | 0 14670 * BNO055_ACCEL_HIGH_G_Y_AXIS | 1 14671 * BNO055_ACCEL_HIGH_G_Z_AXIS | 2 14672 * 14673 * @return results of bus communication function 14674 * @retval 0 -> BNO055_SUCCESS 14675 * @retval 1 -> BNO055_ERROR 14676 * 14677 * 14678 */ 14679 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_high_g_axis_enable( 14680 u8 channel_u8, u8 data_u8) 14681 { 14682 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14683 u8 data_u8r = BNO055_INIT_VALUE; 14684 s8 stat_s8 = BNO055_ERROR; 14685 s8 pg_stat_s8 = BNO055_ERROR; 14686 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 14687 /* Check the struct p_bno055 is empty */ 14688 if (p_bno055 == BNO055_INIT_VALUE) { 14689 return BNO055_E_NULL_PTR; 14690 } else { 14691 /* The write operation effective only if the operation 14692 mode is in config mode, this part of code is checking the 14693 current operation mode and set the config mode */ 14694 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 14695 if (stat_s8 == BNO055_SUCCESS) { 14696 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14697 stat_s8 += bno055_set_operation_mode 14698 (BNO055_OPERATION_MODE_CONFIG); 14699 if (stat_s8 == BNO055_SUCCESS) { 14700 /* Write page as one */ 14701 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14702 if (pg_stat_s8 == BNO055_SUCCESS) { 14703 switch (channel_u8) { 14704 case BNO055_ACCEL_HIGH_G_X_AXIS: 14705 /* Write the value of 14706 accel x highg enable*/ 14707 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14708 (p_bno055->dev_addr, 14709 BNO055_ACCEL_HIGH_G_X_AXIS_REG, 14710 &data_u8r, 14711 BNO055_GEN_READ_WRITE_LENGTH); 14712 if (com_rslt == BNO055_SUCCESS) { 14713 data_u8r = 14714 BNO055_SET_BITSLICE(data_u8r, 14715 BNO055_ACCEL_HIGH_G_X_AXIS, data_u8); 14716 com_rslt += 14717 p_bno055->BNO055_BUS_WRITE_FUNC 14718 (p_bno055->dev_addr, 14719 BNO055_ACCEL_HIGH_G_X_AXIS_REG, 14720 &data_u8r, 14721 BNO055_GEN_READ_WRITE_LENGTH); 14722 } 14723 break; 14724 case BNO055_ACCEL_HIGH_G_Y_AXIS: 14725 /* Write the value of 14726 accel y highg enable*/ 14727 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14728 (p_bno055->dev_addr, 14729 BNO055_ACCEL_HIGH_G_Y_AXIS_REG, 14730 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14731 if (com_rslt == BNO055_SUCCESS) { 14732 data_u8r = 14733 BNO055_SET_BITSLICE(data_u8r, 14734 BNO055_ACCEL_HIGH_G_Y_AXIS, 14735 data_u8); 14736 com_rslt += 14737 p_bno055->BNO055_BUS_WRITE_FUNC 14738 (p_bno055->dev_addr, 14739 BNO055_ACCEL_HIGH_G_Y_AXIS_REG, 14740 &data_u8r, 14741 BNO055_GEN_READ_WRITE_LENGTH); 14742 } 14743 break; 14744 case BNO055_ACCEL_HIGH_G_Z_AXIS: 14745 /* Write the value of 14746 accel z highg enable*/ 14747 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14748 (p_bno055->dev_addr, 14749 BNO055_ACCEL_HIGH_G_Z_AXIS_REG, 14750 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14751 if (com_rslt == BNO055_SUCCESS) { 14752 data_u8r = 14753 BNO055_SET_BITSLICE(data_u8r, 14754 BNO055_ACCEL_HIGH_G_Z_AXIS, data_u8); 14755 com_rslt += 14756 p_bno055->BNO055_BUS_WRITE_FUNC 14757 (p_bno055->dev_addr, 14758 BNO055_ACCEL_HIGH_G_Z_AXIS_REG, 14759 &data_u8r, 14760 BNO055_GEN_READ_WRITE_LENGTH); 14761 } 14762 break; 14763 default: 14764 com_rslt = BNO055_OUT_OF_RANGE; 14765 break; 14766 } 14767 } else { 14768 com_rslt = BNO055_ERROR; 14769 } 14770 } else { 14771 com_rslt = BNO055_ERROR; 14772 } 14773 } else { 14774 com_rslt = BNO055_ERROR; 14775 } 14776 } 14777 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14778 /* set the operation mode of 14779 previous operation mode*/ 14780 com_rslt += bno055_set_operation_mode 14781 (prev_opmode_u8); 14782 return com_rslt; 14783 } 14784 /*! 14785 * @brief This API used to read the accel highg duration 14786 * from page one register from 0x13 bit 0 to 7 14787 * 14788 * @param accel_high_g_durn_u8 : The value of accel highg duration 14789 * 14790 * @return results of bus communication function 14791 * @retval 0 -> BNO055_SUCCESS 14792 * @retval 1 -> BNO055_ERROR 14793 * 14794 * @note The high-g interrupt trigger delay according 14795 * to [highg duration + 1] * 2 ms 14796 * 14797 * in a range from 2 ms to 512 ms 14798 * 14799 */ 14800 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_high_g_durn( 14801 u8 *accel_high_g_durn_u8) 14802 { 14803 /* Variable used to return value of 14804 communication routine*/ 14805 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14806 u8 data_u8r = BNO055_INIT_VALUE; 14807 s8 stat_s8 = BNO055_ERROR; 14808 /* Check the struct p_bno055 is empty */ 14809 if (p_bno055 == BNO055_INIT_VALUE) { 14810 return BNO055_E_NULL_PTR; 14811 } else { 14812 /*condition check for page, accel highg duration is 14813 available in the page one*/ 14814 if (p_bno055->page_id != BNO055_PAGE_ONE) 14815 /* Write page as one */ 14816 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14817 if ((stat_s8 == BNO055_SUCCESS) || 14818 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14819 /* Read the value of accel highg duration*/ 14820 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14821 (p_bno055->dev_addr, 14822 BNO055_ACCEL_HIGH_G_DURN_REG, 14823 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14824 *accel_high_g_durn_u8 = 14825 BNO055_GET_BITSLICE(data_u8r, 14826 BNO055_ACCEL_HIGH_G_DURN); 14827 } else { 14828 com_rslt = BNO055_ERROR; 14829 } 14830 } 14831 return com_rslt; 14832 } 14833 /*! 14834 * @brief This API used to write the accel highg duration 14835 * from page one register from 0x13 bit 0 to 7 14836 * 14837 * @param accel_high_g_durn_u8 : The value of accel highg duration 14838 * 14839 * @return results of bus communication function 14840 * @retval 0 -> BNO055_SUCCESS 14841 * @retval 1 -> BNO055_ERROR 14842 * 14843 * @note The high-g interrupt trigger delay according 14844 * to [highg duration + 1] * 2 ms 14845 * 14846 * in a range from 2 ms to 512 ms 14847 * 14848 */ 14849 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_high_g_durn( 14850 u8 accel_high_g_durn_u8) 14851 { 14852 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14853 u8 data_u8r = BNO055_INIT_VALUE; 14854 s8 stat_s8 = BNO055_ERROR; 14855 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 14856 s8 pg_stat_s8 = BNO055_ERROR; 14857 /* Check the struct p_bno055 is empty */ 14858 if (p_bno055 == BNO055_INIT_VALUE) { 14859 return BNO055_E_NULL_PTR; 14860 } else { 14861 /* The write operation effective only if the operation 14862 mode is in config mode, this part of code is checking the 14863 current operation mode and set the config mode */ 14864 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 14865 if (stat_s8 == BNO055_SUCCESS) { 14866 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14867 stat_s8 += bno055_set_operation_mode 14868 (BNO055_OPERATION_MODE_CONFIG); 14869 14870 if (stat_s8 == BNO055_SUCCESS) { 14871 /* Write page as one */ 14872 pg_stat_s8 = bno055_write_page_id( 14873 BNO055_PAGE_ONE); 14874 if (pg_stat_s8 == BNO055_SUCCESS) { 14875 com_rslt = 14876 p_bno055->BNO055_BUS_READ_FUNC 14877 (p_bno055->dev_addr, 14878 BNO055_ACCEL_HIGH_G_DURN_REG, 14879 &data_u8r, 14880 BNO055_GEN_READ_WRITE_LENGTH); 14881 if (com_rslt == BNO055_SUCCESS) { 14882 /* Write the value of 14883 accel highg duration*/ 14884 data_u8r = 14885 BNO055_SET_BITSLICE(data_u8r, 14886 BNO055_ACCEL_HIGH_G_DURN, 14887 accel_high_g_durn_u8); 14888 com_rslt += 14889 p_bno055->BNO055_BUS_WRITE_FUNC 14890 (p_bno055->dev_addr, 14891 BNO055_ACCEL_HIGH_G_DURN_REG, 14892 &data_u8r, 14893 BNO055_GEN_READ_WRITE_LENGTH); 14894 } 14895 } else { 14896 com_rslt = BNO055_ERROR; 14897 } 14898 } else { 14899 com_rslt = BNO055_ERROR; 14900 } 14901 } else { 14902 com_rslt = BNO055_ERROR; 14903 } 14904 } 14905 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 14906 /* set the operation mode of 14907 previous operation mode*/ 14908 com_rslt += bno055_set_operation_mode 14909 (prev_opmode_u8); 14910 return com_rslt; 14911 } 14912 /*! 14913 * @brief This API used to read the accel highg threshold 14914 * from page one register from 0x14 bit 0 to 7 14915 * 14916 * @param accel_high_g_thres_u8 : The value of accel highg threshold 14917 * 14918 * @return results of bus communication function 14919 * @retval 0 -> BNO055_SUCCESS 14920 * @retval 1 -> BNO055_ERROR 14921 * 14922 * @note Accel highg interrupt threshold dependent 14923 * for accel g range 14924 * 14925 * accel_range_u8 | threshold | LSB 14926 * ------------- | ------------- | --------- 14927 * 2g | 7.81mg | 1LSB 14928 * 4g | 15.63mg | 1LSB 14929 * 8g | 31.25mg | 1LSB 14930 * 16g | 62.5mg | 1LSB 14931 * 14932 */ 14933 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_high_g_thres( 14934 u8 *accel_high_g_thres_u8) 14935 { 14936 /* Variable used to return value of 14937 communication routine*/ 14938 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14939 u8 data_u8r = BNO055_INIT_VALUE; 14940 s8 stat_s8 = BNO055_ERROR; 14941 /* Check the struct p_bno055 is empty */ 14942 if (p_bno055 == BNO055_INIT_VALUE) { 14943 return BNO055_E_NULL_PTR; 14944 } else { 14945 /*condition check for page, highg threshold is 14946 available in the page one*/ 14947 if (p_bno055->page_id != BNO055_PAGE_ONE) 14948 /* Write page as one */ 14949 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 14950 if ((stat_s8 == BNO055_SUCCESS) || 14951 (p_bno055->page_id == BNO055_PAGE_ONE)) { 14952 /* Read the value of highg threshold */ 14953 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 14954 (p_bno055->dev_addr, 14955 BNO055_ACCEL_HIGH_G_THRES_REG, 14956 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 14957 *accel_high_g_thres_u8 = 14958 BNO055_GET_BITSLICE(data_u8r, 14959 BNO055_ACCEL_HIGH_G_THRES); 14960 } else { 14961 com_rslt = BNO055_ERROR; 14962 } 14963 } 14964 return com_rslt; 14965 } 14966 /*! 14967 * @brief This API used to write the accel highg threshold 14968 * from page one register from 0x14 bit 0 to 7 14969 * 14970 * @param accel_high_g_thres_u8 : The value of accel highg threshold 14971 * 14972 * @return results of bus communication function 14973 * @retval 0 -> BNO055_SUCCESS 14974 * @retval 1 -> BNO055_ERROR 14975 * 14976 * @note Accel highg interrupt threshold dependent 14977 * for accel g range 14978 * 14979 * accel_range_u8 | threshold | LSB 14980 * ------------- | ------------- | --------- 14981 * 2g | 7.81mg | 1LSB 14982 * 4g | 15.63mg | 1LSB 14983 * 8g | 31.25mg | 1LSB 14984 * 16g | 62.5mg | 1LSB 14985 * 14986 */ 14987 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_high_g_thres( 14988 u8 accel_high_g_thres_u8) 14989 { 14990 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 14991 u8 data_u8r = BNO055_INIT_VALUE; 14992 s8 stat_s8 = BNO055_ERROR; 14993 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 14994 s8 pg_stat_s8 = BNO055_ERROR; 14995 /* Check the struct p_bno055 is empty */ 14996 if (p_bno055 == BNO055_INIT_VALUE) { 14997 return BNO055_E_NULL_PTR; 14998 } else { 14999 /* The write operation effective only if the operation 15000 mode is in config mode, this part of code is checking the 15001 current operation mode and set the config mode */ 15002 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 15003 if (stat_s8 == BNO055_SUCCESS) { 15004 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15005 stat_s8 += bno055_set_operation_mode 15006 (BNO055_OPERATION_MODE_CONFIG); 15007 if (stat_s8 == BNO055_SUCCESS) { 15008 /* Write page as one */ 15009 pg_stat_s8 = bno055_write_page_id( 15010 BNO055_PAGE_ONE); 15011 if (pg_stat_s8 == BNO055_SUCCESS) { 15012 com_rslt = 15013 p_bno055->BNO055_BUS_READ_FUNC 15014 (p_bno055->dev_addr, 15015 BNO055_ACCEL_HIGH_G_THRES_REG, 15016 &data_u8r, 15017 BNO055_GEN_READ_WRITE_LENGTH); 15018 if (com_rslt == BNO055_SUCCESS) { 15019 /* Write the value of 15020 accel highg threshold */ 15021 data_u8r = 15022 BNO055_SET_BITSLICE(data_u8r, 15023 BNO055_ACCEL_HIGH_G_THRES, 15024 accel_high_g_thres_u8); 15025 com_rslt += 15026 p_bno055->BNO055_BUS_WRITE_FUNC 15027 (p_bno055->dev_addr, 15028 BNO055_ACCEL_HIGH_G_THRES_REG, 15029 &data_u8r, 15030 BNO055_GEN_READ_WRITE_LENGTH); 15031 } 15032 } else { 15033 com_rslt = BNO055_ERROR; 15034 } 15035 } else { 15036 com_rslt = BNO055_ERROR; 15037 } 15038 } else { 15039 com_rslt = BNO055_ERROR; 15040 } 15041 } 15042 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15043 /* set the operation mode of 15044 previous operation mode*/ 15045 com_rslt += bno055_set_operation_mode 15046 (prev_opmode_u8); 15047 return com_rslt; 15048 } 15049 /*! 15050 * @brief This API used to read the accel slownomotion threshold 15051 * from page one register from 0x15 bit 0 to 7 15052 * 15053 * @param accel_slow_no_motion_thres_u8 : 15054 * The value of accel slownomotion threshold 15055 * 15056 * @return results of bus communication function 15057 * @retval 0 -> BNO055_SUCCESS 15058 * @retval 1 -> BNO055_ERROR 15059 * 15060 * @note Accel slow no motion interrupt threshold dependent 15061 * for accel g range 15062 * 15063 * accel_range_u8 | threshold | LSB 15064 * ------------- | ------------- | --------- 15065 * 2g | 3.19mg | 1LSB 15066 * 4g | 7.81mg | 1LSB 15067 * 8g | 15.63mg | 1LSB 15068 * 16g | 31.25mg | 1LSB 15069 */ 15070 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_slow_no_motion_thres( 15071 u8 *accel_slow_no_motion_thres_u8) 15072 { 15073 /* Variable used to return value of 15074 communication routine*/ 15075 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15076 u8 data_u8r = BNO055_INIT_VALUE; 15077 s8 stat_s8 = BNO055_ERROR; 15078 /* Check the struct p_bno055 is empty */ 15079 if (p_bno055 == BNO055_INIT_VALUE) { 15080 return BNO055_E_NULL_PTR; 15081 } else { 15082 /*condition check for page, accel slownomotion threshold is 15083 available in the page one*/ 15084 if (p_bno055->page_id != BNO055_PAGE_ONE) 15085 /* Write page as one */ 15086 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15087 if ((stat_s8 == BNO055_SUCCESS) || 15088 (p_bno055->page_id == BNO055_PAGE_ONE)) { 15089 /* Read the value of slownomotion threshold */ 15090 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15091 (p_bno055->dev_addr, 15092 BNO055_ACCEL_SLOW_NO_MOTION_THRES_REG, 15093 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15094 *accel_slow_no_motion_thres_u8 = 15095 BNO055_GET_BITSLICE(data_u8r, 15096 BNO055_ACCEL_SLOW_NO_MOTION_THRES); 15097 } else { 15098 com_rslt = BNO055_ERROR; 15099 } 15100 } 15101 return com_rslt; 15102 } 15103 /*! 15104 * @brief This API used to write the accel slownomotion threshold 15105 * from page one register from 0x15 bit 0 to 7 15106 * 15107 * @param accel_slow_no_motion_thres_u8 : 15108 * The value of accel slownomotion threshold 15109 * 15110 * @return results of bus communication function 15111 * @retval 0 -> BNO055_SUCCESS 15112 * @retval 1 -> BNO055_ERROR 15113 * 15114 * @note Accel slow no motion interrupt threshold dependent 15115 * for accel g range 15116 * 15117 * accel_range_u8 | threshold | LSB 15118 * ------------- | ------------- | --------- 15119 * 2g | 3.19mg | 1LSB 15120 * 4g | 7.81mg | 1LSB 15121 * 8g | 15.63mg | 1LSB 15122 * 16g | 31.25mg | 1LSB 15123 */ 15124 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_slow_no_motion_thres( 15125 u8 accel_slow_no_motion_thres_u8) 15126 { 15127 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15128 u8 data_u8r = BNO055_INIT_VALUE; 15129 s8 stat_s8 = BNO055_ERROR; 15130 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 15131 s8 pg_stat_s8 = BNO055_ERROR; 15132 /* Check the struct p_bno055 is empty */ 15133 if (p_bno055 == BNO055_INIT_VALUE) { 15134 return BNO055_E_NULL_PTR; 15135 } else { 15136 /* The write operation effective only if the operation 15137 mode is in config mode, this part of code is checking the 15138 current operation mode and set the config mode */ 15139 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 15140 if (stat_s8 == BNO055_SUCCESS) { 15141 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15142 stat_s8 += bno055_set_operation_mode 15143 (BNO055_OPERATION_MODE_CONFIG); 15144 if (stat_s8 == BNO055_SUCCESS) { 15145 /* Write page as one */ 15146 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15147 if (pg_stat_s8 == BNO055_SUCCESS) { 15148 /* Write the value of 15149 slownomotion threshold */ 15150 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15151 (p_bno055->dev_addr, 15152 BNO055_ACCEL_SLOW_NO_MOTION_THRES_REG, 15153 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15154 if (com_rslt == BNO055_SUCCESS) { 15155 data_u8r = 15156 BNO055_SET_BITSLICE(data_u8r, 15157 BNO055_ACCEL_SLOW_NO_MOTION_THRES, 15158 accel_slow_no_motion_thres_u8); 15159 com_rslt += 15160 p_bno055->BNO055_BUS_WRITE_FUNC 15161 (p_bno055->dev_addr, 15162 BNO055_ACCEL_SLOW_NO_MOTION_THRES_REG, 15163 &data_u8r, 15164 BNO055_GEN_READ_WRITE_LENGTH); 15165 } 15166 } else { 15167 com_rslt = BNO055_ERROR; 15168 } 15169 } else { 15170 com_rslt = BNO055_ERROR; 15171 } 15172 } else { 15173 com_rslt = BNO055_ERROR; 15174 } 15175 } 15176 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15177 /* set the operation mode of 15178 previous operation mode*/ 15179 com_rslt += bno055_set_operation_mode 15180 (prev_opmode_u8); 15181 return com_rslt; 15182 } 15183 /*! 15184 * @brief This API used to read accel slownomotion enable 15185 * from page one register from 0x16 bit 0 15186 * 15187 * @param accel_slow_no_motion_en_u8 : The value of accel slownomotion enable 15188 * accel_slow_no_motion_en_u8 | result 15189 * ------------------------ | -------- 15190 * 0x01 | Slow motion 15191 * 0x00 | No motion 15192 * 15193 * @return results of bus communication function 15194 * @retval 0 -> BNO055_SUCCESS 15195 * @retval 1 -> BNO055_ERROR 15196 * 15197 */ 15198 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_slow_no_motion_enable( 15199 u8 *accel_slow_no_motion_en_u8) 15200 { 15201 /* Variable used to return value of 15202 communication routine*/ 15203 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15204 u8 data_u8r = BNO055_INIT_VALUE; 15205 s8 stat_s8 = BNO055_ERROR; 15206 /* Check the struct p_bno055 is empty */ 15207 if (p_bno055 == BNO055_INIT_VALUE) { 15208 return BNO055_E_NULL_PTR; 15209 } else { 15210 /*condition check for page, accel slownomotion enable is 15211 available in the page one*/ 15212 if (p_bno055->page_id != BNO055_PAGE_ONE) 15213 /* Write page as one */ 15214 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15215 if ((stat_s8 == BNO055_SUCCESS) || 15216 (p_bno055->page_id == BNO055_PAGE_ONE)) { 15217 /* Read the value of accel slownomotion enable */ 15218 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15219 (p_bno055->dev_addr, 15220 BNO055_ACCEL_SLOW_NO_MOTION_ENABLE_REG, 15221 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15222 *accel_slow_no_motion_en_u8 = 15223 BNO055_GET_BITSLICE(data_u8r, 15224 BNO055_ACCEL_SLOW_NO_MOTION_ENABLE); 15225 } else { 15226 com_rslt = BNO055_ERROR; 15227 } 15228 } 15229 return com_rslt; 15230 } 15231 /*! 15232 * @brief This API used to write accel slownomotion enable 15233 * from page one register from 0x16 bit 0 15234 * 15235 * @param accel_slow_no_motion_en_u8 : The value of accel slownomotion enable 15236 * accel_slow_no_motion_en_u8 | result 15237 * ------------------------ | -------- 15238 * 0x01 | Slow motion 15239 * 0x00 | No motion 15240 * 15241 * @return results of bus communication function 15242 * @retval 0 -> BNO055_SUCCESS 15243 * @retval 1 -> BNO055_ERROR 15244 * 15245 */ 15246 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_slow_no_motion_enable( 15247 u8 accel_slow_no_motion_en_u8) 15248 { 15249 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15250 u8 data_u8r = BNO055_INIT_VALUE; 15251 s8 stat_s8 = BNO055_ERROR; 15252 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 15253 s8 pg_stat_s8 = BNO055_ERROR; 15254 /* Check the struct p_bno055 is empty */ 15255 if (p_bno055 == BNO055_INIT_VALUE) { 15256 return BNO055_E_NULL_PTR; 15257 } else { 15258 /* The write operation effective only if the operation 15259 mode is in config mode, this part of code is checking the 15260 current operation mode and set the config mode */ 15261 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 15262 if (stat_s8 == BNO055_SUCCESS) { 15263 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15264 stat_s8 += bno055_set_operation_mode 15265 (BNO055_OPERATION_MODE_CONFIG); 15266 if (stat_s8 == BNO055_SUCCESS) { 15267 /* Write page as one */ 15268 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15269 if (pg_stat_s8 == BNO055_SUCCESS) { 15270 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15271 (p_bno055->dev_addr, 15272 BNO055_ACCEL_SLOW_NO_MOTION_ENABLE_REG, 15273 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15274 if (com_rslt == BNO055_SUCCESS) { 15275 /* Read the value of 15276 accel slownomotion enable */ 15277 data_u8r = 15278 BNO055_SET_BITSLICE(data_u8r, 15279 BNO055_ACCEL_SLOW_NO_MOTION_ENABLE, 15280 accel_slow_no_motion_en_u8); 15281 com_rslt += 15282 p_bno055->BNO055_BUS_WRITE_FUNC 15283 (p_bno055->dev_addr, 15284 BNO055_ACCEL_SLOW_NO_MOTION_ENABLE_REG, 15285 &data_u8r, 15286 BNO055_GEN_READ_WRITE_LENGTH); 15287 } 15288 } else { 15289 com_rslt = BNO055_ERROR; 15290 } 15291 } else { 15292 com_rslt = BNO055_ERROR; 15293 } 15294 } else { 15295 com_rslt = BNO055_ERROR; 15296 } 15297 } 15298 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15299 /* set the operation mode of 15300 previous operation mode*/ 15301 com_rslt += bno055_set_operation_mode 15302 (prev_opmode_u8); 15303 return com_rslt; 15304 } 15305 /*! 15306 * @brief This API used to read accel slownomotion duration 15307 * from page one register from 0x16 bit 1 to 6 15308 * 15309 * @param accel_slow_no_motion_durn_u8 : 15310 * The value of accel slownomotion duration 15311 * 15312 * @return results of bus communication function 15313 * @retval 0 -> BNO055_SUCCESS 15314 * @retval 1 -> BNO055_ERROR 15315 * 15316 */ 15317 BNO055_RETURN_FUNCTION_TYPE bno055_get_accel_slow_no_motion_durn( 15318 u8 *accel_slow_no_motion_durn_u8) 15319 { 15320 /* Variable used to return value of 15321 communication routine*/ 15322 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15323 u8 data_u8r = BNO055_INIT_VALUE; 15324 s8 stat_s8 = BNO055_ERROR; 15325 /* Check the struct p_bno055 is empty */ 15326 if (p_bno055 == BNO055_INIT_VALUE) { 15327 return BNO055_E_NULL_PTR; 15328 } else { 15329 /*condition check for page, accel slownomotion duration is 15330 available in the page one*/ 15331 if (p_bno055->page_id != BNO055_PAGE_ONE) 15332 /* Write page as one */ 15333 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15334 if ((stat_s8 == BNO055_SUCCESS) || 15335 (p_bno055->page_id == BNO055_PAGE_ONE)) { 15336 /*read value of accel slownomotion duration*/ 15337 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15338 (p_bno055->dev_addr, 15339 BNO055_ACCEL_SLOW_NO_MOTION_DURN_REG, 15340 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15341 *accel_slow_no_motion_durn_u8 = 15342 BNO055_GET_BITSLICE(data_u8r, 15343 BNO055_ACCEL_SLOW_NO_MOTION_DURN); 15344 } else { 15345 com_rslt = BNO055_ERROR; 15346 } 15347 } 15348 return com_rslt; 15349 } 15350 /*! 15351 * @brief This API used to write accel slownomotion duration 15352 * from page one register from 0x16 bit 1 to 6 15353 * 15354 * @param accel_slow_no_motion_durn_u8 : 15355 * The value of accel slownomotion duration 15356 * 15357 * @return results of bus communication function 15358 * @retval 0 -> BNO055_SUCCESS 15359 * @retval 1 -> BNO055_ERROR 15360 * 15361 */ 15362 BNO055_RETURN_FUNCTION_TYPE bno055_set_accel_slow_no_motion_durn( 15363 u8 accel_slow_no_motion_durn_u8) 15364 { 15365 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15366 u8 data_u8r = BNO055_INIT_VALUE; 15367 s8 stat_s8 = BNO055_ERROR; 15368 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 15369 s8 pg_stat_s8 = BNO055_ERROR; 15370 /* Check the struct p_bno055 is empty */ 15371 if (p_bno055 == BNO055_INIT_VALUE) { 15372 return BNO055_E_NULL_PTR; 15373 } else { 15374 /* The write operation effective only if the operation 15375 mode is in config mode, this part of code is checking the 15376 current operation mode and set the config mode */ 15377 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 15378 if (stat_s8 == BNO055_SUCCESS) { 15379 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15380 stat_s8 += bno055_set_operation_mode 15381 (BNO055_OPERATION_MODE_CONFIG); 15382 if (stat_s8 == BNO055_SUCCESS) { 15383 /* Write page as one */ 15384 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15385 if (pg_stat_s8 == BNO055_SUCCESS) { 15386 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15387 (p_bno055->dev_addr, 15388 BNO055_ACCEL_SLOW_NO_MOTION_DURN_REG, 15389 &data_u8r, 15390 BNO055_GEN_READ_WRITE_LENGTH); 15391 if (com_rslt == BNO055_SUCCESS) { 15392 /*Write the value of accel 15393 slownomotion duration*/ 15394 data_u8r = 15395 BNO055_SET_BITSLICE(data_u8r, 15396 BNO055_ACCEL_SLOW_NO_MOTION_DURN, 15397 accel_slow_no_motion_durn_u8); 15398 com_rslt += 15399 p_bno055->BNO055_BUS_WRITE_FUNC 15400 (p_bno055->dev_addr, 15401 BNO055_ACCEL_SLOW_NO_MOTION_DURN_REG, 15402 &data_u8r, 15403 BNO055_GEN_READ_WRITE_LENGTH); 15404 } 15405 } else { 15406 com_rslt = BNO055_ERROR; 15407 } 15408 } else { 15409 com_rslt = BNO055_ERROR; 15410 } 15411 } else { 15412 com_rslt = BNO055_ERROR; 15413 } 15414 } 15415 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15416 /* set the operation mode of 15417 previous operation mode*/ 15418 com_rslt += bno055_set_operation_mode 15419 (prev_opmode_u8); 15420 return com_rslt; 15421 } 15422 /*! 15423 * @brief This API used to read the gyro anymotion enable 15424 * from page one register from 0x17 bit 0 to 2 15425 * 15426 * @param data_u8 : The value of gyro anymotion enable 15427 * data_u8 | result 15428 * ----------------- |------------- 15429 * 0x01 | BNO055_BIT_ENABLE 15430 * 0x00 | BNO055_BIT_DISABLE 15431 * @param channel_u8 : The value of gyro anymotion axis selection 15432 * channel_u8 | value 15433 * --------------------------- | ---------- 15434 * BNO055_GYRO_ANY_MOTIONX_AXIS | 0 15435 * BNO055_GYRO_ANY_MOTIONY_AXIS | 1 15436 * BNO055_GYRO_ANY_MOTIONZ_AXIS | 2 15437 * 15438 * 15439 * @return results of bus communication function 15440 * @retval 0 -> BNO055_SUCCESS 15441 * @retval 1 -> BNO055_ERROR 15442 * 15443 * 15444 */ 15445 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_any_motion_axis_enable( 15446 u8 channel_u8, u8 *data_u8) 15447 { 15448 /* Variable used to return value of 15449 communication routine*/ 15450 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15451 u8 data_u8r = BNO055_INIT_VALUE; 15452 s8 stat_s8 = BNO055_ERROR; 15453 /* Check the struct p_bno055 is empty */ 15454 if (p_bno055 == BNO055_INIT_VALUE) { 15455 return BNO055_E_NULL_PTR; 15456 } else { 15457 /*condition check for page, gyro anymotion axis is 15458 available in the page one*/ 15459 if (p_bno055->page_id != BNO055_PAGE_ONE) 15460 /* Write page as one */ 15461 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15462 if ((stat_s8 == BNO055_SUCCESS) || 15463 (p_bno055->page_id == BNO055_PAGE_ONE)) { 15464 switch (channel_u8) { 15465 case BNO055_GYRO_ANY_MOTION_X_AXIS: 15466 /* Read the gyro anymotion x enable*/ 15467 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15468 (p_bno055->dev_addr, 15469 BNO055_GYRO_ANY_MOTION_X_AXIS_REG, 15470 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15471 *data_u8 = 15472 BNO055_GET_BITSLICE(data_u8r, 15473 BNO055_GYRO_ANY_MOTION_X_AXIS); 15474 break; 15475 case BNO055_GYRO_ANY_MOTION_Y_AXIS: 15476 /* Read the gyro anymotion y enable*/ 15477 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15478 (p_bno055->dev_addr, 15479 BNO055_GYRO_ANY_MOTION_Y_AXIS_REG, 15480 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15481 *data_u8 = 15482 BNO055_GET_BITSLICE(data_u8r, 15483 BNO055_GYRO_ANY_MOTION_Y_AXIS); 15484 break; 15485 case BNO055_GYRO_ANY_MOTION_Z_AXIS: 15486 /* Read the gyro anymotion z enable*/ 15487 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15488 (p_bno055->dev_addr, 15489 BNO055_GYRO_ANY_MOTION_Z_AXIS_REG, 15490 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15491 *data_u8 = 15492 BNO055_GET_BITSLICE(data_u8r, 15493 BNO055_GYRO_ANY_MOTION_Z_AXIS); 15494 break; 15495 default: 15496 com_rslt = BNO055_OUT_OF_RANGE; 15497 break; 15498 } 15499 } else { 15500 com_rslt = BNO055_ERROR; 15501 } 15502 } 15503 return com_rslt; 15504 } 15505 /*! 15506 * @brief This API used to write the gyro anymotion enable 15507 * from page one register from 0x17 bit 0 to 2 15508 * 15509 * @param data_u8 : The value of gyro anymotion enable 15510 * data_u8 | result 15511 * ----------------- |------------- 15512 * 0x01 | BNO055_BIT_ENABLE 15513 * 0x00 | BNO055_BIT_DISABLE 15514 * @param channel_u8 : The value of gyro anymotion axis selection 15515 * channel_u8 | value 15516 * --------------------------- | ---------- 15517 * BNO055_GYRO_ANY_MOTIONX_AXIS | 0 15518 * BNO055_GYRO_ANY_MOTIONY_AXIS | 1 15519 * BNO055_GYRO_ANY_MOTIONZ_AXIS | 2 15520 * 15521 * @return results of bus communication function 15522 * @retval 0 -> BNO055_SUCCESS 15523 * @retval 1 -> BNO055_ERROR 15524 * 15525 * 15526 */ 15527 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_any_motion_axis_enable( 15528 u8 channel_u8, u8 data_u8) 15529 { 15530 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15531 u8 data_u8r = BNO055_INIT_VALUE; 15532 s8 stat_s8 = BNO055_ERROR; 15533 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 15534 s8 pg_stat_s8 = BNO055_ERROR; 15535 /* Check the struct p_bno055 is empty */ 15536 if (p_bno055 == BNO055_INIT_VALUE) { 15537 return BNO055_E_NULL_PTR; 15538 } else { 15539 /* The write operation effective only if the operation 15540 mode is in config mode, this part of code is checking the 15541 current operation mode and set the config mode */ 15542 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 15543 if (stat_s8 == BNO055_SUCCESS) { 15544 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15545 stat_s8 += bno055_set_operation_mode 15546 (BNO055_OPERATION_MODE_CONFIG); 15547 if (stat_s8 == BNO055_SUCCESS) { 15548 /* Write page as one */ 15549 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15550 if (pg_stat_s8 == BNO055_SUCCESS) { 15551 switch (channel_u8) { 15552 case BNO055_GYRO_ANY_MOTION_X_AXIS: 15553 /* Write the gyro 15554 anymotion x enable*/ 15555 com_rslt = 15556 p_bno055->BNO055_BUS_READ_FUNC 15557 (p_bno055->dev_addr, 15558 BNO055_GYRO_ANY_MOTION_X_AXIS_REG, 15559 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15560 if (com_rslt == BNO055_SUCCESS) { 15561 data_u8r = BNO055_SET_BITSLICE 15562 (data_u8r, 15563 BNO055_GYRO_ANY_MOTION_X_AXIS, 15564 data_u8); 15565 com_rslt += 15566 p_bno055->BNO055_BUS_WRITE_FUNC 15567 (p_bno055->dev_addr, 15568 BNO055_GYRO_ANY_MOTION_X_AXIS_REG, 15569 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15570 } 15571 break; 15572 case BNO055_GYRO_ANY_MOTION_Y_AXIS: 15573 /* Write the gyro 15574 anymotion y enable*/ 15575 com_rslt = 15576 p_bno055->BNO055_BUS_READ_FUNC 15577 (p_bno055->dev_addr, 15578 BNO055_GYRO_ANY_MOTION_Y_AXIS_REG, 15579 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15580 if (com_rslt == BNO055_SUCCESS) { 15581 data_u8r = BNO055_SET_BITSLICE 15582 (data_u8r, 15583 BNO055_GYRO_ANY_MOTION_Y_AXIS, data_u8); 15584 com_rslt += 15585 p_bno055->BNO055_BUS_WRITE_FUNC 15586 (p_bno055->dev_addr, 15587 BNO055_GYRO_ANY_MOTION_Y_AXIS_REG, 15588 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15589 } 15590 break; 15591 case BNO055_GYRO_ANY_MOTION_Z_AXIS: 15592 /* Write the gyro 15593 anymotion z enable*/ 15594 com_rslt = 15595 p_bno055->BNO055_BUS_READ_FUNC 15596 (p_bno055->dev_addr, 15597 BNO055_GYRO_ANY_MOTION_Z_AXIS_REG, 15598 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15599 if (com_rslt == BNO055_SUCCESS) { 15600 data_u8r = BNO055_SET_BITSLICE 15601 (data_u8r, 15602 BNO055_GYRO_ANY_MOTION_Z_AXIS, 15603 data_u8); 15604 com_rslt += 15605 p_bno055->BNO055_BUS_WRITE_FUNC 15606 (p_bno055->dev_addr, 15607 BNO055_GYRO_ANY_MOTION_Z_AXIS_REG, 15608 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15609 } 15610 break; 15611 default: 15612 com_rslt = BNO055_OUT_OF_RANGE; 15613 break; 15614 } 15615 } else { 15616 com_rslt = BNO055_ERROR; 15617 } 15618 } else { 15619 com_rslt = BNO055_ERROR; 15620 } 15621 } else { 15622 com_rslt = BNO055_ERROR; 15623 } 15624 } 15625 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15626 /* set the operation mode of 15627 previous operation mode*/ 15628 com_rslt += bno055_set_operation_mode 15629 (prev_opmode_u8); 15630 return com_rslt; 15631 } 15632 /*! 15633 * @brief This API used to read the gyro highrate enable 15634 * from page one register from 0x17 bit 3 to 5 15635 * 15636 * @param data_u8 : The value of gyro highrate enable 15637 * data_u8 | result 15638 * ---------------- |------------- 15639 * 0x01 | BNO055_BIT_ENABLE 15640 * 0x00 | BNO055_BIT_DISABLE 15641 * @param channel_u8 : The value of gyro highrate axis selection 15642 * channel_u8 | value 15643 * ------------------------ | ---------- 15644 * BNO055_GYRO_HIGHRATE_X_AXIS | 0 15645 * BNO055_GYRO_HIGHRATE_Y_AXIS | 1 15646 * BNO055_GYRO_HIGHRATE_Z_AXIS | 2 15647 * 15648 * 15649 * @return results of bus communication function 15650 * @retval 0 -> BNO055_SUCCESS 15651 * @retval 1 -> BNO055_ERROR 15652 * 15653 * 15654 */ 15655 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_axis_enable( 15656 u8 channel_u8, u8 *data_u8) 15657 { 15658 /* Variable used to return value of 15659 communication routine*/ 15660 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15661 u8 data_u8r = BNO055_INIT_VALUE; 15662 s8 stat_s8 = BNO055_ERROR; 15663 /* Check the struct p_bno055 is empty */ 15664 if (p_bno055 == BNO055_INIT_VALUE) { 15665 return BNO055_E_NULL_PTR; 15666 } else { 15667 /*condition check for page, gyro highrate enable is 15668 available in the page one*/ 15669 if (p_bno055->page_id != BNO055_PAGE_ONE) 15670 /* Write page as one */ 15671 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15672 if ((stat_s8 == BNO055_SUCCESS) || 15673 (p_bno055->page_id == BNO055_PAGE_ONE)) { 15674 switch (channel_u8) { 15675 case BNO055_GYRO_HIGHRATE_X_AXIS: 15676 /* Read the gyro highrate x enable */ 15677 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15678 (p_bno055->dev_addr, 15679 BNO055_GYRO_HIGHRATE_X_AXIS_REG, 15680 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15681 *data_u8 = 15682 BNO055_GET_BITSLICE(data_u8r, 15683 BNO055_GYRO_HIGHRATE_X_AXIS); 15684 break; 15685 case BNO055_GYRO_HIGHRATE_Y_AXIS: 15686 /* Read the gyro highrate y enable */ 15687 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15688 (p_bno055->dev_addr, 15689 BNO055_GYRO_HIGHRATE_Y_AXIS_REG, 15690 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15691 *data_u8 = 15692 BNO055_GET_BITSLICE(data_u8r, 15693 BNO055_GYRO_HIGHRATE_Y_AXIS); 15694 break; 15695 case BNO055_GYRO_HIGHRATE_Z_AXIS: 15696 /* Read the gyro highrate z enable */ 15697 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15698 (p_bno055->dev_addr, 15699 BNO055_GYRO_HIGHRATE_Z_AXIS_REG, 15700 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15701 *data_u8 = 15702 BNO055_GET_BITSLICE(data_u8r, 15703 BNO055_GYRO_HIGHRATE_Z_AXIS); 15704 break; 15705 default: 15706 com_rslt = BNO055_OUT_OF_RANGE; 15707 break; 15708 } 15709 } else { 15710 com_rslt = BNO055_ERROR; 15711 } 15712 } 15713 return com_rslt; 15714 } 15715 /*! 15716 * @brief This API used to write the gyro highrate enable 15717 * from page one register from 0x17 bit 3 to 5 15718 * 15719 * @param data_u8 : The value of gyro highrate enable 15720 * data_u8 | result 15721 * ---------------- |------------- 15722 * 0x01 | BNO055_BIT_ENABLE 15723 * 0x00 | BNO055_BIT_DISABLE 15724 * @param channel_u8 : The value of gyro highrate axis selection 15725 * channel_u8 | value 15726 * ------------------------ | ---------- 15727 * BNO055_GYRO_HIGHRATE_X_AXIS | 0 15728 * BNO055_GYRO_HIGHRATE_Y_AXIS | 1 15729 * BNO055_GYRO_HIGHRATE_Z_AXIS | 2 15730 * 15731 * @return results of bus communication function 15732 * @retval 0 -> BNO055_SUCCESS 15733 * @retval 1 -> BNO055_ERROR 15734 * 15735 * 15736 */ 15737 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_axis_enable( 15738 u8 channel_u8, u8 data_u8) 15739 { 15740 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15741 u8 data_u8r = BNO055_INIT_VALUE; 15742 s8 stat_s8 = BNO055_ERROR; 15743 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 15744 s8 pg_stat_s8 = BNO055_ERROR; 15745 /* Check the struct p_bno055 is empty */ 15746 if (p_bno055 == BNO055_INIT_VALUE) { 15747 return BNO055_E_NULL_PTR; 15748 } else { 15749 /* The write operation effective only if the operation 15750 mode is in config mode, this part of code is checking the 15751 current operation mode and set the config mode */ 15752 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 15753 if (stat_s8 == BNO055_SUCCESS) { 15754 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15755 stat_s8 += bno055_set_operation_mode 15756 (BNO055_OPERATION_MODE_CONFIG); 15757 if (stat_s8 == BNO055_SUCCESS) { 15758 /* Write page as one */ 15759 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15760 if (pg_stat_s8 == BNO055_SUCCESS) { 15761 switch (channel_u8) { 15762 case BNO055_GYRO_HIGHRATE_X_AXIS: 15763 /* Write the value of 15764 gyro highrate x enable*/ 15765 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15766 (p_bno055->dev_addr, 15767 BNO055_GYRO_HIGHRATE_X_AXIS_REG, 15768 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15769 if (com_rslt == BNO055_SUCCESS) { 15770 data_u8r = BNO055_SET_BITSLICE 15771 (data_u8r, 15772 BNO055_GYRO_HIGHRATE_X_AXIS, data_u8); 15773 com_rslt += 15774 p_bno055->BNO055_BUS_WRITE_FUNC 15775 (p_bno055->dev_addr, 15776 BNO055_GYRO_HIGHRATE_X_AXIS_REG, 15777 &data_u8r, 15778 BNO055_GEN_READ_WRITE_LENGTH); 15779 } 15780 break; 15781 case BNO055_GYRO_HIGHRATE_Y_AXIS: 15782 /* Write the value of 15783 gyro highrate y enable*/ 15784 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15785 (p_bno055->dev_addr, 15786 BNO055_GYRO_HIGHRATE_Y_AXIS_REG, 15787 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15788 if (com_rslt == BNO055_SUCCESS) { 15789 data_u8r = 15790 BNO055_SET_BITSLICE( 15791 data_u8r, 15792 BNO055_GYRO_HIGHRATE_Y_AXIS, data_u8); 15793 com_rslt += 15794 p_bno055->BNO055_BUS_WRITE_FUNC 15795 (p_bno055->dev_addr, 15796 BNO055_GYRO_HIGHRATE_Y_AXIS_REG, 15797 &data_u8r, 15798 BNO055_GEN_READ_WRITE_LENGTH); 15799 } 15800 break; 15801 case BNO055_GYRO_HIGHRATE_Z_AXIS: 15802 /* Write the value of 15803 gyro highrate z enable*/ 15804 com_rslt = 15805 p_bno055->BNO055_BUS_READ_FUNC 15806 (p_bno055->dev_addr, 15807 BNO055_GYRO_HIGHRATE_Z_AXIS_REG, 15808 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15809 if (com_rslt == BNO055_SUCCESS) { 15810 data_u8r = BNO055_SET_BITSLICE 15811 (data_u8r, 15812 BNO055_GYRO_HIGHRATE_Z_AXIS, data_u8); 15813 com_rslt += 15814 p_bno055->BNO055_BUS_WRITE_FUNC 15815 (p_bno055->dev_addr, 15816 BNO055_GYRO_HIGHRATE_Z_AXIS_REG, 15817 &data_u8r, 15818 BNO055_GEN_READ_WRITE_LENGTH); 15819 } 15820 break; 15821 default: 15822 com_rslt = BNO055_OUT_OF_RANGE; 15823 break; 15824 } 15825 } else { 15826 com_rslt = BNO055_ERROR; 15827 } 15828 } else { 15829 com_rslt = BNO055_ERROR; 15830 } 15831 } else { 15832 com_rslt = BNO055_ERROR; 15833 } 15834 } 15835 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15836 /* set the operation mode of 15837 previous operation mode*/ 15838 com_rslt += bno055_set_operation_mode 15839 (prev_opmode_u8); 15840 return com_rslt; 15841 } 15842 /*! 15843 * @brief This API used to read gyro anymotion filter 15844 * from page one register from 0x17 bit 6 15845 * 15846 * @param gyro_any_motion_filter_u8 : The value of gyro anymotion filter 15847 * gyro_any_motion_filter_u8 | result 15848 * --------------------------- |------------ 15849 * 0x00 | BNO055_GYRO_FILTERED_CONFIG 15850 * 0x01 | BNO055_GYRO_UNFILTERED_CONFIG 15851 * 15852 * @return results of bus communication function 15853 * @retval 0 -> BNO055_SUCCESS 15854 * @retval 1 -> BNO055_ERROR 15855 * 15856 */ 15857 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_any_motion_filter( 15858 u8 *gyro_any_motion_filter_u8) 15859 { 15860 /* Variable used to return value of 15861 communication routine*/ 15862 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15863 u8 data_u8r = BNO055_INIT_VALUE; 15864 s8 stat_s8 = BNO055_ERROR; 15865 /* Check the struct p_bno055 is empty */ 15866 if (p_bno055 == BNO055_INIT_VALUE) { 15867 return BNO055_E_NULL_PTR; 15868 } else { 15869 /*condition check for page, gyro anymotion filter is 15870 available in the page one*/ 15871 if (p_bno055->page_id != BNO055_PAGE_ONE) 15872 /* Write page as one */ 15873 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15874 if ((stat_s8 == BNO055_SUCCESS) || 15875 (p_bno055->page_id == BNO055_PAGE_ONE)) { 15876 /* Read the value of gyro anymotion filter*/ 15877 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15878 (p_bno055->dev_addr, 15879 BNO055_GYRO_ANY_MOTION_FILTER_REG, 15880 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15881 *gyro_any_motion_filter_u8 = 15882 BNO055_GET_BITSLICE(data_u8r, 15883 BNO055_GYRO_ANY_MOTION_FILTER); 15884 } else { 15885 com_rslt = BNO055_ERROR; 15886 } 15887 } 15888 return com_rslt; 15889 } 15890 /*! 15891 * @brief This API used to write gyro anymotion filter 15892 * from page one register from 0x17 bit 6 15893 * 15894 * @param gyro_any_motion_filter_u8 : The value of gyro anymotion filter 15895 * gyro_any_motion_filter_u8 | result 15896 * --------------------------- |------------ 15897 * 0x00 | BNO055_GYRO_FILTERED_CONFIG 15898 * 0x01 | BNO055_GYRO_UNFILTERED_CONFIG 15899 * 15900 * @return results of bus communication function 15901 * @retval 0 -> BNO055_SUCCESS 15902 * @retval 1 -> BNO055_ERROR 15903 * 15904 */ 15905 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_any_motion_filter( 15906 u8 gyro_any_motion_filter_u8) 15907 { 15908 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15909 u8 data_u8r = BNO055_INIT_VALUE; 15910 s8 stat_s8 = BNO055_ERROR; 15911 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 15912 s8 pg_stat_s8 = BNO055_ERROR; 15913 /* Check the struct p_bno055 is empty */ 15914 if (p_bno055 == BNO055_INIT_VALUE) { 15915 return BNO055_E_NULL_PTR; 15916 } else { 15917 /* The write operation effective only if the operation 15918 mode is in config mode, this part of code is checking the 15919 current operation mode and set the config mode */ 15920 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 15921 if (stat_s8 == BNO055_SUCCESS) { 15922 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15923 stat_s8 += bno055_set_operation_mode 15924 (BNO055_OPERATION_MODE_CONFIG); 15925 if (stat_s8 == BNO055_SUCCESS) { 15926 /* Write page as one */ 15927 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15928 if (pg_stat_s8 == BNO055_SUCCESS) { 15929 /* Write the value of 15930 gyro anymotion filter*/ 15931 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 15932 (p_bno055->dev_addr, 15933 BNO055_GYRO_ANY_MOTION_FILTER_REG, 15934 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 15935 if (com_rslt == BNO055_SUCCESS) { 15936 data_u8r = 15937 BNO055_SET_BITSLICE(data_u8r, 15938 BNO055_GYRO_ANY_MOTION_FILTER, 15939 gyro_any_motion_filter_u8); 15940 com_rslt += 15941 p_bno055->BNO055_BUS_WRITE_FUNC 15942 (p_bno055->dev_addr, 15943 BNO055_GYRO_ANY_MOTION_FILTER_REG, 15944 &data_u8r, 15945 BNO055_GEN_READ_WRITE_LENGTH); 15946 } 15947 } else { 15948 com_rslt = BNO055_ERROR; 15949 } 15950 } else { 15951 com_rslt = BNO055_ERROR; 15952 } 15953 } else { 15954 com_rslt = BNO055_ERROR; 15955 } 15956 } 15957 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 15958 /* set the operation mode of 15959 previous operation mode*/ 15960 com_rslt += bno055_set_operation_mode 15961 (prev_opmode_u8); 15962 return com_rslt; 15963 } 15964 /*! 15965 * @brief This API used to read gyro highrate filter 15966 * from page one register from 0x17 bit 7 15967 * 15968 * @param gyro_highrate_filter_u8 : The value of gyro highrate filter 15969 * gyro_highrate_filter_u8 | result 15970 * --------------------------- |------------ 15971 * 0x00 | BNO055_GYRO_FILTERED_CONFIG 15972 * 0x01 | BNO055_GYRO_UNFILTERED_CONFIG 15973 * 15974 * @return results of bus communication function 15975 * @retval 0 -> BNO055_SUCCESS 15976 * @retval 1 -> BNO055_ERROR 15977 * 15978 */ 15979 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_filter( 15980 u8 *gyro_highrate_filter_u8) 15981 { 15982 /* Variable used to return value of 15983 communication routine*/ 15984 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 15985 u8 data_u8r = BNO055_INIT_VALUE; 15986 s8 stat_s8 = BNO055_ERROR; 15987 /* Check the struct p_bno055 is empty */ 15988 if (p_bno055 == BNO055_INIT_VALUE) { 15989 return BNO055_E_NULL_PTR; 15990 } else { 15991 /*condition check for page, gyro highrate filter is 15992 available in the page one*/ 15993 if (p_bno055->page_id != BNO055_PAGE_ONE) 15994 /* Write page as one */ 15995 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 15996 if ((stat_s8 == BNO055_SUCCESS) || 15997 (p_bno055->page_id == BNO055_PAGE_ONE)) { 15998 /* Read the value of gyro highrate filter */ 15999 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16000 (p_bno055->dev_addr, 16001 BNO055_GYRO_HIGHRATE_FILTER_REG, 16002 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16003 *gyro_highrate_filter_u8 = 16004 BNO055_GET_BITSLICE(data_u8r, 16005 BNO055_GYRO_HIGHRATE_FILTER); 16006 } else { 16007 com_rslt = BNO055_ERROR; 16008 } 16009 } 16010 return com_rslt; 16011 } 16012 /*! 16013 * @brief This API used to write gyro highrate filter 16014 * from page one register from 0x17 bit 7 16015 * 16016 * @param gyro_highrate_filter_u8 : The value of gyro highrate filter 16017 * gyro_highrate_filter_u8 | result 16018 * --------------------------- |------------ 16019 * 0x00 | BNO055_GYRO_FILTERED_CONFIG 16020 * 0x01 | BNO055_GYRO_UNFILTERED_CONFIG 16021 * 16022 * @return results of bus communication function 16023 * @retval 0 -> BNO055_SUCCESS 16024 * @retval 1 -> BNO055_ERROR 16025 * 16026 */ 16027 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_filter( 16028 u8 gyro_highrate_filter_u8) 16029 { 16030 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16031 u8 data_u8r = BNO055_INIT_VALUE; 16032 s8 stat_s8 = BNO055_ERROR; 16033 s8 pg_stat_s8 = BNO055_ERROR; 16034 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16035 /* Check the struct p_bno055 is empty */ 16036 if (p_bno055 == BNO055_INIT_VALUE) { 16037 return BNO055_E_NULL_PTR; 16038 } else { 16039 /* The write operation effective only if the operation 16040 mode is in config mode, this part of code is checking the 16041 current operation mode and set the config mode */ 16042 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16043 if (stat_s8 == BNO055_SUCCESS) { 16044 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16045 stat_s8 += bno055_set_operation_mode 16046 (BNO055_OPERATION_MODE_CONFIG); 16047 if (stat_s8 == BNO055_SUCCESS) { 16048 /* Write page as one */ 16049 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16050 if (pg_stat_s8 == BNO055_SUCCESS) { 16051 /* Write the value of 16052 gyro highrate filter*/ 16053 com_rslt = 16054 p_bno055->BNO055_BUS_READ_FUNC 16055 (p_bno055->dev_addr, 16056 BNO055_GYRO_HIGHRATE_FILTER_REG, 16057 &data_u8r, 16058 BNO055_GEN_READ_WRITE_LENGTH); 16059 if (com_rslt == BNO055_SUCCESS) { 16060 data_u8r = 16061 BNO055_SET_BITSLICE(data_u8r, 16062 BNO055_GYRO_HIGHRATE_FILTER, 16063 gyro_highrate_filter_u8); 16064 com_rslt += 16065 p_bno055->BNO055_BUS_WRITE_FUNC 16066 (p_bno055->dev_addr, 16067 BNO055_GYRO_HIGHRATE_FILTER_REG, 16068 &data_u8r, 16069 BNO055_GEN_READ_WRITE_LENGTH); 16070 } 16071 } else { 16072 com_rslt = BNO055_ERROR; 16073 } 16074 } else { 16075 com_rslt = BNO055_ERROR; 16076 } 16077 } else { 16078 com_rslt = BNO055_ERROR; 16079 } 16080 } 16081 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16082 /* set the operation mode of 16083 previous operation mode*/ 16084 com_rslt += bno055_set_operation_mode 16085 (prev_opmode_u8); 16086 return com_rslt; 16087 } 16088 /*! 16089 * @brief This API used to read gyro highrate x threshold 16090 * from page one register from 0x18 bit 0 to 4 16091 * 16092 * @param gyro_highrate_x_thres_u8 : The value of gyro x highrate threshold 16093 * 16094 * @return results of bus communication function 16095 * @retval 0 -> BNO055_SUCCESS 16096 * @retval 1 -> BNO055_ERROR 16097 * 16098 * @note Gyro highrate threshold dependent on the 16099 * selection of gyro range 16100 * 16101 * gyro_range_u8 | threshold | LSB 16102 * ----------------- | ------------- | --------- 16103 * 2000 | 62.5dps | 1LSB 16104 * 1000 | 31.25dps | 1LSB 16105 * 500 | 15.625dps | 1LSB 16106 * 125 | 7.8125dps | 1LSB 16107 * 16108 */ 16109 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_x_thres( 16110 u8 *gyro_highrate_x_thres_u8) 16111 { 16112 /* Variable used to return value of 16113 communication routine*/ 16114 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16115 u8 data_u8r = BNO055_INIT_VALUE; 16116 s8 stat_s8 = BNO055_ERROR; 16117 /* Check the struct p_bno055 is empty */ 16118 if (p_bno055 == BNO055_INIT_VALUE) { 16119 return BNO055_E_NULL_PTR; 16120 } else { 16121 /*condition check for page, gyro highrate x threshold is 16122 available in the page one*/ 16123 if (p_bno055->page_id != BNO055_PAGE_ONE) 16124 /* Write page as one */ 16125 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16126 if ((stat_s8 == BNO055_SUCCESS) || 16127 (p_bno055->page_id == BNO055_PAGE_ONE)) { 16128 /* Read the value of gyro highrate threshold*/ 16129 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16130 (p_bno055->dev_addr, 16131 BNO055_GYRO_HIGHRATE_X_THRES_REG, 16132 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16133 *gyro_highrate_x_thres_u8 = 16134 BNO055_GET_BITSLICE(data_u8r, 16135 BNO055_GYRO_HIGHRATE_X_THRES); 16136 } else { 16137 com_rslt = BNO055_ERROR; 16138 } 16139 } 16140 return com_rslt; 16141 } 16142 /*! 16143 * @brief This API used to write gyro highrate x threshold 16144 * from page one register from 0x18 bit 0 to 4 16145 * 16146 * @param gyro_highrate_x_thres_u8 : The value of gyro x highrate threshold 16147 * 16148 * @return results of bus communication function 16149 * @retval 0 -> BNO055_SUCCESS 16150 * @retval 1 -> BNO055_ERROR 16151 * 16152 * @note Gyro highrate threshold dependent on the 16153 * selection of gyro range 16154 * 16155 * gyro_range_u8 | threshold | LSB 16156 * ----------------- | ------------- | --------- 16157 * 2000 | 62.5dps | 1LSB 16158 * 1000 | 31.25dps | 1LSB 16159 * 500 | 15.625dps | 1LSB 16160 * 125 | 7.8125dps | 1LSB 16161 * 16162 */ 16163 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_x_thres( 16164 u8 gyro_highrate_x_thres_u8) 16165 { 16166 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16167 u8 data_u8r = BNO055_INIT_VALUE; 16168 s8 stat_s8 = BNO055_ERROR; 16169 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16170 s8 pg_stat_s8 = BNO055_ERROR; 16171 /* Check the struct p_bno055 is empty */ 16172 if (p_bno055 == BNO055_INIT_VALUE) { 16173 return BNO055_E_NULL_PTR; 16174 } else { 16175 /* The write operation effective only if the operation 16176 mode is in config mode, this part of code is checking the 16177 current operation mode and set the config mode */ 16178 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16179 if (stat_s8 == BNO055_SUCCESS) { 16180 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16181 stat_s8 += bno055_set_operation_mode 16182 (BNO055_OPERATION_MODE_CONFIG); 16183 if (stat_s8 == BNO055_SUCCESS) { 16184 /* Write page as one */ 16185 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16186 if (pg_stat_s8 == BNO055_SUCCESS) { 16187 /* Write the value of 16188 gyro highrate x threshold*/ 16189 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16190 (p_bno055->dev_addr, 16191 BNO055_GYRO_HIGHRATE_X_THRES_REG, 16192 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16193 if (com_rslt == BNO055_SUCCESS) { 16194 data_u8r = 16195 BNO055_SET_BITSLICE(data_u8r, 16196 BNO055_GYRO_HIGHRATE_X_THRES, 16197 gyro_highrate_x_thres_u8); 16198 com_rslt += 16199 p_bno055->BNO055_BUS_WRITE_FUNC 16200 (p_bno055->dev_addr, 16201 BNO055_GYRO_HIGHRATE_X_THRES_REG, 16202 &data_u8r, 16203 BNO055_GEN_READ_WRITE_LENGTH); 16204 } 16205 } else { 16206 com_rslt = BNO055_ERROR; 16207 } 16208 } else { 16209 com_rslt = BNO055_ERROR; 16210 } 16211 } else { 16212 com_rslt = BNO055_ERROR; 16213 } 16214 } 16215 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16216 /* set the operation mode of 16217 previous operation mode*/ 16218 com_rslt += bno055_set_operation_mode 16219 (prev_opmode_u8); 16220 return com_rslt; 16221 } 16222 /*! 16223 * @brief This API used to read gyro highrate x hysteresis 16224 * from page one register from 0x18 bit 5 to 6 16225 * 16226 * @param gyro_highrate_x_hyst_u8 : The value of gyro highrate x hysteresis 16227 * 16228 * @return results of bus communication function 16229 * @retval 0 -> BNO055_SUCCESS 16230 * @retval 1 -> BNO055_ERROR 16231 * 16232 * @note Gyro high rate hysteresis calculated by 16233 * 16234 * using this (255 + 256 * gyro_highrate_x_hyst_u8) *4 LSB 16235 * 16236 * The high rate value scales with the range setting 16237 * 16238 * gyro_range_u8 | hysteresis | LSB 16239 * ----------------- | ------------- | --------- 16240 * 2000 | 62.26dps | 1LSB 16241 * 1000 | 31.13dps | 1LSB 16242 * 500 | 15.56dps | 1LSB 16243 * 16244 */ 16245 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_x_hyst( 16246 u8 *gyro_highrate_x_hyst_u8) 16247 { 16248 /* Variable used to return value of 16249 communication routine*/ 16250 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16251 u8 data_u8r = BNO055_INIT_VALUE; 16252 s8 stat_s8 = BNO055_ERROR; 16253 /* Check the struct p_bno055 is empty */ 16254 if (p_bno055 == BNO055_INIT_VALUE) { 16255 return BNO055_E_NULL_PTR; 16256 } else { 16257 /*condition check for page,gyro highrate x hysteresis is 16258 available in the page one*/ 16259 if (p_bno055->page_id != BNO055_PAGE_ONE) 16260 /* Write page as one */ 16261 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16262 if ((stat_s8 == BNO055_SUCCESS) || 16263 (p_bno055->page_id == BNO055_PAGE_ONE)) { 16264 /* Read the value of gyro highrate x hysteresis*/ 16265 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16266 (p_bno055->dev_addr, 16267 BNO055_GYRO_HIGHRATE_X_HYST_REG, 16268 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16269 *gyro_highrate_x_hyst_u8 = 16270 BNO055_GET_BITSLICE(data_u8r, 16271 BNO055_GYRO_HIGHRATE_X_HYST); 16272 } else { 16273 com_rslt = BNO055_ERROR; 16274 } 16275 } 16276 return com_rslt; 16277 } 16278 /*! 16279 * @brief This API used to write gyro highrate x hysteresis 16280 * from page one register from 0x18 bit 5 to 6 16281 * 16282 * @param gyro_highrate_x_hyst_u8 : The value of gyro highrate x hysteresis 16283 * 16284 * @return results of bus communication function 16285 * @retval 0 -> BNO055_SUCCESS 16286 * @retval 1 -> BNO055_ERROR 16287 * 16288 * @note Gyro high rate hysteresis calculated by 16289 * 16290 * using this (255 + 256 * gyro_highrate_x_hyst_u8) *4 LSB 16291 * 16292 * The high rate value scales with the range setting 16293 * 16294 * gyro_range_u8 | hysteresis | LSB 16295 * ----------------- | ------------- | --------- 16296 * 2000 | 62.26dps | 1LSB 16297 * 1000 | 31.13dps | 1LSB 16298 * 500 | 15.56dps | 1LSB 16299 * 16300 */ 16301 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_x_hyst( 16302 u8 gyro_highrate_x_hyst_u8) 16303 { 16304 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16305 u8 data_u8r = BNO055_INIT_VALUE; 16306 s8 stat_s8 = BNO055_ERROR; 16307 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16308 s8 pg_stat_s8 = BNO055_ERROR; 16309 /* Check the struct p_bno055 is empty */ 16310 if (p_bno055 == BNO055_INIT_VALUE) { 16311 return BNO055_E_NULL_PTR; 16312 } else { 16313 /* The write operation effective only if the operation 16314 mode is in config mode, this part of code is checking the 16315 current operation mode and set the config mode */ 16316 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16317 if (stat_s8 == BNO055_SUCCESS) { 16318 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16319 stat_s8 += bno055_set_operation_mode 16320 (BNO055_OPERATION_MODE_CONFIG); 16321 if (stat_s8 == BNO055_SUCCESS) { 16322 /* Write page as one */ 16323 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16324 if (pg_stat_s8 == BNO055_SUCCESS) { 16325 /*Write the value of 16326 gyro highrate x hysteresis*/ 16327 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16328 (p_bno055->dev_addr, 16329 BNO055_GYRO_HIGHRATE_X_HYST_REG, 16330 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16331 if (com_rslt == BNO055_SUCCESS) { 16332 data_u8r = 16333 BNO055_SET_BITSLICE(data_u8r, 16334 BNO055_GYRO_HIGHRATE_X_HYST, 16335 gyro_highrate_x_hyst_u8); 16336 com_rslt += 16337 p_bno055->BNO055_BUS_WRITE_FUNC 16338 (p_bno055->dev_addr, 16339 BNO055_GYRO_HIGHRATE_X_HYST_REG, 16340 &data_u8r, 16341 BNO055_GEN_READ_WRITE_LENGTH); 16342 } 16343 } else { 16344 com_rslt = BNO055_ERROR; 16345 } 16346 } else { 16347 com_rslt = BNO055_ERROR; 16348 } 16349 } else { 16350 com_rslt = BNO055_ERROR; 16351 } 16352 } 16353 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16354 /* set the operation mode of 16355 previous operation mode*/ 16356 com_rslt += bno055_set_operation_mode 16357 (prev_opmode_u8); 16358 return com_rslt; 16359 } 16360 /*! 16361 * @brief This API used to read gyro highrate x duration 16362 * from page one register from 0x19 bit 0 to 7 16363 * 16364 * @param gyro_highrate_x_durn_u8 : The value of gyro highrate x duration 16365 * 16366 * @return results of bus communication function 16367 * @retval 0 -> BNO055_SUCCESS 16368 * @retval 1 -> BNO055_ERROR 16369 * 16370 * @note Gyro highrate duration calculate by using the formula 16371 * 16372 * (1 + gyro_highrate_x_durn_u8)*2.5ms 16373 * 16374 */ 16375 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_x_durn( 16376 u8 *gyro_highrate_x_durn_u8) 16377 { 16378 /* Variable used to return value of 16379 communication routine*/ 16380 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16381 u8 data_u8r = BNO055_INIT_VALUE; 16382 s8 stat_s8 = BNO055_ERROR; 16383 /* Check the struct p_bno055 is empty */ 16384 if (p_bno055 == BNO055_INIT_VALUE) { 16385 return BNO055_E_NULL_PTR; 16386 } else { 16387 /*condition check for page, gyro highrate x duration is 16388 available in the page one*/ 16389 if (p_bno055->page_id != BNO055_PAGE_ONE) 16390 /* Write page as one */ 16391 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16392 if ((stat_s8 == BNO055_SUCCESS) || 16393 (p_bno055->page_id == BNO055_PAGE_ONE)) { 16394 /* Read the value of gyro highrate x duration*/ 16395 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16396 (p_bno055->dev_addr, 16397 BNO055_GYRO_HIGHRATE_X_DURN_REG, 16398 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16399 *gyro_highrate_x_durn_u8 = 16400 BNO055_GET_BITSLICE(data_u8r, 16401 BNO055_GYRO_HIGHRATE_X_DURN); 16402 } else { 16403 com_rslt = BNO055_ERROR; 16404 } 16405 } 16406 return com_rslt; 16407 } 16408 /*! 16409 * @brief This API used to write gyro highrate x duration 16410 * from page one register from 0x19 bit 0 to 7 16411 * 16412 * @param gyro_highrate_x_durn_u8 : The value of gyro highrate x duration 16413 * 16414 * @return results of bus communication function 16415 * @retval 0 -> BNO055_SUCCESS 16416 * @retval 1 -> BNO055_ERROR 16417 * 16418 * @note Gyro highrate duration calculate by using the formula 16419 * 16420 * (1 + gyro_highrate_x_durn_u8)*2.5ms 16421 */ 16422 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_x_durn( 16423 u8 gyro_highrate_x_durn_u8) 16424 { 16425 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16426 u8 data_u8r = BNO055_INIT_VALUE; 16427 s8 stat_s8 = BNO055_ERROR; 16428 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16429 s8 pg_stat_s8 = BNO055_ERROR; 16430 /* Check the struct p_bno055 is empty */ 16431 if (p_bno055 == BNO055_INIT_VALUE) { 16432 return BNO055_E_NULL_PTR; 16433 } else { 16434 /* The write operation effective only if the operation 16435 mode is in config mode, this part of code is checking the 16436 current operation mode and set the config mode */ 16437 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16438 if (stat_s8 == BNO055_SUCCESS) { 16439 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16440 stat_s8 += bno055_set_operation_mode 16441 (BNO055_OPERATION_MODE_CONFIG); 16442 if (stat_s8 == BNO055_SUCCESS) { 16443 /* Write page as one */ 16444 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16445 if (pg_stat_s8 == BNO055_SUCCESS) { 16446 /* Write the value 16447 of gyro highrate x duration*/ 16448 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16449 (p_bno055->dev_addr, 16450 BNO055_GYRO_HIGHRATE_X_DURN_REG, 16451 &data_u8r, 16452 BNO055_GEN_READ_WRITE_LENGTH); 16453 if (com_rslt == BNO055_SUCCESS) { 16454 data_u8r = 16455 BNO055_SET_BITSLICE(data_u8r, 16456 BNO055_GYRO_HIGHRATE_X_DURN, 16457 gyro_highrate_x_durn_u8); 16458 com_rslt += 16459 p_bno055->BNO055_BUS_WRITE_FUNC 16460 (p_bno055->dev_addr, 16461 BNO055_GYRO_HIGHRATE_X_DURN_REG, 16462 &data_u8r, 16463 BNO055_GEN_READ_WRITE_LENGTH); 16464 } 16465 } else { 16466 com_rslt = BNO055_ERROR; 16467 } 16468 } else { 16469 com_rslt = BNO055_ERROR; 16470 } 16471 } else { 16472 com_rslt = BNO055_ERROR; 16473 } 16474 } 16475 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16476 /* set the operation mode of 16477 previous operation mode*/ 16478 com_rslt += bno055_set_operation_mode 16479 (prev_opmode_u8); 16480 return com_rslt; 16481 } 16482 /*! 16483 * @brief This API used to read gyro highrate y threshold 16484 * from page one register from 0x1A bit 0 to 4 16485 * 16486 * @param gyro_highrate_y_thres_u8 : The value of gyro highrate y threshold 16487 * 16488 * @return results of bus communication function 16489 * @retval 0 -> BNO055_SUCCESS 16490 * @retval 1 -> BNO055_ERROR 16491 * 16492 * @note Gyro highrate threshold dependent on the 16493 * selection of gyro range 16494 * 16495 * gyro_range_u8 | threshold | LSB 16496 * ----------------- | ------------- | --------- 16497 * 2000 | 62.5dps | 1LSB 16498 * 1000 | 31.25dps | 1LSB 16499 * 500 | 15.625dps | 1LSB 16500 * 125 | 7.8125dps | 1LSB 16501 * 16502 */ 16503 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_y_thres( 16504 u8 *gyro_highrate_y_thres_u8) 16505 { 16506 /* Variable used to return value of 16507 communication routine*/ 16508 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16509 u8 data_u8r = BNO055_INIT_VALUE; 16510 s8 stat_s8 = BNO055_ERROR; 16511 /* Check the struct p_bno055 is empty */ 16512 if (p_bno055 == BNO055_INIT_VALUE) { 16513 return BNO055_E_NULL_PTR; 16514 } else { 16515 /*condition check for page, gyro highrate y threshold is 16516 available in the page one*/ 16517 if (p_bno055->page_id != BNO055_PAGE_ONE) 16518 /* Write page as one */ 16519 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16520 if ((stat_s8 == BNO055_SUCCESS) || 16521 (p_bno055->page_id == BNO055_PAGE_ONE)) { 16522 /* Read the value of gyro highrate y threshold*/ 16523 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16524 (p_bno055->dev_addr, 16525 BNO055_GYRO_HIGHRATE_Y_THRES_REG, 16526 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16527 *gyro_highrate_y_thres_u8 = 16528 BNO055_GET_BITSLICE(data_u8r, 16529 BNO055_GYRO_HIGHRATE_Y_THRES); 16530 } else { 16531 com_rslt = BNO055_ERROR; 16532 } 16533 } 16534 return com_rslt; 16535 } 16536 /*! 16537 * @brief This API used to write gyro highrate y threshold 16538 * from page one register from 0x1A bit 0 to 4 16539 * 16540 * @param gyro_highrate_y_thres_u8 : The value of gyro highrate y threshold 16541 * 16542 * @return results of bus communication function 16543 * @retval 0 -> BNO055_SUCCESS 16544 * @retval 1 -> BNO055_ERROR 16545 * 16546 * @note Gyro highrate threshold dependent on the 16547 * selection of gyro range 16548 * 16549 * gyro_range_u8 | threshold | LSB 16550 * ----------------- | ------------- | --------- 16551 * 2000 | 62.5dps | 1LSB 16552 * 1000 | 31.25dps | 1LSB 16553 * 500 | 15.625dps | 1LSB 16554 * 125 | 7.8125dps | 1LSB 16555 * 16556 */ 16557 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_y_thres( 16558 u8 gyro_highrate_y_thres_u8) 16559 { 16560 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16561 u8 data_u8r = BNO055_INIT_VALUE; 16562 s8 stat_s8 = BNO055_ERROR; 16563 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16564 s8 pg_stat_s8 = BNO055_ERROR; 16565 /* Check the struct p_bno055 is empty */ 16566 if (p_bno055 == BNO055_INIT_VALUE) { 16567 return BNO055_E_NULL_PTR; 16568 } else { 16569 /* The write operation effective only if the operation 16570 mode is in config mode, this part of code is checking the 16571 current operation mode and set the config mode */ 16572 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16573 if (stat_s8 == BNO055_SUCCESS) { 16574 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16575 stat_s8 += bno055_set_operation_mode 16576 (BNO055_OPERATION_MODE_CONFIG); 16577 if (stat_s8 == BNO055_SUCCESS) { 16578 /* Write page as one */ 16579 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16580 if (pg_stat_s8 == BNO055_SUCCESS) { 16581 /* Write the value 16582 of gyro highrate y threshold*/ 16583 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16584 (p_bno055->dev_addr, 16585 BNO055_GYRO_HIGHRATE_Y_THRES_REG, 16586 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16587 if (com_rslt == BNO055_SUCCESS) { 16588 data_u8r = 16589 BNO055_SET_BITSLICE(data_u8r, 16590 BNO055_GYRO_HIGHRATE_Y_THRES, 16591 gyro_highrate_y_thres_u8); 16592 com_rslt += 16593 p_bno055->BNO055_BUS_WRITE_FUNC 16594 (p_bno055->dev_addr, 16595 BNO055_GYRO_HIGHRATE_Y_THRES_REG, 16596 &data_u8r, 16597 BNO055_GEN_READ_WRITE_LENGTH); 16598 } 16599 } else { 16600 com_rslt = BNO055_ERROR; 16601 } 16602 } else { 16603 com_rslt = BNO055_ERROR; 16604 } 16605 } else { 16606 com_rslt = BNO055_ERROR; 16607 } 16608 } 16609 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16610 /* set the operation mode of 16611 previous operation mode*/ 16612 com_rslt += bno055_set_operation_mode 16613 (prev_opmode_u8); 16614 return com_rslt; 16615 } 16616 /*! 16617 * @brief This API used to read gyro highrate y hysteresis 16618 * from page one register from 0x1A bit 5 to 6 16619 * 16620 * @param gyro_highrate_y_hyst_u8 : The value of gyro highrate y hysteresis 16621 * 16622 * @return results of bus communication function 16623 * @retval 0 -> BNO055_SUCCESS 16624 * @retval 1 -> BNO055_ERROR 16625 * 16626 * @note Gyro high rate hysteresis calculated by 16627 * 16628 * using this (255 + 256 * gyro_highrate_y_hyst_u8) *4 LSB 16629 * 16630 * The high rate value scales with the range setting 16631 * 16632 * gyro_range_u8 | hysteresis | LSB 16633 * ----------------- | ------------- | --------- 16634 * 2000 | 62.26dps | 1LSB 16635 * 1000 | 31.13dps | 1LSB 16636 * 500 | 15.56dps | 1LSB 16637 */ 16638 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_y_hyst( 16639 u8 *gyro_highrate_y_hyst_u8) 16640 { 16641 /* Variable used to return value of 16642 communication routine*/ 16643 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16644 u8 data_u8r = BNO055_INIT_VALUE; 16645 s8 stat_s8 = BNO055_ERROR; 16646 /* Check the struct p_bno055 is empty */ 16647 if (p_bno055 == BNO055_INIT_VALUE) { 16648 return BNO055_E_NULL_PTR; 16649 } else { 16650 /*condition check for page, gyro highrate y hysteresis is 16651 available in the page one*/ 16652 if (p_bno055->page_id != BNO055_PAGE_ONE) 16653 /* Write page as one */ 16654 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16655 if ((stat_s8 == BNO055_SUCCESS) || 16656 (p_bno055->page_id == BNO055_PAGE_ONE)) { 16657 /* Read the value of gyro highrate y hysteresis*/ 16658 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16659 (p_bno055->dev_addr, 16660 BNO055_GYRO_HIGHRATE_Y_HYST_REG, 16661 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16662 *gyro_highrate_y_hyst_u8 = 16663 BNO055_GET_BITSLICE(data_u8r, 16664 BNO055_GYRO_HIGHRATE_Y_HYST); 16665 } else { 16666 com_rslt = BNO055_ERROR; 16667 } 16668 } 16669 return com_rslt; 16670 } 16671 /*! 16672 * @brief This API used to write gyro highrate y hysteresis 16673 * from page one register from 0x1A bit 5 to 6 16674 * 16675 * @param gyro_highrate_y_hyst_u8 : The value of gyro highrate y hysteresis 16676 * 16677 * @return results of bus communication function 16678 * @retval 0 -> BNO055_SUCCESS 16679 * @retval 1 -> BNO055_ERROR 16680 * 16681 * @note Gyro high rate hysteresis calculated by 16682 * 16683 * using this (255 + 256 * gyro_highrate_y_hyst_u8) *4 LSB 16684 * 16685 * The high rate value scales with the range setting 16686 * 16687 * gyro_range_u8 | hysteresis | LSB 16688 * ----------------- | ------------- | --------- 16689 * 2000 | 62.26dps | 1LSB 16690 * 1000 | 31.13dps | 1LSB 16691 * 500 | 15.56dps | 1LSB 16692 */ 16693 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_y_hyst( 16694 u8 gyro_highrate_y_hyst_u8) 16695 { 16696 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16697 u8 data_u8r = BNO055_INIT_VALUE; 16698 s8 stat_s8 = BNO055_ERROR; 16699 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16700 s8 pg_stat_s8 = BNO055_ERROR; 16701 /* Check the struct p_bno055 is empty */ 16702 if (p_bno055 == BNO055_INIT_VALUE) { 16703 return BNO055_E_NULL_PTR; 16704 } else { 16705 /* The write operation effective only if the operation 16706 mode is in config mode, this part of code is checking the 16707 current operation mode and set the config mode */ 16708 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16709 if (stat_s8 == BNO055_SUCCESS) { 16710 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16711 stat_s8 += bno055_set_operation_mode 16712 (BNO055_OPERATION_MODE_CONFIG); 16713 if (stat_s8 == BNO055_SUCCESS) { 16714 /* Write page as one */ 16715 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16716 if (pg_stat_s8 == BNO055_SUCCESS) { 16717 /* Write the value of 16718 gyro highrate y hysteresis*/ 16719 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16720 (p_bno055->dev_addr, 16721 BNO055_GYRO_HIGHRATE_Y_HYST_REG, 16722 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16723 if (com_rslt == BNO055_SUCCESS) { 16724 data_u8r = 16725 BNO055_SET_BITSLICE(data_u8r, 16726 BNO055_GYRO_HIGHRATE_Y_HYST, 16727 gyro_highrate_y_hyst_u8); 16728 com_rslt += 16729 p_bno055->BNO055_BUS_WRITE_FUNC 16730 (p_bno055->dev_addr, 16731 BNO055_GYRO_HIGHRATE_Y_HYST_REG, 16732 &data_u8r, 16733 BNO055_GEN_READ_WRITE_LENGTH); 16734 } 16735 } else { 16736 com_rslt = BNO055_ERROR; 16737 } 16738 } else { 16739 com_rslt = BNO055_ERROR; 16740 } 16741 } else { 16742 com_rslt = BNO055_ERROR; 16743 } 16744 } 16745 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16746 /* set the operation mode of 16747 previous operation mode*/ 16748 com_rslt += bno055_set_operation_mode 16749 (prev_opmode_u8); 16750 return com_rslt; 16751 } 16752 /*! 16753 * @brief This API used to read gyro highrate y duration 16754 * from page one register from 0x1B bit 0 to 7 16755 * 16756 * @param gyro_highrate_y_durn_u8 : The value of gyro highrate y duration 16757 * 16758 * @return results of bus communication function 16759 * @retval 0 -> BNO055_SUCCESS 16760 * @retval 1 -> BNO055_ERROR 16761 * 16762 * @note Gyro highrate duration calculate by using the formula 16763 * 16764 * (1 + gyro_highrate_y_durn_u8)*2.5ms 16765 */ 16766 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_y_durn( 16767 u8 *gyro_highrate_y_durn_u8) 16768 { 16769 /* Variable used to return value of 16770 communication routine*/ 16771 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16772 u8 data_u8r = BNO055_INIT_VALUE; 16773 s8 stat_s8 = BNO055_ERROR; 16774 /* Check the struct p_bno055 is empty */ 16775 if (p_bno055 == BNO055_INIT_VALUE) { 16776 return BNO055_E_NULL_PTR; 16777 } else { 16778 /*condition check for page, gyro highrate y duration is 16779 available in the page one*/ 16780 if (p_bno055->page_id != BNO055_PAGE_ONE) 16781 /* Write page as one */ 16782 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16783 if ((stat_s8 == BNO055_SUCCESS) || 16784 (p_bno055->page_id == BNO055_PAGE_ONE)) { 16785 /* Read the value of gyro highrate y duration*/ 16786 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16787 (p_bno055->dev_addr, 16788 BNO055_GYRO_HIGHRATE_Y_DURN_REG, 16789 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16790 *gyro_highrate_y_durn_u8 = 16791 BNO055_GET_BITSLICE(data_u8r, 16792 BNO055_GYRO_HIGHRATE_Y_DURN); 16793 } else { 16794 com_rslt = BNO055_ERROR; 16795 } 16796 } 16797 return com_rslt; 16798 } 16799 /*! 16800 * @brief This API used to write gyro highrate y duration 16801 * from page one register from 0x1B bit 0 to 7 16802 * 16803 * @param gyro_highrate_y_durn_u8 : The value of gyro highrate y duration 16804 * 16805 * @return results of bus communication function 16806 * @retval 0 -> BNO055_SUCCESS 16807 * @retval 1 -> BNO055_ERROR 16808 * 16809 * @note Gyro highrate duration calculate by using the formula 16810 * 16811 * (1 + gyro_highrate_y_durn_u8)*2.5ms 16812 */ 16813 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_y_durn( 16814 u8 gyro_highrate_y_durn_u8) 16815 { 16816 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16817 u8 data_u8r = BNO055_INIT_VALUE; 16818 s8 stat_s8 = BNO055_ERROR; 16819 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16820 s8 pg_stat_s8 = BNO055_ERROR; 16821 /* Check the struct p_bno055 is empty */ 16822 if (p_bno055 == BNO055_INIT_VALUE) { 16823 return BNO055_E_NULL_PTR; 16824 } else { 16825 /* The write operation effective only if the operation 16826 mode is in config mode, this part of code is checking the 16827 current operation mode and set the config mode */ 16828 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16829 if (stat_s8 == BNO055_SUCCESS) { 16830 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16831 stat_s8 += bno055_set_operation_mode 16832 (BNO055_OPERATION_MODE_CONFIG); 16833 16834 if (stat_s8 == BNO055_SUCCESS) { 16835 /* Write page as one */ 16836 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16837 if (pg_stat_s8 == BNO055_SUCCESS) { 16838 /* Write the value 16839 of gyro highrate y duration*/ 16840 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16841 (p_bno055->dev_addr, 16842 BNO055_GYRO_HIGHRATE_Y_DURN_REG, 16843 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16844 if (com_rslt == BNO055_SUCCESS) { 16845 data_u8r = 16846 BNO055_SET_BITSLICE(data_u8r, 16847 BNO055_GYRO_HIGHRATE_Y_DURN, 16848 gyro_highrate_y_durn_u8); 16849 com_rslt += 16850 p_bno055->BNO055_BUS_WRITE_FUNC 16851 (p_bno055->dev_addr, 16852 BNO055_GYRO_HIGHRATE_Y_DURN_REG, 16853 &data_u8r, 16854 BNO055_GEN_READ_WRITE_LENGTH); 16855 } 16856 } else { 16857 com_rslt = BNO055_ERROR; 16858 } 16859 } else { 16860 com_rslt = BNO055_ERROR; 16861 } 16862 } else { 16863 com_rslt = BNO055_ERROR; 16864 } 16865 } 16866 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16867 /* set the operation mode of 16868 previous operation mode*/ 16869 com_rslt += bno055_set_operation_mode 16870 (prev_opmode_u8); 16871 return com_rslt; 16872 } 16873 /*! 16874 * @brief This API used to read gyro highrate z threshold 16875 * from page one register from 0x1C bit 0 to 4 16876 * 16877 * @param gyro_highrate_z_thres_u8 : The value of gyro highrate z threshold 16878 * 16879 * @return results of bus communication function 16880 * @retval 0 -> BNO055_SUCCESS 16881 * @retval 1 -> BNO055_ERROR 16882 * 16883 * @note Gyro highrate threshold dependent on the 16884 * selection of gyro range 16885 * 16886 * gyro_range_u8 | threshold | LSB 16887 * ----------------- | ------------- | --------- 16888 * 2000 | 62.5dps | 1LSB 16889 * 1000 | 31.25dps | 1LSB 16890 * 500 | 15.625dps | 1LSB 16891 * 125 | 7.8125dps | 1LSB 16892 * 16893 */ 16894 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_z_thres( 16895 u8 *gyro_highrate_z_thres_u8) 16896 { 16897 /* Variable used to return value of 16898 communication routine*/ 16899 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16900 u8 data_u8r = BNO055_INIT_VALUE; 16901 s8 stat_s8 = BNO055_ERROR; 16902 /* Check the struct p_bno055 is empty */ 16903 if (p_bno055 == BNO055_INIT_VALUE) { 16904 return BNO055_E_NULL_PTR; 16905 } else { 16906 /*condition check for page, gyro highrate z threshold is 16907 available in the page one*/ 16908 if (p_bno055->page_id != BNO055_PAGE_ONE) 16909 /* Write page as one */ 16910 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16911 if ((stat_s8 == BNO055_SUCCESS) || 16912 (p_bno055->page_id == BNO055_PAGE_ONE)) { 16913 /* Read the value of gyro highrate z threshold*/ 16914 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16915 (p_bno055->dev_addr, 16916 BNO055_GYRO_HIGHRATE_Z_THRES_REG, 16917 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16918 *gyro_highrate_z_thres_u8 = 16919 BNO055_GET_BITSLICE(data_u8r, 16920 BNO055_GYRO_HIGHRATE_Z_THRES); 16921 } else { 16922 com_rslt = BNO055_ERROR; 16923 } 16924 } 16925 return com_rslt; 16926 } 16927 /*! 16928 * @brief This API used to write gyro highrate z threshold 16929 * from page one register from 0x1C bit 0 to 4 16930 * 16931 * @param gyro_highrate_z_thres_u8 : The value of gyro highrate z threshold 16932 * 16933 * @return results of bus communication function 16934 * @retval 0 -> BNO055_SUCCESS 16935 * @retval 1 -> BNO055_ERROR 16936 * 16937 * @note Gyro highrate threshold dependent on the 16938 * selection of gyro range 16939 * 16940 * gyro_range_u8 | threshold | LSB 16941 * ----------------- | ------------- | --------- 16942 * 2000 | 62.5dps | 1LSB 16943 * 1000 | 31.25dps | 1LSB 16944 * 500 | 15.625dps | 1LSB 16945 * 125 | 7.8125dps | 1LSB 16946 * 16947 */ 16948 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_z_thres( 16949 u8 gyro_highrate_z_thres_u8) 16950 { 16951 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 16952 u8 data_u8r = BNO055_INIT_VALUE; 16953 s8 stat_s8 = BNO055_ERROR; 16954 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 16955 s8 pg_stat_s8 = BNO055_ERROR; 16956 /* Check the struct p_bno055 is empty */ 16957 if (p_bno055 == BNO055_INIT_VALUE) { 16958 return BNO055_E_NULL_PTR; 16959 } else { 16960 /* The write operation effective only if the operation 16961 mode is in config mode, this part of code is checking the 16962 current operation mode and set the config mode */ 16963 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 16964 if (stat_s8 == BNO055_SUCCESS) { 16965 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 16966 stat_s8 += bno055_set_operation_mode 16967 (BNO055_OPERATION_MODE_CONFIG); 16968 if (stat_s8 == BNO055_SUCCESS) { 16969 /* Write page as one */ 16970 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 16971 if (pg_stat_s8 == BNO055_SUCCESS) { 16972 /* Write the value 16973 of gyro highrate z threshold*/ 16974 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 16975 (p_bno055->dev_addr, 16976 BNO055_GYRO_HIGHRATE_Z_THRES_REG, 16977 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 16978 if (com_rslt == BNO055_SUCCESS) { 16979 data_u8r = 16980 BNO055_SET_BITSLICE(data_u8r, 16981 BNO055_GYRO_HIGHRATE_Z_THRES, 16982 gyro_highrate_z_thres_u8); 16983 com_rslt += 16984 p_bno055->BNO055_BUS_WRITE_FUNC 16985 (p_bno055->dev_addr, 16986 BNO055_GYRO_HIGHRATE_Z_THRES_REG, 16987 &data_u8r, 16988 BNO055_GEN_READ_WRITE_LENGTH); 16989 } 16990 } else { 16991 com_rslt = BNO055_ERROR; 16992 } 16993 } else { 16994 com_rslt = BNO055_ERROR; 16995 } 16996 } else { 16997 com_rslt = BNO055_ERROR; 16998 } 16999 } 17000 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17001 /* set the operation mode of 17002 previous operation mode*/ 17003 com_rslt += bno055_set_operation_mode 17004 (prev_opmode_u8); 17005 return com_rslt; 17006 } 17007 /*! 17008 * @brief This API used to read gyro highrate z hysteresis 17009 * from page one register from 0x1C bit 5 to 6 17010 * 17011 * @param gyro_highrate_z_hyst_u8 : The value of gyro highrate z hysteresis 17012 * 17013 * @return results of bus communication function 17014 * @retval 0 -> BNO055_SUCCESS 17015 * @retval 1 -> BNO055_ERROR 17016 * 17017 * @note Gyro high rate hysteresis calculated by 17018 * 17019 * using this (255 + 256 * gyro_highrate_z_hyst_u8) *4 LSB 17020 * 17021 * The high rate value scales with the range setting 17022 * 17023 * gyro_range_u8 | hysteresis | LSB 17024 * ----------------- | ------------- | --------- 17025 * 2000 | 62.26dps | 1LSB 17026 * 1000 | 31.13dps | 1LSB 17027 * 500 | 15.56dps | 1LSB 17028 */ 17029 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_z_hyst( 17030 u8 *gyro_highrate_z_hyst_u8) 17031 { 17032 /* Variable used to return value of 17033 communication routine*/ 17034 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17035 u8 data_u8r = BNO055_INIT_VALUE; 17036 s8 stat_s8 = BNO055_ERROR; 17037 /* Check the struct p_bno055 is empty */ 17038 if (p_bno055 == BNO055_INIT_VALUE) { 17039 return BNO055_E_NULL_PTR; 17040 } else { 17041 /*condition check for page, gyro highrate z hysteresis is 17042 available in the page one*/ 17043 if (p_bno055->page_id != BNO055_PAGE_ONE) 17044 /* Write page as one */ 17045 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17046 if ((stat_s8 == BNO055_SUCCESS) || 17047 (p_bno055->page_id == BNO055_PAGE_ONE)) { 17048 /* Read the value of gyro highrate z hysteresis*/ 17049 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17050 (p_bno055->dev_addr, 17051 BNO055_GYRO_HIGHRATE_Z_HYST_REG, 17052 &data_u8r, 17053 BNO055_GEN_READ_WRITE_LENGTH); 17054 *gyro_highrate_z_hyst_u8 = 17055 BNO055_GET_BITSLICE(data_u8r, 17056 BNO055_GYRO_HIGHRATE_Z_HYST); 17057 } else { 17058 com_rslt = BNO055_ERROR; 17059 } 17060 } 17061 return com_rslt; 17062 } 17063 /*! 17064 * @brief This API used to write gyro highrate z hysteresis 17065 * from page one register from 0x1C bit 5 to 6 17066 * 17067 * @param gyro_highrate_z_hyst_u8 : The value of gyro highrate z hysteresis 17068 * 17069 * @return results of bus communication function 17070 * @retval 0 -> BNO055_SUCCESS 17071 * @retval 1 -> BNO055_ERROR 17072 * 17073 * @note Gyro high rate hysteresis calculated by 17074 * 17075 * using this (255 + 256 * gyro_highrate_z_hyst_u8) *4 LSB 17076 * 17077 * The high rate value scales with the range setting 17078 * 17079 * gyro_range_u8 | hysteresis | LSB 17080 * ----------------- | ------------- | --------- 17081 * 2000 | 62.26dps | 1LSB 17082 * 1000 | 31.13dps | 1LSB 17083 * 500 | 15.56dps | 1LSB 17084 */ 17085 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_z_hyst( 17086 u8 gyro_highrate_z_hyst_u8) 17087 { 17088 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17089 u8 data_u8r = BNO055_INIT_VALUE; 17090 s8 stat_s8 = BNO055_ERROR; 17091 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 17092 s8 pg_stat_s8 = BNO055_ERROR; 17093 /* Check the struct p_bno055 is empty */ 17094 if (p_bno055 == BNO055_INIT_VALUE) { 17095 return BNO055_E_NULL_PTR; 17096 } else { 17097 /* The write operation effective only if the operation 17098 mode is in config mode, this part of code is checking the 17099 current operation mode and set the config mode */ 17100 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 17101 if (stat_s8 == BNO055_SUCCESS) { 17102 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17103 stat_s8 += bno055_set_operation_mode 17104 (BNO055_OPERATION_MODE_CONFIG); 17105 if (stat_s8 == BNO055_SUCCESS) { 17106 /* Write page as one */ 17107 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17108 if (pg_stat_s8 == BNO055_SUCCESS) { 17109 /* Write the value 17110 of gyro highrate z hysteresis*/ 17111 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17112 (p_bno055->dev_addr, 17113 BNO055_GYRO_HIGHRATE_Z_HYST_REG, 17114 &data_u8r, 17115 BNO055_GEN_READ_WRITE_LENGTH); 17116 if (com_rslt == BNO055_SUCCESS) { 17117 data_u8r = 17118 BNO055_SET_BITSLICE(data_u8r, 17119 BNO055_GYRO_HIGHRATE_Z_HYST, 17120 gyro_highrate_z_hyst_u8); 17121 com_rslt += 17122 p_bno055->BNO055_BUS_WRITE_FUNC 17123 (p_bno055->dev_addr, 17124 BNO055_GYRO_HIGHRATE_Z_HYST_REG, 17125 &data_u8r, 17126 BNO055_GEN_READ_WRITE_LENGTH); 17127 } 17128 } else { 17129 com_rslt = BNO055_ERROR; 17130 } 17131 } else { 17132 com_rslt = BNO055_ERROR; 17133 } 17134 } else { 17135 com_rslt = BNO055_ERROR; 17136 } 17137 } 17138 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17139 /* set the operation mode of 17140 previous operation mode*/ 17141 com_rslt += bno055_set_operation_mode 17142 (prev_opmode_u8); 17143 return com_rslt; 17144 } 17145 /*! 17146 * @brief This API used to read gyro highrate z duration 17147 * from page one register from 0x1D bit 0 to 7 17148 * 17149 * @param gyro_highrate_z_durn_u8 : The value of gyro highrate z duration 17150 * 17151 * @return results of bus communication function 17152 * @retval 0 -> BNO055_SUCCESS 17153 * @retval 1 -> BNO055_ERROR 17154 * 17155 * @note Gyro highrate duration calculate by using the formula 17156 * 17157 * (1 + gyro_highrate_z_durn_u8)*2.5ms 17158 */ 17159 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_highrate_z_durn( 17160 u8 *gyro_highrate_z_durn_u8) 17161 { 17162 /* Variable used to return value of 17163 communication routine*/ 17164 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17165 u8 data_u8r = BNO055_INIT_VALUE; 17166 s8 stat_s8 = BNO055_ERROR; 17167 /* Check the struct p_bno055 is empty */ 17168 if (p_bno055 == BNO055_INIT_VALUE) { 17169 return BNO055_E_NULL_PTR; 17170 } else { 17171 /*condition check for page, gyro highrate z duration is 17172 available in the page one*/ 17173 if (p_bno055->page_id != BNO055_PAGE_ONE) 17174 /* Write page as one */ 17175 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17176 if ((stat_s8 == BNO055_SUCCESS) || 17177 (p_bno055->page_id == BNO055_PAGE_ONE)) { 17178 /* Read the value of gyro highrate z duration*/ 17179 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17180 (p_bno055->dev_addr, 17181 BNO055_GYRO_HIGHRATE_Z_DURN_REG, 17182 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 17183 *gyro_highrate_z_durn_u8 = 17184 BNO055_GET_BITSLICE(data_u8r, 17185 BNO055_GYRO_HIGHRATE_Z_DURN); 17186 } else { 17187 com_rslt = BNO055_ERROR; 17188 } 17189 } 17190 return com_rslt; 17191 } 17192 /*! 17193 * @brief This API used to write gyro highrate z duration 17194 * from page one register from 0x1D bit 0 to 7 17195 * 17196 * @param gyro_highrate_z_durn_u8 : The value of gyro highrate z duration 17197 * 17198 * @return results of bus communication function 17199 * @retval 0 -> BNO055_SUCCESS 17200 * @retval 1 -> BNO055_ERROR 17201 * 17202 * @note Gyro highrate duration calculate by using the formula 17203 * 17204 * (1 + gyro_highrate_z_durn_u8)*2.5ms 17205 */ 17206 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_highrate_z_durn( 17207 u8 gyro_highrate_z_durn_u8) 17208 { 17209 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17210 u8 data_u8r = BNO055_INIT_VALUE; 17211 s8 stat_s8 = BNO055_ERROR; 17212 s8 pg_stat_s8 = BNO055_ERROR; 17213 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 17214 /* Check the struct p_bno055 is empty */ 17215 if (p_bno055 == BNO055_INIT_VALUE) { 17216 return BNO055_E_NULL_PTR; 17217 } else { 17218 /* The write operation effective only if the operation 17219 mode is in config mode, this part of code is checking the 17220 current operation mode and set the config mode */ 17221 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 17222 if (stat_s8 == BNO055_SUCCESS) { 17223 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17224 stat_s8 += bno055_set_operation_mode 17225 (BNO055_OPERATION_MODE_CONFIG); 17226 if (stat_s8 == BNO055_SUCCESS) { 17227 /* Write page as one */ 17228 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17229 if (pg_stat_s8 == BNO055_SUCCESS) { 17230 /* Write the value of 17231 gyro highrate z duration*/ 17232 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17233 (p_bno055->dev_addr, 17234 BNO055_GYRO_HIGHRATE_Z_DURN_REG, 17235 &data_u8r, 17236 BNO055_GEN_READ_WRITE_LENGTH); 17237 if (com_rslt == BNO055_SUCCESS) { 17238 data_u8r = 17239 BNO055_SET_BITSLICE(data_u8r, 17240 BNO055_GYRO_HIGHRATE_Z_DURN, 17241 gyro_highrate_z_durn_u8); 17242 com_rslt += 17243 p_bno055->BNO055_BUS_WRITE_FUNC 17244 (p_bno055->dev_addr, 17245 BNO055_GYRO_HIGHRATE_Z_DURN_REG, 17246 &data_u8r, 17247 BNO055_GEN_READ_WRITE_LENGTH); 17248 } 17249 } else { 17250 com_rslt = BNO055_ERROR; 17251 } 17252 } else { 17253 com_rslt = BNO055_ERROR; 17254 } 17255 } else { 17256 com_rslt = BNO055_ERROR; 17257 } 17258 } 17259 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17260 /* set the operation mode of 17261 previous operation mode*/ 17262 com_rslt += bno055_set_operation_mode 17263 (prev_opmode_u8); 17264 return com_rslt; 17265 } 17266 /*! 17267 * @brief This API used to read gyro anymotion threshold 17268 * from page one register from 0x1E bit 0 to 6 17269 * 17270 * @param gyro_any_motion_thres_u8 : The value of gyro anymotion threshold 17271 * 17272 * @return results of bus communication function 17273 * @retval 0 -> BNO055_SUCCESS 17274 * @retval 1 -> BNO055_ERROR 17275 * 17276 * @note Gyro anymotion interrupt threshold dependent 17277 * on the selection of gyro range 17278 * 17279 * gyro_range_u8 | threshold | LSB 17280 * ----------------- | ------------- | --------- 17281 * 2000 | 1dps | 1LSB 17282 * 1000 | 0.5dps | 1LSB 17283 * 500 | 0.25dps | 1LSB 17284 * 17285 */ 17286 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_any_motion_thres( 17287 u8 *gyro_any_motion_thres_u8) 17288 { 17289 /* Variable used to return value of 17290 communication routine*/ 17291 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17292 u8 data_u8r = BNO055_INIT_VALUE; 17293 s8 stat_s8 = BNO055_ERROR; 17294 /* Check the struct p_bno055 is empty */ 17295 if (p_bno055 == BNO055_INIT_VALUE) { 17296 return BNO055_E_NULL_PTR; 17297 } else { 17298 /*condition check for page,gyro anymotion threshold is 17299 available in the page one*/ 17300 if (p_bno055->page_id != BNO055_PAGE_ONE) 17301 /* Write page as one */ 17302 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17303 if ((stat_s8 == BNO055_SUCCESS) || 17304 (p_bno055->page_id == BNO055_PAGE_ONE)) { 17305 /* Read the value of gyro anymotion threshold*/ 17306 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17307 (p_bno055->dev_addr, 17308 BNO055_GYRO_ANY_MOTION_THRES_REG, 17309 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 17310 *gyro_any_motion_thres_u8 = 17311 BNO055_GET_BITSLICE(data_u8r, 17312 BNO055_GYRO_ANY_MOTION_THRES); 17313 } else { 17314 com_rslt = BNO055_ERROR; 17315 } 17316 } 17317 return com_rslt; 17318 } 17319 /*! 17320 * @brief This API used to write gyro anymotion threshold 17321 * from page one register from 0x1E bit 0 to 6 17322 * 17323 * @param gyro_any_motion_thres_u8 : The value of gyro anymotion threshold 17324 * 17325 * @return results of bus communication function 17326 * @retval 0 -> BNO055_SUCCESS 17327 * @retval 1 -> BNO055_ERROR 17328 * 17329 * @note Gyro anymotion interrupt threshold dependent 17330 * on the selection of gyro range 17331 * 17332 * gyro_range_u8 | threshold | LSB 17333 * ----------------- | ------------- | --------- 17334 * 2000 | 1dps | 1LSB 17335 * 1000 | 0.5dps | 1LSB 17336 * 500 | 0.25dps | 1LSB 17337 * 17338 */ 17339 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_any_motion_thres( 17340 u8 gyro_any_motion_thres_u8) 17341 { 17342 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17343 u8 data_u8r = BNO055_INIT_VALUE; 17344 s8 stat_s8 = BNO055_ERROR; 17345 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 17346 s8 pg_stat_s8 = BNO055_ERROR; 17347 /* Check the struct p_bno055 is empty */ 17348 if (p_bno055 == BNO055_INIT_VALUE) { 17349 return BNO055_E_NULL_PTR; 17350 } else { 17351 /* The write operation effective only if the operation 17352 mode is in config mode, this part of code is checking the 17353 current operation mode and set the config mode */ 17354 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 17355 if (stat_s8 == BNO055_SUCCESS) { 17356 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17357 stat_s8 += bno055_set_operation_mode 17358 (BNO055_OPERATION_MODE_CONFIG); 17359 if (stat_s8 == BNO055_SUCCESS) { 17360 /* Write page as one */ 17361 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17362 if (pg_stat_s8 == BNO055_SUCCESS) { 17363 /* Write the value 17364 of gyro anymotion threshold*/ 17365 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17366 (p_bno055->dev_addr, 17367 BNO055_GYRO_ANY_MOTION_THRES_REG, 17368 &data_u8r, 17369 BNO055_GEN_READ_WRITE_LENGTH); 17370 if (com_rslt == BNO055_SUCCESS) { 17371 data_u8r = 17372 BNO055_SET_BITSLICE(data_u8r, 17373 BNO055_GYRO_ANY_MOTION_THRES, 17374 gyro_any_motion_thres_u8); 17375 com_rslt += 17376 p_bno055->BNO055_BUS_WRITE_FUNC 17377 (p_bno055->dev_addr, 17378 BNO055_GYRO_ANY_MOTION_THRES_REG, 17379 &data_u8r, 17380 BNO055_GEN_READ_WRITE_LENGTH); 17381 } 17382 } else { 17383 com_rslt = BNO055_ERROR; 17384 } 17385 } else { 17386 com_rslt = BNO055_ERROR; 17387 } 17388 } else { 17389 com_rslt = BNO055_ERROR; 17390 } 17391 } 17392 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17393 /* set the operation mode of 17394 previous operation mode*/ 17395 com_rslt += bno055_set_operation_mode 17396 (prev_opmode_u8); 17397 return com_rslt; 17398 } 17399 /*! 17400 * @brief This API used to read gyro anymotion slope samples 17401 * from page one register from 0x1F bit 0 to 1 17402 * 17403 * @param gyro_any_motion_slope_samples_u8 : 17404 * The value of gyro anymotion slope samples 17405 * gyro_any_motion_slope_samples_u8 | result 17406 * ---------------------------------- | ----------- 17407 * 0 | 8 samples 17408 * 1 | 16 samples 17409 * 2 | 32 samples 17410 * 3 | 64 samples 17411 * 17412 * @return results of bus communication function 17413 * @retval 0 -> BNO055_SUCCESS 17414 * @retval 1 -> BNO055_ERROR 17415 * 17416 */ 17417 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_any_motion_slope_samples( 17418 u8 *gyro_any_motion_slope_samples_u8) 17419 { 17420 /* Variable used to return value of 17421 communication routine*/ 17422 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17423 u8 data_u8r = BNO055_INIT_VALUE; 17424 s8 stat_s8 = BNO055_ERROR; 17425 /* Check the struct p_bno055 is empty */ 17426 if (p_bno055 == BNO055_INIT_VALUE) { 17427 return BNO055_E_NULL_PTR; 17428 } else { 17429 /*condition check for page, gyro anymotion slope samples is 17430 available in the page one*/ 17431 if (p_bno055->page_id != BNO055_PAGE_ONE) 17432 /* Write page as one */ 17433 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17434 if ((stat_s8 == BNO055_SUCCESS) || 17435 (p_bno055->page_id == BNO055_PAGE_ONE)) { 17436 /*Read the value of gyro anymotion slope samples*/ 17437 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17438 (p_bno055->dev_addr, 17439 BNO055_GYRO_SLOPE_SAMPLES_REG, 17440 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 17441 *gyro_any_motion_slope_samples_u8 = 17442 BNO055_GET_BITSLICE(data_u8r, 17443 BNO055_GYRO_SLOPE_SAMPLES); 17444 } else { 17445 com_rslt = BNO055_ERROR; 17446 } 17447 } 17448 return com_rslt; 17449 } 17450 /*! 17451 * @brief This API used to write gyro anymotion slope samples 17452 * from page one register from 0x1F bit 0 to 1 17453 * 17454 * @param gyro_any_motion_slope_samples_u8 : 17455 * The value of gyro anymotion slope samples 17456 * gyro_any_motion_slope_samples_u8 | result 17457 * ---------------------------------- | ----------- 17458 * 0 | 8 samples 17459 * 1 | 16 samples 17460 * 2 | 32 samples 17461 * 3 | 64 samples 17462 * 17463 * @return results of bus communication function 17464 * @retval 0 -> BNO055_SUCCESS 17465 * @retval 1 -> BNO055_ERROR 17466 * 17467 */ 17468 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_any_motion_slope_samples( 17469 u8 gyro_any_motion_slope_samples_u8) 17470 { 17471 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17472 u8 data_u8r = BNO055_INIT_VALUE; 17473 s8 stat_s8 = BNO055_ERROR; 17474 s8 pg_stat_s8 = BNO055_ERROR; 17475 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 17476 /* Check the struct p_bno055 is empty */ 17477 if (p_bno055 == BNO055_INIT_VALUE) { 17478 return BNO055_E_NULL_PTR; 17479 } else { 17480 /* The write operation effective only if the operation 17481 mode is in config mode, this part of code is checking the 17482 current operation mode and set the config mode */ 17483 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 17484 if (stat_s8 == BNO055_SUCCESS) { 17485 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17486 stat_s8 += bno055_set_operation_mode 17487 (BNO055_OPERATION_MODE_CONFIG); 17488 if (stat_s8 == BNO055_SUCCESS) { 17489 /* Write page as one */ 17490 pg_stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17491 if (pg_stat_s8 == BNO055_SUCCESS) { 17492 /* Write the value of 17493 gyro anymotion slope samples*/ 17494 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17495 (p_bno055->dev_addr, 17496 BNO055_GYRO_SLOPE_SAMPLES_REG, 17497 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 17498 if (com_rslt == BNO055_SUCCESS) { 17499 data_u8r = 17500 BNO055_SET_BITSLICE(data_u8r, 17501 BNO055_GYRO_SLOPE_SAMPLES, 17502 gyro_any_motion_slope_samples_u8); 17503 com_rslt += 17504 p_bno055->BNO055_BUS_WRITE_FUNC 17505 (p_bno055->dev_addr, 17506 BNO055_GYRO_SLOPE_SAMPLES_REG, 17507 &data_u8r, 17508 BNO055_GEN_READ_WRITE_LENGTH); 17509 } 17510 } else { 17511 com_rslt = BNO055_ERROR; 17512 } 17513 } else { 17514 com_rslt = BNO055_ERROR; 17515 } 17516 } else { 17517 com_rslt = BNO055_ERROR; 17518 } 17519 } 17520 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17521 /* set the operation mode of 17522 previous operation mode*/ 17523 com_rslt += bno055_set_operation_mode 17524 (prev_opmode_u8); 17525 return com_rslt; 17526 } 17527 /*! 17528 * @brief This API used to read gyro anymotion awake duration 17529 * from page one register from 0x1F bit 2 to 3 17530 * 17531 * @param gyro_awake_durn_u8 : The value of gyro anymotion awake duration 17532 * 17533 * @return results of bus communication function 17534 * @retval 0 -> BNO055_SUCCESS 17535 * @retval 1 -> BNO055_ERROR 17536 * 17537 */ 17538 BNO055_RETURN_FUNCTION_TYPE bno055_get_gyro_any_motion_awake_durn( 17539 u8 *gyro_awake_durn_u8) 17540 { 17541 /* Variable used to return value of 17542 communication routine*/ 17543 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17544 u8 data_u8r = BNO055_INIT_VALUE; 17545 s8 stat_s8 = BNO055_ERROR; 17546 /* Check the struct p_bno055 is empty */ 17547 if (p_bno055 == BNO055_INIT_VALUE) { 17548 return BNO055_E_NULL_PTR; 17549 } else { 17550 /*condition check for page, gyro anymotion awake duration is 17551 available in the page one*/ 17552 if (p_bno055->page_id != BNO055_PAGE_ONE) 17553 /* Write page as one */ 17554 stat_s8 = bno055_write_page_id(BNO055_PAGE_ONE); 17555 if ((stat_s8 == BNO055_SUCCESS) || 17556 (p_bno055->page_id == BNO055_PAGE_ONE)) { 17557 /* Read the value of gyro anymotion awake duration*/ 17558 com_rslt = p_bno055->BNO055_BUS_READ_FUNC 17559 (p_bno055->dev_addr, 17560 BNO055_GYRO_AWAKE_DURN_REG, 17561 &data_u8r, BNO055_GEN_READ_WRITE_LENGTH); 17562 *gyro_awake_durn_u8 = BNO055_GET_BITSLICE(data_u8r, 17563 BNO055_GYRO_AWAKE_DURN); 17564 } else { 17565 com_rslt = BNO055_ERROR; 17566 } 17567 } 17568 return com_rslt; 17569 } 17570 /*! 17571 * @brief This API used to write gyro anymotion awake duration 17572 * from page one register from 0x1F bit 2 to 3 17573 * 17574 * @param gyro_awake_durn_u8 : The value of gyro anymotion awake duration 17575 * 17576 * @return results of bus communication function 17577 * @retval 0 -> BNO055_SUCCESS 17578 * @retval 1 -> BNO055_ERROR 17579 * 17580 */ 17581 BNO055_RETURN_FUNCTION_TYPE bno055_set_gyro_any_motion_awake_durn( 17582 u8 gyro_awake_durn_u8) 17583 { 17584 BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR; 17585 u8 data_u8r = BNO055_INIT_VALUE; 17586 s8 stat_s8 = BNO055_ERROR; 17587 s8 pg_stat_s8 = BNO055_ERROR; 17588 u8 prev_opmode_u8 = BNO055_OPERATION_MODE_CONFIG; 17589 /* Check the struct p_bno055 is empty */ 17590 if (p_bno055 == BNO055_INIT_VALUE) { 17591 return BNO055_E_NULL_PTR; 17592 } else { 17593 /* The write operation effective only if the operation 17594 mode is in config mode, this part of code is checking the 17595 current operation mode and set the config mode */ 17596 stat_s8 = bno055_get_operation_mode(&prev_opmode_u8); 17597 if (stat_s8 == BNO055_SUCCESS) { 17598 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17599 stat_s8 += bno055_set_operation_mode 17600 (BNO055_OPERATION_MODE_CONFIG); 17601 if (stat_s8 == BNO055_SUCCESS) { 17602 /* Write page as one */ 17603 pg_stat_s8 = bno055_write_page_id( 17604 BNO055_PAGE_ONE); 17605 if (pg_stat_s8 == BNO055_SUCCESS) { 17606 /* Write the value of gyro 17607 anymotion awake duration*/ 17608 com_rslt = 17609 p_bno055->BNO055_BUS_READ_FUNC 17610 (p_bno055->dev_addr, 17611 BNO055_GYRO_AWAKE_DURN_REG, 17612 &data_u8r, 17613 BNO055_GEN_READ_WRITE_LENGTH); 17614 if (com_rslt == BNO055_SUCCESS) { 17615 data_u8r = 17616 BNO055_SET_BITSLICE(data_u8r, 17617 BNO055_GYRO_AWAKE_DURN, 17618 gyro_awake_durn_u8); 17619 com_rslt += 17620 p_bno055->BNO055_BUS_WRITE_FUNC 17621 (p_bno055->dev_addr, 17622 BNO055_GYRO_AWAKE_DURN_REG, 17623 &data_u8r, 17624 BNO055_GEN_READ_WRITE_LENGTH); 17625 } 17626 } else { 17627 com_rslt = BNO055_ERROR; 17628 } 17629 } else { 17630 com_rslt = BNO055_ERROR; 17631 } 17632 } else { 17633 com_rslt = BNO055_ERROR; 17634 } 17635 } 17636 if (prev_opmode_u8 != BNO055_OPERATION_MODE_CONFIG) 17637 /* set the operation mode 17638 of previous operation mode*/ 17639 com_rslt += bno055_set_operation_mode 17640 (prev_opmode_u8); 17641 return com_rslt; 17642 }
Generated on Fri Jul 15 2022 23:17:15 by
1.7.2