fsl_elcdif.h 22 KB

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