Merge develop into main branch (#137)
* SdCard HAL refactored (#135) - Refactor SdCard HAL - introduce Lockable * Screenshot and FatFS improvements (#136) - Fix screenshots on ESP32 - Improve Screenshot service - Convert Screenshot app to class-based instead of structs - Screenshot app now automatically updates when task is finished - Enable FatFS long filename support * Re-use common log messages (#138) For consistency and binary size reduction * Toolbar spinner should get margin to the right * More TactilityC features (#139) * Rewrote Loader - Simplified Loader by removing custom threa - Created DispatcherThread - Move auto-starting apps to Boot app - Fixed Dispatcher bug where it could get stuck not processing new messages * Hide AP settings if the AP is not saved * Missing from previous commit * Replace LV_EVENT_CLICKED with LV_EVENT_SHORT_CLICKED * Refactored files app and created InputDialog (#140) - Changed Files app so that it has a View and State - Files app now allows for long-pressing on files to perform actions - Files app now has rename and delete actions - Created InputDialog app - Improved AlertDialog app layout
This commit is contained in:
committed by
GitHub
parent
9033daa6dd
commit
50bd6e8bf6
@@ -1,85 +0,0 @@
|
||||
#include "Sdcard.h"
|
||||
|
||||
#include "Mutex.h"
|
||||
#include "TactilityCore.h"
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
#define TAG "sdcard"
|
||||
|
||||
static Mutex mutex(Mutex::TypeRecursive);
|
||||
|
||||
typedef struct {
|
||||
const SdCard* sdcard;
|
||||
void* context;
|
||||
} MountData;
|
||||
|
||||
static MountData data = {
|
||||
.sdcard = nullptr,
|
||||
.context = nullptr
|
||||
};
|
||||
|
||||
static bool lock(uint32_t timeout_ticks) {
|
||||
return mutex.acquire(timeout_ticks) == TtStatusOk;
|
||||
}
|
||||
|
||||
static void unlock() {
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
bool mount(const SdCard* sdcard) {
|
||||
TT_LOG_I(TAG, "Mounting");
|
||||
|
||||
if (data.sdcard != nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to mount: already mounted");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lock(100)) {
|
||||
void* context = sdcard->mount(TT_SDCARD_MOUNT_POINT);
|
||||
data = (MountData) {
|
||||
.sdcard = sdcard,
|
||||
.context = context
|
||||
};
|
||||
unlock();
|
||||
return (data.context != nullptr);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to lock");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
State getState() {
|
||||
if (data.context == nullptr) {
|
||||
return StateUnmounted;
|
||||
} else if (data.sdcard->is_mounted(data.context)) {
|
||||
return StateMounted;
|
||||
} else {
|
||||
return StateError;
|
||||
}
|
||||
}
|
||||
|
||||
bool unmount(uint32_t timeout_ticks) {
|
||||
TT_LOG_I(TAG, "Unmounting");
|
||||
bool result = false;
|
||||
|
||||
if (lock(timeout_ticks)) {
|
||||
if (data.sdcard != nullptr) {
|
||||
data.sdcard->unmount(data.context);
|
||||
data = (MountData) {
|
||||
.sdcard = nullptr,
|
||||
.context = nullptr
|
||||
};
|
||||
result = true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Can't unmount: nothing mounted");
|
||||
}
|
||||
unlock();
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to lock in %lu ticks", timeout_ticks);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "TactilityCore.h"
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
#define TT_SDCARD_MOUNT_POINT "/sdcard"
|
||||
|
||||
typedef void* (*Mount)(const char* mount_path);
|
||||
typedef void (*Unmount)(void* context);
|
||||
typedef bool (*IsMounted)(void* context);
|
||||
|
||||
typedef enum {
|
||||
StateMounted,
|
||||
StateUnmounted,
|
||||
StateError,
|
||||
} State;
|
||||
|
||||
typedef enum {
|
||||
MountBehaviourAtBoot, /** Only mount at boot */
|
||||
MountBehaviourAnytime /** Mount/dismount any time */
|
||||
} MountBehaviour;
|
||||
|
||||
typedef struct {
|
||||
Mount mount;
|
||||
Unmount unmount;
|
||||
IsMounted is_mounted;
|
||||
MountBehaviour mount_behaviour;
|
||||
} SdCard;
|
||||
|
||||
bool mount(const SdCard* sdcard);
|
||||
State getState();
|
||||
bool unmount(uint32_t timeout_ticks);
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user