SDL stands for "Simple DirectMedia Layer". It is simple, small and can access multimedia hardware directly. Therefore, it is particularly useful in developing applications for Embedded Linux systems as such systems usually have highly constrained resources. However, from time to time you may need to make modifications to the SDL libraries in order that they fully function in the embedded environment. In general, an Embedded Linux system does not support X-Window as it requires tremendous amount of resources to run; this may render the mouse useless. In order to use the mouse in a non-X environment, we need to make some minor modifications to the SDL libraries as of to date ( version 1.2.11 ). Very often, an embedded Linux development board provides one or more USB ports for I/O interface; the USB ports can be used to interface to a mouse, a keyboard or some other USB devices. In this chapter, we discuss how to modify SDL-1.2.11 to support USB I/O devices for Embedded Linux.
USB Mouse and Touch Screen ( TS ) InputMouse and TS have similar input mechanisms. For latest Linux versions, the devices in general can be accessed via
/dev/input/event0 or /dev/input/event1
For backward compatibility, the mouse may also be accessed via /dev/input/mice, /dev/input/mouse0, or/dev/input/mouse1, etc
You could test if the mouse works by the executing the command,
#cat /dev/input/event1
Moving the mouse around will display some random characters, mostly unprintable on the screen.In an ARM-9 board, most likely you can only see
/dev/input/event0
/dev/input/event1In this case, event0 is for ts ( touch screen ) and event1 is for mouse or keyboard, depending on what you have plugged in the USB port. Again, you can use the command "cat /dev/input/eventn" to test if you could open the device.SDL mouse support
SDL does not support USB mouse directly ( in a PC, SDL utilizes X-window routine to handle the mouse but in our ARM board, we use the frame buffer routine directly ). To support USB mouse and touch screen, we may modify some of the source files of the SDL-1.2.11 library as follows.You need to modify the following three files located at src/video/fbcon of the SDL source code tree:
SDL_fbevents.c
SDL_fbevents_c.h
SDL_fbvideo.c
First, add functions in SDL_fbvideo.c to handle mouse/ts I/Os ( note that we use SELECT to handle I/O ):
static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) ... #ifdef __ARM__ if ( FB_OpenEventX(this) == 0 ) { SDL_SetError("Unable to open /dev/input/eventX"); FB_VideoQuit(this); return(-1); } #else //PC original code #endif
Second, add function prototypes to header file SDL_fbevents_c.h:
static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) extern int FB_OpenEventX(_THIS); extern void FB_CloseEventX(_THIS); extern void FB_vgamousecallback(int button, int relative, int dx, int dy);
After you've made the above modifications, recompile the SDL library as discussed in the previous chapters. The new library will support both USB mouse and touch screen.