LoRa node acquiring analog input and sending to LoRa Server - Working ok
Dependents: DISCO-L072CZ-LRWAN1_LoRa_node EIoT_LoRa_node_1 EIoT_LoRa_node_2 EIoT_LoRa_node_3
Fork of SX1276GenericLib by
sx1276/sx1276-arduino-hal.h@46:e78a1d0391ac, 2017-05-11 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Thu May 11 10:11:13 2017 +0200
- Revision:
- 46:e78a1d0391ac
- Parent:
- 40:0165543c0986
- Child:
- 52:4d304485eda0
Updated LoRa_TODO.txt
Added template code to the Arduino HAL files
Change DigitalInOut to DigitalOut for the antenna switch
Added README.md file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut Tschemernjak | 40:0165543c0986 | 1 | |
Helmut Tschemernjak | 40:0165543c0986 | 2 | /* |
Helmut Tschemernjak | 40:0165543c0986 | 3 | * This file contains a copy of the master content sx1276-mbed-hal.h |
Helmut Tschemernjak | 40:0165543c0986 | 4 | * with adaption for the Arduino environment |
Helmut Tschemernjak | 40:0165543c0986 | 5 | * (c) 2017 Helmut Tschemernjak |
Helmut Tschemernjak | 40:0165543c0986 | 6 | * 30826 Garbsen (Hannover) Germany |
Helmut Tschemernjak | 40:0165543c0986 | 7 | */ |
Helmut Tschemernjak | 40:0165543c0986 | 8 | #ifdef ARDUINO |
Helmut Tschemernjak | 40:0165543c0986 | 9 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 10 | /* |
Helmut Tschemernjak | 46:e78a1d0391ac | 11 | (C) 2014 Semtech |
Helmut Tschemernjak | 46:e78a1d0391ac | 12 | Description: - |
Helmut Tschemernjak | 46:e78a1d0391ac | 13 | License: Revised BSD License, see LICENSE.TXT file include in the project |
Helmut Tschemernjak | 46:e78a1d0391ac | 14 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
Helmut Tschemernjak | 46:e78a1d0391ac | 15 | */ |
Helmut Tschemernjak | 40:0165543c0986 | 16 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 17 | /* |
Helmut Tschemernjak | 46:e78a1d0391ac | 18 | * additional development to make it more generic across multiple OS versions |
Helmut Tschemernjak | 46:e78a1d0391ac | 19 | * (c) 2017 Helmut Tschemernjak |
Helmut Tschemernjak | 46:e78a1d0391ac | 20 | * 30826 Garbsen (Hannover) Germany |
Helmut Tschemernjak | 46:e78a1d0391ac | 21 | */ |
Helmut Tschemernjak | 40:0165543c0986 | 22 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 23 | #ifndef __SX1276_ARDUINO_HAL_H__ |
Helmut Tschemernjak | 46:e78a1d0391ac | 24 | #define __SX1276_ARDUINO_HAL_H__ |
Helmut Tschemernjak | 46:e78a1d0391ac | 25 | #include "sx1276.h" |
Helmut Tschemernjak | 40:0165543c0986 | 26 | |
Helmut Tschemernjak | 40:0165543c0986 | 27 | |
Helmut Tschemernjak | 40:0165543c0986 | 28 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 29 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 30 | * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board |
Helmut Tschemernjak | 46:e78a1d0391ac | 31 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 32 | class SX1276Generic : public SX1276 |
Helmut Tschemernjak | 46:e78a1d0391ac | 33 | { |
Helmut Tschemernjak | 46:e78a1d0391ac | 34 | protected: |
Helmut Tschemernjak | 46:e78a1d0391ac | 35 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 36 | * Antenna switch GPIO pins objects |
Helmut Tschemernjak | 46:e78a1d0391ac | 37 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 38 | DigitalOut *_antSwitch; |
Helmut Tschemernjak | 46:e78a1d0391ac | 39 | DigitalOut *_antSwitchTX; |
Helmut Tschemernjak | 46:e78a1d0391ac | 40 | DigitalOut *_antSwitchTXBoost; |
Helmut Tschemernjak | 46:e78a1d0391ac | 41 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 42 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 43 | * SX1276 Reset pin |
Helmut Tschemernjak | 46:e78a1d0391ac | 44 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 45 | DigitalInOut *_reset; |
Helmut Tschemernjak | 46:e78a1d0391ac | 46 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 47 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 48 | * TCXO being used with the Murata Module |
Helmut Tschemernjak | 46:e78a1d0391ac | 49 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 50 | DigitalOut *_tcxo; |
Helmut Tschemernjak | 46:e78a1d0391ac | 51 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 52 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 53 | * SPI Interface |
Helmut Tschemernjak | 46:e78a1d0391ac | 54 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 55 | SPI *_spi; // mosi, miso, sclk |
Helmut Tschemernjak | 46:e78a1d0391ac | 56 | DigitalOut *_nss; |
Helmut Tschemernjak | 46:e78a1d0391ac | 57 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 58 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 59 | * SX1276 DIO pins |
Helmut Tschemernjak | 46:e78a1d0391ac | 60 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 61 | InterruptIn *_dio0; |
Helmut Tschemernjak | 46:e78a1d0391ac | 62 | InterruptIn *_dio1; |
Helmut Tschemernjak | 46:e78a1d0391ac | 63 | InterruptIn *_dio2; |
Helmut Tschemernjak | 46:e78a1d0391ac | 64 | InterruptIn *_dio3; |
Helmut Tschemernjak | 46:e78a1d0391ac | 65 | InterruptIn *_dio4; |
Helmut Tschemernjak | 46:e78a1d0391ac | 66 | DigitalIn *_dio5; |
Helmut Tschemernjak | 46:e78a1d0391ac | 67 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 68 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 69 | * Tx and Rx timers |
Helmut Tschemernjak | 46:e78a1d0391ac | 70 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 71 | Timeout txTimeoutTimer; |
Helmut Tschemernjak | 46:e78a1d0391ac | 72 | Timeout rxTimeoutTimer; |
Helmut Tschemernjak | 46:e78a1d0391ac | 73 | Timeout rxTimeoutSyncWord; |
Helmut Tschemernjak | 46:e78a1d0391ac | 74 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 75 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 76 | private: |
Helmut Tschemernjak | 46:e78a1d0391ac | 77 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 78 | * triggers definition |
Helmut Tschemernjak | 46:e78a1d0391ac | 79 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 80 | typedef void (SX1276Generic::*Trigger)(void); |
Helmut Tschemernjak | 46:e78a1d0391ac | 81 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 82 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 83 | public: |
Helmut Tschemernjak | 46:e78a1d0391ac | 84 | SX1276Generic( RadioEvents_t *events, BoardType_t board, |
Helmut Tschemernjak | 46:e78a1d0391ac | 85 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
Helmut Tschemernjak | 46:e78a1d0391ac | 86 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, |
Helmut Tschemernjak | 46:e78a1d0391ac | 87 | PinName antSwitch = NC, PinName antSwitchTX= NC, PinName antSwitchTXBoost = NC, PinName tcxo = NC); |
Helmut Tschemernjak | 46:e78a1d0391ac | 88 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 89 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 90 | SX1276Generic( RadioEvents_t *events ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 91 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 92 | virtual ~SX1276Generic(); |
Helmut Tschemernjak | 46:e78a1d0391ac | 93 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 94 | protected: |
Helmut Tschemernjak | 46:e78a1d0391ac | 95 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 96 | * @brief Initializes the radio I/Os pins interface |
Helmut Tschemernjak | 46:e78a1d0391ac | 97 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 98 | virtual void IoInit( void ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 99 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 100 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 101 | * @brief Initializes the radio SPI |
Helmut Tschemernjak | 46:e78a1d0391ac | 102 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 103 | virtual void SpiInit( void ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 104 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 105 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 106 | * @brief Initializes DIO IRQ handlers |
Helmut Tschemernjak | 46:e78a1d0391ac | 107 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 108 | * @param [IN] irqHandlers Array containing the IRQ callback functions |
Helmut Tschemernjak | 46:e78a1d0391ac | 109 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 110 | virtual void IoIrqInit( DioIrqHandler *irqHandlers ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 111 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 112 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 113 | * @brief De-initializes the radio I/Os pins interface. |
Helmut Tschemernjak | 46:e78a1d0391ac | 114 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 115 | * \remark Useful when going in MCU lowpower modes |
Helmut Tschemernjak | 46:e78a1d0391ac | 116 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 117 | virtual void IoDeInit( void ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 118 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 119 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 120 | * \brief Sets the radio output power. |
Helmut Tschemernjak | 46:e78a1d0391ac | 121 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 122 | * @param [IN] power Sets the RF output power |
Helmut Tschemernjak | 46:e78a1d0391ac | 123 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 124 | virtual void SetRfTxPower( int8_t power ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 125 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 126 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 127 | * @brief Gets the board PA selection configuration |
Helmut Tschemernjak | 46:e78a1d0391ac | 128 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 129 | * @param [IN] channel Channel frequency in Hz |
Helmut Tschemernjak | 46:e78a1d0391ac | 130 | * @retval PaSelect RegPaConfig PaSelect value |
Helmut Tschemernjak | 46:e78a1d0391ac | 131 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 132 | virtual uint8_t GetPaSelect( uint32_t channel ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 133 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 134 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 135 | * @brief Set the RF Switch I/Os pins in Low Power mode |
Helmut Tschemernjak | 46:e78a1d0391ac | 136 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 137 | * @param [IN] status enable or disable |
Helmut Tschemernjak | 46:e78a1d0391ac | 138 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 139 | virtual void SetAntSwLowPower( bool status ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 140 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 141 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 142 | * @brief Initializes the RF Switch I/Os pins interface |
Helmut Tschemernjak | 46:e78a1d0391ac | 143 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 144 | virtual void AntSwInit( void ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 145 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 146 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 147 | * @brief De-initializes the RF Switch I/Os pins interface |
Helmut Tschemernjak | 46:e78a1d0391ac | 148 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 149 | * @remark Needed to decrease the power consumption in MCU lowpower modes |
Helmut Tschemernjak | 46:e78a1d0391ac | 150 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 151 | virtual void AntSwDeInit( void ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 152 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 153 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 154 | * @brief Controls the antena switch if necessary. |
Helmut Tschemernjak | 46:e78a1d0391ac | 155 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 156 | * @remark see errata note |
Helmut Tschemernjak | 46:e78a1d0391ac | 157 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 158 | * @param [IN] opMode Current radio operating mode |
Helmut Tschemernjak | 46:e78a1d0391ac | 159 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 160 | virtual void SetAntSw( uint8_t opMode ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 161 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 162 | /* |
Helmut Tschemernjak | 46:e78a1d0391ac | 163 | * The the Timeout for a given Timer. |
Helmut Tschemernjak | 46:e78a1d0391ac | 164 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 165 | virtual void SetTimeout(TimeoutTimer_t timer, timeoutFuncPtr, int timeout_ms = 0); |
Helmut Tschemernjak | 46:e78a1d0391ac | 166 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 167 | public: |
Helmut Tschemernjak | 46:e78a1d0391ac | 168 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 169 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 170 | * @brief Detect the board connected by reading the value of the antenna switch pin |
Helmut Tschemernjak | 46:e78a1d0391ac | 171 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 172 | virtual uint8_t DetectBoardType( void ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 173 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 174 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 175 | * @brief Checks if the given RF frequency is supported by the hardware |
Helmut Tschemernjak | 46:e78a1d0391ac | 176 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 177 | * @param [IN] frequency RF frequency to be checked |
Helmut Tschemernjak | 46:e78a1d0391ac | 178 | * @retval isSupported [true: supported, false: unsupported] |
Helmut Tschemernjak | 46:e78a1d0391ac | 179 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 180 | virtual bool CheckRfFrequency( uint32_t frequency ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 181 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 182 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 183 | * @brief Writes the radio register at the specified address |
Helmut Tschemernjak | 46:e78a1d0391ac | 184 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 185 | * @param [IN]: addr Register address |
Helmut Tschemernjak | 46:e78a1d0391ac | 186 | * @param [IN]: data New register value |
Helmut Tschemernjak | 46:e78a1d0391ac | 187 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 188 | virtual void Write ( uint8_t addr, uint8_t data ) ; |
Helmut Tschemernjak | 46:e78a1d0391ac | 189 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 190 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 191 | * @brief Reads the radio register at the specified address |
Helmut Tschemernjak | 46:e78a1d0391ac | 192 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 193 | * @param [IN]: addr Register address |
Helmut Tschemernjak | 46:e78a1d0391ac | 194 | * @retval data Register value |
Helmut Tschemernjak | 46:e78a1d0391ac | 195 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 196 | virtual uint8_t Read ( uint8_t addr ) ; |
Helmut Tschemernjak | 46:e78a1d0391ac | 197 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 198 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 199 | * @brief Writes multiple radio registers starting at address |
Helmut Tschemernjak | 46:e78a1d0391ac | 200 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 201 | * @param [IN] addr First Radio register address |
Helmut Tschemernjak | 46:e78a1d0391ac | 202 | * @param [IN] buffer Buffer containing the new register's values |
Helmut Tschemernjak | 46:e78a1d0391ac | 203 | * @param [IN] size Number of registers to be written |
Helmut Tschemernjak | 46:e78a1d0391ac | 204 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 205 | virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
Helmut Tschemernjak | 46:e78a1d0391ac | 206 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 207 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 208 | * @brief Reads multiple radio registers starting at address |
Helmut Tschemernjak | 46:e78a1d0391ac | 209 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 210 | * @param [IN] addr First Radio register address |
Helmut Tschemernjak | 46:e78a1d0391ac | 211 | * @param [OUT] buffer Buffer where to copy the registers data |
Helmut Tschemernjak | 46:e78a1d0391ac | 212 | * @param [IN] size Number of registers to be read |
Helmut Tschemernjak | 46:e78a1d0391ac | 213 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 214 | virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
Helmut Tschemernjak | 46:e78a1d0391ac | 215 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 216 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 217 | * @brief Writes the buffer contents to the SX1276 FIFO |
Helmut Tschemernjak | 46:e78a1d0391ac | 218 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 219 | * @param [IN] buffer Buffer containing data to be put on the FIFO. |
Helmut Tschemernjak | 46:e78a1d0391ac | 220 | * @param [IN] size Number of bytes to be written to the FIFO |
Helmut Tschemernjak | 46:e78a1d0391ac | 221 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 222 | virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ; |
Helmut Tschemernjak | 46:e78a1d0391ac | 223 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 224 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 225 | * @brief Reads the contents of the SX1276 FIFO |
Helmut Tschemernjak | 46:e78a1d0391ac | 226 | * |
Helmut Tschemernjak | 46:e78a1d0391ac | 227 | * @param [OUT] buffer Buffer where to copy the FIFO read data. |
Helmut Tschemernjak | 46:e78a1d0391ac | 228 | * @param [IN] size Number of bytes to be read from the FIFO |
Helmut Tschemernjak | 46:e78a1d0391ac | 229 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 230 | virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ; |
Helmut Tschemernjak | 46:e78a1d0391ac | 231 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 232 | /*! |
Helmut Tschemernjak | 46:e78a1d0391ac | 233 | * @brief Reset the SX1276 |
Helmut Tschemernjak | 46:e78a1d0391ac | 234 | */ |
Helmut Tschemernjak | 46:e78a1d0391ac | 235 | virtual void Reset( void ); |
Helmut Tschemernjak | 46:e78a1d0391ac | 236 | }; |
Helmut Tschemernjak | 40:0165543c0986 | 237 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 238 | #endif // __SX1276_ARDUINO_HAL_H__ |
Helmut Tschemernjak | 40:0165543c0986 | 239 | #endif // ARDUINO |