wayne roberts / Mbed OS utility_sx12xx
Committer:
dudmuck
Date:
Mon Aug 05 20:07:16 2024 +0000
Revision:
15:703ca340d0fb
Parent:
14:14b9e1c08bfc
add reading of RSSI

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
dudmuck 15:703ca340d0fb 564 void Radio::get_rssi()
dudmuck 15:703ca340d0fb 565 {
dudmuck 15:703ca340d0fb 566 uint8_t buf[3];
dudmuck 15:703ca340d0fb 567 radio.xfer(OPCODE_GET_RSSIINST, 0, 3, buf);
dudmuck 15:703ca340d0fb 568 log_printf("-%0.1f dBm\r\n", buf[1]/2.0);
dudmuck 15:703ca340d0fb 569 }
dudmuck 15:703ca340d0fb 570
dudmuck 15:703ca340d0fb 571
Wayne Roberts 3:56fc764dee0a 572 void Radio::rngTx()
Wayne Roberts 3:56fc764dee0a 573 {
Wayne Roberts 3:56fc764dee0a 574 IrqFlags_t irqEnable;
Wayne Roberts 3:56fc764dee0a 575 uint8_t buf[8];
Wayne Roberts 3:56fc764dee0a 576
Wayne Roberts 3:56fc764dee0a 577 if (!manualRngDelay)
Wayne Roberts 3:56fc764dee0a 578 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 579
Wayne Roberts 3:56fc764dee0a 580 irqEnable.word = 0;
Wayne Roberts 3:56fc764dee0a 581 irqEnable.bits.TxDone = 1;
Wayne Roberts 3:56fc764dee0a 582 irqEnable.bits.RxTxTimeout = 1;
Wayne Roberts 3:56fc764dee0a 583 irqEnable.bits.RangingMasterTimeout = 1;
Wayne Roberts 3:56fc764dee0a 584 irqEnable.bits.RangingMasterResultValid = 1;
Wayne Roberts 3:56fc764dee0a 585 irqEnable.bits.RangingMasterRequestValid = 1;
Wayne Roberts 3:56fc764dee0a 586
Wayne Roberts 3:56fc764dee0a 587 buf[0] = irqEnable.word >> 8; // enable bits
Wayne Roberts 3:56fc764dee0a 588 buf[1] = irqEnable.word; // enable bits
Wayne Roberts 3:56fc764dee0a 589
Wayne Roberts 3:56fc764dee0a 590 irqEnable.bits.RangingMasterTimeout = 0;
Wayne Roberts 3:56fc764dee0a 591 irqEnable.bits.RangingMasterResultValid = 0;
Wayne Roberts 3:56fc764dee0a 592 irqEnable.bits.RangingMasterRequestValid = 0;
Wayne Roberts 3:56fc764dee0a 593 buf[2] = irqEnable.word >> 8; // dio1
Wayne Roberts 3:56fc764dee0a 594 buf[3] = irqEnable.word; // dio1
Wayne Roberts 3:56fc764dee0a 595
Wayne Roberts 3:56fc764dee0a 596 buf[4] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 597 buf[5] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 598 buf[6] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 599 buf[7] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 600 radio.xfer(OPCODE_SET_DIO_IRQ_PARAMS, 8, 0, buf);
Wayne Roberts 3:56fc764dee0a 601
Wayne Roberts 3:56fc764dee0a 602 log_printf("rngTx\r\n");
Wayne Roberts 3:56fc764dee0a 603
Wayne Roberts 3:56fc764dee0a 604 buf[0] = radio.periodBase;
Wayne Roberts 3:56fc764dee0a 605 /* no timeout */
Wayne Roberts 3:56fc764dee0a 606 buf[1] = 0;
Wayne Roberts 3:56fc764dee0a 607 buf[2] = 0;
Wayne Roberts 3:56fc764dee0a 608 radio.xfer(OPCODE_SET_TX, 3, 0, buf);
Wayne Roberts 3:56fc764dee0a 609
Wayne Roberts 3:56fc764dee0a 610 radio.chipMode = CHIPMODE_TX;
Wayne Roberts 3:56fc764dee0a 611 chipModeChange();
Wayne Roberts 3:56fc764dee0a 612 }
Wayne Roberts 3:56fc764dee0a 613
Wayne Roberts 1:0817a150122b 614 void Radio::txPkt()
Wayne Roberts 1:0817a150122b 615 {
Wayne Roberts 1:0817a150122b 616 uint8_t txlen = 0;
Wayne Roberts 1:0817a150122b 617
Wayne Roberts 1:0817a150122b 618 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 619
Wayne Roberts 1:0817a150122b 620 switch (pktType) {
Wayne Roberts 1:0817a150122b 621 case PACKET_TYPE_FLRC:
Wayne Roberts 1:0817a150122b 622 case PACKET_TYPE_GFSK:
Wayne Roberts 1:0817a150122b 623 txlen = radio.readReg(REG_ADDR_PAYLOAD_LEN, 1);
Wayne Roberts 1:0817a150122b 624 break;
Wayne Roberts 1:0817a150122b 625 case PACKET_TYPE_BLE:
Wayne Roberts 1:0817a150122b 626 return; // TODO BLE
Wayne Roberts 1:0817a150122b 627 case PACKET_TYPE_RANGING:
Wayne Roberts 3:56fc764dee0a 628 rngTx();
Wayne Roberts 3:56fc764dee0a 629 return;
Wayne Roberts 1:0817a150122b 630 case PACKET_TYPE_LORA:
Wayne Roberts 1:0817a150122b 631 txlen = radio.readReg(REG_ADDR_LORA_TX_PAYLOAD_LENGTH, 1);
Wayne Roberts 1:0817a150122b 632 break;
Wayne Roberts 1:0817a150122b 633 }
Wayne Roberts 1:0817a150122b 634 log_printf("txPkt%u\r\n", txlen);
Wayne Roberts 1:0817a150122b 635
Wayne Roberts 3:56fc764dee0a 636 radio.setBufferBase(0, 0);
Wayne Roberts 3:56fc764dee0a 637
Wayne Roberts 1:0817a150122b 638 radio.start_tx(txlen, 0);
Wayne Roberts 1:0817a150122b 639
Wayne Roberts 1:0817a150122b 640 }
Wayne Roberts 1:0817a150122b 641
Wayne Roberts 1:0817a150122b 642 #define REGBW_2_4MHZ 0
Wayne Roberts 1:0817a150122b 643 #define REGBW_1_2MHZ 1
Wayne Roberts 1:0817a150122b 644 #define REGBW_0_6MHZ 2
Wayne Roberts 1:0817a150122b 645 #define REGBW_0_3MHZ 3
Wayne Roberts 1:0817a150122b 646
Wayne Roberts 2:ea9245bb1c53 647 unsigned Radio::gfsk_flrc_bpsbw_read(bool fw)
Wayne Roberts 1:0817a150122b 648 {
Wayne Roberts 1:0817a150122b 649 unsigned n = UINT_MAX;
Wayne Roberts 1:0817a150122b 650 RegRxBw_t RegRxBw;
Wayne Roberts 1:0817a150122b 651 FloraPreambleHi_t FloraPreambleHi;
Wayne Roberts 1:0817a150122b 652 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 653
Wayne Roberts 1:0817a150122b 654 FloraPreambleHi.octet = radio.readReg(REG_ADDR_FLORA_PREAMBLE_HI, 1);
Wayne Roberts 1:0817a150122b 655
Wayne Roberts 1:0817a150122b 656 RegRxBw.octet = radio.readReg(REG_ADDR_RXBW, 1);
Wayne Roberts 1:0817a150122b 657
Wayne Roberts 1:0817a150122b 658 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 659 switch (FloraPreambleHi.bits.data_rate) {
Wayne Roberts 1:0817a150122b 660 case 0:
Wayne Roberts 1:0817a150122b 661 n = 0; // 2Mbps, 2.4MHz
Wayne Roberts 1:0817a150122b 662 break;
Wayne Roberts 1:0817a150122b 663 case 1:
Wayne Roberts 1:0817a150122b 664 n = 1; // 1.6Mbps, 2.4MHz
Wayne Roberts 1:0817a150122b 665 break;
Wayne Roberts 1:0817a150122b 666 case 2:
Wayne Roberts 1:0817a150122b 667 if (RegRxBw.bits.bw == REGBW_2_4MHZ)
Wayne Roberts 1:0817a150122b 668 n = 2;
Wayne Roberts 1:0817a150122b 669 else if (RegRxBw.bits.bw == REGBW_1_2MHZ)
Wayne Roberts 1:0817a150122b 670 n = 3;
Wayne Roberts 1:0817a150122b 671 break;
Wayne Roberts 1:0817a150122b 672 case 3:
Wayne Roberts 1:0817a150122b 673 if (RegRxBw.bits.bw == REGBW_2_4MHZ) // 0.8Mbps 2.4 2.4MHz
Wayne Roberts 1:0817a150122b 674 n = 4;
Wayne Roberts 1:0817a150122b 675 else if (RegRxBw.bits.bw == REGBW_1_2MHZ) // 0.8Mbps 1.2MHz
Wayne Roberts 1:0817a150122b 676 n = 5;
Wayne Roberts 1:0817a150122b 677 break;
Wayne Roberts 1:0817a150122b 678 case 4:
Wayne Roberts 1:0817a150122b 679 if (RegRxBw.bits.bw == REGBW_1_2MHZ) // 0.5Mbps 1.2MHz
Wayne Roberts 1:0817a150122b 680 n = 6;
Wayne Roberts 1:0817a150122b 681 else if (RegRxBw.bits.bw == REGBW_0_6MHZ) // 0.5Mbps 0.6MHz
Wayne Roberts 1:0817a150122b 682 n = 7;
Wayne Roberts 1:0817a150122b 683 break;
Wayne Roberts 1:0817a150122b 684 case 5:
Wayne Roberts 1:0817a150122b 685 if (RegRxBw.bits.bw == REGBW_1_2MHZ) // 0.4Mbps 1.2MHz
Wayne Roberts 1:0817a150122b 686 n = 8;
Wayne Roberts 1:0817a150122b 687 else if (RegRxBw.bits.bw == REGBW_0_6MHZ) // 0.4Mbps 0.6MHz
Wayne Roberts 1:0817a150122b 688 n = 9;
Wayne Roberts 1:0817a150122b 689 break;
Wayne Roberts 1:0817a150122b 690 case 6:
Wayne Roberts 1:0817a150122b 691 if (RegRxBw.bits.bw == REGBW_0_6MHZ) // 0.25Mbps 0.6MHz
Wayne Roberts 1:0817a150122b 692 n = 10;
Wayne Roberts 1:0817a150122b 693 else if (RegRxBw.bits.bw == REGBW_0_3MHZ) // 0.25Mbps 0.3MHz
Wayne Roberts 1:0817a150122b 694 n = 11;
Wayne Roberts 1:0817a150122b 695 break;
Wayne Roberts 1:0817a150122b 696 case 7:
Wayne Roberts 1:0817a150122b 697 n = 12; // 0.125Mbps, assume bw=0.3MHz
Wayne Roberts 1:0817a150122b 698 break;
Wayne Roberts 1:0817a150122b 699 } // ..switch (FloraPreambleHi.bits.data_rate)
Wayne Roberts 1:0817a150122b 700 } else if (pktType == PACKET_TYPE_FLRC) {
Wayne Roberts 1:0817a150122b 701 n = FloraPreambleHi.bits.data_rate;
Wayne Roberts 1:0817a150122b 702 // datarate, bits 5,6,7.. bw bits 0,1,2
Wayne Roberts 1:0817a150122b 703 switch (FloraPreambleHi.bits.data_rate) {
Wayne Roberts 1:0817a150122b 704 case 0:
Wayne Roberts 1:0817a150122b 705 break;
Wayne Roberts 1:0817a150122b 706 case 1:
Wayne Roberts 1:0817a150122b 707 break;
Wayne Roberts 1:0817a150122b 708 case 2:
Wayne Roberts 1:0817a150122b 709 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_300_BW_1_2;
Wayne Roberts 1:0817a150122b 710 break;
Wayne Roberts 1:0817a150122b 711 case 3:
Wayne Roberts 1:0817a150122b 712 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_000_BW_1_2;
Wayne Roberts 1:0817a150122b 713 break;
Wayne Roberts 1:0817a150122b 714 case 4:
Wayne Roberts 1:0817a150122b 715 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_650_BW_0_6;
Wayne Roberts 1:0817a150122b 716 break;
Wayne Roberts 1:0817a150122b 717 case 5:
Wayne Roberts 1:0817a150122b 718 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_520_BW_0_6;
Wayne Roberts 1:0817a150122b 719 break;
Wayne Roberts 1:0817a150122b 720 case 6:
Wayne Roberts 1:0817a150122b 721 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_325_BW_0_3;
Wayne Roberts 1:0817a150122b 722 break;
Wayne Roberts 1:0817a150122b 723 case 7:
Wayne Roberts 1:0817a150122b 724 mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_260_BW_0_3;
Wayne Roberts 1:0817a150122b 725 break;
Wayne Roberts 1:0817a150122b 726 } // ..switch (FloraPreambleHi.bits.data_rate)
Wayne Roberts 1:0817a150122b 727 }
Wayne Roberts 1:0817a150122b 728
Wayne Roberts 1:0817a150122b 729 return n;
Wayne Roberts 1:0817a150122b 730 }
Wayne Roberts 1:0817a150122b 731
Wayne Roberts 2:ea9245bb1c53 732 menuMode_e Radio::gfsk_flrc_bpsbw_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 733 {
Wayne Roberts 1:0817a150122b 734 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 735
Wayne Roberts 1:0817a150122b 736 if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 737 switch (sidx) {
Wayne Roberts 1:0817a150122b 738 case 0: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_2_000_BW_2_4; break;
Wayne Roberts 1:0817a150122b 739 case 1: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_600_BW_2_4; break;
Wayne Roberts 1:0817a150122b 740 case 2: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_2_4; break;
Wayne Roberts 1:0817a150122b 741 case 3: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_1_000_BW_1_2; break;
Wayne Roberts 1:0817a150122b 742 case 4: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_2_4; break;
Wayne Roberts 1:0817a150122b 743 case 5: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_800_BW_1_2; break;
Wayne Roberts 1:0817a150122b 744 case 6: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_1_2; break;
Wayne Roberts 1:0817a150122b 745 case 7: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_500_BW_0_6; break;
Wayne Roberts 1:0817a150122b 746 case 8: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_1_2; break;
Wayne Roberts 1:0817a150122b 747 case 9: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_400_BW_0_6; break;
Wayne Roberts 1:0817a150122b 748 case 10: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_6; break;
Wayne Roberts 1:0817a150122b 749 case 11: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_250_BW_0_3; break;
Wayne Roberts 1:0817a150122b 750 case 12: mpBLE_GFSK.gfskBle.bitrateBandwidth = GFSK_BLE_BR_0_125_BW_0_3; break;
Wayne Roberts 1:0817a150122b 751 }
Wayne Roberts 1:0817a150122b 752 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpBLE_GFSK.buf);
Wayne Roberts 1:0817a150122b 753 } else if (pktType == PACKET_TYPE_FLRC) {
Wayne Roberts 1:0817a150122b 754 switch (sidx) {
Wayne Roberts 1:0817a150122b 755 case 2: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_300_BW_1_2; break;
Wayne Roberts 1:0817a150122b 756 case 3: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_1_000_BW_1_2; break;
Wayne Roberts 1:0817a150122b 757 case 4: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_650_BW_0_6; break;
Wayne Roberts 1:0817a150122b 758 case 5: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_520_BW_0_6; break;
Wayne Roberts 1:0817a150122b 759 case 6: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_325_BW_0_3; break;
Wayne Roberts 1:0817a150122b 760 case 7: mpFLRC.flrc.bitrateBandwidth = FLRC_BR_0_260_BW_0_3; break;
Wayne Roberts 1:0817a150122b 761 default:
Wayne Roberts 1:0817a150122b 762 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 763 }
Wayne Roberts 1:0817a150122b 764 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpFLRC.buf);
Wayne Roberts 1:0817a150122b 765 }
Wayne Roberts 1:0817a150122b 766
Wayne Roberts 1:0817a150122b 767 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 768 }
Wayne Roberts 1:0817a150122b 769
Wayne Roberts 3:56fc764dee0a 770 static const char* const gfsk_bpsbw[] = {
Wayne Roberts 1:0817a150122b 771 " 2.0Mbps 2.4MHz", //0 GFSK_BLE_BR_2_000_BW_2_4 0x04 // Mbps:2 bw:2.4MHz
Wayne Roberts 1:0817a150122b 772 " 1.6Mbps 2.4MHz", //1 GFSK_BLE_BR_1_600_BW_2_4 0x28 // Mbps:1.6 bw:2.4MHz
Wayne Roberts 1:0817a150122b 773 " 1.0Mbps 2.4MHz", //2 GFSK_BLE_BR_1_000_BW_2_4 0x4C // Mbps:1 bw:2.4MHz
Wayne Roberts 1:0817a150122b 774 " 1.0Mbps 1.2MHz", //3 GFSK_BLE_BR_1_000_BW_1_2 0x45 // Mbps:1 bw:1.2MHz
Wayne Roberts 1:0817a150122b 775 " 0.8Mbps 2.4MHz", //4 GFSK_BLE_BR_0_800_BW_2_4 0x70 // Mbps:0.8 bw:2.4MHz
Wayne Roberts 1:0817a150122b 776 " 0.8Mbps 1.2MHz", //5 GFSK_BLE_BR_0_800_BW_1_2 0x69 // Mbps:0.8 bw:1.2MHz
Wayne Roberts 1:0817a150122b 777 " 0.5Mbps 1.2MHz", //6 GFSK_BLE_BR_0_500_BW_1_2 0x8D // Mbps:0.5 bw:1.2MHz
Wayne Roberts 1:0817a150122b 778 " 0.5Mbps 0.6MHz", //7 GFSK_BLE_BR_0_500_BW_0_6 0x86 // Mbps:0.5 bw:0.6MHz
Wayne Roberts 1:0817a150122b 779 " 0.4Mbps 1.2MHz", //8 GFSK_BLE_BR_0_400_BW_1_2 0xB1 // Mbps:0.4 bw:1.2MHz
Wayne Roberts 1:0817a150122b 780 " 0.4Mbps 0.6MHz", //9 GFSK_BLE_BR_0_400_BW_0_6 0xAA // Mbps:0.4 bw:0.6MHz
Wayne Roberts 1:0817a150122b 781 " 0.25Mbps 0.6MHz", //10 GFSK_BLE_BR_0_250_BW_0_6 0xCE // Mbps:0.25 bw:0.6MHz
Wayne Roberts 1:0817a150122b 782 " 0.25Mbps 0.3MHz", //11 GFSK_BLE_BR_0_250_BW_0_3 0xC7 // Mbps:0.25 bw:0.3MHz
Wayne Roberts 1:0817a150122b 783 "0.125Mbps 0.3MHz", //12 GFSK_BLE_BR_0_125_BW_0_3 0xEF // Mbps:0.125 bw:0.3MHz
Wayne Roberts 1:0817a150122b 784 // 01234567890123456
Wayne Roberts 1:0817a150122b 785 NULL
Wayne Roberts 1:0817a150122b 786 };
Wayne Roberts 1:0817a150122b 787
Wayne Roberts 2:ea9245bb1c53 788 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 789
Wayne Roberts 1:0817a150122b 790 void Radio::modindex_print()
Wayne Roberts 1:0817a150122b 791 {
Wayne Roberts 1:0817a150122b 792 float mi, Mbps, fdev_hz;
Wayne Roberts 1:0817a150122b 793 unsigned bps, freqDev;
Wayne Roberts 1:0817a150122b 794 FskModDfH_t FskModDfH;
Wayne Roberts 1:0817a150122b 795 FloraPreambleHi_t FloraPreambleHi;
Wayne Roberts 1:0817a150122b 796
Wayne Roberts 1:0817a150122b 797 FloraPreambleHi.octet = radio.readReg(REG_ADDR_FLORA_PREAMBLE_HI, 1);
Wayne Roberts 1:0817a150122b 798 switch (FloraPreambleHi.bits.data_rate) {
Wayne Roberts 1:0817a150122b 799 case 0: Mbps = 2.0; break;
Wayne Roberts 1:0817a150122b 800 case 1: Mbps = 1.6; break;
Wayne Roberts 1:0817a150122b 801 case 2: Mbps = 1.0; break;
Wayne Roberts 1:0817a150122b 802 case 3: Mbps = 0.8; break;
Wayne Roberts 1:0817a150122b 803 case 4: Mbps = 0.5; break;
Wayne Roberts 1:0817a150122b 804 case 5: Mbps = 0.4; break;
Wayne Roberts 1:0817a150122b 805 case 6: Mbps = 0.25; break;
Wayne Roberts 1:0817a150122b 806 case 7: Mbps = 0.125; break;
Wayne Roberts 1:0817a150122b 807 }
Wayne Roberts 1:0817a150122b 808
Wayne Roberts 1:0817a150122b 809 FskModDfH.octet = radio.readReg(REG_ADDR_FSK_MODDFH, 1);
Wayne Roberts 1:0817a150122b 810 freqDev = FskModDfH.bits.freqDev;
Wayne Roberts 1:0817a150122b 811 freqDev <<= 8;
Wayne Roberts 1:0817a150122b 812 freqDev |= radio.readReg(REG_ADDR_FSK_MODDFL, 1);
Wayne Roberts 1:0817a150122b 813
Wayne Roberts 1:0817a150122b 814 fdev_hz = freqDev * PLL_STEP_HZ;
Wayne Roberts 1:0817a150122b 815 bps = Mbps * 1e6;
Wayne Roberts 1:0817a150122b 816 mi = (fdev_hz * 2.0) / bps;
Wayne Roberts 1:0817a150122b 817
dudmuck 13:8ce61a1897ab 818 printf("%.2f", mi);
Wayne Roberts 1:0817a150122b 819 }
Wayne Roberts 1:0817a150122b 820
Wayne Roberts 1:0817a150122b 821 bool Radio::modindex_write(const char* valStr)
Wayne Roberts 1:0817a150122b 822 {
Wayne Roberts 1:0817a150122b 823 float f;
Wayne Roberts 1:0817a150122b 824
Wayne Roberts 1:0817a150122b 825 if (sscanf(valStr, "%f", &f) == 1) {
Wayne Roberts 1:0817a150122b 826 log_printf("scanned %f from \"%s\"\r\n", f);
Wayne Roberts 1:0817a150122b 827 if (f > 0.35) {
Wayne Roberts 1:0817a150122b 828 f -= 0.5;
Wayne Roberts 1:0817a150122b 829 f /= 0.25;
Wayne Roberts 1:0817a150122b 830 log_printf("set modindex:%f\r\n", f);
Wayne Roberts 1:0817a150122b 831 mpBLE_GFSK.gfskBle.ModulationIndex = ((uint8_t)f) + 1;
Wayne Roberts 1:0817a150122b 832 log_printf("to set %02x\r\n", mpBLE_GFSK.gfskBle.ModulationIndex);
Wayne Roberts 1:0817a150122b 833 } else
Wayne Roberts 1:0817a150122b 834 mpBLE_GFSK.gfskBle.ModulationIndex = 0;
Wayne Roberts 1:0817a150122b 835
Wayne Roberts 1:0817a150122b 836 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpBLE_GFSK.buf);
Wayne Roberts 1:0817a150122b 837 }
Wayne Roberts 1:0817a150122b 838 return false;
Wayne Roberts 1:0817a150122b 839 }
Wayne Roberts 1:0817a150122b 840
Wayne Roberts 4:fa31fdf4ec8d 841 const value_item_t Radio::gfsk_modindex_item = { _ITEM_VALUE, 5, modindex_print, modindex_write };
Wayne Roberts 1:0817a150122b 842
Wayne Roberts 3:56fc764dee0a 843 static const char* const gfsk_flrc_bts[] = {
Wayne Roberts 1:0817a150122b 844 "off",
Wayne Roberts 1:0817a150122b 845 "1.0",
Wayne Roberts 1:0817a150122b 846 "0.5",
Wayne Roberts 1:0817a150122b 847 "0.3",
Wayne Roberts 1:0817a150122b 848 NULL
Wayne Roberts 1:0817a150122b 849 };
Wayne Roberts 1:0817a150122b 850
Wayne Roberts 2:ea9245bb1c53 851 unsigned Radio::gfsk_flrc_bt_read(bool fw)
Wayne Roberts 1:0817a150122b 852 {
Wayne Roberts 1:0817a150122b 853 FskCfg_t FskCfg;
Wayne Roberts 1:0817a150122b 854 FskCfg.octet = radio.readReg(REG_ADDR_FSK_CFG, 1);
Wayne Roberts 1:0817a150122b 855 return FskCfg.bits.gf_bt;
Wayne Roberts 1:0817a150122b 856 }
Wayne Roberts 1:0817a150122b 857
Wayne Roberts 2:ea9245bb1c53 858 menuMode_e Radio::gfsk_flrc_bt_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 859 {
Wayne Roberts 1:0817a150122b 860 mpBLE_GFSK.gfskBle.ModulationShaping = sidx << 4;
Wayne Roberts 1:0817a150122b 861 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpBLE_GFSK.buf);
Wayne Roberts 1:0817a150122b 862 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 863 }
Wayne Roberts 1:0817a150122b 864
Wayne Roberts 2:ea9245bb1c53 865 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 866
Wayne Roberts 3:56fc764dee0a 867 static const char* const gfsk_flrc_pblLens[] = {
Wayne Roberts 1:0817a150122b 868 "4",
Wayne Roberts 1:0817a150122b 869 "8",
Wayne Roberts 1:0817a150122b 870 "12",
Wayne Roberts 1:0817a150122b 871 "16",
Wayne Roberts 1:0817a150122b 872 "20",
Wayne Roberts 1:0817a150122b 873 "24",
Wayne Roberts 1:0817a150122b 874 "28",
Wayne Roberts 1:0817a150122b 875 "32",
Wayne Roberts 1:0817a150122b 876 NULL,
Wayne Roberts 1:0817a150122b 877 };
Wayne Roberts 1:0817a150122b 878
Wayne Roberts 2:ea9245bb1c53 879 unsigned Radio::gfsk_flrc_pl_read(bool fw)
Wayne Roberts 1:0817a150122b 880 {
Wayne Roberts 1:0817a150122b 881 PktCtrl1_t PktCtrl1;
Wayne Roberts 1:0817a150122b 882 PktCtrl1.octet = radio.readReg(REG_ADDR_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 883 ppFLRC.gfskFLRC.PreambleLength = PktCtrl1.octet & 0x70;
Wayne Roberts 1:0817a150122b 884 ppGFSK.gfskFLRC.PreambleLength = ppFLRC.gfskFLRC.PreambleLength;
Wayne Roberts 1:0817a150122b 885 return PktCtrl1.gfsk.preamble_len;
Wayne Roberts 1:0817a150122b 886 }
Wayne Roberts 1:0817a150122b 887
Wayne Roberts 2:ea9245bb1c53 888 menuMode_e Radio::gfsk_flrc_pl_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 889 {
Wayne Roberts 1:0817a150122b 890 ppFLRC.gfskFLRC.PreambleLength = sidx << 4;
Wayne Roberts 1:0817a150122b 891 ppGFSK.gfskFLRC.PreambleLength = ppFLRC.gfskFLRC.PreambleLength;
Wayne Roberts 1:0817a150122b 892 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 893 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 894 }
Wayne Roberts 1:0817a150122b 895
Wayne Roberts 2:ea9245bb1c53 896 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 897
Wayne Roberts 3:56fc764dee0a 898 static const char* const gfsk_syncLens[] = {
Wayne Roberts 1:0817a150122b 899 "1", // 0
Wayne Roberts 1:0817a150122b 900 "2", // 1
Wayne Roberts 1:0817a150122b 901 "3", // 2
Wayne Roberts 1:0817a150122b 902 "4", // 3
Wayne Roberts 1:0817a150122b 903 "5", // 4
Wayne Roberts 1:0817a150122b 904 NULL,
Wayne Roberts 1:0817a150122b 905 };
Wayne Roberts 1:0817a150122b 906
Wayne Roberts 2:ea9245bb1c53 907 unsigned Radio::gfsk_synclen_read(bool fw)
Wayne Roberts 1:0817a150122b 908 {
Wayne Roberts 1:0817a150122b 909 PktCtrl1_t PktCtrl1;
Wayne Roberts 1:0817a150122b 910 PktCtrl1.octet = radio.readReg(REG_ADDR_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 911
Wayne Roberts 1:0817a150122b 912 ppGFSK.gfskFLRC.SyncWordLength = PktCtrl1.octet & 0x0e;
Wayne Roberts 1:0817a150122b 913 ppFLRC.gfskFLRC.SyncWordLength = PktCtrl1.octet & 0x06;
Wayne Roberts 1:0817a150122b 914
Wayne Roberts 1:0817a150122b 915 return PktCtrl1.gfsk.sync_adrs_len;
Wayne Roberts 1:0817a150122b 916 }
Wayne Roberts 1:0817a150122b 917
Wayne Roberts 2:ea9245bb1c53 918 menuMode_e Radio::gfsk_synclen_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 919 {
Wayne Roberts 1:0817a150122b 920 ppGFSK.gfskFLRC.SyncWordLength = sidx << 1;
Wayne Roberts 1:0817a150122b 921 //log_printf("SWL %u %02x\r\n", sidx, ppGFSK.gfskFLRC.SyncWordLength);
Wayne Roberts 1:0817a150122b 922 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 923 //return MENUMODE_NONE;
Wayne Roberts 1:0817a150122b 924 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 925 }
Wayne Roberts 1:0817a150122b 926
Wayne Roberts 2:ea9245bb1c53 927 const dropdown_item_t Radio::gfsk_synclen_item = { _ITEM_DROPDOWN, gfsk_syncLens, gfsk_syncLens, gfsk_synclen_read, gfsk_synclen_write};
Wayne Roberts 1:0817a150122b 928
Wayne Roberts 1:0817a150122b 929 bool Radio::gfsk_flrc_fixvar_read()
Wayne Roberts 1:0817a150122b 930 {
Wayne Roberts 1:0817a150122b 931 PktCtrl0_t PktCtrl0;
Wayne Roberts 1:0817a150122b 932 PktCtrl0.octet = radio.readReg(REG_ADDR_PKTCTRL0, 1);
Wayne Roberts 1:0817a150122b 933
Wayne Roberts 1:0817a150122b 934 ppGFSK.gfskFLRC.HeaderType = PktCtrl0.octet & 0x20;
Wayne Roberts 1:0817a150122b 935 ppFLRC.gfskFLRC.HeaderType = PktCtrl0.octet & 0x20;
Wayne Roberts 1:0817a150122b 936
Wayne Roberts 1:0817a150122b 937 return PktCtrl0.bits.pkt_len_format;
Wayne Roberts 1:0817a150122b 938 }
Wayne Roberts 1:0817a150122b 939
Wayne Roberts 1:0817a150122b 940 bool Radio::gfsk_flrc_fixvar_push()
Wayne Roberts 1:0817a150122b 941 {
Wayne Roberts 1:0817a150122b 942 PacketParams_t* pp;
Wayne Roberts 1:0817a150122b 943 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 944
Wayne Roberts 1:0817a150122b 945 if (pktType == PACKET_TYPE_FLRC)
Wayne Roberts 1:0817a150122b 946 pp = &ppFLRC;
Wayne Roberts 1:0817a150122b 947 else if (pktType == PACKET_TYPE_GFSK)
Wayne Roberts 1:0817a150122b 948 pp = &ppGFSK;
Wayne Roberts 1:0817a150122b 949 else
Wayne Roberts 1:0817a150122b 950 return false;
Wayne Roberts 1:0817a150122b 951
Wayne Roberts 1:0817a150122b 952 if (pp->gfskFLRC.HeaderType == RADIO_PACKET_VARIABLE_LENGTH)
Wayne Roberts 1:0817a150122b 953 pp->gfskFLRC.HeaderType = RADIO_PACKET_FIXED_LENGTH;
Wayne Roberts 1:0817a150122b 954 else
Wayne Roberts 1:0817a150122b 955 pp->gfskFLRC.HeaderType = RADIO_PACKET_VARIABLE_LENGTH;
Wayne Roberts 1:0817a150122b 956
Wayne Roberts 1:0817a150122b 957 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, pp->buf);
Wayne Roberts 1:0817a150122b 958
Wayne Roberts 1:0817a150122b 959 return pp->gfskFLRC.HeaderType == RADIO_PACKET_VARIABLE_LENGTH;
Wayne Roberts 1:0817a150122b 960 }
Wayne Roberts 1:0817a150122b 961
Wayne Roberts 1:0817a150122b 962 const toggle_item_t Radio::gfsk_flrc_fixvar_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 963 "fixed ",
Wayne Roberts 1:0817a150122b 964 "variable",
Wayne Roberts 1:0817a150122b 965 gfsk_flrc_fixvar_read, gfsk_flrc_fixvar_push
Wayne Roberts 1:0817a150122b 966 };
Wayne Roberts 1:0817a150122b 967
Wayne Roberts 3:56fc764dee0a 968 static const char* const gfsk_flrc_crclens[] = {
Wayne Roberts 1:0817a150122b 969 "0 off",
Wayne Roberts 1:0817a150122b 970 "1 byte",
Wayne Roberts 1:0817a150122b 971 "2 bytes",
Wayne Roberts 1:0817a150122b 972 NULL,
Wayne Roberts 1:0817a150122b 973 };
Wayne Roberts 1:0817a150122b 974
Wayne Roberts 2:ea9245bb1c53 975 unsigned Radio::gfsk_flrc_crclen_read(bool fw)
Wayne Roberts 1:0817a150122b 976 {
Wayne Roberts 1:0817a150122b 977 PktBitStreamCtrl_t PktBitStreamCtrl;
Wayne Roberts 1:0817a150122b 978 PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 979 ppGFSK.gfskFLRC.CRCLength = PktBitStreamCtrl.octet & 0x30;
Wayne Roberts 1:0817a150122b 980 return PktBitStreamCtrl.bits.crc_mode;
Wayne Roberts 1:0817a150122b 981 }
Wayne Roberts 1:0817a150122b 982
Wayne Roberts 2:ea9245bb1c53 983 menuMode_e Radio::gfsk_flrc_crclen_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 984 {
Wayne Roberts 1:0817a150122b 985 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 986
Wayne Roberts 1:0817a150122b 987 ppGFSK.gfskFLRC.CRCLength = (sidx & 3) << 4;
Wayne Roberts 1:0817a150122b 988 ppFLRC.gfskFLRC.CRCLength = (sidx & 3) << 4;
Wayne Roberts 1:0817a150122b 989
Wayne Roberts 1:0817a150122b 990 if (pktType == PACKET_TYPE_GFSK)
Wayne Roberts 1:0817a150122b 991 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 992 else if (pktType == PACKET_TYPE_FLRC)
Wayne Roberts 1:0817a150122b 993 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppFLRC.buf);
Wayne Roberts 1:0817a150122b 994
Wayne Roberts 1:0817a150122b 995 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 996 }
Wayne Roberts 1:0817a150122b 997
Wayne Roberts 2:ea9245bb1c53 998 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 999
Wayne Roberts 1:0817a150122b 1000 bool Radio::gfsk_flrc_whit_read()
Wayne Roberts 1:0817a150122b 1001 {
Wayne Roberts 1:0817a150122b 1002 PktBitStreamCtrl_t PktBitStreamCtrl;
Wayne Roberts 1:0817a150122b 1003 PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 1004 ppGFSK.gfskFLRC.Whitening = PktBitStreamCtrl.octet & 0x08;
Wayne Roberts 1:0817a150122b 1005 ppFLRC.gfskFLRC.Whitening = PktBitStreamCtrl.octet & 0x08;
Wayne Roberts 1:0817a150122b 1006 return PktBitStreamCtrl.bits.whit_disable;
Wayne Roberts 1:0817a150122b 1007 }
Wayne Roberts 1:0817a150122b 1008
Wayne Roberts 1:0817a150122b 1009 bool Radio::gfsk_flrc_whit_push()
Wayne Roberts 1:0817a150122b 1010 {
Wayne Roberts 1:0817a150122b 1011 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 1012
Wayne Roberts 1:0817a150122b 1013 if (ppGFSK.gfskFLRC.Whitening == WHITENING_DISABLE)
Wayne Roberts 1:0817a150122b 1014 ppGFSK.gfskFLRC.Whitening = WHITENING_ENABLE;
Wayne Roberts 1:0817a150122b 1015 else
Wayne Roberts 1:0817a150122b 1016 ppGFSK.gfskFLRC.Whitening = WHITENING_DISABLE;
Wayne Roberts 1:0817a150122b 1017
Wayne Roberts 1:0817a150122b 1018 ppFLRC.gfskFLRC.Whitening = ppGFSK.gfskFLRC.Whitening;
Wayne Roberts 1:0817a150122b 1019
Wayne Roberts 1:0817a150122b 1020 if (pktType == PACKET_TYPE_GFSK)
Wayne Roberts 1:0817a150122b 1021 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1022 else if (pktType == PACKET_TYPE_FLRC)
Wayne Roberts 1:0817a150122b 1023 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppFLRC.buf);
Wayne Roberts 1:0817a150122b 1024
Wayne Roberts 1:0817a150122b 1025 return ppGFSK.gfskFLRC.Whitening == WHITENING_DISABLE;
Wayne Roberts 1:0817a150122b 1026 }
Wayne Roberts 1:0817a150122b 1027
Wayne Roberts 1:0817a150122b 1028 const toggle_item_t Radio::gfsk_flrc_whit_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1029 "ENABLE ",
Wayne Roberts 1:0817a150122b 1030 "DISABLE",
Wayne Roberts 1:0817a150122b 1031 gfsk_flrc_whit_read, gfsk_flrc_whit_push
Wayne Roberts 1:0817a150122b 1032 };
Wayne Roberts 1:0817a150122b 1033
Wayne Roberts 1:0817a150122b 1034 void Radio::gfsk_flrc_crcinit_print()
Wayne Roberts 1:0817a150122b 1035 {
Wayne Roberts 1:0817a150122b 1036 unsigned val = radio.readReg(0x9c8, 2);
dudmuck 13:8ce61a1897ab 1037 printf("0x%04x", val);
Wayne Roberts 1:0817a150122b 1038 }
Wayne Roberts 1:0817a150122b 1039
Wayne Roberts 1:0817a150122b 1040 bool Radio::gfsk_flrc_crcinit_write(const char* txt)
Wayne Roberts 1:0817a150122b 1041 {
Wayne Roberts 1:0817a150122b 1042 unsigned val;
Wayne Roberts 1:0817a150122b 1043 sscanf(txt, "%x", &val);
Wayne Roberts 1:0817a150122b 1044 radio.writeReg(0x9c8, val, 2);
Wayne Roberts 1:0817a150122b 1045 return false;
Wayne Roberts 1:0817a150122b 1046 }
Wayne Roberts 1:0817a150122b 1047
Wayne Roberts 1:0817a150122b 1048 const value_item_t Radio::gfsk_flrc_crcinit_item = { _ITEM_VALUE, 7, gfsk_flrc_crcinit_print, gfsk_flrc_crcinit_write };
Wayne Roberts 1:0817a150122b 1049
Wayne Roberts 1:0817a150122b 1050 void Radio::gfsk_flrc_crcpoly_print(void)
Wayne Roberts 1:0817a150122b 1051 {
Wayne Roberts 1:0817a150122b 1052 unsigned val = radio.readReg(0x9c6, 2);
dudmuck 13:8ce61a1897ab 1053 printf("0x%04x", val);
Wayne Roberts 1:0817a150122b 1054 }
Wayne Roberts 1:0817a150122b 1055
Wayne Roberts 1:0817a150122b 1056 bool Radio::gfsk_flrc_crcpoly_write(const char* txt)
Wayne Roberts 1:0817a150122b 1057 {
Wayne Roberts 1:0817a150122b 1058 unsigned val;
Wayne Roberts 1:0817a150122b 1059 sscanf(txt, "%x", &val);
Wayne Roberts 1:0817a150122b 1060 radio.writeReg(0x9c6, val, 2);
Wayne Roberts 1:0817a150122b 1061 return false;
Wayne Roberts 1:0817a150122b 1062 }
Wayne Roberts 1:0817a150122b 1063
Wayne Roberts 1:0817a150122b 1064 const value_item_t Radio::gfsk_flrc_crcpoly_item = { _ITEM_VALUE, 7, gfsk_flrc_crcpoly_print, gfsk_flrc_crcpoly_write };
Wayne Roberts 1:0817a150122b 1065
Wayne Roberts 1:0817a150122b 1066 bool Radio::gfsk_flrc_sync1en_read()
Wayne Roberts 1:0817a150122b 1067 {
Wayne Roberts 1:0817a150122b 1068 PktSyncAdrs_t PktSyncAdrs;
Wayne Roberts 1:0817a150122b 1069 PktSyncAdrs.octet = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1);
Wayne Roberts 1:0817a150122b 1070
Wayne Roberts 1:0817a150122b 1071 ppGFSK.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1072 ppFLRC.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1073
Wayne Roberts 1:0817a150122b 1074 return PktSyncAdrs.gfskflrc.sync_addr_mask & 1;
Wayne Roberts 1:0817a150122b 1075 }
Wayne Roberts 1:0817a150122b 1076
Wayne Roberts 1:0817a150122b 1077 bool Radio::gfsk_flrc_sync2en_read()
Wayne Roberts 1:0817a150122b 1078 {
Wayne Roberts 1:0817a150122b 1079 PktSyncAdrs_t PktSyncAdrs;
Wayne Roberts 1:0817a150122b 1080 PktSyncAdrs.octet = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1);
Wayne Roberts 1:0817a150122b 1081
Wayne Roberts 1:0817a150122b 1082 ppGFSK.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1083 ppFLRC.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1084
Wayne Roberts 1:0817a150122b 1085 return ppGFSK.gfskFLRC.SyncWordMatch & 0x20;
Wayne Roberts 1:0817a150122b 1086 }
Wayne Roberts 1:0817a150122b 1087
Wayne Roberts 1:0817a150122b 1088 bool Radio::gfsk_flrc_sync3en_read()
Wayne Roberts 1:0817a150122b 1089 {
Wayne Roberts 1:0817a150122b 1090 PktSyncAdrs_t PktSyncAdrs;
Wayne Roberts 1:0817a150122b 1091 PktSyncAdrs.octet = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_CTRL, 1);
Wayne Roberts 1:0817a150122b 1092
Wayne Roberts 1:0817a150122b 1093 ppGFSK.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1094 ppFLRC.gfskFLRC.SyncWordMatch = PktSyncAdrs.octet & 0x70;
Wayne Roberts 1:0817a150122b 1095
Wayne Roberts 1:0817a150122b 1096 return ppGFSK.gfskFLRC.SyncWordMatch & 0x40;
Wayne Roberts 1:0817a150122b 1097 //return PktSyncAdrs.gfskflrc.sync_addr_mask & 4;
Wayne Roberts 1:0817a150122b 1098 }
Wayne Roberts 1:0817a150122b 1099
Wayne Roberts 1:0817a150122b 1100 bool Radio::gfsk_flrc_sync1en_push()
Wayne Roberts 1:0817a150122b 1101 {
Wayne Roberts 1:0817a150122b 1102 if (ppGFSK.gfskFLRC.SyncWordMatch & 0x10)
Wayne Roberts 1:0817a150122b 1103 ppGFSK.gfskFLRC.SyncWordMatch &= ~0x10;
Wayne Roberts 1:0817a150122b 1104 else
Wayne Roberts 1:0817a150122b 1105 ppGFSK.gfskFLRC.SyncWordMatch |= 0x10;
Wayne Roberts 1:0817a150122b 1106
Wayne Roberts 1:0817a150122b 1107 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1108
Wayne Roberts 1:0817a150122b 1109 ppFLRC.gfskFLRC.SyncWordMatch = ppGFSK.gfskFLRC.SyncWordMatch;
Wayne Roberts 1:0817a150122b 1110
Wayne Roberts 1:0817a150122b 1111 return ppGFSK.gfskFLRC.SyncWordMatch & 0x10;
Wayne Roberts 1:0817a150122b 1112 }
Wayne Roberts 1:0817a150122b 1113
Wayne Roberts 1:0817a150122b 1114 bool Radio::gfsk_flrc_sync2en_push()
Wayne Roberts 1:0817a150122b 1115 {
Wayne Roberts 1:0817a150122b 1116 if (ppGFSK.gfskFLRC.SyncWordMatch & 0x20)
Wayne Roberts 1:0817a150122b 1117 ppGFSK.gfskFLRC.SyncWordMatch &= ~0x20;
Wayne Roberts 1:0817a150122b 1118 else
Wayne Roberts 1:0817a150122b 1119 ppGFSK.gfskFLRC.SyncWordMatch |= 0x20;
Wayne Roberts 1:0817a150122b 1120
Wayne Roberts 1:0817a150122b 1121 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1122
Wayne Roberts 1:0817a150122b 1123 ppFLRC.gfskFLRC.SyncWordMatch = ppGFSK.gfskFLRC.SyncWordMatch;
Wayne Roberts 1:0817a150122b 1124
Wayne Roberts 1:0817a150122b 1125 return ppGFSK.gfskFLRC.SyncWordMatch & 0x20;
Wayne Roberts 1:0817a150122b 1126 }
Wayne Roberts 1:0817a150122b 1127
Wayne Roberts 1:0817a150122b 1128 bool Radio::gfsk_flrc_sync3en_push()
Wayne Roberts 1:0817a150122b 1129 {
Wayne Roberts 1:0817a150122b 1130 if (ppGFSK.gfskFLRC.SyncWordMatch & 0x40)
Wayne Roberts 1:0817a150122b 1131 ppGFSK.gfskFLRC.SyncWordMatch &= ~0x40;
Wayne Roberts 1:0817a150122b 1132 else
Wayne Roberts 1:0817a150122b 1133 ppGFSK.gfskFLRC.SyncWordMatch |= 0x40;
Wayne Roberts 1:0817a150122b 1134
Wayne Roberts 1:0817a150122b 1135 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppGFSK.buf);
Wayne Roberts 1:0817a150122b 1136
Wayne Roberts 1:0817a150122b 1137 ppFLRC.gfskFLRC.SyncWordMatch = ppGFSK.gfskFLRC.SyncWordMatch;
Wayne Roberts 1:0817a150122b 1138
Wayne Roberts 1:0817a150122b 1139 return ppGFSK.gfskFLRC.SyncWordMatch & 0x40;
Wayne Roberts 1:0817a150122b 1140 }
Wayne Roberts 1:0817a150122b 1141
Wayne Roberts 1:0817a150122b 1142 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 1143 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 1144 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 1145
Wayne Roberts 1:0817a150122b 1146 void Radio::gfsk_flrc_sync1_print(void)
Wayne Roberts 1:0817a150122b 1147 {
Wayne Roberts 1:0817a150122b 1148 uint64_t val;
Wayne Roberts 1:0817a150122b 1149 uint32_t val32 = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_1+1, 4);
Wayne Roberts 1:0817a150122b 1150 uint32_t upper = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_1, 1);
Wayne Roberts 1:0817a150122b 1151 val = upper;
Wayne Roberts 1:0817a150122b 1152 val <<= 32;
Wayne Roberts 1:0817a150122b 1153 val |= val32;
dudmuck 13:8ce61a1897ab 1154 printf("%llx", val);
Wayne Roberts 1:0817a150122b 1155 }
Wayne Roberts 1:0817a150122b 1156
Wayne Roberts 1:0817a150122b 1157 void Radio::gfsk_flrc_sync2_print(void)
Wayne Roberts 1:0817a150122b 1158 {
Wayne Roberts 1:0817a150122b 1159 uint64_t val;
Wayne Roberts 1:0817a150122b 1160 uint32_t val32 = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_2+1, 4);
Wayne Roberts 1:0817a150122b 1161 uint32_t upper = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_2, 1);
Wayne Roberts 1:0817a150122b 1162 val = upper;
Wayne Roberts 1:0817a150122b 1163 val <<= 32;
Wayne Roberts 1:0817a150122b 1164 val |= val32;
dudmuck 13:8ce61a1897ab 1165 printf("%llx", val);
Wayne Roberts 1:0817a150122b 1166 }
Wayne Roberts 1:0817a150122b 1167
Wayne Roberts 1:0817a150122b 1168 void Radio::gfsk_flrc_sync3_print(void)
Wayne Roberts 1:0817a150122b 1169 {
Wayne Roberts 1:0817a150122b 1170 uint64_t val;
Wayne Roberts 1:0817a150122b 1171 uint32_t val32 = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_3+1, 4);
Wayne Roberts 1:0817a150122b 1172 uint32_t upper = radio.readReg(REG_ADDR_PKT_SYNC_ADRS_3, 1);
Wayne Roberts 1:0817a150122b 1173 val = upper;
Wayne Roberts 1:0817a150122b 1174 val <<= 32;
Wayne Roberts 1:0817a150122b 1175 val |= val32;
dudmuck 13:8ce61a1897ab 1176 printf("%llx", val);
Wayne Roberts 1:0817a150122b 1177 }
Wayne Roberts 1:0817a150122b 1178
Wayne Roberts 1:0817a150122b 1179 bool Radio::gfsk_flrc_sync1_write(const char* txt)
Wayne Roberts 1:0817a150122b 1180 {
Wayne Roberts 1:0817a150122b 1181 uint32_t val32, upper;
Wayne Roberts 1:0817a150122b 1182 uint64_t val;
Wayne Roberts 1:0817a150122b 1183 sscanf(txt, "%llx", &val);
Wayne Roberts 1:0817a150122b 1184
Wayne Roberts 1:0817a150122b 1185 val32 = val;
Wayne Roberts 1:0817a150122b 1186 val >>= 32;
Wayne Roberts 1:0817a150122b 1187 upper = val;
Wayne Roberts 1:0817a150122b 1188
Wayne Roberts 1:0817a150122b 1189 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_1, upper, 1);
Wayne Roberts 1:0817a150122b 1190 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_1+1, val32, 4);
Wayne Roberts 1:0817a150122b 1191
Wayne Roberts 1:0817a150122b 1192 return false;
Wayne Roberts 1:0817a150122b 1193 }
Wayne Roberts 1:0817a150122b 1194
Wayne Roberts 1:0817a150122b 1195 bool Radio::gfsk_flrc_sync2_write(const char* txt)
Wayne Roberts 1:0817a150122b 1196 {
Wayne Roberts 1:0817a150122b 1197 uint32_t val32, upper;
Wayne Roberts 1:0817a150122b 1198 uint64_t val;
Wayne Roberts 1:0817a150122b 1199 sscanf(txt, "%llx", &val);
Wayne Roberts 1:0817a150122b 1200
Wayne Roberts 1:0817a150122b 1201 val32 = val;
Wayne Roberts 1:0817a150122b 1202 val >>= 32;
Wayne Roberts 1:0817a150122b 1203 upper = val;
Wayne Roberts 1:0817a150122b 1204
Wayne Roberts 1:0817a150122b 1205 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_2, upper, 1);
Wayne Roberts 1:0817a150122b 1206 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_2+1, val32, 4);
Wayne Roberts 1:0817a150122b 1207
Wayne Roberts 1:0817a150122b 1208 return false;
Wayne Roberts 1:0817a150122b 1209 }
Wayne Roberts 1:0817a150122b 1210
Wayne Roberts 1:0817a150122b 1211 bool Radio::gfsk_flrc_sync3_write(const char* txt)
Wayne Roberts 1:0817a150122b 1212 {
Wayne Roberts 1:0817a150122b 1213 uint32_t val32, upper;
Wayne Roberts 1:0817a150122b 1214 uint64_t val;
Wayne Roberts 1:0817a150122b 1215 sscanf(txt, "%llx", &val);
Wayne Roberts 1:0817a150122b 1216
Wayne Roberts 1:0817a150122b 1217 val32 = val;
Wayne Roberts 1:0817a150122b 1218 val >>= 32;
Wayne Roberts 1:0817a150122b 1219 upper = val;
Wayne Roberts 1:0817a150122b 1220
Wayne Roberts 1:0817a150122b 1221 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_3, upper, 1);
Wayne Roberts 1:0817a150122b 1222 radio.writeReg(REG_ADDR_PKT_SYNC_ADRS_3+1, val32, 4);
Wayne Roberts 1:0817a150122b 1223
Wayne Roberts 1:0817a150122b 1224 return false;
Wayne Roberts 1:0817a150122b 1225 }
Wayne Roberts 1:0817a150122b 1226
Wayne Roberts 1:0817a150122b 1227 const value_item_t Radio::gfsk_flrc_sync1_item = { _ITEM_VALUE, 10, gfsk_flrc_sync1_print, gfsk_flrc_sync1_write };
Wayne Roberts 1:0817a150122b 1228 const value_item_t Radio::gfsk_flrc_sync2_item = { _ITEM_VALUE, 10, gfsk_flrc_sync2_print, gfsk_flrc_sync2_write };
Wayne Roberts 1:0817a150122b 1229 const value_item_t Radio::gfsk_flrc_sync3_item = { _ITEM_VALUE, 10, gfsk_flrc_sync3_print, gfsk_flrc_sync3_write };
Wayne Roberts 1:0817a150122b 1230
Wayne Roberts 1:0817a150122b 1231
Wayne Roberts 1:0817a150122b 1232 const menu_t Radio::gfsk_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1233 { {FIRST_CHIP_MENU_ROW+1, 1}, NULL, &gfsk_bitrate_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1234 { {FIRST_CHIP_MENU_ROW+1, 19}, "mod index:", &gfsk_modindex_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1235 { {FIRST_CHIP_MENU_ROW+1, 35}, "BT:", &gfsk_flrc_bt_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1236 { {FIRST_CHIP_MENU_ROW+1, 43}, "PreambleLength:", &gfsk_flrc_preamble_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1237 { {FIRST_CHIP_MENU_ROW+1, 61}, "SyncLength:", &gfsk_synclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1238
Wayne Roberts 4:fa31fdf4ec8d 1239 { {FIRST_CHIP_MENU_ROW+2, 1}, "Length:", &gfsk_flrc_fixvar_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1240 { {FIRST_CHIP_MENU_ROW+2, 18}, "crcLength:", &gfsk_flrc_crclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1241 { {FIRST_CHIP_MENU_ROW+2, 37}, "whitening:", &gfsk_flrc_whit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1242 { {FIRST_CHIP_MENU_ROW+2, 57}, "crcInit:", &gfsk_flrc_crcinit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1243 { {FIRST_CHIP_MENU_ROW+2, 72}, "poly:", &gfsk_flrc_crcpoly_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1244
Wayne Roberts 4:fa31fdf4ec8d 1245 { {FIRST_CHIP_MENU_ROW+3, 1}, "sync1 ", &gfsk_flrc_sync1en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1246 { {FIRST_CHIP_MENU_ROW+3, 15}, NULL, &gfsk_flrc_sync1_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1247 { {FIRST_CHIP_MENU_ROW+3, 27}, "sync2 ", &gfsk_flrc_sync2en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1248 { {FIRST_CHIP_MENU_ROW+3, 41}, NULL, &gfsk_flrc_sync2_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1249 { {FIRST_CHIP_MENU_ROW+3, 53}, "sync3 ", &gfsk_flrc_sync3en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1250 { {FIRST_CHIP_MENU_ROW+3, 65}, NULL, &gfsk_flrc_sync3_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1251
Wayne Roberts 1:0817a150122b 1252 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1253 };
Wayne Roberts 1:0817a150122b 1254
Wayne Roberts 3:56fc764dee0a 1255 static const char* const flrc_bpsbw[] = {
Wayne Roberts 1:0817a150122b 1256 "2.6",
Wayne Roberts 1:0817a150122b 1257 "2.08",
Wayne Roberts 1:0817a150122b 1258 "1.3Mb/s 1.2MHz",
Wayne Roberts 1:0817a150122b 1259 "1.04Mb/s 1.2MHz",
Wayne Roberts 1:0817a150122b 1260 "0.65Mb/s 0.6MHz",
Wayne Roberts 1:0817a150122b 1261 "0.52Mb/s 0.6MHz",
Wayne Roberts 1:0817a150122b 1262 "0.325Mb/s 0.3MHz",
Wayne Roberts 1:0817a150122b 1263 "0.26Mb/s 0.3MHz",
Wayne Roberts 1:0817a150122b 1264 NULL
Wayne Roberts 1:0817a150122b 1265 };
Wayne Roberts 1:0817a150122b 1266
Wayne Roberts 2:ea9245bb1c53 1267 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 1268
Wayne Roberts 3:56fc764dee0a 1269 static const char* const flrc_crs[] = {
Wayne Roberts 1:0817a150122b 1270 "1/2",
Wayne Roberts 1:0817a150122b 1271 "3/4",
Wayne Roberts 1:0817a150122b 1272 "1 ",
Wayne Roberts 1:0817a150122b 1273 NULL
Wayne Roberts 1:0817a150122b 1274 };
Wayne Roberts 2:ea9245bb1c53 1275 unsigned Radio::flrc_cr_read(bool fw)
Wayne Roberts 1:0817a150122b 1276 {
Wayne Roberts 1:0817a150122b 1277 PktBitStreamCtrl_t PktBitStreamCtrl;
Wayne Roberts 1:0817a150122b 1278 PktBitStreamCtrl.octet = radio.readReg(REG_ADDR_PKT_BITSTREAM_CTRL, 1);
Wayne Roberts 1:0817a150122b 1279
Wayne Roberts 1:0817a150122b 1280 mpFLRC.flrc.CodingRate = PktBitStreamCtrl.octet & 0x06; // PktBitStreamCtrl.bits.flora_coding_rate
Wayne Roberts 1:0817a150122b 1281
Wayne Roberts 1:0817a150122b 1282 return PktBitStreamCtrl.bits.flora_coding_rate;
Wayne Roberts 1:0817a150122b 1283 }
Wayne Roberts 1:0817a150122b 1284
Wayne Roberts 2:ea9245bb1c53 1285 menuMode_e Radio::flrc_cr_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1286 {
Wayne Roberts 1:0817a150122b 1287 mpFLRC.flrc.CodingRate = sidx << 1;
Wayne Roberts 1:0817a150122b 1288 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpFLRC.buf);
Wayne Roberts 1:0817a150122b 1289 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1290 }
Wayne Roberts 1:0817a150122b 1291
Wayne Roberts 2:ea9245bb1c53 1292 const dropdown_item_t Radio::flrc_cr_item = { _ITEM_DROPDOWN, flrc_crs, flrc_crs, flrc_cr_read, flrc_cr_write};
Wayne Roberts 1:0817a150122b 1293
Wayne Roberts 3:56fc764dee0a 1294 static const char* const flrc_syncLens[] = {
Wayne Roberts 1:0817a150122b 1295 "SYNC OFF ",
Wayne Roberts 1:0817a150122b 1296 "16BIT SYNC",
Wayne Roberts 1:0817a150122b 1297 "32BIT SYNC",
Wayne Roberts 1:0817a150122b 1298 NULL
Wayne Roberts 1:0817a150122b 1299 };
Wayne Roberts 1:0817a150122b 1300
Wayne Roberts 2:ea9245bb1c53 1301 unsigned Radio::flrc_synclen_read(bool fw)
Wayne Roberts 1:0817a150122b 1302 {
Wayne Roberts 1:0817a150122b 1303 PktCtrl1_t PktCtrl1;
Wayne Roberts 1:0817a150122b 1304 PktCtrl1.octet = radio.readReg(REG_ADDR_PKTCTRL1, 1);
Wayne Roberts 1:0817a150122b 1305 ppFLRC.gfskFLRC.SyncWordLength = PktCtrl1.octet & 0x06;
Wayne Roberts 1:0817a150122b 1306 if (ppFLRC.gfskFLRC.SyncWordLength == 0x06) {
Wayne Roberts 1:0817a150122b 1307 ppFLRC.gfskFLRC.SyncWordLength = FLRC_SYNC_WORD_LEN_P32S;
Wayne Roberts 1:0817a150122b 1308 return 2;
Wayne Roberts 1:0817a150122b 1309 }
Wayne Roberts 1:0817a150122b 1310
Wayne Roberts 1:0817a150122b 1311 return PktCtrl1.flrc.sync_adrs_len;
Wayne Roberts 1:0817a150122b 1312 }
Wayne Roberts 1:0817a150122b 1313
Wayne Roberts 2:ea9245bb1c53 1314 menuMode_e Radio::flrc_synclen_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1315 {
Wayne Roberts 1:0817a150122b 1316 ppFLRC.gfskFLRC.SyncWordLength = sidx << 1;
Wayne Roberts 1:0817a150122b 1317 radio.xfer(OPCODE_SET_PACKET_PARAMS, 7, 0, ppFLRC.buf);
Wayne Roberts 1:0817a150122b 1318 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1319 }
Wayne Roberts 1:0817a150122b 1320
Wayne Roberts 2:ea9245bb1c53 1321 const dropdown_item_t Radio::flrc_synclen_item = { _ITEM_DROPDOWN, flrc_syncLens, flrc_syncLens, flrc_synclen_read, flrc_synclen_write};
Wayne Roberts 1:0817a150122b 1322
Wayne Roberts 1:0817a150122b 1323
Wayne Roberts 1:0817a150122b 1324 const menu_t Radio::flrc_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1325 { {FIRST_CHIP_MENU_ROW+1, 1}, NULL, &flrc_bitrate_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1326 { {FIRST_CHIP_MENU_ROW+1, 20}, "cr:", &flrc_cr_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1327 { {FIRST_CHIP_MENU_ROW+1, 27}, "BT:", &gfsk_flrc_bt_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1328 { {FIRST_CHIP_MENU_ROW+1, 34}, "PreambleLength:", &gfsk_flrc_preamble_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1329 { {FIRST_CHIP_MENU_ROW+1, 52}, "SyncLength:", &flrc_synclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1330
Wayne Roberts 4:fa31fdf4ec8d 1331 { {FIRST_CHIP_MENU_ROW+2, 1}, "Length:", &gfsk_flrc_fixvar_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1332 { {FIRST_CHIP_MENU_ROW+2, 18}, "crcLength:", &gfsk_flrc_crclen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1333 { {FIRST_CHIP_MENU_ROW+2, 38}, "whitening:", &gfsk_flrc_whit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1334 { {FIRST_CHIP_MENU_ROW+2, 58}, "crcInit:", &gfsk_flrc_crcinit_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1335 { {FIRST_CHIP_MENU_ROW+2, 73}, "poly:", &gfsk_flrc_crcpoly_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1336
Wayne Roberts 4:fa31fdf4ec8d 1337 { {FIRST_CHIP_MENU_ROW+3, 1}, "sync1 ", &gfsk_flrc_sync1en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1338 { {FIRST_CHIP_MENU_ROW+3, 12}, NULL, &gfsk_flrc_sync1_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1339 { {FIRST_CHIP_MENU_ROW+3, 24}, "sync2 ", &gfsk_flrc_sync2en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1340 { {FIRST_CHIP_MENU_ROW+3, 35}, NULL, &gfsk_flrc_sync2_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1341 { {FIRST_CHIP_MENU_ROW+3, 47}, "sync3 ", &gfsk_flrc_sync3en_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1342 { {FIRST_CHIP_MENU_ROW+3, 59}, NULL, &gfsk_flrc_sync3_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1343
Wayne Roberts 1:0817a150122b 1344 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1345 };
Wayne Roberts 1:0817a150122b 1346
Wayne Roberts 3:56fc764dee0a 1347 bool Radio::manualRngDelay;
Wayne Roberts 3:56fc764dee0a 1348 const uint16_t Radio::rngDelays[3][6] = {
Wayne Roberts 3:56fc764dee0a 1349 10299, 10271, 10244, 10242, 10230, 10246,
Wayne Roberts 3:56fc764dee0a 1350 11486, 11474, 11453, 11426, 11417, 11401,
Wayne Roberts 3:56fc764dee0a 1351 13308, 13493, 13528, 13515, 13430, 13376
Wayne Roberts 3:56fc764dee0a 1352 };
Wayne Roberts 3:56fc764dee0a 1353
Wayne Roberts 3:56fc764dee0a 1354 void Radio::rngUpdateDelayCal()
Wayne Roberts 3:56fc764dee0a 1355 {
Wayne Roberts 3:56fc764dee0a 1356 LoRaPktPar0.octet = radio.readReg(REG_ADDR_LORA_PKTPAR0, 1);
Wayne Roberts 3:56fc764dee0a 1357
Wayne Roberts 3:56fc764dee0a 1358 if (LoRaPktPar0.bits.modem_bw > 2 && LoRaPktPar0.bits.modem_sf < 11) {
Wayne Roberts 3:56fc764dee0a 1359 uint32_t delayCal = radio.readReg(REG_ADDR_LORA_DELAY_CAL, 3);
Wayne Roberts 3:56fc764dee0a 1360 delayCal &= ~0x3fffff;
Wayne Roberts 3:56fc764dee0a 1361 delayCal |= rngDelays[LoRaPktPar0.bits.modem_bw-3][LoRaPktPar0.bits.modem_sf-5];
Wayne Roberts 3:56fc764dee0a 1362 /*log_printf("%u = rngDelays[%u][%u]\r\n",
Wayne Roberts 3:56fc764dee0a 1363 rngDelays[LoRaPktPar0.bits.modem_bw-3][LoRaPktPar0.bits.modem_sf-5],
Wayne Roberts 3:56fc764dee0a 1364 LoRaPktPar0.bits.modem_bw-3, LoRaPktPar0.bits.modem_sf-5
Wayne Roberts 3:56fc764dee0a 1365 );*/
Wayne Roberts 3:56fc764dee0a 1366 radio.writeReg(REG_ADDR_LORA_DELAY_CAL, delayCal, 3);
Wayne Roberts 3:56fc764dee0a 1367 }
Wayne Roberts 3:56fc764dee0a 1368 }
Wayne Roberts 3:56fc764dee0a 1369
Wayne Roberts 3:56fc764dee0a 1370 static const char* const lora_bws[] = {
Wayne Roberts 1:0817a150122b 1371 " 50KHz", // 0
Wayne Roberts 1:0817a150122b 1372 " 100KHz", // 1
Wayne Roberts 1:0817a150122b 1373 " 200KHz", // 2
Wayne Roberts 1:0817a150122b 1374 " 400KHz", // 3
Wayne Roberts 1:0817a150122b 1375 " 800KHz", // 4
Wayne Roberts 1:0817a150122b 1376 "1600KHz", // 5
Wayne Roberts 1:0817a150122b 1377 NULL
Wayne Roberts 1:0817a150122b 1378 };
Wayne Roberts 1:0817a150122b 1379
Wayne Roberts 3:56fc764dee0a 1380 const float Radio::bwMHzs[] = { 0.05, 0.1, 0.2, 0.4, 0.8, 1.6 };
Wayne Roberts 3:56fc764dee0a 1381
Wayne Roberts 3:56fc764dee0a 1382 LoRaPktPar0_t Radio::LoRaPktPar0;
Wayne Roberts 3:56fc764dee0a 1383
Wayne Roberts 1:0817a150122b 1384 unsigned Radio::lora_bw_read(bool fw)
Wayne Roberts 1:0817a150122b 1385 {
Wayne Roberts 1:0817a150122b 1386 LoRaPktPar0.octet = radio.readReg(REG_ADDR_LORA_PKTPAR0, 1);
Wayne Roberts 1:0817a150122b 1387
Wayne Roberts 1:0817a150122b 1388 return LoRaPktPar0.bits.modem_bw;
Wayne Roberts 1:0817a150122b 1389 }
Wayne Roberts 1:0817a150122b 1390
Wayne Roberts 1:0817a150122b 1391 menuMode_e Radio::lora_bw_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1392 {
Wayne Roberts 1:0817a150122b 1393 switch (sidx) {
Wayne Roberts 1:0817a150122b 1394 case 0: mpLORA.lora.bandwidth = LORA_BW_50; break;
Wayne Roberts 1:0817a150122b 1395 case 1: mpLORA.lora.bandwidth = LORA_BW_100; break;
Wayne Roberts 1:0817a150122b 1396 case 2: mpLORA.lora.bandwidth = LORA_BW_200; break;
Wayne Roberts 1:0817a150122b 1397 case 3: mpLORA.lora.bandwidth = LORA_BW_400; break;
Wayne Roberts 1:0817a150122b 1398 case 4: mpLORA.lora.bandwidth = LORA_BW_800; break;
Wayne Roberts 1:0817a150122b 1399 case 5: mpLORA.lora.bandwidth = LORA_BW_1600; break;
Wayne Roberts 1:0817a150122b 1400 }
Wayne Roberts 1:0817a150122b 1401 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 1402
Wayne Roberts 3:56fc764dee0a 1403 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 1404 manualRngDelay = false;
Wayne Roberts 3:56fc764dee0a 1405 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 1406 }
Wayne Roberts 3:56fc764dee0a 1407
Wayne Roberts 1:0817a150122b 1408 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1409 }
Wayne Roberts 1:0817a150122b 1410
Wayne Roberts 1:0817a150122b 1411 const dropdown_item_t Radio::lora_bw_item = { _ITEM_DROPDOWN, lora_bws, lora_bws, lora_bw_read, lora_bw_write};
Wayne Roberts 1:0817a150122b 1412
Wayne Roberts 1:0817a150122b 1413 void Radio::lora_sf_print()
Wayne Roberts 1:0817a150122b 1414 {
Wayne Roberts 1:0817a150122b 1415 LoRaPktPar0.octet = radio.readReg(REG_ADDR_LORA_PKTPAR0, 1);
Wayne Roberts 1:0817a150122b 1416
dudmuck 13:8ce61a1897ab 1417 printf("%u", LoRaPktPar0.bits.modem_sf);
Wayne Roberts 1:0817a150122b 1418 }
Wayne Roberts 1:0817a150122b 1419
Wayne Roberts 1:0817a150122b 1420 bool Radio::lora_sf_write(const char* str)
Wayne Roberts 1:0817a150122b 1421 {
Wayne Roberts 1:0817a150122b 1422 unsigned n;
Wayne Roberts 1:0817a150122b 1423 if (sscanf(str, "%u", &n) == 1) {
Wayne Roberts 1:0817a150122b 1424 mpLORA.lora.spreadingFactor = n << 4;
Wayne Roberts 1:0817a150122b 1425 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf);
Wayne Roberts 3:56fc764dee0a 1426
Wayne Roberts 3:56fc764dee0a 1427 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 1428 manualRngDelay = false;
Wayne Roberts 3:56fc764dee0a 1429 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 1430 }
Wayne Roberts 1:0817a150122b 1431 }
Wayne Roberts 1:0817a150122b 1432 return false;
Wayne Roberts 1:0817a150122b 1433 }
Wayne Roberts 1:0817a150122b 1434
Wayne Roberts 1:0817a150122b 1435 const value_item_t Radio::lora_sf_item = { _ITEM_VALUE, 3, lora_sf_print, lora_sf_write };
Wayne Roberts 1:0817a150122b 1436
Wayne Roberts 3:56fc764dee0a 1437 static const char* const lora_crs[] = {
Wayne Roberts 1:0817a150122b 1438 "4/5 ",
Wayne Roberts 1:0817a150122b 1439 "4/6 ",
Wayne Roberts 1:0817a150122b 1440 "4/7 ",
Wayne Roberts 1:0817a150122b 1441 "4/8 ",
Wayne Roberts 1:0817a150122b 1442 "4/5 LI",
Wayne Roberts 1:0817a150122b 1443 "4/6 LI",
Wayne Roberts 1:0817a150122b 1444 "4/7 LI",
Wayne Roberts 1:0817a150122b 1445 NULL
Wayne Roberts 1:0817a150122b 1446 };
Wayne Roberts 1:0817a150122b 1447
Wayne Roberts 2:ea9245bb1c53 1448 unsigned Radio::lora_cr_read(bool fw)
Wayne Roberts 1:0817a150122b 1449 {
Wayne Roberts 1:0817a150122b 1450 LoRaPktPar1_t LoRaPktPar1;
Wayne Roberts 1:0817a150122b 1451 LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
Wayne Roberts 1:0817a150122b 1452 mpLORA.lora.codingRate = LoRaPktPar1.bits.coding_rate;
Wayne Roberts 1:0817a150122b 1453 return LoRaPktPar1.bits.coding_rate;
Wayne Roberts 1:0817a150122b 1454 }
Wayne Roberts 1:0817a150122b 1455
Wayne Roberts 2:ea9245bb1c53 1456 menuMode_e Radio::lora_cr_write(unsigned sidx)
Wayne Roberts 1:0817a150122b 1457 {
Wayne Roberts 1:0817a150122b 1458 mpLORA.lora.codingRate = sidx;
Wayne Roberts 1:0817a150122b 1459 radio.xfer(OPCODE_SET_MODULATION_PARAMS, 3, 0, mpLORA.buf);
Wayne Roberts 1:0817a150122b 1460 return MENUMODE_REDRAW;
Wayne Roberts 1:0817a150122b 1461 }
Wayne Roberts 1:0817a150122b 1462
Wayne Roberts 2:ea9245bb1c53 1463 const dropdown_item_t Radio::lora_cr_item = { _ITEM_DROPDOWN, lora_crs, lora_crs, lora_cr_read, lora_cr_write};
Wayne Roberts 1:0817a150122b 1464
Wayne Roberts 1:0817a150122b 1465 void Radio::lora_pblLen_print()
Wayne Roberts 1:0817a150122b 1466 {
Wayne Roberts 1:0817a150122b 1467 LoRaPreambleReg_t LoRaPreambleReg;
Wayne Roberts 1:0817a150122b 1468 LoRaPreambleReg.octet = radio.readReg(REG_ADDR_LORA_PREAMBLE, 1);
Wayne Roberts 1:0817a150122b 1469 ppLORA.lora.PreambleLength = (1 << LoRaPreambleReg.bits.preamble_symb_nb_exp) * LoRaPreambleReg.bits.preamble_symb1_nb;
dudmuck 13:8ce61a1897ab 1470 printf("%u", ppLORA.lora.PreambleLength);
Wayne Roberts 1:0817a150122b 1471 }
Wayne Roberts 1:0817a150122b 1472
Wayne Roberts 1:0817a150122b 1473 bool Radio::lora_pblLen_write(const char* str)
Wayne Roberts 1:0817a150122b 1474 {
Wayne Roberts 1:0817a150122b 1475 unsigned val, exp, mant;
Wayne Roberts 1:0817a150122b 1476 sscanf(str, "%u", &val);
Wayne Roberts 1:0817a150122b 1477
Wayne Roberts 1:0817a150122b 1478 for (exp = 0; exp < 16; exp++) {
Wayne Roberts 1:0817a150122b 1479 mant = val / (1 << exp);
Wayne Roberts 1:0817a150122b 1480 if (mant < 16)
Wayne Roberts 1:0817a150122b 1481 break;
Wayne Roberts 1:0817a150122b 1482 }
Wayne Roberts 1:0817a150122b 1483
Wayne Roberts 1:0817a150122b 1484 ppLORA.lora.PreambleLength = (exp << 4) + mant;
Wayne Roberts 1:0817a150122b 1485 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 5:1e5cb7139acb 1486
Wayne Roberts 1:0817a150122b 1487 return false;
Wayne Roberts 1:0817a150122b 1488 }
Wayne Roberts 1:0817a150122b 1489
Wayne Roberts 1:0817a150122b 1490 const value_item_t Radio::lora_pblLen_item = { _ITEM_VALUE, 5, lora_pblLen_print, lora_pblLen_write};
Wayne Roberts 1:0817a150122b 1491
Wayne Roberts 1:0817a150122b 1492 bool Radio::lora_fixlen_read()
Wayne Roberts 1:0817a150122b 1493 {
Wayne Roberts 1:0817a150122b 1494 LoRaPktPar1_t LoRaPktPar1;
Wayne Roberts 1:0817a150122b 1495 LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
Wayne Roberts 1:0817a150122b 1496 ppLORA.lora.HeaderType = LoRaPktPar1.bits.implicit_header ? IMPLICIT_HEADER : EXPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1497 return LoRaPktPar1.bits.implicit_header;
Wayne Roberts 1:0817a150122b 1498 }
Wayne Roberts 1:0817a150122b 1499
Wayne Roberts 1:0817a150122b 1500 bool Radio::lora_fixlen_push()
Wayne Roberts 1:0817a150122b 1501 {
Wayne Roberts 1:0817a150122b 1502 if (ppLORA.lora.HeaderType == EXPLICIT_HEADER)
Wayne Roberts 1:0817a150122b 1503 ppLORA.lora.HeaderType = IMPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1504 else
Wayne Roberts 1:0817a150122b 1505 ppLORA.lora.HeaderType = EXPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1506
Wayne Roberts 1:0817a150122b 1507 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 6:44a9df0e7855 1508 return ppLORA.lora.HeaderType == IMPLICIT_HEADER;
Wayne Roberts 1:0817a150122b 1509 }
Wayne Roberts 1:0817a150122b 1510
Wayne Roberts 1:0817a150122b 1511 const toggle_item_t Radio::lora_fixlen_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1512 "EXPLICIT", // 0
Wayne Roberts 1:0817a150122b 1513 "IMPLICIT", // 1
Wayne Roberts 1:0817a150122b 1514 lora_fixlen_read, lora_fixlen_push
Wayne Roberts 1:0817a150122b 1515 };
Wayne Roberts 1:0817a150122b 1516
Wayne Roberts 1:0817a150122b 1517 bool Radio::lora_crcon_read()
Wayne Roberts 1:0817a150122b 1518 {
Wayne Roberts 1:0817a150122b 1519 LoRaLrCtl_t LoRaLrCtl;
Wayne Roberts 1:0817a150122b 1520 LoRaLrCtl.octet = radio.readReg(REG_ADDR_LORA_LRCTL, 1);
Wayne Roberts 1:0817a150122b 1521 ppLORA.lora.crc = LoRaLrCtl.octet & 0x20; // LoRaLrCtl.bits.crc_en
Wayne Roberts 1:0817a150122b 1522 return LoRaLrCtl.bits.crc_en;
Wayne Roberts 1:0817a150122b 1523 }
Wayne Roberts 1:0817a150122b 1524
Wayne Roberts 1:0817a150122b 1525 bool Radio::lora_crcon_push()
Wayne Roberts 1:0817a150122b 1526 {
Wayne Roberts 1:0817a150122b 1527 if (ppLORA.lora.crc == LORA_CRC_ENABLE)
Wayne Roberts 1:0817a150122b 1528 ppLORA.lora.crc = LORA_CRC_DISABLE;
Wayne Roberts 1:0817a150122b 1529 else
Wayne Roberts 1:0817a150122b 1530 ppLORA.lora.crc = LORA_CRC_ENABLE;
Wayne Roberts 1:0817a150122b 1531
Wayne Roberts 1:0817a150122b 1532 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 1533
Wayne Roberts 1:0817a150122b 1534 return ppLORA.lora.crc == LORA_CRC_ENABLE;
Wayne Roberts 1:0817a150122b 1535 }
Wayne Roberts 1:0817a150122b 1536
Wayne Roberts 1:0817a150122b 1537 const toggle_item_t Radio::lora_crcon_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1538 "CRC_DISABLE", // 0
Wayne Roberts 1:0817a150122b 1539 "CRC_ENABLE ", // 1
Wayne Roberts 1:0817a150122b 1540 lora_crcon_read, lora_crcon_push
Wayne Roberts 1:0817a150122b 1541 };
Wayne Roberts 1:0817a150122b 1542
Wayne Roberts 1:0817a150122b 1543 bool Radio::lora_iqinv_read()
Wayne Roberts 1:0817a150122b 1544 {
Wayne Roberts 1:0817a150122b 1545 LoRaPktPar1_t LoRaPktPar1;
Wayne Roberts 1:0817a150122b 1546 LoRaPktPar1.octet = radio.readReg(REG_ADDR_LORA_PKTPAR1, 1);
Wayne Roberts 1:0817a150122b 1547 ppLORA.lora.InvertIQ = LoRaPktPar1.bits.rxinvert_iq ? LORA_IQ_STD : LORA_IQ_INVERTED;
Wayne Roberts 1:0817a150122b 1548 return LoRaPktPar1.bits.rxinvert_iq ? 0 : 1;
Wayne Roberts 1:0817a150122b 1549 }
Wayne Roberts 1:0817a150122b 1550
Wayne Roberts 1:0817a150122b 1551 bool Radio::lora_iqinv_push()
Wayne Roberts 1:0817a150122b 1552 {
Wayne Roberts 1:0817a150122b 1553 if (ppLORA.lora.InvertIQ == LORA_IQ_STD)
Wayne Roberts 1:0817a150122b 1554 ppLORA.lora.InvertIQ = LORA_IQ_INVERTED;
Wayne Roberts 1:0817a150122b 1555 else
Wayne Roberts 1:0817a150122b 1556 ppLORA.lora.InvertIQ = LORA_IQ_STD;
Wayne Roberts 1:0817a150122b 1557
Wayne Roberts 1:0817a150122b 1558 radio.xfer(OPCODE_SET_PACKET_PARAMS, 5, 0, ppLORA.buf);
Wayne Roberts 1:0817a150122b 1559
Wayne Roberts 6:44a9df0e7855 1560 return ppLORA.lora.InvertIQ == LORA_IQ_INVERTED;
Wayne Roberts 1:0817a150122b 1561 }
Wayne Roberts 1:0817a150122b 1562
Wayne Roberts 1:0817a150122b 1563 const toggle_item_t Radio::lora_iqinv_item = { _ITEM_TOGGLE,
Wayne Roberts 1:0817a150122b 1564 "IQ_STD", // 0
Wayne Roberts 1:0817a150122b 1565 "IQ_INV", // 1
Wayne Roberts 1:0817a150122b 1566 lora_iqinv_read, lora_iqinv_push
Wayne Roberts 1:0817a150122b 1567 };
Wayne Roberts 1:0817a150122b 1568
Wayne Roberts 3:56fc764dee0a 1569 void Radio::lora_ppg_print()
Wayne Roberts 3:56fc764dee0a 1570 {
Wayne Roberts 3:56fc764dee0a 1571 uint8_t val;
Wayne Roberts 3:56fc764dee0a 1572 ppg = radio.readReg(REG_ADDR_LORA_SYNC, 2);
Wayne Roberts 3:56fc764dee0a 1573
Wayne Roberts 3:56fc764dee0a 1574 val = (ppg >> 8) & 0xf0;
Wayne Roberts 3:56fc764dee0a 1575 val |= (ppg & 0xf0) >> 4;
dudmuck 13:8ce61a1897ab 1576 printf("%02x", val);
Wayne Roberts 3:56fc764dee0a 1577 }
Wayne Roberts 3:56fc764dee0a 1578
Wayne Roberts 3:56fc764dee0a 1579 bool Radio::lora_ppg_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1580 {
Wayne Roberts 3:56fc764dee0a 1581 unsigned val;
Wayne Roberts 3:56fc764dee0a 1582 if (sscanf(txt, "%x", &val) == 1) {
Wayne Roberts 3:56fc764dee0a 1583 ppg &= 0x0707;
Wayne Roberts 3:56fc764dee0a 1584 ppg |= (val & 0xf0) << 8;
Wayne Roberts 3:56fc764dee0a 1585 ppg |= (val & 0x0f) << 4;
Wayne Roberts 3:56fc764dee0a 1586 radio.writeReg(REG_ADDR_LORA_SYNC, ppg, 2);
Wayne Roberts 3:56fc764dee0a 1587 }
Wayne Roberts 3:56fc764dee0a 1588 return false;
Wayne Roberts 3:56fc764dee0a 1589 }
Wayne Roberts 3:56fc764dee0a 1590
Wayne Roberts 3:56fc764dee0a 1591 const value_item_t Radio::lora_ppg_item = { _ITEM_VALUE, 4, lora_ppg_print, lora_ppg_write};
Wayne Roberts 3:56fc764dee0a 1592
Wayne Roberts 2:ea9245bb1c53 1593 void Radio::cad_push()
Wayne Roberts 2:ea9245bb1c53 1594 {
Wayne Roberts 2:ea9245bb1c53 1595 radio.setCAD();
Wayne Roberts 2:ea9245bb1c53 1596 }
Wayne Roberts 2:ea9245bb1c53 1597
Wayne Roberts 2:ea9245bb1c53 1598 const button_item_t Radio::lora_cad_item = { _ITEM_BUTTON, "CAD", cad_push };
Wayne Roberts 2:ea9245bb1c53 1599
Wayne Roberts 3:56fc764dee0a 1600 static const char* const lora_cadsymbs[] = {
Wayne Roberts 2:ea9245bb1c53 1601 " 1",
Wayne Roberts 2:ea9245bb1c53 1602 " 2",
Wayne Roberts 2:ea9245bb1c53 1603 " 4",
Wayne Roberts 2:ea9245bb1c53 1604 " 8",
Wayne Roberts 2:ea9245bb1c53 1605 "16",
Wayne Roberts 2:ea9245bb1c53 1606 NULL
Wayne Roberts 2:ea9245bb1c53 1607 };
Wayne Roberts 2:ea9245bb1c53 1608
Wayne Roberts 2:ea9245bb1c53 1609 unsigned Radio::lora_cadsymbs_read(bool forWriting)
Wayne Roberts 2:ea9245bb1c53 1610 {
Wayne Roberts 2:ea9245bb1c53 1611 unsigned n = radio.readReg(REG_ADDR_LORA_FE_GAIN, 1);
Wayne Roberts 2:ea9245bb1c53 1612 return n >> 5;
Wayne Roberts 2:ea9245bb1c53 1613 }
Wayne Roberts 2:ea9245bb1c53 1614
Wayne Roberts 2:ea9245bb1c53 1615 menuMode_e Radio::lora_cadsymbs_write(unsigned sidx)
Wayne Roberts 2:ea9245bb1c53 1616 {
Wayne Roberts 2:ea9245bb1c53 1617 uint8_t buf = sidx << 5;
Wayne Roberts 2:ea9245bb1c53 1618 radio.xfer(OPCODE_SET_CAD_PARAM, 1, 0, &buf);
Wayne Roberts 2:ea9245bb1c53 1619 return MENUMODE_REDRAW;
Wayne Roberts 2:ea9245bb1c53 1620 }
Wayne Roberts 2:ea9245bb1c53 1621
Wayne Roberts 2:ea9245bb1c53 1622 const dropdown_item_t Radio::lora_cadsymbs_item = { _ITEM_DROPDOWN, lora_cadsymbs, lora_cadsymbs, lora_cadsymbs_read, lora_cadsymbs_write};
Wayne Roberts 2:ea9245bb1c53 1623
Wayne Roberts 1:0817a150122b 1624 const menu_t Radio::lora_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1625 { {FIRST_CHIP_MENU_ROW+1, 1}, NULL, &lora_bw_item, FLAG_MSGTYPE_ALL, &rng_delay_item},
Wayne Roberts 4:fa31fdf4ec8d 1626 { {FIRST_CHIP_MENU_ROW+1, 12}, "sf:", &lora_sf_item, FLAG_MSGTYPE_ALL, &rng_delay_item},
Wayne Roberts 4:fa31fdf4ec8d 1627 { {FIRST_CHIP_MENU_ROW+1, 20}, "cr:", &lora_cr_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1628 { {FIRST_CHIP_MENU_ROW+1, 30}, "PreambleLength:", &lora_pblLen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1629 { {FIRST_CHIP_MENU_ROW+2, 1}, NULL, &lora_fixlen_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1630 { {FIRST_CHIP_MENU_ROW+2, 12}, NULL, &lora_crcon_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1631 { {FIRST_CHIP_MENU_ROW+2, 25}, NULL, &lora_iqinv_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1632 { {FIRST_CHIP_MENU_ROW+2, 35}, "ppg:", &lora_ppg_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 2:ea9245bb1c53 1633
Wayne Roberts 4:fa31fdf4ec8d 1634 { {FIRST_CHIP_MENU_ROW+3, 1}, NULL, &lora_cad_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1635 { {FIRST_CHIP_MENU_ROW+3, 5}, "symbols:", &lora_cadsymbs_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 2:ea9245bb1c53 1636
Wayne Roberts 1:0817a150122b 1637 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1638 };
Wayne Roberts 1:0817a150122b 1639
Wayne Roberts 3:56fc764dee0a 1640 bool Radio::tmp;
Wayne Roberts 3:56fc764dee0a 1641
Wayne Roberts 3:56fc764dee0a 1642 bool Radio::rng_role_read()
Wayne Roberts 3:56fc764dee0a 1643 {
Wayne Roberts 3:56fc764dee0a 1644 //RngCfg0_t RngCfg0;
Wayne Roberts 3:56fc764dee0a 1645 //RngCfg0.octet = radio.readReg(REG_ADDR_RNGCFG0, 1);
Wayne Roberts 3:56fc764dee0a 1646
Wayne Roberts 3:56fc764dee0a 1647 //return !RngCfg0.bits.ranging_resp_en;
Wayne Roberts 3:56fc764dee0a 1648 //log_printf("%02x ranging_resp_en: %u\r\n", RngCfg0.octet, RngCfg0.bits.ranging_resp_en);
Wayne Roberts 3:56fc764dee0a 1649 return tmp;
Wayne Roberts 3:56fc764dee0a 1650 }
Wayne Roberts 3:56fc764dee0a 1651
Wayne Roberts 3:56fc764dee0a 1652 bool Radio::rng_role_push()
Wayne Roberts 3:56fc764dee0a 1653 {
Wayne Roberts 3:56fc764dee0a 1654 uint8_t buf;
Wayne Roberts 3:56fc764dee0a 1655 /*
Wayne Roberts 3:56fc764dee0a 1656 RngCfg0_t RngCfg0;
Wayne Roberts 3:56fc764dee0a 1657 RngCfg0.octet = radio.readReg(REG_ADDR_RNGCFG0, 1);
Wayne Roberts 3:56fc764dee0a 1658
Wayne Roberts 3:56fc764dee0a 1659 buf = RngCfg0.bits.ranging_resp_en ? 0 : 1;
Wayne Roberts 3:56fc764dee0a 1660 log_printf("role %02x %u\r\n", RngCfg0.octet, buf);
Wayne Roberts 3:56fc764dee0a 1661 radio.xfer(OPCODE_SET_RANGING_ROLE, 1, 0, &buf);
Wayne Roberts 3:56fc764dee0a 1662 return buf;
Wayne Roberts 3:56fc764dee0a 1663 */
Wayne Roberts 3:56fc764dee0a 1664 tmp ^= true;
Wayne Roberts 3:56fc764dee0a 1665 buf = tmp;
Wayne Roberts 3:56fc764dee0a 1666 radio.xfer(OPCODE_SET_RANGING_ROLE, 1, 0, &buf);
Wayne Roberts 3:56fc764dee0a 1667 return tmp;
Wayne Roberts 3:56fc764dee0a 1668 }
Wayne Roberts 3:56fc764dee0a 1669
Wayne Roberts 3:56fc764dee0a 1670 const toggle_item_t Radio::rng_role_item = { _ITEM_TOGGLE,
Wayne Roberts 3:56fc764dee0a 1671 " SLAVE", // 0
Wayne Roberts 3:56fc764dee0a 1672 "MASTER", // 1
Wayne Roberts 3:56fc764dee0a 1673 rng_role_read, rng_role_push
Wayne Roberts 3:56fc764dee0a 1674 };
Wayne Roberts 3:56fc764dee0a 1675
Wayne Roberts 3:56fc764dee0a 1676 void Radio::rng_id_send_print()
Wayne Roberts 3:56fc764dee0a 1677 {
dudmuck 13:8ce61a1897ab 1678 printf("%08x", radio.readReg(REG_ADDR_LORA_MASTER_REQ_ID, 4));
Wayne Roberts 3:56fc764dee0a 1679 }
Wayne Roberts 3:56fc764dee0a 1680
Wayne Roberts 3:56fc764dee0a 1681 bool Radio::rng_id_send_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1682 {
Wayne Roberts 3:56fc764dee0a 1683 unsigned n;
Wayne Roberts 3:56fc764dee0a 1684 sscanf(txt, "%x", &n);
Wayne Roberts 3:56fc764dee0a 1685 radio.writeReg(REG_ADDR_LORA_MASTER_REQ_ID, n, 4);
Wayne Roberts 3:56fc764dee0a 1686 return false;
Wayne Roberts 3:56fc764dee0a 1687 }
Wayne Roberts 3:56fc764dee0a 1688
Wayne Roberts 3:56fc764dee0a 1689 const value_item_t Radio::rng_id_send_item = { _ITEM_VALUE, 9, rng_id_send_print, rng_id_send_write};
Wayne Roberts 3:56fc764dee0a 1690
Wayne Roberts 3:56fc764dee0a 1691 void Radio::rng_slave_id_print()
Wayne Roberts 3:56fc764dee0a 1692 {
dudmuck 13:8ce61a1897ab 1693 printf("%08x", radio.readReg(REG_ADDR_LORA_SLAVE_ID, 4));
Wayne Roberts 3:56fc764dee0a 1694 }
Wayne Roberts 3:56fc764dee0a 1695
Wayne Roberts 3:56fc764dee0a 1696 bool Radio::rng_slave_id_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1697 {
Wayne Roberts 3:56fc764dee0a 1698 unsigned n;
Wayne Roberts 3:56fc764dee0a 1699 sscanf(txt, "%x", &n);
Wayne Roberts 3:56fc764dee0a 1700 radio.writeReg(REG_ADDR_LORA_SLAVE_ID, n, 4);
Wayne Roberts 3:56fc764dee0a 1701 return false;
Wayne Roberts 3:56fc764dee0a 1702 }
Wayne Roberts 3:56fc764dee0a 1703
Wayne Roberts 3:56fc764dee0a 1704 const value_item_t Radio::rng_slave_id_item = { _ITEM_VALUE, 9, rng_slave_id_print, rng_slave_id_write};
Wayne Roberts 3:56fc764dee0a 1705
Wayne Roberts 3:56fc764dee0a 1706 unsigned Radio::rng_idLength_read(bool forWriting)
Wayne Roberts 3:56fc764dee0a 1707 {
Wayne Roberts 3:56fc764dee0a 1708 RngDebTh2_t RngDebTh2;
Wayne Roberts 3:56fc764dee0a 1709 RngDebTh2.octet = radio.readReg(REG_ADDR_LORA_RNGDEBTH2, 1);
Wayne Roberts 3:56fc764dee0a 1710 return RngDebTh2.bits.ranging_id_check_length;
Wayne Roberts 3:56fc764dee0a 1711 }
Wayne Roberts 3:56fc764dee0a 1712
Wayne Roberts 3:56fc764dee0a 1713 menuMode_e Radio::rng_idLength_write(unsigned sidx)
Wayne Roberts 3:56fc764dee0a 1714 {
Wayne Roberts 3:56fc764dee0a 1715 RngDebTh2_t RngDebTh2;
Wayne Roberts 3:56fc764dee0a 1716 RngDebTh2.octet = radio.readReg(REG_ADDR_LORA_RNGDEBTH2, 1);
Wayne Roberts 3:56fc764dee0a 1717 RngDebTh2.bits.ranging_id_check_length = sidx;
Wayne Roberts 3:56fc764dee0a 1718 radio.writeReg(REG_ADDR_LORA_RNGDEBTH2, RngDebTh2.octet, 1);
Wayne Roberts 3:56fc764dee0a 1719 return MENUMODE_REDRAW;
Wayne Roberts 3:56fc764dee0a 1720 }
Wayne Roberts 3:56fc764dee0a 1721
Wayne Roberts 3:56fc764dee0a 1722 static const char* const rngLens[] = {
Wayne Roberts 3:56fc764dee0a 1723 " 8 bits",
Wayne Roberts 3:56fc764dee0a 1724 "16 bits",
Wayne Roberts 3:56fc764dee0a 1725 "24 bits",
Wayne Roberts 3:56fc764dee0a 1726 "32 bits",
Wayne Roberts 3:56fc764dee0a 1727 NULL
Wayne Roberts 3:56fc764dee0a 1728 };
Wayne Roberts 3:56fc764dee0a 1729
Wayne Roberts 3:56fc764dee0a 1730 const dropdown_item_t Radio::rng_idLength_item = { _ITEM_DROPDOWN, rngLens, rngLens, rng_idLength_read, rng_idLength_write};
Wayne Roberts 3:56fc764dee0a 1731
Wayne Roberts 3:56fc764dee0a 1732
Wayne Roberts 3:56fc764dee0a 1733 void Radio::rng_delay_print(void)
Wayne Roberts 3:56fc764dee0a 1734 {
Wayne Roberts 3:56fc764dee0a 1735 if (pktType == PACKET_TYPE_RANGING) {
dudmuck 13:8ce61a1897ab 1736 printf("%u", radio.readReg(REG_ADDR_LORA_DELAY_CAL, 3) & 0x3fffff);
Wayne Roberts 3:56fc764dee0a 1737 }
Wayne Roberts 3:56fc764dee0a 1738 }
Wayne Roberts 3:56fc764dee0a 1739
Wayne Roberts 3:56fc764dee0a 1740 bool Radio::rng_delay_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1741 {
Wayne Roberts 3:56fc764dee0a 1742 unsigned n;
Wayne Roberts 3:56fc764dee0a 1743 uint32_t delayCal = radio.readReg(REG_ADDR_LORA_DELAY_CAL, 3);
Wayne Roberts 3:56fc764dee0a 1744 sscanf(txt, "%u", &n);
Wayne Roberts 3:56fc764dee0a 1745 delayCal &= ~0x3fffff;
Wayne Roberts 3:56fc764dee0a 1746 delayCal |= n;
Wayne Roberts 3:56fc764dee0a 1747 radio.writeReg(REG_ADDR_LORA_DELAY_CAL, delayCal, 3);
Wayne Roberts 3:56fc764dee0a 1748
Wayne Roberts 3:56fc764dee0a 1749 manualRngDelay = true;
Wayne Roberts 3:56fc764dee0a 1750 return false;
Wayne Roberts 3:56fc764dee0a 1751 }
Wayne Roberts 3:56fc764dee0a 1752
Wayne Roberts 3:56fc764dee0a 1753 const value_item_t Radio::rng_delay_item = { _ITEM_VALUE, 7, rng_delay_print, rng_delay_write };
Wayne Roberts 3:56fc764dee0a 1754
Wayne Roberts 3:56fc764dee0a 1755 unsigned Radio::rng_resultMux_read(bool)
Wayne Roberts 3:56fc764dee0a 1756 {
Wayne Roberts 3:56fc764dee0a 1757 RngCfg1_t RngCfg1;
Wayne Roberts 3:56fc764dee0a 1758 RngCfg1.octet = radio.readReg(REG_ADDR_RNGCFG1, 1);
Wayne Roberts 3:56fc764dee0a 1759 return RngCfg1.bits.ranging_result_mux_sel;
Wayne Roberts 3:56fc764dee0a 1760 }
Wayne Roberts 3:56fc764dee0a 1761
Wayne Roberts 3:56fc764dee0a 1762 menuMode_e Radio::rng_resultMux_write(unsigned sidx)
Wayne Roberts 3:56fc764dee0a 1763 {
Wayne Roberts 3:56fc764dee0a 1764 RngCfg1_t RngCfg1;
Wayne Roberts 3:56fc764dee0a 1765 RngCfg1.octet = radio.readReg(REG_ADDR_RNGCFG1, 1);
Wayne Roberts 3:56fc764dee0a 1766 RngCfg1.bits.ranging_result_mux_sel = sidx;
Wayne Roberts 3:56fc764dee0a 1767 radio.writeReg(REG_ADDR_RNGCFG1, RngCfg1.octet, 1);
Wayne Roberts 3:56fc764dee0a 1768 return MENUMODE_REDRAW;
Wayne Roberts 3:56fc764dee0a 1769 }
Wayne Roberts 3:56fc764dee0a 1770
Wayne Roberts 3:56fc764dee0a 1771 static const char* const rngResults[] = {
Wayne Roberts 3:56fc764dee0a 1772 " raw ",
Wayne Roberts 3:56fc764dee0a 1773 " rssiAvg ",
Wayne Roberts 3:56fc764dee0a 1774 " debiased ",
Wayne Roberts 3:56fc764dee0a 1775 "finalFilter",
Wayne Roberts 3:56fc764dee0a 1776 NULL
Wayne Roberts 3:56fc764dee0a 1777 };
Wayne Roberts 3:56fc764dee0a 1778
Wayne Roberts 3:56fc764dee0a 1779 const dropdown_item_t Radio::rng_resultMux_item = { _ITEM_DROPDOWN, rngResults, rngResults, rng_resultMux_read, rng_resultMux_write};
Wayne Roberts 3:56fc764dee0a 1780
Wayne Roberts 3:56fc764dee0a 1781
Wayne Roberts 3:56fc764dee0a 1782 void Radio::rng_wndFltSize_print()
Wayne Roberts 3:56fc764dee0a 1783 {
dudmuck 13:8ce61a1897ab 1784 printf("%u", radio.readReg(REG_ADDR_RNGFLTWNDSIZE, 1));
Wayne Roberts 3:56fc764dee0a 1785 }
Wayne Roberts 3:56fc764dee0a 1786
Wayne Roberts 3:56fc764dee0a 1787 bool Radio::rng_wndFltSize_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1788 {
Wayne Roberts 3:56fc764dee0a 1789 unsigned n;
Wayne Roberts 3:56fc764dee0a 1790 sscanf(txt, "%u", &n);
Wayne Roberts 3:56fc764dee0a 1791 radio.writeReg(REG_ADDR_RNGFLTWNDSIZE, n, 1);
Wayne Roberts 3:56fc764dee0a 1792 return false;
Wayne Roberts 3:56fc764dee0a 1793 }
Wayne Roberts 3:56fc764dee0a 1794
Wayne Roberts 3:56fc764dee0a 1795 const value_item_t Radio::rng_wndFltSize_item = { _ITEM_VALUE, 4, rng_wndFltSize_print, rng_wndFltSize_write};
Wayne Roberts 3:56fc764dee0a 1796
Wayne Roberts 3:56fc764dee0a 1797
Wayne Roberts 3:56fc764dee0a 1798
Wayne Roberts 3:56fc764dee0a 1799
Wayne Roberts 3:56fc764dee0a 1800 void Radio::rng_rngRssiThresh_print()
Wayne Roberts 3:56fc764dee0a 1801 {
Wayne Roberts 3:56fc764dee0a 1802 RngDebTh4H_t RngDebTh4H;
Wayne Roberts 3:56fc764dee0a 1803 RngDebTh4H.octet = radio.readReg(REG_ADDR_RNGDEBTH4H, 1);
dudmuck 13:8ce61a1897ab 1804 printf("%u", RngDebTh4H.bits.rng_rssi_threshold);
Wayne Roberts 3:56fc764dee0a 1805 }
Wayne Roberts 3:56fc764dee0a 1806
Wayne Roberts 3:56fc764dee0a 1807 bool Radio::rng_rngRssiThresh_write(const char* txt)
Wayne Roberts 3:56fc764dee0a 1808 {
Wayne Roberts 3:56fc764dee0a 1809 unsigned n;
Wayne Roberts 3:56fc764dee0a 1810 RngDebTh4H_t RngDebTh4H;
Wayne Roberts 3:56fc764dee0a 1811 RngDebTh4H.octet = radio.readReg(REG_ADDR_RNGDEBTH4H, 1);
Wayne Roberts 3:56fc764dee0a 1812 sscanf(txt, "%u", &n);
Wayne Roberts 3:56fc764dee0a 1813 RngDebTh4H.bits.rng_rssi_threshold = n;
Wayne Roberts 3:56fc764dee0a 1814 radio.writeReg(REG_ADDR_RNGDEBTH4H, RngDebTh4H.octet, 1);
Wayne Roberts 3:56fc764dee0a 1815 return false;
Wayne Roberts 3:56fc764dee0a 1816 }
Wayne Roberts 3:56fc764dee0a 1817
Wayne Roberts 3:56fc764dee0a 1818 const value_item_t Radio::rng_rngRssiThresh_item = { _ITEM_VALUE, 4, rng_rngRssiThresh_print, rng_rngRssiThresh_write};
Wayne Roberts 3:56fc764dee0a 1819
Wayne Roberts 3:56fc764dee0a 1820 const menu_t Radio::rng_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1821 { {FIRST_CHIP_MENU_ROW+3, 19}, NULL, &rng_role_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1822 { {FIRST_CHIP_MENU_ROW+3, 28}, "ID to send:", &rng_id_send_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1823 { {FIRST_CHIP_MENU_ROW+3, 49}, "slave ID:", &rng_slave_id_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1824 { {FIRST_CHIP_MENU_ROW+3, 67}, NULL, &rng_idLength_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1825 { {FIRST_CHIP_MENU_ROW+4, 1}, "delay:", &rng_delay_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1826 { {FIRST_CHIP_MENU_ROW+4, 14}, "resultMux:", &rng_resultMux_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1827 { {FIRST_CHIP_MENU_ROW+4, 37}, "windowFilterSize:", &rng_wndFltSize_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1828 { {FIRST_CHIP_MENU_ROW+4, 59}, "rngRssiThresh:", &rng_rngRssiThresh_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 3:56fc764dee0a 1829
Wayne Roberts 3:56fc764dee0a 1830 { {0, 0}, NULL, NULL }
Wayne Roberts 3:56fc764dee0a 1831 };
Wayne Roberts 3:56fc764dee0a 1832
Wayne Roberts 4:fa31fdf4ec8d 1833 void Radio::xta_print()
Wayne Roberts 4:fa31fdf4ec8d 1834 {
Wayne Roberts 4:fa31fdf4ec8d 1835 uint8_t trim = radio.readReg(REG_ADDR_XTA_TRIM, 1);
dudmuck 13:8ce61a1897ab 1836 printf("%02x", trim);
Wayne Roberts 4:fa31fdf4ec8d 1837 }
Wayne Roberts 4:fa31fdf4ec8d 1838
Wayne Roberts 4:fa31fdf4ec8d 1839 bool Radio::xta_write(const char* txt)
Wayne Roberts 4:fa31fdf4ec8d 1840 {
Wayne Roberts 4:fa31fdf4ec8d 1841 unsigned trim;
Wayne Roberts 4:fa31fdf4ec8d 1842 if (sscanf(txt, "%x", &trim) == 1)
Wayne Roberts 4:fa31fdf4ec8d 1843 radio.writeReg(REG_ADDR_XTA_TRIM, trim, 1);
Wayne Roberts 4:fa31fdf4ec8d 1844
Wayne Roberts 4:fa31fdf4ec8d 1845 return false;
Wayne Roberts 4:fa31fdf4ec8d 1846 }
Wayne Roberts 4:fa31fdf4ec8d 1847
Wayne Roberts 4:fa31fdf4ec8d 1848 const value_item_t Radio::xta_item = { _ITEM_VALUE, 3, xta_print, xta_write};
Wayne Roberts 4:fa31fdf4ec8d 1849
Wayne Roberts 4:fa31fdf4ec8d 1850 void Radio::xtb_print()
Wayne Roberts 4:fa31fdf4ec8d 1851 {
Wayne Roberts 4:fa31fdf4ec8d 1852 uint8_t trim = radio.readReg(REG_ADDR_XTB_TRIM, 1);
dudmuck 13:8ce61a1897ab 1853 printf("%02x", trim);
Wayne Roberts 4:fa31fdf4ec8d 1854 }
Wayne Roberts 4:fa31fdf4ec8d 1855
Wayne Roberts 4:fa31fdf4ec8d 1856 bool Radio::xtb_write(const char* txt)
Wayne Roberts 4:fa31fdf4ec8d 1857 {
Wayne Roberts 4:fa31fdf4ec8d 1858 unsigned trim;
Wayne Roberts 4:fa31fdf4ec8d 1859 if (sscanf(txt, "%x", &trim) == 1)
Wayne Roberts 4:fa31fdf4ec8d 1860 radio.writeReg(REG_ADDR_XTB_TRIM, trim, 1);
Wayne Roberts 4:fa31fdf4ec8d 1861
Wayne Roberts 4:fa31fdf4ec8d 1862 return false;
Wayne Roberts 4:fa31fdf4ec8d 1863 }
Wayne Roberts 4:fa31fdf4ec8d 1864
Wayne Roberts 4:fa31fdf4ec8d 1865 const value_item_t Radio::xtb_item = { _ITEM_VALUE, 3, xtb_print, xtb_write};
Wayne Roberts 4:fa31fdf4ec8d 1866
Wayne Roberts 1:0817a150122b 1867 const menu_t Radio::common_menu[] = {
Wayne Roberts 4:fa31fdf4ec8d 1868 { {FIRST_CHIP_MENU_ROW, 1}, "XTA:", &xta_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 4:fa31fdf4ec8d 1869 { {FIRST_CHIP_MENU_ROW, 8}, "XTB:", &xtb_item, FLAG_MSGTYPE_ALL },
Wayne Roberts 1:0817a150122b 1870 { {0, 0}, NULL, NULL }
Wayne Roberts 1:0817a150122b 1871 };
Wayne Roberts 1:0817a150122b 1872
Wayne Roberts 1:0817a150122b 1873 const menu_t* Radio::get_modem_menu()
Wayne Roberts 1:0817a150122b 1874 {
Wayne Roberts 1:0817a150122b 1875 pktType = radio.getPacketType();
Wayne Roberts 1:0817a150122b 1876
Wayne Roberts 1:0817a150122b 1877 if (pktType == PACKET_TYPE_RANGING || pktType == PACKET_TYPE_LORA) {
Wayne Roberts 1:0817a150122b 1878 return lora_menu;
Wayne Roberts 1:0817a150122b 1879 } else if (pktType == PACKET_TYPE_FLRC) {
Wayne Roberts 1:0817a150122b 1880 return flrc_menu;
Wayne Roberts 1:0817a150122b 1881 } else if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 1882 return gfsk_menu;
Wayne Roberts 1:0817a150122b 1883 }
Wayne Roberts 1:0817a150122b 1884
Wayne Roberts 1:0817a150122b 1885 return NULL;
Wayne Roberts 1:0817a150122b 1886 }
Wayne Roberts 1:0817a150122b 1887
Wayne Roberts 3:56fc764dee0a 1888 const menu_t* Radio::get_modem_sub_menu()
Wayne Roberts 3:56fc764dee0a 1889 {
Wayne Roberts 3:56fc764dee0a 1890 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 1891 return rng_menu;
Wayne Roberts 3:56fc764dee0a 1892 }
Wayne Roberts 3:56fc764dee0a 1893 return NULL;
Wayne Roberts 3:56fc764dee0a 1894 }
Wayne Roberts 1:0817a150122b 1895
Wayne Roberts 1:0817a150122b 1896 bool Radio::service(int8_t statusRow)
Wayne Roberts 1:0817a150122b 1897 {
Wayne Roberts 1:0817a150122b 1898 static pktStatus_t prevPktStatus;
Wayne Roberts 1:0817a150122b 1899 static IrqFlags_t prevIrqFlags;
Wayne Roberts 1:0817a150122b 1900 IrqFlags_t irqFlags;
Wayne Roberts 1:0817a150122b 1901 bool ret = false;
dudmuck 14:14b9e1c08bfc 1902 static long prev_now_ms;
dudmuck 14:14b9e1c08bfc 1903 auto now_tp = time_point_cast<milliseconds>(Kernel::Clock::now());
dudmuck 14:14b9e1c08bfc 1904 long now_ms = now_tp.time_since_epoch().count();
Wayne Roberts 1:0817a150122b 1905
Wayne Roberts 1:0817a150122b 1906 radio.service();
Wayne Roberts 1:0817a150122b 1907
dudmuck 14:14b9e1c08bfc 1908 if (statusRow > 0 && now_ms-prev_now_ms > 50) {
Wayne Roberts 1:0817a150122b 1909 int cmp = 0;
Wayne Roberts 1:0817a150122b 1910 pktStatus_t pktStatus;
Wayne Roberts 1:0817a150122b 1911 uint8_t buf[6];
Wayne Roberts 1:0817a150122b 1912 radio.xfer(OPCODE_GET_IRQ_STATUS, 0, 3, buf);
Wayne Roberts 1:0817a150122b 1913 irqFlags.word = buf[1] << 8;
Wayne Roberts 1:0817a150122b 1914 irqFlags.word |= buf[2];
Wayne Roberts 1:0817a150122b 1915
Wayne Roberts 1:0817a150122b 1916 if (rx_led == LED_ON) {
Wayne Roberts 1:0817a150122b 1917 uint8_t slen;
Wayne Roberts 1:0817a150122b 1918 if (pktType == PACKET_TYPE_LORA || pktType == PACKET_TYPE_RANGING)
Wayne Roberts 1:0817a150122b 1919 slen = 3;
Wayne Roberts 1:0817a150122b 1920 else
Wayne Roberts 1:0817a150122b 1921 slen = 6;
Wayne Roberts 1:0817a150122b 1922
Wayne Roberts 1:0817a150122b 1923 radio.xfer(OPCODE_GET_PACKET_STATUS, 0, slen, pktStatus.buf);
Wayne Roberts 2:ea9245bb1c53 1924 cmp = memcmp(prevPktStatus.buf, pktStatus.buf, slen);
Wayne Roberts 1:0817a150122b 1925 }
Wayne Roberts 1:0817a150122b 1926
Wayne Roberts 1:0817a150122b 1927 if (irqFlags.word != prevIrqFlags.word || cmp) {
Wayne Roberts 3:56fc764dee0a 1928 IrqFlags_t clearIrqFlags;
Wayne Roberts 3:56fc764dee0a 1929 clearIrqFlags.word = 0;
Wayne Roberts 3:56fc764dee0a 1930
dudmuck 13:8ce61a1897ab 1931 printf("\e[%u;1f", statusRow); // set (force) cursor to row;column
Wayne Roberts 1:0817a150122b 1932
Wayne Roberts 1:0817a150122b 1933 if (cmp) {
Wayne Roberts 1:0817a150122b 1934 if (pktType == PACKET_TYPE_FLRC || pktType == PACKET_TYPE_BLE || pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 1:0817a150122b 1935 if (pktStatus.ble_gfsk_flrc.errors.SyncError)
dudmuck 13:8ce61a1897ab 1936 printf("SyncError ");
Wayne Roberts 1:0817a150122b 1937 if (pktStatus.ble_gfsk_flrc.errors.LengthError)
dudmuck 13:8ce61a1897ab 1938 printf("LengthError ");
Wayne Roberts 1:0817a150122b 1939 if (pktStatus.ble_gfsk_flrc.errors.CrcError)
dudmuck 13:8ce61a1897ab 1940 printf("CrcError ");
Wayne Roberts 1:0817a150122b 1941 if (pktStatus.ble_gfsk_flrc.errors.AbortErr)
dudmuck 13:8ce61a1897ab 1942 printf("AbortErr ");
Wayne Roberts 1:0817a150122b 1943 if (pktStatus.ble_gfsk_flrc.errors.headerReceived)
dudmuck 13:8ce61a1897ab 1944 printf("headerReceived ");
Wayne Roberts 1:0817a150122b 1945 if (pktStatus.ble_gfsk_flrc.errors.packetReceived)
dudmuck 13:8ce61a1897ab 1946 printf("packetReceived ");
Wayne Roberts 1:0817a150122b 1947 if (pktStatus.ble_gfsk_flrc.errors.pktCtrlBusy)
dudmuck 13:8ce61a1897ab 1948 printf("pktCtrlBusy ");
Wayne Roberts 1:0817a150122b 1949 }
Wayne Roberts 1:0817a150122b 1950 memcpy(prevPktStatus.buf, pktStatus.buf, sizeof(pktStatus_t));
dudmuck 13:8ce61a1897ab 1951 printf(" | ");
Wayne Roberts 1:0817a150122b 1952 }
Wayne Roberts 1:0817a150122b 1953
Wayne Roberts 1:0817a150122b 1954 if (irqFlags.bits.TxDone)
dudmuck 13:8ce61a1897ab 1955 printf("TxDone ");
Wayne Roberts 1:0817a150122b 1956 if (irqFlags.bits.RxDone)
dudmuck 13:8ce61a1897ab 1957 printf("RxDone ");
Wayne Roberts 1:0817a150122b 1958 if (irqFlags.bits.SyncWordValid)
dudmuck 13:8ce61a1897ab 1959 printf("SyncWordValid ");
Wayne Roberts 1:0817a150122b 1960 if (irqFlags.bits.SyncWordError)
dudmuck 13:8ce61a1897ab 1961 printf("SyncWordError ");
Wayne Roberts 1:0817a150122b 1962 if (irqFlags.bits.HeaderValid)
dudmuck 13:8ce61a1897ab 1963 printf("HeaderValid ");
Wayne Roberts 1:0817a150122b 1964 if (irqFlags.bits.HeaderError)
dudmuck 13:8ce61a1897ab 1965 printf("HeaderError ");
Wayne Roberts 1:0817a150122b 1966 if (irqFlags.bits.CrcError)
dudmuck 13:8ce61a1897ab 1967 printf("CrcError ");
Wayne Roberts 3:56fc764dee0a 1968 if (irqFlags.bits.RangingSlaveResponseDone) {
dudmuck 13:8ce61a1897ab 1969 printf("RangingSlaveResponseDone ");
Wayne Roberts 3:56fc764dee0a 1970 clearIrqFlags.bits.RangingSlaveResponseDone = 1;
Wayne Roberts 3:56fc764dee0a 1971 } if (irqFlags.bits.RangingSlaveRequestDiscard) {
dudmuck 13:8ce61a1897ab 1972 printf("RangingSlaveRequestDiscard ");
Wayne Roberts 3:56fc764dee0a 1973 clearIrqFlags.bits.RangingSlaveRequestDiscard = 1;
Wayne Roberts 3:56fc764dee0a 1974 } if (irqFlags.bits.RangingMasterResultValid) {
dudmuck 13:8ce61a1897ab 1975 printf("RangingMasterResultValid ");
Wayne Roberts 3:56fc764dee0a 1976 } if (irqFlags.bits.RangingMasterTimeout) {
Wayne Roberts 3:56fc764dee0a 1977 radio.chipMode = CHIPMODE_NONE;
Wayne Roberts 3:56fc764dee0a 1978 chipModeChange();
dudmuck 13:8ce61a1897ab 1979 printf("RangingMasterTimeout ");
Wayne Roberts 3:56fc764dee0a 1980 clearIrqFlags.bits.RangingMasterTimeout = 1;
Wayne Roberts 3:56fc764dee0a 1981 } if (irqFlags.bits.RangingMasterRequestValid) {
dudmuck 13:8ce61a1897ab 1982 printf("RangingMasterRequestValid ");
Wayne Roberts 3:56fc764dee0a 1983 clearIrqFlags.bits.RangingMasterRequestValid = 1;
Wayne Roberts 3:56fc764dee0a 1984 } if (irqFlags.bits.CadDone)
dudmuck 13:8ce61a1897ab 1985 printf("CadDone ");
Wayne Roberts 1:0817a150122b 1986 if (irqFlags.bits.CadDetected)
dudmuck 13:8ce61a1897ab 1987 printf("CadDetected ");
Wayne Roberts 1:0817a150122b 1988 if (irqFlags.bits.RxTxTimeout)
dudmuck 13:8ce61a1897ab 1989 printf("RxTxTimeout ");
Wayne Roberts 1:0817a150122b 1990 if (irqFlags.bits.PreambleDetected)
dudmuck 13:8ce61a1897ab 1991 printf("PreambleDetected ");
Wayne Roberts 1:0817a150122b 1992
dudmuck 13:8ce61a1897ab 1993 printf("\e[K");
Wayne Roberts 1:0817a150122b 1994 ret = true;
Wayne Roberts 1:0817a150122b 1995
Wayne Roberts 1:0817a150122b 1996 prevIrqFlags.word = irqFlags.word;
Wayne Roberts 3:56fc764dee0a 1997
Wayne Roberts 3:56fc764dee0a 1998 if (irqFlags.bits.RangingMasterResultValid) {
Wayne Roberts 3:56fc764dee0a 1999 float m;
Wayne Roberts 3:56fc764dee0a 2000 unsigned rngResult, rngRssi;
Wayne Roberts 3:56fc764dee0a 2001 radio.chipMode = CHIPMODE_NONE;
Wayne Roberts 3:56fc764dee0a 2002 chipModeChange();
Wayne Roberts 3:56fc764dee0a 2003 rngResult = radio.readReg(REG_ADDR_RNGRESULT, 3);
Wayne Roberts 3:56fc764dee0a 2004 // Distance [m] = RangingResult*150/(2^12*BwMHz)
Wayne Roberts 3:56fc764dee0a 2005 m = rngResult * 150 / (4096*bwMHzs[LoRaPktPar0.bits.modem_bw]);
Wayne Roberts 3:56fc764dee0a 2006 rngRssi = radio.readReg(REG_ADDR_RNGRSSI, 1);
Wayne Roberts 3:56fc764dee0a 2007 log_printf("%u rngResult %.2fm, RngRssi:%u bw%.1f\r\n", rngResult, m, rngRssi, bwMHzs[LoRaPktPar0.bits.modem_bw]);
Wayne Roberts 3:56fc764dee0a 2008 clearIrqFlags.bits.RangingMasterResultValid = 1;
Wayne Roberts 3:56fc764dee0a 2009 }
Wayne Roberts 3:56fc764dee0a 2010
Wayne Roberts 3:56fc764dee0a 2011 if (irqFlags.bits.RangingSlaveResponseDone)
Wayne Roberts 3:56fc764dee0a 2012 log_printf("RangingSlaveResponseDone\r\n");
Wayne Roberts 3:56fc764dee0a 2013 if (irqFlags.bits.RangingSlaveRequestDiscard)
Wayne Roberts 3:56fc764dee0a 2014 log_printf("RangingSlaveRequestDiscard\r\n");
Wayne Roberts 3:56fc764dee0a 2015 if (irqFlags.bits.RangingMasterRequestValid)
Wayne Roberts 3:56fc764dee0a 2016 log_printf("RangingMasterRequestValid\r\n");
Wayne Roberts 3:56fc764dee0a 2017
Wayne Roberts 3:56fc764dee0a 2018 if (clearIrqFlags.word != 0) {
Wayne Roberts 3:56fc764dee0a 2019 buf[0] = clearIrqFlags.word >> 8;
Wayne Roberts 3:56fc764dee0a 2020 buf[1] = (uint8_t)clearIrqFlags.word;
Wayne Roberts 3:56fc764dee0a 2021 radio.xfer(OPCODE_CLEAR_IRQ_STATUS, 2, 0, buf);
Wayne Roberts 3:56fc764dee0a 2022 }
Wayne Roberts 3:56fc764dee0a 2023 } // ..if change
Wayne Roberts 1:0817a150122b 2024
dudmuck 14:14b9e1c08bfc 2025 prev_now_ms = now_ms;
Wayne Roberts 1:0817a150122b 2026 }
Wayne Roberts 1:0817a150122b 2027
Wayne Roberts 1:0817a150122b 2028 return ret;
Wayne Roberts 1:0817a150122b 2029 }
Wayne Roberts 1:0817a150122b 2030
Wayne Roberts 1:0817a150122b 2031 void Radio::Rx()
Wayne Roberts 1:0817a150122b 2032 {
Wayne Roberts 3:56fc764dee0a 2033 if (pktType == PACKET_TYPE_RANGING) {
Wayne Roberts 3:56fc764dee0a 2034 IrqFlags_t irqEnable;
Wayne Roberts 3:56fc764dee0a 2035 uint8_t buf[8];
Wayne Roberts 3:56fc764dee0a 2036
Wayne Roberts 3:56fc764dee0a 2037 if (!manualRngDelay)
Wayne Roberts 3:56fc764dee0a 2038 rngUpdateDelayCal();
Wayne Roberts 3:56fc764dee0a 2039
Wayne Roberts 3:56fc764dee0a 2040 irqEnable.word = 0;
Wayne Roberts 3:56fc764dee0a 2041 irqEnable.bits.RxDone = 1;
Wayne Roberts 3:56fc764dee0a 2042 irqEnable.bits.RxTxTimeout = 1;
Wayne Roberts 3:56fc764dee0a 2043 irqEnable.bits.RangingSlaveResponseDone = 1;
Wayne Roberts 3:56fc764dee0a 2044 irqEnable.bits.RangingSlaveRequestDiscard = 1;
Wayne Roberts 3:56fc764dee0a 2045 irqEnable.bits.RangingMasterRequestValid = 1;
Wayne Roberts 3:56fc764dee0a 2046
Wayne Roberts 3:56fc764dee0a 2047 buf[0] = irqEnable.word >> 8; // enable bits
Wayne Roberts 3:56fc764dee0a 2048 buf[1] = irqEnable.word; // enable bits
Wayne Roberts 3:56fc764dee0a 2049
Wayne Roberts 3:56fc764dee0a 2050 irqEnable.bits.RangingSlaveResponseDone = 0;
Wayne Roberts 3:56fc764dee0a 2051 irqEnable.bits.RangingSlaveRequestDiscard = 0;
Wayne Roberts 3:56fc764dee0a 2052 irqEnable.bits.RangingMasterRequestValid = 0;
Wayne Roberts 3:56fc764dee0a 2053 buf[2] = irqEnable.word >> 8; // dio1
Wayne Roberts 3:56fc764dee0a 2054 buf[3] = irqEnable.word; // dio1
Wayne Roberts 3:56fc764dee0a 2055
Wayne Roberts 3:56fc764dee0a 2056 buf[4] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 2057 buf[5] = 0; // dio2
Wayne Roberts 3:56fc764dee0a 2058 buf[6] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 2059 buf[7] = 0; // dio3
Wayne Roberts 3:56fc764dee0a 2060 radio.xfer(OPCODE_SET_DIO_IRQ_PARAMS, 8, 0, buf);
Wayne Roberts 3:56fc764dee0a 2061
Wayne Roberts 3:56fc764dee0a 2062 buf[0] = radio.periodBase;
Wayne Roberts 3:56fc764dee0a 2063 /* receive packets forever */
Wayne Roberts 3:56fc764dee0a 2064 buf[1] = 0xff;
Wayne Roberts 3:56fc764dee0a 2065 buf[2] = 0xff;
Wayne Roberts 3:56fc764dee0a 2066 radio.xfer(OPCODE_SET_RX, 3, 0, buf);
Wayne Roberts 3:56fc764dee0a 2067
Wayne Roberts 3:56fc764dee0a 2068 radio.chipMode = CHIPMODE_RX;
Wayne Roberts 3:56fc764dee0a 2069 chipModeChange();
Wayne Roberts 3:56fc764dee0a 2070 } else
Wayne Roberts 3:56fc764dee0a 2071 radio.start_rx(0);
Wayne Roberts 1:0817a150122b 2072 }
Wayne Roberts 1:0817a150122b 2073
Wayne Roberts 1:0817a150122b 2074 void Radio::setFS()
Wayne Roberts 1:0817a150122b 2075 {
Wayne Roberts 1:0817a150122b 2076 radio.setFS();
Wayne Roberts 1:0817a150122b 2077 }
Wayne Roberts 1:0817a150122b 2078
Wayne Roberts 3:56fc764dee0a 2079 void Radio::test()
Wayne Roberts 3:56fc764dee0a 2080 {
Wayne Roberts 3:56fc764dee0a 2081 /*
Wayne Roberts 3:56fc764dee0a 2082 RngCfg0_t RngCfg0;
Wayne Roberts 3:56fc764dee0a 2083 RngCfg0.octet = radio.readReg(REG_ADDR_RNGCFG0, 1);
Wayne Roberts 3:56fc764dee0a 2084
Wayne Roberts 3:56fc764dee0a 2085 log_printf("Rngcfg0 %02x\r\n", RngCfg0.octet);*/
Wayne Roberts 3:56fc764dee0a 2086 unsigned a;
Wayne Roberts 3:56fc764dee0a 2087 log_printf("%02x ", radio.readReg(0x910, 1));
Wayne Roberts 3:56fc764dee0a 2088 for (a = 0x911; a < 0x980; a++) {
dudmuck 13:8ce61a1897ab 2089 printf("%02x ", radio.readReg(a, 1));
Wayne Roberts 3:56fc764dee0a 2090 if ((a & 0x1f) == 0x1f)
dudmuck 13:8ce61a1897ab 2091 printf("\r\n%03x ", a+1);
Wayne Roberts 3:56fc764dee0a 2092 }
dudmuck 13:8ce61a1897ab 2093 printf("\r\n");
Wayne Roberts 3:56fc764dee0a 2094 }
Wayne Roberts 1:0817a150122b 2095
Wayne Roberts 4:fa31fdf4ec8d 2096 unsigned Radio::read_register(unsigned addr)
Wayne Roberts 4:fa31fdf4ec8d 2097 {
Wayne Roberts 4:fa31fdf4ec8d 2098 return radio.readReg(addr, 1);
Wayne Roberts 4:fa31fdf4ec8d 2099 }
Wayne Roberts 4:fa31fdf4ec8d 2100
Wayne Roberts 4:fa31fdf4ec8d 2101 void Radio::write_register(unsigned addr, unsigned val)
Wayne Roberts 4:fa31fdf4ec8d 2102 {
Wayne Roberts 4:fa31fdf4ec8d 2103 radio.writeReg(addr, val, 1);
Wayne Roberts 4:fa31fdf4ec8d 2104 }
Wayne Roberts 4:fa31fdf4ec8d 2105
Wayne Roberts 1:0817a150122b 2106 #endif /* ..SX126x_H */