UNPKG

2.64 kBJavaScriptView Raw
1import{R as t}from"./rom-B2LvkjpK.js";class s extends t{constructor(){super(...arguments),this.CHIP_NAME="ESP32",this.IMAGE_CHIP_ID=0,this.EFUSE_RD_REG_BASE=1073061888,this.DR_REG_SYSCON_BASE=1073111040,this.UART_CLKDIV_REG=1072955412,this.UART_CLKDIV_MASK=1048575,this.UART_DATE_REG_ADDR=1610612856,this.XTAL_CLK_DIVIDER=1,this.FLASH_SIZES={"1MB":0,"2MB":16,"4MB":32,"8MB":48,"16MB":64},this.FLASH_WRITE_SIZE=1024,this.BOOTLOADER_FLASH_OFFSET=4096,this.SPI_REG_BASE=1072963584,this.SPI_USR_OFFS=28,this.SPI_USR1_OFFS=32,this.SPI_USR2_OFFS=36,this.SPI_W0_OFFS=128,this.SPI_MOSI_DLEN_OFFS=40,this.SPI_MISO_DLEN_OFFS=44}async readEfuse(t,s){const e=this.EFUSE_RD_REG_BASE+4*s;return t.debug("Read efuse "+e),await t.readReg(e)}async getPkgVersion(t){const s=await this.readEfuse(t,3);let e=s>>9&7;return e+=(s>>2&1)<<3,e}async getChipRevision(t){const s=await this.readEfuse(t,3),e=await this.readEfuse(t,5),i=await t.readReg(this.DR_REG_SYSCON_BASE+124);return 0!=(s>>15&1)?0!=(e>>20&1)?0!=(i>>31&1)?3:2:1:0}async getChipDescription(t){const s=["ESP32-D0WDQ6","ESP32-D0WD","ESP32-D2WD","","ESP32-U4WDH","ESP32-PICO-D4","ESP32-PICO-V3-02"];let e="";const i=await this.getPkgVersion(t),a=await this.getChipRevision(t),h=3==a;return 0!=(1&await this.readEfuse(t,3))&&(s[0]="ESP32-S0WDQ6",s[1]="ESP32-S0WD"),h&&(s[5]="ESP32-PICO-V3"),e=i>=0&&i<=6?s[i]:"Unknown ESP32",!h||0!==i&&1!==i||(e+="-V3"),e+" (revision "+a+")"}async getChipFeatures(t){const s=["Wi-Fi"],e=await this.readEfuse(t,3);0===(2&e)&&s.push(" BT");0!==(1&e)?s.push(" Single Core"):s.push(" Dual Core");if(0!==(8192&e)){0!==(4096&e)?s.push(" 160MHz"):s.push(" 240MHz")}const i=await this.getPkgVersion(t);-1!==[2,4,5,6].indexOf(i)&&s.push(" Embedded Flash"),6===i&&s.push(" Embedded PSRAM");0!==(await this.readEfuse(t,4)>>8&31)&&s.push(" VRef calibration in efuse");0!==(e>>14&1)&&s.push(" BLK3 partially reserved");const a=3&await this.readEfuse(t,6);return s.push(" Coding Scheme "+["None","3/4","Repeat (UNSUPPORTED)","Invalid"][a]),s}async getCrystalFreq(t){const s=await t.readReg(this.UART_CLKDIV_REG)&this.UART_CLKDIV_MASK,e=t.transport.baudrate*s/1e6/this.XTAL_CLK_DIVIDER;let i;return i=e>33?40:26,Math.abs(i-e)>1&&t.info("WARNING: Unsupported crystal in use"),i}_d2h(t){const s=(+t).toString(16);return 1===s.length?"0"+s:s}async readMac(t){let s=await this.readEfuse(t,1);s>>>=0;let e=await this.readEfuse(t,2);e>>>=0;const i=new Uint8Array(6);return i[0]=e>>8&255,i[1]=255&e,i[2]=s>>24&255,i[3]=s>>16&255,i[4]=s>>8&255,i[5]=255&s,this._d2h(i[0])+":"+this._d2h(i[1])+":"+this._d2h(i[2])+":"+this._d2h(i[3])+":"+this._d2h(i[4])+":"+this._d2h(i[5])}}export{s as ESP32ROM};