fsl_elcdif.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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_ELCDIF_H_
  35. #define _FSL_ELCDIF_H_
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup elcdif
  39. * @{
  40. */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /*! @name Driver version */
  45. /*@{*/
  46. /*! @brief eLCDIF driver version */
  47. #define FSL_ELCDIF_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
  48. /*@}*/
  49. /* All IRQ flags in CTRL1 register. */
  50. #define ELCDIF_CTRL1_IRQ_MASK \
  51. (LCDIF_CTRL1_BM_ERROR_IRQ_MASK | LCDIF_CTRL1_OVERFLOW_IRQ_MASK | LCDIF_CTRL1_UNDERFLOW_IRQ_MASK | \
  52. LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_MASK | LCDIF_CTRL1_VSYNC_EDGE_IRQ_MASK)
  53. /* All IRQ enable control bits in CTRL1 register. */
  54. #define ELCDIF_CTRL1_IRQ_EN_MASK \
  55. (LCDIF_CTRL1_BM_ERROR_IRQ_EN_MASK | LCDIF_CTRL1_OVERFLOW_IRQ_EN_MASK | LCDIF_CTRL1_UNDERFLOW_IRQ_EN_MASK | \
  56. LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_EN_MASK | LCDIF_CTRL1_VSYNC_EDGE_IRQ_EN_MASK)
  57. /* All IRQ flags in AS_CTRL register. */
  58. #if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK)
  59. #define ELCDIF_AS_CTRL_IRQ_MASK (LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK)
  60. #else
  61. #define ELCDIF_AS_CTRL_IRQ_MASK 0U
  62. #endif
  63. /* All IRQ enable control bits in AS_CTRL register. */
  64. #if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK)
  65. #define ELCDIF_AS_CTRL_IRQ_EN_MASK (LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK)
  66. #else
  67. #define ELCDIF_AS_CTRL_IRQ_EN_MASK 0U
  68. #endif
  69. #if ((ELCDIF_CTRL1_IRQ_MASK & ELCDIF_AS_CTRL_IRQ_MASK) || (ELCDIF_AS_CTRL_IRQ_MASK & ELCDIF_AS_CTRL_IRQ_EN_MASK))
  70. #error Interrupt bits overlap, need to update the interrupt functions.
  71. #endif
  72. /* LUT memory entery number. */
  73. #define ELCDIF_LUT_ENTRY_NUM 256
  74. /*!
  75. * @brief eLCDIF signal polarity flags
  76. */
  77. enum _elcdif_polarity_flags
  78. {
  79. kELCDIF_VsyncActiveLow = 0U, /*!< VSYNC active low. */
  80. kELCDIF_VsyncActiveHigh = LCDIF_VDCTRL0_VSYNC_POL_MASK, /*!< VSYNC active high. */
  81. kELCDIF_HsyncActiveLow = 0U, /*!< HSYNC active low. */
  82. kELCDIF_HsyncActiveHigh = LCDIF_VDCTRL0_HSYNC_POL_MASK, /*!< HSYNC active high. */
  83. kELCDIF_DataEnableActiveLow = 0U, /*!< Data enable line active low. */
  84. kELCDIF_DataEnableActiveHigh = LCDIF_VDCTRL0_ENABLE_POL_MASK, /*!< Data enable line active high. */
  85. kELCDIF_DriveDataOnFallingClkEdge = 0U, /*!< Drive data on falling clock edge, capture data
  86. on rising clock edge. */
  87. kELCDIF_DriveDataOnRisingClkEdge = LCDIF_VDCTRL0_DOTCLK_POL_MASK, /*!< Drive data on falling
  88. clock edge, capture data
  89. on rising clock edge. */
  90. };
  91. /*!
  92. * @brief The eLCDIF interrupts to enable.
  93. */
  94. enum _elcdif_interrupt_enable
  95. {
  96. kELCDIF_BusMasterErrorInterruptEnable = LCDIF_CTRL1_BM_ERROR_IRQ_EN_MASK, /*!< Bus master error interrupt. */
  97. kELCDIF_TxFifoOverflowInterruptEnable = LCDIF_CTRL1_OVERFLOW_IRQ_EN_MASK, /*!< TXFIFO overflow interrupt. */
  98. kELCDIF_TxFifoUnderflowInterruptEnable = LCDIF_CTRL1_UNDERFLOW_IRQ_EN_MASK, /*!< TXFIFO underflow interrupt. */
  99. kELCDIF_CurFrameDoneInterruptEnable =
  100. LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_EN_MASK, /*!< Interrupt when hardware enters vertical blanking state. */
  101. kELCDIF_VsyncEdgeInterruptEnable =
  102. LCDIF_CTRL1_VSYNC_EDGE_IRQ_EN_MASK, /*!< Interrupt when hardware encounters VSYNC edge. */
  103. #if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK)
  104. kELCDIF_SciSyncOnInterruptEnable =
  105. LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK, /*!< Interrupt when eLCDIF lock with CSI input. */
  106. #endif
  107. };
  108. /*!
  109. * @brief The eLCDIF interrupt status flags.
  110. */
  111. enum _elcdif_interrupt_flags
  112. {
  113. kELCDIF_BusMasterError = LCDIF_CTRL1_BM_ERROR_IRQ_MASK, /*!< Bus master error interrupt. */
  114. kELCDIF_TxFifoOverflow = LCDIF_CTRL1_OVERFLOW_IRQ_MASK, /*!< TXFIFO overflow interrupt. */
  115. kELCDIF_TxFifoUnderflow = LCDIF_CTRL1_UNDERFLOW_IRQ_MASK, /*!< TXFIFO underflow interrupt. */
  116. kELCDIF_CurFrameDone =
  117. LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_MASK, /*!< Interrupt when hardware enters vertical blanking state. */
  118. kELCDIF_VsyncEdge = LCDIF_CTRL1_VSYNC_EDGE_IRQ_MASK, /*!< Interrupt when hardware encounters VSYNC edge. */
  119. #if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK)
  120. kELCDIF_SciSyncOn = LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK, /*!< Interrupt when eLCDIF lock with CSI input. */
  121. #endif
  122. };
  123. /*!
  124. * @brief eLCDIF status flags
  125. */
  126. enum _elcdif_status_flags
  127. {
  128. kELCDIF_LFifoFull = LCDIF_STAT_LFIFO_FULL_MASK, /*!< LFIFO full. */
  129. kELCDIF_LFifoEmpty = LCDIF_STAT_LFIFO_EMPTY_MASK, /*!< LFIFO empty. */
  130. kELCDIF_TxFifoFull = LCDIF_STAT_TXFIFO_FULL_MASK, /*!< TXFIFO full. */
  131. kELCDIF_TxFifoEmpty = LCDIF_STAT_TXFIFO_EMPTY_MASK, /*!< TXFIFO empty. */
  132. #if defined(LCDIF_STAT_BUSY_MASK)
  133. kELCDIF_LcdControllerBusy = LCDIF_STAT_BUSY_MASK, /*!< The external LCD controller busy signal. */
  134. #endif
  135. #if defined(LCDIF_STAT_DVI_CURRENT_FIELD_MASK)
  136. kELCDIF_CurDviField2 = LCDIF_STAT_DVI_CURRENT_FIELD_MASK, /*!< Current DVI filed, if set, then current filed is 2,
  137. otherwise current filed is 1. */
  138. #endif
  139. };
  140. /*!
  141. * @brief The pixel format.
  142. *
  143. * This enumerator should be defined together with the array s_pixelFormatReg.
  144. * To support new pixel format, enhance this enumerator and s_pixelFormatReg.
  145. */
  146. typedef enum _elcdif_pixel_format
  147. {
  148. kELCDIF_PixelFormatRAW8 = 0, /*!< RAW 8 bit, four data use 32 bits. */
  149. kELCDIF_PixelFormatRGB565 = 1, /*!< RGB565, two pixel use 32 bits. */
  150. kELCDIF_PixelFormatRGB666 = 2, /*!< RGB666 unpacked, one pixel uses 32 bits, high byte unused,
  151. upper 2 bits of other bytes unused. */
  152. kELCDIF_PixelFormatXRGB8888 = 3, /*!< XRGB8888 unpacked, one pixel uses 32 bits, high byte unused. */
  153. kELCDIF_PixelFormatRGB888 = 4, /*!< RGB888 packed, one pixel uses 24 bits. */
  154. } elcdif_pixel_format_t;
  155. /*! @brief The LCD data bus type. */
  156. typedef enum _elcdif_lcd_data_bus
  157. {
  158. kELCDIF_DataBus8Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(1), /*!< 8-bit data bus. */
  159. kELCDIF_DataBus16Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(0), /*!< 16-bit data bus, support RGB565. */
  160. kELCDIF_DataBus18Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(2), /*!< 18-bit data bus, support RGB666. */
  161. kELCDIF_DataBus24Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(3), /*!< 24-bit data bus, support RGB888. */
  162. } elcdif_lcd_data_bus_t;
  163. /*!
  164. * @brief The register value when using different pixel format.
  165. *
  166. * These register bits control the pixel format:
  167. * - CTRL[DATA_FORMAT_24_BIT]
  168. * - CTRL[DATA_FORMAT_18_BIT]
  169. * - CTRL[DATA_FORMAT_16_BIT]
  170. * - CTRL[WORD_LENGTH]
  171. * - CTRL1[BYTE_PACKING_FORMAT]
  172. */
  173. typedef struct _elcdif_pixel_format_reg
  174. {
  175. uint32_t regCtrl; /*!< Value of register CTRL. */
  176. uint32_t regCtrl1; /*!< Value of register CTRL1. */
  177. } elcdif_pixel_format_reg_t;
  178. /*!
  179. * @brief eLCDIF configure structure for RGB mode (DOTCLK mode).
  180. */
  181. typedef struct _elcdif_rgb_mode_config
  182. {
  183. uint16_t panelWidth; /*!< Display panel width, pixels per line. */
  184. uint16_t panelHeight; /*!< Display panel height, how many lines per panel. */
  185. uint8_t hsw; /*!< HSYNC pulse width. */
  186. uint8_t hfp; /*!< Horizontal front porch. */
  187. uint8_t hbp; /*!< Horizontal back porch. */
  188. uint8_t vsw; /*!< VSYNC pulse width. */
  189. uint8_t vfp; /*!< Vrtical front porch. */
  190. uint8_t vbp; /*!< Vertical back porch. */
  191. uint32_t polarityFlags; /*!< OR'ed value of @ref _elcdif_polarity_flags, used to contol the signal polarity. */
  192. uint32_t bufferAddr; /*!< Frame buffer address. */
  193. elcdif_pixel_format_t pixelFormat; /*!< Pixel format. */
  194. elcdif_lcd_data_bus_t dataBus; /*!< LCD data bus. */
  195. } elcdif_rgb_mode_config_t;
  196. /*!
  197. * @brief eLCDIF alpha surface pixel format.
  198. */
  199. typedef enum _elcdif_as_pixel_format
  200. {
  201. kELCDIF_AsPixelFormatARGB8888 = 0x0, /*!< 32-bit pixels with alpha. */
  202. kELCDIF_AsPixelFormatRGB888 = 0x4, /*!< 32-bit pixels without alpha (unpacked 24-bit format) */
  203. kELCDIF_AsPixelFormatARGB1555 = 0x8, /*!< 16-bit pixels with alpha. */
  204. kELCDIF_AsPixelFormatARGB4444 = 0x9, /*!< 16-bit pixels with alpha. */
  205. kELCDIF_AsPixelFormatRGB555 = 0xC, /*!< 16-bit pixels without alpha. */
  206. kELCDIF_AsPixelFormatRGB444 = 0xD, /*!< 16-bit pixels without alpha. */
  207. kELCDIF_AsPixelFormatRGB565 = 0xE, /*!< 16-bit pixels without alpha. */
  208. } elcdif_as_pixel_format_t;
  209. /*!
  210. * @brief eLCDIF alpha surface buffer configuration.
  211. */
  212. typedef struct _elcdif_as_buffer_config
  213. {
  214. uint32_t bufferAddr; /*!< Buffer address. */
  215. elcdif_as_pixel_format_t pixelFormat; /*!< Pixel format. */
  216. } elcdif_as_buffer_config_t;
  217. /*!
  218. * @brief eLCDIF alpha mode during blending.
  219. */
  220. typedef enum _elcdif_alpha_mode
  221. {
  222. kELCDIF_AlphaEmbedded, /*!< The alpha surface pixel alpha value will be used for blend. */
  223. kELCDIF_AlphaOverride, /*!< The user defined alpha value will be used for blend directly. */
  224. kELCDIF_AlphaMultiply, /*!< The alpha surface pixel alpha value scaled the user defined
  225. alpha value will be used for blend, for example, pixel alpha set
  226. set to 200, user defined alpha set to 100, then the reault alpha
  227. is 200 * 100 / 255. */
  228. kELCDIF_AlphaRop /*!< Raster operation. */
  229. } elcdif_alpha_mode_t;
  230. /*!
  231. * @brief eLCDIF ROP mode during blending.
  232. *
  233. * Explanation:
  234. * - AS: Alpha surface
  235. * - PS: Process surface
  236. * - nAS: Alpha surface NOT value
  237. * - nPS: Process surface NOT value
  238. */
  239. typedef enum _elcdif_rop_mode
  240. {
  241. kELCDIF_RopMaskAs = 0x0, /*!< AS AND PS. */
  242. kELCDIF_RopMaskNotAs = 0x1, /*!< nAS AND PS. */
  243. kELCDIF_RopMaskAsNot = 0x2, /*!< AS AND nPS. */
  244. kELCDIF_RopMergeAs = 0x3, /*!< AS OR PS. */
  245. kELCDIF_RopMergeNotAs = 0x4, /*!< nAS OR PS. */
  246. kELCDIF_RopMergeAsNot = 0x5, /*!< AS OR nPS. */
  247. kELCDIF_RopNotCopyAs = 0x6, /*!< nAS. */
  248. kELCDIF_RopNot = 0x7, /*!< nPS. */
  249. kELCDIF_RopNotMaskAs = 0x8, /*!< AS NAND PS. */
  250. kELCDIF_RopNotMergeAs = 0x9, /*!< AS NOR PS. */
  251. kELCDIF_RopXorAs = 0xA, /*!< AS XOR PS. */
  252. kELCDIF_RopNotXorAs = 0xB /*!< AS XNOR PS. */
  253. } elcdif_rop_mode_t;
  254. /*!
  255. * @brief eLCDIF alpha surface blending configuration.
  256. */
  257. typedef struct _elcdif_as_blend_config
  258. {
  259. uint8_t alpha; /*!< User defined alpha value, only used when @ref alphaMode is @ref kELCDIF_AlphaOverride or @ref
  260. kELCDIF_AlphaRop. */
  261. bool invertAlpha; /*!< Set true to invert the alpha. */
  262. elcdif_alpha_mode_t alphaMode; /*!< Alpha mode. */
  263. elcdif_rop_mode_t ropMode; /*!< ROP mode, only valid when @ref alphaMode is @ref kELCDIF_AlphaRop. */
  264. } elcdif_as_blend_config_t;
  265. /*!
  266. * @brief eLCDIF LUT
  267. *
  268. * The Lookup Table (LUT) is used to expand the 8 bits pixel to 24 bits pixel
  269. * before output to external displayer.
  270. *
  271. * There are two 256x24 bits LUT memory in LCDIF, the LSB of frame buffer address
  272. * determins which memory to use.
  273. */
  274. typedef enum _elcdif_lut
  275. {
  276. kELCDIF_Lut0 = 0, /*!< LUT 0. */
  277. kELCDIF_Lut1, /*!< LUT 1. */
  278. } elcdif_lut_t;
  279. /*******************************************************************************
  280. * APIs
  281. ******************************************************************************/
  282. #if defined(__cplusplus)
  283. extern "C" {
  284. #endif /* __cplusplus */
  285. /*!
  286. * @name eLCDIF initialization and de-initialization
  287. * @{
  288. */
  289. /*!
  290. * @brief Initializes the eLCDIF to work in RGB mode (DOTCLK mode).
  291. *
  292. * This function ungates the eLCDIF clock and configures the eLCDIF peripheral according
  293. * to the configuration structure.
  294. *
  295. * @param base eLCDIF peripheral base address.
  296. * @param config Pointer to the configuration structure.
  297. */
  298. void ELCDIF_RgbModeInit(LCDIF_Type *base, const elcdif_rgb_mode_config_t *config);
  299. /*!
  300. * @brief Gets the eLCDIF default configuration structure for RGB (DOTCLK) mode.
  301. *
  302. * This function sets the configuration structure to default values.
  303. * The default configuration is set to the following values.
  304. * @code
  305. config->panelWidth = 480U;
  306. config->panelHeight = 272U;
  307. config->hsw = 41;
  308. config->hfp = 4;
  309. config->hbp = 8;
  310. config->vsw = 10;
  311. config->vfp = 4;
  312. config->vbp = 2;
  313. config->polarityFlags = kELCDIF_VsyncActiveLow |
  314. kELCDIF_HsyncActiveLow |
  315. kELCDIF_DataEnableActiveLow |
  316. kELCDIF_DriveDataOnFallingClkEdge;
  317. config->bufferAddr = 0U;
  318. config->pixelFormat = kELCDIF_PixelFormatRGB888;
  319. config->dataBus = kELCDIF_DataBus24Bit;
  320. @code
  321. *
  322. * @param config Pointer to the eLCDIF configuration structure.
  323. */
  324. void ELCDIF_RgbModeGetDefaultConfig(elcdif_rgb_mode_config_t *config);
  325. /*!
  326. * @brief Deinitializes the eLCDIF peripheral.
  327. *
  328. * @param base eLCDIF peripheral base address.
  329. */
  330. void ELCDIF_Deinit(LCDIF_Type *base);
  331. /* @} */
  332. /*!
  333. * @name Module operation
  334. * @{
  335. */
  336. /*!
  337. * @brief Start to display in RGB (DOTCLK) mode.
  338. *
  339. * @param base eLCDIF peripheral base address.
  340. */
  341. static inline void ELCDIF_RgbModeStart(LCDIF_Type *base)
  342. {
  343. base->CTRL_SET = LCDIF_CTRL_RUN_MASK | LCDIF_CTRL_DOTCLK_MODE_MASK;
  344. }
  345. /*!
  346. * @brief Stop display in RGB (DOTCLK) mode and wait until finished.
  347. *
  348. * @param base eLCDIF peripheral base address.
  349. */
  350. void ELCDIF_RgbModeStop(LCDIF_Type *base);
  351. /*!
  352. * @brief Set the next frame buffer address to display.
  353. *
  354. * @param base eLCDIF peripheral base address.
  355. * @param bufferAddr The frame buffer address to set.
  356. */
  357. static inline void ELCDIF_SetNextBufferAddr(LCDIF_Type *base, uint32_t bufferAddr)
  358. {
  359. base->NEXT_BUF = bufferAddr;
  360. }
  361. /*!
  362. * @brief Reset the eLCDIF peripheral.
  363. *
  364. * @param base eLCDIF peripheral base address.
  365. */
  366. void ELCDIF_Reset(LCDIF_Type *base);
  367. #if !(defined(FSL_FEATURE_LCDIF_HAS_NO_RESET_PIN) && FSL_FEATURE_LCDIF_HAS_NO_RESET_PIN)
  368. /*!
  369. * @brief Pull up or down the reset pin for the externel LCD controller.
  370. *
  371. * @param base eLCDIF peripheral base address.
  372. * @param pullUp True to pull up reset pin, false to pull down.
  373. */
  374. static inline void ELCDIF_PullUpResetPin(LCDIF_Type *base, bool pullUp)
  375. {
  376. if (pullUp)
  377. {
  378. base->CTRL1_SET = LCDIF_CTRL1_RESET_MASK;
  379. }
  380. else
  381. {
  382. base->CTRL1_CLR = LCDIF_CTRL1_RESET_MASK;
  383. }
  384. }
  385. #endif
  386. /*!
  387. * @brief Enable or disable the hand shake with PXP.
  388. *
  389. * @param base eLCDIF peripheral base address.
  390. * @param enable True to enable, false to disable.
  391. */
  392. static inline void ELCDIF_EnablePxpHandShake(LCDIF_Type *base, bool enable)
  393. {
  394. if (enable)
  395. {
  396. base->CTRL_SET = LCDIF_CTRL_ENABLE_PXP_HANDSHAKE_MASK;
  397. }
  398. else
  399. {
  400. base->CTRL_CLR = LCDIF_CTRL_ENABLE_PXP_HANDSHAKE_MASK;
  401. }
  402. }
  403. /* @} */
  404. /*!
  405. * @name Status
  406. * @{
  407. */
  408. /*!
  409. * @brief Get the CRC value of the frame sent out.
  410. *
  411. * When a frame is sent complete (the interrupt @ref kELCDIF_CurFrameDone assert), this function
  412. * can be used to get the CRC value of the frame sent.
  413. *
  414. * @param base eLCDIF peripheral base address.
  415. * @return The CRC value.
  416. *
  417. * @note The CRC value is dependent on the LCD_DATABUS_WIDTH.
  418. */
  419. static inline uint32_t ELCDIF_GetCrcValue(LCDIF_Type *base)
  420. {
  421. return base->CRC_STAT;
  422. }
  423. /*!
  424. * @brief Get the bus master error virtual address.
  425. *
  426. * When bus master error occurs (the interrupt kELCDIF_BusMasterError assert), this function
  427. * can get the virtual address at which the AXI master received an error
  428. * response from the slave.
  429. *
  430. * @param base eLCDIF peripheral base address.
  431. * @return The error virtual address.
  432. */
  433. static inline uint32_t ELCDIF_GetBusMasterErrorAddr(LCDIF_Type *base)
  434. {
  435. return base->BM_ERROR_STAT;
  436. }
  437. /*!
  438. * @brief Get the eLCDIF status.
  439. *
  440. * The status flags are returned as a mask value, application could check the
  441. * corresponding bit. Example:
  442. *
  443. * @code
  444. uint32_t statusFlags;
  445. statusFlags = ELCDIF_GetStatus(LCDIF);
  446. // If LFIFO is full.
  447. if (kELCDIF_LFifoFull & statusFlags)
  448. {
  449. // ...;
  450. }
  451. // If TXFIFO is empty.
  452. if (kELCDIF_TxFifoEmpty & statusFlags)
  453. {
  454. // ...;
  455. }
  456. @endcode
  457. *
  458. * @param base eLCDIF peripheral base address.
  459. * @return The mask value of status flags, it is OR'ed value of @ref _elcdif_status_flags.
  460. */
  461. static inline uint32_t ELCDIF_GetStatus(LCDIF_Type *base)
  462. {
  463. return base->STAT & (LCDIF_STAT_LFIFO_FULL_MASK | LCDIF_STAT_LFIFO_EMPTY_MASK | LCDIF_STAT_TXFIFO_FULL_MASK |
  464. LCDIF_STAT_TXFIFO_EMPTY_MASK
  465. #if defined(LCDIF_STAT_BUSY_MASK)
  466. | LCDIF_STAT_BUSY_MASK
  467. #endif
  468. #if defined(LCDIF_STAT_DVI_CURRENT_FIELD_MASK)
  469. | LCDIF_STAT_DVI_CURRENT_FIELD_MASK
  470. #endif
  471. );
  472. }
  473. /*!
  474. * @brief Get current count in Latency buffer (LFIFO).
  475. *
  476. * @param base eLCDIF peripheral base address.
  477. * @return The LFIFO current count
  478. */
  479. static inline uint32_t ELCDIF_GetLFifoCount(LCDIF_Type *base)
  480. {
  481. return (base->STAT & LCDIF_STAT_LFIFO_COUNT_MASK) >> LCDIF_STAT_LFIFO_COUNT_SHIFT;
  482. }
  483. /* @} */
  484. /*!
  485. * @name Interrupts
  486. * @{
  487. */
  488. /*!
  489. * @brief Enables eLCDIF interrupt requests.
  490. *
  491. * @param base eLCDIF peripheral base address.
  492. * @param mask interrupt source, OR'ed value of _elcdif_interrupt_enable.
  493. */
  494. static inline void ELCDIF_EnableInterrupts(LCDIF_Type *base, uint32_t mask)
  495. {
  496. base->CTRL1_SET = (mask & ELCDIF_CTRL1_IRQ_EN_MASK);
  497. #if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
  498. base->AS_CTRL |= (mask & ELCDIF_AS_CTRL_IRQ_EN_MASK);
  499. #endif
  500. }
  501. /*!
  502. * @brief Disables eLCDIF interrupt requests.
  503. *
  504. * @param base eLCDIF peripheral base address.
  505. * @param mask interrupt source, OR'ed value of _elcdif_interrupt_enable.
  506. */
  507. static inline void ELCDIF_DisableInterrupts(LCDIF_Type *base, uint32_t mask)
  508. {
  509. base->CTRL1_CLR = (mask & ELCDIF_CTRL1_IRQ_EN_MASK);
  510. #if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
  511. base->AS_CTRL &= ~(mask & ELCDIF_AS_CTRL_IRQ_EN_MASK);
  512. #endif
  513. }
  514. /*!
  515. * @brief Get eLCDIF interrupt peding status.
  516. *
  517. * @param base eLCDIF peripheral base address.
  518. * @return Interrupt pending status, OR'ed value of _elcdif_interrupt_flags.
  519. */
  520. static inline uint32_t ELCDIF_GetInterruptStatus(LCDIF_Type *base)
  521. {
  522. uint32_t flags;
  523. flags = (base->CTRL1 & ELCDIF_CTRL1_IRQ_MASK);
  524. #if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
  525. flags |= (base->AS_CTRL & ELCDIF_AS_CTRL_IRQ_MASK);
  526. #endif
  527. return flags;
  528. }
  529. /*!
  530. * @brief Clear eLCDIF interrupt peding status.
  531. *
  532. * @param base eLCDIF peripheral base address.
  533. * @param mask of the flags to clear, OR'ed value of _elcdif_interrupt_flags.
  534. */
  535. static inline void ELCDIF_ClearInterruptStatus(LCDIF_Type *base, uint32_t mask)
  536. {
  537. base->CTRL1_CLR = (mask & ELCDIF_CTRL1_IRQ_MASK);
  538. #if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
  539. base->AS_CTRL &= ~(mask & ELCDIF_AS_CTRL_IRQ_MASK);
  540. #endif
  541. }
  542. /* @} */
  543. #if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
  544. /*!
  545. * @name Alpha surface
  546. * @{
  547. */
  548. /*!
  549. * @brief Set the configuration for alpha surface buffer.
  550. *
  551. * @param base eLCDIF peripheral base address.
  552. * @param config Pointer to the configuration structure.
  553. */
  554. void ELCDIF_SetAlphaSurfaceBufferConfig(LCDIF_Type *base, const elcdif_as_buffer_config_t *config);
  555. /*!
  556. * @brief Set the alpha surface blending configuration.
  557. *
  558. * @param base eLCDIF peripheral base address.
  559. * @param config Pointer to the configuration structure.
  560. */
  561. void ELCDIF_SetAlphaSurfaceBlendConfig(LCDIF_Type *base, const elcdif_as_blend_config_t *config);
  562. /*!
  563. * @brief Set the next alpha surface buffer address.
  564. *
  565. * @param base eLCDIF peripheral base address.
  566. * @param bufferAddr Alpha surface buffer address.
  567. */
  568. static inline void ELCDIF_SetNextAlphaSurfaceBufferAddr(LCDIF_Type *base, uint32_t bufferAddr)
  569. {
  570. base->AS_NEXT_BUF = bufferAddr;
  571. }
  572. /*!
  573. * @brief Set the overlay color key.
  574. *
  575. * If a pixel in the current overlay image with a color that falls in the range
  576. * from the @p colorKeyLow to @p colorKeyHigh range, it will use the process surface
  577. * pixel value for that location.
  578. *
  579. * @param base eLCDIF peripheral base address.
  580. * @param colorKeyLow Color key low range.
  581. * @param colorKeyHigh Color key high range.
  582. *
  583. * @note Colorkey operations are higher priority than alpha or ROP operations
  584. */
  585. static inline void ELCDIF_SetOverlayColorKey(LCDIF_Type *base, uint32_t colorKeyLow, uint32_t colorKeyHigh)
  586. {
  587. base->AS_CLRKEYLOW = colorKeyLow;
  588. base->AS_CLRKEYHIGH = colorKeyHigh;
  589. }
  590. /*!
  591. * @brief Enable or disable the color key.
  592. *
  593. * @param base eLCDIF peripheral base address.
  594. * @param enable True to enable, false to disable.
  595. */
  596. static inline void ELCDIF_EnableOverlayColorKey(LCDIF_Type *base, bool enable)
  597. {
  598. if (enable)
  599. {
  600. base->AS_CTRL |= LCDIF_AS_CTRL_ENABLE_COLORKEY_MASK;
  601. }
  602. else
  603. {
  604. base->AS_CTRL &= ~LCDIF_AS_CTRL_ENABLE_COLORKEY_MASK;
  605. }
  606. }
  607. /*!
  608. * @brief Enable or disable the alpha surface.
  609. *
  610. * @param base eLCDIF peripheral base address.
  611. * @param enable True to enable, false to disable.
  612. */
  613. static inline void ELCDIF_EnableAlphaSurface(LCDIF_Type *base, bool enable)
  614. {
  615. if (enable)
  616. {
  617. base->AS_CTRL |= LCDIF_AS_CTRL_AS_ENABLE_MASK;
  618. }
  619. else
  620. {
  621. base->AS_CTRL &= ~LCDIF_AS_CTRL_AS_ENABLE_MASK;
  622. }
  623. }
  624. /*!
  625. * @brief Enable or disable the process surface.
  626. *
  627. * Process surface is the normal frame buffer. The process surface content
  628. * is controlled by @ref ELCDIF_SetNextBufferAddr.
  629. *
  630. * @param base eLCDIF peripheral base address.
  631. * @param enable True to enable, false to disable.
  632. */
  633. static inline void ELCDIF_EnableProcessSurface(LCDIF_Type *base, bool enable)
  634. {
  635. if (enable)
  636. {
  637. base->AS_CTRL &= ~LCDIF_AS_CTRL_PS_DISABLE_MASK;
  638. }
  639. else
  640. {
  641. base->AS_CTRL |= LCDIF_AS_CTRL_PS_DISABLE_MASK;
  642. }
  643. }
  644. /* @} */
  645. #endif /* FSL_FEATURE_LCDIF_HAS_NO_AS */
  646. #if (defined(FSL_FEATURE_LCDIF_HAS_LUT) && FSL_FEATURE_LCDIF_HAS_LUT)
  647. /*!
  648. * @name LUT
  649. *
  650. * The Lookup Table (LUT) is used to expand the 8 bits pixel to 24 bits pixel
  651. * before output to external displayer.
  652. *
  653. * There are two 256x24 bits LUT memory in LCDIF, the LSB of frame buffer address
  654. * determins which memory to use.
  655. *
  656. * @{
  657. */
  658. /*!
  659. * @brief Enable or disable the LUT.
  660. *
  661. * @param base eLCDIF peripheral base address.
  662. * @param enable True to enable, false to disable.
  663. */
  664. static inline void ELCDIF_EnableLut(LCDIF_Type *base, bool enable)
  665. {
  666. if (enable)
  667. {
  668. base->LUT_CTRL &= ~LCDIF_LUT_CTRL_LUT_BYPASS_MASK;
  669. }
  670. else
  671. {
  672. base->LUT_CTRL |= LCDIF_LUT_CTRL_LUT_BYPASS_MASK;
  673. }
  674. }
  675. /*!
  676. * @brief Load the LUT value.
  677. *
  678. * This function loads the LUT value to the specific LUT memory, user can
  679. * specify the start entry index.
  680. *
  681. * @param base eLCDIF peripheral base address.
  682. * @param lut Which LUT to load.
  683. * @param startIndex The start index of the LUT entry to update.
  684. * @param lutData The LUT data to load.
  685. * @param count Count of @p lutData.
  686. * @retval kStatus_Success Initialization success.
  687. * @retval kStatus_InvalidArgument Wrong argument.
  688. */
  689. status_t ELCDIF_UpdateLut(
  690. LCDIF_Type *base, elcdif_lut_t lut, uint16_t startIndex, const uint32_t *lutData, uint16_t count);
  691. /* @} */
  692. #endif /* FSL_FEATURE_LCDIF_HAS_LUT */
  693. #if defined(__cplusplus)
  694. }
  695. #endif /* __cplusplus */
  696. /* @} */
  697. #endif /*_FSL_ELCDIF_H_*/