blob: ee4991f7c24aeb8518b3f97b1edd03809b30b213 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassbbc09bf2014-02-27 13:26:17 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glassbbc09bf2014-02-27 13:26:17 -07004 */
5
6#ifndef __SANDBOX_SDL_H
7#define __SANDBOX_SDL_H
8
9#include <errno.h>
Sergei Antonov76e16072023-06-13 00:19:04 +030010#include <video.h>
Simon Glassbbc09bf2014-02-27 13:26:17 -070011
12#ifdef CONFIG_SANDBOX_SDL
13
14/**
15 * sandbox_sdl_init_display() - Set up SDL video ready for use
16 *
17 * @width: Window width in pixels
18 * @height Window height in pixels
19 * @log2_bpp: Log to base 2 of the number of bits per pixel. So a 32bpp
20 * display will pass 5, since 2*5 = 32
Simon Glass6be88c72020-02-03 07:36:13 -070021 * @double_size: true to double the visible size in each direction for high-DPI
22 * displays
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010023 * Return: 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize
Simon Glassbbc09bf2014-02-27 13:26:17 -070024 * and -EPERM if the video failed to come up.
25 */
Simon Glass6be88c72020-02-03 07:36:13 -070026int sandbox_sdl_init_display(int width, int height, int log2_bpp,
27 bool double_size);
Simon Glassbbc09bf2014-02-27 13:26:17 -070028
29/**
Simon Glass250e7352021-11-19 13:23:46 -070030 * sandbox_sdl_remove_display() - Remove the SDL screen
31 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010032 * Return: 0 if OK, -ENOENT if the SDL had not been inited.
Simon Glass250e7352021-11-19 13:23:46 -070033 */
34int sandbox_sdl_remove_display(void);
35
36/**
Simon Glassbbc09bf2014-02-27 13:26:17 -070037 * sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL
38 *
39 * This must be called periodically to update the screen for SDL so that the
40 * user can see it.
41 *
42 * @lcd_base: Base of frame buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010043 * Return: 0 if screen was updated, -ENODEV is there is no screen.
Simon Glassbbc09bf2014-02-27 13:26:17 -070044 */
45int sandbox_sdl_sync(void *lcd_base);
46
47/**
48 * sandbox_sdl_scan_keys() - scan for pressed keys
49 *
50 * Works out which keys are pressed and returns a list
51 *
52 * @key: Array to receive keycodes
53 * @max_keys: Size of array
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010054 * Return: number of keycodes found, 0 if none, -ENODEV if no keyboard
Simon Glassbbc09bf2014-02-27 13:26:17 -070055 */
56int sandbox_sdl_scan_keys(int key[], int max_keys);
57
58/**
59 * sandbox_sdl_key_pressed() - check if a particular key is pressed
60 *
61 * @keycode: Keycode to check (KEY_... - see include/linux/input.h
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010062 * Return: 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not
Simon Glassbbc09bf2014-02-27 13:26:17 -070063 * available,
64 */
65int sandbox_sdl_key_pressed(int keycode);
66
67/**
Simon Glassf2b25c92018-12-10 10:37:47 -070068 * sandbox_sdl_sound_play() - Play a sound
Simon Glassbbc09bf2014-02-27 13:26:17 -070069 *
Simon Glassf2b25c92018-12-10 10:37:47 -070070 * @data: Data to play (typically 16-bit)
71 * @count: Number of bytes in data
Simon Glassbbc09bf2014-02-27 13:26:17 -070072 */
Simon Glassf2b25c92018-12-10 10:37:47 -070073int sandbox_sdl_sound_play(const void *data, uint count);
Simon Glassbbc09bf2014-02-27 13:26:17 -070074
75/**
76 * sandbox_sdl_sound_stop() - stop playing a sound
77 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010078 * Return: 0 if OK, -ENODEV if no sound is available
Simon Glassbbc09bf2014-02-27 13:26:17 -070079 */
80int sandbox_sdl_sound_stop(void);
81
82/**
Simon Glassbbc09bf2014-02-27 13:26:17 -070083 * sandbox_sdl_sound_init() - set up the sound system
84 *
Simon Glasse221cdc2018-12-10 10:37:50 -070085 * @rate: Sample rate to use
86 * @channels: Number of channels to use (1=mono, 2=stereo)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010087 * Return: 0 if OK, -ENODEV if no sound is available
Simon Glassbbc09bf2014-02-27 13:26:17 -070088 */
Simon Glasse221cdc2018-12-10 10:37:50 -070089int sandbox_sdl_sound_init(int rate, int channels);
Simon Glassbbc09bf2014-02-27 13:26:17 -070090
Sergei Antonov76e16072023-06-13 00:19:04 +030091/**
92 * sandbox_sdl_set_bpp() - Set the depth of the sandbox display
93 *
94 * The device must not be active when this function is called. It activiates it
95 * before returning.
96 *
97 * This updates the depth value and adjusts a few other settings accordingly.
98 * It must be called before the display is probed.
99 *
100 * @dev: Device to adjust
101 * @l2bpp: depth to set
102 * Return: 0 if the device was already active, other error if it fails to probe
103 * after the change
104 */
105int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp);
106
Simon Glassbbc09bf2014-02-27 13:26:17 -0700107#else
Simon Glass6be88c72020-02-03 07:36:13 -0700108static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp,
109 bool double_size)
Simon Glassbbc09bf2014-02-27 13:26:17 -0700110{
111 return -ENODEV;
112}
113
Andrew Scullc527e3f2022-03-23 20:20:37 +0000114static inline int sandbox_sdl_remove_display(void)
115{
116 return -ENODEV;
117}
118
Simon Glassbbc09bf2014-02-27 13:26:17 -0700119static inline int sandbox_sdl_sync(void *lcd_base)
120{
121 return -ENODEV;
122}
123
124static inline int sandbox_sdl_scan_keys(int key[], int max_keys)
125{
126 return -ENODEV;
127}
128
129static inline int sandbox_sdl_key_pressed(int keycode)
130{
131 return -ENODEV;
132}
133
134static inline int sandbox_sdl_sound_start(uint frequency)
135{
136 return -ENODEV;
137}
138
Christian Gmeiner65397002019-04-09 11:27:00 +0200139static inline int sandbox_sdl_sound_play(const void *data, uint count)
Simon Glassf2b25c92018-12-10 10:37:47 -0700140{
141 return -ENODEV;
142}
143
Simon Glassbbc09bf2014-02-27 13:26:17 -0700144static inline int sandbox_sdl_sound_stop(void)
145{
146 return -ENODEV;
147}
148
Christian Gmeiner65397002019-04-09 11:27:00 +0200149static inline int sandbox_sdl_sound_init(int rate, int channels)
Simon Glassbbc09bf2014-02-27 13:26:17 -0700150{
151 return -ENODEV;
152}
153
Sergei Antonov76e16072023-06-13 00:19:04 +0300154static inline int sandbox_sdl_set_bpp(struct udevice *dev,
155 enum video_log2_bpp l2bpp)
156{
157 return -ENOSYS;
158}
159
Simon Glassbbc09bf2014-02-27 13:26:17 -0700160#endif
161
162#endif