Compare commits

..

10 Commits

Author SHA1 Message Date
Thomas Göttgens
6d202158ba add (and fix) CPU Shutdown Flags 2023-03-12 20:20:55 +01:00
Thomas Göttgens
c288974b67 don't adjust brightness on long press any more 2023-03-12 20:20:55 +01:00
Thomas Göttgens
9b1d461567 add NO_SCREEN shim 2023-03-12 20:20:55 +01:00
Thomas Göttgens
210e3e09d5 enable deep sleep behaviour for ESP32 2023-03-12 20:20:55 +01:00
Thomas Göttgens
0d001423c8 woops 2023-03-12 20:20:55 +01:00
Thomas Göttgens
a83d5ada86 - implement shutdown (deep sleep forever) on ESP32
- Clean up shutdown and delayed shutdown code conditionals.
- clean up inputbroker includes
2023-03-12 20:20:55 +01:00
andrekir
c9686d2f62 remove PIN_EINK_EN from RAK4631 variants 2023-03-12 19:29:12 +01:00
Andre K
634251834f fix rak4631_epaper PIN_EINK_EN
revert 088ab106dd
2023-03-12 19:29:12 +01:00
GUVWAF
6d443d2c67 SX126x/8x: Also use PREAMBLE_DETECTED IRQ flag for actively receiving check (#2349)
* Use startReceive() instead of startReceiveDutyCycleAuto()

* Add preamble detected IRQ

* Escape from 'freeze' state when packet should have been received

* Use RADIOLIB_GODMODE for access to clearIrqStatus

* SX126x: Better handling of false preamble detections

* SX128x: Add preamble IRQ and false detection handling to active receiving check

* Remove unnecessary function declaration

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
2023-03-11 12:59:29 -06:00
thebentern
9cadc0a16f [create-pull-request] automated change 2023-03-11 12:08:25 +01:00
18 changed files with 88 additions and 44 deletions

View File

@@ -123,9 +123,6 @@ class ButtonThread : public concurrency::OSThread
static void userButtonPressedLong()
{
// LOG_DEBUG("Long press!\n");
#ifdef ARCH_ESP32
screen->adjustBrightness();
#endif
// If user button is held down for 5 seconds, shutdown the device.
if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0)) {
#ifdef HAS_PMU
@@ -133,7 +130,7 @@ class ButtonThread : public concurrency::OSThread
setLed(false);
power->shutdown();
}
#elif defined(ARCH_NRF52)
#elif defined(ARCH_NRF52) || defined(ARCH_ESP32)
// Do actual shutdown when button released, otherwise the button release
// may wake the board immediatedly.
if ((!shutdown_on_long_stop) && (millis() > 30 * 1000)) {

View File

@@ -13,6 +13,10 @@
#include <WiFi.h>
#endif
#ifndef DELAY_FOREVER
#define DELAY_FOREVER portMAX_DELAY
#endif
#ifdef HAS_PMU
#include "XPowersAXP192.tpp"
#include "XPowersAXP2101.tpp"
@@ -256,16 +260,24 @@ void Power::shutdown()
digitalWrite(PIN_EINK_EN, LOW); // power off backlight first
#endif
#ifdef HAS_PMU
LOG_INFO("Shutting down\n");
#ifdef HAS_PMU
if (PMU) {
PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF);
PMU->shutdown();
}
#elif defined(ARCH_NRF52)
playBeep();
#endif
#if defined(ARCH_NRF52) || defined(ARCH_ESP32)
#ifdef PIN_LED1
ledOff(PIN_LED1);
#endif
#ifdef PIN_LED2
ledOff(PIN_LED2);
#endif
#ifdef PIN_LED3
ledOff(PIN_LED2);
#endif
doDeepSleep(DELAY_FOREVER);
#endif
}

View File

@@ -25,6 +25,7 @@ class Screen
void startBluetoothPinScreen(uint32_t pin) {}
void stopBluetoothPinScreen() {}
void startRebootScreen() {}
void startShutdownScreen() {}
void startFirmwareUpdateScreen() {}
};
} // namespace graphics

View File

@@ -1,7 +1,8 @@
#pragma once
#include "InputBroker.h"
#include "SinglePortModule.h" // TODO: what header file to include?
#include "concurrency/OSThread.h"
#include "mesh/NodeDB.h"
enum RotaryEncoderInterruptBaseStateType { ROTARY_EVENT_OCCURRED, ROTARY_EVENT_CLEARED };

View File

