# RadioLib: src/ArduinoHal.h Source File

ArduinoHal.h
// 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)
#include "mbed.h"
#endif
#include "Hal.h"
#include <SPI.h>
class ArduinoHal : public RadioLibHal {
public:
ArduinoHal();
ArduinoHal(SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
// 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;
void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override;
void detachInterrupt(uint32_t interruptNum) override;
void delay(unsigned long ms) override;
void delayMicroseconds(unsigned long us) override;
unsigned long millis() override;
unsigned long micros() override;
long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override;
void spiBegin() override;
void spiBeginTransaction() override;
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override;
void spiEndTransaction() override;
void spiEnd() override;
void readPersistentStorage(uint32_t addr, uint8_t* buff, size_t len) override;
void writePersistentStorage(uint32_t addr, uint8_t* buff, size_t len) 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;
uint32_t pinToInterrupt(uint32_t pin) override;
#if !defined(RADIOLIB_GODMODE)
private:
#endif
SPIClass* spi = NULL;
SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS;
bool initInterface = false;
#if defined(RADIOLIB_MBED_TONE_OVERRIDE)
mbed::PwmOut *pwmPin = NULL;
#endif
#if defined(ESP32)
int32_t prev = -1;
#endif
};
#endif
#endif
RadioLibHal
Hardware abstraction library base interface.
Definition: Hal.h:35
RadioLibHal::digitalRead
virtual uint32_t digitalRead(uint32_t pin)=0
Digital read method. Must be implemented by the platform-specific hardware abstraction!
RadioLibHal::yield
virtual void yield()
Yield method, called from long loops in multi-threaded environment (to prevent blocking other threads...
Definition: Hal.cpp:29
RadioLibHal::millis
virtual unsigned long millis()=0
Get number of milliseconds since start. Must be implemented by the platform-specific hardware abstrac...
RadioLibHal::detachInterrupt
virtual void detachInterrupt(uint32_t interruptNum)=0
Method to detach function from an external interrupt. Must be implemented by the platform-specific ha...
RadioLibHal::pinToInterrupt
virtual uint32_t pinToInterrupt(uint32_t pin)
Function to convert from pin number to interrupt number.
Definition: Hal.cpp:33
RadioLibHal::pulseIn
virtual long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout)=0
Measure the length of incoming digital pulse in microseconds. Must be implemented by the platform-spe...
RadioLibHal::spiEnd
virtual void spiEnd()=0
SPI termination method.
RadioLibHal::init
virtual void init()
Module initialization method. This will be called by all radio modules at the beginning of startup....
Definition: Hal.cpp:11
RadioLibHal::readPersistentStorage
virtual void readPersistentStorage(uint32_t addr, uint8_t *buff, size_t len)
Method to read from persistent storage (e.g. EEPROM).
Definition: Hal.cpp:37
RadioLibHal::digitalWrite
virtual void digitalWrite(uint32_t pin, uint32_t value)=0
Digital write method. Must be implemented by the platform-specific hardware abstraction!
RadioLibHal::spiEndTransaction
virtual void spiEndTransaction()=0
Method to end SPI transaction.
RadioLibHal::noTone
virtual void noTone(uint32_t pin)
Method to stop producing a tone.
Definition: Hal.cpp:25
RadioLibHal::delay
virtual void delay(unsigned long ms)=0
Blocking wait function. Must be implemented by the platform-specific hardware abstraction!
RadioLibHal::writePersistentStorage
virtual void writePersistentStorage(uint32_t addr, uint8_t *buff, size_t len)
Method to write to persistent storage (e.g. EEPROM).
Definition: Hal.cpp:44
RadioLibHal::spiBegin
virtual void spiBegin()=0
SPI initialization method.
RadioLibHal::term
virtual void term()
Module termination method. This will be called by all radio modules when the destructor is called....
Definition: Hal.cpp:15
RadioLibHal::tone
virtual void tone(uint32_t pin, unsigned int frequency, unsigned long duration=0)
Method to produce a square-wave with 50% duty cycle ("tone") of a given frequency at some pin.
Definition: Hal.cpp:19
RadioLibHal::spiBeginTransaction
virtual void spiBeginTransaction()=0
Method to start SPI transaction.
RadioLibHal::delayMicroseconds
virtual void delayMicroseconds(unsigned long us)=0
Blocking microsecond wait function. Must be implemented by the platform-specific hardware abstraction...
RadioLibHal::spiTransfer
virtual void spiTransfer(uint8_t *out, size_t len, uint8_t *in)=0
Method to transfer buffer over SPI.
RadioLibHal::micros
virtual unsigned long micros()=0
Get number of microseconds since start. Must be implemented by the platform-specific hardware abstrac...
RadioLibHal::pinMode
virtual void pinMode(uint32_t pin, uint32_t mode)=0
GPIO pin mode (input/output/...) configuration method. Must be implemented by the platform-specific h...
RadioLibHal::attachInterrupt
virtual void attachInterrupt(uint32_t interruptNum, void(*interruptCb)(void), uint32_t mode)=0
Method to attach function to an external interrupt. Must be implemented by the platform-specific hard...