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

Reverse IMU I2C address from supplement to full #372

Merged
merged 6 commits into from
Dec 20, 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
13 changes: 13 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Global code owner
* @Eirenliel

# Make Loucas code owner of the defines to keep fw tool compatibility
/src/defines.h @loucass003
/src/consts.h @loucass003
/src/debug.h @loucass003

# Sfusion framework
/src/sensors/softfusion/ @gorbit99 @l0ud
/srs/sensors/SensorFusion* @gorbit99 @l0ud
/srs/sensors/motionprocessing/ @gorbit99 @l0ud
/lib/vqf/
4 changes: 2 additions & 2 deletions src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ enum class ImuID {
#define BOARD_MOCOPI 15 // Used by mocopi/moslime
#define BOARD_WEMOSWROOM02 16
#define BOARD_XIAO_ESP32C3 17
#define BOARD_HARITORA 18 // Used by Haritora/SlimeTora
#define BOARD_HARITORA 18 // Used by Haritora/SlimeTora
#define BOARD_ES32C6DEVKITC1 19
#define BOARD_DEV_RESERVED 250 // Reserved, should not be used in any release firmware
#define BOARD_DEV_RESERVED 250 // Reserved, should not be used in any release firmware

#define BAT_EXTERNAL 1
#define BAT_INTERNAL 2
Expand Down
5 changes: 5 additions & 0 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#define PRIMARY_IMU_OPTIONAL false
#define SECONDARY_IMU_OPTIONAL true

// Set I2C address here or directly in IMU_DESC_ENTRY for each IMU used
// If not set, default address is used based on the IMU and Sensor ID
// #define PRIMARY_IMU_ADDRESS_ONE 0x4a
// #define SECONDARY_IMU_ADDRESS_TWO 0x4b

#define MAX_IMU_COUNT 2

// Axis mapping example
Expand Down
1 change: 0 additions & 1 deletion src/sensors/SensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "icm20948sensor.h"
#include "mpu6050sensor.h"
#include "mpu9250sensor.h"
#include "sensoraddresses.h"
#include "softfusion/drivers/bmi270.h"
#include "softfusion/drivers/icm42688.h"
#include "softfusion/drivers/lsm6ds3trc.h"
Expand Down
27 changes: 18 additions & 9 deletions src/sensors/SensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#ifndef SLIMEVR_SENSORMANAGER
#define SLIMEVR_SENSORMANAGER

#ifndef PRIMARY_IMU_ADDRESS_ONE
#define PRIMARY_IMU_ADDRESS_ONE std::nullopt
#endif

#ifndef SECONDARY_IMU_ADDRESS_TWO
#define SECONDARY_IMU_ADDRESS_TWO std::nullopt
#endif

#include <i2cscan.h>

#include <memory>
#include <optional>

#include "EmptySensor.h"
#include "ErroneousSensor.h"
Expand Down Expand Up @@ -61,20 +69,20 @@ class SensorManager {
template <typename ImuType>
std::unique_ptr<Sensor> buildSensor(
uint8_t sensorID,
uint8_t addrSuppl,
std::optional<uint8_t> imuAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
bool optional = false,
int extraParam = 0
) {
const uint8_t address = ImuType::Address + addrSuppl;
uint8_t i2cAddress = imuAddress.value_or(ImuType::Address + sensorID);
m_Logger.trace(
"Building IMU with: id=%d,\n\
address=0x%02X, rotation=%f,\n\
sclPin=%d, sdaPin=%d, extraParam=%d, optional=%d",
sensorID,
address,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand All @@ -89,21 +97,22 @@ class SensorManager {
I2CSCAN::clearBus(sdaPin, sclPin);
swapI2C(sclPin, sdaPin);

if (I2CSCAN::hasDevOnBus(address)) {
m_Logger.trace("Sensor %d found at address 0x%02X", sensorID + 1, address);
if (I2CSCAN::hasDevOnBus(i2cAddress)) {
m_Logger
.trace("Sensor %d found at address 0x%02X", sensorID + 1, i2cAddress);
} else {
if (!optional) {
m_Logger.error(
"Mandatory sensor %d not found at address 0x%02X",
sensorID + 1,
address
i2cAddress
);
sensor = std::make_unique<ErroneousSensor>(sensorID, ImuType::TypeID);
} else {
m_Logger.debug(
"Optional sensor %d not found at address 0x%02X",
sensorID + 1,
address
i2cAddress
);
sensor = std::make_unique<EmptySensor>(sensorID);
}
Expand All @@ -113,7 +122,7 @@ class SensorManager {
uint8_t intPin = extraParam;
sensor = std::make_unique<ImuType>(
sensorID,
addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/bmi160sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class BMI160Sensor : public Sensor {

BMI160Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -148,7 +148,7 @@ class BMI160Sensor : public Sensor {
"BMI160Sensor",
ImuID::BMI160,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/bno055sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BNO055Sensor : public Sensor {

BNO055Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -45,7 +45,7 @@ class BNO055Sensor : public Sensor {
"BNO055Sensor",
ImuID::BNO055,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
16 changes: 8 additions & 8 deletions src/sensors/bno080sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BNO080Sensor : public Sensor {

BNO080Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -47,7 +47,7 @@ class BNO080Sensor : public Sensor {
"BNO080Sensor",
ImuID::BNO080,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand All @@ -69,13 +69,13 @@ class BNO080Sensor : public Sensor {
const char* sensorName,
ImuID imuId,
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
uint8_t intPin
)
: Sensor(sensorName, imuId, id, Address + addrSuppl, rotation, sclPin, sdaPin)
: Sensor(sensorName, imuId, id, i2cAddress, rotation, sclPin, sdaPin)
, m_IntPin(intPin){};

private:
Expand All @@ -102,7 +102,7 @@ class BNO085Sensor : public BNO080Sensor {
static constexpr auto TypeID = ImuID::BNO085;
BNO085Sensor(
uint8_t id,
uint8_t address,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -112,7 +112,7 @@ class BNO085Sensor : public BNO080Sensor {
"BNO085Sensor",
ImuID::BNO085,
id,
address,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand All @@ -125,7 +125,7 @@ class BNO086Sensor : public BNO080Sensor {
static constexpr auto TypeID = ImuID::BNO086;
BNO086Sensor(
uint8_t id,
uint8_t address,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -135,7 +135,7 @@ class BNO086Sensor : public BNO080Sensor {
"BNO086Sensor",
ImuID::BNO086,
id,
address,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/icm20948sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ICM20948Sensor : public Sensor {

ICM20948Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -45,7 +45,7 @@ class ICM20948Sensor : public Sensor {
"ICM20948Sensor",
ImuID::ICM20948,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/mpu6050sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MPU6050Sensor : public Sensor {

MPU6050Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -46,7 +46,7 @@ class MPU6050Sensor : public Sensor {
"MPU6050Sensor",
ImuID::MPU6050,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/mpu9250sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MPU9250Sensor : public Sensor {

MPU9250Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -59,7 +59,7 @@ class MPU9250Sensor : public Sensor {
"MPU9250Sensor",
ImuID::MPU9250,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
7 changes: 0 additions & 7 deletions src/sensors/sensoraddresses.h

This file was deleted.

14 changes: 3 additions & 11 deletions src/sensors/softfusion/softfusionsensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,15 @@ class SoftFusionSensor : public Sensor {

SoftFusionSensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
uint8_t
)
: Sensor(
imu::Name,
imu::Type,
id,
imu::Address + addrSuppl,
rotation,
sclPin,
sdaPin
)
: Sensor(imu::Name, imu::Type, id, i2cAddress, rotation, sclPin, sdaPin)
, m_fusion(imu::GyrTs, imu::AccTs, imu::MagTs)
, m_sensor(I2CImpl(imu::Address + addrSuppl), m_Logger) {}
, m_sensor(I2CImpl(i2cAddress), m_Logger) {}
~SoftFusionSensor() {}

void motionLoop() override final {
Expand Down
4 changes: 2 additions & 2 deletions src/serial/serialcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void printState() {
}

#if ESP32
char* getEncryptionTypeName(wifi_auth_mode_t type) {
String getEncryptionTypeName(wifi_auth_mode_t type) {
switch (type) {
case WIFI_AUTH_OPEN:
return "OPEN";
Expand All @@ -197,7 +197,7 @@ char* getEncryptionTypeName(wifi_auth_mode_t type) {
return "WPA3_ENT_192";
}
#else
char* getEncryptionTypeName(uint8_t type) {
String getEncryptionTypeName(uint8_t type) {
switch (type) {
case ENC_TYPE_NONE:
return "OPEN";
Expand Down
Loading