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:
2:ea9245bb1c53
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 #ifdef SX126x_H
Wayne Roberts 1:0817a150122b 3
Wayne Roberts 1:0817a150122b 4 #ifdef TARGET_FF_ARDUINO
Wayne Roberts 1:0817a150122b 5 SPI spi(D11, D12, D13); // mosi, miso, sclk
Wayne Roberts 1:0817a150122b 6 //spi, nss, busy, dio1
Wayne Roberts 1:0817a150122b 7 SX126x Radio::radio(spi, D7, D3, D5);
Wayne Roberts 1:0817a150122b 8
Wayne Roberts 1:0817a150122b 9 DigitalOut antswPower(D8);
Wayne Roberts 1:0817a150122b 10 AnalogIn xtalSel(A3);
Wayne Roberts 1:0817a150122b 11
Wayne Roberts 1:0817a150122b 12 DigitalIn chipType(A2);
Wayne Roberts 1:0817a150122b 13 #define CHIP_TYPE_SX1262 0
Wayne Roberts 1:0817a150122b 14 #define CHIP_TYPE_SX1261 1
Wayne Roberts 1:0817a150122b 15
Wayne Roberts 1:0817a150122b 16 #define PINNAME_NRST A0
Wayne Roberts 1:0817a150122b 17
Wayne Roberts 1:0817a150122b 18 #define LED_ON 1
Wayne Roberts 1:0817a150122b 19 #define LED_OFF 0
Wayne Roberts 1:0817a150122b 20 DigitalOut tx_led(A4);
Wayne Roberts 1:0817a150122b 21 DigitalOut rx_led(A5);
Wayne Roberts 1:0817a150122b 22
Wayne Roberts 1:0817a150122b 23 void Radio::chipModeChange()
Wayne Roberts 1:0817a150122b 24 {
Wayne Roberts 1:0817a150122b 25 if (radio.chipMode == CHIPMODE_NONE) {
Wayne Roberts 1:0817a150122b 26 tx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 27 rx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 28 } else if (radio.chipMode == CHIPMODE_TX) {
Wayne Roberts 1:0817a150122b 29 tx_led = LED_ON;
Wayne Roberts 1:0817a150122b 30 rx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 31 } else if (radio.chipMode == CHIPMODE_RX) {
Wayne Roberts 1:0817a150122b 32 tx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 33 rx_led = LED_ON;
Wayne Roberts 1:0817a150122b 34 }
Wayne Roberts 1:0817a150122b 35 }
Wayne Roberts 1:0817a150122b 36 #endif /* TARGET_FF_ARDUINO */
Wayne Roberts 1:0817a150122b 37
Wayne Roberts 1:0817a150122b 38 const char* const Radio::chipNum_str = "SX126x";
Wayne Roberts 1:0817a150122b 39
Wayne Roberts 1:0817a150122b 40 ModulationParams_t Radio::mpFSK, Radio::mpLORA;
Wayne Roberts 1:0817a150122b 41 PacketParams_t Radio::ppFSK, Radio::ppLORA;
Wayne Roberts 1:0817a150122b 42
Wayne Roberts 1:0817a150122b 43 const RadioEvents_t* Radio::RadioEvents;
Wayne Roberts 1:0817a150122b 44 LowPowerTimer Radio::lpt;
Wayne Roberts 1:0817a150122b 45 uint8_t Radio::pktType;
Wayne Roberts 1:0817a150122b 46 uint8_t Radio::bw_idx;
Wayne Roberts 1:0817a150122b 47
Wayne Roberts 1:0817a150122b 48 const char* opModes[] = {
Wayne Roberts 1:0817a150122b 49 "SLEEP ", // 0
Wayne Roberts 1:0817a150122b 50 "STBY_RC ", // 1
Wayne Roberts 1:0817a150122b 51 "STBY_XOSC", // 2
Wayne Roberts 1:0817a150122b 52 "FS ", // 3
Wayne Roberts 1:0817a150122b 53 "RX ", // 4
Wayne Roberts 1:0817a150122b 54 "TX " // 5
Wayne Roberts 1:0817a150122b 55 };
Wayne Roberts 1:0817a150122b 56
Wayne Roberts 1:0817a150122b 57 void Radio::readChip()
Wayne Roberts 1:0817a150122b 58 {
Wayne Roberts 1:0817a150122b 59 bwSel_t bwSel;
Wayne Roberts 1:0817a150122b 60 shapeCfg_t shapeCfg;
Wayne Roberts 1:0817a150122b 61 unsigned d = radio.readReg(REG_ADDR_BITRATE, 3);
Wayne Roberts 1:0817a150122b 62 pc.printf("%06x:%u->", d ,d);
Wayne Roberts 1:0817a150122b 63 pc.printf("bitrate %ubps\r\n", (32 * XTAL_FREQ_HZ) / d);
Wayne Roberts 1:0817a150122b 64 mpFSK.gfsk.bitrateHi = d >> 16;
Wayne Roberts 1:0817a150122b 65 mpFSK.gfsk.bitrateMid = d >> 8;
Wayne Roberts 1:0817a150122b 66 mpFSK.gfsk.bitrateLo = d;
Wayne Roberts 1:0817a150122b 67
Wayne Roberts 1:0817a150122b 68 d = radio.readReg(REG_ADDR_FREQDEV, 3);
Wayne Roberts 1:0817a150122b 69 pc.printf("fdev %fKHz\r\n", d / KHZ_TO_FRF);
Wayne Roberts 1:0817a150122b 70 mpFSK.gfsk.fdevHi = d >> 16;
Wayne Roberts 1:0817a150122b 71 mpFSK.gfsk.fdevMid = d >> 8;
Wayne Roberts 1:0817a150122b 72 mpFSK.gfsk.fdevLo = d;
Wayne Roberts 1:0817a150122b 73
Wayne Roberts 1:0817a150122b 74 shapeCfg.octet = radio.readReg(REG_ADDR_SHAPECFG, 1);
Wayne Roberts 1:0817a150122b 75 mpFSK.gfsk.PulseShape = shapeCfg.octet;
Wayne Roberts 1:0817a150122b 76
Wayne Roberts 1:0817a150122b 77 bwSel.octet = radio.readReg(REG_ADDR_BWSEL, 1);
Wayne Roberts 1:0817a150122b 78 // GFSK_RX_BW_*
Wayne Roberts 1:0817a150122b 79 pc.printf("bwsSel:%02x\r\n", bwSel.octet);
Wayne Roberts 1:0817a150122b 80 mpFSK.gfsk.bandwidth = bwSel.octet;
Wayne Roberts 1:0817a150122b 81
Wayne Roberts 1:0817a150122b 82 {
Wayne Roberts 1:0817a150122b 83 unsigned n = radio.readReg(REG_ADDR_FSK_PREAMBLE_TXLEN , 2);
Wayne Roberts 1:0817a150122b 84 ppFSK.gfsk.PreambleLengthHi = n << 8; // param1
Wayne Roberts 1:0817a150122b 85 ppFSK.gfsk.PreambleLengthLo = n;// param2
Wayne Roberts 1:0817a150122b 86 }
Wayne Roberts 1:0817a150122b 87
Wayne Roberts 1:0817a150122b 88 {
Wayne Roberts 1:0817a150122b 89 pktCtrl1_t pktCtrl1;
Wayne Roberts 1:0817a150122b 90 pktCtrl1.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 91 ppFSK.gfsk.PreambleDetectorLength = pktCtrl1.octet & 0x07; // param3
Wayne Roberts 1:0817a150122b 92 }
Wayne Roberts 1:0817a150122b 93
Wayne Roberts 1:0817a150122b 94
Wayne Roberts 1:0817a150122b 95 ppFSK.gfsk.SyncWordLength = radio.readReg(REG_ADDR_FSK_SYNC_LEN, 1);// param4
Wayne Roberts 1:0817a150122b 96 ppFSK.gfsk.AddrComp = radio.readReg(REG_ADDR_NODEADDRCOMP, 1);// param5
Wayne Roberts 1:0817a150122b 97
Wayne Roberts 1:0817a150122b 98 {
Wayne Roberts 1:0817a150122b 99 pktCtrl0_t pktCtrl0;
Wayne Roberts 1:0817a150122b 100 pktCtrl0.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL0, 1);
Wayne Roberts 1:0817a150122b 101 ppFSK.gfsk.PacketType = pktCtrl0.bits.pkt_len_format; // param6
Wayne Roberts 1:0817a150122b 102 }
Wayne Roberts 1:0817a150122b 103
Wayne Roberts 1:0817a150122b 104 ppFSK.gfsk.PayloadLength = radio.readReg(REG_ADDR_FSK_PAYLOAD_LEN, 1);// param7
Wayne Roberts 1:0817a150122b 105
Wayne Roberts 1:0817a150122b 106 {
Wayne Roberts 1:0817a150122b 107 pktCtrl2_t pktCtrl2;
Wayne Roberts 1:0817a150122b 108 pktCtrl2.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL2, 1);
Wayne Roberts 1:0817a150122b 109 ppFSK.gfsk.CRCType = pktCtrl2.octet & 0x7; // param8
Wayne Roberts 1:0817a150122b 110 ppFSK.gfsk.Whitening = pktCtrl2.bits.whit_enable; // param9
Wayne Roberts 1:0817a150122b 111 }
Wayne Roberts 1:0817a150122b 112
Wayne Roberts 1:0817a150122b 113 /*******************************/
Wayne Roberts 1:0817a150122b 114
Wayne Roberts 1:0817a150122b 115 {
Wayne Roberts 1:0817a150122b 116 loraConfig0_t conf0;
Wayne Roberts 1:0817a150122b 117 conf0.octet = radio.readReg(REG_ADDR_LORA_CONFIG0, 1);
Wayne Roberts 1:0817a150122b 118 pc.printf("LoRa bw%u sf%u ", conf0.bits.modem_bw, conf0.bits.modem_sf);
Wayne Roberts 1:0817a150122b 119 mpLORA.lora.spreadingFactor = conf0.bits.modem_sf;
Wayne Roberts 1:0817a150122b 120 mpLORA.lora.bandwidth = conf0.bits.modem_bw;
Wayne Roberts 1:0817a150122b 121 }
Wayne Roberts 1:0817a150122b 122
Wayne Roberts 1:0817a150122b 123 {
Wayne Roberts 1:0817a150122b 124 loraConfig1_t conf1;
Wayne Roberts 1:0817a150122b 125 conf1.octet = radio.readReg(REG_ADDR_LORA_CONFIG1, 1);
Wayne Roberts 1:0817a150122b 126 mpLORA.lora.LowDatarateOptimize = conf1.bits.ppm_offset;
Wayne Roberts 1:0817a150122b 127 ppLORA.lora.HeaderType = conf1.bits.implicit_header;
Wayne Roberts 1:0817a150122b 128 ppLORA.lora.InvertIQ = conf1.bits.rx_invert_iq;
Wayne Roberts 1:0817a150122b 129 mpLORA.lora.codingRate = conf1.bits.tx_coding_rate;
Wayne Roberts 1:0817a150122b 130 }
Wayne Roberts 1:0817a150122b 131
Wayne Roberts 1:0817a150122b 132 {
Wayne Roberts 1:0817a150122b 133 loraConfig2_t conf2;
Wayne Roberts 1:0817a150122b 134 conf2.octet = radio.readReg(REG_ADDR_LORA_CONFIG2, 1);
Wayne Roberts 1:0817a150122b 135 ppLORA.lora.CRCType = conf2.bits.tx_payload_crc16_en;
Wayne Roberts 1:0817a150122b 136 }
Wayne Roberts 1:0817a150122b 137
Wayne Roberts 1:0817a150122b 138 {
Wayne Roberts 1:0817a150122b 139 uint32_t val = radio.readReg(REG_ADDR_LORA_PREAMBLE_SYMBNB, 2);
Wayne Roberts 1:0817a150122b 140 ppLORA.lora.PreambleLengthHi = val >> 8;
Wayne Roberts 1:0817a150122b 141 ppLORA.lora.PreambleLengthLo = val;
Wayne Roberts 1:0817a150122b 142 }
Wayne Roberts 1:0817a150122b 143
Wayne Roberts 1:0817a150122b 144 {
Wayne Roberts 1:0817a150122b 145 AnaCtrl6_t AnaCtrl6;
Wayne Roberts 1:0817a150122b 146 AnaCtrl7_t AnaCtrl7;
Wayne Roberts 1:0817a150122b 147 PaCtrl1b_t PaCtrl1b;
Wayne Roberts 1:0817a150122b 148
Wayne Roberts 1:0817a150122b 149 AnaCtrl6.octet = radio.readReg(REG_ADDR_ANACTRL6, 1);
Wayne Roberts 1:0817a150122b 150 pa_config_buf[0] = AnaCtrl6.bits.pa_dctrim_select_ana; // paDutyCycle
Wayne Roberts 1:0817a150122b 151
Wayne Roberts 1:0817a150122b 152 AnaCtrl7.octet = radio.readReg(REG_ADDR_ANACTRL7, 1);
Wayne Roberts 1:0817a150122b 153 pa_config_buf[1] = AnaCtrl7.bits.pa_hp_sel_ana; // hpMax
Wayne Roberts 1:0817a150122b 154
Wayne Roberts 1:0817a150122b 155 PaCtrl1b.octet = radio.readReg(REG_ADDR_PA_CTRL1B, 1);
Wayne Roberts 1:0817a150122b 156 pa_config_buf[2] = PaCtrl1b.bits.tx_mode_bat; // deviceSel
Wayne Roberts 1:0817a150122b 157
Wayne Roberts 1:0817a150122b 158 pa_config_buf[3] = 1; // paLut
Wayne Roberts 1:0817a150122b 159 }
Wayne Roberts 1:0817a150122b 160
Wayne Roberts 1:0817a150122b 161 }
Wayne Roberts 1:0817a150122b 162
Wayne Roberts 1:0817a150122b 163 void Radio::hw_reset()
Wayne Roberts 1:0817a150122b 164 {
Wayne Roberts 1:0817a150122b 165 radio.hw_reset(PINNAME_NRST);
Wayne Roberts 1:0817a150122b 166 }
Wayne Roberts 1:0817a150122b 167
Wayne Roberts 1:0817a150122b 168 void Radio::clearIrqFlags()
Wayne Roberts 1:0817a150122b 169 {
Wayne Roberts 1:0817a150122b 170 uint8_t buf[2];
Wayne Roberts 1:0817a150122b 171 buf[0] = 0x03;
Wayne Roberts 1:0817a150122b 172 buf[1] = 0xff;
Wayne Roberts 1:0817a150122b 173 radio.xfer(OPCODE_CLEAR_IRQ_STATUS, 2, 0, buf);
Wayne Roberts 1:0817a150122b 174 }
Wayne Roberts 1:0817a150122b 175
Wayne Roberts 1:0817a150122b 176 uint8_t Radio::get_payload_length()
Wayne Roberts 1:0817a150122b 177 {
Wayne Roberts 1:0817a150122b 178 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 179
Wayne Roberts 1:0817a150122b 180 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 181 ppFSK.gfsk.PayloadLength = radio.readReg(REG_ADDR_FSK_PAYLOAD_LEN, 1);
Wayne Roberts 1:0817a150122b 182 return ppFSK.gfsk.PayloadLength;
Wayne Roberts 1:0817a150122b 183 } else if (pktType == PACKET_TYPE_LORA) {
Wayne Roberts 1:0817a150122b 184 ppLORA.lora.PayloadLength = radio.readReg(REG_ADDR_LORA_TXPKTLEN, 1);
Wayne Roberts 1:0817a150122b 185 return ppLORA.lora.PayloadLength;
Wayne Roberts 1:0817a150122b 186 } else
Wayne Roberts 1:0817a150122b 187 return 0;
Wayne Roberts 1:0817a150122b 188 }
Wayne Roberts 1:0817a150122b 189
Wayne Roberts 1:0817a150122b 190 const char* const Radio::opmode_status_strs[] = {
Wayne Roberts 1:0817a150122b 191 "<0> ", // 0
Wayne Roberts 1:0817a150122b 192 "RFU ", // 1
Wayne Roberts 1:0817a150122b 193 "STBY_RC ", // 2
Wayne Roberts 1:0817a150122b 194 "STBY_XOSC", // 3
Wayne Roberts 1:0817a150122b 195 "FS ", // 4
Wayne Roberts 1:0817a150122b 196 "RX ", // 5
Wayne Roberts 1:0817a150122b 197 "TX ", // 6
Wayne Roberts 1:0817a150122b 198 "<7> ", // 7
Wayne Roberts 1:0817a150122b 199 NULL
Wayne Roberts 1:0817a150122b 200 };
Wayne Roberts 1:0817a150122b 201
Wayne Roberts 1:0817a150122b 202 const char* const Radio::opmode_select_strs[] = {
Wayne Roberts 1:0817a150122b 203 "SLEEP ", // 0
Wayne Roberts 1:0817a150122b 204 "STDBY_RC ", // 1
Wayne Roberts 1:0817a150122b 205 "STDBY_XOSC", // 2
Wayne Roberts 1:0817a150122b 206 "FS ", // 3
Wayne Roberts 1:0817a150122b 207 "RX ", // 4
Wayne Roberts 1:0817a150122b 208 "TX ", // 5
Wayne Roberts 1:0817a150122b 209 NULL
Wayne Roberts 1:0817a150122b 210 };
Wayne Roberts 1:0817a150122b 211
Wayne Roberts 1:0817a150122b 212 unsigned Radio::opmode_read_cb(bool forWriting)
Wayne Roberts 1:0817a150122b 213 {
Wayne Roberts 1:0817a150122b 214 status_t status;
Wayne Roberts 1:0817a150122b 215 radio.xfer(OPCODE_GET_STATUS, 0, 1, &status.octet);
Wayne Roberts 1:0817a150122b 216
Wayne Roberts 1:0817a150122b 217 if (forWriting) {
Wayne Roberts 1:0817a150122b 218 /* translate opmode_status_strs to opmode_select_strs */
Wayne Roberts 1:0817a150122b 219 switch (status.bits.chipMode) {
Wayne Roberts 1:0817a150122b 220 case 2: return 1; // STBY_RC
Wayne Roberts 1:0817a150122b 221 case 3: return 2; // STBY_XOSC
Wayne Roberts 1:0817a150122b 222 case 4: return 3; // FS
Wayne Roberts 1:0817a150122b 223 case 5: return 4; // RX
Wayne Roberts 1:0817a150122b 224 case 6: return 5; // TX
Wayne Roberts 1:0817a150122b 225 default: return 0;
Wayne Roberts 1:0817a150122b 226 }
Wayne Roberts 1:0817a150122b 227 } else
Wayne Roberts 1:0817a150122b 228 return status.bits.chipMode;
Wayne Roberts 1:0817a150122b 229 }
Wayne Roberts 1:0817a150122b 230
Wayne Roberts 1:0817a150122b 231 menuMode_e Radio::opmode_write_cb(unsigned sel)
Wayne Roberts 1:0817a150122b 232 {
Wayne Roberts 1:0817a150122b 233 switch (sel) {
Wayne Roberts 1:0817a150122b 234 case 0:
Wayne Roberts 1:0817a150122b 235 antswPower = 0;
Wayne Roberts 1:0817a150122b 236 radio.setSleep(true, false);
Wayne Roberts 1:0817a150122b 237 break;
Wayne Roberts 1:0817a150122b 238 case 1:
Wayne Roberts 1:0817a150122b 239 antswPower = 0;
Wayne Roberts 1:0817a150122b 240 radio.setStandby(STBY_RC);
Wayne Roberts 1:0817a150122b 241 break;
Wayne Roberts 1:0817a150122b 242 case 2:
Wayne Roberts 1:0817a150122b 243 antswPower = 0;
Wayne Roberts 1:0817a150122b 244 radio.setStandby(STBY_XOSC);
Wayne Roberts 1:0817a150122b 245 break;
Wayne Roberts 1:0817a150122b 246 case 3:
Wayne Roberts 1:0817a150122b 247 antswPower = 0;
Wayne Roberts 1:0817a150122b 248 radio.setFS();
Wayne Roberts 1:0817a150122b 249 break;
Wayne Roberts 1:0817a150122b 250 case 4:
Wayne Roberts 1:0817a150122b 251 antswPower = 1;
Wayne Roberts 1:0817a150122b 252 radio.start_rx(0);
Wayne Roberts 1:0817a150122b 253 break;
Wayne Roberts 1:0817a150122b 254 case 5:
Wayne Roberts 1:0817a150122b 255 antswPower = 1;
Wayne Roberts 1:0817a150122b 256 {
Wayne Roberts 1:0817a150122b 257 uint8_t buf[3];
Wayne Roberts 1:0817a150122b 258 buf[0] = 0;
Wayne Roberts 1:0817a150122b 259 buf[0] = 0;
Wayne Roberts 1:0817a150122b 260 buf[1] = 0;
Wayne Roberts 1:0817a150122b 261 radio.xfer(OPCODE_SET_TX, 3, 0, buf);
Wayne Roberts 1:0817a150122b 262 }
Wayne Roberts 1:0817a150122b 263 break;
Wayne Roberts 1:0817a150122b 264 }
Wayne Roberts 1:0817a150122b 265
Wayne Roberts 1:0817a150122b 266 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 267 }
Wayne Roberts 1:0817a150122b 268
Wayne Roberts 1:0817a150122b 269 void Radio::setFS()
Wayne Roberts 1:0817a150122b 270 {
Wayne Roberts 1:0817a150122b 271 radio.setFS();
Wayne Roberts 1:0817a150122b 272 }
Wayne Roberts 1:0817a150122b 273
Wayne Roberts 1:0817a150122b 274 const char* const Radio::pktType_strs[] = {
Wayne Roberts 1:0817a150122b 275 "GFSK ",
Wayne Roberts 1:0817a150122b 276 "LORA ",
Wayne Roberts 1:0817a150122b 277 NULL
Wayne Roberts 1:0817a150122b 278 };
Wayne Roberts 1:0817a150122b 279
Wayne Roberts 1:0817a150122b 280 unsigned Radio::pktType_read_cb(bool fw)
Wayne Roberts 1:0817a150122b 281 {
Wayne Roberts 1:0817a150122b 282 return radio.getPacketType();
Wayne Roberts 1:0817a150122b 283 }
Wayne Roberts 1:0817a150122b 284
Wayne Roberts 1:0817a150122b 285 menuMode_e Radio::pktType_write_cb(unsigned idx)
Wayne Roberts 1:0817a150122b 286 {
Wayne Roberts 1:0817a150122b 287 radio.setPacketType(idx);
Wayne Roberts 1:0817a150122b 288 return MENUMODE_REINIT_MENU;
Wayne Roberts 1:0817a150122b 289 }
Wayne Roberts 1:0817a150122b 290
Wayne Roberts 1:0817a150122b 291 void Radio::tx_carrier()
Wayne Roberts 1:0817a150122b 292 {
Wayne Roberts 1:0817a150122b 293 radio.xfer(OPCODE_SET_TX_CARRIER, 0, 0, NULL);
Wayne Roberts 1:0817a150122b 294 }
Wayne Roberts 1:0817a150122b 295
Wayne Roberts 1:0817a150122b 296 void Radio::tx_preamble()
Wayne Roberts 1:0817a150122b 297 {
Wayne Roberts 1:0817a150122b 298 radio.xfer(OPCODE_SET_TX_PREAMBLE, 0, 0, NULL);
Wayne Roberts 1:0817a150122b 299 }
Wayne Roberts 1:0817a150122b 300
Wayne Roberts 1:0817a150122b 301 void Radio::txPkt()
Wayne Roberts 1:0817a150122b 302 {
Wayne Roberts 1:0817a150122b 303 uint8_t txlen = get_payload_length();
Wayne Roberts 1:0817a150122b 304
Wayne Roberts 1:0817a150122b 305 radio.setBufferBase(0, 0);
Wayne Roberts 1:0817a150122b 306
Wayne Roberts 1:0817a150122b 307 {
Wayne Roberts 1:0817a150122b 308 uint8_t buf[8];
Wayne Roberts 1:0817a150122b 309 IrqFlags_t irqEnable;
Wayne Roberts 1:0817a150122b 310 irqEnable.word = 0;
Wayne Roberts 1:0817a150122b 311 irqEnable.bits.TxDone = 1;
Wayne Roberts 1:0817a150122b 312 irqEnable.bits.Timeout = 1;
Wayne Roberts 1:0817a150122b 313
Wayne Roberts 1:0817a150122b 314 buf[0] = irqEnable.word >> 8; // enable bits
Wayne Roberts 1:0817a150122b 315 buf[1] = irqEnable.word; // enable bits
Wayne Roberts 1:0817a150122b 316 buf[2] = irqEnable.word >> 8; // dio1
Wayne Roberts 1:0817a150122b 317 buf[3] = irqEnable.word; // dio1
Wayne Roberts 1:0817a150122b 318 buf[4] = 0; // dio2
Wayne Roberts 1:0817a150122b 319 buf[5] = 0; // dio2
Wayne Roberts 1:0817a150122b 320 buf[6] = 0; // dio3
Wayne Roberts 1:0817a150122b 321 buf[7] = 0; // dio3
Wayne Roberts 1:0817a150122b 322 radio.xfer(OPCODE_SET_DIO_IRQ_PARAMS, 8, 0, buf);
Wayne Roberts 1:0817a150122b 323 }
Wayne Roberts 1:0817a150122b 324
Wayne Roberts 1:0817a150122b 325 radio.start_tx(txlen);
Wayne Roberts 1:0817a150122b 326 }
Wayne Roberts 1:0817a150122b 327
Wayne Roberts 1:0817a150122b 328 uint8_t Radio::tx_param_buf[2];
Wayne Roberts 1:0817a150122b 329 uint8_t Radio::pa_config_buf[4];
Wayne Roberts 1:0817a150122b 330
Wayne Roberts 1:0817a150122b 331 void Radio::tx_dbm_print()
Wayne Roberts 1:0817a150122b 332 {
Wayne Roberts 1:0817a150122b 333 PwrCtrl_t PwrCtrl;
Wayne Roberts 1:0817a150122b 334 PaCtrl1b_t PaCtrl1b;
Wayne Roberts 1:0817a150122b 335
Wayne Roberts 1:0817a150122b 336 PwrCtrl.octet = radio.readReg(REG_ADDR_PWR_CTRL, 1);
Wayne Roberts 1:0817a150122b 337
Wayne Roberts 1:0817a150122b 338 PaCtrl1b.octet = radio.readReg(REG_ADDR_PA_CTRL1B, 1);
Wayne Roberts 1:0817a150122b 339 pa_config_buf[2] = PaCtrl1b.bits.tx_mode_bat; // deviceSel
Wayne Roberts 1:0817a150122b 340
Wayne Roberts 1:0817a150122b 341 if (PaCtrl1b.bits.tx_mode_bat)
Wayne Roberts 1:0817a150122b 342 pc.printf("%d", PwrCtrl.bits.tx_pwr - 17);
Wayne Roberts 1:0817a150122b 343 else
Wayne Roberts 1:0817a150122b 344 pc.printf("%d", PwrCtrl.bits.tx_pwr - 9);
Wayne Roberts 1:0817a150122b 345 }
Wayne Roberts 1:0817a150122b 346
Wayne Roberts 1:0817a150122b 347 bool Radio::tx_dbm_write(const char* str)
Wayne Roberts 1:0817a150122b 348 {
Wayne Roberts 1:0817a150122b 349 int dbm;
Wayne Roberts 1:0817a150122b 350
Wayne Roberts 1:0817a150122b 351 sscanf(str, "%d", &dbm);
Wayne Roberts 1:0817a150122b 352
Wayne Roberts 1:0817a150122b 353 tx_param_buf[0] = dbm;
Wayne Roberts 1:0817a150122b 354
Wayne Roberts 1:0817a150122b 355 radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
Wayne Roberts 1:0817a150122b 356 return false;
Wayne Roberts 1:0817a150122b 357 }
Wayne Roberts 1:0817a150122b 358
Wayne Roberts 1:0817a150122b 359 const char* Radio::tx_ramp_strs[] = {
Wayne Roberts 1:0817a150122b 360 "10 ", // 0
Wayne Roberts 1:0817a150122b 361 "20 ", // 1
Wayne Roberts 1:0817a150122b 362 "80 ", // 2
Wayne Roberts 1:0817a150122b 363 "80 ", // 3
Wayne Roberts 1:0817a150122b 364 "200 ", // 4
Wayne Roberts 1:0817a150122b 365 "800 ", // 5
Wayne Roberts 1:0817a150122b 366 "1700", // 6
Wayne Roberts 1:0817a150122b 367 "3400", // 7
Wayne Roberts 1:0817a150122b 368 NULL
Wayne Roberts 1:0817a150122b 369 };
Wayne Roberts 1:0817a150122b 370
Wayne Roberts 1:0817a150122b 371 unsigned Radio::tx_ramp_read_cb(bool fw)
Wayne Roberts 1:0817a150122b 372 {
Wayne Roberts 1:0817a150122b 373 PwrCtrl_t PwrCtrl;
Wayne Roberts 1:0817a150122b 374 PwrCtrl.octet = radio.readReg(REG_ADDR_PWR_CTRL, 1);
Wayne Roberts 1:0817a150122b 375 tx_param_buf[1] = PwrCtrl.octet >> 5;
Wayne Roberts 1:0817a150122b 376 return PwrCtrl.bits.ramp_time;
Wayne Roberts 1:0817a150122b 377 }
Wayne Roberts 1:0817a150122b 378
Wayne Roberts 1:0817a150122b 379 menuMode_e Radio::tx_ramp_write_cb(unsigned sidx)
Wayne Roberts 1:0817a150122b 380 {
Wayne Roberts 1:0817a150122b 381 tx_param_buf[1] = sidx;
Wayne Roberts 1:0817a150122b 382 radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
Wayne Roberts 1:0817a150122b 383 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 384 }
Wayne Roberts 1:0817a150122b 385
Wayne Roberts 1:0817a150122b 386 void Radio::set_payload_length(uint8_t len)
Wayne Roberts 1:0817a150122b 387 {
Wayne Roberts 1:0817a150122b 388 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 389
Wayne Roberts 1:0817a150122b 390 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 391 ppFSK.gfsk.PayloadLength = len;
Wayne Roberts 1:0817a150122b 392 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 393 } else if (pktType == PACKET_TYPE_LORA) {
Wayne Roberts 1:0817a150122b 394 ppLORA.lora.PayloadLength = len;
Wayne Roberts 1:0817a150122b 395 radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 396 }
Wayne Roberts 1:0817a150122b 397 }
Wayne Roberts 1:0817a150122b 398
Wayne Roberts 1:0817a150122b 399 void Radio::tx_payload_length_print()
Wayne Roberts 1:0817a150122b 400 {
Wayne Roberts 1:0817a150122b 401 pc.printf("%u", get_payload_length());
Wayne Roberts 1:0817a150122b 402 }
Wayne Roberts 1:0817a150122b 403
Wayne Roberts 1:0817a150122b 404 bool Radio::tx_payload_length_write(const char* txt)
Wayne Roberts 1:0817a150122b 405 {
Wayne Roberts 1:0817a150122b 406 unsigned len;
Wayne Roberts 1:0817a150122b 407
Wayne Roberts 1:0817a150122b 408 sscanf(txt, "%u", &len);
Wayne Roberts 1:0817a150122b 409
Wayne Roberts 1:0817a150122b 410 set_payload_length(len);
Wayne Roberts 1:0817a150122b 411
Wayne Roberts 1:0817a150122b 412 return false;
Wayne Roberts 1:0817a150122b 413 }
Wayne Roberts 1:0817a150122b 414
Wayne Roberts 1:0817a150122b 415 bool Radio::service(int8_t statusRow)
Wayne Roberts 1:0817a150122b 416 {
Wayne Roberts 1:0817a150122b 417 static uint8_t prevRxStatus;
Wayne Roberts 1:0817a150122b 418 static uint8_t prevPktCtrl0;
Wayne Roberts 1:0817a150122b 419 uint8_t buf[4];
Wayne Roberts 1:0817a150122b 420 static IrqFlags_t prevIrqFlags;
Wayne Roberts 1:0817a150122b 421 IrqFlags_t irqFlags;
Wayne Roberts 1:0817a150122b 422 bool ret = false;
Wayne Roberts 1:0817a150122b 423 static us_timestamp_t prev_now;
Wayne Roberts 1:0817a150122b 424 us_timestamp_t now = lpt.read_us();
Wayne Roberts 1:0817a150122b 425
Wayne Roberts 1:0817a150122b 426 radio.service();
Wayne Roberts 1:0817a150122b 427
Wayne Roberts 1:0817a150122b 428 if (statusRow > 0 && now-prev_now > 50000) {
Wayne Roberts 1:0817a150122b 429 uint8_t rxStatus, pktCtrl0;
Wayne Roberts 1:0817a150122b 430 bool chg = false;
Wayne Roberts 1:0817a150122b 431 radio.xfer(OPCODE_GET_IRQ_STATUS, 0, 3, buf);
Wayne Roberts 1:0817a150122b 432 irqFlags.word = buf[1] << 8;
Wayne Roberts 1:0817a150122b 433 irqFlags.word |= buf[2];
Wayne Roberts 1:0817a150122b 434
Wayne Roberts 1:0817a150122b 435 rxStatus = radio.readReg(0x6c9, 1);
Wayne Roberts 1:0817a150122b 436 if (rxStatus != prevRxStatus) {
Wayne Roberts 1:0817a150122b 437 chg = true;
Wayne Roberts 1:0817a150122b 438 prevRxStatus = rxStatus;
Wayne Roberts 1:0817a150122b 439 }
Wayne Roberts 1:0817a150122b 440
Wayne Roberts 1:0817a150122b 441 pktCtrl0 = radio.readReg(0x6b3, 1);
Wayne Roberts 1:0817a150122b 442 if (pktCtrl0 != prevPktCtrl0) {
Wayne Roberts 1:0817a150122b 443 chg = true;
Wayne Roberts 1:0817a150122b 444 prevPktCtrl0 = pktCtrl0;
Wayne Roberts 1:0817a150122b 445 }
Wayne Roberts 1:0817a150122b 446
Wayne Roberts 1:0817a150122b 447 if (irqFlags.word != prevIrqFlags.word && chg) {
Wayne Roberts 1:0817a150122b 448 pc.printf("\e[%u;1f", statusRow); // set (force) cursor to row;column
Wayne Roberts 1:0817a150122b 449
Wayne Roberts 1:0817a150122b 450 pc.printf("%02x ", rxStatus);
Wayne Roberts 1:0817a150122b 451 pc.printf("%02x ", pktCtrl0);
Wayne Roberts 1:0817a150122b 452
Wayne Roberts 1:0817a150122b 453 if (irqFlags.bits.TxDone)
Wayne Roberts 1:0817a150122b 454 pc.printf("TxDone ");
Wayne Roberts 1:0817a150122b 455 if (irqFlags.bits.RxDone)
Wayne Roberts 1:0817a150122b 456 pc.printf("RxDone ");
Wayne Roberts 1:0817a150122b 457 if (irqFlags.bits.PreambleDetected)
Wayne Roberts 1:0817a150122b 458 pc.printf("PreambleDetected ");
Wayne Roberts 1:0817a150122b 459 if (irqFlags.bits.SyncWordValid)
Wayne Roberts 1:0817a150122b 460 pc.printf("SyncWordValid ");
Wayne Roberts 1:0817a150122b 461 if (irqFlags.bits.HeaderValid)
Wayne Roberts 1:0817a150122b 462 pc.printf("HeaderValid ");
Wayne Roberts 1:0817a150122b 463 if (irqFlags.bits.HeaderErr)
Wayne Roberts 1:0817a150122b 464 pc.printf("HeaderErr ");
Wayne Roberts 1:0817a150122b 465 if (irqFlags.bits.CrCerr)
Wayne Roberts 1:0817a150122b 466 pc.printf("CrCerr ");
Wayne Roberts 1:0817a150122b 467 if (irqFlags.bits.CadDone)
Wayne Roberts 1:0817a150122b 468 pc.printf("CadDone ");
Wayne Roberts 1:0817a150122b 469 if (irqFlags.bits.CadDetected)
Wayne Roberts 1:0817a150122b 470 pc.printf("CadDetected ");
Wayne Roberts 1:0817a150122b 471 if (irqFlags.bits.Timeout)
Wayne Roberts 1:0817a150122b 472 pc.printf("Timeout ");
Wayne Roberts 1:0817a150122b 473
Wayne Roberts 1:0817a150122b 474 pc.printf("\e[K");
Wayne Roberts 1:0817a150122b 475 ret = true;
Wayne Roberts 1:0817a150122b 476
Wayne Roberts 1:0817a150122b 477 prevIrqFlags.word = irqFlags.word;
Wayne Roberts 1:0817a150122b 478 }
Wayne Roberts 1:0817a150122b 479
Wayne Roberts 1:0817a150122b 480 prev_now = now;
Wayne Roberts 1:0817a150122b 481 }
Wayne Roberts 1:0817a150122b 482
Wayne Roberts 1:0817a150122b 483 return ret;
Wayne Roberts 1:0817a150122b 484 }
Wayne Roberts 1:0817a150122b 485
Wayne Roberts 1:0817a150122b 486 void Radio::Rx()
Wayne Roberts 1:0817a150122b 487 {
Wayne Roberts 1:0817a150122b 488 antswPower = 1;
Wayne Roberts 1:0817a150122b 489
Wayne Roberts 1:0817a150122b 490 {
Wayne Roberts 1:0817a150122b 491 uint8_t buf[8];
Wayne Roberts 1:0817a150122b 492 IrqFlags_t irqEnable;
Wayne Roberts 1:0817a150122b 493 irqEnable.word = 0;
Wayne Roberts 1:0817a150122b 494 irqEnable.bits.RxDone = 1;
Wayne Roberts 1:0817a150122b 495 irqEnable.bits.Timeout = 1;
Wayne Roberts 1:0817a150122b 496
Wayne Roberts 1:0817a150122b 497 buf[0] = 3;//irqEnable.word >> 8; // enable bits
Wayne Roberts 1:0817a150122b 498 buf[1] = 0xff;//irqEnable.word; // enable bits
Wayne Roberts 1:0817a150122b 499 buf[2] = irqEnable.word >> 8; // dio1
Wayne Roberts 1:0817a150122b 500 buf[3] = irqEnable.word; // dio1
Wayne Roberts 1:0817a150122b 501 buf[4] = 0; // dio2
Wayne Roberts 1:0817a150122b 502 buf[5] = 0; // dio2
Wayne Roberts 1:0817a150122b 503 buf[6] = 0; // dio3
Wayne Roberts 1:0817a150122b 504 buf[7] = 0; // dio3
Wayne Roberts 1:0817a150122b 505 radio.xfer(OPCODE_SET_DIO_IRQ_PARAMS, 8, 0, buf);
Wayne Roberts 1:0817a150122b 506 }
Wayne Roberts 1:0817a150122b 507
Wayne Roberts 1:0817a150122b 508 radio.start_rx(RX_TIMEOUT_CONTINUOUS);
Wayne Roberts 1:0817a150122b 509 }
Wayne Roberts 1:0817a150122b 510
Wayne Roberts 1:0817a150122b 511 void Radio::rxDone(uint8_t size, float rssi, float snr)
Wayne Roberts 1:0817a150122b 512 {
Wayne Roberts 1:0817a150122b 513 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 514 int16_t cfo = radio.readReg(REG_ADDR_FSK_DEMOD_CFO, 2);
Wayne Roberts 1:0817a150122b 515 // justify 12bit to 16bit signed
Wayne Roberts 1:0817a150122b 516 if (cfo & 0x0800)
Wayne Roberts 1:0817a150122b 517 cfo |= 0xf000;
Wayne Roberts 1:0817a150122b 518 log_printf("cfo:%d\r\n", cfo);
Wayne Roberts 1:0817a150122b 519 } else if (pktType == PACKET_TYPE_LORA) {
Wayne Roberts 1:0817a150122b 520 const float bwkhzs[] = {
Wayne Roberts 1:0817a150122b 521 7.81, 10.42, 15.63, 20.83, 31.25, 41.67, 62.5, 125, 250, 500
Wayne Roberts 1:0817a150122b 522 };
Wayne Roberts 1:0817a150122b 523 int hz;
Wayne Roberts 1:0817a150122b 524 int32_t fei;
Wayne Roberts 1:0817a150122b 525 loraStatus1_t loraStatus1;
Wayne Roberts 1:0817a150122b 526 loraStatus1.dword = radio.readReg(REG_ADDR_LORA_STATUS, 3);
Wayne Roberts 1:0817a150122b 527 if (loraStatus1.bits.est_freq_error & 0x80000)
Wayne Roberts 1:0817a150122b 528 fei = 0xfff00000 | loraStatus1.bits.est_freq_error;
Wayne Roberts 1:0817a150122b 529 else
Wayne Roberts 1:0817a150122b 530 fei = loraStatus1.bits.est_freq_error;
Wayne Roberts 1:0817a150122b 531
Wayne Roberts 1:0817a150122b 532 //hz = fei * HZ_TO_FRF * bwkhzs[bw_idx]/500;
Wayne Roberts 1:0817a150122b 533 hz = fei * -HZ_TO_FRF * bwkhzs[bw_idx]/1000;
Wayne Roberts 1:0817a150122b 534 log_printf("hz:%d\r\n", hz);
Wayne Roberts 1:0817a150122b 535 }
Wayne Roberts 1:0817a150122b 536
Wayne Roberts 1:0817a150122b 537 RadioEvents->RxDone(size, rssi, snr);
Wayne Roberts 1:0817a150122b 538 }
Wayne Roberts 1:0817a150122b 539
Wayne Roberts 1:0817a150122b 540 void Radio::txDoneBottom()
Wayne Roberts 1:0817a150122b 541 {
Wayne Roberts 1:0817a150122b 542 if (RadioEvents->TxDone_botHalf)
Wayne Roberts 1:0817a150122b 543 RadioEvents->TxDone_botHalf();
Wayne Roberts 1:0817a150122b 544 }
Wayne Roberts 1:0817a150122b 545
Wayne Roberts 1:0817a150122b 546 uint8_t ana_regs[128];
Wayne Roberts 1:0817a150122b 547
Wayne Roberts 1:0817a150122b 548 void Radio::boardInit(const RadioEvents_t* e)
Wayne Roberts 1:0817a150122b 549 {
Wayne Roberts 1:0817a150122b 550 hw_reset();
Wayne Roberts 1:0817a150122b 551
Wayne Roberts 1:0817a150122b 552 radio.txDone = txDoneBottom;
Wayne Roberts 1:0817a150122b 553 radio.rxDone = rxDone;
Wayne Roberts 1:0817a150122b 554
Wayne Roberts 1:0817a150122b 555 radio.chipModeChange = chipModeChange;
Wayne Roberts 1:0817a150122b 556
Wayne Roberts 1:0817a150122b 557 readChip();
Wayne Roberts 1:0817a150122b 558
Wayne Roberts 1:0817a150122b 559 RadioEvents = e;
Wayne Roberts 1:0817a150122b 560
Wayne Roberts 1:0817a150122b 561 lpt.start();
Wayne Roberts 1:0817a150122b 562 }
Wayne Roberts 1:0817a150122b 563
Wayne Roberts 1:0817a150122b 564 bool Radio::deviceSel_read()
Wayne Roberts 1:0817a150122b 565 {
Wayne Roberts 1:0817a150122b 566 PaCtrl1b_t PaCtrl1b;
Wayne Roberts 1:0817a150122b 567 PaCtrl1b.octet = radio.readReg(REG_ADDR_PA_CTRL1B, 1);
Wayne Roberts 1:0817a150122b 568 pa_config_buf[2] = PaCtrl1b.bits.tx_mode_bat; // deviceSel
Wayne Roberts 1:0817a150122b 569 return PaCtrl1b.bits.tx_mode_bat;
Wayne Roberts 1:0817a150122b 570 }
Wayne Roberts 1:0817a150122b 571
Wayne Roberts 1:0817a150122b 572 bool Radio::deviceSel_push()
Wayne Roberts 1:0817a150122b 573 {
Wayne Roberts 1:0817a150122b 574 if (pa_config_buf[2])
Wayne Roberts 1:0817a150122b 575 pa_config_buf[2] = 0;
Wayne Roberts 1:0817a150122b 576 else
Wayne Roberts 1:0817a150122b 577 pa_config_buf[2] = 1;
Wayne Roberts 1:0817a150122b 578
Wayne Roberts 1:0817a150122b 579 radio.xfer(OPCODE_SET_PA_CONFIG, 4, 0, pa_config_buf);
Wayne Roberts 1:0817a150122b 580
Wayne Roberts 1:0817a150122b 581 return pa_config_buf[2];
Wayne Roberts 1:0817a150122b 582 }
Wayne Roberts 1:0817a150122b 583
Wayne Roberts 1:0817a150122b 584 const toggle_item_t Radio::deviceSel_item = { _ITEM_TOGGLE, "SX1262", "SX1261", deviceSel_read, deviceSel_push};
Wayne Roberts 1:0817a150122b 585
Wayne Roberts 1:0817a150122b 586 static const char* paDutyCycles[] = {
Wayne Roberts 1:0817a150122b 587 "0",
Wayne Roberts 1:0817a150122b 588 "1",
Wayne Roberts 1:0817a150122b 589 "2",
Wayne Roberts 1:0817a150122b 590 "3",
Wayne Roberts 1:0817a150122b 591 "4",
Wayne Roberts 1:0817a150122b 592 "5",
Wayne Roberts 1:0817a150122b 593 "6",
Wayne Roberts 1:0817a150122b 594 "7",
Wayne Roberts 1:0817a150122b 595 NULL
Wayne Roberts 1:0817a150122b 596 };
Wayne Roberts 1:0817a150122b 597
Wayne Roberts 1:0817a150122b 598 unsigned Radio::paDutyCycle_read(bool forWriting)
Wayne Roberts 1:0817a150122b 599 {
Wayne Roberts 1:0817a150122b 600 AnaCtrl6_t AnaCtrl6;
Wayne Roberts 1:0817a150122b 601 AnaCtrl6.octet = radio.readReg(REG_ADDR_ANACTRL6, 1);
Wayne Roberts 1:0817a150122b 602 pa_config_buf[0] = AnaCtrl6.bits.pa_dctrim_select_ana;
Wayne Roberts 1:0817a150122b 603 return AnaCtrl6.bits.pa_dctrim_select_ana;
Wayne Roberts 1:0817a150122b 604 }
Wayne Roberts 1:0817a150122b 605
Wayne Roberts 1:0817a150122b 606 menuMode_e Radio::paDutyCycle_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 607 {
Wayne Roberts 1:0817a150122b 608 pa_config_buf[0] = sidx;
Wayne Roberts 1:0817a150122b 609 radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
Wayne Roberts 1:0817a150122b 610 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 611 }
Wayne Roberts 1:0817a150122b 612
Wayne Roberts 1:0817a150122b 613 const dropdown_item_t Radio::paDutyCycle_item = { _ITEM_DROPDOWN, paDutyCycles, paDutyCycles, paDutyCycle_read, paDutyCycle_write};
Wayne Roberts 1:0817a150122b 614
Wayne Roberts 1:0817a150122b 615 static const char* hpMaxs[] = {
Wayne Roberts 1:0817a150122b 616 "0",
Wayne Roberts 1:0817a150122b 617 "1",
Wayne Roberts 1:0817a150122b 618 "2",
Wayne Roberts 1:0817a150122b 619 "3",
Wayne Roberts 1:0817a150122b 620 "4",
Wayne Roberts 1:0817a150122b 621 "5",
Wayne Roberts 1:0817a150122b 622 "6",
Wayne Roberts 1:0817a150122b 623 "7",
Wayne Roberts 1:0817a150122b 624 NULL
Wayne Roberts 1:0817a150122b 625 };
Wayne Roberts 1:0817a150122b 626
Wayne Roberts 1:0817a150122b 627 unsigned Radio::hpMax_read(bool forWriting)
Wayne Roberts 1:0817a150122b 628 {
Wayne Roberts 1:0817a150122b 629 AnaCtrl7_t AnaCtrl7;
Wayne Roberts 1:0817a150122b 630 AnaCtrl7.octet = radio.readReg(REG_ADDR_ANACTRL7, 1);
Wayne Roberts 1:0817a150122b 631 pa_config_buf[1] = AnaCtrl7.bits.pa_hp_sel_ana;
Wayne Roberts 1:0817a150122b 632 return AnaCtrl7.bits.pa_hp_sel_ana;
Wayne Roberts 1:0817a150122b 633 }
Wayne Roberts 1:0817a150122b 634
Wayne Roberts 1:0817a150122b 635 menuMode_e Radio::hpMax_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 636 {
Wayne Roberts 1:0817a150122b 637 pa_config_buf[1] = sidx;
Wayne Roberts 1:0817a150122b 638 radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
Wayne Roberts 1:0817a150122b 639 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 640 }
Wayne Roberts 1:0817a150122b 641
Wayne Roberts 1:0817a150122b 642 const dropdown_item_t Radio::hpMax_item = { _ITEM_DROPDOWN, hpMaxs, hpMaxs, hpMax_read, hpMax_write};
Wayne Roberts 1:0817a150122b 643
Wayne Roberts 1:0817a150122b 644 void Radio::ocp_print()
Wayne Roberts 1:0817a150122b 645 {
Wayne Roberts 1:0817a150122b 646 uint8_t ocp = radio.readReg(REG_ADDR_OCP, 1);
Wayne Roberts 1:0817a150122b 647 pc.printf("%.1f", ocp * 2.5);
Wayne Roberts 1:0817a150122b 648
Wayne Roberts 1:0817a150122b 649 }
Wayne Roberts 1:0817a150122b 650
Wayne Roberts 1:0817a150122b 651 bool Radio::ocp_write(const char* txt)
Wayne Roberts 1:0817a150122b 652 {
Wayne Roberts 1:0817a150122b 653 float mA;
Wayne Roberts 1:0817a150122b 654 if (sscanf(txt, "%f", &mA) == 1)
Wayne Roberts 1:0817a150122b 655 radio.writeReg(REG_ADDR_OCP, mA / 2.5, 1);
Wayne Roberts 1:0817a150122b 656
Wayne Roberts 1:0817a150122b 657 return false;
Wayne Roberts 1:0817a150122b 658 }
Wayne Roberts 1:0817a150122b 659
Wayne Roberts 1:0817a150122b 660 const value_item_t Radio::ocp_item = { _ITEM_VALUE, 7, ocp_print, ocp_write};
Wayne Roberts 1:0817a150122b 661
Wayne Roberts 1:0817a150122b 662 const menu_t Radio::common_menu[] = {
Wayne Roberts 1:0817a150122b 663 { {FIRST_CHIP_MENU_ROW, 1}, "deviceSel:", &deviceSel_item, FLAG_MSGTYPE_ALL, &tx_dbm_item },
Wayne Roberts 1:0817a150122b 664 { {FIRST_CHIP_MENU_ROW, 18}, "paDutyCycle:", &paDutyCycle_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 665 { {FIRST_CHIP_MENU_ROW, 36}, "hpMax:", &hpMax_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 666 { {FIRST_CHIP_MENU_ROW, 45}, "ocp mA:", &ocp_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 667
Wayne Roberts 1:0817a150122b 668 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 669 };
Wayne Roberts 1:0817a150122b 670
Wayne Roberts 1:0817a150122b 671 const uint8_t loraBWs[] = {
Wayne Roberts 1:0817a150122b 672 LORA_BW_7, LORA_BW_10, LORA_BW_15,
Wayne Roberts 1:0817a150122b 673 LORA_BW_20, LORA_BW_31, LORA_BW_41,
Wayne Roberts 1:0817a150122b 674 LORA_BW_62, LORA_BW_125, LORA_BW_250,
Wayne Roberts 1:0817a150122b 675 LORA_BW_500
Wayne Roberts 1:0817a150122b 676 };
Wayne Roberts 1:0817a150122b 677
Wayne Roberts 1:0817a150122b 678 static const char* lora_bwstrs[] = {
Wayne Roberts 1:0817a150122b 679 " 7.81KHz", "10.42KHz", "15.63KHz",
Wayne Roberts 1:0817a150122b 680 "20.83KHz", "31.25KHz", "41.67KHz",
Wayne Roberts 1:0817a150122b 681 " 62.5KHz", " 125KHz", " 250KHz",
Wayne Roberts 1:0817a150122b 682 " 500KHz",
Wayne Roberts 1:0817a150122b 683 NULL
Wayne Roberts 1:0817a150122b 684 };
Wayne Roberts 1:0817a150122b 685
Wayne Roberts 1:0817a150122b 686 unsigned Radio::lora_bw_read(bool forWriting)
Wayne Roberts 1:0817a150122b 687 {
Wayne Roberts 1:0817a150122b 688 unsigned n;
Wayne Roberts 1:0817a150122b 689 loraConfig0_t conf0;
Wayne Roberts 1:0817a150122b 690 conf0.octet = radio.readReg(REG_ADDR_LORA_CONFIG0, 1);
Wayne Roberts 1:0817a150122b 691 mpLORA.lora.bandwidth = conf0.bits.modem_bw;
Wayne Roberts 1:0817a150122b 692 for (n = 0; n < sizeof(loraBWs); n++) {
Wayne Roberts 1:0817a150122b 693 if (conf0.bits.modem_bw == loraBWs[n]) {
Wayne Roberts 1:0817a150122b 694 bw_idx = n;
Wayne Roberts 1:0817a150122b 695 return n;
Wayne Roberts 1:0817a150122b 696 }
Wayne Roberts 1:0817a150122b 697 }
Wayne Roberts 1:0817a150122b 698 return sizeof(loraBWs);
Wayne Roberts 1:0817a150122b 699 }
Wayne Roberts 1:0817a150122b 700
Wayne Roberts 1:0817a150122b 701 menuMode_e Radio::lora_bw_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 702 {
Wayne Roberts 1:0817a150122b 703 mpLORA.lora.bandwidth = loraBWs[sidx];
Wayne Roberts 1:0817a150122b 704 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 705 bw_idx = sidx;
Wayne Roberts 1:0817a150122b 706 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 707 }
Wayne Roberts 1:0817a150122b 708
Wayne Roberts 1:0817a150122b 709 const dropdown_item_t Radio::lora_bw_item = { _ITEM_DROPDOWN, lora_bwstrs, lora_bwstrs, lora_bw_read, lora_bw_write};
Wayne Roberts 1:0817a150122b 710
Wayne Roberts 1:0817a150122b 711 void Radio::lora_sf_print()
Wayne Roberts 1:0817a150122b 712 {
Wayne Roberts 1:0817a150122b 713 loraConfig0_t conf0;
Wayne Roberts 1:0817a150122b 714 conf0.octet = radio.readReg(REG_ADDR_LORA_CONFIG0, 1);
Wayne Roberts 1:0817a150122b 715 mpLORA.lora.spreadingFactor = conf0.bits.modem_sf;
Wayne Roberts 1:0817a150122b 716 pc.printf("%u", conf0.bits.modem_sf);
Wayne Roberts 1:0817a150122b 717 }
Wayne Roberts 1:0817a150122b 718
Wayne Roberts 1:0817a150122b 719 bool Radio::lora_sf_write(const char* str)
Wayne Roberts 1:0817a150122b 720 {
Wayne Roberts 1:0817a150122b 721 unsigned sf;
Wayne Roberts 1:0817a150122b 722 if (sscanf(str, "%u", &sf) == 1) {
Wayne Roberts 1:0817a150122b 723 mpLORA.lora.spreadingFactor = sf;
Wayne Roberts 1:0817a150122b 724 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 725 }
Wayne Roberts 1:0817a150122b 726 return false;
Wayne Roberts 1:0817a150122b 727 }
Wayne Roberts 1:0817a150122b 728
Wayne Roberts 1:0817a150122b 729 const value_item_t Radio::lora_sf_item = { _ITEM_VALUE, 3, lora_sf_print, lora_sf_write };
Wayne Roberts 1:0817a150122b 730
Wayne Roberts 1:0817a150122b 731 static const char* lora_crs[] = {
Wayne Roberts 1:0817a150122b 732 "4/5 ",
Wayne Roberts 1:0817a150122b 733 "4/6 ",
Wayne Roberts 1:0817a150122b 734 "4/7 ",
Wayne Roberts 1:0817a150122b 735 "4/8 ",
Wayne Roberts 1:0817a150122b 736 NULL
Wayne Roberts 1:0817a150122b 737 };
Wayne Roberts 1:0817a150122b 738
Wayne Roberts 1:0817a150122b 739 unsigned Radio::lora_cr_read(bool forWriting)
Wayne Roberts 1:0817a150122b 740 {
Wayne Roberts 1:0817a150122b 741 loraConfig1_t conf1;
Wayne Roberts 1:0817a150122b 742 conf1.octet = radio.readReg(REG_ADDR_LORA_CONFIG1, 1);
Wayne Roberts 1:0817a150122b 743 mpLORA.lora.codingRate = conf1.bits.tx_coding_rate;
Wayne Roberts 1:0817a150122b 744 return conf1.bits.tx_coding_rate;
Wayne Roberts 1:0817a150122b 745 }
Wayne Roberts 1:0817a150122b 746
Wayne Roberts 1:0817a150122b 747 menuMode_e Radio::lora_cr_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 748 {
Wayne Roberts 1:0817a150122b 749 mpLORA.lora.codingRate = sidx;
Wayne Roberts 1:0817a150122b 750 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 751 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 752 }
Wayne Roberts 1:0817a150122b 753
Wayne Roberts 1:0817a150122b 754 const dropdown_item_t Radio::lora_cr_item = { _ITEM_DROPDOWN, lora_crs, lora_crs, lora_cr_read, lora_cr_write};
Wayne Roberts 1:0817a150122b 755
Wayne Roberts 1:0817a150122b 756 bool Radio::ppmOffset_read()
Wayne Roberts 1:0817a150122b 757 {
Wayne Roberts 1:0817a150122b 758 loraConfig1_t conf1;
Wayne Roberts 1:0817a150122b 759 conf1.octet = radio.readReg(REG_ADDR_LORA_CONFIG1, 1);
Wayne Roberts 1:0817a150122b 760 mpLORA.lora.LowDatarateOptimize = conf1.bits.ppm_offset;
Wayne Roberts 1:0817a150122b 761 return conf1.bits.ppm_offset;
Wayne Roberts 1:0817a150122b 762 }
Wayne Roberts 1:0817a150122b 763
Wayne Roberts 1:0817a150122b 764 bool Radio::ppmOffset_push()
Wayne Roberts 1:0817a150122b 765 {
Wayne Roberts 1:0817a150122b 766 if (mpLORA.lora.LowDatarateOptimize)
Wayne Roberts 1:0817a150122b 767 mpLORA.lora.LowDatarateOptimize = 0;
Wayne Roberts 1:0817a150122b 768 else
Wayne Roberts 1:0817a150122b 769 mpLORA.lora.LowDatarateOptimize = 1;
Wayne Roberts 1:0817a150122b 770
Wayne Roberts 1:0817a150122b 771 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 4, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 772 return mpLORA.lora.LowDatarateOptimize;
Wayne Roberts 1:0817a150122b 773 }
Wayne Roberts 1:0817a150122b 774
Wayne Roberts 1:0817a150122b 775 const toggle_item_t Radio::lora_ppmOffset_item = { _ITEM_TOGGLE, "LowDatarateOptimize", NULL, ppmOffset_read, ppmOffset_push};
Wayne Roberts 1:0817a150122b 776
Wayne Roberts 1:0817a150122b 777 void Radio::lora_pblLen_print()
Wayne Roberts 1:0817a150122b 778 {
Wayne Roberts 1:0817a150122b 779 uint32_t val = radio.readReg(REG_ADDR_LORA_PREAMBLE_SYMBNB, 2);
Wayne Roberts 1:0817a150122b 780 ppLORA.lora.PreambleLengthHi = val >> 8;
Wayne Roberts 1:0817a150122b 781 ppLORA.lora.PreambleLengthLo = val;
Wayne Roberts 1:0817a150122b 782 pc.printf("%u", val);
Wayne Roberts 1:0817a150122b 783 }
Wayne Roberts 1:0817a150122b 784
Wayne Roberts 1:0817a150122b 785 bool Radio::lora_pblLen_write(const char* txt)
Wayne Roberts 1:0817a150122b 786 {
Wayne Roberts 1:0817a150122b 787 unsigned n;
Wayne Roberts 1:0817a150122b 788 if (sscanf(txt, "%u", &n) == 1) {
Wayne Roberts 1:0817a150122b 789 ppLORA.lora.PreambleLengthHi = n >> 8;
Wayne Roberts 1:0817a150122b 790 ppLORA.lora.PreambleLengthLo = n;
Wayne Roberts 1:0817a150122b 791 radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 792 }
Wayne Roberts 1:0817a150122b 793 return false;
Wayne Roberts 1:0817a150122b 794 }
Wayne Roberts 1:0817a150122b 795
Wayne Roberts 1:0817a150122b 796 const value_item_t Radio::lora_pblLen_item = { _ITEM_VALUE, 5, lora_pblLen_print, lora_pblLen_write};
Wayne Roberts 1:0817a150122b 797
Wayne Roberts 1:0817a150122b 798 bool Radio::lora_headerType_read()
Wayne Roberts 1:0817a150122b 799 {
Wayne Roberts 1:0817a150122b 800 loraConfig1_t conf1;
Wayne Roberts 1:0817a150122b 801 conf1.octet = radio.readReg(REG_ADDR_LORA_CONFIG1, 1);
Wayne Roberts 1:0817a150122b 802 ppLORA.lora.HeaderType = conf1.bits.implicit_header;
Wayne Roberts 1:0817a150122b 803 return conf1.bits.implicit_header;
Wayne Roberts 1:0817a150122b 804 }
Wayne Roberts 1:0817a150122b 805
Wayne Roberts 1:0817a150122b 806 bool Radio::lora_headerType_push()
Wayne Roberts 1:0817a150122b 807 {
Wayne Roberts 1:0817a150122b 808 if (ppLORA.lora.HeaderType)
Wayne Roberts 1:0817a150122b 809 ppLORA.lora.HeaderType = 0;
Wayne Roberts 1:0817a150122b 810 else
Wayne Roberts 1:0817a150122b 811 ppLORA.lora.HeaderType = 1;
Wayne Roberts 1:0817a150122b 812
Wayne Roberts 1:0817a150122b 813 radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 814 return ppLORA.lora.HeaderType;
Wayne Roberts 1:0817a150122b 815 }
Wayne Roberts 1:0817a150122b 816
Wayne Roberts 1:0817a150122b 817 const toggle_item_t Radio::lora_headerType_item = { _ITEM_TOGGLE, "EXPLICIT", "IMPLICIT", lora_headerType_read, lora_headerType_push};
Wayne Roberts 1:0817a150122b 818
Wayne Roberts 1:0817a150122b 819 bool Radio::lora_crcon_read()
Wayne Roberts 1:0817a150122b 820 {
Wayne Roberts 1:0817a150122b 821 loraConfig2_t conf2;
Wayne Roberts 1:0817a150122b 822 conf2.octet = radio.readReg(REG_ADDR_LORA_CONFIG2, 1);
Wayne Roberts 1:0817a150122b 823 ppLORA.lora.CRCType = conf2.bits.tx_payload_crc16_en;
Wayne Roberts 1:0817a150122b 824 return conf2.bits.tx_payload_crc16_en;
Wayne Roberts 1:0817a150122b 825 }
Wayne Roberts 1:0817a150122b 826
Wayne Roberts 1:0817a150122b 827 bool Radio::lora_crcon_push()
Wayne Roberts 1:0817a150122b 828 {
Wayne Roberts 1:0817a150122b 829 if (ppLORA.lora.CRCType)
Wayne Roberts 1:0817a150122b 830 ppLORA.lora.CRCType = 0;
Wayne Roberts 1:0817a150122b 831 else
Wayne Roberts 1:0817a150122b 832 ppLORA.lora.CRCType = 1;
Wayne Roberts 1:0817a150122b 833
Wayne Roberts 1:0817a150122b 834 radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 835 return ppLORA.lora.CRCType;
Wayne Roberts 1:0817a150122b 836 }
Wayne Roberts 1:0817a150122b 837
Wayne Roberts 1:0817a150122b 838 const toggle_item_t Radio::lora_crcon_item = { _ITEM_TOGGLE, "CrcOn", NULL, lora_crcon_read, lora_crcon_push};
Wayne Roberts 1:0817a150122b 839
Wayne Roberts 1:0817a150122b 840 bool Radio::lora_inviq_read()
Wayne Roberts 1:0817a150122b 841 {
Wayne Roberts 1:0817a150122b 842 loraConfig1_t conf1;
Wayne Roberts 1:0817a150122b 843 conf1.octet = radio.readReg(REG_ADDR_LORA_CONFIG1, 1);
Wayne Roberts 1:0817a150122b 844 ppLORA.lora.InvertIQ = conf1.bits.rx_invert_iq;
Wayne Roberts 1:0817a150122b 845 return conf1.bits.rx_invert_iq;
Wayne Roberts 1:0817a150122b 846 }
Wayne Roberts 1:0817a150122b 847
Wayne Roberts 1:0817a150122b 848 bool Radio::lora_inviq_push()
Wayne Roberts 1:0817a150122b 849 {
Wayne Roberts 1:0817a150122b 850 if (ppLORA.lora.InvertIQ)
Wayne Roberts 1:0817a150122b 851 ppLORA.lora.InvertIQ = 0;
Wayne Roberts 1:0817a150122b 852 else
Wayne Roberts 1:0817a150122b 853 ppLORA.lora.InvertIQ = 1;
Wayne Roberts 1:0817a150122b 854
Wayne Roberts 1:0817a150122b 855 radio.xfer(OPCODE_SET_PACKET_PARAMS, 6, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 856 return ppLORA.lora.InvertIQ;
Wayne Roberts 1:0817a150122b 857 }
Wayne Roberts 1:0817a150122b 858
Wayne Roberts 1:0817a150122b 859 const toggle_item_t Radio::lora_inviq_item = { _ITEM_TOGGLE, "InvertIQ", NULL, lora_inviq_read, lora_inviq_push};
Wayne Roberts 1:0817a150122b 860
Wayne Roberts 1:0817a150122b 861 const menu_t Radio::lora_menu[] = {
Wayne Roberts 1:0817a150122b 862 { {FIRST_CHIP_MENU_ROW+1, 1}, NULL, &lora_bw_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 863 { {FIRST_CHIP_MENU_ROW+1, 12}, "sf:", &lora_sf_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 864 { {FIRST_CHIP_MENU_ROW+1, 20}, "cr:", &lora_cr_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 865 { {FIRST_CHIP_MENU_ROW+1, 30}, NULL, &lora_ppmOffset_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 866
Wayne Roberts 1:0817a150122b 867 { {FIRST_CHIP_MENU_ROW+2, 1}, "PreambleLength:", &lora_pblLen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 868 { {FIRST_CHIP_MENU_ROW+2, 22}, NULL, &lora_headerType_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 869 { {FIRST_CHIP_MENU_ROW+2, 32}, NULL, &lora_crcon_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 870 { {FIRST_CHIP_MENU_ROW+2, 39}, NULL, &lora_inviq_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 871 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 872 };
Wayne Roberts 1:0817a150122b 873
Wayne Roberts 1:0817a150122b 874 void Radio::test()
Wayne Roberts 1:0817a150122b 875 {
Wayne Roberts 1:0817a150122b 876 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 877
Wayne Roberts 1:0817a150122b 878 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 879 } else if (pktType == PACKET_TYPE_LORA) {
Wayne Roberts 1:0817a150122b 880 }
Wayne Roberts 1:0817a150122b 881 }
Wayne Roberts 1:0817a150122b 882
Wayne Roberts 1:0817a150122b 883 void Radio::gfsk_bitrate_print()
Wayne Roberts 1:0817a150122b 884 {
Wayne Roberts 1:0817a150122b 885 unsigned d = radio.readReg(REG_ADDR_BITRATE, 3);
Wayne Roberts 1:0817a150122b 886 float f = d / 32.0;
Wayne Roberts 1:0817a150122b 887
Wayne Roberts 1:0817a150122b 888 pc.printf("%u", (unsigned)(XTAL_FREQ_HZ / f));
Wayne Roberts 1:0817a150122b 889
Wayne Roberts 1:0817a150122b 890 mpFSK.gfsk.bitrateHi = d >> 16;
Wayne Roberts 1:0817a150122b 891 mpFSK.gfsk.bitrateMid = d >> 8;
Wayne Roberts 1:0817a150122b 892 mpFSK.gfsk.bitrateLo = d;
Wayne Roberts 1:0817a150122b 893 }
Wayne Roberts 1:0817a150122b 894
Wayne Roberts 1:0817a150122b 895 bool Radio::gfsk_bitrate_write(const char* txt)
Wayne Roberts 1:0817a150122b 896 {
Wayne Roberts 1:0817a150122b 897 unsigned bps, br;
Wayne Roberts 1:0817a150122b 898
Wayne Roberts 1:0817a150122b 899 if (sscanf(txt, "%u", &bps) == 1) {
Wayne Roberts 1:0817a150122b 900 br = 32 * (XTAL_FREQ_HZ / (float)bps);
Wayne Roberts 1:0817a150122b 901 mpFSK.gfsk.bitrateHi = br >> 16;
Wayne Roberts 1:0817a150122b 902 mpFSK.gfsk.bitrateMid = br >> 8;
Wayne Roberts 1:0817a150122b 903 mpFSK.gfsk.bitrateLo = br;
Wayne Roberts 1:0817a150122b 904 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 8, 0, mpFSK.buf);
Wayne Roberts 1:0817a150122b 905 }
Wayne Roberts 1:0817a150122b 906 return false;
Wayne Roberts 1:0817a150122b 907 }
Wayne Roberts 1:0817a150122b 908
Wayne Roberts 1:0817a150122b 909 const value_item_t Radio::gfsk_bitrate_item = { _ITEM_VALUE, 8, gfsk_bitrate_print, gfsk_bitrate_write};
Wayne Roberts 1:0817a150122b 910
Wayne Roberts 1:0817a150122b 911 static const char* gfsk_bts[] = {
Wayne Roberts 1:0817a150122b 912 "off", // 0
Wayne Roberts 1:0817a150122b 913 "0.3", // 1
Wayne Roberts 1:0817a150122b 914 "0.5", // 2
Wayne Roberts 1:0817a150122b 915 "0.7", // 3
Wayne Roberts 1:0817a150122b 916 "1.0", // 4
Wayne Roberts 1:0817a150122b 917 NULL
Wayne Roberts 1:0817a150122b 918 };
Wayne Roberts 1:0817a150122b 919
Wayne Roberts 1:0817a150122b 920 unsigned Radio::gfsk_bt_read(bool forWriting)
Wayne Roberts 1:0817a150122b 921 {
Wayne Roberts 1:0817a150122b 922 shapeCfg_t shapeCfg;
Wayne Roberts 1:0817a150122b 923 shapeCfg.octet = radio.readReg(REG_ADDR_SHAPECFG, 1);
Wayne Roberts 1:0817a150122b 924 mpFSK.gfsk.PulseShape = shapeCfg.octet;
Wayne Roberts 1:0817a150122b 925 if (shapeCfg.bits.pulse_shape)
Wayne Roberts 1:0817a150122b 926 return shapeCfg.bits.bt + 1;
Wayne Roberts 1:0817a150122b 927 else
Wayne Roberts 1:0817a150122b 928 return 0;
Wayne Roberts 1:0817a150122b 929 }
Wayne Roberts 1:0817a150122b 930
Wayne Roberts 1:0817a150122b 931 menuMode_e Radio::gfsk_bt_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 932 {
Wayne Roberts 1:0817a150122b 933 switch (sidx) {
Wayne Roberts 1:0817a150122b 934 case 0: mpFSK.gfsk.PulseShape = GFSK_SHAPE_NONE; break;
Wayne Roberts 1:0817a150122b 935 case 1: mpFSK.gfsk.PulseShape = GFSK_SHAPE_BT0_3; break;
Wayne Roberts 1:0817a150122b 936 case 2: mpFSK.gfsk.PulseShape = GFSK_SHAPE_BT0_5; break;
Wayne Roberts 1:0817a150122b 937 case 3: mpFSK.gfsk.PulseShape = GFSK_SHAPE_BT0_7; break;
Wayne Roberts 1:0817a150122b 938 case 4: mpFSK.gfsk.PulseShape = GFSK_SHAPE_BT1_0; break;
Wayne Roberts 1:0817a150122b 939 }
Wayne Roberts 1:0817a150122b 940 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 8, 0, mpFSK.buf);
Wayne Roberts 1:0817a150122b 941 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 942 }
Wayne Roberts 1:0817a150122b 943
Wayne Roberts 1:0817a150122b 944 const dropdown_item_t Radio::gfsk_bt_item = { _ITEM_DROPDOWN, gfsk_bts, gfsk_bts, gfsk_bt_read, gfsk_bt_write};
Wayne Roberts 1:0817a150122b 945
Wayne Roberts 1:0817a150122b 946 static const uint8_t rx_bws[] = {
Wayne Roberts 1:0817a150122b 947 GFSK_RX_BW_4800, GFSK_RX_BW_5800, GFSK_RX_BW_7300, GFSK_RX_BW_9700,
Wayne Roberts 1:0817a150122b 948 GFSK_RX_BW_11700, GFSK_RX_BW_14600, GFSK_RX_BW_19500, GFSK_RX_BW_23400,
Wayne Roberts 1:0817a150122b 949 GFSK_RX_BW_29300, GFSK_RX_BW_39000, GFSK_RX_BW_46900, GFSK_RX_BW_58600,
Wayne Roberts 1:0817a150122b 950 GFSK_RX_BW_78200, GFSK_RX_BW_93800, GFSK_RX_BW_117300, GFSK_RX_BW_156200,
Wayne Roberts 1:0817a150122b 951 GFSK_RX_BW_187200, GFSK_RX_BW_234300, GFSK_RX_BW_312000, GFSK_RX_BW_373600,
Wayne Roberts 1:0817a150122b 952 GFSK_RX_BW_467000
Wayne Roberts 1:0817a150122b 953 };
Wayne Roberts 1:0817a150122b 954
Wayne Roberts 1:0817a150122b 955 static const char* rxbw_str[] = {
Wayne Roberts 1:0817a150122b 956 " 4.8KHz", " 5.8KHz", " 7.3KHz", " 9.7KHz",
Wayne Roberts 1:0817a150122b 957 " 11.7KHz", " 14.6KHz", " 19.5KHz", " 23.4KHz",
Wayne Roberts 1:0817a150122b 958 " 29.3KHz", " 39.0KHz", " 46.9KHz", " 58.6KHz",
Wayne Roberts 1:0817a150122b 959 " 78.2KHz", " 93.8KHz", "117.3KHz", "156.2KHz",
Wayne Roberts 1:0817a150122b 960 "187.2KHz", "234.3KHz", "312.0KHz", "373.6KHz",
Wayne Roberts 1:0817a150122b 961 "467.0KHz",
Wayne Roberts 1:0817a150122b 962 NULL
Wayne Roberts 1:0817a150122b 963 };
Wayne Roberts 1:0817a150122b 964
Wayne Roberts 1:0817a150122b 965 unsigned Radio::gfsk_rxbw_read(bool forWriting)
Wayne Roberts 1:0817a150122b 966 {
Wayne Roberts 1:0817a150122b 967 unsigned n;
Wayne Roberts 1:0817a150122b 968 bwSel_t bwSel;
Wayne Roberts 1:0817a150122b 969 bwSel.octet = radio.readReg(REG_ADDR_BWSEL, 1);
Wayne Roberts 1:0817a150122b 970 mpFSK.gfsk.bandwidth = bwSel.octet;
Wayne Roberts 1:0817a150122b 971
Wayne Roberts 1:0817a150122b 972 for (n = 0; n < sizeof(rx_bws); n++) {
Wayne Roberts 1:0817a150122b 973 if (bwSel.octet == rx_bws[n])
Wayne Roberts 1:0817a150122b 974 return n;
Wayne Roberts 1:0817a150122b 975 }
Wayne Roberts 1:0817a150122b 976 return sizeof(rx_bws);
Wayne Roberts 1:0817a150122b 977 }
Wayne Roberts 1:0817a150122b 978
Wayne Roberts 1:0817a150122b 979 menuMode_e Radio::gfsk_rxbw_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 980 {
Wayne Roberts 1:0817a150122b 981 mpFSK.gfsk.bandwidth = rx_bws[sidx];
Wayne Roberts 1:0817a150122b 982 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 8, 0, mpFSK.buf);
Wayne Roberts 1:0817a150122b 983 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 984 }
Wayne Roberts 1:0817a150122b 985
Wayne Roberts 1:0817a150122b 986 const dropdown_item_t Radio::gfsk_rxbw_item = { _ITEM_DROPDOWN, rxbw_str, rxbw_str, gfsk_rxbw_read, gfsk_rxbw_write};
Wayne Roberts 1:0817a150122b 987
Wayne Roberts 1:0817a150122b 988 void Radio::gfsk_fdev_print()
Wayne Roberts 1:0817a150122b 989 {
Wayne Roberts 1:0817a150122b 990 unsigned d = radio.readReg(REG_ADDR_FREQDEV, 3);
Wayne Roberts 1:0817a150122b 991 pc.printf("%u", (unsigned)(d * FREQ_STEP));
Wayne Roberts 1:0817a150122b 992 }
Wayne Roberts 1:0817a150122b 993
Wayne Roberts 1:0817a150122b 994 bool Radio::gfsk_fdev_write(const char* txt)
Wayne Roberts 1:0817a150122b 995 {
Wayne Roberts 1:0817a150122b 996 unsigned hz, fdev;
Wayne Roberts 1:0817a150122b 997 if (sscanf(txt, "%u", &hz) == 1) {
Wayne Roberts 1:0817a150122b 998 fdev = hz / FREQ_STEP;
Wayne Roberts 1:0817a150122b 999 mpFSK.gfsk.fdevHi = fdev >> 16;
Wayne Roberts 1:0817a150122b 1000 mpFSK.gfsk.fdevMid = fdev >> 8;
Wayne Roberts 1:0817a150122b 1001 mpFSK.gfsk.fdevLo = fdev;
Wayne Roberts 1:0817a150122b 1002 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 8, 0, mpFSK.buf);
Wayne Roberts 1:0817a150122b 1003 }
Wayne Roberts 1:0817a150122b 1004 return false;
Wayne Roberts 1:0817a150122b 1005 }
Wayne Roberts 1:0817a150122b 1006
Wayne Roberts 1:0817a150122b 1007 const value_item_t Radio::gfsk_fdev_item = { _ITEM_VALUE, 8, gfsk_fdev_print, gfsk_fdev_write};
Wayne Roberts 1:0817a150122b 1008
Wayne Roberts 1:0817a150122b 1009 void Radio::gfsk_pblLen_print()
Wayne Roberts 1:0817a150122b 1010 {
Wayne Roberts 1:0817a150122b 1011 unsigned n = radio.readReg(REG_ADDR_FSK_PREAMBLE_TXLEN , 2);
Wayne Roberts 1:0817a150122b 1012 ppFSK.gfsk.PreambleLengthHi = n << 8; // param1
Wayne Roberts 1:0817a150122b 1013 ppFSK.gfsk.PreambleLengthLo = n;// param2
Wayne Roberts 1:0817a150122b 1014 pc.printf("%u", n);
Wayne Roberts 1:0817a150122b 1015 }
Wayne Roberts 1:0817a150122b 1016
Wayne Roberts 1:0817a150122b 1017 bool Radio::gfsk_pblLen_write(const char* txt)
Wayne Roberts 1:0817a150122b 1018 {
Wayne Roberts 1:0817a150122b 1019 unsigned n;
Wayne Roberts 1:0817a150122b 1020 if (sscanf(txt, "%u", &n) == 1) {
Wayne Roberts 1:0817a150122b 1021 ppFSK.gfsk.PreambleLengthHi = n << 8; // param1
Wayne Roberts 1:0817a150122b 1022 ppFSK.gfsk.PreambleLengthLo = n;// param2
Wayne Roberts 1:0817a150122b 1023 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 1024 }
Wayne Roberts 1:0817a150122b 1025 return false;
Wayne Roberts 1:0817a150122b 1026 }
Wayne Roberts 1:0817a150122b 1027
Wayne Roberts 1:0817a150122b 1028 const value_item_t Radio::gfsk_pblLen_item = { _ITEM_VALUE, 5, gfsk_pblLen_print, gfsk_pblLen_write};
Wayne Roberts 1:0817a150122b 1029
Wayne Roberts 1:0817a150122b 1030 static const char* fsk_detlens[] = {
Wayne Roberts 1:0817a150122b 1031 " off ",
Wayne Roberts 1:0817a150122b 1032 " 8bits",
Wayne Roberts 1:0817a150122b 1033 "16bits",
Wayne Roberts 1:0817a150122b 1034 "24bits",
Wayne Roberts 1:0817a150122b 1035 "32bits",
Wayne Roberts 1:0817a150122b 1036 NULL
Wayne Roberts 1:0817a150122b 1037 };
Wayne Roberts 1:0817a150122b 1038
Wayne Roberts 1:0817a150122b 1039 unsigned Radio::gfsk_pblDetLen_read(bool forWriting)
Wayne Roberts 1:0817a150122b 1040 {
Wayne Roberts 1:0817a150122b 1041 pktCtrl1_t pktCtrl1;
Wayne Roberts 1:0817a150122b 1042 pktCtrl1.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 1043 ppFSK.gfsk.PreambleDetectorLength = pktCtrl1.octet & 0x07; // param3
Wayne Roberts 1:0817a150122b 1044 if (pktCtrl1.bits.preamble_det_on)
Wayne Roberts 1:0817a150122b 1045 return pktCtrl1.bits.preamble_len_rx + 1;
Wayne Roberts 1:0817a150122b 1046 else
Wayne Roberts 1:0817a150122b 1047 return 0;
Wayne Roberts 1:0817a150122b 1048 }
Wayne Roberts 1:0817a150122b 1049
Wayne Roberts 1:0817a150122b 1050 menuMode_e Radio::gfsk_pblDetLen_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1051 {
Wayne Roberts 1:0817a150122b 1052 if (sidx == 0)
Wayne Roberts 1:0817a150122b 1053 ppFSK.gfsk.PreambleDetectorLength = 0;
Wayne Roberts 1:0817a150122b 1054 else
Wayne Roberts 1:0817a150122b 1055 ppFSK.gfsk.PreambleDetectorLength = sidx + 3;
Wayne Roberts 1:0817a150122b 1056
Wayne Roberts 1:0817a150122b 1057 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 1058 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1059 }
Wayne Roberts 1:0817a150122b 1060
Wayne Roberts 1:0817a150122b 1061 const dropdown_item_t Radio::gfsk_pblDetLen_item = { _ITEM_DROPDOWN, fsk_detlens, fsk_detlens, gfsk_pblDetLen_read, gfsk_pblDetLen_write};
Wayne Roberts 1:0817a150122b 1062
Wayne Roberts 1:0817a150122b 1063 void Radio::gfsk_swl_print()
Wayne Roberts 1:0817a150122b 1064 {
Wayne Roberts 1:0817a150122b 1065 ppFSK.gfsk.SyncWordLength = radio.readReg(REG_ADDR_FSK_SYNC_LEN, 1);// param4
Wayne Roberts 1:0817a150122b 1066 pc.printf("%u", ppFSK.gfsk.SyncWordLength);
Wayne Roberts 1:0817a150122b 1067 }
Wayne Roberts 1:0817a150122b 1068
Wayne Roberts 1:0817a150122b 1069 bool Radio::gfsk_swl_write(const char* txt)
Wayne Roberts 1:0817a150122b 1070 {
Wayne Roberts 1:0817a150122b 1071 unsigned n;
Wayne Roberts 1:0817a150122b 1072 unsigned r;
Wayne Roberts 1:0817a150122b 1073 r = sscanf(txt, "%u", &n);
Wayne Roberts 1:0817a150122b 1074 if (r == 1) {
Wayne Roberts 1:0817a150122b 1075 ppFSK.gfsk.SyncWordLength = n;
Wayne Roberts 1:0817a150122b 1076 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 1077 }
Wayne Roberts 1:0817a150122b 1078 return false;
Wayne Roberts 1:0817a150122b 1079 }
Wayne Roberts 1:0817a150122b 1080
Wayne Roberts 1:0817a150122b 1081 const value_item_t Radio::gfsk_swl_item = { _ITEM_VALUE, 3, gfsk_swl_print, gfsk_swl_write};
Wayne Roberts 1:0817a150122b 1082
Wayne Roberts 1:0817a150122b 1083 void Radio::gfsk_syncword_print()
Wayne Roberts 1:0817a150122b 1084 {
Wayne Roberts 1:0817a150122b 1085 unsigned addr = REG_ADDR_SYNCADDR;
Wayne Roberts 1:0817a150122b 1086 uint8_t swl_bits = radio.readReg(REG_ADDR_FSK_SYNC_LEN, 1);
Wayne Roberts 1:0817a150122b 1087 if (swl_bits & 7) {
Wayne Roberts 1:0817a150122b 1088 swl_bits |= 7;
Wayne Roberts 1:0817a150122b 1089 swl_bits++;
Wayne Roberts 1:0817a150122b 1090 }
Wayne Roberts 1:0817a150122b 1091 while (swl_bits > 0) {
Wayne Roberts 1:0817a150122b 1092 pc.printf("%02x", radio.readReg(addr++, 1));
Wayne Roberts 1:0817a150122b 1093 swl_bits -= 8;
Wayne Roberts 1:0817a150122b 1094 }
Wayne Roberts 1:0817a150122b 1095 }
Wayne Roberts 1:0817a150122b 1096
Wayne Roberts 1:0817a150122b 1097 bool Radio::gfsk_syncword_write(const char* txt)
Wayne Roberts 1:0817a150122b 1098 {
Wayne Roberts 1:0817a150122b 1099 const char* ptr = txt;
Wayne Roberts 1:0817a150122b 1100 unsigned addr = REG_ADDR_SYNCADDR;
Wayne Roberts 1:0817a150122b 1101 int8_t swl_bits = radio.readReg(REG_ADDR_FSK_SYNC_LEN, 1);
Wayne Roberts 1:0817a150122b 1102 if (swl_bits & 7) {
Wayne Roberts 1:0817a150122b 1103 swl_bits |= 7;
Wayne Roberts 1:0817a150122b 1104 swl_bits++;
Wayne Roberts 1:0817a150122b 1105 }
Wayne Roberts 1:0817a150122b 1106 while (swl_bits > 0) {
Wayne Roberts 1:0817a150122b 1107 char buf[3];
Wayne Roberts 1:0817a150122b 1108 unsigned n;
Wayne Roberts 1:0817a150122b 1109 buf[0] = ptr[0];
Wayne Roberts 1:0817a150122b 1110 buf[1] = ptr[1];
Wayne Roberts 1:0817a150122b 1111 buf[2] = 0;
Wayne Roberts 1:0817a150122b 1112 sscanf(buf, "%x", &n);
Wayne Roberts 1:0817a150122b 1113 radio.writeReg(addr++, n, 1);
Wayne Roberts 1:0817a150122b 1114 ptr += 2;
Wayne Roberts 1:0817a150122b 1115 swl_bits -= 8;
Wayne Roberts 1:0817a150122b 1116 }
Wayne Roberts 1:0817a150122b 1117 return false;
Wayne Roberts 1:0817a150122b 1118 }
Wayne Roberts 1:0817a150122b 1119
Wayne Roberts 1:0817a150122b 1120 const value_item_t Radio::gfsk_syncword_item = { _ITEM_VALUE, 17, gfsk_syncword_print, gfsk_syncword_write};
Wayne Roberts 1:0817a150122b 1121
Wayne Roberts 1:0817a150122b 1122 bool Radio::gfsk_fixLen_read()
Wayne Roberts 1:0817a150122b 1123 {
Wayne Roberts 1:0817a150122b 1124 pktCtrl0_t pktCtrl0;
Wayne Roberts 1:0817a150122b 1125 pktCtrl0.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL0, 1);
Wayne Roberts 1:0817a150122b 1126 ppFSK.gfsk.PacketType = pktCtrl0.bits.pkt_len_format; // param6
Wayne Roberts 1:0817a150122b 1127 return pktCtrl0.bits.pkt_len_format;
Wayne Roberts 1:0817a150122b 1128 }
Wayne Roberts 1:0817a150122b 1129
Wayne Roberts 1:0817a150122b 1130 bool Radio::gfsk_fixLen_push()
Wayne Roberts 1:0817a150122b 1131 {
Wayne Roberts 1:0817a150122b 1132 if (ppFSK.gfsk.PacketType)
Wayne Roberts 1:0817a150122b 1133 ppFSK.gfsk.PacketType = 0;
Wayne Roberts 1:0817a150122b 1134 else
Wayne Roberts 1:0817a150122b 1135 ppFSK.gfsk.PacketType = 1;
Wayne Roberts 1:0817a150122b 1136
Wayne Roberts 1:0817a150122b 1137 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 1138 return ppFSK.gfsk.PacketType;
Wayne Roberts 1:0817a150122b 1139 }
Wayne Roberts 1:0817a150122b 1140
Wayne Roberts 1:0817a150122b 1141 const toggle_item_t Radio::gfsk_fixLen_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1142 "fixed ",
Wayne Roberts 1:0817a150122b 1143 "variable",
Wayne Roberts 1:0817a150122b 1144 gfsk_fixLen_read, gfsk_fixLen_push
Wayne Roberts 1:0817a150122b 1145 };
Wayne Roberts 1:0817a150122b 1146
Wayne Roberts 1:0817a150122b 1147
Wayne Roberts 1:0817a150122b 1148 static const char* addrcomps[] = {
Wayne Roberts 1:0817a150122b 1149 " off ",
Wayne Roberts 1:0817a150122b 1150 "NodeAddress ",
Wayne Roberts 1:0817a150122b 1151 "NodeAddress+broadcast",
Wayne Roberts 1:0817a150122b 1152 NULL
Wayne Roberts 1:0817a150122b 1153 };
Wayne Roberts 1:0817a150122b 1154
Wayne Roberts 1:0817a150122b 1155 unsigned Radio::gfsk_addrcomp_read(bool forWriting)
Wayne Roberts 1:0817a150122b 1156 {
Wayne Roberts 1:0817a150122b 1157 ppFSK.gfsk.AddrComp = radio.readReg(REG_ADDR_NODEADDRCOMP, 1);// param5
Wayne Roberts 1:0817a150122b 1158 return ppFSK.gfsk.AddrComp;
Wayne Roberts 1:0817a150122b 1159 }
Wayne Roberts 1:0817a150122b 1160
Wayne Roberts 1:0817a150122b 1161 menuMode_e Radio::gfsk_addrcomp_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1162 {
Wayne Roberts 1:0817a150122b 1163 ppFSK.gfsk.AddrComp = sidx;
Wayne Roberts 1:0817a150122b 1164 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 1165 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1166 }
Wayne Roberts 1:0817a150122b 1167
Wayne Roberts 1:0817a150122b 1168 const dropdown_item_t Radio::gfsk_addrcomp_item = { _ITEM_DROPDOWN, addrcomps, addrcomps, gfsk_addrcomp_read, gfsk_addrcomp_write};
Wayne Roberts 1:0817a150122b 1169
Wayne Roberts 1:0817a150122b 1170 void Radio::gfsk_nodeadrs_print()
Wayne Roberts 1:0817a150122b 1171 {
Wayne Roberts 1:0817a150122b 1172 pc.printf("%02x", radio.readReg(REG_ADDR_NODEADDR, 1));
Wayne Roberts 1:0817a150122b 1173 }
Wayne Roberts 1:0817a150122b 1174
Wayne Roberts 1:0817a150122b 1175 bool Radio::gfsk_nodeadrs_write(const char* txt)
Wayne Roberts 1:0817a150122b 1176 {
Wayne Roberts 1:0817a150122b 1177 unsigned v;
Wayne Roberts 1:0817a150122b 1178 if (sscanf(txt, "%x", &v) == 1)
Wayne Roberts 1:0817a150122b 1179 radio.writeReg(REG_ADDR_NODEADDR, v, 1);
Wayne Roberts 1:0817a150122b 1180
Wayne Roberts 1:0817a150122b 1181 return false;
Wayne Roberts 1:0817a150122b 1182 }
Wayne Roberts 1:0817a150122b 1183
Wayne Roberts 1:0817a150122b 1184 const value_item_t Radio::gfsk_nodeadrs_item = { _ITEM_VALUE, 3, gfsk_nodeadrs_print, gfsk_nodeadrs_write};
Wayne Roberts 1:0817a150122b 1185
Wayne Roberts 1:0817a150122b 1186 void Radio::gfsk_broadcast_print()
Wayne Roberts 1:0817a150122b 1187 {
Wayne Roberts 1:0817a150122b 1188 pc.printf("%02x", radio.readReg(REG_ADDR_BROADCAST, 1));
Wayne Roberts 1:0817a150122b 1189 }
Wayne Roberts 1:0817a150122b 1190
Wayne Roberts 1:0817a150122b 1191 bool Radio::gfsk_broadcast_write(const char* txt)
Wayne Roberts 1:0817a150122b 1192 {
Wayne Roberts 1:0817a150122b 1193 unsigned v;
Wayne Roberts 1:0817a150122b 1194 if (sscanf(txt, "%x", &v) == 1)
Wayne Roberts 1:0817a150122b 1195 radio.writeReg(REG_ADDR_BROADCAST, v, 1);
Wayne Roberts 1:0817a150122b 1196
Wayne Roberts 1:0817a150122b 1197 return false;
Wayne Roberts 1:0817a150122b 1198 }
Wayne Roberts 1:0817a150122b 1199
Wayne Roberts 1:0817a150122b 1200 const value_item_t Radio::gfsk_broadcast_item = { _ITEM_VALUE, 3, gfsk_broadcast_print, gfsk_broadcast_write};
Wayne Roberts 1:0817a150122b 1201
Wayne Roberts 1:0817a150122b 1202 static const char* crctypes[] = {
Wayne Roberts 1:0817a150122b 1203 " off ", // 0
Wayne Roberts 1:0817a150122b 1204 "1 Byte ", // 1
Wayne Roberts 1:0817a150122b 1205 "2 Byte ", // 2
Wayne Roberts 1:0817a150122b 1206 "1 Byte inv", // 3
Wayne Roberts 1:0817a150122b 1207 "2 Byte inv", // 4
Wayne Roberts 1:0817a150122b 1208 NULL
Wayne Roberts 1:0817a150122b 1209 };
Wayne Roberts 1:0817a150122b 1210
Wayne Roberts 1:0817a150122b 1211 unsigned Radio::gfsk_crctype_read(bool forWriting)
Wayne Roberts 1:0817a150122b 1212 {
Wayne Roberts 1:0817a150122b 1213 pktCtrl2_t pktCtrl2;
Wayne Roberts 1:0817a150122b 1214 pktCtrl2.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL2, 1);
Wayne Roberts 1:0817a150122b 1215 ppFSK.gfsk.CRCType = pktCtrl2.octet & 0x7; // param8
Wayne Roberts 1:0817a150122b 1216 switch (ppFSK.gfsk.CRCType) {
Wayne Roberts 1:0817a150122b 1217 case GFSK_CRC_OFF: return 0;
Wayne Roberts 1:0817a150122b 1218 case GFSK_CRC_1_BYTE: return 1;
Wayne Roberts 1:0817a150122b 1219 case GFSK_CRC_2_BYTE: return 2;
Wayne Roberts 1:0817a150122b 1220 case GFSK_CRC_1_BYTE_INV: return 3;
Wayne Roberts 1:0817a150122b 1221 case GFSK_CRC_2_BYTE_INV: return 4;
Wayne Roberts 1:0817a150122b 1222 default: return 5;
Wayne Roberts 1:0817a150122b 1223 }
Wayne Roberts 1:0817a150122b 1224 }
Wayne Roberts 1:0817a150122b 1225
Wayne Roberts 1:0817a150122b 1226 menuMode_e Radio::gfsk_crctype_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1227 {
Wayne Roberts 1:0817a150122b 1228 switch (sidx) {
Wayne Roberts 1:0817a150122b 1229 case 0: ppFSK.gfsk.CRCType = GFSK_CRC_OFF; break;
Wayne Roberts 1:0817a150122b 1230 case 1: ppFSK.gfsk.CRCType = GFSK_CRC_1_BYTE; break;
Wayne Roberts 1:0817a150122b 1231 case 2: ppFSK.gfsk.CRCType = GFSK_CRC_2_BYTE; break;
Wayne Roberts 1:0817a150122b 1232 case 3: ppFSK.gfsk.CRCType = GFSK_CRC_1_BYTE_INV; break;
Wayne Roberts 1:0817a150122b 1233 case 4: ppFSK.gfsk.CRCType = GFSK_CRC_2_BYTE_INV; break;
Wayne Roberts 1:0817a150122b 1234 }
Wayne Roberts 1:0817a150122b 1235
Wayne Roberts 1:0817a150122b 1236 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 1237 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1238 }
Wayne Roberts 1:0817a150122b 1239
Wayne Roberts 1:0817a150122b 1240 const dropdown_item_t Radio::gfsk_crctype_item = { _ITEM_DROPDOWN, crctypes, crctypes, gfsk_crctype_read, gfsk_crctype_write};
Wayne Roberts 1:0817a150122b 1241
Wayne Roberts 1:0817a150122b 1242 bool Radio::gfsk_white_read()
Wayne Roberts 1:0817a150122b 1243 {
Wayne Roberts 1:0817a150122b 1244 pktCtrl2_t pktCtrl2;
Wayne Roberts 1:0817a150122b 1245 pktCtrl2.octet = radio.readReg(REG_ADDR_FSK_PKTCTRL2, 1);
Wayne Roberts 1:0817a150122b 1246 ppFSK.gfsk.Whitening = pktCtrl2.bits.whit_enable; // param9
Wayne Roberts 1:0817a150122b 1247 return pktCtrl2.bits.whit_enable;
Wayne Roberts 1:0817a150122b 1248 }
Wayne Roberts 1:0817a150122b 1249
Wayne Roberts 1:0817a150122b 1250 bool Radio::gfsk_white_push()
Wayne Roberts 1:0817a150122b 1251 {
Wayne Roberts 1:0817a150122b 1252 if (ppFSK.gfsk.Whitening)
Wayne Roberts 1:0817a150122b 1253 ppFSK.gfsk.Whitening = 0;
Wayne Roberts 1:0817a150122b 1254 else
Wayne Roberts 1:0817a150122b 1255 ppFSK.gfsk.Whitening = 1;
Wayne Roberts 1:0817a150122b 1256
Wayne Roberts 1:0817a150122b 1257 radio.xfer(OPCODE_SET_PACKET_PARAMS, 9, 0, ppFSK.buf);
Wayne Roberts 1:0817a150122b 1258 return ppFSK.gfsk.Whitening;
Wayne Roberts 1:0817a150122b 1259 }
Wayne Roberts 1:0817a150122b 1260
Wayne Roberts 1:0817a150122b 1261 const toggle_item_t Radio::gfsk_white_item = { _ITEM_TOGGLE, "Whitening", NULL, gfsk_white_read, gfsk_white_push};
Wayne Roberts 1:0817a150122b 1262
Wayne Roberts 1:0817a150122b 1263 void Radio::gfsk_crcinit_print()
Wayne Roberts 1:0817a150122b 1264 {
Wayne Roberts 1:0817a150122b 1265 pc.printf("%04x", radio.readReg(REG_ADDR_FSK_CRCINIT, 2));
Wayne Roberts 1:0817a150122b 1266 }
Wayne Roberts 1:0817a150122b 1267
Wayne Roberts 1:0817a150122b 1268 bool Radio::gfsk_crcinit_write(const char* txt)
Wayne Roberts 1:0817a150122b 1269 {
Wayne Roberts 1:0817a150122b 1270 unsigned v;
Wayne Roberts 1:0817a150122b 1271 if (sscanf(txt, "%x", &v) == 1)
Wayne Roberts 1:0817a150122b 1272 radio.writeReg(REG_ADDR_FSK_CRCINIT, v, 2);
Wayne Roberts 1:0817a150122b 1273
Wayne Roberts 1:0817a150122b 1274 return false;
Wayne Roberts 1:0817a150122b 1275 }
Wayne Roberts 1:0817a150122b 1276
Wayne Roberts 1:0817a150122b 1277 const value_item_t Radio::gfsk_crcinit_item = { _ITEM_VALUE, 5, gfsk_crcinit_print, gfsk_crcinit_write};
Wayne Roberts 1:0817a150122b 1278
Wayne Roberts 1:0817a150122b 1279 void Radio::gfsk_crcpoly_print()
Wayne Roberts 1:0817a150122b 1280 {
Wayne Roberts 1:0817a150122b 1281 pc.printf("%04x", radio.readReg(REG_ADDR_FSK_CRCPOLY, 2));
Wayne Roberts 1:0817a150122b 1282 }
Wayne Roberts 1:0817a150122b 1283
Wayne Roberts 1:0817a150122b 1284 bool Radio::gfsk_crcpoly_write(const char* txt)
Wayne Roberts 1:0817a150122b 1285 {
Wayne Roberts 1:0817a150122b 1286 unsigned v;
Wayne Roberts 1:0817a150122b 1287 if (sscanf(txt, "%x", &v) == 1)
Wayne Roberts 1:0817a150122b 1288 radio.writeReg(REG_ADDR_FSK_CRCPOLY, v, 2);
Wayne Roberts 1:0817a150122b 1289
Wayne Roberts 1:0817a150122b 1290 return false;
Wayne Roberts 1:0817a150122b 1291 }
Wayne Roberts 1:0817a150122b 1292
Wayne Roberts 1:0817a150122b 1293 const value_item_t Radio::gfsk_crcpoly_item = { _ITEM_VALUE, 5, gfsk_crcpoly_print, gfsk_crcpoly_write};
Wayne Roberts 1:0817a150122b 1294
Wayne Roberts 1:0817a150122b 1295 void Radio::gfsk_whiteInit_print()
Wayne Roberts 1:0817a150122b 1296 {
Wayne Roberts 1:0817a150122b 1297 PktCtrl1a_t PktCtrl1a;
Wayne Roberts 1:0817a150122b 1298 PktCtrl1a.word = radio.readReg(REG_ADDR_FSK_PKTCTRL1A, 2);
Wayne Roberts 1:0817a150122b 1299 pc.printf("%x", PktCtrl1a.bits.whit_init_val);
Wayne Roberts 1:0817a150122b 1300 }
Wayne Roberts 1:0817a150122b 1301
Wayne Roberts 1:0817a150122b 1302 bool Radio::gfsk_whiteInit_write(const char* txt)
Wayne Roberts 1:0817a150122b 1303 {
Wayne Roberts 1:0817a150122b 1304 unsigned n;
Wayne Roberts 1:0817a150122b 1305 PktCtrl1a_t PktCtrl1a;
Wayne Roberts 1:0817a150122b 1306 PktCtrl1a.word = radio.readReg(REG_ADDR_FSK_PKTCTRL1A, 2);
Wayne Roberts 1:0817a150122b 1307 if (sscanf(txt, "%x", &n) == 1) {
Wayne Roberts 1:0817a150122b 1308 PktCtrl1a.bits.whit_init_val = n;
Wayne Roberts 1:0817a150122b 1309 radio.writeReg(REG_ADDR_FSK_PKTCTRL1A, PktCtrl1a.word, 2);
Wayne Roberts 1:0817a150122b 1310 }
Wayne Roberts 1:0817a150122b 1311 return false;
Wayne Roberts 1:0817a150122b 1312 }
Wayne Roberts 1:0817a150122b 1313
Wayne Roberts 1:0817a150122b 1314 const value_item_t Radio::gfsk_whiteInit_item = { _ITEM_VALUE, 5, gfsk_whiteInit_print, gfsk_whiteInit_write};
Wayne Roberts 1:0817a150122b 1315
Wayne Roberts 1:0817a150122b 1316 const menu_t Radio::gfsk_menu[] = {
Wayne Roberts 1:0817a150122b 1317 { {FIRST_CHIP_MENU_ROW+1, 1}, "bps:", &gfsk_bitrate_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1318 { {FIRST_CHIP_MENU_ROW+1, 15}, "bt:", &gfsk_bt_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1319 { {FIRST_CHIP_MENU_ROW+1, 23}, "rxbw:", &gfsk_rxbw_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1320 { {FIRST_CHIP_MENU_ROW+1, 39}, "fdev:", &gfsk_fdev_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1321 { {FIRST_CHIP_MENU_ROW+1, 53}, NULL, &gfsk_fixLen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1322
Wayne Roberts 1:0817a150122b 1323 { {FIRST_CHIP_MENU_ROW+2, 1}, "PreambleLength:", &gfsk_pblLen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1324 { {FIRST_CHIP_MENU_ROW+2, 21}, "PreambleDetectorLength:", &gfsk_pblDetLen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1325 { {FIRST_CHIP_MENU_ROW+2, 51}, "SyncWordLength bits:", &gfsk_swl_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1326
Wayne Roberts 1:0817a150122b 1327 { {FIRST_CHIP_MENU_ROW+3, 1}, "SyncWord:", &gfsk_syncword_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1328
Wayne Roberts 1:0817a150122b 1329 { {FIRST_CHIP_MENU_ROW+4, 1}, "AddrComp:", &gfsk_addrcomp_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1330 { {FIRST_CHIP_MENU_ROW+4, 33}, "NodeAdrs:", &gfsk_nodeadrs_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1331 { {FIRST_CHIP_MENU_ROW+4, 47}, "broadcast:", &gfsk_broadcast_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1332
Wayne Roberts 1:0817a150122b 1333 { {FIRST_CHIP_MENU_ROW+5, 1}, "crcType:", &gfsk_crctype_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1334 { {FIRST_CHIP_MENU_ROW+5, 21}, "crcInit:", &gfsk_crcinit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1335 { {FIRST_CHIP_MENU_ROW+5, 34}, "crcPoly:", &gfsk_crcpoly_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1336
Wayne Roberts 1:0817a150122b 1337 { {FIRST_CHIP_MENU_ROW+6, 1}, NULL, &gfsk_white_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1338 { {FIRST_CHIP_MENU_ROW+6, 12}, "lfsr init:", &gfsk_whiteInit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1339 //12345678901234567890123456789012
Wayne Roberts 1:0817a150122b 1340
Wayne Roberts 1:0817a150122b 1341 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1342 };
Wayne Roberts 1:0817a150122b 1343
Wayne Roberts 1:0817a150122b 1344 const menu_t* Radio::get_modem_sub_menu() { return NULL; }
Wayne Roberts 1:0817a150122b 1345
Wayne Roberts 1:0817a150122b 1346 const menu_t* Radio::get_modem_menu()
Wayne Roberts 1:0817a150122b 1347 {
Wayne Roberts 1:0817a150122b 1348 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 1349
Wayne Roberts 1:0817a150122b 1350 if (pktType == PACKET_TYPE_LORA) {
Wayne Roberts 1:0817a150122b 1351 return lora_menu;
Wayne Roberts 1:0817a150122b 1352 } else if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 1353 return gfsk_menu;
Wayne Roberts 1:0817a150122b 1354 }
Wayne Roberts 1:0817a150122b 1355
Wayne Roberts 1:0817a150122b 1356 return NULL;
Wayne Roberts 1:0817a150122b 1357 }
Wayne Roberts 1:0817a150122b 1358
Wayne Roberts 1:0817a150122b 1359 #endif /* ..SX126x_H */
Wayne Roberts 1:0817a150122b 1360