Browse Source

Merge b89e529300 into 5f3b7f25d0

pull/1117/merge
Ashley 18 hours ago
committed by GitHub
parent
commit
3d5e5c430d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 54
      variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp
  2. 50
      variants/arduino_nesso_n1/ArduinoNessoN1Board.h
  3. 235
      variants/arduino_nesso_n1/expander.cpp
  4. 107
      variants/arduino_nesso_n1/pins_arduino.h
  5. 89
      variants/arduino_nesso_n1/platformio.ini
  6. 54
      variants/arduino_nesso_n1/target.cpp
  7. 22
      variants/arduino_nesso_n1/target.h

54
variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp

@ -0,0 +1,54 @@
#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.begin();
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);
#ifdef MESH_DEBUG
// Toggle LCD backlight to show the device has powered on until we get the screen working
// Only do this if in debug mode, since the delay is quite long
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...");
#endif
}

50
variants/arduino_nesso_n1/ArduinoNessoN1Board.h

@ -0,0 +1,50 @@
#pragma once
#include <Arduino.h>
#include <MeshCore.h>
#include <helpers/ESP32Board.h>
#include "pins_arduino.h"
#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(); // Defined in ArduinoNessoN1Board.cpp
#ifdef P_LORA_TX_LED
void onBeforeTransmit() override {
MESH_DEBUG_PRINTLN("onBeforeTransmit: LOW LED for On");
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
}
void onAfterTransmit() override {
MESH_DEBUG_PRINTLN("onBeforeTransmit: HIGH LED for Off");
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
}
#endif
const char* getManufacturerName() const override {
return "Arduino Nesso N1";
}
uint16_t getBattMilliVolts() override {
#ifdef MESH_DEBUG
MESH_DEBUG_PRINTLN("getBattMilliVolts(): isCharging(): %u", battery.isCharging());
MESH_DEBUG_PRINTLN("getBattMilliVolts(): Current charge level %u %%", battery.getChargeLevel());
MESH_DEBUG_PRINTLN("getBattMilliVolts(): Current voltage %f V", battery.getVoltage());
MESH_DEBUG_PRINTLN("getBattMilliVolts(): Current voltage %u mV", battery.getMilliVoltage());
#endif
return battery.getMilliVoltage();
}
void reboot() override {
MESH_DEBUG_PRINTLN("ArduinoNessoN1.reboot(): noop() instead");
// esp_restart();
}
};

235
variants/arduino_nesso_n1/expander.cpp

