From 32424b91a63db5f51d3743b6f8e5b2c878939340 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 13 Feb 2024 12:56:14 +0100 Subject: [PATCH] Cleanup --- Makefile | 4 ++-- sx126x.cpp | 40 +++++++++++----------------------------- sx126x.h | 2 ++ sx127x.cpp | 4 ++-- 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 3ad2fbe..6513fdf 100644 --- a/Makefile +++ b/Makefile @@ -118,8 +118,8 @@ upload-tbeam: arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:t-beam @sleep 1 rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.t-beam/RNode_Firmware.ino.bin) - @sleep 3 - python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin +# @sleep 3 +# python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-lora32_v10: arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:ttgo-lora32 diff --git a/sx126x.cpp b/sx126x.cpp index 7587e3b..ad6501b 100644 --- a/sx126x.cpp +++ b/sx126x.cpp @@ -9,28 +9,6 @@ #if MODEM == SX1262 #include "sx126x.h" -#define MCU_1284P 0x91 -#define MCU_2560 0x92 -#define MCU_ESP32 0x81 -#define MCU_NRF52 0x71 -#if defined(__AVR_ATmega1284P__) - #define PLATFORM PLATFORM_AVR - #define MCU_VARIANT MCU_1284P -#elif defined(__AVR_ATmega2560__) - #define PLATFORM PLATFORM_AVR - #define MCU_VARIANT MCU_2560 -#elif defined(ESP32) - #define PLATFORM PLATFORM_ESP32 - #define MCU_VARIANT MCU_ESP32 -#elif defined(NRF52840_XXAA) - #define PLATFORM PLATFORM_NRF52 - #define MCU_VARIANT MCU_NRF52 -#endif - -#ifndef MCU_VARIANT - #error No MCU variant defined, cannot compile -#endif - #if MCU_VARIANT == MCU_ESP32 #if MCU_VARIANT == MCU_ESP32 and !defined(CONFIG_IDF_TARGET_ESP32S3) #include "soc/rtc_wdt.h" @@ -132,9 +110,7 @@ sx126x::sx126x() : } bool sx126x::preInit() { - // setup pins pinMode(_ss, OUTPUT); - // set SS high digitalWrite(_ss, HIGH); #if BOARD_MODEL == BOARD_RNODE_NG_22 @@ -144,6 +120,7 @@ bool sx126x::preInit() { #endif // check version (retry for up to 2 seconds) + // TODO: Actually read version registers, not syncwords long start = millis(); uint8_t syncmsb; uint8_t synclsb; @@ -342,9 +319,7 @@ void sx126x::setPacketParams(long preamble, uint8_t headermode, uint8_t length, executeOpcode(OP_PACKET_PARAMS_6X, buf, 9); } - -int sx126x::begin(long frequency) -{ +void sx126x::reset(void) { if (_reset != -1) { pinMode(_reset, OUTPUT); @@ -354,6 +329,12 @@ int sx126x::begin(long frequency) digitalWrite(_reset, HIGH); delay(10); } +} + + +int sx126x::begin(long frequency) +{ + reset(); if (_busy != -1) { pinMode(_busy, INPUT); @@ -797,8 +778,9 @@ long sx126x::getSignalBandwidth() } void sx126x::handleLowDataRate(){ - _ldro = 1; - setModulationParams(_sf, _bw, _cr, _ldro); + // TODO: Why was this enabled without any logic to check LDRO conditions? + //_ldro = 1; + //setModulationParams(_sf, _bw, _cr, _ldro); } void sx126x::optimizeModemSensitivity(){ diff --git a/sx126x.h b/sx126x.h index d20f713..605442f 100644 --- a/sx126x.h +++ b/sx126x.h @@ -112,6 +112,8 @@ private: void handleLowDataRate(); void optimizeModemSensitivity(); + void reset(void); + private: SPISettings _spiSettings; int _ss; diff --git a/sx127x.cpp b/sx127x.cpp index aef035b..177fe21 100644 --- a/sx127x.cpp +++ b/sx127x.cpp @@ -73,8 +73,8 @@ #define IRQ_RX_DONE_MASK_7X 0x40 #define IRQ_PAYLOAD_CRC_ERROR_MASK_7X 0x20 -#define MAX_PKT_LENGTH 255 -#define SYNC_WORD_7X 0x12 +#define SYNC_WORD_7X 0x12 +#define MAX_PKT_LENGTH 255 extern SPIClass SPI;