Hardware Abstraction Layer, permitting any LoRa application to use any LoRa radio chip

Dependents:   alarm_slave alarm_master lora_p2p lorawan1v1 ... more

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
if you're using LR1110, then import LR1110 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.
If you're using Type1SJ select target DISCO_L072CZ_LRWAN1 and import sx126x driver into your program.

Pin assigned to arduino LoRa radio shield form-factor

Revision:
1:e79b0a55135f
Parent:
0:9c052ff8dd6a
Child:
5:ab124d3842a8
--- a/radio_sx128x.cpp	Thu Jul 05 17:31:54 2018 -0700
+++ b/radio_sx128x.cpp	Mon Jul 16 11:15:59 2018 -0700
@@ -4,16 +4,16 @@
 #include <float.h>
 
 #ifdef TARGET_FF_ARDUINO    /* pins of SX126xDVK1xAS board */
+    #define NRST_PIN        A0
     SPIu spi(D11, D12, D13); // mosi, miso, sclk
     //           spi, nss, busy, dio1
-    SX128x Radio::radio(spi,  D7,   D3,   D5 );
+    SX128x Radio::radio(spi,  D7,   D3,   D5, NRST_PIN);
 
     #define LED_ON      1
     #define LED_OFF     0
     DigitalOut tx_led(A4);
     DigitalOut rx_led(A5);
 
-    #define NRST_PIN        A0
 
     DigitalOut ant_sw(A3);
     DigitalOut cps(D6); // SE2436L
@@ -44,7 +44,6 @@
 
 
 LowPowerTimer Radio::lpt;
-RadioModems_t Radio::_m_;
 
 PacketParams_t Radio::ppGFSK;
 PacketParams_t Radio::ppLORA;
@@ -109,8 +108,8 @@
         LoRaPktPar1_t LoRaPktPar1;
         LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
         mpLORA.lora.codingRate = LoRaPktPar1.bits.coding_rate;
-        ppLORA.lora.InvertIQ = LoRaPktPar1.bits.rxinvert_iq;
-        ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header;
+        ppLORA.lora.InvertIQ = LoRaPktPar1.octet & LORA_IQ_STD; // LoRaPktPar1.bits.rxinvert_iq
+        ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header ? IMPLICIT_HEADER : EXPLICIT_HEADER;
         // LoRaPktPar1.bits.ppm_offset
     }
 
@@ -317,13 +316,14 @@
 int Radio::Send(uint8_t size, timestamp_t maxListenTime, timestamp_t channelFreeTime, int rssiThresh)
 {
     uint8_t buf[8];
+    uint8_t pktType = radio.getPacketType();
 
-    if (_m_ == MODEM_FSK) {
+    if (pktType == PACKET_TYPE_LORA) {
+        ppLORA.lora.PayloadLength = size;
+        radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
+    } else if (pktType == PACKET_TYPE_GFSK) {
         ppGFSK.gfskFLRC.PayloadLength = size;
         radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
-    } else if (_m_ == MODEM_LORA) {
-        ppLORA.lora.PayloadLength = size;
-        radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
     }
 
     if (maxListenTime > 0) {
@@ -394,8 +394,8 @@
     {
         LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
         LowDatarateOptimize = LoRaPktPar1.bits.ppm_offset ? 1 : 0;
-        ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header;
-        ppLORA.lora.InvertIQ = LoRaPktPar1.bits.rxinvert_iq;
+        ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header ? IMPLICIT_HEADER : EXPLICIT_HEADER;
+        ppLORA.lora.InvertIQ = LoRaPktPar1.octet & LORA_IQ_STD; // LoRaPktPar1.bits.rxinvert_iq
         mpLORA.lora.codingRate = LoRaPktPar1.bits.coding_rate;
     }
 
@@ -528,14 +528,24 @@
 
 void Radio::LoRaModemConfig(unsigned bwKHz, uint8_t sf, uint8_t cr)
 {
-    if (bwKHz > 800)
+    unsigned use;
+
+    if (radio.getPacketType() != PACKET_TYPE_LORA)
+        radio.setPacketType(PACKET_TYPE_LORA);
+
+    if (bwKHz > 800) {
         mpLORA.lora.bandwidth = LORA_BW_1600;
-    if (bwKHz > 400)
+        use = 1600;
+    } if (bwKHz > 400) {
         mpLORA.lora.bandwidth = LORA_BW_800;
-    if (bwKHz > 200)
+        use = 800;
+    } if (bwKHz > 200) {
         mpLORA.lora.bandwidth = LORA_BW_400;
-    else
+        use = 400;
+    } else {
         mpLORA.lora.bandwidth = LORA_BW_200;
+        use = 200;
+    }
 
     mpLORA.lora.codingRate = cr;
 
@@ -546,6 +556,9 @@
 
 void Radio::LoRaPacketConfig(unsigned preambleLen, bool fixLen, bool crcOn, bool invIQ)
 {
+    if (radio.getPacketType() != PACKET_TYPE_LORA)
+        radio.setPacketType(PACKET_TYPE_LORA);
+
     ppLORA.lora.PreambleLength = preambleLen;
     ppLORA.lora.HeaderType = fixLen ? IMPLICIT_HEADER : EXPLICIT_HEADER;
     ppLORA.lora.crc = crcOn ? LORA_CRC_ENABLE : LORA_CRC_DISABLE;
@@ -604,13 +617,14 @@
     radio.xfer(OPCODE_SET_TX_CARRIER, 0, 0, NULL);
 }
 
-void Radio::SetRxMaxPayloadLength(RadioModems_t modem, uint8_t max)
+void Radio::SetRxMaxPayloadLength(uint8_t max)
 {
-    if (_m_ == MODEM_FSK) {
+    uint8_t pktType = radio.getPacketType();
+
+    if (pktType == PACKET_TYPE_GFSK)
         ppGFSK.gfskFLRC.PayloadLength = max;
-    } else if (_m_ == MODEM_LORA) {
+    else if (pktType == PACKET_TYPE_LORA)
         ppLORA.lora.PayloadLength = max;
-    }
 }
 
 #endif /* ..SX126x_H */