From ca54c9f5e832b9d822f8df6bf2f87af5bce2fd60 Mon Sep 17 00:00:00 2001 From: alexklimaj Date: Mon, 3 Oct 2022 16:02:00 -0600 Subject: [PATCH] AP_Baro: BMP390 --- Tools/scripts/decode_devid.py | 1 + libraries/AP_Baro/AP_Baro_BMP388.cpp | 18 ++++++++++++++---- libraries/AP_Baro/AP_Baro_Backend.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Tools/scripts/decode_devid.py b/Tools/scripts/decode_devid.py index c5da7a0f01..15b574306b 100755 --- a/Tools/scripts/decode_devid.py +++ b/Tools/scripts/decode_devid.py @@ -121,6 +121,7 @@ baro_types = { 0x11 : "DEVTYPE_BARO_MS5607", 0x12 : "DEVTYPE_BARO_MS5837", 0x13 : "DEVTYPE_BARO_MS5637", + 0x14 : "DEVTYPE_BARO_BMP390", } airspeed_types = { diff --git a/libraries/AP_Baro/AP_Baro_BMP388.cpp b/libraries/AP_Baro/AP_Baro_BMP388.cpp index 6b8b102d6a..e069a293d4 100644 --- a/libraries/AP_Baro/AP_Baro_BMP388.cpp +++ b/libraries/AP_Baro/AP_Baro_BMP388.cpp @@ -26,8 +26,10 @@ extern const AP_HAL::HAL &hal; #define BMP388_MODE BMP388_MODE_NORMAL #define BMP388_ID 0x50 +#define BMP390_ID 0x60 #define BMP388_REG_ID 0x00 +#define BMP388_REV_ID_ADDR 0x01 #define BMP388_REG_ERR 0x02 #define BMP388_REG_STATUS 0x03 #define BMP388_REG_PRESS 0x04 // 24 bit @@ -89,9 +91,18 @@ bool AP_Baro_BMP388::init() dev->write_register(BMP388_REG_PWR_CTRL, 0x33, true); uint8_t whoami; - if (!read_registers(BMP388_REG_ID, &whoami, 1) || - whoami != BMP388_ID) { - // not a BMP388 + if (!read_registers(BMP388_REG_ID, &whoami, 1)) { + return false; + } + + switch (whoami) { + case BMP388_ID: + dev->set_device_type(DEVTYPE_BARO_BMP388); + break; + case BMP390_ID: + dev->set_device_type(DEVTYPE_BARO_BMP390); + break; + default: return false; } @@ -108,7 +119,6 @@ bool AP_Baro_BMP388::init() instance = _frontend.register_sensor(); - dev->set_device_type(DEVTYPE_BARO_BMP388); set_bus_id(instance, dev->get_bus_id()); // request 50Hz update diff --git a/libraries/AP_Baro/AP_Baro_Backend.h b/libraries/AP_Baro/AP_Baro_Backend.h index 914995529c..045fffcca3 100644 --- a/libraries/AP_Baro/AP_Baro_Backend.h +++ b/libraries/AP_Baro/AP_Baro_Backend.h @@ -61,6 +61,7 @@ public: DEVTYPE_BARO_MS5607 = 0x11, DEVTYPE_BARO_MS5837 = 0x12, DEVTYPE_BARO_MS5637 = 0x13, + DEVTYPE_BARO_BMP390 = 0x14, }; protected: