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

SX1272.h (14847B)

      1 #if !defined(_RADIOLIB_SX1272_H)
      2 #define _RADIOLIB_SX1272_H
      3 
      4 #include "../../TypeDef.h"
      5 
      6 #if !defined(RADIOLIB_EXCLUDE_SX127X)
      7 
      8 #include "../../Module.h"
      9 #include "SX127x.h"
     10 
     11 // SX1272 specific register map
     12 #define RADIOLIB_SX1272_REG_AGC_REF                            0x43
     13 #define RADIOLIB_SX1272_REG_AGC_THRESH_1                       0x44
     14 #define RADIOLIB_SX1272_REG_AGC_THRESH_2                       0x45
     15 #define RADIOLIB_SX1272_REG_AGC_THRESH_3                       0x46
     16 #define RADIOLIB_SX1272_REG_PLL_HOP                            0x4B
     17 #define RADIOLIB_SX1272_REG_TCXO                               0x58
     18 #define RADIOLIB_SX1272_REG_PA_DAC                             0x5A
     19 #define RADIOLIB_SX1272_REG_PLL                                0x5C
     20 #define RADIOLIB_SX1272_REG_PLL_LOW_PN                         0x5E
     21 #define RADIOLIB_SX1272_REG_FORMER_TEMP                        0x6C
     22 #define RADIOLIB_SX1272_REG_BIT_RATE_FRAC                      0x70
     23 
     24 // SX1272 LoRa modem settings
     25 // RADIOLIB_SX1272_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
     26 #define RADIOLIB_SX1272_FRF_MSB                                0xE4        //  7     0     carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
     27 #define RADIOLIB_SX1272_FRF_MID                                0xC0        //  7     0         where F(XOSC) = 32 MHz
     28 #define RADIOLIB_SX1272_FRF_LSB                                0x00        //  7     0               FRF = 3 byte value of FRF registers
     29 
     30 // RADIOLIB_SX127X_REG_MODEM_CONFIG_1
     31 #define RADIOLIB_SX1272_BW_125_00_KHZ                          0b00000000  //  7     6     bandwidth:  125 kHz
     32 #define RADIOLIB_SX1272_BW_250_00_KHZ                          0b01000000  //  7     6                 250 kHz
     33 #define RADIOLIB_SX1272_BW_500_00_KHZ                          0b10000000  //  7     6                 500 kHz
     34 #define RADIOLIB_SX1272_CR_4_5                                 0b00001000  //  5     3     error coding rate:  4/5
     35 #define RADIOLIB_SX1272_CR_4_6                                 0b00010000  //  5     3                         4/6
     36 #define RADIOLIB_SX1272_CR_4_7                                 0b00011000  //  5     3                         4/7
     37 #define RADIOLIB_SX1272_CR_4_8                                 0b00100000  //  5     3                         4/8
     38 #define RADIOLIB_SX1272_HEADER_EXPL_MODE                       0b00000000  //  2     2     explicit header mode
     39 #define RADIOLIB_SX1272_HEADER_IMPL_MODE                       0b00000100  //  2     2     implicit header mode
     40 #define RADIOLIB_SX1272_RX_CRC_MODE_OFF                        0b00000000  //  1     1     CRC disabled
     41 #define RADIOLIB_SX1272_RX_CRC_MODE_ON                         0b00000010  //  1     1     CRC enabled
     42 #define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF                  0b00000000  //  0     0     low data rate optimization disabled
     43 #define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON                   0b00000001  //  0     0     low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz
     44 
     45 // RADIOLIB_SX127X_REG_MODEM_CONFIG_2
     46 #define RADIOLIB_SX1272_AGC_AUTO_OFF                           0b00000000  //  2     2     LNA gain set by REG_LNA
     47 #define RADIOLIB_SX1272_AGC_AUTO_ON                            0b00000100  //  2     2     LNA gain set by internal AGC loop
     48 
     49 // RADIOLIB_SX127X_REG_VERSION
     50 #define RADIOLIB_SX1272_CHIP_VERSION                           0x22
     51 
     52 // SX1272 FSK modem settings
     53 // RADIOLIB_SX127X_REG_OP_MODE
     54 #define RADIOLIB_SX1272_NO_SHAPING                             0b00000000  //  4     3     data shaping: no shaping (default)
     55 #define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0                       0b00001000  //  4     3                   FSK modulation Gaussian filter, BT = 1.0
     56 #define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5                       0b00010000  //  4     3                   FSK modulation Gaussian filter, BT = 0.5
     57 #define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3                       0b00011000  //  4     3                   FSK modulation Gaussian filter, BT = 0.3
     58 #define RADIOLIB_SX1272_OOK_FILTER_BR                          0b00001000  //  4     3                   OOK modulation filter, f_cutoff = BR
     59 #define RADIOLIB_SX1272_OOK_FILTER_2BR                         0b00010000  //  4     3                   OOK modulation filter, f_cutoff = 2*BR
     60 
     61 // RADIOLIB_SX127X_REG_PA_RAMP
     62 #define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF                      0b00010000  //  4     4     use standard PLL in transmit mode (default)
     63 #define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON                       0b00000000  //  4     4     use lower phase noise PLL in transmit mode
     64 
     65 // RADIOLIB_SX127X_REG_SYNC_CONFIG
     66 #define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS       0b00000000  //  3     3     FIFO will be filled when sync address interrupt occurs (default)
     67 #define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS             0b00001000  //  3     3     FIFO will be filled as long as this bit is set
     68 
     69 // RADIOLIB_SX1272_REG_AGC_REF
     70 #define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL                    0x13        //  5     0     floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]
     71 
     72 // RADIOLIB_SX1272_REG_AGC_THRESH_1
     73 #define RADIOLIB_SX1272_AGC_STEP_1                             0x0E        //  4     0     1st AGC threshold
     74 
     75 // RADIOLIB_SX1272_REG_AGC_THRESH_2
     76 #define RADIOLIB_SX1272_AGC_STEP_2                             0x50        //  7     4     2nd AGC threshold
     77 #define RADIOLIB_SX1272_AGC_STEP_3                             0x0B        //  4     0     3rd AGC threshold
     78 
     79 // RADIOLIB_SX1272_REG_AGC_THRESH_3
     80 #define RADIOLIB_SX1272_AGC_STEP_4                             0xD0        //  7     4     4th AGC threshold
     81 #define RADIOLIB_SX1272_AGC_STEP_5                             0x0B        //  4     0     5th AGC threshold
     82 
     83 // RADIOLIB_SX1272_REG_PLL_LOW_PN
     84 #define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ            0b00000000  //  7     6     low phase noise PLL bandwidth: 75 kHz
     85 #define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ           0b01000000  //  7     6                                    150 kHz
     86 #define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ           0b10000000  //  7     6                                    225 kHz
     87 #define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ           0b11000000  //  7     6                                    300 kHz (default)
     88 
     89 /*!
     90   \class SX1272
     91 
     92   \brief Derived class for %SX1272 modules. Also used as base class for SX1273.
     93   Both modules use the same basic hardware and only differ in parameter ranges.
     94 */
     95 class SX1272: public SX127x {
     96   public:
     97 
     98     // constructor
     99 
    100     /*!
    101       \brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
    102 
    103       \param mod Instance of Module that will be used to communicate with the %LoRa chip.
    104     */
    105     SX1272(Module* mod);
    106 
    107     // basic methods
    108 
    109     /*!
    110       \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
    111 
    112       \param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
    113 
    114       \param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz.
    115 
    116       \param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
    117 
    118       \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
    119 
    120       \param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
    121 
    122       \param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
    123       Set to 0 to disable OCP (not recommended).
    124 
    125       \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
    126       Allowed values range from 6 to 65535.
    127 
    128       \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
    129       Set to 0 to enable automatic gain control (recommended).
    130 
    131       \returns \ref status_codes
    132     */
    133     int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
    134 
    135     /*!
    136       \brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
    137 
    138       \param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
    139 
    140       \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
    141 
    142       \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
    143       Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
    144 
    145       \param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
    146 
    147       \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
    148 
    149       \param preambleLength Length of FSK preamble in bits.
    150 
    151       \param enableOOK Use OOK modulation instead of FSK.
    152 
    153       \returns \ref status_codes
    154     */
    155     int16_t beginFSK(float freq = 915.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
    156 
    157     /*!
    158       \brief Reset method. Will reset the chip to the default state using RST pin.
    159     */
    160     void reset() override;
    161 
    162     // configuration methods
    163 
    164     /*!
    165       \brief Sets carrier frequency. Allowed values range from 860.0 MHz to 1020.0 MHz.
    166 
    167       \param freq Carrier frequency to be set in MHz.
    168 
    169       \returns \ref status_codes
    170     */
    171     int16_t setFrequency(float freq);
    172 
    173     /*!
    174       \brief Sets %LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in %LoRa mode.
    175 
    176       \param bw %LoRa link bandwidth to be set in kHz.
    177 
    178       \returns \ref status_codes
    179     */
    180     int16_t setBandwidth(float bw);
    181 
    182     /*!
    183       \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode.
    184 
    185       \param sf %LoRa link spreading factor to be set.
    186 
    187       \returns \ref status_codes
    188     */
    189     int16_t setSpreadingFactor(uint8_t sf);
    190 
    191     /*!
    192       \brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode.
    193 
    194       \param cr %LoRa link coding rate denominator to be set.
    195 
    196       \returns \ref status_codes
    197     */
    198     int16_t setCodingRate(uint8_t cr);
    199 
    200     /*!
    201       \brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
    202 
    203       \param power Transmission output power in dBm.
    204 
    205       \param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST.
    206 
    207       \returns \ref status_codes
    208     */
    209     int16_t setOutputPower(int8_t power, bool useRfo = false);
    210 
    211     /*!
    212       \brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
    213       Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode.
    214 
    215       \param gain Gain of receiver LNA (low-noise amplifier) to be set.
    216 
    217       \returns \ref status_codes
    218     */
    219     int16_t setGain(uint8_t gain);
    220 
    221     /*!
    222       \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation.
    223       Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
    224 
    225       \param sh Gaussian shaping bandwidth-time product that will be used for data shaping
    226 
    227       \returns \ref status_codes
    228     */
    229     int16_t setDataShaping(uint8_t sh) override;
    230 
    231     /*!
    232       \brief Sets filter cutoff frequency that will be used for data shaping.
    233       Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping.
    234       Only available in FSK mode with OOK modulation.
    235 
    236       \param sh Cutoff frequency that will be used for data shaping
    237 
    238       \returns \ref status_codes
    239     */
    240     int16_t setDataShapingOOK(uint8_t sh);
    241 
    242     /*!
    243       \brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
    244 
    245       \param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
    246 
    247       \returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
    248     */
    249     float getRSSI(bool skipReceive = false);
    250 
    251     /*!
    252       \brief Enables/disables CRC check of received packets.
    253 
    254       \param enable Enable (true) or disable (false) CRC.
    255 
    256       \param mode Set CRC mode to RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) or RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
    257 
    258       \returns \ref status_codes
    259     */
    260     int16_t setCRC(bool enable, bool mode = false);
    261 
    262     /*!
    263       \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to
    264       the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO()
    265 
    266       \param enable Force LDRO to be always enabled (true) or disabled (false).
    267 
    268       \returns \ref status_codes
    269     */
    270     int16_t forceLDRO(bool enable);
    271 
    272     /*!
    273       \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically
    274       when symbol length exceeds 16 ms.
    275 
    276       \returns \ref status_codes
    277     */
    278     int16_t autoLDRO();
    279 
    280     /*!
    281      \brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
    282 
    283       \param len Payload length in bytes.
    284 
    285       \returns \ref status_codes
    286     */
    287     int16_t implicitHeader(size_t len);
    288 
    289     /*!
    290       \brief Set explicit header mode for future reception/transmission.
    291 
    292       \returns \ref status_codes
    293     */
    294     int16_t explicitHeader();
    295 
    296 #if !defined(RADIOLIB_GODMODE)
    297   protected:
    298 #endif
    299     int16_t setBandwidthRaw(uint8_t newBandwidth);
    300     int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor);
    301     int16_t setCodingRateRaw(uint8_t newCodingRate);
    302     int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
    303 
    304     int16_t configFSK();
    305     void errataFix(bool rx);
    306 
    307 #if !defined(RADIOLIB_GODMODE)
    308   private:
    309 #endif
    310     bool _ldroAuto = true;
    311     bool _ldroEnabled = false;
    312 
    313 };
    314 
    315 #endif
    316 
    317 #endif