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