fsl_elcdif.h 24.8 KB
Newer Older
T
tanek liang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
/*
 * Copyright (c) 2017, NXP Semiconductors, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _FSL_ELCDIF_H_
#define _FSL_ELCDIF_H_

#include "fsl_common.h"

/*!
 * @addtogroup elcdif
 * @{
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*! @name Driver version */
/*@{*/
/*! @brief eLCDIF driver version */
#define FSL_ELCDIF_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
/*@}*/

/* All IRQ flags in CTRL1 register. */
#define ELCDIF_CTRL1_IRQ_MASK                                                                         \
    (LCDIF_CTRL1_BM_ERROR_IRQ_MASK | LCDIF_CTRL1_OVERFLOW_IRQ_MASK | LCDIF_CTRL1_UNDERFLOW_IRQ_MASK | \
     LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_MASK | LCDIF_CTRL1_VSYNC_EDGE_IRQ_MASK)

/* All IRQ enable control bits in CTRL1 register. */
#define ELCDIF_CTRL1_IRQ_EN_MASK                                                                               \
    (LCDIF_CTRL1_BM_ERROR_IRQ_EN_MASK | LCDIF_CTRL1_OVERFLOW_IRQ_EN_MASK | LCDIF_CTRL1_UNDERFLOW_IRQ_EN_MASK | \
     LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_EN_MASK | LCDIF_CTRL1_VSYNC_EDGE_IRQ_EN_MASK)

/* All IRQ flags in AS_CTRL register. */
#if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK)
#define ELCDIF_AS_CTRL_IRQ_MASK (LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK)
#else
#define ELCDIF_AS_CTRL_IRQ_MASK 0U
#endif

/* All IRQ enable control bits in AS_CTRL register. */
#if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK)
#define ELCDIF_AS_CTRL_IRQ_EN_MASK (LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK)
#else
#define ELCDIF_AS_CTRL_IRQ_EN_MASK 0U
#endif

#if ((ELCDIF_CTRL1_IRQ_MASK & ELCDIF_AS_CTRL_IRQ_MASK) || (ELCDIF_AS_CTRL_IRQ_MASK & ELCDIF_AS_CTRL_IRQ_EN_MASK))
#error Interrupt bits overlap, need to update the interrupt functions.
#endif

/* LUT memory entery number. */
#define ELCDIF_LUT_ENTRY_NUM 256

/*!
 * @brief eLCDIF signal polarity flags
 */
enum _elcdif_polarity_flags
{
    kELCDIF_VsyncActiveLow = 0U,                                  /*!< VSYNC active low. */
    kELCDIF_VsyncActiveHigh = LCDIF_VDCTRL0_VSYNC_POL_MASK,       /*!< VSYNC active high. */
    kELCDIF_HsyncActiveLow = 0U,                                  /*!< HSYNC active low. */
    kELCDIF_HsyncActiveHigh = LCDIF_VDCTRL0_HSYNC_POL_MASK,       /*!< HSYNC active high. */
    kELCDIF_DataEnableActiveLow = 0U,                             /*!< Data enable line active low. */
    kELCDIF_DataEnableActiveHigh = LCDIF_VDCTRL0_ENABLE_POL_MASK, /*!< Data enable line active high. */
    kELCDIF_DriveDataOnFallingClkEdge = 0U,                       /*!< Drive data on falling clock edge, capture data
                                                                       on rising clock edge. */
    kELCDIF_DriveDataOnRisingClkEdge = LCDIF_VDCTRL0_DOTCLK_POL_MASK, /*!< Drive data on falling
                                                                        clock edge, capture data
                                                                        on rising clock edge. */
};

/*!
 * @brief The eLCDIF interrupts to enable.
 */
enum _elcdif_interrupt_enable
{
    kELCDIF_BusMasterErrorInterruptEnable = LCDIF_CTRL1_BM_ERROR_IRQ_EN_MASK,   /*!< Bus master error interrupt. */
    kELCDIF_TxFifoOverflowInterruptEnable = LCDIF_CTRL1_OVERFLOW_IRQ_EN_MASK,   /*!< TXFIFO overflow interrupt. */
    kELCDIF_TxFifoUnderflowInterruptEnable = LCDIF_CTRL1_UNDERFLOW_IRQ_EN_MASK, /*!< TXFIFO underflow interrupt. */
    kELCDIF_CurFrameDoneInterruptEnable =
        LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_EN_MASK, /*!< Interrupt when hardware enters vertical blanking state. */
    kELCDIF_VsyncEdgeInterruptEnable =
        LCDIF_CTRL1_VSYNC_EDGE_IRQ_EN_MASK, /*!< Interrupt when hardware encounters VSYNC edge. */
#if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK)
    kELCDIF_SciSyncOnInterruptEnable =
        LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_EN_MASK, /*!< Interrupt when eLCDIF lock with CSI input. */
#endif
};

