Add wifi, nvs and inplace_function implementations
This commit is contained in:
2
components/nvs/CMakeLists.txt
Normal file
2
components/nvs/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "src/nvs.cpp" INCLUDE_DIRS include REQUIRES
|
||||
nvs_flash)
|
||||
10
components/nvs/include/nvs/nvs.h
Normal file
10
components/nvs/include/nvs/nvs.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace nvs {
|
||||
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
} // namespace nvs
|
||||
26
components/nvs/src/nvs.cpp
Normal file
26
components/nvs/src/nvs.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
|
||||
namespace nvs {
|
||||
|
||||
|
||||
void init() {
|
||||
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
|
||||
if (nvs_flash_erase() != ESP_OK)
|
||||
throw std::runtime_error("Failed to erase NVS");
|
||||
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
|
||||
if (ret != ESP_OK) throw std::runtime_error("Failed to initialize NVS");
|
||||
}
|
||||
|
||||
|
||||
} // namespace nvs
|
||||
Reference in New Issue
Block a user