From a201b2428776f8968fd99f99f7cce091254a35f9 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 6 Jul 2026 13:59:39 +1200 Subject: [PATCH] fix(boards/airbrainh743): mark I2C1 external for external compass scan (#27814) The AirBrainH743 breaks out a single I2C bus (I2C1) that also carries the onboard DPS310 baro and IIS2MDC mag. Because the bus was marked internal, the external-compass autostart (which scans external buses with -X) never probed it, so an external GPS/compass on that bus was never bound. Mark I2C1 external so the external-mag autostart scans it, and add a px4_i2c_device_external() override (guarded by BOARD_OVERRIDE_I2C_DEVICE_EXTERNAL) that keeps the onboard baro and mag classified as internal. This mirrors the approach used on fmu-v6c. The onboard baro/mag are now started explicitly by bus and address (-X -b 1) since -I no longer matches the external bus. Also enable the i2cdetect command, which is handy for probing the shared external bus on this board. Signed-off-by: Julian Oes --- boards/gearup/airbrainh743/default.px4board | 1 + .../gearup/airbrainh743/init/rc.board_sensors | 12 ++--- boards/gearup/airbrainh743/src/board_config.h | 4 ++ boards/gearup/airbrainh743/src/i2c.cpp | 45 +++++++++++++++++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/boards/gearup/airbrainh743/default.px4board b/boards/gearup/airbrainh743/default.px4board index cf2ece5a986..8c45bef369d 100644 --- a/boards/gearup/airbrainh743/default.px4board +++ b/boards/gearup/airbrainh743/default.px4board @@ -88,3 +88,4 @@ CONFIG_SYSTEMCMDS_UORB=y CONFIG_SYSTEMCMDS_USB_CONNECTED=y CONFIG_SYSTEMCMDS_VER=y CONFIG_SYSTEMCMDS_WORK_QUEUE=y +CONFIG_SYSTEMCMDS_I2CDETECT=y diff --git a/boards/gearup/airbrainh743/init/rc.board_sensors b/boards/gearup/airbrainh743/init/rc.board_sensors index 06eac2ea345..d839b336a40 100644 --- a/boards/gearup/airbrainh743/init/rc.board_sensors +++ b/boards/gearup/airbrainh743/init/rc.board_sensors @@ -8,9 +8,11 @@ board_adc start # Internal SPI bus IMU - ICM42688P (Invensensev3) icm42688p -R 2 -b 1 -s start -# Internal I2C bus barometer - DPS310 @ 0x76 (118 decimal) -dps310 -I -a 118 start +# Onboard baro/mag are on I2C1, which is marked external because the bus is +# also broken out. Start them explicitly by bus + address. -# Internal I2C bus magnetometer - LIS2MDL @ 0x1E (30 decimal) -# Using iis2mdc driver (functionally equivalent to LIS2MDL) -iis2mdc -I -R 2 -a 30 start +# Onboard I2C1 barometer - DPS310 @ 0x76 (118 decimal) +dps310 -X -b 1 -a 118 start + +# Onboard I2C1 magnetometer - IIS2MDC @ 0x1E (30 decimal) +iis2mdc -X -b 1 -R 2 -a 30 start diff --git a/boards/gearup/airbrainh743/src/board_config.h b/boards/gearup/airbrainh743/src/board_config.h index f6317c8c0fe..0755cea43da 100644 --- a/boards/gearup/airbrainh743/src/board_config.h +++ b/boards/gearup/airbrainh743/src/board_config.h @@ -180,6 +180,10 @@ #define BOARD_ENABLE_CONSOLE_BUFFER +/* The onboard baro/mag share I2C1, which is broken out externally, so the + * board provides its own px4_i2c_device_external() (see src/i2c.cpp). */ +#define BOARD_OVERRIDE_I2C_DEVICE_EXTERNAL + #define BOARD_NUM_IO_TIMERS 4 diff --git a/boards/gearup/airbrainh743/src/i2c.cpp b/boards/gearup/airbrainh743/src/i2c.cpp index 26e33dc7fe9..4a623f5df36 100644 --- a/boards/gearup/airbrainh743/src/i2c.cpp +++ b/boards/gearup/airbrainh743/src/i2c.cpp @@ -33,15 +33,54 @@ #include +#include +#include + /* * I2C bus configuration for AirBrainH743 * - * I2C1: Internal bus - PB6 (SCL), PB7 (SDA) - * Devices: DPS310 baro @ 0x76, LIS2MDL compass @ 0x1E + * I2C1: PB6 (SCL), PB7 (SDA) + * Devices: DPS310 baro @ 0x76, IIS2MDC compass @ 0x1E + * This single bus is also broken out externally, so it is marked + * external to allow scanning for external compasses. The onboard baro + * and mag are forced back to internal in px4_i2c_device_external(). * I2C4: External bus - PD12 (SCL), PD13 (SDA) */ constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = { - initI2CBusInternal(1), + initI2CBusExternal(1), initI2CBusExternal(4), }; + +bool px4_i2c_device_external(const uint32_t device_id) +{ + // The onboard baro and mag are on I2C1, which is marked external because + // the same bus is also broken out externally. Keep these known onboard + // devices classified as internal. + + // DPS310 baro @ 0x76 on I2C1 + device::Device::DeviceId device_id_baro{}; + device_id_baro.devid_s.bus_type = device::Device::DeviceBusType_I2C; + device_id_baro.devid_s.bus = 1; + device_id_baro.devid_s.address = 0x76; + device_id_baro.devid_s.devtype = DRV_BARO_DEVTYPE_DPS310; + + if (device_id_baro.devid == device_id) { + return false; + } + + // IIS2MDC mag @ 0x1E on I2C1 + device::Device::DeviceId device_id_mag{}; + device_id_mag.devid_s.bus_type = device::Device::DeviceBusType_I2C; + device_id_mag.devid_s.bus = 1; + device_id_mag.devid_s.address = 0x1E; + device_id_mag.devid_s.devtype = DRV_MAG_DEVTYPE_IIS2MDC; + + if (device_id_mag.devid == device_id) { + return false; + } + + device::Device::DeviceId dev_id{}; + dev_id.devid = device_id; + return px4_i2c_bus_external(dev_id.devid_s.bus); +}