LoRa node acquiring analog input and sending to LoRa Server - Working ok
Dependents: DISCO-L072CZ-LRWAN1_LoRa_node EIoT_LoRa_node_1 EIoT_LoRa_node_2 EIoT_LoRa_node_3
Fork of SX1276GenericLib by
sx1276/sx1276-hal.cpp@35:c278a826a8e2, 2017-05-06 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Sat May 06 13:58:14 2017 +0200
- Revision:
- 35:c278a826a8e2
- Parent:
- 34:07e89f23c734
Disable MURATA Boost by default.
Who changed what in which revision?
User | Revision | Line number | New 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 | 34:07e89f23c734 | 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 | |
GregCr | 0:e6ceb13d2d05 | 22 | #include "sx1276-hal.h" |
GregCr | 0:e6ceb13d2d05 | 23 | |
Helmut Tschemernjak | 34:07e89f23c734 | 24 | const RadioRegisters_t SX1276Generic::RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE; |
GregCr | 0:e6ceb13d2d05 | 25 | |
Helmut Tschemernjak | 34:07e89f23c734 | 26 | SX1276Generic::SX1276Generic( RadioEvents_t *events, BoardType_t board, |
GregCr | 0:e6ceb13d2d05 | 27 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
GregCr | 0:e6ceb13d2d05 | 28 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, |
Helmut Tschemernjak | 34:07e89f23c734 | 29 | PinName antSwitch, PinName antSwitchTX, PinName antSwitchTXBoost, PinName tcxo) |
Helmut Tschemernjak | 34:07e89f23c734 | 30 | : SX1276( events) |
GregCr | 0:e6ceb13d2d05 | 31 | { |
mluis | 21:2e496deb7858 | 32 | this->RadioEvents = events; |
Helmut Tschemernjak | 34:07e89f23c734 | 33 | boardConnected = board; |
Helmut Tschemernjak | 34:07e89f23c734 | 34 | |
Helmut Tschemernjak | 34:07e89f23c734 | 35 | _antSwitch = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 36 | _antSwitchTX = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 37 | _antSwitchTXBoost = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 38 | |
Helmut Tschemernjak | 34:07e89f23c734 | 39 | _tcxo = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 40 | if (tcxo != NC) |
Helmut Tschemernjak | 34:07e89f23c734 | 41 | _tcxo = new DigitalOut(tcxo); |
Helmut Tschemernjak | 34:07e89f23c734 | 42 | |
Helmut Tschemernjak | 34:07e89f23c734 | 43 | switch(boardConnected) { |
Helmut Tschemernjak | 34:07e89f23c734 | 44 | case SX1276MB1MAS: |
Helmut Tschemernjak | 34:07e89f23c734 | 45 | case SX1276MB1LAS: |
Helmut Tschemernjak | 34:07e89f23c734 | 46 | _antSwitch = new DigitalInOut(antSwitch); |
Helmut Tschemernjak | 34:07e89f23c734 | 47 | break; |
Helmut Tschemernjak | 34:07e89f23c734 | 48 | case RFM95_SX1276: |
Helmut Tschemernjak | 34:07e89f23c734 | 49 | break; |
Helmut Tschemernjak | 34:07e89f23c734 | 50 | case MURATA_SX1276: |
Helmut Tschemernjak | 34:07e89f23c734 | 51 | _antSwitch = new DigitalInOut(antSwitch); |
Helmut Tschemernjak | 34:07e89f23c734 | 52 | _antSwitchTX = new DigitalInOut(antSwitchTX); |
Helmut Tschemernjak | 34:07e89f23c734 | 53 | _antSwitchTXBoost = new DigitalInOut(antSwitchTXBoost); |
Helmut Tschemernjak | 34:07e89f23c734 | 54 | break; |
Helmut Tschemernjak | 34:07e89f23c734 | 55 | default: |
Helmut Tschemernjak | 34:07e89f23c734 | 56 | break; |
Helmut Tschemernjak | 34:07e89f23c734 | 57 | } |
Helmut Tschemernjak | 34:07e89f23c734 | 58 | _spi = new SPI(mosi, miso, sclk ); |
Helmut Tschemernjak | 34:07e89f23c734 | 59 | _nss = new DigitalOut(nss); |
Helmut Tschemernjak | 34:07e89f23c734 | 60 | |
Helmut Tschemernjak | 34:07e89f23c734 | 61 | _reset = new DigitalInOut(reset); |
Helmut Tschemernjak | 34:07e89f23c734 | 62 | |
Helmut Tschemernjak | 34:07e89f23c734 | 63 | _dio0 = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 64 | _dio1 = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 65 | _dio2 = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 66 | _dio3 = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 67 | _dio4 = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 68 | _dio5 = NULL; |
Helmut Tschemernjak | 34:07e89f23c734 | 69 | if (dio0 != NC) |
Helmut Tschemernjak | 34:07e89f23c734 | 70 | _dio0 = new InterruptIn(dio0); |
Helmut Tschemernjak | 34:07e89f23c734 | 71 | if (dio1 != NC) |
Helmut Tschemernjak | 34:07e89f23c734 | 72 | _dio1 = new InterruptIn(dio1); |
Helmut Tschemernjak | 34:07e89f23c734 | 73 | if (dio2 != NC) |
Helmut Tschemernjak | 34:07e89f23c734 | 74 | _dio2 = new InterruptIn(dio2); |
Helmut Tschemernjak | 34:07e89f23c734 | 75 | if (dio3 != NC) |
Helmut Tschemernjak | 34:07e89f23c734 | 76 | _dio3 = new InterruptIn(dio3); |
Helmut Tschemernjak | 34:07e89f23c734 | 77 | if (dio4 != NC) |
Helmut Tschemernjak | 34:07e89f23c734 | 78 | _dio4 = new InterruptIn(dio4); |
Helmut Tschemernjak | 34:07e89f23c734 | 79 | if (dio5 != NC) |
Helmut Tschemernjak | 34:07e89f23c734 | 80 | _dio5 = new DigitalIn(dio5); |
Helmut Tschemernjak | 34:07e89f23c734 | 81 | |
GregCr | 0:e6ceb13d2d05 | 82 | Reset( ); |
mluis | 25:3778e6204cc1 | 83 | |
GregCr | 0:e6ceb13d2d05 | 84 | IoInit( ); |
mluis | 25:3778e6204cc1 | 85 | |
Helmut Tschemernjak | 34:07e89f23c734 | 86 | RxChainCalibration( ); |
Helmut Tschemernjak | 34:07e89f23c734 | 87 | |
GregCr | 0:e6ceb13d2d05 | 88 | SetOpMode( RF_OPMODE_SLEEP ); |
mluis | 25:3778e6204cc1 | 89 | |
GregCr | 0:e6ceb13d2d05 | 90 | IoIrqInit( dioIrq ); |
mluis | 25:3778e6204cc1 | 91 | |
GregCr | 0:e6ceb13d2d05 | 92 | RadioRegistersInit( ); |
GregCr | 0:e6ceb13d2d05 | 93 | |
GregCr | 0:e6ceb13d2d05 | 94 | SetModem( MODEM_FSK ); |
GregCr | 0:e6ceb13d2d05 | 95 | |
mluis | 21:2e496deb7858 | 96 | this->settings.State = RF_IDLE ; |
GregCr | 0:e6ceb13d2d05 | 97 | } |
GregCr | 0:e6ceb13d2d05 | 98 | |
Helmut Tschemernjak | 34:07e89f23c734 | 99 | SX1276Generic::~SX1276Generic() |
GregCr | 0:e6ceb13d2d05 | 100 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 101 | if (_antSwitch) |
Helmut Tschemernjak | 34:07e89f23c734 | 102 | delete _antSwitch; |
Helmut Tschemernjak | 34:07e89f23c734 | 103 | if (_antSwitchTX) |
Helmut Tschemernjak | 34:07e89f23c734 | 104 | delete _antSwitchTX; |
Helmut Tschemernjak | 34:07e89f23c734 | 105 | if (_antSwitchTXBoost) |
Helmut Tschemernjak | 34:07e89f23c734 | 106 | delete _antSwitchTXBoost; |
Helmut Tschemernjak | 34:07e89f23c734 | 107 | |
Helmut Tschemernjak | 34:07e89f23c734 | 108 | if (_tcxo) { |
Helmut Tschemernjak | 34:07e89f23c734 | 109 | *_tcxo = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 110 | delete (_tcxo); |
Helmut Tschemernjak | 34:07e89f23c734 | 111 | } |
Helmut Tschemernjak | 34:07e89f23c734 | 112 | delete _reset; |
Helmut Tschemernjak | 34:07e89f23c734 | 113 | delete _spi; |
Helmut Tschemernjak | 34:07e89f23c734 | 114 | delete _nss; |
Helmut Tschemernjak | 34:07e89f23c734 | 115 | |
Helmut Tschemernjak | 34:07e89f23c734 | 116 | if (_dio0) |
Helmut Tschemernjak | 34:07e89f23c734 | 117 | delete _dio0; |
Helmut Tschemernjak | 34:07e89f23c734 | 118 | if (_dio1) |
Helmut Tschemernjak | 34:07e89f23c734 | 119 | delete _dio1; |
Helmut Tschemernjak | 34:07e89f23c734 | 120 | if (_dio2) |
Helmut Tschemernjak | 34:07e89f23c734 | 121 | delete _dio2; |
Helmut Tschemernjak | 34:07e89f23c734 | 122 | if (_dio3) |
Helmut Tschemernjak | 34:07e89f23c734 | 123 | delete _dio3; |
Helmut Tschemernjak | 34:07e89f23c734 | 124 | if (_dio4) |
Helmut Tschemernjak | 34:07e89f23c734 | 125 | delete _dio4; |
Helmut Tschemernjak | 34:07e89f23c734 | 126 | if (_dio5) |
Helmut Tschemernjak | 34:07e89f23c734 | 127 | delete _dio5; |
GregCr | 0:e6ceb13d2d05 | 128 | } |
GregCr | 0:e6ceb13d2d05 | 129 | |
GregCr | 0:e6ceb13d2d05 | 130 | //------------------------------------------------------------------------- |
GregCr | 0:e6ceb13d2d05 | 131 | // Board relative functions |
GregCr | 0:e6ceb13d2d05 | 132 | //------------------------------------------------------------------------- |
Helmut Tschemernjak | 34:07e89f23c734 | 133 | uint8_t SX1276Generic::DetectBoardType( void ) |
GregCr | 1:f979673946c0 | 134 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 135 | return boardConnected; |
GregCr | 1:f979673946c0 | 136 | } |
GregCr | 0:e6ceb13d2d05 | 137 | |
Helmut Tschemernjak | 34:07e89f23c734 | 138 | void SX1276Generic::IoInit( void ) |
GregCr | 0:e6ceb13d2d05 | 139 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 140 | if (_tcxo) |
Helmut Tschemernjak | 34:07e89f23c734 | 141 | *_tcxo = 1; |
GregCr | 0:e6ceb13d2d05 | 142 | AntSwInit( ); |
GregCr | 0:e6ceb13d2d05 | 143 | SpiInit( ); |
GregCr | 0:e6ceb13d2d05 | 144 | } |
GregCr | 0:e6ceb13d2d05 | 145 | |
Helmut Tschemernjak | 34:07e89f23c734 | 146 | void SX1276Generic::RadioRegistersInit( ) |
mluis | 22:7f3aab69cca9 | 147 | { |
GregCr | 0:e6ceb13d2d05 | 148 | uint8_t i = 0; |
GregCr | 0:e6ceb13d2d05 | 149 | for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ ) |
GregCr | 0:e6ceb13d2d05 | 150 | { |
GregCr | 0:e6ceb13d2d05 | 151 | SetModem( RadioRegsInit[i].Modem ); |
GregCr | 0:e6ceb13d2d05 | 152 | Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value ); |
GregCr | 0:e6ceb13d2d05 | 153 | } |
GregCr | 0:e6ceb13d2d05 | 154 | } |
GregCr | 0:e6ceb13d2d05 | 155 | |
Helmut Tschemernjak | 34:07e89f23c734 | 156 | void SX1276Generic::SpiInit( void ) |
GregCr | 0:e6ceb13d2d05 | 157 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 158 | *_nss = 1; |
Helmut Tschemernjak | 34:07e89f23c734 | 159 | _spi->format( 8,0 ); |
GregCr | 0:e6ceb13d2d05 | 160 | uint32_t frequencyToSet = 8000000; |
Helmut Tschemernjak | 34:07e89f23c734 | 161 | #ifdef TARGET_KL25Z //busclock frequency is halved -> double the spi frequency to compensate |
Helmut Tschemernjak | 34:07e89f23c734 | 162 | _spi->frequency( frequencyToSet * 2 ); |
Helmut Tschemernjak | 34:07e89f23c734 | 163 | #else |
Helmut Tschemernjak | 34:07e89f23c734 | 164 | _spi->frequency( frequencyToSet ); |
Helmut Tschemernjak | 34:07e89f23c734 | 165 | #endif |
Helmut Tschemernjak | 34:07e89f23c734 | 166 | wait_ms(100); |
GregCr | 0:e6ceb13d2d05 | 167 | } |
GregCr | 0:e6ceb13d2d05 | 168 | |
Helmut Tschemernjak | 34:07e89f23c734 | 169 | void SX1276Generic::IoIrqInit( DioIrqHandler *irqHandlers ) |
GregCr | 0:e6ceb13d2d05 | 170 | { |
mluis | 25:3778e6204cc1 | 171 | #if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) ) |
mluis | 25:3778e6204cc1 | 172 | dio0.mode( PullDown ); |
mluis | 25:3778e6204cc1 | 173 | dio1.mode( PullDown ); |
mluis | 25:3778e6204cc1 | 174 | dio2.mode( PullDown ); |
mluis | 25:3778e6204cc1 | 175 | dio3.mode( PullDown ); |
mluis | 25:3778e6204cc1 | 176 | dio4.mode( PullDown ); |
mluis | 22:7f3aab69cca9 | 177 | #endif |
Helmut Tschemernjak | 34:07e89f23c734 | 178 | if (_dio0) |
Helmut Tschemernjak | 34:07e89f23c734 | 179 | _dio0->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[0] ))); |
Helmut Tschemernjak | 34:07e89f23c734 | 180 | if (_dio1) |
Helmut Tschemernjak | 34:07e89f23c734 | 181 | _dio1->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[1] ))); |
Helmut Tschemernjak | 34:07e89f23c734 | 182 | if (_dio2) |
Helmut Tschemernjak | 34:07e89f23c734 | 183 | _dio2->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[2] ))); |
Helmut Tschemernjak | 34:07e89f23c734 | 184 | if (_dio3) |
Helmut Tschemernjak | 34:07e89f23c734 | 185 | _dio3->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[3] ))); |
Helmut Tschemernjak | 34:07e89f23c734 | 186 | if (_dio4) |
Helmut Tschemernjak | 34:07e89f23c734 | 187 | _dio4->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[4] ))); |
GregCr | 0:e6ceb13d2d05 | 188 | } |
GregCr | 0:e6ceb13d2d05 | 189 | |
Helmut Tschemernjak | 34:07e89f23c734 | 190 | void SX1276Generic::IoDeInit( void ) |
GregCr | 0:e6ceb13d2d05 | 191 | { |
GregCr | 0:e6ceb13d2d05 | 192 | //nothing |
GregCr | 0:e6ceb13d2d05 | 193 | } |
GregCr | 0:e6ceb13d2d05 | 194 | |
Helmut Tschemernjak | 34:07e89f23c734 | 195 | void SX1276Generic::SetRfTxPower( int8_t power ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 196 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 197 | uint8_t paConfig = 0; |
Helmut Tschemernjak | 31:e50929bd3f32 | 198 | uint8_t paDac = 0; |
Helmut Tschemernjak | 31:e50929bd3f32 | 199 | |
Helmut Tschemernjak | 31:e50929bd3f32 | 200 | paConfig = Read( REG_PACONFIG ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 201 | paDac = Read( REG_PADAC ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 202 | |
Helmut Tschemernjak | 31:e50929bd3f32 | 203 | paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | GetPaSelect( this->settings.Channel ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 204 | paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70; |
Helmut Tschemernjak | 31:e50929bd3f32 | 205 | |
Helmut Tschemernjak | 31:e50929bd3f32 | 206 | if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 207 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 208 | if( power > 17 ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 209 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 210 | paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON; |
Helmut Tschemernjak | 31:e50929bd3f32 | 211 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 212 | else |
Helmut Tschemernjak | 31:e50929bd3f32 | 213 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 214 | paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF; |
Helmut Tschemernjak | 31:e50929bd3f32 | 215 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 216 | if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 217 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 218 | if( power < 5 ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 219 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 220 | power = 5; |
Helmut Tschemernjak | 31:e50929bd3f32 | 221 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 222 | if( power > 20 ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 223 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 224 | power = 20; |
Helmut Tschemernjak | 31:e50929bd3f32 | 225 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 226 | paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 227 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 228 | else |
Helmut Tschemernjak | 31:e50929bd3f32 | 229 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 230 | if( power < 2 ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 231 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 232 | power = 2; |
Helmut Tschemernjak | 31:e50929bd3f32 | 233 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 234 | if( power > 17 ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 235 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 236 | power = 17; |
Helmut Tschemernjak | 31:e50929bd3f32 | 237 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 238 | paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 239 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 240 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 241 | else |
Helmut Tschemernjak | 31:e50929bd3f32 | 242 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 243 | if( power < -1 ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 244 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 245 | power = -1; |
Helmut Tschemernjak | 31:e50929bd3f32 | 246 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 247 | if( power > 14 ) |
Helmut Tschemernjak | 31:e50929bd3f32 | 248 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 249 | power = 14; |
Helmut Tschemernjak | 31:e50929bd3f32 | 250 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 251 | paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 252 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 253 | Write( REG_PACONFIG, paConfig ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 254 | Write( REG_PADAC, paDac ); |
Helmut Tschemernjak | 31:e50929bd3f32 | 255 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 256 | |
Helmut Tschemernjak | 31:e50929bd3f32 | 257 | |
Helmut Tschemernjak | 34:07e89f23c734 | 258 | uint8_t SX1276Generic::GetPaSelect( uint32_t channel ) |
GregCr | 0:e6ceb13d2d05 | 259 | { |
GregCr | 0:e6ceb13d2d05 | 260 | if( channel > RF_MID_BAND_THRESH ) |
GregCr | 0:e6ceb13d2d05 | 261 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 262 | if( boardConnected == SX1276MB1LAS || boardConnected == RFM95_SX1276) |
GregCr | 1:f979673946c0 | 263 | { |
GregCr | 1:f979673946c0 | 264 | return RF_PACONFIG_PASELECT_PABOOST; |
GregCr | 1:f979673946c0 | 265 | } |
GregCr | 1:f979673946c0 | 266 | else |
GregCr | 1:f979673946c0 | 267 | { |
GregCr | 1:f979673946c0 | 268 | return RF_PACONFIG_PASELECT_RFO; |
GregCr | 1:f979673946c0 | 269 | } |
GregCr | 0:e6ceb13d2d05 | 270 | } |
GregCr | 0:e6ceb13d2d05 | 271 | else |
GregCr | 0:e6ceb13d2d05 | 272 | { |
GregCr | 0:e6ceb13d2d05 | 273 | return RF_PACONFIG_PASELECT_RFO; |
GregCr | 0:e6ceb13d2d05 | 274 | } |
GregCr | 0:e6ceb13d2d05 | 275 | } |
GregCr | 0:e6ceb13d2d05 | 276 | |
Helmut Tschemernjak | 34:07e89f23c734 | 277 | void SX1276Generic::SetAntSwLowPower( bool status ) |
GregCr | 0:e6ceb13d2d05 | 278 | { |
GregCr | 0:e6ceb13d2d05 | 279 | if( isRadioActive != status ) |
GregCr | 0:e6ceb13d2d05 | 280 | { |
GregCr | 0:e6ceb13d2d05 | 281 | isRadioActive = status; |
GregCr | 0:e6ceb13d2d05 | 282 | |
GregCr | 0:e6ceb13d2d05 | 283 | if( status == false ) |
GregCr | 0:e6ceb13d2d05 | 284 | { |
GregCr | 0:e6ceb13d2d05 | 285 | AntSwInit( ); |
GregCr | 0:e6ceb13d2d05 | 286 | } |
GregCr | 0:e6ceb13d2d05 | 287 | else |
GregCr | 0:e6ceb13d2d05 | 288 | { |
GregCr | 0:e6ceb13d2d05 | 289 | AntSwDeInit( ); |
GregCr | 0:e6ceb13d2d05 | 290 | } |
GregCr | 0:e6ceb13d2d05 | 291 | } |
GregCr | 0:e6ceb13d2d05 | 292 | } |
GregCr | 0:e6ceb13d2d05 | 293 | |
Helmut Tschemernjak | 34:07e89f23c734 | 294 | void SX1276Generic::AntSwInit( void ) |
GregCr | 0:e6ceb13d2d05 | 295 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 296 | if (_antSwitch) |
Helmut Tschemernjak | 34:07e89f23c734 | 297 | *_antSwitch = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 298 | if (boardConnected == MURATA_SX1276) { |
Helmut Tschemernjak | 34:07e89f23c734 | 299 | *_antSwitchTX = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 300 | *_antSwitchTXBoost = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 301 | } |
GregCr | 0:e6ceb13d2d05 | 302 | } |
GregCr | 0:e6ceb13d2d05 | 303 | |
Helmut Tschemernjak | 34:07e89f23c734 | 304 | void SX1276Generic::AntSwDeInit( void ) |
GregCr | 0:e6ceb13d2d05 | 305 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 306 | if (_antSwitch) |
Helmut Tschemernjak | 34:07e89f23c734 | 307 | *_antSwitch = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 308 | if (boardConnected == MURATA_SX1276) { |
Helmut Tschemernjak | 34:07e89f23c734 | 309 | *_antSwitchTX = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 310 | *_antSwitchTXBoost = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 311 | } |
GregCr | 0:e6ceb13d2d05 | 312 | } |
GregCr | 0:e6ceb13d2d05 | 313 | |
Helmut Tschemernjak | 31:e50929bd3f32 | 314 | |
Helmut Tschemernjak | 34:07e89f23c734 | 315 | void SX1276Generic::SetAntSw( uint8_t opMode ) |
GregCr | 0:e6ceb13d2d05 | 316 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 317 | switch( opMode ) |
GregCr | 0:e6ceb13d2d05 | 318 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 319 | case RFLR_OPMODE_TRANSMITTER: |
Helmut Tschemernjak | 34:07e89f23c734 | 320 | if (boardConnected == MURATA_SX1276) { |
Helmut Tschemernjak | 34:07e89f23c734 | 321 | *_antSwitch = 0;// Murata-RX |
Helmut Tschemernjak | 34:07e89f23c734 | 322 | *_antSwitchTX = 1; // alternate: antSwitchTXBoost = 1 |
Helmut Tschemernjak | 35:c278a826a8e2 | 323 | *_antSwitchTXBoost = 0; |
Helmut Tschemernjak | 35:c278a826a8e2 | 324 | } else { |
Helmut Tschemernjak | 34:07e89f23c734 | 325 | if (_antSwitch) |
Helmut Tschemernjak | 34:07e89f23c734 | 326 | *_antSwitch = 1; |
Helmut Tschemernjak | 34:07e89f23c734 | 327 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 328 | break; |
Helmut Tschemernjak | 31:e50929bd3f32 | 329 | case RFLR_OPMODE_RECEIVER: |
Helmut Tschemernjak | 31:e50929bd3f32 | 330 | case RFLR_OPMODE_RECEIVER_SINGLE: |
Helmut Tschemernjak | 31:e50929bd3f32 | 331 | case RFLR_OPMODE_CAD: |
Helmut Tschemernjak | 34:07e89f23c734 | 332 | if (boardConnected == MURATA_SX1276) { |
Helmut Tschemernjak | 34:07e89f23c734 | 333 | *_antSwitch = 1; // Murata-RX |
Helmut Tschemernjak | 34:07e89f23c734 | 334 | *_antSwitchTX = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 335 | *_antSwitchTXBoost = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 336 | } else { |
Helmut Tschemernjak | 34:07e89f23c734 | 337 | if (_antSwitch) |
Helmut Tschemernjak | 34:07e89f23c734 | 338 | _antSwitch = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 339 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 340 | break; |
Helmut Tschemernjak | 31:e50929bd3f32 | 341 | default: |
Helmut Tschemernjak | 34:07e89f23c734 | 342 | if (boardConnected == MURATA_SX1276) { |
Helmut Tschemernjak | 34:07e89f23c734 | 343 | *_antSwitch = 0; //Murata-RX |
Helmut Tschemernjak | 34:07e89f23c734 | 344 | *_antSwitchTX = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 345 | *_antSwitchTXBoost = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 346 | } else { |
Helmut Tschemernjak | 34:07e89f23c734 | 347 | if (_antSwitch) |
Helmut Tschemernjak | 34:07e89f23c734 | 348 | *_antSwitch = 0; |
Helmut Tschemernjak | 34:07e89f23c734 | 349 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 350 | break; |
GregCr | 0:e6ceb13d2d05 | 351 | } |
GregCr | 0:e6ceb13d2d05 | 352 | } |
GregCr | 0:e6ceb13d2d05 | 353 | |
Helmut Tschemernjak | 34:07e89f23c734 | 354 | bool SX1276Generic::CheckRfFrequency( uint32_t frequency ) |
GregCr | 0:e6ceb13d2d05 | 355 | { |
Helmut Tschemernjak | 31:e50929bd3f32 | 356 | // Implement check. Currently all frequencies are supported |
GregCr | 0:e6ceb13d2d05 | 357 | return true; |
GregCr | 0:e6ceb13d2d05 | 358 | } |
GregCr | 0:e6ceb13d2d05 | 359 | |
Helmut Tschemernjak | 34:07e89f23c734 | 360 | void SX1276Generic::Reset( void ) |
GregCr | 0:e6ceb13d2d05 | 361 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 362 | _reset->output(); |
Helmut Tschemernjak | 34:07e89f23c734 | 363 | *_reset = 0; |
Helmut Tschemernjak | 31:e50929bd3f32 | 364 | wait_ms( 1 ); |
Helmut Tschemernjak | 34:07e89f23c734 | 365 | *_reset = 1; |
Helmut Tschemernjak | 34:07e89f23c734 | 366 | _reset->input(); // I don't know my input again, maybe to save power (Helmut T) |
Helmut Tschemernjak | 31:e50929bd3f32 | 367 | wait_ms( 6 ); |
GregCr | 0:e6ceb13d2d05 | 368 | } |
Helmut Tschemernjak | 31:e50929bd3f32 | 369 | |
Helmut Tschemernjak | 34:07e89f23c734 | 370 | void SX1276Generic::Write( uint8_t addr, uint8_t data ) |
GregCr | 0:e6ceb13d2d05 | 371 | { |
GregCr | 0:e6ceb13d2d05 | 372 | Write( addr, &data, 1 ); |
GregCr | 0:e6ceb13d2d05 | 373 | } |
GregCr | 0:e6ceb13d2d05 | 374 | |
Helmut Tschemernjak | 34:07e89f23c734 | 375 | uint8_t SX1276Generic::Read( uint8_t addr ) |
GregCr | 0:e6ceb13d2d05 | 376 | { |
GregCr | 0:e6ceb13d2d05 | 377 | uint8_t data; |
GregCr | 0:e6ceb13d2d05 | 378 | Read( addr, &data, 1 ); |
GregCr | 0:e6ceb13d2d05 | 379 | return data; |
GregCr | 0:e6ceb13d2d05 | 380 | } |
GregCr | 0:e6ceb13d2d05 | 381 | |
Helmut Tschemernjak | 34:07e89f23c734 | 382 | void SX1276Generic::Write( uint8_t addr, uint8_t *buffer, uint8_t size ) |
GregCr | 0:e6ceb13d2d05 | 383 | { |
GregCr | 0:e6ceb13d2d05 | 384 | uint8_t i; |
GregCr | 0:e6ceb13d2d05 | 385 | |
Helmut Tschemernjak | 34:07e89f23c734 | 386 | *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut |
Helmut Tschemernjak | 34:07e89f23c734 | 387 | _spi->write( addr | 0x80 ); |
GregCr | 0:e6ceb13d2d05 | 388 | for( i = 0; i < size; i++ ) |
GregCr | 0:e6ceb13d2d05 | 389 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 390 | _spi->write( buffer[i] ); |
GregCr | 0:e6ceb13d2d05 | 391 | } |
Helmut Tschemernjak | 34:07e89f23c734 | 392 | *_nss = 1; |
GregCr | 0:e6ceb13d2d05 | 393 | } |
GregCr | 0:e6ceb13d2d05 | 394 | |
Helmut Tschemernjak | 34:07e89f23c734 | 395 | void SX1276Generic::Read( uint8_t addr, uint8_t *buffer, uint8_t size ) |
GregCr | 0:e6ceb13d2d05 | 396 | { |
GregCr | 0:e6ceb13d2d05 | 397 | uint8_t i; |
GregCr | 0:e6ceb13d2d05 | 398 | |
Helmut Tschemernjak | 34:07e89f23c734 | 399 | *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut |
Helmut Tschemernjak | 34:07e89f23c734 | 400 | _spi->write( addr & 0x7F ); |
GregCr | 0:e6ceb13d2d05 | 401 | for( i = 0; i < size; i++ ) |
GregCr | 0:e6ceb13d2d05 | 402 | { |
Helmut Tschemernjak | 34:07e89f23c734 | 403 | buffer[i] = _spi->write( 0 ); |
GregCr | 0:e6ceb13d2d05 | 404 | } |
Helmut Tschemernjak | 34:07e89f23c734 | 405 | *_nss = 1; |
GregCr | 0:e6ceb13d2d05 | 406 | } |
GregCr | 0:e6ceb13d2d05 | 407 | |
Helmut Tschemernjak | 34:07e89f23c734 | 408 | void SX1276Generic::WriteFifo( uint8_t *buffer, uint8_t size ) |
GregCr | 0:e6ceb13d2d05 | 409 | { |
GregCr | 0:e6ceb13d2d05 | 410 | Write( 0, buffer, size ); |
GregCr | 0:e6ceb13d2d05 | 411 | } |
GregCr | 0:e6ceb13d2d05 | 412 | |
Helmut Tschemernjak | 34:07e89f23c734 | 413 | void SX1276Generic::ReadFifo( uint8_t *buffer, uint8_t size ) |
GregCr | 0:e6ceb13d2d05 | 414 | { |
GregCr | 0:e6ceb13d2d05 | 415 | Read( 0, buffer, size ); |
GregCr | 0:e6ceb13d2d05 | 416 | } |