Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __SANDBOX_SDL_H |
| 7 | #define __SANDBOX_SDL_H |
| 8 | |
| 9 | #include <errno.h> |
Sergei Antonov | 5da2b46 | 2023-06-13 00:19:04 +0300 | [diff] [blame] | 10 | #include <video.h> |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 11 | |
| 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 Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 21 | * @double_size: true to double the visible size in each direction for high-DPI |
| 22 | * displays |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 23 | * Return: 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 24 | * and -EPERM if the video failed to come up. |
| 25 | */ |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 26 | int sandbox_sdl_init_display(int width, int height, int log2_bpp, |
| 27 | bool double_size); |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
Simon Glass | cce7480 | 2021-11-19 13:23:46 -0700 | [diff] [blame] | 30 | * sandbox_sdl_remove_display() - Remove the SDL screen |
| 31 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 32 | * Return: 0 if OK, -ENOENT if the SDL had not been inited. |
Simon Glass | cce7480 | 2021-11-19 13:23:46 -0700 | [diff] [blame] | 33 | */ |
| 34 | int sandbox_sdl_remove_display(void); |
| 35 | |
| 36 | /** |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 37 | * 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 43 | * Return: 0 if screen was updated, -ENODEV is there is no screen. |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 44 | */ |
| 45 | int 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 54 | * Return: number of keycodes found, 0 if none, -ENODEV if no keyboard |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 55 | */ |
| 56 | int 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 62 | * Return: 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 63 | * available, |
| 64 | */ |
| 65 | int sandbox_sdl_key_pressed(int keycode); |
| 66 | |
| 67 | /** |
Simon Glass | ab6dbe6 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 68 | * sandbox_sdl_sound_play() - Play a sound |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 69 | * |
Simon Glass | ab6dbe6 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 70 | * @data: Data to play (typically 16-bit) |
| 71 | * @count: Number of bytes in data |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 72 | */ |
Simon Glass | ab6dbe6 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 73 | int sandbox_sdl_sound_play(const void *data, uint count); |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * sandbox_sdl_sound_stop() - stop playing a sound |
| 77 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 78 | * Return: 0 if OK, -ENODEV if no sound is available |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 79 | */ |
| 80 | int sandbox_sdl_sound_stop(void); |
| 81 | |
| 82 | /** |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 83 | * sandbox_sdl_sound_init() - set up the sound system |
| 84 | * |
Simon Glass | 658a874 | 2018-12-10 10:37:50 -0700 | [diff] [blame] | 85 | * @rate: Sample rate to use |
| 86 | * @channels: Number of channels to use (1=mono, 2=stereo) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 87 | * Return: 0 if OK, -ENODEV if no sound is available |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 88 | */ |
Simon Glass | 658a874 | 2018-12-10 10:37:50 -0700 | [diff] [blame] | 89 | int sandbox_sdl_sound_init(int rate, int channels); |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 90 | |
Sergei Antonov | 5da2b46 | 2023-06-13 00:19:04 +0300 | [diff] [blame] | 91 | /** |
| 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 | */ |
| 105 | int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp); |
| 106 | |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 107 | #else |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 108 | static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp, |
| 109 | bool double_size) |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 110 | { |
| 111 | return -ENODEV; |
| 112 | } |
| 113 | |
Andrew Scull | 3374704 | 2022-03-23 20:20:37 +0000 | [diff] [blame] | 114 | static inline int sandbox_sdl_remove_display(void) |
| 115 | { |
| 116 | return -ENODEV; |
| 117 | } |
| 118 | |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 119 | static inline int sandbox_sdl_sync(void *lcd_base) |
| 120 | { |
| 121 | return -ENODEV; |
| 122 | } |
| 123 | |
| 124 | static inline int sandbox_sdl_scan_keys(int key[], int max_keys) |
| 125 | { |
| 126 | return -ENODEV; |
| 127 | } |
| 128 | |
| 129 | static inline int sandbox_sdl_key_pressed(int keycode) |
| 130 | { |
| 131 | return -ENODEV; |
| 132 | } |
| 133 | |
| 134 | static inline int sandbox_sdl_sound_start(uint frequency) |
| 135 | { |
| 136 | return -ENODEV; |
| 137 | } |
| 138 | |
Christian Gmeiner | c679def | 2019-04-09 11:27:00 +0200 | [diff] [blame] | 139 | static inline int sandbox_sdl_sound_play(const void *data, uint count) |
Simon Glass | ab6dbe6 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 140 | { |
| 141 | return -ENODEV; |
| 142 | } |
| 143 | |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 144 | static inline int sandbox_sdl_sound_stop(void) |
| 145 | { |
| 146 | return -ENODEV; |
| 147 | } |
| 148 | |
Christian Gmeiner | c679def | 2019-04-09 11:27:00 +0200 | [diff] [blame] | 149 | static inline int sandbox_sdl_sound_init(int rate, int channels) |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 150 | { |
| 151 | return -ENODEV; |
| 152 | } |
| 153 | |
Sergei Antonov | 5da2b46 | 2023-06-13 00:19:04 +0300 | [diff] [blame] | 154 | static inline int sandbox_sdl_set_bpp(struct udevice *dev, |
| 155 | enum video_log2_bpp l2bpp) |
| 156 | { |
| 157 | return -ENOSYS; |
| 158 | } |
| 159 | |
Simon Glass | 0d10f29 | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 160 | #endif |
| 161 | |
| 162 | #endif |