LCOV - code coverage report
Current view: top level - src/modules/LR11x0 - LR1110.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 24 61 39.3 %
Date: 2026-11-08 19:43:08 Functions: 6 9 66.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 :   this->powerMin = RADIOLIB_LR1110_LP_POUT_MIN;
       9           1 :   this->powerMax = RADIOLIB_LR1110_HP_POUT_MAX;
      10           1 :   this->paSteps = this->powerMax - this->powerMin + 1;
      11           1 : }
      12             : 
      13           0 : int16_t LR1110::begin(const ConfigLoRa_t& cfg) {
      14             :   // execute common part
      15           0 :   int16_t state = LR11x0::begin(cfg.bandwidth, cfg.spreadingFactor, cfg.codingRate, cfg.syncWord, cfg.preambleLength);
      16           0 :   RADIOLIB_ASSERT(state);
      17             : 
      18             :   // configure publicly accessible settings
      19           0 :   state = setFrequency(cfg.frequency);
      20           0 :   RADIOLIB_ASSERT(state);
      21             : 
      22           0 :   state = setOutputPower(cfg.power);
      23           0 :   return(state);
      24             : }
      25             : 
      26           0 : int16_t LR1110::beginGFSK(const ConfigFSK_t& cfg) {
      27             :   // execute common part
      28           0 :   int16_t state = LR11x0::beginGFSK(cfg.bitRate, cfg.frequencyDeviation, cfg.receiverBandwidth, cfg.preambleLength);
      29           0 :   RADIOLIB_ASSERT(state);
      30             : 
      31             :   // configure publicly accessible settings
      32           0 :   state = setFrequency(cfg.frequency);
      33           0 :   RADIOLIB_ASSERT(state);
      34             : 
      35           0 :   state = setOutputPower(cfg.power);
      36           0 :   return(state);
      37             : }
      38             : 
      39           0 : int16_t LR1110::beginLRFHSS(const ConfigLRFHSS_t& cfg) {
      40             :   // execute common part
      41           0 :   int16_t state = LR11x0::beginLRFHSS(cfg.bandwidth, cfg.bandwidth, cfg.narrowGrid);
      42           0 :   RADIOLIB_ASSERT(state);
      43             : 
      44             :   // configure publicly accessible settings
      45           0 :   state = setFrequency(cfg.frequency);
      46           0 :   RADIOLIB_ASSERT(state);
      47             : 
      48           0 :   state = setOutputPower(cfg.power);
      49           0 :   return(state);
      50             : }
      51             : 
      52           1 : int16_t LR1110::setFrequency(uint32_t freq) {
      53           1 :   return(this->setFrequency(freq, false));
      54             : }
      55             : 
      56           1 : int16_t LR1110::setFrequency(uint32_t freq, bool skipCalibration, uint32_t band) {
      57           1 :   RADIOLIB_CHECK_RANGE(freq, RADIOLIB_UNIT_MEGA(150), RADIOLIB_UNIT_MEGA(960), RADIOLIB_ERR_INVALID_FREQUENCY);
      58             :   
      59             :   // check if we need to recalibrate image
      60             :   int16_t state;
      61           0 :   if(!skipCalibration && (RADIOLIB_ABS_UNSIGNED(freq, this->freqHz) >= RADIOLIB_UNIT_MEGA(RADIOLIB_LR11X0_CAL_IMG_FREQ_TRIG_MHZ))) {
      62           0 :     state = LR11x0::calibrateImageRejection(freq - band, freq + band);
      63           0 :     RADIOLIB_ASSERT(state);
      64             :   }
      65             : 
      66             :   // set frequency
      67           0 :   state = LR11x0::setRfFrequency(freq);
      68           0 :   RADIOLIB_ASSERT(state);
      69           0 :   this->freqHz = freq;
      70           0 :   return(state);
      71             : }
      72             : 
      73           1 : int16_t LR1110::setOutputPower(int8_t power) {
      74           1 :   return(this->setOutputPower(power, false));
      75             : }
      76             : 
      77           1 : int16_t LR1110::setOutputPower(int8_t power, bool forceHighPower, uint32_t rampTimeUs) {
      78             :   // apply offset for external PA
      79             :   // use the minimum possible output as LUT base
      80           1 :   int8_t pwr = power;
      81           1 :   int16_t state = this->applyOutputPowerOffset(RADIOLIB_LR1110_LP_POUT_MIN, &power, &pwr);
      82           1 :   RADIOLIB_ASSERT(state);
      83             :   
      84             :   //! \TODO: [LR1110] how and when to configure OCP?
      85             : 
      86             :   // update PA config and set output power - always use VBAT for high-power PA
      87             :   // the value returned by LRxxxx class is offset by 3 for LR11x0
      88           1 :   bool useHp = forceHighPower || (pwr > RADIOLIB_LR1110_LP_POUT_MAX);
      89           1 :   this->txMode = useHp ? LR11x0::MODE_TX_HP : LR11x0::MODE_TX;
      90           1 :   state = LR11x0::setOutputPower(pwr, (uint8_t)useHp, (uint8_t)useHp, 0x04, 0x07, roundRampTime(rampTimeUs) - 0x03);
      91           1 :   return(state);
      92             : }
      93             : 
      94           1 : int16_t LR1110::setModem(ModemType_t modem) {
      95           1 :   switch(modem) {
      96           0 :     case(ModemType_t::RADIOLIB_MODEM_LORA): {
      97           0 :       ConfigLoRa_t cfg;
      98           0 :       return(this->begin(cfg));
      99             :     } break;
     100           0 :     case(ModemType_t::RADIOLIB_MODEM_FSK): {
     101           0 :       ConfigFSK_t cfg;
     102           0 :       return(this->beginGFSK(cfg));
     103             :     } break;
     104           0 :     case(ModemType_t::RADIOLIB_MODEM_LRFHSS): {
     105           0 :       ConfigLRFHSS_t cfg;
     106           0 :       return(this->beginLRFHSS(cfg));
     107             :     } break;
     108           1 :     default:
     109           1 :       return(RADIOLIB_ERR_WRONG_MODEM);
     110             :   }
     111             :   return(RADIOLIB_ERR_WRONG_MODEM);
     112             : }
     113             : 
     114             : #endif

Generated by: LCOV version 1.14