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 |
SX1268.cpp (2771B)
1 #include "SX1268.h" 2 #if !defined(RADIOLIB_EXCLUDE_SX126X) 3 4 SX1268::SX1268(Module* mod) : SX126x(mod) { 5 6 } 7 8 int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { 9 // execute common part 10 int16_t state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO); 11 RADIOLIB_ASSERT(state); 12 13 // configure publicly accessible settings 14 state = setFrequency(freq); 15 RADIOLIB_ASSERT(state); 16 17 state = setSpreadingFactor(sf); 18 RADIOLIB_ASSERT(state); 19 20 state = setBandwidth(bw); 21 RADIOLIB_ASSERT(state); 22 23 state = setOutputPower(power); 24 RADIOLIB_ASSERT(state); 25 26 state = SX126x::fixPaClamping(); 27 RADIOLIB_ASSERT(state); 28 29 return(state); 30 } 31 32 int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { 33 // execute common part 34 int16_t state = SX126x::beginFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage, useRegulatorLDO); 35 RADIOLIB_ASSERT(state); 36 37 // configure publicly accessible settings 38 state = setFrequency(freq); 39 RADIOLIB_ASSERT(state); 40 41 state = setOutputPower(power); 42 RADIOLIB_ASSERT(state); 43 44 state = SX126x::fixPaClamping(); 45 RADIOLIB_ASSERT(state); 46 47 return(state); 48 } 49 50 /// \todo integers only (all modules - frequency, data rate, bandwidth etc.) 51 int16_t SX1268::setFrequency(float freq, bool calibrate) { 52 RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, RADIOLIB_ERR_INVALID_FREQUENCY); 53 54 // calibrate image 55 if(calibrate) { 56 uint8_t data[2]; 57 if(freq > 770.0) { 58 data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1; 59 data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2; 60 } else if(freq > 460.0) { 61 data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1; 62 data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2; 63 } else { 64 data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1; 65 data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2; 66 } 67 int16_t state = SX126x::calibrateImage(data); 68 RADIOLIB_ASSERT(state); 69 } 70 71 // set frequency 72 return(SX126x::setFrequencyRaw(freq)); 73 } 74 75 int16_t SX1268::setOutputPower(int8_t power) { 76 RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER); 77 78 // get current OCP configuration 79 uint8_t ocp = 0; 80 int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1); 81 RADIOLIB_ASSERT(state); 82 83 // set PA config 84 state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1268); 85 RADIOLIB_ASSERT(state); 86 87 // set output power 88 /// \todo power ramp time configuration 89 state = SX126x::setTxParams(power); 90 RADIOLIB_ASSERT(state); 91 92 // restore OCP configuration 93 return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); 94 } 95 96 #endif