@ -0,0 +1,235 @@
#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
// Some inspiration from: https://github.com/m5stack/M5Unified/blob/master/src/utility/power/AW32001_Class.cpp
#include "pins_arduino.h"
#include <helpers/ESP32Board.h>
#include <Wire.h>
static bool wireInitialized = true; // initialised in ESP32Board.begin() ; ToDo: Remove all these conditions in future
static bool expanderInitialized = false;
// From https://www.diodes.com/datasheet/download/PI4IOE5V6408.pdf
static void writeRegister(uint8_t address, uint8_t reg, uint8_t value) {
Wire.beginTransmission(address);
Wire.write(reg);
Wire.write(value);
Wire.endTransmission();
}
static uint8_t readRegister(uint8_t address, uint8_t reg) {
Wire.beginTransmission(address);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(address, 1);
return Wire.read();
}
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));
} else {
writeRegister(address, reg, val & ~(1 << bit));
}
}
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);
}
void pinMode(ExpanderPin pin, uint8_t mode) {
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
// reset all registers to default state
}
if (!expanderInitialized) {
writeRegister(pin.address, 0x1, 0x1);
// set all pins as high as default state
writeRegister(pin.address, 0x9, 0xFF);
// interrupt mask to all pins
writeRegister(pin.address, 0x11, 0xFF);
// all input
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
writeBitRegister(pin.address, 0x7, pin.pin, false);
} else if (mode == INPUT_PULLUP) {
// set pull-up resistor
writeBitRegister(pin.address, 0xB, pin.pin, true);
writeBitRegister(pin.address, 0xD, pin.pin, true);
} else if (mode == INPUT_PULLDOWN) {
// disable pull-up resistor
writeBitRegister(pin.address, 0xB, pin.pin, true);
writeBitRegister(pin.address, 0xD, pin.pin, false);
} else if (mode == INPUT) {
// disable pull selector resistor
writeBitRegister(pin.address, 0xB, pin.pin, false);
}
}
void digitalWrite(ExpanderPin pin, uint8_t val) {
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin digitalWrite(%u)", pin.pin);
writeBitRegister(pin.address, 0x5, pin.pin, val == HIGH);
}
int digitalRead(ExpanderPin pin) {
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin digitalRead(%u)", pin.pin);
return readBitRegister(pin.address, 0xF, pin.pin);
}
void NessoBattery::begin() {
// AW32001E - address 0x49
// Spec: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/core/LLM630%20Computer%20Kit/AW32001E.pdf
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
uint8_t val = 0;
val = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHIP_ID);
// coarsely check if chip is actually the right chip
auto res = (val == AW32001_I2C_CHIP_ADDR);
if (res) {
val = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHR_TMR);
#ifdef MESH_DEBUG
// Debug output the WatchDog Timer (wdt) state
MESH_DEBUG_PRINTLN("NessoBattery.begin(): CHR_TMR full register; bits 5,6 are for WDT = %#02x", val);
#endif
// disable WatchDog Timer (wdt)
// take existing register value AND with 00011111
val = val & 0x1f;
writeRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHR_TMR, val);
}
#ifdef MESH_DEBUG
else {
MESH_DEBUG_PRINTLN("NessoBattery.begin(): Register of chip ADDR = %u != I2C of chip %u", AW32001_REG_CHIP_ID, AW32001_I2C_CHIP_ADDR);
}
#endif
// store if chip is initiated by whether it passed above checks and had watchdog disabled
_power_mgmt_init = res;
}
void NessoBattery::enableCharge() {
// AW32001E - address 0x49
// set CEB (charge enable) bit (3) low (0) in AW32001_REG_PWR_CFG (0x01)
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge()");
if (_power_mgmt_init) {
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): _power_mgmt_init = true");
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
bool charge_enable_bit = readBitRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_PWR_CFG, 3);
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge setting (low is on): %u", charge_enable_bit);
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): isCharging(): %u", NessoBattery::isCharging());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge level %u %%", NessoBattery::getChargeLevel());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %f V", NessoBattery::getVoltage());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %u mV", NessoBattery::getMilliVoltage());
writeBitRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_PWR_CFG, 3, false);
}
#ifdef MESH_DEBUG
else {
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): _power_mgmt_init is false, won't enable charge");
}
#endif
}
NessoBattery::ChargeStatus NessoBattery::getChargeStatus(void) {
uint8_t reg_value = 0;
if (_power_mgmt_init)
{
reg_value = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_SYS_STA);
// Extract bits 4 and 3 for charge status
reg_value = (reg_value >> 3) & 0b00000011; // Get bits 4 and 3
MESH_DEBUG_PRINTLN("NessoBattery::getChargeStatus(): bits 4 and 3 from register %#02x = %u", AW32001_REG_SYS_STA, reg_value);
switch (reg_value)
{
case 0b00: return CS_NOT_CHARGING; // Not charging
case 0b01: return CS_PRE_CHARGE; // Pre-charge
case 0b10: return CS_CHARGE; // Charging
case 0b11: return CS_CHARGE_DONE; // Charge done
default: return CS_UNKNOWN; // Unknown state
}
}
MESH_DEBUG_PRINTLN("NessoBattery::getChargeStatus(): failed, probably chip wasn't init");
return CS_UNKNOWN; // Return unknown if read failed
}
bool NessoBattery::isCharging(void)
{
ChargeStatus status = getChargeStatus();
MESH_DEBUG_PRINTLN("NessoBattery::isCharging(): ChargeStatus = %u; is? false0/true1 = %u", status, (status == CS_PRE_CHARGE || status == CS_CHARGE));
return (status == CS_PRE_CHARGE || status == CS_CHARGE);
}
float NessoBattery::getVoltage() {
// BQ27220 - address 0x55
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("NessoBattery::getVoltage()");
uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8);
MESH_DEBUG_PRINTLN("NessoBattery::getVoltage(): %f", voltage / 1000.0f);
return (float)voltage / 1000.0f;
}
uint16_t NessoBattery::getMilliVoltage() {
// BQ27220 - address 0x55
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("NessoBattery::getMilliVoltage()");
uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8);
MESH_DEBUG_PRINTLN("NessoBattery::getMilliVoltage(): %u", voltage);
return voltage;
}
uint16_t NessoBattery::getChargeLevel() {
// BQ27220 - address 0x55
if (!wireInitialized) {
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);
MESH_DEBUG_PRINTLN("NessoBattery::getChargeLevel(): curr = %u / total = %u; pct = %u %%", current_capacity, total_capacity, ((current_capacity * 100) / total_capacity));
return (current_capacity * 100) / total_capacity;
}
ExpanderPin LORA_LNA_ENABLE(5);
ExpanderPin LORA_ANTENNA_SWITCH(6);
ExpanderPin LORA_ENABLE(7);
ExpanderPin KEY1(0);
ExpanderPin KEY2(1);
ExpanderPin POWEROFF((1 << 8) | 0);
ExpanderPin LCD_RESET((1 << 8) | 1);
ExpanderPin GROVE_POWER_EN((1 << 8) | 2);
ExpanderPin VIN_DETECT((1 << 8) | 5);
ExpanderPin LCD_BACKLIGHT((1 << 8) | 6);
ExpanderPin LED_BUILTIN((1 << 8) | 7);

