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 NAmote72 or Murata discovery, then you must import only sx127x driver.

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.

Files at this revision

API Documentation at this revision

Comitter:
Wayne Roberts
Date:
Thu Dec 06 14:24:18 2018 -0800
Parent:
4:fa31fdf4ec8d
Commit message:
correct PA_OFF for sx127x

Changed in this revision

TARGET_DISCO_L072CZ_LRWAN1/radio_typeABZ.cpp Show annotated file Show diff for this revision Revisions of this file
TARGET_MOTE_L152RC/radio_mote.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
radio_ff_arduino_sx127x.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx126x.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx127x.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx128x.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/TARGET_DISCO_L072CZ_LRWAN1/radio_typeABZ.cpp	Sun Nov 25 15:34:40 2018 -0800
+++ b/TARGET_DISCO_L072CZ_LRWAN1/radio_typeABZ.cpp	Thu Dec 06 14:24:18 2018 -0800
@@ -16,22 +16,22 @@
 void Radio::rfsw_callback()
 {
     if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {
-        Vctl1 = 0;        
+        Vctl1 = 0;
         if (radio.RegPaConfig.bits.PaSelect) {
             Vctl2 = 0;
-            Vctl3 = 1;                        
+            Vctl3 = 1;
         } else {
             Vctl2 = 1;
-            Vctl3 = 0;            
+            Vctl3 = 0;
         }
     } else {
         if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
             Vctl1 = 1;
         else
             Vctl1 = 0;
-        
+
         Vctl2 = 0;
-        Vctl3 = 0;        
+        Vctl3 = 0;
     }
 }
 
@@ -39,22 +39,29 @@
 {
     int dbm;
     RegPdsTrim1_t pds_trim;
-    uint8_t adr;
+    uint8_t adr, pa_test_adr;
 
-    if (radio.type == SX1276)
+    if (radio.type == SX1276) {
         adr = REG_PDSTRIM1_SX1276;
-    else
+        pa_test_adr = REG_PATEST_SX1276;
+    } else {
         adr = REG_PDSTRIM1_SX1272;
+        pa_test_adr = REG_PATEST_SX1272;
+    }
 
-    pds_trim.octet = radio.read_reg(adr);   
+    if (radio.read_reg(pa_test_adr) & 0x20) {
+        pds_trim.octet = radio.read_reg(adr);
 
-    radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
-    if (radio.RegPaConfig.bits.PaSelect) {
-        dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
-    } else {
-        dbm = radio.RegPaConfig.bits.OutputPower - 1;
-    }
-    pc.printf(":%d", dbm);
+        radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
+        if (radio.RegPaConfig.bits.PaSelect) {
+            dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
+        } else {
+            dbm = radio.RegPaConfig.bits.OutputPower - 1;
+        }
+    } else
+        dbm = PA_OFF_DBM;
+
+    pc.printf("%d", dbm);
 }
 
 bool Radio::tx_dbm_write(const char* str)
@@ -69,8 +76,8 @@
         adr = REG_PDSTRIM1_SX1276;
     else
         adr = REG_PDSTRIM1_SX1272;
-       
-    pds_trim.octet = radio.read_reg(adr);   
+
+    pds_trim.octet = radio.read_reg(adr);
 
     if (dbm > 14) {
         radio.RegPaConfig.bits.PaSelect = 1;    // PA_BOOST
--- a/TARGET_MOTE_L152RC/radio_mote.cpp	Sun Nov 25 15:34:40 2018 -0800
+++ b/TARGET_MOTE_L152RC/radio_mote.cpp	Thu Dec 06 14:24:18 2018 -0800
@@ -41,7 +41,7 @@
                 rfsw1 = 1;
             } else { // RFO to power amp
                 rfsw2 = 1;
-                rfsw1 = 0;            
+                rfsw1 = 0;
             }
         } else {
             // todo: sx1276
@@ -51,7 +51,7 @@
         yellow = LED_ON;
         if (radio.HF) {
             rfsw2 = 1;
-            rfsw1 = 1;              
+            rfsw1 = 1;
         } else {
             // todo: sx1276
         }
@@ -59,29 +59,36 @@
         yellow = LED_OFF;
         red = LED_OFF;
         rfsw2 = 0;
-        rfsw1 = 0;     
+        rfsw1 = 0;
     }
 }
 
 void Radio::tx_dbm_print()
 {
     int dbm;
+    uint8_t adr, pa_test_adr;
 
-    radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
-    if (radio.RegPaConfig.bits.PaSelect) {
-        RegPdsTrim1_t pds_trim;
-        uint8_t adr;
+    if (radio.type == SX1276) {
+        adr = REG_PDSTRIM1_SX1276;
+        pa_test_adr = REG_PATEST_SX1276;
+    } else {
+        adr = REG_PDSTRIM1_SX1272;
+        pa_test_adr = REG_PATEST_SX1272;
+    }
 
-        if (radio.type == SX1276)
-            adr = REG_PDSTRIM1_SX1276;
-        else
-            adr = REG_PDSTRIM1_SX1272;
+    if (radio.read_reg(pa_test_adr) & 0x20) {
+        radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
+        if (radio.RegPaConfig.bits.PaSelect) {
+            RegPdsTrim1_t pds_trim;
 
-        pds_trim.octet = radio.read_reg(adr);   
-        dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
-    } else {
-        dbm = radio.RegPaConfig.bits.OutputPower - 21;
-    }
+            pds_trim.octet = radio.read_reg(adr);
+            dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
+        } else {
+            dbm = radio.RegPaConfig.bits.OutputPower - 21;
+        }
+    } else
+        dbm = PA_OFF_DBM;
+
     pc.printf(":%d", dbm);
 }
 
