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_remove_display() - Remove the SDL screen
30 *
31 * Return: 0 if OK, -ENOENT if the SDL had not been inited.
32 */
33 int sandbox_sdl_remove_display(void);
34
35 /**
36 * sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL
37 *
38 * This must be called periodically to update the screen for SDL so that the
39 * user can see it.
40 *
41 * @lcd_base: Base of frame buffer
42 * Return: 0 if screen was updated, -ENODEV is there is no screen.
43 */
44 int sandbox_sdl_sync(void *lcd_base);
45
46 /**
47 * sandbox_sdl_scan_keys() - scan for pressed keys
48 *
49 * Works out which keys are pressed and returns a list
50 *
51 * @key: Array to receive keycodes
52 * @max_keys: Size of array
53 * Return: number of keycodes found, 0 if none, -ENODEV if no keyboard
54 */
55 int sandbox_sdl_scan_keys(int key[], int max_keys);
56
57 /**
58 * sandbox_sdl_key_pressed() - check if a particular key is pressed
59 *
60 * @keycode: Keycode to check (KEY_... - see include/linux/input.h
61 * Return: 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not
62 * available,
63 */
64 int sandbox_sdl_key_pressed(int keycode);
65
66 /**
67 * sandbox_sdl_sound_play() - Play a sound
68 *
69 * @data: Data to play (typically 16-bit)
70 * @count: Number of bytes in data
71 */
72 int sandbox_sdl_sound_play(const void *data, uint count);
73
74 /**
75 * sandbox_sdl_sound_stop() - stop playing a sound
76 *
77 * Return: 0 if OK, -ENODEV if no sound is available
78 */
79 int sandbox_sdl_sound_stop(void);
80
81 /**
82 * sandbox_sdl_sound_init() - set up the sound system
83 *
84 * @rate: Sample rate to use
85 * @channels: Number of channels to use (1=mono, 2=stereo)
86 * Return: 0 if OK, -ENODEV if no sound is available
87 */
88 int sandbox_sdl_sound_init(int rate, int channels);
89
90 #else
sandbox_sdl_init_display(int width,int height,int log2_bpp,bool double_size)91 static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp,
92 bool double_size)
93 {
94 return -ENODEV;
95 }
96
sandbox_sdl_remove_display(void)97 static inline int sandbox_sdl_remove_display(void)
98 {
99 return -ENODEV;
100 }
101
sandbox_sdl_sync(void * lcd_base)102 static inline int sandbox_sdl_sync(void *lcd_base)
103 {
104 return -ENODEV;
105 }
106
sandbox_sdl_scan_keys(int key[],int max_keys)107 static inline int sandbox_sdl_scan_keys(int key[], int max_keys)
108 {
109 return -ENODEV;
110 }
111
sandbox_sdl_key_pressed(int keycode)112 static inline int sandbox_sdl_key_pressed(int keycode)
113 {
114 return -ENODEV;
115 }
116
sandbox_sdl_sound_start(uint frequency)117 static inline int sandbox_sdl_sound_start(uint frequency)
118 {
119 return -ENODEV;
120 }
121
sandbox_sdl_sound_play(const void * data,uint count)122 static inline int sandbox_sdl_sound_play(const void *data, uint count)
123 {
124 return -ENODEV;
125 }
126
sandbox_sdl_sound_stop(void)127 static inline int sandbox_sdl_sound_stop(void)
128 {
129 return -ENODEV;
130 }
131
sandbox_sdl_sound_init(int rate,int channels)132 static inline int sandbox_sdl_sound_init(int rate, int channels)
133 {
134 return -ENODEV;
135 }
136
137 #endif
138
139 #endif
140