2021-06-27 10:56:28 -07:00
|
|
|
#include "configuration.h"
|
2023-12-27 14:26:40 -06:00
|
|
|
#include <Adafruit_TinyUSB.h>
|
2023-01-21 14:34:29 +01:00
|
|
|
#include <Adafruit_nRFCrypto.h>
|
2025-01-20 09:43:35 -08:00
|
|
|
#include <InternalFileSystem.h>
|
2020-11-13 09:33:59 +08:00
|
|
|
#include <SPI.h>
|
|
|
|
|
#include <Wire.h>
|
2020-04-23 12:47:41 -07:00
|
|
|
#include <assert.h>
|
2020-04-23 16:55:25 -07:00
|
|
|
#include <ble_gap.h>
|
|
|
|
|
#include <memory.h>
|
2020-07-17 09:14:23 -07:00
|
|
|
#include <stdio.h>
|
2021-08-12 22:07:18 -07:00
|
|
|
// #include <Adafruit_USBD_Device.h>
|
2022-08-22 16:41:23 -05:00
|
|
|
#include "NodeDB.h"
|
2024-08-06 10:35:54 -07:00
|
|
|
#include "PowerMon.h"
|
2021-03-17 10:44:42 -07:00
|
|
|
#include "error.h"
|
2023-02-03 08:50:10 -06:00
|
|
|
#include "main.h"
|
2024-09-25 13:50:00 -05:00
|
|
|
#include "meshUtils.h"
|
2021-03-17 10:44:42 -07:00
|
|
|
|
|
|
|
|
#ifdef BQ25703A_ADDR
|
|
|
|
|
#include "BQ25713.h"
|
2020-07-09 21:27:34 -07:00
|
|
|
#endif
|
2020-04-23 16:55:25 -07:00
|
|
|
|
2021-04-11 13:52:39 +08:00
|
|
|
static inline void debugger_break(void)
|
|
|
|
|
{
|
|
|
|
|
__asm volatile("bkpt #0x01\n\t"
|
|
|
|
|
"mov pc, lr\n\t");
|
2020-04-23 12:47:41 -07:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 14:34:29 +01:00
|
|
|
bool loopCanSleep()
|
|
|
|
|
{
|
2021-08-12 15:50:54 -07:00
|
|
|
// turn off sleep only while connected via USB
|
2021-08-12 22:07:18 -07:00
|
|
|
// return true;
|
|
|
|
|
return !Serial; // the bool operator on the nrf52 serial class returns true if connected to a PC currently
|
|
|
|
|
// return !(TinyUSBDevice.mounted() && !TinyUSBDevice.suspended());
|
2021-04-28 15:11:55 +08:00
|
|
|
}
|
|
|
|
|
|
2020-04-23 12:47:41 -07:00
|
|
|
// handle standard gcc assert failures
|
2021-04-11 13:52:39 +08:00
|
|
|
void __attribute__((noreturn)) __assert_func(const char *file, int line, const char *func, const char *failedexpr)
|
|
|
|
|
{
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_ERROR("assert failed %s: %d, %s, test=%s", file, line, func, failedexpr);
|
2021-04-11 13:52:39 +08:00
|
|
|
// debugger_break(); FIXME doesn't work, possibly not for segger
|
2022-04-26 06:49:05 -05:00
|
|
|
// Reboot cpu
|
|
|
|
|
NVIC_SystemReset();
|
2020-04-23 16:55:25 -07:00
|
|
|
}
|
|
|
|
|
|
2021-04-11 13:52:39 +08:00
|
|
|
void getMacAddr(uint8_t *dmac)
|
|
|
|
|
{
|
2021-12-28 11:20:45 -06:00
|
|
|
const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR;
|
|
|
|
|
dmac[5] = src[0];
|
|
|
|
|
dmac[4] = src[1];
|
|
|
|
|
dmac[3] = src[2];
|
|
|
|
|
dmac[2] = src[3];
|
|
|
|
|
dmac[1] = src[4];
|
|
|
|
|
dmac[0] = src[5] | 0xc0; // MSB high two bits get set elsewhere in the bluetooth stack
|
2020-04-23 18:02:28 -07:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 13:25:55 +08:00
|
|
|
static void initBrownout()
|
|
|
|
|
{
|
2023-12-16 06:57:01 -06:00
|
|
|
auto vccthresh = POWER_POFCON_THRESHOLD_V24;
|
2021-04-12 13:25:55 +08:00
|
|
|
|
|
|
|
|
auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled);
|
|
|
|
|
assert(err_code == NRF_SUCCESS);
|
|
|
|
|
|
|
|
|
|
err_code = sd_power_pof_threshold_set(vccthresh);
|
|
|
|
|
assert(err_code == NRF_SUCCESS);
|
|
|
|
|
|
|
|
|
|
// We don't bother with setting up brownout if soft device is disabled - because during production we always use softdevice
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-28 04:48:55 -07:00
|
|
|
// This is a public global so that the debugger can set it to false automatically from our gdbinit
|
|
|
|
|
bool useSoftDevice = true; // Set to false for easier debugging
|
2021-04-11 13:52:39 +08:00
|
|
|
|
2024-03-25 05:33:57 -06:00
|
|
|
#if !MESHTASTIC_EXCLUDE_BLUETOOTH
|
2024-03-03 13:56:55 -06:00
|
|
|
void setBluetoothEnable(bool enable)
|
2021-04-11 13:52:39 +08:00
|
|
|
{
|
2024-06-12 23:34:00 +12:00
|
|
|
// For debugging use: don't use bluetooth
|
|
|
|
|
if (!useSoftDevice) {
|
|
|
|
|
if (enable)
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_INFO("Disable NRF52 BLUETOOTH WHILE DEBUGGING");
|
2024-06-12 23:34:00 +12:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If user disabled bluetooth: init then disable advertising & reduce power
|
|
|
|
|
// Workaround. Avoid issue where device hangs several days after boot..
|
|
|
|
|
// Allegedly, no significant increase in power consumption
|
|
|
|
|
if (!config.bluetooth.enabled) {
|
|
|
|
|
static bool initialized = false;
|
|
|
|
|
if (!initialized) {
|
|
|
|
|
nrf52Bluetooth = new NRF52Bluetooth();
|
|
|
|
|
nrf52Bluetooth->startDisabled();
|
|
|
|
|
initBrownout();
|
|
|
|
|
initialized = true;
|
2024-03-03 13:56:55 -06:00
|
|
|
}
|
2024-06-12 23:34:00 +12:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (enable) {
|
2024-08-06 10:35:54 -07:00
|
|
|
powerMon->setState(meshtastic_PowerMon_State_BT_On);
|
|
|
|
|
|
2024-06-12 23:34:00 +12:00
|
|
|
// If not yet set-up
|
|
|
|
|
if (!nrf52Bluetooth) {
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_DEBUG("Init NRF52 Bluetooth");
|
2024-06-12 23:34:00 +12:00
|
|
|
nrf52Bluetooth = new NRF52Bluetooth();
|
|
|
|
|
nrf52Bluetooth->setup();
|
|
|
|
|
|
|
|
|
|
// We delay brownout init until after BLE because BLE starts soft device
|
|
|
|
|
initBrownout();
|
2020-04-23 18:02:28 -07:00
|
|
|
}
|
2024-06-12 23:34:00 +12:00
|
|
|
// Already setup, apparently
|
|
|
|
|
else
|
|
|
|
|
nrf52Bluetooth->resumeAdvertising();
|
2020-04-23 18:02:28 -07:00
|
|
|
}
|
2024-06-12 23:34:00 +12:00
|
|
|
// Disable (if previously set-up)
|
2024-08-06 10:35:54 -07:00
|
|
|
else if (nrf52Bluetooth) {
|
|
|
|
|
powerMon->clearState(meshtastic_PowerMon_State_BT_On);
|
2024-06-12 23:34:00 +12:00
|
|
|
nrf52Bluetooth->shutdown();
|
2024-08-06 10:35:54 -07:00
|
|
|
}
|
2020-04-23 18:02:28 -07:00
|
|
|
}
|
2024-03-25 05:33:57 -06:00
|
|
|
#else
|
2024-06-12 23:34:00 +12:00
|
|
|
#warning NRF52 "Bluetooth disable" workaround does not apply to builds with MESHTASTIC_EXCLUDE_BLUETOOTH
|
2024-03-25 05:33:57 -06:00
|
|
|
void setBluetoothEnable(bool enable) {}
|
|
|
|
|
#endif
|
2020-07-17 09:14:23 -07:00
|
|
|
/**
|
2021-08-12 22:07:18 -07:00
|
|
|
* Override printf to use the SEGGER output library (note - this does not effect the printf method on the debug console)
|
2020-07-17 09:14:23 -07:00
|
|
|
*/
|
2021-04-11 13:52:39 +08:00
|
|
|
int printf(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
auto res = SEGGER_RTT_vprintf(0, fmt, &args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
return res;
|
2020-07-17 09:14:23 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-20 09:43:35 -08:00
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
constexpr uint8_t NRF52_MAGIC_LFS_IS_CORRUPT = 0xF5;
|
|
|
|
|
constexpr uint32_t MULTIPLE_CORRUPTION_DELAY_MILLIS = 20 * 60 * 1000;
|
|
|
|
|
static unsigned long millis_until_formatting_again = 0;
|
|
|
|
|
|
|
|
|
|
// Report the critical error from loop(), giving a chance for the screen to be initialized first.
|
|
|
|
|
inline void reportLittleFSCorruptionOnce()
|
|
|
|
|
{
|
|
|
|
|
static bool report_corruption = !!millis_until_formatting_again;
|
|
|
|
|
if (report_corruption) {
|
|
|
|
|
report_corruption = false;
|
|
|
|
|
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_FLASH_CORRUPTION_UNRECOVERABLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
void preFSBegin()
|
|
|
|
|
{
|
|
|
|
|
// The GPREGRET register keeps its value across warm boots. Check that this is a warm boot and, if GPREGRET
|
|
|
|
|
// is set to NRF52_MAGIC_LFS_IS_CORRUPT, format LittleFS.
|
|
|
|
|
if (!(NRF_POWER->RESETREAS == 0 && NRF_POWER->GPREGRET == NRF52_MAGIC_LFS_IS_CORRUPT))
|
|
|
|
|
return;
|
|
|
|
|
NRF_POWER->GPREGRET = 0;
|
|
|
|
|
millis_until_formatting_again = millis() + MULTIPLE_CORRUPTION_DELAY_MILLIS;
|
|
|
|
|
InternalFS.format();
|
|
|
|
|
LOG_INFO("LittleFS format complete; restoring default settings");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void lfs_assert(const char *reason)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("LittleFS corruption detected: %s", reason);
|
|
|
|
|
if (millis_until_formatting_again > millis()) {
|
|
|
|
|
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_FLASH_CORRUPTION_UNRECOVERABLE);
|
|
|
|
|
const long millis_remain = millis_until_formatting_again - millis();
|
|
|
|
|
LOG_WARN("Pausing %d seconds to avoid wear on flash storage", millis_remain / 1000);
|
|
|
|
|
delay(millis_remain);
|
|
|
|
|
}
|
|
|
|
|
LOG_INFO("Rebooting to format LittleFS");
|
|
|
|
|
delay(500); // Give the serial port a bit of time to output that last message.
|
|
|
|
|
// Try setting GPREGRET with the SoftDevice first. If that fails (perhaps because the SD hasn't been initialize yet) then set
|
|
|
|
|
// NRF_POWER->GPREGRET directly.
|
|
|
|
|
if (!(sd_power_gpregret_clr(0, 0xFF) == NRF_SUCCESS && sd_power_gpregret_set(0, NRF52_MAGIC_LFS_IS_CORRUPT) == NRF_SUCCESS)) {
|
|
|
|
|
NRF_POWER->GPREGRET = NRF52_MAGIC_LFS_IS_CORRUPT;
|
|
|
|
|
}
|
|
|
|
|
NVIC_SystemReset();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 13:52:39 +08:00
|
|
|
void checkSDEvents()
|
|
|
|
|
{
|
|
|
|
|
if (useSoftDevice) {
|
|
|
|
|
uint32_t evt;
|
|
|
|
|
while (NRF_SUCCESS == sd_evt_get(&evt)) {
|
|
|
|
|
switch (evt) {
|
|
|
|
|
case NRF_EVT_POWER_FAILURE_WARNING:
|
2023-01-21 18:22:19 +01:00
|
|
|
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_BROWNOUT);
|
2021-04-11 13:52:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Unexpected SDevt %d", evt);
|
2021-04-11 13:52:39 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (NRF_POWER->EVENTS_POFWARN)
|
2023-01-21 18:22:19 +01:00
|
|
|
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_BROWNOUT);
|
2021-03-08 18:12:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 13:52:39 +08:00
|
|
|
void nrf52Loop()
|
|
|
|
|
{
|
|
|
|
|
checkSDEvents();
|
2025-01-20 09:43:35 -08:00
|
|
|
reportLittleFSCorruptionOnce();
|
2021-04-11 13:52:39 +08:00
|
|
|
}
|
2020-05-24 16:20:21 -07:00
|
|
|
|
2024-06-24 08:27:37 -07:00
|
|
|
#ifdef USE_SEMIHOSTING
|
|
|
|
|
#include <SemihostingStream.h>
|
2024-09-25 13:50:00 -05:00
|
|
|
#include <meshUtils.h>
|
2024-06-24 08:27:37 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Note: this variable is in BSS and therfore false by default. But the gdbinit
|
|
|
|
|
* file will be installing a temporary breakpoint that changes wantSemihost to true.
|
|
|
|
|
*/
|
|
|
|
|
bool wantSemihost;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Turn on semihosting if the ICE debugger wants it.
|
|
|
|
|
*/
|
|
|
|
|
void nrf52InitSemiHosting()
|
|
|
|
|
{
|
|
|
|
|
if (wantSemihost) {
|
|
|
|
|
static SemihostingStream semiStream;
|
|
|
|
|
// We must dynamically alloc because the constructor does semihost operations which
|
|
|
|
|
// would crash any load not talking to a debugger
|
|
|
|
|
semiStream.open();
|
|
|
|
|
semiStream.println("Semihosting starts!");
|
|
|
|
|
// Redirect our serial output to instead go via the ICE port
|
|
|
|
|
console->setDestination(&semiStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-04-11 13:52:39 +08:00
|
|
|
void nrf52Setup()
|
|
|
|
|
{
|
2025-03-28 21:22:17 +01:00
|
|
|
#ifdef ADC_V
|
|
|
|
|
pinMode(ADC_V, INPUT);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-06-24 08:27:37 -07:00
|
|
|
uint32_t why = NRF_POWER->RESETREAS;
|
2021-04-11 13:52:39 +08:00
|
|
|
// per
|
|
|
|
|
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Reset reason: 0x%x", why);
|
2020-05-24 16:20:21 -07:00
|
|
|
|
2024-06-24 08:27:37 -07:00
|
|
|
#ifdef USE_SEMIHOSTING
|
|
|
|
|
nrf52InitSemiHosting();
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-04-11 13:52:39 +08:00
|
|
|
// Per
|
|
|
|
|
// https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/monitor-mode-debugging-with-j-link-and-gdbeclipse
|
|
|
|
|
// This is the recommended setting for Monitor Mode Debugging
|
|
|
|
|
NVIC_SetPriority(DebugMonitor_IRQn, 6UL);
|
2020-05-25 15:56:06 -07:00
|
|
|
|
2020-10-24 18:40:47 +08:00
|
|
|
#ifdef BQ25703A_ADDR
|
2021-04-11 13:52:39 +08:00
|
|
|
auto *bq = new BQ25713();
|
|
|
|
|
if (!bq->setup())
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_ERROR("ERROR! Charge controller init failed");
|
2020-10-24 18:40:47 +08:00
|
|
|
#endif
|
2020-05-27 15:31:32 -07:00
|
|
|
|
2021-04-11 13:52:39 +08:00
|
|
|
// Init random seed
|
2022-04-25 07:13:41 +02:00
|
|
|
union seedParts {
|
|
|
|
|
uint32_t seed32;
|
2023-01-21 14:34:29 +01:00
|
|
|
uint8_t seed8[4];
|
2022-04-25 07:13:41 +02:00
|
|
|
} seed;
|
|
|
|
|
nRFCrypto.begin();
|
|
|
|
|
nRFCrypto.Random.generate(seed.seed8, sizeof(seed.seed8));
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_DEBUG("Set random seed %u", seed.seed32);
|
2022-04-25 07:13:41 +02:00
|
|
|
randomSeed(seed.seed32);
|
|
|
|
|
nRFCrypto.end();
|
2020-10-30 17:05:32 +08:00
|
|
|
}
|
|
|
|
|
|
2023-04-11 13:32:19 +02:00
|
|
|
void cpuDeepSleep(uint32_t msecToWake)
|
2021-04-11 13:52:39 +08:00
|
|
|
{
|
|
|
|
|
// FIXME, configure RTC or button press to wake us
|
|
|
|
|
// FIXME, power down SPI, I2C, RAMs
|
2022-07-31 07:11:47 -05:00
|
|
|
#if HAS_WIRE
|
2021-04-11 13:52:39 +08:00
|
|
|
Wire.end();
|
2021-03-17 10:44:42 -07:00
|
|
|
#endif
|
2021-04-11 13:52:39 +08:00
|
|
|
SPI.end();
|
2025-03-28 21:22:17 +01:00
|
|
|
#if SPI_INTERFACES_COUNT > 1
|
|
|
|
|
SPI1.end();
|
|
|
|
|
#endif
|
2021-04-11 13:52:39 +08:00
|
|
|
// This may cause crashes as debug messages continue to flow.
|
|
|
|
|
Serial.end();
|
2025-04-07 12:46:22 +02:00
|
|
|
#ifdef PIN_SERIAL1_RX
|
2021-04-11 13:52:39 +08:00
|
|
|
Serial1.end();
|
2021-03-17 10:44:42 -07:00
|
|
|
#endif
|
2021-04-11 13:52:39 +08:00
|
|
|
setBluetoothEnable(false);
|
2023-07-03 16:34:32 +02:00
|
|
|
|
2023-01-10 07:36:19 -06:00
|
|
|
#ifdef RAK4630
|
2023-07-03 16:34:32 +02:00
|
|
|
#ifdef PIN_3V3_EN
|
2023-01-10 07:36:19 -06:00
|
|
|
digitalWrite(PIN_3V3_EN, LOW);
|
2023-07-03 16:34:32 +02:00
|
|
|
#endif
|
2024-03-12 19:03:04 +01:00
|
|
|
#ifdef AQ_SET_PIN
|
2023-06-09 05:58:58 -05:00
|
|
|
// RAK-12039 set pin for Air quality sensor
|
|
|
|
|
digitalWrite(AQ_SET_PIN, LOW);
|
|
|
|
|
#endif
|
2024-07-11 21:34:33 +08:00
|
|
|
#ifdef RAK14014
|
|
|
|
|
// GPIO restores input status, otherwise there will be leakage current
|
|
|
|
|
nrf_gpio_cfg_default(TFT_BL);
|
|
|
|
|
nrf_gpio_cfg_default(TFT_DC);
|
|
|
|
|
nrf_gpio_cfg_default(TFT_CS);
|
|
|
|
|
nrf_gpio_cfg_default(TFT_SCLK);
|
|
|
|
|
nrf_gpio_cfg_default(TFT_MOSI);
|
|
|
|
|
nrf_gpio_cfg_default(TFT_MISO);
|
|
|
|
|
nrf_gpio_cfg_default(SCREEN_TOUCH_INT);
|
|
|
|
|
nrf_gpio_cfg_default(WB_I2C1_SCL);
|
|
|
|
|
nrf_gpio_cfg_default(WB_I2C1_SDA);
|
Add rak12035 VB Soil Monitor Tested & Working (#6741)
* [WIP] Add RAK12035VB Soil Moisture Sensor support
Introduce the RAK12035 sensor as an environmental telemetry sensor,
including necessary calibration checks and default values. Update
relevant files to integrate the sensor into the existing telemetry system.
This hardware is not just one module, but a couple.. RAK12023 and
RAK12035 is the component stack, the RAK12023 does not seem to matter
much and allows for multiple RAK12035 devices to be used.
Co-Authored-By: @Justin-Mann
* [WIP] Add RAK12035VB Soil Moisture Sensor support
Introduce the RAK12035 sensor as an environmental telemetry sensor,
including necessary calibration checks and default values. Update
relevant files to integrate the sensor into the existing telemetry system.
This hardware is not just one module, but a couple.. RAK12023 and
RAK12035 is the component stack, the RAK12023 does not seem to matter
much and allows for multiple RAK12035 devices to be used.
Co-Authored-By: @Justin-Mann
* [WIP] Add RAK12035VB Soil Moisture Sensor support
Introduce the RAK12035 sensor as an environmental telemetry sensor,
including necessary calibration checks and default values. Update
relevant files to integrate the sensor into the existing telemetry system.
This hardware is not just one module, but a couple.. RAK12023 and
RAK12035 is the component stack, the RAK12023 does not seem to matter
much and allows for multiple RAK12035 devices to be used.
Co-Authored-By: @Justin-Mann
* [WIP] Add RAK12035VB Soil Moisture Sensor support
Introduce the RAK12035 sensor as an environmental telemetry sensor,
including necessary calibration checks and default values. Update
relevant files to integrate the sensor into the existing telemetry system.
This hardware is not just one module, but a couple.. RAK12023 and
RAK12035 is the component stack, the RAK12023 does not seem to matter
much and allows for multiple RAK12035 devices to be used.
Co-Authored-By: @Justin-Mann
* Update to 1.0.4 release of RAK12035_SoilMoisture
* cleanup
* cool
* .
* ..
* little bit of cleanup and recompile/upload/test on RAK WISBLAOCK STACK: RAK19007/RAK4631/RAK12035VB/RAK12500
looks like soil monitor is working correctly, new environmental metrics are comming thru [new protos soil_moisture, soil_temperature] and GPS is working again with the RAK 12500.
improvements could be made around the configuration of the monitor.
next steps include updating the client(s) to react to, log and display the new proto metrics for soil temp and humidity.
* . comments about current limitations and TODOs
* trunk update
* trying to autoformat..
* fix formatting attempt 2
* ..
* ...
* ...
* .
* some corrections and local build success
* correction in temp code
* grr formatting
* cleanup after a few experiments
* remove temp code to overwrite values for temp and humidity protos.. next step just update the clients to know about soil_temperature and soil_humidity protos.
* update some values in varient for rak wistap
* working out trunk formatting..
* wip
. corrections to other build variants
* .
* protobuffs?
* protobufs?
* Update protobufs ref
* Protobufs ref
* Trunk
* Update RAK12035Sensor.cpp
* Fmt
* comment changes
* dumb mistakes... resolved, actually built and tested.. all good..
* Update src/modules/Telemetry/Sensor/RAK12035Sensor.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update src/modules/Telemetry/Sensor/RAK12035Sensor.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* . proto submod
* proto
* proto
* merge master
* mabe a fix for GPS pin conflict, waiting on a new gps module to try
* merge master, attempt to fix gps (RAK12500) pin conflict with RAK12023/12035
* .
* .
---------
Co-authored-by: Tom Fifield <tom@tomfifield.net>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-19 17:51:03 -06:00
|
|
|
|
|
|
|
|
// nrf_gpio_cfg_default(WB_I2C2_SCL);
|
|
|
|
|
// nrf_gpio_cfg_default(WB_I2C2_SDA);
|
2024-07-11 21:34:33 +08:00
|
|
|
#endif
|
2024-08-13 19:30:35 +08:00
|
|
|
#endif
|
2025-02-17 02:49:17 +01:00
|
|
|
#ifdef MESHLINK
|
|
|
|
|
#ifdef PIN_WD_EN
|
|
|
|
|
digitalWrite(PIN_WD_EN, LOW);
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2024-08-13 19:30:35 +08:00
|
|
|
|
|
|
|
|
#ifdef HELTEC_MESH_NODE_T114
|
|
|
|
|
nrf_gpio_cfg_default(PIN_GPS_PPS);
|
|
|
|
|
detachInterrupt(PIN_GPS_PPS);
|
|
|
|
|
detachInterrupt(PIN_BUTTON1);
|
2023-01-10 07:36:19 -06:00
|
|
|
#endif
|
2025-03-28 21:22:17 +01:00
|
|
|
|
|
|
|
|
#ifdef ELECROW_ThinkNode_M1
|
|
|
|
|
for (int pin = 0; pin < 48; pin++) {
|
|
|
|
|
if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 ||
|
|
|
|
|
pin == PIN_BUTTON1 || pin == PIN_BUTTON2) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pinMode(pin, OUTPUT);
|
|
|
|
|
}
|
|
|
|
|
for (int pin = 0; pin < 48; pin++) {
|
|
|
|
|
if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 ||
|
|
|
|
|
pin == PIN_BUTTON1 || pin == PIN_BUTTON2) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
digitalWrite(pin, LOW);
|
|
|
|
|
}
|
|
|
|
|
for (int pin = 0; pin < 48; pin++) {
|
|
|
|
|
if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 ||
|
|
|
|
|
pin == PIN_BUTTON1 || pin == PIN_BUTTON2) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
NRF_GPIO->DIRCLR = (1 << pin);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-10-05 12:42:03 -05:00
|
|
|
// Sleepy trackers or sensors can low power "sleep"
|
|
|
|
|
// Don't enter this if we're sleeping portMAX_DELAY, since that's a shutdown event
|
|
|
|
|
if (msecToWake != portMAX_DELAY &&
|
2024-09-25 13:50:00 -05:00
|
|
|
(IS_ONE_OF(config.device.role, meshtastic_Config_DeviceConfig_Role_TRACKER,
|
|
|
|
|
meshtastic_Config_DeviceConfig_Role_TAK_TRACKER, meshtastic_Config_DeviceConfig_Role_SENSOR) &&
|
|
|
|
|
config.power.is_power_saving == true)) {
|
2023-09-30 21:09:17 -05:00
|
|
|
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
|
|
|
|
|
delay(msecToWake);
|
|
|
|
|
NVIC_SystemReset();
|
|
|
|
|
} else {
|
2024-10-07 18:39:59 -07:00
|
|
|
// Resume on user button press
|
|
|
|
|
// https://github.com/lyusupov/SoftRF/blob/81c519ca75693b696752235d559e881f2e0511ee/software/firmware/source/SoftRF/src/platform/nRF52.cpp#L1738
|
|
|
|
|
constexpr uint32_t DFU_MAGIC_SKIP = 0x6d;
|
|
|
|
|
sd_power_gpregret_set(0, DFU_MAGIC_SKIP); // Equivalent NRF_POWER->GPREGRET = DFU_MAGIC_SKIP
|
|
|
|
|
|
2023-10-05 12:42:03 -05:00
|
|
|
// FIXME, use system off mode with ram retention for key state?
|
|
|
|
|
// FIXME, use non-init RAM per
|
|
|
|
|
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
|
2025-03-28 21:22:17 +01:00
|
|
|
|
|
|
|
|
#ifdef ELECROW_ThinkNode_M1
|
|
|
|
|
nrf_gpio_cfg_input(PIN_BUTTON1, NRF_GPIO_PIN_PULLUP); // Configure the pin to be woken up as an input
|
|
|
|
|
nrf_gpio_pin_sense_t sense = NRF_GPIO_PIN_SENSE_LOW;
|
|
|
|
|
nrf_gpio_cfg_sense_set(PIN_BUTTON1, sense);
|
|
|
|
|
|
|
|
|
|
nrf_gpio_cfg_input(PIN_BUTTON2, NRF_GPIO_PIN_PULLUP);
|
|
|
|
|
nrf_gpio_pin_sense_t sense1 = NRF_GPIO_PIN_SENSE_LOW;
|
|
|
|
|
nrf_gpio_cfg_sense_set(PIN_BUTTON2, sense1);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-09-30 21:09:17 -05:00
|
|
|
auto ok = sd_power_system_off();
|
|
|
|
|
if (ok != NRF_SUCCESS) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_ERROR("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!");
|
2023-09-30 21:09:17 -05:00
|
|
|
NRF_POWER->SYSTEMOFF = 1;
|
|
|
|
|
}
|
2021-04-11 13:52:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The following code should not be run, because we are off
|
|
|
|
|
while (1) {
|
|
|
|
|
delay(5000);
|
2022-12-29 20:41:37 -06:00
|
|
|
LOG_DEBUG(".");
|
2021-04-11 13:52:39 +08:00
|
|
|
}
|
2022-02-01 18:32:26 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 14:34:29 +01:00
|
|
|
void clearBonds()
|
|
|
|
|
{
|
2022-02-01 18:32:26 -06:00
|
|
|
if (!nrf52Bluetooth) {
|
|
|
|
|
nrf52Bluetooth = new NRF52Bluetooth();
|
|
|
|
|
nrf52Bluetooth->setup();
|
|
|
|
|
}
|
|
|
|
|
nrf52Bluetooth->clearBonds();
|
2023-12-27 14:26:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void enterDfuMode()
|
|
|
|
|
{
|
2024-07-11 14:08:31 -05:00
|
|
|
// SDK kit does not have native USB like almost all other NRF52 boards
|
|
|
|
|
#ifdef NRF_USE_SERIAL_DFU
|
|
|
|
|
enterSerialDfu();
|
|
|
|
|
#else
|
2023-12-27 14:26:40 -06:00
|
|
|
enterUf2Dfu();
|
2024-07-11 14:08:31 -05:00
|
|
|
#endif
|
2025-01-20 09:43:35 -08:00
|
|
|
}
|