@@ -107,8 +114,8 @@
             adr = REG_PDSTRIM1_SX1276;
         else
             adr = REG_PDSTRIM1_SX1272;
-       
-        pds_trim.octet = radio.read_reg(adr);   
+
+        pds_trim.octet = radio.read_reg(adr);
         if (dbm > 17) {
             dbm -= 3;
             pds_trim.bits.prog_txdac = 7;
--- a/main.cpp	Sun Nov 25 15:34:40 2018 -0800
+++ b/main.cpp	Thu Dec 06 14:24:18 2018 -0800
@@ -467,16 +467,16 @@
 const value_item_t bottomRow_item = { _ITEM_VALUE, 4, botrow_print, botrow_write };
 
 const menu_t common_menu[] = {
-    {  {1, 1},          NULL,  &hw_reset_item, FLAG_MSGTYPE_ALL },
-    { {1, 15}, "packetType:",   &pktType_item, FLAG_MSGTYPE_ALL },
-    { {1, 37},          NULL,   &msgType_item, FLAG_MSGTYPE_ALL },
-    { {1, 50},          NULL,   &chipNum_item, FLAG_MSGTYPE_ALL },
-    { {1, 60},  "bottomRow:", &bottomRow_item, FLAG_MSGTYPE_ALL },
-    { {2, 1},           NULL,       &frf_item, FLAG_MSGTYPE_ALL },
-    { {2, 15},     "TX dBm:",    &Radio::tx_dbm_item, FLAG_MSGTYPE_ALL },
-    { {2, 30},    "ramp us:",   &tx_ramp_item, FLAG_MSGTYPE_ALL },
-    { {2, 45},          NULL, &clearirqs_item, FLAG_MSGTYPE_ALL },
-    { {2, 55},     "opmode:",    &opmode_item, FLAG_MSGTYPE_ALL },
+    {  {1, 1},          NULL,      &hw_reset_item, FLAG_MSGTYPE_ALL },
+    { {1, 15}, "packetType:",       &pktType_item, FLAG_MSGTYPE_ALL },
+    { {1, 37},          NULL,       &msgType_item, FLAG_MSGTYPE_ALL },
+    { {1, 50},          NULL,       &chipNum_item, FLAG_MSGTYPE_ALL },
+    { {1, 60},  "bottomRow:",     &bottomRow_item, FLAG_MSGTYPE_ALL },
+    { {2, 1},           NULL,           &frf_item, FLAG_MSGTYPE_ALL },
+    { {2, 15},     "TX dBm:", &Radio::tx_dbm_item, FLAG_MSGTYPE_ALL },
+    { {2, 30},    "ramp us:",       &tx_ramp_item, FLAG_MSGTYPE_ALL },
+    { {2, 45},          NULL,     &clearirqs_item, FLAG_MSGTYPE_ALL },
+    { {2, 55},     "opmode:",        &opmode_item, FLAG_MSGTYPE_ALL },
 
 
     { {0, 0}, NULL, NULL }
@@ -977,7 +977,7 @@
 
     txy.row = INT_MAX;
     txy.col = 0;
-    
+
     for (n = 0; n < MAX_MENU_ROWS; n++) {
         StopMenuCols[n] = -1;
     }
@@ -1087,7 +1087,7 @@
                     pc.putc(ch);
                 }
             } else if (menuState.mode == MENUMODE_NONE) {
-                if (ishexchar(ch)) {
+                if (ishexchar(ch) || ch == '-') {   // characters which start entry
                     const value_item_t* vi = (const value_item_t*)menu_table[curpos.row][curpos.tableCol]->itemPtr;
                     if (vi->itemType == _ITEM_VALUE) {
                         start_value_entry(menu_table[curpos.row][curpos.tableCol]);
--- a/radio_ff_arduino_sx127x.cpp	Sun Nov 25 15:34:40 2018 -0800
+++ b/radio_ff_arduino_sx127x.cpp	Thu Dec 06 14:24:18 2018 -0800
@@ -46,14 +46,14 @@
         adr = REG_PDSTRIM1_SX1276;
     else
         adr = REG_PDSTRIM1_SX1272;
-       
-    pds_trim.octet = radio.read_reg(adr);   
+
+    pds_trim.octet = radio.read_reg(adr);
 
     if (shield_type == SHIELD_TYPE_LAS)
         radio.RegPaConfig.bits.PaSelect = 1;
     else
         radio.RegPaConfig.bits.PaSelect = 0;
-                
+
     if (radio.RegPaConfig.bits.PaSelect) {
         /* PABOOST used: +2dbm to +17, or +20 */
         if (dbm > 17) {
@@ -101,7 +101,7 @@
     }
 
     radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
-    
+
     rfsw.output();
 }
 
@@ -119,8 +119,8 @@
         pa_test_adr = REG_PATEST_SX1272;
     }
 
-    if (pa_test_adr & 0x20) {
-        pds_trim.octet = radio.read_reg(adr);   
+    if (radio.read_reg(pa_test_adr) & 0x20) {
+        pds_trim.octet = radio.read_reg(adr);
 
         radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
         if (radio.RegPaConfig.bits.PaSelect) {
@@ -131,7 +131,7 @@
     } else {
         dbm = PA_OFF_DBM;
     }
-    pc.printf(":%d", dbm);
+    pc.printf("%d", dbm);
 }
 
 bool Radio::tx_dbm_write(const char* str)
@@ -161,8 +161,8 @@
         v |= 0x20; // turn on pu_regpa_n: enable PA
         radio.write_reg(pa_test_adr, v);
     }
-       
-    pds_trim.octet = radio.read_reg(adr);   
+
+    pds_trim.octet = radio.read_reg(adr);
 
     if (radio.RegPaConfig.bits.PaSelect) {
         /* PABOOST used: +2dbm to +17, or +20 */
--- a/radio_sx126x.cpp	Sun Nov 25 15:34:40 2018 -0800
+++ b/radio_sx126x.cpp	Thu Dec 06 14:24:18 2018 -0800
@@ -113,7 +113,7 @@
     }
 
     /*******************************/
-    
+
     {
         loraConfig0_t conf0;
         conf0.octet = radio.readReg(REG_ADDR_LORA_CONFIG0, 1);
--- a/radio_sx127x.cpp	Sun Nov 25 15:34:40 2018 -0800
+++ b/radio_sx127x.cpp	Thu Dec 06 14:24:18 2018 -0800
@@ -137,7 +137,7 @@
         radio.write_reg(REG_LR_PAYLOADLENGTH, lora.RegPayloadLength);
     } else {
         fsk.RegPktConfig2.bits.PayloadLength = len;
-        radio.write_u16(REG_FSK_PACKETCONFIG2, fsk.RegPktConfig2.word);    
+        radio.write_u16(REG_FSK_PACKETCONFIG2, fsk.RegPktConfig2.word);
     }
 }
 
@@ -158,7 +158,7 @@
         fsk.RegPktConfig2.word = radio.read_u16(REG_FSK_PACKETCONFIG2);
         //log_printf("fsk payLen %u\r\n", fsk.RegPktConfig2.bits.PayloadLength);
         fsk.start_tx(fsk.RegPktConfig2.bits.PayloadLength);
-    }    
+    }
 }
 
 void Radio::tx_carrier()
