LCOV - code coverage report
Current view: top level - src - Hal.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 1 1 100.0 %
Date: 2026-06-03 18:53:41 Functions: 1 2 50.0 %

          Line data    Source code
       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             : 
       9             : #include "utils/Cryptography.h"
      10             : 
      11             : /*! \brief Global-scope function that returns timestamp since start (in microseconds). */
      12             : RadioLibTime_t rlb_time_us();
      13             : 
      14             : /*!
      15             :   \class RadioLibHal
      16             :   \brief Hardware abstraction library base interface.
      17             : */
      18             : class RadioLibHal {
      19             :   public:
      20             : 
      21             :     // values for pin modes, levels and change directions
      22             :     // these tell RadioLib how are different logic states represented on a given platform
      23             : 
      24             :     /*!
      25             :       \brief Value to be used as the "input" GPIO direction.
      26             :     */
      27             :     const uint32_t GpioModeInput;
      28             : 
      29             :     /*!
      30             :       \brief Value to be used as the "output" GPIO direction.
      31             :     */
      32             :     const uint32_t GpioModeOutput;
      33             :     
      34             :     /*!
      35             :       \brief Value to be used as the "low" GPIO level.
      36             :     */
      37             :     const uint32_t GpioLevelLow;
      38             :     
      39             :     /*!
      40             :       \brief Value to be used as the "high" GPIO level.
      41             :     */
      42             :     const uint32_t GpioLevelHigh;
      43             :     
      44             :     /*!
      45             :       \brief Value to be used as the "rising" GPIO level change direction.
      46             :     */
      47             :     const uint32_t GpioInterruptRising;
      48             :     
      49             :     /*!
      50             :       \brief Value to be used as the "falling" GPIO level change direction.
      51             :     */
      52             :     const uint32_t GpioInterruptFalling;
      53             : 
      54             :     /*!
      55             :       \brief AES-128 engine instance to be used. When using platform with AES hardware acceleration,
      56             :       it is usually highly advantageous to use it instead of the default software implementation.
      57             :       With custom AES-128, set this pointer to an instance of that class.
      58             :       See the macro RADIOLIB_CUSTOM_AES128 in BuildOpt.h for details.
      59             :     */
      60             :     RadioLibAES128* aes128 = nullptr;
      61             : 
      62             :     /*!
      63             :       \brief Default constructor.
      64             :       \param input Value to be used as the "input" GPIO direction.
      65             :       \param output Value to be used as the "output" GPIO direction.
      66             :       \param low Value to be used as the "low" GPIO level.
      67             :       \param high Value to be used as the "high" GPIO level.
      68             :       \param rising Value to be used as the "rising" GPIO level change direction.
      69             :       \param falling Value to be used as the "falling" GPIO level change direction.
      70             :     */
      71             :     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);
      72             : 
      73             :     /*!
      74             :       \brief Default destructor.
      75             :     */
      76           7 :     virtual ~RadioLibHal() = default;
      77             : 
      78             :     // pure virtual methods - these must be implemented by the hardware abstraction for RadioLib to function
      79             : 
      80             :     /*!
      81             :       \brief GPIO pin mode (input/output/...) configuration method.
      82             :       Must be implemented by the platform-specific hardware abstraction!
      83             :       \param pin Pin to be changed (platform-specific).
      84             :       \param mode Mode to be set (platform-specific).
      85             :     */
      86             :     virtual void pinMode(uint32_t pin, uint32_t mode) = 0;
      87             : 
      88             :     /*!
      89             :       \brief Digital write method.
      90             :       Must be implemented by the platform-specific hardware abstraction!
      91             :       \param pin Pin to be changed (platform-specific).
      92             :       \param value Value to set (platform-specific).
      93             :     */
      94             :     virtual void digitalWrite(uint32_t pin, uint32_t value) = 0;
      95             : 
      96             :     /*!
      97             :       \brief Digital read method.
      98             :       Must be implemented by the platform-specific hardware abstraction!
      99             :       \param pin Pin to be changed (platform-specific).
     100             :       \returns Value read on the pin (platform-specific).
     101             :     */
     102             :     virtual uint32_t digitalRead(uint32_t pin) = 0;
     103             :     
     104             :     /*!
     105             :       \brief Method to attach function to an external interrupt.
     106             :       Must be implemented by the platform-specific hardware abstraction!
     107             :       \param interruptNum Interrupt number to attach to (platform-specific).
     108             :       \param interruptCb Interrupt service routine to execute.
     109             :       \param mode Rising/falling mode (platform-specific).
     110             :     */
     111             :     virtual void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) = 0;
     112             : 
     113             :     /*!
     114             :       \brief Method to detach function from an external interrupt.
     115             :       Must be implemented by the platform-specific hardware abstraction!
     116             :       \param interruptNum Interrupt number to detach from (platform-specific).
     117             :     */
     118             :     virtual void detachInterrupt(uint32_t interruptNum) = 0;
     119             : 
     120             :     /*!
     121             :       \brief Blocking wait function.
     122             :       Must be implemented by the platform-specific hardware abstraction!
     123             :       \param ms Number of milliseconds to wait.
     124             :     */
     125             :     virtual void delay(RadioLibTime_t ms) = 0;
     126             :     
     127             :     /*!
     128             :       \brief Blocking microsecond wait function.
     129             :       Must be implemented by the platform-specific hardware abstraction!
     130             :       \param us Number of microseconds to wait.
     131             :     */
     132             :     virtual void delayMicroseconds(RadioLibTime_t us) = 0;
     133             :     
     134             :     /*!
     135             :       \brief Get number of milliseconds since start.
     136             :       Must be implemented by the platform-specific hardware abstraction!
     137             :       \returns Number of milliseconds since start.
     138             :     */
     139             :     virtual RadioLibTime_t millis() = 0;
     140             :     
     141             :     /*!
     142             :       \brief Get number of microseconds since start.
     143             :       Must be implemented by the platform-specific hardware abstraction!
     144             :       \returns Number of microseconds since start.
     145             :     */
     146             :     virtual RadioLibTime_t micros() = 0;
     147             :     
     148             :     /*!
     149             :       \brief Measure the length of incoming digital pulse in microseconds.
     150             :       Must be implemented by the platform-specific hardware abstraction!
     151             :       \param pin Pin to measure on (platform-specific).
     152             :       \param state Pin level to monitor (platform-specific).
     153             :       \param timeout Timeout in microseconds.
     154             :       \returns Pulse length in microseconds, or 0 if the pulse did not start before timeout.
     155             :     */
     156             :     virtual long pulseIn(uint32_t pin, uint32_t state, RadioLibTime_t timeout) = 0;
     157             : 
     158             :     /*!
     159             :       \brief SPI initialization method.
     160             :     */
     161             :     virtual void spiBegin() = 0;
     162             : 
     163             :     /*!
     164             :       \brief Method to start SPI transaction.
     165             :     */
     166             :     virtual void spiBeginTransaction() = 0;
     167             : 
     168             :     /*!
     169             :       \brief Method to transfer buffer over SPI.
     170             :       \param out Buffer to send.
     171             :       \param len Number of data to send or receive.
     172             :       \param in Buffer to save received data into.
     173             :     */
     174             :     virtual void spiTransfer(uint8_t* out, size_t len, uint8_t* in) = 0;
     175             : 
     176             :     /*!
     177             :       \brief Method to end SPI transaction.
     178             :     */
     179             :     virtual void spiEndTransaction() = 0;
     180             : 
     181             :     /*!
     182             :       \brief SPI termination method.
     183             :     */
     184             :     virtual void spiEnd() = 0;
     185             : 
     186             :     // virtual methods - these may or may not exists on a given platform
     187             :     // they exist in this implementation, but do nothing
     188             : 
     189             :     /*!
     190             :       \brief Module initialization method.
     191             :       This will be called by all radio modules at the beginning of startup.
     192             :       Can be used to e.g., initialize SPI interface.
     193             :     */
     194             :     virtual void init();
     195             : 
     196             :     /*!
     197             :       \brief Module termination method.
     198             :       This will be called by all radio modules when the destructor is called.
     199             :       Can be used to e.g., stop SPI interface.
     200             :     */
     201             :     virtual void term();
     202             : 
     203             :     /*!
     204             :       \brief Method to produce a square-wave with 50% duty cycle ("tone") of a given frequency at some pin.
     205             :       \param pin Pin to be used as the output.
     206             :       \param frequency Frequency of the square wave.
     207             :       \param duration Duration of the tone in ms. When set to 0, the tone will be infinite.
     208             :     */
     209             :     virtual void tone(uint32_t pin, unsigned int frequency, RadioLibTime_t duration = 0);
     210             : 
     211             :     /*!
     212             :       \brief Method to stop producing a tone.
     213             :       \param pin Pin which is currently producing the tone.
     214             :     */
     215             :     virtual void noTone(uint32_t pin);
     216             :     
     217             :     /*!
     218             :       \brief Yield method, called from long loops in multi-threaded environment (to prevent blocking other threads).
     219             :     */
     220             :     virtual void yield();
     221             :     
     222             :     /*!
     223             :       \brief Function to convert from pin number to interrupt number.
     224             :       \param pin Pin to convert from.
     225             :       \returns The interrupt number of a given pin.
     226             :     */
     227             :     virtual uint32_t pinToInterrupt(uint32_t pin);
     228             : 
     229             :     /*!
     230             :       \brief Enable or disable pull up or pull down for a specific pin.
     231             :       \param pin Pin to change.
     232             :       \param enable True to enable, false to disable.
     233             :       \param up Pull direction, true for pull up, false for pull down.
     234             :     */
     235             :     virtual void pullUpDown(uint32_t pin, bool enable, bool up);
     236             : };
     237             : 
     238             : #endif

Generated by: LCOV version 1.14