# RadioLib: src/Hal.h Source File

Hal.h
#if !defined(_RADIOLIB_HAL_H)
#define _RADIOLIB_HAL_H
#include <stdint.h>
#include <stddef.h>
#include "BuildOpt.h"
class RadioLibHal {
public:
// values for pin modes, levels and change directions
// these tell RadioLib how are different logic states represented on a given platform
const uint32_t GpioModeInput;
const uint32_t GpioModeOutput;
const uint32_t GpioLevelLow;
const uint32_t GpioLevelHigh;
const uint32_t GpioInterruptRising;
const uint32_t GpioInterruptFalling;
RadioLibHal(const uint32_t input, const uint32_t output, const uint32_t low, const uint32_t high, const uint32_t rising, const uint32_t falling);
// pure virtual methods - these must be implemented by the hardware abstraction for RadioLib to function
virtual void pinMode(uint32_t pin, uint32_t mode) = 0;
virtual void digitalWrite(uint32_t pin, uint32_t value) = 0;
virtual uint32_t digitalRead(uint32_t pin) = 0;
virtual void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) = 0;
virtual void detachInterrupt(uint32_t interruptNum) = 0;
virtual void delay(RadioLibTime_t ms) = 0;
virtual void delayMicroseconds(RadioLibTime_t us) = 0;
virtual RadioLibTime_t millis() = 0;
virtual RadioLibTime_t micros() = 0;
virtual long pulseIn(uint32_t pin, uint32_t state, RadioLibTime_t timeout) = 0;
virtual void spiBegin() = 0;
virtual void spiBeginTransaction() = 0;
virtual void spiTransfer(uint8_t* out, size_t len, uint8_t* in) = 0;
virtual void spiEndTransaction() = 0;
virtual void spiEnd() = 0;
// virtual methods - these may or may not exists on a given platform
// they exist in this implementation, but do nothing
virtual void init();
virtual void term();
virtual void tone(uint32_t pin, unsigned int frequency, RadioLibTime_t duration = 0);
virtual void noTone(uint32_t pin);
virtual void yield();
virtual uint32_t pinToInterrupt(uint32_t pin);
};
#endif
RadioLibHal
Hardware abstraction library base interface.
Definition: Hal.h:13
RadioLibHal::GpioInterruptFalling
const uint32_t GpioInterruptFalling
Value to be used as the "falling" GPIO level change direction.
Definition: Hal.h:47
RadioLibHal::digitalRead
virtual uint32_t digitalRead(uint32_t pin)=0
Digital read method. Must be implemented by the platform-specific hardware abstraction!
RadioLibHal::GpioModeOutput
const uint32_t GpioModeOutput
Value to be used as the "output" GPIO direction.
Definition: Hal.h:27
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::GpioModeInput
const uint32_t GpioModeInput
Value to be used as the "input" GPIO direction.
Definition: Hal.h:22
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::GpioLevelLow
const uint32_t GpioLevelLow
Value to be used as the "low" GPIO level.
Definition: Hal.h:32
RadioLibHal::pulseIn
virtual long pulseIn(uint32_t pin, uint32_t state, RadioLibTime_t timeout)=0
Measure the length of incoming digital pulse in microseconds. Must be implemented by the platform-spe...
RadioLibHal::GpioLevelHigh
const uint32_t GpioLevelHigh
Value to be used as the "high" GPIO level.
Definition: Hal.h:37
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::millis
virtual RadioLibTime_t millis()=0
Get number of milliseconds since start. Must be implemented by the platform-specific hardware abstrac...
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::tone
virtual void tone(uint32_t pin, unsigned int frequency, RadioLibTime_t 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::micros
virtual RadioLibTime_t micros()=0
Get number of microseconds since start. Must be implemented by the platform-specific hardware abstrac...
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::GpioInterruptRising
const uint32_t GpioInterruptRising
Value to be used as the "rising" GPIO level change direction.
Definition: Hal.h:42
RadioLibHal::spiBegin
virtual void spiBegin()=0
SPI initialization method.
RadioLibHal::delay
virtual void delay(RadioLibTime_t ms)=0
Blocking wait function. Must be implemented by the platform-specific hardware abstraction!
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::delayMicroseconds
virtual void delayMicroseconds(RadioLibTime_t us)=0
Blocking microsecond wait function. Must be implemented by the platform-specific hardware abstraction...
RadioLibHal::spiBeginTransaction
virtual void spiBeginTransaction()=0
Method to start SPI transaction.
RadioLibHal::RadioLibHal
RadioLibHal(const uint32_t input, const uint32_t output, const uint32_t low, const uint32_t high, const uint32_t rising, const uint32_t falling)
Default constructor.
Definition: Hal.cpp:3
RadioLibHal::spiTransfer
virtual void spiTransfer(uint8_t *out, size_t len, uint8_t *in)=0
Method to transfer buffer over SPI.
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...
RadioLibTime_t
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition: TypeDef.h:586