From fe3cbeed3a5d678672f8b43e9ed36fdd377eef6f Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 23 Apr 2020 12:47:41 -0700 Subject: [PATCH] misc NRF52 fixes --- .vscode/launch.json | 10 ++++++---- platformio.ini | 2 +- src/MeshTypes.h | 1 + src/Observer.h | 3 +-- src/bare/main-nrf52.cpp | 13 +++++++++++++ src/rf95/RH_RF95.cpp | 5 +++++ src/rf95/RadioInterface.h | 10 ++++++++++ 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/bare/main-nrf52.cpp 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/platformio.ini b/platformio.ini index d4b105129..83f6adac5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam +default_envs = bare [common] ; common is not currently used diff --git a/src/MeshTypes.h b/src/MeshTypes.h index ab4203e66..0d9783e14 100644 --- a/src/MeshTypes.h +++ b/src/MeshTypes.h @@ -11,6 +11,7 @@ typedef uint8_t PacketId; // A packet sequence number #define NODENUM_BROADCAST 255 #define ERRNO_OK 0 +#define ERRNO_NO_INTERFACES 33 #define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER typedef int ErrorCode; diff --git a/src/Observer.h b/src/Observer.h index 0c0cb9a92..701495b38 100644 --- a/src/Observer.h +++ b/src/Observer.h @@ -1,7 +1,7 @@ #pragma once #include - +#include #include template class Observable; @@ -14,7 +14,6 @@ template class Observer Observable *observed = NULL; public: - virtual ~Observer(); void observe(Observable *o); diff --git a/src/bare/main-nrf52.cpp b/src/bare/main-nrf52.cpp new file mode 100644 index 000000000..1ccb79615 --- /dev/null +++ b/src/bare/main-nrf52.cpp @@ -0,0 +1,13 @@ +#include + +static inline void debugger_break(void) +{ + __asm volatile("bkpt #0x01\n\t" + "mov pc, lr\n\t"); +} + +// handle standard gcc assert failures +void __attribute__((noreturn)) __assert_func(const char *file, int line, const char *func, const char *failedexpr) +{ + debugger_break(); +} \ No newline at end of file diff --git a/src/rf95/RH_RF95.cpp b/src/rf95/RH_RF95.cpp index 14a2f1826..a5d6b47a7 100644 --- a/src/rf95/RH_RF95.cpp +++ b/src/rf95/RH_RF95.cpp @@ -114,6 +114,11 @@ bool RH_RF95::init() return enableInterrupt(); } +// If on a platform without level trigger definitions, just use RISING and suck it up. +#ifndef ONHIGH +#define ONHIGH RISING +#endif + bool RH_RF95::enableInterrupt() { // Determine the interrupt number that corresponds to the interruptPin diff --git a/src/rf95/RadioInterface.h b/src/rf95/RadioInterface.h index ec7dfce42..bad532a1e 100644 --- a/src/rf95/RadioInterface.h +++ b/src/rf95/RadioInterface.h @@ -39,6 +39,16 @@ class RadioInterface virtual void loop() {} // Idle processing + /** + * Return true if we think the board can go to sleep (i.e. our tx queue is empty, we are not sending or receiving) + * + * This method must be used before putting the CPU into deep or light sleep. + */ + bool canSleep() { return true; } + + /// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep. + virtual bool sleep() { return true; } + /** * Send a packet (possibly by enquing in a private fifo). This routine will * later free() the packet to pool. This routine is not allowed to stall.