Skip to content

Commit a758871

Browse files
committed
SITL: add ENABLED defines for remaining simulated I2C devices
- Reduces DRAM use for SIM on HW (esp. esp32empty and esp32s3empty). Signed-off-by: Rhys Mainwaring <[email protected]>
1 parent 7e3ae6c commit a758871

17 files changed

+158
-0
lines changed

libraries/SITL/SIM_Airspeed_DLVR.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "SIM_Airspeed_DLVR.h"
22

3+
#if AP_SIM_AIRSPEEDDLVR_ENABLED
4+
35
#include "SITL.h"
46

57
int SITL::Airspeed_DLVR::rdwr(I2C::i2c_rdwr_ioctl_data *&data)
@@ -68,3 +70,5 @@ void SITL::Airspeed_DLVR::update(const class Aircraft &aircraft)
6870
// To Do: Add a sensor board temperature offset parameter
6971
temperature = AP_Baro::get_temperatureC_for_alt_amsl(sim_alt);
7072
}
73+
74+
#endif // AP_SIM_AIRSPEEDDLVR_ENABLED

libraries/SITL/SIM_Airspeed_DLVR.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
#include "SIM_I2CDevice.h"
44

5+
#include <AP_HAL/AP_HAL_Boards.h>
6+
7+
#ifndef AP_SIM_AIRSPEEDDLVR_ENABLED
8+
#define AP_SIM_AIRSPEEDDLVR_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
9+
#endif
10+
11+
#if AP_SIM_AIRSPEEDDLVR_ENABLED
12+
513
namespace SITL {
614

715
class Airspeed_DLVR : public I2CDevice
@@ -26,3 +34,5 @@ class Airspeed_DLVR : public I2CDevice
2634
};
2735

2836
} // namespace SITL
37+
38+
#endif // AP_SIM_AIRSPEEDDLVR_ENABLED

libraries/SITL/SIM_BattMonitor_SMBus_Maxell.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "SIM_BattMonitor_SMBus_Maxell.h"
22

3+
#if AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED
4+
35
SITL::Maxell::Maxell() :
46
SIM_BattMonitor_SMBus_Generic()
57
{
@@ -15,3 +17,5 @@ SITL::Maxell::Maxell() :
1517

1618
set_register(SMBusBattGenericDevReg::SERIAL, (uint16_t)37);
1719
}
20+
21+
#endif // AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED

libraries/SITL/SIM_BattMonitor_SMBus_Maxell.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#include <AP_HAL/AP_HAL_Boards.h>
2+
3+
#ifndef AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED
4+
#define AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
5+
#endif
6+
7+
#if AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED
8+
19
#include "SIM_BattMonitor_SMBus_Generic.h"
210

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

2735
} // namespace SITL
36+
37+
#endif // AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED

libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "SIM_BattMonitor_SMBus_Rotoye.h"
2+
3+
#if AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
4+
25
#include <AP_HAL/utility/sparse-endian.h>
36

47
SITL::Rotoye::Rotoye() :
@@ -28,3 +31,5 @@ void SITL::Rotoye::update(const class Aircraft &aircraft)
2831
set_register(SMBusBattRotoyeDevReg::TEMP_EXT, int16_t(outside_temp + 100)); // it's a little warmer inside.... (10 degrees here)
2932
}
3033
}
34+
35+
#endif // AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED

libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#include <AP_HAL/AP_HAL_Boards.h>
2+
3+
#ifndef AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
4+
#define AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
5+
#endif
6+
7+
#if AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
8+
19
#include "SIM_BattMonitor_SMBus_Generic.h"
210

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

3543
} // namespace SITL
44+
45+
#endif // AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED

