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.

Committer:
dudmuck
Date:
Thu Sep 16 21:57:23 2021 +0000
Revision:
14:14b9e1c08bfc
Parent:
11:3a73edb3b246
BufferedSerial flush printf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 1:0817a150122b 1 #include "radio.h"
Wayne Roberts 11:3a73edb3b246 2 #ifdef SX127x_H
Wayne Roberts 1:0817a150122b 3
Wayne Roberts 1:0817a150122b 4 SPI spi(PA_7, PA_6, PB_3); // mosi, miso, sclk
Wayne Roberts 1:0817a150122b 5 // dio0, dio1, nss, spi, rst
Wayne Roberts 1:0817a150122b 6 SX127x Radio::radio(PB_4, PB_1, PA_15, spi, PC_0);
Wayne Roberts 1:0817a150122b 7 SX127x_lora Radio::lora(radio);
Wayne Roberts 1:0817a150122b 8 SX127x_fsk Radio::fsk(radio);
Wayne Roberts 1:0817a150122b 9
Wayne Roberts 1:0817a150122b 10 #define CRF1 PA_1
Wayne Roberts 1:0817a150122b 11 #define CRF2 PC_2
Wayne Roberts 1:0817a150122b 12 #define CRF3 PC_1
Wayne Roberts 1:0817a150122b 13 DigitalOut Vctl1(CRF1);
Wayne Roberts 1:0817a150122b 14 DigitalOut Vctl2(CRF2);
Wayne Roberts 1:0817a150122b 15 DigitalOut Vctl3(CRF3);
Wayne Roberts 1:0817a150122b 16
Wayne Roberts 1:0817a150122b 17 void Radio::rfsw_callback()
Wayne Roberts 1:0817a150122b 18 {
Wayne Roberts 1:0817a150122b 19 if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {
Wayne Roberts 5:1e5cb7139acb 20 Vctl1 = 0;
Wayne Roberts 1:0817a150122b 21 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 1:0817a150122b 22 Vctl2 = 0;
Wayne Roberts 5:1e5cb7139acb 23 Vctl3 = 1;
Wayne Roberts 1:0817a150122b 24 } else {
Wayne Roberts 1:0817a150122b 25 Vctl2 = 1;
Wayne Roberts 5:1e5cb7139acb 26 Vctl3 = 0;
Wayne Roberts 1:0817a150122b 27 }
Wayne Roberts 1:0817a150122b 28 } else {
Wayne Roberts 1:0817a150122b 29 if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
Wayne Roberts 1:0817a150122b 30 Vctl1 = 1;
Wayne Roberts 1:0817a150122b 31 else
Wayne Roberts 1:0817a150122b 32 Vctl1 = 0;
Wayne Roberts 5:1e5cb7139acb 33
Wayne Roberts 1:0817a150122b 34 Vctl2 = 0;
Wayne Roberts 5:1e5cb7139acb 35 Vctl3 = 0;
Wayne Roberts 1:0817a150122b 36 }
Wayne Roberts 1:0817a150122b 37 }
Wayne Roberts 1:0817a150122b 38
Wayne Roberts 1:0817a150122b 39 void Radio::tx_dbm_print()
Wayne Roberts 1:0817a150122b 40 {
Wayne Roberts 1:0817a150122b 41 int dbm;
Wayne Roberts 1:0817a150122b 42 RegPdsTrim1_t pds_trim;
Wayne Roberts 5:1e5cb7139acb 43 uint8_t adr, pa_test_adr;
Wayne Roberts 1:0817a150122b 44
Wayne Roberts 5:1e5cb7139acb 45 if (radio.type == SX1276) {
Wayne Roberts 1:0817a150122b 46 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 5:1e5cb7139acb 47 pa_test_adr = REG_PATEST_SX1276;
Wayne Roberts 5:1e5cb7139acb 48 } else {
Wayne Roberts 1:0817a150122b 49 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 5:1e5cb7139acb 50 pa_test_adr = REG_PATEST_SX1272;
Wayne Roberts 5:1e5cb7139acb 51 }
Wayne Roberts 1:0817a150122b 52
Wayne Roberts 5:1e5cb7139acb 53 if (radio.read_reg(pa_test_adr) & 0x20) {
Wayne Roberts 5:1e5cb7139acb 54 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 1:0817a150122b 55
Wayne Roberts 5:1e5cb7139acb 56 radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
Wayne Roberts 5:1e5cb7139acb 57 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 5:1e5cb7139acb 58 dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
Wayne Roberts 5:1e5cb7139acb 59 } else {
Wayne Roberts 5:1e5cb7139acb 60 dbm = radio.RegPaConfig.bits.OutputPower - 1;
Wayne Roberts 5:1e5cb7139acb 61 }
Wayne Roberts 5:1e5cb7139acb 62 } else
Wayne Roberts 5:1e5cb7139acb 63 dbm = PA_OFF_DBM;
Wayne Roberts 5:1e5cb7139acb 64
Wayne Roberts 5:1e5cb7139acb 65 pc.printf("%d", dbm);
Wayne Roberts 1:0817a150122b 66 }
Wayne Roberts 1:0817a150122b 67
Wayne Roberts 1:0817a150122b 68 bool Radio::tx_dbm_write(const char* str)
Wayne Roberts 1:0817a150122b 69 {
Wayne Roberts 1:0817a150122b 70 int dbm;
Wayne Roberts 1:0817a150122b 71 uint8_t adr;
Wayne Roberts 1:0817a150122b 72 RegPdsTrim1_t pds_trim;
Wayne Roberts 1:0817a150122b 73
Wayne Roberts 1:0817a150122b 74 sscanf(str, "%d", &dbm);
Wayne Roberts 1:0817a150122b 75
Wayne Roberts 1:0817a150122b 76 if (radio.type == SX1276)
Wayne Roberts 1:0817a150122b 77 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 1:0817a150122b 78 else
Wayne Roberts 1:0817a150122b 79 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 5:1e5cb7139acb 80
Wayne Roberts 5:1e5cb7139acb 81 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 1:0817a150122b 82
Wayne Roberts 1:0817a150122b 83 if (dbm > 14) {
Wayne Roberts 1:0817a150122b 84 radio.RegPaConfig.bits.PaSelect = 1; // PA_BOOST
Wayne Roberts 1:0817a150122b 85 if (dbm > 17) {
Wayne Roberts 1:0817a150122b 86 dbm -= 3;
Wayne Roberts 1:0817a150122b 87 pds_trim.bits.prog_txdac = 7;
Wayne Roberts 1:0817a150122b 88 radio.write_reg(adr, pds_trim.octet);
Wayne Roberts 1:0817a150122b 89 }
Wayne Roberts 1:0817a150122b 90 radio.RegPaConfig.bits.OutputPower = dbm - 2;
Wayne Roberts 1:0817a150122b 91 } else {
Wayne Roberts 1:0817a150122b 92 radio.RegPaConfig.bits.PaSelect = 0; // RFO
Wayne Roberts 1:0817a150122b 93 radio.RegPaConfig.bits.OutputPower = dbm + 1;
Wayne Roberts 1:0817a150122b 94 }
Wayne Roberts 1:0817a150122b 95
Wayne Roberts 1:0817a150122b 96 radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
Wayne Roberts 1:0817a150122b 97
Wayne Roberts 1:0817a150122b 98 return false;
Wayne Roberts 1:0817a150122b 99 }
Wayne Roberts 1:0817a150122b 100
Wayne Roberts 1:0817a150122b 101 void Radio::targetInit()
Wayne Roberts 1:0817a150122b 102 {
Wayne Roberts 1:0817a150122b 103 radio.rf_switch = rfsw_callback;
Wayne Roberts 1:0817a150122b 104 }
Wayne Roberts 11:3a73edb3b246 105 #endif /* ..SX127x_H */