An improved version of mbed's I2C class.

Dependents:   acd52832_Humidity_Temp_Example BB acnSensa_LIS aconnoCellularGnss ... more

Revision:
6:4d1b387c12c3
Parent:
5:54ba0e4f13ae
Child:
7:b2f0c302ba6d
--- a/aconno_i2c.cpp	Thu Jul 19 12:48:11 2018 +0200
+++ b/aconno_i2c.cpp	Thu Jul 19 15:07:28 2018 +0200
@@ -19,6 +19,21 @@
     i2cAddress = address;
 }
 
+uint16_t aconno_i2c::changeRegBits(char regAddress, uint8_t regSize,
+	uint16_t newValue, uint16_t numOfBits, uint16_t offset)
+{
+	uint16_t mask;
+    uint16_t regData = 0;
+	// Read old configuration
+	readFromReg(regAddress, (char*)&regData, regSize);
+	mask = 0 | newValue << offset;
+	// Clear bits
+	regData &= ~(((1 << numOfBits)-1) << offset);
+	regData |= mask; // Set/clear bits as required
+    writeToReg(regAddress, (char*)&regData, regSize);
+    return regData;
+}
+
 /**
  * [aconno_i2c::writeToReg description]
  * @param  regAddress [description]