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

Committer:
Helmut64
Date:
Sat May 06 12:10:11 2017 +0000
Revision:
36:f2b885b6f33e
Parent:
sx1276/sx1276-hal.h@34:07e89f23c734
Child:
38:d9189d958db8
Remove debug folder, added TODO file

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 34:07e89f23c734 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
mluis 22:7f3aab69cca9 26 /*!
Helmut Tschemernjak 31:e50929bd3f32 27 * @brief Radio hardware registers initialization definition
mluis 22:7f3aab69cca9 28 *
Helmut Tschemernjak 31:e50929bd3f32 29 * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
mluis 22:7f3aab69cca9 30 */
mluis 22:7f3aab69cca9 31 #define RADIO_INIT_REGISTERS_VALUE \
mluis 22:7f3aab69cca9 32 { \
mluis 22:7f3aab69cca9 33 { MODEM_FSK , REG_LNA , 0x23 },\
mluis 22:7f3aab69cca9 34 { MODEM_FSK , REG_RXCONFIG , 0x1E },\
mluis 22:7f3aab69cca9 35 { MODEM_FSK , REG_RSSICONFIG , 0xD2 },\
mluis 25:3778e6204cc1 36 { MODEM_FSK , REG_AFCFEI , 0x01 },\
mluis 22:7f3aab69cca9 37 { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA },\
mluis 22:7f3aab69cca9 38 { MODEM_FSK , REG_OSC , 0x07 },\
mluis 22:7f3aab69cca9 39 { MODEM_FSK , REG_SYNCCONFIG , 0x12 },\
mluis 22:7f3aab69cca9 40 { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 },\
mluis 22:7f3aab69cca9 41 { MODEM_FSK , REG_SYNCVALUE2 , 0x94 },\
mluis 22:7f3aab69cca9 42 { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 },\
mluis 22:7f3aab69cca9 43 { MODEM_FSK , REG_PACKETCONFIG1 , 0xD8 },\
mluis 22:7f3aab69cca9 44 { MODEM_FSK , REG_FIFOTHRESH , 0x8F },\
mluis 22:7f3aab69cca9 45 { MODEM_FSK , REG_IMAGECAL , 0x02 },\
mluis 22:7f3aab69cca9 46 { MODEM_FSK , REG_DIOMAPPING1 , 0x00 },\
mluis 22:7f3aab69cca9 47 { MODEM_FSK , REG_DIOMAPPING2 , 0x30 },\
mluis 22:7f3aab69cca9 48 { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
mluis 22:7f3aab69cca9 49 } \
mluis 22:7f3aab69cca9 50
GregCr 0:e6ceb13d2d05 51 /*!
GregCr 0:e6ceb13d2d05 52 * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
GregCr 0:e6ceb13d2d05 53 */
Helmut Tschemernjak 34:07e89f23c734 54 class SX1276Generic : public SX1276
GregCr 0:e6ceb13d2d05 55 {
GregCr 0:e6ceb13d2d05 56 protected:
GregCr 0:e6ceb13d2d05 57 /*!
GregCr 0:e6ceb13d2d05 58 * Antenna switch GPIO pins objects
GregCr 0:e6ceb13d2d05 59 */
Helmut Tschemernjak 34:07e89f23c734 60 DigitalInOut *_antSwitch;
Helmut Tschemernjak 34:07e89f23c734 61 DigitalInOut *_antSwitchTX;
Helmut Tschemernjak 34:07e89f23c734 62 DigitalInOut *_antSwitchTXBoost;
Helmut Tschemernjak 34:07e89f23c734 63
Helmut Tschemernjak 34:07e89f23c734 64 /*!
Helmut Tschemernjak 34:07e89f23c734 65 * SX1276 Reset pin
Helmut Tschemernjak 34:07e89f23c734 66 */
Helmut Tschemernjak 34:07e89f23c734 67 DigitalInOut *_reset;
Helmut Tschemernjak 34:07e89f23c734 68
Helmut Tschemernjak 34:07e89f23c734 69 /*!
Helmut Tschemernjak 34:07e89f23c734 70 * TCXO being used with the Murata Module
Helmut Tschemernjak 34:07e89f23c734 71 */
Helmut Tschemernjak 34:07e89f23c734 72 DigitalOut *_tcxo;
mluis 25:3778e6204cc1 73
Helmut Tschemernjak 34:07e89f23c734 74 /*!
Helmut Tschemernjak 34:07e89f23c734 75 * SPI Interface
Helmut Tschemernjak 34:07e89f23c734 76 */
Helmut Tschemernjak 34:07e89f23c734 77 SPI *_spi; // mosi, miso, sclk
Helmut Tschemernjak 34:07e89f23c734 78 DigitalOut *_nss;
Helmut Tschemernjak 34:07e89f23c734 79
Helmut Tschemernjak 34:07e89f23c734 80 /*!
Helmut Tschemernjak 34:07e89f23c734 81 * SX1276 DIO pins
Helmut Tschemernjak 34:07e89f23c734 82 */
Helmut Tschemernjak 34:07e89f23c734 83 InterruptIn *_dio0;
Helmut Tschemernjak 34:07e89f23c734 84 InterruptIn *_dio1;
Helmut Tschemernjak 34:07e89f23c734 85 InterruptIn *_dio2;
Helmut Tschemernjak 34:07e89f23c734 86 InterruptIn *_dio3;
Helmut Tschemernjak 34:07e89f23c734 87 InterruptIn *_dio4;
Helmut Tschemernjak 34:07e89f23c734 88 DigitalIn *_dio5;
Helmut Tschemernjak 34:07e89f23c734 89
GregCr 0:e6ceb13d2d05 90 private:
GregCr 0:e6ceb13d2d05 91 static const RadioRegisters_t RadioRegsInit[];
mluis 25:3778e6204cc1 92
GregCr 0:e6ceb13d2d05 93 public:
Helmut Tschemernjak 34:07e89f23c734 94 SX1276Generic( RadioEvents_t *events, BoardType_t board,
GregCr 0:e6ceb13d2d05 95 PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
GregCr 0:e6ceb13d2d05 96 PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
Helmut Tschemernjak 34:07e89f23c734 97 PinName antSwitch = NC, PinName antSwitchTX= NC, PinName antSwitchTXBoost = NC, PinName tcxo = NC);
mluis 25:3778e6204cc1 98
Helmut Tschemernjak 34:07e89f23c734 99
Helmut Tschemernjak 34:07e89f23c734 100 SX1276Generic( RadioEvents_t *events );
mluis 25:3778e6204cc1 101
Helmut Tschemernjak 34:07e89f23c734 102 virtual ~SX1276Generic();
mluis 25:3778e6204cc1 103
mluis 25:3778e6204cc1 104 protected:
GregCr 0:e6ceb13d2d05 105 /*!
GregCr 0:e6ceb13d2d05 106 * @brief Initializes the radio I/Os pins interface
GregCr 0:e6ceb13d2d05 107 */
GregCr 0:e6ceb13d2d05 108 virtual void IoInit( void );
mluis 25:3778e6204cc1 109
GregCr 0:e6ceb13d2d05 110 /*!
GregCr 0:e6ceb13d2d05 111 * @brief Initializes the radio registers
GregCr 0:e6ceb13d2d05 112 */
GregCr 0:e6ceb13d2d05 113 virtual void RadioRegistersInit( );
GregCr 0:e6ceb13d2d05 114
GregCr 0:e6ceb13d2d05 115 /*!
GregCr 0:e6ceb13d2d05 116 * @brief Initializes the radio SPI
GregCr 0:e6ceb13d2d05 117 */
GregCr 0:e6ceb13d2d05 118 virtual void SpiInit( void );
mluis 25:3778e6204cc1 119
GregCr 0:e6ceb13d2d05 120 /*!
GregCr 0:e6ceb13d2d05 121 * @brief Initializes DIO IRQ handlers
GregCr 0:e6ceb13d2d05 122 *
GregCr 0:e6ceb13d2d05 123 * @param [IN] irqHandlers Array containing the IRQ callback functions
GregCr 0:e6ceb13d2d05 124 */
GregCr 0:e6ceb13d2d05 125 virtual void IoIrqInit( DioIrqHandler *irqHandlers );
GregCr 0:e6ceb13d2d05 126
GregCr 0:e6ceb13d2d05 127 /*!
GregCr 0:e6ceb13d2d05 128 * @brief De-initializes the radio I/Os pins interface.
GregCr 0:e6ceb13d2d05 129 *
GregCr 0:e6ceb13d2d05 130 * \remark Useful when going in MCU lowpower modes
GregCr 0:e6ceb13d2d05 131 */
GregCr 0:e6ceb13d2d05 132 virtual void IoDeInit( void );
GregCr 0:e6ceb13d2d05 133
GregCr 0:e6ceb13d2d05 134 /*!
Helmut Tschemernjak 31:e50929bd3f32 135 * \brief Sets the radio output power.
Helmut Tschemernjak 31:e50929bd3f32 136 *
Helmut Tschemernjak 31:e50929bd3f32 137 * @param [IN] power Sets the RF output power
Helmut Tschemernjak 31:e50929bd3f32 138 */
Helmut Tschemernjak 31:e50929bd3f32 139 virtual void SetRfTxPower( int8_t power );
Helmut Tschemernjak 31:e50929bd3f32 140
Helmut Tschemernjak 31:e50929bd3f32 141 /*!
GregCr 0:e6ceb13d2d05 142 * @brief Gets the board PA selection configuration
GregCr 0:e6ceb13d2d05 143 *
GregCr 0:e6ceb13d2d05 144 * @param [IN] channel Channel frequency in Hz
GregCr 0:e6ceb13d2d05 145 * @retval PaSelect RegPaConfig PaSelect value
GregCr 0:e6ceb13d2d05 146 */
GregCr 0:e6ceb13d2d05 147 virtual uint8_t GetPaSelect( uint32_t channel );
GregCr 0:e6ceb13d2d05 148
GregCr 0:e6ceb13d2d05 149 /*!
GregCr 0:e6ceb13d2d05 150 * @brief Set the RF Switch I/Os pins in Low Power mode
GregCr 0:e6ceb13d2d05 151 *
GregCr 0:e6ceb13d2d05 152 * @param [IN] status enable or disable
GregCr 0:e6ceb13d2d05 153 */
GregCr 0:e6ceb13d2d05 154 virtual void SetAntSwLowPower( bool status );
GregCr 0:e6ceb13d2d05 155
GregCr 0:e6ceb13d2d05 156 /*!
GregCr 0:e6ceb13d2d05 157 * @brief Initializes the RF Switch I/Os pins interface
GregCr 0:e6ceb13d2d05 158 */
GregCr 0:e6ceb13d2d05 159 virtual void AntSwInit( void );
GregCr 0:e6ceb13d2d05 160
GregCr 0:e6ceb13d2d05 161 /*!
GregCr 0:e6ceb13d2d05 162 * @brief De-initializes the RF Switch I/Os pins interface
GregCr 0:e6ceb13d2d05 163 *
Helmut Tschemernjak 31:e50929bd3f32 164 * @remark Needed to decrease the power consumption in MCU lowpower modes
GregCr 0:e6ceb13d2d05 165 */
GregCr 0:e6ceb13d2d05 166 virtual void AntSwDeInit( void );
GregCr 0:e6ceb13d2d05 167
GregCr 0:e6ceb13d2d05 168 /*!
GregCr 0:e6ceb13d2d05 169 * @brief Controls the antena switch if necessary.
GregCr 0:e6ceb13d2d05 170 *
Helmut Tschemernjak 31:e50929bd3f32 171 * @remark see errata note
GregCr 0:e6ceb13d2d05 172 *
Helmut Tschemernjak 31:e50929bd3f32 173 * @param [IN] opMode Current radio operating mode
GregCr 0:e6ceb13d2d05 174 */
Helmut Tschemernjak 31:e50929bd3f32 175 virtual void SetAntSw( uint8_t opMode );
mluis 25:3778e6204cc1 176
mluis 25:3778e6204cc1 177 public:
GregCr 0:e6ceb13d2d05 178 /*!
GregCr 2:5eb3066446dd 179 * @brief Detect the board connected by reading the value of the antenna switch pin
GregCr 2:5eb3066446dd 180 */
Helmut Tschemernjak 31:e50929bd3f32 181 virtual uint8_t DetectBoardType( void );
mluis 25:3778e6204cc1 182
GregCr 2:5eb3066446dd 183 /*!
GregCr 0:e6ceb13d2d05 184 * @brief Checks if the given RF frequency is supported by the hardware
GregCr 0:e6ceb13d2d05 185 *
GregCr 0:e6ceb13d2d05 186 * @param [IN] frequency RF frequency to be checked
GregCr 0:e6ceb13d2d05 187 * @retval isSupported [true: supported, false: unsupported]
GregCr 0:e6ceb13d2d05 188 */
GregCr 0:e6ceb13d2d05 189 virtual bool CheckRfFrequency( uint32_t frequency );
mluis 25:3778e6204cc1 190
mluis 25:3778e6204cc1 191 /*!
GregCr 0:e6ceb13d2d05 192 * @brief Writes the radio register at the specified address
GregCr 0:e6ceb13d2d05 193 *
GregCr 0:e6ceb13d2d05 194 * @param [IN]: addr Register address
GregCr 0:e6ceb13d2d05 195 * @param [IN]: data New register value
GregCr 0:e6ceb13d2d05 196 */
GregCr 0:e6ceb13d2d05 197 virtual void Write ( uint8_t addr, uint8_t data ) ;
mluis 25:3778e6204cc1 198
GregCr 0:e6ceb13d2d05 199 /*!
GregCr 0:e6ceb13d2d05 200 * @brief Reads the radio register at the specified address
GregCr 0:e6ceb13d2d05 201 *
GregCr 0:e6ceb13d2d05 202 * @param [IN]: addr Register address
GregCr 0:e6ceb13d2d05 203 * @retval data Register value
GregCr 0:e6ceb13d2d05 204 */
GregCr 0:e6ceb13d2d05 205 virtual uint8_t Read ( uint8_t addr ) ;
mluis 25:3778e6204cc1 206
GregCr 0:e6ceb13d2d05 207 /*!
GregCr 0:e6ceb13d2d05 208 * @brief Writes multiple radio registers starting at address
GregCr 0:e6ceb13d2d05 209 *
GregCr 0:e6ceb13d2d05 210 * @param [IN] addr First Radio register address
GregCr 0:e6ceb13d2d05 211 * @param [IN] buffer Buffer containing the new register's values
GregCr 0:e6ceb13d2d05 212 * @param [IN] size Number of registers to be written
GregCr 0:e6ceb13d2d05 213 */
GregCr 0:e6ceb13d2d05 214 virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
mluis 25:3778e6204cc1 215
GregCr 0:e6ceb13d2d05 216 /*!
GregCr 0:e6ceb13d2d05 217 * @brief Reads multiple radio registers starting at address
GregCr 0:e6ceb13d2d05 218 *
GregCr 0:e6ceb13d2d05 219 * @param [IN] addr First Radio register address
GregCr 0:e6ceb13d2d05 220 * @param [OUT] buffer Buffer where to copy the registers data
GregCr 0:e6ceb13d2d05 221 * @param [IN] size Number of registers to be read
GregCr 0:e6ceb13d2d05 222 */
GregCr 0:e6ceb13d2d05 223 virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
mluis 25:3778e6204cc1 224
GregCr 0:e6ceb13d2d05 225 /*!
GregCr 0:e6ceb13d2d05 226 * @brief Writes the buffer contents to the SX1276 FIFO
GregCr 0:e6ceb13d2d05 227 *
GregCr 0:e6ceb13d2d05 228 * @param [IN] buffer Buffer containing data to be put on the FIFO.
GregCr 0:e6ceb13d2d05 229 * @param [IN] size Number of bytes to be written to the FIFO
GregCr 0:e6ceb13d2d05 230 */
GregCr 0:e6ceb13d2d05 231 virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
GregCr 0:e6ceb13d2d05 232
GregCr 0:e6ceb13d2d05 233 /*!
GregCr 0:e6ceb13d2d05 234 * @brief Reads the contents of the SX1276 FIFO
GregCr 0:e6ceb13d2d05 235 *
GregCr 0:e6ceb13d2d05 236 * @param [OUT] buffer Buffer where to copy the FIFO read data.
GregCr 0:e6ceb13d2d05 237 * @param [IN] size Number of bytes to be read from the FIFO
GregCr 0:e6ceb13d2d05 238 */
GregCr 0:e6ceb13d2d05 239 virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
mluis 25:3778e6204cc1 240
GregCr 0:e6ceb13d2d05 241 /*!
GregCr 0:e6ceb13d2d05 242 * @brief Reset the SX1276
GregCr 0:e6ceb13d2d05 243 */
GregCr 0:e6ceb13d2d05 244 virtual void Reset( void );
GregCr 0:e6ceb13d2d05 245 };
GregCr 0:e6ceb13d2d05 246
GregCr 0:e6ceb13d2d05 247 #endif // __SX1276_HAL_H__