fsl_pxp.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. /*
  2. * Copyright 2017-2021 NXP
  3. * All rights reserved.
  4. *
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_PXP_H_
  9. #define _FSL_PXP_H_
  10. #include "fsl_common.h"
  11. /* Compatibility macro map. */
  12. #if defined(PXP_AS_CTRL_ALPHA_INVERT_MASK) && (!defined(PXP_AS_CTRL_ALPHA0_INVERT_MASK))
  13. #define PXP_AS_CTRL_ALPHA0_INVERT_MASK PXP_AS_CTRL_ALPHA_INVERT_MASK
  14. #endif
  15. #if defined(PXP_AS_CTRL_ALPHA_INVERT_MASK) && (!defined(PXP_AS_CTRL_ALPHA_INVERT_MASK))
  16. #define PXP_AS_CTRL_ALPHA0_INVERT_MASK PXP_AS_CTRL_ALPHA_INVERT_MASK
  17. #endif
  18. #if defined(PXP_STAT_IRQ_MASK) && (!defined(PXP_STAT_IRQ0_MASK))
  19. #define PXP_STAT_IRQ0_MASK PXP_STAT_IRQ_MASK
  20. #endif
  21. #if defined(PXP_STAT_AXI_READ_ERROR_MASK) && (!defined(PXP_STAT_AXI_READ_ERROR_0_MASK))
  22. #define PXP_STAT_AXI_READ_ERROR_0_MASK PXP_STAT_AXI_READ_ERROR_MASK
  23. #endif
  24. #if defined(PXP_STAT_AXI_WRITE_ERROR_MASK) && (!defined(PXP_STAT_AXI_WRITE_ERROR_0_MASK))
  25. #define PXP_STAT_AXI_WRITE_ERROR_0_MASK PXP_STAT_AXI_WRITE_ERROR_MASK
  26. #endif
  27. /*!
  28. * @addtogroup pxp_driver
  29. * @{
  30. */
  31. /*******************************************************************************
  32. * Definitions
  33. ******************************************************************************/
  34. /* PXP global LUT table is 16K. */
  35. #define PXP_LUT_TABLE_BYTE (16 * 1024)
  36. /* Intenral memory for LUT, the size is 256 bytes. */
  37. #define PXP_INTERNAL_RAM_LUT_BYTE (256)
  38. /*! @name Driver version */
  39. /*@{*/
  40. #define FSL_PXP_DRIVER_VERSION (MAKE_VERSION(2, 2, 2))
  41. /*@}*/
  42. /* This macto indicates whether the rotate sub module is shared by process surface and output buffer. */
  43. #if defined(PXP_CTRL_ROT_POS_MASK)
  44. #define PXP_SHARE_ROTATE 1
  45. #else
  46. #define PXP_SHARE_ROTATE 0
  47. #endif
  48. /*! @brief PXP interrupts to enable. */
  49. enum _pxp_interrupt_enable
  50. {
  51. kPXP_CommandLoadInterruptEnable = PXP_CTRL_NEXT_IRQ_ENABLE_MASK, /*!< Interrupt to show that the command set
  52. by @ref PXP_SetNextCommand has been loaded. */
  53. kPXP_CompleteInterruptEnable = PXP_CTRL_IRQ_ENABLE_MASK, /*!< PXP process completed. */
  54. #if !(defined(FSL_FEATURE_PXP_HAS_NO_LUT) && FSL_FEATURE_PXP_HAS_NO_LUT)
  55. kPXP_LutDmaLoadInterruptEnable = PXP_CTRL_LUT_DMA_IRQ_ENABLE_MASK, /*!< The LUT table has been loaded by DMA. */
  56. #endif
  57. };
  58. /*!
  59. * @brief PXP status flags.
  60. *
  61. * @note These enumerations are meant to be OR'd together to form a bit mask.
  62. */
  63. enum _pxp_flags
  64. {
  65. kPXP_CommandLoadFlag = PXP_STAT_NEXT_IRQ_MASK, /*!< The command set by @ref PXP_SetNextCommand
  66. has been loaded, could set new command. */
  67. kPXP_CompleteFlag = PXP_STAT_IRQ0_MASK, /*!< PXP process completed. */
  68. #if !(defined(FSL_FEATURE_PXP_HAS_NO_LUT) && FSL_FEATURE_PXP_HAS_NO_LUT)
  69. kPXP_LutDmaLoadFlag = PXP_STAT_LUT_DMA_LOAD_DONE_IRQ_MASK, /*!< The LUT table has been loaded by DMA. */
  70. #endif
  71. kPXP_Axi0ReadErrorFlag = PXP_STAT_AXI_READ_ERROR_0_MASK, /*!< PXP encountered an AXI read error
  72. and processing has been terminated. */
  73. kPXP_Axi0WriteErrorFlag = PXP_STAT_AXI_WRITE_ERROR_0_MASK, /*!< PXP encountered an AXI write error
  74. and processing has been terminated. */
  75. #if defined(PXP_STAT_AXI_READ_ERROR_1_MASK)
  76. kPXP_Axi1ReadErrorFlag = PXP_STAT_AXI_READ_ERROR_1_MASK, /*!< PXP encountered an AXI read error
  77. and processing has been terminated. */
  78. kPXP_Axi1WriteErrorFlag = PXP_STAT_AXI_WRITE_ERROR_1_MASK, /*!< PXP encountered an AXI write error
  79. and processing has been terminated. */
  80. #endif
  81. };
  82. /*! @brief PXP output flip mode. */
  83. typedef enum _pxp_flip_mode
  84. {
  85. kPXP_FlipDisable = 0U, /*!< Flip disable. */
  86. kPXP_FlipHorizontal = 0x01U, /*!< Horizontal flip. */
  87. kPXP_FlipVertical = 0x02U, /*!< Vertical flip. */
  88. kPXP_FlipBoth = 0x03U, /*!< Flip both directions. */
  89. } pxp_flip_mode_t;
  90. /*! @brief PXP rotate mode. */
  91. typedef enum _pxp_rotate_position
  92. {
  93. kPXP_RotateOutputBuffer = 0U, /*!< Rotate the output buffer. */
  94. kPXP_RotateProcessSurface, /*!< Rotate the process surface. */
  95. } pxp_rotate_position_t;
  96. /*! @brief PXP rotate degree. */
  97. typedef enum _pxp_rotate_degree
  98. {
  99. kPXP_Rotate0 = 0U, /*!< Clock wise rotate 0 deg. */
  100. kPXP_Rotate90, /*!< Clock wise rotate 90 deg. */
  101. kPXP_Rotate180, /*!< Clock wise rotate 180 deg. */
  102. kPXP_Rotate270, /*!< Clock wise rotate 270 deg. */
  103. } pxp_rotate_degree_t;
  104. /*! @brief PXP interlaced output mode. */
  105. typedef enum _pxp_interlaced_output_mode
  106. {
  107. kPXP_OutputProgressive = 0U, /*!< All data written in progressive format to output buffer 0. */
  108. kPXP_OutputField0, /*!< Only write field 0 data to output buffer 0. */
  109. kPXP_OutputField1, /*!< Only write field 1 data to output buffer 0. */
  110. kPXP_OutputInterlaced, /*!< Field 0 write to buffer 0, field 1 write to buffer 1. */
  111. } pxp_interlaced_output_mode_t;
  112. /*! @brief PXP output buffer format. */
  113. typedef enum _pxp_output_pixel_format
  114. {
  115. kPXP_OutputPixelFormatARGB8888 = 0x0, /*!< 32-bit pixels with alpha. */
  116. kPXP_OutputPixelFormatRGB888 = 0x4, /*!< 32-bit pixels without alpha (unpacked 24-bit format) */
  117. kPXP_OutputPixelFormatRGB888P = 0x5, /*!< 24-bit pixels without alpha (packed 24-bit format) */
  118. kPXP_OutputPixelFormatARGB1555 = 0x8, /*!< 16-bit pixels with alpha. */
  119. kPXP_OutputPixelFormatARGB4444 = 0x9, /*!< 16-bit pixels with alpha. */
  120. kPXP_OutputPixelFormatRGB555 = 0xC, /*!< 16-bit pixels without alpha. */
  121. kPXP_OutputPixelFormatRGB444 = 0xD, /*!< 16-bit pixels without alpha. */
  122. kPXP_OutputPixelFormatRGB565 = 0xE, /*!< 16-bit pixels without alpha. */
  123. kPXP_OutputPixelFormatYUV1P444 = 0x10, /*!< 32-bit pixels (1-plane XYUV unpacked). */
  124. kPXP_OutputPixelFormatUYVY1P422 = 0x12, /*!< 16-bit pixels (1-plane U0,Y0,V0,Y1 interleaved bytes) */
  125. kPXP_OutputPixelFormatVYUY1P422 = 0x13, /*!< 16-bit pixels (1-plane V0,Y0,U0,Y1 interleaved bytes) */
  126. kPXP_OutputPixelFormatY8 = 0x14, /*!< 8-bit monochrome pixels (1-plane Y luma output) */
  127. kPXP_OutputPixelFormatY4 = 0x15, /*!< 4-bit monochrome pixels (1-plane Y luma, 4 bit truncation) */
  128. kPXP_OutputPixelFormatYUV2P422 = 0x18, /*!< 16-bit pixels (2-plane UV interleaved bytes) */
  129. kPXP_OutputPixelFormatYUV2P420 = 0x19, /*!< 16-bit pixels (2-plane UV) */
  130. kPXP_OutputPixelFormatYVU2P422 = 0x1A, /*!< 16-bit pixels (2-plane VU interleaved bytes) */
  131. kPXP_OutputPixelFormatYVU2P420 = 0x1B, /*!< 16-bit pixels (2-plane VU) */
  132. } pxp_output_pixel_format_t;
  133. /*! @brief PXP output buffer configuration. */
  134. typedef struct _pxp_output_buffer_config
  135. {
  136. pxp_output_pixel_format_t pixelFormat; /*!< Output buffer pixel format. */
  137. pxp_interlaced_output_mode_t interlacedMode; /*!< Interlaced output mode. */
  138. uint32_t buffer0Addr; /*!< Output buffer 0 address. */
  139. uint32_t buffer1Addr; /*!< Output buffer 1 address, used for UV data in YUV 2-plane mode, or
  140. field 1 in output interlaced mode. */
  141. uint16_t pitchBytes; /*!< Number of bytes between two vertically adjacent pixels. */
  142. uint16_t width; /*!< Pixels per line. */
  143. uint16_t height; /*!< How many lines in output buffer. */
  144. } pxp_output_buffer_config_t;
  145. /*! @brief PXP process surface buffer pixel format. */
  146. typedef enum _pxp_ps_pixel_format
  147. {
  148. kPXP_PsPixelFormatRGB888 = 0x4, /*!< 32-bit pixels without alpha (unpacked 24-bit format) */
  149. kPXP_PsPixelFormatRGB555 = 0xC, /*!< 16-bit pixels without alpha. */
  150. kPXP_PsPixelFormatRGB444 = 0xD, /*!< 16-bit pixels without alpha. */
  151. kPXP_PsPixelFormatRGB565 = 0xE, /*!< 16-bit pixels without alpha. */
  152. kPXP_PsPixelFormatYUV1P444 = 0x10, /*!< 32-bit pixels (1-plane XYUV unpacked). */
  153. kPXP_PsPixelFormatUYVY1P422 = 0x12, /*!< 16-bit pixels (1-plane U0,Y0,V0,Y1 interleaved bytes) */
  154. kPXP_PsPixelFormatVYUY1P422 = 0x13, /*!< 16-bit pixels (1-plane V0,Y0,U0,Y1 interleaved bytes) */
  155. kPXP_PsPixelFormatY8 = 0x14, /*!< 8-bit monochrome pixels (1-plane Y luma output) */
  156. kPXP_PsPixelFormatY4 = 0x15, /*!< 4-bit monochrome pixels (1-plane Y luma, 4 bit truncation) */
  157. kPXP_PsPixelFormatYUV2P422 = 0x18, /*!< 16-bit pixels (2-plane UV interleaved bytes) */
  158. kPXP_PsPixelFormatYUV2P420 = 0x19, /*!< 16-bit pixels (2-plane UV) */
  159. kPXP_PsPixelFormatYVU2P422 = 0x1A, /*!< 16-bit pixels (2-plane VU interleaved bytes) */
  160. kPXP_PsPixelFormatYVU2P420 = 0x1B, /*!< 16-bit pixels (2-plane VU) */
  161. kPXP_PsPixelFormatYVU422 = 0x1E, /*!< 16-bit pixels (3-plane) */
  162. kPXP_PsPixelFormatYVU420 = 0x1F, /*!< 16-bit pixels (3-plane) */
  163. } pxp_ps_pixel_format_t;
  164. /*! @brief PXP process surface buffer YUV format. */
  165. typedef enum _pxp_ps_yuv_format
  166. {
  167. kPXP_PsYUVFormatYUV = 0U, /*!< YUV format. */
  168. kPXP_PsYUVFormatYCbCr, /*!< YCbCr format. */
  169. } pxp_ps_yuv_format_t;
  170. /*! @brief PXP process surface buffer configuration. */
  171. typedef struct _pxp_ps_buffer_config
  172. {
  173. pxp_ps_pixel_format_t pixelFormat; /*!< PS buffer pixel format. */
  174. bool swapByte; /*!< For each 16 bit word, set true to swap the two bytes. */
  175. uint32_t bufferAddr; /*!< Input buffer address for the first panel. */
  176. uint32_t bufferAddrU; /*!< Input buffer address for the second panel. */
  177. uint32_t bufferAddrV; /*!< Input buffer address for the third panel. */
  178. uint16_t pitchBytes; /*!< Number of bytes between two vertically adjacent pixels. */
  179. } pxp_ps_buffer_config_t;
  180. /*! @brief PXP alpha surface buffer pixel format. */
  181. typedef enum _pxp_as_pixel_format
  182. {
  183. kPXP_AsPixelFormatARGB8888 = 0x0, /*!< 32-bit pixels with alpha. */
  184. kPXP_AsPixelFormatRGB888 = 0x4, /*!< 32-bit pixels without alpha (unpacked 24-bit format) */
  185. kPXP_AsPixelFormatARGB1555 = 0x8, /*!< 16-bit pixels with alpha. */
  186. kPXP_AsPixelFormatARGB4444 = 0x9, /*!< 16-bit pixels with alpha. */
  187. kPXP_AsPixelFormatRGB555 = 0xC, /*!< 16-bit pixels without alpha. */
  188. kPXP_AsPixelFormatRGB444 = 0xD, /*!< 16-bit pixels without alpha. */
  189. kPXP_AsPixelFormatRGB565 = 0xE, /*!< 16-bit pixels without alpha. */
  190. } pxp_as_pixel_format_t;
  191. /*! @brief PXP alphs surface buffer configuration. */
  192. typedef struct _pxp_as_buffer_config
  193. {
  194. pxp_as_pixel_format_t pixelFormat; /*!< AS buffer pixel format. */
  195. uint32_t bufferAddr; /*!< Input buffer address. */
  196. uint16_t pitchBytes; /*!< Number of bytes between two vertically adjacent pixels. */
  197. } pxp_as_buffer_config_t;
  198. /*!
  199. * @brief PXP alpha mode during blending.
  200. */
  201. typedef enum _pxp_alpha_mode
  202. {
  203. kPXP_AlphaEmbedded, /*!< The alpha surface pixel alpha value will be used for blend. */
  204. kPXP_AlphaOverride, /*!< The user defined alpha value will be used for blend directly. */
  205. kPXP_AlphaMultiply, /*!< The alpha surface pixel alpha value scaled the user defined
  206. alpha value will be used for blend, for example, pixel alpha set
  207. set to 200, user defined alpha set to 100, then the reault alpha
  208. is 200 * 100 / 255. */
  209. kPXP_AlphaRop /*!< Raster operation. */
  210. } pxp_alpha_mode_t;
  211. /*!
  212. * @brief PXP ROP mode during blending.
  213. *
  214. * Explanation:
  215. * - AS: Alpha surface
  216. * - PS: Process surface
  217. * - nAS: Alpha surface NOT value
  218. * - nPS: Process surface NOT value
  219. */
  220. typedef enum _pxp_rop_mode
  221. {
  222. kPXP_RopMaskAs = 0x0, /*!< AS AND PS. */
  223. kPXP_RopMaskNotAs = 0x1, /*!< nAS AND PS. */
  224. kPXP_RopMaskAsNot = 0x2, /*!< AS AND nPS. */
  225. kPXP_RopMergeAs = 0x3, /*!< AS OR PS. */
  226. kPXP_RopMergeNotAs = 0x4, /*!< nAS OR PS. */
  227. kPXP_RopMergeAsNot = 0x5, /*!< AS OR nPS. */
  228. kPXP_RopNotCopyAs = 0x6, /*!< nAS. */
  229. kPXP_RopNot = 0x7, /*!< nPS. */
  230. kPXP_RopNotMaskAs = 0x8, /*!< AS NAND PS. */
  231. kPXP_RopNotMergeAs = 0x9, /*!< AS NOR PS. */
  232. kPXP_RopXorAs = 0xA, /*!< AS XOR PS. */
  233. kPXP_RopNotXorAs = 0xB /*!< AS XNOR PS. */
  234. } pxp_rop_mode_t;
  235. /*!
  236. * @brief PXP alpha surface blending configuration.
  237. */
  238. typedef struct _pxp_as_blend_config
  239. {
  240. uint8_t alpha; /*!< User defined alpha value, only used when @ref alphaMode is @ref kPXP_AlphaOverride or @ref
  241. kPXP_AlphaRop. */
  242. bool invertAlpha; /*!< Set true to invert the alpha. */
  243. pxp_alpha_mode_t alphaMode; /*!< Alpha mode. */
  244. pxp_rop_mode_t ropMode; /*!< ROP mode, only valid when @ref alphaMode is @ref kPXP_AlphaRop. */
  245. } pxp_as_blend_config_t;
  246. /*! @brief PXP process block size. */
  247. typedef enum _pxp_block_size
  248. {
  249. kPXP_BlockSize8 = 0U, /*!< Process 8x8 pixel blocks. */
  250. kPXP_BlockSize16, /*!< Process 16x16 pixel blocks. */
  251. } pxp_block_size_t;
  252. /*! @brief PXP CSC1 mode. */
  253. typedef enum _pxp_csc1_mode
  254. {
  255. kPXP_Csc1YUV2RGB = 0U, /*!< YUV to RGB. */
  256. kPXP_Csc1YCbCr2RGB, /*!< YCbCr to RGB. */
  257. } pxp_csc1_mode_t;
  258. /*! @brief PXP CSC2 mode. */
  259. typedef enum _pxp_csc2_mode
  260. {
  261. kPXP_Csc2YUV2RGB = 0U, /*!< YUV to RGB. */
  262. kPXP_Csc2YCbCr2RGB, /*!< YCbCr to RGB. */
  263. kPXP_Csc2RGB2YUV, /*!< RGB to YUV. */
  264. kPXP_Csc2RGB2YCbCr, /*!< RGB to YCbCr. */
  265. } pxp_csc2_mode_t;
  266. /*!
  267. * @brief PXP CSC2 configuration.
  268. *
  269. * Converting from YUV/YCbCr color spaces to the RGB color space uses the
  270. * following equation structure:
  271. *
  272. * R = A1(Y+D1) + A2(U+D2) + A3(V+D3)
  273. * G = B1(Y+D1) + B2(U+D2) + B3(V+D3)
  274. * B = C1(Y+D1) + C2(U+D2) + C3(V+D3)
  275. *
  276. * Converting from the RGB color space to YUV/YCbCr color spaces uses the
  277. * following equation structure:
  278. *
  279. * Y = A1*R + A2*G + A3*B + D1
  280. * U = B1*R + B2*G + B3*B + D2
  281. * V = C1*R + C2*G + C3*B + D3
  282. */
  283. typedef struct _pxp_csc2_config
  284. {
  285. pxp_csc2_mode_t mode; /*!< Convertion mode. */
  286. float A1; /*!< A1. */
  287. float A2; /*!< A2. */
  288. float A3; /*!< A3. */
  289. float B1; /*!< B1. */
  290. float B2; /*!< B2. */
  291. float B3; /*!< B3. */
  292. float C1; /*!< C1. */
  293. float C2; /*!< C2. */
  294. float C3; /*!< C3. */
  295. int16_t D1; /*!< D1. */
  296. int16_t D2; /*!< D2. */
  297. int16_t D3; /*!< D3. */
  298. } pxp_csc2_config_t;
  299. #if !(defined(FSL_FEATURE_PXP_HAS_NO_LUT) && FSL_FEATURE_PXP_HAS_NO_LUT)
  300. /*! @brief PXP LUT lookup mode. */
  301. typedef enum _pxp_lut_lookup_mode
  302. {
  303. kPXP_LutCacheRGB565 = 0U, /*!< LUT ADDR = R[7:3],G[7:2],B[7:3]. Use all 16KB of LUT
  304. for indirect cached 128KB lookup. */
  305. kPXP_LutDirectY8, /*!< LUT ADDR = 16'b0,Y[7:0]. Use the first 256 bytes of LUT.
  306. Only third data path byte is tranformed. */
  307. kPXP_LutDirectRGB444, /*!< LUT ADDR = R[7:4],G[7:4],B[7:4]. Use one 8KB bank of LUT
  308. selected by @ref PXP_Select8kLutBank. */
  309. kPXP_LutDirectRGB454, /*!< LUT ADDR = R[7:4],G[7:3],B[7:4]. Use all 16KB of LUT. */
  310. } pxp_lut_lookup_mode_t;
  311. /*! @brief PXP LUT output mode. */
  312. typedef enum _pxp_lut_out_mode
  313. {
  314. kPXP_LutOutY8 = 1U, /*!< R/Y byte lane 2 lookup, bytes 1,0 bypassed. */
  315. kPXP_LutOutRGBW4444CFA, /*!< Byte lane 2 = CFA_Y8, byte lane 1,0 = RGBW4444. */
  316. kPXP_LutOutRGB888, /*!< RGB565->RGB888 conversion for Gamma correction. */
  317. } pxp_lut_out_mode_t;
  318. /*! @brief PXP LUT 8K bank index used when lookup mode is @ref kPXP_LutDirectRGB444. */
  319. typedef enum _pxp_lut_8k_bank
  320. {
  321. kPXP_Lut8kBank0 = 0U, /*!< The first 8K bank used. */
  322. kPXP_Lut8kBank1, /*!< The second 8K bank used. */
  323. } pxp_lut_8k_bank_t;
  324. /*! @brief PXP LUT configuration. */
  325. typedef struct _pxp_lut_config
  326. {
  327. pxp_lut_lookup_mode_t lookupMode; /*!< Look up mode. */
  328. pxp_lut_out_mode_t outMode; /*!< Out mode. */
  329. uint32_t cfaValue; /*!< The CFA value used when look up mode is @ref kPXP_LutOutRGBW4444CFA. */
  330. } pxp_lut_config_t;
  331. #endif /* FSL_FEATURE_PXP_HAS_NO_LUT */
  332. /*! @brief PXP internal memory. */
  333. typedef enum _pxp_ram
  334. {
  335. kPXP_RamDither0Lut = 0U, /*!< Dither 0 LUT memory. */
  336. kPXP_RamDither1Lut = 3U, /*!< Dither 1 LUT memory. */
  337. kPXP_RamDither2Lut = 4U, /*!< Dither 2 LUT memory. */
  338. } pxp_ram_t;
  339. /*! @brief PXP dither mode. */
  340. enum _pxp_dither_mode
  341. {
  342. kPXP_DitherPassThrough = 0U, /*!< Pass through, no dither. */
  343. kPXP_DitherOrdered = 3U, /*!< Ordered dither. */
  344. kPXP_DitherQuantOnly = 4U, /*!< No dithering, only quantization. */
  345. };
  346. /*! @brief PXP dither LUT mode. */
  347. enum _pxp_dither_lut_mode
  348. {
  349. kPXP_DitherLutOff = 0U, /*!< The LUT memory is not used for LUT, could be used as ordered dither index matrix. */
  350. kPXP_DitherLutPreDither, /*!< Use LUT at the pre-dither stage, The pre-dither LUT could only be used in Floyd mode
  351. or Atkinson mode, which are not supported by current PXP module. */
  352. kPXP_DitherLutPostDither, /*!< Use LUT at the post-dither stage. */
  353. };
  354. /*! @brief PXP dither matrix size. */
  355. enum _pxp_dither_matrix_size
  356. {
  357. kPXP_DitherMatrix8 = 1, /*!< The dither index matrix is 8x8. */
  358. kPXP_DitherMatrix16, /*!< The dither index matrix is 16x16. */
  359. };
  360. /*! @brief PXP dither final LUT data. */
  361. typedef struct _pxp_dither_final_lut_data
  362. {
  363. uint32_t data_3_0; /*!< Data 3 to data 0. Data 0 is the least significant byte. */
  364. uint32_t data_7_4; /*!< Data 7 to data 4. Data 4 is the least significant byte. */
  365. uint32_t data_11_8; /*!< Data 11 to data 8. Data 8 is the least significant byte. */
  366. uint32_t data_15_12; /*!< Data 15 to data 12. Data 12 is the least significant byte. */
  367. } pxp_dither_final_lut_data_t;
  368. /*! @brief PXP dither configuration. */
  369. typedef struct _pxp_dither_config
  370. {
  371. uint32_t enableDither0 : 1; /*!< Enable dither engine 0 or not, set 1 to enable, 0 to disable. */
  372. uint32_t enableDither1 : 1; /*!< Enable dither engine 1 or not, set 1 to enable, 0 to disable. */
  373. uint32_t enableDither2 : 1; /*!< Enable dither engine 2 or not, set 1 to enable, 0 to disable. */
  374. uint32_t ditherMode0 : 3; /*!< Dither mode for dither engine 0. See @ref _pxp_dither_mode. */
  375. uint32_t ditherMode1 : 3; /*!< Dither mode for dither engine 1. See @ref _pxp_dither_mode. */
  376. uint32_t ditherMode2 : 3; /*!< Dither mode for dither engine 2. See @ref _pxp_dither_mode. */
  377. uint32_t quantBitNum : 3; /*!< Number of bits quantize down to, the valid value is 1~7. */
  378. uint32_t lutMode : 2; /*!< How to use the memory LUT, see @ref _pxp_dither_lut_mode. This must be set to @ref
  379. kPXP_DitherLutOff
  380. if any dither engine uses @ref kPXP_DitherOrdered mode. */
  381. uint32_t idxMatrixSize0 : 2; /*!< Size of index matrix used for dither for dither engine 0, see @ref
  382. _pxp_dither_matrix_size. */
  383. uint32_t idxMatrixSize1 : 2; /*!< Size of index matrix used for dither for dither engine 1, see @ref
  384. _pxp_dither_matrix_size. */
  385. uint32_t idxMatrixSize2 : 2; /*!< Size of index matrix used for dither for dither engine 2, see @ref
  386. _pxp_dither_matrix_size. */
  387. uint32_t enableFinalLut : 1; /*!< Enable the final LUT, set 1 to enable, 0 to disable. */
  388. uint32_t : 8;
  389. } pxp_dither_config_t;
  390. /*!
  391. * @brief Porter Duff factor mode.
  392. * @anchor pxp_porter_duff_factor_mode
  393. */
  394. enum
  395. {
  396. kPXP_PorterDuffFactorOne = 0U, /*!< Use 1. */
  397. kPXP_PorterDuffFactorZero, /*!< Use 0. */
  398. kPXP_PorterDuffFactorStraight, /*!< Use straight alpha. */
  399. kPXP_PorterDuffFactorInversed, /*!< Use inversed alpha. */
  400. };
  401. /*!
  402. * @brief Porter Duff global alpha mode.
  403. * @anchor pxp_porter_duff_global_alpha_mode
  404. */
  405. enum
  406. {
  407. kPXP_PorterDuffGlobalAlpha = 0U, /*!< Use global alpha. */
  408. kPXP_PorterDuffLocalAlpha, /*!< Use local alpha in each pixel. */
  409. kPXP_PorterDuffScaledAlpha, /*!< Use global alpha * local alpha. */
  410. };
  411. /*!
  412. * @brief Porter Duff alpha mode.
  413. * @anchor pxp_porter_duff_alpha_mode
  414. */
  415. enum
  416. {
  417. kPXP_PorterDuffAlphaStraight = 0U, /*!< Use straight alpha, s0_alpha' = s0_alpha. */
  418. kPXP_PorterDuffAlphaInversed /*!< Use inversed alpha, s0_alpha' = 0xFF - s0_alpha. */
  419. };
  420. /*!
  421. * @brief Porter Duff color mode.
  422. * @anchor pxp_porter_duff_color_mode
  423. */
  424. enum
  425. {
  426. kPXP_PorterDuffColorStraight = 0, /*!< @deprecated Use kPXP_PorterDuffColorNoAlpha. */
  427. kPXP_PorterDuffColorInversed = 1, /*!< @deprecated Use kPXP_PorterDuffColorWithAlpha. */
  428. kPXP_PorterDuffColorNoAlpha = 0, /*!< s0_pixel' = s0_pixel. */
  429. kPXP_PorterDuffColorWithAlpha = 1, /*!< s0_pixel' = s0_pixel * s0_alpha". */
  430. };
  431. /*! @brief PXP Porter Duff configuration. */
  432. typedef struct
  433. {
  434. uint32_t enable : 1; /*!< Enable or disable Porter Duff. */
  435. uint32_t srcFactorMode : 2; /*!< Source layer (or AS, s1) factor mode, see @ref pxp_porter_duff_factor_mode. */
  436. uint32_t dstGlobalAlphaMode : 2; /*!< Destination layer (or PS, s0) global alpha mode, see
  437. @ref pxp_porter_duff_global_alpha_mode. */
  438. uint32_t dstAlphaMode : 1; /*!< Destination layer (or PS, s0) alpha mode, see @ref pxp_porter_duff_alpha_mode. */
  439. uint32_t dstColorMode : 1; /*!< Destination layer (or PS, s0) color mode, see @ref pxp_porter_duff_color_mode. */
  440. uint32_t : 1;
  441. uint32_t dstFactorMode : 2; /*!< Destination layer (or PS, s0) factor mode, see @ref pxp_porter_duff_factor_mode. */
  442. uint32_t srcGlobalAlphaMode : 2; /*!< Source layer (or AS, s1) global alpha mode, see
  443. @ref pxp_porter_duff_global_alpha_mode. */
  444. uint32_t srcAlphaMode : 1; /*!< Source layer (or AS, s1) alpha mode, see @ref pxp_porter_duff_alpha_mode. */
  445. uint32_t srcColorMode : 1; /*!< Source layer (or AS, s1) color mode, see @ref pxp_porter_duff_color_mode. */
  446. uint32_t : 2;
  447. uint32_t dstGlobalAlpha : 8; /*!< Destination layer (or PS, s0) global alpha value, 0~255. */
  448. uint32_t srcGlobalAlpha : 8; /*!< Source layer (or AS, s1) global alpha value, 0~255. */
  449. } pxp_porter_duff_config_t;
  450. /*! @brief PXP Porter Duff blend mode. Note: don't change the enum item value */
  451. typedef enum _pxp_porter_duff_blend_mode
  452. {
  453. kPXP_PorterDuffSrc = 0, /*!< Source Only */
  454. kPXP_PorterDuffAtop, /*!< Source Atop */
  455. kPXP_PorterDuffOver, /*!< Source Over */
  456. kPXP_PorterDuffIn, /*!< Source In. */
  457. kPXP_PorterDuffOut, /*!< Source Out. */
  458. kPXP_PorterDuffDst, /*!< Destination Only. */
  459. kPXP_PorterDuffDstAtop, /*!< Destination Atop. */
  460. kPXP_PorterDuffDstOver, /*!< Destination Over. */
  461. kPXP_PorterDuffDstIn, /*!< Destination In. */
  462. kPXP_PorterDuffDstOut, /*!< Destination Out. */
  463. kPXP_PorterDuffXor, /*!< XOR. */
  464. kPXP_PorterDuffClear, /*!< Clear. */
  465. kPXP_PorterDuffMax,
  466. } pxp_porter_duff_blend_mode_t;
  467. /*! @brief PXP Porter Duff blend mode. Note: don't change the enum item value */
  468. typedef struct _pxp_pic_copy_config
  469. {
  470. uint32_t srcPicBaseAddr; /*!< Source picture base address. */
  471. uint16_t srcPitchBytes; /*!< Pitch of the source buffer. */
  472. uint16_t srcOffsetX; /*!< Copy position in source picture. */
  473. uint16_t srcOffsetY; /*!< Copy position in source picture. */
  474. uint32_t destPicBaseAddr; /*!< Destination picture base address. */
  475. uint16_t destPitchBytes; /*!< Pitch of the destination buffer. */
  476. uint16_t destOffsetX; /*!< Copy position in destination picture. */
  477. uint16_t destOffsetY; /*!< Copy position in destination picture. */
  478. uint16_t width; /*!< Pixel number each line to copy. */
  479. uint16_t height; /*!< Lines to copy. */
  480. pxp_as_pixel_format_t pixelFormat; /*!< Buffer pixel format. */
  481. } pxp_pic_copy_config_t;
  482. /*******************************************************************************
  483. * API
  484. ******************************************************************************/
  485. #if defined(__cplusplus)
  486. extern "C" {
  487. #endif
  488. /*!
  489. * @name Initialization and deinitialization
  490. * @{
  491. */
  492. /*!
  493. * @brief Initialize the PXP.
  494. *
  495. * This function enables the PXP peripheral clock, and resets the PXP registers
  496. * to default status.
  497. *
  498. * @param base PXP peripheral base address.
  499. */
  500. void PXP_Init(PXP_Type *base);
  501. /*!
  502. * @brief De-initialize the PXP.
  503. *
  504. * This function disables the PXP peripheral clock.
  505. *
  506. * @param base PXP peripheral base address.
  507. */
  508. void PXP_Deinit(PXP_Type *base);
  509. /*!
  510. * @brief Reset the PXP.
  511. *
  512. * This function resets the PXP peripheral registers to default status.
  513. *
  514. * @param base PXP peripheral base address.
  515. */
  516. void PXP_Reset(PXP_Type *base);
  517. /* @} */
  518. /*!
  519. * @name Global operations
  520. * @{
  521. */
  522. /*!
  523. * @brief Start process.
  524. *
  525. * Start PXP process using current configuration.
  526. *
  527. * @param base PXP peripheral base address.
  528. */
  529. static inline void PXP_Start(PXP_Type *base)
  530. {
  531. base->CTRL_SET = PXP_CTRL_ENABLE_MASK;
  532. }
  533. /*!
  534. * @brief Enable or disable LCD hand shake.
  535. *
  536. * @param base PXP peripheral base address.
  537. * @param enable True to enable, false to disable.
  538. */
  539. static inline void PXP_EnableLcdHandShake(PXP_Type *base, bool enable)
  540. {
  541. #if defined(PXP_CTRL_ENABLE_LCD_HANDSHAKE_MASK)
  542. if (enable)
  543. {
  544. base->CTRL_SET = PXP_CTRL_ENABLE_LCD_HANDSHAKE_MASK;
  545. }
  546. else
  547. {
  548. base->CTRL_CLR = PXP_CTRL_ENABLE_LCD_HANDSHAKE_MASK;
  549. }
  550. #else
  551. if (enable)
  552. {
  553. base->CTRL_SET = PXP_CTRL_ENABLE_LCD0_HANDSHAKE_MASK;
  554. }
  555. else
  556. {
  557. base->CTRL_CLR = PXP_CTRL_ENABLE_LCD0_HANDSHAKE_MASK;
  558. }
  559. #endif
  560. }
  561. #if (defined(FSL_FEATURE_PXP_HAS_EN_REPEAT) && FSL_FEATURE_PXP_HAS_EN_REPEAT)
  562. /*!
  563. * @brief Enable or disable continous run.
  564. *
  565. * If continous run not enabled, @ref PXP_Start starts the PXP process. When completed,
  566. * PXP enters idle mode and flag @ref kPXP_CompleteFlag asserts.
  567. *
  568. * If continous run enabled, the PXP will repeat based on the current configuration register
  569. * settings.
  570. *
  571. * @param base PXP peripheral base address.
  572. * @param enable True to enable, false to disable.
  573. */
  574. static inline void PXP_EnableContinousRun(PXP_Type *base, bool enable)
  575. {
  576. if (enable)
  577. {
  578. base->CTRL_SET = PXP_CTRL_EN_REPEAT_MASK;
  579. }
  580. else
  581. {
  582. base->CTRL_CLR = PXP_CTRL_EN_REPEAT_MASK;
  583. }
  584. }
  585. #endif /* FSL_FEATURE_PXP_HAS_EN_REPEAT */
  586. /*!
  587. * @brief Set the PXP processing block size
  588. *
  589. * This function chooses the pixel block size that PXP using during process.
  590. * Larger block size means better performace, but be careful that when PXP is
  591. * rotating, the output must be divisible by the block size selected.
  592. *
  593. * @param base PXP peripheral base address.
  594. * @param size The pixel block size.
  595. */
  596. static inline void PXP_SetProcessBlockSize(PXP_Type *base, pxp_block_size_t size)
  597. {
  598. base->CTRL = (base->CTRL & ~PXP_CTRL_BLOCK_SIZE_MASK) | PXP_CTRL_BLOCK_SIZE(size);
  599. }
  600. /* @} */
  601. /*!
  602. * @name Status
  603. * @{
  604. */
  605. /*!
  606. * @brief Gets PXP status flags.
  607. *
  608. * This function gets all PXP status flags. The flags are returned as the logical
  609. * OR value of the enumerators @ref _pxp_flags. To check a specific status,
  610. * compare the return value with enumerators in @ref _pxp_flags.
  611. * For example, to check whether the PXP has completed process, use like this:
  612. * @code
  613. if (kPXP_CompleteFlag & PXP_GetStatusFlags(PXP))
  614. {
  615. ...
  616. }
  617. @endcode
  618. *
  619. * @param base PXP peripheral base address.
  620. * @return PXP status flags which are OR'ed by the enumerators in the _pxp_flags.
  621. */
  622. static inline uint32_t PXP_GetStatusFlags(PXP_Type *base)
  623. {
  624. #if defined(PXP_STAT_AXI_READ_ERROR_1_MASK)
  625. return base->STAT &
  626. (PXP_STAT_NEXT_IRQ_MASK | PXP_STAT_IRQ0_MASK | PXP_STAT_AXI_READ_ERROR_0_MASK |
  627. PXP_STAT_AXI_WRITE_ERROR_0_MASK | PXP_STAT_AXI_READ_ERROR_1_MASK | PXP_STAT_AXI_WRITE_ERROR_1_MASK);
  628. #else
  629. return base->STAT & (PXP_STAT_NEXT_IRQ_MASK | PXP_STAT_IRQ0_MASK | PXP_STAT_AXI_READ_ERROR_0_MASK |
  630. PXP_STAT_AXI_WRITE_ERROR_0_MASK);
  631. #endif
  632. }
  633. /*!
  634. * @brief Clears status flags with the provided mask.
  635. *
  636. * This function clears PXP status flags with a provided mask.
  637. *
  638. * @param base PXP peripheral base address.
  639. * @param statusMask The status flags to be cleared; it is logical OR value of @ref _pxp_flags.
  640. */
  641. static inline void PXP_ClearStatusFlags(PXP_Type *base, uint32_t statusMask)
  642. {
  643. base->STAT_CLR = statusMask;
  644. }
  645. /*!
  646. * @brief Gets the AXI ID of the failing bus operation.
  647. *
  648. * @param base PXP peripheral base address.
  649. * @param axiIndex Whitch AXI to get
  650. * - 0: AXI0
  651. * - 1: AXI1
  652. * @return The AXI ID of the failing bus operation.
  653. */
  654. static inline uint8_t PXP_GetAxiErrorId(PXP_Type *base, uint8_t axiIndex)
  655. {
  656. #if defined(PXP_STAT_AXI_ERROR_ID_1_MASK)
  657. if (0 == axiIndex)
  658. {
  659. return (uint8_t)((base->STAT & PXP_STAT_AXI_ERROR_ID_0_MASK) >> PXP_STAT_AXI_ERROR_ID_0_SHIFT);
  660. }
  661. else
  662. {
  663. return (uint8_t)((base->STAT & PXP_STAT_AXI_ERROR_ID_1_MASK) >> PXP_STAT_AXI_ERROR_ID_1_SHIFT);
  664. }
  665. #else
  666. return (uint8_t)((base->STAT & PXP_STAT_AXI_ERROR_ID_MASK) >> PXP_STAT_AXI_ERROR_ID_SHIFT);
  667. #endif
  668. }
  669. /* @} */
  670. /*!
  671. * @name Interrupts
  672. * @{
  673. */
  674. /*!
  675. * @brief Enables PXP interrupts according to the provided mask.
  676. *
  677. * This function enables the PXP interrupts according to the provided mask. The mask
  678. * is a logical OR of enumeration members. See @ref _pxp_interrupt_enable.
  679. * For example, to enable PXP process complete interrupt and command loaded
  680. * interrupt, do the following.
  681. * @code
  682. PXP_EnableInterrupts(PXP, kPXP_CommandLoadInterruptEnable | kPXP_CompleteInterruptEnable);
  683. @endcode
  684. *
  685. * @param base PXP peripheral base address.
  686. * @param mask The interrupts to enable. Logical OR of @ref _pxp_interrupt_enable.
  687. */
  688. static inline void PXP_EnableInterrupts(PXP_Type *base, uint32_t mask)
  689. {
  690. base->CTRL_SET = mask;
  691. }
  692. /*!
  693. * @brief Disables PXP interrupts according to the provided mask.
  694. *
  695. * This function disables the PXP interrupts according to the provided mask. The mask
  696. * is a logical OR of enumeration members. See @ref _pxp_interrupt_enable.
  697. *
  698. * @param base PXP peripheral base address.
  699. * @param mask The interrupts to disable. Logical OR of @ref _pxp_interrupt_enable.
  700. */
  701. static inline void PXP_DisableInterrupts(PXP_Type *base, uint32_t mask)
  702. {
  703. base->CTRL_CLR = mask;
  704. }
  705. /* @} */
  706. /*!
  707. * @name Alpha surface
  708. * @{
  709. */
  710. /*!
  711. * @brief Set the alpha surface input buffer configuration.
  712. *
  713. * @param base PXP peripheral base address.
  714. * @param config Pointer to the configuration.
  715. */
  716. void PXP_SetAlphaSurfaceBufferConfig(PXP_Type *base, const pxp_as_buffer_config_t *config);
  717. /*!
  718. * @brief Set the alpha surface blending configuration.
  719. *
  720. * @param base PXP peripheral base address.
  721. * @param config Pointer to the configuration structure.
  722. */
  723. void PXP_SetAlphaSurfaceBlendConfig(PXP_Type *base, const pxp_as_blend_config_t *config);
  724. /*!
  725. * @brief Set the alpha surface overlay color key.
  726. *
  727. * If a pixel in the current overlay image with a color that falls in the range
  728. * from the @p colorKeyLow to @p colorKeyHigh range, it will use the process surface
  729. * pixel value for that location. If no PS image is present or if the PS image also
  730. * matches its colorkey range, the PS background color is used.
  731. *
  732. * @param base PXP peripheral base address.
  733. * @param colorKeyLow Color key low range.
  734. * @param colorKeyHigh Color key high range.
  735. *
  736. * @note Colorkey operations are higher priority than alpha or ROP operations
  737. */
  738. void PXP_SetAlphaSurfaceOverlayColorKey(PXP_Type *base, uint32_t colorKeyLow, uint32_t colorKeyHigh);
  739. /*!
  740. * @brief Enable or disable the alpha surface color key.
  741. *
  742. * @param base PXP peripheral base address.
  743. * @param enable True to enable, false to disable.
  744. */
  745. static inline void PXP_EnableAlphaSurfaceOverlayColorKey(PXP_Type *base, bool enable)
  746. {
  747. if (enable)
  748. {
  749. base->AS_CTRL |= PXP_AS_CTRL_ENABLE_COLORKEY_MASK;
  750. }
  751. else
  752. {
  753. base->AS_CTRL &= ~PXP_AS_CTRL_ENABLE_COLORKEY_MASK;
  754. }
  755. }
  756. /*!
  757. * @brief Set the alpha surface position in output buffer.
  758. *
  759. * @param base PXP peripheral base address.
  760. * @param upperLeftX X of the upper left corner.
  761. * @param upperLeftY Y of the upper left corner.
  762. * @param lowerRightX X of the lower right corner.
  763. * @param lowerRightY Y of the lower right corner.
  764. */
  765. void PXP_SetAlphaSurfacePosition(
  766. PXP_Type *base, uint16_t upperLeftX, uint16_t upperLeftY, uint16_t lowerRightX, uint16_t lowerRightY);
  767. /* @} */
  768. /*!
  769. * @name Process surface
  770. * @{
  771. */
  772. /*!
  773. * @brief Set the back ground color of PS.
  774. *
  775. * @param base PXP peripheral base address.
  776. * @param backGroundColor Pixel value of the background color.
  777. */
  778. static inline void PXP_SetProcessSurfaceBackGroundColor(PXP_Type *base, uint32_t backGroundColor)
  779. {
  780. #if defined(PXP_PS_BACKGROUND_0_COLOR_MASK)
  781. base->PS_BACKGROUND_0 = backGroundColor;
  782. #else
  783. base->PS_BACKGROUND = backGroundColor;
  784. #endif
  785. }
  786. /*!
  787. * @brief Set the process surface input buffer configuration.
  788. *
  789. * @param base PXP peripheral base address.
  790. * @param config Pointer to the configuration.
  791. */
  792. void PXP_SetProcessSurfaceBufferConfig(PXP_Type *base, const pxp_ps_buffer_config_t *config);
  793. /*!
  794. * @brief Set the process surface scaler configuration.
  795. *
  796. * The valid down scale fact is 1/(2^12) ~ 16.
  797. *
  798. * @param base PXP peripheral base address.
  799. * @param inputWidth Input image width.
  800. * @param inputHeight Input image height.
  801. * @param outputWidth Output image width.
  802. * @param outputHeight Output image height.
  803. */
  804. void PXP_SetProcessSurfaceScaler(
  805. PXP_Type *base, uint16_t inputWidth, uint16_t inputHeight, uint16_t outputWidth, uint16_t outputHeight);
  806. /*!
  807. * @brief Set the process surface position in output buffer.
  808. *
  809. * @param base PXP peripheral base address.
  810. * @param upperLeftX X of the upper left corner.
  811. * @param upperLeftY Y of the upper left corner.
  812. * @param lowerRightX X of the lower right corner.
  813. * @param lowerRightY Y of the lower right corner.
  814. */
  815. void PXP_SetProcessSurfacePosition(
  816. PXP_Type *base, uint16_t upperLeftX, uint16_t upperLeftY, uint16_t lowerRightX, uint16_t lowerRightY);
  817. /*!
  818. * @brief Set the process surface color key.
  819. *
  820. * If the PS image matches colorkey range, the PS background color is output. Set
  821. * @p colorKeyLow to 0xFFFFFFFF and @p colorKeyHigh to 0 will disable the colorkeying.
  822. *
  823. * @param base PXP peripheral base address.
  824. * @param colorKeyLow Color key low range.
  825. * @param colorKeyHigh Color key high range.
  826. */
  827. void PXP_SetProcessSurfaceColorKey(PXP_Type *base, uint32_t colorKeyLow, uint32_t colorKeyHigh);
  828. /*!
  829. * @brief Set the process surface input pixel format YUV or YCbCr.
  830. *
  831. * If process surface input pixel format is YUV and CSC1 is not enabled,
  832. * in other words, the process surface output pixel format is also YUV,
  833. * then this function should be called to set whether input pixel format
  834. * is YUV or YCbCr.
  835. *
  836. * @param base PXP peripheral base address.
  837. * @param format The YUV format.
  838. */
  839. static inline void PXP_SetProcessSurfaceYUVFormat(PXP_Type *base, pxp_ps_yuv_format_t format)
  840. {
  841. if (kPXP_PsYUVFormatYUV == format)
  842. {
  843. base->CSC1_COEF0 &= ~PXP_CSC1_COEF0_YCBCR_MODE_MASK;
  844. }
  845. else
  846. {
  847. base->CSC1_COEF0 |= PXP_CSC1_COEF0_YCBCR_MODE_MASK;
  848. }
  849. }
  850. /* @} */
  851. /*!
  852. * @name Output buffer
  853. * @{
  854. */
  855. /*!
  856. * @brief Set the PXP outpt buffer configuration.
  857. *
  858. * @param base PXP peripheral base address.
  859. * @param config Pointer to the configuration.
  860. */
  861. void PXP_SetOutputBufferConfig(PXP_Type *base, const pxp_output_buffer_config_t *config);
  862. /*!
  863. * @brief Set the global overwritten alpha value.
  864. *
  865. * If global overwritten alpha is enabled, the alpha component in output buffer pixels
  866. * will be overwritten, otherwise the computed alpha value is used.
  867. *
  868. * @param base PXP peripheral base address.
  869. * @param alpha The alpha value.
  870. */
  871. static inline void PXP_SetOverwrittenAlphaValue(PXP_Type *base, uint8_t alpha)
  872. {
  873. base->OUT_CTRL = (base->OUT_CTRL & ~PXP_OUT_CTRL_ALPHA_MASK) | PXP_OUT_CTRL_ALPHA(alpha);
  874. }
  875. /*!
  876. * @brief Enable or disable the global overwritten alpha value.
  877. *
  878. * If global overwritten alpha is enabled, the alpha component in output buffer pixels
  879. * will be overwritten, otherwise the computed alpha value is used.
  880. *
  881. * @param base PXP peripheral base address.
  882. * @param enable True to enable, false to disable.
  883. */
  884. static inline void PXP_EnableOverWrittenAlpha(PXP_Type *base, bool enable)
  885. {
  886. if (enable)
  887. {
  888. base->OUT_CTRL_SET = PXP_OUT_CTRL_ALPHA_OUTPUT_MASK;
  889. }
  890. else
  891. {
  892. base->OUT_CTRL_CLR = PXP_OUT_CTRL_ALPHA_OUTPUT_MASK;
  893. }
  894. }
  895. /*!
  896. * @brief Set the rotation configuration.
  897. *
  898. * The PXP could rotate the process surface or the output buffer. There are
  899. * two PXP versions:
  900. * - Version 1: Only has one rotate sub module, the output buffer and process
  901. * surface share the same rotate sub module, which means the process surface
  902. * and output buffer could not be rotate at the same time. When pass in
  903. * @ref kPXP_RotateOutputBuffer, the process surface could not use the rotate,
  904. * Also when pass in @ref kPXP_RotateProcessSurface, output buffer could not
  905. * use the rotate.
  906. * - Version 2: Has two seperate rotate sub modules, the output buffer and
  907. * process surface could configure the rotation independently.
  908. *
  909. * Upper layer could use the macro PXP_SHARE_ROTATE to check which version is.
  910. * PXP_SHARE_ROTATE=1 means version 1.
  911. *
  912. * @param base PXP peripheral base address.
  913. * @param position Rotate process surface or output buffer.
  914. * @param degree Rotate degree.
  915. * @param flipMode Flip mode.
  916. *
  917. * @note This function is different depends on the macro PXP_SHARE_ROTATE.
  918. */
  919. static inline void PXP_SetRotateConfig(PXP_Type *base,
  920. pxp_rotate_position_t position,
  921. pxp_rotate_degree_t degree,
  922. pxp_flip_mode_t flipMode)
  923. {
  924. #if PXP_SHARE_ROTATE
  925. base->CTRL =
  926. (base->CTRL & ~(PXP_CTRL_ROTATE_MASK | PXP_CTRL_ROT_POS_MASK | PXP_CTRL_VFLIP_MASK | PXP_CTRL_HFLIP_MASK)) |
  927. PXP_CTRL_ROTATE(degree) | PXP_CTRL_ROT_POS(position) | ((uint32_t)flipMode << PXP_CTRL_HFLIP_SHIFT);
  928. #else
  929. uint32_t ctrl = base->CTRL;
  930. if (kPXP_RotateOutputBuffer == position)
  931. {
  932. if ((degree != kPXP_Rotate0) || (flipMode != kPXP_FlipDisable))
  933. {
  934. base->DATA_PATH_CTRL0 =
  935. (base->DATA_PATH_CTRL0 & (~PXP_DATA_PATH_CTRL0_MUX12_SEL_MASK)) | PXP_DATA_PATH_CTRL0_MUX12_SEL(0);
  936. }
  937. else
  938. {
  939. base->DATA_PATH_CTRL0 =
  940. (base->DATA_PATH_CTRL0 & (~PXP_DATA_PATH_CTRL0_MUX12_SEL_MASK)) | PXP_DATA_PATH_CTRL0_MUX12_SEL(1);
  941. }
  942. ctrl &= ~(PXP_CTRL_HFLIP0_MASK | PXP_CTRL_VFLIP0_MASK | PXP_CTRL_ROTATE0_MASK);
  943. ctrl |= (PXP_CTRL_ROTATE0(degree) | ((uint32_t)flipMode << PXP_CTRL_HFLIP0_SHIFT));
  944. }
  945. else
  946. {
  947. if ((degree != kPXP_Rotate0) || (flipMode != kPXP_FlipDisable))
  948. {
  949. base->DATA_PATH_CTRL0 =
  950. (base->DATA_PATH_CTRL0 & (~PXP_DATA_PATH_CTRL0_MUX3_SEL_MASK)) | PXP_DATA_PATH_CTRL0_MUX3_SEL(1);
  951. }
  952. else
  953. {
  954. base->DATA_PATH_CTRL0 =
  955. (base->DATA_PATH_CTRL0 & (~PXP_DATA_PATH_CTRL0_MUX3_SEL_MASK)) | PXP_DATA_PATH_CTRL0_MUX3_SEL(0);
  956. }
  957. ctrl &= ~(PXP_CTRL_HFLIP1_MASK | PXP_CTRL_VFLIP1_MASK | PXP_CTRL_ROTATE1_MASK);
  958. ctrl |= (PXP_CTRL_ROTATE1(degree) | ((uint32_t)flipMode << PXP_CTRL_HFLIP1_SHIFT));
  959. }
  960. base->CTRL = ctrl;
  961. #endif
  962. }
  963. /* @} */
  964. /*!
  965. * @name Command queue
  966. * @{
  967. */
  968. /*!
  969. * @brief Set the next command.
  970. *
  971. * The PXP supports a primitive ability to queue up one operation while the current
  972. * operation is running. Workflow:
  973. *
  974. * 1. Prepare the PXP register values except STAT, CSCCOEFn, NEXT in the memory
  975. * in the order they appear in the register map.
  976. * 2. Call this function sets the new operation to PXP.
  977. * 3. There are two methods to check whether the PXP has loaded the new operation.
  978. * The first method is using @ref PXP_IsNextCommandPending. If there is new operation
  979. * not loaded by the PXP, this function returns true. The second method is checking
  980. * the flag @ref kPXP_CommandLoadFlag, if command loaded, this flag asserts. User
  981. * could enable interrupt @ref kPXP_CommandLoadInterruptEnable to get the loaded
  982. * signal in interrupt way.
  983. * 4. When command loaded by PXP, a new command could be set using this function.
  984. *
  985. * @code
  986. uint32_t pxp_command1[48];
  987. uint32_t pxp_command2[48];
  988. pxp_command1[0] = ...;
  989. pxp_command1[1] = ...;
  990. ...
  991. pxp_command2[0] = ...;
  992. pxp_command2[1] = ...;
  993. ...
  994. while (PXP_IsNextCommandPending(PXP))
  995. {
  996. }
  997. PXP_SetNextCommand(PXP, pxp_command1);
  998. while (PXP_IsNextCommandPending(PXP))
  999. {
  1000. }
  1001. PXP_SetNextCommand(PXP, pxp_command2);
  1002. @endcode
  1003. *
  1004. * @param base PXP peripheral base address.
  1005. * @param commandAddr Address of the new command.
  1006. */
  1007. void PXP_SetNextCommand(PXP_Type *base, void *commandAddr);
  1008. /*!
  1009. * @brief Check whether the next command is pending.
  1010. *
  1011. * @param base UART peripheral base address.
  1012. * @return True is pending, false is not.
  1013. */
  1014. static inline bool PXP_IsNextCommandPending(PXP_Type *base)
  1015. {
  1016. return (bool)(base->NEXT & PXP_NEXT_ENABLED_MASK);
  1017. }
  1018. /*!
  1019. * @brief Cancel command set by @ref PXP_SetNextCommand
  1020. *
  1021. * @param base UART peripheral base address.
  1022. */
  1023. static inline void PXP_CancelNextCommand(PXP_Type *base)
  1024. {
  1025. /* Write PXP_NEXT_ENABLED_MASK to the register NEXT_CLR to canel the command. */
  1026. *((volatile uint32_t *)(&(base->NEXT)) + 2U) = PXP_NEXT_ENABLED_MASK;
  1027. }
  1028. /* @} */
  1029. /*!
  1030. * @name Color space conversion
  1031. * @{
  1032. */
  1033. #if !(defined(FSL_FEATURE_PXP_HAS_NO_CSC2) && FSL_FEATURE_PXP_HAS_NO_CSC2)
  1034. /*!
  1035. * @brief Set the CSC2 configuration.
  1036. *
  1037. * The CSC2 module receives pixels in any color space and can convert the pixels
  1038. * into any of RGB, YUV, or YCbCr color spaces. The output pixels are passed
  1039. * onto the LUT and rotation engine for further processing
  1040. *
  1041. * @param base PXP peripheral base address.
  1042. * @param config Pointer to the configuration.
  1043. */
  1044. void PXP_SetCsc2Config(PXP_Type *base, const pxp_csc2_config_t *config);
  1045. /*!
  1046. * @brief Enable or disable the CSC2.
  1047. *
  1048. * @param base PXP peripheral base address.
  1049. * @param enable True to enable, false to disable.
  1050. */
  1051. static inline void PXP_EnableCsc2(PXP_Type *base, bool enable)
  1052. {
  1053. if (enable)
  1054. {
  1055. base->CSC2_CTRL &= ~PXP_CSC2_CTRL_BYPASS_MASK;
  1056. }
  1057. else
  1058. {
  1059. base->CSC2_CTRL |= PXP_CSC2_CTRL_BYPASS_MASK;
  1060. }
  1061. }
  1062. #endif /* FSL_FEATURE_PXP_HAS_NO_CSC2 */
  1063. /*!
  1064. * @brief Set the CSC1 mode.
  1065. *
  1066. * The CSC1 module receives scaled YUV/YCbCr444 pixels from the scale engine and
  1067. * converts the pixels to the RGB888 color space. It could only be used by process
  1068. * surface.
  1069. *
  1070. * @param base PXP peripheral base address.
  1071. * @param mode The conversion mode.
  1072. */
  1073. void PXP_SetCsc1Mode(PXP_Type *base, pxp_csc1_mode_t mode);
  1074. /*!
  1075. * @brief Enable or disable the CSC1.
  1076. *
  1077. * @param base PXP peripheral base address.
  1078. * @param enable True to enable, false to disable.
  1079. */
  1080. static inline void PXP_EnableCsc1(PXP_Type *base, bool enable)
  1081. {
  1082. if (enable)
  1083. {
  1084. base->CSC1_COEF0 &= ~PXP_CSC1_COEF0_BYPASS_MASK;
  1085. }
  1086. else
  1087. {
  1088. base->CSC1_COEF0 |= PXP_CSC1_COEF0_BYPASS_MASK;
  1089. }
  1090. }
  1091. /* @} */
  1092. #if !(defined(FSL_FEATURE_PXP_HAS_NO_LUT) && FSL_FEATURE_PXP_HAS_NO_LUT)
  1093. /*!
  1094. * @name LUT operations
  1095. * @{
  1096. */
  1097. /*!
  1098. * @brief Set the LUT configuration.
  1099. *
  1100. * The lookup table (LUT) is used to modify pixels in a manner that is not linear
  1101. * and that cannot be achieved by the color space conversion modules. To setup
  1102. * the LUT, the complete workflow is:
  1103. * 1. Use @ref PXP_SetLutConfig to set the configuration, such as the lookup mode.
  1104. * 2. Use @ref PXP_LoadLutTable to load the lookup table to PXP.
  1105. * 3. Use @ref PXP_EnableLut to enable the function.
  1106. *
  1107. * @param base PXP peripheral base address.
  1108. * @param config Pointer to the configuration.
  1109. */
  1110. void PXP_SetLutConfig(PXP_Type *base, const pxp_lut_config_t *config);
  1111. /*!
  1112. * @brief Set the look up table to PXP.
  1113. *
  1114. * If lookup mode is DIRECT mode, this function loads @p bytesNum of values
  1115. * from the address @p memAddr into PXP LUT address @p lutStartAddr. So this
  1116. * function allows only update part of the PXP LUT.
  1117. *
  1118. * If lookup mode is CACHE mode, this function sets the new address to @p memAddr
  1119. * and invalid the PXP LUT cache.
  1120. *
  1121. * @param base PXP peripheral base address.
  1122. * @param lookupMode Which lookup mode is used. Note that this parameter is only
  1123. * used to distinguish DIRECT mode and CACHE mode, it does not change the register
  1124. * value PXP_LUT_CTRL[LOOKUP_MODE]. To change that value, use function @ref PXP_SetLutConfig.
  1125. * @param bytesNum How many bytes to set. This value must be divisable by 8.
  1126. * @param memAddr Address of look up table to set.
  1127. * @param lutStartAddr The LUT value will be loaded to LUT from index lutAddr. It should
  1128. * be 8 bytes aligned.
  1129. *
  1130. * @retval kStatus_Success Load successfully.
  1131. * @retval kStatus_InvalidArgument Failed because of invalid argument.
  1132. */
  1133. status_t PXP_LoadLutTable(
  1134. PXP_Type *base, pxp_lut_lookup_mode_t lookupMode, uint32_t bytesNum, uint32_t memAddr, uint16_t lutStartAddr);
  1135. /*!
  1136. * @brief Enable or disable the LUT.
  1137. *
  1138. * @param base PXP peripheral base address.
  1139. * @param enable True to enable, false to disable.
  1140. */
  1141. static inline void PXP_EnableLut(PXP_Type *base, bool enable)
  1142. {
  1143. if (enable)
  1144. {
  1145. base->LUT_CTRL &= ~PXP_LUT_CTRL_BYPASS_MASK;
  1146. }
  1147. else
  1148. {
  1149. base->LUT_CTRL |= PXP_LUT_CTRL_BYPASS_MASK;
  1150. }
  1151. }
  1152. /*!
  1153. * @brief Select the 8kB LUT bank in DIRECT_RGB444 mode.
  1154. *
  1155. * @param base PXP peripheral base address.
  1156. * @param bank The bank to select.
  1157. */
  1158. static inline void PXP_Select8kLutBank(PXP_Type *base, pxp_lut_8k_bank_t bank)
  1159. {
  1160. base->LUT_CTRL = (base->LUT_CTRL & ~PXP_LUT_CTRL_SEL_8KB_MASK) | PXP_LUT_CTRL_SEL_8KB(bank);
  1161. }
  1162. /* @} */
  1163. #endif /* FSL_FEATURE_PXP_HAS_NO_LUT */
  1164. #if (defined(FSL_FEATURE_PXP_HAS_DITHER) && FSL_FEATURE_PXP_HAS_DITHER)
  1165. /*!
  1166. * @name Dither
  1167. * @{
  1168. */
  1169. /*!
  1170. * @brief Write data to the PXP internal memory.
  1171. *
  1172. * @param base PXP peripheral base address.
  1173. * @param ram Which internal memory to write.
  1174. * @param bytesNum How many bytes to write.
  1175. * @param data Pointer to the data to write.
  1176. * @param memStartAddr The start address in the internal memory to write the data.
  1177. */
  1178. void PXP_SetInternalRamData(PXP_Type *base, pxp_ram_t ram, uint32_t bytesNum, uint8_t *data, uint16_t memStartAddr);
  1179. /*!
  1180. * @brief Set the dither final LUT data.
  1181. *
  1182. * The dither final LUT is only applicble to dither engine 0. It takes the bits[7:4]
  1183. * of the output pixel and looks up and 8 bit value from the 16 value LUT to generate
  1184. * the final output pixel to the next process module.
  1185. *
  1186. * @param base PXP peripheral base address.
  1187. * @param data Pointer to the LUT data to set.
  1188. */
  1189. void PXP_SetDitherFinalLutData(PXP_Type *base, const pxp_dither_final_lut_data_t *data);
  1190. /*!
  1191. * @brief Set the configuration for the dither block.
  1192. *
  1193. * If the pre-dither LUT, post-dither LUT or ordered dither is used, please call
  1194. * @ref PXP_SetInternalRamData to set the LUT data to internal memory.
  1195. *
  1196. * If the final LUT is used, please call @ref PXP_SetDitherFinalLutData to set
  1197. * the LUT data.
  1198. *
  1199. * @param base PXP peripheral base address.
  1200. * @param config Pointer to the configuration.
  1201. *
  1202. * @note When using ordered dithering, please set the PXP process block size same
  1203. * with the ordered dithering matrix size using function @ref PXP_SetProcessBlockSize.
  1204. */
  1205. static inline void PXP_SetDitherConfig(PXP_Type *base, const pxp_dither_config_t *config)
  1206. {
  1207. base->DITHER_CTRL = *((const uint32_t *)config) & 0x00FFFFFFU;
  1208. }
  1209. /*!
  1210. * @brief Enable or disable dither engine in the PXP process path.
  1211. *
  1212. * After the initialize function @ref PXP_Init, the dither engine is disabled and not
  1213. * use in the PXP processing path. This function enables the dither engine and
  1214. * routes the dither engine output to the output buffer. When the dither engine
  1215. * is enabled using this function, @ref PXP_SetDitherConfig must be called to
  1216. * configure dither engine correctly, otherwise there is not output to the output
  1217. * buffer.
  1218. *
  1219. * @param base PXP peripheral base address.
  1220. * @param enable Pass in true to enable, false to disable.
  1221. */
  1222. void PXP_EnableDither(PXP_Type *base, bool enable);
  1223. /* @} */
  1224. #endif /* FSL_FEATURE_PXP_HAS_DITHER */
  1225. /*!
  1226. * @name Porter Duff
  1227. * @{
  1228. */
  1229. /*!
  1230. * @brief Set the Porter Duff configuration.
  1231. *
  1232. * @param base PXP peripheral base address.
  1233. * @param config Pointer to the configuration.
  1234. */
  1235. void PXP_SetPorterDuffConfig(PXP_Type *base, const pxp_porter_duff_config_t *config);
  1236. /*!
  1237. * @brief Get the Porter Duff configuration by blend mode.
  1238. *
  1239. * The FactorMode are selected based on blend mode, the AlphaMode are set to
  1240. * @ref kPXP_PorterDuffAlphaStraight, the ColorMode are set to
  1241. * @ref kPXP_PorterDuffColorWithAlpha, the GlobalAlphaMode are set to
  1242. * @ref kPXP_PorterDuffLocalAlpha. These values could be modified after calling
  1243. * this function.
  1244. *
  1245. * @param mode The blend mode.
  1246. * @param config Pointer to the configuration.
  1247. * @retval kStatus_Success Successfully get the configuratoin.
  1248. * @retval kStatus_InvalidArgument The blend mode not supported.
  1249. */
  1250. status_t PXP_GetPorterDuffConfig(pxp_porter_duff_blend_mode_t mode, pxp_porter_duff_config_t *config);
  1251. /* @} */
  1252. /*!
  1253. * @name Buffer copy
  1254. * @{
  1255. */
  1256. /*!
  1257. * @brief Copy picture from one buffer to another buffer.
  1258. *
  1259. * This function copies a rectangle from one buffer to another buffer.
  1260. *
  1261. * @verbatim
  1262. Source buffer:
  1263. srcPicBaseAddr
  1264. +-----------------------------------------------------------+
  1265. | |
  1266. | (srcOffsetX, srcOffsetY) |
  1267. | +-------------------+ |
  1268. | | | |
  1269. | | | |
  1270. | | | height |
  1271. | | | |
  1272. | | | |
  1273. | +-------------------+ |
  1274. | width |
  1275. | |
  1276. | srcPicthBytes |
  1277. +-----------------------------------------------------------+
  1278. Destination buffer:
  1279. destPicBaseAddr
  1280. +-------------------------------------------+
  1281. | |
  1282. | |
  1283. | |
  1284. | (destOffsetX, destOffsetY) |
  1285. | +-------------------+ |
  1286. | | | |
  1287. | | | |
  1288. | | | height |
  1289. | | | |
  1290. | | | |
  1291. | +-------------------+ |
  1292. | width |
  1293. | |
  1294. | |
  1295. | |
  1296. | destPicthBytes |
  1297. +-------------------------------------------+
  1298. @endverbatim
  1299. *
  1300. * @note This function resets the old PXP settings, which means the settings
  1301. * like rotate, flip, will be reseted to disabled status.
  1302. *
  1303. * @param base PXP peripheral base address.
  1304. * @param config Pointer to the picture copy configuration structure.
  1305. * @retval kStatus_Success Successfully started the copy process.
  1306. * @retval kStatus_InvalidArgument Invalid argument.
  1307. */
  1308. status_t PXP_StartPictureCopy(PXP_Type *base, const pxp_pic_copy_config_t *config);
  1309. /*!
  1310. * @brief Copy continous memory.
  1311. *
  1312. * @note The copy size should be 512 byte aligned.
  1313. * @note This function resets the old PXP settings, which means the settings
  1314. * like rotate, flip, will be reseted to disabled status.
  1315. *
  1316. * @param base PXP peripheral base address.
  1317. * @param srcAddr Source memory address.
  1318. * @param destAddr Destination memory address.
  1319. * @param size How many bytes to copy, should be 512 byte aligned.
  1320. * @retval kStatus_Success Successfully started the copy process.
  1321. * @retval kStatus_InvalidArgument Invalid argument.
  1322. */
  1323. status_t PXP_StartMemCopy(PXP_Type *base, uint32_t srcAddr, uint32_t destAddr, uint32_t size);
  1324. /* @} */
  1325. #if defined(__cplusplus)
  1326. }
  1327. #endif
  1328. /*! @}*/
  1329. #endif /* _FSL_PXP_H_ */