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