Merge pull request 'Repeater, room server, sensor, companion: nRF52 no longer stays at +2.6 mA after boot (CC310 IRQ), plus sleep/peripheral fixes' (#28) from feat/powersave-audit into main
This commit is contained in:
commit
ec3b71daa9
9 files changed
+154
-9
No files matched your search
@@ -288,10 +288,7 @@ void NRF52Board::pwrmgtWakeArmVbus() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void NRF52BoardDCDC::begin() {
|
||||
NRF52Board::begin();
|
||||
|
||||
// Enable DC/DC converter for improved power efficiency
|
||||
static void enableNrf52Dcdc() {
|
||||
uint8_t sd_enabled = 0;
|
||||
sd_softdevice_is_enabled(&sd_enabled);
|
||||
if (sd_enabled) {
|
||||
@@ -301,6 +298,22 @@ void NRF52BoardDCDC::begin() {
|
||||
}
|
||||
}
|
||||
|
||||
void NRF52BoardDCDC::begin() {
|
||||
NRF52Board::begin();
|
||||
|
||||
// Enable DC/DC converter for improved power efficiency
|
||||
enableNrf52Dcdc();
|
||||
}
|
||||
|
||||
void NRF52BoardDCDC::onBootComplete() {
|
||||
NRF52Board::onBootComplete();
|
||||
|
||||
// SoftDevice (Bluefruit.begin()) starts after board.begin(). On XIAO x4
|
||||
// (11/2026) DCDCEN read 1 after boot with or without this call, so it is a
|
||||
// safeguard in case a SoftDevice/board combination resets NRF_POWER to LDO.
|
||||
enableNrf52Dcdc();
|
||||
}
|
||||
|
||||
bool NRF52Board::isExternalPowered() {
|
||||
// Check if SoftDevice is enabled before using its API
|
||||
uint8_t sd_enabled = 0;
|
||||
@@ -324,6 +337,14 @@ void NRF52Board::sleep(uint32_t secs) {
|
||||
NVIC_ClearPendingIRQ(FPU_IRQn);
|
||||
#endif
|
||||
|
||||
// Clear pending CRYPTOCELL interrupt to avoid WFE/sd_app_evt_wait() insomnia.
|
||||
// Adafruit_nRFCrypto polls CC310 with CRYPTOCELL_IRQn disabled in NVIC, so
|
||||
// completed crypto/TRNG calls leave it pending (same workaround as Adafruit
|
||||
// core wiring.c / port_cmsis_systick.c).
|
||||
#ifdef NRF_CRYPTOCELL
|
||||
NVIC_ClearPendingIRQ(CRYPTOCELL_IRQn);
|
||||
#endif
|
||||
|
||||
// On nRF52, we use event-driven sleep instead of timed sleep
|
||||
// The 'secs' parameter is ignored - we wake on any interrupt
|
||||
uint8_t sd_enabled = 0;
|
||||
|
||||
@@ -93,5 +93,6 @@ class NRF52BoardDCDC : virtual public NRF52Board {
|
||||
public:
|
||||
NRF52BoardDCDC() {}
|
||||
virtual void begin() override;
|
||||
virtual void onBootComplete() override;
|
||||
};
|
||||
#endif
|
||||
@@ -8,6 +8,10 @@
|
||||
#define TELEM_WIRE &Wire // Use default I2C bus for Environment Sensors
|
||||
#endif
|
||||
|
||||
#ifdef NRF52_PLATFORM
|
||||
static bool telem_wire_stopped = false;
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// Sensor library includes and static driver instances
|
||||
// ============================================================
|
||||
@@ -715,6 +719,11 @@ bool EnvironmentSensorManager::begin() {
|
||||
bool detected[128] = {};
|
||||
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.
|
||||
_active_sensor_count = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
#ifdef NRF52_PLATFORM
|
||||
bool restarted = telem_wire_stopped;
|
||||
if (restarted) {
|
||||
(TELEM_WIRE)->begin();
|
||||
telem_wire_stopped = false;
|
||||
}
|
||||
#endif
|
||||
bool found[128] = {};
|
||||
scanI2CBus(TELEM_WIRE, found);
|
||||
|
||||
@@ -790,6 +815,13 @@ int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) {
|
||||
n++;
|
||||
}
|
||||
|
||||
#ifdef NRF52_PLATFORM
|
||||
if (restarted && n == 0) {
|
||||
(TELEM_WIRE)->end();
|
||||
telem_wire_stopped = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (n == 0) {
|
||||
used = appendWhole(dest, 0, max_len, "no I2C device answered");
|
||||
}
|
||||
|
||||
@@ -204,7 +204,13 @@ class NmeaGpsDriver : public GpsDriver {
|
||||
// core's own Uart::end()) for all the hours `gps duty` keeps the GPS off, and
|
||||
// its idle-high TX line feeds the unpowered module. sendNmeaSentence() is
|
||||
// gated on _started: a write to a closed Uart takes a deleted semaphore.
|
||||
if (_hardwareSerial != nullptr) _hardwareSerial->end();
|
||||
// Uart::end() clears PSEL but leaves GPIO PIN_CNF unchanged, so disconnect
|
||||
// the pins explicitly to avoid back-powering the unpowered GPS module.
|
||||
if (_hardwareSerial != nullptr) {
|
||||
_hardwareSerial->end();
|
||||
if (_txPin != -1) nrf_gpio_cfg_default(g_ADigitalPinMap[_txPin]);
|
||||
if (_rxPin != -1) nrf_gpio_cfg_default(g_ADigitalPinMap[_rxPin]);
|
||||
}
|
||||
#endif
|
||||
_started = false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user