hpm_pdma_drv.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_PDMA_DRV_H
  8. #define HPM_PDMA_DRV_H
  9. #include "hpm_soc_feature.h"
  10. #include "hpm_display_common.h"
  11. #include "hpm_pdma_regs.h"
  12. /**
  13. * @brief PDMA driver APIs
  14. * @defgroup pdma_interface PDMA driver APIs
  15. * @ingroup io_interfaces
  16. * @{
  17. */
  18. /**
  19. * @brief PDMA status
  20. */
  21. enum {
  22. status_pdma_done = status_success,
  23. status_pdma_error = MAKE_STATUS(status_group_pdma, 1),
  24. status_pdma_busy = MAKE_STATUS(status_group_pdma, 2),
  25. status_pdma_idle = MAKE_STATUS(status_group_pdma, 3),
  26. };
  27. /**
  28. * @brief PDMA plane
  29. */
  30. typedef enum pdma_plane {
  31. pdma_plane_src = 0,
  32. pdma_plane_dst = 1,
  33. pdma_plane_both,
  34. pdma_plane_none,
  35. } pdma_plane_t;
  36. /**
  37. * @brief PDMA flip
  38. */
  39. typedef enum pdma_flip {
  40. pdma_flip_none = 0,
  41. pdma_flip_horizontal = 1 << 0,
  42. pdma_flip_vertical = 1 << 1,
  43. pdma_flip_both = pdma_flip_horizontal | pdma_flip_vertical,
  44. } pdma_flip_t;
  45. /**
  46. * @brief PDMA rotate
  47. */
  48. typedef enum pdma_rotate {
  49. pdma_rotate_0_degree = 0,
  50. pdma_rotate_90_degree = 1,
  51. pdma_rotate_180_degree = 2,
  52. pdma_rotate_270_degree = 3,
  53. } pdma_rotate_t;
  54. /**
  55. * @brief PDMA decimation
  56. */
  57. typedef enum pdma_decimation {
  58. pdma_decimation_by_1 = 0,
  59. pdma_decimation_by_2 = 1,
  60. pdma_decimation_by_4 = 2,
  61. pdma_decimation_by_8 = 3,
  62. } pdma_decimation_t;
  63. /**
  64. * @brief PDMA block size
  65. */
  66. typedef enum pdma_blocksize {
  67. pdma_blocksize_16x16,
  68. pdma_blocksize_8x8,
  69. } pdma_blocksize_t;
  70. /**
  71. * @brief PDMA make scale value
  72. */
  73. #define PDMA_MAKE_SCALE_SET(integer, fractional) \
  74. (((integer) & 0x3) << 12 | ((fractional) & 0xFFF))
  75. /**
  76. * @brief PDMA plane config
  77. */
  78. typedef struct pdma_plane_config {
  79. bool swap_byte3_byte1; /**< set true to swap byte [31:24] and byte [15:8] */
  80. bool use_background_as_clear; /**< set true to use background color at blending clear mode */
  81. bool ycbcr_mode; /**< set true if it is YCbCr mode */
  82. bool bypass_colorspace_conversion; /**< set true to bypass color space conversion */
  83. bool byte_swap; /**< set true to swap [31:16] and [15:0] */
  84. display_byteorder_t byteorder; /**< packing byte order type */
  85. pdma_flip_t flip; /**< flip type */
  86. pdma_rotate_t rotate; /**< rotate type */
  87. pdma_decimation_t x_dec; /**< horizontal decimation */
  88. pdma_decimation_t y_dec; /**< vertical decimation */
  89. display_pixel_format_t pixel_format; /**< pixel format */
  90. uint32_t buffer; /**< buffer address */
  91. uint32_t background; /**< background color */
  92. uint32_t colorkey_high; /**< colorkey high limit */
  93. uint32_t colorkey_low; /**< colorkey low limit */
  94. uint16_t x_scale; /**< 14-bit horizontal scale */
  95. uint16_t y_scale; /**< 14-bit vertical scale */
  96. uint16_t pitch; /**< pitch value */
  97. uint16_t x_offset; /**< horizontal offset */
  98. uint16_t y_offset; /**< vertical offset */
  99. uint16_t width; /**< width */
  100. uint16_t height; /**< height */
  101. } pdma_plane_config_t;
  102. /**
  103. * @brief PDMA output config
  104. */
  105. typedef struct pdma_output_config {
  106. display_alphablend_option_t alphablend; /**< alpha blending mode */
  107. display_pixel_format_t pixel_format; /**< pixel format */
  108. display_rgb2yuv_config_t rgb2yuv_config; /**< RGB to YUV config */
  109. uint32_t buffer; /**< buffer */
  110. struct {
  111. uint16_t x; /**< plane origin X coord */
  112. uint16_t y; /**< plane origin Y coord */
  113. uint16_t width; /**< plane width */
  114. uint16_t height; /**< plane height */
  115. } plane[PDMA_SOC_PS_MAX_COUNT]; /**< plane config */
  116. uint16_t width; /**< output plane width */
  117. uint16_t height; /**< output plane height */
  118. uint16_t pitch;
  119. } pdma_output_config_t;
  120. /**
  121. * @brief PDMA config
  122. */
  123. typedef struct pdma_config {
  124. display_byteorder_t byteorder; /**< byte order */
  125. pdma_blocksize_t block_size; /**< block size */
  126. pdma_plane_t enable_plane; /**< plane to be enabled */
  127. } pdma_config_t;
  128. /**
  129. * @brief PDMA plane info
  130. */
  131. typedef struct pdma_plane_info {
  132. uint32_t buffer; /**< buffer */
  133. uint32_t x; /**< plane origin X coord */
  134. uint32_t y; /**< plane origin Y coord */
  135. uint32_t width; /**< plane width */
  136. uint32_t height; /**< plane height */
  137. display_pixel_format_t format; /**< pixel format */
  138. } pdma_plane_info_t;
  139. #ifdef __cplusplus
  140. extern "C" {
  141. #endif
  142. /**
  143. * @brief Get default configuration according to input pixel format
  144. *
  145. * @param [in] ptr PDMA base address
  146. * @param [out] config pdma_config_t
  147. * @param [in] pixel_format display_pixel_format_t
  148. */
  149. void pdma_get_default_config(PDMA_Type *ptr, pdma_config_t *config, display_pixel_format_t pixel_format);
  150. /**
  151. * @brief Get default plane configuration according input pixel format
  152. *
  153. * @param [in] ptr PDMA base address
  154. * @param [out] config pdma_plane_config_t
  155. * @param [in] pixel_format display_pixel_format_t
  156. */
  157. void pdma_get_default_plane_config(PDMA_Type *ptr, pdma_plane_config_t *config, display_pixel_format_t pixel_format);
  158. /**
  159. * @brief Get default YUV2RGB coefficient configuration according to input pixel format
  160. *
  161. * @note The two plane share one YUV2RGB_COEF, so not support convert one plane YUV422 format
  162. * and another plane YCbCr422 format at same time
  163. *
  164. * @param [in] ptr PDMA base address
  165. * @param [out] yuv2rgb_coef display_yuv2rgb_coef_t
  166. * @param [in] source_format the YUV2RGB input source pixel format
  167. */
  168. void pdma_get_default_yuv2rgb_coef_config(PDMA_Type *ptr, display_yuv2rgb_coef_t *yuv2rgb_coef, display_pixel_format_t source_format);
  169. /**
  170. * @brief Get default output configuration
  171. *
  172. * @param [in] ptr PDMA base address
  173. * @param [out] config pdma_output_config_t
  174. * @param [in] pixel_format output data pixel format
  175. */
  176. void pdma_get_default_output_config(PDMA_Type *ptr,
  177. pdma_output_config_t *config, display_pixel_format_t pixel_format);
  178. /**
  179. * @brief PDMA enable/disable irq
  180. *
  181. * @param [in] ptr PDMA base address
  182. * @param [in] mask irq mask
  183. * @param [in] enable :
  184. * @arg true: enable
  185. * @arg false: disable
  186. */
  187. void pdma_enable_irq(PDMA_Type *ptr, uint32_t mask, bool enable);
  188. /**
  189. * @brief PDMA config output
  190. *
  191. * @param [in] ptr PDMA base address
  192. * @param [in] config pdma_output_config_t
  193. */
  194. void pdma_config_output(PDMA_Type *ptr, pdma_output_config_t *config);
  195. /**
  196. * @brief Configure PDMA planes
  197. *
  198. * Note: The plane_src and plane_dst share one YUV2RGB_COEF, so not support convert one plane YUV422 format
  199. * and another plane YCbCr422 format at same time
  200. *
  201. * @param [in] ptr PDMA base address
  202. * @param [in] plane_src_config Pointer to plane_src configuration structure
  203. * @param [in] plane_dst_config Pointer to plan_dst configuration structure
  204. * @param [in] yuv2rgb_coef Pointer to yuv2rgb_coef configuration structure
  205. */
  206. void pdma_config_planes(PDMA_Type *ptr, void *plane_src_config, void *plane_dst_config, void *yuv2rgb_coef);
  207. /**
  208. * @brief PDMA initialization
  209. *
  210. * @param [in] ptr PDMA base address
  211. * @param [in] config pdma_output_config_t
  212. */
  213. void pdma_init(PDMA_Type *ptr, pdma_config_t *config);
  214. /**
  215. * @brief PDMA check status
  216. *
  217. * @param [in] ptr PDMA base address
  218. * @param [out] status pdma status
  219. */
  220. hpm_stat_t pdma_check_status(PDMA_Type *ptr, uint32_t *status);
  221. /**
  222. * @brief PDMA fill color
  223. *
  224. * @param [in] ptr PDMA base address
  225. * @param [in] dst target buff address
  226. * @param [in] dst_width target buff pixel width
  227. * @param [in] width output image width
  228. * @param [in] height output image height
  229. * @param [in] color color value
  230. * @param [in] alpha alpha value
  231. * @param [in] format display_pixel_format_t
  232. * @param [in] wait wait for execution to complete
  233. * @param [out] status pdma status
  234. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  235. */
  236. hpm_stat_t pdma_fill_color(PDMA_Type *ptr, uint32_t dst, uint32_t dst_width,
  237. uint32_t width, uint32_t height,
  238. uint32_t color, uint8_t alpha,
  239. display_pixel_format_t format,
  240. bool wait, uint32_t *status);
  241. /**
  242. * @brief PDMA flip rotate plane
  243. *
  244. * @param [in] ptr PDMA base address
  245. * @param [in] dst target buff address
  246. * @param [in] dst_width target buff pixel width
  247. * @param [in] src source buff address
  248. * @param [in] src_width source buff pixel width
  249. * @param [in] x x coordinate n buffer
  250. * @param [in] y y coordinate n buffer
  251. * @param [in] width output image width
  252. * @param [in] height output image height
  253. * @param [in] flip pdma_flip_t
  254. * @param [in] rotate pdma_rotate_t
  255. * @param [in] alpha alpha value
  256. * @param [in] format display_pixel_format_t
  257. * @param [in] wait wait for execution to complete
  258. * @param [out] status pdma status
  259. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  260. */
  261. hpm_stat_t pdma_flip_rotate(PDMA_Type *ptr, uint32_t dst, uint32_t dst_width,
  262. uint32_t src, uint32_t src_width, uint32_t x, uint32_t y,
  263. uint32_t width, uint32_t height,
  264. pdma_flip_t flip, pdma_rotate_t rotate, uint8_t alpha,
  265. display_pixel_format_t format,
  266. bool wait, uint32_t *status);
  267. /**
  268. * @brief PDMA blit plane
  269. *
  270. * @param [in] ptr PDMA base address
  271. * @param [in] dst target buff address
  272. * @param [in] dst_width target buff pixel width
  273. * @param [in] src source buff address
  274. * @param [in] src_width source buff pixel width
  275. * @param [in] x x coordinate n buffer
  276. * @param [in] y y coordinate n buffer
  277. * @param [in] width output image width
  278. * @param [in] height output image height
  279. * @param [in] alpha alpha value
  280. * @param [in] format display_pixel_format_t
  281. * @param [in] wait wait for execution to complete
  282. * @param [out] status pdma status
  283. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  284. */
  285. hpm_stat_t pdma_blit(PDMA_Type *ptr,
  286. uint32_t dst, uint32_t dst_width,
  287. uint32_t src, uint32_t src_width,
  288. uint32_t x, uint32_t y, uint32_t width, uint32_t height,
  289. uint8_t alpha,
  290. display_pixel_format_t format,
  291. bool wait, uint32_t *status);
  292. /**
  293. * @brief PDMA scale plane
  294. *
  295. * @param [in] ptr PDMA base address
  296. * @param [in] dst target buff address
  297. * @param [in] dst_width target buff pixel width
  298. * @param [in] src source buff address
  299. * @param [in] src_width source buff pixel width
  300. * @param [in] x x coordinate n buffer
  301. * @param [in] y y coordinate n buffer
  302. * @param [in] width input image width
  303. * @param [in] height input image height
  304. * @param [in] target_width output image width
  305. * @param [in] target_height output image height
  306. * @param [in] alpha alpha value
  307. * @param [in] format display_pixel_format_t
  308. * @param [in] wait wait for execution to complete
  309. * @param [out] status pdma status
  310. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  311. */
  312. hpm_stat_t pdma_scale(PDMA_Type *ptr,
  313. uint32_t dst, uint32_t dst_width,
  314. uint32_t src, uint32_t src_width,
  315. uint32_t x, uint32_t y, uint32_t width, uint32_t height,
  316. uint32_t target_width, uint32_t target_height,
  317. uint8_t alpha,
  318. display_pixel_format_t format,
  319. bool wait, uint32_t *status);
  320. /**
  321. * @brief PDMA set block size
  322. *
  323. * @param [in] ptr PDMA base address
  324. * @param [in] size pdma_blocksize_t
  325. */
  326. void pdma_set_block_size(PDMA_Type *ptr, pdma_blocksize_t size);
  327. /**
  328. * @brief PDMA stop
  329. *
  330. * @param [in] ptr PDMA base address
  331. */
  332. void pdma_stop(PDMA_Type *ptr);
  333. /**
  334. * @brief PDMA stop
  335. *
  336. * @param [in] ptr PDMA base address
  337. *
  338. * @retval STAT register value
  339. */
  340. static inline uint32_t pdma_get_status(PDMA_Type *ptr)
  341. {
  342. return ptr->STAT;
  343. }
  344. /**
  345. * @brief PDMA start
  346. *
  347. * @param [in] ptr PDMA base address
  348. */
  349. static inline void pdma_start(PDMA_Type *ptr)
  350. {
  351. ptr->CTRL |= PDMA_CTRL_PDMA_EN_MASK;
  352. __asm volatile ("" : : "r" (ptr->CTRL));
  353. }
  354. /**
  355. * @brief PDMA software reset
  356. *
  357. * @param [in] ptr PDMA base address
  358. */
  359. static inline void pdma_software_reset(PDMA_Type *ptr)
  360. {
  361. ptr->CTRL |= PDMA_CTRL_PDMA_SFTRST_MASK;
  362. ptr->CTRL &= ~(PDMA_CTRL_PDMA_SFTRST_MASK);
  363. __asm volatile ("" : : "r" (ptr->CTRL));
  364. }
  365. /**
  366. * @brief PDMA set plane color key limits
  367. *
  368. * @param [in] ptr PDMA base address
  369. * @param [in] plane_index plane index
  370. * @param [in] key_high color key high limits
  371. * @param [in] key_low color key low limits
  372. */
  373. static inline void pdma_set_plane_colorkey(PDMA_Type *ptr,
  374. uint8_t plane_index,
  375. uint32_t key_high,
  376. uint32_t key_low)
  377. {
  378. ptr->PS[plane_index].CLRKEY_LOW = PDMA_PS_CLRKEY_LOW_LIMIT_SET(key_low);
  379. ptr->PS[plane_index].CLRKEY_HIGH = PDMA_PS_CLRKEY_HIGH_LIMIT_SET(key_high);
  380. }
  381. /**
  382. * @}
  383. */
  384. #ifdef __cplusplus
  385. }
  386. #endif
  387. #endif /* HPM_PDMA_DRV_H */