Text menu driven ANSI/VT100 console test utility for LoRa transceivers

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.

This is VT100 text-based menu driven test program for SX12xx transceiver devices.
Serial console is divided into horizontally into top half and bottom half.
The bottom half serves as scrolling area to log activity.
The top half serves as menu, to configure the radio.
For all devices, the serial console operates at 115200 8N1, and requires terminal with ANSI-VT100 capability, such as putty/teraterm/minicom etc.
Use program only with keyboard up/down/left/right keys. Enter to change an item, or number for value item. Some items are single bit, requiring only enter key to toggle. Others with fixed choices give a drop-down menu.

Revision:
4:fa31fdf4ec8d
Parent:
3:56fc764dee0a
Child:
5:1e5cb7139acb
--- a/radio_sx126x.cpp	Thu Nov 01 13:02:38 2018 -0700
+++ b/radio_sx126x.cpp	Sun Nov 25 15:34:40 2018 -0800
@@ -342,6 +342,12 @@
 {
     PwrCtrl_t PwrCtrl;
     PaCtrl1b_t PaCtrl1b;
+    unsigned v = radio.readReg(REG_ADDR_ANACTRL16, 1);
+
+    if (v & 0x10) {
+        pc.printf("%d", PA_OFF_DBM);
+        return;
+    }
 
     PwrCtrl.octet = radio.readReg(REG_ADDR_PWR_CTRL, 1);
 
@@ -357,12 +363,24 @@
 bool Radio::tx_dbm_write(const char* str)
 {
     int dbm;
+    unsigned v = radio.readReg(REG_ADDR_ANACTRL16, 1);
 
     sscanf(str, "%d", &dbm);
 
-    tx_param_buf[0] = dbm;
+    if (dbm == PA_OFF_DBM) {
+        /* bench test: prevent overloading receiving station (very low tx power) */
+        v |= 0x10;  // pa dac atb tst
+        radio.writeReg(REG_ADDR_ANACTRL16, v, 1);
+    } else {
+        tx_param_buf[0] = dbm;
+        radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
 
-    radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
+        if (v & 0x10) {
+            v &= ~0x10;
+            radio.writeReg(REG_ADDR_ANACTRL16, v, 1);
+        }
+    }
+
     return false;
 }
 
@@ -677,13 +695,49 @@
     return false;
 }
 
-const value_item_t Radio::ocp_item = { _ITEM_VALUE, 7, ocp_print, ocp_write};
+const value_item_t Radio::ocp_item = { _ITEM_VALUE, 5, ocp_print, ocp_write};
+
+void Radio::xta_print()
+{
+    uint8_t trim = radio.readReg(REG_ADDR_XTA_TRIM, 1);
+    pc.printf("%02x", trim);
+}
+
+bool Radio::xta_write(const char* txt)
+{
+    unsigned trim;
+    if (sscanf(txt, "%x", &trim) == 1)
+        radio.writeReg(REG_ADDR_XTA_TRIM, trim, 1);
+
+    return false;
+}
+
+const value_item_t Radio::xta_item = { _ITEM_VALUE, 3, xta_print, xta_write};
+
+void Radio::xtb_print()
+{
+    uint8_t trim = radio.readReg(REG_ADDR_XTB_TRIM, 1);
+    pc.printf("%02x", trim);
+}
+
+bool Radio::xtb_write(const char* txt)
+{
+    unsigned trim;
+    if (sscanf(txt, "%x", &trim) == 1)
+        radio.writeReg(REG_ADDR_XTB_TRIM, trim, 1);
+
+    return false;
+}
+
+const value_item_t Radio::xtb_item = { _ITEM_VALUE, 3, xtb_print, xtb_write};
 
 const menu_t Radio::common_menu[] = {
     { {FIRST_CHIP_MENU_ROW,  1},   "deviceSel:",   &deviceSel_item, FLAG_MSGTYPE_ALL, &tx_dbm_item },
     { {FIRST_CHIP_MENU_ROW, 18}, "paDutyCycle:", &paDutyCycle_item, FLAG_MSGTYPE_ALL },
-    { {FIRST_CHIP_MENU_ROW, 36},       "hpMax:",       &hpMax_item, FLAG_MSGTYPE_ALL },
-    { {FIRST_CHIP_MENU_ROW, 45},      "ocp mA:",         &ocp_item, FLAG_MSGTYPE_ALL },
+    { {FIRST_CHIP_MENU_ROW, 33},       "hpMax:",       &hpMax_item, FLAG_MSGTYPE_ALL },
+    { {FIRST_CHIP_MENU_ROW, 42},      "ocp mA:",         &ocp_item, FLAG_MSGTYPE_ALL },
+    { {FIRST_CHIP_MENU_ROW, 55},         "XTA:",         &xta_item, FLAG_MSGTYPE_ALL },
+    { {FIRST_CHIP_MENU_ROW, 62},         "XTB:",         &xtb_item, FLAG_MSGTYPE_ALL },
 
     { {0, 0}, NULL, NULL }
 };
@@ -1544,5 +1598,15 @@
     return NULL;
 }
 
+unsigned Radio::read_register(unsigned addr)
+{
+    return radio.readReg(addr, 1);
+}
+
+void Radio::write_register(unsigned addr, unsigned val)
+{
+    radio.writeReg(addr, val, 1);
+}
+
 #endif /* ..SX126x_H */