/*!
 * @brief The eLCDIF interrupt status flags.
 */
enum _elcdif_interrupt_flags
{
    kELCDIF_BusMasterError = LCDIF_CTRL1_BM_ERROR_IRQ_MASK,   /*!< Bus master error interrupt. */
    kELCDIF_TxFifoOverflow = LCDIF_CTRL1_OVERFLOW_IRQ_MASK,   /*!< TXFIFO overflow interrupt. */
    kELCDIF_TxFifoUnderflow = LCDIF_CTRL1_UNDERFLOW_IRQ_MASK, /*!< TXFIFO underflow interrupt. */
    kELCDIF_CurFrameDone =
        LCDIF_CTRL1_CUR_FRAME_DONE_IRQ_MASK,             /*!< Interrupt when hardware enters vertical blanking state. */
    kELCDIF_VsyncEdge = LCDIF_CTRL1_VSYNC_EDGE_IRQ_MASK, /*!< Interrupt when hardware encounters VSYNC edge. */
#if defined(LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK)
    kELCDIF_SciSyncOn = LCDIF_AS_CTRL_CSI_SYNC_ON_IRQ_MASK, /*!< Interrupt when eLCDIF lock with CSI input. */
#endif
};

/*!
 * @brief eLCDIF status flags
 */
enum _elcdif_status_flags
{
    kELCDIF_LFifoFull = LCDIF_STAT_LFIFO_FULL_MASK,     /*!< LFIFO full. */
    kELCDIF_LFifoEmpty = LCDIF_STAT_LFIFO_EMPTY_MASK,   /*!< LFIFO empty. */
    kELCDIF_TxFifoFull = LCDIF_STAT_TXFIFO_FULL_MASK,   /*!< TXFIFO full. */
    kELCDIF_TxFifoEmpty = LCDIF_STAT_TXFIFO_EMPTY_MASK, /*!< TXFIFO empty. */
#if defined(LCDIF_STAT_BUSY_MASK)
    kELCDIF_LcdControllerBusy = LCDIF_STAT_BUSY_MASK, /*!< The external LCD controller busy signal. */
#endif
#if defined(LCDIF_STAT_DVI_CURRENT_FIELD_MASK)
    kELCDIF_CurDviField2 = LCDIF_STAT_DVI_CURRENT_FIELD_MASK, /*!< Current DVI filed, if set, then current filed is 2,
                                                               otherwise current filed is 1. */
#endif
};

/*!
 * @brief The pixel format.
 *
 * This enumerator should be defined together with the array s_pixelFormatReg.
 * To support new pixel format, enhance this enumerator and s_pixelFormatReg.
 */
typedef enum _elcdif_pixel_format
{
    kELCDIF_PixelFormatRAW8 = 0,     /*!< RAW 8 bit, four data use 32 bits. */
    kELCDIF_PixelFormatRGB565 = 1,   /*!< RGB565, two pixel use 32 bits. */
    kELCDIF_PixelFormatRGB666 = 2,   /*!< RGB666 unpacked, one pixel uses 32 bits, high byte unused,
                                          upper 2 bits of other bytes unused. */
    kELCDIF_PixelFormatXRGB8888 = 3, /*!< XRGB8888 unpacked, one pixel uses 32 bits, high byte unused. */
    kELCDIF_PixelFormatRGB888 = 4,   /*!< RGB888 packed, one pixel uses 24 bits. */
} elcdif_pixel_format_t;

/*! @brief The LCD data bus type.  */
typedef enum _elcdif_lcd_data_bus
{
    kELCDIF_DataBus8Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(1),  /*!< 8-bit data bus. */
    kELCDIF_DataBus16Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(0), /*!< 16-bit data bus, support RGB565. */
    kELCDIF_DataBus18Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(2), /*!< 18-bit data bus, support RGB666. */
    kELCDIF_DataBus24Bit = LCDIF_CTRL_LCD_DATABUS_WIDTH(3), /*!< 24-bit data bus, support RGB888. */
} elcdif_lcd_data_bus_t;

