码迷,mamicode.com
首页 > 其他好文 > 详细

RT-Thread 学习笔记(十二)--- 开启基于RTGUI的LCD显示功能(2)

时间:2015-04-11 17:59:46      阅读:639      评论:0      收藏:0      [点我收藏+]

标签:rt-thread   rtgui   

软件环境:Win7,Keil MDK 4.72a, IAR EWARM 7.2, GCC 4.2,Python 2.7 ,SCons 2.3.2

硬件环境:Armfly STM32F103ZE-EK v3.0开发板

参考文章:RT-Thread编程指南

RT-Thread_1.2.0+lwip+rtgui0.8.0 移植心得

RT-Thread RTOS组件:RTGUI教程 Hello World

上篇文章中我们LCD驱动进行了移植,接下来进行编译和调试

【1】在命令行中使用scons编译,出现“命令太长”的错误

看到Link时命令行太长的错误,如下图。

技术分享

参考文章修正scons编译时armlink链接错误的解决办法:

(1) 使用Notepad++打开C:\Python27\Lib\site-packages\scons-2.3.2\SCons\Platform\__init__.py,定位到205行,修改如下代码:

prefix = env.subst(‘$TEMPFILEPREFIX‘)
if not prefix:
    #prefix = ‘@‘
    prefix = ‘ ‘

修改后保存。

(2)使用Notepad++打开stm32f103ze-ek/Sconstruct文件,定位到27行附近,如入如下代码:

if rtconfig.PLATFORM == ‘iar‘:
env.Replace(CCCOM = [‘$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES‘])
env.Replace(ARFLAGS = [‘‘])
env.Replace(LINKCOM = [‘$LINK $SOURCES $LINKFLAGS -o $TARGET --map project.map‘])

if rtconfig.PLATFORM == ‘armcc‘:
env["TEMPFILE"] = SCons.Platform.TempFileMunge
# env["LINKCOM"] = "${TEMPFILE(‘$LINK -o $TARGET $SOURCES‘)}"
env["LINKCOM"] = "$LINK -o $TARGET $LINKFLAGS ${TEMPFILE(‘--via $SOURCES‘)}"
env["TEMPFILEPREFIX"] = ‘ ‘ # arm tool chain


Export(‘RTT_ROOT‘)
Export(‘rtconfig‘)

... ...

修改完成后保存。

然后重新scons编译,结果如下:

技术分享


【2】RTGUI运行测试

将编译生成的代码下载到开发板中,复位运行,终端中显示如下:

\ | /
- RT - Thread Operating System
/ | \ 1.2.2 build Apr 10 2015
2006 - 2013 Copyright by rt-thread team
found part[0], begin: 219152384, size: 1.690GB
dm9000 id: 0x90000a46
finsh />operating at 100M full duplex mode
lwIP-1.4.1 initialized!
RTGUI: could not open the font file:/resource/hzk16.fnt
RTGUI: please mount the fs first and make sure the file is there

set font size to 16
W25Q64BV or W25Q64CV detection
flash0 mount to /.
sd0 mount to /dev.
... ...
hard fault on thread: init

thread pri status sp stack size max used left tick error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
... ...

很显然,挂载的根目录下面根本没有/resource/hzk16.fnt文件,所以报错,因为字库占空间较大,所以目前还无法支持汉字功能。打开rtconfig.h文件,定位到173行附近,注释掉RTGUI_USING_FONTHZ定义,修改如下:

/* SECTION: RT-Thread/GUI */
#define RT_USING_RTGUI

/* name length of RTGUI object */
#define RTGUI_NAME_MAX 12
/* support 16 weight font */
#define RTGUI_USING_FONT16
/* support Chinese font */
//#define RTGUI_USING_FONTHZ
/* use DFS as file interface */
#define RTGUI_USING_DFS_FILERW
/* use font file as Chinese font */
#define RTGUI_USING_HZ_FILE
/* use Chinese bitmap font */
#define RTGUI_USING_HZ_BMP
/* use small size in RTGUI */
#define RTGUI_USING_SMALL_SIZE

调试跟踪发现,在执行_graphic_driver_vmode_init()时,导致init进程崩溃,跟进这个函数,发现在执行rt_memset()时导致init进程崩溃。打开rtgui/server/driver.c,定位到46行附近,注释掉rt_memset()这个函数,代码修改如下:

static void _graphic_driver_vmode_init(void)
{
	if (_vfb_driver.width != _driver.width || _vfb_driver.height != _driver.height)
	{
		if (_vfb_driver.framebuffer != RT_NULL) rtgui_free((void*)_vfb_driver.framebuffer);

		_vfb_driver.device = RT_NULL;
		_vfb_driver.pixel_format = RTGUI_VFB_PIXEL_FMT;
		_vfb_driver.bits_per_pixel = rtgui_color_get_bits(RTGUI_VFB_PIXEL_FMT);
		_vfb_driver.width  = _driver.width;
		_vfb_driver.height = _driver.height;
		_vfb_driver.pitch  = _driver.width * _UI_BITBYTES(_vfb_driver.bits_per_pixel);
		_vfb_driver.framebuffer = rtgui_malloc(_vfb_driver.height * _vfb_driver.pitch);
                //rt_memset(_vfb_driver.framebuffer, 0, _vfb_driver.height * _vfb_driver.pitch);
		_vfb_driver.ext_ops = RT_NULL;
		_vfb_driver.ops = rtgui_framebuffer_get_ops(_vfb_driver.pixel_format);
	}
}

