Raspberry Pi support (also unified UDEV and EVDEV support)

1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/README-raspberrypi.txt Sat Sep 28 13:28:19 2013 -0300 1.3 @@ -0,0 +1,48 @@ 1.4 +================================================================================ 1.5 +SDL2 for Raspberry Pi 1.6 +================================================================================ 1.7 + 1.8 +Requirements: 1.9 + 1.10 +Raspbian (other Linux distros may work as well). 1.11 + 1.12 +================================================================================ 1.13 + Features 1.14 +================================================================================ 1.15 + 1.16 +* Works without X11 1.17 +* Hardware accelerated OpenGL ES 2.x 1.18 +* Sound via ALSA 1.19 +* Input (mouse/keyboard/joystick) via EVDEV 1.20 +* Hotplugging of input devices via UDEV 1.21 + 1.22 +================================================================================ 1.23 + Raspbian Build Dependencies 1.24 +================================================================================ 1.25 + 1.26 +sudo apt-get install libudev-dev libasound2-dev 1.27 + 1.28 +You also need the VideoCore binary stuff that ships in /opt/vc for EGL and 1.29 +OpenGL ES 2.x, it usually comes pre installed, but in any case: 1.30 + 1.31 +sudo apt-get install libraspberrypi0 libraspberrypi-bin libraspberrypi-dev 1.32 + 1.33 +================================================================================ 1.34 + No HDMI Audio 1.35 +================================================================================ 1.36 + 1.37 +If you notice that ALSA works but there's no audio over HDMI, try adding: 1.38 + 1.39 + hdmi_drive=2 1.40 + 1.41 +to your config.txt file and reboot. 1.42 + 1.43 +Reference: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=5062 1.44 + 1.45 +================================================================================ 1.46 + Notes 1.47 +================================================================================ 1.48 + 1.49 +* Building has only been tested natively (i.e. not cross compiled). Cross 1.50 + compilation might work though, feedback is welcome! 1.51 +* No Text Input yet. 1.52 \ No newline at end of file

10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/src/input/evdev/SDL_evdev.h Sat Sep 28 13:28:19 2013 -0300 10.3 @@ -0,0 +1,65 @@ 10.4 +/* 10.5 + Simple DirectMedia Layer 10.6 + Copyright (C) 1997-2013 Sam Lantinga 10.7 + 10.8 + This software is provided 'as-is', without any express or implied 10.9 + warranty. In no event will the authors be held liable for any damages 10.10 + arising from the use of this software. 10.11 + 10.12 + Permission is granted to anyone to use this software for any purpose, 10.13 + including commercial applications, and to alter it and redistribute it 10.14 + freely, subject to the following restrictions: 10.15 + 10.16 + 1. The origin of this software must not be misrepresented; you must not 10.17 + claim that you wrote the original software. If you use this software 10.18 + in a product, an acknowledgment in the product documentation would be 10.19 + appreciated but is not required. 10.20 + 2. Altered source versions must be plainly marked as such, and must not be 10.21 + misrepresented as being the original software. 10.22 + 3. This notice may not be removed or altered from any source distribution. 10.23 +*/ 10.24 + 10.25 +#include 10.26 + 10.27 +#include "SDL_config.h" 10.28 + 10.29 +#ifndef _SDL_evdev_h 10.30 +#define _SDL_evdev_h 10.31 + 10.32 +#ifdef SDL_INPUT_LINUXEV 10.33 + 10.34 +#include "SDL_events.h" 10.35 +#include 10.36 + 10.37 +typedef enum 10.38 +{ 10.39 + SDL_EVDEV_DEVICE_MOUSE = 0x0001, 10.40 + SDL_EVDEV_DEVICE_KEYBOARD 10.41 +} SDL_EVDEV_deviceclass; 10.42 + 10.43 +typedef struct SDL_evdevlist_item 10.44 +{ 10.45 + char *path; 10.46 + int fd; 10.47 + SDL_EVDEV_deviceclass devclass; 10.48 + struct SDL_evdevlist_item *next; 10.49 +} SDL_evdevlist_item; 10.50 + 10.51 +typedef struct SDL_EVDEV_PrivateData 10.52 +{ 10.53 + SDL_evdevlist_item *first; 10.54 + SDL_evdevlist_item *last; 10.55 + int numdevices; 10.56 + int ref_count; 10.57 +} SDL_EVDEV_PrivateData; 10.58 + 10.59 +extern int SDL_EVDEV_Init(void); 10.60 +extern void SDL_EVDEV_Quit(void); 10.61 +extern void SDL_EVDEV_Poll(void); 10.62 + 10.63 + 10.64 +#endif /* SDL_INPUT_LINUXEV */ 10.65 + 10.66 +#endif /* _SDL_evdev_h */ 10.67 + 10.68 +/* vi: set ts=4 sw=4 expandtab: */

