work on nvs
This commit is contained in:
@@ -8,6 +8,7 @@ set(SOURCES
|
||||
"char_lcd.cpp"
|
||||
"game_info.cpp"
|
||||
"game_timer.cpp"
|
||||
"hwdata.cpp"
|
||||
"i2c_lcd_pcf8574.c"
|
||||
"i2c.cpp"
|
||||
"leds.cpp"
|
||||
|
||||
@@ -4,6 +4,7 @@ void init_drivers() {
|
||||
init_i2c();
|
||||
// init char_lcd so we can use it to report other initialization errors.
|
||||
init_lcd();
|
||||
init_nvs();
|
||||
init_star_code_system();
|
||||
// init the bottom half so that we can get user input.
|
||||
init_bottom_half();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "game_timer.h"
|
||||
#include "i2c.h"
|
||||
#include "leds.h"
|
||||
#include "nvs.h"
|
||||
#include "power.h"
|
||||
#include "sd.h"
|
||||
#include "speaker.h"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "hwdata.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef HWDATA_H
|
||||
#define HWDATA_H
|
||||
|
||||
|
||||
|
||||
#endif /* HWDATA_H */
|
||||
@@ -1,3 +1,38 @@
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_log.h"
|
||||
#include "bottom_half.h"
|
||||
#include "char_lcd.h"
|
||||
|
||||
static const char* TAG = "nvs";
|
||||
|
||||
nvs_handle_t hw_handle;
|
||||
|
||||
bool init_nvs() {
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
// NVS partition was truncated, erase and retry
|
||||
ESP_LOGE(TAG, "Failed to init nvs flash: %s.", esp_err_to_name(ret));
|
||||
lcd_print(1, 0, "NVS: ");
|
||||
lcd_print(1, 4, esp_err_to_name(ret));
|
||||
lcd_print(2, 0, "Press Yellow to skip");
|
||||
lcd_print(3, 0, "Press Red to erase");
|
||||
|
||||
ButtonKey button;
|
||||
while (!( get_button_pressed(&button) && (button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
lcd_clear();
|
||||
|
||||
if (button == ButtonKey::button_yellow) {
|
||||
return false;
|
||||
}
|
||||
if (button == ButtonKey::button_red) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
#ifndef NVS_H
|
||||
#define NVS_H
|
||||
|
||||
|
||||
/// @brief Initializes the NVS.
|
||||
bool init_nvs();
|
||||
|
||||
#endif /* NVS_H */
|
||||
Reference in New Issue
Block a user