furi_check - a new way to asserting (#204)
* hal-related task_is_isr_context function * furi_check implementation * change application to use furi_check * add second level of assertion * add TODO about ISR context * Applications: refactor furi_check and furi_assert. * Apploader: propwer widget usage. Menu: check on furi resource request. * refactor furi_check Co-authored-by: Aleksandr Kutuzov <aku@plooks.com> Co-authored-by: coreglitch <mail@s3f.ru>
This commit is contained in:
		| @@ -3,8 +3,8 @@ | ||||
| #include "icon.h" | ||||
| #include "icon_i.h" | ||||
|  | ||||
| #include <assert.h> | ||||
| #include <flipper.h> | ||||
| #include <flipper_v2.h> | ||||
|  | ||||
| typedef struct { | ||||
|     CanvasApi api; | ||||
| @@ -60,12 +60,12 @@ CanvasApi* canvas_api_init() { | ||||
| } | ||||
|  | ||||
| void canvas_api_free(CanvasApi* api) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     free(api); | ||||
| } | ||||
|  | ||||
| void canvas_commit(CanvasApi* api) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_SetPowerSave(&canvas->fb, 0); // wake up display | ||||
|     u8g2_SendBuffer(&canvas->fb); | ||||
| @@ -77,7 +77,7 @@ void canvas_frame_set( | ||||
|     uint8_t offset_y, | ||||
|     uint8_t width, | ||||
|     uint8_t height) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     canvas->offset_x = offset_x; | ||||
|     canvas->offset_y = offset_y; | ||||
| @@ -86,31 +86,31 @@ void canvas_frame_set( | ||||
| } | ||||
|  | ||||
| uint8_t canvas_width(CanvasApi* api) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     return canvas->width; | ||||
| } | ||||
|  | ||||
| uint8_t canvas_height(CanvasApi* api) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     return canvas->height; | ||||
| } | ||||
|  | ||||
| void canvas_clear(CanvasApi* api) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_ClearBuffer(&canvas->fb); | ||||
| } | ||||
|  | ||||
| void canvas_color_set(CanvasApi* api, Color color) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_SetDrawColor(&canvas->fb, color); | ||||
| } | ||||
|  | ||||
| void canvas_font_set(CanvasApi* api, Font font) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_SetFontMode(&canvas->fb, 1); | ||||
|     if(font == FontPrimary) { | ||||
| @@ -118,12 +118,12 @@ void canvas_font_set(CanvasApi* api, Font font) { | ||||
|     } else if(font == FontSecondary) { | ||||
|         u8g2_SetFont(&canvas->fb, u8g2_font_HelvetiPixel_tr); | ||||
|     } else { | ||||
|         assert(0); | ||||
|         furi_check(0); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void canvas_str_draw(CanvasApi* api, uint8_t x, uint8_t y, const char* str) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     if(!str) return; | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     x += canvas->offset_x; | ||||
| @@ -132,7 +132,7 @@ void canvas_str_draw(CanvasApi* api, uint8_t x, uint8_t y, const char* str) { | ||||
| } | ||||
|  | ||||
| void canvas_icon_draw(CanvasApi* api, uint8_t x, uint8_t y, Icon* icon) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     if(!icon) return; | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     x += canvas->offset_x; | ||||
| @@ -142,25 +142,25 @@ void canvas_icon_draw(CanvasApi* api, uint8_t x, uint8_t y, Icon* icon) { | ||||
| } | ||||
|  | ||||
| void canvas_dot_draw(CanvasApi* api, uint8_t x, uint8_t y) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_DrawPixel(&canvas->fb, x, y); | ||||
| } | ||||
|  | ||||
| void canvas_box_draw(CanvasApi* api, uint8_t x, uint8_t y, uint8_t width, uint8_t height) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_DrawBox(&canvas->fb, x, y, width, height); | ||||
| } | ||||
|  | ||||
| void canvas_draw_frame(CanvasApi* api, uint8_t x, uint8_t y, uint8_t width, uint8_t height) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_DrawFrame(&canvas->fb, x, y, width, height); | ||||
| } | ||||
|  | ||||
| void canvas_draw_line(CanvasApi* api, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) { | ||||
|     assert(api); | ||||
|     furi_assert(api); | ||||
|     Canvas* canvas = (Canvas*)api; | ||||
|     u8g2_DrawLine(&canvas->fb, x1, y1, x2, y2); | ||||
| } | ||||
|   | ||||
| @@ -34,7 +34,7 @@ Widget* gui_widget_find_enabled(WidgetArray_t array) { | ||||
| } | ||||
|  | ||||
| void gui_update(Gui* gui) { | ||||
|     assert(gui); | ||||
|     furi_assert(gui); | ||||
|     GuiMessage message; | ||||
|     message.type = GuiMessageTypeRedraw; | ||||
|     gui_event_messsage_send(gui->event, &message); | ||||
| @@ -83,7 +83,7 @@ bool gui_redraw_none(Gui* gui) { | ||||
| } | ||||
|  | ||||
| void gui_redraw(Gui* gui) { | ||||
|     assert(gui); | ||||
|     furi_assert(gui); | ||||
|     gui_lock(gui); | ||||
|  | ||||
|     if(!gui_redraw_fs(gui)) { | ||||
| @@ -98,7 +98,9 @@ void gui_redraw(Gui* gui) { | ||||
| } | ||||
|  | ||||
| void gui_input(Gui* gui, InputEvent* input_event) { | ||||
|     assert(gui); | ||||
|     furi_assert(gui); | ||||
|     furi_assert(input_event); | ||||
|  | ||||
|     gui_lock(gui); | ||||
|  | ||||
|     Widget* widget = gui_widget_find_enabled(gui->layers[GuiLayerFullscreen]); | ||||
| @@ -113,19 +115,19 @@ void gui_input(Gui* gui, InputEvent* input_event) { | ||||
| } | ||||
|  | ||||
| void gui_lock(Gui* gui) { | ||||
|     assert(gui); | ||||
|     assert(osMutexAcquire(gui->mutex, osWaitForever) == osOK); | ||||
|     furi_assert(gui); | ||||
|     furi_check(osMutexAcquire(gui->mutex, osWaitForever) == osOK); | ||||
| } | ||||
|  | ||||
| void gui_unlock(Gui* gui) { | ||||
|     assert(gui); | ||||
|     assert(osMutexRelease(gui->mutex) == osOK); | ||||
|     furi_assert(gui); | ||||
|     furi_check(osMutexRelease(gui->mutex) == osOK); | ||||
| } | ||||
|  | ||||
| void gui_add_widget(GuiApi* gui_api, Widget* widget, GuiLayer layer) { | ||||
|     assert(gui_api); | ||||
|     assert(widget); | ||||
|     assert(layer < GuiLayerMAX); | ||||
|     furi_assert(gui_api); | ||||
|     furi_assert(widget); | ||||
|     furi_check(layer < GuiLayerMAX); | ||||
|     Gui* gui = (Gui*)gui_api; | ||||
|  | ||||
|     gui_lock(gui); | ||||
| @@ -136,8 +138,8 @@ void gui_add_widget(GuiApi* gui_api, Widget* widget, GuiLayer layer) { | ||||
| } | ||||
|  | ||||
| void gui_remove_widget(GuiApi* gui_api, Widget* widget) { | ||||
|     assert(gui_api); | ||||
|     assert(widget); | ||||
|     furi_assert(gui_api); | ||||
|     furi_assert(widget); | ||||
|     Gui* gui = (Gui*)gui_api; | ||||
|  | ||||
|     gui_lock(gui); | ||||
| @@ -164,7 +166,7 @@ Gui* gui_alloc() { | ||||
|     gui->api.remove_widget = gui_remove_widget; | ||||
|     // Allocate mutex | ||||
|     gui->mutex = osMutexNew(NULL); | ||||
|     assert(gui->mutex); | ||||
|     furi_check(gui->mutex); | ||||
|     // Event dispatcher | ||||
|     gui->event = gui_event_alloc(); | ||||
|     // Drawing canvas api | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| #include "gui_event.h" | ||||
|  | ||||
| #include <flipper_v2.h> | ||||
| #include <assert.h> | ||||
|  | ||||
| #define GUI_EVENT_MQUEUE_SIZE 8 | ||||
|  | ||||
| @@ -11,7 +10,9 @@ struct GuiEvent { | ||||
| }; | ||||
|  | ||||
| void gui_event_input_events_callback(const void* value, void* ctx) { | ||||
|     assert(ctx); | ||||
|     furi_assert(value); | ||||
|     furi_assert(ctx); | ||||
|  | ||||
|     GuiEvent* gui_event = ctx; | ||||
|  | ||||
|     GuiMessage message; | ||||
| @@ -23,35 +24,36 @@ void gui_event_input_events_callback(const void* value, void* ctx) { | ||||
|  | ||||
| GuiEvent* gui_event_alloc() { | ||||
|     GuiEvent* gui_event = furi_alloc(sizeof(GuiEvent)); | ||||
|     // Allocate message que | ||||
|  | ||||
|     // Allocate message queue | ||||
|     gui_event->mqueue = osMessageQueueNew(GUI_EVENT_MQUEUE_SIZE, sizeof(GuiMessage), NULL); | ||||
|     assert(gui_event->mqueue); | ||||
|     furi_check(gui_event->mqueue); | ||||
|  | ||||
|     // Input | ||||
|     gui_event->input_event_record = furi_open("input_events"); | ||||
|     assert(gui_event->input_event_record != NULL); | ||||
|     furi_check(gui_event->input_event_record != NULL); | ||||
|     subscribe_pubsub(gui_event->input_event_record, gui_event_input_events_callback, gui_event); | ||||
|  | ||||
|     return gui_event; | ||||
| } | ||||
|  | ||||
| void gui_event_free(GuiEvent* gui_event) { | ||||
|     assert(gui_event); | ||||
|     assert(osMessageQueueDelete(gui_event->mqueue) == osOK); | ||||
|     furi_assert(gui_event); | ||||
|     furi_check(osMessageQueueDelete(gui_event->mqueue) == osOK); | ||||
|     free(gui_event); | ||||
| } | ||||
|  | ||||
| void gui_event_messsage_send(GuiEvent* gui_event, GuiMessage* message) { | ||||
|     assert(gui_event); | ||||
|     assert(message); | ||||
|     furi_assert(gui_event); | ||||
|     furi_assert(message); | ||||
|     osMessageQueuePut(gui_event->mqueue, message, 0, 0); | ||||
| } | ||||
|  | ||||
| GuiMessage gui_event_message_next(GuiEvent* gui_event) { | ||||
|     assert(gui_event); | ||||
|     furi_assert(gui_event); | ||||
|     GuiMessage message; | ||||
|  | ||||
|     assert(osMessageQueueGet(gui_event->mqueue, &message, NULL, osWaitForever) == osOK); | ||||
|     furi_check(osMessageQueueGet(gui_event->mqueue, &message, NULL, osWaitForever) == osOK); | ||||
|  | ||||
|     return message; | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  | ||||
| #include <cmsis_os2.h> | ||||
| #include <flipper.h> | ||||
| #include <assert.h> | ||||
| #include <flipper_v2.h> | ||||
|  | ||||
| Icon* icon_alloc(const IconData* data) { | ||||
|     Icon* icon = furi_alloc(sizeof(Icon)); | ||||
| @@ -12,12 +12,12 @@ Icon* icon_alloc(const IconData* data) { | ||||
| } | ||||
|  | ||||
| void icon_free(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     free(icon); | ||||
| } | ||||
|  | ||||
| const uint8_t* icon_get_data(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     if(icon->tick) { | ||||
|         uint32_t now = osKernelGetTickCount(); | ||||
|         if(now < icon->tick) { | ||||
| @@ -32,32 +32,32 @@ const uint8_t* icon_get_data(Icon* icon) { | ||||
| } | ||||
|  | ||||
| void icon_next_frame(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     icon->frame = (icon->frame + 1) % icon->data->frame_count; | ||||
| } | ||||
|  | ||||
| uint8_t icon_get_width(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     return icon->data->width; | ||||
| } | ||||
|  | ||||
| uint8_t icon_get_height(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     return icon->data->height; | ||||
| } | ||||
|  | ||||
| bool icon_is_animated(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     return icon->data->frame_count > 1; | ||||
| } | ||||
|  | ||||
| void icon_start_animation(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     icon->tick = osKernelGetTickCount(); | ||||
| } | ||||
|  | ||||
| void icon_stop_animation(Icon* icon) { | ||||
|     assert(icon); | ||||
|     furi_assert(icon); | ||||
|     icon->tick = 0; | ||||
|     icon->frame = 0; | ||||
| } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
|  | ||||
| #include <cmsis_os.h> | ||||
| #include <flipper.h> | ||||
| #include <flipper_v2.h> | ||||
|  | ||||
| #include "gui.h" | ||||
| #include "gui_i.h" | ||||
| @@ -25,13 +26,13 @@ Widget* widget_alloc(WidgetDrawCallback callback, void* callback_context) { | ||||
| } | ||||
|  | ||||
| void widget_free(Widget* widget) { | ||||
|     assert(widget); | ||||
|     assert(widget->gui == NULL); | ||||
|     furi_assert(widget); | ||||
|     furi_check(widget->gui == NULL); | ||||
|     free(widget); | ||||
| } | ||||
|  | ||||
| void widget_enabled_set(Widget* widget, bool enabled) { | ||||
|     assert(widget); | ||||
|     furi_assert(widget); | ||||
|     if(widget->is_enabled != enabled) { | ||||
|         widget->is_enabled = enabled; | ||||
|         widget_update(widget); | ||||
| @@ -39,47 +40,47 @@ void widget_enabled_set(Widget* widget, bool enabled) { | ||||
| } | ||||
|  | ||||
| bool widget_is_enabled(Widget* widget) { | ||||
|     assert(widget); | ||||
|     furi_assert(widget); | ||||
|     return widget->is_enabled; | ||||
| } | ||||
|  | ||||
| void widget_draw_callback_set(Widget* widget, WidgetDrawCallback callback, void* context) { | ||||
|     assert(widget); | ||||
|     furi_assert(widget); | ||||
|     widget->draw_callback = callback; | ||||
|     widget->draw_callback_context = context; | ||||
| } | ||||
|  | ||||
| void widget_input_callback_set(Widget* widget, WidgetInputCallback callback, void* context) { | ||||
|     assert(widget); | ||||
|     furi_assert(widget); | ||||
|     widget->input_callback = callback; | ||||
|     widget->input_callback_context = context; | ||||
| } | ||||
|  | ||||
| void widget_update(Widget* widget) { | ||||
|     assert(widget); | ||||
|     furi_assert(widget); | ||||
|     if(widget->gui) gui_update(widget->gui); | ||||
| } | ||||
|  | ||||
| void widget_gui_set(Widget* widget, Gui* gui) { | ||||
|     assert(widget); | ||||
|     assert(gui); | ||||
|     furi_assert(widget); | ||||
|     furi_assert(gui); | ||||
|     widget->gui = gui; | ||||
| } | ||||
|  | ||||
| void widget_draw(Widget* widget, CanvasApi* canvas_api) { | ||||
|     assert(widget); | ||||
|     assert(canvas_api); | ||||
|     assert(widget->gui); | ||||
|     furi_assert(widget); | ||||
|     furi_assert(canvas_api); | ||||
|  | ||||
|     furi_check(widget->gui); | ||||
|     if(widget->draw_callback) { | ||||
|         widget->draw_callback(canvas_api, widget->draw_callback_context); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void widget_input(Widget* widget, InputEvent* event) { | ||||
|     assert(widget); | ||||
|     assert(event); | ||||
|     assert(widget->gui); | ||||
|     furi_assert(widget); | ||||
|     furi_assert(event); | ||||
|  | ||||
|     furi_check(widget->gui); | ||||
|     if(widget->input_callback) widget->input_callback(event, widget->input_callback_context); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user