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