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 Nov 01 13:02:38 2018 -0700
Revision:
3:56fc764dee0a
Parent:
2:ea9245bb1c53
Child:
4:fa31fdf4ec8d
add post-preamble gap

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