libraries/SITL/SIM_I2C.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "SIM_I2C.h"
2525
#include "SIM_ToshibaLED.h"
2626
#include "SIM_MaxSonarI2CXL.h"
27+
#include "SIM_BattMonitor_SMBus_Generic.h"
2728
#include "SIM_BattMonitor_SMBus_Maxell.h"
2829
#include "SIM_BattMonitor_SMBus_Rotoye.h"
2930
#include "SIM_Airspeed_DLVR.h"
@@ -59,20 +60,38 @@ static IgnoredI2CDevice ignored;
5960
#if AP_SIM_TOSHIBALED_ENABLED
6061
static ToshibaLED toshibaled;
6162
#endif
63+
#if AP_SIM_MAXSONARI2CXL_ENABLED
6264
static MaxSonarI2CXL maxsonari2cxl;
6365
static MaxSonarI2CXL maxsonari2cxl_2;
66+
#endif
67+
#if AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED
6468
static Maxell maxell;
69+
#endif
70+
#if AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
6571
static Rotoye rotoye;
72+
#endif
6673
static SIM_BattMonitor_SMBus_Generic smbus_generic;
74+
#if AP_SIM_AIRSPEEDDLVR_ENABLED
6775
static Airspeed_DLVR airspeed_dlvr;
76+
#endif
77+
#if AP_SIM_TEMPERATURETSYS01_ENABLED
6878
static TSYS01 tsys01;
79+
#endif
6980
#if AP_SIM_TSYS03_ENABLED
7081
static TSYS03 tsys03;
7182
#endif
83+
#if AP_SIM_TEMPERATUREMCP9600_ENABLED
7284
static MCP9600 mcp9600;
85+
#endif
86+
#if AP_SIM_ICM40609_ENABLED
7387
static ICM40609 icm40609;
88+
#endif
89+
#if AP_SIM_MS5525_ENABLED
7490
static MS5525 ms5525;
91+
#endif
92+
#if AP_SIM_MS5611_ENABLED
7593
static MS5611 ms5611;
94+
#endif
7695
#if AP_SIM_LP5562_ENABLED
7796
static LP5562 lp5562;
7897
#endif
@@ -95,25 +114,43 @@ struct i2c_device_at_address {
95114
uint8_t addr;
96115
I2CDevice &device;
97116
} i2c_devices[] {
117+
#if AP_SIM_MAXSONARI2CXL_ENABLED
98118
{ 0, 0x70, maxsonari2cxl }, // RNGFNDx_TYPE = 2, RNGFNDx_ADDR = 112
119+
#endif
120+
#if AP_SIM_TEMPERATUREMCP9600_ENABLED
99121
{ 0, 0x60, mcp9600 }, // 0x60 is low address
122+
#endif
123+
#if AP_SIM_MAXSONARI2CXL_ENABLED
100124
{ 0, 0x71, maxsonari2cxl_2 }, // RNGFNDx_TYPE = 2, RNGFNDx_ADDR = 113
125+
#endif
126+
#if AP_SIM_ICM40609_ENABLED
101127
{ 1, 0x01, icm40609 },
128+
#endif
102129
#if AP_SIM_TOSHIBALED_ENABLED
103130
{ 1, 0x55, toshibaled },
104131
#endif
105132
{ 1, 0x38, ignored }, // NCP5623
106133
{ 1, 0x39, ignored }, // NCP5623C
107134
{ 1, 0x40, ignored }, // KellerLD
135+
#if AP_SIM_MS5525_ENABLED
108136
{ 1, 0x76, ms5525 }, // MS5525: ARSPD_TYPE = 4
137+
#endif
109138
#if AP_SIM_INA3221_ENABLED
110139
{ 1, 0x42, ina3221 },
111140
#endif
141+
#if AP_SIM_TEMPERATURETSYS01_ENABLED
112142
{ 1, 0x77, tsys01 },
143+
#endif
144+
#if AP_SIM_BATTMONITORSMBUSROTOYE_ENABLED
113145
{ 1, 0x0B, rotoye }, // Rotoye: BATTx_MONITOR 19, BATTx_I2C_ADDR 13
146+
#endif
147+
#if AP_SIM_BATTMONITORSMBUSMAXELL_ENABLED
114148
{ 2, 0x0B, maxell }, // Maxell: BATTx_MONITOR 16, BATTx_I2C_ADDR 13
149+
#endif
115150
{ 3, 0x0B, smbus_generic}, // BATTx_MONITOR 7, BATTx_I2C_ADDR 13
151+
#if AP_SIM_AIRSPEEDDLVR_ENABLED
116152
{ 2, 0x28, airspeed_dlvr }, // ARSPD_TYPE = 7 5inch H2O sensor
153+
#endif
117154
#if AP_SIM_LP5562_ENABLED
118155
{ 2, 0x30, lp5562 }, // LP5562 RGB LED driver
119156
#endif
@@ -126,7 +163,9 @@ struct i2c_device_at_address {
126163
#if AP_SIM_TSYS03_ENABLED
127164
{ 2, 0x40, tsys03 },
128165
#endif
166+
#if AP_SIM_MS5611_ENABLED
129167
{ 2, 0x77, ms5611 }, // MS5611: BARO_PROBE_EXT = 2
168+
#endif
130169
#if AP_SIM_COMPASS_QMC5883L_ENABLED
131170
{ 2, 0x0D, qmc5883l },
132171
#endif

libraries/SITL/SIM_ICM40609.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#include "SIM_Invensense_v3.h"
22

3+
#include <AP_HAL/AP_HAL_Boards.h>
4+
5+
#ifndef AP_SIM_ICM40609_ENABLED
6+
#define AP_SIM_ICM40609_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
7+
#endif
8+
9+
#if AP_SIM_ICM40609_ENABLED
10+
311
namespace SITL {
412

513
class ICM40609DevReg : public InvensenseV3DevReg {
@@ -21,3 +29,5 @@ class ICM40609 : public InvensenseV3
2129
};
2230

2331
} // namespace SITL
32+
33+
#endif // AP_SIM_ICM40609_ENABLED

libraries/SITL/SIM_MS5525.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "SIM_MS5525.h"
22

3+
#if AP_SIM_MS5525_ENABLED
4+
35
#include <SITL/SITL.h>
46

57
using namespace SITL;
@@ -72,3 +74,5 @@ void MS5525::get_pressure_temperature_readings(float &P_Pa, float &Temp_C)
7274
const uint8_t instance = 0; // TODO: work out which sensor this is
7375
P_Pa = AP::sitl()->state.airspeed_raw_pressure[instance] + AP::sitl()->airspeed[instance].offset;
7476
}
77+
78+
#endif // AP_SIM_MS5525_ENABLED

libraries/SITL/SIM_MS5525.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#include "SIM_MS5XXX.h"
22

3+
#include <AP_HAL/AP_HAL_Boards.h>
4+
5+
#ifndef AP_SIM_MS5525_ENABLED
6+
#define AP_SIM_MS5525_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
7+
#endif
8+
9+
#if AP_SIM_MS5525_ENABLED
10+
311
#include <AP_Common/Bitmask.h>
412

513
namespace SITL {
@@ -43,3 +51,5 @@ class MS5525 : public MS5XXX
4351
};
4452

4553
} // namespace SITL
54+
55+
#endif // AP_SIM_MS5525_ENABLED

0 commit comments

Comments
 (0)