upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
sx1276.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Thanks to Semtech for their example code at:
6  * https://github.com/Lora-net/LoRaMac-node
7  * released under a modified BSD license, for many clues as to how to
8  * initialize and operate this radio properly.
9  * See src/sx1276/LICENSE.txt
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  */
30 
31 #pragma once
32 
33 #include <string>
34 
35 #include <sys/time.h>
36 #include <sys/select.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <pthread.h>
40 
41 #include <mraa/common.hpp>
42 #include <mraa/spi.hpp>
43 #include <mraa/gpio.hpp>
44 
45 // Our crystal oscillator frequency (32Mhz)
46 #define FXOSC_FREQ 32000000.0
47 
48 // Our freq stepping resolution (in Hz) if FXOSC_FREQ is 32Mhz
49 // (FXOSC_FREQ / 2^19) =
50 #define FXOSC_STEP 61.03515625
51 
52 namespace upm {
53 
90  class SX1276 {
91  public:
92 
93  // The default chip revision
94  static const uint8_t chipRevision = 0x12;
95 
96 
97  // total FIFO size
98  static const int FIFO_SIZE = 256;
99 
100  // differentiator between high and low bands
101  static const int RF_MID_BAND_THRESH = 525000000;
102 
103  // LoRa RSSI offsets depending on LF or HF bands
104  static const int LOR_RSSI_OFFSET_HF = -157;
105  static const int LOR_RSSI_OFFSET_LF = -164;
106 
110  typedef enum {
111  MODEM_LORA = 0,
112  MODEM_FSK
113  } RADIO_MODEM_T;
114 
128  typedef enum {
129  REVENT_DONE = 0, // operation completed successfully
130  REVENT_EXEC, // runninsg something
131  REVENT_ERROR, // failed, crc error, sync timeout
132  REVENT_TIMEOUT // timed out
133  } RADIO_EVENT_T;
134 
147  typedef enum {
148  COM_RegFifo = 0x00, // FIFO r/w access
149  COM_RegOpMode = 0x01, // LoRa/FSK
150 
151  FSK_RegBitrateMsb = 0x02,
152  LOR_Reserved02 = 0x02, // reserved
153 
154  FSK_RegBitrateLsb = 0x03,
155  LOR_Reserved03 = 0x03, // reserved
156 
157  FSK_RegFdevMsb = 0x04, // freq deviation
158  LOR_Reserved04 = 0x04, // reserved
159 
160  FSK_RegFdevLsb = 0x05,
161  LOR_Reserved05 = 0x05, // reserved
162 
163  COM_RegFrfMsb = 0x06, // carrier freq
164  COM_RegFrfMid = 0x07,
165  COM_RegFrfLsb = 0x08,
166  COM_RegPaConfig = 0x09,
167  COM_RegPaRamp = 0x0a,
168 
169  COM_RegOcp = 0x0b, // overcurrent protection
170  COM_RegLna = 0x0c,
171 
172  FSK_RegRxConfig = 0x0d,
173  LOR_RegFifoAddrPtr = 0x0d,
174 
175  FSK_RegRssiConfg = 0x0e,
176  LOR_RegFifoTxBaseAddr = 0x0e,
177 
178  FSK_RegRssiCollision = 0x0f,
179  LOR_RegFifoRxBaseAddr = 0x0f,
180 
181  FSK_RegRssiThresh = 0x10,
182  LOR_RegFifoRxCurrentAddr = 0x10,
183 
184  FSK_RegRssiValue = 0x11,
185  LOR_RegIrqFlagsMask = 0x11,
186 
187  FSK_RegRxBw = 0x12,
188  LOR_RegIrqFlags = 0x12,
189 
190  FSK_RegAfcBw = 0x13, // automatic freq cntrl
191  LOR_RegRxNbBytes = 0x13, // received pkt len
192 
193  FSK_RegOokPeak = 0x14,
194  LOR_RegRxHeaderCntValueMsb = 0x14,
195 
196  FSK_RegOokFix = 0x15,
197  LOR_RegRxHeaderCntValueLsb = 0x15,
198 
199  FSK_RegOokAvg = 0x16,
200  LOR_RegRxPacketCntValueMsb = 0x16,
201 
202  FSK_Reserved17 = 0x17, // reserved
203  LOR_RegRxPacketCntValueLsb = 0x17,
204 
205  FSK_Reserved18 = 0x18, // reserved
206  LOR_RegModemStat = 0x18,
207 
208  FSK_Reserved19 = 0x19, // reserved
209  LOR_RegPktSnrValue = 0x19,
210 
211  FSK_RegAfcFei = 0x1a,
212  LOR_RegPktRssiValue = 0x1a,
213 
214  FSK_RegAfcMsb = 0x1b,
215  LOR_RegRssiValue = 0x1b,
216 
217  FSK_RegAfcLsb = 0x1c,
218  LOR_RegHopChannel = 0x1c, // fhss starting channel
219 
220  FSK_RegFeiMsb = 0x1d,
221  LOR_RegModemConfig1 = 0x1d,
222 
223  FSK_RegFeiLsb = 0x1e,
224  LOR_RegModemConfig2 = 0x1e,
225 
226  FSK_RegPreambleDetect = 0x1f,
227  LOR_RegSymbTimeoutLsb = 0x1f,
228 
229  FSK_RegRxTimeout1 = 0x20,
230  LOR_RegPreambleMsb = 0x20,
231 
232  FSK_RegRxTimeout2 = 0x21,
233  LOR_RegPreambleLsb = 0x21,
234 
235  FSK_RegRxTimeout3 = 0x22,
236  LOR_RegPayloadLength = 0x22,
237 
238  FSK_RegRxDelay = 0x23,
239  LOR_RegMaxPayloadLength = 0x23,
240 
241  FSK_RegOsc = 0x24,
242  LOR_RegHopPeriod = 0x24,
243 
244  FSK_RegPreambleMsb = 0x25,
245  LOR_RegFifoRxByteAddr = 0x25,
246 
247  FSK_RegPreambleLsb = 0x26,
248  LOR_RegModemConfig3 = 0x26,
249 
250  FSK_RegSyncConfig = 0x27,
251  LOR_Reserved27 = 0x27, // reserved
252 
253  FSK_RegSyncValue1 = 0x28,
254  LOR_RegFeiMsb = 0x28,
255 
256  FSK_RegSyncValue2 = 0x29,
257  LOR_RegFeiMid = 0x29,
258 
259  FSK_RegSyncValue3 = 0x2a,
260  LOR_RegFeiLsb = 0x2a,
261 
262  FSK_RegSyncValue4 = 0x2b,
263  LOR_Reserved2b = 0x2b, // reserved
264 
265  FSK_RegSyncValue5 = 0x2c,
266  LOR_RegRssiWideband = 0x2c,
267 
268  FSK_RegSyncValue6 = 0x2d,
269  LOR_Reserved2d = 0x2d, // reserved
270 
271  FSK_RegSyncValue7 = 0x2e,
272  LOR_Reserved2e = 0x2e, // reserved
273 
274  FSK_RegSyncValue8 = 0x2f,
275  LOR_Reserved2f = 0x2f, // reserved
276 
277  FSK_RegPacketConfig1 = 0x30,
278  LOR_Reserved30 = 0x30, // reserved
279 
280  FSK_RegPacketConfig2 = 0x31,
281  LOR_RegDetectOptimize = 0x31,
282 
283  FSK_RegPayloadLength = 0x32,
284  LOR_Reserved32 = 0x32, // reserved
285 
286  FSK_RegNodeAddr = 0x33,
287  LOR_RegInvertIQ = 0x33,
288 
289  FSK_RegBroadcastAddr = 0x34,
290  LOR_Reserved34 = 0x34, // reserved
291 
292  FSK_RegFifoThresh = 0x35,
293  LOR_Reserved35 = 0x35, // reserved
294 
295  FSK_RegSeqConfig1 = 0x36,
296  LOR_Reserved36 = 0x36, // reserved
297 
298  FSK_RegSeqConfig2 = 0x37,
299  LOR_RegDetectionThreshold = 0x37,
300 
301  FSK_RegTimerResol = 0x38,
302  LOR_Reserved38 = 0x38, // reserved
303 
304  FSK_RegTimer1Coeff = 0x39,
305  LOR_RegSyncWord = 0x39,
306 
307  FSK_RegTimer2Coeff = 0x3a,
308  LOR_Reserved3a = 0x3a, // reserved
309 
310  FSK_RegImageCal = 0x3b,
311  LOR_Reserved3b = 0x3b, // reserved (in datasheet)?
312  LOR_RegInvertIQ2 = 0x3b, // does not exist in datasheet
313  // but used in Semtech code.
314  // UNDOCUMENTED
315 
316  FSK_RegTemp = 0x3c,
317  LOR_Reserved3c = 0x3c, // reserved
318 
319  FSK_RegLowBat = 0x3d,
320  LOR_Reserved3d = 0x3d, // reserved
321 
322  FSK_RegIrqFlags1 = 0x3e,
323  LOR_Reserved3e = 0x3e, // reserved
324 
325  FSK_RegIrqFlags2 = 0x3f,
326  LOR_Reserved3f = 0x3f, // reserved
327 
328  COM_RegDioMapping1 = 0x40, // DIO0-DIO3
329  COM_RegDioMapping2 = 0x41, // DIO4-DIO5, clk out freq
330 
331  COM_RegVersion = 0x42, // Semtech ID (silicon revision)
332 
333  // 0x43 reserved
334 
335  // The data sheet says this is FSK only, but the semtech code
336  // implies this is only valid for LoRa. So for now, assume the
337  // datasheet is wrong.
338  //
339  // FSK_RegPllHop = 0x44,
340  // LOR_Reserved44 = 0x44, // reserved
341 
342  FSK_Reserved44 = 0x44,
343  LOR_RegPllHop = 0x44,
344 
345  // 0x45-0x4a reserved
346 
347  COM_RegTcxo = 0x4b,
348 
349  // 0x4c reserved
350 
351  COM_RegPaDac = 0x4d,
352 
353  // 0x4e-0x5a reserved
354 
355  COM_RegFormerTemp = 0x5b,
356 
357  // 0x5c reserved
358 
359  FSK_RegBitRateFrac = 0x5d,
360  LOR_Reserved5d = 0x5d, // reserved
361 
362  // 0x5e-0x60 reserved
363 
364  COM_RegAgcRef = 0x61,
365  COM_RegAgcThresh1 = 0x62,
366  COM_RegAgcThresh2 = 0x63,
367  COM_RegAgcThresh3 = 0x64,
368 
369  // 0x65-0x6f reserved
370 
371  COM_RegPll = 0x70
372 
373  // 0x71-0xff reserved
374  } SX1276_REGS_T;
375 
379  typedef enum {
380  OPMODE_Mode0 = 0x01, // operating modes (sleep, etc)
381  OPMODE_Mode1 = 0x02,
382  OPMODE_Mode2 = 0x04,
383  _OPMODE_Mode_MASK = 7,
384  _OPMODE_Mode_SHIFT = 0,
385 
386  OPMODE_LowFrequencyModeOn = 0x08,
387 
388  // 0x10 reserved
389 
390  OPMODE_FSK_ModulationType0 = 0x20,
391  OPMODE_FSK_ModulationType1 = 0x40,
392  _OPMODE_FSK_ModulationType_MASK = 3,
393  _OPMODE_FSK_ModulationType_SHIFT = 5,
394 
395  OPMODE_LOR_Reserved0x20 = 0x20,
396 
397  OPMODE_LOR_AccessSharedReg = 0x40, // tmp sw to FSK regs
398 
399  OPMODE_LongRangeMode = 0x80 // LoRa mode enable(1), else FSK
400  } OPMODE_BITS_T;
401 
402 
406  typedef enum {
407  MODE_Sleep = 0,
408  MODE_Standby = 1,
409  MODE_FSTX = 2, // freq synth
410  MODE_TxMode = 3,
411  MODE_FSRX = 4, // freq synth
412 
413  MODE_FSK_RxMode = 5,
414  MODE_LOR_RxContinuous = 5, // continuous rx mode
415 
416  MODE_FSK_Reserved6 = 6,
417  MODE_LOR_RxSingle = 6, // single packet rx mode
418 
419  MODE_FSK_Reserved7 = 7,
420  MODE_LOR_CAD = 7 // channel activity detection
421  } MODE_T;
422 
426  typedef enum {
427  MODULATION_FSK = 0, // freq shift keying
428  MODULATION_OOK = 1, // on/off keying
429  // 2-3 reserved
431 
435  typedef enum {
436  PACONFIG_OutputPower0 = 0x01,
437  PACONFIG_OutputPower1 = 0x02,
438  PACONFIG_OutputPower2 = 0x04,
439  PACONFIG_OutputPower3 = 0x08,
440  _PACONFIG_OutputPower_MASK = 15,
441  _PACONFIG_OutputPower_SHIFT = 0,
442 
443  PACONFIG_MaxPower0 = 0x10,
444  PACONFIG_MaxPower1 = 0x20,
445  PACONFIG_MaxPower2 = 0x40,
446  _PACONFIG_MaxPower_MASK = 7,
447  _PACONFIG_MaxPower_SHIFT = 4,
448 
449  PACONFIG_PaSelect = 0x80 // PA output pin,
450  // 0 = 14dBm, 1 = 20dBm
451  } PACONFIG_BITS_T;
452 
456  typedef enum {
457  PARAMP_PaRamp0 = 0x01, // rise/fall of ramp up/down
458  PARAMP_PaRamp1 = 0x02,
459  PARAMP_PaRamp2 = 0x04,
460  PARAMP_PaRamp3 = 0x08,
461  _PARAMP_PaRamp_MASK = 15,
462  _PARAMP_PaRamp_SHIFT = 0,
463 
464  // 0x10 reserved
465 
466  // LORA 0x20-0x40 reserved
467 
468  PARAMP_FSK_ModulationShaping0 = 0x20,
469  PARAMP_FSK_ModulationShaping1 = 0x40,
470  _PARAMP_FSK_ModulationShaping_MASK = 3,
471  _PARAMP_FSK_ModulationShaping_SHIFT = 5
472 
473  // 0x80 reserved
474  } PARAMP_BITS_T;
475 
479  typedef enum {
480  PARAMP_3_4MS = 0, // 3.4ms
481  PARAMP_2MS = 1,
482  PARAMP_1MS = 2,
483  PARAMP_500US = 3, // 500us
484  PARAMP_250US = 4,
485  PARAMP_125US = 5,
486  PARAMP_100US = 6,
487  PARAMP_62US = 7,
488  PARAMP_50US = 8,
489  PARAMP_40US = 9,
490  PARAMP_31US = 10,
491  PARAMP_25US = 11,
492  PARAMP_20US = 12,
493  PARAMP_15US = 13,
494  PARAMP_12US = 14,
495  PARAMP_10US = 15
496  } PARAMP_T;
497 
504  typedef enum {
505  MODSHAPING_NOSHAPING = 0,
506 
507  // FSK
508  MODSHAPING_FSK_GaussianFilterBT1 = 1, // BT = 1.0
509  MODSHAPING_FSK_GaussianFilterBT05 = 2, // BT = 0.5
510  MODSHAPING_FSK_GaussianFilterBT03 = 3, // BT = 0.3
511 
512  // OOK
513  MODSHAPING_OOK_FCutoffBitRate = 1, // Fcutoff = BitRate
514  MODSHAPING_OOK_FCutoffBitRate2 = 2 // Fcutoff = 2*BitRate
515 
516  // for OOK, 3 is reserved
517  } MODSHAPING_T;
518 
522  typedef enum {
523  OCP_OcpTrim0 = 0x01,
524  OCP_OcpTrim1 = 0x02,
525  OCP_OcpTrim2 = 0x04,
526  OCP_OcpTrim3 = 0x08,
527  _OCP_OcpTrim_MASK = 15,
528  _OCP_OcpTrim_SHIFT = 0,
529 
530  OCP_OcpOn = 0x10
531 
532  // 0x20-0x80 reserved
533  } OCP_BITS_T;
534 
538  typedef enum {
539  LNA_LnaBoostHf0 = 0x01,
540  LNA_LnaBoostHf1 = 0x02,
541  _LNA_LnaBoostHf_MASK = 3,
542  _LNA_LnaBoostHf_SHIFT = 0,
543 
544  // 0x04 reserved
545 
546  LNA_LnaBoostLf0 = 0x08,
547  LNA_LnaBoostLf1 = 0x10,
548  _LNA_LnaBoostLf_MASK = 3,
549  _LNA_LnaBoostLf_SHIFT = 3,
550 
551  LNA_LnaGain0 = 0x20,
552  LNA_LnaGain1 = 0x40,
553  LNA_LnaGain2 = 0x80,
554  _LNA_LnaGain_MASK = 7,
555  _LNA_LnaGain_SHIFT = 5
556  } LNA_BITS_T;
557 
561  typedef enum {
562  LNABOOSTHF_Default = 0,
563  // 1-2 reserved
564  LNABOOSTHF_BoostOn = 3, // 150% LNA current
565  } LNABOOSTHF_T;
566 
570  typedef enum {
571  LNABOOSTLF_Default = 0
572  // 1-3 reserved
573  } LNABOOSTLF_T;
574 
578  typedef enum {
579  // 0 reserved
580  LNAGAIN_G1 = 1, // max gain
581  LNAGAIN_G2 = 2,
582  LNAGAIN_G3 = 3,
583  LNAGAIN_G4 = 4,
584  LNAGAIN_G5 = 5,
585  LNAGAIN_G6 = 6 // minimum gain
586  // 7 reserved
587  } LNAGAIN_T;
588 
593  typedef enum {
594  RXCONFIG_RxTrigger0 = 0x01,
595  RXCONFIG_RxTrigger1 = 0x02,
596  RXCONFIG_RxTrigger2 = 0x04,
597  _RXCONFIG_RxTrigger_MASK = 7,
598  _RXCONFIG_RxTrigger_SHIFT = 0,
599 
600  RXCONFIG_AgcAutoOn = 0x08,
601  RXCONFIG_AfcAutoOn = 0x10,
602  RXCONFIG_RestartRxWithPllLock = 0x20,
603  RXCONFIG_RestartRxWithoutPllLock = 0x40,
604  RXCONFIG_RestartRxOnCollision = 0x80
605  } RXCONFIG_BITS_T;
606 
610  typedef enum {
611  RSSICONFIG_RssiSmoothing0 = 0x01, // RSSI sampling/averaging
612  RSSICONFIG_RssiSmoothing1 = 0x02,
613  RSSICONFIG_RssiSmoothing2 = 0x04,
614  _RSSICONFIG_RssiSmoothing_MASK = 7,
615  _RSSICONFIG_RssiSmoothing_SHIFT = 0,
616 
617  RSSICONFIG_RssiOffset0 = 0x08, // 2's complement offset
618  RSSICONFIG_RssiOffset1 = 0x10,
619  RSSICONFIG_RssiOffset2 = 0x20,
620  RSSICONFIG_RssiOffset3 = 0x40,
621  RSSICONFIG_RssiOffset4 = 0x80,
622  _RSSICONFIG_RssiOffset_MASK = 31,
623  _RSSICONFIG_RssiOffset_SHIFT = 3
625 
629  typedef enum {
630  RSSISMOOTHING_2 = 0, // 2 samples used
631  RSSISMOOTHING_4 = 1,
632  RSSISMOOTHING_8 = 2,
633  RSSISMOOTHING_16 = 3,
634  RSSISMOOTHING_32 = 4,
635  RSSISMOOTHING_64 = 5,
636  RSSISMOOTHING_128 = 6,
637  RSSISMOOTHING_256 = 7
638  } RSSISMOOTHING_T;
639 
643  typedef enum {
644  LOR_IRQFLAG_CadDetected = 0x01,
645  LOR_IRQFLAG_FhssChangeChannel = 0x02,
646  LOR_IRQFLAG_CadDone = 0x04,
647  LOR_IRQFLAG_TxDone = 0x08,
648 
649  LOR_IRQFLAG_ValidHeader = 0x10,
650  LOR_IRQFLAG_PayloadCrcError = 0x20,
651  LOR_IRQFLAG_RxDone = 0x40,
652  LOR_IRQFLAG_RxTimeout = 0x80
654 
658  typedef enum {
659  RXBW_RxBwExp0 = 0x01,
660  RXBW_RxBwExp1 = 0x02,
661  RXBW_RxBwExp2 = 0x04,
662  _RXBW_RxBwExp_MASK = 7,
663  _RXBW_RxBwExp_SHIFT = 0,
664 
665  RXBW_RxBwMant0 = 0x08,
666  RXBW_RxBwMant1 = 0x10,
667  _RXBW_RxBwMant_MASK = 3,
668  _RXBW_RxBwMant_SHIFT = 3,
669  // 0x20-0x80 reserved
670  } RXBW_BITS_T;
671 
675  typedef enum {
676  RXBWMANT_0 = 0,
677  RXBWMANT_1 = 1,
678  RXBWMANT_2 = 2
679  // 3 reserved
680  } RXBWMANT_T;
681 
685  typedef enum {
686  RXBWEXP_1 = 1,
687  RXBWEXP_2 = 2,
688  RXBWEXP_3 = 3,
689  RXBWEXP_4 = 4,
690  RXBWEXP_5 = 5,
691  RXBWEXP_6 = 6,
692  RXBWEXP_7 = 7
693  // other values reserved
694  } RXBWEXP_T;
695 
699  typedef enum {
700  OOKPEAK_OokPeakThreshStep0 = 0x01,
701  OOKPEAK_OokPeakThreshStep1 = 0x02,
702  OOKPEAK_OokPeakThreshStep2 = 0x04,
703  _OOKPEAK_OokPeakThreshStep_MASK = 7,
704  _OOKPEAK_OokPeakThreshStep_SHIFT = 0,
705 
706  OOKPEAK_OokThreshType0 = 0x08,
707  OOKPEAK_OokThreshType1 = 0x10,
708  _OOKPEAK_OokThreshType_MASK = 3,
709  _OOKPEAK_OokThreshType_SHIFT = 3,
710 
711  OOKPEAK_BitSyncOn = 0x20,
712 
713  // 0x40-0x80 reserved
714  } OOKPEAK_BITS_T;
715 
719  typedef enum {
720  OOKPEAKTHRESHSTEP_05dB = 0, // dec of RSSI threshold 0.5dB
721  OOKPEAKTHRESHSTEP_1dB = 1, // 1 dB
722  OOKPEAKTHRESHSTEP_15dB = 2, // 1.5 dB
723  OOKPEAKTHRESHSTEP_2dB = 3, // 2 dB
724  OOKPEAKTHRESHSTEP_3dB = 4,
725  OOKPEAKTHRESHSTEP_4dB = 5,
726  OOKPEAKTHRESHSTEP_5dB = 6,
727  OOKPEAKTHRESHSTEP_6dB = 7
729 
733  typedef enum {
734  OOKTHRESHTYPE_FIXED = 0,
735  OOKTHRESHTYPE_PEAK = 1,
736  OOKTHRESHTYPE_AVERAGE = 2
737  // 3 reserved
738  } OOKTHRESHTYPE_T;
739 
743  typedef enum {
744  OOKAVG_OokAvgThreshFilt0 = 0x01,
745  OOKAVG_OokAvgThreshFilt1 = 0x02,
746  _OOKAVG_OokAvgThreshFilt_MASK = 3,
747  _OOKAVG_OokAvgThreshFilt_SHIFT = 0,
748 
749  OOKAVG_OokAvgOffset0 = 0x04,
750  OOKAVG_OokAvgOffset1 = 0x08,
751  _OOKAVG_OokAvgOffset_MASK = 3,
752  _OOKAVG_OokAvgOffset_SHIFT = 2,
753 
754  // 0x10 reserved
755 
756  OOKAVG_OokPeakThreshDec0 = 0x20,
757  OOKAVG_OokPeakThreshDec1 = 0x40,
758  OOKAVG_OokPeakThreshDec2 = 0x80,
759  _OOKAVG_OokPeakThreshDec_MASK = 7,
760  _OOKAVG_OokPeakThreshDec_SHIFT = 5
761  } OOKAVG_BITS_T;
762 
766  typedef enum {
767  OOKAVGTHRESHFILT_32 = 0, // filter coedd in avg mode
768  OOKAVGTHRESHFILT_8 = 1,
769  OOKAVGTHRESHFILT_4 = 2,
770  OOKAVGTHRESHFILT_2 = 3
772 
776  typedef enum {
777  OOKAVGOFFSET_0 = 0, // 0.0dB
778  OOKAVGOFFSET_2 = 1,
779  OOKAVGOFFSET_4 = 2,
780  OOKAVGOFFSET_6 = 3
781  } OOKAVGOFFSET_T;
782 
786  typedef enum {
787  OOKPEAKTHRESHDEC_1_1 = 0, // once per chip
788  OOKPEAKTHRESHDEC_1_2 = 1, // once every 2 chips...
789  OOKPEAKTHRESHDEC_1_4 = 2,
790  OOKPEAKTHRESHDEC_1_8 = 3,
791  OOKPEAKTHRESHDEC_2_1 = 4, // twice per chip
792  OOKPEAKTHRESHDEC_4_1 = 5, // 4 times every chip...
793  OOKPEAKTHRESHDEC_8_1 = 6,
794  OOKPEAKTHRESHDEC_16_1 = 7
796 
800  typedef enum {
801  MODEMSTAT_SignalDetected = 0x01,
802  MODEMSTAT_SignalSynchronized = 0x02,
803  MODEMSTAT_RxOngoing = 0x04,
804  MODEMSTAT_HeaderInfoValid = 0x08,
805  MODEMSTAT_ModemClear = 0x10,
806 
807  MODEMSTAT_RxCodingRate0 = 0x20,
808  MODEMSTAT_RxCodingRate1 = 0x40,
809  MODEMSTAT_RxCodingRate2 = 0x80,
810  _MODEMSTAT_RxCodingRate_MASK = 7,
811  _MODEMSTAT_RxCodingRate_SHIFT = 5
813 
817  typedef enum {
818  AFCFEI_AfcAutoClearOn = 0x01,
819  AFCFEI_AfcClear = 0x02,
820 
821  // 0x04-0x08 reserved
822 
823  AFCFEI_AgcStart = 0x10
824 
825  // 0x20-0x80 reserved
826  } AFCFEI_BITS_T;
827 
831  typedef enum {
832  HOPCHANNEL_FhssPresentChannel0 = 0x01, // current freq hopping channel
833  HOPCHANNEL_FhssPresentChannel1 = 0x02,
834  HOPCHANNEL_FhssPresentChannel2 = 0x04,
835  HOPCHANNEL_FhssPresentChannel3 = 0x08,
836  HOPCHANNEL_FhssPresentChannel4 = 0x10,
837  HOPCHANNEL_FhssPresentChannel5 = 0x20,
838  _HOPCHANNEL_FhssPresentChannel_MASK = 63,
839  _HOPCHANNEL_FhssPresentChannel_SHIFT = 0,
840 
841  HOPCHANNEL_CrcOnPayload = 0x40,
842  HOPCHANNEL_PllTimeout = 0x80
844 
848  typedef enum {
849  MODEMCONFIG1_ImplicitHeaderModeOn = 0x01,
850 
851  MODEMCONFIG1_CodingRate0 = 0x02,
852  MODEMCONFIG1_CodingRate1 = 0x04,
853  MODEMCONFIG1_CodingRate2 = 0x08,
854  _MODEMCONFIG1_CodingRate_MASK = 7,
855  _MODEMCONFIG1_CodingRate_SHIFT = 0,
856 
857  MODEMCONFIG1_Bw0 = 0x10,
858  MODEMCONFIG1_Bw1 = 0x20,
859  MODEMCONFIG1_Bw2 = 0x40,
860  MODEMCONFIG1_Bw3 = 0x80,
861  _MODEMCONFIG1_Bw_MASK = 15,
862  _MODEMCONFIG1_Bw_SHIFT = 4
864 
868  typedef enum {
869  CODINGRATE_4_5 = 1, // Error coding rate 4/5
870  CODINGRATE_4_6 = 2,
871  CODINGRATE_4_7 = 3,
872  CODINGRATE_4_8 = 4
873  } CODINGRATE_T;
874 
878  typedef enum {
879  BW_7_8 = 0, // 7.8Khz
880  BW_10_4 = 1,
881  BW_15_6 = 2,
882  BW_20_8 = 3,
883  BW_31_25 = 4,
884  BW_41_7 = 5,
885  BW_62_5 = 6,
886  BW_125 = 7,
887  BW_250 = 8,
888  BW_500 = 9
889 
890  // BW250 and BW500 not supported in lower band (169Mhz)
891  } BW_T;
892 
896  typedef enum {
897  MODEMCONFIG2_SymbTimeoutMsb0 = 0x01,
898  MODEMCONFIG2_SymbTimeoutMsb1 = 0x02,
899  _MODEMCONFIG2_SymbTimeoutMsb_MASK = 3,
900  _MODEMCONFIG2_SymbTimeoutMsb_SHIFT = 0,
901 
902  MODEMCONFIG2_RxPayloadCrcOn = 0x04,
903 
904  MODEMCONFIG2_TxContinuousMode = 0x08,
905 
906  MODEMCONFIG2_SpreadingFactor0 = 0x10,
907  MODEMCONFIG2_SpreadingFactor1 = 0x20,
908  MODEMCONFIG2_SpreadingFactor2 = 0x40,
909  MODEMCONFIG2_SpreadingFactor3 = 0x80,
910  _MODEMCONFIG2_SpreadingFactor_MASK = 15,
911  _MODEMCONFIG2_SpreadingFactor_SHIFT = 4,
913 
917  typedef enum {
918  SPREADINGFACTOR_64 = 6, // 64 chips/symbol
919  SPREADINGFACTOR_128 = 7,
920  SPREADINGFACTOR_256 = 8,
921  SPREADINGFACTOR_512 = 9,
922  SPREADINGFACTOR_1024 = 10,
923  SPREADINGFACTOR_2048 = 11,
924  SPREADINGFACTOR_4096 = 12
925 
926  // other values reserved
928 
932  typedef enum {
933  PREABLEDETECT_PreambleDetectorTol0 = 0x01,
934  PREABLEDETECT_PreambleDetectorTol1 = 0x02,
935  PREABLEDETECT_PreambleDetectorTol2 = 0x04,
936  PREABLEDETECT_PreambleDetectorTol3 = 0x08,
937  PREABLEDETECT_PreambleDetectorTol4 = 0x10,
938  _PREABLEDETECT_PreambleDetectorTol4_MASK = 31,
939  _PREABLEDETECT_PreambleDetectorTol4_SHIFT = 0,
940 
941  PREABLEDETECT_PreambleDetectorSize0 = 0x20,
942  PREABLEDETECT_PreambleDetectorSize1 = 0x40,
943  _PREABLEDETECT_PreambleDetectorSize_MASK = 3,
944  _PREABLEDETECT_PreambleDetectorSize_SHIFT = 5,
945 
946  PREABLEDETECT_PreambleDetectorOn = 0x80
948 
952  typedef enum {
953  PREAMBLEDETECTORSIZE_1 = 0, // 1 byte
954  PREAMBLEDETECTORSIZE_2 = 1,
955  PREAMBLEDETECTORSIZE_3 = 2
956 
957  // other values reserved
959 
963  typedef enum {
964  OSC_ClkOut0 = 0x01, // clk output freq
965  OSC_ClkOut1 = 0x02,
966  OSC_ClkOut2 = 0x04,
967  _OSC_ClkOut_MASK = 7,
968  _OSC_ClkOut_SHIFT = 0,
969 
970  OSC_RcCalStart = 0x08
971 
972  // other bits reserved
973  } OSC_BITS_T;
974 
978  typedef enum {
979  CLKOUT_1 = 0, // FXOSC
980  CLKOUT_2 = 1, // FXOSC / 2 ...
981  CLKOUT_4 = 2,
982  CLKOUT_8 = 3,
983  CLKOUT_16 = 4,
984  CLKOUT_32 = 5,
985  CLKOUT_RC = 6, // RC, (automatically enabled)
986  CLKOUT_OFF = 7 // clkout off
987  } CLKOUT_T;
988 
992  typedef enum {
993  // 0x01-0x02 reserved
994 
995  MODEMCONFIG3_AgcAutoOn = 0x04,
996  MODEMCONFIG3_LowDataRateOptimize = 0x08 // req. for SF11 and SF12 and
997  // BW125
998 
999  // 0x10-0x80 reserved
1001 
1005  typedef enum {
1006  SYNCCONFIG_SyncSize0 = 0x01,
1007  SYNCCONFIG_SyncSize1 = 0x02,
1008  SYNCCONFIG_SyncSize2 = 0x04,
1009  _SYNCCONFIG_SyncSize_MASK = 7,
1010  _SYNCCONFIG_SyncSize_SHIFT = 0,
1011 
1012  // 0x08 reserved
1013 
1014  SYNCCONFIG_SyncOn = 0x10,
1015  SYNCCONFIG_PreamblePolarity = 0x20,
1016 
1017  SYNCCONFIG_AutoRestartMode0 = 0x40,
1018  SYNCCONFIG_AutoRestartMode1 = 0x80,
1019  _SYNCCONFIG_AutoRestartMode_MASK = 3,
1020  _SYNCCONFIG_AutoRestartMode_SHIFT = 6,
1022 
1026  typedef enum {
1027  AUTORESTARTMODE_OFF = 0,
1028  AUTORESTARTMODE_ON_NOPLL = 1, // don't wait for PLL resync
1029  AUTORESTARTMODE_ON_PLL = 2 // wait for PLL resync
1030  // other values reserved
1032 
1036  typedef enum {
1037  FEIMSB_FreqError0 = 0x01,
1038  FEIMSB_FreqError1 = 0x02,
1039  FEIMSB_FreqError2 = 0x04,
1040  FEIMSB_FreqError3 = 0x08,
1041  _FEIMSB_FreqError_MASK = 15,
1042  _FEIMSB_FreqError_SHIFT = 0
1043 
1044  // 0x10-0x80 reserved
1045  } FEIMSB_BITS_T;
1046 
1050  typedef enum {
1051  PACKETCONFIG1_CrcWhiteningType = 0x01,
1052 
1053  PACKETCONFIG1_AddressFiltering0 = 0x02,
1054  PACKETCONFIG1_AddressFiltering1 = 0x04,
1055  _PACKETCONFIG1_AddressFiltering_MASK = 3,
1056  _PACKETCONFIG1_AddressFiltering_SHIFT = 1,
1057 
1058  PACKETCONFIG1_CrcAutoClearOff = 0x08,
1059  PACKETCONFIG1_CrcOn = 0x10,
1060 
1061  PACKETCONFIG1_DcFree0 = 0x20,
1062  PACKETCONFIG1_DcFree1 = 0x40,
1063  _PACKETCONFIG1_DcFree_MASK = 3,
1064  _PACKETCONFIG1_DcFree_SHIFT = 5,
1065 
1066  PACKETCONFIG1_PacketFormat = 0x80 // fixed(0) or variable(1)
1068 
1072  typedef enum {
1073  ADDRESSFILTERING_NONE = 0,
1074  ADDRESSFILTERING_NODE = 1, // must match node addr
1075  ADDRESSFILTERING_NODE_BROADCAST = 2, // match node or broadcast
1077 
1081  typedef enum {
1082  DCFREE_NONE = 0,
1083  DCFREE_MANCHESTER = 1,
1084  DCFREE_WHITENING = 2
1085  // other values reserved
1086  } DCFREE_T;
1087 
1091  typedef enum {
1092  PACKETCONFIG2_PayloadLengthMsb0 = 0x01,
1093  PACKETCONFIG2_PayloadLengthMsb1 = 0x02,
1094  PACKETCONFIG2_PayloadLengthMsb2 = 0x04,
1095  _PACKETCONFIG2_PayloadLengthMsb_MASK = 7,
1096  _PACKETCONFIG2_PayloadLengthMsb_SHIFT = 0,
1097 
1098  PACKETCONFIG2_BeaconOn = 0x08,
1099 
1100  // 0x10 reserved (linked to io-homecontrol compat mode (?))
1101 
1102  PACKETCONFIG2_IoHomeOn = 0x20,
1103  PACKETCONFIG2_DataMode = 0x40, // continuous(0), packet(1)
1104 
1105  // 0x80 reserved
1107 
1111  typedef enum {
1112  DETECTOPTIMIZE_DetectionOptimize0 = 0x01,
1113  DETECTOPTIMIZE_DetectionOptimize1 = 0x02,
1114  DETECTOPTIMIZE_DetectionOptimize2 = 0x04,
1115  _DETECTOPTIMIZE_DetectionOptimize_MASK = 7,
1116  _DETECTOPTIMIZE_DetectionOptimize_SHIFT = 0
1117 
1118  // 0x08-0x80 reserved
1120 
1124  typedef enum {
1125  DETECTIONOPTIMIZE_SF7_SF12 = 3,
1126  DETECTIONOPTIMIZE_SF6 = 5
1127 
1128  // other values reserved
1130 
1134  typedef enum {
1135  INVERTIQ_InvertIQTxOff = 0x01, // invert LoRa I & Q signals
1136  // UNDOCUMENTED
1137 
1138  // 0x01-0x20 reserved
1139 
1140  INVERTIQ_InvertIQRx = 0x40 // invert LoRa I & Q signals
1141 
1142  // 0x80 reserved
1143  } INVERTIQ_BITS_T;
1144 
1148  typedef enum {
1149  FIFOTHRESH_FifoThreshold0 = 0x01,
1150  FIFOTHRESH_FifoThreshold1 = 0x02,
1151  FIFOTHRESH_FifoThreshold2 = 0x04,
1152  FIFOTHRESH_FifoThreshold3 = 0x08,
1153  FIFOTHRESH_FifoThreshold4 = 0x10,
1154  FIFOTHRESH_FifoThreshold5 = 0x20,
1155  _FIFOTHRESH_FifoThreshold_MASK = 63,
1156  _FIFOTHRESH_FifoThreshold_SHIFT = 0,
1157 
1158  // 0x40 reserved
1159 
1160  FIFOTHRESH_TxStartCondition = 0x80
1162 
1166  typedef enum {
1167  SEQCONFIG1_FromTransit = 0x01,
1168  SEQCONFIG1_FromIdle = 0x02,
1169  SEQCONFIG1_LowPowerSelection = 0x04,
1170 
1171  SEQCONFIG1_FromStart0 = 0x08,
1172  SEQCONFIG1_FromStart1 = 0x10,
1173  _SEQCONFIG1_FromStart_MASK = 3,
1174  _SEQCONFIG1_FromStart_SHIFT = 3,
1175 
1176  SEQCONFIG1_IdleMode = 0x20,
1177  SEQCONFIG1_SequencerStop = 0x40,
1178  SEQCONFIG1_SequencerStart = 0x80
1180 
1184  typedef enum {
1185  FROMSTART_ToLowPowerSelection = 0,
1186  FROMSTART_ToReceiveState = 1,
1187  FROMSTART_ToTransmitState = 2,
1188  FROMSTART_ToTransmitStateOnFifoLevel = 3
1189  } FROMSTART_T;
1190 
1194  typedef enum {
1195  SEQCONFIG2_FromPacketReceived0 = 0x01,
1196  SEQCONFIG2_FromPacketReceived1 = 0x02,
1197  SEQCONFIG2_FromPacketReceived2 = 0x04,
1198  _SEQCONFIG2_FromPacketReceived_MASK = 7,
1199  _SEQCONFIG2_FromPacketReceived_SHIFT = 0,
1200 
1201  SEQCONFIG2_FromRxTimeout0 = 0x08,
1202  SEQCONFIG2_FromRxTimeout1 = 0x10,
1203  _SEQCONFIG2_FromRxTimeout_MASK = 3,
1204  _SEQCONFIG2_FromRxTimeout_SHIFT = 3,
1205 
1206  SEQCONFIG2_FromReceive0 = 0x20,
1207  SEQCONFIG2_FromReceive1 = 0x40,
1208  SEQCONFIG2_FromReceive2 = 0x80,
1209  _SEQCONFIG2_FromReceive_MASK = 3,
1210  _SEQCONFIG2_FromReceive_SHIFT = 5
1212 
1216  typedef enum {
1217  FROMPACKETRECEIVED_ToSequencerOff = 0,
1218  FROMPACKETRECEIVED_ToTransmitStateOnFifoEmpty = 1,
1219  FROMPACKETRECEIVED_ToLowPowerSelection = 2,
1220  FROMPACKETRECEIVED_ToReceiveViaFS = 3, // if freq was changed
1221  FROMPACKETRECEIVED_ToReceive = 4 // if freq was not changed
1222 
1223  // other values reserved
1225 
1229  typedef enum {
1230  FROMRXTIMEOUT_ToReceiveViaReceiveStart = 0,
1231  FROMRXTIMEOUT_ToTransmitState = 1,
1232  FROMRXTIMEOUT_ToLowPowerSelection = 2,
1233  FROMRXTIMEOUT_ToSequencerOffState = 3
1234  } FROMRXTIMEOUT_T;
1235 
1239  typedef enum {
1240  FROMRECEIVE_ToPcketReceived = 1,
1241  FROMRECEIVE_ToLowPowerSelection = 2,
1242  FROMRECEIVE_ToPacketReceived = 3,
1243  FROMRECEIVE_ToSequencerOffOnRSSI = 4, // RSSI interrupt
1244  FROMRECEIVE_ToSequencerOffOnSync = 5, // SyncAddr interrupt
1245  FROMRECEIVE_ToSequencerOffOnPreambleDetect = 6, // PreambleDetect intr
1246  // other values reserved
1247  } FROMRECEIVE_T;
1248 
1252  typedef enum {
1253  TIMERRESOL_Timer2Resolution0 = 0x01,
1254  TIMERRESOL_Timer2Resolution1 = 0x02,
1255  _TIMERRESOL_Timer2Resolution_MASK = 3,
1256  _TIMERRESOL_Timer2Resolution_SHIFT = 0,
1257 
1258  TIMERRESOL_Timer1Resolution0 = 0x04,
1259  TIMERRESOL_Timer1Resolution1 = 0x08,
1260  _TIMERRESOL_Timer1Resolution_MASK = 3,
1261  _TIMERRESOL_Timer1Resolution_SHIFT = 2
1262 
1263  // 0x10-0x80 reserved
1265 
1269  typedef enum {
1270  TIMERRESOLUTION_DISABLED = 0,
1271  TIMERRESOLUTION_64us = 1, // 64us
1272  TIMERRESOLUTION_4_1ms = 2, // 4.1ms
1273  TIMERRESOLUTION_262ms = 3 // 262ms
1275 
1279  typedef enum {
1280  IMAGECAL_TempMonitorOff = 0x01,
1281 
1282  IMAGECAL_TempThreshold0 = 0x02,
1283  IMAGECAL_TempThreshold1 = 0x04,
1284  _IMAGECAL_TempThreshold_MASK = 3,
1285  _IMAGECAL_TempThreshold_SHIFT = 1,
1286 
1287  IMAGECAL_TenpChange = 0x08,
1288 
1289  // 0x10 reserved
1290 
1291  IMAGECAL_ImageCalRunning = 0x20,
1292  IMAGECAL_ImageCalStart = 0x40,
1293  IMAGECAL_AutoImageCalOn = 0x80
1294  } IMAGECAL_BITS_T;
1295 
1299  typedef enum {
1300  TEMPTHRESHOLD_5C = 0, // temp change to trigger new I/Q
1301  TEMPTHRESHOLD_10C = 1, // calibration
1302  TEMPTHRESHOLD_15C = 2,
1303  TEMPTHRESHOLD_20C = 3
1304  } TEMPTHRESHOLD_T;
1305 
1309  typedef enum {
1310  LOWBAT_LowBatTrim0 = 0x01,
1311  LOWBAT_LowBatTrim1 = 0x02,
1312  LOWBAT_LowBatTrim2 = 0x04,
1313  _LOWBAT_LowBatTrim_MASK = 7,
1314  _LOWBAT_LowBatTrim_SHIFT = 0,
1315 
1316  LOWBAT_LowBatOn = 0x08
1317 
1318  // 0x10-0z80 reserved
1319  } LOWBAT_BITS_T;
1320 
1324  typedef enum {
1325  LOWBATTRIM_1_695 = 0, // 1.695v
1326  LOWBATTRIM_1_764 = 1,
1327  LOWBATTRIM_1_835 = 2,
1328  LOWBATTRIM_1_905 = 3,
1329  LOWBATTRIM_1_976 = 4,
1330  LOWBATTRIM_2_045 = 5,
1331  LOWBATTRIM_2_116 = 6,
1332  LOWBATTRIM_2_185 = 7
1333  } LOWBATTRIM_T;
1334 
1338  typedef enum {
1339  IRQFLAGS1_SyncAddressMatch = 0x01,
1340  IRQFLAGS1_PreambleDetect = 0x02,
1341  IRQFLAGS1_Timeout = 0x04,
1342  IRQFLAGS1_Rssi = 0x08,
1343  IRQFLAGS1_PllLock = 0x10,
1344  IRQFLAGS1_TxReady = 0x20,
1345  IRQFLAGS1_RxReady = 0x40,
1346  IRQFLAGS1_ModeReady = 0x80
1347  } IRQFLAGS1_BITS_T;
1348 
1352  typedef enum {
1353  IRQFLAGS2_LowBat = 0x01,
1354  IRQFLAGS2_CrcOk = 0x02,
1355  IRQFLAGS2_PayloadReady = 0x04,
1356  IRQFLAGS2_PacketSent = 0x08,
1357  IRQFLAGS2_FifoOverrun = 0x10,
1358  IRQFLAGS2_FifoLevel = 0x20,
1359  IRQFLAGS2_FifoEmpty = 0x40,
1360  IRQFLAGS2_FifoFull = 0x80
1361  } IRQFLAGS2_BITS_T;
1362 
1367  typedef enum {
1368  DOIMAPPING1_Dio3Mapping0 = 0x01,
1369  DOIMAPPING1_Dio3Mapping1 = 0x02,
1370  DOIMAPPING1_Dio3Mapping_MASK = 3,
1371  DOIMAPPING1_Dio3Mapping_SHIFT = 0,
1372 
1373  DOIMAPPING1_Dio2Mapping0 = 0x04,
1374  DOIMAPPING1_Dio2Mapping1 = 0x08,
1375  DOIMAPPING1_Dio2Mapping_MASK = 3,
1376  DOIMAPPING1_Dio2Mapping_SHIFT = 2,
1377 
1378  DOIMAPPING1_Dio1Mapping0 = 0x10,
1379  DOIMAPPING1_Dio1Mapping1 = 0x20,
1380  DOIMAPPING1_Dio1Mapping_MASK = 3,
1381  DOIMAPPING1_Dio1Mapping_SHIFT = 4,
1382 
1383  DOIMAPPING1_Dio0Mapping0 = 0x40,
1384  DOIMAPPING1_Dio0Mapping1 = 0x80,
1385  DOIMAPPING1_Dio0Mapping_MASK = 3,
1386  DOIMAPPING1_Dio0Mapping_SHIFT = 6,
1388 
1389 
1394  typedef enum {
1395  DOIMAPPING2_MapPreambleDetect = 0x01, // rssi intr(0), preambledet(1)
1396 
1397  // 0x02-0x08 reserved
1398 
1399  DOIMAPPING2_Dio5Mapping0 = 0x10,
1400  DOIMAPPING2_Dio5Mapping1 = 0x20,
1401  DOIMAPPING2_Dio5Mapping_MASK = 3,
1402  DOIMAPPING2_Dio5Mapping_SHIFT = 4,
1403 
1404  DOIMAPPING2_Dio4Mapping0 = 0x40,
1405  DOIMAPPING2_Dio4Mapping1 = 0x80,
1406  DOIMAPPING2_Dio4Mapping_MASK = 3,
1407  DOIMAPPING2_Dio4Mapping_SHIFT = 6,
1409 
1417  typedef enum {
1418  DIOMAPPING_00 = 0,
1419  DIOMAPPING_01 = 1,
1420  DIOMAPPING_10 = 2,
1421  DIOMAPPING_11 = 3
1422  } DIOMAPPING_T;
1423 
1424 
1428  typedef enum {
1429  // 0x01-0x40 reserved
1430 
1431  PLLHOP_FastHopOn = 0x80
1432  } PLLHOP_BITS_T;
1433 
1437  typedef enum {
1438  // 0x01-0x08 reserved
1439 
1440  TCXO_TcxoOn = 0x10
1441 
1442  // 0x20-0x80 reserved
1443  } TCXO_BITS_T;
1444 
1448  typedef enum {
1449  PADAC_PaDac0 = 0x01,
1450  PADAC_PaDac1 = 0x02,
1451  PADAC_PaDac2 = 0x04,
1452  _PADAC_PaDac_MASK = 7,
1453  _PADAC_PaDac_SHIFT = 0
1454 
1455  // 0x08-0x80 reserved
1456  } PADAC_BITS_T;
1457 
1461  typedef enum {
1462  PADAC_DEFAULT = 4,
1463  PADAC_BOOST = 7 // +20dBm on PA_BOOST when
1464  // OuputPower = 1111
1465  // other values reserved
1466  } PADAC_T;
1467 
1471  typedef enum {
1472  BITRATEFRAC_BitRateFrac0 = 0x01,
1473  BITRATEFRAC_BitRateFrac1 = 0x02,
1474  BITRATEFRAC_BitRateFrac2 = 0x04,
1475  BITRATEFRAC_BitRateFrac3 = 0x08,
1476  _BITRATEFRAC_BitRateFrac_MASK = 15,
1477  _BITRATEFRAC_BitRateFrac_SHIFT = 0
1478 
1479  // 0x10-0x80 reserved
1481 
1488  typedef enum {
1489  AGCREF_AgcReferenceLevel0 = 0x01,
1490  AGCREF_AgcReferenceLevel1 = 0x02,
1491  AGCREF_AgcReferenceLevel2 = 0x04,
1492  AGCREF_AgcReferenceLevel3 = 0x08,
1493  AGCREF_AgcReferenceLevel4 = 0x10,
1494  AGCREF_AgcReferenceLevel5 = 0x20,
1495  _AGCREF_AgcReferenceLevel_MASK = 63,
1496  _AGCREF_AgcReferenceLevel_SHIFT = 0
1497 
1498  // 0x40-0x80 reserved
1499  } ACFREF_BITS_T;
1500 
1507  typedef enum {
1508  AGCTHRESH1_AcgStep10 = 0x01,
1509  AGCTHRESH1_AcgStep11 = 0x02,
1510  AGCTHRESH1_AcgStep12 = 0x04,
1511  AGCTHRESH1_AcgStep13 = 0x08,
1512  _AGCTHRESH1_AcgStep1_MASK = 15,
1513  _AGCTHRESH1_AcgStep1_SHIFT = 0,
1514 
1515  // 0x10-0x80 reserved
1517 
1524  typedef enum {
1525  AGCTHRESH2_AcgStep30 = 0x01,
1526  AGCTHRESH2_AcgStep31 = 0x02,
1527  AGCTHRESH2_AcgStep32 = 0x04,
1528  AGCTHRESH2_AcgStep33 = 0x08,
1529  _AGCTHRESH2_AcgStep3_MASK = 15,
1530  _AGCTHRESH2_AcgStep3_SHIFT = 0,
1531 
1532  AGCTHRESH2_AcgStep20 = 0x10,
1533  AGCTHRESH2_AcgStep21 = 0x20,
1534  AGCTHRESH2_AcgStep22 = 0x40,
1535  AGCTHRESH2_AcgStep23 = 0x80,
1536  _AGCTHRESH2_AcgStep2_MASK = 15,
1537  _AGCTHRESH2_AcgStep2_SHIFT = 4
1539 
1543  typedef enum {
1544  LOR_DetectionThreshold_SF7_SF12 = 0x0a,
1545  LOR_DetectionThreshold_SF6 = 0x0c
1547 
1554  typedef enum {
1555  AGCTHRESH3_AcgStep50 = 0x01,
1556  AGCTHRESH3_AcgStep51 = 0x02,
1557  AGCTHRESH3_AcgStep52 = 0x04,
1558  AGCTHRESH3_AcgStep53 = 0x08,
1559  _AGCTHRESH3_AcgStep5_MASK = 15,
1560  _AGCTHRESH3_AcgStep5_SHIFT = 0,
1561 
1562  AGCTHRESH3_AcgStep40 = 0x10,
1563  AGCTHRESH3_AcgStep41 = 0x20,
1564  AGCTHRESH3_AcgStep42 = 0x40,
1565  AGCTHRESH3_AcgStep43 = 0x80,
1566  _AGCTHRESH3_AcgStep4_MASK = 15,
1567  _AGCTHRESH3_AcgStep4_SHIFT = 4
1569 
1570 
1588  SX1276(uint8_t chipRev=chipRevision, int bus=1, int cs=10, int resetPin=14,
1589  int dio0=2, int dio1=3, int dio2=4, int dio3=5, int dio4=17,
1590  int dio5=9);
1591 
1595  ~SX1276();
1596 
1603  uint8_t readReg(uint8_t reg);
1604 
1612  bool writeReg(uint8_t reg, uint8_t val);
1613 
1619  uint8_t getChipVersion();
1620 
1624  void reset();
1625 
1632  void readFifo(uint8_t *buffer, int len);
1633 
1640  void writeFifo(uint8_t *buffer, int len);
1641 
1647  void setChannel(uint32_t freq);
1648 
1654  void setOpMode(MODE_T opMode);
1655 
1662  void setModem(RADIO_MODEM_T modem);
1663 
1667  void setSleep();
1668 
1672  void setStandby();
1673 
1680  int16_t getRSSI(RADIO_MODEM_T modem);
1681 
1691  bool isChannelFree(RADIO_MODEM_T modem, uint32_t freq, int16_t rssiThresh);
1692 
1702  RADIO_EVENT_T sendStr(std::string buffer, int timeout);
1703 
1713  RADIO_EVENT_T send(uint8_t *buffer, uint8_t size, int timeout);
1714 
1757  void setRxConfig(RADIO_MODEM_T modem, uint32_t bandwidth,
1758  uint32_t datarate, uint8_t coderate,
1759  uint32_t bandwidthAfc, uint16_t preambleLen,
1760  uint16_t symbTimeout, bool fixLen,
1761  uint8_t payloadLen,
1762  bool crcOn, bool freqHopOn, uint8_t hopPeriod,
1763  bool iqInverted, bool rxContinuous);
1764 
1802  void setTxConfig(RADIO_MODEM_T modem, int8_t power, uint32_t fdev,
1803  uint32_t bandwidth, uint32_t datarate,
1804  uint8_t coderate, uint16_t preambleLen,
1805  bool fixLen, bool crcOn, bool freqHopOn,
1806  uint8_t hopPeriod, bool iqInverted);
1807 
1818  RADIO_EVENT_T setRx(uint32_t timeout);
1819 
1826  std::string getRxBufferStr()
1827  {
1828  std::string rBuffer((char *)m_rxBuffer, getRxLen());
1829  return rBuffer;
1830  };
1831 
1839  uint8_t *getRxBuffer()
1840  {
1841  return (uint8_t*)m_rxBuffer;
1842  };
1843 
1852  {
1853  return m_rxRSSI;
1854  };
1855 
1862  int getRxSNR()
1863  {
1864  return m_rxSNR;
1865  };
1866 
1873  int getRxLen()
1874  {
1875  return m_rxLen;
1876  };
1877 
1878 
1879  protected:
1880  // I/O
1881  mraa::Spi m_spi;
1882  mraa::Gpio m_gpioCS;
1883  mraa::Gpio m_gpioReset;
1884 
1885  mraa::Gpio m_gpioDIO0;
1886  mraa::Gpio m_gpioDIO1;
1887  mraa::Gpio m_gpioDIO2;
1888  mraa::Gpio m_gpioDIO3;
1889  mraa::Gpio m_gpioDIO4;
1890  mraa::Gpio m_gpioDIO5;
1891 
1892  // calibration called during init()
1893  void rxChainCalibration();
1894 
1895  // interrupt handlers
1896  static void onDio0Irq(void *ctx);
1897  static void onDio1Irq(void *ctx);
1898  static void onDio2Irq(void *ctx);
1899  static void onDio3Irq(void *ctx);
1900  static void onDio4Irq(void *ctx);
1901  static void onDio5Irq(void *ctx);
1902 
1906  typedef enum {
1907  STATE_IDLE = 0,
1908  STATE_RX_RUNNING,
1909  STATE_TX_RUNNING,
1910  STATE_CAD
1911  } RADIO_STATES_T;
1912 
1913  // needs to be OR'd onto registers for SPI write
1914  static const uint8_t m_writeMode = 0x80;
1915 
1916  // initialize the chip
1917  void init();
1918 
1919  // Start a transmit event (you should use send() or sendStr()
1920  // rather than call this function directly.
1921  RADIO_EVENT_T setTx(int timeout);
1922 
1923  void startCAD(); // non-functional/non-tested
1924 
1925  // not really used, maybe it should be
1926  void setMaxPayloadLength(RADIO_MODEM_T modem, uint8_t max);
1927 
1928  // Chip Select control (active LOW)
1929  void csOn()
1930  {
1931  m_gpioCS.write(0);
1932  };
1933 
1934  void csOff()
1935  {
1936  m_gpioCS.write(1);
1937  };
1938 
1939  private:
1940  // Thse structs will generate SWIG warnings, as we do not expose
1941  // this data, they can be ignored.
1942 
1943  // stored settings for the FSK modem
1944  typedef struct
1945  {
1946  int8_t Power;
1947  uint32_t Fdev;
1948  uint32_t Bandwidth;
1949  uint32_t BandwidthAfc;
1950  uint32_t Datarate;
1951  uint16_t PreambleLen;
1952  bool FixLen;
1953  uint8_t PayloadLen;
1954  bool CrcOn;
1955  bool IqInverted;
1956  bool RxContinuous;
1957  } radioFskSettings_t;
1958 
1959  // stored settings for the LoRa modem
1960  typedef struct
1961  {
1962  int8_t Power;
1963  uint32_t Bandwidth;
1964  uint32_t Datarate;
1965  bool LowDatarateOptimize;
1966  uint8_t Coderate;
1967  uint16_t PreambleLen;
1968  bool FixLen;
1969  uint8_t PayloadLen;
1970  bool CrcOn;
1971  bool FreqHopOn;
1972  uint8_t HopPeriod;
1973  bool IqInverted;
1974  bool RxContinuous;
1975  } radioLoRaSettings_t;
1976 
1977  // FSK packet handler state
1978  typedef struct
1979  {
1980  uint8_t PreambleDetected;
1981  uint8_t SyncWordDetected;
1982  int8_t RssiValue;
1983  int32_t AfcValue;
1984  uint8_t RxGain;
1985  uint16_t Size;
1986  uint16_t NbBytes;
1987  uint8_t FifoThresh;
1988  uint8_t ChunkSize;
1989  } radioFskPacketHandler_t;
1990 
1991  // LoRa packet handler state
1992  typedef struct
1993  {
1994  int8_t SnrValue;
1995  int16_t RssiValue;
1996  uint8_t Size;
1997  } radioLoRaPacketHandler_t;
1998 
1999  // our radio settings
2000  struct {
2001  RADIO_MODEM_T modem;
2002  volatile RADIO_STATES_T state;
2003  uint32_t channel;
2004 
2005  radioFskSettings_t fskSettings;
2006  volatile radioFskPacketHandler_t fskPacketHandler;
2007 
2008  radioLoRaSettings_t loraSettings;
2009  volatile radioLoRaPacketHandler_t loraPacketHandler;
2010  } m_settings;
2011 
2012  uint8_t lookupFSKBandWidth(uint32_t bw);
2013 
2014  // received data (on successfull completion)
2015  volatile int m_rxRSSI;
2016  volatile int m_rxSNR;
2017  volatile int m_rxLen;
2018  uint8_t m_rxBuffer[FIFO_SIZE];
2019 
2020  // for coordinating interrupt access
2021  pthread_mutex_t m_intrLock;
2022 
2023  void lockIntrs() { pthread_mutex_lock(&m_intrLock); };
2024  void unlockIntrs() { pthread_mutex_unlock(&m_intrLock); };
2025 
2026  // current radio event status
2027  volatile RADIO_EVENT_T m_radioEvent;
2028 
2029  // timer support
2030  struct timeval m_startTime;
2031  void initClock();
2032  uint32_t getMillis();
2033  };
2034 }
2035 
2036 
FROMSTART_T
Definition: sx1276.h:1184
LOR_DETECTIONTHRESHOLD_T
Definition: sx1276.h:1543
SX1276(uint8_t chipRev=chipRevision, int bus=1, int cs=10, int resetPin=14, int dio0=2, int dio1=3, int dio2=4, int dio3=5, int dio4=17, int dio5=9)
Definition: sx1276.cxx:77
MODE_T
Definition: sx1276.h:406
OSC_BITS_T
Definition: sx1276.h:963
CODINGRATE_T
Definition: sx1276.h:868
ADDRESSFILTERING_T
Definition: sx1276.h:1072
DETECTIONOPTIMIZE_T
Definition: sx1276.h:1124
SPREADINGFACTOR_T
Definition: sx1276.h:917
LOR_IRQFLAG_BITS_T
Definition: sx1276.h:643
OOKPEAKTHRESHSTEP_T
Definition: sx1276.h:719
IRQFLAGS1_BITS_T
Definition: sx1276.h:1338
void readFifo(uint8_t *buffer, int len)
Definition: sx1276.cxx:202
void setRxConfig(RADIO_MODEM_T modem, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, uint16_t symbTimeout, bool fixLen, uint8_t payloadLen, bool crcOn, bool freqHopOn, uint8_t hopPeriod, bool iqInverted, bool rxContinuous)
Definition: sx1276.cxx:640
PACKETCONFIG1_BITS_T
Definition: sx1276.h:1050
LNAGAIN_T
Definition: sx1276.h:578
OPMODE_BITS_T
Definition: sx1276.h:379
RSSISMOOTHING_T
Definition: sx1276.h:629
OOKPEAK_BITS_T
Definition: sx1276.h:699
IRQFLAGS2_BITS_T
Definition: sx1276.h:1352
BITRATEFRAC_BITS_T
Definition: sx1276.h:1471
void setOpMode(MODE_T opMode)
Definition: sx1276.cxx:383
BW_T
Definition: sx1276.h:878
MODSHAPING_T
Definition: sx1276.h:504
DIOMAPPING_T
Definition: sx1276.h:1417
~SX1276()
Definition: sx1276.cxx:163
DIOMAPPING2_BITS_T
Definition: sx1276.h:1394
void writeFifo(uint8_t *buffer, int len)
Definition: sx1276.cxx:233
FIFOTHRESH_BITS_T
Definition: sx1276.h:1148
RXBWMANT_T
Definition: sx1276.h:675
ACGTHRESH2_BITS_T
Definition: sx1276.h:1524
CLKOUT_T
Definition: sx1276.h:978
LNA_BITS_T
Definition: sx1276.h:538
RADIO_EVENT_T send(uint8_t *buffer, uint8_t size, int timeout)
Definition: sx1276.cxx:551
DETECTOPTIMIZE_BITS_T
Definition: sx1276.h:1111
OOKAVGTHRESHFILT_T
Definition: sx1276.h:766
void reset()
Definition: sx1276.cxx:271
TEMPTHRESHOLD_T
Definition: sx1276.h:1299
TIMERRESOLUTION_T
Definition: sx1276.h:1269
PADAC_BITS_T
Definition: sx1276.h:1448
RSSICONFIG_BITS_T
Definition: sx1276.h:610
LNABOOSTLF_T
Definition: sx1276.h:570
AUTORESTARTMODE_T
Definition: sx1276.h:1026
RXBWEXP_T
Definition: sx1276.h:685
int getRxSNR()
Definition: sx1276.h:1862
RADIO_EVENT_T
Definition: sx1276.h:128
FSK_MODULATION_TYPE_T
Definition: sx1276.h:426
OOKAVGOFFSET_T
Definition: sx1276.h:776
AFCFEI_BITS_T
Definition: sx1276.h:817
void setChannel(uint32_t freq)
Definition: sx1276.cxx:372
RXBW_BITS_T
Definition: sx1276.h:658
void setTxConfig(RADIO_MODEM_T modem, int8_t power, uint32_t fdev, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint16_t preambleLen, bool fixLen, bool crcOn, bool freqHopOn, uint8_t hopPeriod, bool iqInverted)
Definition: sx1276.cxx:888
PREAMBLEDETECT_BITS_T
Definition: sx1276.h:932
MODEMCONFIG1_BITS_T
Definition: sx1276.h:848
RADIO_STATES_T
Definition: sx1276.h:1906
OCP_BITS_T
Definition: sx1276.h:522
ACGTHRESH3_BITS_T
Definition: sx1276.h:1554
OOKAVG_BITS_T
Definition: sx1276.h:743
MODEMCONFIG2_BITS_T
Definition: sx1276.h:896
uint8_t getChipVersion()
Definition: sx1276.cxx:265
SEQCONFIG2_BITS_T
Definition: sx1276.h:1194
LOWBATTRIM_T
Definition: sx1276.h:1324
void setStandby()
Definition: sx1276.cxx:503
bool isChannelFree(RADIO_MODEM_T modem, uint32_t freq, int16_t rssiThresh)
Definition: sx1276.cxx:437
PARAMP_T
Definition: sx1276.h:479
DIOMAPPING1_BITS_T
Definition: sx1276.h:1367
PARAMP_BITS_T
Definition: sx1276.h:456
LNABOOSTHF_T
Definition: sx1276.h:561
PREAMBLEDETECTORSIZE_T
Definition: sx1276.h:952
LOWBAT_BITS_T
Definition: sx1276.h:1309
void setModem(RADIO_MODEM_T modem)
Definition: sx1276.cxx:398
SX1276_REGS_T
Definition: sx1276.h:147
std::string getRxBufferStr()
Definition: sx1276.h:1826
uint8_t * getRxBuffer()
Definition: sx1276.h:1839
TCXO_BITS_T
Definition: sx1276.h:1437
RADIO_MODEM_T
Definition: sx1276.h:110
uint8_t readReg(uint8_t reg)
Definition: sx1276.cxx:168
SEQCONFIG1_BITS_T
Definition: sx1276.h:1166
FROMPACKETRECEIVED_T
Definition: sx1276.h:1216
HOPCHANNEL_BITS_T
Definition: sx1276.h:831
int getRxRSSI()
Definition: sx1276.h:1851
ACGTHRESH1_BITS_T
Definition: sx1276.h:1507
PADAC_T
Definition: sx1276.h:1461
ACFREF_BITS_T
Definition: sx1276.h:1488
RADIO_EVENT_T setRx(uint32_t timeout)
Definition: sx1276.cxx:1277
MODEMSTAT_BITS_T
Definition: sx1276.h:800
RADIO_EVENT_T sendStr(std::string buffer, int timeout)
Definition: sx1276.cxx:534
PACONFIG_BITS_T
Definition: sx1276.h:435
RXCONFIG_BITS_T
Definition: sx1276.h:593
int16_t getRSSI(RADIO_MODEM_T modem)
Definition: sx1276.cxx:462
DCFREE_T
Definition: sx1276.h:1081
IMAGECAL_BITS_T
Definition: sx1276.h:1279
OOKTHRESHTYPE_T
Definition: sx1276.h:733
bool writeReg(uint8_t reg, uint8_t val)
Definition: sx1276.cxx:185
int getRxLen()
Definition: sx1276.h:1873
void setSleep()
Definition: sx1276.cxx:497
OOKPEAKTHRESHDEC_T
Definition: sx1276.h:786
FROMRECEIVE_T
Definition: sx1276.h:1239
MODEMCONFIG3_BITS_T
Definition: sx1276.h:992
FEIMSB_BITS_T
Definition: sx1276.h:1036
API for the SX1276 LoRa/FSK modem.
Definition: sx1276.h:90
PACKETCONFIG2_BITS_T
Definition: sx1276.h:1091
FROMRXTIMEOUT_T
Definition: sx1276.h:1229
TIMERRESOL_BITS_T
Definition: sx1276.h:1252
PLLHOP_BITS_T
Definition: sx1276.h:1428
INVERTIQ_BITS_T
Definition: sx1276.h:1134
SYNCCONFIG_BITS_T
Definition: sx1276.h:1005