compile/run ok, issue with backlight
This commit is contained in:
@@ -3,15 +3,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <flipper.h>
|
||||
#include <u8g2.h>
|
||||
|
||||
struct Canvas {
|
||||
u8g2_t fb;
|
||||
uint8_t offset_x;
|
||||
uint8_t offset_y;
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
};
|
||||
|
||||
uint8_t canvas_width(CanvasApi* api);
|
||||
uint8_t canvas_height(CanvasApi* api);
|
||||
@@ -20,14 +11,20 @@ void canvas_color_set(CanvasApi* api, uint8_t color);
|
||||
void canvas_font_set(CanvasApi* api, Font font);
|
||||
void canvas_str_draw(CanvasApi* api, uint8_t x, uint8_t y, const char* str);
|
||||
|
||||
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);
|
||||
|
||||
CanvasApi* canvas_api_init() {
|
||||
CanvasApi* api = furi_alloc(sizeof(CanvasApi));
|
||||
|
||||
u8g2_t _u8g2;
|
||||
u8g2_Setup_st7565_erc12864_alt_f(
|
||||
&api->canvas.fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32);
|
||||
u8g2_InitDisplay(
|
||||
&canvas->fb); // send init sequence to the display, display is in sleep mode after this
|
||||
&api->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
|
||||
u8g2_InitDisplay(&api->canvas.fb);
|
||||
u8g2_SetContrast(&api->canvas.fb, 36);
|
||||
|
||||
u8g2_SetPowerSave(&api->canvas.fb, 0); // wake up display
|
||||
@@ -36,14 +33,13 @@ CanvasApi* canvas_api_init() {
|
||||
api->width = canvas_width;
|
||||
api->height = canvas_height;
|
||||
api->clear = canvas_clear;
|
||||
api->canvas_color_set = canvas_color_set;
|
||||
api->canvas_font_set = canvas_font_set;
|
||||
api->set_color = canvas_color_set;
|
||||
api->set_font = canvas_font_set;
|
||||
api->draw_str = canvas_str_draw;
|
||||
|
||||
api->fonts = {
|
||||
.primary = u8g2_font_Born2bSportyV2_tr,
|
||||
.secondary = u8g2_font_HelvetiPixel_tr,
|
||||
};
|
||||
api->fonts = furi_alloc(sizeof(Fonts));
|
||||
api->fonts->primary = u8g2_font_Born2bSportyV2_tr;
|
||||
api->fonts->secondary = u8g2_font_HelvetiPixel_tr;
|
||||
|
||||
return api;
|
||||
}
|
||||
|
@@ -1,25 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <u8g2.h>
|
||||
|
||||
typedef enum {
|
||||
ColorWhite = 0x00,
|
||||
ColorBlack = 0x01,
|
||||
} Color;
|
||||
|
||||
typedef struct Canvas Canvas;
|
||||
typedef const uint8_t* Font;
|
||||
|
||||
struct _CanvasApi;
|
||||
|
||||
typedef struct _CanvasApi CanvasApi;
|
||||
|
||||
typedef struct {
|
||||
Font primary;
|
||||
Font secondary;
|
||||
} Fonts;
|
||||
|
||||
struct {
|
||||
struct _CanvasApi;
|
||||
|
||||
typedef struct _CanvasApi CanvasApi;
|
||||
|
||||
// Canvas is private but we need its declaration here
|
||||
typedef struct {
|
||||
u8g2_t fb;
|
||||
uint8_t offset_x;
|
||||
uint8_t offset_y;
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
} Canvas;
|
||||
|
||||
struct _CanvasApi {
|
||||
Canvas canvas;
|
||||
Fonts* fonts;
|
||||
|
||||
@@ -28,8 +37,8 @@ struct {
|
||||
|
||||
void (*clear)(CanvasApi* canvas);
|
||||
|
||||
void (*canvas_color_set)(CanvasApi* canvas, Color color);
|
||||
void (*canvas_font_set)(CanvasApi* canvas, Font font);
|
||||
void (*set_color)(CanvasApi* canvas, Color color);
|
||||
void (*set_font)(CanvasApi* canvas, Font font);
|
||||
|
||||
void (*draw_str)(CanvasApi* canvas, uint8_t x, uint8_t y, const char* str);
|
||||
} _CanvasApi;
|
||||
};
|
||||
|
@@ -4,10 +4,10 @@ CanvasApi* canvas_api_init();
|
||||
|
||||
void canvas_api_free(CanvasApi* api);
|
||||
|
||||
void canvas_commit(Canvas* canvas);
|
||||
void canvas_commit(CanvasApi* api);
|
||||
|
||||
void canvas_frame_set(
|
||||
Canvas* canvas,
|
||||
CanvasApi* api,
|
||||
uint8_t offset_x,
|
||||
uint8_t offset_y,
|
||||
uint8_t width,
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "gui_i.h"
|
||||
|
||||
#include <flipper.h>
|
||||
#include <flipper_v2.h>
|
||||
#include <stdio.h>
|
||||
#include <m-array.h>
|
||||
|
||||
@@ -22,36 +23,40 @@ struct Gui {
|
||||
WidgetArray_t widgets_dialog;
|
||||
};
|
||||
|
||||
void gui_add_widget(Gui* gui, Widget* widget, WidgetLayer layer) {
|
||||
void gui_add_widget(GuiApi* gui_api, Widget* widget, WidgetLayer layer) {
|
||||
assert(gui_api);
|
||||
assert(gui_api->gui);
|
||||
|
||||
// TODO add mutex on widget array
|
||||
|
||||
WidgetArray_t* widget_array = NULL;
|
||||
|
||||
switch(layer) {
|
||||
case WidgetLayerStatusBar:
|
||||
widget_array = &gui->widgets_status_bar;
|
||||
widget_array = &gui_api->gui->widgets_status_bar;
|
||||
break;
|
||||
case WidgetLayerMain:
|
||||
widget_array = &gui->widgets;
|
||||
widget_array = &gui_api->gui->widgets;
|
||||
break;
|
||||
case WidgetLayerFullscreen:
|
||||
widget_array = &gui->widgets_fs;
|
||||
widget_array = &gui_api->gui->widgets_fs;
|
||||
break;
|
||||
case WidgetLayerDialog:
|
||||
widget_array = &gui->widgets_dialog;
|
||||
widget_array = &gui_api->gui->widgets_dialog;
|
||||
break;
|
||||
|
||||
default:
|
||||
default: break;
|
||||
}
|
||||
|
||||
assert(gui);
|
||||
assert(widget);
|
||||
assert(widget_array);
|
||||
|
||||
gui_event_lock(gui->event);
|
||||
WidgetArray_push_back(widget_array, widget);
|
||||
widget_gui_set(widget, gui);
|
||||
gui_event_unlock(gui->event);
|
||||
gui_event_lock(gui_api->gui->event);
|
||||
WidgetArray_push_back((struct WidgetArray_s*)widget_array, widget);
|
||||
widget_gui_set(widget, gui_api->gui);
|
||||
gui_event_unlock(gui_api->gui->event);
|
||||
|
||||
gui_update(gui);
|
||||
gui_update(gui_api->gui);
|
||||
}
|
||||
|
||||
void gui_update(Gui* gui) {
|
||||
@@ -110,7 +115,7 @@ void gui_redraw(Gui* gui) {
|
||||
}
|
||||
gui_redraw_dialogs(gui);
|
||||
|
||||
canvas_commit(gui->canvas);
|
||||
canvas_commit(gui->canvas_api);
|
||||
}
|
||||
|
||||
void gui_input(Gui* gui, InputEvent* input_event) {
|
||||
|
@@ -13,7 +13,10 @@ typedef enum {
|
||||
typedef struct Widget Widget;
|
||||
typedef struct Gui Gui;
|
||||
|
||||
typedef struct {
|
||||
void (*add_widget)(Gui* gui, Widget* widget, WidgetLayer layer);
|
||||
struct _GuiApi;
|
||||
typedef struct _GuiApi GuiApi;
|
||||
|
||||
struct _GuiApi {
|
||||
void (*add_widget)(GuiApi* gui_api, Widget* widget, WidgetLayer layer);
|
||||
Gui* gui;
|
||||
} GuiApi;
|
||||
};
|
||||
|
@@ -7,6 +7,8 @@
|
||||
#include "gui.h"
|
||||
#include "gui_i.h"
|
||||
|
||||
// TODO add mutex to widget ops
|
||||
|
||||
struct Widget {
|
||||
void* gui;
|
||||
bool is_enabled;
|
||||
@@ -14,7 +16,7 @@ struct Widget {
|
||||
void* draw_callback_context;
|
||||
WidgetInputCallback input_callback;
|
||||
void* input_callback_context;
|
||||
}
|
||||
};
|
||||
|
||||
Widget* widget_alloc(WidgetDrawCallback callback, void* callback_context) {
|
||||
Widget* widget = furi_alloc(sizeof(Widget));
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
void widget_gui_set(Widget* widget, Gui* gui);
|
||||
|
||||
void widget_draw(Widget* widget, Canvas* canvas);
|
||||
void widget_draw(Widget* widget, CanvasApi* canvas_api);
|
||||
|
||||
void widget_input(Widget* widget, InputEvent* event);
|
||||
|
Reference in New Issue
Block a user