From b1397675591e37bfedd7a11c92741ef4b9d3f450 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 7 Jul 2023 20:48:51 +0200 Subject: [PATCH] [EXT] Implemented direct transmit (#646) --- src/protocols/ExternalRadio/ExternalRadio.cpp | 40 +++++++++++++-- src/protocols/ExternalRadio/ExternalRadio.h | 49 ++++++++++++++++++- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/src/protocols/ExternalRadio/ExternalRadio.cpp b/src/protocols/ExternalRadio/ExternalRadio.cpp index 48332fec..0748b495 100644 --- a/src/protocols/ExternalRadio/ExternalRadio.cpp +++ b/src/protocols/ExternalRadio/ExternalRadio.cpp @@ -1,15 +1,47 @@ #include "ExternalRadio.h" #if defined(RADIOLIB_BUILD_ARDUINO) -ExternalRadio::ExternalRadio() : PhysicalLayer(1, 0) { - mod = new Module(RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC); +ExternalRadio::ExternalRadio(uint32_t pin) : PhysicalLayer(1, 0) { + mod = new Module(RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, pin); + mod->hal->pinMode(pin, mod->hal->GpioModeOutput); + this->prevFrf = 0; } #endif -ExternalRadio::ExternalRadio(RadioLibHal *hal) : PhysicalLayer(1, 0) { - mod = new Module(hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC); +ExternalRadio::ExternalRadio(RadioLibHal *hal, uint32_t pin) : PhysicalLayer(1, 0) { + mod = new Module(hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, pin); + mod->hal->pinMode(pin, mod->hal->GpioModeOutput); + this->prevFrf = 0; } Module* ExternalRadio::getMod() { return(mod); +} + +int16_t ExternalRadio::setFrequencyDeviation(float freqDev) { + (void)freqDev; + return(RADIOLIB_ERR_NONE); +} + +int16_t ExternalRadio::setDataShaping(uint8_t sh) { + (void)sh; + return(RADIOLIB_ERR_NONE); +} + +int16_t ExternalRadio::setEncoding(uint8_t encoding) { + (void)encoding; + return(RADIOLIB_ERR_NONE); +} + +int16_t ExternalRadio::transmitDirect(uint32_t frf) { + if(frf != this->prevFrf) { + uint32_t val = this->mod->hal->GpioLevelLow; + if(frf > this->prevFrf) { + val = this->mod->hal->GpioLevelHigh; + } + this->prevFrf = frf; + this->mod->hal->digitalWrite(this->mod->getGpio(), val); + } + + return(RADIOLIB_ERR_NONE); } \ No newline at end of file diff --git a/src/protocols/ExternalRadio/ExternalRadio.h b/src/protocols/ExternalRadio/ExternalRadio.h index bbbbd447..25908fd0 100644 --- a/src/protocols/ExternalRadio/ExternalRadio.h +++ b/src/protocols/ExternalRadio/ExternalRadio.h @@ -12,13 +12,58 @@ class ExternalRadio: public PhysicalLayer { public: #if defined(RADIOLIB_BUILD_ARDUINO) - ExternalRadio(); + /*! + \brief Default constructor. + \param pin Output pin when using direct transmission, defaults to unused pin. + */ + ExternalRadio(uint32_t pin = RADIOLIB_NC); #endif - ExternalRadio(RadioLibHal *hal); + + /*! + \brief Default constructor. + \param hal Pointer to the hardware abstraction layer to use. + \param pin Output pin when using direct transmission, defaults to unused pin. + */ + ExternalRadio(RadioLibHal *hal, uint32_t pin = RADIOLIB_NC); + /*! + \brief Method to retrieve pointer to the underlying Module instance. + \returns Pointer to the Module instance. + */ Module* getMod(); + + /*! + \brief Dummy implementation overriding PhysicalLayer. + \param freqDev Ignored. + \returns \ref status_codes + */ + int16_t setFrequencyDeviation(float freqDev) override; + + /*! + \brief Dummy implementation overriding PhysicalLayer. + \param sh Ignored. + \returns \ref status_codes + */ + int16_t setDataShaping(uint8_t sh) override; + + /*! + \brief Dummy implementation overriding PhysicalLayer. + \param encoding Ignored. + \returns \ref status_codes + */ + int16_t setEncoding(uint8_t encoding) override; + + /*! + \brief Direct transmission to drive external radio. + \param frf "Frequency" to control the output pin. If the frequency is higher than the one sent previously, + the output pin will be set to logic high. Otherwise it will be set to logic low. + \returns \ref status_codes + */ + int16_t transmitDirect(uint32_t frf = 0); + private: Module* mod; + uint32_t prevFrf; }; #endif \ No newline at end of file