sdl.h 2.9 KB

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