SX1276 library for modtronix inair9. Edited for use with NRF51DK board.
Fork of SX1276Lib_modtronix by
sx1276/sx1276-inAir.h@25:72381be1b0ce, 2015-07-29 (annotated)
- Committer:
- modtronix
- Date:
- Wed Jul 29 12:07:40 2015 +1000
- Revision:
- 25:72381be1b0ce
- Parent:
- 22:20db480143c9
Removed DIO4 and DIO5 from code. Not available on inAir Modules.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
modtronix | 16:0927c093fd82 | 1 | /* |
modtronix | 16:0927c093fd82 | 2 | Description: - |
modtronix | 16:0927c093fd82 | 3 | |
modtronix | 16:0927c093fd82 | 4 | License: Revised BSD License, see LICENSE.TXT file include in the project |
modtronix | 16:0927c093fd82 | 5 | |
modtronix | 16:0927c093fd82 | 6 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
modtronix | 16:0927c093fd82 | 7 | */ |
modtronix | 16:0927c093fd82 | 8 | #ifndef __SX1276_HAL_H__ |
modtronix | 16:0927c093fd82 | 9 | #define __SX1276_HAL_H__ |
modtronix | 18:cdb08d710838 | 10 | #include "SX1276LibConfig.h" |
modtronix | 16:0927c093fd82 | 11 | #include "sx1276.h" |
modtronix | 16:0927c093fd82 | 12 | |
modtronix | 16:0927c093fd82 | 13 | /*! |
modtronix | 22:20db480143c9 | 14 | * Modtronix BOARD_INAIR4 board with SX1276 radio. This board supports 868MHz and 915MHz at 14dBm (no boost circuit) |
modtronix | 16:0927c093fd82 | 15 | */ |
modtronix | 22:20db480143c9 | 16 | class SX1276inAir : public SX1276 |
modtronix | 16:0927c093fd82 | 17 | { |
modtronix | 16:0927c093fd82 | 18 | protected: |
modtronix | 16:0927c093fd82 | 19 | /*! |
modtronix | 16:0927c093fd82 | 20 | * Antenna switch GPIO pins objects |
modtronix | 16:0927c093fd82 | 21 | */ |
modtronix | 16:0927c093fd82 | 22 | DigitalInOut antSwitch; |
modtronix | 16:0927c093fd82 | 23 | |
modtronix | 16:0927c093fd82 | 24 | DigitalIn fake; |
modtronix | 16:0927c093fd82 | 25 | |
modtronix | 16:0927c093fd82 | 26 | private: |
modtronix | 16:0927c093fd82 | 27 | static const RadioRegisters_t RadioRegsInit[]; |
modtronix | 16:0927c093fd82 | 28 | |
modtronix | 16:0927c093fd82 | 29 | public: |
modtronix | 22:20db480143c9 | 30 | SX1276inAir( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), |
modtronix | 16:0927c093fd82 | 31 | void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ), |
modtronix | 16:0927c093fd82 | 32 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
modtronix | 25:72381be1b0ce | 33 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, /*PinName dio4, PinName dio5,*/ |
modtronix | 16:0927c093fd82 | 34 | PinName antSwitch ); |
modtronix | 22:20db480143c9 | 35 | SX1276inAir( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), |
modtronix | 16:0927c093fd82 | 36 | void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ) ); |
modtronix | 22:20db480143c9 | 37 | virtual ~SX1276inAir( ) { }; |
modtronix | 16:0927c093fd82 | 38 | |
modtronix | 16:0927c093fd82 | 39 | protected: |
modtronix | 16:0927c093fd82 | 40 | /*! |
modtronix | 16:0927c093fd82 | 41 | * @brief Initializes the radio I/Os pins interface |
modtronix | 16:0927c093fd82 | 42 | */ |
modtronix | 16:0927c093fd82 | 43 | virtual void IoInit( void ); |
modtronix | 16:0927c093fd82 | 44 | |
modtronix | 16:0927c093fd82 | 45 | /*! |
modtronix | 16:0927c093fd82 | 46 | * @brief Initializes the radio registers |
modtronix | 16:0927c093fd82 | 47 | */ |
modtronix | 16:0927c093fd82 | 48 | virtual void RadioRegistersInit( ); |
modtronix | 16:0927c093fd82 | 49 | |
modtronix | 16:0927c093fd82 | 50 | /*! |
modtronix | 16:0927c093fd82 | 51 | * @brief Initializes the radio SPI |
modtronix | 16:0927c093fd82 | 52 | */ |
modtronix | 16:0927c093fd82 | 53 | virtual void SpiInit( void ); |
modtronix | 16:0927c093fd82 | 54 | |
modtronix | 16:0927c093fd82 | 55 | /*! |
modtronix | 16:0927c093fd82 | 56 | * @brief Initializes DIO IRQ handlers |
modtronix | 16:0927c093fd82 | 57 | * |
modtronix | 16:0927c093fd82 | 58 | * @param [IN] irqHandlers Array containing the IRQ callback functions |
modtronix | 16:0927c093fd82 | 59 | */ |
modtronix | 16:0927c093fd82 | 60 | virtual void IoIrqInit( DioIrqHandler *irqHandlers ); |
modtronix | 16:0927c093fd82 | 61 | |
modtronix | 16:0927c093fd82 | 62 | /*! |
modtronix | 16:0927c093fd82 | 63 | * @brief De-initializes the radio I/Os pins interface. |
modtronix | 16:0927c093fd82 | 64 | * |
modtronix | 16:0927c093fd82 | 65 | * \remark Useful when going in MCU lowpower modes |
modtronix | 16:0927c093fd82 | 66 | */ |
modtronix | 16:0927c093fd82 | 67 | virtual void IoDeInit( void ); |
modtronix | 16:0927c093fd82 | 68 | |
modtronix | 16:0927c093fd82 | 69 | /*! |
modtronix | 16:0927c093fd82 | 70 | * @brief Gets the board PA selection configuration |
modtronix | 16:0927c093fd82 | 71 | * |
modtronix | 16:0927c093fd82 | 72 | * @param [IN] channel Channel frequency in Hz |
modtronix | 16:0927c093fd82 | 73 | * @retval PaSelect RegPaConfig PaSelect value |
modtronix | 16:0927c093fd82 | 74 | */ |
modtronix | 16:0927c093fd82 | 75 | virtual uint8_t GetPaSelect( uint32_t channel ); |
modtronix | 16:0927c093fd82 | 76 | |
modtronix | 16:0927c093fd82 | 77 | /*! |
modtronix | 16:0927c093fd82 | 78 | * @brief Set the RF Switch I/Os pins in Low Power mode |
modtronix | 16:0927c093fd82 | 79 | * |
modtronix | 16:0927c093fd82 | 80 | * @param [IN] status enable or disable |
modtronix | 16:0927c093fd82 | 81 | */ |
modtronix | 16:0927c093fd82 | 82 | virtual void SetAntSwLowPower( bool status ); |
modtronix | 16:0927c093fd82 | 83 | |
modtronix | 16:0927c093fd82 | 84 | /*! |
modtronix | 16:0927c093fd82 | 85 | * @brief Initializes the RF Switch I/Os pins interface |
modtronix | 16:0927c093fd82 | 86 | */ |
modtronix | 16:0927c093fd82 | 87 | virtual void AntSwInit( void ); |
modtronix | 16:0927c093fd82 | 88 | |
modtronix | 16:0927c093fd82 | 89 | /*! |
modtronix | 16:0927c093fd82 | 90 | * @brief De-initializes the RF Switch I/Os pins interface |
modtronix | 16:0927c093fd82 | 91 | * |
modtronix | 16:0927c093fd82 | 92 | * \remark Needed to decrease the power consumption in MCU lowpower modes |
modtronix | 16:0927c093fd82 | 93 | */ |
modtronix | 16:0927c093fd82 | 94 | virtual void AntSwDeInit( void ); |
modtronix | 16:0927c093fd82 | 95 | |
modtronix | 16:0927c093fd82 | 96 | /*! |
modtronix | 16:0927c093fd82 | 97 | * @brief Controls the antena switch if necessary. |
modtronix | 16:0927c093fd82 | 98 | * |
modtronix | 16:0927c093fd82 | 99 | * \remark see errata note |
modtronix | 16:0927c093fd82 | 100 | * |
modtronix | 16:0927c093fd82 | 101 | * @param [IN] rxTx [1: Tx, 0: Rx] |
modtronix | 16:0927c093fd82 | 102 | */ |
modtronix | 16:0927c093fd82 | 103 | virtual void SetAntSw( uint8_t rxTx ); |
modtronix | 16:0927c093fd82 | 104 | |
modtronix | 16:0927c093fd82 | 105 | public: |
modtronix | 16:0927c093fd82 | 106 | /*! |
modtronix | 16:0927c093fd82 | 107 | * @brief Detect the board connected by reading the value of the antenna switch pin |
modtronix | 16:0927c093fd82 | 108 | */ |
modtronix | 16:0927c093fd82 | 109 | virtual uint8_t DetectBoardType( void ); |
modtronix | 16:0927c093fd82 | 110 | |
modtronix | 16:0927c093fd82 | 111 | /*! |
modtronix | 16:0927c093fd82 | 112 | * @brief Checks if the given RF frequency is supported by the hardware |
modtronix | 16:0927c093fd82 | 113 | * |
modtronix | 16:0927c093fd82 | 114 | * @param [IN] frequency RF frequency to be checked |
modtronix | 16:0927c093fd82 | 115 | * @retval isSupported [true: supported, false: unsupported] |
modtronix | 16:0927c093fd82 | 116 | */ |
modtronix | 16:0927c093fd82 | 117 | virtual bool CheckRfFrequency( uint32_t frequency ); |
modtronix | 16:0927c093fd82 | 118 | |
modtronix | 16:0927c093fd82 | 119 | /*! |
modtronix | 16:0927c093fd82 | 120 | * @brief Writes the radio register at the specified address |
modtronix | 16:0927c093fd82 | 121 | * |
modtronix | 16:0927c093fd82 | 122 | * @param [IN]: addr Register address |
modtronix | 16:0927c093fd82 | 123 | * @param [IN]: data New register value |
modtronix | 16:0927c093fd82 | 124 | */ |
modtronix | 16:0927c093fd82 | 125 | virtual void Write ( uint8_t addr, uint8_t data ) ; |
modtronix | 16:0927c093fd82 | 126 | |
modtronix | 16:0927c093fd82 | 127 | /*! |
modtronix | 16:0927c093fd82 | 128 | * @brief Reads the radio register at the specified address |
modtronix | 16:0927c093fd82 | 129 | * |
modtronix | 16:0927c093fd82 | 130 | * @param [IN]: addr Register address |
modtronix | 16:0927c093fd82 | 131 | * @retval data Register value |
modtronix | 16:0927c093fd82 | 132 | */ |
modtronix | 16:0927c093fd82 | 133 | virtual uint8_t Read ( uint8_t addr ) ; |
modtronix | 16:0927c093fd82 | 134 | |
modtronix | 16:0927c093fd82 | 135 | /*! |
modtronix | 16:0927c093fd82 | 136 | * @brief Writes multiple radio registers starting at address |
modtronix | 16:0927c093fd82 | 137 | * |
modtronix | 16:0927c093fd82 | 138 | * @param [IN] addr First Radio register address |
modtronix | 16:0927c093fd82 | 139 | * @param [IN] buffer Buffer containing the new register's values |
modtronix | 16:0927c093fd82 | 140 | * @param [IN] size Number of registers to be written |
modtronix | 16:0927c093fd82 | 141 | */ |
modtronix | 16:0927c093fd82 | 142 | virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
modtronix | 16:0927c093fd82 | 143 | |
modtronix | 16:0927c093fd82 | 144 | /*! |
modtronix | 16:0927c093fd82 | 145 | * @brief Reads multiple radio registers starting at address |
modtronix | 16:0927c093fd82 | 146 | * |
modtronix | 16:0927c093fd82 | 147 | * @param [IN] addr First Radio register address |
modtronix | 16:0927c093fd82 | 148 | * @param [OUT] buffer Buffer where to copy the registers data |
modtronix | 16:0927c093fd82 | 149 | * @param [IN] size Number of registers to be read |
modtronix | 16:0927c093fd82 | 150 | */ |
modtronix | 16:0927c093fd82 | 151 | virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
modtronix | 16:0927c093fd82 | 152 | |
modtronix | 16:0927c093fd82 | 153 | /*! |
modtronix | 16:0927c093fd82 | 154 | * @brief Writes the buffer contents to the SX1276 FIFO |
modtronix | 16:0927c093fd82 | 155 | * |
modtronix | 16:0927c093fd82 | 156 | * @param [IN] buffer Buffer containing data to be put on the FIFO. |
modtronix | 16:0927c093fd82 | 157 | * @param [IN] size Number of bytes to be written to the FIFO |
modtronix | 16:0927c093fd82 | 158 | */ |
modtronix | 16:0927c093fd82 | 159 | virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ; |
modtronix | 16:0927c093fd82 | 160 | |
modtronix | 16:0927c093fd82 | 161 | /*! |
modtronix | 16:0927c093fd82 | 162 | * @brief Reads the contents of the SX1276 FIFO |
modtronix | 16:0927c093fd82 | 163 | * |
modtronix | 16:0927c093fd82 | 164 | * @param [OUT] buffer Buffer where to copy the FIFO read data. |
modtronix | 16:0927c093fd82 | 165 | * @param [IN] size Number of bytes to be read from the FIFO |
modtronix | 16:0927c093fd82 | 166 | */ |
modtronix | 16:0927c093fd82 | 167 | virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ; |
modtronix | 16:0927c093fd82 | 168 | |
modtronix | 16:0927c093fd82 | 169 | /*! |
modtronix | 16:0927c093fd82 | 170 | * @brief Reset the SX1276 |
modtronix | 16:0927c093fd82 | 171 | */ |
modtronix | 16:0927c093fd82 | 172 | virtual void Reset( void ); |
modtronix | 16:0927c093fd82 | 173 | }; |
modtronix | 16:0927c093fd82 | 174 | |
modtronix | 16:0927c093fd82 | 175 | #endif // __SX1276_HAL_H__ |