acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
SX1277.cpp (2604B)
1 #include "SX1277.h" 2 #if !defined(RADIOLIB_EXCLUDE_SX127X) 3 4 SX1277::SX1277(Module* mod) : SX1278(mod) { 5 6 } 7 8 int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { 9 // execute common part 10 int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength); 11 RADIOLIB_ASSERT(state); 12 13 // configure publicly accessible settings 14 state = setBandwidth(bw); 15 RADIOLIB_ASSERT(state); 16 17 state = setFrequency(freq); 18 RADIOLIB_ASSERT(state); 19 20 state = setSpreadingFactor(sf); 21 RADIOLIB_ASSERT(state); 22 23 state = setCodingRate(cr); 24 RADIOLIB_ASSERT(state); 25 26 state = setOutputPower(power); 27 RADIOLIB_ASSERT(state); 28 29 state = setGain(gain); 30 RADIOLIB_ASSERT(state); 31 32 return(state); 33 } 34 35 int16_t SX1277::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { 36 // execute common part 37 int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK); 38 RADIOLIB_ASSERT(state); 39 40 // configure settings not accessible by API 41 state = configFSK(); 42 RADIOLIB_ASSERT(state); 43 44 // configure publicly accessible settings 45 state = setFrequency(freq); 46 RADIOLIB_ASSERT(state); 47 48 state = setOutputPower(power); 49 RADIOLIB_ASSERT(state); 50 51 if(enableOOK) { 52 state = setDataShapingOOK(RADIOLIB_SHAPING_NONE); 53 RADIOLIB_ASSERT(state); 54 } else { 55 state = setDataShaping(RADIOLIB_SHAPING_NONE); 56 RADIOLIB_ASSERT(state); 57 } 58 59 return(state); 60 } 61 62 int16_t SX1277::setFrequency(float freq) { 63 RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, RADIOLIB_ERR_INVALID_FREQUENCY); 64 65 // set frequency and if successful, save the new setting 66 int16_t state = SX127x::setFrequencyRaw(freq); 67 if(state == RADIOLIB_ERR_NONE) { 68 SX127x::_freq = freq; 69 } 70 return(state); 71 } 72 73 int16_t SX1277::setSpreadingFactor(uint8_t sf) { 74 uint8_t newSpreadingFactor; 75 76 // check allowed spreading factor values 77 switch(sf) { 78 case 6: 79 newSpreadingFactor = RADIOLIB_SX127X_SF_6; 80 break; 81 case 7: 82 newSpreadingFactor = RADIOLIB_SX127X_SF_7; 83 break; 84 case 8: 85 newSpreadingFactor = RADIOLIB_SX127X_SF_8; 86 break; 87 case 9: 88 newSpreadingFactor = RADIOLIB_SX127X_SF_9; 89 break; 90 default: 91 return(RADIOLIB_ERR_INVALID_SPREADING_FACTOR); 92 } 93 94 // set spreading factor and if successful, save the new setting 95 int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); 96 if(state == RADIOLIB_ERR_NONE) { 97 SX127x::_sf = sf; 98 } 99 100 return(state); 101 } 102 103 #endif