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 |
SX1231.cpp (2820B)
1 #include "SX1231.h" 2 #if !defined(RADIOLIB_EXCLUDE_SX1231) 3 4 SX1231::SX1231(Module* mod) : RF69(mod) { 5 6 } 7 8 int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { 9 // set module properties 10 _mod->init(); 11 _mod->pinMode(_mod->getIrq(), INPUT); 12 _mod->pinMode(_mod->getRst(), OUTPUT); 13 14 // try to find the SX1231 chip 15 uint8_t i = 0; 16 bool flagFound = false; 17 while((i < 10) && !flagFound) { 18 int16_t version = getChipVersion(); 19 if((version == 0x21) || (version == 0x22) || (version == 0x23)) { 20 flagFound = true; 21 _chipRevision = version; 22 } else { 23 #if defined(RADIOLIB_DEBUG) 24 RADIOLIB_DEBUG_PRINT(F("SX1231 not found! (")); 25 RADIOLIB_DEBUG_PRINT(i + 1); 26 RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RF69_REG_VERSION == ")); 27 28 char buffHex[12]; 29 sprintf(buffHex, "0x%04X", version); 30 RADIOLIB_DEBUG_PRINT(buffHex); 31 RADIOLIB_DEBUG_PRINT(F(", expected 0x0021 / 0x0022 / 0x0023")); 32 RADIOLIB_DEBUG_PRINTLN(); 33 #endif 34 _mod->delay(10); 35 i++; 36 } 37 } 38 39 if(!flagFound) { 40 RADIOLIB_DEBUG_PRINTLN(F("No SX1231 found!")); 41 _mod->term(); 42 return(RADIOLIB_ERR_CHIP_NOT_FOUND); 43 } 44 RADIOLIB_DEBUG_PRINTLN(F("M\tSX1231")); 45 46 // configure settings not accessible by API 47 int16_t state = config(); 48 RADIOLIB_ASSERT(state); 49 RADIOLIB_DEBUG_PRINTLN(F("M\tRF69")); 50 51 // configure publicly accessible settings 52 state = setFrequency(freq); 53 RADIOLIB_ASSERT(state); 54 55 // configure bitrate 56 _rxBw = 125.0; 57 state = setBitRate(br); 58 RADIOLIB_ASSERT(state); 59 60 // configure default RX bandwidth 61 state = setRxBandwidth(rxBw); 62 RADIOLIB_ASSERT(state); 63 64 // configure default frequency deviation 65 state = setFrequencyDeviation(freqDev); 66 RADIOLIB_ASSERT(state); 67 68 // configure default TX output power 69 state = setOutputPower(power); 70 RADIOLIB_ASSERT(state); 71 72 // configure default preamble length 73 state = setPreambleLength(preambleLen); 74 RADIOLIB_ASSERT(state); 75 76 // default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library 77 uint8_t syncWord[] = {0x2D, 0x01}; 78 state = setSyncWord(syncWord, 2); 79 RADIOLIB_ASSERT(state); 80 81 // set default packet length mode 82 state = variablePacketLengthMode(); 83 if (state != RADIOLIB_ERR_NONE) { 84 return(state); 85 } 86 87 // SX1231 V2a only 88 if(_chipRevision == RADIOLIB_SX1231_CHIP_REVISION_2_A) { 89 // modify default OOK threshold value 90 state = _mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD); 91 RADIOLIB_ASSERT(state); 92 93 // enable OCP with 95 mA limit 94 state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0); 95 RADIOLIB_ASSERT(state); 96 } 97 98 return(RADIOLIB_ERR_NONE); 99 } 100 101 #endif