Add wifi, nvs and inplace_function implementations

This commit is contained in:
2024-03-02 15:27:26 +01:00
parent d8caca71e2
commit 418e057377
10 changed files with 519 additions and 48 deletions

View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "src/nvs.cpp" INCLUDE_DIRS include REQUIRES
nvs_flash)

View File

@@ -0,0 +1,10 @@
#pragma once
namespace nvs {
void init();
} // namespace nvs

View 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