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.

radio_ff_arduino_sx127x.cpp

Committer:
Wayne Roberts
Date:
2020-05-04
Revision:
9:295e37c38fb3
Parent:
7:ea73b63b9eb1
Child:
14:14b9e1c08bfc

File content as of revision 9:295e37c38fb3:

/* Only for NUCLEO boards: prevent compiling for MOTE_L152RC and typeABZ discovery */
#if defined(TARGET_FF_ARDUINO) && !defined(TARGET_DISCO_L072CZ_LRWAN1)
#include "radio.h"
#ifdef SX127x_H 

SPI spi(D11, D12, D13); // mosi, miso, sclk
//                  dio0, dio1, nss, spi, rst
SX127x Radio::radio(  D2,   D3, D10, spi, A0); // sx127[62] arduino shield
SX127x_lora Radio::lora(radio);
SX127x_fsk Radio::fsk(radio);

InterruptIn Radio::dio0(D2);
InterruptIn Radio::dio1(D3);

typedef enum {
    SHIELD_TYPE_NONE = 0,
    SHIELD_TYPE_LAS,
    SHIELD_TYPE_MAS,
} shield_type_e;
shield_type_e shield_type;

#ifdef TARGET_FF_MORPHO
DigitalOut pc3(PC_3);   // debug RX indication, for nucleo boards
#endif /* TARGET_FF_MORPHO */
DigitalInOut rfsw(A4);
void Radio::rfsw_callback()
{
    if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER)
        rfsw = 1;
    else
        rfsw = 0;

#ifdef TARGET_FF_MORPHO
    if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
        pc3 = 1;
    else
        pc3 = 0;
#endif /* TARGET_FF_MORPHO */
}

void Radio::targetInit()
{
    radio.rf_switch = rfsw_callback;

    rfsw.input();

    radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);

    if (rfsw.read()) {
        shield_type = SHIELD_TYPE_LAS;
        radio.RegPaConfig.bits.PaSelect = 1;
    } else {
        shield_type = SHIELD_TYPE_MAS;
        radio.RegPaConfig.bits.PaSelect = 0;
    }

    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);

    rfsw.output();
}

void Radio::tx_dbm_print()
{
    int dbm;
    RegPdsTrim1_t pds_trim;
    uint8_t adr, pa_test_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.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;
        }
    } else {
        dbm = PA_OFF_DBM;
    }
    pc.printf("%d", dbm);
}

bool Radio::tx_dbm_write(const char* str)
{
    int i;
    uint8_t v, adr, pa_test_adr;
    RegPdsTrim1_t pds_trim;

    sscanf(str, "%d", &i);

    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;
    }

    v = radio.read_reg(pa_test_adr);

    if (i == PA_OFF_DBM) {
        /* for bench testing: prevent overloading receiving station (very low TX power) */
        v &= ~0x20; // turn off pu_regpa_n: disable PA
        radio.write_reg(pa_test_adr, v);
        return false;
    } else if ((v & 0x20) == 0) {
        v |= 0x20; // turn on pu_regpa_n: enable PA
        radio.write_reg(pa_test_adr, v);
    }

    pds_trim.octet = radio.read_reg(adr);

    if (radio.RegPaConfig.bits.PaSelect) {
        /* PABOOST used: +2dbm to +17, or +20 */
        if (i == 20) {
            log_printf("+20dBm PADAC bias\r\n");
            i -= 3;
            pds_trim.bits.prog_txdac = 7;
            radio.write_reg(adr, pds_trim.octet);
        }
        if (i > 1)
                radio.RegPaConfig.bits.OutputPower = i - 2;
    } else {
        /* RFO used: -1 to +14dbm */
        if (i < 15)
            radio.RegPaConfig.bits.OutputPower = i + 1;
    }
    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);

    return false;
}


#endif /* ..SX127x_H */
#endif /* ...sx127x shield */