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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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_AIRSPEEDDLVR_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_AIRSPEEDDLVR_ENABLED
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_Airspeed_DLVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

#include "SIM_I2CDevice.h"

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_AIRSPEEDDLVR_ENABLED
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should go in SIM_config.h

Also, please add underscores in each of them:

Suggested change
#ifndef AP_SIM_AIRSPEEDDLVR_ENABLED
#ifndef AP_SIM_AIRSPEED_DLVR_ENABLED

#define AP_SIM_AIRSPEEDDLVR_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_AIRSPEEDDLVR_ENABLED

namespace SITL {

class Airspeed_DLVR : public I2CDevice
Expand All @@ -26,3 +34,5 @@ class Airspeed_DLVR : public I2CDevice
};

} // namespace SITL

#endif // AP_SIM_AIRSPEEDDLVR_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_BATTMONITORSMBUSMAXELL_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_BATTMONITORSMBUSMAXELL_ENABLED
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED
#define AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED

#include "SIM_BattMonitor_SMBus_Generic.h"

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

} // namespace SITL

#endif // AP_SIM_BATTMONITORSMBUSMAXELL_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_BATTMONITORSMBUSROTOYE_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_BATTMONITORSMBUSROTOYE_ENABLED
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
#define AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED

#include "SIM_BattMonitor_SMBus_Generic.h"

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

} // namespace SITL

#endif // AP_SIM_BATTMONITORSMBUSROTOYE_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_MAXSONARI2CXL_ENABLED
static MaxSonarI2CXL maxsonari2cxl;
static MaxSonarI2CXL maxsonari2cxl_2;
#endif
#if AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED
static Maxell maxell;
#endif
#if AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
static Rotoye rotoye;
#endif
static SIM_BattMonitor_SMBus_Generic smbus_generic;
#if AP_SIM_AIRSPEEDDLVR_ENABLED
static Airspeed_DLVR airspeed_dlvr;
#endif
#if AP_SIM_TEMPERATURETSYS01_ENABLED
static TSYS01 tsys01;
#endif
#if AP_SIM_TSYS03_ENABLED
static TSYS03 tsys03;
#endif
#if AP_SIM_TEMPERATUREMCP9600_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_MAXSONARI2CXL_ENABLED
{ 0, 0x70, maxsonari2cxl }, // RNGFNDx_TYPE = 2, RNGFNDx_ADDR = 112
#endif
#if AP_SIM_TEMPERATUREMCP9600_ENABLED
{ 0, 0x60, mcp9600 }, // 0x60 is low address
#endif
#if AP_SIM_MAXSONARI2CXL_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_TEMPERATURETSYS01_ENABLED
{ 1, 0x77, tsys01 },
#endif
#if AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
{ 1, 0x0B, rotoye }, // Rotoye: BATTx_MONITOR 19, BATTx_I2C_ADDR 13
#endif
#if AP_SIM_BATTMONITORSMBUSMAXELL_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_AIRSPEEDDLVR_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
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_ICM40609.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "SIM_Invensense_v3.h"

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_ICM40609_ENABLED
#define AP_SIM_ICM40609_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_ICM40609_ENABLED

namespace SITL {

class ICM40609DevReg : public InvensenseV3DevReg {
Expand All @@ -21,3 +29,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
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_MS5525.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "SIM_MS5XXX.h"

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_MS5525_ENABLED
#define AP_SIM_MS5525_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_MS5525_ENABLED

#include <AP_Common/Bitmask.h>

namespace SITL {
Expand Down Expand Up @@ -43,3 +51,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
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_MS5611.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "SIM_MS5XXX.h"

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_MS5611_ENABLED
#define AP_SIM_MS5611_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_MS5611_ENABLED

#include <AP_Common/Bitmask.h>

namespace SITL {
Expand Down Expand Up @@ -43,3 +51,5 @@ class MS5611 : public MS5XXX
};

} // namespace SITL

#endif // AP_SIM_MS5611_ENABLED
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_MaxSonarI2CXL.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

#include "SIM_I2CDevice.h"

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_MAXSONARI2CXL_ENABLED
#define AP_SIM_MAXSONARI2CXL_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_MAXSONARI2CXL_ENABLED

namespace SITL {

class MaxSonarI2CXL : public I2CDevice, public I2CCommandResponseDevice
Expand Down Expand Up @@ -29,3 +37,5 @@ class MaxSonarI2CXL : public I2CDevice, public I2CCommandResponseDevice
};

} // namespace SITL

#endif // AP_SIM_MAXSONARI2CXL_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_TEMPERATUREMCP9600_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_TEMPERATUREMCP9600_ENABLED
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_Temperature_MCP9600.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "SIM_I2CDevice.h"

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_TEMPERATUREMCP9600_ENABLED
#define AP_SIM_TEMPERATUREMCP9600_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_TEMPERATUREMCP9600_ENABLED

/*
Simulator for the MCP9600 temperature sensor

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

} // namespace SITL

#endif // AP_SIM_TEMPERATUREMCP9600_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_TEMPERATURETSYS01_ENABLED

#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_TEMPERATURETSYS01_ENABLED
10 changes: 10 additions & 0 deletions libraries/SITL/SIM_Temperature_TSYS01.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "SIM_I2CDevice.h"

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_SIM_TEMPERATURETSYS01_ENABLED
#define AP_SIM_TEMPERATURETSYS01_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
#endif

#if AP_SIM_TEMPERATURETSYS01_ENABLED

/*
Simulator for the TSYS01 temperature sensor

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

} // namespace SITL

#endif // AP_SIM_TEMPERATURETSYS01_ENABLED
Loading