mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 09:48:35 -07:00
Merge branch 'dev' of https://github.com/DarkFlippers/unleashed-firmware into xfw-dev --nobuild
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#define ICON_SD_MOUNTED &I_SDcardMounted_11x8
|
||||
#define ICON_SD_ERROR &I_SDcardFail_11x8
|
||||
|
||||
#define TAG RECORD_STORAGE
|
||||
#define TAG "Storage"
|
||||
|
||||
static void storage_app_sd_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(canvas);
|
||||
|
||||
@@ -351,12 +351,20 @@ const char* storage_file_get_error_desc(File* file);
|
||||
*/
|
||||
FS_Error storage_sd_format(Storage* api);
|
||||
|
||||
/** Will unmount the SD card
|
||||
/** Will unmount the SD card.
|
||||
* Will return FSE_NOT_READY if the SD card is not mounted.
|
||||
* Will return FSE_DENIED if there are open files on the SD card.
|
||||
* @param api pointer to the api
|
||||
* @return FS_Error operation result
|
||||
*/
|
||||
FS_Error storage_sd_unmount(Storage* api);
|
||||
|
||||
/** Will mount the SD card
|
||||
* @param api pointer to the api
|
||||
* @return FS_Error operation result
|
||||
*/
|
||||
FS_Error storage_sd_mount(Storage* api);
|
||||
|
||||
/** Retrieves SD card information
|
||||
* @param api pointer to the api
|
||||
* @param info pointer to the info
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#define MAX_NAME_LENGTH 254
|
||||
#define FILE_BUFFER_SIZE 512
|
||||
|
||||
#define TAG "StorageAPI"
|
||||
#define TAG "StorageApi"
|
||||
|
||||
#define S_API_PROLOGUE FuriApiLock lock = api_lock_alloc_locked();
|
||||
|
||||
@@ -863,6 +863,14 @@ FS_Error storage_sd_unmount(Storage* storage) {
|
||||
return S_RETURN_ERROR;
|
||||
}
|
||||
|
||||
FS_Error storage_sd_mount(Storage* storage) {
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {};
|
||||
S_API_MESSAGE(StorageCommandSDMount);
|
||||
S_API_EPILOGUE;
|
||||
return S_RETURN_ERROR;
|
||||
}
|
||||
|
||||
FS_Error storage_sd_info(Storage* storage, SDInfo* info) {
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "storage_glue.h"
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define TAG "StorageGlue"
|
||||
|
||||
/****************** storage file ******************/
|
||||
|
||||
void storage_file_init(StorageFile* obj) {
|
||||
@@ -149,3 +151,8 @@ bool storage_pop_storage_file(File* file, StorageData* storage) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t storage_open_files_count(StorageData* storage) {
|
||||
size_t count = StorageFileList_size(storage->files);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ void* storage_get_storage_file_data(const File* file, StorageData* storage);
|
||||
void storage_push_storage_file(File* file, FuriString* path, StorageData* storage);
|
||||
bool storage_pop_storage_file(File* file, StorageData* storage);
|
||||
|
||||
size_t storage_open_files_count(StorageData* storage);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -154,6 +154,7 @@ typedef enum {
|
||||
StorageCommandSDInfo,
|
||||
StorageCommandSDStatus,
|
||||
StorageCommandCommonResolvePath,
|
||||
StorageCommandSDMount,
|
||||
|
||||
StorageCommandFileExpand,
|
||||
StorageCommandCommonRename,
|
||||
|
||||
@@ -449,12 +449,38 @@ static FS_Error storage_process_sd_format(Storage* app) {
|
||||
static FS_Error storage_process_sd_unmount(Storage* app) {
|
||||
FS_Error ret = FSE_OK;
|
||||
|
||||
if(storage_data_status(&app->storage[ST_EXT]) == StorageStatusNotReady) {
|
||||
ret = FSE_NOT_READY;
|
||||
} else {
|
||||
sd_unmount_card(&app->storage[ST_EXT]);
|
||||
storage_data_timestamp(&app->storage[ST_EXT]);
|
||||
}
|
||||
do {
|
||||
StorageData* storage = &app->storage[ST_EXT];
|
||||
if(storage_data_status(storage) == StorageStatusNotReady) {
|
||||
ret = FSE_NOT_READY;
|
||||
break;
|
||||
}
|
||||
|
||||
if(storage_open_files_count(storage)) {
|
||||
ret = FSE_DENIED;
|
||||
break;
|
||||
}
|
||||
|
||||
sd_unmount_card(storage);
|
||||
storage_data_timestamp(storage);
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FS_Error storage_process_sd_mount(Storage* app) {
|
||||
FS_Error ret = FSE_OK;
|
||||
|
||||
do {
|
||||
StorageData* storage = &app->storage[ST_EXT];
|
||||
if(storage_data_status(storage) != StorageStatusNotReady) {
|
||||
ret = FSE_NOT_READY;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = sd_mount_card(storage, true);
|
||||
storage_data_timestamp(storage);
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -688,6 +714,9 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
||||
case StorageCommandSDUnmount:
|
||||
message->return_data->error_value = storage_process_sd_unmount(app);
|
||||
break;
|
||||
case StorageCommandSDMount:
|
||||
message->return_data->error_value = storage_process_sd_mount(app);
|
||||
break;
|
||||
case StorageCommandSDInfo:
|
||||
message->return_data->error_value =
|
||||
storage_process_sd_info(app, message->data->sdinfo.info);
|
||||
|
||||
@@ -24,7 +24,7 @@ static FS_Error storage_ext_parse_error(SDError error);
|
||||
|
||||
/******************* Core Functions *******************/
|
||||
|
||||
static bool sd_mount_card(StorageData* storage, bool notify) {
|
||||
static bool sd_mount_card_internal(StorageData* storage, bool notify) {
|
||||
bool result = false;
|
||||
uint8_t counter = sd_max_mount_retry_count();
|
||||
uint8_t bsp_result;
|
||||
@@ -106,6 +106,32 @@ FS_Error sd_unmount_card(StorageData* storage) {
|
||||
return storage_ext_parse_error(error);
|
||||
}
|
||||
|
||||
FS_Error sd_mount_card(StorageData* storage, bool notify) {
|
||||
sd_mount_card_internal(storage, notify);
|
||||
FS_Error error;
|
||||
|
||||
if(storage->status != StorageStatusOK) {
|
||||
FURI_LOG_E(TAG, "sd init error: %s", storage_data_status_text(storage));
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_error(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
error = FSE_INTERNAL;
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "card mounted");
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_success(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
|
||||
error = FSE_OK;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
FS_Error sd_format_card(StorageData* storage) {
|
||||
#ifdef FURI_RAM_EXEC
|
||||
UNUSED(storage);
|
||||
@@ -222,25 +248,8 @@ static void storage_ext_tick_internal(StorageData* storage, bool notify) {
|
||||
if(sd_data->sd_was_present) {
|
||||
if(hal_sd_detect()) {
|
||||
FURI_LOG_I(TAG, "card detected");
|
||||
sd_mount_card(storage, notify);
|
||||
|
||||
if(storage->status != StorageStatusOK) {
|
||||
FURI_LOG_E(TAG, "sd init error: %s", storage_data_status_text(storage));
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_error(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "card mounted");
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_success(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
}
|
||||
|
||||
sd_data->sd_was_present = false;
|
||||
sd_mount_card(storage, notify);
|
||||
|
||||
if(!hal_sd_detect()) {
|
||||
FURI_LOG_I(TAG, "card removed while mounting");
|
||||
|
||||
@@ -8,6 +8,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void storage_ext_init(StorageData* storage);
|
||||
FS_Error sd_mount_card(StorageData* storage, bool notify);
|
||||
FS_Error sd_unmount_card(StorageData* storage);
|
||||
FS_Error sd_format_card(StorageData* storage);
|
||||
FS_Error sd_card_info(StorageData* storage, SDInfo* sd_info);
|
||||
|
||||
Reference in New Issue
Block a user