This is code is part of a Technion course project in advanced IoT, implementing a device to receive and present sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

Dependencies:   mbed Buffer

Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by ST

This is code is part of a Technion course project in advanced IoT, implementing a device to receive sensors data from another L072CZ-LRWAN1 installed on a Formula racing car (built by students at Technion - Israel Institute of Technology), and sends it to a GUI presenting the data (GUI project: github.com/ward-mattar/TechnionFormulaGUI).

How to install

  • Create an account on Mbed: https://os.mbed.com/account/signup/
  • Import project into Compiler
  • In the Program Workspace select "Formula_Nucleo_Receiver"
  • Select a Platform like so:
  1. Click button at top-left
  2. Add Board
  3. Search "NUCLEO F103RB" and then "Add to your Mbed Compiler"
  • Finally click "Compile", if the build was successful, the binary would download automatically
  • To install it on device simply plug it in to a PC, open device drive and drag then drop binary file in it
Committer:
wardm
Date:
Sat May 19 15:42:38 2018 +0000
Revision:
12:046346a16ff4
V1.0.0

Who changed what in which revision?

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