1 /*
2  * Copyright 2021,2022 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef FSL_EPDC_H_
9 #define FSL_EPDC_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup epdc_driver
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @name Driver version */
23 /*! @{ */
24 #define FSL_EPDC_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
25 /*! @} */
26 
27 /* Definitions for interrupts and status. */
28 
29 /*!
30  * @brief EPDC non LUT complete interrupts.
31  * @note These enumerations are meant to be OR'd together to form a bit mask.
32  *       EPDC also has 64 independent LUT complete interrupts.
33  */
34 enum _epdc_interrupt_enable
35 {
36     kEPDC_WbCompleteInterruptEnable           = 1UL << 0U, /*!< Working buffer complete interrupt. */
37     kEPDC_LutCollisionDetetionInterruptEnable = 1UL << 1U, /*!< Collision detection interrupt for all LUTs. */
38     kEPDC_FifoUnderRunInterruptEnable         = 1UL << 2U, /*!< Pixel FIFO underrun interrupt. */
39     kEPDC_FrameCompleteInterruptEnable =
40         1UL << 3U, /*!< Current frame is complete and in vertical blanking period interrupt. */
41     kEPDC_AxiBusErrorInterruptEnable    = 1UL << 4U, /*!< AXI bus error occur interrupt. */
42     kEPDC_TceIdleInterruptEnable        = 1UL << 5U, /*!< TCE finished frame scan and in isle state interrupt. */
43     kEPDC_UpdateCompleteInterruptEnable = 1UL << 6U, /*!< Update complete interrupt.TODO */
44     kEPDC_PowerInterruptEnable          = 1UL << 7U, /*!< Power interrupt.TODO */
45 };
46 
47 /*!
48  * @brief EPDC non LUT complete status flags.
49  * @note These enumerations are meant to be OR'd together to form a bit mask.
50  *       EPDC also has 64 independent LUT complete interrupt status.
51  */
52 enum _epdc_status_flags
53 {
54     kEPDC_WbBusyFlag =
55         EPDC_STATUS_WB_BUSY_MASK, /*!< Working buffer process is busy and cannot accept new update requests. */
56     kEPDC_LutBusyFlag = EPDC_STATUS_LUTS_BUSY_MASK, /*!< All the LUTs ary busy. */
57     kEPDC_LutUnderrunFlag =
58         EPDC_STATUS_LUTS_UNDERRUN_MASK, /*!< Not enough time for active luts read during blanking period. */
59     kEPDC_UpdateBufferVoidFlag = EPDC_STATUS_UPD_VOID_MASK, /*!< Update buffer is void indicating no pixels need
60                                                                updating or all pixels were collided. */
61     kEPDC_WbCompleteInterruptFlag           = 1UL << 4U,    /*!< Working buffer complete interrupt flag. */
62     kEPDC_LutCollisionDetetionInterruptFlag = 1UL << 5U,    /*!< Collision detection interrupt flag for all LUTs. */
63     kEPDC_FifoUnderRunInterruptFlag         = 1UL << 6U,    /*!< Pixel FIFO underrun interrupt flag. */
64     kEPDC_FrameCompleteInterruptFlag =
65         1UL << 7U, /*!< Interrupt flag indicating current frame is complete and in vertical blanking period. */
66     kEPDC_AxiBusErrorInterruptFlag = 1UL << 8U, /*!< AXI bus error occur interrupt flag. */
67     kEPDC_TceIdleInterruptFlag =
68         1UL << 9U, /*!< Interrupt flag indicationg TCE has finished frame scan and in isle state. */
69     kEPDC_UpdateCompleteInterruptFlag = 1UL << 10U, /*!< Update complete interrupt flag.TODO */
70     kEPDC_PowerInterruptFlag          = 1UL << 11U, /*!< Power interrupt flag.TODO */
71 };
72 
73 /* Definitions for display parameters. */
74 
75 /*! @brief EPDC TFT pixel format. */
76 typedef enum _epdc_pixel_format
77 {
78     kEPDC_Pixel2bit     = 0x0U,
79     kEPDC_Pixel2bitVcom = 0x1U,
80     kEPDC_Pixel4bit     = 0x2U,
81     kEPDC_Pixel4bitVcom = 0x3U,
82 } epdc_pixel_format_t;
83 
84 /*! @brief EPDC working buffer type. */
85 typedef enum _epdc_wb_type
86 {
87     kEPDC_WbInternal = 0x0U, /*!< Internal Working Buffer written by EPDC itself. */
88     kEPDC_WbWaveform = 0x1U, /*!< Working buffer is actually holding waveform. */
89     kEPDC_Wb16bit    = 0x2U, /*!< 16bit working buffer written by PXP or CPU. */
90     kEPDC_Wb32bit    = 0x3U, /*!< 32bit working buffer written by PXP or CPU. */
91 } epdc_wb_type_t;
92 
93 /*! @brief EPDC data swizzle type for update date or LUT data. */
94 typedef enum _epdc_data_swizzle
95 {
96     kEPDC_NoSwap             = 0x0U, /*!< Little endian, no byte swapping. */
97     kEPDC_SwapAllBytes       = 0x1U, /*!< Big endian, byte 0|1|2|3 -> 3|2|1|0. */
98     kEPDC_SwapHalfWord       = 0x2U, /*!< byte 0|1|2|3 -> 2|3|0|1. */
99     kEPDC_SwapWithinHalfWord = 0x3U, /*!< byte 0|1|2|3 -> 1|0|3|2. */
100 } epdc_data_swizzle_t;
101 
102 /*! @brief EPDC display configuration. */
103 typedef struct _epdc_display_config
104 {
105     uint32_t waveformAddr; /*!< 64-bit aligned waveform table address. */
106     uint32_t wbAddr;       /*!< 64-bit aligned working buffer address. */
107     uint32_t
108         tempIdx;   /*!< Temperature index, used by the EPDC to access the correct temperature compensated waveform. */
109     uint16_t resX; /*!< Horizontal resolution in pixels. */
110     uint16_t resY; /*!< Vertical resolution in pixels. */
111     uint8_t defaltTftPixelValue; /*!< The source-driver voltage value for either partial updates where a pixel has not
112                                changed or for any part of the screen which is not being updated during active frame
113                                scans. */
114     epdc_pixel_format_t pixelFormat; /*!< How many bits of the SDDO bus are required per pixel. This field must be
115                                         consistent with the waveform and panel architecture. */
116     epdc_wb_type_t wbType;           /*!< Working buffer type. */
117     epdc_data_swizzle_t updSwizzle;  /*!< How to swap the bytes for the UPD data before the WB construction. */
118     epdc_data_swizzle_t lutSwizzle;  /*!< How to swap the bytes for the LUT data before store to LUTRAM. */
119 } epdc_display_config_t;
120 
121 /* Definitions for FIFO control parameters. */
122 
123 /*! @brief EPDC FIFO control configuration. */
124 typedef struct _epdc_fifo_config
125 {
126     uint32_t lowLevel : 10U;     /*!< Low level for panic function. */
127     uint32_t highLevel : 10U;    /*!< High level for panic function. */
128     uint32_t prefillLevel : 10U; /*!< EPDC pre-fill pixel FIFO to this level before TCE starts refresh operations. Must
129                                     be less than VERTICAL x HORIZONTAL / 4. */
130     uint32_t : 1U;               /*!< Reserved. */
131     uint32_t panicEnable : 1U; /*!< Enable epdc_panic output signal for priority elevation. Signal asserts when data in
132                                   FIFO is below the low level and de-asserts when above the high level. When asserted,
133                                   EPDC transaction requests have elevated priority at SoC-level bus arbitration. */
134 } epdc_fifo_config_t;
135 
136 /* Definitions for TCE configuration. */
137 
138 /*! @brief The VCOM value configuration. */
139 typedef enum _epdc_tce_vcom_mode
140 {
141     kEPDC_VcomManual = 0x0U, /*!< VCOM value is set manually, call EPDC_SetGpioOutput to set the VCOM value output. */
142     kEPDC_VcomAuto   = 0x1U, /*!< VCOM value is used from waveform. */
143 } epdc_tce_vcom_mode_t;
144 
145 /*! @brief The data output mode using DATA0 - DATA15. */
146 typedef enum _epdc_data_output_mode
147 {
148     kEPDC_Sdr8bit  = 0x0U,  /*!< Data driven only on positive edge of SDCLK. Connect to 8-bit SDDO. */
149     kEPDC_Sdr16bit = 0x1U,  /*!< Data driven only on positive edge of SDCLK. Connect to 8-bit SDDO. */
150     kEPDC_Ddr8bit  = 0x40U, /*!< Data driven on both edge of SDCLK. Connect to 8-bit SDDO. */
151     kEPDC_Ddr16bit = 0x41U, /*!< Data driven on both edge of SDCLK. Connect to 16-bit SDDO. */
152     kEPDC_Lvds = 0x71U, /*!< DATA[15:8] is for differencial signalling. Requires data driven on both edge of SDCLK and
153                            connect to 16-bit SDDO. */
154     kEPDC_SdrDualScan = 0x3U,  /*!< Data driven only on positive edge of SDCLK. DATA[7:0] and DATA[15:8] drive the
155                                   upper/lower half of the panel. */
156     kEPDC_DdrDualScan = 0x43U, /*!< Data driven on both edge of SDCLK. DATA[7:0] and DATA[15:8] drive the upper/lower
157                                   half of the panel. */
158 } epdc_data_output_mode_t;
159 
160 /*! @brief The vertical scan direction in dual scan mode. */
161 typedef enum _epdc_dualscan_direction
162 {
163     kEPDC_DualScanToptoBottom = 0x0U, /*!< Scan this region from top to bottom. */
164     kEPDC_DualScanBottomtoTop = 0x1U, /*!< Scan this region from bottom to top. */
165 } epdc_dualscan_direction_t;
166 
167 /*! @brief The signal output polarity for SDCE/SDLE/SDOE in source driver and GDOE/GDSP in gate driver. */
168 typedef enum _epdc_polarity
169 {
170     kEPDC_ActiveLow  = 0x0U,
171     kEPDC_ActiveHigh = 0x1U,
172 } epdc_polarity_t;
173 
174 /*! @brief The data reverse configuration for source driver configuration. */
175 typedef enum _epdc_data_reverse
176 {
177     kEPDC_DataUnchanged = 0x0U,
178     kEPDC_DataReversed =
179         0x1U, /*!< Reverse the pixel order on SDDO, eg: 2B/pixel on 8-bit bus, P3,P2,P1,P0->P0,P1,P2,P3. */
180 } epdc_data_reverse_t;
181 
182 /*! @brief Shift direction for SDSHR/GDRL signal for sourece/gate driver configuration.TODO */
183 typedef enum _epdc_shift_direction
184 {
185     kEPDC_ShiftRight = 0x0U,
186     kEPDC_ShiftLeft  = 0x1U,
187 } epdc_shift_direction_t;
188 
189 /*! @brief SDCLK/SDLE signal delay. */
190 typedef enum _epdc_signal_delay
191 {
192     kEPDC_NoDelay     = 0x0U, /*!< No delay. */
193     kEPDC_Delay1Cycle = 0x1U, /*!< Delay 1 SDCLK cycle. */
194     kEPDC_Delay2Cycle = 0x2U, /*!< Delay 2 SDCLK cycle. */
195     kEPDC_Delay3Cycle = 0x3U, /*!< Delay 3 SDCLK cycle. */
196 } epdc_signal_delay_t;
197 
198 /*! @brief EPDC source driver configuration. Source driver controls the timing for horizontal scan. */
199 typedef struct _epdc_sd_config
200 {
201     uint32_t sdcePol : 1U;         /*!< SDCE polarity. Refer @ref epdc_polarity_t. */
202     uint32_t sdlePol : 1U;         /*!< SDLE polarity. Refer @ref epdc_polarity_t. */
203     uint32_t sdoePol : 1U;         /*!< SDOE polarity, including SDOE/SDOEZ/SDOED. Refer @ref epdc_polarity_t. */
204     uint32_t sdclk_delay : 2;      /*!< Additional delay to the SDCLK generation. Refer @ref epdc_signal_delay_t. */
205     uint32_t : 1U;                 /*!< Reserved. */
206     uint32_t sdclk_invert : 1;     /*!< Invert the SDCLK signal. */
207     uint32_t sdle_delay : 2;       /*!< Additional delay to the SDLE generation. Refer @ref epdc_signal_delay_t. */
208     uint32_t : 4U;                 /*!< Reserved. */
209     uint32_t dataInvert : 1U;      /*!< Invert the polarity of each SDDO bit, eg: 0xAAAA -> 0x5555. */
210     uint32_t pixelReverse : 2U;    /*!< Reverse the pixel order on SDDO, eg: 2B/pixel on 8-bit bus,
211                                       P3,P2,P1,P0->P0,P1,P2,P3. Refer @ref epdc_data_reverse_t. */
212     uint32_t sdceCount : 4U;       /*!< The total count of source driver IC chip-enable pins. Make sure the horizontal
213                                       resolution can be evenly devided by it. */
214     uint32_t shiftDir : 1U;        /*!< The value of the SDSHR output signal controlling shift direction. Refer @ref
215                                       epdc_shift_direction_t. */
216     uint32_t clockHoldEnable : 1U; /*!< Enable to hold the SDCLK low furing line begin phase. */
217     uint32_t : 10U;                /*!< Reserved. */
218     uint32_t sdoezDelay : 8U;      /*!< Number of PIXCLK cycles from SDLE falling edge to SDOEZ rising. */
219     uint32_t sdoezWidth : 8U;      /*!< Number of PIXCLK cycles from SDOEZ high to SDOEZ falling. */
220     uint32_t sdoedDelay : 8U;      /*!< Number of PIXCLK cycles from SDOEZ low to SDOED rising. */
221     uint32_t sdoedWidth : 8U;      /*!< Number of PIXCLK cycles from SDOED high to SDOED falling. */
222 } epdc_sd_config_t;
223 
224 /*! @brief The output mode for GDOE signal. */
225 typedef enum _epdc_gdoe_mode
226 {
227     kEPDC_GDOEActiveBesideSync = 0x0U, /*!< GDOE is driven at all times during the frame-scan except FRAME_SYNC. */
228     kEPDC_GDOEActiveDelayedSck =
229         0x1U, /*!< GDOE is driven as a delayed version of GDCLK, and only active during the frame-data time. */
230 } epdc_gdoe_mode_t;
231 
232 /*! @brief The output mode for GDSP signal. */
233 typedef enum _epdc_gdsp_mode
234 {
235     kEPDC_GDSPActiveOnBegin = 0x0U, /*!< GDSP is driven on the first line clock of FRAME_BEGIN for one GDCLK period, and
236                                        can be shifted using the GDSP_OFFSET control. */
237     kEPDC_GDSPActiveDuringSync =
238         0x1U, /*!< GDSP is active during the entire FRAME_SYNC, and GDSP_OFFSET has no effect. */
239 } epdc_gdsp_mode_t;
240 
241 /*! @brief EPDC gate driver configuration. Gate driver controls the timing for vertical scan. */
242 typedef struct _epdc_gd_config
243 {
244     epdc_shift_direction_t
245         shiftDir; /*!< The value of the GDRL output signal controlling gate driver pulse shift direction. */
246     epdc_gdoe_mode_t gdoeMode; /*!< GDOE(gate driver output enable) signal mode. */
247     epdc_gdsp_mode_t gdspMode; /*!< GDSP(gate driver start pulse) signal mode. */
248     epdc_polarity_t gdoePol;   /*!< GDOE polarity. */
249     epdc_polarity_t gdspPol;   /*!< GDSP polarity. */
250     uint16_t gdoeOffset;       /*!< Delay GDOE in the terms of PIXCLK. */
251     uint16_t
252         gdspOffset; /*!< Delay GDSP in the terms of PIXCLK, only works when GDSP mode is kEPDC_GDSPActiveOnBegin. */
253     uint16_t gdClkOffset; /*!< Delay GDCLK from the line time in the terms of PIXCLK. */
254     uint16_t gdClkHigh; /*!< GDCLK high-pulse width in PIXCLK. The GDCLK cycle(high+low) always equal to line timing. */
255 } epdc_gd_config_t;
256 
257 /*! @brief EPDC scan configuration. Including horizontal scan(line timing) and vertical scan(fram timing). */
258 typedef struct _epdc_scan_config
259 {
260     uint16_t lineSync;  /*!< Number of PIXCLK cycles for line sync duration. */
261     uint16_t lineBegin; /*!< Number of PIXCLK cycles for line begin duration. */
262     uint16_t lineEnd;   /*!< Number of PIXCLK cycles for line end duration. */
263     uint8_t frameSync;  /*!< Number of lines for frame sync duration. */
264     uint8_t frameBegin; /*!< Number of lines for frame begin duration. */
265     uint8_t frameEnd;   /*!< Number of lines for frame end duration. */
266 } epdc_scan_config_t;
267 
268 /*! @brief EPDC TCE(timing controller engine) configuration. */
269 typedef struct _epdc_tce_config
270 {
271     uint32_t tceWbAddr;    /*!< Working buffer address for TCE. */
272     uint16_t vscanHoldoff; /*!< 9-bit max. Hold off the vertical scan timing during the blanking period to allow more
273                               smaller updates to be processed and included in the frame scan. Note the remainder of the
274                               blanking period is reserved for pre-filling the TCE pixel FIFOs so make sure enough time
275                               is left to prevent FIFO underrun. */
276     uint8_t vcomVal;       /*!< 2-bit max. The VCOM value when mode is manual. */
277     epdc_tce_vcom_mode_t vcomMode;                /*!< The method to driver VCOM signal. */
278     epdc_data_output_mode_t outMode;              /*!< The data output mode. */
279     epdc_dualscan_direction_t upperScanDirection; /*!< The scan direction of the upper half in dual scan mode. */
280     epdc_dualscan_direction_t lowerScanDirection; /*!< The scan direction of the lower half in dual scan mode. */
281     epdc_sd_config_t sdConfig;                    /*!< Source driver configuration */
282     epdc_gd_config_t gdConfig;                    /*!< Gate driver configuration */
283     epdc_scan_config_t scanConfig;                /*!< Scan configuration */
284 } epdc_tce_config_t;
285 
286 /* Pigeon mode configuration parameters. */
287 
288 /*! @brief Local counter tick event. */
289 typedef enum _epdc_pigeon_localCounter_tickEvent
290 {
291     kEPDC_TickOnPclk          = 0x0U, /*!< Counter tick on pixel clock. */
292     kEPDC_TickOnLineStart     = 0x1U, /*!< Counter tick on line start pulse. */
293     kEPDC_TickOnFrameStart    = 0x2U, /*!< Counter tick on frame start pulse. */
294     kEPDC_TickOnAnotherSignal = 0x3U, /*!< Use another signal as tick event. */
295 } epdc_pigeon_localCounter_tickEvent_t;
296 
297 /*!
298  * @brief Global counter select for pigeon signal's local counter start event.
299  * If selecting any of the pclk/line/frame cycle, need to call @ref EPDC_ConfigPigeonCycle to set the cycle period
300  * first. The cycle configuration applies to all pigeon signals.
301  */
302 typedef enum _epdc_pigeon_globalCounter
303 {
304     kEPDC_PclkCounterReset = 0x0U, /*!< Use pclk counter as global counter, counter reset when state changes. */
305     kEPDC_PclkCycleReset = 0x1U, /*!< Use pclk cycle as global counter, counter reset when state changes. Refer to @ref
306                                     epdc_pigeon_cycle_config_t for the definition of cycle. */
307     kEPDC_LineCounterReset = 0x2U, /*!< Use line counter as global counter, counter reset when state changes. */
308     kEPDC_LineCycleReset = 0x3U, /*!< Use line cycle as global counter, counter reset when state changes. Refer to @ref
309                                     epdc_pigeon_cycle_config_t for the definition of cycle. */
310     kEPDC_FrameCounter = 0x4U,   /*!< Use frame counter as global counter. */
311     kEPDC_FrameCycle   = 0x5U, /*!< Use frame cycle as global counter. Refer to @ref epdc_pigeon_cycle_config_t for the
312                                   definition of cycle. */
313     kEPDC_PclkCounter = 0x6U,  /*!< Use pclk counter as global counter. */
314     kEPDC_LineCounter = 0x7U,  /*!< Use line counter as global counter. */
315 } epdc_pigeon_globalCounter_t;
316 
317 /*!
318  * @brief The event for the pigeon signal's local counter to start ticking.
319  * Chose one or more frame events and one or more line events, OR them together to form the final event.
320  * eg: Use (kEPDC_FrameData | kEPDC_LineBegin), then the local counter will start ticking when line begin starts on the
321  * frame data phase.
322  */
323 enum _epdc_pigeon_localCounter_startEvent
324 {
325     kEPDC_FrameSync  = 1U << 0U,
326     kEPDC_FrameBegin = 1U << 1U,
327     kEPDC_FrameData  = 1U << 2U,
328     kEPDC_FrameEnd   = 1U << 3U,
329     kEPDC_LineSync   = 1U << 4U,
330     kEPDC_LineBegin  = 1U << 5U,
331     kEPDC_LineData   = 1U << 6U,
332     kEPDC_LineEnd    = 1U << 7U,
333 };
334 
335 /*! @brief Signal output logic . */
336 typedef enum _epdc_pigeon_output_logic
337 {
338     kEPDC_NoLogic = 0x0U, /*!< No logic operation, use the chosen another signal directly as the output. */
339     kEPDC_SignalAndAnother =
340         0x1U,                     /*!< Use the pigeon signal AND this chosen another signal to form the final output. */
341     kEPDC_SignalOrAnother = 0x2U, /*!< Use the pigeon signal OR this chosen another signal to form the final output. */
342     kEPDC_StartPointAndAnother =
343         0x3U, /*!< Use local counter's start point AND this chosen another signal to form the final output.TODO */
344 } epdc_pigeon_output_logic_t;
345 
346 /*!
347  * @brief Signal pigeon mode configuration.
348  * Each pigeon signal has one local counter with a configurable start/tick event. The counter value is compared to
349  * setCount/clearCount for signal assertion/de-assertion.
350  */
351 typedef struct _epdc_pigeon_config
352 {
353     uint32_t enablePigeon : 1U;          /*!< Enable pigeon mode for this signal. */
354     uint32_t polarity : 1U;              /*!< Polarty of the signal output. */
355     uint32_t localCounterTickEvent : 2U; /*!< The tick event selection for local counter. Refer @ref
356                                             epdc_pigeon_localCounter_tickEvent_t. */
357     uint32_t offset : 4U;                /*!< The offset of pclk unit, to let the signal come out earlier/later.TODO */
358     uint32_t globalCounterSelect : 4U;   /*!< To use a more accurate local counter start event than
359                                             localCounterStartEvent, a global counter combined with startCount can be used.
360                                             Refer @ref epdc_pigeon_globalCounter_t. */
361     uint32_t startCount : 12U; /*!< When the value of the selected global counter matches the count, the local counter
362                                   starts. */
363     uint32_t localCounterStartEvent : 8U; /*!< The event to start the local counter. Refer @ref
364                                              _epdc_pigeon_localCounter_startEvent. */
365     uint32_t setCount : 16U;              /*!< Assert signal when local counter matches this value. */
366     uint32_t clearCount : 16U;            /*!< De-assert signal when local counter matches this value. */
367     uint32_t outputLogic : 4U; /*!< When localCounterTickEvent is kEPDC_TickOnOtherSignal, use this logic to form the
368                                   final output. Refer @ref epdc_pigeon_output_logic_t. */
369     uint32_t anotherSignalNum : 5U; /*!< When localCounterTickEvent is kEPDC_TickOnOtherSignal, use the pigeon signal of
370                                        this number to form the tick event. */
371     uint32_t : 23U;                 /*!< Reserved. */
372 } epdc_pigeon_config_t;
373 
374 /*! @brief The pixle/line/frame cycle definition for global counter, shared by all pegion signals. */
375 typedef struct _epdc_pigeon_cycle_config
376 {
377     uint32_t lineCount : 12U; /*!< If chosing kEPDC_LineCycleReset, n lines in a frame are considered as one cycle, when
378                                  the period count matches startCount global counter starts ticking. */
379     uint32_t : 4U;            /*!< Reserved. */
380     uint32_t pixCount : 12U;  /*!< If chosing kEPDC_PclkCycleReset, n pixles in a line are considered as one cycle, when
381                                  the period count matches startCount global counter starts ticking. */
382     uint32_t : 4U;            /*!< Reserved. */
383     uint32_t frameCount : 12U; /*!< If chosing kEPDC_FrameCycle, n frames are considered as one cycle, when the period
384                                   count matches startCount global counter starts ticking. */
385     uint32_t : 4U;             /*!< Reserved. */
386     uint32_t maxframeCycle : 12U; /*!< The max cycles of frame cycle counter, frame cycle counter resets when reaches
387                                      this value. */
388     uint32_t : 4U;                /*!< Reserved. */
389 } epdc_pigeon_cycle_config_t;
390 
391 /* Definitions for panel update structure. */
392 
393 /*! @brief Waveform mode. */
394 typedef enum _epdc_waveform_mode
395 {
396     kEPDC_WaveformInit =
397         0x0U, /*!< Panel initialization. Completely erase the display and leave it in the white state. */
398     kEPDC_WaveformDU =
399         0x1U, /*!< Direct update. Very fast, non-flashy, transitions from any graytone to black or white only. */
400     kEPDC_WaveformGC16 = 0x2U, /*!< Grayscale clearing. High image quality, has 16 unique gray levels. */
401     kEPDC_WaveformGL16 = 0x3U, /*!< Used to update scattered content on a white background with reduced flash, has 16
402                                   unique gray levels. */
403     /* For the AF waveform, GLR16 and GLD16 waveform data points to the same voltage lists as the GL16 data and does not
404        need to be stored in a separate memory. */
405     kEPDC_WaveformGLR16 = 0x4U, /*!< Similar to GL16, but if a separately-supplied image preprocessing algorithm is
406                                    used, display quality is improved when transitions to pixel states 29 and 31. */
407     kEPDC_WaveformGLD16 =
408         0x5U, /*!< Similar to GL16, but if a separately-supplied image preprocessing algorithm is used, display quality
409                  is improved when transitions to pixel states 29 and 31, with lighter flash of the background compared
410                  to GC16 mode, and reduce image artifacts even more compared to the GLR16 mode. */
411     kEPDC_WaveformA2  = 0x6U, /*!< Very fast, non-flashy, transitions from black or white to black or white only. */
412     kEPDC_WaveformDU4 = 0x7U, /*!< Direct update 4. Very fast, non-flashy, from any graytone to gray tones 1,6,11,16
413                                  represented by pixel states [0 10 20 30]. */
414 } epdc_waveform_mode_t;
415 
416 /*! @brief Panel update configuration. */
417 typedef struct _epdc_update_config
418 {
419     uint32_t
420         bufferAddress; /*!< Address pointing to the update region which will be processed into the working buffer. If
421                           stride is zero(disabled), the address must start and end on the 8-byte aligned addresses. */
422     uint32_t stride;   /*!< Line stride. */
423     uint32_t coordinateX : 13;     /*!< X coordinate of the new update region. */
424     uint32_t : 3;                  /*!< Reserved. */
425     uint32_t coordinateY : 13;     /*!< Y coordinate of the new update region. */
426     uint32_t : 3;                  /*!< Reserved. */
427     uint32_t width : 13;           /*!< The width of the new update region in pixels. */
428     uint32_t : 3;                  /*!< Reserved. */
429     uint32_t height : 13;          /*!< The height of the new update region in pixels. */
430     uint32_t : 3;                  /*!< Reserved. */
431     uint32_t cpValue : 8;          /*!< The CP value if using fixed CP. */
432     uint32_t npValue : 8;          /*!< The NP value if using fixed NP. */
433     uint32_t : 14;                 /*!< Reserved. */
434     uint32_t fixedCpEnable : 1;    /*!< Enable fixed CP, need to set fixedEnable first. */
435     uint32_t fixedNpEnable : 1;    /*!< Enable fixed NP, need to set fixedEnable first. */
436     uint32_t fullUpdateEnable : 1; /*!< Enable full update. */
437     uint32_t dryRunEnable : 1; /*!< Enable dryrun which runs an update to obtain information without performing any real
438                                   action. */
439     uint32_t autoWaveEnable : 1; /*!< Enable automatical waveform mode selection. After completes the update buffer
440                                     processing, EPDC reports the minimal grey level, retrieves the mapped waveform mode
441                                     and program it into UPD_CTRL[WAVEFORM_MODE]. To use autowave the waveform map should
442                                     be programmed in advance. */
443     uint32_t pauseEnable : 1;    /*!< Enable pause after auto waveform selection. User can choose to check and alter the
444                                     waveform mode then initiate the update by calling @ref EPDC_ConfigureWaveform. */
445     uint32_t voidUpdateCancleDisable : 1; /*!< Disable the feature of cancelling void update(due to collision). */
446     uint32_t : 3;                         /*!< Reserved. */
447     uint32_t waveformMode : 8;            /*!< Waveform used for the update. Refer @ref epdc_waveform_mode_t. */
448     uint32_t lutNum : 6;                  /*!< The LUT number used for the update, can use EPDC_GetNextAvailableLUT. */
449     uint32_t : 9;                         /*!< Reserved. */
450     uint32_t fixedEnable : 1;             /*!< Use fixed pixel values. */
451 } epdc_update_config_t;
452 
453 /*! @brief Autowave map configuration. */
454 typedef struct _epdc_autowave_map
455 {
456     uint32_t greyLevel : 3;    /*!< Grey level. */
457     uint32_t : 13;             /*!< Reserved. */
458     uint32_t waveformMode : 8; /*!< Waveform mode. Refer @epdc_waveform_mode_t. */
459     uint32_t : 8;              /*!< Reserved. */
460 } epdc_autowave_map_t;
461 
462 /* GPIO configuration */
463 
464 /*! @brief GPIO pin output configuration. */
465 typedef struct _epdc_gpio_config
466 {
467     uint32_t bdrOutput : 2;     /*!< The BDR(0,1) pin output value. */
468     uint32_t pwrCtrlOutput : 4; /*!< The PWR_CTRL(0,1,2,3) pin output value. */
469     uint32_t pwrComOutput : 1;  /*!< The PWR_COM pin output value. */
470     uint32_t pwrWakeOutput : 1; /*!< The PWR_WAKE pin output value. */
471     uint32_t : 24;              /*!< Reserved. */
472 } epdc_gpio_config_t;
473 
474 /* LUT collision status */
475 
476 /*! @brief Update collision status structure. */
477 typedef struct _epdc_collision_status
478 {
479     uint16_t minX;    /*!< The x offset of the ULC of the collision region. */
480     uint16_t minY;    /*!< The y offset of the ULC of the collision region. */
481     uint16_t width;   /*!< The width of the collision region. */
482     uint16_t height;  /*!< The height of the collision region. */
483     uint64_t lutlist; /*!< 64-bit LUT list of the victim LUT(s), if LUT17 is being collided, then the bit17 of the list
484                          is set. */
485 } epdc_collision_status_t;
486 
487 /*******************************************************************************
488  * API
489  ******************************************************************************/
490 
491 #if defined(__cplusplus)
492 extern "C" {
493 #endif
494 
495 /*!
496  * @name Interrupt Sub-group
497  * @{
498  */
499 /*!
500  * @brief Enables non LUT complete EPDC interrupt source.
501  *
502  * @param base EPDC base pointer
503  * @param interrupts The interrupt source mask, can be a single source or several sources in #_epdc_interrupt_enable
504  * ORed together.
505  */
EPDC_EnableInterrupts(EPDC_Type * base,uint8_t interrupts)506 static inline void EPDC_EnableInterrupts(EPDC_Type *base, uint8_t interrupts)
507 {
508     base->IRQ_MASK.SET = ((uint32_t)interrupts << 16U);
509 }
510 
511 /*!
512  * @brief Diables non LUT complete EPDC interrupt source.
513  *
514  * @param base EPDC base pointer
515  * @param interrupts The interrupt source mask, can be a single source or several sources in #_epdc_interrupt_enable
516  * ORed together.
517  */
EPDC_DisableInterrupts(EPDC_Type * base,uint8_t interrupts)518 static inline void EPDC_DisableInterrupts(EPDC_Type *base, uint8_t interrupts)
519 {
520     base->IRQ_MASK.CLR = ((uint32_t)interrupts << 16U);
521 }
522 
523 /*!
524  * @brief Gets all the enabled non LUT complete interrupt sources.
525  *
526  * @param base EPDC base pointer
527  * @return The interrupt source mask, can be a single source or several sources in #_epdc_interrupt_enable ORed
528  * together.
529  */
EPDC_GetEnabledInterrupts(EPDC_Type * base)530 static inline uint8_t EPDC_GetEnabledInterrupts(EPDC_Type *base)
531 {
532     return (uint8_t)(base->IRQ_MASK.RW >> 16U);
533 }
534 
535 /*!
536  * @brief Gets the EPDC status flags.
537  *
538  * @param base EPDC base pointer
539  * @return the mask of status flags, can be a single flag or several flags in #_epdc_status_flags ORed together.
540  */
EPDC_GetStatusFlags(EPDC_Type * base)541 static inline uint16_t EPDC_GetStatusFlags(EPDC_Type *base)
542 {
543     return (uint16_t)((base->IRQ.RW >> 12U) | (base->STATUS.RW & 0xFU));
544 }
545 
546 /*!
547  * @brief Clears the EPDC status flags.
548  *
549  * @param base EPDC base pointer
550  * @param statusFlags The status flag mask, can be a single flag or several flags in #_epdc_status_flags ORed together.
551  */
EPDC_ClearStatusFlags(EPDC_Type * base,uint16_t statusFlags)552 static inline void EPDC_ClearStatusFlags(EPDC_Type *base, uint16_t statusFlags)
553 {
554     base->IRQ.CLR = ((uint32_t)statusFlags << 12U);
555 }
556 /*! @} */
557 
558 /*!
559  * @name LUT complete Interrupt Sub-group
560  * @{
561  */
562 /*!
563  * @brief Enables LUT complete interrupt source.
564  *
565  * @param base EPDC base pointer
566  * @param interrupts The interrupt source mask of single source or several sources up to all 64 interrupt sources.
567  *  If user wants to enable the complete interrupt for LUT17, set the bit 17 in this param.
568  */
EPDC_EnableLutCompleteInterrupts(EPDC_Type * base,uint64_t interrupts)569 static inline void EPDC_EnableLutCompleteInterrupts(EPDC_Type *base, uint64_t interrupts)
570 {
571     base->IRQ_MASK1.SET = (uint32_t)interrupts;
572     base->IRQ_MASK2.SET = (uint32_t)(interrupts >> 32U);
573 }
574 
575 /*!
576  * @brief Disables LUT complete interrupt source.
577  *
578  * @param base EPDC base pointer
579  * @param interrupts The interrupt source mask of single source or several sources up to all 64 interrupt sources.
580  *  If user wants to disable the complete interrupt for LUT17, set the bit 17 in this param.
581  */
EPDC_DisableLutCompleteInterrupts(EPDC_Type * base,uint64_t interrupts)582 static inline void EPDC_DisableLutCompleteInterrupts(EPDC_Type *base, uint64_t interrupts)
583 {
584     base->IRQ_MASK1.CLR = (uint32_t)interrupts;
585     base->IRQ_MASK2.CLR = (uint32_t)(interrupts >> 32U);
586 }
587 
588 /*!
589  * @brief Gets all the enabled LUT complete interrupts.
590  *
591  * @param base EPDC base pointer
592  * @return The interrupt source mask, can be a single source or several sources up to all 64 interrupt sources.
593  *  If complete interrupt for LUT17 is enabled, bit 17 is set.
594  */
EPDC_GetEnabledLutCompleteInterrupts(EPDC_Type * base)595 static inline uint64_t EPDC_GetEnabledLutCompleteInterrupts(EPDC_Type *base)
596 {
597     return (((uint64_t)(base->IRQ_MASK2.RW) << 32U) | (uint64_t)base->IRQ_MASK1.RW);
598 }
599 
600 /*!
601  * @brief Gets the LUT complete status flags.
602  *
603  * @param base EPDC base pointer
604  * @return the mask of status flags, can be a single flag or several flags up to all 64 interrupt flags.
605  *  If LUT17 has completed, bit 17 is set.
606  */
EPDC_GetLutCompleteStatusFlags(EPDC_Type * base)607 static inline uint64_t EPDC_GetLutCompleteStatusFlags(EPDC_Type *base)
608 {
609     return (uint64_t)base->IRQ1.RW | ((uint64_t)base->IRQ2.RW << 32U);
610 }
611 
612 /*!
613  * @brief Clears the LUT complete status flags.
614  *
615  * @param base EPDC base pointer
616  * @param the mask of status flags, can be a single flag or several flags up to all 64 interrupt flags.
617  *  If user wants to clear LUT17 completion, set bit 17 in this param.
618  */
EPDC_ClearLutCompleteStatusFlags(EPDC_Type * base,uint64_t statusFlags)619 static inline void EPDC_ClearLutCompleteStatusFlags(EPDC_Type *base, uint64_t statusFlags)
620 {
621     base->IRQ1.CLR = (uint32_t)statusFlags;
622     base->IRQ2.CLR = (uint32_t)(statusFlags >> 32U);
623 }
624 /*! @} */
625 
626 /*!
627  * @name Initialization and deinitialization
628  * @{
629  */
630 
631 /*!
632  * @brief Resets the EPDC to initialized state.
633  *
634  * @param base EPDC base pointer
635  */
636 void EPDC_ResetToInit(EPDC_Type *base);
637 
638 /*!
639  * @brief Initializes the EPDC.
640  *
641  * This function enables the EPDC peripheral clock, and resets the EPDC registers
642  * to default status.
643  *
644  * @param base EPDC base pointer
645  */
646 void EPDC_Init(EPDC_Type *base);
647 
648 /*!
649  * @brief De-initializes the EPDC.
650  *
651  * This function disables the EPDC peripheral clock.
652  *
653  * @param base EPDC base pointer
654  */
655 void EPDC_Deinit(EPDC_Type *base);
656 /*! @} */
657 
658 /*!
659  * @name Display Parameters Initialization
660  * @{
661  */
662 /*!
663  * @brief Initializes the EPDC dispaly parameters.
664  *
665  * @param base EPDC base pointer
666  * @param config Pointer to EPDC display configuration structure
667  * @retval kStatus_Success Successfully initialized the display parameters
668  * @retval kStatus_InvalidArgument parameter(s) is(are) not valid
669  */
670 status_t EPDC_InitDisplay(EPDC_Type *base, const epdc_display_config_t *config);
671 /*! @} */
672 
673 /*!
674  * @name FIFO control
675  * @{
676  */
677 /*!
678  * @brief Configures the FIFO control parameters, including panic function and pre-fill level.
679  *
680  * @param base EPDC base pointer
681  * @param config Pointer to EPDC FIFO control configuration structure
682  * @retval kStatus_Success Successfully configured the FIFO
683  * @retval kStatus_InvalidArgument parameter(s) is(are) not valid
684  */
685 status_t EPDC_ConfigFifo(EPDC_Type *base, const epdc_fifo_config_t *config);
686 
687 /*!
688  * @brief Enables/disables the panic funtion for FIFO control.
689  *
690  * @param base EPDC base pointer
691  * @param enable true to enable panic function, false to disable
692  */
EPDC_EnableFifoPanic(EPDC_Type * base,bool enable)693 static inline void EPDC_EnableFifoPanic(EPDC_Type *base, bool enable)
694 {
695     if (enable)
696     {
697         base->FIFOCTRL.SET = EPDC_FIFOCTRL_ENABLE_PRIORITY_MASK;
698     }
699     else
700     {
701         base->FIFOCTRL.CLR = EPDC_FIFOCTRL_ENABLE_PRIORITY_MASK;
702     }
703 }
704 /*! @} */
705 
706 /*!
707  * @name TCE(timing controller engine) configuration
708  * @{
709  */
710 /*!
711  * @brief Configures the TCE parameters before initiating the panel update.
712  *
713  * @note Make sure to configure the display parameters by @ref EPDC_InitDisplay before calling this API.
714  *
715  * @param base EPDC base pointer
716  * @param config Pointer to EPDC TCE control configuration structure
717  * @retval kStatus_Success Successfully configured the TCE
718  * @retval kStatus_InvalidArgument parameter(s) is(are) not valid
719  */
720 status_t EPDC_ConfigTCE(EPDC_Type *base, const epdc_tce_config_t *config);
721 /*! @} */
722 
723 /*!
724  * @name PIGEON mode configuration
725  * @{
726  */
727 /*!
728  * @brief Configures the signal output format for signals that support pigeon mode.
729  *
730  * @note Refer to the soc reference manual to check the configurable pigeon signal.
731  *       No need to call this API if not using the pigeon mode.
732  *
733  * @param base EPDC base pointer
734  * @param signalNum The number of the pigeon signal to be configured
735  * @param config Pointer to EPDC pigeon mode configuration structure
736  */
737 void EPDC_ConfigPigeon(EPDC_Type *base, uint8_t signalNum, const epdc_pigeon_config_t *config);
738 
739 /*!
740  * @brief Configures the cycle's period.
741  *
742  * When selecting any of the pclk/line/frame cycle as global counter, call this API forst to set the proper cycle
743  * period. The configuraton is shared for all pigeon signals.
744  *
745  * @param base EPDC base pointer
746  * @param config Pointer to EPDC pigeon mode cycle configuration structure
747  */
748 void EPDC_ConfigPigeonCycle(EPDC_Type *base, const epdc_pigeon_cycle_config_t *config);
749 /*! @} */
750 
751 /*!
752  * @name Panel Update
753  * @{
754  */
755 /*!
756  * @brief Gets the number of the next available LUT.
757  *
758  * @param base EPDC base pointer
759  * @param lutNum Pointer to LUT number
760  * @retval kStatus_Success Successfully got the LUT number
761  * @retval kStatus_Fail no valid LUT present, all LUTs are busy
762  */
763 status_t EPDC_GetNextAvailableLUT(EPDC_Type *base, uint8_t *lutNum);
764 
765 /*!
766  * @brief Configures the waveform mode and initiate the panel update.
767  *
768  * @param base EPDC base pointer
769  * @param waveformMode Waveform mode
770  */
EPDC_ConfigureWaveform(EPDC_Type * base,uint8_t waveformMode)771 static inline void EPDC_ConfigureWaveform(EPDC_Type *base, uint8_t waveformMode)
772 {
773     base->UPD_CTRL.RW = (base->UPD_CTRL.RW & ~EPDC_UPD_CTRL_WAVEFORM_MODE_MASK) | EPDC_UPD_CTRL_WAVEFORM_MODE(waveformMode);
774 }
775 
776 /*!
777  * @brief Initiates a panel display update.
778  *
779  * @param base EPDC base pointer
780  * @param config Pointer to update configuration structure
781  * @retval kStatus_Success Successfully initiate an update
782  * @retval kStatus_Fail update failed due to busy working buffer or LUT
783  * @retval kStatus_InvalidArgument parameter(s) is(are) not valid
784  */
785 status_t EPDC_UpdateDisplay(EPDC_Type *base, epdc_update_config_t *config);
786 
787 /*!
788  * @brief Sets one map between a grey level and its waveform mode.
789  *
790  * Call this API multiple times until all the maps are set.
791  *
792  * @param base EPDC base pointer
793  * @param config Pointer to autowave configuration structure
794  */
795 void EPDC_SetAutowaveMap(EPDC_Type *base, const epdc_autowave_map_t *config);
796 /*! @} */
797 
798 /*!
799  * @name Panel Update
800  * @{
801  */
802 /*!
803  * @brief Sets the GPIO output value for BDR(0,1), PWR_CTRL(0,1,2,3), PWR_COM and PWR_WAKE pins.
804  *
805  * @param base EPDC base pointer
806  * @param config Pointer to GPIO configuration structure
807  */
808 void EPDC_SetGpioOutput(EPDC_Type *base, const epdc_gpio_config_t *config);
809 /*! @} */
810 
811 /*!
812  * @name Update collision
813  * @{
814  */
815 /*!
816  * @brief Gets the status of the collision
817  *
818  * @param base EPDC base pointer
819  * @param status Pointer to collision status structure
820  */
821 void EPDC_GetCollisionStatus(EPDC_Type *base, epdc_collision_status_t *status);
822 /*! @} */
823 
824 #if defined(__cplusplus)
825 }
826 #endif
827 
828 /*! @}*/
829 
830 #endif /* FSL_EPDC_H_ */
831