36 #include <sys/select.h>
37 #include <sys/types.h>
41 #include <mraa/common.hpp>
42 #include <mraa/spi.hpp>
43 #include <mraa/gpio.hpp>
46 #define FXOSC_FREQ 32000000.0
50 #define FXOSC_STEP 61.03515625
94 static const uint8_t chipRevision = 0x12;
98 static const int FIFO_SIZE = 256;
101 static const int RF_MID_BAND_THRESH = 525000000;
104 static const int LOR_RSSI_OFFSET_HF = -157;
105 static const int LOR_RSSI_OFFSET_LF = -164;
149 COM_RegOpMode = 0x01,
151 FSK_RegBitrateMsb = 0x02,
152 LOR_Reserved02 = 0x02,
154 FSK_RegBitrateLsb = 0x03,
155 LOR_Reserved03 = 0x03,
157 FSK_RegFdevMsb = 0x04,
158 LOR_Reserved04 = 0x04,
160 FSK_RegFdevLsb = 0x05,
161 LOR_Reserved05 = 0x05,
163 COM_RegFrfMsb = 0x06,
164 COM_RegFrfMid = 0x07,
165 COM_RegFrfLsb = 0x08,
166 COM_RegPaConfig = 0x09,
167 COM_RegPaRamp = 0x0a,
172 FSK_RegRxConfig = 0x0d,
173 LOR_RegFifoAddrPtr = 0x0d,
175 FSK_RegRssiConfg = 0x0e,
176 LOR_RegFifoTxBaseAddr = 0x0e,
178 FSK_RegRssiCollision = 0x0f,
179 LOR_RegFifoRxBaseAddr = 0x0f,
181 FSK_RegRssiThresh = 0x10,
182 LOR_RegFifoRxCurrentAddr = 0x10,
184 FSK_RegRssiValue = 0x11,
185 LOR_RegIrqFlagsMask = 0x11,
188 LOR_RegIrqFlags = 0x12,
191 LOR_RegRxNbBytes = 0x13,
193 FSK_RegOokPeak = 0x14,
194 LOR_RegRxHeaderCntValueMsb = 0x14,
196 FSK_RegOokFix = 0x15,
197 LOR_RegRxHeaderCntValueLsb = 0x15,
199 FSK_RegOokAvg = 0x16,
200 LOR_RegRxPacketCntValueMsb = 0x16,
202 FSK_Reserved17 = 0x17,
203 LOR_RegRxPacketCntValueLsb = 0x17,
205 FSK_Reserved18 = 0x18,
206 LOR_RegModemStat = 0x18,
208 FSK_Reserved19 = 0x19,
209 LOR_RegPktSnrValue = 0x19,
211 FSK_RegAfcFei = 0x1a,
212 LOR_RegPktRssiValue = 0x1a,
214 FSK_RegAfcMsb = 0x1b,
215 LOR_RegRssiValue = 0x1b,
217 FSK_RegAfcLsb = 0x1c,
218 LOR_RegHopChannel = 0x1c,
220 FSK_RegFeiMsb = 0x1d,
221 LOR_RegModemConfig1 = 0x1d,
223 FSK_RegFeiLsb = 0x1e,
224 LOR_RegModemConfig2 = 0x1e,
226 FSK_RegPreambleDetect = 0x1f,
227 LOR_RegSymbTimeoutLsb = 0x1f,
229 FSK_RegRxTimeout1 = 0x20,
230 LOR_RegPreambleMsb = 0x20,
232 FSK_RegRxTimeout2 = 0x21,
233 LOR_RegPreambleLsb = 0x21,
235 FSK_RegRxTimeout3 = 0x22,
236 LOR_RegPayloadLength = 0x22,
238 FSK_RegRxDelay = 0x23,
239 LOR_RegMaxPayloadLength = 0x23,
242 LOR_RegHopPeriod = 0x24,
244 FSK_RegPreambleMsb = 0x25,
245 LOR_RegFifoRxByteAddr = 0x25,
247 FSK_RegPreambleLsb = 0x26,
248 LOR_RegModemConfig3 = 0x26,
250 FSK_RegSyncConfig = 0x27,
251 LOR_Reserved27 = 0x27,
253 FSK_RegSyncValue1 = 0x28,
254 LOR_RegFeiMsb = 0x28,
256 FSK_RegSyncValue2 = 0x29,
257 LOR_RegFeiMid = 0x29,
259 FSK_RegSyncValue3 = 0x2a,
260 LOR_RegFeiLsb = 0x2a,
262 FSK_RegSyncValue4 = 0x2b,
263 LOR_Reserved2b = 0x2b,
265 FSK_RegSyncValue5 = 0x2c,
266 LOR_RegRssiWideband = 0x2c,
268 FSK_RegSyncValue6 = 0x2d,
269 LOR_Reserved2d = 0x2d,
271 FSK_RegSyncValue7 = 0x2e,
272 LOR_Reserved2e = 0x2e,
274 FSK_RegSyncValue8 = 0x2f,
275 LOR_Reserved2f = 0x2f,
277 FSK_RegPacketConfig1 = 0x30,
278 LOR_Reserved30 = 0x30,
280 FSK_RegPacketConfig2 = 0x31,
281 LOR_RegDetectOptimize = 0x31,
283 FSK_RegPayloadLength = 0x32,
284 LOR_Reserved32 = 0x32,
286 FSK_RegNodeAddr = 0x33,
287 LOR_RegInvertIQ = 0x33,
289 FSK_RegBroadcastAddr = 0x34,
290 LOR_Reserved34 = 0x34,
292 FSK_RegFifoThresh = 0x35,
293 LOR_Reserved35 = 0x35,
295 FSK_RegSeqConfig1 = 0x36,
296 LOR_Reserved36 = 0x36,
298 FSK_RegSeqConfig2 = 0x37,
299 LOR_RegDetectionThreshold = 0x37,
301 FSK_RegTimerResol = 0x38,
302 LOR_Reserved38 = 0x38,
304 FSK_RegTimer1Coeff = 0x39,
305 LOR_RegSyncWord = 0x39,
307 FSK_RegTimer2Coeff = 0x3a,
308 LOR_Reserved3a = 0x3a,
310 FSK_RegImageCal = 0x3b,
311 LOR_Reserved3b = 0x3b,
312 LOR_RegInvertIQ2 = 0x3b,
317 LOR_Reserved3c = 0x3c,
319 FSK_RegLowBat = 0x3d,
320 LOR_Reserved3d = 0x3d,
322 FSK_RegIrqFlags1 = 0x3e,
323 LOR_Reserved3e = 0x3e,
325 FSK_RegIrqFlags2 = 0x3f,
326 LOR_Reserved3f = 0x3f,
328 COM_RegDioMapping1 = 0x40,
329 COM_RegDioMapping2 = 0x41,
331 COM_RegVersion = 0x42,
342 FSK_Reserved44 = 0x44,
343 LOR_RegPllHop = 0x44,
355 COM_RegFormerTemp = 0x5b,
359 FSK_RegBitRateFrac = 0x5d,
360 LOR_Reserved5d = 0x5d,
364 COM_RegAgcRef = 0x61,
365 COM_RegAgcThresh1 = 0x62,
366 COM_RegAgcThresh2 = 0x63,
367 COM_RegAgcThresh3 = 0x64,
383 _OPMODE_Mode_MASK = 7,
384 _OPMODE_Mode_SHIFT = 0,
386 OPMODE_LowFrequencyModeOn = 0x08,
390 OPMODE_FSK_ModulationType0 = 0x20,
391 OPMODE_FSK_ModulationType1 = 0x40,
392 _OPMODE_FSK_ModulationType_MASK = 3,
393 _OPMODE_FSK_ModulationType_SHIFT = 5,
395 OPMODE_LOR_Reserved0x20 = 0x20,
397 OPMODE_LOR_AccessSharedReg = 0x40,
399 OPMODE_LongRangeMode = 0x80
414 MODE_LOR_RxContinuous = 5,
416 MODE_FSK_Reserved6 = 6,
417 MODE_LOR_RxSingle = 6,
419 MODE_FSK_Reserved7 = 7,
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,
443 PACONFIG_MaxPower0 = 0x10,
444 PACONFIG_MaxPower1 = 0x20,
445 PACONFIG_MaxPower2 = 0x40,
446 _PACONFIG_MaxPower_MASK = 7,
447 _PACONFIG_MaxPower_SHIFT = 4,
449 PACONFIG_PaSelect = 0x80
457 PARAMP_PaRamp0 = 0x01,
458 PARAMP_PaRamp1 = 0x02,
459 PARAMP_PaRamp2 = 0x04,
460 PARAMP_PaRamp3 = 0x08,
461 _PARAMP_PaRamp_MASK = 15,
462 _PARAMP_PaRamp_SHIFT = 0,
468 PARAMP_FSK_ModulationShaping0 = 0x20,
469 PARAMP_FSK_ModulationShaping1 = 0x40,
470 _PARAMP_FSK_ModulationShaping_MASK = 3,
471 _PARAMP_FSK_ModulationShaping_SHIFT = 5
505 MODSHAPING_NOSHAPING = 0,
508 MODSHAPING_FSK_GaussianFilterBT1 = 1,
509 MODSHAPING_FSK_GaussianFilterBT05 = 2,
510 MODSHAPING_FSK_GaussianFilterBT03 = 3,
513 MODSHAPING_OOK_FCutoffBitRate = 1,
514 MODSHAPING_OOK_FCutoffBitRate2 = 2
527 _OCP_OcpTrim_MASK = 15,
528 _OCP_OcpTrim_SHIFT = 0,
539 LNA_LnaBoostHf0 = 0x01,
540 LNA_LnaBoostHf1 = 0x02,
541 _LNA_LnaBoostHf_MASK = 3,
542 _LNA_LnaBoostHf_SHIFT = 0,
546 LNA_LnaBoostLf0 = 0x08,
547 LNA_LnaBoostLf1 = 0x10,
548 _LNA_LnaBoostLf_MASK = 3,
549 _LNA_LnaBoostLf_SHIFT = 3,
554 _LNA_LnaGain_MASK = 7,
555 _LNA_LnaGain_SHIFT = 5
562 LNABOOSTHF_Default = 0,
564 LNABOOSTHF_BoostOn = 3,
571 LNABOOSTLF_Default = 0
594 RXCONFIG_RxTrigger0 = 0x01,
595 RXCONFIG_RxTrigger1 = 0x02,
596 RXCONFIG_RxTrigger2 = 0x04,
597 _RXCONFIG_RxTrigger_MASK = 7,
598 _RXCONFIG_RxTrigger_SHIFT = 0,
600 RXCONFIG_AgcAutoOn = 0x08,
601 RXCONFIG_AfcAutoOn = 0x10,
602 RXCONFIG_RestartRxWithPllLock = 0x20,
603 RXCONFIG_RestartRxWithoutPllLock = 0x40,
604 RXCONFIG_RestartRxOnCollision = 0x80
611 RSSICONFIG_RssiSmoothing0 = 0x01,
612 RSSICONFIG_RssiSmoothing1 = 0x02,
613 RSSICONFIG_RssiSmoothing2 = 0x04,
614 _RSSICONFIG_RssiSmoothing_MASK = 7,
615 _RSSICONFIG_RssiSmoothing_SHIFT = 0,
617 RSSICONFIG_RssiOffset0 = 0x08,
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
633 RSSISMOOTHING_16 = 3,
634 RSSISMOOTHING_32 = 4,
635 RSSISMOOTHING_64 = 5,
636 RSSISMOOTHING_128 = 6,
637 RSSISMOOTHING_256 = 7
644 LOR_IRQFLAG_CadDetected = 0x01,
645 LOR_IRQFLAG_FhssChangeChannel = 0x02,
646 LOR_IRQFLAG_CadDone = 0x04,
647 LOR_IRQFLAG_TxDone = 0x08,
649 LOR_IRQFLAG_ValidHeader = 0x10,
650 LOR_IRQFLAG_PayloadCrcError = 0x20,
651 LOR_IRQFLAG_RxDone = 0x40,
652 LOR_IRQFLAG_RxTimeout = 0x80
659 RXBW_RxBwExp0 = 0x01,
660 RXBW_RxBwExp1 = 0x02,
661 RXBW_RxBwExp2 = 0x04,
662 _RXBW_RxBwExp_MASK = 7,
663 _RXBW_RxBwExp_SHIFT = 0,
665 RXBW_RxBwMant0 = 0x08,
666 RXBW_RxBwMant1 = 0x10,
667 _RXBW_RxBwMant_MASK = 3,
668 _RXBW_RxBwMant_SHIFT = 3,
700 OOKPEAK_OokPeakThreshStep0 = 0x01,
701 OOKPEAK_OokPeakThreshStep1 = 0x02,
702 OOKPEAK_OokPeakThreshStep2 = 0x04,
703 _OOKPEAK_OokPeakThreshStep_MASK = 7,
704 _OOKPEAK_OokPeakThreshStep_SHIFT = 0,
706 OOKPEAK_OokThreshType0 = 0x08,
707 OOKPEAK_OokThreshType1 = 0x10,
708 _OOKPEAK_OokThreshType_MASK = 3,
709 _OOKPEAK_OokThreshType_SHIFT = 3,
711 OOKPEAK_BitSyncOn = 0x20,
720 OOKPEAKTHRESHSTEP_05dB = 0,
721 OOKPEAKTHRESHSTEP_1dB = 1,
722 OOKPEAKTHRESHSTEP_15dB = 2,
723 OOKPEAKTHRESHSTEP_2dB = 3,
724 OOKPEAKTHRESHSTEP_3dB = 4,
725 OOKPEAKTHRESHSTEP_4dB = 5,
726 OOKPEAKTHRESHSTEP_5dB = 6,
727 OOKPEAKTHRESHSTEP_6dB = 7
734 OOKTHRESHTYPE_FIXED = 0,
735 OOKTHRESHTYPE_PEAK = 1,
736 OOKTHRESHTYPE_AVERAGE = 2
744 OOKAVG_OokAvgThreshFilt0 = 0x01,
745 OOKAVG_OokAvgThreshFilt1 = 0x02,
746 _OOKAVG_OokAvgThreshFilt_MASK = 3,
747 _OOKAVG_OokAvgThreshFilt_SHIFT = 0,
749 OOKAVG_OokAvgOffset0 = 0x04,
750 OOKAVG_OokAvgOffset1 = 0x08,
751 _OOKAVG_OokAvgOffset_MASK = 3,
752 _OOKAVG_OokAvgOffset_SHIFT = 2,
756 OOKAVG_OokPeakThreshDec0 = 0x20,
757 OOKAVG_OokPeakThreshDec1 = 0x40,
758 OOKAVG_OokPeakThreshDec2 = 0x80,
759 _OOKAVG_OokPeakThreshDec_MASK = 7,
760 _OOKAVG_OokPeakThreshDec_SHIFT = 5
767 OOKAVGTHRESHFILT_32 = 0,
768 OOKAVGTHRESHFILT_8 = 1,
769 OOKAVGTHRESHFILT_4 = 2,
770 OOKAVGTHRESHFILT_2 = 3
787 OOKPEAKTHRESHDEC_1_1 = 0,
788 OOKPEAKTHRESHDEC_1_2 = 1,
789 OOKPEAKTHRESHDEC_1_4 = 2,
790 OOKPEAKTHRESHDEC_1_8 = 3,
791 OOKPEAKTHRESHDEC_2_1 = 4,
792 OOKPEAKTHRESHDEC_4_1 = 5,
793 OOKPEAKTHRESHDEC_8_1 = 6,
794 OOKPEAKTHRESHDEC_16_1 = 7
801 MODEMSTAT_SignalDetected = 0x01,
802 MODEMSTAT_SignalSynchronized = 0x02,
803 MODEMSTAT_RxOngoing = 0x04,
804 MODEMSTAT_HeaderInfoValid = 0x08,
805 MODEMSTAT_ModemClear = 0x10,
807 MODEMSTAT_RxCodingRate0 = 0x20,
808 MODEMSTAT_RxCodingRate1 = 0x40,
809 MODEMSTAT_RxCodingRate2 = 0x80,
810 _MODEMSTAT_RxCodingRate_MASK = 7,
811 _MODEMSTAT_RxCodingRate_SHIFT = 5
818 AFCFEI_AfcAutoClearOn = 0x01,
819 AFCFEI_AfcClear = 0x02,
823 AFCFEI_AgcStart = 0x10
832 HOPCHANNEL_FhssPresentChannel0 = 0x01,
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,
841 HOPCHANNEL_CrcOnPayload = 0x40,
842 HOPCHANNEL_PllTimeout = 0x80
849 MODEMCONFIG1_ImplicitHeaderModeOn = 0x01,
851 MODEMCONFIG1_CodingRate0 = 0x02,
852 MODEMCONFIG1_CodingRate1 = 0x04,
853 MODEMCONFIG1_CodingRate2 = 0x08,
854 _MODEMCONFIG1_CodingRate_MASK = 7,
855 _MODEMCONFIG1_CodingRate_SHIFT = 0,
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
897 MODEMCONFIG2_SymbTimeoutMsb0 = 0x01,
898 MODEMCONFIG2_SymbTimeoutMsb1 = 0x02,
899 _MODEMCONFIG2_SymbTimeoutMsb_MASK = 3,
900 _MODEMCONFIG2_SymbTimeoutMsb_SHIFT = 0,
902 MODEMCONFIG2_RxPayloadCrcOn = 0x04,
904 MODEMCONFIG2_TxContinuousMode = 0x08,
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,
918 SPREADINGFACTOR_64 = 6,
919 SPREADINGFACTOR_128 = 7,
920 SPREADINGFACTOR_256 = 8,
921 SPREADINGFACTOR_512 = 9,
922 SPREADINGFACTOR_1024 = 10,
923 SPREADINGFACTOR_2048 = 11,
924 SPREADINGFACTOR_4096 = 12
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,
941 PREABLEDETECT_PreambleDetectorSize0 = 0x20,
942 PREABLEDETECT_PreambleDetectorSize1 = 0x40,
943 _PREABLEDETECT_PreambleDetectorSize_MASK = 3,
944 _PREABLEDETECT_PreambleDetectorSize_SHIFT = 5,
946 PREABLEDETECT_PreambleDetectorOn = 0x80
953 PREAMBLEDETECTORSIZE_1 = 0,
954 PREAMBLEDETECTORSIZE_2 = 1,
955 PREAMBLEDETECTORSIZE_3 = 2
967 _OSC_ClkOut_MASK = 7,
968 _OSC_ClkOut_SHIFT = 0,
970 OSC_RcCalStart = 0x08
995 MODEMCONFIG3_AgcAutoOn = 0x04,
996 MODEMCONFIG3_LowDataRateOptimize = 0x08
1006 SYNCCONFIG_SyncSize0 = 0x01,
1007 SYNCCONFIG_SyncSize1 = 0x02,
1008 SYNCCONFIG_SyncSize2 = 0x04,
1009 _SYNCCONFIG_SyncSize_MASK = 7,
1010 _SYNCCONFIG_SyncSize_SHIFT = 0,
1014 SYNCCONFIG_SyncOn = 0x10,
1015 SYNCCONFIG_PreamblePolarity = 0x20,
1017 SYNCCONFIG_AutoRestartMode0 = 0x40,
1018 SYNCCONFIG_AutoRestartMode1 = 0x80,
1019 _SYNCCONFIG_AutoRestartMode_MASK = 3,
1020 _SYNCCONFIG_AutoRestartMode_SHIFT = 6,
1027 AUTORESTARTMODE_OFF = 0,
1028 AUTORESTARTMODE_ON_NOPLL = 1,
1029 AUTORESTARTMODE_ON_PLL = 2
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
1051 PACKETCONFIG1_CrcWhiteningType = 0x01,
1053 PACKETCONFIG1_AddressFiltering0 = 0x02,
1054 PACKETCONFIG1_AddressFiltering1 = 0x04,
1055 _PACKETCONFIG1_AddressFiltering_MASK = 3,
1056 _PACKETCONFIG1_AddressFiltering_SHIFT = 1,
1058 PACKETCONFIG1_CrcAutoClearOff = 0x08,
1059 PACKETCONFIG1_CrcOn = 0x10,
1061 PACKETCONFIG1_DcFree0 = 0x20,
1062 PACKETCONFIG1_DcFree1 = 0x40,
1063 _PACKETCONFIG1_DcFree_MASK = 3,
1064 _PACKETCONFIG1_DcFree_SHIFT = 5,
1066 PACKETCONFIG1_PacketFormat = 0x80
1073 ADDRESSFILTERING_NONE = 0,
1074 ADDRESSFILTERING_NODE = 1,
1075 ADDRESSFILTERING_NODE_BROADCAST = 2,
1083 DCFREE_MANCHESTER = 1,
1084 DCFREE_WHITENING = 2
1092 PACKETCONFIG2_PayloadLengthMsb0 = 0x01,
1093 PACKETCONFIG2_PayloadLengthMsb1 = 0x02,
1094 PACKETCONFIG2_PayloadLengthMsb2 = 0x04,
1095 _PACKETCONFIG2_PayloadLengthMsb_MASK = 7,
1096 _PACKETCONFIG2_PayloadLengthMsb_SHIFT = 0,
1098 PACKETCONFIG2_BeaconOn = 0x08,
1102 PACKETCONFIG2_IoHomeOn = 0x20,
1103 PACKETCONFIG2_DataMode = 0x40,
1112 DETECTOPTIMIZE_DetectionOptimize0 = 0x01,
1113 DETECTOPTIMIZE_DetectionOptimize1 = 0x02,
1114 DETECTOPTIMIZE_DetectionOptimize2 = 0x04,
1115 _DETECTOPTIMIZE_DetectionOptimize_MASK = 7,
1116 _DETECTOPTIMIZE_DetectionOptimize_SHIFT = 0
1125 DETECTIONOPTIMIZE_SF7_SF12 = 3,
1126 DETECTIONOPTIMIZE_SF6 = 5
1135 INVERTIQ_InvertIQTxOff = 0x01,
1140 INVERTIQ_InvertIQRx = 0x40
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,
1160 FIFOTHRESH_TxStartCondition = 0x80
1167 SEQCONFIG1_FromTransit = 0x01,
1168 SEQCONFIG1_FromIdle = 0x02,
1169 SEQCONFIG1_LowPowerSelection = 0x04,
1171 SEQCONFIG1_FromStart0 = 0x08,
1172 SEQCONFIG1_FromStart1 = 0x10,
1173 _SEQCONFIG1_FromStart_MASK = 3,
1174 _SEQCONFIG1_FromStart_SHIFT = 3,
1176 SEQCONFIG1_IdleMode = 0x20,
1177 SEQCONFIG1_SequencerStop = 0x40,
1178 SEQCONFIG1_SequencerStart = 0x80
1185 FROMSTART_ToLowPowerSelection = 0,
1186 FROMSTART_ToReceiveState = 1,
1187 FROMSTART_ToTransmitState = 2,
1188 FROMSTART_ToTransmitStateOnFifoLevel = 3
1195 SEQCONFIG2_FromPacketReceived0 = 0x01,
1196 SEQCONFIG2_FromPacketReceived1 = 0x02,
1197 SEQCONFIG2_FromPacketReceived2 = 0x04,
1198 _SEQCONFIG2_FromPacketReceived_MASK = 7,
1199 _SEQCONFIG2_FromPacketReceived_SHIFT = 0,
1201 SEQCONFIG2_FromRxTimeout0 = 0x08,
1202 SEQCONFIG2_FromRxTimeout1 = 0x10,
1203 _SEQCONFIG2_FromRxTimeout_MASK = 3,
1204 _SEQCONFIG2_FromRxTimeout_SHIFT = 3,
1206 SEQCONFIG2_FromReceive0 = 0x20,
1207 SEQCONFIG2_FromReceive1 = 0x40,
1208 SEQCONFIG2_FromReceive2 = 0x80,
1209 _SEQCONFIG2_FromReceive_MASK = 3,
1210 _SEQCONFIG2_FromReceive_SHIFT = 5
1217 FROMPACKETRECEIVED_ToSequencerOff = 0,
1218 FROMPACKETRECEIVED_ToTransmitStateOnFifoEmpty = 1,
1219 FROMPACKETRECEIVED_ToLowPowerSelection = 2,
1220 FROMPACKETRECEIVED_ToReceiveViaFS = 3,
1221 FROMPACKETRECEIVED_ToReceive = 4
1230 FROMRXTIMEOUT_ToReceiveViaReceiveStart = 0,
1231 FROMRXTIMEOUT_ToTransmitState = 1,
1232 FROMRXTIMEOUT_ToLowPowerSelection = 2,
1233 FROMRXTIMEOUT_ToSequencerOffState = 3
1240 FROMRECEIVE_ToPcketReceived = 1,
1241 FROMRECEIVE_ToLowPowerSelection = 2,
1242 FROMRECEIVE_ToPacketReceived = 3,
1243 FROMRECEIVE_ToSequencerOffOnRSSI = 4,
1244 FROMRECEIVE_ToSequencerOffOnSync = 5,
1245 FROMRECEIVE_ToSequencerOffOnPreambleDetect = 6,
1253 TIMERRESOL_Timer2Resolution0 = 0x01,
1254 TIMERRESOL_Timer2Resolution1 = 0x02,
1255 _TIMERRESOL_Timer2Resolution_MASK = 3,
1256 _TIMERRESOL_Timer2Resolution_SHIFT = 0,
1258 TIMERRESOL_Timer1Resolution0 = 0x04,
1259 TIMERRESOL_Timer1Resolution1 = 0x08,
1260 _TIMERRESOL_Timer1Resolution_MASK = 3,
1261 _TIMERRESOL_Timer1Resolution_SHIFT = 2
1270 TIMERRESOLUTION_DISABLED = 0,
1271 TIMERRESOLUTION_64us = 1,
1272 TIMERRESOLUTION_4_1ms = 2,
1273 TIMERRESOLUTION_262ms = 3
1280 IMAGECAL_TempMonitorOff = 0x01,
1282 IMAGECAL_TempThreshold0 = 0x02,
1283 IMAGECAL_TempThreshold1 = 0x04,
1284 _IMAGECAL_TempThreshold_MASK = 3,
1285 _IMAGECAL_TempThreshold_SHIFT = 1,
1287 IMAGECAL_TenpChange = 0x08,
1291 IMAGECAL_ImageCalRunning = 0x20,
1292 IMAGECAL_ImageCalStart = 0x40,
1293 IMAGECAL_AutoImageCalOn = 0x80
1300 TEMPTHRESHOLD_5C = 0,
1301 TEMPTHRESHOLD_10C = 1,
1302 TEMPTHRESHOLD_15C = 2,
1303 TEMPTHRESHOLD_20C = 3
1310 LOWBAT_LowBatTrim0 = 0x01,
1311 LOWBAT_LowBatTrim1 = 0x02,
1312 LOWBAT_LowBatTrim2 = 0x04,
1313 _LOWBAT_LowBatTrim_MASK = 7,
1314 _LOWBAT_LowBatTrim_SHIFT = 0,
1316 LOWBAT_LowBatOn = 0x08
1325 LOWBATTRIM_1_695 = 0,
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
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
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
1368 DOIMAPPING1_Dio3Mapping0 = 0x01,
1369 DOIMAPPING1_Dio3Mapping1 = 0x02,
1370 DOIMAPPING1_Dio3Mapping_MASK = 3,
1371 DOIMAPPING1_Dio3Mapping_SHIFT = 0,
1373 DOIMAPPING1_Dio2Mapping0 = 0x04,
1374 DOIMAPPING1_Dio2Mapping1 = 0x08,
1375 DOIMAPPING1_Dio2Mapping_MASK = 3,
1376 DOIMAPPING1_Dio2Mapping_SHIFT = 2,
1378 DOIMAPPING1_Dio1Mapping0 = 0x10,
1379 DOIMAPPING1_Dio1Mapping1 = 0x20,
1380 DOIMAPPING1_Dio1Mapping_MASK = 3,
1381 DOIMAPPING1_Dio1Mapping_SHIFT = 4,
1383 DOIMAPPING1_Dio0Mapping0 = 0x40,
1384 DOIMAPPING1_Dio0Mapping1 = 0x80,
1385 DOIMAPPING1_Dio0Mapping_MASK = 3,
1386 DOIMAPPING1_Dio0Mapping_SHIFT = 6,
1395 DOIMAPPING2_MapPreambleDetect = 0x01,
1399 DOIMAPPING2_Dio5Mapping0 = 0x10,
1400 DOIMAPPING2_Dio5Mapping1 = 0x20,
1401 DOIMAPPING2_Dio5Mapping_MASK = 3,
1402 DOIMAPPING2_Dio5Mapping_SHIFT = 4,
1404 DOIMAPPING2_Dio4Mapping0 = 0x40,
1405 DOIMAPPING2_Dio4Mapping1 = 0x80,
1406 DOIMAPPING2_Dio4Mapping_MASK = 3,
1407 DOIMAPPING2_Dio4Mapping_SHIFT = 6,
1431 PLLHOP_FastHopOn = 0x80
1449 PADAC_PaDac0 = 0x01,
1450 PADAC_PaDac1 = 0x02,
1451 PADAC_PaDac2 = 0x04,
1452 _PADAC_PaDac_MASK = 7,
1453 _PADAC_PaDac_SHIFT = 0
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
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
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,
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,
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
1544 LOR_DetectionThreshold_SF7_SF12 = 0x0a,
1545 LOR_DetectionThreshold_SF6 = 0x0c
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,
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
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,
1612 bool writeReg(uint8_t reg, uint8_t val);
1632 void readFifo(uint8_t *buffer,
int len);
1640 void writeFifo(uint8_t *buffer,
int len);
1758 uint32_t datarate, uint8_t coderate,
1759 uint32_t bandwidthAfc, uint16_t preambleLen,
1760 uint16_t symbTimeout,
bool fixLen,
1762 bool crcOn,
bool freqHopOn, uint8_t hopPeriod,
1763 bool iqInverted,
bool rxContinuous);
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);
1828 std::string rBuffer((
char *)m_rxBuffer,
getRxLen());
1841 return (uint8_t*)m_rxBuffer;
1882 mraa::Gpio m_gpioCS;
1883 mraa::Gpio m_gpioReset;
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;
1893 void rxChainCalibration();
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);
1914 static const uint8_t m_writeMode = 0x80;
1949 uint32_t BandwidthAfc;
1951 uint16_t PreambleLen;
1957 } radioFskSettings_t;
1965 bool LowDatarateOptimize;
1967 uint16_t PreambleLen;
1975 } radioLoRaSettings_t;
1980 uint8_t PreambleDetected;
1981 uint8_t SyncWordDetected;
1989 } radioFskPacketHandler_t;
1997 } radioLoRaPacketHandler_t;
2005 radioFskSettings_t fskSettings;
2006 volatile radioFskPacketHandler_t fskPacketHandler;
2008 radioLoRaSettings_t loraSettings;
2009 volatile radioLoRaPacketHandler_t loraPacketHandler;
2012 uint8_t lookupFSKBandWidth(uint32_t bw);
2015 volatile int m_rxRSSI;
2016 volatile int m_rxSNR;
2017 volatile int m_rxLen;
2018 uint8_t m_rxBuffer[FIFO_SIZE];
2021 pthread_mutex_t m_intrLock;
2023 void lockIntrs() { pthread_mutex_lock(&m_intrLock); };
2024 void unlockIntrs() { pthread_mutex_unlock(&m_intrLock); };
2030 struct timeval m_startTime;
2032 uint32_t getMillis();
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