hpm_pdma_drv.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. typedef struct pdma_blit_option {
  140. display_alphablend_mode_t blend;
  141. struct {
  142. uint16_t x;
  143. uint16_t y;
  144. } translate;
  145. pdma_flip_t flip;
  146. pdma_rotate_t rotate;
  147. struct {
  148. float x; /* 0.0625 - 4095 */
  149. float y; /* 0.0625 - 4095 */
  150. } scale;
  151. } pdma_blit_option_t;
  152. #ifdef __cplusplus
  153. extern "C" {
  154. #endif
  155. /**
  156. * @brief Get default configuration according to input pixel format
  157. *
  158. * @param [in] ptr PDMA base address
  159. * @param [out] config pdma_config_t
  160. * @param [in] pixel_format display_pixel_format_t
  161. */
  162. void pdma_get_default_config(PDMA_Type *ptr, pdma_config_t *config, display_pixel_format_t pixel_format);
  163. /**
  164. * @brief Get default plane configuration according input pixel format
  165. *
  166. * @param [in] ptr PDMA base address
  167. * @param [out] config pdma_plane_config_t
  168. * @param [in] pixel_format display_pixel_format_t
  169. */
  170. void pdma_get_default_plane_config(PDMA_Type *ptr, pdma_plane_config_t *config, display_pixel_format_t pixel_format);
  171. /**
  172. * @brief Get default YUV2RGB coefficient configuration according to input pixel format
  173. *
  174. * @note The two plane share one YUV2RGB_COEF, so not support convert one plane YUV422 format
  175. * and another plane YCbCr422 format at same time
  176. *
  177. * @param [in] ptr PDMA base address
  178. * @param [out] yuv2rgb_coef display_yuv2rgb_coef_t
  179. * @param [in] source_format the YUV2RGB input source pixel format
  180. */
  181. void pdma_get_default_yuv2rgb_coef_config(PDMA_Type *ptr, display_yuv2rgb_coef_t *yuv2rgb_coef, display_pixel_format_t source_format);
  182. /**
  183. * @brief Get default output configuration
  184. *
  185. * @param [in] ptr PDMA base address
  186. * @param [out] config pdma_output_config_t
  187. * @param [in] pixel_format output data pixel format
  188. */
  189. void pdma_get_default_output_config(PDMA_Type *ptr,
  190. pdma_output_config_t *config, display_pixel_format_t pixel_format);
  191. /**
  192. * @brief PDMA enable/disable irq
  193. *
  194. * @param [in] ptr PDMA base address
  195. * @param [in] mask irq mask
  196. * @param [in] enable :
  197. * @arg true: enable
  198. * @arg false: disable
  199. */
  200. void pdma_enable_irq(PDMA_Type *ptr, uint32_t mask, bool enable);
  201. /**
  202. * @brief PDMA config output
  203. *
  204. * @param [in] ptr PDMA base address
  205. * @param [in] config pdma_output_config_t
  206. */
  207. void pdma_config_output(PDMA_Type *ptr, pdma_output_config_t *config);
  208. /**
  209. * @brief Configure PDMA planes
  210. *
  211. * Note: The plane_src and plane_dst share one YUV2RGB_COEF, so not support convert one plane YUV422 format
  212. * and another plane YCbCr422 format at same time
  213. *
  214. * @param [in] ptr PDMA base address
  215. * @param [in] plane_src_config Pointer to plane_src configuration structure
  216. * @param [in] plane_dst_config Pointer to plan_dst configuration structure
  217. * @param [in] yuv2rgb_coef Pointer to yuv2rgb_coef configuration structure
  218. */
  219. void pdma_config_planes(PDMA_Type *ptr, void *plane_src_config, void *plane_dst_config, void *yuv2rgb_coef);
  220. /**
  221. * @brief PDMA initialization
  222. *
  223. * @param [in] ptr PDMA base address
  224. * @param [in] config pdma_output_config_t
  225. */
  226. void pdma_init(PDMA_Type *ptr, pdma_config_t *config);
  227. /**
  228. * @brief PDMA check status
  229. *
  230. * @param [in] ptr PDMA base address
  231. * @param [out] status pdma status
  232. */
  233. hpm_stat_t pdma_check_status(PDMA_Type *ptr, uint32_t *status);
  234. /**
  235. * @brief PDMA fill color
  236. *
  237. * @param [in] ptr PDMA base address
  238. * @param [in] dst target buff address
  239. * @param [in] dst_width target buff pixel width
  240. * @param [in] width output image width
  241. * @param [in] height output image height
  242. * @param [in] color color value
  243. * @param [in] alpha alpha value
  244. * @param [in] format display_pixel_format_t
  245. * @param [in] wait wait for execution to complete
  246. * @param [out] status pdma status
  247. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  248. */
  249. hpm_stat_t pdma_fill_color(PDMA_Type *ptr, uint32_t dst, uint32_t dst_width,
  250. uint32_t width, uint32_t height,
  251. uint32_t color, uint8_t alpha,
  252. display_pixel_format_t format,
  253. bool wait, uint32_t *status);
  254. /**
  255. * @brief PDMA flip rotate plane
  256. *
  257. * @param [in] ptr PDMA base address
  258. * @param [in] dst target buff address
  259. * @param [in] dst_width target buff pixel width
  260. * @param [in] src source buff address
  261. * @param [in] src_width source buff pixel width
  262. * @param [in] x x coordinate n buffer
  263. * @param [in] y y coordinate n buffer
  264. * @param [in] width output image width
  265. * @param [in] height output image height
  266. * @param [in] flip pdma_flip_t
  267. * @param [in] rotate pdma_rotate_t
  268. * @param [in] alpha alpha value
  269. * @param [in] format display_pixel_format_t
  270. * @param [in] wait wait for execution to complete
  271. * @param [out] status pdma status
  272. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  273. */
  274. hpm_stat_t pdma_flip_rotate(PDMA_Type *ptr, uint32_t dst, uint32_t dst_width,
  275. uint32_t src, uint32_t src_width, uint32_t x, uint32_t y,
  276. uint32_t width, uint32_t height,
  277. pdma_flip_t flip, pdma_rotate_t rotate, uint8_t alpha,
  278. display_pixel_format_t format,
  279. bool wait, uint32_t *status);
  280. /**
  281. * @brief PDMA blit plane
  282. *
  283. * @param [in] ptr PDMA base address
  284. * @param [in] dst target buff address
  285. * @param [in] dst_width target buff pixel width
  286. * @param [in] src source buff address
  287. * @param [in] src_width source buff pixel width
  288. * @param [in] x x coordinate n buffer
  289. * @param [in] y y coordinate n buffer
  290. * @param [in] width output image width
  291. * @param [in] height output image height
  292. * @param [in] alpha alpha value
  293. * @param [in] format display_pixel_format_t
  294. * @param [in] wait wait for execution to complete
  295. * @param [out] status pdma status
  296. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  297. */
  298. hpm_stat_t pdma_blit(PDMA_Type *ptr,
  299. uint32_t dst, uint32_t dst_width,
  300. uint32_t src, uint32_t src_width,
  301. uint32_t x, uint32_t y, uint32_t width, uint32_t height,
  302. uint8_t alpha,
  303. display_pixel_format_t format,
  304. bool wait, uint32_t *status);
  305. /**
  306. * @brief PDMA scale plane
  307. *
  308. * @param [in] ptr PDMA base address
  309. * @param [in] dst target buff address
  310. * @param [in] dst_width target buff pixel width
  311. * @param [in] src source buff address
  312. * @param [in] src_width source buff pixel width
  313. * @param [in] x x coordinate n buffer
  314. * @param [in] y y coordinate n buffer
  315. * @param [in] width input image width
  316. * @param [in] height input image height
  317. * @param [in] target_width output image width
  318. * @param [in] target_height output image height
  319. * @param [in] alpha alpha value
  320. * @param [in] format display_pixel_format_t
  321. * @param [in] wait wait for execution to complete
  322. * @param [out] status pdma status
  323. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  324. */
  325. hpm_stat_t pdma_scale(PDMA_Type *ptr,
  326. uint32_t dst, uint32_t dst_width,
  327. uint32_t src, uint32_t src_width,
  328. uint32_t x, uint32_t y, uint32_t width, uint32_t height,
  329. uint32_t target_width, uint32_t target_height,
  330. uint8_t alpha,
  331. display_pixel_format_t format,
  332. bool wait, uint32_t *status);
  333. /**
  334. * @brief PDMA get default blit option
  335. *
  336. * @param op option of blit
  337. */
  338. void pdma_get_default_blit_option(pdma_blit_option_t *op);
  339. /**
  340. * @brief PDMA blit plane by option
  341. *
  342. * @param ptr PDMA base address
  343. * @param dst target buff address
  344. * @param src source buff address
  345. * @param op option of blit
  346. * @param wait wait for execution to complete
  347. * @param status pdma status
  348. * @retval hpm_stat_t: status_success if flip and rotate plane without any error
  349. */
  350. hpm_stat_t pdma_blit_ex(PDMA_Type *ptr,
  351. display_buf_t *dst,
  352. display_buf_t *src,
  353. pdma_blit_option_t *op,
  354. bool wait, uint32_t *status);
  355. /**
  356. * @brief PDMA set block size
  357. *
  358. * @param [in] ptr PDMA base address
  359. * @param [in] size pdma_blocksize_t
  360. */
  361. void pdma_set_block_size(PDMA_Type *ptr, pdma_blocksize_t size);
  362. /**
  363. * @brief PDMA stop
  364. *
  365. * @param [in] ptr PDMA base address
  366. */
  367. void pdma_stop(PDMA_Type *ptr);
  368. /**
  369. * @brief PDMA stop
  370. *
  371. * @param [in] ptr PDMA base address
  372. *
  373. * @retval STAT register value
  374. */
  375. static inline uint32_t pdma_get_status(PDMA_Type *ptr)
  376. {
  377. return ptr->STAT;
  378. }
  379. /**
  380. * @brief PDMA start
  381. *
  382. * @param [in] ptr PDMA base address
  383. */
  384. static inline void pdma_start(PDMA_Type *ptr)
  385. {
  386. ptr->CTRL |= PDMA_CTRL_PDMA_EN_MASK;
  387. __asm volatile ("" : : "r" (ptr->CTRL));
  388. }
  389. /**
  390. * @brief PDMA software reset
  391. *
  392. * @param [in] ptr PDMA base address
  393. */
  394. static inline void pdma_software_reset(PDMA_Type *ptr)
  395. {
  396. ptr->CTRL |= PDMA_CTRL_PDMA_SFTRST_MASK;
  397. ptr->CTRL &= ~(PDMA_CTRL_PDMA_SFTRST_MASK);
  398. __asm volatile ("" : : "r" (ptr->CTRL));
  399. }
  400. /**
  401. * @brief PDMA set plane color key limits
  402. *
  403. * @param [in] ptr PDMA base address
  404. * @param [in] plane_index plane index
  405. * @param [in] key_high color key high limits
  406. * @param [in] key_low color key low limits
  407. */
  408. static inline void pdma_set_plane_colorkey(PDMA_Type *ptr,
  409. uint8_t plane_index,
  410. uint32_t key_high,
  411. uint32_t key_low)
  412. {
  413. ptr->PS[plane_index].CLRKEY_LOW = PDMA_PS_CLRKEY_LOW_LIMIT_SET(key_low);
  414. ptr->PS[plane_index].CLRKEY_HIGH = PDMA_PS_CLRKEY_HIGH_LIMIT_SET(key_high);
  415. }
  416. /**
  417. * @}
  418. */
  419. #ifdef __cplusplus
  420. }
  421. #endif
  422. #endif /* HPM_PDMA_DRV_H */