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