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

SX1262.cpp (2959B)

      1 #include "SX1262.h"
      2 #if !defined(RADIOLIB_EXCLUDE_SX126X)
      3 
      4 SX1262::SX1262(Module* mod) : SX126x(mod) {
      5 
      6 }
      7 
      8 int16_t SX1262::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 = setSpreadingFactor(sf);
     15   RADIOLIB_ASSERT(state);
     16 
     17   state = setBandwidth(bw);
     18   RADIOLIB_ASSERT(state);
     19 
     20   state = setFrequency(freq);
     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 SX1262::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 int16_t SX1262::setFrequency(float freq, bool calibrate) {
     51   RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, RADIOLIB_ERR_INVALID_FREQUENCY);
     52 
     53   // calibrate image
     54   if(calibrate) {
     55     uint8_t data[2];
     56     if(freq > 900.0) {
     57       data[0] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_1;
     58       data[1] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_2;
     59     } else if(freq > 850.0) {
     60       data[0] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_1;
     61       data[1] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_2;
     62     } else if(freq > 770.0) {
     63       data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1;
     64       data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2;
     65     } else if(freq > 460.0) {
     66       data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1;
     67       data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2;
     68     } else {
     69       data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1;
     70       data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2;
     71     }
     72     int16_t state = SX126x::calibrateImage(data);
     73     RADIOLIB_ASSERT(state);
     74   }
     75 
     76   // set frequency
     77   return(SX126x::setFrequencyRaw(freq));
     78 }
     79 
     80 int16_t SX1262::setOutputPower(int8_t power) {
     81   RADIOLIB_CHECK_RANGE(power, -17, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
     82 
     83   // get current OCP configuration
     84   uint8_t ocp = 0;
     85   int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
     86   RADIOLIB_ASSERT(state);
     87 
     88   // set PA config
     89   state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1262);
     90   RADIOLIB_ASSERT(state);
     91 
     92   // set output power
     93   /// \todo power ramp time configuration
     94   state = SX126x::setTxParams(power);
     95   RADIOLIB_ASSERT(state);
     96 
     97   // restore OCP configuration
     98   return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
     99 }
    100 
    101 #endif