@@ -1,7 +1,7 @@
#pragma once
#include "InputBroker.h"
#include "SinglePortModule.h" // TODO: what header file to include?
#include "mesh/NodeDB.h"
class UpDownInterruptBase : public Observable<const InputEvent *>
{

View File

@@ -1,8 +1,8 @@
#pragma once
#include "InputBroker.h"
#include "SinglePortModule.h" // TODO: what header file to include?
#include "Wire.h"
#include "concurrency/OSThread.h"
class KbI2cBase : public Observable<const InputEvent *>, public concurrency::OSThread
{

View File

@@ -471,6 +471,9 @@ void RadioInterface::applyModemConfig()
saveChannelNum(channel_num);
saveFreq(freq + loraConfig.frequency_offset);
preambleTimeMsec = getPacketTime((uint32_t)0);
maxPacketTimeMsec = getPacketTime(meshtastic_Constants_DATA_PAYLOAD_LEN + sizeof(PacketHeader));
LOG_INFO("Radio freq=%.3f, config.lora.frequency_offset=%.3f\n", freq, loraConfig.frequency_offset);
LOG_INFO("Set radio: region=%s, name=%s, config=%u, ch=%d, power=%d\n", myRegion->name, channelName, loraConfig.modem_preset,
channel_num, power);

View File

@@ -63,7 +63,9 @@ class RadioInterface
- Tx/Rx turnaround time (maximum of SX126x and SX127x);
- MAC processing time (measured on T-beam) */
uint32_t slotTimeMsec = 8.5 * pow(2, sf) / bw + 0.2 + 0.4 + 7;
uint16_t preambleLength = 16; // 8 is default, but we use longer to increase the amount of sleep time when receiving
uint16_t preambleLength = 16; // 8 is default, but we use longer to increase the amount of sleep time when receiving
uint32_t preambleTimeMsec = 165; // calculated on startup, this is the default for LongFast
uint32_t maxPacketTimeMsec = 3246; // calculated on startup, this is the default for LongFast
const uint32_t PROCESSING_TIME_MSEC =
4500; // time to construct, process and construct a packet again (empirically determined)
const uint8_t CWmin = 2; // minimum CWsize

View File

@@ -180,6 +180,7 @@ template <typename T> void SX126xInterface<T>::setStandby()
assert(err == RADIOLIB_ERR_NONE);
isReceiving = false; // If we were receiving, not any more
activeReceiveStart = 0;
disableInterrupt();
completeSending(); // If we were sending, not anymore
}
@@ -213,9 +214,10 @@ template <typename T> void SX126xInterface<T>::startReceive()
setStandby();
// We use a 16 bit preamble so this should save some power by letting radio sit in standby mostly.
// Furthermore, we need the HEADER_VALID IRQ flag to detect whether we are actively receiving
int err =
lora.startReceiveDutyCycleAuto(preambleLength, 8, RADIOLIB_SX126X_IRQ_RX_DEFAULT | RADIOLIB_SX126X_IRQ_HEADER_VALID);
// Furthermore, we need the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving
int err = lora.startReceiveDutyCycleAuto(preambleLength, 8,
RADIOLIB_SX126X_IRQ_RX_DEFAULT | RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED |
RADIOLIB_SX126X_IRQ_HEADER_VALID);
assert(err == RADIOLIB_ERR_NONE);
isReceiving = true;
@@ -248,10 +250,27 @@ template <typename T> bool SX126xInterface<T>::isActivelyReceiving()
// received and handled the interrupt for reading the packet/handling errors.
uint16_t irq = lora.getIrqStatus();
bool headerValid = (irq & RADIOLIB_SX126X_IRQ_HEADER_VALID);
bool detected = (irq & (RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED));
// Handle false detections
if (detected) {
uint32_t now = millis();
if (!activeReceiveStart) {
activeReceiveStart = now;
} else if ((now - activeReceiveStart > 2 * preambleTimeMsec) && !(irq & RADIOLIB_SX126X_IRQ_HEADER_VALID)) {
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
activeReceiveStart = 0;
LOG_DEBUG("Ignore false preamble detection.\n");
return false;
} else if (now - activeReceiveStart > maxPacketTimeMsec) {
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
activeReceiveStart = 0;
LOG_DEBUG("Ignore false header detection.\n");
return false;
}
}
// if (headerValid) LOG_DEBUG("rx headerValid\n");
return headerValid;
// if (detected) LOG_DEBUG("rx detected\n");
return detected;
}
template <typename T> bool SX126xInterface<T>::sleep()

View File

@@ -68,4 +68,5 @@ template <class T> class SX126xInterface : public RadioLibInterface
virtual void setStandby() override;
private:
uint32_t activeReceiveStart = 0;
};

View File

