diff --git a/keywords.txt b/keywords.txt index 150f81f9..9aabb1c0 100644 --- a/keywords.txt +++ b/keywords.txt @@ -175,7 +175,7 @@ shutdown KEYWORD2 # Constants (LITERAL1) ####################################### -RADIOLIB_PIN_UNUSED LITERAL1 +NC LITERAL1 RADIOLIB_VERSION LITERAL1 ERR_NONE LITERAL1 diff --git a/src/Module.cpp b/src/Module.cpp index d1b1f136..27181535 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -1,10 +1,10 @@ #include "Module.h" Module::Module(int16_t rx, int16_t tx, HardwareSerial* useSer, int16_t rst) { - _cs = RADIOLIB_PIN_UNUSED; + _cs = NC; _rx = rx; _tx = tx; - _irq = RADIOLIB_PIN_UNUSED; + _irq = NC; _rst = rst; #ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED @@ -17,8 +17,8 @@ Module::Module(int16_t rx, int16_t tx, HardwareSerial* useSer, int16_t rst) { Module::Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi, SPISettings spiSettings) { _cs = cs; - _rx = RADIOLIB_PIN_UNUSED; - _tx = RADIOLIB_PIN_UNUSED; + _rx = NC; + _tx = NC; _irq = irq; _rst = rst; _spi = &spi; @@ -28,7 +28,7 @@ Module::Module(int16_t cs, int16_t irq, int16_t rst, SPIClass& spi, SPISettings Module::Module(int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass& spi, SPISettings spiSettings) { _cs = cs; _rx = gpio; - _tx = RADIOLIB_PIN_UNUSED; + _tx = NC; _irq = irq; _rst = rst; _spi = &spi; @@ -205,10 +205,16 @@ 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); - RADIOLIB_VERBOSE_PRINT(reg | cmd, HEX); - RADIOLIB_VERBOSE_PRINT('\t'); - RADIOLIB_VERBOSE_PRINT(reg | cmd, BIN); - RADIOLIB_VERBOSE_PRINT('\t'); + #ifdef RADIOLIB_VERBOSE + if(cmd == SPIwriteCommand) { + RADIOLIB_VERBOSE_PRINT('W'); + } else if(cmd == SPIreadCommand) { + RADIOLIB_VERBOSE_PRINT('R'); + } + RADIOLIB_VERBOSE_PRINT('\t') + RADIOLIB_VERBOSE_PRINT(reg, HEX); + RADIOLIB_VERBOSE_PRINT('\t'); + #endif // send data or get response if(cmd == SPIwriteCommand) { @@ -216,16 +222,12 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da _spi->transfer(dataOut[n]); RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); RADIOLIB_VERBOSE_PRINT('\t'); - RADIOLIB_VERBOSE_PRINT(dataOut[n], BIN); - 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'); - RADIOLIB_VERBOSE_PRINT(dataIn[n], BIN); - RADIOLIB_VERBOSE_PRINT('\t'); } } RADIOLIB_VERBOSE_PRINTLN(); @@ -238,13 +240,13 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da } void Module::pinMode(int16_t pin, uint8_t mode) { - if(pin != RADIOLIB_PIN_UNUSED) { + if(pin != NC) { ::pinMode(pin, mode); } } void Module::digitalWrite(int16_t pin, uint8_t value) { - if(pin != RADIOLIB_PIN_UNUSED) { + if(pin != NC) { ::digitalWrite(pin, value); } } diff --git a/src/TypeDef.h b/src/TypeDef.h index 90b417c5..69ea2fc2 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -75,9 +75,11 @@ #endif /*! - \brief Alias for unused pin. + \brief Alias for unused pin, if not supplied by the Arduino core. */ -#define RADIOLIB_PIN_UNUSED (-1) +#ifndef NC +#define NC (-1) +#endif /*! \defgroup shield_config Shield Configuration diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index d9d7e048..6e3fc053 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -196,7 +196,7 @@ void CC1101::clearGdo0Action() { } void CC1101::setGdo2Action(void (*func)(void), uint8_t dir) { - if(_mod->getGpio() != RADIOLIB_PIN_UNUSED) { + if(_mod->getGpio() != NC) { return; } Module::pinMode(_mod->getGpio(), INPUT); @@ -204,7 +204,7 @@ void CC1101::setGdo2Action(void (*func)(void), uint8_t dir) { } void CC1101::clearGdo2Action() { - if(_mod->getGpio() != RADIOLIB_PIN_UNUSED) { + if(_mod->getGpio() != NC) { return; } detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 76150d4d..9f1b9544 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -268,7 +268,7 @@ void RF69::clearDio0Action() { } void RF69::setDio1Action(void (*func)(void)) { - if(_mod->getGpio() != RADIOLIB_PIN_UNUSED) { + if(_mod->getGpio() != NC) { return; } Module::pinMode(_mod->getGpio(), INPUT); @@ -276,7 +276,7 @@ void RF69::setDio1Action(void (*func)(void)) { } void RF69::clearDio1Action() { - if(_mod->getGpio() != RADIOLIB_PIN_UNUSED) { + if(_mod->getGpio() != NC) { return; } detachInterrupt(digitalPinToInterrupt(_mod->getGpio())); diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 3098f63e..60f63b2f 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -437,11 +437,14 @@ void SX127x::clearDio0Action() { } void SX127x::setDio1Action(void (*func)(void)) { + if(_mod->getGpio() != NC) { + return; + } attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, RISING); } void SX127x::clearDio1Action() { - if(_mod->getGpio() != RADIOLIB_PIN_UNUSED) { + if(_mod->getGpio() != NC) { return; } detachInterrupt(digitalPinToInterrupt(_mod->getGpio()));