display_hal.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file display_hal.h
  8. */
  9. #ifndef ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_DISPLAY_HAL_H_
  10. #define ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_DISPLAY_HAL_H_
  11. #include <stdint.h>
  12. #include <drivers/display/display_graphics.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /**
  17. * @brief HAL pixel format definitions
  18. *
  19. * HAL pixel format enumeration.
  20. *
  21. */
  22. enum hal_pixel_format {
  23. /*
  24. * "linear" color pixel formats:
  25. */
  26. /* order: [31..24] A, [23..16] R, [15..8] G, [7..0] B */
  27. HAL_PIXEL_FORMAT_ARGB_8888 = PIXEL_FORMAT_ARGB_8888,
  28. /* order: [31..24] X, [23..16] R, [15..8] G, [7..0] B */
  29. HAL_PIXEL_FORMAT_XRGB_8888 = PIXEL_FORMAT_XRGB_8888,
  30. /* order: [23..18] A, [17..12] R, [11..6] G, [5..0] B */
  31. HAL_PIXEL_FORMAT_ARGB_6666 = PIXEL_FORMAT_BGRA_6666,
  32. /* order: [23..18] A, [17..12] B, [11..6] G, [5..0] R */
  33. HAL_PIXEL_FORMAT_ABGR_6666 = PIXEL_FORMAT_RGBA_6666,
  34. /* order: [23..16] A, [15..11] R, [10..5] G, [4..0] B */
  35. HAL_PIXEL_FORMAT_ARGB_8565 = PIXEL_FORMAT_BGRA_5658,
  36. /* order: [23..16] B, [15..8] G, [7..0] R */
  37. HAL_PIXEL_FORMAT_BGR_888 = PIXEL_FORMAT_RGB_888,
  38. /* order: [23..16] R, [15..8] G, [7..0] B */
  39. HAL_PIXEL_FORMAT_RGB_888 = PIXEL_FORMAT_BGR_888,
  40. /* order: [15..11] R, [10..5] G, [4..0] B */
  41. HAL_PIXEL_FORMAT_RGB_565 = PIXEL_FORMAT_BGR_565,
  42. /* order: [15..13] G[2..0], [12..8] B, [7..3] R, [2..0] G[5..3] */
  43. HAL_PIXEL_FORMAT_RGB_565_BE = PIXEL_FORMAT_RGB_565,
  44. /* order: [15..15] A, [14..10] R, [9..5] G, [4..0] B */
  45. HAL_PIXEL_FORMAT_ARGB_1555 = PIXEL_FORMAT_BGRA_5551,
  46. /* order: [7..0] I */
  47. HAL_PIXEL_FORMAT_I8 = PIXEL_FORMAT_I8,
  48. /* order: [7..4] I0, [3..0] I1 */
  49. HAL_PIXEL_FORMAT_I4 = PIXEL_FORMAT_I4,
  50. /* order: [7..6] I0, [5..4] I1, [3..2] I2, [1..0] I3 */
  51. HAL_PIXEL_FORMAT_I2 = PIXEL_FORMAT_I2,
  52. /* order: [7] I0, [6] I1, [5] I2, [4] I3, [3] I4, [2] I5, [1] I6, [0] I7 */
  53. HAL_PIXEL_FORMAT_I1 = PIXEL_FORMAT_I1,
  54. /* order: [7..0] A */
  55. HAL_PIXEL_FORMAT_A8 = PIXEL_FORMAT_A8,
  56. /* order: [7..4] A0, [3..0] A1 */
  57. HAL_PIXEL_FORMAT_A4 = PIXEL_FORMAT_A4,
  58. /* order: [7..6] A0, [5..4] A1, [3..2] A2, [1..0] A3 */
  59. HAL_PIXEL_FORMAT_A2 = PIXEL_FORMAT_A2,
  60. /* order: [7] A0, [6] A1, [5] A2, [4] A3, [3] A4, [2] A5, [1] A6, [0] A7 */
  61. HAL_PIXEL_FORMAT_A1 = PIXEL_FORMAT_A1,
  62. /* order: [7..4] A1, [3..0] A0 */
  63. HAL_PIXEL_FORMAT_A4_LE = PIXEL_FORMAT_A4_LE,
  64. /* order: [7..6] A3, [5..4] A2, [3..2] A1, [1..0] A0 */
  65. //HAL_PIXEL_FORMAT_A2_LE = PIXEL_FORMAT_A2_LE,
  66. /* order: [7] A7, [6] A6, [5] A5, [4] A4, [3] A3, [2] A2, [1] A1, [0] A0 */
  67. HAL_PIXEL_FORMAT_A1_LE = PIXEL_FORMAT_A1_LE,
  68. };
  69. /**
  70. * @brief HAL blending type definitions
  71. *
  72. * HAL blending type enumeration.
  73. *
  74. */
  75. enum hal_blending_type {
  76. /* no blending */
  77. HAL_BLENDING_NONE = DISPLAY_BLENDING_NONE,
  78. /* ONE / ONE_MINUS_SRC_ALPHA */
  79. HAL_BLENDING_PREMULT = DISPLAY_BLENDING_PREMULT,
  80. /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
  81. HAL_BLENDING_COVERAGE = DISPLAY_BLENDING_COVERAGE,
  82. };
  83. /**
  84. * @brief HAL transform type definitions
  85. *
  86. * HAL transform type enumeration.
  87. *
  88. */
  89. enum hal_transform_type {
  90. /* flip source image horizontally (around the vertical axis) */
  91. HAL_TRANSFORM_FLIP_H = DISPLAY_TRANSFORM_FLIP_H,
  92. /* flip source image vertically (around the horizontal axis)*/
  93. HAL_TRANSFORM_FLIP_V = DISPLAY_TRANSFORM_FLIP_V,
  94. /* rotate source image 90 degrees clockwise */
  95. HAL_TRANSFORM_ROT_90 = DISPLAY_TRANSFORM_ROT_90,
  96. /* rotate source image 180 degrees */
  97. HAL_TRANSFORM_ROT_180 = DISPLAY_TRANSFORM_ROT_180,
  98. /* rotate source image 270 degrees clockwise */
  99. HAL_TRANSFORM_ROT_270 = DISPLAY_TRANSFORM_ROT_270,
  100. /* don't use. see system/window.h */
  101. HAL_TRANSFORM_RESERVED = DISPLAY_TRANSFORM_RESERVED,
  102. };
  103. /**
  104. * @struct hal_color
  105. * @brief Structure holding color
  106. *
  107. */
  108. typedef struct hal_color {
  109. union {
  110. /* access as per-channel name for ARGB-8888 */
  111. struct {
  112. uint8_t b; /* blue component */
  113. uint8_t g; /* green component */
  114. uint8_t r; /* red component */
  115. uint8_t a; /* alpha component */
  116. };
  117. uint8_t c8[4]; /* access as 8-bit byte array */
  118. uint16_t c16[2]; /* access as 16-bit half word array */
  119. uint32_t c32[1]; /* access as 32-bit word array */
  120. uint32_t full; /* access as 32-bit full value */
  121. };
  122. } hal_color_t;
  123. /**
  124. * @brief Construct color
  125. *
  126. * @param r r component
  127. * @param g g component
  128. * @param b b component
  129. * @param a a component
  130. *
  131. * @return color structure
  132. */
  133. static inline hal_color_t hal_color_make(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
  134. {
  135. hal_color_t color = { .r = r, .g = g, .b = b, .a = a, };
  136. return color;
  137. }
  138. /**
  139. * @brief Construct color from 32-bit hex value
  140. *
  141. * @param c 32-bit color value argb-8888
  142. *
  143. * @return color structure
  144. */
  145. static inline hal_color_t hal_color_hex(uint32_t c)
  146. {
  147. hal_color_t color = { .full = c, };
  148. return color;
  149. }
  150. /**
  151. * @brief Construct color from 16-bit hex value
  152. *
  153. * @param c 16-bit color value rgb-565
  154. *
  155. * @return color structure
  156. */
  157. static inline hal_color_t hal_color_hex16(uint16_t c)
  158. {
  159. hal_color_t color = {
  160. .a = 0xff,
  161. .r = (c & 0xf800) >> 8,
  162. .g = (c & 0x07f0) >> 3,
  163. .b = (c & 0x001f) << 3,
  164. };
  165. color.r = color.r | ((color.r >> 5) & 0x7);
  166. color.g = color.g | ((color.g >> 6) & 0x3);
  167. color.b = color.b | ((color.b >> 5) & 0x7);
  168. return color;
  169. }
  170. /**
  171. * @brief Query display format is opaque
  172. *
  173. * @param pixel_format hal pixel format, see@enum hal_pixel_format
  174. *
  175. * @return the query result
  176. */
  177. static inline bool hal_pixel_format_is_opaque(uint32_t pixel_format)
  178. {
  179. return display_format_is_opaque(pixel_format);
  180. }
  181. /**
  182. * @brief Query pixel format bits per pixel
  183. *
  184. * @param pixel_format hal pixel format, see@enum hal_pixel_format
  185. *
  186. * @return the query result
  187. */
  188. static inline uint8_t hal_pixel_format_get_bits_per_pixel(uint32_t pixel_format)
  189. {
  190. return display_format_get_bits_per_pixel(pixel_format);
  191. }
  192. /**
  193. * @brief Get display format name string
  194. *
  195. * @param pixel_format hal pixel format, see@enum hal_pixel_format
  196. *
  197. * @return the name string
  198. */
  199. static inline const char * hal_pixel_format_get_name(uint32_t pixel_format)
  200. {
  201. return display_format_get_name(pixel_format);
  202. }
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif /* ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_DISPLAY_HAL_H_ */