1
0
forked from me/IronOS

Step 1: make LIS2DH12 driver stricter

This commit is contained in:
Ben V. Brown
2022-02-12 11:04:28 +11:00
parent 3869003cf4
commit ba119007ff
2 changed files with 27 additions and 16 deletions

View File

@@ -36,4 +36,14 @@ void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
z = sensorData[2];
}
bool LIS2DH12::detect() { return FRToSI2C::probe(LIS2DH_I2C_ADDRESS); }
bool LIS2DH12::detect() {
if (!FRToSI2C::probe(LIS2DH_I2C_ADDRESS)) {
return false;
}
// Read chip id to ensure its not an address collision
uint8_t id = 0;
if (FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, LIS2DH_WHOAMI_REG, &id, 1)) {
return id == LIS2DH_WHOAMI_ID;
}
return false; // cant read ID
}

View File

@@ -9,7 +9,8 @@
#define LIS2DH12_DEFINES_HPP_
#define LIS2DH_I2C_ADDRESS (25 << 1)
#define LIS2DH_WHOAMI_REG 0x0F
#define LIS2DH_WHOAMI_ID (0b00110011)
#define LIS_CTRL_REG1 0x20 | 0x80
#define LIS_CTRL_REG2 0x21 | 0x80
#define LIS_CTRL_REG3 0x22 | 0x80