Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SITL: add ENABLED defines for remaining simulated I2C devices #28848

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libraries/SITL/SIM_Airspeed_DLVR.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_Airspeed_DLVR.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#include "SIM_config.h"

#if AP_SIM_AIRSPEED_DLVR_ENABLED

#include "SIM_I2CDevice.h"

namespace SITL {
Expand All @@ -26,3 +30,5 @@ class Airspeed_DLVR : public I2CDevice
};

} // namespace SITL

#endif // AP_SIM_AIRSPEED_DLVR_ENABLED
4 changes: 4 additions & 0 deletions libraries/SITL/SIM_BattMonitor_SMBus_Maxell.cpp
Original file line number Diff line number Diff line change
@@ -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()
{
Expand All @@ -15,3 +17,5 @@ SITL::Maxell::Maxell() :

set_register(SMBusBattGenericDevReg::SERIAL, (uint16_t)37);
}

#endif // AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "SIM_config.h"

#if AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED

#include "SIM_BattMonitor_SMBus_Generic.h"

#include <AP_Common/Bitmask.h>
Expand Down Expand Up @@ -25,3 +29,5 @@ class Maxell : public SIM_BattMonitor_SMBus_Generic
};

} // namespace SITL

#endif // AP_SIM_BATT_MONITOR_SMBUS_MAXELL_ENABLED
5 changes: 5 additions & 0 deletions libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "SIM_BattMonitor_SMBus_Rotoye.h"

#if AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED

#include <AP_HAL/utility/sparse-endian.h>

SITL::Rotoye::Rotoye() :
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "SIM_config.h"

#if AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED

#include "SIM_BattMonitor_SMBus_Generic.h"

#include <AP_Common/Bitmask.h>
Expand Down Expand Up @@ -33,3 +37,5 @@ class Rotoye : public SIM_BattMonitor_SMBus_Generic
};

} // namespace SITL

#endif // AP_SIM_BATT_MONITOR_SMBUS_ROTOYE_ENABLED
39 changes: 39 additions & 0 deletions libraries/SITL/SIM_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_ICM40609.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "SIM_config.h"

#if AP_SIM_ICM40609_ENABLED

#include "SIM_Invensense_v3.h"

namespace SITL {
Expand All @@ -21,3 +25,5 @@ class ICM40609 : public InvensenseV3
};

} // namespace SITL

#endif // AP_SIM_ICM40609_ENABLED
4 changes: 4 additions & 0 deletions libraries/SITL/SIM_MS5525.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SIM_MS5525.h"

#if AP_SIM_MS5525_ENABLED

#include <SITL/SITL.h>

using namespace SITL;
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_MS5525.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "SIM_config.h"

#if AP_SIM_MS5525_ENABLED

#include "SIM_MS5XXX.h"

#include <AP_Common/Bitmask.h>
Expand Down Expand Up @@ -43,3 +47,5 @@ class MS5525 : public MS5XXX
};

} // namespace SITL

#endif // AP_SIM_MS5525_ENABLED
4 changes: 4 additions & 0 deletions libraries/SITL/SIM_MS5611.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SIM_MS5611.h"

#if AP_SIM_MS5611_ENABLED

#include <SITL/SITL.h>

#include <stdio.h>
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_MS5611.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "SIM_config.h"

#if AP_SIM_MS5611_ENABLED

#include "SIM_MS5XXX.h"

#include <AP_Common/Bitmask.h>
Expand Down Expand Up @@ -43,3 +47,5 @@ class MS5611 : public MS5XXX
};

} // namespace SITL

#endif // AP_SIM_MS5611_ENABLED
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_MaxSonarI2CXL.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#include "SIM_config.h"

#if AP_SIM_MAXSONAR_I2C_XL_ENABLED

#include "SIM_I2CDevice.h"

namespace SITL {
Expand Down Expand Up @@ -29,3 +33,5 @@ class MaxSonarI2CXL : public I2CDevice, public I2CCommandResponseDevice
};

} // namespace SITL

#endif // AP_SIM_MAXSONAR_I2C_XL_ENABLED
4 changes: 4 additions & 0 deletions libraries/SITL/SIM_Temperature_MCP9600.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SIM_Temperature_MCP9600.h"

#if AP_SIM_TEMPERATURE_MCP9600_ENABLED

using namespace SITL;

#include <GCS_MAVLink/GCS.h>
Expand Down Expand Up @@ -65,3 +67,5 @@ int MCP9600::rdwr(I2C::i2c_rdwr_ioctl_data *&data)
{
return I2CRegisters_ConfigurableLength::rdwr(data);
}

#endif // AP_SIM_TEMPERATURE_MCP9600_ENABLED
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_Temperature_MCP9600.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "SIM_config.h"

#if AP_SIM_TEMPERATURE_MCP9600_ENABLED

#include "SIM_I2CDevice.h"

/*
Expand Down Expand Up @@ -36,3 +40,5 @@ class MCP9600 : public I2CDevice, private I2CRegisters_ConfigurableLength
};

} // namespace SITL

#endif // AP_SIM_TEMPERATURE_MCP9600_ENABLED
4 changes: 4 additions & 0 deletions libraries/SITL/SIM_Temperature_TSYS01.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SIM_Temperature_TSYS01.h"

#if AP_SIM_TEMPERATURE_TSYS01_ENABLED
davidbuzz marked this conversation as resolved.
Show resolved Hide resolved

#include <stdio.h>

constexpr const int32_t SITL::TSYS01::_k[5];
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions libraries/SITL/SIM_Temperature_TSYS01.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "SIM_config.h"

#if AP_SIM_TEMPERATURE_TSYS01_ENABLED

#include "SIM_I2CDevice.h"

/*
Expand Down Expand Up @@ -63,3 +67,5 @@ class TSYS01 : public I2CDevice
};

} // namespace SITL

#endif // AP_SIM_TEMPERATURE_TSYS01_ENABLED
36 changes: 36 additions & 0 deletions libraries/SITL/SIM_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading