From 3a5d9b5c321ea881966f7836380e7237a702e317 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 12 Jan 2024 20:26:07 +0100 Subject: [PATCH] [RF69] Cleanup private/protected members --- src/modules/RF69/RF69.cpp | 8 ++++---- src/modules/RF69/RF69.h | 22 +++++++++++----------- src/modules/SX123x/SX1231.cpp | 15 ++++++++------- src/modules/SX123x/SX1233.cpp | 22 ++++++++++++---------- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index db3335db..54e6cc74 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -6,10 +6,6 @@ RF69::RF69(Module* module) : PhysicalLayer(RADIOLIB_RF69_FREQUENCY_STEP_SIZE, RA this->mod = module; } -Module* RF69::getMod() { - return(this->mod); -} - int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t pwr, uint8_t preambleLen) { // set module properties this->mod->init(); @@ -982,6 +978,10 @@ int16_t RF69::setDIOMapping(uint32_t pin, uint32_t value) { return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_2, value, 15 - 2 * pin, 14 - 2 * pin)); } +Module* RF69::getMod() { + return(this->mod); +} + int16_t RF69::getChipVersion() { return(this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_VERSION)); } diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index d71d91c6..177b839c 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -490,8 +490,6 @@ class RF69: public PhysicalLayer { */ RF69(Module* module); - Module* getMod(); - // basic methods /*! @@ -998,15 +996,23 @@ class RF69: public PhysicalLayer { #if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL protected: #endif - Module* mod; + Module* getMod(); #if !RADIOLIB_GODMODE protected: #endif - - float frequency = RADIOLIB_RF69_DEFAULT_FREQ; float bitRate = RADIOLIB_RF69_DEFAULT_BR; float rxBandwidth = RADIOLIB_RF69_DEFAULT_RXBW; + + int16_t config(); + int16_t setMode(uint8_t mode); + +#if !RADIOLIB_GODMODE + private: +#endif + Module* mod; + + float frequency = RADIOLIB_RF69_DEFAULT_FREQ; bool ookEnabled = false; int16_t tempOffset = 0; int8_t power = RADIOLIB_RF69_DEFAULT_POWER; @@ -1021,14 +1027,8 @@ class RF69: public PhysicalLayer { bool bitSync = true; - int16_t config(); int16_t directMode(); int16_t setPacketMode(uint8_t mode, uint8_t len); - int16_t setMode(uint8_t mode); - -#if !RADIOLIB_GODMODE - private: -#endif void clearIRQFlags(); void clearFIFO(size_t count); }; diff --git a/src/modules/SX123x/SX1231.cpp b/src/modules/SX123x/SX1231.cpp index 8d38edaf..44ff904d 100644 --- a/src/modules/SX123x/SX1231.cpp +++ b/src/modules/SX123x/SX1231.cpp @@ -7,9 +7,10 @@ SX1231::SX1231(Module* mod) : RF69(mod) { int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { // set module properties - this->mod->init(); - this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput); - this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput); + Module* mod = this->getMod(); + mod->init(); + mod->hal->pinMode(mod->getIrq(), mod->hal->GpioModeInput); + mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput); // try to find the SX1231 chip uint8_t i = 0; @@ -21,14 +22,14 @@ int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t po this->chipRevision = version; } else { RADIOLIB_DEBUG_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version); - this->mod->hal->delay(10); + mod->hal->delay(10); i++; } } if(!flagFound) { RADIOLIB_DEBUG_PRINTLN("No SX1231 found!"); - this->mod->term(); + mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } RADIOLIB_DEBUG_PRINTLN("M\tSX1231"); @@ -77,11 +78,11 @@ int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t po // SX123x V2a only if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) { // modify default OOK threshold value - state = this->mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD); + state = mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD); RADIOLIB_ASSERT(state); // enable OCP with 95 mA limit - state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0); + state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0); RADIOLIB_ASSERT(state); } diff --git a/src/modules/SX123x/SX1233.cpp b/src/modules/SX123x/SX1233.cpp index c13d5e39..6acf5a7e 100644 --- a/src/modules/SX123x/SX1233.cpp +++ b/src/modules/SX123x/SX1233.cpp @@ -8,9 +8,10 @@ SX1233::SX1233(Module* mod) : SX1231(mod) { int16_t SX1233::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { // set module properties - this->mod->init(); - this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput); - this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput); + Module* mod = this->getMod(); + mod->init(); + mod->hal->pinMode(mod->getIrq(), mod->hal->GpioModeInput); + mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput); // try to find the SX1233 chip uint8_t i = 0; @@ -22,14 +23,14 @@ int16_t SX1233::begin(float freq, float br, float freqDev, float rxBw, int8_t po this->chipRevision = version; } else { RADIOLIB_DEBUG_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version); - this->mod->hal->delay(10); + mod->hal->delay(10); i++; } } if(!flagFound) { RADIOLIB_DEBUG_PRINTLN("No SX1233 found!"); - this->mod->term(); + mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } RADIOLIB_DEBUG_PRINTLN("M\tSX1233"); @@ -78,11 +79,11 @@ int16_t SX1233::begin(float freq, float br, float freqDev, float rxBw, int8_t po // SX123x V2a only if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) { // modify default OOK threshold value - state = this->mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD); + state = mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD); RADIOLIB_ASSERT(state); // enable OCP with 95 mA limit - state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0); + state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0); RADIOLIB_ASSERT(state); } @@ -109,13 +110,14 @@ int16_t SX1233::setBitRate(float br) { setMode(RADIOLIB_RF69_STANDBY); // set PLL bandwidth - int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX1233_REG_TEST_PLL, pllBandwidth, 7, 0); + Module* mod = this->getMod(); + int16_t state = mod->SPIsetRegValue(RADIOLIB_SX1233_REG_TEST_PLL, pllBandwidth, 7, 0); RADIOLIB_ASSERT(state); // set bit rate uint16_t bitRate = 32000 / br; - state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); - state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); + state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); + state |= mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); if(state == RADIOLIB_ERR_NONE) { this->bitRate = br; }