/*!
 * @brief The register value when using different pixel format.
 *
 * These register bits control the pixel format:
 * - CTRL[DATA_FORMAT_24_BIT]
 * - CTRL[DATA_FORMAT_18_BIT]
 * - CTRL[DATA_FORMAT_16_BIT]
 * - CTRL[WORD_LENGTH]
 * - CTRL1[BYTE_PACKING_FORMAT]
 */
typedef struct _elcdif_pixel_format_reg
{
    uint32_t regCtrl;  /*!< Value of register CTRL. */
    uint32_t regCtrl1; /*!< Value of register CTRL1. */
} elcdif_pixel_format_reg_t;

/*!
 * @brief eLCDIF configure structure for RGB mode (DOTCLK mode).
 */
typedef struct _elcdif_rgb_mode_config
{
    uint16_t panelWidth;    /*!< Display panel width, pixels per line. */
    uint16_t panelHeight;   /*!< Display panel height, how many lines per panel. */
    uint8_t hsw;            /*!< HSYNC pulse width. */
    uint8_t hfp;            /*!< Horizontal front porch. */
    uint8_t hbp;            /*!< Horizontal back porch. */
    uint8_t vsw;            /*!< VSYNC pulse width. */
    uint8_t vfp;            /*!< Vrtical front porch. */
    uint8_t vbp;            /*!< Vertical back porch. */
    uint32_t polarityFlags; /*!< OR'ed value of @ref _elcdif_polarity_flags, used to contol the signal polarity. */
    uint32_t bufferAddr;    /*!< Frame buffer address. */
    elcdif_pixel_format_t pixelFormat; /*!< Pixel format. */
    elcdif_lcd_data_bus_t dataBus;     /*!< LCD data bus. */
} elcdif_rgb_mode_config_t;

/*!
 * @brief eLCDIF alpha surface pixel format.
 */
typedef enum _elcdif_as_pixel_format
{
    kELCDIF_AsPixelFormatARGB8888 = 0x0, /*!< 32-bit pixels with alpha. */
    kELCDIF_AsPixelFormatRGB888 = 0x4,   /*!< 32-bit pixels without alpha (unpacked 24-bit format) */
    kELCDIF_AsPixelFormatARGB1555 = 0x8, /*!< 16-bit pixels with alpha. */
    kELCDIF_AsPixelFormatARGB4444 = 0x9, /*!< 16-bit pixels with alpha. */
    kELCDIF_AsPixelFormatRGB555 = 0xC,   /*!< 16-bit pixels without alpha. */
    kELCDIF_AsPixelFormatRGB444 = 0xD,   /*!< 16-bit pixels without alpha. */
    kELCDIF_AsPixelFormatRGB565 = 0xE,   /*!< 16-bit pixels without alpha. */
} elcdif_as_pixel_format_t;

/*!
 * @brief eLCDIF alpha surface buffer configuration.
 */
typedef struct _elcdif_as_buffer_config
{
    uint32_t bufferAddr;                  /*!< Buffer address. */
    elcdif_as_pixel_format_t pixelFormat; /*!< Pixel format. */
} elcdif_as_buffer_config_t;

/*!
 * @brief eLCDIF alpha mode during blending.
 */
typedef enum _elcdif_alpha_mode
{
    kELCDIF_AlphaEmbedded, /*!< The alpha surface pixel alpha value will be used for blend. */
    kELCDIF_AlphaOverride, /*!< The user defined alpha value will be used for blend directly. */
    kELCDIF_AlphaMultiply, /*!< The alpha surface pixel alpha value scaled the user defined
                             alpha value will be used for blend, for example, pixel alpha set
                             set to 200, user defined alpha set to 100, then the reault alpha
                             is 200 * 100 / 255. */
    kELCDIF_AlphaRop       /*!< Raster operation. */
} elcdif_alpha_mode_t;

/*!
 * @brief eLCDIF ROP mode during blending.
 *
 * Explanation:
 * - AS: Alpha surface
 * - PS: Process surface
 * - nAS: Alpha surface NOT value
 * - nPS: Process surface NOT value
 */
