1
sx1276/sx1276-hal.h@0:7e14d7c443f1, 2016-10-08 (annotated)
- Committer:
- floatlei
- Date:
- Sat Oct 08 02:35:14 2016 +0000
- Revision:
- 0:7e14d7c443f1
11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
floatlei | 0:7e14d7c443f1 | 1 | /* |
floatlei | 0:7e14d7c443f1 | 2 | / _____) _ | | |
floatlei | 0:7e14d7c443f1 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
floatlei | 0:7e14d7c443f1 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
floatlei | 0:7e14d7c443f1 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
floatlei | 0:7e14d7c443f1 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
floatlei | 0:7e14d7c443f1 | 7 | (C) 2014 Semtech |
floatlei | 0:7e14d7c443f1 | 8 | |
floatlei | 0:7e14d7c443f1 | 9 | Description: - |
floatlei | 0:7e14d7c443f1 | 10 | |
floatlei | 0:7e14d7c443f1 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
floatlei | 0:7e14d7c443f1 | 12 | |
floatlei | 0:7e14d7c443f1 | 13 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
floatlei | 0:7e14d7c443f1 | 14 | */ |
floatlei | 0:7e14d7c443f1 | 15 | #ifndef __SX1276_HAL_H__ |
floatlei | 0:7e14d7c443f1 | 16 | #define __SX1276_HAL_H__ |
floatlei | 0:7e14d7c443f1 | 17 | #include "sx1276.h" |
floatlei | 0:7e14d7c443f1 | 18 | |
floatlei | 0:7e14d7c443f1 | 19 | /*! |
floatlei | 0:7e14d7c443f1 | 20 | * \brief Radio hardware registers initialization definition |
floatlei | 0:7e14d7c443f1 | 21 | * |
floatlei | 0:7e14d7c443f1 | 22 | * \remark Can be automatically generated by the SX1276 GUI (not yet implemented) |
floatlei | 0:7e14d7c443f1 | 23 | */ |
floatlei | 0:7e14d7c443f1 | 24 | #define RADIO_INIT_REGISTERS_VALUE \ |
floatlei | 0:7e14d7c443f1 | 25 | { \ |
floatlei | 0:7e14d7c443f1 | 26 | { MODEM_FSK , REG_LNA , 0x23 },\ |
floatlei | 0:7e14d7c443f1 | 27 | { MODEM_FSK , REG_RXCONFIG , 0x1E },\ |
floatlei | 0:7e14d7c443f1 | 28 | { MODEM_FSK , REG_RSSICONFIG , 0xD2 },\ |
floatlei | 0:7e14d7c443f1 | 29 | { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA },\ |
floatlei | 0:7e14d7c443f1 | 30 | { MODEM_FSK , REG_OSC , 0x07 },\ |
floatlei | 0:7e14d7c443f1 | 31 | { MODEM_FSK , REG_SYNCCONFIG , 0x12 },\ |
floatlei | 0:7e14d7c443f1 | 32 | { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 },\ |
floatlei | 0:7e14d7c443f1 | 33 | { MODEM_FSK , REG_SYNCVALUE2 , 0x94 },\ |
floatlei | 0:7e14d7c443f1 | 34 | { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 },\ |
floatlei | 0:7e14d7c443f1 | 35 | { MODEM_FSK , REG_PACKETCONFIG1 , 0xD8 },\ |
floatlei | 0:7e14d7c443f1 | 36 | { MODEM_FSK , REG_FIFOTHRESH , 0x8F },\ |
floatlei | 0:7e14d7c443f1 | 37 | { MODEM_FSK , REG_IMAGECAL , 0x02 },\ |
floatlei | 0:7e14d7c443f1 | 38 | { MODEM_FSK , REG_DIOMAPPING1 , 0x00 },\ |
floatlei | 0:7e14d7c443f1 | 39 | { MODEM_FSK , REG_DIOMAPPING2 , 0x30 },\ |
floatlei | 0:7e14d7c443f1 | 40 | { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\ |
floatlei | 0:7e14d7c443f1 | 41 | } \ |
floatlei | 0:7e14d7c443f1 | 42 | |
floatlei | 0:7e14d7c443f1 | 43 | /*! |
floatlei | 0:7e14d7c443f1 | 44 | * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board |
floatlei | 0:7e14d7c443f1 | 45 | */ |
floatlei | 0:7e14d7c443f1 | 46 | class SX1276MB1xAS : public SX1276 |
floatlei | 0:7e14d7c443f1 | 47 | { |
floatlei | 0:7e14d7c443f1 | 48 | protected: |
floatlei | 0:7e14d7c443f1 | 49 | /*! |
floatlei | 0:7e14d7c443f1 | 50 | * Antenna switch GPIO pins objects |
floatlei | 0:7e14d7c443f1 | 51 | */ |
floatlei | 0:7e14d7c443f1 | 52 | DigitalInOut antSwitch; |
floatlei | 0:7e14d7c443f1 | 53 | |
floatlei | 0:7e14d7c443f1 | 54 | DigitalIn fake; |
floatlei | 0:7e14d7c443f1 | 55 | |
floatlei | 0:7e14d7c443f1 | 56 | private: |
floatlei | 0:7e14d7c443f1 | 57 | static const RadioRegisters_t RadioRegsInit[]; |
floatlei | 0:7e14d7c443f1 | 58 | |
floatlei | 0:7e14d7c443f1 | 59 | public: |
floatlei | 0:7e14d7c443f1 | 60 | SX1276MB1xAS( RadioEvents_t *events, |
floatlei | 0:7e14d7c443f1 | 61 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
floatlei | 0:7e14d7c443f1 | 62 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, |
floatlei | 0:7e14d7c443f1 | 63 | PinName antSwitch ); |
floatlei | 0:7e14d7c443f1 | 64 | |
floatlei | 0:7e14d7c443f1 | 65 | SX1276MB1xAS( RadioEvents_t *events ); |
floatlei | 0:7e14d7c443f1 | 66 | |
floatlei | 0:7e14d7c443f1 | 67 | virtual ~SX1276MB1xAS( ) { }; |
floatlei | 0:7e14d7c443f1 | 68 | |
floatlei | 0:7e14d7c443f1 | 69 | protected: |
floatlei | 0:7e14d7c443f1 | 70 | /*! |
floatlei | 0:7e14d7c443f1 | 71 | * @brief Initializes the radio I/Os pins interface |
floatlei | 0:7e14d7c443f1 | 72 | */ |
floatlei | 0:7e14d7c443f1 | 73 | virtual void IoInit( void ); |
floatlei | 0:7e14d7c443f1 | 74 | |
floatlei | 0:7e14d7c443f1 | 75 | /*! |
floatlei | 0:7e14d7c443f1 | 76 | * @brief Initializes the radio registers |
floatlei | 0:7e14d7c443f1 | 77 | */ |
floatlei | 0:7e14d7c443f1 | 78 | virtual void RadioRegistersInit( ); |
floatlei | 0:7e14d7c443f1 | 79 | |
floatlei | 0:7e14d7c443f1 | 80 | /*! |
floatlei | 0:7e14d7c443f1 | 81 | * @brief Initializes the radio SPI |
floatlei | 0:7e14d7c443f1 | 82 | */ |
floatlei | 0:7e14d7c443f1 | 83 | virtual void SpiInit( void ); |
floatlei | 0:7e14d7c443f1 | 84 | |
floatlei | 0:7e14d7c443f1 | 85 | /*! |
floatlei | 0:7e14d7c443f1 | 86 | * @brief Initializes DIO IRQ handlers |
floatlei | 0:7e14d7c443f1 | 87 | * |
floatlei | 0:7e14d7c443f1 | 88 | * @param [IN] irqHandlers Array containing the IRQ callback functions |
floatlei | 0:7e14d7c443f1 | 89 | */ |
floatlei | 0:7e14d7c443f1 | 90 | virtual void IoIrqInit( DioIrqHandler *irqHandlers ); |
floatlei | 0:7e14d7c443f1 | 91 | |
floatlei | 0:7e14d7c443f1 | 92 | /*! |
floatlei | 0:7e14d7c443f1 | 93 | * @brief De-initializes the radio I/Os pins interface. |
floatlei | 0:7e14d7c443f1 | 94 | * |
floatlei | 0:7e14d7c443f1 | 95 | * \remark Useful when going in MCU lowpower modes |
floatlei | 0:7e14d7c443f1 | 96 | */ |
floatlei | 0:7e14d7c443f1 | 97 | virtual void IoDeInit( void ); |
floatlei | 0:7e14d7c443f1 | 98 | |
floatlei | 0:7e14d7c443f1 | 99 | /*! |
floatlei | 0:7e14d7c443f1 | 100 | * @brief Gets the board PA selection configuration |
floatlei | 0:7e14d7c443f1 | 101 | * |
floatlei | 0:7e14d7c443f1 | 102 | * @param [IN] channel Channel frequency in Hz |
floatlei | 0:7e14d7c443f1 | 103 | * @retval PaSelect RegPaConfig PaSelect value |
floatlei | 0:7e14d7c443f1 | 104 | */ |
floatlei | 0:7e14d7c443f1 | 105 | virtual uint8_t GetPaSelect( uint32_t channel ); |
floatlei | 0:7e14d7c443f1 | 106 | |
floatlei | 0:7e14d7c443f1 | 107 | /*! |
floatlei | 0:7e14d7c443f1 | 108 | * @brief Set the RF Switch I/Os pins in Low Power mode |
floatlei | 0:7e14d7c443f1 | 109 | * |
floatlei | 0:7e14d7c443f1 | 110 | * @param [IN] status enable or disable |
floatlei | 0:7e14d7c443f1 | 111 | */ |
floatlei | 0:7e14d7c443f1 | 112 | virtual void SetAntSwLowPower( bool status ); |
floatlei | 0:7e14d7c443f1 | 113 | |
floatlei | 0:7e14d7c443f1 | 114 | /*! |
floatlei | 0:7e14d7c443f1 | 115 | * @brief Initializes the RF Switch I/Os pins interface |
floatlei | 0:7e14d7c443f1 | 116 | */ |
floatlei | 0:7e14d7c443f1 | 117 | virtual void AntSwInit( void ); |
floatlei | 0:7e14d7c443f1 | 118 | |
floatlei | 0:7e14d7c443f1 | 119 | /*! |
floatlei | 0:7e14d7c443f1 | 120 | * @brief De-initializes the RF Switch I/Os pins interface |
floatlei | 0:7e14d7c443f1 | 121 | * |
floatlei | 0:7e14d7c443f1 | 122 | * \remark Needed to decrease the power consumption in MCU lowpower modes |
floatlei | 0:7e14d7c443f1 | 123 | */ |
floatlei | 0:7e14d7c443f1 | 124 | virtual void AntSwDeInit( void ); |
floatlei | 0:7e14d7c443f1 | 125 | |
floatlei | 0:7e14d7c443f1 | 126 | /*! |
floatlei | 0:7e14d7c443f1 | 127 | * @brief Controls the antena switch if necessary. |
floatlei | 0:7e14d7c443f1 | 128 | * |
floatlei | 0:7e14d7c443f1 | 129 | * \remark see errata note |
floatlei | 0:7e14d7c443f1 | 130 | * |
floatlei | 0:7e14d7c443f1 | 131 | * @param [IN] rxTx [1: Tx, 0: Rx] |
floatlei | 0:7e14d7c443f1 | 132 | */ |
floatlei | 0:7e14d7c443f1 | 133 | virtual void SetAntSw( uint8_t rxTx ); |
floatlei | 0:7e14d7c443f1 | 134 | |
floatlei | 0:7e14d7c443f1 | 135 | public: |
floatlei | 0:7e14d7c443f1 | 136 | /*! |
floatlei | 0:7e14d7c443f1 | 137 | * @brief Detect the board connected by reading the value of the antenna switch pin |
floatlei | 0:7e14d7c443f1 | 138 | */ |
floatlei | 0:7e14d7c443f1 | 139 | virtual uint8_t DetectBoardType( void ); |
floatlei | 0:7e14d7c443f1 | 140 | |
floatlei | 0:7e14d7c443f1 | 141 | /*! |
floatlei | 0:7e14d7c443f1 | 142 | * @brief Checks if the given RF frequency is supported by the hardware |
floatlei | 0:7e14d7c443f1 | 143 | * |
floatlei | 0:7e14d7c443f1 | 144 | * @param [IN] frequency RF frequency to be checked |
floatlei | 0:7e14d7c443f1 | 145 | * @retval isSupported [true: supported, false: unsupported] |
floatlei | 0:7e14d7c443f1 | 146 | */ |
floatlei | 0:7e14d7c443f1 | 147 | virtual bool CheckRfFrequency( uint32_t frequency ); |
floatlei | 0:7e14d7c443f1 | 148 | |
floatlei | 0:7e14d7c443f1 | 149 | /*! |
floatlei | 0:7e14d7c443f1 | 150 | * @brief Writes the radio register at the specified address |
floatlei | 0:7e14d7c443f1 | 151 | * |
floatlei | 0:7e14d7c443f1 | 152 | * @param [IN]: addr Register address |
floatlei | 0:7e14d7c443f1 | 153 | * @param [IN]: data New register value |
floatlei | 0:7e14d7c443f1 | 154 | */ |
floatlei | 0:7e14d7c443f1 | 155 | virtual void Write ( uint8_t addr, uint8_t data ) ; |
floatlei | 0:7e14d7c443f1 | 156 | |
floatlei | 0:7e14d7c443f1 | 157 | /*! |
floatlei | 0:7e14d7c443f1 | 158 | * @brief Reads the radio register at the specified address |
floatlei | 0:7e14d7c443f1 | 159 | * |
floatlei | 0:7e14d7c443f1 | 160 | * @param [IN]: addr Register address |
floatlei | 0:7e14d7c443f1 | 161 | * @retval data Register value |
floatlei | 0:7e14d7c443f1 | 162 | */ |
floatlei | 0:7e14d7c443f1 | 163 | virtual uint8_t Read ( uint8_t addr ) ; |
floatlei | 0:7e14d7c443f1 | 164 | |
floatlei | 0:7e14d7c443f1 | 165 | /*! |
floatlei | 0:7e14d7c443f1 | 166 | * @brief Writes multiple radio registers starting at address |
floatlei | 0:7e14d7c443f1 | 167 | * |
floatlei | 0:7e14d7c443f1 | 168 | * @param [IN] addr First Radio register address |
floatlei | 0:7e14d7c443f1 | 169 | * @param [IN] buffer Buffer containing the new register's values |
floatlei | 0:7e14d7c443f1 | 170 | * @param [IN] size Number of registers to be written |
floatlei | 0:7e14d7c443f1 | 171 | */ |
floatlei | 0:7e14d7c443f1 | 172 | virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
floatlei | 0:7e14d7c443f1 | 173 | |
floatlei | 0:7e14d7c443f1 | 174 | /*! |
floatlei | 0:7e14d7c443f1 | 175 | * @brief Reads multiple radio registers starting at address |
floatlei | 0:7e14d7c443f1 | 176 | * |
floatlei | 0:7e14d7c443f1 | 177 | * @param [IN] addr First Radio register address |
floatlei | 0:7e14d7c443f1 | 178 | * @param [OUT] buffer Buffer where to copy the registers data |
floatlei | 0:7e14d7c443f1 | 179 | * @param [IN] size Number of registers to be read |
floatlei | 0:7e14d7c443f1 | 180 | */ |
floatlei | 0:7e14d7c443f1 | 181 | virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
floatlei | 0:7e14d7c443f1 | 182 | |
floatlei | 0:7e14d7c443f1 | 183 | /*! |
floatlei | 0:7e14d7c443f1 | 184 | * @brief Writes the buffer contents to the SX1276 FIFO |
floatlei | 0:7e14d7c443f1 | 185 | * |
floatlei | 0:7e14d7c443f1 | 186 | * @param [IN] buffer Buffer containing data to be put on the FIFO. |
floatlei | 0:7e14d7c443f1 | 187 | * @param [IN] size Number of bytes to be written to the FIFO |
floatlei | 0:7e14d7c443f1 | 188 | */ |
floatlei | 0:7e14d7c443f1 | 189 | virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ; |
floatlei | 0:7e14d7c443f1 | 190 | |
floatlei | 0:7e14d7c443f1 | 191 | /*! |
floatlei | 0:7e14d7c443f1 | 192 | * @brief Reads the contents of the SX1276 FIFO |
floatlei | 0:7e14d7c443f1 | 193 | * |
floatlei | 0:7e14d7c443f1 | 194 | * @param [OUT] buffer Buffer where to copy the FIFO read data. |
floatlei | 0:7e14d7c443f1 | 195 | * @param [IN] size Number of bytes to be read from the FIFO |
floatlei | 0:7e14d7c443f1 | 196 | */ |
floatlei | 0:7e14d7c443f1 | 197 | virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ; |
floatlei | 0:7e14d7c443f1 | 198 | |
floatlei | 0:7e14d7c443f1 | 199 | /*! |
floatlei | 0:7e14d7c443f1 | 200 | * @brief Reset the SX1276 |
floatlei | 0:7e14d7c443f1 | 201 | */ |
floatlei | 0:7e14d7c443f1 | 202 | virtual void Reset( void ); |
floatlei | 0:7e14d7c443f1 | 203 | }; |
floatlei | 0:7e14d7c443f1 | 204 | |
floatlei | 0:7e14d7c443f1 | 205 | #endif // __SX1276_HAL_H__ |