fsl_pxp.h 43 KB

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