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:
dudmuck
Date:
Thu Sep 16 21:57:23 2021 +0000
Revision:
14:14b9e1c08bfc
Parent:
13:8ce61a1897ab
BufferedSerial flush printf

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 SX128x_H
Wayne Roberts 1:0817a150122b 3
Wayne Roberts 1:0817a150122b 4 #include <float.h>
dudmuck 14:14b9e1c08bfc 5 using namespace std::chrono;
Wayne Roberts 1:0817a150122b 6
dudmuck 14:14b9e1c08bfc 7 #if defined(TARGET_FF_ARDUINO) || defined(TARGET_FF_ARDUINO_UNO) /* pins of SX126xDVK1xAS board */
Wayne Roberts 1:0817a150122b 8 #define NRST_PIN A0
Wayne Roberts 1:0817a150122b 9 SPI spi(D11, D12, D13); // mosi, miso, sclk
Wayne Roberts 1:0817a150122b 10 // spi, nss, busy, dio1
Wayne Roberts 1:0817a150122b 11 SX128x Radio::radio(spi, D7, D3, D5, NRST_PIN);
Wayne Roberts 1:0817a150122b 12
Wayne Roberts 1:0817a150122b 13 #define LED_ON 1
Wayne Roberts 1:0817a150122b 14 #define LED_OFF 0
Wayne Roberts 1:0817a150122b 15 DigitalOut tx_led(A4);
Wayne Roberts 1:0817a150122b 16 DigitalOut rx_led(A5);
Wayne Roberts 1:0817a150122b 17
Wayne Roberts 1:0817a150122b 18
Wayne Roberts 1:0817a150122b 19 DigitalOut ant_sw(A3);
Wayne Roberts 1:0817a150122b 20 DigitalOut cps(D6); // SE2436L
Wayne Roberts 1:0817a150122b 21
Wayne Roberts 1:0817a150122b 22 bool fe_enable; // SE2436L
Wayne Roberts 1:0817a150122b 23
Wayne Roberts 1:0817a150122b 24 void Radio::chipModeChange()
Wayne Roberts 1:0817a150122b 25 {
Wayne Roberts 1:0817a150122b 26 if (radio.chipMode == CHIPMODE_NONE) {
Wayne Roberts 1:0817a150122b 27 cps = 0;
Wayne Roberts 1:0817a150122b 28 tx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 29 rx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 30 } else if (radio.chipMode == CHIPMODE_TX) {
Wayne Roberts 1:0817a150122b 31 cps = fe_enable;
Wayne Roberts 1:0817a150122b 32 tx_led = LED_ON;
Wayne Roberts 1:0817a150122b 33 rx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 34 } else if (radio.chipMode == CHIPMODE_RX) {
Wayne Roberts 1:0817a150122b 35 cps = fe_enable;
Wayne Roberts 1:0817a150122b 36 tx_led = LED_OFF;
Wayne Roberts 1:0817a150122b 37 rx_led = LED_ON;
Wayne Roberts 1:0817a150122b 38 }
Wayne Roberts 1:0817a150122b 39 }
Wayne Roberts 1:0817a150122b 40 #endif /* TARGET_FF_ARDUINO */
Wayne Roberts 1:0817a150122b 41
Wayne Roberts 1:0817a150122b 42 const char* const Radio::chipNum_str = "SX1280";
Wayne Roberts 1:0817a150122b 43
Wayne Roberts 1:0817a150122b 44 uint8_t Radio::tx_param_buf[2];
Wayne Roberts 1:0817a150122b 45
Wayne Roberts 1:0817a150122b 46 ModulationParams_t Radio::Radio::mpFLRC, Radio::Radio::mpBLE_GFSK, Radio::mpLORA;
Wayne Roberts 1:0817a150122b 47 PacketParams_t Radio::ppGFSK, Radio::ppFLRC, Radio::ppLORA, Radio::ppBLE;
Wayne Roberts 1:0817a150122b 48
Wayne Roberts 1:0817a150122b 49 const RadioEvents_t* Radio::RadioEvents;
Wayne Roberts 1:0817a150122b 50 LowPowerTimer Radio::lpt;
Wayne Roberts 1:0817a150122b 51 uint8_t Radio::pktType;
Wayne Roberts 3:56fc764dee0a 52 uint16_t Radio::ppg;
Wayne Roberts 1:0817a150122b 53
Wayne Roberts 1:0817a150122b 54 const char* const Radio::pktType_strs[] = {
Wayne Roberts 1:0817a150122b 55 "GFSK ",
Wayne Roberts 1:0817a150122b 56 "LORA ",
Wayne Roberts 1:0817a150122b 57 "RANGING",
Wayne Roberts 1:0817a150122b 58 "FLRC ",
Wayne Roberts 1:0817a150122b 59 "BLE ",
Wayne Roberts 1:0817a150122b 60 NULL
Wayne Roberts 1:0817a150122b 61 };
Wayne Roberts 1:0817a150122b 62
Wayne Roberts 2:ea9245bb1c53 63 unsigned Radio::pktType_read(bool fw)
Wayne Roberts 1:0817a150122b 64 {
Wayne Roberts 1:0817a150122b 65 return radio.getPacketType();
Wayne Roberts 1:0817a150122b 66 }
Wayne Roberts 1:0817a150122b 67
Wayne Roberts 2:ea9245bb1c53 68 menuMode_e Radio::pktType_write(unsigned idx)
Wayne Roberts 1:0817a150122b 69 {
Wayne Roberts 1:0817a150122b 70 radio.setPacketType(idx);
Wayne Roberts 1:0817a150122b 71 return MENUMODE_REINIT_MENU;
Wayne Roberts 1:0817a150122b 72 }
Wayne Roberts 1:0817a150122b 73
Wayne Roberts 1:0817a150122b 74 const char* Radio::tx_ramp_strs[] = {
Wayne Roberts 1:0817a150122b 75 "2 ", // 0
Wayne Roberts 1:0817a150122b 76 "4 ", // 1
Wayne Roberts 1:0817a150122b 77 "6 ", // 2
Wayne Roberts 1:0817a150122b 78 "8 ", // 3
Wayne Roberts 1:0817a150122b 79 "10", // 4
Wayne Roberts 1:0817a150122b 80 "12", // 5
Wayne Roberts 1:0817a150122b 81 "16", // 6
Wayne Roberts 1:0817a150122b 82 "20", // 7
Wayne Roberts 1:0817a150122b 83 NULL
Wayne Roberts 1:0817a150122b 84 };
Wayne Roberts 1:0817a150122b 85
Wayne Roberts 2:ea9245bb1c53 86 unsigned Radio::tx_ramp_read(bool fw)
Wayne Roberts 1:0817a150122b 87 {
Wayne Roberts 1:0817a150122b 88 PaPwrCtrl_t PaPwrCtrl;
Wayne Roberts 1:0817a150122b 89 PaPwrCtrl.octet = radio.readReg(REG_ADDR_PA_PWR_CTRL, 1);
Wayne Roberts 1:0817a150122b 90
Wayne Roberts 1:0817a150122b 91 switch (PaPwrCtrl.bits.ramp_time) {
Wayne Roberts 1:0817a150122b 92 case 0: tx_param_buf[1] = RADIO_RAMP_02_US; break;
Wayne Roberts 1:0817a150122b 93 case 1: tx_param_buf[1] = RADIO_RAMP_04_US; break;
Wayne Roberts 1:0817a150122b 94 case 2: tx_param_buf[1] = RADIO_RAMP_06_US; break;
Wayne Roberts 1:0817a150122b 95 case 3: tx_param_buf[1] = RADIO_RAMP_08_US; break;
Wayne Roberts 1:0817a150122b 96 case 4: tx_param_buf[1] = RADIO_RAMP_10_US; break;
Wayne Roberts 1:0817a150122b 97 case 5: tx_param_buf[1] = RADIO_RAMP_12_US; break;
Wayne Roberts 1:0817a150122b 98 case 6: tx_param_buf[1] = RADIO_RAMP_16_US; break;
Wayne Roberts 1:0817a150122b 99 case 7: tx_param_buf[1] = RADIO_RAMP_20_US; break;
Wayne Roberts 1:0817a150122b 100 }
Wayne Roberts 1:0817a150122b 101
Wayne Roberts 1:0817a150122b 102 return PaPwrCtrl.bits.ramp_time;
Wayne Roberts 1:0817a150122b 103 }
Wayne Roberts 1:0817a150122b 104
Wayne Roberts 2:ea9245bb1c53 105 menuMode_e Radio::tx_ramp_write(unsigned val)
Wayne Roberts 1:0817a150122b 106 {
Wayne Roberts 1:0817a150122b 107 switch (val) {
Wayne Roberts 1:0817a150122b 108 case 0: tx_param_buf[1] = RADIO_RAMP_02_US; break;
Wayne Roberts 1:0817a150122b 109 case 1: tx_param_buf[1] = RADIO_RAMP_04_US; break;
Wayne Roberts 1:0817a150122b 110 case 2: tx_param_buf[1] = RADIO_RAMP_06_US; break;
Wayne Roberts 1:0817a150122b 111 case 3: tx_param_buf[1] = RADIO_RAMP_08_US; break;
Wayne Roberts 1:0817a150122b 112 case 4: tx_param_buf[1] = RADIO_RAMP_10_US; break;
Wayne Roberts 1:0817a150122b 113 case 5: tx_param_buf[1] = RADIO_RAMP_12_US; break;
Wayne Roberts 1:0817a150122b 114 case 6: tx_param_buf[1] = RADIO_RAMP_16_US; break;
Wayne Roberts 1:0817a150122b 115 case 7: tx_param_buf[1] = RADIO_RAMP_20_US; break;
Wayne Roberts 1:0817a150122b 116 }
Wayne Roberts 1:0817a150122b 117
Wayne Roberts 1:0817a150122b 118 radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
Wayne Roberts 1:0817a150122b 119
Wayne Roberts 1:0817a150122b 120 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 121 }
Wayne Roberts 1:0817a150122b 122
Wayne Roberts 1:0817a150122b 123 #define TX_PWR_OFFSET 18
Wayne Roberts 1:0817a150122b 124
Wayne Roberts 1:0817a150122b 125 void Radio::tx_dbm_print()
Wayne Roberts 1:0817a150122b 126 {
Wayne Roberts 1:0817a150122b 127 PaPwrCtrl_t PaPwrCtrl;
Wayne Roberts 1:0817a150122b 128
Wayne Roberts 1:0817a150122b 129 PaPwrCtrl.octet = radio.readReg(REG_ADDR_PA_PWR_CTRL, 1);
dudmuck 13:8ce61a1897ab 130 printf("%d", PaPwrCtrl.bits.tx_pwr - TX_PWR_OFFSET);
Wayne Roberts 1:0817a150122b 131
Wayne Roberts 1:0817a150122b 132 tx_param_buf[0] = PaPwrCtrl.bits.tx_pwr;
Wayne Roberts 1:0817a150122b 133 }
Wayne Roberts 1:0817a150122b 134
Wayne Roberts 1:0817a150122b 135 bool Radio::tx_dbm_write(const char* str)
Wayne Roberts 1:0817a150122b 136 {
Wayne Roberts 1:0817a150122b 137 int dbm;
Wayne Roberts 1:0817a150122b 138 sscanf(str, "%d", &dbm);
Wayne Roberts 1:0817a150122b 139
Wayne Roberts 1:0817a150122b 140 tx_param_buf[0] = dbm + TX_PWR_OFFSET;
Wayne Roberts 1:0817a150122b 141 radio.xfer(OPCODE_SET_TX_PARAMS, 2, 0, tx_param_buf);
Wayne Roberts 1:0817a150122b 142 return false;
Wayne Roberts 1:0817a150122b 143 }
Wayne Roberts 1:0817a150122b 144
Wayne Roberts 1:0817a150122b 145 const uint8_t ramp_us[] = {
Wayne Roberts 1:0817a150122b 146 2, // 0
Wayne Roberts 1:0817a150122b 147 4, // 1
Wayne Roberts 1:0817a150122b 148 6, // 2
Wayne Roberts 1:0817a150122b 149 8, // 3
Wayne Roberts 1:0817a150122b 150 10, // 4
Wayne Roberts 1:0817a150122b 151 12, // 5
Wayne Roberts 1:0817a150122b 152 16, // 6
Wayne Roberts 1:0817a150122b 153 20 // 7
Wayne Roberts 1:0817a150122b 154 };
Wayne Roberts 1:0817a150122b 155
Wayne Roberts 1:0817a150122b 156 const char* const Radio::opmode_status_strs[] = {
Wayne Roberts 1:0817a150122b 157 "<0> ", // 0
Wayne Roberts 1:0817a150122b 158 "<1> ", // 1
Wayne Roberts 1:0817a150122b 159 "STDBY_RC ", // 2
Wayne Roberts 1:0817a150122b 160 "STDBY_XOSC", // 3
Wayne Roberts 1:0817a150122b 161 "FS ", // 4
Wayne Roberts 1:0817a150122b 162 "RX ", // 5
Wayne Roberts 1:0817a150122b 163 "TX ", // 6
Wayne Roberts 1:0817a150122b 164 "<7> ", // 7
Wayne Roberts 1:0817a150122b 165 NULL
Wayne Roberts 1:0817a150122b 166 };
Wayne Roberts 1:0817a150122b 167
Wayne Roberts 1:0817a150122b 168 const char* const Radio::opmode_select_strs[] = {
Wayne Roberts 1:0817a150122b 169 "SLEEP ", // 0
Wayne Roberts 1:0817a150122b 170 "STDBY_RC ", // 1
Wayne Roberts 1:0817a150122b 171 "STDBY_XOSC", // 2
Wayne Roberts 1:0817a150122b 172 "FS ", // 3
Wayne Roberts 1:0817a150122b 173 "RX ", // 4
Wayne Roberts 1:0817a150122b 174 "TX ", // 5
Wayne Roberts 1:0817a150122b 175 NULL
Wayne Roberts 1:0817a150122b 176 };
Wayne Roberts 1:0817a150122b 177
Wayne Roberts 2:ea9245bb1c53 178 unsigned Radio::opmode_read(bool forWriting)
Wayne Roberts 1:0817a150122b 179 {
Wayne Roberts 1:0817a150122b 180 status_t status;
Wayne Roberts 1:0817a150122b 181 status.octet = radio.xfer(OPCODE_GET_STATUS, 0, 0, NULL);
Wayne Roberts 1:0817a150122b 182
Wayne Roberts 1:0817a150122b 183 if (forWriting) {
Wayne Roberts 1:0817a150122b 184 /* translate opmode_status_strs to opmode_select_strs */
Wayne Roberts 1:0817a150122b 185 switch (status.bits.chipMode) {
Wayne Roberts 1:0817a150122b 186 case 2: return 1; // STDBY_RC
Wayne Roberts 1:0817a150122b 187 case 3: return 2; //STDBY_XOSC
Wayne Roberts 1:0817a150122b 188 case 4: return 3; //FS
Wayne Roberts 1:0817a150122b 189 case 5: return 4; // RX
Wayne Roberts 1:0817a150122b 190 case 6: return 5; // TX
Wayne Roberts 1:0817a150122b 191 default: return 0;
Wayne Roberts 1:0817a150122b 192 }
Wayne Roberts 1:0817a150122b 193 } else
Wayne Roberts 1:0817a150122b 194 return status.bits.chipMode;
Wayne Roberts 1:0817a150122b 195 }
Wayne Roberts 1:0817a150122b 196
Wayne Roberts 2:ea9245bb1c53 197 menuMode_e Radio::opmode_write(unsigned sel)
Wayne Roberts 1:0817a150122b 198 {
Wayne Roberts 1:0817a150122b 199 switch (sel) {
Wayne Roberts 1:0817a150122b 200 case 0: // SLEEP
Wayne Roberts 1:0817a150122b 201 radio.setSleep(true);
Wayne Roberts 1:0817a150122b 202 break;
Wayne Roberts 1:0817a150122b 203 case 1: // STDBY_RC
Wayne Roberts 1:0817a150122b 204 radio.setStandby(STDBY_RC);
Wayne Roberts 1:0817a150122b 205 break;
Wayne Roberts 1:0817a150122b 206 case 2: // STDBY_XOSC
Wayne Roberts 1:0817a150122b 207 radio.setStandby(STDBY_XOSC);
Wayne Roberts 1:0817a150122b 208 break; case 3: // FS
Wayne Roberts 1:0817a150122b 209 radio.setFS();
Wayne Roberts 1:0817a150122b 210 break;
Wayne Roberts 1:0817a150122b 211 case 4: // RX
Wayne Roberts 1:0817a150122b 212 radio.start_rx(0);
Wayne Roberts 1:0817a150122b 213 break;
Wayne Roberts 1:0817a150122b 214 case 5: // TX
Wayne Roberts 1:0817a150122b 215 {
Wayne Roberts 1:0817a150122b 216 uint8_t buf[3];
Wayne Roberts 1:0817a150122b 217 buf[0] = radio.periodBase;
Wayne Roberts 1:0817a150122b 218 buf[0] = 0;
Wayne Roberts 1:0817a150122b 219 buf[1] = 0;
Wayne Roberts 1:0817a150122b 220 radio.xfer(OPCODE_SET_TX, 3, 0, buf);
Wayne Roberts 1:0817a150122b 221 }
Wayne Roberts 1:0817a150122b 222 break;
Wayne Roberts 1:0817a150122b 223 } // ..switch (menuState.sel_idx)
Wayne Roberts 1:0817a150122b 224
Wayne Roberts 1:0817a150122b 225 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 226 }
Wayne Roberts 1:0817a150122b 227
Wayne Roberts 1:0817a150122b 228 uint8_t Radio::get_payload_length()
Wayne Roberts 1:0817a150122b 229 {
Wayne Roberts 1:0817a150122b 230 uint8_t reg8;
Wayne Roberts 1:0817a150122b 231
Wayne Roberts 1:0817a150122b 232 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 233
Wayne Roberts 1:0817a150122b 234 switch (pktType) {
Wayne Roberts 1:0817a150122b 235 case PACKET_TYPE_FLRC:
Wayne Roberts 1:0817a150122b 236 case PACKET_TYPE_GFSK:
Wayne Roberts 1:0817a150122b 237 reg8 = radio.readReg(REG_ADDR_PAYLOAD_LEN, 1);
Wayne Roberts 1:0817a150122b 238 ppGFSK.gfskFLRC.PayloadLength = reg8;
Wayne Roberts 1:0817a150122b 239 ppFLRC.gfskFLRC.PayloadLength = reg8;
Wayne Roberts 1:0817a150122b 240 return ppFLRC.gfskFLRC.PayloadLength;
Wayne Roberts 1:0817a150122b 241 case PACKET_TYPE_RANGING:
Wayne Roberts 1:0817a150122b 242 case PACKET_TYPE_LORA:
Wayne Roberts 1:0817a150122b 243 ppLORA.lora.PayloadLength = radio.readReg(REG_ADDR_LORA_TX_PAYLOAD_LENGTH, 1);
Wayne Roberts 1:0817a150122b 244 return ppLORA.lora.PayloadLength;
Wayne Roberts 1:0817a150122b 245 case PACKET_TYPE_BLE:
Wayne Roberts 1:0817a150122b 246 return 0; // TODO BLE
Wayne Roberts 1:0817a150122b 247 }
Wayne Roberts 1:0817a150122b 248
Wayne Roberts 1:0817a150122b 249 return 0;
Wayne Roberts 1:0817a150122b 250 }
Wayne Roberts 1:0817a150122b 251
Wayne Roberts 1:0817a150122b 252 void Radio::set_payload_length(uint8_t len)
Wayne Roberts 1:0817a150122b 253 {
Wayne Roberts 1:0817a150122b 254 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 255
Wayne Roberts 1:0817a150122b 256 switch (pktType) {
Wayne Roberts 1:0817a150122b 257 case PACKET_TYPE_FLRC:
Wayne Roberts 1:0817a150122b 258 ppFLRC.gfskFLRC.PayloadLength = len;
Wayne Roberts 1:0817a150122b 259 ppGFSK.gfskFLRC.PayloadLength = len;
Wayne Roberts 1:0817a150122b 260 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppFLRC.buf);
Wayne Roberts 1:0817a150122b 261 break;
Wayne Roberts 1:0817a150122b 262 case PACKET_TYPE_GFSK:
Wayne Roberts 1:0817a150122b 263 ppFLRC.gfskFLRC.PayloadLength = len;
Wayne Roberts 1:0817a150122b 264 ppGFSK.gfskFLRC.PayloadLength = len;
Wayne Roberts 1:0817a150122b 265 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 266 break;
Wayne Roberts 1:0817a150122b 267 case PACKET_TYPE_RANGING:
Wayne Roberts 1:0817a150122b 268 case PACKET_TYPE_LORA:
Wayne Roberts 1:0817a150122b 269 ppLORA.lora.PayloadLength = len;
Wayne Roberts 1:0817a150122b 270 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 271 break;
Wayne Roberts 1:0817a150122b 272 case PACKET_TYPE_BLE:
Wayne Roberts 1:0817a150122b 273 // TODO BLE
Wayne Roberts 1:0817a150122b 274 break;
Wayne Roberts 1:0817a150122b 275 }
Wayne Roberts 1:0817a150122b 276 }
Wayne Roberts 1:0817a150122b 277
Wayne Roberts 1:0817a150122b 278 void Radio::tx_payload_length_print()
Wayne Roberts 1:0817a150122b 279 {
dudmuck 13:8ce61a1897ab 280 printf("%u", get_payload_length());
Wayne Roberts 1:0817a150122b 281 }
Wayne Roberts 1:0817a150122b 282
Wayne Roberts 1:0817a150122b 283 bool Radio::tx_payload_length_write(const char* txt)
Wayne Roberts 1:0817a150122b 284 {
Wayne Roberts 1:0817a150122b 285 unsigned len;
Wayne Roberts 1:0817a150122b 286
Wayne Roberts 1:0817a150122b 287 sscanf(txt, "%u", &len);
Wayne Roberts 1:0817a150122b 288
Wayne Roberts 1:0817a150122b 289 set_payload_length(len);
Wayne Roberts 1:0817a150122b 290
Wayne Roberts 1:0817a150122b 291 return false;
Wayne Roberts 1:0817a150122b 292 }
Wayne Roberts 1:0817a150122b 293
Wayne Roberts 1:0817a150122b 294 void Radio::hw_reset()
Wayne Roberts 1:0817a150122b 295 {
Wayne Roberts 1:0817a150122b 296 radio.hw_reset();
Wayne Roberts 3:56fc764dee0a 297
Wayne Roberts 3:56fc764dee0a 298 manualRngDelay = false;
Wayne Roberts 1:0817a150122b 299 }
Wayne Roberts 1:0817a150122b 300
Wayne Roberts 1:0817a150122b 301 void Radio::clearIrqFlags()
Wayne Roberts 1:0817a150122b 302 {
Wayne Roberts 1:0817a150122b 303 uint8_t buf[2];
Wayne Roberts 1:0817a150122b 304 buf[0] = 0xff;
Wayne Roberts 1:0817a150122b 305 buf[1] = 0xff;
Wayne Roberts 1:0817a150122b 306 radio.xfer(OPCODE_CLEAR_IRQ_STATUS, 2, 0, buf);
Wayne Roberts 1:0817a150122b 307 }
Wayne Roberts 1:0817a150122b 308
Wayne Roberts 1:0817a150122b 309 void Radio::readChip()
Wayne Roberts 1:0817a150122b 310 {
Wayne Roberts 1:0817a150122b 311 uint8_t reg8;
Wayne Roberts 1:0817a150122b 312
Wayne Roberts 1:0817a150122b 313 reg8 = radio.readReg(REG_ADDR_PKTCTRL0, 1);
Wayne Roberts 1:0817a150122b 314 ppGFSK.gfskFLRC.HeaderType = reg8 & 0x20;
Wayne Roberts 1:0817a150122b 315 ppFLRC.gfskFLRC.HeaderType = reg8 & 0x20;
Wayne Roberts 1:0817a150122b 316
Wayne Roberts 1:0817a150122b 317 reg8 = radio.readReg(REG_ADDR_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 318 ppGFSK.gfskFLRC.PreambleLength = reg8 & 0x70;
Wayne Roberts 1:0817a150122b 319 ppFLRC.gfskFLRC.PreambleLength = reg8 & 0x70;
Wayne Roberts 1:0817a150122b 320 ppGFSK.gfskFLRC.SyncWordLength = reg8 & 0x0e;
Wayne Roberts 1:0817a150122b 321 ppFLRC.gfskFLRC.SyncWordLength = reg8 & 0x06;
Wayne Roberts 1:0817a150122b 322 if (ppFLRC.gfskFLRC.SyncWordLength == 0x06)
Wayne Roberts 1:0817a150122b 323 ppFLRC.gfskFLRC.SyncWordLength = FLRC_SYNC_WORD_LEN_P32S;
Wayne Roberts 1:0817a150122b 324
Wayne Roberts 1:0817a150122b 325 reg8 = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1);
Wayne Roberts 1:0817a150122b 326 ppGFSK.gfskFLRC.SyncWordMatch = reg8 & 0x70;
Wayne Roberts 1:0817a150122b 327 ppFLRC.gfskFLRC.SyncWordMatch = reg8 & 0x70;
Wayne Roberts 1:0817a150122b 328
Wayne Roberts 1:0817a150122b 329 reg8 = radio.readReg(REG_ADDR_PAYLOAD_LEN, 1);
Wayne Roberts 1:0817a150122b 330 ppGFSK.gfskFLRC.PayloadLength = reg8;
Wayne Roberts 1:0817a150122b 331 ppFLRC.gfskFLRC.PayloadLength = reg8;
Wayne Roberts 1:0817a150122b 332
Wayne Roberts 1:0817a150122b 333 reg8 = radio.readReg(REG_ADDR_PKT_TX_HEADER, 1); // TODO hi bit of payload length
Wayne Roberts 1:0817a150122b 334 ppBLE.ble.ConnectionState = reg8 & 0xe0;
Wayne Roberts 1:0817a150122b 335 ppBLE.ble.BleTestPayload = reg8 & 0x1c;
Wayne Roberts 1:0817a150122b 336
Wayne Roberts 1:0817a150122b 337 reg8 = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 338 ppBLE.ble.CrcLength = reg8 & 0x30;
Wayne Roberts 1:0817a150122b 339 ppBLE.ble.Whitening = reg8 & 0x08;
Wayne Roberts 1:0817a150122b 340 ppGFSK.gfskFLRC.CRCLength = reg8 & 0x30;
Wayne Roberts 1:0817a150122b 341 ppFLRC.gfskFLRC.CRCLength = reg8 & 0x30;
Wayne Roberts 1:0817a150122b 342 ppGFSK.gfskFLRC.Whitening = reg8 & 0x08;
Wayne Roberts 1:0817a150122b 343 ppFLRC.gfskFLRC.Whitening = reg8 & 0x08;
Wayne Roberts 1:0817a150122b 344
Wayne Roberts 3:56fc764dee0a 345 LoRaPktPar0.octet = radio.readReg(REG_ADDR_LORA_PKTPAR0, 1);
Wayne Roberts 3:56fc764dee0a 346 switch (LoRaPktPar0.bits.modem_bw) {
Wayne Roberts 3:56fc764dee0a 347 case 2: mpLORA.lora.bandwidth = LORA_BW_200; break;
Wayne Roberts 3:56fc764dee0a 348 case 3: mpLORA.lora.bandwidth = LORA_BW_400; break;
Wayne Roberts 3:56fc764dee0a 349 case 4: mpLORA.lora.bandwidth = LORA_BW_800; break;
Wayne Roberts 3:56fc764dee0a 350 case 5: mpLORA.lora.bandwidth = LORA_BW_1600; break;
Wayne Roberts 1:0817a150122b 351 }
Wayne Roberts 3:56fc764dee0a 352 mpLORA.lora.spreadingFactor = LoRaPktPar0.bits.modem_sf << 4;
Wayne Roberts 1:0817a150122b 353
Wayne Roberts 1:0817a150122b 354 {
Wayne Roberts 1:0817a150122b 355 LoRaPktPar1_t LoRaPktPar1;
Wayne Roberts 1:0817a150122b 356 LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
Wayne Roberts 1:0817a150122b 357 mpLORA.lora.codingRate = LoRaPktPar1.bits.coding_rate;
Wayne Roberts 1:0817a150122b 358 ppLORA.lora.InvertIQ = LoRaPktPar1.bits.rxinvert_iq ? LORA_IQ_INVERTED : LORA_IQ_STD;
Wayne Roberts 1:0817a150122b 359 ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header ? IMPLICIT_HEADER : EXPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 360 // LoRaPktPar1.bits.ppm_offset
Wayne Roberts 1:0817a150122b 361 }
Wayne Roberts 1:0817a150122b 362
Wayne Roberts 1:0817a150122b 363 {
Wayne Roberts 1:0817a150122b 364 LoRaPreambleReg_t LoRaPreambleReg;
Wayne Roberts 1:0817a150122b 365 LoRaPreambleReg.octet = radio.readReg(REG_ADDR_LORA_PREAMBLE, 1);
Wayne Roberts 1:0817a150122b 366 ppLORA.lora.PreambleLength = LoRaPreambleReg.bits.preamble_symb1_nb * (1 << LoRaPreambleReg.bits.preamble_symb_nb_exp);
Wayne Roberts 1:0817a150122b 367 }
Wayne Roberts 1:0817a150122b 368 ppLORA.lora.PayloadLength = radio.readReg(REG_ADDR_LORA_TX_PAYLOAD_LENGTH, 1);
Wayne Roberts 1:0817a150122b 369
Wayne Roberts 1:0817a150122b 370 {
Wayne Roberts 1:0817a150122b 371 LoRaLrCtl_t LoRaLrCtl;
Wayne Roberts 1:0817a150122b 372 LoRaLrCtl.octet = radio.readReg(REG_ADDR_LORA_LRCTL, 1);
Wayne Roberts 1:0817a150122b 373 ppLORA.lora.crc = LoRaLrCtl.octet & 0x20; // LoRaLrCtl.bits.crc_en
Wayne Roberts 1:0817a150122b 374 }
Wayne Roberts 1:0817a150122b 375
Wayne Roberts 1:0817a150122b 376 {
Wayne Roberts 1:0817a150122b 377 RegRxBw_t RegRxBw;
Wayne Roberts 1:0817a150122b 378 unsigned bps;
Wayne Roberts 1:0817a150122b 379 FloraPreambleHi_t FloraPreambleHi;
Wayne Roberts 1:0817a150122b 380 float mi, fdev_hz;
Wayne Roberts 1:0817a150122b 381 unsigned freqDev;
Wayne Roberts 1:0817a150122b 382 FskModDfH_t FskModDfH;
Wayne Roberts 1:0817a150122b 383 FskModDfH.octet = radio.readReg(REG_ADDR_FSK_MODDFH, 1);
Wayne Roberts 1:0817a150122b 384 freqDev = FskModDfH.bits.freqDev;
Wayne Roberts 1:0817a150122b 385 freqDev <<= 8;
Wayne Roberts 1:0817a150122b 386 freqDev |= radio.readReg(REG_ADDR_FSK_MODDFL, 1);
Wayne Roberts 1:0817a150122b 387 //printf("freqDev %x, %x\r\n", freqDev, freqDev);
Wayne Roberts 1:0817a150122b 388 fdev_hz = freqDev * PLL_STEP_HZ;
Wayne Roberts 1:0817a150122b 389 //printf("fdev hz:%f\r\n", fdev_hz);
Wayne Roberts 1:0817a150122b 390
Wayne Roberts 1:0817a150122b 391 FloraPreambleHi.octet = radio.readReg(REG_ADDR_FLORA_PREAMBLE_HI, 1);
Wayne Roberts 1:0817a150122b 392 switch (FloraPreambleHi.bits.data_rate) {
Wayne Roberts 1:0817a150122b 393 case 0:
Wayne Roberts 1:0817a150122b 394 bps = 2.0e6;
Wayne Roberts 1:0817a150122b 395 //mpFLRC.flrc.bitrateBandwidth = ??; // 2.6
Wayne Roberts 1:0817a150122b 396 break;
Wayne Roberts 1:0817a150122b 397 case 1:
Wayne Roberts 1:0817a150122b 398 bps = 1.6e6;
Wayne Roberts 1:0817a150122b 399 //mpFLRC.flrc.bitrateBandwidth = ??; // 2.08
Wayne Roberts 1:0817a150122b 400 break;
Wayne Roberts 1:0817a150122b 401 case 2:
Wayne Roberts 1:0817a150122b 402 bps = 1.0e6;
Wayne Roberts 1:0817a150122b 403 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_300_BW_1_2; // 1.3
Wayne Roberts 1:0817a150122b 404 break;
Wayne Roberts 1:0817a150122b 405 case 3:
Wayne Roberts 1:0817a150122b 406 bps = 0.8e6;
Wayne Roberts 1:0817a150122b 407 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_000_BW_1_2; // 1.04
Wayne Roberts 1:0817a150122b 408 break;
Wayne Roberts 1:0817a150122b 409 case 4:
Wayne Roberts 1:0817a150122b 410 bps = 0.5e6;
Wayne Roberts 1:0817a150122b 411 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_650_BW_0_6; // 0.65
Wayne Roberts 1:0817a150122b 412 break;
Wayne Roberts 1:0817a150122b 413 case 5:
Wayne Roberts 1:0817a150122b 414 bps = 0.4e6;
Wayne Roberts 1:0817a150122b 415 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_520_BW_0_6; // 0.52
Wayne Roberts 1:0817a150122b 416 break;
Wayne Roberts 1:0817a150122b 417 case 6:
Wayne Roberts 1:0817a150122b 418 bps = 0.25e6;
Wayne Roberts 1:0817a150122b 419 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_325_BW_0_3; // 0.325
Wayne Roberts 1:0817a150122b 420 break;
Wayne Roberts 1:0817a150122b 421 case 7:
Wayne Roberts 1:0817a150122b 422 bps = 0.125e6;
Wayne Roberts 1:0817a150122b 423 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_260_BW_0_3; // 0.26
Wayne Roberts 1:0817a150122b 424 break;
Wayne Roberts 1:0817a150122b 425 }
Wayne Roberts 1:0817a150122b 426
Wayne Roberts 1:0817a150122b 427 mi = (fdev_hz * 2.0) / bps;
Wayne Roberts 1:0817a150122b 428 if (mi > 0.35) {
Wayne Roberts 1:0817a150122b 429 mi -= 0.5;
Wayne Roberts 1:0817a150122b 430 mi /= 0.25;
Wayne Roberts 1:0817a150122b 431 mpBLE_GFSK.gfskBle.ModulationIndex = ((uint8_t)mi) + 1;
Wayne Roberts 1:0817a150122b 432 } else
Wayne Roberts 1:0817a150122b 433 mpBLE_GFSK.gfskBle.ModulationIndex = 0;
Wayne Roberts 1:0817a150122b 434
Wayne Roberts 1:0817a150122b 435 RegRxBw.octet = radio.readReg(REG_ADDR_RXBW, 1);
Wayne Roberts 1:0817a150122b 436
Wayne Roberts 1:0817a150122b 437 //printf("rx ");
Wayne Roberts 1:0817a150122b 438 switch (RegRxBw.bits.bw) {
Wayne Roberts 1:0817a150122b 439 case 0:
Wayne Roberts 1:0817a150122b 440 //printf("2.4");
Wayne Roberts 1:0817a150122b 441 if (FloraPreambleHi.bits.data_rate == 0)
Wayne Roberts 1:0817a150122b 442 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_2_000_BW_2_4;
Wayne Roberts 1:0817a150122b 443 if (FloraPreambleHi.bits.data_rate == 1)
Wayne Roberts 1:0817a150122b 444 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_600_BW_2_4;
Wayne Roberts 1:0817a150122b 445 if (FloraPreambleHi.bits.data_rate == 2)
Wayne Roberts 1:0817a150122b 446 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_2_4;
Wayne Roberts 1:0817a150122b 447 if (FloraPreambleHi.bits.data_rate == 3)
Wayne Roberts 1:0817a150122b 448 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_2_4;
Wayne Roberts 1:0817a150122b 449 break;
Wayne Roberts 1:0817a150122b 450 case 1:
Wayne Roberts 1:0817a150122b 451 //printf("1.2");
Wayne Roberts 1:0817a150122b 452 if (FloraPreambleHi.bits.data_rate == 2)
Wayne Roberts 1:0817a150122b 453 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_1_2;
Wayne Roberts 1:0817a150122b 454 if (FloraPreambleHi.bits.data_rate == 3)
Wayne Roberts 1:0817a150122b 455 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_1_2;
Wayne Roberts 1:0817a150122b 456 if (FloraPreambleHi.bits.data_rate == 4)
Wayne Roberts 1:0817a150122b 457 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_1_2;
Wayne Roberts 1:0817a150122b 458 if (FloraPreambleHi.bits.data_rate == 5)
Wayne Roberts 1:0817a150122b 459 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_1_2;
Wayne Roberts 1:0817a150122b 460 break;
Wayne Roberts 1:0817a150122b 461 case 2:
Wayne Roberts 1:0817a150122b 462 //printf("0.6");
Wayne Roberts 1:0817a150122b 463 if (FloraPreambleHi.bits.data_rate == 4)
Wayne Roberts 1:0817a150122b 464 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_0_6;
Wayne Roberts 1:0817a150122b 465 if (FloraPreambleHi.bits.data_rate == 5)
Wayne Roberts 1:0817a150122b 466 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_0_6;
Wayne Roberts 1:0817a150122b 467 if (FloraPreambleHi.bits.data_rate == 6)
Wayne Roberts 1:0817a150122b 468 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_6;
Wayne Roberts 1:0817a150122b 469 break;
Wayne Roberts 1:0817a150122b 470 case 3:
Wayne Roberts 1:0817a150122b 471 //printf("0.3");
Wayne Roberts 1:0817a150122b 472 if (FloraPreambleHi.bits.data_rate == 6)
Wayne Roberts 1:0817a150122b 473 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_3;
Wayne Roberts 1:0817a150122b 474 if (FloraPreambleHi.bits.data_rate == 7)
Wayne Roberts 1:0817a150122b 475 mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_125_BW_0_3;
Wayne Roberts 1:0817a150122b 476 break;
Wayne Roberts 1:0817a150122b 477 }
Wayne Roberts 1:0817a150122b 478 //printf("MHz bw:%u\r\n", RegRxBw.bits.bw);
Wayne Roberts 1:0817a150122b 479 mpBLE_GFSK.gfskBle.bitrateBandwidth = reg8;
Wayne Roberts 1:0817a150122b 480 }
Wayne Roberts 1:0817a150122b 481
Wayne Roberts 1:0817a150122b 482 {
Wayne Roberts 1:0817a150122b 483 FskCfg_t FskCfg;
Wayne Roberts 1:0817a150122b 484 FskCfg.octet = radio.readReg(REG_ADDR_FSK_CFG, 1);
Wayne Roberts 1:0817a150122b 485 //printf("gf_bt:%u\r\n", FskCfg.bits.gf_bt);
Wayne Roberts 1:0817a150122b 486 mpBLE_GFSK.gfskBle.ModulationShaping = FskCfg.bits.gf_bt << 4;
Wayne Roberts 1:0817a150122b 487 mpFLRC.flrc.ModulationShaping = mpBLE_GFSK.gfskBle.ModulationShaping;
Wayne Roberts 1:0817a150122b 488 }
Wayne Roberts 1:0817a150122b 489
Wayne Roberts 1:0817a150122b 490 {
Wayne Roberts 1:0817a150122b 491 PktBitStreamCtrl_t PktBitStreamCtrl;
Wayne Roberts 1:0817a150122b 492 PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 493 mpFLRC.flrc.CodingRate = PktBitStreamCtrl.octet & 0x06; // PktBitStreamCtrl.bits.flora_coding_rate
Wayne Roberts 1:0817a150122b 494 }
Wayne Roberts 1:0817a150122b 495
Wayne Roberts 1:0817a150122b 496 }
Wayne Roberts 1:0817a150122b 497
Wayne Roberts 1:0817a150122b 498 void Radio::rxDone(uint8_t size, const pktStatus_t* pktStatus)
Wayne Roberts 1:0817a150122b 499 {
Wayne Roberts 1:0817a150122b 500 float rssi, snr;
Wayne Roberts 1:0817a150122b 501
Wayne Roberts 1:0817a150122b 502 if (pktStatus->ble_gfsk_flrc.sync.syncAddrsCode == 0) {
Wayne Roberts 1:0817a150122b 503 int8_t s = pktStatus->lora.snr;
Wayne Roberts 1:0817a150122b 504 rssi = -pktStatus->lora.rssiSync / 2.0;
Wayne Roberts 1:0817a150122b 505 snr = s / 4.0;
Wayne Roberts 1:0817a150122b 506 } else {
Wayne Roberts 1:0817a150122b 507 rssi = -pktStatus->ble_gfsk_flrc.rssiSync / 2.0;
Wayne Roberts 1:0817a150122b 508 snr = FLT_MIN;
Wayne Roberts 1:0817a150122b 509 }
Wayne Roberts 1:0817a150122b 510
Wayne Roberts 1:0817a150122b 511 RadioEvents->RxDone(size, rssi, snr);
Wayne Roberts 1:0817a150122b 512 }
Wayne Roberts 1:0817a150122b 513
Wayne Roberts 1:0817a150122b 514 void Radio::txDoneBottom()
Wayne Roberts 1:0817a150122b 515 {
Wayne Roberts 1:0817a150122b 516 if (RadioEvents->TxDone_botHalf)
Wayne Roberts 1:0817a150122b 517 RadioEvents->TxDone_botHalf();
Wayne Roberts 1:0817a150122b 518 }
Wayne Roberts 1:0817a150122b 519
Wayne Roberts 9:295e37c38fb3 520 /*void Radio::cadDone(bool det)
Wayne Roberts 2:ea9245bb1c53 521 {
Wayne Roberts 2:ea9245bb1c53 522 log_printf("cadDone ");
Wayne Roberts 2:ea9245bb1c53 523 if (det)
dudmuck 13:8ce61a1897ab 524 printf("CadDetected");
Wayne Roberts 2:ea9245bb1c53 525
dudmuck 13:8ce61a1897ab 526 printf("\r\n");
Wayne Roberts 9:295e37c38fb3 527 }*/
Wayne Roberts 2:ea9245bb1c53 528
Wayne Roberts 1:0817a150122b 529 void Radio::boardInit(const RadioEvents_t* e)
Wayne Roberts 1:0817a150122b 530 {
Wayne Roberts 1:0817a150122b 531 hw_reset();
Wayne Roberts 1:0817a150122b 532
Wayne Roberts 1:0817a150122b 533 radio.txDone = txDoneBottom;
Wayne Roberts 1:0817a150122b 534 radio.rxDone = rxDone;
Wayne Roberts 2:ea9245bb1c53 535 radio.cadDone = cadDone;
Wayne Roberts 1:0817a150122b 536
Wayne Roberts 1:0817a150122b 537 radio.chipModeChange = chipModeChange;
Wayne Roberts 1:0817a150122b 538
Wayne Roberts 1:0817a150122b 539 readChip();
Wayne Roberts 1:0817a150122b 540
Wayne Roberts 1:0817a150122b 541 RadioEvents = e;
Wayne Roberts 1:0817a150122b 542
Wayne Roberts 1:0817a150122b 543 fe_enable = true;
Wayne Roberts 1:0817a150122b 544
Wayne Roberts 1:0817a150122b 545 lpt.start();
Wayne Roberts 1:0817a150122b 546 }
Wayne Roberts 1:0817a150122b 547
Wayne Roberts 1:0817a150122b 548 void Radio::tx_carrier()
Wayne Roberts 1:0817a150122b 549 {
Wayne Roberts 1:0817a150122b 550 radio.xfer(OPCODE_SET_TX_CARRIER, 0, 0, NULL);
Wayne Roberts 2:ea9245bb1c53 551
Wayne Roberts 2:ea9245bb1c53 552 radio.chipMode = CHIPMODE_TX;
Wayne Roberts 2:ea9245bb1c53 553 chipModeChange();
Wayne Roberts 1:0817a150122b 554 }
Wayne Roberts 1:0817a150122b 555
Wayne Roberts 1:0817a150122b 556 void Radio::tx_preamble()
Wayne Roberts 1:0817a150122b 557 {
Wayne Roberts 1:0817a150122b 558 radio.xfer(OPCODE_SET_TX_PREAMBLE, 0, 0, NULL);
Wayne Roberts 2:ea9245bb1c53 559
Wayne Roberts 2:ea9245bb1c53 560 radio.chipMode = CHIPMODE_TX;
Wayne Roberts 2:ea9245bb1c53 561 chipModeChange();
Wayne Roberts 1:0817a150122b 562 }
Wayne Roberts 1:0817a150122b 563
Wayne Roberts 3:56fc764dee0a 564 void Radio::rngTx()
Wayne Roberts 3:56fc764dee0a 565 {
Wayne Roberts 3:56fc764dee0a 566 IrqFlags_t irqEnable;
Wayne Roberts 3:56fc764dee0a 567 uint8_t buf[8];
Wayne Roberts 3:56fc764dee0a 568
Wayne Roberts 3:56fc764dee0a 569 if (!manualRngDelay)
Wayne Roberts 3:56fc764dee0a 570 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 571
Wayne Roberts 3:56fc764dee0a 572 irqEnable.word = 0;
Wayne Roberts 3:56fc764dee0a 573 irqEnable.bits.TxDone = 1;
Wayne Roberts 3:56fc764dee0a 574 irqEnable.bits.RxTxTimeout = 1;
Wayne Roberts 3:56fc764dee0a 575 irqEnable.bits.RangingMasterTimeout = 1;
Wayne Roberts 3:56fc764dee0a 576 irqEnable.bits.RangingMasterResultValid = 1;
Wayne Roberts 3:56fc764dee0a 577 irqEnable.bits.RangingMasterRequestValid = 1;
Wayne Roberts 3:56fc764dee0a 578
Wayne Roberts 3:56fc764dee0a 579 buf[0] = irqEnable.word >> 8; // enable bits
Wayne Roberts 3:56fc764dee0a 580 buf[1] = irqEnable.word; // enable bits
Wayne Roberts 3:56fc764dee0a 581
Wayne Roberts 3:56fc764dee0a 582 irqEnable.bits.RangingMasterTimeout = 0;
Wayne Roberts 3:56fc764dee0a 583 irqEnable.bits.RangingMasterResultValid = 0;
Wayne Roberts 3:56fc764dee0a 584 irqEnable.bits.RangingMasterRequestValid = 0;
Wayne Roberts 3:56fc764dee0a 585 buf[2] = irqEnable.word >> 8; // dio1
Wayne Roberts 3:56fc764dee0a 586 buf[3] = irqEnable.word; // dio1
Wayne Roberts 3:56fc764dee0a 587
Wayne Roberts 3:56fc764dee0a 588 buf[4] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 589 buf[5] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 590 buf[6] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 591 buf[7] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 592 radio.xfer(OPCODE_SET_DIO_IRQ_PARAMS, 8, 0, buf);
Wayne Roberts 3:56fc764dee0a 593
Wayne Roberts 3:56fc764dee0a 594 log_printf("rngTx\r\n");
Wayne Roberts 3:56fc764dee0a 595
Wayne Roberts 3:56fc764dee0a 596 buf[0] = radio.periodBase;
Wayne Roberts 3:56fc764dee0a 597 /* no timeout */
Wayne Roberts 3:56fc764dee0a 598 buf[1] = 0;
Wayne Roberts 3:56fc764dee0a 599 buf[2] = 0;
Wayne Roberts 3:56fc764dee0a 600 radio.xfer(OPCODE_SET_TX, 3, 0, buf);
Wayne Roberts 3:56fc764dee0a 601
Wayne Roberts 3:56fc764dee0a 602 radio.chipMode = CHIPMODE_TX;
Wayne Roberts 3:56fc764dee0a 603 chipModeChange();
Wayne Roberts 3:56fc764dee0a 604 }
Wayne Roberts 3:56fc764dee0a 605
Wayne Roberts 1:0817a150122b 606 void Radio::txPkt()
Wayne Roberts 1:0817a150122b 607 {
Wayne Roberts 1:0817a150122b 608 uint8_t txlen = 0;
Wayne Roberts 1:0817a150122b 609
Wayne Roberts 1:0817a150122b 610 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 611
Wayne Roberts 1:0817a150122b 612 switch (pktType) {
Wayne Roberts 1:0817a150122b 613 case PACKET_TYPE_FLRC:
Wayne Roberts 1:0817a150122b 614 case PACKET_TYPE_GFSK:
Wayne Roberts 1:0817a150122b 615 txlen = radio.readReg(REG_ADDR_PAYLOAD_LEN, 1);
Wayne Roberts 1:0817a150122b 616 break;
Wayne Roberts 1:0817a150122b 617 case PACKET_TYPE_BLE:
Wayne Roberts 1:0817a150122b 618 return; // TODO BLE
Wayne Roberts 1:0817a150122b 619 case PACKET_TYPE_RANGING:
Wayne Roberts 3:56fc764dee0a 620 rngTx();
Wayne Roberts 3:56fc764dee0a 621 return;
Wayne Roberts 1:0817a150122b 622 case PACKET_TYPE_LORA:
Wayne Roberts 1:0817a150122b 623 txlen = radio.readReg(REG_ADDR_LORA_TX_PAYLOAD_LENGTH, 1);
Wayne Roberts 1:0817a150122b 624 break;
Wayne Roberts 1:0817a150122b 625 }
Wayne Roberts 1:0817a150122b 626 log_printf("txPkt%u\r\n", txlen);
Wayne Roberts 1:0817a150122b 627
Wayne Roberts 3:56fc764dee0a 628 radio.setBufferBase(0, 0);
Wayne Roberts 3:56fc764dee0a 629
Wayne Roberts 1:0817a150122b 630 radio.start_tx(txlen, 0);
Wayne Roberts 1:0817a150122b 631
Wayne Roberts 1:0817a150122b 632 }
Wayne Roberts 1:0817a150122b 633
Wayne Roberts 1:0817a150122b 634 #define REGBW_2_4MHZ 0
Wayne Roberts 1:0817a150122b 635 #define REGBW_1_2MHZ 1
Wayne Roberts 1:0817a150122b 636 #define REGBW_0_6MHZ 2
Wayne Roberts 1:0817a150122b 637 #define REGBW_0_3MHZ 3
Wayne Roberts 1:0817a150122b 638
Wayne Roberts 2:ea9245bb1c53 639 unsigned Radio::gfsk_flrc_bpsbw_read(bool fw)
Wayne Roberts 1:0817a150122b 640 {
Wayne Roberts 1:0817a150122b 641 unsigned n = UINT_MAX;
Wayne Roberts 1:0817a150122b 642 RegRxBw_t RegRxBw;
Wayne Roberts 1:0817a150122b 643 FloraPreambleHi_t FloraPreambleHi;
Wayne Roberts 1:0817a150122b 644 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 645
Wayne Roberts 1:0817a150122b 646 FloraPreambleHi.octet = radio.readReg(REG_ADDR_FLORA_PREAMBLE_HI, 1);
Wayne Roberts 1:0817a150122b 647
Wayne Roberts 1:0817a150122b 648 RegRxBw.octet = radio.readReg(REG_ADDR_RXBW, 1);
Wayne Roberts 1:0817a150122b 649
Wayne Roberts 1:0817a150122b 650 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 651 switch (FloraPreambleHi.bits.data_rate) {
Wayne Roberts 1:0817a150122b 652 case 0:
Wayne Roberts 1:0817a150122b 653 n = 0; // 2Mbps, 2.4MHz
Wayne Roberts 1:0817a150122b 654 break;
Wayne Roberts 1:0817a150122b 655 case 1:
Wayne Roberts 1:0817a150122b 656 n = 1; // 1.6Mbps, 2.4MHz
Wayne Roberts 1:0817a150122b 657 break;
Wayne Roberts 1:0817a150122b 658 case 2:
Wayne Roberts 1:0817a150122b 659 if (RegRxBw.bits.bw == REGBW_2_4MHZ)
Wayne Roberts 1:0817a150122b 660 n = 2;
Wayne Roberts 1:0817a150122b 661 else if (RegRxBw.bits.bw == REGBW_1_2MHZ)
Wayne Roberts 1:0817a150122b 662 n = 3;
Wayne Roberts 1:0817a150122b 663 break;
Wayne Roberts 1:0817a150122b 664 case 3:
Wayne Roberts 1:0817a150122b 665 if (RegRxBw.bits.bw == REGBW_2_4MHZ) // 0.8Mbps 2.4 2.4MHz
Wayne Roberts 1:0817a150122b 666 n = 4;
Wayne Roberts 1:0817a150122b 667 else if (RegRxBw.bits.bw == REGBW_1_2MHZ) // 0.8Mbps 1.2MHz
Wayne Roberts 1:0817a150122b 668 n = 5;
Wayne Roberts 1:0817a150122b 669 break;
Wayne Roberts 1:0817a150122b 670 case 4:
Wayne Roberts 1:0817a150122b 671 if (RegRxBw.bits.bw == REGBW_1_2MHZ) // 0.5Mbps 1.2MHz
Wayne Roberts 1:0817a150122b 672 n = 6;
Wayne Roberts 1:0817a150122b 673 else if (RegRxBw.bits.bw == REGBW_0_6MHZ) // 0.5Mbps 0.6MHz
Wayne Roberts 1:0817a150122b 674 n = 7;
Wayne Roberts 1:0817a150122b 675 break;
Wayne Roberts 1:0817a150122b 676 case 5:
Wayne Roberts 1:0817a150122b 677 if (RegRxBw.bits.bw == REGBW_1_2MHZ) // 0.4Mbps 1.2MHz
Wayne Roberts 1:0817a150122b 678 n = 8;
Wayne Roberts 1:0817a150122b 679 else if (RegRxBw.bits.bw == REGBW_0_6MHZ) // 0.4Mbps 0.6MHz
Wayne Roberts 1:0817a150122b 680 n = 9;
Wayne Roberts 1:0817a150122b 681 break;
Wayne Roberts 1:0817a150122b 682 case 6:
Wayne Roberts 1:0817a150122b 683 if (RegRxBw.bits.bw == REGBW_0_6MHZ) // 0.25Mbps 0.6MHz
Wayne Roberts 1:0817a150122b 684 n = 10;
Wayne Roberts 1:0817a150122b 685 else if (RegRxBw.bits.bw == REGBW_0_3MHZ) // 0.25Mbps 0.3MHz
Wayne Roberts 1:0817a150122b 686 n = 11;
Wayne Roberts 1:0817a150122b 687 break;
Wayne Roberts 1:0817a150122b 688 case 7:
Wayne Roberts 1:0817a150122b 689 n = 12; // 0.125Mbps, assume bw=0.3MHz
Wayne Roberts 1:0817a150122b 690 break;
Wayne Roberts 1:0817a150122b 691 } // ..switch (FloraPreambleHi.bits.data_rate)
Wayne Roberts 1:0817a150122b 692 } else if (pktType == PACKET_TYPE_FLRC) {
Wayne Roberts 1:0817a150122b 693 n = FloraPreambleHi.bits.data_rate;
Wayne Roberts 1:0817a150122b 694 // datarate, bits 5,6,7.. bw bits 0,1,2
Wayne Roberts 1:0817a150122b 695 switch (FloraPreambleHi.bits.data_rate) {
Wayne Roberts 1:0817a150122b 696 case 0:
Wayne Roberts 1:0817a150122b 697 break;
Wayne Roberts 1:0817a150122b 698 case 1:
Wayne Roberts 1:0817a150122b 699 break;
Wayne Roberts 1:0817a150122b 700 case 2:
Wayne Roberts 1:0817a150122b 701 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_300_BW_1_2;
Wayne Roberts 1:0817a150122b 702 break;
Wayne Roberts 1:0817a150122b 703 case 3:
Wayne Roberts 1:0817a150122b 704 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_000_BW_1_2;
Wayne Roberts 1:0817a150122b 705 break;
Wayne Roberts 1:0817a150122b 706 case 4:
Wayne Roberts 1:0817a150122b 707 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_650_BW_0_6;
Wayne Roberts 1:0817a150122b 708 break;
Wayne Roberts 1:0817a150122b 709 case 5:
Wayne Roberts 1:0817a150122b 710 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_520_BW_0_6;
Wayne Roberts 1:0817a150122b 711 break;
Wayne Roberts 1:0817a150122b 712 case 6:
Wayne Roberts 1:0817a150122b 713 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_325_BW_0_3;
Wayne Roberts 1:0817a150122b 714 break;
Wayne Roberts 1:0817a150122b 715 case 7:
Wayne Roberts 1:0817a150122b 716 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_260_BW_0_3;
Wayne Roberts 1:0817a150122b 717 break;
Wayne Roberts 1:0817a150122b 718 } // ..switch (FloraPreambleHi.bits.data_rate)
Wayne Roberts 1:0817a150122b 719 }
Wayne Roberts 1:0817a150122b 720
Wayne Roberts 1:0817a150122b 721 return n;
Wayne Roberts 1:0817a150122b 722 }
Wayne Roberts 1:0817a150122b 723
Wayne Roberts 2:ea9245bb1c53 724 menuMode_e Radio::gfsk_flrc_bpsbw_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 725 {
Wayne Roberts 1:0817a150122b 726 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 727
Wayne Roberts 1:0817a150122b 728 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 729 switch (sidx) {
Wayne Roberts 1:0817a150122b 730 case 0: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_2_000_BW_2_4; break;
Wayne Roberts 1:0817a150122b 731 case 1: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_600_BW_2_4; break;
Wayne Roberts 1:0817a150122b 732 case 2: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_2_4; break;
Wayne Roberts 1:0817a150122b 733 case 3: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_1_2; break;
Wayne Roberts 1:0817a150122b 734 case 4: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_2_4; break;
Wayne Roberts 1:0817a150122b 735 case 5: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_1_2; break;
Wayne Roberts 1:0817a150122b 736 case 6: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_1_2; break;
Wayne Roberts 1:0817a150122b 737 case 7: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_0_6; break;
Wayne Roberts 1:0817a150122b 738 case 8: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_1_2; break;
Wayne Roberts 1:0817a150122b 739 case 9: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_0_6; break;
Wayne Roberts 1:0817a150122b 740 case 10: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_6; break;
Wayne Roberts 1:0817a150122b 741 case 11: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_3; break;
Wayne Roberts 1:0817a150122b 742 case 12: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_125_BW_0_3; break;
Wayne Roberts 1:0817a150122b 743 }
Wayne Roberts 1:0817a150122b 744 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpBLE_GFSK.buf);
Wayne Roberts 1:0817a150122b 745 } else if (pktType == PACKET_TYPE_FLRC) {
Wayne Roberts 1:0817a150122b 746 switch (sidx) {
Wayne Roberts 1:0817a150122b 747 case 2: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_300_BW_1_2; break;
Wayne Roberts 1:0817a150122b 748 case 3: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_000_BW_1_2; break;
Wayne Roberts 1:0817a150122b 749 case 4: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_650_BW_0_6; break;
Wayne Roberts 1:0817a150122b 750 case 5: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_520_BW_0_6; break;
Wayne Roberts 1:0817a150122b 751 case 6: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_325_BW_0_3; break;
Wayne Roberts 1:0817a150122b 752 case 7: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_260_BW_0_3; break;
Wayne Roberts 1:0817a150122b 753 default:
Wayne Roberts 1:0817a150122b 754 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 755 }
Wayne Roberts 1:0817a150122b 756 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpFLRC.buf);
Wayne Roberts 1:0817a150122b 757 }
Wayne Roberts 1:0817a150122b 758
Wayne Roberts 1:0817a150122b 759 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 760 }
Wayne Roberts 1:0817a150122b 761
Wayne Roberts 3:56fc764dee0a 762 static const char* const gfsk_bpsbw[] = {
Wayne Roberts 1:0817a150122b 763 " 2.0Mbps 2.4MHz", //0 GFSK_BLE_BR_2_000_BW_2_4 0x04 // Mbps:2 bw:2.4MHz
Wayne Roberts 1:0817a150122b 764 " 1.6Mbps 2.4MHz", //1 GFSK_BLE_BR_1_600_BW_2_4 0x28 // Mbps:1.6 bw:2.4MHz
Wayne Roberts 1:0817a150122b 765 " 1.0Mbps 2.4MHz", //2 GFSK_BLE_BR_1_000_BW_2_4 0x4C // Mbps:1 bw:2.4MHz
Wayne Roberts 1:0817a150122b 766 " 1.0Mbps 1.2MHz", //3 GFSK_BLE_BR_1_000_BW_1_2 0x45 // Mbps:1 bw:1.2MHz
Wayne Roberts 1:0817a150122b 767 " 0.8Mbps 2.4MHz", //4 GFSK_BLE_BR_0_800_BW_2_4 0x70 // Mbps:0.8 bw:2.4MHz
Wayne Roberts 1:0817a150122b 768 " 0.8Mbps 1.2MHz", //5 GFSK_BLE_BR_0_800_BW_1_2 0x69 // Mbps:0.8 bw:1.2MHz
Wayne Roberts 1:0817a150122b 769 " 0.5Mbps 1.2MHz", //6 GFSK_BLE_BR_0_500_BW_1_2 0x8D // Mbps:0.5 bw:1.2MHz
Wayne Roberts 1:0817a150122b 770 " 0.5Mbps 0.6MHz", //7 GFSK_BLE_BR_0_500_BW_0_6 0x86 // Mbps:0.5 bw:0.6MHz
Wayne Roberts 1:0817a150122b 771 " 0.4Mbps 1.2MHz", //8 GFSK_BLE_BR_0_400_BW_1_2 0xB1 // Mbps:0.4 bw:1.2MHz
Wayne Roberts 1:0817a150122b 772 " 0.4Mbps 0.6MHz", //9 GFSK_BLE_BR_0_400_BW_0_6 0xAA // Mbps:0.4 bw:0.6MHz
Wayne Roberts 1:0817a150122b 773 " 0.25Mbps 0.6MHz", //10 GFSK_BLE_BR_0_250_BW_0_6 0xCE // Mbps:0.25 bw:0.6MHz
Wayne Roberts 1:0817a150122b 774 " 0.25Mbps 0.3MHz", //11 GFSK_BLE_BR_0_250_BW_0_3 0xC7 // Mbps:0.25 bw:0.3MHz
Wayne Roberts 1:0817a150122b 775 "0.125Mbps 0.3MHz", //12 GFSK_BLE_BR_0_125_BW_0_3 0xEF // Mbps:0.125 bw:0.3MHz
Wayne Roberts 1:0817a150122b 776 // 01234567890123456
Wayne Roberts 1:0817a150122b 777 NULL
Wayne Roberts 1:0817a150122b 778 };
Wayne Roberts 1:0817a150122b 779
Wayne Roberts 2:ea9245bb1c53 780 const dropdown_item_t Radio::gfsk_bitrate_item = { _ITEM_DROPDOWN, gfsk_bpsbw, gfsk_bpsbw, gfsk_flrc_bpsbw_read, gfsk_flrc_bpsbw_write};
Wayne Roberts 1:0817a150122b 781
Wayne Roberts 1:0817a150122b 782 void Radio::modindex_print()
Wayne Roberts 1:0817a150122b 783 {
Wayne Roberts 1:0817a150122b 784 float mi, Mbps, fdev_hz;
Wayne Roberts 1:0817a150122b 785 unsigned bps, freqDev;
Wayne Roberts 1:0817a150122b 786 FskModDfH_t FskModDfH;
Wayne Roberts 1:0817a150122b 787 FloraPreambleHi_t FloraPreambleHi;
Wayne Roberts 1:0817a150122b 788
Wayne Roberts 1:0817a150122b 789 FloraPreambleHi.octet = radio.readReg(REG_ADDR_FLORA_PREAMBLE_HI, 1);
Wayne Roberts 1:0817a150122b 790 switch (FloraPreambleHi.bits.data_rate) {
Wayne Roberts 1:0817a150122b 791 case 0: Mbps = 2.0; break;
Wayne Roberts 1:0817a150122b 792 case 1: Mbps = 1.6; break;
Wayne Roberts 1:0817a150122b 793 case 2: Mbps = 1.0; break;
Wayne Roberts 1:0817a150122b 794 case 3: Mbps = 0.8; break;
Wayne Roberts 1:0817a150122b 795 case 4: Mbps = 0.5; break;
Wayne Roberts 1:0817a150122b 796 case 5: Mbps = 0.4; break;
Wayne Roberts 1:0817a150122b 797 case 6: Mbps = 0.25; break;
Wayne Roberts 1:0817a150122b 798 case 7: Mbps = 0.125; break;
Wayne Roberts 1:0817a150122b 799 }
Wayne Roberts 1:0817a150122b 800
Wayne Roberts 1:0817a150122b 801 FskModDfH.octet = radio.readReg(REG_ADDR_FSK_MODDFH, 1);
Wayne Roberts 1:0817a150122b 802 freqDev = FskModDfH.bits.freqDev;
Wayne Roberts 1:0817a150122b 803 freqDev <<= 8;
Wayne Roberts 1:0817a150122b 804 freqDev |= radio.readReg(REG_ADDR_FSK_MODDFL, 1);
Wayne Roberts 1:0817a150122b 805
Wayne Roberts 1:0817a150122b 806 fdev_hz = freqDev * PLL_STEP_HZ;
Wayne Roberts 1:0817a150122b 807 bps = Mbps * 1e6;
Wayne Roberts 1:0817a150122b 808 mi = (fdev_hz * 2.0) / bps;
Wayne Roberts 1:0817a150122b 809
dudmuck 13:8ce61a1897ab 810 printf("%.2f", mi);
Wayne Roberts 1:0817a150122b 811 }
Wayne Roberts 1:0817a150122b 812
Wayne Roberts 1:0817a150122b 813 bool Radio::modindex_write(const char* valStr)
Wayne Roberts 1:0817a150122b 814 {
Wayne Roberts 1:0817a150122b 815 float f;
Wayne Roberts 1:0817a150122b 816
Wayne Roberts 1:0817a150122b 817 if (sscanf(valStr, "%f", &f) == 1) {
Wayne Roberts 1:0817a150122b 818 log_printf("scanned %f from \"%s\"\r\n", f);
Wayne Roberts 1:0817a150122b 819 if (f > 0.35) {
Wayne Roberts 1:0817a150122b 820 f -= 0.5;
Wayne Roberts 1:0817a150122b 821 f /= 0.25;
Wayne Roberts 1:0817a150122b 822 log_printf("set modindex:%f\r\n", f);
Wayne Roberts 1:0817a150122b 823 mpBLE_GFSK.gfskBle.ModulationIndex = ((uint8_t)f) + 1;
Wayne Roberts 1:0817a150122b 824 log_printf("to set %02x\r\n", mpBLE_GFSK.gfskBle.ModulationIndex);
Wayne Roberts 1:0817a150122b 825 } else
Wayne Roberts 1:0817a150122b 826 mpBLE_GFSK.gfskBle.ModulationIndex = 0;
Wayne Roberts 1:0817a150122b 827
Wayne Roberts 1:0817a150122b 828 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpBLE_GFSK.buf);
Wayne Roberts 1:0817a150122b 829 }
Wayne Roberts 1:0817a150122b 830 return false;
Wayne Roberts 1:0817a150122b 831 }
Wayne Roberts 1:0817a150122b 832
Wayne Roberts 4:fa31fdf4ec8d 833 const value_item_t Radio::gfsk_modindex_item = { _ITEM_VALUE, 5, modindex_print, modindex_write };
Wayne Roberts 1:0817a150122b 834
Wayne Roberts 3:56fc764dee0a 835 static const char* const gfsk_flrc_bts[] = {
Wayne Roberts 1:0817a150122b 836 "off",
Wayne Roberts 1:0817a150122b 837 "1.0",
Wayne Roberts 1:0817a150122b 838 "0.5",
Wayne Roberts 1:0817a150122b 839 "0.3",
Wayne Roberts 1:0817a150122b 840 NULL
Wayne Roberts 1:0817a150122b 841 };
Wayne Roberts 1:0817a150122b 842
Wayne Roberts 2:ea9245bb1c53 843 unsigned Radio::gfsk_flrc_bt_read(bool fw)
Wayne Roberts 1:0817a150122b 844 {
Wayne Roberts 1:0817a150122b 845 FskCfg_t FskCfg;
Wayne Roberts 1:0817a150122b 846 FskCfg.octet = radio.readReg(REG_ADDR_FSK_CFG, 1);
Wayne Roberts 1:0817a150122b 847 return FskCfg.bits.gf_bt;
Wayne Roberts 1:0817a150122b 848 }
Wayne Roberts 1:0817a150122b 849
Wayne Roberts 2:ea9245bb1c53 850 menuMode_e Radio::gfsk_flrc_bt_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 851 {
Wayne Roberts 1:0817a150122b 852 mpBLE_GFSK.gfskBle.ModulationShaping = sidx << 4;
Wayne Roberts 1:0817a150122b 853 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpBLE_GFSK.buf);
Wayne Roberts 1:0817a150122b 854 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 855 }
Wayne Roberts 1:0817a150122b 856
Wayne Roberts 2:ea9245bb1c53 857 const dropdown_item_t Radio::gfsk_flrc_bt_item = { _ITEM_DROPDOWN, gfsk_flrc_bts, gfsk_flrc_bts, gfsk_flrc_bt_read, gfsk_flrc_bt_write};
Wayne Roberts 1:0817a150122b 858
Wayne Roberts 3:56fc764dee0a 859 static const char* const gfsk_flrc_pblLens[] = {
Wayne Roberts 1:0817a150122b 860 "4",
Wayne Roberts 1:0817a150122b 861 "8",
Wayne Roberts 1:0817a150122b 862 "12",
Wayne Roberts 1:0817a150122b 863 "16",
Wayne Roberts 1:0817a150122b 864 "20",
Wayne Roberts 1:0817a150122b 865 "24",
Wayne Roberts 1:0817a150122b 866 "28",
Wayne Roberts 1:0817a150122b 867 "32",
Wayne Roberts 1:0817a150122b 868 NULL,
Wayne Roberts 1:0817a150122b 869 };
Wayne Roberts 1:0817a150122b 870
Wayne Roberts 2:ea9245bb1c53 871 unsigned Radio::gfsk_flrc_pl_read(bool fw)
Wayne Roberts 1:0817a150122b 872 {
Wayne Roberts 1:0817a150122b 873 PktCtrl1_t PktCtrl1;
Wayne Roberts 1:0817a150122b 874 PktCtrl1.octet = radio.readReg(REG_ADDR_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 875 ppFLRC.gfskFLRC.PreambleLength = PktCtrl1.octet & 0x70;
Wayne Roberts 1:0817a150122b 876 ppGFSK.gfskFLRC.PreambleLength = ppFLRC.gfskFLRC.PreambleLength;
Wayne Roberts 1:0817a150122b 877 return PktCtrl1.gfsk.preamble_len;
Wayne Roberts 1:0817a150122b 878 }
Wayne Roberts 1:0817a150122b 879
Wayne Roberts 2:ea9245bb1c53 880 menuMode_e Radio::gfsk_flrc_pl_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 881 {
Wayne Roberts 1:0817a150122b 882 ppFLRC.gfskFLRC.PreambleLength = sidx << 4;
Wayne Roberts 1:0817a150122b 883 ppGFSK.gfskFLRC.PreambleLength = ppFLRC.gfskFLRC.PreambleLength;
Wayne Roberts 1:0817a150122b 884 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 885 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 886 }
Wayne Roberts 1:0817a150122b 887
Wayne Roberts 2:ea9245bb1c53 888 const dropdown_item_t Radio::gfsk_flrc_preamble_item = { _ITEM_DROPDOWN, gfsk_flrc_pblLens, gfsk_flrc_pblLens, gfsk_flrc_pl_read, gfsk_flrc_pl_write};
Wayne Roberts 1:0817a150122b 889
Wayne Roberts 3:56fc764dee0a 890 static const char* const gfsk_syncLens[] = {
Wayne Roberts 1:0817a150122b 891 "1", // 0
Wayne Roberts 1:0817a150122b 892 "2", // 1
Wayne Roberts 1:0817a150122b 893 "3", // 2
Wayne Roberts 1:0817a150122b 894 "4", // 3
Wayne Roberts 1:0817a150122b 895 "5", // 4
Wayne Roberts 1:0817a150122b 896 NULL,
Wayne Roberts 1:0817a150122b 897 };
Wayne Roberts 1:0817a150122b 898
Wayne Roberts 2:ea9245bb1c53 899 unsigned Radio::gfsk_synclen_read(bool fw)
Wayne Roberts 1:0817a150122b 900 {
Wayne Roberts 1:0817a150122b 901 PktCtrl1_t PktCtrl1;
Wayne Roberts 1:0817a150122b 902 PktCtrl1.octet = radio.readReg(REG_ADDR_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 903
Wayne Roberts 1:0817a150122b 904 ppGFSK.gfskFLRC.SyncWordLength = PktCtrl1.octet & 0x0e;
Wayne Roberts 1:0817a150122b 905 ppFLRC.gfskFLRC.SyncWordLength = PktCtrl1.octet & 0x06;
Wayne Roberts 1:0817a150122b 906
Wayne Roberts 1:0817a150122b 907 return PktCtrl1.gfsk.sync_adrs_len;
Wayne Roberts 1:0817a150122b 908 }
Wayne Roberts 1:0817a150122b 909
Wayne Roberts 2:ea9245bb1c53 910 menuMode_e Radio::gfsk_synclen_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 911 {
Wayne Roberts 1:0817a150122b 912 ppGFSK.gfskFLRC.SyncWordLength = sidx << 1;
Wayne Roberts 1:0817a150122b 913 //log_printf("SWL %u %02x\r\n", sidx, ppGFSK.gfskFLRC.SyncWordLength);
Wayne Roberts 1:0817a150122b 914 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 915 //return MENUMODE_NONE;
Wayne Roberts 1:0817a150122b 916 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 917 }
Wayne Roberts 1:0817a150122b 918
Wayne Roberts 2:ea9245bb1c53 919 const dropdown_item_t Radio::gfsk_synclen_item = { _ITEM_DROPDOWN, gfsk_syncLens, gfsk_syncLens, gfsk_synclen_read, gfsk_synclen_write};
Wayne Roberts 1:0817a150122b 920
Wayne Roberts 1:0817a150122b 921 bool Radio::gfsk_flrc_fixvar_read()
Wayne Roberts 1:0817a150122b 922 {
Wayne Roberts 1:0817a150122b 923 PktCtrl0_t PktCtrl0;
Wayne Roberts 1:0817a150122b 924 PktCtrl0.octet = radio.readReg(REG_ADDR_PKTCTRL0, 1);
Wayne Roberts 1:0817a150122b 925
Wayne Roberts 1:0817a150122b 926 ppGFSK.gfskFLRC.HeaderType = PktCtrl0.octet & 0x20;
Wayne Roberts 1:0817a150122b 927 ppFLRC.gfskFLRC.HeaderType = PktCtrl0.octet & 0x20;
Wayne Roberts 1:0817a150122b 928
Wayne Roberts 1:0817a150122b 929 return PktCtrl0.bits.pkt_len_format;
Wayne Roberts 1:0817a150122b 930 }
Wayne Roberts 1:0817a150122b 931
Wayne Roberts 1:0817a150122b 932 bool Radio::gfsk_flrc_fixvar_push()
Wayne Roberts 1:0817a150122b 933 {
Wayne Roberts 1:0817a150122b 934 PacketParams_t* pp;
Wayne Roberts 1:0817a150122b 935 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 936
Wayne Roberts 1:0817a150122b 937 if (pktType == PACKET_TYPE_FLRC)
Wayne Roberts 1:0817a150122b 938 pp = &ppFLRC;
Wayne Roberts 1:0817a150122b 939 else if (pktType == PACKET_TYPE_GFSK)
Wayne Roberts 1:0817a150122b 940 pp = &ppGFSK;
Wayne Roberts 1:0817a150122b 941 else
Wayne Roberts 1:0817a150122b 942 return false;
Wayne Roberts 1:0817a150122b 943
Wayne Roberts 1:0817a150122b 944 if (pp->gfskFLRC.HeaderType == RADIO_PACKET_VARIABLE_LENGTH)
Wayne Roberts 1:0817a150122b 945 pp->gfskFLRC.HeaderType = RADIO_PACKET_FIXED_LENGTH;
Wayne Roberts 1:0817a150122b 946 else
Wayne Roberts 1:0817a150122b 947 pp->gfskFLRC.HeaderType = RADIO_PACKET_VARIABLE_LENGTH;
Wayne Roberts 1:0817a150122b 948
Wayne Roberts 1:0817a150122b 949 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, pp->buf);
Wayne Roberts 1:0817a150122b 950
Wayne Roberts 1:0817a150122b 951 return pp->gfskFLRC.HeaderType == RADIO_PACKET_VARIABLE_LENGTH;
Wayne Roberts 1:0817a150122b 952 }
Wayne Roberts 1:0817a150122b 953
Wayne Roberts 1:0817a150122b 954 const toggle_item_t Radio::gfsk_flrc_fixvar_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 955 "fixed ",
Wayne Roberts 1:0817a150122b 956 "variable",
Wayne Roberts 1:0817a150122b 957 gfsk_flrc_fixvar_read, gfsk_flrc_fixvar_push
Wayne Roberts 1:0817a150122b 958 };
Wayne Roberts 1:0817a150122b 959
Wayne Roberts 3:56fc764dee0a 960 static const char* const gfsk_flrc_crclens[] = {
Wayne Roberts 1:0817a150122b 961 "0 off",
Wayne Roberts 1:0817a150122b 962 "1 byte",
Wayne Roberts 1:0817a150122b 963 "2 bytes",
Wayne Roberts 1:0817a150122b 964 NULL,
Wayne Roberts 1:0817a150122b 965 };
Wayne Roberts 1:0817a150122b 966
Wayne Roberts 2:ea9245bb1c53 967 unsigned Radio::gfsk_flrc_crclen_read(bool fw)
Wayne Roberts 1:0817a150122b 968 {
Wayne Roberts 1:0817a150122b 969 PktBitStreamCtrl_t PktBitStreamCtrl;
Wayne Roberts 1:0817a150122b 970 PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 971 ppGFSK.gfskFLRC.CRCLength = PktBitStreamCtrl.octet & 0x30;
Wayne Roberts 1:0817a150122b 972 return PktBitStreamCtrl.bits.crc_mode;
Wayne Roberts 1:0817a150122b 973 }
Wayne Roberts 1:0817a150122b 974
Wayne Roberts 2:ea9245bb1c53 975 menuMode_e Radio::gfsk_flrc_crclen_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 976 {
Wayne Roberts 1:0817a150122b 977 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 978
Wayne Roberts 1:0817a150122b 979 ppGFSK.gfskFLRC.CRCLength = (sidx & 3) << 4;
Wayne Roberts 1:0817a150122b 980 ppFLRC.gfskFLRC.CRCLength = (sidx & 3) << 4;
Wayne Roberts 1:0817a150122b 981
Wayne Roberts 1:0817a150122b 982 if (pktType == PACKET_TYPE_GFSK)
Wayne Roberts 1:0817a150122b 983 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 984 else if (pktType == PACKET_TYPE_FLRC)
Wayne Roberts 1:0817a150122b 985 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppFLRC.buf);
Wayne Roberts 1:0817a150122b 986
Wayne Roberts 1:0817a150122b 987 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 988 }
Wayne Roberts 1:0817a150122b 989
Wayne Roberts 2:ea9245bb1c53 990 const dropdown_item_t Radio::gfsk_flrc_crclen_item = { _ITEM_DROPDOWN, gfsk_flrc_crclens, gfsk_flrc_crclens, gfsk_flrc_crclen_read, gfsk_flrc_crclen_write};
Wayne Roberts 1:0817a150122b 991
Wayne Roberts 1:0817a150122b 992 bool Radio::gfsk_flrc_whit_read()
Wayne Roberts 1:0817a150122b 993 {
Wayne Roberts 1:0817a150122b 994 PktBitStreamCtrl_t PktBitStreamCtrl;
Wayne Roberts 1:0817a150122b 995 PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 996 ppGFSK.gfskFLRC.Whitening = PktBitStreamCtrl.octet & 0x08;
Wayne Roberts 1:0817a150122b 997 ppFLRC.gfskFLRC.Whitening = PktBitStreamCtrl.octet & 0x08;
Wayne Roberts 1:0817a150122b 998 return PktBitStreamCtrl.bits.whit_disable;
Wayne Roberts 1:0817a150122b 999 }
Wayne Roberts 1:0817a150122b 1000
Wayne Roberts 1:0817a150122b 1001 bool Radio::gfsk_flrc_whit_push()
Wayne Roberts 1:0817a150122b 1002 {
Wayne Roberts 1:0817a150122b 1003 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 1004
Wayne Roberts 1:0817a150122b 1005 if (ppGFSK.gfskFLRC.Whitening == WHITENING_DISABLE)
Wayne Roberts 1:0817a150122b 1006 ppGFSK.gfskFLRC.Whitening = WHITENING_ENABLE;
Wayne Roberts 1:0817a150122b 1007 else
Wayne Roberts 1:0817a150122b 1008 ppGFSK.gfskFLRC.Whitening = WHITENING_DISABLE;
Wayne Roberts 1:0817a150122b 1009
Wayne Roberts 1:0817a150122b 1010 ppFLRC.gfskFLRC.Whitening = ppGFSK.gfskFLRC.Whitening;
Wayne Roberts 1:0817a150122b 1011
Wayne Roberts 1:0817a150122b 1012 if (pktType == PACKET_TYPE_GFSK)
Wayne Roberts 1:0817a150122b 1013 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1014 else if (pktType == PACKET_TYPE_FLRC)
Wayne Roberts 1:0817a150122b 1015 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppFLRC.buf);
Wayne Roberts 1:0817a150122b 1016
Wayne Roberts 1:0817a150122b 1017 return ppGFSK.gfskFLRC.Whitening == WHITENING_DISABLE;
Wayne Roberts 1:0817a150122b 1018 }
Wayne Roberts 1:0817a150122b 1019
Wayne Roberts 1:0817a150122b 1020 const toggle_item_t Radio::gfsk_flrc_whit_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1021 "ENABLE ",
Wayne Roberts 1:0817a150122b 1022 "DISABLE",
Wayne Roberts 1:0817a150122b 1023 gfsk_flrc_whit_read, gfsk_flrc_whit_push
Wayne Roberts 1:0817a150122b 1024 };
Wayne Roberts 1:0817a150122b 1025
Wayne Roberts 1:0817a150122b 1026 void Radio::gfsk_flrc_crcinit_print()
Wayne Roberts 1:0817a150122b 1027 {
Wayne Roberts 1:0817a150122b 1028 unsigned val = radio.readReg(0x9c8, 2);
dudmuck 13:8ce61a1897ab 1029 printf("0x%04x", val);
Wayne Roberts 1:0817a150122b 1030 }
Wayne Roberts 1:0817a150122b 1031
Wayne Roberts 1:0817a150122b 1032 bool Radio::gfsk_flrc_crcinit_write(const char* txt)
Wayne Roberts 1:0817a150122b 1033 {
Wayne Roberts 1:0817a150122b 1034 unsigned val;
Wayne Roberts 1:0817a150122b 1035 sscanf(txt, "%x", &val);
Wayne Roberts 1:0817a150122b 1036 radio.writeReg(0x9c8, val, 2);
Wayne Roberts 1:0817a150122b 1037 return false;
Wayne Roberts 1:0817a150122b 1038 }
Wayne Roberts 1:0817a150122b 1039
Wayne Roberts 1:0817a150122b 1040 const value_item_t Radio::gfsk_flrc_crcinit_item = { _ITEM_VALUE, 7, gfsk_flrc_crcinit_print, gfsk_flrc_crcinit_write };
Wayne Roberts 1:0817a150122b 1041
Wayne Roberts 1:0817a150122b 1042 void Radio::gfsk_flrc_crcpoly_print(void)
Wayne Roberts 1:0817a150122b 1043 {
Wayne Roberts 1:0817a150122b 1044 unsigned val = radio.readReg(0x9c6, 2);
dudmuck 13:8ce61a1897ab 1045 printf("0x%04x", val);
Wayne Roberts 1:0817a150122b 1046 }
Wayne Roberts 1:0817a150122b 1047
Wayne Roberts 1:0817a150122b 1048 bool Radio::gfsk_flrc_crcpoly_write(const char* txt)
Wayne Roberts 1:0817a150122b 1049 {
Wayne Roberts 1:0817a150122b 1050 unsigned val;
Wayne Roberts 1:0817a150122b 1051 sscanf(txt, "%x", &val);
Wayne Roberts 1:0817a150122b 1052 radio.writeReg(0x9c6, val, 2);
Wayne Roberts 1:0817a150122b 1053 return false;
Wayne Roberts 1:0817a150122b 1054 }
Wayne Roberts 1:0817a150122b 1055
Wayne Roberts 1:0817a150122b 1056 const value_item_t Radio::gfsk_flrc_crcpoly_item = { _ITEM_VALUE, 7, gfsk_flrc_crcpoly_print, gfsk_flrc_crcpoly_write };
Wayne Roberts 1:0817a150122b 1057
Wayne Roberts 1:0817a150122b 1058 bool Radio::gfsk_flrc_sync1en_read()
Wayne Roberts 1:0817a150122b 1059 {
Wayne Roberts 1:0817a150122b 1060 PktSyncAdrs_t PktSyncAdrs;
Wayne Roberts 1:0817a150122b 1061 PktSyncAdrs.octet = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1);
Wayne Roberts 1:0817a150122b 1062
Wayne Roberts 1:0817a150122b 1063 ppGFSK.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1064 ppFLRC.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1065
Wayne Roberts 1:0817a150122b 1066 return PktSyncAdrs.gfskflrc.sync_addr_mask & 1;
Wayne Roberts 1:0817a150122b 1067 }
Wayne Roberts 1:0817a150122b 1068
Wayne Roberts 1:0817a150122b 1069 bool Radio::gfsk_flrc_sync2en_read()
Wayne Roberts 1:0817a150122b 1070 {
Wayne Roberts 1:0817a150122b 1071 PktSyncAdrs_t PktSyncAdrs;
Wayne Roberts 1:0817a150122b 1072 PktSyncAdrs.octet = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1);
Wayne Roberts 1:0817a150122b 1073
Wayne Roberts 1:0817a150122b 1074 ppGFSK.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1075 ppFLRC.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1076
Wayne Roberts 1:0817a150122b 1077 return ppGFSK.gfskFLRC.SyncWordMatch & 0x20;
Wayne Roberts 1:0817a150122b 1078 }
Wayne Roberts 1:0817a150122b 1079
Wayne Roberts 1:0817a150122b 1080 bool Radio::gfsk_flrc_sync3en_read()
Wayne Roberts 1:0817a150122b 1081 {
Wayne Roberts 1:0817a150122b 1082 PktSyncAdrs_t PktSyncAdrs;
Wayne Roberts 1:0817a150122b 1083 PktSyncAdrs.octet = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1);
Wayne Roberts 1:0817a150122b 1084
Wayne Roberts 1:0817a150122b 1085 ppGFSK.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1086 ppFLRC.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1087
Wayne Roberts 1:0817a150122b 1088 return ppGFSK.gfskFLRC.SyncWordMatch & 0x40;
Wayne Roberts 1:0817a150122b 1089 //return PktSyncAdrs.gfskflrc.sync_addr_mask & 4;
Wayne Roberts 1:0817a150122b 1090 }
Wayne Roberts 1:0817a150122b 1091
Wayne Roberts 1:0817a150122b 1092 bool Radio::gfsk_flrc_sync1en_push()
Wayne Roberts 1:0817a150122b 1093 {
Wayne Roberts 1:0817a150122b 1094 if (ppGFSK.gfskFLRC.SyncWordMatch & 0x10)
Wayne Roberts 1:0817a150122b 1095 ppGFSK.gfskFLRC.SyncWordMatch &= ~0x10;
Wayne Roberts 1:0817a150122b 1096 else
Wayne Roberts 1:0817a150122b 1097 ppGFSK.gfskFLRC.SyncWordMatch |= 0x10;
Wayne Roberts 1:0817a150122b 1098
Wayne Roberts 1:0817a150122b 1099 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1100
Wayne Roberts 1:0817a150122b 1101 ppFLRC.gfskFLRC.SyncWordMatch = ppGFSK.gfskFLRC.SyncWordMatch;
Wayne Roberts 1:0817a150122b 1102
Wayne Roberts 1:0817a150122b 1103 return ppGFSK.gfskFLRC.SyncWordMatch & 0x10;
Wayne Roberts 1:0817a150122b 1104 }
Wayne Roberts 1:0817a150122b 1105
Wayne Roberts 1:0817a150122b 1106 bool Radio::gfsk_flrc_sync2en_push()
Wayne Roberts 1:0817a150122b 1107 {
Wayne Roberts 1:0817a150122b 1108 if (ppGFSK.gfskFLRC.SyncWordMatch & 0x20)
Wayne Roberts 1:0817a150122b 1109 ppGFSK.gfskFLRC.SyncWordMatch &= ~0x20;
Wayne Roberts 1:0817a150122b 1110 else
Wayne Roberts 1:0817a150122b 1111 ppGFSK.gfskFLRC.SyncWordMatch |= 0x20;
Wayne Roberts 1:0817a150122b 1112
Wayne Roberts 1:0817a150122b 1113 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1114
Wayne Roberts 1:0817a150122b 1115 ppFLRC.gfskFLRC.SyncWordMatch = ppGFSK.gfskFLRC.SyncWordMatch;
Wayne Roberts 1:0817a150122b 1116
Wayne Roberts 1:0817a150122b 1117 return ppGFSK.gfskFLRC.SyncWordMatch & 0x20;
Wayne Roberts 1:0817a150122b 1118 }
Wayne Roberts 1:0817a150122b 1119
Wayne Roberts 1:0817a150122b 1120 bool Radio::gfsk_flrc_sync3en_push()
Wayne Roberts 1:0817a150122b 1121 {
Wayne Roberts 1:0817a150122b 1122 if (ppGFSK.gfskFLRC.SyncWordMatch & 0x40)
Wayne Roberts 1:0817a150122b 1123 ppGFSK.gfskFLRC.SyncWordMatch &= ~0x40;
Wayne Roberts 1:0817a150122b 1124 else
Wayne Roberts 1:0817a150122b 1125 ppGFSK.gfskFLRC.SyncWordMatch |= 0x40;
Wayne Roberts 1:0817a150122b 1126
Wayne Roberts 1:0817a150122b 1127 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1128
Wayne Roberts 1:0817a150122b 1129 ppFLRC.gfskFLRC.SyncWordMatch = ppGFSK.gfskFLRC.SyncWordMatch;
Wayne Roberts 1:0817a150122b 1130
Wayne Roberts 1:0817a150122b 1131 return ppGFSK.gfskFLRC.SyncWordMatch & 0x40;
Wayne Roberts 1:0817a150122b 1132 }
Wayne Roberts 1:0817a150122b 1133
Wayne Roberts 1:0817a150122b 1134 const toggle_item_t Radio::gfsk_flrc_sync1en_item = { _ITEM_TOGGLE, "off:", " ON:", gfsk_flrc_sync1en_read, gfsk_flrc_sync1en_push};
Wayne Roberts 1:0817a150122b 1135 const toggle_item_t Radio::gfsk_flrc_sync2en_item = { _ITEM_TOGGLE, "off:", " ON:", gfsk_flrc_sync2en_read, gfsk_flrc_sync2en_push};
Wayne Roberts 1:0817a150122b 1136 const toggle_item_t Radio::gfsk_flrc_sync3en_item = { _ITEM_TOGGLE, "off:", " ON:", gfsk_flrc_sync3en_read, gfsk_flrc_sync3en_push};
Wayne Roberts 1:0817a150122b 1137
Wayne Roberts 1:0817a150122b 1138 void Radio::gfsk_flrc_sync1_print(void)
Wayne Roberts 1:0817a150122b 1139 {
Wayne Roberts 1:0817a150122b 1140 uint64_t val;
Wayne Roberts 1:0817a150122b 1141 uint32_t val32 = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_1+1, 4);
Wayne Roberts 1:0817a150122b 1142 uint32_t upper = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_1, 1);
Wayne Roberts 1:0817a150122b 1143 val = upper;
Wayne Roberts 1:0817a150122b 1144 val <<= 32;
Wayne Roberts 1:0817a150122b 1145 val |= val32;
dudmuck 13:8ce61a1897ab 1146 printf("%llx", val);
Wayne Roberts 1:0817a150122b 1147 }
Wayne Roberts 1:0817a150122b 1148
Wayne Roberts 1:0817a150122b 1149 void Radio::gfsk_flrc_sync2_print(void)
Wayne Roberts 1:0817a150122b 1150 {
Wayne Roberts 1:0817a150122b 1151 uint64_t val;
Wayne Roberts 1:0817a150122b 1152 uint32_t val32 = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_2+1, 4);
Wayne Roberts 1:0817a150122b 1153 uint32_t upper = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_2, 1);
Wayne Roberts 1:0817a150122b 1154 val = upper;
Wayne Roberts 1:0817a150122b 1155 val <<= 32;
Wayne Roberts 1:0817a150122b 1156 val |= val32;
dudmuck 13:8ce61a1897ab 1157 printf("%llx", val);
Wayne Roberts 1:0817a150122b 1158 }
Wayne Roberts 1:0817a150122b 1159
Wayne Roberts 1:0817a150122b 1160 void Radio::gfsk_flrc_sync3_print(void)
Wayne Roberts 1:0817a150122b 1161 {
Wayne Roberts 1:0817a150122b 1162 uint64_t val;
Wayne Roberts 1:0817a150122b 1163 uint32_t val32 = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_3+1, 4);
Wayne Roberts 1:0817a150122b 1164 uint32_t upper = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_3, 1);
Wayne Roberts 1:0817a150122b 1165 val = upper;
Wayne Roberts 1:0817a150122b 1166 val <<= 32;
Wayne Roberts 1:0817a150122b 1167 val |= val32;
dudmuck 13:8ce61a1897ab 1168 printf("%llx", val);
Wayne Roberts 1:0817a150122b 1169 }
Wayne Roberts 1:0817a150122b 1170
Wayne Roberts 1:0817a150122b 1171 bool Radio::gfsk_flrc_sync1_write(const char* txt)
Wayne Roberts 1:0817a150122b 1172 {
Wayne Roberts 1:0817a150122b 1173 uint32_t val32, upper;
Wayne Roberts 1:0817a150122b 1174 uint64_t val;
Wayne Roberts 1:0817a150122b 1175 sscanf(txt, "%llx", &val);
Wayne Roberts 1:0817a150122b 1176
Wayne Roberts 1:0817a150122b 1177 val32 = val;
Wayne Roberts 1:0817a150122b 1178 val >>= 32;
Wayne Roberts 1:0817a150122b 1179 upper = val;
Wayne Roberts 1:0817a150122b 1180
Wayne Roberts 1:0817a150122b 1181 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_1, upper, 1);
Wayne Roberts 1:0817a150122b 1182 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_1+1, val32, 4);
Wayne Roberts 1:0817a150122b 1183
Wayne Roberts 1:0817a150122b 1184 return false;
Wayne Roberts 1:0817a150122b 1185 }
Wayne Roberts 1:0817a150122b 1186
Wayne Roberts 1:0817a150122b 1187 bool Radio::gfsk_flrc_sync2_write(const char* txt)
Wayne Roberts 1:0817a150122b 1188 {
Wayne Roberts 1:0817a150122b 1189 uint32_t val32, upper;
Wayne Roberts 1:0817a150122b 1190 uint64_t val;
Wayne Roberts 1:0817a150122b 1191 sscanf(txt, "%llx", &val);
Wayne Roberts 1:0817a150122b 1192
Wayne Roberts 1:0817a150122b 1193 val32 = val;
Wayne Roberts 1:0817a150122b 1194 val >>= 32;
Wayne Roberts 1:0817a150122b 1195 upper = val;
Wayne Roberts 1:0817a150122b 1196
Wayne Roberts 1:0817a150122b 1197 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_2, upper, 1);
Wayne Roberts 1:0817a150122b 1198 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_2+1, val32, 4);
Wayne Roberts 1:0817a150122b 1199
Wayne Roberts 1:0817a150122b 1200 return false;
Wayne Roberts 1:0817a150122b 1201 }
Wayne Roberts 1:0817a150122b 1202
Wayne Roberts 1:0817a150122b 1203 bool Radio::gfsk_flrc_sync3_write(const char* txt)
Wayne Roberts 1:0817a150122b 1204 {
Wayne Roberts 1:0817a150122b 1205 uint32_t val32, upper;
Wayne Roberts 1:0817a150122b 1206 uint64_t val;
Wayne Roberts 1:0817a150122b 1207 sscanf(txt, "%llx", &val);
Wayne Roberts 1:0817a150122b 1208
Wayne Roberts 1:0817a150122b 1209 val32 = val;
Wayne Roberts 1:0817a150122b 1210 val >>= 32;
Wayne Roberts 1:0817a150122b 1211 upper = val;
Wayne Roberts 1:0817a150122b 1212
Wayne Roberts 1:0817a150122b 1213 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_3, upper, 1);
Wayne Roberts 1:0817a150122b 1214 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_3+1, val32, 4);
Wayne Roberts 1:0817a150122b 1215
Wayne Roberts 1:0817a150122b 1216 return false;
Wayne Roberts 1:0817a150122b 1217 }
Wayne Roberts 1:0817a150122b 1218
Wayne Roberts 1:0817a150122b 1219 const value_item_t Radio::gfsk_flrc_sync1_item = { _ITEM_VALUE, 10, gfsk_flrc_sync1_print, gfsk_flrc_sync1_write };
Wayne Roberts 1:0817a150122b 1220 const value_item_t Radio::gfsk_flrc_sync2_item = { _ITEM_VALUE, 10, gfsk_flrc_sync2_print, gfsk_flrc_sync2_write };
Wayne Roberts 1:0817a150122b 1221 const value_item_t Radio::gfsk_flrc_sync3_item = { _ITEM_VALUE, 10, gfsk_flrc_sync3_print, gfsk_flrc_sync3_write };
Wayne Roberts 1:0817a150122b 1222
Wayne Roberts 1:0817a150122b 1223
Wayne Roberts 1:0817a150122b 1224 const menu_t Radio::gfsk_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1225 { {FIRST_CHIP_MENU_ROW+1, 1}, NULL, &gfsk_bitrate_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1226 { {FIRST_CHIP_MENU_ROW+1, 19}, "mod index:", &gfsk_modindex_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1227 { {FIRST_CHIP_MENU_ROW+1, 35}, "BT:", &gfsk_flrc_bt_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1228 { {FIRST_CHIP_MENU_ROW+1, 43}, "PreambleLength:", &gfsk_flrc_preamble_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1229 { {FIRST_CHIP_MENU_ROW+1, 61}, "SyncLength:", &gfsk_synclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1230
Wayne Roberts 4:fa31fdf4ec8d 1231 { {FIRST_CHIP_MENU_ROW+2, 1}, "Length:", &gfsk_flrc_fixvar_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1232 { {FIRST_CHIP_MENU_ROW+2, 18}, "crcLength:", &gfsk_flrc_crclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1233 { {FIRST_CHIP_MENU_ROW+2, 37}, "whitening:", &gfsk_flrc_whit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1234 { {FIRST_CHIP_MENU_ROW+2, 57}, "crcInit:", &gfsk_flrc_crcinit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1235 { {FIRST_CHIP_MENU_ROW+2, 72}, "poly:", &gfsk_flrc_crcpoly_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1236
Wayne Roberts 4:fa31fdf4ec8d 1237 { {FIRST_CHIP_MENU_ROW+3, 1}, "sync1 ", &gfsk_flrc_sync1en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1238 { {FIRST_CHIP_MENU_ROW+3, 15}, NULL, &gfsk_flrc_sync1_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1239 { {FIRST_CHIP_MENU_ROW+3, 27}, "sync2 ", &gfsk_flrc_sync2en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1240 { {FIRST_CHIP_MENU_ROW+3, 41}, NULL, &gfsk_flrc_sync2_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1241 { {FIRST_CHIP_MENU_ROW+3, 53}, "sync3 ", &gfsk_flrc_sync3en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1242 { {FIRST_CHIP_MENU_ROW+3, 65}, NULL, &gfsk_flrc_sync3_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1243
Wayne Roberts 1:0817a150122b 1244 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1245 };
Wayne Roberts 1:0817a150122b 1246
Wayne Roberts 3:56fc764dee0a 1247 static const char* const flrc_bpsbw[] = {
Wayne Roberts 1:0817a150122b 1248 "2.6",
Wayne Roberts 1:0817a150122b 1249 "2.08",
Wayne Roberts 1:0817a150122b 1250 "1.3Mb/s 1.2MHz",
Wayne Roberts 1:0817a150122b 1251 "1.04Mb/s 1.2MHz",
Wayne Roberts 1:0817a150122b 1252 "0.65Mb/s 0.6MHz",
Wayne Roberts 1:0817a150122b 1253 "0.52Mb/s 0.6MHz",
Wayne Roberts 1:0817a150122b 1254 "0.325Mb/s 0.3MHz",
Wayne Roberts 1:0817a150122b 1255 "0.26Mb/s 0.3MHz",
Wayne Roberts 1:0817a150122b 1256 NULL
Wayne Roberts 1:0817a150122b 1257 };
Wayne Roberts 1:0817a150122b 1258
Wayne Roberts 2:ea9245bb1c53 1259 const dropdown_item_t Radio::flrc_bitrate_item = { _ITEM_DROPDOWN, flrc_bpsbw, flrc_bpsbw, gfsk_flrc_bpsbw_read, gfsk_flrc_bpsbw_write};
Wayne Roberts 1:0817a150122b 1260
Wayne Roberts 3:56fc764dee0a 1261 static const char* const flrc_crs[] = {
Wayne Roberts 1:0817a150122b 1262 "1/2",
Wayne Roberts 1:0817a150122b 1263 "3/4",
Wayne Roberts 1:0817a150122b 1264 "1 ",
Wayne Roberts 1:0817a150122b 1265 NULL
Wayne Roberts 1:0817a150122b 1266 };
Wayne Roberts 2:ea9245bb1c53 1267 unsigned Radio::flrc_cr_read(bool fw)
Wayne Roberts 1:0817a150122b 1268 {
Wayne Roberts 1:0817a150122b 1269 PktBitStreamCtrl_t PktBitStreamCtrl;
Wayne Roberts 1:0817a150122b 1270 PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 1271
Wayne Roberts 1:0817a150122b 1272 mpFLRC.flrc.CodingRate = PktBitStreamCtrl.octet & 0x06; // PktBitStreamCtrl.bits.flora_coding_rate
Wayne Roberts 1:0817a150122b 1273
Wayne Roberts 1:0817a150122b 1274 return PktBitStreamCtrl.bits.flora_coding_rate;
Wayne Roberts 1:0817a150122b 1275 }
Wayne Roberts 1:0817a150122b 1276
Wayne Roberts 2:ea9245bb1c53 1277 menuMode_e Radio::flrc_cr_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1278 {
Wayne Roberts 1:0817a150122b 1279 mpFLRC.flrc.CodingRate = sidx << 1;
Wayne Roberts 1:0817a150122b 1280 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpFLRC.buf);
Wayne Roberts 1:0817a150122b 1281 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1282 }
Wayne Roberts 1:0817a150122b 1283
Wayne Roberts 2:ea9245bb1c53 1284 const dropdown_item_t Radio::flrc_cr_item = { _ITEM_DROPDOWN, flrc_crs, flrc_crs, flrc_cr_read, flrc_cr_write};
Wayne Roberts 1:0817a150122b 1285
Wayne Roberts 3:56fc764dee0a 1286 static const char* const flrc_syncLens[] = {
Wayne Roberts 1:0817a150122b 1287 "SYNC OFF ",
Wayne Roberts 1:0817a150122b 1288 "16BIT SYNC",
Wayne Roberts 1:0817a150122b 1289 "32BIT SYNC",
Wayne Roberts 1:0817a150122b 1290 NULL
Wayne Roberts 1:0817a150122b 1291 };
Wayne Roberts 1:0817a150122b 1292
Wayne Roberts 2:ea9245bb1c53 1293 unsigned Radio::flrc_synclen_read(bool fw)
Wayne Roberts 1:0817a150122b 1294 {
Wayne Roberts 1:0817a150122b 1295 PktCtrl1_t PktCtrl1;
Wayne Roberts 1:0817a150122b 1296 PktCtrl1.octet = radio.readReg(REG_ADDR_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 1297 ppFLRC.gfskFLRC.SyncWordLength = PktCtrl1.octet & 0x06;
Wayne Roberts 1:0817a150122b 1298 if (ppFLRC.gfskFLRC.SyncWordLength == 0x06) {
Wayne Roberts 1:0817a150122b 1299 ppFLRC.gfskFLRC.SyncWordLength = FLRC_SYNC_WORD_LEN_P32S;
Wayne Roberts 1:0817a150122b 1300 return 2;
Wayne Roberts 1:0817a150122b 1301 }
Wayne Roberts 1:0817a150122b 1302
Wayne Roberts 1:0817a150122b 1303 return PktCtrl1.flrc.sync_adrs_len;
Wayne Roberts 1:0817a150122b 1304 }
Wayne Roberts 1:0817a150122b 1305
Wayne Roberts 2:ea9245bb1c53 1306 menuMode_e Radio::flrc_synclen_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1307 {
Wayne Roberts 1:0817a150122b 1308 ppFLRC.gfskFLRC.SyncWordLength = sidx << 1;
Wayne Roberts 1:0817a150122b 1309 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppFLRC.buf);
Wayne Roberts 1:0817a150122b 1310 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1311 }
Wayne Roberts 1:0817a150122b 1312
Wayne Roberts 2:ea9245bb1c53 1313 const dropdown_item_t Radio::flrc_synclen_item = { _ITEM_DROPDOWN, flrc_syncLens, flrc_syncLens, flrc_synclen_read, flrc_synclen_write};
Wayne Roberts 1:0817a150122b 1314
Wayne Roberts 1:0817a150122b 1315
Wayne Roberts 1:0817a150122b 1316 const menu_t Radio::flrc_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1317 { {FIRST_CHIP_MENU_ROW+1, 1}, NULL, &flrc_bitrate_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1318 { {FIRST_CHIP_MENU_ROW+1, 20}, "cr:", &flrc_cr_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1319 { {FIRST_CHIP_MENU_ROW+1, 27}, "BT:", &gfsk_flrc_bt_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1320 { {FIRST_CHIP_MENU_ROW+1, 34}, "PreambleLength:", &gfsk_flrc_preamble_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1321 { {FIRST_CHIP_MENU_ROW+1, 52}, "SyncLength:", &flrc_synclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1322
Wayne Roberts 4:fa31fdf4ec8d 1323 { {FIRST_CHIP_MENU_ROW+2, 1}, "Length:", &gfsk_flrc_fixvar_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1324 { {FIRST_CHIP_MENU_ROW+2, 18}, "crcLength:", &gfsk_flrc_crclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1325 { {FIRST_CHIP_MENU_ROW+2, 38}, "whitening:", &gfsk_flrc_whit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1326 { {FIRST_CHIP_MENU_ROW+2, 58}, "crcInit:", &gfsk_flrc_crcinit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1327 { {FIRST_CHIP_MENU_ROW+2, 73}, "poly:", &gfsk_flrc_crcpoly_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1328
Wayne Roberts 4:fa31fdf4ec8d 1329 { {FIRST_CHIP_MENU_ROW+3, 1}, "sync1 ", &gfsk_flrc_sync1en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1330 { {FIRST_CHIP_MENU_ROW+3, 12}, NULL, &gfsk_flrc_sync1_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1331 { {FIRST_CHIP_MENU_ROW+3, 24}, "sync2 ", &gfsk_flrc_sync2en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1332 { {FIRST_CHIP_MENU_ROW+3, 35}, NULL, &gfsk_flrc_sync2_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1333 { {FIRST_CHIP_MENU_ROW+3, 47}, "sync3 ", &gfsk_flrc_sync3en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1334 { {FIRST_CHIP_MENU_ROW+3, 59}, NULL, &gfsk_flrc_sync3_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1335
Wayne Roberts 1:0817a150122b 1336 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1337 };
Wayne Roberts 1:0817a150122b 1338
Wayne Roberts 3:56fc764dee0a 1339 bool Radio::manualRngDelay;
Wayne Roberts 3:56fc764dee0a 1340 const uint16_t Radio::rngDelays[3][6] = {
Wayne Roberts 3:56fc764dee0a 1341 10299, 10271, 10244, 10242, 10230, 10246,
Wayne Roberts 3:56fc764dee0a 1342 11486, 11474, 11453, 11426, 11417, 11401,
Wayne Roberts 3:56fc764dee0a 1343 13308, 13493, 13528, 13515, 13430, 13376
Wayne Roberts 3:56fc764dee0a 1344 };
Wayne Roberts 3:56fc764dee0a 1345
Wayne Roberts 3:56fc764dee0a 1346 void Radio::rngUpdateDelayCal()
Wayne Roberts 3:56fc764dee0a 1347 {
Wayne Roberts 3:56fc764dee0a 1348 LoRaPktPar0.octet = radio.readReg(REG_ADDR_LORA_PKTPAR0, 1);
Wayne Roberts 3:56fc764dee0a 1349
Wayne Roberts 3:56fc764dee0a 1350 if (LoRaPktPar0.bits.modem_bw > 2 && LoRaPktPar0.bits.modem_sf < 11) {
Wayne Roberts 3:56fc764dee0a 1351 uint32_t delayCal = radio.readReg(REG_ADDR_LORA_DELAY_CAL, 3);
Wayne Roberts 3:56fc764dee0a 1352 delayCal &= ~0x3fffff;
Wayne Roberts 3:56fc764dee0a 1353 delayCal |= rngDelays[LoRaPktPar0.bits.modem_bw-3][LoRaPktPar0.bits.modem_sf-5];
Wayne Roberts 3:56fc764dee0a 1354 /*log_printf("%u = rngDelays[%u][%u]\r\n",
Wayne Roberts 3:56fc764dee0a 1355 rngDelays[LoRaPktPar0.bits.modem_bw-3][LoRaPktPar0.bits.modem_sf-5],
Wayne Roberts 3:56fc764dee0a 1356 LoRaPktPar0.bits.modem_bw-3, LoRaPktPar0.bits.modem_sf-5
Wayne Roberts 3:56fc764dee0a 1357 );*/
Wayne Roberts 3:56fc764dee0a 1358 radio.writeReg(REG_ADDR_LORA_DELAY_CAL, delayCal, 3);
Wayne Roberts 3:56fc764dee0a 1359 }
Wayne Roberts 3:56fc764dee0a 1360 }
Wayne Roberts 3:56fc764dee0a 1361
Wayne Roberts 3:56fc764dee0a 1362 static const char* const lora_bws[] = {
Wayne Roberts 1:0817a150122b 1363 " 50KHz", // 0
Wayne Roberts 1:0817a150122b 1364 " 100KHz", // 1
Wayne Roberts 1:0817a150122b 1365 " 200KHz", // 2
Wayne Roberts 1:0817a150122b 1366 " 400KHz", // 3
Wayne Roberts 1:0817a150122b 1367 " 800KHz", // 4
Wayne Roberts 1:0817a150122b 1368 "1600KHz", // 5
Wayne Roberts 1:0817a150122b 1369 NULL
Wayne Roberts 1:0817a150122b 1370 };
Wayne Roberts 1:0817a150122b 1371
Wayne Roberts 3:56fc764dee0a 1372 const float Radio::bwMHzs[] = { 0.05, 0.1, 0.2, 0.4, 0.8, 1.6 };
Wayne Roberts 3:56fc764dee0a 1373
Wayne Roberts 3:56fc764dee0a 1374 LoRaPktPar0_t Radio::LoRaPktPar0;
Wayne Roberts 3:56fc764dee0a 1375
Wayne Roberts 1:0817a150122b 1376 unsigned Radio::lora_bw_read(bool fw)
Wayne Roberts 1:0817a150122b 1377 {
Wayne Roberts 1:0817a150122b 1378 LoRaPktPar0.octet = radio.readReg(REG_ADDR_LORA_PKTPAR0, 1);
Wayne Roberts 1:0817a150122b 1379
Wayne Roberts 1:0817a150122b 1380 return LoRaPktPar0.bits.modem_bw;
Wayne Roberts 1:0817a150122b 1381 }
Wayne Roberts 1:0817a150122b 1382
Wayne Roberts 1:0817a150122b 1383 menuMode_e Radio::lora_bw_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1384 {
Wayne Roberts 1:0817a150122b 1385 switch (sidx) {
Wayne Roberts 1:0817a150122b 1386 case 0: mpLORA.lora.bandwidth = LORA_BW_50; break;
Wayne Roberts 1:0817a150122b 1387 case 1: mpLORA.lora.bandwidth = LORA_BW_100; break;
Wayne Roberts 1:0817a150122b 1388 case 2: mpLORA.lora.bandwidth = LORA_BW_200; break;
Wayne Roberts 1:0817a150122b 1389 case 3: mpLORA.lora.bandwidth = LORA_BW_400; break;
Wayne Roberts 1:0817a150122b 1390 case 4: mpLORA.lora.bandwidth = LORA_BW_800; break;
Wayne Roberts 1:0817a150122b 1391 case 5: mpLORA.lora.bandwidth = LORA_BW_1600; break;
Wayne Roberts 1:0817a150122b 1392 }
Wayne Roberts 1:0817a150122b 1393 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 1394
Wayne Roberts 3:56fc764dee0a 1395 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 1396 manualRngDelay = false;
Wayne Roberts 3:56fc764dee0a 1397 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 1398 }
Wayne Roberts 3:56fc764dee0a 1399
Wayne Roberts 1:0817a150122b 1400 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1401 }
Wayne Roberts 1:0817a150122b 1402
Wayne Roberts 1:0817a150122b 1403 const dropdown_item_t Radio::lora_bw_item = { _ITEM_DROPDOWN, lora_bws, lora_bws, lora_bw_read, lora_bw_write};
Wayne Roberts 1:0817a150122b 1404
Wayne Roberts 1:0817a150122b 1405 void Radio::lora_sf_print()
Wayne Roberts 1:0817a150122b 1406 {
Wayne Roberts 1:0817a150122b 1407 LoRaPktPar0.octet = radio.readReg(REG_ADDR_LORA_PKTPAR0, 1);
Wayne Roberts 1:0817a150122b 1408
dudmuck 13:8ce61a1897ab 1409 printf("%u", LoRaPktPar0.bits.modem_sf);
Wayne Roberts 1:0817a150122b 1410 }
Wayne Roberts 1:0817a150122b 1411
Wayne Roberts 1:0817a150122b 1412 bool Radio::lora_sf_write(const char* str)
Wayne Roberts 1:0817a150122b 1413 {
Wayne Roberts 1:0817a150122b 1414 unsigned n;
Wayne Roberts 1:0817a150122b 1415 if (sscanf(str, "%u", &n) == 1) {
Wayne Roberts 1:0817a150122b 1416 mpLORA.lora.spreadingFactor = n << 4;
Wayne Roberts 1:0817a150122b 1417 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf);
Wayne Roberts 3:56fc764dee0a 1418
Wayne Roberts 3:56fc764dee0a 1419 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 1420 manualRngDelay = false;
Wayne Roberts 3:56fc764dee0a 1421 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 1422 }
Wayne Roberts 1:0817a150122b 1423 }
Wayne Roberts 1:0817a150122b 1424 return false;
Wayne Roberts 1:0817a150122b 1425 }
Wayne Roberts 1:0817a150122b 1426
Wayne Roberts 1:0817a150122b 1427 const value_item_t Radio::lora_sf_item = { _ITEM_VALUE, 3, lora_sf_print, lora_sf_write };
Wayne Roberts 1:0817a150122b 1428
Wayne Roberts 3:56fc764dee0a 1429 static const char* const lora_crs[] = {
Wayne Roberts 1:0817a150122b 1430 "4/5 ",
Wayne Roberts 1:0817a150122b 1431 "4/6 ",
Wayne Roberts 1:0817a150122b 1432 "4/7 ",
Wayne Roberts 1:0817a150122b 1433 "4/8 ",
Wayne Roberts 1:0817a150122b 1434 "4/5 LI",
Wayne Roberts 1:0817a150122b 1435 "4/6 LI",
Wayne Roberts 1:0817a150122b 1436 "4/7 LI",
Wayne Roberts 1:0817a150122b 1437 NULL
Wayne Roberts 1:0817a150122b 1438 };
Wayne Roberts 1:0817a150122b 1439
Wayne Roberts 2:ea9245bb1c53 1440 unsigned Radio::lora_cr_read(bool fw)
Wayne Roberts 1:0817a150122b 1441 {
Wayne Roberts 1:0817a150122b 1442 LoRaPktPar1_t LoRaPktPar1;
Wayne Roberts 1:0817a150122b 1443 LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
Wayne Roberts 1:0817a150122b 1444 mpLORA.lora.codingRate = LoRaPktPar1.bits.coding_rate;
Wayne Roberts 1:0817a150122b 1445 return LoRaPktPar1.bits.coding_rate;
Wayne Roberts 1:0817a150122b 1446 }
Wayne Roberts 1:0817a150122b 1447
Wayne Roberts 2:ea9245bb1c53 1448 menuMode_e Radio::lora_cr_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1449 {
Wayne Roberts 1:0817a150122b 1450 mpLORA.lora.codingRate = sidx;
Wayne Roberts 1:0817a150122b 1451 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 1452 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1453 }
Wayne Roberts 1:0817a150122b 1454
Wayne Roberts 2:ea9245bb1c53 1455 const dropdown_item_t Radio::lora_cr_item = { _ITEM_DROPDOWN, lora_crs, lora_crs, lora_cr_read, lora_cr_write};
Wayne Roberts 1:0817a150122b 1456
Wayne Roberts 1:0817a150122b 1457 void Radio::lora_pblLen_print()
Wayne Roberts 1:0817a150122b 1458 {
Wayne Roberts 1:0817a150122b 1459 LoRaPreambleReg_t LoRaPreambleReg;
Wayne Roberts 1:0817a150122b 1460 LoRaPreambleReg.octet = radio.readReg(REG_ADDR_LORA_PREAMBLE, 1);
Wayne Roberts 1:0817a150122b 1461 ppLORA.lora.PreambleLength = (1 << LoRaPreambleReg.bits.preamble_symb_nb_exp) * LoRaPreambleReg.bits.preamble_symb1_nb;
dudmuck 13:8ce61a1897ab 1462 printf("%u", ppLORA.lora.PreambleLength);
Wayne Roberts 1:0817a150122b 1463 }
Wayne Roberts 1:0817a150122b 1464
Wayne Roberts 1:0817a150122b 1465 bool Radio::lora_pblLen_write(const char* str)
Wayne Roberts 1:0817a150122b 1466 {
Wayne Roberts 1:0817a150122b 1467 unsigned val, exp, mant;
Wayne Roberts 1:0817a150122b 1468 sscanf(str, "%u", &val);
Wayne Roberts 1:0817a150122b 1469
Wayne Roberts 1:0817a150122b 1470 for (exp = 0; exp < 16; exp++) {
Wayne Roberts 1:0817a150122b 1471 mant = val / (1 << exp);
Wayne Roberts 1:0817a150122b 1472 if (mant < 16)
Wayne Roberts 1:0817a150122b 1473 break;
Wayne Roberts 1:0817a150122b 1474 }
Wayne Roberts 1:0817a150122b 1475
Wayne Roberts 1:0817a150122b 1476 ppLORA.lora.PreambleLength = (exp << 4) + mant;
Wayne Roberts 1:0817a150122b 1477 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 5:1e5cb7139acb 1478
Wayne Roberts 1:0817a150122b 1479 return false;
Wayne Roberts 1:0817a150122b 1480 }
Wayne Roberts 1:0817a150122b 1481
Wayne Roberts 1:0817a150122b 1482 const value_item_t Radio::lora_pblLen_item = { _ITEM_VALUE, 5, lora_pblLen_print, lora_pblLen_write};
Wayne Roberts 1:0817a150122b 1483
Wayne Roberts 1:0817a150122b 1484 bool Radio::lora_fixlen_read()
Wayne Roberts 1:0817a150122b 1485 {
Wayne Roberts 1:0817a150122b 1486 LoRaPktPar1_t LoRaPktPar1;
Wayne Roberts 1:0817a150122b 1487 LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
Wayne Roberts 1:0817a150122b 1488 ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header ? IMPLICIT_HEADER : EXPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1489 return LoRaPktPar1.bits.implicit_header;
Wayne Roberts 1:0817a150122b 1490 }
Wayne Roberts 1:0817a150122b 1491
Wayne Roberts 1:0817a150122b 1492 bool Radio::lora_fixlen_push()
Wayne Roberts 1:0817a150122b 1493 {
Wayne Roberts 1:0817a150122b 1494 if (ppLORA.lora.HeaderType == EXPLICIT_HEADER)
Wayne Roberts 1:0817a150122b 1495 ppLORA.lora.HeaderType = IMPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1496 else
Wayne Roberts 1:0817a150122b 1497 ppLORA.lora.HeaderType = EXPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1498
Wayne Roberts 1:0817a150122b 1499 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 6:44a9df0e7855 1500 return ppLORA.lora.HeaderType == IMPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1501 }
Wayne Roberts 1:0817a150122b 1502
Wayne Roberts 1:0817a150122b 1503 const toggle_item_t Radio::lora_fixlen_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1504 "EXPLICIT", // 0
Wayne Roberts 1:0817a150122b 1505 "IMPLICIT", // 1
Wayne Roberts 1:0817a150122b 1506 lora_fixlen_read, lora_fixlen_push
Wayne Roberts 1:0817a150122b 1507 };
Wayne Roberts 1:0817a150122b 1508
Wayne Roberts 1:0817a150122b 1509 bool Radio::lora_crcon_read()
Wayne Roberts 1:0817a150122b 1510 {
Wayne Roberts 1:0817a150122b 1511 LoRaLrCtl_t LoRaLrCtl;
Wayne Roberts 1:0817a150122b 1512 LoRaLrCtl.octet = radio.readReg(REG_ADDR_LORA_LRCTL, 1);
Wayne Roberts 1:0817a150122b 1513 ppLORA.lora.crc = LoRaLrCtl.octet & 0x20; // LoRaLrCtl.bits.crc_en
Wayne Roberts 1:0817a150122b 1514 return LoRaLrCtl.bits.crc_en;
Wayne Roberts 1:0817a150122b 1515 }
Wayne Roberts 1:0817a150122b 1516
Wayne Roberts 1:0817a150122b 1517 bool Radio::lora_crcon_push()
Wayne Roberts 1:0817a150122b 1518 {
Wayne Roberts 1:0817a150122b 1519 if (ppLORA.lora.crc == LORA_CRC_ENABLE)
Wayne Roberts 1:0817a150122b 1520 ppLORA.lora.crc = LORA_CRC_DISABLE;
Wayne Roberts 1:0817a150122b 1521 else
Wayne Roberts 1:0817a150122b 1522 ppLORA.lora.crc = LORA_CRC_ENABLE;
Wayne Roberts 1:0817a150122b 1523
Wayne Roberts 1:0817a150122b 1524 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 1525
Wayne Roberts 1:0817a150122b 1526 return ppLORA.lora.crc == LORA_CRC_ENABLE;
Wayne Roberts 1:0817a150122b 1527 }
Wayne Roberts 1:0817a150122b 1528
Wayne Roberts 1:0817a150122b 1529 const toggle_item_t Radio::lora_crcon_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1530 "CRC_DISABLE", // 0
Wayne Roberts 1:0817a150122b 1531 "CRC_ENABLE ", // 1
Wayne Roberts 1:0817a150122b 1532 lora_crcon_read, lora_crcon_push
Wayne Roberts 1:0817a150122b 1533 };
Wayne Roberts 1:0817a150122b 1534
Wayne Roberts 1:0817a150122b 1535 bool Radio::lora_iqinv_read()
Wayne Roberts 1:0817a150122b 1536 {
Wayne Roberts 1:0817a150122b 1537 LoRaPktPar1_t LoRaPktPar1;
Wayne Roberts 1:0817a150122b 1538 LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
Wayne Roberts 1:0817a150122b 1539 ppLORA.lora.InvertIQ = LoRaPktPar1.bits.rxinvert_iq ? LORA_IQ_STD : LORA_IQ_INVERTED;
Wayne Roberts 1:0817a150122b 1540 return LoRaPktPar1.bits.rxinvert_iq ? 0 : 1;
Wayne Roberts 1:0817a150122b 1541 }
Wayne Roberts 1:0817a150122b 1542
Wayne Roberts 1:0817a150122b 1543 bool Radio::lora_iqinv_push()
Wayne Roberts 1:0817a150122b 1544 {
Wayne Roberts 1:0817a150122b 1545 if (ppLORA.lora.InvertIQ == LORA_IQ_STD)
Wayne Roberts 1:0817a150122b 1546 ppLORA.lora.InvertIQ = LORA_IQ_INVERTED;
Wayne Roberts 1:0817a150122b 1547 else
Wayne Roberts 1:0817a150122b 1548 ppLORA.lora.InvertIQ = LORA_IQ_STD;
Wayne Roberts 1:0817a150122b 1549
Wayne Roberts 1:0817a150122b 1550 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 1551
Wayne Roberts 6:44a9df0e7855 1552 return ppLORA.lora.InvertIQ == LORA_IQ_INVERTED;
Wayne Roberts 1:0817a150122b 1553 }
Wayne Roberts 1:0817a150122b 1554
Wayne Roberts 1:0817a150122b 1555 const toggle_item_t Radio::lora_iqinv_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1556 "IQ_STD", // 0
Wayne Roberts 1:0817a150122b 1557 "IQ_INV", // 1
Wayne Roberts 1:0817a150122b 1558 lora_iqinv_read, lora_iqinv_push
Wayne Roberts 1:0817a150122b 1559 };
Wayne Roberts 1:0817a150122b 1560
Wayne Roberts 3:56fc764dee0a 1561 void Radio::lora_ppg_print()
Wayne Roberts 3:56fc764dee0a 1562 {
Wayne Roberts 3:56fc764dee0a 1563 uint8_t val;
Wayne Roberts 3:56fc764dee0a 1564 ppg = radio.readReg(REG_ADDR_LORA_SYNC, 2);
Wayne Roberts 3:56fc764dee0a 1565
Wayne Roberts 3:56fc764dee0a 1566 val = (ppg >> 8) & 0xf0;
Wayne Roberts 3:56fc764dee0a 1567 val |= (ppg & 0xf0) >> 4;
dudmuck 13:8ce61a1897ab 1568 printf("%02x", val);
Wayne Roberts 3:56fc764dee0a 1569 }
Wayne Roberts 3:56fc764dee0a 1570
Wayne Roberts 3:56fc764dee0a 1571 bool Radio::lora_ppg_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1572 {
Wayne Roberts 3:56fc764dee0a 1573 unsigned val;
Wayne Roberts 3:56fc764dee0a 1574 if (sscanf(txt, "%x", &val) == 1) {
Wayne Roberts 3:56fc764dee0a 1575 ppg &= 0x0707;
Wayne Roberts 3:56fc764dee0a 1576 ppg |= (val & 0xf0) << 8;
Wayne Roberts 3:56fc764dee0a 1577 ppg |= (val & 0x0f) << 4;
Wayne Roberts 3:56fc764dee0a 1578 radio.writeReg(REG_ADDR_LORA_SYNC, ppg, 2);
Wayne Roberts 3:56fc764dee0a 1579 }
Wayne Roberts 3:56fc764dee0a 1580 return false;
Wayne Roberts 3:56fc764dee0a 1581 }
Wayne Roberts 3:56fc764dee0a 1582
Wayne Roberts 3:56fc764dee0a 1583 const value_item_t Radio::lora_ppg_item = { _ITEM_VALUE, 4, lora_ppg_print, lora_ppg_write};
Wayne Roberts 3:56fc764dee0a 1584
Wayne Roberts 2:ea9245bb1c53 1585 void Radio::cad_push()
Wayne Roberts 2:ea9245bb1c53 1586 {
Wayne Roberts 2:ea9245bb1c53 1587 radio.setCAD();
Wayne Roberts 2:ea9245bb1c53 1588 }
Wayne Roberts 2:ea9245bb1c53 1589
Wayne Roberts 2:ea9245bb1c53 1590 const button_item_t Radio::lora_cad_item = { _ITEM_BUTTON, "CAD", cad_push };
Wayne Roberts 2:ea9245bb1c53 1591
Wayne Roberts 3:56fc764dee0a 1592 static const char* const lora_cadsymbs[] = {
Wayne Roberts 2:ea9245bb1c53 1593 " 1",
Wayne Roberts 2:ea9245bb1c53 1594 " 2",
Wayne Roberts 2:ea9245bb1c53 1595 " 4",
Wayne Roberts 2:ea9245bb1c53 1596 " 8",
Wayne Roberts 2:ea9245bb1c53 1597 "16",
Wayne Roberts 2:ea9245bb1c53 1598 NULL
Wayne Roberts 2:ea9245bb1c53 1599 };
Wayne Roberts 2:ea9245bb1c53 1600
Wayne Roberts 2:ea9245bb1c53 1601 unsigned Radio::lora_cadsymbs_read(bool forWriting)
Wayne Roberts 2:ea9245bb1c53 1602 {
Wayne Roberts 2:ea9245bb1c53 1603 unsigned n = radio.readReg(REG_ADDR_LORA_FE_GAIN, 1);
Wayne Roberts 2:ea9245bb1c53 1604 return n >> 5;
Wayne Roberts 2:ea9245bb1c53 1605 }
Wayne Roberts 2:ea9245bb1c53 1606
Wayne Roberts 2:ea9245bb1c53 1607 menuMode_e Radio::lora_cadsymbs_write(unsigned sidx)
Wayne Roberts 2:ea9245bb1c53 1608 {
Wayne Roberts 2:ea9245bb1c53 1609 uint8_t buf = sidx << 5;
Wayne Roberts 2:ea9245bb1c53 1610 radio.xfer(OPCODE_SET_CAD_PARAM, 1, 0, &buf);
Wayne Roberts 2:ea9245bb1c53 1611 return MENUMODE_REDRAW;
Wayne Roberts 2:ea9245bb1c53 1612 }
Wayne Roberts 2:ea9245bb1c53 1613
Wayne Roberts 2:ea9245bb1c53 1614 const dropdown_item_t Radio::lora_cadsymbs_item = { _ITEM_DROPDOWN, lora_cadsymbs, lora_cadsymbs, lora_cadsymbs_read, lora_cadsymbs_write};
Wayne Roberts 2:ea9245bb1c53 1615
Wayne Roberts 1:0817a150122b 1616 const menu_t Radio::lora_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1617 { {FIRST_CHIP_MENU_ROW+1, 1}, NULL, &lora_bw_item, FLAG_MSGTYPE_ALL, &rng_delay_item},
Wayne Roberts 4:fa31fdf4ec8d 1618 { {FIRST_CHIP_MENU_ROW+1, 12}, "sf:", &lora_sf_item, FLAG_MSGTYPE_ALL, &rng_delay_item},
Wayne Roberts 4:fa31fdf4ec8d 1619 { {FIRST_CHIP_MENU_ROW+1, 20}, "cr:", &lora_cr_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1620 { {FIRST_CHIP_MENU_ROW+1, 30}, "PreambleLength:", &lora_pblLen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1621 { {FIRST_CHIP_MENU_ROW+2, 1}, NULL, &lora_fixlen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1622 { {FIRST_CHIP_MENU_ROW+2, 12}, NULL, &lora_crcon_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1623 { {FIRST_CHIP_MENU_ROW+2, 25}, NULL, &lora_iqinv_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1624 { {FIRST_CHIP_MENU_ROW+2, 35}, "ppg:", &lora_ppg_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 2:ea9245bb1c53 1625
Wayne Roberts 4:fa31fdf4ec8d 1626 { {FIRST_CHIP_MENU_ROW+3, 1}, NULL, &lora_cad_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1627 { {FIRST_CHIP_MENU_ROW+3, 5}, "symbols:", &lora_cadsymbs_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 2:ea9245bb1c53 1628
Wayne Roberts 1:0817a150122b 1629 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1630 };
Wayne Roberts 1:0817a150122b 1631
Wayne Roberts 3:56fc764dee0a 1632 bool Radio::tmp;
Wayne Roberts 3:56fc764dee0a 1633
Wayne Roberts 3:56fc764dee0a 1634 bool Radio::rng_role_read()
Wayne Roberts 3:56fc764dee0a 1635 {
Wayne Roberts 3:56fc764dee0a 1636 //RngCfg0_t RngCfg0;
Wayne Roberts 3:56fc764dee0a 1637 //RngCfg0.octet = radio.readReg(REG_ADDR_RNGCFG0, 1);
Wayne Roberts 3:56fc764dee0a 1638
Wayne Roberts 3:56fc764dee0a 1639 //return !RngCfg0.bits.ranging_resp_en;
Wayne Roberts 3:56fc764dee0a 1640 //log_printf("%02x ranging_resp_en: %u\r\n", RngCfg0.octet, RngCfg0.bits.ranging_resp_en);
Wayne Roberts 3:56fc764dee0a 1641 return tmp;
Wayne Roberts 3:56fc764dee0a 1642 }
Wayne Roberts 3:56fc764dee0a 1643
Wayne Roberts 3:56fc764dee0a 1644 bool Radio::rng_role_push()
Wayne Roberts 3:56fc764dee0a 1645 {
Wayne Roberts 3:56fc764dee0a 1646 uint8_t buf;
Wayne Roberts 3:56fc764dee0a 1647 /*
Wayne Roberts 3:56fc764dee0a 1648 RngCfg0_t RngCfg0;
Wayne Roberts 3:56fc764dee0a 1649 RngCfg0.octet = radio.readReg(REG_ADDR_RNGCFG0, 1);
Wayne Roberts 3:56fc764dee0a 1650
Wayne Roberts 3:56fc764dee0a 1651 buf = RngCfg0.bits.ranging_resp_en ? 0 : 1;
Wayne Roberts 3:56fc764dee0a 1652 log_printf("role %02x %u\r\n", RngCfg0.octet, buf);
Wayne Roberts 3:56fc764dee0a 1653 radio.xfer(OPCODE_SET_RANGING_ROLE, 1, 0, &buf);
Wayne Roberts 3:56fc764dee0a 1654 return buf;
Wayne Roberts 3:56fc764dee0a 1655 */
Wayne Roberts 3:56fc764dee0a 1656 tmp ^= true;
Wayne Roberts 3:56fc764dee0a 1657 buf = tmp;
Wayne Roberts 3:56fc764dee0a 1658 radio.xfer(OPCODE_SET_RANGING_ROLE, 1, 0, &buf);
Wayne Roberts 3:56fc764dee0a 1659 return tmp;
Wayne Roberts 3:56fc764dee0a 1660 }
Wayne Roberts 3:56fc764dee0a 1661
Wayne Roberts 3:56fc764dee0a 1662 const toggle_item_t Radio::rng_role_item = { _ITEM_TOGGLE,
Wayne Roberts 3:56fc764dee0a 1663 " SLAVE", // 0
Wayne Roberts 3:56fc764dee0a 1664 "MASTER", // 1
Wayne Roberts 3:56fc764dee0a 1665 rng_role_read, rng_role_push
Wayne Roberts 3:56fc764dee0a 1666 };
Wayne Roberts 3:56fc764dee0a 1667
Wayne Roberts 3:56fc764dee0a 1668 void Radio::rng_id_send_print()
Wayne Roberts 3:56fc764dee0a 1669 {
dudmuck 13:8ce61a1897ab 1670 printf("%08x", radio.readReg(REG_ADDR_LORA_MASTER_REQ_ID, 4));
Wayne Roberts 3:56fc764dee0a 1671 }
Wayne Roberts 3:56fc764dee0a 1672
Wayne Roberts 3:56fc764dee0a 1673 bool Radio::rng_id_send_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1674 {
Wayne Roberts 3:56fc764dee0a 1675 unsigned n;
Wayne Roberts 3:56fc764dee0a 1676 sscanf(txt, "%x", &n);
Wayne Roberts 3:56fc764dee0a 1677 radio.writeReg(REG_ADDR_LORA_MASTER_REQ_ID, n, 4);
Wayne Roberts 3:56fc764dee0a 1678 return false;
Wayne Roberts 3:56fc764dee0a 1679 }
Wayne Roberts 3:56fc764dee0a 1680
Wayne Roberts 3:56fc764dee0a 1681 const value_item_t Radio::rng_id_send_item = { _ITEM_VALUE, 9, rng_id_send_print, rng_id_send_write};
Wayne Roberts 3:56fc764dee0a 1682
Wayne Roberts 3:56fc764dee0a 1683 void Radio::rng_slave_id_print()
Wayne Roberts 3:56fc764dee0a 1684 {
dudmuck 13:8ce61a1897ab 1685 printf("%08x", radio.readReg(REG_ADDR_LORA_SLAVE_ID, 4));
Wayne Roberts 3:56fc764dee0a 1686 }
Wayne Roberts 3:56fc764dee0a 1687
Wayne Roberts 3:56fc764dee0a 1688 bool Radio::rng_slave_id_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1689 {
Wayne Roberts 3:56fc764dee0a 1690 unsigned n;
Wayne Roberts 3:56fc764dee0a 1691 sscanf(txt, "%x", &n);
Wayne Roberts 3:56fc764dee0a 1692 radio.writeReg(REG_ADDR_LORA_SLAVE_ID, n, 4);
Wayne Roberts 3:56fc764dee0a 1693 return false;
Wayne Roberts 3:56fc764dee0a 1694 }
Wayne Roberts 3:56fc764dee0a 1695
Wayne Roberts 3:56fc764dee0a 1696 const value_item_t Radio::rng_slave_id_item = { _ITEM_VALUE, 9, rng_slave_id_print, rng_slave_id_write};
Wayne Roberts 3:56fc764dee0a 1697
Wayne Roberts 3:56fc764dee0a 1698 unsigned Radio::rng_idLength_read(bool forWriting)
Wayne Roberts 3:56fc764dee0a 1699 {
Wayne Roberts 3:56fc764dee0a 1700 RngDebTh2_t RngDebTh2;
Wayne Roberts 3:56fc764dee0a 1701 RngDebTh2.octet = radio.readReg(REG_ADDR_LORA_RNGDEBTH2, 1);
Wayne Roberts 3:56fc764dee0a 1702 return RngDebTh2.bits.ranging_id_check_length;
Wayne Roberts 3:56fc764dee0a 1703 }
Wayne Roberts 3:56fc764dee0a 1704
Wayne Roberts 3:56fc764dee0a 1705 menuMode_e Radio::rng_idLength_write(unsigned sidx)
Wayne Roberts 3:56fc764dee0a 1706 {
Wayne Roberts 3:56fc764dee0a 1707 RngDebTh2_t RngDebTh2;
Wayne Roberts 3:56fc764dee0a 1708 RngDebTh2.octet = radio.readReg(REG_ADDR_LORA_RNGDEBTH2, 1);
Wayne Roberts 3:56fc764dee0a 1709 RngDebTh2.bits.ranging_id_check_length = sidx;
Wayne Roberts 3:56fc764dee0a 1710 radio.writeReg(REG_ADDR_LORA_RNGDEBTH2, RngDebTh2.octet, 1);
Wayne Roberts 3:56fc764dee0a 1711 return MENUMODE_REDRAW;
Wayne Roberts 3:56fc764dee0a 1712 }
Wayne Roberts 3:56fc764dee0a 1713
Wayne Roberts 3:56fc764dee0a 1714 static const char* const rngLens[] = {
Wayne Roberts 3:56fc764dee0a 1715 " 8 bits",
Wayne Roberts 3:56fc764dee0a 1716 "16 bits",
Wayne Roberts 3:56fc764dee0a 1717 "24 bits",
Wayne Roberts 3:56fc764dee0a 1718 "32 bits",
Wayne Roberts 3:56fc764dee0a 1719 NULL
Wayne Roberts 3:56fc764dee0a 1720 };
Wayne Roberts 3:56fc764dee0a 1721
Wayne Roberts 3:56fc764dee0a 1722 const dropdown_item_t Radio::rng_idLength_item = { _ITEM_DROPDOWN, rngLens, rngLens, rng_idLength_read, rng_idLength_write};
Wayne Roberts 3:56fc764dee0a 1723
Wayne Roberts 3:56fc764dee0a 1724
Wayne Roberts 3:56fc764dee0a 1725 void Radio::rng_delay_print(void)
Wayne Roberts 3:56fc764dee0a 1726 {
Wayne Roberts 3:56fc764dee0a 1727 if (pktType == PACKET_TYPE_RANGING) {
dudmuck 13:8ce61a1897ab 1728 printf("%u", radio.readReg(REG_ADDR_LORA_DELAY_CAL, 3) & 0x3fffff);
Wayne Roberts 3:56fc764dee0a 1729 }
Wayne Roberts 3:56fc764dee0a 1730 }
Wayne Roberts 3:56fc764dee0a 1731
Wayne Roberts 3:56fc764dee0a 1732 bool Radio::rng_delay_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1733 {
Wayne Roberts 3:56fc764dee0a 1734 unsigned n;
Wayne Roberts 3:56fc764dee0a 1735 uint32_t delayCal = radio.readReg(REG_ADDR_LORA_DELAY_CAL, 3);
Wayne Roberts 3:56fc764dee0a 1736 sscanf(txt, "%u", &n);
Wayne Roberts 3:56fc764dee0a 1737 delayCal &= ~0x3fffff;
Wayne Roberts 3:56fc764dee0a 1738 delayCal |= n;
Wayne Roberts 3:56fc764dee0a 1739 radio.writeReg(REG_ADDR_LORA_DELAY_CAL, delayCal, 3);
Wayne Roberts 3:56fc764dee0a 1740
Wayne Roberts 3:56fc764dee0a 1741 manualRngDelay = true;
Wayne Roberts 3:56fc764dee0a 1742 return false;
Wayne Roberts 3:56fc764dee0a 1743 }
Wayne Roberts 3:56fc764dee0a 1744
Wayne Roberts 3:56fc764dee0a 1745 const value_item_t Radio::rng_delay_item = { _ITEM_VALUE, 7, rng_delay_print, rng_delay_write };
Wayne Roberts 3:56fc764dee0a 1746
Wayne Roberts 3:56fc764dee0a 1747 unsigned Radio::rng_resultMux_read(bool)
Wayne Roberts 3:56fc764dee0a 1748 {
Wayne Roberts 3:56fc764dee0a 1749 RngCfg1_t RngCfg1;
Wayne Roberts 3:56fc764dee0a 1750 RngCfg1.octet = radio.readReg(REG_ADDR_RNGCFG1, 1);
Wayne Roberts 3:56fc764dee0a 1751 return RngCfg1.bits.ranging_result_mux_sel;
Wayne Roberts 3:56fc764dee0a 1752 }
Wayne Roberts 3:56fc764dee0a 1753
Wayne Roberts 3:56fc764dee0a 1754 menuMode_e Radio::rng_resultMux_write(unsigned sidx)
Wayne Roberts 3:56fc764dee0a 1755 {
Wayne Roberts 3:56fc764dee0a 1756 RngCfg1_t RngCfg1;
Wayne Roberts 3:56fc764dee0a 1757 RngCfg1.octet = radio.readReg(REG_ADDR_RNGCFG1, 1);
Wayne Roberts 3:56fc764dee0a 1758 RngCfg1.bits.ranging_result_mux_sel = sidx;
Wayne Roberts 3:56fc764dee0a 1759 radio.writeReg(REG_ADDR_RNGCFG1, RngCfg1.octet, 1);
Wayne Roberts 3:56fc764dee0a 1760 return MENUMODE_REDRAW;
Wayne Roberts 3:56fc764dee0a 1761 }
Wayne Roberts 3:56fc764dee0a 1762
Wayne Roberts 3:56fc764dee0a 1763 static const char* const rngResults[] = {
Wayne Roberts 3:56fc764dee0a 1764 " raw ",
Wayne Roberts 3:56fc764dee0a 1765 " rssiAvg ",
Wayne Roberts 3:56fc764dee0a 1766 " debiased ",
Wayne Roberts 3:56fc764dee0a 1767 "finalFilter",
Wayne Roberts 3:56fc764dee0a 1768 NULL
Wayne Roberts 3:56fc764dee0a 1769 };
Wayne Roberts 3:56fc764dee0a 1770
Wayne Roberts 3:56fc764dee0a 1771 const dropdown_item_t Radio::rng_resultMux_item = { _ITEM_DROPDOWN, rngResults, rngResults, rng_resultMux_read, rng_resultMux_write};
Wayne Roberts 3:56fc764dee0a 1772
Wayne Roberts 3:56fc764dee0a 1773
Wayne Roberts 3:56fc764dee0a 1774 void Radio::rng_wndFltSize_print()
Wayne Roberts 3:56fc764dee0a 1775 {
dudmuck 13:8ce61a1897ab 1776 printf("%u", radio.readReg(REG_ADDR_RNGFLTWNDSIZE, 1));
Wayne Roberts 3:56fc764dee0a 1777 }
Wayne Roberts 3:56fc764dee0a 1778
Wayne Roberts 3:56fc764dee0a 1779 bool Radio::rng_wndFltSize_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1780 {
Wayne Roberts 3:56fc764dee0a 1781 unsigned n;
Wayne Roberts 3:56fc764dee0a 1782 sscanf(txt, "%u", &n);
Wayne Roberts 3:56fc764dee0a 1783 radio.writeReg(REG_ADDR_RNGFLTWNDSIZE, n, 1);
Wayne Roberts 3:56fc764dee0a 1784 return false;
Wayne Roberts 3:56fc764dee0a 1785 }
Wayne Roberts 3:56fc764dee0a 1786
Wayne Roberts 3:56fc764dee0a 1787 const value_item_t Radio::rng_wndFltSize_item = { _ITEM_VALUE, 4, rng_wndFltSize_print, rng_wndFltSize_write};
Wayne Roberts 3:56fc764dee0a 1788
Wayne Roberts 3:56fc764dee0a 1789
Wayne Roberts 3:56fc764dee0a 1790
Wayne Roberts 3:56fc764dee0a 1791
Wayne Roberts 3:56fc764dee0a 1792 void Radio::rng_rngRssiThresh_print()
Wayne Roberts 3:56fc764dee0a 1793 {
Wayne Roberts 3:56fc764dee0a 1794 RngDebTh4H_t RngDebTh4H;
Wayne Roberts 3:56fc764dee0a 1795 RngDebTh4H.octet = radio.readReg(REG_ADDR_RNGDEBTH4H, 1);
dudmuck 13:8ce61a1897ab 1796 printf("%u", RngDebTh4H.bits.rng_rssi_threshold);
Wayne Roberts 3:56fc764dee0a 1797 }
Wayne Roberts 3:56fc764dee0a 1798
Wayne Roberts 3:56fc764dee0a 1799 bool Radio::rng_rngRssiThresh_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1800 {
Wayne Roberts 3:56fc764dee0a 1801 unsigned n;
Wayne Roberts 3:56fc764dee0a 1802 RngDebTh4H_t RngDebTh4H;
Wayne Roberts 3:56fc764dee0a 1803 RngDebTh4H.octet = radio.readReg(REG_ADDR_RNGDEBTH4H, 1);
Wayne Roberts 3:56fc764dee0a 1804 sscanf(txt, "%u", &n);
Wayne Roberts 3:56fc764dee0a 1805 RngDebTh4H.bits.rng_rssi_threshold = n;
Wayne Roberts 3:56fc764dee0a 1806 radio.writeReg(REG_ADDR_RNGDEBTH4H, RngDebTh4H.octet, 1);
Wayne Roberts 3:56fc764dee0a 1807 return false;
Wayne Roberts 3:56fc764dee0a 1808 }
Wayne Roberts 3:56fc764dee0a 1809
Wayne Roberts 3:56fc764dee0a 1810 const value_item_t Radio::rng_rngRssiThresh_item = { _ITEM_VALUE, 4, rng_rngRssiThresh_print, rng_rngRssiThresh_write};
Wayne Roberts 3:56fc764dee0a 1811
Wayne Roberts 3:56fc764dee0a 1812 const menu_t Radio::rng_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1813 { {FIRST_CHIP_MENU_ROW+3, 19}, NULL, &rng_role_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1814 { {FIRST_CHIP_MENU_ROW+3, 28}, "ID to send:", &rng_id_send_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1815 { {FIRST_CHIP_MENU_ROW+3, 49}, "slave ID:", &rng_slave_id_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1816 { {FIRST_CHIP_MENU_ROW+3, 67}, NULL, &rng_idLength_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1817 { {FIRST_CHIP_MENU_ROW+4, 1}, "delay:", &rng_delay_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1818 { {FIRST_CHIP_MENU_ROW+4, 14}, "resultMux:", &rng_resultMux_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1819 { {FIRST_CHIP_MENU_ROW+4, 37}, "windowFilterSize:", &rng_wndFltSize_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1820 { {FIRST_CHIP_MENU_ROW+4, 59}, "rngRssiThresh:", &rng_rngRssiThresh_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 3:56fc764dee0a 1821
Wayne Roberts 3:56fc764dee0a 1822 { {0, 0}, NULL, NULL }
Wayne Roberts 3:56fc764dee0a 1823 };
Wayne Roberts 3:56fc764dee0a 1824
Wayne Roberts 4:fa31fdf4ec8d 1825 void Radio::xta_print()
Wayne Roberts 4:fa31fdf4ec8d 1826 {
Wayne Roberts 4:fa31fdf4ec8d 1827 uint8_t trim = radio.readReg(REG_ADDR_XTA_TRIM, 1);
dudmuck 13:8ce61a1897ab 1828 printf("%02x", trim);
Wayne Roberts 4:fa31fdf4ec8d 1829 }
Wayne Roberts 4:fa31fdf4ec8d 1830
Wayne Roberts 4:fa31fdf4ec8d 1831 bool Radio::xta_write(const char* txt)
Wayne Roberts 4:fa31fdf4ec8d 1832 {
Wayne Roberts 4:fa31fdf4ec8d 1833 unsigned trim;
Wayne Roberts 4:fa31fdf4ec8d 1834 if (sscanf(txt, "%x", &trim) == 1)
Wayne Roberts 4:fa31fdf4ec8d 1835 radio.writeReg(REG_ADDR_XTA_TRIM, trim, 1);
Wayne Roberts 4:fa31fdf4ec8d 1836
Wayne Roberts 4:fa31fdf4ec8d 1837 return false;
Wayne Roberts 4:fa31fdf4ec8d 1838 }
Wayne Roberts 4:fa31fdf4ec8d 1839
Wayne Roberts 4:fa31fdf4ec8d 1840 const value_item_t Radio::xta_item = { _ITEM_VALUE, 3, xta_print, xta_write};
Wayne Roberts 4:fa31fdf4ec8d 1841
Wayne Roberts 4:fa31fdf4ec8d 1842 void Radio::xtb_print()
Wayne Roberts 4:fa31fdf4ec8d 1843 {
Wayne Roberts 4:fa31fdf4ec8d 1844 uint8_t trim = radio.readReg(REG_ADDR_XTB_TRIM, 1);
dudmuck 13:8ce61a1897ab 1845 printf("%02x", trim);
Wayne Roberts 4:fa31fdf4ec8d 1846 }
Wayne Roberts 4:fa31fdf4ec8d 1847
Wayne Roberts 4:fa31fdf4ec8d 1848 bool Radio::xtb_write(const char* txt)
Wayne Roberts 4:fa31fdf4ec8d 1849 {
Wayne Roberts 4:fa31fdf4ec8d 1850 unsigned trim;
Wayne Roberts 4:fa31fdf4ec8d 1851 if (sscanf(txt, "%x", &trim) == 1)
Wayne Roberts 4:fa31fdf4ec8d 1852 radio.writeReg(REG_ADDR_XTB_TRIM, trim, 1);
Wayne Roberts 4:fa31fdf4ec8d 1853
Wayne Roberts 4:fa31fdf4ec8d 1854 return false;
Wayne Roberts 4:fa31fdf4ec8d 1855 }
Wayne Roberts 4:fa31fdf4ec8d 1856
Wayne Roberts 4:fa31fdf4ec8d 1857 const value_item_t Radio::xtb_item = { _ITEM_VALUE, 3, xtb_print, xtb_write};
Wayne Roberts 4:fa31fdf4ec8d 1858
Wayne Roberts 1:0817a150122b 1859 const menu_t Radio::common_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1860 { {FIRST_CHIP_MENU_ROW, 1}, "XTA:", &xta_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1861 { {FIRST_CHIP_MENU_ROW, 8}, "XTB:", &xtb_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1862 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1863 };
Wayne Roberts 1:0817a150122b 1864
Wayne Roberts 1:0817a150122b 1865 const menu_t* Radio::get_modem_menu()
Wayne Roberts 1:0817a150122b 1866 {
Wayne Roberts 1:0817a150122b 1867 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 1868
Wayne Roberts 1:0817a150122b 1869 if (pktType == PACKET_TYPE_RANGING || pktType == PACKET_TYPE_LORA) {
Wayne Roberts 1:0817a150122b 1870 return lora_menu;
Wayne Roberts 1:0817a150122b 1871 } else if (pktType == PACKET_TYPE_FLRC) {
Wayne Roberts 1:0817a150122b 1872 return flrc_menu;
Wayne Roberts 1:0817a150122b 1873 } else if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 1874 return gfsk_menu;
Wayne Roberts 1:0817a150122b 1875 }
Wayne Roberts 1:0817a150122b 1876
Wayne Roberts 1:0817a150122b 1877 return NULL;
Wayne Roberts 1:0817a150122b 1878 }
Wayne Roberts 1:0817a150122b 1879
Wayne Roberts 3:56fc764dee0a 1880 const menu_t* Radio::get_modem_sub_menu()
Wayne Roberts 3:56fc764dee0a 1881 {
Wayne Roberts 3:56fc764dee0a 1882 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 1883 return rng_menu;
Wayne Roberts 3:56fc764dee0a 1884 }
Wayne Roberts 3:56fc764dee0a 1885 return NULL;
Wayne Roberts 3:56fc764dee0a 1886 }
Wayne Roberts 1:0817a150122b 1887
Wayne Roberts 1:0817a150122b 1888 bool Radio::service(int8_t statusRow)
Wayne Roberts 1:0817a150122b 1889 {
Wayne Roberts 1:0817a150122b 1890 static pktStatus_t prevPktStatus;
Wayne Roberts 1:0817a150122b 1891 static IrqFlags_t prevIrqFlags;
Wayne Roberts 1:0817a150122b 1892 IrqFlags_t irqFlags;
Wayne Roberts 1:0817a150122b 1893 bool ret = false;
dudmuck 14:14b9e1c08bfc 1894 static long prev_now_ms;
dudmuck 14:14b9e1c08bfc 1895 auto now_tp = time_point_cast<milliseconds>(Kernel::Clock::now());
dudmuck 14:14b9e1c08bfc 1896 long now_ms = now_tp.time_since_epoch().count();
Wayne Roberts 1:0817a150122b 1897
Wayne Roberts 1:0817a150122b 1898 radio.service();
Wayne Roberts 1:0817a150122b 1899
dudmuck 14:14b9e1c08bfc 1900 if (statusRow > 0 && now_ms-prev_now_ms > 50) {
Wayne Roberts 1:0817a150122b 1901 int cmp = 0;
Wayne Roberts 1:0817a150122b 1902 pktStatus_t pktStatus;
Wayne Roberts 1:0817a150122b 1903 uint8_t buf[6];
Wayne Roberts 1:0817a150122b 1904 radio.xfer(OPCODE_GET_IRQ_STATUS, 0, 3, buf);
Wayne Roberts 1:0817a150122b 1905 irqFlags.word = buf[1] << 8;
Wayne Roberts 1:0817a150122b 1906 irqFlags.word |= buf[2];
Wayne Roberts 1:0817a150122b 1907
Wayne Roberts 1:0817a150122b 1908 if (rx_led == LED_ON) {
Wayne Roberts 1:0817a150122b 1909 uint8_t slen;
Wayne Roberts 1:0817a150122b 1910 if (pktType == PACKET_TYPE_LORA || pktType == PACKET_TYPE_RANGING)
Wayne Roberts 1:0817a150122b 1911 slen = 3;
Wayne Roberts 1:0817a150122b 1912 else
Wayne Roberts 1:0817a150122b 1913 slen = 6;
Wayne Roberts 1:0817a150122b 1914
Wayne Roberts 1:0817a150122b 1915 radio.xfer(OPCODE_GET_PACKET_STATUS, 0, slen, pktStatus.buf);
Wayne Roberts 2:ea9245bb1c53 1916 cmp = memcmp(prevPktStatus.buf, pktStatus.buf, slen);
Wayne Roberts 1:0817a150122b 1917 }
Wayne Roberts 1:0817a150122b 1918
Wayne Roberts 1:0817a150122b 1919 if (irqFlags.word != prevIrqFlags.word || cmp) {
Wayne Roberts 3:56fc764dee0a 1920 IrqFlags_t clearIrqFlags;
Wayne Roberts 3:56fc764dee0a 1921 clearIrqFlags.word = 0;
Wayne Roberts 3:56fc764dee0a 1922
dudmuck 13:8ce61a1897ab 1923 printf("\e[%u;1f", statusRow); // set (force) cursor to row;column
Wayne Roberts 1:0817a150122b 1924
Wayne Roberts 1:0817a150122b 1925 if (cmp) {
Wayne Roberts 1:0817a150122b 1926 if (pktType == PACKET_TYPE_FLRC || pktType == PACKET_TYPE_BLE || pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 1927 if (pktStatus.ble_gfsk_flrc.errors.SyncError)
dudmuck 13:8ce61a1897ab 1928 printf("SyncError ");
Wayne Roberts 1:0817a150122b 1929 if (pktStatus.ble_gfsk_flrc.errors.LengthError)
dudmuck 13:8ce61a1897ab 1930 printf("LengthError ");
Wayne Roberts 1:0817a150122b 1931 if (pktStatus.ble_gfsk_flrc.errors.CrcError)
dudmuck 13:8ce61a1897ab 1932 printf("CrcError ");
Wayne Roberts 1:0817a150122b 1933 if (pktStatus.ble_gfsk_flrc.errors.AbortErr)
dudmuck 13:8ce61a1897ab 1934 printf("AbortErr ");
Wayne Roberts 1:0817a150122b 1935 if (pktStatus.ble_gfsk_flrc.errors.headerReceived)
dudmuck 13:8ce61a1897ab 1936 printf("headerReceived ");
Wayne Roberts 1:0817a150122b 1937 if (pktStatus.ble_gfsk_flrc.errors.packetReceived)
dudmuck 13:8ce61a1897ab 1938 printf("packetReceived ");
Wayne Roberts 1:0817a150122b 1939 if (pktStatus.ble_gfsk_flrc.errors.pktCtrlBusy)
dudmuck 13:8ce61a1897ab 1940 printf("pktCtrlBusy ");
Wayne Roberts 1:0817a150122b 1941 }
Wayne Roberts 1:0817a150122b 1942 memcpy(prevPktStatus.buf, pktStatus.buf, sizeof(pktStatus_t));
dudmuck 13:8ce61a1897ab 1943 printf(" | ");
Wayne Roberts 1:0817a150122b 1944 }
Wayne Roberts 1:0817a150122b 1945
Wayne Roberts 1:0817a150122b 1946 if (irqFlags.bits.TxDone)
dudmuck 13:8ce61a1897ab 1947 printf("TxDone ");
Wayne Roberts 1:0817a150122b 1948 if (irqFlags.bits.RxDone)
dudmuck 13:8ce61a1897ab 1949 printf("RxDone ");
Wayne Roberts 1:0817a150122b 1950 if (irqFlags.bits.SyncWordValid)
dudmuck 13:8ce61a1897ab 1951 printf("SyncWordValid ");
Wayne Roberts 1:0817a150122b 1952 if (irqFlags.bits.SyncWordError)
dudmuck 13:8ce61a1897ab 1953 printf("SyncWordError ");
Wayne Roberts 1:0817a150122b 1954 if (irqFlags.bits.HeaderValid)
dudmuck 13:8ce61a1897ab 1955 printf("HeaderValid ");
Wayne Roberts 1:0817a150122b 1956 if (irqFlags.bits.HeaderError)
dudmuck 13:8ce61a1897ab 1957 printf("HeaderError ");
Wayne Roberts 1:0817a150122b 1958 if (irqFlags.bits.CrcError)
dudmuck 13:8ce61a1897ab 1959 printf("CrcError ");
Wayne Roberts 3:56fc764dee0a 1960 if (irqFlags.bits.RangingSlaveResponseDone) {
dudmuck 13:8ce61a1897ab 1961 printf("RangingSlaveResponseDone ");
Wayne Roberts 3:56fc764dee0a 1962 clearIrqFlags.bits.RangingSlaveResponseDone = 1;
Wayne Roberts 3:56fc764dee0a 1963 } if (irqFlags.bits.RangingSlaveRequestDiscard) {
dudmuck 13:8ce61a1897ab 1964 printf("RangingSlaveRequestDiscard ");
Wayne Roberts 3:56fc764dee0a 1965 clearIrqFlags.bits.RangingSlaveRequestDiscard = 1;
Wayne Roberts 3:56fc764dee0a 1966 } if (irqFlags.bits.RangingMasterResultValid) {
dudmuck 13:8ce61a1897ab 1967 printf("RangingMasterResultValid ");
Wayne Roberts 3:56fc764dee0a 1968 } if (irqFlags.bits.RangingMasterTimeout) {
Wayne Roberts 3:56fc764dee0a 1969 radio.chipMode = CHIPMODE_NONE;
Wayne Roberts 3:56fc764dee0a 1970 chipModeChange();
dudmuck 13:8ce61a1897ab 1971 printf("RangingMasterTimeout ");
Wayne Roberts 3:56fc764dee0a 1972 clearIrqFlags.bits.RangingMasterTimeout = 1;
Wayne Roberts 3:56fc764dee0a 1973 } if (irqFlags.bits.RangingMasterRequestValid) {
dudmuck 13:8ce61a1897ab 1974 printf("RangingMasterRequestValid ");
Wayne Roberts 3:56fc764dee0a 1975 clearIrqFlags.bits.RangingMasterRequestValid = 1;
Wayne Roberts 3:56fc764dee0a 1976 } if (irqFlags.bits.CadDone)
dudmuck 13:8ce61a1897ab 1977 printf("CadDone ");
Wayne Roberts 1:0817a150122b 1978 if (irqFlags.bits.CadDetected)
dudmuck 13:8ce61a1897ab 1979 printf("CadDetected ");
Wayne Roberts 1:0817a150122b 1980 if (irqFlags.bits.RxTxTimeout)
dudmuck 13:8ce61a1897ab 1981 printf("RxTxTimeout ");
Wayne Roberts 1:0817a150122b 1982 if (irqFlags.bits.PreambleDetected)
dudmuck 13:8ce61a1897ab 1983 printf("PreambleDetected ");
Wayne Roberts 1:0817a150122b 1984
dudmuck 13:8ce61a1897ab 1985 printf("\e[K");
Wayne Roberts 1:0817a150122b 1986 ret = true;
Wayne Roberts 1:0817a150122b 1987
Wayne Roberts 1:0817a150122b 1988 prevIrqFlags.word = irqFlags.word;
Wayne Roberts 3:56fc764dee0a 1989
Wayne Roberts 3:56fc764dee0a 1990 if (irqFlags.bits.RangingMasterResultValid) {
Wayne Roberts 3:56fc764dee0a 1991 float m;
Wayne Roberts 3:56fc764dee0a 1992 unsigned rngResult, rngRssi;
Wayne Roberts 3:56fc764dee0a 1993 radio.chipMode = CHIPMODE_NONE;
Wayne Roberts 3:56fc764dee0a 1994 chipModeChange();
Wayne Roberts 3:56fc764dee0a 1995 rngResult = radio.readReg(REG_ADDR_RNGRESULT, 3);
Wayne Roberts 3:56fc764dee0a 1996 // Distance [m] = RangingResult*150/(2^12*BwMHz)
Wayne Roberts 3:56fc764dee0a 1997 m = rngResult * 150 / (4096*bwMHzs[LoRaPktPar0.bits.modem_bw]);
Wayne Roberts 3:56fc764dee0a 1998 rngRssi = radio.readReg(REG_ADDR_RNGRSSI, 1);
Wayne Roberts 3:56fc764dee0a 1999 log_printf("%u rngResult %.2fm, RngRssi:%u bw%.1f\r\n", rngResult, m, rngRssi, bwMHzs[LoRaPktPar0.bits.modem_bw]);
Wayne Roberts 3:56fc764dee0a 2000 clearIrqFlags.bits.RangingMasterResultValid = 1;
Wayne Roberts 3:56fc764dee0a 2001 }
Wayne Roberts 3:56fc764dee0a 2002
Wayne Roberts 3:56fc764dee0a 2003 if (irqFlags.bits.RangingSlaveResponseDone)
Wayne Roberts 3:56fc764dee0a 2004 log_printf("RangingSlaveResponseDone\r\n");
Wayne Roberts 3:56fc764dee0a 2005 if (irqFlags.bits.RangingSlaveRequestDiscard)
Wayne Roberts 3:56fc764dee0a 2006 log_printf("RangingSlaveRequestDiscard\r\n");
Wayne Roberts 3:56fc764dee0a 2007 if (irqFlags.bits.RangingMasterRequestValid)
Wayne Roberts 3:56fc764dee0a 2008 log_printf("RangingMasterRequestValid\r\n");
Wayne Roberts 3:56fc764dee0a 2009
Wayne Roberts 3:56fc764dee0a 2010 if (clearIrqFlags.word != 0) {
Wayne Roberts 3:56fc764dee0a 2011 buf[0] = clearIrqFlags.word >> 8;
Wayne Roberts 3:56fc764dee0a 2012 buf[1] = (uint8_t)clearIrqFlags.word;
Wayne Roberts 3:56fc764dee0a 2013 radio.xfer(OPCODE_CLEAR_IRQ_STATUS, 2, 0, buf);
Wayne Roberts 3:56fc764dee0a 2014 }
Wayne Roberts 3:56fc764dee0a 2015 } // ..if change
Wayne Roberts 1:0817a150122b 2016
dudmuck 14:14b9e1c08bfc 2017 prev_now_ms = now_ms;
Wayne Roberts 1:0817a150122b 2018 }
Wayne Roberts 1:0817a150122b 2019
Wayne Roberts 1:0817a150122b 2020 return ret;
Wayne Roberts 1:0817a150122b 2021 }
Wayne Roberts 1:0817a150122b 2022
Wayne Roberts 1:0817a150122b 2023 void Radio::Rx()
Wayne Roberts 1:0817a150122b 2024 {
Wayne Roberts 3:56fc764dee0a 2025 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 2026 IrqFlags_t irqEnable;
Wayne Roberts 3:56fc764dee0a 2027 uint8_t buf[8];
Wayne Roberts 3:56fc764dee0a 2028
Wayne Roberts 3:56fc764dee0a 2029 if (!manualRngDelay)
Wayne Roberts 3:56fc764dee0a 2030 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 2031
Wayne Roberts 3:56fc764dee0a 2032 irqEnable.word = 0;
Wayne Roberts 3:56fc764dee0a 2033 irqEnable.bits.RxDone = 1;
Wayne Roberts 3:56fc764dee0a 2034 irqEnable.bits.RxTxTimeout = 1;
Wayne Roberts 3:56fc764dee0a 2035 irqEnable.bits.RangingSlaveResponseDone = 1;
Wayne Roberts 3:56fc764dee0a 2036 irqEnable.bits.RangingSlaveRequestDiscard = 1;
Wayne Roberts 3:56fc764dee0a 2037 irqEnable.bits.RangingMasterRequestValid = 1;
Wayne Roberts 3:56fc764dee0a 2038
Wayne Roberts 3:56fc764dee0a 2039 buf[0] = irqEnable.word >> 8; // enable bits
Wayne Roberts 3:56fc764dee0a 2040 buf[1] = irqEnable.word; // enable bits
Wayne Roberts 3:56fc764dee0a 2041
Wayne Roberts 3:56fc764dee0a 2042 irqEnable.bits.RangingSlaveResponseDone = 0;
Wayne Roberts 3:56fc764dee0a 2043 irqEnable.bits.RangingSlaveRequestDiscard = 0;
Wayne Roberts 3:56fc764dee0a 2044 irqEnable.bits.RangingMasterRequestValid = 0;
Wayne Roberts 3:56fc764dee0a 2045 buf[2] = irqEnable.word >> 8; // dio1
Wayne Roberts 3:56fc764dee0a 2046 buf[3] = irqEnable.word; // dio1
Wayne Roberts 3:56fc764dee0a 2047
Wayne Roberts 3:56fc764dee0a 2048 buf[4] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 2049 buf[5] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 2050 buf[6] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 2051 buf[7] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 2052 radio.xfer(OPCODE_SET_DIO_IRQ_PARAMS, 8, 0, buf);
Wayne Roberts 3:56fc764dee0a 2053
Wayne Roberts 3:56fc764dee0a 2054 buf[0] = radio.periodBase;
Wayne Roberts 3:56fc764dee0a 2055 /* receive packets forever */
Wayne Roberts 3:56fc764dee0a 2056 buf[1] = 0xff;
Wayne Roberts 3:56fc764dee0a 2057 buf[2] = 0xff;
Wayne Roberts 3:56fc764dee0a 2058 radio.xfer(OPCODE_SET_RX, 3, 0, buf);
Wayne Roberts 3:56fc764dee0a 2059
Wayne Roberts 3:56fc764dee0a 2060 radio.chipMode = CHIPMODE_RX;
Wayne Roberts 3:56fc764dee0a 2061 chipModeChange();
Wayne Roberts 3:56fc764dee0a 2062 } else
Wayne Roberts 3:56fc764dee0a 2063 radio.start_rx(0);
Wayne Roberts 1:0817a150122b 2064 }
Wayne Roberts 1:0817a150122b 2065
Wayne Roberts 1:0817a150122b 2066 void Radio::setFS()
Wayne Roberts 1:0817a150122b 2067 {
Wayne Roberts 1:0817a150122b 2068 radio.setFS();
Wayne Roberts 1:0817a150122b 2069 }
Wayne Roberts 1:0817a150122b 2070
Wayne Roberts 3:56fc764dee0a 2071 void Radio::test()
Wayne Roberts 3:56fc764dee0a 2072 {
Wayne Roberts 3:56fc764dee0a 2073 /*
Wayne Roberts 3:56fc764dee0a 2074 RngCfg0_t RngCfg0;
Wayne Roberts 3:56fc764dee0a 2075 RngCfg0.octet = radio.readReg(REG_ADDR_RNGCFG0, 1);
Wayne Roberts 3:56fc764dee0a 2076
Wayne Roberts 3:56fc764dee0a 2077 log_printf("Rngcfg0 %02x\r\n", RngCfg0.octet);*/
Wayne Roberts 3:56fc764dee0a 2078 unsigned a;
Wayne Roberts 3:56fc764dee0a 2079 log_printf("%02x ", radio.readReg(0x910, 1));
Wayne Roberts 3:56fc764dee0a 2080 for (a = 0x911; a < 0x980; a++) {
dudmuck 13:8ce61a1897ab 2081 printf("%02x ", radio.readReg(a, 1));
Wayne Roberts 3:56fc764dee0a 2082 if ((a & 0x1f) == 0x1f)
dudmuck 13:8ce61a1897ab 2083 printf("\r\n%03x ", a+1);
Wayne Roberts 3:56fc764dee0a 2084 }
dudmuck 13:8ce61a1897ab 2085 printf("\r\n");
Wayne Roberts 3:56fc764dee0a 2086 }
Wayne Roberts 1:0817a150122b 2087
Wayne Roberts 4:fa31fdf4ec8d 2088 unsigned Radio::read_register(unsigned addr)
Wayne Roberts 4:fa31fdf4ec8d 2089 {
Wayne Roberts 4:fa31fdf4ec8d 2090 return radio.readReg(addr, 1);
Wayne Roberts 4:fa31fdf4ec8d 2091 }
Wayne Roberts 4:fa31fdf4ec8d 2092
Wayne Roberts 4:fa31fdf4ec8d 2093 void Radio::write_register(unsigned addr, unsigned val)
Wayne Roberts 4:fa31fdf4ec8d 2094 {
Wayne Roberts 4:fa31fdf4ec8d 2095 radio.writeReg(addr, val, 1);
Wayne Roberts 4:fa31fdf4ec8d 2096 }
Wayne Roberts 4:fa31fdf4ec8d 2097
Wayne Roberts 1:0817a150122b 2098 #endif /* ..SX126x_H */