gd32f4xx_tli.c 24 KB

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