First Commit as a new library

Dependents:   Host_Software_MAX32664GWEB_HR_wrist Host_Software_MAX32664GWEC_SpO2_HR Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more

Committer:
j3
Date:
Tue Dec 20 01:08:33 2016 +0000
Revision:
9:ca6b5fecdd63
Parent:
3:e1770675eca4
Child:
19:8e66f58bef44
Added range support for accelerometer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 2:598e601e5846 1 /**********************************************************************
j3 2:598e601e5846 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 2:598e601e5846 3 *
j3 2:598e601e5846 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 2:598e601e5846 5 * copy of this software and associated documentation files (the "Software"),
j3 2:598e601e5846 6 * to deal in the Software without restriction, including without limitation
j3 2:598e601e5846 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 2:598e601e5846 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 2:598e601e5846 9 * Software is furnished to do so, subject to the following conditions:
j3 2:598e601e5846 10 *
j3 2:598e601e5846 11 * The above copyright notice and this permission notice shall be included
j3 2:598e601e5846 12 * in all copies or substantial portions of the Software.
j3 2:598e601e5846 13 *
j3 2:598e601e5846 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 2:598e601e5846 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 2:598e601e5846 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 2:598e601e5846 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 2:598e601e5846 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 2:598e601e5846 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 2:598e601e5846 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 2:598e601e5846 21 *
j3 2:598e601e5846 22 * Except as contained in this notice, the name of Maxim Integrated
j3 2:598e601e5846 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 2:598e601e5846 24 * Products, Inc. Branding Policy.
j3 2:598e601e5846 25 *
j3 2:598e601e5846 26 * The mere transfer of this software does not imply any licenses
j3 2:598e601e5846 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 2:598e601e5846 28 * trademarks, maskwork rights, or any other form of intellectual
j3 2:598e601e5846 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 2:598e601e5846 30 * ownership rights.
j3 2:598e601e5846 31 **********************************************************************/
j3 2:598e601e5846 32
j3 2:598e601e5846 33
j3 2:598e601e5846 34 #include "bmi160.h"
j3 2:598e601e5846 35
j3 2:598e601e5846 36
j3 2:598e601e5846 37 //*****************************************************************************
j3 2:598e601e5846 38 BMI160_I2C::BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs)
j3 2:598e601e5846 39 :m_i2cBus(i2cBus), m_Wadrs(i2cAdrs << 1), m_Radrs((i2cAdrs << 1) | 1)
j3 2:598e601e5846 40 {
j3 9:ca6b5fecdd63 41
j3 2:598e601e5846 42 }
j3 2:598e601e5846 43
j3 2:598e601e5846 44
j3 2:598e601e5846 45 //*****************************************************************************
j3 2:598e601e5846 46 int32_t BMI160_I2C::readRegister(Registers reg, uint8_t *data)
j3 2:598e601e5846 47 {
j3 2:598e601e5846 48 int32_t rtnVal = -1;
j3 2:598e601e5846 49 char packet[] = {static_cast<char>(reg)};
j3 2:598e601e5846 50
j3 2:598e601e5846 51 if(m_i2cBus.write(m_Wadrs, packet, 1) == 0)
j3 2:598e601e5846 52 {
j3 2:598e601e5846 53 rtnVal = m_i2cBus.read(m_Radrs, reinterpret_cast<char *>(data), 1);
j3 2:598e601e5846 54 }
j3 2:598e601e5846 55
j3 2:598e601e5846 56 return rtnVal;
j3 2:598e601e5846 57 }
j3 2:598e601e5846 58
j3 2:598e601e5846 59
j3 2:598e601e5846 60 //*****************************************************************************
j3 2:598e601e5846 61 int32_t BMI160_I2C::writeRegister(Registers reg, const uint8_t data)
j3 2:598e601e5846 62 {
j3 2:598e601e5846 63 char packet[] = {static_cast<char>(reg), static_cast<char>(data)};
j3 2:598e601e5846 64
j3 2:598e601e5846 65 return m_i2cBus.write(m_Wadrs, packet, sizeof(packet));
j3 2:598e601e5846 66 }
j3 2:598e601e5846 67
j3 2:598e601e5846 68
j3 2:598e601e5846 69 //*****************************************************************************
j3 3:e1770675eca4 70 int32_t BMI160_I2C::readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 71 uint8_t *data)
j3 2:598e601e5846 72 {
j3 2:598e601e5846 73 int32_t rtnVal = -1;
j3 2:598e601e5846 74 int32_t numBytes = ((stopReg - startReg) + 1);
j3 2:598e601e5846 75 char packet[] = {static_cast<char>(startReg)};
j3 2:598e601e5846 76
j3 2:598e601e5846 77 if(m_i2cBus.write(m_Wadrs, packet, 1) == 0)
j3 2:598e601e5846 78 {
j3 2:598e601e5846 79 rtnVal = m_i2cBus.read(m_Radrs, reinterpret_cast<char *>(data), numBytes);
j3 2:598e601e5846 80 }
j3 2:598e601e5846 81
j3 2:598e601e5846 82 return rtnVal;
j3 2:598e601e5846 83 }
j3 2:598e601e5846 84
j3 2:598e601e5846 85
j3 2:598e601e5846 86 //*****************************************************************************
j3 3:e1770675eca4 87 int32_t BMI160_I2C::writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 88 const uint8_t *data)
j3 2:598e601e5846 89 {
j3 2:598e601e5846 90 int32_t numBytes = ((stopReg - startReg) + 1);
j3 2:598e601e5846 91 char packet[numBytes + 1];
j3 2:598e601e5846 92
j3 2:598e601e5846 93 packet[0] = static_cast<char>(startReg);
j3 2:598e601e5846 94
j3 2:598e601e5846 95 memcpy(packet + 1, data, numBytes);
j3 2:598e601e5846 96
j3 2:598e601e5846 97 return m_i2cBus.write(m_Wadrs, packet, sizeof(packet));
j3 2:598e601e5846 98 }