From 0c1342257d9feda1bbcde0968e43d34bf846416c Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Tue, 4 Feb 2025 15:31:27 +0000 Subject: [PATCH] Add reset functions + default bandwidth for SX127X --- Radio.cpp | 15 ++++++++++++--- Radio.hpp | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Radio.cpp b/Radio.cpp index 9d73dcd..7a6478c 100644 --- a/Radio.cpp +++ b/Radio.cpp @@ -1054,7 +1054,7 @@ sx127x::sx127x(uint8_t index, SPIClass* spi, int ss, int sclk, int mosi, int mis _spiSettings(8E6, MSBFIRST, SPI_MODE0), _spiModem(spi), _ss(ss), _sclk(sclk), _mosi(mosi), _miso(miso), _reset(reset), _dio0(dio0), - _busy(busy), _frequency(0), _packetIndex(0), _preinit_done(false), _bw(0) + _busy(busy), _frequency(0), _packetIndex(0), _preinit_done(false), _bw(7800) { setTimeout(0); } void sx127x::setSPIFrequency(uint32_t frequency) { _spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0); } @@ -1114,7 +1114,7 @@ uint8_t ISR_VECT sx127x::singleTransfer(uint8_t address, uint8_t value) { return response; } -int sx127x::begin() { +void sx127x::reset() { if (_reset != -1) { pinMode(_reset, OUTPUT); @@ -1124,6 +1124,10 @@ int sx127x::begin() { digitalWrite(_reset, HIGH); delay(10); } +} + +int sx127x::begin() { + reset(); sleep(); @@ -1799,7 +1803,7 @@ void sx128x::setPacketParams(uint32_t target_preamble, uint8_t headermode, uint8 _last_preamble = target_preamble; } -int sx128x::begin() +void sx128x::reset() { if (_reset != -1) { pinMode(_reset, OUTPUT); @@ -1810,6 +1814,11 @@ int sx128x::begin() digitalWrite(_reset, HIGH); delay(10); } +} + +int sx128x::begin() +{ + reset(); if (_rxen != -1) { pinMode(_rxen, OUTPUT); diff --git a/Radio.hpp b/Radio.hpp index 7047d02..34ed9d6 100644 --- a/Radio.hpp +++ b/Radio.hpp @@ -100,6 +100,8 @@ public: _lora_preamble_time_ms(0), _lora_header_time_ms(0), _lora_symbol_rate(0.0), _lora_us_per_byte(0.0), _bitrate(0), _packet{0}, _onReceive(NULL), _txp(0), _ldro(false), _limit_rate(false), _interference_detected(false), _avoid_interference(true), _difs_ms(CSMA_SIFS_MS + 2 * _csma_slot_ms), _difs_wait_start(0), _cw_wait_start(0), _cw_wait_target(0), _cw_wait_passed(0), _csma_cw(-1), _cw_band(1), _cw_min(0), _cw_max(CSMA_CW_PER_BAND_WINDOWS), _noise_floor_sampled(false), _noise_floor_sample(0), _noise_floor_buffer({0}), _noise_floor(-292), _led_id_filter(0), _preamble_detected_at(0) {}; + virtual void reset() = 0; + virtual int begin() = 0; virtual void end() = 0; @@ -155,7 +157,6 @@ public: void updateBitrate() { if (!_radio_online) { _bitrate = 0; } else { - _lora_symbol_rate = (float)getSignalBandwidth()/(float)(pow(2, _sf)); _lora_symbol_time_ms = (1.0/_lora_symbol_rate)*1000.0; _bitrate = (uint32_t)(_sf * ( (4.0/(float)getCodingRate4()) / ((float)(pow(2, _sf))/((float)getSignalBandwidth()/1000.0)) ) * 1000.0); @@ -461,6 +462,8 @@ public: sx126x(uint8_t index, SPIClass* spi, bool tcxo, bool dio2_as_rf_switch, int ss, int sclk, int mosi, int miso, int reset, int dio0, int busy, int rxen); + void reset(); + int begin(); void end(); @@ -541,7 +544,6 @@ private: void handleLowDataRate(); void optimizeModemSensitivity(); - void reset(void); void calibrate(void); void calibrate_image(uint32_t frequency); bool getPacketValidity(); @@ -575,6 +577,8 @@ class sx127x : public RadioInterface { public: sx127x(uint8_t index, SPIClass* spi, int ss, int sclk, int mosi, int miso, int reset, int dio0, int busy); + void reset(); + int begin(); void end(); @@ -667,6 +671,8 @@ class sx128x : public RadioInterface { public: sx128x(uint8_t index, SPIClass* spi, bool tcxo, int ss, int sclk, int mosi, int miso, int reset, int dio0, int busy, int rxen, int txen); + void reset(); + int begin(); void end();