typedef enum _elcdif_rop_mode
{
    kELCDIF_RopMaskAs = 0x0,     /*!< AS AND PS. */
    kELCDIF_RopMaskNotAs = 0x1,  /*!< nAS AND PS. */
    kELCDIF_RopMaskAsNot = 0x2,  /*!< AS AND nPS. */
    kELCDIF_RopMergeAs = 0x3,    /*!< AS OR PS. */
    kELCDIF_RopMergeNotAs = 0x4, /*!< nAS OR PS. */
    kELCDIF_RopMergeAsNot = 0x5, /*!< AS OR nPS. */
    kELCDIF_RopNotCopyAs = 0x6,  /*!< nAS. */
    kELCDIF_RopNot = 0x7,        /*!< nPS. */
    kELCDIF_RopNotMaskAs = 0x8,  /*!< AS NAND PS. */
    kELCDIF_RopNotMergeAs = 0x9, /*!< AS NOR PS. */
    kELCDIF_RopXorAs = 0xA,      /*!< AS XOR PS. */
    kELCDIF_RopNotXorAs = 0xB    /*!< AS XNOR PS. */
} elcdif_rop_mode_t;

/*!
 * @brief eLCDIF alpha surface blending configuration.
 */
typedef struct _elcdif_as_blend_config
{
    uint8_t alpha;    /*!< User defined alpha value, only used when @ref alphaMode is @ref kELCDIF_AlphaOverride or @ref
                         kELCDIF_AlphaRop. */
    bool invertAlpha; /*!< Set true to invert the alpha. */
    elcdif_alpha_mode_t alphaMode; /*!< Alpha mode. */
    elcdif_rop_mode_t ropMode;     /*!< ROP mode, only valid when @ref alphaMode is @ref kELCDIF_AlphaRop. */
} elcdif_as_blend_config_t;

/*!
 * @brief eLCDIF LUT
 *
 * The Lookup Table (LUT) is used to expand the 8 bits pixel to 24 bits pixel
 * before output to external displayer.
 *
 * There are two 256x24 bits LUT memory in LCDIF, the LSB of frame buffer address
 * determins which memory to use.
 */
typedef enum _elcdif_lut
{
    kELCDIF_Lut0 = 0, /*!< LUT 0. */
    kELCDIF_Lut1,     /*!< LUT 1. */
} elcdif_lut_t;

/*******************************************************************************
 * APIs
 ******************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */

/*!
 * @name eLCDIF initialization and de-initialization
 * @{
 */

/*!
 * @brief Initializes the eLCDIF to work in RGB mode (DOTCLK mode).
 *
 * This function ungates the eLCDIF clock and configures the eLCDIF peripheral according
 * to the configuration structure.
 *
 * @param base eLCDIF peripheral base address.
 * @param config Pointer to the configuration structure.
 */
void ELCDIF_RgbModeInit(LCDIF_Type *base, const elcdif_rgb_mode_config_t *config);

/*!
 * @brief Gets the eLCDIF default configuration structure for RGB (DOTCLK) mode.
 *
 * This function sets the configuration structure to default values.
 * The default configuration is set to the following values.
 * @code
    config->panelWidth = 480U;
    config->panelHeight = 272U;
    config->hsw = 41;
    config->hfp = 4;
    config->hbp = 8;
    config->vsw = 10;
    config->vfp = 4;
    config->vbp = 2;
    config->polarityFlags = kELCDIF_VsyncActiveLow |
                            kELCDIF_HsyncActiveLow |
                            kELCDIF_DataEnableActiveLow |
                            kELCDIF_DriveDataOnFallingClkEdge;
    config->bufferAddr = 0U;
    config->pixelFormat = kELCDIF_PixelFormatRGB888;
    config->dataBus = kELCDIF_DataBus24Bit;
    @code
 *
 * @param config Pointer to the eLCDIF configuration structure.
 */
void ELCDIF_RgbModeGetDefaultConfig(elcdif_rgb_mode_config_t *config);

/*!
 * @brief Deinitializes the eLCDIF peripheral.
 *
 * @param base eLCDIF peripheral base address.
 */
void ELCDIF_Deinit(LCDIF_Type *base);

/* @} */

/*!
 * @name Module operation
 * @{
 */

/*!
 * @brief Start to display in RGB (DOTCLK) mode.
 *
 * @param base eLCDIF peripheral base address.
 */
static inline void ELCDIF_RgbModeStart(LCDIF_Type *base)
{
    base->CTRL_SET = LCDIF_CTRL_RUN_MASK | LCDIF_CTRL_DOTCLK_MODE_MASK;
}

