Skip to content

Commit 8d3f0ee

Browse files
committed
add feature for automatic enable invert IQ on Rx or Tx
1 parent 18fb9d8 commit 8d3f0ee

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=LoRa
2-
version=0.9.6
2+
version=0.9.7
33
author=Sandeep Mistry <[email protected]>
44
maintainer=Sandeep Mistry <[email protected]>
55
sentence=An Arduino library for sending and receiving data using LoRa radios.

src/LoRa.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ LoRaClass::LoRaClass()
7777
_frequency(0),
7878
_packetIndex(0),
7979
// _crcEnabled(false),
80+
_automaticInvertIq(false),
81+
_invertIqOnTx(false),
82+
_invertIqOnRx(false),
83+
_invertIqEnable(false),
8084
_tx_payload_length(0),
8185
_implicitHeaderMode(0),
8286
_onReceive(NULL),
@@ -208,6 +212,13 @@ int LoRaClass::endPacket(bool async, int implicitHeader) {
208212
fifoTransferWrite(_tx_payload, _tx_payload_length);
209213
// }
210214

215+
if (_automaticInvertIq) {
216+
if (_invertIqOnTx) {
217+
enableInvertIQ();
218+
} else {
219+
disableInvertIQ();
220+
}
221+
}
211222
// start end
212223

213224
writeRegister(REG_PAYLOAD_LENGTH, _tx_payload_length);
@@ -444,6 +455,14 @@ void LoRaClass::receive(int size) {
444455
writeRegister(REG_DIO_MAPPING_1, 0x00); // DIO0 => RXDONE
445456
writeRegister(REG_DIO_MAPPING_2, 0x40); //
446457

458+
if (_automaticInvertIq) {
459+
if (_invertIqOnRx) {
460+
enableInvertIQ();
461+
} else {
462+
disableInvertIQ();
463+
}
464+
}
465+
447466
if (size > 0) {
448467
implicitHeaderMode();
449468

@@ -636,12 +655,31 @@ void LoRaClass::disableCrc() {
636655
// _crcEnabled = false;
637656
}
638657

639-
void LoRaClass::enableInvertIQ() {
658+
void LoRaClass::setAutomaticInvertIQ(bool onTx, bool onRx) {
659+
if((onTx == false) && (onRx == false)) {
660+
_automaticInvertIq = false;
661+
disableInvertIQ(true);
662+
} else {
663+
_automaticInvertIq = true;
664+
_invertIqOnTx = onTx;
665+
_invertIqOnRx = onRx;
666+
}
667+
}
668+
669+
void LoRaClass::enableInvertIQ(bool forceInvertIqState) {
670+
if (_invertIqEnable == true && forceInvertIqState == false) {
671+
return;
672+
}
673+
_invertIqEnable = true;
640674
writeRegister(REG_INVERTIQ, 0x66);
641675
writeRegister(REG_INVERTIQ2, 0x19);
642676
}
643677

644-
void LoRaClass::disableInvertIQ() {
678+
void LoRaClass::disableInvertIQ(bool forceInvertIqState) {
679+
if(_invertIqEnable == false && forceInvertIqState == false) {
680+
return;
681+
}
682+
_invertIqEnable = false;
645683
writeRegister(REG_INVERTIQ, 0x27);
646684
writeRegister(REG_INVERTIQ2, 0x1d);
647685
}

src/LoRa.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define MAX_PKT_LENGTH 255
3535

3636
class LoRaClass : public Stream {
37-
public:
37+
public:
3838
LoRaClass();
3939

4040
int begin(long frequency);
@@ -81,8 +81,9 @@ class LoRaClass : public Stream {
8181
void setSyncWord(int sw);
8282
void enableCrc();
8383
void disableCrc();
84-
void enableInvertIQ();
85-
void disableInvertIQ();
84+
void enableInvertIQ(bool forceInvertIqState = false);
85+
void disableInvertIQ(bool forceInvertIqState = false);
86+
void setAutomaticInvertIQ(bool onTx = false, bool onRx = false);
8687

8788
void setOCP(uint8_t mA); // Over Current Protection control
8889

@@ -101,7 +102,7 @@ class LoRaClass : public Stream {
101102

102103
void dumpRegisters(Stream &out);
103104

104-
private:
105+
private:
105106
void explicitHeaderMode();
106107
void implicitHeaderMode();
107108

@@ -122,7 +123,7 @@ class LoRaClass : public Stream {
122123

123124
static void onDio0Rise();
124125

125-
private:
126+
private:
126127
SPISettings _spiSettings;
127128
SPIClass *_spi;
128129
int _ss;
@@ -131,6 +132,10 @@ class LoRaClass : public Stream {
131132
long _frequency;
132133
int _packetIndex;
133134
// bool _crcEnabled;
135+
bool _automaticInvertIq;
136+
bool _invertIqOnTx;
137+
bool _invertIqOnRx;
138+
bool _invertIqEnable;
134139
size_t _tx_payload_length;
135140
uint8_t _tx_payload[MAX_PKT_LENGTH + 1 + 2];
136141
int _implicitHeaderMode;

0 commit comments

Comments
 (0)