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