mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-06 11:39:32 +00:00
Remove unused I2C speed functions and cleanup
* Cleanup of SEN5X specific code added from switching branches * Remove SCAN_I2C_CLOCK_SPEED block as its not needed * Remove associated functions for setting I2C speed
This commit is contained in:
parent
b23605aba0
commit
a129441533
@ -109,75 +109,6 @@ uint16_t ScanI2CTwoWire::getRegisterValue(const ScanI2CTwoWire::RegisterLocation
|
||||
return value;
|
||||
}
|
||||
|
||||
bool ScanI2CTwoWire::setClockSpeed(I2CPort port, uint32_t speed) {
|
||||
|
||||
DeviceAddress addr(port, 0x00);
|
||||
TwoWire *i2cBus;
|
||||
|
||||
#if WIRE_INTERFACES_COUNT == 2
|
||||
if (port == I2CPort::WIRE1) {
|
||||
i2cBus = &Wire1;
|
||||
} else {
|
||||
#endif
|
||||
i2cBus = &Wire;
|
||||
#if WIRE_INTERFACES_COUNT == 2
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2cBus->setClock(speed);
|
||||
}
|
||||
|
||||
uint32_t ScanI2CTwoWire::getClockSpeed(I2CPort port) {
|
||||
|
||||
DeviceAddress addr(port, 0x00);
|
||||
TwoWire *i2cBus;
|
||||
|
||||
#if WIRE_INTERFACES_COUNT == 2
|
||||
if (port == I2CPort::WIRE1) {
|
||||
i2cBus = &Wire1;
|
||||
} else {
|
||||
#endif
|
||||
i2cBus = &Wire;
|
||||
#if WIRE_INTERFACES_COUNT == 2
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2cBus->getClock();
|
||||
}
|
||||
|
||||
/// for SEN5X detection
|
||||
String readSEN5xProductName(TwoWire* i2cBus, uint8_t address) {
|
||||
uint8_t cmd[] = { 0xD0, 0x14 };
|
||||
uint8_t response[48] = {0};
|
||||
|
||||
i2cBus->beginTransmission(address);
|
||||
i2cBus->write(cmd, 2);
|
||||
if (i2cBus->endTransmission() != 0) return "";
|
||||
|
||||
delay(20);
|
||||
if (i2cBus->requestFrom(address, (uint8_t)48) != 48) return "";
|
||||
|
||||
for (int i = 0; i < 48 && i2cBus->available(); ++i) {
|
||||
response[i] = i2cBus->read();
|
||||
}
|
||||
|
||||
char productName[33] = {0};
|
||||
int j = 0;
|
||||
for (int i = 0; i < 48 && j < 32; i += 3) {
|
||||
if (response[i] >= 32 && response[i] <= 126)
|
||||
productName[j++] = response[i];
|
||||
else
|
||||
break;
|
||||
|
||||
if (response[i + 1] >= 32 && response[i + 1] <= 126)
|
||||
productName[j++] = response[i + 1];
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return String(productName);
|
||||
}
|
||||
|
||||
#define SCAN_SIMPLE_CASE(ADDR, T, ...) \
|
||||
case ADDR: \
|
||||
logFoundDevice(__VA_ARGS__); \
|
||||
|
@ -29,9 +29,6 @@ class ScanI2CTwoWire : public ScanI2C
|
||||
|
||||
size_t countDevices() const override;
|
||||
|
||||
bool setClockSpeed(ScanI2C::I2CPort, uint32_t);
|
||||
uint32_t getClockSpeed(ScanI2C::I2CPort);
|
||||
|
||||
protected:
|
||||
FoundDevice firstOfOrNONE(size_t, DeviceType[]) const override;
|
||||
|
||||
|
33
src/main.cpp
33
src/main.cpp
@ -524,39 +524,6 @@ void setup()
|
||||
LOG_INFO("Scan for i2c devices");
|
||||
#endif
|
||||
|
||||
// Scan I2C port at desired speed
|
||||
#ifdef SCAN_I2C_CLOCK_SPEED
|
||||
uint32_t currentClock;
|
||||
currentClock = i2cScanner->getClockSpeed(ScanI2C::I2CPort::WIRE);
|
||||
LOG_INFO("Clock speed: %uHz on WIRE", currentClock);
|
||||
LOG_DEBUG("Setting Wire with defined clock speed, %uHz...", SCAN_I2C_CLOCK_SPEED);
|
||||
|
||||
if(!i2cScanner->setClockSpeed(ScanI2C::I2CPort::WIRE, SCAN_I2C_CLOCK_SPEED)) {
|
||||
LOG_ERROR("Unable to set clock speed on WIRE");
|
||||
} else {
|
||||
currentClock = i2cScanner->getClockSpeed(ScanI2C::I2CPort::WIRE);
|
||||
LOG_INFO("Set clock speed: %uHz on WIRE", currentClock);
|
||||
}
|
||||
|
||||
// TODO Check if necessary
|
||||
// LOG_DEBUG("Starting Wire with defined clock speed, %d...", SCAN_I2C_CLOCK_SPEED);
|
||||
// if(!i2cScanner->setClockSpeed(ScanI2C::I2CPort::WIRE1, SCAN_I2C_CLOCK_SPEED)) {
|
||||
// LOG_ERROR("Unable to set clock speed on WIRE1");
|
||||
// } else {
|
||||
// LOG_INFO("Set clock speed: %d on WIRE1", SCAN_I2C_CLOCK_SPEED);
|
||||
// }
|
||||
|
||||
// Restore clock speed
|
||||
if (currentClock != SCAN_I2C_CLOCK_SPEED) {
|
||||
if(!i2cScanner->setClockSpeed(ScanI2C::I2CPort::WIRE, currentClock)) {
|
||||
LOG_ERROR("Unable to restore clock speed on WIRE");
|
||||
} else {
|
||||
currentClock = i2cScanner->getClockSpeed(ScanI2C::I2CPort::WIRE);
|
||||
LOG_INFO("Set clock speed restored to: %uHz on WIRE", currentClock);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(I2C_SDA1) || (defined(NRF52840_XXAA) && (WIRE_INTERFACES_COUNT == 2))
|
||||
i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1);
|
||||
#endif
|
||||
|
@ -56,9 +56,11 @@ int32_t PMSA003ISensor::runOnce()
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
|
||||
#ifdef PMSA003I_I2C_CLOCK_SPEED
|
||||
restoreClock(currentClock);
|
||||
#endif
|
||||
|
||||
status = 1;
|
||||
status = 1;
|
||||
LOG_INFO("PMSA003I Enabled");
|
||||
|
||||
return initI2CSensor();
|
||||
@ -86,7 +88,9 @@ bool PMSA003ISensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef PMSA003I_I2C_CLOCK_SPEED
|
||||
restoreClock(currentClock);
|
||||
#endif
|
||||
|
||||
for (uint8_t i = 0; i < PMSA003I_FRAME_LENGTH; i++) {
|
||||
buffer[i] = bus->read();
|
||||
@ -136,19 +140,19 @@ bool PMSA003ISensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
|
||||
measurement->variant.air_quality_metrics.has_particles_05um = true;
|
||||
measurement->variant.air_quality_metrics.particles_05um = read16(buffer, 18);
|
||||
|
||||
|
||||
measurement->variant.air_quality_metrics.has_particles_10um = true;
|
||||
measurement->variant.air_quality_metrics.particles_10um = read16(buffer, 20);
|
||||
|
||||
|
||||
measurement->variant.air_quality_metrics.has_particles_25um = true;
|
||||
measurement->variant.air_quality_metrics.particles_25um = read16(buffer, 22);
|
||||
|
||||
|
||||
measurement->variant.air_quality_metrics.has_particles_50um = true;
|
||||
measurement->variant.air_quality_metrics.particles_50um = read16(buffer, 24);
|
||||
|
||||
|
||||
measurement->variant.air_quality_metrics.has_particles_100um = true;
|
||||
measurement->variant.air_quality_metrics.particles_100um = read16(buffer, 26);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define PMSA003I_FRAME_LENGTH 32
|
||||
#define PMSA003I_WARMUP_MS 30000
|
||||
|
||||
|
||||
class PMSA003ISensor : public TelemetrySensor
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user