14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/src/video/raspberry/SDL_rpievents.c Sat Sep 28 13:28:19 2013 -0300 14.3 @@ -0,0 +1,45 @@ 14.4 +/* 14.5 + Simple DirectMedia Layer 14.6 + Copyright (C) 1997-2013 Sam Lantinga 14.7 + 14.8 + This software is provided 'as-is', without any express or implied 14.9 + warranty. In no event will the authors be held liable for any damages 14.10 + arising from the use of this software. 14.11 + 14.12 + Permission is granted to anyone to use this software for any purpose, 14.13 + including commercial applications, and to alter it and redistribute it 14.14 + freely, subject to the following restrictions: 14.15 + 14.16 + 1. The origin of this software must not be misrepresented; you must not 14.17 + claim that you wrote the original software. If you use this software 14.18 + in a product, an acknowledgment in the product documentation would be 14.19 + appreciated but is not required. 14.20 + 2. Altered source versions must be plainly marked as such, and must not be 14.21 + misrepresented as being the original software. 14.22 + 3. This notice may not be removed or altered from any source distribution. 14.23 +*/ 14.24 + 14.25 +#include "SDL_config.h" 14.26 + 14.27 +#if SDL_VIDEO_DRIVER_RPI 14.28 + 14.29 +#include "../../events/SDL_sysevents.h" 14.30 +#include "../../events/SDL_events_c.h" 14.31 +#include "../../events/SDL_keyboard_c.h" 14.32 +#include "SDL_rpivideo.h" 14.33 +#include "SDL_rpievents_c.h" 14.34 + 14.35 +#ifdef SDL_INPUT_LINUXEV 14.36 +#include "../../input/evdev/SDL_evdev.h" 14.37 +#endif 14.38 + 14.39 +void RPI_PumpEvents(_THIS) 14.40 +{ 14.41 +#ifdef SDL_INPUT_LINUXEV 14.42 + SDL_EVDEV_Poll(); 14.43 +#endif 14.44 + 14.45 +} 14.46 + 14.47 +#endif /* SDL_VIDEO_DRIVER_RPI */ 14.48 +

15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/src/video/raspberry/SDL_rpievents_c.h Sat Sep 28 13:28:19 2013 -0300 15.3 @@ -0,0 +1,31 @@ 15.4 +/* 15.5 + Simple DirectMedia Layer 15.6 + Copyright (C) 1997-2013 Sam Lantinga 15.7 + 15.8 + This software is provided 'as-is', without any express or implied 15.9 + warranty. In no event will the authors be held liable for any damages 15.10 + arising from the use of this software. 15.11 + 15.12 + Permission is granted to anyone to use this software for any purpose, 15.13 + including commercial applications, and to alter it and redistribute it 15.14 + freely, subject to the following restrictions: 15.15 + 15.16 + 1. The origin of this software must not be misrepresented; you must not 15.17 + claim that you wrote the original software. If you use this software 15.18 + in a product, an acknowledgment in the product documentation would be 15.19 + appreciated but is not required. 15.20 + 2. Altered source versions must be plainly marked as such, and must not be 15.21 + misrepresented as being the original software. 15.22 + 3. This notice may not be removed or altered from any source distribution. 15.23 +*/ 15.24 + 15.25 +#ifndef _SDL_rpievents_c_h 15.26 +#define _SDL_rpievents_c_h 15.27 + 15.28 +#include "SDL_rpivideo.h" 15.29 + 15.30 +void RPI_PumpEvents(_THIS); 15.31 +void RPI_EventInit(_THIS); 15.32 +void RPI_EventQuit(_THIS); 15.33 + 15.34 +#endif /* _SDL_rpievents_c_h */

