* new helper: AutoDiscoverRTCClock, which detects: DS3231 (on i2c addr 0x68), or RV3028 (on i2c addr 0x52)

* repeater and room server: ver bump (v5), now use AutoDiscoverRTCClock
* various Board::begin() now should do Wire.begin(), with custom pin mappings if needed
* examples removed: ping client/server, and test_admin
This commit is contained in:
Scott Powell 2025-02-25 19:00:07 +11:00
parent c4cc3dd1ec
commit a6a6bef371
13 changed files with 155 additions and 755 deletions

View file

@ -0,0 +1,61 @@
#include "AutoDiscoverRTCClock.h"
#include "RTClib.h"
#include <Melopero_RV3028.h>
static RTC_DS3231 rtc_3231;
static bool ds3231_success = false;
static Melopero_RV3028 rtc_rv3028;
static bool rv3028_success = false;
#define DS3231_ADDRESS 0x68
#define RV3028_ADDRESS 0x52
bool AutoDiscoverRTCClock::i2c_probe(TwoWire& wire, uint8_t addr) {
wire.beginTransmission(addr);
uint8_t error = wire.endTransmission();
return (error == 0);
}
void AutoDiscoverRTCClock::begin(TwoWire& wire) {
if (i2c_probe(wire, DS3231_ADDRESS)) {
ds3231_success = rtc_3231.begin(&wire);
}
if (i2c_probe(wire, RV3028_ADDRESS)) {
rtc_rv3028.initI2C(wire);
rtc_rv3028.writeToRegister(0x35, 0x00);
rtc_rv3028.writeToRegister(0x37, 0xB4); // Direct Switching Mode (DSM): when VDD < VBACKUP, switchover occurs from VDD to VBACKUP
rtc_rv3028.set24HourMode(); // Set the device to use the 24hour format (default) instead of the 12 hour format
rv3028_success = true;
}
}
uint32_t AutoDiscoverRTCClock::getCurrentTime() {
if (ds3231_success) {
return rtc_3231.now().unixtime();
}
if (rv3028_success) {
return DateTime(
rtc_rv3028.getYear(),
rtc_rv3028.getMonth(),
rtc_rv3028.getDate(),
rtc_rv3028.getHour(),
rtc_rv3028.getMinute(),
rtc_rv3028.getSecond()
).unixtime();
}
return _fallback->getCurrentTime();
}
void AutoDiscoverRTCClock::setCurrentTime(uint32_t time) {
if (ds3231_success) {
rtc_3231.adjust(DateTime(time));
} else if (rv3028_success) {
auto dt = DateTime(time);
uint8_t weekday = (dt.day() + (uint16_t)((2.6 * dt.month()) - 0.2) - (2 * (dt.year() / 100)) + dt.year() + (uint16_t)(dt.year() / 4) + (uint16_t)(dt.year() / 400)) % 7;
rtc_rv3028.setTime(dt.year(), dt.month(), weekday, dt.day(), dt.hour(), dt.minute(), dt.second());
} else {
_fallback->setCurrentTime(time);
}
}

View file

@ -0,0 +1,17 @@
#pragma once
#include <Mesh.h>
#include <Arduino.h>
#include <Wire.h>
class AutoDiscoverRTCClock : public mesh::RTCClock {
mesh::RTCClock* _fallback;
bool i2c_probe(TwoWire& wire, uint8_t addr);
public:
AutoDiscoverRTCClock(mesh::RTCClock& fallback) : _fallback(&fallback) { }
void begin(TwoWire& wire);
uint32_t getCurrentTime() override;
void setCurrentTime(uint32_t time) override;
};

View file

@ -27,6 +27,12 @@ public:
pinMode(P_LORA_TX_LED, OUTPUT);
digitalWrite(P_LORA_TX_LED, LOW);
#endif
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
#else
Wire.begin();
#endif
}
uint8_t getStartupReason() const override { return startup_reason; }

View file

@ -20,6 +20,23 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason)
MESH_DEBUG_PRINTLN("BLE client disconnected");
}
void RAK4631Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
pinMode(PIN_VBAT_READ, INPUT);
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
#else
Wire.begin();
#endif
pinMode(SX126X_POWER_EN, OUTPUT);
digitalWrite(SX126X_POWER_EN, HIGH);
delay(10); // give sx1262 some time to power up
}
bool RAK4631Board::startOTAUpdate() {
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice

View file

@ -25,17 +25,7 @@ protected:
uint8_t startup_reason;
public:
void begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
pinMode(PIN_VBAT_READ, INPUT);
pinMode(SX126X_POWER_EN, OUTPUT);
digitalWrite(SX126X_POWER_EN, HIGH);
delay(10); // give sx1262 some time to power up
}
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#define BATTERY_SAMPLES 8

View file

@ -4,7 +4,23 @@
#include <bluefruit.h>
#include <Wire.h>
void T1000eBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
#else
Wire.begin();
#endif
// pinMode(PIN_VBAT_READ, INPUT);
// Doesn't seem to be a pwr en pin ...
// pinMode(LR1110_POWER_EN, OUTPUT);
// digitalWrite(LR1110_POWER_EN, HIGH);
delay(10); // give sx1262 some time to power up
}
#if 0
static BLEDfu bledfu;

View file

@ -25,17 +25,7 @@ protected:
uint8_t startup_reason;
public:
void begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
// pinMode(PIN_VBAT_READ, INPUT);
// Doesn't seem to be a pwr en pin ...
// pinMode(LR1110_POWER_EN, OUTPUT);
// digitalWrite(LR1110_POWER_EN, HIGH);
delay(10); // give sx1262 some time to power up
}
void begin();
uint16_t getBattMilliVolts() override {
return 0;