[FL-1942] Applications: Display Test. u8g2 usage refactoring. #770
This commit is contained in:
		
							parent
							
								
									19be061693
								
							
						
					
					
						commit
						f390060922
					
				| @ -19,8 +19,11 @@ extern int32_t desktop_srv(void* p); | |||||||
| // Apps
 | // Apps
 | ||||||
| extern int32_t accessor_app(void* p); | extern int32_t accessor_app(void* p); | ||||||
| extern int32_t archive_app(void* p); | extern int32_t archive_app(void* p); | ||||||
|  | extern int32_t bad_usb_app(void* p); | ||||||
| extern int32_t blink_test_app(void* p); | extern int32_t blink_test_app(void* p); | ||||||
|  | extern int32_t bt_debug_app(void* p); | ||||||
| extern int32_t delay_test_app(void* p); | extern int32_t delay_test_app(void* p); | ||||||
|  | extern int32_t display_test_app(void* p); | ||||||
| extern int32_t gpio_app(void* p); | extern int32_t gpio_app(void* p); | ||||||
| extern int32_t ibutton_app(void* p); | extern int32_t ibutton_app(void* p); | ||||||
| extern int32_t irda_app(void* p); | extern int32_t irda_app(void* p); | ||||||
| @ -32,11 +35,9 @@ extern int32_t nfc_app(void* p); | |||||||
| extern int32_t scened_app(void* p); | extern int32_t scened_app(void* p); | ||||||
| extern int32_t storage_test_app(void* p); | extern int32_t storage_test_app(void* p); | ||||||
| extern int32_t subghz_app(void* p); | extern int32_t subghz_app(void* p); | ||||||
| extern int32_t vibro_test_app(void* p); |  | ||||||
| extern int32_t bt_debug_app(void* p); |  | ||||||
| extern int32_t usb_test_app(void* p); |  | ||||||
| extern int32_t usb_mouse_app(void* p); | extern int32_t usb_mouse_app(void* p); | ||||||
| extern int32_t bad_usb_app(void* p); | extern int32_t usb_test_app(void* p); | ||||||
|  | extern int32_t vibro_test_app(void* p); | ||||||
| 
 | 
 | ||||||
| // Plugins
 | // Plugins
 | ||||||