/*!
 * @brief Stop display in RGB (DOTCLK) mode and wait until finished.
 *
 * @param base eLCDIF peripheral base address.
 */
void ELCDIF_RgbModeStop(LCDIF_Type *base);

/*!
 * @brief Set the next frame buffer address to display.
 *
 * @param base eLCDIF peripheral base address.
 * @param bufferAddr The frame buffer address to set.
 */
static inline void ELCDIF_SetNextBufferAddr(LCDIF_Type *base, uint32_t bufferAddr)
{
    base->NEXT_BUF = bufferAddr;
}

/*!
 * @brief Reset the eLCDIF peripheral.
 *
 * @param base eLCDIF peripheral base address.
 */
void ELCDIF_Reset(LCDIF_Type *base);

#if !(defined(FSL_FEATURE_LCDIF_HAS_NO_RESET_PIN) && FSL_FEATURE_LCDIF_HAS_NO_RESET_PIN)
/*!
 * @brief Pull up or down the reset pin for the externel LCD controller.
 *
 * @param base eLCDIF peripheral base address.
 * @param pullUp True to pull up reset pin, false to pull down.
 */
static inline void ELCDIF_PullUpResetPin(LCDIF_Type *base, bool pullUp)
{
    if (pullUp)
    {
        base->CTRL1_SET = LCDIF_CTRL1_RESET_MASK;
    }
    else
    {
        base->CTRL1_CLR = LCDIF_CTRL1_RESET_MASK;
    }
}
#endif

/*!
 * @brief Enable or disable the hand shake with PXP.
 *
 * @param base eLCDIF peripheral base address.
 * @param enable True to enable, false to disable.
 */
static inline void ELCDIF_EnablePxpHandShake(LCDIF_Type *base, bool enable)
{
    if (enable)
    {
        base->CTRL_SET = LCDIF_CTRL_ENABLE_PXP_HANDSHAKE_MASK;
    }
    else
    {
        base->CTRL_CLR = LCDIF_CTRL_ENABLE_PXP_HANDSHAKE_MASK;
    }
}

/* @} */

/*!
 * @name Status
 * @{
 */

/*!
 * @brief Get the CRC value of the frame sent out.
 *
 * When a frame is sent complete (the interrupt @ref kELCDIF_CurFrameDone assert), this function
 * can be used to get the CRC value of the frame sent.
 *
 * @param base eLCDIF peripheral base address.
 * @return The CRC value.
 *
 * @note The CRC value is dependent on the LCD_DATABUS_WIDTH.
 */
static inline uint32_t ELCDIF_GetCrcValue(LCDIF_Type *base)
{
    return base->CRC_STAT;
}

/*!
 * @brief Get the bus master error virtual address.
 *
 * When bus master error occurs (the interrupt kELCDIF_BusMasterError assert), this function
 * can get the virtual address at which the AXI master received an error
 * response from the slave.
 *
 * @param base eLCDIF peripheral base address.
 * @return The error virtual address.
 */
static inline uint32_t ELCDIF_GetBusMasterErrorAddr(LCDIF_Type *base)
{
    return base->BM_ERROR_STAT;
}

/*!
 * @brief Get the eLCDIF status.
 *
 * The status flags are returned as a mask value, application could check the
 * corresponding bit. Example:
 *
 * @code
   uint32_t statusFlags;
   statusFlags = ELCDIF_GetStatus(LCDIF);

   // If LFIFO is full.
   if (kELCDIF_LFifoFull & statusFlags)
   {
       // ...;
   }
   // If TXFIFO is empty.
   if (kELCDIF_TxFifoEmpty & statusFlags)
   {
       // ...;
   }
   @endcode
 *
 * @param base eLCDIF peripheral base address.
 * @return The mask value of status flags, it is OR'ed value of @ref _elcdif_status_flags.
 */
static inline uint32_t ELCDIF_GetStatus(LCDIF_Type *base)
{
    return base->STAT & (LCDIF_STAT_LFIFO_FULL_MASK | LCDIF_STAT_LFIFO_EMPTY_MASK | LCDIF_STAT_TXFIFO_FULL_MASK |
                         LCDIF_STAT_TXFIFO_EMPTY_MASK
#if defined(LCDIF_STAT_BUSY_MASK)
                         | LCDIF_STAT_BUSY_MASK
#endif
#if defined(LCDIF_STAT_DVI_CURRENT_FIELD_MASK)
                         | LCDIF_STAT_DVI_CURRENT_FIELD_MASK
#endif
                         );
}