@@ -157,6 +157,7 @@ template <typename T> void SX128xInterface<T>::setStandby()
#endif
isReceiving = false; // If we were receiving, not any more
activeReceiveStart = 0;
disableInterrupt();
completeSending(); // If we were sending, not anymore
}
@@ -203,9 +204,10 @@ template <typename T> void SX128xInterface<T>::startReceive()
digitalWrite(SX128X_TXEN, LOW);
#endif
// We use the HEADER_VALID IRQ flag to detect whether we are actively receiving
int err =
lora.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_SX128X_IRQ_RX_DEFAULT | RADIOLIB_SX128X_IRQ_HEADER_VALID);
// We use the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving
int err = lora.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_SX128X_IRQ_RX_DEFAULT |
RADIOLIB_SX128X_IRQ_RADIOLIB_PREAMBLE_DETECTED |
RADIOLIB_SX128X_IRQ_HEADER_VALID);
assert(err == RADIOLIB_ERR_NONE);
@@ -236,8 +238,27 @@ template <typename T> bool SX128xInterface<T>::isChannelActive()
template <typename T> bool SX128xInterface<T>::isActivelyReceiving()
{
uint16_t irq = lora.getIrqStatus();
bool hasHeader = (irq & RADIOLIB_SX128X_IRQ_HEADER_VALID);
return hasHeader;
bool detected = (irq & (RADIOLIB_SX128X_IRQ_HEADER_VALID | RADIOLIB_SX128X_IRQ_RADIOLIB_PREAMBLE_DETECTED));
// Handle false detections
if (detected) {
uint32_t now = millis();
if (!activeReceiveStart) {
activeReceiveStart = now;
} else if ((now - activeReceiveStart > 2 * preambleTimeMsec) && !(irq & RADIOLIB_SX128X_IRQ_HEADER_VALID)) {
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
activeReceiveStart = 0;
LOG_DEBUG("Ignore false preamble detection.\n");
return false;
} else if (now - activeReceiveStart > maxPacketTimeMsec) {
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
activeReceiveStart = 0;
LOG_DEBUG("Ignore false header detection.\n");
return false;
}
}
return detected;
}
template <typename T> bool SX128xInterface<T>::sleep()

View File

@@ -68,4 +68,5 @@ template <class T> class SX128xInterface : public RadioLibInterface
virtual void setStandby() override;
private:
uint32_t activeReceiveStart = 0;
};

View File

@@ -36,6 +36,9 @@
#ifndef HAS_RTC
#define HAS_RTC 1
#endif
#ifndef HAS_CPU_SHUTDOWN
#define HAS_CPU_SHUTDOWN 1
#endif
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
#define HAS_PMU

View File

@@ -29,7 +29,7 @@
#ifndef HAS_RADIO
#define HAS_RADIO 1
#endif
#ifdef HAS_CPU_SHUTDOWN
#ifndef HAS_CPU_SHUTDOWN
#define HAS_CPU_SHUTDOWN 1
#endif

View File

@@ -18,31 +18,16 @@ void powerCommandsCheck()
#endif
}
#if defined(ARCH_NRF52) || defined(HAS_PMU)
#if defined(ARCH_ESP32) || defined(ARCH_NRF52)
if (shutdownAtMsec) {
screen->startShutdownScreen();
playBeep();
#ifdef PIN_LED1
ledOff(PIN_LED1);
#endif
#ifdef PIN_LED2
ledOff(PIN_LED2);
#endif
#ifdef PIN_LED3
ledOff(PIN_LED3);
#endif
}
#endif
if (shutdownAtMsec && millis() > shutdownAtMsec) {
LOG_INFO("Shutting down from admin command\n");
#ifdef HAS_PMU
if (pmu_found == true) {
playShutdownMelody();
power->shutdown();
}
#elif defined(ARCH_NRF52)
playShutdownMelody();
#if defined(ARCH_NRF52) || defined(ARCH_ESP32)
power->shutdown();
#else
LOG_WARN("FIXME implement shutdown for this platform");

View File

@@ -126,7 +126,6 @@ static const uint8_t SCK = PIN_SPI_SCK;
* eink display pins
*/
#define PIN_EINK_EN (32 + 2) // (0 + 2) Note: this is really just backlight power
#define PIN_EINK_CS (0 + 26)
#define PIN_EINK_BUSY (0 + 4)
#define PIN_EINK_DC (0 + 17)

View File

@@ -126,7 +126,6 @@ static const uint8_t SCK = PIN_SPI_SCK;
* eink display pins
*/
#define PIN_EINK_EN (32 + 2) // (0 + 2) Note: this is really just backlight power
#define PIN_EINK_CS (0 + 26)
#define PIN_EINK_BUSY (0 + 4)
#define PIN_EINK_DC (0 + 17)

View File

@@ -1,4 +1,4 @@
[VERSION]
major = 2
minor = 1
build = 1
build = 2