use dynamic targets import
This commit is contained in:
parent
2ed745673c
commit
bf13211362
@ -12,6 +12,7 @@ const config = {
|
|||||||
name: "esptooljs",
|
name: "esptooljs",
|
||||||
file: 'bundle.js',
|
file: 'bundle.js',
|
||||||
format: 'es',
|
format: 'es',
|
||||||
|
inlineDynamicImports: true
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
resolve(),
|
resolve(),
|
||||||
|
@ -1,25 +1,34 @@
|
|||||||
import { ESPError } from "./error";
|
import { ESPError } from "./error";
|
||||||
import { inflate, deflate } from "pako";
|
import { inflate, deflate } from "pako";
|
||||||
import ESP32ROM from "./targets/esp32";
|
|
||||||
import { Transport } from "./webserial";
|
import { Transport } from "./webserial";
|
||||||
import { ROM } from "./targets/rom";
|
import { ROM } from "./targets/rom";
|
||||||
import ESP32C3ROM from "./targets/esp32c3";
|
|
||||||
import ESP32S3ROM from "./targets/esp32s3";
|
|
||||||
import ESP32S2ROM from "./targets/esp32s2";
|
|
||||||
import ESP8266ROM from "./targets/esp8266";
|
|
||||||
|
|
||||||
const MAGIC_TO_CHIP: { [key: number]: ROM } = {
|
async function magic2Chip(magic: number): Promise<ROM> {
|
||||||
0x00f01d83: new ESP32ROM(),
|
switch (magic) {
|
||||||
0x6921506f: new ESP32C3ROM(), // ECO 1+2
|
case 0x00f01d83: {
|
||||||
0x1b31506f: new ESP32C3ROM(), //ECO 3
|
const { ESP32ROM } = await import("./targets/esp32");
|
||||||
0x09: new ESP32S3ROM(),
|
return new ESP32ROM();
|
||||||
0x000007c6: new ESP32S2ROM(),
|
}
|
||||||
0xfff0c101: new ESP8266ROM(),
|
case 0x6921506f:
|
||||||
};
|
case 0x1b31506f: {
|
||||||
|
const { ESP32C3ROM } = await import("./targets/esp32c3");
|
||||||
export interface ESPBinFile {
|
return new ESP32C3ROM();
|
||||||
data: string;
|
}
|
||||||
address: number;
|
case 0x09: {
|
||||||
|
const { ESP32S3ROM } = await import("./targets/esp32s3");
|
||||||
|
return new ESP32S3ROM();
|
||||||
|
}
|
||||||
|
case 0x000007c6: {
|
||||||
|
const { ESP32S2ROM } = await import("./targets/esp32s2");
|
||||||
|
return new ESP32S2ROM();
|
||||||
|
}
|
||||||
|
case 0xfff0c101: {
|
||||||
|
const { ESP8266ROM } = await import("./targets/esp8266");
|
||||||
|
return new ESP8266ROM();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEspLoaderTerminal {
|
export interface IEspLoaderTerminal {
|
||||||
@ -307,7 +316,7 @@ export class ESPLoader {
|
|||||||
while (i--) {
|
while (i--) {
|
||||||
try {
|
try {
|
||||||
const resp = await this.sync();
|
const resp = await this.sync();
|
||||||
this.log(resp[0].toString(0));
|
this.log(resp[0].toString());
|
||||||
return "success";
|
return "success";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.log(error);
|
this.log(error);
|
||||||
@ -349,10 +358,8 @@ export class ESPLoader {
|
|||||||
if (!detecting) {
|
if (!detecting) {
|
||||||
const chip_magic_value = (await this.read_reg(0x40001000)) >>> 0;
|
const chip_magic_value = (await this.read_reg(0x40001000)) >>> 0;
|
||||||
this.log("Chip Magic " + chip_magic_value.toString(16));
|
this.log("Chip Magic " + chip_magic_value.toString(16));
|
||||||
|
this.chip = await magic2Chip(chip_magic_value);
|
||||||
if (chip_magic_value in MAGIC_TO_CHIP) {
|
if (this.chip === null) {
|
||||||
this.chip = MAGIC_TO_CHIP[chip_magic_value];
|
|
||||||
} else {
|
|
||||||
throw new ESPError(`Unexpected CHIP magic value ${chip_magic_value}. Failed to autodetect chip type.`);
|
throw new ESPError(`Unexpected CHIP magic value ${chip_magic_value}. Failed to autodetect chip type.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -840,7 +847,10 @@ export class ESPLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async write_flash(
|
async write_flash(
|
||||||
fileArray: ESPBinFile[],
|
fileArray: {
|
||||||
|
data: string;
|
||||||
|
address: number;
|
||||||
|
}[],
|
||||||
flash_size = "keep",
|
flash_size = "keep",
|
||||||
flash_mode = "keep",
|
flash_mode = "keep",
|
||||||
flash_freq = "keep",
|
flash_freq = "keep",
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export { IEspLoaderTerminal, ESPLoader, ESPBinFile } from "./esploader";
|
export { IEspLoaderTerminal, ESPLoader } from "./esploader";
|
||||||
export { Transport } from "./webserial";
|
export { Transport } from "./webserial";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ESPLoader } from "../esploader";
|
import { ESPLoader } from "../esploader";
|
||||||
import { ROM } from "./rom";
|
import { ROM } from "./rom";
|
||||||
|
|
||||||
export default class ESP32ROM extends ROM {
|
export class ESP32ROM extends ROM {
|
||||||
public CHIP_NAME = "ESP32";
|
public CHIP_NAME = "ESP32";
|
||||||
public IMAGE_CHIP_ID = 0;
|
public IMAGE_CHIP_ID = 0;
|
||||||
public EFUSE_RD_REG_BASE = 0x3ff5a000;
|
public EFUSE_RD_REG_BASE = 0x3ff5a000;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ESPLoader } from "../esploader";
|
import { ESPLoader } from "../esploader";
|
||||||
import { ROM } from "./rom";
|
import { ROM } from "./rom";
|
||||||
|
|
||||||
export default class ESP32C3ROM extends ROM {
|
export class ESP32C3ROM extends ROM {
|
||||||
public CHIP_NAME = "ESP32-C3";
|
public CHIP_NAME = "ESP32-C3";
|
||||||
public IMAGE_CHIP_ID = 5;
|
public IMAGE_CHIP_ID = 5;
|
||||||
public EFUSE_BASE = 0x60008800;
|
public EFUSE_BASE = 0x60008800;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ESPLoader } from "../esploader";
|
import { ESPLoader } from "../esploader";
|
||||||
import { ROM } from "./rom";
|
import { ROM } from "./rom";
|
||||||
|
|
||||||
export default class ESP32S2ROM extends ROM {
|
export class ESP32S2ROM extends ROM {
|
||||||
public CHIP_NAME = "ESP32-S2";
|
public CHIP_NAME = "ESP32-S2";
|
||||||
public IMAGE_CHIP_ID = 2;
|
public IMAGE_CHIP_ID = 2;
|
||||||
public MAC_EFUSE_REG = 0x3f41a044;
|
public MAC_EFUSE_REG = 0x3f41a044;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ESPLoader } from "../esploader";
|
import { ESPLoader } from "../esploader";
|
||||||
import { ROM } from "./rom";
|
import { ROM } from "./rom";
|
||||||
|
|
||||||
export default class ESP32S3ROM extends ROM {
|
export class ESP32S3ROM extends ROM {
|
||||||
public CHIP_NAME = "ESP32-S3";
|
public CHIP_NAME = "ESP32-S3";
|
||||||
public IMAGE_CHIP_ID = 9;
|
public IMAGE_CHIP_ID = 9;
|
||||||
public EFUSE_BASE = 0x60007000;
|
public EFUSE_BASE = 0x60007000;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ESPLoader } from "../esploader";
|
import { ESPLoader } from "../esploader";
|
||||||
import { ROM } from "./rom";
|
import { ROM } from "./rom";
|
||||||
|
|
||||||
export default class ESP8266ROM extends ROM {
|
export class ESP8266ROM extends ROM {
|
||||||
public CHIP_NAME = "ESP8266";
|
public CHIP_NAME = "ESP8266";
|
||||||
public CHIP_DETECT_MAGIC_VALUE = [0xfff0c101];
|
public CHIP_DETECT_MAGIC_VALUE = [0xfff0c101];
|
||||||
public EFUSE_RD_REG_BASE = 0x3ff00050;
|
public EFUSE_RD_REG_BASE = 0x3ff00050;
|
||||||
|
Loading…
Reference in New Issue
Block a user