/*!
 * @brief Get current count in Latency buffer (LFIFO).
 *
 * @param base eLCDIF peripheral base address.
 * @return The LFIFO current count
 */
static inline uint32_t ELCDIF_GetLFifoCount(LCDIF_Type *base)
{
    return (base->STAT & LCDIF_STAT_LFIFO_COUNT_MASK) >> LCDIF_STAT_LFIFO_COUNT_SHIFT;
}

/* @} */

/*!
 * @name Interrupts
 * @{
 */

/*!
 * @brief Enables eLCDIF interrupt requests.
 *
 * @param base eLCDIF peripheral base address.
 * @param mask interrupt source, OR'ed value of _elcdif_interrupt_enable.
 */
static inline void ELCDIF_EnableInterrupts(LCDIF_Type *base, uint32_t mask)
{
    base->CTRL1_SET = (mask & ELCDIF_CTRL1_IRQ_EN_MASK);
#if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
    base->AS_CTRL |= (mask & ELCDIF_AS_CTRL_IRQ_EN_MASK);
#endif
}

/*!
 * @brief Disables eLCDIF interrupt requests.
 *
 * @param base eLCDIF peripheral base address.
 * @param mask interrupt source, OR'ed value of _elcdif_interrupt_enable.
 */
static inline void ELCDIF_DisableInterrupts(LCDIF_Type *base, uint32_t mask)
{
    base->CTRL1_CLR = (mask & ELCDIF_CTRL1_IRQ_EN_MASK);
#if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
    base->AS_CTRL &= ~(mask & ELCDIF_AS_CTRL_IRQ_EN_MASK);
#endif
}

/*!
 * @brief Get eLCDIF interrupt peding status.
 *
 * @param base eLCDIF peripheral base address.
 * @return Interrupt pending status, OR'ed value of _elcdif_interrupt_flags.
 */
static inline uint32_t ELCDIF_GetInterruptStatus(LCDIF_Type *base)
{
    uint32_t flags;

    flags = (base->CTRL1 & ELCDIF_CTRL1_IRQ_MASK);
#if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
    flags |= (base->AS_CTRL & ELCDIF_AS_CTRL_IRQ_MASK);
#endif

    return flags;
}

/*!
 * @brief Clear eLCDIF interrupt peding status.
 *
 * @param base eLCDIF peripheral base address.
 * @param mask of the flags to clear, OR'ed value of _elcdif_interrupt_flags.
 */
static inline void ELCDIF_ClearInterruptStatus(LCDIF_Type *base, uint32_t mask)
{
    base->CTRL1_CLR = (mask & ELCDIF_CTRL1_IRQ_MASK);
#if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
    base->AS_CTRL &= ~(mask & ELCDIF_AS_CTRL_IRQ_MASK);
#endif
}

/* @} */

#if !(defined(FSL_FEATURE_LCDIF_HAS_NO_AS) && FSL_FEATURE_LCDIF_HAS_NO_AS)
/*!
 * @name Alpha surface
 * @{
 */

/*!
 * @brief Set the configuration for alpha surface buffer.
 *
 * @param base eLCDIF peripheral base address.
 * @param config Pointer to the configuration structure.
 */
void ELCDIF_SetAlphaSurfaceBufferConfig(LCDIF_Type *base, const elcdif_as_buffer_config_t *config);

/*!
 * @brief Set the alpha surface blending configuration.
 *
 * @param base eLCDIF peripheral base address.
 * @param config Pointer to the configuration structure.
 */
void ELCDIF_SetAlphaSurfaceBlendConfig(LCDIF_Type *base, const elcdif_as_blend_config_t *config);

/*!
 * @brief Set the next alpha surface buffer address.
 *
 * @param base eLCDIF peripheral base address.
 * @param bufferAddr Alpha surface buffer address.
 */
static inline void ELCDIF_SetNextAlphaSurfaceBufferAddr(LCDIF_Type *base, uint32_t bufferAddr)
{
    base->AS_NEXT_BUF = bufferAddr;
}