修改后保存,重新编译下载,复位运行,此时终端显示

finsh />list_thread()
 thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
rtgui    0x0f suspend 0x000000f8 0x00000400 0x000000f8 0x00000005 000
tshell   0x14 ready   0x00000090 0x00000800 0x000001b0 0x00000008 -04
tidle    0x1f ready   0x0000005c 0x00000100 0x00000064 0x0000001f 000
led      0x14 suspend 0x00000078 0x00000200 0x00000078 0x00000005 000
        0, 0x00000000
finsh />

信息显示rtgui线程处于挂起状态,下面将加载一些Demo程序进行测试。

【3】加入RTGUI Demo例程

(1)将github网站的RTGUI-Master/demo/examples复制到rt-thread-1.2.2/components/rtgui目录下,然后在命令行运行scons --tartget=mdk4 -s,重新打开工程后可以看到gui-examples组已经加入进来,如下图:

技术分享

(2)打开application.c,定位到129行附近,加入gui_appplication_init(),修改如下:

... ...

#ifdef RT_USING_RTGUI
{
extern void rt_hw_lcd_init();
extern void rtgui_touch_hw_init(void);
extern void gui_application_init(void);
rt_device_t lcd;

/* init lcd */
rt_hw_lcd_init();

... ...

#ifdef RTGUI_USING_CALIBRATION
calibration_set_restore(cali_setup);
calibration_set_after(cali_store);
calibration_init();
#endif /* #ifdef RTGUI_USING_CALIBRATION */
gui_application_init();
}
#endif /* RT_USING_RTGUI */

(3)打开gui_examples工作组下dem_application.c,定位到129行附近,代码修改如下:

void gui_application_init(void)
{
static rt_bool_t inited = RT_FALSE;

if (inited == RT_FALSE) /*避免重复初始化 */
{
rt_thread_t tid;

tid = rt_thread_create("wb",
gui_application_entry, RT_NULL,
2048 * 2, 25, 10);

if (tid != RT_NULL)
rt_thread_startup(tid);

inited = RT_TRUE;
}
}

#ifdef RT_USING_FINSH
#include <finsh.h>
void gui_application()
{
gui_application_init();
}
/* finsh 终端可以执行gui_appplication() 命令运行上面函数*/
FINSH_FUNCTION_EXPORT(gui_application, gui application demo)
#endif

然后再定位到31行附近,将gui_appliction线程入口的名字改过来,修改如下:

... ...

struct rtgui_win *main_win;
static void gui_application_entry(void *parameter)
{
struct rtgui_app *app;
struct rtgui_rect rect;

app = rtgui_app_create("gui_demo");
if (app == RT_NULL)
return;
... ...

然后定位到64行到120附近代码,从demo_view_box()开始,直到rtgui_win_show()之间的代码除了留下demo_view_button() ,其它代码注释掉,修改如下:

<pre name="code" class="cpp">rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(the_notebook));

    //demo_view_box();

    /* 初始化各个例子的视图 */
/*		
    demo_view_benchmark();
    demo_view_dc();
#ifdef RTGUI_USING_TTF
    demo_view_ttf();
#endif

#ifndef RTGUI_USING_SMALL_SIZE
    demo_view_dc_buffer();
#endif
    //demo_view_animation();
#ifndef RTGUI_USING_SMALL_SIZE
    demo_view_instrument_panel();
#endif
    //demo_view_buffer_animation();
    demo_view_window();
    demo_view_label();
*/    demo_view_button();
/*    demo_view_checkbox();
    demo_view_progressbar();
    demo_view_scrollbar();
    demo_view_radiobox();
    demo_view_textbox();
    demo_view_listbox();
    demo_view_menu();
    demo_view_listctrl();
    demo_view_combobox();
    demo_view_slider();
    demo_view_notebook();
    demo_view_mywidget();
    demo_plot();
	demo_view_digtube();

#if defined(RTGUI_USING_DFS_FILERW)
	demo_view_edit();
	//demo_view_bmp();
#endif
#if defined(RTGUI_USING_DFS_FILERW)
    demo_fn_view();
#endif

#if 0
#if defined(RTGUI_USING_DFS_FILERW)
    demo_view_image();
#endif
#ifdef RT_USING_MODULE
#if defined(RTGUI_USING_DFS_FILERW)
    demo_view_module();
#endif
#endif
    demo_listview_view();
    demo_listview_icon_view();
#endif
*/
    rtgui_win_show(main_win, RT_FALSE);


然后保存,重新scons编译,下载到开发板上,可以看到如下效果:

技术分享

由于拍摄的原因,实际可左边的四个按钮的前景色应该分别是红色、蓝色、灰色和灰色,是但实际上没有显示出来。而RTGUI默认的背景色是灰色,到此可以基本说明,LCD底层启动可以正常工作了,余下的问题留待后面解决。


                                                 

RT-Thread 学习笔记(十二)--- 开启基于RTGUI的LCD显示功能(2)

标签:rt-thread   rtgui   

原文地址:http://blog.csdn.net/aping_cs_dn/article/details/44963375

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!