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
Diff: bmi160_i2c.cpp
- Revision:
- 21:f7216b5dc6c0
- Parent:
- 19:8e66f58bef44
diff -r a521606048bb -r f7216b5dc6c0 bmi160_i2c.cpp --- a/bmi160_i2c.cpp Fri May 04 13:35:59 2018 +0300 +++ b/bmi160_i2c.cpp Wed Dec 19 14:54:05 2018 +0300 @@ -35,24 +35,29 @@ //***************************************************************************** -BMI160_I2C::BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs) +BMI160_I2C::BMI160_I2C(I2C *i2cBus, uint8_t i2cAdrs) :m_i2cBus(i2cBus), m_Wadrs(i2cAdrs << 1), m_Radrs((i2cAdrs << 1) | 1) { - + } +BMI160_I2C::BMI160_I2C(I2C *i2cBus, uint8_t i2cAdrs, InterruptIn *int_pin) +:m_i2cBus(i2cBus), m_Wadrs(i2cAdrs << 1), m_Radrs((i2cAdrs << 1) | 1), BMI160(int_pin) +{ -//***************************************************************************** +} + +//***************************************************************************** int32_t BMI160_I2C::readRegister(Registers reg, uint8_t *data) { int32_t rtnVal = -1; char packet[] = {static_cast<char>(reg)}; - - if(m_i2cBus.write(m_Wadrs, packet, 1) == 0) + + if(m_i2cBus->write(m_Wadrs, packet, 1) == 0) { - rtnVal = m_i2cBus.read(m_Radrs, reinterpret_cast<char *>(data), 1); + rtnVal = m_i2cBus->read(m_Radrs, reinterpret_cast<char *>(data), 1); } - + return rtnVal; } @@ -61,38 +66,38 @@ int32_t BMI160_I2C::writeRegister(Registers reg, const uint8_t data) { char packet[] = {static_cast<char>(reg), static_cast<char>(data)}; - - return m_i2cBus.write(m_Wadrs, packet, sizeof(packet)); + + return m_i2cBus->write(m_Wadrs, packet, sizeof(packet)); } //***************************************************************************** -int32_t BMI160_I2C::readBlock(Registers startReg, Registers stopReg, +int32_t BMI160_I2C::readBlock(Registers startReg, Registers stopReg, uint8_t *data) { int32_t rtnVal = -1; int32_t numBytes = ((stopReg - startReg) + 1); char packet[] = {static_cast<char>(startReg)}; - - if(m_i2cBus.write(m_Wadrs, packet, 1) == 0) + + if(m_i2cBus->write(m_Wadrs, packet, 1) == 0) { - rtnVal = m_i2cBus.read(m_Radrs, reinterpret_cast<char *>(data), numBytes); + rtnVal = m_i2cBus->read(m_Radrs, reinterpret_cast<char *>(data), numBytes); } - + return rtnVal; } //***************************************************************************** -int32_t BMI160_I2C::writeBlock(Registers startReg, Registers stopReg, +int32_t BMI160_I2C::writeBlock(Registers startReg, Registers stopReg, const uint8_t *data) { int32_t numBytes = ((stopReg - startReg) + 1); - char packet[32]; - + char packet[numBytes + 1]; + packet[0] = static_cast<char>(startReg); - + memcpy(packet + 1, data, numBytes); - - return m_i2cBus.write(m_Wadrs, packet, (numBytes+1) * sizeof(char)); + + return m_i2cBus->write(m_Wadrs, packet, sizeof(packet)); }