Browse Source

Arduino Nesso N1: header/cpp rearrange + attempting to debug crash

pull/1117/head
Ashley 7 months ago
parent
commit
b4b844b067
  1. 50
      variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp
  2. 25
      variants/arduino_nesso_n1/ArduinoNessoN1Board.h
  3. 7
      variants/arduino_nesso_n1/expander.cpp
  4. 20
      variants/arduino_nesso_n1/platformio.ini
  5. 31
      variants/arduino_nesso_n1/target.cpp

50
variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp

@ -0,0 +1,50 @@
#include "ArduinoNessoN1Board.h"
#include <Arduino.h>
void ArduinoNessoN1Board::begin() {
ESP32Board::begin();
#ifdef MESH_DEBUG
// delay for 2s after boot to ensure early output below makes it to the serial logger
delay(2000);
#endif
#ifdef P_LORA_TX_LED
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): setup TX LED mode");
pinMode(P_LORA_TX_LED, OUTPUT);
digitalWrite(P_LORA_TX_LED, HIGH);
#endif
battery.enableCharge();
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): set Nesso N1 pin modes and default states...");
pinMode(LORA_ENABLE, OUTPUT); // RESET
pinMode(LORA_ANTENNA_SWITCH, OUTPUT); // ANTENNA_SWITCH
pinMode(LORA_LNA_ENABLE, OUTPUT); // LNA_ENABLE
pinMode(LCD_BACKLIGHT, OUTPUT);
pinMode(BEEP_PIN, OUTPUT);
// Toggle LoRa reset via expander
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Enable LoRa...");
digitalWrite(LORA_ENABLE, LOW);
delay(10);
digitalWrite(LORA_ENABLE, HIGH);
// Configure antenna switch and LNA
digitalWrite(LORA_ANTENNA_SWITCH, HIGH); // enable antenna switch
digitalWrite(LORA_LNA_ENABLE, HIGH); // enable LNA
// Configure initial state of further devices on expander
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Set LCD_BACKLIGHT and BEEP_PIN to low initial state...");
digitalWrite(LCD_BACKLIGHT, LOW);
digitalWrite(BEEP_PIN, LOW);
// Toggle LCD backlight to show the device has powered on until we get the screen working
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Now high...");
digitalWrite(LCD_BACKLIGHT, HIGH);
digitalWrite(BEEP_PIN, HIGH);
delay(2000);
digitalWrite(LCD_BACKLIGHT, LOW);
digitalWrite(BEEP_PIN, LOW);
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Now low...");
}

25
variants/arduino_nesso_n1/ArduinoNessoN1Board.h

@ -1,32 +1,20 @@
#pragma once
#include <Arduino.h>
#include <MeshCore.h>
#include <helpers/ESP32Board.h>
#include "pins_arduino.h"
#define P_LORA_TX_LED LED_BUILTIN
#define P_LORA_TX_LED LED_BUILTIN // defined in pins_arduino.h / expander.cpp through pin handling functions specific to the IO expander
// #define PIN_TFT_RST LCD_RESET
// #define PIN_TFT_LEDA_CTL LCD_BACKLIGHT
class ArduinoNessoN1Board : public ESP32Board {
private:
NessoBattery battery;
public:
void begin() {
ESP32Board::begin();
#ifdef MESH_DEBUG
// delay for 2s after boot to ensure early output below makes it to the serial logger
delay(2000);
#endif
#ifdef P_LORA_TX_LED
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): setup TX LED mode");
pinMode(P_LORA_TX_LED, OUTPUT);
digitalWrite(P_LORA_TX_LED, HIGH);
#endif
battery.enableCharge();
}
public:
void begin(); // Defined in ArduinoNessoN1Board.cpp
#ifdef P_LORA_TX_LED
void onBeforeTransmit() override {
@ -46,6 +34,11 @@ public:
uint16_t getBattMilliVolts() override {
return battery.getMilliVoltage();
}
void reboot() override {
MESH_DEBUG_PRINTLN("ArduinoNessoN1.reboot(): noop() instead");
// esp_restart();
}
};

