Sorry for small info!
Some helper function:
Code: Select all
#include <esp_spi_flash.h>
#include <rom/spi_flash.h>
#include "../cache_utils.h"
SpiFlashOpResult IRAM_ATTR guarded_spi_flash_read(size_t src_addr, void *dest, size_t size){
spi_flash_disable_interrupts_caches_and_other_cpu();
SpiFlashOpResult ret = SPIRead(src_addr,dest,size);
spi_flash_enable_interrupts_caches_and_other_cpu();
return ret;
}
SpiFlashOpResult IRAM_ATTR guarded_spi_flash_write(size_t src_addr, const uint32_t *dest, size_t size){
spi_flash_disable_interrupts_caches_and_other_cpu();
size_t alignedSize = size | 0x03;
SpiFlashOpResult ret = SPIEraseArea(src_addr,alignedSize);
ret = SPIWrite(src_addr,dest,size);
spi_flash_enable_interrupts_caches_and_other_cpu();
return ret;
}
Config class:
Code: Select all
#ifndef CONFIG_H
#define CONFIG_H
#include <stdio.h>
#include "configuration.h"
#include <rom/spi_flash.h>
extern "C" SpiFlashOpResult guarded_spi_flash_read(size_t src_addr, void *dest, size_t size);
extern "C" SpiFlashOpResult guarded_spi_flash_write(size_t src_addr, const uint32_t *dest, size_t size);
class Config {
public:
enum class NetworkType {
AP, CLIENT, AP_CLIENT
};
Config(){};
virtual ~Config(){};
char ssid[32+1];
char password[64+1];
NetworkType networkType;
virtual int sizeObject() {
return sizeof(class Config);
}
static int sizeClass() {
return sizeof(class Config);
}
virtual void getFromFlash() {
SpiFlashOpResult err = guarded_spi_flash_read((size_t)CONFIGURATION_CONFIG_START_ADDRESS,(void *)this,(size_t)sizeObject());
}
virtual void storeToFlash() {
SpiFlashOpResult err = guarded_spi_flash_write((size_t)CONFIGURATION_CONFIG_START_ADDRESS,(const uint32_t *)this,(size_t)sizeObject());
}
enum class ErrorType {
OK = SPI_FLASH_RESULT_OK, SPI_FLASH_RESULT_ERR = SPI_FLASH_RESULT_ERR,SPI_FLASH_RESULT_TIMEOUT = SPI_FLASH_RESULT_TIMEOUT
};
};
#endif /* CONFIG_H */