107
variants/arduino_nesso_n1/pins_arduino.h

@ -0,0 +1,107 @@
// from https://github.com/espressif/arduino-esp32/pull/11985/files
// some inspiration from https://github.com/m5stack/M5Unified/blob/master/src/utility/power/AW32001_Class.hpp
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#include "soc/soc_caps.h"
#define USB_VID 0x303A
#define USB_PID 0x1001
#define USB_MANUFACTURER "Arduino"
#define USB_PRODUCT "Nesso N1"
#define USB_SERIAL ""
static const uint8_t TX = -1;
static const uint8_t RX = -1;
static const uint8_t SDA = 10;
static const uint8_t SCL = 8;
static const uint8_t MOSI = 21;
static const uint8_t MISO = 22;
static const uint8_t SCK = 20;
static const uint8_t SS = 23;
static const uint8_t D1 = 7;
static const uint8_t D2 = 2;
static const uint8_t D3 = 6;
static const uint8_t IR_TX_PIN = 9;
static const uint8_t BEEP_PIN = 11;
static const uint8_t GROVE_IO_0 = 5;
static const uint8_t GROVE_IO_1 = 4;
static const uint8_t LORA_IRQ = 15;
static const uint8_t LORA_CS = 23;
static const uint8_t LORA_BUSY = 19;
static const uint8_t SYS_IRQ = 3;
static const uint8_t LCD_CS = 17;
static const uint8_t LCD_RS = 16;
// AW32001 registers
static const uint8_t AW32001_REG_PWR_CFG = 0x01; // Power Configuration
static const uint8_t AW32001_REG_CHR_CUR = 0x02; // Charging current
static const uint8_t AW32001_REG_CHR_VOL = 0x04; // Charge voltage
static const uint8_t AW32001_REG_CHR_TMR = 0x05; // Charge timer
static const uint8_t AW32001_REG_SYS_STA = 0x08; // System status
static const uint8_t AW32001_REG_CHIP_ID = 0x0A; // ChipID
static const uint8_t AW32001_I2C_CHIP_ADDR = 0x49; // ChipID
#if !defined(MAIN_ESP32_HAL_GPIO_H_) && defined(__cplusplus)
/* address: 0x43/0x44 */
class ExpanderPin {
public:
ExpanderPin(uint16_t _pin) : pin(_pin & 0xFF), address(_pin & 0x100 ? 0x44 : 0x43){};
uint8_t pin;
uint8_t address;
};
class NessoBattery {
private:
bool _power_mgmt_init = false;
public:
enum ChargeStatus
{
CS_UNKNOWN = -1,
CS_NOT_CHARGING = 0,
CS_PRE_CHARGE = 1,
CS_CHARGE = 2,
CS_CHARGE_DONE = 3
};
NessoBattery(){};
void begin(); // setup and check power management chip
void enableCharge(); // enable charging via power management chip
float getVoltage(); // get battery voltage in Volts
uint16_t getMilliVoltage(); // get battery voltage in millivolts
uint16_t getChargeLevel(); // get battery charge level in percents
ChargeStatus getChargeStatus();
bool isCharging();
};
extern ExpanderPin LORA_LNA_ENABLE;
extern ExpanderPin LORA_ANTENNA_SWITCH;
extern ExpanderPin LORA_ENABLE;
extern ExpanderPin POWEROFF;
extern ExpanderPin GROVE_POWER_EN;
extern ExpanderPin VIN_DETECT;
extern ExpanderPin LCD_RESET;
extern ExpanderPin LCD_BACKLIGHT;
extern ExpanderPin LED_BUILTIN;
extern ExpanderPin KEY1;
extern ExpanderPin KEY2;
void pinMode(ExpanderPin pin, uint8_t mode);
void digitalWrite(ExpanderPin pin, uint8_t val);
int digitalRead(ExpanderPin pin);
#endif
#endif /* Pins_Arduino_h */

89
variants/arduino_nesso_n1/platformio.ini

