1#if !defined(RADIOLIB_LR_COMMON_H)
2#define RADIOLIB_LR_COMMON_H
4#include "../../Module.h"
5#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
7#define RADIOLIB_LRXXXX_CMD_NOP (0x0000)
8#define RADIOLIB_LRXXXX_SPI_MAX_READ_WRITE_LEN (128)
12#define RADIOLIB_LRXXXX_STAT_1_CMD_FAIL (0x00UL << 1)
13#define RADIOLIB_LRXXXX_STAT_1_CMD_PERR (0x01UL << 1)
14#define RADIOLIB_LRXXXX_STAT_1_CMD_OK (0x02UL << 1)
15#define RADIOLIB_LRXXXX_STAT_1_CMD_DAT (0x03UL << 1)
19#define RADIOLIB_LRXXXX_LR_FHSS_CR_5_6 (0x00UL << 0)
20#define RADIOLIB_LRXXXX_LR_FHSS_CR_2_3 (0x01UL << 0)
21#define RADIOLIB_LRXXXX_LR_FHSS_CR_1_2 (0x02UL << 0)
22#define RADIOLIB_LRXXXX_LR_FHSS_CR_1_3 (0x03UL << 0)
23#define RADIOLIB_LRXXXX_LR_FHSS_MOD_TYPE_GMSK (0x00UL << 0)
24#define RADIOLIB_LRXXXX_LR_FHSS_GRID_STEP_FCC (0x00UL << 0)
25#define RADIOLIB_LRXXXX_LR_FHSS_GRID_STEP_NON_FCC (0x01UL << 0)
26#define RADIOLIB_LRXXXX_LR_FHSS_HOPPING_DISABLED (0x00UL << 0)
27#define RADIOLIB_LRXXXX_LR_FHSS_HOPPING_ENABLED (0x01UL << 0)
28#define RADIOLIB_LRXXXX_LR_FHSS_HOPPING_TEST_NO_HOP (0x02UL << 0)
29#define RADIOLIB_LRXXXX_LR_FHSS_HOPPING_TEST_PA_RAMP (0x03UL << 0)
30#define RADIOLIB_LRXXXX_LR_FHSS_BW_39_06 (0x00UL << 0)
31#define RADIOLIB_LRXXXX_LR_FHSS_BW_85_94 (0x01UL << 0)
32#define RADIOLIB_LRXXXX_LR_FHSS_BW_136_72 (0x02UL << 0)
33#define RADIOLIB_LRXXXX_LR_FHSS_BW_183_59 (0x03UL << 0)
34#define RADIOLIB_LRXXXX_LR_FHSS_BW_335_94 (0x04UL << 0)
35#define RADIOLIB_LRXXXX_LR_FHSS_BW_386_72 (0x05UL << 0)
36#define RADIOLIB_LRXXXX_LR_FHSS_BW_722_66 (0x06UL << 0)
37#define RADIOLIB_LRXXXX_LR_FHSS_BW_773_44 (0x07UL << 0)
38#define RADIOLIB_LRXXXX_LR_FHSS_BW_1523_4 (0x08UL << 0)
39#define RADIOLIB_LRXXXX_LR_FHSS_BW_1574_2 (0x09UL << 0)
40#define RADIOLIB_LRXXXX_LR_FHSS_HEADER_BITS (114)
41#define RADIOLIB_LRXXXX_LR_FHSS_FRAG_BITS (48)
42#define RADIOLIB_LRXXXX_LR_FHSS_BLOCK_PREAMBLE_BITS (2)
43#define RADIOLIB_LRXXXX_LR_FHSS_BLOCK_BITS (RADIOLIB_LRXXXX_LR_FHSS_FRAG_BITS + RADIOLIB_LRXXXX_LR_FHSS_BLOCK_PREAMBLE_BITS)
47#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_1_6 (0x00UL << 0)
48#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_1_7 (0x01UL << 0)
49#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_1_8 (0x02UL << 0)
50#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_2_2 (0x03UL << 0)
51#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_2_4 (0x04UL << 0)
52#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_2_7 (0x05UL << 0)
53#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_3_0 (0x06UL << 0)
54#define RADIOLIB_LRXXXX_TCXO_VOLTAGE_3_3 (0x07UL << 0)
58#define RADIOLIB_LRXXXX_PA_RAMP_2U (0x00UL << 0)
59#define RADIOLIB_LRXXXX_PA_RAMP_4U (0x01UL << 0)
60#define RADIOLIB_LRXXXX_PA_RAMP_8U (0x02UL << 0)
61#define RADIOLIB_LRXXXX_PA_RAMP_16U (0x03UL << 0)
62#define RADIOLIB_LRXXXX_PA_RAMP_32U (0x04UL << 0)
63#define RADIOLIB_LRXXXX_PA_RAMP_48U (0x05UL << 0)
64#define RADIOLIB_LRXXXX_PA_RAMP_64U (0x06UL << 0)
65#define RADIOLIB_LRXXXX_PA_RAMP_80U (0x07UL << 0)
66#define RADIOLIB_LRXXXX_PA_RAMP_96U (0x08UL << 0)
67#define RADIOLIB_LRXXXX_PA_RAMP_112U (0x09UL << 0)
68#define RADIOLIB_LRXXXX_PA_RAMP_128U (0x0AUL << 0)
69#define RADIOLIB_LRXXXX_PA_RAMP_144U (0x0BUL << 0)
70#define RADIOLIB_LRXXXX_PA_RAMP_160U (0x0CUL << 0)
71#define RADIOLIB_LRXXXX_PA_RAMP_176U (0x0DUL << 0)
72#define RADIOLIB_LRXXXX_PA_RAMP_192U (0x0EUL << 0)
73#define RADIOLIB_LRXXXX_PA_RAMP_208U (0x0FUL << 0)
74#define RADIOLIB_LRXXXX_PA_RAMP_240U (0x10UL << 0)
75#define RADIOLIB_LRXXXX_PA_RAMP_272U (0x11UL << 0)
76#define RADIOLIB_LRXXXX_PA_RAMP_304U (0x12UL << 0)
80#define RADIOLIB_LRXXXX_DIOx(X) ((X) | RFSWITCH_PIN_FLAG)
81#define RADIOLIB_LRXXXX_DIOx_VAL(X) ((X) & ~RFSWITCH_PIN_FLAG)
84#define RADIOLIB_LRXXXX_LR_FHSS_BIT_RATE (488.28215f)
85#define RADIOLIB_LRXXXX_LR_FHSS_BIT_RATE_RAW (0x8001E848UL)
86#define RADIOLIB_LRXXXX_LORA_HEADER_EXPLICIT (0x00UL << 0)
87#define RADIOLIB_LRXXXX_LORA_HEADER_IMPLICIT (0x01UL << 0)
88#define RADIOLIB_LRXXXX_LORA_CRC_ENABLED (0x01UL << 0)
89#define RADIOLIB_LRXXXX_LORA_CRC_DISABLED (0x00UL << 0)
166 uint32_t rxTimeout = 0;
169 uint8_t bandwidth = 0, spreadingFactor = 0, codingRate = 0, ldrOptimize = 0, crcTypeLoRa = 0, headerType = 0;
170 uint16_t preambleLengthLoRa = 0;
171 float bandwidthKhz = 0;
172 bool ldroAuto =
true;
173 size_t implicitLen = 0;
174 bool invertIQEnabled =
false;
177 uint32_t bitRate = 0, frequencyDev = 0;
178 uint8_t preambleDetLength = 0, rxBandwidth = 0, pulseShape = 0, crcTypeGFSK = 0, crcLenGFSK = 0, syncWordLength = 0, addrComp = 0, whitening = 0, packetType = 0, node = 0;
179 uint16_t preambleLengthGFSK = 0;
182 uint8_t lrFhssCr = 0, lrFhssBw = 0, lrFhssHdrCount = 0, lrFhssGrid = 0;
183 uint16_t lrFhssHopSeq = 0;
189 int16_t getStatus(uint8_t* stat1, uint8_t* stat2, uint32_t* irq);
190 int16_t lrFhssBuildFrame(uint16_t cmd, uint8_t hdrCount, uint8_t cr, uint8_t grid, uint8_t hop, uint8_t bw, uint16_t hopSeq, int8_t devOffset,
const uint8_t* payload,
size_t len);
191 uint8_t roundRampTime(uint32_t rampTimeUs);
192 int16_t findRxBw(
float rxBw,
const uint8_t* lut,
size_t lutSize,
float rxBwMax, uint8_t* val);
196 int16_t setU32(uint16_t cmd, uint32_t u32);
198 int16_t writeCommon(uint16_t cmd, uint32_t addrOffset,
const uint32_t* data,
size_t len,
bool nonvolatile);
199 int16_t SPIcommand(uint16_t cmd,
bool write, uint8_t* data,
size_t len,
const uint8_t* out = NULL,
size_t outLen = 0);
201 static int16_t SPIparseStatus(uint8_t in);
202 static int16_t SPIcheckStatus(
Module* mod);
Definition LR_common.h:91
uint32_t getIrqStatus()
Reads the current IRQ status.
Definition LR_common.cpp:39
void setPacketReceivedAction(void(*func)(void)) override
Sets interrupt service routine to call when a packet is received.
Definition LR_common.cpp:23
RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override
Calculate the timeout value for this specific module / series (in number of symbols or units of time)
Definition LR_common.cpp:171
RadioLibTime_t calculateTimeOnAir(ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len) override
Calculate the expected time-on-air for a given modem, data rate, packet configuration and payload siz...
Definition LR_common.cpp:99
void setPacketSentAction(void(*func)(void)) override
Sets interrupt service routine to call when a packet is sent.
Definition LR_common.cpp:31
void setIrqAction(void(*func)(void))
Sets interrupt service routine to call when IRQ1 activates.
Definition LR_common.cpp:15
void clearIrqAction()
Clears interrupt service routine to call when IRQ1 activates.
Definition LR_common.cpp:19
void clearPacketSentAction() override
Clears interrupt service routine to call when a packet is sent.
Definition LR_common.cpp:35
void clearPacketReceivedAction() override
Clears interrupt service routine to call when a packet is received.
Definition LR_common.cpp:27
int16_t reset()
Reset method. Will reset the chip to the default state using RST pin.
Definition LR_common.cpp:178
bool XTAL
Whether the module has an XTAL (true) or TCXO (false). Defaults to false.
Definition LR_common.h:98
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition Module.h:73
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition PhysicalLayer.h:257
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition TypeDef.h:658
Common data rate structure.
Definition PhysicalLayer.h:74
Common packet configuration structure.
Definition PhysicalLayer.h:119