fsl_elcdif.h 25 KB

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