SX1276 library for modtronix inair9. Edited for use with NRF51DK board.
Fork of SX1276Lib_modtronix by
sx1276/sx1276-inAir.cpp@21:d3f64a075f0c, 2015-04-02 (annotated)
- Committer:
- modtronix
- Date:
- Thu Apr 02 12:27:47 2015 +1100
- Revision:
- 21:d3f64a075f0c
- Parent:
- 20:7cf7c08f0088
- Child:
- 22:20db480143c9
Test commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
modtronix | 16:0927c093fd82 | 1 | /* |
modtronix | 16:0927c093fd82 | 2 | |
modtronix | 16:0927c093fd82 | 3 | Description: - |
modtronix | 16:0927c093fd82 | 4 | |
modtronix | 16:0927c093fd82 | 5 | License: Revised BSD License, see LICENSE.TXT file include in the project |
modtronix | 16:0927c093fd82 | 6 | |
modtronix | 16:0927c093fd82 | 7 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
modtronix | 16:0927c093fd82 | 8 | */ |
modtronix | 17:6ae745bb937f | 9 | #include "myDebug.h" |
modtronix | 16:0927c093fd82 | 10 | #include "sx1276-inAir.h" |
modtronix | 16:0927c093fd82 | 11 | |
modtronix | 16:0927c093fd82 | 12 | const RadioRegisters_t SX1276inAir9::RadioRegsInit[] = |
modtronix | 16:0927c093fd82 | 13 | { |
modtronix | 16:0927c093fd82 | 14 | { MODEM_FSK , REG_LNA , 0x23 }, |
modtronix | 16:0927c093fd82 | 15 | { MODEM_FSK , REG_RXCONFIG , 0x1E }, |
modtronix | 16:0927c093fd82 | 16 | { MODEM_FSK , REG_RSSICONFIG , 0xD2 }, |
modtronix | 16:0927c093fd82 | 17 | { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA }, |
modtronix | 16:0927c093fd82 | 18 | { MODEM_FSK , REG_OSC , 0x07 }, |
modtronix | 16:0927c093fd82 | 19 | { MODEM_FSK , REG_SYNCCONFIG , 0x12 }, |
modtronix | 16:0927c093fd82 | 20 | { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 }, |
modtronix | 16:0927c093fd82 | 21 | { MODEM_FSK , REG_SYNCVALUE2 , 0x94 }, |
modtronix | 16:0927c093fd82 | 22 | { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 }, |
modtronix | 16:0927c093fd82 | 23 | { MODEM_FSK , REG_PACKETCONFIG1 , 0xD8 }, |
modtronix | 16:0927c093fd82 | 24 | { MODEM_FSK , REG_FIFOTHRESH , 0x8F }, |
modtronix | 16:0927c093fd82 | 25 | { MODEM_FSK , REG_IMAGECAL , 0x02 }, |
modtronix | 16:0927c093fd82 | 26 | { MODEM_FSK , REG_DIOMAPPING1 , 0x00 }, |
modtronix | 16:0927c093fd82 | 27 | { MODEM_FSK , REG_DIOMAPPING2 , 0x30 }, |
modtronix | 16:0927c093fd82 | 28 | { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 }, |
modtronix | 16:0927c093fd82 | 29 | }; |
modtronix | 16:0927c093fd82 | 30 | |
modtronix | 16:0927c093fd82 | 31 | SX1276inAir9::SX1276inAir9( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), |
modtronix | 16:0927c093fd82 | 32 | void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ), |
modtronix | 16:0927c093fd82 | 33 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
modtronix | 16:0927c093fd82 | 34 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, |
modtronix | 16:0927c093fd82 | 35 | PinName antSwitch ) |
modtronix | 16:0927c093fd82 | 36 | : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone, mosi, miso, sclk, nss, reset, dio0, dio1, dio2, dio3, dio4, dio5), |
modtronix | 16:0927c093fd82 | 37 | antSwitch( NC ), |
modtronix | 16:0927c093fd82 | 38 | fake( NC ) |
modtronix | 16:0927c093fd82 | 39 | { |
modtronix | 16:0927c093fd82 | 40 | Reset( ); |
modtronix | 16:0927c093fd82 | 41 | |
modtronix | 16:0927c093fd82 | 42 | boardConnected = UNKNOWN; |
modtronix | 16:0927c093fd82 | 43 | |
modtronix | 16:0927c093fd82 | 44 | RxChainCalibration( ); |
modtronix | 16:0927c093fd82 | 45 | |
modtronix | 16:0927c093fd82 | 46 | IoInit( ); |
modtronix | 16:0927c093fd82 | 47 | |
modtronix | 16:0927c093fd82 | 48 | SetOpMode( RF_OPMODE_SLEEP ); |
modtronix | 16:0927c093fd82 | 49 | |
modtronix | 16:0927c093fd82 | 50 | IoIrqInit( dioIrq ); |
modtronix | 16:0927c093fd82 | 51 | |
modtronix | 16:0927c093fd82 | 52 | RadioRegistersInit( ); |
modtronix | 16:0927c093fd82 | 53 | |
modtronix | 16:0927c093fd82 | 54 | SetModem( MODEM_FSK ); |
modtronix | 16:0927c093fd82 | 55 | |
modtronix | 16:0927c093fd82 | 56 | this->settings.State = IDLE ; |
modtronix | 16:0927c093fd82 | 57 | } |
modtronix | 16:0927c093fd82 | 58 | |
modtronix | 16:0927c093fd82 | 59 | SX1276inAir9::SX1276inAir9( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), |
modtronix | 16:0927c093fd82 | 60 | void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ) ) |
modtronix | 18:cdb08d710838 | 61 | #if( (defined (TARGET_NUCLEO_L152RE) || defined (TARGET_NUCLEO_F401RE)) && defined(SHIELD_SHD3I_INAIR9)) |
modtronix | 16:0927c093fd82 | 62 | //For SHD3I with inAir9 in imod3, on Nucleo board |
modtronix | 16:0927c093fd82 | 63 | : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone, |
modtronix | 16:0927c093fd82 | 64 | D11/*MOSI*/, D12/*MISO*/, D13/*SCLK*/, D7/*CS*/, A5/*RST*/, D2/*DIO0*/, D8, D4, A4, PC_3/*FAKE!!!*/, D3/*DIO5*/ ), |
modtronix | 18:cdb08d710838 | 65 | #elif( defined (TARGET_K64F) && defined(SHIELD_SHD3I_INAIR9) ) /* Use pin PTC0 as fake pin */ |
modtronix | 18:cdb08d710838 | 66 | //For SHD3I with inAir9 in imod3, on FRDM-K64F board |
modtronix | 17:6ae745bb937f | 67 | : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone, |
modtronix | 17:6ae745bb937f | 68 | D11/*MOSI*/, D12/*MISO*/, D13/*SCLK*/, D7/*CS*/, A5/*RST*/, D2/*DIO0*/, D8, D4, A4, PTC0/*FAKE!!!*/, D3/*DIO5*/ ), |
modtronix | 18:cdb08d710838 | 69 | #elif( defined (TARGET_KL25Z) && defined(SHIELD_SHD3I_INAIR9) ) /* Use pin PTD7 as fake pin - only A & D pins have interrupts */ |
modtronix | 18:cdb08d710838 | 70 | //For SHD3I with inAir9 in imod3, on FRDM-KL25Z board |
modtronix | 18:cdb08d710838 | 71 | : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone, |
modtronix | 18:cdb08d710838 | 72 | D11/*MOSI*/, D12/*MISO*/, D13/*SCLK*/, D7/*CS*/, A5/*RST*/, D2/*DIO0*/, D8, D4, A4, PTD7/*FAKE!!!*/, D3/*DIO5*/ ), |
modtronix | 16:0927c093fd82 | 73 | #elif ( defined ( TARGET_NZ32ST1L ) ) |
modtronix | 16:0927c093fd82 | 74 | //For NZ32ST1L board with inAir9 in imod2 |
modtronix | 16:0927c093fd82 | 75 | : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone, |
modtronix | 16:0927c093fd82 | 76 | PB_5/*MOSI*/, PB_4/*MISO*/, PB_3/*SCLK*/, PC_8/*CS*/, PA_9/*RST*/, PB_0/*DIO0*/, PB_1, PC_6, PA_10, PC_3/*FAKE!!!*/, PC_13/*DIO5*/ ), |
modtronix | 16:0927c093fd82 | 77 | #else |
modtronix | 16:0927c093fd82 | 78 | : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone, D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9 ), |
modtronix | 16:0927c093fd82 | 79 | #endif |
modtronix | 16:0927c093fd82 | 80 | antSwitch( NC ), |
modtronix | 16:0927c093fd82 | 81 | fake( NC ) |
modtronix | 16:0927c093fd82 | 82 | |
modtronix | 16:0927c093fd82 | 83 | { |
modtronix | 16:0927c093fd82 | 84 | Reset( ); |
modtronix | 16:0927c093fd82 | 85 | |
modtronix | 16:0927c093fd82 | 86 | boardConnected = UNKNOWN; |
modtronix | 16:0927c093fd82 | 87 | |
modtronix | 16:0927c093fd82 | 88 | DetectBoardType( ); |
modtronix | 16:0927c093fd82 | 89 | |
modtronix | 16:0927c093fd82 | 90 | RxChainCalibration( ); |
modtronix | 16:0927c093fd82 | 91 | |
modtronix | 16:0927c093fd82 | 92 | IoInit( ); |
modtronix | 16:0927c093fd82 | 93 | |
modtronix | 16:0927c093fd82 | 94 | SetOpMode( RF_OPMODE_SLEEP ); |
modtronix | 16:0927c093fd82 | 95 | IoIrqInit( dioIrq ); |
modtronix | 16:0927c093fd82 | 96 | |
modtronix | 16:0927c093fd82 | 97 | RadioRegistersInit( ); |
modtronix | 16:0927c093fd82 | 98 | |
modtronix | 16:0927c093fd82 | 99 | SetModem( MODEM_FSK ); |
modtronix | 16:0927c093fd82 | 100 | |
modtronix | 16:0927c093fd82 | 101 | this->settings.State = IDLE ; |
modtronix | 16:0927c093fd82 | 102 | } |
modtronix | 16:0927c093fd82 | 103 | |
modtronix | 16:0927c093fd82 | 104 | //------------------------------------------------------------------------- |
modtronix | 16:0927c093fd82 | 105 | // Board relative functions |
modtronix | 16:0927c093fd82 | 106 | //------------------------------------------------------------------------- |
modtronix | 16:0927c093fd82 | 107 | uint8_t SX1276inAir9::DetectBoardType( void ) |
modtronix | 16:0927c093fd82 | 108 | { |
modtronix | 16:0927c093fd82 | 109 | // if( boardConnected == UNKNOWN ) |
modtronix | 16:0927c093fd82 | 110 | // { |
modtronix | 16:0927c093fd82 | 111 | // antSwitch.input( ); |
modtronix | 16:0927c093fd82 | 112 | // wait_ms( 1 ); |
modtronix | 16:0927c093fd82 | 113 | // if( antSwitch == 1 ) |
modtronix | 16:0927c093fd82 | 114 | // { |
modtronix | 16:0927c093fd82 | 115 | // boardConnected = SX1276MB1LAS; |
modtronix | 16:0927c093fd82 | 116 | // } |
modtronix | 16:0927c093fd82 | 117 | // else |
modtronix | 16:0927c093fd82 | 118 | // { |
modtronix | 16:0927c093fd82 | 119 | // boardConnected = SX1276MB1MAS; |
modtronix | 16:0927c093fd82 | 120 | // } |
modtronix | 16:0927c093fd82 | 121 | // antSwitch.output( ); |
modtronix | 16:0927c093fd82 | 122 | // wait_ms( 1 ); |
modtronix | 16:0927c093fd82 | 123 | // } |
modtronix | 16:0927c093fd82 | 124 | boardConnected = SX1276MB1MAS; //Use SX1276MB1MAS, it is a 14dBm output board |
modtronix | 16:0927c093fd82 | 125 | |
modtronix | 16:0927c093fd82 | 126 | return ( boardConnected ); |
modtronix | 16:0927c093fd82 | 127 | } |
modtronix | 16:0927c093fd82 | 128 | |
modtronix | 16:0927c093fd82 | 129 | void SX1276inAir9::IoInit( void ) |
modtronix | 16:0927c093fd82 | 130 | { |
modtronix | 16:0927c093fd82 | 131 | AntSwInit( ); |
modtronix | 16:0927c093fd82 | 132 | SpiInit( ); |
modtronix | 16:0927c093fd82 | 133 | } |
modtronix | 16:0927c093fd82 | 134 | |
modtronix | 16:0927c093fd82 | 135 | void SX1276inAir9::RadioRegistersInit( ){ |
modtronix | 16:0927c093fd82 | 136 | uint8_t i = 0; |
modtronix | 16:0927c093fd82 | 137 | for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ ) |
modtronix | 16:0927c093fd82 | 138 | { |
modtronix | 16:0927c093fd82 | 139 | SetModem( RadioRegsInit[i].Modem ); |
modtronix | 16:0927c093fd82 | 140 | Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value ); |
modtronix | 16:0927c093fd82 | 141 | } |
modtronix | 16:0927c093fd82 | 142 | } |
modtronix | 16:0927c093fd82 | 143 | |
modtronix | 16:0927c093fd82 | 144 | void SX1276inAir9::SpiInit( void ) |
modtronix | 16:0927c093fd82 | 145 | { |
modtronix | 16:0927c093fd82 | 146 | nss = 1; |
modtronix | 16:0927c093fd82 | 147 | spi.format( 8,0 ); |
modtronix | 16:0927c093fd82 | 148 | //uint32_t frequencyToSet = 8000000; |
modtronix | 21:d3f64a075f0c | 149 | // TEST TEST TEST |
modtronix | 16:0927c093fd82 | 150 | uint32_t frequencyToSet = 1000000; //DJH - Reduced speed to 1MHz |
modtronix | 17:6ae745bb937f | 151 | #if( defined ( TARGET_NUCLEO_L152RE ) || defined (TARGET_NUCLEO_F401RE) || defined ( TARGET_LPC11U6X ) || defined (TARGET_K64F) || defined ( TARGET_NZ32ST1L ) ) |
modtronix | 18:cdb08d710838 | 152 | spi.frequency( frequencyToSet ); |
modtronix | 16:0927c093fd82 | 153 | #elif( defined ( TARGET_KL25Z ) ) //busclock frequency is halved -> double the spi frequency to compensate |
modtronix | 16:0927c093fd82 | 154 | spi.frequency( frequencyToSet * 2 ); |
modtronix | 16:0927c093fd82 | 155 | #else |
modtronix | 16:0927c093fd82 | 156 | #warning "Check the board's SPI frequency" |
modtronix | 16:0927c093fd82 | 157 | #endif |
modtronix | 16:0927c093fd82 | 158 | wait(0.1); |
modtronix | 16:0927c093fd82 | 159 | } |
modtronix | 16:0927c093fd82 | 160 | |
modtronix | 16:0927c093fd82 | 161 | void SX1276inAir9::IoIrqInit( DioIrqHandler *irqHandlers ) |
modtronix | 16:0927c093fd82 | 162 | { |
modtronix | 18:cdb08d710838 | 163 | //TARGET_KL25Z board does not have pulldown resistors, seems like TARGET_K64F does have them |
modtronix | 17:6ae745bb937f | 164 | #if( defined ( TARGET_NUCLEO_L152RE ) || defined (TARGET_NUCLEO_F401RE) || defined ( TARGET_LPC11U6X ) || defined (TARGET_K64F) || defined ( TARGET_NZ32ST1L )) |
modtronix | 16:0927c093fd82 | 165 | dio0.mode(PullDown); |
modtronix | 16:0927c093fd82 | 166 | dio1.mode(PullDown); |
modtronix | 16:0927c093fd82 | 167 | dio2.mode(PullDown); |
modtronix | 16:0927c093fd82 | 168 | dio3.mode(PullDown); |
modtronix | 16:0927c093fd82 | 169 | dio4.mode(PullDown); |
modtronix | 16:0927c093fd82 | 170 | #endif |
modtronix | 16:0927c093fd82 | 171 | dio0.rise( this, static_cast< TriggerInAir > ( irqHandlers[0] ) ); |
modtronix | 16:0927c093fd82 | 172 | dio1.rise( this, static_cast< TriggerInAir > ( irqHandlers[1] ) ); |
modtronix | 16:0927c093fd82 | 173 | dio2.rise( this, static_cast< TriggerInAir > ( irqHandlers[2] ) ); |
modtronix | 18:cdb08d710838 | 174 | //For SHD3I with inAir9 in imod3, on FRDM-KL25Z board. It uses A4 on FRDM-KL25Z board, which does not have interrupt |
modtronix | 18:cdb08d710838 | 175 | #if( defined ( TARGET_KL25Z ) && defined(SHIELD_SHD3I_INAIR9) ) |
modtronix | 18:cdb08d710838 | 176 | //Nothing to be done |
modtronix | 18:cdb08d710838 | 177 | #else |
modtronix | 16:0927c093fd82 | 178 | dio3.rise( this, static_cast< TriggerInAir > ( irqHandlers[3] ) ); |
modtronix | 18:cdb08d710838 | 179 | #endif |
modtronix | 16:0927c093fd82 | 180 | dio4.rise( this, static_cast< TriggerInAir > ( irqHandlers[4] ) ); |
modtronix | 16:0927c093fd82 | 181 | } |
modtronix | 16:0927c093fd82 | 182 | |
modtronix | 16:0927c093fd82 | 183 | void SX1276inAir9::IoDeInit( void ) |
modtronix | 16:0927c093fd82 | 184 | { |
modtronix | 16:0927c093fd82 | 185 | //nothing |
modtronix | 16:0927c093fd82 | 186 | } |
modtronix | 16:0927c093fd82 | 187 | |
modtronix | 16:0927c093fd82 | 188 | uint8_t SX1276inAir9::GetPaSelect( uint32_t channel ) |
modtronix | 16:0927c093fd82 | 189 | { |
modtronix | 16:0927c093fd82 | 190 | if( channel > RF_MID_BAND_THRESH ) |
modtronix | 16:0927c093fd82 | 191 | { |
modtronix | 16:0927c093fd82 | 192 | if( boardConnected == SX1276MB1LAS ) |
modtronix | 16:0927c093fd82 | 193 | { |
modtronix | 16:0927c093fd82 | 194 | return RF_PACONFIG_PASELECT_PABOOST; |
modtronix | 16:0927c093fd82 | 195 | } |
modtronix | 16:0927c093fd82 | 196 | else |
modtronix | 16:0927c093fd82 | 197 | { |
modtronix | 16:0927c093fd82 | 198 | return RF_PACONFIG_PASELECT_RFO; |
modtronix | 16:0927c093fd82 | 199 | } |
modtronix | 16:0927c093fd82 | 200 | } |
modtronix | 16:0927c093fd82 | 201 | else |
modtronix | 16:0927c093fd82 | 202 | { |
modtronix | 16:0927c093fd82 | 203 | return RF_PACONFIG_PASELECT_RFO; |
modtronix | 16:0927c093fd82 | 204 | } |
modtronix | 16:0927c093fd82 | 205 | } |
modtronix | 16:0927c093fd82 | 206 | |
modtronix | 16:0927c093fd82 | 207 | void SX1276inAir9::SetAntSwLowPower( bool status ) |
modtronix | 16:0927c093fd82 | 208 | { |
modtronix | 16:0927c093fd82 | 209 | if( isRadioActive != status ) |
modtronix | 16:0927c093fd82 | 210 | { |
modtronix | 16:0927c093fd82 | 211 | isRadioActive = status; |
modtronix | 16:0927c093fd82 | 212 | |
modtronix | 16:0927c093fd82 | 213 | if( status == false ) |
modtronix | 16:0927c093fd82 | 214 | { |
modtronix | 16:0927c093fd82 | 215 | AntSwInit( ); |
modtronix | 16:0927c093fd82 | 216 | } |
modtronix | 16:0927c093fd82 | 217 | else |
modtronix | 16:0927c093fd82 | 218 | { |
modtronix | 16:0927c093fd82 | 219 | AntSwDeInit( ); |
modtronix | 16:0927c093fd82 | 220 | } |
modtronix | 16:0927c093fd82 | 221 | } |
modtronix | 16:0927c093fd82 | 222 | } |
modtronix | 16:0927c093fd82 | 223 | |
modtronix | 16:0927c093fd82 | 224 | void SX1276inAir9::AntSwInit( void ) |
modtronix | 16:0927c093fd82 | 225 | { |
modtronix | 16:0927c093fd82 | 226 | //antSwitch = 0; |
modtronix | 16:0927c093fd82 | 227 | } |
modtronix | 16:0927c093fd82 | 228 | |
modtronix | 16:0927c093fd82 | 229 | void SX1276inAir9::AntSwDeInit( void ) |
modtronix | 16:0927c093fd82 | 230 | { |
modtronix | 16:0927c093fd82 | 231 | //antSwitch = 0; |
modtronix | 16:0927c093fd82 | 232 | } |
modtronix | 16:0927c093fd82 | 233 | |
modtronix | 16:0927c093fd82 | 234 | void SX1276inAir9::SetAntSw( uint8_t rxTx ) |
modtronix | 16:0927c093fd82 | 235 | { |
modtronix | 16:0927c093fd82 | 236 | if( this->rxTx == rxTx ) |
modtronix | 16:0927c093fd82 | 237 | { |
modtronix | 16:0927c093fd82 | 238 | //no need to go further |
modtronix | 16:0927c093fd82 | 239 | return; |
modtronix | 16:0927c093fd82 | 240 | } |
modtronix | 16:0927c093fd82 | 241 | |
modtronix | 16:0927c093fd82 | 242 | this->rxTx = rxTx; |
modtronix | 16:0927c093fd82 | 243 | |
modtronix | 16:0927c093fd82 | 244 | // if( rxTx != 0 ) |
modtronix | 16:0927c093fd82 | 245 | // { |
modtronix | 16:0927c093fd82 | 246 | // antSwitch = 1; |
modtronix | 16:0927c093fd82 | 247 | // } |
modtronix | 16:0927c093fd82 | 248 | // else |
modtronix | 16:0927c093fd82 | 249 | // { |
modtronix | 16:0927c093fd82 | 250 | // antSwitch = 0; |
modtronix | 16:0927c093fd82 | 251 | // } |
modtronix | 16:0927c093fd82 | 252 | } |
modtronix | 16:0927c093fd82 | 253 | |
modtronix | 16:0927c093fd82 | 254 | bool SX1276inAir9::CheckRfFrequency( uint32_t frequency ) |
modtronix | 16:0927c093fd82 | 255 | { |
modtronix | 16:0927c093fd82 | 256 | //TODO: Implement check, currently all frequencies are supported |
modtronix | 16:0927c093fd82 | 257 | return true; |
modtronix | 16:0927c093fd82 | 258 | } |
modtronix | 16:0927c093fd82 | 259 | |
modtronix | 16:0927c093fd82 | 260 | |
modtronix | 16:0927c093fd82 | 261 | void SX1276inAir9::Reset( void ) |
modtronix | 16:0927c093fd82 | 262 | { |
modtronix | 16:0927c093fd82 | 263 | reset.output(); |
modtronix | 16:0927c093fd82 | 264 | reset = 0; |
modtronix | 16:0927c093fd82 | 265 | wait_ms( 1 ); |
modtronix | 16:0927c093fd82 | 266 | reset.input(); |
modtronix | 16:0927c093fd82 | 267 | wait_ms( 6 ); |
modtronix | 16:0927c093fd82 | 268 | } |
modtronix | 16:0927c093fd82 | 269 | |
modtronix | 16:0927c093fd82 | 270 | void SX1276inAir9::Write( uint8_t addr, uint8_t data ) |
modtronix | 16:0927c093fd82 | 271 | { |
modtronix | 16:0927c093fd82 | 272 | Write( addr, &data, 1 ); |
modtronix | 16:0927c093fd82 | 273 | } |
modtronix | 16:0927c093fd82 | 274 | |
modtronix | 16:0927c093fd82 | 275 | uint8_t SX1276inAir9::Read( uint8_t addr ) |
modtronix | 16:0927c093fd82 | 276 | { |
modtronix | 16:0927c093fd82 | 277 | uint8_t data; |
modtronix | 16:0927c093fd82 | 278 | Read( addr, &data, 1 ); |
modtronix | 16:0927c093fd82 | 279 | return data; |
modtronix | 16:0927c093fd82 | 280 | } |
modtronix | 16:0927c093fd82 | 281 | |
modtronix | 16:0927c093fd82 | 282 | void SX1276inAir9::Write( uint8_t addr, uint8_t *buffer, uint8_t size ) |
modtronix | 16:0927c093fd82 | 283 | { |
modtronix | 16:0927c093fd82 | 284 | uint8_t i; |
modtronix | 16:0927c093fd82 | 285 | |
modtronix | 16:0927c093fd82 | 286 | nss = 0; |
modtronix | 16:0927c093fd82 | 287 | spi.write( addr | 0x80 ); |
modtronix | 16:0927c093fd82 | 288 | for( i = 0; i < size; i++ ) |
modtronix | 16:0927c093fd82 | 289 | { |
modtronix | 16:0927c093fd82 | 290 | spi.write( buffer[i] ); |
modtronix | 16:0927c093fd82 | 291 | } |
modtronix | 16:0927c093fd82 | 292 | nss = 1; |
modtronix | 16:0927c093fd82 | 293 | } |
modtronix | 16:0927c093fd82 | 294 | |
modtronix | 16:0927c093fd82 | 295 | void SX1276inAir9::Read( uint8_t addr, uint8_t *buffer, uint8_t size ) |
modtronix | 16:0927c093fd82 | 296 | { |
modtronix | 16:0927c093fd82 | 297 | uint8_t i; |
modtronix | 16:0927c093fd82 | 298 | |
modtronix | 16:0927c093fd82 | 299 | nss = 0; |
modtronix | 16:0927c093fd82 | 300 | spi.write( addr & 0x7F ); |
modtronix | 16:0927c093fd82 | 301 | for( i = 0; i < size; i++ ) |
modtronix | 16:0927c093fd82 | 302 | { |
modtronix | 16:0927c093fd82 | 303 | buffer[i] = spi.write( 0 ); |
modtronix | 16:0927c093fd82 | 304 | } |
modtronix | 16:0927c093fd82 | 305 | nss = 1; |
modtronix | 16:0927c093fd82 | 306 | } |
modtronix | 16:0927c093fd82 | 307 | |
modtronix | 16:0927c093fd82 | 308 | void SX1276inAir9::WriteFifo( uint8_t *buffer, uint8_t size ) |
modtronix | 16:0927c093fd82 | 309 | { |
modtronix | 16:0927c093fd82 | 310 | Write( 0, buffer, size ); |
modtronix | 16:0927c093fd82 | 311 | } |
modtronix | 16:0927c093fd82 | 312 | |
modtronix | 16:0927c093fd82 | 313 | void SX1276inAir9::ReadFifo( uint8_t *buffer, uint8_t size ) |
modtronix | 16:0927c093fd82 | 314 | { |
modtronix | 16:0927c093fd82 | 315 | Read( 0, buffer, size ); |
modtronix | 16:0927c093fd82 | 316 | } |