From 1e1a7173bf0f760a28a9bf1f60e22d83a7d1ea77 Mon Sep 17 00:00:00 2001 From: Elias Santistevan Date: Fri, 2 Oct 2020 13:54:03 -0600 Subject: [PATCH] Replaces the ridiculous #define to set the correct bitorder depending on the hardware used * Instead we're using instantiating SPISettings correctly and passing arguments depending on hardware. * rolls version --- library.properties | 2 +- src/SparkFun_AS3935.cpp | 8 ++++---- src/SparkFun_AS3935.h | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/library.properties b/library.properties index 95b4f5b..d2ecb57 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name= SparkFun AS3935 Lightning Detector Arduino Library -version=1.4.2 +version=1.4.3 author=Elias Santistevan maintainer=SparkFun Electronics sentence=This is an Arduino Library for the AS3935 Lightning Detector by AMS diff --git a/src/SparkFun_AS3935.cpp b/src/SparkFun_AS3935.cpp index 512be9f..f2206e9 100644 --- a/src/SparkFun_AS3935.cpp +++ b/src/SparkFun_AS3935.cpp @@ -52,9 +52,9 @@ bool SparkFun_AS3935::beginSPI(uint8_t user_CSPin, uint32_t spiPortSpeed, SPICla // Bit order is different for ESP32 #ifdef ESP32 -#define _bitOrder SPI_MSBFIRST +mySpiSettings = SPISettings(spiPortSpeed, SPI_MSBFIRST, SPI_MODE1); #else -#define _bitOrder MSBFIRST +mySpiSettings = SPISettings(spiPortSpeed, MSBFIRST, SPI_MODE1); #endif return true; @@ -464,7 +464,7 @@ void SparkFun_AS3935::_writeRegister(uint8_t _wReg, uint8_t _mask, uint8_t _bits _spiWrite = _readRegister(_wReg); // Get the current value of the register _spiWrite &= _mask; // Mask the position we want to write to _spiWrite |= (_bits << _startPosition); // Write the given bits to the variable - _spiPort->beginTransaction(SPISettings(_spiPortSpeed, _bitOrder, SPI_MODE1)); + _spiPort->beginTransaction(mySpiSettings); digitalWrite(_cs, LOW); // Start communication _spiPort->transfer(_wReg); // Start write command at given register _spiPort->transfer(_spiWrite); // Write to register @@ -487,7 +487,7 @@ uint8_t SparkFun_AS3935::_readRegister(uint8_t _reg) { if(_i2cPort == NULL) { - _spiPort->beginTransaction(SPISettings(_spiPortSpeed, _bitOrder, SPI_MODE1)); + _spiPort->beginTransaction(mySpiSettings); digitalWrite(_cs, LOW); // Start communication. _spiPort->transfer(_reg |= SPI_READ_M); // Register OR'ed with SPI read command. _regValue = _spiPort->transfer(0); // Get data from register. diff --git a/src/SparkFun_AS3935.h b/src/SparkFun_AS3935.h index 3f9e2d0..276a8c2 100644 --- a/src/SparkFun_AS3935.h +++ b/src/SparkFun_AS3935.h @@ -5,6 +5,8 @@ #include #include + + typedef uint8_t i2cAddress; const i2cAddress defAddr = 0x03; // Default ADD0 and ADD1 are HIGH @@ -235,6 +237,8 @@ class SparkFun_AS3935 uint8_t _regValue; // Variable for returned register data. uint8_t _spiWrite; // Variable used for SPI write commands. uint8_t _i2cWrite; // Variable used for SPI write commands. + + SPISettings mySpiSettings; // Address variable. i2cAddress _address;