diff --git a/src/modules/SX126x/STM32WLx.cpp b/src/modules/SX126x/STM32WLx.cpp index 508ea4e5..69515fcf 100644 --- a/src/modules/SX126x/STM32WLx.cpp +++ b/src/modules/SX126x/STM32WLx.cpp @@ -87,6 +87,7 @@ int16_t STM32WLx::setOutputPower(int8_t power) { return(RADIOLIB_ERR_INVALID_OUTPUT_POWER); } + RADIOLIB_ASSERT(state); // Apply workaround for HP only state = SX126x::fixPaClamping(use_hp); diff --git a/src/modules/SX126x/STM32WLx.h b/src/modules/SX126x/STM32WLx.h index 16c88cc9..993791aa 100644 --- a/src/modules/SX126x/STM32WLx.h +++ b/src/modules/SX126x/STM32WLx.h @@ -39,7 +39,7 @@ class STM32WLx : public SX1262 { \brief Default constructor. \param mod Instance of STM32WLx_Module that will be used to communicate with the radio. */ - STM32WLx(STM32WLx_Module* mod); + STM32WLx(STM32WLx_Module* mod); // cppcheck-suppress noExplicitConstructor /*! \brief Custom operation modes for STMWLx. @@ -124,34 +124,34 @@ class STM32WLx : public SX1262 { \brief Sets interrupt service routine to call when a packet is received. \param func ISR to call. */ - void setPacketReceivedAction(void (*func)(void)); + void setPacketReceivedAction(void (*func)(void)) override; /*! \brief Clears interrupt service routine to call when a packet is received. */ - void clearPacketReceivedAction(); + void clearPacketReceivedAction() override; /*! \brief Sets interrupt service routine to call when a packet is sent. \param func ISR to call. */ - void setPacketSentAction(void (*func)(void)); + void setPacketSentAction(void (*func)(void)) override; /*! \brief Clears interrupt service routine to call when a packet is sent. */ - void clearPacketSentAction(); + void clearPacketSentAction() override; /*! \brief Sets interrupt service routine to call when a channel scan is finished. \param func ISR to call. */ - void setChannelScanAction(void (*func)(void)); + void setChannelScanAction(void (*func)(void)) override; /*! \brief Clears interrupt service routine to call when a channel scan is finished. */ - void clearChannelScanAction(); + void clearChannelScanAction() override; #if !RADIOLIB_GODMODE protected: diff --git a/src/modules/SX126x/SX1261.h b/src/modules/SX126x/SX1261.h index 6f401159..196cc21b 100644 --- a/src/modules/SX126x/SX1261.h +++ b/src/modules/SX126x/SX1261.h @@ -25,14 +25,14 @@ class SX1261 : public SX1262 { \brief Default constructor. \param mod Instance of Module that will be used to communicate with the radio. */ - SX1261(Module* mod); + SX1261(Module* mod); // cppcheck-suppress noExplicitConstructor /*! \brief Sets output power. Allowed values are in range from -17 to 14 dBm. \param power Output power to be set in dBm. \returns \ref status_codes */ - int16_t setOutputPower(int8_t power); + int16_t setOutputPower(int8_t power) override; /*! \brief Check if output power is configurable. @@ -40,7 +40,7 @@ class SX1261 : public SX1262 { \param clipped Clipped output power value to what is possible within the module's range. \returns \ref status_codes */ - int16_t checkOutputPower(int8_t power, int8_t* clipped); + int16_t checkOutputPower(int8_t power, int8_t* clipped) override; #if !RADIOLIB_GODMODE private: diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index ebe8652a..7ae6789f 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -25,7 +25,7 @@ class SX1262: public SX126x { \brief Default constructor. \param mod Instance of Module that will be used to communicate with the radio. */ - SX1262(Module* mod); + SX1262(Module* mod); // cppcheck-suppress noExplicitConstructor // basic methods @@ -69,7 +69,7 @@ class SX1262: public SX126x { \param freq Carrier frequency to be set in MHz. \returns \ref status_codes */ - int16_t setFrequency(float freq); + int16_t setFrequency(float freq) override; /*! \brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz. @@ -85,7 +85,7 @@ class SX1262: public SX126x { \param power Output power to be set in dBm. \returns \ref status_codes */ - virtual int16_t setOutputPower(int8_t power); + virtual int16_t setOutputPower(int8_t power) override; /*! \brief Check if output power is configurable. @@ -93,7 +93,7 @@ class SX1262: public SX126x { \param clipped Clipped output power value to what is possible within the module's range. \returns \ref status_codes */ - int16_t checkOutputPower(int8_t power, int8_t* clipped); + int16_t checkOutputPower(int8_t power, int8_t* clipped) override; #if !RADIOLIB_GODMODE private: diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index d6f0415e..503c74e8 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -24,7 +24,7 @@ class SX1268: public SX126x { \brief Default constructor. \param mod Instance of Module that will be used to communicate with the radio. */ - SX1268(Module* mod); + SX1268(Module* mod); // cppcheck-suppress noExplicitConstructor // basic methods @@ -68,7 +68,7 @@ class SX1268: public SX126x { \param freq Carrier frequency to be set in MHz. \returns \ref status_codes */ - int16_t setFrequency(float freq); + int16_t setFrequency(float freq) override; /*! \brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz. @@ -83,7 +83,7 @@ class SX1268: public SX126x { \param power Output power to be set in dBm. \returns \ref status_codes */ - int16_t setOutputPower(int8_t power); + int16_t setOutputPower(int8_t power) override; /*! \brief Check if output power is configurable. @@ -91,7 +91,7 @@ class SX1268: public SX126x { \param clipped Clipped output power value to what is possible within the module's range. \returns \ref status_codes */ - int16_t checkOutputPower(int8_t power, int8_t* clipped); + int16_t checkOutputPower(int8_t power, int8_t* clipped) override; #if !RADIOLIB_GODMODE private: diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 105d1fda..aca4f15b 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -76,10 +76,11 @@ int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, flo RADIOLIB_ASSERT(state); if (useRegulatorLDO) { - state = setRegulatorLDO(); + state = setRegulatorLDO(); } else { - state = setRegulatorDCDC(); + state = setRegulatorDCDC(); } + RADIOLIB_ASSERT(state); // set publicly accessible settings that are not a part of begin method state = setCurrentLimit(60.0); @@ -1577,7 +1578,7 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile) // check the version #if RADIOLIB_DEBUG_BASIC char ver_pre[16]; - this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_pre); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, reinterpret_cast(ver_pre)); RADIOLIB_DEBUG_BASIC_PRINTLN("Pre-update version string: %s", ver_pre); #endif @@ -1609,7 +1610,7 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile) // check the version again #if RADIOLIB_DEBUG_BASIC char ver_post[16]; - this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_post); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, reinterpret_cast(ver_post)); RADIOLIB_DEBUG_BASIC_PRINTLN("Post-update version string: %s", ver_post); #endif @@ -1736,7 +1737,7 @@ int16_t SX126x::setRx(uint32_t timeout) { int16_t SX126x::setCad(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) { // default CAD parameters are shown in Semtech AN1200.48, page 41. - uint8_t detPeakValues[6] = { 22, 22, 24, 25, 26, 30}; + const uint8_t detPeakValues[6] = { 22, 22, 24, 25, 26, 30}; // CAD parameters aren't available for SF-6. Just to be safe. if(this->spreadingFactor < 7) { @@ -2163,18 +2164,18 @@ bool SX126x::findChip(const char* verStr) { // read the version string char version[16]; - this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)version); + this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, reinterpret_cast(version)); // check version register if(strncmp(verStr, version, 6) == 0) { RADIOLIB_DEBUG_BASIC_PRINTLN("Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:"); - RADIOLIB_DEBUG_BASIC_HEXDUMP((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); + RADIOLIB_DEBUG_BASIC_HEXDUMP(reinterpret_cast(version), 16, RADIOLIB_SX126X_REG_VERSION_STRING); RADIOLIB_DEBUG_BASIC_PRINTLN(); flagFound = true; } else { #if RADIOLIB_DEBUG_BASIC RADIOLIB_DEBUG_BASIC_PRINTLN("SX126x not found! (%d of 10 tries) RADIOLIB_SX126X_REG_VERSION_STRING:", i + 1); - RADIOLIB_DEBUG_BASIC_HEXDUMP((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); + RADIOLIB_DEBUG_BASIC_HEXDUMP(reinterpret_cast(version), 16, RADIOLIB_SX126X_REG_VERSION_STRING); RADIOLIB_DEBUG_BASIC_PRINTLN("Expected string: %s", verStr); #endif this->mod->hal->delay(10); diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index f8829b9c..2bd3a042 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -452,7 +452,7 @@ class SX126x: public PhysicalLayer { \brief Default constructor. \param mod Instance of Module that will be used to communicate with the radio. */ - SX126x(Module* mod); + SX126x(Module* mod); // cppcheck-suppress noExplicitConstructor /*! \brief Whether the module has an XTAL (true) or TCXO (false). Defaults to false. @@ -586,34 +586,34 @@ class SX126x: public PhysicalLayer { \brief Sets interrupt service routine to call when a packet is received. \param func ISR to call. */ - void setPacketReceivedAction(void (*func)(void)); + void setPacketReceivedAction(void (*func)(void)) override; /*! \brief Clears interrupt service routine to call when a packet is received. */ - void clearPacketReceivedAction(); + void clearPacketReceivedAction() override; /*! \brief Sets interrupt service routine to call when a packet is sent. \param func ISR to call. */ - void setPacketSentAction(void (*func)(void)); + void setPacketSentAction(void (*func)(void)) override; /*! \brief Clears interrupt service routine to call when a packet is sent. */ - void clearPacketSentAction(); + void clearPacketSentAction() override; /*! \brief Sets interrupt service routine to call when a channel scan is finished. \param func ISR to call. */ - void setChannelScanAction(void (*func)(void)); + void setChannelScanAction(void (*func)(void)) override; /*! \brief Clears interrupt service routine to call when a channel scan is finished. */ - void clearChannelScanAction(); + void clearChannelScanAction() override; /*! \brief Interrupt-driven binary transmit method. @@ -637,7 +637,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t startReceive(); + int16_t startReceive() override; /*! \brief Interrupt-driven receive method. DIO1 will be activated when full packet is received. @@ -786,7 +786,7 @@ class SX126x: public PhysicalLayer { \param br FSK bit rate to be set in kbps. \returns \ref status_codes */ - int16_t setBitRate(float br); + int16_t setBitRate(float br) override; /*! \brief Set data. @@ -920,7 +920,7 @@ class SX126x: public PhysicalLayer { \brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem. \returns SNR of the last received packet in dB. */ - float getSNR(); + float getSNR() override; /*! \brief Gets frequency error of the latest received packet. @@ -964,7 +964,7 @@ class SX126x: public PhysicalLayer { \param timeoutUs Timeout in microseconds to listen for \returns Timeout value in a unit that is specific for the used module */ - RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs); + RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override; /*! \brief Create the flags that make up RxDone and RxTimeout used for receiving downlinks @@ -972,13 +972,13 @@ class SX126x: public PhysicalLayer { \param irqMask Mask indicating which IRQ triggers a DIO \returns \ref status_codes */ - int16_t irqRxDoneRxTimeout(uint16_t &irqFlags, uint16_t &irqMask); + int16_t irqRxDoneRxTimeout(uint16_t &irqFlags, uint16_t &irqMask) override; /*! \brief Check whether the IRQ bit for RxTimeout is set \returns Whether RxTimeout IRQ is set */ - bool isRxTimeout(); + bool isRxTimeout() override; /*! \brief Set implicit header mode for future reception/transmission. @@ -1040,7 +1040,7 @@ class SX126x: public PhysicalLayer { \brief Get one truly random byte from RSSI noise. \returns TRNG byte. */ - uint8_t randomByte(); + uint8_t randomByte() override; /*! \brief Enable/disable inversion of the I and Q signals @@ -1054,13 +1054,13 @@ class SX126x: public PhysicalLayer { \brief Set interrupt service routine function to call when data bit is received in direct mode. \param func Pointer to interrupt service routine. */ - void setDirectAction(void (*func)(void)); + void setDirectAction(void (*func)(void)) override; /*! \brief Function to read and process data bit in direct reception mode. \param pin Pin on which to read. */ - void readBit(uint32_t pin); + void readBit(uint32_t pin) override; #endif /*! @@ -1132,7 +1132,7 @@ class SX126x: public PhysicalLayer { #if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL protected: #endif - Module* getMod(); + Module* getMod() override; // SX126x SPI command implementations int16_t setFs(); @@ -1163,7 +1163,7 @@ class SX126x: public PhysicalLayer { #if !RADIOLIB_GODMODE protected: #endif - const char* chipType; + const char* chipType = NULL; uint8_t bandwidth = 0; // Allow subclasses to define different TX modes