From e0db8767c79e27e2ff49d48fa8f93b7fbabe454e Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 11 Feb 2024 00:58:43 +0100 Subject: [PATCH] Align code style (#40) - Mutex -> Mutex* - Cleanup enum names - Other small changes --- boards/lilygo_tdeck/sdcard.c | 2 +- boards/yellow_board/sdcard.c | 2 +- docs/ideas.md | 11 ++--- tactility-core/src/bundle.c | 34 +++++++------- tactility-core/src/kernel.c | 4 +- tactility-core/src/kernel.h | 4 +- tactility-core/src/log.c | 20 ++++----- tactility-core/src/log.h | 18 ++++---- tactility-core/src/mutex.c | 12 ++--- tactility-core/src/mutex.h | 12 ++--- tactility-core/src/pubsub.c | 2 +- .../apps/system/wifi_connect/wifi_connect.h | 2 +- .../src/apps/system/wifi_manage/wifi_manage.h | 2 +- tactility-esp/src/services/wifi/wifi.c | 2 +- .../src/services/wifi/wifi_credentials.c | 2 +- tactility/src/app.c | 2 +- tactility/src/app.h | 10 ++--- tactility/src/app_i.h | 2 +- tactility/src/app_manifest_registry.c | 2 +- tactility/src/apps/system/files/files_data.c | 2 +- tactility/src/sdcard.c | 15 +++---- tactility/src/sdcard.h | 10 ++--- tactility/src/service_i.h | 2 +- tactility/src/service_registry.c | 4 +- tactility/src/services/gui/gui_i.h | 2 +- tactility/src/services/loader/loader.c | 44 +++++++++---------- tactility/src/services/loader/loader_i.h | 2 +- tactility/src/services/sdcard/sdcard.c | 6 +-- tactility/src/ui/statusbar.c | 2 +- tests/tactility-core/mutex_test.cpp | 4 +- 30 files changed, 117 insertions(+), 121 deletions(-) diff --git a/boards/lilygo_tdeck/sdcard.c b/boards/lilygo_tdeck/sdcard.c index 93d896e4..b8fa7e03 100644 --- a/boards/lilygo_tdeck/sdcard.c +++ b/boards/lilygo_tdeck/sdcard.c @@ -133,5 +133,5 @@ const SdCard tdeck_sdcard = { .mount = &sdcard_init_and_mount, .unmount = &sdcard_unmount, .is_mounted = &sdcard_is_mounted, - .mount_behaviour = SDCARD_MOUNT_BEHAVIOUR_AT_BOOT + .mount_behaviour = SdcardMountBehaviourAtBoot }; diff --git a/boards/yellow_board/sdcard.c b/boards/yellow_board/sdcard.c index d9aaec08..ee3aecba 100644 --- a/boards/yellow_board/sdcard.c +++ b/boards/yellow_board/sdcard.c @@ -75,5 +75,5 @@ const SdCard twodotfour_sdcard = { .mount = &sdcard_mount, .unmount = &sdcard_unmount, .is_mounted = &sdcard_is_mounted, - .mount_behaviour = SDCARD_MOUNT_BEHAVIOUR_ANYTIME + .mount_behaviour = SdcardMountBehaviourAnytime }; diff --git a/docs/ideas.md b/docs/ideas.md index eedd8dd7..995055a9 100644 --- a/docs/ideas.md +++ b/docs/ideas.md @@ -6,11 +6,11 @@ - Show a warning screen when a user plugs in the SD card on a device that only supports mounting at boot. - Try out Waveshare S3 120MHz mode for PSRAM (see "enabling 120M PSRAM is necessary" in [docs](https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-4.3#Other_Notes)) - T-Deck has random sdcard SPI crashes due to sharing bus with screen SPI: make it use the LVGL lock for sdcard operations? +- Wi-Fi connect app should show info about connection result # Core Ideas - Make a HAL? It would mainly be there to support PC development. It's a lot of effort for supporting what's effectively a dev-only feature. - Support for displays with different DPI. Consider the layer-based system like on Android. -- Display orientation support for Display app - If present, use LED to show boot status - 2 wire speaker support - tt_app_start() and similar functions as proxies for Loader app start/stop/etc. @@ -22,10 +22,11 @@ - Light/dark mode selection in Display settings app. # App Ideas -- Chip 8 emulator -- Discord bot -- BadUSB -- IR transceiver app +- File viewer (images, text... binary?) - GPIO status viewer - BlueTooth keyboard app +- Chip 8 emulator +- BadUSB +- Discord bot +- IR transceiver app - Investigate CSI https://stevenmhernandez.github.io/ESP32-CSI-Tool/ \ No newline at end of file diff --git a/tactility-core/src/bundle.c b/tactility-core/src/bundle.c index 05e9ac81..8ebfc900 100644 --- a/tactility-core/src/bundle.c +++ b/tactility-core/src/bundle.c @@ -7,9 +7,9 @@ // region BundleEntry typedef enum { - BUNDLE_ENTRY_TYPE_BOOL, - BUNDLE_ENTRY_TYPE_INT32, - BUNDLE_ENTRY_TYPE_STRING, + BundleEntryTypeBool, + BundleEntryTypeInt32, + BundleEntryTypeString, } BundleEntryType; typedef struct { @@ -23,21 +23,21 @@ typedef struct { BundleEntry* bundle_entry_alloc_bool(bool value) { BundleEntry* entry = malloc(sizeof(BundleEntry)); - entry->type = BUNDLE_ENTRY_TYPE_BOOL; + entry->type = BundleEntryTypeBool; entry->bool_value = value; return entry; } BundleEntry* bundle_entry_alloc_int32(int32_t value) { BundleEntry* entry = malloc(sizeof(BundleEntry)); - entry->type = BUNDLE_ENTRY_TYPE_INT32; + entry->type = BundleEntryTypeInt32; entry->int32_value = value; return entry; } BundleEntry* bundle_entry_alloc_string(const char* text) { BundleEntry* entry = malloc(sizeof(BundleEntry)); - entry->type = BUNDLE_ENTRY_TYPE_STRING; + entry->type = BundleEntryTypeString; entry->string_ptr = malloc(strlen(text) + 1); strcpy(entry->string_ptr, text); return entry; @@ -46,7 +46,7 @@ BundleEntry* bundle_entry_alloc_string(const char* text) { BundleEntry* bundle_entry_alloc_copy(BundleEntry* source) { BundleEntry* entry = malloc(sizeof(BundleEntry)); entry->type = source->type; - if (source->type == BUNDLE_ENTRY_TYPE_STRING) { + if (source->type == BundleEntryTypeString) { entry->string_ptr = malloc(strlen(source->string_ptr) + 1); strcpy(entry->string_ptr, source->string_ptr); } else { @@ -56,7 +56,7 @@ BundleEntry* bundle_entry_alloc_copy(BundleEntry* source) { } void bundle_entry_free(BundleEntry* entry) { - if (entry->type == BUNDLE_ENTRY_TYPE_STRING) { + if (entry->type == BundleEntryTypeString) { free(entry->string_ptr); } free(entry); @@ -129,19 +129,19 @@ const char* tt_bundle_get_string(Bundle bundle, const char* key) { bool tt_bundle_has_bool(Bundle bundle, const char* key) { BundleData* data = (BundleData*)bundle; BundleEntry** entry = BundleDict_get(data->dict, key); - return (entry != NULL) && ((*entry)->type == BUNDLE_ENTRY_TYPE_BOOL); + return (entry != NULL) && ((*entry)->type == BundleEntryTypeBool); } bool tt_bundle_has_int32(Bundle bundle, const char* key) { BundleData* data = (BundleData*)bundle; BundleEntry** entry = BundleDict_get(data->dict, key); - return (entry != NULL) && ((*entry)->type == BUNDLE_ENTRY_TYPE_INT32); + return (entry != NULL) && ((*entry)->type == BundleEntryTypeInt32); } bool tt_bundle_has_string(Bundle bundle, const char* key) { BundleData* data = (BundleData*)bundle; BundleEntry** entry = BundleDict_get(data->dict, key); - return (entry != NULL) && ((*entry)->type == BUNDLE_ENTRY_TYPE_STRING); + return (entry != NULL) && ((*entry)->type == BundleEntryTypeString); } bool tt_bundle_opt_bool(Bundle bundle, const char* key, bool* out) { @@ -149,7 +149,7 @@ bool tt_bundle_opt_bool(Bundle bundle, const char* key, bool* out) { BundleEntry** entry_ptr = BundleDict_get(data->dict, key); if (entry_ptr != NULL) { BundleEntry* entry = *entry_ptr; - if (entry->type == BUNDLE_ENTRY_TYPE_BOOL) { + if (entry->type == BundleEntryTypeBool) { *out = entry->bool_value; return true; } else { @@ -165,7 +165,7 @@ bool tt_bundle_opt_int32(Bundle bundle, const char* key, int32_t* out) { BundleEntry** entry_ptr = BundleDict_get(data->dict, key); if (entry_ptr != NULL) { BundleEntry* entry = *entry_ptr; - if (entry->type == BUNDLE_ENTRY_TYPE_INT32) { + if (entry->type == BundleEntryTypeInt32) { *out = entry->int32_value; return true; } else { @@ -181,7 +181,7 @@ bool tt_bundle_opt_string(Bundle bundle, const char* key, char** out) { BundleEntry** entry_ptr = BundleDict_get(data->dict, key); if (entry_ptr != NULL) { BundleEntry* entry = *entry_ptr; - if (entry->type == BUNDLE_ENTRY_TYPE_STRING) { + if (entry->type == BundleEntryTypeString) { *out = entry->string_ptr; return true; } else { @@ -197,7 +197,7 @@ void tt_bundle_put_bool(Bundle bundle, const char* key, bool value) { BundleEntry** entry_handle = BundleDict_get(data->dict, key); if (entry_handle != NULL) { BundleEntry* entry = *entry_handle; - tt_assert(entry->type == BUNDLE_ENTRY_TYPE_BOOL); + tt_assert(entry->type == BundleEntryTypeBool); entry->bool_value = value; } else { BundleEntry* entry = bundle_entry_alloc_bool(value); @@ -210,7 +210,7 @@ void tt_bundle_put_int32(Bundle bundle, const char* key, int32_t value) { BundleEntry** entry_handle = BundleDict_get(data->dict, key); if (entry_handle != NULL) { BundleEntry* entry = *entry_handle; - tt_assert(entry->type == BUNDLE_ENTRY_TYPE_INT32); + tt_assert(entry->type == BundleEntryTypeInt32); entry->int32_value = value; } else { BundleEntry* entry = bundle_entry_alloc_int32(value); @@ -223,7 +223,7 @@ void tt_bundle_put_string(Bundle bundle, const char* key, const char* value) { BundleEntry** entry_handle = BundleDict_get(data->dict, key); if (entry_handle != NULL) { BundleEntry* entry = *entry_handle; - tt_assert(entry->type == BUNDLE_ENTRY_TYPE_STRING); + tt_assert(entry->type == BundleEntryTypeString); if (entry->string_ptr != NULL) { free(entry->string_ptr); } diff --git a/tactility-core/src/kernel.c b/tactility-core/src/kernel.c index a8f8fe5b..91f4c1b9 100644 --- a/tactility-core/src/kernel.c +++ b/tactility-core/src/kernel.c @@ -197,8 +197,8 @@ void tt_delay_us(uint32_t microseconds) { Platform tt_get_platform() { #ifdef ESP_PLATFORM - return PLATFORM_ESP; + return PlatformEsp; #else - return PLATFORM_PC; + return PlatformPc; #endif } diff --git a/tactility-core/src/kernel.h b/tactility-core/src/kernel.h index c0bec3e2..4fa9f9ad 100644 --- a/tactility-core/src/kernel.h +++ b/tactility-core/src/kernel.h @@ -7,8 +7,8 @@ extern "C" { #endif typedef enum { - PLATFORM_ESP, - PLATFORM_PC + PlatformEsp, + PlatformPc } Platform; /** Check if CPU is in IRQ or kernel running and IRQ is masked diff --git a/tactility-core/src/log.c b/tactility-core/src/log.c index 83dd7124..004937cb 100644 --- a/tactility-core/src/log.c +++ b/tactility-core/src/log.c @@ -13,15 +13,15 @@ static char tt_loglevel_to_prefix(LogLevel level) { switch (level) { - case LOG_LEVEL_ERROR: + case LogLevelError: return 'E'; - case LOG_LEVEL_WARNING: + case LogLevelWarning: return 'W'; - case LOG_LEVEL_INFO: + case LogLevelInfo: return 'I'; - case LOG_LEVEL_DEBUG: + case LogLevelDebug: return 'D'; - case LOG_LEVEL_TRACE: + case LogLevelTrace: return 'T'; default: return '?'; @@ -30,15 +30,15 @@ static char tt_loglevel_to_prefix(LogLevel level) { static const char* tt_loglevel_to_colour(LogLevel level) { switch (level) { - case LOG_LEVEL_ERROR: + case LogLevelError: return "\033[1;31m"; - case LOG_LEVEL_WARNING: + case LogLevelWarning: return "\033[33m"; - case LOG_LEVEL_INFO: + case LogLevelInfo: return "\033[32m"; - case LOG_LEVEL_DEBUG: + case LogLevelDebug: return "\033[1;37m"; - case LOG_LEVEL_TRACE: + case LogLevelTrace: return "\033[37m"; default: return ""; diff --git a/tactility-core/src/log.h b/tactility-core/src/log.h index abd864d3..0deaa107 100644 --- a/tactility-core/src/log.h +++ b/tactility-core/src/log.h @@ -27,23 +27,23 @@ extern "C" { #else typedef enum { - LOG_LEVEL_ERROR, - LOG_LEVEL_WARNING, - LOG_LEVEL_INFO, - LOG_LEVEL_DEBUG, - LOG_LEVEL_TRACE + LogLevelError, + LogLevelWarning, + LogLevelInfo, + LogLevelDebug, + LogLevelTrace } LogLevel; void tt_log(LogLevel level, const char* tag, const char* format, ...); #define TT_LOG_E(tag, format, ...) \ - tt_log(LOG_LEVEL_ERROR, tag, format, ##__VA_ARGS__) + tt_log(LogLevelError, tag, format, ##__VA_ARGS__) #define TT_LOG_W(tag, format, ...) \ - tt_log(LOG_LEVEL_WARNING, tag, format, ##__VA_ARGS__) + tt_log(LogLevelWarning, tag, format, ##__VA_ARGS__) #define TT_LOG_I(tag, format, ...) \ - tt_log(LOG_LEVEL_INFO, tag, format, ##__VA_ARGS__) + tt_log(LogLevelInfo, tag, format, ##__VA_ARGS__) #define TT_LOG_D(tag, format, ...) \ - tt_log(LOG_LEVEL_DEBUG, tag, format, ##__VA_ARGS__) + tt_log(LogLevelDebug, tag, format, ##__VA_ARGS__) #define TT_LOG_T(tag, format, ...) \ tt_log(LOG_LEVEL_TRACE, tag, format, ##__VA_ARGS__) diff --git a/tactility-core/src/mutex.c b/tactility-core/src/mutex.c index 02c3bc0a..d2307edd 100644 --- a/tactility-core/src/mutex.c +++ b/tactility-core/src/mutex.c @@ -33,7 +33,7 @@ void tt_mutex_info(Mutex mutex, const char* label) { #define tt_mutex_info(mutex, text) #endif -Mutex tt_mutex_alloc(MutexType type) { +Mutex* tt_mutex_alloc(MutexType type) { tt_assert(!TT_IS_IRQ_MODE()); MutexData* data = malloc(sizeof(MutexData)); @@ -52,10 +52,10 @@ Mutex tt_mutex_alloc(MutexType type) { tt_check(data->handle != NULL); tt_mutex_info(data, "alloc "); - return (Mutex)data; + return (Mutex*)data; } -void tt_mutex_free(Mutex mutex) { +void tt_mutex_free(Mutex* mutex) { tt_assert(!TT_IS_IRQ_MODE()); tt_assert(mutex); @@ -66,7 +66,7 @@ void tt_mutex_free(Mutex mutex) { free(data); } -TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout) { +TtStatus tt_mutex_acquire(Mutex* mutex, uint32_t timeout) { tt_assert(mutex); tt_assert(!TT_IS_IRQ_MODE()); MutexData* data = (MutexData*)mutex; @@ -101,7 +101,7 @@ TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout) { return status; } -TtStatus tt_mutex_release(Mutex mutex) { +TtStatus tt_mutex_release(Mutex* mutex) { tt_assert(mutex); assert(!TT_IS_IRQ_MODE()); MutexData* data = (MutexData*)mutex; @@ -129,7 +129,7 @@ TtStatus tt_mutex_release(Mutex mutex) { return status; } -ThreadId tt_mutex_get_owner(Mutex mutex) { +ThreadId tt_mutex_get_owner(Mutex* mutex) { tt_assert(mutex != NULL); tt_assert(!TT_IS_IRQ_MODE()); MutexData* data = (MutexData*)mutex; diff --git a/tactility-core/src/mutex.h b/tactility-core/src/mutex.h index f9e42a7a..a7059c62 100644 --- a/tactility-core/src/mutex.h +++ b/tactility-core/src/mutex.h @@ -16,7 +16,7 @@ typedef enum { MutexTypeRecursive, } MutexType; -typedef void* Mutex; +typedef void Mutex; /** Allocate Mutex * @@ -24,13 +24,13 @@ typedef void* Mutex; * * @return pointer to Mutex instance */ -Mutex tt_mutex_alloc(MutexType type); +Mutex* tt_mutex_alloc(MutexType type); /** Free Mutex * * @param mutex The Mutex instance */ -void tt_mutex_free(Mutex mutex); +void tt_mutex_free(Mutex* mutex); /** Acquire mutex * @@ -39,7 +39,7 @@ void tt_mutex_free(Mutex mutex); * * @return The status. */ -TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout); +TtStatus tt_mutex_acquire(Mutex* mutex, uint32_t timeout); /** Release mutex * @@ -47,7 +47,7 @@ TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout); * * @return The status. */ -TtStatus tt_mutex_release(Mutex mutex); +TtStatus tt_mutex_release(Mutex* mutex); /** Get mutex owner thread id * @@ -55,7 +55,7 @@ TtStatus tt_mutex_release(Mutex mutex); * * @return The thread identifier. */ -ThreadId tt_mutex_get_owner(Mutex mutex); +ThreadId tt_mutex_get_owner(Mutex* mutex); #ifdef __cplusplus } diff --git a/tactility-core/src/pubsub.c b/tactility-core/src/pubsub.c index 4fcfc227..7bb65f7f 100644 --- a/tactility-core/src/pubsub.c +++ b/tactility-core/src/pubsub.c @@ -13,7 +13,7 @@ LIST_DEF(PubSubSubscriptionList, PubSubSubscription, M_POD_OPLIST); struct PubSub { PubSubSubscriptionList_t items; - Mutex mutex; + Mutex* mutex; }; PubSub* tt_pubsub_alloc() { diff --git a/tactility-esp/src/apps/system/wifi_connect/wifi_connect.h b/tactility-esp/src/apps/system/wifi_connect/wifi_connect.h index bdd76f29..c7f4da9a 100644 --- a/tactility-esp/src/apps/system/wifi_connect/wifi_connect.h +++ b/tactility-esp/src/apps/system/wifi_connect/wifi_connect.h @@ -12,7 +12,7 @@ extern "C" { typedef struct { PubSubSubscription* wifi_subscription; - Mutex mutex; + Mutex* mutex; WifiConnectState state; WifiConnectView view; bool view_enabled; diff --git a/tactility-esp/src/apps/system/wifi_manage/wifi_manage.h b/tactility-esp/src/apps/system/wifi_manage/wifi_manage.h index 0701302e..bc7ab626 100644 --- a/tactility-esp/src/apps/system/wifi_manage/wifi_manage.h +++ b/tactility-esp/src/apps/system/wifi_manage/wifi_manage.h @@ -10,7 +10,7 @@ extern "C" { typedef struct { PubSubSubscription* wifi_subscription; - Mutex mutex; + Mutex* mutex; WifiManageState state; WifiManageView view; bool view_enabled; diff --git a/tactility-esp/src/services/wifi/wifi.c b/tactility-esp/src/services/wifi/wifi.c index 7984b5c9..9ae4fe1c 100644 --- a/tactility-esp/src/services/wifi/wifi.c +++ b/tactility-esp/src/services/wifi/wifi.c @@ -19,7 +19,7 @@ typedef struct { /** @brief Locking mechanism for modifying the Wifi instance */ - Mutex mutex; + Mutex* mutex; /** @brief The public event bus */ PubSub* pubsub; /** @brief The internal message queue */ diff --git a/tactility-esp/src/services/wifi/wifi_credentials.c b/tactility-esp/src/services/wifi/wifi_credentials.c index 69801558..07be2fbe 100644 --- a/tactility-esp/src/services/wifi/wifi_credentials.c +++ b/tactility-esp/src/services/wifi/wifi_credentials.c @@ -15,7 +15,7 @@ static void hash_reset_all(); // region Hash -static Mutex hash_mutex = NULL; +static Mutex* hash_mutex = NULL; static int8_t hash_index = -1; static uint32_t hashes[TT_WIFI_CREDENTIALS_LIMIT] = { 0 }; diff --git a/tactility/src/app.c b/tactility/src/app.c index b9370cbc..ea4f56d8 100644 --- a/tactility/src/app.c +++ b/tactility/src/app.c @@ -22,7 +22,7 @@ App tt_app_alloc(const AppManifest* manifest, Bundle* _Nullable parameters) { AppData* data = malloc(sizeof(AppData)); *data = (AppData) { .mutex = tt_mutex_alloc(MutexTypeNormal), - .state = APP_STATE_INITIAL, + .state = AppStateInitial, .flags = tt_app_get_flags_default(manifest->type), .manifest = manifest, .parameters = parameters, diff --git a/tactility/src/app.h b/tactility/src/app.h index c5e0ac66..30302ff1 100644 --- a/tactility/src/app.h +++ b/tactility/src/app.h @@ -8,11 +8,11 @@ extern "C" { #endif typedef enum { - APP_STATE_INITIAL, // App is being activated in loader - APP_STATE_STARTED, // App is in memory - APP_STATE_SHOWING, // App view is created - APP_STATE_HIDING, // App view is destroyed - APP_STATE_STOPPED // App is not in memory + AppStateInitial, // App is being activated in loader + AppStateStarted, // App is in memory + AppStateShowing, // App view is created + AppStateHiding, // App view is destroyed + AppStateStopped // App is not in memory } AppState; typedef union { diff --git a/tactility/src/app_i.h b/tactility/src/app_i.h index d64a9e98..8db5eba8 100644 --- a/tactility/src/app_i.h +++ b/tactility/src/app_i.h @@ -11,7 +11,7 @@ extern "C" { #endif typedef struct { - Mutex mutex; + Mutex* mutex; const AppManifest* manifest; AppState state; /** @brief Memory marker at start of app, to detect memory leaks */ diff --git a/tactility/src/app_manifest_registry.c b/tactility/src/app_manifest_registry.c index 4af0d852..d8c02990 100644 --- a/tactility/src/app_manifest_registry.c +++ b/tactility/src/app_manifest_registry.c @@ -21,7 +21,7 @@ DICT_DEF2(AppManifestDict, const char*, M_CSTR_DUP_OPLIST, const AppManifest*, M } AppManifestDict_t app_manifest_dict; -Mutex hash_mutex = NULL; +Mutex* hash_mutex = NULL; void tt_app_manifest_registry_init() { tt_assert(hash_mutex == NULL); diff --git a/tactility/src/apps/system/files/files_data.c b/tactility/src/apps/system/files/files_data.c index b905b943..368f4da0 100644 --- a/tactility/src/apps/system/files/files_data.c +++ b/tactility/src/apps/system/files/files_data.c @@ -66,7 +66,7 @@ bool files_data_set_entries_for_path(FilesData* data, const char* path) { * ESP32 does not have a root directory, so we have to create it manually. * We'll add the NVS Flash partitions and the binding for the sdcard. */ - if (tt_get_platform() == PLATFORM_ESP && strcmp(path, "/") == 0) { + if (tt_get_platform() == PlatformEsp && strcmp(path, "/") == 0) { int dir_entries_count = 3; struct dirent** dir_entries = malloc(sizeof(struct dirent*) * 3); diff --git a/tactility/src/sdcard.c b/tactility/src/sdcard.c index b04a86e3..d2b6a867 100644 --- a/tactility/src/sdcard.c +++ b/tactility/src/sdcard.c @@ -5,7 +5,7 @@ #define TAG "sdcard" -static Mutex mutex = NULL; +static Mutex* mutex = NULL; typedef struct { const SdCard* sdcard; @@ -59,16 +59,11 @@ bool tt_sdcard_mount(const SdCard* sdcard) { SdcardState tt_sdcard_get_state() { if (data.context == NULL) { - return SDCARD_STATE_UNMOUNTED; + return SdcardStateUnmounted; + } else if (data.sdcard->is_mounted(data.context)) { + return SdcardStateMounted; } else { - // TODO: Side-effects are not great - consider refactoring this, so: - // Consider making tt_sdcard_get_status() that can return an error state - // The sdcard service can then auto-dismount - if (data.sdcard->is_mounted(data.context)) { - return SDCARD_STATE_MOUNTED; - } else { - return SDCARD_STATE_ERROR; - } + return SdcardStateError; } } diff --git a/tactility/src/sdcard.h b/tactility/src/sdcard.h index afd1a1bd..3966e088 100644 --- a/tactility/src/sdcard.h +++ b/tactility/src/sdcard.h @@ -13,14 +13,14 @@ typedef void (*SdcardUnmount)(void* context); typedef bool (*SdcardIsMounted)(void* context); typedef enum { - SDCARD_STATE_MOUNTED, - SDCARD_STATE_UNMOUNTED, - SDCARD_STATE_ERROR, + SdcardStateMounted, + SdcardStateUnmounted, + SdcardStateError, } SdcardState; typedef enum { - SDCARD_MOUNT_BEHAVIOUR_AT_BOOT, /** Only mount at boot */ - SDCARD_MOUNT_BEHAVIOUR_ANYTIME /** Mount/dismount any time */ + SdcardMountBehaviourAtBoot, /** Only mount at boot */ + SdcardMountBehaviourAnytime /** Mount/dismount any time */ } SdcardMountBehaviour; typedef struct { diff --git a/tactility/src/service_i.h b/tactility/src/service_i.h index 5c9119f6..02fea3ca 100644 --- a/tactility/src/service_i.h +++ b/tactility/src/service_i.h @@ -6,7 +6,7 @@ #include "service_manifest.h" typedef struct { - Mutex mutex; + Mutex* mutex; const ServiceManifest* manifest; void* data; } ServiceData; diff --git a/tactility/src/service_registry.c b/tactility/src/service_registry.c index 073af6b6..2f48890a 100644 --- a/tactility/src/service_registry.c +++ b/tactility/src/service_registry.c @@ -25,8 +25,8 @@ DICT_DEF2(ServiceInstanceDict, const char*, M_CSTR_DUP_OPLIST, const ServiceData static ServiceManifestDict_t service_manifest_dict; static ServiceInstanceDict_t service_instance_dict; -static Mutex manifest_mutex = NULL; -static Mutex instance_mutex = NULL; +static Mutex* manifest_mutex = NULL; +static Mutex* instance_mutex = NULL; void tt_service_registry_init() { tt_assert(manifest_mutex == NULL); diff --git a/tactility/src/services/gui/gui_i.h b/tactility/src/services/gui/gui_i.h index 84f78b49..da9022ae 100644 --- a/tactility/src/services/gui/gui_i.h +++ b/tactility/src/services/gui/gui_i.h @@ -17,7 +17,7 @@ struct Gui { // Thread and lock Thread* thread; - Mutex mutex; + Mutex* mutex; // Layers and Canvas lv_obj_t* lvgl_parent; diff --git a/tactility/src/services/loader/loader.c b/tactility/src/services/loader/loader.c index ccd45dd0..6d3e4c24 100644 --- a/tactility/src/services/loader/loader.c +++ b/tactility/src/services/loader/loader.c @@ -109,15 +109,15 @@ PubSub* loader_get_pubsub() { static const char* app_state_to_string(AppState state) { switch (state) { - case APP_STATE_INITIAL: + case AppStateInitial: return "initial"; - case APP_STATE_STARTED: + case AppStateStarted: return "started"; - case APP_STATE_SHOWING: + case AppStateShowing: return "showing"; - case APP_STATE_HIDING: + case AppStateHiding: return "hiding"; - case APP_STATE_STOPPED: + case AppStateStopped: return "stopped"; default: return "?"; @@ -137,33 +137,33 @@ static void app_transition_to_state(App app, AppState state) { ); switch (state) { - case APP_STATE_INITIAL: - tt_app_set_state(app, APP_STATE_INITIAL); + case AppStateInitial: + tt_app_set_state(app, AppStateInitial); break; - case APP_STATE_STARTED: + case AppStateStarted: if (manifest->on_start != NULL) { manifest->on_start(app); } - tt_app_set_state(app, APP_STATE_STARTED); + tt_app_set_state(app, AppStateStarted); break; - case APP_STATE_SHOWING: + case AppStateShowing: gui_show_app( app, manifest->on_show, manifest->on_hide ); - tt_app_set_state(app, APP_STATE_SHOWING); + tt_app_set_state(app, AppStateShowing); break; - case APP_STATE_HIDING: + case AppStateHiding: gui_hide_app(); - tt_app_set_state(app, APP_STATE_HIDING); + tt_app_set_state(app, AppStateHiding); break; - case APP_STATE_STOPPED: + case AppStateStopped: if (manifest->on_stop) { manifest->on_stop(app); } tt_app_set_data(app, NULL); - tt_app_set_state(app, APP_STATE_STOPPED); + tt_app_set_state(app, AppStateStopped); break; } } @@ -187,16 +187,16 @@ LoaderStatus loader_do_start_app_with_manifest( App app = tt_app_alloc(manifest, bundle); tt_assert(loader_singleton->app_stack[loader_singleton->app_stack_index] == NULL); loader_singleton->app_stack[loader_singleton->app_stack_index] = app; - app_transition_to_state(app, APP_STATE_INITIAL); - app_transition_to_state(app, APP_STATE_STARTED); + app_transition_to_state(app, AppStateInitial); + app_transition_to_state(app, AppStateStarted); // We might have to hide the previous app first if (previous_index != -1) { App previous_app = loader_singleton->app_stack[previous_index]; - app_transition_to_state(previous_app, APP_STATE_HIDING); + app_transition_to_state(previous_app, AppStateHiding); } - app_transition_to_state(app, APP_STATE_SHOWING); + app_transition_to_state(app, AppStateShowing); loader_unlock(); @@ -240,8 +240,8 @@ static void loader_do_stop_app() { // Stop current app App app_to_stop = loader_singleton->app_stack[current_app_index]; - app_transition_to_state(app_to_stop, APP_STATE_HIDING); - app_transition_to_state(app_to_stop, APP_STATE_STOPPED); + app_transition_to_state(app_to_stop, AppStateHiding); + app_transition_to_state(app_to_stop, AppStateStopped); tt_app_free(app_to_stop); loader_singleton->app_stack[current_app_index] = NULL; @@ -254,7 +254,7 @@ static void loader_do_stop_app() { // Resume previous app tt_assert(loader_singleton->app_stack[loader_singleton->app_stack_index] != NULL); App app_to_resume = loader_singleton->app_stack[loader_singleton->app_stack_index]; - app_transition_to_state(app_to_resume, APP_STATE_SHOWING); + app_transition_to_state(app_to_resume, AppStateShowing); loader_unlock(); diff --git a/tactility/src/services/loader/loader_i.h b/tactility/src/services/loader/loader_i.h index 605dc949..785475c9 100644 --- a/tactility/src/services/loader/loader_i.h +++ b/tactility/src/services/loader/loader_i.h @@ -22,7 +22,7 @@ struct Loader { Thread* thread; PubSub* pubsub; MessageQueue* queue; - Mutex mutex; + Mutex* mutex; int8_t app_stack_index; App app_stack[APP_STACK_SIZE]; }; diff --git a/tactility/src/services/sdcard/sdcard.c b/tactility/src/services/sdcard/sdcard.c index 9aadf0dd..b1582ace 100644 --- a/tactility/src/services/sdcard/sdcard.c +++ b/tactility/src/services/sdcard/sdcard.c @@ -12,7 +12,7 @@ static int32_t sdcard_task(TT_UNUSED void* context); typedef struct { - Mutex mutex; + Mutex* mutex; Thread* thread; SdcardState last_state; int8_t statusbar_icon_id; @@ -65,14 +65,14 @@ static int32_t sdcard_task(void* context) { SdcardState new_state = tt_sdcard_get_state(); - if (new_state == SDCARD_STATE_ERROR) { + if (new_state == SdcardStateError) { TT_LOG_W(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?"); tt_sdcard_unmount(); } if (new_state != data->last_state) { TT_LOG_I(TAG, "State change %d -> %d", data->last_state, new_state); - if (new_state == SDCARD_STATE_MOUNTED) { + if (new_state == SdcardStateMounted) { tt_statusbar_icon_set_image(data->statusbar_icon_id, TT_ASSETS_ICON_SDCARD); } else { tt_statusbar_icon_set_image(data->statusbar_icon_id, TT_ASSETS_ICON_SDCARD_ALERT); diff --git a/tactility/src/ui/statusbar.c b/tactility/src/ui/statusbar.c index d7fcfcc9..72f67f72 100644 --- a/tactility/src/ui/statusbar.c +++ b/tactility/src/ui/statusbar.c @@ -18,7 +18,7 @@ typedef struct { } StatusbarIcon; typedef struct { - Mutex mutex; + Mutex* mutex; PubSub* pubsub; StatusbarIcon icons[STATUSBAR_ICON_LIMIT]; } StatusbarData; diff --git a/tests/tactility-core/mutex_test.cpp b/tests/tactility-core/mutex_test.cpp index a0ea7b70..829f1039 100644 --- a/tests/tactility-core/mutex_test.cpp +++ b/tests/tactility-core/mutex_test.cpp @@ -3,13 +3,13 @@ #include "mutex.h" static int thread_with_mutex_parameter(void* parameter) { - Mutex mutex = (Mutex)parameter; + Mutex* mutex = (Mutex*)parameter; tt_mutex_acquire(mutex, TtWaitForever); return 0; } TEST_CASE("a mutex can block a thread") { - Mutex mutex = tt_mutex_alloc(MutexTypeNormal); + Mutex* mutex = tt_mutex_alloc(MutexTypeNormal); tt_mutex_acquire(mutex, TtWaitForever); Thread* thread = tt_thread_alloc_ex(