1 /*!
2     \file    gd32f4xx_tli.c
3     \brief   TLI driver
4 
5     \version 2016-08-15, V1.0.0, firmware for GD32F4xx
6     \version 2018-12-12, V2.0.0, firmware for GD32F4xx
7     \version 2020-09-30, V2.1.0, firmware for GD32F4xx
8     \version 2022-03-09, V3.0.0, firmware for GD32F4xx
9 */
10 
11 /*
12     Copyright (c) 2022, GigaDevice Semiconductor Inc.
13 
14     Redistribution and use in source and binary forms, with or without modification,
15 are permitted provided that the following conditions are met:
16 
17     1. Redistributions of source code must retain the above copyright notice, this
18        list of conditions and the following disclaimer.
19     2. Redistributions in binary form must reproduce the above copyright notice,
20        this list of conditions and the following disclaimer in the documentation
21        and/or other materials provided with the distribution.
22     3. Neither the name of the copyright holder nor the names of its contributors
23        may be used to endorse or promote products derived from this software without
24        specific prior written permission.
25 
26     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35 OF SUCH DAMAGE.
36 */
37 
38 #include "gd32f4xx_tli.h"
39 
40 #define TLI_DEFAULT_VALUE   0x00000000U
41 #define TLI_OPAQUE_VALUE    0x000000FFU
42 
43 /*!
44     \brief    deinitialize TLI registers
45     \param[in]  none
46     \param[out] none
47     \retval     none
48 */
tli_deinit(void)49 void tli_deinit(void)
50 {
51     rcu_periph_reset_enable(RCU_TLIRST);
52     rcu_periph_reset_disable(RCU_TLIRST);
53 }
54 
55 /*!
56     \brief    initialize the parameters of TLI parameter structure with the default values, it is suggested
57                 that call this function after a tli_parameter_struct structure is defined
58     \param[in]  none
59     \param[out] tli_struct: the data needed to initialize TLI
60                   synpsz_vpsz: size of the vertical synchronous pulse
61                   synpsz_hpsz: size of the horizontal synchronous pulse
62                   backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
63                   backpsz_hbpsz: size of the horizontal back porch plus synchronous pulse
64                   activesz_vasz: size of the vertical active area width plus back porch and synchronous pulse
65                   activesz_hasz: size of the horizontal active area width plus back porch and synchronous pulse
66                   totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
67                   totalsz_htsz: vorizontal total size of the display, including active area, back porch, synchronous
68                   backcolor_red: background value red
69                   backcolor_green: background value green
70                   backcolor_blue: background value blue
71                   signalpolarity_hs: TLI_HSYN_ACTLIVE_LOW,TLI_HSYN_ACTLIVE_HIGHT
72                   signalpolarity_vs: TLI_VSYN_ACTLIVE_LOW,TLI_VSYN_ACTLIVE_HIGHT
73                   signalpolarity_de: TLI_DE_ACTLIVE_LOW,TLI_DE_ACTLIVE_HIGHT
74                   signalpolarity_pixelck: TLI_PIXEL_CLOCK_TLI,TLI_PIXEL_CLOCK_INVERTEDTLI
75     \retval     none
76 */
tli_struct_para_init(tli_parameter_struct * tli_struct)77 void tli_struct_para_init(tli_parameter_struct *tli_struct)
78 {
79     /* initialize the struct parameters with default values */
80     tli_struct->synpsz_vpsz = TLI_DEFAULT_VALUE;
81     tli_struct->synpsz_hpsz = TLI_DEFAULT_VALUE;
82     tli_struct->backpsz_vbpsz = TLI_DEFAULT_VALUE;
83     tli_struct->backpsz_hbpsz = TLI_DEFAULT_VALUE;
84     tli_struct->activesz_vasz = TLI_DEFAULT_VALUE;
85     tli_struct->activesz_hasz = TLI_DEFAULT_VALUE;
86     tli_struct->totalsz_vtsz = TLI_DEFAULT_VALUE;
87     tli_struct->totalsz_htsz = TLI_DEFAULT_VALUE;
88     tli_struct->backcolor_red = TLI_DEFAULT_VALUE;
89     tli_struct->backcolor_green = TLI_DEFAULT_VALUE;
90     tli_struct->backcolor_blue = TLI_DEFAULT_VALUE;
91     tli_struct->signalpolarity_hs = TLI_HSYN_ACTLIVE_LOW;
92     tli_struct->signalpolarity_vs = TLI_VSYN_ACTLIVE_LOW;
93     tli_struct->signalpolarity_de = TLI_DE_ACTLIVE_LOW;
94     tli_struct->signalpolarity_pixelck = TLI_PIXEL_CLOCK_TLI;
95 }
96 
97 /*!
98     \brief    initialize TLI display timing parameters
99     \param[in]  tli_struct: the data needed to initialize TLI
100                   synpsz_vpsz: size of the vertical synchronous pulse
101                   synpsz_hpsz: size of the horizontal synchronous pulse
102                   backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
103                   backpsz_hbpsz: size of the horizontal back porch plus synchronous pulse
104                   activesz_vasz: size of the vertical active area width plus back porch and synchronous pulse
105                   activesz_hasz: size of the horizontal active area width plus back porch and synchronous pulse
106                   totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
107                   totalsz_htsz: vorizontal total size of the display, including active area, back porch, synchronous
108                   backcolor_red: background value red
109                   backcolor_green: background value green
110                   backcolor_blue: background value blue
111                   signalpolarity_hs: TLI_HSYN_ACTLIVE_LOW,TLI_HSYN_ACTLIVE_HIGHT
112                   signalpolarity_vs: TLI_VSYN_ACTLIVE_LOW,TLI_VSYN_ACTLIVE_HIGHT
113                   signalpolarity_de: TLI_DE_ACTLIVE_LOW,TLI_DE_ACTLIVE_HIGHT
114                   signalpolarity_pixelck: TLI_PIXEL_CLOCK_TLI,TLI_PIXEL_CLOCK_INVERTEDTLI
115     \param[out] none
116     \retval     none
117 */
tli_init(tli_parameter_struct * tli_struct)118 void tli_init(tli_parameter_struct *tli_struct)
119 {
120     /* synchronous pulse size configuration */
121     TLI_SPSZ &= ~(TLI_SPSZ_VPSZ | TLI_SPSZ_HPSZ);
122     TLI_SPSZ = (uint32_t)((uint32_t)tli_struct->synpsz_vpsz | ((uint32_t)tli_struct->synpsz_hpsz << 16U));
123     /* back-porch size configuration */
124     TLI_BPSZ &= ~(TLI_BPSZ_VBPSZ | TLI_BPSZ_HBPSZ);
125     TLI_BPSZ = (uint32_t)((uint32_t)tli_struct->backpsz_vbpsz | ((uint32_t)tli_struct->backpsz_hbpsz << 16U));
126     /* active size configuration */
127     TLI_ASZ &= ~(TLI_ASZ_VASZ | TLI_ASZ_HASZ);
128     TLI_ASZ = (tli_struct->activesz_vasz | (tli_struct->activesz_hasz << 16U));
129     /* total size configuration */
130     TLI_TSZ &= ~(TLI_TSZ_VTSZ | TLI_TSZ_HTSZ);
131     TLI_TSZ = (tli_struct->totalsz_vtsz | (tli_struct->totalsz_htsz << 16U));
132     /* background color configuration */
133     TLI_BGC &= ~(TLI_BGC_BVB | (TLI_BGC_BVG) | (TLI_BGC_BVR));
134     TLI_BGC = (tli_struct->backcolor_blue | (tli_struct->backcolor_green << 8U) | (tli_struct->backcolor_red << 16U));
135     TLI_CTL &= ~(TLI_CTL_HPPS | TLI_CTL_VPPS | TLI_CTL_DEPS | TLI_CTL_CLKPS);
136     TLI_CTL |= (tli_struct->signalpolarity_hs | tli_struct->signalpolarity_vs | \
137                 tli_struct->signalpolarity_de | tli_struct->signalpolarity_pixelck);
138 
139 }
140 
141 /*!
142     \brief    configure TLI dither function
143     \param[in]  dither_stat
144                 only one parameter can be selected which is shown as below:
145       \arg        TLI_DITHER_ENABLE
146       \arg        TLI_DITHER_DISABLE
147     \param[out] none
148     \retval     none
149 */
tli_dither_config(uint8_t dither_stat)150 void tli_dither_config(uint8_t dither_stat)
151 {
152     if(TLI_DITHER_ENABLE == dither_stat) {
153         TLI_CTL |= TLI_CTL_DFEN;
154     } else {
155         TLI_CTL &= ~(TLI_CTL_DFEN);
156     }
157 }
158 
159 /*!
160     \brief    enable TLI
161     \param[in]  none
162     \param[out] none
163     \retval     none
164 */
tli_enable(void)165 void tli_enable(void)
166 {
167     TLI_CTL |= TLI_CTL_TLIEN;
168 }
169 
170 /*!
171     \brief    disable TLI
172     \param[in]  none
173     \param[out] none
174     \retval     none
175 */
tli_disable(void)176 void tli_disable(void)
177 {
178     TLI_CTL &= ~(TLI_CTL_TLIEN);
179 }
180 
181 /*!
182     \brief    configure TLI reload mode
183     \param[in]  reload_mod
184                 only one parameter can be selected which is shown as below:
185       \arg        TLI_FRAME_BLANK_RELOAD_EN
186       \arg        TLI_REQUEST_RELOAD_EN
187     \param[out] none
188     \retval     none
189 */
tli_reload_config(uint8_t reload_mod)190 void tli_reload_config(uint8_t reload_mod)
191 {
192     if(TLI_FRAME_BLANK_RELOAD_EN == reload_mod) {
193         /* the layer configuration will be reloaded at frame blank */
194         TLI_RL |= TLI_RL_FBR;
195     } else {
196         /* the layer configuration will be reloaded after this bit sets */
197         TLI_RL |= TLI_RL_RQR;
198     }
199 }
200 
201 /*!
202     \brief    initialize the parameters of TLI layer structure with the default values, it is suggested
203                 that call this function after a tli_layer_parameter_struct structure is defined
204     \param[in]  none
205     \param[out] layer_struct: TLI Layer parameter struct
206                   layer_window_rightpos: window right position
207                   layer_window_leftpos: window left position
208                   layer_window_bottompos: window bottom position
209                   layer_window_toppos: window top position
210                   layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
211                                  LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
212                                  LAYER_PPF_AL44,LAYER_PPF_AL88
213                   layer_sa: specified alpha
214                   layer_default_alpha: the default color alpha
215                   layer_default_red: the default color red
216                   layer_default_green: the default color green
217                   layer_default_blue: the default color blue
218                   layer_acf1: LAYER_ACF1_SA,LAYER_ACF1_PASA
219                   layer_acf2: LAYER_ACF2_SA,LAYER_ACF2_PASA
220                   layer_frame_bufaddr: frame buffer base address
221                   layer_frame_buf_stride_offset: frame buffer stride offset
222                   layer_frame_line_length: frame line length
223                   layer_frame_total_line_number: frame total line number
224     \retval     none
225 */
tli_layer_struct_para_init(tli_layer_parameter_struct * layer_struct)226 void tli_layer_struct_para_init(tli_layer_parameter_struct *layer_struct)
227 {
228     /* initialize the struct parameters with default values */
229     layer_struct->layer_window_rightpos = TLI_DEFAULT_VALUE;
230     layer_struct->layer_window_leftpos = TLI_DEFAULT_VALUE;
231     layer_struct->layer_window_bottompos = TLI_DEFAULT_VALUE;
232     layer_struct->layer_window_toppos = TLI_DEFAULT_VALUE;
233     layer_struct->layer_ppf = LAYER_PPF_ARGB8888;
234     layer_struct->layer_sa = TLI_OPAQUE_VALUE;
235     layer_struct->layer_default_alpha = TLI_DEFAULT_VALUE;
236     layer_struct->layer_default_red = TLI_DEFAULT_VALUE;
237     layer_struct->layer_default_green = TLI_DEFAULT_VALUE;
238     layer_struct->layer_default_blue = TLI_DEFAULT_VALUE;
239     layer_struct->layer_acf1 = LAYER_ACF1_PASA;
240     layer_struct->layer_acf2 = LAYER_ACF2_PASA;
241     layer_struct->layer_frame_bufaddr = TLI_DEFAULT_VALUE;
242     layer_struct->layer_frame_buf_stride_offset = TLI_DEFAULT_VALUE;
243     layer_struct->layer_frame_line_length = TLI_DEFAULT_VALUE;
244     layer_struct->layer_frame_total_line_number = TLI_DEFAULT_VALUE;
245 }
246 
247 /*!
248     \brief    initialize TLI layer
249     \param[in]  layerx: LAYERx(x=0,1)
250     \param[in]  layer_struct: TLI Layer parameter struct
251                   layer_window_rightpos: window right position
252                   layer_window_leftpos: window left position
253                   layer_window_bottompos: window bottom position
254                   layer_window_toppos: window top position
255                   layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
256                                  LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
257                                  LAYER_PPF_AL44,LAYER_PPF_AL88
258                   layer_sa: specified alpha
259                   layer_default_alpha: the default color alpha
260                   layer_default_red: the default color red
261                   layer_default_green: the default color green
262                   layer_default_blue: the default color blue
263                   layer_acf1: LAYER_ACF1_SA,LAYER_ACF1_PASA
264                   layer_acf2: LAYER_ACF2_SA,LAYER_ACF2_PASA
265                   layer_frame_bufaddr: frame buffer base address
266                   layer_frame_buf_stride_offset: frame buffer stride offset
267                   layer_frame_line_length: frame line length
268                   layer_frame_total_line_number: frame total line number
269     \param[out] none
270     \retval     none
271 */
tli_layer_init(uint32_t layerx,tli_layer_parameter_struct * layer_struct)272 void tli_layer_init(uint32_t layerx, tli_layer_parameter_struct *layer_struct)
273 {
274     /* configure layer window horizontal position */
275     TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP | (TLI_LxHPOS_WRP));
276     TLI_LxHPOS(layerx) = (uint32_t)((uint32_t)layer_struct->layer_window_leftpos | ((uint32_t)layer_struct->layer_window_rightpos << 16U));
277     /* configure layer window vertical position */
278     TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP | (TLI_LxVPOS_WBP));
279     TLI_LxVPOS(layerx) = (uint32_t)((uint32_t)layer_struct->layer_window_toppos | ((uint32_t)layer_struct->layer_window_bottompos << 16U));
280     /* configure layer packeted pixel format */
281     TLI_LxPPF(layerx) &= ~(TLI_LxPPF_PPF);
282     TLI_LxPPF(layerx) = layer_struct->layer_ppf;
283     /* configure layer specified alpha */
284     TLI_LxSA(layerx) &= ~(TLI_LxSA_SA);
285     TLI_LxSA(layerx) = layer_struct->layer_sa;
286     /* configure layer default color */
287     TLI_LxDC(layerx) &= ~(TLI_LxDC_DCB | (TLI_LxDC_DCG) | (TLI_LxDC_DCR) | (TLI_LxDC_DCA));
288     TLI_LxDC(layerx) = (uint32_t)((uint32_t)layer_struct->layer_default_blue | ((uint32_t)layer_struct->layer_default_green << 8U)
289                                   | ((uint32_t)layer_struct->layer_default_red << 16U)
290                                   | ((uint32_t)layer_struct->layer_default_alpha << 24U));
291 
292     /* configure layer alpha calculation factors */
293     TLI_LxBLEND(layerx) &= ~(TLI_LxBLEND_ACF2 | (TLI_LxBLEND_ACF1));
294     TLI_LxBLEND(layerx) = ((layer_struct->layer_acf2) | (layer_struct->layer_acf1));
295     /* configure layer frame buffer base address */
296     TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
297     TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
298     /* configure layer frame line length */
299     TLI_LxFLLEN(layerx) &= ~(TLI_LxFLLEN_FLL | (TLI_LxFLLEN_STDOFF));
300     TLI_LxFLLEN(layerx) = (uint32_t)((uint32_t)layer_struct->layer_frame_line_length | ((uint32_t)layer_struct->layer_frame_buf_stride_offset << 16U));
301     /* configure layer frame total line number */
302     TLI_LxFTLN(layerx) &= ~(TLI_LxFTLN_FTLN);
303     TLI_LxFTLN(layerx) = (uint32_t)(layer_struct->layer_frame_total_line_number);
304 
305 }
306 
307 /*!
308     \brief    reconfigure window position
309     \param[in]  layerx: LAYERx(x=0,1)
310     \param[in]  offset_x: new horizontal offset
311     \param[in]  offset_y: new vertical offset
312     \param[out] none
313     \retval     none
314 */
tli_layer_window_offset_modify(uint32_t layerx,uint16_t offset_x,uint16_t offset_y)315 void tli_layer_window_offset_modify(uint32_t layerx, uint16_t offset_x, uint16_t offset_y)
316 {
317     /* configure window start position */
318     uint32_t layer_ppf, line_num, hstart, vstart;
319     uint32_t line_length = 0U;
320     TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP | (TLI_LxHPOS_WRP));
321     TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP | (TLI_LxVPOS_WBP));
322     hstart = (uint32_t)offset_x + (((TLI_BPSZ & TLI_BPSZ_HBPSZ) >> 16U) + 1U);
323     vstart = (uint32_t)offset_y + ((TLI_BPSZ & TLI_BPSZ_VBPSZ) + 1U);
324     line_num = (TLI_LxFTLN(layerx) & TLI_LxFTLN_FTLN);
325     layer_ppf = (TLI_LxPPF(layerx) & TLI_LxPPF_PPF);
326     /* the bytes of a line equal TLI_LxFLLEN_FLL bits value minus 3 */
327     switch(layer_ppf) {
328     case LAYER_PPF_ARGB8888:
329         /* each pixel includes 4bytes, when pixel format is ARGB8888 */
330         line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U) / 4U);
331         break;
332     case LAYER_PPF_RGB888:
333         /* each pixel includes 3bytes, when pixel format is RGB888 */
334         line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U) / 3U);
335         break;
336     case LAYER_PPF_RGB565:
337     case LAYER_PPF_ARGB1555:
338     case LAYER_PPF_ARGB4444:
339     case LAYER_PPF_AL88:
340         /* each pixel includes 2bytes, when pixel format is RGB565,ARG1555,ARGB4444 or AL88 */
341         line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U) / 2U);
342         break;
343     case LAYER_PPF_L8:
344     case LAYER_PPF_AL44:
345         /* each pixel includes 1byte, when pixel format is L8 or AL44 */
346         line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U));
347         break;
348     default:
349         break;
350     }
351     /* reconfigure window position */
352     TLI_LxHPOS(layerx) = (hstart | ((hstart + line_length - 1U) << 16U));
353     TLI_LxVPOS(layerx) = (vstart | ((vstart + line_num - 1U) << 16U));
354 }
355 
356 /*!
357     \brief    initialize the parameters of TLI layer LUT structure with the default values, it is suggested
358                 that call this function after a tli_layer_lut_parameter_struct structure is defined
359     \param[in]  none
360     \param[out] lut_struct: TLI layer LUT parameter struct
361                   layer_table_addr: look up table write address
362                   layer_lut_channel_red: red channel of a LUT entry
363                   layer_lut_channel_green: green channel of a LUT entry
364                   layer_lut_channel_blue: blue channel of a LUT entry
365     \retval     none
366 */
tli_lut_struct_para_init(tli_layer_lut_parameter_struct * lut_struct)367 void tli_lut_struct_para_init(tli_layer_lut_parameter_struct *lut_struct)
368 {
369     /* initialize the struct parameters with default values */
370     lut_struct->layer_table_addr = TLI_DEFAULT_VALUE;
371     lut_struct->layer_lut_channel_red = TLI_DEFAULT_VALUE;
372     lut_struct->layer_lut_channel_green = TLI_DEFAULT_VALUE;
373     lut_struct->layer_lut_channel_blue = TLI_DEFAULT_VALUE;
374 }
375 
376 /*!
377     \brief    initialize TLI layer LUT
378     \param[in]  layerx: LAYERx(x=0,1)
379     \param[in]  lut_struct: TLI layer LUT parameter struct
380                   layer_table_addr: look up table write address
381                   layer_lut_channel_red: red channel of a LUT entry
382                   layer_lut_channel_green: green channel of a LUT entry
383                   layer_lut_channel_blue: blue channel of a LUT entry
384     \param[out] none
385     \retval     none
386 */
tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct * lut_struct)387 void tli_lut_init(uint32_t layerx, tli_layer_lut_parameter_struct *lut_struct)
388 {
389     TLI_LxLUT(layerx) = (uint32_t)(((uint32_t)lut_struct->layer_lut_channel_blue) | ((uint32_t)lut_struct->layer_lut_channel_green << 8U)
390                                    | ((uint32_t)lut_struct->layer_lut_channel_red << 16U
391                                       | ((uint32_t)lut_struct->layer_table_addr << 24U)));
392 }
393 
394 /*!
395     \brief    initialize TLI layer color key
396     \param[in]  layerx: LAYERx(x=0,1)
397     \param[in]  redkey: color key red
398     \param[in]  greenkey: color key green
399     \param[in]  bluekey: color key blue
400     \param[out] none
401     \retval     none
402 */
tli_color_key_init(uint32_t layerx,uint8_t redkey,uint8_t greenkey,uint8_t bluekey)403 void tli_color_key_init(uint32_t layerx, uint8_t redkey, uint8_t greenkey, uint8_t bluekey)
404 {
405     TLI_LxCKEY(layerx) = (((uint32_t)bluekey) | ((uint32_t)greenkey << 8U) | ((uint32_t)redkey << 16U));
406 }
407 
408 /*!
409     \brief    enable TLI layer
410     \param[in]  layerx: LAYERx(x=0,1)
411     \param[out] none
412     \retval     none
413 */
tli_layer_enable(uint32_t layerx)414 void tli_layer_enable(uint32_t layerx)
415 {
416     TLI_LxCTL(layerx) |= TLI_LxCTL_LEN;
417 }
418 
419 /*!
420     \brief    disable TLI layer
421     \param[in]  layerx: LAYERx(x=0,1)
422     \param[out] none
423     \retval     none
424 */
tli_layer_disable(uint32_t layerx)425 void tli_layer_disable(uint32_t layerx)
426 {
427     TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LEN);
428 }
429 
430 /*!
431     \brief    enable TLI layer color keying
432     \param[in]  layerx: LAYERx(x=0,1)
433     \param[out] none
434     \retval     none
435 */
tli_color_key_enable(uint32_t layerx)436 void tli_color_key_enable(uint32_t layerx)
437 {
438     TLI_LxCTL(layerx) |= TLI_LxCTL_CKEYEN;
439 }
440 
441 /*!
442     \brief    disable TLI layer color keying
443     \param[in]  layerx: LAYERx(x=0,1)
444     \param[out] none
445     \retval     none
446 */
tli_color_key_disable(uint32_t layerx)447 void tli_color_key_disable(uint32_t layerx)
448 {
449     TLI_LxCTL(layerx) &= ~(TLI_LxCTL_CKEYEN);
450 }
451 
452 /*!
453     \brief    enable TLI layer LUT
454     \param[in]  layerx: LAYERx(x=0,1)
455     \param[out] none
456     \retval     none
457 */
tli_lut_enable(uint32_t layerx)458 void tli_lut_enable(uint32_t layerx)
459 {
460     TLI_LxCTL(layerx) |= TLI_LxCTL_LUTEN;
461 }
462 
463 /*!
464     \brief    disable TLI layer LUT
465     \param[in]  layerx: LAYERx(x=0,1)
466     \param[out] none
467     \retval     none
468 */
tli_lut_disable(uint32_t layerx)469 void tli_lut_disable(uint32_t layerx)
470 {
471     TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LUTEN);
472 }
473 
474 /*!
475     \brief    set line mark value
476     \param[in]  line_num: line number
477     \param[out] none
478     \retval     none
479 */
tli_line_mark_set(uint16_t line_num)480 void tli_line_mark_set(uint16_t line_num)
481 {
482     TLI_LM &= ~(TLI_LM_LM);
483     TLI_LM = (uint32_t)line_num;
484 }
485 
486 /*!
487     \brief    get current displayed position
488     \param[in]  none
489     \param[out] none
490     \retval     position of current pixel
491 */
tli_current_pos_get(void)492 uint32_t tli_current_pos_get(void)
493 {
494     return TLI_CPPOS;
495 }
496 
497 /*!
498     \brief    enable TLI interrupt
499     \param[in]  int_flag: TLI interrupt flags
500                 one or more parameters can be selected which are shown as below:
501       \arg        TLI_INT_LM: line mark interrupt
502       \arg        TLI_INT_FE: FIFO error interrupt
503       \arg        TLI_INT_TE: transaction error interrupt
504       \arg        TLI_INT_LCR: layer configuration reloaded interrupt
505     \param[out] none
506     \retval     none
507 */
tli_interrupt_enable(uint32_t int_flag)508 void tli_interrupt_enable(uint32_t int_flag)
509 {
510     TLI_INTEN |= (int_flag);
511 }
512 
513 /*!
514     \brief    disable TLI interrupt
515     \param[in]  int_flag: TLI interrupt flags
516                 one or more parameters can be selected which are shown as below:
517       \arg        TLI_INT_LM: line mark interrupt
518       \arg        TLI_INT_FE: FIFO error interrupt
519       \arg        TLI_INT_TE: transaction error interrupt
520       \arg        TLI_INT_LCR: layer configuration reloaded interrupt
521     \param[out] none
522     \retval     none
523 */
tli_interrupt_disable(uint32_t int_flag)524 void tli_interrupt_disable(uint32_t int_flag)
525 {
526     TLI_INTEN &= ~(int_flag);
527 }
528 
529 /*!
530     \brief    get TLI interrupt flag
531     \param[in]  int_flag: TLI interrupt flags
532                 one or more parameters can be selected which are shown as below:
533       \arg        TLI_INT_FLAG_LM: line mark interrupt flag
534       \arg        TLI_INT_FLAG_FE: FIFO error interrupt flag
535       \arg        TLI_INT_FLAG_TE: transaction error interrupt flag
536       \arg        TLI_INT_FLAG_LCR: layer configuration reloaded interrupt flag
537     \param[out] none
538     \retval     FlagStatus: SET or RESET
539 */
tli_interrupt_flag_get(uint32_t int_flag)540 FlagStatus tli_interrupt_flag_get(uint32_t int_flag)
541 {
542     uint32_t state;
543     state = TLI_INTF;
544     if(state & int_flag) {
545         state = TLI_INTEN;
546         if(state & int_flag) {
547             return SET;
548         }
549     }
550     return RESET;
551 }
552 
553 /*!
554     \brief    clear TLI interrupt flag
555     \param[in]  int_flag: TLI interrupt flags
556                 one or more parameters can be selected which are shown as below:
557       \arg        TLI_INT_FLAG_LM: line mark interrupt flag
558       \arg        TLI_INT_FLAG_FE: FIFO error interrupt flag
559       \arg        TLI_INT_FLAG_TE: transaction error interrupt flag
560       \arg        TLI_INT_FLAG_LCR: layer configuration reloaded interrupt flag
561     \param[out] none
562     \retval     none
563 */
tli_interrupt_flag_clear(uint32_t int_flag)564 void tli_interrupt_flag_clear(uint32_t int_flag)
565 {
566     TLI_INTC |= (int_flag);
567 }
568 
569 /*!
570     \brief    get TLI flag or state in TLI_INTF register or TLI_STAT register
571     \param[in]  flag: TLI flags or states
572                 only one parameter can be selected which is shown as below:
573       \arg        TLI_FLAG_VDE: current VDE state
574       \arg        TLI_FLAG_HDE: current HDE state
575       \arg        TLI_FLAG_VS: current VS status of the TLI
576       \arg        TLI_FLAG_HS: current HS status of the TLI
577       \arg        TLI_FLAG_LM: line mark interrupt flag
578       \arg        TLI_FLAG_FE: FIFO error interrupt flag
579       \arg        TLI_FLAG_TE: transaction error interrupt flag
580       \arg        TLI_FLAG_LCR: layer configuration reloaded interrupt flag
581     \param[out] none
582     \retval     FlagStatus: SET or RESET
583 */
tli_flag_get(uint32_t flag)584 FlagStatus tli_flag_get(uint32_t flag)
585 {
586     uint32_t stat;
587     /* choose which register to get flag or state */
588     if(flag >> 31U) {
589         stat = TLI_INTF;
590     } else {
591         stat = TLI_STAT;
592     }
593     if(flag & stat) {
594         return SET;
595     } else {
596         return RESET;
597     }
598 }
599