Merge branch 'main' into LCD_API
This commit is contained in:
61
project/Core/Inc/llfs.h
Normal file
61
project/Core/Inc/llfs.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file llfs.h
|
||||
* @brief Linked List Filesystem header (llfs)
|
||||
* @author Lorenz C.
|
||||
*/
|
||||
|
||||
#ifndef LLFS_H
|
||||
#define LLFS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Representation of a file in the llfs filesystem
|
||||
*/
|
||||
typedef struct llfs_file {
|
||||
const uint8_t* data; // Pointer to the file data (len bytes)
|
||||
const char* name; // Null-terminated string with the filename
|
||||
size_t len; // Length of the file data
|
||||
} llfs_file_t;
|
||||
|
||||
/**
|
||||
* @brief Internal representation of a file in the filesystem
|
||||
* @warning This struct should only be used in the llfs_data.c file.
|
||||
*/
|
||||
struct llfs_data_file {
|
||||
const uint8_t* data;
|
||||
const char* name;
|
||||
const size_t len;
|
||||
const struct llfs_data_file* next;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get a list of files in the filesystem
|
||||
* Get a list of all the files in the filesystem.
|
||||
*
|
||||
* Use the filter to filter out files with a filename that do not match the filter. (e.g. "*.txt" or "*.png|*.jpg") (not
|
||||
* implemented yet) Multiple filters can be used by separating them with a pipe (|).
|
||||
*
|
||||
* The following members of the llfs_file_t struct are set: name, len and data. @ref llfs_file_t
|
||||
*
|
||||
* @todo Implement file filter
|
||||
*
|
||||
* @param[out] file_list A pointer to an array of llfs_file_t to store the files in @ref llfs_file_t
|
||||
* @param[in] max_files The maximum number of files to return (size of file_list)
|
||||
* @param[in] filter A string with file extensions to filter out. (e.g. "*.txt" or "*.png|*.jpg")
|
||||
* @return The number of files returned
|
||||
*/
|
||||
size_t llfs_file_list(llfs_file_t* file_list, size_t max_files, char* filter);
|
||||
|
||||
/**
|
||||
* @brief Open a file
|
||||
* Get a file from the filesystem by name.
|
||||
*
|
||||
* @param[in] name The name of the file to open
|
||||
* @return A pointer to a llfs_file_t with the file data @ref llfs_file_t
|
||||
* NULL if the file does not exist
|
||||
*/
|
||||
llfs_file_t* llfs_file_open(const char* name);
|
||||
|
||||
#endif // LLFS_H
|
||||
@@ -88,17 +88,17 @@
|
||||
#endif
|
||||
|
||||
#if LOGGER_LEVEL <= 1
|
||||
#define LOG_DEBUG(tag, fmt, ...) printf(LOG_COLOR_D"[Debug] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#define LOG_DEBUG(tag, fmt, ...) printf(LOG_COLOR_D"[Debug] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_DEBUG(tag, fmt, ...)
|
||||
#endif
|
||||
#if LOGGER_LEVEL <= 2
|
||||
#define LOG_INFO(tag, fmt, ...) printf(LOG_COLOR_I"[Info] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#define LOG_INFO(tag, fmt, ...) printf(LOG_COLOR_I"[Info] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_INFO(tag, fmt, ...)
|
||||
#endif
|
||||
#if LOGGER_LEVEL <= 3
|
||||
#define LOG_WARN(tag, fmt, ...) printf(LOG_COLOR_W"[Warning] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#define LOG_WARN(tag, fmt, ...) printf(LOG_COLOR_W"[Warning] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_WARN(tag, fmt, ...)
|
||||
#endif
|
||||
@@ -108,7 +108,7 @@
|
||||
#define LOG_CRIT(tag, fmt, ...)
|
||||
#endif
|
||||
#if LOGGER_LEVEL <= 4
|
||||
#define LOG_FATAL(tag, fmt, ...) printf(LOG_COLOR_F"[Fatal] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#define LOG_FATAL(tag, fmt, ...) printf(LOG_COLOR_F"[Fatal] (%lu) [%s]: " fmt LOG_RESET_COLOR "\r\n", logger_get_timestamp(), tag, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_FATAL(tag, fmt, ...)
|
||||
#endif
|
||||
|
||||
50
project/Core/Src/llfs.c
Normal file
50
project/Core/Src/llfs.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @file llfs.c
|
||||
* @brief Linked List Filesystem implementation (llfs)
|
||||
* @author Lorenz C.
|
||||
* @todo Implement file extension filter
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#define LOGGER_LEVEL_WARN
|
||||
#include "llfs.h"
|
||||
#include "log.h"
|
||||
|
||||
extern struct llfs_data_file* llfs_root;
|
||||
const char* TAG = "llfs";
|
||||
|
||||
// TODO: Implement file extension filter
|
||||
size_t llfs_file_list(llfs_file_t* file_list, size_t max_files, char* filter) {
|
||||
size_t file_count = 0;
|
||||
const struct llfs_data_file* file = llfs_root;
|
||||
|
||||
LOG_DEBUG(TAG, "Getting file list with filter: %s", filter);
|
||||
|
||||
while (file != NULL && file_count < max_files) {
|
||||
file_list[file_count].data = file->data;
|
||||
file_list[file_count].name = file->name;
|
||||
file_list[file_count].len = file->len;
|
||||
file_count++;
|
||||
file = file->next;
|
||||
}
|
||||
|
||||
LOG_DEBUG(TAG, "Files found: %d", file_count);
|
||||
return file_count;
|
||||
}
|
||||
|
||||
llfs_file_t* llfs_file_open(const char* name) {
|
||||
const struct llfs_data_file* file = llfs_root;
|
||||
|
||||
LOG_DEBUG(TAG, "Opening file: %s", name);
|
||||
|
||||
while (file != NULL) {
|
||||
if (strcmp(file->name, name) == 0) {
|
||||
LOG_DEBUG(TAG, "File found: %s, size: %d", file->name, file->len);
|
||||
return (llfs_file_t*)file;
|
||||
}
|
||||
file = file->next;
|
||||
}
|
||||
|
||||
LOG_DEBUG(TAG, "File not found: %s", name);
|
||||
return NULL;
|
||||
}
|
||||
3152
project/Core/Src/llfs_data.c
Normal file
3152
project/Core/Src/llfs_data.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,7 @@
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#define LOGGER_LEVEL_ALL
|
||||
#include "log.h"
|
||||
|
||||
//#include "test_img.h"
|
||||
@@ -36,7 +37,7 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
static const char *TAG = "main";
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -125,6 +126,7 @@ int main(void)
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
MX_LWIP_Process();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user