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,19 +9,20 @@
#define LIS2DH12_DEFINES_HPP_
#define LIS2DH_I2C_ADDRESS (25 << 1)
#define LIS_CTRL_REG1 0x20 | 0x80
#define LIS_CTRL_REG2 0x21 | 0x80
#define LIS_CTRL_REG3 0x22 | 0x80
#define LIS_CTRL_REG4 0x23 | 0x80
#define LIS_CTRL_REG5 0x24 | 0x80
#define LIS_CTRL_REG6 0x25 | 0x80
#define LIS_INT1_CFG 0xB0 | 0x80
#define LIS_INT2_CFG 0xB4 | 0x80
#define LIS_INT1_DURATION 0x33 | 0x80
#define LIS_INT1_THS 0x32 | 0x80
#define LIS_INT1_SRC 0x31 | 0x80
#define LIS_INT2_DURATION 0x37 | 0x80
#define LIS_INT2_THS 0x36 | 0x80
#define LIS_INT2_SRC 0x35 | 0x80
#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
#define LIS_CTRL_REG4 0x23 | 0x80
#define LIS_CTRL_REG5 0x24 | 0x80
#define LIS_CTRL_REG6 0x25 | 0x80
#define LIS_INT1_CFG 0xB0 | 0x80
#define LIS_INT2_CFG 0xB4 | 0x80
#define LIS_INT1_DURATION 0x33 | 0x80
#define LIS_INT1_THS 0x32 | 0x80
#define LIS_INT1_SRC 0x31 | 0x80
#define LIS_INT2_DURATION 0x37 | 0x80
#define LIS_INT2_THS 0x36 | 0x80
#define LIS_INT2_SRC 0x35 | 0x80
#endif /* LIS2DH12_DEFINES_HPP_ */