Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | bbc09bf | 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> |
| 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 |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 20 | * @double_size: true to double the visible size in each direction for high-DPI |
| 21 | * displays |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 22 | * Return: 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 23 | * and -EPERM if the video failed to come up. |
| 24 | */ |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 25 | int sandbox_sdl_init_display(int width, int height, int log2_bpp, |
| 26 | bool double_size); |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
Simon Glass | 250e735 | 2021-11-19 13:23:46 -0700 | [diff] [blame] | 29 | * sandbox_sdl_remove_display() - Remove the SDL screen |
| 30 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 31 | * Return: 0 if OK, -ENOENT if the SDL had not been inited. |
Simon Glass | 250e735 | 2021-11-19 13:23:46 -0700 | [diff] [blame] | 32 | */ |
| 33 | int sandbox_sdl_remove_display(void); |
| 34 | |
| 35 | /** |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 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 |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 42 | * Return: 0 if screen was updated, -ENODEV is there is no screen. |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 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 |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 53 | * Return: number of keycodes found, 0 if none, -ENODEV if no keyboard |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 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 |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 61 | * Return: 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 62 | * available, |
| 63 | */ |
| 64 | int sandbox_sdl_key_pressed(int keycode); |
| 65 | |
| 66 | /** |
Simon Glass | f2b25c9 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 67 | * sandbox_sdl_sound_play() - Play a sound |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 68 | * |
Simon Glass | f2b25c9 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 69 | * @data: Data to play (typically 16-bit) |
| 70 | * @count: Number of bytes in data |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 71 | */ |
Simon Glass | f2b25c9 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 72 | int sandbox_sdl_sound_play(const void *data, uint count); |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * sandbox_sdl_sound_stop() - stop playing a sound |
| 76 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 77 | * Return: 0 if OK, -ENODEV if no sound is available |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 78 | */ |
| 79 | int sandbox_sdl_sound_stop(void); |
| 80 | |
| 81 | /** |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 82 | * sandbox_sdl_sound_init() - set up the sound system |
| 83 | * |
Simon Glass | e221cdc | 2018-12-10 10:37:50 -0700 | [diff] [blame] | 84 | * @rate: Sample rate to use |
| 85 | * @channels: Number of channels to use (1=mono, 2=stereo) |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 86 | * Return: 0 if OK, -ENODEV if no sound is available |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 87 | */ |
Simon Glass | e221cdc | 2018-12-10 10:37:50 -0700 | [diff] [blame] | 88 | int sandbox_sdl_sound_init(int rate, int channels); |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 89 | |
| 90 | #else |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 91 | static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp, |
| 92 | bool double_size) |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 93 | { |
| 94 | return -ENODEV; |
| 95 | } |
| 96 | |
Andrew Scull | c527e3f | 2022-03-23 20:20:37 +0000 | [diff] [blame] | 97 | static inline int sandbox_sdl_remove_display(void) |
| 98 | { |
| 99 | return -ENODEV; |
| 100 | } |
| 101 | |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 102 | static inline int sandbox_sdl_sync(void *lcd_base) |
| 103 | { |
| 104 | return -ENODEV; |
| 105 | } |
| 106 | |
| 107 | static inline int sandbox_sdl_scan_keys(int key[], int max_keys) |
| 108 | { |
| 109 | return -ENODEV; |
| 110 | } |
| 111 | |
| 112 | static inline int sandbox_sdl_key_pressed(int keycode) |
| 113 | { |
| 114 | return -ENODEV; |
| 115 | } |
| 116 | |
| 117 | static inline int sandbox_sdl_sound_start(uint frequency) |
| 118 | { |
| 119 | return -ENODEV; |
| 120 | } |
| 121 | |
Christian Gmeiner | 6539700 | 2019-04-09 11:27:00 +0200 | [diff] [blame] | 122 | static inline int sandbox_sdl_sound_play(const void *data, uint count) |
Simon Glass | f2b25c9 | 2018-12-10 10:37:47 -0700 | [diff] [blame] | 123 | { |
| 124 | return -ENODEV; |
| 125 | } |
| 126 | |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 127 | static inline int sandbox_sdl_sound_stop(void) |
| 128 | { |
| 129 | return -ENODEV; |
| 130 | } |
| 131 | |
Christian Gmeiner | 6539700 | 2019-04-09 11:27:00 +0200 | [diff] [blame] | 132 | static inline int sandbox_sdl_sound_init(int rate, int channels) |
Simon Glass | bbc09bf | 2014-02-27 13:26:17 -0700 | [diff] [blame] | 133 | { |
| 134 | return -ENODEV; |
| 135 | } |
| 136 | |
| 137 | #endif |
| 138 | |
| 139 | #endif |