Fork with intent to refactor and add support for American 902-928(915) Frequency Bands

Committer:
Kevin Barnett
Date:
Sat Sep 11 19:17:21 2021 -0700
Revision:
119:f6ba5b34efee
Parent:
117:5b5ad247cc3b
created constants and inline functions for american 902-928 MHz freq

Who changed what in which revision?

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