Fork with intent to refactor and add support for American 902-928(915) Frequency Bands

Committer:
Helmut Tschemernjak
Date:
Sun Jun 03 15:07:53 2018 +0200
Revision:
111:c47d5224a2d1
Parent:
110:e04a263e272d
Added support for the Heltec L4 P-CH external power
switch which disables power of the antenna switch in
sleep/suspend mode.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregCr 0:e6ceb13d2d05 1 /*
GregCr 0:e6ceb13d2d05 2 / _____) _ | |
GregCr 0:e6ceb13d2d05 3 ( (____ _____ ____ _| |_ _____ ____| |__
GregCr 0:e6ceb13d2d05 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
GregCr 0:e6ceb13d2d05 5 _____) ) ____| | | || |_| ____( (___| | | |
GregCr 0:e6ceb13d2d05 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mluis 22:7f3aab69cca9 7 (C) 2014 Semtech
GregCr 0:e6ceb13d2d05 8
GregCr 0:e6ceb13d2d05 9 Description: -
GregCr 0:e6ceb13d2d05 10
GregCr 0:e6ceb13d2d05 11 License: Revised BSD License, see LICENSE.TXT file include in the project
GregCr 0:e6ceb13d2d05 12
GregCr 0:e6ceb13d2d05 13 Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
GregCr 0:e6ceb13d2d05 14 */
Helmut Tschemernjak 34:07e89f23c734 15
Helmut Tschemernjak 34:07e89f23c734 16 /*
Helmut Tschemernjak 38:d9189d958db8 17 * additional development to make it more generic across multiple OS versions
Helmut Tschemernjak 34:07e89f23c734 18 * (c) 2017 Helmut Tschemernjak
Helmut Tschemernjak 34:07e89f23c734 19 * 30826 Garbsen (Hannover) Germany
Helmut Tschemernjak 34:07e89f23c734 20 */
Helmut Tschemernjak 34:07e89f23c734 21
Helmut Tschemernjak 65:b2d98328fcba 22 #ifdef ARDUINO
Helmut Tschemernjak 65:b2d98328fcba 23 #include "arduino-mbed.h"
Helmut Tschemernjak 65:b2d98328fcba 24 #endif
Helmut Tschemernjak 65:b2d98328fcba 25
Helmut64 36:f2b885b6f33e 26 #include "sx1276-mbed-hal.h"
GregCr 0:e6ceb13d2d05 27
Helmut Tschemernjak 38:d9189d958db8 28
GregCr 0:e6ceb13d2d05 29
Helmut Tschemernjak 34:07e89f23c734 30 SX1276Generic::SX1276Generic( RadioEvents_t *events, BoardType_t board,
GregCr 0:e6ceb13d2d05 31 PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
GregCr 0:e6ceb13d2d05 32 PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
Helmut Tschemernjak 34:07e89f23c734 33 PinName antSwitch, PinName antSwitchTX, PinName antSwitchTXBoost, PinName tcxo)
Helmut Tschemernjak 34:07e89f23c734 34 : SX1276( events)
GregCr 0:e6ceb13d2d05 35 {
Helmut Tschemernjak 64:b721e6ab656a 36 Sleep_ms( 10 );
mluis 21:2e496deb7858 37 this->RadioEvents = events;
Helmut Tschemernjak 34:07e89f23c734 38 boardConnected = board;
Helmut Tschemernjak 34:07e89f23c734 39
Helmut Tschemernjak 111:c47d5224a2d1 40 _antSwitchPwr = NULL;
Helmut Tschemernjak 34:07e89f23c734 41 _antSwitch = NULL;
Helmut Tschemernjak 34:07e89f23c734 42 _antSwitchTX = NULL;
Helmut Tschemernjak 34:07e89f23c734 43 _antSwitchTXBoost = NULL;
Helmut Tschemernjak 34:07e89f23c734 44
Helmut Tschemernjak 34:07e89f23c734 45 _tcxo = NULL;
Helmut Tschemernjak 34:07e89f23c734 46 if (tcxo != NC)
Helmut Tschemernjak 34:07e89f23c734 47 _tcxo = new DigitalOut(tcxo);
Helmut Tschemernjak 34:07e89f23c734 48
Helmut Tschemernjak 34:07e89f23c734 49 switch(boardConnected) {
Helmut Tschemernjak 34:07e89f23c734 50 case SX1276MB1MAS:
Helmut Tschemernjak 34:07e89f23c734 51 case SX1276MB1LAS:
Helmut Tschemernjak 46:e78a1d0391ac 52 _antSwitch = new DigitalOut(antSwitch);
Helmut Tschemernjak 34:07e89f23c734 53 break;
Helmut Tschemernjak 34:07e89f23c734 54 case RFM95_SX1276:
Helmut Tschemernjak 34:07e89f23c734 55 break;
Helmut Tschemernjak 111:c47d5224a2d1 56 case HELTEC_L4_1276:
Helmut Tschemernjak 111:c47d5224a2d1 57 _antSwitchPwr = new DigitalOut(antSwitch);
Helmut Tschemernjak 111:c47d5224a2d1 58 break;
Helmut Tschemernjak 34:07e89f23c734 59 case MURATA_SX1276:
Helmut Tschemernjak 46:e78a1d0391ac 60 _antSwitch = new DigitalOut(antSwitch);
Helmut Tschemernjak 46:e78a1d0391ac 61 _antSwitchTX = new DigitalOut(antSwitchTX);
Helmut Tschemernjak 46:e78a1d0391ac 62 _antSwitchTXBoost = new DigitalOut(antSwitchTXBoost);
Helmut Tschemernjak 34:07e89f23c734 63 break;
Helmut Tschemernjak 34:07e89f23c734 64 default:
Helmut Tschemernjak 34:07e89f23c734 65 break;
Helmut Tschemernjak 34:07e89f23c734 66 }
Helmut Tschemernjak 65:b2d98328fcba 67 _spi = new XSPI(mosi, miso, sclk );
Helmut Tschemernjak 34:07e89f23c734 68 _nss = new DigitalOut(nss);
Helmut Tschemernjak 34:07e89f23c734 69
Helmut Tschemernjak 34:07e89f23c734 70 _reset = new DigitalInOut(reset);
Helmut Tschemernjak 34:07e89f23c734 71
Helmut Tschemernjak 34:07e89f23c734 72 _dio0 = NULL;
Helmut Tschemernjak 34:07e89f23c734 73 _dio1 = NULL;
Helmut Tschemernjak 34:07e89f23c734 74 _dio2 = NULL;
Helmut Tschemernjak 34:07e89f23c734 75 _dio3 = NULL;
Helmut Tschemernjak 34:07e89f23c734 76 _dio4 = NULL;
Helmut Tschemernjak 34:07e89f23c734 77 _dio5 = NULL;
Helmut Tschemernjak 34:07e89f23c734 78 if (dio0 != NC)
Helmut Tschemernjak 34:07e89f23c734 79 _dio0 = new InterruptIn(dio0);
Helmut Tschemernjak 34:07e89f23c734 80 if (dio1 != NC)
Helmut Tschemernjak 34:07e89f23c734 81 _dio1 = new InterruptIn(dio1);
Helmut Tschemernjak 34:07e89f23c734 82 if (dio2 != NC)
Helmut Tschemernjak 34:07e89f23c734 83 _dio2 = new InterruptIn(dio2);
Helmut Tschemernjak 34:07e89f23c734 84 if (dio3 != NC)
Helmut Tschemernjak 34:07e89f23c734 85 _dio3 = new InterruptIn(dio3);
Helmut Tschemernjak 34:07e89f23c734 86 if (dio4 != NC)
Helmut Tschemernjak 34:07e89f23c734 87 _dio4 = new InterruptIn(dio4);
Helmut Tschemernjak 34:07e89f23c734 88 if (dio5 != NC)
Helmut Tschemernjak 34:07e89f23c734 89 _dio5 = new DigitalIn(dio5);
Helmut Tschemernjak 34:07e89f23c734 90
GregCr 0:e6ceb13d2d05 91 Reset( );
mluis 25:3778e6204cc1 92
GregCr 0:e6ceb13d2d05 93 IoInit( );
mluis 25:3778e6204cc1 94
Helmut Tschemernjak 34:07e89f23c734 95 RxChainCalibration( );
Helmut Tschemernjak 34:07e89f23c734 96
GregCr 0:e6ceb13d2d05 97 SetOpMode( RF_OPMODE_SLEEP );
mluis 25:3778e6204cc1 98
GregCr 0:e6ceb13d2d05 99 IoIrqInit( dioIrq );
mluis 25:3778e6204cc1 100
GregCr 0:e6ceb13d2d05 101 RadioRegistersInit( );
GregCr 0:e6ceb13d2d05 102
GregCr 0:e6ceb13d2d05 103 SetModem( MODEM_FSK );
GregCr 0:e6ceb13d2d05 104 }
GregCr 0:e6ceb13d2d05 105
Helmut Tschemernjak 34:07e89f23c734 106 SX1276Generic::~SX1276Generic()
GregCr 0:e6ceb13d2d05 107 {
Helmut Tschemernjak 90:d98572047c9c 108 txTimeoutTimer.detach();
Helmut Tschemernjak 90:d98572047c9c 109 rxTimeoutTimer.detach();
Helmut Tschemernjak 90:d98572047c9c 110 rxTimeoutSyncWord.detach();
Helmut Tschemernjak 90:d98572047c9c 111
Helmut Tschemernjak 111:c47d5224a2d1 112 if (_antSwitchPwr)
Helmut Tschemernjak 111:c47d5224a2d1 113 delete(_antSwitchPwr);
Helmut Tschemernjak 34:07e89f23c734 114 if (_antSwitch)
Helmut Tschemernjak 34:07e89f23c734 115 delete _antSwitch;
Helmut Tschemernjak 34:07e89f23c734 116 if (_antSwitchTX)
Helmut Tschemernjak 34:07e89f23c734 117 delete _antSwitchTX;
Helmut Tschemernjak 34:07e89f23c734 118 if (_antSwitchTXBoost)
Helmut Tschemernjak 34:07e89f23c734 119 delete _antSwitchTXBoost;
Helmut Tschemernjak 34:07e89f23c734 120
Helmut Tschemernjak 34:07e89f23c734 121 if (_tcxo) {
Helmut Tschemernjak 34:07e89f23c734 122 *_tcxo = 0;
Helmut Tschemernjak 34:07e89f23c734 123 delete (_tcxo);
Helmut Tschemernjak 34:07e89f23c734 124 }
Helmut Tschemernjak 110:e04a263e272d 125 /*
Helmut Tschemernjak 110:e04a263e272d 126 * Reset(); // to put chip back into fresh state
Helmut Tschemernjak 110:e04a263e272d 127 * We disabled the Reset() to allow the destructor to keep the
Helmut Tschemernjak 110:e04a263e272d 128 * chip in Sleep() mode to stay turned off with little energy
Helmut Tschemernjak 110:e04a263e272d 129 * consumption.
Helmut Tschemernjak 110:e04a263e272d 130 */
Helmut Tschemernjak 34:07e89f23c734 131 delete _reset;
Helmut Tschemernjak 34:07e89f23c734 132 delete _spi;
Helmut Tschemernjak 34:07e89f23c734 133 delete _nss;
Helmut Tschemernjak 34:07e89f23c734 134
Helmut Tschemernjak 34:07e89f23c734 135 if (_dio0)
Helmut Tschemernjak 34:07e89f23c734 136 delete _dio0;
Helmut Tschemernjak 34:07e89f23c734 137 if (_dio1)
Helmut Tschemernjak 34:07e89f23c734 138 delete _dio1;
Helmut Tschemernjak 34:07e89f23c734 139 if (_dio2)
Helmut Tschemernjak 34:07e89f23c734 140 delete _dio2;
Helmut Tschemernjak 34:07e89f23c734 141 if (_dio3)
Helmut Tschemernjak 34:07e89f23c734 142 delete _dio3;
Helmut Tschemernjak 34:07e89f23c734 143 if (_dio4)
Helmut Tschemernjak 34:07e89f23c734 144 delete _dio4;
Helmut Tschemernjak 34:07e89f23c734 145 if (_dio5)
Helmut Tschemernjak 34:07e89f23c734 146 delete _dio5;
GregCr 0:e6ceb13d2d05 147 }
GregCr 0:e6ceb13d2d05 148
Helmut Tschemernjak 38:d9189d958db8 149
GregCr 0:e6ceb13d2d05 150 //-------------------------------------------------------------------------
GregCr 0:e6ceb13d2d05 151 // Board relative functions
GregCr 0:e6ceb13d2d05 152 //-------------------------------------------------------------------------
Helmut Tschemernjak 34:07e89f23c734 153 uint8_t SX1276Generic::DetectBoardType( void )
GregCr 1:f979673946c0 154 {
Helmut Tschemernjak 34:07e89f23c734 155 return boardConnected;
GregCr 1:f979673946c0 156 }
GregCr 0:e6ceb13d2d05 157
Helmut Tschemernjak 34:07e89f23c734 158 void SX1276Generic::IoInit( void )
GregCr 0:e6ceb13d2d05 159 {
Helmut Tschemernjak 34:07e89f23c734 160 if (_tcxo)
Helmut Tschemernjak 34:07e89f23c734 161 *_tcxo = 1;
GregCr 0:e6ceb13d2d05 162 AntSwInit( );
GregCr 0:e6ceb13d2d05 163 SpiInit( );
GregCr 0:e6ceb13d2d05 164 }
GregCr 0:e6ceb13d2d05 165
GregCr 0:e6ceb13d2d05 166
Helmut Tschemernjak 34:07e89f23c734 167 void SX1276Generic::SpiInit( void )
GregCr 0:e6ceb13d2d05 168 {
Helmut Tschemernjak 34:07e89f23c734 169 *_nss = 1;
Helmut Tschemernjak 34:07e89f23c734 170 _spi->format( 8,0 );
GregCr 0:e6ceb13d2d05 171 uint32_t frequencyToSet = 8000000;
Helmut Tschemernjak 34:07e89f23c734 172 #ifdef TARGET_KL25Z //busclock frequency is halved -> double the spi frequency to compensate
Helmut Tschemernjak 34:07e89f23c734 173 _spi->frequency( frequencyToSet * 2 );
Helmut Tschemernjak 34:07e89f23c734 174 #else
Helmut Tschemernjak 34:07e89f23c734 175 _spi->frequency( frequencyToSet );
Helmut Tschemernjak 34:07e89f23c734 176 #endif
Helmut Tschemernjak 34:07e89f23c734 177 wait_ms(100);
GregCr 0:e6ceb13d2d05 178 }
GregCr 0:e6ceb13d2d05 179
Helmut Tschemernjak 34:07e89f23c734 180 void SX1276Generic::IoIrqInit( DioIrqHandler *irqHandlers )
GregCr 0:e6ceb13d2d05 181 {
Helmut Tschemernjak 34:07e89f23c734 182 if (_dio0)
Helmut Tschemernjak 39:706c32eda7e7 183 _dio0->rise(callback(this, static_cast< Trigger > ( irqHandlers[0] )));
Helmut Tschemernjak 94:e6c0279f550a 184 else
Helmut Tschemernjak 94:e6c0279f550a 185 irqHandlers[0] = NULL;
Helmut Tschemernjak 94:e6c0279f550a 186
Helmut Tschemernjak 34:07e89f23c734 187 if (_dio1)
Helmut Tschemernjak 39:706c32eda7e7 188 _dio1->rise(callback(this, static_cast< Trigger > ( irqHandlers[1] )));
Helmut Tschemernjak 94:e6c0279f550a 189 else
Helmut Tschemernjak 94:e6c0279f550a 190 irqHandlers[1] = NULL;
Helmut Tschemernjak 94:e6c0279f550a 191
Helmut Tschemernjak 34:07e89f23c734 192 if (_dio2)
Helmut Tschemernjak 39:706c32eda7e7 193 _dio2->rise(callback(this, static_cast< Trigger > ( irqHandlers[2] )));
Helmut Tschemernjak 94:e6c0279f550a 194 else
Helmut Tschemernjak 94:e6c0279f550a 195 irqHandlers[2] = NULL;
Helmut Tschemernjak 94:e6c0279f550a 196
Helmut Tschemernjak 34:07e89f23c734 197 if (_dio3)
Helmut Tschemernjak 39:706c32eda7e7 198 _dio3->rise(callback(this, static_cast< Trigger > ( irqHandlers[3] )));
Helmut Tschemernjak 94:e6c0279f550a 199 else
Helmut Tschemernjak 94:e6c0279f550a 200 irqHandlers[3] = NULL;
Helmut Tschemernjak 94:e6c0279f550a 201
Helmut Tschemernjak 34:07e89f23c734 202 if (_dio4)
Helmut Tschemernjak 39:706c32eda7e7 203 _dio4->rise(callback(this, static_cast< Trigger > ( irqHandlers[4] )));
Helmut Tschemernjak 94:e6c0279f550a 204 else
Helmut Tschemernjak 94:e6c0279f550a 205 irqHandlers[4] = NULL;
GregCr 0:e6ceb13d2d05 206 }
GregCr 0:e6ceb13d2d05 207
Helmut Tschemernjak 34:07e89f23c734 208 void SX1276Generic::IoDeInit( void )
GregCr 0:e6ceb13d2d05 209 {
GregCr 0:e6ceb13d2d05 210 //nothing
GregCr 0:e6ceb13d2d05 211 }
GregCr 0:e6ceb13d2d05 212
Helmut Tschemernjak 34:07e89f23c734 213 void SX1276Generic::SetRfTxPower( int8_t power )
Helmut Tschemernjak 31:e50929bd3f32 214 {
Helmut Tschemernjak 31:e50929bd3f32 215 uint8_t paConfig = 0;
Helmut Tschemernjak 31:e50929bd3f32 216 uint8_t paDac = 0;
Helmut Tschemernjak 31:e50929bd3f32 217
Helmut Tschemernjak 31:e50929bd3f32 218 paConfig = Read( REG_PACONFIG );
Helmut Tschemernjak 31:e50929bd3f32 219 paDac = Read( REG_PADAC );
Helmut Tschemernjak 31:e50929bd3f32 220
Helmut Tschemernjak 31:e50929bd3f32 221 paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | GetPaSelect( this->settings.Channel );
Helmut Tschemernjak 31:e50929bd3f32 222 paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
Helmut Tschemernjak 31:e50929bd3f32 223
Helmut Tschemernjak 31:e50929bd3f32 224 if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
Helmut Tschemernjak 31:e50929bd3f32 225 {
Helmut Tschemernjak 31:e50929bd3f32 226 if( power > 17 )
Helmut Tschemernjak 31:e50929bd3f32 227 {
Helmut Tschemernjak 31:e50929bd3f32 228 paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
Helmut Tschemernjak 31:e50929bd3f32 229 }
Helmut Tschemernjak 31:e50929bd3f32 230 else
Helmut Tschemernjak 31:e50929bd3f32 231 {
Helmut Tschemernjak 31:e50929bd3f32 232 paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
Helmut Tschemernjak 31:e50929bd3f32 233 }
Helmut Tschemernjak 31:e50929bd3f32 234 if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
Helmut Tschemernjak 31:e50929bd3f32 235 {
Helmut Tschemernjak 31:e50929bd3f32 236 if( power < 5 )
Helmut Tschemernjak 31:e50929bd3f32 237 {
Helmut Tschemernjak 31:e50929bd3f32 238 power = 5;
Helmut Tschemernjak 31:e50929bd3f32 239 }
Helmut Tschemernjak 31:e50929bd3f32 240 if( power > 20 )
Helmut Tschemernjak 31:e50929bd3f32 241 {
Helmut Tschemernjak 31:e50929bd3f32 242 power = 20;
Helmut Tschemernjak 31:e50929bd3f32 243 }
Helmut Tschemernjak 31:e50929bd3f32 244 paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
Helmut Tschemernjak 31:e50929bd3f32 245 }
Helmut Tschemernjak 31:e50929bd3f32 246 else
Helmut Tschemernjak 31:e50929bd3f32 247 {
Helmut Tschemernjak 31:e50929bd3f32 248 if( power < 2 )
Helmut Tschemernjak 31:e50929bd3f32 249 {
Helmut Tschemernjak 31:e50929bd3f32 250 power = 2;
Helmut Tschemernjak 31:e50929bd3f32 251 }
Helmut Tschemernjak 31:e50929bd3f32 252 if( power > 17 )
Helmut Tschemernjak 31:e50929bd3f32 253 {
Helmut Tschemernjak 31:e50929bd3f32 254 power = 17;
Helmut Tschemernjak 31:e50929bd3f32 255 }
Helmut Tschemernjak 31:e50929bd3f32 256 paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
Helmut Tschemernjak 31:e50929bd3f32 257 }
Helmut Tschemernjak 31:e50929bd3f32 258 }
Helmut Tschemernjak 31:e50929bd3f32 259 else
Helmut Tschemernjak 31:e50929bd3f32 260 {
Helmut Tschemernjak 31:e50929bd3f32 261 if( power < -1 )
Helmut Tschemernjak 31:e50929bd3f32 262 {
Helmut Tschemernjak 31:e50929bd3f32 263 power = -1;
Helmut Tschemernjak 31:e50929bd3f32 264 }
Helmut Tschemernjak 31:e50929bd3f32 265 if( power > 14 )
Helmut Tschemernjak 31:e50929bd3f32 266 {
Helmut Tschemernjak 31:e50929bd3f32 267 power = 14;
Helmut Tschemernjak 31:e50929bd3f32 268 }
Helmut Tschemernjak 31:e50929bd3f32 269 paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
Helmut Tschemernjak 31:e50929bd3f32 270 }
Helmut Tschemernjak 31:e50929bd3f32 271 Write( REG_PACONFIG, paConfig );
Helmut Tschemernjak 31:e50929bd3f32 272 Write( REG_PADAC, paDac );
Helmut Tschemernjak 31:e50929bd3f32 273 }
Helmut Tschemernjak 31:e50929bd3f32 274
Helmut Tschemernjak 31:e50929bd3f32 275
Helmut Tschemernjak 34:07e89f23c734 276 uint8_t SX1276Generic::GetPaSelect( uint32_t channel )
GregCr 0:e6ceb13d2d05 277 {
GregCr 0:e6ceb13d2d05 278 if( channel > RF_MID_BAND_THRESH )
GregCr 0:e6ceb13d2d05 279 {
Helmut Tschemernjak 111:c47d5224a2d1 280 if (boardConnected == SX1276MB1LAS || boardConnected == RFM95_SX1276 || boardConnected == MURATA_SX1276 || boardConnected == HELTEC_L4_1276)
GregCr 1:f979673946c0 281 {
GregCr 1:f979673946c0 282 return RF_PACONFIG_PASELECT_PABOOST;
GregCr 1:f979673946c0 283 }
GregCr 1:f979673946c0 284 else
GregCr 1:f979673946c0 285 {
GregCr 1:f979673946c0 286 return RF_PACONFIG_PASELECT_RFO;
GregCr 1:f979673946c0 287 }
GregCr 0:e6ceb13d2d05 288 }
GregCr 0:e6ceb13d2d05 289 else
GregCr 0:e6ceb13d2d05 290 {
GregCr 0:e6ceb13d2d05 291 return RF_PACONFIG_PASELECT_RFO;
GregCr 0:e6ceb13d2d05 292 }
GregCr 0:e6ceb13d2d05 293 }
GregCr 0:e6ceb13d2d05 294
Helmut Tschemernjak 34:07e89f23c734 295 void SX1276Generic::SetAntSwLowPower( bool status )
GregCr 0:e6ceb13d2d05 296 {
GregCr 0:e6ceb13d2d05 297 if( isRadioActive != status )
GregCr 0:e6ceb13d2d05 298 {
GregCr 0:e6ceb13d2d05 299 isRadioActive = status;
GregCr 0:e6ceb13d2d05 300
GregCr 0:e6ceb13d2d05 301 if( status == false )
GregCr 0:e6ceb13d2d05 302 {
GregCr 0:e6ceb13d2d05 303 AntSwInit( );
GregCr 0:e6ceb13d2d05 304 }
GregCr 0:e6ceb13d2d05 305 else
GregCr 0:e6ceb13d2d05 306 {
GregCr 0:e6ceb13d2d05 307 AntSwDeInit( );
GregCr 0:e6ceb13d2d05 308 }
GregCr 0:e6ceb13d2d05 309 }
GregCr 0:e6ceb13d2d05 310 }
GregCr 0:e6ceb13d2d05 311
Helmut Tschemernjak 34:07e89f23c734 312 void SX1276Generic::AntSwInit( void )
GregCr 0:e6ceb13d2d05 313 {
Helmut Tschemernjak 34:07e89f23c734 314 if (_antSwitch)
Helmut Tschemernjak 34:07e89f23c734 315 *_antSwitch = 0;
Helmut Tschemernjak 34:07e89f23c734 316 if (boardConnected == MURATA_SX1276) {
Helmut Tschemernjak 34:07e89f23c734 317 *_antSwitchTX = 0;
Helmut Tschemernjak 34:07e89f23c734 318 *_antSwitchTXBoost = 0;
Helmut Tschemernjak 34:07e89f23c734 319 }
Helmut Tschemernjak 111:c47d5224a2d1 320 if (boardConnected == HELTEC_L4_1276)
Helmut Tschemernjak 111:c47d5224a2d1 321 *_antSwitchPwr = PWR_OFF;
GregCr 0:e6ceb13d2d05 322 }
GregCr 0:e6ceb13d2d05 323
Helmut Tschemernjak 34:07e89f23c734 324 void SX1276Generic::AntSwDeInit( void )
GregCr 0:e6ceb13d2d05 325 {
Helmut Tschemernjak 34:07e89f23c734 326 if (_antSwitch)
Helmut Tschemernjak 34:07e89f23c734 327 *_antSwitch = 0;
Helmut Tschemernjak 34:07e89f23c734 328 if (boardConnected == MURATA_SX1276) {
Helmut Tschemernjak 34:07e89f23c734 329 *_antSwitchTX = 0;
Helmut Tschemernjak 34:07e89f23c734 330 *_antSwitchTXBoost = 0;
Helmut Tschemernjak 34:07e89f23c734 331 }
Helmut Tschemernjak 111:c47d5224a2d1 332 if (boardConnected == HELTEC_L4_1276)
Helmut Tschemernjak 111:c47d5224a2d1 333 *_antSwitchPwr = PWR_OFF;
GregCr 0:e6ceb13d2d05 334 }
GregCr 0:e6ceb13d2d05 335
Helmut Tschemernjak 31:e50929bd3f32 336
Helmut Tschemernjak 34:07e89f23c734 337 void SX1276Generic::SetAntSw( uint8_t opMode )
GregCr 0:e6ceb13d2d05 338 {
Helmut Tschemernjak 31:e50929bd3f32 339 switch( opMode )
GregCr 0:e6ceb13d2d05 340 {
Helmut Tschemernjak 31:e50929bd3f32 341 case RFLR_OPMODE_TRANSMITTER:
Helmut Tschemernjak 34:07e89f23c734 342 if (boardConnected == MURATA_SX1276) {
Helmut Tschemernjak 34:07e89f23c734 343 *_antSwitch = 0;// Murata-RX
Helmut Tschemernjak 41:2dbc4afedf61 344 if (Read( REG_PACONFIG) & RF_PACONFIG_PASELECT_PABOOST)
Helmut Tschemernjak 41:2dbc4afedf61 345 *_antSwitchTXBoost = 1;
Helmut Tschemernjak 41:2dbc4afedf61 346 else
Helmut Tschemernjak 41:2dbc4afedf61 347 *_antSwitchTX = 1; // alternate: antSwitchTXBoost = 1
Helmut Tschemernjak 35:c278a826a8e2 348 } else {
Helmut Tschemernjak 34:07e89f23c734 349 if (_antSwitch)
Helmut Tschemernjak 34:07e89f23c734 350 *_antSwitch = 1;
Helmut Tschemernjak 34:07e89f23c734 351 }
Helmut Tschemernjak 111:c47d5224a2d1 352 if (boardConnected == HELTEC_L4_1276)
Helmut Tschemernjak 111:c47d5224a2d1 353 *_antSwitchPwr = PWR_ON;
Helmut Tschemernjak 31:e50929bd3f32 354 break;
Helmut Tschemernjak 31:e50929bd3f32 355 case RFLR_OPMODE_RECEIVER:
Helmut Tschemernjak 31:e50929bd3f32 356 case RFLR_OPMODE_RECEIVER_SINGLE:
Helmut Tschemernjak 31:e50929bd3f32 357 case RFLR_OPMODE_CAD:
Helmut Tschemernjak 34:07e89f23c734 358 if (boardConnected == MURATA_SX1276) {
Helmut Tschemernjak 34:07e89f23c734 359 *_antSwitch = 1; // Murata-RX
Helmut Tschemernjak 34:07e89f23c734 360 *_antSwitchTX = 0;
Helmut Tschemernjak 34:07e89f23c734 361 *_antSwitchTXBoost = 0;
Helmut Tschemernjak 111:c47d5224a2d1 362 } else if (boardConnected == HELTEC_L4_1276) {
Helmut Tschemernjak 111:c47d5224a2d1 363 *_antSwitchPwr = PWR_ON;
Helmut Tschemernjak 111:c47d5224a2d1 364 } else {
Helmut Tschemernjak 34:07e89f23c734 365 if (_antSwitch)
Helmut Tschemernjak 34:07e89f23c734 366 _antSwitch = 0;
Helmut Tschemernjak 34:07e89f23c734 367 }
Helmut Tschemernjak 31:e50929bd3f32 368 break;
Helmut Tschemernjak 41:2dbc4afedf61 369 case RFLR_OPMODE_SLEEP:
Helmut Tschemernjak 41:2dbc4afedf61 370 case RFLR_OPMODE_STANDBY:
Helmut Tschemernjak 31:e50929bd3f32 371 default:
Helmut Tschemernjak 34:07e89f23c734 372 if (boardConnected == MURATA_SX1276) {
Helmut Tschemernjak 34:07e89f23c734 373 *_antSwitch = 0; //Murata-RX
Helmut Tschemernjak 34:07e89f23c734 374 *_antSwitchTX = 0;
Helmut Tschemernjak 34:07e89f23c734 375 *_antSwitchTXBoost = 0;
Helmut Tschemernjak 111:c47d5224a2d1 376 } else if (boardConnected == HELTEC_L4_1276) {
Helmut Tschemernjak 111:c47d5224a2d1 377 *_antSwitchPwr = PWR_OFF;
Helmut Tschemernjak 111:c47d5224a2d1 378 } else {
Helmut Tschemernjak 34:07e89f23c734 379 if (_antSwitch)
Helmut Tschemernjak 34:07e89f23c734 380 *_antSwitch = 0;
Helmut Tschemernjak 34:07e89f23c734 381 }
Helmut Tschemernjak 31:e50929bd3f32 382 break;
GregCr 0:e6ceb13d2d05 383 }
GregCr 0:e6ceb13d2d05 384 }
GregCr 0:e6ceb13d2d05 385
Helmut Tschemernjak 44:544add59b26d 386 void SX1276Generic::SetTimeout(TimeoutTimer_t timer, timeoutFuncPtr func, int timeout_ms)
Helmut Tschemernjak 38:d9189d958db8 387 {
Helmut Tschemernjak 42:72deced1a4c4 388 switch(timer) {
Helmut Tschemernjak 42:72deced1a4c4 389 case RXTimeoutTimer:
Helmut Tschemernjak 44:544add59b26d 390 if (func)
Helmut Tschemernjak 44:544add59b26d 391 rxTimeoutTimer.attach_us(callback(this, func), timeout_ms);
Helmut Tschemernjak 42:72deced1a4c4 392 else
Helmut Tschemernjak 42:72deced1a4c4 393 rxTimeoutTimer.detach();
Helmut Tschemernjak 42:72deced1a4c4 394 break;
Helmut Tschemernjak 42:72deced1a4c4 395 case TXTimeoutTimer:
Helmut Tschemernjak 44:544add59b26d 396 if (func)
Helmut Tschemernjak 44:544add59b26d 397 txTimeoutTimer.attach_us(callback(this, func), timeout_ms);
Helmut Tschemernjak 42:72deced1a4c4 398 else
Helmut Tschemernjak 42:72deced1a4c4 399 txTimeoutTimer.detach();
Helmut Tschemernjak 42:72deced1a4c4 400 break;
Helmut Tschemernjak 53:6d3adad59633 401 case RXTimeoutSyncWordTimer:
Helmut Tschemernjak 44:544add59b26d 402 if (func)
Helmut Tschemernjak 44:544add59b26d 403 rxTimeoutSyncWord.attach_us(callback(this, func), timeout_ms);
Helmut Tschemernjak 42:72deced1a4c4 404 else
Helmut Tschemernjak 42:72deced1a4c4 405 rxTimeoutSyncWord.detach();
Helmut Tschemernjak 42:72deced1a4c4 406 break;
Helmut Tschemernjak 42:72deced1a4c4 407 }
Helmut Tschemernjak 38:d9189d958db8 408 }
Helmut Tschemernjak 38:d9189d958db8 409
Helmut Tschemernjak 64:b721e6ab656a 410 void
Helmut Tschemernjak 64:b721e6ab656a 411 SX1276Generic::Sleep_ms(int ms)
Helmut Tschemernjak 64:b721e6ab656a 412 {
Helmut Tschemernjak 64:b721e6ab656a 413 wait_ms(ms);
Helmut Tschemernjak 64:b721e6ab656a 414 }
Helmut Tschemernjak 64:b721e6ab656a 415
Helmut Tschemernjak 34:07e89f23c734 416 bool SX1276Generic::CheckRfFrequency( uint32_t frequency )
GregCr 0:e6ceb13d2d05 417 {
Helmut Tschemernjak 65:b2d98328fcba 418 if (frequency > 1200000)
Helmut Tschemernjak 65:b2d98328fcba 419 return false;
Helmut Tschemernjak 31:e50929bd3f32 420 // Implement check. Currently all frequencies are supported
GregCr 0:e6ceb13d2d05 421 return true;
GregCr 0:e6ceb13d2d05 422 }
GregCr 0:e6ceb13d2d05 423
Helmut Tschemernjak 34:07e89f23c734 424 void SX1276Generic::Reset( void )
GregCr 0:e6ceb13d2d05 425 {
Helmut Tschemernjak 34:07e89f23c734 426 _reset->output();
Helmut Tschemernjak 34:07e89f23c734 427 *_reset = 0;
Helmut Tschemernjak 31:e50929bd3f32 428 wait_ms( 1 );
Helmut Tschemernjak 34:07e89f23c734 429 *_reset = 1;
Helmut Tschemernjak 108:3d7cfa8b8519 430 _reset->input(); // I don't know why input again, maybe to save power (Helmut T)
Helmut Tschemernjak 31:e50929bd3f32 431 wait_ms( 6 );
GregCr 0:e6ceb13d2d05 432 }
Helmut Tschemernjak 31:e50929bd3f32 433
Helmut Tschemernjak 34:07e89f23c734 434 void SX1276Generic::Write( uint8_t addr, uint8_t data )
GregCr 0:e6ceb13d2d05 435 {
GregCr 0:e6ceb13d2d05 436 Write( addr, &data, 1 );
GregCr 0:e6ceb13d2d05 437 }
GregCr 0:e6ceb13d2d05 438
Helmut Tschemernjak 34:07e89f23c734 439 uint8_t SX1276Generic::Read( uint8_t addr )
GregCr 0:e6ceb13d2d05 440 {
GregCr 0:e6ceb13d2d05 441 uint8_t data;
GregCr 0:e6ceb13d2d05 442 Read( addr, &data, 1 );
GregCr 0:e6ceb13d2d05 443 return data;
GregCr 0:e6ceb13d2d05 444 }
GregCr 0:e6ceb13d2d05 445
Helmut Tschemernjak 51:aef3234bcb71 446 void SX1276Generic::Write( uint8_t addr, void *buffer, uint8_t size )
GregCr 0:e6ceb13d2d05 447 {
GregCr 0:e6ceb13d2d05 448 uint8_t i;
Helmut Tschemernjak 51:aef3234bcb71 449 uint8_t *p = (uint8_t *)buffer;
GregCr 0:e6ceb13d2d05 450
Helmut Tschemernjak 34:07e89f23c734 451 *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut
Helmut Tschemernjak 34:07e89f23c734 452 _spi->write( addr | 0x80 );
GregCr 0:e6ceb13d2d05 453 for( i = 0; i < size; i++ )
GregCr 0:e6ceb13d2d05 454 {
Helmut Tschemernjak 51:aef3234bcb71 455 _spi->write(*p++);
GregCr 0:e6ceb13d2d05 456 }
Helmut Tschemernjak 34:07e89f23c734 457 *_nss = 1;
GregCr 0:e6ceb13d2d05 458 }
GregCr 0:e6ceb13d2d05 459
Helmut Tschemernjak 51:aef3234bcb71 460 void SX1276Generic::Read( uint8_t addr, void *buffer, uint8_t size )
GregCr 0:e6ceb13d2d05 461 {
GregCr 0:e6ceb13d2d05 462 uint8_t i;
Helmut Tschemernjak 51:aef3234bcb71 463 uint8_t *p = (uint8_t *)buffer;
Helmut Tschemernjak 51:aef3234bcb71 464
Helmut Tschemernjak 34:07e89f23c734 465 *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut
Helmut Tschemernjak 34:07e89f23c734 466 _spi->write( addr & 0x7F );
GregCr 0:e6ceb13d2d05 467 for( i = 0; i < size; i++ )
GregCr 0:e6ceb13d2d05 468 {
Helmut Tschemernjak 51:aef3234bcb71 469 *p++ = _spi->write( 0 );
GregCr 0:e6ceb13d2d05 470 }
Helmut Tschemernjak 34:07e89f23c734 471 *_nss = 1;
GregCr 0:e6ceb13d2d05 472 }
GregCr 0:e6ceb13d2d05 473
Helmut Tschemernjak 51:aef3234bcb71 474 void SX1276Generic::WriteFifo( void *buffer, uint8_t size )
GregCr 0:e6ceb13d2d05 475 {
GregCr 0:e6ceb13d2d05 476 Write( 0, buffer, size );
GregCr 0:e6ceb13d2d05 477 }
GregCr 0:e6ceb13d2d05 478
Helmut Tschemernjak 51:aef3234bcb71 479 void SX1276Generic::ReadFifo( void *buffer, uint8_t size )
GregCr 0:e6ceb13d2d05 480 {
GregCr 0:e6ceb13d2d05 481 Read( 0, buffer, size );
GregCr 0:e6ceb13d2d05 482 }