add rtthread support

This commit is contained in:
jim 2018-02-22 18:07:22 +08:00
parent 0c87a12324
commit 07c6ee34e6
10 changed files with 392 additions and 31 deletions

Binary file not shown.

View File

@ -19,8 +19,10 @@
*
*/
#include "base/platform.h"
#include "resource.h"
#include "base/platform.h"
ret_t application_init(void);
#ifdef WITH_STM32F103ZE_RAW
#include "button.h"
@ -29,52 +31,34 @@
#include "gui.h"
#include "lcd_driver.h"
#include "led.h"
#include "main_loop/main_loop_stm32_raw.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];
#else
#include "main_loop/main_loop_sdl2.h"
static uint32_t s_heap_mem[2048];
#endif
#ifdef WIN32
#include <windows.h>
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) {
#else
#elif defined(WITH_RT_THREAD)
#include "base/mem.h"
int gui_app_start() {
#else
#include "base/mem.h"
int mem_test() {
char* str = NULL;
char* p[32];
uint32_t i = 0;
str = (char*)mem_alloc(100);
mem_free(str);
for (i = 0; i < ARRAY_SIZE(p); i++) {
p[i] = (char*)MEM_ALLOC(i);
}
for (i = 0; i < ARRAY_SIZE(p); i++) {
MEM_FREE(p[i]);
}
return 0;
}
ret_t application_init(void);
int main(void) {
#endif
platform_init();
platform_prepare();
mem_init(s_heap_mem, sizeof(s_heap_mem));
resource_init();

View File

@ -26,7 +26,7 @@
BEGIN_C_DECLS
ret_t platform_init(void);
ret_t platform_prepare(void);
uint32_t get_time_ms();
END_C_DECLS

135
src/lcd/lcd_rtthread.c Normal file
View File

@ -0,0 +1,135 @@
/**
* File: lcd_rtthread.c
* Author: Li XianJing <xianjimli@hotmail.com>
* Brief: rtthread implemented lcd interface/
*
* Copyright (c) 2018 - 2018 Li XianJing <xianjimli@hotmail.com>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-02-22 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "lcd/lcd_mem.h"
#include "lcd/lcd_rtthread.h"
typedef struct _lcd_rtthread_t {
lcd_t base;
lcd_mem_t* lcd_mem;
struct rtgui_graphic_driver* driver;
} lcd_rtthread_t;
static ret_t lcd_rtthread_begin_frame(lcd_t* lcd, rect_t* dr) {
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
lcd->dirty_rect = dr;
rtt->lcd_mem->pixels = rtt->driver->framebuffer;
return RET_OK;
}
static ret_t lcd_rtthread_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) {
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
mem->stroke_color = lcd->stroke_color;
return lcd_draw_hline(mem, x, y, w);
}
static ret_t lcd_rtthread_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) {
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
mem->stroke_color = lcd->stroke_color;
return lcd_draw_vline(mem, x, y, h);
}
static ret_t lcd_rtthread_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) {
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
mem->stroke_color = lcd->stroke_color;
return lcd_draw_points(mem, points, nr);
}
static ret_t lcd_rtthread_fill_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) {
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
mem->fill_color = lcd->fill_color;
return lcd_fill_rect(mem, x, y, w, h);
}
static ret_t lcd_rtthread_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y) {
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
mem->text_color = lcd->text_color;
mem->fill_color = lcd->fill_color;
return lcd_draw_glyph(mem, glyph, src, x, y);
}
static ret_t lcd_rtthread_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst) {
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
lcd_t* mem = (lcd_t*)(rtt->lcd_mem);
return lcd_draw_image(mem, img, src, dst);
}
static ret_t lcd_rtthread_end_frame(lcd_t* lcd) {
rtgui_rect_t rect;
rect_t* dr = lcd->dirty_rect;
lcd_rtthread_t* rtt = (lcd_rtthread_t*)lcd;
rect.x1 = dr->x;
rect.y1 = dr->y;
rect.x2 = dr->x + dr->w;
rect.y2 = dr->y + dr->w;
rtgui_graphic_driver_screen_update(rtt->driver, &rect);
return RET_OK;
}
static ret_t lcd_rtthread_destroy(lcd_t* lcd) {
(void)lcd;
return RET_OK;
}
lcd_t* lcd_rtthread_init(struct rtgui_graphic_driver* driver) {
int w = 0;
int h = 0;
static lcd_rtthread_t lcd;
lcd_t* base = &(lcd.base);
return_value_if_fail(driver != NULL, NULL);
memset(&lcd, 0x00, sizeof(lcd_rtthread_t));
base->begin_frame = lcd_rtthread_begin_frame;
base->draw_vline = lcd_rtthread_draw_vline;
base->draw_hline = lcd_rtthread_draw_hline;
base->fill_rect = lcd_rtthread_fill_rect;
base->draw_image = lcd_rtthread_draw_image;
base->draw_glyph = lcd_rtthread_draw_glyph;
base->draw_points = lcd_rtthread_draw_points;
base->end_frame = lcd_rtthread_end_frame;
base->destroy = lcd_rtthread_destroy;
base->width = (wh_t)driver->width;
base->height = (wh_t)driver->height;
lcd.driver = driver;
lcd.lcd_mem = (lcd_mem_t*)lcd_mem_create(base->width, base->height, FALSE);
return base;
}

35
src/lcd/lcd_rtthread.h Executable file
View File

@ -0,0 +1,35 @@
/**
* File: lcd_rtthread.h
* Author: Li XianJing <xianjimli@hotmail.com>
* Brief: rtthread implemented lcd interface/
*
* Copyright (c) 2018 - 2018 Li XianJing <xianjimli@hotmail.com>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-02-22 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef LCD_RTT_H
#define LCD_RTT_H
#include "base/lcd.h"
#include "rtgui/driver.h"
BEGIN_C_DECLS
lcd_t* lcd_rtthread_init(struct rtgui_graphic_driver* driver);
END_C_DECLS
#endif/*LCD_RTT_H*/

View File

@ -0,0 +1,139 @@
/**
* file: main_loop_rtthread.c
* author: li xianjing <xianjimli@hotmail.com>
* brief: rtthread implemented main_loop interface
*
* copyright (c) 2018 - 2018 li xianjing <xianjimli@hotmail.com>
*
* this program is distributed in the hope that it will be useful,
* but without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. see the
* license file for more details.
*
*/
/**
* history:
* ================================================================
* 2018-02-17 li xianjing <xianjimli@hotmail.com> created
*
*/
#include "base/timer.h"
#include "rtgui/event.h"
#include "lcd/lcd_rtthread.h"
#include <rtgui/rtgui_system.h>
#include "base/font_manager.h"
#include "base/window_manager.h"
#include "main_loop/main_loop_rtthread.h"
typedef struct _main_loop_rtthread_t {
main_loop_t base;
int w;
int h;
widget_t* wm;
canvas_t canvas;
xy_t touch_x;
xy_t touch_y;
bool_t pressed;
} main_loop_rtthread_t;
static main_loop_rtthread_t loop;
static void dispatch_touch_events(bool_t pressed, xy_t x, xy_t y) {
pointer_event_t event;
widget_t* widget = loop.wm;
loop.touch_x = x;
loop.touch_y = y;
event.button = 0;
event.x = loop.touch_x;
event.y = loop.touch_y;
if (pressed) {
if (loop.pressed) {
event.e.type = EVT_POINTER_MOVE;
} else {
event.e.type = EVT_POINTER_DOWN;
}
loop.pressed = TRUE;
event.pressed = loop.pressed;
widget_on_pointer_down(widget, &event);
} else {
if (loop.pressed) {
loop.pressed = FALSE;
event.e.type = EVT_POINTER_UP;
event.pressed = loop.pressed;
widget_on_pointer_up(widget, &event);
}
}
}
static ret_t main_loop_rtthread_dispatch(main_loop_rtthread_t* loop) {
rt_err_t result;
struct rtgui_event *event;
result = rtgui_recv(event, sizeof(union rtgui_event_generic), 100);
if(result == RT_EOK) {
/*TODO*/
}
return RET_OK;
}
static ret_t main_loop_rtthread_paint(main_loop_rtthread_t* loop) {
canvas_t* c = &(loop->canvas);
return window_manager_paint(loop->wm, c);
}
static ret_t main_loop_rtthread_run(main_loop_t* l) {
main_loop_rtthread_t* loop = (main_loop_rtthread_t*)l;
while (l->running) {
timer_check();
main_loop_rtthread_dispatch(loop);
main_loop_rtthread_paint(loop);
}
return RET_OK;
}
static ret_t main_loop_rtthread_quit(main_loop_t* l) { return RET_OK; }
static ret_t main_loop_rtthread_destroy(main_loop_t* l) {
(void)l;
return RET_OK;
}
main_loop_t* main_loop_rtthread_init(int w, int h) {
lcd_t* lcd = NULL;
widget_t* wm = default_wm();
main_loop_t* base = &(loop.base);
struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default();
return_value_if_fail(driver != NULL, NULL);
memset(&loop, 0x00, sizeof(loop));
base->run = main_loop_rtthread_run;
base->quit = main_loop_rtthread_quit;
base->destroy = main_loop_rtthread_destroy;
loop.wm = wm;
window_manager_resize(wm, driver->width, driver->height);
lcd = lcd_rtthread_init(driver);
canvas_init(&(loop.canvas), lcd, default_fm());
(void)w;
(void)h;
return base;
}
main_loop_t* default_main_loop() { return &loop.base; }

View File

@ -0,0 +1,34 @@
/**
* file: main_loop_rtthread.h
* author: li xianjing <xianjimli@hotmail.com>
* brief: rtthread implemented main_loop interface
*
* copyright (c) 2018 - 2018 li xianjing <xianjimli@hotmail.com>
*
* this program is distributed in the hope that it will be useful,
* but without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. see the
* license file for more details.
*
*/
/**
* history:
* ================================================================
* 2018-02-22 li xianjing <xianjimli@hotmail.com> created
*
*/
#ifndef LFTK_MAIN_LOOP_RTTHREAD_H
#define LFTK_MAIN_LOOP_RTTHREAD_H
#include "base/main_loop.h"
BEGIN_C_DECLS
main_loop_t* main_loop_rtthread_init(int w, int h);
END_C_DECLS
#endif/*LFTK_MAIN_LOOP_RTTHREAD_H*/

View File

@ -22,7 +22,7 @@
#include "base/timer.h"
#include "base/platform.h"
ret_t platform_init() {
ret_t platform_prepare() {
timer_init(get_time_ms);
return RET_OK;

View File

@ -0,0 +1,34 @@
/**
* File: platform_default.c
* Author: Li XianJing <xianjimli@hotmail.com>
* Brief: default platform
*
* Copyright (c) 2018 - 2018 Li XianJing <xianjimli@hotmail.com>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-02-21 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/timer.h"
#include "base/platform.h"
ret_t platform_prepare() {
timer_init(get_time_ms);
return RET_OK;
}
uint32_t get_time_ms() {
/**/
return 0;
}

View File

@ -33,7 +33,7 @@
#include "touch.h"
#include "usart.h"
ret_t platform_init() {
ret_t platform_prepare() {
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
led_init();