From 450ea0d211739090506113ddf893d133146e9505 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sat, 11 Feb 2017 23:34:43 +0200 Subject: [PATCH] Update ESP class --- cores/esp32/Esp.cpp | 35 +++++++---------------------------- cores/esp32/Esp.h | 10 ++-------- 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index 70203701..2d12ee5d 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -21,6 +21,7 @@ #include "Esp.h" #include "rom/spi_flash.h" #include "esp_deep_sleep.h" +#include "esp_spi_flash.h" #include //#define DEBUG_SERIAL Serial @@ -113,7 +114,7 @@ uint32_t EspClass::getFlashChipSize(void) uint32_t data; uint8_t * bytes = (uint8_t *) &data; // read first 4 byte (magic byte + flash config) - if(SPIRead(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { + if(flashRead(0x0000, &data, 4) == ESP_OK) { return magicFlashChipSize((bytes[3] & 0xf0) >> 4); } return 0; @@ -124,7 +125,7 @@ uint32_t EspClass::getFlashChipSpeed(void) uint32_t data; uint8_t * bytes = (uint8_t *) &data; // read first 4 byte (magic byte + flash config) - if(SPIRead(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { + if(flashRead(0x0000, &data, 4) == ESP_OK) { return magicFlashChipSpeed(bytes[3] & 0x0F); } return 0; @@ -136,7 +137,7 @@ FlashMode_t EspClass::getFlashChipMode(void) uint32_t data; uint8_t * bytes = (uint8_t *) &data; // read first 4 byte (magic byte + flash config) - if(SPIRead(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { + if(flashRead(0x0000, &data, 4) == ESP_OK) { mode = magicFlashChipMode(bytes[2]); } return mode; @@ -191,39 +192,17 @@ FlashMode_t EspClass::magicFlashChipMode(uint8_t byte) return mode; } -bool EspClass::eraseConfig(void) -{ - bool ret = true; - size_t cfgAddr = (getFlashChipSize() - 0x4000); - size_t cfgSize = (8*1024); - - while(cfgSize) { - - if(SPIEraseSector((cfgAddr / 4096)) != SPI_FLASH_RESULT_OK) { - ret = false; - } - - cfgSize -= 4096; - cfgAddr += 4096; - } - - return ret; -} - bool EspClass::flashEraseSector(uint32_t sector) { - int rc = SPIEraseSector(sector); - return rc == 0; + return spi_flash_erase_sector(sector) == ESP_OK; } bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) { - int rc = SPIWrite(offset, (uint32_t*) data, size); - return rc == 0; + return spi_flash_write(offset, (uint32_t*) data, size) == ESP_OK; } bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) { - int rc = SPIRead(offset, (uint32_t*) data, size); - return rc == 0; + return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK; } diff --git a/cores/esp32/Esp.h b/cores/esp32/Esp.h index 02eb25ba..e23e6076 100644 --- a/cores/esp32/Esp.h +++ b/cores/esp32/Esp.h @@ -55,15 +55,12 @@ public: ~EspClass() {} void restart(); uint32_t getFreeHeap(); - - uint32_t getChipId(); - + uint8_t getCpuFreqMHz(){ return F_CPU; } + uint32_t getCycleCount(); const char * getSdkVersion(); void deepSleep(uint32_t time_us); - uint8_t getCpuFreqMHz(); - uint32_t getFlashChipSize(); uint32_t getFlashChipSpeed(); FlashMode_t getFlashChipMode(); @@ -76,9 +73,6 @@ public: bool flashWrite(uint32_t offset, uint32_t *data, size_t size); bool flashRead(uint32_t offset, uint32_t *data, size_t size); - bool eraseConfig(); - - uint32_t getCycleCount(); }; extern EspClass ESP;