@@ -248,24 +248,24 @@
         switch (act) {
             case SERVICE_READ_FIFO:
                 /*if (fsk.RegRxConfig.bits.AfcAutoOn) {
-                    printf("%dHz ", (int)(FREQ_STEP_HZ * fsk.RegAfcValue));   
+                    printf("%dHz ", (int)(FREQ_STEP_HZ * fsk.RegAfcValue));
                     if (rssi != 0) {
                         printf("pkt:-%.1fdBm ", rssi / 2.0);
                         rssi = 0;
-                    }    
+                    }
                 }*/
                 if (fsk.RegRxConfig.bits.AfcAutoOn)
                     log_printf("%dHz\r\n", (int)(FREQ_STEP_HZ * fsk.RegAfcValue));
 
                 RadioEvents->RxDone(fsk.rx_buf_length, /*TODO rssi*/0, 0);
-                break;                
+                break;
             case SERVICE_TX_DONE:
                 if (RadioEvents->TxDone_botHalf)
                     RadioEvents->TxDone_botHalf();
-                break;                
+                break;
             case SERVICE_ERROR:
             case SERVICE_NONE:
-                break;                
+                break;
         }
 
         if (statusRow > 0 && now-prev_now > 50000) {
@@ -546,7 +546,7 @@
 
     lora.RegPreamble = n;
     radio.write_u16(REG_LR_PREAMBLEMSB, lora.RegPreamble);
-    
+
     return false;
 }
 
