LCOV - code coverage report
Current view: top level - src/modules/LR11x0 - LR_common.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 91 256 35.5 %
Date: 2026-06-03 18:53:41 Functions: 10 21 47.6 %

          Line data    Source code
       1             : #include "LR_common.h"
       2             : 
       3             : #include <string.h>
       4             : 
       5          17 : LRxxxx::LRxxxx(Module* mod) : PhysicalLayer() {
       6          17 :   this->mod = mod;
       7          17 :   this->mod->spiConfig.stream = true;
       8          17 :   this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_16;
       9          17 :   this->mod->spiConfig.statusPos = 0;
      10          17 :   this->mod->spiConfig.parseStatusCb = SPIparseStatus;
      11          17 :   this->mod->spiConfig.checkStatusCb = SPIcheckStatus;
      12          17 : }
      13             : 
      14           0 : void LRxxxx::setIrqAction(void (*func)(void)) {
      15           0 :   this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptRising);
      16           0 : }
      17             : 
      18           0 : void LRxxxx::clearIrqAction() {
      19           0 :   this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
      20           0 : }
      21             : 
      22           0 : void LRxxxx::setPacketReceivedAction(void (*func)(void)) {
      23           0 :   this->setIrqAction(func);
      24           0 : }
      25             : 
      26           0 : void LRxxxx::clearPacketReceivedAction() {
      27           0 :   this->clearIrqAction();
      28           0 : }
      29             : 
      30           0 : void LRxxxx::setPacketSentAction(void (*func)(void)) {
      31           0 :   this->setIrqAction(func);
      32           0 : }
      33             : 
      34           0 : void LRxxxx::clearPacketSentAction() {
      35           0 :   this->clearIrqAction();
      36           0 : }
      37             : 
      38           4 : uint32_t LRxxxx::getIrqStatus() {
      39             :   // there is no dedicated "get IRQ" command, the IRQ bits are sent after the status bytes
      40           4 :   uint8_t buff[6] = { 0 };
      41           4 :   Module::BitWidth_t statusWidth = mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS];
      42           4 :   this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS] = Module::BITS_0;
      43           4 :   mod->SPItransferStream(NULL, 0, false, NULL, buff, sizeof(buff), true);
      44           4 :   this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS] = statusWidth;
      45           4 :   uint32_t irq = ((uint32_t)(buff[2]) << 24) | ((uint32_t)(buff[3]) << 16) | ((uint32_t)(buff[4]) << 8) | (uint32_t)buff[5];
      46           4 :   return(irq);
      47             : }
      48             : 
      49           3 : RadioLibTime_t LRxxxx::getToA(size_t len, ModemType_t modem) {
      50           3 :   DataRate_t dr = {};
      51           3 :   PacketConfig_t pc = {};
      52           3 :   switch(modem) {
      53           0 :     case ModemType_t::RADIOLIB_MODEM_LORA: {
      54           0 :       uint8_t cr = this->codingRate;
      55             :       // We assume same calculation for short and long interleaving, so map CR values 0-4 and 5-7 to the same values
      56           0 :       if (cr < 5) {
      57           0 :         cr = cr + 4;
      58           0 :       } else if (cr == 7) {
      59           0 :         cr = cr + 1;
      60             :       }
      61             : 
      62           0 :       dr.lora.spreadingFactor = this->spreadingFactor;
      63           0 :       dr.lora.bandwidth = this->bandwidthKhz;
      64           0 :       dr.lora.codingRate = cr;
      65             : 
      66           0 :       pc.lora.preambleLength = this->preambleLengthLoRa;
      67           0 :       pc.lora.implicitHeader = (this->headerType == RADIOLIB_LRXXXX_LORA_HEADER_IMPLICIT);
      68           0 :       pc.lora.crcEnabled = (this->crcTypeLoRa == RADIOLIB_LRXXXX_LORA_CRC_ENABLED);
      69           0 :       pc.lora.ldrOptimize = (bool)this->ldrOptimize;
      70           0 :       break;
      71             :     }
      72             : 
      73           0 :     case ModemType_t::RADIOLIB_MODEM_FSK: {
      74           0 :       dr.fsk.bitRate = (float)this->bitRate / 1000.0f;
      75           0 :       dr.fsk.freqDev = (float)this->frequencyDev;
      76           0 :       pc.fsk.preambleLength = this->preambleLengthGFSK;
      77           0 :       pc.fsk.syncWordLength = this->syncWordLength; 
      78           0 :       pc.fsk.crcLength = this->crcLenGFSK;
      79           0 :       break;
      80             :     }
      81             : 
      82           0 :     case ModemType_t::RADIOLIB_MODEM_LRFHSS: {
      83           0 :       dr.lrFhss.bw = this->lrFhssBw;
      84           0 :       dr.lrFhss.cr = this->lrFhssCr;
      85           0 :       dr.lrFhss.narrowGrid = (this->lrFhssGrid == RADIOLIB_LRXXXX_LR_FHSS_GRID_STEP_NON_FCC) ? true : false;
      86             : 
      87           0 :       pc.lrFhss.hdrCount = this->lrFhssHdrCount;
      88           0 :       break;
      89             :     }
      90             : 
      91           3 :     default:
      92           3 :       return(RADIOLIB_ERR_WRONG_MODEM);
      93             :   }
      94             : 
      95           0 :   return(this->calculateTimeOnAir(modem, dr, pc, len));
      96             : }
      97             : 
      98          17 : RadioLibTime_t LRxxxx::calculateTimeOnAir(ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len) {
      99             :   // check active modem
     100          17 :   if (modem == ModemType_t::RADIOLIB_MODEM_LORA) {  
     101           6 :     uint32_t symbolLength_us = ((uint32_t)(1000 * 10) << dr.lora.spreadingFactor) / (dr.lora.bandwidth * 10) ;
     102           6 :     uint8_t sfCoeff1_x4 = 17; // (4.25 * 4)
     103           6 :     uint8_t sfCoeff2 = 8;
     104           6 :     if(dr.lora.spreadingFactor == 5 || dr.lora.spreadingFactor == 6) {
     105           0 :       sfCoeff1_x4 = 25; // 6.25 * 4
     106           0 :       sfCoeff2 = 0;
     107             :     }
     108           6 :     uint8_t sfDivisor = 4*dr.lora.spreadingFactor;
     109           6 :     if(pc.lora.ldrOptimize) {
     110           3 :       sfDivisor = 4*(dr.lora.spreadingFactor - 2);
     111             :     }
     112           6 :     const int8_t bitsPerCrc = 16;
     113           6 :     const int8_t N_symbol_header = pc.lora.implicitHeader ? 0 : 20;
     114             : 
     115             :     // numerator of equation in section 6.1.4 of SX1268 datasheet v1.1 (might not actually be bitcount, but it has len * 8)
     116           6 :     int16_t bitCount = (int16_t) 8 * len + pc.lora.crcEnabled * bitsPerCrc - 4 * dr.lora.spreadingFactor  + sfCoeff2 + N_symbol_header;
     117           6 :     if(bitCount < 0) {
     118           0 :       bitCount = 0;
     119             :     }
     120             :     // add (sfDivisor) - 1 to the numerator to give integer CEIL(...)
     121           6 :     uint16_t nPreCodedSymbols = (bitCount + (sfDivisor - 1)) / (sfDivisor);
     122             : 
     123             :     // preamble can be 65k, therefore nSymbol_x4 needs to be 32 bit
     124           6 :     uint32_t nSymbol_x4 = (pc.lora.preambleLength + 8) * 4 + sfCoeff1_x4 + nPreCodedSymbols * dr.lora.codingRate * 4;
     125             : 
     126             :     // get time-on-air in us
     127           6 :     return((symbolLength_us * nSymbol_x4) / 4);
     128             : 
     129          11 :   } else if(modem == ModemType_t::RADIOLIB_MODEM_FSK) {
     130           4 :     return((((float)(pc.fsk.crcLength * 8) + pc.fsk.syncWordLength + pc.fsk.preambleLength + (uint32_t)len * 8) / (dr.fsk.bitRate / 1000.0f)));
     131             : 
     132           7 :   } else if(modem == ModemType_t::RADIOLIB_MODEM_LRFHSS) {
     133             :     // calculate the number of bits based on coding rate
     134             :     uint16_t N_bits;
     135           3 :     switch(dr.lrFhss.cr) {
     136           0 :       case RADIOLIB_LRXXXX_LR_FHSS_CR_5_6:
     137           0 :         N_bits = ((len * 6) + 4) / 5; // this is from the official LR11xx driver, but why the extra +4?
     138           0 :         break;
     139           0 :       case RADIOLIB_LRXXXX_LR_FHSS_CR_2_3:
     140           0 :         N_bits = (len * 3) / 2;
     141           0 :         break;
     142           0 :       case RADIOLIB_LRXXXX_LR_FHSS_CR_1_2:
     143           0 :         N_bits = len * 2;
     144           0 :         break;
     145           3 :       case RADIOLIB_LRXXXX_LR_FHSS_CR_1_3:
     146           3 :         N_bits = len * 3;
     147           3 :         break;
     148           0 :       default:
     149           0 :         return(RADIOLIB_ERR_INVALID_CODING_RATE);
     150             :     }
     151             : 
     152             :     // calculate number of bits when accounting for unaligned last block
     153           3 :     uint16_t N_payBits = (N_bits / RADIOLIB_LRXXXX_LR_FHSS_FRAG_BITS) * RADIOLIB_LRXXXX_LR_FHSS_BLOCK_BITS;
     154           3 :     uint16_t N_lastBlockBits = N_bits % RADIOLIB_LRXXXX_LR_FHSS_FRAG_BITS;
     155           3 :     if(N_lastBlockBits) {
     156           3 :       N_payBits += N_lastBlockBits + 2;
     157             :     }
     158             : 
     159             :     // add header bits
     160           3 :     uint16_t N_totalBits = (RADIOLIB_LRXXXX_LR_FHSS_HEADER_BITS * pc.lrFhss.hdrCount) + N_payBits;
     161           3 :     return(((uint32_t)N_totalBits * 8 * 1000000UL) / RADIOLIB_LRXXXX_LR_FHSS_BIT_RATE);
     162             :   
     163             :   } else {
     164           4 :     return(RADIOLIB_ERR_WRONG_MODEM);
     165             :   }
     166             : 
     167             :   return(0);
     168             : }
     169             : 
     170           4 : RadioLibTime_t LRxxxx::calculateRxTimeout(RadioLibTime_t timeoutUs) {
     171             :   // the timeout value is given in units of 30.52 microseconds
     172             :   // the calling function should provide some extra width, as this number of units is truncated to integer
     173           4 :   RadioLibTime_t timeout = timeoutUs / 30.52;
     174           4 :   return(timeout);
     175             : }
     176             : 
     177           0 : int16_t LRxxxx::reset() {
     178             :   // run the reset sequence
     179           0 :   this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
     180           0 :   this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
     181           0 :   this->mod->hal->delay(10);
     182           0 :   this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
     183             : 
     184             :   // the typical transition duration should be 273 ms
     185           0 :   this->mod->hal->delay(300);
     186             :   
     187             :   // wait for BUSY to go low
     188           0 :   RadioLibTime_t start = this->mod->hal->millis();
     189           0 :   while(this->mod->hal->digitalRead(this->mod->getGpio())) {
     190           0 :     this->mod->hal->yield();
     191           0 :     if(this->mod->hal->millis() - start >= 3000) {
     192             :       RADIOLIB_DEBUG_BASIC_PRINTLN("BUSY pin timeout after reset!");
     193           0 :       return(RADIOLIB_ERR_SPI_CMD_TIMEOUT);
     194             :     }
     195             :   }
     196             : 
     197           0 :   return(RADIOLIB_ERR_NONE);
     198             : }
     199             : 
     200           0 : int16_t LRxxxx::getStatus(uint8_t* stat1, uint8_t* stat2, uint32_t* irq) {
     201           0 :   uint8_t buff[6] = { 0 };
     202             : 
     203             :   // the status check command doesn't return status in the same place as other read commands
     204             :   // but only as the first byte (as with any other command), hence LRxxxx::SPIcommand can't be used
     205             :   // it also seems to ignore the actual command, and just sending in bunch of NOPs will work 
     206           0 :   int16_t state = this->mod->SPItransferStream(NULL, 0, false, NULL, buff, sizeof(buff), true);
     207             : 
     208             :   // pass the replies
     209           0 :   if(stat1) { *stat1 = buff[0]; }
     210           0 :   if(stat2) { *stat2 = buff[1]; }
     211           0 :   if(irq)   { *irq = ((uint32_t)(buff[2]) << 24) | ((uint32_t)(buff[3]) << 16) | ((uint32_t)(buff[4]) << 8) | (uint32_t)buff[5]; }
     212             : 
     213           0 :   return(state);
     214             : }
     215             : 
     216           0 : int16_t LRxxxx::lrFhssBuildFrame(uint16_t cmd, uint8_t hdrCount, uint8_t cr, uint8_t grid, uint8_t hop, uint8_t bw, uint16_t hopSeq, int8_t devOffset, const uint8_t* payload, size_t len) {
     217             :   // check maximum size
     218           0 :   const uint8_t maxLen[4][4] = {
     219             :     { 189, 178, 167, 155, },
     220             :     { 151, 142, 133, 123, },
     221             :     { 112, 105,  99,  92, },
     222             :     {  74,  69,  65,  60, },
     223             :   };
     224           0 :   if((cr > RADIOLIB_LRXXXX_LR_FHSS_CR_1_3) || ((hdrCount - 1) > (int)sizeof(maxLen[0])) || (len > maxLen[cr][hdrCount - 1])) {
     225           0 :     return(RADIOLIB_ERR_SPI_CMD_INVALID);
     226             :   }
     227             : 
     228             :   // build buffers
     229           0 :   size_t buffLen = 9 + len;
     230             :   #if RADIOLIB_STATIC_ONLY
     231             :     uint8_t dataBuff[9 + 190];
     232             :   #else
     233           0 :     uint8_t* dataBuff = new uint8_t[buffLen];
     234             :   #endif
     235             : 
     236             :   // set properties of the packet
     237           0 :   dataBuff[0] = hdrCount;
     238           0 :   dataBuff[1] = cr;
     239           0 :   dataBuff[2] = RADIOLIB_LRXXXX_LR_FHSS_MOD_TYPE_GMSK;
     240           0 :   dataBuff[3] = grid;
     241           0 :   dataBuff[4] = hop;
     242           0 :   dataBuff[5] = bw;
     243           0 :   dataBuff[6] = (uint8_t)((hopSeq >> 8) & 0x01);
     244           0 :   dataBuff[7] = (uint8_t)(hopSeq & 0xFF);
     245           0 :   dataBuff[8] = devOffset;
     246           0 :   memcpy(&dataBuff[9], payload, len);
     247             : 
     248           0 :   int16_t state = this->SPIcommand(cmd, true, dataBuff, buffLen);
     249             :   #if !RADIOLIB_STATIC_ONLY
     250           0 :     delete[] dataBuff;
     251             :   #endif
     252           0 :   return(state);
     253             : }
     254             : 
     255           3 : uint8_t LRxxxx::roundRampTime(uint32_t rampTimeUs) {
     256             :   uint8_t regVal;
     257             : 
     258             :   // Round up the ramp time to nearest discrete register value
     259           3 :   if(rampTimeUs <= 2) {
     260           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_2U;
     261           3 :   } else if(rampTimeUs <= 4) {
     262           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_4U;
     263           3 :   } else if(rampTimeUs <= 8) {
     264           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_8U;
     265           3 :   } else if(rampTimeUs <= 16) {
     266           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_16U;
     267           3 :   } else if(rampTimeUs <= 32) {
     268           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_32U;
     269           3 :   } else if(rampTimeUs <= 48) {
     270           3 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_48U;
     271           0 :   } else if(rampTimeUs <= 64) {
     272           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_64U;
     273           0 :   } else if(rampTimeUs <= 80) {
     274           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_80U;
     275           0 :   } else if(rampTimeUs <= 96) {
     276           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_96U;
     277           0 :   } else if(rampTimeUs <= 112) {
     278           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_112U;
     279           0 :   } else if(rampTimeUs <= 128) {
     280           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_128U;
     281           0 :   } else if(rampTimeUs <= 144) {
     282           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_144U;
     283           0 :   } else if(rampTimeUs <= 160) {
     284           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_160U;
     285           0 :   } else if(rampTimeUs <= 176) {
     286           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_176U;
     287           0 :   } else if(rampTimeUs <= 192) {
     288           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_192U;
     289           0 :   } else if(rampTimeUs <= 208) {
     290           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_208U;
     291           0 :   } else if(rampTimeUs <= 240) {
     292           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_240U;
     293           0 :   } else if(rampTimeUs <= 272) {
     294           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_272U;
     295             :   } else {  // 304
     296           0 :     regVal = RADIOLIB_LRXXXX_PA_RAMP_304U;
     297             :   }
     298             : 
     299           3 :   return regVal;
     300             : }
     301             : 
     302           0 : int16_t LRxxxx::findRxBw(float rxBw, const uint8_t* lut, size_t lutSize, float rxBwMax, uint8_t* val) {
     303             :   // lookup tables to avoid comparing a whole bunch of floats
     304           0 :   const uint16_t rxBwAvg[] = {
     305             :     53, 66, 85, 108, 134, 170, 211, 264,
     306             :     341, 424, 529, 682, 847, 1058, 1364,
     307             :     1695, 2116, 2729, 3390, 4233, 5159,
     308             :     6111, 7179, 9401, 16665, 24440, 28710,
     309             :   };
     310             : 
     311             :   // iterate through the table and find whether the user-provided value
     312             :   // is lower than the pre-computed average of the adjacent bandwidth values
     313             :   // if it is, we consider that to be a match even though the actual value is not precise
     314           0 :   uint16_t rxBwInt = rxBw*10.0f;
     315           0 :   for(size_t i = 0; i < (lutSize - 1); i++) {
     316           0 :     if(rxBwInt < rxBwAvg[i]) {
     317           0 :       *val = lut[i];
     318           0 :       return(RADIOLIB_ERR_NONE);
     319             :     }
     320             :   }
     321             : 
     322             :   // if nothing matched up to here, match with the last value
     323           0 :   if(rxBwInt <= rxBwMax*10) {
     324           0 :     *val = lut[lutSize - 1];
     325           0 :     return(RADIOLIB_ERR_NONE);
     326             :   }
     327             : 
     328           0 :   return(RADIOLIB_ERR_INVALID_RX_BANDWIDTH);
     329             : }
     330             : 
     331           8 : int16_t LRxxxx::setU32(uint16_t cmd, uint32_t u32) {
     332             :   uint8_t buff[] = { 
     333           8 :     (uint8_t)((u32 >> 24) & 0xFF), (uint8_t)((u32 >> 16) & 0xFF),
     334           8 :     (uint8_t)((u32 >> 8) & 0xFF), (uint8_t)(u32 & 0xFF),
     335           8 :   };
     336          16 :   return(this->SPIcommand(cmd, true, buff, sizeof(buff)));
     337             : }
     338             : 
     339        3059 : int16_t LRxxxx::SPIparseStatus(uint8_t in) {
     340        3059 :   if((in & 0b00001110) == RADIOLIB_LRXXXX_STAT_1_CMD_PERR) {
     341           0 :     return(RADIOLIB_ERR_SPI_CMD_INVALID);
     342        3059 :   } else if((in & 0b00001110) == RADIOLIB_LRXXXX_STAT_1_CMD_FAIL) {
     343           0 :     return(RADIOLIB_ERR_SPI_CMD_FAILED);
     344        3059 :   } else if((in == 0x00) || (in == 0xFF)) {
     345        3059 :     return(RADIOLIB_ERR_CHIP_NOT_FOUND);
     346             :   }
     347           0 :   return(RADIOLIB_ERR_NONE);
     348             : }
     349             : 
     350           9 : int16_t LRxxxx::SPIcheckStatus(Module* mod) {
     351             :   // the status check command doesn't return status in the same place as other read commands,
     352             :   // but only as the first byte (as with any other command), hence LR11x0::SPIcommand can't be used
     353             :   // it also seems to ignore the actual command, and just sending in bunch of NOPs will work 
     354           9 :   uint8_t buff[6] = { 0 };
     355           9 :   Module::BitWidth_t statusWidth = mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS];
     356           9 :   mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS] = Module::BITS_0;
     357           9 :   int16_t state = mod->SPItransferStream(NULL, 0, false, NULL, buff, sizeof(buff), true);
     358           9 :   mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS] = statusWidth;
     359           9 :   RADIOLIB_ASSERT(state);
     360           0 :   return(LRxxxx::SPIparseStatus(buff[0]));
     361             : }
     362             : 
     363           0 : int16_t LRxxxx::writeCommon(uint16_t cmd, uint32_t addrOffset, const uint32_t* data, size_t len, bool nonvolatile) {
     364             :   // build buffers - later we need to ensure endians are correct, 
     365             :   // so there is probably no way to do this without copying buffers and iterating
     366           0 :   size_t buffLen = sizeof(uint32_t) + len*sizeof(uint32_t);
     367             :   #if RADIOLIB_STATIC_ONLY
     368             :     uint8_t dataBuff[sizeof(uint32_t) + RADIOLIB_LRXXXX_SPI_MAX_READ_WRITE_LEN];
     369             :   #else
     370           0 :     uint8_t* dataBuff = new uint8_t[buffLen];
     371             :   #endif
     372             : 
     373             :   // set the address or offset
     374           0 :   uint8_t* dataBuffPtr = reinterpret_cast<uint8_t*>(dataBuff);
     375           0 :   if(this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] >= Module::BITS_32) {
     376             :     // LR2021 has 24-bit address, whereas LR11x0 has 32-bit
     377           0 :     *(dataBuffPtr++) = (uint8_t)((addrOffset >> 24) & 0xFF);
     378             :   }
     379             :   
     380           0 :   *(dataBuffPtr++) = (uint8_t)((addrOffset >> 16) & 0xFF);
     381           0 :   *(dataBuffPtr++) = (uint8_t)((addrOffset >> 8) & 0xFF);
     382           0 :   *(dataBuffPtr++) = (uint8_t)(addrOffset & 0xFF);
     383             : 
     384             :   // convert endians
     385           0 :   for(size_t i = 0; i < len; i++) {
     386           0 :     uint32_t bin = 0;
     387           0 :     if(nonvolatile) {
     388           0 :       uint32_t* ptr = const_cast<uint32_t*>(data) + i;
     389           0 :       bin = RADIOLIB_NONVOLATILE_READ_DWORD(ptr);
     390             :     } else {
     391           0 :       bin = data[i];
     392             :     }
     393           0 :     *(dataBuffPtr++) = (uint8_t)((bin >> 24) & 0xFF);
     394           0 :     *(dataBuffPtr++) = (uint8_t)((bin >> 16) & 0xFF);
     395           0 :     *(dataBuffPtr++) = (uint8_t)((bin >> 8) & 0xFF);
     396           0 :     *(dataBuffPtr++) = (uint8_t)(bin & 0xFF);
     397             :   }
     398             : 
     399           0 :   int16_t state = this->mod->SPIwriteStream(cmd, dataBuff, buffLen, true, false);
     400             :   #if !RADIOLIB_STATIC_ONLY
     401           0 :     delete[] dataBuff;
     402             :   #endif
     403           0 :   return(state);
     404             : }
     405             : 
     406         149 : int16_t LRxxxx::SPIcommand(uint16_t cmd, bool write, uint8_t* data, size_t len, const uint8_t* out, size_t outLen) {
     407         149 :   int16_t state = RADIOLIB_ERR_UNKNOWN;
     408         149 :   if(!write) {
     409             :     // the SPI interface of LR11x0 requires two separate transactions for reading
     410             :     // send the 16-bit command
     411         101 :     state = this->mod->SPIwriteStream(cmd, out, outLen, true, false);
     412         101 :     RADIOLIB_ASSERT(state);
     413             : 
     414             :     // read the result without command
     415         101 :     this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_0;
     416         101 :     state = this->mod->SPIreadStream(RADIOLIB_LRXXXX_CMD_NOP, data, len, true, false);
     417         101 :     this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_16;
     418             : 
     419             :   } else {
     420             :     // write is just a single transaction
     421          48 :     state = this->mod->SPIwriteStream(cmd, data, len, true, true);
     422             :   
     423             :   }
     424             :   
     425         149 :   return(state);
     426             : }

Generated by: LCOV version 1.14