[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)
|
||||
|
||||
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() {
|
||||
if(_initInterface) {
|
||||
|
@ -19,128 +19,147 @@ void ArduinoHal::term() {
|
|||
}
|
||||
|
||||
void inline ArduinoHal::pinMode(uint32_t pin, uint32_t mode) {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::pinMode(pin, RADIOLIB_ARDUINOHAL_PIN_MODE_CAST mode);
|
||||
}
|
||||
|
||||
void inline ArduinoHal::digitalWrite(uint32_t pin, uint32_t value) {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::digitalWrite(pin, RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST value);
|
||||
}
|
||||
|
||||
uint32_t inline ArduinoHal::digitalRead(uint32_t pin) {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return 0;
|
||||
}
|
||||
return ::digitalRead(pin);
|
||||
return(::digitalRead(pin));
|
||||
}
|
||||
|
||||
void inline ArduinoHal::attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) {
|
||||
if (interruptNum == RADIOLIB_NC) {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::attachInterrupt(interruptNum, interruptCb, RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST mode);
|
||||
}
|
||||
|
||||
void inline ArduinoHal::detachInterrupt(uint32_t interruptNum) {
|
||||
if (interruptNum == RADIOLIB_NC) {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::detachInterrupt(interruptNum);
|
||||
}
|
||||
|
||||
void inline ArduinoHal::delay(unsigned long ms) {
|
||||
::delay(ms);
|
||||
}
|
||||
|
||||
void inline ArduinoHal::delayMicroseconds(unsigned long us) {
|
||||
::delayMicroseconds(us);
|
||||
}
|
||||
|
||||
unsigned long inline ArduinoHal::millis() {
|
||||
return ::millis();
|
||||
return(::millis());
|
||||
}
|
||||
|
||||
unsigned long inline ArduinoHal::micros() {
|
||||
return ::micros();
|
||||
return(::micros());
|
||||
}
|
||||
|
||||
long inline ArduinoHal::pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return 0;
|
||||
}
|
||||
return ::pulseIn(pin, state, timeout);
|
||||
return(::pulseIn(pin, state, timeout));
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiBegin() {
|
||||
_spi->begin();
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiBeginTransaction() {
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
}
|
||||
|
||||
uint8_t inline ArduinoHal::spiTransfer(uint8_t b) {
|
||||
return _spi->transfer(b);
|
||||
return(_spi->transfer(b));
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiEndTransaction() {
|
||||
_spi->endTransaction();
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiEnd() {
|
||||
_spi->end();
|
||||
}
|
||||
|
||||
void inline ArduinoHal::tone(uint32_t pin, unsigned int frequency, unsigned long duration) {
|
||||
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::tone(pin, frequency, duration);
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::tone(pin, frequency, duration);
|
||||
#elif defined(ESP32)
|
||||
// ESP32 tone() emulation
|
||||
(void)duration;
|
||||
if(_prev == -1) {
|
||||
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
|
||||
}
|
||||
if(_prev != frequency) {
|
||||
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, frequency);
|
||||
}
|
||||
_prev = frequency;
|
||||
// ESP32 tone() emulation
|
||||
(void)duration;
|
||||
if(_prev == -1) {
|
||||
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
|
||||
}
|
||||
if(_prev != frequency) {
|
||||
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, frequency);
|
||||
}
|
||||
_prev = frequency;
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
// better tone for mbed OS boards
|
||||
(void)duration;
|
||||
if(!pwmPin) {
|
||||
pwmPin = new mbed::PwmOut(digitalPinToPinName(pin));
|
||||
}
|
||||
pwmPin->period(1.0 / frequency);
|
||||
pwmPin->write(0.5);
|
||||
// better tone for mbed OS boards
|
||||
(void)duration;
|
||||
if(!pwmPin) {
|
||||
pwmPin = new mbed::PwmOut(digitalPinToPinName(pin));
|
||||
}
|
||||
pwmPin->period(1.0 / frequency);
|
||||
pwmPin->write(0.5);
|
||||
#endif
|
||||
}
|
||||
|
||||
void inline ArduinoHal::noTone(uint32_t pin) {
|
||||
#if !defined(RADIOLIB_TONE_UNSUPPORTED) and defined(ARDUINO_ARCH_STM32)
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::noTone(pin, false);
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::noTone(pin, false);
|
||||
#elif !defined(RADIOLIB_TONE_UNSUPPORTED)
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::noTone(pin);
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::noTone(pin);
|
||||
#elif defined(ESP32)
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
// ESP32 tone() emulation
|
||||
ledcDetachPin(pin);
|
||||
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
|
||||
_prev = -1;
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
// ESP32 tone() emulation
|
||||
ledcDetachPin(pin);
|
||||
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
|
||||
_prev = -1;
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
// better tone for mbed OS boards
|
||||
(void)pin;
|
||||
pwmPin->suspend();
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
// better tone for mbed OS boards
|
||||
(void)pin;
|
||||
pwmPin->suspend();
|
||||
#endif
|
||||
}
|
||||
|
||||
void inline ArduinoHal::yield() {
|
||||
#if !defined(RADIOLIB_YIELD_UNSUPPORTED)
|
||||
::yield();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t inline ArduinoHal::pinToInterrupt(uint32_t pin) {
|
||||
return digitalPinToInterrupt(pin);
|
||||
return(digitalPinToInterrupt(pin));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
// make sure this is always compiled
|
||||
#include "TypeDef.h"
|
||||
|
||||
#if !defined(_RADIOLIB_ARDUINOHAL_H)
|
||||
#define _RADIOLIB_ARDUINOHAL_H
|
||||
|
||||
// this file only makes sense for Arduino builds
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
|
||||
#if defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
|
@ -10,7 +12,7 @@
|
|||
#endif
|
||||
|
||||
#include "Hal.h"
|
||||
#include <stdint.h>
|
||||
//#include <stdint.h>
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
|
@ -18,9 +20,9 @@
|
|||
\class ArduinoHal
|
||||
|
||||
\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:
|
||||
/*!
|
||||
\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.
|
||||
|
||||
\param spi SPI interface to be used, can also use software SPI implementations.
|
||||
|
||||
\param spiSettings SPI interface settings.
|
||||
*/
|
||||
ArduinoHal(SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
|
||||
|
||||
void init() override;
|
||||
void term() override;
|
||||
|
||||
// implementations of pure virtual RadioLibHal methods
|
||||
void pinMode(uint32_t pin, uint32_t mode) override;
|
||||
void digitalWrite(uint32_t pin, uint32_t value) override;
|
||||
uint32_t digitalRead(uint32_t pin) override;
|
||||
|
@ -54,6 +52,10 @@ class ArduinoHal : public Hal {
|
|||
uint8_t spiTransfer(uint8_t b) override;
|
||||
void spiEndTransaction() 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 noTone(uint32_t pin) override;
|
||||
void yield() override;
|
||||
|
@ -76,4 +78,5 @@ class ArduinoHal : public Hal {
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue