1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2013 Google, Inc
4  */
5 
6 #ifndef __SANDBOX_SDL_H
7 #define __SANDBOX_SDL_H
8 
9 #include <errno.h>
10 
11 #ifdef CONFIG_SANDBOX_SDL
12 
13 /**
14  * sandbox_sdl_init_display() - Set up SDL video ready for use
15  *
16  * @width:	Window width in pixels
17  * @height	Window height in pixels
18  * @log2_bpp:	Log to base 2 of the number of bits per pixel. So a 32bpp
19  *		display will pass 5, since 2*5 = 32
20  * @double_size: true to double the visible size in each direction for high-DPI
21  *		displays
22  * @return 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize
23  *		and -EPERM if the video failed to come up.
24  */
25 int sandbox_sdl_init_display(int width, int height, int log2_bpp,
26 			     bool double_size);
27 
28 /**
29  * sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL
30  *
31  * This must be called periodically to update the screen for SDL so that the
32  * user can see it.
33  *
34  * @lcd_base: Base of frame buffer
35  * @return 0 if screen was updated, -ENODEV is there is no screen.
36  */
37 int sandbox_sdl_sync(void *lcd_base);
38 
39 /**
40  * sandbox_sdl_scan_keys() - scan for pressed keys
41  *
42  * Works out which keys are pressed and returns a list
43  *
44  * @key:	Array to receive keycodes
45  * @max_keys:	Size of array
46  * @return number of keycodes found, 0 if none, -ENODEV if no keyboard
47  */
48 int sandbox_sdl_scan_keys(int key[], int max_keys);
49 
50 /**
51  * sandbox_sdl_key_pressed() - check if a particular key is pressed
52  *
53  * @keycode:	Keycode to check (KEY_... - see include/linux/input.h
54  * @return 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not
55  * available,
56  */
57 int sandbox_sdl_key_pressed(int keycode);
58 
59 /**
60  * sandbox_sdl_sound_play() - Play a sound
61  *
62  * @data:	Data to play (typically 16-bit)
63  * @count:	Number of bytes in data
64  */
65 int sandbox_sdl_sound_play(const void *data, uint count);
66 
67 /**
68  * sandbox_sdl_sound_stop() - stop playing a sound
69  *
70  * @return 0 if OK, -ENODEV if no sound is available
71  */
72 int sandbox_sdl_sound_stop(void);
73 
74 /**
75  * sandbox_sdl_sound_init() - set up the sound system
76  *
77  * @rate:	Sample rate to use
78  * @channels:	Number of channels to use (1=mono, 2=stereo)
79  * @return 0 if OK, -ENODEV if no sound is available
80  */
81 int sandbox_sdl_sound_init(int rate, int channels);
82 
83 #else
sandbox_sdl_init_display(int width,int height,int log2_bpp,bool double_size)84 static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp,
85 					   bool double_size)
86 {
87 	return -ENODEV;
88 }
89 
sandbox_sdl_sync(void * lcd_base)90 static inline int sandbox_sdl_sync(void *lcd_base)
91 {
92 	return -ENODEV;
93 }
94 
sandbox_sdl_scan_keys(int key[],int max_keys)95 static inline int sandbox_sdl_scan_keys(int key[], int max_keys)
96 {
97 	return -ENODEV;
98 }
99 
sandbox_sdl_key_pressed(int keycode)100 static inline int sandbox_sdl_key_pressed(int keycode)
101 {
102 	return -ENODEV;
103 }
104 
sandbox_sdl_sound_start(uint frequency)105 static inline int sandbox_sdl_sound_start(uint frequency)
106 {
107 	return -ENODEV;
108 }
109 
sandbox_sdl_sound_play(const void * data,uint count)110 static inline int sandbox_sdl_sound_play(const void *data, uint count)
111 {
112 	return -ENODEV;
113 }
114 
sandbox_sdl_sound_stop(void)115 static inline int sandbox_sdl_sound_stop(void)
116 {
117 	return -ENODEV;
118 }
119 
sandbox_sdl_sound_init(int rate,int channels)120 static inline int sandbox_sdl_sound_init(int rate, int channels)
121 {
122 	return -ENODEV;
123 }
124 
125 #endif
126 
127 #endif
128