lsm6ds3 library working on mbed-os 5
Diff: LSM6DS3.cpp
- Revision:
- 2:ed14e6196255
- Parent:
- 1:924c7dea286e
- Child:
- 3:69c5c66c3f2f
--- a/LSM6DS3.cpp Mon Jun 20 19:15:31 2016 +0000 +++ b/LSM6DS3.cpp Tue Jun 21 20:51:25 2016 +0000 @@ -44,6 +44,9 @@ setAccelODR(aODR); // Set the accel data rate. setAccelScale(aScale); // Set the accel range. + // Interrupt initialization stuff; + initIntr(); + // Once everything is initialized, return the WHO_AM_I registers we read: return xgTest; } @@ -74,6 +77,27 @@ i2c.write(xgAddress, cmd, 4); } +void LSM6DS3::initIntr() +{ + char cmd[2]; + + cmd[0] = TAP_CFG; + cmd[1] = 0x0E; + i2c.write(xgAddress, cmd, 2); + cmd[0] = TAP_THS_6D; + cmd[1] = 0x03; + i2c.write(xgAddress, cmd, 2); + cmd[0] = INT_DUR2; + cmd[1] = 0x7F; + i2c.write(xgAddress, cmd, 2); + cmd[0] = WAKE_UP_THS; + cmd[1] = 0x80; + i2c.write(xgAddress, cmd, 2); + cmd[0] = MD1_CFG; + cmd[1] = 0x48; + i2c.write(xgAddress, cmd, 2); +} + void LSM6DS3::readAccel() { // The data we are going to read from the accel @@ -112,6 +136,17 @@ az = az_raw * aRes; } +void LSM6DS3::readIntr() +{ + char data[1]; + char subAddress = TAP_SRC; + + i2c.write(xgAddress, &subAddress, 1, true); + i2c.read(xgAddress, data, 1); + + intr = (float)data[0]; +} + void LSM6DS3::readTemp() { // The data we are going to read from the temp