This commit is contained in:
commit
5dd6e7ac6a
3 files changed
+102
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
#include <HardwarePWM.h>
|
||||||
|
|
||||||
#include "SenseCapSolarBoard.h"
|
#include "SenseCapSolarBoard.h"
|
||||||
|
|
||||||
@@ -50,6 +51,9 @@ void SenseCapSolarBoard::begin() {
|
|||||||
#ifdef LED_WHITE
|
#ifdef LED_WHITE
|
||||||
pinMode(LED_WHITE, OUTPUT);
|
pinMode(LED_WHITE, OUTPUT);
|
||||||
digitalWrite(LED_WHITE, LOW);
|
digitalWrite(LED_WHITE, LOW);
|
||||||
|
#ifdef SENSECAP_SOLAR_WHITE_LED
|
||||||
|
white_led_last_pulse_at_ = millis(); // first heartbeat pulse 5 s after boot
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef LED_BLUE
|
#ifdef LED_BLUE
|
||||||
pinMode(LED_BLUE, OUTPUT);
|
pinMode(LED_BLUE, OUTPUT);
|
||||||
@@ -67,3 +71,76 @@ void SenseCapSolarBoard::begin() {
|
|||||||
|
|
||||||
delay(10); // give sx1262 some time to power up
|
delay(10); // give sx1262 some time to power up
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SENSECAP_SOLAR_WHITE_LED
|
||||||
|
// Dimmed WHITE heartbeat using hardware PWM (repeater builds only).
|
||||||
|
//
|
||||||
|
// Peripheral audit for this firmware: no analogWrite()/tone() callers, no
|
||||||
|
// NeoPixel/Servo, Bluefruit52Lib uses no PWM, SoftDevice S140 does not own
|
||||||
|
// any PWM instance -> NRF_PWM0 (HwPWM0) is free. takeOwnership() fences the
|
||||||
|
// instance so a future analogWrite() caller cannot claim it.
|
||||||
|
//
|
||||||
|
// Timing: base clock 16 MHz (DIV_1), COUNTERTOP 16000 -> exactly 1 kHz.
|
||||||
|
// Duty: HardwarePWM non-inverted values place bit15 (active-HIGH polarity),
|
||||||
|
// so compare 1600 => HIGH for [0,1600)/16000 => 10% duty, active-high.
|
||||||
|
static const uint32_t WHITE_LED_PWM_TOKEN = 0x5031574C; // 'P1WL'
|
||||||
|
static const uint16_t WHITE_LED_PWM_TOP = 16000; // 16 MHz / 16000 = 1 kHz
|
||||||
|
static const uint16_t WHITE_LED_PWM_DUTY = 1600; // 1600 / 16000 = 10 %
|
||||||
|
static_assert(WHITE_LED_PWM_TOP <= 0x7FFF, "PWM compare values are 15-bit");
|
||||||
|
static_assert(WHITE_LED_PWM_DUTY < WHITE_LED_PWM_TOP, "duty must stay below COUNTERTOP");
|
||||||
|
|
||||||
|
void SenseCapSolarBoard::whiteLedHeartbeatOn() {
|
||||||
|
HwPWM0.takeOwnership(WHITE_LED_PWM_TOKEN); // no-op once owned; keeps analogWrite away
|
||||||
|
HwPWM0.setClockDiv(PWM_PRESCALER_PRESCALER_DIV_1); // 16 MHz base clock
|
||||||
|
HwPWM0.setMaxValue(WHITE_LED_PWM_TOP); // 1 kHz period
|
||||||
|
HwPWM0.addPin(LED_WHITE); // drives pin LOW, connects PSEL
|
||||||
|
HwPWM0.writePin(LED_WHITE, WHITE_LED_PWM_DUTY); // enables + starts 10% PWM
|
||||||
|
}
|
||||||
|
|
||||||
|
void SenseCapSolarBoard::whiteLedHeartbeatOff() {
|
||||||
|
HwPWM0.stop(); // ENABLE=0: waveform and its HFCLK demand stop
|
||||||
|
if (HwPWM0.checkPin(LED_WHITE)) {
|
||||||
|
HwPWM0.removePin(LED_WHITE); // disconnect PSEL; GPIO block drives again
|
||||||
|
}
|
||||||
|
pinMode(LED_WHITE, OUTPUT);
|
||||||
|
digitalWrite(LED_WHITE, LOW); // deterministic LOW during the 4900 ms off phase
|
||||||
|
}
|
||||||
|
|
||||||
|
// 100 ms pulse every 5000 ms, non-blocking millis() with wrap-safe unsigned
|
||||||
|
// arithmetic. Called from loop(); frozen while the OTA steady-on owns the LED.
|
||||||
|
void SenseCapSolarBoard::updateWhiteStatusLed() {
|
||||||
|
if (white_led_ota_active_) return;
|
||||||
|
|
||||||
|
const uint32_t now = millis();
|
||||||
|
const uint32_t elapsed = (uint32_t)(now - white_led_last_pulse_at_);
|
||||||
|
if (white_led_pulse_active_ && elapsed >= 100U) {
|
||||||
|
whiteLedHeartbeatOff(); // stop PWM, pin LOW
|
||||||
|
white_led_pulse_active_ = false;
|
||||||
|
}
|
||||||
|
if (!white_led_pulse_active_ && elapsed >= 5000U) {
|
||||||
|
whiteLedHeartbeatOn(); // 1 kHz hardware PWM, 10% duty
|
||||||
|
white_led_pulse_active_ = true;
|
||||||
|
white_led_last_pulse_at_ = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SenseCapSolarBoard::loop() {
|
||||||
|
mesh::MainBoard::loop(); // keep base housekeeping (watchdog etc.) if it ever gains any
|
||||||
|
updateWhiteStatusLed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// `start ota` keeps WHITE on for as long as the application is advertising
|
||||||
|
// its BLE OTA service. The heartbeat PWM is stopped and the pin released
|
||||||
|
// first, so steady-on is a plain full-brightness GPIO drive (no PWM vs
|
||||||
|
// digitalWrite conflict). On a failed start nothing changes: the heartbeat
|
||||||
|
// keeps its normal blinking.
|
||||||
|
bool SenseCapSolarBoard::startOTAUpdate(const char *id, char reply[]) {
|
||||||
|
const bool started = NRF52Board::startOTAUpdate(id, reply);
|
||||||
|
if (started) {
|
||||||
|
white_led_ota_active_ = true;
|
||||||
|
whiteLedHeartbeatOff();
|
||||||
|
digitalWrite(LED_WHITE, LED_STATE_ON);
|
||||||
|
}
|
||||||
|
return started;
|
||||||
|
}
|
||||||
|
#endif // SENSECAP_SOLAR_WHITE_LED
|
||||||
@@ -5,6 +5,19 @@
|
|||||||
#include <helpers/NRF52Board.h>
|
#include <helpers/NRF52Board.h>
|
||||||
|
|
||||||
class SenseCapSolarBoard : public NRF52BoardDCDC {
|
class SenseCapSolarBoard : public NRF52BoardDCDC {
|
||||||
|
#ifdef SENSECAP_SOLAR_WHITE_LED
|
||||||
|
// Dimmed white-LED heartbeat state (repeater builds only; enabled with
|
||||||
|
// -D SENSECAP_SOLAR_WHITE_LED in the PlatformIO env, so room-server and
|
||||||
|
// companion firmwares sharing this board class are unaffected).
|
||||||
|
bool white_led_ota_active_ = false;
|
||||||
|
bool white_led_pulse_active_ = false;
|
||||||
|
uint32_t white_led_last_pulse_at_ = 0;
|
||||||
|
|
||||||
|
void whiteLedHeartbeatOn(); // start 1 kHz PWM at 10% duty on LED_WHITE
|
||||||
|
void whiteLedHeartbeatOff(); // stop/release PWM, hold LED_WHITE LOW
|
||||||
|
void updateWhiteStatusLed(); // non-blocking 100 ms pulse every 5000 ms
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef NRF52_POWER_MANAGEMENT
|
#ifdef NRF52_POWER_MANAGEMENT
|
||||||
void initiateShutdown(uint8_t reason) override;
|
void initiateShutdown(uint8_t reason) override;
|
||||||
@@ -14,6 +27,13 @@ public:
|
|||||||
SenseCapSolarBoard() : NRF52Board("SENSECAP_SOLAR_OTA") {}
|
SenseCapSolarBoard() : NRF52Board("SENSECAP_SOLAR_OTA") {}
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
|
#ifdef SENSECAP_SOLAR_WHITE_LED
|
||||||
|
// Runs the white-LED heartbeat; invoked by the example main loops via the
|
||||||
|
// existing board.loop() call (mesh::MainBoard::loop() is a no-op by default).
|
||||||
|
void loop() override;
|
||||||
|
bool startOTAUpdate(const char *id, char reply[]) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(P_LORA_TX_LED)
|
#if defined(P_LORA_TX_LED)
|
||||||
void onBeforeTransmit() override {
|
void onBeforeTransmit() override {
|
||||||
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
|
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
|
||||||
@@ -38,6 +58,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void powerOff() override {
|
void powerOff() override {
|
||||||
|
#ifdef SENSECAP_SOLAR_WHITE_LED
|
||||||
|
whiteLedHeartbeatOff(); // stop/release the heartbeat PWM before shutdown
|
||||||
|
#endif
|
||||||
digitalWrite(LED_WHITE, LOW);
|
digitalWrite(LED_WHITE, LOW);
|
||||||
digitalWrite(LED_BLUE, LOW);
|
digitalWrite(LED_BLUE, LOW);
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ build_flags =
|
|||||||
-D ADVERT_LON=0.0
|
-D ADVERT_LON=0.0
|
||||||
-D ADMIN_PASSWORD='"password"'
|
-D ADMIN_PASSWORD='"password"'
|
||||||
-D MAX_NEIGHBOURS=50
|
-D MAX_NEIGHBOURS=50
|
||||||
|
; dimmed white-LED heartbeat + OTA steady-on (repeater builds only)
|
||||||
|
-D SENSECAP_SOLAR_WHITE_LED=1
|
||||||
; -D MESH_PACKET_LOGGING=1
|
; -D MESH_PACKET_LOGGING=1
|
||||||
; -D MESH_DEBUG=1
|
; -D MESH_DEBUG=1
|
||||||
build_src_filter = ${SenseCap_Solar.build_src_filter}
|
build_src_filter = ${SenseCap_Solar.build_src_filter}
|
||||||
|
|||||||
Reference in new issue
Block a user