| extern int32_t music_player_app(void* p); | extern int32_t music_player_app(void* p); | ||||||
| @ -208,43 +209,43 @@ const size_t FLIPPER_PLUGINS_COUNT = sizeof(FLIPPER_PLUGINS) / sizeof(FlipperApp | |||||||
| // Plugin menu
 | // Plugin menu
 | ||||||
| const FlipperApplication FLIPPER_DEBUG_APPS[] = { | const FlipperApplication FLIPPER_DEBUG_APPS[] = { | ||||||
| #ifdef APP_BLINK | #ifdef APP_BLINK | ||||||
|     {.app = blink_test_app, .name = "Blink Test", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = blink_test_app, .name = "Blink Test", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_VIBRO_DEMO | #ifdef APP_VIBRO_TEST | ||||||
|     {.app = vibro_test_app, .name = "Vibro Test", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = vibro_test_app, .name = "Vibro Test", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_KEYPAD_TEST | #ifdef APP_KEYPAD_TEST | ||||||
|     {.app = keypad_test_app, .name = "Keypad Test", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = keypad_test_app, .name = "Keypad Test", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_ACCESSOR | #ifdef APP_ACCESSOR | ||||||
|     {.app = accessor_app, .name = "Accessor", .stack_size = 4096, .icon = &A_Plugins_14}, |     {.app = accessor_app, .name = "Accessor", .stack_size = 4096, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_USB_TEST | #ifdef APP_USB_TEST | ||||||
|     {.app = usb_test_app, .name = "USB Test", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = usb_test_app, .name = "USB Test", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_USB_MOUSE | #ifdef APP_USB_MOUSE | ||||||
|     {.app = usb_mouse_app, .name = "USB Mouse demo", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = usb_mouse_app, .name = "USB Mouse demo", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_BAD_USB | #ifdef APP_BAD_USB | ||||||
|     {.app = bad_usb_app, .name = "Bad USB test", .stack_size = 2048, .icon = &A_Plugins_14}, |     {.app = bad_usb_app, .name = "Bad USB test", .stack_size = 2048, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_IRDA_MONITOR | #ifdef APP_IRDA_MONITOR | ||||||
|     {.app = irda_monitor_app, .name = "Irda Monitor", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = irda_monitor_app, .name = "Irda Monitor", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_SCENED | #ifdef APP_SCENED | ||||||
|     {.app = scened_app, .name = "Templated Scene", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = scened_app, .name = "Templated Scene", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_LF_RFID | #ifdef APP_LF_RFID | ||||||
|     {.app = lfrfid_debug_app, .name = "LF-RFID Debug", .stack_size = 1024, .icon = &A_125khz_14}, |     {.app = lfrfid_debug_app, .name = "LF-RFID Debug", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef SRV_BT | #ifdef SRV_BT | ||||||
| @ -252,7 +253,11 @@ const FlipperApplication FLIPPER_DEBUG_APPS[] = { | |||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef APP_UNIT_TESTS | #ifdef APP_UNIT_TESTS | ||||||
|     {.app = delay_test_app, .name = "Delay Test App", .stack_size = 1024, .icon = &A_Plugins_14}, |     {.app = delay_test_app, .name = "Delay Test", .stack_size = 1024, .icon = NULL}, | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | #ifdef APP_DISPLAY_TEST | ||||||
|  |     {.app = display_test_app, .name = "Display Test", .stack_size = 1024, .icon = NULL}, | ||||||
| #endif | #endif | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -42,8 +42,10 @@ APP_BLINK	= 1 | |||||||
| APP_IRDA_MONITOR = 1 | APP_IRDA_MONITOR = 1 | ||||||
| APP_KEYPAD_TEST = 1 | APP_KEYPAD_TEST = 1 | ||||||
| APP_SD_TEST	= 1 | APP_SD_TEST	= 1 | ||||||
| APP_VIBRO_DEMO = 1 | APP_VIBRO_TEST = 1 | ||||||
| APP_USB_TEST = 1 | APP_USB_TEST = 1 | ||||||
|  | APP_DISPLAY_TEST = 1 | ||||||
|  | 
 | ||||||
| APP_USB_MOUSE = 1 | APP_USB_MOUSE = 1 | ||||||
| APP_BAD_USB = 1 | APP_BAD_USB = 1 | ||||||
| endif | endif | ||||||
| @ -117,9 +119,9 @@ SRV_GUI		= 1 | |||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| APP_VIBRO_DEMO ?= 0 | APP_VIBRO_TEST ?= 0 | ||||||
| ifeq ($(APP_VIBRO_DEMO), 1) | ifeq ($(APP_VIBRO_TEST), 1) | ||||||
| CFLAGS		+= -DAPP_VIBRO_DEMO | CFLAGS		+= -DAPP_VIBRO_TEST | ||||||
| SRV_GUI		= 1 | SRV_GUI		= 1 | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
| @ -127,21 +129,26 @@ endif | |||||||
| APP_USB_TEST ?= 0 | APP_USB_TEST ?= 0 | ||||||
| ifeq ($(APP_USB_TEST), 1) | ifeq ($(APP_USB_TEST), 1) | ||||||
| CFLAGS		+= -DAPP_USB_TEST | CFLAGS		+= -DAPP_USB_TEST | ||||||
| SRV_INPUT = 1 |  | ||||||
| SRV_GUI = 1 | SRV_GUI = 1 | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | APP_DISPLAY_TEST ?= 0 | ||||||
|  | ifeq ($(APP_DISPLAY_TEST), 1) | ||||||
|  | CFLAGS		+= -DAPP_DISPLAY_TEST | ||||||
|  | SRV_GUI = 1 | ||||||
|  | endif | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| APP_USB_MOUSE ?= 0 | APP_USB_MOUSE ?= 0 | ||||||
| ifeq ($(APP_USB_MOUSE), 1) | ifeq ($(APP_USB_MOUSE), 1) | ||||||
| CFLAGS		+= -DAPP_USB_MOUSE | CFLAGS		+= -DAPP_USB_MOUSE | ||||||
| SRV_INPUT = 1 |  | ||||||
| SRV_GUI = 1 | SRV_GUI = 1 | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
| APP_BAD_USB ?= 0 | APP_BAD_USB ?= 0 | ||||||
| ifeq ($(APP_BAD_USB), 1) | ifeq ($(APP_BAD_USB), 1) | ||||||
| CFLAGS		+= -DAPP_BAD_USB | CFLAGS		+= -DAPP_BAD_USB | ||||||
| SRV_INPUT = 1 |  | ||||||
| SRV_GUI = 1 | SRV_GUI = 1 | ||||||
| endif  | endif  | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										100
									
								
								applications/debug_tools/display_test/display_test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								applications/debug_tools/display_test/display_test.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,100 @@ | |||||||
|  | #include "display_test.h" | ||||||
|  | 
 | ||||||
|  | #include <furi-hal.h> | ||||||
|  | #include <furi.h> | ||||||
|  | 
 | ||||||
|  | #include <gui/gui.h> | ||||||
|  | #include <gui/view_dispatcher.h> | ||||||
|  | #include <gui/modules/submenu.h> | ||||||
|  | #include <gui/modules/variable-item-list.h> | ||||||
|  | 
 | ||||||
|  | #include "view_display_test.h" | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |     Gui* gui; | ||||||
|  |     ViewDispatcher* view_dispatcher; | ||||||
|  |     ViewDisplayTest* view_display_test; | ||||||
|  |     VariableItemList* variable_item_list; | ||||||
|  |     Submenu* submenu; | ||||||
|  | } DisplayTest; | ||||||
|  | 
 | ||||||
|  | typedef enum { | ||||||
|  |     DisplayTestViewSubmenu, | ||||||
|  |     DisplayTestViewConfigure, | ||||||
|  |     DisplayTestViewDisplayTest, | ||||||
|  | } DisplayTestView; | ||||||
|  | 
 | ||||||
|  | static void display_test_submenu_callback(void* context, uint32_t index) { | ||||||
|  |     DisplayTest* instance = (DisplayTest*)context; | ||||||
|  | 
 | ||||||
|  |     view_dispatcher_switch_to_view(instance->view_dispatcher, index); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static uint32_t display_test_previous_callback(void* context) { | ||||||
|  |     return DisplayTestViewSubmenu; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static uint32_t display_test_exit_callback(void* context) { | ||||||
|  |     return VIEW_NONE; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | DisplayTest* display_test_alloc() { | ||||||
|  |     DisplayTest* instance = furi_alloc(sizeof(DisplayTest)); | ||||||
|  | 
 | ||||||
|  |     View* view = NULL; | ||||||
|  | 
 | ||||||
|  |     instance->gui = furi_record_open("gui"); | ||||||
|  |     instance->view_dispatcher = view_dispatcher_alloc(); | ||||||
|  | 
 | ||||||
|  |     instance->view_display_test = view_display_test_alloc(); | ||||||
|  |     view_dispatcher_enable_queue(instance->view_dispatcher); | ||||||
|  |     view_dispatcher_attach_to_gui( | ||||||
|  |         instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen); | ||||||
|  |     view = view_display_test_get_view(instance->view_display_test); | ||||||
|  |     view_set_previous_callback(view, display_test_previous_callback); | ||||||
|  |     view_dispatcher_add_view(instance->view_dispatcher, DisplayTestViewDisplayTest, view); | ||||||
|  | 
 | ||||||
|  |     instance->submenu = submenu_alloc(); | ||||||
|  |     view = submenu_get_view(instance->submenu); | ||||||
|  |     view_set_previous_callback(view, display_test_exit_callback); | ||||||
|  |     view_dispatcher_add_view(instance->view_dispatcher, DisplayTestViewSubmenu, view); | ||||||
|  |     submenu_add_item( | ||||||
|  |         instance->submenu, | ||||||
|  |         "Test", | ||||||
|  |         DisplayTestViewDisplayTest, | ||||||
|  |         display_test_submenu_callback, | ||||||
|  |         instance); | ||||||
|  |     // submenu_add_item(instance->submenu, "Configure", DisplayTestViewConfigure, display_test_submenu_callback, instance);
 | ||||||
|  | 
 | ||||||
|  |     return instance; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void display_test_free(DisplayTest* instance) { | ||||||
|  |     view_dispatcher_remove_view(instance->view_dispatcher, DisplayTestViewSubmenu); | ||||||
|  |     submenu_free(instance->submenu); | ||||||
|  | 
 | ||||||
|  |     view_dispatcher_remove_view(instance->view_dispatcher, DisplayTestViewDisplayTest); | ||||||
|  |     view_display_test_free(instance->view_display_test); | ||||||
|  | 
 | ||||||
|  |     view_dispatcher_free(instance->view_dispatcher); | ||||||
|  |     furi_record_close("gui"); | ||||||
|  | 
 | ||||||
|  |     free(instance); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | int32_t display_test_run(DisplayTest* instance) { | ||||||
|  |     view_dispatcher_switch_to_view(instance->view_dispatcher, DisplayTestViewSubmenu); | ||||||
|  |     view_dispatcher_run(instance->view_dispatcher); | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | int32_t display_test_app(void* p) { | ||||||
|  |     DisplayTest* instance = display_test_alloc(); | ||||||
|  | 
 | ||||||
|  |     int32_t ret = display_test_run(instance); | ||||||
|  | 
 | ||||||
|  |     display_test_free(instance); | ||||||
|  | 
 | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
							
								
								
									
										1
									
								
								applications/debug_tools/display_test/display_test.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								applications/debug_tools/display_test/display_test.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | #pragma once | ||||||
							
								
								
									
										185
									
								
								applications/debug_tools/display_test/view_display_test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										185
									
								
								applications/debug_tools/display_test/view_display_test.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,185 @@ | |||||||
|  | #include "view_display_test.h" | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |     uint32_t test; | ||||||
|  |     uint32_t size; | ||||||
|  |     uint32_t counter; | ||||||
|  |     bool flip_flop; | ||||||
|  | } ViewDisplayTestModel; | ||||||
|  | 
 | ||||||
|  | struct ViewDisplayTest { | ||||||
|  |     View* view; | ||||||
|  |     osTimerId_t timer; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static void view_display_test_draw_callback_intro(Canvas* canvas, void* _model) { | ||||||
|  |     canvas_draw_str(canvas, 12, 24, "Use < and > to switch tests"); | ||||||
|  |     canvas_draw_str(canvas, 12, 36, "Use ^ and v to switch size"); | ||||||
|  |     canvas_draw_str(canvas, 32, 48, "Use (o) to flip"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_draw_callback_fill(Canvas* canvas, void* _model) { | ||||||
|  |     ViewDisplayTestModel* model = _model; | ||||||
|  |     if(model->flip_flop) { | ||||||
|  |         uint8_t width = canvas_width(canvas); | ||||||
|  |         uint8_t height = canvas_height(canvas); | ||||||
|  |         canvas_draw_box(canvas, 0, 0, width, height); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_draw_callback_hstripe(Canvas* canvas, void* _model) { | ||||||
|  |     ViewDisplayTestModel* model = _model; | ||||||
|  |     uint8_t block = 1 + model->size; | ||||||
|  |     uint8_t width = canvas_width(canvas); | ||||||
|  |     uint8_t height = canvas_height(canvas); | ||||||
|  | 
 | ||||||
|  |     for(uint8_t y = model->flip_flop * block; y < height; y += 2 * block) { | ||||||
|  |         canvas_draw_box(canvas, 0, y, width, block); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_draw_callback_vstripe(Canvas* canvas, void* _model) { | ||||||
|  |     ViewDisplayTestModel* model = _model; | ||||||
|  |     uint8_t block = 1 + model->size; | ||||||
|  |     uint8_t width = canvas_width(canvas); | ||||||
|  |     uint8_t height = canvas_height(canvas); | ||||||
|  | 
 | ||||||
|  |     for(uint8_t x = model->flip_flop * block; x < width; x += 2 * block) { | ||||||
|  |         canvas_draw_box(canvas, x, 0, block, height); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_draw_callback_check(Canvas* canvas, void* _model) { | ||||||
|  |     ViewDisplayTestModel* model = _model; | ||||||
|  |     uint8_t block = 1 + model->size; | ||||||
|  |     uint8_t width = canvas_width(canvas); | ||||||
|  |     uint8_t height = canvas_height(canvas); | ||||||
|  | 
 | ||||||
|  |     bool flip_flop = model->flip_flop; | ||||||
|  |     for(uint8_t x = 0; x < width; x += block) { | ||||||
|  |         bool last_flip_flop = flip_flop; | ||||||
|  |         for(uint8_t y = 0; y < height; y += block) { | ||||||
|  |             if(flip_flop) { | ||||||
|  |                 canvas_draw_box(canvas, x, y, block, block); | ||||||
|  |             } | ||||||
|  |             flip_flop = !flip_flop; | ||||||
|  |         } | ||||||
|  |         if(last_flip_flop == flip_flop) { | ||||||
|  |             flip_flop = !flip_flop; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_draw_callback_move(Canvas* canvas, void* _model) { | ||||||
|  |     ViewDisplayTestModel* model = _model; | ||||||
|  |     uint8_t block = 1 + model->size; | ||||||
|  |     uint8_t width = canvas_width(canvas) - block; | ||||||
|  |     uint8_t height = canvas_height(canvas) - block; | ||||||
|  | 
 | ||||||
|  |     uint8_t x = model->counter % width; | ||||||
|  |     if((model->counter / width) % 2) { | ||||||
|  |         x = width - x; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     uint8_t y = model->counter % height; | ||||||
|  |     if((model->counter / height) % 2) { | ||||||
|  |         y = height - y; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     canvas_draw_box(canvas, x, y, block, block); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ViewDrawCallback view_display_test_tests[] = { | ||||||
|  |     view_display_test_draw_callback_intro, | ||||||
|  |     view_display_test_draw_callback_fill, | ||||||
|  |     view_display_test_draw_callback_hstripe, | ||||||
|  |     view_display_test_draw_callback_vstripe, | ||||||
|  |     view_display_test_draw_callback_check, | ||||||
|  |     view_display_test_draw_callback_move, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static void view_display_test_draw_callback(Canvas* canvas, void* _model) { | ||||||
|  |     ViewDisplayTestModel* model = _model; | ||||||
|  |     view_display_test_tests[model->test](canvas, _model); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static bool view_display_test_input_callback(InputEvent* event, void* context) { | ||||||
|  |     ViewDisplayTest* instance = context; | ||||||
|  | 
 | ||||||
|  |     bool consumed = false; | ||||||
|  |     if(event->type == InputTypeShort || event->type == InputTypeRepeat) { | ||||||
|  |         with_view_model( | ||||||
|  |             instance->view, (ViewDisplayTestModel * model) { | ||||||
|  |                 if(event->key == InputKeyLeft && model->test > 0) { | ||||||
|  |                     model->test--; | ||||||
|  |                     consumed = true; | ||||||
|  |                 } else if( | ||||||
|  |                     event->key == InputKeyRight && | ||||||
|  |                     model->test < (COUNT_OF(view_display_test_tests) - 1)) { | ||||||
|  |                     model->test++; | ||||||
|  |                     consumed = true; | ||||||
|  |                 } else if(event->key == InputKeyDown && model->size > 0) { | ||||||
|  |                     model->size--; | ||||||
|  |                     consumed = true; | ||||||
|  |                 } else if(event->key == InputKeyUp && model->size < 24) { | ||||||
|  |                     model->size++; | ||||||
|  |                     consumed = true; | ||||||
|  |                 } else if(event->key == InputKeyOk) { | ||||||
|  |                     model->flip_flop = !model->flip_flop; | ||||||
|  |                     consumed = true; | ||||||
|  |                 } | ||||||
|  |                 return consumed; | ||||||
|  |             }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return consumed; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_enter(void* context) { | ||||||
|  |     ViewDisplayTest* instance = context; | ||||||
|  |     osTimerStart(instance->timer, osKernelGetTickFreq() / 32); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_exit(void* context) { | ||||||
|  |     ViewDisplayTest* instance = context; | ||||||
|  |     osTimerStop(instance->timer); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void view_display_test_timer_callback(void* context) { | ||||||
|  |     ViewDisplayTest* instance = context; | ||||||
|  |     with_view_model( | ||||||
|  |         instance->view, (ViewDisplayTestModel * model) { | ||||||
|  |             model->counter++; | ||||||
|  |             return true; | ||||||
|  |         }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ViewDisplayTest* view_display_test_alloc() { | ||||||
|  |     ViewDisplayTest* instance = furi_alloc(sizeof(ViewDisplayTest)); | ||||||
|  | 
 | ||||||
|  |     instance->view = view_alloc(); | ||||||
|  |     view_set_context(instance->view, instance); | ||||||
|  |     view_allocate_model(instance->view, ViewModelTypeLockFree, sizeof(ViewDisplayTestModel)); | ||||||
|  |     view_set_draw_callback(instance->view, view_display_test_draw_callback); | ||||||
|  |     view_set_input_callback(instance->view, view_display_test_input_callback); | ||||||
|  |     view_set_enter_callback(instance->view, view_display_test_enter); | ||||||
|  |     view_set_exit_callback(instance->view, view_display_test_exit); | ||||||
|  | 
 | ||||||
|  |     instance->timer = | ||||||
|  |         osTimerNew(view_display_test_timer_callback, osTimerPeriodic, instance, NULL); | ||||||
|  | 
 | ||||||
|  |     return instance; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void view_display_test_free(ViewDisplayTest* instance) { | ||||||
|  |     furi_assert(instance); | ||||||
|  | 
 | ||||||
|  |     osTimerDelete(instance->timer); | ||||||
|  |     view_free(instance->view); | ||||||
|  |     free(instance); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | View* view_display_test_get_view(ViewDisplayTest* instance) { | ||||||
|  |     furi_assert(instance); | ||||||
|  |     return instance->view; | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								applications/debug_tools/display_test/view_display_test.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								applications/debug_tools/display_test/view_display_test.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <gui/view.h> | ||||||
|  | 
 | ||||||
|  | typedef struct ViewDisplayTest ViewDisplayTest; | ||||||
|  | 
 | ||||||
|  | ViewDisplayTest* view_display_test_alloc(); | ||||||
|  | 
 | ||||||
|  | void view_display_test_free(ViewDisplayTest* instance); | ||||||
|  | 
 | ||||||
|  | View* view_display_test_get_view(ViewDisplayTest* instance); | ||||||
| @ -4,9 +4,7 @@ | |||||||
| 
 | 
 | ||||||
| #include <furi.h> | #include <furi.h> | ||||||
| #include <furi-hal.h> | #include <furi-hal.h> | ||||||
| 
 | #include <u8g2_glue.h> | ||||||
| uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); |  | ||||||
| uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); |  | ||||||
| 
 | 
 | ||||||
| Canvas* canvas_init() { | Canvas* canvas_init() { | ||||||
|     Canvas* canvas = furi_alloc(sizeof(Canvas)); |     Canvas* canvas = furi_alloc(sizeof(Canvas)); | ||||||
| @ -14,8 +12,7 @@ Canvas* canvas_init() { | |||||||
|     furi_hal_power_insomnia_enter(); |     furi_hal_power_insomnia_enter(); | ||||||
| 
 | 
 | ||||||
|     canvas->orientation = CanvasOrientationHorizontal; |     canvas->orientation = CanvasOrientationHorizontal; | ||||||
|     u8g2_Setup_st7565_erc12864_alt_f( |     u8g2_Setup_st756x_erc(&canvas->fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); | ||||||
|         &canvas->fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); |  | ||||||
| 
 | 
 | ||||||
|     // send init sequence to the display, display is in sleep mode after this
 |     // send init sequence to the display, display is in sleep mode after this
 | ||||||
|     u8g2_InitDisplay(&canvas->fb); |     u8g2_InitDisplay(&canvas->fb); | ||||||
|  | |||||||
| @ -1,68 +0,0 @@ | |||||||
| #include "u8g2/u8g2.h" |  | ||||||
| #include <furi-hal.h> |  | ||||||
| #include <furi.h> |  | ||||||
| 
 |  | ||||||
| static FuriHalSpiDevice* u8g2_periphery_display = NULL; |  | ||||||
| 
 |  | ||||||
| uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { |  | ||||||
|     switch(msg) { |  | ||||||
|     case U8X8_MSG_GPIO_AND_DELAY_INIT: |  | ||||||
|         /* HAL initialization contains all what we need so we can skip this part. */ |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_MILLI: |  | ||||||
|         osDelay(arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_10MICRO: |  | ||||||
|         delay_us(10); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_100NANO: |  | ||||||
|         asm("nop"); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_GPIO_RESET: |  | ||||||
|         hal_gpio_write(&gpio_display_rst, arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     default: |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { |  | ||||||
|     switch(msg) { |  | ||||||
|     case U8X8_MSG_BYTE_SEND: |  | ||||||
|         furi_hal_spi_bus_tx(u8g2_periphery_display->bus, (uint8_t*)arg_ptr, arg_int, 10000); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_SET_DC: |  | ||||||
|         hal_gpio_write(&gpio_display_di, arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_INIT: |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_START_TRANSFER: |  | ||||||
|         furi_assert(u8g2_periphery_display == NULL); |  | ||||||
|         u8g2_periphery_display = |  | ||||||
|             (FuriHalSpiDevice*)furi_hal_spi_device_get(FuriHalSpiDeviceIdDisplay); |  | ||||||
|         hal_gpio_write(u8g2_periphery_display->chip_select, false); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_END_TRANSFER: |  | ||||||
|         furi_assert(u8g2_periphery_display); |  | ||||||
|         hal_gpio_write(u8g2_periphery_display->chip_select, true); |  | ||||||
|         furi_hal_spi_device_return(u8g2_periphery_display); |  | ||||||
|         u8g2_periphery_display = NULL; |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     default: |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| @ -17,8 +17,7 @@ LIB_DIR			= $(PROJECT_ROOT)/lib | |||||||
| # U8G2 display library
 | # U8G2 display library
 | ||||||
| U8G2_DIR		= $(LIB_DIR)/u8g2 | U8G2_DIR		= $(LIB_DIR)/u8g2 | ||||||
| CFLAGS			+= -I$(U8G2_DIR) | CFLAGS			+= -I$(U8G2_DIR) | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8x8_d_st7565.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_glue.c | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_d_setup.c |  | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_intersection.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_intersection.c | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_setup.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_setup.c | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_d_memory.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_d_memory.c | ||||||
|  | |||||||
| @ -1,7 +1,20 @@ | |||||||
| #include <furi-hal.h> | #include <furi-hal.h> | ||||||
|  | #include <stm32wbxx_ll_utils.h> | ||||||
| 
 | 
 | ||||||
| void furi_hal_init() { | void furi_hal_init() { | ||||||
|     furi_hal_i2c_init(); |     furi_hal_i2c_init(); | ||||||
|     furi_hal_light_init(); |     furi_hal_light_init(); | ||||||
|     furi_hal_spi_init(); |     furi_hal_spi_init(); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void delay(float milliseconds) { | ||||||
|  |     LL_mDelay((uint32_t)milliseconds); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void delay_us(float microseconds) { | ||||||
|  |     microseconds = microseconds / 1000; | ||||||
|  |     if(microseconds < 1) { | ||||||
|  |         microseconds = 1; | ||||||
|  |     } | ||||||
|  |     LL_mDelay((uint32_t)microseconds); | ||||||
|  | } | ||||||
|  | |||||||
| @ -5,4 +5,10 @@ | |||||||
| #include <furi-hal-resources.h> | #include <furi-hal-resources.h> | ||||||
| #include <furi-hal-spi.h> | #include <furi-hal-spi.h> | ||||||
| 
 | 
 | ||||||
|  | #define furi_assert(value) (void)(value) | ||||||
|  | 
 | ||||||
| void furi_hal_init(); | void furi_hal_init(); | ||||||
|  | 
 | ||||||
|  | void delay(float milliseconds); | ||||||
|  | 
 | ||||||
|  | void delay_us(float microseconds); | ||||||
|  | |||||||
| @ -1,69 +0,0 @@ | |||||||
| #include <u8g2.h> |  | ||||||
| #include <assert.h> |  | ||||||
| #include <furi-hal.h> |  | ||||||
| #include <stm32wbxx_ll_utils.h> |  | ||||||
| 
 |  | ||||||
| static FuriHalSpiDevice* u8g2_periphery_display = NULL; |  | ||||||
| 
 |  | ||||||
| uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { |  | ||||||
|     switch(msg) { |  | ||||||
|     case U8X8_MSG_GPIO_AND_DELAY_INIT: |  | ||||||
|         /* HAL initialization contains all what we need so we can skip this part. */ |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_MILLI: |  | ||||||
|         LL_mDelay(arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_10MICRO: |  | ||||||
|         LL_mDelay(1); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_100NANO: |  | ||||||
|         asm("nop"); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_GPIO_RESET: |  | ||||||
|         hal_gpio_write(&gpio_display_rst, arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     default: |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { |  | ||||||
|     switch(msg) { |  | ||||||
|     case U8X8_MSG_BYTE_SEND: |  | ||||||
|         furi_hal_spi_bus_tx(u8g2_periphery_display->bus, (uint8_t*)arg_ptr, arg_int, 10000); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_SET_DC: |  | ||||||
|         hal_gpio_write(&gpio_display_di, arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_INIT: |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_START_TRANSFER: |  | ||||||
|         assert(u8g2_periphery_display == NULL); |  | ||||||
|         u8g2_periphery_display = |  | ||||||
|             (FuriHalSpiDevice*)furi_hal_spi_device_get(FuriHalSpiDeviceIdDisplay); |  | ||||||
|         hal_gpio_write(u8g2_periphery_display->chip_select, false); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_END_TRANSFER: |  | ||||||
|         assert(u8g2_periphery_display); |  | ||||||
|         hal_gpio_write(u8g2_periphery_display->chip_select, true); |  | ||||||
|         furi_hal_spi_device_return(u8g2_periphery_display); |  | ||||||
|         u8g2_periphery_display = NULL; |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     default: |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| @ -11,7 +11,9 @@ | |||||||
| 
 | 
 | ||||||
| #include <lib/toolbox/version.h> | #include <lib/toolbox/version.h> | ||||||
| #include <furi-hal.h> | #include <furi-hal.h> | ||||||
|  | 
 | ||||||
| #include <u8g2.h> | #include <u8g2.h> | ||||||
|  | #include <u8g2_glue.h> | ||||||
| 
 | 
 | ||||||
| const uint8_t I_DFU_128x50[] = { | const uint8_t I_DFU_128x50[] = { | ||||||
|     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, |     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, | ||||||
| @ -81,9 +83,6 @@ const uint8_t I_DFU_128x50[] = { | |||||||
| 
 | 
 | ||||||
| #define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) | #define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) | ||||||
| 
 | 
 | ||||||
| uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); |  | ||||||
| uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); |  | ||||||
| 
 |  | ||||||
| void target_led_control(char* c) { | void target_led_control(char* c) { | ||||||
|     furi_hal_light_set(LightRed, 0x00); |     furi_hal_light_set(LightRed, 0x00); | ||||||
|     furi_hal_light_set(LightGreen, 0x00); |     furi_hal_light_set(LightGreen, 0x00); | ||||||
| @ -190,7 +189,7 @@ void target_display_init() { | |||||||
|     hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); |     hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); | ||||||
|     // Initialize
 |     // Initialize
 | ||||||
|     u8g2_t fb; |     u8g2_t fb; | ||||||
|     u8g2_Setup_st7565_erc12864_alt_f(&fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); |     u8g2_Setup_st756x_erc(&fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); | ||||||
|     u8g2_InitDisplay(&fb); |     u8g2_InitDisplay(&fb); | ||||||
|     u8g2_SetContrast(&fb, 36); |     u8g2_SetContrast(&fb, 36); | ||||||
|     // Create payload
 |     // Create payload
 | ||||||
|  | |||||||
| @ -1,7 +1,20 @@ | |||||||
| #include <furi-hal.h> | #include <furi-hal.h> | ||||||
|  | #include <stm32wbxx_ll_utils.h> | ||||||
| 
 | 
 | ||||||
| void furi_hal_init() { | void furi_hal_init() { | ||||||
|     furi_hal_i2c_init(); |     furi_hal_i2c_init(); | ||||||
|     furi_hal_light_init(); |     furi_hal_light_init(); | ||||||
|     furi_hal_spi_init(); |     furi_hal_spi_init(); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void delay(float milliseconds) { | ||||||
|  |     LL_mDelay((uint32_t)milliseconds); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void delay_us(float microseconds) { | ||||||
|  |     microseconds = microseconds / 1000; | ||||||
|  |     if(microseconds < 1) { | ||||||
|  |         microseconds = 1; | ||||||
|  |     } | ||||||
|  |     LL_mDelay((uint32_t)microseconds); | ||||||
|  | } | ||||||
|  | |||||||
| @ -5,4 +5,10 @@ | |||||||
| #include <furi-hal-resources.h> | #include <furi-hal-resources.h> | ||||||
| #include <furi-hal-spi.h> | #include <furi-hal-spi.h> | ||||||
| 
 | 
 | ||||||
|  | #define furi_assert(value) (void)(value) | ||||||
|  | 
 | ||||||
| void furi_hal_init(); | void furi_hal_init(); | ||||||
|  | 
 | ||||||
|  | void delay(float milliseconds); | ||||||
|  | 
 | ||||||
|  | void delay_us(float microseconds); | ||||||
|  | |||||||
| @ -1,69 +0,0 @@ | |||||||
| #include <u8g2.h> |  | ||||||
| #include <assert.h> |  | ||||||
| #include <furi-hal.h> |  | ||||||
| #include <stm32wbxx_ll_utils.h> |  | ||||||
| 
 |  | ||||||
| static FuriHalSpiDevice* u8g2_periphery_display = NULL; |  | ||||||
| 
 |  | ||||||
| uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { |  | ||||||
|     switch(msg) { |  | ||||||
|     case U8X8_MSG_GPIO_AND_DELAY_INIT: |  | ||||||
|         /* HAL initialization contains all what we need so we can skip this part. */ |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_MILLI: |  | ||||||
|         LL_mDelay(arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_10MICRO: |  | ||||||
|         LL_mDelay(1); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_DELAY_100NANO: |  | ||||||
|         asm("nop"); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_GPIO_RESET: |  | ||||||
|         hal_gpio_write(&gpio_display_rst, arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     default: |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { |  | ||||||
|     switch(msg) { |  | ||||||
|     case U8X8_MSG_BYTE_SEND: |  | ||||||
|         furi_hal_spi_bus_tx(u8g2_periphery_display->bus, (uint8_t*)arg_ptr, arg_int, 10000); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_SET_DC: |  | ||||||
|         hal_gpio_write(&gpio_display_di, arg_int); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_INIT: |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_START_TRANSFER: |  | ||||||
|         assert(u8g2_periphery_display == NULL); |  | ||||||
|         u8g2_periphery_display = |  | ||||||
|             (FuriHalSpiDevice*)furi_hal_spi_device_get(FuriHalSpiDeviceIdDisplay); |  | ||||||
|         hal_gpio_write(u8g2_periphery_display->chip_select, false); |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     case U8X8_MSG_BYTE_END_TRANSFER: |  | ||||||
|         assert(u8g2_periphery_display); |  | ||||||
|         hal_gpio_write(u8g2_periphery_display->chip_select, true); |  | ||||||
|         furi_hal_spi_device_return(u8g2_periphery_display); |  | ||||||
|         u8g2_periphery_display = NULL; |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|     default: |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| @ -11,7 +11,9 @@ | |||||||
| 
 | 
 | ||||||
| #include <lib/toolbox/version.h> | #include <lib/toolbox/version.h> | ||||||
| #include <furi-hal.h> | #include <furi-hal.h> | ||||||
|  | 
 | ||||||
| #include <u8g2.h> | #include <u8g2.h> | ||||||
|  | #include <u8g2_glue.h> | ||||||
| 
 | 
 | ||||||
| const uint8_t I_DFU_128x50[] = { | const uint8_t I_DFU_128x50[] = { | ||||||
|     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, |     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, | ||||||
| @ -81,9 +83,6 @@ const uint8_t I_DFU_128x50[] = { | |||||||
| 
 | 
 | ||||||
| #define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) | #define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) | ||||||
| 
 | 
 | ||||||
| uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); |  | ||||||
| uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); |  | ||||||
| 
 |  | ||||||
| void target_led_control(char* c) { | void target_led_control(char* c) { | ||||||
|     furi_hal_light_set(LightRed, 0x00); |     furi_hal_light_set(LightRed, 0x00); | ||||||
|     furi_hal_light_set(LightGreen, 0x00); |     furi_hal_light_set(LightGreen, 0x00); | ||||||
| @ -190,7 +189,7 @@ void target_display_init() { | |||||||
|     hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); |     hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); | ||||||
|     // Initialize
 |     // Initialize
 | ||||||
|     u8g2_t fb; |     u8g2_t fb; | ||||||
|     u8g2_Setup_st7565_erc12864_alt_f(&fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); |     u8g2_Setup_st756x_erc(&fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); | ||||||
|     u8g2_InitDisplay(&fb); |     u8g2_InitDisplay(&fb); | ||||||
|     u8g2_SetContrast(&fb, 36); |     u8g2_SetContrast(&fb, 36); | ||||||
|     // Create payload
 |     // Create payload
 | ||||||
|  | |||||||
| @ -9,8 +9,7 @@ CFLAGS			+= -I$(LIB_DIR)/mlib | |||||||
| # U8G2 display library
 | # U8G2 display library
 | ||||||
| U8G2_DIR		= $(LIB_DIR)/u8g2 | U8G2_DIR		= $(LIB_DIR)/u8g2 | ||||||
| CFLAGS			+= -I$(U8G2_DIR) | CFLAGS			+= -I$(U8G2_DIR) | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8x8_d_st7565.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_glue.c | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_d_setup.c |  | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_intersection.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_intersection.c | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_setup.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_setup.c | ||||||
| C_SOURCES		+= $(U8G2_DIR)/u8g2_d_memory.c | C_SOURCES		+= $(U8G2_DIR)/u8g2_d_memory.c | ||||||
|  | |||||||
| @ -961,7 +961,6 @@ void u8g2_Setup_st7565_zolen_128x64_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u | |||||||
| void u8g2_Setup_st7565_lm6059_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | void u8g2_Setup_st7565_lm6059_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | ||||||
| void u8g2_Setup_st7565_lx12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | void u8g2_Setup_st7565_lx12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | ||||||
| void u8g2_Setup_st7565_erc12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | void u8g2_Setup_st7565_erc12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | ||||||
| void u8g2_Setup_st7565_erc12864_alt_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); |  | ||||||
| void u8g2_Setup_st7565_nhd_c12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | void u8g2_Setup_st7565_nhd_c12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | ||||||
| void u8g2_Setup_st7565_jlx12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | void u8g2_Setup_st7565_jlx12864_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | ||||||
| void u8g2_Setup_st7565_nhd_c12832_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | void u8g2_Setup_st7565_nhd_c12832_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | ||||||
|  | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										222
									
								
								lib/u8g2/u8g2_glue.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								lib/u8g2/u8g2_glue.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,222 @@ | |||||||
|  | #include "u8g2_glue.h" | ||||||
|  | 
 | ||||||
|  | #include <furi-hal.h> | ||||||
|  | 
 | ||||||
|  | static FuriHalSpiDevice* u8g2_periphery_display = NULL; | ||||||
|  | 
 | ||||||
|  | uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { | ||||||
|  |     switch(msg) { | ||||||
|  |     case U8X8_MSG_GPIO_AND_DELAY_INIT: | ||||||
|  |         /* HAL initialization contains all what we need so we can skip this part. */ | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_DELAY_MILLI: | ||||||
|  |         delay(arg_int); | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_DELAY_10MICRO: | ||||||
|  |         delay_us(10); | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_DELAY_100NANO: | ||||||
|  |         asm("nop"); | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_GPIO_RESET: | ||||||
|  |         hal_gpio_write(&gpio_display_rst, arg_int); | ||||||
|  |         break; | ||||||
|  |     default: | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { | ||||||
|  |     switch(msg) { | ||||||
|  |     case U8X8_MSG_BYTE_SEND: | ||||||
|  |         furi_hal_spi_bus_tx(u8g2_periphery_display->bus, (uint8_t*)arg_ptr, arg_int, 10000); | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_BYTE_SET_DC: | ||||||
|  |         hal_gpio_write(&gpio_display_di, arg_int); | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_BYTE_INIT: | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_BYTE_START_TRANSFER: | ||||||
|  |         furi_assert(u8g2_periphery_display == NULL); | ||||||
|  |         u8g2_periphery_display = | ||||||
|  |             (FuriHalSpiDevice*)furi_hal_spi_device_get(FuriHalSpiDeviceIdDisplay); | ||||||
|  |         hal_gpio_write(u8g2_periphery_display->chip_select, false); | ||||||
|  |         break; | ||||||
|  |     case U8X8_MSG_BYTE_END_TRANSFER: | ||||||
|  |         furi_assert(u8g2_periphery_display); | ||||||
|  |         hal_gpio_write(u8g2_periphery_display->chip_select, true); | ||||||
|  |         furi_hal_spi_device_return(u8g2_periphery_display); | ||||||
|  |         u8g2_periphery_display = NULL; | ||||||
|  |         break; | ||||||
|  |     default: | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static const uint8_t u8x8_d_st7565_powersave0_seq[] = { | ||||||
|  |     U8X8_START_TRANSFER(),              /* enable chip, delay is part of the transfer start */ | ||||||
|  |     U8X8_C(0x0a4),                      /* all pixel off, issue 142 */ | ||||||
|  |     U8X8_C(0x0af),                      /* display on */ | ||||||
|  |     U8X8_END_TRANSFER(),                /* disable chip */ | ||||||
|  |     U8X8_END()                          /* end of sequence */ | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static const uint8_t u8x8_d_st7565_powersave1_seq[] = { | ||||||
|  |     U8X8_START_TRANSFER(),              /* enable chip, delay is part of the transfer start */ | ||||||
|  |     U8X8_C(0x0ae),                      /* display off */ | ||||||
|  |     U8X8_C(0x0a5),                      /* enter powersafe: all pixel on, issue 142 */ | ||||||
|  |     U8X8_END_TRANSFER(),                /* disable chip */ | ||||||
|  |     U8X8_END()                          /* end of sequence */ | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static const uint8_t u8x8_d_st7565_flip0_seq[] = { | ||||||
|  |     U8X8_START_TRANSFER(),              /* enable chip, delay is part of the transfer start */ | ||||||
|  |     U8X8_C(0x0a1),                      /* segment remap a0/a1*/ | ||||||
|  |     U8X8_C(0x0c0),                      /* c0: scan dir normal, c8: reverse */ | ||||||
|  |     U8X8_END_TRANSFER(),                /* disable chip */ | ||||||
|  |     U8X8_END()                          /* end of sequence */ | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static const uint8_t u8x8_d_st7565_flip1_seq[] = { | ||||||
|  |     U8X8_START_TRANSFER(),              /* enable chip, delay is part of the transfer start */ | ||||||
|  |     U8X8_C(0x0a0),                      /* segment remap a0/a1*/ | ||||||
|  |     U8X8_C(0x0c8),                      /* c0: scan dir normal, c8: reverse */ | ||||||
|  |     U8X8_END_TRANSFER(),                /* disable chip */ | ||||||
|  |     U8X8_END()                          /* end of sequence */ | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static const u8x8_display_info_t u8x8_st756x_128x64_display_info = { | ||||||
|  |     .chip_enable_level = 0, | ||||||
|  |     .chip_disable_level = 1, | ||||||
|  |     .post_chip_enable_wait_ns = 150,    /* st7565 datasheet, table 26, tcsh */ | ||||||
|  |     .pre_chip_disable_wait_ns = 50,     /* st7565 datasheet, table 26, tcss */ | ||||||
|  |     .reset_pulse_width_ms = 1, | ||||||
|  |     .post_reset_wait_ms = 1, | ||||||
|  |     .sda_setup_time_ns = 50,            /* st7565 datasheet, table 26, tsds */ | ||||||
|  |     .sck_pulse_width_ns = 120,          /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */ | ||||||
|  |     .sck_clock_hz = 4000000UL,          /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be  1000000000/sck_pulse_width_ns */ | ||||||
|  |     .spi_mode = 0,                      /* active high, rising edge */ | ||||||
|  |     .i2c_bus_clock_100kHz = 4, | ||||||
|  |     .data_setup_time_ns = 40,           /* st7565 datasheet, table 24, tds8 */ | ||||||
|  |     .write_pulse_width_ns = 80,         /* st7565 datasheet, table 24, tcclw */ | ||||||
|  |     .tile_width = 16,                   /* width of 16*8=128 pixel */ | ||||||
|  |     .tile_height = 8, | ||||||
|  |     .default_x_offset = 0, | ||||||
|  |     .flipmode_x_offset = 4, | ||||||
|  |     .pixel_width = 128, | ||||||
|  |     .pixel_height = 64 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | uint8_t u8x8_d_st7565_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { | ||||||
|  |     uint8_t x, c; | ||||||
|  |     uint8_t *ptr; | ||||||
|  | 
 | ||||||
|  |     switch(msg) { | ||||||
|  |         case U8X8_MSG_DISPLAY_DRAW_TILE: | ||||||
|  |             u8x8_cad_StartTransfer(u8x8); | ||||||
|  | 
 | ||||||
|  |             x = ((u8x8_tile_t *)arg_ptr)->x_pos; | ||||||
|  |             x *= 8; | ||||||
|  |             x += u8x8->x_offset; | ||||||
|  |             u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) ); | ||||||
|  |             u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15))); | ||||||
|  |             u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos)); | ||||||
|  | 
 | ||||||
|  |             c = ((u8x8_tile_t *)arg_ptr)->cnt; | ||||||
|  |             c *= 8; | ||||||
|  |             ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; | ||||||
|  |             /* 
 | ||||||
|  |                 The following if condition checks the hardware limits of the st7565  | ||||||
|  |                 controller: It is not allowed to write beyond the display limits. | ||||||
|  |                 This is in fact an issue within flip mode. | ||||||
|  |             */ | ||||||
|  |             if ( c + x > 132u ) { | ||||||
|  |                 c = 132u; | ||||||
|  |                 c -= x; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             do { | ||||||
|  |                 u8x8_cad_SendData(u8x8, c, ptr);    /* note: SendData can not handle more than 255 bytes */ | ||||||
|  |                 arg_int--; | ||||||
|  |             } while( arg_int > 0 ); | ||||||
|  | 
 | ||||||
|  |             u8x8_cad_EndTransfer(u8x8); | ||||||
|  |             break; | ||||||
|  |         case U8X8_MSG_DISPLAY_SET_POWER_SAVE: | ||||||
|  |             if ( arg_int == 0 ) | ||||||
|  |                 u8x8_cad_SendSequence(u8x8, u8x8_d_st7565_powersave0_seq); | ||||||
|  |             else | ||||||
|  |                 u8x8_cad_SendSequence(u8x8, u8x8_d_st7565_powersave1_seq); | ||||||
|  |             break; | ||||||
|  | #ifdef U8X8_WITH_SET_CONTRAST | ||||||
|  |         case U8X8_MSG_DISPLAY_SET_CONTRAST: | ||||||
|  |             u8x8_cad_StartTransfer(u8x8); | ||||||
|  |             u8x8_cad_SendCmd(u8x8, 0x081 ); | ||||||
|  |             u8x8_cad_SendArg(u8x8, arg_int >> 2 );  /* st7565 has range from 0 to 63 */ | ||||||
|  |             u8x8_cad_EndTransfer(u8x8); | ||||||
|  |             break; | ||||||
|  | #endif | ||||||
|  |         default: | ||||||
|  |             return 0; | ||||||
|  |     } | ||||||
|  |     return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static const uint8_t u8x8_d_st756x_erc_init_seq[] = { | ||||||
|  |     U8X8_START_TRANSFER(), | ||||||
|  |     U8X8_C(0x0e2),        // soft reset
 | ||||||
|  |     U8X8_C(0xA3),         // CMD_SET_BIAS_7
 | ||||||
|  |     U8X8_C(0xA0),         // CMD_SET_ADC_NORMAL
 | ||||||
|  |     U8X8_C(0xC8),         // CMD_SET_COM_REVERSE
 | ||||||
|  |     U8X8_C(0x40),         // CMD_SET_DISP_START_LINE
 | ||||||
|  |     U8X8_C(0x28 | 0x4),   // CMD_SET_POWER_CONTROL | 0x4
 | ||||||
|  |     U8X8_DLY(50),  | ||||||
|  |     U8X8_C(0x28 | 0x6),   // CMD_SET_POWER_CONTROL | 0x6
 | ||||||
|  |     U8X8_DLY(50),  | ||||||
|  |     U8X8_C(0x28 | 0x7),   // CMD_SET_POWER_CONTROL | 0x7
 | ||||||
|  |     U8X8_DLY(50),  | ||||||
|  |     U8X8_C(0x20 | 0x6),   // CMD_SET_RESISTOR_RATIO | 0x6
 | ||||||
|  |     U8X8_END_TRANSFER(), | ||||||
|  |     U8X8_END()            // end of sequence
 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | uint8_t u8x8_d_st756x_erc(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { | ||||||
|  |     /* call common procedure first and handle messages there */ | ||||||
|  |     if (u8x8_d_st7565_common(u8x8, msg, arg_int, arg_ptr) == 0) { | ||||||
|  |         /* msg not handled, then try here */ | ||||||
|  |         switch(msg){ | ||||||
|  |             case U8X8_MSG_DISPLAY_SETUP_MEMORY: | ||||||
|  |             u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st756x_128x64_display_info); | ||||||
|  |             break; | ||||||
|  |         case U8X8_MSG_DISPLAY_INIT: | ||||||
|  |             u8x8_d_helper_display_init(u8x8); | ||||||
|  |             u8x8_cad_SendSequence(u8x8, u8x8_d_st756x_erc_init_seq); | ||||||
|  |             break; | ||||||
|  |         case U8X8_MSG_DISPLAY_SET_FLIP_MODE: | ||||||
|  |             if ( arg_int == 0 ) { | ||||||
|  |                 u8x8_cad_SendSequence(u8x8, u8x8_d_st7565_flip1_seq); | ||||||
|  |                 u8x8->x_offset = u8x8->display_info->default_x_offset; | ||||||
|  |             } else { | ||||||
|  |                 u8x8_cad_SendSequence(u8x8, u8x8_d_st7565_flip0_seq); | ||||||
|  |                 u8x8->x_offset = u8x8->display_info->flipmode_x_offset; | ||||||
|  |             }    | ||||||
|  |             break; | ||||||
|  |         default: | ||||||
|  |             /* msg unknown */ | ||||||
|  |             return 0; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void u8g2_Setup_st756x_erc(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb) { | ||||||
|  |     uint8_t tile_buf_height; | ||||||
|  |     uint8_t *buf; | ||||||
|  |     u8g2_SetupDisplay(u8g2, u8x8_d_st756x_erc, u8x8_cad_001, byte_cb, gpio_and_delay_cb); | ||||||
|  |     buf = u8g2_m_16_8_f(&tile_buf_height); | ||||||
|  |     u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation); | ||||||
|  | } | ||||||
							
								
								
									
										9
									
								
								lib/u8g2/u8g2_glue.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								lib/u8g2/u8g2_glue.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include "u8g2.h" | ||||||
|  | 
 | ||||||
|  | uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); | ||||||
|  | 
 | ||||||
|  | uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); | ||||||
|  | 
 | ||||||
|  | void u8g2_Setup_st756x_erc(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 あく
						あく