us915 ch 9 20dbm
Dependents: DISCO-L072CZ-LRWAN1_LoRa_PingPong
Fork of SX1276GenericLib by
sx1276/sx1276-mbed-hal.h@38:d9189d958db8, 2017-05-07 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Sun May 07 18:09:10 2017 +0200
- Revision:
- 38:d9189d958db8
- Parent:
- 36:f2b885b6f33e
- Child:
- 39:706c32eda7e7
Migrated typedefs.h into the sx1276 source.
Migrated radio init register values and settings into sx1276.cpp
where it belongs to.
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 | |
GregCr | 0:e6ceb13d2d05 | 22 | #ifndef __SX1276_HAL_H__ |
GregCr | 0:e6ceb13d2d05 | 23 | #define __SX1276_HAL_H__ |
GregCr | 0:e6ceb13d2d05 | 24 | #include "sx1276.h" |
GregCr | 0:e6ceb13d2d05 | 25 | |
Helmut Tschemernjak | 38:d9189d958db8 | 26 | |
mluis | 22:7f3aab69cca9 | 27 | /*! |
Helmut Tschemernjak | 38:d9189d958db8 | 28 | * triggers definition |
mluis | 22:7f3aab69cca9 | 29 | */ |
Helmut Tschemernjak | 38:d9189d958db8 | 30 | typedef void ( SX1276::*Trigger )( void ); |
Helmut Tschemernjak | 38:d9189d958db8 | 31 | typedef void ( SX1276Generic::*TriggerMB1xAS )( void ); |
mluis | 22:7f3aab69cca9 | 32 | |
Helmut Tschemernjak | 38:d9189d958db8 | 33 | |
Helmut Tschemernjak | 38:d9189d958db8 | 34 | /*! |
GregCr | 0:e6ceb13d2d05 | 35 | * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board |
GregCr | 0:e6ceb13d2d05 | 36 | */ |
Helmut Tschemernjak | 34:07e89f23c734 | 37 | class SX1276Generic : public SX1276 |
GregCr | 0:e6ceb13d2d05 | 38 | { |
GregCr | 0:e6ceb13d2d05 | 39 | protected: |
GregCr | 0:e6ceb13d2d05 | 40 | /*! |
GregCr | 0:e6ceb13d2d05 | 41 | * Antenna switch GPIO pins objects |
GregCr | 0:e6ceb13d2d05 | 42 | */ |
Helmut Tschemernjak | 34:07e89f23c734 | 43 | DigitalInOut *_antSwitch; |
Helmut Tschemernjak | 34:07e89f23c734 | 44 | DigitalInOut *_antSwitchTX; |
Helmut Tschemernjak | 34:07e89f23c734 | 45 | DigitalInOut *_antSwitchTXBoost; |
Helmut Tschemernjak | 34:07e89f23c734 | 46 | |
Helmut Tschemernjak | 34:07e89f23c734 | 47 | /*! |
Helmut Tschemernjak | 34:07e89f23c734 | 48 | * SX1276 Reset pin |
Helmut Tschemernjak | 34:07e89f23c734 | 49 | */ |
Helmut Tschemernjak | 34:07e89f23c734 | 50 | DigitalInOut *_reset; |
Helmut Tschemernjak | 34:07e89f23c734 | 51 | |
Helmut Tschemernjak | 34:07e89f23c734 | 52 | /*! |
Helmut Tschemernjak | 34:07e89f23c734 | 53 | * TCXO being used with the Murata Module |
Helmut Tschemernjak | 34:07e89f23c734 | 54 | */ |
Helmut Tschemernjak | 34:07e89f23c734 | 55 | DigitalOut *_tcxo; |
mluis | 25:3778e6204cc1 | 56 | |
Helmut Tschemernjak | 34:07e89f23c734 | 57 | /*! |
Helmut Tschemernjak | 34:07e89f23c734 | 58 | * SPI Interface |
Helmut Tschemernjak | 34:07e89f23c734 | 59 | */ |
Helmut Tschemernjak | 34:07e89f23c734 | 60 | SPI *_spi; // mosi, miso, sclk |
Helmut Tschemernjak | 34:07e89f23c734 | 61 | DigitalOut *_nss; |
Helmut Tschemernjak | 34:07e89f23c734 | 62 | |
Helmut Tschemernjak | 34:07e89f23c734 | 63 | /*! |
Helmut Tschemernjak | 34:07e89f23c734 | 64 | * SX1276 DIO pins |
Helmut Tschemernjak | 34:07e89f23c734 | 65 | */ |
Helmut Tschemernjak | 34:07e89f23c734 | 66 | InterruptIn *_dio0; |
Helmut Tschemernjak | 34:07e89f23c734 | 67 | InterruptIn *_dio1; |
Helmut Tschemernjak | 34:07e89f23c734 | 68 | InterruptIn *_dio2; |
Helmut Tschemernjak | 34:07e89f23c734 | 69 | InterruptIn *_dio3; |
Helmut Tschemernjak | 34:07e89f23c734 | 70 | InterruptIn *_dio4; |
Helmut Tschemernjak | 34:07e89f23c734 | 71 | DigitalIn *_dio5; |
Helmut Tschemernjak | 34:07e89f23c734 | 72 | |
Helmut Tschemernjak | 38:d9189d958db8 | 73 | Timeout txTimeoutTimer; |
Helmut Tschemernjak | 38:d9189d958db8 | 74 | |
Helmut Tschemernjak | 38:d9189d958db8 | 75 | |
GregCr | 0:e6ceb13d2d05 | 76 | private: |
mluis | 25:3778e6204cc1 | 77 | |
GregCr | 0:e6ceb13d2d05 | 78 | public: |
Helmut Tschemernjak | 34:07e89f23c734 | 79 | SX1276Generic( RadioEvents_t *events, BoardType_t board, |
GregCr | 0:e6ceb13d2d05 | 80 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
GregCr | 0:e6ceb13d2d05 | 81 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, |
Helmut Tschemernjak | 34:07e89f23c734 | 82 | PinName antSwitch = NC, PinName antSwitchTX= NC, PinName antSwitchTXBoost = NC, PinName tcxo = NC); |
mluis | 25:3778e6204cc1 | 83 | |
Helmut Tschemernjak | 34:07e89f23c734 | 84 | |
Helmut Tschemernjak | 34:07e89f23c734 | 85 | SX1276Generic( RadioEvents_t *events ); |
mluis | 25:3778e6204cc1 | 86 | |
Helmut Tschemernjak | 34:07e89f23c734 | 87 | virtual ~SX1276Generic(); |
mluis | 25:3778e6204cc1 | 88 | |
mluis | 25:3778e6204cc1 | 89 | protected: |
GregCr | 0:e6ceb13d2d05 | 90 | /*! |
GregCr | 0:e6ceb13d2d05 | 91 | * @brief Initializes the radio I/Os pins interface |
GregCr | 0:e6ceb13d2d05 | 92 | */ |
GregCr | 0:e6ceb13d2d05 | 93 | virtual void IoInit( void ); |
mluis | 25:3778e6204cc1 | 94 | |
GregCr | 0:e6ceb13d2d05 | 95 | /*! |
GregCr | 0:e6ceb13d2d05 | 96 | * @brief Initializes the radio SPI |
GregCr | 0:e6ceb13d2d05 | 97 | */ |
GregCr | 0:e6ceb13d2d05 | 98 | virtual void SpiInit( void ); |
mluis | 25:3778e6204cc1 | 99 | |
GregCr | 0:e6ceb13d2d05 | 100 | /*! |
GregCr | 0:e6ceb13d2d05 | 101 | * @brief Initializes DIO IRQ handlers |
GregCr | 0:e6ceb13d2d05 | 102 | * |
GregCr | 0:e6ceb13d2d05 | 103 | * @param [IN] irqHandlers Array containing the IRQ callback functions |
GregCr | 0:e6ceb13d2d05 | 104 | */ |
GregCr | 0:e6ceb13d2d05 | 105 | virtual void IoIrqInit( DioIrqHandler *irqHandlers ); |
GregCr | 0:e6ceb13d2d05 | 106 | |
GregCr | 0:e6ceb13d2d05 | 107 | /*! |
GregCr | 0:e6ceb13d2d05 | 108 | * @brief De-initializes the radio I/Os pins interface. |
GregCr | 0:e6ceb13d2d05 | 109 | * |
GregCr | 0:e6ceb13d2d05 | 110 | * \remark Useful when going in MCU lowpower modes |
GregCr | 0:e6ceb13d2d05 | 111 | */ |
GregCr | 0:e6ceb13d2d05 | 112 | virtual void IoDeInit( void ); |
GregCr | 0:e6ceb13d2d05 | 113 | |
GregCr | 0:e6ceb13d2d05 | 114 | /*! |
Helmut Tschemernjak | 31:e50929bd3f32 | 115 | * \brief Sets the radio output power. |
Helmut Tschemernjak | 31:e50929bd3f32 | 116 | * |
Helmut Tschemernjak | 31:e50929bd3f32 | 117 | * @param [IN] power Sets the RF output power |
Helmut Tschemernjak | 31:e50929bd3f32 | 118 | */ |
Helmut Tschemernjak | 31:e50929bd3f32 | 119 | virtual void SetRfTxPower( int8_t power ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 120 | |
Helmut Tschemernjak | 31:e50929bd3f32 | 121 | /*! |
GregCr | 0:e6ceb13d2d05 | 122 | * @brief Gets the board PA selection configuration |
GregCr | 0:e6ceb13d2d05 | 123 | * |
GregCr | 0:e6ceb13d2d05 | 124 | * @param [IN] channel Channel frequency in Hz |
GregCr | 0:e6ceb13d2d05 | 125 | * @retval PaSelect RegPaConfig PaSelect value |
GregCr | 0:e6ceb13d2d05 | 126 | */ |
GregCr | 0:e6ceb13d2d05 | 127 | virtual uint8_t GetPaSelect( uint32_t channel ); |
GregCr | 0:e6ceb13d2d05 | 128 | |
GregCr | 0:e6ceb13d2d05 | 129 | /*! |
GregCr | 0:e6ceb13d2d05 | 130 | * @brief Set the RF Switch I/Os pins in Low Power mode |
GregCr | 0:e6ceb13d2d05 | 131 | * |
GregCr | 0:e6ceb13d2d05 | 132 | * @param [IN] status enable or disable |
GregCr | 0:e6ceb13d2d05 | 133 | */ |
GregCr | 0:e6ceb13d2d05 | 134 | virtual void SetAntSwLowPower( bool status ); |
GregCr | 0:e6ceb13d2d05 | 135 | |
GregCr | 0:e6ceb13d2d05 | 136 | /*! |
GregCr | 0:e6ceb13d2d05 | 137 | * @brief Initializes the RF Switch I/Os pins interface |
GregCr | 0:e6ceb13d2d05 | 138 | */ |
GregCr | 0:e6ceb13d2d05 | 139 | virtual void AntSwInit( void ); |
GregCr | 0:e6ceb13d2d05 | 140 | |
GregCr | 0:e6ceb13d2d05 | 141 | /*! |
GregCr | 0:e6ceb13d2d05 | 142 | * @brief De-initializes the RF Switch I/Os pins interface |
GregCr | 0:e6ceb13d2d05 | 143 | * |
Helmut Tschemernjak | 31:e50929bd3f32 | 144 | * @remark Needed to decrease the power consumption in MCU lowpower modes |
GregCr | 0:e6ceb13d2d05 | 145 | */ |
GregCr | 0:e6ceb13d2d05 | 146 | virtual void AntSwDeInit( void ); |
GregCr | 0:e6ceb13d2d05 | 147 | |
GregCr | 0:e6ceb13d2d05 | 148 | /*! |
GregCr | 0:e6ceb13d2d05 | 149 | * @brief Controls the antena switch if necessary. |
GregCr | 0:e6ceb13d2d05 | 150 | * |
Helmut Tschemernjak | 31:e50929bd3f32 | 151 | * @remark see errata note |
GregCr | 0:e6ceb13d2d05 | 152 | * |
Helmut Tschemernjak | 31:e50929bd3f32 | 153 | * @param [IN] opMode Current radio operating mode |
GregCr | 0:e6ceb13d2d05 | 154 | */ |
Helmut Tschemernjak | 31:e50929bd3f32 | 155 | virtual void SetAntSw( uint8_t opMode ); |
Helmut Tschemernjak | 38:d9189d958db8 | 156 | |
Helmut Tschemernjak | 38:d9189d958db8 | 157 | /* |
Helmut Tschemernjak | 38:d9189d958db8 | 158 | * The the Timeout for a given Timer. |
Helmut Tschemernjak | 38:d9189d958db8 | 159 | */ |
Helmut Tschemernjak | 38:d9189d958db8 | 160 | virtual void SetTimeout(Timeout_t timer, int timeout_ms); |
mluis | 25:3778e6204cc1 | 161 | |
mluis | 25:3778e6204cc1 | 162 | public: |
Helmut Tschemernjak | 38:d9189d958db8 | 163 | |
GregCr | 0:e6ceb13d2d05 | 164 | /*! |
GregCr | 2:5eb3066446dd | 165 | * @brief Detect the board connected by reading the value of the antenna switch pin |
GregCr | 2:5eb3066446dd | 166 | */ |
Helmut Tschemernjak | 31:e50929bd3f32 | 167 | virtual uint8_t DetectBoardType( void ); |
mluis | 25:3778e6204cc1 | 168 | |
GregCr | 2:5eb3066446dd | 169 | /*! |
GregCr | 0:e6ceb13d2d05 | 170 | * @brief Checks if the given RF frequency is supported by the hardware |
GregCr | 0:e6ceb13d2d05 | 171 | * |
GregCr | 0:e6ceb13d2d05 | 172 | * @param [IN] frequency RF frequency to be checked |
GregCr | 0:e6ceb13d2d05 | 173 | * @retval isSupported [true: supported, false: unsupported] |
GregCr | 0:e6ceb13d2d05 | 174 | */ |
GregCr | 0:e6ceb13d2d05 | 175 | virtual bool CheckRfFrequency( uint32_t frequency ); |
mluis | 25:3778e6204cc1 | 176 | |
mluis | 25:3778e6204cc1 | 177 | /*! |
GregCr | 0:e6ceb13d2d05 | 178 | * @brief Writes the radio register at the specified address |
GregCr | 0:e6ceb13d2d05 | 179 | * |
GregCr | 0:e6ceb13d2d05 | 180 | * @param [IN]: addr Register address |
GregCr | 0:e6ceb13d2d05 | 181 | * @param [IN]: data New register value |
GregCr | 0:e6ceb13d2d05 | 182 | */ |
GregCr | 0:e6ceb13d2d05 | 183 | virtual void Write ( uint8_t addr, uint8_t data ) ; |
mluis | 25:3778e6204cc1 | 184 | |
GregCr | 0:e6ceb13d2d05 | 185 | /*! |
GregCr | 0:e6ceb13d2d05 | 186 | * @brief Reads the radio register at the specified address |
GregCr | 0:e6ceb13d2d05 | 187 | * |
GregCr | 0:e6ceb13d2d05 | 188 | * @param [IN]: addr Register address |
GregCr | 0:e6ceb13d2d05 | 189 | * @retval data Register value |
GregCr | 0:e6ceb13d2d05 | 190 | */ |
GregCr | 0:e6ceb13d2d05 | 191 | virtual uint8_t Read ( uint8_t addr ) ; |
mluis | 25:3778e6204cc1 | 192 | |
GregCr | 0:e6ceb13d2d05 | 193 | /*! |
GregCr | 0:e6ceb13d2d05 | 194 | * @brief Writes multiple radio registers starting at address |
GregCr | 0:e6ceb13d2d05 | 195 | * |
GregCr | 0:e6ceb13d2d05 | 196 | * @param [IN] addr First Radio register address |
GregCr | 0:e6ceb13d2d05 | 197 | * @param [IN] buffer Buffer containing the new register's values |
GregCr | 0:e6ceb13d2d05 | 198 | * @param [IN] size Number of registers to be written |
GregCr | 0:e6ceb13d2d05 | 199 | */ |
GregCr | 0:e6ceb13d2d05 | 200 | virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
mluis | 25:3778e6204cc1 | 201 | |
GregCr | 0:e6ceb13d2d05 | 202 | /*! |
GregCr | 0:e6ceb13d2d05 | 203 | * @brief Reads multiple radio registers starting at address |
GregCr | 0:e6ceb13d2d05 | 204 | * |
GregCr | 0:e6ceb13d2d05 | 205 | * @param [IN] addr First Radio register address |
GregCr | 0:e6ceb13d2d05 | 206 | * @param [OUT] buffer Buffer where to copy the registers data |
GregCr | 0:e6ceb13d2d05 | 207 | * @param [IN] size Number of registers to be read |
GregCr | 0:e6ceb13d2d05 | 208 | */ |
GregCr | 0:e6ceb13d2d05 | 209 | virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
mluis | 25:3778e6204cc1 | 210 | |
GregCr | 0:e6ceb13d2d05 | 211 | /*! |
GregCr | 0:e6ceb13d2d05 | 212 | * @brief Writes the buffer contents to the SX1276 FIFO |
GregCr | 0:e6ceb13d2d05 | 213 | * |
GregCr | 0:e6ceb13d2d05 | 214 | * @param [IN] buffer Buffer containing data to be put on the FIFO. |
GregCr | 0:e6ceb13d2d05 | 215 | * @param [IN] size Number of bytes to be written to the FIFO |
GregCr | 0:e6ceb13d2d05 | 216 | */ |
GregCr | 0:e6ceb13d2d05 | 217 | virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ; |
GregCr | 0:e6ceb13d2d05 | 218 | |
GregCr | 0:e6ceb13d2d05 | 219 | /*! |
GregCr | 0:e6ceb13d2d05 | 220 | * @brief Reads the contents of the SX1276 FIFO |
GregCr | 0:e6ceb13d2d05 | 221 | * |
GregCr | 0:e6ceb13d2d05 | 222 | * @param [OUT] buffer Buffer where to copy the FIFO read data. |
GregCr | 0:e6ceb13d2d05 | 223 | * @param [IN] size Number of bytes to be read from the FIFO |
GregCr | 0:e6ceb13d2d05 | 224 | */ |
GregCr | 0:e6ceb13d2d05 | 225 | virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ; |
mluis | 25:3778e6204cc1 | 226 | |
GregCr | 0:e6ceb13d2d05 | 227 | /*! |
GregCr | 0:e6ceb13d2d05 | 228 | * @brief Reset the SX1276 |
GregCr | 0:e6ceb13d2d05 | 229 | */ |
GregCr | 0:e6ceb13d2d05 | 230 | virtual void Reset( void ); |
GregCr | 0:e6ceb13d2d05 | 231 | }; |
GregCr | 0:e6ceb13d2d05 | 232 | |
GregCr | 0:e6ceb13d2d05 | 233 | #endif // __SX1276_HAL_H__ |