Library for Bosch Sensortec BMI160 IMU

Dependents:   Rocket MAX32630FTHR_JOYSTICK MAX32630FTHR_IMU_Hello_World Pike_the_Flipper_Main_Branch ... more

Fork of BMI160 by Justin Jordan

Committer:
j3
Date:
Thu Dec 15 00:38:04 2016 +0000
Revision:
6:9615aa90087d
Parent:
5:35e032c8d8aa
Child:
7:9848196cb65e
Fixed Temperature fx

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 3:e1770675eca4 1 /**********************************************************************
j3 3:e1770675eca4 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 3:e1770675eca4 3 *
j3 3:e1770675eca4 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 3:e1770675eca4 5 * copy of this software and associated documentation files (the "Software"),
j3 3:e1770675eca4 6 * to deal in the Software without restriction, including without limitation
j3 3:e1770675eca4 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 3:e1770675eca4 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 3:e1770675eca4 9 * Software is furnished to do so, subject to the following conditions:
j3 3:e1770675eca4 10 *
j3 3:e1770675eca4 11 * The above copyright notice and this permission notice shall be included
j3 3:e1770675eca4 12 * in all copies or substantial portions of the Software.
j3 3:e1770675eca4 13 *
j3 3:e1770675eca4 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 3:e1770675eca4 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 3:e1770675eca4 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 3:e1770675eca4 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 3:e1770675eca4 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 3:e1770675eca4 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 3:e1770675eca4 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 3:e1770675eca4 21 *
j3 3:e1770675eca4 22 * Except as contained in this notice, the name of Maxim Integrated
j3 3:e1770675eca4 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 3:e1770675eca4 24 * Products, Inc. Branding Policy.
j3 3:e1770675eca4 25 *
j3 3:e1770675eca4 26 * The mere transfer of this software does not imply any licenses
j3 3:e1770675eca4 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 3:e1770675eca4 28 * trademarks, maskwork rights, or any other form of intellectual
j3 3:e1770675eca4 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 3:e1770675eca4 30 * ownership rights.
j3 3:e1770675eca4 31 **********************************************************************/
j3 3:e1770675eca4 32
j3 3:e1770675eca4 33
j3 3:e1770675eca4 34 #include "bmi160.h"
j3 3:e1770675eca4 35
j3 3:e1770675eca4 36
j3 3:e1770675eca4 37 //*****************************************************************************
j3 5:35e032c8d8aa 38 int32_t BMI160::setSensorPowerMode(Sensors sensor, PowerModes pwrMode)
j3 3:e1770675eca4 39 {
j3 3:e1770675eca4 40 int32_t rtnVal = -1;
j3 3:e1770675eca4 41
j3 5:35e032c8d8aa 42 switch(sensor)
j3 5:35e032c8d8aa 43 {
j3 5:35e032c8d8aa 44 case MAG:
j3 5:35e032c8d8aa 45 rtnVal = writeRegister(CMD, (MAG_SET_PMU_MODE | pwrMode));
j3 5:35e032c8d8aa 46 break;
j3 5:35e032c8d8aa 47
j3 5:35e032c8d8aa 48 case GYRO:
j3 5:35e032c8d8aa 49 rtnVal = writeRegister(CMD, (GYR_SET_PMU_MODE | pwrMode));
j3 5:35e032c8d8aa 50 break;
j3 5:35e032c8d8aa 51
j3 5:35e032c8d8aa 52 case ACC:
j3 5:35e032c8d8aa 53 rtnVal = writeRegister(CMD, (ACC_SET_PMU_MODE | pwrMode));
j3 5:35e032c8d8aa 54 break;
j3 5:35e032c8d8aa 55
j3 5:35e032c8d8aa 56 default:
j3 5:35e032c8d8aa 57 rtnVal = -1;
j3 5:35e032c8d8aa 58 break;
j3 5:35e032c8d8aa 59 }
j3 5:35e032c8d8aa 60
j3 3:e1770675eca4 61 return rtnVal;
j3 3:e1770675eca4 62 }
j3 5:35e032c8d8aa 63
j3 5:35e032c8d8aa 64
j3 5:35e032c8d8aa 65 //*****************************************************************************
j3 5:35e032c8d8aa 66 int32_t BMI160::getTemperature(float *temp)
j3 5:35e032c8d8aa 67 {
j3 5:35e032c8d8aa 68 uint8_t data[2];
j3 6:9615aa90087d 69 uint16_t rawTemp;
j3 5:35e032c8d8aa 70
j3 5:35e032c8d8aa 71 int32_t rtnVal = readBlock(TEMPERATURE_0, TEMPERATURE_1, data);
j3 5:35e032c8d8aa 72 if(rtnVal == RTN_NO_ERROR)
j3 5:35e032c8d8aa 73 {
j3 6:9615aa90087d 74 rawTemp = ((data[1] << 8) | data[0]);
j3 6:9615aa90087d 75 if(rawTemp & 0x8000)
j3 6:9615aa90087d 76 {
j3 6:9615aa90087d 77 *temp = (23.0F - (((0xFFFF - rawTemp) + 1)/512.0F));
j3 6:9615aa90087d 78 }
j3 6:9615aa90087d 79 else
j3 6:9615aa90087d 80 {
j3 6:9615aa90087d 81 *temp = ((rawTemp/512.0F) + 23.0F);
j3 6:9615aa90087d 82 }
j3 5:35e032c8d8aa 83 }
j3 5:35e032c8d8aa 84
j3 5:35e032c8d8aa 85 return rtnVal;
j3 5:35e032c8d8aa 86 }