diff --git a/.vscode/launch.json b/.vscode/launch.json
index 914831d68..77b1fb363 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -12,8 +12,9 @@
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
- "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf",
- "toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin",
+ "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/bare/firmware.elf",
+ "toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-gccarmnoneeabi/bin",
+ "svdPath": "/home/kevinh/.platformio/platforms/nordicnrf52/misc/svd/nrf52840.svd",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
@@ -24,8 +25,9 @@
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
- "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf",
- "toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin",
+ "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/bare/firmware.elf",
+ "toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-gccarmnoneeabi/bin",
+ "svdPath": "/home/kevinh/.platformio/platforms/nordicnrf52/misc/svd/nrf52840.svd",
"internalConsoleOptions": "openOnSessionStart"
}
]
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 6622b9aeb..dfe3b542f 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -42,7 +42,12 @@
"typeinfo": "cpp",
"string": "cpp",
"*.xbm": "cpp",
- "list": "cpp"
+ "list": "cpp",
+ "atomic": "cpp",
+ "memory_resource": "cpp",
+ "optional": "cpp",
+ "string_view": "cpp",
+ "cassert": "cpp"
},
"cSpell.words": [
"Meshtastic",
diff --git a/platformio.ini b/platformio.ini
index 5d388aafe..c15d4d0db 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -9,16 +9,12 @@
; https://docs.platformio.org/page/projectconf.html
[platformio]
-default_envs = tbeam
+default_envs = bare
[common]
; default to a US frequency range, change it as needed for your region and hardware (CN, JP, EU433, EU865)
hw_version = US
-; Common settings for ESP targes, mixin with extends = esp32_base
-[esp32_base]
-src_filter =
- ${env.src_filter} -
[env]
platform = espressif32
@@ -30,7 +26,7 @@ board_build.partitions = partition-table.csv
; note: we add src to our include search path so that lmic_project_config can override
; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc
-build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Isrc/rf95 -Os -Wl,-Map,.pio/build/output.map -DAXP_DEBUG_PORT=Serial -DHW_VERSION_${common.hw_version}
+build_flags = -Wno-missing-field-initializers -Isrc -Isrc/rf95 -Os -Wl,-Map,.pio/build/output.map -DAXP_DEBUG_PORT=Serial -DHW_VERSION_${common.hw_version}
; not needed included in ttgo-t-beam board file
; also to use PSRAM https://docs.platformio.org/en/latest/platforms/espressif32.html#external-ram-psram
@@ -43,8 +39,6 @@ build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Isrc/rf95 -Os
;upload_port = /dev/ttyUSB0
;monitor_port = /dev/ttyUSB0
-upload_speed = 921600
-
; the default is esptool
; upload_protocol = esp-prog
@@ -62,8 +56,6 @@ debug_tool = jlink
;debug_init_cmds =
; monitor adapter_khz 10000
-debug_init_break = tbreak setup
-
lib_deps =
https://github.com/meshtastic/LoRaLayer2.git
https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
@@ -74,6 +66,15 @@ lib_deps =
https://github.com/meshtastic/arduino-fsm.git
https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git
+; Common settings for ESP targes, mixin with extends = esp32_base
+[esp32_base]
+src_filter =
+ ${env.src_filter} -
+upload_speed = 921600
+debug_init_break = tbreak setup
+build_flags =
+ ${env.build_flags} -Wall -Wextra
+
; The 1.0 release of the TBEAM board
[env:tbeam]
extends = esp32_base
@@ -82,14 +83,14 @@ lib_deps =
${env.lib_deps}
AXP202X_Library
build_flags =
- ${env.build_flags} -D TBEAM_V10
+ ${esp32_base.build_flags} -D TBEAM_V10
; The original TBEAM board without the AXP power chip and a few other changes
[env:tbeam0.7]
extends = esp32_base
board = ttgo-t-beam
build_flags =
- ${env.build_flags} -D TBEAM_V07
+ ${esp32_base.build_flags} -D TBEAM_V07
[env:heltec]
;build_type = debug ; to make it possible to step through our jtag debugger
@@ -100,22 +101,28 @@ board = heltec_wifi_lora_32_V2
extends = esp32_base
board = ttgo-lora32-v1
build_flags =
- ${env.build_flags} -D TTGO_LORA_V1
+ ${esp32_base.build_flags} -D TTGO_LORA_V1
; note: the platformio definition for lora32-v2 seems stale, it is missing a pins_arduino.h file, therefore I don't think it works
[env:ttgo-lora32-v2]
extends = esp32_base
board = ttgo-lora32-v1
build_flags =
- ${env.build_flags} -D TTGO_LORA_V2
+ ${esp32_base.build_flags} -D TTGO_LORA_V2
; This is a temporary build target to test turning off particular hardare bits in the build (to improve modularity)
[env:bare]
-board = ttgo-lora32-v1
+platform = nordicnrf52
+board = nrf52840_dk_adafruit ; nicer than nrf52840_dk - more full gpio mappings
+framework = arduino
+debug_tool = jlink
build_flags =
- ${env.build_flags} -D BARE_BOARD
+ ${env.build_flags} -D BARE_BOARD -Wno-unused-variable -Isrc/bare
src_filter =
${env.src_filter} -
lib_ignore =
- BluetoothOTA
\ No newline at end of file
+ BluetoothOTA
+lib_deps =
+ ${env.lib_deps}
+monitor_port = /dev/ttyACM1
\ No newline at end of file
diff --git a/src/GPS.cpp b/src/GPS.cpp
index ea04b09f9..60dedf429 100644
--- a/src/GPS.cpp
+++ b/src/GPS.cpp
@@ -2,9 +2,15 @@
#include "GPS.h"
#include "configuration.h"
#include "time.h"
+#include
#include
+#ifdef GPS_RX_PIN
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
+#else
+// Assume NRF52
+// Uart _serial_gps(GPS_SERIAL_NUM);
+#endif
bool timeSetFromGPS; // We try to set our time from GPS each time we wake from sleep
@@ -97,7 +103,11 @@ void GPS::perhapsSetRTC(const struct timeval *tv)
if (!timeSetFromGPS) {
timeSetFromGPS = true;
DEBUG_MSG("Setting RTC %ld secs\n", tv->tv_sec);
+#ifndef NO_ESP32
settimeofday(tv, NULL);
+#else
+ assert(0);
+#endif
readFromRTC();
}
}
diff --git a/src/MeshService.cpp b/src/MeshService.cpp
index c8e947acf..c7794bde8 100644
--- a/src/MeshService.cpp
+++ b/src/MeshService.cpp
@@ -1,6 +1,7 @@
#include
#include
+#include
#include "GPS.h"
//#include "MeshBluetoothService.h"
diff --git a/src/MeshService.h b/src/MeshService.h
index e9d4fe488..235801211 100644
--- a/src/MeshService.h
+++ b/src/MeshService.h
@@ -2,6 +2,7 @@
#include
#include
+#include
#include "MemoryPool.h"
#include "MeshRadio.h"
diff --git a/src/NodeDB.cpp b/src/NodeDB.cpp
index 3dad39dd2..525136760 100644
--- a/src/NodeDB.cpp
+++ b/src/NodeDB.cpp
@@ -30,7 +30,12 @@ DeviceState versions used to be defined in the .proto file but really only this
#define DEVICESTATE_CUR_VER 7
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
+#ifndef NO_ESP32
#define FS SPIFFS
+#endif
+
+// FIXME - move this somewhere else
+extern void getMacAddr(uint8_t *dmac);
/**
*
@@ -97,7 +102,7 @@ void NodeDB::init()
strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model));
// Init our blank owner info to reasonable defaults
- esp_efuse_mac_get_default(ourMacAddr);
+ getMacAddr(ourMacAddr);
sprintf(owner.id, "!%02x%02x%02x%02x%02x%02x", ourMacAddr[0], ourMacAddr[1], ourMacAddr[2], ourMacAddr[3], ourMacAddr[4],
ourMacAddr[5]);
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
@@ -116,12 +121,6 @@ void NodeDB::init()
info->user = owner;
info->has_user = true;
- if (!FS.begin(true)) // FIXME - do this in main?
- {
- DEBUG_MSG("ERROR SPIFFS Mount Failed\n");
- // FIXME - report failure to phone
- }
-
// saveToDisk();
loadFromDisk();
resetRadioConfig(); // If bogus settings got saved, then fix them
@@ -157,8 +156,15 @@ const char *preftmp = "/db.proto.tmp";
void NodeDB::loadFromDisk()
{
+#ifdef FS
static DeviceState scratch;
+ if (!FS.begin(true)) // FIXME - do this in main?
+ {
+ DEBUG_MSG("ERROR SPIFFS Mount Failed\n");
+ // FIXME - report failure to phone
+ }
+
File f = FS.open(preffile);
if (f) {
DEBUG_MSG("Loading saved preferences\n");
@@ -185,10 +191,14 @@ void NodeDB::loadFromDisk()
} else {
DEBUG_MSG("No saved preferences found\n");
}
+#else
+ DEBUG_MSG("ERROR: Filesystem not implemented\n");
+#endif
}
void NodeDB::saveToDisk()
{
+#ifdef FS
File f = FS.open(preftmp, "w");
if (f) {
DEBUG_MSG("Writing preferences\n");
@@ -213,6 +223,9 @@ void NodeDB::saveToDisk()
} else {
DEBUG_MSG("ERROR: can't write prefs\n"); // FIXME report to app
}
+#else
+ DEBUG_MSG("ERROR filesystem not implemented\n");
+#endif
}
const NodeInfo *NodeDB::readNextInfo()
diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp
index 716e4e2c3..45c68805a 100644
--- a/src/PowerFSM.cpp
+++ b/src/PowerFSM.cpp
@@ -38,6 +38,7 @@ static void lsIdle()
{
DEBUG_MSG("lsIdle begin ls_secs=%u\n", radioConfig.preferences.ls_secs);
+#ifndef NO_ESP32
uint32_t secsSlept = 0;
esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED;
bool reached_ls_secs = false;
@@ -80,6 +81,7 @@ static void lsIdle()
powerFSM.trigger(EVENT_WAKE_TIMER);
}
}
+#endif
}
static void lsExit()
diff --git a/src/bare/FS.h b/src/bare/FS.h
new file mode 100644
index 000000000..819693660
--- /dev/null
+++ b/src/bare/FS.h
@@ -0,0 +1,3 @@
+#pragma once
+
+// FIXME - make a FS abstraction for NRF52
\ No newline at end of file
diff --git a/src/bare/SPIFFS.h b/src/bare/SPIFFS.h
new file mode 100644
index 000000000..819693660
--- /dev/null
+++ b/src/bare/SPIFFS.h
@@ -0,0 +1,3 @@
+#pragma once
+
+// FIXME - make a FS abstraction for NRF52
\ No newline at end of file
diff --git a/src/configuration.h b/src/configuration.h
index 9d6ca47d3..b35e4beec 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -73,6 +73,10 @@ along with this program. If not, see .
// devices. Comment this out to not rotate screen 180 degrees.
#define FLIP_SCREEN_VERTICALLY
+// DEBUG LED
+
+#define LED_INVERTED 0 // define as 1 if LED is active low (on)
+
// -----------------------------------------------------------------------------
// GPS
// -----------------------------------------------------------------------------
@@ -204,6 +208,20 @@ along with this program. If not, see .
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
+// Turn off GPS code for now
+#undef GPS_RX_PIN
+#undef GPS_TX_PIN
+
+// FIXME, not yet ready for NRF52
+#define RTC_DATA_ATTR
+
+#define LED_PIN PIN_LED1 // LED1 on nrf52840-DK
+#define BUTTON_PIN PIN_BUTTON1
+
+// This board uses 0 to be mean LED on
+#undef LED_INVERTED
+#define LED_INVERTED 1
+
#endif
// -----------------------------------------------------------------------------
diff --git a/src/debug.cpp b/src/debug.cpp
index a866d56a9..9d8f19f09 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -2,9 +2,7 @@
#include
-#include
-#include
-
+#include "freertosinc.h"
#include "configuration.h"
namespace meshtastic
@@ -12,9 +10,11 @@ namespace meshtastic
void printThreadInfo(const char *extra)
{
+#ifndef NO_ESP32
uint32_t taskHandle = reinterpret_cast(xTaskGetCurrentTaskHandle());
DEBUG_MSG("printThreadInfo(%s) task: %" PRIx32 " core id: %u min free stack: %u\n", extra, taskHandle, xPortGetCoreID(),
uxTaskGetStackHighWaterMark(nullptr));
+#endif
}
} // namespace meshtastic
diff --git a/src/freertosinc.h b/src/freertosinc.h
new file mode 100644
index 000000000..0d86ee2c9
--- /dev/null
+++ b/src/freertosinc.h
@@ -0,0 +1,16 @@
+#pragma once
+
+// The FreeRTOS includes are in a different directory on ESP32 and I can't figure out how to make that work with platformio gcc options
+// so this is my quick hack to make things work
+
+#ifdef ARDUINO_ARCH_ESP32
+#include
+#include
+#include
+#include
+#else
+#include
+#include
+#include
+#include
+#endif
\ No newline at end of file
diff --git a/src/lock.h b/src/lock.h
index 57d466a89..a6afa2f6c 100644
--- a/src/lock.h
+++ b/src/lock.h
@@ -1,7 +1,6 @@
#pragma once
-#include
-#include
+#include "freertosinc.h"
namespace meshtastic
{
diff --git a/src/main.cpp b/src/main.cpp
index a10de160b..758a6a824 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,14 +29,12 @@
#include "PowerFSM.h"
#include "configuration.h"
#include "error.h"
-#include "esp32/pm.h"
-#include "esp_pm.h"
#include "power.h"
-#include "rom/rtc.h"
+// #include "rom/rtc.h"
#include "screen.h"
#include "sleep.h"
#include
-#include
+// #include
#ifndef NO_ESP32
#include "BluetoothUtil.h"
@@ -195,10 +193,24 @@ void axp192Init()
#endif
}
+void getMacAddr(uint8_t *dmac) {
+#ifndef NO_ESP32
+ assert(esp_efuse_mac_get_default(dmac) == ESP_OK);
+#else
+ dmac[0] = 0xde;
+ dmac[1] = 0xad;
+ dmac[2] = 0xbe;
+ dmac[3] = 0xef;
+ dmac[4] = 0x01;
+ dmac[5] = 0x02; // FIXME, macaddr stuff needed for NRF52
+#endif
+}
+
const char *getDeviceName()
{
uint8_t dmac[6];
- assert(esp_efuse_mac_get_default(dmac) == ESP_OK);
+
+ getMacAddr(dmac);
// Meshtastic_ab3c
static char name[20];
@@ -239,15 +251,17 @@ void setup()
#endif
#ifdef LED_PIN
pinMode(LED_PIN, OUTPUT);
- digitalWrite(LED_PIN, 1); // turn on for now
+ digitalWrite(LED_PIN, 1 ^ LED_INVERTED); // turn on for now
#endif
// Hello
DEBUG_MSG("Meshtastic swver=%s, hwver=%s\n", xstr(APP_VERSION), xstr(HW_VERSION));
+#ifndef NO_ESP32
// Don't init display if we don't have one or we are waking headless due to a timer event
if (wakeCause == ESP_SLEEP_WAKEUP_TIMER)
ssd1306_found = false; // forget we even have the hardware
+#endif
// Initialize the screen first so we can show the logo while we start up everything else.
if (ssd1306_found)
diff --git a/src/mesh-pb-constants.cpp b/src/mesh-pb-constants.cpp
index 204fdd8fe..7e3800112 100644
--- a/src/mesh-pb-constants.cpp
+++ b/src/mesh-pb-constants.cpp
@@ -35,8 +35,9 @@ bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msg
/// Read from an Arduino File
bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
{
+ bool status = false;
+#ifndef NO_ESP32
File *file = (File *)stream->state;
- bool status;
if (buf == NULL) {
while (count-- && file->read() != EOF)
@@ -48,14 +49,18 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
if (file->available() == 0)
stream->bytes_left = 0;
-
+#endif
return status;
}
/// Write to an arduino file
bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
+#ifndef NO_ESP32
File *file = (File *)stream->state;
// DEBUG_MSG("writing %d bytes to protobuf file\n", count);
return file->write(buf, count) == count;
+#else
+ return false;
+#endif
}
diff --git a/src/rf95/MemoryPool.h b/src/rf95/MemoryPool.h
index babcd2225..a0033d9d8 100644
--- a/src/rf95/MemoryPool.h
+++ b/src/rf95/MemoryPool.h
@@ -24,7 +24,7 @@ template class MemoryPool
buf = new T[maxElements];
// prefill dead
- for (int i = 0; i < maxElements; i++)
+ for (size_t i = 0; i < maxElements; i++)
release(&buf[i]);
}
@@ -65,7 +65,7 @@ template class MemoryPool
{
assert(dead.enqueue(p, 0));
assert(p >= buf &&
- (p - buf) <
+ (size_t) (p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
}
@@ -74,7 +74,7 @@ template class MemoryPool
{
assert(dead.enqueueFromISR(p, higherPriWoken));
assert(p >= buf &&
- (p - buf) <
+ (size_t) (p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
}
};
diff --git a/src/rf95/RHutil/atomic.h b/src/rf95/RHutil/atomic.h
new file mode 100644
index 000000000..019219827
--- /dev/null
+++ b/src/rf95/RHutil/atomic.h
@@ -0,0 +1,71 @@
+/*
+* This is port of Dean Camera's ATOMIC_BLOCK macros for AVR to ARM Cortex M3
+* v1.0
+* Mark Pendrith, Nov 27, 2012.
+*
+* From Mark:
+* >When I ported the macros I emailed Dean to ask what attribution would be
+* >appropriate, and here is his response:
+* >
+* >>Mark,
+* >>I think it's great that you've ported the macros; consider them
+* >>public domain, to do with whatever you wish. I hope you find them >useful .
+* >>
+* >>Cheers!
+* >>- Dean
+*/
+
+#ifdef __arm__
+#ifndef _CORTEX_M3_ATOMIC_H_
+#define _CORTEX_M3_ATOMIC_H_
+
+static __inline__ uint32_t __get_primask(void) \
+{ uint32_t primask = 0; \
+ __asm__ volatile ("MRS %[result], PRIMASK\n\t":[result]"=r"(primask)::); \
+ return primask; } // returns 0 if interrupts enabled, 1 if disabled
+
+static __inline__ void __set_primask(uint32_t setval) \
+{ __asm__ volatile ("MSR PRIMASK, %[value]\n\t""dmb\n\t""dsb\n\t""isb\n\t"::[value]"r"(setval):);
+ __asm__ volatile ("" ::: "memory");}
+
+static __inline__ uint32_t __iSeiRetVal(void) \
+{ __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
+ __asm__ volatile ("" ::: "memory"); return 1; }
+
+static __inline__ uint32_t __iCliRetVal(void) \
+{ __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
+ __asm__ volatile ("" ::: "memory"); return 1; }
+
+static __inline__ void __iSeiParam(const uint32_t *__s) \
+{ __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
+ __asm__ volatile ("" ::: "memory"); (void)__s; }
+
+static __inline__ void __iCliParam(const uint32_t *__s) \
+{ __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
+ __asm__ volatile ("" ::: "memory"); (void)__s; }
+
+static __inline__ void __iRestore(const uint32_t *__s) \
+{ __set_primask(*__s); __asm__ volatile ("dmb\n\t""dsb\n\t""isb\n\t"); \
+ __asm__ volatile ("" ::: "memory"); }
+
+
+#define ATOMIC_BLOCK(type) \
+for ( type, __ToDo = __iCliRetVal(); __ToDo ; __ToDo = 0 )
+
+#define ATOMIC_RESTORESTATE \
+uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask()
+
+#define ATOMIC_FORCEON \
+uint32_t primask_save __attribute__((__cleanup__(__iSeiParam))) = 0
+
+#define NONATOMIC_BLOCK(type) \
+for ( type, __ToDo = __iSeiRetVal(); __ToDo ; __ToDo = 0 )
+
+#define NONATOMIC_RESTORESTATE \
+uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask()
+
+#define NONATOMIC_FORCEOFF \
+uint32_t primask_save __attribute__((__cleanup__(__iCliParam))) = 0
+
+#endif
+#endif
diff --git a/src/rf95/TypedQueue.h b/src/rf95/TypedQueue.h
index 6dfdc8e4f..a16e624f9 100644
--- a/src/rf95/TypedQueue.h
+++ b/src/rf95/TypedQueue.h
@@ -3,8 +3,7 @@
#include
#include
-#include
-#include
+#include "freertosinc.h"
/**
* A wrapper for freertos queues. Note: each element object should be small
diff --git a/src/screen.h b/src/screen.h
index 6d088b1f9..45b6a694a 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -9,6 +9,7 @@
#include "TypedQueue.h"
#include "lock.h"
#include "power.h"
+#include
namespace meshtastic
{
diff --git a/src/sleep.cpp b/src/sleep.cpp
index 0ae911b04..0459dbe7a 100644
--- a/src/sleep.cpp
+++ b/src/sleep.cpp
@@ -6,16 +6,20 @@
#include "Periodic.h"
#include "configuration.h"
#include "error.h"
-#include "esp32/pm.h"
-#include "esp_pm.h"
+
#include "main.h"
-#include "rom/rtc.h"
#include "target_specific.h"
#include
-#include
#ifndef NO_ESP32
+#include "rom/rtc.h"
+#include "esp32/pm.h"
+#include "esp_pm.h"
+#include
+
#include "BluetoothUtil.h"
+
+esp_sleep_source_t wakeCause; // the reason we booted this time
#endif
#ifdef TBEAM_V10
@@ -31,7 +35,6 @@ Observable notifySleep, notifyDeepSleep;
// deep sleep support
RTC_DATA_ATTR int bootCount = 0;
-esp_sleep_source_t wakeCause; // the reason we booted this time
#define xstr(s) str(s)
#define str(s) #s
@@ -48,14 +51,16 @@ esp_sleep_source_t wakeCause; // the reason we booted this time
*/
void setCPUFast(bool on)
{
+#ifndef NO_ESP32
setCpuFrequencyMhz(on ? 240 : 80);
+#endif
}
void setLed(bool ledOn)
{
#ifdef LED_PIN
// toggle the led so we can get some rough sense of how often loop is pausing
- digitalWrite(LED_PIN, ledOn);
+ digitalWrite(LED_PIN, ledOn ^ LED_INVERTED);
#endif
#ifdef TBEAM_V10
@@ -79,6 +84,7 @@ void setGPSPower(bool on)
// Perform power on init that we do on each wake from deep sleep
void initDeepSleep()
{
+#ifndef NO_ESP32
bootCount++;
wakeCause = esp_sleep_get_wakeup_cause();
/*
@@ -106,6 +112,7 @@ void initDeepSleep()
reason = "timeout";
DEBUG_MSG("booted, wake cause %d (boot count %d), reset_reason=%s\n", wakeCause, bootCount, reason);
+#endif
}
/// return true if sleep is allowed
@@ -148,6 +155,7 @@ void doDeepSleep(uint64_t msecToWake)
{
DEBUG_MSG("Entering deep sleep for %llu seconds\n", msecToWake / 1000);
+#ifndef NO_ESP32
// not using wifi yet, but once we are this is needed to shutoff the radio hw
// esp_wifi_stop();
waitEnterSleep();
@@ -232,8 +240,10 @@ void doDeepSleep(uint64_t msecToWake)
esp_sleep_enable_timer_wakeup(msecToWake * 1000ULL); // call expects usecs
esp_deep_sleep_start(); // TBD mA sleep current (battery)
+#endif
}
+#ifndef NO_ESP32
/**
* enter light sleep (preserves ram but stops everything about CPU).
*
@@ -274,6 +284,7 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
// digitalRead(PMU_IRQ));
return esp_sleep_get_wakeup_cause();
}
+#endif
#if 0
// not legal on the stock android ESP build
diff --git a/src/sleep.h b/src/sleep.h
index e63fa70a6..b3446882a 100644
--- a/src/sleep.h
+++ b/src/sleep.h
@@ -2,10 +2,15 @@
#include "Arduino.h"
#include "Observer.h"
-#include "esp_sleep.h"
+#include "configuration.h"
void doDeepSleep(uint64_t msecToWake);
+#ifndef NO_ESP32
+#include "esp_sleep.h"
esp_sleep_wakeup_cause_t doLightSleep(uint64_t msecToWake);
+
+extern esp_sleep_source_t wakeCause;
+#endif
void setGPSPower(bool on);
// Perform power on init that we do on each wake from deep sleep
@@ -15,7 +20,6 @@ void setCPUFast(bool on);
void setLed(bool ledOn);
extern int bootCount;
-extern esp_sleep_source_t wakeCause;
// is bluetooth sw currently running?
extern bool bluetoothOn;