Furi: core refactoring and CMSIS removal part 2 (#1410)
* Furi: rename and move core * Furi: drop CMSIS_OS header and unused api, partially refactor and cleanup the rest * Furi: CMSIS_OS drop and refactoring. * Furi: refactoring, remove cmsis legacy * Furi: fix incorrect assert on queue deallocation, cleanup timer * Furi: improve delay api, get rid of floats * hal: dropped furi_hal_crc * Furi: move DWT based delay to cortex HAL * Furi: update core documentation Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
@@ -28,7 +28,7 @@ void gui_input_events_callback(const void* value, void* ctx) {
|
||||
|
||||
Gui* gui = ctx;
|
||||
|
||||
osMessageQueuePut(gui->input_queue, value, 0, osWaitForever);
|
||||
furi_message_queue_put(gui->input_queue, value, FuriWaitForever);
|
||||
furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_INPUT);
|
||||
}
|
||||
|
||||
@@ -308,12 +308,12 @@ void gui_input(Gui* gui, InputEvent* input_event) {
|
||||
|
||||
void gui_lock(Gui* gui) {
|
||||
furi_assert(gui);
|
||||
furi_check(osMutexAcquire(gui->mutex, osWaitForever) == osOK);
|
||||
furi_check(furi_mutex_acquire(gui->mutex, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void gui_unlock(Gui* gui) {
|
||||
furi_assert(gui);
|
||||
furi_check(osMutexRelease(gui->mutex) == osOK);
|
||||
furi_check(furi_mutex_release(gui->mutex) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer) {
|
||||
@@ -473,7 +473,7 @@ Gui* gui_alloc() {
|
||||
// Thread ID
|
||||
gui->thread_id = furi_thread_get_current_id();
|
||||
// Allocate mutex
|
||||
gui->mutex = osMutexNew(NULL);
|
||||
gui->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
furi_check(gui->mutex);
|
||||
// Layers
|
||||
for(size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
@@ -484,7 +484,7 @@ Gui* gui_alloc() {
|
||||
CanvasCallbackPairArray_init(gui->canvas_callback_pair);
|
||||
|
||||
// Input
|
||||
gui->input_queue = osMessageQueueNew(8, sizeof(InputEvent), NULL);
|
||||
gui->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
||||
gui->input_events = furi_record_open("input_events");
|
||||
|
||||
furi_check(gui->input_events);
|
||||
@@ -501,12 +501,12 @@ int32_t gui_srv(void* p) {
|
||||
|
||||
while(1) {
|
||||
uint32_t flags =
|
||||
furi_thread_flags_wait(GUI_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever);
|
||||
furi_thread_flags_wait(GUI_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
||||
// Process and dispatch input
|
||||
if(flags & GUI_THREAD_FLAG_INPUT) {
|
||||
// Process till queue become empty
|
||||
InputEvent input_event;
|
||||
while(osMessageQueueGet(gui->input_queue, &input_event, NULL, 0) == osOK) {
|
||||
while(furi_message_queue_get(gui->input_queue, &input_event, 0) == FuriStatusOk) {
|
||||
gui_input(gui, &input_event);
|
||||
}
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ ALGO_DEF(CanvasCallbackPairArray, CanvasCallbackPairArray_t);
|
||||
struct Gui {
|
||||
// Thread and lock
|
||||
FuriThreadId thread_id;
|
||||
osMutexId_t mutex;
|
||||
FuriMutex* mutex;
|
||||
|
||||
// Layers and Canvas
|
||||
bool lockdown;
|
||||
@@ -67,7 +67,7 @@ struct Gui {
|
||||
CanvasCallbackPairArray_t canvas_callback_pair;
|
||||
|
||||
// Input
|
||||
osMessageQueueId_t input_queue;
|
||||
FuriMessageQueue* input_queue;
|
||||
FuriPubSub* input_events;
|
||||
uint8_t ongoing_input;
|
||||
ViewPort* ongoing_input_view_port;
|
||||
|
@@ -7,15 +7,16 @@ IconAnimation* icon_animation_alloc(const Icon* icon) {
|
||||
furi_assert(icon);
|
||||
IconAnimation* instance = malloc(sizeof(IconAnimation));
|
||||
instance->icon = icon;
|
||||
instance->timer = osTimerNew(icon_animation_timer_callback, osTimerPeriodic, instance, NULL);
|
||||
instance->timer =
|
||||
furi_timer_alloc(icon_animation_timer_callback, FuriTimerTypePeriodic, instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void icon_animation_free(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
icon_animation_stop(instance);
|
||||
while(xTimerIsTimerActive(instance->timer) == pdTRUE) osDelay(1);
|
||||
furi_check(osTimerDelete(instance->timer) == osOK);
|
||||
while(xTimerIsTimerActive(instance->timer) == pdTRUE) furi_delay_tick(1);
|
||||
furi_timer_free(instance->timer);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ void icon_animation_start(IconAnimation* instance) {
|
||||
furi_check(
|
||||
xTimerChangePeriod(
|
||||
instance->timer,
|
||||
(osKernelGetTickFreq() / instance->icon->frame_rate),
|
||||
(furi_kernel_get_tick_frequency() / instance->icon->frame_rate),
|
||||
portMAX_DELAY) == pdPASS);
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ struct IconAnimation {
|
||||
const Icon* icon;
|
||||
uint8_t frame;
|
||||
bool animating;
|
||||
osTimerId_t timer;
|
||||
FuriTimer* timer;
|
||||
IconAnimationCallback callback;
|
||||
void* callback_context;
|
||||
};
|
||||
|
@@ -1,10 +1,9 @@
|
||||
#include "file_browser.h"
|
||||
#include "assets_icons.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "file_browser_worker.h"
|
||||
#include "furi/check.h"
|
||||
#include "furi/common_defines.h"
|
||||
#include "furi/log.h"
|
||||
#include <core/check.h>
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include "furi_hal_resources.h"
|
||||
#include "m-string.h"
|
||||
#include <m-array.h>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "file_browser_worker.h"
|
||||
#include "furi/check.h"
|
||||
#include "furi/common_defines.h"
|
||||
#include <core/check.h>
|
||||
#include <core/common_defines.h>
|
||||
#include "m-string.h"
|
||||
#include "storage/filesystem_api_defines.h"
|
||||
#include <m-array.h>
|
||||
@@ -262,8 +262,9 @@ static int32_t browser_worker(void* context) {
|
||||
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
|
||||
|
||||
while(1) {
|
||||
uint32_t flags = furi_thread_flags_wait(WORKER_FLAGS_ALL, osFlagsWaitAny, osWaitForever);
|
||||
furi_assert((flags & osFlagsError) == 0);
|
||||
uint32_t flags =
|
||||
furi_thread_flags_wait(WORKER_FLAGS_ALL, FuriFlagWaitAny, FuriWaitForever);
|
||||
furi_assert((flags & FuriFlagError) == 0);
|
||||
|
||||
if(flags & WorkerEvtConfigChange) {
|
||||
// If start path is a path to the file - try finding index of this file in a folder
|
||||
|
@@ -7,7 +7,7 @@ struct Popup {
|
||||
void* context;
|
||||
PopupCallback callback;
|
||||
|
||||
osTimerId_t timer;
|
||||
FuriTimer* timer;
|
||||
uint32_t timer_period_in_ms;
|
||||
bool timer_enabled;
|
||||
};
|
||||
@@ -93,10 +93,11 @@ static bool popup_view_input_callback(InputEvent* event, void* context) {
|
||||
void popup_start_timer(void* context) {
|
||||
Popup* popup = context;
|
||||
if(popup->timer_enabled) {
|
||||
uint32_t timer_period = popup->timer_period_in_ms / (1000.0f / osKernelGetTickFreq());
|
||||
uint32_t timer_period =
|
||||
popup->timer_period_in_ms / (1000.0f / furi_kernel_get_tick_frequency());
|
||||
if(timer_period == 0) timer_period = 1;
|
||||
|
||||
if(osTimerStart(popup->timer, timer_period) != osOK) {
|
||||
if(furi_timer_start(popup->timer, timer_period) != FuriStatusOk) {
|
||||
furi_assert(0);
|
||||
};
|
||||
}
|
||||
@@ -104,13 +105,13 @@ void popup_start_timer(void* context) {
|
||||
|
||||
void popup_stop_timer(void* context) {
|
||||
Popup* popup = context;
|
||||
osTimerStop(popup->timer);
|
||||
furi_timer_stop(popup->timer);
|
||||
}
|
||||
|
||||
Popup* popup_alloc() {
|
||||
Popup* popup = malloc(sizeof(Popup));
|
||||
popup->view = view_alloc();
|
||||
popup->timer = osTimerNew(popup_timer_callback, osTimerOnce, popup, NULL);
|
||||
popup->timer = furi_timer_alloc(popup_timer_callback, FuriTimerTypeOnce, popup);
|
||||
furi_assert(popup->timer);
|
||||
popup->timer_period_in_ms = 1000;
|
||||
popup->timer_enabled = false;
|
||||
@@ -146,7 +147,7 @@ Popup* popup_alloc() {
|
||||
|
||||
void popup_free(Popup* popup) {
|
||||
furi_assert(popup);
|
||||
osTimerDelete(popup->timer);
|
||||
furi_timer_free(popup->timer);
|
||||
view_free(popup->view);
|
||||
free(popup);
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
struct TextInput {
|
||||
View* view;
|
||||
osTimerId_t timer;
|
||||
FuriTimer* timer;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -310,7 +310,7 @@ static void text_input_handle_ok(TextInput* text_input, TextInputModel* model, b
|
||||
(!model->validator_callback(
|
||||
model->text_buffer, model->validator_text, model->validator_callback_context))) {
|
||||
model->valadator_message_visible = true;
|
||||
osTimerStart(text_input->timer, osKernelGetTickFreq() * 4);
|
||||
furi_timer_start(text_input->timer, furi_kernel_get_tick_frequency() * 4);
|
||||
} else if(model->callback != 0 && text_length > 0) {
|
||||
model->callback(model->callback_context);
|
||||
}
|
||||
@@ -438,7 +438,7 @@ TextInput* text_input_alloc() {
|
||||
view_set_draw_callback(text_input->view, text_input_view_draw_callback);
|
||||
view_set_input_callback(text_input->view, text_input_view_input_callback);
|
||||
|
||||
text_input->timer = osTimerNew(text_input_timer_callback, osTimerOnce, text_input, NULL);
|
||||
text_input->timer = furi_timer_alloc(text_input_timer_callback, FuriTimerTypeOnce, text_input);
|
||||
|
||||
with_view_model(
|
||||
text_input->view, (TextInputModel * model) {
|
||||
@@ -460,11 +460,11 @@ void text_input_free(TextInput* text_input) {
|
||||
});
|
||||
|
||||
// Send stop command
|
||||
osTimerStop(text_input->timer);
|
||||
furi_timer_stop(text_input->timer);
|
||||
// Wait till timer stop
|
||||
while(osTimerIsRunning(text_input->timer)) osDelay(1);
|
||||
while(furi_timer_is_running(text_input->timer)) furi_delay_tick(1);
|
||||
// Release allocated memory
|
||||
osTimerDelete(text_input->timer);
|
||||
furi_timer_free(text_input->timer);
|
||||
|
||||
view_free(text_input->view);
|
||||
|
||||
|
@@ -81,7 +81,7 @@ void view_allocate_model(View* view, ViewModelType type, size_t size) {
|
||||
view->model = malloc(size);
|
||||
} else if(view->model_type == ViewModelTypeLocking) {
|
||||
ViewModelLocking* model = malloc(sizeof(ViewModelLocking));
|
||||
model->mutex = osMutexNew(NULL);
|
||||
model->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
furi_check(model->mutex);
|
||||
model->data = malloc(size);
|
||||
view->model = model;
|
||||
@@ -98,7 +98,7 @@ void view_free_model(View* view) {
|
||||
free(view->model);
|
||||
} else if(view->model_type == ViewModelTypeLocking) {
|
||||
ViewModelLocking* model = view->model;
|
||||
furi_check(osMutexDelete(model->mutex) == osOK);
|
||||
furi_mutex_free(model->mutex);
|
||||
free(model->data);
|
||||
free(model);
|
||||
view->model = NULL;
|
||||
@@ -111,7 +111,7 @@ void* view_get_model(View* view) {
|
||||
furi_assert(view);
|
||||
if(view->model_type == ViewModelTypeLocking) {
|
||||
ViewModelLocking* model = (ViewModelLocking*)(view->model);
|
||||
furi_check(osMutexAcquire(model->mutex, osWaitForever) == osOK);
|
||||
furi_check(furi_mutex_acquire(model->mutex, FuriWaitForever) == FuriStatusOk);
|
||||
return model->data;
|
||||
}
|
||||
return view->model;
|
||||
@@ -138,7 +138,7 @@ void view_unlock_model(View* view) {
|
||||
furi_assert(view);
|
||||
if(view->model_type == ViewModelTypeLocking) {
|
||||
ViewModelLocking* model = (ViewModelLocking*)(view->model);
|
||||
furi_check(osMutexRelease(model->mutex) == osOK);
|
||||
furi_check(furi_mutex_release(model->mutex) == FuriStatusOk);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,7 @@ void view_dispatcher_free(ViewDispatcher* view_dispatcher) {
|
||||
view_port_free(view_dispatcher->view_port);
|
||||
// Free internal queue
|
||||
if(view_dispatcher->queue) {
|
||||
osMessageQueueDelete(view_dispatcher->queue);
|
||||
furi_message_queue_free(view_dispatcher->queue);
|
||||
}
|
||||
// Free dispatcher
|
||||
free(view_dispatcher);
|
||||
@@ -39,7 +39,7 @@ void view_dispatcher_free(ViewDispatcher* view_dispatcher) {
|
||||
void view_dispatcher_enable_queue(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->queue == NULL);
|
||||
view_dispatcher->queue = osMessageQueueNew(16, sizeof(ViewDispatcherMessage), NULL);
|
||||
view_dispatcher->queue = furi_message_queue_alloc(16, sizeof(ViewDispatcherMessage));
|
||||
}
|
||||
|
||||
void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, void* context) {
|
||||
@@ -77,11 +77,11 @@ void view_dispatcher_run(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->queue);
|
||||
|
||||
uint32_t tick_period = view_dispatcher->tick_period == 0 ? osWaitForever :
|
||||
uint32_t tick_period = view_dispatcher->tick_period == 0 ? FuriWaitForever :
|
||||
view_dispatcher->tick_period;
|
||||
ViewDispatcherMessage message;
|
||||
while(1) {
|
||||
if(osMessageQueueGet(view_dispatcher->queue, &message, NULL, tick_period) != osOK) {
|
||||
if(furi_message_queue_get(view_dispatcher->queue, &message, tick_period) != FuriStatusOk) {
|
||||
view_dispatcher_handle_tick_event(view_dispatcher);
|
||||
continue;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ void view_dispatcher_run(ViewDispatcher* view_dispatcher) {
|
||||
|
||||
// Wait till all input events delivered
|
||||
while(view_dispatcher->ongoing_input) {
|
||||
osMessageQueueGet(view_dispatcher->queue, &message, NULL, osWaitForever);
|
||||
furi_message_queue_get(view_dispatcher->queue, &message, FuriWaitForever);
|
||||
if(message.type == ViewDispatcherMessageTypeInput) {
|
||||
uint8_t key_bit = (1 << message.input.key);
|
||||
if(message.input.type == InputTypePress) {
|
||||
@@ -113,7 +113,8 @@ void view_dispatcher_stop(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher->queue);
|
||||
ViewDispatcherMessage message;
|
||||
message.type = ViewDispatcherMessageTypeStop;
|
||||
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(view_dispatcher->queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void view_dispatcher_add_view(ViewDispatcher* view_dispatcher, uint32_t view_id, View* view) {
|
||||
@@ -224,7 +225,9 @@ void view_dispatcher_input_callback(InputEvent* event, void* context) {
|
||||
ViewDispatcherMessage message;
|
||||
message.type = ViewDispatcherMessageTypeInput;
|
||||
message.input = *event;
|
||||
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(view_dispatcher->queue, &message, FuriWaitForever) ==
|
||||
FuriStatusOk);
|
||||
} else {
|
||||
view_dispatcher_handle_input(view_dispatcher, event);
|
||||
}
|
||||
@@ -314,7 +317,8 @@ void view_dispatcher_send_custom_event(ViewDispatcher* view_dispatcher, uint32_t
|
||||
message.type = ViewDispatcherMessageTypeCustomEvent;
|
||||
message.custom_event = event;
|
||||
|
||||
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(view_dispatcher->queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* view) {
|
||||
|
@@ -15,7 +15,7 @@
|
||||
DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST)
|
||||
|
||||
struct ViewDispatcher {
|
||||
osMessageQueueId_t queue;
|
||||
FuriMessageQueue* queue;
|
||||
Gui* gui;
|
||||
ViewPort* view_port;
|
||||
ViewDict_t views;
|
||||
|
@@ -10,7 +10,7 @@
|
||||
|
||||
typedef struct {
|
||||
void* data;
|
||||
osMutexId_t mutex;
|
||||
FuriMutex* mutex;
|
||||
} ViewModelLocking;
|
||||
|
||||
struct View {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include "gui/view.h"
|
||||
#include "furi/memmgr.h"
|
||||
#include <core/memmgr.h>
|
||||
#include "view_stack.h"
|
||||
#include "view_i.h"
|
||||
|
||||
|
Reference in New Issue
Block a user