1272 Library for Ping Pong Example
Fork of SX1272Lib by
sx1272/sx1272-hal.h@7:b988b60083a1, 2017-04-24 (annotated)
- Committer:
- mluis
- Date:
- Mon Apr 24 09:26:08 2017 +0000
- Revision:
- 7:b988b60083a1
- Parent:
- 2:cd1093b6676f
WARNING: Radio API timings changed from micro-seconds to milliseconds; ; Synchronized with https://github.com/Lora-net/LoRaMac-node git revision e506c246652fa44c3f24cecb89d0707b49ece739
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 | 7:b988b60083a1 | 20 | * @brief Radio hardware registers initialization definition |
mluis | 0:45c4f0364ca4 | 21 | * |
mluis | 7:b988b60083a1 | 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 | 7:b988b60083a1 | 29 | { MODEM_FSK , REG_AFCFEI , 0x01 },\ |
mluis | 0:45c4f0364ca4 | 30 | { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA },\ |
mluis | 0:45c4f0364ca4 | 31 | { MODEM_FSK , REG_OSC , 0x07 },\ |
mluis | 0:45c4f0364ca4 | 32 | { MODEM_FSK , REG_SYNCCONFIG , 0x12 },\ |
mluis | 0:45c4f0364ca4 | 33 | { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 },\ |
mluis | 0:45c4f0364ca4 | 34 | { MODEM_FSK , REG_SYNCVALUE2 , 0x94 },\ |
mluis | 0:45c4f0364ca4 | 35 | { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 },\ |
mluis | 0:45c4f0364ca4 | 36 | { MODEM_FSK , REG_PACKETCONFIG1 , 0xD8 },\ |
mluis | 0:45c4f0364ca4 | 37 | { MODEM_FSK , REG_FIFOTHRESH , 0x8F },\ |
mluis | 0:45c4f0364ca4 | 38 | { MODEM_FSK , REG_IMAGECAL , 0x02 },\ |
mluis | 0:45c4f0364ca4 | 39 | { MODEM_FSK , REG_DIOMAPPING1 , 0x00 },\ |
mluis | 0:45c4f0364ca4 | 40 | { MODEM_FSK , REG_DIOMAPPING2 , 0x30 },\ |
mluis | 0:45c4f0364ca4 | 41 | { MODEM_LORA, REG_LR_DETECTOPTIMIZE , 0x43 },\ |
mluis | 0:45c4f0364ca4 | 42 | { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\ |
mluis | 0:45c4f0364ca4 | 43 | } \ |
mluis | 0:45c4f0364ca4 | 44 | |
mluis | 0:45c4f0364ca4 | 45 | /*! |
mluis | 0:45c4f0364ca4 | 46 | * Actual implementation of a SX1272 radio, includes some modifications to make it compatible with the MB1 LAS board |
mluis | 0:45c4f0364ca4 | 47 | */ |
GregCr | 2:cd1093b6676f | 48 | class SX1272MB2xAS : public SX1272 |
mluis | 0:45c4f0364ca4 | 49 | { |
mluis | 0:45c4f0364ca4 | 50 | protected: |
mluis | 0:45c4f0364ca4 | 51 | /*! |
mluis | 0:45c4f0364ca4 | 52 | * Antenna switch GPIO pins objects |
mluis | 0:45c4f0364ca4 | 53 | */ |
mluis | 0:45c4f0364ca4 | 54 | #if defined ( TARGET_MOTE_L152RC ) |
mluis | 0:45c4f0364ca4 | 55 | DigitalOut RfSwitchCntr1; |
mluis | 0:45c4f0364ca4 | 56 | DigitalOut RfSwitchCntr2; |
mluis | 0:45c4f0364ca4 | 57 | DigitalOut PwrAmpCntr; |
dudmuck | 1:b0372ef620d0 | 58 | #elif defined ( TARGET_MTS_MDOT_F411RE ) |
dudmuck | 1:b0372ef620d0 | 59 | DigitalOut TxCtl; |
dudmuck | 1:b0372ef620d0 | 60 | DigitalOut RxCtl; |
mluis | 0:45c4f0364ca4 | 61 | #else |
mluis | 0:45c4f0364ca4 | 62 | DigitalInOut AntSwitch; |
mluis | 0:45c4f0364ca4 | 63 | DigitalIn Fake; |
mluis | 0:45c4f0364ca4 | 64 | #endif |
mluis | 7:b988b60083a1 | 65 | |
mluis | 0:45c4f0364ca4 | 66 | private: |
mluis | 0:45c4f0364ca4 | 67 | static const RadioRegisters_t RadioRegsInit[]; |
mluis | 7:b988b60083a1 | 68 | |
mluis | 0:45c4f0364ca4 | 69 | public: |
GregCr | 2:cd1093b6676f | 70 | SX1272MB2xAS( RadioEvents_t *events, |
mluis | 0:45c4f0364ca4 | 71 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
mluis | 0:45c4f0364ca4 | 72 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, |
mluis | 0:45c4f0364ca4 | 73 | #if defined ( TARGET_MOTE_L152RC ) |
mluis | 0:45c4f0364ca4 | 74 | PinName rfSwitchCntr1, PinName rfSwitchCntr2 ); |
dudmuck | 1:b0372ef620d0 | 75 | #elif defined ( TARGET_MTS_MDOT_F411RE ) |
dudmuck | 1:b0372ef620d0 | 76 | PinName txctl, PinName rxctl ); |
mluis | 0:45c4f0364ca4 | 77 | #else |
mluis | 0:45c4f0364ca4 | 78 | PinName antSwitch ); |
mluis | 0:45c4f0364ca4 | 79 | #endif |
mluis | 7:b988b60083a1 | 80 | |
GregCr | 2:cd1093b6676f | 81 | SX1272MB2xAS( RadioEvents_t *events ); |
mluis | 7:b988b60083a1 | 82 | |
GregCr | 2:cd1093b6676f | 83 | virtual ~SX1272MB2xAS( ) { }; |
mluis | 7:b988b60083a1 | 84 | |
mluis | 7:b988b60083a1 | 85 | protected: |
mluis | 0:45c4f0364ca4 | 86 | /*! |
mluis | 0:45c4f0364ca4 | 87 | * @brief Initializes the radio I/Os pins interface |
mluis | 0:45c4f0364ca4 | 88 | */ |
mluis | 0:45c4f0364ca4 | 89 | virtual void IoInit( void ); |
mluis | 7:b988b60083a1 | 90 | |
mluis | 0:45c4f0364ca4 | 91 | /*! |
mluis | 0:45c4f0364ca4 | 92 | * @brief Initializes the radio registers |
mluis | 0:45c4f0364ca4 | 93 | */ |
mluis | 0:45c4f0364ca4 | 94 | virtual void RadioRegistersInit( ); |
mluis | 0:45c4f0364ca4 | 95 | |
mluis | 0:45c4f0364ca4 | 96 | /*! |
mluis | 0:45c4f0364ca4 | 97 | * @brief Initializes the radio SPI |
mluis | 0:45c4f0364ca4 | 98 | */ |
mluis | 0:45c4f0364ca4 | 99 | virtual void SpiInit( void ); |
mluis | 7:b988b60083a1 | 100 | |
mluis | 0:45c4f0364ca4 | 101 | /*! |
mluis | 0:45c4f0364ca4 | 102 | * @brief Initializes DIO IRQ handlers |
mluis | 0:45c4f0364ca4 | 103 | * |
mluis | 0:45c4f0364ca4 | 104 | * @param [IN] irqHandlers Array containing the IRQ callback functions |
mluis | 0:45c4f0364ca4 | 105 | */ |
mluis | 0:45c4f0364ca4 | 106 | virtual void IoIrqInit( DioIrqHandler *irqHandlers ); |
mluis | 0:45c4f0364ca4 | 107 | |
mluis | 0:45c4f0364ca4 | 108 | /*! |
mluis | 0:45c4f0364ca4 | 109 | * @brief De-initializes the radio I/Os pins interface. |
mluis | 0:45c4f0364ca4 | 110 | * |
mluis | 0:45c4f0364ca4 | 111 | * \remark Useful when going in MCU lowpower modes |
mluis | 0:45c4f0364ca4 | 112 | */ |
mluis | 0:45c4f0364ca4 | 113 | virtual void IoDeInit( void ); |
mluis | 0:45c4f0364ca4 | 114 | |
mluis | 0:45c4f0364ca4 | 115 | /*! |
mluis | 7:b988b60083a1 | 116 | * \brief Sets the radio output power. |
mluis | 7:b988b60083a1 | 117 | * |
mluis | 7:b988b60083a1 | 118 | * @param [IN] power Sets the RF output power |
mluis | 7:b988b60083a1 | 119 | */ |
mluis | 7:b988b60083a1 | 120 | virtual void SetRfTxPower( int8_t power ); |
mluis | 7:b988b60083a1 | 121 | |
mluis | 7:b988b60083a1 | 122 | /*! |
mluis | 0:45c4f0364ca4 | 123 | * @brief Gets the board PA selection configuration |
mluis | 0:45c4f0364ca4 | 124 | * |
mluis | 0:45c4f0364ca4 | 125 | * @param [IN] channel Channel frequency in Hz |
mluis | 0:45c4f0364ca4 | 126 | * @retval PaSelect RegPaConfig PaSelect value |
mluis | 0:45c4f0364ca4 | 127 | */ |
mluis | 0:45c4f0364ca4 | 128 | virtual uint8_t GetPaSelect( uint32_t channel ); |
mluis | 0:45c4f0364ca4 | 129 | |
mluis | 0:45c4f0364ca4 | 130 | /*! |
mluis | 0:45c4f0364ca4 | 131 | * @brief Set the RF Switch I/Os pins in Low Power mode |
mluis | 0:45c4f0364ca4 | 132 | * |
mluis | 0:45c4f0364ca4 | 133 | * @param [IN] status enable or disable |
mluis | 0:45c4f0364ca4 | 134 | */ |
mluis | 0:45c4f0364ca4 | 135 | virtual void SetAntSwLowPower( bool status ); |
mluis | 0:45c4f0364ca4 | 136 | |
mluis | 0:45c4f0364ca4 | 137 | /*! |
mluis | 0:45c4f0364ca4 | 138 | * @brief Initializes the RF Switch I/Os pins interface |
mluis | 0:45c4f0364ca4 | 139 | */ |
mluis | 0:45c4f0364ca4 | 140 | virtual void AntSwInit( void ); |
mluis | 0:45c4f0364ca4 | 141 | |
mluis | 0:45c4f0364ca4 | 142 | /*! |
mluis | 0:45c4f0364ca4 | 143 | * @brief De-initializes the RF Switch I/Os pins interface |
mluis | 0:45c4f0364ca4 | 144 | * |
mluis | 7:b988b60083a1 | 145 | * @remark Needed to decrease the power consumption in MCU lowpower modes |
mluis | 0:45c4f0364ca4 | 146 | */ |
mluis | 0:45c4f0364ca4 | 147 | virtual void AntSwDeInit( void ); |
mluis | 0:45c4f0364ca4 | 148 | |
mluis | 0:45c4f0364ca4 | 149 | /*! |
mluis | 0:45c4f0364ca4 | 150 | * @brief Controls the antena switch if necessary. |
mluis | 0:45c4f0364ca4 | 151 | * |
mluis | 7:b988b60083a1 | 152 | * @remark see errata note |
mluis | 0:45c4f0364ca4 | 153 | * |
mluis | 7:b988b60083a1 | 154 | * @param [IN] opMode Current radio operating mode |
mluis | 0:45c4f0364ca4 | 155 | */ |
mluis | 7:b988b60083a1 | 156 | virtual void SetAntSw( uint8_t opMode ); |
mluis | 7:b988b60083a1 | 157 | |
mluis | 7:b988b60083a1 | 158 | public: |
mluis | 0:45c4f0364ca4 | 159 | /*! |
mluis | 0:45c4f0364ca4 | 160 | * @brief Detect the board connected by reading the value of the antenna switch pin |
mluis | 0:45c4f0364ca4 | 161 | */ |
mluis | 7:b988b60083a1 | 162 | virtual uint8_t DetectBoardType( void ); |
mluis | 7:b988b60083a1 | 163 | |
mluis | 0:45c4f0364ca4 | 164 | /*! |
mluis | 0:45c4f0364ca4 | 165 | * @brief Checks if the given RF frequency is supported by the hardware |
mluis | 0:45c4f0364ca4 | 166 | * |
mluis | 0:45c4f0364ca4 | 167 | * @param [IN] frequency RF frequency to be checked |
mluis | 0:45c4f0364ca4 | 168 | * @retval isSupported [true: supported, false: unsupported] |
mluis | 0:45c4f0364ca4 | 169 | */ |
mluis | 0:45c4f0364ca4 | 170 | virtual bool CheckRfFrequency( uint32_t frequency ); |
mluis | 7:b988b60083a1 | 171 | |
mluis | 7:b988b60083a1 | 172 | /*! |
mluis | 0:45c4f0364ca4 | 173 | * @brief Writes the radio register at the specified address |
mluis | 0:45c4f0364ca4 | 174 | * |
mluis | 0:45c4f0364ca4 | 175 | * @param [IN]: addr Register address |
mluis | 0:45c4f0364ca4 | 176 | * @param [IN]: data New register value |
mluis | 0:45c4f0364ca4 | 177 | */ |
mluis | 0:45c4f0364ca4 | 178 | virtual void Write ( uint8_t addr, uint8_t data ) ; |
mluis | 7:b988b60083a1 | 179 | |
mluis | 0:45c4f0364ca4 | 180 | /*! |
mluis | 0:45c4f0364ca4 | 181 | * @brief Reads the radio register at the specified address |
mluis | 0:45c4f0364ca4 | 182 | * |
mluis | 0:45c4f0364ca4 | 183 | * @param [IN]: addr Register address |
mluis | 0:45c4f0364ca4 | 184 | * @retval data Register value |
mluis | 0:45c4f0364ca4 | 185 | */ |
mluis | 0:45c4f0364ca4 | 186 | virtual uint8_t Read ( uint8_t addr ) ; |
mluis | 7:b988b60083a1 | 187 | |
mluis | 0:45c4f0364ca4 | 188 | /*! |
mluis | 0:45c4f0364ca4 | 189 | * @brief Writes multiple radio registers starting at address |
mluis | 0:45c4f0364ca4 | 190 | * |
mluis | 0:45c4f0364ca4 | 191 | * @param [IN] addr First Radio register address |
mluis | 0:45c4f0364ca4 | 192 | * @param [IN] buffer Buffer containing the new register's values |
mluis | 0:45c4f0364ca4 | 193 | * @param [IN] size Number of registers to be written |
mluis | 0:45c4f0364ca4 | 194 | */ |
mluis | 0:45c4f0364ca4 | 195 | virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
mluis | 7:b988b60083a1 | 196 | |
mluis | 0:45c4f0364ca4 | 197 | /*! |
mluis | 0:45c4f0364ca4 | 198 | * @brief Reads multiple radio registers starting at address |
mluis | 0:45c4f0364ca4 | 199 | * |
mluis | 0:45c4f0364ca4 | 200 | * @param [IN] addr First Radio register address |
mluis | 0:45c4f0364ca4 | 201 | * @param [OUT] buffer Buffer where to copy the registers data |
mluis | 0:45c4f0364ca4 | 202 | * @param [IN] size Number of registers to be read |
mluis | 0:45c4f0364ca4 | 203 | */ |
mluis | 0:45c4f0364ca4 | 204 | virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ; |
mluis | 7:b988b60083a1 | 205 | |
mluis | 0:45c4f0364ca4 | 206 | /*! |
mluis | 0:45c4f0364ca4 | 207 | * @brief Writes the buffer contents to the SX1272 FIFO |
mluis | 0:45c4f0364ca4 | 208 | * |
mluis | 0:45c4f0364ca4 | 209 | * @param [IN] buffer Buffer containing data to be put on the FIFO. |
mluis | 0:45c4f0364ca4 | 210 | * @param [IN] size Number of bytes to be written to the FIFO |
mluis | 0:45c4f0364ca4 | 211 | */ |
mluis | 0:45c4f0364ca4 | 212 | virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ; |
mluis | 0:45c4f0364ca4 | 213 | |
mluis | 0:45c4f0364ca4 | 214 | /*! |
mluis | 0:45c4f0364ca4 | 215 | * @brief Reads the contents of the SX1272 FIFO |
mluis | 0:45c4f0364ca4 | 216 | * |
mluis | 0:45c4f0364ca4 | 217 | * @param [OUT] buffer Buffer where to copy the FIFO read data. |
mluis | 0:45c4f0364ca4 | 218 | * @param [IN] size Number of bytes to be read from the FIFO |
mluis | 0:45c4f0364ca4 | 219 | */ |
mluis | 0:45c4f0364ca4 | 220 | virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ; |
mluis | 7:b988b60083a1 | 221 | |
mluis | 0:45c4f0364ca4 | 222 | /*! |
mluis | 0:45c4f0364ca4 | 223 | * @brief Reset the SX1272 |
mluis | 0:45c4f0364ca4 | 224 | */ |
mluis | 0:45c4f0364ca4 | 225 | virtual void Reset( void ); |
mluis | 0:45c4f0364ca4 | 226 | }; |
mluis | 0:45c4f0364ca4 | 227 | |
mluis | 0:45c4f0364ca4 | 228 | #endif // __SX1272_HAL_H__ |