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:
Wayne Roberts
Date:
Mon Aug 20 18:13:09 2018 -0700
Revision:
1:0817a150122b
Child:
5:1e5cb7139acb
add source files

Who changed what in which revision?

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