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

SX127x.h (73238B)

      1 #if !defined(_RADIOLIB_SX127X_H)
      2 #define _RADIOLIB_SX127X_H
      3 
      4 #include "../../TypeDef.h"
      5 
      6 #if !defined(RADIOLIB_EXCLUDE_SX127X)
      7 
      8 #include "../../Module.h"
      9 
     10 #include "../../protocols/PhysicalLayer/PhysicalLayer.h"
     11 
     12 // SX127x physical layer properties
     13 #define RADIOLIB_SX127X_FREQUENCY_STEP_SIZE                    61.03515625
     14 #define RADIOLIB_SX127X_MAX_PACKET_LENGTH                      255
     15 #define RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK                  64
     16 #define RADIOLIB_SX127X_CRYSTAL_FREQ                           32.0
     17 #define RADIOLIB_SX127X_DIV_EXPONENT                           19
     18 
     19 // SX127x series common LoRa registers
     20 #define RADIOLIB_SX127X_REG_FIFO                               0x00
     21 #define RADIOLIB_SX127X_REG_OP_MODE                            0x01
     22 #define RADIOLIB_SX127X_REG_FRF_MSB                            0x06
     23 #define RADIOLIB_SX127X_REG_FRF_MID                            0x07
     24 #define RADIOLIB_SX127X_REG_FRF_LSB                            0x08
     25 #define RADIOLIB_SX127X_REG_PA_CONFIG                          0x09
     26 #define RADIOLIB_SX127X_REG_PA_RAMP                            0x0A
     27 #define RADIOLIB_SX127X_REG_OCP                                0x0B
     28 #define RADIOLIB_SX127X_REG_LNA                                0x0C
     29 #define RADIOLIB_SX127X_REG_FIFO_ADDR_PTR                      0x0D
     30 #define RADIOLIB_SX127X_REG_FIFO_TX_BASE_ADDR                  0x0E
     31 #define RADIOLIB_SX127X_REG_FIFO_RX_BASE_ADDR                  0x0F
     32 #define RADIOLIB_SX127X_REG_FIFO_RX_CURRENT_ADDR               0x10
     33 #define RADIOLIB_SX127X_REG_IRQ_FLAGS_MASK                     0x11
     34 #define RADIOLIB_SX127X_REG_IRQ_FLAGS                          0x12
     35 #define RADIOLIB_SX127X_REG_RX_NB_BYTES                        0x13
     36 #define RADIOLIB_SX127X_REG_RX_HEADER_CNT_VALUE_MSB            0x14
     37 #define RADIOLIB_SX127X_REG_RX_HEADER_CNT_VALUE_LSB            0x15
     38 #define RADIOLIB_SX127X_REG_RX_PACKET_CNT_VALUE_MSB            0x16
     39 #define RADIOLIB_SX127X_REG_RX_PACKET_CNT_VALUE_LSB            0x17
     40 #define RADIOLIB_SX127X_REG_MODEM_STAT                         0x18
     41 #define RADIOLIB_SX127X_REG_PKT_SNR_VALUE                      0x19
     42 #define RADIOLIB_SX127X_REG_PKT_RSSI_VALUE                     0x1A
     43 #define RADIOLIB_SX127X_REG_RSSI_VALUE                         0x1B
     44 #define RADIOLIB_SX127X_REG_HOP_CHANNEL                        0x1C
     45 #define RADIOLIB_SX127X_REG_MODEM_CONFIG_1                     0x1D
     46 #define RADIOLIB_SX127X_REG_MODEM_CONFIG_2                     0x1E
     47 #define RADIOLIB_SX127X_REG_SYMB_TIMEOUT_LSB                   0x1F
     48 #define RADIOLIB_SX127X_REG_PREAMBLE_MSB                       0x20
     49 #define RADIOLIB_SX127X_REG_PREAMBLE_LSB                       0x21
     50 #define RADIOLIB_SX127X_REG_PAYLOAD_LENGTH                     0x22
     51 #define RADIOLIB_SX127X_REG_MAX_PAYLOAD_LENGTH                 0x23
     52 #define RADIOLIB_SX127X_REG_HOP_PERIOD                         0x24
     53 #define RADIOLIB_SX127X_REG_FIFO_RX_BYTE_ADDR                  0x25
     54 #define RADIOLIB_SX127X_REG_FEI_MSB                            0x28
     55 #define RADIOLIB_SX127X_REG_FEI_MID                            0x29
     56 #define RADIOLIB_SX127X_REG_FEI_LSB                            0x2A
     57 #define RADIOLIB_SX127X_REG_RSSI_WIDEBAND                      0x2C
     58 #define RADIOLIB_SX127X_REG_DETECT_OPTIMIZE                    0x31
     59 #define RADIOLIB_SX127X_REG_INVERT_IQ                          0x33
     60 #define RADIOLIB_SX127X_REG_DETECTION_THRESHOLD                0x37
     61 #define RADIOLIB_SX127X_REG_SYNC_WORD                          0x39
     62 #define RADIOLIB_SX127X_REG_INVERT_IQ2                         0x3B
     63 #define RADIOLIB_SX127X_REG_DIO_MAPPING_1                      0x40
     64 #define RADIOLIB_SX127X_REG_DIO_MAPPING_2                      0x41
     65 #define RADIOLIB_SX127X_REG_VERSION                            0x42
     66 
     67 // SX127x common LoRa modem settings
     68 // SX127X_REG_OP_MODE                                                 MSB   LSB   DESCRIPTION
     69 #define RADIOLIB_SX127X_FSK_OOK                                0b00000000  //  7     7     FSK/OOK mode
     70 #define RADIOLIB_SX127X_LORA                                   0b10000000  //  7     7     LoRa mode
     71 #define RADIOLIB_SX127X_ACCESS_SHARED_REG_OFF                  0b00000000  //  6     6     access LoRa registers (0x0D:0x3F) in LoRa mode
     72 #define RADIOLIB_SX127X_ACCESS_SHARED_REG_ON                   0b01000000  //  6     6     access FSK registers (0x0D:0x3F) in LoRa mode
     73 #define RADIOLIB_SX127X_SLEEP                                  0b00000000  //  2     0     sleep
     74 #define RADIOLIB_SX127X_STANDBY                                0b00000001  //  2     0     standby
     75 #define RADIOLIB_SX127X_FSTX                                   0b00000010  //  2     0     frequency synthesis TX
     76 #define RADIOLIB_SX127X_TX                                     0b00000011  //  2     0     transmit
     77 #define RADIOLIB_SX127X_FSRX                                   0b00000100  //  2     0     frequency synthesis RX
     78 #define RADIOLIB_SX127X_RXCONTINUOUS                           0b00000101  //  2     0     receive continuous
     79 #define RADIOLIB_SX127X_RXSINGLE                               0b00000110  //  2     0     receive single
     80 #define RADIOLIB_SX127X_CAD                                    0b00000111  //  2     0     channel activity detection
     81 
     82 // SX127X_REG_PA_CONFIG
     83 #define RADIOLIB_SX127X_PA_SELECT_RFO                          0b00000000  //  7     7     RFO pin output, power limited to +14 dBm
     84 #define RADIOLIB_SX127X_PA_SELECT_BOOST                        0b10000000  //  7     7     PA_BOOST pin output, power limited to +20 dBm
     85 #define RADIOLIB_SX127X_OUTPUT_POWER                           0b00001111  //  3     0     output power: P_out = 2 + OUTPUT_POWER [dBm] for PA_SELECT_BOOST
     86                                                                   //                            P_out = -1 + OUTPUT_POWER [dBm] for PA_SELECT_RFO
     87 
     88 // SX127X_REG_OCP
     89 #define RADIOLIB_SX127X_OCP_OFF                                0b00000000  //  5     5     PA overload current protection disabled
     90 #define RADIOLIB_SX127X_OCP_ON                                 0b00100000  //  5     5     PA overload current protection enabled
     91 #define RADIOLIB_SX127X_OCP_TRIM                               0b00001011  //  4     0     OCP current: I_max(OCP_TRIM = 0b1011) = 100 mA
     92 
     93 // SX127X_REG_LNA
     94 #define RADIOLIB_SX127X_LNA_GAIN_1                             0b00100000  //  7     5     LNA gain setting:   max gain
     95 #define RADIOLIB_SX127X_LNA_GAIN_2                             0b01000000  //  7     5                         .
     96 #define RADIOLIB_SX127X_LNA_GAIN_3                             0b01100000  //  7     5                         .
     97 #define RADIOLIB_SX127X_LNA_GAIN_4                             0b10000000  //  7     5                         .
     98 #define RADIOLIB_SX127X_LNA_GAIN_5                             0b10100000  //  7     5                         .
     99 #define RADIOLIB_SX127X_LNA_GAIN_6                             0b11000000  //  7     5                         min gain
    100 #define RADIOLIB_SX127X_LNA_BOOST_OFF                          0b00000000  //  1     0     default LNA current
    101 #define RADIOLIB_SX127X_LNA_BOOST_ON                           0b00000011  //  1     0     150% LNA current
    102 
    103 // SX127X_REG_MODEM_CONFIG_2
    104 #define RADIOLIB_SX127X_SF_6                                   0b01100000  //  7     4     spreading factor:   64 chips/bit
    105 #define RADIOLIB_SX127X_SF_7                                   0b01110000  //  7     4                         128 chips/bit
    106 #define RADIOLIB_SX127X_SF_8                                   0b10000000  //  7     4                         256 chips/bit
    107 #define RADIOLIB_SX127X_SF_9                                   0b10010000  //  7     4                         512 chips/bit
    108 #define RADIOLIB_SX127X_SF_10                                  0b10100000  //  7     4                         1024 chips/bit
    109 #define RADIOLIB_SX127X_SF_11                                  0b10110000  //  7     4                         2048 chips/bit
    110 #define RADIOLIB_SX127X_SF_12                                  0b11000000  //  7     4                         4096 chips/bit
    111 #define RADIOLIB_SX127X_TX_MODE_SINGLE                         0b00000000  //  3     3     single TX
    112 #define RADIOLIB_SX127X_TX_MODE_CONT                           0b00001000  //  3     3     continuous TX
    113 #define RADIOLIB_SX127X_RX_TIMEOUT_MSB                         0b00000000  //  1     0
    114 
    115 // SX127X_REG_SYMB_TIMEOUT_LSB
    116 #define RADIOLIB_SX127X_RX_TIMEOUT_LSB                         0b01100100  //  7     0     10 bit RX operation timeout
    117 
    118 // SX127X_REG_PREAMBLE_MSB + REG_PREAMBLE_LSB
    119 #define RADIOLIB_SX127X_PREAMBLE_LENGTH_MSB                    0b00000000  //  7     0     2 byte preamble length setting: l_P = PREAMBLE_LENGTH + 4.25
    120 #define RADIOLIB_SX127X_PREAMBLE_LENGTH_LSB                    0b00001000  //  7     0         where l_p = preamble length
    121 
    122 // SX127X_REG_DETECT_OPTIMIZE
    123 #define RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6                   0b00000101  //  2     0     SF6 detection optimization
    124 #define RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12                0b00000011  //  2     0     SF7 to SF12 detection optimization
    125 
    126 // SX127X_REG_INVERT_IQ
    127 #define RADIOLIB_SX127X_INVERT_IQ_RXPATH_ON                    0b01000000  //  6     6     I and Q signals are inverted
    128 #define RADIOLIB_SX127X_INVERT_IQ_RXPATH_OFF                   0b00000000  //  6     6     normal mode
    129 #define RADIOLIB_SX127X_INVERT_IQ_TXPATH_ON                    0b00000001  //  0     0     I and Q signals are inverted
    130 #define RADIOLIB_SX127X_INVERT_IQ_TXPATH_OFF                   0b00000000  //  0     0     normal mode
    131 
    132 // SX127X_REG_DETECTION_THRESHOLD
    133 #define RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6               0b00001100  //  7     0     SF6 detection threshold
    134 #define RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12            0b00001010  //  7     0     SF7 to SF12 detection threshold
    135 
    136 // SX127X_REG_PA_DAC
    137 #define RADIOLIB_SX127X_PA_BOOST_OFF                           0b00000100  //  2     0     PA_BOOST disabled
    138 #define RADIOLIB_SX127X_PA_BOOST_ON                            0b00000111  //  2     0     +20 dBm on PA_BOOST when OUTPUT_POWER = 0b1111
    139 
    140 // SX127X_REG_HOP_PERIOD
    141 #define RADIOLIB_SX127X_HOP_PERIOD_OFF                         0b00000000  //  7     0     number of periods between frequency hops; 0 = disabled
    142 #define RADIOLIB_SX127X_HOP_PERIOD_MAX                         0b11111111  //  7     0
    143 
    144 // SX127X_REG_IRQ_FLAGS
    145 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_RX_TIMEOUT              0b10000000  //  7     7     timeout
    146 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_RX_DONE                 0b01000000  //  6     6     packet reception complete
    147 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_PAYLOAD_CRC_ERROR       0b00100000  //  5     5     payload CRC error
    148 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_VALID_HEADER            0b00010000  //  4     4     valid header received
    149 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_TX_DONE                 0b00001000  //  3     3     payload transmission complete
    150 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_CAD_DONE                0b00000100  //  2     2     CAD complete
    151 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL     0b00000010  //  1     1     FHSS change channel
    152 #define RADIOLIB_SX127X_CLEAR_IRQ_FLAG_CAD_DETECTED            0b00000001  //  0     0     valid LoRa signal detected during CAD operation
    153 
    154 // SX127X_REG_IRQ_FLAGS_MASK
    155 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_TIMEOUT               0b01111111  //  7     7     timeout
    156 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_RX_DONE                  0b10111111  //  6     6     packet reception complete
    157 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_PAYLOAD_CRC_ERROR        0b11011111  //  5     5     payload CRC error
    158 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_VALID_HEADER             0b11101111  //  4     4     valid header received
    159 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_TX_DONE                  0b11110111  //  3     3     payload transmission complete
    160 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DONE                 0b11111011  //  2     2     CAD complete
    161 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_FHSS_CHANGE_CHANNEL      0b11111101  //  1     1     FHSS change channel
    162 #define RADIOLIB_SX127X_MASK_IRQ_FLAG_CAD_DETECTED             0b11111110  //  0     0     valid LoRa signal detected during CAD operation
    163 
    164 // SX127X_REG_FIFO_TX_BASE_ADDR
    165 #define RADIOLIB_SX127X_FIFO_TX_BASE_ADDR_MAX                  0b00000000  //  7     0     allocate the entire FIFO buffer for TX only
    166 
    167 // SX127X_REG_FIFO_RX_BASE_ADDR
    168 #define RADIOLIB_SX127X_FIFO_RX_BASE_ADDR_MAX                  0b00000000  //  7     0     allocate the entire FIFO buffer for RX only
    169 
    170 // SX127X_REG_SYNC_WORD
    171 #define RADIOLIB_SX127X_SYNC_WORD                              0x12        //  7     0     default LoRa sync word
    172 #define RADIOLIB_SX127X_SYNC_WORD_LORAWAN                      0x34        //  7     0     sync word reserved for LoRaWAN networks
    173 
    174 // SX127X_REG_INVERT_IQ2
    175 #define RADIOLIB_SX127X_IQ2_ENABLE                             0x19        //  7     0     enable optimize for inverted IQ
    176 #define RADIOLIB_SX127X_IQ2_DISABLE                            0x1D        //  7     0     reset optimize for inverted IQ
    177 
    178 // SX127x series common FSK registers
    179 // NOTE: FSK register names that are conflicting with LoRa registers are marked with "_FSK" suffix
    180 #define RADIOLIB_SX127X_REG_BITRATE_MSB                        0x02
    181 #define RADIOLIB_SX127X_REG_BITRATE_LSB                        0x03
    182 #define RADIOLIB_SX127X_REG_FDEV_MSB                           0x04
    183 #define RADIOLIB_SX127X_REG_FDEV_LSB                           0x05
    184 #define RADIOLIB_SX127X_REG_RX_CONFIG                          0x0D
    185 #define RADIOLIB_SX127X_REG_RSSI_CONFIG                        0x0E
    186 #define RADIOLIB_SX127X_REG_RSSI_COLLISION                     0x0F
    187 #define RADIOLIB_SX127X_REG_RSSI_THRESH                        0x10
    188 #define RADIOLIB_SX127X_REG_RSSI_VALUE_FSK                     0x11
    189 #define RADIOLIB_SX127X_REG_RX_BW                              0x12
    190 #define RADIOLIB_SX127X_REG_AFC_BW                             0x13
    191 #define RADIOLIB_SX127X_REG_OOK_PEAK                           0x14
    192 #define RADIOLIB_SX127X_REG_OOK_FIX                            0x15
    193 #define RADIOLIB_SX127X_REG_OOK_AVG                            0x16
    194 #define RADIOLIB_SX127X_REG_AFC_FEI                            0x1A
    195 #define RADIOLIB_SX127X_REG_AFC_MSB                            0x1B
    196 #define RADIOLIB_SX127X_REG_AFC_LSB                            0x1C
    197 #define RADIOLIB_SX127X_REG_FEI_MSB_FSK                        0x1D
    198 #define RADIOLIB_SX127X_REG_FEI_LSB_FSK                        0x1E
    199 #define RADIOLIB_SX127X_REG_PREAMBLE_DETECT                    0x1F
    200 #define RADIOLIB_SX127X_REG_RX_TIMEOUT_1                       0x20
    201 #define RADIOLIB_SX127X_REG_RX_TIMEOUT_2                       0x21
    202 #define RADIOLIB_SX127X_REG_RX_TIMEOUT_3                       0x22
    203 #define RADIOLIB_SX127X_REG_RX_DELAY                           0x23
    204 #define RADIOLIB_SX127X_REG_OSC                                0x24
    205 #define RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK                   0x25
    206 #define RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK                   0x26
    207 #define RADIOLIB_SX127X_REG_SYNC_CONFIG                        0x27
    208 #define RADIOLIB_SX127X_REG_SYNC_VALUE_1                       0x28
    209 #define RADIOLIB_SX127X_REG_SYNC_VALUE_2                       0x29
    210 #define RADIOLIB_SX127X_REG_SYNC_VALUE_3                       0x2A
    211 #define RADIOLIB_SX127X_REG_SYNC_VALUE_4                       0x2B
    212 #define RADIOLIB_SX127X_REG_SYNC_VALUE_5                       0x2C
    213 #define RADIOLIB_SX127X_REG_SYNC_VALUE_6                       0x2D
    214 #define RADIOLIB_SX127X_REG_SYNC_VALUE_7                       0x2E
    215 #define RADIOLIB_SX127X_REG_SYNC_VALUE_8                       0x2F
    216 #define RADIOLIB_SX127X_REG_PACKET_CONFIG_1                    0x30
    217 #define RADIOLIB_SX127X_REG_PACKET_CONFIG_2                    0x31
    218 #define RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK                 0x32
    219 #define RADIOLIB_SX127X_REG_NODE_ADRS                          0x33
    220 #define RADIOLIB_SX127X_REG_BROADCAST_ADRS                     0x34
    221 #define RADIOLIB_SX127X_REG_FIFO_THRESH                        0x35
    222 #define RADIOLIB_SX127X_REG_SEQ_CONFIG_1                       0x36
    223 #define RADIOLIB_SX127X_REG_SEQ_CONFIG_2                       0x37
    224 #define RADIOLIB_SX127X_REG_TIMER_RESOL                        0x38
    225 #define RADIOLIB_SX127X_REG_TIMER1_COEF                        0x39
    226 #define RADIOLIB_SX127X_REG_TIMER2_COEF                        0x3A
    227 #define RADIOLIB_SX127X_REG_IMAGE_CAL                          0x3B
    228 #define RADIOLIB_SX127X_REG_TEMP                               0x3C
    229 #define RADIOLIB_SX127X_REG_LOW_BAT                            0x3D
    230 #define RADIOLIB_SX127X_REG_IRQ_FLAGS_1                        0x3E
    231 #define RADIOLIB_SX127X_REG_IRQ_FLAGS_2                        0x3F
    232 
    233 // SX127x common FSK modem settings
    234 // SX127X_REG_OP_MODE
    235 #define RADIOLIB_SX127X_MODULATION_FSK                         0b00000000  //  6     5     FSK modulation scheme
    236 #define RADIOLIB_SX127X_MODULATION_OOK                         0b00100000  //  6     5     OOK modulation scheme
    237 #define RADIOLIB_SX127X_RX                                     0b00000101  //  2     0     receiver mode
    238 
    239 // SX127X_REG_BITRATE_MSB + SX127X_REG_BITRATE_LSB
    240 #define RADIOLIB_SX127X_BITRATE_MSB                            0x1A        //  7     0     bit rate setting: BitRate = F(XOSC)/(BITRATE + BITRATE_FRAC/16)
    241 #define RADIOLIB_SX127X_BITRATE_LSB                            0x0B        //  7     0                       default value: 4.8 kbps
    242 
    243 // SX127X_REG_FDEV_MSB + SX127X_REG_FDEV_LSB
    244 #define RADIOLIB_SX127X_FDEV_MSB                               0x00        //  5     0     frequency deviation: Fdev = Fstep * FDEV
    245 #define RADIOLIB_SX127X_FDEV_LSB                               0x52        //  7     0                          default value: 5 kHz
    246 
    247 // SX127X_REG_RX_CONFIG
    248 #define RADIOLIB_SX127X_RESTART_RX_ON_COLLISION_OFF            0b00000000  //  7     7     automatic receiver restart disabled (default)
    249 #define RADIOLIB_SX127X_RESTART_RX_ON_COLLISION_ON             0b10000000  //  7     7     automatically restart receiver if it gets saturated or on packet collision
    250 #define RADIOLIB_SX127X_RESTART_RX_WITHOUT_PLL_LOCK            0b01000000  //  6     6     manually restart receiver without frequency change
    251 #define RADIOLIB_SX127X_RESTART_RX_WITH_PLL_LOCK               0b00100000  //  5     5     manually restart receiver with frequency change
    252 #define RADIOLIB_SX127X_AFC_AUTO_OFF                           0b00000000  //  4     4     no AFC performed (default)
    253 #define RADIOLIB_SX127X_AFC_AUTO_ON                            0b00010000  //  4     4     AFC performed at each receiver startup
    254 #define RADIOLIB_SX127X_AGC_AUTO_OFF                           0b00000000  //  3     3     LNA gain set manually by register
    255 #define RADIOLIB_SX127X_AGC_AUTO_ON                            0b00001000  //  3     3     LNA gain controlled by AGC
    256 #define RADIOLIB_SX127X_RX_TRIGGER_NONE                        0b00000000  //  2     0     receiver startup at: none
    257 #define RADIOLIB_SX127X_RX_TRIGGER_RSSI_INTERRUPT              0b00000001  //  2     0                          RSSI interrupt
    258 #define RADIOLIB_SX127X_RX_TRIGGER_PREAMBLE_DETECT             0b00000110  //  2     0                          preamble detected
    259 #define RADIOLIB_SX127X_RX_TRIGGER_BOTH                        0b00000111  //  2     0                          RSSI interrupt and preamble detected
    260 
    261 // SX127X_REG_RSSI_CONFIG
    262 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_2               0b00000000  //  2     0     number of samples for RSSI average: 2
    263 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_4               0b00000001  //  2     0                                         4
    264 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_8               0b00000010  //  2     0                                         8 (default)
    265 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_16              0b00000011  //  2     0                                         16
    266 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_32              0b00000100  //  2     0                                         32
    267 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_64              0b00000101  //  2     0                                         64
    268 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_128             0b00000110  //  2     0                                         128
    269 #define RADIOLIB_SX127X_RSSI_SMOOTHING_SAMPLES_256             0b00000111  //  2     0                                         256
    270 
    271 // SX127X_REG_RSSI_COLLISION
    272 #define RADIOLIB_SX127X_RSSI_COLLISION_THRESHOLD               0x0A        //  7     0     RSSI threshold in dB that will be considered a collision, default value: 10 dB
    273 
    274 // SX127X_REG_RSSI_THRESH
    275 #define RADIOLIB_SX127X_RSSI_THRESHOLD                         0xFF        //  7     0     RSSI threshold that will trigger RSSI interrupt, RssiThreshold = RSSI_THRESHOLD / 2 [dBm]
    276 
    277 // SX127X_REG_RX_BW
    278 #define RADIOLIB_SX127X_RX_BW_MANT_16                          0b00000000  //  4     3     channel filter bandwidth: RxBw = F(XOSC) / (RxBwMant * 2^(RxBwExp + 2)) [kHz]
    279 #define RADIOLIB_SX127X_RX_BW_MANT_20                          0b00001000  //  4     3
    280 #define RADIOLIB_SX127X_RX_BW_MANT_24                          0b00010000  //  4     3     default RxBwMant parameter
    281 #define RADIOLIB_SX127X_RX_BW_EXP                              0b00000101  //  2     0     default RxBwExp parameter
    282 
    283 // SX127X_REG_AFC_BW
    284 #define RADIOLIB_SX127X_RX_BW_MANT_AFC                         0b00001000  //  4     3     default RxBwMant parameter used during AFC
    285 #define RADIOLIB_SX127X_RX_BW_EXP_AFC                          0b00000011  //  2     0     default RxBwExp parameter used during AFC
    286 
    287 // SX127X_REG_OOK_PEAK
    288 #define RADIOLIB_SX127X_BIT_SYNC_OFF                           0b00000000  //  5     5     bit synchronizer disabled (not allowed in packet mode)
    289 #define RADIOLIB_SX127X_BIT_SYNC_ON                            0b00100000  //  5     5     bit synchronizer enabled (default)
    290 #define RADIOLIB_SX127X_OOK_THRESH_FIXED                       0b00000000  //  4     3     OOK threshold type: fixed value
    291 #define RADIOLIB_SX127X_OOK_THRESH_PEAK                        0b00001000  //  4     3                         peak mode (default)
    292 #define RADIOLIB_SX127X_OOK_THRESH_AVERAGE                     0b00010000  //  4     3                         average mode
    293 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_0_5_DB            0b00000000  //  2     0     OOK demodulator step size: 0.5 dB (default)
    294 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_0_DB            0b00000001  //  2     0                                1.0 dB
    295 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_5_DB            0b00000010  //  2     0                                1.5 dB
    296 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_2_0_DB            0b00000011  //  2     0                                2.0 dB
    297 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_3_0_DB            0b00000100  //  2     0                                3.0 dB
    298 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_4_0_DB            0b00000101  //  2     0                                4.0 dB
    299 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_5_0_DB            0b00000110  //  2     0                                5.0 dB
    300 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_6_0_DB            0b00000111  //  2     0                                6.0 dB
    301 
    302 // SX127X_REG_OOK_FIX
    303 #define RADIOLIB_SX127X_OOK_FIXED_THRESHOLD                    0x0C        //  7     0     default fixed threshold for OOK data slicer
    304 
    305 // SX127X_REG_OOK_AVG
    306 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_1_CHIP           0b00000000  //  7     5     OOK demodulator step period: once per chip (default)
    307 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_2_CHIP           0b00100000  //  7     5                                  once every 2 chips
    308 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_4_CHIP           0b01000000  //  7     5                                  once every 4 chips
    309 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_1_8_CHIP           0b01100000  //  7     5                                  once every 8 chips
    310 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_2_1_CHIP           0b10000000  //  7     5                                  2 times per chip
    311 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_4_1_CHIP           0b10100000  //  7     5                                  4 times per chip
    312 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_8_1_CHIP           0b11000000  //  7     5                                  8 times per chip
    313 #define RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_16_1_CHIP          0b11100000  //  7     5                                  16 times per chip
    314 #define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_0_DB                0b00000000  //  3     2     OOK average threshold offset: 0.0 dB (default)
    315 #define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_2_DB                0b00000100  //  3     2                                   2.0 dB
    316 #define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_4_DB                0b00001000  //  3     2                                   4.0 dB
    317 #define RADIOLIB_SX127X_OOK_AVERAGE_OFFSET_6_DB                0b00001100  //  3     2                                   6.0 dB
    318 #define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_32_PI              0b00000000  //  1     0     OOK average filter coefficient: chip rate / 32*pi
    319 #define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_8_PI               0b00000001  //  1     0                                     chip rate / 8*pi
    320 #define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_4_PI               0b00000010  //  1     0                                     chip rate / 4*pi (default)
    321 #define RADIOLIB_SX127X_OOK_AVG_THRESH_FILT_2_PI               0b00000011  //  1     0                                     chip rate / 2*pi
    322 
    323 // SX127X_REG_AFC_FEI
    324 #define RADIOLIB_SX127X_AGC_START                              0b00010000  //  4     4     manually start AGC sequence
    325 #define RADIOLIB_SX127X_AFC_CLEAR                              0b00000010  //  1     1     manually clear AFC register
    326 #define RADIOLIB_SX127X_AFC_AUTO_CLEAR_OFF                     0b00000000  //  0     0     AFC register will not be cleared at the start of AFC (default)
    327 #define RADIOLIB_SX127X_AFC_AUTO_CLEAR_ON                      0b00000001  //  0     0     AFC register will be cleared at the start of AFC
    328 
    329 // SX127X_REG_PREAMBLE_DETECT
    330 #define RADIOLIB_SX127X_PREAMBLE_DETECTOR_OFF                  0b00000000  //  7     7     preamble detection disabled
    331 #define RADIOLIB_SX127X_PREAMBLE_DETECTOR_ON                   0b10000000  //  7     7     preamble detection enabled (default)
    332 #define RADIOLIB_SX127X_PREAMBLE_DETECTOR_1_BYTE               0b00000000  //  6     5     preamble detection size: 1 byte (default)
    333 #define RADIOLIB_SX127X_PREAMBLE_DETECTOR_2_BYTE               0b00100000  //  6     5                              2 bytes
    334 #define RADIOLIB_SX127X_PREAMBLE_DETECTOR_3_BYTE               0b01000000  //  6     5                              3 bytes
    335 #define RADIOLIB_SX127X_PREAMBLE_DETECTOR_TOL                  0x0A        //  4     0     default number of tolerated errors per chip (4 chips per bit)
    336 
    337 // SX127X_REG_RX_TIMEOUT_1
    338 #define RADIOLIB_SX127X_TIMEOUT_RX_RSSI_OFF                    0x00        //  7     0     disable receiver timeout when RSSI interrupt doesn't occur (default)
    339 
    340 // SX127X_REG_RX_TIMEOUT_2
    341 #define RADIOLIB_SX127X_TIMEOUT_RX_PREAMBLE_OFF                0x00        //  7     0     disable receiver timeout when preamble interrupt doesn't occur (default)
    342 
    343 // SX127X_REG_RX_TIMEOUT_3
    344 #define RADIOLIB_SX127X_TIMEOUT_SIGNAL_SYNC_OFF                0x00        //  7     0     disable receiver timeout when sync address interrupt doesn't occur (default)
    345 
    346 // SX127X_REG_OSC
    347 #define RADIOLIB_SX127X_RC_CAL_START                           0b00000000  //  3     3     manually start RC oscillator calibration
    348 #define RADIOLIB_SX127X_CLK_OUT_FXOSC                          0b00000000  //  2     0     ClkOut frequency: F(XOSC)
    349 #define RADIOLIB_SX127X_CLK_OUT_FXOSC_2                        0b00000001  //  2     0                       F(XOSC) / 2
    350 #define RADIOLIB_SX127X_CLK_OUT_FXOSC_4                        0b00000010  //  2     0                       F(XOSC) / 4
    351 #define RADIOLIB_SX127X_CLK_OUT_FXOSC_8                        0b00000011  //  2     0                       F(XOSC) / 8
    352 #define RADIOLIB_SX127X_CLK_OUT_FXOSC_16                       0b00000100  //  2     0                       F(XOSC) / 16
    353 #define RADIOLIB_SX127X_CLK_OUT_FXOSC_32                       0b00000101  //  2     0                       F(XOSC) / 32
    354 #define RADIOLIB_SX127X_CLK_OUT_RC                             0b00000110  //  2     0                       RC
    355 #define RADIOLIB_SX127X_CLK_OUT_OFF                            0b00000111  //  2     0                       disabled (default)
    356 
    357 // SX127X_REG_PREAMBLE_MSB_FSK + SX127X_REG_PREAMBLE_LSB_FSK
    358 #define RADIOLIB_SX127X_PREAMBLE_SIZE_MSB                      0x00        //  7     0     preamble size in bytes
    359 #define RADIOLIB_SX127X_PREAMBLE_SIZE_LSB                      0x03        //  7     0       default value: 3 bytes
    360 
    361 // SX127X_REG_SYNC_CONFIG
    362 #define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_OFF               0b00000000  //  7     6     Rx mode restart after packet reception: disabled
    363 #define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_NO_PLL            0b01000000  //  7     6                                             enabled, don't wait for PLL lock
    364 #define RADIOLIB_SX127X_AUTO_RESTART_RX_MODE_PLL               0b10000000  //  7     6                                             enabled, wait for PLL lock (default)
    365 #define RADIOLIB_SX127X_PREAMBLE_POLARITY_AA                   0b00000000  //  5     5     preamble polarity: 0xAA = 0b10101010 (default)
    366 #define RADIOLIB_SX127X_PREAMBLE_POLARITY_55                   0b00100000  //  5     5                        0x55 = 0b01010101
    367 #define RADIOLIB_SX127X_SYNC_OFF                               0b00000000  //  4     4     sync word disabled
    368 #define RADIOLIB_SX127X_SYNC_ON                                0b00010000  //  4     4     sync word enabled (default)
    369 #define RADIOLIB_SX127X_SYNC_SIZE                              0x03        //  2     0     sync word size in bytes, SyncSize = SYNC_SIZE + 1 bytes
    370 
    371 // SX127X_REG_SYNC_VALUE_1 - SX127X_REG_SYNC_VALUE_8
    372 #define RADIOLIB_SX127X_SYNC_VALUE_1                           0x01        //  7     0     sync word: 1st byte (MSB)
    373 #define RADIOLIB_SX127X_SYNC_VALUE_2                           0x01        //  7     0                2nd byte
    374 #define RADIOLIB_SX127X_SYNC_VALUE_3                           0x01        //  7     0                3rd byte
    375 #define RADIOLIB_SX127X_SYNC_VALUE_4                           0x01        //  7     0                4th byte
    376 #define RADIOLIB_SX127X_SYNC_VALUE_5                           0x01        //  7     0                5th byte
    377 #define RADIOLIB_SX127X_SYNC_VALUE_6                           0x01        //  7     0                6th byte
    378 #define RADIOLIB_SX127X_SYNC_VALUE_7                           0x01        //  7     0                7th byte
    379 #define RADIOLIB_SX127X_SYNC_VALUE_8                           0x01        //  7     0                8th byte (LSB)
    380 
    381 // SX127X_REG_PACKET_CONFIG_1
    382 #define RADIOLIB_SX127X_PACKET_FIXED                           0b00000000  //  7     7     packet format: fixed length
    383 #define RADIOLIB_SX127X_PACKET_VARIABLE                        0b10000000  //  7     7                    variable length (default)
    384 #define RADIOLIB_SX127X_DC_FREE_NONE                           0b00000000  //  6     5     DC-free encoding: disabled (default)
    385 #define RADIOLIB_SX127X_DC_FREE_MANCHESTER                     0b00100000  //  6     5                       Manchester
    386 #define RADIOLIB_SX127X_DC_FREE_WHITENING                      0b01000000  //  6     5                       Whitening
    387 #define RADIOLIB_SX127X_CRC_OFF                                0b00000000  //  4     4     CRC disabled
    388 #define RADIOLIB_SX127X_CRC_ON                                 0b00010000  //  4     4     CRC enabled (default)
    389 #define RADIOLIB_SX127X_CRC_AUTOCLEAR_OFF                      0b00001000  //  3     3     keep FIFO on CRC mismatch, issue payload ready interrupt
    390 #define RADIOLIB_SX127X_CRC_AUTOCLEAR_ON                       0b00000000  //  3     3     clear FIFO on CRC mismatch, do not issue payload ready interrupt
    391 #define RADIOLIB_SX127X_ADDRESS_FILTERING_OFF                  0b00000000  //  2     1     address filtering: none (default)
    392 #define RADIOLIB_SX127X_ADDRESS_FILTERING_NODE                 0b00000010  //  2     1                        node
    393 #define RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST       0b00000100  //  2     1                        node or broadcast
    394 #define RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT               0b00000000  //  0     0     CRC and whitening algorithms: CCITT CRC with standard whitening (default)
    395 #define RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM                 0b00000001  //  0     0                                   IBM CRC with alternate whitening
    396 
    397 // SX127X_REG_PACKET_CONFIG_2
    398 #define RADIOLIB_SX127X_DATA_MODE_PACKET                       0b01000000  //  6     6     data mode: packet (default)
    399 #define RADIOLIB_SX127X_DATA_MODE_CONTINUOUS                   0b00000000  //  6     6                continuous
    400 #define RADIOLIB_SX127X_IO_HOME_OFF                            0b00000000  //  5     5     io-homecontrol compatibility disabled (default)
    401 #define RADIOLIB_SX127X_IO_HOME_ON                             0b00100000  //  5     5     io-homecontrol compatibility enabled
    402 
    403 // SX127X_REG_FIFO_THRESH
    404 #define RADIOLIB_SX127X_TX_START_FIFO_LEVEL                    0b00000000  //  7     7     start packet transmission when: number of bytes in FIFO exceeds FIFO_THRESHOLD
    405 #define RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY                0b10000000  //  7     7                                     at least one byte in FIFO (default)
    406 #define RADIOLIB_SX127X_FIFO_THRESH                            0x1F        //  5     0     FIFO level threshold
    407 
    408 // SX127X_REG_SEQ_CONFIG_1
    409 #define RADIOLIB_SX127X_SEQUENCER_START                        0b10000000  //  7     7     manually start sequencer
    410 #define RADIOLIB_SX127X_SEQUENCER_STOP                         0b01000000  //  6     6     manually stop sequencer
    411 #define RADIOLIB_SX127X_IDLE_MODE_STANDBY                      0b00000000  //  5     5     chip mode during sequencer idle mode: standby (default)
    412 #define RADIOLIB_SX127X_IDLE_MODE_SLEEP                        0b00100000  //  5     5                                           sleep
    413 #define RADIOLIB_SX127X_FROM_START_LP_SELECTION                0b00000000  //  4     3     mode that will be set after starting sequencer: low power selection (default)
    414 #define RADIOLIB_SX127X_FROM_START_RECEIVE                     0b00001000  //  4     3                                                     receive
    415 #define RADIOLIB_SX127X_FROM_START_TRANSMIT                    0b00010000  //  4     3                                                     transmit
    416 #define RADIOLIB_SX127X_FROM_START_TRANSMIT_FIFO_LEVEL         0b00011000  //  4     3                                                     transmit on a FIFO level interrupt
    417 #define RADIOLIB_SX127X_LP_SELECTION_SEQ_OFF                   0b00000000  //  2     2     mode that will be set after exiting low power selection: sequencer off (default)
    418 #define RADIOLIB_SX127X_LP_SELECTION_IDLE                      0b00000100  //  2     2                                                              idle state
    419 #define RADIOLIB_SX127X_FROM_IDLE_TRANSMIT                     0b00000000  //  1     1     mode that will be set after exiting idle mode: transmit (default)
    420 #define RADIOLIB_SX127X_FROM_IDLE_RECEIVE                      0b00000010  //  1     1                                                    receive
    421 #define RADIOLIB_SX127X_FROM_TRANSMIT_LP_SELECTION             0b00000000  //  0     0     mode that will be set after exiting transmit mode: low power selection (default)
    422 #define RADIOLIB_SX127X_FROM_TRANSMIT_RECEIVE                  0b00000001  //  0     0                                                        receive
    423 
    424 // SX127X_REG_SEQ_CONFIG_2
    425 #define RADIOLIB_SX127X_FROM_RECEIVE_PACKET_RECEIVED_PAYLOAD   0b00100000  //  7     5     mode that will be set after exiting receive mode: packet received on payload ready interrupt (default)
    426 #define RADIOLIB_SX127X_FROM_RECEIVE_LP_SELECTION              0b01000000  //  7     5                                                       low power selection
    427 #define RADIOLIB_SX127X_FROM_RECEIVE_PACKET_RECEIVED_CRC_OK    0b01100000  //  7     5                                                       packet received on CRC OK interrupt
    428 #define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_RSSI              0b10000000  //  7     5                                                       sequencer off on RSSI interrupt
    429 #define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_SYNC_ADDR         0b10100000  //  7     5                                                       sequencer off on sync address interrupt
    430 #define RADIOLIB_SX127X_FROM_RECEIVE_SEQ_OFF_PREAMBLE_DETECT   0b11000000  //  7     5                                                       sequencer off on preamble detect interrupt
    431 #define RADIOLIB_SX127X_FROM_RX_TIMEOUT_RECEIVE                0b00000000  //  4     3     mode that will be set after Rx timeout: receive (default)
    432 #define RADIOLIB_SX127X_FROM_RX_TIMEOUT_TRANSMIT               0b00001000  //  4     3                                             transmit
    433 #define RADIOLIB_SX127X_FROM_RX_TIMEOUT_LP_SELECTION           0b00010000  //  4     3                                             low power selection
    434 #define RADIOLIB_SX127X_FROM_RX_TIMEOUT_SEQ_OFF                0b00011000  //  4     3                                             sequencer off
    435 #define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_SEQ_OFF           0b00000000  //  2     0     mode that will be set after packet received: sequencer off (default)
    436 #define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_TRANSMIT          0b00000001  //  2     0                                                  transmit
    437 #define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_LP_SELECTION      0b00000010  //  2     0                                                  low power selection
    438 #define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_RECEIVE_FS        0b00000011  //  2     0                                                  receive via FS
    439 #define RADIOLIB_SX127X_FROM_PACKET_RECEIVED_RECEIVE           0b00000100  //  2     0                                                  receive
    440 
    441 // SX127X_REG_TIMER_RESOL
    442 #define RADIOLIB_SX127X_TIMER1_OFF                             0b00000000  //  3     2     timer 1 resolution: disabled (default)
    443 #define RADIOLIB_SX127X_TIMER1_RESOLUTION_64_US                0b00000100  //  3     2                         64 us
    444 #define RADIOLIB_SX127X_TIMER1_RESOLUTION_4_1_MS               0b00001000  //  3     2                         4.1 ms
    445 #define RADIOLIB_SX127X_TIMER1_RESOLUTION_262_MS               0b00001100  //  3     2                         262 ms
    446 #define RADIOLIB_SX127X_TIMER2_OFF                             0b00000000  //  3     2     timer 2 resolution: disabled (default)
    447 #define RADIOLIB_SX127X_TIMER2_RESOLUTION_64_US                0b00000001  //  3     2                         64 us
    448 #define RADIOLIB_SX127X_TIMER2_RESOLUTION_4_1_MS               0b00000010  //  3     2                         4.1 ms
    449 #define RADIOLIB_SX127X_TIMER2_RESOLUTION_262_MS               0b00000011  //  3     2                         262 ms
    450 
    451 // SX127X_REG_TIMER1_COEF
    452 #define RADIOLIB_SX127X_TIMER1_COEFFICIENT                     0xF5        //  7     0     multiplication coefficient for timer 1
    453 
    454 // SX127X_REG_TIMER2_COEF
    455 #define RADIOLIB_SX127X_TIMER2_COEFFICIENT                     0x20        //  7     0     multiplication coefficient for timer 2
    456 
    457 // SX127X_REG_IMAGE_CAL
    458 #define RADIOLIB_SX127X_AUTO_IMAGE_CAL_OFF                     0b00000000  //  7     7     temperature calibration disabled (default)
    459 #define RADIOLIB_SX127X_AUTO_IMAGE_CAL_ON                      0b10000000  //  7     7     temperature calibration enabled
    460 #define RADIOLIB_SX127X_IMAGE_CAL_START                        0b01000000  //  6     6     start temperature calibration
    461 #define RADIOLIB_SX127X_IMAGE_CAL_RUNNING                      0b00100000  //  5     5     temperature calibration is on-going
    462 #define RADIOLIB_SX127X_IMAGE_CAL_COMPLETE                     0b00000000  //  5     5     temperature calibration finished
    463 #define RADIOLIB_SX127X_TEMP_CHANGED                           0b00001000  //  3     3     temperature changed more than TEMP_THRESHOLD since last calibration
    464 #define RADIOLIB_SX127X_TEMP_THRESHOLD_5_DEG_C                 0b00000000  //  2     1     temperature change threshold: 5 deg. C
    465 #define RADIOLIB_SX127X_TEMP_THRESHOLD_10_DEG_C                0b00000010  //  2     1                                   10 deg. C (default)
    466 #define RADIOLIB_SX127X_TEMP_THRESHOLD_15_DEG_C                0b00000100  //  2     1                                   15 deg. C
    467 #define RADIOLIB_SX127X_TEMP_THRESHOLD_20_DEG_C                0b00000110  //  2     1                                   20 deg. C
    468 #define RADIOLIB_SX127X_TEMP_MONITOR_ON                        0b00000000  //  0     0     temperature monitoring enabled (default)
    469 #define RADIOLIB_SX127X_TEMP_MONITOR_OFF                       0b00000001  //  0     0     temperature monitoring disabled
    470 
    471 // SX127X_REG_LOW_BAT
    472 #define RADIOLIB_SX127X_LOW_BAT_OFF                            0b00000000  //  3     3     low battery detector disabled
    473 #define RADIOLIB_SX127X_LOW_BAT_ON                             0b00001000  //  3     3     low battery detector enabled
    474 #define RADIOLIB_SX127X_LOW_BAT_TRIM_1_695_V                   0b00000000  //  2     0     battery voltage threshold: 1.695 V
    475 #define RADIOLIB_SX127X_LOW_BAT_TRIM_1_764_V                   0b00000001  //  2     0                                1.764 V
    476 #define RADIOLIB_SX127X_LOW_BAT_TRIM_1_835_V                   0b00000010  //  2     0                                1.835 V (default)
    477 #define RADIOLIB_SX127X_LOW_BAT_TRIM_1_905_V                   0b00000011  //  2     0                                1.905 V
    478 #define RADIOLIB_SX127X_LOW_BAT_TRIM_1_976_V                   0b00000100  //  2     0                                1.976 V
    479 #define RADIOLIB_SX127X_LOW_BAT_TRIM_2_045_V                   0b00000101  //  2     0                                2.045 V
    480 #define RADIOLIB_SX127X_LOW_BAT_TRIM_2_116_V                   0b00000110  //  2     0                                2.116 V
    481 #define RADIOLIB_SX127X_LOW_BAT_TRIM_2_185_V                   0b00000111  //  2     0                                2.185 V
    482 
    483 // SX127X_REG_IRQ_FLAGS_1
    484 #define RADIOLIB_SX127X_FLAG_MODE_READY                        0b10000000  //  7     7     requested mode is ready
    485 #define RADIOLIB_SX127X_FLAG_RX_READY                          0b01000000  //  6     6     reception ready (after RSSI, AGC, AFC)
    486 #define RADIOLIB_SX127X_FLAG_TX_READY                          0b00100000  //  5     5     transmission ready (after PA ramp-up)
    487 #define RADIOLIB_SX127X_FLAG_PLL_LOCK                          0b00010000  //  4     4     PLL locked
    488 #define RADIOLIB_SX127X_FLAG_RSSI                              0b00001000  //  3     3     RSSI value exceeds RSSI threshold
    489 #define RADIOLIB_SX127X_FLAG_TIMEOUT                           0b00000100  //  2     2     timeout occurred
    490 #define RADIOLIB_SX127X_FLAG_PREAMBLE_DETECT                   0b00000010  //  1     1     valid preamble was detected
    491 #define RADIOLIB_SX127X_FLAG_SYNC_ADDRESS_MATCH                0b00000001  //  0     0     sync address matched
    492 
    493 // SX127X_REG_IRQ_FLAGS_2
    494 #define RADIOLIB_SX127X_FLAG_FIFO_FULL                         0b10000000  //  7     7     FIFO is full
    495 #define RADIOLIB_SX127X_FLAG_FIFO_EMPTY                        0b01000000  //  6     6     FIFO is empty
    496 #define RADIOLIB_SX127X_FLAG_FIFO_LEVEL                        0b00100000  //  5     5     number of bytes in FIFO exceeds FIFO_THRESHOLD
    497 #define RADIOLIB_SX127X_FLAG_FIFO_OVERRUN                      0b00010000  //  4     4     FIFO overrun occurred
    498 #define RADIOLIB_SX127X_FLAG_PACKET_SENT                       0b00001000  //  3     3     packet was successfully sent
    499 #define RADIOLIB_SX127X_FLAG_PAYLOAD_READY                     0b00000100  //  2     2     packet was successfully received
    500 #define RADIOLIB_SX127X_FLAG_CRC_OK                            0b00000010  //  1     1     CRC check passed
    501 #define RADIOLIB_SX127X_FLAG_LOW_BAT                           0b00000001  //  0     0     battery voltage dropped below threshold
    502 
    503 // SX127X_REG_DIO_MAPPING_1
    504 #define RADIOLIB_SX127X_DIO0_LORA_RX_DONE                      0b00000000  //  7     6
    505 #define RADIOLIB_SX127X_DIO0_LORA_TX_DONE                      0b01000000  //  7     6
    506 #define RADIOLIB_SX127X_DIO0_LORA_CAD_DONE                     0b10000000  //  7     6
    507 #define RADIOLIB_SX127X_DIO0_CONT_MODE_READY                   0b11000000  //  7     6
    508 #define RADIOLIB_SX127X_DIO0_CONT_SYNC_ADDRESS                 0b00000000  //  7     6
    509 #define RADIOLIB_SX127X_DIO0_CONT_RSSI_PREAMBLE_DETECT         0b01000000  //  7     6
    510 #define RADIOLIB_SX127X_DIO0_CONT_RX_READY                     0b10000000  //  7     6
    511 #define RADIOLIB_SX127X_DIO0_CONT_TX_READY                     0b00000000  //  7     6
    512 #define RADIOLIB_SX127X_DIO0_PACK_PAYLOAD_READY                0b00000000  //  7     6
    513 #define RADIOLIB_SX127X_DIO0_PACK_PACKET_SENT                  0b00000000  //  7     6
    514 #define RADIOLIB_SX127X_DIO0_PACK_CRC_OK                       0b01000000  //  7     6
    515 #define RADIOLIB_SX127X_DIO0_PACK_TEMP_CHANGE_LOW_BAT          0b11000000  //  7     6
    516 #define RADIOLIB_SX127X_DIO1_LORA_RX_TIMEOUT                   0b00000000  //  5     4
    517 #define RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL          0b01000000  //  5     4
    518 #define RADIOLIB_SX127X_DIO1_LORA_CAD_DETECTED                 0b10000000  //  5     4
    519 #define RADIOLIB_SX127X_DIO1_CONT_DCLK                         0b00000000  //  5     4
    520 #define RADIOLIB_SX127X_DIO1_CONT_RSSI_PREAMBLE_DETECT         0b00010000  //  5     4
    521 #define RADIOLIB_SX127X_DIO1_PACK_FIFO_LEVEL                   0b00000000  //  5     4
    522 #define RADIOLIB_SX127X_DIO1_PACK_FIFO_EMPTY                   0b00010000  //  5     4
    523 #define RADIOLIB_SX127X_DIO1_PACK_FIFO_FULL                    0b00100000  //  5     4
    524 #define RADIOLIB_SX127X_DIO2_LORA_FHSS_CHANGE_CHANNEL          0b00000000  //  3     2
    525 #define RADIOLIB_SX127X_DIO2_CONT_DATA                         0b00000000  //  3     2
    526 #define RADIOLIB_SX127X_DIO2_PACK_FIFO_FULL                    0b00000000  //  3     2
    527 #define RADIOLIB_SX127X_DIO2_PACK_RX_READY                     0b00000100  //  3     2
    528 #define RADIOLIB_SX127X_DIO2_PACK_TIMEOUT                      0b00001000  //  3     2
    529 #define RADIOLIB_SX127X_DIO2_PACK_SYNC_ADDRESS                 0b00011000  //  3     2
    530 #define RADIOLIB_SX127X_DIO3_LORA_CAD_DONE                     0b00000000  //  0     1
    531 #define RADIOLIB_SX127X_DIO3_LORA_VALID_HEADER                 0b00000001  //  0     1
    532 #define RADIOLIB_SX127X_DIO3_LORA_PAYLOAD_CRC_ERROR            0b00000010  //  0     1
    533 #define RADIOLIB_SX127X_DIO3_CONT_TIMEOUT                      0b00000000  //  0     1
    534 #define RADIOLIB_SX127X_DIO3_CONT_RSSI_PREAMBLE_DETECT         0b00000001  //  0     1
    535 #define RADIOLIB_SX127X_DIO3_CONT_TEMP_CHANGE_LOW_BAT          0b00000011  //  0     1
    536 #define RADIOLIB_SX127X_DIO3_PACK_FIFO_EMPTY                   0b00000000  //  0     1
    537 #define RADIOLIB_SX127X_DIO3_PACK_TX_READY                     0b00000001  //  0     1
    538 
    539 // SX127X_REG_DIO_MAPPING_2
    540 #define RADIOLIB_SX127X_DIO4_LORA_CAD_DETECTED                 0b10000000  //  7     6
    541 #define RADIOLIB_SX127X_DIO4_LORA_PLL_LOCK                     0b01000000  //  7     6
    542 #define RADIOLIB_SX127X_DIO4_CONT_TEMP_CHANGE_LOW_BAT          0b00000000  //  7     6
    543 #define RADIOLIB_SX127X_DIO4_CONT_PLL_LOCK                     0b01000000  //  7     6
    544 #define RADIOLIB_SX127X_DIO4_CONT_TIMEOUT                      0b10000000  //  7     6
    545 #define RADIOLIB_SX127X_DIO4_CONT_MODE_READY                   0b11000000  //  7     6
    546 #define RADIOLIB_SX127X_DIO4_PACK_TEMP_CHANGE_LOW_BAT          0b00000000  //  7     6
    547 #define RADIOLIB_SX127X_DIO4_PACK_PLL_LOCK                     0b01000000  //  7     6
    548 #define RADIOLIB_SX127X_DIO4_PACK_TIMEOUT                      0b10000000  //  7     6
    549 #define RADIOLIB_SX127X_DIO4_PACK_RSSI_PREAMBLE_DETECT         0b11000000  //  7     6
    550 #define RADIOLIB_SX127X_DIO5_LORA_MODE_READY                   0b00000000  //  5     4
    551 #define RADIOLIB_SX127X_DIO5_LORA_CLK_OUT                      0b00010000  //  5     4
    552 #define RADIOLIB_SX127X_DIO5_CONT_CLK_OUT                      0b00000000  //  5     4
    553 #define RADIOLIB_SX127X_DIO5_CONT_PLL_LOCK                     0b00010000  //  5     4
    554 #define RADIOLIB_SX127X_DIO5_CONT_RSSI_PREAMBLE_DETECT         0b00100000  //  5     4
    555 #define RADIOLIB_SX127X_DIO5_CONT_MODE_READY                   0b00110000  //  5     4
    556 #define RADIOLIB_SX127X_DIO5_PACK_CLK_OUT                      0b00000000  //  5     4
    557 #define RADIOLIB_SX127X_DIO5_PACK_PLL_LOCK                     0b00010000  //  5     4
    558 #define RADIOLIB_SX127X_DIO5_PACK_DATA                         0b00100000  //  5     4
    559 #define RADIOLIB_SX127X_DIO5_PACK_MODE_READY                   0b00110000  //  5     4
    560 #define RADIOLIB_SX127X_DIO_MAP_PREAMBLE_DETECT                0b00000001  //  0     0
    561 #define RADIOLIB_SX127X_DIO_MAP_RSSI                           0b00000000  //  0     0
    562 
    563 // SX1272_REG_PLL_HOP + SX1278_REG_PLL_HOP
    564 #define RADIOLIB_SX127X_FAST_HOP_OFF                           0b00000000  //  7     7     carrier frequency validated when FRF registers are written
    565 #define RADIOLIB_SX127X_FAST_HOP_ON                            0b10000000  //  7     7     carrier frequency validated when FS modes are requested
    566 
    567 // SX1272_REG_TCXO + SX1278_REG_TCXO
    568 #define RADIOLIB_SX127X_TCXO_INPUT_EXTERNAL                    0b00000000  //  4     4     use external crystal oscillator
    569 #define RADIOLIB_SX127X_TCXO_INPUT_EXTERNAL_CLIPPED            0b00010000  //  4     4     use external crystal oscillator clipped sine connected to XTA pin
    570 
    571 // SX1272_REG_PLL + SX1278_REG_PLL
    572 #define RADIOLIB_SX127X_PLL_BANDWIDTH_75_KHZ                   0b00000000  //  7     6     PLL bandwidth: 75 kHz
    573 #define RADIOLIB_SX127X_PLL_BANDWIDTH_150_KHZ                  0b01000000  //  7     6                    150 kHz
    574 #define RADIOLIB_SX127X_PLL_BANDWIDTH_225_KHZ                  0b10000000  //  7     6                    225 kHz
    575 #define RADIOLIB_SX127X_PLL_BANDWIDTH_300_KHZ                  0b11000000  //  7     6                    300 kHz (default)
    576 
    577 /*!
    578   \class SX127x
    579 
    580   \brief Base class for SX127x series. All derived classes for SX127x (e.g. SX1278 or SX1272) inherit from this base class.
    581   This class should not be instantiated directly from Arduino sketch, only from its derived classes.
    582 */
    583 class SX127x: public PhysicalLayer {
    584   public:
    585     // introduce PhysicalLayer overloads
    586     using PhysicalLayer::transmit;
    587     using PhysicalLayer::receive;
    588     using PhysicalLayer::startTransmit;
    589     using PhysicalLayer::readData;
    590 
    591     // constructor
    592 
    593     /*!
    594       \brief Default constructor. Called internally when creating new LoRa instance.
    595 
    596       \param mod Instance of Module that will be used to communicate with the %LoRa chip.
    597     */
    598     SX127x(Module* mod);
    599 
    600     Module* getMod();
    601 
    602     // basic methods
    603 
    604     /*!
    605       \brief Initialization method. Will be called with appropriate parameters when calling initialization method from derived class.
    606 
    607       \param chipVersion Value in SPI version register. Used to verify the connection and hardware version.
    608 
    609       \param syncWord %LoRa sync word.
    610 
    611       \param preambleLength Length of %LoRa transmission preamble in symbols.
    612 
    613       \returns \ref status_codes
    614     */
    615     int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLength);
    616 
    617     /*!
    618       \brief Reset method. Will reset the chip to the default state using RST pin. Declared pure virtual since SX1272 and SX1278 implementations differ.
    619     */
    620     virtual void reset() = 0;
    621 
    622     /*!
    623       \brief Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class.
    624 
    625       \param chipVersion Value in SPI version register. Used to verify the connection and hardware version.
    626 
    627       \param br Bit rate of the FSK transmission in kbps (kilobits per second).
    628 
    629       \param freqDev Frequency deviation of the FSK transmission in kHz.
    630 
    631       \param rxBw Receiver bandwidth in kHz.
    632 
    633       \param preambleLength Length of FSK preamble in bits.
    634 
    635       \param enableOOK Flag to specify OOK mode. This modulation is similar to FSK.
    636 
    637       \returns \ref status_codes
    638     */
    639     int16_t beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint16_t preambleLength, bool enableOOK);
    640 
    641     /*!
    642       \brief Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
    643       For overloads to transmit Arduino String or C-string, see PhysicalLayer::transmit.
    644 
    645       \param data Binary data that will be transmitted.
    646 
    647       \param len Length of binary data to transmit (in bytes).
    648 
    649       \param addr Node address to transmit the packet to. Only used in FSK mode.
    650 
    651       \returns \ref status_codes
    652     */
    653     int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
    654 
    655     /*!
    656       \brief Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
    657       For overloads to receive Arduino String, see PhysicalLayer::receive.
    658 
    659       \param data Pointer to array to save the received binary data.
    660 
    661       \param len Number of bytes that will be received. Must be known in advance for binary transmissions.
    662 
    663       \returns \ref status_codes
    664     */
    665     int16_t receive(uint8_t* data, size_t len) override;
    666 
    667     /*!
    668       \brief Performs scan for valid %LoRa preamble in the current channel.
    669 
    670       \returns \ref status_codes
    671     */
    672     int16_t scanChannel();
    673 
    674     /*!
    675       \brief Sets the %LoRa module to sleep to save power. %Module will not be able to transmit or receive any data while in sleep mode.
    676       %Module will wake up automatically when methods like transmit or receive are called.
    677 
    678       \returns \ref status_codes
    679     */
    680     int16_t sleep();
    681 
    682     /*!
    683       \brief Sets the %LoRa module to standby.
    684 
    685       \returns \ref status_codes
    686     */
    687     int16_t standby() override;
    688 
    689     /*!
    690       \brief Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data).
    691       While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
    692 
    693       \param frf 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY.
    694 
    695       \returns \ref status_codes
    696     */
    697     int16_t transmitDirect(uint32_t frf = 0) override;
    698 
    699     /*!
    700       \brief Enables direct reception mode on pins DIO1 (clock) and DIO2 (data).
    701       While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
    702 
    703       \returns \ref status_codes
    704     */
    705     int16_t receiveDirect() override;
    706 
    707     /*!
    708       \brief Disables direct mode and enables packet mode, allowing the module to receive packets. Can only be activated in FSK mode.
    709 
    710       \returns \ref status_codes
    711     */
    712     int16_t packetMode();
    713 
    714     // interrupt methods
    715 
    716     /*!
    717       \brief Set interrupt service routine function to call when DIO0 activates.
    718 
    719       \param func Pointer to interrupt service routine.
    720     */
    721     void setDio0Action(void (*func)(void));
    722 
    723     /*!
    724       \brief Clears interrupt service routine to call when DIO0 activates.
    725     */
    726     void clearDio0Action();
    727 
    728     /*!
    729       \brief Set interrupt service routine function to call when DIO1 activates.
    730 
    731       \param func Pointer to interrupt service routine.
    732     */
    733     void setDio1Action(void (*func)(void));
    734 
    735     /*!
    736       \brief Clears interrupt service routine to call when DIO1 activates.
    737     */
    738     void clearDio1Action();
    739 
    740     /*!
    741       \brief Set interrupt service routine function to call when FIFO is empty.
    742 
    743       \param func Pointer to interrupt service routine.
    744     */
    745     void setFifoEmptyAction(void (*func)(void));
    746 
    747     /*!
    748       \brief Clears interrupt service routine to call when  FIFO is empty.
    749     */
    750     void clearFifoEmptyAction();
    751 
    752     /*!
    753       \brief Set interrupt service routine function to call when FIFO is full.
    754 
    755       \param func Pointer to interrupt service routine.
    756     */
    757     void setFifoFullAction(void (*func)(void));
    758 
    759     /*!
    760       \brief Clears interrupt service routine to call when  FIFO is full.
    761     */
    762     void clearFifoFullAction();
    763 
    764     /*!
    765       \brief Set interrupt service routine function to call when FIFO is empty.
    766 
    767       \param data Pointer to the transmission buffer.
    768 
    769       \param totalLen Total number of bytes to transmit.
    770 
    771       \param remLen Pointer to a counter holding the number of bytes that have been transmitted so far.
    772 
    773       \returns True when a complete packet is sent, false if more data is needed.
    774     */
    775     bool fifoAdd(uint8_t* data, int totalLen, volatile int* remLen);
    776 
    777     /*!
    778       \brief Set interrupt service routine function to call when FIFO is sufficently full to read.
    779 
    780       \param data Pointer to a buffer that stores the receive data.
    781 
    782       \param totalLen Total number of bytes to receive.
    783 
    784       \param rcvLen Pointer to a counter holding the number of bytes that have been received so far.
    785 
    786       \returns True when a complete packet is received, false if more data is needed.
    787     */
    788     bool fifoGet(volatile uint8_t* data, int totalLen, volatile int* rcvLen);
    789 
    790     /*!
    791       \brief Interrupt-driven binary transmit method. Will start transmitting arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
    792 
    793       \param data Binary data that will be transmitted.
    794 
    795       \param len Length of binary data to transmit (in bytes).
    796 
    797       \param addr Node address to transmit the packet to. Only used in FSK mode.
    798 
    799       \returns \ref status_codes
    800     */
    801     int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
    802 
    803     /*!
    804       \brief Interrupt-driven receive method. DIO0 will be activated when full valid packet is received.
    805 
    806       \param len Expected length of packet to be received. Required for LoRa spreading factor 6.
    807 
    808       \param mode Receive mode to be used. Defaults to RxContinuous.
    809 
    810       \returns \ref status_codes
    811     */
    812     int16_t startReceive(uint8_t len = 0, uint8_t mode = RADIOLIB_SX127X_RXCONTINUOUS);
    813 
    814     /*!
    815       \brief Reads data that was received after calling startReceive method. This method reads len characters.
    816 
    817       \param data Pointer to array to save the received binary data.
    818 
    819       \param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically.
    820       When more bytes than received are requested, only the number of bytes requested will be returned.
    821 
    822       \returns \ref status_codes
    823     */
    824     int16_t readData(uint8_t* data, size_t len) override;
    825 
    826     /*!
    827       \brief Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is detected.
    828       DIO1 will be activated if there's no preamble detected before timeout.
    829 
    830       \returns \ref status_codes
    831     */
    832     int16_t startChannelScan();
    833 
    834     // configuration methods
    835 
    836     /*!
    837       \brief Sets %LoRa sync word. Only available in %LoRa mode.
    838 
    839       \param syncWord Sync word to be set.
    840 
    841       \returns \ref status_codes
    842     */
    843     int16_t setSyncWord(uint8_t syncWord);
    844 
    845     /*!
    846       \brief Sets current limit for over current protection at transmitter amplifier. Allowed values range from 45 to 120 mA in 5 mA steps and 120 to 240 mA in 10 mA steps.
    847 
    848       \param currentLimit Current limit to be set (in mA).
    849 
    850       \returns \ref status_codes
    851     */
    852     int16_t setCurrentLimit(uint8_t currentLimit);
    853 
    854     /*!
    855       \brief Sets %LoRa or FSK preamble length. Allowed values range from 6 to 65535 in %LoRa mode or 0 to 65535 in FSK mode.
    856 
    857       \param preambleLength Preamble length to be set (in symbols when in LoRa mode or bits in FSK mode).
    858 
    859       \returns \ref status_codes
    860     */
    861     int16_t setPreambleLength(uint16_t preambleLength);
    862 
    863     /*!
    864       \brief Gets frequency error of the latest received packet.
    865 
    866       \param autoCorrect When set to true, frequency will be automatically corrected.
    867 
    868       \returns Frequency error in Hz.
    869     */
    870     float getFrequencyError(bool autoCorrect = false);
    871 
    872     /*!
    873       \brief Gets current AFC error.
    874 
    875       \returns Frequency offset from RF in Hz if AFC is enabled and triggered, zero otherwise.
    876     */
    877     float getAFCError();
    878 
    879     /*!
    880       \brief Gets signal-to-noise ratio of the latest received packet. Only available in LoRa mode.
    881 
    882       \returns Last packet signal-to-noise ratio (SNR).
    883     */
    884     float getSNR();
    885 
    886     /*!
    887       \brief Get data rate of the latest transmitted packet.
    888 
    889       \returns Last packet data rate in bps (bits per second).
    890     */
    891     float getDataRate() const;
    892 
    893     /*!
    894       \brief Sets FSK bit rate. Allowed values range from 1.2 to 300 kbps. Only available in FSK mode.
    895 
    896       \param br Bit rate to be set (in kbps).
    897 
    898       \returns \ref status_codes
    899     */
    900     int16_t setBitRate(float br);
    901 
    902     /*!
    903       \brief Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode.
    904 
    905       \param freqDev Frequency deviation to be set (in kHz).
    906 
    907       \returns \ref status_codes
    908     */
    909     int16_t setFrequencyDeviation(float freqDev) override;
    910 
    911     /*!
    912       \brief Sets FSK receiver bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode.
    913 
    914       \param rxBw Receiver bandwidth to be set (in kHz).
    915 
    916       \returns \ref status_codes
    917     */
    918     int16_t setRxBandwidth(float rxBw);
    919 
    920     /*!
    921       \brief Sets FSK automatic frequency correction bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode.
    922 
    923       \param rxBw Receiver AFC bandwidth to be set (in kHz).
    924 
    925       \returns \ref status_codes
    926     */
    927     int16_t setAFCBandwidth(float afcBw);
    928 
    929     /*!
    930       \brief Enables or disables FSK automatic frequency correction(AFC)
    931 
    932       \param isEnabled AFC enabled or disabled
    933 
    934       \return \ref status_codes
    935     */
    936     int16_t setAFC(bool isEnabled);
    937 
    938     /*!
    939       \brief Controls trigger of AFC and AGC
    940 
    941       \param trigger one from SX127X_RX_TRIGGER_NONE, SX127X_RX_TRIGGER_RSSI_INTERRUPT, SX127X_RX_TRIGGER_PREAMBLE_DETECT, SX127X_RX_TRIGGER_BOTH
    942 
    943       \return \ref status_codes
    944     */
    945     int16_t setAFCAGCTrigger(uint8_t trigger);
    946 
    947     /*!
    948       \brief Sets FSK sync word. Allowed sync words are up to 8 bytes long and can not contain null bytes. Only available in FSK mode.
    949 
    950       \param syncWord Sync word array.
    951 
    952       \param len Sync word length (in bytes).
    953 
    954       \returns \ref status_codes
    955     */
    956     int16_t setSyncWord(uint8_t* syncWord, size_t len);
    957 
    958     /*!
    959       \brief Sets FSK node address. Calling this method will enable address filtering. Only available in FSK mode.
    960 
    961       \param nodeAddr Node address to be set.
    962 
    963       \returns \ref status_codes
    964     */
    965     int16_t setNodeAddress(uint8_t nodeAddr);
    966 
    967     /*!
    968       \brief Sets FSK broadcast address. Calling this method will enable address filtering. Only available in FSK mode.
    969 
    970       \param broadAddr Broadcast address to be set.
    971 
    972       \returns \ref status_codes
    973     */
    974     int16_t setBroadcastAddress(uint8_t broadAddr);
    975 
    976     /*!
    977       \brief Disables FSK address filtering.
    978 
    979       \returns \ref status_codes
    980     */
    981     int16_t disableAddressFiltering();
    982 
    983     /*!
    984       \brief Enables/disables OOK modulation instead of FSK.
    985 
    986       \param enableOOK Enable (true) or disable (false) OOK.
    987 
    988       \returns \ref status_codes
    989     */
    990     int16_t setOOK(bool enableOOK);
    991 
    992     /*!
    993       \brief Selects the type of threshold in the OOK data slicer.
    994 
    995       \param type Threshold type: SX127X_OOK_THRESH_PEAK(default), SX127X_OOK_THRESH_FIXED, SX127X_OOK_THRESH_AVERAGE
    996 
    997       \returns \ref status_codes
    998     */
    999     int16_t setOokThresholdType(uint8_t type);
   1000 
   1001     /*!
   1002       \brief Period of decrement of the RSSI threshold in the OOK demodulator.
   1003 
   1004       \param value Use defines RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_X_X_CHIP
   1005 
   1006       \returns \ref status_codes
   1007     */
   1008     int16_t setOokPeakThresholdDecrement(uint8_t value);
   1009 
   1010     /*!
   1011       \brief Fixed threshold for the Data Slicer in OOK mode or floor threshold for the Data Slicer in OOK when Peak mode is used.
   1012 
   1013       \param value Threshold level in steps of 0.5 dB.
   1014 
   1015       \returns \ref status_codes
   1016     */
   1017     int16_t setOokFixedOrFloorThreshold(uint8_t value);
   1018 
   1019       /*!
   1020       \brief Size of each decrement of the RSSI threshold in the OOK demodulator.
   1021 
   1022       \param value Step size: RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_0_5_DB (default), RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_5_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_2_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_3_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_4_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_5_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_6_0_DB
   1023 
   1024       \returns \ref status_codes
   1025     */
   1026     int16_t setOokPeakThresholdStep(uint8_t value);
   1027 
   1028     /*!
   1029     \brief Enable Bit synchronizer.
   1030 
   1031     \returns \ref status_codes
   1032     */
   1033     int16_t enableBitSync();
   1034 
   1035     /*!
   1036       \brief Disable Bit synchronizer (not allowed in Packet mode).
   1037 
   1038       \returns \ref status_codes
   1039     */
   1040     int16_t disableBitSync();
   1041 
   1042     /*!
   1043       \brief Query modem for the packet length of received payload.
   1044 
   1045       \param update Update received packet length. Will return cached value when set to false.
   1046 
   1047       \returns Length of last received packet in bytes.
   1048     */
   1049     size_t getPacketLength(bool update = true) override;
   1050 
   1051     /*!
   1052      \brief Set modem in fixed packet length mode. Available in FSK mode only.
   1053 
   1054      \param len Packet length.
   1055 
   1056      \returns \ref status_codes
   1057    */
   1058    int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK);
   1059 
   1060     /*!
   1061      \brief Set modem in variable packet length mode. Available in FSK mode only.
   1062 
   1063      \param len Maximum packet length.
   1064 
   1065      \returns \ref status_codes
   1066    */
   1067    int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK);
   1068 
   1069    /*!
   1070      \brief Get expected time-on-air for a given size of payload
   1071 
   1072      \param len Payload length in bytes.
   1073 
   1074      \returns Expected time-on-air in microseconds.
   1075    */
   1076    uint32_t getTimeOnAir(size_t len);
   1077 
   1078    /*!
   1079       \brief Enable CRC filtering and generation.
   1080 
   1081       \param crcOn Set or unset CRC filtering and generation.
   1082 
   1083       \returns \ref status_codes
   1084    */
   1085    int16_t setCrcFiltering(bool crcOn = true);
   1086 
   1087     /*!
   1088       \brief Sets RSSI measurement configuration in FSK mode.
   1089 
   1090       \param smoothingSamples Number of samples taken to average the RSSI result.
   1091       numSamples = 2 ^ (1 + smoothingSamples), allowed values are in range 0 (2 samples) - 7 (256 samples)
   1092 
   1093       \param offset Signed RSSI offset that will be automatically compensated. 1 dB per LSB, defaults to 0, allowed values are in range -16 dB to +15 dB.
   1094 
   1095       \returns \ref status_codes
   1096     */
   1097     int16_t setRSSIConfig(uint8_t smoothingSamples, int8_t offset = 0);
   1098 
   1099     /*!
   1100       \brief Sets transmission encoding. Only available in FSK mode.
   1101        Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING.
   1102 
   1103       \param encoding Encoding to be used.
   1104 
   1105       \returns \ref status_codes
   1106     */
   1107     int16_t setEncoding(uint8_t encoding) override;
   1108 
   1109     /*!
   1110       \brief Reads currently active IRQ flags, can be used to check which event caused an interrupt.
   1111       In LoRa mode, this is the content of SX127X_REG_IRQ_FLAGS register.
   1112       In FSK mode, this is the contents of SX127X_REG_IRQ_FLAGS_2 (MSB) and SX127X_REG_IRQ_FLAGS_1 (LSB) registers.
   1113 
   1114       \returns IRQ flags.
   1115     */
   1116     uint16_t getIRQFlags();
   1117 
   1118     /*!
   1119       \brief Reads modem status. Only available in LoRa mode.
   1120 
   1121       \returns Modem status.
   1122     */
   1123     uint8_t getModemStatus();
   1124 
   1125     /*!
   1126       \brief Reads uncalibrated temperature value. This function will change operating mode
   1127       and should not be called during Tx, Rx or CAD.
   1128 
   1129       \returns Uncalibrated temperature sensor reading.
   1130     */
   1131     int8_t getTempRaw();
   1132 
   1133     /*!
   1134       \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state.
   1135       When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
   1136 
   1137       \param rxEn RX enable pin.
   1138 
   1139       \param txEn TX enable pin.
   1140     */
   1141     void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
   1142 
   1143     /*!
   1144      \brief Get one truly random byte from RSSI noise.
   1145 
   1146      \returns TRNG byte.
   1147    */
   1148     uint8_t randomByte();
   1149 
   1150     /*!
   1151      \brief Read version SPI register. Should return SX1278_CHIP_VERSION (0x12) or SX1272_CHIP_VERSION (0x22) if SX127x is connected and working.
   1152 
   1153      \returns Version register contents or \ref status_codes
   1154    */
   1155     int16_t getChipVersion();
   1156 
   1157     /*!
   1158       \brief Enables/disables Invert the LoRa I and Q signals.
   1159 
   1160       \param invertIQ Enable (true) or disable (false) LoRa I and Q signals.
   1161 
   1162       \returns \ref status_codes
   1163     */
   1164     int16_t invertIQ(bool invertIQ);
   1165 
   1166     #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
   1167     /*!
   1168       \brief Set interrupt service routine function to call when data bit is receveid in direct mode.
   1169 
   1170       \param func Pointer to interrupt service routine.
   1171     */
   1172     void setDirectAction(void (*func)(void));
   1173 
   1174     /*!
   1175       \brief Function to read and process data bit in direct reception mode.
   1176 
   1177       \param pin Pin on which to read.
   1178     */
   1179     void readBit(RADIOLIB_PIN_TYPE pin);
   1180     #endif
   1181 
   1182     /*!
   1183       \brief Sets the hopping period and enables FHSS
   1184 
   1185       \param freqHoppingPeriod Integer multiple of symbol periods between hops
   1186 
   1187       \returns \ref status_codes
   1188     */
   1189     int16_t setFHSSHoppingPeriod(uint8_t freqHoppingPeriod);
   1190 
   1191         /*!
   1192       \brief Gets FHSS hopping period
   1193 
   1194       \returns 8 bit period
   1195     */
   1196     uint8_t getFHSSHoppingPeriod(void);
   1197 
   1198     /*!
   1199       \brief Gets the FHSS channel in use
   1200 
   1201       \returns 6 bit channel number
   1202     */
   1203     uint8_t getFHSSChannel(void);
   1204 
   1205     /*!
   1206       \brief Clear the FHSS interrupt
   1207     */
   1208     void clearFHSSInt(void);
   1209 
   1210     /*!
   1211       \brief Configure DIO pin mapping to get a given signal on a DIO pin (if available).
   1212 
   1213       \param pin Pin number onto which a signal is to be placed.
   1214 
   1215       \param value The value that indicates which function to place on that pin. See chip datasheet for details.
   1216 
   1217       \returns \ref status_codes
   1218     */
   1219     int16_t setDIOMapping(RADIOLIB_PIN_TYPE pin, uint8_t value);
   1220 
   1221     /*!
   1222       \brief Configure DIO mapping to use RSSI or Preamble Detect for pins that support it.
   1223 
   1224       \param usePreambleDetect Whether to use PreambleDetect (true) or RSSI (false) on the pins that are mapped to this function.
   1225 
   1226       \returns \ref status_codes
   1227     */
   1228     int16_t setDIOPreambleDetect(bool usePreambleDetect);
   1229 
   1230     /*!
   1231       \brief Sets the RSSI value above which the RSSI interrupt is signaled
   1232 
   1233       \param dbm A dBm value between -127.5 and 0 inclusive
   1234 
   1235       \returns \ref status_codes
   1236     */
   1237     int16_t setRSSIThreshold(float dbm);
   1238 
   1239 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
   1240   protected:
   1241 #endif
   1242     Module* _mod;
   1243 
   1244 #if !defined(RADIOLIB_GODMODE)
   1245   protected:
   1246 #endif
   1247 
   1248     float _freq = 0;
   1249     float _bw = 0;
   1250     uint8_t _sf = 0;
   1251     uint8_t _cr = 0;
   1252     float _br = 0;
   1253     bool _ook = false;
   1254     bool _crcEnabled = false;
   1255     bool _crcOn = true; // default value used in FSK mode
   1256     size_t _packetLength = 0;
   1257 
   1258     int16_t setFrequencyRaw(float newFreq);
   1259     int16_t config();
   1260     int16_t configFSK();
   1261     int16_t getActiveModem();
   1262     int16_t directMode();
   1263     int16_t setPacketMode(uint8_t mode, uint8_t len);
   1264 
   1265 #if !defined(RADIOLIB_GODMODE)
   1266   private:
   1267 #endif
   1268     float _dataRate = 0;
   1269     bool _packetLengthQueried = false; // FSK packet length is the first byte in FIFO, length can only be queried once
   1270     uint8_t _packetLengthConfig = RADIOLIB_SX127X_PACKET_VARIABLE;
   1271 
   1272     bool findChip(uint8_t ver);
   1273     int16_t setMode(uint8_t mode);
   1274     int16_t setActiveModem(uint8_t modem);
   1275     void clearIRQFlags();
   1276     void clearFIFO(size_t count); // used mostly to clear remaining bytes in FIFO after a packet read
   1277     /**
   1278      * @brief Calculate exponent and mantissa values for receiver bandwidth and AFC
   1279      *
   1280      * \param bandwidth bandwidth to be set (in kHz).
   1281      *
   1282      * \returns bandwidth in manitsa and exponent format
   1283      */
   1284     static uint8_t calculateBWManExp(float bandwidth);
   1285 
   1286     virtual void errataFix(bool rx) = 0;
   1287 };
   1288 
   1289 #endif
   1290 
   1291 #endif