RadioLib Universal wireless communication library for Arduino

ArduinoHal.h
1 // make sure this is always compiled
2 #include "TypeDef.h"
3
4 #if !defined(_RADIOLIB_ARDUINOHAL_H)
5 #define _RADIOLIB_ARDUINOHAL_H
6
7 // this file only makes sense for Arduino builds
8 #if defined(RADIOLIB_BUILD_ARDUINO)
9
10 #if defined(RADIOLIB_MBED_TONE_OVERRIDE)
11 #include "mbed.h"
12 #endif
13
14 #include "Hal.h"
15
16 #include <SPI.h>
17
23 class ArduinoHal : public RadioLibHal {
24 public:
28 ArduinoHal();
29
35 ArduinoHal(SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
36
37 // implementations of pure virtual RadioLibHal methods
38 void pinMode(uint32_t pin, uint32_t mode) override;
39 void digitalWrite(uint32_t pin, uint32_t value) override;
40 uint32_t digitalRead(uint32_t pin) override;
41 void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override;
42 void detachInterrupt(uint32_t interruptNum) override;
43 void delay(unsigned long ms) override;
44 void delayMicroseconds(unsigned long us) override;
45 unsigned long millis() override;
46 unsigned long micros() override;
47 long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override;
48 void spiBegin() override;
49 void spiBeginTransaction() override;
50 void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override;
51 void spiEndTransaction() override;
52 void spiEnd() override;
53
54 // implementations of virtual RadioLibHal methods
55 void init() override;
56 void term() override;
57 void tone(uint32_t pin, unsigned int frequency, unsigned long duration = 0) override;
58 void noTone(uint32_t pin) override;
59 void yield() override;
60 uint32_t pinToInterrupt(uint32_t pin) override;
61
62 #if !RADIOLIB_GODMODE
63 protected:
64 #endif
65 SPIClass* spi = NULL;
66 SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS;
67 bool initInterface = false;
68
69 #if defined(RADIOLIB_MBED_TONE_OVERRIDE)
70 mbed::PwmOut *pwmPin = NULL;
71 #endif
72
73 #if defined(RADIOLIB_ESP32)
74 int32_t prev = -1;
75 #endif
76 };
77
78 #endif
79
80 #endif
RadioLibHal
Hardware abstraction library base interface.
Definition: Hal.h:13
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::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::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...