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

SX128x.h (50728B)

      1 #if !defined(_RADIOLIB_SX128X_H)
      2 #define _RADIOLIB_SX128X_H
      3 
      4 #include "../../TypeDef.h"
      5 
      6 #if !defined(RADIOLIB_EXCLUDE_SX128X)
      7 
      8 #include "../../Module.h"
      9 
     10 #include "../../protocols/PhysicalLayer/PhysicalLayer.h"
     11 
     12 // SX128X physical layer properties
     13 #define RADIOLIB_SX128X_FREQUENCY_STEP_SIZE                    198.3642578
     14 #define RADIOLIB_SX128X_MAX_PACKET_LENGTH                      255
     15 #define RADIOLIB_SX128X_CRYSTAL_FREQ                           52.0
     16 #define RADIOLIB_SX128X_DIV_EXPONENT                           18
     17 
     18 // SX128X SPI commands
     19 #define RADIOLIB_SX128X_CMD_NOP                                0x00
     20 #define RADIOLIB_SX128X_CMD_GET_STATUS                         0xC0
     21 #define RADIOLIB_SX128X_CMD_WRITE_REGISTER                     0x18
     22 #define RADIOLIB_SX128X_CMD_READ_REGISTER                      0x19
     23 #define RADIOLIB_SX128X_CMD_WRITE_BUFFER                       0x1A
     24 #define RADIOLIB_SX128X_CMD_READ_BUFFER                        0x1B
     25 #define RADIOLIB_SX128X_CMD_SET_SLEEP                          0x84
     26 #define RADIOLIB_SX128X_CMD_SET_STANDBY                        0x80
     27 #define RADIOLIB_SX128X_CMD_SET_FS                             0xC1
     28 #define RADIOLIB_SX128X_CMD_SET_TX                             0x83
     29 #define RADIOLIB_SX128X_CMD_SET_RX                             0x82
     30 #define RADIOLIB_SX128X_CMD_SET_RX_DUTY_CYCLE                  0x94
     31 #define RADIOLIB_SX128X_CMD_SET_CAD                            0xC5
     32 #define RADIOLIB_SX128X_CMD_SET_TX_CONTINUOUS_WAVE             0xD1
     33 #define RADIOLIB_SX128X_CMD_SET_TX_CONTINUOUS_PREAMBLE         0xD2
     34 #define RADIOLIB_SX128X_CMD_SET_PACKET_TYPE                    0x8A
     35 #define RADIOLIB_SX128X_CMD_GET_PACKET_TYPE                    0x03
     36 #define RADIOLIB_SX128X_CMD_SET_RF_FREQUENCY                   0x86
     37 #define RADIOLIB_SX128X_CMD_SET_TX_PARAMS                      0x8E
     38 #define RADIOLIB_SX128X_CMD_SET_CAD_PARAMS                     0x88
     39 #define RADIOLIB_SX128X_CMD_SET_BUFFER_BASE_ADDRESS            0x8F
     40 #define RADIOLIB_SX128X_CMD_SET_MODULATION_PARAMS              0x8B
     41 #define RADIOLIB_SX128X_CMD_SET_PACKET_PARAMS                  0x8C
     42 #define RADIOLIB_SX128X_CMD_GET_RX_BUFFER_STATUS               0x17
     43 #define RADIOLIB_SX128X_CMD_GET_PACKET_STATUS                  0x1D
     44 #define RADIOLIB_SX128X_CMD_GET_RSSI_INST                      0x1F
     45 #define RADIOLIB_SX128X_CMD_SET_DIO_IRQ_PARAMS                 0x8D
     46 #define RADIOLIB_SX128X_CMD_GET_IRQ_STATUS                     0x15
     47 #define RADIOLIB_SX128X_CMD_CLEAR_IRQ_STATUS                   0x97
     48 #define RADIOLIB_SX128X_CMD_SET_REGULATOR_MODE                 0x96
     49 #define RADIOLIB_SX128X_CMD_SET_SAVE_CONTEXT                   0xD5
     50 #define RADIOLIB_SX128X_CMD_SET_AUTO_TX                        0x98
     51 #define RADIOLIB_SX128X_CMD_SET_AUTO_FS                        0x9E
     52 #define RADIOLIB_SX128X_CMD_SET_PERF_COUNTER_MODE              0x9C
     53 #define RADIOLIB_SX128X_CMD_SET_LONG_PREAMBLE                  0x9B
     54 #define RADIOLIB_SX128X_CMD_SET_UART_SPEED                     0x9D
     55 #define RADIOLIB_SX128X_CMD_SET_RANGING_ROLE                   0xA3
     56 #define RADIOLIB_SX128X_CMD_SET_ADVANCED_RANGING               0x9A
     57 
     58 // SX128X register map
     59 #define RADIOLIB_SX128X_REG_GAIN_MODE                          0x0891
     60 #define RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2       0x0895
     61 #define RADIOLIB_SX128X_REG_MANUAL_GAIN_SETTING                0x089E
     62 #define RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1       0x089F
     63 #define RADIOLIB_SX128X_REG_SYNCH_PEAK_ATTENUATION             0x08C2
     64 #define RADIOLIB_SX128X_REG_LORA_FIXED_PAYLOAD_LENGTH          0x0901
     65 #define RADIOLIB_SX128X_REG_LORA_HEADER_MODE                   0x0903
     66 #define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_3      0x0912
     67 #define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_2      0x0913
     68 #define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_1      0x0914
     69 #define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_0      0x0915
     70 #define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_3       0x0916
     71 #define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_2       0x0917
     72 #define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_1       0x0918
     73 #define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_0       0x0919
     74 #define RADIOLIB_SX128X_REG_RANGING_FILTER_WINDOW_SIZE         0x091E
     75 #define RADIOLIB_SX128X_REG_RANGING_FILTER_RESET               0x0923
     76 #define RADIOLIB_SX128X_REG_RANGING_TYPE                       0x0924
     77 #define RADIOLIB_SX128X_REG_LORA_SF_CONFIG                     0x0925
     78 #define RADIOLIB_SX128X_REG_RANGING_ADDRESS_SWITCH             0x0927
     79 #define RADIOLIB_SX128X_REG_RANGING_CALIBRATION_BYTE_2         0x092B
     80 #define RADIOLIB_SX128X_REG_RANGING_CALIBRATION_MSB            0x092C
     81 #define RADIOLIB_SX128X_REG_RANGING_CALIBRATION_LSB            0x092D
     82 #define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH        0x0931
     83 #define RADIOLIB_SX128X_REG_FREQ_ERROR_CORRECTION              0x093C
     84 #define RADIOLIB_SX128X_REG_LORA_SYNC_WORD_MSB                 0x0944
     85 #define RADIOLIB_SX128X_REG_LORA_SYNC_WORD_LSB                 0x0945
     86 #define RADIOLIB_SX128X_REG_RANGING_FILTER_RSSI_OFFSET         0x0953
     87 #define RADIOLIB_SX128X_REG_FEI_MSB                            0x0954
     88 #define RADIOLIB_SX128X_REG_FEI_MID                            0x0955
     89 #define RADIOLIB_SX128X_REG_FEI_LSB                            0x0956
     90 #define RADIOLIB_SX128X_REG_RANGING_ADDRESS_MSB                0x095F
     91 #define RADIOLIB_SX128X_REG_RANGING_ADDRESS_LSB                0x0960
     92 #define RADIOLIB_SX128X_REG_RANGING_RESULT_MSB                 0x0961
     93 #define RADIOLIB_SX128X_REG_RANGING_RESULT_MID                 0x0962
     94 #define RADIOLIB_SX128X_REG_RANGING_RESULT_LSB                 0x0963
     95 #define RADIOLIB_SX128X_REG_RANGING_RSSI                       0x0964
     96 #define RADIOLIB_SX128X_REG_RANGING_LORA_CLOCK_ENABLE          0x097F
     97 #define RADIOLIB_SX128X_REG_PACKET_PREAMBLE_SETTINGS           0x09C1
     98 #define RADIOLIB_SX128X_REG_WHITENING_INITIAL_VALUE            0x09C5
     99 #define RADIOLIB_SX128X_REG_CRC_POLYNOMIAL_MSB                 0x09C6
    100 #define RADIOLIB_SX128X_REG_CRC_POLYNOMIAL_LSB                 0x09C7
    101 #define RADIOLIB_SX128X_REG_CRC_INITIAL_MSB                    0x09C8
    102 #define RADIOLIB_SX128X_REG_CRC_INITIAL_LSB                    0x09C9
    103 #define RADIOLIB_SX128X_REG_BLE_CRC_INITIAL_MSB                0x09C7
    104 #define RADIOLIB_SX128X_REG_BLE_CRC_INITIAL_MID                (RADIOLIB_SX128X_REG_CRC_INITIAL_MSB)
    105 #define RADIOLIB_SX128X_REG_BLE_CRC_INITIAL_LSB                (RADIOLIB_SX128X_REG_CRC_INITIAL_LSB)
    106 #define RADIOLIB_SX128X_REG_SYNCH_ADDRESS_CONTROL              0x09CD
    107 #define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_4                 0x09CE
    108 #define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_3                 0x09CF
    109 #define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_2                 0x09D0
    110 #define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_1                 0x09D1
    111 #define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_0                 0x09D2
    112 #define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_4                 0x09D3
    113 #define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_3                 0x09D4
    114 #define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_2                 0x09D5
    115 #define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_1                 0x09D6
    116 #define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_0                 0x09D7
    117 #define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_4                 0x09D8
    118 #define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_3                 0x09D9
    119 #define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_2                 0x09DA
    120 #define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_1                 0x09DB
    121 #define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_0                 0x09DC
    122 #define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_3              (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_3)
    123 #define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_2              (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_2)
    124 #define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_1              (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_1)
    125 #define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_0              (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_0)
    126 
    127 // SX128X SPI command variables
    128 //RADIOLIB_SX128X_CMD_GET_STATUS                                               MSB   LSB   DESCRIPTION
    129 #define RADIOLIB_SX128X_STATUS_MODE_STDBY_RC                   0b01000000  //  7     5     current chip mode: STDBY_RC
    130 #define RADIOLIB_SX128X_STATUS_MODE_STDBY_XOSC                 0b01100000  //  7     5                        STDBY_XOSC
    131 #define RADIOLIB_SX128X_STATUS_MODE_FS                         0b10000000  //  7     5                        FS
    132 #define RADIOLIB_SX128X_STATUS_MODE_RX                         0b10100000  //  7     5                        Rx
    133 #define RADIOLIB_SX128X_STATUS_MODE_TX                         0b11000000  //  7     5                        Tx
    134 #define RADIOLIB_SX128X_STATUS_CMD_PROCESSED                   0b00000100  //  4     2     command status: processing OK
    135 #define RADIOLIB_SX128X_STATUS_DATA_AVAILABLE                  0b00001000  //  4     2                     data available
    136 #define RADIOLIB_SX128X_STATUS_CMD_TIMEOUT                     0b00001100  //  4     2                     timeout
    137 #define RADIOLIB_SX128X_STATUS_CMD_ERROR                       0b00010000  //  4     2                     processing error
    138 #define RADIOLIB_SX128X_STATUS_CMD_FAILED                      0b00010100  //  4     2                     failed to execute
    139 #define RADIOLIB_SX128X_STATUS_TX_DONE                         0b00011000  //  4     2                     transmission finished
    140 #define RADIOLIB_SX128X_STATUS_BUSY                            0b00000001  //  0     0     chip busy
    141 #define RADIOLIB_SX128X_STATUS_SPI_FAILED                      0b11111111  //  7     0     SPI transaction failed
    142 
    143 //RADIOLIB_SX128X_CMD_SET_SLEEP
    144 #define RADIOLIB_SX128X_SLEEP_DATA_BUFFER_FLUSH                0b00000000  //  1     1     data buffer behavior in sleep mode: flush
    145 #define RADIOLIB_SX128X_SLEEP_DATA_BUFFER_RETAIN               0b00000010  //  1     1                                         retain
    146 #define RADIOLIB_SX128X_SLEEP_DATA_RAM_FLUSH                   0b00000000  //  0     0     data RAM (configuration) behavior in sleep mode: flush
    147 #define RADIOLIB_SX128X_SLEEP_DATA_RAM_RETAIN                  0b00000001  //  0     0                                                      retain
    148 
    149 //RADIOLIB_SX128X_CMD_SET_STANDBY
    150 #define RADIOLIB_SX128X_STANDBY_RC                             0x00        //  7     0     standby mode: 13 MHz RC oscillator
    151 #define RADIOLIB_SX128X_STANDBY_XOSC                           0x01        //  7     0                   52 MHz crystal oscillator
    152 
    153 //RADIOLIB_SX128X_CMD_SET_TX + RADIOLIB_SX128X_CMD_SET_RX + RADIOLIB_SX128X_CMD_SET_RX_DUTY_CYCLE
    154 #define RADIOLIB_SX128X_PERIOD_BASE_15_625_US                  0x00        //  7     0     time period step: 15.625 us
    155 #define RADIOLIB_SX128X_PERIOD_BASE_62_5_US                    0x01        //  7     0                       62.5 us
    156 #define RADIOLIB_SX128X_PERIOD_BASE_1_MS                       0x02        //  7     0                       1 ms
    157 #define RADIOLIB_SX128X_PERIOD_BASE_4_MS                       0x03        //  7     0                       4 ms
    158 
    159 //RADIOLIB_SX128X_CMD_SET_TX
    160 #define RADIOLIB_SX128X_TX_TIMEOUT_NONE                        0x0000      //  15    0     Tx timeout duration: no timeout (Tx single mode)
    161 
    162 //RADIOLIB_SX128X_CMD_SET_RX
    163 #define RADIOLIB_SX128X_RX_TIMEOUT_NONE                        0x0000      //  15    0     Rx timeout duration: no timeout (Rx single mode)
    164 #define RADIOLIB_SX128X_RX_TIMEOUT_INF                         0xFFFF      //  15    0                          infinite (Rx continuous mode)
    165 
    166 //RADIOLIB_SX128X_CMD_SET_PACKET_TYPE
    167 #define RADIOLIB_SX128X_PACKET_TYPE_GFSK                       0x00        //  7     0     packet type: (G)FSK
    168 #define RADIOLIB_SX128X_PACKET_TYPE_LORA                       0x01        //  7     0                  LoRa
    169 #define RADIOLIB_SX128X_PACKET_TYPE_RANGING                    0x02        //  7     0                  ranging engine
    170 #define RADIOLIB_SX128X_PACKET_TYPE_FLRC                       0x03        //  7     0                  FLRC
    171 #define RADIOLIB_SX128X_PACKET_TYPE_BLE                        0x04        //  7     0                  BLE
    172 
    173 //RADIOLIB_SX128X_CMD_SET_TX_PARAMS
    174 #define RADIOLIB_SX128X_PA_RAMP_02_US                          0x00        //  7     0     PA ramp time: 2 us
    175 #define RADIOLIB_SX128X_PA_RAMP_04_US                          0x20        //  7     0                   4 us
    176 #define RADIOLIB_SX128X_PA_RAMP_06_US                          0x40        //  7     0                   6 us
    177 #define RADIOLIB_SX128X_PA_RAMP_08_US                          0x60        //  7     0                   8 us
    178 #define RADIOLIB_SX128X_PA_RAMP_10_US                          0x80        //  7     0                   10 us
    179 #define RADIOLIB_SX128X_PA_RAMP_12_US                          0xA0        //  7     0                   12 us
    180 #define RADIOLIB_SX128X_PA_RAMP_16_US                          0xC0        //  7     0                   16 us
    181 #define RADIOLIB_SX128X_PA_RAMP_20_US                          0xE0        //  7     0                   20 us
    182 
    183 //RADIOLIB_SX128X_CMD_SET_CAD_PARAMS
    184 #define RADIOLIB_SX128X_CAD_ON_1_SYMB                          0x00        //  7     0     number of symbols used for CAD: 1
    185 #define RADIOLIB_SX128X_CAD_ON_2_SYMB                          0x20        //  7     0                                     2
    186 #define RADIOLIB_SX128X_CAD_ON_4_SYMB                          0x40        //  7     0                                     4
    187 #define RADIOLIB_SX128X_CAD_ON_8_SYMB                          0x60        //  7     0                                     8
    188 #define RADIOLIB_SX128X_CAD_ON_16_SYMB                         0x80        //  7     0                                     16
    189 
    190 //RADIOLIB_SX128X_CMD_SET_MODULATION_PARAMS
    191 #define RADIOLIB_SX128X_BLE_GFSK_BR_2_000_BW_2_4               0x04        //  7     0     GFSK/BLE bit rate and bandwidth setting: 2.0 Mbps   2.4 MHz
    192 #define RADIOLIB_SX128X_BLE_GFSK_BR_1_600_BW_2_4               0x28        //  7     0                                              1.6 Mbps   2.4 MHz
    193 #define RADIOLIB_SX128X_BLE_GFSK_BR_1_000_BW_2_4               0x4C        //  7     0                                              1.0 Mbps   2.4 MHz
    194 #define RADIOLIB_SX128X_BLE_GFSK_BR_1_000_BW_1_2               0x45        //  7     0                                              1.0 Mbps   1.2 MHz
    195 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_800_BW_2_4               0x70        //  7     0                                              0.8 Mbps   2.4 MHz
    196 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_800_BW_1_2               0x69        //  7     0                                              0.8 Mbps   1.2 MHz
    197 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_500_BW_1_2               0x8D        //  7     0                                              0.5 Mbps   1.2 MHz
    198 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_500_BW_0_6               0x86        //  7     0                                              0.5 Mbps   0.6 MHz
    199 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_400_BW_1_2               0xB1        //  7     0                                              0.4 Mbps   1.2 MHz
    200 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_400_BW_0_6               0xAA        //  7     0                                              0.4 Mbps   0.6 MHz
    201 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_250_BW_0_6               0xCE        //  7     0                                              0.25 Mbps  0.6 MHz
    202 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_250_BW_0_3               0xC7        //  7     0                                              0.25 Mbps  0.3 MHz
    203 #define RADIOLIB_SX128X_BLE_GFSK_BR_0_125_BW_0_3               0xEF        //  7     0                                              0.125 Mbps 0.3 MHz
    204 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_0_35                  0x00        //  7     0     GFSK/BLE modulation index: 0.35
    205 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_0_50                  0x01        //  7     0                                0.50
    206 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_0_75                  0x02        //  7     0                                0.75
    207 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_00                  0x03        //  7     0                                1.00
    208 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_25                  0x04        //  7     0                                1.25
    209 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_50                  0x05        //  7     0                                1.50
    210 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_75                  0x06        //  7     0                                1.75
    211 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_00                  0x07        //  7     0                                2.00
    212 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_25                  0x08        //  7     0                                2.25
    213 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_50                  0x09        //  7     0                                2.50
    214 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_75                  0x0A        //  7     0                                2.75
    215 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_00                  0x0B        //  7     0                                3.00
    216 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_25                  0x0C        //  7     0                                3.25
    217 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_50                  0x0D        //  7     0                                3.50
    218 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_75                  0x0E        //  7     0                                3.75
    219 #define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_4_00                  0x0F        //  7     0                                4.00
    220 #define RADIOLIB_SX128X_BLE_GFSK_BT_OFF                        0x00        //  7     0     GFSK Gaussian filter BT product: filter disabled
    221 #define RADIOLIB_SX128X_BLE_GFSK_BT_1_0                        0x10        //  7     0                                      1.0
    222 #define RADIOLIB_SX128X_BLE_GFSK_BT_0_5                        0x20        //  7     0                                      0.5
    223 #define RADIOLIB_SX128X_FLRC_BR_1_300_BW_1_2                   0x45        //  7     0     FLRC bit rate and bandwidth setting: 1.3 Mbps   1.2 MHz
    224 #define RADIOLIB_SX128X_FLRC_BR_1_000_BW_1_2                   0x69        //  7     0                                          1.04 Mbps  1.2 MHz
    225 #define RADIOLIB_SX128X_FLRC_BR_0_650_BW_0_6                   0x86        //  7     0                                          0.65 Mbps  0.6 MHz
    226 #define RADIOLIB_SX128X_FLRC_BR_0_520_BW_0_6                   0xAA        //  7     0                                          0.52 Mbps  0.6 MHz
    227 #define RADIOLIB_SX128X_FLRC_BR_0_325_BW_0_3                   0xC7        //  7     0                                          0.325 Mbps 0.3 MHz
    228 #define RADIOLIB_SX128X_FLRC_BR_0_260_BW_0_3                   0xEB        //  7     0                                          0.260 Mbps 0.3 MHz
    229 #define RADIOLIB_SX128X_FLRC_CR_1_2                            0x00        //  7     0     FLRC coding rate: 1/2
    230 #define RADIOLIB_SX128X_FLRC_CR_3_4                            0x02        //  7     0                       3/4
    231 #define RADIOLIB_SX128X_FLRC_CR_1_0                            0x04        //  7     0                       1/1
    232 #define RADIOLIB_SX128X_FLRC_BT_OFF                            0x00        //  7     0     FLRC Gaussian filter BT product: filter disabled
    233 #define RADIOLIB_SX128X_FLRC_BT_1_0                            0x10        //  7     0                                      1.0
    234 #define RADIOLIB_SX128X_FLRC_BT_0_5                            0x20        //  7     0                                      0.5
    235 #define RADIOLIB_SX128X_LORA_SF_5                              0x50        //  7     0     LoRa spreading factor: 5
    236 #define RADIOLIB_SX128X_LORA_SF_6                              0x60        //  7     0                            6
    237 #define RADIOLIB_SX128X_LORA_SF_7                              0x70        //  7     0                            7
    238 #define RADIOLIB_SX128X_LORA_SF_8                              0x80        //  7     0                            8
    239 #define RADIOLIB_SX128X_LORA_SF_9                              0x90        //  7     0                            9
    240 #define RADIOLIB_SX128X_LORA_SF_10                             0xA0        //  7     0                            10
    241 #define RADIOLIB_SX128X_LORA_SF_11                             0xB0        //  7     0                            11
    242 #define RADIOLIB_SX128X_LORA_SF_12                             0xC0        //  7     0                            12
    243 #define RADIOLIB_SX128X_LORA_BW_1625_00                        0x0A        //  7     0     LoRa bandwidth: 1625.0 kHz
    244 #define RADIOLIB_SX128X_LORA_BW_812_50                         0x18        //  7     0                     812.5 kHz
    245 #define RADIOLIB_SX128X_LORA_BW_406_25                         0x26        //  7     0                     406.25 kHz
    246 #define RADIOLIB_SX128X_LORA_BW_203_125                        0x34        //  7     0                     203.125 kHz
    247 #define RADIOLIB_SX128X_LORA_CR_4_5                            0x01        //  7     0     LoRa coding rate: 4/5
    248 #define RADIOLIB_SX128X_LORA_CR_4_6                            0x02        //  7     0                       4/6
    249 #define RADIOLIB_SX128X_LORA_CR_4_7                            0x03        //  7     0                       4/7
    250 #define RADIOLIB_SX128X_LORA_CR_4_8                            0x04        //  7     0                       4/8
    251 #define RADIOLIB_SX128X_LORA_CR_4_5_LI                         0x05        //  7     0                       4/5, long interleaving
    252 #define RADIOLIB_SX128X_LORA_CR_4_6_LI                         0x06        //  7     0                       4/6, long interleaving
    253 #define RADIOLIB_SX128X_LORA_CR_4_7_LI                         0x07        //  7     0                       4/7, long interleaving
    254 
    255 //RADIOLIB_SX128X_CMD_SET_PACKET_PARAMS
    256 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_OFF                0x00        //  7     0     GFSK/FLRC sync word used: none
    257 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1                  0x10        //  7     0                               sync word 1
    258 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_2                  0x20        //  7     0                               sync word 2
    259 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1_2                0x30        //  7     0                               sync words 1 and 2
    260 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_3                  0x40        //  7     0                               sync word 3
    261 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1_3                0x50        //  7     0                               sync words 1 and 3
    262 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_2_3                0x60        //  7     0                               sync words 2 and 3
    263 #define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1_2_3              0x70        //  7     0                               sync words 1, 2 and 3
    264 #define RADIOLIB_SX128X_GFSK_FLRC_PACKET_FIXED                 0x00        //  7     0     GFSK/FLRC packet length mode: fixed
    265 #define RADIOLIB_SX128X_GFSK_FLRC_PACKET_VARIABLE              0x20        //  7     0                                   variable
    266 #define RADIOLIB_SX128X_GFSK_FLRC_CRC_OFF                      0x00        //  7     0     GFSK/FLRC packet CRC: none
    267 #define RADIOLIB_SX128X_GFSK_FLRC_CRC_1_BYTE                   0x10        //  7     0                           1 byte
    268 #define RADIOLIB_SX128X_GFSK_FLRC_CRC_2_BYTE                   0x20        //  7     0                           2 bytes
    269 #define RADIOLIB_SX128X_GFSK_FLRC_CRC_3_BYTE                   0x30        //  7     0                           3 bytes (FLRC only)
    270 #define RADIOLIB_SX128X_GFSK_BLE_WHITENING_ON                  0x00        //  7     0     GFSK/BLE whitening: enabled
    271 #define RADIOLIB_SX128X_GFSK_BLE_WHITENING_OFF                 0x08        //  7     0                         disabled
    272 #define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_MAX_31              0x00        //  7     0     BLE maximum payload length: 31 bytes
    273 #define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_MAX_37              0x20        //  7     0                                 37 bytes
    274 #define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_TEST                0x40        //  7     0                                 63 bytes (test mode)
    275 #define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_MAX_255             0x80        //  7     0                                 255 bytes (Bluetooth 4.2 and above)
    276 #define RADIOLIB_SX128X_BLE_CRC_OFF                            0x00        //  7     0     BLE packet CRC: none
    277 #define RADIOLIB_SX128X_BLE_CRC_3_BYTE                         0x10        //  7     0                     3 byte
    278 #define RADIOLIB_SX128X_BLE_PRBS_9                             0x00        //  7     0     BLE test payload contents: PRNG sequence using x^9 + x^5 + x
    279 #define RADIOLIB_SX128X_BLE_EYELONG                            0x04        //  7     0                                repeated 0xF0
    280 #define RADIOLIB_SX128X_BLE_EYESHORT                           0x08        //  7     0                                repeated 0xAA
    281 #define RADIOLIB_SX128X_BLE_PRBS_15                            0x0C        //  7     0                                PRNG sequence using x^15 + x^14 + x^13 + x^12 + x^2 + x + 1
    282 #define RADIOLIB_SX128X_BLE_ALL_1                              0x10        //  7     0                                repeated 0xFF
    283 #define RADIOLIB_SX128X_BLE_ALL_0                              0x14        //  7     0                                repeated 0x00
    284 #define RADIOLIB_SX128X_BLE_EYELONG_INV                        0x18        //  7     0                                repeated 0x0F
    285 #define RADIOLIB_SX128X_BLE_EYESHORT_INV                       0x1C        //  7     0                                repeated 0x55
    286 #define RADIOLIB_SX128X_FLRC_SYNC_WORD_OFF                     0x00        //  7     0     FLRC sync word: disabled
    287 #define RADIOLIB_SX128X_FLRC_SYNC_WORD_ON                      0x04        //  7     0                     enabled
    288 #define RADIOLIB_SX128X_LORA_HEADER_EXPLICIT                   0x00        //  7     0     LoRa header mode: explicit
    289 #define RADIOLIB_SX128X_LORA_HEADER_IMPLICIT                   0x80        //  7     0                       implicit
    290 #define RADIOLIB_SX128X_LORA_CRC_OFF                           0x00        //  7     0     LoRa packet CRC: disabled
    291 #define RADIOLIB_SX128X_LORA_CRC_ON                            0x20        //  7     0                      enabled
    292 #define RADIOLIB_SX128X_LORA_IQ_STANDARD                       0x40        //  7     0     LoRa IQ: standard
    293 #define RADIOLIB_SX128X_LORA_IQ_INVERTED                       0x00        //  7     0              inverted
    294 
    295 //RADIOLIB_SX128X_CMD_GET_PACKET_STATUS
    296 #define RADIOLIB_SX128X_PACKET_STATUS_SYNC_ERROR               0b01000000  //  6     6     packet status errors byte: sync word error
    297 #define RADIOLIB_SX128X_PACKET_STATUS_LENGTH_ERROR             0b00100000  //  5     5                                packet length error
    298 #define RADIOLIB_SX128X_PACKET_STATUS_CRC_ERROR                0b00010000  //  4     4                                CRC error
    299 #define RADIOLIB_SX128X_PACKET_STATUS_ABORT_ERROR              0b00001000  //  3     3                                packet reception aborted
    300 #define RADIOLIB_SX128X_PACKET_STATUS_HEADER_RECEIVED          0b00000100  //  2     2                                header received
    301 #define RADIOLIB_SX128X_PACKET_STATUS_PACKET_RECEIVED          0b00000010  //  1     1                                packet received
    302 #define RADIOLIB_SX128X_PACKET_STATUS_PACKET_CTRL_BUSY         0b00000001  //  0     0                                packet controller is busy
    303 #define RADIOLIB_SX128X_PACKET_STATUS_RX_PID                   0b11000000  //  7     6     packet status status byte: PID field of the received packet
    304 #define RADIOLIB_SX128X_PACKET_STATUS_NO_ACK                   0b00100000  //  5     5                                NO_ACK field of the received packet
    305 #define RADIOLIB_SX128X_PACKET_STATUS_RX_PID_ERROR             0b00010000  //  4     4                                PID field error
    306 #define RADIOLIB_SX128X_PACKET_STATUS_PACKET_SENT              0b00000001  //  0     0                                packet sent
    307 #define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_ERROR           0b00000000  //  2     0     packet status sync byte: sync word detection error
    308 #define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_1               0b00000001  //  2     0                              detected sync word 1
    309 #define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_2               0b00000010  //  2     0                              detected sync word 2
    310 #define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_3               0b00000100  //  2     0                              detected sync word 3
    311 
    312 //RADIOLIB_SX128X_CMD_SET_DIO_IRQ_PARAMS
    313 #define RADIOLIB_SX128X_IRQ_RADIOLIB_PREAMBLE_DETECTED                  0x8000      //  15    15    interrupt source: preamble detected
    314 #define RADIOLIB_SX128X_IRQ_ADVANCED_RANGING_DONE              0x8000      //  15    15                      advanced ranging done
    315 #define RADIOLIB_SX128X_IRQ_RX_TX_TIMEOUT                      0x4000      //  14    14                      Rx or Tx timeout
    316 #define RADIOLIB_SX128X_IRQ_CAD_DETECTED                       0x2000      //  13    13                      channel activity detected
    317 #define RADIOLIB_SX128X_IRQ_CAD_DONE                           0x1000      //  12    12                      CAD finished
    318 #define RADIOLIB_SX128X_IRQ_RANGING_SLAVE_REQ_VALID            0x0800      //  11    11                      ranging request valid (slave)
    319 #define RADIOLIB_SX128X_IRQ_RANGING_MASTER_TIMEOUT             0x0400      //  10    10                      ranging timeout (master)
    320 #define RADIOLIB_SX128X_IRQ_RANGING_MASTER_RES_VALID           0x0200      //  9     9                       ranging result valid (master)
    321 #define RADIOLIB_SX128X_IRQ_RANGING_SLAVE_REQ_DISCARD          0x0100      //  8     8                       ranging result valid (master)
    322 #define RADIOLIB_SX128X_IRQ_RANGING_SLAVE_RESP_DONE            0x0080      //  7     7                       ranging response complete (slave)
    323 #define RADIOLIB_SX128X_IRQ_CRC_ERROR                          0x0040      //  6     6                       CRC error
    324 #define RADIOLIB_SX128X_IRQ_HEADER_ERROR                       0x0020      //  5     5                       header error
    325 #define RADIOLIB_SX128X_IRQ_HEADER_VALID                       0x0010      //  4     4                       header valid
    326 #define RADIOLIB_SX128X_IRQ_SYNC_WORD_ERROR                    0x0008      //  3     3                       sync word error
    327 #define RADIOLIB_SX128X_IRQ_SYNC_WORD_VALID                    0x0004      //  2     2                       sync word valid
    328 #define RADIOLIB_SX128X_IRQ_RX_DONE                            0x0002      //  1     1                       Rx done
    329 #define RADIOLIB_SX128X_IRQ_TX_DONE                            0x0001      //  0     0                       Tx done
    330 #define RADIOLIB_SX128X_IRQ_NONE                               0x0000      //  15    0                       none
    331 #define RADIOLIB_SX128X_IRQ_ALL                                0xFFFF      //  15    0                       all
    332 
    333 //RADIOLIB_SX128X_CMD_SET_REGULATOR_MODE
    334 #define RADIOLIB_SX128X_REGULATOR_LDO                          0x00        //  7     0     set regulator mode: LDO (default)
    335 #define RADIOLIB_SX128X_REGULATOR_DC_DC                        0x01        //  7     0                         DC-DC
    336 
    337 //RADIOLIB_SX128X_CMD_SET_RANGING_ROLE
    338 #define RADIOLIB_SX128X_RANGING_ROLE_MASTER                    0x01        //  7     0     ranging role: master
    339 #define RADIOLIB_SX128X_RANGING_ROLE_SLAVE                     0x00        //  7     0                   slave
    340 
    341 //RADIOLIB_SX128X_REG_LORA_SYNC_WORD_1 - RADIOLIB_SX128X_REG_LORA_SYNC_WORD_2
    342 #define RADIOLIB_SX128X_SYNC_WORD_PRIVATE                      0x12
    343 
    344 /*!
    345   \class SX128x
    346 
    347   \brief Base class for %SX128x series. All derived classes for %SX128x (e.g. SX1280 or SX1281) inherit from this base class.
    348   This class should not be instantiated directly from Arduino sketch, only from its derived classes.
    349 */
    350 class SX128x: public PhysicalLayer {
    351   public:
    352     // introduce PhysicalLayer overloads
    353     using PhysicalLayer::transmit;
    354     using PhysicalLayer::receive;
    355     using PhysicalLayer::startTransmit;
    356     using PhysicalLayer::readData;
    357 
    358     /*!
    359       \brief Default constructor.
    360 
    361       \param mod Instance of Module that will be used to communicate with the radio.
    362     */
    363     SX128x(Module* mod);
    364 
    365     Module* getMod();
    366 
    367     // basic methods
    368 
    369     /*!
    370       \brief Initialization method for LoRa modem.
    371 
    372       \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz.
    373 
    374       \param bw LoRa bandwidth in kHz. Defaults to 812.5 kHz.
    375 
    376       \param sf LoRa spreading factor. Defaults to 9.
    377 
    378       \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
    379 
    380       \param syncWord 2-byte LoRa sync word. Defaults to RADIOLIB_SX128X_SYNC_WORD_PRIVATE (0x12).
    381 
    382       \param power Output power in dBm. Defaults to 10 dBm.
    383 
    384       \param preambleLength LoRa preamble length in symbols. Defaults to 12 symbols.
    385 
    386       \returns \ref status_codes
    387     */
    388     int16_t begin(float freq = 2400.0, float bw = 812.5, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX128X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 12);
    389 
    390     /*!
    391       \brief Initialization method for GFSK modem.
    392 
    393       \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz.
    394 
    395       \param br FSK bit rate in kbps. Defaults to 800 kbps.
    396 
    397       \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 400.0 kHz.
    398 
    399       \param power Output power in dBm. Defaults to 10 dBm.
    400 
    401       \parma preambleLength FSK preamble length in bits. Defaults to 16 bits.
    402 
    403       \returns \ref status_codes
    404     */
    405     int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16);
    406 
    407     /*!
    408       \brief Initialization method for BLE modem.
    409 
    410       \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz.
    411 
    412       \param br BLE bit rate in kbps. Defaults to 800 kbps.
    413 
    414       \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 400.0 kHz.
    415 
    416       \param power Output power in dBm. Defaults to 10 dBm.
    417 
    418       \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5.
    419 
    420       \returns \ref status_codes
    421     */
    422     int16_t beginBLE(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint8_t dataShaping = RADIOLIB_SHAPING_0_5);
    423 
    424     /*!
    425       \brief Initialization method for FLRC modem.
    426 
    427       \param freq Carrier frequency in MHz. Defaults to 2400.0 MHz.
    428 
    429       \param br FLRC bit rate in kbps. Defaults to 650 kbps.
    430 
    431       \param cr FLRC coding rate. Defaults to 3 (coding rate 3/4).
    432 
    433       \param power Output power in dBm. Defaults to 10 dBm.
    434 
    435       \parma preambleLength FLRC preamble length in bits. Defaults to 16 bits.
    436 
    437       \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5.
    438 
    439       \returns \ref status_codes
    440     */
    441     int16_t beginFLRC(float freq = 2400.0, uint16_t br = 650, uint8_t cr = 3, int8_t power = 10, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5);
    442 
    443     /*!
    444       \brief Reset method. Will reset the chip to the default state using RST pin.
    445 
    446       \param verify Whether correct module startup should be verified. When set to true, RadioLib will attempt to verify the module has started correctly
    447       by repeatedly issuing setStandby command. Enabled by default.
    448 
    449       \returns \ref status_codes
    450     */
    451     int16_t reset(bool verify = true);
    452 
    453     /*!
    454       \brief Blocking binary transmit method.
    455       Overloads for string-based transmissions are implemented in PhysicalLayer.
    456 
    457       \param data Binary data to be sent.
    458 
    459       \param len Number of bytes to send.
    460 
    461       \param addr Address to send the data to. Unsupported, compatibility only.
    462 
    463       \returns \ref status_codes
    464     */
    465     int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
    466 
    467     /*!
    468       \brief Blocking binary receive method.
    469       Overloads for string-based transmissions are implemented in PhysicalLayer.
    470 
    471       \param data Binary data to be sent.
    472 
    473       \param len Number of bytes to send.
    474 
    475       \returns \ref status_codes
    476     */
    477     int16_t receive(uint8_t* data, size_t len) override;
    478 
    479     /*!
    480       \brief Starts direct mode transmission.
    481 
    482       \param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
    483 
    484       \returns \ref status_codes
    485     */
    486     int16_t transmitDirect(uint32_t frf = 0) override;
    487 
    488     /*!
    489       \brief Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as %SX128x series does not support direct mode reception.
    490       Will always return RADIOLIB_ERR_UNKNOWN.
    491 
    492       \returns \ref status_codes
    493     */
    494     int16_t receiveDirect() override;
    495 
    496     /*!
    497       \brief Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.
    498 
    499       \returns \ref status_codes
    500     */
    501     int16_t scanChannel();
    502 
    503     /*!
    504       \brief Sets the module to sleep mode.
    505 
    506       \param retainConfig Set to true to retain configuration and data buffer or to false to discard current configuration and data buffer. Defaults to true.
    507 
    508       \returns \ref status_codes
    509     */
    510     int16_t sleep(bool retainConfig = true);
    511 
    512     /*!
    513       \brief Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator).
    514 
    515       \returns \ref status_codes
    516     */
    517     int16_t standby() override;
    518 
    519     /*!
    520       \brief Sets the module to standby mode.
    521 
    522       \param mode Oscillator to be used in standby mode. Can be set to RADIOLIB_SX128X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX128X_STANDBY_XOSC (52 MHz external crystal oscillator).
    523 
    524       \returns \ref status_codes
    525     */
    526     int16_t standby(uint8_t mode);
    527 
    528     // interrupt methods
    529 
    530     /*!
    531       \brief Sets interrupt service routine to call when DIO1 activates.
    532 
    533       \param func ISR to call.
    534     */
    535     void setDio1Action(void (*func)(void));
    536 
    537     /*!
    538       \brief Clears interrupt service routine to call when DIO1 activates.
    539     */
    540     void clearDio1Action();
    541 
    542     /*!
    543       \brief Interrupt-driven binary transmit method.
    544       Overloads for string-based transmissions are implemented in PhysicalLayer.
    545 
    546       \param data Binary data to be sent.
    547 
    548       \param len Number of bytes to send.
    549 
    550       \param addr Address to send the data to. Unsupported, compatibility only.
    551 
    552       \returns \ref status_codes
    553     */
    554     int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
    555 
    556     /*!
    557       \brief Interrupt-driven receive method. DIO1 will be activated when full packet is received.
    558 
    559       \param timeout Raw timeout value, expressed as multiples of 15.625 us. Defaults to RADIOLIB_SX128X_RX_TIMEOUT_INF for infinite timeout (Rx continuous mode), set to RADIOLIB_SX128X_RX_TIMEOUT_NONE for no timeout (Rx single mode).
    560 
    561       \returns \ref status_codes
    562     */
    563     int16_t startReceive(uint16_t timeout = RADIOLIB_SX128X_RX_TIMEOUT_INF);
    564 
    565     /*!
    566       \brief Reads data received after calling startReceive method.
    567 
    568       \param data Pointer to array to save the received binary data.
    569 
    570       \param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically.
    571       When more bytes than received are requested, only the number of bytes requested will be returned.
    572 
    573       \returns \ref status_codes
    574     */
    575     int16_t readData(uint8_t* data, size_t len) override;
    576 
    577     // configuration methods
    578 
    579     /*!
    580       \brief Sets carrier frequency. Allowed values are in range from 2400.0 to 2500.0 MHz.
    581 
    582       \param freq Carrier frequency to be set in MHz.
    583 
    584       \returns \ref status_codes
    585     */
    586     int16_t setFrequency(float freq);
    587 
    588     /*!
    589       \brief Sets LoRa bandwidth. Allowed values are 203.125, 406.25, 812.5 and 1625.0 kHz.
    590 
    591       \param bw LoRa bandwidth to be set in kHz.
    592 
    593       \returns \ref status_codes
    594     */
    595     int16_t setBandwidth(float bw);
    596 
    597     /*!
    598       \brief Sets LoRa spreading factor. Allowed values range from 5 to 12.
    599 
    600       \param sf LoRa spreading factor to be set.
    601 
    602       \returns \ref status_codes
    603     */
    604     int16_t setSpreadingFactor(uint8_t sf);
    605 
    606     /*!
    607       \brief Sets LoRa coding rate denominator. Allowed values range from 5 to 8.
    608 
    609       \param cr LoRa coding rate denominator to be set.
    610 
    611       \param longInterleaving Whether to enable long interleaving mode. Not available for coding rate 4/7, defaults to false.
    612 
    613       \returns \ref status_codes
    614     */
    615     int16_t setCodingRate(uint8_t cr, bool longInterleaving = false);
    616 
    617     /*!
    618       \brief Sets output power. Allowed values are in range from -18 to 13 dBm.
    619 
    620       \param power Output power to be set in dBm.
    621 
    622       \returns \ref status_codes
    623     */
    624     int16_t setOutputPower(int8_t power);
    625 
    626     /*!
    627       \brief Sets preamble length for currently active modem. Allowed values range from 1 to 65535.
    628 
    629       \param preambleLength Preamble length to be set in symbols (LoRa) or bits (FSK/BLE/FLRC).
    630 
    631       \returns \ref status_codes
    632     */
    633     int16_t setPreambleLength(uint32_t preambleLength);
    634 
    635     /*!
    636       \brief Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem).
    637 
    638       \param br FSK/FLRC bit rate to be set in kbps.
    639 
    640       \returns \ref status_codes
    641     */
    642     int16_t setBitRate(uint16_t br);
    643 
    644     /*!
    645       \brief Sets FSK frequency deviation. Allowed values range from 0.0 to 3200.0 kHz.
    646 
    647       \param freqDev FSK frequency deviation to be set in kHz.
    648 
    649       \returns \ref status_codes
    650     */
    651     int16_t setFrequencyDeviation(float freqDev) override;
    652 
    653     /*!
    654       \brief Sets time-bandwidth product of Gaussian filter applied for shaping.
    655       Allowed values are RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
    656 
    657       \param sh Time-bandwidth product of Gaussian filter to be set.
    658 
    659       \returns \ref status_codes
    660     */
    661     int16_t setDataShaping(uint8_t sh) override;
    662 
    663     /*!
    664       \brief Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long
    665 
    666       \param syncWord Sync word to be set.
    667 
    668       \param len Sync word length in bytes.
    669 
    670       \returns \ref status_codes
    671     */
    672     int16_t setSyncWord(uint8_t* syncWord, uint8_t len);
    673 
    674     /*!
    675       \brief Sets LoRa sync word.
    676 
    677       \param syncWord LoRa sync word to be set.
    678 
    679       \param controlBits Undocumented control bits, required for compatibility purposes.
    680 
    681       \returns \ref status_codes
    682     */
    683     int16_t setSyncWord(uint8_t syncWord, uint8_t controlBits = 0x44);
    684 
    685     /*!
    686       \brief Sets CRC configuration.
    687 
    688       \param len CRC length in bytes, Allowed values are 1, 2 or 3, set to 0 to disable CRC.
    689 
    690       \param initial Initial CRC value. Defaults to 0x1D0F (CCIT CRC), not available for LoRa modem.
    691 
    692       \param polynomial Polynomial for CRC calculation. Defaults to 0x1021 (CCIT CRC), not available for LoRa or BLE modem.
    693 
    694       \returns \ref status_codes
    695     */
    696     int16_t setCRC(uint8_t len, uint32_t initial = 0x1D0F, uint16_t polynomial = 0x1021);
    697 
    698     /*!
    699       \brief Sets whitening parameters, not available for LoRa or FLRC modem.
    700 
    701       \param enabled Set to true to enable whitening.
    702 
    703       \returns \ref status_codes
    704     */
    705     int16_t setWhitening(bool enabled);
    706 
    707     /*!
    708       \brief Sets BLE access address.
    709 
    710       \param addr BLE access address.
    711 
    712       \returns \ref status_codes
    713     */
    714     int16_t setAccessAddress(uint32_t addr);
    715 
    716     /*!
    717       \brief Enables or disables receiver high sensitivity mode.
    718 
    719       \param True to enable and false to disable.
    720 
    721       \returns 0
    722     */
    723     int16_t setHighSensitivityMode(bool hsm = false);
    724 
    725     /*!
    726       \brief Enables or disables receiver manual gain control.
    727 
    728       \param gain Use 0 for automatic gain, 1 for minimum gain and up to 13 for maximum gain.
    729 
    730       \returns 0
    731     */
    732     int16_t setGainControl(uint8_t gain = 0);
    733 
    734     /*!
    735       \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
    736 
    737       \returns RSSI of the last received packet in dBm.
    738     */
    739     float getRSSI();
    740 
    741     /*!
    742       \brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem.
    743 
    744       \returns SNR of the last received packet in dB.
    745     */
    746     float getSNR();
    747 
    748     /*!
    749       \brief Gets frequency error of the latest received packet.
    750 
    751       \returns Frequency error in Hz.
    752     */
    753     float getFrequencyError();
    754 
    755     /*!
    756       \brief Query modem for the packet length of received payload.
    757 
    758       \param update Update received packet length. Will return cached value when set to false.
    759 
    760       \returns Length of last received packet in bytes.
    761     */
    762     size_t getPacketLength(bool update = true) override;
    763 
    764     /*!
    765       \brief Get expected time-on-air for a given size of payload.
    766 
    767       \param len Payload length in bytes.
    768 
    769       \returns Expected time-on-air in microseconds.
    770     */
    771     uint32_t getTimeOnAir(size_t len);
    772 
    773     /*!
    774       \brief Set implicit header mode for future reception/transmission.
    775 
    776       \returns \ref status_codes
    777     */
    778     int16_t implicitHeader(size_t len);
    779 
    780     /*!
    781       \brief Set explicit header mode for future reception/transmission.
    782 
    783       \param len Payload length in bytes.
    784 
    785       \returns \ref status_codes
    786     */
    787     int16_t explicitHeader();
    788 
    789     /*!
    790       \brief Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility.
    791 
    792       \param encoding Encoding to be used. Set to 0 for NRZ, and 2 for whitening.
    793 
    794       \returns \ref status_codes
    795     */
    796     int16_t setEncoding(uint8_t encoding) override;
    797 
    798     /*!
    799       \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.
    800       When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
    801 
    802       \param rxEn RX enable pin.
    803 
    804       \param txEn TX enable pin.
    805     */
    806     void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
    807 
    808     /*!
    809      \brief Dummy random method, to ensure PhysicalLayer compatibility.
    810 
    811      \returns Always returns 0.
    812    */
    813     uint8_t randomByte();
    814 
    815     #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
    816     /*!
    817       \brief Dummy method, to ensure PhysicalLayer compatibility.
    818 
    819       \param func Ignored.
    820     */
    821     void setDirectAction(void (*func)(void));
    822 
    823     /*!
    824       \brief Dummy method, to ensure PhysicalLayer compatibility.
    825 
    826       \param pin Ignored.
    827     */
    828     void readBit(RADIOLIB_PIN_TYPE pin);
    829     #endif
    830 
    831 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
    832   protected:
    833 #endif
    834     Module* _mod;
    835 
    836 #if !defined(RADIOLIB_GODMODE)
    837   protected:
    838 #endif
    839 
    840     // cached LoRa parameters
    841     float _bwKhz = 0;
    842     uint8_t _bw = 0, _sf = 0, _cr = 0;
    843     uint8_t _preambleLengthLoRa = 0, _headerType = 0, _payloadLen = 0, _crcLoRa = 0;
    844 
    845     // SX128x SPI command implementations
    846     uint8_t getStatus();
    847     int16_t writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
    848     int16_t readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
    849     int16_t writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00);
    850     int16_t readBuffer(uint8_t* data, uint8_t numBytes);
    851     int16_t setTx(uint16_t periodBaseCount = RADIOLIB_SX128X_TX_TIMEOUT_NONE, uint8_t periodBase = RADIOLIB_SX128X_PERIOD_BASE_15_625_US);
    852     int16_t setRx(uint16_t periodBaseCount, uint8_t periodBase = RADIOLIB_SX128X_PERIOD_BASE_15_625_US);
    853     int16_t setCad();
    854     uint8_t getPacketType();
    855     int16_t setRfFrequency(uint32_t frf);
    856     int16_t setTxParams(uint8_t power, uint8_t rampTime = RADIOLIB_SX128X_PA_RAMP_10_US);
    857     int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00);
    858     int16_t setModulationParams(uint8_t modParam1, uint8_t modParam2, uint8_t modParam3);
    859     int16_t setPacketParamsGFSK(uint8_t preambleLen, uint8_t syncWordLen, uint8_t syncWordMatch, uint8_t crcLen, uint8_t whitening, uint8_t payloadLen = 0xFF, uint8_t headerType = RADIOLIB_SX128X_GFSK_FLRC_PACKET_VARIABLE);
    860     int16_t setPacketParamsBLE(uint8_t connState, uint8_t crcLen, uint8_t bleTestPayload, uint8_t whitening);
    861     int16_t setPacketParamsLoRa(uint8_t preambleLen, uint8_t headerType, uint8_t payloadLen, uint8_t crc, uint8_t invertIQ = RADIOLIB_SX128X_LORA_IQ_STANDARD);
    862     int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = RADIOLIB_SX128X_IRQ_NONE, uint16_t dio3Mask = RADIOLIB_SX128X_IRQ_NONE);
    863     uint16_t getIrqStatus();
    864     int16_t clearIrqStatus(uint16_t clearIrqParams = RADIOLIB_SX128X_IRQ_ALL);
    865     int16_t setRangingRole(uint8_t role);
    866     int16_t setPacketType(uint8_t type);
    867 
    868     int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
    869 
    870 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
    871   private:
    872 #endif
    873 
    874     // common low-level SPI interface
    875     int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
    876     int16_t SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
    877     int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
    878     int16_t SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
    879     int16_t SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy, uint32_t timeout = 5000);
    880 
    881 #if !defined(RADIOLIB_GODMODE)
    882   private:
    883 #endif
    884     // common parameters
    885     uint8_t _pwr = 0;
    886 
    887     // cached GFSK parameters
    888     float _modIndexReal = 0;
    889     uint16_t _brKbps = 0;
    890     uint8_t _br = 0, _modIndex = 0, _shaping = 0;
    891     uint8_t _preambleLengthGFSK = 0, _syncWordLen = 0, _syncWordMatch = 0, _crcGFSK = 0, _whitening = 0;
    892 
    893     // cached FLRC parameters
    894     uint8_t _crFLRC = 0;
    895 
    896     // cached BLE parameters
    897     uint8_t _connectionState = 0, _crcBLE = 0, _bleTestPayload = 0;
    898 
    899     int16_t config(uint8_t modem);
    900 };
    901 
    902 #endif
    903 
    904 #endif