Tactility/tactility-headless/src/esp_partitions.c
Ken Van Hoeylandt 27730260e0
Project restructuring: add tactility-headless (#55)
- Created `tactility-headless` to support ESP32 firmwares that don't require graphics
- `tactility` subproject now contains both PC and ESP32 code (to avoid having to split up `tactility` and `tactility-headless` into separate projects, which would result in a very complex dependency tree)
- `tactility` subproject is now defined as component for ESP32 and as regular module for PC
- Improvements for dispatcher
- Added `project-structure.puml` to docs
- `Gui` service now depends on `Loader` service instead of the reverse
- Added `statusbar_updater` service for updating Wi-Fi and SD card icons
2024-08-31 17:56:28 +02:00

71 lines
2.0 KiB
C

#ifdef ESP_TARGET
#include "esp_partitions.h"
#include "esp_spiffs.h"
#include "log.h"
#include "nvs_flash.h"
static const char* TAG = "filesystem";
static esp_err_t nvs_flash_init_safely() {
esp_err_t result = nvs_flash_init();
if (result == ESP_ERR_NVS_NO_FREE_PAGES || result == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
result = nvs_flash_init();
}
return result;
}
static esp_err_t spiffs_init(esp_vfs_spiffs_conf_t* conf) {
esp_err_t ret = esp_vfs_spiffs_register(conf);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
TT_LOG_E(TAG, "Failed to mount or format filesystem %s", conf->base_path);
} else if (ret == ESP_ERR_NOT_FOUND) {
TT_LOG_E(TAG, "Failed to find SPIFFS partition %s", conf->base_path);
} else {
TT_LOG_E(TAG, "Failed to initialize SPIFFS %s (%s)", conf->base_path, esp_err_to_name(ret));
}
return ESP_FAIL;
}
size_t total = -1, used = 0;
ret = esp_spiffs_info(NULL, &total, &used);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to get SPIFFS partition information for %s (%s)", conf->base_path, esp_err_to_name(ret));
} else {
TT_LOG_I(TAG, "Partition size for %s: total: %d, used: %d", conf->base_path, total, used);
}
return ESP_OK;
}
esp_err_t tt_esp_partitions_init() {
ESP_ERROR_CHECK(nvs_flash_init_safely());
esp_vfs_spiffs_conf_t assets_spiffs = {
.base_path = MOUNT_POINT_ASSETS,
.partition_label = NULL,
.max_files = 100,
.format_if_mount_failed = false
};
if (spiffs_init(&assets_spiffs) != ESP_OK) {
return ESP_FAIL;
}
esp_vfs_spiffs_conf_t config_spiffs = {
.base_path = MOUNT_POINT_CONFIG,
.partition_label = "config",
.max_files = 100,
.format_if_mount_failed = false
};
if (spiffs_init(&config_spiffs) != ESP_OK) {
return ESP_FAIL;
}
return ESP_OK;
}
#endif // ESP_TARGET