1

Revision:
5:ab124d3842a8
Parent:
4:57080d572494
Child:
7:ba81f66e56d1
diff -r 57080d572494 -r ab124d3842a8 radio_sx126x.cpp
--- a/radio_sx126x.cpp	Mon Aug 20 14:07:47 2018 -0700
+++ b/radio_sx126x.cpp	Sun Nov 25 17:12:03 2018 -0800
@@ -4,6 +4,7 @@
 
 LowPowerTimer Radio::lpt;
 volatile us_timestamp_t Radio::irqAt;
+bool Radio::paOff;
 
 #ifdef TARGET_FF_ARDUINO
     SPIu spi(D11, D12, D13); // mosi, miso, sclk
@@ -93,7 +94,23 @@
 
 void Radio::set_tx_dbm(int8_t dbm)
 {
-    radio.set_tx_dbm(chipType == CHIP_TYPE_SX1262, dbm);
+    unsigned v = radio.readReg(REG_ADDR_ANACTRL16, 1);
+
+    if (dbm == PA_OFF_DBM) {
+        /* bench test: prevent overloading receiving station (very low tx power) */
+        if ((v & 0x10) == 0) {
+            v |= 0x10;
+            radio.writeReg(REG_ADDR_ANACTRL16, v, 1);
+        }
+        paOff = true;
+    } else {
+        radio.set_tx_dbm(chipType == CHIP_TYPE_SX1262, dbm);
+        if (v & 0x10) {
+            v &= ~0x10;
+            radio.writeReg(REG_ADDR_ANACTRL16, v, 1);
+        }
+        paOff = false;
+    }
 }
 
 void Radio::SetTxContinuousWave(unsigned hz, int8_t dbm, unsigned timeout_us)
@@ -360,6 +377,13 @@
         } while ((now - chFreeAt) < channelFreeTime);
     } 
 
+    if (paOff) {
+        unsigned v = radio.readReg(REG_ADDR_ANACTRL16, 1);
+        if ((v & 0x10) == 0) {
+            v |= 0x10;
+            radio.writeReg(REG_ADDR_ANACTRL16, v, 1);
+        }
+    }
     radio.start_tx(size);
 
     return 0;