[HAL] Fixed formatting
This commit is contained in:
parent
d5fe5e3e2d
commit
37bb8af768
2 changed files with 85 additions and 63 deletions
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||||
|
|
||||||
ArduinoHal::ArduinoHal(SPIClass& spi, SPISettings spiSettings): Hal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING), _spi(&spi), _spiSettings(spiSettings) {}
|
ArduinoHal::ArduinoHal(): RadioLibHal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING), _spi(&RADIOLIB_DEFAULT_SPI), _initInterface(true) {}
|
||||||
|
|
||||||
ArduinoHal::ArduinoHal(): Hal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING), _spi(&RADIOLIB_DEFAULT_SPI), _initInterface(true) {}
|
ArduinoHal::ArduinoHal(SPIClass& spi, SPISettings spiSettings): RadioLibHal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING), _spi(&spi), _spiSettings(spiSettings) {}
|
||||||
|
|
||||||
void ArduinoHal::init() {
|
void ArduinoHal::init() {
|
||||||
if(_initInterface) {
|
if(_initInterface) {
|
||||||
|
@ -19,128 +19,147 @@ void ArduinoHal::term() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::pinMode(uint32_t pin, uint32_t mode) {
|
void inline ArduinoHal::pinMode(uint32_t pin, uint32_t mode) {
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::pinMode(pin, RADIOLIB_ARDUINOHAL_PIN_MODE_CAST mode);
|
::pinMode(pin, RADIOLIB_ARDUINOHAL_PIN_MODE_CAST mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::digitalWrite(uint32_t pin, uint32_t value) {
|
void inline ArduinoHal::digitalWrite(uint32_t pin, uint32_t value) {
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::digitalWrite(pin, RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST value);
|
::digitalWrite(pin, RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST value);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t inline ArduinoHal::digitalRead(uint32_t pin) {
|
uint32_t inline ArduinoHal::digitalRead(uint32_t pin) {
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ::digitalRead(pin);
|
return(::digitalRead(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) {
|
void inline ArduinoHal::attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) {
|
||||||
if (interruptNum == RADIOLIB_NC) {
|
if(interruptNum == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::attachInterrupt(interruptNum, interruptCb, RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST mode);
|
::attachInterrupt(interruptNum, interruptCb, RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::detachInterrupt(uint32_t interruptNum) {
|
void inline ArduinoHal::detachInterrupt(uint32_t interruptNum) {
|
||||||
if (interruptNum == RADIOLIB_NC) {
|
if(interruptNum == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::detachInterrupt(interruptNum);
|
::detachInterrupt(interruptNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::delay(unsigned long ms) {
|
void inline ArduinoHal::delay(unsigned long ms) {
|
||||||
::delay(ms);
|
::delay(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::delayMicroseconds(unsigned long us) {
|
void inline ArduinoHal::delayMicroseconds(unsigned long us) {
|
||||||
::delayMicroseconds(us);
|
::delayMicroseconds(us);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long inline ArduinoHal::millis() {
|
unsigned long inline ArduinoHal::millis() {
|
||||||
return ::millis();
|
return(::millis());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long inline ArduinoHal::micros() {
|
unsigned long inline ArduinoHal::micros() {
|
||||||
return ::micros();
|
return(::micros());
|
||||||
}
|
}
|
||||||
|
|
||||||
long inline ArduinoHal::pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) {
|
long inline ArduinoHal::pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) {
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ::pulseIn(pin, state, timeout);
|
return(::pulseIn(pin, state, timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::spiBegin() {
|
void inline ArduinoHal::spiBegin() {
|
||||||
_spi->begin();
|
_spi->begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::spiBeginTransaction() {
|
void inline ArduinoHal::spiBeginTransaction() {
|
||||||
_spi->beginTransaction(_spiSettings);
|
_spi->beginTransaction(_spiSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t inline ArduinoHal::spiTransfer(uint8_t b) {
|
uint8_t inline ArduinoHal::spiTransfer(uint8_t b) {
|
||||||
return _spi->transfer(b);
|
return(_spi->transfer(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::spiEndTransaction() {
|
void inline ArduinoHal::spiEndTransaction() {
|
||||||
_spi->endTransaction();
|
_spi->endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::spiEnd() {
|
void inline ArduinoHal::spiEnd() {
|
||||||
_spi->end();
|
_spi->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::tone(uint32_t pin, unsigned int frequency, unsigned long duration) {
|
void inline ArduinoHal::tone(uint32_t pin, unsigned int frequency, unsigned long duration) {
|
||||||
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
|
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::tone(pin, frequency, duration);
|
::tone(pin, frequency, duration);
|
||||||
#elif defined(ESP32)
|
#elif defined(ESP32)
|
||||||
// ESP32 tone() emulation
|
// ESP32 tone() emulation
|
||||||
(void)duration;
|
(void)duration;
|
||||||
if(_prev == -1) {
|
if(_prev == -1) {
|
||||||
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
|
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
|
||||||
}
|
}
|
||||||
if(_prev != frequency) {
|
if(_prev != frequency) {
|
||||||
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, frequency);
|
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, frequency);
|
||||||
}
|
}
|
||||||
_prev = frequency;
|
_prev = frequency;
|
||||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||||
// better tone for mbed OS boards
|
// better tone for mbed OS boards
|
||||||
(void)duration;
|
(void)duration;
|
||||||
if(!pwmPin) {
|
if(!pwmPin) {
|
||||||
pwmPin = new mbed::PwmOut(digitalPinToPinName(pin));
|
pwmPin = new mbed::PwmOut(digitalPinToPinName(pin));
|
||||||
}
|
}
|
||||||
pwmPin->period(1.0 / frequency);
|
pwmPin->period(1.0 / frequency);
|
||||||
pwmPin->write(0.5);
|
pwmPin->write(0.5);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::noTone(uint32_t pin) {
|
void inline ArduinoHal::noTone(uint32_t pin) {
|
||||||
#if !defined(RADIOLIB_TONE_UNSUPPORTED) and defined(ARDUINO_ARCH_STM32)
|
#if !defined(RADIOLIB_TONE_UNSUPPORTED) and defined(ARDUINO_ARCH_STM32)
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::noTone(pin, false);
|
::noTone(pin, false);
|
||||||
#elif !defined(RADIOLIB_TONE_UNSUPPORTED)
|
#elif !defined(RADIOLIB_TONE_UNSUPPORTED)
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::noTone(pin);
|
::noTone(pin);
|
||||||
#elif defined(ESP32)
|
#elif defined(ESP32)
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// ESP32 tone() emulation
|
// ESP32 tone() emulation
|
||||||
ledcDetachPin(pin);
|
ledcDetachPin(pin);
|
||||||
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
|
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
|
||||||
_prev = -1;
|
_prev = -1;
|
||||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||||
if (pin == RADIOLIB_NC) {
|
if(pin == RADIOLIB_NC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// better tone for mbed OS boards
|
// better tone for mbed OS boards
|
||||||
(void)pin;
|
(void)pin;
|
||||||
pwmPin->suspend();
|
pwmPin->suspend();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline ArduinoHal::yield() {
|
void inline ArduinoHal::yield() {
|
||||||
#if !defined(RADIOLIB_YIELD_UNSUPPORTED)
|
#if !defined(RADIOLIB_YIELD_UNSUPPORTED)
|
||||||
::yield();
|
::yield();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t inline ArduinoHal::pinToInterrupt(uint32_t pin) {
|
uint32_t inline ArduinoHal::pinToInterrupt(uint32_t pin) {
|
||||||
return digitalPinToInterrupt(pin);
|
return(digitalPinToInterrupt(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
// make sure this is always compiled
|
||||||
#include "TypeDef.h"
|
#include "TypeDef.h"
|
||||||
|
|
||||||
#if !defined(_RADIOLIB_ARDUINOHAL_H)
|
#if !defined(_RADIOLIB_ARDUINOHAL_H)
|
||||||
#define _RADIOLIB_ARDUINOHAL_H
|
#define _RADIOLIB_ARDUINOHAL_H
|
||||||
|
|
||||||
|
// this file only makes sense for Arduino builds
|
||||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||||
|
|
||||||
#if defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
#if defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||||
|
@ -10,7 +12,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Hal.h"
|
#include "Hal.h"
|
||||||
#include <stdint.h>
|
//#include <stdint.h>
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
|
@ -18,9 +20,9 @@
|
||||||
\class ArduinoHal
|
\class ArduinoHal
|
||||||
|
|
||||||
\brief Arduino default hardware abstraction library implementation.
|
\brief Arduino default hardware abstraction library implementation.
|
||||||
This class can be extended to support other Arduino platform or change behaviour of the default implementation
|
This class can be extended to support other Arduino platform or change behaviour of the default implementation.
|
||||||
*/
|
*/
|
||||||
class ArduinoHal : public Hal {
|
class ArduinoHal : public RadioLibHal {
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
\brief Arduino Hal constructor. Will use the default SPI interface and automatically initialize it.
|
\brief Arduino Hal constructor. Will use the default SPI interface and automatically initialize it.
|
||||||
|
@ -29,16 +31,12 @@ class ArduinoHal : public Hal {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Arduino Hal constructor. Will not attempt SPI interface initialization.
|
\brief Arduino Hal constructor. Will not attempt SPI interface initialization.
|
||||||
|
|
||||||
\param spi SPI interface to be used, can also use software SPI implementations.
|
\param spi SPI interface to be used, can also use software SPI implementations.
|
||||||
|
|
||||||
\param spiSettings SPI interface settings.
|
\param spiSettings SPI interface settings.
|
||||||
*/
|
*/
|
||||||
ArduinoHal(SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
|
ArduinoHal(SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
|
||||||
|
|
||||||
void init() override;
|
// implementations of pure virtual RadioLibHal methods
|
||||||
void term() override;
|
|
||||||
|
|
||||||
void pinMode(uint32_t pin, uint32_t mode) override;
|
void pinMode(uint32_t pin, uint32_t mode) override;
|
||||||
void digitalWrite(uint32_t pin, uint32_t value) override;
|
void digitalWrite(uint32_t pin, uint32_t value) override;
|
||||||
uint32_t digitalRead(uint32_t pin) override;
|
uint32_t digitalRead(uint32_t pin) override;
|
||||||
|
@ -54,6 +52,10 @@ class ArduinoHal : public Hal {
|
||||||
uint8_t spiTransfer(uint8_t b) override;
|
uint8_t spiTransfer(uint8_t b) override;
|
||||||
void spiEndTransaction() override;
|
void spiEndTransaction() override;
|
||||||
void spiEnd() override;
|
void spiEnd() override;
|
||||||
|
|
||||||
|
// implementations of virtual RadioLibHal methods
|
||||||
|
void init() override;
|
||||||
|
void term() override;
|
||||||
void tone(uint32_t pin, unsigned int frequency, unsigned long duration = 0) override;
|
void tone(uint32_t pin, unsigned int frequency, unsigned long duration = 0) override;
|
||||||
void noTone(uint32_t pin) override;
|
void noTone(uint32_t pin) override;
|
||||||
void yield() override;
|
void yield() override;
|
||||||
|
@ -76,4 +78,5 @@ class ArduinoHal : public Hal {
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue