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