55#define SX126X_XTAL_FREQ 32000000UL
60#define SX126X_RTC_FREQ_IN_HZ 64000UL
65#define SX126X_PLL_STEP_SHIFT_AMOUNT (14)
70#define SX126X_PLL_STEP_SCALED (SX126X_XTAL_FREQ >> (25 - SX126X_PLL_STEP_SHIFT_AMOUNT))
82 SX126X_SET_SLEEP = 0x84,
83 SX126X_SET_STANDBY = 0x80,
87 SX126X_SET_STOP_TIMER_ON_PREAMBLE = 0x9F,
88 SX126X_SET_RX_DUTY_CYCLE = 0x94,
89 SX126X_SET_CAD = 0xC5,
90 SX126X_SET_TX_CONTINUOUS_WAVE = 0xD1,
91 SX126X_SET_TX_INFINITE_PREAMBLE = 0xD2,
92 SX126X_SET_REGULATOR_MODE = 0x96,
93 SX126X_CALIBRATE = 0x89,
94 SX126X_CALIBRATE_IMAGE = 0x98,
95 SX126X_SET_PA_CFG = 0x95,
96 SX126X_SET_RX_TX_FALLBACK_MODE = 0x93,
98 SX126X_WRITE_REGISTER = 0x0D,
99 SX126X_READ_REGISTER = 0x1D,
100 SX126X_WRITE_BUFFER = 0x0E,
101 SX126X_READ_BUFFER = 0x1E,
103 SX126X_SET_DIO_IRQ_PARAMS = 0x08,
104 SX126X_GET_IRQ_STATUS = 0x12,
105 SX126X_CLR_IRQ_STATUS = 0x02,
106 SX126X_SET_DIO2_AS_RF_SWITCH_CTRL = 0x9D,
107 SX126X_SET_DIO3_AS_TCXO_CTRL = 0x97,
109 SX126X_SET_RF_FREQUENCY = 0x86,
110 SX126X_SET_PKT_TYPE = 0x8A,
111 SX126X_GET_PKT_TYPE = 0x11,
112 SX126X_SET_TX_PARAMS = 0x8E,
113 SX126X_SET_MODULATION_PARAMS = 0x8B,
114 SX126X_SET_PKT_PARAMS = 0x8C,
115 SX126X_SET_CAD_PARAMS = 0x88,
116 SX126X_SET_BUFFER_BASE_ADDRESS = 0x8F,
117 SX126X_SET_LORA_SYMB_NUM_TIMEOUT = 0xA0,
119 SX126X_GET_STATUS = 0xC0,
120 SX126X_GET_RX_BUFFER_STATUS = 0x13,
121 SX126X_GET_PKT_STATUS = 0x14,
122 SX126X_GET_RSSI_INST = 0x15,
123 SX126X_GET_STATS = 0x10,
124 SX126X_RESET_STATS = 0x00,
126 SX126X_GET_DEVICE_ERRORS = 0x17,
127 SX126X_CLR_DEVICE_ERRORS = 0x07,
135 SX126X_SIZE_SET_SLEEP = 2,
136 SX126X_SIZE_SET_STANDBY = 2,
137 SX126X_SIZE_SET_FS = 1,
138 SX126X_SIZE_SET_TX = 4,
139 SX126X_SIZE_SET_RX = 4,
140 SX126X_SIZE_SET_STOP_TIMER_ON_PREAMBLE = 2,
141 SX126X_SIZE_SET_RX_DUTY_CYCLE = 7,
142 SX126X_SIZE_SET_CAD = 1,
143 SX126X_SIZE_SET_TX_CONTINUOUS_WAVE = 1,
144 SX126X_SIZE_SET_TX_INFINITE_PREAMBLE = 1,
145 SX126X_SIZE_SET_REGULATOR_MODE = 2,
146 SX126X_SIZE_CALIBRATE = 2,
147 SX126X_SIZE_CALIBRATE_IMAGE = 3,
148 SX126X_SIZE_SET_PA_CFG = 5,
149 SX126X_SIZE_SET_RX_TX_FALLBACK_MODE = 2,
152 SX126X_SIZE_WRITE_REGISTER = 3,
154 SX126X_SIZE_READ_REGISTER = 4,
156 SX126X_SIZE_WRITE_BUFFER = 2,
158 SX126X_SIZE_READ_BUFFER = 3,
160 SX126X_SIZE_SET_DIO_IRQ_PARAMS = 9,
161 SX126X_SIZE_GET_IRQ_STATUS = 2,
162 SX126X_SIZE_CLR_IRQ_STATUS = 3,
163 SX126X_SIZE_SET_DIO2_AS_RF_SWITCH_CTRL = 2,
164 SX126X_SIZE_SET_DIO3_AS_TCXO_CTRL = 5,
166 SX126X_SIZE_SET_RF_FREQUENCY = 5,
167 SX126X_SIZE_SET_PKT_TYPE = 2,
168 SX126X_SIZE_GET_PKT_TYPE = 3,
169 SX126X_SIZE_SET_TX_PARAMS = 3,
170 SX126X_SIZE_SET_MODULATION_PARAMS_GFSK = 9,
171 SX126X_SIZE_SET_MODULATION_PARAMS_LORA = 5,
172 SX126X_SIZE_SET_PKT_PARAMS_GFSK = 10,
173 SX126X_SIZE_SET_PKT_PARAMS_LORA = 7,
174 SX126X_SIZE_SET_CAD_PARAMS = 8,
175 SX126X_SIZE_SET_BUFFER_BASE_ADDRESS = 3,
176 SX126X_SIZE_SET_LORA_SYMB_NUM_TIMEOUT = 2,
178 SX126X_SIZE_GET_STATUS = 1,
179 SX126X_SIZE_GET_RX_BUFFER_STATUS = 2,
180 SX126X_SIZE_GET_PKT_STATUS = 2,
181 SX126X_SIZE_GET_RSSI_INST = 2,
182 SX126X_SIZE_GET_STATS = 2,
183 SX126X_SIZE_RESET_STATS = 7,
185 SX126X_SIZE_GET_DEVICE_ERRORS = 2,
186 SX126X_SIZE_CLR_DEVICE_ERRORS = 3,
187 SX126X_SIZE_MAX_BUFFER = 255,
188 SX126X_SIZE_DUMMY_BYTE = 1,
249 uint8_t buf[SX126X_SIZE_SET_STANDBY] = { 0 };
251 buf[0] = SX126X_SET_STANDBY;
253 buf[1] = (uint8_t)cfg;
260 return SX126X_STATUS_UNKNOWN_VALUE;
269 uint8_t buf[SX126X_SIZE_SET_TX] = { 0 };
271 buf[0] = SX126X_SET_TX;
273 buf[1] = (uint8_t)(timeout_in_rtc_step >> 16);
274 buf[2] = (uint8_t)(timeout_in_rtc_step >> 8);
275 buf[3] = (uint8_t)(timeout_in_rtc_step >> 0);
282 return SX126X_STATUS_UNKNOWN_VALUE;
291 uint8_t buf[SX126X_SIZE_SET_RX] = { 0 };
293 buf[0] = SX126X_SET_RX;
295 buf[1] = (uint8_t)(timeout_in_rtc_step >> 16);
296 buf[2] = (uint8_t)(timeout_in_rtc_step >> 8);
297 buf[3] = (uint8_t)(timeout_in_rtc_step >> 0);
303 const uint32_t rx_time_in_rtc_step,
304 const uint32_t sleep_time_in_rtc_step) {
305 uint8_t buf[SX126X_SIZE_SET_RX_DUTY_CYCLE] = { 0 };
307 buf[0] = SX126X_SET_RX_DUTY_CYCLE;
309 buf[1] = (uint8_t)(rx_time_in_rtc_step >> 16);
310 buf[2] = (uint8_t)(rx_time_in_rtc_step >> 8);
311 buf[3] = (uint8_t)(rx_time_in_rtc_step >> 0);
313 buf[4] = (uint8_t)(sleep_time_in_rtc_step >> 16);
314 buf[5] = (uint8_t)(sleep_time_in_rtc_step >> 8);
315 buf[6] = (uint8_t)(sleep_time_in_rtc_step >> 0);
321 uint8_t buf[SX126X_SIZE_SET_CAD] = { 0 };
323 buf[0] = SX126X_SET_CAD;
329 uint8_t buf[SX126X_SIZE_SET_REGULATOR_MODE] = { 0 };
331 buf[0] = SX126X_SET_REGULATOR_MODE;
333 buf[1] = (uint8_t)mode;
339 uint8_t buf[SX126X_SIZE_CALIBRATE] = { 0 };
341 buf[0] = SX126X_CALIBRATE;
349 uint8_t buf[SX126X_SIZE_CALIBRATE_IMAGE] = { 0 };
351 buf[0] = SX126X_CALIBRATE_IMAGE;
353 if (freq_in_hz > 900000000) {
356 }
else if (freq_in_hz > 850000000) {
359 }
else if (freq_in_hz > 770000000) {
362 }
else if (freq_in_hz > 460000000) {
374 uint8_t buf[SX126X_SIZE_SET_PA_CFG] = { 0 };
376 buf[0] = SX126X_SET_PA_CFG;
378 buf[1] = params->pa_duty_cycle;
379 buf[2] = params->hp_max;
380 buf[3] = params->device_sel;
381 buf[4] = params->pa_lut;
387 uint8_t buf[SX126X_SIZE_SET_RX_TX_FALLBACK_MODE] = { 0 };
389 buf[0] = SX126X_SET_RX_TX_FALLBACK_MODE;
391 buf[1] = (uint8_t)fallback_mode;
401 const uint8_t size) {
402 uint8_t buf[SX126X_SIZE_WRITE_REGISTER] = { 0 };
404 buf[0] = SX126X_WRITE_REGISTER;
406 buf[1] = (uint8_t)(address >> 8);
407 buf[2] = (uint8_t)(address >> 0);
413 uint8_t buf[SX126X_SIZE_READ_REGISTER] = { 0 };
416 buf[0] = SX126X_READ_REGISTER;
418 buf[1] = (uint8_t)(address >> 8);
419 buf[2] = (uint8_t)(address >> 0);
427 const uint8_t size) {
428 uint8_t buf[SX126X_SIZE_WRITE_BUFFER] = { 0 };
430 buf[0] = SX126X_WRITE_BUFFER;
438 uint8_t buf[SX126X_SIZE_READ_BUFFER] = { 0 };
441 buf[0] = SX126X_READ_BUFFER;
454 const uint16_t dio2_mask,
const uint16_t dio3_mask) {
455 uint8_t buf[SX126X_SIZE_SET_DIO_IRQ_PARAMS] = { 0 };
457 buf[0] = SX126X_SET_DIO_IRQ_PARAMS;
459 buf[1] = (uint8_t)(irq_mask >> 8);
460 buf[2] = (uint8_t)(irq_mask >> 0);
462 buf[3] = (uint8_t)(dio1_mask >> 8);
463 buf[4] = (uint8_t)(dio1_mask >> 0);
465 buf[5] = (uint8_t)(dio2_mask >> 8);
466 buf[6] = (uint8_t)(dio2_mask >> 0);
468 buf[7] = (uint8_t)(dio3_mask >> 8);
469 buf[8] = (uint8_t)(dio3_mask >> 0);
475 uint8_t buf[SX126X_SIZE_GET_IRQ_STATUS] = { 0 };
476 uint8_t irq_local[
sizeof(sx126x_irq_mask_t)] = { 0x00 };
479 buf[0] = SX126X_GET_IRQ_STATUS;
482 sizeof(sx126x_irq_mask_t));
484 if (status == SX126X_STATUS_OK) {
485 *irq = ((sx126x_irq_mask_t)irq_local[0] << 8) + ((sx126x_irq_mask_t)irq_local[1] << 0);
492 uint8_t buf[SX126X_SIZE_CLR_IRQ_STATUS] = { 0 };
494 buf[0] = SX126X_CLR_IRQ_STATUS;
496 buf[1] = (uint8_t)(irq_mask >> 8);
497 buf[2] = (uint8_t)(irq_mask >> 0);
503 sx126x_irq_mask_t sx126x_irq_mask = SX126X_IRQ_NONE;
507 if ((status == SX126X_STATUS_OK) && (sx126x_irq_mask != 0)) {
510 if ((status == SX126X_STATUS_OK) && (irq != NULL)) {
511 *irq = sx126x_irq_mask;
517 uint8_t buf[SX126X_SIZE_SET_DIO2_AS_RF_SWITCH_CTRL] = { 0 };
519 buf[0] = SX126X_SET_DIO2_AS_RF_SWITCH_CTRL;
521 buf[1] = (enable ==
true) ? 1 : 0;
527 const uint32_t timeout) {
528 uint8_t buf[SX126X_SIZE_SET_DIO3_AS_TCXO_CTRL] = { 0 };
530 buf[0] = SX126X_SET_DIO3_AS_TCXO_CTRL;
532 buf[1] = (uint8_t)tcxo_voltage;
534 buf[2] = (uint8_t)(timeout >> 16);
535 buf[3] = (uint8_t)(timeout >> 8);
536 buf[4] = (uint8_t)(timeout >> 0);
552 uint8_t buf[SX126X_SIZE_SET_RF_FREQUENCY] = { 0 };
554 buf[0] = SX126X_SET_RF_FREQUENCY;
556 buf[1] = (uint8_t)(freq >> 24);
557 buf[2] = (uint8_t)(freq >> 16);
558 buf[3] = (uint8_t)(freq >> 8);
559 buf[4] = (uint8_t)(freq >> 0);
565 uint8_t buf[SX126X_SIZE_SET_PKT_TYPE] = { 0 };
567 buf[0] = SX126X_SET_PKT_TYPE;
569 buf[1] = (uint8_t)pkt_type;
575 uint8_t buf[SX126X_SIZE_GET_PKT_TYPE] = { 0 };
577 uint8_t pkt_type_raw;
579 buf[0] = SX126X_GET_PKT_TYPE;
588 uint8_t buf[SX126X_SIZE_SET_TX_PARAMS] = { 0 };
590 buf[0] = SX126X_SET_TX_PARAMS;
592 buf[1] = (uint8_t)pwr_in_dbm;
593 buf[2] = (uint8_t)ramp_time;
603 uint8_t buf[SX126X_SIZE_SET_MODULATION_PARAMS_LORA] = { 0 };
605 buf[0] = SX126X_SET_MODULATION_PARAMS;
607 buf[1] = (uint8_t)(params->
sf);
608 buf[2] = (uint8_t)(params->
bw);
609 buf[3] = (uint8_t)(params->
cr);
610 buf[4] = params->
ldro & 0x01;
614 if (status == SX126X_STATUS_OK) {
616 status = sx126x_tx_modulation_workaround(nctx, SX126X_PKT_TYPE_LORA, params->
bw);
627 uint8_t buf[SX126X_SIZE_SET_PKT_PARAMS_LORA] = { 0 };
629 buf[0] = SX126X_SET_PKT_PARAMS;
635 buf[5] = (uint8_t)(params->
crc_is_on ? 1 : 0);
641 if (status == SX126X_STATUS_OK) {
642 uint8_t reg_value = 0;
645 if (status == SX126X_STATUS_OK) {
647 reg_value &= ~(1 << 2);
649 reg_value |= (1 << 2);
660 uint8_t buf[SX126X_SIZE_SET_CAD_PARAMS] = { 0 };
662 buf[0] = SX126X_SET_CAD_PARAMS;
676 const uint8_t rx_base_address) {
677 uint8_t buf[SX126X_SIZE_SET_BUFFER_BASE_ADDRESS] = { 0 };
679 buf[0] = SX126X_SET_BUFFER_BASE_ADDRESS;
681 buf[1] = tx_base_address;
682 buf[2] = rx_base_address;
688 uint8_t buf[SX126X_SIZE_SET_LORA_SYMB_NUM_TIMEOUT] = { 0 };
691 buf[0] = SX126X_SET_LORA_SYMB_NUM_TIMEOUT;
693 buf[1] = nb_of_symbs;
697 if ((status == SX126X_STATUS_OK) && (nb_of_symbs >= 64)) {
698 uint8_t mant = nb_of_symbs >> 1;
707 reg = exp + (mant << 3);
719 uint8_t buf[SX126X_SIZE_GET_STATUS] = { 0 };
720 uint8_t status_local = 0;
723 buf[0] = SX126X_GET_STATUS;
727 if (status == SX126X_STATUS_OK) {
738 uint8_t buf[SX126X_SIZE_GET_RX_BUFFER_STATUS] = { 0 };
742 buf[0] = SX126X_GET_RX_BUFFER_STATUS;
747 if (status == SX126X_STATUS_OK) {
756 uint8_t buf[SX126X_SIZE_GET_PKT_STATUS] = { 0 };
760 buf[0] = SX126X_GET_PKT_STATUS;
765 if (status == SX126X_STATUS_OK) {
767 pkt_status->
snr_pkt_in_db = (((int8_t)pkt_status_local[1]) + 2) >> 2;
775 uint8_t buf[SX126X_SIZE_GET_RSSI_INST] = { 0 };
776 uint8_t rssi_local = 0x00;
779 buf[0] = SX126X_GET_RSSI_INST;
783 if (status == SX126X_STATUS_OK) {
784 *rssi_in_dbm = (int8_t)(-rssi_local >> 1);
792 uint8_t buf[SX126X_SIZE_GET_STATS] = { 0 };
796 buf[0] = SX126X_GET_STATS;
801 if (status == SX126X_STATUS_OK) {
802 stats->nb_pkt_received = ((uint16_t)stats_local[0] << 8) + (uint16_t)stats_local[1];
803 stats->nb_pkt_crc_error = ((uint16_t)stats_local[2] << 8) + (uint16_t)stats_local[3];
804 stats->nb_pkt_header_error = ((uint16_t)stats_local[4] << 8) + (uint16_t)stats_local[5];
810 uint8_t buf[SX126X_SIZE_RESET_STATS] = { 0 };
812 buf[0] = SX126X_RESET_STATS;
826 uint8_t buf[SX126X_SIZE_GET_DEVICE_ERRORS] = { 0 };
827 uint8_t errors_local[
sizeof(sx126x_errors_mask_t)] = { 0x00 };
830 buf[0] = SX126X_GET_DEVICE_ERRORS;
833 sizeof(sx126x_errors_mask_t));
835 if (status == SX126X_STATUS_OK) {
836 *errors = ((sx126x_errors_mask_t)errors_local[0] << 8) + ((sx126x_errors_mask_t)errors_local[1] << 0);
843 uint8_t buf[SX126X_SIZE_CLR_DEVICE_ERRORS] = { 0 };
845 buf[0] = SX126X_CLR_DEVICE_ERRORS;
851 uint32_t bw_in_hz = 0;
854 case SX126X_LORA_BW_007:
857 case SX126X_LORA_BW_010:
860 case SX126X_LORA_BW_015:
863 case SX126X_LORA_BW_020:
866 case SX126X_LORA_BW_031:
869 case SX126X_LORA_BW_041:
872 case SX126X_LORA_BW_062:
875 case SX126X_LORA_BW_125:
878 case SX126X_LORA_BW_250:
881 case SX126X_LORA_BW_500:
892 const int32_t sf = mod_p->
sf;
894 const int32_t cr_denom = mod_p->
cr + 4;
896 int32_t ceil_denominator;
897 int32_t ceil_numerator =
898 (pld_len_in_bytes << 3) + (pkt_p->
crc_is_on ? 16 : 0) - (4 * sf) + (pld_is_fix ? 0 : 20);
901 ceil_denominator = 4 * sf;
906 ceil_denominator = 4 * (sf - 2);
908 ceil_denominator = 4 * sf;
912 if (ceil_numerator < 0) {
918 ((ceil_numerator + ceil_denominator - 1) / ceil_denominator) * cr_denom + pkt_p->
preamble_len_in_symb + 12;
924 return (uint32_t)((4 * intermed + 1) * (1 << (sf - 2)));
933 return (numerator + denominator - 1) / denominator;
939 uint8_t tmp_ana_lna = 0x00;
940 uint8_t tmp_ana_mixer = 0x00;
945 if (status != SX126X_STATUS_OK) {
948 tmp = tmp_ana_lna & ~(1 << 0);
950 if (status != SX126X_STATUS_OK) {
955 if (status != SX126X_STATUS_OK) {
958 tmp = tmp_ana_mixer & ~(1 << 7);
960 if (status != SX126X_STATUS_OK) {
966 if (status != SX126X_STATUS_OK) {
971 for (
unsigned int i = 0; i < n; i++) {
973 if (status != SX126X_STATUS_OK) {
979 if (status != SX126X_STATUS_OK) {
985 if (status != SX126X_STATUS_OK) {
1016 if (state ==
true) {
1025 uint8_t buffer[2] = { 0x00 };
1029 if (status == SX126X_STATUS_OK) {
1030 buffer[0] = (buffer[0] & ~0xF0) + (sync_word & 0xF0);
1031 buffer[1] = (buffer[1] & ~0xF0) + ((sync_word & 0x0F) << 4);
1043 uint8_t reg_value = 0x00;
1047 if (status == SX126X_STATUS_OK) {
1048 reg_value |= SX126X_REG_TX_CLAMP_CFG_MASK;
1062 uint8_t reg_value = 0;
1066 if (status == SX126X_STATUS_OK) {
1067 if (pkt_type == SX126X_PKT_TYPE_LORA) {
1068 if (bw == SX126X_LORA_BW_500) {
1069 reg_value &= ~(1 << 2);
1071 reg_value |= (1 << 2);
1074 reg_value |= (1 << 2);
SX126X CAD parameters structure definition.
sx126x_cad_symbs_t cad_symb_nb
CAD number of symbols.
sx126x_cad_exit_modes_t cad_exit_mode
CAD exit mode.
uint8_t cad_detect_min
CAD minimum detection.
uint8_t cad_detect_peak
CAD peak detection.
uint32_t cad_timeout
CAD timeout value.
SX126X chip status structure definition.
sx126x_chip_modes_t chip_mode
Current chip mode.
sx126x_cmd_status_t cmd_status
Previous command status.
SX126X LoRa modulation parameters structure definition.
sx126x_lora_sf_t sf
LoRa Spreading Factor.
sx126x_lora_cr_t cr
LoRa Coding Rate.
uint8_t ldro
Low DataRate Optimization configuration.
sx126x_lora_bw_t bw
LoRa Bandwidth.
SX126X power amplifier configuration parameters structure definition.
SX126X LoRa packet parameters structure definition.
uint16_t preamble_len_in_symb
Preamble length in symbols.
bool crc_is_on
CRC activation.
bool invert_iq_is_on
IQ polarity setup.
uint8_t pld_len_in_bytes
Payload length in bytes.
sx126x_lora_pkt_len_modes_t header_type
Header type.
SX126X LoRa packet status structure definition.
int8_t signal_rssi_pkt_in_dbm
Estimation of RSSI (after despreading)
int8_t rssi_pkt_in_dbm
RSSI of the last packet.
int8_t snr_pkt_in_db
SNR of the last packet.
SX126X RX buffer status structure definition.
uint8_t buffer_start_pointer
Position of the first byte in the buffer.
uint8_t pld_len_in_bytes
Number of bytes available in the buffer.
SX126X LoRa reception statistics structure definition.
sx126x_status_t sx126x_set_rf_freq_in_pll_steps(struct network_context *nctx, const uint32_t freq)
Set the RF frequency for future radio operations - parameter in PLL steps.
#define SX126X_RTC_FREQ_IN_HZ
Internal frequency of the radio.
#define SX126X_PLL_STEP_SCALED
PLL step - scaled with SX126X_PLL_STEP_SHIFT_AMOUNT.
sx126x_status_t sx126x_set_dio3_as_tcxo_ctrl(struct network_context *nctx, const sx126x_tcxo_ctrl_voltages_t tcxo_voltage, const uint32_t timeout)
Configure the embedded TCXO switch control.
sx126x_status_t sx126x_set_rx_with_timeout_in_rtc_step(struct network_context *nctx, const uint32_t timeout_in_rtc_step)
Set the chip in reception mode.
sx126x_status_t sx126x_get_rssi_inst(struct network_context *nctx, int16_t *rssi_in_dbm)
Get the instantaneous RSSI value.
sx126x_status_t sx126x_set_pkt_type(struct network_context *nctx, const sx126x_pkt_type_t pkt_type)
Set the packet type.
sx126x_status_t sx126x_cfg_rx_boosted(struct network_context *nctx, const bool state)
Configure the boost mode in reception.
sx126x_status_t sx126x_set_rx_tx_fallback_mode(struct network_context *nctx, const sx126x_fallback_modes_t fallback_mode)
Set chip mode to be used after successful transmission or reception.
sx126x_status_t sx126x_set_pa_cfg(struct network_context *nctx, const sx126x_pa_cfg_params_t *params)
Configure the PA (Power Amplifier)
sx126x_status_t sx126x_set_standby(struct network_context *nctx, const sx126x_standby_cfg_t cfg)
Set the chip in stand-by mode.
sx126x_status_t sx126x_get_lora_pkt_status(struct network_context *nctx, sx126x_pkt_status_lora_t *pkt_status)
Get the status of the last LoRa packet received.
sx126x_status_t sx126x_get_status(struct network_context *nctx, sx126x_chip_status_t *radio_status)
Get the chip status.
sx126x_status_t sx126x_set_lora_mod_params(struct network_context *nctx, const sx126x_mod_params_lora_t *params)
Set the modulation parameters for LoRa packets.
sx126x_status_t sx126x_set_rf_freq(struct network_context *nctx, const uint32_t freq_in_hz)
Set the RF frequency for future radio operations.
sx126x_status_t sx126x_set_tx(struct network_context *nctx, const uint32_t timeout_in_ms)
Set the chip in transmission mode.
enum sx126x_commands_size_e sx126x_commands_size_t
uint32_t sx126x_get_lora_bw_in_hz(sx126x_lora_bw_t bw)
Get the actual value in Hertz of a given LoRa bandwidth.
sx126x_status_t sx126x_read_register(struct network_context *nctx, const uint16_t address, uint8_t *buffer, const uint8_t size)
Read data from register memory space.
uint32_t sx126x_convert_timeout_in_ms_to_rtc_step(uint32_t timeout_in_ms)
Get the number of RTC steps for a given timeout in millisecond.
sx126x_status_t sx126x_cfg_tx_clamp(struct network_context *nctx)
Configure the Tx PA clamp.
sx126x_status_t sx126x_get_irq_status(struct network_context *nctx, sx126x_irq_mask_t *irq)
Get system interrupt status.
enum sx126x_commands_e sx126x_commands_t
sx126x_status_t sx126x_reset_stats(struct network_context *nctx)
Reset all the statistics for both Lora and GFSK communications.
sx126x_status_t sx126x_write_register(struct network_context *nctx, const uint16_t address, const uint8_t *buffer, const uint8_t size)
Write data into register memory space.
sx126x_status_t sx126x_set_reg_mode(struct network_context *nctx, const sx126x_reg_mod_t mode)
Configure the regulator mode to be used.
sx126x_status_t sx126x_cal_img(struct network_context *nctx, const uint32_t freq_in_hz)
Perform device operating frequency band image rejection calibration.
sx126x_status_t sx126x_get_device_errors(struct network_context *nctx, sx126x_errors_mask_t *errors)
Get the list of all active errors.
uint32_t sx126x_get_lora_time_on_air_in_ms(const sx126x_pkt_params_lora_t *pkt_p, const sx126x_mod_params_lora_t *mod_p)
Get the time on air in ms for LoRa transmission.
sx126x_status_t sx126x_cal(struct network_context *nctx, const sx126x_cal_mask_t param)
Perform the calibration of the requested blocks.
sx126x_status_t sx126x_get_pkt_type(struct network_context *nctx, sx126x_pkt_type_t *pkt_type)
Get the current packet type.
sx126x_status_t sx126x_get_and_clear_irq_status(struct network_context *nctx, sx126x_irq_mask_t *irq)
Clears any radio irq status flags that are set and returns the flags that were cleared.
sx126x_status_t sx126x_reset(struct network_context *nctx)
Perform a hard reset of the chip.
sx126x_status_t sx126x_set_rx_duty_cycle_with_timings_in_rtc_step(struct network_context *nctx, const uint32_t rx_time_in_rtc_step, const uint32_t sleep_time_in_rtc_step)
Set the chip in reception mode with duty cycling.
sx126x_status_t sx126x_write_buffer(struct network_context *nctx, const uint8_t offset, const uint8_t *buffer, const uint8_t size)
Write data into radio Tx buffer memory space.
sx126x_status_t sx126x_read_buffer(struct network_context *nctx, const uint8_t offset, uint8_t *buffer, const uint8_t size)
Read data from radio Rx buffer memory space.
sx126x_status_t sx126x_get_rx_buffer_status(struct network_context *nctx, sx126x_rx_buffer_status_t *rx_buffer_status)
Get the current Rx buffer status for both LoRa and GFSK Rx operations.
sx126x_status_t sx126x_set_dio_irq_params(struct network_context *nctx, const uint16_t irq_mask, const uint16_t dio1_mask, const uint16_t dio2_mask, const uint16_t dio3_mask)
Set which interrupt signals are redirected to the dedicated DIO pin.
sx126x_status_t sx126x_clear_device_errors(struct network_context *nctx)
Clear all active errors.
sx126x_status_t sx126x_set_dio2_as_rf_sw_ctrl(struct network_context *nctx, const bool enable)
Configure the embedded RF switch control.
sx126x_status_t sx126x_get_random_numbers(struct network_context *nctx, uint32_t *numbers, unsigned int n)
Generate one or more 32-bit random numbers.
sx126x_status_t sx126x_set_buffer_base_address(struct network_context *nctx, const uint8_t tx_base_address, const uint8_t rx_base_address)
Set buffer start addresses for both Tx and Rx operations.
uint32_t sx126x_convert_freq_in_hz_to_pll_step(uint32_t freq_in_hz)
Get the number of PLL steps for a given frequency in Hertz.
sx126x_status_t sx126x_set_tx_params(struct network_context *nctx, const int8_t pwr_in_dbm, const sx126x_ramp_time_t ramp_time)
Set the parameters for TX power and power amplifier ramp time.
sx126x_status_t sx126x_get_lora_stats(struct network_context *nctx, sx126x_stats_lora_t *stats)
Get the statistics about LoRa communication.
uint32_t sx126x_get_lora_time_on_air_numerator(const sx126x_pkt_params_lora_t *pkt_p, const sx126x_mod_params_lora_t *mod_p)
Compute the numerator for LoRa time-on-air computation.
sx126x_status_t sx126x_set_cad(struct network_context *nctx)
Set the chip in CAD (Channel Activity Detection) mode.
#define SX126X_PLL_STEP_SHIFT_AMOUNT
Scaling factor used to perform fixed-point operations.
sx126x_status_t sx126x_set_lora_pkt_params(struct network_context *nctx, const sx126x_pkt_params_lora_t *params)
Set the packet parameters for LoRa packets.
sx126x_status_t sx126x_set_rx(struct network_context *nctx, const uint32_t timeout_in_ms)
Set the chip in reception mode.
sx126x_status_t sx126x_set_lora_sync_word(struct network_context *nctx, const uint8_t sync_word)
Configure the sync word used in LoRa packet.
sx126x_status_t sx126x_set_cad_params(struct network_context *nctx, const sx126x_cad_params_t *params)
Set the parameters for CAD operation.
sx126x_status_t sx126x_set_tx_with_timeout_in_rtc_step(struct network_context *nctx, const uint32_t timeout_in_rtc_step)
Set the chip in transmission mode.
sx126x_status_t sx126x_clear_irq_status(struct network_context *nctx, const sx126x_irq_mask_t irq_mask)
Clear selected system interrupts.
SX126x radio driver definition.
enum sx126x_lora_bw_e sx126x_lora_bw_t
SX126X LoRa bandwidth enumeration definition.
enum sx126x_cmd_status_e sx126x_cmd_status_t
SX126X command status enumeration definition.
enum sx126x_status_e sx126x_status_t
SX126X APIs return status enumeration definition.
#define SX126X_MAX_TIMEOUT_IN_MS
Maximum value for parameter timeout_in_ms in both functions sx126x_set_rx and sx126x_set_tx.
enum sx126x_pkt_types_e sx126x_pkt_type_t
SX126X packet types enumeration definition.
enum sx126x_ramp_time_e sx126x_ramp_time_t
SX126X power amplifier ramp-up timings enumeration definition.
enum sx126x_chip_modes_e sx126x_chip_modes_t
SX126X chip mode enumeration definition.
enum sx126x_tcxo_ctrl_voltages_e sx126x_tcxo_ctrl_voltages_t
SX126X TCXO control voltages enumeration definition.
@ SX126X_LORA_PKT_IMPLICIT
Header not included in the packet.
enum sx126x_fallback_modes_e sx126x_fallback_modes_t
SX126X fallback modes enumeration definition.
struct sx126x_rx_buffer_status_s sx126x_rx_buffer_status_t
SX126X RX buffer status structure definition.
struct sx126x_stats_lora_s sx126x_stats_lora_t
SX126X LoRa reception statistics structure definition.
enum sx126x_reg_mods_e sx126x_reg_mod_t
SX126X power regulator modes enumeration definition.
struct sx126x_pkt_status_lora_s sx126x_pkt_status_lora_t
SX126X LoRa packet status structure definition.
Hardware Abstraction Layer for SX126x.
sx126x_hal_status_t sx126x_hal_reset(struct network_context *nctx)
sx126x_hal_status_t sx126x_hal_write(struct network_context *nctx, const uint8_t *command, const uint16_t command_length, const uint8_t *data, const uint16_t data_length)
sx126x_hal_status_t sx126x_hal_read(struct network_context *nctx, const uint8_t *command, const uint16_t command_length, uint8_t *data, const uint16_t data_length)
SX126x register definitions.
#define SX126X_REG_RXGAIN
#define SX126X_REG_IRQ_POLARITY
WORKAROUND - Optimizing the Inverted IQ Operation, see DS_SX1261-2_V1.2 datasheet chapter 15....
#define SX126X_REG_LR_SYNCWORD
The addresses of the register holding LoRa Modem SyncWord value 0x1424: LoRaWAN private network,...
#define SX126X_REG_TX_CLAMP_CFG
WORKAROUND - Better resistance to antenna mismatch, see DS_SX1261-2_V1.2 datasheet chapter 15....
#define SX126X_REG_RNGBASEADDRESS
#define SX126X_REG_ANA_LNA
#define SX126X_REG_TX_MODULATION
WORKAROUND - Modulation Quality with 500 kHz LoRa Bandwidth, see DS_SX1261-2_V1.2 datasheet chapter 1...
#define SX126X_REG_ANA_MIXER
#define SX126X_REG_LR_SYNCH_TIMEOUT
Number of symbols given as SX126X_REG_LR_SYNCH_TIMEOUT[7:3] * 2 ^ (2*SX126X_REG_LR_SYNCH_TIMEOUT[2:0]...