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

ESP32C3 stability improvements #265

Merged
merged 3 commits into from
Sep 18, 2023
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
38 changes: 24 additions & 14 deletions lib/i2cscan/i2cscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ namespace I2CSCAN
{

uint8_t pickDevice(uint8_t addr1, uint8_t addr2, bool scanIfNotFound) {
if(I2CSCAN::isI2CExist(addr1))
if(I2CSCAN::hasDevOnBus(addr1)) {
return addr1;
if(!I2CSCAN::isI2CExist(addr2)) {
if(scanIfNotFound) {
Serial.println("[ERR] I2C: Can't find I2C device on provided addresses, scanning for all I2C devices and returning");
I2CSCAN::scani2cports();
} else {
Serial.println("[ERR] I2C: Can't find I2C device on provided addresses");
}
return 0;
}
return addr2;
if(I2CSCAN::hasDevOnBus(addr2)) {
return addr2;
}
if (scanIfNotFound) {
Serial.println("[ERR] I2C: Can't find I2C device on provided addresses, scanning for all I2C devices and returning");
I2CSCAN::scani2cports();
} else {
Serial.println("[ERR] I2C: Can't find I2C device on provided addresses");
}
return 0;
}

void scani2cports()
Expand Down Expand Up @@ -103,16 +104,25 @@ namespace I2CSCAN
}
else if (error == 4)
{
Serial.printf("[ERR] I2C (@ %s(%d) : %s(%d)): Unknow error at address 0x%02x\n",
Serial.printf("[ERR] I2C (@ %s(%d) : %s(%d)): Unknown error at address 0x%02x\n",
portMap[i].c_str(), portArray[i], portMap[j].c_str(), portArray[j], address);
}
}
return found;
}

bool isI2CExist(uint8_t addr) {
Wire.beginTransmission(addr);
byte error = Wire.endTransmission();
bool hasDevOnBus(uint8_t addr) {
byte error;
#if ESP32C3
int retries = 1;
do {
#endif
Wire.beginTransmission(addr);
error = Wire.endTransmission();
#if ESP32C3
}
while (error == 5 && retries--);
#endif
if(error == 0)
return true;
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/i2cscan/i2cscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace I2CSCAN {
void scani2cports();
bool checkI2C(uint8_t i, uint8_t j);
bool isI2CExist(uint8_t addr);
bool hasDevOnBus(uint8_t addr);
uint8_t pickDevice(uint8_t addr1, uint8_t addr2, bool scanIfNotFound);
int clearBus(uint8_t SDA, uint8_t SCL);
boolean inArray(uint8_t value, uint8_t* arr, size_t arrSize);
Expand Down
2 changes: 1 addition & 1 deletion src/batterymonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void BatteryMonitor::Setup()
#if BATTERY_MONITOR == BAT_MCP3021 || BATTERY_MONITOR == BAT_INTERNAL_MCP3021
for (uint8_t i = 0x48; i < 0x4F; i++)
{
if (I2CSCAN::isI2CExist(i))
if (I2CSCAN::hasDevOnBus(i))
{
address = i;
break;
Expand Down
6 changes: 2 additions & 4 deletions src/configuration/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

namespace SlimeVR {
namespace Configuration {
CalibrationConfig Configuration::m_EmptyCalibration = {NONE};

void Configuration::setup() {
if (m_Loaded) {
return;
Expand Down Expand Up @@ -140,7 +138,7 @@ namespace SlimeVR {

CalibrationConfig Configuration::getCalibration(size_t sensorID) const {
if (sensorID >= m_Calibrations.size()) {
return m_EmptyCalibration;
return {};
}

return m_Calibrations.at(sensorID);
Expand All @@ -150,7 +148,7 @@ namespace SlimeVR {
size_t currentCalibrations = m_Calibrations.size();

if (sensorID >= currentCalibrations) {
m_Calibrations.resize(sensorID + 1, m_EmptyCalibration);
m_Calibrations.resize(sensorID + 1);
}

m_Calibrations[sensorID] = config;
Expand Down
2 changes: 0 additions & 2 deletions src/configuration/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ namespace SlimeVR {
std::vector<CalibrationConfig> m_Calibrations;

Logging::Logger m_Logger = Logging::Logger("Configuration");

static CalibrationConfig m_EmptyCalibration;
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/SensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace SlimeVR
I2CSCAN::clearBus(sdaPin, sclPin);
swapI2C(sclPin, sdaPin);

if (I2CSCAN::isI2CExist(address)) {
if (I2CSCAN::hasDevOnBus(address)) {
m_Logger.trace("IMU %d found at address 0x%02X", sensorID, address);
} else {
sensor = new ErroneousSensor(sensorID, imuType);
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/bmi160sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ class BMI160Sensor : public Sensor {
double gscaleY = BMI160_GSCALE;
double gscaleZ = BMI160_GSCALE;

double GOxyzStaticTempCompensated[3];
double GOxyzStaticTempCompensated[3] = {0.0, 0.0, 0.0};

bool isGyroCalibrated = false;
bool isAccelCalibrated = false;
bool isMagCalibrated = false;

SlimeVR::Configuration::BMI160CalibrationConfig m_Calibration;
SlimeVR::Configuration::BMI160CalibrationConfig m_Calibration = {};
};

#endif
2 changes: 1 addition & 1 deletion src/sensors/icm20948sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ICM20948Sensor : public Sensor
icm_20948_DMP_data_t dmpData{};
icm_20948_DMP_data_t dmpDataTemp{};

SlimeVR::Configuration::ICM20948CalibrationConfig m_Calibration;
SlimeVR::Configuration::ICM20948CalibrationConfig m_Calibration = {};

SlimeVR::Sensors::SensorFusionDMP sfusion;

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/mpu6050sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MPU6050Sensor : public Sensor
SlimeVR::Sensors::SensorFusionDMP sfusion;

#ifndef IMU_MPU6050_RUNTIME_CALIBRATION
SlimeVR::Configuration::MPU6050CalibrationConfig m_Calibration;
SlimeVR::Configuration::MPU6050CalibrationConfig m_Calibration = {};
#endif
};

Expand Down
4 changes: 2 additions & 2 deletions src/sensors/mpu9250sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class MPU9250Sensor : public Sensor
float Mxyz[3]{};
VectorInt16 rawAccel{};
Quat correction{0, 0, 0, 0};
SlimeVR::Configuration::MPU9250CalibrationConfig m_Calibration;

SlimeVR::Configuration::MPU9250CalibrationConfig m_Calibration = {};

// outputs to respective member variables
void parseAccelData(int16_t data[3]);
Expand Down
Loading