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