sforkowany z mirror/meshtastic-firmware
Fixed compilation on nrf52 and brownout code
rodzic
b20b21c553
commit
ddcfff3b59
|
@ -64,6 +64,7 @@ debug_tool = jlink
|
|||
; monitor adapter_khz 10000
|
||||
|
||||
lib_deps =
|
||||
https://github.com/meshtastic/esp8266-oled-ssd1306.git#35d796226b853b0c0ff818b2f1aa3d35e7296a96 ; ESP8266_SSD1306
|
||||
https://github.com/geeksville/OneButton.git ; OneButton library for non-blocking button debounce
|
||||
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
|
||||
https://github.com/meshtastic/arduino-fsm.git#55c47b6cded91645aff05a27b6e5821d8d0f64be
|
||||
|
@ -102,7 +103,6 @@ build_flags =
|
|||
lib_deps =
|
||||
${arduino_base.lib_deps}
|
||||
https://github.com/meshtastic/esp32_https_server.git
|
||||
https://github.com/meshtastic/esp8266-oled-ssd1306.git#35d796226b853b0c0ff818b2f1aa3d35e7296a96 ; ESP8266_SSD1306
|
||||
adafruit/DHT sensor library@^1.4.1
|
||||
adafruit/Adafruit Unified Sensor@^1.1.4
|
||||
# Hmm - this doesn't work yet
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "mesh/MeshTypes.h"
|
||||
#include <vector>
|
||||
|
||||
#ifndef NO_SCREEN
|
||||
#include <OLEDDisplay.h>
|
||||
#include <OLEDDisplayUi.h>
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
/** A baseclass for any mesh "plugin".
|
||||
*
|
||||
* A plugin allows you to add new features to meshtastic device code, without needing to know messaging details.
|
||||
|
@ -31,9 +35,9 @@ class MeshPlugin
|
|||
static void callPlugins(const MeshPacket &mp);
|
||||
|
||||
static std::vector<MeshPlugin *> GetMeshPluginsWithUIFrames();
|
||||
|
||||
#ifndef NO_SCREEN
|
||||
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { return; }
|
||||
|
||||
#endif
|
||||
protected:
|
||||
const char *name;
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#include "NRF52Bluetooth.h"
|
||||
#include "configuration.h"
|
||||
#include "error.h"
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <assert.h>
|
||||
|
@ -8,184 +5,182 @@
|
|||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
// #include <nrf52840.h>
|
||||
#include "NRF52Bluetooth.h"
|
||||
#include "configuration.h"
|
||||
#include "error.h"
|
||||
|
||||
#ifdef BQ25703A_ADDR
|
||||
#include "BQ25713.h"
|
||||
#endif
|
||||
|
||||
// #define USE_SOFTDEVICE
|
||||
|
||||
static inline void debugger_break(void)
|
||||
{
|
||||
__asm volatile("bkpt #0x01\n\t"
|
||||
"mov pc, lr\n\t");
|
||||
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)
|
||||
{
|
||||
DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func, failedexpr);
|
||||
// debugger_break(); FIXME doesn't work, possibly not for segger
|
||||
while (1)
|
||||
; // FIXME, reboot!
|
||||
void __attribute__((noreturn))
|
||||
__assert_func(const char *file, int line, const char *func,
|
||||
const char *failedexpr) {
|
||||
DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func,
|
||||
failedexpr);
|
||||
// debugger_break(); FIXME doesn't work, possibly not for segger
|
||||
while (1)
|
||||
; // FIXME, reboot!
|
||||
}
|
||||
|
||||
void getMacAddr(uint8_t *dmac)
|
||||
{
|
||||
ble_gap_addr_t addr;
|
||||
|
||||
#ifdef USE_SOFTDEVICE
|
||||
uint32_t res = sd_ble_gap_addr_get(&addr);
|
||||
assert(res == NRF_SUCCESS);
|
||||
void getMacAddr(uint8_t *dmac) {
|
||||
ble_gap_addr_t addr;
|
||||
if (sd_ble_gap_addr_get(&addr) == NRF_SUCCESS) {
|
||||
memcpy(dmac, addr.addr, 6);
|
||||
#else
|
||||
} else {
|
||||
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
|
||||
#endif
|
||||
dmac[0] = src[5] |
|
||||
0xc0; // MSB high two bits get set elsewhere in the bluetooth stack
|
||||
}
|
||||
}
|
||||
|
||||
NRF52Bluetooth *nrf52Bluetooth;
|
||||
|
||||
static bool bleOn = false;
|
||||
static const bool useSoftDevice = false; // Set to false for easier debugging
|
||||
static const bool useSoftDevice = true; // Set to false for easier debugging
|
||||
|
||||
void setBluetoothEnable(bool on)
|
||||
{
|
||||
if (on != bleOn) {
|
||||
if (on) {
|
||||
if (!nrf52Bluetooth) {
|
||||
if (!useSoftDevice)
|
||||
DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||
else {
|
||||
nrf52Bluetooth = new NRF52Bluetooth();
|
||||
nrf52Bluetooth->setup();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nrf52Bluetooth)
|
||||
nrf52Bluetooth->shutdown();
|
||||
void setBluetoothEnable(bool on) {
|
||||
if (on != bleOn) {
|
||||
if (on) {
|
||||
if (!nrf52Bluetooth) {
|
||||
if (!useSoftDevice)
|
||||
DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||
else {
|
||||
nrf52Bluetooth = new NRF52Bluetooth();
|
||||
nrf52Bluetooth->setup();
|
||||
}
|
||||
bleOn = on;
|
||||
}
|
||||
} else {
|
||||
if (nrf52Bluetooth) nrf52Bluetooth->shutdown();
|
||||
}
|
||||
bleOn = on;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override printf to use the SEGGER output library
|
||||
*/
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
#include "BQ25713.h"
|
||||
void initBrownout() {
|
||||
auto vccthresh = POWER_POFCON_THRESHOLD_V28;
|
||||
|
||||
void initBrownout()
|
||||
{
|
||||
auto vccthresh = POWER_POFCON_THRESHOLD_V28;
|
||||
if (useSoftDevice) {
|
||||
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);
|
||||
} else {
|
||||
uint32_t pof_flags = POWER_POFCON_POF_Enabled | (vccthresh << POWER_POFCON_THRESHOLD_Pos);
|
||||
|
||||
#ifdef POWER_POFCON_THRESHOLDVDDH_Msk
|
||||
auto vcchthresh = POWER_POFCON_THRESHOLDVDDH_V27;
|
||||
pof_flags |= (vcchthresh << POWER_POFCON_THRESHOLDVDDH_Pos);
|
||||
#endif
|
||||
|
||||
if (useSoftDevice) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
NRF_POWER->POFCON = POWER_POFCON_POF_Msk | (vccthresh << POWER_POFCON_THRESHOLD_Pos) | (vcchthresh << POWER_POFCON_THRESHOLDVDDH_Pos);
|
||||
}
|
||||
NRF_POWER->POFCON = pof_flags;
|
||||
}
|
||||
}
|
||||
|
||||
void checkSDEvents()
|
||||
{
|
||||
if (useSoftDevice) {
|
||||
uint32_t evt;
|
||||
while (NRF_ERROR_NOT_FOUND == sd_evt_get(&evt)) {
|
||||
switch (evt) {
|
||||
case NRF_EVT_POWER_FAILURE_WARNING:
|
||||
recordCriticalError(CriticalErrorCode_Brownout);
|
||||
break;
|
||||
void checkSDEvents() {
|
||||
if (useSoftDevice) {
|
||||
uint32_t evt;
|
||||
while (NRF_SUCCESS == sd_evt_get(&evt)) {
|
||||
switch (evt) {
|
||||
case NRF_EVT_POWER_FAILURE_WARNING:
|
||||
recordCriticalError(CriticalErrorCode_Brownout);
|
||||
break;
|
||||
|
||||
default:
|
||||
DEBUG_MSG("Unexpected SDevt %d\n", evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(NRF_POWER->EVENTS_POFWARN)
|
||||
recordCriticalError(CriticalErrorCode_Brownout);
|
||||
default:
|
||||
DEBUG_MSG("Unexpected SDevt %d\n", evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (NRF_POWER->EVENTS_POFWARN)
|
||||
recordCriticalError(CriticalErrorCode_Brownout);
|
||||
}
|
||||
}
|
||||
|
||||
void nrf52Loop()
|
||||
{
|
||||
checkSDEvents();
|
||||
}
|
||||
void nrf52Loop() { checkSDEvents(); }
|
||||
|
||||
void nrf52Setup()
|
||||
{
|
||||
void nrf52Setup() {
|
||||
auto why = NRF_POWER->RESETREAS;
|
||||
// per
|
||||
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html
|
||||
DEBUG_MSG("Reset reason: 0x%x\n", why);
|
||||
|
||||
auto why = NRF_POWER->RESETREAS;
|
||||
// per https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html
|
||||
DEBUG_MSG("Reset reason: 0x%x\n", why);
|
||||
|
||||
// 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);
|
||||
// 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);
|
||||
|
||||
#ifdef BQ25703A_ADDR
|
||||
auto *bq = new BQ25713();
|
||||
if (!bq->setup())
|
||||
DEBUG_MSG("ERROR! Charge controller init failed\n");
|
||||
auto *bq = new BQ25713();
|
||||
if (!bq->setup()) DEBUG_MSG("ERROR! Charge controller init failed\n");
|
||||
#endif
|
||||
|
||||
// Init random seed
|
||||
// FIXME - use this to get random numbers
|
||||
// #include "nrf_rng.h"
|
||||
// uint32_t r;
|
||||
// ble_controller_rand_vector_get_blocking(&r, sizeof(r));
|
||||
// randomSeed(r);
|
||||
DEBUG_MSG("FIXME, call randomSeed\n");
|
||||
// ::printf("TESTING PRINTF\n");
|
||||
// Init random seed
|
||||
// FIXME - use this to get random numbers
|
||||
// #include "nrf_rng.h"
|
||||
// uint32_t r;
|
||||
// ble_controller_rand_vector_get_blocking(&r, sizeof(r));
|
||||
// randomSeed(r);
|
||||
DEBUG_MSG("FIXME, call randomSeed\n");
|
||||
// ::printf("TESTING PRINTF\n");
|
||||
|
||||
initBrownout();
|
||||
initBrownout();
|
||||
}
|
||||
|
||||
void cpuDeepSleep(uint64_t msecToWake)
|
||||
{
|
||||
// FIXME, configure RTC or button press to wake us
|
||||
// FIXME, power down SPI, I2C, RAMs
|
||||
#if WIRE_INTERFACES_COUNT > 0
|
||||
Wire.end();
|
||||
#endif
|
||||
SPI.end();
|
||||
Serial.end();
|
||||
void cpuDeepSleep(uint64_t msecToWake) {
|
||||
// FIXME, configure RTC or button press to wake us
|
||||
// FIXME, power down SPI, I2C, RAMs
|
||||
#if WIRE_INTERFACES_COUNT > 0
|
||||
Wire.end();
|
||||
#endif
|
||||
SPI.end();
|
||||
// This may cause crashes as debug messages continue to flow.
|
||||
Serial.end();
|
||||
|
||||
#ifdef PIN_SERIAL_RX1
|
||||
Serial1.end();
|
||||
#endif
|
||||
#ifdef PIN_SERIAL_RX1
|
||||
Serial1.end();
|
||||
#endif
|
||||
setBluetoothEnable(false);
|
||||
// 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
|
||||
|
||||
// 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
|
||||
auto ok = sd_power_system_off();
|
||||
if (ok != NRF_SUCCESS) {
|
||||
DEBUG_MSG(
|
||||
"FIXME: Ignoring soft device (EasyDMA pending?) and forcing "
|
||||
"system-off!\n");
|
||||
NRF_POWER->SYSTEMOFF = 1;
|
||||
}
|
||||
|
||||
auto ok = sd_power_system_off();
|
||||
if (ok != NRF_SUCCESS) {
|
||||
DEBUG_MSG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n");
|
||||
NRF_POWER->SYSTEMOFF = 1;
|
||||
}
|
||||
|
||||
// The following code should not be run, because we are off
|
||||
while (1) {
|
||||
delay(5000);
|
||||
DEBUG_MSG(".");
|
||||
}
|
||||
// The following code should not be run, because we are off
|
||||
while (1) {
|
||||
delay(5000);
|
||||
DEBUG_MSG(".");
|
||||
}
|
||||
}
|
|
@ -19,12 +19,13 @@
|
|||
#ifndef _VARIANT_LORA_ISP4520_
|
||||
#define _VARIANT_LORA_ISP4520_
|
||||
|
||||
#define HW_VERSION_US
|
||||
#define HW_VERSION_US 1
|
||||
#undef HW_VERSION
|
||||
#define HW_VERSION "0.1.0"
|
||||
#define HW_VERSION "1.0"
|
||||
#undef HW_VENDOR
|
||||
#define HW_VENDOR "lora_ISP4520"
|
||||
|
||||
#define USE_SEGGER
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
@ -33,7 +34,7 @@
|
|||
|
||||
#define USE_LFXO
|
||||
|
||||
#define USE_SEGGER
|
||||
//#define USE_SEGGER
|
||||
|
||||
// Number of pins defined in PinDescription array
|
||||
#define PINS_COUNT (16)
|
||||
|
|
Ładowanie…
Reference in New Issue