/*!
 * @brief Set the overlay color key.
 *
 * If a pixel in the current overlay image with a color that falls in the range
 * from the @p colorKeyLow to @p colorKeyHigh range, it will use the process surface
 * pixel value for that location.
 *
 * @param base eLCDIF peripheral base address.
 * @param colorKeyLow Color key low range.
 * @param colorKeyHigh Color key high range.
 *
 * @note Colorkey operations are higher priority than alpha or ROP operations
 */
static inline void ELCDIF_SetOverlayColorKey(LCDIF_Type *base, uint32_t colorKeyLow, uint32_t colorKeyHigh)
{
    base->AS_CLRKEYLOW = colorKeyLow;
    base->AS_CLRKEYHIGH = colorKeyHigh;
}

/*!
 * @brief Enable or disable the color key.
 *
 * @param base eLCDIF peripheral base address.
 * @param enable True to enable, false to disable.
 */
static inline void ELCDIF_EnableOverlayColorKey(LCDIF_Type *base, bool enable)
{
    if (enable)
    {
        base->AS_CTRL |= LCDIF_AS_CTRL_ENABLE_COLORKEY_MASK;
    }
    else
    {
        base->AS_CTRL &= ~LCDIF_AS_CTRL_ENABLE_COLORKEY_MASK;
    }
}

/*!
 * @brief Enable or disable the alpha surface.
 *
 * @param base eLCDIF peripheral base address.
 * @param enable True to enable, false to disable.
 */
static inline void ELCDIF_EnableAlphaSurface(LCDIF_Type *base, bool enable)
{
    if (enable)
    {
        base->AS_CTRL |= LCDIF_AS_CTRL_AS_ENABLE_MASK;
    }
    else
    {
        base->AS_CTRL &= ~LCDIF_AS_CTRL_AS_ENABLE_MASK;
    }
}

/*!
 * @brief Enable or disable the process surface.
 *
 * Process surface is the normal frame buffer. The process surface content
 * is controlled by @ref ELCDIF_SetNextBufferAddr.
 *
 * @param base eLCDIF peripheral base address.
 * @param enable True to enable, false to disable.
 */
static inline void ELCDIF_EnableProcessSurface(LCDIF_Type *base, bool enable)
{
    if (enable)
    {
        base->AS_CTRL &= ~LCDIF_AS_CTRL_PS_DISABLE_MASK;
    }
    else
    {
        base->AS_CTRL |= LCDIF_AS_CTRL_PS_DISABLE_MASK;
    }
}

/* @} */
#endif /* FSL_FEATURE_LCDIF_HAS_NO_AS */

#if (defined(FSL_FEATURE_LCDIF_HAS_LUT) && FSL_FEATURE_LCDIF_HAS_LUT)
/*!
 * @name LUT
 *
 * The Lookup Table (LUT) is used to expand the 8 bits pixel to 24 bits pixel
 * before output to external displayer.
 *
 * There are two 256x24 bits LUT memory in LCDIF, the LSB of frame buffer address
 * determins which memory to use.
 *
 * @{
 */

/*!
 * @brief Enable or disable the LUT.
 *
 * @param base eLCDIF peripheral base address.
 * @param enable True to enable, false to disable.
 */
static inline void ELCDIF_EnableLut(LCDIF_Type *base, bool enable)
{
    if (enable)
    {
        base->LUT_CTRL &= ~LCDIF_LUT_CTRL_LUT_BYPASS_MASK;
    }
    else
    {
        base->LUT_CTRL |= LCDIF_LUT_CTRL_LUT_BYPASS_MASK;
    }
}

/*!
 * @brief Load the LUT value.
 *
 * This function loads the LUT value to the specific LUT memory, user can
 * specify the start entry index.
 *
 * @param base eLCDIF peripheral base address.
 * @param lut Which LUT to load.
 * @param startIndex The start index of the LUT entry to update.
 * @param lutData The LUT data to load.
 * @param count Count of @p lutData.
 * @retval kStatus_Success Initialization success.
 * @retval kStatus_InvalidArgument Wrong argument.
 */
status_t ELCDIF_UpdateLut(
    LCDIF_Type *base, elcdif_lut_t lut, uint16_t startIndex, const uint32_t *lutData, uint16_t count);

/* @} */
#endif /* FSL_FEATURE_LCDIF_HAS_LUT */

#if defined(__cplusplus)
}
#endif /* __cplusplus */

/* @} */

#endif /*_FSL_ELCDIF_H_*/