support lps22 (#3900)

* support lps22

* s

* changelog, UI
This commit is contained in:
Matthew Kennedy 2022-02-07 14:09:51 -08:00 committed by GitHub
parent 460ef3eb4a
commit 70ac0c378b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 13 deletions

View File

@ -26,7 +26,8 @@ Release template (copy/paste this for new release):
All notable user-facing or behavior-altering changes will be documented in this file. All notable user-facing or behavior-altering changes will be documented in this file.
### Added ### Added
- Use board-specific output and digital input pin names in error messages #3886 - Use board-specific output and digital input pin names in error messages #3886
- Support LPS22 in addition to LPS25 baro sensors #3900
### Fixed ### Fixed
- SD card logging with SDIO hardware #3873 - SD card logging with SDIO hardware #3873

View File

@ -9,7 +9,8 @@
#include "lps25.h" #include "lps25.h"
static constexpr uint8_t addr = 0x5C; static constexpr uint8_t addr = 0x5C;
static constexpr uint8_t expectedWhoAmI = 0xBD; static constexpr uint8_t expectedWhoAmILps22 = 0xB1;
static constexpr uint8_t expectedWhoAmILps25 = 0xBD;
// Control register 1 // Control register 1
#define LPS_CR1_PD (1 << 7) #define LPS_CR1_PD (1 << 7)
@ -20,7 +21,10 @@ static constexpr uint8_t expectedWhoAmI = 0xBD;
#define LPS_SR_P_DA (1 << 1) // Pressure data available #define LPS_SR_P_DA (1 << 1) // Pressure data available
#define REG_WhoAmI 0x0F #define REG_WhoAmI 0x0F
#define REG_Cr1 0x20
// register address different on LPS22 vs LPS25
#define REG_Cr1_Lps22 0x10
#define REG_Cr1_Lps25 0x20
#define REG_Status 0x27 #define REG_Status 0x27
#define REG_PressureOutXl 0x28 #define REG_PressureOutXl 0x28
#define REG_PressureOutL 0x29 #define REG_PressureOutL 0x29
@ -33,18 +37,33 @@ bool Lps25::init(brain_pin_e scl, brain_pin_e sda) {
// Read ident register // Read ident register
auto whoAmI = m_i2c.readRegister(addr, REG_WhoAmI); auto whoAmI = m_i2c.readRegister(addr, REG_WhoAmI);
if (whoAmI != expectedWhoAmI) {
switch (whoAmI)
{
case expectedWhoAmILps22:
m_type = Type::Lps22;
break;
case expectedWhoAmILps25:
m_type = Type::Lps25;
break;
default:
// chip not detected
return false; return false;
} }
// Set the control registers uint8_t cr1 =
m_i2c.writeRegister(addr, REG_Cr1,
LPS_CR1_PD | // Set to active mode
LPS_CR1_ODR_25hz | // 25hz update rate LPS_CR1_ODR_25hz | // 25hz update rate
// TODO: should bdu be set? // TODO: should bdu be set?
LPS_CR1_BDU // Output registers update only when read LPS_CR1_BDU; // Output registers update only when read
);
if (m_type == Type::Lps25) {
// Set to active mode
// this bit must be 0 on LPS22
cr1 |= LPS_CR1_PD;
}
// Set the control registers
m_i2c.writeRegister(addr, regCr1(), cr1);
m_hasInit = true; m_hasInit = true;
return true; return true;
@ -103,3 +122,14 @@ expected<float> Lps25::readPressureKpa() {
return kilopascal; return kilopascal;
} }
uint8_t Lps25::regCr1() const {
switch (m_type)
{
case Type::Lps22:
return REG_Cr1_Lps22;
case Type::Lps25:
default:
return REG_Cr1_Lps25;
}
}

View File

@ -1,6 +1,6 @@
/** /**
* @file lps25.h * @file lps25.h
* @brief Driver for the ST LPS25HB pressure sensor * @brief Driver for the ST LPS22HB and LPS25HB pressure sensor
* *
* @date February 6, 2020 * @date February 6, 2020
* @author Matthew Kennedy, (c) 2020 * @author Matthew Kennedy, (c) 2020
@ -25,5 +25,14 @@ public:
private: private:
BitbangI2c m_i2c; BitbangI2c m_i2c;
enum class Type {
Lps22,
Lps25,
};
Type m_type;
bool m_hasInit = false; bool m_hasInit = false;
uint8_t regCr1() const;
}; };

View File

@ -2629,8 +2629,8 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
field = "Low Value", baroSensor_lowValue, {baroSensor_hwChannel != @@ADC_CHANNEL_NONE@@ || lps25BaroSensorScl != 0 } field = "Low Value", baroSensor_lowValue, {baroSensor_hwChannel != @@ADC_CHANNEL_NONE@@ || lps25BaroSensorScl != 0 }
field = "High Value", baroSensor_highValue, {baroSensor_hwChannel != @@ADC_CHANNEL_NONE@@ || lps25BaroSensorScl != 0 } field = "High Value", baroSensor_highValue, {baroSensor_hwChannel != @@ADC_CHANNEL_NONE@@ || lps25BaroSensorScl != 0 }
field = "Type", baroSensor_type, {baroSensor_hwChannel != @@ADC_CHANNEL_NONE@@ || lps25BaroSensorScl != 0 } field = "Type", baroSensor_type, {baroSensor_hwChannel != @@ADC_CHANNEL_NONE@@ || lps25BaroSensorScl != 0 }
field = "LPS25 Baro SCL", lps25BaroSensorScl, { baroSensor_hwChannel == @@ADC_CHANNEL_NONE@@} field = "LPS2x Baro SCL", lps25BaroSensorScl, { baroSensor_hwChannel == @@ADC_CHANNEL_NONE@@}
field = "LPS25 Baro SDA", lps25BaroSensorSda, { baroSensor_hwChannel == @@ADC_CHANNEL_NONE@@} field = "LPS2x Baro SDA", lps25BaroSensorSda, { baroSensor_hwChannel == @@ADC_CHANNEL_NONE@@}
dialog = mapCurves, "MAP sampling", yAxis dialog = mapCurves, "MAP sampling", yAxis
field = "isMapAveragingEnabled", isMapAveragingEnabled field = "isMapAveragingEnabled", isMapAveragingEnabled