From d1586449f46a6b01353bc3e6a246607b7ed83dc7 Mon Sep 17 00:00:00 2001 From: Andrea Guglielmini Date: Wed, 26 Feb 2020 15:54:41 +0100 Subject: [PATCH 001/334] [nRF24] Added "isCarrierDetected()" --- src/modules/nRF24/nRF24.cpp | 4 ++++ src/modules/nRF24/nRF24.h | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 3a91862d..34b54f93 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -423,6 +423,10 @@ int16_t nRF24::getStatus(uint8_t mask) { return(_mod->SPIgetRegValue(NRF24_REG_STATUS) & mask); } +bool nRF24::isCarrierDetected() { + return(_mod->SPIgetRegValue(NRF24_REG_RPD, 0,0)) == 1; +} + int16_t nRF24::setFrequencyDeviation(float freqDev) { // nRF24 is unable to set frequency deviation // this method is implemented only for PhysicalLayer compatibility diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 6eafc342..4528c949 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -392,6 +392,13 @@ class nRF24: public PhysicalLayer { */ int16_t getStatus(uint8_t mask = 0xFF); + /*! + \brief Checks if carrier was detected during last RX + + \returns Whatever the carrier was above threshold. + */ + bool isCarrierDetected(); + /*! \brief Dummy configuration method, to ensure PhysicalLayer compatibility. From ff7831655b3f2deea0905f61a0759f34abeab34f Mon Sep 17 00:00:00 2001 From: Andrea Guglielmini Date: Wed, 26 Feb 2020 15:55:44 +0100 Subject: [PATCH 002/334] [nRF24] Minor fixes --- src/modules/nRF24/nRF24.cpp | 15 +++++++++------ src/modules/nRF24/nRF24.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 34b54f93..732fc20b 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -230,14 +230,9 @@ int16_t nRF24::setFrequency(int16_t freq) { return(ERR_INVALID_FREQUENCY); } - // set mode to standby - int16_t state = standby(); - RADIOLIB_ASSERT(state); - // set frequency uint8_t freqRaw = freq - 2400; - state = _mod->SPIsetRegValue(NRF24_REG_RF_CH, freqRaw, 6, 0); - return(state); + return _mod->SPIsetRegValue(NRF24_REG_RF_CH, freqRaw, 6, 0); } int16_t nRF24::setDataRate(int16_t dataRate) { @@ -332,6 +327,7 @@ int16_t nRF24::setTransmitPipe(uint8_t* addr) { // set Rx pipe 0 address (for ACK) _mod->SPIwriteRegisterBurst(NRF24_REG_RX_ADDR_P0, addr, _addrWidth); + state |= _mod->SPIsetRegValue(NRF24_REG_EN_RXADDR, NRF24_P0_ON, 0, 0); return(state); } @@ -442,6 +438,13 @@ size_t nRF24::getPacketLength(bool update) { } int16_t nRF24::setCrcFiltering(bool crcOn) { + // Auto Ack needs to be disabled in order to disable CRC. + if (!crcOn) { + int16_t status = setAutoAck(false); + RADIOLIB_ASSERT(status) + } + + // Disable CRC return _mod->SPIsetRegValue(NRF24_REG_CONFIG, crcOn ? NRF24_CRC_ON : NRF24_CRC_OFF, 3, 3); } diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 4528c949..3ca3ac75 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -127,7 +127,7 @@ // NRF24_REG_STATUS #define NRF24_RX_DR 0b01000000 // 6 6 Rx data ready #define NRF24_TX_DS 0b00100000 // 5 5 Tx data sent -#define NRF24_MAX_RT 0b00010000 // 4 4 maximum number of rentransmits reached (must be cleared to continue) +#define NRF24_MAX_RT 0b00010000 // 4 4 maximum number of retransmits reached (must be cleared to continue) #define NRF24_RX_FIFO_EMPTY 0b00001110 // 3 1 Rx FIFO is empty #define NRF24_RX_P_NO 0b00000000 // 3 1 number of data pipe that received data #define NRF24_TX_FIFO_FULL 0b00000001 // 0 0 Tx FIFO is full From b69437c48fee48b031669389efead7b347eace4c Mon Sep 17 00:00:00 2001 From: Andrea Guglielmini Date: Thu, 27 Feb 2020 20:11:47 +0100 Subject: [PATCH 003/334] [nRF24] Removed ambiguity, PR #119 --- src/modules/nRF24/nRF24.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 3ca3ac75..70362dfe 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -445,7 +445,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t setAutoAck(uint8_t pipeNum, bool autoAckOn = true); + int16_t setAutoAck(uint8_t pipeNum, bool autoAckOn); /*! \brief Dummy data shaping configuration method, to ensure PhysicalLayer compatibility. From 5846c9d9d9415af21a0de99ee4a79ed8ffc6885a Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 2 Mar 2020 13:25:35 +0100 Subject: [PATCH 004/334] [Module] Only initializing default SPI interface (#121) --- src/Module.cpp | 39 ++++++++++++++++++++++++++++++++++++--- src/Module.h | 43 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index bce8abd4..409e012e 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -1,11 +1,34 @@ #include "Module.h" +Module::Module(int16_t cs, int16_t irq, int16_t rst) { + _cs = cs; + _rx = NC; + _tx = NC; + _irq = irq; + _rst = rst; + _spi = &SPI; + _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); + _initInterface = true; +} + +Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio) { + _cs = cs; + _rx = gpio; + _tx = NC; + _irq = irq; + _rst = rst; + _spi = &SPI; + _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); + _initInterface = true; +} + Module::Module(int16_t rx, int16_t tx, HardwareSerial* useSer, int16_t rst) { _cs = NC; _rx = rx; _tx = tx; _irq = NC; _rst = rst; + _initInterface = true; #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED ModuleSerial = useSer; @@ -23,6 +46,7 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi, SPISettings _rst = rst; _spi = &spi; _spiSettings = spiSettings; + _initInterface = false; } Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi, SPISettings spiSettings) { @@ -33,6 +57,7 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi _rst = rst; _spi = &spi; _spiSettings = spiSettings; + _initInterface = false; } Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t rx, int16_t tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* useSer) { @@ -43,6 +68,7 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t rx, int16_t tx, SPI _rst = rst; _spi = &spi; _spiSettings = spiSettings; + _initInterface = false; #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED ModuleSerial = useSer; @@ -58,14 +84,18 @@ void Module::init(uint8_t interface) { case RADIOLIB_USE_SPI: Module::pinMode(_cs, OUTPUT); Module::digitalWrite(_cs, HIGH); - _spi->begin(); + if(_initInterface) { + _spi->begin(); + } break; case RADIOLIB_USE_UART: + if(_initInterface) { #if defined(ESP32) - ModuleSerial->begin(baudrate, SERIAL_8N1, _rx, _tx); + ModuleSerial->begin(baudrate, SERIAL_8N1, _rx, _tx); #else - ModuleSerial->begin(baudrate); + ModuleSerial->begin(baudrate); #endif + } break; case RADIOLIB_USE_I2C: break; @@ -211,6 +241,7 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da // send SPI register address with access command _spi->transfer(reg | cmd); + delayMicroseconds(120); #ifdef RADIOLIB_VERBOSE if(cmd == SPIwriteCommand) { RADIOLIB_VERBOSE_PRINT('W'); @@ -226,12 +257,14 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da if(cmd == SPIwriteCommand) { for(size_t n = 0; n < numBytes; n++) { _spi->transfer(dataOut[n]); + delayMicroseconds(120); RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); RADIOLIB_VERBOSE_PRINT('\t'); } } else if (cmd == SPIreadCommand) { for(size_t n = 0; n < numBytes; n++) { dataIn[n] = _spi->transfer(0x00); + delayMicroseconds(120); RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX); RADIOLIB_VERBOSE_PRINT('\t'); } diff --git a/src/Module.h b/src/Module.h index cb688435..ddc43c51 100644 --- a/src/Module.h +++ b/src/Module.h @@ -27,14 +27,38 @@ class Module { \param serial HardwareSerial to be used on platforms that do not support SoftwareSerial. Defaults to Serial1. - \param rst Arduino pin to be used as hardware reset for the module. Defaults to -1 (unused). + \param rst Arduino pin to be used as hardware reset for the module. Defaults to NC (unused). */ #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - Module(int16_t tx, int16_t rx, HardwareSerial* serial = &Serial1, int16_t rst = -1); + Module(int16_t tx, int16_t rx, HardwareSerial* serial = &Serial1, int16_t rst = NC); #else - Module(int16_t tx, int16_t rx, HardwareSerial* serial = nullptr, int16_t rst = -1); + Module(int16_t tx, int16_t rx, HardwareSerial* serial = nullptr, int16_t rst = NC); #endif + /*! + \brief SPI-based module constructor. Will use the default SPI interface automatically initialize it. + + \param cs Arduino pin to be used as chip select. + + \param irq Arduino pin to be used as interrupt/GPIO. + + \param rst Arduino pin to be used as hardware reset for the module. + */ + Module(int16_t cs, int16_t irq, int16_t rst); + + /*! + \brief Extended SPI-based module constructor. Will use the default SPI interface automatically initialize it. + + \param cs Arduino pin to be used as chip select. + + \param irq Arduino pin to be used as interrupt/GPIO. + + \param rst Arduino pin to be used as hardware reset for the module. + + \param gpio Arduino pin to be used as additional interrupt/GPIO. + */ + Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio); + /*! \brief SPI-based module constructor. @@ -44,11 +68,11 @@ class Module { \param rst Arduino pin to be used as hardware reset for the module. - \param spi SPI interface to be used. Defaults to Arduino hardware SPI interface, can also use software SPI implementations. + \param spi SPI interface to be used, can also use software SPI implementations. - \param spiSettings SPI interface settings. Defaults to 2 MHz clock, MSB first, mode 0. + \param spiSettings SPI interface settings. */ - Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0)); + Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi, SPISettings spiSettings); /*! \brief Extended SPI-based module constructor. @@ -61,11 +85,11 @@ class Module { \param gpio Arduino pin to be used as additional interrupt/GPIO. - \param spi SPI interface to be used. Defaults to Arduino hardware SPI interface, can also use software SPI implementations. + \param spi SPI interface to be used, can also use software SPI implementations. - \param spiSettings SPI interface settings. Defaults to 2 MHz clock, MSB first, mode 0. + \param spiSettings SPI interface settings. */ - Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0)); + Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi, SPISettings spiSettings); /*! \brief Generic module constructor. @@ -344,6 +368,7 @@ class Module { int16_t _irq; int16_t _rst; + bool _initInterface; SPIClass* _spi; SPISettings _spiSettings; From c12cd6a53d2e57dc696c54e2037f99d5b53fd1f5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 13 Mar 2020 21:16:10 +0100 Subject: [PATCH 005/334] [Module] Removed debug-only delays --- src/Module.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index 409e012e..7a714d85 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -241,7 +241,6 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da // send SPI register address with access command _spi->transfer(reg | cmd); - delayMicroseconds(120); #ifdef RADIOLIB_VERBOSE if(cmd == SPIwriteCommand) { RADIOLIB_VERBOSE_PRINT('W'); @@ -257,14 +256,12 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da if(cmd == SPIwriteCommand) { for(size_t n = 0; n < numBytes; n++) { _spi->transfer(dataOut[n]); - delayMicroseconds(120); RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); RADIOLIB_VERBOSE_PRINT('\t'); } } else if (cmd == SPIreadCommand) { for(size_t n = 0; n < numBytes; n++) { dataIn[n] = _spi->transfer(0x00); - delayMicroseconds(120); RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX); RADIOLIB_VERBOSE_PRINT('\t'); } From c1c991acc831cbb457cf96037eb9cf4ced261a6f Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 13 Mar 2020 21:16:29 +0100 Subject: [PATCH 006/334] [SX127x] Fixed reset implementation for SX1272/73 --- src/modules/SX127x/SX1272.cpp | 8 ++++++++ src/modules/SX127x/SX1272.h | 5 +++++ src/modules/SX127x/SX1278.cpp | 8 ++++++++ src/modules/SX127x/SX1278.h | 5 +++++ src/modules/SX127x/SX127x.cpp | 11 ----------- src/modules/SX127x/SX127x.h | 4 ++-- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index d5bb554c..7624da78 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -57,6 +57,14 @@ int16_t SX1272::beginFSK(float freq, float br, float rxBw, float freqDev, int8_t return(state); } +void SX1272::reset() { + Module::pinMode(_mod->getRst(), OUTPUT); + Module::digitalWrite(_mod->getRst(), HIGH); + delayMicroseconds(100); + Module::digitalWrite(_mod->getRst(), LOW); + delay(5); +} + int16_t SX1272::setFrequency(float freq) { // check frequency range if((freq < 860.0) || (freq > 1020.0)) { diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index dd90b739..a0f64541 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -155,6 +155,11 @@ class SX1272: public SX127x { \returns \ref status_codes */ int16_t beginFSK(float freq = 915.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13, uint8_t currentLimit = 100, uint16_t preambleLength = 16, bool enableOOK = false); + + /*! + \brief Reset method. Will reset the chip to the default state using RST pin. + */ + void reset(); // configuration methods diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index b2ab0b3c..8a5b68ea 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -52,6 +52,14 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t return(state); } +void SX1278::reset() { + Module::pinMode(_mod->getRst(), OUTPUT); + Module::digitalWrite(_mod->getRst(), LOW); + delayMicroseconds(100); + Module::digitalWrite(_mod->getRst(), HIGH); + delay(5); +} + int16_t SX1278::setFrequency(float freq) { // check frequency range if((freq < 137.0) || (freq > 525.0)) { diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index c081e76c..77318e15 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -165,6 +165,11 @@ class SX1278: public SX127x { */ int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 13, uint8_t currentLimit = 100, uint16_t preambleLength = 16, bool enableOOK = false); + /*! + \brief Reset method. Will reset the chip to the default state using RST pin. + */ + void reset(); + // configuration methods /*! diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 73d796bf..1ba7b49e 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -54,9 +54,6 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); - // reset the module - reset(); - // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!")); @@ -121,14 +118,6 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB return(state); } -void SX127x::reset() { - Module::pinMode(_mod->getRst(), OUTPUT); - Module::digitalWrite(_mod->getRst(), LOW); - delayMicroseconds(100); - Module::digitalWrite(_mod->getRst(), HIGH); - delay(5); -} - int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { // set mode to standby int16_t state = setMode(SX127X_STANDBY); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index d48e9e30..aa6bb03b 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -565,9 +565,9 @@ class SX127x: public PhysicalLayer { int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength); /*! - \brief Reset method. Will reset the chip to the default state using RST pin. + \brief Reset method. Will reset the chip to the default state using RST pin. Declared pure virtual since SX1272 and SX1278 implmentations differ. */ - void reset(); + virtual void reset() = 0; /*! \brief Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class. From 009b8a5373471504c2c174ed34b9684d15a8034a Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 13 Mar 2020 21:22:41 +0100 Subject: [PATCH 007/334] Bump version to 3.4.0 --- library.properties | 2 +- src/TypeDef.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.properties b/library.properties index bee08568..21975e9d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=3.3.1 +version=3.4.0 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/TypeDef.h b/src/TypeDef.h index 8ed5b4ee..d149ca1b 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -9,8 +9,8 @@ // version definitions #define RADIOLIB_VERSION_MAJOR (0x03) -#define RADIOLIB_VERSION_MINOR (0x03) -#define RADIOLIB_VERSION_PATCH (0x01) +#define RADIOLIB_VERSION_MINOR (0x04) +#define RADIOLIB_VERSION_PATCH (0x00) #define RADIOLIB_VERSION_EXTRA (0x00) #define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MAJOR << 16) | (RADIOLIB_VERSION_MAJOR << 8) | (RADIOLIB_VERSION_EXTRA)) From 898696fb52162ca673acf66a2594c04b655a8e05 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 14 Mar 2020 13:34:31 +0100 Subject: [PATCH 008/334] [SX126x] Set default whitener initial value to 0x1FF for SX127x FSK --- src/modules/SX126x/SX126x.cpp | 2 +- src/modules/SX126x/SX126x.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index b089f247..6b9aa0e4 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -131,7 +131,7 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit state = setSyncWord(sync, 2); RADIOLIB_ASSERT(state); - state = setWhitening(true, 0x0100); + state = setWhitening(true, 0x01FF); RADIOLIB_ASSERT(state); state = variablePacketLengthMode(SX126X_MAX_PACKET_LENGTH); diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index df6e8028..1b9ce54f 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -725,7 +725,7 @@ class SX126x: public PhysicalLayer { \param enabled True = Whitening enabled - \param initial Initial value used for the whitening LFSR in FSK mode. + \param initial Initial value used for the whitening LFSR in FSK mode. Defaults to 0x0100, use 0x01FF for SX127x compatibility. \returns \ref status_codes */ From 2cf4971c2dc0cec299f37199fc33ac0edb86b7bb Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 14 Mar 2020 13:44:50 +0100 Subject: [PATCH 009/334] [SX127x] Set default FSK BT shaping to 0.5 for SX126x FSK (#123) --- examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino | 2 +- src/modules/SX127x/SX1272.cpp | 4 ++++ src/modules/SX127x/SX1278.cpp | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino index f9c89154..f9e2821d 100644 --- a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino +++ b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino @@ -38,7 +38,7 @@ void setup() { // Rx bandwidth: 125.0 kHz // output power: 13 dBm // current limit: 100 mA - // data shaping: Gaussian, BT = 0.3 + // data shaping: Gaussian, BT = 0.5 // sync word: 0x2D 0x01 // OOK modulation: disabled int state = fsk.beginFSK(); diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 7624da78..1251d90a 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -413,6 +413,10 @@ int16_t SX1272::configFSK() { // set fast PLL hop state = _mod->SPIsetRegValue(SX1272_REG_PLL_HOP, SX127X_FAST_HOP_ON, 7, 7); + RADIOLIB_ASSERT(state); + + // set Gauss filter BT product to 0.5 + state = _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_5, 4, 3); return(state); } diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 8a5b68ea..24ea9e64 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -491,6 +491,10 @@ int16_t SX1278::configFSK() { // set fast PLL hop state = _mod->SPIsetRegValue(SX1278_REG_PLL_HOP, SX127X_FAST_HOP_ON, 7, 7); + RADIOLIB_ASSERT(state); + + // set Gauss filter BT product to 0.5 + state = _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_0_5, 6, 5); return(state); } From 6c9948634317b2da511c5d627f89bb9008e100af Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Mon, 16 Mar 2020 12:12:06 +0000 Subject: [PATCH 010/334] Swap delayMicroseconds() to delay where appropriate See https://github.com/jgromes/RadioLib/issues/126 for context. --- src/modules/RF69/RF69.cpp | 2 +- src/modules/SX126x/SX126x.cpp | 4 ++-- src/modules/SX127x/SX1272.cpp | 2 +- src/modules/SX127x/SX1278.cpp | 2 +- src/modules/XBee/XBee.cpp | 4 ++-- src/modules/nRF24/nRF24.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index b652a5fd..052bbd2c 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -101,7 +101,7 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe void RF69::reset() { Module::pinMode(_mod->getRst(), OUTPUT); Module::digitalWrite(_mod->getRst(), HIGH); - delayMicroseconds(100); + delay(1); Module::digitalWrite(_mod->getRst(), LOW); delay(10); } diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 6b9aa0e4..6b72f690 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -153,7 +153,7 @@ int16_t SX126x::reset(bool verify) { // run the reset sequence Module::pinMode(_mod->getRst(), OUTPUT); Module::digitalWrite(_mod->getRst(), LOW); - delayMicroseconds(150); + delay(1); Module::digitalWrite(_mod->getRst(), HIGH); // return immediately when verification is disabled @@ -364,7 +364,7 @@ int16_t SX126x::sleep(bool retainConfig) { int16_t state = SPIwriteCommand(SX126X_CMD_SET_SLEEP, &sleepMode, 1, false); // wait for SX126x to safely enter sleep mode - delayMicroseconds(500); + delay(1); return(state); } diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 1251d90a..06646d1f 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -60,7 +60,7 @@ int16_t SX1272::beginFSK(float freq, float br, float rxBw, float freqDev, int8_t void SX1272::reset() { Module::pinMode(_mod->getRst(), OUTPUT); Module::digitalWrite(_mod->getRst(), HIGH); - delayMicroseconds(100); + delay(1); Module::digitalWrite(_mod->getRst(), LOW); delay(5); } diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 24ea9e64..5989aa13 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -55,7 +55,7 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t void SX1278::reset() { Module::pinMode(_mod->getRst(), OUTPUT); Module::digitalWrite(_mod->getRst(), LOW); - delayMicroseconds(100); + delay(1); Module::digitalWrite(_mod->getRst(), HIGH); delay(5); } diff --git a/src/modules/XBee/XBee.cpp b/src/modules/XBee/XBee.cpp index 1e5d7a15..cefc7dff 100644 --- a/src/modules/XBee/XBee.cpp +++ b/src/modules/XBee/XBee.cpp @@ -54,7 +54,7 @@ int16_t XBee::begin(long speed) { void XBee::reset() { pinMode(_mod->getRst(), OUTPUT); digitalWrite(_mod->getRst(), LOW); - delayMicroseconds(200); + delay(1); digitalWrite(_mod->getRst(), HIGH); } @@ -218,7 +218,7 @@ int16_t XBeeSerial::begin(long speed) { void XBeeSerial::reset() { pinMode(_mod->getRst(), OUTPUT); digitalWrite(_mod->getRst(), LOW); - delayMicroseconds(200); + delay(1); digitalWrite(_mod->getRst(), HIGH); pinMode(_mod->getRst(), INPUT); } diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 732fc20b..7316f2f0 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -172,7 +172,7 @@ int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // CE high to start transmitting digitalWrite(_mod->getRst(), HIGH); - delayMicroseconds(10); + delay(1); digitalWrite(_mod->getRst(), LOW); return(state); @@ -199,7 +199,7 @@ int16_t nRF24::startReceive() { digitalWrite(_mod->getRst(), HIGH); // wait to enter Rx state - delayMicroseconds(130); + delay(1); return(state); } From 3bb81988dde001c35d862c41715dfa315c69dfdb Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:10:23 +0100 Subject: [PATCH 011/334] [AX25] Fixed typos --- examples/AX25/AX25_Transmit/AX25_Transmit.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/AX25/AX25_Transmit/AX25_Transmit.ino b/examples/AX25/AX25_Transmit/AX25_Transmit.ino index fa97067d..ac0eb1d2 100644 --- a/examples/AX25/AX25_Transmit/AX25_Transmit.ino +++ b/examples/AX25/AX25_Transmit/AX25_Transmit.ino @@ -68,7 +68,7 @@ void setup() { } void loop() { - // send AX.25 unnumbered infomration frame + // send AX.25 unnumbered information frame Serial.print(F("[AX.25] Sending UI frame ... ")); // destination station callsign: "NJ7P" // destination station SSID: 0 From 28c12f45769f85c5f658cc56f1b20e5f85806819 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:10:49 +0100 Subject: [PATCH 012/334] [CC1101] Fixed typos --- .../CC1101_Transmit_Address.ino | 4 ++-- .../CC1101_Transmit_Interrupt.ino | 4 ++-- src/modules/CC1101/CC1101.cpp | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino index 7e130920..94905bad 100644 --- a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino +++ b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino @@ -91,11 +91,11 @@ void loop() { if (state == ERR_NONE) { // the packet was successfully transmitted - Serial.println(F(" success!")); + Serial.println(F("success!")); } else if (state == ERR_PACKET_TOO_LONG) { // the supplied packet was longer than 255 bytes - Serial.println(F(" too long!")); + Serial.println(F("too long!")); } else { // some other error occurred diff --git a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino index dde5d54d..a89cf0ca 100644 --- a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino +++ b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino @@ -123,8 +123,8 @@ void loop() { // you can also transmit byte array up to 256 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; int state = cc.startTransmit(byteArr, 8); */ diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index a207bafb..f8e2aa1e 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -76,7 +76,7 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po state = variablePacketLengthMode(); RADIOLIB_ASSERT(state); - // configure default preamble lenght + // configure default preamble length state = setPreambleLength(preambleLength); RADIOLIB_ASSERT(state); @@ -330,7 +330,7 @@ int16_t CC1101::setBitRate(float br) { // set mode to standby SPIsendCommand(CC1101_CMD_IDLE); - // calculate exponent and mantisa values + // calculate exponent and mantissa values uint8_t e = 0; uint8_t m = 0; getExpMant(br * 1000.0, 256, 28, 14, e, m); @@ -350,7 +350,7 @@ int16_t CC1101::setRxBandwidth(float rxBw) { // set mode to standby SPIsendCommand(CC1101_CMD_IDLE); - // calculate exponent and mantisa values + // calculate exponent and mantissa values for(int8_t e = 3; e >= 0; e--) { for(int8_t m = 3; m >= 0; m --) { float point = (CC1101_CRYSTAL_FREQ * 1000000.0)/(8 * (m + 4) * ((uint32_t)1 << e)); @@ -380,7 +380,7 @@ int16_t CC1101::setFrequencyDeviation(float freqDev) { // set mode to standby SPIsendCommand(CC1101_CMD_IDLE); - // calculate exponent and mantisa values + // calculate exponent and mantissa values uint8_t e = 0; uint8_t m = 0; getExpMant(freqDev * 1000.0, 8, 17, 7, e, m); @@ -563,8 +563,8 @@ int16_t CC1101::setOOK(bool enableOOK) { int16_t state = SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MOD_FORMAT_ASK_OOK, 6, 4); RADIOLIB_ASSERT(state); - // PA_TABLE[0] is (by default) the power value used when transmitting a "0L". - // Set PA_TABLE[1] to be used when transmitting a "1L". + // PA_TABLE[0] is (by default) the power value used when transmitting a "0". + // Set PA_TABLE[1] to be used when transmitting a "1". state = SPIsetRegValue(CC1101_REG_FREND0, 1, 2, 0); RADIOLIB_ASSERT(state); @@ -627,11 +627,11 @@ int16_t CC1101::variablePacketLengthMode(uint8_t maxLen) { int16_t CC1101::enableSyncWordFiltering(uint8_t maxErrBits, bool requireCarrierSense) { switch (maxErrBits){ case 0: - // in 16 bit sync word, expect all 16 bits. + // in 16 bit sync word, expect all 16 bits return (SPIsetRegValue(CC1101_REG_MDMCFG2, requireCarrierSense ? CC1101_SYNC_MODE_16_16_THR : CC1101_SYNC_MODE_16_16, 2, 0)); case 1: - // in 16 bit sync word, expect at least 15 bits. + // in 16 bit sync word, expect at least 15 bits return (SPIsetRegValue(CC1101_REG_MDMCFG2, requireCarrierSense ? CC1101_SYNC_MODE_15_16_THR : CC1101_SYNC_MODE_15_16, 2, 0)); default: From 089d925f82a63c8c31c69ae45a912fbd3645c475 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:11:32 +0100 Subject: [PATCH 013/334] [RF69] Fixed typos --- .../RF69/RF69_Receive_Address/RF69_Receive_Address.ino | 4 ++-- .../RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino | 2 +- examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino | 4 ++-- .../RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino | 8 ++++---- .../RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino | 8 ++++---- src/modules/RF69/RF69.cpp | 2 +- src/modules/RF69/RF69.h | 6 +++--- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino b/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino index 86e1ebbc..08242ec3 100644 --- a/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino +++ b/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino @@ -58,8 +58,8 @@ void setup() { } // set broadcast address - // NOTE: calling this method will autmatically enable - // address filtering (node or broadcast address) + // NOTE: calling this method will automatically enable + // address filtering (node or broadcast address) Serial.print(F("[RF69] Setting broadcast address ... ")); state = rf.setBroadcastAddress(0xFF); if (state == ERR_NONE) { diff --git a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino index 2e8929ac..32aef55f 100644 --- a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino +++ b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino @@ -104,7 +104,7 @@ void loop() { // you can also read received data as byte array /* byte byteArr[8]; - int state = lora.readData(byteArr, 8); + int state = rf.readData(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino b/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino index a9ec4ff5..5df09c65 100644 --- a/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino +++ b/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino @@ -71,11 +71,11 @@ void loop() { if (state == ERR_NONE) { // the packet was successfully transmitted - Serial.println(F(" success!")); + Serial.println(F("success!")); } else if (state == ERR_PACKET_TOO_LONG) { // the supplied packet was longer than 64 bytes - Serial.println(F(" too long!")); + Serial.println(F("too long!")); } else { // some other error occurred diff --git a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino index b9b36870..7413822e 100644 --- a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino +++ b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino @@ -72,7 +72,7 @@ void setup() { // address filtering can also be disabled // NOTE: calling this method will also erase previously set - // node and broadcast address + // node and broadcast address /* Serial.print(F("[RF69] Disabling address filtering ... ")); state = rf.disableAddressFiltering(); @@ -105,17 +105,17 @@ void loop() { // transmit byte array in broadcast mode /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; int state = rf.transmit(byteArr, 8, 0xFF); */ if (state == ERR_NONE) { // the packet was successfully transmitted - Serial.println(F(" success!")); + Serial.println(F("success!")); } else if (state == ERR_PACKET_TOO_LONG) { // the supplied packet was longer than 64 bytes - Serial.println(F(" too long!")); + Serial.println(F("too long!")); } else { // some other error occurred diff --git a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino index 0387849a..3e83042a 100644 --- a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino +++ b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino @@ -61,8 +61,8 @@ void setup() { // you can also transmit byte array up to 64 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; state = rf.startTransmit(byteArr, 8); */ } @@ -123,8 +123,8 @@ void loop() { // you can also transmit byte array up to 64 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; int state = rf.startTransmit(byteArr, 8); */ diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 052bbd2c..69dc4351 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -308,7 +308,7 @@ int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) { } int16_t RF69::readData(uint8_t* data, size_t len) { - // set mdoe to standby + // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); // get packet length diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 6c5333fe..1a40e5dc 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -144,7 +144,7 @@ #define RF69_LISTEN_RES_IDLE_64_US 0b01000000 // 7 6 resolution of Listen mode idle time: 64 us #define RF69_LISTEN_RES_IDLE_4_1_MS 0b10000000 // 7 6 4.1 ms (default) #define RF69_LISTEN_RES_IDLE_262_MS 0b11000000 // 7 6 262 ms -#define RF69_LISTEN_RES_RX_64_US 0b00010000 // 5 4 resolution of Listen mode ry time: 64 us (default) +#define RF69_LISTEN_RES_RX_64_US 0b00010000 // 5 4 resolution of Listen mode rx time: 64 us (default) #define RF69_LISTEN_RES_RX_4_1_MS 0b00100000 // 5 4 4.1 ms #define RF69_LISTEN_RES_RX_262_MS 0b00110000 // 5 4 262 ms #define RF69_LISTEN_ACCEPT_ABOVE_RSSI_THRESH 0b00000000 // 3 3 packet acceptance criteria: RSSI above threshold @@ -305,7 +305,7 @@ #define RF69_IRQ_TX_READY 0b00100000 // 5 5 Tx mode ready #define RF69_IRQ_PLL_LOCK 0b00010000 // 4 4 PLL is locked #define RF69_IRQ_RSSI 0b00001000 // 3 3 RSSI value exceeded RssiThreshold -#define RF69_IRQ_TIMEOUT 0b00000100 // 2 2 timeout occured +#define RF69_IRQ_TIMEOUT 0b00000100 // 2 2 timeout occurred #define RF69_IRQ_AUTO_MODE 0b00000010 // 1 1 entered intermediate mode #define RF69_SYNC_ADDRESS_MATCH 0b00000001 // 0 0 sync address detected @@ -313,7 +313,7 @@ #define RF69_IRQ_FIFO_FULL 0b10000000 // 7 7 FIFO is full #define RF69_IRQ_FIFO_NOT_EMPTY 0b01000000 // 6 6 FIFO contains at least 1 byte #define RF69_IRQ_FIFO_LEVEL 0b00100000 // 5 5 FIFO contains more than FifoThreshold bytes -#define RF69_IRQ_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occured +#define RF69_IRQ_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occurred #define RF69_IRQ_PACKET_SENT 0b00001000 // 3 3 packet was sent #define RF69_IRQ_PAYLOAD_READY 0b00000100 // 2 2 last payload byte received and CRC check passed #define RF69_IRQ_CRC_OK 0b00000010 // 1 1 CRC check passed From 2f4a5c660c1f6bf74ae457ea7c0e800574dbb309 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:11:55 +0100 Subject: [PATCH 014/334] [SX1231] Fixed typos --- examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino b/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino index c781b02a..e651202a 100644 --- a/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino +++ b/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino @@ -53,17 +53,17 @@ void loop() { // you can also transmit byte array up to 256 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; int state = rf.transmit(byteArr, 8); */ if (state == ERR_NONE) { // the packet was successfully transmitted - Serial.println(F(" success!")); + Serial.println(F("success!")); } else if (state == ERR_PACKET_TOO_LONG) { // the supplied packet was longer than 256 bytes - Serial.println(F(" too long!")); + Serial.println(F("too long!")); } From f1f995e9d81364a53538422833cc8d3c50888b00 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:12:38 +0100 Subject: [PATCH 015/334] [SX126x] Fixed typos --- .../SX126x_FSK_Modem/SX126x_FSK_Modem.ino | 4 ++-- .../SX126x/SX126x_Settings/SX126x_Settings.ino | 8 ++++---- .../SX126x_Transmit_Interrupt.ino | 12 ++++++------ src/modules/SX126x/SX126x.cpp | 18 +++++++++--------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino index e3e04627..90730ed0 100644 --- a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino +++ b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino @@ -99,8 +99,8 @@ void loop() { // transmit FSK packet int state = fsk.transmit("Hello World!"); /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; int state = lora.transmit(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino index 3c8a3e5e..3da7d650 100644 --- a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino +++ b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino @@ -76,12 +76,12 @@ void setup() { // bandwidth: 500.0 kHz // spreading factor: 6 // coding rate: 5 - // sync word: 0x34 (public network) + // sync word: 0x34 (public network/LoRaWAN) // output power: 2 dBm // current limit: 50 mA // preamble length: 20 symbols // CRC: enabled - state = loraSX1268.begin(915.0, 500.0, 6, 5, 0x3444, 50, 20); + state = loraSX1268.begin(915.0, 500.0, 6, 5, 0x34, 50, 20); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -117,8 +117,8 @@ void setup() { while (true); } - // set LoRa sync word to 0x1234 - if (loraSX1262.setSyncWord(0x1234) != ERR_NONE) { + // set LoRa sync word to 0xAB + if (loraSX1262.setSyncWord(0xAB) != ERR_NONE) { Serial.println(F("Unable to set sync word!")); while (true); } diff --git a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino index 157f00a1..724e05dc 100644 --- a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino +++ b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino @@ -65,9 +65,9 @@ void setup() { // you can also transmit byte array up to 256 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; - state = lora.transmit(byteArr, 8); + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + state = lora.startTransmit(byteArr, 8); */ } @@ -127,9 +127,9 @@ void loop() { // you can also transmit byte array up to 256 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; - int state = lora.transmit(byteArr, 8); + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + int state = lora.startTransmit(byteArr, 8); */ // we're ready to send more packets, diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 6b72f690..5754893f 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -310,7 +310,7 @@ int16_t SX126x::transmitDirect(uint32_t frf) { } int16_t SX126x::receiveDirect() { - // SX126x is unable to ouput received data directly + // SX126x is unable to output received data directly return(ERR_UNKNOWN); } @@ -486,7 +486,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_ senderPreambleLength = _preambleLength; } - // worst case is that the sender starts transmiting when we're just less than minSymbols from going back to sleep. + // worst case is that the sender starts transmitting when we're just less than minSymbols from going back to sleep. // in this case, we don't catch minSymbols before going to sleep, // so we must be awake for at least that long before the sender stops transmitting. uint16_t sleepSymbols = senderPreambleLength - 2 * minSymbols; @@ -504,7 +504,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_ // when the unit detects a preamble, it starts a timer that will timeout if it doesn't receive a header in time. // the duration is sleepPeriod + 2 * wakePeriod. // The sleepPeriod doesn't take into account shutdown and startup time for the unit (~1ms) - // We need to ensure that the timout is longer than senderPreambleLength. + // We need to ensure that the timeout is longer than senderPreambleLength. // So we must satisfy: wakePeriod > (preamblePeriod - (sleepPeriod - 1000)) / 2. (A) // we also need to ensure the unit is awake to see at least minSymbols. (B) uint32_t wakePeriod = max( @@ -513,7 +513,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_ RADIOLIB_DEBUG_PRINT(F("Auto wake period: ")); RADIOLIB_DEBUG_PRINTLN(wakePeriod); - //If our sleep period is shorter than our transition time, just use the standard startReceive + // If our sleep period is shorter than our transition time, just use the standard startReceive if(sleepPeriod < _tcxoDelay + 1016) { return(startReceive()); } @@ -711,7 +711,7 @@ int16_t SX126x::setFrequencyDeviation(float freqDev) { return(ERR_WRONG_MODEM); } - // check alowed frequency deviation values + // check allowed frequency deviation values if(!(freqDev <= 200.0)) { return(ERR_INVALID_FREQUENCY_DEVIATION); } @@ -735,7 +735,7 @@ int16_t SX126x::setBitRate(float br) { return(ERR_WRONG_MODEM); } - // check alowed bit rate values + // check allowed bit rate values if(!((br >= 0.6) && (br <= 300.0))) { return(ERR_INVALID_BIT_RATE); } @@ -765,7 +765,7 @@ int16_t SX126x::setRxBandwidth(float rxBw) { }*/ _rxBwKhz = rxBw; - // check alowed receiver bandwidth values + // check allowed receiver bandwidth values if(abs(rxBw - 4.8) <= 0.001) { _rxBw = SX126X_GFSK_RX_BW_4_8; } else if(abs(rxBw - 5.8) <= 0.001) { @@ -980,7 +980,7 @@ int16_t SX126x::setCRC(uint8_t len, uint16_t initial, uint16_t polynomial, bool return(state); } else if(modem == SX126X_PACKET_TYPE_LORA) { - // LoRa CRC doesn't allow to set CRC polynomial, inital value, or inversion + // LoRa CRC doesn't allow to set CRC polynomial, initial value, or inversion // update packet parameters if(len) { @@ -1526,7 +1526,7 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d // pull NSS low digitalWrite(_mod->getCs(), LOW); - // ensure BUSY is low (state meachine ready) + // ensure BUSY is low (state machine ready) uint32_t start = millis(); while(digitalRead(_mod->getGpio())) { if(millis() - start >= timeout) { From caa05f8ad8aa8f0d7e629228732dc3f3514a62b6 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:13:27 +0100 Subject: [PATCH 016/334] [SX127x] Fixed typos --- .../SX127x_Channel_Activity_Detection.ino | 4 ++-- .../SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino | 6 +++--- .../SX127x_Receive_Interrupt.ino | 2 +- examples/SX127x/SX127x_Settings/SX127x_Settings.ino | 7 ++----- examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino | 8 ++++---- .../SX127x_Transmit_Interrupt.ino | 12 ++++++------ src/modules/SX127x/SX127x.cpp | 2 +- src/modules/SX127x/SX127x.h | 9 ++++----- 8 files changed, 23 insertions(+), 27 deletions(-) diff --git a/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino b/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino index 163f8273..4d946254 100644 --- a/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino +++ b/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino @@ -59,11 +59,11 @@ void loop() { if (state == PREAMBLE_DETECTED) { // LoRa preamble was detected - Serial.println(F(" detected preamble!")); + Serial.println(F("detected preamble!")); } else if (state == CHANNEL_FREE) { // no preamble was detected, channel is free - Serial.println(F(" channel is free!")); + Serial.println(F("channel is free!")); } diff --git a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino index f9e2821d..7727bcfe 100644 --- a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino +++ b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino @@ -97,8 +97,8 @@ void loop() { // transmit FSK packet int state = fsk.transmit("Hello World!"); /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; int state = lora.transmit(byteArr, 8); */ if (state == ERR_NONE) { @@ -151,7 +151,7 @@ void loop() { // address filtering can also be disabled // NOTE: calling this method will also erase previously set - // node and broadcast address + // node and broadcast address /* state = fsk.disableAddressFiltering(); if (state != ERR_NONE) { diff --git a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino index fbc20651..7f192757 100644 --- a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino +++ b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino @@ -118,7 +118,7 @@ void loop() { // you can also read received data as byte array /* byte byteArr[8]; - int state = lora.receive(byteArr, 8); + int state = lora.readData(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino index 681c76d2..76b26b10 100644 --- a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino +++ b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino @@ -91,9 +91,6 @@ void setup() { // you can also change the settings at runtime // and check if the configuration was changed successfully - // different modules accept different parameters - // see https://github.com/jgromes/LoRaLib/wiki/Supported-LoRa-modules - // set carrier frequency to 433.5 MHz if (loraSX1278.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { Serial.println(F("Selected frequency is invalid for this module!")); @@ -147,14 +144,14 @@ void setup() { } // set amplifier gain to 1 (accepted range is 1 - 6, where 1 is maximum gain) - // NOTE: set value to 0 to enable autmatic gain control + // NOTE: set value to 0 to enable automatic gain control // leave at 0 unless you know what you're doing if (loraSX1278.setGain(1) == ERR_INVALID_GAIN) { Serial.println(F("Selected gain is invalid for this module!")); while (true); } - Serial.println(F("All settings succesfully changed!")); + Serial.println(F("All settings successfully changed!")); } void loop() { diff --git a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino index d14e76f7..cd5ad220 100644 --- a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino +++ b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino @@ -63,7 +63,7 @@ void loop() { // you can also transmit byte array up to 256 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; int state = lora.transmit(byteArr, 8); */ @@ -78,11 +78,11 @@ void loop() { } else if (state == ERR_PACKET_TOO_LONG) { // the supplied packet was longer than 256 bytes - Serial.println(F(" too long!")); + Serial.println(F("too long!")); } else if (state == ERR_TX_TIMEOUT) { - // timeout occured while transmitting packet - Serial.println(F(" timeout!")); + // timeout occurred while transmitting packet + Serial.println(F("timeout!")); } else { // some other error occurred diff --git a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino index 8368a7d4..0290e54b 100644 --- a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino +++ b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino @@ -67,9 +67,9 @@ void setup() { // you can also transmit byte array up to 256 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; - state = lora.transmit(byteArr, 8); + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + state = lora.startTransmit(byteArr, 8); */ } @@ -129,9 +129,9 @@ void loop() { // you can also transmit byte array up to 256 bytes long /* - byte byteArr[] = {0x01, 0x23, 0x45, 0x56, - 0x78, 0xAB, 0xCD, 0xEF}; - int state = lora.transmit(byteArr, 8); + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + int state = lora.startTransmit(byteArr, 8); */ // we're ready to send more packets, diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 1ba7b49e..b8b01dbc 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -43,7 +43,7 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi state = SX127x::setPreambleLength(preambleLength); RADIOLIB_ASSERT(state); - // initalize internal variables + // initialize internal variables _dataRate = 0.0; return(state); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index aa6bb03b..1edf5917 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -480,7 +480,7 @@ #define SX127X_FLAG_TX_READY 0b00100000 // 5 5 transmission ready (after PA ramp-up) #define SX127X_FLAG_PLL_LOCK 0b00010000 // 4 4 PLL locked #define SX127X_FLAG_RSSI 0b00001000 // 3 3 RSSI value exceeds RSSI threshold -#define SX127X_FLAG_TIMEOUT 0b00000100 // 2 2 timeout occured +#define SX127X_FLAG_TIMEOUT 0b00000100 // 2 2 timeout occurred #define SX127X_FLAG_PREAMBLE_DETECT 0b00000010 // 1 1 valid preamble was detected #define SX127X_FLAG_SYNC_ADDRESS_MATCH 0b00000001 // 0 0 sync address matched @@ -488,7 +488,7 @@ #define SX127X_FLAG_FIFO_FULL 0b10000000 // 7 7 FIFO is full #define SX127X_FLAG_FIFO_EMPTY 0b01000000 // 6 6 FIFO is empty #define SX127X_FLAG_FIFO_LEVEL 0b00100000 // 5 5 number of bytes in FIFO exceeds FIFO_THRESHOLD -#define SX127X_FLAG_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occured +#define SX127X_FLAG_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occurred #define SX127X_FLAG_PACKET_SENT 0b00001000 // 3 3 packet was successfully sent #define SX127X_FLAG_PAYLOAD_READY 0b00000100 // 2 2 packet was successfully received #define SX127X_FLAG_CRC_OK 0b00000010 // 1 1 CRC check passed @@ -565,7 +565,7 @@ class SX127x: public PhysicalLayer { int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength); /*! - \brief Reset method. Will reset the chip to the default state using RST pin. Declared pure virtual since SX1272 and SX1278 implmentations differ. + \brief Reset method. Will reset the chip to the default state using RST pin. Declared pure virtual since SX1272 and SX1278 implementations differ. */ virtual void reset() = 0; @@ -663,7 +663,6 @@ class SX127x: public PhysicalLayer { */ int16_t packetMode(); - // interrupt methods /*! @@ -880,7 +879,7 @@ class SX127x: public PhysicalLayer { /*! \brief Sets RSSI measurement configuration in FSK mode. - \param smoothingSamples Number of samples taken to avergae the RSSI result. + \param smoothingSamples Number of samples taken to average the RSSI result. numSamples = 2 ^ (1 + smoothingSamples), allowed values are in range 0 (2 samples) - 7 (256 samples) \param offset Signed RSSI offset that will be automatically compensated. 1 dB per LSB, defaults to 0, allowed values are in range -16 dB to +15 dB. From d3cec5d3b43d6ad4d85977f3e59307b838935ddd Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:14:03 +0100 Subject: [PATCH 017/334] [Module] Removed String class from AT commands --- src/Module.cpp | 11 ++++++----- src/Module.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index 7a714d85..06213b55 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -137,19 +137,20 @@ bool Module::ATsendData(uint8_t* data, uint32_t len) { } bool Module::ATgetResponse() { - String data = ""; + char data[128]; + char* dataPtr = data; uint32_t start = millis(); - while (millis() - start < _ATtimeout) { + while(millis() - start < _ATtimeout) { while(ModuleSerial->available() > 0) { char c = ModuleSerial->read(); RADIOLIB_VERBOSE_PRINT(c); - data += c; + *dataPtr++ = c; } - if(data.indexOf("OK") != -1) { + if(strstr(data, "OK") == 0) { RADIOLIB_VERBOSE_PRINTLN(); return(true); - } else if (data.indexOf("ERROR") != -1) { + } else if(strstr(data, "ERROR") == 0) { RADIOLIB_VERBOSE_PRINTLN(); return(false); } diff --git a/src/Module.h b/src/Module.h index ddc43c51..fd0b4e25 100644 --- a/src/Module.h +++ b/src/Module.h @@ -172,7 +172,7 @@ class Module { /*! \brief Get response after sending AT command. - \returns True if AT response contains the string "OK", false otehrwise. + \returns True if AT response contains the string "OK", false otherwise. */ bool ATgetResponse(); From 61bb57b9be0c5617e62186e5fe8ca06ed8c930fc Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:14:23 +0100 Subject: [PATCH 018/334] [ESP8266] Fixed typos --- src/modules/ESP8266/ESP8266.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/ESP8266/ESP8266.h b/src/modules/ESP8266/ESP8266.h index aa4e145c..0469cd01 100644 --- a/src/modules/ESP8266/ESP8266.h +++ b/src/modules/ESP8266/ESP8266.h @@ -46,7 +46,7 @@ class ESP8266: public TransportLayer { */ int16_t join(const char* ssid, const char* password); - // transport layer methods (implementations of purely virtual methods in TransportMethod class) + // transport layer methods (implementations of purely virtual methods in TransportLayer class) int16_t openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive = 0); int16_t closeTransportConnection(); int16_t send(const char* data); From 73d5a482d16ab4e77431cb29e93ab7d157dac154 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Mar 2020 08:14:32 +0100 Subject: [PATCH 019/334] [nRF24] Fixed typos --- src/modules/nRF24/nRF24.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 70362dfe..a3205f78 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -428,7 +428,7 @@ class nRF24: public PhysicalLayer { int16_t setCrcFiltering(bool crcOn = true); /*! - \brief Enable or disable auto-acknowlede packets on all pipes + \brief Enable or disable auto-acknowledge packets on all pipes \param autoAckOn Enable (true) or disable (false) auto-acks. @@ -437,7 +437,7 @@ class nRF24: public PhysicalLayer { int16_t setAutoAck(bool autoAckOn = true); /*! - \brief Enable or disable auto-acknowlede packets on given pipe. + \brief Enable or disable auto-acknowledge packets on given pipe. \param pipeNum Number of pipe to which enable / disable auto-acks. From b05c264363cf43edcbf303a5639527ce3cc2255b Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 23 Mar 2020 20:23:37 +0100 Subject: [PATCH 020/334] Fixed typo in version macro --- src/TypeDef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TypeDef.h b/src/TypeDef.h index d149ca1b..adc3b1eb 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -13,7 +13,7 @@ #define RADIOLIB_VERSION_PATCH (0x00) #define RADIOLIB_VERSION_EXTRA (0x00) -#define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MAJOR << 16) | (RADIOLIB_VERSION_MAJOR << 8) | (RADIOLIB_VERSION_EXTRA)) +#define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA)) /* * Uncomment to enable static-only memory management: no dynamic allocation will be performed. From 8a496efd4186e3156544ebc81529a5220050d89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Thu, 26 Mar 2020 21:41:52 +0100 Subject: [PATCH 021/334] Update CONTRIBUTING.md --- CONTRIBUTING.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12fa8518..563d444f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,3 +67,44 @@ If you're adding a new method, make sure to add appropriate Doxygen comments, so 6. **Keywords** This is an Arduino library, so it needs to comply with the Arduino library specification. To add a new keyword to the Arduino IDE syntax highlighting, add it to the keywords.txt file. **Use true tabs in keywords.txt! No spaces there!** + +7. **Dynamic memory** +Sometimes, RadioLib might be used in critical applications where dynamic memory allocation using `new` or `malloc` might cause issues. For such cases, RadioLib provides the option to compile using only static arrays. This means that every dynamically allocated array must have a sufficiently large static counterpart. Naturally, all dynamically allocated memory must be properly de-allocated using `delete` or `free`. + +```c++ +// build a temporary buffer +#ifdef RADIOLIB_STATIC_ONLY + uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1]; +#else + uint8_t* data = new uint8_t[length + 1]; + if(!data) { + return(ERR_MEMORY_ALLOCATION_FAILED); + } +#endif + +// read the received data +readData(data, length); + +// deallocate temporary buffer +#ifndef RADIOLIB_STATIC_ONLY + delete[] data; +#endif +``` + +8. **God Mode** +During development, it can be useful to have access to the low level drivers, such as the SPI commands. These are incredibly powerful, since they will basically let user do anything he wants with the module, outside of the normal level of sanity checks. As such, they are normally protected using C++ access modifiers `private` or `protected`. God mode disables this protection, and so any newly implemented `class` must contain the appropriate macro check: + +```c++ +class Module { + void publicMethod(); + +#ifndef RADIOLIB_GODMODE + private: +#endif + + void privateMethod(); +}; +``` + +9. **No Arduino Strings** +Arduino `String` class should never be used internally in the library. The only allowed occurence of Arduino `String` is in public API methods, and only at the top-most layer. From fd6ef55a068d2209a5b301375a2e96facb7b737e Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 27 Mar 2020 14:09:46 +0100 Subject: [PATCH 022/334] Simplified ESP8266 detection macro --- src/RadioLib.h | 9 +++++---- src/modules/ESP8266/ESP8266.cpp | 2 +- src/modules/ESP8266/ESP8266.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/RadioLib.h b/src/RadioLib.h index 1775fa0e..78b0f8ae 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -44,9 +44,9 @@ #endif #include "modules/CC1101/CC1101.h" -#ifndef ESP8266 +//#if !defined(ESP8266) && !defined(ARDUINO_ARDUINO_NANO33BLE) #include "modules/ESP8266/ESP8266.h" -#endif +//#endif #include "modules/HC05/HC05.h" #include "modules/JDY08/JDY08.h" #include "modules/nRF24/nRF24.h" @@ -54,6 +54,7 @@ #include "modules/RFM9x/RFM95.h" #include "modules/RFM9x/RFM96.h" #include "modules/RFM9x/RFM97.h" +//#include "modules/Si443x/Si4432.h" #include "modules/SX1231/SX1231.h" #include "modules/SX126x/SX1261.h" #include "modules/SX126x/SX1262.h" @@ -73,11 +74,11 @@ #include "protocols/RTTY/RTTY.h" // transport layer protocols -#ifndef ESP8266 +//#if !defined(ESP8266) && !defined(ARDUINO_ARDUINO_NANO33BLE) #include "protocols/TransportLayer/TransportLayer.h" #include "protocols/HTTP/HTTP.h" #include "protocols/MQTT/MQTT.h" -#endif +//#endif // only create Radio class when using RadioShield #ifdef RADIOLIB_RADIOSHIELD diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index ab50f640..b221d0ff 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -1,4 +1,4 @@ -#ifndef ESP8266 +#if !defined(ESP8266) && !defined(ARDUINO_ARDUINO_NANO33BLE) #include "ESP8266.h" ESP8266::ESP8266(Module* module) { diff --git a/src/modules/ESP8266/ESP8266.h b/src/modules/ESP8266/ESP8266.h index 0469cd01..e817038e 100644 --- a/src/modules/ESP8266/ESP8266.h +++ b/src/modules/ESP8266/ESP8266.h @@ -1,4 +1,4 @@ -#if !defined(_RADIOLIB_ESP8266_H) && !defined(ESP8266) +#if !defined(_RADIOLIB_ESP8266_H) #define _RADIOLIB_ESP8266_H #include "../../Module.h" From 39c259848c8cf30b282b741b2dcc107a3a292178 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 27 Mar 2020 14:10:45 +0100 Subject: [PATCH 023/334] Added support for Nano 33 BLE --- src/Module.cpp | 43 ++++++----- src/Module.h | 55 ++++++++------ src/TypeDef.h | 131 ++++++++++++++++++++++++++++++---- src/modules/CC1101/CC1101.cpp | 8 +-- src/modules/CC1101/CC1101.h | 4 +- src/modules/RF69/RF69.cpp | 4 +- src/modules/SX127x/SX127x.cpp | 4 +- 7 files changed, 184 insertions(+), 65 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index 06213b55..8482e32c 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -1,9 +1,9 @@ #include "Module.h" -Module::Module(int16_t cs, int16_t irq, int16_t rst) { +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst) { _cs = cs; - _rx = NC; - _tx = NC; + _rx = RADIOLIB_NC; + _tx = RADIOLIB_NC; _irq = irq; _rst = rst; _spi = &SPI; @@ -11,10 +11,10 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst) { _initInterface = true; } -Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio) { +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio) { _cs = cs; _rx = gpio; - _tx = NC; + _tx = RADIOLIB_NC; _irq = irq; _rst = rst; _spi = &SPI; @@ -22,11 +22,11 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio) { _initInterface = true; } -Module::Module(int16_t rx, int16_t tx, HardwareSerial* useSer, int16_t rst) { - _cs = NC; +Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* useSer, RADIOLIB_PIN_TYPE rst) { + _cs = RADIOLIB_NC; _rx = rx; _tx = tx; - _irq = NC; + _irq = RADIOLIB_NC; _rst = rst; _initInterface = true; @@ -38,10 +38,10 @@ Module::Module(int16_t rx, int16_t tx, HardwareSerial* useSer, int16_t rst) { #endif } -Module::Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi, SPISettings spiSettings) { +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass& spi, SPISettings spiSettings) { _cs = cs; - _rx = NC; - _tx = NC; + _rx = RADIOLIB_NC; + _tx = RADIOLIB_NC; _irq = irq; _rst = rst; _spi = &spi; @@ -49,10 +49,10 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi, SPISettings _initInterface = false; } -Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi, SPISettings spiSettings) { +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings) { _cs = cs; _rx = gpio; - _tx = NC; + _tx = RADIOLIB_NC; _irq = irq; _rst = rst; _spi = &spi; @@ -60,7 +60,7 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi _initInterface = false; } -Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t rx, int16_t tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* useSer) { +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* useSer) { _cs = cs; _rx = rx; _tx = tx; @@ -276,14 +276,21 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da _spi->endTransaction(); } -void Module::pinMode(int16_t pin, uint8_t mode) { - if(pin != NC) { +void Module::pinMode(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_MODE mode) { + if(pin != RADIOLIB_NC) { ::pinMode(pin, mode); } } -void Module::digitalWrite(int16_t pin, uint8_t value) { - if(pin != NC) { +void Module::digitalWrite(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS value) { + if(pin != RADIOLIB_NC) { ::digitalWrite(pin, value); } } + +RADIOLIB_PIN_STATUS Module::digitalRead(RADIOLIB_PIN_TYPE pin) { + if(pin != RADIOLIB_NC) { + return(::digitalRead(pin)); + } + return(LOW); +} diff --git a/src/Module.h b/src/Module.h index fd0b4e25..ebc81986 100644 --- a/src/Module.h +++ b/src/Module.h @@ -30,9 +30,9 @@ class Module { \param rst Arduino pin to be used as hardware reset for the module. Defaults to NC (unused). */ #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - Module(int16_t tx, int16_t rx, HardwareSerial* serial = &Serial1, int16_t rst = NC); + Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC); #else - Module(int16_t tx, int16_t rx, HardwareSerial* serial = nullptr, int16_t rst = NC); + Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = nullptr, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC); #endif /*! @@ -44,7 +44,7 @@ class Module { \param rst Arduino pin to be used as hardware reset for the module. */ - Module(int16_t cs, int16_t irq, int16_t rst); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst); /*! \brief Extended SPI-based module constructor. Will use the default SPI interface automatically initialize it. @@ -57,7 +57,7 @@ class Module { \param gpio Arduino pin to be used as additional interrupt/GPIO. */ - Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio); /*! \brief SPI-based module constructor. @@ -72,7 +72,7 @@ class Module { \param spiSettings SPI interface settings. */ - Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi, SPISettings spiSettings); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass& spi, SPISettings spiSettings); /*! \brief Extended SPI-based module constructor. @@ -89,7 +89,7 @@ class Module { \param spiSettings SPI interface settings. */ - Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi, SPISettings spiSettings); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings); /*! \brief Generic module constructor. @@ -111,9 +111,9 @@ class Module { \param serial HardwareSerial to be used on ESP32 and SAMD. Defaults to 1 */ #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - Module(int16_t cs, int16_t irq, int16_t rst, int16_t rx, int16_t tx, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = &Serial1); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT); #else - Module(int16_t cs, int16_t irq, int16_t rst, int16_t rx, int16_t tx, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = nullptr); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = nullptr); #endif @@ -290,42 +290,42 @@ class Module { \returns Pin number of SPI chip select configured in the constructor. */ - int16_t getCs() const { return(_cs); } + RADIOLIB_PIN_TYPE getCs() const { return(_cs); } /*! \brief Access method to get the pin number of interrupt/GPIO. \returns Pin number of interrupt/GPIO configured in the constructor. */ - int16_t getIrq() const { return(_irq); } + RADIOLIB_PIN_TYPE getIrq() const { return(_irq); } /*! \brief Access method to get the pin number of hardware reset pin. \returns Pin number of hardware reset pin configured in the constructor. */ - int16_t getRst() const { return(_rst); } + RADIOLIB_PIN_TYPE getRst() const { return(_rst); } /*! \brief Access method to get the pin number of second interrupt/GPIO. \returns Pin number of second interrupt/GPIO configured in the constructor. */ - int16_t getGpio() const { return(_rx); } + RADIOLIB_PIN_TYPE getGpio() const { return(_rx); } /*! \brief Access method to get the pin number of UART Rx. \returns Pin number of UART Rx configured in the constructor. */ - int16_t getRx() const { return(_rx); } + RADIOLIB_PIN_TYPE getRx() const { return(_rx); } /*! \brief Access method to get the pin number of UART Rx. \returns Pin number of UART Rx configured in the constructor. */ - int16_t getTx() const { return(_tx); } + RADIOLIB_PIN_TYPE getTx() const { return(_tx); } /*! \brief Access method to get the SPI interface. @@ -342,31 +342,40 @@ class Module { SPISettings getSpiSettings() const { return(_spiSettings); } /*! - \brief Arduino core pinMode override that checks -1 as alias for unused pin. + \brief Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin. \param pin Pin to change the mode of. \param mode Which mode to set. */ - static void pinMode(int16_t pin, uint8_t mode); + static void pinMode(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_MODE mode); /*! - \brief Arduino core digitalWrite override that checks -1 as alias for unused pin. + \brief Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin. \param pin Pin to write to. \param value Whether to set the pin high or low. */ - static void digitalWrite(int16_t pin, uint8_t value); + static void digitalWrite(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS value); + + /*! + \brief Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin. + + \param pin Pin to read from. + + \returns Pin value. + */ + static RADIOLIB_PIN_STATUS digitalRead(RADIOLIB_PIN_TYPE pin); #ifndef RADIOLIB_GODMODE private: #endif - int16_t _cs; - int16_t _tx; - int16_t _rx; - int16_t _irq; - int16_t _rst; + RADIOLIB_PIN_TYPE _cs; + RADIOLIB_PIN_TYPE _tx; + RADIOLIB_PIN_TYPE _rx; + RADIOLIB_PIN_TYPE _irq; + RADIOLIB_PIN_TYPE _rst; bool _initInterface; SPIClass* _spi; diff --git a/src/TypeDef.h b/src/TypeDef.h index adc3b1eb..08c58f6e 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -7,6 +7,123 @@ #error "Unsupported Arduino version (< 1.0.0)" #endif +/* + * Platform-specific configuration. + * + * RADIOLIB_PIN_TYPE - which type should be used for pin numbers in functions like digitalRead(). + * RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode(). + * RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite(). + * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. + * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platfrom does not support SoftwareSerial. + * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platfroms taht do not have SoftwareSerial support. + * + * In addition, some platforms amy require RadioLib to disable spceific drivers (such as ESP8266). + */ +#if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) + // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + +#elif defined(ESP8266) + // ESP8266 boards + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + + // RadioLib has ESPS8266 driver, this must be disabled to use ESP8266 as platform + #define _RADIOLIB_ESP8266_H + +#elif defined(ESP32) + // ESP32 boards + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(ARDUINO_ARCH_STM32) + // STM32duino boards + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(SAMD_SERIES) + // Arduino SAMD boards - Zero, MKR, etc. + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(__SAM3X8E__) + // Arduino Due + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) + // Adafruit nRF52 boards + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + +#elif defined(ARDUINO_ARC32_TOOLS) + // Intel Curie + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) + // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE PinMode + #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_NC (0xFF) + +#elif defined(AM_PART_APOLLO3) + // Sparkfun Artemis boards + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(ARDUINO_ARDUINO_NANO33BLE) + // Arduino Nano 33 BLE + #define RADIOLIB_PIN_TYPE pin_size_t + #define RADIOLIB_PIN_MODE PinMode + #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + + // Nano 33 BLE uses mbed libraries, which already contain ESP8266 driver + #define _RADIOLIB_ESP8266_H + +#else + // other platforms not covered by the above list - this may or may not work + #warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + +#endif + // version definitions #define RADIOLIB_VERSION_MAJOR (0x03) #define RADIOLIB_VERSION_MINOR (0x04) @@ -67,20 +184,6 @@ */ //#define RADIOLIB_RADIOSHIELD -/* - * The following platforms do not support SoftwareSerial library. - */ -#if defined(ESP32) || defined(SAMD_SERIES) || defined(ARDUINO_ARCH_STM32) || defined(__SAM3X8E__) || defined(AM_PART_APOLLO3) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED -#endif - -/*! - \brief Alias for unused pin, if not supplied by the Arduino core. -*/ -#if !(defined(NC) || defined(ARDUINO_ARCH_STM32)) -#define NC (-1) -#endif - /*! \brief A simple assert macro, will return on error. */ diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index f8e2aa1e..823b6b27 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -179,7 +179,7 @@ int16_t CC1101::packetMode() { return(state); } -void CC1101::setGdo0Action(void (*func)(void), uint8_t dir) { +void CC1101::setGdo0Action(void (*func)(void), RADIOLIB_PIN_STATUS dir) { attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, dir); } @@ -187,8 +187,8 @@ void CC1101::clearGdo0Action() { detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); } -void CC1101::setGdo2Action(void (*func)(void), uint8_t dir) { - if(_mod->getGpio() != NC) { +void CC1101::setGdo2Action(void (*func)(void), RADIOLIB_PIN_STATUS dir) { + if(_mod->getGpio() != RADIOLIB_NC) { return; } Module::pinMode(_mod->getGpio(), INPUT); @@ -196,7 +196,7 @@ void CC1101::setGdo2Action(void (*func)(void), uint8_t dir) { } void CC1101::clearGdo2Action() { - if(_mod->getGpio() != NC) { + if(_mod->getGpio() != RADIOLIB_NC) { return; } detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index 2486647f..c1969d27 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -600,7 +600,7 @@ class CC1101: public PhysicalLayer { \param dir Signal change direction. Defaults to FALLING. */ - void setGdo0Action(void (*func)(void), uint8_t dir = FALLING); + void setGdo0Action(void (*func)(void), RADIOLIB_PIN_STATUS dir = FALLING); /*! \brief Clears interrupt service routine to call when GDO0 activates. @@ -614,7 +614,7 @@ class CC1101: public PhysicalLayer { \param dir Signal change direction. Defaults to FALLING. */ - void setGdo2Action(void (*func)(void), uint8_t dir = FALLING); + void setGdo2Action(void (*func)(void), RADIOLIB_PIN_STATUS dir = FALLING); /*! \brief Clears interrupt service routine to call when GDO0 activates. diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 69dc4351..2ef86d4e 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -251,7 +251,7 @@ void RF69::clearDio0Action() { } void RF69::setDio1Action(void (*func)(void)) { - if(_mod->getGpio() != NC) { + if(_mod->getGpio() != RADIOLIB_NC) { return; } Module::pinMode(_mod->getGpio(), INPUT); @@ -259,7 +259,7 @@ void RF69::setDio1Action(void (*func)(void)) { } void RF69::clearDio1Action() { - if(_mod->getGpio() != NC) { + if(_mod->getGpio() != RADIOLIB_NC) { return; } detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index b8b01dbc..5eab0195 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -376,14 +376,14 @@ void SX127x::clearDio0Action() { } void SX127x::setDio1Action(void (*func)(void)) { - if(_mod->getGpio() != NC) { + if(_mod->getGpio() != RADIOLIB_NC) { return; } attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, RISING); } void SX127x::clearDio1Action() { - if(_mod->getGpio() != NC) { + if(_mod->getGpio() != RADIOLIB_NC) { return; } detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); From c9785f30b2b3d421b795dbbe82ca24b7fffe43ae Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 27 Mar 2020 14:11:13 +0100 Subject: [PATCH 024/334] Renamed NC macro --- .../CC1101/CC1101_Receive/CC1101_Receive.ino | 2 +- .../CC1101_Receive_Address.ino | 2 +- .../CC1101_Receive_Interrupt.ino | 17 ++++++++++------- .../CC1101/CC1101_Settings/CC1101_Settings.ino | 4 ++-- .../CC1101/CC1101_Transmit/CC1101_Transmit.ino | 2 +- .../CC1101_Transmit_Address.ino | 2 +- .../CC1101_Transmit_Interrupt.ino | 2 +- keywords.txt | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/examples/CC1101/CC1101_Receive/CC1101_Receive.ino b/examples/CC1101/CC1101_Receive/CC1101_Receive.ino index e36c1d9a..fa8f3aa8 100644 --- a/examples/CC1101/CC1101_Receive/CC1101_Receive.ino +++ b/examples/CC1101/CC1101_Receive/CC1101_Receive.ino @@ -21,7 +21,7 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, NC, 3); +CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino b/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino index 4cbd10f2..3e12b6d5 100644 --- a/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino +++ b/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino @@ -19,7 +19,7 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, NC, 3); +CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino index 46f3279d..b57c4102 100644 --- a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino +++ b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino @@ -24,7 +24,7 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, NC, 3); +CC1101 cc = new Module(5, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield @@ -105,22 +105,25 @@ void loop() { receivedFlag = false; // you can read received data as an Arduino String - String str; - int state = cc.readData(str); + //String str; + //int state = cc.readData(str); // you can also read received data as byte array - /* + byte byteArr[8]; int state = cc.readData(byteArr, 8); - */ + if (state == ERR_NONE) { // packet was successfully received Serial.println(F("[CC1101] Received packet!")); // print data of the packet - Serial.print(F("[CC1101] Data:\t\t")); - Serial.println(str); + Serial.println(F("[CC1101] Data:\t\t")); + //Serial.println(str); + for(uint8_t i = 0; i < 8; i++) { + Serial.println(byteArr[i], HEX); + } // print RSSI (Received Signal Strength Indicator) // of the last received packet diff --git a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino index 74b2b3b1..02394da1 100644 --- a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino +++ b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino @@ -23,14 +23,14 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc1 = new Module(10, 2, NC, 3); +CC1101 cc1 = new Module(10, 2, RADIOLIB_NC, 3); // second CC1101 has different connections: // CS pin: 9 // GDO0 pin: 4 // RST pin: unused // GDO2 pin: 5 (optional) -CC1101 cc2 = new Module(9, 4, NC, 53); +CC1101 cc2 = new Module(9, 4, RADIOLIB_NC, 53); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino b/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino index 104fe2bb..be530890 100644 --- a/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino +++ b/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino @@ -19,7 +19,7 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, NC, 3); +CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino index 94905bad..e584eb7c 100644 --- a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino +++ b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino @@ -19,7 +19,7 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, NC, 3); +CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino index a89cf0ca..47991677 100644 --- a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino +++ b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino @@ -20,7 +20,7 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, NC, 3); +CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/keywords.txt b/keywords.txt index 10f66074..a5ba3b5a 100644 --- a/keywords.txt +++ b/keywords.txt @@ -188,7 +188,7 @@ sendFrame KEYWORD2 # Constants (LITERAL1) ####################################### -NC LITERAL1 +RADIOLIB_NC LITERAL1 RADIOLIB_VERSION LITERAL1 ERR_NONE LITERAL1 From d8816f7bad90102511df6b7bb5d81dedbcf355a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Fri, 27 Mar 2020 14:39:45 +0100 Subject: [PATCH 025/334] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b3980dee..dce4e29a 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,17 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * __AX.25__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231 and CC1101 ### Supported platforms: -* __AVR__ - tested with hardware on Uno, Mega and Leonardo +* __Arduino AVR__ - tested with hardware on Uno, Mega and Leonardo * __ESP8266__ - tested with hardware on NodeMCU and Wemos D1 * __ESP32__ - tested with hardware on ESP-WROOM-32 * __STM32__ - tested with hardware on Nucleo L452RE-P -* __SAMD__ - Arduino Zero, Arduino MKR boards, M0 Pro etc. -* __SAM__ - Arduino Due -* __nRF52__ - Adafruit Bluefruit Feather etc. +* __Arduino SAMD__ - Arduino Zero, Arduino MKR boards, M0 Pro etc. +* __Arduino SAM__ - Arduino Due +* __Adafruit nRF52__ - Adafruit Bluefruit Feather etc. * _Intel Curie_ - Arduino 101 -* _megaAVR_ - Arduino Uno WiFi Rev.2 etc. +* _Arduino megaAVR_ - Arduino Uno WiFi Rev.2 etc. * _Apollo3_ - SparkFun Artemis Redboard etc. +* _Arduino nRF52__ - Arduino Nano 33 BLE The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platoforms in __bold__ on each git push. Platforms in _italic_ are not tested on each push, but do compile and should be working. From 035693fc11b613458735826c583b485f7d1e8579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Fri, 27 Mar 2020 14:40:20 +0100 Subject: [PATCH 026/334] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dce4e29a..61bf5c97 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * _Intel Curie_ - Arduino 101 * _Arduino megaAVR_ - Arduino Uno WiFi Rev.2 etc. * _Apollo3_ - SparkFun Artemis Redboard etc. -* _Arduino nRF52__ - Arduino Nano 33 BLE +* _Arduino nRF52_ - Arduino Nano 33 BLE The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platoforms in __bold__ on each git push. Platforms in _italic_ are not tested on each push, but do compile and should be working. From 512567b9f31de764266679464b827646bf81da72 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 27 Mar 2020 21:03:23 +0100 Subject: [PATCH 027/334] Fixed typos --- src/RadioLib.h | 5 ----- src/TypeDef.h | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/RadioLib.h b/src/RadioLib.h index 78b0f8ae..d434a8d5 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -44,9 +44,7 @@ #endif #include "modules/CC1101/CC1101.h" -//#if !defined(ESP8266) && !defined(ARDUINO_ARDUINO_NANO33BLE) #include "modules/ESP8266/ESP8266.h" -//#endif #include "modules/HC05/HC05.h" #include "modules/JDY08/JDY08.h" #include "modules/nRF24/nRF24.h" @@ -54,7 +52,6 @@ #include "modules/RFM9x/RFM95.h" #include "modules/RFM9x/RFM96.h" #include "modules/RFM9x/RFM97.h" -//#include "modules/Si443x/Si4432.h" #include "modules/SX1231/SX1231.h" #include "modules/SX126x/SX1261.h" #include "modules/SX126x/SX1262.h" @@ -74,11 +71,9 @@ #include "protocols/RTTY/RTTY.h" // transport layer protocols -//#if !defined(ESP8266) && !defined(ARDUINO_ARDUINO_NANO33BLE) #include "protocols/TransportLayer/TransportLayer.h" #include "protocols/HTTP/HTTP.h" #include "protocols/MQTT/MQTT.h" -//#endif // only create Radio class when using RadioShield #ifdef RADIOLIB_RADIOSHIELD diff --git a/src/TypeDef.h b/src/TypeDef.h index 08c58f6e..4f4c2171 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -14,10 +14,10 @@ * RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode(). * RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite(). * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. - * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platfrom does not support SoftwareSerial. - * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platfroms taht do not have SoftwareSerial support. + * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platform does not support SoftwareSerial. + * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platform that do not have SoftwareSerial support. * - * In addition, some platforms amy require RadioLib to disable spceific drivers (such as ESP8266). + * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). */ #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. From 7007cd873adea87329625b09cdd3cea1390dba11 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 29 Mar 2020 10:02:23 +0200 Subject: [PATCH 028/334] Extracted build options into a new file --- src/BuildOpt.h | 198 +++++++++++++++++++++++++++++++++++++++++++++++++ src/TypeDef.h | 188 +--------------------------------------------- 2 files changed, 199 insertions(+), 187 deletions(-) create mode 100644 src/BuildOpt.h diff --git a/src/BuildOpt.h b/src/BuildOpt.h new file mode 100644 index 00000000..6e1a8690 --- /dev/null +++ b/src/BuildOpt.h @@ -0,0 +1,198 @@ +#ifndef _RADIOLIB_BUILD_OPTIONS_H +#define _RADIOLIB_BUILD_OPTIONS_H + +#if ARDUINO >= 100 + #include "Arduino.h" +#else + #error "Unsupported Arduino version (< 1.0.0)" +#endif + +/* + * Platform-specific configuration. + * + * RADIOLIB_PIN_TYPE - which type should be used for pin numbers in functions like digitalRead(). + * RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode(). + * RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite(). + * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. + * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platform does not support SoftwareSerial. + * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platform that do not have SoftwareSerial support. + * + * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). + */ +#if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) + // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + +#elif defined(ESP8266) + // ESP8266 boards + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + + // RadioLib has ESPS8266 driver, this must be disabled to use ESP8266 as platform + #define _RADIOLIB_ESP8266_H + +#elif defined(ESP32) + // ESP32 boards + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(ARDUINO_ARCH_STM32) + // STM32duino boards + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(SAMD_SERIES) + // Arduino SAMD boards - Zero, MKR, etc. + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(__SAM3X8E__) + // Arduino Due + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) + // Adafruit nRF52 boards + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_NC (0xFFFFFFFF) + +#elif defined(ARDUINO_ARC32_TOOLS) + // Intel Curie + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) + // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE PinMode + #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_NC (0xFF) + +#elif defined(AM_PART_APOLLO3) + // Sparkfun Artemis boards + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + +#elif defined(ARDUINO_ARDUINO_NANO33BLE) + // Arduino Nano 33 BLE + #define RADIOLIB_PIN_TYPE pin_size_t + #define RADIOLIB_PIN_MODE PinMode + #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + + // Nano 33 BLE uses mbed libraries, which already contain ESP8266 driver + #define _RADIOLIB_ESP8266_H + +#else + // other platforms not covered by the above list - this may or may not work + #warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_NC (0xFF) + +#endif + +/* + * Uncomment to enable debug output. + * Warning: Debug output will slow down the whole system significantly. + * Also, it will result in larger compiled binary. + * Levels: debug - only main info + * verbose - full transcript of all SPI/UART communication + */ + +//#define RADIOLIB_DEBUG +//#define RADIOLIB_VERBOSE + +// set which Serial port should be used for debug output +#define RADIOLIB_DEBUG_PORT Serial + +#ifdef RADIOLIB_DEBUG + #define RADIOLIB_DEBUG_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); } + #define RADIOLIB_DEBUG_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } +#else + #define RADIOLIB_DEBUG_PRINT(...) {} + #define RADIOLIB_DEBUG_PRINTLN(...) {} +#endif + +#ifdef RADIOLIB_VERBOSE + #define RADIOLIB_VERBOSE_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); } + #define RADIOLIB_VERBOSE_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } +#else + #define RADIOLIB_VERBOSE_PRINT(...) {} + #define RADIOLIB_VERBOSE_PRINTLN(...) {} +#endif + +/* + * Uncomment to enable god mode - all methods and member variables in all classes will be made public, thus making them accessible from Arduino code. + * Warning: Come on, it's called GOD mode - obviously only use this if you know what you're doing. + * Failure to heed the above warning may result in bricked module. + */ +//#define RADIOLIB_GODMODE + +/* + * Uncomment to enable pre-defined modules when using RadioShield. + */ +//#define RADIOLIB_RADIOSHIELD + +/* + * Uncomment to enable static-only memory management: no dynamic allocation will be performed. + * Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode. + */ + +//#define RADIOLIB_STATIC_ONLY + +// set the size of static arrays to use +#define RADIOLIB_STATIC_ARRAY_SIZE 256 + +/*! + \brief A simple assert macro, will return on error. +*/ +#define RADIOLIB_ASSERT(STATEVAR) { if((STATEVAR) != ERR_NONE) { return(STATEVAR); } } + +/*! + \brief Macro to check variable is within constraints - this is commonly used to check parameter ranges. +*/ +#define RADIOLIB_CHECK_CONSTRAINTS(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } } + + +// version definitions +#define RADIOLIB_VERSION_MAJOR (0x03) +#define RADIOLIB_VERSION_MINOR (0x04) +#define RADIOLIB_VERSION_PATCH (0x00) +#define RADIOLIB_VERSION_EXTRA (0x00) + +#define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA)) + +#endif diff --git a/src/TypeDef.h b/src/TypeDef.h index 4f4c2171..00ef2096 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -1,193 +1,7 @@ #ifndef _RADIOLIB_TYPES_H #define _RADIOLIB_TYPES_H -#if ARDUINO >= 100 - #include "Arduino.h" -#else - #error "Unsupported Arduino version (< 1.0.0)" -#endif - -/* - * Platform-specific configuration. - * - * RADIOLIB_PIN_TYPE - which type should be used for pin numbers in functions like digitalRead(). - * RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode(). - * RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite(). - * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. - * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platform does not support SoftwareSerial. - * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platform that do not have SoftwareSerial support. - * - * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). - */ -#if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) - // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_NC (0xFF) - -#elif defined(ESP8266) - // ESP8266 boards - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_NC (0xFF) - - // RadioLib has ESPS8266 driver, this must be disabled to use ESP8266 as platform - #define _RADIOLIB_ESP8266_H - -#elif defined(ESP32) - // ESP32 boards - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_NC (0xFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - -#elif defined(ARDUINO_ARCH_STM32) - // STM32duino boards - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_NC (0xFFFFFFFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - -#elif defined(SAMD_SERIES) - // Arduino SAMD boards - Zero, MKR, etc. - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_NC (0xFFFFFFFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - -#elif defined(__SAM3X8E__) - // Arduino Due - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_NC (0xFFFFFFFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - -#elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) - // Adafruit nRF52 boards - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_NC (0xFFFFFFFF) - -#elif defined(ARDUINO_ARC32_TOOLS) - // Intel Curie - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_NC (0xFF) - -#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) - // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE PinMode - #define RADIOLIB_PIN_STATUS PinStatus - #define RADIOLIB_NC (0xFF) - -#elif defined(AM_PART_APOLLO3) - // Sparkfun Artemis boards - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_NC (0xFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - -#elif defined(ARDUINO_ARDUINO_NANO33BLE) - // Arduino Nano 33 BLE - #define RADIOLIB_PIN_TYPE pin_size_t - #define RADIOLIB_PIN_MODE PinMode - #define RADIOLIB_PIN_STATUS PinStatus - #define RADIOLIB_NC (0xFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - - // Nano 33 BLE uses mbed libraries, which already contain ESP8266 driver - #define _RADIOLIB_ESP8266_H - -#else - // other platforms not covered by the above list - this may or may not work - #warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_NC (0xFF) - -#endif - -// version definitions -#define RADIOLIB_VERSION_MAJOR (0x03) -#define RADIOLIB_VERSION_MINOR (0x04) -#define RADIOLIB_VERSION_PATCH (0x00) -#define RADIOLIB_VERSION_EXTRA (0x00) - -#define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA)) - -/* - * Uncomment to enable static-only memory management: no dynamic allocation will be performed. - * Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode. - */ - -//#define RADIOLIB_STATIC_ONLY - -// set the size of static arrays to use -#define RADIOLIB_STATIC_ARRAY_SIZE 256 - -/* - * Uncomment to enable debug output. - * Warning: Debug output will slow down the whole system significantly. - * Also, it will result in larger compiled binary. - * Levels: debug - only main info - * verbose - full transcript of all SPI/UART communication - */ - -//#define RADIOLIB_DEBUG -//#define RADIOLIB_VERBOSE - -// set which Serial port should be used for debug output -#define RADIOLIB_DEBUG_PORT Serial - -#ifdef RADIOLIB_DEBUG - #define RADIOLIB_DEBUG_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); } - #define RADIOLIB_DEBUG_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } -#else - #define RADIOLIB_DEBUG_PRINT(...) {} - #define RADIOLIB_DEBUG_PRINTLN(...) {} -#endif - -#ifdef RADIOLIB_VERBOSE - #define RADIOLIB_VERBOSE_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); } - #define RADIOLIB_VERBOSE_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } -#else - #define RADIOLIB_VERBOSE_PRINT(...) {} - #define RADIOLIB_VERBOSE_PRINTLN(...) {} -#endif - -/* - * Uncomment to enable god mode - all methods and member variables in all classes will be made public, thus making them accessible from Arduino code. - * Warning: Come on, it's called GOD mode - obviously only use this if you know what you're doing. - * Failure to heed the above warning may result in bricked module. - */ -//#define RADIOLIB_GODMODE - -/* - * Uncomment to enable pre-defined modules when using RadioShield. - */ -//#define RADIOLIB_RADIOSHIELD - -/*! - \brief A simple assert macro, will return on error. -*/ -#define RADIOLIB_ASSERT(STATEVAR) { if(STATEVAR != ERR_NONE) { return(STATEVAR); } } +#include "BuildOpt.h" /*! \defgroup shield_config Shield Configuration From 29103517408e73c71d297bf0b429f21214af36a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Sun, 29 Mar 2020 10:05:03 +0200 Subject: [PATCH 029/334] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 779c3533..49d358d7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -11,7 +11,7 @@ assignees: '' Before submitting new issue, please check the [Wiki](https://github.com/jgromes/RadioLib/wiki) and the [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there. **Describe the bug** -A clear and concise description of what the bug is. When applicable, please include debug mode output: uncomment [debug macro definitions in TypeDef.h](https://github.com/jgromes/RadioLib/blob/master/src/TypeDef.h#L36) and post the output. +A clear and concise description of what the bug is. When applicable, please include debug mode output: uncomment [debug macro definitions in BuildOpt.h](https://github.com/jgromes/RadioLib/blob/master/src/BuildOpt.h#L135) and post the output. **To Reproduce** Minimal Arduino sketch to reproduce the behavior. Please user Markdown to style the code to make it readable (see [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code)). @@ -24,6 +24,6 @@ If applicable, add screenshots to help explain your problem. **Additional info (please complete):** - MCU: [e.g. Arduino Uno, ESP8266 etc.] - - Wireless module type [e.g. SX1276, ESP8266, etc.] + - Wireless module type [e.g. CC1101, SX1268, etc.] - Arduino IDE version [e.g. 1.8.5] - - Library version [e.g. 1.0.1] + - Library version [e.g. 3.0.0] From 83b713b7769d179fe8ef29787a1f1cd8469e7d23 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 17:38:04 +0200 Subject: [PATCH 030/334] [Si443x] Added support for Si443x/RFM2x --- README.md | 10 +- .../Si443x/Si443x_Receive/Si443x_Receive.ino | 87 ++ .../Si443x_Receive_Interrupt.ino | 139 ++++ .../Si443x_Settings/Si443x_Settings.ino | 126 +++ .../Si443x_Transmit/Si443x_Transmit.ino | 87 ++ .../Si443x_Transmit_Interrupt.ino | 133 +++ keywords.txt | 6 + src/RadioLib.h | 6 + src/modules/RFM2x/RFM22.h | 16 + src/modules/RFM2x/RFM23.h | 16 + src/modules/Si443x/Si4430.cpp | 34 + src/modules/Si443x/Si4430.h | 74 ++ src/modules/Si443x/Si4431.cpp | 27 + src/modules/Si443x/Si4431.h | 65 ++ src/modules/Si443x/Si4432.cpp | 34 + src/modules/Si443x/Si4432.h | 74 ++ src/modules/Si443x/Si443x.cpp | 668 +++++++++++++++ src/modules/Si443x/Si443x.h | 786 ++++++++++++++++++ 18 files changed, 2384 insertions(+), 4 deletions(-) create mode 100644 examples/Si443x/Si443x_Receive/Si443x_Receive.ino create mode 100644 examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino create mode 100644 examples/Si443x/Si443x_Settings/Si443x_Settings.ino create mode 100644 examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino create mode 100644 examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino create mode 100644 src/modules/RFM2x/RFM22.h create mode 100644 src/modules/RFM2x/RFM23.h create mode 100644 src/modules/Si443x/Si4430.cpp create mode 100644 src/modules/Si443x/Si4430.h create mode 100644 src/modules/Si443x/Si4431.cpp create mode 100644 src/modules/Si443x/Si4431.h create mode 100644 src/modules/Si443x/Si4432.cpp create mode 100644 src/modules/Si443x/Si4432.h create mode 100644 src/modules/Si443x/Si443x.cpp create mode 100644 src/modules/Si443x/Si443x.h diff --git a/README.md b/README.md index 61bf5c97..0a789d21 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * __JDY08__ BLE module * __nRF24L01__ 2.4 GHz module * __RF69__ FSK/OOK radio module +* __RFM2x__ series FSK modules (RFM22, RM23) * __RFM9x__ series LoRa modules (RFM95, RM96, RFM97, RFM98) +* __Si443x__ series FSK modules (Si4430, Si4431, Si4432) * __SX127x__ series LoRa modules (SX1272, SX1273, SX1276, SX1277, SX1278, SX1279) * __SX126x__ series LoRa modules (SX1261, SX1262, SX1268) * __SX1231__ FSK/OOK radio module @@ -27,9 +29,9 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github ### Supported protocols: * __MQTT__ for modules: ESP8266 * __HTTP__ for modules: ESP8266 -* __RTTY__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101 and nRF24L01 -* __Morse Code__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101 and nRF24L01 -* __AX.25__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231 and CC1101 +* __RTTY__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x +* __Morse Code__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x +* __AX.25__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x ### Supported platforms: * __Arduino AVR__ - tested with hardware on Uno, Mega and Leonardo @@ -44,7 +46,7 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * _Apollo3_ - SparkFun Artemis Redboard etc. * _Arduino nRF52_ - Arduino Nano 33 BLE -The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platoforms in __bold__ on each git push. Platforms in _italic_ are not tested on each push, but do compile and should be working. +The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platforms in __bold__ on each git push. Platforms in _italic_ are not tested on each push, but do compile and should be working. ### In development: * __SIM800C__ GSM module diff --git a/examples/Si443x/Si443x_Receive/Si443x_Receive.ino b/examples/Si443x/Si443x_Receive/Si443x_Receive.ino new file mode 100644 index 00000000..345fb8a6 --- /dev/null +++ b/examples/Si443x/Si443x_Receive/Si443x_Receive.ino @@ -0,0 +1,87 @@ +/* + RadioLib Si443x Receive Example + + This example receives packets using Si443x FSK radio module. + To successfully receive data, the following settings have to be the same + on both transmitter and receiver: + - carrier frequency + - bit rate + - frequency deviation + - sync word + + Other modules from Si443x/RFM2x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// Si4432 has the following connections: +// nSEL pin: 10 +// nIRQ pin: 2 +// SDN pin: 9 +Si4432 fsk = new Module(10, 2, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//Si4432 fsk = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize Si4432 with default settings + Serial.print(F("[Si4432] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 225.1 kHz + // output power: 11 dBm + // sync word: 0x2D 0x01 + int state = fsk.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } +} + +void loop() { + Serial.print(F("[Si4432] Waiting for incoming transmission ... ")); + + // you can receive data as an Arduino String + String str; + int state = fsk.receive(str); + + // you can also receive data as byte array + /* + byte byteArr[8]; + int state = rf.receive(byteArr, 8); + */ + + if (state == ERR_NONE) { + // packet was successfully received + Serial.println(F("success!")); + + // print the data of the packet + Serial.print(F("[Si4432] Data:\t\t")); + Serial.println(str); + + } else if (state == ERR_RX_TIMEOUT) { + // timeout occurred while waiting for a packet + Serial.println(F("timeout!")); + + } else if (state == ERR_CRC_MISMATCH) { + // packet was received, but is malformed + Serial.println(F("CRC error!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } +} diff --git a/examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino b/examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino new file mode 100644 index 00000000..a514980e --- /dev/null +++ b/examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino @@ -0,0 +1,139 @@ +/* + RadioLib Si443x Receive with Interrupts Example + + This example listens for FSK transmissions and tries to + receive them. Once a packet is received, an interrupt is + triggered. + + Other modules from Si443x/RFM2x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// Si4432 has the following connections: +// nSEL pin: 10 +// nIRQ pin: 2 +// SDN pin: 9 +Si4432 fsk = new Module(10, 2, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//Si4432 fsk = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize Si4432 with default settings + Serial.print(F("[Si4432] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 225.1 kHz + // output power: 11 dBm + // sync word: 0x2D 0x01 + int state = fsk.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // set the function that will be called + // when new packet is received + fsk.setIrqAction(setFlag); + + // start listening for packets + Serial.print(F("[Si4432] Starting to listen ... ")); + state = fsk.startReceive(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // if needed, 'listen' mode can be disabled by calling + // any of the following methods: + // + // fsk.standby() + // fsk.sleep() + // fsk.transmit(); + // fsk.receive(); + // fsk.readData(); +} + +// flag to indicate that a packet was received +volatile bool receivedFlag = false; + +// disable interrupt when it's not needed +volatile bool enableInterrupt = true; + +// this function is called when a complete packet +// is received by the module +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +void setFlag(void) { + // check if the interrupt is enabled + if(!enableInterrupt) { + return; + } + + // we got a packet, set the flag + receivedFlag = true; +} + +void loop() { + // check if the flag is set + if(receivedFlag) { + // disable the interrupt service routine while + // processing the data + enableInterrupt = false; + + // reset flag + receivedFlag = false; + + // you can read received data as an Arduino String + String str; + int state = fsk.readData(str); + + // you can also read received data as byte array + /* + byte byteArr[8]; + int state = fsk.readData(byteArr, 8); + */ + + if (state == ERR_NONE) { + // packet was successfully received + Serial.println(F("[Si4432] Received packet!")); + + // print data of the packet + Serial.print(F("[Si4432] Data:\t\t\t")); + Serial.println(str); + + } else if (state == ERR_CRC_MISMATCH) { + // packet was received, but is malformed + Serial.println(F("CRC error!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } + + // put module back to listen mode + fsk.startReceive(); + + // we're ready to receive more packets, + // enable interrupt service routine + enableInterrupt = true; + } + +} diff --git a/examples/Si443x/Si443x_Settings/Si443x_Settings.ino b/examples/Si443x/Si443x_Settings/Si443x_Settings.ino new file mode 100644 index 00000000..b3d1ab82 --- /dev/null +++ b/examples/Si443x/Si443x_Settings/Si443x_Settings.ino @@ -0,0 +1,126 @@ +/* + RadioLib Si443x Settings Example + + This example shows how to change all the properties of RF69 radio. + RadioLib currently supports the following settings: + - pins (SPI slave select, nIRQ, shutdown) + - carrier frequency + - bit rate + - receiver bandwidth + - frequency deviation + - output power during transmission + - sync word + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// Si4432 has the following connections: +// nSEL pin: 10 +// nIRQ pin: 2 +// SDN pin: 9 +Si4432 fsk1 = new Module(10, 2, 9); + +// Si4432 has the following connections: +// nSEL pin: 8 +// nIRQ pin: 3 +// SDN pin: 7 +Si4432 fsk2 = new Module(8, 3, 7); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//Si4432 fsk3 = RadioShield.ModuleB; + +void setup() { + Serial.begin(9600); + + // initialize Si4432 with default settings + Serial.print(F("[Si4432] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 225.1 kHz + // output power: 11 dBm + // sync word: 0x2D 0x01 + int state = fsk1.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // initialize Si4432 with non-default settings + Serial.print(F("[Si4432] Initializing ... ")); + // carrier frequency: 868.0 MHz + // bit rate: 200.0 kbps + // frequency deviation: 60.0 kHz + // Rx bandwidth: 335.5 kHz + // output power: 17 dBm + // sync word: 0x2D 0x01 + state = fsk2.begin(868.0, 200.0, 60.0, 335.5, 17); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // you can also change the settings at runtime + // and check if the configuration was changed successfully + + // set carrier frequency to 433.5 MHz + if (fsk1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { + Serial.println(F("[Si4432] Selected frequency is invalid for this module!")); + while (true); + } + + // set bit rate to 100.0 kbps + state = fsk1.setBitRate(100.0); + if (state == ERR_INVALID_BIT_RATE) { + Serial.println(F("[Si4432] Selected bit rate is invalid for this module!")); + while (true); + } else if (state == ERR_INVALID_BIT_RATE_BW_RATIO) { + Serial.println(F("[Si4432] Selected bit rate to bandwidth ratio is invalid!")); + Serial.println(F("[Si4432] Increase receiver bandwidth to set this bit rate.")); + while (true); + } + + // set receiver bandwidth to 284.8 kHz + state = fsk1.setRxBandwidth(284.8); + if (state == ERR_INVALID_RX_BANDWIDTH) { + Serial.println(F("[Si4432] Selected receiver bandwidth is invalid for this module!")); + while (true); + } + + // set frequency deviation to 10.0 kHz + if (fsk1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) { + Serial.println(F("[Si4432] Selected frequency deviation is invalid for this module!")); + while (true); + } + + // set output power to 2 dBm + if (fsk1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) { + Serial.println(F("[Si4432] Selected output power is invalid for this module!")); + while (true); + } + + // up to 4 bytes can be set as sync word + // set sync word to 0x01234567 + uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67}; + if (fsk1.setSyncWord(syncWord, 4) == ERR_INVALID_SYNC_WORD) { + Serial.println(F("[Si4432] Selected sync word is invalid for this module!")); + while (true); + } + + Serial.println(F("[Si4432] All settings changed successfully!")); +} + +void loop() { + // nothing here +} diff --git a/examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino b/examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino new file mode 100644 index 00000000..34a278da --- /dev/null +++ b/examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino @@ -0,0 +1,87 @@ +/* + RadioLib Si443x Transmit Example + + This example transmits packets using Si4432 FSK radio module. + Each packet contains up to 64 bytes of data, in the form of: + - Arduino String + - null-terminated char array (C-string) + - arbitrary binary data (byte array) + + Other modules from Si443x/RFM2x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// Si4432 has the following connections: +// nSEL pin: 10 +// nIRQ pin: 2 +// SDN pin: 9 +Si4432 fsk = new Module(10, 2, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//Si4432 fsk = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize Si4432 with default settings + Serial.print(F("[Si4432] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 225.1 kHz + // output power: 11 dBm + // sync word: 0x2D 0x01 + int state = fsk.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } +} + +void loop() { + Serial.print(F("[Si4432] Transmitting packet ... ")); + + // you can transmit C-string or Arduino string up to + // 64 characters long + // NOTE: transmit() is a blocking method! + // See example Si443x_Transmit_Interrupt for details + // on non-blocking transmission method. + int state = fsk.transmit("Hello World!"); + + // you can also transmit byte array up to 64 bytes long + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; + int state = fsk.transmit(byteArr, 8); + */ + + if (state == ERR_NONE) { + // the packet was successfully transmitted + Serial.println(F(" success!")); + + } else if (state == ERR_PACKET_TOO_LONG) { + // the supplied packet was longer than 256 bytes + Serial.println(F(" too long!")); + + } else if (state == ERR_TX_TIMEOUT) { + // timeout occured while transmitting packet + Serial.println(F(" timeout!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } + + // wait for a second before transmitting again + delay(1000); +} diff --git a/examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino b/examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino new file mode 100644 index 00000000..e4c56c18 --- /dev/null +++ b/examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino @@ -0,0 +1,133 @@ +/* + RadioLib Si443x Transmit with Interrupts Example + + This example transmits packets using Si4432 FSK radio module. + Each packet contains up to 64 bytes of data, in the form of: + - Arduino String + - null-terminated char array (C-string) + - arbitrary binary data (byte array) + + Other modules from Si443x/RFM2x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// Si4432 has the following connections: +// nSEL pin: 10 +// nIRQ pin: 2 +// SDN pin: 9 +Si4432 fsk = new Module(10, 2, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//Si4432 fsk = RadioShield.ModuleA; + +// save transmission state between loops +int transmissionState = ERR_NONE; + +void setup() { + Serial.begin(9600); + + // initialize Si4432 with default settings + Serial.print(F("[Si4432] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 225.1 kHz + // output power: 11 dBm + // sync word: 0x2D 0x01 + int state = fsk.begin(); + fsk.setOutputPower(13); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // set the function that will be called + // when packet transmission is finished + fsk.setIrqAction(setFlag); + + // start transmitting the first packet + Serial.print(F("[Si4432] Sending first packet ... ")); + + // you can transmit C-string or Arduino string up to + // 64 characters long + transmissionState = fsk.startTransmit("Hello World!"); + + // you can also transmit byte array up to 64 bytes long + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + state = fsk.startTransmit(byteArr, 8); + */ +} + +// flag to indicate that a packet was sent +volatile bool transmittedFlag = false; + +// disable interrupt when it's not needed +volatile bool enableInterrupt = true; + +// this function is called when a complete packet +// is transmitted by the module +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +void setFlag(void) { + // check if the interrupt is enabled + if(!enableInterrupt) { + return; + } + + // we sent a packet, set the flag + transmittedFlag = true; +} + +void loop() { + // check if the previous transmission finished + if(transmittedFlag) { + // disable the interrupt service routine while + // processing the data + enableInterrupt = false; + + // reset flag + transmittedFlag = false; + + if (transmissionState == ERR_NONE) { + // packet was successfully sent + Serial.println(F("transmission finished!")); + + } else { + Serial.print(F("failed, code ")); + Serial.println(transmissionState); + + } + + // wait a second before transmitting again + delay(1000); + + // send another one + Serial.print(F("[Si4432] Sending another packet ... ")); + + // you can transmit C-string or Arduino string up to + // 256 characters long + transmissionState = fsk.startTransmit("Hello World!"); + + // you can also transmit byte array up to 64 bytes long + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + int state = fsk.startTransmit(byteArr, 8); + */ + + // we're ready to send more packets, + // enable interrupt service routine + enableInterrupt = true; + } +} diff --git a/keywords.txt b/keywords.txt index a5ba3b5a..bcf0f9fd 100644 --- a/keywords.txt +++ b/keywords.txt @@ -16,10 +16,15 @@ HC05 KEYWORD1 JDY08 KEYWORD1 nRF24 KEYWORD1 RF69 KEYWORD1 +RFM22 KEYWORD1 +RFM23 KEYWORD1 RFM95 KEYWORD1 RFM96 KEYWORD1 RFM97 KEYWORD1 RFM98 KEYWORD1 +Si4430 KEYWORD1 +Si4431 KEYWORD1 +Si4432 KEYWORD1 SIM800 KEYWORD1 SX1231 KEYWORD1 SX1261 KEYWORD1 @@ -140,6 +145,7 @@ getPacketSource KEYWORD2 getPacketData KEYWORD2 # nRF24 +setIrqAction KEYWORD2 setAddressWidth KEYWORD2 setTransmitPipe KEYWORD2 setReceivePipe KEYWORD2 diff --git a/src/RadioLib.h b/src/RadioLib.h index d434a8d5..16947fbd 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -11,6 +11,7 @@ - HC05 Bluetooth module - JDY08 BLE module - RF69 FSK module + - Si443x FSK module - SX126x LoRa/FSK module - SX127x LoRa/FSK module - SX1231 FSK module @@ -49,9 +50,14 @@ #include "modules/JDY08/JDY08.h" #include "modules/nRF24/nRF24.h" #include "modules/RF69/RF69.h" +#include "modules/RFM2x/RFM22.h" +#include "modules/RFM2x/RFM23.h" #include "modules/RFM9x/RFM95.h" #include "modules/RFM9x/RFM96.h" #include "modules/RFM9x/RFM97.h" +#include "modules/Si443x/Si4430.h" +#include "modules/Si443x/Si4431.h" +#include "modules/Si443x/Si4432.h" #include "modules/SX1231/SX1231.h" #include "modules/SX126x/SX1261.h" #include "modules/SX126x/SX1262.h" diff --git a/src/modules/RFM2x/RFM22.h b/src/modules/RFM2x/RFM22.h new file mode 100644 index 00000000..e3cd4a4d --- /dev/null +++ b/src/modules/RFM2x/RFM22.h @@ -0,0 +1,16 @@ +#ifndef _RADIOLIB_RFM22_H +#define _RADIOLIB_RFM22_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "../Si443x/Si443x.h" +#include "../Si443x/Si4432.h" + +/*! + \class RFM22 + + \brief Only exists as alias for Si4432, since there seems to be no difference between %RFM22 and %Si4432 modules. +*/ +using RFM22 = Si4432; + +#endif diff --git a/src/modules/RFM2x/RFM23.h b/src/modules/RFM2x/RFM23.h new file mode 100644 index 00000000..4f72557d --- /dev/null +++ b/src/modules/RFM2x/RFM23.h @@ -0,0 +1,16 @@ +#ifndef _RADIOLIB_RFM23_H +#define _RADIOLIB_RFM23_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "../Si443x/Si443x.h" +#include "../Si443x/Si4431.h" + +/*! + \class RFM23 + + \brief Only exists as alias for Si4431, since there seems to be no difference between %RFM23 and %Si4431 modules. +*/ +using RFM23 = Si4431; + +#endif diff --git a/src/modules/Si443x/Si4430.cpp b/src/modules/Si443x/Si4430.cpp new file mode 100644 index 00000000..c59f1ea7 --- /dev/null +++ b/src/modules/Si443x/Si4430.cpp @@ -0,0 +1,34 @@ +#include "Si4430.h" + +Si4430::Si4430(Module* mod) : Si4432(mod) { + +} + +int16_t Si4430::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { + // execute common part + int16_t state = Si443x::begin(br, freqDev, rxBw); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setFrequency(freq); + RADIOLIB_ASSERT(state); + + state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + return(state); +} + +int16_t Si4430::setFrequency(float freq) { + RADIOLIB_CHECK_RANGE(freq, 900.0, 960.0, ERR_INVALID_FREQUENCY); + + // set frequency + return(Si443x::setFrequencyRaw(freq)); +} + +int16_t Si4430::setOutputPower(int8_t power) { + RADIOLIB_CHECK_RANGE(power, -8, 13, ERR_INVALID_OUTPUT_POWER); + + // set output power + return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0)); +} diff --git a/src/modules/Si443x/Si4430.h b/src/modules/Si443x/Si4430.h new file mode 100644 index 00000000..7e7f8b36 --- /dev/null +++ b/src/modules/Si443x/Si4430.h @@ -0,0 +1,74 @@ +#ifndef _RADIOLIB_SI4430_H +#define _RADIOLIB_SI4430_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "Si4432.h" + +/*! + \class Si4430 + + \brief Derived class for %Si4430 modules. +*/ +class Si4430: public Si4432 { + public: + + // constructor + + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio chip. + */ + Si4430(Module* mod); + + // basic methods + + /*! + \brief Initialization method. Must be called at least once from Arduino sketch to initialize the module. + + \param freq Carrier frequency in MHz. Allowed values range from 900.0 MHz to 960.0 MHz. + + \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps. + + \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps. + + \param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz. + + \param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps. + + \returns \ref status_codes + */ + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10); + + // configuration methods + + /*! + \brief Sets carrier frequency. Allowed values range from 900.0 MHz to 960.0 MHz. + + \param freq Carrier frequency to be set in MHz. + + \returns \ref status_codes + */ + int16_t setFrequency(float freq); + + /*! + \brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps. + + \param power Output power to be set in dBm. + + \returns \ref status_codes + */ + int16_t setOutputPower(int8_t power); + + +#ifndef RADIOLIB_GODMODE + protected: +#endif + +#ifndef RADIOLIB_GODMODE + private: +#endif +}; + +#endif diff --git a/src/modules/Si443x/Si4431.cpp b/src/modules/Si443x/Si4431.cpp new file mode 100644 index 00000000..25c7baf9 --- /dev/null +++ b/src/modules/Si443x/Si4431.cpp @@ -0,0 +1,27 @@ +#include "Si4431.h" + +Si4431::Si4431(Module* mod) : Si4432(mod) { + +} + +int16_t Si4431::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { + // execute common part + int16_t state = Si443x::begin(br, freqDev, rxBw); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setFrequency(freq); + RADIOLIB_ASSERT(state); + + state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + return(state); +} + +int16_t Si4431::setOutputPower(int8_t power) { + RADIOLIB_CHECK_RANGE(power, -8, 13, ERR_INVALID_OUTPUT_POWER); + + // set output power + return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0)); +} diff --git a/src/modules/Si443x/Si4431.h b/src/modules/Si443x/Si4431.h new file mode 100644 index 00000000..c033bcbd --- /dev/null +++ b/src/modules/Si443x/Si4431.h @@ -0,0 +1,65 @@ +#ifndef _RADIOLIB_SI4431_H +#define _RADIOLIB_SI4431_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "Si4432.h" + +/*! + \class Si4431 + + \brief Derived class for %Si4431 modules. +*/ +class Si4431: public Si4432 { + public: + + // constructor + + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio chip. + */ + Si4431(Module* mod); + + // basic methods + + /*! + \brief Initialization method. Must be called at least once from Arduino sketch to initialize the module. + + \param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz. + + \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps. + + \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps. + + \param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz. + + \param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps. + + \returns \ref status_codes + */ + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10); + + // configuration methods + + /*! + \brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps. + + \param power Output power to be set in dBm. + + \returns \ref status_codes + */ + int16_t setOutputPower(int8_t power); + + +#ifndef RADIOLIB_GODMODE + protected: +#endif + +#ifndef RADIOLIB_GODMODE + private: +#endif +}; + +#endif diff --git a/src/modules/Si443x/Si4432.cpp b/src/modules/Si443x/Si4432.cpp new file mode 100644 index 00000000..38d42863 --- /dev/null +++ b/src/modules/Si443x/Si4432.cpp @@ -0,0 +1,34 @@ +#include "Si4432.h" + +Si4432::Si4432(Module* mod) : Si443x(mod) { + +} + +int16_t Si4432::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { + // execute common part + int16_t state = Si443x::begin(br, freqDev, rxBw); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setFrequency(freq); + RADIOLIB_ASSERT(state); + + state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + return(state); +} + +int16_t Si4432::setFrequency(float freq) { + RADIOLIB_CHECK_RANGE(freq, 240.0, 930.0, ERR_INVALID_FREQUENCY); + + // set frequency + return(Si443x::setFrequencyRaw(freq)); +} + +int16_t Si4432::setOutputPower(int8_t power) { + RADIOLIB_CHECK_RANGE(power, -1, 20, ERR_INVALID_OUTPUT_POWER); + + // set output power + return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 1) / 3), 2, 0)); +} diff --git a/src/modules/Si443x/Si4432.h b/src/modules/Si443x/Si4432.h new file mode 100644 index 00000000..01dd92c5 --- /dev/null +++ b/src/modules/Si443x/Si4432.h @@ -0,0 +1,74 @@ +#ifndef _RADIOLIB_SI4432_H +#define _RADIOLIB_SI4432_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "Si443x.h" + +/*! + \class Si4432 + + \brief Derived class for %Si4432 modules. +*/ +class Si4432: public Si443x { + public: + + // constructor + + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio chip. + */ + Si4432(Module* mod); + + // basic methods + + /*! + \brief Initialization method. Must be called at least once from Arduino sketch to initialize the module. + + \param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz. + + \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps. + + \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps. + + \param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz. + + \param power Transmission output power in dBm. Allowed values range from -1 to 20 dBm in 3 dBm steps. + + \returns \ref status_codes + */ + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 11); + + // configuration methods + + /*! + \brief Sets carrier frequency. Allowed values range from 240.0 MHz to 930.0 MHz. + + \param freq Carrier frequency to be set in MHz. + + \returns \ref status_codes + */ + int16_t setFrequency(float freq); + + /*! + \brief Sets output power. Allowed values range from -1 to 20 dBm in 3 dBm steps. + + \param power Output power to be set in dBm. + + \returns \ref status_codes + */ + int16_t setOutputPower(int8_t power); + + +#ifndef RADIOLIB_GODMODE + protected: +#endif + +#ifndef RADIOLIB_GODMODE + private: +#endif +}; + +#endif diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp new file mode 100644 index 00000000..6cfc6ffd --- /dev/null +++ b/src/modules/Si443x/Si443x.cpp @@ -0,0 +1,668 @@ +#include "Si443x.h" + +Si443x::Si443x(Module* mod) : PhysicalLayer(SI443X_FREQUENCY_STEP_SIZE, SI443X_MAX_PACKET_LENGTH) { + _mod = mod; + + _packetLengthQueried = false; +} + +int16_t Si443x::begin(float br, float freqDev, float rxBw) { + // set module properties + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); + Module::pinMode(_mod->getRst(), OUTPUT); + Module::digitalWrite(_mod->getRst(), LOW); + + // try to find the Si443x chip + if(!Si443x::findChip()) { + RADIOLIB_DEBUG_PRINTLN(F("No Si443x found!")); + _mod->term(); + return(ERR_CHIP_NOT_FOUND); + } else { + RADIOLIB_DEBUG_PRINTLN(F("Found Si443x!")); + } + + // clear POR interrupt + clearIRQFlags(); + + // configure settings not accessible by API + int16_t state = config(); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setBitRate(br); + RADIOLIB_ASSERT(state); + + state = setFrequencyDeviation(freqDev); + RADIOLIB_ASSERT(state); + + state = setRxBandwidth(rxBw); + RADIOLIB_ASSERT(state); + + uint8_t syncWord[] = {0x2D, 0x01}; + state = setSyncWord(syncWord, sizeof(syncWord)); + RADIOLIB_ASSERT(state); + + state = packetMode(); + RADIOLIB_ASSERT(state); + + state = setDataShaping(0); + RADIOLIB_ASSERT(state); + + state = setEncoding(0); + RADIOLIB_ASSERT(state); + + return(state); +} + +void Si443x::reset() { + Module::pinMode(_mod->getRst(), OUTPUT); + Module::digitalWrite(_mod->getRst(), HIGH); + delay(1); + Module::digitalWrite(_mod->getRst(), LOW); + delay(100); +} + +int16_t Si443x::transmit(uint8_t* data, size_t len, uint8_t addr) { + // calculate timeout (5ms + 500 % of expected time-on-air) + uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0); + + // start transmission + int16_t state = startTransmit(data, len, addr); + RADIOLIB_ASSERT(state); + + // wait for transmission end or timeout + uint32_t start = micros(); + while(digitalRead(_mod->getIrq())) { + if(micros() - start > timeout) { + standby(); + clearIRQFlags(); + return(ERR_TX_TIMEOUT); + } + } + + // set mode to standby + state = standby(); + + // clear interrupt flags + clearIRQFlags(); + + return(state); +} + +int16_t Si443x::receive(uint8_t* data, size_t len) { + // calculate timeout (500 ms + 400 full 64-byte packets at current bit rate) + uint32_t timeout = 500000 + (1.0/(_br*1000.0))*(SI443X_MAX_PACKET_LENGTH*400.0); + + // start reception + int16_t state = startReceive(); + RADIOLIB_ASSERT(state); + + // wait for packet reception or timeout + uint32_t start = micros(); + while(digitalRead(_mod->getIrq())) { + if(micros() - start > timeout) { + standby(); + clearIRQFlags(); + return(ERR_RX_TIMEOUT); + } + } + + // read packet data + return(readData(data, len)); +} + +int16_t Si443x::sleep() { + // disable wakeup timer interrupt + int16_t state = _mod->SPIsetRegValue(SI443X_REG_INTERRUPT_ENABLE_1, 0x00); + RADIOLIB_ASSERT(state); + state = _mod->SPIsetRegValue(SI443X_REG_INTERRUPT_ENABLE_2, 0x00); + RADIOLIB_ASSERT(state); + + // enable wakeup timer to set mode to sleep + _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_ENABLE_WAKEUP_TIMER); + + return(state); +} + +int16_t Si443x::standby() { + return(_mod->SPIsetRegValue(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_XTAL_ON, 7, 0, 10)); +} + +int16_t Si443x::transmitDirect(uint32_t frf) { + // user requested to start transmitting immediately (required for RTTY) + if(frf != 0) { + // convert the 24-bit frequency to the format accepted by the module + // TODO integers only + float newFreq = frf / 6400.0; + + // check high/low band + uint8_t bandSelect = SI443X_BAND_SELECT_LOW; + uint8_t freqBand = (newFreq / 10) - 24; + if(newFreq >= 480.0) { + bandSelect = SI443X_BAND_SELECT_HIGH; + freqBand = (newFreq / 20) - 24; + } + + // calculate register values + uint16_t freqCarrier = ((newFreq / (10 * ((bandSelect >> 5) + 1))) - freqBand - 24) * (uint32_t)64000; + + // update registers + _mod->SPIwriteRegister(SI443X_REG_FREQUENCY_BAND_SELECT, SI443X_SIDE_BAND_SELECT_LOW | bandSelect | freqBand); + _mod->SPIwriteRegister(SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8)); + _mod->SPIwriteRegister(SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF)); + + // start direct transmission + directMode(); + _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_TX_ON); + + return(ERR_NONE); + } + + // activate direct mode + int16_t state = directMode(); + RADIOLIB_ASSERT(state); + + // start transmitting + _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_TX_ON); + return(state); +} + +int16_t Si443x::receiveDirect() { + // activate direct mode + int16_t state = directMode(); + RADIOLIB_ASSERT(state); + + // start receiving + _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_RX_ON); + return(state); +} + +int16_t Si443x::packetMode() { + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_TX_DATA_SOURCE_FIFO, 5, 4)); +} + +void Si443x::setIrqAction(void (*func)(void)) { + attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, FALLING); +} + +void Si443x::clearIrqAction() { + detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); +} + +int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { + // check packet length + if(len > SI443X_MAX_PACKET_LENGTH) { + return(ERR_PACKET_TOO_LONG); + } + + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // clear Tx FIFO + _mod->SPIsetRegValue(SI443X_REG_OP_FUNC_CONTROL_2, SI443X_TX_FIFO_RESET, 0, 0); + _mod->SPIsetRegValue(SI443X_REG_OP_FUNC_CONTROL_2, SI443X_TX_FIFO_CLEAR, 0, 0); + + // set interrupt mapping + state = _mod->SPIsetRegValue(SI443X_REG_INTERRUPT_ENABLE_1, SI443X_PACKET_SENT_ENABLED); + RADIOLIB_ASSERT(state); + + // clear interrupt flags + clearIRQFlags(); + + // set packet length + // TODO variable packet length + _mod->SPIwriteRegister(SI443X_REG_TRANSMIT_PACKET_LENGTH, len); + + // TODO use header as address field? + (void)addr; + + // write packet to FIFO + _mod->SPIwriteRegisterBurst(SI443X_REG_FIFO_ACCESS, data, len); + + // set mode to transmit + _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_TX_ON); + + return(state); +} + +int16_t Si443x::startReceive() { + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // clear Rx FIFO + _mod->SPIsetRegValue(SI443X_REG_OP_FUNC_CONTROL_2, SI443X_RX_FIFO_RESET, 1, 1); + _mod->SPIsetRegValue(SI443X_REG_OP_FUNC_CONTROL_2, SI443X_RX_FIFO_CLEAR, 1, 1); + + // set interrupt mapping + state = _mod->SPIsetRegValue(SI443X_REG_INTERRUPT_ENABLE_1, SI443X_VALID_PACKET_RECEIVED_ENABLED, SI443X_CRC_ERROR_ENABLED); + RADIOLIB_ASSERT(state); + state = _mod->SPIsetRegValue(SI443X_REG_INTERRUPT_ENABLE_2, 0x00); + RADIOLIB_ASSERT(state); + + // clear interrupt flags + clearIRQFlags(); + + // set mode to receive + _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_RX_ON); + + return(state); +} + +int16_t Si443x::readData(uint8_t* data, size_t len) { + // clear interrupt flags + clearIRQFlags(); + + // get packet length + size_t length = len; + if(len == SI443X_MAX_PACKET_LENGTH) { + length = getPacketLength(); + } + + // read packet data + _mod->SPIreadRegisterBurst(SI443X_REG_FIFO_ACCESS, length, data); + + // clear internal flag so getPacketLength can return the new packet length + _packetLengthQueried = false; + + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // clear interrupt flags + clearIRQFlags(); + + return(ERR_NONE); +} + +int16_t Si443x::setBitRate(float br) { + RADIOLIB_CHECK_RANGE(br, 0.123, 256.0, ERR_INVALID_BIT_RATE); + + // check high data rate + uint8_t dataRateMode = SI443X_LOW_DATA_RATE_MODE; + uint8_t exp = 21; + if(br >= 30.0) { + // bit rate above 30 kbps + dataRateMode = SI443X_HIGH_DATA_RATE_MODE; + exp = 16; + } + + // calculate raw data rate value + uint16_t txDr = (br * ((uint32_t)1 << exp)) / 1000.0; + + // update registers + int16_t state = _mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, dataRateMode, 5, 5); + _mod->SPIwriteRegister(SI443X_REG_TX_DATA_RATE_1, (uint8_t)((txDr & 0xFF00) >> 8)); + _mod->SPIwriteRegister(SI443X_REG_TX_DATA_RATE_0, (uint8_t)(txDr & 0xFF)); + + if(state == ERR_NONE) { + _br = br; + } + RADIOLIB_ASSERT(state); + + // update clock recovery + state = updateClockRecovery(); + + return(state); +} + +int16_t Si443x::setFrequencyDeviation(float freqDev) { + // set frequency deviation to lowest available setting (required for RTTY) + if(freqDev == 0.0) { + int16_t state = _mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, 0x00, 2, 2); + _mod->SPIwriteRegister(SI443X_REG_FREQUENCY_DEVIATION, 0x00); + + if(state == ERR_NONE) { + _freqDev = freqDev; + } + + } + + RADIOLIB_CHECK_RANGE(freqDev, 0.625, 320.0, ERR_INVALID_FREQUENCY_DEVIATION); + + // calculate raw frequency deviation value + uint16_t fdev = (uint16_t)(freqDev / 0.625); + + // update registers + int16_t state = _mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, (uint8_t)((fdev & 0x0100) >> 6), 2, 2); + _mod->SPIwriteRegister(SI443X_REG_FREQUENCY_DEVIATION, (uint8_t)(fdev & 0xFF)); + + if(state == ERR_NONE) { + _freqDev = freqDev; + } + + return(state); +} + +int16_t Si443x::setRxBandwidth(float rxBw) { + RADIOLIB_CHECK_RANGE(rxBw, 2.6, 620.7, ERR_INVALID_RX_BANDWIDTH); + + // decide which approximation to use for decimation rate and filter tap calculation + uint8_t bypass = SI443X_BYPASS_DEC_BY_3_OFF; + uint8_t decRate = SI443X_IF_FILTER_DEC_RATE; + uint8_t filterSet = SI443X_IF_FILTER_COEFF_SET; + + // this is the "well-behaved" section - can be linearly approximated + if((rxBw >= 2.6) && (rxBw <= 4.5)) { + decRate = 5; + filterSet = ((rxBw - 2.1429)/0.3250 + 0.5); + } else if((rxBw > 4.5) && (rxBw <= 8.8)) { + decRate = 4; + filterSet = ((rxBw - 3.9857)/0.6643 + 0.5); + } else if((rxBw > 8.8) && (rxBw <= 17.5)) { + decRate = 3; + filterSet = ((rxBw - 7.6714)/1.3536 + 0.5); + } else if((rxBw > 17.5) && (rxBw <= 34.7)) { + decRate = 2; + filterSet = ((rxBw - 15.2000)/2.6893 + 0.5); + } else if((rxBw > 34.7) && (rxBw <= 69.2)) { + decRate = 1; + filterSet = ((rxBw - 30.2430)/5.3679 + 0.5); + } else if((rxBw > 69.2) && (rxBw <= 137.9)) { + decRate = 0; + filterSet = ((rxBw - 60.286)/10.7000 + 0.5); + + // this is the "Lord help thee who tread 'ere" section - no way to approximate this mess + } else if(rxBw == 142.8) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 1; + filterSet = 4; + } else if(rxBw == 167.8) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 1; + filterSet = 5; + } else if(rxBw == 181.1) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 1; + filterSet = 6; + } else if(rxBw == 191.5) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 15; + } else if(rxBw == 225.1) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 1; + } else if(rxBw == 248.8) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 2; + } else if(rxBw == 269.3) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 3; + } else if(rxBw == 284.8) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 4; + } else if(rxBw == 335.5) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 8; + } else if(rxBw == 391.8) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 9; + } else if(rxBw == 420.2) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 10; + } else if(rxBw == 468.4) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 11; + } else if(rxBw == 518.8) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 12; + } else if(rxBw == 577.0) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 13; + } else if(rxBw == 620.7) { + bypass = SI443X_BYPASS_DEC_BY_3_ON; + decRate = 0; + filterSet = 14; + } else { + return(ERR_INVALID_RX_BANDWIDTH); + } + + // shift decimation rate bits + decRate <<= 4; + + // update register + int16_t state = _mod->SPIsetRegValue(SI443X_REG_IF_FILTER_BANDWIDTH, bypass | decRate | filterSet); + RADIOLIB_ASSERT(state); + + // update clock recovery + state = updateClockRecovery(); + + return(state); +} + +int16_t Si443x::setSyncWord(uint8_t* syncWord, size_t len) { + RADIOLIB_CHECK_RANGE(len, 1, 4, ERR_INVALID_SYNC_WORD); + + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // set sync word length + state = _mod->SPIsetRegValue(SI443X_REG_HEADER_CONTROL_2, (uint8_t)(len - 1) << 1, 2, 1); + RADIOLIB_ASSERT(state); + + // set sync word bytes + _mod->SPIwriteRegisterBurst(SI443X_REG_SYNC_WORD_3, syncWord, len); + + return(state); +} + +size_t Si443x::getPacketLength(bool update) { + // TODO variable length mode + if(!_packetLengthQueried && update) { + _packetLength = _mod->SPIreadRegister(SI443X_REG_RECEIVED_PACKET_LENGTH); + _packetLengthQueried = true; + } + + return(_packetLength); +} + +int16_t Si443x::setEncoding(uint8_t encoding) { + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // set encoding + // TODO - add inverted Manchester? + switch(encoding) { + case 0: + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_OFF, 2, 0)); + case 1: + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_ON | SI443X_WHITENING_OFF, 2, 0)); + case 2: + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_ON, 2, 0)); + default: + return(ERR_INVALID_ENCODING); + } +} + +int16_t Si443x::setDataShaping(float sh) { + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + if(sh == 0.0) { + // set modulation to FSK + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_MODULATION_FSK, 1, 0)); + } else { + // set modulation to GFSK + // TODO implement fiter configuration - docs claim this should be possible, but seems undocumented + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_MODULATION_GFSK, 1, 0)); + } +} + +int16_t Si443x::setFrequencyRaw(float newFreq) { + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // check high/low band + uint8_t bandSelect = SI443X_BAND_SELECT_LOW; + uint8_t freqBand = (newFreq / 10) - 24; + if(newFreq >= 480.0) { + bandSelect = SI443X_BAND_SELECT_HIGH; + freqBand = (newFreq / 20) - 24; + } + + // calculate register values + uint16_t freqCarrier = ((newFreq / (10 * ((bandSelect >> 5) + 1))) - freqBand - 24) * (uint32_t)64000; + + // update registers + state = _mod->SPIsetRegValue(SI443X_REG_FREQUENCY_BAND_SELECT, bandSelect | freqBand, 5, 0); + state |= _mod->SPIsetRegValue(SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8)); + state |= _mod->SPIsetRegValue(SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF)); + + return(state); +} + +bool Si443x::findChip() { + uint8_t i = 0; + bool flagFound = false; + while((i < 10) && !flagFound) { + // reset the module + reset(); + + // check version register + uint8_t version = _mod->SPIreadRegister(SI443X_REG_DEVICE_VERSION); + if(version == SI443X_DEVICE_VERSION) { + flagFound = true; + } else { + #ifdef RADIOLIB_DEBUG + RADIOLIB_DEBUG_PRINT(F("Si443x not found! (")); + RADIOLIB_DEBUG_PRINT(i + 1); + RADIOLIB_DEBUG_PRINT(F(" of 10 tries) SI443X_REG_DEVICE_VERSION == ")); + + char buffHex[5]; + sprintf(buffHex, "0x%02X", version); + RADIOLIB_DEBUG_PRINT(buffHex); + RADIOLIB_DEBUG_PRINT(F(", expected 0x00")); + RADIOLIB_DEBUG_PRINTLN(SI443X_DEVICE_VERSION, HEX); + #endif + delay(1000); + i++; + } + } + + return(flagFound); +} + +void Si443x::clearIRQFlags() { + _mod->SPIreadRegister(SI443X_REG_INTERRUPT_STATUS_1); + _mod->SPIreadRegister(SI443X_REG_INTERRUPT_STATUS_2); +} + +int16_t Si443x::config() { + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // disable POR and chip ready interrupts + state = _mod->SPIsetRegValue(SI443X_REG_INTERRUPT_ENABLE_2, 0x00); + RADIOLIB_ASSERT(state); + + // disable packet header + state = _mod->SPIsetRegValue(SI443X_REG_HEADER_CONTROL_2, SI443X_SYNC_WORD_TIMEOUT_ON | SI443X_HEADER_LENGTH_HEADER_NONE, 7, 4); + RADIOLIB_ASSERT(state); + + // disable packet header checking + state = _mod->SPIsetRegValue(SI443X_REG_HEADER_CONTROL_1, SI443X_BROADCAST_ADDR_CHECK_NONE | SI443X_RECEIVED_HEADER_CHECK_NONE); + RADIOLIB_ASSERT(state); + + return(state); +} + +int16_t Si443x::updateClockRecovery() { + // get the parameters + uint8_t bypass = _mod->SPIgetRegValue(SI443X_REG_IF_FILTER_BANDWIDTH, 7, 7) >> 7; + uint8_t decRate = _mod->SPIgetRegValue(SI443X_REG_IF_FILTER_BANDWIDTH, 6, 4) >> 4; + uint8_t manch = _mod->SPIgetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, 1, 1) >> 1; + + // calculate oversampling ratio, NCO offset and clock recovery gain + float rxOsr = ((float)(500 * (1 + 2*bypass))) / (((float)((uint16_t)(1) << decRate)) * _br * ((float)(1 + manch))); + uint32_t ncoOff = (_br * (1 + manch) * ((uint32_t)(1) << (20 + decRate))) / (500 * (1 + 2*bypass)); + uint16_t crGain = 2 + (((float)(65536.0 * (1 + manch)) * _br) / (rxOsr * (_freqDev / 0.625))); + + // convert oversampling ratio from float to fixed point + uint8_t rxOsr_int = (uint8_t)rxOsr; + uint8_t rxOsr_dec = 0; + float rxOsr_temp = rxOsr; + if(rxOsr_temp - rxOsr_int >= 0.5) { + rxOsr_dec |= 0x04; + rxOsr_temp -= 0.5; + } + if(rxOsr_temp - rxOsr_int >= 0.25) { + rxOsr_dec |= 0x02; + rxOsr_temp -= 0.25; + } + if(rxOsr_temp - rxOsr_int >= 0.125) { + rxOsr_dec |= 0x01; + rxOsr_temp -= 0.125; + } + uint16_t rxOsr_fixed = ((uint16_t)rxOsr_int << 3) | ((uint16_t)rxOsr_dec); + + // print that whole mess + RADIOLIB_DEBUG_PRINTLN(bypass, HEX); + RADIOLIB_DEBUG_PRINTLN(decRate, HEX); + RADIOLIB_DEBUG_PRINTLN(manch, HEX); + RADIOLIB_DEBUG_PRINT(rxOsr, 3); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINT(rxOsr_int); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINT(rxOsr_int, HEX); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINT(rxOsr_dec); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINT(rxOsr_dec, HEX); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINT(rxOsr_fixed); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINTLN(rxOsr_fixed, HEX); + RADIOLIB_DEBUG_PRINT(ncoOff); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINTLN(ncoOff, HEX); + RADIOLIB_DEBUG_PRINT(crGain); + RADIOLIB_DEBUG_PRINT('\t'); + RADIOLIB_DEBUG_PRINTLN(crGain, HEX); + + // update oversampling ratio + int16_t state = _mod->SPIsetRegValue(SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5); + RADIOLIB_ASSERT(state); + state = _mod->SPIsetRegValue(SI443X_REG_CLOCK_REC_OVERSAMP_RATIO, (uint8_t)(rxOsr_fixed & 0x00FF)); + RADIOLIB_ASSERT(state); + + // update NCO offset + state = _mod->SPIsetRegValue(SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((ncoOff & 0x0F0000) >> 16), 3, 0); + RADIOLIB_ASSERT(state); + state = _mod->SPIsetRegValue(SI443X_REG_CLOCK_REC_OFFSET_1, (uint8_t)((ncoOff & 0x00FF00) >> 8)); + RADIOLIB_ASSERT(state); + state = _mod->SPIsetRegValue(SI443X_REG_CLOCK_REC_OFFSET_0, (uint8_t)(ncoOff & 0x0000FF)); + RADIOLIB_ASSERT(state); + + // update clock recovery loop gain + state = _mod->SPIsetRegValue(SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_1, (uint8_t)((crGain & 0x0700) >> 8), 2, 0); + RADIOLIB_ASSERT(state); + state = _mod->SPIsetRegValue(SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_0, (uint8_t)(crGain & 0x00FF)); + RADIOLIB_ASSERT(state); + + return(state); +} + +int16_t Si443x::directMode() { + int16_t state = _mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_TX_DATA_SOURCE_GPIO, 5, 4); + RADIOLIB_ASSERT(state); + + state = _mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_MODULATION_NONE, 1, 0); + return(state); +} diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h new file mode 100644 index 00000000..df5ae4d0 --- /dev/null +++ b/src/modules/Si443x/Si443x.h @@ -0,0 +1,786 @@ +#ifndef _RADIOLIB_SI443X_H +#define _RADIOLIB_SI443X_H + +#include "../../TypeDef.h" +#include "../../Module.h" + +#include "../../protocols/PhysicalLayer/PhysicalLayer.h" + +// Si443x physical layer properties +#define SI443X_FREQUENCY_STEP_SIZE 156.25 +#define SI443X_MAX_PACKET_LENGTH 64 + +// Si443x series common registers +#define SI443X_REG_DEVICE_TYPE 0x00 +#define SI443X_REG_DEVICE_VERSION 0x01 +#define SI443X_REG_DEVICE_STATUS 0x02 +#define SI443X_REG_INTERRUPT_STATUS_1 0x03 +#define SI443X_REG_INTERRUPT_STATUS_2 0x04 +#define SI443X_REG_INTERRUPT_ENABLE_1 0x05 +#define SI443X_REG_INTERRUPT_ENABLE_2 0x06 +#define SI443X_REG_OP_FUNC_CONTROL_1 0x07 +#define SI443X_REG_OP_FUNC_CONTROL_2 0x08 +#define SI443X_REG_XOSC_LOAD_CAPACITANCE 0x09 +#define SI443X_REG_MCU_OUTPUT_CLOCK 0x0A +#define SI443X_REG_GPIO0_CONFIG 0x0B +#define SI443X_REG_GPIO1_CONFIG 0x0C +#define SI443X_REG_GPIO2_CONFIG 0x0D +#define SI443X_REG_IO_PORT_CONFIG 0x0E +#define SI443X_REG_ADC_CONFIG 0x0F +#define SI443X_REG_ADC_SENSOR_AMP_OFFSET 0x10 +#define SI443X_REG_ADC_VALUE 0x11 +#define SI443X_REG_TEMP_SENSOR_CONTROL 0x12 +#define SI443X_REG_TEMP_VALUE_OFFSET 0x13 +#define SI443X_REG_WAKEUP_TIMER_PERIOD_1 0x14 +#define SI443X_REG_WAKEUP_TIMER_PERIOD_2 0x15 +#define SI443X_REG_WAKEUP_TIMER_PERIOD_3 0x16 +#define SI443X_REG_WAKEUP_TIMER_VALUE_1 0x17 +#define SI443X_REG_WAKEUP_TIMER_VALUE_2 0x18 +#define SI443X_REG_LOW_DC_MODE_DURATION 0x19 +#define SI443X_REG_LOW_BATT_DET_THRESHOLD 0x1A +#define SI443X_REG_BATT_VOLTAGE_LEVEL 0x1B +#define SI443X_REG_IF_FILTER_BANDWIDTH 0x1C +#define SI443X_REG_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1D +#define SI443X_REG_AFC_TIMING_CONTROL 0x1E +#define SI443X_REG_CLOCK_REC_GEARSHIFT_OVERRIDE 0x1F +#define SI443X_REG_CLOCK_REC_OVERSAMP_RATIO 0x20 +#define SI443X_REG_CLOCK_REC_OFFSET_2 0x21 +#define SI443X_REG_CLOCK_REC_OFFSET_1 0x22 +#define SI443X_REG_CLOCK_REC_OFFSET_0 0x23 +#define SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_1 0x24 +#define SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_0 0x25 +#define SI443X_REG_RSSI 0x26 +#define SI443X_REG_RSSI_CLEAR_CHANNEL_THRESHOLD 0x27 +#define SI443X_REG_ANTENNA_DIVERSITY_1 0x28 +#define SI443X_REG_ANTENNA_DIVERSITY_2 0x29 +#define SI443X_REG_AFC_LIMITER 0x2A +#define SI443X_REG_AFC_CORRECTION 0x2B +#define SI443X_REG_OOK_COUNTER_1 0x2C +#define SI443X_REG_OOK_COUNTER_2 0x2D +#define SI443X_REG_SLICER_PEAK_HOLD 0x2E +#define SI443X_REG_DATA_ACCESS_CONTROL 0x30 +#define SI443X_REG_EZMAC_STATUS 0x31 +#define SI443X_REG_HEADER_CONTROL_1 0x32 +#define SI443X_REG_HEADER_CONTROL_2 0x33 +#define SI443X_REG_PREAMBLE_LENGTH 0x34 +#define SI443X_REG_PREAMBLE_DET_CONTROL 0x35 +#define SI443X_REG_SYNC_WORD_3 0x36 +#define SI443X_REG_SYNC_WORD_2 0x37 +#define SI443X_REG_SYNC_WORD_1 0x38 +#define SI443X_REG_SYNC_WORD_0 0x39 +#define SI443X_REG_TRANSMIT_HEADER_3 0x3A +#define SI443X_REG_TRANSMIT_HEADER_2 0x3B +#define SI443X_REG_TRANSMIT_HEADER_1 0x3C +#define SI443X_REG_TRANSMIT_HEADER_0 0x3D +#define SI443X_REG_TRANSMIT_PACKET_LENGTH 0x3E +#define SI443X_REG_CHECK_HEADER_3 0x3F +#define SI443X_REG_CHECK_HEADER_2 0x40 +#define SI443X_REG_CHECK_HEADER_1 0x41 +#define SI443X_REG_CHECK_HEADER_0 0x42 +#define SI443X_REG_HEADER_ENABLE_3 0x43 +#define SI443X_REG_HEADER_ENABLE_2 0x44 +#define SI443X_REG_HEADER_ENABLE_1 0x45 +#define SI443X_REG_HEADER_ENABLE_0 0x46 +#define SI443X_REG_RECEIVED_HEADER_3 0x47 +#define SI443X_REG_RECEIVED_HEADER_2 0x48 +#define SI443X_REG_RECEIVED_HEADER_1 0x49 +#define SI443X_REG_RECEIVED_HEADER_0 0x4A +#define SI443X_REG_RECEIVED_PACKET_LENGTH 0x4B +#define SI443X_REG_ADC8_CONTROL 0x4F +#define SI443X_REG_CHANNEL_FILTER_COEFF 0x60 +#define SI443X_REG_XOSC_CONTROL_TEST 0x62 +#define SI443X_REG_AGC_OVERRIDE_1 0x69 +#define SI443X_REG_TX_POWER 0x6D +#define SI443X_REG_TX_DATA_RATE_1 0x6E +#define SI443X_REG_TX_DATA_RATE_0 0x6F +#define SI443X_REG_MODULATION_MODE_CONTROL_1 0x70 +#define SI443X_REG_MODULATION_MODE_CONTROL_2 0x71 +#define SI443X_REG_FREQUENCY_DEVIATION 0x72 +#define SI443X_REG_FREQUENCY_OFFSET_1 0x73 +#define SI443X_REG_FREQUENCY_OFFSET_2 0x74 +#define SI443X_REG_FREQUENCY_BAND_SELECT 0x75 +#define SI443X_REG_NOM_CARRIER_FREQUENCY_1 0x76 +#define SI443X_REG_NOM_CARRIER_FREQUENCY_0 0x77 +#define SI443X_REG_FREQUENCY_HOPPING_CHANNEL_SEL 0x79 +#define SI443X_REG_FREQUENCY_HOPPING_STEP_SIZE 0x7A +#define SI443X_REG_TX_FIFO_CONTROL_1 0x7C +#define SI443X_REG_TX_FIFO_CONTROL_2 0x7D +#define SI443X_REG_RX_FIFO_CONTROL 0x7E +#define SI443X_REG_FIFO_ACCESS 0x7F + +// SI443X_REG_DEVICE_TYPE MSB LSB DESCRIPTION +#define SI443X_DEVICE_TYPE 0x08 // 4 0 device identification register + +// SI443X_REG_DEVICE_VERSION +#define SI443X_DEVICE_VERSION 0x06 // 4 0 chip version register + +// SI443X_REG_DEVICE_STATUS +#define SI443X_RX_TX_FIFO_OVERFLOW 0b10000000 // 7 7 Rx/Tx FIFO overflow flag +#define SI443X_RX_TX_FIFO_UNDERFLOW 0b01000000 // 6 6 Rx/Tx FIFO underflow flag +#define SI443X_RX_FIFO_EMPTY 0b00100000 // 5 5 Rx FIFO empty flag +#define SI443X_HEADER_ERROR 0b00010000 // 4 4 header error flag +#define SI443X_FREQUENCY_ERROR 0b00001000 // 3 3 frequency error flag (frequency outside allowed range) +#define SI443X_TX 0b00000010 // 1 0 power state: Tx +#define SI443X_RX 0b00000001 // 1 0 Rx +#define SI443X_IDLE 0b00000000 // 1 0 idle + +// SI443X_REG_INTERRUPT_STATUS_1 +#define SI443X_FIFO_LEVEL_ERROR_INTERRUPT 0b10000000 // 7 7 Tx/Rx FIFO overflow or underflow +#define SI443X_TX_FIFO_ALMOST_FULL_INTERRUPT 0b01000000 // 6 6 Tx FIFO almost full +#define SI443X_TX_FIFO_ALMOST_EMPTY_INTERRUPT 0b00100000 // 5 5 Tx FIFO almost empty +#define SI443X_RX_FIFO_ALMOST_FULL_INTERRUPT 0b00010000 // 4 4 Rx FIFO almost full +#define SI443X_EXTERNAL_INTERRUPT 0b00001000 // 3 3 external interrupt occurred on GPIOx +#define SI443X_PACKET_SENT_INTERRUPT 0b00000100 // 2 2 packet transmission done +#define SI443X_VALID_PACKET_RECEIVED_INTERRUPT 0b00000010 // 1 1 valid packet has been received +#define SI443X_CRC_ERROR_INTERRUPT 0b00000001 // 0 0 CRC failed + +// SI443X_REG_INTERRUPT_STATUS_2 +#define SI443X_SYNC_WORD_DETECTED_INTERRUPT 0b10000000 // 7 7 sync word has been detected +#define SI443X_VALID_PREAMBLE_DETECTED_INTERRUPT 0b01000000 // 6 6 valid preamble has been detected +#define SI443X_INVALID_PREAMBLE_DETECTED_INTERRUPT 0b00100000 // 5 5 invalid preamble has been detected +#define SI443X_RSSI_INTERRUPT 0b00010000 // 4 4 RSSI exceeded programmed threshold +#define SI443X_WAKEUP_TIMER_INTERRUPT 0b00001000 // 3 3 wake-up timer expired +#define SI443X_LOW_BATTERY_INTERRUPT 0b00000100 // 2 2 low battery detected +#define SI443X_CHIP_READY_INTERRUPT 0b00000010 // 1 1 chip ready event detected +#define SI443X_POWER_ON_RESET_INTERRUPT 0b00000001 // 0 0 power-on-reset detected + +// SI443X_REG_INTERRUPT_ENABLE_1 +#define SI443X_FIFO_LEVEL_ERROR_ENABLED 0b10000000 // 7 7 Tx/Rx FIFO overflow or underflow interrupt enabled +#define SI443X_TX_FIFO_ALMOST_FULL_ENABLED 0b01000000 // 6 6 Tx FIFO almost full interrupt enabled +#define SI443X_TX_FIFO_ALMOST_EMPTY_ENABLED 0b00100000 // 5 5 Tx FIFO almost empty interrupt enabled +#define SI443X_RX_FIFO_ALMOST_FULL_ENABLED 0b00010000 // 4 4 Rx FIFO almost full interrupt enabled +#define SI443X_EXTERNAL_ENABLED 0b00001000 // 3 3 external interrupt interrupt enabled +#define SI443X_PACKET_SENT_ENABLED 0b00000100 // 2 2 packet transmission done interrupt enabled +#define SI443X_VALID_PACKET_RECEIVED_ENABLED 0b00000010 // 1 1 valid packet received interrupt enabled +#define SI443X_CRC_ERROR_ENABLED 0b00000001 // 0 0 CRC failed interrupt enabled + +// SI443X_REG_INTERRUPT_ENABLE_2 +#define SI443X_SYNC_WORD_DETECTED_ENABLED 0b10000000 // 7 7 sync word interrupt enabled +#define SI443X_VALID_PREAMBLE_DETECTED_ENABLED 0b01000000 // 6 6 valid preamble interrupt enabled +#define SI443X_INVALID_PREAMBLE_DETECTED_ENABLED 0b00100000 // 5 5 invalid preamble interrupt enabled +#define SI443X_RSSI_ENABLED 0b00010000 // 4 4 RSSI exceeded programmed threshold interrupt enabled +#define SI443X_WAKEUP_TIMER_ENABLED 0b00001000 // 3 3 wake-up timer interrupt enabled +#define SI443X_LOW_BATTERY_ENABLED 0b00000100 // 2 2 low battery interrupt enabled +#define SI443X_CHIP_READY_ENABLED 0b00000010 // 1 1 chip ready event interrupt enabled +#define SI443X_POWER_ON_RESET_ENABLED 0b00000001 // 0 0 power-on-reset interrupt enabled + +// SI443X_REG_OP_FUNC_CONTROL_1 +#define SI443X_SOFTWARE_RESET 0b10000000 // 7 7 reset all registers to default values +#define SI443X_ENABLE_LOW_BATTERY_DETECT 0b01000000 // 6 6 enable low battery detection +#define SI443X_ENABLE_WAKEUP_TIMER 0b00100000 // 5 5 enable wakeup timer +#define SI443X_32_KHZ_RC 0b00000000 // 4 4 32.768 kHz source: RC oscillator (default) +#define SI443X_32_KHZ_XOSC 0b00010000 // 4 4 crystal oscillator +#define SI443X_TX_ON 0b00001000 // 3 3 Tx on in manual transmit mode +#define SI443X_RX_ON 0b00000100 // 2 2 Rx on in manual receive mode +#define SI443X_PLL_ON 0b00000010 // 1 1 PLL on (tune mode) +#define SI443X_XTAL_OFF 0b00000000 // 0 0 crystal oscillator: off (standby mode) +#define SI443X_XTAL_ON 0b00000001 // 0 0 on (ready mode) + +// SI443X_REG_OP_FUNC_CONTROL_2 +#define SI443X_ANT_DIV_TR_HL_IDLE_L 0b00000000 // 7 5 GPIO1/2 states: Tx/Rx GPIO1 H, GPIO2 L; idle low (default) +#define SI443X_ANT_DIV_TR_LH_IDLE_L 0b00100000 // 7 5 Tx/Rx GPIO1 L, GPIO2 H; idle low +#define SI443X_ANT_DIV_TR_HL_IDLE_H 0b01000000 // 7 5 Tx/Rx GPIO1 H, GPIO2 L; idle high +#define SI443X_ANT_DIV_TR_LH_IDLE_H 0b01100000 // 7 5 Tx/Rx GPIO1 L, GPIO2 H; idle high +#define SI443X_ANT_DIV_TR_ALG_IDLE_L 0b10000000 // 7 5 Tx/Rx diversity algorithm; idle low +#define SI443X_ANT_DIV_TR_ALG_IDLE_H 0b10100000 // 7 5 Tx/Rx diversity algorithm; idle high +#define SI443X_ANT_DIV_TR_ALG_BEACON_IDLE_L 0b11000000 // 7 5 Tx/Rx diversity algorithm (beacon); idle low +#define SI443X_ANT_DIV_TR_ALG_BEACON_IDLE_H 0b11100000 // 7 5 Tx/Rx diversity algorithm (beacon); idle high +#define SI443X_RX_MULTIPACKET_OFF 0b00000000 // 4 4 Rx multipacket: disabled (default) +#define SI443X_RX_MULTIPACKET_ON 0b00010000 // 4 4 enabled +#define SI443X_AUTO_TX_OFF 0b00000000 // 3 3 Tx autotransmit on FIFO almost full: disabled (default) +#define SI443X_AUTO_TX_ON 0b00001000 // 3 3 enabled +#define SI443X_LOW_DUTY_CYCLE_OFF 0b00000000 // 2 2 low duty cycle mode: disabled (default) +#define SI443X_LOW_DUTY_CYCLE_ON 0b00000100 // 2 2 enabled +#define SI443X_RX_FIFO_RESET 0b00000010 // 1 1 Rx FIFO reset/clear: reset (call first) +#define SI443X_RX_FIFO_CLEAR 0b00000000 // 1 1 clear (call second) +#define SI443X_TX_FIFO_RESET 0b00000001 // 0 0 Tx FIFO reset/clear: reset (call first) +#define SI443X_TX_FIFO_CLEAR 0b00000000 // 0 0 clear (call second) + +// SI443X_REG_XOSC_LOAD_CAPACITANCE +#define SI443X_XTAL_SHIFT 0b00000000 // 7 7 crystal capacitance configuration: +#define SI443X_XTAL_LOAD_CAPACITANCE 0b01111111 // 6 0 C_int = 1.8 pF + 0.085 pF * SI443X_XTAL_LOAD_CAPACITANCE + 3.7 pF * SI443X_XTAL_SHIFT + +// SI443X_REG_MCU_OUTPUT_CLOCK +#define SI443X_CLOCK_TAIL_CYCLES_OFF 0b00000000 // 5 4 additional clock cycles: none (default) +#define SI443X_CLOCK_TAIL_CYCLES_128 0b00010000 // 5 4 128 +#define SI443X_CLOCK_TAIL_CYCLES_256 0b00100000 // 5 4 256 +#define SI443X_CLOCK_TAIL_CYCLES_512 0b00110000 // 5 4 512 +#define SI443X_LOW_FREQ_CLOCK_OFF 0b00000000 // 3 3 32.768 kHz clock output: disabled (default) +#define SI443X_LOW_FREQ_CLOCK_ON 0b00001000 // 3 3 enabled +#define SI443X_MCU_CLOCK_30_MHZ 0b00000000 // 2 0 GPIO clock output: 30 MHz +#define SI443X_MCU_CLOCK_15_MHZ 0b00000001 // 2 0 15 MHz +#define SI443X_MCU_CLOCK_10_MHZ 0b00000010 // 2 0 10 MHz +#define SI443X_MCU_CLOCK_4_MHZ 0b00000011 // 2 0 4 MHz +#define SI443X_MCU_CLOCK_3_MHZ 0b00000100 // 2 0 3 MHz +#define SI443X_MCU_CLOCK_2_MHZ 0b00000101 // 2 0 2 MHz +#define SI443X_MCU_CLOCK_1_MHZ 0b00000110 // 2 0 1 MHz (default) +#define SI443X_MCU_CLOCK_32_KHZ 0b00000111 // 2 0 32.768 kHz + +// SI443X_REG_GPIO0_CONFIG + SI443X_REG_GPIO1_CONFIG + SI443X_REG_GPIO2_CONFIG +#define SI443X_GPIOX_DRIVE_STRENGTH 0b00000000 // 7 6 GPIOx drive strength (higher number = stronger drive) +#define SI443X_GPIOX_PULLUP_OFF 0b00000000 // 5 5 GPIOx internal 200k pullup: disabled (default) +#define SI443X_GPIOX_PULLUP_ON 0b00100000 // 5 5 enabled +#define SI443X_GPIO0_POWER_ON_RESET_OUT 0b00000000 // 4 0 GPIOx function: power-on-reset output (GPIO0 only, default) +#define SI443X_GPIO1_POWER_ON_RESET_INV_OUT 0b00000000 // 4 0 inverted power-on-reset output (GPIO1 only, default) +#define SI443X_GPIO2_MCU_CLOCK_OUT 0b00000000 // 4 0 MCU clock output (GPIO2 only, default) +#define SI443X_GPIOX_WAKEUP_OUT 0b00000001 // 4 0 wakeup timer expired output +#define SI443X_GPIOX_LOW_BATTERY_OUT 0b00000010 // 4 0 low battery detect output +#define SI443X_GPIOX_DIGITAL_OUT 0b00000011 // 4 0 direct digital output +#define SI443X_GPIOX_EXT_INT_FALLING_IN 0b00000100 // 4 0 external interrupt, falling edge +#define SI443X_GPIOX_EXT_INT_RISING_IN 0b00000101 // 4 0 external interrupt, rising edge +#define SI443X_GPIOX_EXT_INT_CHANGE_IN 0b00000110 // 4 0 external interrupt, state change +#define SI443X_GPIOX_ADC_IN 0b00000111 // 4 0 ADC analog input +#define SI443X_GPIOX_ANALOG_TEST_N_IN 0b00001000 // 4 0 analog test N input +#define SI443X_GPIOX_ANALOG_TEST_P_IN 0b00001001 // 4 0 analog test P input +#define SI443X_GPIOX_DIGITAL_IN 0b00001010 // 4 0 direct digital input +#define SI443X_GPIOX_DIGITAL_TEST_OUT 0b00001011 // 4 0 digital test output +#define SI443X_GPIOX_ANALOG_TEST_N_OUT 0b00001100 // 4 0 analog test N output +#define SI443X_GPIOX_ANALOG_TEST_P_OUT 0b00001101 // 4 0 analog test P output +#define SI443X_GPIOX_REFERENCE_VOLTAGE_OUT 0b00001110 // 4 0 reference voltage output +#define SI443X_GPIOX_TX_RX_DATA_CLK_OUT 0b00001111 // 4 0 Tx/Rx clock output in direct mode +#define SI443X_GPIOX_TX_DATA_IN 0b00010000 // 4 0 Tx data input direct mode +#define SI443X_GPIOX_EXT_RETRANSMIT_REQUEST_IN 0b00010001 // 4 0 external retransmission request input +#define SI443X_GPIOX_TX_STATE_OUT 0b00010010 // 4 0 Tx state output +#define SI443X_GPIOX_TX_FIFO_ALMOST_FULL_OUT 0b00010011 // 4 0 Tx FIFO almost full output +#define SI443X_GPIOX_RX_DATA_OUT 0b00010100 // 4 0 Rx data output +#define SI443X_GPIOX_RX_STATE_OUT 0b00010101 // 4 0 Rx state output +#define SI443X_GPIOX_RX_FIFO_ALMOST_FULL_OUT 0b00010110 // 4 0 Rx FIFO almost full output +#define SI443X_GPIOX_ANT_DIV_1_OUT 0b00010111 // 4 0 antenna diversity output 1 +#define SI443X_GPIOX_ANT_DIV_2_OUT 0b00011000 // 4 0 antenna diversity output 2 +#define SI443X_GPIOX_VALID_PREAMBLE_OUT 0b00011001 // 4 0 valid preamble detected output +#define SI443X_GPIOX_INVALID_PREAMBLE_OUT 0b00011010 // 4 0 invalid preamble detected output +#define SI443X_GPIOX_SYNC_WORD_DETECTED_OUT 0b00011011 // 4 0 sync word detected output +#define SI443X_GPIOX_CLEAR_CHANNEL_OUT 0b00011100 // 4 0 clear channel assessment output +#define SI443X_GPIOX_VDD 0b00011101 // 4 0 VDD +#define SI443X_GPIOX_GND 0b00011110 // 4 0 GND + +// SI443X_REG_IO_PORT_CONFIG +#define SI443X_GPIO2_EXT_INT_STATE_MASK 0b01000000 // 6 6 external interrupt state mask for: GPIO2 +#define SI443X_GPIO1_EXT_INT_STATE_MASK 0b00100000 // 5 5 GPIO1 +#define SI443X_GPIO0_EXT_INT_STATE_MASK 0b00010000 // 4 4 GPIO0 +#define SI443X_IRQ_BY_SDO_OFF 0b00000000 // 3 3 output IRQ state on SDO pin: disabled (default) +#define SI443X_IRQ_BY_SDO_ON 0b00001000 // 3 3 enabled +#define SI443X_GPIO2_DIGITAL_STATE_MASK 0b00000100 // 2 2 digital state mask for: GPIO2 +#define SI443X_GPIO1_DIGITAL_STATE_MASK 0b00000010 // 1 1 GPIO1 +#define SI443X_GPIO0_DIGITAL_STATE_MASK 0b00000001 // 0 0 GPIO0 + +// SI443X_REG_ADC_CONFIG +#define SI443X_ADC_START 0b10000000 // 7 7 ADC control: start measurement +#define SI443X_ADC_RUNNING 0b00000000 // 7 7 measurement in progress +#define SI443X_ADC_DONE 0b10000000 // 7 7 done +#define SI443X_ADC_SOURCE_TEMPERATURE 0b00000000 // 6 4 ADC source: internal temperature sensor (default) +#define SI443X_ADC_SOURCE_GPIO0_SINGLE 0b00010000 // 6 4 single-ended on GPIO0 +#define SI443X_ADC_SOURCE_GPIO1_SINGLE 0b00100000 // 6 4 single-ended on GPIO1 +#define SI443X_ADC_SOURCE_GPIO2_SINGLE 0b00110000 // 6 4 single-ended on GPIO2 +#define SI443X_ADC_SOURCE_GPIO01_DIFF 0b01000000 // 6 4 differential on GPIO0 (+) and GPIO1 (-) +#define SI443X_ADC_SOURCE_GPIO12_DIFF 0b01010000 // 6 4 differential on GPIO1 (+) and GPIO2 (-) +#define SI443X_ADC_SOURCE_GPIO02_DIFF 0b01100000 // 6 4 differential on GPIO0 (+) and GPIO2 (-) +#define SI443X_ADC_SOURCE_GND 0b01110000 // 6 4 GND +#define SI443X_ADC_REFERNCE_BAND_GAP 0b00000000 // 3 2 ADC reference: internal bandgap 1.2 V (default) +#define SI443X_ADC_REFERNCE_VDD_3 0b00001000 // 3 2 VDD/3 +#define SI443X_ADC_REFERNCE_VDD_2 0b00001100 // 3 2 VDD/2 +#define SI443X_ADC_GAIN 0b00000000 // 1 0 ADC amplifier gain + +// SI443X_REG_ADC_SENSOR_AMP_OFFSET +#define SI443X_ADC_OFFSET 0b00000000 // 3 0 ADC offset + +// SI443X_REG_TEMP_SENSOR_CONTROL +#define SI443X_TEMP_SENSOR_RANGE_64_TO_64_C 0b00000000 // 7 6 temperature sensor range: -64 to 64 deg. C, 0.5 deg. C resolution (default) +#define SI443X_TEMP_SENSOR_RANGE_64_TO_192_C 0b01000000 // 7 6 -64 to 192 deg. C, 1.0 deg. C resolution +#define SI443X_TEMP_SENSOR_RANGE_0_TO_128_C 0b11000000 // 7 6 0 to 128 deg. C, 0.5 deg. C resolution +#define SI443X_TEMP_SENSOR_RANGE_40_TO_216_F 0b10000000 // 7 6 -40 to 216 deg. F, 1.0 deg. F resolution +#define SI443X_TEMP_SENSOR_KELVIN_TO_CELSIUS_OFF 0b00000000 // 5 5 Kelvin to Celsius offset: disabled +#define SI443X_TEMP_SENSOR_KELVIN_TO_CELSIUS_ON 0b00100000 // 5 5 enabled (default) +#define SI443X_TEMP_SENSOR_TRIM_OFF 0b00000000 // 4 4 temperature sensor trim: disabled (default) +#define SI443X_TEMP_SENSOR_TRIM_ON 0b00010000 // 4 4 enabled +#define SI443X_TEMP_SENSOR_TRIM_VALUE 0b00000000 // 3 0 temperature sensor trim value + +// SI443X_REG_WAKEUP_TIMER_PERIOD_1 +#define SI443X_WAKEUP_TIMER_EXPONENT 0b00000011 // 4 0 wakeup timer value exponent + +// SI443X_REG_WAKEUP_TIMER_PERIOD_2 + SI443X_REG_WAKEUP_TIMER_PERIOD_3 +#define SI443X_WAKEUP_TIMER_MANTISSA_MSB 0x00 // 7 0 wakeup timer value: +#define SI443X_WAKEUP_TIMER_MANTISSA_LSB 0x01 // 7 0 T = (4 * SI443X_WAKEUP_TIMER_MANTISSA * 2 ^ SI443X_WAKEUP_TIMER_EXPONENT) / 32.768 ms + +// SI443X_REG_LOW_DC_MODE_DURATION +#define SI443X_LOW_DC_MODE_DURATION_MANTISSA 0x01 // 7 0 low duty cycle mode duration: T = (4 * SI443X_LOW_DC_MODE_DURATION_MANTISSA * 2 ^ SI443X_WAKEUP_TIMER_EXPONENT) / 32.768 ms + +// SI443X_REG_LOW_BATT_DET_THRESHOLD +#define SI443X_LOW_BATT_DET_THRESHOLD 0b00010100 // 4 0 low battery detection threshold: Vth = 1.7 + SI443X_LOW_BATT_DET_THRESHOLD * 0.05 V (defaults to 2.7 V) + +// SI443X_REG_IF_FILTER_BANDWIDTH +#define SI443X_BYPASS_DEC_BY_3_OFF 0b00000000 // 7 7 bypass decimate-by-3 stage: disabled (default) +#define SI443X_BYPASS_DEC_BY_3_ON 0b10000000 // 7 7 enabled +#define SI443X_IF_FILTER_DEC_RATE 0b00000000 // 6 4 IF filter decimation rate +#define SI443X_IF_FILTER_COEFF_SET 0b00000001 // 3 0 IF filter coefficient set selection + +// SI443X_REG_AFC_LOOP_GEARSHIFT_OVERRIDE +#define SI443X_AFC_WIDEBAND_OFF 0b00000000 // 7 7 AFC wideband: disabled (default) +#define SI443X_AFC_WIDEBAND_ON 0b10000000 // 7 7 enabled +#define SI443X_AFC_OFF 0b00000000 // 6 6 AFC: disabled +#define SI443X_AFC_ON 0b01000000 // 6 6 enabled (default) +#define SI443X_AFC_HIGH_GEAR_SETTING 0b00000000 // 5 3 AFC high gear setting +#define SI443X_SECOND_PHASE_BIAS_0_DB 0b00000100 // 2 2 second phase antenna selection bias: 0 dB (default) +#define SI443X_SECOND_PHASE_BIAS_1_5_DB 0b00000000 // 2 2 1.5 dB +#define SI443X_MOVING_AVERAGE_TAP_8 0b00000010 // 1 1 moving average filter tap length: 8*Tb +#define SI443X_MOVING_AVERAGE_TAP_4 0b00000000 // 1 1 4*Tb after first preamble (default) +#define SI443X_ZERO_PHASE_RESET_5 0b00000000 // 0 0 reset preamble detector after: 5 zero phases (default) +#define SI443X_ZERO_PHASE_RESET_2 0b00000001 // 0 0 3 zero phases + +// SI443X_REG_AFC_TIMING_CONTROL +#define SI443X_SW_ANT_TIMER 0b00000000 // 7 6 number of periods to wait for RSSI to stabilize during antenna switching +#define SI443X_SHORT_WAIT 0b00001000 // 5 3 period to wait after AFC correction +#define SI443X_ANTENNA_SWITCH_WAIT 0b00000010 // 2 0 antenna switching wait time + +// SI443X_REG_CLOCK_REC_GEARSHIFT_OVERRIDE +#define SI443X_CLOCK_RECOVER_FAST_GEARSHIFT 0b00000000 // 5 3 clock recovery fast gearshift value +#define SI443X_CLOCK_RECOVER_SLOW_GEARSHIFT 0b00000011 // 2 0 clock recovery slow gearshift value + +// SI443X_REG_CLOCK_REC_OVERSAMP_RATIO +#define SI443X_CLOCK_REC_OVERSAMP_RATIO_LSB 0b01100100 // 7 0 oversampling rate LSB, defaults to 12.5 clock cycles per bit + +// SI443X_REG_CLOCK_REC_OFFSET_2 +#define SI443X_CLOCK_REC_OVERSAMP_RATIO_MSB 0b00000000 // 7 5 oversampling rate MSB, defaults to 12.5 clock cycles per bit +#define SI443X_SECOND_PHASE_SKIP_THRESHOLD 0b00000000 // 4 4 skip seconds phase antenna diversity threshold +#define SI443X_NCO_OFFSET_MSB 0b00000001 // 3 0 NCO offset MSB + +// SI443X_REG_CLOCK_REC_OFFSET_1 +#define SI443X_NCO_OFFSET_MID 0b01000111 // 7 0 NCO offset MID + +// SI443X_REG_CLOCK_REC_OFFSET_0 +#define SI443X_NCO_OFFSET_LSB 0b10101110 // 7 0 NCO offset LSB + +// SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_1 +#define SI443X_RX_COMPENSATION_OFF 0b00000000 // 4 4 Rx compensation for high data rate: disabled (default) +#define SI443X_RX_COMPENSATION_ON 0b00010000 // 4 4 enabled +#define SI443X_CLOCK_REC_GAIN_DOUBLE_OFF 0b00000000 // 3 3 clock recovery gain doubling: disabled (default) +#define SI443X_CLOCK_REC_GAIN_DOUBLE_ON 0b00001000 // 3 3 enabled +#define SI443X_CLOCK_REC_LOOP_GAIN_MSB 0b00000010 // 2 0 clock recovery timing loop gain MSB + +// SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_0 +#define SI443X_CLOCK_REC_LOOP_GAIN_LSB 0b10001111 // 7 0 clock recovery timing loop gain LSB + +// SI443X_REG_RSSI_CLEAR_CHANNEL_THRESHOLD +#define SI443X_RSSI_CLEAR_CHANNEL_THRESHOLD 0b00011110 // 7 0 RSSI clear channel interrupt threshold + +// SI443X_REG_AFC_LIMITER +#define SI443X_AFC_LIMITER 0x00 // 7 0 AFC limiter value + +// SI443X_REG_OOK_COUNTER_1 +#define SI443X_OOK_FREEZE_OFF 0b00000000 // 5 5 OOK moving average detector freeze: disabled (default) +#define SI443X_OOK_FREEZE_ON 0b00100000 // 5 5 enabled +#define SI443X_PEAK_DETECTOR_OFF 0b00000000 // 4 4 peak detector: disabled +#define SI443X_PEAK_DETECTOR_ON 0b00010000 // 4 4 enabled (default) +#define SI443X_OOK_MOVING_AVERAGE_OFF 0b00000000 // 3 3 OOK moving average: disabled +#define SI443X_OOK_MOVING_AVERAGE_ON 0b00001000 // 3 3 enabled (default) +#define SI443X_OOK_COUNTER_MSB 0b00000000 // 2 0 OOK counter MSB + +// SI443X_REG_OOK_COUNTER_2 +#define SI443X_OOK_COUNTER_LSB 0b10111100 // 7 0 OOK counter LSB + +// SI443X_REG_SLICER_PEAK_HOLD +#define SI443X_PEAK_DETECTOR_ATTACK 0b00010000 // 6 4 OOK peak detector attach time +#define SI443X_PEAK_DETECTOR_DECAY 0b00001100 // 3 0 OOK peak detector decay time + +// SI443X_REG_DATA_ACCESS_CONTROL +#define SI443X_PACKET_RX_HANDLING_OFF 0b00000000 // 7 7 packet Rx handling: disabled +#define SI443X_PACKET_RX_HANDLING_ON 0b10000000 // 7 7 enabled (default) +#define SI443X_LSB_FIRST_OFF 0b00000000 // 6 6 LSB first transmission: disabled (default) +#define SI443X_LSB_FIRST_ON 0b01000000 // 6 6 enabled +#define SI443X_CRC_DATA_ONLY_OFF 0b00000000 // 5 5 CRC calculated only from data fields: disabled (default) +#define SI443X_CRC_DATA_ONLY_ON 0b00100000 // 5 5 enabled +#define SI443X_SKIP_SECOND_PHASE_PREAMBLE_DET_OFF 0b00000000 // 4 4 skip second phase of preamble detection: disabled (default) +#define SI443X_SKIP_SECOND_PHASE_PREAMBLE_DET_ON 0b00010000 // 4 4 enabled +#define SI443X_PACKET_TX_HANDLING_OFF 0b00000000 // 3 3 packet Tx handling: disabled +#define SI443X_PACKET_TX_HANDLING_ON 0b00001000 // 3 3 enabled (default) +#define SI443X_CRC_OFF 0b00000000 // 2 2 CRC: disabled +#define SI443X_CRC_ON 0b00000100 // 2 2 enabled (default) +#define SI443X_CRC_CCITT 0b00000000 // 1 0 CRC type: CCITT +#define SI443X_CRC_IBM_CRC16 0b00000001 // 1 0 IBM CRC-16 (default) +#define SI443X_CRC_IEC16 0b00000010 // 1 0 IEC-16 +#define SI443X_CRC_BIACHEVA 0b00000011 // 1 0 Biacheva + +// SI443X_REG_EZMAC_STATUS +#define SI443X_CRC_ALL_ONE 0b01000000 // 6 6 last received CRC was all ones +#define SI443X_PACKET_SEARCHING 0b00100000 // 5 5 radio is searching for a valid packet +#define SI443X_PACKET_RECEIVING 0b00010000 // 4 4 radio is currently receiving packet +#define SI443X_VALID_PACKET_RECEIVED 0b00001000 // 3 3 valid packet was received +#define SI443X_CRC_ERROR 0b00000100 // 2 2 CRC check failed +#define SI443X_PACKET_TRANSMITTING 0b00000010 // 1 1 radio is currently transmitting packet +#define SI443X_PACKET_SENT 0b00000001 // 0 0 packet sent + +// SI443X_REG_HEADER_CONTROL_1 +#define SI443X_BROADCAST_ADDR_CHECK_NONE 0b00000000 // 7 4 broadcast address check: none (default) +#define SI443X_BROADCAST_ADDR_CHECK_BYTE0 0b00010000 // 7 4 on byte 0 +#define SI443X_BROADCAST_ADDR_CHECK_BYTE1 0b00100000 // 7 4 on byte 1 +#define SI443X_BROADCAST_ADDR_CHECK_BYTE2 0b01000000 // 7 4 on byte 2 +#define SI443X_BROADCAST_ADDR_CHECK_BYTE3 0b10000000 // 7 4 on byte 3 +#define SI443X_RECEIVED_HEADER_CHECK_NONE 0b00000000 // 3 0 received header check: none +#define SI443X_RECEIVED_HEADER_CHECK_BYTE0 0b00000001 // 3 0 on byte 0 +#define SI443X_RECEIVED_HEADER_CHECK_BYTE1 0b00000010 // 3 0 on byte 1 +#define SI443X_RECEIVED_HEADER_CHECK_BYTE2 0b00000100 // 3 0 on byte 2 (default) +#define SI443X_RECEIVED_HEADER_CHECK_BYTE3 0b00001000 // 3 0 on byte 3 (default) + +// SI443X_REG_HEADER_CONTROL_2 +#define SI443X_SYNC_WORD_TIMEOUT_OFF 0b00000000 // 7 7 ignore timeout period when searching for sync word: disabled (default) +#define SI443X_SYNC_WORD_TIMEOUT_ON 0b10000000 // 7 7 enabled +#define SI443X_HEADER_LENGTH_HEADER_NONE 0b00000000 // 6 4 header length: none +#define SI443X_HEADER_LENGTH_HEADER_3 0b00010000 // 6 4 header 3 +#define SI443X_HEADER_LENGTH_HEADER_32 0b00100000 // 6 4 header 3 and 2 +#define SI443X_HEADER_LENGTH_HEADER_321 0b00110000 // 6 4 header 3, 2 and 1 (default) +#define SI443X_HEADER_LENGTH_HEADER_3210 0b01000000 // 6 4 header 3, 2, 1, and 0 +#define SI443X_FIXED_PACKET_LENGTH_OFF 0b00000000 // 3 3 fixed packet length mode: disabled (default) +#define SI443X_FIXED_PACKET_LENGTH_ON 0b00001000 // 3 3 enabled +#define SI443X_SYNC_LENGTH_SYNC_3 0b00000000 // 2 1 sync word length: sync 3 +#define SI443X_SYNC_LENGTH_SYNC_32 0b00000010 // 2 1 sync 3 and 2 (default) +#define SI443X_SYNC_LENGTH_SYNC_321 0b00000100 // 2 1 sync 3, 2 and 1 +#define SI443X_SYNC_LENGTH_SYNC_3210 0b00000110 // 2 1 sync 3, 2, 1 and 0 +#define SI443X_PREAMBLE_LENGTH_MSB 0b00000000 // 0 0 preamble length MSB + +// SI443X_REG_PREAMBLE_LENGTH +#define SI443X_PREAMBLE_LENGTH_LSB 0b00001000 // 0 0 preamble length LSB, defaults to 32 bits + +// SI443X_REG_PREAMBLE_DET_CONTROL +#define SI443X_PREAMBLE_DET_THRESHOLD 0b00101000 // 7 3 number of 4-bit nibbles in valid preamble, defaults to 20 bits +#define SI443X_RSSI_OFFSET 0b00000010 // 2 0 RSSI calculation offset, defaults to +8 dB + +// SI443X_REG_SYNC_WORD_3 - SI443X_REG_SYNC_WORD_0 +#define SI443X_SYNC_WORD_3 0x2D // 7 0 sync word: 4th byte (MSB) +#define SI443X_SYNC_WORD_2 0xD4 // 7 0 3rd byte +#define SI443X_SYNC_WORD_1 0x00 // 7 0 2nd byte +#define SI443X_SYNC_WORD_0 0x00 // 7 0 1st byte (LSB) + +// SI443X_REG_CHANNEL_FILTER_COEFF +#define SI443X_INVALID_PREAMBLE_THRESHOLD 0b00000000 // 7 4 invalid preamble threshold in nibbles + +// SI443X_REG_XOSC_CONTROL_TEST +#define SI443X_STATE_LOW_POWER 0b00000000 // 7 5 chip power state: low power +#define SI443X_STATE_READY 0b00100000 // 7 5 ready +#define SI443X_STATE_TUNE 0b01100000 // 7 5 tune +#define SI443X_STATE_TX 0b01000000 // 7 5 Tx +#define SI443X_STATE_RX 0b11100000 // 7 5 Rx + +// SI443X_REG_AGC_OVERRIDE_1 +#define SI443X_AGC_GAIN_INCREASE_OFF 0b00000000 // 6 6 AGC gain increase override: disabled (default) +#define SI443X_AGC_GAIN_INCREASE_ON 0b01000000 // 6 6 enabled +#define SI443X_AGC_OFF 0b00000000 // 5 5 AGC loop: disabled +#define SI443X_AGC_ON 0b00100000 // 5 5 enabled (default) +#define SI443X_LNA_GAIN_MIN 0b00000000 // 4 4 LNA gain select: 5 dB (default) +#define SI443X_LNA_GAIN_MAX 0b00010000 // 4 4 25 dB +#define SI443X_PGA_GAIN_OVERRIDE 0b00000000 // 3 0 PGA gain override, gain = SI443X_PGA_GAIN_OVERRIDE * 3 dB + +// SI443X_REG_TX_POWER +#define SI443X_LNA_SWITCH_OFF 0b00000000 // 3 3 LNA switch control: disabled +#define SI443X_LNA_SWITCH_ON 0b00001000 // 3 3 enabled (default) +#define SI443X_OUTPUT_POWER 0b00000000 // 2 0 output power in 3 dB steps, 0 is chip min, 7 is chip max + +// SI443X_REG_TX_DATA_RATE_1 + SI443X_REG_TX_DATA_RATE_0 +#define SI443X_DATA_RATE_MSB 0x0A // 7 0 data rate: DR = 10^6 * (SI443X_DATA_RATE / 2^16) in high data rate mode or +#define SI443X_DATA_RATE_LSB 0x3D // 7 0 DR = 10^6 * (SI443X_DATA_RATE / 2^21) in low data rate mode (defaults to 40 kbps) + +// SI443X_REG_MODULATION_MODE_CONTROL_1 +#define SI443X_HIGH_DATA_RATE_MODE 0b00000000 // 5 5 data rate: above 30 kbps (default) +#define SI443X_LOW_DATA_RATE_MODE 0b00100000 // 5 5 below 30 kbps +#define SI443X_PACKET_HANDLER_POWER_DOWN_OFF 0b00000000 // 4 4 power off packet handler in low power mode: disabled (default) +#define SI443X_PACKET_HANDLER_POWER_DOWN_ON 0b00010000 // 4 4 enabled +#define SI443X_MANCHESTER_PREAMBLE_POL_LOW 0b00000000 // 3 3 preamble polarity in Manchester mode: low +#define SI443X_MANCHESTER_PREAMBLE_POL_HIGH 0b00001000 // 3 3 high (default) +#define SI443X_MANCHESTER_INVERTED_OFF 0b00000000 // 2 2 inverted Manchester encoding: disabled +#define SI443X_MANCHESTER_INVERTED_ON 0b00000100 // 2 2 enabled (default) +#define SI443X_MANCHESTER_OFF 0b00000000 // 1 1 Manchester encoding: disabled (default) +#define SI443X_MANCHESTER_ON 0b00000010 // 1 1 enabled +#define SI443X_WHITENING_OFF 0b00000000 // 0 0 data whitening: disabled (default) +#define SI443X_WHITENING_ON 0b00000001 // 0 0 enabled + +// SI443X_REG_MODULATION_MODE_CONTROL_2 +#define SI443X_TX_DATA_CLOCK_NONE 0b00000000 // 7 6 Tx data clock: disabled (default) +#define SI443X_TX_DATA_CLOCK_GPIO 0b01000000 // 7 6 GPIO pin +#define SI443X_TX_DATA_CLOCK_SDI 0b10000000 // 7 6 SDI pin +#define SI443X_TX_DATA_CLOCK_NIRQ 0b11000000 // 7 6 nIRQ pin +#define SI443X_TX_DATA_SOURCE_GPIO 0b00000000 // 5 4 Tx data source in direct mode: GPIO pin (default) +#define SI443X_TX_DATA_SOURCE_SDI 0b00010000 // 5 4 SDI pin +#define SI443X_TX_DATA_SOURCE_FIFO 0b00100000 // 5 4 FIFO +#define SI443X_TX_DATA_SOURCE_PN9 0b00110000 // 5 4 PN9 internal +#define SI443X_TX_RX_INVERTED_OFF 0b00000000 // 3 3 Tx/Rx data inverted: disabled (default) +#define SI443X_TX_RX_INVERTED_ON 0b00001000 // 3 3 enabled +#define SI443X_FREQUENCY_DEVIATION_MSB 0b00000000 // 2 2 frequency deviation MSB +#define SI443X_MODULATION_NONE 0b00000000 // 1 0 modulation type: unmodulated carrier (default) +#define SI443X_MODULATION_OOK 0b00000001 // 1 0 OOK +#define SI443X_MODULATION_FSK 0b00000010 // 1 0 FSK +#define SI443X_MODULATION_GFSK 0b00000011 // 1 0 GFSK + +// SI443X_REG_FREQUENCY_DEVIATION +#define SI443X_FREQUENCY_DEVIATION_LSB 0b00100000 // 7 0 frequency deviation LSB, Fd = 625 Hz * SI443X_FREQUENCY_DEVIATION, defaults to 20 kHz + +// SI443X_REG_FREQUENCY_OFFSET_1 + SI443X_REG_FREQUENCY_OFFSET_2 +#define SI443X_FREQUENCY_OFFSET_MSB 0x00 // 7 0 frequency offset: +#define SI443X_FREQUENCY_OFFSET_LSB 0x00 // 1 0 Foff = 156.25 Hz * (SI443X_BAND_SELECT + 1) * SI443X_FREQUENCY_OFFSET, defaults to 156.25 Hz + +// SI443X_REG_FREQUENCY_BAND_SELECT +#define SI443X_SIDE_BAND_SELECT_LOW 0b00000000 // 6 6 Rx LO tuning: below channel frequency (default) +#define SI443X_SIDE_BAND_SELECT_HIGH 0b01000000 // 6 6 above channel frequency +#define SI443X_BAND_SELECT_LOW 0b00000000 // 5 5 band select: low, 240 - 479.9 MHz +#define SI443X_BAND_SELECT_HIGH 0b00100000 // 5 5 high, 480 - 960 MHz (default) +#define SI443X_FREQUENCY_BAND_SELECT 0b00010101 // 4 0 frequency band select + +// SI443X_REG_NOM_CARRIER_FREQUENCY_1 + SI443X_REG_NOM_CARRIER_FREQUENCY_0 +#define SI443X_NOM_CARRIER_FREQUENCY_MSB 0b10111011 // 7 0 nominal carrier frequency: +#define SI443X_NOM_CARRIER_FREQUENCY_LSB 0b10000000 // 7 0 Fc = (SI443X_BAND_SELECT + 1)*10*(SI443X_FREQUENCY_BAND_SELECT + 24) + (SI443X_NOM_CARRIER_FREQUENCY - SI443X_FREQUENCY_OFFSET)/6400 [MHz] + +// SI443X_REG_FREQUENCY_HOPPING_CHANNEL_SEL +#define SI443X_FREQUENCY_HOPPING_CHANNEL 0x00 // 7 0 frequency hopping channel number + +// SI443X_REG_FREQUENCY_HOPPING_STEP_SIZE +#define SI443X_FREQUENCY_HOPPING_STEP_SIZE 0x00 // 7 0 frequency hopping step size + +// SI443X_REG_TX_FIFO_CONTROL_1 +#define SI443X_TX_FIFO_ALMOST_FULL_THRESHOLD 0x37 // 5 0 Tx FIFO almost full threshold + +// SI443X_REG_TX_FIFO_CONTROL_2 +#define SI443X_TX_FIFO_ALMOST_EMPTY_THRESHOLD 0x04 // 5 0 Tx FIFO almost full threshold + +// SI443X_REG_RX_FIFO_CONTROL +#define SI443X_RX_FIFO_ALMOST_FULL_THRESHOLD 0x37 // 5 0 Rx FIFO almost full threshold + +/*! + \class Si443x + + \brief Base class for Si443x series. All derived classes for Si443x (e.g. Si4431 or Si4432) inherit from this base class. + This class should not be instantiated directly from Arduino sketch, only from its derived classes. +*/ +class Si443x: public PhysicalLayer { + public: + // introduce PhysicalLayer overloads + using PhysicalLayer::transmit; + using PhysicalLayer::receive; + using PhysicalLayer::startTransmit; + using PhysicalLayer::readData; + + // constructor + + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio. + */ + Si443x(Module* mod); + + // basic methods + + /*! + \brief Initialization method. + + \param br Bit rate of the FSK transmission in kbps (kilobits per second). + + \param freqDev Frequency deviation of the FSK transmission in kHz. + + \param rxBw Receiver bandwidth in kHz. + + \returns \ref status_codes + */ + int16_t begin(float br, float freqDev, float rxBw); + + /*! + \brief Reset method. Will reset the chip to the default state using SDN pin. + */ + void reset(); + + /*! + \brief Binary transmit method. Will transmit arbitrary binary data up to 64 bytes long. + For overloads to transmit Arduino String or C-string, see PhysicalLayer::transmit. + + \param data Binary data that will be transmitted. + + \param len Length of binary data to transmit (in bytes). + + \param addr Node address to transmit the packet to. + + \returns \ref status_codes + */ + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + + /*! + \brief Binary receive method. Will attempt to receive arbitrary binary data up to 64 bytes long. + For overloads to receive Arduino String, see PhysicalLayer::receive. + + \param data Pointer to array to save the received binary data. + + \param len Number of bytes that will be received. Must be known in advance for binary transmissions. + + \returns \ref status_codes + */ + int16_t receive(uint8_t* data, size_t len); + + /*! + \brief Sets the module to sleep to save power. %Module will not be able to transmit or receive any data while in sleep mode. + %Module will wake up automatically when methods like transmit or receive are called. + + \returns \ref status_codes + */ + int16_t sleep(); + + /*! + \brief Sets the module to standby. + + \returns \ref status_codes + */ + int16_t standby(); + + /*! + \brief Enables direct transmission mode. While in direct mode, the module will not be able to transmit or receive packets. + + \param FRF 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY. + + \returns \ref status_codes + */ + int16_t transmitDirect(uint32_t frf = 0); + + /*! + \brief Enables direct reception mode. While in direct mode, the module will not be able to transmit or receive packets. + + \returns \ref status_codes + */ + int16_t receiveDirect(); + + /*! + \brief Disables direct mode and enables packet mode, allowing the module to receive packets. + + \returns \ref status_codes + */ + int16_t packetMode(); + + // interrupt methods + + /*! + \brief Sets interrupt service routine to call when IRQ activates. + + \param func ISR to call. + */ + void setIrqAction(void (*func)(void)); + + /*! + \brief Clears interrupt service routine to call when IRQ activates. + */ + void clearIrqAction(); + + /*! + \brief Interrupt-driven binary transmit method. Will start transmitting arbitrary binary data up to 64 bytes long. + + \param data Binary data that will be transmitted. + + \param len Length of binary data to transmit (in bytes). + + \param addr Node address to transmit the packet to. + + \returns \ref status_codes + */ + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + + /*! + \brief Interrupt-driven receive method. IRQ will be activated when full valid packet is received. + + \returns \ref status_codes + */ + int16_t startReceive(); + + /*! + \brief Reads data that was received after calling startReceive method. This method reads len characters. + + \param data Pointer to array to save the received binary data. + + \param len Number of bytes that will be received. Must be known in advance for binary transmissions. + + \returns \ref status_codes + */ + int16_t readData(uint8_t* data, size_t len); + + // configuration methods + + /*! + \brief Sets FSK bit rate. Allowed values range from 0.123 to 256.0 kbps. + + \param br Bit rate to be set (in kbps). + + \returns \ref status_codes + */ + int16_t setBitRate(float br); + + /*! + \brief Sets FSK frequency deviation from carrier frequency. Allowed values range from 0.625 to 320.0 kHz. + + \param freqDev Frequency deviation to be set (in kHz). + + \returns \ref status_codes + */ + int16_t setFrequencyDeviation(float freqDev); + + /*! + \brief Sets receiver bandwidth. Allowed values range from 2.6 to 620.7 kHz. + + \param rxBw Receiver bandwidth to be set in kHz. + + \returns \ref status_codes + */ + int16_t setRxBandwidth(float rxBw); + + /*! + \brief Sets sync word. Up to 4 bytes can be set as sync word. + + \param syncWord Pointer to the array of sync word bytes. + + \param len Sync word length in bytes. + */ + int16_t setSyncWord(uint8_t* syncWord, size_t len); + + /*! + \brief Query modem for the packet length of received payload. + + \param update Update received packet length. Will return cached value when set to false. + + \returns Length of last received packet in bytes. + */ + size_t getPacketLength(bool update = true); + + /*! + \brief Sets transmission encoding. Only available in FSK mode. + + \param encoding Encoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening. + + \returns \ref status_codes + */ + int16_t setEncoding(uint8_t encoding); + + /*! + \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. + Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation. + + \param sh Gaussian shaping bandwidth-time product that will be used for data shaping + + \returns \ref status_codes + */ + int16_t setDataShaping(float sh); + +#ifndef RADIOLIB_GODMODE + protected: +#endif + Module* _mod; + + float _br; + float _freqDev; + + size_t _packetLength; + bool _packetLengthQueried; + + int16_t setFrequencyRaw(float newFreq); + +#ifndef RADIOLIB_GODMODE + private: +#endif + bool findChip(); + void clearIRQFlags(); + int16_t config(); + int16_t updateClockRecovery(); + int16_t directMode(); +}; + +#endif From 43295e6827855f007e0d9fc566465dc6e20c8b17 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 17:38:21 +0200 Subject: [PATCH 031/334] Renamed range check macro --- src/BuildOpt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 6e1a8690..2112e21a 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -184,7 +184,7 @@ /*! \brief Macro to check variable is within constraints - this is commonly used to check parameter ranges. */ -#define RADIOLIB_CHECK_CONSTRAINTS(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } } +#define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } } // version definitions From d795787c6ccd09cc9c6f8c88a69de79232f04833 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 17:39:03 +0200 Subject: [PATCH 032/334] [AX25] Added note about Si443x support --- examples/AX25/AX25_Frames/AX25_Frames.ino | 15 ++++++++------- examples/AX25/AX25_Transmit/AX25_Transmit.ino | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/AX25/AX25_Frames/AX25_Frames.ino b/examples/AX25/AX25_Frames/AX25_Frames.ino index 0d5ae5b6..c6af0ad8 100644 --- a/examples/AX25/AX25_Frames/AX25_Frames.ino +++ b/examples/AX25/AX25_Frames/AX25_Frames.ino @@ -11,6 +11,7 @@ - CC1101 - SX126x - nRF24 + - Si443x/RFM2x Using raw AX.25 frames requires some knowledge of the protocol, refer to @@ -48,7 +49,7 @@ void setup() { int state = fsk.beginFSK(434.0, 1.2, 0.5); // when using one of the non-LoRa modules for AX.25 - // (RF69, CC1101, etc.), use the basic begin() method + // (RF69, CC1101, Si4432 etc.), use the basic begin() method // int state = fsk.begin(); if(state == ERR_NONE) { @@ -83,10 +84,10 @@ void loop() { // control field: UI, P/F not used, unnumbered frame // protocol identifier: no layer 3 protocol implemented // information field: "Hello World!" - AX25Frame frameUI("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_U_UNNUMBERED_INFORMATION | + AX25Frame frameUI("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_U_UNNUMBERED_INFORMATION | AX25_CONTROL_POLL_FINAL_DISABLED | AX25_CONTROL_UNNUMBERED_FRAME, AX25_PID_NO_LAYER_3, "Hello World (unnumbered)!"); - + // send the frame Serial.print(F("[AX.25] Sending UI frame ... ")); int state = ax25.sendFrame(&frameUI); @@ -109,12 +110,12 @@ void loop() { // source station callsign: "N7LEM" // source station SSID: 0 // control field: RR, P/F not used, supervisory frame - AX25Frame frameRR("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_S_RECEIVE_READY | + AX25Frame frameRR("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_S_RECEIVE_READY | AX25_CONTROL_POLL_FINAL_DISABLED | AX25_CONTROL_SUPERVISORY_FRAME); // set receive sequence number (0 - 7) frameRR.setRecvSequence(0); - + // send the frame Serial.print(F("[AX.25] Sending RR frame ... ")); state = ax25.sendFrame(&frameRR); @@ -139,7 +140,7 @@ void loop() { // control field: P/F not used, information frame // protocol identifier: no layer 3 protocol implemented // information field: "Hello World (numbered)!" - AX25Frame frameI("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_POLL_FINAL_DISABLED | + AX25Frame frameI("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_POLL_FINAL_DISABLED | AX25_CONTROL_INFORMATION_FRAME, AX25_PID_NO_LAYER_3, "Hello World (numbered)!"); @@ -148,7 +149,7 @@ void loop() { // set send sequence number (0 - 7) frameI.setSendSequence(0); - + // send the frame Serial.print(F("[AX.25] Sending I frame ... ")); state = ax25.sendFrame(&frameI); diff --git a/examples/AX25/AX25_Transmit/AX25_Transmit.ino b/examples/AX25/AX25_Transmit/AX25_Transmit.ino index ac0eb1d2..0a462eff 100644 --- a/examples/AX25/AX25_Transmit/AX25_Transmit.ino +++ b/examples/AX25/AX25_Transmit/AX25_Transmit.ino @@ -11,6 +11,7 @@ - CC1101 - SX126x - nRF24 + - Si443x/RFM2x */ // include the library @@ -41,7 +42,7 @@ void setup() { int state = fsk.beginFSK(434.0, 1.2, 0.5); // when using one of the non-LoRa modules for AX.25 - // (RF69, CC1101, etc.), use the basic begin() method + // (RF69, CC1101,, Si4432 etc.), use the basic begin() method // int state = fsk.begin(); if(state == ERR_NONE) { From 0cdee788dd067e829ae9b6a6ff1fd26bcbaf589e Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 17:39:13 +0200 Subject: [PATCH 033/334] [Morse] Added note about Si443x support --- examples/Morse/Morse_Transmit/Morse_Transmit.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/Morse/Morse_Transmit/Morse_Transmit.ino b/examples/Morse/Morse_Transmit/Morse_Transmit.ino index 6d71d1a4..0cf02e6e 100644 --- a/examples/Morse/Morse_Transmit/Morse_Transmit.ino +++ b/examples/Morse/Morse_Transmit/Morse_Transmit.ino @@ -11,6 +11,7 @@ - CC1101 - SX126x - nRF24 + - Si443x/RFM2x */ // include the library @@ -45,7 +46,7 @@ void setup() { int state = fsk.beginFSK(); // when using one of the non-LoRa modules for Morse code - // (RF69, CC1101, etc.), use the basic begin() method + // (RF69, CC1101, Si4432 etc.), use the basic begin() method // int state = fsk.begin(); if(state == ERR_NONE) { From 46e5f88bf106308a250b335696a8579152b8607c Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 17:39:47 +0200 Subject: [PATCH 034/334] [RTTY] Added note about Si443x support --- examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino b/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino index da77ea5b..d456b041 100644 --- a/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino +++ b/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino @@ -11,6 +11,7 @@ - CC1101 - SX126x - nRF24 + - Si443x/RFM2x For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ @@ -48,7 +49,7 @@ void setup() { int state = fsk.beginFSK(); // when using one of the non-LoRa modules for RTTY - // (RF69, CC1101, etc.), use the basic begin() method + // (RF69, CC1101, Si4432 etc.), use the basic begin() method // int state = fsk.begin(); if(state == ERR_NONE) { @@ -63,11 +64,12 @@ void setup() { // NOTE: RTTY frequency shift will be rounded // to the nearest multiple of frequency step size. // The exact value depends on the module: - // SX127x - 61 Hz + // SX127x/RFM9x - 61 Hz // RF69 - 61 Hz // CC1101 - 397 Hz // SX126x - 1 Hz // nRF24 - 1000000 Hz + // Si443x/RFM2x - 156 Hz Serial.print(F("[RTTY] Initializing ... ")); // low ("space") frequency: 434.0 MHz // frequency shift: 183 Hz From d58a4c008e6fcabcb6a26b2e927210dd4b302113 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 19:27:17 +0200 Subject: [PATCH 035/334] [nRF24] Using range check macro --- src/modules/nRF24/nRF24.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 7316f2f0..a05d52e3 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -225,14 +225,11 @@ int16_t nRF24::readData(uint8_t* data, size_t len) { } int16_t nRF24::setFrequency(int16_t freq) { - // check allowed range - if(!((freq >= 2400) && (freq <= 2525))) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 2400, 2525, ERR_INVALID_FREQUENCY); // set frequency uint8_t freqRaw = freq - 2400; - return _mod->SPIsetRegValue(NRF24_REG_RF_CH, freqRaw, 6, 0); + return(_mod->SPIsetRegValue(NRF24_REG_RF_CH, freqRaw, 6, 0)); } int16_t nRF24::setDataRate(int16_t dataRate) { @@ -420,7 +417,7 @@ int16_t nRF24::getStatus(uint8_t mask) { } bool nRF24::isCarrierDetected() { - return(_mod->SPIgetRegValue(NRF24_REG_RPD, 0,0)) == 1; + return(_mod->SPIgetRegValue(NRF24_REG_RPD, 0, 0) == 1); } int16_t nRF24::setFrequencyDeviation(float freqDev) { From 274b38d55618007c0848106e16b54f47c6bda679 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 19:29:29 +0200 Subject: [PATCH 036/334] [SX127x] Using range check macro --- src/modules/SX127x/SX1272.cpp | 5 +---- src/modules/SX127x/SX1276.cpp | 5 +---- src/modules/SX127x/SX1277.cpp | 5 +---- src/modules/SX127x/SX1278.cpp | 5 +---- src/modules/SX127x/SX1279.cpp | 5 +---- src/modules/SX127x/SX127x.cpp | 22 +++++----------------- 6 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 06646d1f..28fedba3 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -66,10 +66,7 @@ void SX1272::reset() { } int16_t SX1272::setFrequency(float freq) { - // check frequency range - if((freq < 860.0) || (freq > 1020.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 860.0, 1020.0, ERR_INVALID_FREQUENCY); // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); diff --git a/src/modules/SX127x/SX1276.cpp b/src/modules/SX127x/SX1276.cpp index 40a141a4..2fecd63a 100644 --- a/src/modules/SX127x/SX1276.cpp +++ b/src/modules/SX127x/SX1276.cpp @@ -35,10 +35,7 @@ int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync } int16_t SX1276::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 1020.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, ERR_INVALID_FREQUENCY); // SX1276/77/78 Errata fixes if(getActiveModem() == SX127X_LORA) { diff --git a/src/modules/SX127x/SX1277.cpp b/src/modules/SX127x/SX1277.cpp index bed5a84e..715d8853 100644 --- a/src/modules/SX127x/SX1277.cpp +++ b/src/modules/SX127x/SX1277.cpp @@ -35,10 +35,7 @@ int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync } int16_t SX1277::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 1020.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, ERR_INVALID_FREQUENCY); // SX1276/77/78 Errata fixes if(getActiveModem() == SX127X_LORA) { diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 5989aa13..af3fc0b3 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -61,10 +61,7 @@ void SX1278::reset() { } int16_t SX1278::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 525.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 525.0, ERR_INVALID_FREQUENCY); // SX1276/77/78 Errata fixes if(getActiveModem() == SX127X_LORA) { diff --git a/src/modules/SX127x/SX1279.cpp b/src/modules/SX127x/SX1279.cpp index 3468b0b1..1b45c9b7 100644 --- a/src/modules/SX127x/SX1279.cpp +++ b/src/modules/SX127x/SX1279.cpp @@ -35,10 +35,7 @@ int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync } int16_t SX1279::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 960.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 960.0, ERR_INVALID_FREQUENCY); // set frequency return(SX127x::setFrequencyRaw(freq)); diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 5eab0195..15053fd9 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -647,13 +647,9 @@ int16_t SX127x::setBitRate(float br) { // check allowed bit rate if(_ook) { - if((br < 1.2) || (br > 32.768)) { - return(ERR_INVALID_BIT_RATE); - } + RADIOLIB_CHECK_RANGE(br, 1.2, 32.768, ERR_INVALID_BIT_RATE); } else { - if((br < 1.2) || (br > 300.0)) { - return(ERR_INVALID_BIT_RATE); - } + RADIOLIB_CHECK_RANGE(br, 1.2, 300.0, ERR_INVALID_BIT_RATE); } // set mode to STANDBY @@ -701,10 +697,7 @@ int16_t SX127x::setRxBandwidth(float rxBw) { return(ERR_WRONG_MODEM); } - // check allowed bandwidth values - if(!((rxBw >= 2.6) && (rxBw <= 250.0))) { - return(ERR_INVALID_RX_BANDWIDTH); - } + RADIOLIB_CHECK_RANGE(rxBw, 2.6, 250.0, ERR_INVALID_RX_BANDWIDTH); // set mode to STANDBY int16_t state = setMode(SX127X_STANDBY); @@ -738,10 +731,7 @@ int16_t SX127x::setSyncWord(uint8_t* syncWord, size_t len) { return(ERR_WRONG_MODEM); } - // check constraints - if((len > 8) || (len < 1)) { - return(ERR_INVALID_SYNC_WORD); - } + RADIOLIB_CHECK_RANGE(len, 1, 8, ERR_INVALID_SYNC_WORD); // sync word must not contain value 0x00 for(uint8_t i = 0; i < len; i++) { @@ -887,9 +877,7 @@ int16_t SX127x::setRSSIConfig(uint8_t smoothingSamples, int8_t offset) { return(ERR_INVALID_NUM_SAMPLES); } - if(!((offset >= -16) && (offset <= 15))) { - return(ERR_INVALID_RSSI_OFFSET); - } + RADIOLIB_CHECK_RANGE(offset, -16, 15, ERR_INVALID_RSSI_OFFSET); // set new register values state = _mod->SPIsetRegValue(SX127X_REG_RSSI_CONFIG, offset, 7, 3); From 08e4c3b13be181e8ca82a254e51775d04660925e Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 19:29:55 +0200 Subject: [PATCH 037/334] [RFM9x] Using range check macro --- src/modules/RFM9x/RFM95.cpp | 5 +---- src/modules/RFM9x/RFM96.cpp | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp index 72df63c4..49557190 100644 --- a/src/modules/RFM9x/RFM95.cpp +++ b/src/modules/RFM9x/RFM95.cpp @@ -35,10 +35,7 @@ int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncW } int16_t RFM95::setFrequency(float freq) { - // check frequency range - if((freq < 868.0) || (freq > 915.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 868.0, 915.0, ERR_INVALID_FREQUENCY); // set frequency return(SX127x::setFrequencyRaw(freq)); diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp index 1e045536..cf81ca40 100644 --- a/src/modules/RFM9x/RFM96.cpp +++ b/src/modules/RFM9x/RFM96.cpp @@ -35,10 +35,7 @@ int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncW } int16_t RFM96::setFrequency(float freq) { - // check frequency range - if((freq < 433.0) || (freq > 470.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 433.0, 470.0, ERR_INVALID_FREQUENCY); // set frequency return(SX127x::setFrequencyRaw(freq)); From 7f083bb0837a8efa1836d5fef0858a835c32bd10 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 19:31:02 +0200 Subject: [PATCH 038/334] [SX126x] Using range check macro --- src/modules/SX126x/SX1261.cpp | 5 +---- src/modules/SX126x/SX1262.cpp | 10 ++-------- src/modules/SX126x/SX1268.cpp | 10 ++-------- src/modules/SX126x/SX126x.cpp | 37 ++++++++++++----------------------- 4 files changed, 17 insertions(+), 45 deletions(-) diff --git a/src/modules/SX126x/SX1261.cpp b/src/modules/SX126x/SX1261.cpp index dcf34fac..a78d2578 100644 --- a/src/modules/SX126x/SX1261.cpp +++ b/src/modules/SX126x/SX1261.cpp @@ -5,10 +5,7 @@ SX1261::SX1261(Module* mod): SX1262(mod) { } int16_t SX1261::setOutputPower(int8_t power) { - // check allowed power range - if (!((power >= -17) && (power <= 14))) { - return(ERR_INVALID_OUTPUT_POWER); - } + RADIOLIB_CHECK_RANGE(power, -17, 14, ERR_INVALID_OUTPUT_POWER); // get current OCP configuration uint8_t ocp = 0; diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 3a9d211a..7d1f6efe 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -39,10 +39,7 @@ int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t } int16_t SX1262::setFrequency(float freq, bool calibrate) { - // check frequency range - if((freq < 150.0) || (freq > 960.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, ERR_INVALID_FREQUENCY); int16_t state = ERR_NONE; @@ -74,10 +71,7 @@ int16_t SX1262::setFrequency(float freq, bool calibrate) { } int16_t SX1262::setOutputPower(int8_t power) { - // check allowed power range - if (!((power >= -17) && (power <= 22))) { - return(ERR_INVALID_OUTPUT_POWER); - } + RADIOLIB_CHECK_RANGE(power, -17, 22, ERR_INVALID_OUTPUT_POWER); // get current OCP configuration uint8_t ocp = 0; diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index b6daa489..6b7f3ad2 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -38,10 +38,7 @@ int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t } int16_t SX1268::setFrequency(float freq, bool calibrate) { - // check frequency range - if((freq < 410.0) || (freq > 810.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, ERR_INVALID_FREQUENCY); int16_t state = ERR_NONE; @@ -67,10 +64,7 @@ int16_t SX1268::setFrequency(float freq, bool calibrate) { } int16_t SX1268::setOutputPower(int8_t power) { - // check allowed power range - if(!((power >= -9) && (power <= 22))) { - return(ERR_INVALID_OUTPUT_POWER); - } + RADIOLIB_CHECK_RANGE(power, -9, 22, ERR_INVALID_OUTPUT_POWER); // get current OCP configuration uint8_t ocp = 0; diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 5754893f..93b98dc7 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -140,10 +140,10 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit state = setDio2AsRfSwitch(false); RADIOLIB_ASSERT(state); - if (useRegulatorLDO) { - state = setRegulatorLDO(); + if(useRegulatorLDO) { + state = setRegulatorLDO(); } else { - state = setRegulatorDCDC(); + state = setRegulatorDCDC(); } return(state); @@ -580,12 +580,10 @@ int16_t SX126x::setBandwidth(float bw) { return(ERR_WRONG_MODEM); } - // ensure byte conversion doesn't overflow: - if(!((bw > 0) && (bw < 510))) { - return(ERR_INVALID_BANDWIDTH); - } + // ensure byte conversion doesn't overflow + RADIOLIB_CHECK_RANGE(bw, 0.0, 510.0, ERR_INVALID_BANDWIDTH); - // check alowed bandwidth values + // check allowed bandwidth values uint8_t bw_div2 = bw / 2 + 0.01; switch (bw_div2) { case 3: // 7.8: @@ -633,10 +631,7 @@ int16_t SX126x::setSpreadingFactor(uint8_t sf) { return(ERR_WRONG_MODEM); } - // check allowed spreading factor values - if(!((sf >= 5) && (sf <= 12))) { - return(ERR_INVALID_SPREADING_FACTOR); - } + RADIOLIB_CHECK_RANGE(sf, 5, 12, ERR_INVALID_SPREADING_FACTOR); // update modulation parameters _sf = sf; @@ -649,10 +644,7 @@ int16_t SX126x::setCodingRate(uint8_t cr) { return(ERR_WRONG_MODEM); } - // check allowed spreading factor values - if(!((cr >= 5) && (cr <= 8))) { - return(ERR_INVALID_CODING_RATE); - } + RADIOLIB_CHECK_RANGE(cr, 5, 8, ERR_INVALID_CODING_RATE); // update modulation parameters _cr = cr - 4; @@ -711,10 +703,7 @@ int16_t SX126x::setFrequencyDeviation(float freqDev) { return(ERR_WRONG_MODEM); } - // check allowed frequency deviation values - if(!(freqDev <= 200.0)) { - return(ERR_INVALID_FREQUENCY_DEVIATION); - } + RADIOLIB_CHECK_RANGE(freqDev, 0.0, 200.0, ERR_INVALID_FREQUENCY_DEVIATION); // calculate raw frequency deviation value uint32_t freqDevRaw = (uint32_t)(((freqDev * 1000.0) * (float)((uint32_t)(1) << 25)) / (SX126X_CRYSTAL_FREQ * 1000000.0)); @@ -735,10 +724,7 @@ int16_t SX126x::setBitRate(float br) { return(ERR_WRONG_MODEM); } - // check allowed bit rate values - if(!((br >= 0.6) && (br <= 300.0))) { - return(ERR_INVALID_BIT_RATE); - } + RADIOLIB_CHECK_RANGE(br, 0.6, 300.0, ERR_INVALID_BIT_RATE); // calculate raw bit rate value uint32_t brRaw = (uint32_t)((SX126X_CRYSTAL_FREQ * 1000000.0 * 32.0) / (br * 1000.0)); @@ -1002,12 +988,13 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) { } int16_t state = ERR_NONE; - if(enabled != true) { + if(!enabled) { // disable whitening _whitening = SX126X_GFSK_WHITENING_OFF; state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType); RADIOLIB_ASSERT(state); + } else { // enable whitening _whitening = SX126X_GFSK_WHITENING_ON; From 532c1e6fe94eecbb7644de14db0b7ff9e16e73be Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 19:31:20 +0200 Subject: [PATCH 039/334] [RF69] Using range check macro --- src/modules/RF69/RF69.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 2ef86d4e..2e2eab0e 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -359,10 +359,7 @@ int16_t RF69::setFrequency(float freq) { } int16_t RF69::setBitRate(float br) { - // check allowed bitrate - if((br < 1.2) || (br > 300.0)) { - return(ERR_INVALID_BIT_RATE); - } + RADIOLIB_CHECK_RANGE(br, 1.2, 300.0, ERR_INVALID_BIT_RATE); // check bitrate-bandwidth ratio if(!(br < 2000 * _rxBw)) { @@ -496,10 +493,7 @@ int16_t RF69::setFrequencyDeviation(float freqDev) { } int16_t RF69::setOutputPower(int8_t power) { - // check output power range - if((power < -18) || (power > 17)) { - return(ERR_INVALID_OUTPUT_POWER); - } + RADIOLIB_CHECK_RANGE(power, -18, 17, ERR_INVALID_OUTPUT_POWER); // set mode to standby setMode(RF69_STANDBY); From 75b9395349ad53bd78901d64a115f3a64f5af968 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 30 Mar 2020 19:31:52 +0200 Subject: [PATCH 040/334] [CC1101] Using range check macro --- src/modules/CC1101/CC1101.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 823b6b27..f05fa32e 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -322,10 +322,7 @@ int16_t CC1101::setFrequency(float freq) { } int16_t CC1101::setBitRate(float br) { - // check allowed bit rate range - if(!((br >= 0.025) && (br <= 600.0))) { - return(ERR_INVALID_BIT_RATE); - } + RADIOLIB_CHECK_RANGE(br, 0.025, 600.0, ERR_INVALID_BIT_RATE); // set mode to standby SPIsendCommand(CC1101_CMD_IDLE); @@ -342,10 +339,7 @@ int16_t CC1101::setBitRate(float br) { } int16_t CC1101::setRxBandwidth(float rxBw) { - // check allowed bandwidth range - if(!((rxBw >= 58.0) && (rxBw <= 812.0))) { - return(ERR_INVALID_RX_BANDWIDTH); - } + RADIOLIB_CHECK_RANGE(rxBw, 58.0, 812.0, ERR_INVALID_RX_BANDWIDTH); // set mode to standby SPIsendCommand(CC1101_CMD_IDLE); @@ -372,10 +366,7 @@ int16_t CC1101::setFrequencyDeviation(float freqDev) { return(state); } - // check allowed frequency deviation range - if(!((freqDev >= 1.587) && (freqDev <= 380.8))) { - return(ERR_INVALID_FREQUENCY_DEVIATION); - } + RADIOLIB_CHECK_RANGE(freqDev, 1.587, 380.8, ERR_INVALID_FREQUENCY_DEVIATION); // set mode to standby SPIsendCommand(CC1101_CMD_IDLE); @@ -535,9 +526,7 @@ int16_t CC1101::setPreambleLength(uint8_t preambleLength) { int16_t CC1101::setNodeAddress(uint8_t nodeAddr, uint8_t numBroadcastAddrs) { - if(!(numBroadcastAddrs > 0) && (numBroadcastAddrs <= 2)) { - return(ERR_INVALID_NUM_BROAD_ADDRS); - } + RADIOLIB_CHECK_RANGE(numBroadcastAddrs, 1, 2, ERR_INVALID_NUM_BROAD_ADDRS); // enable address filtering int16_t state = SPIsetRegValue(CC1101_REG_PKTCTRL1, numBroadcastAddrs + 0x01, 1, 0); From c39c4f6b0d8ecfda140dd413cc656ee29f54ff9c Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 31 Mar 2020 17:31:10 +0200 Subject: [PATCH 041/334] [SSTV] Added SSTV support --- README.md | 1 + examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino | 160 +++++++++++ keywords.txt | 19 ++ src/RadioLib.h | 1 + src/protocols/SSTV/SSTV.cpp | 266 ++++++++++++++++++ src/protocols/SSTV/SSTV.h | 123 ++++++++ 6 files changed, 570 insertions(+) create mode 100644 examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino create mode 100644 src/protocols/SSTV/SSTV.cpp create mode 100644 src/protocols/SSTV/SSTV.h diff --git a/README.md b/README.md index 0a789d21..9f5e2dc0 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * __RTTY__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x * __Morse Code__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x * __AX.25__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x +* __SSTV__ for modules: SX127x, RFM9x, SX126x, RF69 and SX1231 ### Supported platforms: * __Arduino AVR__ - tested with hardware on Uno, Mega and Leonardo diff --git a/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino b/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino new file mode 100644 index 00000000..92bdde6f --- /dev/null +++ b/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino @@ -0,0 +1,160 @@ +/* + RadioLib SSTV Transmit Example + + The following example sends SSTV picture using + SX1278's FSK modem. + + Other modules that can be used for SSTV: + - SX127x/RFM9x + - RF69 + - SX1231 + - SX126x + + NOTE: SSTV is an analog modulation, and + requires precise frequency control. + Some of the above modules can only + set their frequency in rough steps, + so the result can be distorted. + Using high-precision radio with TCXO + (like SX126x) is recommended. + + NOTE: Some platforms (such as Arduino Uno) + might not be fast enough to correctly + send pictures via high-speed modes + like Scottie2 or Martin2. For those, + lower speed modes such as Wrasse, + Scottie1 or Martin1 are recommended. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1278 fsk = RadioShield.ModuleA; + +// create SSTV client instance using the FSK module +SSTVClient sstv(&fsk); + +// test "image" - actually just a single 320px line +// will be sent over and over again, to create vertical color stripes at the receiver +uint32_t line[320] = { + // black + 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, + 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, + + // blue + 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, + 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, + + // green + 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, + 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, + + // cyan + 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, + 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, + + // red + 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, + 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, + + // magenta + 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, + 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, + + // yellow + 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, + 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, + + // white + 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, + 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF +}; + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + // sync word: 0x2D 0x01 + int state = fsk.beginFSK(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // when using one of the non-LoRa modules for SSTV + // (RF69, SX1231 etc.), use the basic begin() method + // int state = fsk.begin(); + + // initialize SSTV client + Serial.print(F("[SSTV] Initializing ... ")); + // 0 Hz tone frequency: 434.0 MHz + // SSTV mode: Wrasse (SC2-180) + // correction factor: 0.95 + // NOTE: Due to different speeds of various platforms + // supported by RadioLib (Arduino Uno, ESP32 etc), + // and because SSTV is analog protocol, incorrect + // timing of pulses can lead to distortions. + // To compensate, correction factor can be used + // to adjust the length of timing pulses + // (lower number = shorter pulses). + // The value is usually around 0.95 (95%). + state = sstv.begin(434.0, Wrasse, 0.95); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // to help tune the receiver, SSTVClient can send + // continuous beep at the frequency corresponding to + // 1900 Hz in upper sideband (aka USB) modulation + // (SSTV header "leader tone") + /* + sstv.idle(); + while(true); + */ +} + +void loop() { + // send picture with 8 color stripes + Serial.print(F("[SSTV] Sending test picture ... ")); + + // send synchronization header first + sstv.sendHeader(); + + // send all picture lines + for(uint16_t i = 0; i < sstv.getPictureHeight(); i++) { + sstv.sendLine(line); + } + + // turn off transmitter + fsk.standby(); + + Serial.println(F("done!")); + + delay(30000); +} diff --git a/keywords.txt b/keywords.txt index bcf0f9fd..57b8b822 100644 --- a/keywords.txt +++ b/keywords.txt @@ -10,6 +10,7 @@ RadioLib KEYWORD1 RadioShield KEYWORD1 Module KEYWORD1 +# modules CC1101 KEYWORD1 ESP8266 KEYWORD1 HC05 KEYWORD1 @@ -39,6 +40,7 @@ SX1279 KEYWORD1 XBee KEYWORD1 XBeeSerial KEYWORD1 +# protocols MQTTClient KEYWORD1 HTTPClient KEYWORD1 RTTYClient KEYWORD1 @@ -46,6 +48,18 @@ MorseClient KEYWORD1 PagerClient KEYWORD1 AX25Client KEYWORD1 AX25Frame KEYWORD1 +SSTVClient KEYWORD1 + +# SSTV modes +Scottie1 KEYWORD1 +Scottie2 KEYWORD1 +ScottieDX KEYWORD1 +Martin1 KEYWORD1 +Martin2 KEYWORD1 +Wrasse KEYWORD1 +PasokonP3 KEYWORD1 +PasokonP5 KEYWORD1 +PasokonP7 KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -190,6 +204,11 @@ setRecvSequence KEYWORD2 setSendSequence KEYWORD2 sendFrame KEYWORD2 +# SSTV +sendHeader KEYWORD2 +sendLine KEYWORD2 +getPictureHeight KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### diff --git a/src/RadioLib.h b/src/RadioLib.h index 16947fbd..bb5e085e 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -75,6 +75,7 @@ #include "protocols/AX25/AX25.h" #include "protocols/Morse/Morse.h" #include "protocols/RTTY/RTTY.h" +#include "protocols/SSTV/SSTV.h" // transport layer protocols #include "protocols/TransportLayer/TransportLayer.h" diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp new file mode 100644 index 00000000..dfbeea30 --- /dev/null +++ b/src/protocols/SSTV/SSTV.cpp @@ -0,0 +1,266 @@ +#include "SSTV.h" + +const SSTVMode_t Scottie1 { + .visCode = SSTV_SCOTTIE_1, + .width = 320, + .height = 256, + .scanPixelLen = 432, + .numTones = 7, + .tones = { + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 9000, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 } + } +}; + +const SSTVMode_t Scottie2 { + .visCode = SSTV_SCOTTIE_2, + .width = 320, + .height = 256, + .scanPixelLen = 275, + .numTones = 7, + .tones = { + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 9000, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 } + } +}; + +const SSTVMode_t ScottieDX { + .visCode = SSTV_SCOTTIE_DX, + .width = 320, + .height = 256, + .scanPixelLen = 1080, + .numTones = 7, + .tones = { + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 9000, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 1500, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 } + } +}; + +const SSTVMode_t Martin1 { + .visCode = SSTV_MARTIN_1, + .width = 320, + .height = 256, + .scanPixelLen = 458, + .numTones = 8, + .tones = { + { .type = tone_t::GENERIC, .len = 4862, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 } + } +}; + +const SSTVMode_t Martin2 { + .visCode = SSTV_MARTIN_2, + .width = 320, + .height = 256, + .scanPixelLen = 229, + .numTones = 8, + .tones = { + { .type = tone_t::GENERIC, .len = 4862, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 572, .freq = 1500 } + } +}; + +const SSTVMode_t Wrasse { + .visCode = SSTV_WRASSE_SC2_180, + .width = 320, + .height = 256, + .scanPixelLen = 734, + .numTones = 5, + .tones = { + { .type = tone_t::GENERIC, .len = 5523, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 500, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 } + } +}; + +const SSTVMode_t PasokonP3 { + .visCode = SSTV_PASOKON_P3, + .width = 640, + .height = 496, + .scanPixelLen = 208, + .numTones = 7, + .tones = { + { .type = tone_t::GENERIC, .len = 5208, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 1042, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 1042, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 1042, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 } + } +}; + +const SSTVMode_t PasokonP5 { + .visCode = SSTV_PASOKON_P5, + .width = 640, + .height = 496, + .scanPixelLen = 312, + .numTones = 7, + .tones = { + { .type = tone_t::GENERIC, .len = 7813, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 1563, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 1563, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 1563, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 } + } +}; + +const SSTVMode_t PasokonP7 { + .visCode = SSTV_PASOKON_P7, + .width = 640, + .height = 496, + .scanPixelLen = 417, + .numTones = 7, + .tones = { + { .type = tone_t::GENERIC, .len = 10417, .freq = 1200 }, + { .type = tone_t::GENERIC, .len = 2083, .freq = 1500 }, + { .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 2083, .freq = 1500 }, + { .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 }, + { .type = tone_t::GENERIC, .len = 2083, .freq = 1500 }, + { .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 } + } +}; + +SSTVClient::SSTVClient(PhysicalLayer* phy) { + _phy = phy; +} + +int16_t SSTVClient::begin(float base, SSTVMode_t mode, float correction) { + // save mode + _mode = mode; + + // apply correction factor to all timings + _mode.scanPixelLen *= correction; + for(uint8_t i = 0; i < _mode.numTones; i++) { + _mode.tones[i].len *= correction; + } + + // calculate 24-bit frequency + _base = (base * 1000000.0) / _phy->getFreqStep(); + + // set module frequency deviation to 0 + int16_t state = _phy->setFrequencyDeviation(0); + + return(state); +} + +void SSTVClient::idle() { + tone(SSTV_TONE_LEADER); +} + +void SSTVClient::sendHeader() { + // save first header flag for Scottie modes + _firstLine = true; + + // send the first part of header (leader-break-leader) + tone(SSTV_TONE_LEADER, SSTV_HEADER_LEADER_LENGTH); + tone(SSTV_TONE_BREAK, SSTV_HEADER_BREAK_LENGTH); + tone(SSTV_TONE_LEADER, SSTV_HEADER_LEADER_LENGTH); + + // VIS start bit + tone(SSTV_TONE_BREAK, SSTV_HEADER_BIT_LENGTH); + + // VIS code + uint8_t parityCount = 0; + for(uint8_t mask = 0x01; mask < 0x80; mask <<= 1) { + if(_mode.visCode & mask) { + tone(SSTV_TONE_VIS_1, SSTV_HEADER_BIT_LENGTH); + parityCount++; + } else { + tone(SSTV_TONE_VIS_0, SSTV_HEADER_BIT_LENGTH); + } + } + + // VIS parity + if(parityCount % 2 == 0) { + // even parity + tone(SSTV_TONE_VIS_0, SSTV_HEADER_BIT_LENGTH); + } else { + // odd parity + tone(SSTV_TONE_VIS_1, SSTV_HEADER_BIT_LENGTH); + } + + // VIS stop bit + tone(SSTV_TONE_BREAK, SSTV_HEADER_BIT_LENGTH); +} + +void SSTVClient::sendLine(uint32_t* imgLine) { + // check first line flag in Scottie modes + if(_firstLine && ((_mode.visCode == SSTV_SCOTTIE_1) || (_mode.visCode == SSTV_SCOTTIE_2) || (_mode.visCode == SSTV_SCOTTIE_DX))) { + _firstLine = false; + + // send start sync tone + tone(SSTV_TONE_BREAK, 9000); + } + + // send all tones in sequence + for(uint8_t i = 0; i < _mode.numTones; i++) { + if((_mode.tones[i].type == tone_t::GENERIC) && (_mode.tones[i].len > 0)) { + // sync/porch tones + tone(_mode.tones[i].freq, _mode.tones[i].len); + } else { + // scan lines + for(uint16_t j = 0; j < _mode.width; j++) { + uint32_t color = imgLine[j]; + switch(_mode.tones[i].type) { + case(tone_t::SCAN_RED): + color &= 0x00FF0000; + color >>= 16; + break; + case(tone_t::SCAN_GREEN): + color &= 0x0000FF00; + color >>= 8; + break; + case(tone_t::SCAN_BLUE): + color &= 0x000000FF; + break; + case(tone_t::GENERIC): + break; + } + tone(SSTV_TONE_BRIGHTNESS_MIN + ((float)color * 3.1372549), _mode.scanPixelLen); + } + } + } +} + +uint16_t SSTVClient::getPictureHeight() { + return(_mode.height); +} + +void SSTVClient::tone(float freq, uint32_t len) { + uint32_t start = micros(); + _phy->transmitDirect(_base + (freq / _phy->getFreqStep())); + while(micros() - start < len); +} diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h new file mode 100644 index 00000000..8242d674 --- /dev/null +++ b/src/protocols/SSTV/SSTV.h @@ -0,0 +1,123 @@ +#ifndef _RADIOLIB_SSTV_H +#define _RADIOLIB_SSTV_H + +#include "../../TypeDef.h" +#include "../PhysicalLayer/PhysicalLayer.h" + +// the following implementation is based on information from +// http://www.barberdsp.com/downloads/Dayton%20Paper.pdf + +// VIS codes +#define SSTV_SCOTTIE_1 60 +#define SSTV_SCOTTIE_2 56 +#define SSTV_SCOTTIE_DX 76 +#define SSTV_MARTIN_1 44 +#define SSTV_MARTIN_2 40 +#define SSTV_WRASSE_SC2_180 55 +#define SSTV_PASOKON_P3 113 +#define SSTV_PASOKON_P5 114 +#define SSTV_PASOKON_P7 115 + +// SSTV tones in Hz +#define SSTV_TONE_LEADER 1900 +#define SSTV_TONE_BREAK 1200 +#define SSTV_TONE_VIS_1 1100 +#define SSTV_TONE_VIS_0 1300 +#define SSTV_TONE_BRIGHTNESS_MIN 1500 +#define SSTV_TONE_BRIGHTNESS_MAX 2300 + +// calibration header timing in us +#define SSTV_HEADER_LEADER_LENGTH 300000 +#define SSTV_HEADER_BREAK_LENGTH 10000 +#define SSTV_HEADER_BIT_LENGTH 30000 + +// structure to save data about tone +struct tone_t { + enum { + GENERIC = 0, + SCAN_GREEN, + SCAN_BLUE, + SCAN_RED + } type; + uint32_t len; + uint16_t freq; +}; + +// structure to save data about SSTV mode +struct SSTVMode_t { + uint8_t visCode; + uint16_t width; + uint16_t height; + uint16_t scanPixelLen; + uint8_t numTones; + tone_t tones[8]; +}; + +// all currently supported SSTV modes +extern const SSTVMode_t Scottie1; +extern const SSTVMode_t Scottie2; +extern const SSTVMode_t ScottieDX; +extern const SSTVMode_t Martin1; +extern const SSTVMode_t Martin2; +extern const SSTVMode_t Wrasse; +extern const SSTVMode_t PasokonP3; +extern const SSTVMode_t PasokonP5; +extern const SSTVMode_t PasokonP7; + +class SSTVClient { + public: + /*! + \brief Default constructor. + + \param phy Pointer to the wireless module providing PhysicalLayer communication. + */ + SSTVClient(PhysicalLayer* phy); + + // basic methods + + /*! + \brief Initialization method. + + \param base Base RF frequency to be used in MHz. In USB modulation, this corresponds to "0 Hz tone". + + \param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7. + */ + int16_t begin(float base, SSTVMode_t mode, float correction = 1.0); + + /*! + \brief Sends out tone at 1900 Hz. + */ + void idle(); + + /*! + \brief Sends synchronization header for the SSTV mode set in begin method. + */ + void sendHeader(); + + /*! + \brief Sends single picture line in the currently configured SSTV mode. + + \param imgLine Image line to send, in 24-bit RGB. It is up to the user to ensure that imgLine has enough pixels to send it in the current SSTV mode. + */ + void sendLine(uint32_t* imgLine); + + /*! + \brief Get picture height of the currently configured SSTV mode. + + \returns Picture height of the currently configured SSTV mode in pixels. + */ + uint16_t getPictureHeight(); + +#ifndef RADIOLIB_GODMODE + private: +#endif + PhysicalLayer* _phy; + + uint32_t _base; + SSTVMode_t _mode; + bool _firstLine; + + void tone(float freq, uint32_t len = 0); +}; + +#endif From b731b60852bc2157292d10e1d1581ebc2904afa0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 31 Mar 2020 18:02:51 +0200 Subject: [PATCH 042/334] [SSTV] Added missing Doxygen comments --- src/RadioLib.h | 1 + src/protocols/SSTV/SSTV.h | 53 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/RadioLib.h b/src/RadioLib.h index bb5e085e..eea7044d 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -20,6 +20,7 @@ - RTTY (RTTYClient) - Morse Code (MorseClient) - AX.25 (AX25Client) + - SSTV (SSTVClient) - TransportLayer protocols - HTTP (HTTPClient) - MQTT (MQTTClient) diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h index 8242d674..d8dc0c8b 100644 --- a/src/protocols/SSTV/SSTV.h +++ b/src/protocols/SSTV/SSTV.h @@ -31,25 +31,69 @@ #define SSTV_HEADER_BREAK_LENGTH 10000 #define SSTV_HEADER_BIT_LENGTH 30000 -// structure to save data about tone +/*! + \struct tone_t + + \brief Structure to save data about tone. +*/ struct tone_t { + + /*! + \brief Tone type: GENERIC for sync and porch tones, SCAN_GREEN, SCAN_BLUE and SCAN_RED for scan lines. + */ enum { GENERIC = 0, SCAN_GREEN, SCAN_BLUE, SCAN_RED } type; + + /*! + \brief Length of tone in us, set to 0 for picture scan tones. + */ uint32_t len; + + /*! + \brief Frequency of tone in Hz, set to 0 for picture scan tones. + */ uint16_t freq; }; -// structure to save data about SSTV mode +/*! + \struct SSTVMode_t + + \brief Structure to save data about supported SSTV modes. +*/ struct SSTVMode_t { + + /*! + \brief Unique VIS code of the SSTV mode. + */ uint8_t visCode; + + /*! + \brief Picture width in pixels. + */ uint16_t width; + + /*! + \brief Picture height in pixels. + */ uint16_t height; + + /*! + \brief Pixel scan length in us. + */ uint16_t scanPixelLen; + + /*! + \brief Number of tones in each transmission line. Picture scan data is considered single tone. + */ uint8_t numTones; + + /*! + \brief Sequence of tones in each transmission line. This is used to create the correct encoding sequence. + */ tone_t tones[8]; }; @@ -64,6 +108,11 @@ extern const SSTVMode_t PasokonP3; extern const SSTVMode_t PasokonP5; extern const SSTVMode_t PasokonP7; +/*! + \class SSTVClient + + \brief Client for SSTV transmissions. +*/ class SSTVClient { public: /*! From 9c0cd464d1dcd20148a5054decc64c6cf4253789 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 10:49:45 +0200 Subject: [PATCH 043/334] Moved unsupported platform warning to RadioLib.h to only show it once --- src/BuildOpt.h | 2 +- src/RadioLib.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 2112e21a..063a8e05 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -116,7 +116,7 @@ #else // other platforms not covered by the above list - this may or may not work - #warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!" + #define RADIOLIB_UNKNOWN_PLATFORM #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t diff --git a/src/RadioLib.h b/src/RadioLib.h index eea7044d..ae4a6909 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -41,10 +41,18 @@ #include "TypeDef.h" #include "Module.h" +// warnings are printed in this file since BuildOpt.h is compiled in multiple places + +// check God mode #ifdef RADIOLIB_GODMODE #warning "God mode active, I hope it was intentional. Buckle up, lads." #endif +// check unknown/unsupported platform +#ifdef RADIOLIB_UNKNOWN_PLATFORM + #warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!" +#endif + #include "modules/CC1101/CC1101.h" #include "modules/ESP8266/ESP8266.h" #include "modules/HC05/HC05.h" From 7fec5e629b50fbc54d170b258e9a6a5aadd1b9ed Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:01:02 +0200 Subject: [PATCH 044/334] [ESP8266] Added missing calls to yield --- src/modules/ESP8266/ESP8266.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index b221d0ff..1aa959a9 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -195,6 +195,7 @@ size_t ESP8266::receive(uint8_t* data, size_t len, uint32_t timeout) { // wait until the required number of bytes is received or until timeout while((millis() - start < timeout) && (i < len)) { + yield(); while(_mod->ModuleSerial->available() > 0) { uint8_t b = _mod->ModuleSerial->read(); RADIOLIB_DEBUG_PRINT(b); @@ -209,6 +210,7 @@ size_t ESP8266::getNumBytes(uint32_t timeout, size_t minBytes) { // wait for available data uint32_t start = millis(); while(_mod->ModuleSerial->available() < (int16_t)minBytes) { + yield(); if(millis() - start >= timeout) { return(0); } @@ -219,6 +221,7 @@ size_t ESP8266::getNumBytes(uint32_t timeout, size_t minBytes) { uint8_t i = 0; start = millis(); while(_mod->ModuleSerial->available() > 0) { + yield(); char c = _mod->ModuleSerial->read(); rawStr[i++] = c; if(c == ':') { From 901783cf3948917f964d9800147053ae88cf8380 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:01:18 +0200 Subject: [PATCH 045/334] [RF69] Added missing calls to yield --- src/modules/RF69/RF69.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 2e2eab0e..c9e9fa90 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -117,6 +117,8 @@ int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for transmission end or timeout uint32_t start = micros(); while(!digitalRead(_mod->getIrq())) { + yield(); + if(micros() - start > timeout) { standby(); clearIRQFlags(); @@ -144,6 +146,8 @@ int16_t RF69::receive(uint8_t* data, size_t len) { // wait for packet reception or timeout uint32_t start = micros(); while(!digitalRead(_mod->getIrq())) { + yield(); + if(micros() - start > timeout) { standby(); clearIRQFlags(); From a46a1f5f1c10303620fa028db88e87421c6c19f1 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:01:27 +0200 Subject: [PATCH 046/334] [SX126x] Added missing calls to yield --- src/modules/SX126x/SX126x.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 93b98dc7..1fdf6cc7 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -219,6 +219,7 @@ int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for packet transmission or timeout uint32_t start = micros(); while(!digitalRead(_mod->getIrq())) { + yield(); if(micros() - start > timeout) { clearIrqStatus(); standby(); @@ -278,6 +279,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { // wait for packet reception or timeout uint32_t start = micros(); while(!digitalRead(_mod->getIrq())) { + yield(); if(micros() - start > timeout) { fixImplicitTimeout(); clearIrqStatus(); @@ -1516,6 +1518,7 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d // ensure BUSY is low (state machine ready) uint32_t start = millis(); while(digitalRead(_mod->getGpio())) { + yield(); if(millis() - start >= timeout) { return(ERR_SPI_CMD_TIMEOUT); } @@ -1583,6 +1586,7 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d delayMicroseconds(1); start = millis(); while(digitalRead(_mod->getGpio())) { + yield(); if(millis() - start >= timeout) { status = SX126X_STATUS_CMD_TIMEOUT; break; From 218587b887f34c8aa6d91b761c970e4b64e82ab9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:01:41 +0200 Subject: [PATCH 047/334] [SX127x] Added missing calls to yield --- src/modules/SX127x/SX127x.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 15053fd9..727cf2b1 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -144,6 +144,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for packet transmission or timeout start = micros(); while(!digitalRead(_mod->getIrq())) { + yield(); if(micros() - start > timeout) { clearIRQFlags(); return(ERR_TX_TIMEOUT); @@ -161,6 +162,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for transmission end or timeout start = micros(); while(!digitalRead(_mod->getIrq())) { + yield(); if(micros() - start > timeout) { clearIRQFlags(); standby(); @@ -194,6 +196,7 @@ int16_t SX127x::receive(uint8_t* data, size_t len) { // wait for packet reception or timeout (100 LoRa symbols) while(!digitalRead(_mod->getIrq())) { + yield(); if(digitalRead(_mod->getGpio())) { clearIRQFlags(); return(ERR_RX_TIMEOUT); @@ -211,6 +214,7 @@ int16_t SX127x::receive(uint8_t* data, size_t len) { // wait for packet reception or timeout uint32_t start = micros(); while(!digitalRead(_mod->getIrq())) { + yield(); if(micros() - start > timeout) { clearIRQFlags(); return(ERR_RX_TIMEOUT); @@ -247,6 +251,7 @@ int16_t SX127x::scanChannel() { // wait for channel activity detected or timeout while(!digitalRead(_mod->getIrq())) { + yield(); if(digitalRead(_mod->getGpio())) { clearIRQFlags(); return(PREAMBLE_DETECTED); From a7c4dd44ce14930c1f90ce2e24fd491c81481aa1 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:01:49 +0200 Subject: [PATCH 048/334] [Si443x] Added missing calls to yield --- src/modules/Si443x/Si443x.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 6cfc6ffd..13af7747 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -74,6 +74,7 @@ int16_t Si443x::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for transmission end or timeout uint32_t start = micros(); while(digitalRead(_mod->getIrq())) { + yield(); if(micros() - start > timeout) { standby(); clearIRQFlags(); From eb71582a96ee4bd5abb99914bf762358e2658579 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:01:57 +0200 Subject: [PATCH 049/334] [XBee] Added missing calls to yield --- src/modules/XBee/XBee.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/XBee/XBee.cpp b/src/modules/XBee/XBee.cpp index cefc7dff..aa365ea3 100644 --- a/src/modules/XBee/XBee.cpp +++ b/src/modules/XBee/XBee.cpp @@ -405,6 +405,7 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) { // wait until all response bytes are available (5s timeout) uint32_t start = millis(); while(_mod->ModuleSerial->available() < (int16_t)numBytes) { + yield(); if(millis() - start >= timeout/2) { return(ERR_FRAME_MALFORMED); } @@ -456,6 +457,7 @@ uint16_t XBee::getNumBytes(uint32_t timeout, size_t minBytes) { // wait for available data uint32_t start = millis(); while((size_t)_mod->ModuleSerial->available() < minBytes) { + yield(); if(millis() - start >= timeout) { return(0); } @@ -466,6 +468,7 @@ uint16_t XBee::getNumBytes(uint32_t timeout, size_t minBytes) { uint8_t i = 0; RADIOLIB_DEBUG_PRINT(F("reading frame length: ")); while(_mod->ModuleSerial->available() > 0) { + yield(); uint8_t b = _mod->ModuleSerial->read(); RADIOLIB_DEBUG_PRINT(b, HEX); RADIOLIB_DEBUG_PRINT('\t'); From 6a4fdd9a9207f5c630d932c86e603acd2f002637 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:02:06 +0200 Subject: [PATCH 050/334] [nRF24] Added missing calls to yield --- src/modules/nRF24/nRF24.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index a05d52e3..ab6cc6b6 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -72,6 +72,8 @@ int16_t nRF24::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait until transmission is finished uint32_t start = micros(); while(digitalRead(_mod->getIrq())) { + yield(); + // check maximum number of retransmits if(getStatus(NRF24_MAX_RT)) { standby(); @@ -101,6 +103,8 @@ int16_t nRF24::receive(uint8_t* data, size_t len) { // wait for Rx_DataReady or timeout uint32_t start = micros(); while(digitalRead(_mod->getIrq())) { + yield(); + // check timeout: 15 retries * 4ms (max Tx time as per datasheet) if(micros() - start >= 60000) { standby(); From 87014929596b5600ba417ae03efbdefb5084493a Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:02:16 +0200 Subject: [PATCH 051/334] [RTTY] Added missing calls to yield --- src/protocols/RTTY/RTTY.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index c5eebe6c..085d3794 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -392,13 +392,17 @@ size_t RTTYClient::println(double d, int digits) { void RTTYClient::mark() { uint32_t start = micros(); _phy->transmitDirect(_base + _shift); - while(micros() - start < _bitDuration); + while(micros() - start < _bitDuration) { + yield(); + } } void RTTYClient::space() { uint32_t start = micros(); _phy->transmitDirect(_base); - while(micros() - start < _bitDuration); + while(micros() - start < _bitDuration) { + yield(); + } } size_t RTTYClient::printNumber(unsigned long n, uint8_t base) { From 34559fdee3a174a6a4c2c1469efe9802cf6e803c Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 1 Apr 2020 14:02:25 +0200 Subject: [PATCH 052/334] [SSTV] Added missing calls to yield --- src/protocols/SSTV/SSTV.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp index dfbeea30..c3843ad8 100644 --- a/src/protocols/SSTV/SSTV.cpp +++ b/src/protocols/SSTV/SSTV.cpp @@ -262,5 +262,7 @@ uint16_t SSTVClient::getPictureHeight() { void SSTVClient::tone(float freq, uint32_t len) { uint32_t start = micros(); _phy->transmitDirect(_base + (freq / _phy->getFreqStep())); - while(micros() - start < len); + while(micros() - start < len) { + yield(); + } } From cc903453423468b842f3027599d37bab7064fe87 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 7 Apr 2020 13:27:55 +0200 Subject: [PATCH 053/334] [SX126x] Minor formatting fixes --- src/modules/SX126x/SX126x.cpp | 29 +++++++++++++---------------- src/modules/SX126x/SX126x.h | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 1fdf6cc7..685163cf 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -78,6 +78,7 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); + Module::pinMode(_mod->getGpio(), INPUT); // initialize configuration variables (will be overwritten during public settings configuration) _br = 21333; // 48.0 kbps @@ -553,7 +554,6 @@ int16_t SX126x::readData(uint8_t* data, size_t len) { uint16_t irq = getIrqStatus(); int16_t crcState = ERR_NONE; if((irq & SX126X_IRQ_CRC_ERR) || (irq & SX126X_IRQ_HEADER_ERR)) { - clearIrqStatus(); crcState = ERR_CRC_MISMATCH; } @@ -1171,12 +1171,12 @@ int16_t SX126x::setDio2AsRfSwitch(bool enable) { } int16_t SX126x::setTx(uint32_t timeout) { - uint8_t data[3] = {(uint8_t)((timeout >> 16) & 0xFF), (uint8_t)((timeout >> 8) & 0xFF), (uint8_t)(timeout & 0xFF)}; + uint8_t data[] = { (uint8_t)((timeout >> 16) & 0xFF), (uint8_t)((timeout >> 8) & 0xFF), (uint8_t)(timeout & 0xFF)} ; return(SPIwriteCommand(SX126X_CMD_SET_TX, data, 3)); } int16_t SX126x::setRx(uint32_t timeout) { - uint8_t data[3] = {(uint8_t)((timeout >> 16) & 0xFF), (uint8_t)((timeout >> 8) & 0xFF), (uint8_t)(timeout & 0xFF)}; + uint8_t data[] = { (uint8_t)((timeout >> 16) & 0xFF), (uint8_t)((timeout >> 8) & 0xFF), (uint8_t)(timeout & 0xFF) }; return(SPIwriteCommand(SX126X_CMD_SET_RX, data, 3)); } @@ -1185,32 +1185,28 @@ int16_t SX126x::setCad() { } int16_t SX126x::setPaConfig(uint8_t paDutyCycle, uint8_t deviceSel, uint8_t hpMax, uint8_t paLut) { - uint8_t data[4] = {paDutyCycle, hpMax, deviceSel, paLut}; + uint8_t data[] = { paDutyCycle, hpMax, deviceSel, paLut }; return(SPIwriteCommand(SX126X_CMD_SET_PA_CONFIG, data, 4)); } int16_t SX126x::writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes) { uint8_t cmd[] = { SX126X_CMD_WRITE_REGISTER, (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; - int16_t state = SPIwriteCommand(cmd, 3, data, numBytes); - return(state); + return(SPIwriteCommand(cmd, 3, data, numBytes)); } int16_t SX126x::readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes) { - uint8_t cmd[] = {SX126X_CMD_READ_REGISTER, (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF)}; + uint8_t cmd[] = { SX126X_CMD_READ_REGISTER, (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; return(SX126x::SPItransfer(cmd, 3, false, NULL, data, numBytes, true)); } int16_t SX126x::writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset) { uint8_t cmd[] = { SX126X_CMD_WRITE_BUFFER, offset }; - int16_t state = SPIwriteCommand(cmd, 2, data, numBytes); - - return(state); + return(SPIwriteCommand(cmd, 2, data, numBytes)); } int16_t SX126x::readBuffer(uint8_t* data, uint8_t numBytes) { uint8_t cmd[] = { SX126X_CMD_READ_BUFFER, SX126X_CMD_NOP }; - int16_t state = SPIreadCommand(cmd, 2, data, numBytes); - return(state); + return(SPIreadCommand(cmd, 2, data, numBytes)); } int16_t SX126x::setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask) { @@ -1222,18 +1218,18 @@ int16_t SX126x::setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t di } uint16_t SX126x::getIrqStatus() { - uint8_t data[2] = {0, 0};; + uint8_t data[] = { 0x00, 0x00 }; SPIreadCommand(SX126X_CMD_GET_IRQ_STATUS, data, 2); return(((uint16_t)(data[0]) << 8) | data[1]); } int16_t SX126x::clearIrqStatus(uint16_t clearIrqParams) { - uint8_t data[2] = {(uint8_t)((clearIrqParams >> 8) & 0xFF), (uint8_t)(clearIrqParams & 0xFF)}; + uint8_t data[] = { (uint8_t)((clearIrqParams >> 8) & 0xFF), (uint8_t)(clearIrqParams & 0xFF) }; return(SPIwriteCommand(SX126X_CMD_CLEAR_IRQ_STATUS, data, 2)); } int16_t SX126x::setRfFrequency(uint32_t frf) { - uint8_t data[4] = {(uint8_t)((frf >> 24) & 0xFF), (uint8_t)((frf >> 16) & 0xFF), (uint8_t)((frf >> 8) & 0xFF), (uint8_t)(frf & 0xFF)}; + uint8_t data[] = { (uint8_t)((frf >> 24) & 0xFF), (uint8_t)((frf >> 16) & 0xFF), (uint8_t)((frf >> 8) & 0xFF), (uint8_t)(frf & 0xFF) }; return(SPIwriteCommand(SX126X_CMD_SET_RF_FREQUENCY, data, 4)); } @@ -1248,7 +1244,7 @@ uint8_t SX126x::getPacketType() { } int16_t SX126x::setTxParams(uint8_t power, uint8_t rampTime) { - uint8_t data[2] = {power, rampTime}; + uint8_t data[] = { power, rampTime }; return(SPIwriteCommand(SX126X_CMD_SET_TX_PARAMS, data, 2)); } @@ -1520,6 +1516,7 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d while(digitalRead(_mod->getGpio())) { yield(); if(millis() - start >= timeout) { + digitalWrite(_mod->getCs(), HIGH); return(ERR_SPI_CMD_TIMEOUT); } } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 1b9ce54f..e6a7f078 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -106,7 +106,7 @@ // SX126X SPI command variables -//SX126X_CMD_SET_SLEEP +//SX126X_CMD_SET_SLEEP MSB LSB DESCRIPTION #define SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default) #define SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained #define SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled @@ -768,7 +768,7 @@ class SX126x: public PhysicalLayer { */ float getSNR(); - /*! + /*! \brief Query modem for the packet length of received payload. \param update Update received packet length. Will return cached value when set to false. @@ -786,7 +786,7 @@ class SX126x: public PhysicalLayer { */ int16_t fixedPacketLengthMode(uint8_t len = SX126X_MAX_PACKET_LENGTH); - /*! + /*! \brief Set modem in variable packet length mode. Available in FSK mode only. \param len Maximum packet length. @@ -795,7 +795,7 @@ class SX126x: public PhysicalLayer { */ int16_t variablePacketLengthMode(uint8_t maxLen = SX126X_MAX_PACKET_LENGTH); - /*! + /*! \brief Get expected time-on-air for a given size of payload \param len Payload length in bytes. @@ -804,14 +804,14 @@ class SX126x: public PhysicalLayer { */ uint32_t getTimeOnAir(size_t len); - /*! + /*! \brief Set implicit header mode for future reception/transmission. \returns \ref status_codes */ int16_t implicitHeader(size_t len); - /*! + /*! \brief Set explicit header mode for future reception/transmission. \param len Payload length in bytes. @@ -821,17 +821,17 @@ class SX126x: public PhysicalLayer { int16_t explicitHeader(); /*! - \brief Set regulator mode to LDO. + \brief Set regulator mode to LDO. - \returns \ref status_codes - */ + \returns \ref status_codes + */ int16_t setRegulatorLDO(); /*! - \brief Set regulator mode to DC-DC. + \brief Set regulator mode to DC-DC. - \returns \ref status_codes - */ + \returns \ref status_codes + */ int16_t setRegulatorDCDC(); /*! @@ -846,7 +846,7 @@ class SX126x: public PhysicalLayer { #ifndef RADIOLIB_GODMODE protected: #endif - // SX1276x SPI command implementations + // SX126x SPI command implementations int16_t setTx(uint32_t timeout = 0); int16_t setRx(uint32_t timeout); int16_t setCad(); From 55ad72e0e0f9e92440899a70f4fd3fb7b0b95cb0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 7 Apr 2020 13:30:05 +0200 Subject: [PATCH 054/334] [SX128x] Added support for SX128x --- .../SX128x_Channel_Activity_Detection.ino | 72 + .../SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino | 116 ++ .../SX128x/SX128x_Receive/SX128x_Receive.ino | 106 ++ .../SX128x_Receive_Interrupt.ino | 159 +++ .../SX128x_Settings/SX128x_Settings.ino | 134 ++ .../SX128x_Transmit/SX128x_Transmit.ino | 85 ++ .../SX128x_Transmit_Interrupt.ino | 135 ++ keywords.txt | 6 + src/RadioLib.h | 5 +- src/modules/SX128x/SX1280.cpp | 5 + src/modules/SX128x/SX1280.h | 31 + src/modules/SX128x/SX1281.cpp | 5 + src/modules/SX128x/SX1281.h | 28 + src/modules/SX128x/SX1282.cpp | 5 + src/modules/SX128x/SX1282.h | 31 + src/modules/SX128x/SX128x.cpp | 1208 +++++++++++++++++ src/modules/SX128x/SX128x.h | 748 ++++++++++ 17 files changed, 2878 insertions(+), 1 deletion(-) create mode 100644 examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino create mode 100644 examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino create mode 100644 examples/SX128x/SX128x_Receive/SX128x_Receive.ino create mode 100644 examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino create mode 100644 examples/SX128x/SX128x_Settings/SX128x_Settings.ino create mode 100644 examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino create mode 100644 examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino create mode 100644 src/modules/SX128x/SX1280.cpp create mode 100644 src/modules/SX128x/SX1280.h create mode 100644 src/modules/SX128x/SX1281.cpp create mode 100644 src/modules/SX128x/SX1281.h create mode 100644 src/modules/SX128x/SX1282.cpp create mode 100644 src/modules/SX128x/SX1282.h create mode 100644 src/modules/SX128x/SX128x.cpp create mode 100644 src/modules/SX128x/SX128x.h diff --git a/examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino b/examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino new file mode 100644 index 00000000..6ec30377 --- /dev/null +++ b/examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino @@ -0,0 +1,72 @@ +/* + RadioLib SX128x Channel Activity Detection Example + + This example uses SX1280 to scan the current LoRa + channel and detect ongoing LoRa transmissions. + + Other modules from SX128x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 lora = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 lora = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bandwidth: 812.5 kHz + // spreading factor: 9 + // coding rate: 7 + // output power: 10 dBm + // preamble length: 12 symbols + // CRC: enabled + int state = lora.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } +} + +void loop() { + Serial.print(F("[SX1280] Scanning channel for LoRa transmission ... ")); + + // start scanning current channel + int state = lora.scanChannel(); + + if (state == LORA_DETECTED) { + // LoRa preamble was detected + Serial.println(F("detected!")); + + } else if (state == CHANNEL_FREE) { + // no preamble was detected, channel is free + Serial.println(F("channel is free!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } + + // wait 100 ms before new scan + delay(100); +} diff --git a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino new file mode 100644 index 00000000..9b93c481 --- /dev/null +++ b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino @@ -0,0 +1,116 @@ +/* + RadioLib SX128x GFSK Modem Example + + This example shows how to use GFSK modem in SX128x chips. + + NOTE: The sketch below is just a guide on how to use + GFSK modem, so this code should not be run directly! + Instead, modify the other examples to use GFSK + modem and use the appropriate configuration + methods. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 gfsk = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 lora = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bit rate: 800 kbps + // frequency deviation: 400.0 kHz + // output power: 10 dBm + // preamble length: 16 bits + // coding rate: 7 + // data shaping: Gaussian, BT = 0.5 + // sync word: 0x2D 0x01 + // CRC: enabled, CRC16 (CCIT) + int state = gfsk.beginGFSK(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // if needed, you can switch between LoRa and FSK modes + // + // gfsk.begin() start LoRa mode (and disable GFSK) + // lora.beginGFSK() start GFSK mode (and disable LoRa) + + // the following settings can also + // be modified at run-time + state = gfsk.setFrequency(2410.5); + state = gfsk.setBitRate(200); + state = gfsk.setFrequencyDeviation(100.0); + state = gfsk.setRxBandwidth(250.0); + state = gfsk.setOutputPower(5); + state = gfsk.setDataShaping(1.0); + uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89}; + state = gfsk.setSyncWord(syncWord, 5); + if (state != ERR_NONE) { + Serial.print(F("Unable to set configuration, code ")); + Serial.println(state); + while (true); + } + + #warning "This sketch is just an API guide! Read the note at line 6." +} + +void loop() { + // GFSK modem can use the same transmit/receive methods + // as the LoRa modem, even their interrupt-driven versions + + // transmit GFSK packet + int state = gfsk.transmit("Hello World!"); + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + int state = gfsk.transmit(byteArr, 8); + */ + if (state == ERR_NONE) { + Serial.println(F("[SX1280] Packet transmitted successfully!")); + } else if (state == ERR_PACKET_TOO_LONG) { + Serial.println(F("[SX1280] Packet too long!")); + } else if (state == ERR_TX_TIMEOUT) { + Serial.println(F("[SX1280] Timed out while transmitting!")); + } else { + Serial.println(F("[SX1280] Failed to transmit packet, code ")); + Serial.println(state); + } + + // receive GFSK packet + String str; + state = gfsk.receive(str); + /* + byte byteArr[8]; + int state = gfsk.receive(byteArr, 8); + */ + if (state == ERR_NONE) { + Serial.println(F("[SX1280] Received packet!")); + Serial.print(F("[SX1280] Data:\t")); + Serial.println(str); + } else if (state == ERR_RX_TIMEOUT) { + Serial.println(F("[SX1280] Timed out while waiting for packet!")); + } else { + Serial.print(F("[SX1280] Failed to receive packet, code ")); + Serial.println(state); + } +} diff --git a/examples/SX128x/SX128x_Receive/SX128x_Receive.ino b/examples/SX128x/SX128x_Receive/SX128x_Receive.ino new file mode 100644 index 00000000..0427cf41 --- /dev/null +++ b/examples/SX128x/SX128x_Receive/SX128x_Receive.ino @@ -0,0 +1,106 @@ +/* + RadioLib SX128x Receive Example + + This example listens for LoRa transmissions using SX126x Lora modules. + To successfully receive data, the following settings have to be the same + on both transmitter and receiver: + - carrier frequency + - bandwidth + - spreading factor + - coding rate + - sync word + - preamble length + + Other modules from SX128x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 lora = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 lora = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bandwidth: 812.5 kHz + // spreading factor: 9 + // coding rate: 7 + // output power: 10 dBm + // preamble length: 12 symbols + // CRC: enabled + int state = lora.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } +} + +void loop() { + Serial.print(F("[SX1280] Waiting for incoming transmission ... ")); + + // you can receive data as an Arduino String + // NOTE: receive() is a blocking method! + // See example ReceiveInterrupt for details + // on non-blocking reception method. + String str; + int state = lora.receive(str); + + // you can also receive data as byte array + /* + byte byteArr[8]; + int state = lora.receive(byteArr, 8); + */ + + if (state == ERR_NONE) { + // packet was successfully received + Serial.println(F("success!")); + + // print the data of the packet + Serial.print(F("[SX1280] Data:\t\t")); + Serial.println(str); + + // print the RSSI (Received Signal Strength Indicator) + // of the last received packet + Serial.print(F("[SX1280] RSSI:\t\t")); + Serial.print(lora.getRSSI()); + Serial.println(F(" dBm")); + + // print the SNR (Signal-to-Noise Ratio) + // of the last received packet + Serial.print(F("[SX1280] SNR:\t\t")); + Serial.print(lora.getSNR()); + Serial.println(F(" dB")); + + } else if (state == ERR_RX_TIMEOUT) { + // timeout occurred while waiting for a packet + Serial.println(F("timeout!")); + + } else if (state == ERR_CRC_MISMATCH) { + // packet was received, but is malformed + Serial.println(F("CRC error!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } +} diff --git a/examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino b/examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino new file mode 100644 index 00000000..2d6f1664 --- /dev/null +++ b/examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino @@ -0,0 +1,159 @@ +/* + RadioLib SX128x Receive with Interrupts Example + + This example listens for LoRa transmissions and tries to + receive them. Once a packet is received, an interrupt is + triggered. To successfully receive data, the following + settings have to be the same on both transmitter + and receiver: + - carrier frequency + - bandwidth + - spreading factor + - coding rate + - sync word + + Other modules from SX128x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 lora = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 lora = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bandwidth: 812.5 kHz + // spreading factor: 9 + // coding rate: 7 + // output power: 10 dBm + // preamble length: 12 symbols + // CRC: enabled + int state = lora.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // set the function that will be called + // when new packet is received + lora.setDio1Action(setFlag); + + // start listening for LoRa packets + Serial.print(F("[SX1280] Starting to listen ... ")); + state = lora.startReceive(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // if needed, 'listen' mode can be disabled by calling + // any of the following methods: + // + // lora.standby() + // lora.sleep() + // lora.transmit(); + // lora.receive(); + // lora.readData(); + // lora.scanChannel(); +} + +// flag to indicate that a packet was received +volatile bool receivedFlag = false; + +// disable interrupt when it's not needed +volatile bool enableInterrupt = true; + +// this function is called when a complete packet +// is received by the module +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +void setFlag(void) { + // check if the interrupt is enabled + if(!enableInterrupt) { + return; + } + + // we got a packet, set the flag + receivedFlag = true; +} + +void loop() { + // check if the flag is set + if(receivedFlag) { + // disable the interrupt service routine while + // processing the data + enableInterrupt = false; + + // reset flag + receivedFlag = false; + + // you can read received data as an Arduino String + String str; + int state = lora.readData(str); + + // you can also read received data as byte array + /* + byte byteArr[8]; + int state = lora.readData(byteArr, 8); + */ + + if (state == ERR_NONE) { + // packet was successfully received + Serial.println(F("[SX1280] Received packet!")); + + // print data of the packet + Serial.print(F("[SX1280] Data:\t\t")); + Serial.println(str); + + // print RSSI (Received Signal Strength Indicator) + Serial.print(F("[SX1280] RSSI:\t\t")); + Serial.print(lora.getRSSI()); + Serial.println(F(" dBm")); + + // print SNR (Signal-to-Noise Ratio) + Serial.print(F("[SX1280] SNR:\t\t")); + Serial.print(lora.getSNR()); + Serial.println(F(" dB")); + + } else if (state == ERR_CRC_MISMATCH) { + // packet was received, but is malformed + Serial.println(F("CRC error!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } + + // put module back to listen mode + lora.startReceive(); + + // we're ready to receive more packets, + // enable interrupt service routine + enableInterrupt = true; + } + +} diff --git a/examples/SX128x/SX128x_Settings/SX128x_Settings.ino b/examples/SX128x/SX128x_Settings/SX128x_Settings.ino new file mode 100644 index 00000000..49d218d6 --- /dev/null +++ b/examples/SX128x/SX128x_Settings/SX128x_Settings.ino @@ -0,0 +1,134 @@ +/* + RadioLib SX128x Settings Example + + This example shows how to change all the properties of LoRa transmission. + RadioLib currently supports the following settings: + - pins (SPI slave select, DIO1, DIO2, BUSY pin) + - carrier frequency + - bandwidth + - spreading factor + - coding rate + - output power during transmission + - CRC + - preamble length + + Other modules from SX128x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 loraSX1280 = new Module(10, 2, 3, 9); + +// SX1280 has the following connections: +// NSS pin: 8 +// DIO1 pin: 4 +// NRST pin: 5 +// BUSY pin: 6 +SX1281 loraSX1281 = new Module(8, 4, 5, 6); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1282 loraSX1282 = RadioShield.ModuleB; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bandwidth: 812.5 kHz + // spreading factor: 9 + // coding rate: 7 + // output power: 10 dBm + // preamble length: 12 symbols + // CRC: enabled + int state = loraSX1280.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // initialize the second LoRa instance with + // non-default settings + // this LoRa link will have high data rate, + // but lower range + Serial.print(F("[SX1281] Initializing ... ")); + // carrier frequency: 2450.0 MHz + // bandwidth: 1625.0 kHz + // spreading factor: 7 + // coding rate: 5 + // output power: 2 dBm + // preamble length: 20 symbols + // CRC: enabled + state = loraSX1281.begin(2450.0, 1625.0, 7, 5, 2, 20); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // you can also change the settings at runtime + // and check if the configuration was changed successfully + + // set carrier frequency to 2410.5 MHz + if (loraSX1280.setFrequency(2410.5) == ERR_INVALID_FREQUENCY) { + Serial.println(F("Selected frequency is invalid for this module!")); + while (true); + } + + // set bandwidth to 203.125 kHz + if (loraSX1280.setBandwidth(203.125) == ERR_INVALID_BANDWIDTH) { + Serial.println(F("Selected bandwidth is invalid for this module!")); + while (true); + } + + // set spreading factor to 10 + if (loraSX1280.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) { + Serial.println(F("Selected spreading factor is invalid for this module!")); + while (true); + } + + // set coding rate to 6 + if (loraSX1280.setCodingRate(6) == ERR_INVALID_CODING_RATE) { + Serial.println(F("Selected coding rate is invalid for this module!")); + while (true); + } + + // set output power to -2 dBm + if (loraSX1280.setOutputPower(-2) == ERR_INVALID_OUTPUT_POWER) { + Serial.println(F("Selected output power is invalid for this module!")); + while (true); + } + + // set LoRa preamble length to 16 symbols (accepted range is 2 - 65535) + if (loraSX1280.setPreambleLength(16) == ERR_INVALID_PREAMBLE_LENGTH) { + Serial.println(F("Selected preamble length is invalid for this module!")); + while (true); + } + + // disable CRC + if (loraSX1280.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) { + Serial.println(F("Selected CRC is invalid for this module!")); + while (true); + } + + Serial.println(F("All settings succesfully changed!")); +} + +void loop() { + // nothing here +} diff --git a/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino b/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino new file mode 100644 index 00000000..e8e777dc --- /dev/null +++ b/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino @@ -0,0 +1,85 @@ +/* + RadioLib SX128x Transmit Example + + This example transmits packets using SX1280 LoRa radio module. + Each packet contains up to 256 bytes of data, in the form of: + - Arduino String + - null-terminated char array (C-string) + - arbitrary binary data (byte array) + + Other modules from SX128x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 lora = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 lora = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bandwidth: 812.5 kHz + // spreading factor: 9 + // coding rate: 7 + // output power: 10 dBm + // preamble length: 12 symbols + // CRC: enabled + int state = lora.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } +} + +void loop() { + Serial.print(F("[SX1280] Transmitting packet ... ")); + + // you can transmit C-string or Arduino string up to + // 256 characters long + // NOTE: transmit() is a blocking method! + // See example SX128x_Transmit_Interrupt for details + // on non-blocking transmission method. + int state = lora.transmit("Hello World!"); + + // you can also transmit byte array up to 256 bytes long + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; + int state = lora.transmit(byteArr, 8); + */ + + if (state == ERR_NONE) { + // the packet was successfully transmitted + Serial.println(F("success!")); + + } else if (state == ERR_PACKET_TOO_LONG) { + // the supplied packet was longer than 256 bytes + Serial.println(F("too long!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } + + // wait for a second before transmitting again + delay(1000); +} diff --git a/examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino b/examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino new file mode 100644 index 00000000..284244e8 --- /dev/null +++ b/examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino @@ -0,0 +1,135 @@ +/* + RadioLib SX128x Transmit with Interrupts Example + + This example transmits LoRa packets with one second delays + between them. Each packet contains up to 256 bytes + of data, in the form of: + - Arduino String + - null-terminated char array (C-string) + - arbitrary binary data (byte array) + + Other modules from SX128x family can also be used. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 lora = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 lora = RadioShield.ModuleA; + +// save transmission state between loops +int transmissionState = ERR_NONE; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bandwidth: 812.5 kHz + // spreading factor: 9 + // coding rate: 7 + // output power: 10 dBm + // preamble length: 12 symbols + // CRC: enabled + int state = lora.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // set the function that will be called + // when packet transmission is finished + lora.setDio1Action(setFlag); + + // start transmitting the first packet + Serial.print(F("[SX1280] Sending first packet ... ")); + + // you can transmit C-string or Arduino string up to + // 256 characters long + transmissionState = lora.startTransmit("Hello World!"); + + // you can also transmit byte array up to 256 bytes long + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + state = lora.startTransmit(byteArr, 8); + */ +} + +// flag to indicate that a packet was sent +volatile bool transmittedFlag = false; + +// disable interrupt when it's not needed +volatile bool enableInterrupt = true; + +// this function is called when a complete packet +// is transmitted by the module +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +void setFlag(void) { + // check if the interrupt is enabled + if(!enableInterrupt) { + return; + } + + // we sent a packet, set the flag + transmittedFlag = true; +} + +void loop() { + // check if the previous transmission finished + if(transmittedFlag) { + // disable the interrupt service routine while + // processing the data + enableInterrupt = false; + + // reset flag + transmittedFlag = false; + + if (transmissionState == ERR_NONE) { + // packet was successfully sent + Serial.println(F("transmission finished!")); + + } else { + Serial.print(F("failed, code ")); + Serial.println(transmissionState); + + } + + // wait a second before transmitting again + delay(1000); + + // send another one + Serial.print(F("[SX1280] Sending another packet ... ")); + + // you can transmit C-string or Arduino string up to + // 256 characters long + transmissionState = lora.startTransmit("Hello World!"); + + // you can also transmit byte array up to 256 bytes long + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + int state = lora.startTransmit(byteArr, 8); + */ + + // we're ready to send more packets, + // enable interrupt service routine + enableInterrupt = true; + } +} diff --git a/keywords.txt b/keywords.txt index 57b8b822..d42b2c73 100644 --- a/keywords.txt +++ b/keywords.txt @@ -37,6 +37,9 @@ SX1276 KEYWORD1 SX1277 KEYWORD1 SX1278 KEYWORD1 SX1279 KEYWORD1 +SX1280 KEYWORD1 +SX1281 KEYWORD1 +SX1282 KEYWORD1 XBee KEYWORD1 XBeeSerial KEYWORD1 @@ -209,6 +212,9 @@ sendHeader KEYWORD2 sendLine KEYWORD2 getPictureHeight KEYWORD2 +# SX128x +beginGFSK KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### diff --git a/src/RadioLib.h b/src/RadioLib.h index ae4a6909..d4911d51 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -14,6 +14,7 @@ - Si443x FSK module - SX126x LoRa/FSK module - SX127x LoRa/FSK module + - SX128x LoRa/GFSK/BLE/FLRC module - SX1231 FSK module - XBee module (S2B) - PhysicalLayer protocols @@ -77,6 +78,9 @@ #include "modules/SX127x/SX1277.h" #include "modules/SX127x/SX1278.h" #include "modules/SX127x/SX1279.h" +#include "modules/SX128x/SX1280.h" +#include "modules/SX128x/SX1281.h" +#include "modules/SX128x/SX1282.h" #include "modules/XBee/XBee.h" // physical layer protocols @@ -110,7 +114,6 @@ \brief Library control object when using RadioShield. Contains two pre-configured "modules", which correspond to the slots on shield. */ - class Radio { public: diff --git a/src/modules/SX128x/SX1280.cpp b/src/modules/SX128x/SX1280.cpp new file mode 100644 index 00000000..afbc96df --- /dev/null +++ b/src/modules/SX128x/SX1280.cpp @@ -0,0 +1,5 @@ +#include "SX1280.h" + +SX1280::SX1280(Module* mod) : SX1281(mod) { + +} diff --git a/src/modules/SX128x/SX1280.h b/src/modules/SX128x/SX1280.h new file mode 100644 index 00000000..08aa1ec1 --- /dev/null +++ b/src/modules/SX128x/SX1280.h @@ -0,0 +1,31 @@ +#ifndef _RADIOLIB_SX1280_H +#define _RADIOLIB_SX1280_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "SX128x.h" +#include "SX1281.h" + +// TODO implement ranging + +/*! + \class SX1280 + + \brief Derived class for %SX1280 modules. +*/ +class SX1280: public SX1281 { + public: + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio. + */ + SX1280(Module* mod); + +#ifndef RADIOLIB_GODMODE + private: +#endif + +}; + +#endif diff --git a/src/modules/SX128x/SX1281.cpp b/src/modules/SX128x/SX1281.cpp new file mode 100644 index 00000000..4aa09b0d --- /dev/null +++ b/src/modules/SX128x/SX1281.cpp @@ -0,0 +1,5 @@ +#include "SX1281.h" + +SX1281::SX1281(Module* mod) : SX128x(mod) { + +} diff --git a/src/modules/SX128x/SX1281.h b/src/modules/SX128x/SX1281.h new file mode 100644 index 00000000..88037a09 --- /dev/null +++ b/src/modules/SX128x/SX1281.h @@ -0,0 +1,28 @@ +#ifndef _RADIOLIB_SX1281_H +#define _RADIOLIB_SX1281_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "SX128x.h" + +/*! + \class SX1281 + + \brief Derived class for %SX1281 modules. +*/ +class SX1281: public SX128x { + public: + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio. + */ + SX1281(Module* mod); + +#ifndef RADIOLIB_GODMODE + private: +#endif + +}; + +#endif diff --git a/src/modules/SX128x/SX1282.cpp b/src/modules/SX128x/SX1282.cpp new file mode 100644 index 00000000..847a36d1 --- /dev/null +++ b/src/modules/SX128x/SX1282.cpp @@ -0,0 +1,5 @@ +#include "SX1282.h" + +SX1282::SX1282(Module* mod) : SX1280(mod) { + +} diff --git a/src/modules/SX128x/SX1282.h b/src/modules/SX128x/SX1282.h new file mode 100644 index 00000000..09f92075 --- /dev/null +++ b/src/modules/SX128x/SX1282.h @@ -0,0 +1,31 @@ +#ifndef _RADIOLIB_SX1282_H +#define _RADIOLIB_SX1282_H + +#include "../../TypeDef.h" +#include "../../Module.h" +#include "SX128x.h" +#include "SX1280.h" + +// TODO implement advanced ranging + +/*! + \class SX1282 + + \brief Derived class for %SX1282 modules. +*/ +class SX1282: public SX1280 { + public: + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio. + */ + SX1282(Module* mod); + +#ifndef RADIOLIB_GODMODE + private: +#endif + +}; + +#endif diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp new file mode 100644 index 00000000..a11b1788 --- /dev/null +++ b/src/modules/SX128x/SX128x.cpp @@ -0,0 +1,1208 @@ +#include "SX128x.h" + +SX128x::SX128x(Module* mod) : PhysicalLayer(SX128X_FREQUENCY_STEP_SIZE, SX128X_MAX_PACKET_LENGTH) { + _mod = mod; +} + +int16_t SX128x::begin(float freq, float bw, uint8_t sf, uint8_t cr, int8_t power, uint16_t preambleLength) { + // set module properties + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); + Module::pinMode(_mod->getGpio(), INPUT); + + // initialize LoRa modulation variables + _bwKhz = bw; + _sf = SX128X_LORA_SF_9; + _cr = SX128X_LORA_CR_4_7; + + // initialize LoRa packet variables + _preambleLengthLoRa = preambleLength; + _headerType = SX128X_LORA_HEADER_EXPLICIT; + _payloadLen = 0xFF; + _crcLoRa = SX128X_LORA_CRC_ON; + + // reset the module and verify startup + int16_t state = reset(); + RADIOLIB_ASSERT(state); + + // set mode to standby + state = standby(); + RADIOLIB_ASSERT(state); + + // configure settings not accessible by API + state = config(SX128X_PACKET_TYPE_LORA); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setFrequency(freq); + RADIOLIB_ASSERT(state); + + state = setBandwidth(bw); + RADIOLIB_ASSERT(state); + + state = setSpreadingFactor(sf); + RADIOLIB_ASSERT(state); + + state = setCodingRate(cr); + RADIOLIB_ASSERT(state); + + state = setPreambleLength(preambleLength); + RADIOLIB_ASSERT(state); + + state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + return(state); +} + +int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, uint16_t preambleLength, float dataShaping) { + // set module properties + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); + Module::pinMode(_mod->getGpio(), INPUT); + + // initialize GFSK modulation variables + _brKbps = br; + _br = SX128X_BLE_GFSK_BR_0_800_BW_2_4; + _modIndexReal = 1.0; + _modIndex = SX128X_BLE_GFSK_MOD_IND_1_00; + _shaping = SX128X_BLE_GFSK_BT_0_5; + + // initialize GFSK packet variables + _preambleLengthGFSK = preambleLength; + _syncWordLen = 2; + _syncWordMatch = SX128X_GFSK_FLRC_SYNC_WORD_1; + _crcGFSK = SX128X_GFSK_FLRC_CRC_2_BYTE; + _whitening = SX128X_GFSK_BLE_WHITENING_ON; + + // reset the module and verify startup + int16_t state = reset(); + RADIOLIB_ASSERT(state); + + // set mode to standby + state = standby(); + RADIOLIB_ASSERT(state); + + // configure settings not accessible by API + state = config(SX128X_PACKET_TYPE_GFSK); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setFrequency(freq); + RADIOLIB_ASSERT(state); + + state = setBitRate(br); + RADIOLIB_ASSERT(state); + + state = setFrequencyDeviation(freqDev); + RADIOLIB_ASSERT(state); + + state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + state = setPreambleLength(preambleLength); + RADIOLIB_ASSERT(state); + + state = setDataShaping(dataShaping); + RADIOLIB_ASSERT(state); + + // set publicly accessible settings that are not a part of begin method + uint8_t sync[] = { 0x2D, 0x01 }; + state = setSyncWord(sync, 2); + RADIOLIB_ASSERT(state); + + return(state); +} + +int16_t SX128x::reset(bool verify) { + // run the reset sequence - same as SX126x, as SX128x docs don't seem to mention this + Module::pinMode(_mod->getRst(), OUTPUT); + Module::digitalWrite(_mod->getRst(), LOW); + delay(1); + Module::digitalWrite(_mod->getRst(), HIGH); + + // return immediately when verification is disabled + if(!verify) { + return(ERR_NONE); + } + + // set mode to standby + uint32_t start = millis(); + while(true) { + // try to set mode to standby + int16_t state = standby(); + if(state == ERR_NONE) { + // standby command successful + return(ERR_NONE); + } + + // standby command failed, check timeout and try again + if(millis() - start >= 3000) { + // timed out, possibly incorrect wiring + return(state); + } + + // wait a bit to not spam the module + delay(10); + } +} + +int16_t SX128x::transmit(uint8_t* data, size_t len, uint8_t addr) { + // check packet length + if(len > SX128X_MAX_PACKET_LENGTH) { + return(ERR_PACKET_TOO_LONG); + } + + // check active modem + uint8_t modem = getPacketType(); + if(modem == SX128X_PACKET_TYPE_RANGING) { + return(ERR_WRONG_MODEM); + } + + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // calculate timeout (500% of expected time-on-air) + uint32_t timeout = getTimeOnAir(len) * 5; + + RADIOLIB_DEBUG_PRINT(F("Timeout in ")); + RADIOLIB_DEBUG_PRINT(timeout); + RADIOLIB_DEBUG_PRINTLN(F(" us")); + + // start transmission + state = startTransmit(data, len, addr); + RADIOLIB_ASSERT(state); + + // wait for packet transmission or timeout + uint32_t start = micros(); + while(!digitalRead(_mod->getIrq())) { + yield(); + if(micros() - start > timeout) { + clearIrqStatus(); + standby(); + return(ERR_TX_TIMEOUT); + } + } + + // clear interrupt flags + state = clearIrqStatus(); + RADIOLIB_ASSERT(state); + + // set mode to standby to disable transmitter + state = standby(); + + return(state); +} + +int16_t SX128x::receive(uint8_t* data, size_t len) { + // check active modem + uint8_t modem = getPacketType(); + if(modem == SX128X_PACKET_TYPE_RANGING) { + return(ERR_WRONG_MODEM); + } + + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // calculate timeout (1000% of expected time-on-air) + uint32_t timeout = getTimeOnAir(len) * 10; + + RADIOLIB_DEBUG_PRINT(F("Timeout in ")); + RADIOLIB_DEBUG_PRINT(timeout); + RADIOLIB_DEBUG_PRINTLN(F(" us")); + + // start reception + uint32_t timeoutValue = (uint32_t)((float)timeout / 15.625); + state = startReceive(timeoutValue); + RADIOLIB_ASSERT(state); + + // wait for packet reception or timeout + uint32_t start = micros(); + while(!digitalRead(_mod->getIrq())) { + yield(); + if(micros() - start > timeout) { + clearIrqStatus(); + standby(); + return(ERR_RX_TIMEOUT); + } + } + + // read the received data + return(readData(data, len)); +} + +int16_t SX128x::transmitDirect(uint32_t frf) { + // user requested to start transmitting immediately (required for RTTY) + int16_t state = ERR_NONE; + if(frf != 0) { + state = setRfFrequency(frf); + } + RADIOLIB_ASSERT(state); + + // start transmitting + return(SPIwriteCommand(SX128X_CMD_SET_TX_CONTINUOUS_WAVE, NULL, 0)); +} + +int16_t SX128x::receiveDirect() { + // SX128x is unable to output received data directly + return(ERR_UNKNOWN); +} + +int16_t SX128x::scanChannel() { + // check active modem + if(getPacketType() != SX128X_PACKET_TYPE_LORA) { + return(ERR_WRONG_MODEM); + } + + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // set DIO pin mapping + state = setDioIrqParams(SX128X_IRQ_CAD_DETECTED | SX128X_IRQ_CAD_DONE, SX128X_IRQ_CAD_DETECTED | SX128X_IRQ_CAD_DONE); + RADIOLIB_ASSERT(state); + + // clear interrupt flags + state = clearIrqStatus(); + RADIOLIB_ASSERT(state); + + // set mode to CAD + state = setCad(); + RADIOLIB_ASSERT(state); + + // wait for channel activity detected or timeout + while(!digitalRead(_mod->getIrq())) { + yield(); + } + + // check CAD result + uint16_t cadResult = getIrqStatus(); + if(cadResult & SX128X_IRQ_CAD_DETECTED) { + // detected some LoRa activity + clearIrqStatus(); + return(LORA_DETECTED); + } else if(cadResult & SX128X_IRQ_CAD_DONE) { + // channel is free + clearIrqStatus(); + return(CHANNEL_FREE); + } + + return(ERR_UNKNOWN); +} + +int16_t SX128x::sleep(bool retainConfig) { + uint8_t sleepConfig = SX128X_SLEEP_DATA_BUFFER_RETAIN | SX128X_SLEEP_DATA_RAM_RETAIN; + if(!retainConfig) { + sleepConfig = SX128X_SLEEP_DATA_BUFFER_FLUSH | SX128X_SLEEP_DATA_RAM_FLUSH; + } + int16_t state = SPIwriteCommand(SX128X_CMD_SET_SLEEP, &sleepConfig, 1, false); + + // wait for SX128x to safely enter sleep mode + delay(1); + + return(state); +} + +int16_t SX128x::standby() { + return(SX128x::standby(SX128X_STANDBY_RC)); +} + +int16_t SX128x::standby(uint8_t mode) { + uint8_t data[] = { mode }; + return(SPIwriteCommand(SX128X_CMD_SET_STANDBY, data, 1)); +} + +void SX128x::setDio1Action(void (*func)(void)) { + attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING); +} + +void SX128x::clearDio1Action() { + detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); +} + +int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { + // suppress unused variable warning + (void)addr; + + // check packet length + if(len > SX128X_MAX_PACKET_LENGTH) { + return(ERR_PACKET_TOO_LONG); + } + + // set packet Length + int16_t state = ERR_NONE; + uint8_t modem = getPacketType(); + if(modem == SX128X_PACKET_TYPE_LORA) { + state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, len, _crcLoRa); + } else if(modem == SX128X_PACKET_TYPE_GFSK) { + state = setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening, len); + } else { + return(ERR_WRONG_MODEM); + } + RADIOLIB_ASSERT(state); + + // update output power + state = setTxParams(_pwr); + RADIOLIB_ASSERT(state); + + // set buffer pointers + state = setBufferBaseAddress(); + RADIOLIB_ASSERT(state); + + // write packet to buffer + state = writeBuffer(data, len); + RADIOLIB_ASSERT(state); + + // set DIO mapping + state = setDioIrqParams(SX128X_IRQ_TX_DONE | SX128X_IRQ_RX_TX_TIMEOUT, SX128X_IRQ_TX_DONE); + RADIOLIB_ASSERT(state); + + // clear interrupt flags + state = clearIrqStatus(); + RADIOLIB_ASSERT(state); + + // start transmission + state = setTx(SX128X_TX_TIMEOUT_NONE); + RADIOLIB_ASSERT(state); + + // wait for BUSY to go low (= PA ramp up done) + while(digitalRead(_mod->getGpio())) { + yield(); + } + + return(state); +} + +int16_t SX128x::startReceive(uint16_t timeout) { + // check active modem + if(getPacketType() == SX128X_PACKET_TYPE_RANGING) { + return(ERR_WRONG_MODEM); + } + + // set DIO mapping + int16_t state = setDioIrqParams(SX128X_IRQ_RX_DONE | SX128X_IRQ_RX_TX_TIMEOUT | SX128X_IRQ_CRC_ERROR | SX128X_IRQ_HEADER_ERROR, SX128X_IRQ_RX_DONE); + RADIOLIB_ASSERT(state); + + // set buffer pointers + state = setBufferBaseAddress(); + RADIOLIB_ASSERT(state); + + // clear interrupt flags + state = clearIrqStatus(); + RADIOLIB_ASSERT(state); + + // set implicit mode and expected len if applicable + if((_headerType == SX128X_LORA_HEADER_IMPLICIT) && (getPacketType() == SX128X_PACKET_TYPE_LORA)) { + state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa); + RADIOLIB_ASSERT(state); + } + + // set mode to receive + state = setRx(timeout); + + return(state); +} + +int16_t SX128x::readData(uint8_t* data, size_t len) { + // set mode to standby + int16_t state = standby(); + RADIOLIB_ASSERT(state); + + // check integrity CRC + uint16_t irq = getIrqStatus(); + int16_t crcState = ERR_NONE; + if((irq & SX128X_IRQ_CRC_ERROR) || (irq & SX128X_IRQ_HEADER_ERROR)) { + crcState = ERR_CRC_MISMATCH; + } + + // get packet length + size_t length = len; + if(len == SX128X_MAX_PACKET_LENGTH) { + length = getPacketLength(); + } + + // read packet data + state = readBuffer(data, length); + RADIOLIB_ASSERT(state); + + // clear interrupt flags + state = clearIrqStatus(); + + // check if CRC failed - this is done after reading data to give user the option to keep them + RADIOLIB_ASSERT(crcState); + + return(state); +} + +int16_t SX128x::setFrequency(float freq) { + RADIOLIB_CHECK_RANGE(freq, 2400.0, 2500.0, ERR_INVALID_FREQUENCY); + + // calculate raw value + uint32_t frf = (freq * (uint32_t(1) << SX128X_DIV_EXPONENT)) / SX128X_CRYSTAL_FREQ; + return(setRfFrequency(frf)); +} + +int16_t SX128x::setBandwidth(float bw) { + // check active modem + uint8_t modem = getPacketType(); + if(modem == SX128X_PACKET_TYPE_LORA) { + // check range for LoRa + RADIOLIB_CHECK_RANGE(bw, 203.125, 1625.0, ERR_INVALID_BANDWIDTH); + } else if(modem == SX128X_PACKET_TYPE_RANGING) { + // check range for ranging + RADIOLIB_CHECK_RANGE(bw, 406.25, 1625.0, ERR_INVALID_BANDWIDTH); + } else { + return(ERR_WRONG_MODEM); + } + + if(abs(bw - 203.125) <= 0.001) { + _bw = SX128X_LORA_BW_203_125; + } else if(abs(bw - 406.25) <= 0.001) { + _bw = SX128X_LORA_BW_406_25; + } else if(abs(bw - 812.5) <= 0.001) { + _bw = SX128X_LORA_BW_812_50; + } else if(abs(bw - 1625.0) <= 0.001) { + _bw = SX128X_LORA_BW_1625_00; + } else { + return(ERR_INVALID_BANDWIDTH); + } + + // update modulation parameters + _bwKhz = bw; + return(setModulationParams(_sf, _bw, _cr)); +} + +int16_t SX128x::setSpreadingFactor(uint8_t sf) { + // check active modem + uint8_t modem = getPacketType(); + if(modem == SX128X_PACKET_TYPE_LORA) { + // check range for LoRa + RADIOLIB_CHECK_RANGE(sf, 5, 12, ERR_INVALID_SPREADING_FACTOR); + } else if(modem == SX128X_PACKET_TYPE_RANGING) { + // check range for ranging + RADIOLIB_CHECK_RANGE(sf, 5, 10, ERR_INVALID_SPREADING_FACTOR); + } else { + return(ERR_WRONG_MODEM); + } + + // update modulation parameters + _sf = sf << 4; + int16_t state = setModulationParams(_sf, _bw, _cr); + RADIOLIB_ASSERT(state); + + // update mystery register in LoRa mode - SX1280 datasheet v3.0 section 13.4.1 + if(modem == SX128X_PACKET_TYPE_LORA) { + uint8_t data = 0; + if((_sf == SX128X_LORA_SF_5) || (_sf == SX128X_LORA_SF_6)) { + data = 0x1E; + } else if((_sf == SX128X_LORA_SF_7) || (_sf == SX128X_LORA_SF_8)) { + data = 0x37; + } else { + data = 0x32; + } + state = SX128x::writeRegister(SX128X_REG_LORA_SF_CONFIG, &data, 1); + } + + return(state); +} + +int16_t SX128x::setCodingRate(uint8_t cr, bool longInterleaving) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING))) { + return(ERR_WRONG_MODEM); + } + + RADIOLIB_CHECK_RANGE(cr, 5, 8, ERR_INVALID_CODING_RATE); + + // update modulation parameters + if(longInterleaving && (modem == SX128X_PACKET_TYPE_LORA)) { + _cr = cr; + } else { + _cr = cr - 4; + } + return(setModulationParams(_sf, _bw, _cr)); +} + +int16_t SX128x::setOutputPower(int8_t power) { + RADIOLIB_CHECK_RANGE(power, -18, 13, ERR_INVALID_OUTPUT_POWER); + _pwr = power + 18; + return(setTxParams(_pwr)); +} + +int16_t SX128x::setPreambleLength(uint32_t preambleLength) { + uint8_t modem = getPacketType(); + if((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING)) { + // LoRa or ranging + RADIOLIB_CHECK_RANGE(preambleLength, 2, 491520, ERR_INVALID_PREAMBLE_LENGTH); + + // check preamble length is even - no point even trying odd numbers + if(preambleLength % 2 != 0) { + return(ERR_INVALID_PREAMBLE_LENGTH); + } + + // calculate exponent and mantissa values (use the next longer preamble if there's no exact match) + uint8_t e = 1; + uint8_t m = 1; + uint32_t len = 0; + for(; e <= 15; e++) { + for(; m <= 15; m++) { + len = m * (uint32_t(1) << e); + if(len >= preambleLength) { + break; + } + } + if(len >= preambleLength) { + break; + } + } + + // update packet parameters + _preambleLengthLoRa = (e << 4) | m; + return(setPacketParamsLoRa(_preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa)); + + } else if((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_FLRC)) { + // GFSK or FLRC + RADIOLIB_CHECK_RANGE(preambleLength, 4, 32, ERR_INVALID_PREAMBLE_LENGTH); + + // check preamble length is multiple of 4 + if(preambleLength % 4 != 0) { + return(ERR_INVALID_PREAMBLE_LENGTH); + } + + // update packet parameters + _preambleLengthGFSK = ((preambleLength / 4) - 1) << 4; + return(setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening)); + } + + return(ERR_WRONG_MODEM); +} + +int16_t SX128x::setBitRate(uint16_t br) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE))) { + return(ERR_WRONG_MODEM); + } + + if(br == 125) { + _br = SX128X_BLE_GFSK_BR_0_125_BW_0_3; + } else if(br == 250) { + _br = SX128X_BLE_GFSK_BR_0_250_BW_0_6; + } else if(br == 400) { + _br = SX128X_BLE_GFSK_BR_0_400_BW_1_2; + } else if(br == 500) { + _br = SX128X_BLE_GFSK_BR_0_500_BW_1_2; + } else if(br == 800) { + _br = SX128X_BLE_GFSK_BR_0_800_BW_2_4; + } else if(br == 1000) { + _br = SX128X_BLE_GFSK_BR_1_000_BW_2_4; + } else if(br == 1600) { + _br = SX128X_BLE_GFSK_BR_1_600_BW_2_4; + } else if(br == 2000) { + _br = SX128X_BLE_GFSK_BR_2_000_BW_2_4; + } else { + return(ERR_INVALID_BIT_RANGE); + } + + // update modulation parameters + _brKbps = br; + return(setModulationParams(_br, _modIndex, _shaping)); +} + +int16_t SX128x::setFrequencyDeviation(float freqDev) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE))) { + return(ERR_WRONG_MODEM); + } + + RADIOLIB_CHECK_RANGE(freqDev, 0.0, 3200.0, ERR_INVALID_FREQUENCY_DEVIATION); + + // override for the lowest possible frequency deviation - required for some PhysicalLayer protocols + if(freqDev == 0.0) { + _modIndex = SX128X_BLE_GFSK_MOD_IND_0_35; + _br = SX128X_BLE_GFSK_BR_0_125_BW_0_3; + return(setModulationParams(_br, _modIndex, _shaping)); + } + + // update modulation parameters + uint8_t modIndex = (uint8_t)((8.0 * (freqDev / (float)_brKbps)) - 1.0); + if(modIndex > SX128X_BLE_GFSK_MOD_IND_4_00) { + return(ERR_INVALID_MODULATION_PARAMETERS); + } + + // update modulation parameters + _modIndex = modIndex; + return(setModulationParams(_br, _modIndex, _shaping)); +} + +int16_t SX128x::setDataShaping(float dataShaping) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE))) { + return(ERR_WRONG_MODEM); + } + + // check allowed values + dataShaping *= 10.0; + if(abs(dataShaping - 0.0) <= 0.001) { + _shaping = SX128X_BLE_GFSK_BT_OFF; + } else if(abs(dataShaping - 5.0) <= 0.001) { + _shaping = SX128X_BLE_GFSK_BT_0_5; + } else if(abs(dataShaping - 10.0) <= 0.001) { + _shaping = SX128X_BLE_GFSK_BT_1_0; + } else { + return(ERR_INVALID_DATA_SHAPING); + } + + // update modulation parameters + return(setModulationParams(_br, _modIndex, _shaping)); +} + +int16_t SX128x::setSyncWord(uint8_t* syncWord, uint8_t len) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_FLRC))) { + return(ERR_WRONG_MODEM); + } + + if(len > 5) { + return(ERR_INVALID_SYNC_WORD); + } + + // reverse sync word byte order + uint8_t syncWordBuff[] = { 0x00, 0x00, 0x00, 0x00, 0x00 }; + for(uint8_t i = 0; i < len; i++) { + syncWordBuff[4 - i] = syncWord[i]; + } + + // update sync word + int16_t state = SX128x::writeRegister(SX128X_REG_SYNC_WORD_1_BYTE_4, syncWordBuff, 5); + RADIOLIB_ASSERT(state); + + // update packet parameters + _syncWordLen = len; + if(_syncWordLen == 0) { + _syncWordMatch = SX128X_GFSK_FLRC_SYNC_WORD_OFF; + } else { + // TODO add support for multiple sync words + _syncWordMatch = SX128X_GFSK_FLRC_SYNC_WORD_1; + } + return(setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening)); +} + +int16_t SX128x::setCRC(uint8_t len, uint32_t initial, uint16_t polynomial) { + // check active modem + uint8_t modem = getPacketType(); + + int16_t state = ERR_NONE; + if((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_FLRC)) { + // update packet parameters + if(modem == SX128X_PACKET_TYPE_GFSK) { + if(len > 2) { + return(ERR_INVALID_CRC_CONFIGURATION); + } + } else { + if(len > 3) { + return(ERR_INVALID_CRC_CONFIGURATION); + } + } + _crcGFSK = len << 4; + state = setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening); + RADIOLIB_ASSERT(state); + + // set initial CRC value + uint8_t data[] = { (uint8_t)((initial >> 8) & 0xFF), (uint8_t)(initial & 0xFF) }; + state = writeRegister(SX128X_REG_CRC_INITIAL_MSB, data, 2); + RADIOLIB_ASSERT(state); + + // set CRC polynomial + data[0] = (uint8_t)((polynomial >> 8) & 0xFF); + data[1] = (uint8_t)(polynomial & 0xFF); + state = writeRegister(SX128X_REG_CRC_POLYNOMIAL_MSB, data, 2); + return(state); + + } else if(modem == SX128X_PACKET_TYPE_BLE) { + // update packet parameters + if(len == 0) { + _crcBLE = SX128X_BLE_CRC_OFF; + } else if(len == 3) { + _crcBLE = SX128X_BLE_CRC_3_BYTE; + } else { + return(ERR_INVALID_CRC_CONFIGURATION); + } + state = setPacketParamsBLE(_connectionState, _crcBLE, _bleTestPayload, _whitening); + RADIOLIB_ASSERT(state); + + // set initial CRC value + uint8_t data[] = { (uint8_t)((initial >> 16) & 0xFF), (uint8_t)((initial >> 8) & 0xFF), (uint8_t)(initial & 0xFF) }; + state = writeRegister(SX128X_REG_BLE_CRC_INITIAL_MSB, data, 3); + return(state); + + } else if((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING)) { + // update packet parameters + if(len == 0) { + _crcLoRa = SX128X_LORA_CRC_OFF; + } else if(len == 2) { + _crcLoRa = SX128X_LORA_CRC_ON; + } else { + return(ERR_INVALID_CRC_CONFIGURATION); + } + state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa); + return(state); + } + + return(ERR_UNKNOWN); +} + +int16_t SX128x::setWhitening(bool enabled) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE))) { + return(ERR_WRONG_MODEM); + } + + // update packet parameters + if(enabled) { + _whitening = SX128X_GFSK_BLE_WHITENING_ON; + } else { + _whitening = SX128X_GFSK_BLE_WHITENING_OFF; + } + + if(modem == SX128X_PACKET_TYPE_GFSK) { + return(setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening)); + } + return(setPacketParamsBLE(_connectionState, _crcBLE, _bleTestPayload, _whitening)); +} + +float SX128x::getRSSI() { + // get packet status + uint8_t packetStatus[5]; + SPIreadCommand(SX128X_CMD_GET_PACKET_STATUS, packetStatus, 5); + + // check active modem + uint8_t modem = getPacketType(); + if((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING)) { + // LoRa or ranging + uint8_t rssiSync = packetStatus[0]; + float rssiMeasured = -1.0 * rssiSync/2.0; + float snr = getSNR(); + if(snr <= 0.0) { + return(rssiMeasured - snr); + } else { + return(rssiMeasured); + } + } else { + // GFSK, BLE or FLRC + uint8_t rssiSync = packetStatus[1]; + return(-1.0 * rssiSync/2.0); + } +} + +float SX128x::getSNR() { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING))) { + return(0.0); + } + + // get packet status + uint8_t packetStatus[5]; + SPIreadCommand(SX128X_CMD_GET_PACKET_STATUS, packetStatus, 5); + + // calculate real SNR + uint8_t snr = packetStatus[1]; + if(snr < 128) { + return(snr/4.0); + } else { + return((snr - 256)/4.0); + } +} + +size_t SX128x::getPacketLength(bool update) { + (void)update; + uint8_t rxBufStatus[2]; + SPIreadCommand(SX128X_CMD_GET_RX_BUFFER_STATUS, rxBufStatus, 2); + return((size_t)rxBufStatus[0]); +} + +uint32_t SX128x::getTimeOnAir(size_t len) { + // check active modem + uint8_t modem = getPacketType(); + if(modem == SX128X_PACKET_TYPE_LORA) { + // calculate number of symbols + float N_symbol = 0; + uint8_t sf = _sf >> 4; + if(_cr <= SX128X_LORA_CR_4_8) { + // legacy coding rate - nice and simple + + // get SF coefficients + float coeff1 = 0; + uint8_t coeff2 = 0; + uint8_t coeff3 = 0; + if(sf < 7) { + // SF5, SF6 + coeff1 = 6.25; + coeff2 = 4*sf; + coeff3 = 4*sf; + } else if(sf < 11) { + // SF7. SF8, SF9, SF10 + coeff1 = 4.25; + coeff2 = 4*sf + 8; + coeff3 = 4*sf; + } else { + // SF11, SF12 + coeff1 = 4.25; + coeff2 = 4*sf + 8; + coeff3 = 4*(sf - 2); + } + + // get CRC length + uint8_t N_bitCRC = 16; + if(_crcLoRa == SX128X_LORA_CRC_OFF) { + N_bitCRC = 0; + } + + // get header length + uint8_t N_symbolHeader = 20; + if(_headerType == SX128X_LORA_HEADER_IMPLICIT) { + N_symbolHeader = 0; + } + + // calculate number of LoRa preamble symbols + uint32_t N_symbolPreamble = (_preambleLengthLoRa & 0x0F) * (uint32_t(1) << ((_preambleLengthLoRa & 0xF0) >> 4)); + + // calculate the number of symbols + N_symbol = (float)N_symbolPreamble + coeff1 + 8.0 + ceil(max(8 * len + N_bitCRC - coeff2 + N_symbolHeader, 0) / (float)coeff3) * (float)(_cr + 4); + + } else { + // long interleaving - abandon hope all ye who enter here + // TODO implement this mess - SX1280 datasheet v3.0 section 7.4.4.2 + + } + + // get time-on-air in us + return(((uint32_t(1) << sf) / _bwKhz) * N_symbol * 1000.0); + + } else { + return((len * 8) / _brKbps); + } + +} + +int16_t SX128x::implicitHeader(size_t len) { + return(setHeaderType(SX128X_LORA_HEADER_IMPLICIT, len)); +} + +int16_t SX128x::explicitHeader() { + return(setHeaderType(SX128X_LORA_HEADER_EXPLICIT)); +} + +int16_t SX128x::setEncoding(uint8_t encoding) { + return(setWhitening(encoding)); +} + +uint8_t SX128x::getStatus() { + uint8_t data = 0; + SPIreadCommand(SX128X_CMD_GET_STATUS, &data, 1); + return(data); +} + +int16_t SX128x::writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes) { + uint8_t cmd[] = { SX128X_CMD_WRITE_REGISTER, (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; + return(SPIwriteCommand(cmd, 3, data, numBytes)); +} + +int16_t SX128x::readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes) { + uint8_t cmd[] = { SX128X_CMD_READ_REGISTER, (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; + return(SX128x::SPItransfer(cmd, 3, false, NULL, data, numBytes, true)); +} + +int16_t SX128x::writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset) { + uint8_t cmd[] = { SX128X_CMD_WRITE_BUFFER, offset }; + return(SPIwriteCommand(cmd, 2, data, numBytes)); +} + +int16_t SX128x::readBuffer(uint8_t* data, uint8_t numBytes) { + uint8_t cmd[] = { SX128X_CMD_READ_BUFFER, SX128X_CMD_NOP }; + return(SPIreadCommand(cmd, 2, data, numBytes)); +} + +int16_t SX128x::setTx(uint16_t periodBaseCount, uint8_t periodBase) { + uint8_t data[] = { periodBase, (uint8_t)((periodBaseCount >> 8) & 0xFF), (uint8_t)(periodBaseCount & 0xFF) }; + return(SPIwriteCommand(SX128X_CMD_SET_TX, data, 3)); +} + +int16_t SX128x::setRx(uint16_t periodBaseCount, uint8_t periodBase) { + uint8_t data[] = { periodBase, (uint8_t)((periodBaseCount >> 8) & 0xFF), (uint8_t)(periodBaseCount & 0xFF) }; + return(SPIwriteCommand(SX128X_CMD_SET_RX, data, 3)); +} + +int16_t SX128x::setCad() { + return(SPIwriteCommand(SX128X_CMD_SET_CAD, NULL, 0)); +} + +uint8_t SX128x::getPacketType() { + uint8_t data = 0xFF; + SPIreadCommand(SX128X_CMD_GET_PACKET_TYPE, &data, 1); + return(data); +} + +int16_t SX128x::setRfFrequency(uint32_t frf) { + uint8_t data[] = { (uint8_t)((frf >> 16) & 0xFF), (uint8_t)((frf >> 8) & 0xFF), (uint8_t)(frf & 0xFF) }; + return(SPIwriteCommand(SX128X_CMD_SET_RF_FREQUENCY, data, 3)); +} + +int16_t SX128x::setTxParams(uint8_t power, uint8_t rampTime) { + uint8_t data[] = { power, rampTime }; + return(SPIwriteCommand(SX128X_CMD_SET_TX_PARAMS, data, 2)); +} + +int16_t SX128x::setBufferBaseAddress(uint8_t txBaseAddress, uint8_t rxBaseAddress) { + uint8_t data[] = { txBaseAddress, rxBaseAddress }; + return(SPIwriteCommand(SX128X_CMD_SET_BUFFER_BASE_ADDRESS, data, 2)); +} + +int16_t SX128x::setModulationParams(uint8_t modParam1, uint8_t modParam2, uint8_t modParam3) { + uint8_t data[] = { modParam1, modParam2, modParam3 }; + return(SPIwriteCommand(SX128X_CMD_SET_MODULATION_PARAMS, data, 3)); +} + +int16_t SX128x::setPacketParamsGFSK(uint8_t preambleLen, uint8_t syncWordLen, uint8_t syncWordMatch, uint8_t crcLen, uint8_t whitening, uint8_t payloadLen, uint8_t headerType) { + uint8_t data[] = { preambleLen, syncWordLen, syncWordMatch, headerType, payloadLen, crcLen, whitening }; + return(SPIwriteCommand(SX128X_CMD_SET_PACKET_PARAMS, data, 7)); +} + +int16_t SX128x::setPacketParamsBLE(uint8_t connState, uint8_t crcLen, uint8_t bleTestPayload, uint8_t whitening) { + uint8_t data[] = { connState, crcLen, bleTestPayload, whitening, 0x00, 0x00, 0x00 }; + return(SPIwriteCommand(SX128X_CMD_SET_PACKET_PARAMS, data, 7)); +} + +int16_t SX128x::setPacketParamsLoRa(uint8_t preambleLen, uint8_t headerType, uint8_t payloadLen, uint8_t crc, uint8_t invertIQ) { + uint8_t data[] = { preambleLen, headerType, payloadLen, crc, invertIQ, 0x00, 0x00 }; + return(SPIwriteCommand(SX128X_CMD_SET_PACKET_PARAMS, data, 7)); +} + +int16_t SX128x::setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask) { + uint8_t data[] = { (uint8_t)((irqMask >> 8) & 0xFF), (uint8_t)(irqMask & 0xFF), + (uint8_t)((dio1Mask >> 8) & 0xFF), (uint8_t)(dio1Mask & 0xFF), + (uint8_t)((dio2Mask >> 8) & 0xFF), (uint8_t)(dio2Mask & 0xFF), + (uint8_t)((dio3Mask >> 8) & 0xFF), (uint8_t)(dio3Mask & 0xFF) }; + return(SPIwriteCommand(SX128X_CMD_SET_DIO_IRQ_PARAMS, data, 8)); +} + +uint16_t SX128x::getIrqStatus() { + uint8_t data[] = { 0x00, 0x00 }; + SPIreadCommand(SX128X_CMD_GET_IRQ_STATUS, data, 2); + return(((uint16_t)(data[0]) << 8) | data[1]); +} + +int16_t SX128x::clearIrqStatus(uint16_t clearIrqParams) { + uint8_t data[] = { (uint8_t)((clearIrqParams >> 8) & 0xFF), (uint8_t)(clearIrqParams & 0xFF) }; + return(SPIwriteCommand(SX128X_CMD_CLEAR_IRQ_STATUS, data, 2)); +} + +int16_t SX128x::setHeaderType(uint8_t headerType, size_t len) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING))) { + return(ERR_WRONG_MODEM); + } + + // update packet parameters + _headerType = headerType; + _payloadLen = len; + return(setPacketParamsLoRa(_preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa)); +} + +int16_t SX128x::config(uint8_t modem) { + // reset buffer base address + int16_t state = setBufferBaseAddress(); + RADIOLIB_ASSERT(state); + + // set modem + uint8_t data[1]; + data[0] = modem; + state = SPIwriteCommand(SX128X_CMD_SET_PACKET_TYPE, data, 1); + RADIOLIB_ASSERT(state); + + // set CAD parameters + data[0] = SX128X_CAD_ON_8_SYMB; + state = SPIwriteCommand(SX128X_CMD_SET_CAD_PARAMS, data, 1); + RADIOLIB_ASSERT(state); + + return(ERR_NONE); +} + +int16_t SX128x::SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy) { + return(SX128x::SPItransfer(cmd, cmdLen, true, data, NULL, numBytes, waitForBusy)); +} + +int16_t SX128x::SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy) { + return(SX128x::SPItransfer(&cmd, 1, true, data, NULL, numBytes, waitForBusy)); +} + +int16_t SX128x::SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy) { + return(SX128x::SPItransfer(cmd, cmdLen, false, NULL, data, numBytes, waitForBusy)); +} + +int16_t SX128x::SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy) { + return(SX128x::SPItransfer(&cmd, 1, false, NULL, data, numBytes, waitForBusy)); +} + +int16_t SX128x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy, uint32_t timeout) { + // get pointer to used SPI interface and the settings + SPIClass* spi = _mod->getSpi(); + SPISettings spiSettings = _mod->getSpiSettings(); + + #ifdef RADIOLIB_VERBOSE + uint8_t debugBuff[256]; + #endif + + // ensure BUSY is low (state machine ready) + uint32_t start = millis(); + while(digitalRead(_mod->getGpio())) { + yield(); + if(millis() - start >= timeout) { + digitalWrite(_mod->getCs(), HIGH); + return(ERR_SPI_CMD_TIMEOUT); + } + } + + // pull NSS low + digitalWrite(_mod->getCs(), LOW); + + // start transfer + spi->beginTransaction(spiSettings); + + // send command byte(s) + for(uint8_t n = 0; n < cmdLen; n++) { + spi->transfer(cmd[n]); + } + + // variable to save error during SPI transfer + uint8_t status = 0; + + // send/receive all bytes + if(write) { + for(uint8_t n = 0; n < numBytes; n++) { + // send byte + uint8_t in = spi->transfer(dataOut[n]); + #ifdef RADIOLIB_VERBOSE + debugBuff[n] = in; + #endif + + // check status + if(((in & 0b00011100) == SX128X_STATUS_CMD_TIMEOUT) || + ((in & 0b00011100) == SX128X_STATUS_CMD_ERROR) || + ((in & 0b00011100) == SX128X_STATUS_CMD_FAILED)) { + status = in & 0b00011100; + break; + } else if(in == 0x00 || in == 0xFF) { + status = SX128X_STATUS_SPI_FAILED; + break; + } + } + + } else { + // skip the first byte for read-type commands (status-only) + uint8_t in = spi->transfer(SX128X_CMD_NOP); + #ifdef RADIOLIB_VERBOSE + debugBuff[0] = in; + #endif + + // check status + if(((in & 0b00011100) == SX128X_STATUS_CMD_TIMEOUT) || + ((in & 0b00011100) == SX128X_STATUS_CMD_ERROR) || + ((in & 0b00011100) == SX128X_STATUS_CMD_FAILED)) { + status = in & 0b00011100; + } else if(in == 0x00 || in == 0xFF) { + status = SX128X_STATUS_SPI_FAILED; + } else { + for(uint8_t n = 0; n < numBytes; n++) { + dataIn[n] = spi->transfer(SX128X_CMD_NOP); + } + } + } + + // stop transfer + spi->endTransaction(); + digitalWrite(_mod->getCs(), HIGH); + + // wait for BUSY to go high and then low + if(waitForBusy) { + delayMicroseconds(1); + start = millis(); + while(digitalRead(_mod->getGpio())) { + yield(); + if(millis() - start >= timeout) { + status = SX128X_STATUS_CMD_TIMEOUT; + break; + } + } + } + + // print debug output + #ifdef RADIOLIB_VERBOSE + // print command byte(s) + RADIOLIB_VERBOSE_PRINT("CMD\t"); + for(uint8_t n = 0; n < cmdLen; n++) { + RADIOLIB_VERBOSE_PRINT(cmd[n], HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + } + RADIOLIB_VERBOSE_PRINTLN(); + + // print data bytes + RADIOLIB_VERBOSE_PRINT("DAT"); + if(write) { + RADIOLIB_VERBOSE_PRINT("W\t"); + for(uint8_t n = 0; n < numBytes; n++) { + RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT(debugBuff[n], HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + } + RADIOLIB_VERBOSE_PRINTLN(); + } else { + RADIOLIB_VERBOSE_PRINT("R\t"); + // skip the first byte for read-type commands (status-only) + RADIOLIB_VERBOSE_PRINT(SX128X_CMD_NOP, HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT(debugBuff[0], HEX); + RADIOLIB_VERBOSE_PRINT('\t') + + for(uint8_t n = 0; n < numBytes; n++) { + RADIOLIB_VERBOSE_PRINT(SX128X_CMD_NOP, HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + } + RADIOLIB_VERBOSE_PRINTLN(); + } + RADIOLIB_VERBOSE_PRINTLN(); + #else + // some faster platforms require a short delay here + // not sure why, but it seems that long enough SPI transaction + // (e.g. setPacketParams for GFSK) will fail without it + #if defined(ARDUINO_ARCH_STM32) + delay(1); + #endif + #endif + + // parse status + switch(status) { + case SX128X_STATUS_CMD_TIMEOUT: + return(ERR_SPI_CMD_TIMEOUT); + case SX128X_STATUS_CMD_ERROR: + return(ERR_SPI_CMD_INVALID); + case SX128X_STATUS_CMD_FAILED: + return(ERR_SPI_CMD_FAILED); + case SX128X_STATUS_SPI_FAILED: + return(ERR_CHIP_NOT_FOUND); + default: + return(ERR_NONE); + } +} diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h new file mode 100644 index 00000000..2e74f7e0 --- /dev/null +++ b/src/modules/SX128x/SX128x.h @@ -0,0 +1,748 @@ +#ifndef _RADIOLIB_SX128X_H +#define _RADIOLIB_SX128X_H + +#include "../../TypeDef.h" +#include "../../Module.h" + +#include "../../protocols/PhysicalLayer/PhysicalLayer.h" + +// SX128X physical layer properties +#define SX128X_FREQUENCY_STEP_SIZE 198.3642578 +#define SX128X_MAX_PACKET_LENGTH 255 +#define SX128X_CRYSTAL_FREQ 52.0 +#define SX128X_DIV_EXPONENT 18 + +// SX128X SPI commands +#define SX128X_CMD_NOP 0x00 +#define SX128X_CMD_GET_STATUS 0xC0 +#define SX128X_CMD_WRITE_REGISTER 0x18 +#define SX128X_CMD_READ_REGISTER 0x19 +#define SX128X_CMD_WRITE_BUFFER 0x1A +#define SX128X_CMD_READ_BUFFER 0x1B +#define SX128X_CMD_SET_SLEEP 0x84 +#define SX128X_CMD_SET_STANDBY 0x80 +#define SX128X_CMD_SET_FS 0xC1 +#define SX128X_CMD_SET_TX 0x83 +#define SX128X_CMD_SET_RX 0x82 +#define SX128X_CMD_SET_RX_DUTY_CYCLE 0x94 +#define SX128X_CMD_SET_CAD 0xC5 +#define SX128X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1 +#define SX128X_CMD_SET_TX_CONTINUOUS_PREAMBLE 0xD2 +#define SX128X_CMD_SET_PACKET_TYPE 0x8A +#define SX128X_CMD_GET_PACKET_TYPE 0x03 +#define SX128X_CMD_SET_RF_FREQUENCY 0x86 +#define SX128X_CMD_SET_TX_PARAMS 0x8E +#define SX128X_CMD_SET_CAD_PARAMS 0x88 +#define SX128X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F +#define SX128X_CMD_SET_MODULATION_PARAMS 0x8B +#define SX128X_CMD_SET_PACKET_PARAMS 0x8C +#define SX128X_CMD_GET_RX_BUFFER_STATUS 0x17 +#define SX128X_CMD_GET_PACKET_STATUS 0x1D +#define SX128X_CMD_GET_RSSI_INST 0x1F +#define SX128X_CMD_SET_DIO_IRQ_PARAMS 0x8D +#define SX128X_CMD_GET_IRQ_STATUS 0x15 +#define SX128X_CMD_CLEAR_IRQ_STATUS 0x97 +#define SX128X_CMD_SET_REGULATOR_MODE 0x96 +#define SX128X_CMD_SET_SAVE_CONTEXT 0xD5 +#define SX128X_CMD_SET_AUTO_TX 0x98 +#define SX128X_CMD_SET_AUTO_FS 0x9E +#define SX128X_CMD_SET_PERF_COUNTER_MODE 0x9C +#define SX128X_CMD_SET_LONG_PREAMBLE 0x9B +#define SX128X_CMD_SET_UART_SPEED 0x9D +#define SX128X_CMD_SET_RANGING_ROLE 0xA3 +#define SX128X_CMD_SET_ADVANCED_RANGING 0x9A + +// SX128X register map +#define SX128X_REG_SYNC_WORD_1_BYTE_4 0x09CE +#define SX128X_REG_SYNC_WORD_1_BYTE_3 0x09CF +#define SX128X_REG_SYNC_WORD_1_BYTE_2 0x09D0 +#define SX128X_REG_SYNC_WORD_1_BYTE_1 0x09D1 +#define SX128X_REG_SYNC_WORD_1_BYTE_0 0x09D2 +#define SX128X_REG_SYNC_WORD_2_BYTE_4 0x09D3 +#define SX128X_REG_SYNC_WORD_2_BYTE_3 0x09D4 +#define SX128X_REG_SYNC_WORD_2_BYTE_2 0x09D5 +#define SX128X_REG_SYNC_WORD_2_BYTE_1 0x09D6 +#define SX128X_REG_SYNC_WORD_2_BYTE_0 0x09D7 +#define SX128X_REG_SYNC_WORD_3_BYTE_4 0x09D8 +#define SX128X_REG_SYNC_WORD_3_BYTE_3 0x09D9 +#define SX128X_REG_SYNC_WORD_3_BYTE_2 0x09DA +#define SX128X_REG_SYNC_WORD_3_BYTE_1 0x09DB +#define SX128X_REG_SYNC_WORD_3_BYTE_0 0x09DC +#define SX128X_REG_CRC_INITIAL_MSB 0x09C8 +#define SX128X_REG_CRC_INITIAL_LSB 0x09C9 +#define SX128X_REG_CRC_POLYNOMIAL_MSB 0x09C6 +#define SX128X_REG_CRC_POLYNOMIAL_LSB 0x09C7 +#define SX128X_REG_ACCESS_ADDRESS_BYTE_3 (SX128X_REG_SYNC_WORD_1_BYTE_3) +#define SX128X_REG_ACCESS_ADDRESS_BYTE_2 (SX128X_REG_SYNC_WORD_1_BYTE_2) +#define SX128X_REG_ACCESS_ADDRESS_BYTE_1 (SX128X_REG_SYNC_WORD_1_BYTE_1) +#define SX128X_REG_ACCESS_ADDRESS_BYTE_0 (SX128X_REG_SYNC_WORD_1_BYTE_0) +#define SX128X_REG_BLE_CRC_INITIAL_MSB 0x09C7 +#define SX128X_REG_BLE_CRC_INITIAL_MID (SX128X_REG_CRC_INITIAL_MSB) +#define SX128X_REG_BLE_CRC_INITIAL_LSB (SX128X_REG_CRC_INITIAL_LSB) +#define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_3 0x0916 +#define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_2 0x0917 +#define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_1 0x0918 +#define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_0 0x0919 +#define SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH 0x0931 +#define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_3 0x0912 +#define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_2 0x0913 +#define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_1 0x0914 +#define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_0 0x0915 +#define SX128X_REG_RANGING_CALIBRATION_MSB 0x092C +#define SX128X_REG_RANGING_CALIBRATION_LSB 0x092D +#define SX128X_REG_RANGING_RESULT_MSB 0x0961 +#define SX128X_REG_RANGING_RESULT_MID 0x0962 +#define SX128X_REG_RANGING_RESULT_LSB 0x0963 +#define SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1 0x089F +#define SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2 0x0895 +#define SX128X_REG_MANUAL_GAIN_SETTING 0x089E +#define SX128X_REG_GAIN_MODE 0x0891 +#define SX128X_REG_LORA_FIXED_PAYLOAD_LENGTH 0x0901 +#define SX128X_REG_LORA_SF_CONFIG 0x0925 +#define SX128X_REG_FEI_MSB 0x0954 +#define SX128X_REG_FEI_MID 0x0955 +#define SX128X_REG_FEI_LSB 0x0956 +#define SX128X_REG_RANGING_FILTER_WINDOW_SIZE 0x091E +#define SX128X_REG_RANGING_FILTER_RSSI_OFFSET 0x0953 +#define SX128X_REG_RANGING_FILTER_RESET 0x0923 +#define SX128X_REG_RANGING_LORA_CLOCK_ENABLE 0x097F +#define SX128X_REG_RANGING_TYPE 0x0924 +#define SX128X_REG_RANGING_ADDRESS_SWITCH 0x0927 +#define SX128X_REG_RANGING_ADDRESS_MSB 0x095F +#define SX128X_REG_RANGING_ADDRESS_LSB 0x0960 + + +// SX128X SPI command variables +//SX128X_CMD_GET_STATUS MSB LSB DESCRIPTION +#define SX128X_STATUS_MODE_STDBY_RC 0b01000000 // 7 5 current chip mode: STDBY_RC +#define SX128X_STATUS_MODE_STDBY_XOSC 0b01100000 // 7 5 STDBY_XOSC +#define SX128X_STATUS_MODE_FS 0b10000000 // 7 5 FS +#define SX128X_STATUS_MODE_RX 0b10100000 // 7 5 Rx +#define SX128X_STATUS_MODE_TX 0b11000000 // 7 5 Tx +#define SX128X_STATUS_CMD_PROCESSED 0b00000100 // 4 2 command status: processing OK +#define SX128X_STATUS_DATA_AVAILABLE 0b00001000 // 4 2 data available +#define SX128X_STATUS_CMD_TIMEOUT 0b00001100 // 4 2 timeout +#define SX128X_STATUS_CMD_ERROR 0b00010000 // 4 2 processing error +#define SX128X_STATUS_CMD_FAILED 0b00010100 // 4 2 failed to execute +#define SX128X_STATUS_TX_DONE 0b00011000 // 4 2 transmission finished +#define SX128X_STATUS_BUSY 0b00000001 // 0 0 chip busy +#define SX128X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed + +//SX128X_CMD_SET_SLEEP +#define SX128X_SLEEP_DATA_BUFFER_FLUSH 0b00000000 // 1 1 data buffer behavior in sleep mode: flush +#define SX128X_SLEEP_DATA_BUFFER_RETAIN 0b00000010 // 1 1 retain +#define SX128X_SLEEP_DATA_RAM_FLUSH 0b00000000 // 0 0 data RAM (configuration) behavior in sleep mode: flush +#define SX128X_SLEEP_DATA_RAM_RETAIN 0b00000001 // 0 0 retain + +//SX128X_CMD_SET_STANDBY +#define SX128X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator +#define SX128X_STANDBY_XOSC 0x01 // 7 0 52 MHz crystal oscillator + +//SX128X_CMD_SET_TX + SX128X_CMD_SET_RX + SX128X_CMD_SET_RX_DUTY_CYCLE +#define SX128X_PERIOD_BASE_15_625_US 0x00 // 7 0 time period step: 15.625 us +#define SX128X_PERIOD_BASE_62_5_US 0x01 // 7 0 62.5 us +#define SX128X_PERIOD_BASE_1_MS 0x02 // 7 0 1 ms +#define SX128X_PERIOD_BASE_4_MS 0x03 // 7 0 4 ms + +//SX128X_CMD_SET_TX +#define SX128X_TX_TIMEOUT_NONE 0x0000 // 15 0 Tx timeout duration: no timeout (Tx single mode) + +//SX128X_CMD_SET_RX +#define SX128X_RX_TIMEOUT_NONE 0x0000 // 15 0 Rx timeout duration: no timeout (Rx single mode) +#define SX128X_RX_TIMEOUT_INF 0xFFFF // 15 0 infinite (Rx continuous mode) + +//SX128X_CMD_SET_PACKET_TYPE +#define SX128X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: (G)FSK +#define SX128X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa +#define SX128X_PACKET_TYPE_RANGING 0x02 // 7 0 ranging engine +#define SX128X_PACKET_TYPE_FLRC 0x03 // 7 0 FLRC +#define SX128X_PACKET_TYPE_BLE 0x04 // 7 0 BLE + +//SX128X_CMD_SET_TX_PARAMS +#define SX128X_PA_RAMP_02_US 0x00 // 7 0 PA ramp time: 2 us +#define SX128X_PA_RAMP_04_US 0x20 // 7 0 4 us +#define SX128X_PA_RAMP_06_US 0x40 // 7 0 6 us +#define SX128X_PA_RAMP_08_US 0x60 // 7 0 8 us +#define SX128X_PA_RAMP_10_US 0x80 // 7 0 10 us +#define SX128X_PA_RAMP_12_US 0xA0 // 7 0 12 us +#define SX128X_PA_RAMP_16_US 0xC0 // 7 0 16 us +#define SX128X_PA_RAMP_20_US 0xE0 // 7 0 20 us + +//SX128X_CMD_SET_CAD_PARAMS +#define SX128X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1 +#define SX128X_CAD_ON_2_SYMB 0x20 // 7 0 2 +#define SX128X_CAD_ON_4_SYMB 0x40 // 7 0 4 +#define SX128X_CAD_ON_8_SYMB 0x60 // 7 0 8 +#define SX128X_CAD_ON_16_SYMB 0x80 // 7 0 16 + +//SX128X_CMD_SET_MODULATION_PARAMS +#define SX128X_BLE_GFSK_BR_2_000_BW_2_4 0x04 // 7 0 GFSK/BLE bit rate and bandwidth setting: 2.0 Mbps 2.4 MHz +#define SX128X_BLE_GFSK_BR_1_600_BW_2_4 0x28 // 7 0 1.6 Mbps 2.4 MHz +#define SX128X_BLE_GFSK_BR_1_000_BW_2_4 0x4C // 7 0 1.0 Mbps 2.4 MHz +#define SX128X_BLE_GFSK_BR_1_000_BW_1_2 0x45 // 7 0 1.0 Mbps 1.2 MHz +#define SX128X_BLE_GFSK_BR_0_800_BW_2_4 0x70 // 7 0 0.8 Mbps 2.4 MHz +#define SX128X_BLE_GFSK_BR_0_800_BW_1_2 0x69 // 7 0 0.8 Mbps 1.2 MHz +#define SX128X_BLE_GFSK_BR_0_500_BW_1_2 0x8D // 7 0 0.5 Mbps 1.2 MHz +#define SX128X_BLE_GFSK_BR_0_500_BW_0_6 0x86 // 7 0 0.5 Mbps 0.6 MHz +#define SX128X_BLE_GFSK_BR_0_400_BW_1_2 0xB1 // 7 0 0.4 Mbps 1.2 MHz +#define SX128X_BLE_GFSK_BR_0_400_BW_0_6 0xAA // 7 0 0.4 Mbps 0.6 MHz +#define SX128X_BLE_GFSK_BR_0_250_BW_0_6 0xCE // 7 0 0.25 Mbps 0.6 MHz +#define SX128X_BLE_GFSK_BR_0_250_BW_0_3 0xC7 // 7 0 0.25 Mbps 0.3 MHz +#define SX128X_BLE_GFSK_BR_0_125_BW_0_3 0xEF // 7 0 0.125 Mbps 0.3 MHz +#define SX128X_BLE_GFSK_MOD_IND_0_35 0x00 // 7 0 GFSK/BLE modulation index: 0.35 +#define SX128X_BLE_GFSK_MOD_IND_0_50 0x01 // 7 0 0.50 +#define SX128X_BLE_GFSK_MOD_IND_0_75 0x02 // 7 0 0.75 +#define SX128X_BLE_GFSK_MOD_IND_1_00 0x03 // 7 0 1.00 +#define SX128X_BLE_GFSK_MOD_IND_1_25 0x04 // 7 0 1.25 +#define SX128X_BLE_GFSK_MOD_IND_1_50 0x05 // 7 0 1.50 +#define SX128X_BLE_GFSK_MOD_IND_1_75 0x06 // 7 0 1.75 +#define SX128X_BLE_GFSK_MOD_IND_2_00 0x07 // 7 0 2.00 +#define SX128X_BLE_GFSK_MOD_IND_2_25 0x08 // 7 0 2.25 +#define SX128X_BLE_GFSK_MOD_IND_2_50 0x09 // 7 0 2.50 +#define SX128X_BLE_GFSK_MOD_IND_2_75 0x0A // 7 0 2.75 +#define SX128X_BLE_GFSK_MOD_IND_3_00 0x0B // 7 0 3.00 +#define SX128X_BLE_GFSK_MOD_IND_3_25 0x0C // 7 0 3.25 +#define SX128X_BLE_GFSK_MOD_IND_3_50 0x0D // 7 0 3.50 +#define SX128X_BLE_GFSK_MOD_IND_3_75 0x0E // 7 0 3.75 +#define SX128X_BLE_GFSK_MOD_IND_4_00 0x0F // 7 0 4.00 +#define SX128X_BLE_GFSK_BT_OFF 0x00 // 7 0 GFSK Gaussian filter BT product: filter disabled +#define SX128X_BLE_GFSK_BT_1_0 0x10 // 7 0 1.0 +#define SX128X_BLE_GFSK_BT_0_5 0x20 // 7 0 0.5 +#define SX128X_FLRC_BR_1_300_BW_1_2 0x45 // 7 0 FLRC bit rate and bandwidth setting: 1.3 Mbps 1.2 MHz +#define SX128X_FLRC_BR_1_000_BW_1_2 0x69 // 7 0 1.04 Mbps 1.2 MHz +#define SX128X_FLRC_BR_0_650_BW_0_6 0x86 // 7 0 0.65 Mbps 0.6 MHz +#define SX128X_FLRC_BR_0_520_BW_0_6 0xAA // 7 0 0.52 Mbps 0.6 MHz +#define SX128X_FLRC_BR_0_325_BW_0_3 0xC7 // 7 0 0.325 Mbps 0.3 MHz +#define SX128X_FLRC_BR_0_260_BW_0_3 0xEB // 7 0 0.260 Mbps 0.3 MHz +#define SX128X_FLRC_CR_1_2 0x00 // 7 0 FLRC coding rate: 1/2 +#define SX128X_FLRC_CR_3_4 0x02 // 7 0 3/4 +#define SX128X_FLRC_CR_1_0 0x04 // 7 0 1/1 +#define SX128X_FLRC_BT_OFF 0x00 // 7 0 FLRC Gaussian filter BT product: filter disabled +#define SX128X_FLRC_BT_1_0 0x10 // 7 0 1.0 +#define SX128X_FLRC_BT_0_5 0x20 // 7 0 0.5 +#define SX128X_LORA_SF_5 0x50 // 7 0 LoRa spreading factor: 5 +#define SX128X_LORA_SF_6 0x60 // 7 0 6 +#define SX128X_LORA_SF_7 0x70 // 7 0 7 +#define SX128X_LORA_SF_8 0x80 // 7 0 8 +#define SX128X_LORA_SF_9 0x90 // 7 0 9 +#define SX128X_LORA_SF_10 0xA0 // 7 0 10 +#define SX128X_LORA_SF_11 0xB0 // 7 0 11 +#define SX128X_LORA_SF_12 0xC0 // 7 0 12 +#define SX128X_LORA_BW_1625_00 0x0A // 7 0 LoRa bandwidth: 1625.0 kHz +#define SX128X_LORA_BW_812_50 0x18 // 7 0 812.5 kHz +#define SX128X_LORA_BW_406_25 0x26 // 7 0 406.25 kHz +#define SX128X_LORA_BW_203_125 0x34 // 7 0 203.125 kHz +#define SX128X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5 +#define SX128X_LORA_CR_4_6 0x02 // 7 0 4/6 +#define SX128X_LORA_CR_4_7 0x03 // 7 0 4/7 +#define SX128X_LORA_CR_4_8 0x04 // 7 0 4/8 +#define SX128X_LORA_CR_4_5_LI 0x05 // 7 0 4/5, long interleaving +#define SX128X_LORA_CR_4_6_LI 0x06 // 7 0 4/6, long interleaving +#define SX128X_LORA_CR_4_7_LI 0x07 // 7 0 4/7, long interleaving + +//SX128X_CMD_SET_PACKET_PARAMS +#define SX128X_GFSK_FLRC_SYNC_WORD_OFF 0x00 // 7 0 GFSK/FLRC sync word used: none +#define SX128X_GFSK_FLRC_SYNC_WORD_1 0x10 // 7 0 sync word 1 +#define SX128X_GFSK_FLRC_SYNC_WORD_2 0x20 // 7 0 sync word 2 +#define SX128X_GFSK_FLRC_SYNC_WORD_1_2 0x30 // 7 0 sync words 1 and 2 +#define SX128X_GFSK_FLRC_SYNC_WORD_3 0x40 // 7 0 sync word 3 +#define SX128X_GFSK_FLRC_SYNC_WORD_1_3 0x50 // 7 0 sync words 1 and 3 +#define SX128X_GFSK_FLRC_SYNC_WORD_2_3 0x60 // 7 0 sync words 2 and 3 +#define SX128X_GFSK_FLRC_SYNC_WORD_1_2_3 0x70 // 7 0 sync words 1, 2 and 3 +#define SX128X_GFSK_FLRC_PACKET_FIXED 0x00 // 7 0 GFSK/FLRC packet length mode: fixed +#define SX128X_GFSK_FLRC_PACKET_VARIABLE 0x20 // 7 0 variable +#define SX128X_GFSK_FLRC_CRC_OFF 0x00 // 7 0 GFSK/FLRC packet CRC: none +#define SX128X_GFSK_FLRC_CRC_1_BYTE 0x10 // 7 0 1 byte +#define SX128X_GFSK_FLRC_CRC_2_BYTE 0x20 // 7 0 2 bytes +#define SX128X_GFSK_FLRC_CRC_3_BYTE 0x30 // 7 0 3 bytes (FLRC only) +#define SX128X_GFSK_BLE_WHITENING_ON 0x00 // 7 0 GFSK/BLE whitening: enabled +#define SX128X_GFSK_BLE_WHITENING_OFF 0x08 // 7 0 disabled +#define SX128X_BLE_PAYLOAD_LENGTH_MAX_31 0x00 // 7 0 BLE maximum payload length: 31 bytes +#define SX128X_BLE_PAYLOAD_LENGTH_MAX_37 0x20 // 7 0 37 bytes +#define SX128X_BLE_PAYLOAD_LENGTH_TEST 0x40 // 7 0 63 bytes (test mode) +#define SX128X_BLE_PAYLOAD_LENGTH_MAX_255 0x80 // 7 0 255 bytes (Bluetooth 4.2 and above) +#define SX128X_BLE_CRC_OFF 0x00 // 7 0 BLE packet CRC: none +#define SX128X_BLE_CRC_3_BYTE 0x10 // 7 0 3 byte +#define SX128X_BLE_PRBS_9 0x00 // 7 0 BLE test payload contents: PRNG sequence using x^9 + x^5 + x +#define SX128X_BLE_EYELONG 0x04 // 7 0 repeated 0xF0 +#define SX128X_BLE_EYESHORT 0x08 // 7 0 repeated 0xAA +#define SX128X_BLE_PRBS_15 0x0C // 7 0 PRNG sequence using x^15 + x^14 + x^13 + x^12 + x^2 + x + 1 +#define SX128X_BLE_ALL_1 0x10 // 7 0 repeated 0xFF +#define SX128X_BLE_ALL_0 0x14 // 7 0 repeated 0x00 +#define SX128X_BLE_EYELONG_INV 0x18 // 7 0 repeated 0x0F +#define SX128X_BLE_EYESHORT_INV 0x1C // 7 0 repeated 0x55 +#define SX128X_FLRC_SYNC_WORD_OFF 0x00 // 7 0 FLRC sync word: disabled +#define SX128X_FLRC_SYNC_WORD_ON 0x04 // 7 0 enabled +#define SX128X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit +#define SX128X_LORA_HEADER_IMPLICIT 0x80 // 7 0 implicit +#define SX128X_LORA_CRC_OFF 0x00 // 7 0 LoRa packet CRC: disabled +#define SX128X_LORA_CRC_ON 0x20 // 7 0 enabled +#define SX128X_LORA_IQ_STANDARD 0x40 // 7 0 LoRa IQ: standard +#define SX128X_LORA_IQ_INVERTED 0x00 // 7 0 inverted + +//SX128X_CMD_GET_PACKET_STATUS +#define SX128X_PACKET_STATUS_SYNC_ERROR 0b01000000 // 6 6 packet status errors byte: sync word error +#define SX128X_PACKET_STATUS_LENGTH_ERROR 0b00100000 // 5 5 packet length error +#define SX128X_PACKET_STATUS_CRC_ERROR 0b00010000 // 4 4 CRC error +#define SX128X_PACKET_STATUS_ABORT_ERROR 0b00001000 // 3 3 packet reception aborted +#define SX128X_PACKET_STATUS_HEADER_RECEIVED 0b00000100 // 2 2 header received +#define SX128X_PACKET_STATUS_PACKET_RECEIVED 0b00000010 // 1 1 packet received +#define SX128X_PACKET_STATUS_PACKET_CTRL_BUSY 0b00000001 // 0 0 packet controller is busy +#define SX128X_PACKET_STATUS_RX_PID 0b11000000 // 7 6 packet status status byte: PID field of the received packet +#define SX128X_PACKET_STATUS_NO_ACK 0b00100000 // 5 5 NO_ACK field of the received packet +#define SX128X_PACKET_STATUS_RX_PID_ERROR 0b00010000 // 4 4 PID field error +#define SX128X_PACKET_STATUS_PACKET_SENT 0b00000001 // 0 0 packet sent +#define SX128X_PACKET_STATUS_SYNC_DET_ERROR 0b00000000 // 2 0 packet status sync byte: sync word detection error +#define SX128X_PACKET_STATUS_SYNC_DET_1 0b00000001 // 2 0 detected sync word 1 +#define SX128X_PACKET_STATUS_SYNC_DET_2 0b00000010 // 2 0 detected sync word 2 +#define SX128X_PACKET_STATUS_SYNC_DET_3 0b00000100 // 2 0 detected sync word 3 + +//SX128X_CMD_SET_DIO_IRQ_PARAMS +#define SX128X_IRQ_PREAMBLE_DETECTED 0x8000 // 15 15 interrupt source: preamble detected +#define SX128X_IRQ_ADVANCED_RANGING_DONE 0x8000 // 15 15 advanced ranging done +#define SX128X_IRQ_RX_TX_TIMEOUT 0x4000 // 14 14 Rx or Tx timeout +#define SX128X_IRQ_CAD_DETECTED 0x2000 // 13 13 channel activity detected +#define SX128X_IRQ_CAD_DONE 0x1000 // 12 12 CAD finished +#define SX128X_IRQ_RANGING_SLAVE_REQ_VALID 0x0800 // 11 11 ranging request valid (slave) +#define SX128X_IRQ_RANGING_MASTER_TIMEOUT 0x0400 // 10 10 ranging timeout (master) +#define SX128X_IRQ_RANGING_MASTER_RES_VALID 0x0200 // 9 9 ranging result valid (master) +#define SX128X_IRQ_RANGING_SLAVE_REQ_DISCARD 0x0100 // 8 8 ranging result valid (master) +#define SX128X_IRQ_RANGING_SLAVE_RESP_DONE 0x0080 // 7 7 ranging response complete (slave) +#define SX128X_IRQ_CRC_ERROR 0x0040 // 6 6 CRC error +#define SX128X_IRQ_HEADER_ERROR 0x0020 // 5 5 header error +#define SX128X_IRQ_HEADER_VALID 0x0010 // 4 4 header valid +#define SX128X_IRQ_SYNC_WORD_ERROR 0x0008 // 3 3 sync word error +#define SX128X_IRQ_SYNC_WORD_VALID 0x0004 // 2 2 sync word valid +#define SX128X_IRQ_RX_DONE 0x0002 // 1 1 Rx done +#define SX128X_IRQ_TX_DONE 0x0001 // 0 0 Tx done +#define SX128X_IRQ_NONE 0x0000 // 15 0 none +#define SX128X_IRQ_ALL 0xFFFF // 15 0 all + +/*! + \class SX128x + + \brief Base class for %SX128x series. All derived classes for %SX128x (e.g. SX1280 or SX1281) inherit from this base class. + This class should not be instantiated directly from Arduino sketch, only from its derived classes. +*/ +class SX128x: public PhysicalLayer { + public: + // introduce PhysicalLayer overloads + using PhysicalLayer::transmit; + using PhysicalLayer::receive; + using PhysicalLayer::startTransmit; + using PhysicalLayer::readData; + + /*! + \brief Default constructor. + + \param mod Instance of Module that will be used to communicate with the radio. + */ + SX128x(Module* mod); + + // basic methods + + /*! + \brief Initialization method for LoRa modem. + + \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz. + + \param bw LoRa bandwidth in kHz. Defaults to 812.5 kHz. + + \param sf LoRa spreading factor. Defaults to 9. + + \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). + + \param power Output power in dBm. Defaults to 10 dBm. + + \param preambleLength LoRa preamble length in symbols. Defaults to 12 symbols. + + \returns \ref status_codes + */ + int16_t begin(float freq = 2400.0, float bw = 812.5, uint8_t sf = 9, uint8_t cr = 7, int8_t power = 10, uint16_t preambleLength = 12); + + /*! + \brief Initialization method for GFSK modem. + + \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz. + + \param br FSK bit rate in kbps. Defaults to 800 kbps. + + \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 400.0 kHz. + + \param power Output power in dBm. Defaults to 10 dBm. + + \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. + + \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. + + \returns \ref status_codes + */ + int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); + + /*! + \brief Reset method. Will reset the chip to the default state using RST pin. + + \param verify Whether correct module startup should be verified. When set to true, RadioLib will attempt to verify the module has started correctly + by repeatedly issuing setStandby command. Enabled by default. + + \returns \ref status_codes + */ + int16_t reset(bool verify = true); + + /*! + \brief Blocking binary transmit method. + Overloads for string-based transmissions are implemented in PhysicalLayer. + + \param data Binary data to be sent. + + \param len Number of bytes to send. + + \param addr Address to send the data to. Will only be added if address filtering was enabled. + + \returns \ref status_codes + */ + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + + /*! + \brief Blocking binary receive method. + Overloads for string-based transmissions are implemented in PhysicalLayer. + + \param data Binary data to be sent. + + \param len Number of bytes to send. + + \returns \ref status_codes + */ + int16_t receive(uint8_t* data, size_t len); + + /*! + \brief Starts direct mode transmission. + + \param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY. + + \returns \ref status_codes + */ + int16_t transmitDirect(uint32_t frf = 0); + + /*! + \brief Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as %SX128x series does not support direct mode reception. + Will always return ERR_UNKNOWN. + + \returns \ref status_codes + */ + int16_t receiveDirect(); + + /*! + \brief Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. + + \returns \ref status_codes + */ + int16_t scanChannel(); + + /*! + \brief Sets the module to sleep mode. + + \param retainConfig Set to true to retain configuration and data buffer or to false to discard current configuration and data buffer. Defaults to true. + + \returns \ref status_codes + */ + int16_t sleep(bool retainConfig = true); + + /*! + \brief Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator). + + \returns \ref status_codes + */ + int16_t standby(); + + /*! + \brief Sets the module to standby mode. + + \param mode Oscillator to be used in standby mode. Can be set to SX128X_STANDBY_RC (13 MHz RC oscillator) or SX128X_STANDBY_XOSC (52 MHz external crystal oscillator). + + \returns \ref status_codes + */ + int16_t standby(uint8_t mode); + + // interrupt methods + + /*! + \brief Sets interrupt service routine to call when DIO1 activates. + + \param func ISR to call. + */ + void setDio1Action(void (*func)(void)); + + /*! + \brief Clears interrupt service routine to call when DIO1 activates. + */ + void clearDio1Action(); + + /*! + \brief Interrupt-driven binary transmit method. + Overloads for string-based transmissions are implemented in PhysicalLayer. + + \param data Binary data to be sent. + + \param len Number of bytes to send. + + \param addr Address to send the data to. Will only be added if address filtering was enabled. + + \returns \ref status_codes + */ + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + + /*! + \brief Interrupt-driven receive method. DIO1 will be activated when full packet is received. + + \param timeout Raw timeout value, expressed as multiples of 15.625 us. Defaults to SX128X_RX_TIMEOUT_INF for infinite timeout (Rx continuous mode), set to SX128X_RX_TIMEOUT_NONE for no timeout (Rx single mode). + + \returns \ref status_codes + */ + int16_t startReceive(uint16_t timeout = SX128X_RX_TIMEOUT_INF); + + /*! + \brief Reads data received after calling startReceive method. + + \param data Pointer to array to save the received binary data. + + \param len Number of bytes that will be received. Must be known in advance for binary transmissions. + + \returns \ref status_codes + */ + int16_t readData(uint8_t* data, size_t len); + + // configuration methods + + /*! + \brief Sets carrier frequency. Allowed values are in range from 2400.0 to 2500.0 MHz. + + \param freq Carrier frequency to be set in MHz. + + \returns \ref status_codes + */ + int16_t setFrequency(float freq); + + /*! + \brief Sets LoRa bandwidth. Allowed values are 203.125, 406.25, 812.5 and 1625.0 kHz. + + \param bw LoRa bandwidth to be set in kHz. + + \returns \ref status_codes + */ + int16_t setBandwidth(float bw); + + /*! + \brief Sets LoRa spreading factor. Allowed values range from 5 to 12. + + \param sf LoRa spreading factor to be set. + + \returns \ref status_codes + */ + int16_t setSpreadingFactor(uint8_t sf); + + /*! + \brief Sets LoRa coding rate denominator. Allowed values range from 5 to 8. + + \param cr LoRa coding rate denominator to be set. + + \param longInterleaving Whether to enable long interleaving mode. Not available for coding rate 4/7, defaults to false. + + \returns \ref status_codes + */ + int16_t setCodingRate(uint8_t cr, bool longInterleaving = false); + + /*! + \brief Sets output power. Allowed values are in range from -18 to 13 dBm. + + \param power Output power to be set in dBm. + + \returns \ref status_codes + */ + int16_t setOutputPower(int8_t power); + + /*! + \brief Sets preamble length for currently active modem. Allowed values range from 1 to 65535. + + \param preambleLength Preamble length to be set in symbols (LoRa) or bits (FSK/BLE/FLRC). + + \returns \ref status_codes + */ + int16_t setPreambleLength(uint32_t preambleLength); + + /*! + \brief Sets FSK bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps. + + \param br FSK bit rate to be set in kbps. + + \returns \ref status_codes + */ + int16_t setBitRate(uint16_t br); + + /*! + \brief Sets FSK frequency deviation. Allowed values range from 0.0 to 3200.0 kHz. + + \param freqDev FSK frequency deviation to be set in kHz. + + \returns \ref status_codes + */ + int16_t setFrequencyDeviation(float freqDev); + + /*! + \brief Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are 0.5 and 1.0. Set to 0 to disable shaping. + + \param sh Time-bandwidth product of Gaussian filter to be set. + + \returns \ref status_codes + */ + int16_t setDataShaping(float dataShaping); + + /*! + \brief Sets sync word in the form of array of up to 8 bytes. + + \param syncWord Sync word to be set. + + \param len Sync word length in bytes. + + \returns \ref status_codes + */ + int16_t setSyncWord(uint8_t* syncWord, uint8_t len); + + /*! + \brief Sets CRC configuration. + + \param len CRC length in bytes, Allowed values are 1, 2 or 3, set to 0 to disable CRC. + + \param initial Initial CRC value. Defaults to 0x1D0F (CCIT CRC), not available for LoRa modem. + + \param polynomial Polynomial for CRC calculation. Defaults to 0x1021 (CCIT CRC), not available for LoRa or BLE modem. + + \returns \ref status_codes + */ + int16_t setCRC(uint8_t len, uint32_t initial = 0x1D0F, uint16_t polynomial = 0x1021); + + /*! + \brief Sets whitening parameters, not available for LoRa or FLRC modem. + + \param enabled Set to true to enable whitening. + + \returns \ref status_codes + */ + int16_t setWhitening(bool enabled); + + /*! + \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. + + \returns RSSI of the last received packet in dBm. + */ + float getRSSI(); + + /*! + \brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem. + + \returns SNR of the last received packet in dB. + */ + float getSNR(); + + /*! + \brief Query modem for the packet length of received payload. + + \param update Update received packet length. Will return cached value when set to false. + + \returns Length of last received packet in bytes. + */ + size_t getPacketLength(bool update = true); + + /*! + \brief Get expected time-on-air for a given size of payload. + + \param len Payload length in bytes. + + \returns Expected time-on-air in microseconds. + */ + uint32_t getTimeOnAir(size_t len); + + /*! + \brief Set implicit header mode for future reception/transmission. + + \returns \ref status_codes + */ + int16_t implicitHeader(size_t len); + + /*! + \brief Set explicit header mode for future reception/transmission. + + \param len Payload length in bytes. + + \returns \ref status_codes + */ + int16_t explicitHeader(); + + /*! + \brief Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility. + + \param encoding Encoding to be used. Set to 0 for NRZ, and 2 for whitening. + + \returns \ref status_codes + */ + int16_t setEncoding(uint8_t encoding); + +#ifndef RADIOLIB_GODMODE + protected: +#endif + // SX128x SPI command implementations + uint8_t getStatus(); + int16_t writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes); + int16_t readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes); + int16_t writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00); + int16_t readBuffer(uint8_t* data, uint8_t numBytes); + int16_t setTx(uint16_t periodBaseCount = SX128X_TX_TIMEOUT_NONE, uint8_t periodBase = SX128X_PERIOD_BASE_15_625_US); + int16_t setRx(uint16_t periodBaseCount, uint8_t periodBase = SX128X_PERIOD_BASE_15_625_US); + int16_t setCad(); + uint8_t getPacketType(); + int16_t setRfFrequency(uint32_t frf); + int16_t setTxParams(uint8_t power, uint8_t rampTime = SX128X_PA_RAMP_10_US); + int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00); + int16_t setModulationParams(uint8_t modParam1, uint8_t modParam2, uint8_t modParam3); + int16_t setPacketParamsGFSK(uint8_t preambleLen, uint8_t syncWordLen, uint8_t syncWordMatch, uint8_t crcLen, uint8_t whitening, uint8_t payloadLen = 0xFF, uint8_t headerType = SX128X_GFSK_FLRC_PACKET_VARIABLE); + int16_t setPacketParamsBLE(uint8_t connState, uint8_t crcLen, uint8_t bleTestPayload, uint8_t whitening); + int16_t setPacketParamsLoRa(uint8_t preambleLen, uint8_t headerType, uint8_t payloadLen, uint8_t crc, uint8_t invertIQ = SX128X_LORA_IQ_STANDARD); + int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = SX128X_IRQ_NONE, uint16_t dio3Mask = SX128X_IRQ_NONE); + uint16_t getIrqStatus(); + int16_t clearIrqStatus(uint16_t clearIrqParams = SX128X_IRQ_ALL); + + int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF); + +#ifndef RADIOLIB_GODMODE + private: +#endif + Module* _mod; + + // common parameters + uint8_t _pwr; + + // cached LoRa parameters + float _bwKhz; + uint8_t _bw, _sf, _cr; + uint8_t _preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa; + + // cached GFSK parameters + float _modIndexReal; + uint16_t _brKbps; + uint8_t _br, _modIndex, _shaping; + uint8_t _preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening; + + // cached BLE parameters + uint8_t _connectionState, _crcBLE, _bleTestPayload; + + int16_t config(uint8_t modem); + + // common low-level SPI interface + int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); + int16_t SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); + int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); + int16_t SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); + int16_t SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy, uint32_t timeout = 5000); +}; + +#endif From acc2fd36f69607eb9895f2f17de7b1981217d0f2 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 7 Apr 2020 13:30:20 +0200 Subject: [PATCH 055/334] [Morse] Added note about SX128x usage --- examples/Morse/Morse_Transmit/Morse_Transmit.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/Morse/Morse_Transmit/Morse_Transmit.ino b/examples/Morse/Morse_Transmit/Morse_Transmit.ino index 0cf02e6e..e0d6d1fe 100644 --- a/examples/Morse/Morse_Transmit/Morse_Transmit.ino +++ b/examples/Morse/Morse_Transmit/Morse_Transmit.ino @@ -12,6 +12,7 @@ - SX126x - nRF24 - Si443x/RFM2x + - SX128x */ // include the library @@ -44,7 +45,7 @@ void setup() { // current limit: 100 mA // sync word: 0x2D 0x01 int state = fsk.beginFSK(); - + // when using one of the non-LoRa modules for Morse code // (RF69, CC1101, Si4432 etc.), use the basic begin() method // int state = fsk.begin(); From 4b0c68e2973e1a20677491cffadf3c7fbc1f7f36 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 7 Apr 2020 13:30:27 +0200 Subject: [PATCH 056/334] [RTTY] Added note about SX128x usage --- examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino b/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino index d456b041..f565c6f0 100644 --- a/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino +++ b/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino @@ -12,6 +12,7 @@ - SX126x - nRF24 - Si443x/RFM2x + - SX128x For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ @@ -70,6 +71,7 @@ void setup() { // SX126x - 1 Hz // nRF24 - 1000000 Hz // Si443x/RFM2x - 156 Hz + // SX128x - 198 Hz Serial.print(F("[RTTY] Initializing ... ")); // low ("space") frequency: 434.0 MHz // frequency shift: 183 Hz From 5eb92ef4dcfcdaddc94141cd455563686c35019d Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 7 Apr 2020 13:41:44 +0200 Subject: [PATCH 057/334] Updated readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9f5e2dc0..1884cd88 100644 --- a/README.md +++ b/README.md @@ -21,16 +21,17 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * __RFM2x__ series FSK modules (RFM22, RM23) * __RFM9x__ series LoRa modules (RFM95, RM96, RFM97, RFM98) * __Si443x__ series FSK modules (Si4430, Si4431, Si4432) -* __SX127x__ series LoRa modules (SX1272, SX1273, SX1276, SX1277, SX1278, SX1279) * __SX126x__ series LoRa modules (SX1261, SX1262, SX1268) +* __SX127x__ series LoRa modules (SX1272, SX1273, SX1276, SX1277, SX1278, SX1279) +* __SX128x__ series LoRa/GFSK/BLE/FLRC modules (SX1280, SX1281, SX1282) * __SX1231__ FSK/OOK radio module * __XBee__ modules (S2B) ### Supported protocols: * __MQTT__ for modules: ESP8266 * __HTTP__ for modules: ESP8266 -* __RTTY__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x -* __Morse Code__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x +* __RTTY__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x +* __Morse Code__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x * __AX.25__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x * __SSTV__ for modules: SX127x, RFM9x, SX126x, RF69 and SX1231 From 46be8529154a34c32dd3574c416dd6d3f39c393a Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 7 Apr 2020 13:42:09 +0200 Subject: [PATCH 058/334] [SX128x] Removed reference to unsupported method --- examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino index 9b93c481..1ee3a7a4 100644 --- a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino +++ b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino @@ -60,7 +60,6 @@ void setup() { state = gfsk.setFrequency(2410.5); state = gfsk.setBitRate(200); state = gfsk.setFrequencyDeviation(100.0); - state = gfsk.setRxBandwidth(250.0); state = gfsk.setOutputPower(5); state = gfsk.setDataShaping(1.0); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89}; From 7c9f422e0c9820c4af2d96b889eda5089353b743 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 7 Apr 2020 13:42:30 +0200 Subject: [PATCH 059/334] [SX128x] Fixed type conflict in max() --- src/modules/SX128x/SX128x.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index a11b1788..186e7d86 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -841,8 +841,8 @@ uint32_t SX128x::getTimeOnAir(size_t len) { // get SF coefficients float coeff1 = 0; - uint8_t coeff2 = 0; - uint8_t coeff3 = 0; + int16_t coeff2 = 0; + int16_t coeff3 = 0; if(sf < 7) { // SF5, SF6 coeff1 = 6.25; @@ -861,13 +861,13 @@ uint32_t SX128x::getTimeOnAir(size_t len) { } // get CRC length - uint8_t N_bitCRC = 16; + int16_t N_bitCRC = 16; if(_crcLoRa == SX128X_LORA_CRC_OFF) { N_bitCRC = 0; } // get header length - uint8_t N_symbolHeader = 20; + int16_t N_symbolHeader = 20; if(_headerType == SX128X_LORA_HEADER_IMPLICIT) { N_symbolHeader = 0; } @@ -876,7 +876,7 @@ uint32_t SX128x::getTimeOnAir(size_t len) { uint32_t N_symbolPreamble = (_preambleLengthLoRa & 0x0F) * (uint32_t(1) << ((_preambleLengthLoRa & 0xF0) >> 4)); // calculate the number of symbols - N_symbol = (float)N_symbolPreamble + coeff1 + 8.0 + ceil(max(8 * len + N_bitCRC - coeff2 + N_symbolHeader, 0) / (float)coeff3) * (float)(_cr + 4); + N_symbol = (float)N_symbolPreamble + coeff1 + 8.0 + ceil(max((int16_t)(8 * len + N_bitCRC - coeff2 + N_symbolHeader), (int16_t)0) / (float)coeff3) * (float)(_cr + 4); } else { // long interleaving - abandon hope all ye who enter here From f8c9b5d03a01c74fc4649047f47be3f6d85cbf20 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 9 Apr 2020 09:58:35 +0200 Subject: [PATCH 060/334] [SX128x] Fixed incorrect status code --- src/modules/SX128x/SX128x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 186e7d86..c61900a5 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -604,7 +604,7 @@ int16_t SX128x::setBitRate(uint16_t br) { } else if(br == 2000) { _br = SX128X_BLE_GFSK_BR_2_000_BW_2_4; } else { - return(ERR_INVALID_BIT_RANGE); + return(ERR_INVALID_BIT_RATE); } // update modulation parameters From 635c008e26ca718b0121604ae33acd6c3e3e1024 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 9 Apr 2020 09:59:31 +0200 Subject: [PATCH 061/334] [SX128x] Fixed bug in ToA calculation for non-LoRa modems (#132) --- src/modules/SX128x/SX128x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index c61900a5..369d7b67 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -888,7 +888,7 @@ uint32_t SX128x::getTimeOnAir(size_t len) { return(((uint32_t(1) << sf) / _bwKhz) * N_symbol * 1000.0); } else { - return((len * 8) / _brKbps); + return(((uint32_t)len * 8 * 1000) / _brKbps); } } From 5c0c7f32c301855c699d481403c3161e3ed556d5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 9 Apr 2020 12:10:38 +0200 Subject: [PATCH 062/334] [SX128x] Set default regulator mode to DC-DC --- src/modules/SX128x/SX128x.cpp | 5 +++++ src/modules/SX128x/SX128x.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 369d7b67..4b765b6d 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -1034,6 +1034,11 @@ int16_t SX128x::config(uint8_t modem) { state = SPIwriteCommand(SX128X_CMD_SET_CAD_PARAMS, data, 1); RADIOLIB_ASSERT(state); + // set regulator mode to DC-DC + data[0] = SX128X_REGULATOR_DC_DC; + state = SPIwriteCommand(SX128X_CMD_SET_REGULATOR_MODE, data, 1); + RADIOLIB_ASSERT(state); + return(ERR_NONE); } diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 2e74f7e0..a06a4cca 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -318,6 +318,11 @@ #define SX128X_IRQ_NONE 0x0000 // 15 0 none #define SX128X_IRQ_ALL 0xFFFF // 15 0 all +//SX128X_CMD_SET_REGULATOR_MODE +#define SX128X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default) +#define SX128X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC + + /*! \class SX128x From ff3225cd199c95da7e0bc6acc81ba5ce0f439cef Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 12 Apr 2020 11:05:16 +0200 Subject: [PATCH 063/334] [SX128x] Added FLRC modem support --- .../SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino | 114 ++++++++++ .../SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino | 1 - keywords.txt | 5 + src/modules/SX128x/SX128x.cpp | 202 ++++++++++++++---- src/modules/SX128x/SX128x.h | 28 ++- 5 files changed, 304 insertions(+), 46 deletions(-) create mode 100644 examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino diff --git a/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino b/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino new file mode 100644 index 00000000..1f28b834 --- /dev/null +++ b/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino @@ -0,0 +1,114 @@ +/* + RadioLib SX128x FLRC Modem Example + + This example shows how to use FLRC modem in SX128x chips. + + NOTE: The sketch below is just a guide on how to use + FLRC modem, so this code should not be run directly! + Instead, modify the other examples to use FLRC + modem and use the appropriate configuration + methods. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 flrc = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 flrc = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bit rate: 650 kbps + // coding rate: 3 + // output power: 10 dBm + // preamble length: 16 bits + // data shaping: Gaussian, BT = 0.5 + // sync word: 0x2D 0x01 0x4B 0x1D + // CRC: enabled + int state = flrc.beginFLRC(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // if needed, you can switch between LoRa and FLRC modes + // + // flrc.begin() start LoRa mode (and disable FLRC) + // lora.beginFLRC() start FLRC mode (and disable LoRa) + + // the following settings can also + // be modified at run-time + state = flrc.setFrequency(2410.5); + state = flrc.setBitRate(200); + state = flrc.setCodingRate(2); + state = flrc.setOutputPower(5); + state = flrc.setDataShaping(1.0); + uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67}; + state = flrc.setSyncWord(syncWord, 4); + if (state != ERR_NONE) { + Serial.print(F("Unable to set configuration, code ")); + Serial.println(state); + while (true); + } + + #warning "This sketch is just an API guide! Read the note at line 6." +} + +void loop() { + // FLRC modem can use the same transmit/receive methods + // as the LoRa modem, even their interrupt-driven versions + + // transmit FLRC packet + int state = flrc.transmit("Hello World!"); + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + int state = flrc.transmit(byteArr, 8); + */ + if (state == ERR_NONE) { + Serial.println(F("[SX1280] Packet transmitted successfully!")); + } else if (state == ERR_PACKET_TOO_LONG) { + Serial.println(F("[SX1280] Packet too long!")); + } else if (state == ERR_TX_TIMEOUT) { + Serial.println(F("[SX1280] Timed out while transmitting!")); + } else { + Serial.println(F("[SX1280] Failed to transmit packet, code ")); + Serial.println(state); + } + + // receive GFSK packet + String str; + state = flrc.receive(str); + /* + byte byteArr[8]; + int state = flrc.receive(byteArr, 8); + */ + if (state == ERR_NONE) { + Serial.println(F("[SX1280] Received packet!")); + Serial.print(F("[SX1280] Data:\t")); + Serial.println(str); + } else if (state == ERR_RX_TIMEOUT) { + Serial.println(F("[SX1280] Timed out while waiting for packet!")); + } else { + Serial.print(F("[SX1280] Failed to receive packet, code ")); + Serial.println(state); + } +} diff --git a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino index 1ee3a7a4..adfc5320 100644 --- a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino +++ b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino @@ -37,7 +37,6 @@ void setup() { // frequency deviation: 400.0 kHz // output power: 10 dBm // preamble length: 16 bits - // coding rate: 7 // data shaping: Gaussian, BT = 0.5 // sync word: 0x2D 0x01 // CRC: enabled, CRC16 (CCIT) diff --git a/keywords.txt b/keywords.txt index d42b2c73..af21ca40 100644 --- a/keywords.txt +++ b/keywords.txt @@ -214,6 +214,11 @@ getPictureHeight KEYWORD2 # SX128x beginGFSK KEYWORD2 +beginFLRC KEYWORD2 +beginBLE KEYWORD2 +range KEYWORD2 +startRanging KEYWORD2 +getRangingResult KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 4b765b6d..73a25fe5 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -114,6 +114,64 @@ int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, return(state); } +int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t power, uint16_t preambleLength, float dataShaping) { + // set module properties + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); + Module::pinMode(_mod->getGpio(), INPUT); + + // initialize FLRC modulation variables + _brKbps = br; + _br = SX128X_FLRC_BR_0_650_BW_0_6; + _crFLRC = SX128X_FLRC_CR_3_4; + _shaping = SX128X_FLRC_BT_0_5; + + // initialize FLRC packet variables + _preambleLengthGFSK = preambleLength; + _syncWordLen = 2; + _syncWordMatch = SX128X_GFSK_FLRC_SYNC_WORD_1; + _crcGFSK = SX128X_GFSK_FLRC_CRC_2_BYTE; + _whitening = SX128X_GFSK_BLE_WHITENING_OFF; + + // reset the module and verify startup + int16_t state = reset(); + RADIOLIB_ASSERT(state); + + // set mode to standby + state = standby(); + RADIOLIB_ASSERT(state); + + // configure settings not accessible by API + state = config(SX128X_PACKET_TYPE_FLRC); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setFrequency(freq); + RADIOLIB_ASSERT(state); + + state = setBitRate(br); + RADIOLIB_ASSERT(state); + + state = setCodingRate(cr); + RADIOLIB_ASSERT(state); + + state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + state = setPreambleLength(preambleLength); + RADIOLIB_ASSERT(state); + + state = setDataShaping(dataShaping); + RADIOLIB_ASSERT(state); + + // set publicly accessible settings that are not a part of begin method + uint8_t sync[] = { 0x2D, 0x01, 0x4B, 0x1D}; + state = setSyncWord(sync, 4); + RADIOLIB_ASSERT(state); + + return(state); +} + int16_t SX128x::reset(bool verify) { // run the reset sequence - same as SX126x, as SX128x docs don't seem to mention this Module::pinMode(_mod->getRst(), OUTPUT); @@ -336,7 +394,7 @@ int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { uint8_t modem = getPacketType(); if(modem == SX128X_PACKET_TYPE_LORA) { state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, len, _crcLoRa); - } else if(modem == SX128X_PACKET_TYPE_GFSK) { + } else if((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_FLRC)) { state = setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening, len); } else { return(ERR_WRONG_MODEM); @@ -406,6 +464,11 @@ int16_t SX128x::startReceive(uint16_t timeout) { } int16_t SX128x::readData(uint8_t* data, size_t len) { + // check active modem + if(getPacketType() == SX128X_PACKET_TYPE_RANGING) { + return(ERR_WRONG_MODEM); + } + // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); @@ -511,19 +574,29 @@ int16_t SX128x::setSpreadingFactor(uint8_t sf) { int16_t SX128x::setCodingRate(uint8_t cr, bool longInterleaving) { // check active modem uint8_t modem = getPacketType(); - if(!((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING))) { - return(ERR_WRONG_MODEM); + + // LoRa/ranging + if((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING)) { + RADIOLIB_CHECK_RANGE(cr, 5, 8, ERR_INVALID_CODING_RATE); + + // update modulation parameters + if(longInterleaving && (modem == SX128X_PACKET_TYPE_LORA)) { + _cr = cr; + } else { + _cr = cr - 4; + } + return(setModulationParams(_sf, _bw, _cr)); + + // FLRC + } else if(modem == SX128X_PACKET_TYPE_FLRC) { + RADIOLIB_CHECK_RANGE(cr, 2, 4, ERR_INVALID_CODING_RATE); + + // update modulation parameters + _crFLRC = (cr - 2) * 2; + return(setModulationParams(_br, _crFLRC, _shaping)); } - RADIOLIB_CHECK_RANGE(cr, 5, 8, ERR_INVALID_CODING_RATE); - - // update modulation parameters - if(longInterleaving && (modem == SX128X_PACKET_TYPE_LORA)) { - _cr = cr; - } else { - _cr = cr - 4; - } - return(setModulationParams(_sf, _bw, _cr)); + return(ERR_WRONG_MODEM); } int16_t SX128x::setOutputPower(int8_t power) { @@ -583,33 +656,58 @@ int16_t SX128x::setPreambleLength(uint32_t preambleLength) { int16_t SX128x::setBitRate(uint16_t br) { // check active modem uint8_t modem = getPacketType(); - if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE))) { - return(ERR_WRONG_MODEM); + + // GFSK/BLE + if((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE)) { + if(br == 125) { + _br = SX128X_BLE_GFSK_BR_0_125_BW_0_3; + } else if(br == 250) { + _br = SX128X_BLE_GFSK_BR_0_250_BW_0_6; + } else if(br == 400) { + _br = SX128X_BLE_GFSK_BR_0_400_BW_1_2; + } else if(br == 500) { + _br = SX128X_BLE_GFSK_BR_0_500_BW_1_2; + } else if(br == 800) { + _br = SX128X_BLE_GFSK_BR_0_800_BW_2_4; + } else if(br == 1000) { + _br = SX128X_BLE_GFSK_BR_1_000_BW_2_4; + } else if(br == 1600) { + _br = SX128X_BLE_GFSK_BR_1_600_BW_2_4; + } else if(br == 2000) { + _br = SX128X_BLE_GFSK_BR_2_000_BW_2_4; + } else { + return(ERR_INVALID_BIT_RATE); + } + + // update modulation parameters + _brKbps = br; + return(setModulationParams(_br, _modIndex, _shaping)); + + // FLRC + } else if(modem == SX128X_PACKET_TYPE_FLRC) { + if(br == 260) { + _br = SX128X_FLRC_BR_0_260_BW_0_3; + } else if(br == 325) { + _br = SX128X_FLRC_BR_0_325_BW_0_3; + } else if(br == 520) { + _br = SX128X_FLRC_BR_0_520_BW_0_6; + } else if(br == 650) { + _br = SX128X_FLRC_BR_0_650_BW_0_6; + } else if(br == 1000) { + _br = SX128X_FLRC_BR_1_000_BW_1_2; + } else if(br == 1300) { + _br = SX128X_FLRC_BR_1_300_BW_1_2; + } else { + return(ERR_INVALID_BIT_RATE); + } + + // update modulation parameters + _brKbps = br; + return(setModulationParams(_br, _crFLRC, _shaping)); + } - if(br == 125) { - _br = SX128X_BLE_GFSK_BR_0_125_BW_0_3; - } else if(br == 250) { - _br = SX128X_BLE_GFSK_BR_0_250_BW_0_6; - } else if(br == 400) { - _br = SX128X_BLE_GFSK_BR_0_400_BW_1_2; - } else if(br == 500) { - _br = SX128X_BLE_GFSK_BR_0_500_BW_1_2; - } else if(br == 800) { - _br = SX128X_BLE_GFSK_BR_0_800_BW_2_4; - } else if(br == 1000) { - _br = SX128X_BLE_GFSK_BR_1_000_BW_2_4; - } else if(br == 1600) { - _br = SX128X_BLE_GFSK_BR_1_600_BW_2_4; - } else if(br == 2000) { - _br = SX128X_BLE_GFSK_BR_2_000_BW_2_4; - } else { - return(ERR_INVALID_BIT_RATE); - } - - // update modulation parameters - _brKbps = br; - return(setModulationParams(_br, _modIndex, _shaping)); + return(ERR_WRONG_MODEM); } int16_t SX128x::setFrequencyDeviation(float freqDev) { @@ -642,7 +740,7 @@ int16_t SX128x::setFrequencyDeviation(float freqDev) { int16_t SX128x::setDataShaping(float dataShaping) { // check active modem uint8_t modem = getPacketType(); - if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE))) { + if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE) || (modem == SX128X_PACKET_TYPE_FLRC))) { return(ERR_WRONG_MODEM); } @@ -659,7 +757,11 @@ int16_t SX128x::setDataShaping(float dataShaping) { } // update modulation parameters - return(setModulationParams(_br, _modIndex, _shaping)); + if((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE)) { + return(setModulationParams(_br, _modIndex, _shaping)); + } else { + return(setModulationParams(_br, _crFLRC, _shaping)); + } } int16_t SX128x::setSyncWord(uint8_t* syncWord, uint8_t len) { @@ -669,8 +771,25 @@ int16_t SX128x::setSyncWord(uint8_t* syncWord, uint8_t len) { return(ERR_WRONG_MODEM); } - if(len > 5) { - return(ERR_INVALID_SYNC_WORD); + if(modem == SX128X_PACKET_TYPE_GFSK) { + // GFSK can use up to 5 bytes as sync word + if(len > 5) { + return(ERR_INVALID_SYNC_WORD); + } + + // calculate sync word length parameter value + if(len > 0) { + _syncWordLen = (len - 1)*2; + } + + } else { + // FLRC requires 32-bit sync word + if(!((len == 0) || (len == 4))) { + return(ERR_INVALID_SYNC_WORD); + } + + // save sync word length parameter value + _syncWordLen = len; } // reverse sync word byte order @@ -684,7 +803,6 @@ int16_t SX128x::setSyncWord(uint8_t* syncWord, uint8_t len) { RADIOLIB_ASSERT(state); // update packet parameters - _syncWordLen = len; if(_syncWordLen == 0) { _syncWordMatch = SX128X_GFSK_FLRC_SYNC_WORD_OFF; } else { diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index a06a4cca..6548f511 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -384,6 +384,25 @@ class SX128x: public PhysicalLayer { */ int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); + /*! + \brief Initialization method for FLRC modem. + + \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz. + + \param br FLRC bit rate in kbps. Defaults to 650 kbps. + + \param cr FLRC coding rate. Defaults to 3 (coding rate 3/4). + + \param power Output power in dBm. Defaults to 10 dBm. + + \parma preambleLength FLRC preamble length in bits. Defaults to 16 bits. + + \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. + + \returns \ref status_codes + */ + int16_t beginFLRC(float freq = 2400.0, uint16_t br = 650, uint8_t cr = 3, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); + /*! \brief Reset method. Will reset the chip to the default state using RST pin. @@ -576,9 +595,9 @@ class SX128x: public PhysicalLayer { int16_t setPreambleLength(uint32_t preambleLength); /*! - \brief Sets FSK bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps. + \brief Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem). - \param br FSK bit rate to be set in kbps. + \param br FSK/FLRC bit rate to be set in kbps. \returns \ref status_codes */ @@ -603,7 +622,7 @@ class SX128x: public PhysicalLayer { int16_t setDataShaping(float dataShaping); /*! - \brief Sets sync word in the form of array of up to 8 bytes. + \brief Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long \param syncWord Sync word to be set. @@ -737,6 +756,9 @@ class SX128x: public PhysicalLayer { uint8_t _br, _modIndex, _shaping; uint8_t _preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening; + // cached FLRC parameters + uint8_t _crFLRC; + // cached BLE parameters uint8_t _connectionState, _crcBLE, _bleTestPayload; From a355a098e6543cb2101f10b5a2d517e7c6301a65 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 12 Apr 2020 11:32:07 +0200 Subject: [PATCH 064/334] [SX128x] Added BLE modem support --- .../SX128x_BLE_Modem/SX128x_BLE_Modem.ino | 114 ++++++++++++++++++ keywords.txt | 1 + src/modules/SX128x/SX128x.cpp | 61 +++++++++- src/modules/SX128x/SX128x.h | 26 ++++ 4 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino diff --git a/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino b/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino new file mode 100644 index 00000000..166215b7 --- /dev/null +++ b/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino @@ -0,0 +1,114 @@ +/* + RadioLib SX128x BLE Modem Example + + This example shows how to use BLE modem in SX128x chips. + RadioLib does not provide BLE protocol support (yet), + only compatibility with the physical layer. + + NOTE: The sketch below is just a guide on how to use + BLE modem, so this code should not be run directly! + Instead, modify the other examples to use BLE + modem and use the appropriate configuration + methods. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 ble = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 ble = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bit rate: 800 kbps + // frequency deviation: 400.0 kHz + // output power: 10 dBm + // preamble length: 16 bits + // data shaping: Gaussian, BT = 0.5 + // CRC: enabled, CRC16 (CCIT) + int state = ble.beginBLE(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // if needed, you can switch between LoRa and FSK modes + // + // ble.begin() start LoRa mode (and disable BLE) + // lora.beginBLE() start BLE mode (and disable LoRa) + + // the following settings can also + // be modified at run-time + state = ble.setFrequency(2410.5); + state = ble.setBitRate(200); + state = ble.setFrequencyDeviation(100.0); + state = ble.setOutputPower(5); + state = ble.setDataShaping(1.0); + state = ble.setAccessAddress(0x12345678); + if (state != ERR_NONE) { + Serial.print(F("Unable to set configuration, code ")); + Serial.println(state); + while (true); + } + + #warning "This sketch is just an API guide! Read the note at line 6." +} + +void loop() { + // BLE modem can use the same transmit/receive methods + // as the LoRa modem, even their interrupt-driven versions + + // transmit BLE packet + int state = ble.transmit("Hello World!"); + /* + byte byteArr[] = {0x01, 0x23, 0x45, 0x67, + 0x89, 0xAB, 0xCD, 0xEF}; + int state = ble.transmit(byteArr, 8); + */ + if (state == ERR_NONE) { + Serial.println(F("[SX1280] Packet transmitted successfully!")); + } else if (state == ERR_PACKET_TOO_LONG) { + Serial.println(F("[SX1280] Packet too long!")); + } else if (state == ERR_TX_TIMEOUT) { + Serial.println(F("[SX1280] Timed out while transmitting!")); + } else { + Serial.println(F("[SX1280] Failed to transmit packet, code ")); + Serial.println(state); + } + + // receive BLE packet + String str; + state = ble.receive(str); + /* + byte byteArr[8]; + int state = ble.receive(byteArr, 8); + */ + if (state == ERR_NONE) { + Serial.println(F("[SX1280] Received packet!")); + Serial.print(F("[SX1280] Data:\t")); + Serial.println(str); + } else if (state == ERR_RX_TIMEOUT) { + Serial.println(F("[SX1280] Timed out while waiting for packet!")); + } else { + Serial.print(F("[SX1280] Failed to receive packet, code ")); + Serial.println(state); + } +} diff --git a/keywords.txt b/keywords.txt index af21ca40..6afdf6ba 100644 --- a/keywords.txt +++ b/keywords.txt @@ -216,6 +216,7 @@ getPictureHeight KEYWORD2 beginGFSK KEYWORD2 beginFLRC KEYWORD2 beginBLE KEYWORD2 +setAccessAddress KEYWORD2 range KEYWORD2 startRanging KEYWORD2 getRangingResult KEYWORD2 diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 73a25fe5..2404e420 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -114,6 +114,54 @@ int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, return(state); } +int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, float dataShaping) { + // set module properties + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); + Module::pinMode(_mod->getGpio(), INPUT); + + // initialize BLE modulation variables + _brKbps = br; + _br = SX128X_BLE_GFSK_BR_0_800_BW_2_4; + _modIndexReal = 1.0; + _modIndex = SX128X_BLE_GFSK_MOD_IND_1_00; + _shaping = SX128X_BLE_GFSK_BT_0_5; + + // initialize BLE packet variables + _crcGFSK = SX128X_BLE_CRC_3_BYTE; + _whitening = SX128X_GFSK_BLE_WHITENING_ON; + + // reset the module and verify startup + int16_t state = reset(); + RADIOLIB_ASSERT(state); + + // set mode to standby + state = standby(); + RADIOLIB_ASSERT(state); + + // configure settings not accessible by API + state = config(SX128X_PACKET_TYPE_BLE); + RADIOLIB_ASSERT(state); + + // configure publicly accessible settings + state = setFrequency(freq); + RADIOLIB_ASSERT(state); + + state = setBitRate(br); + RADIOLIB_ASSERT(state); + + state = setFrequencyDeviation(freqDev); + RADIOLIB_ASSERT(state); + + state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + state = setDataShaping(dataShaping); + RADIOLIB_ASSERT(state); + + return(state); +} + int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t power, uint16_t preambleLength, float dataShaping) { // set module properties _mod->init(RADIOLIB_USE_SPI); @@ -468,7 +516,7 @@ int16_t SX128x::readData(uint8_t* data, size_t len) { if(getPacketType() == SX128X_PACKET_TYPE_RANGING) { return(ERR_WRONG_MODEM); } - + // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); @@ -896,6 +944,17 @@ int16_t SX128x::setWhitening(bool enabled) { return(setPacketParamsBLE(_connectionState, _crcBLE, _bleTestPayload, _whitening)); } +int16_t SX128x::setAccessAddress(uint32_t addr) { + // check active modem + if(getPacketType() != SX128X_PACKET_TYPE_BLE) { + return(ERR_WRONG_MODEM); + } + + // use setSyncWord to set the address + uint8_t syncWord[] = { (uint8_t)((addr >> 24) & 0xFF), (uint8_t)((addr >> 16) & 0xFF), (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; + return(setSyncWord(syncWord, 4)); +} + float SX128x::getRSSI() { // get packet status uint8_t packetStatus[5]; diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 6548f511..82e19884 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -384,6 +384,23 @@ class SX128x: public PhysicalLayer { */ int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); + /*! + \brief Initialization method for BLE modem. + + \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz. + + \param br BLE bit rate in kbps. Defaults to 800 kbps. + + \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 400.0 kHz. + + \param power Output power in dBm. Defaults to 10 dBm. + + \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. + + \returns \ref status_codes + */ + int16_t beginBLE(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, float dataShaping = 0.5); + /*! \brief Initialization method for FLRC modem. @@ -654,6 +671,15 @@ class SX128x: public PhysicalLayer { */ int16_t setWhitening(bool enabled); + /*! + \brief Sets BLE access address. + + \param addr BLE access address. + + \returns \ref status_codes + */ + int16_t setAccessAddress(uint32_t addr); + /*! \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. From 1592831e0c99913e6cea2a3a619961c69fe99c3f Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 12 Apr 2020 13:47:56 +0200 Subject: [PATCH 065/334] [SX128x] Implemented ranging --- .../SX128x/SX128x_Ranging/SX128x_Ranging.ino | 84 ++++++++++++++ keywords.txt | 2 + src/TypeDef.h | 7 ++ src/modules/SX128x/SX1280.cpp | 108 ++++++++++++++++++ src/modules/SX128x/SX1280.h | 31 ++++- src/modules/SX128x/SX128x.cpp | 10 ++ src/modules/SX128x/SX128x.h | 20 ++-- 7 files changed, 253 insertions(+), 9 deletions(-) create mode 100644 examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino diff --git a/examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino b/examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino new file mode 100644 index 00000000..585f948b --- /dev/null +++ b/examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino @@ -0,0 +1,84 @@ +/* + RadioLib SX128x Ranging Example + + This example performs ranging exchange between two + SX1280 LoRa radio modules. Ranging allows to measure + distance between the modules using time-of-flight + measurement. + + Only SX1280 and SX1282 support ranging! + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1280 has the following connections: +// NSS pin: 10 +// DIO1 pin: 2 +// NRST pin: 3 +// BUSY pin: 9 +SX1280 lora = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1280 lora = RadioShield.ModuleA; + +void setup() { + Serial.begin(9600); + + // initialize SX1280 with default settings + Serial.print(F("[SX1280] Initializing ... ")); + // carrier frequency: 2400.0 MHz + // bandwidth: 812.5 kHz + // spreading factor: 9 + // coding rate: 7 + // output power: 10 dBm + // preamble length: 12 symbols + // CRC: enabled + int state = lora.begin(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } +} + +void loop() { + Serial.print(F("[SX1280] Ranging ... ")); + + // start ranging exchange + // range as master: true + // slave address: 0x12345678 + int state = lora.range(true, 0x12345678); + + // the other module must be configured as slave with the same address + /* + int state = lora.range(false, 0x12345678); + */ + + if (state == ERR_NONE) { + // ranging finished successfully + Serial.println(F("success!")); + Serial.print(F("[SX1280] Distance:\t\t\t")); + Serial.print(lora.getRangingResult()); + Serial.println(F(" meters")); + + } else if (state == ERR_RANGING_TIMEOUT) { + // timed out waiting for ranging packet + Serial.println(F("timed out!")); + + } else { + // some other error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } + + // wait for a second before ranging again + delay(1000); +} diff --git a/keywords.txt b/keywords.txt index 6afdf6ba..bcc233c4 100644 --- a/keywords.txt +++ b/keywords.txt @@ -311,3 +311,5 @@ ERR_INVALID_RX_PERIOD LITERAL1 ERR_INVALID_CALLSIGN LITERAL1 ERR_INVALID_NUM_REPEATERS LITERAL1 ERR_INVALID_REPEATER_CALLSIGN LITERAL1 + +ERR_RANGING_TIMEOUT LITERAL1 diff --git a/src/TypeDef.h b/src/TypeDef.h index 00ef2096..f8254d3d 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -480,6 +480,13 @@ */ #define ERR_INVALID_REPEATER_CALLSIGN -803 +// SX128x-specific status codes + +/*! + \brief Timed out waiting for ranging exchange finish. +*/ +#define ERR_RANGING_TIMEOUT -901 + /*! \} */ diff --git a/src/modules/SX128x/SX1280.cpp b/src/modules/SX128x/SX1280.cpp index afbc96df..2c4d09ee 100644 --- a/src/modules/SX128x/SX1280.cpp +++ b/src/modules/SX128x/SX1280.cpp @@ -3,3 +3,111 @@ SX1280::SX1280(Module* mod) : SX1281(mod) { } + +int16_t SX1280::range(bool master, uint32_t addr) { + // start ranging + int16_t state = startRanging(master, addr); + RADIOLIB_ASSERT(state); + + // wait until ranging is finished + uint32_t start = millis(); + while(!digitalRead(_mod->getIrq())) { + yield(); + if(millis() - start > 10000) { + clearIrqStatus(); + standby(); + return(ERR_RANGING_TIMEOUT); + } + } + + // clear interrupt flags + state = clearIrqStatus(); + RADIOLIB_ASSERT(state); + + // set mode to standby + state = standby(); + + return(state); +} + +int16_t SX1280::startRanging(bool master, uint32_t addr) { + // check active modem + uint8_t modem = getPacketType(); + if(!((modem == SX128X_PACKET_TYPE_LORA) || (modem == SX128X_PACKET_TYPE_RANGING))) { + return(ERR_WRONG_MODEM); + } + + // ensure modem is set to ranging + int16_t state = ERR_NONE; + if(modem == SX128X_PACKET_TYPE_LORA) { + state = setPacketType(SX128X_PACKET_TYPE_RANGING); + RADIOLIB_ASSERT(state); + } + + // set modulation parameters + state = setModulationParams(_sf, _bw, _cr); + RADIOLIB_ASSERT(state); + + // set packet parameters + state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa); + RADIOLIB_ASSERT(state); + + // check all address bits + uint8_t regValue; + state = readRegister(SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, ®Value, 1); + RADIOLIB_ASSERT(state); + regValue &= 0b00111111; + regValue |= 0b11000000; + state = writeRegister(SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, ®Value, 1); + RADIOLIB_ASSERT(state); + + // set remaining parameter values + uint32_t addrReg = SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_3; + uint32_t irqMask = SX128X_IRQ_RANGING_SLAVE_RESP_DONE | SX128X_IRQ_RANGING_SLAVE_REQ_DISCARD; + uint32_t irqDio1 = SX128X_IRQ_RANGING_SLAVE_RESP_DONE; + if(master) { + addrReg = SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_3; + irqMask = SX128X_IRQ_RANGING_MASTER_RES_VALID | SX128X_IRQ_RANGING_MASTER_TIMEOUT; + irqDio1 = SX128X_IRQ_RANGING_MASTER_RES_VALID; + } + + // set ranging address + uint8_t addrBuff[] = { (uint8_t)((addr >> 24) & 0xFF), (uint8_t)((addr >> 16) & 0xFF), (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; + state = writeRegister(addrReg, addrBuff, 4); + RADIOLIB_ASSERT(state); + + // set DIO mapping + state = setDioIrqParams(irqMask, irqDio1); + RADIOLIB_ASSERT(state); + + // set role and start ranging + if(master) { + state = setRangingRole(SX128X_RANGING_ROLE_MASTER); + RADIOLIB_ASSERT(state); + + state = setTx(SX128X_TX_TIMEOUT_NONE); + RADIOLIB_ASSERT(state); + + } else { + state = setRangingRole(SX128X_RANGING_ROLE_SLAVE); + RADIOLIB_ASSERT(state); + + state = setRx(SX128X_RX_TIMEOUT_INF); + RADIOLIB_ASSERT(state); + + } + + return(state); +} + +float SX1280::getRangingResult() { + // read the register values + uint8_t data[4]; + int16_t state = readRegister(SX128X_REG_RANGING_RESULT_MSB, data + 1, 3); + RADIOLIB_ASSERT(state); + + // calculate the real result + uint32_t raw = 0; + memcpy(&raw, data, sizeof(uint32_t)); + return((float)raw * (150.0/(4.096 * _bwKhz))); +} diff --git a/src/modules/SX128x/SX1280.h b/src/modules/SX128x/SX1280.h index 08aa1ec1..ea8c5a18 100644 --- a/src/modules/SX128x/SX1280.h +++ b/src/modules/SX128x/SX1280.h @@ -6,8 +6,6 @@ #include "SX128x.h" #include "SX1281.h" -// TODO implement ranging - /*! \class SX1280 @@ -22,6 +20,35 @@ class SX1280: public SX1281 { */ SX1280(Module* mod); + /*! + \brief Blocking ranging method. + + \param master Whether to execute ranging in master mode (true) or slave mode (false). + + \param addr Ranging address to be used. + + \returns \ref status_codes + */ + int16_t range(bool master, uint32_t addr); + + /*! + \brief Interrupt-driven ranging method. + + \param master Whether to execute ranging in master mode (true) or slave mode (false). + + \param addr Ranging address to be used. + + \returns \ref status_codes + */ + int16_t startRanging(bool master, uint32_t addr); + + /*! + \brief Gets ranging result of the last ranging exchange. + + \returns Ranging result in meters. + */ + float getRangingResult(); + #ifndef RADIOLIB_GODMODE private: #endif diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 2404e420..e4dae862 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -1182,6 +1182,16 @@ int16_t SX128x::clearIrqStatus(uint16_t clearIrqParams) { return(SPIwriteCommand(SX128X_CMD_CLEAR_IRQ_STATUS, data, 2)); } +int16_t SX128x::setRangingRole(uint8_t role) { + uint8_t data[] = { role }; + return(SPIwriteCommand(SX128X_CMD_SET_RANGING_ROLE, data, 1)); +} + +int16_t SX128x::setPacketType(uint8_t type) { + uint8_t data[] = { type }; + return(SPIwriteCommand(SX128X_CMD_SET_PACKET_TYPE, data, 1)); +} + int16_t SX128x::setHeaderType(uint8_t headerType, size_t len) { // check active modem uint8_t modem = getPacketType(); diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 82e19884..f093a3c9 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -322,6 +322,10 @@ #define SX128X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default) #define SX128X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC +//SX128X_CMD_SET_RANGING_ROLE +#define SX128X_RANGING_ROLE_MASTER 0x01 // 7 0 ranging role: master +#define SX128X_RANGING_ROLE_SLAVE 0x00 // 7 0 slave + /*! \class SX128x @@ -740,6 +744,13 @@ class SX128x: public PhysicalLayer { #ifndef RADIOLIB_GODMODE protected: #endif + Module* _mod; + + // cached LoRa parameters + float _bwKhz; + uint8_t _bw, _sf, _cr; + uint8_t _preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa; + // SX128x SPI command implementations uint8_t getStatus(); int16_t writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes); @@ -760,22 +771,17 @@ class SX128x: public PhysicalLayer { int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = SX128X_IRQ_NONE, uint16_t dio3Mask = SX128X_IRQ_NONE); uint16_t getIrqStatus(); int16_t clearIrqStatus(uint16_t clearIrqParams = SX128X_IRQ_ALL); + int16_t setRangingRole(uint8_t role); + int16_t setPacketType(uint8_t type); int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF); #ifndef RADIOLIB_GODMODE private: #endif - Module* _mod; - // common parameters uint8_t _pwr; - // cached LoRa parameters - float _bwKhz; - uint8_t _bw, _sf, _cr; - uint8_t _preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa; - // cached GFSK parameters float _modIndexReal; uint16_t _brKbps; From abad47bdaea864d50cb92a8ac44c7065c677f900 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 14 Apr 2020 09:33:39 +0200 Subject: [PATCH 066/334] [Hell] Added Hellschreiber support --- README.md | 13 +- .../Hellschreiber_Transmit.ino | 117 ++++++++ keywords.txt | 4 + src/RadioLib.h | 1 + src/protocols/Hellschreiber/Hellschreiber.cpp | 271 ++++++++++++++++++ src/protocols/Hellschreiber/Hellschreiber.h | 151 ++++++++++ 6 files changed, 551 insertions(+), 6 deletions(-) create mode 100644 examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino create mode 100644 src/protocols/Hellschreiber/Hellschreiber.cpp create mode 100644 src/protocols/Hellschreiber/Hellschreiber.h diff --git a/README.md b/README.md index 1884cd88..c62b393a 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ ## See the [Wiki](https://github.com/jgromes/RadioLib/wiki) for further information. See the [GitHub Pages](https://jgromes.github.io/RadioLib) for detailed and up-to-date API reference. -RadioLib allows its users to integrate all sorts of different wireless communication modules into a single consistent system. -Want to add a Bluetooth interface to your ZigBee network? Sure thing! Need to connect LoRa network to the Internet with a GSM module? RadioLib has got your back! +RadioLib allows its users to integrate all sorts of different wireless communication modules, protocols and even digital modes into a single consistent system. +Want to add a Bluetooth interface to your LoRa network? Sure thing! Do you just want to go really old-school and play around with radio teletype, slow-scan TV, or even Hellschreiber using nothing but a cheap radio module? Why not! RadioLib was originally created as a driver for [__RadioShield__](https://github.com/jgromes/RadioShield), but it can be used to control as many different wireless modules as you like - or at least as many as your Arduino can handle! @@ -27,13 +27,14 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * __SX1231__ FSK/OOK radio module * __XBee__ modules (S2B) -### Supported protocols: +### Supported protocols and digital modes: * __MQTT__ for modules: ESP8266 * __HTTP__ for modules: ESP8266 -* __RTTY__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x -* __Morse Code__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x * __AX.25__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x -* __SSTV__ for modules: SX127x, RFM9x, SX126x, RF69 and SX1231 +* [__RTTY__](https://www.sigidwiki.com/wiki/RTTY) for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x +* [__Morse Code__](https://www.sigidwiki.com/wiki/Morse_Code_(CW)) for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x +* [__SSTV__](https://www.sigidwiki.com/wiki/SSTV) for modules: SX127x, RFM9x, SX126x, RF69 and SX1231 +* [__Hellschreiber__](https://www.sigidwiki.com/wiki/Hellschreiber) for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x ### Supported platforms: * __Arduino AVR__ - tested with hardware on Uno, Mega and Leonardo diff --git a/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino b/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino new file mode 100644 index 00000000..c1d74d31 --- /dev/null +++ b/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino @@ -0,0 +1,117 @@ +/* + RadioLib Hellschreiber Transmit Example + + This example sends Hellschreiber message using + SX1278's FSK modem. + + Other modules that can be used for Hellschreiber: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - SX126x + - nRF24 + - Si443x/RFM2x + - SX128x +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1278 fsk = RadioShield.ModuleA; + +// create Hellschreiber client instance using the FSK module +HellClient hell(&fsk); + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + // sync word: 0x2D 0x01 + int state = fsk.beginFSK(); + + // when using one of the non-LoRa modules for Morse code + // (RF69, CC1101, Si4432 etc.), use the basic begin() method + // int state = fsk.begin(); + + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // initialize Hellschreiber client + Serial.print(F("[Hell] Initializing ... ")); + // base frequency: 434.0 MHz + // speed: 122.5 Baud ("Feld Hell") + state = hell.begin(434.0); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } +} + +void loop() { + Serial.print(F("[Hell] Sending Hellschreiber data ... ")); + + // HellClient supports all methods of the Serial class + // NOTE: Lower case letter will be capitalized. + + // Arduino String class + String aStr = "Arduino String"; + hell.print(aStr); + + // character array (C-String) + hell.print("C-String"); + + // string saved in flash + hell.print(F("Flash String")); + + // character + hell.print('c'); + + // byte + // formatting DEC/HEX/OCT/BIN is supported for + // any integer type (byte/int/long) + hell.print(255, HEX); + + // integer number + int i = 1000; + hell.print(i); + + // floating point number + // NOTE: println() has no effect on the transmission, + // and is only kept for compatibility reasons. + float f = -3.1415; + hell.println(f, 3); + + // custom glyph - must be a 7 byte array of rows 7 pixels long + uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 }; + hell.printGlyph(customGlyph); + + Serial.println(F("done!")); + + // wait for a second before transmitting again + delay(1000); +} diff --git a/keywords.txt b/keywords.txt index bcc233c4..21e58818 100644 --- a/keywords.txt +++ b/keywords.txt @@ -52,6 +52,7 @@ PagerClient KEYWORD1 AX25Client KEYWORD1 AX25Frame KEYWORD1 SSTVClient KEYWORD1 +HellClient KEYWORD1 # SSTV modes Scottie1 KEYWORD1 @@ -221,6 +222,9 @@ range KEYWORD2 startRanging KEYWORD2 getRangingResult KEYWORD2 +# Hellschreiber +printGlyph KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### diff --git a/src/RadioLib.h b/src/RadioLib.h index d4911d51..04ea18e7 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -86,6 +86,7 @@ // physical layer protocols #include "protocols/PhysicalLayer/PhysicalLayer.h" #include "protocols/AX25/AX25.h" +#include "protocols/Hellschreiber/Hellschreiber.h" #include "protocols/Morse/Morse.h" #include "protocols/RTTY/RTTY.h" #include "protocols/SSTV/SSTV.h" diff --git a/src/protocols/Hellschreiber/Hellschreiber.cpp b/src/protocols/Hellschreiber/Hellschreiber.cpp new file mode 100644 index 00000000..ffc30ee3 --- /dev/null +++ b/src/protocols/Hellschreiber/Hellschreiber.cpp @@ -0,0 +1,271 @@ +#include "Hellschreiber.h" + +HellClient::HellClient(PhysicalLayer* phy) { + _phy = phy; +} + +int16_t HellClient::begin(float base, float rate) { + // calculate 24-bit frequency + _base = (base * 1000000.0) / _phy->getFreqStep(); + + // calculate "pixel" duration + _pixelDuration = 1000000.0/rate; + + // set module frequency deviation to 0 + int16_t state = _phy->setFrequencyDeviation(0); + + return(state); +} + +size_t HellClient::printGlyph(uint8_t* buff) { + // print the character + for(uint8_t mask = 0x40; mask >= 0x01; mask >>= 1) { + for(int8_t i = HELL_FONT_HEIGHT - 1; i >= 0; i--) { + uint32_t start = micros(); + if(buff[i] & mask) { + _phy->transmitDirect(_base); + } else { + _phy->standby(); + } + while(micros() - start < _pixelDuration); + } + } + + // make sure transmitter is off + _phy->standby(); + + return(1); +} + +size_t HellClient::write(const char* str) { + if(str == NULL) { + return(0); + } + return(HellClient::write((uint8_t *)str, strlen(str))); +} + +size_t HellClient::write(uint8_t* buff, size_t len) { + size_t n = 0; + for(size_t i = 0; i < len; i++) { + n += HellClient::write(buff[i]); + } + return(n); +} + +size_t HellClient::write(uint8_t b) { + // convert to position in font buffer + uint8_t pos = b; + if((pos >= ' ') && (pos <= '_')) { + pos -= ' '; + } else if((pos >= 'a') && (pos <= 'z')) { + pos -= (2*' '); + } else { + return(0); + } + + // fetch character from flash + uint8_t buff[HELL_FONT_WIDTH]; + buff[0] = 0x00; + for(uint8_t i = 0; i < HELL_FONT_WIDTH - 2; i++) { + buff[i + 1] = pgm_read_byte(&HellFont[pos][i]); + } + buff[HELL_FONT_WIDTH - 1] = 0x00; + + // print the character + return(printGlyph(buff)); +} + +size_t HellClient::print(__FlashStringHelper* fstr) { + PGM_P p = reinterpret_cast(fstr); + size_t n = 0; + while(true) { + char c = pgm_read_byte(p++); + if(c == '\0') { + break; + } + n += HellClient::write(c); + } + return n; +} + +size_t HellClient::print(const String& str) { + return(HellClient::write((uint8_t*)str.c_str(), str.length())); +} + +size_t HellClient::print(const char* str) { + return(HellClient::write((uint8_t*)str, strlen(str))); +} + +size_t HellClient::print(char c) { + return(HellClient::write(c)); +} + +size_t HellClient::print(unsigned char b, int base) { + return(HellClient::print((unsigned long)b, base)); +} + +size_t HellClient::print(int n, int base) { + return(HellClient::print((long)n, base)); +} + +size_t HellClient::print(unsigned int n, int base) { + return(HellClient::print((unsigned long)n, base)); +} + +size_t HellClient::print(long n, int base) { + if(base == 0) { + return(HellClient::write(n)); + } else if(base == DEC) { + if (n < 0) { + int t = HellClient::print('-'); + n = -n; + return(HellClient::printNumber(n, DEC) + t); + } + return(HellClient::printNumber(n, DEC)); + } else { + return(HellClient::printNumber(n, base)); + } +} + +size_t HellClient::print(unsigned long n, int base) { + if(base == 0) { + return(HellClient::write(n)); + } else { + return(HellClient::printNumber(n, base)); + } +} + +size_t HellClient::print(double n, int digits) { + return(HellClient::printFloat(n, digits)); +} + +size_t HellClient::println(void) { + return(0); +} + +size_t HellClient::println(__FlashStringHelper* fstr) { + size_t n = HellClient::print(fstr); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(const String& str) { + size_t n = HellClient::print(str); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(const char* str) { + size_t n = HellClient::print(str); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(char c) { + size_t n = HellClient::print(c); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(unsigned char b, int base) { + size_t n = HellClient::print(b, base); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(int num, int base) { + size_t n = HellClient::print(num, base); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(unsigned int num, int base) { + size_t n = HellClient::print(num, base); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(long num, int base) { + size_t n = HellClient::print(num, base); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(unsigned long num, int base) { + size_t n = HellClient::print(num, base); + n += HellClient::println(); + return(n); +} + +size_t HellClient::println(double d, int digits) { + size_t n = HellClient::print(d, digits); + n += HellClient::println(); + return(n); +} + +size_t HellClient::printNumber(unsigned long n, uint8_t base) { + char buf[8 * sizeof(long) + 1]; + char *str = &buf[sizeof(buf) - 1]; + + *str = '\0'; + + if(base < 2) { + base = 10; + } + + do { + char c = n % base; + n /= base; + + *--str = c < 10 ? c + '0' : c + 'A' - 10; + } while(n); + + return(HellClient::write(str)); +} + +size_t HellClient::printFloat(double number, uint8_t digits) { + size_t n = 0; + + char code[] = {0x00, 0x00, 0x00, 0x00}; + if (isnan(number)) strcpy(code, "nan"); + if (isinf(number)) strcpy(code, "inf"); + if (number > 4294967040.0) strcpy(code, "ovf"); // constant determined empirically + if (number <-4294967040.0) strcpy(code, "ovf"); // constant determined empirically + + if(code[0] != 0x00) { + return(HellClient::write(code)); + } + + // Handle negative numbers + if (number < 0.0) { + n += HellClient::print('-'); + number = -number; + } + + // Round correctly so that print(1.999, 2) prints as "2.00" + double rounding = 0.5; + for(uint8_t i = 0; i < digits; ++i) { + rounding /= 10.0; + } + number += rounding; + + // Extract the integer part of the number and print it + unsigned long int_part = (unsigned long)number; + double remainder = number - (double)int_part; + n += HellClient::print(int_part); + + // Print the decimal point, but only if there are digits beyond + if(digits > 0) { + n += HellClient::print('.'); + } + + // Extract digits from the remainder one at a time + while(digits-- > 0) { + remainder *= 10.0; + unsigned int toPrint = (unsigned int)(remainder); + n += HellClient::print(toPrint); + remainder -= toPrint; + } + + return n; +} diff --git a/src/protocols/Hellschreiber/Hellschreiber.h b/src/protocols/Hellschreiber/Hellschreiber.h new file mode 100644 index 00000000..9b14c27e --- /dev/null +++ b/src/protocols/Hellschreiber/Hellschreiber.h @@ -0,0 +1,151 @@ +#ifndef _RADIOLIB_HELLSCHREIBER_H +#define _RADIOLIB_HELLSCHREIBER_H + +#include "../../TypeDef.h" +#include "../PhysicalLayer/PhysicalLayer.h" + +#define HELL_FONT_WIDTH 7 +#define HELL_FONT_HEIGHT 7 + +// font definition: characters are stored in rows, +// least significant byte of each character is the first row +// Hellschreiber use 7x7 characters, but this simplified font uses only 5x5 - the extra bytes aren't stored +static const uint8_t HellFont[64][HELL_FONT_WIDTH - 2] PROGMEM = { + { 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000 }, // space + { 0b0001000, 0b0001000, 0b0001000, 0b0000000, 0b0001000 }, // ! + { 0b0010100, 0b0010100, 0b0000000, 0b0000000, 0b0000000 }, // " + { 0b0010100, 0b0111110, 0b0010100, 0b0111110, 0b0010100 }, // # + { 0b0111110, 0b0101000, 0b0111110, 0b0001010, 0b0111110 }, // $ + { 0b0110010, 0b0110100, 0b0001000, 0b0010110, 0b0100110 }, // % + { 0b0010000, 0b0101000, 0b0010000, 0b0101000, 0b0110100 }, // & + { 0b0001000, 0b0001000, 0b0000000, 0b0000000, 0b0000000 }, // ' + { 0b0000100, 0b0001000, 0b0001000, 0b0001000, 0b0000100 }, // ( + { 0b0010000, 0b0001000, 0b0001000, 0b0001000, 0b0010000 }, // ) + { 0b0010100, 0b0001000, 0b0010100, 0b0000000, 0b0000000 }, // * + { 0b0001000, 0b0001000, 0b0111110, 0b0001000, 0b0001000 }, // + + { 0b0001000, 0b0010000, 0b0000000, 0b0000000, 0b0000000 }, // ´ + { 0b0000000, 0b0000000, 0b0111110, 0b0000000, 0b0000000 }, // - + { 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0001000 }, // . + { 0b0000010, 0b0000100, 0b0001000, 0b0010000, 0b0100000 }, // / + { 0b0011100, 0b0100110, 0b0101010, 0b0110010, 0b0011100 }, // 0 + { 0b0011000, 0b0001000, 0b0001000, 0b0001000, 0b0001000 }, // 1 + { 0b0011000, 0b0100100, 0b0001000, 0b0010000, 0b0111100 }, // 2 + { 0b0111100, 0b0000100, 0b0011100, 0b0000100, 0b0111100 }, // 3 + { 0b0100100, 0b0100100, 0b0111100, 0b0000100, 0b0000100 }, // 4 + { 0b0011100, 0b0100000, 0b0111100, 0b0000100, 0b0111100 }, // 5 + { 0b0111100, 0b0100000, 0b0111100, 0b0100100, 0b0111100 }, // 6 + { 0b0111100, 0b0000100, 0b0001000, 0b0010000, 0b0100000 }, // 7 + { 0b0111100, 0b0100100, 0b0011000, 0b0100100, 0b0111100 }, // 8 + { 0b0111100, 0b0100100, 0b0111100, 0b0000100, 0b0111100 }, // 9 + { 0b0000000, 0b0001000, 0b0000000, 0b0000000, 0b0001000 }, // : + { 0b0000000, 0b0001000, 0b0000000, 0b0001000, 0b0001000 }, // ; + { 0b0000100, 0b0001000, 0b0010000, 0b0001000, 0b0000100 }, // < + { 0b0000000, 0b0111110, 0b0000000, 0b0111110, 0b0000000 }, // = + { 0b0010000, 0b0001000, 0b0000100, 0b0001000, 0b0010000 }, // > + { 0b0011100, 0b0000100, 0b0001000, 0b0000000, 0b0001000 }, // ? + { 0b0011100, 0b0100010, 0b0101110, 0b0101010, 0b0001100 }, // @ + { 0b0111110, 0b0100010, 0b0111110, 0b0100010, 0b0100010 }, // A + { 0b0111100, 0b0010010, 0b0011110, 0b0010010, 0b0111100 }, // B + { 0b0011110, 0b0110000, 0b0100000, 0b0110000, 0b0011110 }, // C + { 0b0111100, 0b0100010, 0b0100010, 0b0100010, 0b0111100 }, // D + { 0b0111110, 0b0100000, 0b0111100, 0b0100000, 0b0111110 }, // E + { 0b0111110, 0b0100000, 0b0111100, 0b0100000, 0b0100000 }, // F + { 0b0111110, 0b0100000, 0b0101110, 0b0100010, 0b0111110 }, // G + { 0b0100010, 0b0100010, 0b0111110, 0b0100010, 0b0100010 }, // H + { 0b0011100, 0b0001000, 0b0001000, 0b0001000, 0b0011100 }, // I + { 0b0111100, 0b0001000, 0b0001000, 0b0101000, 0b0111000 }, // J + { 0b0100100, 0b0101000, 0b0110000, 0b0101000, 0b0100100 }, // K + { 0b0100000, 0b0100000, 0b0100000, 0b0100000, 0b0111100 }, // L + { 0b0100010, 0b0110110, 0b0101010, 0b0100010, 0b0100010 }, // M + { 0b0100010, 0b0110010, 0b0101010, 0b0100110, 0b0100010 }, // N + { 0b0011100, 0b0100010, 0b0100010, 0b0100010, 0b0011100 }, // O + { 0b0111110, 0b0100010, 0b0111110, 0b0100000, 0b0100000 }, // P + { 0b0111110, 0b0100010, 0b0100010, 0b0100110, 0b0111110 }, // Q + { 0b0111110, 0b0100010, 0b0111110, 0b0100100, 0b0100010 }, // R + { 0b0111110, 0b0100000, 0b0111110, 0b0000010, 0b0111110 }, // S + { 0b0111110, 0b0001000, 0b0001000, 0b0001000, 0b0001000 }, // T + { 0b0100010, 0b0100010, 0b0100010, 0b0100010, 0b0111110 }, // U + { 0b0100010, 0b0100010, 0b0010100, 0b0010100, 0b0001000 }, // V + { 0b0100010, 0b0100010, 0b0101010, 0b0110110, 0b0100010 }, // W + { 0b0100010, 0b0010100, 0b0001000, 0b0010100, 0b0100010 }, // X + { 0b0100010, 0b0010100, 0b0001000, 0b0001000, 0b0001000 }, // Y + { 0b0111110, 0b0000100, 0b0001000, 0b0010000, 0b0111110 }, // Z + { 0b0001100, 0b0001000, 0b0001000, 0b0001000, 0b0001100 }, // [ + { 0b0100000, 0b0010000, 0b0001000, 0b0000100, 0b0000010 }, // backslash + { 0b0011000, 0b0001000, 0b0001000, 0b0001000, 0b0011000 }, // ] + { 0b0001000, 0b0010100, 0b0000000, 0b0000000, 0b0000000 }, // ^ + { 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0111110 } // _ +}; + +/*! + \class HellClient + + \brief Client for Hellschreiber transmissions. +*/ +class HellClient { + public: + /*! + \brief Default constructor. + + \param phy Pointer to the wireless module providing PhysicalLayer communication. + */ + HellClient(PhysicalLayer* phy); + + // basic methods + + /*! + \brief Initialization method. + + \param base Base RF frequency to be used in MHz. + + \param rate Baud rate to be used during transmission. Defaults to 122.5 ("Feld Hell") + */ + int16_t begin(float base, float rate = 122.5); + + /*! + \brief Method to "print" a buffer of pixels, this is exposed to allow users to send custom characters. + + \param buff Buffer of pixels to send, in a 7x7 pixel array. + */ + size_t printGlyph(uint8_t* buff); + + size_t write(const char* str); + size_t write(uint8_t* buff, size_t len); + size_t write(uint8_t b); + + size_t print(__FlashStringHelper*); + size_t print(const String &); + size_t print(const char[]); + size_t print(char); + size_t print(unsigned char, int = DEC); + size_t print(int, int = DEC); + size_t print(unsigned int, int = DEC); + size_t print(long, int = DEC); + size_t print(unsigned long, int = DEC); + size_t print(double, int = 2); + + size_t println(void); + size_t println(__FlashStringHelper*); + size_t println(const String &s); + size_t println(const char[]); + size_t println(char); + size_t println(unsigned char, int = DEC); + size_t println(int, int = DEC); + size_t println(unsigned int, int = DEC); + size_t println(long, int = DEC); + size_t println(unsigned long, int = DEC); + size_t println(double, int = 2); + +#ifndef RADIOLIB_GODMODE + private: +#endif + PhysicalLayer* _phy; + + uint32_t _base; + uint32_t _pixelDuration; + + size_t printNumber(unsigned long, uint8_t); + size_t printFloat(double, uint8_t); +}; + +#endif From ebfa2f8e3611a6a825f71ece12059c4a1cd56e89 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 14 Apr 2020 10:54:44 +0200 Subject: [PATCH 067/334] [Hell] Added missing link to docs --- src/RadioLib.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/RadioLib.h b/src/RadioLib.h index 04ea18e7..cc9bc83c 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -22,6 +22,7 @@ - Morse Code (MorseClient) - AX.25 (AX25Client) - SSTV (SSTVClient) + - Hellschreiber (HellClient) - TransportLayer protocols - HTTP (HTTPClient) - MQTT (MQTTClient) From 976cd8734cabd15b9bbb5627023dac039829cad7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 14 Apr 2020 10:59:13 +0200 Subject: [PATCH 068/334] Bump version to 3.5.0 --- library.properties | 2 +- src/BuildOpt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 21975e9d..9113c270 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=3.4.0 +version=3.5.0 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 063a8e05..ff46595a 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -189,7 +189,7 @@ // version definitions #define RADIOLIB_VERSION_MAJOR (0x03) -#define RADIOLIB_VERSION_MINOR (0x04) +#define RADIOLIB_VERSION_MINOR (0x05) #define RADIOLIB_VERSION_PATCH (0x00) #define RADIOLIB_VERSION_EXTRA (0x00) From a089452e0fc31808a65bca854e518e4046ab20bd Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 14 Apr 2020 15:01:19 +0200 Subject: [PATCH 069/334] [CC1101] Fixed example --- .../CC1101_Receive_Interrupt.ino | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino index b57c4102..e036d71e 100644 --- a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino +++ b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino @@ -24,7 +24,7 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(5, 2, RADIOLIB_NC, 3); +CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield @@ -105,25 +105,22 @@ void loop() { receivedFlag = false; // you can read received data as an Arduino String - //String str; - //int state = cc.readData(str); + String str; + int state = cc.readData(str); // you can also read received data as byte array - + /* byte byteArr[8]; int state = cc.readData(byteArr, 8); - + */ if (state == ERR_NONE) { // packet was successfully received Serial.println(F("[CC1101] Received packet!")); // print data of the packet - Serial.println(F("[CC1101] Data:\t\t")); - //Serial.println(str); - for(uint8_t i = 0; i < 8; i++) { - Serial.println(byteArr[i], HEX); - } + Serial.print(F("[CC1101] Data:\t\t")); + Serial.println(str); // print RSSI (Received Signal Strength Indicator) // of the last received packet From e9f879aea63cbcb273241b1f089693eefadc9462 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 14 Apr 2020 15:01:39 +0200 Subject: [PATCH 070/334] [SX1231] Fixed typo in debug message --- src/modules/SX1231/SX1231.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/SX1231/SX1231.cpp b/src/modules/SX1231/SX1231.cpp index b7412bcb..da54a919 100644 --- a/src/modules/SX1231/SX1231.cpp +++ b/src/modules/SX1231/SX1231.cpp @@ -20,9 +20,9 @@ int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po _chipRevision = version; } else { #ifdef RADIOLIB_DEBUG - RADIOLIB_DEBUG_PRINT(F("SX127x not found! (")); + RADIOLIB_DEBUG_PRINT(F("SX1231 not found! (")); RADIOLIB_DEBUG_PRINT(i + 1); - RADIOLIB_DEBUG_PRINT(F(" of 10 tries) SX127X_REG_VERSION == ")); + RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RF69_REG_VERSION == ")); char buffHex[7]; sprintf(buffHex, "0x%04X", version); From 9f8ec689dd2fd8fda38c6ac1e9f788ecad748118 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 14 Apr 2020 15:02:33 +0200 Subject: [PATCH 071/334] [RF69] Replaced RSSI member variable with getRSSI method --- examples/RF69/RF69_Receive/RF69_Receive.ino | 6 ++++++ .../RF69_Receive_Interrupt.ino | 8 +++++++- src/modules/RF69/RF69.cpp | 9 +++++---- src/modules/RF69/RF69.h | 12 +++++++----- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/examples/RF69/RF69_Receive/RF69_Receive.ino b/examples/RF69/RF69_Receive/RF69_Receive.ino index 597ee63e..161173e3 100644 --- a/examples/RF69/RF69_Receive/RF69_Receive.ino +++ b/examples/RF69/RF69_Receive/RF69_Receive.ino @@ -68,6 +68,12 @@ void loop() { Serial.print(F("[RF69] Data:\t\t")); Serial.println(str); + // print RSSI (Received Signal Strength Indicator) + // of the last received packet + Serial.print(F("[RF69] RSSI:\t\t")); + Serial.print(rf.getRSSI()); + Serial.println(F(" dBm")); + } else if (state == ERR_RX_TIMEOUT) { // timeout occurred while waiting for a packet Serial.println(F("timeout!")); diff --git a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino index 32aef55f..e028a678 100644 --- a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino +++ b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino @@ -112,9 +112,15 @@ void loop() { Serial.println(F("[RF69] Received packet!")); // print data of the packet - Serial.print(F("[RF69] Data:\t\t\t")); + Serial.print(F("[RF69] Data:\t\t")); Serial.println(str); + // print RSSI (Received Signal Strength Indicator) + // of the last received packet + Serial.print(F("[RF69] RSSI:\t\t")); + Serial.print(rf.getRSSI()); + Serial.println(F(" dBm")); + } else if (state == ERR_CRC_MISMATCH) { // packet was received, but is malformed Serial.println(F("CRC error!")); diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index c9e9fa90..35bb2070 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -147,7 +147,7 @@ int16_t RF69::receive(uint8_t* data, size_t len) { uint32_t start = micros(); while(!digitalRead(_mod->getIrq())) { yield(); - + if(micros() - start > timeout) { standby(); clearIRQFlags(); @@ -330,9 +330,6 @@ int16_t RF69::readData(uint8_t* data, size_t len) { // read packet data _mod->SPIreadRegisterBurst(RF69_REG_FIFO, length, data); - // update RSSI - lastPacketRSSI = -1.0 * (_mod->SPIgetRegValue(RF69_REG_RSSI_VALUE)/2.0); - // clear internal flag so getPacketLength can return the new packet length _packetLengthQueried = false; @@ -701,6 +698,10 @@ int16_t RF69::setEncoding(uint8_t encoding) { } } +float RF69::getRSSI() { + return(-1.0 * (_mod->SPIgetRegValue(RF69_REG_RSSI_VALUE)/2.0)); +} + int16_t RF69::config() { int16_t state = ERR_NONE; diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 1a40e5dc..9f465df6 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -441,11 +441,6 @@ class RF69: public PhysicalLayer { */ RF69(Module* module); - /*! - \brief RSSI value of the last received packet. - */ - float lastPacketRSSI; - // basic methods /*! @@ -791,6 +786,13 @@ class RF69: public PhysicalLayer { */ int16_t setEncoding(uint8_t encoding); + /*! + \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. + + \returns Last packet RSSI in dBm. + */ + float getRSSI(); + #ifndef RADIOLIB_GODMODE protected: #endif From d94eeaae27c2a8b6aa5f8fb2b2dd48603dbaea77 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 08:44:58 +0200 Subject: [PATCH 072/334] [Travis] Formatting change --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8e36b9cb..be6e3618 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,12 @@ before_install: - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT # install 3rd party boards - - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json,https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1 + - arduino --pref 'boardsmanager.additional.urls=' \ + 'http://arduino.esp8266.com/stable/package_esp8266com_index.json,' \ + 'https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,' \ + 'https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,' \ + 'https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json' \ + --save-prefs 2>&1 - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then arduino --install-boards esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; From 4c2cfe44140ba3a3a4209820154afa46ff965ca3 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 08:52:05 +0200 Subject: [PATCH 073/334] [Travis] Fix multiline string --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index be6e3618..62b20862 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,12 +30,12 @@ before_install: - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT # install 3rd party boards - - arduino --pref 'boardsmanager.additional.urls=' \ - 'http://arduino.esp8266.com/stable/package_esp8266com_index.json,' \ - 'https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,' \ - 'https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,' \ - 'https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json' \ - --save-prefs 2>&1 + - additionalUrls="boardsmanager.additional.urls=\ + http://arduino.esp8266.com/stable/package_esp8266com_index.json,\ + https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,\ + https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,\ + https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json,\" + - arduino --pref "$additionalUrls" --save-prefs 2>&1 - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then arduino --install-boards esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; From cfa98b6a324830acdb5d51ebd33a879272d271a4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 08:54:14 +0200 Subject: [PATCH 074/334] [Travis] Fix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 62b20862..821fae80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ before_install: http://arduino.esp8266.com/stable/package_esp8266com_index.json,\ https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,\ https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,\ - https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json,\" + https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" - arduino --pref "$additionalUrls" --save-prefs 2>&1 - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then arduino --install-boards esp8266:esp8266; From 1592a137eb17a371477d765abee524cd1f75f61f Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:06:47 +0200 Subject: [PATCH 075/334] [Travis] Attempt to fix multiline string --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 821fae80..55892e74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,8 +34,8 @@ before_install: http://arduino.esp8266.com/stable/package_esp8266com_index.json,\ https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,\ https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,\ - https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" - - arduino --pref "$additionalUrls" --save-prefs 2>&1 + https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json"; + arduino --pref "$additionalUrls" --save-prefs 2>&1; - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then arduino --install-boards esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; From c907e967b4550dd852257dabb61c5cde58a3a3cc Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:14:34 +0200 Subject: [PATCH 076/334] [Travis] Anotehr fix attempt --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 55892e74..6ed87d2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,8 @@ before_install: - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT # install 3rd party boards - - additionalUrls="boardsmanager.additional.urls=\ + - | + additionalUrls="boardsmanager.additional.urls=\ http://arduino.esp8266.com/stable/package_esp8266com_index.json,\ https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,\ https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,\ From 61e5a9e7076936fc668c0187e3d75e4c94d2ce10 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:29:05 +0200 Subject: [PATCH 077/334] [Travis] Build only for Uno --- .travis.yml | 59 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6ed87d2b..8fca349c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,29 +29,36 @@ before_install: - sudo iptables -A OUTPUT -o lo -j ACCEPT - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - # install 3rd party boards - - | - additionalUrls="boardsmanager.additional.urls=\ - http://arduino.esp8266.com/stable/package_esp8266com_index.json,\ - https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,\ - https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json,\ - https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json"; - arduino --pref "$additionalUrls" --save-prefs 2>&1; - - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then + # check every board in matrix and install 3rd aprty definitions + - if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then + export BUILD_EXAMPLES=true + elif [[ "$BOARD" =~ "arduino:avr:mega" ]]; then + elif [[ "$BOARD" =~ "arduino:avr:leonardo" ]]; then + elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then + arduino --pref "http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; arduino --install-boards esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "esp32:esp32:" ]]; then + arduino --pref "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; arduino --install-boards esp32:esp32; elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then + arduino --pref "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; arduino --install-boards STM32:stm32; elif [[ "$BOARD" =~ "arduino:samd:" ]]; then + arduino --pref "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; arduino --install-boards arduino:samd; elif [[ "$BOARD" =~ "arduino:sam:" ]]; then arduino --install-boards arduino:sam; elif [[ "$BOARD" =~ "SparkFun:apollo3:" ]]; then + arduino --pref "https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; arduino --install-boards SparkFun:apollo3; fi + # check if this release commit (or forced build) and if so, build for every board + - if [[ "$TRAVIS_COMMIT_MESSAGE" =~ "Bump version to" ] || [ "$TRAVIS_COMMIT_MESSAGE" =~ "TRAVIS_FORCE_BUILD" ]]; then + export BUILD_EXAMPLES=true + fi + # create directory to save the library and create symbolic link install: - mkdir -p $HOME/Arduino/libraries @@ -65,23 +72,27 @@ branches: script: # build all example sketches - | - for example in $(find $PWD/examples -name '*.ino' | sort); do - # check whether to skip this sketch - if [ ! -z "$SKIP_PAT" ] && [[ ${example} =~ $SKIP_PAT ]]; then - # skip sketch - echo -e "\n\033[1;33mSkipped ${example##*/} (matched with $SKIP_PAT)\033[0m"; - else - # build sketch - echo -e "\n\033[1;33mBuilding ${example##*/} ... \033[0m"; - arduino --verify --board $BOARD $example; - if [ $? -ne 0 ]; then - echo -e "\033[1;31m${example##*/} build FAILED\033[0m\n"; - exit 1; + if [ "$BUILD_EXAMPLES" = true ] ; then + for example in $(find $PWD/examples -name '*.ino' | sort); do + # check whether to skip this sketch + if [ ! -z "$SKIP_PAT" ] && [[ ${example} =~ $SKIP_PAT ]]; then + # skip sketch + echo -e "\n\033[1;33mSkipped ${example##*/} (matched with $SKIP_PAT)\033[0m"; else - echo -e "\033[1;32m${example##*/} build PASSED\033[0m\n"; + # build sketch + echo -e "\n\033[1;33mBuilding ${example##*/} ... \033[0m"; + arduino --verify --board $BOARD $example; + if [ $? -ne 0 ]; then + echo -e "\033[1;31m${example##*/} build FAILED\033[0m\n"; + exit 1; + else + echo -e "\033[1;32m${example##*/} build PASSED\033[0m\n"; + fi fi - fi - done + done + else + echo -e "\n\033[1;33mExample build skipped for $BOARD\033[0m"; + fi # generate Doxygen documentation (only for Arduino UNO) - if [ $BOARD = "arduino:avr:uno" ]; then From 84938f276d5d9e1a1485072718acb7f9794ed502 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:32:39 +0200 Subject: [PATCH 078/334] [Travis] Fixed missing semicolons --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fca349c..cc4076b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ before_install: # check every board in matrix and install 3rd aprty definitions - if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then - export BUILD_EXAMPLES=true + export BUILD_EXAMPLES=true; elif [[ "$BOARD" =~ "arduino:avr:mega" ]]; then elif [[ "$BOARD" =~ "arduino:avr:leonardo" ]]; then elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then @@ -56,7 +56,7 @@ before_install: # check if this release commit (or forced build) and if so, build for every board - if [[ "$TRAVIS_COMMIT_MESSAGE" =~ "Bump version to" ] || [ "$TRAVIS_COMMIT_MESSAGE" =~ "TRAVIS_FORCE_BUILD" ]]; then - export BUILD_EXAMPLES=true + export BUILD_EXAMPLES=true; fi # create directory to save the library and create symbolic link From bbc35b969bea7e0dee010cca3710247ef11f1e97 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:36:29 +0200 Subject: [PATCH 079/334] [Travis] Explicitly set build flag --- .travis.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index cc4076b2..6cba81a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,29 +33,37 @@ before_install: - if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then export BUILD_EXAMPLES=true; elif [[ "$BOARD" =~ "arduino:avr:mega" ]]; then + export BUILD_EXAMPLES=false; elif [[ "$BOARD" =~ "arduino:avr:leonardo" ]]; then + export BUILD_EXAMPLES=false; elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then + export BUILD_EXAMPLES=false; arduino --pref "http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; arduino --install-boards esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "esp32:esp32:" ]]; then + export BUILD_EXAMPLES=false; arduino --pref "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; arduino --install-boards esp32:esp32; elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then + export BUILD_EXAMPLES=false; arduino --pref "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; arduino --install-boards STM32:stm32; elif [[ "$BOARD" =~ "arduino:samd:" ]]; then + export BUILD_EXAMPLES=false; arduino --pref "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; arduino --install-boards arduino:samd; elif [[ "$BOARD" =~ "arduino:sam:" ]]; then + export BUILD_EXAMPLES=false; arduino --install-boards arduino:sam; elif [[ "$BOARD" =~ "SparkFun:apollo3:" ]]; then + export BUILD_EXAMPLES=false; arduino --pref "https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; arduino --install-boards SparkFun:apollo3; fi # check if this release commit (or forced build) and if so, build for every board - - if [[ "$TRAVIS_COMMIT_MESSAGE" =~ "Bump version to" ] || [ "$TRAVIS_COMMIT_MESSAGE" =~ "TRAVIS_FORCE_BUILD" ]]; then + - if [[ "$TRAVIS_COMMIT_MESSAGE" =~ "Bump version to" || "$TRAVIS_COMMIT_MESSAGE" =~ "TRAVIS_FORCE_BUILD" ]]; then export BUILD_EXAMPLES=true; fi @@ -72,7 +80,7 @@ branches: script: # build all example sketches - | - if [ "$BUILD_EXAMPLES" = true ] ; then + if [ ! -z "$BUILD_EXAMPLES" ] && [ "$BUILD_EXAMPLES" = true ] ; then for example in $(find $PWD/examples -name '*.ino' | sort); do # check whether to skip this sketch if [ ! -z "$SKIP_PAT" ] && [[ ${example} =~ $SKIP_PAT ]]; then @@ -91,7 +99,7 @@ script: fi done else - echo -e "\n\033[1;33mExample build skipped for $BOARD\033[0m"; + echo -e "\n\033[1;33mExample builds skipped for $BOARD\033[0m"; fi # generate Doxygen documentation (only for Arduino UNO) From e070029f44a06164883877c4eadf99c1eda0fef9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:39:34 +0200 Subject: [PATCH 080/334] [Travis] Fixed incorrect board URL format --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6cba81a8..b40a2c19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,27 +38,27 @@ before_install: export BUILD_EXAMPLES=false; elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; + arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; arduino --install-boards esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "esp32:esp32:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; + arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; arduino --install-boards esp32:esp32; elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; + arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; arduino --install-boards STM32:stm32; elif [[ "$BOARD" =~ "arduino:samd:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; + arduino --pref "boardsmanager.additional.urls=https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; arduino --install-boards arduino:samd; elif [[ "$BOARD" =~ "arduino:sam:" ]]; then export BUILD_EXAMPLES=false; arduino --install-boards arduino:sam; elif [[ "$BOARD" =~ "SparkFun:apollo3:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; + arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; arduino --install-boards SparkFun:apollo3; fi From 7cbb248ee678a9eba235ce92eb45db1ca93e2ae1 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:42:55 +0200 Subject: [PATCH 081/334] [Travis] Fixed wrong URL for STM32 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b40a2c19..10a431ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,11 +47,10 @@ before_install: arduino --install-boards esp32:esp32; elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; + arduino --pref "boardsmanager.additional.urls=https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; arduino --install-boards STM32:stm32; elif [[ "$BOARD" =~ "arduino:samd:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; arduino --install-boards arduino:samd; elif [[ "$BOARD" =~ "arduino:sam:" ]]; then export BUILD_EXAMPLES=false; From 57f63bff9153adb29ac52e7d55a97c543a8220ec Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 09:47:18 +0200 Subject: [PATCH 082/334] [Travis] Rebuld all using TRAVIS_FORCE_BUILD --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10a431ab..58252507 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,15 +4,15 @@ env: matrix: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt + - BOARD="arduino:avr:uno" + - BOARD="arduino:avr:mega:cpu=atmega2560" + - BOARD="arduino:avr:leonardo" + - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" - BOARD="esp32:esp32:esp32" - BOARD="STM32:stm32:GenF3:pnum=BLACKPILL_F303CC" - - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" - # - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:samd:arduino_zero_native" - BOARD="arduino:sam:arduino_due_x" - - BOARD="arduino:avr:uno" - - BOARD="arduino:avr:leonardo" - - BOARD="arduino:avr:mega:cpu=atmega2560" + # - BOARD="SparkFun:apollo3:amap3redboard" before_install: # install Arduino IDE From 0daa14175df1bfe86cdb7b0a9696e68ed3956a98 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 10:01:39 +0200 Subject: [PATCH 083/334] [Travis] Added all platforms from readme TRAVIS_FORCE_BUILD --- .travis.yml | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58252507..d46ac61b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,11 @@ env: - BOARD="STM32:stm32:GenF3:pnum=BLACKPILL_F303CC" - BOARD="arduino:samd:arduino_zero_native" - BOARD="arduino:sam:arduino_due_x" - # - BOARD="SparkFun:apollo3:amap3redboard" + - BOARD="adafruit:nrf52:feather52832" + - BOARD="Intel:arc32:arduino_101" + - BOARD="arduino:megaavr:uno2018" + - BOARD="SparkFun:apollo3:amap3redboard" + - BOARD="arduino:mbed:nano33ble" before_install: # install Arduino IDE @@ -29,36 +33,62 @@ before_install: - sudo iptables -A OUTPUT -o lo -j ACCEPT - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - # check every board in matrix and install 3rd aprty definitions + # check every board in matrix and install 3rd party definitions - if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then export BUILD_EXAMPLES=true; + elif [[ "$BOARD" =~ "arduino:avr:mega" ]]; then export BUILD_EXAMPLES=false; + elif [[ "$BOARD" =~ "arduino:avr:leonardo" ]]; then export BUILD_EXAMPLES=false; + elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then export BUILD_EXAMPLES=false; arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; arduino --install-boards esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; + elif [[ "$BOARD" =~ "esp32:esp32:" ]]; then export BUILD_EXAMPLES=false; arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; arduino --install-boards esp32:esp32; + elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then export BUILD_EXAMPLES=false; arduino --pref "boardsmanager.additional.urls=https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; arduino --install-boards STM32:stm32; + elif [[ "$BOARD" =~ "arduino:samd:" ]]; then export BUILD_EXAMPLES=false; arduino --install-boards arduino:samd; + elif [[ "$BOARD" =~ "arduino:sam:" ]]; then export BUILD_EXAMPLES=false; arduino --install-boards arduino:sam; + + elif [[ "$BOARD" =~ "adafruit:nrf52:" ]]; then + export BUILD_EXAMPLES=false; + arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; + arduino --install-boards adafruit:nrf52; + + elif [[ "$BOARD" =~ "Intel:arc32:" ]]; then + export BUILD_EXAMPLES=false; + arduino --install-boards Intel:arc32; + + elif [[ "$BOARD" =~ "arduino:megaavr:" ]]; then + export BUILD_EXAMPLES=false; + arduino --install-boards arduino:megaavr; + elif [[ "$BOARD" =~ "SparkFun:apollo3:" ]]; then export BUILD_EXAMPLES=false; arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; arduino --install-boards SparkFun:apollo3; + + elif [[ "$BOARD" =~ "arduino:mbed:" ]]; then + export BUILD_EXAMPLES=false; + arduino --install-boards arduino:mbed; + fi # check if this release commit (or forced build) and if so, build for every board From c3d6ebce755df836b7c9ff29cb6c73a0e2660923 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 10:48:59 +0200 Subject: [PATCH 084/334] [Travis] Added missing parameters for some platforms TRAVIS_FORCE_BUILD --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d46ac61b..6916a505 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,9 @@ env: - BOARD="STM32:stm32:GenF3:pnum=BLACKPILL_F303CC" - BOARD="arduino:samd:arduino_zero_native" - BOARD="arduino:sam:arduino_due_x" - - BOARD="adafruit:nrf52:feather52832" + - BOARD="adafruit:nrf52:feather52832:softdevice=s132v6,debug=l0" - BOARD="Intel:arc32:arduino_101" - - BOARD="arduino:megaavr:uno2018" + - BOARD="arduino:megaavr:uno2018:mode=on" - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" @@ -88,6 +88,7 @@ before_install: elif [[ "$BOARD" =~ "arduino:mbed:" ]]; then export BUILD_EXAMPLES=false; arduino --install-boards arduino:mbed; + export SKIP_PAT='(HTTP|MQTT).*ino'; fi From c17509db4dd84d5f49bdeeb5cb38b8ec3afbc2ca Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 11:38:20 +0200 Subject: [PATCH 085/334] [Travis] Added missing tool for nRF52 TRAVIS_FORCE_BUILD --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6916a505..a2785c20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,13 @@ env: - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" +addons: + apt: + packages: + - python3 + - python3-pip + - python3-setuptools + before_install: # install Arduino IDE - wget https://downloads.arduino.cc/arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz @@ -68,6 +75,7 @@ before_install: arduino --install-boards arduino:sam; elif [[ "$BOARD" =~ "adafruit:nrf52:" ]]; then + pip3 install --user adafruit-nrfutil export BUILD_EXAMPLES=false; arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; arduino --install-boards adafruit:nrf52; From 87d5103563920cb4a3cfeeacb4db29cdf58de2c3 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 15 Apr 2020 12:25:39 +0200 Subject: [PATCH 086/334] [Travis] Added missing semicolon TRAVIS_FORCE_BUILD --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a2785c20..9552fd5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,7 +75,7 @@ before_install: arduino --install-boards arduino:sam; elif [[ "$BOARD" =~ "adafruit:nrf52:" ]]; then - pip3 install --user adafruit-nrfutil + pip3 install --user adafruit-nrfutil; export BUILD_EXAMPLES=false; arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; arduino --install-boards adafruit:nrf52; From b778aa2e47b5be1df28f01d9e8b75fabf6fc3023 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 16 Apr 2020 07:11:56 +0200 Subject: [PATCH 087/334] Updated readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c62b393a..ffc80347 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,12 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * __Arduino SAMD__ - Arduino Zero, Arduino MKR boards, M0 Pro etc. * __Arduino SAM__ - Arduino Due * __Adafruit nRF52__ - Adafruit Bluefruit Feather etc. -* _Intel Curie_ - Arduino 101 -* _Arduino megaAVR_ - Arduino Uno WiFi Rev.2 etc. -* _Apollo3_ - SparkFun Artemis Redboard etc. -* _Arduino nRF52_ - Arduino Nano 33 BLE +* __Intel Curie__ - Arduino 101 +* __Arduino megaAVR__ - Arduino Uno WiFi Rev.2 etc. +* __Apollo3__ - SparkFun Artemis Redboard etc. +* __Arduino nRF52__ - Arduino Nano 33 BLE -The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platforms in __bold__ on each git push. Platforms in _italic_ are not tested on each push, but do compile and should be working. +The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platforms prior to releasing new version. ### In development: * __SIM800C__ GSM module From e8857fd8d734179764790be2dbea5ebee6a071e5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 17 Apr 2020 07:50:15 +0200 Subject: [PATCH 088/334] [SX128x] Fixed unsupported bit rate value in example --- examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino b/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino index 166215b7..abf6a582 100644 --- a/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino +++ b/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino @@ -58,7 +58,7 @@ void setup() { // the following settings can also // be modified at run-time state = ble.setFrequency(2410.5); - state = ble.setBitRate(200); + state = ble.setBitRate(250); state = ble.setFrequencyDeviation(100.0); state = ble.setOutputPower(5); state = ble.setDataShaping(1.0); @@ -90,7 +90,7 @@ void loop() { } else if (state == ERR_TX_TIMEOUT) { Serial.println(F("[SX1280] Timed out while transmitting!")); } else { - Serial.println(F("[SX1280] Failed to transmit packet, code ")); + Serial.print(F("[SX1280] Failed to transmit packet, code ")); Serial.println(state); } From dcf31e481dbe8d01f0158ae7644e45f543210347 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 17 Apr 2020 07:51:06 +0200 Subject: [PATCH 089/334] [SX128x] Fixed BLE access address configuration (#135) --- src/modules/SX128x/SX128x.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index e4dae862..4b2409a5 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -950,9 +950,9 @@ int16_t SX128x::setAccessAddress(uint32_t addr) { return(ERR_WRONG_MODEM); } - // use setSyncWord to set the address - uint8_t syncWord[] = { (uint8_t)((addr >> 24) & 0xFF), (uint8_t)((addr >> 16) & 0xFF), (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; - return(setSyncWord(syncWord, 4)); + // set the address + uint8_t addrBuff[] = { (uint8_t)((addr >> 24) & 0xFF), (uint8_t)((addr >> 16) & 0xFF), (uint8_t)((addr >> 8) & 0xFF), (uint8_t)(addr & 0xFF) }; + return(SX128x::writeRegister(SX128X_REG_ACCESS_ADDRESS_BYTE_3, addrBuff, 4)); } float SX128x::getRSSI() { From 1aef03c473e2af6c3e754a5440e04ded98f0b5c0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 17 Apr 2020 07:51:29 +0200 Subject: [PATCH 090/334] [SX128x] Added missing BLE modem check --- src/modules/SX128x/SX128x.cpp | 12 ++++++++++-- src/modules/SX128x/SX128x.h | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 4b2409a5..098d783f 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -444,6 +444,8 @@ int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, len, _crcLoRa); } else if((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_FLRC)) { state = setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening, len); + } else if(modem == SX128X_PACKET_TYPE_BLE) { + state = setPacketParamsBLE(_connectionState, _crcBLE, _bleTestPayload, _whitening); } else { return(ERR_WRONG_MODEM); } @@ -458,8 +460,14 @@ int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); // write packet to buffer - state = writeBuffer(data, len); - RADIOLIB_ASSERT(state); + if(modem == SX128X_PACKET_TYPE_BLE) { + // first 2 bytes of BLE payload are PDU header + state = writeBuffer(data, len, 2); + RADIOLIB_ASSERT(state); + } else { + state = writeBuffer(data, len); + RADIOLIB_ASSERT(state); + } // set DIO mapping state = setDioIrqParams(SX128X_IRQ_TX_DONE | SX128X_IRQ_RX_TX_TIMEOUT, SX128X_IRQ_TX_DONE); diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index f093a3c9..a5aea25c 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -442,7 +442,7 @@ class SX128x: public PhysicalLayer { \param len Number of bytes to send. - \param addr Address to send the data to. Will only be added if address filtering was enabled. + \param addr Address to send the data to. Unsupported, compatibility only. \returns \ref status_codes */ @@ -531,7 +531,7 @@ class SX128x: public PhysicalLayer { \param len Number of bytes to send. - \param addr Address to send the data to. Will only be added if address filtering was enabled. + \param addr Address to send the data to. Unsupported, compatibility only. \returns \ref status_codes */ @@ -745,7 +745,7 @@ class SX128x: public PhysicalLayer { protected: #endif Module* _mod; - + // cached LoRa parameters float _bwKhz; uint8_t _bw, _sf, _cr; From 9ad020750a248b247eab91dd8991d3c2ddbef031 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 17 Apr 2020 08:35:47 +0200 Subject: [PATCH 091/334] [SX128x] Fixed unsupported FLRC bit rate --- examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino b/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino index 1f28b834..af680b50 100644 --- a/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino +++ b/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino @@ -57,7 +57,7 @@ void setup() { // the following settings can also // be modified at run-time state = flrc.setFrequency(2410.5); - state = flrc.setBitRate(200); + state = flrc.setBitRate(520); state = flrc.setCodingRate(2); state = flrc.setOutputPower(5); state = flrc.setDataShaping(1.0); From bd5be7729e281aee5f686ada78dabecec2de83b7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 21 Apr 2020 12:00:23 +0200 Subject: [PATCH 092/334] [RF69] Extended power configuration (#133) --- examples/RF69/RF69_Transmit/RF69_Transmit.ino | 17 +++++++ .../RF69_Transmit_Interrupt.ino | 17 +++++++ src/modules/RF69/RF69.cpp | 50 +++++++++++++++---- src/modules/RF69/RF69.h | 9 ++-- 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/examples/RF69/RF69_Transmit/RF69_Transmit.ino b/examples/RF69/RF69_Transmit/RF69_Transmit.ino index 05879c0b..5d39f6f2 100644 --- a/examples/RF69/RF69_Transmit/RF69_Transmit.ino +++ b/examples/RF69/RF69_Transmit/RF69_Transmit.ino @@ -43,6 +43,23 @@ void setup() { Serial.println(state); while (true); } + + // NOTE: some RF69 modules use high power output, + // those are usually marked RF69H(C/CW). + // To configure RadioLib for these modules, + // you must call setOutputPower() with + // second argument set to true. + /* + Serial.print(F("[RF69] Setting high power module ... ")); + state = rf.setOutputPower(20, true); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + */ } void loop() { diff --git a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino index 3e83042a..e07b41ec 100644 --- a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino +++ b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino @@ -52,6 +52,23 @@ void setup() { // when packet transmission is finished rf.setDio0Action(setFlag); + // NOTE: some RF69 modules use high power output, + // those are usually marked RF69H(C/CW). + // To configure RadioLib for these modules, + // you must call setOutputPower() with + // second argument set to true. + /* + Serial.print(F("[RF69] Setting high power module ... ")); + state = rf.setOutputPower(20, true); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + */ + // start transmitting the first packet Serial.print(F("[RF69] Sending first packet ... ")); diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 35bb2070..ba7bfcb7 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -239,9 +239,12 @@ int16_t RF69::startReceive() { clearIRQFlags(); // set mode to receive - state = _mod->SPIsetRegValue(RF69_REG_TEST_PA1, RF69_PA1_NORMAL); + state = _mod->SPIsetRegValue(RF69_REG_OCP, RF69_OCP_ON | RF69_OCP_TRIM); + state |= _mod->SPIsetRegValue(RF69_REG_TEST_PA1, RF69_PA1_NORMAL); state |= _mod->SPIsetRegValue(RF69_REG_TEST_PA2, RF69_PA2_NORMAL); - state |= setMode(RF69_RX); + RADIOLIB_ASSERT(state); + + state = setMode(RF69_RX); return(state); } @@ -303,10 +306,16 @@ int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // write packet to FIFO _mod->SPIwriteRegisterBurst(RF69_REG_FIFO, data, len); + // enable +20 dBm operation + if(_power > 17) { + state = _mod->SPIsetRegValue(RF69_REG_OCP, RF69_OCP_OFF | 0x0F); + state |= _mod->SPIsetRegValue(RF69_REG_TEST_PA1, RF69_PA1_20_DBM); + state |= _mod->SPIsetRegValue(RF69_REG_TEST_PA2, RF69_PA2_20_DBM); + RADIOLIB_ASSERT(state); + } + // set mode to transmit - state = _mod->SPIsetRegValue(RF69_REG_TEST_PA1, RF69_PA1_20_DBM); - state |= _mod->SPIsetRegValue(RF69_REG_TEST_PA2, RF69_PA2_20_DBM); - state |= setMode(RF69_TX); + state = setMode(RF69_TX); return(state); } @@ -493,22 +502,41 @@ int16_t RF69::setFrequencyDeviation(float freqDev) { return(state); } -int16_t RF69::setOutputPower(int8_t power) { - RADIOLIB_CHECK_RANGE(power, -18, 17, ERR_INVALID_OUTPUT_POWER); +int16_t RF69::setOutputPower(int8_t power, bool highPower) { + if(highPower) { + RADIOLIB_CHECK_RANGE(power, -2, 20, ERR_INVALID_OUTPUT_POWER); + } else { + RADIOLIB_CHECK_RANGE(power, -18, 13, ERR_INVALID_OUTPUT_POWER); + } // set mode to standby setMode(RF69_STANDBY); // set output power int16_t state; - if(power > 13) { - // requested output power is higher than 13 dBm, enable PA2 + PA1 on PA_BOOST - state = _mod->SPIsetRegValue(RF69_REG_PA_LEVEL, RF69_PA0_OFF | RF69_PA1_ON | RF69_PA2_ON | (power + 14), 7, 0); + if(highPower) { + // check if both PA1 and PA2 are needed + if(power <= 10) { + // -2 to 13 dBm, PA1 is enough + state = _mod->SPIsetRegValue(RF69_REG_PA_LEVEL, RF69_PA0_OFF | RF69_PA1_ON | RF69_PA2_OFF | (power + 18), 7, 0); + } else if(power <= 17) { + // 13 to 17 dBm, both PAs required + state = _mod->SPIsetRegValue(RF69_REG_PA_LEVEL, RF69_PA0_OFF | RF69_PA1_ON | RF69_PA2_ON | (power + 14), 7, 0); + } else { + // 18 - 20 dBm, both PAs and hig power settings required + state = _mod->SPIsetRegValue(RF69_REG_PA_LEVEL, RF69_PA0_OFF | RF69_PA1_ON | RF69_PA2_ON | (power + 11), 7, 0); + } + } else { - // requested output power is lower than 13 dBm, enable PA0 on RFIO + // low power module, use only PA0 state = _mod->SPIsetRegValue(RF69_REG_PA_LEVEL, RF69_PA0_ON | RF69_PA1_OFF | RF69_PA2_OFF | (power + 18), 7, 0); } + // cache the power value + if(state == ERR_NONE) { + _power = power; + } + return(state); } diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 9f465df6..18aa8df4 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -188,7 +188,7 @@ // RF69_REG_OCP #define RF69_OCP_OFF 0b00000000 // 4 4 PA overload current protection disabled -#define RF69_OCP_ON 0b00100000 // 4 4 PA overload current protection enabled +#define RF69_OCP_ON 0b00010000 // 4 4 PA overload current protection enabled #define RF69_OCP_TRIM 0b00001010 // 3 0 OCP current: I_max(OCP_TRIM = 0b1010) = 95 mA // RF69_REG_LNA @@ -646,13 +646,15 @@ class RF69: public PhysicalLayer { int16_t setFrequencyDeviation(float freqDev); /*! - \brief Sets output power. Allowed values are -30, -20, -15, -10, 0, 5, 7 or 10 dBm. + \brief Sets output power. Allowed values range from -18 to 13 dBm for low power modules (RF69C/CW) or -2 to 20 dBm (RF69H/HC/HCW). \param power Output power to be set in dBm. + \param highPower Set to true when using modules high power port (RF69H/HC/HCW). Defaults to false (models without high power port - RF69C/CW). + \returns \ref status_codes */ - int16_t setOutputPower(int8_t power); + int16_t setOutputPower(int8_t power, bool highPower = false); /*! \brief Sets sync word. Up to 8 bytes can be set as sync word. @@ -801,6 +803,7 @@ class RF69: public PhysicalLayer { float _br; float _rxBw; int16_t _tempOffset; + int8_t _power; size_t _packetLength; bool _packetLengthQueried; From 271f5bd62cd02e98818a4b7268b5da03ab4c29be Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 14:55:02 +0200 Subject: [PATCH 093/334] [ESP8266] Replaced itoa() with sprintf() --- src/modules/ESP8266/ESP8266.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index 1aa959a9..f55d7c9d 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -83,9 +83,9 @@ int16_t ESP8266::join(const char* ssid, const char* password) { int16_t ESP8266::openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive) { char portStr[6]; - itoa(port, portStr, 10); + sprintf(portStr, "%d", port); char tcpKeepAliveStr[6]; - itoa(tcpKeepAlive, tcpKeepAliveStr, 10); + sprintf(tcpKeepAliveStr, "%d", tcpKeepAlive); // build AT command const char* atStr = "AT+CIPSTART=\""; @@ -132,7 +132,7 @@ int16_t ESP8266::closeTransportConnection() { int16_t ESP8266::send(const char* data) { // build AT command char lenStr[8]; - itoa(strlen(data), lenStr, 10); + sprintf(lenStr, "%d", strlen(data)); const char* atStr = "AT+CIPSEND="; #ifdef RADIOLIB_STATIC_ONLY char cmd[RADIOLIB_STATIC_ARRAY_SIZE]; @@ -162,7 +162,7 @@ int16_t ESP8266::send(const char* data) { int16_t ESP8266::send(uint8_t* data, uint32_t len) { // build AT command char lenStr[8]; - itoa(len, lenStr, 10); + sprintf(lenStr, "%lu", len); const char atStr[] = "AT+CIPSEND="; #ifdef RADIOLIB_STATIC_ONLY char cmd[RADIOLIB_STATIC_ARRAY_SIZE]; From 6f0989993e092119508c2578f79ee972dbc1b2bd Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 14:55:23 +0200 Subject: [PATCH 094/334] [HTTP] Replaced itoa() with sprintf() --- src/protocols/HTTP/HTTP.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/protocols/HTTP/HTTP.cpp b/src/protocols/HTTP/HTTP.cpp index 9200acb0..00b046d2 100644 --- a/src/protocols/HTTP/HTTP.cpp +++ b/src/protocols/HTTP/HTTP.cpp @@ -140,8 +140,8 @@ int16_t HTTPClient::post(const char* url, const char* content, String& response, } // build the POST request - char contentLengthStr[8]; - itoa(strlen(content), contentLengthStr, 10); + char contentLengthStr[12]; + sprintf(contentLengthStr, "%d", strlen(content)); char* request = new char[strlen(endpoint) + strlen(host) + strlen(contentType) + strlen(contentLengthStr) + strlen(content) + 64 + 1]; strcpy(request, "POST "); strcat(request, endpoint); From 2eb3df5c897e3a5ccbe7ea1b6f51b8be2c1c719b Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 14:57:51 +0200 Subject: [PATCH 095/334] Added interrupt pin status macro --- src/BuildOpt.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index ff46595a..17fccab4 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -13,6 +13,7 @@ * RADIOLIB_PIN_TYPE - which type should be used for pin numbers in functions like digitalRead(). * RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode(). * RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite(). + * RADIOLIB_INTERRUPT_STATUS - which type should be used for pin changes in functions like attachInterrupt(). * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platform does not support SoftwareSerial. * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platform that do not have SoftwareSerial support. @@ -24,6 +25,7 @@ #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) #elif defined(ESP8266) @@ -31,6 +33,7 @@ #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) // RadioLib has ESPS8266 driver, this must be disabled to use ESP8266 as platform @@ -41,6 +44,7 @@ #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -50,6 +54,7 @@ #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -59,6 +64,7 @@ #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -68,6 +74,7 @@ #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -77,6 +84,7 @@ #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFFFFFFFF) #elif defined(ARDUINO_ARC32_TOOLS) @@ -84,6 +92,7 @@ #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) #elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) @@ -91,6 +100,7 @@ #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE PinMode #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) #elif defined(AM_PART_APOLLO3) @@ -98,6 +108,7 @@ #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -107,6 +118,7 @@ #define RADIOLIB_PIN_TYPE pin_size_t #define RADIOLIB_PIN_MODE PinMode #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -120,6 +132,7 @@ #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_NC (0xFF) #endif From 75cc35171417e099c10f8df7213fb3f936f66a9c Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 14:58:47 +0200 Subject: [PATCH 096/334] Added platform name printing in debug mpde --- src/BuildOpt.h | 15 ++++++++++++++- src/RadioLib.h | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 17fccab4..6c14e783 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -10,6 +10,7 @@ /* * Platform-specific configuration. * + * RADIOLIB_PLATFORM - platform name, used in debugging to quickly check the correct platform is detected, * RADIOLIB_PIN_TYPE - which type should be used for pin numbers in functions like digitalRead(). * RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode(). * RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite(). @@ -22,6 +23,7 @@ */ #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. + #define RADIOLIB_PLATFORM "Arduino AVR" #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t @@ -30,6 +32,7 @@ #elif defined(ESP8266) // ESP8266 boards + #define RADIOLIB_PLATFORM "ESP8266" #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t @@ -41,6 +44,7 @@ #elif defined(ESP32) // ESP32 boards + #define RADIOLIB_PLATFORM "ESP32" #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t @@ -50,7 +54,8 @@ #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 #elif defined(ARDUINO_ARCH_STM32) - // STM32duino boards + // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32) + #define RADIOLIB_PLATFORM "Arduino STM32 (official)" #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t @@ -61,6 +66,7 @@ #elif defined(SAMD_SERIES) // Arduino SAMD boards - Zero, MKR, etc. + #define RADIOLIB_PLATFORM "Arduino SAMD" #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t @@ -71,6 +77,7 @@ #elif defined(__SAM3X8E__) // Arduino Due + #define RADIOLIB_PLATFORM "Arduino Due" #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t @@ -81,6 +88,7 @@ #elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) // Adafruit nRF52 boards + #define RADIOLIB_PLATFORM "Adafruit nRF52" #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t @@ -89,6 +97,7 @@ #elif defined(ARDUINO_ARC32_TOOLS) // Intel Curie + #define RADIOLIB_PLATFORM "Intel Curie" #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t @@ -97,6 +106,7 @@ #elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every + #define RADIOLIB_PLATFORM "Arduino megaAVR" #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE PinMode #define RADIOLIB_PIN_STATUS PinStatus @@ -105,6 +115,7 @@ #elif defined(AM_PART_APOLLO3) // Sparkfun Artemis boards + #define RADIOLIB_PLATFORM "Sparkfun Artemis" #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t @@ -115,6 +126,7 @@ #elif defined(ARDUINO_ARDUINO_NANO33BLE) // Arduino Nano 33 BLE + #define RADIOLIB_PLATFORM "Arduino Nano 33 BLE" #define RADIOLIB_PIN_TYPE pin_size_t #define RADIOLIB_PIN_MODE PinMode #define RADIOLIB_PIN_STATUS PinStatus @@ -128,6 +140,7 @@ #else // other platforms not covered by the above list - this may or may not work + #define RADIOLIB_PLATFORM "Unknown" #define RADIOLIB_UNKNOWN_PLATFORM #define RADIOLIB_PIN_TYPE uint8_t #define RADIOLIB_PIN_MODE uint8_t diff --git a/src/RadioLib.h b/src/RadioLib.h index cc9bc83c..b9446834 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -50,6 +50,11 @@ #warning "God mode active, I hope it was intentional. Buckle up, lads." #endif +// print debug info +#ifdef RADIOLIB_DEBUG + #pragma message "RADIOLIB_PLATFORM: " RADIOLIB_PLATFORM +#endif + // check unknown/unsupported platform #ifdef RADIOLIB_UNKNOWN_PLATFORM #warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!" From 332a981c230d155091814bd62ea81b949d0f65ed Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 14:59:17 +0200 Subject: [PATCH 097/334] [CC1101] Changed interrupt pin macro --- src/modules/CC1101/CC1101.cpp | 4 ++-- src/modules/CC1101/CC1101.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index f05fa32e..039c155d 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -179,7 +179,7 @@ int16_t CC1101::packetMode() { return(state); } -void CC1101::setGdo0Action(void (*func)(void), RADIOLIB_PIN_STATUS dir) { +void CC1101::setGdo0Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir) { attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, dir); } @@ -187,7 +187,7 @@ void CC1101::clearGdo0Action() { detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); } -void CC1101::setGdo2Action(void (*func)(void), RADIOLIB_PIN_STATUS dir) { +void CC1101::setGdo2Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir) { if(_mod->getGpio() != RADIOLIB_NC) { return; } diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index c1969d27..d6cfe45c 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -600,7 +600,7 @@ class CC1101: public PhysicalLayer { \param dir Signal change direction. Defaults to FALLING. */ - void setGdo0Action(void (*func)(void), RADIOLIB_PIN_STATUS dir = FALLING); + void setGdo0Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir = FALLING); /*! \brief Clears interrupt service routine to call when GDO0 activates. @@ -614,7 +614,7 @@ class CC1101: public PhysicalLayer { \param dir Signal change direction. Defaults to FALLING. */ - void setGdo2Action(void (*func)(void), RADIOLIB_PIN_STATUS dir = FALLING); + void setGdo2Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir = FALLING); /*! \brief Clears interrupt service routine to call when GDO0 activates. From 26ff33a8acba8d0855162845404e28ef0050061a Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 15:00:44 +0200 Subject: [PATCH 098/334] Added support for Roger Clark's STM32duino core TRAVIS_FORCE_BUILD --- .travis.yml | 13 +++++++++++++ src/BuildOpt.h | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9552fd5e..af3e371b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,10 +17,13 @@ env: - BOARD="arduino:megaavr:uno2018:mode=on" - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" + - BOARD="stm32duino:STM32F1:mapleMini" + #- BOARD="stm32duino:STM32F4:discovery_f407" addons: apt: packages: + # required for Adafruit nRF52 (adafruit-nrfutil package) - python3 - python3-pip - python3-setuptools @@ -98,6 +101,16 @@ before_install: arduino --install-boards arduino:mbed; export SKIP_PAT='(HTTP|MQTT).*ino'; + elif [[ "$BOARD" =~ "stm32duino:STM32F1:" ]]; then + export BUILD_EXAMPLES=false; + arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; + arduino --install-boards stm32duino:STM32F1; + + elif [[ "$BOARD" =~ "stm32duino:STM32F4:" ]]; then + export BUILD_EXAMPLES=false; + arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; + arduino --install-boards stm32duino:STM32F4; + fi # check if this release commit (or forced build) and if so, build for every board diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 6c14e783..8273cd3f 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -138,6 +138,17 @@ // Nano 33 BLE uses mbed libraries, which already contain ESP8266 driver #define _RADIOLIB_ESP8266_H +#elif defined(__STM32F4__) || defined(__STM32F1__) + // Arduino STM32 core by Roger Clark (https://github.com/rogerclarkmelbourne/Arduino_STM32) + #define RADIOLIB_PLATFORM "STM32duino (unofficial)" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE WiringPinMode + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS ExtIntTriggerMode + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #else // other platforms not covered by the above list - this may or may not work #define RADIOLIB_PLATFORM "Unknown" From 7d56a8021f13562336a315564cac51fe356041c5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 15:57:56 +0200 Subject: [PATCH 099/334] Travis set Maple parameters --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af3e371b..3ef815e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ env: matrix: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt + - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" - BOARD="arduino:avr:uno" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" @@ -17,7 +18,6 @@ env: - BOARD="arduino:megaavr:uno2018:mode=on" - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" - - BOARD="stm32duino:STM32F1:mapleMini" #- BOARD="stm32duino:STM32F4:discovery_f407" addons: From 27ec766e6200912dfa99a601349f15c74c3a644b Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 15:59:21 +0200 Subject: [PATCH 100/334] Forcing build TRAVIS_FORCE_BUILD --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3ef815e6..be97ffec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ env: matrix: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt - - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" - BOARD="arduino:avr:uno" + - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" From 54fc5533716ad971b61ff468438a2b6aa78c7c79 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 22 Apr 2020 16:02:14 +0200 Subject: [PATCH 101/334] Travis fixed build order TRAVIS_FORCE_BUILD --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be97ffec..a7381d87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ env: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt - BOARD="arduino:avr:uno" - - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" @@ -18,6 +17,7 @@ env: - BOARD="arduino:megaavr:uno2018:mode=on" - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" + - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" #- BOARD="stm32duino:STM32F4:discovery_f407" addons: From 9bd1a63bbad86c14d3b6ffe4d0b52eefad886e59 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 13:34:35 +0200 Subject: [PATCH 102/334] Organized platform list --- README.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ffc80347..b56ab927 100644 --- a/README.md +++ b/README.md @@ -37,17 +37,29 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * [__Hellschreiber__](https://www.sigidwiki.com/wiki/Hellschreiber) for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x ### Supported platforms: -* __Arduino AVR__ - tested with hardware on Uno, Mega and Leonardo -* __ESP8266__ - tested with hardware on NodeMCU and Wemos D1 -* __ESP32__ - tested with hardware on ESP-WROOM-32 -* __STM32__ - tested with hardware on Nucleo L452RE-P -* __Arduino SAMD__ - Arduino Zero, Arduino MKR boards, M0 Pro etc. -* __Arduino SAM__ - Arduino Due -* __Adafruit nRF52__ - Adafruit Bluefruit Feather etc. -* __Intel Curie__ - Arduino 101 -* __Arduino megaAVR__ - Arduino Uno WiFi Rev.2 etc. -* __Apollo3__ - SparkFun Artemis Redboard etc. -* __Arduino nRF52__ - Arduino Nano 33 BLE +* __Arduino__ + * [__AVR__](https://github.com/arduino/ArduinoCore-avr) - Arduino Uno, Mega, Leonardo, Pro Mini, Nano etc. + * [__mbed__](https://github.com/arduino/ArduinoCore-nRF528x-mbedos) - Arduino Nano 33 BLE + * [__megaAVR__](https://github.com/arduino/ArduinoCore-megaavr) - Arduino Uno WiFi Rev.2 and Nano Every + * [__SAM__](https://github.com/arduino/ArduinoCore-sam) - Arduino Due + * [__SAMD__](https://github.com/arduino/ArduinoCore-samd) - Arduino Zero, MKR boards, M0 Pro etc. + +* __Adafruit__ + * [__nRF52__](https://github.com/adafruit/Adafruit_nRF52_Arduino) - Adafruit Feather nRF528x, Bluefruit and CLUE + +* __Espressif__ + * [__ESP32__](https://github.com/espressif/arduino-esp32) - ESP32-based boards + * [__ESP8266__](https://github.com/esp8266/Arduino) - ESP8266-based boards + +* __Intel__ + * [__Curie__](https://github.com/arduino/ArduinoCore-arc32) - Arduino 101 + +* __SparkFun__ + * [__Apollo3__](https://github.com/sparkfun/Arduino_Apollo3) - Sparkfun Artemis Redboard + +* __ST Microelectronics__ + * [__STM32__ (official core)](https://github.com/stm32duino/Arduino_Core_STM32) - STM32 Nucleo, Discovery, Maple, BluePill, BlackPill etc. + * [__STM32__ (unofficial core)](https://github.com/rogerclarkmelbourne/Arduino_STM32) - STM32F1 and STM32F4-based boards The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platforms prior to releasing new version. From 325d925e9f48b825cae121f18d006a5c08c99e63 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 13:46:50 +0200 Subject: [PATCH 103/334] Travis added configuration for stm32duino F4 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a7381d87..a35b2190 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" - #- BOARD="stm32duino:STM32F4:discovery_f407" + - BOARD="stm32duino:STM32F4:discovery_f407:usb_cfg=usb_serial" addons: apt: From 6215330858ff09a4f2636d92f5f579ffe7d20b66 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:07:28 +0200 Subject: [PATCH 104/334] Added tone support --- src/BuildOpt.h | 5 +++++ src/Module.cpp | 16 ++++++++++++++++ src/Module.h | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 8273cd3f..5ea12a5e 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -18,6 +18,7 @@ * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platform does not support SoftwareSerial. * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platform that do not have SoftwareSerial support. + * RADIOLIB_TONE_UNSUPPORTED - some platforms do not have tone()/noTone(), which is required for AFSK. * * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). */ @@ -52,6 +53,7 @@ #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #elif defined(ARDUINO_ARCH_STM32) // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32) @@ -85,6 +87,7 @@ #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) // Adafruit nRF52 boards @@ -123,6 +126,7 @@ #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #elif defined(ARDUINO_ARDUINO_NANO33BLE) // Arduino Nano 33 BLE @@ -148,6 +152,7 @@ #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #else // other platforms not covered by the above list - this may or may not work diff --git a/src/Module.cpp b/src/Module.cpp index 8482e32c..67ac9ac8 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -294,3 +294,19 @@ RADIOLIB_PIN_STATUS Module::digitalRead(RADIOLIB_PIN_TYPE pin) { } return(LOW); } + +void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) { + #ifndef RADIOLIB_TONE_UNSUPPORTED + if(pin != RADIOLIB_NC) { + ::tone(pin, value); + } + #endif +} + +void Module::noTone(RADIOLIB_PIN_TYPE pin) { + #ifndef RADIOLIB_TONE_UNSUPPORTED + if(pin != RADIOLIB_NC) { + ::noTone(pin); + } + #endif +} diff --git a/src/Module.h b/src/Module.h index ebc81986..f6855a05 100644 --- a/src/Module.h +++ b/src/Module.h @@ -368,6 +368,22 @@ class Module { */ static RADIOLIB_PIN_STATUS digitalRead(RADIOLIB_PIN_TYPE pin); + /*! + \brief Arduino core tone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone. + + \param pin Pin to write to. + + \param value Frequency to output. + */ + static void tone(RADIOLIB_PIN_TYPE pin, uint16_t value); + + /*! + \brief Arduino core noTone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone. + + \param pin Pin to write to. + */ + static void noTone(RADIOLIB_PIN_TYPE pin); + #ifndef RADIOLIB_GODMODE private: #endif From 072e4288c96a45337be533b8459aec121a793693 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:09:25 +0200 Subject: [PATCH 105/334] [AFSK] Added AFSK support (#139) --- examples/AFSK/AFSK_Tone/AFSK_Tone.ino | 80 +++++++++++++++++++++++++++ keywords.txt | 5 ++ src/RadioLib.h | 1 + src/protocols/AFSK/AFSK.cpp | 21 +++++++ src/protocols/AFSK/AFSK.h | 57 +++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 examples/AFSK/AFSK_Tone/AFSK_Tone.ino create mode 100644 src/protocols/AFSK/AFSK.cpp create mode 100644 src/protocols/AFSK/AFSK.h diff --git a/examples/AFSK/AFSK_Tone/AFSK_Tone.ino b/examples/AFSK/AFSK_Tone/AFSK_Tone.ino new file mode 100644 index 00000000..09e66c28 --- /dev/null +++ b/examples/AFSK/AFSK_Tone/AFSK_Tone.ino @@ -0,0 +1,80 @@ +/* + RadioLib AFSK Example + + This example shows hot to send audio FSK tones + using SX1278's FSK modem. + + Other modules that can be used for AFSK: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - Si443x/RFM2x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// create AFSK client instance using the FSK module +// this requires connection to the module direct +// input pin, here connected to Arduino pin 5 +// SX127x/RFM9x: DIO2 +// RF69: DIO2 +// SX1231: DIO2 +// CC1101: GDO2 +// Si443x/RFM2x: GPIO +AFSKClient audio(&fsk, 5); + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + int state = fsk.beginFSK(); + + // when using one of the non-LoRa modules for AFSK + // (RF69, CC1101,, Si4432 etc.), use the basic begin() method + // int state = fsk.begin(); + + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } +} + +void loop() { + // AFSKClient can be used to transmit tones, + // same as Arduino tone() function + + // 400 Hz tone + audio.tone(400); + delay(1000); + + // silence + audio.noTone(); + delay(1000); + + // AFSKClient can also be used to transmit HAM-friendly + // RTTY, Morse code, Hellschreiber, SSTV and AX.25. + // Details on how to use AFSK are in the example + // folders for each of the above modes. +} diff --git a/keywords.txt b/keywords.txt index 21e58818..53b945b0 100644 --- a/keywords.txt +++ b/keywords.txt @@ -53,6 +53,7 @@ AX25Client KEYWORD1 AX25Frame KEYWORD1 SSTVClient KEYWORD1 HellClient KEYWORD1 +AFSKClient KEYWORD1 # SSTV modes Scottie1 KEYWORD1 @@ -225,6 +226,10 @@ getRangingResult KEYWORD2 # Hellschreiber printGlyph KEYWORD2 +# AFSK +tone KEYWORD2 +noTone KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### diff --git a/src/RadioLib.h b/src/RadioLib.h index b9446834..c6afae7a 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -91,6 +91,7 @@ // physical layer protocols #include "protocols/PhysicalLayer/PhysicalLayer.h" +#include "protocols/AFSK/AFSK.h" #include "protocols/AX25/AX25.h" #include "protocols/Hellschreiber/Hellschreiber.h" #include "protocols/Morse/Morse.h" diff --git a/src/protocols/AFSK/AFSK.cpp b/src/protocols/AFSK/AFSK.cpp new file mode 100644 index 00000000..a8453925 --- /dev/null +++ b/src/protocols/AFSK/AFSK.cpp @@ -0,0 +1,21 @@ +#include "AFSK.h" + +AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin) { + _phy = phy; + _pin = pin; +} + +int16_t AFSKClient::tone(uint16_t freq, bool autoStart) { + if(autoStart) { + int16_t state = _phy->transmitDirect(); + RADIOLIB_ASSERT(state); + } + + Module::tone(_pin, freq); + return(ERR_NONE); +} + +int16_t AFSKClient::noTone() { + Module::noTone(_pin); + return(_phy->standby()); +} diff --git a/src/protocols/AFSK/AFSK.h b/src/protocols/AFSK/AFSK.h new file mode 100644 index 00000000..c5c71221 --- /dev/null +++ b/src/protocols/AFSK/AFSK.h @@ -0,0 +1,57 @@ +#ifndef _RADIOLIB_AFSK_H +#define _RADIOLIB_AFSK_H + +#include "../../TypeDef.h" +#include "../../Module.h" + +#include "../PhysicalLayer/PhysicalLayer.h" + +/*! + \class AFSKClient + + \brief Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direct mode transmission using DIO pins. +*/ +class AFSKClient { + public: + /*! + \brief Default contructor. + + \param phy Pointer to the wireless module providing PhysicalLayer communication. + + \param pin The pin that will be used for audio output. + */ + AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin); + + /*! + \brief Start transmitting audio tone. + + \param freq Frequency of the tone in Hz. + + \param autoStart Whether to automatically enter transmission mode. Defaults to true. + + \returns \ref status_codes + */ + int16_t tone(uint16_t freq, bool autoStart = true); + + /*! + \brief Stops transmitting audio tone. + + \returns \ref status_codes + */ + int16_t noTone(); + +#ifndef RADIOLIB_GODMODE + private: +#endif + PhysicalLayer* _phy; + RADIOLIB_PIN_TYPE _pin; + + // allow specific classes access the private PhysicalLayer pointer + friend class RTTYClient; + friend class MorseClient; + friend class HellClient; + friend class SSTVClient; + friend class AX25Client; +}; + +#endif From ed699310410811a16ee8b01c5bf99b788bdcb97c Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:10:21 +0200 Subject: [PATCH 106/334] [AX25] Added AFSK support --- examples/AX25/AX25_Frames/AX25_Frames.ino | 3 + examples/AX25/AX25_Transmit/AX25_Transmit.ino | 7 +- .../AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino | 100 ++++++++++++++++++ src/protocols/AX25/AX25.cpp | 46 ++++++-- src/protocols/AX25/AX25.h | 18 +++- 5 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino diff --git a/examples/AX25/AX25_Frames/AX25_Frames.ino b/examples/AX25/AX25_Frames/AX25_Frames.ino index c6af0ad8..45cbba32 100644 --- a/examples/AX25/AX25_Frames/AX25_Frames.ino +++ b/examples/AX25/AX25_Frames/AX25_Frames.ino @@ -19,6 +19,9 @@ Frames shown in this example are not exhaustive; all possible AX.25 frames should be supported. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ */ // include the library diff --git a/examples/AX25/AX25_Transmit/AX25_Transmit.ino b/examples/AX25/AX25_Transmit/AX25_Transmit.ino index 0a462eff..6ab9c59e 100644 --- a/examples/AX25/AX25_Transmit/AX25_Transmit.ino +++ b/examples/AX25/AX25_Transmit/AX25_Transmit.ino @@ -12,6 +12,9 @@ - SX126x - nRF24 - Si443x/RFM2x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ */ // include the library @@ -37,8 +40,8 @@ void setup() { // initialize SX1278 Serial.print(F("[SX1278] Initializing ... ")); // carrier frequency: 434.0 MHz - // bit rate: 1.2 kbps (1200 baud AFSK AX.25) - // frequency deviation: 0.5 kHz (1200 baud AFSK AX.25) + // bit rate: 1.2 kbps (1200 baud 2-FSK AX.25) + // frequency deviation: 0.5 kHz (1200 baud 2-FSK AX.25) int state = fsk.beginFSK(434.0, 1.2, 0.5); // when using one of the non-LoRa modules for AX.25 diff --git a/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino new file mode 100644 index 00000000..aa9d82f4 --- /dev/null +++ b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino @@ -0,0 +1,100 @@ +/* + RadioLib AX.25 Transmit AFSK Example + + This example sends AX.25 messages using + SX1278's FSK modem. The data is modulated + as AFSK at 1200 baud using Bell 202 tones. + + Other modules that can be used for AX.25 + with AFSK modulation: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - nRF24 + - Si443x/RFM2x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1278 fsk = RadioShield.ModuleA; + +// create AFSK client instance using the FSK module +// pin 5 is connected to SX1278 DIO2 +AFSKClient audio(&fsk, 5); + +// create AX.25 client instance using the AFSK instance +AX25Client ax25(&audio); + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + int state = fsk.beginFSK(434.0); + + // when using one of the non-LoRa modules for AX.25 + // (RF69, CC1101,, Si4432 etc.), use the basic begin() method + // int state = fsk.begin(); + + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // initialize AX.25 client + Serial.print(F("[AX.25] Initializing ... ")); + // source station callsign: "N7LEM" + // source station SSID: 0 + // preamble length: 8 bytes + state = ax25.begin("N7LEM"); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } +} + +void loop() { + // send AX.25 unnumbered information frame + Serial.print(F("[AX.25] Sending UI frame ... ")); + // destination station callsign: "NJ7P" + // destination station SSID: 0 + int state = ax25.transmit("Hello World!", "NJ7P"); + if (state == ERR_NONE) { + // the packet was successfully transmitted + Serial.println(F("success!")); + + } else { + // some error occurred + Serial.print(F("failed, code ")); + Serial.println(state); + + } + + delay(1000); +} diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index 7c6a7933..1693cbe7 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -112,6 +112,12 @@ void AX25Frame::setSendSequence(uint8_t seqNumber) { AX25Client::AX25Client(PhysicalLayer* phy) { _phy = phy; + _audio = nullptr; +} + +AX25Client::AX25Client(AFSKClient* audio) { + _phy = audio->_phy; + _audio = audio; } int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preambleLen) { @@ -130,11 +136,14 @@ int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t prea // save preamble length _preambleLen = preambleLen; - // disable physical layer data shaping and set encoding to NRZ - int16_t state = _phy->setDataShaping(0.0); - RADIOLIB_ASSERT(state); + // set module frequency deviation to 0 if using FSK + int16_t state = ERR_NONE; + if(_audio == nullptr) { + state = _phy->setFrequencyDeviation(0); + RADIOLIB_ASSERT(state); - state = _phy->setEncoding(0); + state = _phy->setEncoding(0); + } return(state); } @@ -154,7 +163,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { if(strlen(frame->destCallsign) > AX25_MAX_CALLSIGN_LEN) { return(ERR_INVALID_CALLSIGN); } - + // check repeater configuration #ifndef RADIOLIB_STATIC_ONLY if(!(((frame->repeaterCallsigns == NULL) && (frame->repeaterSSIDs == NULL) && (frame->numRepeaters == 0)) || @@ -333,7 +342,32 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { } // transmit - int16_t state = _phy->transmit(stuffedFrameBuff, stuffedFrameBuffLen); + int16_t state = ERR_NONE; + if(_audio == nullptr) { + state = _phy->transmit(stuffedFrameBuff, stuffedFrameBuffLen); + } else { + _phy->transmitDirect(); + + // iterate over all bytes in the buffer + for(uint32_t i = 0; i < stuffedFrameBuffLen; i++) { + + // check each bit + for(uint16_t mask = 0x80; mask >= 0x01; mask >>= 1) { + uint32_t start = micros(); + if(stuffedFrameBuff[i] & mask) { + _audio->tone(AX25_AFSK_MARK, false); + } else { + _audio->tone(AX25_AFSK_SPACE, false); + } + while(micros() - start < 833) { + yield(); + } + } + + } + + _audio->noTone(); + } // deallocate memory #ifndef RADIOLIB_STATIC_ONLY diff --git a/src/protocols/AX25/AX25.h b/src/protocols/AX25/AX25.h index bfe322af..dc385dfa 100644 --- a/src/protocols/AX25/AX25.h +++ b/src/protocols/AX25/AX25.h @@ -3,6 +3,7 @@ #include "../../TypeDef.h" #include "../PhysicalLayer/PhysicalLayer.h" +#include "../AFSK/AFSK.h" // macros to access bits in byte array, from http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html #define SET_BIT_IN_ARRAY(A, k) ( A[(k/8)] |= (1 << (k%8)) ) @@ -69,6 +70,13 @@ #define AX25_PID_NO_LAYER_3 0xF0 #define AX25_PID_ESCAPE_CHARACTER 0xFF +// AFSK tones in Hz +#define AX25_AFSK_MARK 1200 +#define AX25_AFSK_SPACE 2200 + +// tone duration in us (for 1200 baud AFSK) +#define AX25_AFSK_TONE_DURATION 833 + /*! \class AX25Frame @@ -254,12 +262,19 @@ class AX25Frame { class AX25Client { public: /*! - \brief Default constructor. + \brief Constructor for 2-FSK mode. \param phy Pointer to the wireless module providing PhysicalLayer communication. */ AX25Client(PhysicalLayer* phy); + /*! + \brief Constructor for AFSK mode. + + \param audio Pointer to the AFSK instance providing audio. + */ + AX25Client(AFSKClient* audio); + // basic methods /*! @@ -301,6 +316,7 @@ class AX25Client { private: #endif PhysicalLayer* _phy; + AFSKClient* _audio; char _srcCallsign[AX25_MAX_CALLSIGN_LEN + 1]; uint8_t _srcSSID; From 21c0703383706aee05f9cb5e6c13255defbdb873 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:10:37 +0200 Subject: [PATCH 107/334] [Hell] Added AFSK support --- .../Hellschreiber_Transmit.ino | 3 + .../Hellschreiber_Transmit_AFSK.ino | 122 ++++++++++++++++++ src/protocols/Hellschreiber/Hellschreiber.cpp | 36 +++++- src/protocols/Hellschreiber/Hellschreiber.h | 18 ++- 4 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino diff --git a/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino b/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino index c1d74d31..a8dda9f0 100644 --- a/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino +++ b/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino @@ -13,6 +13,9 @@ - nRF24 - Si443x/RFM2x - SX128x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ */ // include the library diff --git a/examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino b/examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino new file mode 100644 index 00000000..ec2aa4e7 --- /dev/null +++ b/examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino @@ -0,0 +1,122 @@ +/* + RadioLib Hellschreiber Transmit AFSK Example + + This example sends Hellschreiber message using + SX1278's FSK modem. The data is modulated + as AFSK. + + Other modules that can be used for Hellschreiber + with AFSK modulation: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - Si443x/RFM2x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1278 fsk = RadioShield.ModuleA; + +// create AFSK client instance using the FSK module +// pin 5 is connected to SX1278 DIO2 +AFSKClient audio(&fsk, 5); + +// create Hellschreiber client instance using the AFSK instance +HellClient hell(&audio); + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + int state = fsk.beginFSK(); + + // when using one of the non-LoRa modules for Morse code + // (RF69, CC1101, Si4432 etc.), use the basic begin() method + // int state = fsk.begin(); + + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // initialize Hellschreiber client + Serial.print(F("[Hell] Initializing ... ")); + // AFSK tone frequency: 400 Hz + // speed: 122.5 Baud ("Feld Hell") + state = hell.begin(400); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } +} + +void loop() { + Serial.print(F("[Hell] Sending Hellschreiber data ... ")); + + // HellClient supports all methods of the Serial class + // NOTE: Lower case letter will be capitalized. + + // Arduino String class + String aStr = "Arduino String"; + hell.print(aStr); + + // character array (C-String) + hell.print("C-String"); + + // string saved in flash + hell.print(F("Flash String")); + + // character + hell.print('c'); + + // byte + // formatting DEC/HEX/OCT/BIN is supported for + // any integer type (byte/int/long) + hell.print(255, HEX); + + // integer number + int i = 1000; + hell.print(i); + + // floating point number + // NOTE: println() has no effect on the transmission, + // and is only kept for compatibility reasons. + float f = -3.1415; + hell.println(f, 3); + + // custom glyph - must be a 7 byte array of rows 7 pixels long + uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 }; + hell.printGlyph(customGlyph); + + Serial.println(F("done!")); + + // wait for a second before transmitting again + delay(1000); +} diff --git a/src/protocols/Hellschreiber/Hellschreiber.cpp b/src/protocols/Hellschreiber/Hellschreiber.cpp index ffc30ee3..3f769add 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.cpp +++ b/src/protocols/Hellschreiber/Hellschreiber.cpp @@ -2,17 +2,27 @@ HellClient::HellClient(PhysicalLayer* phy) { _phy = phy; + _audio = nullptr; +} + +HellClient::HellClient(AFSKClient* audio) { + _phy = audio->_phy; + _audio = audio; } int16_t HellClient::begin(float base, float rate) { // calculate 24-bit frequency + _baseHz = base; _base = (base * 1000000.0) / _phy->getFreqStep(); // calculate "pixel" duration _pixelDuration = 1000000.0/rate; - // set module frequency deviation to 0 - int16_t state = _phy->setFrequencyDeviation(0); + // set module frequency deviation to 0 if using FSK + int16_t state = ERR_NONE; + if(_audio == nullptr) { + state = _phy->setFrequencyDeviation(0); + } return(state); } @@ -23,16 +33,16 @@ size_t HellClient::printGlyph(uint8_t* buff) { for(int8_t i = HELL_FONT_HEIGHT - 1; i >= 0; i--) { uint32_t start = micros(); if(buff[i] & mask) { - _phy->transmitDirect(_base); + transmitDirect(_base, _baseHz); } else { - _phy->standby(); + standby(); } while(micros() - start < _pixelDuration); } } // make sure transmitter is off - _phy->standby(); + standby(); return(1); } @@ -269,3 +279,19 @@ size_t HellClient::printFloat(double number, uint8_t digits) { return n; } + +int16_t HellClient::transmitDirect(uint32_t freq, uint32_t freqHz) { + if(_audio != nullptr) { + return(_audio->tone(freqHz)); + } else { + return(_phy->transmitDirect(freq)); + } +} + +int16_t HellClient::standby() { + if(_audio != nullptr) { + return(_audio->noTone()); + } else { + return(_phy->standby()); + } +} diff --git a/src/protocols/Hellschreiber/Hellschreiber.h b/src/protocols/Hellschreiber/Hellschreiber.h index 9b14c27e..8756df5f 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.h +++ b/src/protocols/Hellschreiber/Hellschreiber.h @@ -3,6 +3,7 @@ #include "../../TypeDef.h" #include "../PhysicalLayer/PhysicalLayer.h" +#include "../AFSK/AFSK.h" #define HELL_FONT_WIDTH 7 #define HELL_FONT_HEIGHT 7 @@ -85,18 +86,25 @@ static const uint8_t HellFont[64][HELL_FONT_WIDTH - 2] PROGMEM = { class HellClient { public: /*! - \brief Default constructor. + \brief Constructor for 2-FSK mode. \param phy Pointer to the wireless module providing PhysicalLayer communication. */ HellClient(PhysicalLayer* phy); + /*! + \brief Constructor for AFSK mode. + + \param audio Pointer to the AFSK instance providing audio. + */ + HellClient(AFSKClient* audio); + // basic methods /*! \brief Initialization method. - \param base Base RF frequency to be used in MHz. + \param base Base RF frequency to be used in MHz (in 2-FSK mode), or the tone frequency in Hz (in AFSK mode). \param rate Baud rate to be used during transmission. Defaults to 122.5 ("Feld Hell") */ @@ -140,12 +148,16 @@ class HellClient { private: #endif PhysicalLayer* _phy; + AFSKClient* _audio; - uint32_t _base; + uint32_t _base, _baseHz; uint32_t _pixelDuration; size_t printNumber(unsigned long, uint8_t); size_t printFloat(double, uint8_t); + + int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0); + int16_t standby(); }; #endif From 0a705f5bb9a54833c7fdc01d24bf4083f1e28c8f Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:10:54 +0200 Subject: [PATCH 108/334] [Morse] Added AFSK support --- .../Morse/Morse_Transmit/Morse_Transmit.ino | 3 + .../Morse_Transmit_AFSK.ino | 123 ++++++++++++++++++ src/protocols/Morse/Morse.cpp | 40 +++++- src/protocols/Morse/Morse.h | 19 ++- 4 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino diff --git a/examples/Morse/Morse_Transmit/Morse_Transmit.ino b/examples/Morse/Morse_Transmit/Morse_Transmit.ino index e0d6d1fe..4f3c07e4 100644 --- a/examples/Morse/Morse_Transmit/Morse_Transmit.ino +++ b/examples/Morse/Morse_Transmit/Morse_Transmit.ino @@ -13,6 +13,9 @@ - nRF24 - Si443x/RFM2x - SX128x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ */ // include the library diff --git a/examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino b/examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino new file mode 100644 index 00000000..3dbb5d6f --- /dev/null +++ b/examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino @@ -0,0 +1,123 @@ +/* + RadioLib Morse Transmit AFSK Example + + This example sends Morse code message using + SX1278's FSK modem. The data is modulated + as AFSK. + + Other modules that can be used for Morse Code + with AFSK modulation: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - Si443x/RFM2x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1278 fsk = RadioShield.ModuleA; + +// create AFSK client instance using the FSK module +// pin 5 is connected to SX1278 DIO2 +AFSKClient audio(&fsk, 5); + +// create Morse client instance using the AFSK instance +MorseClient morse(&audio); + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + int state = fsk.beginFSK(); + + // when using one of the non-LoRa modules for Morse code + // (RF69, CC1101, Si4432 etc.), use the basic begin() method + // int state = fsk.begin(); + + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // initialize Morse client + Serial.print(F("[Morse] Initializing ... ")); + // AFSK tone frequency: 400 MHz + // speed: 20 words per minute + state = morse.begin(400); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } +} + +void loop() { + Serial.print(F("[Morse] Sending Morse data ... ")); + + // MorseClient supports all methods of the Serial class + // NOTE: Characters that do not have ITU-R M.1677-1 + // representation will not be sent! Lower case + // letters will be capitalized. + + // send start signal first + morse.startSignal(); + + // Arduino String class + String aStr = "Arduino String"; + morse.print(aStr); + + // character array (C-String) + morse.print("C-String"); + + // string saved in flash + morse.print(F("Flash String")); + + // character + morse.print('c'); + + // byte + // formatting DEC/HEX/OCT/BIN is supported for + // any integer type (byte/int/long) + morse.print(255, HEX); + + // integer number + int i = 1000; + morse.print(i); + + // floating point number + // NOTE: When using println(), the transmission will be + // terminated with end-of-work signal (...-.-). + float f = -3.1415; + morse.println(f, 3); + + Serial.println(F("done!")); + + // wait for a second before transmitting again + delay(1000); +} diff --git a/src/protocols/Morse/Morse.cpp b/src/protocols/Morse/Morse.cpp index 6b3e0c16..fe516132 100644 --- a/src/protocols/Morse/Morse.cpp +++ b/src/protocols/Morse/Morse.cpp @@ -2,17 +2,27 @@ MorseClient::MorseClient(PhysicalLayer* phy) { _phy = phy; + _audio = nullptr; +} + +MorseClient::MorseClient(AFSKClient* audio) { + _phy = audio->_phy; + _audio = audio; } int16_t MorseClient::begin(float base, uint8_t speed) { // calculate 24-bit frequency + _baseHz = base; _base = (base * 1000000.0) / _phy->getFreqStep(); // calculate dot length (assumes PARIS as typical word) _dotLength = 1200 / speed; - // set module frequency deviation to 0 - int16_t state = _phy->setFrequencyDeviation(0); + // set module frequency deviation to 0 if using FSK + int16_t state = ERR_NONE; + if(_audio == nullptr) { + state = _phy->setFrequencyDeviation(0); + } return(state); } @@ -46,7 +56,7 @@ size_t MorseClient::write(uint8_t b) { // inter-word pause (space) if(b == ' ') { RADIOLIB_DEBUG_PRINTLN(F("space")); - _phy->standby(); + standby(); delay(4 * _dotLength); return(1); } @@ -65,16 +75,16 @@ size_t MorseClient::write(uint8_t b) { // send dot or dash if (code & MORSE_DASH) { RADIOLIB_DEBUG_PRINT('-'); - _phy->transmitDirect(_base); + transmitDirect(_base, _baseHz); delay(3 * _dotLength); } else { RADIOLIB_DEBUG_PRINT('.'); - _phy->transmitDirect(_base); + transmitDirect(_base, _baseHz); delay(_dotLength); } // symbol space - _phy->standby(); + standby(); delay(_dotLength); // move onto the next bit @@ -82,7 +92,7 @@ size_t MorseClient::write(uint8_t b) { } // letter space - _phy->standby(); + standby(); delay(2 * _dotLength); RADIOLIB_DEBUG_PRINTLN(); @@ -283,3 +293,19 @@ size_t MorseClient::printFloat(double number, uint8_t digits) { return n; } + +int16_t MorseClient::transmitDirect(uint32_t freq, uint32_t freqHz) { + if(_audio != nullptr) { + return(_audio->tone(freqHz)); + } else { + return(_phy->transmitDirect(freq)); + } +} + +int16_t MorseClient::standby() { + if(_audio != nullptr) { + return(_audio->noTone()); + } else { + return(_phy->standby()); + } +} diff --git a/src/protocols/Morse/Morse.h b/src/protocols/Morse/Morse.h index 66df3280..e09fece0 100644 --- a/src/protocols/Morse/Morse.h +++ b/src/protocols/Morse/Morse.h @@ -3,6 +3,7 @@ #include "../../TypeDef.h" #include "../PhysicalLayer/PhysicalLayer.h" +#include "../AFSK/AFSK.h" #define MORSE_DOT 0b0 #define MORSE_DASH 0b1 @@ -88,18 +89,25 @@ static const uint8_t MorseTable[] PROGMEM = { class MorseClient { public: /*! - \brief Default constructor. + \brief Constructor for 2-FSK mode. \param phy Pointer to the wireless module providing PhysicalLayer communication. */ MorseClient(PhysicalLayer* phy); + /*! + \brief Constructor for AFSK mode. + + \param audio Pointer to the AFSK instance providing audio. + */ + MorseClient(AFSKClient* audio); + // basic methods /*! \brief Initialization method. - \param base Base RF frequency to be used in MHz. + \param base Base RF frequency to be used in MHz (in 2-FSK mode), or the tone frequency in Hz (in AFSK mode) \param speed Coding speed in words per minute. @@ -145,11 +153,16 @@ class MorseClient { private: #endif PhysicalLayer* _phy; - uint32_t _base; + AFSKClient* _audio; + + uint32_t _base, _baseHz; uint16_t _dotLength; size_t printNumber(unsigned long, uint8_t); size_t printFloat(double, uint8_t); + + int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0); + int16_t standby(); }; #endif From f7f81cd41e44ac06e19495e370e3aa5513cdecd9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:11:09 +0200 Subject: [PATCH 109/334] [RTTY] Added AFSK support --- .../RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino | 133 ++++++++++++++++++ src/protocols/RTTY/RTTY.cpp | 40 +++++- src/protocols/RTTY/RTTY.h | 20 ++- 3 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino diff --git a/examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino b/examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino new file mode 100644 index 00000000..d836821e --- /dev/null +++ b/examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino @@ -0,0 +1,133 @@ +/* + RadioLib RTTY Transmit AFSK Example + + This example sends RTTY message using SX1278's + FSK modem. The data is modulated as AFSK. + + Other modules that can be used for RTTY: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - Si443x/RFM2x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1278 fsk = RadioShield.ModuleA; + +// create AFSK client instance using the FSK module +// pin 5 is connected to SX1278 DIO2 +AFSKClient audio(&fsk, 5); + +// create RTTY client instance using the AFSK instance +RTTYClient rtty(&audio); + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + int state = fsk.beginFSK(); + + // when using one of the non-LoRa modules for RTTY + // (RF69, CC1101, Si4432 etc.), use the basic begin() method + // int state = fsk.begin(); + + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // initialize RTTY client + // NOTE: Unlike FSK RTTY, AFSK requires no rounding of + // the frequency shift. + Serial.print(F("[RTTY] Initializing ... ")); + // space frequency: 400 Hz + // frequency shift: 170 Hz + // baud rate: 45 baud + // encoding: ASCII (7-bit) + // stop bits: 1 + state = rtty.begin(400, 170, 45); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + /* + // RadioLib also provides ITA2 ("Baudot") support + rtty.begin(400, 170, 45, ITA2); + + // All transmissions in loop() (strings and numbers) + // will now be encoded using ITA2 code + + // ASCII characters that do not have ITA2 equivalent + // will be sent as NUL (including lower case letters!) + */ +} + +void loop() { + Serial.print(F("[RTTY] Sending RTTY data ... ")); + + // send out idle condition for 500 ms + rtty.idle(); + delay(500); + + // RTTYClient supports all methods of the Serial class + + // Arduino String class + String aStr = "Arduino String"; + rtty.println(aStr); + + // character array (C-String) + rtty.println("C-String"); + + // string saved in flash + rtty.println(F("Flash String")); + + // character + rtty.println('c'); + + // byte + // formatting DEC/HEX/OCT/BIN is supported for + // any integer type (byte/int/long) + rtty.println(255, HEX); + + // integer number + int i = 1000; + rtty.println(i); + + // floating point number + float f = -3.1415; + rtty.println(f, 3); + + Serial.println(F("done!")); + + // wait for a second before transmitting again + delay(1000); +} diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index 085d3794..1a96d5e2 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -106,12 +106,20 @@ uint16_t ITA2String::getBits(char c) { RTTYClient::RTTYClient(PhysicalLayer* phy) { _phy = phy; + _audio = nullptr; +} + +RTTYClient::RTTYClient(AFSKClient* audio) { + _phy = audio->_phy; + _audio = audio; } int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t encoding, uint8_t stopBits) { // save configuration _encoding = encoding; _stopBits = stopBits; + _baseHz = base; + _shiftHz = shift; switch(encoding) { case ASCII: @@ -148,15 +156,17 @@ int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t enc // calculate 24-bit frequency _base = (base * 1000000.0) / _phy->getFreqStep(); - // set module frequency deviation to 0 - int16_t state = _phy->setFrequencyDeviation(0); + // set module frequency deviation to 0 if using FSK + int16_t state = ERR_NONE; + if(_audio == nullptr) { + state = _phy->setFrequencyDeviation(0); + } return(state); } void RTTYClient::idle() { - _phy->transmitDirect(); - + transmitDirect(); mark(); } @@ -190,7 +200,7 @@ size_t RTTYClient::write(uint8_t b) { mark(); } - _phy->standby(); + standby(); return(1); } @@ -391,7 +401,7 @@ size_t RTTYClient::println(double d, int digits) { void RTTYClient::mark() { uint32_t start = micros(); - _phy->transmitDirect(_base + _shift); + transmitDirect(_base + _shift, _baseHz + _shiftHz); while(micros() - start < _bitDuration) { yield(); } @@ -399,7 +409,7 @@ void RTTYClient::mark() { void RTTYClient::space() { uint32_t start = micros(); - _phy->transmitDirect(_base); + transmitDirect(_base, _baseHz); while(micros() - start < _bitDuration) { yield(); } @@ -505,3 +515,19 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) { return n; } + +int16_t RTTYClient::transmitDirect(uint32_t freq, uint32_t freqHz) { + if(_audio != nullptr) { + return(_audio->tone(freqHz)); + } else { + return(_phy->transmitDirect(freq)); + } +} + +int16_t RTTYClient::standby() { + if(_audio != nullptr) { + return(_audio->noTone()); + } else { + return(_phy->standby()); + } +} diff --git a/src/protocols/RTTY/RTTY.h b/src/protocols/RTTY/RTTY.h index 5c22568c..1e6120c1 100644 --- a/src/protocols/RTTY/RTTY.h +++ b/src/protocols/RTTY/RTTY.h @@ -3,6 +3,7 @@ #include "../../TypeDef.h" #include "../PhysicalLayer/PhysicalLayer.h" +#include "../AFSK/AFSK.h" #define ITA2_FIGS 0x1B #define ITA2_LTRS 0x1F @@ -84,18 +85,25 @@ class ITA2String { class RTTYClient { public: /*! - \brief Default constructor. + \brief Constructor for 2-FSK mode. \param phy Pointer to the wireless module providing PhysicalLayer communication. */ RTTYClient(PhysicalLayer* phy); + /*! + \brief Constructor for AFSK mode. + + \param audio Pointer to the AFSK instance providing audio. + */ + RTTYClient(AFSKClient* audio); + // basic methods /*! \brief Initialization method. - \param base Base (space) RF frequency to be used in MHz. + \param base Base (space) frequency to be used in MHz (in 2-FSK mode), or the space tone frequency in Hz (in AFSK mode) \param shift Frequency shift between mark and space in Hz. @@ -147,10 +155,11 @@ class RTTYClient { private: #endif PhysicalLayer* _phy; + AFSKClient* _audio; uint8_t _encoding; - uint32_t _base; - uint32_t _shift; + uint32_t _base, _baseHz; + uint32_t _shift, _shiftHz; uint32_t _bitDuration; uint8_t _dataBits; uint8_t _stopBits; @@ -160,6 +169,9 @@ class RTTYClient { size_t printNumber(unsigned long, uint8_t); size_t printFloat(double, uint8_t); + + int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0); + int16_t standby(); }; #endif From 0a07f22e931efe61ceb0c61993214a0a73791892 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:11:24 +0200 Subject: [PATCH 110/334] [SSTV] Added AFSK support --- .../SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino | 155 ++++++++++++++++++ src/protocols/SSTV/SSTV.cpp | 30 +++- src/protocols/SSTV/SSTV.h | 30 +++- 3 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino diff --git a/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino b/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino new file mode 100644 index 00000000..b43c3743 --- /dev/null +++ b/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino @@ -0,0 +1,155 @@ +/* + RadioLib SSTV Transmit AFSK Example + + The following example sends SSTV picture using + SX1278's FSK modem. The data is modulated + as AFSK. + + Other modules that can be used for SSTV: + with AFSK modulation: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - Si443x/RFM2x + + NOTE: Some platforms (such as Arduino Uno) + might not be fast enough to correctly + send pictures via high-speed modes + like Scottie2 or Martin2. For those, + lower speed modes such as Wrasse, + Scottie1 or Martin1 are recommended. + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1278 fsk = RadioShield.ModuleA; + +// create AFSK client instance using the FSK module +// pin 5 is connected to SX1278 DIO2 +AFSKClient audio(&fsk, 5); + +// create SSTV client instance using the AFSK instance +SSTVClient sstv(&audio); + +// test "image" - actually just a single 320px line +// will be sent over and over again, to create vertical color stripes at the receiver +uint32_t line[320] = { + // black + 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, + 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, + + // blue + 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, + 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, + + // green + 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, + 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, + + // cyan + 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, + 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, + + // red + 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, + 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, + + // magenta + 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, + 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, + + // yellow + 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, + 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, + + // white + 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, + 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF +}; + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + int state = fsk.beginFSK(); + if (state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while (true); + } + + // when using one of the non-LoRa modules for SSTV + // (RF69, SX1231 etc.), use the basic begin() method + // int state = fsk.begin(); + + // initialize SSTV client + Serial.print(F("[SSTV] Initializing ... ")); + // SSTV mode: Wrasse (SC2-180) + // correction factor: 0.95 + // NOTE: Due to different speeds of various platforms + // supported by RadioLib (Arduino Uno, ESP32 etc), + // and because SSTV is analog protocol, incorrect + // timing of pulses can lead to distortions. + // To compensate, correction factor can be used + // to adjust the length of timing pulses + // (lower number = shorter pulses). + // The value is usually around 0.95 (95%). + state = sstv.begin(Wrasse, 0.95); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + + // to help tune the receiver, SSTVClient can send + // continuous 1900 Hz beep + /* + sstv.idle(); + while(true); + */ +} + +void loop() { + // send picture with 8 color stripes + Serial.print(F("[SSTV] Sending test picture ... ")); + + // send synchronization header first + sstv.sendHeader(); + + // send all picture lines + for(uint16_t i = 0; i < sstv.getPictureHeight(); i++) { + sstv.sendLine(line); + } + + // turn off transmitter + fsk.standby(); + + Serial.println(F("done!")); + + delay(30000); +} diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp index c3843ad8..4bc16902 100644 --- a/src/protocols/SSTV/SSTV.cpp +++ b/src/protocols/SSTV/SSTV.cpp @@ -155,6 +155,21 @@ const SSTVMode_t PasokonP7 { SSTVClient::SSTVClient(PhysicalLayer* phy) { _phy = phy; + _audio = nullptr; +} + +SSTVClient::SSTVClient(AFSKClient* audio) { + _phy = audio->_phy; + _audio = audio; +} + +int16_t SSTVClient::begin(SSTVMode_t mode, float correction) { + if(_audio == nullptr) { + // this initialization method can only be used in AFSK mode + return(ERR_WRONG_MODEM); + } + + return(begin(0, mode, correction)); } int16_t SSTVClient::begin(float base, SSTVMode_t mode, float correction) { @@ -170,19 +185,24 @@ int16_t SSTVClient::begin(float base, SSTVMode_t mode, float correction) { // calculate 24-bit frequency _base = (base * 1000000.0) / _phy->getFreqStep(); - // set module frequency deviation to 0 - int16_t state = _phy->setFrequencyDeviation(0); + // set module frequency deviation to 0 if using FSK + int16_t state = ERR_NONE; + if(_audio == nullptr) { + state = _phy->setFrequencyDeviation(0); + } return(state); } void SSTVClient::idle() { + _phy->transmitDirect(); tone(SSTV_TONE_LEADER); } void SSTVClient::sendHeader() { // save first header flag for Scottie modes _firstLine = true; + _phy->transmitDirect(); // send the first part of header (leader-break-leader) tone(SSTV_TONE_LEADER, SSTV_HEADER_LEADER_LENGTH); @@ -261,7 +281,11 @@ uint16_t SSTVClient::getPictureHeight() { void SSTVClient::tone(float freq, uint32_t len) { uint32_t start = micros(); - _phy->transmitDirect(_base + (freq / _phy->getFreqStep())); + if(_audio != nullptr) { + _audio->tone(freq, false); + } else { + _phy->transmitDirect(_base + (freq / _phy->getFreqStep())); + } while(micros() - start < len) { yield(); } diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h index d8dc0c8b..4c6777d0 100644 --- a/src/protocols/SSTV/SSTV.h +++ b/src/protocols/SSTV/SSTV.h @@ -3,6 +3,7 @@ #include "../../TypeDef.h" #include "../PhysicalLayer/PhysicalLayer.h" +#include "../AFSK/AFSK.h" // the following implementation is based on information from // http://www.barberdsp.com/downloads/Dayton%20Paper.pdf @@ -116,23 +117,45 @@ extern const SSTVMode_t PasokonP7; class SSTVClient { public: /*! - \brief Default constructor. + \brief Constructor for 2-FSK mode. \param phy Pointer to the wireless module providing PhysicalLayer communication. */ SSTVClient(PhysicalLayer* phy); + /*! + \brief Constructor for AFSK mode. + + \param audio Pointer to the AFSK instance providing audio. + */ + SSTVClient(AFSKClient* phy); + // basic methods /*! - \brief Initialization method. + \brief Initialization method for 2-FSK. - \param base Base RF frequency to be used in MHz. In USB modulation, this corresponds to "0 Hz tone". + \param base Base "0 Hz tone" RF frequency to be used in MHz. \param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7. + + \param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction). + + \returns \ref status_codes */ int16_t begin(float base, SSTVMode_t mode, float correction = 1.0); + /*! + \brief Initialization method for AFSK. + + \param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7. + + \param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction). + + \returns \ref status_codes + */ + int16_t begin(SSTVMode_t mode, float correction = 1.0); + /*! \brief Sends out tone at 1900 Hz. */ @@ -161,6 +184,7 @@ class SSTVClient { private: #endif PhysicalLayer* _phy; + AFSKClient* _audio; uint32_t _base; SSTVMode_t _mode; From c389e68ee8b4d9bddccd57b0d959de54db2d4141 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 17:11:54 +0200 Subject: [PATCH 111/334] Added notes about AFSK TRAVIS_FORCE_BUILD --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b56ab927..884d0c1f 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,20 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github * __XBee__ modules (S2B) ### Supported protocols and digital modes: -* __MQTT__ for modules: ESP8266 -* __HTTP__ for modules: ESP8266 -* __AX.25__ for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x -* [__RTTY__](https://www.sigidwiki.com/wiki/RTTY) for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x -* [__Morse Code__](https://www.sigidwiki.com/wiki/Morse_Code_(CW)) for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x -* [__SSTV__](https://www.sigidwiki.com/wiki/SSTV) for modules: SX127x, RFM9x, SX126x, RF69 and SX1231 -* [__Hellschreiber__](https://www.sigidwiki.com/wiki/Hellschreiber) for modules: SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x +* __MQTT__ for modules: +ESP8266 +* __HTTP__ for modules: +ESP8266 +* __AX.25__ using 2-FSK or AFSK for modules: +SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x +* [__RTTY__](https://www.sigidwiki.com/wiki/RTTY) using 2-FSK or AFSK for modules: +SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x +* [__Morse Code__](https://www.sigidwiki.com/wiki/Morse_Code_(CW)) using 2-FSK or AFSK for modules: +SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x +* [__SSTV__](https://www.sigidwiki.com/wiki/SSTV) using 2-FSK or AFSK for modules: +SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x +* [__Hellschreiber__](https://www.sigidwiki.com/wiki/Hellschreiber) using 2-FSK or AFSK for modules: +SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x ### Supported platforms: * __Arduino__ @@ -66,6 +73,7 @@ The list above is by no means exhaustive. Most of RadioLib code is independent o ### In development: * __SIM800C__ GSM module * __LoRaWAN__ protocol for SX127x, RFM9x and SX126x modules +* __APRS__ protocol for all the modules that can transmit AX.25 * ___and more!___ ## Frequently Asked Questions From 288d8a3051b70944117bcab9290d1acf5a444da3 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 18:29:57 +0200 Subject: [PATCH 112/334] Travis attempt to fix exec not found error for STM32F4 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a35b2190..72221365 100644 --- a/.travis.yml +++ b/.travis.yml @@ -107,8 +107,9 @@ before_install: arduino --install-boards stm32duino:STM32F1; elif [[ "$BOARD" =~ "stm32duino:STM32F4:" ]]; then - export BUILD_EXAMPLES=false; + export BUILD_EXAMPLES=true; arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; + arduino --install-boards stm32duino:STM32F1; arduino --install-boards stm32duino:STM32F4; fi From c8e1c48c006987f54de8f16573da0a62da88b348 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 18:44:27 +0200 Subject: [PATCH 113/334] Travis trying different STM32F4 board --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 72221365..7c1f8700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ env: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt - BOARD="arduino:avr:uno" + - BOARD="stm32duino:STM32F4:generic_f407v:usb_cfg=usb_serial" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" @@ -18,7 +19,6 @@ env: - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" - - BOARD="stm32duino:STM32F4:discovery_f407:usb_cfg=usb_serial" addons: apt: @@ -109,7 +109,6 @@ before_install: elif [[ "$BOARD" =~ "stm32duino:STM32F4:" ]]; then export BUILD_EXAMPLES=true; arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; - arduino --install-boards stm32duino:STM32F1; arduino --install-boards stm32duino:STM32F4; fi From 59fa831d996b0cbcb37c041c286b3211e0fdc91d Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 18:48:13 +0200 Subject: [PATCH 114/334] Travis added upload method to STM32F4 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c1f8700..619d72d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ env: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt - BOARD="arduino:avr:uno" - - BOARD="stm32duino:STM32F4:generic_f407v:usb_cfg=usb_serial" + - BOARD="stm32duino:STM32F4:generic_f407v:usb_cfg=usb_serial,upload_method=STLinkMethod" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" From 9477789e9be195f5b036e61ed814a2cab13dbe7d Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 30 Apr 2020 18:51:21 +0200 Subject: [PATCH 115/334] Travis removed STM32F4 --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 619d72d1..dbb1da43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ env: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt - BOARD="arduino:avr:uno" - - BOARD="stm32duino:STM32F4:generic_f407v:usb_cfg=usb_serial,upload_method=STLinkMethod" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" @@ -106,11 +105,6 @@ before_install: arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; arduino --install-boards stm32duino:STM32F1; - elif [[ "$BOARD" =~ "stm32duino:STM32F4:" ]]; then - export BUILD_EXAMPLES=true; - arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; - arduino --install-boards stm32duino:STM32F4; - fi # check if this release commit (or forced build) and if so, build for every board From eccf6e3865e2073bf17bf7b166e3a6c36d455442 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 1 May 2020 13:50:29 +0200 Subject: [PATCH 116/334] [ESP8266] Fixed format overflow warning --- src/modules/ESP8266/ESP8266.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index f55d7c9d..bc372ac6 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -131,7 +131,7 @@ int16_t ESP8266::closeTransportConnection() { int16_t ESP8266::send(const char* data) { // build AT command - char lenStr[8]; + char lenStr[12]; sprintf(lenStr, "%d", strlen(data)); const char* atStr = "AT+CIPSEND="; #ifdef RADIOLIB_STATIC_ONLY From e070cf9ef400c83464a0a90b9344b1dffd0708b6 Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 30 Apr 2020 21:13:37 -0700 Subject: [PATCH 117/334] No reason to wait 1s between probes (for a 4MHz spi bus). Change to 10ms so probing for parts doesn't slow our boot so much. --- src/modules/SX127x/SX127x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 727cf2b1..84cf1eb6 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -998,7 +998,7 @@ bool SX127x::findChip(uint8_t ver) { RADIOLIB_DEBUG_PRINT(F(", expected 0x00")); RADIOLIB_DEBUG_PRINTLN(ver, HEX); #endif - delay(1000); + delay(10); i++; } } From 2c31adc4015a46697171c5911f7c60d4e24c7942 Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 30 Apr 2020 18:29:51 -0700 Subject: [PATCH 118/334] Set the min/max ranges per the Semtech SX1278/SX1276 datasheet --- src/modules/RFM9x/RFM95.cpp | 2 +- src/modules/RFM9x/RFM96.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp index 49557190..fa5c684a 100644 --- a/src/modules/RFM9x/RFM95.cpp +++ b/src/modules/RFM9x/RFM95.cpp @@ -35,7 +35,7 @@ int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncW } int16_t RFM95::setFrequency(float freq) { - RADIOLIB_CHECK_RANGE(freq, 868.0, 915.0, ERR_INVALID_FREQUENCY); + RADIOLIB_CHECK_RANGE(freq, 862.0, 1020.0, ERR_INVALID_FREQUENCY); // set frequency return(SX127x::setFrequencyRaw(freq)); diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp index cf81ca40..1d5cdc74 100644 --- a/src/modules/RFM9x/RFM96.cpp +++ b/src/modules/RFM9x/RFM96.cpp @@ -35,7 +35,7 @@ int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncW } int16_t RFM96::setFrequency(float freq) { - RADIOLIB_CHECK_RANGE(freq, 433.0, 470.0, ERR_INVALID_FREQUENCY); + RADIOLIB_CHECK_RANGE(freq, 410.0, 525.0, ERR_INVALID_FREQUENCY); // set frequency return(SX127x::setFrequencyRaw(freq)); From 601f6324e4bccaca2bc6db2932c1ab62f6872152 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 1 May 2020 20:26:53 +0200 Subject: [PATCH 119/334] [SX128x] Fixed unitialized variable warning --- src/modules/SX128x/SX128x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 098d783f..f7d104ff 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -1009,7 +1009,7 @@ float SX128x::getSNR() { size_t SX128x::getPacketLength(bool update) { (void)update; - uint8_t rxBufStatus[2]; + uint8_t rxBufStatus[2] = {0, 0}; SPIreadCommand(SX128X_CMD_GET_RX_BUFFER_STATUS, rxBufStatus, 2); return((size_t)rxBufStatus[0]); } From 305d8809265080f2661e6ea4ee7dea84a505a39a Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 1 May 2020 20:52:59 +0200 Subject: [PATCH 120/334] [Xbee] Lowered findChip delay to 10 ms --- src/modules/XBee/XBee.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/XBee/XBee.cpp b/src/modules/XBee/XBee.cpp index aa365ea3..4bfcab40 100644 --- a/src/modules/XBee/XBee.cpp +++ b/src/modules/XBee/XBee.cpp @@ -35,7 +35,7 @@ int16_t XBee::begin(long speed) { RADIOLIB_DEBUG_PRINTLN(state); RADIOLIB_DEBUG_PRINTLN(F("Resetting ...")); reset(); - delay(1000); + delay(10); _mod->ATemptyBuffer(); i++; } From 9119020d0db20b5b6a19bebc7b73fe29ef590dac Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 1 May 2020 20:53:08 +0200 Subject: [PATCH 121/334] [Si443x] Lowered findChip delay to 10 ms --- src/modules/Si443x/Si443x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 13af7747..5a55a98f 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -551,7 +551,7 @@ bool Si443x::findChip() { RADIOLIB_DEBUG_PRINT(F(", expected 0x00")); RADIOLIB_DEBUG_PRINTLN(SI443X_DEVICE_VERSION, HEX); #endif - delay(1000); + delay(10); i++; } } From 1fa483f98b1e7840192bcab6f668c6017f08cef9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 1 May 2020 20:53:15 +0200 Subject: [PATCH 122/334] [SX1231] Lowered findChip delay to 10 ms --- src/modules/SX1231/SX1231.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX1231/SX1231.cpp b/src/modules/SX1231/SX1231.cpp index da54a919..1e1388d7 100644 --- a/src/modules/SX1231/SX1231.cpp +++ b/src/modules/SX1231/SX1231.cpp @@ -30,7 +30,7 @@ int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po RADIOLIB_DEBUG_PRINT(F(", expected 0x0021 / 0x0022 / 0x0023")); RADIOLIB_DEBUG_PRINTLN(); #endif - delay(1000); + delay(10); i++; } } From 078ec4d13e0e63df660f992f6c30c8073864084d Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 1 May 2020 20:53:23 +0200 Subject: [PATCH 123/334] [RF69] Lowered findChip delay to 10 ms --- src/modules/RF69/RF69.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index ba7bfcb7..1eb2a146 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -40,7 +40,7 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe RADIOLIB_DEBUG_PRINT(F(", expected 0x0024")); RADIOLIB_DEBUG_PRINTLN(); #endif - delay(1000); + delay(10); i++; } } From d609c8ba5680c3700ef17f3dd41074971b67211f Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 1 May 2020 20:53:50 +0200 Subject: [PATCH 124/334] [CC1101] Lowered findChip delay to 10 ms --- src/modules/CC1101/CC1101.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 039c155d..c913aacd 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -35,7 +35,7 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po RADIOLIB_DEBUG_PRINT(F(", expected 0x0014")); RADIOLIB_DEBUG_PRINTLN(); #endif - delay(1000); + delay(10); i++; } } From ed0a6623a605e6cbc25b5c102f91c297b78afcc0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 3 May 2020 11:04:45 +0200 Subject: [PATCH 125/334] [AFSK] Executed Order 66 --- .../AFSK_Imperial_March.ino | 97 +++++++++++++ examples/AFSK/AFSK_Imperial_March/melody.h | 128 ++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino create mode 100644 examples/AFSK/AFSK_Imperial_March/melody.h diff --git a/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino b/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino new file mode 100644 index 00000000..82052f05 --- /dev/null +++ b/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino @@ -0,0 +1,97 @@ +/* + RadioLib AFSK Imperial March Example + + This example shows how to EXECUTE ORDER 66 + + Other modules that can be used for AFSK: + - SX127x/RFM9x + - RF69 + - SX1231 + - CC1101 + - Si443x/RFM2x + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ +*/ + +// include the library +#include + +// include the melody +#include "melody.h" + +// SX1278 has the following connections: +// NSS pin: 10 +// DIO0 pin: 2 +// RESET pin: 9 +// DIO1 pin: 3 +SX1278 fsk = new Module(10, 2, 9, 3); + +// create AFSK client instance using the FSK module +// this requires connection to the module direct +// input pin, here connected to Arduino pin 5 +// SX127x/RFM9x: DIO2 +// RF69: DIO2 +// SX1231: DIO2 +// CC1101: GDO2 +// Si443x/RFM2x: GPIO +AFSKClient audio(&fsk, 5); + +void setup() { + Serial.begin(9600); + + // initialize SX1278 + Serial.print(F("[SX1278] Initializing ... ")); + // carrier frequency: 434.0 MHz + // bit rate: 48.0 kbps + // frequency deviation: 50.0 kHz + // Rx bandwidth: 125.0 kHz + // output power: 13 dBm + // current limit: 100 mA + int state = fsk.beginFSK(); + + // when using one of the non-LoRa modules for AFSK + // (RF69, CC1101,, Si4432 etc.), use the basic begin() method + // int state = fsk.begin(); + + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } +} + +void loop() { + Serial.print(F("[AFSK] Executing Order 66 ... ")); + + // calculate whole note duration + int wholenote = (60000 * 4) / 120; + + // iterate over the melody + for(int note = 0; note < sizeof(melody) / sizeof(melody[0]); note += 2) { + // calculate the duration of each note + int noteDuration = 0; + int divider = melody[note + 1]; + if(divider > 0) { + // regular note, just proceed + noteDuration = wholenote / divider; + } else if(divider < 0) { + // dotted notes are represented with negative durations!! + noteDuration = wholenote / abs(divider); + noteDuration *= 1.5; // increases the duration in half for dotted notes + } + + // we only play the note for 90% of the duration, leaving 10% as a pause + audio.tone(melody[note]); + delay(noteDuration*0.9); + audio.noTone(); + delay(noteDuration*0.1); + } + + Serial.println(F("done!")); + + // wait for a second + delay(1000); +} diff --git a/examples/AFSK/AFSK_Imperial_March/melody.h b/examples/AFSK/AFSK_Imperial_March/melody.h new file mode 100644 index 00000000..e4b15169 --- /dev/null +++ b/examples/AFSK/AFSK_Imperial_March/melody.h @@ -0,0 +1,128 @@ +/* + Note definitions, melody and melody-related functions + adapted from https://github.com/robsoncouto/arduino-songs + by Robson Couto, 2019 +*/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 +#define REST 0 + +// notes of the moledy followed by the duration. +// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on +// !!negative numbers are used to represent dotted notes, +// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!! +int melody[] = { + + // Darth Vader theme (Imperial March) - Star wars + // Score available at https://musescore.com/user/202909/scores/1141521 + // The tenor saxophone part was used + + NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8, + NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8, + NOTE_A4,4, NOTE_A4,4, NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, + + NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,//4 + NOTE_E5,4, NOTE_E5,4, NOTE_E5,4, NOTE_F5,-8, NOTE_C5,16, + NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2, + + NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 + NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16, + + NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9 + NOTE_C5,4, NOTE_A4,-8, NOTE_C5,16, NOTE_E5,2, + + NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 + NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16, + + NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9 + NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2, + +}; From 79d8ff2ca03a43689f5be8662a8027e8ccc4bf3d Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 3 May 2020 11:04:51 +0200 Subject: [PATCH 126/334] [AFSK] Added check for zero tone frequency --- src/protocols/AFSK/AFSK.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/protocols/AFSK/AFSK.cpp b/src/protocols/AFSK/AFSK.cpp index a8453925..e2a90641 100644 --- a/src/protocols/AFSK/AFSK.cpp +++ b/src/protocols/AFSK/AFSK.cpp @@ -6,6 +6,10 @@ AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin) { } int16_t AFSKClient::tone(uint16_t freq, bool autoStart) { + if(freq == 0) { + return(ERR_INVALID_FREQUENCY); + } + if(autoStart) { int16_t state = _phy->transmitDirect(); RADIOLIB_ASSERT(state); From 3719d6dd9251cf3661066f7a5fb6c9f268b52f3e Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:30:57 +0200 Subject: [PATCH 127/334] [AFSK] Removed redundant argument --- examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino index aa9d82f4..d55e14aa 100644 --- a/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino +++ b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino @@ -50,7 +50,7 @@ void setup() { // Rx bandwidth: 125.0 kHz // output power: 13 dBm // current limit: 100 mA - int state = fsk.beginFSK(434.0); + int state = fsk.beginFSK(); // when using one of the non-LoRa modules for AX.25 // (RF69, CC1101,, Si4432 etc.), use the basic begin() method From 6721fad68a025a134e8bb4e652a2acd01289be86 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:31:47 +0200 Subject: [PATCH 128/334] Implemented custom digital pin to interrupt macro --- src/BuildOpt.h | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 5ea12a5e..4d47b7b1 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -23,25 +23,27 @@ * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). */ #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) - // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. - #define RADIOLIB_PLATFORM "Arduino AVR" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_NC (0xFF) + // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. + #define RADIOLIB_PLATFORM "Arduino AVR" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) #elif defined(ESP8266) - // ESP8266 boards - #define RADIOLIB_PLATFORM "ESP8266" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_NC (0xFF) + // ESP8266 boards + #define RADIOLIB_PLATFORM "ESP8266" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) - // RadioLib has ESPS8266 driver, this must be disabled to use ESP8266 as platform - #define _RADIOLIB_ESP8266_H + // RadioLib has ESP8266 driver, this must be disabled to use ESP8266 as platform + #define _RADIOLIB_ESP8266_H #elif defined(ESP32) // ESP32 boards @@ -50,6 +52,7 @@ #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -62,6 +65,7 @@ #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(digitalPinToPinName(p)) #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -73,6 +77,7 @@ #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -84,6 +89,7 @@ #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -96,6 +102,7 @@ #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFFFFFFFF) #elif defined(ARDUINO_ARC32_TOOLS) @@ -105,6 +112,7 @@ #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) #elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) @@ -114,6 +122,7 @@ #define RADIOLIB_PIN_MODE PinMode #define RADIOLIB_PIN_STATUS PinStatus #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) #elif defined(AM_PART_APOLLO3) @@ -123,6 +132,7 @@ #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -135,6 +145,7 @@ #define RADIOLIB_PIN_MODE PinMode #define RADIOLIB_PIN_STATUS PinStatus #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -149,6 +160,7 @@ #define RADIOLIB_PIN_MODE WiringPinMode #define RADIOLIB_PIN_STATUS uint8_t #define RADIOLIB_INTERRUPT_STATUS ExtIntTriggerMode + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -162,6 +174,7 @@ #define RADIOLIB_PIN_MODE uint8_t #define RADIOLIB_PIN_STATUS uint8_t #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) #endif @@ -213,7 +226,7 @@ * Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode. */ -//#define RADIOLIB_STATIC_ONLY +#define RADIOLIB_STATIC_ONLY // set the size of static arrays to use #define RADIOLIB_STATIC_ARRAY_SIZE 256 From f9c7e9e7f50073720c60e7154f66a6b5c5dc4db0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:32:17 +0200 Subject: [PATCH 129/334] [CC1101] Added digital pin to interrupt macro --- src/modules/CC1101/CC1101.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index c913aacd..d0259e4a 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -180,11 +180,11 @@ int16_t CC1101::packetMode() { } void CC1101::setGdo0Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir) { - attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, dir); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, dir); } void CC1101::clearGdo0Action() { - detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq())); } void CC1101::setGdo2Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir) { @@ -192,14 +192,14 @@ void CC1101::setGdo2Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir) { return; } Module::pinMode(_mod->getGpio(), INPUT); - attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, dir); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio()), func, dir); } void CC1101::clearGdo2Action() { if(_mod->getGpio() != RADIOLIB_NC) { return; } - detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio())); } int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { From 19028b64e0e51901a93023d62124ce03bc4d7a3d Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:32:26 +0200 Subject: [PATCH 130/334] [RF69] Added digital pin to interrupt macro --- src/modules/RF69/RF69.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 1eb2a146..08d6a12e 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -250,11 +250,11 @@ int16_t RF69::startReceive() { } void RF69::setDio0Action(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, RISING); } void RF69::clearDio0Action() { - detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq())); } void RF69::setDio1Action(void (*func)(void)) { @@ -262,14 +262,14 @@ void RF69::setDio1Action(void (*func)(void)) { return; } Module::pinMode(_mod->getGpio(), INPUT); - attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, RISING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio()), func, RISING); } void RF69::clearDio1Action() { if(_mod->getGpio() != RADIOLIB_NC) { return; } - detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio())); } int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) { From d0051124073aa1ebd3617f14afab09a3248ab0ca Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:32:32 +0200 Subject: [PATCH 131/334] [SX126x] Added digital pin to interrupt macro --- src/modules/SX126x/SX126x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 685163cf..e419761e 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -382,11 +382,11 @@ int16_t SX126x::standby(uint8_t mode) { } void SX126x::setDio1Action(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, RISING); } void SX126x::clearDio1Action() { - detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq())); } int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { From 9b0cf7abb298536a8be773d98c3c1bed0d4f0380 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:32:41 +0200 Subject: [PATCH 132/334] [SX127x] Added digital pin to interrupt macro --- src/modules/SX127x/SX127x.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 84cf1eb6..d0aaca44 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -373,25 +373,25 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { } void SX127x::setDio0Action(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, RISING); } void SX127x::clearDio0Action() { - detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq())); } void SX127x::setDio1Action(void (*func)(void)) { if(_mod->getGpio() != RADIOLIB_NC) { return; } - attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, RISING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio()), func, RISING); } void SX127x::clearDio1Action() { if(_mod->getGpio() != RADIOLIB_NC) { return; } - detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio())); } int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { From e2689940a621f4d88fae18a265bba1fb48a6a0e4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:32:47 +0200 Subject: [PATCH 133/334] [SX128x] Added digital pin to interrupt macro --- src/modules/SX128x/SX128x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index f7d104ff..993ff9ec 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -421,11 +421,11 @@ int16_t SX128x::standby(uint8_t mode) { } void SX128x::setDio1Action(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, RISING); } void SX128x::clearDio1Action() { - detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq())); } int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { From 8b12def14d370913ee9f3094b92c616ae5d8e366 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:32:56 +0200 Subject: [PATCH 134/334] [Si443x] Added digital pin to interrupt macro --- src/modules/Si443x/Si443x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 5a55a98f..e1b253c5 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -184,11 +184,11 @@ int16_t Si443x::packetMode() { } void Si443x::setIrqAction(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, FALLING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, FALLING); } void Si443x::clearIrqAction() { - detachInterrupt(digitalPinToInterrupt(_mod->getIrq())); + detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq())); } int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { From 3aae02e4ea7987d17c1e113d068bd6b697e098b0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 20:33:02 +0200 Subject: [PATCH 135/334] [nRF24] Added digital pin to interrupt macro --- src/modules/nRF24/nRF24.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index ab6cc6b6..76ce1afd 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -104,7 +104,7 @@ int16_t nRF24::receive(uint8_t* data, size_t len) { uint32_t start = micros(); while(digitalRead(_mod->getIrq())) { yield(); - + // check timeout: 15 retries * 4ms (max Tx time as per datasheet) if(micros() - start >= 60000) { standby(); @@ -139,7 +139,7 @@ int16_t nRF24::receiveDirect() { } void nRF24::setIrqAction(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, FALLING); + attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, FALLING); } int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) { From a7a2dcabd282e1f6fac2d807b982d827ea5c3521 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 11 May 2020 21:07:57 +0200 Subject: [PATCH 136/334] Added custom platform option --- src/BuildOpt.h | 286 +++++++++++++++++++++++++------------------------ 1 file changed, 146 insertions(+), 140 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 4d47b7b1..2864dedc 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -14,6 +14,7 @@ * RADIOLIB_PIN_TYPE - which type should be used for pin numbers in functions like digitalRead(). * RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode(). * RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite(). + * RADIOLIB_DIGITAL_PIN_TO_INTERRUPT - function to be used to convert digital pin number to interrupt pin number. * RADIOLIB_INTERRUPT_STATUS - which type should be used for pin changes in functions like attachInterrupt(). * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platform does not support SoftwareSerial. @@ -21,162 +22,167 @@ * RADIOLIB_TONE_UNSUPPORTED - some platforms do not have tone()/noTone(), which is required for AFSK. * * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). + * + * Users may also specify their own configuration by defining all of the platform-specific parameters + * and macro RADIOLIB_CUSTOM_PLATFORM prior to including the main library file (RadioLib.h). */ -#if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) - // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. - #define RADIOLIB_PLATFORM "Arduino AVR" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) +#if !defined(RADIOLIB_CUSTOM_PLATFORM) + #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) + // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. + #define RADIOLIB_PLATFORM "Arduino AVR" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) -#elif defined(ESP8266) - // ESP8266 boards - #define RADIOLIB_PLATFORM "ESP8266" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) + #elif defined(ESP8266) + // ESP8266 boards + #define RADIOLIB_PLATFORM "ESP8266" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) - // RadioLib has ESP8266 driver, this must be disabled to use ESP8266 as platform - #define _RADIOLIB_ESP8266_H + // RadioLib has ESP8266 driver, this must be disabled to use ESP8266 as platform + #define _RADIOLIB_ESP8266_H -#elif defined(ESP32) - // ESP32 boards - #define RADIOLIB_PLATFORM "ESP32" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - #define RADIOLIB_TONE_UNSUPPORTED + #elif defined(ESP32) + // ESP32 boards + #define RADIOLIB_PLATFORM "ESP32" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED -#elif defined(ARDUINO_ARCH_STM32) - // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32) - #define RADIOLIB_PLATFORM "Arduino STM32 (official)" - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(digitalPinToPinName(p)) - #define RADIOLIB_NC (0xFFFFFFFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #elif defined(ARDUINO_ARCH_STM32) + // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32) + #define RADIOLIB_PLATFORM "Arduino STM32 (official)" + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(digitalPinToPinName(p)) + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 -#elif defined(SAMD_SERIES) - // Arduino SAMD boards - Zero, MKR, etc. - #define RADIOLIB_PLATFORM "Arduino SAMD" - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFFFFFFFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #elif defined(SAMD_SERIES) + // Arduino SAMD boards - Zero, MKR, etc. + #define RADIOLIB_PLATFORM "Arduino SAMD" + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 -#elif defined(__SAM3X8E__) - // Arduino Due - #define RADIOLIB_PLATFORM "Arduino Due" - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFFFFFFFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - #define RADIOLIB_TONE_UNSUPPORTED + #elif defined(__SAM3X8E__) + // Arduino Due + #define RADIOLIB_PLATFORM "Arduino Due" + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED -#elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) - // Adafruit nRF52 boards - #define RADIOLIB_PLATFORM "Adafruit nRF52" - #define RADIOLIB_PIN_TYPE uint32_t - #define RADIOLIB_PIN_MODE uint32_t - #define RADIOLIB_PIN_STATUS uint32_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFFFFFFFF) + #elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) + // Adafruit nRF52 boards + #define RADIOLIB_PLATFORM "Adafruit nRF52" + #define RADIOLIB_PIN_TYPE uint32_t + #define RADIOLIB_PIN_MODE uint32_t + #define RADIOLIB_PIN_STATUS uint32_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFFFFFFFF) -#elif defined(ARDUINO_ARC32_TOOLS) - // Intel Curie - #define RADIOLIB_PLATFORM "Intel Curie" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) + #elif defined(ARDUINO_ARC32_TOOLS) + // Intel Curie + #define RADIOLIB_PLATFORM "Intel Curie" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) -#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) - // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every - #define RADIOLIB_PLATFORM "Arduino megaAVR" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE PinMode - #define RADIOLIB_PIN_STATUS PinStatus - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) + #elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) + // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every + #define RADIOLIB_PLATFORM "Arduino megaAVR" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE PinMode + #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) -#elif defined(AM_PART_APOLLO3) - // Sparkfun Artemis boards - #define RADIOLIB_PLATFORM "Sparkfun Artemis" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - #define RADIOLIB_TONE_UNSUPPORTED + #elif defined(AM_PART_APOLLO3) + // Sparkfun Artemis boards + #define RADIOLIB_PLATFORM "Sparkfun Artemis" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED -#elif defined(ARDUINO_ARDUINO_NANO33BLE) - // Arduino Nano 33 BLE - #define RADIOLIB_PLATFORM "Arduino Nano 33 BLE" - #define RADIOLIB_PIN_TYPE pin_size_t - #define RADIOLIB_PIN_MODE PinMode - #define RADIOLIB_PIN_STATUS PinStatus - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #elif defined(ARDUINO_ARDUINO_NANO33BLE) + // Arduino Nano 33 BLE + #define RADIOLIB_PLATFORM "Arduino Nano 33 BLE" + #define RADIOLIB_PIN_TYPE pin_size_t + #define RADIOLIB_PIN_MODE PinMode + #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - // Nano 33 BLE uses mbed libraries, which already contain ESP8266 driver - #define _RADIOLIB_ESP8266_H + // Nano 33 BLE uses mbed libraries, which already contain ESP8266 driver + #define _RADIOLIB_ESP8266_H -#elif defined(__STM32F4__) || defined(__STM32F1__) - // Arduino STM32 core by Roger Clark (https://github.com/rogerclarkmelbourne/Arduino_STM32) - #define RADIOLIB_PLATFORM "STM32duino (unofficial)" - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE WiringPinMode - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS ExtIntTriggerMode - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) - #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 - #define RADIOLIB_TONE_UNSUPPORTED + #elif defined(__STM32F4__) || defined(__STM32F1__) + // Arduino STM32 core by Roger Clark (https://github.com/rogerclarkmelbourne/Arduino_STM32) + #define RADIOLIB_PLATFORM "STM32duino (unofficial)" + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE WiringPinMode + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS ExtIntTriggerMode + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED -#else - // other platforms not covered by the above list - this may or may not work - #define RADIOLIB_PLATFORM "Unknown" - #define RADIOLIB_UNKNOWN_PLATFORM - #define RADIOLIB_PIN_TYPE uint8_t - #define RADIOLIB_PIN_MODE uint8_t - #define RADIOLIB_PIN_STATUS uint8_t - #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS - #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) - #define RADIOLIB_NC (0xFF) + #else + // other platforms not covered by the above list - this may or may not work + #define RADIOLIB_PLATFORM "Unknown" + #define RADIOLIB_UNKNOWN_PLATFORM + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) + #endif #endif /* From 7503604765d5318b1194664f4c0e0dc4194eec2e Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 12 May 2020 08:39:28 +0200 Subject: [PATCH 137/334] [SX127x] Fixed sprintf buffer size --- src/modules/SX127x/SX127x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index d0aaca44..ca76b072 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -992,7 +992,7 @@ bool SX127x::findChip(uint8_t ver) { RADIOLIB_DEBUG_PRINT(i + 1); RADIOLIB_DEBUG_PRINT(F(" of 10 tries) SX127X_REG_VERSION == ")); - char buffHex[5]; + char buffHex[12]; sprintf(buffHex, "0x%02X", version); RADIOLIB_DEBUG_PRINT(buffHex); RADIOLIB_DEBUG_PRINT(F(", expected 0x00")); From 0c4f449181ecd625ddbed976d9946df8d0f15210 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 12 May 2020 08:40:31 +0200 Subject: [PATCH 138/334] Added default SPI instance to platform config --- src/BuildOpt.h | 19 ++++++++++++++++++- src/Module.h | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 2864dedc..8d013b5d 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -26,7 +26,11 @@ * Users may also specify their own configuration by defining all of the platform-specific parameters * and macro RADIOLIB_CUSTOM_PLATFORM prior to including the main library file (RadioLib.h). */ -#if !defined(RADIOLIB_CUSTOM_PLATFORM) +#if defined(RADIOLIB_CUSTOM_PLATFORM) + #if !defined(RADIOLIB_PLATFORM) + #define RADIOLIB_PLATFORM "Custom" + #endif +#else #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. #define RADIOLIB_PLATFORM "Arduino AVR" @@ -36,6 +40,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #elif defined(ESP8266) // ESP8266 boards @@ -46,6 +51,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI // RadioLib has ESP8266 driver, this must be disabled to use ESP8266 as platform #define _RADIOLIB_ESP8266_H @@ -59,6 +65,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 #define RADIOLIB_TONE_UNSUPPORTED @@ -72,6 +79,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(digitalPinToPinName(p)) #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_DEFAULT_SPI SPI #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -84,6 +92,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_DEFAULT_SPI SPI #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -96,6 +105,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_DEFAULT_SPI SPI #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 #define RADIOLIB_TONE_UNSUPPORTED @@ -109,6 +119,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFFFFFFFF) + #define RADIOLIB_DEFAULT_SPI SPI #elif defined(ARDUINO_ARC32_TOOLS) // Intel Curie @@ -119,6 +130,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every @@ -129,6 +141,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #elif defined(AM_PART_APOLLO3) // Sparkfun Artemis boards @@ -139,6 +152,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 #define RADIOLIB_TONE_UNSUPPORTED @@ -152,6 +166,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 @@ -167,6 +182,7 @@ #define RADIOLIB_INTERRUPT_STATUS ExtIntTriggerMode #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 #define RADIOLIB_TONE_UNSUPPORTED @@ -181,6 +197,7 @@ #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI #endif #endif diff --git a/src/Module.h b/src/Module.h index f6855a05..12247f3c 100644 --- a/src/Module.h +++ b/src/Module.h @@ -111,9 +111,9 @@ class Module { \param serial HardwareSerial to be used on ESP32 and SAMD. Defaults to 1 */ #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi = RADIOLIB_DEFAULT_SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT); #else - Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi = SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = nullptr); + Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi = RADIOLIB_DEFAULT_SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = nullptr); #endif From 9798de62724ccdf5cdb5130f56b2511729e5075c Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 12 May 2020 08:42:10 +0200 Subject: [PATCH 139/334] Added support for Adafruit SAMD boards --- .travis.yml | 6 ++++++ README.md | 1 + src/BuildOpt.h | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dbb1da43..ff2646a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ env: - BOARD="SparkFun:apollo3:amap3redboard" - BOARD="arduino:mbed:nano33ble" - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" + - BOARD="adafruit:samd:adafruit_feather_m0:usbstack=arduino,debug=off" addons: apt: @@ -105,6 +106,11 @@ before_install: arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; arduino --install-boards stm32duino:STM32F1; + elif [[ "$BOARD" =~ "adafruit:samd:" ]]; then + export BUILD_EXAMPLES=true; + arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; + arduino --install-boards adafruit:samd; + fi # check if this release commit (or forced build) and if so, build for every board diff --git a/README.md b/README.md index 884d0c1f..ad437969 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x * [__SAMD__](https://github.com/arduino/ArduinoCore-samd) - Arduino Zero, MKR boards, M0 Pro etc. * __Adafruit__ + * [__SAMD__](https://github.com/adafruit/ArduinoCore-samd) - Adafruit Feather M0 and M4 boards (Feather, Metro, Gemma, Trinket etc.) * [__nRF52__](https://github.com/adafruit/Adafruit_nRF52_Arduino) - Adafruit Feather nRF528x, Bluefruit and CLUE * __Espressif__ diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 8d013b5d..c593448d 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -84,8 +84,8 @@ #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 #elif defined(SAMD_SERIES) - // Arduino SAMD boards - Zero, MKR, etc. - #define RADIOLIB_PLATFORM "Arduino SAMD" + // Arduino SAMD (Zero, MKR, etc.) and Adafruit SAMD boards (M0 and M4) + #define RADIOLIB_PLATFORM "Arduino/Adafruit SAMD" #define RADIOLIB_PIN_TYPE uint32_t #define RADIOLIB_PIN_MODE uint32_t #define RADIOLIB_PIN_STATUS uint32_t From 4198551e5510dea09fc41daa0a89ac2d3d0abe00 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 12 May 2020 08:57:38 +0200 Subject: [PATCH 140/334] Disabled default build for Adafruit SAMD --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ff2646a6..889773ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -107,7 +107,7 @@ before_install: arduino --install-boards stm32duino:STM32F1; elif [[ "$BOARD" =~ "adafruit:samd:" ]]; then - export BUILD_EXAMPLES=true; + export BUILD_EXAMPLES=false; arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; arduino --install-boards adafruit:samd; From 50cc06021b550d2161ac72ca2654474afa18be57 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 12 May 2020 16:00:13 +0200 Subject: [PATCH 141/334] Only stopping hardware interface on automated initialization (#143) --- src/Module.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Module.cpp b/src/Module.cpp index 67ac9ac8..eed3e298 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -103,7 +103,11 @@ void Module::init(uint8_t interface) { } void Module::term() { - // stop hardware interfaces + // stop hardware interfaces (if they were initialized by the library) + if(!_initInterface) { + return; + } + if(_spi != nullptr) { _spi->end(); } From 86da5780c3278ede864cb18d49996b3af73cf919 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 12 May 2020 16:04:29 +0200 Subject: [PATCH 142/334] Added missing RADIOLIB_DEFAULT_SPI parameter --- src/Module.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index eed3e298..ff03b1f3 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -6,7 +6,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs _tx = RADIOLIB_NC; _irq = irq; _rst = rst; - _spi = &SPI; + _spi = &RADIOLIB_DEFAULT_SPI; _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); _initInterface = true; } @@ -17,7 +17,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs _tx = RADIOLIB_NC; _irq = irq; _rst = rst; - _spi = &SPI; + _spi = &RADIOLIB_DEFAULT_SPI; _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); _initInterface = true; } From 2ebd6d355ca3652b251920669cc6dcdeaf203d09 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 12 May 2020 16:16:56 +0200 Subject: [PATCH 143/334] Bump version to 3.6.0 --- library.properties | 2 +- src/BuildOpt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 9113c270..f927739f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=3.5.0 +version=3.6.0 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/BuildOpt.h b/src/BuildOpt.h index c593448d..b8d95197 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -267,7 +267,7 @@ // version definitions #define RADIOLIB_VERSION_MAJOR (0x03) -#define RADIOLIB_VERSION_MINOR (0x05) +#define RADIOLIB_VERSION_MINOR (0x06) #define RADIOLIB_VERSION_PATCH (0x00) #define RADIOLIB_VERSION_EXTRA (0x00) From f588d3b3a2c39dd5bbc137fdebf83a6887e04b62 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 14 May 2020 19:53:46 +0200 Subject: [PATCH 144/334] Fixed static only build set by default --- src/BuildOpt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index b8d95197..134b0b1f 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -249,7 +249,7 @@ * Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode. */ -#define RADIOLIB_STATIC_ONLY +//#define RADIOLIB_STATIC_ONLY // set the size of static arrays to use #define RADIOLIB_STATIC_ARRAY_SIZE 256 From a969517e0445a1c9d52a6bff73fdffa42a2c71ef Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 15 May 2020 09:56:40 +0200 Subject: [PATCH 145/334] Bump version to 3.6.1 (hotfix) --- library.properties | 2 +- src/BuildOpt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index f927739f..1f6c35f8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=3.6.0 +version=3.6.1 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 134b0b1f..eef56d8c 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -268,7 +268,7 @@ // version definitions #define RADIOLIB_VERSION_MAJOR (0x03) #define RADIOLIB_VERSION_MINOR (0x06) -#define RADIOLIB_VERSION_PATCH (0x00) +#define RADIOLIB_VERSION_PATCH (0x01) #define RADIOLIB_VERSION_EXTRA (0x00) #define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA)) From da177c9b2a36580aaa2a4eecc14bd7354529c308 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 17 May 2020 20:26:57 +0200 Subject: [PATCH 146/334] Added interface argument to termination method --- src/Module.cpp | 6 +++--- src/Module.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index ff03b1f3..b4db0504 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -102,17 +102,17 @@ void Module::init(uint8_t interface) { } } -void Module::term() { +void Module::term(uint8_t interface) { // stop hardware interfaces (if they were initialized by the library) if(!_initInterface) { return; } - if(_spi != nullptr) { + if((interface == RADIOLIB_USE_SPI) && (_spi != nullptr)) { _spi->end(); } - if(ModuleSerial != nullptr) { + if(((interface == RADIOLIB_USE_UART) && ModuleSerial != nullptr)) { ModuleSerial->end(); } } diff --git a/src/Module.h b/src/Module.h index 12247f3c..a77d1a7e 100644 --- a/src/Module.h +++ b/src/Module.h @@ -159,8 +159,10 @@ class Module { /*! \brief Terminate low-level module control. + + \param interface Interface to be terminated. See \ref shield_config for details. */ - void term(); + void term(uint8_t interface); // AT methods From 3721d0a51b45a25c3e82581c7440050e91d306ee Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 17 May 2020 20:27:34 +0200 Subject: [PATCH 147/334] [CC1101] Added interface argument to Module::term --- src/modules/CC1101/CC1101.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index d0259e4a..2854fca8 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -42,7 +42,7 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po if(!flagFound) { RADIOLIB_DEBUG_PRINTLN(F("No CC1101 found!")); - _mod->term(); + _mod->term(RADIOLIB_USE_SPI); return(ERR_CHIP_NOT_FOUND); } else { RADIOLIB_DEBUG_PRINTLN(F("Found CC1101! (match by CC1101_REG_VERSION == 0x14)")); From 657d7495cbbdcf2da828039b0db9163b18d3a430 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 17 May 2020 20:27:42 +0200 Subject: [PATCH 148/334] [RF69] Added interface argument to Module::term --- src/modules/RF69/RF69.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 08d6a12e..856101f2 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -47,7 +47,7 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe if(!flagFound) { RADIOLIB_DEBUG_PRINTLN(F("No RF69 found!")); - _mod->term(); + _mod->term(RADIOLIB_USE_SPI); return(ERR_CHIP_NOT_FOUND); } else { RADIOLIB_DEBUG_PRINTLN(F("Found RF69! (match by RF69_REG_VERSION == 0x24)")); From e6caf3fc37bd5577390bd38735d6cf304b35d30f Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 17 May 2020 20:27:51 +0200 Subject: [PATCH 149/334] [nRF24] Added interface argument to Module::term --- src/modules/nRF24/nRF24.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 76ce1afd..73d25ee6 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -21,7 +21,7 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW int16_t val = _mod->SPIgetRegValue(NRF24_REG_SETUP_AW); if(!((val >= 0) && (val <= 3))) { RADIOLIB_DEBUG_PRINTLN(F("No nRF24 found!")); - _mod->term(); + _mod->term(RADIOLIB_USE_SPI); return(ERR_CHIP_NOT_FOUND); } From b0a6b1db08a52aa02340edc4e7701041eb09bd65 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 17 May 2020 20:27:58 +0200 Subject: [PATCH 150/334] [Si443x] Added interface argument to Module::term --- src/modules/Si443x/Si443x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index e1b253c5..153e5c3e 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -16,7 +16,7 @@ int16_t Si443x::begin(float br, float freqDev, float rxBw) { // try to find the Si443x chip if(!Si443x::findChip()) { RADIOLIB_DEBUG_PRINTLN(F("No Si443x found!")); - _mod->term(); + _mod->term(RADIOLIB_USE_SPI); return(ERR_CHIP_NOT_FOUND); } else { RADIOLIB_DEBUG_PRINTLN(F("Found Si443x!")); From 6e7554191f4e4c8ec07d363aa543431a9d4e2e10 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 17 May 2020 20:28:05 +0200 Subject: [PATCH 151/334] [SX1231] Added interface argument to Module::term --- src/modules/SX1231/SX1231.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX1231/SX1231.cpp b/src/modules/SX1231/SX1231.cpp index 1e1388d7..f42c584e 100644 --- a/src/modules/SX1231/SX1231.cpp +++ b/src/modules/SX1231/SX1231.cpp @@ -37,7 +37,7 @@ int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po if(!flagFound) { RADIOLIB_DEBUG_PRINTLN(F("No SX1231 found!")); - _mod->term(); + _mod->term(RADIOLIB_USE_SPI); return(ERR_CHIP_NOT_FOUND); } else { RADIOLIB_DEBUG_PRINTLN(F("Found SX1231!")); From bff077af3cb41bf0884dcde997effc0ff98fd774 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 17 May 2020 20:28:22 +0200 Subject: [PATCH 152/334] [SX127x] Added interface argument to Module::term (#146) --- src/modules/SX127x/SX127x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index ca76b072..8ba220d1 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -14,7 +14,7 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!")); - _mod->term(); + _mod->term(RADIOLIB_USE_SPI); return(ERR_CHIP_NOT_FOUND); } else { RADIOLIB_DEBUG_PRINTLN(F("Found SX127x!")); @@ -57,7 +57,7 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!")); - _mod->term(); + _mod->term(RADIOLIB_USE_SPI); return(ERR_CHIP_NOT_FOUND); } else { RADIOLIB_DEBUG_PRINTLN(F("Found SX127x!")); From 3682c6c9215891e3afb7672f1235fde1c3bd75fd Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 18 May 2020 07:17:08 +0200 Subject: [PATCH 153/334] Bump version to 3.6.2 --- library.properties | 2 +- src/BuildOpt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 1f6c35f8..733be1bd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=3.6.1 +version=3.6.2 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/BuildOpt.h b/src/BuildOpt.h index eef56d8c..45248a78 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -268,7 +268,7 @@ // version definitions #define RADIOLIB_VERSION_MAJOR (0x03) #define RADIOLIB_VERSION_MINOR (0x06) -#define RADIOLIB_VERSION_PATCH (0x01) +#define RADIOLIB_VERSION_PATCH (0x02) #define RADIOLIB_VERSION_EXTRA (0x00) #define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA)) From 56dd0ab41d838f2194b2458b3b102eec4a957c2d Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 19 May 2020 21:11:12 +0200 Subject: [PATCH 154/334] Added guards to allow user redefinition of RADIOLIB_STATIC_ARRAY_SIZE --- src/BuildOpt.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 45248a78..a5de6898 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -252,7 +252,9 @@ //#define RADIOLIB_STATIC_ONLY // set the size of static arrays to use +#if !defined(RADIOLIB_STATIC_ARRAY_SIZE) #define RADIOLIB_STATIC_ARRAY_SIZE 256 +#endif /*! \brief A simple assert macro, will return on error. From 3a15335b590fdd55817472dbd87906284aa6b317 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 20 May 2020 11:17:40 +0200 Subject: [PATCH 155/334] [RFM9x] Added 0x12 as valid device ID --- src/modules/RFM9x/RFM95.cpp | 11 +++++++++-- src/modules/RFM9x/RFM95.h | 3 ++- src/modules/RFM9x/RFM96.cpp | 11 +++++++++-- src/modules/RFM9x/RFM96.h | 3 ++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp index fa5c684a..53f1eb7c 100644 --- a/src/modules/RFM9x/RFM95.cpp +++ b/src/modules/RFM9x/RFM95.cpp @@ -6,8 +6,15 @@ RFM95::RFM95(Module* mod) : SX1278(mod) { int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RFM95_CHIP_VERSION, syncWord, currentLimit, preambleLength); - RADIOLIB_ASSERT(state); + int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, currentLimit, preambleLength); + if(state == ERR_CHIP_NOT_FOUND) { + // SX127X_REG_VERSION might be set 0x12 + state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, currentLimit, preambleLength); + RADIOLIB_ASSERT(state); + } else if(state != ERR_NONE) { + // some other error + return(state); + } // configure settings not accessible by API state = config(); diff --git a/src/modules/RFM9x/RFM95.h b/src/modules/RFM9x/RFM95.h index 78758971..fcbcf67d 100644 --- a/src/modules/RFM9x/RFM95.h +++ b/src/modules/RFM9x/RFM95.h @@ -7,7 +7,8 @@ #include "../SX127x/SX1278.h" // SX127X_REG_VERSION -#define RFM95_CHIP_VERSION 0x11 +#define RFM9X_CHIP_VERSION_OFFICIAL 0x11 +#define RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12 /*! \class RFM95 diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp index 1d5cdc74..159c4995 100644 --- a/src/modules/RFM9x/RFM96.cpp +++ b/src/modules/RFM9x/RFM96.cpp @@ -6,8 +6,15 @@ RFM96::RFM96(Module* mod) : SX1278(mod) { int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RFM9X_CHIP_VERSION, syncWord, currentLimit, preambleLength); - RADIOLIB_ASSERT(state); + int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, currentLimit, preambleLength); + if(state == ERR_CHIP_NOT_FOUND) { + // SX127X_REG_VERSION might be set 0x12 + state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, currentLimit, preambleLength); + RADIOLIB_ASSERT(state); + } else if(state != ERR_NONE) { + // some other error + return(state); + } // configure settings not accessible by API state = config(); diff --git a/src/modules/RFM9x/RFM96.h b/src/modules/RFM9x/RFM96.h index 1288c797..74b6d382 100644 --- a/src/modules/RFM9x/RFM96.h +++ b/src/modules/RFM9x/RFM96.h @@ -7,7 +7,8 @@ #include "../SX127x/SX1278.h" // SX127X_REG_VERSION -#define RFM9X_CHIP_VERSION 0x12 // according to datasheet, this should be 0x11, but all modules seem to have 0x12 +#define RFM9X_CHIP_VERSION_OFFICIAL 0x11 +#define RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12 /*! \class RFM96 From f068a150291f6716b0280dab5b0f1ff5a6458491 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 28 May 2020 21:07:23 +0200 Subject: [PATCH 156/334] [SX127x] Added getIRQFlags and getModemStatus methods (#145) --- keywords.txt | 2 ++ src/modules/SX127x/SX127x.cpp | 25 +++++++++++++++++++++++++ src/modules/SX127x/SX127x.h | 16 ++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/keywords.txt b/keywords.txt index 53b945b0..84b70c88 100644 --- a/keywords.txt +++ b/keywords.txt @@ -124,6 +124,8 @@ disableSyncWordFiltering KEYWORD2 setPromiscuous KEYWORD2 setRSSIConfig KEYWORD2 setEncoding KEYWORD2 +getIRQFlags KEYWORD2 +getModemStatus KEYWORD2 # RF69-specific setAESKey KEYWORD2 diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 8ba220d1..2a3a5121 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -909,6 +909,31 @@ int16_t SX127x::setEncoding(uint8_t encoding) { } } +uint16_t SX127x::getIRQFlags() { + // check active modem + if(getActiveModem() == SX127X_LORA) { + // LoRa, just 8-bit value + return((uint16_t)_mod->SPIreadRegister(SX127X_REG_IRQ_FLAGS)); + + } else { + // FSK, the IRQ flags are 16 bits in total + uint16_t flags = ((uint16_t)_mod->SPIreadRegister(SX127X_REG_IRQ_FLAGS_2)) << 8; + flags |= (uint16_t)_mod->SPIreadRegister(SX127X_REG_IRQ_FLAGS_1); + return(flags); + } + +} + +uint8_t SX127x::getModemStatus() { + // check active modem + if(getActiveModem() != SX127X_LORA) { + return(0x00); + } + + // read the register + return(_mod->SPIreadRegister(SX127X_REG_MODEM_STAT)); +} + int16_t SX127x::config() { // turn off frequency hopping int16_t state = _mod->SPIsetRegValue(SX127X_REG_HOP_PERIOD, SX127X_HOP_PERIOD_OFF); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 1edf5917..7404427c 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -897,6 +897,22 @@ class SX127x: public PhysicalLayer { */ int16_t setEncoding(uint8_t encoding); + /*! + \brief Reads currently active IRQ flags, can be used to check which event caused an interrupt. + In LoRa mode, this is the content of SX127X_REG_IRQ_FLAGS register. + In FSK mode, this is the contents of SX127X_REG_IRQ_FLAGS_2 (MSB) and SX127X_REG_IRQ_FLAGS_1 (LSB) registers. + + \returns IRQ flags. + */ + uint16_t getIRQFlags(); + + /*! + \brief Reads modem status. Only available in LoRa mode. + + \returns Modem status. + */ + uint8_t getModemStatus(); + #ifdef RADIOLIB_DEBUG void regDump(); #endif From f534185cfbc66e3e2be73cc3bfa9f6ffea6dd261 Mon Sep 17 00:00:00 2001 From: gozu42 Date: Mon, 1 Jun 2020 14:26:30 +0200 Subject: [PATCH 157/334] [SX127x] add getTempRaw method Signed-off-by: gozu42 --- keywords.txt | 1 + src/modules/SX127x/SX127x.cpp | 52 +++++++++++++++++++++++++++++++++++ src/modules/SX127x/SX127x.h | 11 ++++++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/keywords.txt b/keywords.txt index 84b70c88..d7aa3950 100644 --- a/keywords.txt +++ b/keywords.txt @@ -126,6 +126,7 @@ setRSSIConfig KEYWORD2 setEncoding KEYWORD2 getIRQFlags KEYWORD2 getModemStatus KEYWORD2 +getTempRaw KEYWORD2 # RF69-specific setAESKey KEYWORD2 diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 2a3a5121..a26e0c60 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -934,6 +934,58 @@ uint8_t SX127x::getModemStatus() { return(_mod->SPIreadRegister(SX127X_REG_MODEM_STAT)); } +int8_t SX127x::getTempRaw() { + int8_t temp = 0; + uint8_t previousOpMode; + uint8_t ival; + + // save current Op Mode + previousOpMode = _mod->SPIgetRegValue(SX127X_REG_OP_MODE); + + // check if we need to step out of LoRa mode first + if ((previousOpMode & SX127X_LORA) == SX127X_LORA) { + _mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_LORA | SX127X_SLEEP)); + } + + // put device in FSK sleep + _mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_FSK_OOK | SX127X_SLEEP)); + + // put device in FSK RxSynth + _mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_FSK_OOK | SX127X_FSRX)); + + // enable temperature reading + _mod->SPIsetRegValue(SX127X_REG_IMAGE_CAL, SX127X_TEMP_MONITOR_ON, 0, 0); + + // wait + delayMicroseconds(200); + + // disable temperature reading + _mod->SPIsetRegValue(SX127X_REG_IMAGE_CAL, SX127X_TEMP_MONITOR_OFF, 0, 0); + + // put device in FSK sleep + _mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_FSK_OOK | SX127X_SLEEP)); + + // read temperature + ival = _mod->SPIgetRegValue(SX127X_REG_TEMP); + + // convert very raw value + if ((ival & 0x80) == 0x80) { + temp = 255 - ival; + } else { + temp = -1 * ival; + } + + // check if we need to step back into LoRa mode + if ((previousOpMode & SX127X_LORA) == SX127X_LORA) { + _mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_LORA | SX127X_SLEEP)); + } + + // reload previous Op Mode + _mod->SPIsetRegValue(SX127X_REG_OP_MODE, previousOpMode); + + return(temp); +} + int16_t SX127x::config() { // turn off frequency hopping int16_t state = _mod->SPIsetRegValue(SX127X_REG_HOP_PERIOD, SX127X_HOP_PERIOD_OFF); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 7404427c..7d2a00a2 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -459,8 +459,8 @@ #define SX127X_TEMP_THRESHOLD_10_DEG_C 0b00000010 // 2 1 10 deg. C (default) #define SX127X_TEMP_THRESHOLD_15_DEG_C 0b00000100 // 2 1 15 deg. C #define SX127X_TEMP_THRESHOLD_20_DEG_C 0b00000110 // 2 1 20 deg. C -#define SX127X_TEMP_MONITOR_OFF 0b00000000 // 0 0 temperature monitoring disabled (default) -#define SX127X_TEMP_MONITOR_ON 0b00000001 // 0 0 temperature monitoring enabled +#define SX127X_TEMP_MONITOR_ON 0b00000000 // 0 0 temperature monitoring enabled (default) +#define SX127X_TEMP_MONITOR_OFF 0b00000001 // 0 0 temperature monitoring disabled // SX127X_REG_LOW_BAT #define SX127X_LOW_BAT_OFF 0b00000000 // 3 3 low battery detector disabled @@ -913,6 +913,13 @@ class SX127x: public PhysicalLayer { */ uint8_t getModemStatus(); + /*! + \brief Reads uncalibrated temperature value. + + \returns Uncalibrated temperature sensor reading. + */ + int8_t getTempRaw(); + #ifdef RADIOLIB_DEBUG void regDump(); #endif From cec0c4d1e2256222b2bd0d7279feca24445a0af4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 1 Jun 2020 16:14:33 +0200 Subject: [PATCH 158/334] [SX127x] Added comment about op mode change --- src/modules/SX127x/SX127x.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 7d2a00a2..25a06a14 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -914,7 +914,8 @@ class SX127x: public PhysicalLayer { uint8_t getModemStatus(); /*! - \brief Reads uncalibrated temperature value. + \brief Reads uncalibrated temperature value. This function will change operating mode + and should not be called during Tx, Rx or CAD. \returns Uncalibrated temperature sensor reading. */ From 78022ce6add50f50ce81bda59c374410e879597b Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:31:38 +0200 Subject: [PATCH 159/334] Added external RF switch control base --- keywords.txt | 1 + src/Module.cpp | 24 ++++++++++++++++++++++++ src/Module.h | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/keywords.txt b/keywords.txt index d7aa3950..f55c7fbf 100644 --- a/keywords.txt +++ b/keywords.txt @@ -127,6 +127,7 @@ setEncoding KEYWORD2 getIRQFlags KEYWORD2 getModemStatus KEYWORD2 getTempRaw KEYWORD2 +setRfSwitchPins KEYWORD2 # RF69-specific setAESKey KEYWORD2 diff --git a/src/Module.cpp b/src/Module.cpp index b4db0504..af6415bb 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -314,3 +314,27 @@ void Module::noTone(RADIOLIB_PIN_TYPE pin) { } #endif } + +void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _useRfSwitch = true; + _rxEn = rxEn; + _txEn = txEn; + Module::pinMode(rxEn, OUTPUT); + Module::pinMode(txEn, OUTPUT); +} + +void Module::setRfSwitchState(bool tx) { + // check RF switch control is enabled + if(!_useRfSwitch) { + return; + } + + // set pins + if(tx) { + Module::digitalWrite(_rxEn, LOW); + Module::digitalWrite(_txEn, HIGH); + } else { + Module::digitalWrite(_rxEn, HIGH); + Module::digitalWrite(_txEn, LOW); + } +} diff --git a/src/Module.h b/src/Module.h index a77d1a7e..41e25299 100644 --- a/src/Module.h +++ b/src/Module.h @@ -386,6 +386,23 @@ class Module { */ static void noTone(RADIOLIB_PIN_TYPE pin); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + + /*! + \brief Set RF switch state. + + \param tx True to set RF switch to Tx, false to set switch to Rx. + */ + void setRfSwitchState(bool tx); + #ifndef RADIOLIB_GODMODE private: #endif @@ -399,6 +416,9 @@ class Module { SPIClass* _spi; SPISettings _spiSettings; + bool _useRfSwitch = false; + RADIOLIB_PIN_TYPE _rxEn, _txEn; + uint32_t _ATtimeout = 15000; }; From 3aafb2f5bf997ec56c28619f2c432e02c275edc1 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:32:11 +0200 Subject: [PATCH 160/334] [CC1101] Implemented RF switch control --- src/modules/CC1101/CC1101.cpp | 10 ++++++++++ src/modules/CC1101/CC1101.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 2854fca8..2e3f4dea 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -232,6 +232,9 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // write packet to FIFO SPIwriteRegisterBurst(CC1101_REG_FIFO, data, len); + // set RF switch (if present) + _mod->setRfSwitchState(true); + // set mode to transmit SPIsendCommand(CC1101_CMD_TX); @@ -249,6 +252,9 @@ int16_t CC1101::startReceive() { int state = SPIsetRegValue(CC1101_REG_IOCFG0, CC1101_GDOX_SYNC_WORD_SENT_OR_RECEIVED); RADIOLIB_ASSERT(state); + // set RF switch (if present) + _mod->setRfSwitchState(false); + // set mode to receive SPIsendCommand(CC1101_CMD_RX); @@ -710,6 +716,10 @@ int16_t CC1101::setEncoding(uint8_t encoding) { } } +void CC1101::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _mod->setRfSwitchPins(rxEn, txEn); +} + int16_t CC1101::config() { // Reset the radio. Registers may be dirty from previous usage. SPIsendCommand(CC1101_CMD_RESET); diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index d6cfe45c..0ef0df29 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -864,6 +864,16 @@ class CC1101: public PhysicalLayer { */ int16_t setEncoding(uint8_t encoding); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + #ifndef RADIOLIB_GODMODE private: #endif From 0f287a53e7013c1e9183e6c38a8e2259e5f7d6b1 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:32:30 +0200 Subject: [PATCH 161/334] [RF69] Implemented RF switch control --- src/modules/RF69/RF69.cpp | 10 ++++++++++ src/modules/RF69/RF69.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 856101f2..6b925eb6 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -238,6 +238,9 @@ int16_t RF69::startReceive() { // clear interrupt flags clearIRQFlags(); + // set RF switch (if present) + _mod->setRfSwitchState(false); + // set mode to receive state = _mod->SPIsetRegValue(RF69_REG_OCP, RF69_OCP_ON | RF69_OCP_TRIM); state |= _mod->SPIsetRegValue(RF69_REG_TEST_PA1, RF69_PA1_NORMAL); @@ -314,6 +317,9 @@ int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); } + // set RF switch (if present) + _mod->setRfSwitchState(true); + // set mode to transmit state = setMode(RF69_TX); @@ -730,6 +736,10 @@ float RF69::getRSSI() { return(-1.0 * (_mod->SPIgetRegValue(RF69_REG_RSSI_VALUE)/2.0)); } +void RF69::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _mod->setRfSwitchPins(rxEn, txEn); +} + int16_t RF69::config() { int16_t state = ERR_NONE; diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 18aa8df4..fa8362a5 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -795,6 +795,16 @@ class RF69: public PhysicalLayer { */ float getRSSI(); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + #ifndef RADIOLIB_GODMODE protected: #endif From d1527b0d8cdef4c7350dabc860e73e71d1789da7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:32:52 +0200 Subject: [PATCH 162/334] [Si443x] Implemented RF switch control --- src/modules/Si443x/Si443x.cpp | 10 ++++++++++ src/modules/Si443x/Si443x.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 153e5c3e..0ec47c9b 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -222,6 +222,9 @@ int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // write packet to FIFO _mod->SPIwriteRegisterBurst(SI443X_REG_FIFO_ACCESS, data, len); + // set RF switch (if present) + _mod->setRfSwitchState(true); + // set mode to transmit _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_TX_ON); @@ -246,6 +249,9 @@ int16_t Si443x::startReceive() { // clear interrupt flags clearIRQFlags(); + // set RF switch (if present) + _mod->setRfSwitchState(false); + // set mode to receive _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_RX_ON); @@ -504,6 +510,10 @@ int16_t Si443x::setDataShaping(float sh) { } } +void Si443x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _mod->setRfSwitchPins(rxEn, txEn); +} + int16_t Si443x::setFrequencyRaw(float newFreq) { // set mode to standby int16_t state = standby(); diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h index df5ae4d0..1cfd2700 100644 --- a/src/modules/Si443x/Si443x.h +++ b/src/modules/Si443x/Si443x.h @@ -760,6 +760,16 @@ class Si443x: public PhysicalLayer { */ int16_t setDataShaping(float sh); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + #ifndef RADIOLIB_GODMODE protected: #endif From 5a3d7a71731c60f4ecfc4d8c39ba359f982380af Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:36:02 +0200 Subject: [PATCH 163/334] [SX128x] Implemented RF switch control --- examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino | 10 ++++++++++ src/modules/SX128x/SX128x.cpp | 10 ++++++++++ src/modules/SX128x/SX128x.h | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino b/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino index e8e777dc..b86259cf 100644 --- a/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino +++ b/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino @@ -47,6 +47,16 @@ void setup() { Serial.println(state); while (true); } + + // some modules have an external RF switch + // controlled via two pins (RX enable, TX enable) + // to enable automatic control of the switch, + // call the following method + // RX enable: 4 + // TX enable: 5 + /* + lora.setRfSwitchPins(4, 5); + */ } void loop() { diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 993ff9ec..d222b016 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -477,6 +477,9 @@ int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { state = clearIrqStatus(); RADIOLIB_ASSERT(state); + // set RF switch (if present) + _mod->setRfSwitchState(true); + // start transmission state = setTx(SX128X_TX_TIMEOUT_NONE); RADIOLIB_ASSERT(state); @@ -513,6 +516,9 @@ int16_t SX128x::startReceive(uint16_t timeout) { RADIOLIB_ASSERT(state); } + // set RF switch (if present) + _mod->setRfSwitchState(false); + // set mode to receive state = setRx(timeout); @@ -1090,6 +1096,10 @@ int16_t SX128x::setEncoding(uint8_t encoding) { return(setWhitening(encoding)); } +void SX128x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _mod->setRfSwitchPins(rxEn, txEn); +} + uint8_t SX128x::getStatus() { uint8_t data = 0; SPIreadCommand(SX128X_CMD_GET_STATUS, &data, 1); diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index a5aea25c..755bc443 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -741,6 +741,16 @@ class SX128x: public PhysicalLayer { */ int16_t setEncoding(uint8_t encoding); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + #ifndef RADIOLIB_GODMODE protected: #endif From 4ad82f15725f475664d599ab5ad3b141365ba5d8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:36:11 +0200 Subject: [PATCH 164/334] [SX127x] Implemented RF switch control --- examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino | 10 ++++++++++ src/modules/SX127x/SX127x.cpp | 13 +++++++++++++ src/modules/SX127x/SX127x.h | 10 ++++++++++ 3 files changed, 33 insertions(+) diff --git a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino index cd5ad220..265ee32f 100644 --- a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino +++ b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino @@ -49,6 +49,16 @@ void setup() { Serial.println(state); while (true); } + + // some modules have an external RF switch + // controlled via two pins (RX enable, TX enable) + // to enable automatic control of the switch, + // call the following method + // RX enable: 4 + // TX enable: 5 + /* + lora.setRfSwitchPins(4, 5); + */ } void loop() { diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index a26e0c60..ccc27da1 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -368,6 +368,9 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { } } + // set RF switch (if present) + _mod->setRfSwitchState(false); + // set mode to receive return(setMode(mode)); } @@ -421,6 +424,9 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // write packet to FIFO _mod->SPIwriteRegisterBurst(SX127X_REG_FIFO, data, len); + // set RF switch (if present) + _mod->setRfSwitchState(true); + // start transmission state |= setMode(SX127X_TX); RADIOLIB_ASSERT(state); @@ -451,6 +457,9 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // write packet to FIFO _mod->SPIwriteRegisterBurst(SX127X_REG_FIFO, data, len); + // set RF switch (if present) + _mod->setRfSwitchState(true); + // start transmission state |= setMode(SX127X_TX); RADIOLIB_ASSERT(state); @@ -934,6 +943,10 @@ uint8_t SX127x::getModemStatus() { return(_mod->SPIreadRegister(SX127X_REG_MODEM_STAT)); } +void SX127x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _mod->setRfSwitchPins(rxEn, txEn); +} + int8_t SX127x::getTempRaw() { int8_t temp = 0; uint8_t previousOpMode; diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 25a06a14..7f075e9b 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -921,6 +921,16 @@ class SX127x: public PhysicalLayer { */ int8_t getTempRaw(); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + #ifdef RADIOLIB_DEBUG void regDump(); #endif From d710a85985168b163267250d1cd5d814dc5968a9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 18 Jun 2020 16:38:30 +0200 Subject: [PATCH 165/334] [SX126x] Implemented RF switch control (#153) --- examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino | 10 ++++++++++ src/modules/SX126x/SX126x.cpp | 10 ++++++++++ src/modules/SX126x/SX126x.h | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino b/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino index 574fdff3..338bf3f5 100644 --- a/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino +++ b/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino @@ -51,6 +51,16 @@ void setup() { Serial.println(state); while (true); } + + // some modules have an external RF switch + // controlled via two pins (RX enable, TX enable) + // to enable automatic control of the switch, + // call the following method + // RX enable: 4 + // TX enable: 5 + /* + lora.setRfSwitchPins(4, 5); + */ } void loop() { diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index e419761e..efbecc10 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -435,6 +435,9 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { state = fixSensitivity(); RADIOLIB_ASSERT(state); + // set RF switch (if present) + _mod->setRfSwitchState(true); + // start transmission state = setTx(SX126X_TX_TIMEOUT_NONE); RADIOLIB_ASSERT(state); @@ -451,6 +454,9 @@ int16_t SX126x::startReceive(uint32_t timeout) { int16_t state = startReceiveCommon(); RADIOLIB_ASSERT(state); + // set RF switch (if present) + _mod->setRfSwitchState(true); + // set mode to receive state = setRx(timeout); @@ -1117,6 +1123,10 @@ int16_t SX126x::setEncoding(uint8_t encoding) { return(setWhitening(encoding)); } +void SX126x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { + _mod->setRfSwitchPins(rxEn, txEn); +} + int16_t SX126x::setTCXO(float voltage, uint32_t delay) { // set mode to standby standby(); diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index e6a7f078..ae2216d6 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -843,6 +843,16 @@ class SX126x: public PhysicalLayer { */ int16_t setEncoding(uint8_t encoding); + /*! + \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. + When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! + + \param rxEn RX enable pin. + + \param txEn TX enable pin. + */ + void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + #ifndef RADIOLIB_GODMODE protected: #endif From bb7108a52bbc5178f3223dc97e344da8eaaa1b36 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 19 Jun 2020 08:23:28 +0200 Subject: [PATCH 166/334] [SX126x] Fixed RF switch state in Rx mode --- src/modules/SX126x/SX126x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index efbecc10..9a018b8e 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -455,7 +455,7 @@ int16_t SX126x::startReceive(uint32_t timeout) { RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(true); + _mod->setRfSwitchState(false); // set mode to receive state = setRx(timeout); From 56360a2a0560e158074ecfd654b5d8996ebb6182 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 16:59:20 +0200 Subject: [PATCH 167/334] Changed setRfSwitchState to directly change switch pins --- src/Module.cpp | 11 +++-------- src/Module.h | 6 ++++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index af6415bb..e24e6424 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -323,18 +323,13 @@ void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { Module::pinMode(txEn, OUTPUT); } -void Module::setRfSwitchState(bool tx) { +void Module::setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState) { // check RF switch control is enabled if(!_useRfSwitch) { return; } // set pins - if(tx) { - Module::digitalWrite(_rxEn, LOW); - Module::digitalWrite(_txEn, HIGH); - } else { - Module::digitalWrite(_rxEn, HIGH); - Module::digitalWrite(_txEn, LOW); - } + Module::digitalWrite(_rxEn, rxPinState); + Module::digitalWrite(_txEn, txPinState); } diff --git a/src/Module.h b/src/Module.h index 41e25299..2a20b926 100644 --- a/src/Module.h +++ b/src/Module.h @@ -399,9 +399,11 @@ class Module { /*! \brief Set RF switch state. - \param tx True to set RF switch to Tx, false to set switch to Rx. + \param rxPinState Pin state to set on Tx enable pin (usually high to transmit). + + \param txPinState Pin state to set on Rx enable pin (usually high to receive). */ - void setRfSwitchState(bool tx); + void setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState); #ifndef RADIOLIB_GODMODE private: From 05f1e998d7050468c5058ea486168cfe1cbb2226 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 17:03:34 +0200 Subject: [PATCH 168/334] [CC1101] Added missing RF switch control --- src/modules/CC1101/CC1101.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 2e3f4dea..8074a37b 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -139,11 +139,18 @@ int16_t CC1101::receive(uint8_t* data, size_t len) { } int16_t CC1101::standby() { + // set idle mode SPIsendCommand(CC1101_CMD_IDLE); + + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); return(ERR_NONE); } int16_t CC1101::transmitDirect(uint32_t frf) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, HIGH); + // user requested to start transmitting immediately (required for RTTY) if(frf != 0) { SPIwriteRegister(CC1101_REG_FREQ2, (frf & 0xFF0000) >> 16); @@ -163,6 +170,9 @@ int16_t CC1101::transmitDirect(uint32_t frf) { } int16_t CC1101::receiveDirect() { + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // activate direct mode int16_t state = directMode(); RADIOLIB_ASSERT(state); @@ -233,7 +243,7 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { SPIwriteRegisterBurst(CC1101_REG_FIFO, data, len); // set RF switch (if present) - _mod->setRfSwitchState(true); + _mod->setRfSwitchState(LOW, HIGH); // set mode to transmit SPIsendCommand(CC1101_CMD_TX); @@ -253,7 +263,7 @@ int16_t CC1101::startReceive() { RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(false); + _mod->setRfSwitchState(HIGH, LOW); // set mode to receive SPIsendCommand(CC1101_CMD_RX); From b68bd2f9f9f0df0e599e8db7fddc34853fe32418 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 17:03:42 +0200 Subject: [PATCH 169/334] [RF69] Added missing RF switch control --- src/modules/RF69/RF69.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 6b925eb6..2e57bf7f 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -160,16 +160,25 @@ int16_t RF69::receive(uint8_t* data, size_t len) { } int16_t RF69::sleep() { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + // set module to sleep return(setMode(RF69_SLEEP)); } int16_t RF69::standby() { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + // set module to standby return(setMode(RF69_STANDBY)); } int16_t RF69::transmitDirect(uint32_t frf) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, HIGH); + // user requested to start transmitting immediately (required for RTTY) if(frf != 0) { _mod->SPIwriteRegister(RF69_REG_FRF_MSB, (frf & 0xFF0000) >> 16); @@ -188,6 +197,9 @@ int16_t RF69::transmitDirect(uint32_t frf) { } int16_t RF69::receiveDirect() { + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // activate direct mode int16_t state = directMode(); RADIOLIB_ASSERT(state); @@ -239,7 +251,7 @@ int16_t RF69::startReceive() { clearIRQFlags(); // set RF switch (if present) - _mod->setRfSwitchState(false); + _mod->setRfSwitchState(HIGH, LOW); // set mode to receive state = _mod->SPIsetRegValue(RF69_REG_OCP, RF69_OCP_ON | RF69_OCP_TRIM); @@ -318,7 +330,7 @@ int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) { } // set RF switch (if present) - _mod->setRfSwitchState(true); + _mod->setRfSwitchState(LOW, HIGH); // set mode to transmit state = setMode(RF69_TX); @@ -330,6 +342,7 @@ int16_t RF69::readData(uint8_t* data, size_t len) { // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); + // get packet length size_t length = len; if(len == RF69_MAX_PACKET_LENGTH) { From 5f4481aef61e9c43d7d8fd1ef231021f5701daa0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 17:03:55 +0200 Subject: [PATCH 170/334] [Si443x] Added missing RF switch control --- src/modules/Si443x/Si443x.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 0ec47c9b..099fb866 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -114,6 +114,9 @@ int16_t Si443x::receive(uint8_t* data, size_t len) { } int16_t Si443x::sleep() { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + // disable wakeup timer interrupt int16_t state = _mod->SPIsetRegValue(SI443X_REG_INTERRUPT_ENABLE_1, 0x00); RADIOLIB_ASSERT(state); @@ -127,10 +130,16 @@ int16_t Si443x::sleep() { } int16_t Si443x::standby() { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + return(_mod->SPIsetRegValue(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_XTAL_ON, 7, 0, 10)); } int16_t Si443x::transmitDirect(uint32_t frf) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, HIGH); + // user requested to start transmitting immediately (required for RTTY) if(frf != 0) { // convert the 24-bit frequency to the format accepted by the module @@ -170,6 +179,9 @@ int16_t Si443x::transmitDirect(uint32_t frf) { } int16_t Si443x::receiveDirect() { + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // activate direct mode int16_t state = directMode(); RADIOLIB_ASSERT(state); @@ -223,7 +235,7 @@ int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { _mod->SPIwriteRegisterBurst(SI443X_REG_FIFO_ACCESS, data, len); // set RF switch (if present) - _mod->setRfSwitchState(true); + _mod->setRfSwitchState(LOW, HIGH); // set mode to transmit _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_TX_ON); @@ -250,7 +262,7 @@ int16_t Si443x::startReceive() { clearIRQFlags(); // set RF switch (if present) - _mod->setRfSwitchState(false); + _mod->setRfSwitchState(HIGH, LOW); // set mode to receive _mod->SPIwriteRegister(SI443X_REG_OP_FUNC_CONTROL_1, SI443X_RX_ON); From 75197d78a0fe7afbe1dd98530c9370c692ae03aa Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 17:04:03 +0200 Subject: [PATCH 171/334] [SX128x] Added missing RF switch control --- src/modules/SX128x/SX128x.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index d222b016..97222c70 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -340,6 +340,9 @@ int16_t SX128x::receive(uint8_t* data, size_t len) { } int16_t SX128x::transmitDirect(uint32_t frf) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, HIGH); + // user requested to start transmitting immediately (required for RTTY) int16_t state = ERR_NONE; if(frf != 0) { @@ -352,6 +355,9 @@ int16_t SX128x::transmitDirect(uint32_t frf) { } int16_t SX128x::receiveDirect() { + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // SX128x is unable to output received data directly return(ERR_UNKNOWN); } @@ -374,6 +380,9 @@ int16_t SX128x::scanChannel() { state = clearIrqStatus(); RADIOLIB_ASSERT(state); + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // set mode to CAD state = setCad(); RADIOLIB_ASSERT(state); @@ -399,6 +408,9 @@ int16_t SX128x::scanChannel() { } int16_t SX128x::sleep(bool retainConfig) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + uint8_t sleepConfig = SX128X_SLEEP_DATA_BUFFER_RETAIN | SX128X_SLEEP_DATA_RAM_RETAIN; if(!retainConfig) { sleepConfig = SX128X_SLEEP_DATA_BUFFER_FLUSH | SX128X_SLEEP_DATA_RAM_FLUSH; @@ -416,6 +428,9 @@ int16_t SX128x::standby() { } int16_t SX128x::standby(uint8_t mode) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + uint8_t data[] = { mode }; return(SPIwriteCommand(SX128X_CMD_SET_STANDBY, data, 1)); } @@ -478,7 +493,7 @@ int16_t SX128x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(true); + _mod->setRfSwitchState(LOW, HIGH); // start transmission state = setTx(SX128X_TX_TIMEOUT_NONE); @@ -517,7 +532,7 @@ int16_t SX128x::startReceive(uint16_t timeout) { } // set RF switch (if present) - _mod->setRfSwitchState(false); + _mod->setRfSwitchState(HIGH, LOW); // set mode to receive state = setRx(timeout); From 3fe7da9788e59d6cf6e6d0a34cf744dbf77952a8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 17:04:11 +0200 Subject: [PATCH 172/334] [SX127x] Added missing RF switch control --- src/modules/SX127x/SX127x.cpp | 53 ++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index ccc27da1..45fe5f01 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -245,6 +245,9 @@ int16_t SX127x::scanChannel() { // clear interrupt flags clearIRQFlags(); + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // set mode to CAD state = setMode(SX127X_CAD); RADIOLIB_ASSERT(state); @@ -265,11 +268,17 @@ int16_t SX127x::scanChannel() { } int16_t SX127x::sleep() { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + // set mode to sleep return(setMode(SX127X_SLEEP)); } int16_t SX127x::standby() { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + // set mode to standby return(setMode(SX127X_STANDBY)); } @@ -280,6 +289,9 @@ int16_t SX127x::transmitDirect(uint32_t FRF) { return(ERR_WRONG_MODEM); } + // set RF switch (if present) + _mod->setRfSwitchState(LOW, HIGH); + // user requested to start transmitting immediately (required for RTTY) if(FRF != 0) { _mod->SPIwriteRegister(SX127X_REG_FRF_MSB, (FRF & 0xFF0000) >> 16); @@ -303,6 +315,9 @@ int16_t SX127x::receiveDirect() { return(ERR_WRONG_MODEM); } + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // activate direct mode int16_t state = directMode(); RADIOLIB_ASSERT(state); @@ -369,7 +384,7 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { } // set RF switch (if present) - _mod->setRfSwitchState(false); + _mod->setRfSwitchState(HIGH, LOW); // set mode to receive return(setMode(mode)); @@ -421,18 +436,6 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { state |= _mod->SPIsetRegValue(SX127X_REG_FIFO_TX_BASE_ADDR, SX127X_FIFO_TX_BASE_ADDR_MAX); state |= _mod->SPIsetRegValue(SX127X_REG_FIFO_ADDR_PTR, SX127X_FIFO_TX_BASE_ADDR_MAX); - // write packet to FIFO - _mod->SPIwriteRegisterBurst(SX127X_REG_FIFO, data, len); - - // set RF switch (if present) - _mod->setRfSwitchState(true); - - // start transmission - state |= setMode(SX127X_TX); - RADIOLIB_ASSERT(state); - - return(ERR_NONE); - } else if(modem == SX127X_FSK_OOK) { // check packet length if(len >= SX127X_MAX_PACKET_LENGTH_FSK) { @@ -453,21 +456,19 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { if((filter == SX127X_ADDRESS_FILTERING_NODE) || (filter == SX127X_ADDRESS_FILTERING_NODE_BROADCAST)) { _mod->SPIwriteRegister(SX127X_REG_FIFO, addr); } - - // write packet to FIFO - _mod->SPIwriteRegisterBurst(SX127X_REG_FIFO, data, len); - - // set RF switch (if present) - _mod->setRfSwitchState(true); - - // start transmission - state |= setMode(SX127X_TX); - RADIOLIB_ASSERT(state); - - return(ERR_NONE); } - return(ERR_UNKNOWN); + // write packet to FIFO + _mod->SPIwriteRegisterBurst(SX127X_REG_FIFO, data, len); + + // set RF switch (if present) + _mod->setRfSwitchState(LOW, HIGH); + + // start transmission + state |= setMode(SX127X_TX); + RADIOLIB_ASSERT(state); + + return(ERR_NONE); } int16_t SX127x::readData(uint8_t* data, size_t len) { From 06c254bc6edd2e25cd04c1b37bfbec37ad645ad2 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 17:04:17 +0200 Subject: [PATCH 173/334] [SX126x] Added missing RF switch control --- src/modules/SX126x/SX126x.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 9a018b8e..18d9ad81 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -300,6 +300,9 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { } int16_t SX126x::transmitDirect(uint32_t frf) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, HIGH); + // user requested to start transmitting immediately (required for RTTY) int16_t state = ERR_NONE; if(frf != 0) { @@ -313,6 +316,9 @@ int16_t SX126x::transmitDirect(uint32_t frf) { } int16_t SX126x::receiveDirect() { + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // SX126x is unable to output received data directly return(ERR_UNKNOWN); } @@ -327,6 +333,9 @@ int16_t SX126x::scanChannel() { int16_t state = standby(); RADIOLIB_ASSERT(state); + // set RF switch (if present) + _mod->setRfSwitchState(HIGH, LOW); + // set DIO pin mapping state = setDioIrqParams(SX126X_IRQ_CAD_DETECTED | SX126X_IRQ_CAD_DONE, SX126X_IRQ_CAD_DETECTED | SX126X_IRQ_CAD_DONE); RADIOLIB_ASSERT(state); @@ -360,6 +369,9 @@ int16_t SX126x::scanChannel() { } int16_t SX126x::sleep(bool retainConfig) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + uint8_t sleepMode = SX126X_SLEEP_START_WARM | SX126X_SLEEP_RTC_OFF; if(!retainConfig) { sleepMode = SX126X_SLEEP_START_COLD | SX126X_SLEEP_RTC_OFF; @@ -377,6 +389,9 @@ int16_t SX126x::standby() { } int16_t SX126x::standby(uint8_t mode) { + // set RF switch (if present) + _mod->setRfSwitchState(LOW, LOW); + uint8_t data[] = {mode}; return(SPIwriteCommand(SX126X_CMD_SET_STANDBY, data, 1)); } @@ -436,7 +451,7 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(true); + _mod->setRfSwitchState(LOW, HIGH); // start transmission state = setTx(SX126X_TX_TIMEOUT_NONE); @@ -455,7 +470,7 @@ int16_t SX126x::startReceive(uint32_t timeout) { RADIOLIB_ASSERT(state); // set RF switch (if present) - _mod->setRfSwitchState(false); + _mod->setRfSwitchState(HIGH, LOW); // set mode to receive state = setRx(timeout); From 6bdef760315c76cac2f6bfef249ce79eddf77d5f Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 21:09:12 +0200 Subject: [PATCH 174/334] [SX128x] Added SPI delay for SAMD cores --- src/modules/SX128x/SX128x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 97222c70..112417f5 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -1412,7 +1412,7 @@ int16_t SX128x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d // some faster platforms require a short delay here // not sure why, but it seems that long enough SPI transaction // (e.g. setPacketParams for GFSK) will fail without it - #if defined(ARDUINO_ARCH_STM32) + #if defined(ARDUINO_ARCH_STM32) || defined(SAMD_SERIES) delay(1); #endif #endif From aa4f4c9ab41dcff153f90267b38a2eb46ab22a98 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 20 Jun 2020 21:13:50 +0200 Subject: [PATCH 175/334] [SX126x] Added SPI delay for SAMD cores (#153) --- src/modules/SX126x/SX126x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 18d9ad81..3a8aecaa 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -1658,7 +1658,7 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d // some faster platforms require a short delay here // not sure why, but it seems that long enough SPI transaction // (e.g. setPacketParams for GFSK) will fail without it - #if defined(ARDUINO_ARCH_STM32) + #if defined(ARDUINO_ARCH_STM32) || defined(SAMD_SERIES) delay(1); #endif #endif From e356054f56235107892a7f8fbfa45cce2e76c795 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 21 Jun 2020 08:15:53 +0200 Subject: [PATCH 176/334] Bump version to 3.7.0 --- library.properties | 2 +- src/BuildOpt.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.properties b/library.properties index 733be1bd..f2c3def6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=3.6.2 +version=3.7.0 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/BuildOpt.h b/src/BuildOpt.h index a5de6898..8e4918ae 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -269,8 +269,8 @@ // version definitions #define RADIOLIB_VERSION_MAJOR (0x03) -#define RADIOLIB_VERSION_MINOR (0x06) -#define RADIOLIB_VERSION_PATCH (0x02) +#define RADIOLIB_VERSION_MINOR (0x07) +#define RADIOLIB_VERSION_PATCH (0x00) #define RADIOLIB_VERSION_EXTRA (0x00) #define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA)) From 67925473a0faf9b73e77136fbfe94547814c01e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Sat, 27 Jun 2020 07:49:50 +0200 Subject: [PATCH 177/334] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 49d358d7..94d6b531 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -11,7 +11,7 @@ assignees: '' Before submitting new issue, please check the [Wiki](https://github.com/jgromes/RadioLib/wiki) and the [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there. **Describe the bug** -A clear and concise description of what the bug is. When applicable, please include debug mode output: uncomment [debug macro definitions in BuildOpt.h](https://github.com/jgromes/RadioLib/blob/master/src/BuildOpt.h#L135) and post the output. +A clear and concise description of what the bug is. When applicable, please include [debug mode output](https://github.com/jgromes/RadioLib/wiki/Debug-mode). **To Reproduce** Minimal Arduino sketch to reproduce the behavior. Please user Markdown to style the code to make it readable (see [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code)). From 25dcf8c16117a0019d754b15d12ab68615db3a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Sat, 27 Jun 2020 18:04:33 +0200 Subject: [PATCH 178/334] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 94d6b531..0258df19 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -24,6 +24,7 @@ If applicable, add screenshots to help explain your problem. **Additional info (please complete):** - MCU: [e.g. Arduino Uno, ESP8266 etc.] + - Link to Arduino core: [e.g. https://github.com/stm32duino/Arduino_Core_STM32 when using official STM32 core. See readme for links to all supported cores] - Wireless module type [e.g. CC1101, SX1268, etc.] - Arduino IDE version [e.g. 1.8.5] - Library version [e.g. 3.0.0] From 49259109d31368f54c66b19303685657ce992093 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 28 Jun 2020 20:36:16 +0200 Subject: [PATCH 179/334] Updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad437969..10da3c3f 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ The list above is by no means exhaustive. Most of RadioLib code is independent o ## Frequently Asked Questions ### Where should I start? -First of all, take a look at the [examples](https://github.com/jgromes/RadioLib/tree/master/examples) and the [Wiki](https://github.com/jgromes/RadioLib/wiki) - especially the [Basics](https://github.com/jgromes/RadioLib/wiki/Basics) page. There's a lot of useful information over there. Also, you should check out [RadioShield](https://github.com/jgromes/RadioShield) - open source Arduino shield that will allow you to easily connect any two wireless modules supported by RadioLib! +First of all, take a look at the [examples](https://github.com/jgromes/RadioLib/tree/master/examples) and the [Wiki](https://github.com/jgromes/RadioLib/wiki) - especially the [Basics](https://github.com/jgromes/RadioLib/wiki/Basics) page. There's a lot of useful information over there. If something isn't working as expected, try searching the [issues](https://github.com/jgromes/RadioLib/issues/). ### Help, my module isn't working! The fastest way to get help is by creating an [issue](https://github.com/jgromes/RadioLib/issues/new?assignees=&labels=&template=bug_report.md&title=) using the appropriate template. It is also highly recommended to try running the examples first - their functionality is tested from time to time and they should work. Finally, RadioLib is still under development, which means that sometimes, backwards-incompatible changes might be introduced. Though these are kept at minimum, sometimes it is unavoidable. You can check the [release changelog](https://github.com/jgromes/RadioLib/releases) to find out if there's been such a major change recently. From 738d7116987cb9505c0ea1fefad8e18b56d73f51 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 29 Jun 2020 08:13:41 +0200 Subject: [PATCH 180/334] Fixed debug conditionals --- src/BuildOpt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 8e4918ae..70a64e60 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -216,7 +216,7 @@ // set which Serial port should be used for debug output #define RADIOLIB_DEBUG_PORT Serial -#ifdef RADIOLIB_DEBUG +#if defined(RADIOLIB_DEBUG) #define RADIOLIB_DEBUG_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); } #define RADIOLIB_DEBUG_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } #else @@ -224,7 +224,7 @@ #define RADIOLIB_DEBUG_PRINTLN(...) {} #endif -#ifdef RADIOLIB_VERBOSE +#if defined(RADIOLIB_VERBOSE) #define RADIOLIB_VERBOSE_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); } #define RADIOLIB_VERBOSE_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } #else From 1749da28d7225cf3aff43f0ccd6e9e335b0004a0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 29 Jun 2020 09:54:26 +0200 Subject: [PATCH 181/334] Added custom platform template --- src/BuildOpt.h | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 70a64e60..d9ed675a 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -23,13 +23,34 @@ * * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). * - * Users may also specify their own configuration by defining all of the platform-specific parameters - * and macro RADIOLIB_CUSTOM_PLATFORM prior to including the main library file (RadioLib.h). + * Users may also specify their own configuration by uncommenting the RADIOLIB_CUSTOM_PLATFORM, + * and then specifying all platform parameters in the section below. This will override automatic + * platform detection. */ + +// uncomment to enable custom platform definition +#define RADIOLIB_CUSTOM_PLATFORM + #if defined(RADIOLIB_CUSTOM_PLATFORM) - #if !defined(RADIOLIB_PLATFORM) - #define RADIOLIB_PLATFORM "Custom" - #endif + // name for your platform + #define RADIOLIB_PLATFORM "Custom" + + // the following parameters must always be defined + #define RADIOLIB_PIN_TYPE uint8_t + #define RADIOLIB_PIN_MODE uint8_t + #define RADIOLIB_PIN_STATUS uint8_t + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI + + // the following must be defined if the Arduino core does not support SoftwareSerial library + //#define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + //#define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + + // the following must be defined if the Arduino core does not support tone function + //#define RADIOLIB_TONE_UNSUPPORTED + #else #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. From 4ad5261a8333eabb7af332fc60df5e007bf22647 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 29 Jun 2020 09:55:02 +0200 Subject: [PATCH 182/334] Fixed custom platform enabled by default --- src/BuildOpt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index d9ed675a..84c9b684 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -29,7 +29,7 @@ */ // uncomment to enable custom platform definition -#define RADIOLIB_CUSTOM_PLATFORM +//#define RADIOLIB_CUSTOM_PLATFORM #if defined(RADIOLIB_CUSTOM_PLATFORM) // name for your platform From 995d7054ef400c407173793c5a1f651f01847554 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:41:48 +0200 Subject: [PATCH 183/334] [CC1101] Reworked driver exlusion --- src/modules/CC1101/CC1101.cpp | 3 +++ src/modules/CC1101/CC1101.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 8074a37b..80b0c7db 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -1,4 +1,5 @@ #include "CC1101.h" +#if !defined(RADIOLIB_EXCLUDE_CC1101) CC1101::CC1101(Module* module) : PhysicalLayer(CC1101_FREQUENCY_STEP_SIZE, CC1101_MAX_PACKET_LENGTH) { _mod = module; @@ -857,3 +858,5 @@ void CC1101::SPIsendCommand(uint8_t cmd) { SPI.endTransaction(); Module::digitalWrite(_mod->getCs(), HIGH); } + +#endif diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index 0ef0df29..2ba3089e 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_CC1101_H +#if !defined(_RADIOLIB_CC1101_H) && !defined(RADIOLIB_EXCLUDE_CC1101) #define _RADIOLIB_CC1101_H #include "../../TypeDef.h" From 36a44ed44defb890eafb87bb96855f3dc13e9c93 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:42:13 +0200 Subject: [PATCH 184/334] [ESP8266] Reworked driver exclusion --- src/modules/ESP8266/ESP8266.cpp | 2 +- src/modules/ESP8266/ESP8266.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index bc372ac6..63f7bca0 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -1,5 +1,5 @@ -#if !defined(ESP8266) && !defined(ARDUINO_ARDUINO_NANO33BLE) #include "ESP8266.h" +#if !defined(RADIOLIB_EXCLUDE_ESP8266) ESP8266::ESP8266(Module* module) { _mod = module; diff --git a/src/modules/ESP8266/ESP8266.h b/src/modules/ESP8266/ESP8266.h index e817038e..a825b984 100644 --- a/src/modules/ESP8266/ESP8266.h +++ b/src/modules/ESP8266/ESP8266.h @@ -1,4 +1,4 @@ -#if !defined(_RADIOLIB_ESP8266_H) +#if !defined(_RADIOLIB_ESP8266_H) && !defined(RADIOLIB_EXCLUDE_ESP8266) #define _RADIOLIB_ESP8266_H #include "../../Module.h" From 535e35a3db1750cb3504d12ad055c9bea9912d08 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:42:23 +0200 Subject: [PATCH 185/334] [HC05] Reworked driver exclusion --- src/modules/HC05/HC05.cpp | 3 +++ src/modules/HC05/HC05.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/HC05/HC05.cpp b/src/modules/HC05/HC05.cpp index 2aecab76..7a35ce71 100644 --- a/src/modules/HC05/HC05.cpp +++ b/src/modules/HC05/HC05.cpp @@ -1,4 +1,5 @@ #include "HC05.h" +#if !defined(RADIOLIB_EXCLUDE_HC05) HC05::HC05(Module* mod) : ISerial(mod) { @@ -9,3 +10,5 @@ void HC05::begin(long speed) { _mod->baudrate = speed; _mod->init(RADIOLIB_USE_UART); } + +#endif diff --git a/src/modules/HC05/HC05.h b/src/modules/HC05/HC05.h index 2bfacb48..7721a50a 100644 --- a/src/modules/HC05/HC05.h +++ b/src/modules/HC05/HC05.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_HC05_H +#if !defined(_RADIOLIB_HC05_H) && !defined(RADIOLIB_EXCLUDE_HC05) #define _RADIOLIB_HC05_H #include "../../ISerial.h" From 67e36f4ed93e0b286c9f4c4ad09a74b0c30ee401 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:42:37 +0200 Subject: [PATCH 186/334] [JDY08] Reworked driver exclusion --- src/modules/JDY08/JDY08.cpp | 3 +++ src/modules/JDY08/JDY08.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/JDY08/JDY08.cpp b/src/modules/JDY08/JDY08.cpp index 78bc596b..a94cb37d 100644 --- a/src/modules/JDY08/JDY08.cpp +++ b/src/modules/JDY08/JDY08.cpp @@ -1,3 +1,4 @@ +#if !defined(_RADIOLIB_JDY08_H) && !defined(RADIOLIB_EXCLUDE_JDY08) #include "JDY08.h" JDY08::JDY08(Module* mod) : ISerial(mod) { @@ -10,3 +11,5 @@ void JDY08::begin(long speed) { _mod->baudrate = speed; _mod->init(RADIOLIB_USE_UART); } + +#endif diff --git a/src/modules/JDY08/JDY08.h b/src/modules/JDY08/JDY08.h index be01ef19..7bb64011 100644 --- a/src/modules/JDY08/JDY08.h +++ b/src/modules/JDY08/JDY08.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_JDY08_H +#if !defined(_RADIOLIB_JDY08_H) && !defined(RADIOLIB_EXCLUDE_JDY08) #define _RADIOLIB_JDY08_H #include "../../ISerial.h" From 984cfac31969d4571594b650e88c4254fd0a9e3b Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:42:47 +0200 Subject: [PATCH 187/334] [RF69] Reworked driver exclusion --- src/modules/RF69/RF69.cpp | 5 ++++- src/modules/RF69/RF69.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 2e57bf7f..7b1cad43 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -1,4 +1,5 @@ #include "RF69.h" +#if !defined(RADIOLIB_EXCLUDE_RF69) RF69::RF69(Module* module) : PhysicalLayer(RF69_FREQUENCY_STEP_SIZE, RF69_MAX_PACKET_LENGTH) { _mod = module; @@ -342,7 +343,7 @@ int16_t RF69::readData(uint8_t* data, size_t len) { // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); - + // get packet length size_t length = len; if(len == RF69_MAX_PACKET_LENGTH) { @@ -836,3 +837,5 @@ void RF69::clearIRQFlags() { _mod->SPIwriteRegister(RF69_REG_IRQ_FLAGS_1, 0b11111111); _mod->SPIwriteRegister(RF69_REG_IRQ_FLAGS_2, 0b11111111); } + +#endif diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index fa8362a5..b82f607d 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_RF69_H +#if !defined(_RADIOLIB_RF69_H) && !defined(RADIOLIB_EXCLUDE_RF69) #define _RADIOLIB_RF69_H #include "../../TypeDef.h" From e6657cf2f013b0c317f7eab372df69763fa276fa Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:43:00 +0200 Subject: [PATCH 188/334] [RFM2x] Reworked driver exclusion --- src/modules/RFM2x/RFM22.h | 2 +- src/modules/RFM2x/RFM23.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/RFM2x/RFM22.h b/src/modules/RFM2x/RFM22.h index e3cd4a4d..bfad6cd7 100644 --- a/src/modules/RFM2x/RFM22.h +++ b/src/modules/RFM2x/RFM22.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_RFM22_H +#if !defined(_RADIOLIB_RFM22_H) && !defined(RADIOLIB_EXCLUDE_SI443X) #define _RADIOLIB_RFM22_H #include "../../TypeDef.h" diff --git a/src/modules/RFM2x/RFM23.h b/src/modules/RFM2x/RFM23.h index 4f72557d..506c3482 100644 --- a/src/modules/RFM2x/RFM23.h +++ b/src/modules/RFM2x/RFM23.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_RFM23_H +#if !defined(_RADIOLIB_RFM23_H) && !defined(RADIOLIB_EXCLUDE_SI443X) #define _RADIOLIB_RFM23_H #include "../../TypeDef.h" From 04ea05c7ec30da4b05614a77ae3152724a52dd52 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:43:14 +0200 Subject: [PATCH 189/334] [RFM9x] Reworked driver exclusion --- src/modules/RFM9x/RFM95.cpp | 3 +++ src/modules/RFM9x/RFM95.h | 2 +- src/modules/RFM9x/RFM96.cpp | 3 +++ src/modules/RFM9x/RFM96.h | 2 +- src/modules/RFM9x/RFM97.cpp | 3 +++ src/modules/RFM9x/RFM97.h | 2 +- 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp index 53f1eb7c..80db42a6 100644 --- a/src/modules/RFM9x/RFM95.cpp +++ b/src/modules/RFM9x/RFM95.cpp @@ -1,4 +1,5 @@ #include "RFM95.h" +#if !defined(RADIOLIB_EXCLUDE_RFM9X) RFM95::RFM95(Module* mod) : SX1278(mod) { @@ -47,3 +48,5 @@ int16_t RFM95::setFrequency(float freq) { // set frequency return(SX127x::setFrequencyRaw(freq)); } + +#endif diff --git a/src/modules/RFM9x/RFM95.h b/src/modules/RFM9x/RFM95.h index fcbcf67d..914ccad9 100644 --- a/src/modules/RFM9x/RFM95.h +++ b/src/modules/RFM9x/RFM95.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_RFM95_H +#if !defined(_RADIOLIB_RFM95_H) && !defined(RADIOLIB_EXCLUDE_RFM9X) #define _RADIOLIB_RFM95_H #include "../../TypeDef.h" diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp index 159c4995..5ca6f594 100644 --- a/src/modules/RFM9x/RFM96.cpp +++ b/src/modules/RFM9x/RFM96.cpp @@ -1,4 +1,5 @@ #include "RFM96.h" +#if !defined(RADIOLIB_EXCLUDE_RFM9X) RFM96::RFM96(Module* mod) : SX1278(mod) { @@ -47,3 +48,5 @@ int16_t RFM96::setFrequency(float freq) { // set frequency return(SX127x::setFrequencyRaw(freq)); } + +#endif diff --git a/src/modules/RFM9x/RFM96.h b/src/modules/RFM9x/RFM96.h index 74b6d382..985fcf74 100644 --- a/src/modules/RFM9x/RFM96.h +++ b/src/modules/RFM9x/RFM96.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_RFM96_H +#if !defined(_RADIOLIB_RFM96_H) && !defined(RADIOLIB_EXCLUDE_RFM9X) #define _RADIOLIB_RFM96_H #include "../../TypeDef.h" diff --git a/src/modules/RFM9x/RFM97.cpp b/src/modules/RFM9x/RFM97.cpp index 102fecf9..ccf19134 100644 --- a/src/modules/RFM9x/RFM97.cpp +++ b/src/modules/RFM9x/RFM97.cpp @@ -1,4 +1,5 @@ #include "RFM97.h" +#if !defined(RADIOLIB_EXCLUDE_RFM9X) RFM97::RFM97(Module* mod) : RFM95(mod) { @@ -37,3 +38,5 @@ int16_t RFM97::setSpreadingFactor(uint8_t sf) { } return(state); } + +#endif diff --git a/src/modules/RFM9x/RFM97.h b/src/modules/RFM9x/RFM97.h index b5dcbbdf..90e59e42 100644 --- a/src/modules/RFM9x/RFM97.h +++ b/src/modules/RFM9x/RFM97.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_RFM97_H +#if !defined(_RADIOLIB_RFM97_H) && !defined(RADIOLIB_EXCLUDE_RFM9X) #define _RADIOLIB_RFM97_H #include "../../TypeDef.h" From 893d8a905f208797861d841168490f19a5ec47d8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:43:26 +0200 Subject: [PATCH 190/334] [SX1231] Reworked driver exclusion --- src/modules/SX1231/SX1231.cpp | 3 +++ src/modules/SX1231/SX1231.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/SX1231/SX1231.cpp b/src/modules/SX1231/SX1231.cpp index f42c584e..53981685 100644 --- a/src/modules/SX1231/SX1231.cpp +++ b/src/modules/SX1231/SX1231.cpp @@ -1,4 +1,5 @@ #include "SX1231.h" +#if !defined(RADIOLIB_EXCLUDE_RF69) SX1231::SX1231(Module* mod) : RF69(mod) { @@ -92,3 +93,5 @@ int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po return(ERR_NONE); } + +#endif diff --git a/src/modules/SX1231/SX1231.h b/src/modules/SX1231/SX1231.h index d048fd02..0761fa8e 100644 --- a/src/modules/SX1231/SX1231.h +++ b/src/modules/SX1231/SX1231.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1231_H +#if !defined(_RADIOLIB_SX1231_H) && !defined(RADIOLIB_EXCLUDE_RF69) #define _RADIOLIB_SX1231_H #include "../../TypeDef.h" From 58ddfb8b51772214c4a59c41aa0a81df119832f4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:43:41 +0200 Subject: [PATCH 191/334] [SX126x] Reworked driver exclusion --- src/modules/SX126x/SX1261.cpp | 3 +++ src/modules/SX126x/SX1261.h | 2 +- src/modules/SX126x/SX1262.cpp | 3 +++ src/modules/SX126x/SX1262.h | 2 +- src/modules/SX126x/SX1268.cpp | 3 +++ src/modules/SX126x/SX1268.h | 2 +- src/modules/SX126x/SX126x.cpp | 3 +++ src/modules/SX126x/SX126x.h | 2 +- 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/modules/SX126x/SX1261.cpp b/src/modules/SX126x/SX1261.cpp index a78d2578..b0b626c2 100644 --- a/src/modules/SX126x/SX1261.cpp +++ b/src/modules/SX126x/SX1261.cpp @@ -1,4 +1,5 @@ #include "SX1261.h" +#if !defined(RADIOLIB_EXCLUDE_SX126X) SX1261::SX1261(Module* mod): SX1262(mod) { @@ -24,3 +25,5 @@ int16_t SX1261::setOutputPower(int8_t power) { // restore OCP configuration return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); } + +#endif diff --git a/src/modules/SX126x/SX1261.h b/src/modules/SX126x/SX1261.h index 2dca7ed1..5b6f9ef6 100644 --- a/src/modules/SX126x/SX1261.h +++ b/src/modules/SX126x/SX1261.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1261_H +#if !defined(_RADIOLIB_SX1261_H) && !defined(RADIOLIB_EXCLUDE_SX126X) #define _RADIOLIB_SX1261_H #include "../../TypeDef.h" diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 7d1f6efe..1ce049af 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -1,4 +1,5 @@ #include "SX1262.h" +#if !defined(RADIOLIB_EXCLUDE_SX126X) SX1262::SX1262(Module* mod) : SX126x(mod) { @@ -90,3 +91,5 @@ int16_t SX1262::setOutputPower(int8_t power) { // restore OCP configuration return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); } + +#endif diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index e33f568b..b268759b 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1262_H +#if !defined(_RADIOLIB_SX1262_H) && !defined(RADIOLIB_EXCLUDE_SX126X) #define _RADIOLIB_SX1262_H #include "../../TypeDef.h" diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index 6b7f3ad2..04cd370f 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -1,4 +1,5 @@ #include "SX1268.h" +#if !defined(RADIOLIB_EXCLUDE_SX126X) SX1268::SX1268(Module* mod) : SX126x(mod) { @@ -83,3 +84,5 @@ int16_t SX1268::setOutputPower(int8_t power) { // restore OCP configuration return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); } + +#endif diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index 5b203b72..76f01c1e 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1268_H +#if !defined(_RADIOLIB_SX1268_H) && !defined(RADIOLIB_EXCLUDE_SX126X) #define _RADIOLIB_SX1268_H #include "../../TypeDef.h" diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 3a8aecaa..900a835c 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -1,4 +1,5 @@ #include "SX126x.h" +#if !defined(RADIOLIB_EXCLUDE_SX126X) SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_FREQUENCY_STEP_SIZE, SX126X_MAX_PACKET_LENGTH) { _mod = mod; @@ -1677,3 +1678,5 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d return(ERR_NONE); } } + +#endif diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index ae2216d6..26881c8c 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX126X_H +#if !defined(_RADIOLIB_SX126X_H) && !defined(RADIOLIB_EXCLUDE_SX126X) #define _RADIOLIB_SX126X_H #include "../../TypeDef.h" From 3dd3a471e50b942ed25ae83dcd2d31743a1c90ec Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:43:56 +0200 Subject: [PATCH 192/334] [SX127x] Reworked driver exclusion --- src/modules/SX127x/SX1272.cpp | 3 +++ src/modules/SX127x/SX1272.h | 4 ++-- src/modules/SX127x/SX1273.cpp | 3 +++ src/modules/SX127x/SX1273.h | 2 +- src/modules/SX127x/SX1276.cpp | 3 +++ src/modules/SX127x/SX1276.h | 2 +- src/modules/SX127x/SX1277.cpp | 3 +++ src/modules/SX127x/SX1277.h | 2 +- src/modules/SX127x/SX1278.cpp | 3 +++ src/modules/SX127x/SX1278.h | 4 ++-- src/modules/SX127x/SX1279.cpp | 3 +++ src/modules/SX127x/SX1279.h | 2 +- src/modules/SX127x/SX127x.cpp | 24 +----------------------- src/modules/SX127x/SX127x.h | 6 +----- 14 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 28fedba3..b37cf75e 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -1,4 +1,5 @@ #include "SX1272.h" +#if !defined(RADIOLIB_EXCLUDE_SX127X) SX1272::SX1272(Module* mod) : SX127x(mod) { @@ -417,3 +418,5 @@ int16_t SX1272::configFSK() { return(state); } + +#endif diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index a0f64541..547f2905 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1272_H +#if !defined(_RADIOLIB_SX1272_H) && !defined(RADIOLIB_EXCLUDE_SX127X) #define _RADIOLIB_SX1272_H #include "../../TypeDef.h" @@ -155,7 +155,7 @@ class SX1272: public SX127x { \returns \ref status_codes */ int16_t beginFSK(float freq = 915.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13, uint8_t currentLimit = 100, uint16_t preambleLength = 16, bool enableOOK = false); - + /*! \brief Reset method. Will reset the chip to the default state using RST pin. */ diff --git a/src/modules/SX127x/SX1273.cpp b/src/modules/SX127x/SX1273.cpp index ee0a48fc..b45ca0e5 100644 --- a/src/modules/SX127x/SX1273.cpp +++ b/src/modules/SX127x/SX1273.cpp @@ -1,4 +1,5 @@ #include "SX1273.h" +#if !defined(RADIOLIB_EXCLUDE_SX127X) SX1273::SX1273(Module* mod) : SX1272(mod) { @@ -68,3 +69,5 @@ int16_t SX1273::setSpreadingFactor(uint8_t sf) { return(state); } + +#endif diff --git a/src/modules/SX127x/SX1273.h b/src/modules/SX127x/SX1273.h index 52ffafd1..ac7fcd98 100644 --- a/src/modules/SX127x/SX1273.h +++ b/src/modules/SX127x/SX1273.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1273_H +#if !defined(_RADIOLIB_SX1273_H) && !defined(RADIOLIB_EXCLUDE_SX127X) #define _RADIOLIB_SX1273_H #include "../../TypeDef.h" diff --git a/src/modules/SX127x/SX1276.cpp b/src/modules/SX127x/SX1276.cpp index 2fecd63a..66510443 100644 --- a/src/modules/SX127x/SX1276.cpp +++ b/src/modules/SX127x/SX1276.cpp @@ -1,4 +1,5 @@ #include "SX1276.h" +#if !defined(RADIOLIB_EXCLUDE_SX127X) SX1276::SX1276(Module* mod) : SX1278(mod) { @@ -103,3 +104,5 @@ int16_t SX1276::setFrequency(float freq) { // set frequency return(SX127x::setFrequencyRaw(freq)); } + +#endif diff --git a/src/modules/SX127x/SX1276.h b/src/modules/SX127x/SX1276.h index 8a320ec8..55861cc3 100644 --- a/src/modules/SX127x/SX1276.h +++ b/src/modules/SX127x/SX1276.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1276_H +#if !defined(_RADIOLIB_SX1276_H) && !defined(RADIOLIB_EXCLUDE_SX127X) #define _RADIOLIB_SX1276_H #include "../../TypeDef.h" diff --git a/src/modules/SX127x/SX1277.cpp b/src/modules/SX127x/SX1277.cpp index 715d8853..fe187055 100644 --- a/src/modules/SX127x/SX1277.cpp +++ b/src/modules/SX127x/SX1277.cpp @@ -1,4 +1,5 @@ #include "SX1277.h" +#if !defined(RADIOLIB_EXCLUDE_SX127X) SX1277::SX1277(Module* mod) : SX1278(mod) { @@ -133,3 +134,5 @@ int16_t SX1277::setSpreadingFactor(uint8_t sf) { return(state); } + +#endif diff --git a/src/modules/SX127x/SX1277.h b/src/modules/SX127x/SX1277.h index cee312a3..afbfdc1f 100644 --- a/src/modules/SX127x/SX1277.h +++ b/src/modules/SX127x/SX1277.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1277_H +#if !defined(_RADIOLIB_SX1277_H) && !defined(RADIOLIB_EXCLUDE_SX127X) #define _RADIOLIB_SX1277_H #include "../../TypeDef.h" diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index af3fc0b3..698634f8 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -1,4 +1,5 @@ #include "SX1278.h" +#if !defined(RADIOLIB_EXCLUDE_SX127X) SX1278::SX1278(Module* mod) : SX127x(mod) { @@ -495,3 +496,5 @@ int16_t SX1278::configFSK() { return(state); } + +#endif diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index 77318e15..e2c5220a 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1278_H +#if !defined(_RADIOLIB_SX1278_H) && !defined(RADIOLIB_EXCLUDE_SX127X) #define _RADIOLIB_SX1278_H #include "../../TypeDef.h" @@ -169,7 +169,7 @@ class SX1278: public SX127x { \brief Reset method. Will reset the chip to the default state using RST pin. */ void reset(); - + // configuration methods /*! diff --git a/src/modules/SX127x/SX1279.cpp b/src/modules/SX127x/SX1279.cpp index 1b45c9b7..9d5562e5 100644 --- a/src/modules/SX127x/SX1279.cpp +++ b/src/modules/SX127x/SX1279.cpp @@ -1,4 +1,5 @@ #include "SX1279.h" +#if !defined(RADIOLIB_EXCLUDE_SX127X) SX1279::SX1279(Module* mod) : SX1278(mod) { @@ -40,3 +41,5 @@ int16_t SX1279::setFrequency(float freq) { // set frequency return(SX127x::setFrequencyRaw(freq)); } + +#endif diff --git a/src/modules/SX127x/SX1279.h b/src/modules/SX127x/SX1279.h index f0953ecd..9908b3eb 100644 --- a/src/modules/SX127x/SX1279.h +++ b/src/modules/SX127x/SX1279.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1279_H +#if !defined(_RADIOLIB_SX1279_H) && !defined(RADIOLIB_EXCLUDE_SX127X) #define _RADIOLIB_SX1279_H #include "../../TypeDef.h" diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 45fe5f01..c3d2dd7e 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -1,4 +1,5 @@ #include "SX127x.h" +#if !defined(RADIOLIB_EXCLUDE_SX127X) SX127x::SX127x(Module* mod) : PhysicalLayer(SX127X_FREQUENCY_STEP_SIZE, SX127X_MAX_PACKET_LENGTH) { _mod = mod; @@ -1134,27 +1135,4 @@ void SX127x::clearFIFO(size_t count) { } } -#ifdef RADIOLIB_DEBUG -void SX127x::regDump() { - RADIOLIB_DEBUG_PRINTLN(); - RADIOLIB_DEBUG_PRINTLN(F("ADDR\tVALUE")); - for(uint16_t addr = 0x01; addr <= 0x70; addr++) { - if(addr <= 0x0F) { - RADIOLIB_DEBUG_PRINT(F("0x0")); - } else { - RADIOLIB_DEBUG_PRINT(F("0x")); - } - RADIOLIB_DEBUG_PRINT(addr, HEX); - RADIOLIB_DEBUG_PRINT('\t'); - uint8_t val = _mod->SPIreadRegister(addr); - if(val <= 0x0F) { - RADIOLIB_DEBUG_PRINT(F("0x0")); - } else { - RADIOLIB_DEBUG_PRINT(F("0x")); - } - RADIOLIB_DEBUG_PRINTLN(val, HEX); - - delay(50); - } -} #endif diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 7f075e9b..0023e4d8 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX127X_H +#if !defined(_RADIOLIB_SX127X_H) && !defined(RADIOLIB_EXCLUDE_SX127X) #define _RADIOLIB_SX127X_H #include "../../TypeDef.h" @@ -931,10 +931,6 @@ class SX127x: public PhysicalLayer { */ void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); - #ifdef RADIOLIB_DEBUG - void regDump(); - #endif - #ifndef RADIOLIB_GODMODE protected: #endif From 515551e7bc1e8f4163bb195156c761d1f5087d7a Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:44:08 +0200 Subject: [PATCH 193/334] [SX128x] Reworked driver exclusion --- src/modules/SX128x/SX1280.cpp | 3 +++ src/modules/SX128x/SX1280.h | 2 +- src/modules/SX128x/SX1281.cpp | 3 +++ src/modules/SX128x/SX1281.h | 2 +- src/modules/SX128x/SX1282.cpp | 3 +++ src/modules/SX128x/SX1282.h | 2 +- src/modules/SX128x/SX128x.cpp | 3 +++ src/modules/SX128x/SX128x.h | 2 +- 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/modules/SX128x/SX1280.cpp b/src/modules/SX128x/SX1280.cpp index 2c4d09ee..b0d513ef 100644 --- a/src/modules/SX128x/SX1280.cpp +++ b/src/modules/SX128x/SX1280.cpp @@ -1,4 +1,5 @@ #include "SX1280.h" +#if !defined(RADIOLIB_EXCLUDE_SX128X) SX1280::SX1280(Module* mod) : SX1281(mod) { @@ -111,3 +112,5 @@ float SX1280::getRangingResult() { memcpy(&raw, data, sizeof(uint32_t)); return((float)raw * (150.0/(4.096 * _bwKhz))); } + +#endif diff --git a/src/modules/SX128x/SX1280.h b/src/modules/SX128x/SX1280.h index ea8c5a18..4c079ac4 100644 --- a/src/modules/SX128x/SX1280.h +++ b/src/modules/SX128x/SX1280.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1280_H +#if !defined(_RADIOLIB_SX1280_H) && !defined(RADIOLIB_EXCLUDE_SX128X) #define _RADIOLIB_SX1280_H #include "../../TypeDef.h" diff --git a/src/modules/SX128x/SX1281.cpp b/src/modules/SX128x/SX1281.cpp index 4aa09b0d..c6b2b5eb 100644 --- a/src/modules/SX128x/SX1281.cpp +++ b/src/modules/SX128x/SX1281.cpp @@ -1,5 +1,8 @@ #include "SX1281.h" +#if !defined(RADIOLIB_EXCLUDE_SX128X) SX1281::SX1281(Module* mod) : SX128x(mod) { } + +#endif diff --git a/src/modules/SX128x/SX1281.h b/src/modules/SX128x/SX1281.h index 88037a09..6cb85192 100644 --- a/src/modules/SX128x/SX1281.h +++ b/src/modules/SX128x/SX1281.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1281_H +#if !defined(_RADIOLIB_SX1281_H) && !defined(RADIOLIB_EXCLUDE_SX128X) #define _RADIOLIB_SX1281_H #include "../../TypeDef.h" diff --git a/src/modules/SX128x/SX1282.cpp b/src/modules/SX128x/SX1282.cpp index 847a36d1..2a77ffcd 100644 --- a/src/modules/SX128x/SX1282.cpp +++ b/src/modules/SX128x/SX1282.cpp @@ -1,5 +1,8 @@ #include "SX1282.h" +#if !defined(RADIOLIB_EXCLUDE_SX128X) SX1282::SX1282(Module* mod) : SX1280(mod) { } + +#endif diff --git a/src/modules/SX128x/SX1282.h b/src/modules/SX128x/SX1282.h index 09f92075..8b677d95 100644 --- a/src/modules/SX128x/SX1282.h +++ b/src/modules/SX128x/SX1282.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX1282_H +#if !defined(_RADIOLIB_SX1282_H) && !defined(RADIOLIB_EXCLUDE_SX128X) #define _RADIOLIB_SX1282_H #include "../../TypeDef.h" diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 112417f5..1dda7d8c 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -1,4 +1,5 @@ #include "SX128x.h" +#if !defined(RADIOLIB_EXCLUDE_SX128X) SX128x::SX128x(Module* mod) : PhysicalLayer(SX128X_FREQUENCY_STEP_SIZE, SX128X_MAX_PACKET_LENGTH) { _mod = mod; @@ -1431,3 +1432,5 @@ int16_t SX128x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d return(ERR_NONE); } } + +#endif diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 755bc443..bd403a29 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SX128X_H +#if !defined(_RADIOLIB_SX128X_H) && !defined(RADIOLIB_EXCLUDE_SX128X) #define _RADIOLIB_SX128X_H #include "../../TypeDef.h" From f05f1e9d82a4f9020ecabd91ad7e64ac584bda34 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:44:22 +0200 Subject: [PATCH 194/334] [Si443x] Reworked driver exclusion --- src/modules/Si443x/Si4430.cpp | 3 +++ src/modules/Si443x/Si4430.h | 2 +- src/modules/Si443x/Si4431.cpp | 3 +++ src/modules/Si443x/Si4431.h | 2 +- src/modules/Si443x/Si4432.cpp | 3 +++ src/modules/Si443x/Si4432.h | 2 +- src/modules/Si443x/Si443x.cpp | 3 +++ src/modules/Si443x/Si443x.h | 2 +- 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/modules/Si443x/Si4430.cpp b/src/modules/Si443x/Si4430.cpp index c59f1ea7..3f31370c 100644 --- a/src/modules/Si443x/Si4430.cpp +++ b/src/modules/Si443x/Si4430.cpp @@ -1,4 +1,5 @@ #include "Si4430.h" +#if !defined(RADIOLIB_EXCLUDE_SI443X) Si4430::Si4430(Module* mod) : Si4432(mod) { @@ -32,3 +33,5 @@ int16_t Si4430::setOutputPower(int8_t power) { // set output power return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0)); } + +#endif diff --git a/src/modules/Si443x/Si4430.h b/src/modules/Si443x/Si4430.h index 7e7f8b36..815ec7ad 100644 --- a/src/modules/Si443x/Si4430.h +++ b/src/modules/Si443x/Si4430.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SI4430_H +#if !defined(_RADIOLIB_SI4430_H) && !defined(RADIOLIB_EXCLUDE_SI443X) #define _RADIOLIB_SI4430_H #include "../../TypeDef.h" diff --git a/src/modules/Si443x/Si4431.cpp b/src/modules/Si443x/Si4431.cpp index 25c7baf9..54371858 100644 --- a/src/modules/Si443x/Si4431.cpp +++ b/src/modules/Si443x/Si4431.cpp @@ -1,4 +1,5 @@ #include "Si4431.h" +#if !defined(RADIOLIB_EXCLUDE_SI443X) Si4431::Si4431(Module* mod) : Si4432(mod) { @@ -25,3 +26,5 @@ int16_t Si4431::setOutputPower(int8_t power) { // set output power return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0)); } + +#endif diff --git a/src/modules/Si443x/Si4431.h b/src/modules/Si443x/Si4431.h index c033bcbd..5f8b3821 100644 --- a/src/modules/Si443x/Si4431.h +++ b/src/modules/Si443x/Si4431.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SI4431_H +#if !defined(_RADIOLIB_SI4431_H) && !defined(RADIOLIB_EXCLUDE_SI443X) #define _RADIOLIB_SI4431_H #include "../../TypeDef.h" diff --git a/src/modules/Si443x/Si4432.cpp b/src/modules/Si443x/Si4432.cpp index 38d42863..0c9dee43 100644 --- a/src/modules/Si443x/Si4432.cpp +++ b/src/modules/Si443x/Si4432.cpp @@ -1,4 +1,5 @@ #include "Si4432.h" +#if !defined(RADIOLIB_EXCLUDE_SI443X) Si4432::Si4432(Module* mod) : Si443x(mod) { @@ -32,3 +33,5 @@ int16_t Si4432::setOutputPower(int8_t power) { // set output power return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 1) / 3), 2, 0)); } + +#endif diff --git a/src/modules/Si443x/Si4432.h b/src/modules/Si443x/Si4432.h index 01dd92c5..4b1d0af6 100644 --- a/src/modules/Si443x/Si4432.h +++ b/src/modules/Si443x/Si4432.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SI4432_H +#if !defined(_RADIOLIB_SI4432_H) && !defined(RADIOLIB_EXCLUDE_SI443X) #define _RADIOLIB_SI4432_H #include "../../TypeDef.h" diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 099fb866..45734b3a 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -1,4 +1,5 @@ #include "Si443x.h" +#if !defined(RADIOLIB_EXCLUDE_SI443X) Si443x::Si443x(Module* mod) : PhysicalLayer(SI443X_FREQUENCY_STEP_SIZE, SI443X_MAX_PACKET_LENGTH) { _mod = mod; @@ -689,3 +690,5 @@ int16_t Si443x::directMode() { state = _mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_MODULATION_NONE, 1, 0); return(state); } + +#endif diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h index 1cfd2700..7fbe26b6 100644 --- a/src/modules/Si443x/Si443x.h +++ b/src/modules/Si443x/Si443x.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SI443X_H +#if !defined(_RADIOLIB_SI443X_H) && !defined(RADIOLIB_EXCLUDE_SI443X) #define _RADIOLIB_SI443X_H #include "../../TypeDef.h" From 78c1f94233cd2b54d89f4195f32de879cc93abe5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:44:33 +0200 Subject: [PATCH 195/334] [XBee] Reworked driver exclusion --- src/modules/XBee/XBee.cpp | 3 +++ src/modules/XBee/XBee.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/XBee/XBee.cpp b/src/modules/XBee/XBee.cpp index 4bfcab40..919de28e 100644 --- a/src/modules/XBee/XBee.cpp +++ b/src/modules/XBee/XBee.cpp @@ -1,4 +1,5 @@ #include "XBee.h" +#if !defined(RADIOLIB_EXCLUDE_XBEE) XBee::XBee(Module* mod) { _mod = mod; @@ -481,3 +482,5 @@ uint16_t XBee::getNumBytes(uint32_t timeout, size_t minBytes) { return((resp[1] << 8) | resp[2]); } + +#endif diff --git a/src/modules/XBee/XBee.h b/src/modules/XBee/XBee.h index 1cb9607a..e9c970b2 100644 --- a/src/modules/XBee/XBee.h +++ b/src/modules/XBee/XBee.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_XBEE_H +#if !defined(_RADIOLIB_XBEE_H) && !defined(RADIOLIB_EXCLUDE_XBEE) #define _RADIOLIB_XBEE_H #include "../../ISerial.h" From 0e120a760a32a3f8f46fbc534af40c7c2878457b Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:44:41 +0200 Subject: [PATCH 196/334] [nRF24] Reworked driver exclusion --- src/modules/nRF24/nRF24.cpp | 3 +++ src/modules/nRF24/nRF24.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 73d25ee6..888b959f 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -1,4 +1,5 @@ #include "nRF24.h" +#if !defined(RADIOLIB_EXCLUDE_NRF24) nRF24::nRF24(Module* mod) : PhysicalLayer(NRF24_FREQUENCY_STEP_SIZE, NRF24_MAX_PACKET_LENGTH) { _mod = mod; @@ -568,3 +569,5 @@ void nRF24::SPItransfer(uint8_t cmd, bool write, uint8_t* dataOut, uint8_t* data spi->endTransaction(); digitalWrite(_mod->getCs(), HIGH); } + +#endif diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index a3205f78..55802bbe 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_NRF24_H +#if !defined(_RADIOLIB_NRF24_H) && !defined(RADIOLIB_EXCLUDE_NRF24) #define _RADIOLIB_NRF24_H #include "../../Module.h" From 6f6ff7d6371fa803c1203de98646ac89bb68b3e7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:44:48 +0200 Subject: [PATCH 197/334] [AFSK] Reworked driver exclusion --- src/protocols/AFSK/AFSK.cpp | 3 +++ src/protocols/AFSK/AFSK.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/protocols/AFSK/AFSK.cpp b/src/protocols/AFSK/AFSK.cpp index e2a90641..6cf64ac9 100644 --- a/src/protocols/AFSK/AFSK.cpp +++ b/src/protocols/AFSK/AFSK.cpp @@ -1,4 +1,5 @@ #include "AFSK.h" +#if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin) { _phy = phy; @@ -23,3 +24,5 @@ int16_t AFSKClient::noTone() { Module::noTone(_pin); return(_phy->standby()); } + +#endif diff --git a/src/protocols/AFSK/AFSK.h b/src/protocols/AFSK/AFSK.h index c5c71221..c487dd17 100644 --- a/src/protocols/AFSK/AFSK.h +++ b/src/protocols/AFSK/AFSK.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_AFSK_H +#if !defined(_RADIOLIB_AFSK_H) && !defined(RADIOLIB_EXCLUDE_AFSK) #define _RADIOLIB_AFSK_H #include "../../TypeDef.h" From 55ebbc348802618b1450928d7751d4718d2ccdca Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:45:00 +0200 Subject: [PATCH 198/334] [AX25] Reworked driver exclusion --- src/protocols/AX25/AX25.cpp | 5 +++++ src/protocols/AX25/AX25.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index 1693cbe7..579ed8f1 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -1,4 +1,5 @@ #include "AX25.h" +#if !defined(RADIOLIB_EXCLUDE_AX25) AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control) : AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, 0, NULL, 0) { @@ -115,10 +116,12 @@ AX25Client::AX25Client(PhysicalLayer* phy) { _audio = nullptr; } +#if !defined(RADIOLIB_EXCLUDE_AFSK) AX25Client::AX25Client(AFSKClient* audio) { _phy = audio->_phy; _audio = audio; } +#endif int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preambleLen) { // set source SSID @@ -414,3 +417,5 @@ uint16_t AX25Client::flipBits16(uint16_t i) { i = (i & 0xAAAA) >> 1 | (i & 0x5555) << 1; return i; } + +#endif diff --git a/src/protocols/AX25/AX25.h b/src/protocols/AX25/AX25.h index dc385dfa..c751a7c1 100644 --- a/src/protocols/AX25/AX25.h +++ b/src/protocols/AX25/AX25.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_AX25_H +#if !defined(_RADIOLIB_AX25_H) && !defined(RADIOLIB_EXCLUDE_AX25) #define _RADIOLIB_AX25_H #include "../../TypeDef.h" @@ -268,12 +268,14 @@ class AX25Client { */ AX25Client(PhysicalLayer* phy); + #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! \brief Constructor for AFSK mode. \param audio Pointer to the AFSK instance providing audio. */ AX25Client(AFSKClient* audio); + #endif // basic methods @@ -316,7 +318,11 @@ class AX25Client { private: #endif PhysicalLayer* _phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; + #else + void* _audio; + #endif char _srcCallsign[AX25_MAX_CALLSIGN_LEN + 1]; uint8_t _srcSSID; From fc21a1d50192f32fd7d6d9cb05e7d5e333cb3142 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:45:11 +0200 Subject: [PATCH 199/334] [HTTP] Reworked driver exclusion --- src/protocols/HTTP/HTTP.cpp | 3 +++ src/protocols/HTTP/HTTP.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/protocols/HTTP/HTTP.cpp b/src/protocols/HTTP/HTTP.cpp index 00b046d2..6f4cd23d 100644 --- a/src/protocols/HTTP/HTTP.cpp +++ b/src/protocols/HTTP/HTTP.cpp @@ -1,4 +1,5 @@ #include "HTTP.h" +#if !defined(RADIOLIB_EXCLUDE_HTTP) HTTPClient::HTTPClient(TransportLayer* tl, uint16_t port) { _tl = tl; @@ -216,3 +217,5 @@ int16_t HTTPClient::post(const char* url, const char* content, String& response, statusStr[3] = 0x00; return(atoi(statusStr)); } + +#endif diff --git a/src/protocols/HTTP/HTTP.h b/src/protocols/HTTP/HTTP.h index 118df7ec..edc7d6f1 100644 --- a/src/protocols/HTTP/HTTP.h +++ b/src/protocols/HTTP/HTTP.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_HTTP_H +#if !defined(_RADIOLIB_HTTP_H) && !defined(RADIOLIB_EXCLUDE_HTTP) #define _RADIOLIB_HTTP_H #include "../../TypeDef.h" From d032015e318a3b54ea14de41a151f7b2f45b81d2 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:45:28 +0200 Subject: [PATCH 200/334] [Hell] Reworked driver exclusion --- src/protocols/Hellschreiber/Hellschreiber.cpp | 5 +++++ src/protocols/Hellschreiber/Hellschreiber.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/protocols/Hellschreiber/Hellschreiber.cpp b/src/protocols/Hellschreiber/Hellschreiber.cpp index 3f769add..5c6483b3 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.cpp +++ b/src/protocols/Hellschreiber/Hellschreiber.cpp @@ -1,14 +1,17 @@ #include "Hellschreiber.h" +#if !defined(RADIOLIB_EXCLUDE_HELLSCHREIBER) HellClient::HellClient(PhysicalLayer* phy) { _phy = phy; _audio = nullptr; } +#if !defined(RADIOLIB_EXCLUDE_AFSK) HellClient::HellClient(AFSKClient* audio) { _phy = audio->_phy; _audio = audio; } +#endif int16_t HellClient::begin(float base, float rate) { // calculate 24-bit frequency @@ -295,3 +298,5 @@ int16_t HellClient::standby() { return(_phy->standby()); } } + +#endif diff --git a/src/protocols/Hellschreiber/Hellschreiber.h b/src/protocols/Hellschreiber/Hellschreiber.h index 8756df5f..a70e74e7 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.h +++ b/src/protocols/Hellschreiber/Hellschreiber.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_HELLSCHREIBER_H +#if !defined(_RADIOLIB_HELLSCHREIBER_H) && !defined(RADIOLIB_EXCLUDE_HELLSCHREIBER) #define _RADIOLIB_HELLSCHREIBER_H #include "../../TypeDef.h" @@ -92,12 +92,14 @@ class HellClient { */ HellClient(PhysicalLayer* phy); + #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! \brief Constructor for AFSK mode. \param audio Pointer to the AFSK instance providing audio. */ HellClient(AFSKClient* audio); + #endif // basic methods @@ -148,7 +150,11 @@ class HellClient { private: #endif PhysicalLayer* _phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; + #else + void* _audio; + #endif uint32_t _base, _baseHz; uint32_t _pixelDuration; From 7a22cbfd4d13cab230d7f8d90547b6db75df837a Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:45:35 +0200 Subject: [PATCH 201/334] [MQTT] Reworked driver exclusion --- src/protocols/MQTT/MQTT.cpp | 3 +++ src/protocols/MQTT/MQTT.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/protocols/MQTT/MQTT.cpp b/src/protocols/MQTT/MQTT.cpp index 92583cbb..cc561157 100644 --- a/src/protocols/MQTT/MQTT.cpp +++ b/src/protocols/MQTT/MQTT.cpp @@ -1,4 +1,5 @@ #include "MQTT.h" +#if !defined(RADIOLIB_EXCLUDE_MQTT) MQTTClient::MQTTClient(TransportLayer* tl, uint16_t port) { _tl = tl; @@ -469,3 +470,5 @@ uint32_t MQTTClient::decodeLength(uint8_t* encoded) { } while((encoded[i] & 128) != 0); return len; } + +#endif diff --git a/src/protocols/MQTT/MQTT.h b/src/protocols/MQTT/MQTT.h index b7a94bdb..efc40d3a 100644 --- a/src/protocols/MQTT/MQTT.h +++ b/src/protocols/MQTT/MQTT.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_MQTT_H +#if !defined(_RADIOLIB_MQTT_H) && !defined(RADIOLIB_EXCLUDE_MQTT) #define _RADIOLIB_MQTT_H #include "../../TypeDef.h" From e5437deae2fc91368d849b76b514e728ac34398f Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:45:45 +0200 Subject: [PATCH 202/334] [Morse] Reworked driver exclusion --- src/protocols/Morse/Morse.cpp | 5 +++++ src/protocols/Morse/Morse.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/protocols/Morse/Morse.cpp b/src/protocols/Morse/Morse.cpp index fe516132..bd336229 100644 --- a/src/protocols/Morse/Morse.cpp +++ b/src/protocols/Morse/Morse.cpp @@ -1,14 +1,17 @@ #include "Morse.h" +#if !defined(RADIOLIB_EXCLUDE_MORSE) MorseClient::MorseClient(PhysicalLayer* phy) { _phy = phy; _audio = nullptr; } +#if !defined(RADIOLIB_EXCLUDE_AFSK) MorseClient::MorseClient(AFSKClient* audio) { _phy = audio->_phy; _audio = audio; } +#endif int16_t MorseClient::begin(float base, uint8_t speed) { // calculate 24-bit frequency @@ -309,3 +312,5 @@ int16_t MorseClient::standby() { return(_phy->standby()); } } + +#endif diff --git a/src/protocols/Morse/Morse.h b/src/protocols/Morse/Morse.h index e09fece0..276a443b 100644 --- a/src/protocols/Morse/Morse.h +++ b/src/protocols/Morse/Morse.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_MORSE_H +#if !defined(_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE) #define _RADIOLIB_MORSE_H #include "../../TypeDef.h" @@ -95,12 +95,14 @@ class MorseClient { */ MorseClient(PhysicalLayer* phy); + #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! \brief Constructor for AFSK mode. \param audio Pointer to the AFSK instance providing audio. */ MorseClient(AFSKClient* audio); + #endif // basic methods @@ -153,7 +155,11 @@ class MorseClient { private: #endif PhysicalLayer* _phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; + #else + void* _audio; + #endif uint32_t _base, _baseHz; uint16_t _dotLength; From 80fa8ba99d7a26c1679f03a541a8e02ceda0ad63 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:45:52 +0200 Subject: [PATCH 203/334] [RTTY] Reworked driver exclusion --- src/protocols/RTTY/RTTY.cpp | 5 +++++ src/protocols/RTTY/RTTY.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index 1a96d5e2..7b023f8e 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -1,4 +1,5 @@ #include "RTTY.h" +#if !defined(RADIOLIB_EXCLUDE_RTTY) ITA2String::ITA2String(char c) { _len = 1; @@ -109,10 +110,12 @@ RTTYClient::RTTYClient(PhysicalLayer* phy) { _audio = nullptr; } +#if !defined(RADIOLIB_EXCLUDE_AFSK) RTTYClient::RTTYClient(AFSKClient* audio) { _phy = audio->_phy; _audio = audio; } +#endif int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t encoding, uint8_t stopBits) { // save configuration @@ -531,3 +534,5 @@ int16_t RTTYClient::standby() { return(_phy->standby()); } } + +#endif diff --git a/src/protocols/RTTY/RTTY.h b/src/protocols/RTTY/RTTY.h index 1e6120c1..7dc54076 100644 --- a/src/protocols/RTTY/RTTY.h +++ b/src/protocols/RTTY/RTTY.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_RTTY_H +#if !defined(_RADIOLIB_RTTY_H) && !defined(RADIOLIB_EXCLUDE_RTTY) #define _RADIOLIB_RTTY_H #include "../../TypeDef.h" @@ -91,12 +91,14 @@ class RTTYClient { */ RTTYClient(PhysicalLayer* phy); + #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! \brief Constructor for AFSK mode. \param audio Pointer to the AFSK instance providing audio. */ RTTYClient(AFSKClient* audio); + #endif // basic methods @@ -155,7 +157,11 @@ class RTTYClient { private: #endif PhysicalLayer* _phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; + #else + void* _audio; + #endif uint8_t _encoding; uint32_t _base, _baseHz; From 10f11aac885c0ea95c0124ec3ab1e5728a7d73ae Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:46:04 +0200 Subject: [PATCH 204/334] [SSTV] Reworked driver exclusion --- src/protocols/SSTV/SSTV.cpp | 5 +++++ src/protocols/SSTV/SSTV.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp index 4bc16902..73b9b1d9 100644 --- a/src/protocols/SSTV/SSTV.cpp +++ b/src/protocols/SSTV/SSTV.cpp @@ -1,4 +1,5 @@ #include "SSTV.h" +#if !defined(RADIOLIB_EXCLUDE_SSTV) const SSTVMode_t Scottie1 { .visCode = SSTV_SCOTTIE_1, @@ -158,10 +159,12 @@ SSTVClient::SSTVClient(PhysicalLayer* phy) { _audio = nullptr; } +#if !defined(RADIOLIB_EXCLUDE_AFSK) SSTVClient::SSTVClient(AFSKClient* audio) { _phy = audio->_phy; _audio = audio; } +#endif int16_t SSTVClient::begin(SSTVMode_t mode, float correction) { if(_audio == nullptr) { @@ -290,3 +293,5 @@ void SSTVClient::tone(float freq, uint32_t len) { yield(); } } + +#endif diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h index 4c6777d0..1ab9225b 100644 --- a/src/protocols/SSTV/SSTV.h +++ b/src/protocols/SSTV/SSTV.h @@ -1,4 +1,4 @@ -#ifndef _RADIOLIB_SSTV_H +#if !defined(_RADIOLIB_SSTV_H) && !defined(RADIOLIB_EXCLUDE_SSTV) #define _RADIOLIB_SSTV_H #include "../../TypeDef.h" @@ -123,12 +123,14 @@ class SSTVClient { */ SSTVClient(PhysicalLayer* phy); + #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! \brief Constructor for AFSK mode. \param audio Pointer to the AFSK instance providing audio. */ SSTVClient(AFSKClient* phy); + #endif // basic methods @@ -184,7 +186,11 @@ class SSTVClient { private: #endif PhysicalLayer* _phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; + #else + void* _audio; + #endif uint32_t _base; SSTVMode_t _mode; From 8e736217012e988a303e76751ca32c41edbb32e7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 10:53:22 +0200 Subject: [PATCH 205/334] Added support for Arduino Portenta H7 (TRAVIS_FORCE_BUILD) --- .travis.yml | 6 ++++++ README.md | 2 +- src/BuildOpt.h | 26 +++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 889773ac..dd69e1c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ env: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt - BOARD="arduino:avr:uno" + - BOARD="arduino-beta:mbed:envie_m4" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" @@ -111,6 +112,11 @@ before_install: arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; arduino --install-boards adafruit:samd; + elif [[ "$BOARD" =~ "arduino-beta:mbed:" ]]; then + export BUILD_EXAMPLES=false; + arduino --install-boards arduino-beta:mbed; + export SKIP_PAT='(HTTP|MQTT).*ino'; + fi # check if this release commit (or forced build) and if so, build for every board diff --git a/README.md b/README.md index 10da3c3f..e8677ece 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x ### Supported platforms: * __Arduino__ * [__AVR__](https://github.com/arduino/ArduinoCore-avr) - Arduino Uno, Mega, Leonardo, Pro Mini, Nano etc. - * [__mbed__](https://github.com/arduino/ArduinoCore-nRF528x-mbedos) - Arduino Nano 33 BLE + * [__mbed__](https://github.com/arduino/ArduinoCore-mbed) - Arduino Nano 33 BLE and Arduino Portenta H7 * [__megaAVR__](https://github.com/arduino/ArduinoCore-megaavr) - Arduino Uno WiFi Rev.2 and Nano Every * [__SAM__](https://github.com/arduino/ArduinoCore-sam) - Arduino Due * [__SAMD__](https://github.com/arduino/ArduinoCore-samd) - Arduino Zero, MKR boards, M0 Pro etc. diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 84c9b684..490dbf1a 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -33,7 +33,7 @@ #if defined(RADIOLIB_CUSTOM_PLATFORM) // name for your platform - #define RADIOLIB_PLATFORM "Custom" + #define RADIOLIB_PLATFORM "Custom" // the following parameters must always be defined #define RADIOLIB_PIN_TYPE uint8_t @@ -51,6 +51,10 @@ // the following must be defined if the Arduino core does not support tone function //#define RADIOLIB_TONE_UNSUPPORTED + // some of RadioLib drivers may be excluded, to prevent collisions with platform (or to speed up build process) + // for example, to exclude ESP8266 driver: + //RADIOLIB_EXCLUDE_ESP8266 + #else #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) // Arduino AVR boards (except for megaAVR) - Uno, Mega etc. @@ -75,7 +79,7 @@ #define RADIOLIB_DEFAULT_SPI SPI // RadioLib has ESP8266 driver, this must be disabled to use ESP8266 as platform - #define _RADIOLIB_ESP8266_H + #define RADIOLIB_EXCLUDE_ESP8266 #elif defined(ESP32) // ESP32 boards @@ -192,7 +196,23 @@ #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 // Nano 33 BLE uses mbed libraries, which already contain ESP8266 driver - #define _RADIOLIB_ESP8266_H + #define RADIOLIB_EXCLUDE_ESP8266 + + #elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) + // Arduino Portenta H7 + #define RADIOLIB_PLATFORM "Portenta H7" + #define RADIOLIB_PIN_TYPE pin_size_t + #define RADIOLIB_PIN_MODE PinMode + #define RADIOLIB_PIN_STATUS PinStatus + #define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS + #define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p) + #define RADIOLIB_NC (0xFF) + #define RADIOLIB_DEFAULT_SPI SPI + #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED + #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + + // Arduino Portenta H7 uses mbed libraries, which already contain ESP8266 driver + #define RADIOLIB_EXCLUDE_ESP8266 #elif defined(__STM32F4__) || defined(__STM32F1__) // Arduino STM32 core by Roger Clark (https://github.com/rogerclarkmelbourne/Arduino_STM32) From 0831b4a3a143a6de88857d81cffed3f60f8b6d8c Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 11:16:50 +0200 Subject: [PATCH 206/334] [AFSK] Fixed sign --- examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino b/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino index 82052f05..9b80046e 100644 --- a/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino +++ b/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino @@ -28,7 +28,7 @@ SX1278 fsk = new Module(10, 2, 9, 3); // create AFSK client instance using the FSK module -// this requires connection to the module direct +// this requires connection to the module direct // input pin, here connected to Arduino pin 5 // SX127x/RFM9x: DIO2 // RF69: DIO2 @@ -65,12 +65,12 @@ void setup() { void loop() { Serial.print(F("[AFSK] Executing Order 66 ... ")); - + // calculate whole note duration int wholenote = (60000 * 4) / 120; // iterate over the melody - for(int note = 0; note < sizeof(melody) / sizeof(melody[0]); note += 2) { + for(unsigned int note = 0; note < sizeof(melody) / sizeof(melody[0]); note += 2) { // calculate the duration of each note int noteDuration = 0; int divider = melody[note + 1]; @@ -89,7 +89,7 @@ void loop() { audio.noTone(); delay(noteDuration*0.1); } - + Serial.println(F("done!")); // wait for a second From a33a3a5389a41ffbe1c1a71a047e0c7fa3f5a08b Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 11:17:21 +0200 Subject: [PATCH 207/334] [ESP8266] Added missing ESP8266 exclude --- src/modules/ESP8266/ESP8266.cpp | 2 +- src/modules/ESP8266/ESP8266.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index 63f7bca0..7cfef116 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -1,5 +1,5 @@ #include "ESP8266.h" -#if !defined(RADIOLIB_EXCLUDE_ESP8266) +#if !defined(RADIOLIB_EXCLUDE_ESP8266) && !defined(ESP8266) ESP8266::ESP8266(Module* module) { _mod = module; diff --git a/src/modules/ESP8266/ESP8266.h b/src/modules/ESP8266/ESP8266.h index a825b984..4169f12f 100644 --- a/src/modules/ESP8266/ESP8266.h +++ b/src/modules/ESP8266/ESP8266.h @@ -1,6 +1,7 @@ -#if !defined(_RADIOLIB_ESP8266_H) && !defined(RADIOLIB_EXCLUDE_ESP8266) +#if !defined(_RADIOLIB_ESP8266_H) && !defined(RADIOLIB_EXCLUDE_ESP8266) && !defined(ESP8266) #define _RADIOLIB_ESP8266_H +#include "../../TypeDef.h" #include "../../Module.h" #include "../../protocols/TransportLayer/TransportLayer.h" From 9758ad1e444548c2184a94f27b2c382532e8f6f8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 30 Jun 2020 11:17:50 +0200 Subject: [PATCH 208/334] Travis updated build order TRAVIS_FORCE_BUILD --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dd69e1c9..c141bb73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ env: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt - BOARD="arduino:avr:uno" - - BOARD="arduino-beta:mbed:envie_m4" - BOARD="arduino:avr:mega:cpu=atmega2560" - BOARD="arduino:avr:leonardo" - BOARD="esp8266:esp8266:generic:xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K" @@ -20,6 +19,7 @@ env: - BOARD="arduino:mbed:nano33ble" - BOARD="stm32duino:STM32F1:mapleMini:bootloader_version=original,cpu_speed=speed_72mhz" - BOARD="adafruit:samd:adafruit_feather_m0:usbstack=arduino,debug=off" + - BOARD="arduino-beta:mbed:envie_m4" addons: apt: From 2b61001f40489d6f77af3b39767da02a0b362ed5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:21:21 +0200 Subject: [PATCH 209/334] [CC1101] Added explicit default sync word config --- src/modules/CC1101/CC1101.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 80b0c7db..a2b56ac8 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -89,6 +89,10 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po state = setEncoding(2); RADIOLIB_ASSERT(state); + // set default sync word + state = setSyncWord(0xD3, 0x91, 0, false); + RADIOLIB_ASSERT(state); + // flush FIFOs SPIsendCommand(CC1101_CMD_FLUSH_RX); SPIsendCommand(CC1101_CMD_FLUSH_TX); From 0d5b7cb3e9f255eef4c1188d31bff73311388b3f Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:21:44 +0200 Subject: [PATCH 210/334] [AX.25] Fixed modulation type in comment --- examples/AX25/AX25_Frames/AX25_Frames.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/AX25/AX25_Frames/AX25_Frames.ino b/examples/AX25/AX25_Frames/AX25_Frames.ino index 45cbba32..4289c866 100644 --- a/examples/AX25/AX25_Frames/AX25_Frames.ino +++ b/examples/AX25/AX25_Frames/AX25_Frames.ino @@ -47,8 +47,8 @@ void setup() { // initialize SX1278 Serial.print(F("[SX1278] Initializing ... ")); // carrier frequency: 434.0 MHz - // bit rate: 1.2 kbps (1200 baud AFSK AX.25) - // frequency deviation: 0.5 kHz (1200 baud AFSK AX.25) + // bit rate: 1.2 kbps (1200 baud 2-FSK AX.25) + // frequency deviation: 0.5 kHz (1200 baud 2-FSK AX.25) int state = fsk.beginFSK(434.0, 1.2, 0.5); // when using one of the non-LoRa modules for AX.25 From 4819168d2ea722156fc254d2206fc8808683a650 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:22:47 +0200 Subject: [PATCH 211/334] [CC1101] Added links to default config wiki page --- .../CC1101/CC1101_Receive/CC1101_Receive.ino | 22 +++++----- .../CC1101_Receive_Address.ino | 26 ++++++------ .../CC1101_Receive_Interrupt.ino | 42 +++++++++---------- .../CC1101_Settings/CC1101_Settings.ino | 30 +++++++------ .../CC1101_Transmit/CC1101_Transmit.ino | 20 ++++----- .../CC1101_Transmit_Address.ino | 22 +++++----- .../CC1101_Transmit_Interrupt.ino | 24 +++++------ 7 files changed, 86 insertions(+), 100 deletions(-) diff --git a/examples/CC1101/CC1101_Receive/CC1101_Receive.ino b/examples/CC1101/CC1101_Receive/CC1101_Receive.ino index fa8f3aa8..b51bdf20 100644 --- a/examples/CC1101/CC1101_Receive/CC1101_Receive.ino +++ b/examples/CC1101/CC1101_Receive/CC1101_Receive.ino @@ -9,6 +9,9 @@ - frequency deviation - sync word + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,23 +24,18 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); +CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//CC1101 cc = RadioShield.ModuleA; +//CC1101 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize CC1101 with default settings Serial.print(F("[CC1101] Initializing ... ")); - // carrier frequency: 868.0 MHz - // bit rate: 4.8 kbps - // frequency deviation: 48.0 kHz - // Rx bandwidth: 325.0 kHz - // sync word: 0xD391 - int state = cc.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -52,12 +50,12 @@ void loop() { // you can receive data as an Arduino String String str; - int state = cc.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = cc.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { @@ -71,13 +69,13 @@ void loop() { // print RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[CC1101] RSSI:\t\t")); - Serial.print(cc.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print LQI (Link Quality Indicator) // of the last received packet, lower is better Serial.print(F("[CC1101] LQI:\t\t")); - Serial.println(cc.getLQI()); + Serial.println(radio.getLQI()); } else if (state == ERR_CRC_MISMATCH) { // packet was received, but is malformed diff --git a/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino b/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino index 3e12b6d5..81eac67c 100644 --- a/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino +++ b/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino @@ -7,6 +7,9 @@ will automatically filter out any packets that do not contain either node address or broadcast addresses. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -19,23 +22,18 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); +CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//CC1101 cc = RadioShield.ModuleA; +//CC1101 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize CC1101 with default settings Serial.print(F("[CC1101] Initializing ... ")); - // carrier frequency: 868.0 MHz - // bit rate: 4.8 kbps - // frequency deviation: 48.0 kHz - // Rx bandwidth: 325.0 kHz - // sync word: 0xD391 - int state = cc.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -52,7 +50,7 @@ void setup() { // When setting two broadcast addresses, 0x00 and // 0xFF will be used. Serial.print(F("[CC1101] Setting node address ... ")); - state = cc.setNodeAddress(0x01, 1); + state = radio.setNodeAddress(0x01, 1); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -66,7 +64,7 @@ void setup() { // set node address /* Serial.print(F("[CC1101] Disabling address filtering ... ")); - state == cc.disableAddressFiltering(); + state == radio.disableAddressFiltering(); if(state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -82,12 +80,12 @@ void loop() { // you can receive data as an Arduino String String str; - int state = cc.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = cc.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { @@ -101,13 +99,13 @@ void loop() { // print RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[CC1101] RSSI:\t\t")); - Serial.print(cc.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print LQI (Link Quality Indicator) // of the last received packet, lower is better Serial.print(F("[CC1101] LQI:\t\t")); - Serial.println(cc.getLQI()); + Serial.println(radio.getLQI()); } else if (state == ERR_CRC_MISMATCH) { // packet was received, but is malformed diff --git a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino index e036d71e..a7228de4 100644 --- a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino +++ b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino @@ -12,8 +12,11 @@ - frequency deviation - sync word - For full API reference, see the GitHub Pages - https://jgromes.github.io/RadioLib/ + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 + + For full API reference, see the GitHub Pages + https://jgromes.github.io/RadioLib/ */ // include the library @@ -24,23 +27,18 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); +CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//CC1101 cc = RadioShield.ModuleA; +//CC1101 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize CC1101 with default settings Serial.print(F("[CC1101] Initializing ... ")); - // carrier frequency: 868.0 MHz - // bit rate: 4.8 kbps - // frequency deviation: 48.0 kHz - // Rx bandwidth: 325.0 kHz - // sync word: 0xD391 - int state = cc.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -51,11 +49,11 @@ void setup() { // set the function that will be called // when new packet is received - cc.setGdo0Action(setFlag); + radio.setGdo0Action(setFlag); // start listening for packets Serial.print(F("[CC1101] Starting to listen ... ")); - state = cc.startReceive(); + state = radio.startReceive(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -67,11 +65,11 @@ void setup() { // if needed, 'listen' mode can be disabled by calling // any of the following methods: // - // cc.standby() - // cc.sleep() - // cc.transmit(); - // cc.receive(); - // cc.readData(); + // radio.standby() + // radio.sleep() + // radio.transmit(); + // radio.receive(); + // radio.readData(); } // flag to indicate that a packet was received @@ -106,12 +104,12 @@ void loop() { // you can read received data as an Arduino String String str; - int state = cc.readData(str); + int state = radio.readData(str); // you can also read received data as byte array /* byte byteArr[8]; - int state = cc.readData(byteArr, 8); + int state = radio.readData(byteArr, 8); */ if (state == ERR_NONE) { @@ -125,13 +123,13 @@ void loop() { // print RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[CC1101] RSSI:\t\t")); - Serial.print(cc.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print LQI (Link Quality Indicator) // of the last received packet, lower is better Serial.print(F("[CC1101] LQI:\t\t")); - Serial.println(cc.getLQI()); + Serial.println(radio.getLQI()); } else if (state == ERR_CRC_MISMATCH) { // packet was received, but is malformed @@ -145,7 +143,7 @@ void loop() { } // put module back to listen mode - cc.startReceive(); + radio.startReceive(); // we're ready to receive more packets, // enable interrupt service routine diff --git a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino index 02394da1..4e4bcfd3 100644 --- a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino +++ b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino @@ -11,6 +11,9 @@ - output power during transmission - sync word + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -23,30 +26,25 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc1 = new Module(10, 2, RADIOLIB_NC, 3); +CC1101 radio1 = new Module(10, 2, RADIOLIB_NC, 3); // second CC1101 has different connections: // CS pin: 9 // GDO0 pin: 4 // RST pin: unused // GDO2 pin: 5 (optional) -CC1101 cc2 = new Module(9, 4, RADIOLIB_NC, 53); +CC1101 radio2 = new Module(9, 4, RADIOLIB_NC, 53); // or using RadioShield // https://github.com/jgromes/RadioShield -//CC1101 cc3 = RadioShield.ModuleB; +//CC1101 radio3 = RadioShield.ModuleB; void setup() { Serial.begin(9600); // initialize CC1101 with default settings Serial.print(F("[CC1101] Initializing ... ")); - // carrier frequency: 868.0 MHz - // bit rate: 4.8 kbps - // frequency deviation: 48.0 kHz - // Rx bandwidth: 325.0 kHz - // sync word: 0xD391 - int state = cc1.begin(); + int state = radio1.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -62,7 +60,7 @@ void setup() { // frequency deviation: 60.0 kHz // Rx bandwidth: 250.0 kHz // sync word: 0xD391 - state = cc2.begin(434.0, 32.0, 60.0, 250.0); + state = radio2.begin(434.0, 32.0, 60.0, 250.0); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -75,13 +73,13 @@ void setup() { // and check if the configuration was changed successfully // set carrier frequency to 433.5 MHz - if (cc1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { + if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { Serial.println(F("[CC1101] Selected frequency is invalid for this module!")); while (true); } // set bit rate to 100.0 kbps - state = cc1.setBitRate(100.0); + state = radio1.setBitRate(100.0); if (state == ERR_INVALID_BIT_RATE) { Serial.println(F("[CC1101] Selected bit rate is invalid for this module!")); while (true); @@ -92,25 +90,25 @@ void setup() { } // set receiver bandwidth to 250.0 kHz - if (cc1.setRxBandwidth(250.0) == ERR_INVALID_RX_BANDWIDTH) { + if (radio1.setRxBandwidth(250.0) == ERR_INVALID_RX_BANDWIDTH) { Serial.println(F("[CC1101] Selected receiver bandwidth is invalid for this module!")); while (true); } // set allowed frequency deviation to 10.0 kHz - if (cc1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) { + if (radio1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) { Serial.println(F("[CC1101] Selected frequency deviation is invalid for this module!")); while (true); } // set output power to 5 dBm - if (cc1.setOutputPower(5) == ERR_INVALID_OUTPUT_POWER) { + if (radio1.setOutputPower(5) == ERR_INVALID_OUTPUT_POWER) { Serial.println(F("[CC1101] Selected output power is invalid for this module!")); while (true); } // 2 bytes can be set as sync word - if (cc1.setSyncWord(0x01, 0x23) == ERR_INVALID_SYNC_WORD) { + if (radio1.setSyncWord(0x01, 0x23) == ERR_INVALID_SYNC_WORD) { Serial.println(F("[CC1101] Selected sync word is invalid for this module!")); while (true); } diff --git a/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino b/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino index be530890..3463c6f1 100644 --- a/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino +++ b/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino @@ -7,6 +7,9 @@ - null-terminated char array (C-string) - arbitrary binary data (byte array) + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -19,23 +22,18 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); +CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//CC1101 cc = RadioShield.ModuleA; +//CC1101 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); - // initialize CC1101 + // initialize CC1101 with default settings Serial.print(F("[CC1101] Initializing ... ")); - // carrier frequency: 868.0 MHz - // bit rate: 4.8 kbps - // frequency deviation: 48.0 kHz - // Rx bandwidth: 325.0 kHz - // sync word: 0xD391 - int state = cc.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -49,12 +47,12 @@ void loop() { Serial.print(F("[CC1101] Transmitting packet ... ")); // you can transmit C-string or Arduino string up to 63 characters long - int state = cc.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 63 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = cc.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino index e584eb7c..430eafd8 100644 --- a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino +++ b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino @@ -7,6 +7,9 @@ will automatically filter out any packets that do not contain either node address or broadcast addresses. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -19,23 +22,18 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); +CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//CC1101 cc = RadioShield.ModuleA; +//CC1101 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize CC1101 with default settings Serial.print(F("[CC1101] Initializing ... ")); - // carrier frequency: 868.0 MHz - // bit rate: 4.8 kbps - // frequency deviation: 48.0 kHz - // Rx bandwidth: 325.0 kHz - // sync word: 0xD391 - int state = cc.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -52,7 +50,7 @@ void setup() { // When setting two broadcast addresses, 0x00 and // 0xFF will be used. Serial.print(F("[CC1101] Setting node address ... ")); - state = cc.setNodeAddress(0x01, 1); + state = radio.setNodeAddress(0x01, 1); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -66,7 +64,7 @@ void setup() { // set node address /* Serial.print(F("[CC1101] Disabling address filtering ... ")); - state == cc.disableAddressFiltering(); + state == radio.disableAddressFiltering(); if(state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -81,12 +79,12 @@ void loop() { Serial.print(F("[CC1101] Transmitting packet ... ")); // you can transmit C-string or Arduino string up to 63 characters long - int state = cc.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 63 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = cc.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino index 47991677..c15652b6 100644 --- a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino +++ b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino @@ -8,6 +8,9 @@ - null-terminated char array (C-string) - arbitrary binary data (byte array) + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,11 +23,11 @@ // GDO0 pin: 2 // RST pin: unused // GDO2 pin: 3 (optional) -CC1101 cc = new Module(10, 2, RADIOLIB_NC, 3); +CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//CC1101 cc = RadioShield.ModuleA; +//CC1101 radio = RadioShield.ModuleA; // save transmission state between loops int transmissionState = ERR_NONE; @@ -34,12 +37,7 @@ void setup() { // initialize CC1101 with default settings Serial.print(F("[CC1101] Initializing ... ")); - // carrier frequency: 868.0 MHz - // bit rate: 4.8 kbps - // frequency deviation: 48.0 kHz - // Rx bandwidth: 325.0 kHz - // sync word: 0xD391 - int state = cc.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -50,20 +48,20 @@ void setup() { // set the function that will be called // when packet transmission is finished - cc.setGdo0Action(setFlag); + radio.setGdo0Action(setFlag); // start transmitting the first packet Serial.print(F("[CC1101] Sending first packet ... ")); // you can transmit C-string or Arduino string up to // 64 characters long - transmissionState = cc.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; - state = cc.startTransmit(byteArr, 8); + state = radio.startTransmit(byteArr, 8); */ } @@ -119,13 +117,13 @@ void loop() { // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = cc.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = cc.startTransmit(byteArr, 8); + int state = radio.startTransmit(byteArr, 8); */ // we're ready to send more packets, From bd559b57f19cb92a98095a112139fdbd3be389d8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:24:46 +0200 Subject: [PATCH 212/334] [nRF24] Added explicit default param config --- src/modules/nRF24/nRF24.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 888b959f..e8df4e13 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -33,6 +33,7 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW // set mode to standby state = standby(); RADIOLIB_ASSERT(state); + // set frequency state = setFrequency(freq); RADIOLIB_ASSERT(state); @@ -47,6 +48,15 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW // set address width state = setAddressWidth(addrWidth); + RADIOLIB_ASSERT(state); + + // set CRC + state = setCrcFiltering(true); + RADIOLIB_ASSERT(state); + + // set auto-ACK on all pipes + state = setAutoAck(true); + RADIOLIB_ASSERT(state); return(state); } From d867bc043ab98fff1c417a96ad57890ed7ed12a6 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:25:05 +0200 Subject: [PATCH 213/334] [nRF24] Added links to default config wiki page --- .../nRF24/nRF24_Receive/nRF24_Receive.ino | 21 +++++++++---------- .../nRF24/nRF24_Transmit/nRF24_Transmit.ino | 19 ++++++++--------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/examples/nRF24/nRF24_Receive/nRF24_Receive.ino b/examples/nRF24/nRF24_Receive/nRF24_Receive.ino index b5b5571e..2c036fd6 100644 --- a/examples/nRF24/nRF24_Receive/nRF24_Receive.ino +++ b/examples/nRF24/nRF24_Receive/nRF24_Receive.ino @@ -9,6 +9,9 @@ - transmit pipe on transmitter must match receive pipe on receiver + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,22 +23,18 @@ // CS pin: 10 // IRQ pin: 2 // CE pin: 3 -nRF24 nrf = new Module(10, 2, 3); +nRF24 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//nRF24 nrf = RadioShield.ModuleA; +//nRF24 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); - // initialize nRF24 + // initialize nRF24 with default settings Serial.print(F("[nRF24] Initializing ... ")); - // carrier frequency: 2400 MHz - // data rate: 1000 kbps - // output power: -12 dBm - // address width: 5 bytes - int state = nrf.begin(); + int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -50,7 +49,7 @@ void setup() { // methods (5 by default) Serial.print(F("[nRF24] Setting address for receive pipe 0 ... ")); byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89}; - state = nrf.setReceivePipe(0, addr); + state = radio.setReceivePipe(0, addr); if(state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -68,12 +67,12 @@ void loop() { // See example ReceiveInterrupt for details // on non-blocking reception method. String str; - int state = nrf.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = nrf.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/nRF24/nRF24_Transmit/nRF24_Transmit.ino b/examples/nRF24/nRF24_Transmit/nRF24_Transmit.ino index 89006b38..c692e8a8 100644 --- a/examples/nRF24/nRF24_Transmit/nRF24_Transmit.ino +++ b/examples/nRF24/nRF24_Transmit/nRF24_Transmit.ino @@ -9,6 +9,9 @@ Packet delivery is automatically acknowledged by the receiver. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,22 +23,18 @@ // CS pin: 10 // IRQ pin: 2 // CE pin: 3 -nRF24 nrf = new Module(10, 2, 3); +nRF24 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//nRF24 nrf = RadioShield.ModuleA; +//nRF24 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); - // initialize nRF24 + // initialize nRF24 with default settings Serial.print(F("[nRF24] Initializing ... ")); - // carrier frequency: 2400 MHz - // data rate: 1000 kbps - // output power: -12 dBm - // address width: 5 bytes - int state = nrf.begin(); + int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -50,7 +49,7 @@ void setup() { // methods (5 by default) byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89}; Serial.print(F("[nRF24] Setting transmit pipe ... ")); - state = nrf.setTransmitPipe(addr); + state = radio.setTransmitPipe(addr); if(state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -65,7 +64,7 @@ void loop() { // you can transmit C-string or Arduino string up to // 32 characters long - int state = nrf.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); if (state == ERR_NONE) { // the packet was successfully transmitted From 59c4a71fad8e796da41b3216166c4d713416fe12 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:25:39 +0200 Subject: [PATCH 214/334] [RF69] Added explicit default param config --- src/modules/RF69/RF69.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 7b1cad43..bebaba12 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -96,7 +96,11 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe state = setEncoding(0); RADIOLIB_ASSERT(state); - return(ERR_NONE); + // set CRC on by default + state = setCrcFiltering(true); + RADIOLIB_ASSERT(state); + + return(state); } void RF69::reset() { From 1db4a47181f5148d99a8935429a191c0e7affbed Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:26:01 +0200 Subject: [PATCH 215/334] [RF69] Added links to default config wiki page --- examples/RF69/RF69_Receive/RF69_Receive.ino | 21 +++++------ .../RF69_Receive_AES/RF69_Receive_AES.ino | 25 ++++++------- .../RF69_Receive_Address.ino | 25 ++++++------- .../RF69_Receive_Interrupt.ino | 37 +++++++++---------- examples/RF69/RF69_Settings/RF69_Settings.ino | 36 ++++++++---------- examples/RF69/RF69_Transmit/RF69_Transmit.ino | 21 +++++------ .../RF69_Transmit_AES/RF69_Transmit_AES.ino | 25 ++++++------- .../RF69_Transmit_Address.ino | 21 +++++------ .../RF69_Transmit_Interrupt.ino | 27 ++++++-------- 9 files changed, 105 insertions(+), 133 deletions(-) diff --git a/examples/RF69/RF69_Receive/RF69_Receive.ino b/examples/RF69/RF69_Receive/RF69_Receive.ino index 161173e3..fd924755 100644 --- a/examples/RF69/RF69_Receive/RF69_Receive.ino +++ b/examples/RF69/RF69_Receive/RF69_Receive.ino @@ -9,6 +9,9 @@ - frequency deviation - sync word + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,24 +23,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -52,12 +49,12 @@ void loop() { // you can receive data as an Arduino String String str; - int state = rf.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = rf.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { @@ -71,7 +68,7 @@ void loop() { // print RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[RF69] RSSI:\t\t")); - Serial.print(rf.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); } else if (state == ERR_RX_TIMEOUT) { diff --git a/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino b/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino index 7c947cf0..c1fa2816 100644 --- a/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino +++ b/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino @@ -5,6 +5,9 @@ Packets are decrypted using hardware AES. NOTE: When using address filtering, the address byte is NOT encrypted! + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -16,24 +19,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -46,14 +43,14 @@ void setup() { // NOTE: the key must be exactly 16 bytes long! uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; - rf.setAESKey(key); + radio.setAESKey(key); // enable AES encryption - rf.enableAES(); + radio.enableAES(); // AES encryption can also be disabled /* - rf.disableAES(); + radio.disableAES(); */ } @@ -62,12 +59,12 @@ void loop() { // you can receive data as an Arduino String String str; - int state = rf.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = rf.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino b/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino index 08242ec3..df20200c 100644 --- a/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino +++ b/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino @@ -7,6 +7,9 @@ automatically filter out any packets that do not contain either node address or broadcast address. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -18,24 +21,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -48,7 +45,7 @@ void setup() { // NOTE: calling this method will automatically enable // address filtering (node address only) Serial.print(F("[RF69] Setting node address ... ")); - state = rf.setNodeAddress(0x02); + state = radio.setNodeAddress(0x02); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -61,7 +58,7 @@ void setup() { // NOTE: calling this method will automatically enable // address filtering (node or broadcast address) Serial.print(F("[RF69] Setting broadcast address ... ")); - state = rf.setBroadcastAddress(0xFF); + state = radio.setBroadcastAddress(0xFF); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -75,7 +72,7 @@ void setup() { // node and broadcast address /* Serial.print(F("[RF69] Disabling address filtering ... ")); - state == rf.disableAddressFiltering(); + state == radio.disableAddressFiltering(); if(state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -91,12 +88,12 @@ void loop() { // you can receive data as an Arduino String String str; - int state = rf.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = rf.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino index e028a678..2a512783 100644 --- a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino +++ b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino @@ -5,6 +5,9 @@ receive them. Once a packet is received, an interrupt is triggered. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -16,24 +19,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -44,11 +41,11 @@ void setup() { // set the function that will be called // when new packet is received - rf.setDio0Action(setFlag); + radio.setDio0Action(setFlag); // start listening for packets Serial.print(F("[RF69] Starting to listen ... ")); - state = rf.startReceive(); + state = radio.startReceive(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -60,11 +57,11 @@ void setup() { // if needed, 'listen' mode can be disabled by calling // any of the following methods: // - // rf.standby() - // rf.sleep() - // rf.transmit(); - // rf.receive(); - // rf.readData(); + // radio.standby() + // radio.sleep() + // radio.transmit(); + // radio.receive(); + // radio.readData(); } // flag to indicate that a packet was received @@ -99,12 +96,12 @@ void loop() { // you can read received data as an Arduino String String str; - int state = rf.readData(str); + int state = radio.readData(str); // you can also read received data as byte array /* byte byteArr[8]; - int state = rf.readData(byteArr, 8); + int state = radio.readData(byteArr, 8); */ if (state == ERR_NONE) { @@ -118,7 +115,7 @@ void loop() { // print RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[RF69] RSSI:\t\t")); - Serial.print(rf.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); } else if (state == ERR_CRC_MISMATCH) { @@ -133,7 +130,7 @@ void loop() { } // put module back to listen mode - rf.startReceive(); + radio.startReceive(); // we're ready to receive more packets, // enable interrupt service routine diff --git a/examples/RF69/RF69_Settings/RF69_Settings.ino b/examples/RF69/RF69_Settings/RF69_Settings.ino index 2fee90ba..49c23e80 100644 --- a/examples/RF69/RF69_Settings/RF69_Settings.ino +++ b/examples/RF69/RF69_Settings/RF69_Settings.ino @@ -11,6 +11,9 @@ - output power during transmission - sync word + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -22,30 +25,24 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf1 = new Module(10, 2, 3); +RF69 radio1 = new Module(10, 2, 3); // second CC1101 has different connections: // CS pin: 9 // DIO0 pin: 4 // RESET pin: 5 -RF69 rf2 = new Module(9, 4, 5); +RF69 radio2 = new Module(9, 4, 5); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf3 = RadioShield.ModuleB; +//RF69 radio3 = RadioShield.ModuleB; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf1.begin(); + int state = radio1.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -61,8 +58,7 @@ void setup() { // frequency deviation: 60.0 kHz // Rx bandwidth: 250.0 kHz // output power: 17 dBm - // sync word: 0x2D01 - state = rf2.begin(868.0, 300.0, 60.0, 250.0, 17); + state = radio2.begin(868.0, 300.0, 60.0, 250.0, 17); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -75,13 +71,13 @@ void setup() { // and check if the configuration was changed successfully // set carrier frequency to 433.5 MHz - if (rf1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { + if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { Serial.println(F("[RF69] Selected frequency is invalid for this module!")); while (true); } // set bit rate to 100.0 kbps - state = rf1.setBitRate(100.0); + state = radio1.setBitRate(100.0); if (state == ERR_INVALID_BIT_RATE) { Serial.println(F("[RF69] Selected bit rate is invalid for this module!")); while (true); @@ -92,7 +88,7 @@ void setup() { } // set receiver bandwidth to 250.0 kHz - state = rf1.setRxBandwidth(250.0); + state = radio1.setRxBandwidth(250.0); if (state == ERR_INVALID_RX_BANDWIDTH) { Serial.println(F("[RF69] Selected receiver bandwidth is invalid for this module!")); while (true); @@ -103,13 +99,13 @@ void setup() { } // set allowed frequency deviation to 10.0 kHz - if (rf1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) { + if (radio1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) { Serial.println(F("[RF69] Selected frequency deviation is invalid for this module!")); while (true); } // set output power to 2 dBm - if (rf1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) { + if (radio1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) { Serial.println(F("[RF69] Selected output power is invalid for this module!")); while (true); } @@ -118,7 +114,7 @@ void setup() { // NOTE: sync word must not contain any zero bytes // set sync word to 0x0123456789ABCDEF uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - if (rf1.setSyncWord(syncWord, 8) == ERR_INVALID_SYNC_WORD) { + if (radio1.setSyncWord(syncWord, 8) == ERR_INVALID_SYNC_WORD) { Serial.println(F("[RF69] Selected sync word is invalid for this module!")); while (true); } @@ -128,13 +124,13 @@ void setup() { // RF69 can also measure temperature (roughly) // to get correct temperature measurements, the sensor must be calibrated // at ambient temperature - rf1.setAmbientTemperature(25); // replace 25 with your ambient temperature + radio1.setAmbientTemperature(25); // replace 25 with your ambient temperature } void loop() { // measure temperature Serial.print(F("[RF69] Measured temperature: ")); - Serial.print(rf1.getTemperature()); + Serial.print(radio1.getTemperature()); Serial.println(F(" deg C")); // wait 100 ms before the next measurement diff --git a/examples/RF69/RF69_Transmit/RF69_Transmit.ino b/examples/RF69/RF69_Transmit/RF69_Transmit.ino index 5d39f6f2..c57122b2 100644 --- a/examples/RF69/RF69_Transmit/RF69_Transmit.ino +++ b/examples/RF69/RF69_Transmit/RF69_Transmit.ino @@ -7,6 +7,9 @@ - null-terminated char array (C-string) - arbitrary binary data (byte array) + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -18,24 +21,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -51,7 +48,7 @@ void setup() { // second argument set to true. /* Serial.print(F("[RF69] Setting high power module ... ")); - state = rf.setOutputPower(20, true); + state = radio.setOutputPower(20, true); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -66,12 +63,12 @@ void loop() { Serial.print(F("[RF69] Transmitting packet ... ")); // you can transmit C-string or Arduino string up to 64 characters long - int state = rf.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = rf.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino b/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino index 5df09c65..d5bc2de2 100644 --- a/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino +++ b/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino @@ -5,6 +5,9 @@ Packets are encrypted using hardware AES. NOTE: When using address filtering, the address byte is NOT encrypted! + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -16,24 +19,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -46,14 +43,14 @@ void setup() { // NOTE: the key must be exactly 16 bytes long! uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; - rf.setAESKey(key); + radio.setAESKey(key); // enable AES encryption - rf.enableAES(); + radio.enableAES(); // AES encryption can also be disabled /* - rf.disableAES(); + radio.disableAES(); */ } @@ -61,12 +58,12 @@ void loop() { Serial.print(F("[RF69] Transmitting packet ... ")); // you can transmit C-string or Arduino string up to 64 characters long - int state = rf.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = rf.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino index 7413822e..4e8c2667 100644 --- a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino +++ b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino @@ -7,6 +7,9 @@ automatically filter out any packets that do not contain either node address or broadcast address. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -18,24 +21,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -48,7 +45,7 @@ void setup() { // NOTE: calling this method will automatically enable // address filtering (node address only) Serial.print(F("[RF69] Setting node address ... ")); - state = rf.setNodeAddress(0x01); + state = radio.setNodeAddress(0x01); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -61,7 +58,7 @@ void setup() { // NOTE: calling this method will automatically enable // address filtering (node or broadcast address) Serial.print(F("[RF69] Setting broadcast address ... ")); - state = rf.setBroadcastAddress(0xFF); + state = radio.setBroadcastAddress(0xFF); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -75,7 +72,7 @@ void setup() { // node and broadcast address /* Serial.print(F("[RF69] Disabling address filtering ... ")); - state = rf.disableAddressFiltering(); + state = radio.disableAddressFiltering(); if(state == ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino index e07b41ec..0f03dad1 100644 --- a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino +++ b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino @@ -8,6 +8,9 @@ - null-terminated char array (C-string) - arbitrary binary data (byte array) + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -19,11 +22,11 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -RF69 rf = new Module(10, 2, 3); +RF69 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//RF69 rf = RadioShield.ModuleA; +//RF69 radio = RadioShield.ModuleA; // save transmission state between loops int transmissionState = ERR_NONE; @@ -33,13 +36,7 @@ void setup() { // initialize RF69 with default settings Serial.print(F("[RF69] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -50,7 +47,7 @@ void setup() { // set the function that will be called // when packet transmission is finished - rf.setDio0Action(setFlag); + radio.setDio0Action(setFlag); // NOTE: some RF69 modules use high power output, // those are usually marked RF69H(C/CW). @@ -59,7 +56,7 @@ void setup() { // second argument set to true. /* Serial.print(F("[RF69] Setting high power module ... ")); - state = rf.setOutputPower(20, true); + state = radio.setOutputPower(20, true); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -74,13 +71,13 @@ void setup() { // you can transmit C-string or Arduino string up to // 64 characters long - transmissionState = rf.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - state = rf.startTransmit(byteArr, 8); + state = radio.startTransmit(byteArr, 8); */ } @@ -136,13 +133,13 @@ void loop() { // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = rf.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = rf.startTransmit(byteArr, 8); + int state = radio.startTransmit(byteArr, 8); */ // we're ready to send more packets, From d89025d8c789cab4f5dc6c9c1f20829e793228d0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:28:47 +0200 Subject: [PATCH 216/334] [Si443x] Added links to default config wiki page --- .../Si443x/Si443x_Receive/Si443x_Receive.ino | 19 +++++----- .../Si443x_Receive_Interrupt.ino | 35 +++++++++---------- .../Si443x_Settings/Si443x_Settings.ino | 32 ++++++++--------- .../Si443x_Transmit/Si443x_Transmit.ino | 19 +++++----- .../Si443x_Transmit_Interrupt.ino | 26 ++++++-------- 5 files changed, 57 insertions(+), 74 deletions(-) diff --git a/examples/Si443x/Si443x_Receive/Si443x_Receive.ino b/examples/Si443x/Si443x_Receive/Si443x_Receive.ino index 345fb8a6..846e46e3 100644 --- a/examples/Si443x/Si443x_Receive/Si443x_Receive.ino +++ b/examples/Si443x/Si443x_Receive/Si443x_Receive.ino @@ -11,6 +11,9 @@ Other modules from Si443x/RFM2x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -22,24 +25,18 @@ // nSEL pin: 10 // nIRQ pin: 2 // SDN pin: 9 -Si4432 fsk = new Module(10, 2, 9); +Si4432 radio = new Module(10, 2, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//Si4432 fsk = RadioShield.ModuleA; +//Si4432 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize Si4432 with default settings Serial.print(F("[Si4432] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 225.1 kHz - // output power: 11 dBm - // sync word: 0x2D 0x01 - int state = fsk.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -54,12 +51,12 @@ void loop() { // you can receive data as an Arduino String String str; - int state = fsk.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = rf.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino b/examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino index a514980e..e890b08d 100644 --- a/examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino +++ b/examples/Si443x/Si443x_Receive_Interrupt/Si443x_Receive_Interrupt.ino @@ -7,6 +7,9 @@ Other modules from Si443x/RFM2x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -18,24 +21,18 @@ // nSEL pin: 10 // nIRQ pin: 2 // SDN pin: 9 -Si4432 fsk = new Module(10, 2, 9); +Si4432 radio = new Module(10, 2, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//Si4432 fsk = RadioShield.ModuleA; +//Si4432 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize Si4432 with default settings Serial.print(F("[Si4432] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 225.1 kHz - // output power: 11 dBm - // sync word: 0x2D 0x01 - int state = fsk.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -46,11 +43,11 @@ void setup() { // set the function that will be called // when new packet is received - fsk.setIrqAction(setFlag); + radio.setIrqAction(setFlag); // start listening for packets Serial.print(F("[Si4432] Starting to listen ... ")); - state = fsk.startReceive(); + state = radio.startReceive(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -62,11 +59,11 @@ void setup() { // if needed, 'listen' mode can be disabled by calling // any of the following methods: // - // fsk.standby() - // fsk.sleep() - // fsk.transmit(); - // fsk.receive(); - // fsk.readData(); + // radio.standby() + // radio.sleep() + // radio.transmit(); + // radio.receive(); + // radio.readData(); } // flag to indicate that a packet was received @@ -101,12 +98,12 @@ void loop() { // you can read received data as an Arduino String String str; - int state = fsk.readData(str); + int state = radio.readData(str); // you can also read received data as byte array /* byte byteArr[8]; - int state = fsk.readData(byteArr, 8); + int state = radio.readData(byteArr, 8); */ if (state == ERR_NONE) { @@ -129,7 +126,7 @@ void loop() { } // put module back to listen mode - fsk.startReceive(); + radio.startReceive(); // we're ready to receive more packets, // enable interrupt service routine diff --git a/examples/Si443x/Si443x_Settings/Si443x_Settings.ino b/examples/Si443x/Si443x_Settings/Si443x_Settings.ino index b3d1ab82..ee5f7e9b 100644 --- a/examples/Si443x/Si443x_Settings/Si443x_Settings.ino +++ b/examples/Si443x/Si443x_Settings/Si443x_Settings.ino @@ -11,6 +11,9 @@ - output power during transmission - sync word + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -22,30 +25,24 @@ // nSEL pin: 10 // nIRQ pin: 2 // SDN pin: 9 -Si4432 fsk1 = new Module(10, 2, 9); +Si4432 radio1 = new Module(10, 2, 9); // Si4432 has the following connections: // nSEL pin: 8 // nIRQ pin: 3 // SDN pin: 7 -Si4432 fsk2 = new Module(8, 3, 7); +Si4432 radio2 = new Module(8, 3, 7); // or using RadioShield // https://github.com/jgromes/RadioShield -//Si4432 fsk3 = RadioShield.ModuleB; +//Si4432 radio3 = RadioShield.ModuleB; void setup() { Serial.begin(9600); // initialize Si4432 with default settings Serial.print(F("[Si4432] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 225.1 kHz - // output power: 11 dBm - // sync word: 0x2D 0x01 - int state = fsk1.begin(); + int state = radio1.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -61,8 +58,7 @@ void setup() { // frequency deviation: 60.0 kHz // Rx bandwidth: 335.5 kHz // output power: 17 dBm - // sync word: 0x2D 0x01 - state = fsk2.begin(868.0, 200.0, 60.0, 335.5, 17); + state = radio2.begin(868.0, 200.0, 60.0, 335.5, 17); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -75,13 +71,13 @@ void setup() { // and check if the configuration was changed successfully // set carrier frequency to 433.5 MHz - if (fsk1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { + if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { Serial.println(F("[Si4432] Selected frequency is invalid for this module!")); while (true); } // set bit rate to 100.0 kbps - state = fsk1.setBitRate(100.0); + state = radio1.setBitRate(100.0); if (state == ERR_INVALID_BIT_RATE) { Serial.println(F("[Si4432] Selected bit rate is invalid for this module!")); while (true); @@ -92,20 +88,20 @@ void setup() { } // set receiver bandwidth to 284.8 kHz - state = fsk1.setRxBandwidth(284.8); + state = radio1.setRxBandwidth(284.8); if (state == ERR_INVALID_RX_BANDWIDTH) { Serial.println(F("[Si4432] Selected receiver bandwidth is invalid for this module!")); while (true); } // set frequency deviation to 10.0 kHz - if (fsk1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) { + if (radio1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) { Serial.println(F("[Si4432] Selected frequency deviation is invalid for this module!")); while (true); } // set output power to 2 dBm - if (fsk1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) { + if (radio1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) { Serial.println(F("[Si4432] Selected output power is invalid for this module!")); while (true); } @@ -113,7 +109,7 @@ void setup() { // up to 4 bytes can be set as sync word // set sync word to 0x01234567 uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67}; - if (fsk1.setSyncWord(syncWord, 4) == ERR_INVALID_SYNC_WORD) { + if (radio1.setSyncWord(syncWord, 4) == ERR_INVALID_SYNC_WORD) { Serial.println(F("[Si4432] Selected sync word is invalid for this module!")); while (true); } diff --git a/examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino b/examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino index 34a278da..ca267624 100644 --- a/examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino +++ b/examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino @@ -9,6 +9,9 @@ Other modules from Si443x/RFM2x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,24 +23,18 @@ // nSEL pin: 10 // nIRQ pin: 2 // SDN pin: 9 -Si4432 fsk = new Module(10, 2, 9); +Si4432 radio = new Module(10, 2, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//Si4432 fsk = RadioShield.ModuleA; +//Si4432 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize Si4432 with default settings Serial.print(F("[Si4432] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 225.1 kHz - // output power: 11 dBm - // sync word: 0x2D 0x01 - int state = fsk.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -55,12 +52,12 @@ void loop() { // NOTE: transmit() is a blocking method! // See example Si443x_Transmit_Interrupt for details // on non-blocking transmission method. - int state = fsk.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; - int state = fsk.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino b/examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino index e4c56c18..82c5364d 100644 --- a/examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino +++ b/examples/Si443x/Si443x_Transmit_Interrupt/Si443x_Transmit_Interrupt.ino @@ -9,6 +9,9 @@ Other modules from Si443x/RFM2x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,11 +23,11 @@ // nSEL pin: 10 // nIRQ pin: 2 // SDN pin: 9 -Si4432 fsk = new Module(10, 2, 9); +Si4432 radio = new Module(10, 2, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//Si4432 fsk = RadioShield.ModuleA; +//Si4432 radio = RadioShield.ModuleA; // save transmission state between loops int transmissionState = ERR_NONE; @@ -34,14 +37,7 @@ void setup() { // initialize Si4432 with default settings Serial.print(F("[Si4432] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 225.1 kHz - // output power: 11 dBm - // sync word: 0x2D 0x01 - int state = fsk.begin(); - fsk.setOutputPower(13); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -52,20 +48,20 @@ void setup() { // set the function that will be called // when packet transmission is finished - fsk.setIrqAction(setFlag); + radio.setIrqAction(setFlag); // start transmitting the first packet Serial.print(F("[Si4432] Sending first packet ... ")); // you can transmit C-string or Arduino string up to // 64 characters long - transmissionState = fsk.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - state = fsk.startTransmit(byteArr, 8); + state = radio.startTransmit(byteArr, 8); */ } @@ -117,13 +113,13 @@ void loop() { // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = fsk.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 64 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = fsk.startTransmit(byteArr, 8); + int state = radio.startTransmit(byteArr, 8); */ // we're ready to send more packets, From b98f910367d0fefebc019841bcfd02eac1938e9b Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:32:21 +0200 Subject: [PATCH 217/334] [SX126x] Added missing assertions --- src/modules/SX126x/SX1262.cpp | 2 ++ src/modules/SX126x/SX1268.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 1ce049af..3f086c9a 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -18,6 +18,7 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = SX126x::fixPaClamping(); + RADIOLIB_ASSERT(state); return(state); } @@ -35,6 +36,7 @@ int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t RADIOLIB_ASSERT(state); state = SX126x::fixPaClamping(); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index 04cd370f..7e6b3443 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -18,9 +18,11 @@ int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = SX126x::fixPaClamping(); + RADIOLIB_ASSERT(state); return(state); } + int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage, bool useRegulatorLDO) { // execute common part int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping, tcxoVoltage, useRegulatorLDO); @@ -34,6 +36,7 @@ int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t RADIOLIB_ASSERT(state); state = SX126x::fixPaClamping(); + RADIOLIB_ASSERT(state); return(state); } From 4a53a58258320d2935851d093c25e9fd7e29898f Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:32:44 +0200 Subject: [PATCH 218/334] [SX126x] Added links to default config wiki page --- .../SX126x_Channel_Activity_Detection.ino | 22 ++---- .../SX126x_FSK_Modem/SX126x_FSK_Modem.ino | 67 ++++++++----------- .../SX126x/SX126x_Receive/SX126x_Receive.ino | 28 +++----- .../SX126x_Receive_Interrupt.ino | 48 ++++++------- .../SX126x_Settings/SX126x_Settings.ino | 45 +++++-------- .../SX126x_Transmit/SX126x_Transmit.ino | 28 +++----- .../SX126x_Transmit_Interrupt.ino | 32 ++++----- 7 files changed, 108 insertions(+), 162 deletions(-) diff --git a/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino b/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino index 99209b99..b888a95d 100644 --- a/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino +++ b/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino @@ -8,6 +8,9 @@ Other modules from SX126x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,29 +23,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1262 lora = new Module(10, 2, 3, 9); +SX1262 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1262 lora = RadioShield.ModuleA; +//SX1262 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1262 with default settings Serial.print(F("[SX1262] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 (private network) - // output power: 14 dBm - // current limit: 60 mA - // preamble length: 8 symbols - // TCXO voltage: 1.6 V (set to 0 to not use TCXO) - // regulator: DC-DC (set to true to use LDO) - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -56,7 +48,7 @@ void loop() { Serial.print(F("[SX1262] Scanning channel for LoRa transmission ... ")); // start scanning current channel - int state = lora.scanChannel(); + int state = radio.scanChannel(); if (state == LORA_DETECTED) { // LoRa preamble was detected diff --git a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino index 90730ed0..13411fdd 100644 --- a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino +++ b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino @@ -9,6 +9,9 @@ modem and use the appropriate configuration methods. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---fsk-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,30 +24,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1262 fsk = new Module(10, 2, 3, 9); +SX1262 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1262 fsk = RadioShield.ModuleA; +//SX1262 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1262 FSK modem with default settings Serial.print(F("[SX1262] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 156.2 kHz - // output power: 14 dBm - // current limit: 60.0 mA - // preamble length: 16 bits - // data shaping: Gaussian, BT = 0.5 - // TCXO voltage: 1.6 V (set to 0 to not use TCXO) - // regulator: DC-DC (set to true to use LDO) - // sync word: 0x2D 0x01 - // CRC: enabled, CRC16 (CCIT) - int state = fsk.beginFSK(); + int state = radio.beginFSK(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -55,21 +46,21 @@ void setup() { // if needed, you can switch between LoRa and FSK modes // - // lora.begin() start LoRa mode (and disable FSK) - // lora.beginFSK() start FSK mode (and disable LoRa) + // radio.begin() start LoRa mode (and disable FSK) + // radio.beginFSK() start FSK mode (and disable LoRa) // the following settings can also // be modified at run-time - state = fsk.setFrequency(433.5); - state = fsk.setBitRate(100.0); - state = fsk.setFrequencyDeviation(10.0); - state = fsk.setRxBandwidth(250.0); - state = fsk.setOutputPower(10.0); - state = fsk.setCurrentLimit(100.0); - state = fsk.setDataShaping(1.0); + state = radio.setFrequency(433.5); + state = radio.setBitRate(100.0); + state = radio.setFrequencyDeviation(10.0); + state = radio.setRxBandwidth(250.0); + state = radio.setOutputPower(10.0); + state = radio.setCurrentLimit(100.0); + state = radio.setDataShaping(1.0); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - state = fsk.setSyncWord(syncWord, 8); + state = radio.setSyncWord(syncWord, 8); if (state != ERR_NONE) { Serial.print(F("Unable to set configuration, code ")); Serial.println(state); @@ -78,15 +69,15 @@ void setup() { // FSK modem on SX126x can handle the sync word setting in bits, not just // whole bytes. The value used is left-justified. - // This makes same result as fsk.setSyncWord(syncWord, 8): - state = fsk.setSyncBits(syncWord, 64); + // This makes same result as radio.setSyncWord(syncWord, 8): + state = radio.setSyncBits(syncWord, 64); // This will use 0x012 as sync word (12 bits only): - state = fsk.setSyncBits(syncWord, 12); + state = radio.setSyncBits(syncWord, 12); // FSK modem allows advanced CRC configuration // Default is CCIT CRC16 (2 bytes, initial 0x1D0F, polynomial 0x1021, inverted) // Set CRC to IBM CRC (2 bytes, initial 0xFFFF, polynomial 0x8005, non-inverted) - state = fsk.setCRC(2, 0xFFFF, 0x8005, false); + state = radio.setCRC(2, 0xFFFF, 0x8005, false); // set CRC length to 0 to disable CRC #warning "This sketch is just an API guide! Read the note at line 6." @@ -97,11 +88,11 @@ void loop() { // as the LoRa modem, even their interrupt-driven versions // transmit FSK packet - int state = fsk.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = lora.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1262] Packet transmitted successfully!")); @@ -116,10 +107,10 @@ void loop() { // receive FSK packet String str; - state = fsk.receive(str); + state = radio.receive(str); /* byte byteArr[8]; - int state = lora.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1262] Received packet!")); @@ -139,13 +130,13 @@ void loop() { // to transmit packet to a particular address, // use the following methods: // - // fsk.transmit("Hello World!", address); - // fsk.startTransmit("Hello World!", address); + // radio.transmit("Hello World!", address); + // radio.startTransmit("Hello World!", address); // set node address to 0x02 - state = fsk.setNodeAddress(0x02); + state = radio.setNodeAddress(0x02); // set broadcast address to 0xFF - state = fsk.setBroadcastAddress(0xFF); + state = radio.setBroadcastAddress(0xFF); if (state != ERR_NONE) { Serial.println(F("[SX1262] Unable to set address filter, code ")); Serial.println(state); @@ -155,7 +146,7 @@ void loop() { // NOTE: calling this method will also erase previously set // node and broadcast address /* - state = fsk.disableAddressFiltering(); + state = radio.disableAddressFiltering(); if (state != ERR_NONE) { Serial.println(F("Unable to remove address filter, code ")); } diff --git a/examples/SX126x/SX126x_Receive/SX126x_Receive.ino b/examples/SX126x/SX126x_Receive/SX126x_Receive.ino index c95592f0..23969cb1 100644 --- a/examples/SX126x/SX126x_Receive/SX126x_Receive.ino +++ b/examples/SX126x/SX126x_Receive/SX126x_Receive.ino @@ -13,6 +13,9 @@ Other modules from SX126x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,29 +28,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1262 lora = new Module(10, 2, 3, 9); +SX1262 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1262 lora = RadioShield.ModuleA; +//SX1262 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1262 with default settings Serial.print(F("[SX1262] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 (private network) - // output power: 14 dBm - // current limit: 60 mA - // preamble length: 8 symbols - // TCXO voltage: 1.6 V (set to 0 to not use TCXO) - // regulator: DC-DC (set to true to use LDO) - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -65,12 +57,12 @@ void loop() { // See example ReceiveInterrupt for details // on non-blocking reception method. String str; - int state = lora.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = lora.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { @@ -84,13 +76,13 @@ void loop() { // print the RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[SX1262] RSSI:\t\t")); - Serial.print(lora.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print the SNR (Signal-to-Noise Ratio) // of the last received packet Serial.print(F("[SX1262] SNR:\t\t")); - Serial.print(lora.getSNR()); + Serial.print(radio.getSNR()); Serial.println(F(" dB")); } else if (state == ERR_RX_TIMEOUT) { diff --git a/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino b/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino index 59d49f53..3932f7b0 100644 --- a/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino +++ b/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino @@ -12,7 +12,10 @@ - coding rate - sync word - Other modules from SX126x/RFM9x family can also be used. + Other modules from SX126x family can also be used. + + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ @@ -26,29 +29,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1262 lora = new Module(10, 2, 3, 9); +SX1262 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1262 lora = RadioShield.ModuleA; +//SX1262 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1262 with default settings Serial.print(F("[SX1262] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 (private network) - // output power: 14 dBm - // current limit: 60 mA - // preamble length: 8 symbols - // TCXO voltage: 1.6 V (set to 0 to not use TCXO) - // regulator: DC-DC (set to true to use LDO) - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -59,11 +51,11 @@ void setup() { // set the function that will be called // when new packet is received - lora.setDio1Action(setFlag); + radio.setDio1Action(setFlag); // start listening for LoRa packets Serial.print(F("[SX1262] Starting to listen ... ")); - state = lora.startReceive(); + state = radio.startReceive(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -75,12 +67,12 @@ void setup() { // if needed, 'listen' mode can be disabled by calling // any of the following methods: // - // lora.standby() - // lora.sleep() - // lora.transmit(); - // lora.receive(); - // lora.readData(); - // lora.scanChannel(); + // radio.standby() + // radio.sleep() + // radio.transmit(); + // radio.receive(); + // radio.readData(); + // radio.scanChannel(); } // flag to indicate that a packet was received @@ -115,12 +107,12 @@ void loop() { // you can read received data as an Arduino String String str; - int state = lora.readData(str); + int state = radio.readData(str); // you can also read received data as byte array /* byte byteArr[8]; - int state = lora.readData(byteArr, 8); + int state = radio.readData(byteArr, 8); */ if (state == ERR_NONE) { @@ -133,12 +125,12 @@ void loop() { // print RSSI (Received Signal Strength Indicator) Serial.print(F("[SX1262] RSSI:\t\t")); - Serial.print(lora.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print SNR (Signal-to-Noise Ratio) Serial.print(F("[SX1262] SNR:\t\t")); - Serial.print(lora.getSNR()); + Serial.print(radio.getSNR()); Serial.println(F(" dB")); } else if (state == ERR_CRC_MISMATCH) { @@ -153,7 +145,7 @@ void loop() { } // put module back to listen mode - lora.startReceive(); + radio.startReceive(); // we're ready to receive more packets, // enable interrupt service routine diff --git a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino index 3da7d650..5e34d203 100644 --- a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino +++ b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino @@ -17,6 +17,9 @@ Other modules from SX126x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -29,14 +32,14 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1262 loraSX1262 = new Module(10, 2, 3, 9); +SX1262 radio1 = new Module(10, 2, 3, 9); // SX12628 has different connections: // NSS pin: 8 // DIO1 pin: 4 // NRST pin: 5 // BUSY pin: 6 -SX1268 loraSX1268 = new Module(8, 4, 5, 6); +SX1268 radio2 = new Module(8, 4, 5, 6); // or using RadioShield // https://github.com/jgromes/RadioShield @@ -47,18 +50,7 @@ void setup() { // initialize SX1268 with default settings Serial.print(F("[SX1262] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 (private network) - // output power: 14 dBm - // current limit: 60 mA - // preamble length: 8 symbols - // TCXO voltage: 1.6 V (set to 0 to not use TCXO) - // regulator: DC-DC (set to true to use LDO) - // CRC: enabled - int state = loraSX1262.begin(); + int state = radio1.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -80,8 +72,7 @@ void setup() { // output power: 2 dBm // current limit: 50 mA // preamble length: 20 symbols - // CRC: enabled - state = loraSX1268.begin(915.0, 500.0, 6, 5, 0x34, 50, 20); + state = radio2.begin(915.0, 500.0, 6, 5, 0x34, 50, 20); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -94,56 +85,56 @@ void setup() { // and check if the configuration was changed successfully // set carrier frequency to 433.5 MHz - if (loraSX1262.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { + if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { Serial.println(F("Selected frequency is invalid for this module!")); while (true); } // set bandwidth to 250 kHz - if (loraSX1262.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) { + if (radio1.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) { Serial.println(F("Selected bandwidth is invalid for this module!")); while (true); } // set spreading factor to 10 - if (loraSX1262.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) { + if (radio1.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) { Serial.println(F("Selected spreading factor is invalid for this module!")); while (true); } // set coding rate to 6 - if (loraSX1262.setCodingRate(6) == ERR_INVALID_CODING_RATE) { + if (radio1.setCodingRate(6) == ERR_INVALID_CODING_RATE) { Serial.println(F("Selected coding rate is invalid for this module!")); while (true); } // set LoRa sync word to 0xAB - if (loraSX1262.setSyncWord(0xAB) != ERR_NONE) { + if (radio1.setSyncWord(0xAB) != ERR_NONE) { Serial.println(F("Unable to set sync word!")); while (true); } // set output power to 10 dBm (accepted range is -17 - 22 dBm) - if (loraSX1262.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) { + if (radio1.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) { Serial.println(F("Selected output power is invalid for this module!")); while (true); } // set over current protection limit to 80 mA (accepted range is 45 - 240 mA) // NOTE: set value to 0 to disable overcurrent protection - if (loraSX1262.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) { + if (radio1.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) { Serial.println(F("Selected current limit is invalid for this module!")); while (true); } // set LoRa preamble length to 15 symbols (accepted range is 0 - 65535) - if (loraSX1262.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) { + if (radio1.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) { Serial.println(F("Selected preamble length is invalid for this module!")); while (true); } // disable CRC - if (loraSX1262.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) { + if (radio1.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) { Serial.println(F("Selected CRC is invalid for this module!")); while (true); } @@ -151,7 +142,7 @@ void setup() { // Some SX126x modules have TCXO (temperature compensated crystal // oscillator). To configure TCXO reference voltage, // the following method can be used. - if (loraSX1262.setTCXO(2.4) == ERR_INVALID_TCXO_VOLTAGE) { + if (radio1.setTCXO(2.4) == ERR_INVALID_TCXO_VOLTAGE) { Serial.println(F("Selected TCXO voltage is invalid for this module!")); while (true); } @@ -160,7 +151,7 @@ void setup() { // this feature, the following method can be used. // NOTE: As long as DIO2 is configured to control RF switch, // it can't be used as interrupt pin! - if (loraSX1262.setDio2AsRfSwitch() != ERR_NONE) { + if (radio1.setDio2AsRfSwitch() != ERR_NONE) { Serial.println(F("Failed to set DIO2 as RF switch!")); while (true); } diff --git a/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino b/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino index 338bf3f5..541645ee 100644 --- a/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino +++ b/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino @@ -9,6 +9,9 @@ Other modules from SX126x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,29 +24,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1262 lora = new Module(10, 2, 3, 9); +SX1262 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1262 lora = RadioShield.ModuleA; +//SX1262 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1262 with default settings Serial.print(F("[SX1262] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 (private network) - // output power: 14 dBm - // current limit: 60 mA - // preamble length: 8 symbols - // TCXO voltage: 1.6 V (set to 0 to not use TCXO) - // regulator: DC-DC (set to true to use LDO) - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -59,7 +51,7 @@ void setup() { // RX enable: 4 // TX enable: 5 /* - lora.setRfSwitchPins(4, 5); + radio.setRfSwitchPins(4, 5); */ } @@ -71,12 +63,12 @@ void loop() { // NOTE: transmit() is a blocking method! // See example SX126x_Transmit_Interrupt for details // on non-blocking transmission method. - int state = lora.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; - int state = lora.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { @@ -85,7 +77,7 @@ void loop() { // print measured data rate Serial.print(F("[SX1262] Datarate:\t")); - Serial.print(lora.getDataRate()); + Serial.print(radio.getDataRate()); Serial.println(F(" bps")); } else if (state == ERR_PACKET_TOO_LONG) { diff --git a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino index 724e05dc..20600a11 100644 --- a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino +++ b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino @@ -10,6 +10,9 @@ Other modules from SX126x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -22,7 +25,11 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1262 lora = new Module(10, 2, 3, 9); +SX1262 radio = new Module(10, 2, 3, 9); + +// or using RadioShield +// https://github.com/jgromes/RadioShield +//SX1262 radio = RadioShield.ModuleA; // save transmission state between loops int transmissionState = ERR_NONE; @@ -32,18 +39,7 @@ void setup() { // initialize SX1262 with default settings Serial.print(F("[SX1262] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 (private network) - // output power: 14 dBm - // current limit: 60 mA - // preamble length: 8 symbols - // TCXO voltage: 1.6 V (set to 0 to not use TCXO) - // regulator: DC-DC (set to true to use LDO) - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -54,20 +50,20 @@ void setup() { // set the function that will be called // when packet transmission is finished - lora.setDio1Action(setFlag); + radio.setDio1Action(setFlag); // start transmitting the first packet Serial.print(F("[SX1262] Sending first packet ... ")); // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = lora.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - state = lora.startTransmit(byteArr, 8); + state = radio.startTransmit(byteArr, 8); */ } @@ -123,13 +119,13 @@ void loop() { // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = lora.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = lora.startTransmit(byteArr, 8); + int state = radio.startTransmit(byteArr, 8); */ // we're ready to send more packets, From 256da12c66aa28d065f9b7b49de7f5ab9d2c4965 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:38:02 +0200 Subject: [PATCH 219/334] [SX127x] Added links to default config wiki page --- .../SX127x_Channel_Activity_Detection.ino | 20 ++---- .../SX127x_FSK_Modem/SX127x_FSK_Modem.ino | 66 +++++++++---------- .../SX127x/SX127x_Receive/SX127x_Receive.ino | 28 ++++---- .../SX127x_Receive_Interrupt.ino | 46 ++++++------- .../SX127x_Settings/SX127x_Settings.ino | 38 +++++------ .../SX127x_Transmit/SX127x_Transmit.ino | 26 +++----- .../SX127x_Transmit_Interrupt.ino | 28 ++++---- 7 files changed, 105 insertions(+), 147 deletions(-) diff --git a/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino b/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino index 4d946254..ececb747 100644 --- a/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino +++ b/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino @@ -9,6 +9,9 @@ Other modules from SX127x/RFM9x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,27 +24,18 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 lora = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 - // output power: 17 dBm - // current limit: 100 mA - // preamble length: 8 symbols - // amplifier gain: 0 (automatic gain control) - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -55,7 +49,7 @@ void loop() { Serial.print(F("[SX1278] Scanning channel for LoRa preamble ... ")); // start scanning current channel - int state = lora.scanChannel(); + int state = radio.scanChannel(); if (state == PREAMBLE_DETECTED) { // LoRa preamble was detected diff --git a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino index 7727bcfe..184008e8 100644 --- a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino +++ b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino @@ -9,6 +9,9 @@ modem and use the appropriate configuration methods. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---fsk-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,7 +24,7 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield @@ -32,16 +35,7 @@ void setup() { // initialize SX1278 FSK modem with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - // data shaping: Gaussian, BT = 0.5 - // sync word: 0x2D 0x01 - // OOK modulation: disabled - int state = fsk.beginFSK(); + int state = radio.beginFSK(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -52,21 +46,21 @@ void setup() { // if needed, you can switch between LoRa and FSK modes // - // lora.begin() start LoRa mode (and disable FSK) - // lora.beginFSK() start FSK mode (and disable LoRa) + // radio.begin() start LoRa mode (and disable FSK) + // radio.beginFSK() start FSK mode (and disable LoRa) // the following settings can also // be modified at run-time - state = fsk.setFrequency(433.5); - state = fsk.setBitRate(100.0); - state = fsk.setFrequencyDeviation(10.0); - state = fsk.setRxBandwidth(250.0); - state = fsk.setOutputPower(10.0); - state = fsk.setCurrentLimit(100); - state = fsk.setDataShaping(0.5); + state = radio.setFrequency(433.5); + state = radio.setBitRate(100.0); + state = radio.setFrequencyDeviation(10.0); + state = radio.setRxBandwidth(250.0); + state = radio.setOutputPower(10.0); + state = radio.setCurrentLimit(100); + state = radio.setDataShaping(0.5); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - state = fsk.setSyncWord(syncWord, 8); + state = radio.setSyncWord(syncWord, 8); if (state != ERR_NONE) { Serial.print(F("Unable to set configuration, code ")); Serial.println(state); @@ -78,8 +72,8 @@ void setup() { // Also, data shaping changes from Gaussian filter to // simple filter with cutoff frequency. Make sure to call // setDataShapingOOK() to set the correct shaping! - state = fsk.setOOK(true); - state = fsk.setDataShapingOOK(1); + state = radio.setOOK(true); + state = radio.setDataShapingOOK(1); if (state != ERR_NONE) { Serial.print(F("Unable to change modulation, code ")); Serial.println(state); @@ -95,11 +89,11 @@ void loop() { // NOTE: FSK modem maximum packet length is 63 bytes! // transmit FSK packet - int state = fsk.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = lora.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1278] Packet transmitted successfully!")); @@ -114,10 +108,10 @@ void loop() { // receive FSK packet String str; - state = fsk.receive(str); + state = radio.receive(str); /* byte byteArr[8]; - int state = lora.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1278] Received packet!")); @@ -137,13 +131,13 @@ void loop() { // to transmit packet to a particular address, // use the following methods: // - // fsk.transmit("Hello World!", address); - // fsk.startTransmit("Hello World!", address); + // radio.transmit("Hello World!", address); + // radio.startTransmit("Hello World!", address); // set node address to 0x02 - state = fsk.setNodeAddress(0x02); + state = radio.setNodeAddress(0x02); // set broadcast address to 0xFF - state = fsk.setBroadcastAddress(0xFF); + state = radio.setBroadcastAddress(0xFF); if (state != ERR_NONE) { Serial.println(F("[SX1278] Unable to set address filter, code ")); Serial.println(state); @@ -153,7 +147,7 @@ void loop() { // NOTE: calling this method will also erase previously set // node and broadcast address /* - state = fsk.disableAddressFiltering(); + state = radio.disableAddressFiltering(); if (state != ERR_NONE) { Serial.println(F("Unable to remove address filter, code ")); } @@ -164,7 +158,7 @@ void loop() { // sent to DIO1 (data) and DIO2 (clock) // activate direct mode transmitter - state = fsk.transmitDirect(); + state = radio.transmitDirect(); if (state != ERR_NONE) { Serial.println(F("[SX1278] Unable to start direct transmission mode, code ")); Serial.println(state); @@ -175,7 +169,7 @@ void loop() { // it is recommended to set data shaping to 0 // (no shaping) when transmitting audio - state = fsk.setDataShaping(0.0); + state = radio.setDataShaping(0.0); if (state != ERR_NONE) { Serial.println(F("[SX1278] Unable to set data shaping, code ")); Serial.println(state); @@ -199,7 +193,7 @@ void loop() { // direct mode transmissions can also be received // as bit stream on DIO1 (data) and DIO2 (clock) - state = fsk.receiveDirect(); + state = radio.receiveDirect(); if (state != ERR_NONE) { Serial.println(F("[SX1278] Unable to start direct reception mode, code ")); Serial.println(state); @@ -207,5 +201,5 @@ void loop() { // NOTE: you will not be able to send or receive packets // while direct mode is active! to deactivate it, call method - // fsk.packetMode() + // radio.packetMode() } diff --git a/examples/SX127x/SX127x_Receive/SX127x_Receive.ino b/examples/SX127x/SX127x_Receive/SX127x_Receive.ino index 5627bdc3..0f839eec 100644 --- a/examples/SX127x/SX127x_Receive/SX127x_Receive.ino +++ b/examples/SX127x/SX127x_Receive/SX127x_Receive.ino @@ -13,6 +13,9 @@ Other modules from SX127x/RFM9x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,27 +28,18 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 lora = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 - // output power: 17 dBm - // current limit: 100 mA - // preamble length: 8 symbols - // amplifier gain: 0 (automatic gain control) - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -63,12 +57,12 @@ void loop() { // See example ReceiveInterrupt for details // on non-blocking reception method. String str; - int state = lora.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = lora.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { @@ -82,19 +76,19 @@ void loop() { // print the RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[SX1278] RSSI:\t\t\t")); - Serial.print(lora.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print the SNR (Signal-to-Noise Ratio) // of the last received packet Serial.print(F("[SX1278] SNR:\t\t\t")); - Serial.print(lora.getSNR()); + Serial.print(radio.getSNR()); Serial.println(F(" dB")); // print frequency error // of the last received packet Serial.print(F("[SX1278] Frequency error:\t")); - Serial.print(lora.getFrequencyError()); + Serial.print(radio.getFrequencyError()); Serial.println(F(" Hz")); } else if (state == ERR_RX_TIMEOUT) { diff --git a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino index 7f192757..8a755bb8 100644 --- a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino +++ b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino @@ -14,6 +14,9 @@ Other modules from SX127x/RFM9x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -26,27 +29,18 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 lora = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 - // output power: 17 dBm - // current limit: 100 mA - // preamble length: 8 symbols - // amplifier gain: 0 (automatic gain control) - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -57,11 +51,11 @@ void setup() { // set the function that will be called // when new packet is received - lora.setDio0Action(setFlag); + radio.setDio0Action(setFlag); // start listening for LoRa packets Serial.print(F("[SX1278] Starting to listen ... ")); - state = lora.startReceive(); + state = radio.startReceive(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -73,12 +67,12 @@ void setup() { // if needed, 'listen' mode can be disabled by calling // any of the following methods: // - // lora.standby() - // lora.sleep() - // lora.transmit(); - // lora.receive(); - // lora.readData(); - // lora.scanChannel(); + // radio.standby() + // radio.sleep() + // radio.transmit(); + // radio.receive(); + // radio.readData(); + // radio.scanChannel(); } // flag to indicate that a packet was received @@ -113,12 +107,12 @@ void loop() { // you can read received data as an Arduino String String str; - int state = lora.readData(str); + int state = radio.readData(str); // you can also read received data as byte array /* byte byteArr[8]; - int state = lora.readData(byteArr, 8); + int state = radio.readData(byteArr, 8); */ if (state == ERR_NONE) { @@ -131,17 +125,17 @@ void loop() { // print RSSI (Received Signal Strength Indicator) Serial.print(F("[SX1278] RSSI:\t\t")); - Serial.print(lora.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print SNR (Signal-to-Noise Ratio) Serial.print(F("[SX1278] SNR:\t\t")); - Serial.print(lora.getSNR()); + Serial.print(radio.getSNR()); Serial.println(F(" dB")); // print frequency error Serial.print(F("[SX1278] Frequency error:\t")); - Serial.print(lora.getFrequencyError()); + Serial.print(radio.getFrequencyError()); Serial.println(F(" Hz")); } else if (state == ERR_CRC_MISMATCH) { @@ -156,7 +150,7 @@ void loop() { } // put module back to listen mode - lora.startReceive(); + radio.startReceive(); // we're ready to receive more packets, // enable interrupt service routine diff --git a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino index 76b26b10..45f637a4 100644 --- a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino +++ b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino @@ -13,6 +13,9 @@ Other modules from SX127x/RFM9x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,14 +28,14 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 loraSX1278 = new Module(10, 2, 9, 3); +SX1278 radio1 = new Module(10, 2, 9, 3); // SX1272 has different connections: // NSS pin: 9 // DIO0 pin: 4 // RESET pin: 5 // DIO1 pin: 6 -SX1272 loraSX1272 = new Module(9, 4, 5, 6); +SX1272 radio2 = new Module(9, 4, 5, 6); // or using RadioShield // https://github.com/jgromes/RadioShield @@ -43,16 +46,7 @@ void setup() { // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 - // output power: 17 dBm - // current limit: 100 mA - // preamble length: 8 symbols - // amplifier gain: 0 (automatic gain control) - int state = loraSX1278.begin(); + int state = radio1.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -79,7 +73,7 @@ void setup() { // current limit: 50 mA // preamble length: 20 symbols // amplifier gain: 1 (maximum gain) - state = loraSX1272.begin(915.0, 500.0, 6, 5, 0x14, 2); + state = radio2.begin(915.0, 500.0, 6, 5, 0x14, 2); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -92,32 +86,32 @@ void setup() { // and check if the configuration was changed successfully // set carrier frequency to 433.5 MHz - if (loraSX1278.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { + if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) { Serial.println(F("Selected frequency is invalid for this module!")); while (true); } // set bandwidth to 250 kHz - if (loraSX1278.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) { + if (radio1.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) { Serial.println(F("Selected bandwidth is invalid for this module!")); while (true); } // set spreading factor to 10 - if (loraSX1278.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) { + if (radio1.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) { Serial.println(F("Selected spreading factor is invalid for this module!")); while (true); } // set coding rate to 6 - if (loraSX1278.setCodingRate(6) == ERR_INVALID_CODING_RATE) { + if (radio1.setCodingRate(6) == ERR_INVALID_CODING_RATE) { Serial.println(F("Selected coding rate is invalid for this module!")); while (true); } // set LoRa sync word to 0x14 // NOTE: value 0x34 is reserved for LoRaWAN networks and should not be used - if (loraSX1278.setSyncWord(0x14) != ERR_NONE) { + if (radio1.setSyncWord(0x14) != ERR_NONE) { Serial.println(F("Unable to set sync word!")); while (true); } @@ -125,20 +119,20 @@ void setup() { // set output power to 10 dBm (accepted range is -3 - 17 dBm) // NOTE: 20 dBm value allows high power operation, but transmission // duty cycle MUST NOT exceed 1% - if (loraSX1278.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) { + if (radio1.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) { Serial.println(F("Selected output power is invalid for this module!")); while (true); } // set over current protection limit to 80 mA (accepted range is 45 - 240 mA) // NOTE: set value to 0 to disable overcurrent protection - if (loraSX1278.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) { + if (radio1.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) { Serial.println(F("Selected current limit is invalid for this module!")); while (true); } // set LoRa preamble length to 15 symbols (accepted range is 6 - 65535) - if (loraSX1278.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) { + if (radio1.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) { Serial.println(F("Selected preamble length is invalid for this module!")); while (true); } @@ -146,7 +140,7 @@ void setup() { // set amplifier gain to 1 (accepted range is 1 - 6, where 1 is maximum gain) // NOTE: set value to 0 to enable automatic gain control // leave at 0 unless you know what you're doing - if (loraSX1278.setGain(1) == ERR_INVALID_GAIN) { + if (radio1.setGain(1) == ERR_INVALID_GAIN) { Serial.println(F("Selected gain is invalid for this module!")); while (true); } diff --git a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino index 265ee32f..6113046b 100644 --- a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino +++ b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino @@ -9,6 +9,9 @@ Other modules from SX127x/RFM9x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,27 +24,18 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 lora = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 - // output power: 17 dBm - // current limit: 100 mA - // preamble length: 8 symbols - // amplifier gain: 0 (automatic gain control) - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -57,7 +51,7 @@ void setup() { // RX enable: 4 // TX enable: 5 /* - lora.setRfSwitchPins(4, 5); + radio.setRfSwitchPins(4, 5); */ } @@ -69,12 +63,12 @@ void loop() { // NOTE: transmit() is a blocking method! // See example SX127x_Transmit_Interrupt for details // on non-blocking transmission method. - int state = lora.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = lora.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { @@ -83,7 +77,7 @@ void loop() { // print measured data rate Serial.print(F("[SX1278] Datarate:\t")); - Serial.print(lora.getDataRate()); + Serial.print(radio.getDataRate()); Serial.println(F(" bps")); } else if (state == ERR_PACKET_TOO_LONG) { diff --git a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino index 0290e54b..7f4b33be 100644 --- a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino +++ b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino @@ -10,6 +10,9 @@ Other modules from SX127x/RFM9x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -22,11 +25,11 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 lora = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // save transmission state between loops int transmissionState = ERR_NONE; @@ -36,16 +39,7 @@ void setup() { // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bandwidth: 125.0 kHz - // spreading factor: 9 - // coding rate: 7 - // sync word: 0x12 - // output power: 17 dBm - // current limit: 100 mA - // preamble length: 8 symbols - // amplifier gain: 0 (automatic gain control) - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -56,20 +50,20 @@ void setup() { // set the function that will be called // when packet transmission is finished - lora.setDio0Action(setFlag); + radio.setDio0Action(setFlag); // start transmitting the first packet Serial.print(F("[SX1278] Sending first packet ... ")); // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = lora.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - state = lora.startTransmit(byteArr, 8); + state = radio.startTransmit(byteArr, 8); */ } @@ -125,13 +119,13 @@ void loop() { // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = lora.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = lora.startTransmit(byteArr, 8); + int state = radio.startTransmit(byteArr, 8); */ // we're ready to send more packets, From 0bf3406d45cdae6326326f8384a53d06227f60e0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:45:56 +0200 Subject: [PATCH 220/334] [SX127x] Fixed typo --- examples/SX127x/SX127x_Settings/SX127x_Settings.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino index 45f637a4..08d1c967 100644 --- a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino +++ b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino @@ -39,7 +39,7 @@ SX1272 radio2 = new Module(9, 4, 5, 6); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1276 loraSX1276 = RadioShield.ModuleB; +//SX1276 radio3 = RadioShield.ModuleB; void setup() { Serial.begin(9600); From 4a4f3256e99ff784b8be7967408025ebf0873078 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:46:20 +0200 Subject: [PATCH 221/334] [SX126x] Fixed typo --- examples/SX126x/SX126x_Settings/SX126x_Settings.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino index 5e34d203..2e500dee 100644 --- a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino +++ b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino @@ -43,7 +43,7 @@ SX1268 radio2 = new Module(8, 4, 5, 6); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1261 loraSX1261 = RadioShield.ModuleB; +//SX1261 radio3 = RadioShield.ModuleB; void setup() { Serial.begin(9600); From 12770ddfdb913ea18abcc17cf6ea609325cdc6a0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 11:47:24 +0200 Subject: [PATCH 222/334] [SX128x] Added links to default config wiki page --- .../SX128x_BLE_Modem/SX128x_BLE_Modem.ino | 42 ++++++++--------- .../SX128x_Channel_Activity_Detection.ino | 18 +++----- .../SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino | 45 +++++++++---------- .../SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino | 43 ++++++++---------- .../SX128x/SX128x_Ranging/SX128x_Ranging.ino | 22 ++++----- .../SX128x/SX128x_Receive/SX128x_Receive.ino | 24 +++++----- .../SX128x_Receive_Interrupt.ino | 42 ++++++++--------- .../SX128x_Settings/SX128x_Settings.ino | 35 +++++++-------- .../SX128x_Transmit/SX128x_Transmit.ino | 15 ++++--- .../SX128x_Transmit_Interrupt.ino | 26 +++++------ 10 files changed, 138 insertions(+), 174 deletions(-) diff --git a/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino b/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino index abf6a582..96a96ffa 100644 --- a/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino +++ b/examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino @@ -11,6 +11,9 @@ modem and use the appropriate configuration methods. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---ble-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -23,25 +26,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 ble = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 ble = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bit rate: 800 kbps - // frequency deviation: 400.0 kHz - // output power: 10 dBm - // preamble length: 16 bits - // data shaping: Gaussian, BT = 0.5 - // CRC: enabled, CRC16 (CCIT) - int state = ble.beginBLE(); + int state = radio.beginBLE(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -50,19 +46,19 @@ void setup() { while (true); } - // if needed, you can switch between LoRa and FSK modes + // if needed, you can switch between any of the modems // - // ble.begin() start LoRa mode (and disable BLE) - // lora.beginBLE() start BLE mode (and disable LoRa) + // radio.begin() start LoRa modem (and disable BLE) + // radio.beginBLE() start BLE modem (and disable LoRa) // the following settings can also // be modified at run-time - state = ble.setFrequency(2410.5); - state = ble.setBitRate(250); - state = ble.setFrequencyDeviation(100.0); - state = ble.setOutputPower(5); - state = ble.setDataShaping(1.0); - state = ble.setAccessAddress(0x12345678); + state = radio.setFrequency(2410.5); + state = radio.setBitRate(250); + state = radio.setFrequencyDeviation(100.0); + state = radio.setOutputPower(5); + state = radio.setDataShaping(1.0); + state = radio.setAccessAddress(0x12345678); if (state != ERR_NONE) { Serial.print(F("Unable to set configuration, code ")); Serial.println(state); @@ -77,11 +73,11 @@ void loop() { // as the LoRa modem, even their interrupt-driven versions // transmit BLE packet - int state = ble.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = ble.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1280] Packet transmitted successfully!")); @@ -96,10 +92,10 @@ void loop() { // receive BLE packet String str; - state = ble.receive(str); + state = radio.receive(str); /* byte byteArr[8]; - int state = ble.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1280] Received packet!")); diff --git a/examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino b/examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino index 6ec30377..cec1560a 100644 --- a/examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino +++ b/examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino @@ -6,6 +6,9 @@ Other modules from SX128x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -18,25 +21,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 lora = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 lora = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bandwidth: 812.5 kHz - // spreading factor: 9 - // coding rate: 7 - // output power: 10 dBm - // preamble length: 12 symbols - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -50,7 +46,7 @@ void loop() { Serial.print(F("[SX1280] Scanning channel for LoRa transmission ... ")); // start scanning current channel - int state = lora.scanChannel(); + int state = radio.scanChannel(); if (state == LORA_DETECTED) { // LoRa preamble was detected diff --git a/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino b/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino index af680b50..cf2d0e7c 100644 --- a/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino +++ b/examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino @@ -9,6 +9,9 @@ modem and use the appropriate configuration methods. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---flrc-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,26 +24,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 flrc = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 flrc = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bit rate: 650 kbps - // coding rate: 3 - // output power: 10 dBm - // preamble length: 16 bits - // data shaping: Gaussian, BT = 0.5 - // sync word: 0x2D 0x01 0x4B 0x1D - // CRC: enabled - int state = flrc.beginFLRC(); + int state = radio.beginFLRC(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -49,20 +44,20 @@ void setup() { while (true); } - // if needed, you can switch between LoRa and FLRC modes + // if needed, you can switch between any of the modems // - // flrc.begin() start LoRa mode (and disable FLRC) - // lora.beginFLRC() start FLRC mode (and disable LoRa) + // radio.begin() start LoRa modem (and disable FLRC) + // radio.beginFLRC() start FLRC modem (and disable LoRa) // the following settings can also // be modified at run-time - state = flrc.setFrequency(2410.5); - state = flrc.setBitRate(520); - state = flrc.setCodingRate(2); - state = flrc.setOutputPower(5); - state = flrc.setDataShaping(1.0); + state = radio.setFrequency(2410.5); + state = radio.setBitRate(520); + state = radio.setCodingRate(2); + state = radio.setOutputPower(5); + state = radio.setDataShaping(1.0); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67}; - state = flrc.setSyncWord(syncWord, 4); + state = radio.setSyncWord(syncWord, 4); if (state != ERR_NONE) { Serial.print(F("Unable to set configuration, code ")); Serial.println(state); @@ -77,11 +72,11 @@ void loop() { // as the LoRa modem, even their interrupt-driven versions // transmit FLRC packet - int state = flrc.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = flrc.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1280] Packet transmitted successfully!")); @@ -94,12 +89,12 @@ void loop() { Serial.println(state); } - // receive GFSK packet + // receive FLRC packet String str; - state = flrc.receive(str); + state = radio.receive(str); /* byte byteArr[8]; - int state = flrc.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1280] Received packet!")); diff --git a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino index adfc5320..4ef75900 100644 --- a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino +++ b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino @@ -9,6 +9,9 @@ modem and use the appropriate configuration methods. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---gfsk-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,26 +24,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 gfsk = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 lora = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bit rate: 800 kbps - // frequency deviation: 400.0 kHz - // output power: 10 dBm - // preamble length: 16 bits - // data shaping: Gaussian, BT = 0.5 - // sync word: 0x2D 0x01 - // CRC: enabled, CRC16 (CCIT) - int state = gfsk.beginGFSK(); + int state = radio.beginGFSK(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -49,20 +44,20 @@ void setup() { while (true); } - // if needed, you can switch between LoRa and FSK modes + // if needed, you can switch between any of the modems // - // gfsk.begin() start LoRa mode (and disable GFSK) - // lora.beginGFSK() start GFSK mode (and disable LoRa) + // radio.begin() start LoRa modem (and disable GFSK) + // radio.beginGFSK() start GFSK modem (and disable LoRa) // the following settings can also // be modified at run-time - state = gfsk.setFrequency(2410.5); - state = gfsk.setBitRate(200); - state = gfsk.setFrequencyDeviation(100.0); - state = gfsk.setOutputPower(5); - state = gfsk.setDataShaping(1.0); + state = radio.setFrequency(2410.5); + state = radio.setBitRate(200); + state = radio.setFrequencyDeviation(100.0); + state = radio.setOutputPower(5); + state = radio.setDataShaping(1.0); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89}; - state = gfsk.setSyncWord(syncWord, 5); + state = radio.setSyncWord(syncWord, 5); if (state != ERR_NONE) { Serial.print(F("Unable to set configuration, code ")); Serial.println(state); @@ -77,11 +72,11 @@ void loop() { // as the LoRa modem, even their interrupt-driven versions // transmit GFSK packet - int state = gfsk.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = gfsk.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1280] Packet transmitted successfully!")); @@ -96,10 +91,10 @@ void loop() { // receive GFSK packet String str; - state = gfsk.receive(str); + state = radio.receive(str); /* byte byteArr[8]; - int state = gfsk.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { Serial.println(F("[SX1280] Received packet!")); diff --git a/examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino b/examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino index 585f948b..f53b1a2d 100644 --- a/examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino +++ b/examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino @@ -8,6 +8,9 @@ Only SX1280 and SX1282 support ranging! + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -20,25 +23,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 lora = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 lora = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bandwidth: 812.5 kHz - // spreading factor: 9 - // coding rate: 7 - // output power: 10 dBm - // preamble length: 12 symbols - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -54,18 +50,18 @@ void loop() { // start ranging exchange // range as master: true // slave address: 0x12345678 - int state = lora.range(true, 0x12345678); + int state = radio.range(true, 0x12345678); // the other module must be configured as slave with the same address /* - int state = lora.range(false, 0x12345678); + int state = radio.range(false, 0x12345678); */ if (state == ERR_NONE) { // ranging finished successfully Serial.println(F("success!")); Serial.print(F("[SX1280] Distance:\t\t\t")); - Serial.print(lora.getRangingResult()); + Serial.print(radio.getRangingResult()); Serial.println(F(" meters")); } else if (state == ERR_RANGING_TIMEOUT) { diff --git a/examples/SX128x/SX128x_Receive/SX128x_Receive.ino b/examples/SX128x/SX128x_Receive/SX128x_Receive.ino index 0427cf41..ff5adc41 100644 --- a/examples/SX128x/SX128x_Receive/SX128x_Receive.ino +++ b/examples/SX128x/SX128x_Receive/SX128x_Receive.ino @@ -13,6 +13,9 @@ Other modules from SX128x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,25 +28,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 lora = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 lora = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bandwidth: 812.5 kHz - // spreading factor: 9 - // coding rate: 7 - // output power: 10 dBm - // preamble length: 12 symbols - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -61,12 +57,12 @@ void loop() { // See example ReceiveInterrupt for details // on non-blocking reception method. String str; - int state = lora.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = lora.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { @@ -80,13 +76,13 @@ void loop() { // print the RSSI (Received Signal Strength Indicator) // of the last received packet Serial.print(F("[SX1280] RSSI:\t\t")); - Serial.print(lora.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print the SNR (Signal-to-Noise Ratio) // of the last received packet Serial.print(F("[SX1280] SNR:\t\t")); - Serial.print(lora.getSNR()); + Serial.print(radio.getSNR()); Serial.println(F(" dB")); } else if (state == ERR_RX_TIMEOUT) { diff --git a/examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino b/examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino index 2d6f1664..65e03f7d 100644 --- a/examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino +++ b/examples/SX128x/SX128x_Receive_Interrupt/SX128x_Receive_Interrupt.ino @@ -14,6 +14,9 @@ Other modules from SX128x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -26,25 +29,18 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 lora = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 lora = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bandwidth: 812.5 kHz - // spreading factor: 9 - // coding rate: 7 - // output power: 10 dBm - // preamble length: 12 symbols - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -55,11 +51,11 @@ void setup() { // set the function that will be called // when new packet is received - lora.setDio1Action(setFlag); + radio.setDio1Action(setFlag); // start listening for LoRa packets Serial.print(F("[SX1280] Starting to listen ... ")); - state = lora.startReceive(); + state = radio.startReceive(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -71,12 +67,12 @@ void setup() { // if needed, 'listen' mode can be disabled by calling // any of the following methods: // - // lora.standby() - // lora.sleep() - // lora.transmit(); - // lora.receive(); - // lora.readData(); - // lora.scanChannel(); + // radio.standby() + // radio.sleep() + // radio.transmit(); + // radio.receive(); + // radio.readData(); + // radio.scanChannel(); } // flag to indicate that a packet was received @@ -111,12 +107,12 @@ void loop() { // you can read received data as an Arduino String String str; - int state = lora.readData(str); + int state = radio.readData(str); // you can also read received data as byte array /* byte byteArr[8]; - int state = lora.readData(byteArr, 8); + int state = radio.readData(byteArr, 8); */ if (state == ERR_NONE) { @@ -129,12 +125,12 @@ void loop() { // print RSSI (Received Signal Strength Indicator) Serial.print(F("[SX1280] RSSI:\t\t")); - Serial.print(lora.getRSSI()); + Serial.print(radio.getRSSI()); Serial.println(F(" dBm")); // print SNR (Signal-to-Noise Ratio) Serial.print(F("[SX1280] SNR:\t\t")); - Serial.print(lora.getSNR()); + Serial.print(radio.getSNR()); Serial.println(F(" dB")); } else if (state == ERR_CRC_MISMATCH) { @@ -149,7 +145,7 @@ void loop() { } // put module back to listen mode - lora.startReceive(); + radio.startReceive(); // we're ready to receive more packets, // enable interrupt service routine diff --git a/examples/SX128x/SX128x_Settings/SX128x_Settings.ino b/examples/SX128x/SX128x_Settings/SX128x_Settings.ino index 49d218d6..0963d85a 100644 --- a/examples/SX128x/SX128x_Settings/SX128x_Settings.ino +++ b/examples/SX128x/SX128x_Settings/SX128x_Settings.ino @@ -14,6 +14,9 @@ Other modules from SX128x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -26,32 +29,25 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 loraSX1280 = new Module(10, 2, 3, 9); +SX1280 radio1 = new Module(10, 2, 3, 9); // SX1280 has the following connections: // NSS pin: 8 // DIO1 pin: 4 // NRST pin: 5 // BUSY pin: 6 -SX1281 loraSX1281 = new Module(8, 4, 5, 6); +SX1281 radio2 = new Module(8, 4, 5, 6); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1282 loraSX1282 = RadioShield.ModuleB; +//SX1282 radio3 = RadioShield.ModuleB; void setup() { Serial.begin(9600); // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bandwidth: 812.5 kHz - // spreading factor: 9 - // coding rate: 7 - // output power: 10 dBm - // preamble length: 12 symbols - // CRC: enabled - int state = loraSX1280.begin(); + int state = radio1.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -71,8 +67,7 @@ void setup() { // coding rate: 5 // output power: 2 dBm // preamble length: 20 symbols - // CRC: enabled - state = loraSX1281.begin(2450.0, 1625.0, 7, 5, 2, 20); + state = radio2.begin(2450.0, 1625.0, 7, 5, 2, 20); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -85,43 +80,43 @@ void setup() { // and check if the configuration was changed successfully // set carrier frequency to 2410.5 MHz - if (loraSX1280.setFrequency(2410.5) == ERR_INVALID_FREQUENCY) { + if (radio1.setFrequency(2410.5) == ERR_INVALID_FREQUENCY) { Serial.println(F("Selected frequency is invalid for this module!")); while (true); } // set bandwidth to 203.125 kHz - if (loraSX1280.setBandwidth(203.125) == ERR_INVALID_BANDWIDTH) { + if (radio1.setBandwidth(203.125) == ERR_INVALID_BANDWIDTH) { Serial.println(F("Selected bandwidth is invalid for this module!")); while (true); } // set spreading factor to 10 - if (loraSX1280.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) { + if (radio1.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) { Serial.println(F("Selected spreading factor is invalid for this module!")); while (true); } // set coding rate to 6 - if (loraSX1280.setCodingRate(6) == ERR_INVALID_CODING_RATE) { + if (radio1.setCodingRate(6) == ERR_INVALID_CODING_RATE) { Serial.println(F("Selected coding rate is invalid for this module!")); while (true); } // set output power to -2 dBm - if (loraSX1280.setOutputPower(-2) == ERR_INVALID_OUTPUT_POWER) { + if (radio1.setOutputPower(-2) == ERR_INVALID_OUTPUT_POWER) { Serial.println(F("Selected output power is invalid for this module!")); while (true); } // set LoRa preamble length to 16 symbols (accepted range is 2 - 65535) - if (loraSX1280.setPreambleLength(16) == ERR_INVALID_PREAMBLE_LENGTH) { + if (radio1.setPreambleLength(16) == ERR_INVALID_PREAMBLE_LENGTH) { Serial.println(F("Selected preamble length is invalid for this module!")); while (true); } // disable CRC - if (loraSX1280.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) { + if (radio1.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) { Serial.println(F("Selected CRC is invalid for this module!")); while (true); } diff --git a/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino b/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino index b86259cf..a4037def 100644 --- a/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino +++ b/examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino @@ -9,6 +9,9 @@ Other modules from SX128x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -21,11 +24,11 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 lora = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 lora = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); @@ -39,7 +42,7 @@ void setup() { // output power: 10 dBm // preamble length: 12 symbols // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -55,7 +58,7 @@ void setup() { // RX enable: 4 // TX enable: 5 /* - lora.setRfSwitchPins(4, 5); + radio.setRfSwitchPins(4, 5); */ } @@ -67,12 +70,12 @@ void loop() { // NOTE: transmit() is a blocking method! // See example SX128x_Transmit_Interrupt for details // on non-blocking transmission method. - int state = lora.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; - int state = lora.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino b/examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino index 284244e8..ecdd9312 100644 --- a/examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino +++ b/examples/SX128x/SX128x_Transmit_Interrupt/SX128x_Transmit_Interrupt.ino @@ -10,6 +10,9 @@ Other modules from SX128x family can also be used. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -22,11 +25,11 @@ // DIO1 pin: 2 // NRST pin: 3 // BUSY pin: 9 -SX1280 lora = new Module(10, 2, 3, 9); +SX1280 radio = new Module(10, 2, 3, 9); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1280 lora = RadioShield.ModuleA; +//SX1280 radio = RadioShield.ModuleA; // save transmission state between loops int transmissionState = ERR_NONE; @@ -36,14 +39,7 @@ void setup() { // initialize SX1280 with default settings Serial.print(F("[SX1280] Initializing ... ")); - // carrier frequency: 2400.0 MHz - // bandwidth: 812.5 kHz - // spreading factor: 9 - // coding rate: 7 - // output power: 10 dBm - // preamble length: 12 symbols - // CRC: enabled - int state = lora.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -54,20 +50,20 @@ void setup() { // set the function that will be called // when packet transmission is finished - lora.setDio1Action(setFlag); + radio.setDio1Action(setFlag); // start transmitting the first packet Serial.print(F("[SX1280] Sending first packet ... ")); // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = lora.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - state = lora.startTransmit(byteArr, 8); + state = radio.startTransmit(byteArr, 8); */ } @@ -119,13 +115,13 @@ void loop() { // you can transmit C-string or Arduino string up to // 256 characters long - transmissionState = lora.startTransmit("Hello World!"); + transmissionState = radio.startTransmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = lora.startTransmit(byteArr, 8); + int state = radio.startTransmit(byteArr, 8); */ // we're ready to send more packets, From a31a028e4e84e678725fec3a32143232d36b0b35 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:02:35 +0200 Subject: [PATCH 223/334] [AFSK] Added links to default config wiki page --- .../AFSK_Imperial_March.ino | 19 +++++++-------- examples/AFSK/AFSK_Tone/AFSK_Tone.ino | 23 ++++++++----------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino b/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino index 9b80046e..29469f48 100644 --- a/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino +++ b/examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino @@ -10,6 +10,9 @@ - CC1101 - Si443x/RFM2x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,7 +28,7 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // create AFSK client instance using the FSK module // this requires connection to the module direct @@ -35,24 +38,18 @@ SX1278 fsk = new Module(10, 2, 9, 3); // SX1231: DIO2 // CC1101: GDO2 // Si443x/RFM2x: GPIO -AFSKClient audio(&fsk, 5); +AFSKClient audio(&radio, 5); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - int state = fsk.beginFSK(); + int state = radio.beginFSK(); // when using one of the non-LoRa modules for AFSK // (RF69, CC1101,, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); diff --git a/examples/AFSK/AFSK_Tone/AFSK_Tone.ino b/examples/AFSK/AFSK_Tone/AFSK_Tone.ino index 09e66c28..43286f84 100644 --- a/examples/AFSK/AFSK_Tone/AFSK_Tone.ino +++ b/examples/AFSK/AFSK_Tone/AFSK_Tone.ino @@ -11,6 +11,9 @@ - CC1101 - Si443x/RFM2x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -23,34 +26,28 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // create AFSK client instance using the FSK module -// this requires connection to the module direct +// this requires connection to the module direct // input pin, here connected to Arduino pin 5 // SX127x/RFM9x: DIO2 // RF69: DIO2 // SX1231: DIO2 // CC1101: GDO2 // Si443x/RFM2x: GPIO -AFSKClient audio(&fsk, 5); +AFSKClient audio(&radio, 5); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - int state = fsk.beginFSK(); + int state = radio.beginFSK(); // when using one of the non-LoRa modules for AFSK // (RF69, CC1101,, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); @@ -62,7 +59,7 @@ void setup() { } void loop() { - // AFSKClient can be used to transmit tones, + // AFSKClient can be used to transmit tones, // same as Arduino tone() function // 400 Hz tone From 41db6b18bfbe20f84e4ef20af389f2f6b4730bd5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:02:47 +0200 Subject: [PATCH 224/334] [AX25] Added links to default config wiki page --- examples/AX25/AX25_Frames/AX25_Frames.ino | 13 +++++++----- examples/AX25/AX25_Transmit/AX25_Transmit.ino | 13 +++++++----- .../AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino | 21 ++++++++----------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/examples/AX25/AX25_Frames/AX25_Frames.ino b/examples/AX25/AX25_Frames/AX25_Frames.ino index 4289c866..0167214c 100644 --- a/examples/AX25/AX25_Frames/AX25_Frames.ino +++ b/examples/AX25/AX25_Frames/AX25_Frames.ino @@ -20,6 +20,9 @@ exhaustive; all possible AX.25 frames should be supported. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -32,14 +35,14 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create AX.25 client instance using the FSK module -AX25Client ax25(&fsk); +AX25Client ax25(&radio); void setup() { Serial.begin(9600); @@ -49,11 +52,11 @@ void setup() { // carrier frequency: 434.0 MHz // bit rate: 1.2 kbps (1200 baud 2-FSK AX.25) // frequency deviation: 0.5 kHz (1200 baud 2-FSK AX.25) - int state = fsk.beginFSK(434.0, 1.2, 0.5); + int state = radio.beginFSK(434.0, 1.2, 0.5); // when using one of the non-LoRa modules for AX.25 // (RF69, CC1101, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); diff --git a/examples/AX25/AX25_Transmit/AX25_Transmit.ino b/examples/AX25/AX25_Transmit/AX25_Transmit.ino index 6ab9c59e..2ed78875 100644 --- a/examples/AX25/AX25_Transmit/AX25_Transmit.ino +++ b/examples/AX25/AX25_Transmit/AX25_Transmit.ino @@ -13,6 +13,9 @@ - nRF24 - Si443x/RFM2x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,14 +28,14 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create AX.25 client instance using the FSK module -AX25Client ax25(&fsk); +AX25Client ax25(&radio); void setup() { Serial.begin(9600); @@ -42,11 +45,11 @@ void setup() { // carrier frequency: 434.0 MHz // bit rate: 1.2 kbps (1200 baud 2-FSK AX.25) // frequency deviation: 0.5 kHz (1200 baud 2-FSK AX.25) - int state = fsk.beginFSK(434.0, 1.2, 0.5); + int state = radio.beginFSK(434.0, 1.2, 0.5); // when using one of the non-LoRa modules for AX.25 // (RF69, CC1101,, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); diff --git a/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino index d55e14aa..703847af 100644 --- a/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino +++ b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino @@ -14,6 +14,9 @@ - nRF24 - Si443x/RFM2x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -26,15 +29,15 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create AFSK client instance using the FSK module // pin 5 is connected to SX1278 DIO2 -AFSKClient audio(&fsk, 5); +AFSKClient audio(&radio, 5); // create AX.25 client instance using the AFSK instance AX25Client ax25(&audio); @@ -42,19 +45,13 @@ AX25Client ax25(&audio); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - int state = fsk.beginFSK(); + int state = radio.beginFSK(); // when using one of the non-LoRa modules for AX.25 // (RF69, CC1101,, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); From fd69e8a29459f4286ae8526189f093b0657d9154 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:02:57 +0200 Subject: [PATCH 225/334] [Hell] Added links to default config wiki page --- .../Hellschreiber_Transmit.ino | 24 ++++++++----------- .../Hellschreiber_Transmit_AFSK.ino | 23 ++++++++---------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino b/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino index a8dda9f0..edadc5d6 100644 --- a/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino +++ b/examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino @@ -14,6 +14,9 @@ - Si443x/RFM2x - SX128x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -26,32 +29,25 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create Hellschreiber client instance using the FSK module -HellClient hell(&fsk); +HellClient hell(&radio); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - // sync word: 0x2D 0x01 - int state = fsk.beginFSK(); + int state = radio.beginFSK(); // when using one of the non-LoRa modules for Morse code // (RF69, CC1101, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); @@ -109,7 +105,7 @@ void loop() { float f = -3.1415; hell.println(f, 3); - // custom glyph - must be a 7 byte array of rows 7 pixels long + // custom glyph - must be a 7 byte array of rows 7 pixels long uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 }; hell.printGlyph(customGlyph); diff --git a/examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino b/examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino index ec2aa4e7..1938f34c 100644 --- a/examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino +++ b/examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino @@ -13,6 +13,9 @@ - CC1101 - Si443x/RFM2x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,15 +28,15 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create AFSK client instance using the FSK module // pin 5 is connected to SX1278 DIO2 -AFSKClient audio(&fsk, 5); +AFSKClient audio(&radio, 5); // create Hellschreiber client instance using the AFSK instance HellClient hell(&audio); @@ -41,19 +44,13 @@ HellClient hell(&audio); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - int state = fsk.beginFSK(); + int state = radio.beginFSK(); // when using one of the non-LoRa modules for Morse code // (RF69, CC1101, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); @@ -111,7 +108,7 @@ void loop() { float f = -3.1415; hell.println(f, 3); - // custom glyph - must be a 7 byte array of rows 7 pixels long + // custom glyph - must be a 7 byte array of rows 7 pixels long uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 }; hell.printGlyph(customGlyph); From 96f7a51ec9416b4409ab54aa3e9b72a778ee2a37 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:03:04 +0200 Subject: [PATCH 226/334] [Morse] Added links to default config wiki page --- .../Morse/Morse_Transmit/Morse_Transmit.ino | 24 ++++++++----------- .../Morse_Transmit_AFSK.ino | 23 ++++++++---------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/examples/Morse/Morse_Transmit/Morse_Transmit.ino b/examples/Morse/Morse_Transmit/Morse_Transmit.ino index 4f3c07e4..9c39a3b7 100644 --- a/examples/Morse/Morse_Transmit/Morse_Transmit.ino +++ b/examples/Morse/Morse_Transmit/Morse_Transmit.ino @@ -14,6 +14,9 @@ - Si443x/RFM2x - SX128x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -26,32 +29,25 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create Morse client instance using the FSK module -MorseClient morse(&fsk); +MorseClient morse(&radio); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - // sync word: 0x2D 0x01 - int state = fsk.beginFSK(); - + int state = radio.beginFSK(); + // when using one of the non-LoRa modules for Morse code // (RF69, CC1101, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); diff --git a/examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino b/examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino index 3dbb5d6f..ad89cb49 100644 --- a/examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino +++ b/examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino @@ -13,6 +13,9 @@ - CC1101 - Si443x/RFM2x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -25,15 +28,15 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create AFSK client instance using the FSK module // pin 5 is connected to SX1278 DIO2 -AFSKClient audio(&fsk, 5); +AFSKClient audio(&radio, 5); // create Morse client instance using the AFSK instance MorseClient morse(&audio); @@ -41,19 +44,13 @@ MorseClient morse(&audio); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - int state = fsk.beginFSK(); - + int state = radio.beginFSK(); + // when using one of the non-LoRa modules for Morse code // (RF69, CC1101, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); From 92ded012349d211427d36ee9e66d1291c52e86cc Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:03:11 +0200 Subject: [PATCH 227/334] [RTTY] Added links to default config wiki page --- examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino | 22 ++++++++----------- .../RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino | 21 ++++++++---------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino b/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino index f565c6f0..80c3c67f 100644 --- a/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino +++ b/examples/RTTY/RTTY_Transmit/RTTY_Transmit.ino @@ -14,6 +14,9 @@ - Si443x/RFM2x - SX128x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -26,32 +29,25 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create RTTY client instance using the FSK module -RTTYClient rtty(&fsk); +RTTYClient rtty(&radio); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - // sync word: 0x2D 0x01 - int state = fsk.beginFSK(); + int state = radio.beginFSK(); // when using one of the non-LoRa modules for RTTY // (RF69, CC1101, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); diff --git a/examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino b/examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino index d836821e..23a66598 100644 --- a/examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino +++ b/examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino @@ -11,6 +11,9 @@ - CC1101 - Si443x/RFM2x + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -23,15 +26,15 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create AFSK client instance using the FSK module // pin 5 is connected to SX1278 DIO2 -AFSKClient audio(&fsk, 5); +AFSKClient audio(&radio, 5); // create RTTY client instance using the AFSK instance RTTYClient rtty(&audio); @@ -39,19 +42,13 @@ RTTYClient rtty(&audio); void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - int state = fsk.beginFSK(); + int state = radio.beginFSK(); // when using one of the non-LoRa modules for RTTY // (RF69, CC1101, Si4432 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); if(state == ERR_NONE) { Serial.println(F("success!")); From ffe535c873489c490dadd09b524382bd2b47e532 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:03:17 +0200 Subject: [PATCH 228/334] [SSTV] Added links to default config wiki page --- examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino | 24 ++++++++----------- .../SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino | 23 ++++++++---------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino b/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino index 92bdde6f..6b06bae3 100644 --- a/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino +++ b/examples/SSTV/SSTV_Transmit/SSTV_Transmit.ino @@ -25,6 +25,9 @@ lower speed modes such as Wrasse, Scottie1 or Martin1 are recommended. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -37,14 +40,14 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create SSTV client instance using the FSK module -SSTVClient sstv(&fsk); +SSTVClient sstv(&radio); // test "image" - actually just a single 320px line // will be sent over and over again, to create vertical color stripes at the receiver @@ -85,16 +88,9 @@ uint32_t line[320] = { void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - // sync word: 0x2D 0x01 - int state = fsk.beginFSK(); + int state = radio.beginFSK(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -105,7 +101,7 @@ void setup() { // when using one of the non-LoRa modules for SSTV // (RF69, SX1231 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); // initialize SSTV client Serial.print(F("[SSTV] Initializing ... ")); @@ -152,7 +148,7 @@ void loop() { } // turn off transmitter - fsk.standby(); + radio.standby(); Serial.println(F("done!")); diff --git a/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino b/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino index b43c3743..e27bf67e 100644 --- a/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino +++ b/examples/SSTV/SSTV_Transmit_AFSK/SSTV_Transmit_AFSK.ino @@ -20,6 +20,9 @@ lower speed modes such as Wrasse, Scottie1 or Martin1 are recommended. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -32,15 +35,15 @@ // DIO0 pin: 2 // RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 9, 3); +SX1278 radio = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1278 fsk = RadioShield.ModuleA; +//SX1278 radio = RadioShield.ModuleA; // create AFSK client instance using the FSK module // pin 5 is connected to SX1278 DIO2 -AFSKClient audio(&fsk, 5); +AFSKClient audio(&radio, 5); // create SSTV client instance using the AFSK instance SSTVClient sstv(&audio); @@ -84,15 +87,9 @@ uint32_t line[320] = { void setup() { Serial.begin(9600); - // initialize SX1278 + // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // frequency deviation: 50.0 kHz - // Rx bandwidth: 125.0 kHz - // output power: 13 dBm - // current limit: 100 mA - int state = fsk.beginFSK(); + int state = radio.beginFSK(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -103,7 +100,7 @@ void setup() { // when using one of the non-LoRa modules for SSTV // (RF69, SX1231 etc.), use the basic begin() method - // int state = fsk.begin(); + // int state = radio.begin(); // initialize SSTV client Serial.print(F("[SSTV] Initializing ... ")); @@ -147,7 +144,7 @@ void loop() { } // turn off transmitter - fsk.standby(); + radio.standby(); Serial.println(F("done!")); From 305e187bfe73695755887f38c97810d23b220e1a Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:03:26 +0200 Subject: [PATCH 229/334] [SX1231] Added links to default config wiki page --- .../SX1231/SX1231_Receive/SX1231_Receive.ino | 19 ++++++++----------- .../SX1231_Transmit/SX1231_Transmit.ino | 19 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/examples/SX1231/SX1231_Receive/SX1231_Receive.ino b/examples/SX1231/SX1231_Receive/SX1231_Receive.ino index 727de1e5..18d0354c 100644 --- a/examples/SX1231/SX1231_Receive/SX1231_Receive.ino +++ b/examples/SX1231/SX1231_Receive/SX1231_Receive.ino @@ -7,6 +7,9 @@ interface. Please see RF69 examples for examples on AES, address filtering, interrupts and settings. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -18,24 +21,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -SX1231 rf = new Module(10, 2, 3); +SX1231 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1231 rf = RadioShield.ModuleA; +//SX1231 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1231 with default settings Serial.print(F("[SX1231] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // Rx bandwidth: 125.0 kHz - // frequency deviation: 50.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -50,12 +47,12 @@ void loop() { // you can receive data as an Arduino String String str; - int state = rf.receive(str); + int state = radio.receive(str); // you can also receive data as byte array /* byte byteArr[8]; - int state = rf.receive(byteArr, 8); + int state = radio.receive(byteArr, 8); */ if (state == ERR_NONE) { diff --git a/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino b/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino index e651202a..0f8cd14b 100644 --- a/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino +++ b/examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino @@ -7,6 +7,9 @@ interface. Please see RF69 examples for examples on AES, address filtering, interrupts and settings. + For default module settings, see the wiki page + https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 + For full API reference, see the GitHub Pages https://jgromes.github.io/RadioLib/ */ @@ -18,24 +21,18 @@ // CS pin: 10 // DIO0 pin: 2 // RESET pin: 3 -SX1231 rf = new Module(10, 2, 3); +SX1231 radio = new Module(10, 2, 3); // or using RadioShield // https://github.com/jgromes/RadioShield -//SX1231 rf = RadioShield.ModuleA; +//SX1231 radio = RadioShield.ModuleA; void setup() { Serial.begin(9600); // initialize SX1231 with default settings Serial.print(F("[SX1231] Initializing ... ")); - // carrier frequency: 434.0 MHz - // bit rate: 48.0 kbps - // Rx bandwidth: 125.0 kHz - // frequency deviation: 50.0 kHz - // output power: 13 dBm - // sync word: 0x2D01 - int state = rf.begin(); + int state = radio.begin(); if (state == ERR_NONE) { Serial.println(F("success!")); } else { @@ -49,12 +46,12 @@ void loop() { Serial.print(F("[SX1231] Transmitting packet ... ")); // you can transmit C-string or Arduino string up to 256 characters long - int state = rf.transmit("Hello World!"); + int state = radio.transmit("Hello World!"); // you can also transmit byte array up to 256 bytes long /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = rf.transmit(byteArr, 8); + int state = radio.transmit(byteArr, 8); */ if (state == ERR_NONE) { From 4d87146123dc6979d39692b67cf1e75222bc039c Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:08:43 +0200 Subject: [PATCH 230/334] [RF69] Fixed old variable name --- .../RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino index 4e8c2667..5f91e1f6 100644 --- a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino +++ b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino @@ -87,23 +87,23 @@ void loop() { Serial.print(F("[RF69] Transmitting packet ... ")); // transmit C-string or Arduino string to node with address 0x02 - int state = rf.transmit("Hello World!", 0x02); + int state = radio.transmit("Hello World!", 0x02); // transmit byte array to node with address 0x02 /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = rf.transmit(byteArr, 8, 0x02); + int state = radio.transmit(byteArr, 8, 0x02); */ // transmit C-string or Arduino string in broadcast mode /* - int state = rf.transmit("Hello World!", 0xFF); + int state = radio.transmit("Hello World!", 0xFF); */ // transmit byte array in broadcast mode /* byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; - int state = rf.transmit(byteArr, 8, 0xFF); + int state = radio.transmit(byteArr, 8, 0xFF); */ if (state == ERR_NONE) { From b67060e424b25c90469240950bbf41cdff10bd73 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 12:18:02 +0200 Subject: [PATCH 231/334] [AX25] Fixed uninitialized array --- src/protocols/AX25/AX25.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index 579ed8f1..e73021a6 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -266,6 +266,9 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { uint8_t stuffedFrameBuff[RADIOLIB_STATIC_ARRAY_SIZE]; #endif + // initialize buffer to all zeros + memset(stuffedFrameBuff, 0x00, _preambleLen + 1 + (6*frameBuffLen)/5 + 2); + // stuff bits (skip preamble and both flags) uint16_t stuffedFrameBuffLenBits = 8*(_preambleLen + 1); uint8_t count = 0; From be585bbf78ca8ba89b243524852c00a0085fc533 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 13:18:24 +0200 Subject: [PATCH 232/334] [SSTV] Fixes from cppcheck scan --- src/protocols/SSTV/SSTV.cpp | 8 ++------ src/protocols/SSTV/SSTV.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp index 73b9b1d9..7988fc64 100644 --- a/src/protocols/SSTV/SSTV.cpp +++ b/src/protocols/SSTV/SSTV.cpp @@ -166,7 +166,7 @@ SSTVClient::SSTVClient(AFSKClient* audio) { } #endif -int16_t SSTVClient::begin(SSTVMode_t mode, float correction) { +int16_t SSTVClient::begin(const SSTVMode_t& mode, float correction) { if(_audio == nullptr) { // this initialization method can only be used in AFSK mode return(ERR_WRONG_MODEM); @@ -175,7 +175,7 @@ int16_t SSTVClient::begin(SSTVMode_t mode, float correction) { return(begin(0, mode, correction)); } -int16_t SSTVClient::begin(float base, SSTVMode_t mode, float correction) { +int16_t SSTVClient::begin(float base, const SSTVMode_t& mode, float correction) { // save mode _mode = mode; @@ -278,10 +278,6 @@ void SSTVClient::sendLine(uint32_t* imgLine) { } } -uint16_t SSTVClient::getPictureHeight() { - return(_mode.height); -} - void SSTVClient::tone(float freq, uint32_t len) { uint32_t start = micros(); if(_audio != nullptr) { diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h index 1ab9225b..ea64ceca 100644 --- a/src/protocols/SSTV/SSTV.h +++ b/src/protocols/SSTV/SSTV.h @@ -121,7 +121,7 @@ class SSTVClient { \param phy Pointer to the wireless module providing PhysicalLayer communication. */ - SSTVClient(PhysicalLayer* phy); + explicit SSTVClient(PhysicalLayer* phy); #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! @@ -129,7 +129,7 @@ class SSTVClient { \param audio Pointer to the AFSK instance providing audio. */ - SSTVClient(AFSKClient* phy); + explicit SSTVClient(AFSKClient* audio); #endif // basic methods @@ -145,7 +145,7 @@ class SSTVClient { \returns \ref status_codes */ - int16_t begin(float base, SSTVMode_t mode, float correction = 1.0); + int16_t begin(float base, const SSTVMode_t& mode, float correction = 1.0); /*! \brief Initialization method for AFSK. @@ -156,7 +156,7 @@ class SSTVClient { \returns \ref status_codes */ - int16_t begin(SSTVMode_t mode, float correction = 1.0); + int16_t begin(const SSTVMode_t& mode, float correction = 1.0); /*! \brief Sends out tone at 1900 Hz. @@ -180,7 +180,7 @@ class SSTVClient { \returns Picture height of the currently configured SSTV mode in pixels. */ - uint16_t getPictureHeight(); + uint16_t getPictureHeight() const { return(_mode.height); }; #ifndef RADIOLIB_GODMODE private: @@ -192,9 +192,9 @@ class SSTVClient { void* _audio; #endif - uint32_t _base; - SSTVMode_t _mode; - bool _firstLine; + uint32_t _base = 0; + SSTVMode_t _mode = Scottie1; + bool _firstLine = true; void tone(float freq, uint32_t len = 0); }; From d066f616b152bb242a7e94146ba68d4496018f26 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 13:18:48 +0200 Subject: [PATCH 233/334] [RTTY] Fixes from cppcheck scan --- src/protocols/RTTY/RTTY.cpp | 18 +++++++++--------- src/protocols/RTTY/RTTY.h | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index 7b023f8e..ccd166cf 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -235,7 +235,7 @@ size_t RTTYClient::print(__FlashStringHelper* fstr) { size_t n = 0; if(_encoding == ITA2) { - ITA2String ita2 = str; + ITA2String ita2 = ITA2String(str); n = RTTYClient::print(ita2); } else if((_encoding == ASCII) || (_encoding == ASCII_EXTENDED)) { n = RTTYClient::write((uint8_t*)str, len); @@ -256,7 +256,7 @@ size_t RTTYClient::print(ITA2String& ita2) { size_t RTTYClient::print(const String& str) { size_t n = 0; if(_encoding == ITA2) { - ITA2String ita2 = str.c_str(); + ITA2String ita2 = ITA2String(str.c_str()); n = RTTYClient::print(ita2); } else if((_encoding == ASCII) || (_encoding == ASCII_EXTENDED)) { n = RTTYClient::write((uint8_t*)str.c_str(), str.length()); @@ -267,7 +267,7 @@ size_t RTTYClient::print(const String& str) { size_t RTTYClient::print(const char str[]) { size_t n = 0; if(_encoding == ITA2) { - ITA2String ita2 = str; + ITA2String ita2 = ITA2String(str); n = RTTYClient::print(ita2); } else if((_encoding == ASCII) || (_encoding == ASCII_EXTENDED)) { n = RTTYClient::write((uint8_t*)str, strlen(str)); @@ -278,7 +278,7 @@ size_t RTTYClient::print(const char str[]) { size_t RTTYClient::print(char c) { size_t n = 0; if(_encoding == ITA2) { - ITA2String ita2 = c; + ITA2String ita2 = ITA2String(c); n = RTTYClient::print(ita2); } else if((_encoding == ASCII) || (_encoding == ASCII_EXTENDED)) { n = RTTYClient::write(c); @@ -328,7 +328,7 @@ size_t RTTYClient::print(double n, int digits) { size_t RTTYClient::println(void) { size_t n = 0; if(_encoding == ITA2) { - ITA2String lf = "\r\n"; + ITA2String lf = ITA2String("\r\n"); n = RTTYClient::print(lf); } else if((_encoding == ASCII) || (_encoding == ASCII_EXTENDED)) { n = RTTYClient::write("\r\n"); @@ -437,7 +437,7 @@ size_t RTTYClient::printNumber(unsigned long n, uint8_t base) { size_t l = 0; if(_encoding == ITA2) { - ITA2String ita2 = str; + ITA2String ita2 = ITA2String(str); uint8_t* arr = ita2.byteArr(); l = RTTYClient::write(arr, ita2.length()); delete[] arr; @@ -461,7 +461,7 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) { if(code[0] != 0x00) { if(_encoding == ITA2) { - ITA2String ita2 = code; + ITA2String ita2 = ITA2String(code); uint8_t* arr = ita2.byteArr(); n = RTTYClient::write(arr, ita2.length()); delete[] arr; @@ -474,7 +474,7 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) { // Handle negative numbers if (number < 0.0) { if(_encoding == ITA2) { - ITA2String ita2 = "-"; + ITA2String ita2 = ITA2String("-"); uint8_t* arr = ita2.byteArr(); n += RTTYClient::write(arr, ita2.length()); delete[] arr; @@ -499,7 +499,7 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) { // Print the decimal point, but only if there are digits beyond if(digits > 0) { if(_encoding == ITA2) { - ITA2String ita2 = "."; + ITA2String ita2 = ITA2String("."); uint8_t* arr = ita2.byteArr(); n += RTTYClient::write(arr, ita2.length()); delete[] arr; diff --git a/src/protocols/RTTY/RTTY.h b/src/protocols/RTTY/RTTY.h index 7dc54076..a7bfbf73 100644 --- a/src/protocols/RTTY/RTTY.h +++ b/src/protocols/RTTY/RTTY.h @@ -29,14 +29,14 @@ class ITA2String { \param c ASCII-encoded character to encode as ITA2. */ - ITA2String(char c); + explicit ITA2String(char c); /*! \brief Default string constructor. \param str ASCII-encoded string to encode as ITA2. */ - ITA2String(const char* str); + explicit ITA2String(const char* str); /*! \brief Default destructor. @@ -69,7 +69,7 @@ class ITA2String { size_t _len; size_t _ita2Len; - uint16_t getBits(char c); + static uint16_t getBits(char c); }; // supported encoding schemes @@ -89,7 +89,7 @@ class RTTYClient { \param phy Pointer to the wireless module providing PhysicalLayer communication. */ - RTTYClient(PhysicalLayer* phy); + explicit RTTYClient(PhysicalLayer* phy); #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! @@ -97,7 +97,7 @@ class RTTYClient { \param audio Pointer to the AFSK instance providing audio. */ - RTTYClient(AFSKClient* audio); + explicit RTTYClient(AFSKClient* audio); #endif // basic methods @@ -143,7 +143,7 @@ class RTTYClient { size_t println(void); size_t println(__FlashStringHelper*); size_t println(ITA2String &); - size_t println(const String &s); + size_t println(const String &); size_t println(const char[]); size_t println(char); size_t println(unsigned char, int = DEC); @@ -163,12 +163,12 @@ class RTTYClient { void* _audio; #endif - uint8_t _encoding; - uint32_t _base, _baseHz; - uint32_t _shift, _shiftHz; - uint32_t _bitDuration; - uint8_t _dataBits; - uint8_t _stopBits; + uint8_t _encoding = ASCII; + uint32_t _base = 0, _baseHz = 0; + uint32_t _shift = 0, _shiftHz = 0; + uint32_t _bitDuration = 0; + uint8_t _dataBits = 0; + uint8_t _stopBits = 0; void mark(); void space(); From 7e62dbd1d87b7c4a6b31a7da7a7c1616fc091a05 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 13:43:39 +0200 Subject: [PATCH 234/334] Fixes from cppcheck scan --- src/ISerial.h | 2 +- src/Module.cpp | 36 ++++++++++++++++++++++-------------- src/Module.h | 24 ++++++++++++------------ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/ISerial.h b/src/ISerial.h index d086beaf..c8ecacbe 100644 --- a/src/ISerial.h +++ b/src/ISerial.h @@ -15,7 +15,7 @@ */ class ISerial { public: - ISerial(Module* mod); + explicit ISerial(Module* mod); void begin(long); bool listen(); diff --git a/src/Module.cpp b/src/Module.cpp index e24e6424..218be4fa 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -9,6 +9,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs _spi = &RADIOLIB_DEFAULT_SPI; _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); _initInterface = true; + ModuleSerial = NULL; } Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio) { @@ -20,9 +21,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs _spi = &RADIOLIB_DEFAULT_SPI; _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); _initInterface = true; + ModuleSerial = NULL; } -Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* useSer, RADIOLIB_PIN_TYPE rst) { +Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial, RADIOLIB_PIN_TYPE rst) { _cs = RADIOLIB_NC; _rx = rx; _tx = tx; @@ -31,10 +33,10 @@ Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* useSe _initInterface = true; #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - ModuleSerial = useSer; + ModuleSerial = serial; #else ModuleSerial = new SoftwareSerial(_rx, _tx); - (void)useSer; + (void)serial; #endif } @@ -47,6 +49,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs _spi = &spi; _spiSettings = spiSettings; _initInterface = false; + ModuleSerial = NULL; } Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings) { @@ -58,9 +61,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs _spi = &spi; _spiSettings = spiSettings; _initInterface = false; + ModuleSerial = NULL; } -Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* useSer) { +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* serial) { _cs = cs; _rx = rx; _tx = tx; @@ -71,10 +75,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs _initInterface = false; #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - ModuleSerial = useSer; + ModuleSerial = serial; #else ModuleSerial = new SoftwareSerial(_rx, _tx); - (void)useSer; + (void)serial; #endif } @@ -259,16 +263,20 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da // send data or get response if(cmd == SPIwriteCommand) { - for(size_t n = 0; n < numBytes; n++) { - _spi->transfer(dataOut[n]); - RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + if(dataOut != NULL) { + for(size_t n = 0; n < numBytes; n++) { + _spi->transfer(dataOut[n]); + RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + } } } else if (cmd == SPIreadCommand) { - for(size_t n = 0; n < numBytes; n++) { - dataIn[n] = _spi->transfer(0x00); - RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + if(dataIn != NULL) { + for(size_t n = 0; n < numBytes; n++) { + dataIn[n] = _spi->transfer(0x00); + RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + } } } RADIOLIB_VERBOSE_PRINTLN(); diff --git a/src/Module.h b/src/Module.h index 2a20b926..ccc571c0 100644 --- a/src/Module.h +++ b/src/Module.h @@ -21,18 +21,18 @@ class Module { /*! \brief UART-based module constructor. - \param tx Arduino pin to be used as Tx pin for SoftwareSerial communication. - \param rx Arduino pin to be used as Rx pin for SoftwareSerial communication. + \param tx Arduino pin to be used as Tx pin for SoftwareSerial communication. + \param serial HardwareSerial to be used on platforms that do not support SoftwareSerial. Defaults to Serial1. \param rst Arduino pin to be used as hardware reset for the module. Defaults to NC (unused). */ #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC); + Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC); #else - Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = nullptr, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC); + Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial = nullptr, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC); #endif /*! @@ -408,18 +408,18 @@ class Module { #ifndef RADIOLIB_GODMODE private: #endif - RADIOLIB_PIN_TYPE _cs; - RADIOLIB_PIN_TYPE _tx; - RADIOLIB_PIN_TYPE _rx; - RADIOLIB_PIN_TYPE _irq; - RADIOLIB_PIN_TYPE _rst; + RADIOLIB_PIN_TYPE _cs = RADIOLIB_NC; + RADIOLIB_PIN_TYPE _tx = RADIOLIB_NC; + RADIOLIB_PIN_TYPE _rx = RADIOLIB_NC; + RADIOLIB_PIN_TYPE _irq = RADIOLIB_NC; + RADIOLIB_PIN_TYPE _rst = RADIOLIB_NC; - bool _initInterface; - SPIClass* _spi; + bool _initInterface = false; + SPIClass* _spi = NULL; SPISettings _spiSettings; bool _useRfSwitch = false; - RADIOLIB_PIN_TYPE _rxEn, _txEn; + RADIOLIB_PIN_TYPE _rxEn = RADIOLIB_NC, _txEn = RADIOLIB_NC; uint32_t _ATtimeout = 15000; }; From e3fb8959698d5989ff2dc2574a364c31cdf349ed Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:10:09 +0200 Subject: [PATCH 235/334] [CC1101] Fixes from cppcheck scan --- src/modules/CC1101/CC1101.cpp | 9 ++----- src/modules/CC1101/CC1101.h | 48 +++++++++++++++++------------------ 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index a2b56ac8..3d1f50dd 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -3,11 +3,6 @@ CC1101::CC1101(Module* module) : PhysicalLayer(CC1101_FREQUENCY_STEP_SIZE, CC1101_MAX_PACKET_LENGTH) { _mod = module; - _packetLengthQueried = false; - _packetLengthConfig = CC1101_LENGTH_CONFIG_VARIABLE; - _modulation = CC1101_MOD_FORMAT_2_FSK; - - _syncWordLength = 2; } int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLength) { @@ -598,7 +593,7 @@ int16_t CC1101::setOOK(bool enableOOK) { } -float CC1101::getRSSI() { +float CC1101::getRSSI() const { float rssi; if(_rawRSSI >= 128) { rssi = (((float)_rawRSSI - 256.0)/2.0) - 74.0; @@ -608,7 +603,7 @@ float CC1101::getRSSI() { return(rssi); } -uint8_t CC1101::getLQI() { +uint8_t CC1101::getLQI() const { return(_rawLQI); } diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index 2ba3089e..f38b57c6 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -549,7 +549,7 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Blocking binary receive method. @@ -561,14 +561,14 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t receive(uint8_t* data, size_t len); + int16_t receive(uint8_t* data, size_t len) override; /*! \brief Sets the module to standby mode. \returns \ref status_codes */ - int16_t standby(); + int16_t standby() override; /*! \brief Starts direct mode transmission. @@ -577,14 +577,14 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmitDirect(uint32_t frf = 0); + int16_t transmitDirect(uint32_t frf = 0) override; /*! \brief Starts direct mode reception. \returns \ref status_codes */ - int16_t receiveDirect(); + int16_t receiveDirect() override; /*! \brief Stops direct mode. It is required to call this method to switch from direct transmissions to packet-based transmissions. @@ -633,7 +633,7 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Interrupt-driven receive method. GDO0 will be activated when full packet is received. @@ -651,7 +651,7 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t len); + int16_t readData(uint8_t* data, size_t len) override; // configuration methods @@ -689,7 +689,7 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t setFrequencyDeviation(float freqDev); + int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets output power. Allowed values are -30, -20, -15, -10, 0, 5, 7 or 10 dBm. @@ -771,14 +771,14 @@ class CC1101: public PhysicalLayer { \returns Last packet RSSI in dBm. */ - float getRSSI(); + float getRSSI() const; /*! \brief Gets LQI (Link Quality Indicator) of the last received packet. \returns Last packet LQI (lower is better). */ - uint8_t getLQI(); + uint8_t getLQI() const; /*! \brief Query modem for the packet length of received payload. @@ -787,7 +787,7 @@ class CC1101: public PhysicalLayer { \returns Length of last received packet in bytes. */ - size_t getPacketLength(bool update = true); + size_t getPacketLength(bool update = true) override; /*! \brief Set modem in fixed packet length mode. @@ -853,7 +853,7 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t setDataShaping(float sh); + int16_t setDataShaping(float sh) override; /*! \brief Sets transmission encoding. @@ -862,7 +862,7 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t setEncoding(uint8_t encoding); + int16_t setEncoding(uint8_t encoding) override; /*! \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. @@ -879,24 +879,24 @@ class CC1101: public PhysicalLayer { #endif Module* _mod; - float _freq; - uint8_t _rawRSSI; - uint8_t _rawLQI; - uint8_t _modulation; + float _freq = 0; + uint8_t _rawRSSI = 0; + uint8_t _rawLQI = 0; + uint8_t _modulation = CC1101_MOD_FORMAT_2_FSK; - size_t _packetLength; - bool _packetLengthQueried; - uint8_t _packetLengthConfig; + size_t _packetLength = 0; + bool _packetLengthQueried = false; + uint8_t _packetLengthConfig = CC1101_LENGTH_CONFIG_VARIABLE; - bool _promiscuous; + bool _promiscuous = false; bool _crcOn = true; - uint8_t _syncWordLength; - int8_t _power; + uint8_t _syncWordLength = 2; + int8_t _power = 0; int16_t config(); int16_t directMode(); - void getExpMant(float target, uint16_t mantOffset, uint8_t divExp, uint8_t expMax, uint8_t& exp, uint8_t& mant); + static void getExpMant(float target, uint16_t mantOffset, uint8_t divExp, uint8_t expMax, uint8_t& exp, uint8_t& mant); int16_t setPacketMode(uint8_t mode, uint8_t len); // SPI read overrides to set bit for burst write and status registers access From 7a8cde1d38366b57300b9e1501d7d61ce7cc7386 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:15:23 +0200 Subject: [PATCH 236/334] [ESP8266] Fixes from cppchekc scan --- src/modules/ESP8266/ESP8266.cpp | 6 +++--- src/modules/ESP8266/ESP8266.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index 7cfef116..c7e23b00 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -83,9 +83,9 @@ int16_t ESP8266::join(const char* ssid, const char* password) { int16_t ESP8266::openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive) { char portStr[6]; - sprintf(portStr, "%d", port); + sprintf(portStr, "%u", port); char tcpKeepAliveStr[6]; - sprintf(tcpKeepAliveStr, "%d", tcpKeepAlive); + sprintf(tcpKeepAliveStr, "%u", tcpKeepAlive); // build AT command const char* atStr = "AT+CIPSTART=\""; @@ -132,7 +132,7 @@ int16_t ESP8266::closeTransportConnection() { int16_t ESP8266::send(const char* data) { // build AT command char lenStr[12]; - sprintf(lenStr, "%d", strlen(data)); + sprintf(lenStr, "%u", (uint16_t)strlen(data)); const char* atStr = "AT+CIPSEND="; #ifdef RADIOLIB_STATIC_ONLY char cmd[RADIOLIB_STATIC_ARRAY_SIZE]; diff --git a/src/modules/ESP8266/ESP8266.h b/src/modules/ESP8266/ESP8266.h index 4169f12f..eff7b8b0 100644 --- a/src/modules/ESP8266/ESP8266.h +++ b/src/modules/ESP8266/ESP8266.h @@ -48,12 +48,12 @@ class ESP8266: public TransportLayer { int16_t join(const char* ssid, const char* password); // transport layer methods (implementations of purely virtual methods in TransportLayer class) - int16_t openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive = 0); - int16_t closeTransportConnection(); - int16_t send(const char* data); - int16_t send(uint8_t* data, uint32_t len); - size_t receive(uint8_t* data, size_t len, uint32_t timeout = 10000); - size_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10); + int16_t openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive = 0) override; + int16_t closeTransportConnection() override; + int16_t send(const char* data) override; + int16_t send(uint8_t* data, uint32_t len) override; + size_t receive(uint8_t* data, size_t len, uint32_t timeout = 10000) override; + size_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10) override; #ifndef RADIOLIB_GODMODE private: From 0a53900b5172772e23627f5ada51114ab6d615e0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:22:36 +0200 Subject: [PATCH 237/334] [RF69] Fixes from cppcheck scan --- src/modules/RF69/RF69.cpp | 13 +++---------- src/modules/RF69/RF69.h | 40 +++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index bebaba12..ba1548b8 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -3,14 +3,6 @@ RF69::RF69(Module* module) : PhysicalLayer(RF69_FREQUENCY_STEP_SIZE, RF69_MAX_PACKET_LENGTH) { _mod = module; - _tempOffset = 0; - - _packetLengthQueried = false; - _packetLengthConfig = RF69_PACKET_FORMAT_VARIABLE; - - _promiscuous = false; - - _syncWordLength = 2; } int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { @@ -245,6 +237,7 @@ int16_t RF69::disableAES() { int16_t RF69::startReceive() { // set mode to standby int16_t state = setMode(RF69_STANDBY); + RADIOLIB_ASSERT(state); // set RX timeouts and DIO pin mapping state = _mod->SPIsetRegValue(RF69_REG_DIO_MAPPING_1, RF69_DIO0_PACK_PAYLOAD_READY, 7, 4); @@ -805,13 +798,13 @@ int16_t RF69::config() { // set Rx timeouts state = _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_1, RF69_TIMEOUT_RX_START, 7, 0); - state = _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_2, RF69_TIMEOUT_RSSI_THRESH, 7, 0); + state |= _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_2, RF69_TIMEOUT_RSSI_THRESH, 7, 0); RADIOLIB_ASSERT(state); // enable improved fading margin state = _mod->SPIsetRegValue(RF69_REG_TEST_DAGC, RF69_CONTINUOUS_DAGC_LOW_BETA_OFF, 7, 0); - return(ERR_NONE); + return(state); } int16_t RF69::setPacketMode(uint8_t mode, uint8_t len) { diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index b82f607d..70815395 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -477,7 +477,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Blocking binary receive method. @@ -489,7 +489,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t receive(uint8_t* data, size_t len); + int16_t receive(uint8_t* data, size_t len) override; /*! \brief Sets the module to sleep mode. @@ -503,7 +503,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t standby(); + int16_t standby() override; /*! \brief Starts direct mode transmission. @@ -512,14 +512,14 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmitDirect(uint32_t frf = 0); + int16_t transmitDirect(uint32_t frf = 0) override; /*! \brief Starts direct mode reception. \returns \ref status_codes */ - int16_t receiveDirect(); + int16_t receiveDirect() override; /*! \brief Stops direct mode. It is required to call this method to switch from direct transmissions to packet-based transmissions. @@ -587,7 +587,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Interrupt-driven receive method. GDO0 will be activated when full packet is received. @@ -605,7 +605,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t len); + int16_t readData(uint8_t* data, size_t len) override; // configuration methods @@ -643,7 +643,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t setFrequencyDeviation(float freqDev); + int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets output power. Allowed values range from -18 to 13 dBm for low power modules (RF69C/CW) or -2 to 20 dBm (RF69H/HC/HCW). @@ -715,7 +715,7 @@ class RF69: public PhysicalLayer { \returns Length of last received packet in bytes. */ - size_t getPacketLength(bool update = true); + size_t getPacketLength(bool update = true) override; /*! \brief Set modem in fixed packet length mode. @@ -777,7 +777,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t setDataShaping(float sh); + int16_t setDataShaping(float sh) override; /*! \brief Sets transmission encoding. @@ -786,7 +786,7 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t setEncoding(uint8_t encoding); + int16_t setEncoding(uint8_t encoding) override; /*! \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. @@ -810,18 +810,18 @@ class RF69: public PhysicalLayer { #endif Module* _mod; - float _br; - float _rxBw; - int16_t _tempOffset; - int8_t _power; + float _br = 0; + float _rxBw = 0; + int16_t _tempOffset = 0; + int8_t _power = 0; - size_t _packetLength; - bool _packetLengthQueried; - uint8_t _packetLengthConfig; + size_t _packetLength = 0; + bool _packetLengthQueried = false; + uint8_t _packetLengthConfig = RF69_PACKET_FORMAT_VARIABLE; - bool _promiscuous; + bool _promiscuous = false; - uint8_t _syncWordLength; + uint8_t _syncWordLength = 2; int16_t config(); int16_t directMode(); From 638bcfd32be0e49c021ca77a85bdb3887ca8a5a0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:24:14 +0200 Subject: [PATCH 238/334] [SX1231] Fixes from cppcheck scan --- src/modules/SX1231/SX1231.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX1231/SX1231.h b/src/modules/SX1231/SX1231.h index 0761fa8e..4597efa8 100644 --- a/src/modules/SX1231/SX1231.h +++ b/src/modules/SX1231/SX1231.h @@ -49,7 +49,7 @@ class SX1231: public RF69 { #ifndef RADIOLIB_GODMODE private: #endif - uint8_t _chipRevision; + uint8_t _chipRevision = 0; }; #endif From fed86b0742cef33db83ed6a0295cce8c1d2f9967 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:32:29 +0200 Subject: [PATCH 239/334] [SX126x] Fixes from cppcheck scan --- src/modules/SX126x/SX1262.cpp | 4 +--- src/modules/SX126x/SX1268.cpp | 4 +--- src/modules/SX126x/SX126x.cpp | 2 +- src/modules/SX126x/SX126x.h | 42 +++++++++++++++++------------------ 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 3f086c9a..804c88a3 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -44,8 +44,6 @@ int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t int16_t SX1262::setFrequency(float freq, bool calibrate) { RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, ERR_INVALID_FREQUENCY); - int16_t state = ERR_NONE; - // calibrate image if(calibrate) { uint8_t data[2]; @@ -65,7 +63,7 @@ int16_t SX1262::setFrequency(float freq, bool calibrate) { data[0] = SX126X_CAL_IMG_430_MHZ_1; data[1] = SX126X_CAL_IMG_430_MHZ_2; } - state = SX126x::calibrateImage(data); + int16_t state = SX126x::calibrateImage(data); RADIOLIB_ASSERT(state); } diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index 7e6b3443..a6ec18ed 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -44,8 +44,6 @@ int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t int16_t SX1268::setFrequency(float freq, bool calibrate) { RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, ERR_INVALID_FREQUENCY); - int16_t state = ERR_NONE; - // calibrate image if(calibrate) { uint8_t data[2]; @@ -59,7 +57,7 @@ int16_t SX1268::setFrequency(float freq, bool calibrate) { data[0] = SX126X_CAL_IMG_430_MHZ_1; data[1] = SX126X_CAL_IMG_430_MHZ_2; } - state = SX126x::calibrateImage(data); + int16_t state = SX126x::calibrateImage(data); RADIOLIB_ASSERT(state); } diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 900a835c..f459e975 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -1042,7 +1042,7 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) { return(state); } -float SX126x::getDataRate() { +float SX126x::getDataRate() const { return(_dataRate); } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 26881c8c..09c22639 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -421,7 +421,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Blocking binary receive method. @@ -433,7 +433,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t receive(uint8_t* data, size_t len); + int16_t receive(uint8_t* data, size_t len) override; /*! \brief Starts direct mode transmission. @@ -450,7 +450,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t receiveDirect(); + int16_t receiveDirect() override; /*! \brief Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. @@ -473,7 +473,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t standby(); + int16_t standby() override; /*! \brief Sets the module to standby mode. @@ -510,7 +510,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Interrupt-driven receive method. DIO1 will be activated when full packet is received. @@ -555,7 +555,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t len); + int16_t readData(uint8_t* data, size_t len) override; // configuration methods @@ -629,7 +629,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setFrequencyDeviation(float freqDev); + int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets FSK bit rate. Allowed values range from 0.6 to 300.0 kbps. @@ -656,7 +656,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setDataShaping(float sh); + int16_t setDataShaping(float sh) override; /*! \brief Sets FSK sync word in the form of array of up to 8 bytes. @@ -752,7 +752,7 @@ class SX126x: public PhysicalLayer { \returns Effective data rate in bps. */ - float getDataRate(); + float getDataRate() const; /*! \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. @@ -775,7 +775,7 @@ class SX126x: public PhysicalLayer { \returns Length of last received packet in bytes. */ - size_t getPacketLength(bool update = true); + size_t getPacketLength(bool update = true) override; /*! \brief Set modem in fixed packet length mode. Available in FSK mode only. @@ -841,7 +841,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setEncoding(uint8_t encoding); + int16_t setEncoding(uint8_t encoding) override; /*! \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. @@ -899,20 +899,20 @@ class SX126x: public PhysicalLayer { #endif Module* _mod; - uint8_t _bw, _sf, _cr, _ldro, _crcType, _headerType; - uint16_t _preambleLength; - float _bwKhz; + uint8_t _bw = 0, _sf = 0, _cr = 0, _ldro = 0, _crcType = 0, _headerType = 0; + uint16_t _preambleLength = 0; + float _bwKhz = 0; - uint32_t _br, _freqDev; - uint8_t _rxBw, _pulseShape, _crcTypeFSK, _syncWordLength, _addrComp, _whitening, _packetType; - uint16_t _preambleLengthFSK; - float _rxBwKhz; + uint32_t _br = 0, _freqDev = 0; + uint8_t _rxBw = 0, _pulseShape = 0, _crcTypeFSK = 0, _syncWordLength = 0, _addrComp = 0, _whitening = 0, _packetType = 0; + uint16_t _preambleLengthFSK = 0; + float _rxBwKhz = 0; - float _dataRate; + float _dataRate = 0; - uint32_t _tcxoDelay; + uint32_t _tcxoDelay = 0; - size_t _implicitLen; + size_t _implicitLen = 0; int16_t config(uint8_t modem); From 95e7bdb7c67a0e6a24f55998ca5930b0872ac19a Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:48:51 +0200 Subject: [PATCH 240/334] [SX126x] Added missing override --- src/modules/SX126x/SX126x.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 09c22639..ae92e253 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -442,7 +442,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmitDirect(uint32_t frf = 0); + int16_t transmitDirect(uint32_t frf = 0) override; /*! \brief Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as %SX126x series does not support direct mode reception. From a367a3fe699c64ca90f38950fe4c6f1c1eecf6ff Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:49:05 +0200 Subject: [PATCH 241/334] [SX127x] Fixes from cppcheck scan --- src/modules/SX127x/SX1272.cpp | 2 +- src/modules/SX127x/SX1272.h | 4 +-- src/modules/SX127x/SX1278.cpp | 2 +- src/modules/SX127x/SX1278.h | 4 +-- src/modules/SX127x/SX127x.cpp | 21 +++++++++------- src/modules/SX127x/SX127x.h | 46 +++++++++++++++++------------------ 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index b37cf75e..4384fd54 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -218,7 +218,7 @@ int16_t SX1272::setOutputPower(int8_t power) { state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX127X_PA_SELECT_RFO, 7, 7); state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, (power + 1), 3, 0); state |= _mod->SPIsetRegValue(SX1272_REG_PA_DAC, SX127X_PA_BOOST_OFF, 2, 0); - } else if((power >= 2) && (power <= 17)) { + } else if(power <= 17) { // power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX127X_PA_SELECT_BOOST, 7, 7); state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, (power - 2), 3, 0); diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index 547f2905..7538c845 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -159,7 +159,7 @@ class SX1272: public SX127x { /*! \brief Reset method. Will reset the chip to the default state using RST pin. */ - void reset(); + void reset() override; // configuration methods @@ -226,7 +226,7 @@ class SX1272: public SX127x { \returns \ref status_codes */ - int16_t setDataShaping(float sh); + int16_t setDataShaping(float sh) override; /*! \brief Sets filter cutoff frequency that will be used for data shaping. diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 698634f8..8e70be39 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -290,7 +290,7 @@ int16_t SX1278::setOutputPower(int8_t power) { state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX127X_PA_SELECT_RFO, 7, 7); state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX1278_LOW_POWER | (power + 3), 6, 0); state |= _mod->SPIsetRegValue(SX1278_REG_PA_DAC, SX127X_PA_BOOST_OFF, 2, 0); - } else if((power >= 2) && (power <= 17)) { + } else if(power <= 17) { // power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX127X_PA_SELECT_BOOST, 7, 7); state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX1278_MAX_POWER | (power - 2), 6, 0); diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index e2c5220a..ccd47da8 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -168,7 +168,7 @@ class SX1278: public SX127x { /*! \brief Reset method. Will reset the chip to the default state using RST pin. */ - void reset(); + void reset() override; // configuration methods @@ -235,7 +235,7 @@ class SX1278: public SX127x { \returns \ref status_codes */ - int16_t setDataShaping(float sh); + int16_t setDataShaping(float sh) override; /*! \brief Sets filter cutoff frequency that will be used for data shaping. diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index c3d2dd7e..79c2ab65 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -3,7 +3,6 @@ SX127x::SX127x(Module* mod) : PhysicalLayer(SX127X_FREQUENCY_STEP_SIZE, SX127X_MAX_PACKET_LENGTH) { _mod = mod; - _packetLengthQueried = false; } int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength) { @@ -122,6 +121,7 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { // set mode to standby int16_t state = setMode(SX127X_STANDBY); + RADIOLIB_ASSERT(state); int16_t modem = getActiveModem(); uint32_t start = 0; @@ -188,6 +188,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { int16_t SX127x::receive(uint8_t* data, size_t len) { // set mode to standby int16_t state = setMode(SX127X_STANDBY); + RADIOLIB_ASSERT(state); int16_t modem = getActiveModem(); if(modem == SX127X_LORA) { @@ -284,7 +285,7 @@ int16_t SX127x::standby() { return(setMode(SX127X_STANDBY)); } -int16_t SX127x::transmitDirect(uint32_t FRF) { +int16_t SX127x::transmitDirect(uint32_t frf) { // check modem if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); @@ -294,10 +295,10 @@ int16_t SX127x::transmitDirect(uint32_t FRF) { _mod->setRfSwitchState(LOW, HIGH); // user requested to start transmitting immediately (required for RTTY) - if(FRF != 0) { - _mod->SPIwriteRegister(SX127X_REG_FRF_MSB, (FRF & 0xFF0000) >> 16); - _mod->SPIwriteRegister(SX127X_REG_FRF_MID, (FRF & 0x00FF00) >> 8); - _mod->SPIwriteRegister(SX127X_REG_FRF_LSB, FRF & 0x0000FF); + if(frf != 0) { + _mod->SPIwriteRegister(SX127X_REG_FRF_MSB, (frf & 0xFF0000) >> 16); + _mod->SPIwriteRegister(SX127X_REG_FRF_MID, (frf & 0x00FF00) >> 8); + _mod->SPIwriteRegister(SX127X_REG_FRF_LSB, frf & 0x0000FF); return(setMode(SX127X_TX)); } @@ -352,11 +353,12 @@ int16_t SX127x::packetMode() { int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { // set mode to standby int16_t state = setMode(SX127X_STANDBY); + RADIOLIB_ASSERT(state); int16_t modem = getActiveModem(); if(modem == SX127X_LORA) { // set DIO pin mapping - state |= _mod->SPIsetRegValue(SX127X_REG_DIO_MAPPING_1, SX127X_DIO0_RX_DONE | SX127X_DIO1_RX_TIMEOUT, 7, 4); + state = _mod->SPIsetRegValue(SX127X_REG_DIO_MAPPING_1, SX127X_DIO0_RX_DONE | SX127X_DIO1_RX_TIMEOUT, 7, 4); // set expected packet length for SF6 if(_sf == 6) { @@ -373,7 +375,8 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { } else if(modem == SX127X_FSK_OOK) { // set DIO pin mapping - state |= _mod->SPIsetRegValue(SX127X_REG_DIO_MAPPING_1, SX127X_DIO0_PACK_PAYLOAD_READY, 7, 6); + state = _mod->SPIsetRegValue(SX127X_REG_DIO_MAPPING_1, SX127X_DIO0_PACK_PAYLOAD_READY, 7, 6); + RADIOLIB_ASSERT(state); // clear interrupt flags clearIRQFlags(); @@ -651,7 +654,7 @@ float SX127x::getSNR() { return(rawSNR / 4.0); } -float SX127x::getDataRate() { +float SX127x::getDataRate() const { return(_dataRate); } diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 0023e4d8..ac22a49b 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -602,7 +602,7 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem. @@ -614,7 +614,7 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t receive(uint8_t* data, size_t len); + int16_t receive(uint8_t* data, size_t len) override; /*! \brief Performs scan for valid %LoRa preamble in the current channel. @@ -636,17 +636,17 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t standby(); + int16_t standby() override; /*! \brief Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. - \param FRF 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY. + \param frf 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY. \returns \ref status_codes */ - int16_t transmitDirect(uint32_t FRF = 0); + int16_t transmitDirect(uint32_t frf = 0) override; /*! \brief Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). @@ -654,7 +654,7 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t receiveDirect(); + int16_t receiveDirect() override; /*! \brief Disables direct mode and enables packet mode, allowing the module to receive packets. Can only be activated in FSK mode. @@ -700,7 +700,7 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Interrupt-driven receive method. DIO0 will be activated when full valid packet is received. @@ -722,7 +722,7 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t len); + int16_t readData(uint8_t* data, size_t len) override; // configuration methods @@ -775,7 +775,7 @@ class SX127x: public PhysicalLayer { \returns Last packet data rate in bps (bits per second). */ - float getDataRate(); + float getDataRate() const; /*! \brief Sets FSK bit rate. Allowed values range from 1.2 to 300 kbps. Only available in FSK mode. @@ -793,7 +793,7 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setFrequencyDeviation(float freqDev); + int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets FSK receiver bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode. @@ -856,7 +856,7 @@ class SX127x: public PhysicalLayer { \returns Length of last received packet in bytes. */ - size_t getPacketLength(bool update = true); + size_t getPacketLength(bool update = true) override; /*! \brief Set modem in fixed packet length mode. Available in FSK mode only. @@ -895,7 +895,7 @@ class SX127x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setEncoding(uint8_t encoding); + int16_t setEncoding(uint8_t encoding) override; /*! \brief Reads currently active IRQ flags, can be used to check which event caused an interrupt. @@ -936,13 +936,13 @@ class SX127x: public PhysicalLayer { #endif Module* _mod; - float _freq; - float _bw; - uint8_t _sf; - uint8_t _cr; - float _br; - float _rxBw; - bool _ook; + float _freq = 0; + float _bw = 0; + uint8_t _sf = 0; + uint8_t _cr = 0; + float _br = 0; + float _rxBw = 0; + bool _ook = false; int16_t setFrequencyRaw(float newFreq); int16_t config(); @@ -954,10 +954,10 @@ class SX127x: public PhysicalLayer { #ifndef RADIOLIB_GODMODE private: #endif - float _dataRate; - size_t _packetLength; - bool _packetLengthQueried; // FSK packet length is the first byte in FIFO, length can only be queried once - uint8_t _packetLengthConfig; + float _dataRate = 0; + size_t _packetLength = 0; + bool _packetLengthQueried = false; // FSK packet length is the first byte in FIFO, length can only be queried once + uint8_t _packetLengthConfig = SX127X_PACKET_VARIABLE; bool findChip(uint8_t ver); int16_t setMode(uint8_t mode); From b642fd1a8de9aa87e08f4fb25cf9b3936bc5fa47 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:54:01 +0200 Subject: [PATCH 242/334] [SX128x] Fixes from cppcheck scan --- src/modules/SX128x/SX128x.cpp | 2 +- src/modules/SX128x/SX128x.h | 42 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 1dda7d8c..a5fec200 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -894,7 +894,7 @@ int16_t SX128x::setCRC(uint8_t len, uint32_t initial, uint16_t polynomial) { // check active modem uint8_t modem = getPacketType(); - int16_t state = ERR_NONE; + int16_t state; if((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_FLRC)) { // update packet parameters if(modem == SX128X_PACKET_TYPE_GFSK) { diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index bd403a29..873525fa 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -446,7 +446,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Blocking binary receive method. @@ -458,7 +458,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t receive(uint8_t* data, size_t len); + int16_t receive(uint8_t* data, size_t len) override; /*! \brief Starts direct mode transmission. @@ -467,7 +467,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmitDirect(uint32_t frf = 0); + int16_t transmitDirect(uint32_t frf = 0) override; /*! \brief Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as %SX128x series does not support direct mode reception. @@ -475,7 +475,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t receiveDirect(); + int16_t receiveDirect() override; /*! \brief Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. @@ -498,7 +498,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t standby(); + int16_t standby() override; /*! \brief Sets the module to standby mode. @@ -535,7 +535,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Interrupt-driven receive method. DIO1 will be activated when full packet is received. @@ -555,7 +555,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t len); + int16_t readData(uint8_t* data, size_t len) override; // configuration methods @@ -631,7 +631,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setFrequencyDeviation(float freqDev); + int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are 0.5 and 1.0. Set to 0 to disable shaping. @@ -640,7 +640,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setDataShaping(float dataShaping); + int16_t setDataShaping(float dataShaping) override; /*! \brief Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long @@ -705,7 +705,7 @@ class SX128x: public PhysicalLayer { \returns Length of last received packet in bytes. */ - size_t getPacketLength(bool update = true); + size_t getPacketLength(bool update = true) override; /*! \brief Get expected time-on-air for a given size of payload. @@ -739,7 +739,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setEncoding(uint8_t encoding); + int16_t setEncoding(uint8_t encoding) override; /*! \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. @@ -757,9 +757,9 @@ class SX128x: public PhysicalLayer { Module* _mod; // cached LoRa parameters - float _bwKhz; - uint8_t _bw, _sf, _cr; - uint8_t _preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa; + float _bwKhz = 0; + uint8_t _bw = 0, _sf = 0, _cr = 0; + uint8_t _preambleLengthLoRa = 0, _headerType = 0, _payloadLen = 0, _crcLoRa = 0; // SX128x SPI command implementations uint8_t getStatus(); @@ -790,19 +790,19 @@ class SX128x: public PhysicalLayer { private: #endif // common parameters - uint8_t _pwr; + uint8_t _pwr = 0; // cached GFSK parameters - float _modIndexReal; - uint16_t _brKbps; - uint8_t _br, _modIndex, _shaping; - uint8_t _preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening; + float _modIndexReal = 0; + uint16_t _brKbps = 0; + uint8_t _br = 0, _modIndex = 0, _shaping = 0; + uint8_t _preambleLengthGFSK = 0, _syncWordLen = 0, _syncWordMatch = 0, _crcGFSK = 0, _whitening = 0; // cached FLRC parameters - uint8_t _crFLRC; + uint8_t _crFLRC = 0; // cached BLE parameters - uint8_t _connectionState, _crcBLE, _bleTestPayload; + uint8_t _connectionState = 0, _crcBLE = 0, _bleTestPayload = 0; int16_t config(uint8_t modem); From 7e9686fcaa457cf2ca54de729b65adab666ccc5c Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 14:59:37 +0200 Subject: [PATCH 243/334] [Si443x] Fixes from cppcheck scan --- src/modules/Si443x/Si443x.cpp | 8 +++----- src/modules/Si443x/Si443x.h | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 45734b3a..94ca8446 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -3,8 +3,6 @@ Si443x::Si443x(Module* mod) : PhysicalLayer(SI443X_FREQUENCY_STEP_SIZE, SI443X_MAX_PACKET_LENGTH) { _mod = mod; - - _packetLengthQueried = false; } int16_t Si443x::begin(float br, float freqDev, float rxBw) { @@ -622,15 +620,15 @@ int16_t Si443x::updateClockRecovery() { uint8_t rxOsr_int = (uint8_t)rxOsr; uint8_t rxOsr_dec = 0; float rxOsr_temp = rxOsr; - if(rxOsr_temp - rxOsr_int >= 0.5) { + if((rxOsr_temp - rxOsr_int) >= 0.5) { rxOsr_dec |= 0x04; rxOsr_temp -= 0.5; } - if(rxOsr_temp - rxOsr_int >= 0.25) { + if((rxOsr_temp - rxOsr_int) >= 0.25) { rxOsr_dec |= 0x02; rxOsr_temp -= 0.25; } - if(rxOsr_temp - rxOsr_int >= 0.125) { + if((rxOsr_temp - rxOsr_int) >= 0.125) { rxOsr_dec |= 0x01; rxOsr_temp -= 0.125; } diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h index 7fbe26b6..29417363 100644 --- a/src/modules/Si443x/Si443x.h +++ b/src/modules/Si443x/Si443x.h @@ -597,7 +597,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Binary receive method. Will attempt to receive arbitrary binary data up to 64 bytes long. @@ -609,7 +609,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t receive(uint8_t* data, size_t len); + int16_t receive(uint8_t* data, size_t len) override; /*! \brief Sets the module to sleep to save power. %Module will not be able to transmit or receive any data while in sleep mode. @@ -624,7 +624,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t standby(); + int16_t standby() override; /*! \brief Enables direct transmission mode. While in direct mode, the module will not be able to transmit or receive packets. @@ -633,14 +633,14 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmitDirect(uint32_t frf = 0); + int16_t transmitDirect(uint32_t frf = 0) override; /*! \brief Enables direct reception mode. While in direct mode, the module will not be able to transmit or receive packets. \returns \ref status_codes */ - int16_t receiveDirect(); + int16_t receiveDirect() override; /*! \brief Disables direct mode and enables packet mode, allowing the module to receive packets. @@ -674,7 +674,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0); + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; /*! \brief Interrupt-driven receive method. IRQ will be activated when full valid packet is received. @@ -692,7 +692,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t len); + int16_t readData(uint8_t* data, size_t len) override; // configuration methods @@ -712,7 +712,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setFrequencyDeviation(float freqDev); + int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Sets receiver bandwidth. Allowed values range from 2.6 to 620.7 kHz. @@ -739,7 +739,7 @@ class Si443x: public PhysicalLayer { \returns Length of last received packet in bytes. */ - size_t getPacketLength(bool update = true); + size_t getPacketLength(bool update = true) override; /*! \brief Sets transmission encoding. Only available in FSK mode. @@ -748,7 +748,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setEncoding(uint8_t encoding); + int16_t setEncoding(uint8_t encoding) override; /*! \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. @@ -758,7 +758,7 @@ class Si443x: public PhysicalLayer { \returns \ref status_codes */ - int16_t setDataShaping(float sh); + int16_t setDataShaping(float sh) override; /*! \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. @@ -775,11 +775,11 @@ class Si443x: public PhysicalLayer { #endif Module* _mod; - float _br; - float _freqDev; + float _br = 0; + float _freqDev = 0; - size_t _packetLength; - bool _packetLengthQueried; + size_t _packetLength = 0; + bool _packetLengthQueried = false; int16_t setFrequencyRaw(float newFreq); From 57b46386e8644b2b1256a789df8f4d10eea3fbcd Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:03:26 +0200 Subject: [PATCH 244/334] [XBee] Fixes from cppcheck scan --- src/modules/XBee/XBee.cpp | 5 +---- src/modules/XBee/XBee.h | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/modules/XBee/XBee.cpp b/src/modules/XBee/XBee.cpp index 919de28e..d5d4b20c 100644 --- a/src/modules/XBee/XBee.cpp +++ b/src/modules/XBee/XBee.cpp @@ -3,9 +3,6 @@ XBee::XBee(Module* mod) { _mod = mod; - _frameID = 0x01; - _frameLength = 0; - _frameHeaderProcessed = false; } int16_t XBee::begin(long speed) { @@ -97,9 +94,9 @@ size_t XBee::available() { return(0); } - uint8_t header[3]; if(!_frameHeaderProcessed) { // read frame header + uint8_t header[3]; for(uint8_t i = 0; i < 3; i++) { header[i] = _mod->ModuleSerial->read(); } diff --git a/src/modules/XBee/XBee.h b/src/modules/XBee/XBee.h index e9c970b2..15d7cb92 100644 --- a/src/modules/XBee/XBee.h +++ b/src/modules/XBee/XBee.h @@ -79,7 +79,7 @@ class XBeeSerial: public ISerial { \param panId 8-byte PAN ID to be used, in the form of uppercase hexadecimal string (i.e. 16 characters). */ - int16_t setPanId(const char* panID); + int16_t setPanId(const char* panId); #ifndef RADIOLIB_GODMODE private: @@ -170,22 +170,22 @@ class XBee { \param panId 8-byte PAN ID to be used, in the form of uppercase hexadecimal string (i.e. 16 characters). */ - int16_t setPanId(uint8_t* panID); + int16_t setPanId(uint8_t* panId); #ifndef RADIOLIB_GODMODE private: #endif Module* _mod; - uint8_t _frameID; - size_t _frameLength; - bool _frameHeaderProcessed; + uint8_t _frameID = 0x01; + size_t _frameLength = 0; + bool _frameHeaderProcessed = false; #ifdef RADIOLIB_STATIC_ONLY char _packetData[RADIOLIB_STATIC_ARRAY_SIZE]; #else char* _packetData = new char[0]; #endif - uint8_t _packetSource[8]; + uint8_t _packetSource[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int16_t confirmChanges(); From e60435d57c2130892e31bebc0440e77c6cd75031 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:09:14 +0200 Subject: [PATCH 245/334] Updated module template --- extras/ModuleTemplate.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extras/ModuleTemplate.h b/extras/ModuleTemplate.h index dcb7b0f9..4d957cb0 100644 --- a/extras/ModuleTemplate.h +++ b/extras/ModuleTemplate.h @@ -12,14 +12,16 @@ If at any point you are unsure about the required style, please refer to the rest of the modules. */ +#if !defined(_RADIOLIB__H) && !defined(RADIOLIB_EXCLUDE_) #ifndef _RADIOLIB__H #define _RADIOLIB__H /* - Header file for each module MUST include Module.h. + Header file for each module MUST include Module.h and TypeDef.h in the src folder. The header file MAY include additional header files. */ -#include "Module.h" +#include "../../Module.h" +#include "../../TypeDef.h" /* Only use the following include if the module implements methods for OSI transport layer control. @@ -29,7 +31,7 @@ You also MUST provide crystal oscillator frequency and frequency configuration divisor step resolution to the TransportLayer constructor. */ -//#include "../protocols/TransportLayer.h" +//#include "../../protocols/PhysicalLayer/TransportLayer.h" /* Only use the following include if the module implements methods for OSI physical layer control. @@ -37,7 +39,7 @@ In this case, your class MUST implement all virtual methods of PhysicalLayer class. */ -//#include "../protocols/PhysicalLayer.h" +//#include "../../protocols/PhysicalLayer/PhysicalLayer.h" /* Register map @@ -74,7 +76,7 @@ class { The class MAY implement additional overloaded constructors. */ // constructor - (Module* module); + (Module* mod); /* The class MUST implement at least one basic method called "begin". @@ -105,3 +107,5 @@ class { }; #endif + +#endif From 75f2db65099b7db03aa2e1d44a9d10107282fac8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:10:02 +0200 Subject: [PATCH 246/334] [nRF24] Fixes from cppcheck scan --- src/modules/nRF24/nRF24.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 55802bbe..d41e683f 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -189,7 +189,7 @@ class nRF24: public PhysicalLayer { \param mod Instance of Module that will be used to communicate with the radio. */ - nRF24(Module* module); + nRF24(Module* mod); // basic methods @@ -220,7 +220,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t standby(); + int16_t standby() override; /*! \brief Blocking binary transmit method. @@ -234,7 +234,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmit(uint8_t* data, size_t len, uint8_t addr); + int16_t transmit(uint8_t* data, size_t len, uint8_t addr) override; /*! \brief Blocking binary receive method. @@ -246,7 +246,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t receive(uint8_t* data, size_t len); + int16_t receive(uint8_t* data, size_t len) override; /*! \brief Starts direct mode transmission. @@ -255,14 +255,14 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t transmitDirect(uint32_t frf = 0); + int16_t transmitDirect(uint32_t frf = 0) override; /*! \brief Dummy direct mode reception method, to ensure PhysicalLayer compatibility. \returns \ref status_codes */ - int16_t receiveDirect(); + int16_t receiveDirect() override; // interrupt methods @@ -285,7 +285,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr); + int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr) override; /*! \brief Interrupt-driven receive method. IRQ will be activated when full packet is received. @@ -303,7 +303,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t len); + int16_t readData(uint8_t* data, size_t len) override; // configuration methods @@ -406,7 +406,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t setFrequencyDeviation(float freqDev); + int16_t setFrequencyDeviation(float freqDev) override; /*! \brief Query modem for the packet length of received payload. @@ -415,8 +415,7 @@ class nRF24: public PhysicalLayer { \returns Length of last received packet in bytes. */ - size_t getPacketLength(bool update = true); - + size_t getPacketLength(bool update = true) override; /*! \brief Enable CRC filtering and generation. @@ -454,7 +453,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t setDataShaping(float sh); + int16_t setDataShaping(float sh) override; /*! \brief Dummy encoding configuration method, to ensure PhysicalLayer compatibility. @@ -463,14 +462,14 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t setEncoding(uint8_t encoding); + int16_t setEncoding(uint8_t encoding) override; #ifndef RADIOLIB_GODMODE private: #endif Module* _mod; - uint8_t _addrWidth; + uint8_t _addrWidth = 0; int16_t config(); void clearIRQ(); From 36d41671613330fa0312bc281e07eaac23539bca Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:23:57 +0200 Subject: [PATCH 247/334] [AX25] Fixes from cppcheck scan --- src/protocols/AX25/AX25.cpp | 7 +++---- src/protocols/AX25/AX25.h | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index e73021a6..edde12c4 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -74,8 +74,7 @@ int16_t AX25Frame::setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs } // check repeater configuration - if(!(((repeaterCallsigns == NULL) && (repeaterSSIDs == NULL) && (numRepeaters == 0)) || - ((repeaterCallsigns != NULL) && (repeaterSSIDs != NULL) && (numRepeaters != 0)))) { + if((repeaterCallsigns == NULL) || (repeaterSSIDs == NULL)) { return(ERR_INVALID_NUM_REPEATERS); } for(uint16_t i = 0; i < numRepeaters; i++) { @@ -390,8 +389,8 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { https://creativecommons.org/licenses/by-sa/4.0/ */ uint16_t AX25Client::getFrameCheckSequence(uint8_t* buff, size_t len) { - uint8_t outBit = 0; - uint16_t mask = 0x0000; + uint8_t outBit; + uint16_t mask; uint16_t shiftReg = CRC_CCITT_INIT; for(size_t i = 0; i < len; i++) { diff --git a/src/protocols/AX25/AX25.h b/src/protocols/AX25/AX25.h index c751a7c1..7f7ed959 100644 --- a/src/protocols/AX25/AX25.h +++ b/src/protocols/AX25/AX25.h @@ -266,7 +266,7 @@ class AX25Client { \param phy Pointer to the wireless module providing PhysicalLayer communication. */ - AX25Client(PhysicalLayer* phy); + explicit AX25Client(PhysicalLayer* phy); #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! @@ -274,7 +274,7 @@ class AX25Client { \param audio Pointer to the AFSK instance providing audio. */ - AX25Client(AFSKClient* audio); + explicit AX25Client(AFSKClient* audio); #endif // basic methods @@ -324,13 +324,13 @@ class AX25Client { void* _audio; #endif - char _srcCallsign[AX25_MAX_CALLSIGN_LEN + 1]; - uint8_t _srcSSID; - uint16_t _preambleLen; + char _srcCallsign[AX25_MAX_CALLSIGN_LEN + 1] = {0, 0, 0, 0, 0, 0, 0}; + uint8_t _srcSSID = 0; + uint16_t _preambleLen = 0; - uint16_t getFrameCheckSequence(uint8_t* buff, size_t len); - uint8_t flipBits(uint8_t b); - uint16_t flipBits16(uint16_t i); + static uint16_t getFrameCheckSequence(uint8_t* buff, size_t len); + static uint8_t flipBits(uint8_t b); + static uint16_t flipBits16(uint16_t i); }; #endif From 02bb36e1afdbb9b837b99ded8ecf5877ddc84648 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:26:55 +0200 Subject: [PATCH 248/334] [Hell] Fixes from cppcheck scan --- src/protocols/Hellschreiber/Hellschreiber.cpp | 3 ++- src/protocols/Hellschreiber/Hellschreiber.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/protocols/Hellschreiber/Hellschreiber.cpp b/src/protocols/Hellschreiber/Hellschreiber.cpp index 5c6483b3..d2355480 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.cpp +++ b/src/protocols/Hellschreiber/Hellschreiber.cpp @@ -153,7 +153,8 @@ size_t HellClient::print(double n, int digits) { } size_t HellClient::println(void) { - return(0); + // Hellschreiber has no concept of "line ending", print one space instead + return(HellClient::print(' ')); } size_t HellClient::println(__FlashStringHelper* fstr) { diff --git a/src/protocols/Hellschreiber/Hellschreiber.h b/src/protocols/Hellschreiber/Hellschreiber.h index a70e74e7..74eacb33 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.h +++ b/src/protocols/Hellschreiber/Hellschreiber.h @@ -136,7 +136,7 @@ class HellClient { size_t println(void); size_t println(__FlashStringHelper*); - size_t println(const String &s); + size_t println(const String &); size_t println(const char[]); size_t println(char); size_t println(unsigned char, int = DEC); @@ -156,8 +156,8 @@ class HellClient { void* _audio; #endif - uint32_t _base, _baseHz; - uint32_t _pixelDuration; + uint32_t _base = 0, _baseHz = 0; + uint32_t _pixelDuration = 0; size_t printNumber(unsigned long, uint8_t); size_t printFloat(double, uint8_t); From 0c7f597b7f7af9dff5f4b9461eb3672d0311f9d1 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:28:02 +0200 Subject: [PATCH 249/334] [Hell] Made ctors explicit --- src/protocols/Hellschreiber/Hellschreiber.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/protocols/Hellschreiber/Hellschreiber.h b/src/protocols/Hellschreiber/Hellschreiber.h index 74eacb33..1f8087e1 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.h +++ b/src/protocols/Hellschreiber/Hellschreiber.h @@ -90,7 +90,7 @@ class HellClient { \param phy Pointer to the wireless module providing PhysicalLayer communication. */ - HellClient(PhysicalLayer* phy); + explicit HellClient(PhysicalLayer* phy); #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! @@ -98,7 +98,7 @@ class HellClient { \param audio Pointer to the AFSK instance providing audio. */ - HellClient(AFSKClient* audio); + explicit HellClient(AFSKClient* audio); #endif // basic methods From f394912c920f819bde3f10f4ecf5fb71ba72fc29 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:29:37 +0200 Subject: [PATCH 250/334] [HTTP] Fixes from cppcheck scan --- src/protocols/HTTP/HTTP.cpp | 2 +- src/protocols/HTTP/HTTP.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/protocols/HTTP/HTTP.cpp b/src/protocols/HTTP/HTTP.cpp index 6f4cd23d..63b2fe95 100644 --- a/src/protocols/HTTP/HTTP.cpp +++ b/src/protocols/HTTP/HTTP.cpp @@ -142,7 +142,7 @@ int16_t HTTPClient::post(const char* url, const char* content, String& response, // build the POST request char contentLengthStr[12]; - sprintf(contentLengthStr, "%d", strlen(content)); + sprintf(contentLengthStr, "%u", (uint16_t)strlen(content)); char* request = new char[strlen(endpoint) + strlen(host) + strlen(contentType) + strlen(contentLengthStr) + strlen(content) + 64 + 1]; strcpy(request, "POST "); strcat(request, endpoint); diff --git a/src/protocols/HTTP/HTTP.h b/src/protocols/HTTP/HTTP.h index edc7d6f1..ae9a3888 100644 --- a/src/protocols/HTTP/HTTP.h +++ b/src/protocols/HTTP/HTTP.h @@ -19,7 +19,7 @@ class HTTPClient { \param port Port to be used for HTTP. Defaults to 80. */ - HTTPClient(TransportLayer* tl, uint16_t port = 80); + explicit HTTPClient(TransportLayer* tl, uint16_t port = 80); /*! \brief Sends HTTP GET request. From cb0cf75c9958f37378e730eaf923b82ba5d193a8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:32:32 +0200 Subject: [PATCH 251/334] [MQTT] Fixes from cppcheck scan --- src/protocols/MQTT/MQTT.cpp | 3 --- src/protocols/MQTT/MQTT.h | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/protocols/MQTT/MQTT.cpp b/src/protocols/MQTT/MQTT.cpp index cc561157..cb62321c 100644 --- a/src/protocols/MQTT/MQTT.cpp +++ b/src/protocols/MQTT/MQTT.cpp @@ -96,7 +96,6 @@ int16_t MQTTClient::connect(const char* host, const char* clientId, const char* packet[pos++] = (passwordLen & 0xFF00) >> 8;; packet[pos++] = passwordLen & 0x00FF; memcpy(packet + pos, password, passwordLen); - pos += passwordLen; } // create TCP connection @@ -198,7 +197,6 @@ int16_t MQTTClient::publish(const char* topic, const char* message) { // payload // message memcpy(packet + pos, message, messageLen); - pos += messageLen; // send MQTT packet int16_t state = _tl->send(packet, 1 + encodedBytes + remainingLength); @@ -314,7 +312,6 @@ int16_t MQTTClient::unsubscribe(const char* topicFilter) { packet[pos++] = (topicFilterLen & 0xFF00) >> 8;; packet[pos++] = topicFilterLen & 0x00FF; memcpy(packet + pos, topicFilter, topicFilterLen); - pos += topicFilterLen; // send MQTT packet int16_t state = _tl->send(packet, 1 + encodedBytes + remainingLength); diff --git a/src/protocols/MQTT/MQTT.h b/src/protocols/MQTT/MQTT.h index efc40d3a..e6b0adbe 100644 --- a/src/protocols/MQTT/MQTT.h +++ b/src/protocols/MQTT/MQTT.h @@ -39,7 +39,7 @@ class MQTTClient { \param tl Pointer to the wireless module providing TransportLayer communication. */ - MQTTClient(TransportLayer* tl, uint16_t port = 1883); + explicit MQTTClient(TransportLayer* tl, uint16_t port = 1883); // basic methods @@ -135,8 +135,8 @@ class MQTTClient { uint16_t _port; uint16_t _packetId; - size_t encodeLength(uint32_t len, uint8_t* encoded); - uint32_t decodeLength(uint8_t* encoded); + static size_t encodeLength(uint32_t len, uint8_t* encoded); + static uint32_t decodeLength(uint8_t* encoded); }; #endif From b611cf3a9c988011cd0bbc90bacf5e1e99aae317 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:34:06 +0200 Subject: [PATCH 252/334] [Morse] Fixes from cppcheck scan --- src/protocols/Morse/Morse.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/protocols/Morse/Morse.h b/src/protocols/Morse/Morse.h index 276a443b..c7bcce52 100644 --- a/src/protocols/Morse/Morse.h +++ b/src/protocols/Morse/Morse.h @@ -93,7 +93,7 @@ class MorseClient { \param phy Pointer to the wireless module providing PhysicalLayer communication. */ - MorseClient(PhysicalLayer* phy); + explicit MorseClient(PhysicalLayer* phy); #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! @@ -101,7 +101,7 @@ class MorseClient { \param audio Pointer to the AFSK instance providing audio. */ - MorseClient(AFSKClient* audio); + explicit MorseClient(AFSKClient* audio); #endif // basic methods @@ -141,7 +141,7 @@ class MorseClient { size_t println(void); size_t println(__FlashStringHelper*); - size_t println(const String &s); + size_t println(const String &); size_t println(const char[]); size_t println(char); size_t println(unsigned char, int = DEC); @@ -161,8 +161,8 @@ class MorseClient { void* _audio; #endif - uint32_t _base, _baseHz; - uint16_t _dotLength; + uint32_t _base = 0, _baseHz = 0; + uint16_t _dotLength = 0; size_t printNumber(unsigned long, uint8_t); size_t printFloat(double, uint8_t); From c429563deb82180cdc497cb2a81c9f8814423775 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:42:41 +0200 Subject: [PATCH 253/334] [PHY] Fixes from cppcheck scan --- src/protocols/PhysicalLayer/PhysicalLayer.cpp | 2 +- src/protocols/PhysicalLayer/PhysicalLayer.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.cpp b/src/protocols/PhysicalLayer/PhysicalLayer.cpp index 0fc34b5b..9bb8e322 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.cpp +++ b/src/protocols/PhysicalLayer/PhysicalLayer.cpp @@ -140,6 +140,6 @@ int16_t PhysicalLayer::receive(String& str, size_t len) { return(state); } -float PhysicalLayer::getFreqStep() { +float PhysicalLayer::getFreqStep() const { return(_freqStep); } diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.h b/src/protocols/PhysicalLayer/PhysicalLayer.h index a434bcb3..601c39c6 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.h +++ b/src/protocols/PhysicalLayer/PhysicalLayer.h @@ -164,11 +164,11 @@ class PhysicalLayer { \brief Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class. While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. - \param FRF 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY. + \param frf 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY. \returns \ref status_codes */ - virtual int16_t transmitDirect(uint32_t FRF = 0) = 0; + virtual int16_t transmitDirect(uint32_t frf = 0) = 0; /*! \brief Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class. @@ -213,7 +213,7 @@ class PhysicalLayer { \returns Synthesizer frequency step size in Hz. */ - float getFreqStep(); + float getFreqStep() const; /*! \brief Query modem for the packet length of received payload. From 91de2e1eeb520117692543f48a851b0ac3331bed Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 15:43:06 +0200 Subject: [PATCH 254/334] [SSTV] Moved method back to .cpp file --- src/protocols/SSTV/SSTV.cpp | 4 ++++ src/protocols/SSTV/SSTV.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp index 7988fc64..6e658a25 100644 --- a/src/protocols/SSTV/SSTV.cpp +++ b/src/protocols/SSTV/SSTV.cpp @@ -278,6 +278,10 @@ void SSTVClient::sendLine(uint32_t* imgLine) { } } +uint16_t SSTVClient::getPictureHeight() const { + return(_mode.height); +} + void SSTVClient::tone(float freq, uint32_t len) { uint32_t start = micros(); if(_audio != nullptr) { diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h index ea64ceca..fd827b6a 100644 --- a/src/protocols/SSTV/SSTV.h +++ b/src/protocols/SSTV/SSTV.h @@ -180,7 +180,7 @@ class SSTVClient { \returns Picture height of the currently configured SSTV mode in pixels. */ - uint16_t getPictureHeight() const { return(_mode.height); }; + uint16_t getPictureHeight() const; #ifndef RADIOLIB_GODMODE private: From c439b097d85e01e07650e752f46dee035612dc70 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 16:05:56 +0200 Subject: [PATCH 255/334] Switched to initializer lists --- src/Module.cpp | 89 +++++++++++++++++++++++++++----------------------- src/Module.h | 7 ++-- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index 218be4fa..ee9d00e3 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -1,35 +1,39 @@ #include "Module.h" -Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst) { - _cs = cs; - _rx = RADIOLIB_NC; - _tx = RADIOLIB_NC; - _irq = irq; - _rst = rst; +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst): + _cs(cs), + _irq(irq), + _rst(rst), + _rx(RADIOLIB_NC), + _tx(RADIOLIB_NC), + _spiSettings(SPISettings(2000000, MSBFIRST, SPI_MODE0)) +{ _spi = &RADIOLIB_DEFAULT_SPI; - _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); _initInterface = true; ModuleSerial = NULL; } -Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio) { - _cs = cs; - _rx = gpio; - _tx = RADIOLIB_NC; - _irq = irq; - _rst = rst; +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio): + _cs(cs), + _irq(irq), + _rst(rst), + _rx(gpio), + _tx(RADIOLIB_NC), + _spiSettings(SPISettings(2000000, MSBFIRST, SPI_MODE0)) +{ _spi = &RADIOLIB_DEFAULT_SPI; - _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); _initInterface = true; ModuleSerial = NULL; } -Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial, RADIOLIB_PIN_TYPE rst) { - _cs = RADIOLIB_NC; - _rx = rx; - _tx = tx; - _irq = RADIOLIB_NC; - _rst = rst; +Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial, RADIOLIB_PIN_TYPE rst): + _cs(RADIOLIB_NC), + _irq(RADIOLIB_NC), + _rst(rst), + _rx(rx), + _tx(tx), + _spiSettings(SPISettings(2000000, MSBFIRST, SPI_MODE0)) +{ _initInterface = true; #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED @@ -40,38 +44,41 @@ Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* seria #endif } -Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass& spi, SPISettings spiSettings) { - _cs = cs; - _rx = RADIOLIB_NC; - _tx = RADIOLIB_NC; - _irq = irq; - _rst = rst; +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass& spi, SPISettings spiSettings): + _cs(cs), + _irq(irq), + _rst(rst), + _rx(RADIOLIB_NC), + _tx(RADIOLIB_NC), + _spiSettings(spiSettings) +{ _spi = &spi; - _spiSettings = spiSettings; _initInterface = false; ModuleSerial = NULL; } -Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings) { - _cs = cs; - _rx = gpio; - _tx = RADIOLIB_NC; - _irq = irq; - _rst = rst; +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings): + _cs(cs), + _irq(irq), + _rst(rst), + _rx(gpio), + _tx(RADIOLIB_NC), + _spiSettings(spiSettings) +{ _spi = &spi; - _spiSettings = spiSettings; _initInterface = false; ModuleSerial = NULL; } -Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* serial) { - _cs = cs; - _rx = rx; - _tx = tx; - _irq = irq; - _rst = rst; +Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* serial): + _cs(cs), + _irq(irq), + _rst(rst), + _rx(rx), + _tx(tx), + _spiSettings(spiSettings) +{ _spi = &spi; - _spiSettings = spiSettings; _initInterface = false; #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED diff --git a/src/Module.h b/src/Module.h index ccc571c0..71b372eb 100644 --- a/src/Module.h +++ b/src/Module.h @@ -409,14 +409,15 @@ class Module { private: #endif RADIOLIB_PIN_TYPE _cs = RADIOLIB_NC; - RADIOLIB_PIN_TYPE _tx = RADIOLIB_NC; - RADIOLIB_PIN_TYPE _rx = RADIOLIB_NC; RADIOLIB_PIN_TYPE _irq = RADIOLIB_NC; RADIOLIB_PIN_TYPE _rst = RADIOLIB_NC; + RADIOLIB_PIN_TYPE _rx = RADIOLIB_NC; + RADIOLIB_PIN_TYPE _tx = RADIOLIB_NC; + + SPISettings _spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0); bool _initInterface = false; SPIClass* _spi = NULL; - SPISettings _spiSettings; bool _useRfSwitch = false; RADIOLIB_PIN_TYPE _rxEn = RADIOLIB_NC, _txEn = RADIOLIB_NC; From 31c37536b9c87bd00e805fc5fdeb8c02f05e40ed Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 16:16:31 +0200 Subject: [PATCH 256/334] Fixed definition --- src/BuildOpt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 490dbf1a..0366a125 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -53,7 +53,7 @@ // some of RadioLib drivers may be excluded, to prevent collisions with platform (or to speed up build process) // for example, to exclude ESP8266 driver: - //RADIOLIB_EXCLUDE_ESP8266 + //#define RADIOLIB_EXCLUDE_ESP8266 #else #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) From 93f1bd51d36098bbeff4e95487f57aca568c8653 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:13:16 +0200 Subject: [PATCH 257/334] Updated template implementation file --- extras/ModuleTemplate.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extras/ModuleTemplate.cpp b/extras/ModuleTemplate.cpp index 0ee26318..07267305 100644 --- a/extras/ModuleTemplate.cpp +++ b/extras/ModuleTemplate.cpp @@ -1,4 +1,5 @@ #include ".h" +#if !defined(RADIOLIB_EXCLUDE_) ::(Module* mod) { /* @@ -12,10 +13,10 @@ int16_t ::begin() { "begin" method implementation MUST call the "init" method with appropriate settings. */ _mod->init(); - + /* "begin" method SHOULD implement some sort of mechanism to verify the connection between Arduino and the module. - + For example, sending AT command for UART modules, or reading a version register for SPI/I2C modules */ } From ccb363548599252c8db5246a3de8d36d3b3a3680 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:17:14 +0200 Subject: [PATCH 258/334] [RF69] Fixed exclusion macros --- src/modules/RF69/RF69.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 70815395..1994980b 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_RF69_H) && !defined(RADIOLIB_EXCLUDE_RF69) +#if !defined(_RADIOLIB_RF69_H) #define _RADIOLIB_RF69_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_RF69) + #include "../../Module.h" #include "../../protocols/PhysicalLayer/PhysicalLayer.h" @@ -835,3 +838,5 @@ class RF69: public PhysicalLayer { }; #endif + +#endif From 763fed74ffd8a5163046ed016317ce54c643fe03 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:17:29 +0200 Subject: [PATCH 259/334] [RFM2x] Fixed exclusion macros --- src/modules/RFM2x/RFM22.h | 7 ++++++- src/modules/RFM2x/RFM23.h | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/modules/RFM2x/RFM22.h b/src/modules/RFM2x/RFM22.h index bfad6cd7..3204c7ca 100644 --- a/src/modules/RFM2x/RFM22.h +++ b/src/modules/RFM2x/RFM22.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_RFM22_H) && !defined(RADIOLIB_EXCLUDE_SI443X) +#if !defined(_RADIOLIB_RFM22_H) #define _RADIOLIB_RFM22_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_RFM2X) + #include "../../Module.h" #include "../Si443x/Si443x.h" #include "../Si443x/Si4432.h" @@ -14,3 +17,5 @@ using RFM22 = Si4432; #endif + +#endif diff --git a/src/modules/RFM2x/RFM23.h b/src/modules/RFM2x/RFM23.h index 506c3482..45a708a2 100644 --- a/src/modules/RFM2x/RFM23.h +++ b/src/modules/RFM2x/RFM23.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_RFM23_H) && !defined(RADIOLIB_EXCLUDE_SI443X) +#if !defined(_RADIOLIB_RFM23_H) #define _RADIOLIB_RFM23_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_RFM2X) + #include "../../Module.h" #include "../Si443x/Si443x.h" #include "../Si443x/Si4431.h" @@ -14,3 +17,5 @@ using RFM23 = Si4431; #endif + +#endif From a218cc04f2d8b712b2e021b00b8229dccdbe5f11 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:17:37 +0200 Subject: [PATCH 260/334] [RFM9x] Fixed exclusion macros --- src/modules/RFM9x/RFM95.h | 7 ++++++- src/modules/RFM9x/RFM96.h | 7 ++++++- src/modules/RFM9x/RFM97.h | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modules/RFM9x/RFM95.h b/src/modules/RFM9x/RFM95.h index 914ccad9..8c760630 100644 --- a/src/modules/RFM9x/RFM95.h +++ b/src/modules/RFM9x/RFM95.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_RFM95_H) && !defined(RADIOLIB_EXCLUDE_RFM9X) +#if !defined(_RADIOLIB_RFM95_H) #define _RADIOLIB_RFM95_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_RFM9X) + #include "../../Module.h" #include "../SX127x/SX127x.h" #include "../SX127x/SX1278.h" @@ -75,3 +78,5 @@ class RFM95: public SX1278 { }; #endif + +#endif diff --git a/src/modules/RFM9x/RFM96.h b/src/modules/RFM9x/RFM96.h index 985fcf74..9bafe6ea 100644 --- a/src/modules/RFM9x/RFM96.h +++ b/src/modules/RFM9x/RFM96.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_RFM96_H) && !defined(RADIOLIB_EXCLUDE_RFM9X) +#if !defined(_RADIOLIB_RFM96_H) #define _RADIOLIB_RFM96_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_RFM9X) + #include "../../Module.h" #include "../SX127x/SX127x.h" #include "../SX127x/SX1278.h" @@ -82,3 +85,5 @@ class RFM96: public SX1278 { using RFM98 = RFM96; #endif + +#endif diff --git a/src/modules/RFM9x/RFM97.h b/src/modules/RFM9x/RFM97.h index 90e59e42..30454f91 100644 --- a/src/modules/RFM9x/RFM97.h +++ b/src/modules/RFM9x/RFM97.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_RFM97_H) && !defined(RADIOLIB_EXCLUDE_RFM9X) +#if !defined(_RADIOLIB_RFM97_H) #define _RADIOLIB_RFM97_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_RFM9X) + #include "../../Module.h" #include "../SX127x/SX127x.h" #include "../SX127x/SX1278.h" @@ -42,3 +45,5 @@ class RFM97: public RFM95 { }; #endif + +#endif From 3aa5adf91665435d36294a1aa60beb51ab68a4b9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:17:46 +0200 Subject: [PATCH 261/334] [SX1231] Fixed exclusion macros --- src/modules/SX1231/SX1231.cpp | 2 +- src/modules/SX1231/SX1231.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/SX1231/SX1231.cpp b/src/modules/SX1231/SX1231.cpp index 53981685..6122a452 100644 --- a/src/modules/SX1231/SX1231.cpp +++ b/src/modules/SX1231/SX1231.cpp @@ -1,5 +1,5 @@ #include "SX1231.h" -#if !defined(RADIOLIB_EXCLUDE_RF69) +#if !defined(RADIOLIB_EXCLUDE_SX1231) SX1231::SX1231(Module* mod) : RF69(mod) { diff --git a/src/modules/SX1231/SX1231.h b/src/modules/SX1231/SX1231.h index 4597efa8..9ec08f4c 100644 --- a/src/modules/SX1231/SX1231.h +++ b/src/modules/SX1231/SX1231.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1231_H) && !defined(RADIOLIB_EXCLUDE_RF69) +#if !defined(_RADIOLIB_SX1231_H) #define _RADIOLIB_SX1231_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX1231) + #include "../../Module.h" #include "../RF69/RF69.h" @@ -53,3 +56,5 @@ class SX1231: public RF69 { }; #endif + +#endif From b1fa564cd35cd40e860aa874473591a663688aa0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:17:54 +0200 Subject: [PATCH 262/334] [SX126x] Fixed exclusion macros --- src/modules/SX126x/SX1261.h | 6 +++++- src/modules/SX126x/SX1262.h | 7 ++++++- src/modules/SX126x/SX1268.h | 7 ++++++- src/modules/SX126x/SX126x.h | 7 ++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/modules/SX126x/SX1261.h b/src/modules/SX126x/SX1261.h index 5b6f9ef6..a52d4235 100644 --- a/src/modules/SX126x/SX1261.h +++ b/src/modules/SX126x/SX1261.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1261_H) && !defined(RADIOLIB_EXCLUDE_SX126X) +#if !defined(_RADIOLIB_SX1261_H) #define _RADIOLIB_SX1261_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX126X) + #include "../../Module.h" #include "SX126x.h" #include "SX1262.h" @@ -38,5 +41,6 @@ class SX1261 : public SX1262 { }; +#endif #endif diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index b268759b..1aa0529f 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1262_H) && !defined(RADIOLIB_EXCLUDE_SX126X) +#if !defined(_RADIOLIB_SX1262_H) #define _RADIOLIB_SX1262_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX126X) + #include "../../Module.h" #include "SX126x.h" @@ -103,3 +106,5 @@ class SX1262: public SX126x { }; #endif + +#endif diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index 76f01c1e..d7acd5f0 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1268_H) && !defined(RADIOLIB_EXCLUDE_SX126X) +#if !defined(_RADIOLIB_SX1268_H) #define _RADIOLIB_SX1268_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX126X) + #include "../../Module.h" #include "SX126x.h" @@ -103,3 +106,5 @@ class SX1268: public SX126x { }; #endif + +#endif diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index ae92e253..849d8757 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX126X_H) && !defined(RADIOLIB_EXCLUDE_SX126X) +#if !defined(_RADIOLIB_SX126X_H) #define _RADIOLIB_SX126X_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX126X) + #include "../../Module.h" #include "../../protocols/PhysicalLayer/PhysicalLayer.h" @@ -925,3 +928,5 @@ class SX126x: public PhysicalLayer { }; #endif + +#endif From 368c646ad56f928a4fe3b85f556d25348fc897c4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:18:04 +0200 Subject: [PATCH 263/334] [SX127x] Fixed exclusion macros --- src/modules/SX127x/SX1272.h | 7 ++++++- src/modules/SX127x/SX1273.h | 7 ++++++- src/modules/SX127x/SX1276.h | 7 ++++++- src/modules/SX127x/SX1277.h | 7 ++++++- src/modules/SX127x/SX1278.h | 7 ++++++- src/modules/SX127x/SX1279.h | 7 ++++++- src/modules/SX127x/SX127x.h | 7 ++++++- 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index 7538c845..e47e7fed 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1272_H) && !defined(RADIOLIB_EXCLUDE_SX127X) +#if !defined(_RADIOLIB_SX1272_H) #define _RADIOLIB_SX1272_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX127X) + #include "../../Module.h" #include "SX127x.h" @@ -271,3 +274,5 @@ class SX1272: public SX127x { }; #endif + +#endif diff --git a/src/modules/SX127x/SX1273.h b/src/modules/SX127x/SX1273.h index ac7fcd98..e8b3902b 100644 --- a/src/modules/SX127x/SX1273.h +++ b/src/modules/SX127x/SX1273.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1273_H) && !defined(RADIOLIB_EXCLUDE_SX127X) +#if !defined(_RADIOLIB_SX1273_H) #define _RADIOLIB_SX1273_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX127X) + #include "SX1272.h" /*! @@ -69,3 +72,5 @@ class SX1273: public SX1272 { }; #endif + +#endif diff --git a/src/modules/SX127x/SX1276.h b/src/modules/SX127x/SX1276.h index 55861cc3..cc4ce493 100644 --- a/src/modules/SX127x/SX1276.h +++ b/src/modules/SX127x/SX1276.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1276_H) && !defined(RADIOLIB_EXCLUDE_SX127X) +#if !defined(_RADIOLIB_SX1276_H) #define _RADIOLIB_SX1276_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX127X) + #include "SX1278.h" /*! @@ -69,3 +72,5 @@ class SX1276: public SX1278 { }; #endif + +#endif diff --git a/src/modules/SX127x/SX1277.h b/src/modules/SX127x/SX1277.h index afbfdc1f..804ee6f9 100644 --- a/src/modules/SX127x/SX1277.h +++ b/src/modules/SX127x/SX1277.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1277_H) && !defined(RADIOLIB_EXCLUDE_SX127X) +#if !defined(_RADIOLIB_SX1277_H) #define _RADIOLIB_SX1277_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX127X) + #include "SX1278.h" /*! @@ -78,3 +81,5 @@ class SX1277: public SX1278 { }; #endif + +#endif diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index ccd47da8..c7e5d5b5 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1278_H) && !defined(RADIOLIB_EXCLUDE_SX127X) +#if !defined(_RADIOLIB_SX1278_H) #define _RADIOLIB_SX1278_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX127X) + #include "../../Module.h" #include "SX127x.h" @@ -280,3 +283,5 @@ class SX1278: public SX127x { }; #endif + +#endif diff --git a/src/modules/SX127x/SX1279.h b/src/modules/SX127x/SX1279.h index 9908b3eb..c466b64a 100644 --- a/src/modules/SX127x/SX1279.h +++ b/src/modules/SX127x/SX1279.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1279_H) && !defined(RADIOLIB_EXCLUDE_SX127X) +#if !defined(_RADIOLIB_SX1279_H) #define _RADIOLIB_SX1279_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX127X) + #include "SX1278.h" /*! @@ -69,3 +72,5 @@ class SX1279: public SX1278 { }; #endif + +#endif diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index ac22a49b..1a318c33 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX127X_H) && !defined(RADIOLIB_EXCLUDE_SX127X) +#if !defined(_RADIOLIB_SX127X_H) #define _RADIOLIB_SX127X_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX127X) + #include "../../Module.h" #include "../../protocols/PhysicalLayer/PhysicalLayer.h" @@ -967,3 +970,5 @@ class SX127x: public PhysicalLayer { }; #endif + +#endif From 96f4bd667e6aca0430b20db7f099b5490114a36a Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:18:13 +0200 Subject: [PATCH 264/334] [SX128x] Fixed exclusion macros --- src/modules/SX128x/SX1280.h | 7 ++++++- src/modules/SX128x/SX1281.h | 7 ++++++- src/modules/SX128x/SX1282.h | 7 ++++++- src/modules/SX128x/SX128x.h | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/modules/SX128x/SX1280.h b/src/modules/SX128x/SX1280.h index 4c079ac4..3cd3184a 100644 --- a/src/modules/SX128x/SX1280.h +++ b/src/modules/SX128x/SX1280.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1280_H) && !defined(RADIOLIB_EXCLUDE_SX128X) +#if !defined(_RADIOLIB_SX1280_H) #define _RADIOLIB_SX1280_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX128X) + #include "../../Module.h" #include "SX128x.h" #include "SX1281.h" @@ -56,3 +59,5 @@ class SX1280: public SX1281 { }; #endif + +#endif diff --git a/src/modules/SX128x/SX1281.h b/src/modules/SX128x/SX1281.h index 6cb85192..67a0a323 100644 --- a/src/modules/SX128x/SX1281.h +++ b/src/modules/SX128x/SX1281.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1281_H) && !defined(RADIOLIB_EXCLUDE_SX128X) +#if !defined(_RADIOLIB_SX1281_H) #define _RADIOLIB_SX1281_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX128X) + #include "../../Module.h" #include "SX128x.h" @@ -26,3 +29,5 @@ class SX1281: public SX128x { }; #endif + +#endif diff --git a/src/modules/SX128x/SX1282.h b/src/modules/SX128x/SX1282.h index 8b677d95..1e3b9be7 100644 --- a/src/modules/SX128x/SX1282.h +++ b/src/modules/SX128x/SX1282.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX1282_H) && !defined(RADIOLIB_EXCLUDE_SX128X) +#if !defined(_RADIOLIB_SX1282_H) #define _RADIOLIB_SX1282_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX128X) + #include "../../Module.h" #include "SX128x.h" #include "SX1280.h" @@ -29,3 +32,5 @@ class SX1282: public SX1280 { }; #endif + +#endif diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 873525fa..131e7baf 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SX128X_H) && !defined(RADIOLIB_EXCLUDE_SX128X) +#if !defined(_RADIOLIB_SX128X_H) #define _RADIOLIB_SX128X_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SX128X) + #include "../../Module.h" #include "../../protocols/PhysicalLayer/PhysicalLayer.h" @@ -815,3 +818,5 @@ class SX128x: public PhysicalLayer { }; #endif + +#endif From 906b0857bd0d3d7fd4cd1c146a464333caf108e5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:18:24 +0200 Subject: [PATCH 265/334] [Si443x] Fixed exclusion macros --- src/modules/Si443x/Si4430.h | 7 ++++++- src/modules/Si443x/Si4431.h | 7 ++++++- src/modules/Si443x/Si4432.h | 7 ++++++- src/modules/Si443x/Si443x.h | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/modules/Si443x/Si4430.h b/src/modules/Si443x/Si4430.h index 815ec7ad..ff3b06f6 100644 --- a/src/modules/Si443x/Si4430.h +++ b/src/modules/Si443x/Si4430.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SI4430_H) && !defined(RADIOLIB_EXCLUDE_SI443X) +#if !defined(_RADIOLIB_SI4430_H) #define _RADIOLIB_SI4430_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SI443X) + #include "../../Module.h" #include "Si4432.h" @@ -72,3 +75,5 @@ class Si4430: public Si4432 { }; #endif + +#endif diff --git a/src/modules/Si443x/Si4431.h b/src/modules/Si443x/Si4431.h index 5f8b3821..00167a7d 100644 --- a/src/modules/Si443x/Si4431.h +++ b/src/modules/Si443x/Si4431.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SI4431_H) && !defined(RADIOLIB_EXCLUDE_SI443X) +#if !defined(_RADIOLIB_SI4431_H) #define _RADIOLIB_SI4431_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SI443X) + #include "../../Module.h" #include "Si4432.h" @@ -63,3 +66,5 @@ class Si4431: public Si4432 { }; #endif + +#endif diff --git a/src/modules/Si443x/Si4432.h b/src/modules/Si443x/Si4432.h index 4b1d0af6..7537e689 100644 --- a/src/modules/Si443x/Si4432.h +++ b/src/modules/Si443x/Si4432.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SI4432_H) && !defined(RADIOLIB_EXCLUDE_SI443X) +#if !defined(_RADIOLIB_SI4432_H) #define _RADIOLIB_SI4432_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SI443X) + #include "../../Module.h" #include "Si443x.h" @@ -72,3 +75,5 @@ class Si4432: public Si443x { }; #endif + +#endif diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h index 29417363..8e2907a5 100644 --- a/src/modules/Si443x/Si443x.h +++ b/src/modules/Si443x/Si443x.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SI443X_H) && !defined(RADIOLIB_EXCLUDE_SI443X) +#if !defined(_RADIOLIB_SI443X_H) #define _RADIOLIB_SI443X_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SI443X) + #include "../../Module.h" #include "../../protocols/PhysicalLayer/PhysicalLayer.h" @@ -794,3 +797,5 @@ class Si443x: public PhysicalLayer { }; #endif + +#endif From 4ca26f6e477efa77b06e7b9d9d78bccd30b1e391 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:18:31 +0200 Subject: [PATCH 266/334] [AFSK] Fixed exclusion macros --- src/protocols/AFSK/AFSK.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/protocols/AFSK/AFSK.h b/src/protocols/AFSK/AFSK.h index c487dd17..d92ffe65 100644 --- a/src/protocols/AFSK/AFSK.h +++ b/src/protocols/AFSK/AFSK.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_AFSK_H) && !defined(RADIOLIB_EXCLUDE_AFSK) +#if !defined(_RADIOLIB_AFSK_H) #define _RADIOLIB_AFSK_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_AFSK) + #include "../../Module.h" #include "../PhysicalLayer/PhysicalLayer.h" @@ -55,3 +58,5 @@ class AFSKClient { }; #endif + +#endif From 152d3d3da38b629809eaea95acd488d794b99af4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:18:40 +0200 Subject: [PATCH 267/334] [AX25] Fixed exclusion macros --- src/protocols/AX25/AX25.cpp | 15 ++++++++++++--- src/protocols/AX25/AX25.h | 9 ++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index edde12c4..d5bedc48 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -112,7 +112,9 @@ void AX25Frame::setSendSequence(uint8_t seqNumber) { AX25Client::AX25Client(PhysicalLayer* phy) { _phy = phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) _audio = nullptr; + #endif } #if !defined(RADIOLIB_EXCLUDE_AFSK) @@ -140,12 +142,14 @@ int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t prea // set module frequency deviation to 0 if using FSK int16_t state = ERR_NONE; + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio == nullptr) { state = _phy->setFrequencyDeviation(0); RADIOLIB_ASSERT(state); state = _phy->setEncoding(0); } + #endif return(state); } @@ -348,9 +352,8 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { // transmit int16_t state = ERR_NONE; - if(_audio == nullptr) { - state = _phy->transmit(stuffedFrameBuff, stuffedFrameBuffLen); - } else { + #if !defined(RADIOLIB_EXCLUDE_AFSK) + if(_audio != nullptr) { _phy->transmitDirect(); // iterate over all bytes in the buffer @@ -372,7 +375,13 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { } _audio->noTone(); + + } else { + #endif + state = _phy->transmit(stuffedFrameBuff, stuffedFrameBuffLen); + #if !defined(RADIOLIB_EXCLUDE_AFSK) } + #endif // deallocate memory #ifndef RADIOLIB_STATIC_ONLY diff --git a/src/protocols/AX25/AX25.h b/src/protocols/AX25/AX25.h index 7f7ed959..20df8d53 100644 --- a/src/protocols/AX25/AX25.h +++ b/src/protocols/AX25/AX25.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_AX25_H) && !defined(RADIOLIB_EXCLUDE_AX25) +#if !defined(_RADIOLIB_AX25_H) #define _RADIOLIB_AX25_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_AX25) + #include "../PhysicalLayer/PhysicalLayer.h" #include "../AFSK/AFSK.h" @@ -320,8 +323,6 @@ class AX25Client { PhysicalLayer* _phy; #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; - #else - void* _audio; #endif char _srcCallsign[AX25_MAX_CALLSIGN_LEN + 1] = {0, 0, 0, 0, 0, 0, 0}; @@ -334,3 +335,5 @@ class AX25Client { }; #endif + +#endif From dc4c588bae2bffddd4efeea171901a865f8009e8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:18:49 +0200 Subject: [PATCH 268/334] [HTTP] Fixed exclusion macros --- src/protocols/HTTP/HTTP.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/protocols/HTTP/HTTP.h b/src/protocols/HTTP/HTTP.h index ae9a3888..0f30a43e 100644 --- a/src/protocols/HTTP/HTTP.h +++ b/src/protocols/HTTP/HTTP.h @@ -1,9 +1,11 @@ -#if !defined(_RADIOLIB_HTTP_H) && !defined(RADIOLIB_EXCLUDE_HTTP) +#if !defined(_RADIOLIB_HTTP_H) #define _RADIOLIB_HTTP_H #include "../../TypeDef.h" -#include "../TransportLayer/TransportLayer.h" +#if !defined(RADIOLIB_EXCLUDE_HTTP) + +#include "../TransportLayer/TransportLayer.h" /*! \class HTTPClient @@ -67,3 +69,5 @@ class HTTPClient { }; #endif + +#endif From e23f095585b4cac746f15d515f93ee36ac1b92ca Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:19:00 +0200 Subject: [PATCH 269/334] [Hell] Fixed exclusion macros --- src/protocols/Hellschreiber/Hellschreiber.cpp | 15 +++++++++++---- src/protocols/Hellschreiber/Hellschreiber.h | 9 ++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/protocols/Hellschreiber/Hellschreiber.cpp b/src/protocols/Hellschreiber/Hellschreiber.cpp index d2355480..3a7bb6fc 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.cpp +++ b/src/protocols/Hellschreiber/Hellschreiber.cpp @@ -3,7 +3,10 @@ HellClient::HellClient(PhysicalLayer* phy) { _phy = phy; + + #if !defined(RADIOLIB_EXCLUDE_AFSK) _audio = nullptr; + #endif } #if !defined(RADIOLIB_EXCLUDE_AFSK) @@ -23,9 +26,11 @@ int16_t HellClient::begin(float base, float rate) { // set module frequency deviation to 0 if using FSK int16_t state = ERR_NONE; + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio == nullptr) { state = _phy->setFrequencyDeviation(0); } + #endif return(state); } @@ -285,19 +290,21 @@ size_t HellClient::printFloat(double number, uint8_t digits) { } int16_t HellClient::transmitDirect(uint32_t freq, uint32_t freqHz) { + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio != nullptr) { return(_audio->tone(freqHz)); - } else { - return(_phy->transmitDirect(freq)); } + #endif + return(_phy->transmitDirect(freq)); } int16_t HellClient::standby() { + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio != nullptr) { return(_audio->noTone()); - } else { - return(_phy->standby()); } + #endif + return(_phy->standby()); } #endif diff --git a/src/protocols/Hellschreiber/Hellschreiber.h b/src/protocols/Hellschreiber/Hellschreiber.h index 1f8087e1..bfe20473 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.h +++ b/src/protocols/Hellschreiber/Hellschreiber.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_HELLSCHREIBER_H) && !defined(RADIOLIB_EXCLUDE_HELLSCHREIBER) +#if !defined(_RADIOLIB_HELLSCHREIBER_H) #define _RADIOLIB_HELLSCHREIBER_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_HELLSCHREIBER) + #include "../PhysicalLayer/PhysicalLayer.h" #include "../AFSK/AFSK.h" @@ -152,8 +155,6 @@ class HellClient { PhysicalLayer* _phy; #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; - #else - void* _audio; #endif uint32_t _base = 0, _baseHz = 0; @@ -167,3 +168,5 @@ class HellClient { }; #endif + +#endif From 55845fe3d7f68e302758a451615fee79a88b560a Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:19:10 +0200 Subject: [PATCH 270/334] [MQTT] Fixed exclusion macros --- src/protocols/MQTT/MQTT.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/protocols/MQTT/MQTT.h b/src/protocols/MQTT/MQTT.h index e6b0adbe..87b8444d 100644 --- a/src/protocols/MQTT/MQTT.h +++ b/src/protocols/MQTT/MQTT.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_MQTT_H) && !defined(RADIOLIB_EXCLUDE_MQTT) +#if !defined(_RADIOLIB_MQTT_H) #define _RADIOLIB_MQTT_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_MQTT) + #include "../TransportLayer/TransportLayer.h" // MQTT packet types @@ -140,3 +143,5 @@ class MQTTClient { }; #endif + +#endif From 27471fd788d41499dbd636985095802601ce2d57 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:19:16 +0200 Subject: [PATCH 271/334] [Morse] Fixed exclusion macros --- src/protocols/Morse/Morse.cpp | 14 ++++++++++---- src/protocols/Morse/Morse.h | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/protocols/Morse/Morse.cpp b/src/protocols/Morse/Morse.cpp index bd336229..80a44d46 100644 --- a/src/protocols/Morse/Morse.cpp +++ b/src/protocols/Morse/Morse.cpp @@ -3,7 +3,9 @@ MorseClient::MorseClient(PhysicalLayer* phy) { _phy = phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) _audio = nullptr; + #endif } #if !defined(RADIOLIB_EXCLUDE_AFSK) @@ -23,9 +25,11 @@ int16_t MorseClient::begin(float base, uint8_t speed) { // set module frequency deviation to 0 if using FSK int16_t state = ERR_NONE; + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio == nullptr) { state = _phy->setFrequencyDeviation(0); } + #endif return(state); } @@ -298,19 +302,21 @@ size_t MorseClient::printFloat(double number, uint8_t digits) { } int16_t MorseClient::transmitDirect(uint32_t freq, uint32_t freqHz) { + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio != nullptr) { return(_audio->tone(freqHz)); - } else { - return(_phy->transmitDirect(freq)); } + #endif + return(_phy->transmitDirect(freq)); } int16_t MorseClient::standby() { + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio != nullptr) { return(_audio->noTone()); - } else { - return(_phy->standby()); } + #endif + return(_phy->standby()); } #endif diff --git a/src/protocols/Morse/Morse.h b/src/protocols/Morse/Morse.h index c7bcce52..d94fad0d 100644 --- a/src/protocols/Morse/Morse.h +++ b/src/protocols/Morse/Morse.h @@ -157,8 +157,6 @@ class MorseClient { PhysicalLayer* _phy; #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; - #else - void* _audio; #endif uint32_t _base = 0, _baseHz = 0; From dabac56cc45c5a7e3727bcc4b7a4db29b1a4cb31 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:19:23 +0200 Subject: [PATCH 272/334] [RTTY] Fixed exclusion macros --- src/protocols/RTTY/RTTY.cpp | 14 ++++++++++---- src/protocols/RTTY/RTTY.h | 9 ++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index ccd166cf..657f55f1 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -107,7 +107,9 @@ uint16_t ITA2String::getBits(char c) { RTTYClient::RTTYClient(PhysicalLayer* phy) { _phy = phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) _audio = nullptr; + #endif } #if !defined(RADIOLIB_EXCLUDE_AFSK) @@ -161,9 +163,11 @@ int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t enc // set module frequency deviation to 0 if using FSK int16_t state = ERR_NONE; + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio == nullptr) { state = _phy->setFrequencyDeviation(0); } + #endif return(state); } @@ -520,19 +524,21 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) { } int16_t RTTYClient::transmitDirect(uint32_t freq, uint32_t freqHz) { + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio != nullptr) { return(_audio->tone(freqHz)); - } else { - return(_phy->transmitDirect(freq)); } + #endif + return(_phy->transmitDirect(freq)); } int16_t RTTYClient::standby() { + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio != nullptr) { return(_audio->noTone()); - } else { - return(_phy->standby()); } + #endif + return(_phy->standby()); } #endif diff --git a/src/protocols/RTTY/RTTY.h b/src/protocols/RTTY/RTTY.h index a7bfbf73..baf89fe1 100644 --- a/src/protocols/RTTY/RTTY.h +++ b/src/protocols/RTTY/RTTY.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_RTTY_H) && !defined(RADIOLIB_EXCLUDE_RTTY) +#if !defined(_RADIOLIB_RTTY_H) #define _RADIOLIB_RTTY_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_RTTY) + #include "../PhysicalLayer/PhysicalLayer.h" #include "../AFSK/AFSK.h" @@ -159,8 +162,6 @@ class RTTYClient { PhysicalLayer* _phy; #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; - #else - void* _audio; #endif uint8_t _encoding = ASCII; @@ -181,3 +182,5 @@ class RTTYClient { }; #endif + +#endif From a5db0c02bf2d3c9d4bde534a17b877b805f46a67 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:19:30 +0200 Subject: [PATCH 273/334] [SSTV] Fixed exclusion macros --- src/protocols/SSTV/SSTV.cpp | 10 ++++++++++ src/protocols/SSTV/SSTV.h | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/protocols/SSTV/SSTV.cpp b/src/protocols/SSTV/SSTV.cpp index 6e658a25..9fc9fd3e 100644 --- a/src/protocols/SSTV/SSTV.cpp +++ b/src/protocols/SSTV/SSTV.cpp @@ -156,7 +156,9 @@ const SSTVMode_t PasokonP7 { SSTVClient::SSTVClient(PhysicalLayer* phy) { _phy = phy; + #if !defined(RADIOLIB_EXCLUDE_AFSK) _audio = nullptr; + #endif } #if !defined(RADIOLIB_EXCLUDE_AFSK) @@ -166,6 +168,7 @@ SSTVClient::SSTVClient(AFSKClient* audio) { } #endif +#if !defined(RADIOLIB_EXCLUDE_AFSK) int16_t SSTVClient::begin(const SSTVMode_t& mode, float correction) { if(_audio == nullptr) { // this initialization method can only be used in AFSK mode @@ -174,6 +177,7 @@ int16_t SSTVClient::begin(const SSTVMode_t& mode, float correction) { return(begin(0, mode, correction)); } +#endif int16_t SSTVClient::begin(float base, const SSTVMode_t& mode, float correction) { // save mode @@ -190,9 +194,11 @@ int16_t SSTVClient::begin(float base, const SSTVMode_t& mode, float correction) // set module frequency deviation to 0 if using FSK int16_t state = ERR_NONE; + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio == nullptr) { state = _phy->setFrequencyDeviation(0); } + #endif return(state); } @@ -284,11 +290,15 @@ uint16_t SSTVClient::getPictureHeight() const { void SSTVClient::tone(float freq, uint32_t len) { uint32_t start = micros(); + #if !defined(RADIOLIB_EXCLUDE_AFSK) if(_audio != nullptr) { _audio->tone(freq, false); } else { _phy->transmitDirect(_base + (freq / _phy->getFreqStep())); } + #else + _phy->transmitDirect(_base + (freq / _phy->getFreqStep())); + #endif while(micros() - start < len) { yield(); } diff --git a/src/protocols/SSTV/SSTV.h b/src/protocols/SSTV/SSTV.h index fd827b6a..fb8fc27a 100644 --- a/src/protocols/SSTV/SSTV.h +++ b/src/protocols/SSTV/SSTV.h @@ -1,7 +1,10 @@ -#if !defined(_RADIOLIB_SSTV_H) && !defined(RADIOLIB_EXCLUDE_SSTV) +#if !defined(_RADIOLIB_SSTV_H) #define _RADIOLIB_SSTV_H #include "../../TypeDef.h" + +#if !defined(RADIOLIB_EXCLUDE_SSTV) + #include "../PhysicalLayer/PhysicalLayer.h" #include "../AFSK/AFSK.h" @@ -147,6 +150,7 @@ class SSTVClient { */ int16_t begin(float base, const SSTVMode_t& mode, float correction = 1.0); + #if !defined(RADIOLIB_EXCLUDE_AFSK) /*! \brief Initialization method for AFSK. @@ -157,6 +161,7 @@ class SSTVClient { \returns \ref status_codes */ int16_t begin(const SSTVMode_t& mode, float correction = 1.0); + #endif /*! \brief Sends out tone at 1900 Hz. @@ -188,8 +193,6 @@ class SSTVClient { PhysicalLayer* _phy; #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; - #else - void* _audio; #endif uint32_t _base = 0; @@ -200,3 +203,5 @@ class SSTVClient { }; #endif + +#endif From f896765405abe5946ba073b58fef568ae84f0782 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:20:33 +0200 Subject: [PATCH 274/334] Added complete list of supported exclusion macros (TRAVIS_FORCE_BUILD) --- src/BuildOpt.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 0366a125..6c35a902 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -51,9 +51,33 @@ // the following must be defined if the Arduino core does not support tone function //#define RADIOLIB_TONE_UNSUPPORTED - // some of RadioLib drivers may be excluded, to prevent collisions with platform (or to speed up build process) - // for example, to exclude ESP8266 driver: + // some of RadioLib drivers may be excluded, to prevent collisions with platforms (or to speed up build process) + // the following is a complete list of all possible exclusion macros, uncomment any of them to disable that driver + // NOTE: Some of the exclusion macros are dependent on each other. For example, it is not possible to exclude RF69 + // while keeping SX1231 (because RF69 is the base class for SX1231). The dependeny is always uni-directional, + // so excluding SX1231 and keeping RF69 is valid. + //#define RADIOLIB_EXCLUDE_CC1101 //#define RADIOLIB_EXCLUDE_ESP8266 + //#define RADIOLIB_EXCLUDE_HC05 + //#define RADIOLIB_EXCLUDE_JDY08 + //#define RADIOLIB_EXCLUDE_NRF24 + //#define RADIOLIB_EXCLUDE_RF69 + //#define RADIOLIB_EXCLUDE_SX1231 // dependent on RADIOLIB_EXCLUDE_RF69 + //#define RADIOLIB_EXCLUDE_SI443X + //#define RADIOLIB_EXCLUDE_RFM2X // dependent on RADIOLIB_EXCLUDE_SI443X + //#define RADIOLIB_EXCLUDE_SX127X + //#define RADIOLIB_EXCLUDE_RFM9X // dependent on RADIOLIB_EXCLUDE_SX127X + //#define RADIOLIB_EXCLUDE_SX126X + //#define RADIOLIB_EXCLUDE_SX128X + //#define RADIOLIB_EXCLUDE_XBEE + #define RADIOLIB_EXCLUDE_AFSK + //#define RADIOLIB_EXCLUDE_AX25 + //#define RADIOLIB_EXCLUDE_HELLSCHREIBER + //#define RADIOLIB_EXCLUDE_HTTP + //#define RADIOLIB_EXCLUDE_MORSE + //#define RADIOLIB_EXCLUDE_MQTT + //#define RADIOLIB_EXCLUDE_RTTY + //#define RADIOLIB_EXCLUDE_SSTV #else #if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)) From f3fd516a85ac80cf08e2a86b1f4a7b46cf9bba5e Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:24:43 +0200 Subject: [PATCH 275/334] Fixed AFSK excluded by default --- src/BuildOpt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 6c35a902..128450e6 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -70,7 +70,7 @@ //#define RADIOLIB_EXCLUDE_SX126X //#define RADIOLIB_EXCLUDE_SX128X //#define RADIOLIB_EXCLUDE_XBEE - #define RADIOLIB_EXCLUDE_AFSK + //#define RADIOLIB_EXCLUDE_AFSK //#define RADIOLIB_EXCLUDE_AX25 //#define RADIOLIB_EXCLUDE_HELLSCHREIBER //#define RADIOLIB_EXCLUDE_HTTP From eeb70e24bd594f1878a0e7daac3c84827c7968c1 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 4 Jul 2020 21:26:23 +0200 Subject: [PATCH 276/334] Fixed typo (TRAVIS_FORCE_BUILD) --- src/BuildOpt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 128450e6..dfbaf26d 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -54,7 +54,7 @@ // some of RadioLib drivers may be excluded, to prevent collisions with platforms (or to speed up build process) // the following is a complete list of all possible exclusion macros, uncomment any of them to disable that driver // NOTE: Some of the exclusion macros are dependent on each other. For example, it is not possible to exclude RF69 - // while keeping SX1231 (because RF69 is the base class for SX1231). The dependeny is always uni-directional, + // while keeping SX1231 (because RF69 is the base class for SX1231). The dependency is always uni-directional, // so excluding SX1231 and keeping RF69 is valid. //#define RADIOLIB_EXCLUDE_CC1101 //#define RADIOLIB_EXCLUDE_ESP8266 From 0dd3e347a0e19a25a215f26eae0b597bc574f7f8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 09:59:40 +0200 Subject: [PATCH 277/334] [MQTT] Implemented remaining length decoding --- src/protocols/MQTT/MQTT.cpp | 12 +++++++----- src/protocols/MQTT/MQTT.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/protocols/MQTT/MQTT.cpp b/src/protocols/MQTT/MQTT.cpp index cb62321c..fb4791f7 100644 --- a/src/protocols/MQTT/MQTT.cpp +++ b/src/protocols/MQTT/MQTT.cpp @@ -411,10 +411,11 @@ int16_t MQTTClient::check(void (*func)(const char*, const char*)) { _tl->receive(dataIn, numBytes); if(dataIn[0] == MQTT_PUBLISH << 4) { // TODO: properly decode remaining length - uint8_t remainingLength = dataIn[1]; + uint8_t remLenFieldLen = 0; + uint32_t remainingLength = decodeLength(dataIn + 1, remLenFieldLen); // get the topic - size_t topicLength = dataIn[3] | dataIn[2] << 8; + size_t topicLength = dataIn[remLenFieldLen + 2] | dataIn[remLenFieldLen + 1] << 8; char* topic = new char[topicLength + 1]; memcpy(topic, dataIn + 4, topicLength); topic[topicLength] = 0x00; @@ -422,7 +423,7 @@ int16_t MQTTClient::check(void (*func)(const char*, const char*)) { // get the message size_t messageLength = remainingLength - topicLength - 2; char* message = new char[messageLength + 1]; - memcpy(message, dataIn + 4 + topicLength, messageLength); + memcpy(message, dataIn + remLenFieldLen + 3 + topicLength, messageLength); message[messageLength] = 0x00; // execute the callback function provided by user @@ -452,7 +453,7 @@ size_t MQTTClient::encodeLength(uint32_t len, uint8_t* encoded) { return(i); } -uint32_t MQTTClient::decodeLength(uint8_t* encoded) { +uint32_t MQTTClient::decodeLength(uint8_t* encoded, uint8_t& numBytes) { // algorithm to decode packet length as per MQTT specification 3.1.1 uint32_t mult = 1; uint32_t len = 0; @@ -464,7 +465,8 @@ uint32_t MQTTClient::decodeLength(uint8_t* encoded) { // malformed remaining length return(0); } - } while((encoded[i] & 128) != 0); + } while((encoded[i++] & 128) != 0); + numBytes = i; return len; } diff --git a/src/protocols/MQTT/MQTT.h b/src/protocols/MQTT/MQTT.h index 87b8444d..6f21f585 100644 --- a/src/protocols/MQTT/MQTT.h +++ b/src/protocols/MQTT/MQTT.h @@ -139,7 +139,7 @@ class MQTTClient { uint16_t _packetId; static size_t encodeLength(uint32_t len, uint8_t* encoded); - static uint32_t decodeLength(uint8_t* encoded); + static uint32_t decodeLength(uint8_t* encoded, uint8_t& numBytes); }; #endif From fa8d00a7362dc75dd1ea25d66d70d07f20d56431 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:00:04 +0200 Subject: [PATCH 278/334] [ESP8266] Fixed variable scope --- src/modules/ESP8266/ESP8266.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index c7e23b00..c07a96e8 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -7,7 +7,8 @@ ESP8266::ESP8266(Module* module) { int16_t ESP8266::begin(long speed) { // set module properties - _mod->AtLineFeed = "\r\n"; + char lf[3] = "\r\n"; + memcpy(_mod->AtLineFeed, lf, strlen(lf)); _mod->baudrate = speed; _mod->init(RADIOLIB_USE_UART); @@ -89,13 +90,13 @@ int16_t ESP8266::openTransportConnection(const char* host, const char* protocol, // build AT command const char* atStr = "AT+CIPSTART=\""; - uint8_t cmdLen = strlen(atStr) + strlen(protocol) + strlen(host) + strlen(portStr) + 5; - if((strcmp(protocol, "TCP") == 0) && (tcpKeepAlive > 0)) { - cmdLen += strlen(tcpKeepAliveStr) + 1; - } #ifdef RADIOLIB_STATIC_ONLY char cmd[RADIOLIB_STATIC_ARRAY_SIZE]; #else + uint8_t cmdLen = strlen(atStr) + strlen(protocol) + strlen(host) + strlen(portStr) + 5; + if((strcmp(protocol, "TCP") == 0) && (tcpKeepAlive > 0)) { + cmdLen += strlen(tcpKeepAliveStr) + 1; + } char* cmd = new char[cmdLen + 1]; #endif strcpy(cmd, atStr); From 12b4fc9e02c7fd9cd815f6a99177b6a471ceec99 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:00:38 +0200 Subject: [PATCH 279/334] Changed line feed data type --- src/Module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module.h b/src/Module.h index 71b372eb..84b398c4 100644 --- a/src/Module.h +++ b/src/Module.h @@ -136,7 +136,7 @@ class Module { /*! \brief Line feed to be used when sending AT commands. Defaults to CR+LF. */ - const char* AtLineFeed = "\r\n"; + char AtLineFeed[3] = "\r\n"; /*! \brief Basic SPI read command. Defaults to 0x00. From 2c6d42f64854600a6f96eb72c47e8e6466bd6b83 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:01:52 +0200 Subject: [PATCH 280/334] [JDY08] Updated line feed assignment --- src/modules/JDY08/JDY08.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/JDY08/JDY08.cpp b/src/modules/JDY08/JDY08.cpp index a94cb37d..0179a142 100644 --- a/src/modules/JDY08/JDY08.cpp +++ b/src/modules/JDY08/JDY08.cpp @@ -7,7 +7,8 @@ JDY08::JDY08(Module* mod) : ISerial(mod) { void JDY08::begin(long speed) { // set module properties - _mod->AtLineFeed = ""; + char lf[3] = ""; + memcpy(_mod->AtLineFeed, lf, strlen(lf)); _mod->baudrate = speed; _mod->init(RADIOLIB_USE_UART); } From 0ee58ff770c15c6108d201d4ec7e8851b050f5d9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:02:11 +0200 Subject: [PATCH 281/334] [XBee] Updated line feed assignment --- src/modules/XBee/XBee.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/XBee/XBee.cpp b/src/modules/XBee/XBee.cpp index d5d4b20c..894c32b3 100644 --- a/src/modules/XBee/XBee.cpp +++ b/src/modules/XBee/XBee.cpp @@ -3,6 +3,7 @@ XBee::XBee(Module* mod) { _mod = mod; + _packetData[0] = '\0'; } int16_t XBee::begin(long speed) { @@ -182,7 +183,8 @@ XBeeSerial::XBeeSerial(Module* mod) : ISerial(mod) { int16_t XBeeSerial::begin(long speed) { // set module properties - _mod->AtLineFeed = "\r"; + char lf[3] = "\r"; + memcpy(_mod->AtLineFeed, lf, strlen(lf)); _mod->baudrate = speed; _mod->init(RADIOLIB_USE_UART); From 047dee5244ae5dd2e45141a75023622b1ac5a8bb Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:02:38 +0200 Subject: [PATCH 282/334] Moved SoftwareSerial only methods to macro guards --- src/ISerial.cpp | 50 +++++++++++++++++++------------------------------ src/ISerial.h | 12 ++++++++---- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/ISerial.cpp b/src/ISerial.cpp index 8cd4c65a..dbfa6a30 100644 --- a/src/ISerial.cpp +++ b/src/ISerial.cpp @@ -8,41 +8,10 @@ void ISerial::begin(long speed) { _mod->ModuleSerial->begin(speed); } -bool ISerial::listen() { -#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - return true; -#else - return(_mod->ModuleSerial->listen()); -#endif -} - void ISerial::end() { _mod->ModuleSerial->end(); } -bool ISerial::isListening() { -#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - return true; -#else - return(_mod->ModuleSerial->isListening()); -#endif -} - -bool ISerial::stopListening() { -#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - return true; -#else - return(_mod->ModuleSerial->stopListening()); -#endif -} - -bool ISerial::overflow() { -#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - return false; -#else - return(_mod->ModuleSerial->overflow()); -#endif -} int ISerial::peek() { return(_mod->ModuleSerial->peek()); @@ -64,6 +33,25 @@ void ISerial::flush() { _mod->ModuleSerial->flush(); } +// SoftwareSerial-only methods +#if !defined(RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED) +bool ISerial::listen() { + return(_mod->ModuleSerial->listen()); +} + +bool ISerial::isListening() { + return(_mod->ModuleSerial->isListening()); +} + +bool ISerial::stopListening() { + return(_mod->ModuleSerial->stopListening()); +} + +bool ISerial::overflow() { + return(_mod->ModuleSerial->overflow()); +} +#endif + size_t ISerial::print(const __FlashStringHelper *ifsh) { return(_mod->ModuleSerial->print(ifsh)); } diff --git a/src/ISerial.h b/src/ISerial.h index c8ecacbe..34064934 100644 --- a/src/ISerial.h +++ b/src/ISerial.h @@ -18,17 +18,21 @@ class ISerial { explicit ISerial(Module* mod); void begin(long); - bool listen(); void end(); - bool isListening(); - bool stopListening(); - bool overflow(); int peek(); size_t write(uint8_t); int read(); int available(); void flush(); + // SoftwareSerial-only methods + #if !defined(RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED) + bool listen(); + bool isListening(); + bool stopListening(); + bool overflow(); + #endif + size_t print(const __FlashStringHelper *); size_t print(const String &); size_t print(const char[]); From 1534aab9105185cf751b065f31b97d500746261f Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:03:43 +0200 Subject: [PATCH 283/334] [Si443x] Removed redundant variable assingment --- src/modules/Si443x/Si443x.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 94ca8446..301ea4ac 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -630,7 +630,6 @@ int16_t Si443x::updateClockRecovery() { } if((rxOsr_temp - rxOsr_int) >= 0.125) { rxOsr_dec |= 0x01; - rxOsr_temp -= 0.125; } uint16_t rxOsr_fixed = ((uint16_t)rxOsr_int << 3) | ((uint16_t)rxOsr_dec); From e89e8a053a31924d237b90bf79302a22be1fad20 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:03:57 +0200 Subject: [PATCH 284/334] [AFSK] Using init list --- src/protocols/AFSK/AFSK.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/protocols/AFSK/AFSK.cpp b/src/protocols/AFSK/AFSK.cpp index 6cf64ac9..831a278d 100644 --- a/src/protocols/AFSK/AFSK.cpp +++ b/src/protocols/AFSK/AFSK.cpp @@ -1,9 +1,8 @@ #include "AFSK.h" #if !defined(RADIOLIB_EXCLUDE_AFSK) -AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin) { +AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin): _pin(pin) { _phy = phy; - _pin = pin; } int16_t AFSKClient::tone(uint16_t freq, bool autoStart) { From e1990e460dad528b8b617cccebe2fdefcdb39cba Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:05:46 +0200 Subject: [PATCH 285/334] [AX25] Added copy ctor and assignment operator --- src/protocols/AX25/AX25.cpp | 39 +++++++++++++++++++++++++++++++++++++ src/protocols/AX25/AX25.h | 14 +++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index d5bedc48..7f5c0ef6 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -49,6 +49,10 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src } } +AX25Frame::AX25Frame(const AX25Frame& frame) { + *this = frame; +} + AX25Frame::~AX25Frame() { #ifndef RADIOLIB_STATIC_ONLY // deallocate info field @@ -67,6 +71,41 @@ AX25Frame::~AX25Frame() { #endif } +AX25Frame& AX25Frame::operator=(const AX25Frame& frame) { + // destination callsign/SSID + memcpy(this->destCallsign, frame.destCallsign, strlen(frame.destCallsign)); + this->destCallsign[strlen(frame.destCallsign)] = '\0'; + this->destSSID = frame.destSSID; + + // source callsign/SSID + memcpy(this->srcCallsign, frame.srcCallsign, strlen(frame.srcCallsign)); + this->srcCallsign[strlen(frame.srcCallsign)] = '\0'; + this->srcSSID = frame.srcSSID; + + // repeaters + this->numRepeaters = frame.numRepeaters; + for(uint8_t i = 0; i < this->numRepeaters; i++) { + memcpy(this->repeaterCallsigns[i], frame.repeaterCallsigns[i], strlen(frame.repeaterCallsigns[i])); + } + memcpy(this->repeaterSSIDs, frame.repeaterSSIDs, this->numRepeaters); + + // control field + this->control = frame.control; + + // sequence numbers + this->rcvSeqNumber = frame.rcvSeqNumber; + this->sendSeqNumber = frame.sendSeqNumber; + + // PID field + this->protocolID = frame.protocolID; + + // info field + this->infoLen = frame.infoLen; + memcpy(this->info, frame.info, this->infoLen); + + return(*this); +} + int16_t AX25Frame::setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs, uint8_t numRepeaters) { // check number of repeaters if((numRepeaters < 1) || (numRepeaters > 8)) { diff --git a/src/protocols/AX25/AX25.h b/src/protocols/AX25/AX25.h index 20df8d53..8f005b3f 100644 --- a/src/protocols/AX25/AX25.h +++ b/src/protocols/AX25/AX25.h @@ -224,11 +224,25 @@ class AX25Frame { */ AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control, uint8_t protocolID, uint8_t* info, uint16_t infoLen); + /*! + \brief Copy constructor. + + \param frame AX25Frame instance to copy. + */ + AX25Frame(const AX25Frame& frame); + /*! \brief Default destructor. */ ~AX25Frame(); + /*! + \brief Overload for assignment operator. + + \param frame rvalue AX25Frame. + */ + AX25Frame& operator=(const AX25Frame& frame); + /*! \brief Method to set the repeater callsigns and SSIDs. From b8de06288c0847ce076179235cb3ba5a28ff8baf Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Jul 2020 10:05:54 +0200 Subject: [PATCH 286/334] Added copy ctor and assignment operator --- src/Module.cpp | 23 ++++++++++++++++++++++- src/Module.h | 13 +++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Module.cpp b/src/Module.cpp index ee9d00e3..9e690883 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -89,6 +89,27 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs #endif } +Module::Module(const Module& mod) { + *this = mod; +} + +Module& Module::operator=(const Module& mod) { + this->ModuleSerial = mod.ModuleSerial; + this->baudrate = mod.baudrate; + memcpy(this->AtLineFeed, mod.AtLineFeed, strlen(mod.AtLineFeed)); + this->SPIreadCommand = mod.SPIreadCommand; + this->SPIwriteCommand = mod.SPIwriteCommand; + this->_cs = mod.getCs(); + this->_irq = mod.getIrq(); + this->_rst = mod.getRst(); + this->_rx = mod.getRx(); + this->_tx = mod.getTx(); + this->_spiSettings = mod.getSpiSettings(); + this->_spi = mod.getSpi(); + + return(*this); +} + void Module::init(uint8_t interface) { // select interface switch(interface) { @@ -198,7 +219,7 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t // check register value each millisecond until check interval is reached // some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE) uint32_t start = micros(); - uint8_t readValue = 0; + uint8_t readValue; while(micros() - start < (checkInterval * 1000)) { readValue = SPIreadRegister(reg); if(readValue == newValue) { diff --git a/src/Module.h b/src/Module.h index 84b398c4..cdf9109f 100644 --- a/src/Module.h +++ b/src/Module.h @@ -116,6 +116,19 @@ class Module { Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi = RADIOLIB_DEFAULT_SPI, SPISettings spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial* serial = nullptr); #endif + /*! + \brief Copy constructor. + + \param mod Module instance to copy. + */ + Module(const Module& mod); + + /*! + \brief Overload for assignment operator. + + \param frame rvalue Module. + */ + Module& operator=(const Module& mod); // public member variables From cb191e79732b7cd4cfc8c54d8c863b8ffadba140 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:51:24 +0200 Subject: [PATCH 287/334] Added encoding and data shaping aliases --- src/TypeDef.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/TypeDef.h b/src/TypeDef.h index f8254d3d..aa4c41af 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -88,6 +88,66 @@ \} */ +/*! + \defgroup config_shaping Data shaping filter values aliases. + + \{ +*/ + +/*! + \brief No shaping. +*/ +#define RADIOLIB_SHAPING_NONE 0x00 + +/*! + \brief Gaussin shaping filter, BT = 0.3 +*/ +#define RADIOLIB_SHAPING_0_3 0x01 + +/*! + \brief Gaussin shaping filter, BT = 0.5 +*/ +#define RADIOLIB_SHAPING_0_5 0x02 + +/*! + \brief Gaussin shaping filter, BT = 0.7 +*/ +#define RADIOLIB_SHAPING_0_7 0x03 + +/*! + \brief Gaussin shaping filter, BT = 1.0 +*/ +#define RADIOLIB_SHAPING_1_0 0x04 + +/*! + \} +*/ + +/*! + \defgroup config_encoding Encoding type aliases. + + \{ +*/ + +/*! + \brief Non-return to zero - no encoding. +*/ +#define RADIOLIB_ENCODING_NRZ 0x00 + +/*! + \brief Manchester encoding. +*/ +#define RADIOLIB_ENCODING_MANCHESTER 0x01 + +/*! + \brief Whitening. +*/ +#define RADIOLIB_ENCODING_WHITENING 0x02 + +/*! + \} +*/ + /*! \defgroup status_codes Status Codes From acdd70693daf86a8f2a99cfec1e7c22ecd604d6e Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:52:11 +0200 Subject: [PATCH 288/334] [CC1101] Changed shaping datatype to uint8_t --- src/modules/CC1101/CC1101.cpp | 24 +++++++++++++----------- src/modules/CC1101/CC1101.h | 10 +++++----- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 3d1f50dd..3f186000 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -685,19 +685,21 @@ int16_t CC1101::setPromiscuousMode(bool promiscuous) { return(state); } -int16_t CC1101::setDataShaping(float sh) { +int16_t CC1101::setDataShaping(uint8_t sh) { // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); // set data shaping - sh *= 10.0; - if(abs(sh - 0.0) <= 0.001) { - state = _mod->SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MOD_FORMAT_2_FSK, 6, 4); - } else if(abs(sh - 5.0) <= 0.001) { - state = _mod->SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MOD_FORMAT_GFSK, 6, 4); - } else { - return(ERR_INVALID_DATA_SHAPING); + switch(sh) { + case RADIOLIB_SHAPING_NONE: + state = _mod->SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MOD_FORMAT_2_FSK, 6, 4); + break; + case RADIOLIB_SHAPING_0_5: + state = _mod->SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MOD_FORMAT_GFSK, 6, 4); + break; + default: + return(ERR_INVALID_DATA_SHAPING); } return(state); } @@ -709,15 +711,15 @@ int16_t CC1101::setEncoding(uint8_t encoding) { // set encoding switch(encoding) { - case 0: + case RADIOLIB_ENCODING_NRZ: state = _mod->SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MANCHESTER_EN_OFF, 3, 3); RADIOLIB_ASSERT(state); return(_mod->SPIsetRegValue(CC1101_REG_PKTCTRL0, CC1101_WHITE_DATA_OFF, 6, 6)); - case 1: + case RADIOLIB_ENCODING_MANCHESTER: state = _mod->SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MANCHESTER_EN_ON, 3, 3); RADIOLIB_ASSERT(state); return(_mod->SPIsetRegValue(CC1101_REG_PKTCTRL0, CC1101_WHITE_DATA_OFF, 6, 6)); - case 2: + case RADIOLIB_ENCODING_WHITENING: state = _mod->SPIsetRegValue(CC1101_REG_MDMCFG2, CC1101_MANCHESTER_EN_OFF, 3, 3); RADIOLIB_ASSERT(state); return(_mod->SPIsetRegValue(CC1101_REG_PKTCTRL0, CC1101_WHITE_DATA_ON, 6, 6)); diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index f38b57c6..a442a068 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -847,18 +847,18 @@ class CC1101: public PhysicalLayer { /*! \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. - Allowed value is 0.5. Set to 0 to disable data shaping. + Allowed value is RADIOLIB_SHAPING_0_5. Set to RADIOLIB_SHAPING_NONE to disable data shaping. - \param sh Gaussian shaping bandwidth-time product that will be used for data shaping + \param sh Gaussian shaping bandwidth-time product that will be used for data shaping. \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! - \brief Sets transmission encoding. + \brief Sets transmission encoding. Allowed values are RADIOLIB_ENCODING_NRZ and RADIOLIB_ENCODING_WHITENING. - \param encoding Encoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening. + \param encoding Encoding to be used. \returns \ref status_codes */ From 263410ffb1523b3e1e3bb0511bccf48caa80eb5c Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:52:30 +0200 Subject: [PATCH 289/334] [RF69] Changed shaping datatype to uint8_t --- src/modules/RF69/RF69.cpp | 31 +++++++++++++++---------------- src/modules/RF69/RF69.h | 7 ++++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index ba1548b8..263541a3 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -704,25 +704,24 @@ int16_t RF69::setPromiscuousMode(bool promiscuous) { return(state); } -int16_t RF69::setDataShaping(float sh) { +int16_t RF69::setDataShaping(uint8_t sh) { // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); // set data shaping - sh *= 10.0; - if(abs(sh - 0.0) <= 0.001) { - state = _mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_NO_SHAPING, 1, 0); - } else if(abs(sh - 3.0) <= 0.001) { - state = _mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_FSK_GAUSSIAN_0_3, 1, 0); - } else if(abs(sh - 5.0) <= 0.001) { - state = _mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_FSK_GAUSSIAN_0_5, 1, 0); - } else if(abs(sh - 10.0) <= 0.001) { - state = _mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_FSK_GAUSSIAN_1_0, 1, 0); - } else { - return(ERR_INVALID_DATA_SHAPING); + switch(sh) { + case RADIOLIB_SHAPING_NONE: + return(_mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_NO_SHAPING, 1, 0)); + case RADIOLIB_SHAPING_0_3: + return(_mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_FSK_GAUSSIAN_0_3, 1, 0)); + case RADIOLIB_SHAPING_0_5: + return(_mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_FSK_GAUSSIAN_0_5, 1, 0)); + case RADIOLIB_SHAPING_1_0: + return(_mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_FSK_GAUSSIAN_1_0, 1, 0)); + default: + return(ERR_INVALID_DATA_SHAPING); } - return(state); } int16_t RF69::setEncoding(uint8_t encoding) { @@ -732,11 +731,11 @@ int16_t RF69::setEncoding(uint8_t encoding) { // set encoding switch(encoding) { - case 0: + case RADIOLIB_ENCODING_NRZ: return(_mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_DC_FREE_NONE, 6, 5)); - case 1: + case RADIOLIB_ENCODING_MANCHESTER: return(_mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_DC_FREE_MANCHESTER, 6, 5)); - case 2: + case RADIOLIB_ENCODING_WHITENING: return(_mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_DC_FREE_WHITENING, 6, 5)); default: return(ERR_INVALID_ENCODING); diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 1994980b..a87752f0 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -774,18 +774,19 @@ class RF69: public PhysicalLayer { /*! \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. - Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. + Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Gaussian shaping bandwidth-time product that will be used for data shaping \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets transmission encoding. + Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. - \param encoding Encoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening. + \param encoding Encoding to be used. \returns \ref status_codes */ From 5aff492323444f65eac4fd6ddf2c1fecfc4712f6 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:52:48 +0200 Subject: [PATCH 290/334] [SX126x] Changed shaping datatype to uint8_t --- src/modules/SX126x/SX1262.cpp | 2 +- src/modules/SX126x/SX1262.h | 2 +- src/modules/SX126x/SX1268.cpp | 2 +- src/modules/SX126x/SX1268.h | 4 ++-- src/modules/SX126x/SX126x.cpp | 37 ++++++++++++++++++++--------------- src/modules/SX126x/SX126x.h | 8 +++++--- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 804c88a3..02363bf8 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -23,7 +23,7 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync return(state); } -int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO) { // execute common part int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index 1aa0529f..adb11a93 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -75,7 +75,7 @@ class SX1262: public SX126x { \returns \ref status_codes */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, float dataShaping = 0.5, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); // configuration methods diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index a6ec18ed..bf0b15b0 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -23,7 +23,7 @@ int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync return(state); } -int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO) { // execute common part int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index d7acd5f0..004d74b5 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -69,13 +69,13 @@ class SX1268: public SX126x { \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. - \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. + \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to RADIOLIB_SHAPING_0_5. \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. \returns \ref status_codes */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, float dataShaping = 0.5, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); // configuration methods diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index f459e975..e48828b1 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -75,7 +75,7 @@ int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, float return(state); } -int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -826,26 +826,31 @@ int16_t SX126x::setRxBandwidth(float rxBw) { return(setModulationParamsFSK(_br, _pulseShape, _rxBw, _freqDev)); } -int16_t SX126x::setDataShaping(float sh) { +int16_t SX126x::setDataShaping(uint8_t sh) { // check active modem if(getPacketType() != SX126X_PACKET_TYPE_GFSK) { return(ERR_WRONG_MODEM); } - // check allowed values - sh *= 10.0; - if(abs(sh - 0.0) <= 0.001) { - _pulseShape = SX126X_GFSK_FILTER_NONE; - } else if(abs(sh - 3.0) <= 0.001) { - _pulseShape = SX126X_GFSK_FILTER_GAUSS_0_3; - } else if(abs(sh - 5.0) <= 0.001) { - _pulseShape = SX126X_GFSK_FILTER_GAUSS_0_5; - } else if(abs(sh - 7.0) <= 0.001) { - _pulseShape = SX126X_GFSK_FILTER_GAUSS_0_7; - } else if(abs(sh - 10.0) <= 0.001) { - _pulseShape = SX126X_GFSK_FILTER_GAUSS_1; - } else { - return(ERR_INVALID_DATA_SHAPING); + // set data shaping + switch(sh) { + case RADIOLIB_SHAPING_NONE: + _pulseShape = SX126X_GFSK_FILTER_NONE; + break; + case RADIOLIB_SHAPING_0_3: + _pulseShape = SX126X_GFSK_FILTER_GAUSS_0_3; + break; + case RADIOLIB_SHAPING_0_5: + _pulseShape = SX126X_GFSK_FILTER_GAUSS_0_5; + break; + case RADIOLIB_SHAPING_0_7: + _pulseShape = SX126X_GFSK_FILTER_GAUSS_0_7; + break; + case RADIOLIB_SHAPING_1_0: + _pulseShape = SX126X_GFSK_FILTER_GAUSS_1; + break; + default: + return(ERR_INVALID_DATA_SHAPING); } // update modulation parameters diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 849d8757..c2224e92 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -400,7 +400,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage, bool useRegulatorLDO = false); + int16_t beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO = false); /*! \brief Reset method. Will reset the chip to the default state using RST pin. @@ -653,13 +653,15 @@ class SX126x: public PhysicalLayer { int16_t setRxBandwidth(float rxBw); /*! - \brief Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are 0.3, 0.5, 0.7 and 1.0. Set to 0 to disable shaping. + \brief Sets time-bandwidth product of Gaussian filter applied for shaping. + Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5, RADIOLIB_SHAPING_0_7 or RADIOLIB_SHAPING_1_0. + Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Time-bandwidth product of Gaussian filter to be set. \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets FSK sync word in the form of array of up to 8 bytes. From 7dc7f4d76c01358ed02197b597dbd13175bd6a02 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:53:05 +0200 Subject: [PATCH 291/334] [SX127x] Changed shaping datatype to uint8_t --- src/modules/SX127x/SX1272.cpp | 26 +++++++++++++------------- src/modules/SX127x/SX1272.h | 6 +++--- src/modules/SX127x/SX1278.cpp | 26 +++++++++++++------------- src/modules/SX127x/SX1278.h | 6 +++--- src/modules/SX127x/SX127x.cpp | 6 +++--- src/modules/SX127x/SX127x.h | 3 ++- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 4384fd54..411c3ab3 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -257,7 +257,7 @@ int16_t SX1272::setGain(uint8_t gain) { return(state); } -int16_t SX1272::setDataShaping(float sh) { +int16_t SX1272::setDataShaping(uint8_t sh) { // check active modem if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); @@ -270,21 +270,21 @@ int16_t SX1272::setDataShaping(float sh) { // set mode to standby int16_t state = SX127x::standby(); + RADIOLIB_ASSERT(state); // set data shaping - sh *= 10.0; - if(abs(sh - 0.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_NO_SHAPING, 4, 3); - } else if(abs(sh - 3.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_3, 4, 3); - } else if(abs(sh - 5.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_5, 4, 3); - } else if(abs(sh - 10.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_1_0, 4, 3); - } else { - return(ERR_INVALID_DATA_SHAPING); + switch(sh) { + case RADIOLIB_SHAPING_NONE: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_NO_SHAPING, 4, 3)); + case RADIOLIB_SHAPING_0_3: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_3, 4, 3)); + case RADIOLIB_SHAPING_0_5: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_5, 4, 3)); + case RADIOLIB_SHAPING_1_0: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_1_0, 4, 3)); + default: + return(ERR_INVALID_DATA_SHAPING); } - return(state); } int16_t SX1272::setDataShapingOOK(uint8_t sh) { diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index e47e7fed..6aba8259 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -222,14 +222,14 @@ class SX1272: public SX127x { int16_t setGain(uint8_t gain); /*! - \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. - Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation. + \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. + Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Gaussian shaping bandwidth-time product that will be used for data shaping \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets filter cutoff frequency that will be used for data shaping. diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 8e70be39..ae2933a5 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -329,7 +329,7 @@ int16_t SX1278::setGain(uint8_t gain) { return(state); } -int16_t SX1278::setDataShaping(float sh) { +int16_t SX1278::setDataShaping(uint8_t sh) { // check active modem if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); @@ -342,21 +342,21 @@ int16_t SX1278::setDataShaping(float sh) { // set mode to standby int16_t state = SX127x::standby(); + RADIOLIB_ASSERT(state); // set data shaping - sh *= 10.0; - if(abs(sh - 0.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_NO_SHAPING, 6, 5); - } else if(abs(sh - 3.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_0_3, 6, 5); - } else if(abs(sh - 5.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_0_5, 6, 5); - } else if(abs(sh - 10.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_1_0, 6, 5); - } else { - return(ERR_INVALID_DATA_SHAPING); + switch(sh) { + case RADIOLIB_SHAPING_NONE: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_NO_SHAPING, 6, 5)); + case RADIOLIB_SHAPING_0_3: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_FSK_GAUSSIAN_0_3, 6, 5)); + case RADIOLIB_SHAPING_0_5: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_FSK_GAUSSIAN_0_5, 6, 5)); + case RADIOLIB_SHAPING_1_0: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_FSK_GAUSSIAN_1_0, 6, 5)); + default: + return(ERR_INVALID_DATA_SHAPING); } - return(state); } int16_t SX1278::setDataShapingOOK(uint8_t sh) { diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index c7e5d5b5..5ee20cc8 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -231,14 +231,14 @@ class SX1278: public SX127x { int16_t setGain(uint8_t gain); /*! - \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. - Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation. + \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. + Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Gaussian shaping bandwidth-time product that will be used for data shaping \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets filter cutoff frequency that will be used for data shaping. diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 79c2ab65..9f1f4ad0 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -912,11 +912,11 @@ int16_t SX127x::setEncoding(uint8_t encoding) { // set encoding switch(encoding) { - case 0: + case RADIOLIB_ENCODING_NRZ: return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_NONE, 6, 5)); - case 1: + case RADIOLIB_ENCODING_MANCHESTER: return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_MANCHESTER, 6, 5)); - case 2: + case RADIOLIB_ENCODING_WHITENING: return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_WHITENING, 6, 5)); default: return(ERR_INVALID_ENCODING); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 1a318c33..efc5eb50 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -893,8 +893,9 @@ class SX127x: public PhysicalLayer { /*! \brief Sets transmission encoding. Only available in FSK mode. + Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. - \param encoding Encoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening. + \param encoding Encoding to be used. \returns \ref status_codes */ From be346eb6aa2e02afed8e97f9a15ec381828cdcd9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:53:12 +0200 Subject: [PATCH 292/334] [SX128x] Changed shaping datatype to uint8_t --- src/modules/SX128x/SX128x.cpp | 31 +++++++++++++++++-------------- src/modules/SX128x/SX128x.h | 13 +++++++------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index a5fec200..2bd2c456 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -56,7 +56,7 @@ int16_t SX128x::begin(float freq, float bw, uint8_t sf, uint8_t cr, int8_t power return(state); } -int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, uint16_t preambleLength, float dataShaping) { +int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, uint16_t preambleLength, uint8_t dataShaping) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -115,7 +115,7 @@ int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, return(state); } -int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, float dataShaping) { +int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, uint8_t dataShaping) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -163,7 +163,7 @@ int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, f return(state); } -int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t power, uint16_t preambleLength, float dataShaping) { +int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t power, uint16_t preambleLength, uint8_t dataShaping) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -815,23 +815,26 @@ int16_t SX128x::setFrequencyDeviation(float freqDev) { return(setModulationParams(_br, _modIndex, _shaping)); } -int16_t SX128x::setDataShaping(float dataShaping) { +int16_t SX128x::setDataShaping(uint8_t sh) { // check active modem uint8_t modem = getPacketType(); if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE) || (modem == SX128X_PACKET_TYPE_FLRC))) { return(ERR_WRONG_MODEM); } - // check allowed values - dataShaping *= 10.0; - if(abs(dataShaping - 0.0) <= 0.001) { - _shaping = SX128X_BLE_GFSK_BT_OFF; - } else if(abs(dataShaping - 5.0) <= 0.001) { - _shaping = SX128X_BLE_GFSK_BT_0_5; - } else if(abs(dataShaping - 10.0) <= 0.001) { - _shaping = SX128X_BLE_GFSK_BT_1_0; - } else { - return(ERR_INVALID_DATA_SHAPING); + // set data shaping + switch(sh) { + case RADIOLIB_SHAPING_NONE: + _shaping = SX128X_BLE_GFSK_BT_OFF; + break; + case RADIOLIB_SHAPING_0_5: + _shaping = SX128X_BLE_GFSK_BT_0_5; + break; + case RADIOLIB_SHAPING_1_0: + _shaping = SX128X_BLE_GFSK_BT_1_0; + break; + default: + return(ERR_INVALID_DATA_SHAPING); } // update modulation parameters diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 131e7baf..5c4f3978 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -385,11 +385,11 @@ class SX128x: public PhysicalLayer { \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. - \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. + \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to RADIOLIB_SHAPING_0_5. \returns \ref status_codes */ - int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); + int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5); /*! \brief Initialization method for BLE modem. @@ -406,7 +406,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t beginBLE(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, float dataShaping = 0.5); + int16_t beginBLE(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint8_t dataShaping = RADIOLIB_SHAPING_0_5); /*! \brief Initialization method for FLRC modem. @@ -425,7 +425,7 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ - int16_t beginFLRC(float freq = 2400.0, uint16_t br = 650, uint8_t cr = 3, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); + int16_t beginFLRC(float freq = 2400.0, uint16_t br = 650, uint8_t cr = 3, int8_t power = 10, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5); /*! \brief Reset method. Will reset the chip to the default state using RST pin. @@ -637,13 +637,14 @@ class SX128x: public PhysicalLayer { int16_t setFrequencyDeviation(float freqDev) override; /*! - \brief Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are 0.5 and 1.0. Set to 0 to disable shaping. + \brief Sets time-bandwidth product of Gaussian filter applied for shaping. + Allowed values are RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Time-bandwidth product of Gaussian filter to be set. \returns \ref status_codes */ - int16_t setDataShaping(float dataShaping) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long From 3312645d90d4a2f7b1fd761c0814a9e6ee972151 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:53:20 +0200 Subject: [PATCH 293/334] [Si443x] Changed shaping datatype to uint8_t --- src/modules/Si443x/Si443x.cpp | 26 +++++++++++++++----------- src/modules/Si443x/Si443x.h | 9 +++++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 301ea4ac..78c95b74 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -495,29 +495,33 @@ int16_t Si443x::setEncoding(uint8_t encoding) { // set encoding // TODO - add inverted Manchester? switch(encoding) { - case 0: + case RADIOLIB_ENCODING_NRZ: return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_OFF, 2, 0)); - case 1: + case RADIOLIB_ENCODING_MANCHESTER: return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_ON | SI443X_WHITENING_OFF, 2, 0)); - case 2: + case RADIOLIB_ENCODING_WHITENING: return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_ON, 2, 0)); default: return(ERR_INVALID_ENCODING); } } -int16_t Si443x::setDataShaping(float sh) { +int16_t Si443x::setDataShaping(uint8_t sh) { // set mode to standby int16_t state = standby(); RADIOLIB_ASSERT(state); - if(sh == 0.0) { - // set modulation to FSK - return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_MODULATION_FSK, 1, 0)); - } else { - // set modulation to GFSK - // TODO implement fiter configuration - docs claim this should be possible, but seems undocumented - return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_2, SI443X_MODULATION_GFSK, 1, 0)); + // set data shaping + switch(sh) { + case RADIOLIB_SHAPING_NONE: + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_OFF, 2, 0)); + case RADIOLIB_SHAPING_0_3: + case RADIOLIB_SHAPING_0_5: + case RADIOLIB_SHAPING_1_0: + // TODO implement fiter configuration - docs claim this should be possible, but seems undocumented + return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_ON, 2, 0)); + default: + return(ERR_INVALID_ENCODING); } } diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h index 8e2907a5..6cabb7d4 100644 --- a/src/modules/Si443x/Si443x.h +++ b/src/modules/Si443x/Si443x.h @@ -746,22 +746,23 @@ class Si443x: public PhysicalLayer { /*! \brief Sets transmission encoding. Only available in FSK mode. + Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. - \param encoding Encoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening. + \param encoding Encoding to be used. \returns \ref status_codes */ int16_t setEncoding(uint8_t encoding) override; /*! - \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. - Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation. + \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. + Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Gaussian shaping bandwidth-time product that will be used for data shaping \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. From 92c19da05891853ab9bae70968575585339de944 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:53:29 +0200 Subject: [PATCH 294/334] [nRF24] Changed shaping datatype to uint8_t --- src/modules/nRF24/nRF24.cpp | 2 +- src/modules/nRF24/nRF24.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index e8df4e13..135e75af 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -489,7 +489,7 @@ int16_t nRF24::setAutoAck(uint8_t pipeNum, bool autoAckOn){ } } -int16_t nRF24::setDataShaping(float sh) { +int16_t nRF24::setDataShaping(uint8_t sh) { // nRF24 is unable to set data shaping // this method is implemented only for PhysicalLayer compatibility (void)sh; diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index d41e683f..d1e7a8b3 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -453,7 +453,7 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Dummy encoding configuration method, to ensure PhysicalLayer compatibility. From a437e25968aa05db551ade2166d2419746538e65 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:53:40 +0200 Subject: [PATCH 295/334] [PHY] Changed shaping datatype to uint8_t --- src/protocols/PhysicalLayer/PhysicalLayer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.h b/src/protocols/PhysicalLayer/PhysicalLayer.h index 601c39c6..11bfb490 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.h +++ b/src/protocols/PhysicalLayer/PhysicalLayer.h @@ -193,16 +193,16 @@ class PhysicalLayer { /*! \brief Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class. - \param sh Shaping to be set. Set to zero to disable data shaping. + \param sh Shaping to be set. See \ref config_shaping for possible values. \returns \ref status_codes */ - virtual int16_t setDataShaping(float sh) = 0; + virtual int16_t setDataShaping(uint8_t sh) = 0; /*! \brief Sets FSK data encoding. Only available in FSK mode. Must be implemented in module class. - \param enc Encoding to be used. Set to zero to for no encoding (NRZ). + \param enc Encoding to be used. See \ref config_encoding for possible values. \returns \ref status_codes */ From 58db5d1661c6c7885fbd0ce24816a56a381a2a11 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:13:01 +0200 Subject: [PATCH 296/334] [CC1101] Synced parameters of all FSK modules --- .../CC1101_Settings/CC1101_Settings.ino | 5 +++-- src/modules/CC1101/CC1101.cpp | 22 +++++++++---------- src/modules/CC1101/CC1101.h | 14 ++++++------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino index 4e4bcfd3..e724f7b6 100644 --- a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino +++ b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino @@ -59,8 +59,9 @@ void setup() { // bit rate: 32.0 kbps // frequency deviation: 60.0 kHz // Rx bandwidth: 250.0 kHz - // sync word: 0xD391 - state = radio2.begin(434.0, 32.0, 60.0, 250.0); + // output power: 7 dBm + // preamble length: 32 bits + state = radio2.begin(434.0, 32.0, 60.0, 250.0, 7, 32); if (state == ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 3f186000..9fd98d99 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -77,15 +77,15 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po RADIOLIB_ASSERT(state); // set default data shaping - state = setDataShaping(0); + state = setDataShaping(RADIOLIB_ENCODING_NRZ); RADIOLIB_ASSERT(state); // set default encoding - state = setEncoding(2); + state = setEncoding(RADIOLIB_SHAPING_NONE); RADIOLIB_ASSERT(state); // set default sync word - state = setSyncWord(0xD3, 0x91, 0, false); + state = setSyncWord(0x12, 0xAD, 0, false); RADIOLIB_ASSERT(state); // flush FIFOs @@ -508,28 +508,28 @@ int16_t CC1101::setPreambleLength(uint8_t preambleLength) { // check allowed values uint8_t value; switch(preambleLength){ - case 2: + case 16: value = CC1101_NUM_PREAMBLE_2; break; - case 3: + case 24: value = CC1101_NUM_PREAMBLE_3; break; - case 4: + case 32: value = CC1101_NUM_PREAMBLE_4; break; - case 6: + case 48: value = CC1101_NUM_PREAMBLE_6; break; - case 8: + case 64: value = CC1101_NUM_PREAMBLE_8; break; - case 12: + case 96: value = CC1101_NUM_PREAMBLE_12; break; - case 16: + case 128: value = CC1101_NUM_PREAMBLE_16; break; - case 24: + case 192: value = CC1101_NUM_PREAMBLE_24; break; default: diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index a442a068..70256b63 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -521,21 +521,21 @@ class CC1101: public PhysicalLayer { /*! \brief Initialization method. - \param freq Carrier frequency in MHz. Defaults to 868.0 MHz. + \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. - \param br Bit rate to be used in kbps. Defaults to 4.8 kbps. + \param br Bit rate to be used in kbps. Defaults to 48.0 kbps. \param freqDev Frequency deviation from carrier frequency in kHz Defaults to 48.0 kHz. - \param rxBw Receiver bandwidth in kHz. Defaults to 325.0 kHz. + \param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz. - \param power Output power in dBm. Defaults to 0 dBm. + \param power Output power in dBm. Defaults to 10 dBm. - \param preambleLength Preamble Length in bytes. Defaults to 4 bytes. + \param preambleLength Preamble Length in bits. Defaults to 16 bits. \returns \ref status_codes */ - int16_t begin(float freq = 868.0, float br = 4.8, float freqDev = 48.0, float rxBw = 325.0, int8_t power = 0, uint8_t preambleLength = 4); + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 48.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLength = 16); /*! \brief Blocking binary transmit method. @@ -733,7 +733,7 @@ class CC1101: public PhysicalLayer { /*! \brief Sets preamble length. - \param preambleLength Preamble length to be set (in bytes), allowed values: 2, 3, 4, 6, 8, 12, 16, 24 + \param preambleLength Preamble length to be set (in bits), allowed values: 16, 24, 32, 48, 64, 96, 128 and 192. \returns \ref status_codes */ From 59434cb0251b2cdf3c6fb44ff0cacd4acfebac25 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:13:24 +0200 Subject: [PATCH 297/334] [RF69] Synced parameters of all FSK modules --- examples/RF69/RF69_Settings/RF69_Settings.ino | 3 ++- src/modules/RF69/RF69.cpp | 25 +++++++++++++++---- src/modules/RF69/RF69.h | 15 +++++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/examples/RF69/RF69_Settings/RF69_Settings.ino b/examples/RF69/RF69_Settings/RF69_Settings.ino index 49c23e80..f936ee2e 100644 --- a/examples/RF69/RF69_Settings/RF69_Settings.ino +++ b/examples/RF69/RF69_Settings/RF69_Settings.ino @@ -58,7 +58,8 @@ void setup() { // frequency deviation: 60.0 kHz // Rx bandwidth: 250.0 kHz // output power: 17 dBm - state = radio2.begin(868.0, 300.0, 60.0, 250.0, 17); + // preamble length: 32 bits + state = radio2.begin(868.0, 300.0, 60.0, 250.0, 17, 32); if (state == ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 263541a3..ddffc532 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -5,7 +5,7 @@ RF69::RF69(Module* module) : PhysicalLayer(RF69_FREQUENCY_STEP_SIZE, RF69_MAX_PA _mod = module; } -int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { +int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -71,21 +71,25 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe state = setOutputPower(power); RADIOLIB_ASSERT(state); + // configure default preamble length + state = setPreambleLength(preambleLen); + RADIOLIB_ASSERT(state); + // set default packet length mode state = variablePacketLengthMode(); RADIOLIB_ASSERT(state); - // default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library - uint8_t syncWord[] = {0x2D, 0x01}; + // set default sync word + uint8_t syncWord[] = {0x12, 0xAD}; state = setSyncWord(syncWord, sizeof(syncWord)); RADIOLIB_ASSERT(state); // set default data shaping - state = setDataShaping(0); + state = setDataShaping(RADIOLIB_SHAPING_NONE); RADIOLIB_ASSERT(state); // set default encoding - state = setEncoding(0); + state = setEncoding(RADIOLIB_ENCODING_NRZ); RADIOLIB_ASSERT(state); // set CRC on by default @@ -580,6 +584,17 @@ int16_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) { return(ERR_NONE); } +int16_t RF69::setPreambleLength(uint8_t preambleLen) { + // RF69 configures preamble length in bytes + if(preambleLen % 8 != 0) { + return(ERR_INVALID_PREAMBLE_LENGTH); + } + + uint8_t preLenBytes = preambleLen / 8; + _mod->SPIwriteRegister(RF69_REG_PREAMBLE_MSB, 0x00); + return(_mod->SPIsetRegValue(RF69_REG_PREAMBLE_LSB, preLenBytes)); +} + int16_t RF69::setNodeAddress(uint8_t nodeAddr) { // enable address filtering (node only) int16_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_NODE, 2, 1); diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index a87752f0..63b63513 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -457,11 +457,13 @@ class RF69: public PhysicalLayer { \param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz. - \param power Output power in dBm. Defaults to 13 dBm. + \param power Output power in dBm. Defaults to 10 dBm. + + \param preambleLen Preamble Length in bits. Defaults to 16 bits. \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 13); + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16); /*! \brief Reset method. Will reset the chip to the default state using RST pin. @@ -670,6 +672,15 @@ class RF69: public PhysicalLayer { */ int16_t setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits = 0); + /*! + \brief Sets preamble length. + + \param preambleLen Preamble length to be set (in bits), allowed values: 16, 24, 32, 48, 64, 96, 128 and 192. + + \returns \ref status_codes + */ + int16_t setPreambleLength(uint8_t preambleLen); + /*! \brief Sets node address. Calling this method will also enable address filtering for node address only. From c8f4698a26abafbfe8953ad6ae97a3a40cc310e6 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:13:37 +0200 Subject: [PATCH 298/334] [SX126x] Synced parameters of all FSK modules --- .../SX126x_FSK_Modem/SX126x_FSK_Modem.ino | 2 +- src/modules/SX126x/SX1262.cpp | 4 +- src/modules/SX126x/SX1262.h | 14 +++---- src/modules/SX126x/SX1268.cpp | 4 +- src/modules/SX126x/SX1268.h | 16 ++++--- src/modules/SX126x/SX126x.cpp | 42 ++++++++++--------- src/modules/SX126x/SX126x.h | 6 +-- 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino index 13411fdd..d450f9c6 100644 --- a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino +++ b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino @@ -57,7 +57,7 @@ void setup() { state = radio.setRxBandwidth(250.0); state = radio.setOutputPower(10.0); state = radio.setCurrentLimit(100.0); - state = radio.setDataShaping(1.0); + state = radio.setDataShaping(RADIOLIB_SHAPING_1_0); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; state = radio.setSyncWord(syncWord, 8); diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 02363bf8..70bb7c44 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -23,9 +23,9 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync return(state); } -int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // execute common part - int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping, tcxoVoltage, useRegulatorLDO); + int16_t state = SX126x::beginFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index adb11a93..110b4611 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -40,9 +40,7 @@ class SX1262: public SX126x { \param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x12). - \param power Output power in dBm. Defaults to 14 dBm. - - \param currentLimit Current protection limit in mA. Defaults to 60.0 mA. + \param power Output power in dBm. Defaults to 10 dBm. \param preambleLength LoRa preamble length in symbols.Defaults to 8 symbols. @@ -50,7 +48,7 @@ class SX1262: public SX126x { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. @@ -63,19 +61,19 @@ class SX1262: public SX126x { \param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz. - \param power Output power in dBm. Defaults to 14 dBm. + \param power Output power in dBm. Defaults to 10 dBm. \param currentLimit Current protection limit in mA. Defaults to 60.0 mA. \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. - \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. + \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. + \returns \ref status_codes */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); // configuration methods diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index bf0b15b0..44923333 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -23,9 +23,9 @@ int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync return(state); } -int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength,float tcxoVoltage, bool useRegulatorLDO) { // execute common part - int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping, tcxoVoltage, useRegulatorLDO); + int16_t state = SX126x::beginFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index 004d74b5..8d289c72 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -40,7 +40,7 @@ class SX1268: public SX126x { \param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x12). - \param power Output power in dBm. Defaults to 14 dBm. + \param power Output power in dBm. Defaults to 10 dBm. \param currentLimit Current protection limit in mA. Defaults to 60.0 mA. @@ -50,7 +50,7 @@ class SX1268: public SX126x { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. @@ -59,23 +59,21 @@ class SX1268: public SX126x { \param br FSK bit rate in kbps. Defaults to 48.0 kbps. - \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 50.0 kHz. + \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 50.0 kHz. \param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz. - \param power Output power in dBm. Defaults to 14 dBm. - - \param currentLimit Current protection limit in mA. Defaults to 60.0 mA. + \param power Output power in dBm. Defaults to 10 dBm. \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. - \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to RADIOLIB_SHAPING_0_5. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. + \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. + \returns \ref status_codes */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); // configuration methods diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index e48828b1..3b89bdd7 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -75,7 +75,7 @@ int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, float return(state); } -int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -119,34 +119,38 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit state = setRxBandwidth(rxBw); RADIOLIB_ASSERT(state); - state = setCurrentLimit(currentLimit); - RADIOLIB_ASSERT(state); - - state = setDataShaping(dataShaping); + state = setCurrentLimit(60.0); RADIOLIB_ASSERT(state); state = setPreambleLength(preambleLength); RADIOLIB_ASSERT(state); - // set publicly accessible settings that are not a part of begin method - uint8_t sync[] = {0x2D, 0x01}; - state = setSyncWord(sync, 2); - RADIOLIB_ASSERT(state); - - state = setWhitening(true, 0x01FF); - RADIOLIB_ASSERT(state); - - state = variablePacketLengthMode(SX126X_MAX_PACKET_LENGTH); - RADIOLIB_ASSERT(state); - - state = setDio2AsRfSwitch(false); - RADIOLIB_ASSERT(state); - if(useRegulatorLDO) { state = setRegulatorLDO(); } else { state = setRegulatorDCDC(); } + RADIOLIB_ASSERT(state); + + // set publicly accessible settings that are not a part of begin method + uint8_t sync[] = {0x12, 0xAD}; + state = setSyncWord(sync, 2); + RADIOLIB_ASSERT(state); + + state = setDataShaping(RADIOLIB_SHAPING_NONE); + RADIOLIB_ASSERT(state); + + state = setEncoding(RADIOLIB_ENCODING_NRZ); + RADIOLIB_ASSERT(state); + + state = variablePacketLengthMode(SX126X_MAX_PACKET_LENGTH); + RADIOLIB_ASSERT(state); + + state = setCRC(2); + RADIOLIB_ASSERT(state); + + state = setDio2AsRfSwitch(false); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index c2224e92..faf3ae8b 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -388,19 +388,15 @@ class SX126x: public PhysicalLayer { \param rxBw Receiver bandwidth in kHz. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. - \param currentLimit Current protection limit in mA. - \param preambleLength FSK preamble length in bits. Allowed values range from 0 to 65535. - \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Allowed values are 0.3, 0.5, 0.7 and 1.0. Set to 0 to disable shaping. - \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. \param useRegulatorLDO use the LDO instead of DC-DC converter (default false). This is necessary for some modules such as the LAMBDA from RF solutions. \returns \ref status_codes */ - int16_t beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, uint8_t dataShaping, float tcxoVoltage, bool useRegulatorLDO = false); + int16_t beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false); /*! \brief Reset method. Will reset the chip to the default state using RST pin. From 82e4cb7f97d575ff23d4b04007e46d4b6d8dd4cd Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:13:53 +0200 Subject: [PATCH 299/334] [SX127x] Synced parameters of all FSK modules --- examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino | 2 +- src/modules/SX127x/SX1272.cpp | 9 +++++++-- src/modules/SX127x/SX1272.h | 5 +---- src/modules/SX127x/SX1278.cpp | 9 +++++++-- src/modules/SX127x/SX1278.h | 5 +---- src/modules/SX127x/SX127x.cpp | 10 +++++----- src/modules/SX127x/SX127x.h | 4 +--- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino index 184008e8..d6294889 100644 --- a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino +++ b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino @@ -57,7 +57,7 @@ void setup() { state = radio.setRxBandwidth(250.0); state = radio.setOutputPower(10.0); state = radio.setCurrentLimit(100); - state = radio.setDataShaping(0.5); + state = radio.setDataShaping(RADIOLIB_SHAPING_0_5); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; state = radio.setSyncWord(syncWord, 8); diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 411c3ab3..503923e9 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -36,13 +36,14 @@ int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = setGain(gain); + RADIOLIB_ASSERT(state); return(state); } -int16_t SX1272::beginFSK(float freq, float br, float rxBw, float freqDev, int8_t power, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK) { +int16_t SX1272::beginFSK(float freq, float br, float rxBw, float freqDev, int8_t power, uint16_t preambleLength, bool enableOOK) { // execute common part - int16_t state = SX127x::beginFSK(SX1272_CHIP_VERSION, br, rxBw, freqDev, currentLimit, preambleLength, enableOOK); + int16_t state = SX127x::beginFSK(SX1272_CHIP_VERSION, br, rxBw, freqDev, preambleLength, enableOOK); RADIOLIB_ASSERT(state); // configure settings not accessible by API @@ -53,7 +54,11 @@ int16_t SX1272::beginFSK(float freq, float br, float rxBw, float freqDev, int8_t state = setFrequency(freq); RADIOLIB_ASSERT(state); + state = setDataShaping(RADIOLIB_SHAPING_NONE); + RADIOLIB_ASSERT(state); + state = setOutputPower(power); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index 6aba8259..f65539f2 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -148,16 +148,13 @@ class SX1272: public SX127x { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of FSK preamble in bits. \param enableOOK Use OOK modulation instead of FSK. \returns \ref status_codes */ - int16_t beginFSK(float freq = 915.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13, uint8_t currentLimit = 100, uint16_t preambleLength = 16, bool enableOOK = false); + int16_t beginFSK(float freq = 915.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false); /*! \brief Reset method. Will reset the chip to the default state using RST pin. diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index ae2933a5..b4c37576 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -31,13 +31,14 @@ int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = setGain(gain); + RADIOLIB_ASSERT(state); return(state); } -int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK) { +int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { // execute common part - int16_t state = SX127x::beginFSK(SX1278_CHIP_VERSION, br, freqDev, rxBw, currentLimit, preambleLength, enableOOK); + int16_t state = SX127x::beginFSK(SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK); RADIOLIB_ASSERT(state); // configure settings not accessible by API @@ -49,6 +50,10 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t RADIOLIB_ASSERT(state); state = setOutputPower(power); + RADIOLIB_ASSERT(state); + + state = setDataShaping(RADIOLIB_SHAPING_NONE); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index 5ee20cc8..fe136361 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -157,16 +157,13 @@ class SX1278: public SX127x { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of FSK preamble in bits. \param enableOOK Use OOK modulation instead of FSK. \returns \ref status_codes */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 13, uint8_t currentLimit = 100, uint16_t preambleLength = 16, bool enableOOK = false); + int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false); /*! \brief Reset method. Will reset the chip to the default state using RST pin. diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 9f1f4ad0..557035d8 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -49,7 +49,7 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi return(state); } -int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK) { +int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -88,15 +88,15 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB RADIOLIB_ASSERT(state); // set over current protection - state = SX127x::setCurrentLimit(currentLimit); + state = SX127x::setCurrentLimit(60); RADIOLIB_ASSERT(state); // set preamble length state = SX127x::setPreambleLength(preambleLength); RADIOLIB_ASSERT(state); - // default sync word value 0x2D01 is the same as the default in LowPowerLab RFM69 library - uint8_t syncWord[] = {0x2D, 0x01}; + // set default sync word + uint8_t syncWord[] = {0x12, 0xAD}; state = setSyncWord(syncWord, 2); RADIOLIB_ASSERT(state); @@ -109,7 +109,7 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB RADIOLIB_ASSERT(state); // set default encoding - state = setEncoding(0); + state = setEncoding(RADIOLIB_ENCODING_NRZ); RADIOLIB_ASSERT(state); // set default packet length mode diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index efc5eb50..04a28bc5 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -583,15 +583,13 @@ class SX127x: public PhysicalLayer { \param rxBw Receiver bandwidth in kHz. - \param currentLimit Trim value for OCP (over current protection) in mA. - \param preambleLength Length of FSK preamble in bits. \param enableOOK Flag to specify OOK mode. This modulation is similar to FSK. \returns \ref status_codes */ - int16_t beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK); + int16_t beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK); /*! \brief Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem. From ec225236d08fc49c797c095c9ccb79ea0ab6c5d3 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:14:08 +0200 Subject: [PATCH 300/334] [SX1231] Synced parameters of all FSK modules --- src/modules/SX1231/SX1231.cpp | 6 +++++- src/modules/SX1231/SX1231.h | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/SX1231/SX1231.cpp b/src/modules/SX1231/SX1231.cpp index 6122a452..3b4668e9 100644 --- a/src/modules/SX1231/SX1231.cpp +++ b/src/modules/SX1231/SX1231.cpp @@ -5,7 +5,7 @@ SX1231::SX1231(Module* mod) : RF69(mod) { } -int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t power) { +int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t power, uint8_t preambleLen) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -69,6 +69,10 @@ int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po state = setOutputPower(power); RADIOLIB_ASSERT(state); + // configure default preamble length + state = setPreambleLength(preambleLen); + RADIOLIB_ASSERT(state); + // default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library uint8_t syncWord[] = {0x2D, 0x01}; state = setSyncWord(syncWord, 2); diff --git a/src/modules/SX1231/SX1231.h b/src/modules/SX1231/SX1231.h index 9ec08f4c..08cea4d4 100644 --- a/src/modules/SX1231/SX1231.h +++ b/src/modules/SX1231/SX1231.h @@ -43,11 +43,13 @@ class SX1231: public RF69 { \param freqDev Frequency deviation from carrier frequency in kHz Defaults to 50.0 kHz. - \param power Output power in dBm. Defaults to 13 dBm. + \param power Output power in dBm. Defaults to 10 dBm. + + \param preambleLen Preamble Length in bits. Defaults to 16 bits. \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13); + int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 10, uint8_t preambleLen = 16); #ifndef RADIOLIB_GODMODE private: From 4d00170612a7100303eeca46c3832616271339a7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:14:21 +0200 Subject: [PATCH 301/334] [SX128x] Synced parameters of all FSK modules --- examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino | 2 +- src/modules/SX128x/SX128x.cpp | 9 ++++++--- src/modules/SX128x/SX128x.h | 4 +--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino index 4ef75900..2df0d6ac 100644 --- a/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino +++ b/examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino @@ -55,7 +55,7 @@ void setup() { state = radio.setBitRate(200); state = radio.setFrequencyDeviation(100.0); state = radio.setOutputPower(5); - state = radio.setDataShaping(1.0); + state = radio.setDataShaping(RADIOLIB_SHAPING_1_0); uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89}; state = radio.setSyncWord(syncWord, 5); if (state != ERR_NONE) { diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 2bd2c456..48d3b69f 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -56,7 +56,7 @@ int16_t SX128x::begin(float freq, float bw, uint8_t sf, uint8_t cr, int8_t power return(state); } -int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, uint16_t preambleLength, uint8_t dataShaping) { +int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, uint16_t preambleLength) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -104,14 +104,17 @@ int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, state = setPreambleLength(preambleLength); RADIOLIB_ASSERT(state); - state = setDataShaping(dataShaping); + state = setDataShaping(RADIOLIB_SHAPING_0_5); RADIOLIB_ASSERT(state); // set publicly accessible settings that are not a part of begin method - uint8_t sync[] = { 0x2D, 0x01 }; + uint8_t sync[] = { 0x12, 0xAD }; state = setSyncWord(sync, 2); RADIOLIB_ASSERT(state); + state = setEncoding(RADIOLIB_ENCODING_NRZ); + RADIOLIB_ASSERT(state); + return(state); } diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 5c4f3978..bf82c0cc 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -385,11 +385,9 @@ class SX128x: public PhysicalLayer { \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. - \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to RADIOLIB_SHAPING_0_5. - \returns \ref status_codes */ - int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5); + int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16); /*! \brief Initialization method for BLE modem. From 868235788197aa81bcfafb019c3581417556d55a Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:14:33 +0200 Subject: [PATCH 302/334] [Si443x] Synced parameters of all FSK modules --- .../Si443x_Settings/Si443x_Settings.ino | 3 ++- src/modules/Si443x/Si4430.cpp | 4 ++-- src/modules/Si443x/Si4430.h | 4 +++- src/modules/Si443x/Si4431.cpp | 4 ++-- src/modules/Si443x/Si4431.h | 4 +++- src/modules/Si443x/Si4432.cpp | 4 ++-- src/modules/Si443x/Si4432.h | 4 +++- src/modules/Si443x/Si443x.cpp | 23 +++++++++++++++++-- src/modules/Si443x/Si443x.h | 13 ++++++++++- 9 files changed, 50 insertions(+), 13 deletions(-) diff --git a/examples/Si443x/Si443x_Settings/Si443x_Settings.ino b/examples/Si443x/Si443x_Settings/Si443x_Settings.ino index ee5f7e9b..cd420505 100644 --- a/examples/Si443x/Si443x_Settings/Si443x_Settings.ino +++ b/examples/Si443x/Si443x_Settings/Si443x_Settings.ino @@ -58,7 +58,8 @@ void setup() { // frequency deviation: 60.0 kHz // Rx bandwidth: 335.5 kHz // output power: 17 dBm - state = radio2.begin(868.0, 200.0, 60.0, 335.5, 17); + // preamble length: 32 bits + state = radio2.begin(868.0, 200.0, 60.0, 335.5, 17, 32); if (state == ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/src/modules/Si443x/Si4430.cpp b/src/modules/Si443x/Si4430.cpp index 3f31370c..778ee9dd 100644 --- a/src/modules/Si443x/Si4430.cpp +++ b/src/modules/Si443x/Si4430.cpp @@ -5,9 +5,9 @@ Si4430::Si4430(Module* mod) : Si4432(mod) { } -int16_t Si4430::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { +int16_t Si4430::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { // execute common part - int16_t state = Si443x::begin(br, freqDev, rxBw); + int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/Si443x/Si4430.h b/src/modules/Si443x/Si4430.h index ff3b06f6..ca8a1b8f 100644 --- a/src/modules/Si443x/Si4430.h +++ b/src/modules/Si443x/Si4430.h @@ -40,9 +40,11 @@ class Si4430: public Si4432 { \param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps. + \param preambleLen Preamble Length in bits. Defaults to 16 bits. + \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10); + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16); // configuration methods diff --git a/src/modules/Si443x/Si4431.cpp b/src/modules/Si443x/Si4431.cpp index 54371858..88e43396 100644 --- a/src/modules/Si443x/Si4431.cpp +++ b/src/modules/Si443x/Si4431.cpp @@ -5,9 +5,9 @@ Si4431::Si4431(Module* mod) : Si4432(mod) { } -int16_t Si4431::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { +int16_t Si4431::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { // execute common part - int16_t state = Si443x::begin(br, freqDev, rxBw); + int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/Si443x/Si4431.h b/src/modules/Si443x/Si4431.h index 00167a7d..0143d41b 100644 --- a/src/modules/Si443x/Si4431.h +++ b/src/modules/Si443x/Si4431.h @@ -40,9 +40,11 @@ class Si4431: public Si4432 { \param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps. + \param preambleLen Preamble Length in bits. Defaults to 16 bits. + \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10); + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16); // configuration methods diff --git a/src/modules/Si443x/Si4432.cpp b/src/modules/Si443x/Si4432.cpp index 0c9dee43..8037edcf 100644 --- a/src/modules/Si443x/Si4432.cpp +++ b/src/modules/Si443x/Si4432.cpp @@ -5,9 +5,9 @@ Si4432::Si4432(Module* mod) : Si443x(mod) { } -int16_t Si4432::begin(float freq, float br, float freqDev, float rxBw, int8_t power) { +int16_t Si4432::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { // execute common part - int16_t state = Si443x::begin(br, freqDev, rxBw); + int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/Si443x/Si4432.h b/src/modules/Si443x/Si4432.h index 7537e689..2f785634 100644 --- a/src/modules/Si443x/Si4432.h +++ b/src/modules/Si443x/Si4432.h @@ -40,9 +40,11 @@ class Si4432: public Si443x { \param power Transmission output power in dBm. Allowed values range from -1 to 20 dBm in 3 dBm steps. + \param preambleLen Preamble Length in bits. Defaults to 16 bits. + \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 11); + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16); // configuration methods diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 78c95b74..84534e09 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -5,7 +5,7 @@ Si443x::Si443x(Module* mod) : PhysicalLayer(SI443X_FREQUENCY_STEP_SIZE, SI443X_M _mod = mod; } -int16_t Si443x::begin(float br, float freqDev, float rxBw) { +int16_t Si443x::begin(float br, float freqDev, float rxBw, uint8_t preambleLen) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -38,7 +38,10 @@ int16_t Si443x::begin(float br, float freqDev, float rxBw) { state = setRxBandwidth(rxBw); RADIOLIB_ASSERT(state); - uint8_t syncWord[] = {0x2D, 0x01}; + state = setPreambleLength(preambleLen); + RADIOLIB_ASSERT(state); + + uint8_t syncWord[] = {0x12, 0xAD}; state = setSyncWord(syncWord, sizeof(syncWord)); RADIOLIB_ASSERT(state); @@ -477,6 +480,22 @@ int16_t Si443x::setSyncWord(uint8_t* syncWord, size_t len) { return(state); } +int16_t Si443x::setPreambleLength(uint8_t preambleLen) { + // Si443x configures preamble length in bytes + if(preambleLen % 8 != 0) { + return(ERR_INVALID_PREAMBLE_LENGTH); + } + + // set default preamble length + uint8_t preLenBytes = preambleLen / 8; + int16_t state = _mod->SPIsetRegValue(SI443X_REG_PREAMBLE_LENGTH, preLenBytes); + RADIOLIB_ASSERT(state); + + // set default preamble detection threshold to 50% of preamble length (in units of 4 bits) + uint8_t preThreshold = preambleLen / 4; + return(_mod->SPIsetRegValue(SI443X_REG_PREAMBLE_DET_CONTROL, preThreshold << 4, 3, 7)); +} + size_t Si443x::getPacketLength(bool update) { // TODO variable length mode if(!_packetLengthQueried && update) { diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h index 6cabb7d4..b5ffeb54 100644 --- a/src/modules/Si443x/Si443x.h +++ b/src/modules/Si443x/Si443x.h @@ -579,9 +579,11 @@ class Si443x: public PhysicalLayer { \param rxBw Receiver bandwidth in kHz. + \param preambleLen Preamble Length in bits. + \returns \ref status_codes */ - int16_t begin(float br, float freqDev, float rxBw); + int16_t begin(float br, float freqDev, float rxBw, uint8_t preambleLen); /*! \brief Reset method. Will reset the chip to the default state using SDN pin. @@ -735,6 +737,15 @@ class Si443x: public PhysicalLayer { */ int16_t setSyncWord(uint8_t* syncWord, size_t len); + /*! + \brief Sets preamble length. + + \param preambleLen Preamble length to be set (in bits). + + \returns \ref status_codes + */ + int16_t setPreambleLength(uint8_t preambleLen); + /*! \brief Query modem for the packet length of received payload. From 59c4fe638fa93c87311d0be26463664cf6aa0e26 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:48:02 +0200 Subject: [PATCH 303/334] [RFM9x] Synced parameters of all LoRa modules --- src/modules/RFM9x/RFM95.cpp | 6 +++--- src/modules/RFM9x/RFM95.h | 5 +---- src/modules/RFM9x/RFM96.cpp | 7 ++++--- src/modules/RFM9x/RFM96.h | 5 +---- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp index 80db42a6..f2b4a302 100644 --- a/src/modules/RFM9x/RFM95.cpp +++ b/src/modules/RFM9x/RFM95.cpp @@ -5,12 +5,12 @@ RFM95::RFM95(Module* mod) : SX1278(mod) { } -int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength); if(state == ERR_CHIP_NOT_FOUND) { // SX127X_REG_VERSION might be set 0x12 - state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, currentLimit, preambleLength); + state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength); RADIOLIB_ASSERT(state); } else if(state != ERR_NONE) { // some other error diff --git a/src/modules/RFM9x/RFM95.h b/src/modules/RFM9x/RFM95.h index 8c760630..f6c02840 100644 --- a/src/modules/RFM9x/RFM95.h +++ b/src/modules/RFM9x/RFM95.h @@ -47,9 +47,6 @@ class RFM95: public SX1278 { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535. @@ -58,7 +55,7 @@ class RFM95: public SX1278 { \returns \ref status_codes */ - int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); // configuration methods diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp index 5ca6f594..c2f43f0e 100644 --- a/src/modules/RFM9x/RFM96.cpp +++ b/src/modules/RFM9x/RFM96.cpp @@ -5,12 +5,12 @@ RFM96::RFM96(Module* mod) : SX1278(mod) { } -int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength); if(state == ERR_CHIP_NOT_FOUND) { // SX127X_REG_VERSION might be set 0x12 - state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, currentLimit, preambleLength); + state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength); RADIOLIB_ASSERT(state); } else if(state != ERR_NONE) { // some other error @@ -38,6 +38,7 @@ int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncW RADIOLIB_ASSERT(state); state = setGain(gain); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/RFM9x/RFM96.h b/src/modules/RFM9x/RFM96.h index 9bafe6ea..c18019b2 100644 --- a/src/modules/RFM9x/RFM96.h +++ b/src/modules/RFM9x/RFM96.h @@ -47,9 +47,6 @@ class RFM96: public SX1278 { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535. @@ -58,7 +55,7 @@ class RFM96: public SX1278 { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); // configuration methods From e1141ca64c2f19110eac84f123d89861e98c4650 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:48:14 +0200 Subject: [PATCH 304/334] [SX127x] Synced parameters of all LoRa modules --- examples/SX127x/SX127x_Settings/SX127x_Settings.ino | 3 +-- src/modules/SX127x/SX1272.cpp | 4 ++-- src/modules/SX127x/SX1272.h | 4 +--- src/modules/SX127x/SX1273.cpp | 5 +++-- src/modules/SX127x/SX1273.h | 5 +---- src/modules/SX127x/SX1276.cpp | 5 +++-- src/modules/SX127x/SX1276.h | 5 +---- src/modules/SX127x/SX1277.cpp | 5 +++-- src/modules/SX127x/SX1277.h | 5 +---- src/modules/SX127x/SX1278.cpp | 4 ++-- src/modules/SX127x/SX1278.h | 5 +---- src/modules/SX127x/SX1279.cpp | 5 +++-- src/modules/SX127x/SX1279.h | 5 +---- src/modules/SX127x/SX127x.cpp | 4 ++-- src/modules/SX127x/SX127x.h | 4 +--- 15 files changed, 26 insertions(+), 42 deletions(-) diff --git a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino index 08d1c967..84f31fac 100644 --- a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino +++ b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino @@ -70,10 +70,9 @@ void setup() { // coding rate: 5 // sync word: 0x14 // output power: 2 dBm - // current limit: 50 mA // preamble length: 20 symbols // amplifier gain: 1 (maximum gain) - state = radio2.begin(915.0, 500.0, 6, 5, 0x14, 2); + state = radio2.begin(915.0, 500.0, 6, 5, 0x14, 2, 20, 1); if (state == ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 503923e9..e6219fc2 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -5,9 +5,9 @@ SX1272::SX1272(Module* mod) : SX127x(mod) { } -int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(SX1272_CHIP_VERSION, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(SX1272_CHIP_VERSION, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure settings not accessible by API diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index f65539f2..26a5b84a 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -119,8 +119,6 @@ class SX1272: public SX127x { \param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. - \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. Set to 0 to disable OCP (not recommended). @@ -132,7 +130,7 @@ class SX1272: public SX127x { \returns \ref status_codes */ - int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); /*! \brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module. diff --git a/src/modules/SX127x/SX1273.cpp b/src/modules/SX127x/SX1273.cpp index b45ca0e5..97178f81 100644 --- a/src/modules/SX127x/SX1273.cpp +++ b/src/modules/SX127x/SX1273.cpp @@ -5,9 +5,9 @@ SX1273::SX1273(Module* mod) : SX1272(mod) { } -int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(SX1272_CHIP_VERSION, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(SX1272_CHIP_VERSION, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure settings not accessible by API @@ -36,6 +36,7 @@ int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = setGain(gain); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX127x/SX1273.h b/src/modules/SX127x/SX1273.h index e8b3902b..83b43dd4 100644 --- a/src/modules/SX127x/SX1273.h +++ b/src/modules/SX127x/SX1273.h @@ -41,9 +41,6 @@ class SX1273: public SX1272 { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535. @@ -52,7 +49,7 @@ class SX1273: public SX1272 { \returns \ref status_codes */ - int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); // configuration methods diff --git a/src/modules/SX127x/SX1276.cpp b/src/modules/SX127x/SX1276.cpp index 66510443..b331fe95 100644 --- a/src/modules/SX127x/SX1276.cpp +++ b/src/modules/SX127x/SX1276.cpp @@ -5,9 +5,9 @@ SX1276::SX1276(Module* mod) : SX1278(mod) { } -int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure settings not accessible by API @@ -31,6 +31,7 @@ int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = setGain(gain); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX127x/SX1276.h b/src/modules/SX127x/SX1276.h index cc4ce493..ec6e33d6 100644 --- a/src/modules/SX127x/SX1276.h +++ b/src/modules/SX127x/SX1276.h @@ -41,9 +41,6 @@ class SX1276: public SX1278 { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535. @@ -52,7 +49,7 @@ class SX1276: public SX1278 { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); // configuration methods diff --git a/src/modules/SX127x/SX1277.cpp b/src/modules/SX127x/SX1277.cpp index fe187055..371c125e 100644 --- a/src/modules/SX127x/SX1277.cpp +++ b/src/modules/SX127x/SX1277.cpp @@ -5,9 +5,9 @@ SX1277::SX1277(Module* mod) : SX1278(mod) { } -int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure settings not accessible by API @@ -31,6 +31,7 @@ int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = setGain(gain); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX127x/SX1277.h b/src/modules/SX127x/SX1277.h index 804ee6f9..6598f066 100644 --- a/src/modules/SX127x/SX1277.h +++ b/src/modules/SX127x/SX1277.h @@ -41,9 +41,6 @@ class SX1277: public SX1278 { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535. @@ -52,7 +49,7 @@ class SX1277: public SX1278 { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); // configuration methods diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index b4c37576..2e0566a0 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -5,9 +5,9 @@ SX1278::SX1278(Module* mod) : SX127x(mod) { } -int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure settings not accessible by API diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index fe136361..b25d7be8 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -130,9 +130,6 @@ class SX1278: public SX127x { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535. @@ -141,7 +138,7 @@ class SX1278: public SX127x { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); /*! \brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module. diff --git a/src/modules/SX127x/SX1279.cpp b/src/modules/SX127x/SX1279.cpp index 9d5562e5..21d1f598 100644 --- a/src/modules/SX127x/SX1279.cpp +++ b/src/modules/SX127x/SX1279.cpp @@ -5,9 +5,9 @@ SX1279::SX1279(Module* mod) : SX1278(mod) { } -int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { +int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { // execute common part - int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, currentLimit, preambleLength); + int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); RADIOLIB_ASSERT(state); // configure settings not accessible by API @@ -31,6 +31,7 @@ int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync RADIOLIB_ASSERT(state); state = setGain(gain); + RADIOLIB_ASSERT(state); return(state); } diff --git a/src/modules/SX127x/SX1279.h b/src/modules/SX127x/SX1279.h index c466b64a..27220119 100644 --- a/src/modules/SX127x/SX1279.h +++ b/src/modules/SX127x/SX1279.h @@ -41,9 +41,6 @@ class SX1279: public SX1278 { \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. - Set to 0 to disable OCP (not recommended). - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535. @@ -52,7 +49,7 @@ class SX1279: public SX1278 { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); // configuration methods diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 557035d8..3e464260 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -5,7 +5,7 @@ SX127x::SX127x(Module* mod) : PhysicalLayer(SX127X_FREQUENCY_STEP_SIZE, SX127X_M _mod = mod; } -int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength) { +int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLength) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -36,7 +36,7 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi RADIOLIB_ASSERT(state); // set over current protection - state = SX127x::setCurrentLimit(currentLimit); + state = SX127x::setCurrentLimit(60); RADIOLIB_ASSERT(state); // set preamble length diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 04a28bc5..61953144 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -559,13 +559,11 @@ class SX127x: public PhysicalLayer { \param syncWord %LoRa sync word. - \param currentLimit Trim value for OCP (over current protection) in mA. - \param preambleLength Length of %LoRa transmission preamble in symbols. \returns \ref status_codes */ - int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength); + int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLength); /*! \brief Reset method. Will reset the chip to the default state using RST pin. Declared pure virtual since SX1272 and SX1278 implementations differ. From b21f93342ed1f5c9eef346a48252415c1b4c147b Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:48:25 +0200 Subject: [PATCH 305/334] [SX126x] Synced parameters of all LoRa modules --- examples/SX126x/SX126x_Settings/SX126x_Settings.ino | 3 +-- src/modules/SX126x/SX1262.cpp | 4 ++-- src/modules/SX126x/SX1262.h | 6 ++---- src/modules/SX126x/SX1268.cpp | 4 ++-- src/modules/SX126x/SX1268.h | 4 +--- src/modules/SX126x/SX126x.cpp | 8 ++++---- src/modules/SX126x/SX126x.h | 4 +--- 7 files changed, 13 insertions(+), 20 deletions(-) diff --git a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino index 2e500dee..f485284f 100644 --- a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino +++ b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino @@ -70,9 +70,8 @@ void setup() { // coding rate: 5 // sync word: 0x34 (public network/LoRaWAN) // output power: 2 dBm - // current limit: 50 mA // preamble length: 20 symbols - state = radio2.begin(915.0, 500.0, 6, 5, 0x34, 50, 20); + state = radio2.begin(915.0, 500.0, 6, 5, 0x34, 20); if (state == ERR_NONE) { Serial.println(F("success!")); } else { diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 70bb7c44..b67cf949 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -5,9 +5,9 @@ SX1262::SX1262(Module* mod) : SX126x(mod) { } -int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // execute common part - int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO); + int16_t state = SX126x::begin(bw, sf, cr, syncWord, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index 110b4611..616cd407 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -42,13 +42,13 @@ class SX1262: public SX126x { \param power Output power in dBm. Defaults to 10 dBm. - \param preambleLength LoRa preamble length in symbols.Defaults to 8 symbols. + \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. @@ -63,8 +63,6 @@ class SX1262: public SX126x { \param power Output power in dBm. Defaults to 10 dBm. - \param currentLimit Current protection limit in mA. Defaults to 60.0 mA. - \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index 44923333..673f5853 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -5,9 +5,9 @@ SX1268::SX1268(Module* mod) : SX126x(mod) { } -int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // execute common part - int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO); + int16_t state = SX126x::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); // configure publicly accessible settings diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index 8d289c72..909dd334 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -42,15 +42,13 @@ class SX1268: public SX126x { \param power Output power in dBm. Defaults to 10 dBm. - \param currentLimit Current protection limit in mA. Defaults to 60.0 mA. - \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 3b89bdd7..b5b0d8b9 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -5,7 +5,7 @@ SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_FREQUENCY_STEP_SIZE, SX126X_M _mod = mod; } -int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // set module properties _mod->init(RADIOLIB_USE_SPI); Module::pinMode(_mod->getIrq(), INPUT); @@ -56,13 +56,13 @@ int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, float state = setSyncWord(syncWord); RADIOLIB_ASSERT(state); - state = setCurrentLimit(currentLimit); - RADIOLIB_ASSERT(state); - state = setPreambleLength(preambleLength); RADIOLIB_ASSERT(state); // set publicly accessible settings that are not a part of begin method + state = setCurrentLimit(60.0); + RADIOLIB_ASSERT(state); + state = setDio2AsRfSwitch(true); RADIOLIB_ASSERT(state); diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index faf3ae8b..0461e10b 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -367,8 +367,6 @@ class SX126x: public PhysicalLayer { \param syncWord 1-byte LoRa sync word. - \param currentLimit Current protection limit in mA. - \param preambleLength LoRa preamble length in symbols. Allowed values range from 1 to 65535. \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. @@ -377,7 +375,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false); + int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false); /*! \brief Initialization method for FSK modem. From 2a2efb5413b77c2ae16fa776de6f16967ad83cf0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 11:57:09 +0200 Subject: [PATCH 306/334] Bump version to 4.0.0 --- library.properties | 2 +- src/BuildOpt.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.properties b/library.properties index f2c3def6..b7a8ddfa 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=3.7.0 +version=4.0.0 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/BuildOpt.h b/src/BuildOpt.h index dfbaf26d..66697fac 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -333,8 +333,8 @@ // version definitions -#define RADIOLIB_VERSION_MAJOR (0x03) -#define RADIOLIB_VERSION_MINOR (0x07) +#define RADIOLIB_VERSION_MAJOR (0x04) +#define RADIOLIB_VERSION_MINOR (0x00) #define RADIOLIB_VERSION_PATCH (0x00) #define RADIOLIB_VERSION_EXTRA (0x00) From c9add26cfe998c0dc1a2d6312441e59d92e3d0b0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 12:36:19 +0200 Subject: [PATCH 307/334] Fixed array as initializer (illegal pre-C++11) --- src/Module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module.h b/src/Module.h index cdf9109f..aa12389f 100644 --- a/src/Module.h +++ b/src/Module.h @@ -149,7 +149,7 @@ class Module { /*! \brief Line feed to be used when sending AT commands. Defaults to CR+LF. */ - char AtLineFeed[3] = "\r\n"; + char AtLineFeed[3] = {'\r', '\n'}; /*! \brief Basic SPI read command. Defaults to 0x00. From cdbabdb30db9fd611fdcd6779f0915d48bd781f5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 12:37:29 +0200 Subject: [PATCH 308/334] [SX126x] Fixed unused parameter (TRAVIS_FORCE_BUILD) --- src/modules/SX126x/SX1262.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index b67cf949..a73cebe6 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -7,7 +7,7 @@ SX1262::SX1262(Module* mod) : SX126x(mod) { int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // execute common part - int16_t state = SX126x::begin(bw, sf, cr, syncWord, tcxoVoltage, useRegulatorLDO); + int16_t state = SX126x::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); // configure publicly accessible settings From 9152c5d91d1c915bfb28ef8a2e45ac4fe678b21f Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 15:48:23 +0200 Subject: [PATCH 309/334] Travis set Arduino to 1.8.13 and enabled warnings TRAVIS_FORCE_BUILD --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c141bb73..1da28814 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ env: global: - - ARDUINO_IDE_VERSION="1.8.9" + - ARDUINO_IDE_VERSION="1.8.13" matrix: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt @@ -146,7 +146,7 @@ script: else # build sketch echo -e "\n\033[1;33mBuilding ${example##*/} ... \033[0m"; - arduino --verify --board $BOARD $example; + arduino --verify --warnings=all --board $BOARD $example; if [ $? -ne 0 ]; then echo -e "\033[1;31m${example##*/} build FAILED\033[0m\n"; exit 1; From 4e79d7d26af5d3acf7e3ed8c2ed9dab71192bd83 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 16:28:38 +0200 Subject: [PATCH 310/334] Travis switched to Arduino CLI --- .travis.yml | 99 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1da28814..eb85bd00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ env: global: - - ARDUINO_IDE_VERSION="1.8.13" + # - ARDUINO_IDE_VERSION="1.8.13" matrix: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt @@ -30,91 +30,121 @@ addons: - python3-setuptools before_install: - # install Arduino IDE - - wget https://downloads.arduino.cc/arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz - - tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz - - mv arduino-$ARDUINO_IDE_VERSION $HOME/arduino-ide - - export PATH=$PATH:$HOME/arduino-ide - + # install Arduino + # - wget https://downloads.arduino.cc/arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz + # - tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz + # - mv arduino-$ARDUINO_IDE_VERSION $HOME/arduino-ide + # - export PATH=$PATH:$HOME/arduino-ide # firewall Arduino IDE noise (https://github.com/per1234/arduino-ci-script/issues/1#issuecomment-504158113) - - sudo iptables -P INPUT DROP - - sudo iptables -P FORWARD DROP - - sudo iptables -P OUTPUT ACCEPT - - sudo iptables -A INPUT -i lo -j ACCEPT - - sudo iptables -A OUTPUT -o lo -j ACCEPT - - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + # - sudo iptables -P INPUT DROP + # - sudo iptables -P FORWARD DROP + # - sudo iptables -P OUTPUT ACCEPT + # - sudo iptables -A INPUT -i lo -j ACCEPT + # - sudo iptables -A OUTPUT -o lo -j ACCEPT + # - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + + - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh # check every board in matrix and install 3rd party definitions - if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then export BUILD_EXAMPLES=true; + arduino-cli core update-index; elif [[ "$BOARD" =~ "arduino:avr:mega" ]]; then export BUILD_EXAMPLES=false; + arduino-cli core update-index; elif [[ "$BOARD" =~ "arduino:avr:leonardo" ]]; then export BUILD_EXAMPLES=false; + arduino-cli core update-index; elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; - arduino --install-boards esp8266:esp8266; + # arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; + # arduino --install-boards esp8266:esp8266; + arduino-cli core update-index --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json; + arduino-cli core install esp8266:esp8266; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "esp32:esp32:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; - arduino --install-boards esp32:esp32; + # arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; + # arduino --install-boards esp32:esp32; + arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json; + arduino-cli core install esp32:esp32; elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; - arduino --install-boards STM32:stm32; + # arduino --pref "boardsmanager.additional.urls=https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; + # arduino --install-boards STM32:stm32; + arduino-cli core update-index --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json; + arduino-cli core install STM32:stm32; elif [[ "$BOARD" =~ "arduino:samd:" ]]; then export BUILD_EXAMPLES=false; - arduino --install-boards arduino:samd; + arduino-cli core update-index; + # arduino --install-boards arduino:samd; + arduino-cli core install arduino:samd; elif [[ "$BOARD" =~ "arduino:sam:" ]]; then export BUILD_EXAMPLES=false; - arduino --install-boards arduino:sam; + arduino-cli core update-index; + # arduino --install-boards arduino:sam; + arduino-cli core install arduino:sam; elif [[ "$BOARD" =~ "adafruit:nrf52:" ]]; then pip3 install --user adafruit-nrfutil; export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; - arduino --install-boards adafruit:nrf52; + # arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; + # arduino --install-boards adafruit:nrf52; + arduino-cli core update-index --additional-urls https://www.adafruit.com/package_adafruit_index.json; + arduino-cli core install adafruit:nrf52; elif [[ "$BOARD" =~ "Intel:arc32:" ]]; then export BUILD_EXAMPLES=false; - arduino --install-boards Intel:arc32; + arduino-cli core update-index; + # arduino --install-boards Intel:arc32; + arduino-cli core install Intel:arc32; elif [[ "$BOARD" =~ "arduino:megaavr:" ]]; then export BUILD_EXAMPLES=false; - arduino --install-boards arduino:megaavr; + arduino-cli core update-index; + # arduino --install-boards arduino:megaavr; + arduino-cli core install arduino:megaavr; elif [[ "$BOARD" =~ "SparkFun:apollo3:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; - arduino --install-boards SparkFun:apollo3; + # arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; + # arduino --install-boards SparkFun:apollo3; + arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json; + arduino-cli core install SparkFun:apollo3; elif [[ "$BOARD" =~ "arduino:mbed:" ]]; then export BUILD_EXAMPLES=false; - arduino --install-boards arduino:mbed; + arduino-cli core update-index; + # arduino --install-boards arduino:mbed; + arduino-cli core install arduino:mbed; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "stm32duino:STM32F1:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; - arduino --install-boards stm32duino:STM32F1; + # arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; + # arduino --install-boards stm32duino:STM32F1; + arduino-cli core update-index --additional-urls http://dan.drown.org/stm32duino/package_STM32duino_index.json; + arduino-cli core install stm32duino:STM32F1; elif [[ "$BOARD" =~ "adafruit:samd:" ]]; then export BUILD_EXAMPLES=false; - arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; - arduino --install-boards adafruit:samd; + # arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; + # arduino --install-boards adafruit:samd; + arduino-cli core update-index --additional-urls https://www.adafruit.com/package_adafruit_index.json + arduino-cli core install adafruit:samd; elif [[ "$BOARD" =~ "arduino-beta:mbed:" ]]; then export BUILD_EXAMPLES=false; - arduino --install-boards arduino-beta:mbed; + arduino-cli core update-index; + # arduino --install-boards arduino-beta:mbed; + arduino-cli core install arduino-beta:mbed; export SKIP_PAT='(HTTP|MQTT).*ino'; fi @@ -146,7 +176,8 @@ script: else # build sketch echo -e "\n\033[1;33mBuilding ${example##*/} ... \033[0m"; - arduino --verify --warnings=all --board $BOARD $example; + # arduino --verify --warnings=all --board $BOARD $example; + arduino-cli compile --fqbn $BOARD $example --warnings=all if [ $? -ne 0 ]; then echo -e "\033[1;31m${example##*/} build FAILED\033[0m\n"; exit 1; From e0d7398fe924f341978d6653a8bc27ed5db66e2d Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 16:45:18 +0200 Subject: [PATCH 311/334] Travis fix indentation --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index eb85bd00..ad9e03cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,7 +46,8 @@ before_install: - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh # check every board in matrix and install 3rd party definitions - - if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then + - | + if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then export BUILD_EXAMPLES=true; arduino-cli core update-index; @@ -142,8 +143,8 @@ before_install: elif [[ "$BOARD" =~ "arduino-beta:mbed:" ]]; then export BUILD_EXAMPLES=false; - arduino-cli core update-index; # arduino --install-boards arduino-beta:mbed; + arduino-cli core update-index; arduino-cli core install arduino-beta:mbed; export SKIP_PAT='(HTTP|MQTT).*ino'; From f70c403d3f15b00f0e01992bf6efe217f00ec77d Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 16:48:07 +0200 Subject: [PATCH 312/334] Travis fix missing path --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ad9e03cd..65567af4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,7 @@ before_install: # - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh + - export PATH=$PATH:$PWD/bin # check every board in matrix and install 3rd party definitions - | From 362c8a064e848221969c34f07ea325efe185049e Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 16:51:37 +0200 Subject: [PATCH 313/334] Travis added missing platforms --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 65567af4..b630a5e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,14 +51,17 @@ before_install: if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then export BUILD_EXAMPLES=true; arduino-cli core update-index; + arduino-cli core install arduino:avr; elif [[ "$BOARD" =~ "arduino:avr:mega" ]]; then export BUILD_EXAMPLES=false; arduino-cli core update-index; + arduino-cli core install arduino:avr; elif [[ "$BOARD" =~ "arduino:avr:leonardo" ]]; then export BUILD_EXAMPLES=false; arduino-cli core update-index; + arduino-cli core install arduino:avr; elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then export BUILD_EXAMPLES=false; From 422e4ee7b15d9daaa4faca3fb351fb2311ce1e66 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 16:56:21 +0200 Subject: [PATCH 314/334] Travis added missing platform links TRAVIS_FORCE_BUILD --- .travis.yml | 48 ++++++++---------------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index b630a5e5..79b24873 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ env: global: - # - ARDUINO_IDE_VERSION="1.8.13" matrix: # see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options # and https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt @@ -30,19 +29,7 @@ addons: - python3-setuptools before_install: - # install Arduino - # - wget https://downloads.arduino.cc/arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz - # - tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz - # - mv arduino-$ARDUINO_IDE_VERSION $HOME/arduino-ide - # - export PATH=$PATH:$HOME/arduino-ide - # firewall Arduino IDE noise (https://github.com/per1234/arduino-ci-script/issues/1#issuecomment-504158113) - # - sudo iptables -P INPUT DROP - # - sudo iptables -P FORWARD DROP - # - sudo iptables -P OUTPUT ACCEPT - # - sudo iptables -A INPUT -i lo -j ACCEPT - # - sudo iptables -A OUTPUT -o lo -j ACCEPT - # - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - + # install Arduino CLI - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh - export PATH=$PATH:$PWD/bin @@ -65,85 +52,66 @@ before_install: elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then export BUILD_EXAMPLES=false; - # arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1; - # arduino --install-boards esp8266:esp8266; arduino-cli core update-index --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json; - arduino-cli core install esp8266:esp8266; + arduino-cli core install esp8266:esp8266 --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "esp32:esp32:" ]]; then export BUILD_EXAMPLES=false; - # arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs 2>&1; - # arduino --install-boards esp32:esp32; arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json; - arduino-cli core install esp32:esp32; + arduino-cli core install esp32:esp32 --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json; elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then export BUILD_EXAMPLES=false; - # arduino --pref "boardsmanager.additional.urls=https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json" --save-prefs 2>&1; - # arduino --install-boards STM32:stm32; arduino-cli core update-index --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json; - arduino-cli core install STM32:stm32; + arduino-cli core install STM32:stm32 --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json; elif [[ "$BOARD" =~ "arduino:samd:" ]]; then export BUILD_EXAMPLES=false; arduino-cli core update-index; - # arduino --install-boards arduino:samd; arduino-cli core install arduino:samd; elif [[ "$BOARD" =~ "arduino:sam:" ]]; then export BUILD_EXAMPLES=false; arduino-cli core update-index; - # arduino --install-boards arduino:sam; arduino-cli core install arduino:sam; elif [[ "$BOARD" =~ "adafruit:nrf52:" ]]; then pip3 install --user adafruit-nrfutil; export BUILD_EXAMPLES=false; - # arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; - # arduino --install-boards adafruit:nrf52; arduino-cli core update-index --additional-urls https://www.adafruit.com/package_adafruit_index.json; - arduino-cli core install adafruit:nrf52; + arduino-cli core install adafruit:nrf52 --additional-urls https://www.adafruit.com/package_adafruit_index.json; elif [[ "$BOARD" =~ "Intel:arc32:" ]]; then export BUILD_EXAMPLES=false; arduino-cli core update-index; - # arduino --install-boards Intel:arc32; arduino-cli core install Intel:arc32; elif [[ "$BOARD" =~ "arduino:megaavr:" ]]; then export BUILD_EXAMPLES=false; arduino-cli core update-index; - # arduino --install-boards arduino:megaavr; arduino-cli core install arduino:megaavr; elif [[ "$BOARD" =~ "SparkFun:apollo3:" ]]; then export BUILD_EXAMPLES=false; - # arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json" --save-prefs 2>&1; - # arduino --install-boards SparkFun:apollo3; arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json; - arduino-cli core install SparkFun:apollo3; + arduino-cli core install SparkFun:apollo3 --additional-urls https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json; elif [[ "$BOARD" =~ "arduino:mbed:" ]]; then export BUILD_EXAMPLES=false; arduino-cli core update-index; - # arduino --install-boards arduino:mbed; arduino-cli core install arduino:mbed; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "stm32duino:STM32F1:" ]]; then export BUILD_EXAMPLES=false; - # arduino --pref "boardsmanager.additional.urls=http://dan.drown.org/stm32duino/package_STM32duino_index.json" --save-prefs 2>&1; - # arduino --install-boards stm32duino:STM32F1; arduino-cli core update-index --additional-urls http://dan.drown.org/stm32duino/package_STM32duino_index.json; - arduino-cli core install stm32duino:STM32F1; + arduino-cli core install stm32duino:STM32F1 --additional-urls http://dan.drown.org/stm32duino/package_STM32duino_index.json; elif [[ "$BOARD" =~ "adafruit:samd:" ]]; then export BUILD_EXAMPLES=false; - # arduino --pref "boardsmanager.additional.urls=https://www.adafruit.com/package_adafruit_index.json" --save-prefs 2>&1; - # arduino --install-boards adafruit:samd; arduino-cli core update-index --additional-urls https://www.adafruit.com/package_adafruit_index.json - arduino-cli core install adafruit:samd; + arduino-cli core install adafruit:samd --additional-urls https://www.adafruit.com/package_adafruit_index.json elif [[ "$BOARD" =~ "arduino-beta:mbed:" ]]; then export BUILD_EXAMPLES=false; From eabbf9e5afa90be72df239db4ec923b4912d36ee Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 17:16:53 +0200 Subject: [PATCH 315/334] [TL] Changed type to size_t --- src/protocols/TransportLayer/TransportLayer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocols/TransportLayer/TransportLayer.h b/src/protocols/TransportLayer/TransportLayer.h index ecf3ad5b..eb23bd8e 100644 --- a/src/protocols/TransportLayer/TransportLayer.h +++ b/src/protocols/TransportLayer/TransportLayer.h @@ -56,7 +56,7 @@ class TransportLayer { \returns \ref status_codes */ - virtual int16_t send(uint8_t* data, uint32_t len) = 0; + virtual int16_t send(uint8_t* data, size_t len) = 0; /*! \brief Receive data. From 8cbbf3d668ab31c306bb65dd6cb37f58a98abc39 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 17:28:17 +0200 Subject: [PATCH 316/334] [ESP8266] Changed length type to size_t TRAVIS_FORCE_BUILD --- src/modules/ESP8266/ESP8266.cpp | 4 ++-- src/modules/ESP8266/ESP8266.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/ESP8266/ESP8266.cpp b/src/modules/ESP8266/ESP8266.cpp index c07a96e8..98d8c8d5 100644 --- a/src/modules/ESP8266/ESP8266.cpp +++ b/src/modules/ESP8266/ESP8266.cpp @@ -160,10 +160,10 @@ int16_t ESP8266::send(const char* data) { return(ERR_NONE); } -int16_t ESP8266::send(uint8_t* data, uint32_t len) { +int16_t ESP8266::send(uint8_t* data, size_t len) { // build AT command char lenStr[8]; - sprintf(lenStr, "%lu", len); + sprintf(lenStr, "%u", (uint16_t)len); const char atStr[] = "AT+CIPSEND="; #ifdef RADIOLIB_STATIC_ONLY char cmd[RADIOLIB_STATIC_ARRAY_SIZE]; diff --git a/src/modules/ESP8266/ESP8266.h b/src/modules/ESP8266/ESP8266.h index eff7b8b0..cc999500 100644 --- a/src/modules/ESP8266/ESP8266.h +++ b/src/modules/ESP8266/ESP8266.h @@ -51,7 +51,7 @@ class ESP8266: public TransportLayer { int16_t openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive = 0) override; int16_t closeTransportConnection() override; int16_t send(const char* data) override; - int16_t send(uint8_t* data, uint32_t len) override; + int16_t send(uint8_t* data, size_t len) override; size_t receive(uint8_t* data, size_t len, uint32_t timeout = 10000) override; size_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10) override; From 37a94494b4c5ab6a7cde0c85824943618b0011e2 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 18:30:36 +0200 Subject: [PATCH 317/334] Added TODOs --- src/Module.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Module.cpp b/src/Module.cpp index 9e690883..6ce55043 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -336,6 +336,7 @@ RADIOLIB_PIN_STATUS Module::digitalRead(RADIOLIB_PIN_TYPE pin) { } void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) { + // TODO add tone support for platforms without tone() #ifndef RADIOLIB_TONE_UNSUPPORTED if(pin != RADIOLIB_NC) { ::tone(pin, value); @@ -344,6 +345,7 @@ void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) { } void Module::noTone(RADIOLIB_PIN_TYPE pin) { + // TODO add tone support for platforms without noTone() #ifndef RADIOLIB_TONE_UNSUPPORTED if(pin != RADIOLIB_NC) { ::noTone(pin); From a827f91bca156b1196e920fed24304d42cd9e2c3 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 18:31:05 +0200 Subject: [PATCH 318/334] Skipped warnings for SparlFun Apollo --- .travis.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79b24873..39ede145 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,85 +37,100 @@ before_install: - | if [[ "$BOARD" =~ "arduino:avr:uno" ]]; then export BUILD_EXAMPLES=true; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino:avr; elif [[ "$BOARD" =~ "arduino:avr:mega" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino:avr; elif [[ "$BOARD" =~ "arduino:avr:leonardo" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino:avr; elif [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json; arduino-cli core install esp8266:esp8266 --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "esp32:esp32:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json; arduino-cli core install esp32:esp32 --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json; elif [[ "$BOARD" =~ "STM32:stm32:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json; arduino-cli core install STM32:stm32 --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json; elif [[ "$BOARD" =~ "arduino:samd:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino:samd; elif [[ "$BOARD" =~ "arduino:sam:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino:sam; elif [[ "$BOARD" =~ "adafruit:nrf52:" ]]; then pip3 install --user adafruit-nrfutil; export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index --additional-urls https://www.adafruit.com/package_adafruit_index.json; arduino-cli core install adafruit:nrf52 --additional-urls https://www.adafruit.com/package_adafruit_index.json; elif [[ "$BOARD" =~ "Intel:arc32:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install Intel:arc32; elif [[ "$BOARD" =~ "arduino:megaavr:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino:megaavr; elif [[ "$BOARD" =~ "SparkFun:apollo3:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=none; arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json; arduino-cli core install SparkFun:apollo3 --additional-urls https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json; elif [[ "$BOARD" =~ "arduino:mbed:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino:mbed; export SKIP_PAT='(HTTP|MQTT).*ino'; elif [[ "$BOARD" =~ "stm32duino:STM32F1:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index --additional-urls http://dan.drown.org/stm32duino/package_STM32duino_index.json; arduino-cli core install stm32duino:STM32F1 --additional-urls http://dan.drown.org/stm32duino/package_STM32duino_index.json; elif [[ "$BOARD" =~ "adafruit:samd:" ]]; then export BUILD_EXAMPLES=false; + export WARNINGS=all; arduino-cli core update-index --additional-urls https://www.adafruit.com/package_adafruit_index.json arduino-cli core install adafruit:samd --additional-urls https://www.adafruit.com/package_adafruit_index.json elif [[ "$BOARD" =~ "arduino-beta:mbed:" ]]; then export BUILD_EXAMPLES=false; - # arduino --install-boards arduino-beta:mbed; + export WARNINGS=all; arduino-cli core update-index; arduino-cli core install arduino-beta:mbed; export SKIP_PAT='(HTTP|MQTT).*ino'; @@ -149,7 +164,7 @@ script: else # build sketch echo -e "\n\033[1;33mBuilding ${example##*/} ... \033[0m"; - # arduino --verify --warnings=all --board $BOARD $example; + # arduino --verify --warnings=$WARNINGS --board $BOARD $example; arduino-cli compile --fqbn $BOARD $example --warnings=all if [ $? -ne 0 ]; then echo -e "\033[1;31m${example##*/} build FAILED\033[0m\n"; From 93080845d213a17eaa25e48d45cb641b93e672f4 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 19:39:16 +0200 Subject: [PATCH 319/334] Added missing keywords --- keywords.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/keywords.txt b/keywords.txt index f55c7fbf..846709b1 100644 --- a/keywords.txt +++ b/keywords.txt @@ -241,6 +241,16 @@ noTone KEYWORD2 RADIOLIB_NC LITERAL1 RADIOLIB_VERSION LITERAL1 +RADIOLIB_SHAPING_NONE LITERAL1 +RADIOLIB_SHAPING_0_3 LITERAL1 +RADIOLIB_SHAPING_0_5 LITERAL1 +RADIOLIB_SHAPING_0_7 LITERAL1 +RADIOLIB_SHAPING_1_0 LITERAL1 + +RADIOLIB_ENCODING_NRZ LITERAL1 +RADIOLIB_ENCODING_MANCHESTER LITERAL1 +RADIOLIB_ENCODING_WHITENING LITERAL1 + ERR_NONE LITERAL1 ERR_UNKNOWN LITERAL1 From 760fefaad8794ef893aa1aa9bdd33d68f940ad37 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 8 Jul 2020 18:00:09 +0200 Subject: [PATCH 320/334] [CC1101] Fixed invalid default Rx bandwidth --- src/modules/CC1101/CC1101.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index 70256b63..d2284aa2 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -535,7 +535,7 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 48.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLength = 16); + int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 48.0, float rxBw = 135.0, int8_t power = 10, uint8_t preambleLength = 16); /*! \brief Blocking binary transmit method. From a91c8252d62101ef0f12f67d6be89909409ce9c8 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 8 Jul 2020 18:51:01 +0200 Subject: [PATCH 321/334] Added new keywords --- keywords.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keywords.txt b/keywords.txt index 846709b1..a564bcf6 100644 --- a/keywords.txt +++ b/keywords.txt @@ -128,6 +128,8 @@ getIRQFlags KEYWORD2 getModemStatus KEYWORD2 getTempRaw KEYWORD2 setRfSwitchPins KEYWORD2 +forceLDRO KEYWORD2 +autoLDRO KEYWORD2 # RF69-specific setAESKey KEYWORD2 From 96405b938da6a7f93a1b1220901d58d4b773982f Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 8 Jul 2020 18:52:08 +0200 Subject: [PATCH 322/334] [SX126x] Added methods to manually set LoRa LDRO --- src/modules/SX126x/SX126x.cpp | 31 ++++++++++++++++++++++++++----- src/modules/SX126x/SX126x.h | 21 ++++++++++++++++++++- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index b5b0d8b9..fbd0edf4 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -650,7 +650,7 @@ int16_t SX126x::setBandwidth(float bw) { // update modulation parameters _bwKhz = bw; - return(setModulationParams(_sf, _bw, _cr)); + return(setModulationParams(_sf, _bw, _cr, _ldro)); } int16_t SX126x::setSpreadingFactor(uint8_t sf) { @@ -663,7 +663,7 @@ int16_t SX126x::setSpreadingFactor(uint8_t sf) { // update modulation parameters _sf = sf; - return(setModulationParams(_sf, _bw, _cr)); + return(setModulationParams(_sf, _bw, _cr, _ldro)); } int16_t SX126x::setCodingRate(uint8_t cr) { @@ -676,7 +676,7 @@ int16_t SX126x::setCodingRate(uint8_t cr) { // update modulation parameters _cr = cr - 4; - return(setModulationParams(_sf, _bw, _cr)); + return(setModulationParams(_sf, _bw, _cr, _ldro)); } int16_t SX126x::setSyncWord(uint8_t syncWord, uint8_t controlBits) { @@ -1152,6 +1152,27 @@ void SX126x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { _mod->setRfSwitchPins(rxEn, txEn); } +int16_t SX126x::forceLDRO(bool enable) { + // check active modem + if(getPacketType() != SX126X_PACKET_TYPE_LORA) { + return(ERR_WRONG_MODEM); + } + + // update modulation parameters + _ldroAuto = false; + _ldro = (uint8_t)enable; + return(setModulationParams(_sf, _bw, _cr, _ldro)); +} + +int16_t SX126x::autoLDRO() { + if(getPacketType() != SX126X_PACKET_TYPE_LORA) { + return(ERR_WRONG_MODEM); + } + + _ldroAuto = true; + return(ERR_NONE); +} + int16_t SX126x::setTCXO(float voltage, uint32_t delay) { // set mode to standby standby(); @@ -1316,8 +1337,8 @@ int16_t SX126x::setHeaderType(uint8_t headerType, size_t len) { } int16_t SX126x::setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro) { - // calculate symbol length and enable low data rate optimization, if needed - if(ldro == 0xFF) { + // calculate symbol length and enable low data rate optimization, if auto-configuration is enabled + if(_ldroAuto) { float symbolLength = (float)(uint32_t(1) << _sf) / (float)_bwKhz; RADIOLIB_DEBUG_PRINT("Symbol length: "); RADIOLIB_DEBUG_PRINT(symbolLength); diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 0461e10b..3d45266a 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -852,6 +852,24 @@ class SX126x: public PhysicalLayer { */ void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + /*! + \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to + the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO() + + \param enable Force LDRO to be always enabled (true) or disabled (false). + + \returns \ref status_codes + */ + int16_t forceLDRO(bool enable); + + /*! + \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically + when symbol length exceeds 16 ms. + + \returns \ref status_codes + */ + int16_t autoLDRO(); + #ifndef RADIOLIB_GODMODE protected: #endif @@ -871,7 +889,7 @@ class SX126x: public PhysicalLayer { int16_t calibrateImage(uint8_t* data); uint8_t getPacketType(); int16_t setTxParams(uint8_t power, uint8_t rampTime = SX126X_PA_RAMP_200U); - int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro = 0xFF); + int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro); int16_t setModulationParamsFSK(uint32_t br, uint8_t pulseShape, uint8_t rxBw, uint32_t freqDev); int16_t setPacketParams(uint16_t preambleLength, uint8_t crcType, uint8_t payloadLength, uint8_t headerType, uint8_t invertIQ = SX126X_LORA_IQ_STANDARD); int16_t setPacketParamsFSK(uint16_t preambleLength, uint8_t crcType, uint8_t syncWordLength, uint8_t addrComp, uint8_t whitening, uint8_t packetType = SX126X_GFSK_PACKET_VARIABLE, uint8_t payloadLength = 0xFF, uint8_t preambleDetectorLength = SX126X_GFSK_PREAMBLE_DETECT_16); @@ -901,6 +919,7 @@ class SX126x: public PhysicalLayer { uint8_t _bw = 0, _sf = 0, _cr = 0, _ldro = 0, _crcType = 0, _headerType = 0; uint16_t _preambleLength = 0; float _bwKhz = 0; + bool _ldroAuto = true; uint32_t _br = 0, _freqDev = 0; uint8_t _rxBw = 0, _pulseShape = 0, _crcTypeFSK = 0, _syncWordLength = 0, _addrComp = 0, _whitening = 0, _packetType = 0; From 58194483b1fe24fbc6718f513055ac99b156e2c9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 8 Jul 2020 18:52:34 +0200 Subject: [PATCH 323/334] [SX127x] Added methods to manually set LoRa LDRO (#162) --- src/modules/SX127x/SX1272.cpp | 61 ++++++++++++++++++++++++---------- src/modules/SX127x/SX1272.h | 20 +++++++++++ src/modules/SX127x/SX1278.cpp | 62 +++++++++++++++++++++++++---------- src/modules/SX127x/SX1278.h | 20 +++++++++++ 4 files changed, 128 insertions(+), 35 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index e6219fc2..cc3e8133 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -106,15 +106,17 @@ int16_t SX1272::setBandwidth(float bw) { if(state == ERR_NONE) { SX127x::_bw = bw; - // calculate symbol length and set low data rate optimization, if needed - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); - if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); - } else { - state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); + // calculate symbol length and set low data rate optimization, if auto-configuration is enabled + if(_ldroAuto) { + float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; + RADIOLIB_DEBUG_PRINT("Symbol length: "); + RADIOLIB_DEBUG_PRINT(symbolLength); + RADIOLIB_DEBUG_PRINTLN(" ms"); + if(symbolLength >= 16.0) { + state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); + } else { + state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); + } } } return(state); @@ -160,15 +162,17 @@ int16_t SX1272::setSpreadingFactor(uint8_t sf) { if(state == ERR_NONE) { SX127x::_sf = sf; - // calculate symbol length and set low data rate optimization, if needed + // calculate symbol length and set low data rate optimization, if auto-configuration is enabled + if(_ldroAuto) { float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); - if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); - } else { - state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); + RADIOLIB_DEBUG_PRINT("Symbol length: "); + RADIOLIB_DEBUG_PRINT(symbolLength); + RADIOLIB_DEBUG_PRINTLN(" ms"); + if(symbolLength >= 16.0) { + state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); + } else { + state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0); + } } } return(state); @@ -372,6 +376,29 @@ int16_t SX1272::setCRC(bool enableCRC) { } } +int16_t SX1272::forceLDRO(bool enable) { + if(getActiveModem() != SX127X_LORA) { + return(ERR_WRONG_MODEM); + } + + _ldroAuto = false; + if(enable) { + return(_mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0)); + } else { + return(_mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0)); + } +} + +int16_t SX1272::autoLDRO() { + if(getActiveModem() != SX127X_LORA) { + return(ERR_WRONG_MODEM); + } + + _ldroAuto = true; + return(ERR_NONE); +} + + int16_t SX1272::setBandwidthRaw(uint8_t newBandwidth) { // set mode to standby int16_t state = SX127x::standby(); diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index 26a5b84a..78e009d3 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -253,6 +253,24 @@ class SX1272: public SX127x { */ int16_t setCRC(bool enableCRC); + /*! + \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to + the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO() + + \param enable Force LDRO to be always enabled (true) or disabled (false). + + \returns \ref status_codes + */ + int16_t forceLDRO(bool enable); + + /*! + \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically + when symbol length exceeds 16 ms. + + \returns \ref status_codes + */ + int16_t autoLDRO(); + #ifndef RADIOLIB_GODMODE protected: #endif @@ -265,6 +283,8 @@ class SX1272: public SX127x { #ifndef RADIOLIB_GODMODE private: #endif + bool _ldroAuto = true; + bool _ldroEnabled = false; }; diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 2e0566a0..c4f6ff40 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -178,15 +178,17 @@ int16_t SX1278::setBandwidth(float bw) { if(state == ERR_NONE) { SX127x::_bw = bw; - // calculate symbol length and set low data rate optimization, if needed - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); - if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); - } else { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); + // calculate symbol length and set low data rate optimization, if auto-configuration is enabled + if(_ldroAuto) { + float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; + RADIOLIB_DEBUG_PRINT("Symbol length: "); + RADIOLIB_DEBUG_PRINT(symbolLength); + RADIOLIB_DEBUG_PRINTLN(" ms"); + if(symbolLength >= 16.0) { + state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); + } else { + state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); + } } } return(state); @@ -232,15 +234,17 @@ int16_t SX1278::setSpreadingFactor(uint8_t sf) { if(state == ERR_NONE) { SX127x::_sf = sf; - // calculate symbol length and set low data rate optimization, if needed - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); - if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); - } else { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); + // calculate symbol length and set low data rate optimization, if auto-configuration is enabled + if(_ldroAuto) { + float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; + RADIOLIB_DEBUG_PRINT("Symbol length: "); + RADIOLIB_DEBUG_PRINT(symbolLength); + RADIOLIB_DEBUG_PRINTLN(" ms"); + if(symbolLength >= 16.0) { + state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); + } else { + state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); + } } } return(state); @@ -450,6 +454,28 @@ int16_t SX1278::setCRC(bool enableCRC) { } } +int16_t SX1278::forceLDRO(bool enable) { + if(getActiveModem() != SX127X_LORA) { + return(ERR_WRONG_MODEM); + } + + _ldroAuto = false; + if(enable) { + return(_mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3)); + } else { + return(_mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3)); + } +} + +int16_t SX1278::autoLDRO() { + if(getActiveModem() != SX127X_LORA) { + return(ERR_WRONG_MODEM); + } + + _ldroAuto = true; + return(ERR_NONE); +} + int16_t SX1278::setBandwidthRaw(uint8_t newBandwidth) { // set mode to standby int16_t state = SX127x::standby(); diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index b25d7be8..cba8c635 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -261,6 +261,24 @@ class SX1278: public SX127x { */ int16_t setCRC(bool enableCRC); + /*! + \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to + the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO() + + \param enable Force LDRO to be always enabled (true) or disabled (false). + + \returns \ref status_codes + */ + int16_t forceLDRO(bool enable); + + /*! + \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically + when symbol length exceeds 16 ms. + + \returns \ref status_codes + */ + int16_t autoLDRO(); + #ifndef RADIOLIB_GODMODE protected: #endif @@ -273,6 +291,8 @@ class SX1278: public SX127x { #ifndef RADIOLIB_GODMODE private: #endif + bool _ldroAuto = true; + bool _ldroEnabled = false; }; From 7397a1a9578c3017c8e048e09b64debc9bdbe04c Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 8 Jul 2020 19:06:38 +0200 Subject: [PATCH 324/334] Bump version to 4.0.1 --- library.properties | 2 +- src/BuildOpt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index b7a8ddfa..14217d0d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RadioLib -version=4.0.0 +version=4.0.1 author=Jan Gromes maintainer=Jan Gromes sentence=Universal wireless communication library for Arduino diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 66697fac..07a21840 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -335,7 +335,7 @@ // version definitions #define RADIOLIB_VERSION_MAJOR (0x04) #define RADIOLIB_VERSION_MINOR (0x00) -#define RADIOLIB_VERSION_PATCH (0x00) +#define RADIOLIB_VERSION_PATCH (0x01) #define RADIOLIB_VERSION_EXTRA (0x00) #define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA)) From e5d23ba23836d2d274d3825de3320a95379d1512 Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 8 Jul 2020 20:50:23 +0200 Subject: [PATCH 325/334] Travis fixed warnings configuration TRAVIS_FORCE_BUILD --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39ede145..46945334 100644 --- a/.travis.yml +++ b/.travis.yml @@ -164,8 +164,7 @@ script: else # build sketch echo -e "\n\033[1;33mBuilding ${example##*/} ... \033[0m"; - # arduino --verify --warnings=$WARNINGS --board $BOARD $example; - arduino-cli compile --fqbn $BOARD $example --warnings=all + arduino-cli compile --fqbn $BOARD $example --warnings=$WARNINGS if [ $? -ne 0 ]; then echo -e "\033[1;31m${example##*/} build FAILED\033[0m\n"; exit 1; From d3233ff585eb9ca106586fe1094fa2ccfd65a2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Fri, 10 Jul 2020 06:57:46 +0200 Subject: [PATCH 326/334] Added module not working issue template --- .github/ISSUE_TEMPLATE/module-not-working.md | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/module-not-working.md diff --git a/.github/ISSUE_TEMPLATE/module-not-working.md b/.github/ISSUE_TEMPLATE/module-not-working.md new file mode 100644 index 00000000..1b67e8d6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/module-not-working.md @@ -0,0 +1,34 @@ +--- +name: Module not working +about: Template to use when your module isn't working +title: '' +labels: '' +assignees: '' + +--- + +**IMPORTANT: Before submitting an issue, please check the following:** +1. **Read [CONTRIBUTING.md](https://github.com/jgromes/RadioLib/blob/master/CONTRIBUTING.md)!** Issues that do not follow this document will be closed/locked/deleted/ignored. +2. RadioLib has a [Wiki](https://github.com/jgromes/RadioLib/wiki) and an extensive [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there. +3. Make sure you're using the latest release of the library! Releases can be found [here](https://github.com/jgromes/RadioLib/releases). +4. Use [Arduino forums](https://forum.arduino.cc/) to ask generic questions about wireless modules, wiring, usage, etc. Only create issues for problems specific to RadioLib! +5. Error codes, their meaning and how to fix them can be found on [this page](https://jgromes.github.io/RadioLib/group__status__codes.html). + +**Sketch that is causing the module fail** + +```c++ +paste the sketch here, even if it is an unmodified example code +``` + +**Hardware setup** +Wiring diagram, schematic, pictures etc. + +**Debug mode output** +Enable all [debug levels](https://github.com/jgromes/RadioLib/wiki/Debug-mode) and paste the Serial monitor output here. + +**Additional info (please complete):** + - MCU: [e.g. Arduino Uno, ESP8266 etc.] + - Link to Arduino core: [e.g. https://github.com/stm32duino/Arduino_Core_STM32 when using official STM32 core. See readme for links to all supported cores] + - Wireless module type [e.g. CC1101, SX1268, etc.] + - Arduino IDE version [e.g. 1.8.5] + - Library version [e.g. 3.0.0] From 7f31cdab8fa6ecadf4cab4236443eae1441149c6 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:20:45 +0200 Subject: [PATCH 327/334] Test doxygen TODOs --- src/Module.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index 6ce55043..774b409b 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -336,7 +336,7 @@ RADIOLIB_PIN_STATUS Module::digitalRead(RADIOLIB_PIN_TYPE pin) { } void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) { - // TODO add tone support for platforms without tone() + /// \todo Add tone support for platforms without tone() #ifndef RADIOLIB_TONE_UNSUPPORTED if(pin != RADIOLIB_NC) { ::tone(pin, value); @@ -345,7 +345,7 @@ void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) { } void Module::noTone(RADIOLIB_PIN_TYPE pin) { - // TODO add tone support for platforms without noTone() + /// \todo Add tone support for platforms without tone() #ifndef RADIOLIB_TONE_UNSUPPORTED if(pin != RADIOLIB_NC) { ::noTone(pin); From e97755a68becc43f8982479ba847c03262a60093 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:51:05 +0200 Subject: [PATCH 328/334] [SX126x] Added Doxygen TODO --- src/modules/SX126x/SX1261.cpp | 2 +- src/modules/SX126x/SX1262.cpp | 2 +- src/modules/SX126x/SX1268.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/SX126x/SX1261.cpp b/src/modules/SX126x/SX1261.cpp index b0b626c2..1e035651 100644 --- a/src/modules/SX126x/SX1261.cpp +++ b/src/modules/SX126x/SX1261.cpp @@ -18,7 +18,7 @@ int16_t SX1261::setOutputPower(int8_t power) { RADIOLIB_ASSERT(state); // set output power - // TODO power ramp time configuration + /// \todo power ramp time configuration state = SX126x::setTxParams(power); RADIOLIB_ASSERT(state); diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index a73cebe6..0d78eea5 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -84,7 +84,7 @@ int16_t SX1262::setOutputPower(int8_t power) { RADIOLIB_ASSERT(state); // set output power - // TODO power ramp time configuration + /// \todo power ramp time configuration state = SX126x::setTxParams(power); RADIOLIB_ASSERT(state); diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index 673f5853..0addddf8 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -23,7 +23,7 @@ int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync return(state); } -int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength,float tcxoVoltage, bool useRegulatorLDO) { +int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { // execute common part int16_t state = SX126x::beginFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage, useRegulatorLDO); RADIOLIB_ASSERT(state); @@ -41,6 +41,7 @@ int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t return(state); } +/// \todo integers only (all modules - frequency, data rate, bandwidth etc.) int16_t SX1268::setFrequency(float freq, bool calibrate) { RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, ERR_INVALID_FREQUENCY); @@ -78,7 +79,7 @@ int16_t SX1268::setOutputPower(int8_t power) { RADIOLIB_ASSERT(state); // set output power - // TODO power ramp time configuration + /// \todo power ramp time configuration state = SX126x::setTxParams(power); RADIOLIB_ASSERT(state); From 6452ea401fac650378e141bd7959c52f0952fe21 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:51:16 +0200 Subject: [PATCH 329/334] [SX127x] Added Doxygen TODOs --- src/modules/SX127x/SX127x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 3e464260..2890ff5f 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -680,7 +680,7 @@ int16_t SX127x::setBitRate(float br) { state = _mod->SPIsetRegValue(SX127X_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); state |= _mod->SPIsetRegValue(SX127X_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); - // TODO fractional part of bit rate setting (not in OOK) + /// \todo fractional part of bit rate setting (not in OOK) if(state == ERR_NONE) { SX127x::_br = br; } From a1583487b084b9dd9657ab6727b30a855d9867f7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:51:23 +0200 Subject: [PATCH 330/334] [SX128x] Added Doxygen TODOs --- src/modules/SX128x/SX1282.cpp | 1 + src/modules/SX128x/SX1282.h | 2 -- src/modules/SX128x/SX128x.cpp | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/SX128x/SX1282.cpp b/src/modules/SX128x/SX1282.cpp index 2a77ffcd..33deee97 100644 --- a/src/modules/SX128x/SX1282.cpp +++ b/src/modules/SX128x/SX1282.cpp @@ -1,6 +1,7 @@ #include "SX1282.h" #if !defined(RADIOLIB_EXCLUDE_SX128X) +/// \todo implement advanced ranging SX1282::SX1282(Module* mod) : SX1280(mod) { } diff --git a/src/modules/SX128x/SX1282.h b/src/modules/SX128x/SX1282.h index 1e3b9be7..f6cbdbd7 100644 --- a/src/modules/SX128x/SX1282.h +++ b/src/modules/SX128x/SX1282.h @@ -9,8 +9,6 @@ #include "SX128x.h" #include "SX1280.h" -// TODO implement advanced ranging - /*! \class SX1282 diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 48d3b69f..8638ebc9 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -890,7 +890,7 @@ int16_t SX128x::setSyncWord(uint8_t* syncWord, uint8_t len) { if(_syncWordLen == 0) { _syncWordMatch = SX128X_GFSK_FLRC_SYNC_WORD_OFF; } else { - // TODO add support for multiple sync words + /// \todo add support for multiple sync words _syncWordMatch = SX128X_GFSK_FLRC_SYNC_WORD_1; } return(setPacketParamsGFSK(_preambleLengthGFSK, _syncWordLen, _syncWordMatch, _crcGFSK, _whitening)); @@ -1093,7 +1093,7 @@ uint32_t SX128x::getTimeOnAir(size_t len) { } else { // long interleaving - abandon hope all ye who enter here - // TODO implement this mess - SX1280 datasheet v3.0 section 7.4.4.2 + /// \todo implement this mess - SX1280 datasheet v3.0 section 7.4.4.2 } From 6c3dff49357c2ce902ac1c30fe6197387146ccb9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:51:30 +0200 Subject: [PATCH 331/334] [Si443x] Added Doxygen TODOs --- src/modules/Si443x/Si443x.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 84534e09..8f2b9cfe 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -145,7 +145,7 @@ int16_t Si443x::transmitDirect(uint32_t frf) { // user requested to start transmitting immediately (required for RTTY) if(frf != 0) { // convert the 24-bit frequency to the format accepted by the module - // TODO integers only + /// \todo integers only float newFreq = frf / 6400.0; // check high/low band @@ -227,10 +227,10 @@ int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { clearIRQFlags(); // set packet length - // TODO variable packet length + /// \todo variable packet length _mod->SPIwriteRegister(SI443X_REG_TRANSMIT_PACKET_LENGTH, len); - // TODO use header as address field? + /// \todo use header as address field? (void)addr; // write packet to FIFO @@ -497,7 +497,7 @@ int16_t Si443x::setPreambleLength(uint8_t preambleLen) { } size_t Si443x::getPacketLength(bool update) { - // TODO variable length mode + /// \todo variable length mode if(!_packetLengthQueried && update) { _packetLength = _mod->SPIreadRegister(SI443X_REG_RECEIVED_PACKET_LENGTH); _packetLengthQueried = true; @@ -512,7 +512,7 @@ int16_t Si443x::setEncoding(uint8_t encoding) { RADIOLIB_ASSERT(state); // set encoding - // TODO - add inverted Manchester? + /// \todo - add inverted Manchester? switch(encoding) { case RADIOLIB_ENCODING_NRZ: return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_OFF, 2, 0)); @@ -537,7 +537,7 @@ int16_t Si443x::setDataShaping(uint8_t sh) { case RADIOLIB_SHAPING_0_3: case RADIOLIB_SHAPING_0_5: case RADIOLIB_SHAPING_1_0: - // TODO implement fiter configuration - docs claim this should be possible, but seems undocumented + /// \todo implement fiter configuration - docs claim this should be possible, but seems undocumented return(_mod->SPIsetRegValue(SI443X_REG_MODULATION_MODE_CONTROL_1, SI443X_MANCHESTER_INVERTED_OFF | SI443X_MANCHESTER_OFF | SI443X_WHITENING_ON, 2, 0)); default: return(ERR_INVALID_ENCODING); From 29d24c916b36d047ff0478565d03844872416adf Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:51:37 +0200 Subject: [PATCH 332/334] [XBee] Added Doxygen TODOs --- src/modules/XBee/XBee.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/XBee/XBee.cpp b/src/modules/XBee/XBee.cpp index 894c32b3..9b1abe73 100644 --- a/src/modules/XBee/XBee.cpp +++ b/src/modules/XBee/XBee.cpp @@ -391,7 +391,7 @@ void XBee::sendApiFrame(uint8_t type, uint8_t id, uint8_t* data, uint16_t length } int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) { - // TODO: modemStatus frames may be sent at any time, interfering with frame parsing. Add check to make sure this does not happen. + /// \todo modemStatus frames may be sent at any time, interfering with frame parsing. Add check to make sure this does not happen. // get number of bytes in response (must be enough to read the length field uint16_t numBytes = getNumBytes(timeout/2, 3); From 735db87bb3dbf6c1477972fc83a80bed50fb794a Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:51:43 +0200 Subject: [PATCH 333/334] [MQTT] Added Doxygen TODOs --- src/protocols/MQTT/MQTT.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/protocols/MQTT/MQTT.cpp b/src/protocols/MQTT/MQTT.cpp index fb4791f7..b86b548f 100644 --- a/src/protocols/MQTT/MQTT.cpp +++ b/src/protocols/MQTT/MQTT.cpp @@ -205,7 +205,7 @@ int16_t MQTTClient::publish(const char* topic, const char* message) { #endif return(state); - //TODO: implement QoS > 0 and PUBACK response checking + /// \todo implement QoS > 0 and PUBACK response checking } int16_t MQTTClient::subscribe(const char* topicFilter) { @@ -410,7 +410,6 @@ int16_t MQTTClient::check(void (*func)(const char*, const char*)) { uint8_t* dataIn = new uint8_t[numBytes]; _tl->receive(dataIn, numBytes); if(dataIn[0] == MQTT_PUBLISH << 4) { - // TODO: properly decode remaining length uint8_t remLenFieldLen = 0; uint32_t remainingLength = decodeLength(dataIn + 1, remLenFieldLen); From 4e943b5437733dba5e0a17475687cd4b7eaede20 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 10 Jul 2020 08:51:51 +0200 Subject: [PATCH 334/334] [RTTY] Added Doxygen TODOs --- src/protocols/RTTY/RTTY.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index 657f55f1..686c3494 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -452,8 +452,7 @@ size_t RTTYClient::printNumber(unsigned long n, uint8_t base) { return(l); } -// TODO: improve ITA2 float print speed -// (characters are sent one at a time) +/// \todo improve ITA2 float print speed (characters are sent one at a time) size_t RTTYClient::printFloat(double number, uint8_t digits) { size_t n = 0;