@@ -751,7 +751,7 @@
 bool Radio::paSelect_push()
 {
     radio.RegPaConfig.bits.PaSelect ^= 1; 
-    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);   
+    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
     return radio.RegPaConfig.bits.PaSelect;
 }
 
@@ -1029,7 +1029,7 @@
 
 bool Radio::AfcAutoOn_read()
 {
-    fsk.RegRxConfig.octet = radio.read_reg(REG_FSK_RXCONFIG);            
+    fsk.RegRxConfig.octet = radio.read_reg(REG_FSK_RXCONFIG);
     return fsk.RegRxConfig.bits.AfcAutoOn;
 }
 
@@ -1046,7 +1046,7 @@
 
 bool Radio::RestartRxOnCollision_read()
 {
-    fsk.RegRxConfig.octet = radio.read_reg(REG_FSK_RXCONFIG);            
+    fsk.RegRxConfig.octet = radio.read_reg(REG_FSK_RXCONFIG);
     return fsk.RegRxConfig.bits.RestartRxOnCollision;
 }
 
@@ -1211,7 +1211,7 @@
 void Radio::rssiOffset_print(void)
 {
     int ro;
-    fsk.RegRssiConfig.octet = radio.read_reg(REG_FSK_RSSICONFIG);          
+    fsk.RegRssiConfig.octet = radio.read_reg(REG_FSK_RSSICONFIG);
     ro = fsk.RegRssiConfig.bits.RssiOffset;
     pc.printf("%d", ro);
 }
@@ -1263,7 +1263,7 @@
 bool Radio::dataMode_push()
 {
     fsk.RegPktConfig2.bits.DataModePacket ^= 1;
-    radio.write_u16(REG_FSK_PACKETCONFIG2, fsk.RegPktConfig2.word);  
+    radio.write_u16(REG_FSK_PACKETCONFIG2, fsk.RegPktConfig2.word);
     return fsk.RegPktConfig2.bits.DataModePacket;
 }
 
@@ -1327,7 +1327,7 @@
 menuMode_e Radio::pdSize_write(unsigned sidx)
 {
     fsk.RegPreambleDetect.bits.PreambleDetectorSize = sidx;
-    radio.write_reg(REG_FSK_PREAMBLEDETECT, fsk.RegPreambleDetect.octet);     
+    radio.write_reg(REG_FSK_PREAMBLEDETECT, fsk.RegPreambleDetect.octet);
     return MENUMODE_REDRAW;
 }
 
@@ -1344,7 +1344,7 @@
     unsigned n;
     sscanf(txt, "%u", &n);
     fsk.RegPreambleDetect.bits.PreambleDetectorTol = n;
-    radio.write_reg(REG_FSK_PREAMBLEDETECT, fsk.RegPreambleDetect.octet);  
+    radio.write_reg(REG_FSK_PREAMBLEDETECT, fsk.RegPreambleDetect.octet);
     return false;
 }
 
@@ -1352,7 +1352,7 @@
 
 bool Radio::TxStartCondition_read()
 {
-    fsk.RegFifoThreshold.octet = radio.read_reg(REG_FSK_FIFOTHRESH);  
+    fsk.RegFifoThreshold.octet = radio.read_reg(REG_FSK_FIFOTHRESH);
     return fsk.RegFifoThreshold.bits.TxStartCondition;
 }
 
@@ -1371,7 +1371,7 @@
 
 void Radio::FifoThreshold_print(void)
 {
-    fsk.RegFifoThreshold.octet = radio.read_reg(REG_FSK_FIFOTHRESH);  
+    fsk.RegFifoThreshold.octet = radio.read_reg(REG_FSK_FIFOTHRESH);
     pc.printf("%u", fsk.RegFifoThreshold.bits.FifoThreshold);
 }
 
--- a/radio_sx128x.cpp	Sun Nov 25 15:34:40 2018 -0800
+++ b/radio_sx128x.cpp	Thu Dec 06 14:24:18 2018 -0800
@@ -1474,7 +1474,7 @@
 
     ppLORA.lora.PreambleLength = (exp << 4) + mant;
     radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
-    
+
     return false;
 }