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

RFM96.cpp (2625B)

      1 #include "RFM96.h"
      2 #if !defined(RADIOLIB_EXCLUDE_RFM9X)
      3 
      4 RFM96::RFM96(Module* mod) : SX1278(mod) {
      5 
      6 }
      7 
      8 int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
      9   // execute common part
     10   int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength);
     11   if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
     12     // SX127X_REG_VERSION might be set 0x12
     13     state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength);
     14     RADIOLIB_ASSERT(state);
     15   } else if(state != RADIOLIB_ERR_NONE) {
     16     // some other error
     17     return(state);
     18   }
     19   RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
     20   RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96"));
     21 
     22   // configure publicly accessible settings
     23   state = setBandwidth(bw);
     24   RADIOLIB_ASSERT(state);
     25 
     26   state = setFrequency(freq);
     27   RADIOLIB_ASSERT(state);
     28 
     29   state = setSpreadingFactor(sf);
     30   RADIOLIB_ASSERT(state);
     31 
     32   state = setCodingRate(cr);
     33   RADIOLIB_ASSERT(state);
     34 
     35   state = setOutputPower(power);
     36   RADIOLIB_ASSERT(state);
     37 
     38   state = setGain(gain);
     39   RADIOLIB_ASSERT(state);
     40 
     41   return(state);
     42 }
     43 
     44 int16_t RFM96::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
     45   // execute common part
     46   int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
     47   if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
     48     // SX127X_REG_VERSION might be set 0x12
     49     state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
     50     RADIOLIB_ASSERT(state);
     51   } else if(state != RADIOLIB_ERR_NONE) {
     52     // some other error
     53     return(state);
     54   }
     55   RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
     56   RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96"));
     57 
     58   // configure settings not accessible by API
     59   state = configFSK();
     60   RADIOLIB_ASSERT(state);
     61 
     62   // configure publicly accessible settings
     63   state = setFrequency(freq);
     64   RADIOLIB_ASSERT(state);
     65 
     66   state = setOutputPower(power);
     67   RADIOLIB_ASSERT(state);
     68 
     69   if(enableOOK) {
     70     state = setDataShapingOOK(RADIOLIB_SHAPING_NONE);
     71     RADIOLIB_ASSERT(state);
     72   } else {
     73     state = setDataShaping(RADIOLIB_SHAPING_NONE);
     74     RADIOLIB_ASSERT(state);
     75   }
     76 
     77   return(state);
     78 }
     79 
     80 int16_t RFM96::setFrequency(float freq) {
     81   RADIOLIB_CHECK_RANGE(freq, 410.0, 525.0, RADIOLIB_ERR_INVALID_FREQUENCY);
     82 
     83   // set frequency and if successful, save the new setting
     84   int16_t state = SX127x::setFrequencyRaw(freq);
     85   if(state == RADIOLIB_ERR_NONE) {
     86     SX127x::_freq = freq;
     87   }
     88   return(state);
     89 }
     90 
     91 #endif