From 70fe304c7ede711256be792776300fb86cf692fa Mon Sep 17 00:00:00 2001 From: Rhys Mainwaring Date: Thu, 12 Dec 2024 12:05:43 +0000 Subject: [PATCH] SITL: add ENABLED defines for simulated I2C devices Signed-off-by: Rhys Mainwaring --- libraries/SITL/SIM_Airspeed_DLVR.cpp | 4 ++ libraries/SITL/SIM_Airspeed_DLVR.h | 6 +++ .../SITL/SIM_BattMonitor_SMBus_Maxell.cpp | 4 ++ libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h | 6 +++ .../SITL/SIM_BattMonitor_SMBus_Rotoye.cpp | 5 +++ libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h | 6 +++ libraries/SITL/SIM_I2C.cpp | 39 +++++++++++++++++++ libraries/SITL/SIM_ICM40609.h | 6 +++ libraries/SITL/SIM_MS5525.cpp | 4 ++ libraries/SITL/SIM_MS5525.h | 6 +++ libraries/SITL/SIM_MS5611.cpp | 4 ++ libraries/SITL/SIM_MS5611.h | 6 +++ libraries/SITL/SIM_MaxSonarI2CXL.h | 6 +++ libraries/SITL/SIM_Temperature_MCP9600.cpp | 4 ++ libraries/SITL/SIM_Temperature_MCP9600.h | 6 +++ libraries/SITL/SIM_Temperature_TSYS01.cpp | 4 ++ libraries/SITL/SIM_Temperature_TSYS01.h | 6 +++ libraries/SITL/SIM_config.h | 36 +++++++++++++++++ 18 files changed, 158 insertions(+) diff --git a/libraries/SITL/SIM_Airspeed_DLVR.cpp b/libraries/SITL/SIM_Airspeed_DLVR.cpp index 265185fae4..d6bb09b10c 100644 --- a/libraries/SITL/SIM_Airspeed_DLVR.cpp +++ b/libraries/SITL/SIM_Airspeed_DLVR.cpp @@ -1,5 +1,7 @@ #include "SIM_Airspeed_DLVR.h" +#if AP_SIM_AIRSPEED_DLVR_ENABLED + #include "SITL.h" int SITL::Airspeed_DLVR::rdwr(I2C::i2c_rdwr_ioctl_data *&data) @@ -68,3 +70,5 @@ void SITL::Airspeed_DLVR::update(const class Aircraft &aircraft) // To Do: Add a sensor board temperature offset parameter temperature = AP_Baro::get_temperatureC_for_alt_amsl(sim_alt); } + +#endif // AP_SIM_AIRSPEED_DLVR_ENABLED diff --git a/libraries/SITL/SIM_Airspeed_DLVR.h b/libraries/SITL/SIM_Airspeed_DLVR.h index cb21efdb51..6bb95bc2eb 100644 --- a/libraries/SITL/SIM_Airspeed_DLVR.h +++ b/libraries/SITL/SIM_Airspeed_DLVR.h @@ -1,5 +1,9 @@ #pragma once +#include "SIM_config.h" + +#if AP_SIM_AIRSPEED_DLVR_ENABLED + #include "SIM_I2CDevice.h" namespace SITL { @@ -26,3 +30,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_AIRSPEED_DLVR_ENABLED diff --git a/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.cpp b/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.cpp index eaf1c1b19f..4a9cc2c32b 100644 --- a/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.cpp +++ b/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.cpp @@ -1,5 +1,7 @@ #include "SIM_BattMonitor_SMBus_Maxell.h" +#if AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED + SITL::Maxell::Maxell() : SIM_BattMonitor_SMBus_Generic() { @@ -15,3 +17,5 @@ SITL::Maxell::Maxell() : set_register(SMBusBattGenericDevReg::SERIAL, (uint16_t)37); } + +#endif // AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED diff --git a/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h b/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h index 5652b48cbd..e620f0dd2e 100644 --- a/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h +++ b/libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h @@ -1,3 +1,7 @@ +#include "SIM_config.h" + +#if AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED + #include "SIM_BattMonitor_SMBus_Generic.h" #include @@ -25,3 +29,5 @@ public: }; } // namespace SITL + +#endif // AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED diff --git a/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp index adadfda70e..ce52f38b20 100644 --- a/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp +++ b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp @@ -1,4 +1,7 @@ #include "SIM_BattMonitor_SMBus_Rotoye.h" + +#if AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED + #include SITL::Rotoye::Rotoye() : @@ -28,3 +31,5 @@ void SITL::Rotoye::update(const class Aircraft &aircraft) set_register(SMBusBattRotoyeDevReg::TEMP_EXT, int16_t(outside_temp + 100)); // it's a little warmer inside.... (10 degrees here) } } + +#endif // AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED diff --git a/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h index a7617249b9..9c33e9f6ee 100644 --- a/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h +++ b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h @@ -1,3 +1,7 @@ +#include "SIM_config.h" + +#if AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED + #include "SIM_BattMonitor_SMBus_Generic.h" #include @@ -33,3 +37,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED diff --git a/libraries/SITL/SIM_I2C.cpp b/libraries/SITL/SIM_I2C.cpp index 8d1b1daf0a..2b5c6af057 100644 --- a/libraries/SITL/SIM_I2C.cpp +++ b/libraries/SITL/SIM_I2C.cpp @@ -24,6 +24,7 @@ #include "SIM_I2C.h" #include "SIM_ToshibaLED.h" #include "SIM_MaxSonarI2CXL.h" +#include "SIM_BattMonitor_SMBus_Generic.h" #include "SIM_BattMonitor_SMBus_Maxell.h" #include "SIM_BattMonitor_SMBus_Rotoye.h" #include "SIM_Airspeed_DLVR.h" @@ -59,20 +60,38 @@ static IgnoredI2CDevice ignored; #if AP_SIM_TOSHIBALED_ENABLED static ToshibaLED toshibaled; #endif +#if AP_SIM_MAXSONAR_I2C_XL_ENABLED static MaxSonarI2CXL maxsonari2cxl; static MaxSonarI2CXL maxsonari2cxl_2; +#endif +#if AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED static Maxell maxell; +#endif +#if AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED static Rotoye rotoye; +#endif static SIM_BattMonitor_SMBus_Generic smbus_generic; +#if AP_SIM_AIRSPEED_DLVR_ENABLED static Airspeed_DLVR airspeed_dlvr; +#endif +#if AP_SIM_TEMPERATURE_TSYS01_ENABLED static TSYS01 tsys01; +#endif #if AP_SIM_TSYS03_ENABLED static TSYS03 tsys03; #endif +#if AP_SIM_TEMPERATURE_MCP9600_ENABLED static MCP9600 mcp9600; +#endif +#if AP_SIM_ICM40609_ENABLED static ICM40609 icm40609; +#endif +#if AP_SIM_MS5525_ENABLED static MS5525 ms5525; +#endif +#if AP_SIM_MS5611_ENABLED static MS5611 ms5611; +#endif #if AP_SIM_LP5562_ENABLED static LP5562 lp5562; #endif @@ -95,25 +114,43 @@ struct i2c_device_at_address { uint8_t addr; I2CDevice &device; } i2c_devices[] { +#if AP_SIM_MAXSONAR_I2C_XL_ENABLED { 0, 0x70, maxsonari2cxl }, // RNGFNDx_TYPE = 2, RNGFNDx_ADDR = 112 +#endif +#if AP_SIM_TEMPERATURE_MCP9600_ENABLED { 0, 0x60, mcp9600 }, // 0x60 is low address +#endif +#if AP_SIM_MAXSONAR_I2C_XL_ENABLED { 0, 0x71, maxsonari2cxl_2 }, // RNGFNDx_TYPE = 2, RNGFNDx_ADDR = 113 +#endif +#if AP_SIM_ICM40609_ENABLED { 1, 0x01, icm40609 }, +#endif #if AP_SIM_TOSHIBALED_ENABLED { 1, 0x55, toshibaled }, #endif { 1, 0x38, ignored }, // NCP5623 { 1, 0x39, ignored }, // NCP5623C { 1, 0x40, ignored }, // KellerLD +#if AP_SIM_MS5525_ENABLED { 1, 0x76, ms5525 }, // MS5525: ARSPD_TYPE = 4 +#endif #if AP_SIM_INA3221_ENABLED { 1, 0x42, ina3221 }, #endif +#if AP_SIM_TEMPERATURE_TSYS01_ENABLED { 1, 0x77, tsys01 }, +#endif +#if AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED { 1, 0x0B, rotoye }, // Rotoye: BATTx_MONITOR 19, BATTx_I2C_ADDR 13 +#endif +#if AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED { 2, 0x0B, maxell }, // Maxell: BATTx_MONITOR 16, BATTx_I2C_ADDR 13 +#endif { 3, 0x0B, smbus_generic}, // BATTx_MONITOR 7, BATTx_I2C_ADDR 13 +#if AP_SIM_AIRSPEED_DLVR_ENABLED { 2, 0x28, airspeed_dlvr }, // ARSPD_TYPE = 7 5inch H2O sensor +#endif #if AP_SIM_LP5562_ENABLED { 2, 0x30, lp5562 }, // LP5562 RGB LED driver #endif @@ -126,7 +163,9 @@ struct i2c_device_at_address { #if AP_SIM_TSYS03_ENABLED { 2, 0x40, tsys03 }, #endif +#if AP_SIM_MS5611_ENABLED { 2, 0x77, ms5611 }, // MS5611: BARO_PROBE_EXT = 2 +#endif #if AP_SIM_COMPASS_QMC5883L_ENABLED { 2, 0x0D, qmc5883l }, #endif diff --git a/libraries/SITL/SIM_ICM40609.h b/libraries/SITL/SIM_ICM40609.h index 121b82b957..300634eddd 100644 --- a/libraries/SITL/SIM_ICM40609.h +++ b/libraries/SITL/SIM_ICM40609.h @@ -1,3 +1,7 @@ +#include "SIM_config.h" + +#if AP_SIM_ICM40609_ENABLED + #include "SIM_Invensense_v3.h" namespace SITL { @@ -21,3 +25,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_ICM40609_ENABLED diff --git a/libraries/SITL/SIM_MS5525.cpp b/libraries/SITL/SIM_MS5525.cpp index 760c4202f9..30ae091c39 100644 --- a/libraries/SITL/SIM_MS5525.cpp +++ b/libraries/SITL/SIM_MS5525.cpp @@ -1,5 +1,7 @@ #include "SIM_MS5525.h" +#if AP_SIM_MS5525_ENABLED + #include using namespace SITL; @@ -72,3 +74,5 @@ void MS5525::get_pressure_temperature_readings(float &P_Pa, float &Temp_C) const uint8_t instance = 0; // TODO: work out which sensor this is P_Pa = AP::sitl()->state.airspeed_raw_pressure[instance] + AP::sitl()->airspeed[instance].offset; } + +#endif // AP_SIM_MS5525_ENABLED diff --git a/libraries/SITL/SIM_MS5525.h b/libraries/SITL/SIM_MS5525.h index f64b82ff0b..bbc11f4967 100644 --- a/libraries/SITL/SIM_MS5525.h +++ b/libraries/SITL/SIM_MS5525.h @@ -1,3 +1,7 @@ +#include "SIM_config.h" + +#if AP_SIM_MS5525_ENABLED + #include "SIM_MS5XXX.h" #include @@ -43,3 +47,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_MS5525_ENABLED diff --git a/libraries/SITL/SIM_MS5611.cpp b/libraries/SITL/SIM_MS5611.cpp index d205665d5e..cce4927711 100644 --- a/libraries/SITL/SIM_MS5611.cpp +++ b/libraries/SITL/SIM_MS5611.cpp @@ -1,5 +1,7 @@ #include "SIM_MS5611.h" +#if AP_SIM_MS5611_ENABLED + #include #include @@ -121,3 +123,5 @@ void MS5611::get_pressure_temperature_readings(float &P_Pa, float &Temp_C) // TO DO add in wind correction by inheritting from AP_Baro_SITL_Generic? // P_Pa += AP_Baro_SITL::wind_pressure_correction(instance); } + +#endif // AP_SIM_MS5611_ENABLED diff --git a/libraries/SITL/SIM_MS5611.h b/libraries/SITL/SIM_MS5611.h index 7822a470d4..34e8c30f36 100644 --- a/libraries/SITL/SIM_MS5611.h +++ b/libraries/SITL/SIM_MS5611.h @@ -1,3 +1,7 @@ +#include "SIM_config.h" + +#if AP_SIM_MS5611_ENABLED + #include "SIM_MS5XXX.h" #include @@ -43,3 +47,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_MS5611_ENABLED diff --git a/libraries/SITL/SIM_MaxSonarI2CXL.h b/libraries/SITL/SIM_MaxSonarI2CXL.h index a18d981745..df30aa883e 100644 --- a/libraries/SITL/SIM_MaxSonarI2CXL.h +++ b/libraries/SITL/SIM_MaxSonarI2CXL.h @@ -1,5 +1,9 @@ #pragma once +#include "SIM_config.h" + +#if AP_SIM_MAXSONAR_I2C_XL_ENABLED + #include "SIM_I2CDevice.h" namespace SITL { @@ -29,3 +33,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_MAXSONAR_I2C_XL_ENABLED diff --git a/libraries/SITL/SIM_Temperature_MCP9600.cpp b/libraries/SITL/SIM_Temperature_MCP9600.cpp index c05e722150..be6304f745 100644 --- a/libraries/SITL/SIM_Temperature_MCP9600.cpp +++ b/libraries/SITL/SIM_Temperature_MCP9600.cpp @@ -1,5 +1,7 @@ #include "SIM_Temperature_MCP9600.h" +#if AP_SIM_TEMPERATURE_MCP9600_ENABLED + using namespace SITL; #include @@ -65,3 +67,5 @@ int MCP9600::rdwr(I2C::i2c_rdwr_ioctl_data *&data) { return I2CRegisters_ConfigurableLength::rdwr(data); } + +#endif // AP_SIM_TEMPERATURE_MCP9600_ENABLED diff --git a/libraries/SITL/SIM_Temperature_MCP9600.h b/libraries/SITL/SIM_Temperature_MCP9600.h index c0d2f3ae1a..79d5b40e5e 100644 --- a/libraries/SITL/SIM_Temperature_MCP9600.h +++ b/libraries/SITL/SIM_Temperature_MCP9600.h @@ -1,3 +1,7 @@ +#include "SIM_config.h" + +#if AP_SIM_TEMPERATURE_MCP9600_ENABLED + #include "SIM_I2CDevice.h" /* @@ -36,3 +40,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_TEMPERATURE_MCP9600_ENABLED diff --git a/libraries/SITL/SIM_Temperature_TSYS01.cpp b/libraries/SITL/SIM_Temperature_TSYS01.cpp index 5785a73152..a97ca72c46 100644 --- a/libraries/SITL/SIM_Temperature_TSYS01.cpp +++ b/libraries/SITL/SIM_Temperature_TSYS01.cpp @@ -1,5 +1,7 @@ #include "SIM_Temperature_TSYS01.h" +#if AP_SIM_TEMPERATURE_TSYS01_ENABLED + #include constexpr const int32_t SITL::TSYS01::_k[5]; @@ -196,3 +198,5 @@ float SITL::TSYS01::get_sim_temperature() const // To Do: Add a sensor board temperature offset parameter return AP_Baro::get_temperatureC_for_alt_amsl(sim_alt) + 25; } + +#endif // AP_SIM_TEMPERATURE_TSYS01_ENABLED diff --git a/libraries/SITL/SIM_Temperature_TSYS01.h b/libraries/SITL/SIM_Temperature_TSYS01.h index 5ad9bff832..8b7127d0a1 100644 --- a/libraries/SITL/SIM_Temperature_TSYS01.h +++ b/libraries/SITL/SIM_Temperature_TSYS01.h @@ -1,3 +1,7 @@ +#include "SIM_config.h" + +#if AP_SIM_TEMPERATURE_TSYS01_ENABLED + #include "SIM_I2CDevice.h" /* @@ -63,3 +67,5 @@ private: }; } // namespace SITL + +#endif // AP_SIM_TEMPERATURE_TSYS01_ENABLED diff --git a/libraries/SITL/SIM_config.h b/libraries/SITL/SIM_config.h index 12fca3b307..5d6850bd39 100644 --- a/libraries/SITL/SIM_config.h +++ b/libraries/SITL/SIM_config.h @@ -148,6 +148,42 @@ #define AP_SIM_GIMBAL_ENABLED (AP_SIM_SOLOGIMBAL_ENABLED) #endif +#ifndef AP_SIM_AIRSPEED_DLVR_ENABLED +#define AP_SIM_AIRSPEED_DLVR_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#ifndef AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED +#define AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#ifndef AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED +#define AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + #ifndef AP_SIM_INA3221_ENABLED #define AP_SIM_INA3221_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) #endif + +#ifndef AP_SIM_ICM40609_ENABLED +#define AP_SIM_ICM40609_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#ifndef AP_SIM_MS5525_ENABLED +#define AP_SIM_MS5525_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#ifndef AP_SIM_MS5611_ENABLED +#define AP_SIM_MS5611_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#ifndef AP_SIM_MAXSONAR_I2C_XL_ENABLED +#define AP_SIM_MAXSONAR_I2C_XL_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#ifndef AP_SIM_TEMPERATURE_MCP9600_ENABLED +#define AP_SIM_TEMPERATURE_MCP9600_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#ifndef AP_SIM_TEMPERATURE_TSYS01_ENABLED +#define AP_SIM_TEMPERATURE_TSYS01_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif