This library update contains changes according to the HW-modification.

Dependents:   LoRaWAN_Serial_port_driven_and_configurable_ELMO_based_on_TxRx_Template

Fork of SX1272lib by Espotel

Changes compared to original SX1272lib:

HW modification was made to remove RFO-output and replaced with PABOOST-output. PASELECT changed accordingly.

Committer:
KosTee
Date:
Fri Oct 07 11:35:50 2016 +0000
Revision:
13:1af18cdef696
Parent:
12:a3b1b64969b0
RFO & PABOOST transmit modification has been done to some devices.; Selection can be made on sx1272-hal.cpp.; The new transmit route is currently commented on sx1272-hal.cpp, cause majority of devices still use the old route.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WGorniak 0:669f3b0e91c8 1 /*
WGorniak 0:669f3b0e91c8 2 / _____) _ | |
WGorniak 0:669f3b0e91c8 3 ( (____ _____ ____ _| |_ _____ ____| |__
WGorniak 0:669f3b0e91c8 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
WGorniak 0:669f3b0e91c8 5 _____) ) ____| | | || |_| ____( (___| | | |
WGorniak 0:669f3b0e91c8 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
WGorniak 0:669f3b0e91c8 7 ( C ) Semtech
WGorniak 0:669f3b0e91c8 8
WGorniak 0:669f3b0e91c8 9 Description: Port of Semtech SX1276 C++ library to support SX1272 chipset performed by Espotel
WGorniak 0:669f3b0e91c8 10
WGorniak 0:669f3b0e91c8 11 License: Revised BSD License, see LICENSE.TXT file include in the project
WGorniak 0:669f3b0e91c8 12
WGorniak 0:669f3b0e91c8 13 Maintainers: www.espotel.com
WGorniak 0:669f3b0e91c8 14
WGorniak 0:669f3b0e91c8 15 */
WGorniak 0:669f3b0e91c8 16 #include "sx1272-hal.h"
WGorniak 0:669f3b0e91c8 17
mleksio 9:f53b11725565 18 #define TX_STATE 0
WGorniak 5:6740f7ed1d00 19
WGorniak 1:51fd7a5843e5 20 const RadioRegisters_t SX1272BRD::RadioRegsInit[] =
WGorniak 0:669f3b0e91c8 21 {
WGorniak 0:669f3b0e91c8 22 { MODEM_FSK , REG_LNA , 0x23 },
WGorniak 0:669f3b0e91c8 23 { MODEM_FSK , REG_RXCONFIG , 0x1E },
WGorniak 0:669f3b0e91c8 24 { MODEM_FSK , REG_RSSICONFIG , 0xD2 },
WGorniak 0:669f3b0e91c8 25 { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA },
WGorniak 0:669f3b0e91c8 26 { MODEM_FSK , REG_OSC , 0x07 },
WGorniak 0:669f3b0e91c8 27 { MODEM_FSK , REG_SYNCCONFIG , 0x12 },
WGorniak 0:669f3b0e91c8 28 { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 },
WGorniak 0:669f3b0e91c8 29 { MODEM_FSK , REG_SYNCVALUE2 , 0x94 },
WGorniak 0:669f3b0e91c8 30 { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 },
WGorniak 0:669f3b0e91c8 31 { MODEM_FSK , REG_PACKETCONFIG1 , 0x98 },
WGorniak 0:669f3b0e91c8 32 { MODEM_FSK , REG_FIFOTHRESH , 0x8F },
WGorniak 0:669f3b0e91c8 33 { MODEM_FSK , REG_IMAGECAL , 0x02 },
WGorniak 0:669f3b0e91c8 34 { MODEM_FSK , REG_DIOMAPPING1 , 0x00 },
WGorniak 0:669f3b0e91c8 35 { MODEM_FSK , REG_DIOMAPPING2 , 0x30 },
WGorniak 0:669f3b0e91c8 36 { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },
WGorniak 0:669f3b0e91c8 37 };
WGorniak 0:669f3b0e91c8 38
WGorniak 1:51fd7a5843e5 39 SX1272BRD::SX1272BRD( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ),
WGorniak 0:669f3b0e91c8 40 void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ),
WGorniak 0:669f3b0e91c8 41 PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
WGorniak 0:669f3b0e91c8 42 PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
WGorniak 0:669f3b0e91c8 43 PinName antSwitch )
WGorniak 0:669f3b0e91c8 44 : SX1272( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone, mosi, miso, sclk, nss, reset, dio0, dio1, dio2, dio3, dio4, dio5),
WGorniak 0:669f3b0e91c8 45 antSwitch( antSwitch )
WGorniak 0:669f3b0e91c8 46 {
WGorniak 0:669f3b0e91c8 47 Reset( );
WGorniak 0:669f3b0e91c8 48
WGorniak 0:669f3b0e91c8 49 RxChainCalibration( );
WGorniak 0:669f3b0e91c8 50
WGorniak 0:669f3b0e91c8 51 IoInit( );
WGorniak 0:669f3b0e91c8 52
WGorniak 0:669f3b0e91c8 53 SetOpMode( RF_OPMODE_SLEEP );
WGorniak 0:669f3b0e91c8 54
WGorniak 0:669f3b0e91c8 55 IoIrqInit( dioIrq );
WGorniak 0:669f3b0e91c8 56
WGorniak 0:669f3b0e91c8 57 RadioRegistersInit( );
WGorniak 0:669f3b0e91c8 58
WGorniak 0:669f3b0e91c8 59 SetModem( MODEM_FSK );
WGorniak 0:669f3b0e91c8 60
WGorniak 0:669f3b0e91c8 61 this->settings.State = IDLE ;
WGorniak 0:669f3b0e91c8 62 }
WGorniak 0:669f3b0e91c8 63
WGorniak 0:669f3b0e91c8 64
WGorniak 1:51fd7a5843e5 65 SX1272BRD::~SX1272BRD ( )
WGorniak 0:669f3b0e91c8 66 {
WGorniak 0:669f3b0e91c8 67 IoIrqDeInit( );
WGorniak 0:669f3b0e91c8 68 };
WGorniak 0:669f3b0e91c8 69
WGorniak 0:669f3b0e91c8 70 //-------------------------------------------------------------------------
WGorniak 0:669f3b0e91c8 71 // Board relative functions
WGorniak 0:669f3b0e91c8 72 //-------------------------------------------------------------------------
WGorniak 1:51fd7a5843e5 73 void SX1272BRD::IoInit( void )
WGorniak 0:669f3b0e91c8 74 {
WGorniak 0:669f3b0e91c8 75 AntSwInit( );
WGorniak 0:669f3b0e91c8 76 SpiInit( );
WGorniak 0:669f3b0e91c8 77 }
WGorniak 0:669f3b0e91c8 78
WGorniak 1:51fd7a5843e5 79 void SX1272BRD::RadioRegistersInit( ){
WGorniak 0:669f3b0e91c8 80 uint8_t i = 0;
WGorniak 0:669f3b0e91c8 81 for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
WGorniak 0:669f3b0e91c8 82 {
WGorniak 0:669f3b0e91c8 83 SetModem( RadioRegsInit[i].Modem );
WGorniak 0:669f3b0e91c8 84 Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
WGorniak 0:669f3b0e91c8 85 }
WGorniak 0:669f3b0e91c8 86 }
WGorniak 0:669f3b0e91c8 87
WGorniak 1:51fd7a5843e5 88 void SX1272BRD::SpiInit( void )
WGorniak 0:669f3b0e91c8 89 {
WGorniak 0:669f3b0e91c8 90 nss = 1;
WGorniak 0:669f3b0e91c8 91 spi.format( 8,0 );
WGorniak 0:669f3b0e91c8 92 uint32_t frequencyToSet = 8000000;
Daniel_espo 10:070cb8f0f54a 93 #if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) || defined ( TARGET_ELMO_F411RE ) )
WGorniak 0:669f3b0e91c8 94 spi.frequency( frequencyToSet );
WGorniak 0:669f3b0e91c8 95 #elif( defined ( TARGET_KL25Z ) ) //busclock frequency is halved -> double the spi frequency to compensate
WGorniak 0:669f3b0e91c8 96 spi.frequency( frequencyToSet * 2 );
WGorniak 0:669f3b0e91c8 97 #else
WGorniak 0:669f3b0e91c8 98 #warning "Check the board's SPI frequency"
WGorniak 0:669f3b0e91c8 99 #endif
WGorniak 0:669f3b0e91c8 100 wait(0.1);
WGorniak 0:669f3b0e91c8 101 }
WGorniak 0:669f3b0e91c8 102
WGorniak 1:51fd7a5843e5 103 void SX1272BRD::IoIrqInit( DioIrqHandler *irqHandlers )
WGorniak 0:669f3b0e91c8 104 {
WGorniak 0:669f3b0e91c8 105 #if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) )
WGorniak 0:669f3b0e91c8 106 dio0.mode(PullDown);
WGorniak 0:669f3b0e91c8 107 dio1.mode(PullDown);
WGorniak 0:669f3b0e91c8 108 dio2.mode(PullDown);
WGorniak 0:669f3b0e91c8 109 dio3.mode(PullDown);
WGorniak 0:669f3b0e91c8 110 dio4.mode(PullDown);
WGorniak 0:669f3b0e91c8 111 #endif
WGorniak 2:b0a793d995ad 112 dio0.rise( this, static_cast< TriggerSX1272BRD > ( irqHandlers[0] ) );
WGorniak 2:b0a793d995ad 113 dio1.rise( this, static_cast< TriggerSX1272BRD > ( irqHandlers[1] ) );
WGorniak 2:b0a793d995ad 114 dio2.rise( this, static_cast< TriggerSX1272BRD > ( irqHandlers[2] ) );
WGorniak 2:b0a793d995ad 115 dio3.rise( this, static_cast< TriggerSX1272BRD > ( irqHandlers[3] ) );
WGorniak 2:b0a793d995ad 116 dio4.rise( this, static_cast< TriggerSX1272BRD > ( irqHandlers[4] ) );
WGorniak 0:669f3b0e91c8 117 }
WGorniak 0:669f3b0e91c8 118
WGorniak 1:51fd7a5843e5 119 void SX1272BRD::IoIrqDeInit( )
WGorniak 0:669f3b0e91c8 120 {
WGorniak 0:669f3b0e91c8 121 dio0.disable_irq();
WGorniak 0:669f3b0e91c8 122 dio1.disable_irq();
WGorniak 0:669f3b0e91c8 123 dio2.disable_irq();
WGorniak 0:669f3b0e91c8 124 dio3.disable_irq();
WGorniak 0:669f3b0e91c8 125 dio4.disable_irq();
WGorniak 0:669f3b0e91c8 126 }
WGorniak 0:669f3b0e91c8 127
WGorniak 1:51fd7a5843e5 128 void SX1272BRD::IoDeInit( void )
WGorniak 0:669f3b0e91c8 129 {
WGorniak 0:669f3b0e91c8 130 //nothing
WGorniak 0:669f3b0e91c8 131 }
WGorniak 0:669f3b0e91c8 132
WGorniak 1:51fd7a5843e5 133 uint8_t SX1272BRD::GetPaSelect( uint32_t channel )
WGorniak 0:669f3b0e91c8 134 {
KosTee 13:1af18cdef696 135 return RF_PACONFIG_PASELECT_RFO; //Default
KosTee 13:1af18cdef696 136 //return RFLR_PACONFIG_PASELECT_PABOOST; // This modification was done to HW. Default RF0 has been removed from some devices.
WGorniak 0:669f3b0e91c8 137 }
WGorniak 0:669f3b0e91c8 138
WGorniak 1:51fd7a5843e5 139 void SX1272BRD::SetAntSwLowPower( bool status )
WGorniak 0:669f3b0e91c8 140 {
WGorniak 0:669f3b0e91c8 141 if( isRadioActive != status )
WGorniak 0:669f3b0e91c8 142 {
WGorniak 0:669f3b0e91c8 143 isRadioActive = status;
WGorniak 0:669f3b0e91c8 144
WGorniak 0:669f3b0e91c8 145 if( status == false )
WGorniak 0:669f3b0e91c8 146 {
WGorniak 0:669f3b0e91c8 147 AntSwInit( );
WGorniak 0:669f3b0e91c8 148 }
WGorniak 0:669f3b0e91c8 149 else
WGorniak 0:669f3b0e91c8 150 {
WGorniak 0:669f3b0e91c8 151 AntSwDeInit( );
WGorniak 0:669f3b0e91c8 152 }
WGorniak 0:669f3b0e91c8 153 }
WGorniak 0:669f3b0e91c8 154 }
WGorniak 0:669f3b0e91c8 155
WGorniak 5:6740f7ed1d00 156
WGorniak 1:51fd7a5843e5 157 void SX1272BRD::AntSwInit( void )
WGorniak 0:669f3b0e91c8 158 {
WGorniak 5:6740f7ed1d00 159 antSwitch.output();
WGorniak 5:6740f7ed1d00 160 antSwitch = !TX_STATE;
WGorniak 0:669f3b0e91c8 161 }
WGorniak 0:669f3b0e91c8 162
WGorniak 1:51fd7a5843e5 163 void SX1272BRD::AntSwDeInit( void )
WGorniak 0:669f3b0e91c8 164 {
WGorniak 5:6740f7ed1d00 165 antSwitch = !TX_STATE;
WGorniak 0:669f3b0e91c8 166 }
WGorniak 0:669f3b0e91c8 167
WGorniak 1:51fd7a5843e5 168 void SX1272BRD::SetAntSw( uint8_t rxTx )
WGorniak 0:669f3b0e91c8 169 {
WGorniak 5:6740f7ed1d00 170 // if( this->rxTx == rxTx )
WGorniak 5:6740f7ed1d00 171 // {
WGorniak 5:6740f7ed1d00 172 // //no need to go further
WGorniak 5:6740f7ed1d00 173 // return;
WGorniak 5:6740f7ed1d00 174 // }
WGorniak 0:669f3b0e91c8 175
WGorniak 5:6740f7ed1d00 176 // this->rxTx = rxTx;
WGorniak 0:669f3b0e91c8 177
WGorniak 0:669f3b0e91c8 178 if( rxTx != 0 )
WGorniak 0:669f3b0e91c8 179 {
WGorniak 5:6740f7ed1d00 180 antSwitch = TX_STATE;
WGorniak 0:669f3b0e91c8 181 }
WGorniak 0:669f3b0e91c8 182 else
WGorniak 0:669f3b0e91c8 183 {
WGorniak 5:6740f7ed1d00 184 antSwitch = !TX_STATE;
WGorniak 0:669f3b0e91c8 185 }
WGorniak 0:669f3b0e91c8 186 }
WGorniak 0:669f3b0e91c8 187
WGorniak 1:51fd7a5843e5 188 bool SX1272BRD::CheckRfFrequency( uint32_t frequency )
WGorniak 0:669f3b0e91c8 189 {
WGorniak 0:669f3b0e91c8 190 //TODO: Implement check, currently all frequencies are supported
WGorniak 0:669f3b0e91c8 191 return true;
WGorniak 0:669f3b0e91c8 192 }
WGorniak 0:669f3b0e91c8 193
WGorniak 0:669f3b0e91c8 194
WGorniak 1:51fd7a5843e5 195 void SX1272BRD::Reset( void )
WGorniak 0:669f3b0e91c8 196 {
WGorniak 0:669f3b0e91c8 197 reset.output();
WGorniak 0:669f3b0e91c8 198 reset = 1;
WGorniak 0:669f3b0e91c8 199 wait_ms( 1 );
WGorniak 0:669f3b0e91c8 200 reset.input();
WGorniak 0:669f3b0e91c8 201 wait_ms( 6 );
WGorniak 0:669f3b0e91c8 202 }
WGorniak 0:669f3b0e91c8 203
WGorniak 1:51fd7a5843e5 204 void SX1272BRD::Write( uint8_t addr, uint8_t data )
WGorniak 0:669f3b0e91c8 205 {
WGorniak 0:669f3b0e91c8 206 Write( addr, &data, 1 );
WGorniak 0:669f3b0e91c8 207 }
WGorniak 0:669f3b0e91c8 208
WGorniak 1:51fd7a5843e5 209 uint8_t SX1272BRD::Read( uint8_t addr )
WGorniak 0:669f3b0e91c8 210 {
WGorniak 0:669f3b0e91c8 211 uint8_t data;
WGorniak 0:669f3b0e91c8 212 Read( addr, &data, 1 );
WGorniak 0:669f3b0e91c8 213 return data;
WGorniak 0:669f3b0e91c8 214 }
WGorniak 0:669f3b0e91c8 215
WGorniak 1:51fd7a5843e5 216 void SX1272BRD::Write( uint8_t addr, uint8_t *buffer, uint8_t size )
WGorniak 0:669f3b0e91c8 217 {
WGorniak 0:669f3b0e91c8 218 uint8_t i;
WGorniak 0:669f3b0e91c8 219
WGorniak 0:669f3b0e91c8 220 nss = 0;
WGorniak 0:669f3b0e91c8 221 spi.write( addr | 0x80 );
WGorniak 0:669f3b0e91c8 222 for( i = 0; i < size; i++ )
WGorniak 0:669f3b0e91c8 223 {
WGorniak 0:669f3b0e91c8 224 spi.write( buffer[i] );
WGorniak 0:669f3b0e91c8 225 }
WGorniak 0:669f3b0e91c8 226 nss = 1;
WGorniak 0:669f3b0e91c8 227 }
WGorniak 0:669f3b0e91c8 228
WGorniak 1:51fd7a5843e5 229 void SX1272BRD::Read( uint8_t addr, uint8_t *buffer, uint8_t size )
WGorniak 0:669f3b0e91c8 230 {
WGorniak 0:669f3b0e91c8 231 uint8_t i;
WGorniak 0:669f3b0e91c8 232
WGorniak 0:669f3b0e91c8 233 nss = 0;
WGorniak 0:669f3b0e91c8 234 spi.write( addr & 0x7F );
WGorniak 0:669f3b0e91c8 235 for( i = 0; i < size; i++ )
WGorniak 0:669f3b0e91c8 236 {
WGorniak 0:669f3b0e91c8 237 buffer[i] = spi.write( 0 );
WGorniak 0:669f3b0e91c8 238 }
WGorniak 0:669f3b0e91c8 239 nss = 1;
WGorniak 0:669f3b0e91c8 240 }
WGorniak 0:669f3b0e91c8 241
WGorniak 1:51fd7a5843e5 242 void SX1272BRD::WriteFifo( uint8_t *buffer, uint8_t size )
WGorniak 0:669f3b0e91c8 243 {
WGorniak 0:669f3b0e91c8 244 Write( 0, buffer, size );
WGorniak 0:669f3b0e91c8 245 }
WGorniak 0:669f3b0e91c8 246
WGorniak 1:51fd7a5843e5 247 void SX1272BRD::ReadFifo( uint8_t *buffer, uint8_t size )
WGorniak 0:669f3b0e91c8 248 {
WGorniak 0:669f3b0e91c8 249 Read( 0, buffer, size );
WGorniak 0:669f3b0e91c8 250 }