@ -0,0 +1,89 @@
[Arduino_Nesso_N1]
extends = esp32c6_base
board = esp32-c6-devkitm-1
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 ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_MODE=1
; -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=-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_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D LORA_TX_POWER=22
; -D DISPLAY_CLASS=SCIndicatorDisplay ; ToDo: Figure out display later
; -D DISPLAY_LINES=21 ; ToDo: Figure out display later
; -D LINE_LENGTH=53 ; ToDo: Figure out display later
; -D UI_ZOOM=3.5 ; ToDo: Figure out display later
; -D UI_RECENT_LIST_SIZE=9 ; ToDo: Figure out UI later
; -D UI_SENSORS_PAGE=1 ; ToDo: Figure out UI later
; -D PIN_USER_BTN=38 ; ToDo: Figure out UI later
; -D HAS_TOUCH ; ToDo: Figure out UI later
; -D PIN_TFT_SCL=38
; -D PIN_TFT_SDA=48
; -D PIN_TFT_RST=-1 ; It is defined in ArduinoNessoN1Board.h instead, so that the Expander can be targeted
; -D PIN_TFT_VDD_CTL=7 ; Seems to be right, but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices
; -D PIN_TFT_LEDA_CTL=-1 ; It is defined in ArduinoNessoN1Board.h instead, so that the Expander can be targeted
; -D PIN_TFT_LEDA_CTL_ACTIVE=HIGH ; Seems to be right, but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices
; -D PIN_TFT_CS=17 ; Seems to be right, but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices
; -D PIN_TFT_DC=?? ; ToDo: Unsure
; -D ST7789 ; This is the display driver type (- 1.14" IPS LCD, ST7789P3 driver @ SPI communication, Resolution: 135 × 240 pixels, 262K colors (18-bit)), but seems ST7789Display or ST7789LCDDisplay are too hard coded for other devices
; -D DISPLAY_CLASS=ST7789Display
-D DISABLE_WIFI_OTA=1
build_src_filter = ${esp32c6_base.build_src_filter}
+<expander.cpp>
+<ArduinoNessoN1Board.cpp>
+<../variants/arduino_nesso_n1>
[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='"Arduino Nesso N1 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
lib_deps =
${Arduino_Nesso_N1.lib_deps}
; ${esp32_ota.lib_deps}
[env:Arduino_Nesso_N1_companion_radio_ble]
extends = Arduino_Nesso_N1
build_flags = ${Arduino_Nesso_N1.build_flags}
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D BLE_PIN_CODE=123456
-D BLE_DEBUG_LOGGING=1
-D OFFLINE_QUEUE_SIZE=256
-D ENABLE_PRIVATE_KEY_IMPORT=1
-D ENABLE_PRIVATE_KEY_EXPORT=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${Arduino_Nesso_N1.build_src_filter}
+<helpers/esp32/*.cpp>
-<helpers/esp32/ESPNOWRadio.cpp>
+<../examples/companion_radio/*.cpp>
lib_deps =
${Arduino_Nesso_N1.lib_deps}
densaugeo/base64 @ ~1.4.0

54
variants/arduino_nesso_n1/target.cpp

@ -0,0 +1,54 @@
#include <Arduino.h>
#include "target.h"
ArduinoNessoN1Board board;
#if defined(P_LORA_SCLK)
static SPIClass spi(0);
// 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);
#endif
WRAPPER_CLASS radio_driver(radio, board);
ESP32RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
SensorManager sensors;
bool radio_init() {
MESH_DEBUG_PRINTLN("radio_init()");
fallback_clock.begin();
rtc_clock.begin(Wire);
MESH_DEBUG_PRINTLN("radio.std_init() and return...");
#if defined(P_LORA_SCLK)
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
return radio.std_init(&spi);
#else
return radio.std_init();
#endif
}
uint32_t radio_get_rng_seed() {
return radio.random(0x7FFFFFFF);
}
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
radio.setFrequency(freq);
radio.setSpreadingFactor(sf);
radio.setBandwidth(bw);
radio.setCodingRate(cr);
}
void radio_set_tx_power(uint8_t dbm) {
radio.setOutputPower(dbm);
}
mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}

22
variants/arduino_nesso_n1/target.h

@ -0,0 +1,22 @@
#pragma once
#define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#include <ArduinoNessoN1Board.h>
#include "pins_arduino.h"
#include <helpers/radiolib/RadioLibWrappers.h>
#include <helpers/ESP32Board.h>
#include <helpers/radiolib/CustomSX1262Wrapper.h>
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/SensorManager.h>
extern ArduinoNessoN1Board board;
extern WRAPPER_CLASS radio_driver;
extern AutoDiscoverRTCClock rtc_clock;
extern SensorManager sensors;
bool radio_init();
uint32_t radio_get_rng_seed();
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
void radio_set_tx_power(uint8_t dbm);
mesh::LocalIdentity radio_new_identity();
Loading…
Cancel
Save