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