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
11 class RadioLibHal {
12 public:
13
14 // values for pin modes, levels and change directions
15 // these tell RadioLib how are different logic states represented on a given platform
16
20 const uint32_t GpioModeInput;
21
25 const uint32_t GpioModeOutput;
26
30 const uint32_t GpioLevelLow;
31
35 const uint32_t GpioLevelHigh;
36
40 const uint32_t GpioInterruptRising;
41
45 const uint32_t GpioInterruptFalling;
46
56 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);
57
58 // pure virtual methods - these must be implemented by the hardware abstraction for RadioLib to function
59
66 virtual void pinMode(uint32_t pin, uint32_t mode) = 0;
67
74 virtual void digitalWrite(uint32_t pin, uint32_t value) = 0;
75
82 virtual uint32_t digitalRead(uint32_t pin) = 0;
83
91 virtual void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) = 0;
92
98 virtual void detachInterrupt(uint32_t interruptNum) = 0;
99
105 virtual void delay(unsigned long ms) = 0;
106
112 virtual void delayMicroseconds(unsigned long us) = 0;
113
119 virtual unsigned long millis() = 0;
120
126 virtual unsigned long micros() = 0;
127
136 virtual long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) = 0;
137
141 virtual void spiBegin() = 0;
142
146 virtual void spiBeginTransaction() = 0;
147
153 virtual uint8_t spiTransfer(uint8_t b) = 0;
154
158 virtual void spiEndTransaction() = 0;
159
163 virtual void spiEnd() = 0;
164
165 // virtual methods - these may or may not exists on a given platform
166 // they exist in this implementation, but do nothing
167
173 virtual void init();
174
180 virtual void term();
181
188 virtual void tone(uint32_t pin, unsigned int frequency, unsigned long duration = 0);
189
194 virtual void noTone(uint32_t pin);
195
199 virtual void yield();
200
206 virtual uint32_t pinToInterrupt(uint32_t pin);
207 };
208
209 #endif
RadioLibHal
Definition: Hal.h:11
RadioLibHal::GpioInterruptFalling
const uint32_t GpioInterruptFalling
Value to be used as the "falling" GPIO level change direction.
Definition: Hal.h:45
RadioLibHal::digitalRead
virtual uint32_t digitalRead(uint32_t pin)=0
Digital read method. Must be implemented by the platform-specific hardware abstraction!
RadioLibHal::spiTransfer
virtual uint8_t spiTransfer(uint8_t b)=0
Method to transfer one byte over SPI.
RadioLibHal::GpioModeOutput
const uint32_t GpioModeOutput
Value to be used as the "output" GPIO direction.
Definition: Hal.h:25
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:20
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:30
RadioLibHal::GpioLevelHigh
const uint32_t GpioLevelHigh
Value to be used as the "high" GPIO level.
Definition: Hal.h:35
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:40
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 desctructor 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::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...