7
variants/arduino_nesso_n1/expander.cpp

@ -1,3 +1,4 @@
#pragma once
// Based off here https://github.com/espressif/arduino-esp32/blob/d1eb62d7c6dda16c254c374504aa93188d7c386b/variants/arduino_nesso_n1/expander.cpp
// Should be OK based on this? https://opensource.stackexchange.com/a/6406
@ -25,6 +26,7 @@ static uint8_t readRegister(uint8_t address, uint8_t reg) {
}
static void writeBitRegister(uint8_t address, uint8_t reg, uint8_t bit, uint8_t value) {
MESH_DEBUG_PRINTLN("ExpanderPin writeBitRegister(address=%u, reg=%u, bit=%u, value=%u)", address, reg, bit, value);
uint8_t val = readRegister(address, reg);
if (value) {
writeRegister(address, reg, val | (1 << bit));
@ -34,6 +36,7 @@ static void writeBitRegister(uint8_t address, uint8_t reg, uint8_t bit, uint8_t
}
static bool readBitRegister(uint8_t address, uint8_t reg, uint8_t bit) {
MESH_DEBUG_PRINTLN("ExpanderPin readBitRegister(address=%u, reg=%u, bit=%u)", address, reg, bit);
uint8_t val = readRegister(address, reg);
return ((val & (1 << bit)) > 0);
}
@ -54,6 +57,7 @@ void pinMode(ExpanderPin pin, uint8_t mode) {
writeRegister(pin.address, 0x3, 0);
expanderInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin pinMode(pin=%u, mode=%u)", pin.pin, mode);
writeBitRegister(pin.address, 0x3, pin.pin, mode == OUTPUT);
if (mode == OUTPUT) {
// remove high impedance
@ -77,6 +81,7 @@ void digitalWrite(ExpanderPin pin, uint8_t val) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin digitalWrite(%u)", pin.pin);
writeBitRegister(pin.address, 0x5, pin.pin, val == HIGH);
}
@ -85,6 +90,7 @@ int digitalRead(ExpanderPin pin) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin digitalRead(%u)", pin.pin);
return readBitRegister(pin.address, 0xF, pin.pin);
}
@ -132,6 +138,7 @@ uint16_t NessoBattery::getChargeLevel() {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("NessoBattery::getChargeLevel()");
uint16_t current_capacity = readRegister(0x55, 0x11) << 8 | readRegister(0x55, 0x10);
uint16_t total_capacity = readRegister(0x55, 0x13) << 8 | readRegister(0x55, 0x12);
return (current_capacity * 100) / total_capacity;

20
variants/arduino_nesso_n1/platformio.ini

@ -5,23 +5,23 @@ board_build.partitions = min_spiffs.csv ; get around 4mb flash limit
build_flags =
${esp32c6_base.build_flags}
-I variants/arduino_nesso_n1
; -D MESH_DEBUG=1
; -D ARDUINO=1
-D MESH_DEBUG=1
-D ARDUINO=1
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_MODE=1
; -D P_LORA_TX_LED= ; Only an IR LED, so disabled for now
; -D P_LORA_TX_LED= ; Defined in ArduinoNessoN1Board.h
-D P_LORA_SCLK=20
-D P_LORA_MISO=22
-D P_LORA_MOSI=21
-D P_LORA_NSS=23 ; aka LORA_CS on the Nesso N1 schematic
-D P_LORA_DIO_1=15 ; aka LORA_IRQ on the Nesso N1 schematic
-D P_LORA_BUSY=19
; -D P_LORA_RESET=2 ; ToDo: Required, is on an IO expander: E0.P7 (Address 0x43)
; -D P_LORA_RESET=-1 ; Enabled in ArduinoNessoN1Board.cpp instead
-D PIN_BOARD_SDA=10
-D PIN_BOARD_SCL=8
; -D SX126X_RXEN=23 ; ToDo: not sure
-D SX126X_DIO2_AS_RF_SWITCH=true
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
; -D SX126X_DIO2_AS_RF_SWITCH=true
; -D SX126X_DIO3_TCXO_VOLTAGE=1.8
-D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1
-D RADIO_CLASS=CustomSX1262
@ -47,17 +47,17 @@ build_flags =
; -D DISPLAY_CLASS=ST7789Display
-D DISABLE_WIFI_OTA=1
build_src_filter = ${esp32c6_base.build_src_filter}
+<../variants/arduino_nesso_n1>
+<expander.cpp>
+<ArduinoNessoN1Board.cpp>
+<../variants/arduino_nesso_n1>
[env:Arduino_Nesso_N1_repeater_]
[env:Arduino_Nesso_N1_repeater]
extends = Arduino_Nesso_N1
build_src_filter = ${Arduino_Nesso_N1.build_src_filter}
+<../examples/simple_repeater/*.cpp>
build_flags =
${Arduino_Nesso_N1.build_flags}
-D ADVERT_NAME='"Xiao C6 Repeater"'
-D ADVERT_NAME='"Arduino Nesso N1 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
@ -68,7 +68,7 @@ lib_deps =
${Arduino_Nesso_N1.lib_deps}
; ${esp32_ota.lib_deps}
[env:Arduino_Nesso_N1_companion_radio_ble_]
[env:Arduino_Nesso_N1_companion_radio_ble]
extends = Arduino_Nesso_N1
build_flags = ${Arduino_Nesso_N1.build_flags}
-D MAX_CONTACTS=350

31
variants/arduino_nesso_n1/target.cpp

@ -1,12 +1,11 @@
#include <Arduino.h>
#include "target.h"
#include "pins_arduino.h"
ArduinoNessoN1Board board;
#if defined(P_LORA_SCLK)
static SPIClass spi(0);
// replace P_LORA_RESET with -1 to indicate RESET is handled outside
// replace P_LORA_RESET with -1 to indicate RESET is handled elsewhere (which is in ArduinoNessoN1Board.cpp)
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, -1, P_LORA_BUSY, spi);
#else
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, -1, P_LORA_BUSY);
@ -23,34 +22,6 @@ bool radio_init() {
fallback_clock.begin();
rtc_clock.begin(Wire);
MESH_DEBUG_PRINTLN("set Nesso N1 pin modes and default states...");
pinMode(LORA_ENABLE, OUTPUT); // RESET
pinMode(LORA_ANTENNA_SWITCH, OUTPUT); // ANTENNA_SWITCH
pinMode(LORA_LNA_ENABLE, OUTPUT); // LNA_ENABLE
pinMode(LCD_BACKLIGHT, OUTPUT);
pinMode(BEEP_PIN, OUTPUT);
// Toggle LoRa reset via expander
MESH_DEBUG_PRINTLN("Enable LoRa...");
digitalWrite(LORA_ENABLE, LOW);
delay(10);
digitalWrite(LORA_ENABLE, HIGH);
// Configure antenna switch and LNA
digitalWrite(LORA_ANTENNA_SWITCH, HIGH); // enable antenna switch
digitalWrite(LORA_LNA_ENABLE, HIGH); // enable LNA
// Configure initial state of further devices on expander
digitalWrite(LCD_BACKLIGHT, LOW);
digitalWrite(BEEP_PIN, LOW);
// Toggle LCD backlight to show the device has powered on until we get the screen working
digitalWrite(LCD_BACKLIGHT, HIGH);
// digitalWrite(BEEP_PIN, HIGH);
delay(2000);
digitalWrite(LCD_BACKLIGHT, LOW);
// digitalWrite(BEEP_PIN, LOW);
MESH_DEBUG_PRINTLN("radio.std_init() and return...");
#if defined(P_LORA_SCLK)
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);

Loading…
Cancel
Save