Fix #115: wake from light sleep if a character arrives on the serial port

Note - we do this not by using the uart wake feature, but by the lower
power GPIO edge feature.  Recommend sending "Z" 0x5A - because that has
many edges.  Send the character 4 times to make sure the device is awake
This commit is contained in:
geeksville
2020-06-10 14:36:11 -07:00
parent ddfdae64bf
commit 8ccd59a7d8
3 changed files with 20 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
#include "esp_pm.h"
#include "rom/rtc.h"
#include <driver/rtc_io.h>
#include <driver/uart.h>
#include "BluetoothUtil.h"
@@ -111,7 +112,6 @@ void initDeepSleep()
#endif
}
bool doPreflightSleep()
{
if (preflightSleep.notifyObservers(NULL) != 0)
@@ -257,6 +257,17 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
gpio_pullup_en((gpio_num_t)BUTTON_PIN);
#endif
#ifdef SERIAL0_RX_GPIO
// We treat the serial port as a GPIO for a fast/low power way of waking, if we see a rising edge that means
// someone started to send something
// Alas - doesn't work reliably, instead need to use the uart specific version (which burns a little power)
// FIXME: gpio 3 is RXD for serialport 0 on ESP32
// Send a few Z characters to wake the port
gpio_wakeup_enable((gpio_num_t)SERIAL0_RX_GPIO, GPIO_INTR_LOW_LEVEL);
// uart_set_wakeup_threshold(UART_NUM_0, 3);
// esp_sleep_enable_uart_wakeup(0);
#endif
#ifdef BUTTON_PIN
gpio_wakeup_enable((gpio_num_t)BUTTON_PIN, GPIO_INTR_LOW_LEVEL); // when user presses, this button goes low
#endif