RadioLib Universal wireless communication library for Arduino

Hal.h
1 #if !defined(_RADIOLIB_HAL_H)
2 #define _RADIOLIB_HAL_H
3
4 #include <stdint.h>
5 #include <stddef.h>
6
7 #include "BuildOpt.h"
8
13 class RadioLibHal {
14 public:
15
16 // values for pin modes, levels and change directions
17 // these tell RadioLib how are different logic states represented on a given platform
18
22 const uint32_t GpioModeInput;
23
27 const uint32_t GpioModeOutput;
28
32 const uint32_t GpioLevelLow;
33
37 const uint32_t GpioLevelHigh;
38
42 const uint32_t GpioInterruptRising;
43
47 const uint32_t GpioInterruptFalling;
48
58 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);
59
60 // pure virtual methods - these must be implemented by the hardware abstraction for RadioLib to function
61
68 virtual void pinMode(uint32_t pin, uint32_t mode) = 0;
69
76 virtual void digitalWrite(uint32_t pin, uint32_t value) = 0;
77
84 virtual uint32_t digitalRead(uint32_t pin) = 0;
85
93 virtual void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) = 0;
94
100 virtual void detachInterrupt(uint32_t interruptNum) = 0;
101
107 virtual void delay(unsigned long ms) = 0;
108
114 virtual void delayMicroseconds(unsigned long us) = 0;
115
121 virtual unsigned long millis() = 0;
122
128 virtual unsigned long micros() = 0;
129
138 virtual long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) = 0;
139
143 virtual void spiBegin() = 0;
144
148 virtual void spiBeginTransaction() = 0;
149
156 virtual void spiTransfer(uint8_t* out, size_t len, uint8_t* in) = 0;
157
161 virtual void spiEndTransaction() = 0;
162
166 virtual void spiEnd() = 0;
167
168 // virtual methods - these may or may not exists on a given platform
169 // they exist in this implementation, but do nothing
170
176 virtual void init();
177
183 virtual void term();
184
191 virtual void tone(uint32_t pin, unsigned int frequency, unsigned long duration = 0);
192
197 virtual void noTone(uint32_t pin);
198
202 virtual void yield();
203
209 virtual uint32_t pinToInterrupt(uint32_t pin);
210 };
211
212 #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::millis
virtual unsigned long millis()=0
Get number of milliseconds since start. Must be implemented by the platform-specific hardware abstrac...
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::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::GpioLevelLow
const uint32_t GpioLevelLow
Value to be used as the "low" GPIO level.
Definition: Hal.h:32
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::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::GpioInterruptRising
const uint32_t GpioInterruptRising
Value to be used as the "rising" GPIO level change direction.
Definition: Hal.h:42
RadioLibHal::delay
virtual void delay(unsigned long ms)=0
Blocking wait function. Must be implemented by the platform-specific hardware abstraction!
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::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::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...