17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/src/video/raspberry/SDL_rpimouse.h Sat Sep 28 13:28:19 2013 -0300 17.3 @@ -0,0 +1,43 @@ 17.4 +/* 17.5 + Simple DirectMedia Layer 17.6 + Copyright (C) 1997-2013 Sam Lantinga 17.7 + 17.8 + This software is provided 'as-is', without any express or implied 17.9 + warranty. In no event will the authors be held liable for any damages 17.10 + arising from the use of this software. 17.11 + 17.12 + Permission is granted to anyone to use this software for any purpose, 17.13 + including commercial applications, and to alter it and redistribute it 17.14 + freely, subject to the following restrictions: 17.15 + 17.16 + 1. The origin of this software must not be misrepresented; you must not 17.17 + claim that you wrote the original software. If you use this software 17.18 + in a product, an acknowledgment in the product documentation would be 17.19 + appreciated but is not required. 17.20 + 2. Altered source versions must be plainly marked as such, and must not be 17.21 + misrepresented as being the original software. 17.22 + 3. This notice may not be removed or altered from any source distribution. 17.23 +*/ 17.24 + 17.25 +#ifndef _SDL_RPI_mouse_h 17.26 +#define _SDL_RPI_mouse_h 17.27 + 17.28 +#include "../SDL_sysvideo.h" 17.29 + 17.30 +typedef struct _RPI_CursorData RPI_CursorData; 17.31 +struct _RPI_CursorData 17.32 +{ 17.33 + DISPMANX_RESOURCE_HANDLE_T resource; 17.34 + DISPMANX_ELEMENT_HANDLE_T element; 17.35 + int hot_x, hot_y; 17.36 + int w, h; 17.37 +}; 17.38 + 17.39 +#define SDL_RPI_CURSORDATA(curs) RPI_CursorData *curdata = (RPI_CursorData *) ((curs) ? (curs)->driverdata : NULL) 17.40 + 17.41 +extern void RPI_InitMouse(_THIS); 17.42 +extern void RPI_QuitMouse(_THIS); 17.43 + 17.44 +#endif /* _SDL_RPI_mouse_h */ 17.45 + 17.46 +/* vi: set ts=4 sw=4 expandtab: */

18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/src/video/raspberry/SDL_rpiopengles.c Sat Sep 28 13:28:19 2013 -0300 18.3 @@ -0,0 +1,42 @@ 18.4 +/* 18.5 + Simple DirectMedia Layer 18.6 + Copyright (C) 1997-2013 Sam Lantinga 18.7 + 18.8 + This software is provided 'as-is', without any express or implied 18.9 + warranty. In no event will the authors be held liable for any damages 18.10 + arising from the use of this software. 18.11 + 18.12 + Permission is granted to anyone to use this software for any purpose, 18.13 + including commercial applications, and to alter it and redistribute it 18.14 + freely, subject to the following restrictions: 18.15 + 18.16 + 1. The origin of this software must not be misrepresented; you must not 18.17 + claim that you wrote the original software. If you use this software 18.18 + in a product, an acknowledgment in the product documentation would be 18.19 + appreciated but is not required. 18.20 + 2. Altered source versions must be plainly marked as such, and must not be 18.21 + misrepresented as being the original software. 18.22 + 3. This notice may not be removed or altered from any source distribution. 18.23 +*/ 18.24 +#include "SDL_config.h" 18.25 + 18.26 +#if SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL 18.27 + 18.28 +#include "SDL_rpivideo.h" 18.29 +#include "SDL_rpiopengles.h" 18.30 + 18.31 +/* EGL implementation of SDL OpenGL support */ 18.32 + 18.33 +int 18.34 +RPI_GLES_LoadLibrary(_THIS, const char *path) { 18.35 + return SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY); 18.36 +} 18.37 + 18.38 +SDL_EGL_CreateContext_impl(RPI) 18.39 +SDL_EGL_SwapWindow_impl(RPI) 18.40 +SDL_EGL_MakeCurrent_impl(RPI) 18.41 + 18.42 +#endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */ 18.43 + 18.44 +/* vi: set ts=4 sw=4 expandtab: */ 18.45 +