Merge pull request #28 from pkendall64/reset

Add hard/soft reset methods
This commit is contained in:
Adwait 2022-07-12 16:50:20 +05:30 committed by GitHub
commit 97a72d09c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,7 @@ class ESPLoader {
// Only Stub supported commands
ESP_ERASE_FLASH = 0xD0;
ESP_ERASE_REGION = 0xD1;
ESP_RUN_USER_CODE = 0xD3;
ESP_IMAGE_MAGIC = 0xe9;
ESP_CHECKSUM_MAGIC = 0xef;
@ -860,6 +861,26 @@ class ESPLoader {
this.log("Device: "+((flashid >> 8) & 0xff).toString(16) + flid_lowbyte.toString(16));
this.log("Detected flash size: " + this.DETECTED_FLASH_SIZES[flid_lowbyte]);
}
hard_reset = async() => {
this.transport.setRTS(true); // EN->LOW
await this._sleep(100);
this.transport.setRTS(false);
}
soft_reset = async() => {
if (!this.IS_STUB) {
// 'run user code' is as close to a soft reset as we can do
this.flash_begin(0, 0);
this.flash_finish(false);
} else if (this.chip.CHIP_NAME != "ESP8266") {
throw new ESPError("Soft resetting is currently only supported on ESP8266");
} else {
// running user code from stub loader requires some hacks
// in the stub loader
this.command({op: this.ESP_RUN_USER_CODE, wait_response: false});
}
}
}