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