remedy Module when RADIOLIB_BUILD_ARDUINO is not defined

This commit is contained in:
Peter Lawrence 2022-08-04 17:46:58 -05:00
parent 8675f13e5d
commit 4bdec52f88
3 changed files with 28 additions and 5 deletions

View file

@ -886,6 +886,7 @@
#define RADIOLIB_PLATFORM "Generic" #define RADIOLIB_PLATFORM "Generic"
// platform properties may be defined here, or somewhere else in the build system // platform properties may be defined here, or somewhere else in the build system
#include "noarduino.h"
#endif #endif
@ -1019,11 +1020,11 @@
#define RADIOLIB_REST(arg, ...) __VA_ARGS__ #define RADIOLIB_REST(arg, ...) __VA_ARGS__
#define RADIOLIB_EXP(...) __VA_ARGS__ #define RADIOLIB_EXP(...) __VA_ARGS__
#define RADIOLIB_GENERATE_CALLBACK_RET_FUNC(RET, FUNC, ...) public: typedef RET (*FUNC##_cb_t)(__VA_ARGS__); void setCb_##FUNC(FUNC##_cb_t cb) { cb_##FUNC = cb; }; private: FUNC##_cb_t cb_##FUNC; #define RADIOLIB_GENERATE_CALLBACK_RET_FUNC(RET, FUNC, ...) public: typedef RET (*FUNC##_cb_t)(__VA_ARGS__); void setCb_##FUNC(FUNC##_cb_t cb) { cb_##FUNC = cb; }; private: FUNC##_cb_t cb_##FUNC = nullptr;
#define RADIOLIB_GENERATE_CALLBACK_RET(RET, ...) RADIOLIB_GENERATE_CALLBACK_RET_FUNC(RET, __VA_ARGS__) #define RADIOLIB_GENERATE_CALLBACK_RET(RET, ...) RADIOLIB_GENERATE_CALLBACK_RET_FUNC(RET, __VA_ARGS__)
#define RADIOLIB_GENERATE_CALLBACK(CB) RADIOLIB_GENERATE_CALLBACK_RET(RADIOLIB_EXP(RADIOLIB_FIRST CB), RADIOLIB_EXP(RADIOLIB_REST CB)) #define RADIOLIB_GENERATE_CALLBACK(CB) RADIOLIB_GENERATE_CALLBACK_RET(RADIOLIB_EXP(RADIOLIB_FIRST CB), RADIOLIB_EXP(RADIOLIB_REST CB))
#define RADIOLIB_GENERATE_CALLBACK_SPI_RET_FUNC(RET, FUNC, ...) public: typedef RET (Module::*FUNC##_cb_t)(__VA_ARGS__); void setCb_##FUNC(FUNC##_cb_t cb) { cb_##FUNC = cb; }; private: FUNC##_cb_t cb_##FUNC; #define RADIOLIB_GENERATE_CALLBACK_SPI_RET_FUNC(RET, FUNC, ...) public: typedef RET (Module::*FUNC##_cb_t)(__VA_ARGS__); void setCb_##FUNC(FUNC##_cb_t cb) { cb_##FUNC = cb; }; private: FUNC##_cb_t cb_##FUNC = nullptr;
#define RADIOLIB_GENERATE_CALLBACK_SPI_RET(RET, ...) RADIOLIB_GENERATE_CALLBACK_SPI_RET_FUNC(RET, __VA_ARGS__) #define RADIOLIB_GENERATE_CALLBACK_SPI_RET(RET, ...) RADIOLIB_GENERATE_CALLBACK_SPI_RET_FUNC(RET, __VA_ARGS__)
#define RADIOLIB_GENERATE_CALLBACK_SPI(CB) RADIOLIB_GENERATE_CALLBACK_SPI_RET(RADIOLIB_EXP(RADIOLIB_FIRST CB), RADIOLIB_EXP(RADIOLIB_REST CB)) #define RADIOLIB_GENERATE_CALLBACK_SPI(CB) RADIOLIB_GENERATE_CALLBACK_SPI_RET(RADIOLIB_EXP(RADIOLIB_FIRST CB), RADIOLIB_EXP(RADIOLIB_REST CB))

View file

