(options, progress = function() {})
| 231 | return result; |
| 232 | } |
| 233 | async write(options, progress = function() {}) { |
| 234 | const sizes = ("esp32" === this.#mcu) ? sizes_esp32 : sizes_esp8266; |
| 235 | const bootloaderOffset = ("esp32" === this.#mcu) ? 0x1000 : 0; |
| 236 | let offset = options.offset; |
| 237 | let data = new Uint8Array(options.data); |
| 238 | |
| 239 | if ((undefined === offset) || ("app" === offset)) |
| 240 | offset = ("esp32" === this.#mcu) ? 0x10000 : 0x1000; |
| 241 | else if ("bootloader" === offset) |
| 242 | offset = bootloaderOffset; |
| 243 | |
| 244 | if ((offset === bootloaderOffset) && (0xe9 === data[0])) { |
| 245 | let mode = modes[data[2]]; |
| 246 | let frequency = frequencies[data[3] & 0x0F]; |
| 247 | let size = sizes[data[3] >> 4]; |
| 248 | let update; |
| 249 | |
| 250 | if (this.#flashOptions.mode && (this.#flashOptions.mode !== mode)) { |
| 251 | mode = this.#flashOptions.mode; |
| 252 | if (modes.indexOf(mode) < 0) |
| 253 | throw new Error("invalid flash mode"); |
| 254 | update = true; |
| 255 | } |
| 256 | |
| 257 | if (this.#flashOptions.frequency && (this.#flashOptions.frequency !== frequency)) { |
| 258 | frequency = this.#flashOptions.frequency; |
| 259 | if (frequencies.indexOf(frequency) < 0) |
| 260 | throw new Error("invalid flash frequency"); |
| 261 | update = true; |
| 262 | } |
| 263 | |
| 264 | if (this.#flashOptions.size && (this.#flashOptions.size !== size)) { |
| 265 | size = this.#flashOptions.size; |
| 266 | if (sizes.indexOf(size) < 0) |
| 267 | throw new Error("invalid flash size"); |
| 268 | update = true; |
| 269 | } |
| 270 | |
| 271 | if (update) { |
| 272 | data = data.slice(0); |
| 273 | data[2] = modes.indexOf(mode); |
| 274 | data[3] = frequencies.indexOf(frequency) | (sizes.indexOf(size) << 4); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | await this.downloadToFlash(data, offset, true, progress); |
| 279 | } |
| 280 | async restart() { |
| 281 | //@@ command -- flash end to restart! |
| 282 | this.#serial.set({DTR: false, RTS: true}); |
nothing calls this directly
no test coverage detected