[MOD] Fixed SPI callbacks on non-Arduino platforms (#725)
This commit is contained in:
parent
8587f73bd9
commit
9d36ae4bee
2 changed files with 7 additions and 25 deletions
|
@ -350,11 +350,11 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
this->digitalWrite(this->getCs(), LOW);
|
this->digitalWrite(this->getCs(), LOW);
|
||||||
|
|
||||||
// start transfer
|
// start transfer
|
||||||
this->SPIbeginTransaction();
|
this->beginTransaction();
|
||||||
|
|
||||||
// send command byte(s)
|
// send command byte(s)
|
||||||
for(uint8_t n = 0; n < cmdLen; n++) {
|
for(uint8_t n = 0; n < cmdLen; n++) {
|
||||||
this->SPItransfer(cmd[n]);
|
this->transfer(cmd[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// variable to save error during SPI transfer
|
// variable to save error during SPI transfer
|
||||||
|
@ -364,7 +364,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
if(write) {
|
if(write) {
|
||||||
for(size_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
// send byte
|
// send byte
|
||||||
uint8_t in = this->SPItransfer(dataOut[n]);
|
uint8_t in = this->transfer(dataOut[n]);
|
||||||
#if defined(RADIOLIB_VERBOSE)
|
#if defined(RADIOLIB_VERBOSE)
|
||||||
debugBuff[n] = in;
|
debugBuff[n] = in;
|
||||||
#endif
|
#endif
|
||||||
|
@ -377,7 +377,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// skip the first byte for read-type commands (status-only)
|
// skip the first byte for read-type commands (status-only)
|
||||||
uint8_t in = this->SPItransfer(this->SPInopCommand);
|
uint8_t in = this->transfer(this->SPInopCommand);
|
||||||
#if defined(RADIOLIB_VERBOSE)
|
#if defined(RADIOLIB_VERBOSE)
|
||||||
debugBuff[0] = in;
|
debugBuff[0] = in;
|
||||||
#endif
|
#endif
|
||||||
|
@ -392,13 +392,13 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
// read the data
|
// read the data
|
||||||
if(state == RADIOLIB_ERR_NONE) {
|
if(state == RADIOLIB_ERR_NONE) {
|
||||||
for(size_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
dataIn[n] = this->SPItransfer(this->SPInopCommand);
|
dataIn[n] = this->transfer(this->SPInopCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop transfer
|
// stop transfer
|
||||||
this->SPIendTransaction();
|
this->endTransaction();
|
||||||
this->digitalWrite(this->getCs(), HIGH);
|
this->digitalWrite(this->getCs(), HIGH);
|
||||||
|
|
||||||
// wait for GPIO to go high and then low
|
// wait for GPIO to go high and then low
|
||||||
|
@ -622,75 +622,57 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -663,10 +663,10 @@ class Module {
|
||||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||||
void SPIbegin();
|
void SPIbegin();
|
||||||
void SPIend();
|
void SPIend();
|
||||||
#endif
|
|
||||||
virtual void SPIbeginTransaction();
|
virtual void SPIbeginTransaction();
|
||||||
virtual uint8_t SPItransfer(uint8_t b);
|
virtual uint8_t SPItransfer(uint8_t b);
|
||||||
virtual void SPIendTransaction();
|
virtual void SPIendTransaction();
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Function to reflect bits within a byte.
|
\brief Function to reflect bits within a byte.
|
||||||
|
|
Loading…
Add table
Reference in a new issue