Repeater, room server, sensor, companion: disable unused I2C on nRF52 and calibrate noise floor every 10 s
This commit is contained in:
1 parent
a5bdc6db81
commit
76bf7afa11
3 files changed
+38
-1
No files matched your search
@@ -240,6 +240,11 @@ unnecessary idle draw that affect all nRF52 boards (not only SenseCAP Solar):
|
|||||||
- **Disconnect GPS UART pins while GPS is off**: `NmeaGpsDriver::stopHardware()`
|
- **Disconnect GPS UART pins while GPS is off**: `NmeaGpsDriver::stopHardware()`
|
||||||
now resets the UART TX/RX pins via `nrf_gpio_cfg_default()` after `Uart::end()`,
|
now resets the UART TX/RX pins via `nrf_gpio_cfg_default()` after `Uart::end()`,
|
||||||
preventing back-powering of the unpowered GPS receiver through GPIO/ESD paths.
|
preventing back-powering of the unpowered GPS receiver through GPIO/ESD paths.
|
||||||
|
- **Disable unused I2C bus & lower noise-floor calibration rate**: on nRF52,
|
||||||
|
`EnvironmentSensorManager::begin()` calls `Wire.end()` when the I2C bus scan
|
||||||
|
finds zero devices (re-enabling temporarily for the `i2c` CLI command).
|
||||||
|
`NOISE_FLOOR_CALIB_INTERVAL` is raised from 2 s to 10 s to cut idle SPI
|
||||||
|
wake-ups 5x.
|
||||||
|
|
||||||
## Measuring this yourself — two traps
|
## Measuring this yourself — two traps
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ namespace mesh {
|
|||||||
#define MIN_TX_BUDGET_AIRTIME_DIV 2 // require at least 1/N of estimated airtime as budget before TX
|
#define MIN_TX_BUDGET_AIRTIME_DIV 2 // require at least 1/N of estimated airtime as budget before TX
|
||||||
|
|
||||||
#ifndef NOISE_FLOOR_CALIB_INTERVAL
|
#ifndef NOISE_FLOOR_CALIB_INTERVAL
|
||||||
#define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds
|
#define NOISE_FLOOR_CALIB_INTERVAL 10000 // 10 seconds
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Dispatcher::begin() {
|
void Dispatcher::begin() {
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
#define TELEM_WIRE &Wire // Use default I2C bus for Environment Sensors
|
#define TELEM_WIRE &Wire // Use default I2C bus for Environment Sensors
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef NRF52_PLATFORM
|
||||||
|
static bool telem_wire_stopped = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Sensor library includes and static driver instances
|
// Sensor library includes and static driver instances
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@@ -715,6 +719,11 @@ bool EnvironmentSensorManager::begin() {
|
|||||||
bool detected[128] = {};
|
bool detected[128] = {};
|
||||||
scanI2CBus(TELEM_WIRE, detected);
|
scanI2CBus(TELEM_WIRE, detected);
|
||||||
|
|
||||||
|
bool any_i2c_device = false;
|
||||||
|
for (uint8_t addr = 0x08; addr < 0x78; addr++) {
|
||||||
|
if (detected[addr]) { any_i2c_device = true; break; }
|
||||||
|
}
|
||||||
|
|
||||||
// Walk the sensor table and initialize only detected devices.
|
// Walk the sensor table and initialize only detected devices.
|
||||||
_active_sensor_count = 0;
|
_active_sensor_count = 0;
|
||||||
for (size_t i = 0; i < SENSOR_TABLE_SIZE && _active_sensor_count < MAX_ACTIVE_SENSORS; i++) {
|
for (size_t i = 0; i < SENSOR_TABLE_SIZE && _active_sensor_count < MAX_ACTIVE_SENSORS; i++) {
|
||||||
@@ -741,6 +750,15 @@ bool EnvironmentSensorManager::begin() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NRF52_PLATFORM
|
||||||
|
if (!any_i2c_device) {
|
||||||
|
// No device ACKed anywhere on the bus (neither sensor nor RTC/display):
|
||||||
|
// disable TWIM to avoid idle peripheral/pull-up draw.
|
||||||
|
(TELEM_WIRE)->end();
|
||||||
|
telem_wire_stopped = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,6 +783,13 @@ static size_t appendWhole(char* dest, size_t used, size_t max_len, const char* s
|
|||||||
}
|
}
|
||||||
|
|
||||||
int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) {
|
int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) {
|
||||||
|
#ifdef NRF52_PLATFORM
|
||||||
|
bool restarted = telem_wire_stopped;
|
||||||
|
if (restarted) {
|
||||||
|
(TELEM_WIRE)->begin();
|
||||||
|
telem_wire_stopped = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
bool found[128] = {};
|
bool found[128] = {};
|
||||||
scanI2CBus(TELEM_WIRE, found);
|
scanI2CBus(TELEM_WIRE, found);
|
||||||
|
|
||||||
@@ -790,6 +815,13 @@ int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) {
|
|||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NRF52_PLATFORM
|
||||||
|
if (restarted && n == 0) {
|
||||||
|
(TELEM_WIRE)->end();
|
||||||
|
telem_wire_stopped = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
used = appendWhole(dest, 0, max_len, "no I2C device answered");
|
used = appendWhole(dest, 0, max_len, "no I2C device answered");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user