-
Notifications
You must be signed in to change notification settings - Fork 0
/
sx126x.h
1748 lines (1585 loc) · 57.8 KB
/
sx126x.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file sx126x.h
*
* @brief SX126x radio driver definition
*
* The Clear BSD License
* Copyright Semtech Corporation 2021. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the disclaimer
* below) provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Semtech corporation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
* THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SX126X_H
#define SX126X_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* -----------------------------------------------------------------------------
* --- DEPENDENCIES ------------------------------------------------------------
*/
#include <stdint.h>
#include <stdbool.h>
/*
* -----------------------------------------------------------------------------
* --- PUBLIC MACROS -----------------------------------------------------------
*/
/*
* -----------------------------------------------------------------------------
* --- PUBLIC CONSTANTS --------------------------------------------------------
*/
/**
* @brief Maximum value for parameter timeout_in_rtc_step in both functions @ref sx126x_set_rx_with_timeout_in_rtc_step
* and @ref sx126x_set_tx_with_timeout_in_rtc_step
*/
#define SX126X_MAX_TIMEOUT_IN_RTC_STEP 0x00FFFFFE
/**
* @brief Maximum value for parameter timeout_in_ms in both functions @ref sx126x_set_rx and @ref sx126x_set_tx
*/
#define SX126X_MAX_TIMEOUT_IN_MS ( SX126X_MAX_TIMEOUT_IN_RTC_STEP / 64 )
/**
* @brief Timeout parameter in \ref sx126x_set_rx_with_timeout_in_rtc_step to set the chip in reception until a
* reception occurs
*/
#define SX126X_RX_SINGLE_MODE 0x00000000
/**
* @brief Timeout parameter in @ref sx126x_set_rx_with_timeout_in_rtc_step to launch a continuous reception
*/
#define SX126X_RX_CONTINUOUS 0x00FFFFFF
/**
* @brief Over-current protection default value after @ref sx126x_set_pa_cfg is called with @ref device_sel set to 1
*/
#define SX126X_OCP_PARAM_VALUE_60_MA 0x18
/**
* @brief Over-current protection default value after @ref sx126x_set_pa_cfg is called with @ref device_sel set to 0
*/
#define SX126X_OCP_PARAM_VALUE_140_MA 0x38
/**
* @brief XTA and XTB trimming capacitor default value after the chip entered @ref SX126X_STANDBY_CFG_XOSC mode
*/
#define SX126X_XTAL_TRIMMING_CAPACITOR_DEFAULT_VALUE_STDBY_XOSC 0x12
/**
* @brief Maximum value for parameter nb_of_symbs in @ref sx126x_set_lora_symb_nb_timeout
*/
#define SX126X_MAX_LORA_SYMB_NUM_TIMEOUT 248
/**
* @brief Maximum number of register that can be added to the retention list
*/
#define SX126X_MAX_NB_REG_IN_RETENTION 4
/*!
* @brief Frequency step in MHz used to compute the image calibration parameter
*
* @see sx126x_cal_img_in_mhz
*/
#define SX126X_IMAGE_CALIBRATION_STEP_IN_MHZ 4
#define SX126X_CHIP_MODES_POS ( 4U )
#define SX126X_CHIP_MODES_MASK ( 0x07UL << SX126X_CHIP_MODES_POS )
#define SX126X_CMD_STATUS_POS ( 1U )
#define SX126X_CMD_STATUS_MASK ( 0x07UL << SX126X_CMD_STATUS_POS )
#define SX126X_GFSK_RX_STATUS_PKT_SENT_POS ( 0U )
#define SX126X_GFSK_RX_STATUS_PKT_SENT_MASK ( 0x01UL << SX126X_GFSK_RX_STATUS_PKT_SENT_POS )
#define SX126X_GFSK_RX_STATUS_PKT_RECEIVED_POS ( 1U )
#define SX126X_GFSK_RX_STATUS_PKT_RECEIVED_MASK ( 0x01UL << SX126X_GFSK_RX_STATUS_PKT_RECEIVED_POS )
#define SX126X_GFSK_RX_STATUS_ABORT_ERROR_POS ( 2U )
#define SX126X_GFSK_RX_STATUS_ABORT_ERROR_MASK ( 0x01UL << SX126X_GFSK_RX_STATUS_ABORT_ERROR_POS )
#define SX126X_GFSK_RX_STATUS_LENGTH_ERROR_POS ( 3U )
#define SX126X_GFSK_RX_STATUS_LENGTH_ERROR_MASK ( 0x01UL << SX126X_GFSK_RX_STATUS_LENGTH_ERROR_POS )
#define SX126X_GFSK_RX_STATUS_CRC_ERROR_POS ( 4U )
#define SX126X_GFSK_RX_STATUS_CRC_ERROR_MASK ( 0x01UL << SX126X_GFSK_RX_STATUS_CRC_ERROR_POS )
#define SX126X_GFSK_RX_STATUS_ADRS_ERROR_POS ( 5U )
#define SX126X_GFSK_RX_STATUS_ADRS_ERROR_MASK ( 0x01UL << SX126X_GFSK_RX_STATUS_ADRS_ERROR_POS )
/*!
* \brief Ramp-up delay for the power amplifier
*
* This parameter configures the delay to fine tune the ramp-up time of the power amplifier for BPSK operation.
*/
enum
{
SX126X_SIGFOX_DBPSK_RAMP_UP_TIME_DEFAULT = 0x0000, //!< No optimization
SX126X_SIGFOX_DBPSK_RAMP_UP_TIME_100_BPS = 0x370F, //!< Ramp-up optimization for 100bps
SX126X_SIGFOX_DBPSK_RAMP_UP_TIME_600_BPS = 0x092F, //!< Ramp-up optimization for 600bps
};
/*!
* \brief Ramp-down delay for the power amplifier
*
* This parameter configures the delay to fine tune the ramp-down time of the power amplifier for BPSK operation.
*/
enum
{
SX126X_SIGFOX_DBPSK_RAMP_DOWN_TIME_DEFAULT = 0x0000, //!< No optimization
SX126X_SIGFOX_DBPSK_RAMP_DOWN_TIME_100_BPS = 0x1D70, //!< Ramp-down optimization for 100bps
SX126X_SIGFOX_DBPSK_RAMP_DOWN_TIME_600_BPS = 0x04E1, //!< Ramp-down optimization for 600bps
};
/*
* -----------------------------------------------------------------------------
* --- PUBLIC TYPES ------------------------------------------------------------
*/
/**
* @brief SX126X APIs return status enumeration definition
*/
typedef enum sx126x_status_e
{
SX126X_STATUS_OK = 0,
SX126X_STATUS_UNSUPPORTED_FEATURE,
SX126X_STATUS_UNKNOWN_VALUE,
SX126X_STATUS_ERROR,
} sx126x_status_t;
/**
* @brief SX126X sleep mode configurations definition
*/
typedef enum sx126x_sleep_cfgs_e
{
SX126X_SLEEP_CFG_COLD_START = ( 0 << 2 ),
SX126X_SLEEP_CFG_WARM_START = ( 1 << 2 ),
} sx126x_sleep_cfgs_t;
/**
* @brief SX126X standby modes enumeration definition
*/
typedef enum sx126x_standby_cfgs_e
{
SX126X_STANDBY_CFG_RC = 0x00,
SX126X_STANDBY_CFG_XOSC = 0x01,
} sx126x_standby_cfgs_t;
typedef uint8_t sx126x_standby_cfg_t;
/**
* @brief SX126X power regulator modes enumeration definition
*/
typedef enum sx126x_reg_mods_e
{
SX126X_REG_MODE_LDO = 0x00, // default
SX126X_REG_MODE_DCDC = 0x01,
} sx126x_reg_mod_t;
/**
* @brief SX126X power amplifier configuration parameters structure definition
*/
typedef struct sx126x_pa_cfg_params_s
{
uint8_t pa_duty_cycle;
uint8_t hp_max;
uint8_t device_sel;
uint8_t pa_lut;
} sx126x_pa_cfg_params_t;
/**
* @brief SX126X fallback modes enumeration definition
*/
typedef enum sx126x_fallback_modes_e
{
SX126X_FALLBACK_STDBY_RC = 0x20,
SX126X_FALLBACK_STDBY_XOSC = 0x30,
SX126X_FALLBACK_FS = 0x40,
} sx126x_fallback_modes_t;
/**
* @brief SX126X interrupt masks enumeration definition
*/
enum sx126x_irq_masks_e
{
SX126X_IRQ_NONE = ( 0 << 0 ),
SX126X_IRQ_TX_DONE = ( 1 << 0 ),
SX126X_IRQ_RX_DONE = ( 1 << 1 ),
SX126X_IRQ_PREAMBLE_DETECTED = ( 1 << 2 ),
SX126X_IRQ_SYNC_WORD_VALID = ( 1 << 3 ),
SX126X_IRQ_HEADER_VALID = ( 1 << 4 ),
SX126X_IRQ_HEADER_ERROR = ( 1 << 5 ),
SX126X_IRQ_CRC_ERROR = ( 1 << 6 ),
SX126X_IRQ_CAD_DONE = ( 1 << 7 ),
SX126X_IRQ_CAD_DETECTED = ( 1 << 8 ),
SX126X_IRQ_TIMEOUT = ( 1 << 9 ),
SX126X_IRQ_LR_FHSS_HOP = ( 1 << 14 ),
SX126X_IRQ_ALL = SX126X_IRQ_TX_DONE | SX126X_IRQ_RX_DONE | SX126X_IRQ_PREAMBLE_DETECTED |
SX126X_IRQ_SYNC_WORD_VALID | SX126X_IRQ_HEADER_VALID | SX126X_IRQ_HEADER_ERROR |
SX126X_IRQ_CRC_ERROR | SX126X_IRQ_CAD_DONE | SX126X_IRQ_CAD_DETECTED | SX126X_IRQ_TIMEOUT |
SX126X_IRQ_LR_FHSS_HOP,
};
typedef uint16_t sx126x_irq_mask_t;
/**
* @brief Calibration settings
*/
enum sx126x_cal_mask_e
{
SX126X_CAL_RC64K = ( 1 << 0 ),
SX126X_CAL_RC13M = ( 1 << 1 ),
SX126X_CAL_PLL = ( 1 << 2 ),
SX126X_CAL_ADC_PULSE = ( 1 << 3 ),
SX126X_CAL_ADC_BULK_N = ( 1 << 4 ),
SX126X_CAL_ADC_BULK_P = ( 1 << 5 ),
SX126X_CAL_IMAGE = ( 1 << 6 ),
SX126X_CAL_ALL = SX126X_CAL_RC64K | SX126X_CAL_RC13M | SX126X_CAL_PLL | SX126X_CAL_ADC_PULSE |
SX126X_CAL_ADC_BULK_N | SX126X_CAL_ADC_BULK_P | SX126X_CAL_IMAGE,
};
typedef uint8_t sx126x_cal_mask_t;
/**
* @brief SX126X TCXO control voltages enumeration definition
*/
typedef enum sx126x_tcxo_ctrl_voltages_e
{
SX126X_TCXO_CTRL_1_6V = 0x00,
SX126X_TCXO_CTRL_1_7V = 0x01,
SX126X_TCXO_CTRL_1_8V = 0x02,
SX126X_TCXO_CTRL_2_2V = 0x03,
SX126X_TCXO_CTRL_2_4V = 0x04,
SX126X_TCXO_CTRL_2_7V = 0x05,
SX126X_TCXO_CTRL_3_0V = 0x06,
SX126X_TCXO_CTRL_3_3V = 0x07,
} sx126x_tcxo_ctrl_voltages_t;
/**
* @brief SX126X packet types enumeration definition
*/
typedef enum sx126x_pkt_types_e
{
SX126X_PKT_TYPE_GFSK = 0x00,
SX126X_PKT_TYPE_LORA = 0x01,
SX126X_PKT_TYPE_BPSK = 0x02,
SX126X_PKT_TYPE_LR_FHSS = 0x03,
} sx126x_pkt_type_t;
/**
* @brief SX126X power amplifier ramp-up timings enumeration definition
*/
typedef enum sx126x_ramp_time_e
{
SX126X_RAMP_10_US = 0x00,
SX126X_RAMP_20_US = 0x01,
SX126X_RAMP_40_US = 0x02,
SX126X_RAMP_80_US = 0x03,
SX126X_RAMP_200_US = 0x04,
SX126X_RAMP_800_US = 0x05,
SX126X_RAMP_1700_US = 0x06,
SX126X_RAMP_3400_US = 0x07,
} sx126x_ramp_time_t;
/**
* @brief SX126X GFSK modulation shaping enumeration definition
*/
typedef enum sx126x_gfsk_pulse_shape_e
{
SX126X_GFSK_PULSE_SHAPE_OFF = 0x00,
SX126X_GFSK_PULSE_SHAPE_BT_03 = 0x08,
SX126X_GFSK_PULSE_SHAPE_BT_05 = 0x09,
SX126X_GFSK_PULSE_SHAPE_BT_07 = 0x0A,
SX126X_GFSK_PULSE_SHAPE_BT_1 = 0x0B,
} sx126x_gfsk_pulse_shape_t;
/**
* @brief SX126X BPSK modulation shaping enumeration definition
*/
typedef enum
{
SX126X_DBPSK_PULSE_SHAPE = 0x16, //!< Double OSR / RRC / BT 0.7
} sx126x_bpsk_pulse_shape_t;
/**
* @brief SX126X GFSK Rx bandwidth enumeration definition
*/
typedef enum sx126x_gfsk_bw_e
{
SX126X_GFSK_BW_4800 = 0x1F,
SX126X_GFSK_BW_5800 = 0x17,
SX126X_GFSK_BW_7300 = 0x0F,
SX126X_GFSK_BW_9700 = 0x1E,
SX126X_GFSK_BW_11700 = 0x16,
SX126X_GFSK_BW_14600 = 0x0E,
SX126X_GFSK_BW_19500 = 0x1D,
SX126X_GFSK_BW_23400 = 0x15,
SX126X_GFSK_BW_29300 = 0x0D,
SX126X_GFSK_BW_39000 = 0x1C,
SX126X_GFSK_BW_46900 = 0x14,
SX126X_GFSK_BW_58600 = 0x0C,
SX126X_GFSK_BW_78200 = 0x1B,
SX126X_GFSK_BW_93800 = 0x13,
SX126X_GFSK_BW_117300 = 0x0B,
SX126X_GFSK_BW_156200 = 0x1A,
SX126X_GFSK_BW_187200 = 0x12,
SX126X_GFSK_BW_234300 = 0x0A,
SX126X_GFSK_BW_312000 = 0x19,
SX126X_GFSK_BW_373600 = 0x11,
SX126X_GFSK_BW_467000 = 0x09,
} sx126x_gfsk_bw_t;
/**
* @brief SX126X GFSK modulation parameters structure definition
*/
typedef struct sx126x_mod_params_gfsk_s
{
uint32_t br_in_bps;
uint32_t fdev_in_hz;
sx126x_gfsk_pulse_shape_t pulse_shape;
sx126x_gfsk_bw_t bw_dsb_param;
} sx126x_mod_params_gfsk_t;
/**
* @brief Modulation configuration for BPSK packet
*/
typedef struct sx126x_mod_params_bpsk_s
{
uint32_t br_in_bps; //!< BPSK bitrate [bit/s]
sx126x_bpsk_pulse_shape_t pulse_shape; //!< BPSK pulse shape
} sx126x_mod_params_bpsk_t;
/**
* @brief SX126X LoRa spreading factor enumeration definition
*/
typedef enum sx126x_lora_sf_e
{
SX126X_LORA_SF5 = 0x05,
SX126X_LORA_SF6 = 0x06,
SX126X_LORA_SF7 = 0x07,
SX126X_LORA_SF8 = 0x08,
SX126X_LORA_SF9 = 0x09,
SX126X_LORA_SF10 = 0x0A,
SX126X_LORA_SF11 = 0x0B,
SX126X_LORA_SF12 = 0x0C,
} sx126x_lora_sf_t;
/**
* @brief SX126X LoRa bandwidth enumeration definition
*/
typedef enum sx126x_lora_bw_e
{
SX126X_LORA_BW_500 = 6,
SX126X_LORA_BW_250 = 5,
SX126X_LORA_BW_125 = 4,
SX126X_LORA_BW_062 = 3,
SX126X_LORA_BW_041 = 10,
SX126X_LORA_BW_031 = 2,
SX126X_LORA_BW_020 = 9,
SX126X_LORA_BW_015 = 1,
SX126X_LORA_BW_010 = 8,
SX126X_LORA_BW_007 = 0,
} sx126x_lora_bw_t;
/**
* @brief SX126X LoRa coding rate enumeration definition
*/
typedef enum sx126x_lora_cr_e
{
SX126X_LORA_CR_4_5 = 0x01,
SX126X_LORA_CR_4_6 = 0x02,
SX126X_LORA_CR_4_7 = 0x03,
SX126X_LORA_CR_4_8 = 0x04,
} sx126x_lora_cr_t;
/**
* @brief SX126X LoRa modulation parameters structure definition
*/
typedef struct sx126x_mod_params_lora_s
{
sx126x_lora_sf_t sf; //!< LoRa Spreading Factor
sx126x_lora_bw_t bw; //!< LoRa Bandwidth
sx126x_lora_cr_t cr; //!< LoRa Coding Rate
uint8_t ldro; //!< Low DataRate Optimization configuration
} sx126x_mod_params_lora_t;
/**
* @brief SX126X GFSK preamble length Rx detection size enumeration definition
*/
typedef enum sx126x_gfsk_preamble_detector_e
{
SX126X_GFSK_PREAMBLE_DETECTOR_OFF = 0x00,
SX126X_GFSK_PREAMBLE_DETECTOR_MIN_8BITS = 0x04,
SX126X_GFSK_PREAMBLE_DETECTOR_MIN_16BITS = 0x05,
SX126X_GFSK_PREAMBLE_DETECTOR_MIN_24BITS = 0x06,
SX126X_GFSK_PREAMBLE_DETECTOR_MIN_32BITS = 0x07,
} sx126x_gfsk_preamble_detector_t;
/**
* @brief SX126X GFSK address filtering configuration enumeration definition
*/
typedef enum sx126x_gfsk_address_filtering_e
{
SX126X_GFSK_ADDRESS_FILTERING_DISABLE = 0x00,
SX126X_GFSK_ADDRESS_FILTERING_NODE_ADDRESS = 0x01,
SX126X_GFSK_ADDRESS_FILTERING_NODE_AND_BROADCAST_ADDRESSES = 0x02,
} sx126x_gfsk_address_filtering_t;
/**
* @brief SX126X GFSK packet length enumeration definition
*/
typedef enum sx126x_gfsk_pkt_len_modes_e
{
SX126X_GFSK_PKT_FIX_LEN = 0x00, //!< The packet length is known on both sides, no header included
SX126X_GFSK_PKT_VAR_LEN = 0x01, //!< The packet length is variable, header included
} sx126x_gfsk_pkt_len_modes_t;
/**
* @brief SX126X GFSK CRC type enumeration definition
*/
typedef enum sx126x_gfsk_crc_types_e
{
SX126X_GFSK_CRC_OFF = 0x01,
SX126X_GFSK_CRC_1_BYTE = 0x00,
SX126X_GFSK_CRC_2_BYTES = 0x02,
SX126X_GFSK_CRC_1_BYTE_INV = 0x04,
SX126X_GFSK_CRC_2_BYTES_INV = 0x06,
} sx126x_gfsk_crc_types_t;
/**
* @brief SX126X GFSK whitening control enumeration definition
*/
typedef enum sx126x_gfsk_dc_free_e
{
SX126X_GFSK_DC_FREE_OFF = 0x00,
SX126X_GFSK_DC_FREE_WHITENING = 0x01,
} sx126x_gfsk_dc_free_t;
/**
* @brief SX126X LoRa packet length enumeration definition
*/
typedef enum sx126x_lora_pkt_len_modes_e
{
SX126X_LORA_PKT_EXPLICIT = 0x00, //!< Header included in the packet
SX126X_LORA_PKT_IMPLICIT = 0x01, //!< Header not included in the packet
} sx126x_lora_pkt_len_modes_t;
/**
* @brief SX126X LoRa packet parameters structure definition
*/
typedef struct sx126x_pkt_params_lora_s
{
uint16_t preamble_len_in_symb; //!< Preamble length in symbols
sx126x_lora_pkt_len_modes_t header_type; //!< Header type
uint8_t pld_len_in_bytes; //!< Payload length in bytes
bool crc_is_on; //!< CRC activation
bool invert_iq_is_on; //!< IQ polarity setup
} sx126x_pkt_params_lora_t;
/**
* @brief SX126X GFSK packet parameters structure definition
*/
typedef struct sx126x_pkt_params_gfsk_s
{
uint16_t preamble_len_in_bits; //!< Preamble length in bits
sx126x_gfsk_preamble_detector_t preamble_detector; //!< Preamble detection length
uint8_t sync_word_len_in_bits; //!< Sync word length in bits
sx126x_gfsk_address_filtering_t address_filtering; //!< Address filtering configuration
sx126x_gfsk_pkt_len_modes_t header_type; //!< Header type
uint8_t pld_len_in_bytes; //!< Payload length in bytes
sx126x_gfsk_crc_types_t crc_type; //!< CRC type configuration
sx126x_gfsk_dc_free_t dc_free; //!< Whitening configuration
} sx126x_pkt_params_gfsk_t;
/**
* @brief SX126X BPSK packet parameters structure definition
*/
typedef struct sx126x_pkt_params_bpsk_s
{
uint8_t pld_len_in_bytes; //!< Payload length [bytes]
uint16_t ramp_up_delay; //!< Delay to fine tune ramp-up time, if non-zero
uint16_t ramp_down_delay; //!< Delay to fine tune ramp-down time, if non-zero
uint16_t pld_len_in_bits; //!< If non-zero, used to ramp down PA before end of a payload with length that is not a
//!< multiple of 8
} sx126x_pkt_params_bpsk_t;
/**
* @brief SX126X LoRa CAD number of symbols enumeration definition
*
* @note Represents the number of symbols to be used for a CAD operation
*/
typedef enum sx126x_cad_symbs_e
{
SX126X_CAD_01_SYMB = 0x00,
SX126X_CAD_02_SYMB = 0x01,
SX126X_CAD_04_SYMB = 0x02,
SX126X_CAD_08_SYMB = 0x03,
SX126X_CAD_16_SYMB = 0x04,
} sx126x_cad_symbs_t;
/**
* @brief SX126X LoRa CAD exit modes enumeration definition
*
* @note Represents the action to be performed after a CAD is done
*/
typedef enum sx126x_cad_exit_modes_e
{
SX126X_CAD_ONLY = 0x00,
SX126X_CAD_RX = 0x01,
SX126X_CAD_LBT = 0x10,
} sx126x_cad_exit_modes_t;
/**
* @brief SX126X CAD parameters structure definition
*/
typedef struct sx126x_cad_param_s
{
sx126x_cad_symbs_t cad_symb_nb; //!< CAD number of symbols
uint8_t cad_detect_peak; //!< CAD peak detection
uint8_t cad_detect_min; //!< CAD minimum detection
sx126x_cad_exit_modes_t cad_exit_mode; //!< CAD exit mode
uint32_t cad_timeout; //!< CAD timeout value
} sx126x_cad_params_t;
/**
* @brief SX126X chip mode enumeration definition
*/
typedef enum sx126x_chip_modes_e
{
SX126X_CHIP_MODE_UNUSED = 0,
SX126X_CHIP_MODE_RFU = 1,
SX126X_CHIP_MODE_STBY_RC = 2,
SX126X_CHIP_MODE_STBY_XOSC = 3,
SX126X_CHIP_MODE_FS = 4,
SX126X_CHIP_MODE_RX = 5,
SX126X_CHIP_MODE_TX = 6,
} sx126x_chip_modes_t;
/**
* @brief SX126X command status enumeration definition
*/
typedef enum sx126x_cmd_status_e
{
SX126X_CMD_STATUS_RESERVED = 0,
SX126X_CMD_STATUS_RFU = 1,
SX126X_CMD_STATUS_DATA_AVAILABLE = 2,
SX126X_CMD_STATUS_CMD_TIMEOUT = 3,
SX126X_CMD_STATUS_CMD_PROCESS_ERROR = 4,
SX126X_CMD_STATUS_CMD_EXEC_FAILURE = 5,
SX126X_CMD_STATUS_CMD_TX_DONE = 6,
} sx126x_cmd_status_t;
/**
* @brief SX126X chip status structure definition
*/
typedef struct sx126x_chip_status_s
{
sx126x_cmd_status_t cmd_status; //!< Previous command status
sx126x_chip_modes_t chip_mode; //!< Current chip mode
} sx126x_chip_status_t;
/**
* @brief SX126X RX buffer status structure definition
*/
typedef struct sx126x_rx_buffer_status_s
{
uint8_t pld_len_in_bytes; //!< Number of bytes available in the buffer
uint8_t buffer_start_pointer; //!< Position of the first byte in the buffer
} sx126x_rx_buffer_status_t;
typedef struct sx126x_rx_status_gfsk_s
{
bool pkt_sent;
bool pkt_received;
bool abort_error;
bool length_error;
bool crc_error;
bool adrs_error;
} sx126x_rx_status_gfsk_t;
/**
* @brief SX126X GFSK packet status structure definition
*/
typedef struct sx126x_pkt_status_gfsk_s
{
sx126x_rx_status_gfsk_t rx_status;
int8_t rssi_sync; //!< The RSSI measured on last packet
int8_t rssi_avg; //!< The averaged RSSI
} sx126x_pkt_status_gfsk_t;
/**
* @brief SX126X LoRa packet status structure definition
*/
typedef struct sx126x_pkt_status_lora_s
{
int8_t rssi_pkt_in_dbm; //!< RSSI of the last packet
int8_t snr_pkt_in_db; //!< SNR of the last packet
int8_t signal_rssi_pkt_in_dbm; //!< Estimation of RSSI (after despreading)
} sx126x_pkt_status_lora_t;
/**
* @brief SX126X GFSK reception statistics structure definition
*/
typedef struct sx126x_stats_gfsk_s
{
uint16_t nb_pkt_received;
uint16_t nb_pkt_crc_error;
uint16_t nb_pkt_len_error;
} sx126x_stats_gfsk_t;
/**
* @brief SX126X LoRa reception statistics structure definition
*/
typedef struct sx126x_stats_lora_s
{
uint16_t nb_pkt_received;
uint16_t nb_pkt_crc_error;
uint16_t nb_pkt_header_error;
} sx126x_stats_lora_t;
/**
* @brief SX126X errors enumeration definition
*/
enum sx126x_errors_e
{
SX126X_ERRORS_RC64K_CALIBRATION = ( 1 << 0 ),
SX126X_ERRORS_RC13M_CALIBRATION = ( 1 << 1 ),
SX126X_ERRORS_PLL_CALIBRATION = ( 1 << 2 ),
SX126X_ERRORS_ADC_CALIBRATION = ( 1 << 3 ),
SX126X_ERRORS_IMG_CALIBRATION = ( 1 << 4 ),
SX126X_ERRORS_XOSC_START = ( 1 << 5 ),
SX126X_ERRORS_PLL_LOCK = ( 1 << 6 ),
SX126X_ERRORS_PA_RAMP = ( 1 << 8 ),
};
typedef uint16_t sx126x_errors_mask_t;
/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
*/
//
// Operational Modes Functions
//
/**
* @brief Set the chip in sleep mode
*
* @param [in] context Chip implementation context
* @param [in] cfg Sleep mode configuration
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_sleep( const void* context, const sx126x_sleep_cfgs_t cfg );
/**
* @brief Set the chip in stand-by mode
*
* @param [in] context Chip implementation context
* @param [in] cfg Stand-by mode configuration
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_standby( const void* context, const sx126x_standby_cfg_t cfg );
/**
* @brief Set the chip in frequency synthesis mode
*
* @param [in] context Chip implementation context
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_fs( const void* context );
/**
* @brief Set the chip in transmission mode
*
* @remark The packet type shall be configured with @ref sx126x_set_pkt_type before using this command.
*
* @remark By default, the chip returns automatically to standby RC mode as soon as the packet is sent or if the packet
* has not been completely transmitted before the timeout. This behavior can be altered by @ref
* sx126x_set_rx_tx_fallback_mode.
*
* @remark If the timeout argument is 0, then no timeout is used.
*
* @param [in] context Chip implementation context
* @param [in] timeout_in_ms The timeout configuration in millisecond for Tx operation
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_tx( const void* context, const uint32_t timeout_in_ms );
/**
* @brief Set the chip in transmission mode
*
* @remark The packet type shall be configured with @ref sx126x_set_pkt_type before using this command.
*
* @remark By default, the chip returns automatically to standby RC mode as soon as the packet is sent or if the packet
* has not been completely transmitted before the timeout. This behavior can be altered by @ref
* sx126x_set_rx_tx_fallback_mode.
*
* @remark The timeout duration can be computed with the formula:
* \f$ timeout\_duration\_ms = timeout_in_rtc_step \times * \frac{1}{64} \f$
*
* @remark Maximal value is SX126X_MAX_TIMEOUT_IN_RTC_STEP (i.e. 262 143 ms)
*
* @remark If the timeout argument is 0, then no timeout is used.
*
* @param [in] context Chip implementation context
* @param [in] timeout_in_rtc_step The timeout configuration for Tx operation
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_tx_with_timeout_in_rtc_step( const void* context, const uint32_t timeout_in_rtc_step );
/**
* @brief Set the chip in reception mode
*
* @remark The packet type shall be configured with @ref sx126x_set_pkt_type before using this command.
*
* @remark By default, the chip returns automatically to standby RC mode as soon as a packet is received
* or if no packet has been received before the timeout. This behavior can be altered by @ref
* sx126x_set_rx_tx_fallback_mode.
*
* @remark The timeout argument can have the following special values:
*
* | Special values | Meaning |
* | ----------------------| --------------------------------------------------------------------------------------|
* | SX126X_RX_SINGLE_MODE | Single: the chip stays in RX mode until a reception occurs, then switch to standby RC |
*
* @remark Refer to @ref sx126x_handle_rx_done
*
* @param [in] context Chip implementation context
* @param [in] timeout_in_ms The timeout configuration in millisecond for Rx operation
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_rx( const void* context, const uint32_t timeout_in_ms );
/**
* @brief Set the chip in reception mode
*
* @remark The packet type shall be configured with @ref sx126x_set_pkt_type before using this command.
*
* @remark By default, the chip returns automatically to standby RC mode as soon as a packet is received
* or if no packet has been received before the timeout. This behavior can be altered by @ref
* sx126x_set_rx_tx_fallback_mode.
*
* @remark The timeout duration is obtained by:
* \f$ timeout\_duration\_ms = timeout_in_rtc_step \times \frac{1}{64} \f$
*
* @remark Maximal timeout value is SX126X_MAX_TIMEOUT_IN_RTC_STEP (i.e. 262 143 ms).
*
* @remark The timeout argument can have the following special values:
*
* | Special values | Meaning |
* | ----------------------| --------------------------------------------------------------------------------------|
* | SX126X_RX_SINGLE_MODE | Single: the chip stays in RX mode until a reception occurs, then switch to standby RC |
* | SX126X_RX_CONTINUOUS | Continuous: the chip stays in RX mode even after reception of a packet |
*
* @remark Refer to @ref sx126x_handle_rx_done
*
* @param [in] context Chip implementation context
* @param [in] timeout_in_rtc_step The timeout configuration for Rx operation
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_rx_with_timeout_in_rtc_step( const void* context, const uint32_t timeout_in_rtc_step );
/**
* @brief Configure the event on which the Rx timeout is stopped
*
* @remark The two options are:
* - Syncword / Header detection (default)
* - Preamble detection
*
* @param [in] context Chip implementation context
* @param [in] enable If true, the timer stops on Syncword / Header detection
*
* @returns Operation status
*/
sx126x_status_t sx126x_stop_timer_on_preamble( const void* context, const bool enable );
/**
* @brief Set the chip in reception mode with duty cycling
*
* @param [in] context Chip implementation context
* @param [in] rx_time_in_ms The timeout of Rx period - in millisecond
* @param [in] sleep_time_in_ms The length of sleep period - in millisecond
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_rx_duty_cycle( const void* context, const uint32_t rx_time_in_ms,
const uint32_t sleep_time_in_ms );
/**
* @brief Set the chip in reception mode with duty cycling
*
* @remark The Rx mode duration is defined by:
* \f$ rx\_duration\_ms = rx_time \times \frac{1}{64} \f$
*
* @remark The sleep mode duration is defined by:
* \f$ sleep\_duration\_ms = sleep_time \times \frac{1}{64} \f$
*
* @remark Maximal timeout value is 0xFFFFFF (i.e. 511 seconds).
*
* @param [in] context Chip implementation context
* @param [in] rx_time The timeout of Rx period
* @param [in] sleep_time The length of sleep period
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_rx_duty_cycle_with_timings_in_rtc_step( const void* context,
const uint32_t rx_time_in_rtc_step,
const uint32_t sleep_time_in_rtc_step );
/**
* @brief Set the chip in CAD (Channel Activity Detection) mode
*
* @remark The LoRa packet type shall be selected with @ref sx126x_set_pkt_type before this function is called.
*
* @remark The fallback mode is configured with @ref sx126x_set_cad_params.
*
* @param [in] context Chip implementation context
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_cad( const void* context );
/**
* @brief Set the chip in Tx continuous wave (RF tone).
*
* @remark The packet type shall be configured with @ref sx126x_set_pkt_type before using this command.
*
* @param [in] context Chip implementation context
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_tx_cw( const void* context );
/**
* @brief Set the chip in Tx infinite preamble (modulated signal).
*
* @remark The packet type shall be configured with @ref sx126x_set_pkt_type before using this command.
*
* @param [in] context Chip implementation context
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_tx_infinite_preamble( const void* context );
/**
* @brief Configure the regulator mode to be used
*
* @remark This function shall be called to set the correct regulator mode, depending on the usage of LDO or DC/DC on
* the PCB implementation.
*
* @param [in] context Chip implementation context
* @param [in] mode Regulator mode configuration
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_reg_mode( const void* context, const sx126x_reg_mod_t mode );
/**
* @brief Perform the calibration of the requested blocks
*
* @remark This function shall only be called in stand-by RC mode
*
* @remark The chip will return to stand-by RC mode on exit. Potential calibration issues can be read out with @ref
* sx126x_get_device_errors command.
*
* @param [in] context Chip implementation context
* @param [in] param Mask holding the blocks to be calibrated
*
* @returns Operation status
*/
sx126x_status_t sx126x_cal( const void* context, const sx126x_cal_mask_t param );
/**
* @brief Launch an image calibration valid for all frequencies inside an interval, in steps
*
* @param [in] context Chip implementation context
* @param [in] freq1 Image calibration interval lower bound, in steps
* @param [in] freq2 Image calibration interval upper bound, in steps
*
* @remark freq1 must be less than or equal to freq2
*
* @returns Operation status
*/
sx126x_status_t sx126x_cal_img( const void* context, const uint8_t freq1, const uint8_t freq2 );
/**
* @brief Launch an image calibration valid for all frequencies inside an interval, in MHz
*
* @param [in] context Chip implementation context
* @param [in] freq1_in_mhz Image calibration interval lower bound, in MHz
* @param [in] freq2_in_mhz Image calibration interval upper bound, in MHz
*
* @remark freq1_in_mhz must be less than or equal to freq2_in_mhz
*
* @returns Operation status
*/
sx126x_status_t sx126x_cal_img_in_mhz( const void* context, const uint16_t freq1_in_mhz, const uint16_t freq2_in_mhz );
/**
* @brief Configure the PA (Power Amplifier)
*
* @remark The parameters depend on the chip being used
*
* @param [in] context Chip implementation context
* @param [in] params Power amplifier configuration parameters
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_pa_cfg( const void* context, const sx126x_pa_cfg_params_t* params );
/**
* @brief Set chip mode to be used after successful transmission or reception.
*
* @remark This setting is not taken into account during Rx Duty Cycle mode or Auto TxRx.
*
* @param [in] context Chip implementation context
* @param [in] fallback_mode Selected fallback mode
*
* @returns Operation status
*/
sx126x_status_t sx126x_set_rx_tx_fallback_mode( const void* context, const sx126x_fallback_modes_t fallback_mode );
//
// Registers and Buffer Access
//
/**
* @brief Write data into register memory space.
*
* @param [in] context Chip implementation context
* @param [in] address The register memory address to start writing operation
* @param [in] buffer The buffer of bytes to write into memory
* @param [in] size Number of bytes to write into memory, starting from address
*
* @returns Operation status
*
* @see sx126x_read_register
*/
sx126x_status_t sx126x_write_register( const void* context, const uint16_t address, const uint8_t* buffer,
const uint8_t size );
/**
* @brief Read data from register memory space.
*
* @param [in] context Chip implementation context