@ -105,13 +105,16 @@ Module& Module::operator=(const Module& mod) {
void Module::init() { void Module::init() {
this->pinMode(_cs, OUTPUT); this->pinMode(_cs, OUTPUT);
this->digitalWrite(_cs, HIGH); this->digitalWrite(_cs, HIGH);
#if defined(RADIOLIB_BUILD_ARDUINO)
if(_initInterface) { if(_initInterface) {
(this->*cb_SPIbegin)(); (this->*cb_SPIbegin)();
} }
#endif
} }
void Module::term() { void Module::term() {
// stop hardware interfaces (if they were initialized by the library) // stop hardware interfaces (if they were initialized by the library)
#if defined(RADIOLIB_BUILD_ARDUINO)
if(!_initInterface) { if(!_initInterface) {
return; return;
} }
@ -119,6 +122,7 @@ void Module::term() {
if(_spi != nullptr) { if(_spi != nullptr) {
this->SPIend(); this->SPIend();
} }
#endif
} }
int16_t Module::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) { int16_t Module::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) {
@ -381,57 +385,75 @@ uint32_t Module::pulseIn(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS state, uint3
} }
void Module::begin() { void Module::begin() {
#if defined(RADIOLIB_BUILD_ARDUINO)
if(cb_SPIbegin == nullptr) { if(cb_SPIbegin == nullptr) {
return; return;
} }
(this->*cb_SPIbegin)(); (this->*cb_SPIbegin)();
#endif
} }
void Module::beginTransaction() { void Module::beginTransaction() {
#if defined(RADIOLIB_BUILD_ARDUINO)
if(cb_SPIbeginTransaction == nullptr) { if(cb_SPIbeginTransaction == nullptr) {
return; return;
} }
(this->*cb_SPIbeginTransaction)(); (this->*cb_SPIbeginTransaction)();
#endif
} }
uint8_t Module::transfer(uint8_t b) { uint8_t Module::transfer(uint8_t b) {
#if defined(RADIOLIB_BUILD_ARDUINO)
if(cb_SPItransfer == nullptr) { if(cb_SPItransfer == nullptr) {
return(0xFF); return(0xFF);
} }
return((this->*cb_SPItransfer)(b)); return((this->*cb_SPItransfer)(b));
#endif
} }
void Module::endTransaction() { void Module::endTransaction() {
#if defined(RADIOLIB_BUILD_ARDUINO)
if(cb_SPIendTransaction == nullptr) { if(cb_SPIendTransaction == nullptr) {
return; return;
} }
(this->*cb_SPIendTransaction)(); (this->*cb_SPIendTransaction)();
#endif
} }
void Module::end() { void Module::end() {
#if defined(RADIOLIB_BUILD_ARDUINO)
if(cb_SPIend == nullptr) { if(cb_SPIend == nullptr) {
return; return;
} }
(this->*cb_SPIend)(); (this->*cb_SPIend)();
#endif
} }
#if defined(RADIOLIB_BUILD_ARDUINO) #if defined(RADIOLIB_BUILD_ARDUINO)
void Module::SPIbegin() { void Module::SPIbegin() {
_spi->begin(); _spi->begin();
} }
#endif
void Module::SPIbeginTransaction() { void Module::SPIbeginTransaction() {
#if defined(RADIOLIB_BUILD_ARDUINO)
_spi->beginTransaction(_spiSettings); _spi->beginTransaction(_spiSettings);
#endif
} }
uint8_t Module::SPItransfer(uint8_t b) { uint8_t Module::SPItransfer(uint8_t b) {
#if defined(RADIOLIB_BUILD_ARDUINO)
return(_spi->transfer(b)); return(_spi->transfer(b));
#endif
} }
void Module::SPIendTransaction() { void Module::SPIendTransaction() {
#if defined(RADIOLIB_BUILD_ARDUINO)
_spi->endTransaction(); _spi->endTransaction();
#endif
} }
#if defined(RADIOLIB_BUILD_ARDUINO)
void Module::SPIend() { void Module::SPIend() {
_spi->end(); _spi->end();
} }

View file

@ -366,11 +366,11 @@ class Module {
// helper functions to set up SPI overrides on Arduino // helper functions to set up SPI overrides on Arduino
#if defined(RADIOLIB_BUILD_ARDUINO) #if defined(RADIOLIB_BUILD_ARDUINO)
void SPIbegin(); void SPIbegin();
virtual void SPIbeginTransaction();
uint8_t SPItransfer(uint8_t b);
virtual void SPIendTransaction();
void SPIend(); void SPIend();
#endif #endif
virtual void SPIbeginTransaction();
virtual uint8_t SPItransfer(uint8_t b);
virtual void SPIendTransaction();
/*! /*!
\brief Function to reflect bits within a byte. \brief Function to reflect bits within a byte.