![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Updated the code with Class C Lorawan
Dependencies: mbed LoRaWAN-lib
radio/SX1276Lib/sx1276/sx1276-hal.cpp@12:813e9e5f5ff6, 2019-03-22 (annotated)
- Committer:
- amirchaudhary
- Date:
- Fri Mar 22 16:24:25 2019 +0000
- Revision:
- 12:813e9e5f5ff6
Updated the code to Class C Lorawan.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
amirchaudhary | 12:813e9e5f5ff6 | 1 | /* |
amirchaudhary | 12:813e9e5f5ff6 | 2 | / _____) _ | | |
amirchaudhary | 12:813e9e5f5ff6 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
amirchaudhary | 12:813e9e5f5ff6 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
amirchaudhary | 12:813e9e5f5ff6 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
amirchaudhary | 12:813e9e5f5ff6 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
amirchaudhary | 12:813e9e5f5ff6 | 7 | (C) 2014 Semtech |
amirchaudhary | 12:813e9e5f5ff6 | 8 | |
amirchaudhary | 12:813e9e5f5ff6 | 9 | Description: - |
amirchaudhary | 12:813e9e5f5ff6 | 10 | |
amirchaudhary | 12:813e9e5f5ff6 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
amirchaudhary | 12:813e9e5f5ff6 | 12 | |
amirchaudhary | 12:813e9e5f5ff6 | 13 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
amirchaudhary | 12:813e9e5f5ff6 | 14 | */ |
amirchaudhary | 12:813e9e5f5ff6 | 15 | #include "sx1276-hal.h" |
amirchaudhary | 12:813e9e5f5ff6 | 16 | |
amirchaudhary | 12:813e9e5f5ff6 | 17 | const RadioRegisters_t SX1276MB1xAS::RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE; |
amirchaudhary | 12:813e9e5f5ff6 | 18 | |
amirchaudhary | 12:813e9e5f5ff6 | 19 | SX1276MB1xAS::SX1276MB1xAS( RadioEvents_t *events, |
amirchaudhary | 12:813e9e5f5ff6 | 20 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
amirchaudhary | 12:813e9e5f5ff6 | 21 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, |
amirchaudhary | 12:813e9e5f5ff6 | 22 | PinName antSwitch ) |
amirchaudhary | 12:813e9e5f5ff6 | 23 | : SX1276( events, mosi, miso, sclk, nss, reset, dio0, dio1, dio2, dio3, dio4, dio5 ), |
amirchaudhary | 12:813e9e5f5ff6 | 24 | AntSwitch( antSwitch ), |
amirchaudhary | 12:813e9e5f5ff6 | 25 | #if( defined ( TARGET_NUCLEO_L152RE ) ) |
amirchaudhary | 12:813e9e5f5ff6 | 26 | Fake( D8 ) |
amirchaudhary | 12:813e9e5f5ff6 | 27 | #else |
amirchaudhary | 12:813e9e5f5ff6 | 28 | Fake( A3 ) |
amirchaudhary | 12:813e9e5f5ff6 | 29 | #endif |
amirchaudhary | 12:813e9e5f5ff6 | 30 | { |
amirchaudhary | 12:813e9e5f5ff6 | 31 | this->RadioEvents = events; |
amirchaudhary | 12:813e9e5f5ff6 | 32 | |
amirchaudhary | 12:813e9e5f5ff6 | 33 | Reset( ); |
amirchaudhary | 12:813e9e5f5ff6 | 34 | |
amirchaudhary | 12:813e9e5f5ff6 | 35 | RxChainCalibration( ); |
amirchaudhary | 12:813e9e5f5ff6 | 36 | |
amirchaudhary | 12:813e9e5f5ff6 | 37 | IoInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 38 | |
amirchaudhary | 12:813e9e5f5ff6 | 39 | SetOpMode( RF_OPMODE_SLEEP ); |
amirchaudhary | 12:813e9e5f5ff6 | 40 | |
amirchaudhary | 12:813e9e5f5ff6 | 41 | IoIrqInit( dioIrq ); |
amirchaudhary | 12:813e9e5f5ff6 | 42 | |
amirchaudhary | 12:813e9e5f5ff6 | 43 | RadioRegistersInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 44 | |
amirchaudhary | 12:813e9e5f5ff6 | 45 | SetModem( MODEM_FSK ); |
amirchaudhary | 12:813e9e5f5ff6 | 46 | |
amirchaudhary | 12:813e9e5f5ff6 | 47 | this->settings.State = RF_IDLE ; |
amirchaudhary | 12:813e9e5f5ff6 | 48 | } |
amirchaudhary | 12:813e9e5f5ff6 | 49 | |
amirchaudhary | 12:813e9e5f5ff6 | 50 | SX1276MB1xAS::SX1276MB1xAS( RadioEvents_t *events ) |
amirchaudhary | 12:813e9e5f5ff6 | 51 | #if defined ( TARGET_NUCLEO_L152RE ) |
amirchaudhary | 12:813e9e5f5ff6 | 52 | : SX1276( events, D11, D12, D13, D10, A0, D2, D3, D4, D5, A3, D9 ), // For NUCLEO L152RE dio4 is on port A3 |
amirchaudhary | 12:813e9e5f5ff6 | 53 | AntSwitch( A4 ), |
amirchaudhary | 12:813e9e5f5ff6 | 54 | Fake( D8 ) |
amirchaudhary | 12:813e9e5f5ff6 | 55 | #elif defined( TARGET_LPC11U6X ) |
amirchaudhary | 12:813e9e5f5ff6 | 56 | : SX1276( events, D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9 ), |
amirchaudhary | 12:813e9e5f5ff6 | 57 | AntSwitch( P0_23 ), |
amirchaudhary | 12:813e9e5f5ff6 | 58 | Fake( A3 ) |
amirchaudhary | 12:813e9e5f5ff6 | 59 | #else |
amirchaudhary | 12:813e9e5f5ff6 | 60 | : SX1276( events, D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9 ), |
amirchaudhary | 12:813e9e5f5ff6 | 61 | AntSwitch( A4 ), |
amirchaudhary | 12:813e9e5f5ff6 | 62 | Fake( A3 ) |
amirchaudhary | 12:813e9e5f5ff6 | 63 | #endif |
amirchaudhary | 12:813e9e5f5ff6 | 64 | { |
amirchaudhary | 12:813e9e5f5ff6 | 65 | this->RadioEvents = events; |
amirchaudhary | 12:813e9e5f5ff6 | 66 | |
amirchaudhary | 12:813e9e5f5ff6 | 67 | Reset( ); |
amirchaudhary | 12:813e9e5f5ff6 | 68 | |
amirchaudhary | 12:813e9e5f5ff6 | 69 | boardConnected = UNKNOWN; |
amirchaudhary | 12:813e9e5f5ff6 | 70 | |
amirchaudhary | 12:813e9e5f5ff6 | 71 | DetectBoardType( ); |
amirchaudhary | 12:813e9e5f5ff6 | 72 | |
amirchaudhary | 12:813e9e5f5ff6 | 73 | RxChainCalibration( ); |
amirchaudhary | 12:813e9e5f5ff6 | 74 | |
amirchaudhary | 12:813e9e5f5ff6 | 75 | IoInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 76 | |
amirchaudhary | 12:813e9e5f5ff6 | 77 | SetOpMode( RF_OPMODE_SLEEP ); |
amirchaudhary | 12:813e9e5f5ff6 | 78 | IoIrqInit( dioIrq ); |
amirchaudhary | 12:813e9e5f5ff6 | 79 | |
amirchaudhary | 12:813e9e5f5ff6 | 80 | RadioRegistersInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 81 | |
amirchaudhary | 12:813e9e5f5ff6 | 82 | SetModem( MODEM_FSK ); |
amirchaudhary | 12:813e9e5f5ff6 | 83 | |
amirchaudhary | 12:813e9e5f5ff6 | 84 | this->settings.State = RF_IDLE ; |
amirchaudhary | 12:813e9e5f5ff6 | 85 | } |
amirchaudhary | 12:813e9e5f5ff6 | 86 | |
amirchaudhary | 12:813e9e5f5ff6 | 87 | //------------------------------------------------------------------------- |
amirchaudhary | 12:813e9e5f5ff6 | 88 | // Board relative functions |
amirchaudhary | 12:813e9e5f5ff6 | 89 | //------------------------------------------------------------------------- |
amirchaudhary | 12:813e9e5f5ff6 | 90 | uint8_t SX1276MB1xAS::DetectBoardType( void ) |
amirchaudhary | 12:813e9e5f5ff6 | 91 | { |
amirchaudhary | 12:813e9e5f5ff6 | 92 | if( boardConnected == UNKNOWN ) |
amirchaudhary | 12:813e9e5f5ff6 | 93 | { |
amirchaudhary | 12:813e9e5f5ff6 | 94 | this->AntSwitch.input( ); |
amirchaudhary | 12:813e9e5f5ff6 | 95 | wait_ms( 1 ); |
amirchaudhary | 12:813e9e5f5ff6 | 96 | if( this->AntSwitch == 1 ) |
amirchaudhary | 12:813e9e5f5ff6 | 97 | { |
amirchaudhary | 12:813e9e5f5ff6 | 98 | boardConnected = SX1276MB1LAS; |
amirchaudhary | 12:813e9e5f5ff6 | 99 | } |
amirchaudhary | 12:813e9e5f5ff6 | 100 | else |
amirchaudhary | 12:813e9e5f5ff6 | 101 | { |
amirchaudhary | 12:813e9e5f5ff6 | 102 | boardConnected = SX1276MB1MAS; |
amirchaudhary | 12:813e9e5f5ff6 | 103 | } |
amirchaudhary | 12:813e9e5f5ff6 | 104 | this->AntSwitch.output( ); |
amirchaudhary | 12:813e9e5f5ff6 | 105 | wait_ms( 1 ); |
amirchaudhary | 12:813e9e5f5ff6 | 106 | } |
amirchaudhary | 12:813e9e5f5ff6 | 107 | return ( boardConnected ); |
amirchaudhary | 12:813e9e5f5ff6 | 108 | } |
amirchaudhary | 12:813e9e5f5ff6 | 109 | |
amirchaudhary | 12:813e9e5f5ff6 | 110 | void SX1276MB1xAS::IoInit( void ) |
amirchaudhary | 12:813e9e5f5ff6 | 111 | { |
amirchaudhary | 12:813e9e5f5ff6 | 112 | AntSwInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 113 | SpiInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 114 | } |
amirchaudhary | 12:813e9e5f5ff6 | 115 | |
amirchaudhary | 12:813e9e5f5ff6 | 116 | void SX1276MB1xAS::RadioRegistersInit( ) |
amirchaudhary | 12:813e9e5f5ff6 | 117 | { |
amirchaudhary | 12:813e9e5f5ff6 | 118 | uint8_t i = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 119 | for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ ) |
amirchaudhary | 12:813e9e5f5ff6 | 120 | { |
amirchaudhary | 12:813e9e5f5ff6 | 121 | SetModem( RadioRegsInit[i].Modem ); |
amirchaudhary | 12:813e9e5f5ff6 | 122 | Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value ); |
amirchaudhary | 12:813e9e5f5ff6 | 123 | } |
amirchaudhary | 12:813e9e5f5ff6 | 124 | } |
amirchaudhary | 12:813e9e5f5ff6 | 125 | |
amirchaudhary | 12:813e9e5f5ff6 | 126 | void SX1276MB1xAS::SpiInit( void ) |
amirchaudhary | 12:813e9e5f5ff6 | 127 | { |
amirchaudhary | 12:813e9e5f5ff6 | 128 | nss = 1; |
amirchaudhary | 12:813e9e5f5ff6 | 129 | spi.format( 8,0 ); |
amirchaudhary | 12:813e9e5f5ff6 | 130 | uint32_t frequencyToSet = 8000000; |
amirchaudhary | 12:813e9e5f5ff6 | 131 | #if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) ) |
amirchaudhary | 12:813e9e5f5ff6 | 132 | spi.frequency( frequencyToSet ); |
amirchaudhary | 12:813e9e5f5ff6 | 133 | #elif( defined ( TARGET_KL25Z ) ) //busclock frequency is halved -> double the spi frequency to compensate |
amirchaudhary | 12:813e9e5f5ff6 | 134 | spi.frequency( frequencyToSet * 2 ); |
amirchaudhary | 12:813e9e5f5ff6 | 135 | #else |
amirchaudhary | 12:813e9e5f5ff6 | 136 | #warning "Check the board's SPI frequency" |
amirchaudhary | 12:813e9e5f5ff6 | 137 | #endif |
amirchaudhary | 12:813e9e5f5ff6 | 138 | wait(0.1); |
amirchaudhary | 12:813e9e5f5ff6 | 139 | } |
amirchaudhary | 12:813e9e5f5ff6 | 140 | |
amirchaudhary | 12:813e9e5f5ff6 | 141 | void SX1276MB1xAS::IoIrqInit( DioIrqHandler *irqHandlers ) |
amirchaudhary | 12:813e9e5f5ff6 | 142 | { |
amirchaudhary | 12:813e9e5f5ff6 | 143 | #if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) ) |
amirchaudhary | 12:813e9e5f5ff6 | 144 | dio0.mode( PullDown ); |
amirchaudhary | 12:813e9e5f5ff6 | 145 | dio1.mode( PullDown ); |
amirchaudhary | 12:813e9e5f5ff6 | 146 | dio2.mode( PullDown ); |
amirchaudhary | 12:813e9e5f5ff6 | 147 | dio3.mode( PullDown ); |
amirchaudhary | 12:813e9e5f5ff6 | 148 | dio4.mode( PullDown ); |
amirchaudhary | 12:813e9e5f5ff6 | 149 | #endif |
amirchaudhary | 12:813e9e5f5ff6 | 150 | dio0.rise( mbed::callback( this, static_cast< TriggerMB1xAS > ( irqHandlers[0] ) ) ); |
amirchaudhary | 12:813e9e5f5ff6 | 151 | dio1.rise( mbed::callback( this, static_cast< TriggerMB1xAS > ( irqHandlers[1] ) ) ); |
amirchaudhary | 12:813e9e5f5ff6 | 152 | dio2.rise( mbed::callback( this, static_cast< TriggerMB1xAS > ( irqHandlers[2] ) ) ); |
amirchaudhary | 12:813e9e5f5ff6 | 153 | dio3.rise( mbed::callback( this, static_cast< TriggerMB1xAS > ( irqHandlers[3] ) ) ); |
amirchaudhary | 12:813e9e5f5ff6 | 154 | dio4.rise( mbed::callback( this, static_cast< TriggerMB1xAS > ( irqHandlers[4] ) ) ); |
amirchaudhary | 12:813e9e5f5ff6 | 155 | } |
amirchaudhary | 12:813e9e5f5ff6 | 156 | |
amirchaudhary | 12:813e9e5f5ff6 | 157 | void SX1276MB1xAS::IoDeInit( void ) |
amirchaudhary | 12:813e9e5f5ff6 | 158 | { |
amirchaudhary | 12:813e9e5f5ff6 | 159 | //nothing |
amirchaudhary | 12:813e9e5f5ff6 | 160 | } |
amirchaudhary | 12:813e9e5f5ff6 | 161 | |
amirchaudhary | 12:813e9e5f5ff6 | 162 | void SX1276MB1xAS::SetRfTxPower( int8_t power ) |
amirchaudhary | 12:813e9e5f5ff6 | 163 | { |
amirchaudhary | 12:813e9e5f5ff6 | 164 | uint8_t paConfig = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 165 | uint8_t paDac = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 166 | |
amirchaudhary | 12:813e9e5f5ff6 | 167 | paConfig = Read( REG_PACONFIG ); |
amirchaudhary | 12:813e9e5f5ff6 | 168 | paDac = Read( REG_PADAC ); |
amirchaudhary | 12:813e9e5f5ff6 | 169 | |
amirchaudhary | 12:813e9e5f5ff6 | 170 | paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | GetPaSelect( this->settings.Channel ); |
amirchaudhary | 12:813e9e5f5ff6 | 171 | paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70; |
amirchaudhary | 12:813e9e5f5ff6 | 172 | |
amirchaudhary | 12:813e9e5f5ff6 | 173 | if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST ) |
amirchaudhary | 12:813e9e5f5ff6 | 174 | { |
amirchaudhary | 12:813e9e5f5ff6 | 175 | if( power > 17 ) |
amirchaudhary | 12:813e9e5f5ff6 | 176 | { |
amirchaudhary | 12:813e9e5f5ff6 | 177 | paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON; |
amirchaudhary | 12:813e9e5f5ff6 | 178 | } |
amirchaudhary | 12:813e9e5f5ff6 | 179 | else |
amirchaudhary | 12:813e9e5f5ff6 | 180 | { |
amirchaudhary | 12:813e9e5f5ff6 | 181 | paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF; |
amirchaudhary | 12:813e9e5f5ff6 | 182 | } |
amirchaudhary | 12:813e9e5f5ff6 | 183 | if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON ) |
amirchaudhary | 12:813e9e5f5ff6 | 184 | { |
amirchaudhary | 12:813e9e5f5ff6 | 185 | if( power < 5 ) |
amirchaudhary | 12:813e9e5f5ff6 | 186 | { |
amirchaudhary | 12:813e9e5f5ff6 | 187 | power = 5; |
amirchaudhary | 12:813e9e5f5ff6 | 188 | } |
amirchaudhary | 12:813e9e5f5ff6 | 189 | if( power > 20 ) |
amirchaudhary | 12:813e9e5f5ff6 | 190 | { |
amirchaudhary | 12:813e9e5f5ff6 | 191 | power = 20; |
amirchaudhary | 12:813e9e5f5ff6 | 192 | } |
amirchaudhary | 12:813e9e5f5ff6 | 193 | paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F ); |
amirchaudhary | 12:813e9e5f5ff6 | 194 | } |
amirchaudhary | 12:813e9e5f5ff6 | 195 | else |
amirchaudhary | 12:813e9e5f5ff6 | 196 | { |
amirchaudhary | 12:813e9e5f5ff6 | 197 | if( power < 2 ) |
amirchaudhary | 12:813e9e5f5ff6 | 198 | { |
amirchaudhary | 12:813e9e5f5ff6 | 199 | power = 2; |
amirchaudhary | 12:813e9e5f5ff6 | 200 | } |
amirchaudhary | 12:813e9e5f5ff6 | 201 | if( power > 17 ) |
amirchaudhary | 12:813e9e5f5ff6 | 202 | { |
amirchaudhary | 12:813e9e5f5ff6 | 203 | power = 17; |
amirchaudhary | 12:813e9e5f5ff6 | 204 | } |
amirchaudhary | 12:813e9e5f5ff6 | 205 | paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F ); |
amirchaudhary | 12:813e9e5f5ff6 | 206 | } |
amirchaudhary | 12:813e9e5f5ff6 | 207 | } |
amirchaudhary | 12:813e9e5f5ff6 | 208 | else |
amirchaudhary | 12:813e9e5f5ff6 | 209 | { |
amirchaudhary | 12:813e9e5f5ff6 | 210 | if( power < -1 ) |
amirchaudhary | 12:813e9e5f5ff6 | 211 | { |
amirchaudhary | 12:813e9e5f5ff6 | 212 | power = -1; |
amirchaudhary | 12:813e9e5f5ff6 | 213 | } |
amirchaudhary | 12:813e9e5f5ff6 | 214 | if( power > 14 ) |
amirchaudhary | 12:813e9e5f5ff6 | 215 | { |
amirchaudhary | 12:813e9e5f5ff6 | 216 | power = 14; |
amirchaudhary | 12:813e9e5f5ff6 | 217 | } |
amirchaudhary | 12:813e9e5f5ff6 | 218 | paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F ); |
amirchaudhary | 12:813e9e5f5ff6 | 219 | } |
amirchaudhary | 12:813e9e5f5ff6 | 220 | Write( REG_PACONFIG, paConfig ); |
amirchaudhary | 12:813e9e5f5ff6 | 221 | Write( REG_PADAC, paDac ); |
amirchaudhary | 12:813e9e5f5ff6 | 222 | } |
amirchaudhary | 12:813e9e5f5ff6 | 223 | |
amirchaudhary | 12:813e9e5f5ff6 | 224 | uint8_t SX1276MB1xAS::GetPaSelect( uint32_t channel ) |
amirchaudhary | 12:813e9e5f5ff6 | 225 | { |
amirchaudhary | 12:813e9e5f5ff6 | 226 | if( channel > RF_MID_BAND_THRESH ) |
amirchaudhary | 12:813e9e5f5ff6 | 227 | { |
amirchaudhary | 12:813e9e5f5ff6 | 228 | if( boardConnected == SX1276MB1LAS ) |
amirchaudhary | 12:813e9e5f5ff6 | 229 | { |
amirchaudhary | 12:813e9e5f5ff6 | 230 | return RF_PACONFIG_PASELECT_PABOOST; |
amirchaudhary | 12:813e9e5f5ff6 | 231 | } |
amirchaudhary | 12:813e9e5f5ff6 | 232 | else |
amirchaudhary | 12:813e9e5f5ff6 | 233 | { |
amirchaudhary | 12:813e9e5f5ff6 | 234 | // return RF_PACONFIG_PASELECT_RFO; |
amirchaudhary | 12:813e9e5f5ff6 | 235 | return RF_PACONFIG_PASELECT_PABOOST; |
amirchaudhary | 12:813e9e5f5ff6 | 236 | } |
amirchaudhary | 12:813e9e5f5ff6 | 237 | } |
amirchaudhary | 12:813e9e5f5ff6 | 238 | else |
amirchaudhary | 12:813e9e5f5ff6 | 239 | { |
amirchaudhary | 12:813e9e5f5ff6 | 240 | // return RF_PACONFIG_PASELECT_RFO; |
amirchaudhary | 12:813e9e5f5ff6 | 241 | return RF_PACONFIG_PASELECT_PABOOST; |
amirchaudhary | 12:813e9e5f5ff6 | 242 | } |
amirchaudhary | 12:813e9e5f5ff6 | 243 | } |
amirchaudhary | 12:813e9e5f5ff6 | 244 | |
amirchaudhary | 12:813e9e5f5ff6 | 245 | void SX1276MB1xAS::SetAntSwLowPower( bool status ) |
amirchaudhary | 12:813e9e5f5ff6 | 246 | { |
amirchaudhary | 12:813e9e5f5ff6 | 247 | if( isRadioActive != status ) |
amirchaudhary | 12:813e9e5f5ff6 | 248 | { |
amirchaudhary | 12:813e9e5f5ff6 | 249 | isRadioActive = status; |
amirchaudhary | 12:813e9e5f5ff6 | 250 | |
amirchaudhary | 12:813e9e5f5ff6 | 251 | if( status == false ) |
amirchaudhary | 12:813e9e5f5ff6 | 252 | { |
amirchaudhary | 12:813e9e5f5ff6 | 253 | AntSwInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 254 | } |
amirchaudhary | 12:813e9e5f5ff6 | 255 | else |
amirchaudhary | 12:813e9e5f5ff6 | 256 | { |
amirchaudhary | 12:813e9e5f5ff6 | 257 | AntSwDeInit( ); |
amirchaudhary | 12:813e9e5f5ff6 | 258 | } |
amirchaudhary | 12:813e9e5f5ff6 | 259 | } |
amirchaudhary | 12:813e9e5f5ff6 | 260 | } |
amirchaudhary | 12:813e9e5f5ff6 | 261 | |
amirchaudhary | 12:813e9e5f5ff6 | 262 | void SX1276MB1xAS::AntSwInit( void ) |
amirchaudhary | 12:813e9e5f5ff6 | 263 | { |
amirchaudhary | 12:813e9e5f5ff6 | 264 | this->AntSwitch = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 265 | } |
amirchaudhary | 12:813e9e5f5ff6 | 266 | |
amirchaudhary | 12:813e9e5f5ff6 | 267 | void SX1276MB1xAS::AntSwDeInit( void ) |
amirchaudhary | 12:813e9e5f5ff6 | 268 | { |
amirchaudhary | 12:813e9e5f5ff6 | 269 | this->AntSwitch = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 270 | } |
amirchaudhary | 12:813e9e5f5ff6 | 271 | |
amirchaudhary | 12:813e9e5f5ff6 | 272 | void SX1276MB1xAS::SetAntSw( uint8_t opMode ) |
amirchaudhary | 12:813e9e5f5ff6 | 273 | { |
amirchaudhary | 12:813e9e5f5ff6 | 274 | switch( opMode ) |
amirchaudhary | 12:813e9e5f5ff6 | 275 | { |
amirchaudhary | 12:813e9e5f5ff6 | 276 | case RFLR_OPMODE_TRANSMITTER: |
amirchaudhary | 12:813e9e5f5ff6 | 277 | this->AntSwitch = 1; |
amirchaudhary | 12:813e9e5f5ff6 | 278 | break; |
amirchaudhary | 12:813e9e5f5ff6 | 279 | case RFLR_OPMODE_RECEIVER: |
amirchaudhary | 12:813e9e5f5ff6 | 280 | case RFLR_OPMODE_RECEIVER_SINGLE: |
amirchaudhary | 12:813e9e5f5ff6 | 281 | case RFLR_OPMODE_CAD: |
amirchaudhary | 12:813e9e5f5ff6 | 282 | this->AntSwitch = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 283 | break; |
amirchaudhary | 12:813e9e5f5ff6 | 284 | default: |
amirchaudhary | 12:813e9e5f5ff6 | 285 | this->AntSwitch = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 286 | break; |
amirchaudhary | 12:813e9e5f5ff6 | 287 | } |
amirchaudhary | 12:813e9e5f5ff6 | 288 | } |
amirchaudhary | 12:813e9e5f5ff6 | 289 | |
amirchaudhary | 12:813e9e5f5ff6 | 290 | bool SX1276MB1xAS::CheckRfFrequency( uint32_t frequency ) |
amirchaudhary | 12:813e9e5f5ff6 | 291 | { |
amirchaudhary | 12:813e9e5f5ff6 | 292 | // Implement check. Currently all frequencies are supported |
amirchaudhary | 12:813e9e5f5ff6 | 293 | return true; |
amirchaudhary | 12:813e9e5f5ff6 | 294 | } |
amirchaudhary | 12:813e9e5f5ff6 | 295 | |
amirchaudhary | 12:813e9e5f5ff6 | 296 | void SX1276MB1xAS::Reset( void ) |
amirchaudhary | 12:813e9e5f5ff6 | 297 | { |
amirchaudhary | 12:813e9e5f5ff6 | 298 | reset.output( ); |
amirchaudhary | 12:813e9e5f5ff6 | 299 | reset = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 300 | wait_ms( 1 ); |
amirchaudhary | 12:813e9e5f5ff6 | 301 | reset.input( ); |
amirchaudhary | 12:813e9e5f5ff6 | 302 | wait_ms( 6 ); |
amirchaudhary | 12:813e9e5f5ff6 | 303 | } |
amirchaudhary | 12:813e9e5f5ff6 | 304 | |
amirchaudhary | 12:813e9e5f5ff6 | 305 | void SX1276MB1xAS::Write( uint8_t addr, uint8_t data ) |
amirchaudhary | 12:813e9e5f5ff6 | 306 | { |
amirchaudhary | 12:813e9e5f5ff6 | 307 | Write( addr, &data, 1 ); |
amirchaudhary | 12:813e9e5f5ff6 | 308 | } |
amirchaudhary | 12:813e9e5f5ff6 | 309 | |
amirchaudhary | 12:813e9e5f5ff6 | 310 | uint8_t SX1276MB1xAS::Read( uint8_t addr ) |
amirchaudhary | 12:813e9e5f5ff6 | 311 | { |
amirchaudhary | 12:813e9e5f5ff6 | 312 | uint8_t data; |
amirchaudhary | 12:813e9e5f5ff6 | 313 | Read( addr, &data, 1 ); |
amirchaudhary | 12:813e9e5f5ff6 | 314 | return data; |
amirchaudhary | 12:813e9e5f5ff6 | 315 | } |
amirchaudhary | 12:813e9e5f5ff6 | 316 | |
amirchaudhary | 12:813e9e5f5ff6 | 317 | void SX1276MB1xAS::Write( uint8_t addr, uint8_t *buffer, uint8_t size ) |
amirchaudhary | 12:813e9e5f5ff6 | 318 | { |
amirchaudhary | 12:813e9e5f5ff6 | 319 | uint8_t i; |
amirchaudhary | 12:813e9e5f5ff6 | 320 | |
amirchaudhary | 12:813e9e5f5ff6 | 321 | nss = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 322 | spi.write( addr | 0x80 ); |
amirchaudhary | 12:813e9e5f5ff6 | 323 | for( i = 0; i < size; i++ ) |
amirchaudhary | 12:813e9e5f5ff6 | 324 | { |
amirchaudhary | 12:813e9e5f5ff6 | 325 | spi.write( buffer[i] ); |
amirchaudhary | 12:813e9e5f5ff6 | 326 | } |
amirchaudhary | 12:813e9e5f5ff6 | 327 | nss = 1; |
amirchaudhary | 12:813e9e5f5ff6 | 328 | } |
amirchaudhary | 12:813e9e5f5ff6 | 329 | |
amirchaudhary | 12:813e9e5f5ff6 | 330 | void SX1276MB1xAS::Read( uint8_t addr, uint8_t *buffer, uint8_t size ) |
amirchaudhary | 12:813e9e5f5ff6 | 331 | { |
amirchaudhary | 12:813e9e5f5ff6 | 332 | uint8_t i; |
amirchaudhary | 12:813e9e5f5ff6 | 333 | |
amirchaudhary | 12:813e9e5f5ff6 | 334 | nss = 0; |
amirchaudhary | 12:813e9e5f5ff6 | 335 | spi.write( addr & 0x7F ); |
amirchaudhary | 12:813e9e5f5ff6 | 336 | for( i = 0; i < size; i++ ) |
amirchaudhary | 12:813e9e5f5ff6 | 337 | { |
amirchaudhary | 12:813e9e5f5ff6 | 338 | buffer[i] = spi.write( 0 ); |
amirchaudhary | 12:813e9e5f5ff6 | 339 | } |
amirchaudhary | 12:813e9e5f5ff6 | 340 | nss = 1; |
amirchaudhary | 12:813e9e5f5ff6 | 341 | } |
amirchaudhary | 12:813e9e5f5ff6 | 342 | |
amirchaudhary | 12:813e9e5f5ff6 | 343 | void SX1276MB1xAS::WriteFifo( uint8_t *buffer, uint8_t size ) |
amirchaudhary | 12:813e9e5f5ff6 | 344 | { |
amirchaudhary | 12:813e9e5f5ff6 | 345 | Write( 0, buffer, size ); |
amirchaudhary | 12:813e9e5f5ff6 | 346 | } |
amirchaudhary | 12:813e9e5f5ff6 | 347 | |
amirchaudhary | 12:813e9e5f5ff6 | 348 | void SX1276MB1xAS::ReadFifo( uint8_t *buffer, uint8_t size ) |
amirchaudhary | 12:813e9e5f5ff6 | 349 | { |
amirchaudhary | 12:813e9e5f5ff6 | 350 | Read( 0, buffer, size ); |
amirchaudhary | 12:813e9e5f5ff6 | 351 | } |