fsl_pxp.h 44 KB

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