From 59c44d388371869d9b875e76e38ee6ee57293758 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 1 Aug 2020 16:33:25 +0200 Subject: [PATCH] Added Module overrides for all Arduino core functions --- src/Module.cpp | 40 ++++++++++++++++++++++++----- src/Module.h | 70 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 93 insertions(+), 17 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index 774b409b..8d3e2e19 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -175,8 +175,8 @@ bool Module::ATsendData(uint8_t* data, uint32_t len) { bool Module::ATgetResponse() { char data[128]; char* dataPtr = data; - uint32_t start = millis(); - while(millis() - start < _ATtimeout) { + uint32_t start = Module::millis(); + while(Module::millis() - start < _ATtimeout) { while(ModuleSerial->available() > 0) { char c = ModuleSerial->read(); RADIOLIB_VERBOSE_PRINT(c); @@ -218,9 +218,9 @@ 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(); + uint32_t start = Module::micros(); uint8_t readValue; - while(micros() - start < (checkInterval * 1000)) { + while(Module::micros() - start < (checkInterval * 1000)) { readValue = SPIreadRegister(reg); if(readValue == newValue) { // check passed, we can stop the loop @@ -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 tone() + // TODO add tone support for platforms without noTone() #ifndef RADIOLIB_TONE_UNSUPPORTED if(pin != RADIOLIB_NC) { ::noTone(pin); @@ -353,6 +353,34 @@ void Module::noTone(RADIOLIB_PIN_TYPE pin) { #endif } +void Module::attachInterrupt(RADIOLIB_PIN_TYPE interruptNum, void (*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode) { + ::attachInterrupt(interruptNum, userFunc, mode); +} + +void Module::detachInterrupt(RADIOLIB_PIN_TYPE interruptNum) { + ::detachInterrupt(interruptNum); +} + +void Module::yield() { + ::yield(); +} + +void Module::delay(uint32_t ms) { + ::delay(ms); +} + +void Module::delayMicroseconds(uint32_t us) { + ::delayMicroseconds(us); +} + +uint32_t Module::millis() { + return(::millis()); +} + +uint32_t Module::micros() { + return(::micros()); +} + void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { _useRfSwitch = true; _rxEn = rxEn; diff --git a/src/Module.h b/src/Module.h index aa12389f..3f1b9345 100644 --- a/src/Module.h +++ b/src/Module.h @@ -4,7 +4,6 @@ #include "TypeDef.h" #include -//#include #ifndef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #include #endif @@ -356,6 +355,27 @@ class Module { */ SPISettings getSpiSettings() const { return(_spiSettings); } + /*! + \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 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(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState); + + // Arduino core overrides + /*! \brief Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin. @@ -400,23 +420,51 @@ 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! + \brief Arduino core attachInterrupt override. - \param rxEn RX enable pin. + \param interruptNum Interrupt number. - \param txEn TX enable pin. + \param userFunc Interrupt service routine. + + \param mode Pin hcange direction. */ - void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); + static void attachInterrupt(RADIOLIB_PIN_TYPE interruptNum, void (*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode); /*! - \brief Set RF switch state. + \brief Arduino core detachInterrupt override. - \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). + \param interruptNum Interrupt number. */ - void setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState); + static void detachInterrupt(RADIOLIB_PIN_TYPE interruptNum); + + /*! + \brief Arduino core yield override. + */ + static void yield(); + + /*! + \brief Arduino core delay override. + + \param ms Delay length in milliseconds. + */ + static void delay(uint32_t ms); + + /*! + \brief Arduino core delayMicroseconds override. + + \param us Delay length in microseconds. + */ + static void delayMicroseconds(uint32_t us); + + /*! + \brief Arduino core millis override. + */ + static uint32_t millis(); + + /*! + \brief Arduino core micros override. + */ + static uint32_t micros(); #ifndef RADIOLIB_GODMODE private: