Browse Source

add sdl driver for simulator; update scripts in simulator

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2415 bbd45198-f89e-11dd-88c7-29a3b14d5316
goprife@gmail.com 12 years ago
parent
commit
3112b09c8f

+ 26 - 7
bsp/simulator/SConstruct

@@ -7,6 +7,11 @@ if os.getenv('RTT_ROOT'):
 else:
     RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
 
+# if you want use the rtgui in the svn (in google code), you should
+# comment the following line
+RTT_RTGUI = os.path.normpath('F:/Project/git/rt-gui')
+#RTT_RTGUI =''
+
 sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
 from building import *
 
@@ -17,8 +22,6 @@ env = Environment()
 Export('RTT_ROOT')
 Export('rtconfig')
 
-# prepare building environment
-
 libs = Split('''
 kernel32
 msvcrt
@@ -48,13 +51,29 @@ env.Append(LINKFLAGS=rtconfig.LFLAGS)
 env['LIBS']=libs
 env['CPPDEFINES']=definitions
 
-objs = PrepareBuilding(env, RTT_ROOT)
-
-# firemare library building script
-# objs = objs + SConscript( GetCurrentDir() + '/Libraries/SConscript', variant_dir='build/bsp/Libraries', duplicate=0)
+# prepare building environment
+if RTT_RTGUI:
+    objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False, remove_components=['rtgui'])
+    objs += SConscript(os.path.join(RTT_RTGUI + '/components/rtgui', 'SConscript'),
+					   variant_dir='build/components/rtgui',
+					   duplicate=0)
+else:
+    objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
 
 if GetDepend('RT_USING_RTGUI'):
-    objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0)
+    sdl_lib = ['SDL', 'SDLmain']
+    sdl_lib_path = os.path.normpath('SDL/lib/x86')
+    sdl_include_path = os.path.normpath('SDL/include')
+    env.Append(LIBS=sdl_lib)
+    env.Append(LIBPATH=sdl_lib_path)
+    env.Append(CPPPATH=sdl_include_path)
+
+    if RTT_RTGUI:
+        objs = objs + SConscript(RTT_RTGUI+'/demo/examples/SConscript', 
+				variant_dir='build/examples/gui', duplicate=0)
+    else:
+        objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', 
+				variant_dir='build/examples/gui', duplicate=0)
 
 # build program 
 env.Program(TARGET, objs)

+ 2 - 6
bsp/simulator/applications/platform.c

@@ -20,14 +20,10 @@ void rt_platform_init(void)
 #endif /* RT_USING_DFS */
 
 #ifdef RT_USING_RTGUI
-    /* initilize touch panel */
-    rtgui_touch_hw_init("spi21");
 
-    /* initilize ra8875 lcd controller */
-    ra8875_init();
+    /* initilize sdl */
+	 sdl_start();
 
-    /* initilize key module */
-    rt_hw_key_init();
 #endif /* RT_USING_RTGUI */
 
     rt_thread_delay(50);

+ 298 - 0
bsp/simulator/drivers/sdl_fb.c

@@ -0,0 +1,298 @@
+#include <rtthread.h>
+
+#include <sdl.h>
+#include <rtdevice.h>
+#include <rtgui/driver.h>
+
+#define SDL_SCREEN_WIDTH	240
+#define SDL_SCREEN_HEIGHT	320
+
+struct sdlfb_device
+{
+	struct rt_device parent;
+
+	SDL_Surface *screen;
+	rt_uint16_t width;
+	rt_uint16_t height;
+};
+struct sdlfb_device _device;
+
+/* common device interface */
+static rt_err_t  sdlfb_init(rt_device_t dev)
+{
+	return RT_EOK;
+}
+static rt_err_t  sdlfb_open(rt_device_t dev, rt_uint16_t oflag)
+{
+	return RT_EOK;
+}
+static rt_err_t  sdlfb_close(rt_device_t dev)
+{
+	SDL_Quit();
+	return RT_EOK;
+}
+static rt_err_t  sdlfb_control(rt_device_t dev, rt_uint8_t cmd, void *args)
+{
+	struct sdlfb_device *device;
+
+	device = (struct sdlfb_device*)dev;
+	RT_ASSERT(device != RT_NULL);
+	RT_ASSERT(device->screen != RT_NULL);
+
+	switch (cmd)
+	{
+	case RTGRAPHIC_CTRL_GET_INFO:
+		{
+		struct rt_device_graphic_info *info;
+
+		info = (struct rt_device_graphic_info*) args;
+		info->bits_per_pixel = 16;
+		info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
+		info->framebuffer = device->screen->pixels;
+		info->width = device->screen->w;
+		info->height = device->screen->h;
+		}
+		break;
+	case RTGRAPHIC_CTRL_RECT_UPDATE:
+		{
+		struct rt_device_rect_info *rect;
+		rect = (struct rt_device_rect_info*)args;
+
+		/* SDL_UpdateRect(_device.screen, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); */
+		SDL_UpdateRect(_device.screen, 0, 0, device->width, device->height);
+		}
+		break;
+	case RTGRAPHIC_CTRL_SET_MODE:
+		{		
+#if 0
+		struct rt_device_rect_info* rect;
+
+		rect = (struct rt_device_rect_info*)args;
+		if ((_device.width == rect->width) && (_device.height == rect->height)) return -RT_ERROR;
+		
+		_device.width = rect->width;
+		_device.height = rect->height;
+		
+		if (_device.screen != RT_NULL)
+		{
+			SDL_FreeSurface(_device.screen);
+		
+			/* re-create screen surface */
+			_device.screen = SDL_SetVideoMode(_device.width, _device.height, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
+			if ( _device.screen == NULL )
+			{
+				fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
+				exit(1);
+			}
+
+			SDL_WM_SetCaption ("RT-Thread/GUI Simulator", NULL);
+		}
+#endif
+		}
+		break;
+	}
+
+	return RT_EOK;
+}
+
+static void sdlfb_hw_init(void)
+{
+	/* set video driver for VC++ debug */
+	//_putenv("SDL_VIDEODRIVER=windib");
+
+	//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0)
+	if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
+	{
+        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
+        exit(1);
+    }
+
+	_device.parent.init = sdlfb_init;
+	_device.parent.open = sdlfb_open;
+	_device.parent.close = sdlfb_close;
+	_device.parent.read = RT_NULL;
+	_device.parent.write = RT_NULL;
+	_device.parent.control = sdlfb_control;
+
+	_device.width  = SDL_SCREEN_WIDTH;
+	_device.height = SDL_SCREEN_HEIGHT;
+	_device.screen = SDL_SetVideoMode(_device.width, _device.height, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
+    if (_device.screen == NULL)
+	{
+        fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
+        exit(1);
+    }
+
+	SDL_WM_SetCaption ("RT-Thread/GUI Simulator", NULL);
+	rt_device_register(RT_DEVICE(&_device), "sdl", RT_DEVICE_FLAG_RDWR);
+}
+
+#include  <windows.h>
+#include  <mmsystem.h>
+#include  <stdio.h>
+#include <sdl.h>
+#include <rtgui/event.h>
+#include <rtgui/kbddef.h>
+#include <rtgui/rtgui_server.h>
+#include <rtgui/rtgui_system.h>
+
+static DWORD WINAPI sdl_loop(LPVOID lpParam)
+{
+	int quit = 0;
+	SDL_Event event;
+	int button_state = 0;
+
+	rt_device_t device;
+	sdlfb_hw_init();
+
+	device = rt_device_find("sdl");
+	rtgui_graphic_set_device(device);
+
+	/* handle SDL event */
+	while(!quit)
+	{
+		while ( SDL_PollEvent(&event) )
+		{
+			switch (event.type)
+			{
+			case SDL_MOUSEMOTION:
+				{
+					struct rtgui_event_mouse emouse;
+					emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
+					emouse.parent.sender = RT_NULL;
+					emouse.wid = RT_NULL;
+
+					emouse.x = ((SDL_MouseMotionEvent*)&event)->x;
+					emouse.y = ((SDL_MouseMotionEvent*)&event)->y;
+
+					/* init mouse button */
+					emouse.button = button_state;
+
+					/* send event to server */
+					rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
+				}
+				break;
+
+			case SDL_MOUSEBUTTONDOWN:
+			case SDL_MOUSEBUTTONUP:
+				{
+					struct rtgui_event_mouse emouse;
+					SDL_MouseButtonEvent* mb;
+
+					emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
+					emouse.parent.sender = RT_NULL;
+					emouse.wid = RT_NULL;
+
+					mb = (SDL_MouseButtonEvent*)&event;
+
+					emouse.x = mb->x;
+					emouse.y = mb->y;
+
+					/* init mouse button */
+					emouse.button = 0;
+
+					/* set emouse button */
+					if (mb->button & (1 << (SDL_BUTTON_LEFT - 1)) )
+					{
+						emouse.button |= RTGUI_MOUSE_BUTTON_LEFT;
+					}
+					else if (mb->button & (1 << (SDL_BUTTON_RIGHT - 1)))
+					{
+						emouse.button |= RTGUI_MOUSE_BUTTON_RIGHT;
+					}
+					else if (mb->button & (1 << (SDL_BUTTON_MIDDLE - 1)))
+					{
+						emouse.button |= RTGUI_MOUSE_BUTTON_MIDDLE;
+					}
+
+					if (mb->type == SDL_MOUSEBUTTONDOWN)
+					{
+						emouse.button |= RTGUI_MOUSE_BUTTON_DOWN;
+						button_state = emouse.button;
+					}
+					else
+					{
+						emouse.button |= RTGUI_MOUSE_BUTTON_UP;
+						button_state = 0;
+					}
+
+
+					/* send event to server */
+					rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
+				}
+				break;
+
+			case SDL_KEYUP:
+				{
+					struct rtgui_event_kbd ekbd;
+					ekbd.parent.type	= RTGUI_EVENT_KBD;
+					ekbd.parent.sender	= RT_NULL;
+					ekbd.type = RTGUI_KEYUP;
+					ekbd.wid = RT_NULL;
+					ekbd.mod = event.key.keysym.mod;
+					ekbd.key = event.key.keysym.sym;
+
+					/* FIXME: unicode */
+					ekbd.unicode = 0;
+
+					/* send event to server */
+					rtgui_server_post_event(&ekbd.parent, sizeof(struct rtgui_event_kbd));
+				}
+				break;
+
+			case SDL_KEYDOWN:
+				{
+					struct rtgui_event_kbd ekbd;
+					ekbd.parent.type	= RTGUI_EVENT_KBD;
+					ekbd.parent.sender	= RT_NULL;
+					ekbd.type = RTGUI_KEYDOWN;
+					ekbd.wid = RT_NULL;
+					ekbd.mod = event.key.keysym.mod;
+					ekbd.key = event.key.keysym.sym;
+
+					/* FIXME: unicode */
+					ekbd.unicode = 0;
+
+					/* send event to server */
+					rtgui_server_post_event(&ekbd.parent, sizeof(struct rtgui_event_kbd));
+				}
+				break;
+
+			case SDL_QUIT:
+				SDL_Quit();
+				quit = 1;
+				break;
+
+			default:
+				break;
+			}
+
+			SDL_Delay(20);
+		}
+		if (quit)
+			break;
+	}
+	//exit(0);
+	return 0;
+}
+
+void sdl_start(void)
+{
+	HANDLE thread;
+	DWORD  thread_id; 
+
+	/* create thread that loop sdl event */
+    thread = CreateThread(NULL,
+                          0,
+                         (LPTHREAD_START_ROUTINE)sdl_loop,
+                          0,
+                          CREATE_SUSPENDED,
+                          &thread_id);
+    if(thread == NULL)
+    {
+        //Display Error Message
+
+        return;
+    }
+    ResumeThread(thread);
+}

+ 1 - 1
bsp/simulator/rtconfig.py

@@ -59,7 +59,7 @@ elif PLATFORM == 'cl':
     LINK = PREFIX + 'cl'
     AFLAGS = ''
 
-    CFLAGS = '/MT /ZI /Od /W 3 /WL /DMSVC /D_TIME_T_DEFINED'
+    CFLAGS = '/MT /ZI /Od /W 3 /WL '
     #LFLAGS = '/SUBSYSTEM:WINDOWS /NODEFAULTLIB /MACHINE:X86 /DEBUG'
     LFLAGS = '/SUBSYSTEM:CONSOLE /NODEFAULTLIB /MACHINE:X86 '