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