Skip to content

Commit

Permalink
add spiffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Borcin committed Oct 31, 2023
1 parent bab0ac2 commit ac1e646
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions bsp/esp32_s3_korvo_1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ idf_component_register(
SRCS "esp32_s3_korvo_1.c" ${SRC_VER}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES spiffs
)
36 changes: 35 additions & 1 deletion bsp/esp32_s3_korvo_1/esp32_s3_korvo_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include "iot_button.h"
#include "bsp/esp-bsp.h"
#include "bsp_err_check.h"
#include "esp_spiffs.h"

static const char *TAG = "ESP32-S3-Korvo-1";
static const char *TAG = "S3-Korvo-1";

static led_strip_handle_t led_strip;

Expand Down Expand Up @@ -155,3 +156,36 @@ esp_err_t bsp_led_rgb_set(uint8_t r, uint8_t g, uint8_t b)
ret |= led_strip_refresh(led_strip);
return ret;
}

esp_err_t bsp_spiffs_mount(void)
{
esp_vfs_spiffs_conf_t conf = {
.base_path = CONFIG_BSP_SPIFFS_MOUNT_POINT,
.partition_label = CONFIG_BSP_SPIFFS_PARTITION_LABEL,
.max_files = CONFIG_BSP_SPIFFS_MAX_FILES,
#ifdef CONFIG_BSP_SPIFFS_FORMAT_ON_MOUNT_FAIL
.format_if_mount_failed = true,
#else
.format_if_mount_failed = false,
#endif
};

esp_err_t ret_val = esp_vfs_spiffs_register(&conf);

BSP_ERROR_CHECK_RETURN_ERR(ret_val);

size_t total = 0, used = 0;
ret_val = esp_spiffs_info(conf.partition_label, &total, &used);
if (ret_val != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret_val));
} else {
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
}

return ret_val;
}

esp_err_t bsp_spiffs_unmount(void)
{
return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL);
}
38 changes: 38 additions & 0 deletions bsp/esp32_s3_korvo_1/include/bsp/esp32_s3_korvo_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,44 @@ esp_err_t bsp_led_init();
*/
esp_err_t bsp_led_rgb_set(uint8_t r, uint8_t g, uint8_t b);

/**************************************************************************************************
*
* SPIFFS
*
* After mounting the SPIFFS, it can be accessed with stdio functions ie.:
* \code{.c}
* FILE* f = fopen(BSP_SPIFFS_MOUNT_POINT"/hello.txt", "w");
* fprintf(f, "Hello World!\n");
* fclose(f);
* \endcode
**************************************************************************************************/
#define BSP_SPIFFS_MOUNT_POINT CONFIG_BSP_SPIFFS_MOUNT_POINT

/**
* @brief Mount SPIFFS to virtual file system
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if esp_vfs_spiffs_register was already called
* - ESP_ERR_NO_MEM if memory can not be allocated
* - ESP_FAIL if partition can not be mounted
* - other error codes
*/
esp_err_t bsp_spiffs_mount(void);

/**
* @brief Unmount SPIFFS from virtual file system
*
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_FOUND if the partition table does not contain SPIFFS partition with given label
* - ESP_ERR_INVALID_STATE if esp_vfs_spiffs_unregister was already called
* - ESP_ERR_NO_MEM if memory can not be allocated
* - ESP_FAIL if partition can not be mounted
* - other error codes
*/
esp_err_t bsp_spiffs_unmount(void);

#ifdef __cplusplus
}
#endif

0 comments on commit ac1e646

Please sign in to comment.