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:
Thu Dec 06 14:24:18 2018 -0800
Revision:
5:1e5cb7139acb
Parent:
1:0817a150122b
Child:
11:3a73edb3b246
correct PA_OFF for sx127x

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 5:1e5cb7139acb 19 Vctl1 = 0;
Wayne Roberts 1:0817a150122b 20 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 1:0817a150122b 21 Vctl2 = 0;
Wayne Roberts 5:1e5cb7139acb 22 Vctl3 = 1;
Wayne Roberts 1:0817a150122b 23 } else {
Wayne Roberts 1:0817a150122b 24 Vctl2 = 1;
Wayne Roberts 5:1e5cb7139acb 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 5:1e5cb7139acb 32
Wayne Roberts 1:0817a150122b 33 Vctl2 = 0;
Wayne Roberts 5:1e5cb7139acb 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 5:1e5cb7139acb 42 uint8_t adr, pa_test_adr;
Wayne Roberts 1:0817a150122b 43
Wayne Roberts 5:1e5cb7139acb 44 if (radio.type == SX1276) {
Wayne Roberts 1:0817a150122b 45 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 5:1e5cb7139acb 46 pa_test_adr = REG_PATEST_SX1276;
Wayne Roberts 5:1e5cb7139acb 47 } else {
Wayne Roberts 1:0817a150122b 48 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 5:1e5cb7139acb 49 pa_test_adr = REG_PATEST_SX1272;
Wayne Roberts 5:1e5cb7139acb 50 }
Wayne Roberts 1:0817a150122b 51
Wayne Roberts 5:1e5cb7139acb 52 if (radio.read_reg(pa_test_adr) & 0x20) {
Wayne Roberts 5:1e5cb7139acb 53 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 1:0817a150122b 54
Wayne Roberts 5:1e5cb7139acb 55 radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
Wayne Roberts 5:1e5cb7139acb 56 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 5:1e5cb7139acb 57 dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
Wayne Roberts 5:1e5cb7139acb 58 } else {
Wayne Roberts 5:1e5cb7139acb 59 dbm = radio.RegPaConfig.bits.OutputPower - 1;
Wayne Roberts 5:1e5cb7139acb 60 }
Wayne Roberts 5:1e5cb7139acb 61 } else
Wayne Roberts 5:1e5cb7139acb 62 dbm = PA_OFF_DBM;
Wayne Roberts 5:1e5cb7139acb 63
Wayne Roberts 5:1e5cb7139acb 64 pc.printf("%d", dbm);
Wayne Roberts 1:0817a150122b 65 }
Wayne Roberts 1:0817a150122b 66
Wayne Roberts 1:0817a150122b 67 bool Radio::tx_dbm_write(const char* str)
Wayne Roberts 1:0817a150122b 68 {
Wayne Roberts 1:0817a150122b 69 int dbm;
Wayne Roberts 1:0817a150122b 70 uint8_t adr;
Wayne Roberts 1:0817a150122b 71 RegPdsTrim1_t pds_trim;
Wayne Roberts 1:0817a150122b 72
Wayne Roberts 1:0817a150122b 73 sscanf(str, "%d", &dbm);
Wayne Roberts 1:0817a150122b 74
Wayne Roberts 1:0817a150122b 75 if (radio.type == SX1276)
Wayne Roberts 1:0817a150122b 76 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 1:0817a150122b 77 else
Wayne Roberts 1:0817a150122b 78 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 5:1e5cb7139acb 79
Wayne Roberts 5:1e5cb7139acb 80 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 1:0817a150122b 81
Wayne Roberts 1:0817a150122b 82 if (dbm > 14) {
Wayne Roberts 1:0817a150122b 83 radio.RegPaConfig.bits.PaSelect = 1; // PA_BOOST
Wayne Roberts 1:0817a150122b 84 if (dbm > 17) {
Wayne Roberts 1:0817a150122b 85 dbm -= 3;
Wayne Roberts 1:0817a150122b 86 pds_trim.bits.prog_txdac = 7;
Wayne Roberts 1:0817a150122b 87 radio.write_reg(adr, pds_trim.octet);
Wayne Roberts 1:0817a150122b 88 }
Wayne Roberts 1:0817a150122b 89 radio.RegPaConfig.bits.OutputPower = dbm - 2;
Wayne Roberts 1:0817a150122b 90 } else {
Wayne Roberts 1:0817a150122b 91 radio.RegPaConfig.bits.PaSelect = 0; // RFO
Wayne Roberts 1:0817a150122b 92 radio.RegPaConfig.bits.OutputPower = dbm + 1;
Wayne Roberts 1:0817a150122b 93 }
Wayne Roberts 1:0817a150122b 94
Wayne Roberts 1:0817a150122b 95 radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
Wayne Roberts 1:0817a150122b 96
Wayne Roberts 1:0817a150122b 97 return false;
Wayne Roberts 1:0817a150122b 98 }
Wayne Roberts 1:0817a150122b 99
Wayne Roberts 1:0817a150122b 100 void Radio::targetInit()
Wayne Roberts 1:0817a150122b 101 {
Wayne Roberts 1:0817a150122b 102 radio.rf_switch = rfsw_callback;
Wayne Roberts 1:0817a150122b 103 }