From b75065650d2a798175bbeca13996f233cf76fb99 Mon Sep 17 00:00:00 2001 From: xianjimli Date: Wed, 9 May 2018 18:15:24 +0800 Subject: [PATCH] improve for stm32 --- demos/demo1_app.c | 4 ++-- demos/demo_main.c | 33 +++++++++------------------------ src/lcd/lcd_reg.inc | 16 ++++++++-------- 3 files changed, 19 insertions(+), 34 deletions(-) mode change 100644 => 100755 demos/demo_main.c diff --git a/demos/demo1_app.c b/demos/demo1_app.c index aee5f2b8c..5c42491fa 100644 --- a/demos/demo1_app.c +++ b/demos/demo1_app.c @@ -103,7 +103,7 @@ ret_t application_init() { label = label_create(win, 100, 40, 80, 30); widget_set_text(label, L"C enter"); -#ifdef WITH_STM32F103ZE_RAW +#ifdef WITH_STB_FONT widget_use_style(label, "3:center"); #else widget_use_style(label, "5:center-ap"); @@ -117,7 +117,7 @@ ret_t application_init() { widget_set_value(progress_bar, 40); // timer_add(on_timer, progress_bar, 1000); -#ifndef WITH_STM32F103ZE_RAW +#ifndef WITH_STB_FONT progress_bar_set_show_text(progress_bar, TRUE); #endif diff --git a/demos/demo_main.c b/demos/demo_main.c old mode 100644 new mode 100755 index 3f93f0d60..98e012446 --- a/demos/demo_main.c +++ b/demos/demo_main.c @@ -20,45 +20,30 @@ */ #include "tk.h" +#include "base/mem.h" #include "resource.h" #include "base/system_info.h" ret_t application_init(void); -#ifdef WITH_STM32F103ZE_RAW -#include "button.h" -#include "delay.h" -#include "flash.h" -#include "gui.h" -#include "lcd_driver.h" -#include "led.h" -#include "rtc.h" -#include "stdlib.h" -#include "sys.h" -#include "tim.h" -#include "touch.h" -#include "usart.h" -#include "main_loop/main_loop_stm32_raw.h" - -static __align(8) uint32_t s_heap_mem[2048]; -#elif defined(WITH_RT_THREAD) -#include "main_loop/main_loop_rtthread.h" -static uint32_t s_heap_mem[2048]; +#ifndef HAS_STD_MALLOC +#ifndef GUI_HEAP_SIZE +#define GUI_HEAP_SIZE 2048 +#endif/*GUI_HEAP_SIZE*/ +static uint32_t s_heap_mem[GUI_HEAP_SIZE]; #else -#include "main_loop/main_loop_sdl2.h" -static uint32_t s_heap_mem[2048]; -#endif +static uint32_t s_heap_mem[1]; +#endif/*HAS_STD_MALLOC*/ #ifdef USE_GUI_MAIN -#include "base/mem.h" int gui_app_start(void* params) { #elif defined(WIN32) #include int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { #else -#include "base/mem.h" int main(void) { #endif + tk_init(320, 480, s_heap_mem, sizeof(s_heap_mem)); resource_init(); diff --git a/src/lcd/lcd_reg.inc b/src/lcd/lcd_reg.inc index fd5612f24..8865be747 100644 --- a/src/lcd/lcd_reg.inc +++ b/src/lcd/lcd_reg.inc @@ -29,7 +29,7 @@ static ret_t lcd_reg_begin_frame(lcd_t* lcd, rect_t* dirty_rect) { static ret_t lcd_reg_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) { wh_t i = 0; - pixel_t color = to_pixel(lcd->stroke_color); + pixel_t color = color_to_pixel(lcd->stroke_color); set_window_func(x, y, x + w, y); for (i = 0; i < w; i++) { @@ -41,7 +41,7 @@ static ret_t lcd_reg_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) { static ret_t lcd_reg_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) { wh_t i = 0; - pixel_t color = to_pixel(lcd->stroke_color); + pixel_t color = color_to_pixel(lcd->stroke_color); set_window_func(x, y, x, y + h); for (i = 0; i < h; i++) { @@ -53,7 +53,7 @@ static ret_t lcd_reg_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) { static ret_t lcd_reg_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) { wh_t i = 0; - pixel_t color = to_pixel(lcd->stroke_color); + pixel_t color = color_to_pixel(lcd->stroke_color); for (i = 0; i < nr; i++) { point_t* point = points + i; @@ -67,7 +67,7 @@ static ret_t lcd_reg_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) { static ret_t lcd_reg_fill_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) { uint32_t i = 0; uint32_t size = w * h; - pixel_t color = to_pixel(lcd->fill_color); + pixel_t color = color_to_pixel(lcd->fill_color); set_window_func(x, y, x + w - 1, y + h - 1); @@ -97,7 +97,7 @@ static ret_t lcd_reg_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, pixel_t color = blend_color(fill_color, text_color, alpha); write_data_func(color); } else { - write_data_func(to_pixel(fill_color)); + write_data_func(color_to_pixel(fill_color)); } } src_p += glyph->w; @@ -114,7 +114,7 @@ static ret_t lcd_reg_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* wh_t dw = dst->w; wh_t dh = dst->h; color_t fill_color = lcd->fill_color; - pixel_t fill_pixel = to_pixel(fill_color); + pixel_t fill_pixel = color_to_pixel(fill_color); const color_t* data = (color_t*)img->data; if (src->w == dst->w && src->h == dst->h) { @@ -129,7 +129,7 @@ static ret_t lcd_reg_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* if (src_color.rgba.a > 7) { pixel_t color = src_color.rgba.a < 0xfe ? blend_color(fill_color, src_color, src_color.rgba.a) - : to_pixel(src_color); + : color_to_pixel(src_color); write_data_func(color); } else { write_data_func(fill_pixel); @@ -154,7 +154,7 @@ static ret_t lcd_reg_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* if (src_color.rgba.a > 7) { pixel_t color = src_color.rgba.a < 0xfe ? blend_color(fill_color, src_color, src_color.rgba.a) - : to_pixel(src_color); + : color_to_pixel(src_color); set_window_func(x, y, x, y); write_data_func(color);