提交 784e8e24 编写于 作者: B Bernard Xiong

Merge branch 'master' of https://github.com/RT-Thread/rt-thread

RT-Thread
=========
[![Build Status](https://travis-ci.org/RT-Thread/rt-thread.png)](https://travis-ci.org/RT-Thread/rt-thread)
RT-Thread is an open source real-time operating system for embedded devices.
......@@ -12,14 +12,14 @@ if os.getenv('RTT_RTGUI'):
else:
# set the rtgui root directory by hand
# empty string means use the RTGUI in svn
# RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui')
RTT_RTGUI =''
RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui')
# RTT_RTGUI =''
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
env = Environment()
env = Environment(TARGET_ARCH='x86')
Export('RTT_ROOT')
Export('rtconfig')
......@@ -51,13 +51,34 @@ if rtconfig.PLATFORM == 'cl':
env.Append(LINKFLAGS=rtconfig.LFLAGS)
env['LIBS']=libs
env['CPPDEFINES']=definitions
elif rtconfig.PLATFORM == 'mingw':
libs = Split('''
winmm
gdi32
winspool
comdlg32
advapi32
shell32
ole32
oleaut32
uuid
odbc32
odbccp32
''')
TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env['LIBS']=libs
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
else:
TARGET = 'rtthread'
env.Append(CCFLAGS=rtconfig.CFLAGS)
env.Append(LINKFLAGS=rtconfig.LFLAGS)
env.Append(LIBS=['m'])
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False, remove_components=['rtgui'])
......@@ -85,8 +106,42 @@ if GetDepend('RT_USING_RTGUI'):
if GetDepend('RT_USING_TC'):
objs = objs + SConscript(RTT_ROOT + '/examples/kernel/SConscript', variant_dir = 'build/tc/kernel', duplicate=0)
# build program
program = env.Program(TARGET, objs)
def ObjRemove(objs, remove):
for item in objs:
# print type(item), os.path.basename(str(item))
if os.path.basename(str(item)) in remove:
objs.remove(item)
return
# build program -shared
if GetDepend('RT_USING_MODULE'):
# Remove module.c in $RTT_ROOT/src
ObjRemove(objs, ['module.obj', 'module.o'])
AddOption('--def',
dest='def',
action='store_true',
default=False,
help='create rthread.def of rtthread.dll on windows')
if GetOption('def'):
if rtconfig.PLATFORM != 'mingw':
print "scons error: `--def' can only work with mingw"
exit(1)
env['LINKFLAGS'] = rtconfig.DEFFILE_LFLAGS
env.SharedLibrary("rtthread.dll", objs)
program = ''
else:
if rtconfig.PLATFORM == 'cl':
objs += ['rtthread.def']
elif rtconfig.PLATFORM == 'mingw':
rtconfig.POST_ACTION = 'del /Q rtthread.lib \n rename librtthread.a rtthread.lib\n'
# rtconfig.POST_ACTION = 'lib /machine:i386 /def:rtthread.def /out:rtthread.lib'
env.SharedLibrary("rtthread.dll", objs)
program = env.Program(TARGET, 'dummy.c', LIBS='rtthread', LIBPATH='.')
else:
program = env.Program(TARGET, objs)
# end building
EndBuilding(TARGET, program)
......@@ -6,6 +6,8 @@ src = Glob('*.c')
# remove no need file.
if GetDepend('RT_USING_DFS_WINSHAREDIR') == False:
SrcRemove(src, 'dfs_win32.c')
if GetDepend('RT_USING_MODULE') == False:
SrcRemove(src, ['module_win32.c'])
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
......
......@@ -25,11 +25,11 @@ void rt_init_thread_entry(void *parameter)
pcap_netif_hw_init();
#endif
rt_platform_init();
/* initialization RT-Thread Components */
rt_components_init();
rt_platform_init();
/* File system Initialization */
#ifdef RT_USING_DFS
{
......
......@@ -27,6 +27,22 @@
#include <WinError.h>
#include <windows.h>
#if defined(__MINGW32__) && defined(_NO_OLDNAMES)
#define O_RDONLY _O_RDONLY
#define O_WRONLY _O_WRONLY
#define O_RDWR _O_RDWR
#define O_ACCMODE _O_ACCMODE
#define O_APPEND _O_APPEND
#define O_CREAT _O_CREAT
#define O_TRUNC _O_TRUNC
#define O_EXCL _O_EXCL
#define O_TEXT _O_TEXT
#define O_BINARY _O_BINARY
#define O_TEMPORARY _O_TEMPORARY
#define O_NOINHERIT _O_NOINHERIT
#define O_SEQUENTIAL _O_SEQUENTIAL
#define O_RANDOM _O_RANDOM
#endif
/*
* RT-Thread DFS Interface for win-directory as an disk device
*/
......@@ -95,7 +111,7 @@ static int dfs_win32_unmount(struct dfs_filesystem *fs)
return 0;
}
static int dfs_win32_mkfs(const char *device_name)
static int dfs_win32_mkfs(rt_device_t devid)
{
return -DFS_STATUS_ENOSYS;
}
......@@ -132,6 +148,14 @@ static char *winpath_dirdup(char *des, const char *src)
return path;
}
/* This function can convert the path in rt-thread/dfs to the path in windows */
char * dfs_win32_dirdup(char * path)
{
char * file_path;
file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, path);
return file_path;
}
static int dfs_win32_open(struct dfs_fd *file)
{
int fd;
......
/*
* File : module.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2013-02-26 prife first version for win32
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtm.h>
#ifdef RT_USING_MODULE
static void rt_module_init_object_container(struct rt_module *module)
{
RT_ASSERT(module != RT_NULL);
/* initialize object container - thread */
rt_list_init(&(module->module_object[RT_Object_Class_Thread].object_list));
module->module_object[RT_Object_Class_Thread].object_size = sizeof(struct rt_thread);
module->module_object[RT_Object_Class_Thread].type = RT_Object_Class_Thread;
#ifdef RT_USING_SEMAPHORE
/* initialize object container - semaphore */
rt_list_init(&(module->module_object[RT_Object_Class_Semaphore].object_list));
module->module_object[RT_Object_Class_Semaphore].object_size = sizeof(struct rt_semaphore);
module->module_object[RT_Object_Class_Semaphore].type = RT_Object_Class_Semaphore;
#endif
#ifdef RT_USING_MUTEX
/* initialize object container - mutex */
rt_list_init(&(module->module_object[RT_Object_Class_Mutex].object_list));
module->module_object[RT_Object_Class_Mutex].object_size = sizeof(struct rt_mutex);
module->module_object[RT_Object_Class_Mutex].type = RT_Object_Class_Mutex;
#endif
#ifdef RT_USING_EVENT
/* initialize object container - event */
rt_list_init(&(module->module_object[RT_Object_Class_Event].object_list));
module->module_object[RT_Object_Class_Event].object_size = sizeof(struct rt_event);
module->module_object[RT_Object_Class_Event].type = RT_Object_Class_Event;
#endif
#ifdef RT_USING_MAILBOX
/* initialize object container - mailbox */
rt_list_init(&(module->module_object[RT_Object_Class_MailBox].object_list));
module->module_object[RT_Object_Class_MailBox].object_size = sizeof(struct rt_mailbox);
module->module_object[RT_Object_Class_MailBox].type = RT_Object_Class_MailBox;
#endif
#ifdef RT_USING_MESSAGEQUEUE
/* initialize object container - message queue */
rt_list_init(&(module->module_object[RT_Object_Class_MessageQueue].object_list));
module->module_object[RT_Object_Class_MessageQueue].object_size = sizeof(struct rt_messagequeue);
module->module_object[RT_Object_Class_MessageQueue].type = RT_Object_Class_MessageQueue;
#endif
#ifdef RT_USING_MEMHEAP
/* initialize object container - memory heap */
rt_list_init(&(module->module_object[RT_Object_Class_MemHeap].object_list));
module->module_object[RT_Object_Class_MemHeap].object_size = sizeof(struct rt_memheap);
module->module_object[RT_Object_Class_MemHeap].type = RT_Object_Class_MemHeap;
#endif
#ifdef RT_USING_MEMPOOL
/* initialize object container - memory pool */
rt_list_init(&(module->module_object[RT_Object_Class_MemPool].object_list));
module->module_object[RT_Object_Class_MemPool].object_size = sizeof(struct rt_mempool);
module->module_object[RT_Object_Class_MemPool].type = RT_Object_Class_MemPool;
#endif
#ifdef RT_USING_DEVICE
/* initialize object container - device */
rt_list_init(&(module->module_object[RT_Object_Class_Device].object_list));
module->module_object[RT_Object_Class_Device].object_size = sizeof(struct rt_device);
module->module_object[RT_Object_Class_Device].type = RT_Object_Class_Device;
#endif
/* initialize object container - timer */
rt_list_init(&(module->module_object[RT_Object_Class_Timer].object_list));
module->module_object[RT_Object_Class_Timer].object_size = sizeof(struct rt_timer);
module->module_object[RT_Object_Class_Timer].type = RT_Object_Class_Timer;
}
#ifdef RT_USING_HOOK
static void (*rt_module_load_hook)(rt_module_t module);
static void (*rt_module_unload_hook)(rt_module_t module);
/**
* @addtogroup Hook
*/
/*@{*/
/**
* This function will set a hook function, which will be invoked when module
* be loaded to system.
*
* @param hook the hook function
*/
void rt_module_load_sethook(void (*hook)(rt_module_t module))
{
rt_module_load_hook = hook;
}
/**
* This function will set a hook function, which will be invoked when module
* be unloaded from system.
*
* @param hook the hook function
*/
void rt_module_unload_sethook(void (*hook)(rt_module_t module))
{
rt_module_unload_hook = hook;
}
/*@}*/
#endif
/**
* @ingroup SystemInit
*
* This function will initialize system module
*/
void rt_system_module_init(void)
{
}
/**
* This function will return self module object
*
* @return the self module object
*/
rt_module_t rt_module_self(void)
{
rt_thread_t tid;
tid = rt_thread_self();
if (tid == RT_NULL)
return RT_NULL;
/* return current module */
return (rt_module_t)tid->module_id;
}
/**
* This function will find the specified module.
*
* @param name the name of module finding
*
* @return the module
*/
rt_module_t rt_module_find(const char *name)
{
struct rt_object_information *information;
struct rt_object *object;
struct rt_list_node *node;
extern struct rt_object_information rt_object_container[];
RT_DEBUG_NOT_IN_INTERRUPT;
/* enter critical */
rt_enter_critical();
/* try to find device object */
information = &rt_object_container[RT_Object_Class_Module];
for (node = information->object_list.next;
node != &(information->object_list);
node = node->next)
{
object = rt_list_entry(node, struct rt_object, list);
if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
{
/* leave critical */
rt_exit_critical();
return (rt_module_t)object;
}
}
/* leave critical */
rt_exit_critical();
/* not found */
return RT_NULL;
}
#ifdef RT_USING_DFS
#include <windows.h>
#include <dfs_posix.h>
extern char * dfs_win32_dirdup(char * path);
static char* _module_name(const char *path)
{
const char *first, *end, *ptr;
char *name;
int size;
ptr = (char *)path;
first = ptr;
end = path + rt_strlen(path);
while (*ptr != '\0')
{
if (*ptr == '/')
first = ptr + 1;
if (*ptr == '.')
end = ptr - 1;
ptr ++;
}
size = end - first + 1;
name = rt_malloc(size);
rt_strncpy(name, first, size);
name[size] = '\0';
return name;
}
typedef int (*appentry_t)(void);
/**
* This function will load a module from a file
*
* @param path the full path of application module
*
* @return the module object
*/
rt_module_t rt_module_open(const char *path)
{
struct dfs_filesystem *fs;
appentry_t fptr;
HINSTANCE hinstlib;
int len;
char * winpath;
rt_module_t module;
char * name;
RT_DEBUG_NOT_IN_INTERRUPT;
/* check parameters */
RT_ASSERT(path != RT_NULL);
/* app module should only in DFS_WIN32 */
fs = dfs_filesystem_lookup(path);
if ((fs == RT_NULL) || (strcmp(fs->ops->name,"wdir") != 0))
{
rt_kprintf("invalid path: %s\n", path);
return RT_NULL;
}
/* change path */
len = strlen(path+1);
if ((winpath = dfs_win32_dirdup((char *)path)) == RT_NULL)
{
rt_kprintf("out of memory, exit", path);
return RT_NULL;
}
hinstlib = LoadLibrary(winpath);
if (hinstlib == NULL)
{
rt_kprintf("error: unable to open %s\n", winpath);
return RT_NULL;
}
fptr = (appentry_t)GetProcAddress(hinstlib, "main");
if (fptr == NULL)
{
rt_kprintf("error: unable to find function in %s\n", winpath);
FreeLibrary(hinstlib);
return RT_NULL;
}
/* get the name of the module */
name = _module_name(path);
/* allocate module */
module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module,
name);
if (!module)
return RT_NULL;
module->nref = 0;
module->module_entry = fptr;
/* init module object container */
rt_module_init_object_container(module);
/* increase module reference count */
module->nref ++;
if (module->module_entry != 0)
{
rt_uint32_t *stack_size;
rt_uint8_t *priority;
#ifdef RT_USING_SLAB
/* init module memory allocator */
module->mem_list = RT_NULL;
/* create page array */
module->page_array =
(void *)rt_malloc(PAGE_COUNT_MAX * sizeof(struct rt_page_info));
module->page_cnt = 0;
#endif
/* get the main thread stack size */
module->stack_size = 2048;
module->thread_priority = RT_THREAD_PRIORITY_MAX - 2;
/* create module thread */
module->module_thread =
rt_thread_create(name,
(void(*)(void *))module->module_entry,
RT_NULL,
module->stack_size,
module->thread_priority,
10);
RT_DEBUG_LOG(RT_DEBUG_MODULE, ("thread entry 0x%x\n",
module->module_entry));
/* set module id */
module->module_thread->module_id = (void *)module;
module->parent.flag = RT_MODULE_FLAG_WITHENTRY;
/* startup module thread */
rt_thread_startup(module->module_thread);
}
else
{
/* without entry point */
module->parent.flag |= RT_MODULE_FLAG_WITHOUTENTRY;
}
#ifdef RT_USING_HOOK
if (rt_module_load_hook != RT_NULL)
{
rt_module_load_hook(module);
}
#endif
rt_free(name);
return module;
/* FreeLibrary(hinstlib); */
}
#if defined(RT_USING_FINSH)
#include <finsh.h>
FINSH_FUNCTION_EXPORT_ALIAS(rt_module_open, exec, exec module from a file);
#endif
#endif
rt_err_t rt_module_destroy(rt_module_t module)
{
return 0;
}
#endif
......@@ -53,7 +53,7 @@ void rt_hw_win32_low_cpu(void)
#endif
}
#ifdef _WIN32
#ifdef _MSC_VER
#ifndef _CRT_TERMINATE_DEFINED
#define _CRT_TERMINATE_DEFINED
_CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code);
......
......@@ -151,6 +151,7 @@ static void sdlfb_hw_init(void)
#include <rtgui/rtgui_system.h>
#ifdef _WIN32
static HANDLE sdl_ok_event = NULL;
static DWORD WINAPI sdl_loop(LPVOID lpParam)
#else
static void *sdl_loop(void *lpParam)
......@@ -172,7 +173,9 @@ static void *sdl_loop(void *lpParam)
device = rt_device_find("sdl");
rtgui_graphic_set_device(device);
#ifdef _WIN32
SetEvent(sdl_ok_event);
#endif
/* handle SDL event */
while (!quit)
{
......@@ -307,7 +310,15 @@ void rt_hw_sdl_start(void)
#ifdef _WIN32
HANDLE thread;
DWORD thread_id;
sdl_ok_event = CreateEvent(NULL,
FALSE,
FALSE,
NULL);
if (sdl_ok_event == NULL)
{
printf("error, create SDL event failed\n");
exit(-1);
}
/* create thread that loop sdl event */
thread = CreateThread(NULL,
0,
......@@ -322,6 +333,9 @@ void rt_hw_sdl_start(void)
return;
}
ResumeThread(thread);
/* wait until SDL LCD device is registered and seted */
WaitForSingleObject(sdl_ok_event, INFINITE);
#else
/* Linux */
pthread_t pid;
......
int dummy_main()
{
return 0;
}
/* Default linker script, for normal executables */
OUTPUT_FORMAT(pei-i386)
SEARCH_DIR("/usr/local/mingw32/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Make the virtual address and file offset synced if the alignment is
lower than the target page size. */
. = SIZEOF_HEADERS;
. = ALIGN(__section_alignment__);
.text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :
{
*(.init)
*(.text)
*(SORT(.text$*))
*(.glue_7t)
*(.glue_7)
___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0);
___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0);
*(.fini)
/* ??? Why is .gcc_exc here? */
*(.gcc_exc)
PROVIDE (etext = .);
*(.gcc_except_table)
}
/* setction information for finsh shell begin */
. = ALIGN(__section_alignment__);
FSymTab () :
{
___fsymtab_start = .; __fsymtab_start = .;
KEEP(*(FSymTab))
___fsymtab_end = .; __fsymtab_end = .;
}
. = ALIGN(__section_alignment__);
VSymTab () :
{
___vsymtab_start = .; __vsymtab_start = .;
KEEP(*(VSymTab))
___vsymtab_end = .; __vsymtab_end = .;
}
/* setction information for finsh shell end */
/* The Cygwin32 library uses a section to avoid copying certain data
on fork. This used to be named ".data". The linker used
to include this between __data_start__ and __data_end__, but that
breaks building the cygwin32 dll. Instead, we name the section
".data_cygwin_nocopy" and explictly include it after __data_end__. */
.data BLOCK(__section_alignment__) :
{
__data_start__ = . ;
*(.data)
*(.data2)
*(SORT(.data$*))
*(.jcr)
__data_end__ = . ;
*(.data_cygwin_nocopy)
}
.rdata BLOCK(__section_alignment__) :
{
*(.rdata)
*(SORT(.rdata$*))
*(.eh_frame)
___RUNTIME_PSEUDO_RELOC_LIST__ = .;
__RUNTIME_PSEUDO_RELOC_LIST__ = .;
*(.rdata_runtime_pseudo_reloc)
___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
}
.pdata BLOCK(__section_alignment__) :
{
*(.pdata)
}
.bss BLOCK(__section_alignment__) :
{
__bss_start__ = . ;
*(.bss)
*(COMMON)
__bss_end__ = . ;
}
.edata BLOCK(__section_alignment__) :
{
*(.edata)
}
/DISCARD/ :
{
*(.debug$S)
*(.debug$T)
*(.debug$F)
*(.drectve)
}
.idata BLOCK(__section_alignment__) :
{
/* This cannot currently be handled with grouped sections.
See pe.em:sort_sections. */
SORT(*)(.idata$2)
SORT(*)(.idata$3)
/* These zeroes mark the end of the import list. */
LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
SORT(*)(.idata$4)
SORT(*)(.idata$5)
SORT(*)(.idata$6)
SORT(*)(.idata$7)
}
.CRT BLOCK(__section_alignment__) :
{
___crt_xc_start__ = . ;
*(SORT(.CRT$XC*)) /* C initialization */
___crt_xc_end__ = . ;
___crt_xi_start__ = . ;
*(SORT(.CRT$XI*)) /* C++ initialization */
___crt_xi_end__ = . ;
___crt_xl_start__ = . ;
*(SORT(.CRT$XL*)) /* TLS callbacks */
/* ___crt_xl_end__ is defined in the TLS Directory support code */
___crt_xp_start__ = . ;
*(SORT(.CRT$XP*)) /* Pre-termination */
___crt_xp_end__ = . ;
___crt_xt_start__ = . ;
*(SORT(.CRT$XT*)) /* Termination */
___crt_xt_end__ = . ;
}
.tls BLOCK(__section_alignment__) :
{
___tls_start__ = . ;
*(.tls)
*(.tls$)
*(SORT(.tls$*))
___tls_end__ = . ;
}
.endjunk BLOCK(__section_alignment__) :
{
/* end is deprecated, don't use it */
PROVIDE (end = .);
PROVIDE ( _end = .);
__end__ = .;
}
.rsrc BLOCK(__section_alignment__) :
{
*(.rsrc)
*(SORT(.rsrc$*))
}
.reloc BLOCK(__section_alignment__) :
{
*(.reloc)
}
.stab BLOCK(__section_alignment__) (NOLOAD) :
{
*(.stab)
}
.stabstr BLOCK(__section_alignment__) (NOLOAD) :
{
*(.stabstr)
}
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section. Unlike other targets that fake this by putting the
section VMA at 0, the PE format will not allow it. */
/* DWARF 1.1 and DWARF 2. */
.debug_aranges BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_aranges)
}
.debug_pubnames BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_pubnames)
}
/* DWARF 2. */
.debug_info BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_info) *(.gnu.linkonce.wi.*)
}
.debug_abbrev BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_abbrev)
}
.debug_line BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_line)
}
.debug_frame BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_frame)
}
.debug_str BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_str)
}
.debug_loc BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_loc)
}
.debug_macinfo BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_macinfo)
}
/* SGI/MIPS DWARF 2 extensions. */
.debug_weaknames BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_weaknames)
}
.debug_funcnames BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_funcnames)
}
.debug_typenames BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_typenames)
}
.debug_varnames BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_varnames)
}
/* DWARF 3. */
.debug_ranges BLOCK(__section_alignment__) (NOLOAD) :
{
*(.debug_ranges)
}
}
说明: 本BSP可以如下演示
默认演示realtouch GUI效果,并提供了一个贪吃的demo用于演示
目前支持的功能有
1). LWIP(可以打开LWIP选项,不过尚存在bug,不建议使用)
2). 文件系统支持,支持ELM FatFS,UFFS,JFFS2
3). RTGUI支持
目前SVN中的RTGUI源码可以直接用于simulator。
如果读者想快速在simulator上体验RTGUI,那么不需要修改任何文件,首先在命令行中使用
scons --target=vs -s
生成工程后,打开project.vsproj编译,即可看到realtouch的ui出现,然后执行
在finsh中执行snake_main(),即可运行贪吃蛇demo
再补充说明一点,RTGUI的最新源码目前是托管在git上。
github网页:https://github.com/RT-Thread/RTGUI
如果要使用rtgui中的最新源码,共有两种方法。
一 平台及组件支持
目前rtconfig.py中支持的编译器有
1). msvc 用于windows平台
此平台支持的组件
kernel
finsh
LWIP
DFS, ELM FatFS, UFFS, JFFS2, DFS_WIN32
RTGUI
APP MODULE
2). mingw 用于windows平台
kernel
finsh
DFS, ELM FatFS, UFFS, DFS_WIN32
RTGUI
APP MODULE
3). gcc 用于linux平台
kernel
finsh
DFS, ELM FatFS, UFFS
RTGUI
二 组件配置
1) RTGUI
当前代码中已经不含RTGUI源码,因此读者需要配置一下才能在simulator中使用RTGUI
RTGUI的最新源码目前是托管在github上:https://github.com/RT-Thread/RTGUI
共有两种方法。
方法1 添加环境变量
向系统环境变量中加入RTT_RTGUI,其值为刚才github上下载的rtgui源码包的路径。
例如笔者的rtgui源码包解压至 F:\Project\git\rt-gui\下
则将此环境变量配置为 F:\Project\git\rt-gui\components\rtgui
向系统加入RTT_RTGUI环境变量,其值为刚才github上下载的rtgui源码包的路径。
例如笔者的rtgui源码包解压至 F:\Project\git\rt-gui\下, 则将此环境变量配置为 F:\Project\git\rt-gui\components\rtgui
方法2 不添加环境变量
打开SConstruct文件,
....
......@@ -37,106 +49,105 @@
1)#号表示注释,类似于c语言中的//,
2)其中15行的路径为你的RTGUI路径源码,注意不是压缩包路径,而是压缩包路径下的 components\rtgui目录的绝对路径。
1 编译:
1.1 使用Visual Studio(2005以上版本)
在命令行中执行 scons --target=vs -s 可以生成vs2005的工程,名为project.vsproj
编译后运行
1.2 使用scons编译,在当前目录中打开cmd,输入
scons -j4
编译完成后会在当前目录下生成 rtthrad-win32.exe,双击即可运行。
2. 测试文件系统
运行:
编译后运行,会弹出CMD命令行窗口,可以看到控制台的输出信息,如下所示
\ | /
- RT - Thread Operating System
/ | \ 1.1.0 build Oct 21 2012
2006 - 2012 Copyright by rt-thread team
init jffs2 lock mutex okay
hello, world
finsh>>fatfs initialzation failed!
uffs initialzation failed!
jffs2 initialzation failed!
thread 29e4 exit
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
thread 2898 exit
注意上面的信息显示,fatfs/uffs/jffs2均挂载失败,这是因为我们还没有为sd.bin创建fat分区,并且sd上也没有目录用于挂载jffs2和uffs。
并且此时当前bsp目录下,新增了三个文件用于模拟sd卡,nand flash与nor flash,它们是
sd.bin--模拟SD卡,挂载fat,大小为16M
nand.bin-模拟nand flash,挂载uffs,参数page=2048+64bytes,block=64pages,16M
nor.bin--模拟nor flash,挂载jffs2,型号为sst25vf,2M
按下回车,出现finsh,然后输入如下命令格式化sd.bin
三 编译
1) 使用Visual Studio(2005以上版本)
在当前目录中打开cmd,输入命令
`scons --target=vs -s`
可以生成project.vsproj,双击运行
2) 命令行编译
修改rtconfig.py, 配置合适的编译器(msvc/mingw/gcc),及其路径
在当前目录中打开cmd,输入命令
`scons -j4`
编译完成后会在当前目录下生成 rtthrad-win32.exe,双击即可运行。
四 程序测试
1) 测试文件系统
此时当前目录下,新增了三个文件
sd.bin--模拟SD卡,挂载fat,大小为16M
nand.bin-模拟nand flash,挂载uffs,参数page=2048+64bytes,block=64pages,16M
nor.bin--模拟nor flash,挂载jffs2,型号为sst25vf,2M
第一次启动时,会看到fatfs挂在失败。
按下回车,出现finsh,然后输入`mkfs("elm", "sd0")`格式化SD卡,如下所示
finsh>>mkfs("elm", "sd0")
0, 0x00000000
finsh>>
关闭程序重新运行,此时可以看到fatfs挂载成功,不过jffs2和uffs依然失败,如下所示。
\ | /
- RT - Thread Operating System
/ | \ 1.1.0 build Oct 21 2012
2006 - 2012 Copyright by rt-thread team
init jffs2 lock mutex okay
hello, world
finsh>>fatfs initialized!
uffs initialzation failed!
jffs2 initialzation failed!
这是因为sd上还没有目录来用于挂载jffs2和uffs,在finsh中输入如下命令在sd上创建nand与nor文件夹,分别用于挂载uffs与jffs2文件系统。
finsh>>mkdir("/nand")
0, 0x00000000
finsh>>mkdir("/nor")
0, 0x00000000
finsh>>
然后再次关闭程序后重新运行,此时可以看到jffs2与uffs挂载成功。
最终输出如下所示:
\ | /
- RT - Thread Operating System
/ | \ 1.1.0 build Oct 21 2012
2006 - 2012 Copyright by rt-thread team
init jffs2 lock mutex okay
hello, world
finsh>>fatfs initialized!
os : system memory alloc 320 bytes
flsh: ECC size 24
flsh: UFFS consume spare data size 34
os : system memory alloc 83520 bytes
os : system memory alloc 52400 bytes
os : system memory alloc 2048 bytes
tree: DIR 0, FILE 0, DATA 0
uffs initialized!
jffs2 initialized!
thread 2fb4 exit
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
hello, world
thread 312c exit
Ok,到现在,一个完整的文件系统测试环境就搭建完毕了,enjoy~~
3 测试RTGUI
启动后就会看到GUI窗口,分辨率800×480串口,并出现图形界面。
此时在finsh中输入 snake_main()并回车,即可运行贪吃蛇程序。
然后重启程序,就可以看到fatfs挂载成功了
2) 测试RTGUI
启动后就会看到GUI窗口,分辨率800x480,此时在finsh中输入snake_main()并回车,即可运行贪吃蛇程序
3) 测试APP module
rtconfig.h中需要打开RT_USING_MODULE
a. 生成rtthread.def文件
使用msv编译主程序时需要此文件,使用MingW编译主程序时不需要
msvc需要此文件才能生成正确导出符号的rtthread.dll和rtthread-win32.exe。
此目录下默认自带了一个rtthread.def文件,当修改了rtconfig.h,禁用了某些组件时,则需要重新生成rtthread.def文件.
生成方法:
需要借助MingW工具,修改rtconfig.py中CROSS_TOOL为'mingw',然后打开CMD执行`scons --def`就会自动更新rtthread.def。
b. 生成主程序
主程序可以使用msvc和mingw生成
如果rtconfig.h中的使能了RTGUI,则需要参考第二节第1小节配置RTGUI
a.1 使用msvc
修改rtconfig.py中CROSS_TOOL为'msvc'
首先要保证当前目录下有合适的rtthread.def文件,如果没有对默认的rtconfig.h作修改,则使用默认的rtthread.def即可
CMD命令行执行`scons -j4`,即可生成rtthread.dll和 rtthread-win32.exe
a.2 使用mingw
修改rtconfig.py中CROSS_TOOL为'mingw'
CMD命令行执行`scons -j4`,这就会生成 rtthread.dll和 rtthread-win32.exe
c. 生成app module
进入testdll目录,再次修改 testdll/SConstruct, 同样需要配置RTT_RTGUI路径,同 1中3)
在此目录下执行
`scons --app=basicapp`
就会在 basicapp/building目录下生成 basicapp.dll。
然后运行simulator目录下的 rtthread-win32.exe, 在finsh中运行
`exec("/testdll/basicapp/building/basicapp.dll")`
如果觉得这个路径太长,就把 basicapp.dll复制到 simualtor目录下,执行
`exec("/basicapp.dll")`
如果想编译RTGUI应用,如testdll目录下的snake,则需要对RTGUI打一点补丁,共有两个方法
1. 注释掉 //#define RTGUI_USING_CAST_CHECK`
找到rtgui_config.h源码,注释掉如下语句
//#define RTGUI_USING_CAST_CHECK`
然后在testdll目录下打开CMD窗口,执行`scons --app=snake`,才可以正确编译,如果不注释掉上面的宏,则会出现链接错误。
2. 不注释掉#define RTGUI_USING_CAST_CHECK`
那么需要如下两个补丁
1) 修改testdll/SConstruct文件
diff --git a/bsp/simulator/testdll/SConstruct b/bsp/simulator/testdll/SConstruct
index 3324f88..005289c 100644
--- a/bsp/simulator/testdll/SConstruct
+++ b/bsp/simulator/testdll/SConstruct
@@ -70,6 +70,7 @@ env.Append(CCFLAGS=rtconfig.CFLAGS)
env.Append(LINKFLAGS=rtconfig.LFLAGS)
env.Append(CPPPATH=CPPPATH)
env.Append(LIBS='rtthread', LIBPATH='../')
+env.Append(CPPDEFINES=['RTT_IN_MODULE'])
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
PrepareModuleBuilding(env, RTT_ROOT)
2) 修改RTGUI源码
diff --git a/components/rtgui/include/rtgui/rtgui_object.h b/components/rtgui/include/rtgui/rtgui_object.h
index 57fd47f..b32ee17 100644
--- a/components/rtgui/include/rtgui/rtgui_object.h
+++ b/components/rtgui/include/rtgui/rtgui_object.h
@@ -56,7 +56,12 @@ extern "C" {
typedef struct rtgui_type rtgui_type_t;
#define RTGUI_TYPE(type) (struct rtgui_type*)&(_rtgui_##type)
+#ifdef RTT_IN_MODULE
+#define DECLARE_CLASS_TYPE(type) _declspec(dllimport) const struct rtgui_type _rtgui_##type
+#else
#define DECLARE_CLASS_TYPE(type) extern const struct rtgui_type _rtgui_##type
+#endif
+
#define DEFINE_CLASS_TYPE(type, name, parent, constructor, destructor, size) \
const struct rtgui_type _rtgui_##type = { \
name, \
然后再编译snake,可以正确生成。测试方法同basicapp
......@@ -21,6 +21,10 @@
#elif defined(__GNUC__)
#define RT_USING_NOLIBC
#if defined(__MINGW32__)
#define _NO_OLDNAMES /* to ignore: mode_t in sys/type.h */
#endif
#endif
/* SECTION: basic kernel options */
......@@ -83,6 +87,7 @@
/* SECTION: Device System */
/* Using Device System */
#define RT_USING_DEVICE
#define RT_USING_DEVICE_IPC
/* #define RT_USING_UART1 */
/* SECTION: Console options */
......@@ -94,11 +99,14 @@
/* SECTION: component options */
#define RT_USING_COMPONENTS_INIT
/* SECTION: APP MODULE */
#define RT_USING_MODULE
/* SECTION: MTD interface options */
/* using mtd nand flash */
#define RT_USING_MTD_NAND
/* using mtd nor flash */
#define RT_USING_MTD_NOR
/* #define RT_USING_MTD_NOR */
/* SECTION: finsh, a C-Express shell */
#define RT_USING_FINSH
......
# toolchains options
ARCH='sim'
#CROSS_TOOL='msvc' or 'gcc' or 'mingw' (mingw is not supported yet!)
CROSS_TOOL='msvc'
CROSS_TOOL='mingw'
# cross_tool provides the cross compiler
# EXEC_PATH is the compiler execute path
......@@ -10,11 +10,20 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = '/usr/bin/gcc'
if CROSS_TOOL == 'msvc':
elif CROSS_TOOL == 'mingw':
CPU = 'win32'
PLATFORM = 'mingw'
EXEC_PATH = r'D:\Program Files\CodeBlocks\MinGW\bin'
elif CROSS_TOOL == 'msvc':
CPU = 'win32'
PLATFORM = 'cl'
EXEC_PATH = ''
else :
print "bad CROSS TOOL!"
exit(1)
BUILD = 'debug'
#BUILD = ''
......@@ -48,6 +57,35 @@ if PLATFORM == 'gcc':
POST_ACTION = ''
elif PLATFORM == 'mingw':
# toolchains
PREFIX = ''
CC = PREFIX + 'gcc'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'exe'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -ffunction-sections -fdata-sections'
DEVICE = ' '
CFLAGS = DEVICE
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
DEFFILE_LFLAGS = DEVICE + ' -Wl,-Map=rtthread-win32.map,--output-def,rtthread.def -T mingw.ld '
LFLAGS = DEVICE + ' -Wl,-Map=rtthread-win32.map -T mingw.ld '
CPATH = ''
LPATH = ''
if BUILD == 'debug':
CFLAGS += ' -g -O0 -gdwarf-2'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2'
POST_ACTION = ''
elif PLATFORM == 'cl':
# toolchains
PREFIX = ''
......
此差异已折叠。
import os
import sys
import SCons.cpp
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
if os.getenv('RTT_RTGUI'):
RTT_RTGUI = os.getenv('RTT_RTGUI')
else:
# set the rtgui root directory by hand
# empty string means use the RTGUI in svn
RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui')
# RTT_RTGUI =''
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
Export('RTT_ROOT')
# add target option
AddOption('--app',
dest='app',
nargs=1, type='string',
action='store',
metavar='DIR',
help='installation prefix')
# add target option
AddOption('--type',
dest='type',
nargs=1, type='string',
action='store',
metavar='DIR',
help='installation prefix')
app = GetOption('app')
env = Environment()
CPPPATH = [
RTT_ROOT + '/include',
RTT_ROOT + '/bsp/' + rtconfig.BSP,
RTT_ROOT + '/components/finsh',
RTT_ROOT + '/components/libdl',
RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread',
RTT_ROOT + '/components/external/ftk/ftk/src/demos',
RTT_ROOT + '/components/external/ftk/ftk/apps/common',
RTT_ROOT + '/components/external/ftk/ftk/src',
RTT_ROOT + '/components/dfs',
RTT_ROOT + '/components/dfs/include',
RTT_ROOT + '/components/libc/newlib',
RTT_ROOT + '/components/external/cairo/cairo-1.10.2/src',
RTT_ROOT + '/components/external/cairo/'
]
if RTT_RTGUI:
RTGUI_ROOT = RTT_RTGUI
else:
RTGUI_ROOT = RTT_ROOT + '/components/rtgui'
RTGUI_PATH = [
RTGUI_ROOT + '/include',
RTGUI_ROOT + '/common',
RTGUI_ROOT + '/server',
RTGUI_ROOT + '/widgets',
]
CPPPATH += RTGUI_PATH
env.Append(CCFLAGS=rtconfig.CFLAGS)
env.Append(LINKFLAGS=rtconfig.LFLAGS)
env.Append(CPPPATH=CPPPATH)
env.Append(LIBS='rtthread', LIBPATH='../')
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
PrepareModuleBuilding(env, RTT_ROOT)
#dir = app + '/build/' + rtconfig.BSP
dir = app + '/build/'
objs = SConscript(app + '/Sconscript', variant_dir=dir, duplicate=0)
TARGET = dir + '/' + app + '.' + rtconfig.TARGET_EXT
# build program
#env.Program(TARGET, objs)
env.SharedLibrary(TARGET, objs)
import rtconfig
Import('RTT_ROOT')
from building import *
src = Glob('*.c')
group = DefineGroup('', src, depend = [''])
Return('group')
\ No newline at end of file
#include <rtthread.h>
static int a = 0;
static int b = 1000000;
int c = 100;
static void function(int count1, int count2, int count3)
{
rt_kprintf("Hello RT-Thread %d %d\n", count1, count2, count3);
}
int main(void)
{
int i;
rt_kprintf("application entry\n");
rt_kprintf("[addr]a-0x%x,b-0x%x,c-0x%x\n", &a, &b, &c);
rt_kprintf("[value]a-%d,b-%d,c-%d\n", a, b, c);
for(i=0; i<100; i++)
{
a++;
b--;
c++;
function(a, c, b );
}
return 0;
}
import rtconfig
Import('RTT_ROOT')
from building import *
src = Glob('*.c')
group = DefineGroup('', src, depend = [''])
Return('group')
\ No newline at end of file
#include <rtthread.h>
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/label.h>
#include <rtgui/driver.h>
/* 在LCD上创建一个主窗口,这是第一个窗口 */
static void win_thread_entry(void *parameter)
{
struct rtgui_app *app;
struct rtgui_win *win;
struct rtgui_label *label;
struct rtgui_rect rect;
app = rtgui_app_create(rt_thread_self(), "MyApp");
RT_ASSERT(app != RT_NULL);
/* create a full screen window */
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
win = rtgui_win_create(RT_NULL, "MainWin", &rect,
RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
if (win == RT_NULL)
{
rtgui_app_destroy(app);
return;
}
/* 建立一个label,内容为helloworld */
label = rtgui_label_create("Hello World!");
/* 设置label的位置,这里是绝对坐标 */
rect.x1 = 0;
rect.y1 = 100;
rect.x2 = 240;
rect.y2 = 140;
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rt_kprintf("bc: %x\n", RTGUI_WIDGET_BACKGROUND(label));
rt_kprintf("fc: %x\n", RTGUI_WIDGET_FOREGROUND(label));
#if 0
RTGUI_WIDGET_BACKGROUND(label) = 0;
RTGUI_WIDGET_FOREGROUND(label) = RTGUI_RGB(0xFF, 0xFF, 0);
#endif
/*添加label到主窗口*/
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
/* 显示主窗口 */
rtgui_win_show(win, RT_FALSE);
/* 循环 */
rtgui_app_run(app);
rtgui_win_destroy(win);
rtgui_app_destroy(app);
rt_kprintf("MyApp Quit.\n");
}
int main()
{
rt_thread_t tid;
tid = rt_thread_create("win", win_thread_entry, RT_NULL,
2048, 20, 20);
if (tid != RT_NULL)
{
rt_thread_startup(tid);
}
return 0;
}
# bsp name
BSP = 'simulator'
# toolchains
EXEC_PATH = ''
PREFIX = ''
TARGET_EXT = 'dll'
AS = PREFIX + 'cl'
CC = PREFIX + 'cl'
AR = PREFIX + 'cl'
LINK = PREFIX + 'cl'
AFLAGS = ''
CFLAGS = ''
LFLAGS = ''
BUILD = 'debug'
if BUILD == 'debug':
CFLAGS += ' /MTd'
LFLAGS += ' /DEBUG'
else:
CFLAGS += ' /MT'
LFLAGS += ''
CFLAGS += ' /ZI /Od /W 3 /WL'
LFLAGS += ' /DEF:rttapp.def /SUBSYSTEM:CONSOLE /MACHINE:X86'
#LFLAGS += ' /DEF:rttapp.def /SUBSYSTEM:WINDOWS /MACHINE:X86' #/ENTRY:mainCRTStartup
CPATH = ''
LPATH = ''
'''
EXEC_PATH = 'C:/Program Files/CodeSourcery/Sourcery G++ Lite/bin'
PREFIX = 'arm-none-eabi-'
CC = PREFIX + 'gcc'
CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'so'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -mcpu=arm920t'
CFLAGS = DEVICE + ' -O0 -fPIC -DFTK_AS_PLUGIN -DRT_THREAD '
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
LFLAGS = DEVICE + ' -Wl,-z,max-page-size=0x4 -shared -fPIC -nostdlib -s'
CPATH = ''
LPATH = ''
'''
import rtconfig
Import('RTT_ROOT')
from building import *
src = Glob('*.c')
group = DefineGroup('', src, depend = [''])
Return('group')
#include <string.h>
#include <stdlib.h>
#include <rtthread.h>
#include "snake.h"
#define ASSERT_RET(x, ret) \
do{ \
if (x) \
return ret; \
}while(0)
rt_list_t snake_head;
SNAKE_DIR prevdir, newdir;
static SNAKE_DIR dir_adjust(SNAKE_DIR dir)
{
if ((SNAKE_DIR_UP == prevdir && SNAKE_DIR_DOWN != dir)
|| (SNAKE_DIR_DOWN == prevdir && SNAKE_DIR_UP != dir)
|| (SNAKE_DIR_LEFT == prevdir && SNAKE_DIR_RIGHT != dir)
|| (SNAKE_DIR_RIGHT == prevdir && SNAKE_DIR_LEFT != dir)
)
{
newdir = dir;
}
else
{
rt_kprintf("dirction change error\n\r");
}
return newdir;
}
static void across_XY(point_t *node, const map_t *map)
{
RT_ASSERT(node != RT_NULL && map != RT_NULL);
// 如果长度超出当前边框则可以穿越墙到对面
node->x = (node->x + map->width) % map->width;
node->y = (node->y + map->height) % map->height;
}
static SYS_STE node_update(snake_t *tail, const point_t *node, map_t *map)
{
SYS_STE ret;
point_t *pos;
RT_ASSERT(tail != RT_NULL && node != RT_NULL && map != RT_NULL);
pos = map->snake_flush;
pos[0].x = pos[0].y = -1;
pos[1].x = pos[1].y = -1;
ret = (SYS_STE)map->range[node->y * map->width + node->x];
if (FOOD == map->range[node->y * map->width + node->x])
{
// 吃一个食物增加一个节点
snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t));
if (!new)
return NORMAL;
pos[0] = *node;
new->body = *node;
rt_list_insert_after(&snake_head, &new->list);
}
else if (NORMAL == map->range[node->y * map->width + node->x])
{
// 将尾巴修改后拿到头部,其他不变
rt_list_remove(&tail->list);
map->range[tail->body.y * map->width + tail->body.x] = NORMAL;
pos[0] = *node;
pos[1] = tail->body;
tail->body = *node;
rt_list_insert_after(&snake_head, &tail->list);
}
map->range[node->y * map->width + node->x] = OVER;
if (ret != OVER)
prevdir = newdir;
return ret;
}
map_t *map_init(rt_uint32_t width, rt_uint32_t heigth)
{
map_t *map = rt_malloc(sizeof(map_t));
if (map != RT_NULL)
{
map->range = rt_malloc(heigth * width);
if (!map->range)
{
rt_free(map);
map = RT_NULL;
}
else
{
map->width = width;
map->height = heigth;
memset(map->range, NORMAL, heigth * width);
}
}
return map;
}
// 构造一条指定长度的蛇在指定点
rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map)
{
rt_int32_t i;
rt_int32_t inc_x, inc_y;
point_t old = *start;
ASSERT_RET(!map || !start, RT_FALSE);
rt_list_init(&snake_head);
if (dir == SNAKE_DIR_UP || dir == SNAKE_DIR_DOWN)
{
if (map->height <= length)
return RT_FALSE;
inc_x = 0;
inc_y = dir == SNAKE_DIR_DOWN ? 1 : -1; // 反向延长身子,头部在指定位置
old.y -= inc_y;
}
else
{
if (map->width <= length)
return RT_FALSE;
inc_y = 0;
inc_x = dir == SNAKE_DIR_RIGHT ? -1 : 1;
old.x -= inc_x;
}
for (i = 0; i < length; i++)
{
snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t));
if (!new)
return RT_FALSE;
new->body.y = inc_y + old.y;
new->body.x = inc_x + old.x;
// 如果长度超出当前边框则可以穿越墙到对面
across_XY(&new->body, map);
map->range[new->body.y * map->width + new->body.x] = OVER;
old = new->body;
rt_list_insert_before(&snake_head, &new->list);
}
prevdir = dir;
return RT_TRUE;
}
// 构造出食物
rt_bool_t food_init(map_t *map, rt_uint32_t max_num)
{
point_t food;
#ifndef FOOD_TIMEOUT
#define FOOD_TIMEOUT 10
#endif
rt_uint32_t timeout, num;
ASSERT_RET(!map, RT_FALSE);
num = 0;
timeout = rt_tick_get();
srand(rand());
map->food_flush[0].x = map->food_flush[0].y = -1;
do
{
food.x = rand() % map->width;
food.y = rand() % map->height;
if (map->range[food.y * map->width + food.x] == NORMAL)
{
map->food_flush[0] = food;
map->range[food.y * map->width + food.x] = FOOD;
num++;
}
}
while (num < max_num && rt_tick_get() - timeout < FOOD_TIMEOUT);
return num;
}
void map_deinit(map_t *map)
{
if (map)
{
if (map->range)
{
rt_free(map->range);
map->range = RT_NULL;
}
rt_free(map);
}
}
void snake_deinit(void)
{
snake_t *node;
while (!rt_list_isempty(&snake_head))
{
node = rt_list_entry(snake_head.prev, snake_t, list);
rt_list_remove(&node->list);
rt_free(node);
}
}
void food_deinit(void)
{
}
SYS_STE snake_step(SNAKE_DIR dir, map_t *map)
{
snake_t *tail, *head;
point_t node;
ASSERT_RET(!map, RT_FALSE);
dir = dir_adjust(dir);
// 取出头尾两个节点,其他节点不需要改变
tail = rt_list_entry(snake_head.prev, snake_t, list);
head = rt_list_entry(snake_head.next, snake_t, list);
node = head->body;
// 构造一个新的蛇头坐标
switch (dir)
{
case SNAKE_DIR_UP:
case SNAKE_DIR_DOWN:
node.y = head->body.y + (dir == SNAKE_DIR_DOWN ? -1 : 1);
break;
case SNAKE_DIR_LEFT:
case SNAKE_DIR_RIGHT:
node.x = head->body.x + (dir == SNAKE_DIR_RIGHT ? 1 : -1);
break;
}
across_XY(&node, map);
return node_update(tail, &node, map);
}
rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map)
{
ASSERT_RET(!map || !start, RT_FALSE);
snake_deinit();
memset(map->range, NORMAL, map->width * map->height);
return snake_init(start, length, dir, map);
}
#ifndef _SNAKE_H_
#define _SNAKE_H_
#include <rtthread.h>
#define snake_length_max 20 //最大蛇长
#define snake_length_init 3 //初始化蛇长
#define snake_room_size_hight 8 //房子高 0-255 建议>8
#define snake_room_size_widht 8 //房子宽 0-255 建议>8
#define snake_init_pointx 1
#define snake_init_pointy 2
typedef struct
{
rt_int32_t x, y;
} point_t;
typedef struct
{
rt_int32_t width; // max x
rt_int32_t height; // max y
rt_uint8_t *range; // map, map->range[y * map->width + x]
point_t snake_flush[2];
point_t food_flush[1];
} map_t;
typedef enum
{
SNAKE_DIR_UP,
SNAKE_DIR_DOWN,
SNAKE_DIR_LEFT,
SNAKE_DIR_RIGHT
} SNAKE_DIR;
typedef enum
{
FOOD, // 吃到水果
OVER, // 咬到自身
NORMAL // 正常行动
} SYS_STE;
typedef struct
{
point_t body;
rt_list_t list;
} snake_t;
// 构造一个地图
map_t *map_init(rt_uint32_t width, rt_uint32_t heigth);
// 构造一条指定长度的蛇在指定点
rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map);
// 构造出食物
rt_bool_t food_init(map_t *map, rt_uint32_t max_num);
void map_deinit(map_t *map);
void snake_deinit(void);
void food_deinit(void);
SYS_STE snake_step(SNAKE_DIR dir, map_t *map);
rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map);
#endif
#include <string.h>
#include <rtthread.h>
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/widgets/container.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/button.h>
#include "snake.h"
#define LATTICE_SIZE (20)
#define FOOD_MAX (8)
#define WALL_COLOR RTGUI_RGB(255, 0, 0)
#define SNAKE_COLOR RTGUI_RGB(0, 100, 200)
#define SNAKE_HEAD_COLOR RTGUI_RGB(180, 70, 130)
#define BACKGROUND_COLOR RTGUI_RGB(153, 153, 0)
#define FOOD_COLOR RTGUI_RGB(128, 0, 0)
static rtgui_timer_t *timer;
static rt_size_t room_size_x, room_size_y;
static rt_size_t lattice_size_x, lattice_size_y;
static struct rtgui_rect room_rect, lattice_rect;
map_t *map;
SNAKE_DIR run_state;
rt_int32_t snake_len;
rt_int32_t food_num;
point_t second_node;
static void snake_fill_lattice(struct rtgui_dc *dc,
rt_uint32_t x,
rt_uint32_t y,
rtgui_color_t color)
{
struct rtgui_rect rect;
// coordinate conversion
y = (lattice_size_y - 1) - y;
RTGUI_DC_BC(dc) = color;
rect.x1 = lattice_rect.x1 + (LATTICE_SIZE * x);
rect.x2 = rect.x1 + LATTICE_SIZE;
rect.x1 += 2;
rect.y1 = lattice_rect.y1 + (LATTICE_SIZE * y);
rect.y2 = rect.y1 + LATTICE_SIZE;
rect.y1 += 2;
rtgui_dc_fill_rect(dc, &rect);
}
static void snake_draw(struct rtgui_widget *widget)
{
struct rtgui_dc *dc;
struct rtgui_rect rect;
rt_uint32_t i;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
{
rt_kprintf("dc == RT_NULL\r\n");
return;
}
/* get room size, run once frist. */
if ((room_size_x == 0) || (room_size_y == 0))
{
rt_size_t tmp;
rtgui_widget_get_rect(widget, &rect);
rt_kprintf("rect => x1:%d x2:%d, y1:%d y2:%d\r\n", rect.x1, rect.x2, rect.y1, rect.y2);
room_size_x = rect.x2 - rect.x1;
room_size_y = rect.y2 - rect.y1;
memcpy(&room_rect, &rect, sizeof(struct rtgui_rect));
rt_kprintf("room_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
room_rect.x1, room_rect.x2,
room_rect.y1, room_rect.y2);
lattice_size_x = (room_rect.x2 - room_rect.x1) / LATTICE_SIZE;
lattice_size_y = (room_rect.y2 - room_rect.y1) / LATTICE_SIZE;
lattice_size_x -= 2;
lattice_size_y -= 2;
rt_kprintf("lattice_size_x:%d lattice_size_y:%d\r\n",
lattice_size_x,
lattice_size_y);
tmp = (room_rect.x2 - room_rect.x1) - (LATTICE_SIZE * lattice_size_x);
lattice_rect.x1 = room_rect.x1 + (tmp / 2);
lattice_rect.x2 = lattice_rect.x1 + (LATTICE_SIZE * lattice_size_x);
tmp = (room_rect.y2 - room_rect.y1) - (LATTICE_SIZE * lattice_size_y);
lattice_rect.y1 = room_rect.y1 + (tmp / 2);
lattice_rect.y2 = lattice_rect.y1 + (LATTICE_SIZE * lattice_size_y);
rt_kprintf("lattice_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
lattice_rect.x1, lattice_rect.x2,
lattice_rect.y1, lattice_rect.y2);
/* create snake. */
{
point_t start;
map = map_init(lattice_size_x, lattice_size_y);
if (map != RT_NULL)
{
start.x = snake_init_pointx;
start.y = snake_init_pointy;
run_state = SNAKE_DIR_DOWN;
if (snake_init(&start, snake_length_init, run_state, map))
{
food_num = 1;
food_init(map, food_num);
}
else
{
map_deinit(map);
map = RT_NULL;
}
}
}
}
RTGUI_DC_BC(dc) = BACKGROUND_COLOR;
rtgui_dc_fill_rect(dc, &room_rect);
memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
rect.x2 += 1;
rect.y2 += 1;
RTGUI_DC_FC(dc) = WALL_COLOR;
rtgui_dc_draw_rect(dc, &rect);
for (i = 1; i < lattice_size_y; i++)
{
memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
rect.x1 += 1;
rect.x2 -= 1;
rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2,
rect.y1 + (LATTICE_SIZE * i));
}
for (i = 1; i < lattice_size_x; i++)
{
memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
rect.y1 += 1;
rect.y2 -= 1;
rtgui_dc_draw_vertical_line(dc, rect.x1 + (LATTICE_SIZE * i),
rect.y1, rect.y2);
}
/* draw snake. */
{
rt_int32_t x, y;
rt_bool_t first_node = RT_TRUE;
for (y = 0; y < map->height; y++)
{
for (x = 0; x < map->width; x++)
{
switch (map->range[y * map->width + x])
{
case NORMAL:
break;
case FOOD:
snake_fill_lattice(dc, x, y, FOOD_COLOR);
break;
case OVER:
if (first_node)
{
first_node = RT_FALSE;
second_node.x = x;
second_node.y = y;
snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR);
}
else
{
snake_fill_lattice(dc, x, y, SNAKE_COLOR);
}
break;
}
}
}
}
rtgui_dc_end_drawing(dc);
return;
}
static void snake_update(struct rtgui_widget *widget)
{
struct rtgui_dc *dc;
rt_int32_t x, y;
rt_uint32_t i;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
{
rt_kprintf("dc == RT_NULL\r\n");
return;
}
snake_fill_lattice(dc, second_node.x, second_node.y, SNAKE_COLOR);
second_node = map->snake_flush[0];
for (i = 0; i < 3; i++)
{
if (i < 2)
{
x = map->snake_flush[i].x;
y = map->snake_flush[i].y;
}
else
{
x = map->food_flush[0].x;
y = map->food_flush[0].y;
}
if ((x >= 0) && (y >= 0))
{
switch (map->range[(map->width * y) + x])
{
case NORMAL:
snake_fill_lattice(dc, x, y, BACKGROUND_COLOR);
break;
case FOOD:
snake_fill_lattice(dc, x, y, FOOD_COLOR);
break;
case OVER:
if (0 == i)
snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR);
else
snake_fill_lattice(dc, x, y, SNAKE_COLOR);
break;
}
}
}
rtgui_dc_end_drawing(dc);
return;
}
static void snake_handler(struct rtgui_widget *widget, rtgui_event_t *event)
{
struct rtgui_event_kbd *ekbd;
ekbd = (struct rtgui_event_kbd *) event;
if (ekbd->type == RTGUI_KEYDOWN)
{
switch (ekbd->key)
{
case RTGUIK_UP:
rt_kprintf("RTGUIK_UP\r\n");
run_state = SNAKE_DIR_UP;
break;
case RTGUIK_DOWN:
rt_kprintf("RTGUIK_DOWN\r\n");
run_state = SNAKE_DIR_DOWN;
break;
case RTGUIK_LEFT:
rt_kprintf("RTGUIK_LEFT\r\n");
run_state = SNAKE_DIR_LEFT;
break;
case RTGUIK_RIGHT:
rt_kprintf("RTGUIK_RIGHT\r\n");
run_state = SNAKE_DIR_RIGHT;
break;
default:
break;
}
}
}
static rt_bool_t event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
rt_kprintf("event_handler\r\n");
if (event->type == RTGUI_EVENT_PAINT)
{
rt_kprintf("RTGUI_EVENT_PAINT\r\n");
rtgui_win_event_handler((struct rtgui_object *)object, event);
snake_draw(widget);
rtgui_timer_start(timer);
}
else if (event->type == RTGUI_EVENT_SHOW)
{
rt_kprintf("RTGUI_EVENT_SHOW\r\n");
rtgui_win_event_handler((struct rtgui_object *)object, event);
snake_draw(widget);
rtgui_timer_start(timer);
}
else if (event->type == RTGUI_EVENT_HIDE)
{
rt_kprintf("RTGUI_EVENT_HIDE\r\n");
rtgui_win_event_handler((struct rtgui_object *)object, event);
rtgui_timer_stop(timer);
}
else if (event->type == RTGUI_EVENT_WIN_DEACTIVATE)
{
rt_kprintf("RTGUI_EVENT_WIN_DEACTIVATE\r\n");
rtgui_win_event_handler((struct rtgui_object *)object, event);
rtgui_timer_stop(timer);
}
else if (event->type == RTGUI_EVENT_KBD)
{
rtgui_win_event_handler((struct rtgui_object *)object, event);
snake_handler(widget, event);
}
else
{
rt_kprintf("event->type:%d\r\n", event->type);
return rtgui_win_event_handler((struct rtgui_object *)object, event);
}
return RT_FALSE;
}
static void timeout(struct rtgui_timer *timer, void *parameter)
{
struct rtgui_widget *widget;
SYS_STE ret;
if (!map)
return;
ret = snake_step(run_state, map);
if (OVER == ret)
return;
if (FOOD == ret)
{
snake_len++;
if (snake_len >= (map->width * map->height) / 3)
{
point_t start;
start.x = snake_init_pointx;
start.y = snake_init_pointy;
run_state = SNAKE_DIR_DOWN;
snake_len = snake_length_init;
if (!snake_restart(&start, snake_len, run_state, map))
{
map_deinit(map);
snake_deinit();
map = RT_NULL;
}
}
food_init(map, 1);
}
widget = RTGUI_WIDGET(parameter);
snake_update(widget);
}
void main(void)
{
struct rtgui_app *application;
struct rtgui_win *win;
rtgui_rect_t rect;
application = rtgui_app_create("sanke_app");
if (application != RT_NULL)
{
rtgui_get_screen_rect(&rect);
rtgui_set_mainwin_rect(&rect);
win = rtgui_mainwin_create(RT_NULL,
"sanke_win",
RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
if (win == RT_NULL)
{
rt_kprintf("sanke_win create fail!\r\n");
return;
}
rtgui_object_set_event_handler(RTGUI_OBJECT(win), event_handler);
timer = rtgui_timer_create(RT_TICK_PER_SECOND / 2,
RT_TIMER_FLAG_PERIODIC,
timeout,
(void *)win);
rtgui_win_show(win, RT_TRUE);
//˳ŷ
map_deinit(map);
snake_deinit();
food_deinit();
rtgui_app_destroy(application);
}
}
import rtconfig
Import('RTT_ROOT')
from building import *
src = Glob('*.c')
group = DefineGroup('', src, depend = [''])
Return('group')
\ No newline at end of file
#include <rtthread.h>
/* rtgui\common\rtgui_object.c */
_declspec(dllimport) void * _rtgui_object;
/* rtgui\common\color.c */
_declspec(dllimport) rt_uint32_t blue;
//extern rt_uint32_t * green;
int main(void)
{
int i;
//rt_kprintf("green = %x, *green", green, *(rt_uint32_t *)green);
rt_kprintf("blue = %x\n", blue);
rt_kprintf("_rtgui_object = %x\n", _rtgui_object);
return 0;
}
......@@ -15,7 +15,7 @@ if GetDepend('RT_USING_LWIP'):
src_drv += ['enc28j60.c'] + ['dm9000a.c']
if GetDepend('RT_USING_RTGUI'):
src_drv += ['touch.c', 'calibration.c']
src_drv += ['touch.c']
if GetDepend('RT_USING_RTGUI'):
if rtconfig.RT_USING_LCD_TYPE == 'FMT0371':
......
......@@ -41,6 +41,7 @@
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/driver.h>
#include <rtgui/calibration.h>
#endif
#include "led.h"
......@@ -73,6 +74,23 @@ static void led_thread_entry(void* parameter)
}
}
#ifdef RT_USING_RTGUI
rt_bool_t cali_setup(void)
{
rt_kprintf("cali setup entered\n");
return RT_FALSE;
}
void cali_store(struct calibration_data *data)
{
rt_kprintf("cali finished (%d, %d), (%d, %d)\n",
data->min_x,
data->max_x,
data->min_y,
data->max_y);
}
#endif
void rt_init_thread_entry(void* parameter)
{
/* Filesystem Initialization */
......@@ -149,6 +167,10 @@ void rt_init_thread_entry(void* parameter)
/* init rtgui system server */
rtgui_system_server_init();
calibration_set_restore(cali_setup);
calibration_set_after(cali_store);
calibration_init();
}
#endif /* #ifdef RT_USING_RTGUI */
}
......
#include <rtgui/rtgui.h>
#include <rtgui/dc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/window.h>
#include "touch.h"
#define CALIBRATION_STEP_LEFTTOP 0
#define CALIBRATION_STEP_RIGHTTOP 1
#define CALIBRATION_STEP_RIGHTBOTTOM 2
#define CALIBRATION_STEP_LEFTBOTTOM 3
#define CALIBRATION_STEP_CENTER 4
#define TOUCH_WIN_UPDATE 1
#define TOUCH_WIN_CLOSE 2
#define CALIBRATION_WIDTH 15
#define CALIBRATION_HEIGHT 15
struct calibration_session
{
rt_uint8_t step;
struct calibration_data data;
rt_uint16_t width; rt_uint16_t height;
rt_device_t device;
rt_thread_t tid;
};
static struct calibration_session* calibration_ptr = RT_NULL;
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y)
{
if (calibration_ptr != RT_NULL)
{
switch (calibration_ptr->step)
{
case CALIBRATION_STEP_LEFTTOP:
calibration_ptr->data.min_x = x;
calibration_ptr->data.min_y = y;
break;
case CALIBRATION_STEP_RIGHTTOP:
calibration_ptr->data.max_x = x;
calibration_ptr->data.min_y = (calibration_ptr->data.min_y + y)/2;
break;
case CALIBRATION_STEP_LEFTBOTTOM:
calibration_ptr->data.min_x = (calibration_ptr->data.min_x + x)/2;
calibration_ptr->data.max_y = y;
break;
case CALIBRATION_STEP_RIGHTBOTTOM:
calibration_ptr->data.max_x = (calibration_ptr->data.max_x + x)/2;
calibration_ptr->data.max_y = (calibration_ptr->data.max_y + y)/2;
break;
case CALIBRATION_STEP_CENTER:
/* calibration done */
{
rt_uint16_t w, h;
struct rtgui_event_command ecmd;
RTGUI_EVENT_COMMAND_INIT(&ecmd);
ecmd.command_id = TOUCH_WIN_CLOSE;
/* calculate calibrated data */
if (calibration_ptr->data.max_x > calibration_ptr->data.min_x)
w = calibration_ptr->data.max_x - calibration_ptr->data.min_x;
else
w = calibration_ptr->data.min_x - calibration_ptr->data.max_x;
w = (w/(calibration_ptr->width - 2 * CALIBRATION_WIDTH)) * CALIBRATION_WIDTH;
if (calibration_ptr->data.max_y > calibration_ptr->data.min_y)
h = calibration_ptr->data.max_y - calibration_ptr->data.min_y;
else
h = calibration_ptr->data.min_y - calibration_ptr->data.max_y;
h = (h/(calibration_ptr->height - 2 * CALIBRATION_HEIGHT)) * CALIBRATION_HEIGHT;
rt_kprintf("w: %d, h: %d\n", w, h);
if (calibration_ptr->data.max_x > calibration_ptr->data.min_x)
{
calibration_ptr->data.min_x -= w;
calibration_ptr->data.max_x += w;
}
else
{
calibration_ptr->data.min_x += w;
calibration_ptr->data.max_x -= w;
}
if (calibration_ptr->data.max_y > calibration_ptr->data.min_y)
{
calibration_ptr->data.min_y -= h;
calibration_ptr->data.max_y += h;
}
else
{
calibration_ptr->data.min_y += h;
calibration_ptr->data.max_y -= h;
}
rt_kprintf("calibration data: (%d, %d), (%d, %d)\n",
calibration_ptr->data.min_x,
calibration_ptr->data.max_x,
calibration_ptr->data.min_y,
calibration_ptr->data.max_y);
rtgui_thread_send(calibration_ptr->tid, &ecmd.parent, sizeof(struct rtgui_event_command));
}
return;
}
calibration_ptr->step ++;
/* post command event */
{
struct rtgui_event_command ecmd;
RTGUI_EVENT_COMMAND_INIT(&ecmd);
ecmd.command_id = TOUCH_WIN_UPDATE;
rtgui_thread_send(calibration_ptr->tid, &ecmd.parent, sizeof(struct rtgui_event_command));
}
}
}
rt_bool_t calibration_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
switch (event->type)
{
case RTGUI_EVENT_PAINT:
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) break;
/* get rect information */
rtgui_widget_get_rect(widget, &rect);
/* clear whole window */
RTGUI_WIDGET_BACKGROUND(widget) = white;
rtgui_dc_fill_rect(dc, &rect);
/* reset color */
RTGUI_WIDGET_BACKGROUND(widget) = green;
RTGUI_WIDGET_FOREGROUND(widget) = black;
switch (calibration_ptr->step)
{
case CALIBRATION_STEP_LEFTTOP:
rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, CALIBRATION_HEIGHT);
rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
RTGUI_WIDGET_FOREGROUND(widget) = red;
rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
break;
case CALIBRATION_STEP_RIGHTTOP:
rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
calibration_ptr->width, CALIBRATION_HEIGHT);
rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
RTGUI_WIDGET_FOREGROUND(widget) = red;
rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
break;
case CALIBRATION_STEP_LEFTBOTTOM:
rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT);
rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
RTGUI_WIDGET_FOREGROUND(widget) = red;
rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
break;
case CALIBRATION_STEP_RIGHTBOTTOM:
rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
calibration_ptr->width, calibration_ptr->height - CALIBRATION_HEIGHT);
rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
RTGUI_WIDGET_FOREGROUND(widget) = red;
rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
break;
case CALIBRATION_STEP_CENTER:
rtgui_dc_draw_hline(dc, calibration_ptr->width/2 - CALIBRATION_WIDTH, calibration_ptr->width/2 + CALIBRATION_WIDTH, calibration_ptr->height/2);
rtgui_dc_draw_vline(dc, calibration_ptr->width/2, calibration_ptr->height/2 - CALIBRATION_HEIGHT, calibration_ptr->height/2 + CALIBRATION_HEIGHT);
RTGUI_WIDGET_FOREGROUND(widget) = red;
rtgui_dc_fill_circle(dc, calibration_ptr->width/2, calibration_ptr->height/2, 4);
break;
}
rtgui_dc_end_drawing(dc);
}
break;
case RTGUI_EVENT_COMMAND:
{
struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;
switch (ecmd->command_id)
{
case TOUCH_WIN_UPDATE:
rtgui_widget_update(widget);
break;
case TOUCH_WIN_CLOSE:
rtgui_win_close(RTGUI_WIN(widget));
break;
}
}
return RT_TRUE;
default:
rtgui_win_event_handler(widget, event);
}
return RT_FALSE;
}
void calibration_entry(void* parameter)
{
rt_mq_t mq;
rtgui_win_t* win;
struct rtgui_rect rect;
mq = rt_mq_create("cali", 40, 8, RT_IPC_FLAG_FIFO);
if (mq == RT_NULL) return;
rtgui_thread_register(rt_thread_self(), mq);
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
/* set screen rect */
calibration_ptr->width = rect.x2;
calibration_ptr->height = rect.y2;
/* create calibration window */
win = rtgui_win_create(RT_NULL,
"calibration", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
rtgui_widget_set_event_handler(RTGUI_WIDGET(win), calibration_event_handler);
if (win != RT_NULL)
{
rtgui_win_show(win, RT_FALSE);
// rtgui_widget_update(RTGUI_WIDGET(win));
rtgui_win_event_loop(win);
}
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
/* set calibration data */
rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION_DATA, &calibration_ptr->data);
/* recover to normal */
rt_device_control(calibration_ptr->device, RT_TOUCH_NORMAL, RT_NULL);
/* release memory */
rt_free(calibration_ptr);
calibration_ptr = RT_NULL;
}
void calibration_init()
{
rt_device_t device;
device = rt_device_find("touch");
if (device == RT_NULL) return; /* no this device */
calibration_ptr = (struct calibration_session*)rt_malloc(sizeof(struct calibration_session));
rt_memset(calibration_ptr, 0, sizeof(struct calibration_data));
calibration_ptr->device = device;
rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION, (void*)calibration_data_post);
calibration_ptr->tid = rt_thread_create("cali", calibration_entry, RT_NULL,
2048, 20, 5);
if (calibration_ptr->tid != RT_NULL) rt_thread_startup(calibration_ptr->tid);
}
#ifdef RT_USING_FINSH
#include <finsh.h>
void calibration()
{
calibration_init();
}
FINSH_FUNCTION_EXPORT(calibration, perform touch calibration);
#endif
......@@ -14,8 +14,12 @@
* 2011-11-23 Bernard fixed the rename issue.
* 2012-07-26 aozima implement ff_memalloc and ff_memfree.
* 2012-12-19 Bernard fixed the O_APPEND and lseek issue.
* 2013-03-01 aozima fixed the stat(st_mtime) issue.
*/
#include <string.h>
#include <time.h>
#include <rtthread.h>
#include "ffconf.h"
#include "ff.h"
......@@ -178,7 +182,7 @@ int dfs_elm_mkfs(rt_device_t dev_id)
{
#define FSM_STATUS_INIT 0
#define FSM_STATUS_USE_TEMP_DRIVER 1
FATFS *fat;
FATFS *fat = RT_NULL;
int flag;
FRESULT result;
int index;
......@@ -710,8 +714,38 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
st->st_mode &= ~(DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH);
st->st_size = file_info.fsize;
st->st_mtime = file_info.ftime;
st->st_blksize = 512;
/* get st_mtime. */
{
struct tm tm_file;
int year, mon, day, hour, min, sec;
WORD tmp;
tmp = file_info.fdate;
day = tmp & 0x1F; /* bit[4:0] Day(1..31) */
tmp >>= 5;
mon = tmp & 0x0F; /* bit[8:5] Month(1..12) */
tmp >>= 4;
year = (tmp & 0x7F) + 1980; /* bit[15:9] Year origin from 1980(0..127) */
tmp = file_info.ftime;
sec = (tmp & 0x1F) * 2; /* bit[4:0] Second/2(0..29) */
tmp >>= 5;
min = tmp & 0x3F; /* bit[10:5] Minute(0..59) */
tmp >>= 6;
hour = tmp & 0x1F; /* bit[15:11] Hour(0..23) */
memset(&tm_file, 0, sizeof(tm_file));
tm_file.tm_year = year - 1900; /* Years since 1900 */
tm_file.tm_mon = mon - 1; /* Months *since* january: 0-11 */
tm_file.tm_mday = day; /* Day of the month: 1-31 */
tm_file.tm_hour = hour; /* Hours since midnight: 0-23 */
tm_file.tm_min = min; /* Minutes: 0-59 */
tm_file.tm_sec = sec; /* Seconds: 0-59 */
st->st_mtime = mktime(&tm_file);
} /* get st_mtime. */
}
#if _USE_LFN
......
from building import *
import os
'''
demo_view_dc_buffer.c
demo_fnview.c
demo_listview.c
demo_listview_icon.c
demo_panel_single.c
demo_view_box.c
demo_view_image.c
demo_view_module.c
'''
src = Split("""
demo_application.c
demo_view.c
demo_xml.c
demo_view_benchmark.c
demo_view_dc.c
demo_view_ttf.c
demo_view_dc_buffer.c
demo_view_animation.c
demo_view_buffer_animation.c
demo_view_instrument_panel.c
demo_view_window.c
demo_view_label.c
demo_view_button.c
demo_view_checkbox.c
demo_view_progressbar.c
demo_view_scrollbar.c
demo_view_radiobox.c
demo_view_textbox.c
demo_view_listbox.c
demo_view_menu.c
demo_view_listctrl.c
demo_view_combobox.c
demo_view_slider.c
demo_view_notebook.c
demo_view_mywidget.c
demo_view_box.c
demo_view_edit.c
demo_view_bmp.c
demo_plot.c
mywidget.c
demo_view_digtube.c
""")
if GetDepend('RTGUI_USING_FONT_COMPACT'):
import stract_cjk as sf
fl1 = sf.get_font_lib('hz16')
fl2 = sf.get_font_lib('hz12')
cwd = GetCurrentDir()
for i in src:
fl1.push_file(open(os.path.join(cwd, i), 'r'))
fl2.push_file(open(os.path.join(cwd, i), 'r'))
group = DefineGroup('gui_examples', src, depend = ['RT_USING_RTGUI'])
Return('group')
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/notebook.h>
struct rtgui_notebook *the_notebook;
static rt_bool_t demo_handle_key(struct rtgui_object *object, struct rtgui_event *event)
{
struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
if (ekbd->type == RTGUI_KEYUP)
{
if (ekbd->key == RTGUIK_RIGHT)
{
demo_view_next(RT_NULL, RT_NULL);
return RT_TRUE;
}
else if (ekbd->key == RTGUIK_LEFT)
{
demo_view_prev(RT_NULL, RT_NULL);
return RT_TRUE;
}
}
return RT_TRUE;
}
struct rtgui_win *main_win;
static void application_entry(void *parameter)
{
struct rtgui_app *app;
struct rtgui_rect rect;
app = rtgui_app_create("gui_demo");
if (app == RT_NULL)
return;
/* create a full screen window */
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
main_win = rtgui_win_create(RT_NULL, "demo_win", &rect,
RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
if (main_win == RT_NULL)
{
rtgui_app_destroy(app);
return;
}
rtgui_win_set_onkey(main_win, demo_handle_key);
/* create a no title notebook that we can switch demo on it easily. */
the_notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_NOTAB);
if (the_notebook == RT_NULL)
{
rtgui_win_destroy(main_win);
rtgui_app_destroy(app);
return;
}
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_buffer_animation();
demo_view_instrument_panel();
#endif
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 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();
#if defined(RTGUI_USING_DFS_FILERW)
demo_fn_view();
#endif
#endif
rtgui_win_show(main_win, RT_FALSE);
/* 执行工作台事件循环 */
rtgui_app_run(app);
rtgui_app_destroy(app);
}
void application_init()
{
static rt_bool_t inited = RT_FALSE;
if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
{
rt_thread_t tid;
tid = rt_thread_create("wb",
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 application()
{
application_init();
}
/* finsh的命令输出,可以直接执行application()函数以执行上面的函数 */
FINSH_FUNCTION_EXPORT(application, application demo)
#endif
此差异已折叠。
此差异已折叠。
此差异已折叠。
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_server.h>
/*
* Panel demo for 240x320
* info panel: (0, 0) - (240, 25)
* main panel: (0, 25) - (240, 320)
*/
void panel_init(void)
{
rtgui_rect_t rect;
/* register dock panel */
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = 240;
rect.y2 = 25;
rtgui_panel_register("info", &rect);
/* register main panel */
rect.x1 = 0;
rect.y1 = 25;
rect.x2 = 240;
rect.y2 = 320;
rtgui_panel_register("main", &rect);
rtgui_panel_set_default_focused("main");
}
#include <rtgui/rtgui.h>
#include <rtgui/driver.h>
#include <rtgui/rtgui_server.h>
/*
* a single panel
*/
void panel_init(void)
{
rtgui_rect_t rect;
/* register main panel */
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = rtgui_graphic_driver_get_default()->width;
rect.y2 = rtgui_graphic_driver_get_default()->height;
rtgui_panel_register("main", &rect);
rtgui_panel_set_default_focused("main");
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -21,6 +21,9 @@ struct rt_module_symtab
const char *name;
};
#if defined(_MSC_VER) || defined(__MINGW32__)
#define RTM_EXPORT(symbol)
#else
#define RTM_EXPORT(symbol) \
const char __rtmsym_##symbol##_name[] = #symbol; \
const struct rt_module_symtab __rtmsym_##symbol SECTION("RTMSymTab")= \
......@@ -28,6 +31,8 @@ const struct rt_module_symtab __rtmsym_##symbol SECTION("RTMSymTab")= \
(void *)&symbol, \
__rtmsym_##symbol##_name \
};
#endif
#else
#define RTM_EXPORT(symbol)
#endif
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册