LCOV - code coverage report
Current view: top level - src/modules/LR11x0 - LR1110.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 26 64 40.6 %
Date: 2026-02-22 10:42:45 Functions: 8 11 72.7 %

          Line data    Source code
       1             : #include "LR1110.h"
       2             : #include <math.h>
       3             : 
       4             : #if !RADIOLIB_EXCLUDE_LR11X0
       5             : 
       6           1 : LR1110::LR1110(Module* mod) : LR11x0(mod) {
       7           1 :   chipType = RADIOLIB_LR11X0_DEVICE_LR1110;
       8           1 : }
       9             : 
      10           0 : int16_t LR1110::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
      11             :   // execute common part
      12           0 :   int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage);
      13           0 :   RADIOLIB_ASSERT(state);
      14             : 
      15             :   // configure publicly accessible settings
      16           0 :   state = setFrequency(freq);
      17           0 :   RADIOLIB_ASSERT(state);
      18             : 
      19           0 :   state = setOutputPower(power);
      20           0 :   return(state);
      21             : }
      22             : 
      23           0 : int16_t LR1110::beginGFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
      24             :   // execute common part
      25           0 :   int16_t state = LR11x0::beginGFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage);
      26           0 :   RADIOLIB_ASSERT(state);
      27             : 
      28             :   // configure publicly accessible settings
      29           0 :   state = setFrequency(freq);
      30           0 :   RADIOLIB_ASSERT(state);
      31             : 
      32           0 :   state = setOutputPower(power);
      33           0 :   return(state);
      34             : }
      35             : 
      36           0 : int16_t LR1110::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, bool narrowGrid, int8_t power, float tcxoVoltage) {
      37             :   // execute common part
      38           0 :   int16_t state = LR11x0::beginLRFHSS(bw, cr, narrowGrid, tcxoVoltage);
      39           0 :   RADIOLIB_ASSERT(state);
      40             : 
      41             :   // configure publicly accessible settings
      42           0 :   state = setFrequency(freq);
      43           0 :   RADIOLIB_ASSERT(state);
      44             : 
      45           0 :   state = setOutputPower(power);
      46           0 :   return(state);
      47             : }
      48             : 
      49           1 : int16_t LR1110::setFrequency(float freq) {
      50           1 :   return(this->setFrequency(freq, false));
      51             : }
      52             : 
      53           1 : int16_t LR1110::setFrequency(float freq, bool skipCalibration, float band) {
      54           1 :   RADIOLIB_CHECK_RANGE(freq, 150.0f, 960.0f, RADIOLIB_ERR_INVALID_FREQUENCY);
      55             :   
      56             :   // check if we need to recalibrate image
      57             :   int16_t state;
      58           0 :   if(!skipCalibration && (fabsf(freq - this->freqMHz) >= RADIOLIB_LR11X0_CAL_IMG_FREQ_TRIG_MHZ)) {
      59           0 :     state = LR11x0::calibrateImageRejection(freq - band, freq + band);
      60           0 :     RADIOLIB_ASSERT(state);
      61             :   }
      62             : 
      63             :   // set frequency
      64           0 :   state = LR11x0::setRfFrequency((uint32_t)(freq*1000000.0f));
      65           0 :   RADIOLIB_ASSERT(state);
      66           0 :   this->freqMHz = freq;
      67           0 :   return(state);
      68             : }
      69             : 
      70           1 : int16_t LR1110::setOutputPower(int8_t power) {
      71           1 :   return(this->setOutputPower(power, false));
      72             : }
      73             : 
      74           1 : int16_t LR1110::setOutputPower(int8_t power, bool forceHighPower, uint32_t rampTimeUs) {
      75             :   // check if power value is configurable
      76           1 :   int16_t state = this->checkOutputPower(power, NULL, forceHighPower);
      77           1 :   RADIOLIB_ASSERT(state);
      78             : 
      79             :   // determine whether to use HP or LP PA and check range accordingly
      80           1 :   bool useHp = forceHighPower || (power > 14);
      81             :   
      82             :   // TODO how and when to configure OCP?
      83             : 
      84             :   // update PA config and set output power - always use VBAT for high-power PA
      85             :   // the value returned by LRxxxx class is offset by 3 for LR11x0
      86           1 :   state = LR11x0::setOutputPower(power, (uint8_t)useHp, (uint8_t)useHp, 0x04, 0x07, roundRampTime(rampTimeUs) - 0x03);
      87           1 :   return(state);
      88             : }
      89             : 
      90           1 : int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped) {
      91           1 :   return(checkOutputPower(power, clipped, false));
      92             : }
      93             : 
      94           2 : int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower) {
      95           2 :   if(forceHighPower || (power > 14)) {
      96           0 :     if(clipped) {
      97           0 :       *clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
      98             :     }
      99           0 :     RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
     100             :   
     101             :   } else {
     102           2 :     if(clipped) {
     103           0 :       *clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
     104             :     }
     105           2 :     RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
     106             :   
     107             :   }
     108           2 :   return(RADIOLIB_ERR_NONE);
     109             : }
     110             : 
     111           1 : int16_t LR1110::setModem(ModemType_t modem) {
     112           1 :   switch(modem) {
     113           0 :     case(ModemType_t::RADIOLIB_MODEM_LORA): {
     114           0 :       return(this->begin());
     115             :     } break;
     116           0 :     case(ModemType_t::RADIOLIB_MODEM_FSK): {
     117           0 :       return(this->beginGFSK());
     118             :     } break;
     119           0 :     case(ModemType_t::RADIOLIB_MODEM_LRFHSS): {
     120           0 :       return(this->beginLRFHSS());
     121             :     } break;
     122           1 :     default:
     123           1 :       return(RADIOLIB_ERR_WRONG_MODEM);
     124             :   }
     125             :   return(RADIOLIB_ERR_WRONG_MODEM);
     126             : }
     127             : 
     128             : #endif

Generated by: LCOV version 1.14