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