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

RFM95.cpp (2600B)

      1 #include "RFM95.h"
      2 #if !defined(RADIOLIB_EXCLUDE_RFM9X)
      3 
      4 RFM95::RFM95(Module* mod) : SX1278(mod) {
      5 
      6 }
      7 
      8 int16_t RFM95::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\tRFM95"));
     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 
     40   return(state);
     41 }
     42 
     43 int16_t RFM95::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
     44   // execute common part
     45   int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
     46   if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
     47     // SX127X_REG_VERSION might be set 0x12
     48     state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
     49     RADIOLIB_ASSERT(state);
     50   } else if(state != RADIOLIB_ERR_NONE) {
     51     // some other error
     52     return(state);
     53   }
     54   RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
     55   RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95"));
     56 
     57   // configure settings not accessible by API
     58   state = configFSK();
     59   RADIOLIB_ASSERT(state);
     60 
     61   // configure publicly accessible settings
     62   state = setFrequency(freq);
     63   RADIOLIB_ASSERT(state);
     64 
     65   state = setOutputPower(power);
     66   RADIOLIB_ASSERT(state);
     67 
     68   if(enableOOK) {
     69     state = setDataShapingOOK(RADIOLIB_SHAPING_NONE);
     70     RADIOLIB_ASSERT(state);
     71   } else {
     72     state = setDataShaping(RADIOLIB_SHAPING_NONE);
     73     RADIOLIB_ASSERT(state);
     74   }
     75 
     76   return(state);
     77 }
     78 
     79 int16_t RFM95::setFrequency(float freq) {
     80   RADIOLIB_CHECK_RANGE(freq, 862.0, 1020.0, RADIOLIB_ERR_INVALID_FREQUENCY);
     81 
     82   // set frequency and if successful, save the new setting
     83   int16_t state = SX127x::setFrequencyRaw(freq);
     84   if(state == RADIOLIB_ERR_NONE) {
     85     SX127x::_freq = freq;
     86   }
     87   return(state);
     88 }
     89 
     90 #endif