mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-25 06:22:11 +03:00
ESP class - move interpretation of magic bytes in function
This commit is contained in:
@ -177,26 +177,7 @@ uint32_t EspClass::getFlashChipSize(void)
|
|||||||
uint8_t * bytes = (uint8_t *) &data;
|
uint8_t * bytes = (uint8_t *) &data;
|
||||||
// read first 4 byte (magic byte + flash config)
|
// read first 4 byte (magic byte + flash config)
|
||||||
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
|
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
|
||||||
switch((bytes[3] & 0xf0) >> 4) {
|
return magicFlashChipSize((bytes[3] & 0xf0) >> 4);
|
||||||
case 0x0: // 4 Mbit (512KB)
|
|
||||||
return (512_kB);
|
|
||||||
case 0x1: // 2 MBit (256KB)
|
|
||||||
return (256_kB);
|
|
||||||
case 0x2: // 8 MBit (1MB)
|
|
||||||
return (1_MB);
|
|
||||||
case 0x3: // 16 MBit (2MB)
|
|
||||||
return (2_MB);
|
|
||||||
case 0x4: // 32 MBit (4MB)
|
|
||||||
return (4_MB);
|
|
||||||
case 0x5: // 64 MBit (8MB)
|
|
||||||
return (8_MB);
|
|
||||||
case 0x6: // 128 MBit (16MB)
|
|
||||||
return (16_MB);
|
|
||||||
case 0x7: // 256 MBit (32MB)
|
|
||||||
return (32_MB);
|
|
||||||
default: // fail?
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -207,18 +188,7 @@ uint32_t EspClass::getFlashChipSpeed(void)
|
|||||||
uint8_t * bytes = (uint8_t *) &data;
|
uint8_t * bytes = (uint8_t *) &data;
|
||||||
// read first 4 byte (magic byte + flash config)
|
// read first 4 byte (magic byte + flash config)
|
||||||
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
|
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
|
||||||
switch(bytes[3] & 0x0F) {
|
return magicFlashChipSpeed(bytes[3] & 0x0F);
|
||||||
case 0x0: // 40 MHz
|
|
||||||
return (40_MHz);
|
|
||||||
case 0x1: // 26 MHz
|
|
||||||
return (26_MHz);
|
|
||||||
case 0x2: // 20 MHz
|
|
||||||
return (20_MHz);
|
|
||||||
case 0xf: // 80 MHz
|
|
||||||
return (80_MHz);
|
|
||||||
default: // fail?
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -230,10 +200,53 @@ FlashMode_t EspClass::getFlashChipMode(void)
|
|||||||
uint8_t * bytes = (uint8_t *) &data;
|
uint8_t * bytes = (uint8_t *) &data;
|
||||||
// read first 4 byte (magic byte + flash config)
|
// read first 4 byte (magic byte + flash config)
|
||||||
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
|
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
|
||||||
mode = (FlashMode_t) bytes[2];
|
mode = magicFlashChipMode(bytes[2]);
|
||||||
if(mode > FM_DOUT) {
|
}
|
||||||
mode = FM_UNKNOWN;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t EspClass::magicFlashChipSize(uint8_t byte) {
|
||||||
|
switch(byte & 0x0F) {
|
||||||
|
case 0x0: // 4 Mbit (512KB)
|
||||||
|
return (512_kB);
|
||||||
|
case 0x1: // 2 MBit (256KB)
|
||||||
|
return (256_kB);
|
||||||
|
case 0x2: // 8 MBit (1MB)
|
||||||
|
return (1_MB);
|
||||||
|
case 0x3: // 16 MBit (2MB)
|
||||||
|
return (2_MB);
|
||||||
|
case 0x4: // 32 MBit (4MB)
|
||||||
|
return (4_MB);
|
||||||
|
case 0x5: // 64 MBit (8MB)
|
||||||
|
return (8_MB);
|
||||||
|
case 0x6: // 128 MBit (16MB)
|
||||||
|
return (16_MB);
|
||||||
|
case 0x7: // 256 MBit (32MB)
|
||||||
|
return (32_MB);
|
||||||
|
default: // fail?
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) {
|
||||||
|
switch(byte & 0x0F) {
|
||||||
|
case 0x0: // 40 MHz
|
||||||
|
return (40_MHz);
|
||||||
|
case 0x1: // 26 MHz
|
||||||
|
return (26_MHz);
|
||||||
|
case 0x2: // 20 MHz
|
||||||
|
return (20_MHz);
|
||||||
|
case 0xf: // 80 MHz
|
||||||
|
return (80_MHz);
|
||||||
|
default: // fail?
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FlashMode_t EspClass::magicFlashChipMode(uint8_t byte) {
|
||||||
|
FlashMode_t mode = (FlashMode_t) byte;
|
||||||
|
if(mode > FM_DOUT) {
|
||||||
|
mode = FM_UNKNOWN;
|
||||||
}
|
}
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,10 @@ class EspClass {
|
|||||||
FlashMode_t getFlashChipMode();
|
FlashMode_t getFlashChipMode();
|
||||||
uint32_t getFlashChipSizeByChipId();
|
uint32_t getFlashChipSizeByChipId();
|
||||||
|
|
||||||
|
uint32_t magicFlashChipSize(uint8_t byte);
|
||||||
|
uint32_t magicFlashChipSpeed(uint8_t byte);
|
||||||
|
FlashMode_t magicFlashChipMode(uint8_t byte);
|
||||||
|
|
||||||
bool checkFlashConfig(bool needsEquals = false);
|
bool checkFlashConfig(bool needsEquals = false);
|
||||||
|
|
||||||
bool flashEraseSector(uint32_t sector);
|
bool flashEraseSector(uint32_t sector);
|
||||||
|
Reference in New Issue
Block a user