gd32f4xx_tli.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*!
  2. \file gd32f4xx_tli.c
  3. \brief TLI driver
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.1, firmware for GD32F4xx
  8. */
  9. #include "gd32f4xx_tli.h"
  10. /*!
  11. \brief deinitialize TLI registers
  12. \param[in] none
  13. \param[out] none
  14. \retval none
  15. */
  16. void tli_deinit(void)
  17. {
  18. rcu_periph_reset_enable(RCU_TLIRST);
  19. rcu_periph_reset_disable(RCU_TLIRST);
  20. }
  21. /*!
  22. \brief initialize TLI display timing parameters
  23. \param[in] tli_struct: the data needed to initialize tli.
  24. synpsz_vpsz: size of the vertical synchronous pulse
  25. synpsz_hpsz: size of the horizontal synchronous pulse
  26. backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
  27. backpsz_hbpsz: size of the horizontal back porch plus synchronous pulse
  28. activesz_vasz: size of the vertical active area width plus back porch and synchronous pulse
  29. activesz_hasz: size of the horizontal active area width plus back porch and synchronous pulse
  30. totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
  31. totalsz_htsz: vorizontal total size of the display, including active area, back porch, synchronous
  32. backcolor_red: background value red
  33. backcolor_green: background value green
  34. backcolor_blue: background value blue
  35. signalpolarity_hs: TLI_HSYN_ACTLIVE_LOW,TLI_HSYN_ACTLIVE_HIGHT
  36. signalpolarity_vs: TLI_VSYN_ACTLIVE_LOW,TLI_VSYN_ACTLIVE_HIGHT
  37. signalpolarity_de: TLI_DE_ACTLIVE_LOW,TLI_DE_ACTLIVE_HIGHT
  38. signalpolarity_pixelck: TLI_PIXEL_CLOCK_TLI,TLI_PIXEL_CLOCK_INVERTEDTLI
  39. \param[out] none
  40. \retval none
  41. */
  42. void tli_init(tli_parameter_struct *tli_struct)
  43. {
  44. /* synchronous pulse size configuration */
  45. TLI_SPSZ &= ~(TLI_SPSZ_VPSZ|TLI_SPSZ_HPSZ);
  46. TLI_SPSZ = (tli_struct->synpsz_vpsz|(tli_struct->synpsz_hpsz<<16U));
  47. /* back-porch size configuration */
  48. TLI_BPSZ &= ~(TLI_BPSZ_VBPSZ|TLI_BPSZ_HBPSZ);
  49. TLI_BPSZ = (tli_struct->backpsz_vbpsz|(tli_struct->backpsz_hbpsz<<16U));
  50. /* active size configuration */
  51. TLI_ASZ &= ~(TLI_ASZ_VASZ|TLI_ASZ_HASZ);
  52. TLI_ASZ = (tli_struct->activesz_vasz|(tli_struct->activesz_hasz<<16U));
  53. /* total size configuration */
  54. TLI_TSZ &= ~(TLI_TSZ_VTSZ|TLI_TSZ_HTSZ);
  55. TLI_TSZ = (tli_struct->totalsz_vtsz|(tli_struct->totalsz_htsz<<16U));
  56. /* background color configuration */
  57. TLI_BGC &= ~(TLI_BGC_BVB|(TLI_BGC_BVG)|(TLI_BGC_BVR));
  58. TLI_BGC = (tli_struct->backcolor_blue|(tli_struct->backcolor_green<<8U)|(tli_struct->backcolor_red<<16U));
  59. TLI_CTL &= ~(TLI_CTL_HPPS|TLI_CTL_VPPS|TLI_CTL_DEPS|TLI_CTL_CLKPS);
  60. TLI_CTL |= (tli_struct->signalpolarity_hs|tli_struct->signalpolarity_vs|\
  61. tli_struct->signalpolarity_de|tli_struct->signalpolarity_pixelck);
  62. }
  63. /*!
  64. \brief dither function configure
  65. \param[in] ditherstat: TLI_DITHER_ENABLE,TLI_DITHER_DISABLE
  66. \param[out] none
  67. \retval none
  68. */
  69. void tli_dither_config(uint8_t ditherstat)
  70. {
  71. if(TLI_DITHER_ENABLE == ditherstat){
  72. TLI_CTL |= TLI_CTL_DFEN;
  73. }else{
  74. TLI_CTL &= ~(TLI_CTL_DFEN);
  75. }
  76. }
  77. /*!
  78. \brief TLI enable
  79. \param[in] none.
  80. \param[out] none
  81. \retval none
  82. */
  83. void tli_enable(void)
  84. {
  85. TLI_CTL |= TLI_CTL_TLIEN;
  86. }
  87. /*!
  88. \brief TLI disable
  89. \param[in] none.
  90. \param[out] none
  91. \retval none
  92. */
  93. void tli_disable(void)
  94. {
  95. TLI_CTL &= ~(TLI_CTL_DFEN);
  96. }
  97. /*!
  98. \brief TLI reload layer configure
  99. \param[in] reloadmod: TLI_FRAME_BLANK_RELOAD_EN,TLI_REQUEST_RELOAD_EN
  100. \param[out] none
  101. \retval none
  102. */
  103. void tli_reload_config(uint8_t reloadmod)
  104. {
  105. if(TLI_FRAME_BLANK_RELOAD_EN == reloadmod){
  106. TLI_RL |= TLI_RL_FBR;
  107. }else{
  108. TLI_RL |= TLI_RL_RQR;
  109. }
  110. }
  111. /*!
  112. \brief TLI interrupt enable
  113. \param[in] inttype: TLI interrupt bits.
  114. \arg TLI_INTEN_LMIE: line mark interrupt
  115. \arg TLI_INTEN_FEIE: FIFO error interrupt
  116. \arg TLI_INTEN_TEIE: transaction error interrupt
  117. \arg TLI_INTEN_LCRIE: layer configuration reloaded interrupt
  118. \param[out] none
  119. \retval none
  120. */
  121. void tli_interrupt_enable(uint32_t inttype)
  122. {
  123. TLI_INTEN |= (inttype);
  124. }
  125. /*!
  126. \brief TLI interrupt disable
  127. \param[in] inttype: TLI interrupt bits.
  128. \arg TLI_INTEN_LMIE: line mark interrupt
  129. \arg TLI_INTEN_FEIE: FIFO error interrupt
  130. \arg TLI_INTEN_TEIE: transaction error interrupt
  131. \arg TLI_INTEN_LCRIE: layer configuration reloaded interrupt
  132. \param[out] none
  133. \retval none
  134. */
  135. void tli_interrupt_disable(uint32_t inttype)
  136. {
  137. TLI_INTEN &= ~(inttype);
  138. }
  139. /*!
  140. \brief get TLI interrupt flag
  141. \param[in] intflag: TLI interrupt flag bits.
  142. \arg TLI_INTF_LMF: line mark flag
  143. \arg TLI_INTF_FEF: FIFO error flag
  144. \arg TLI_INTF_TEF: transaction error flag
  145. \arg TLI_INTF_LCRF: layer configuration reloaded flag
  146. \param[out] none
  147. \retval none
  148. */
  149. FlagStatus tli_interrupt_flag_get(uint32_t intflag)
  150. {
  151. uint32_t state;
  152. state = TLI_INTF;
  153. if(state & intflag){
  154. return SET;
  155. }else{
  156. return RESET;
  157. }
  158. }
  159. /*!
  160. \brief clear TLI interrupt flag
  161. \param[in] intflag: TLI interrupt flag bits.
  162. \arg TLI_INTC_LMC: line mark flag
  163. \arg TLI_INTC_FEC: FIFO error flag
  164. \arg TLI_INTC_TEC: transaction error flag
  165. \arg TLI_INTC_LCRC: layer configuration reloaded flag
  166. \param[out] none
  167. \retval none
  168. */
  169. void tli_interrupt_flag_clear(uint32_t intflag)
  170. {
  171. TLI_INTC |= (intflag);
  172. }
  173. /*!
  174. \brief set line mark value
  175. \param[in] linenum: line number.
  176. \param[out] none
  177. \retval none
  178. */
  179. void tli_line_mark_set(uint32_t linenum)
  180. {
  181. TLI_LM &= ~(TLI_LM_LM);
  182. TLI_LM = linenum;
  183. }
  184. /*!
  185. \brief get current displayed position
  186. \param[in] none
  187. \param[out] none
  188. \retval none
  189. */
  190. uint32_t tli_current_pos_get(void)
  191. {
  192. return TLI_CPPOS;
  193. }
  194. /*!
  195. \brief get TLI state
  196. \param[in] state: TLI state.
  197. \arg TLI_STAT_VDE: current VDE state
  198. \arg TLI_STAT_HDE: current HDE state
  199. \arg TLI_STAT_VS: current vs state
  200. \arg TLI_STAT_HS: current hs state
  201. \param[out] none
  202. \retval none
  203. */
  204. FlagStatus tli_flag_get(uint32_t state)
  205. {
  206. uint32_t stat;
  207. stat = TLI_STAT;
  208. if(state & stat){
  209. return SET;
  210. }else{
  211. return RESET;
  212. }
  213. }
  214. /*!
  215. \brief TLI layer enable
  216. \param[in] layerx: LAYERx(x=0,1).
  217. \param[out] none
  218. \retval none
  219. */
  220. void tli_layer_enable(uint32_t layerx)
  221. {
  222. TLI_LxCTL(layerx) |= TLI_LxCTL_LEN;
  223. }
  224. /*!
  225. \brief TLI layer disable
  226. \param[in] layerx: LAYERx(x=0,1).
  227. \param[out] none
  228. \retval none
  229. */
  230. void tli_layer_disable(uint32_t layerx)
  231. {
  232. TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LEN);
  233. }
  234. /*!
  235. \brief TLI layer color keying enable
  236. \param[in] layerx: LAYERx(x=0,1).
  237. \param[out] none
  238. \retval none
  239. */
  240. void tli_color_key_enable(uint32_t layerx)
  241. {
  242. TLI_LxCTL(layerx) |= TLI_LxCTL_CKEYEN;
  243. }
  244. /*!
  245. \brief TLI layer color keying disable
  246. \param[in] layerx: LAYERx(x=0,1).
  247. \param[out] none
  248. \retval none
  249. */
  250. void tli_color_key_disable(uint32_t layerx)
  251. {
  252. TLI_LxCTL(layerx) &= ~(TLI_LxCTL_CKEYEN);
  253. }
  254. /*!
  255. \brief TLI layer LUT enable
  256. \param[in] layerx: LAYERx(x=0,1).
  257. \param[out] none
  258. \retval none
  259. */
  260. void tli_lut_enable(uint32_t layerx)
  261. {
  262. TLI_LxCTL(layerx) |= TLI_LxCTL_LUTEN;
  263. }
  264. /*!
  265. \brief TLI layer LUT disable
  266. \param[in] layerx: LAYERx(x=0,1).
  267. \param[out] none
  268. \retval none
  269. */
  270. void tli_lut_disable(uint32_t layerx)
  271. {
  272. TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LUTEN);
  273. }
  274. /*!
  275. \brief TLI layer initialize
  276. \param[in] layerx: LAYERx(x=0,1)
  277. \param[in] layer_struct: TLI Layer parameter struct
  278. layer_window_rightpos: window right position
  279. layer_window_leftpos: window left position
  280. layer_window_bottompos: window bottom position
  281. layer_window_toppos: window top position
  282. layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
  283. LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
  284. LAYER_PPF_AL44,LAYER_PPF_AL88
  285. layer_sa: specified alpha
  286. layer_default_alpha: the default color alpha
  287. layer_default_red: the default color red
  288. layer_default_green: the default color green
  289. layer_default_blue: the default color blue
  290. layer_acf1: LAYER_ACF1_SA,LAYER_ACF1_PASA
  291. layer_acf2: LAYER_ACF2_SA,LAYER_ACF2_PASA
  292. layer_frame_bufaddr: frame buffer base address
  293. layer_frame_buf_stride_offset: frame buffer stride offset
  294. layer_frame_line_length: frame line length
  295. layer_frame_total_line_number: frame total line number
  296. \param[out] none
  297. \retval none
  298. */
  299. void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct)
  300. {
  301. /* configure layer window horizontal position */
  302. TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
  303. TLI_LxHPOS(layerx) = (layer_struct->layer_window_leftpos | (layer_struct->layer_window_rightpos<<16U));
  304. /* configure layer window vertical position */
  305. TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
  306. TLI_LxVPOS(layerx) = (layer_struct->layer_window_toppos |(layer_struct->layer_window_bottompos<<16U));
  307. /* configure layer packeted pixel format */
  308. TLI_LxPPF(layerx) &= ~(TLI_LxPPF_PPF);
  309. TLI_LxPPF(layerx) = layer_struct->layer_ppf;
  310. /* configure layer specified alpha */
  311. TLI_LxSA(layerx) &= ~(TLI_LxSA_SA);
  312. TLI_LxSA(layerx) = layer_struct->layer_sa;
  313. /* configure layer default color */
  314. TLI_LxDC(layerx) &= ~(TLI_LxDC_DCB|(TLI_LxDC_DCG)|(TLI_LxDC_DCR)|(TLI_LxDC_DCA));
  315. TLI_LxDC(layerx) = (layer_struct->layer_default_blue |(layer_struct->layer_default_green<<8U)
  316. |(layer_struct->layer_default_red<<16U)
  317. |(layer_struct->layer_default_alpha<<24U));
  318. /* configure layer alpha calculation factors */
  319. TLI_LxBLEND(layerx) &= ~(TLI_LxBLEND_ACF2|(TLI_LxBLEND_ACF1));
  320. TLI_LxBLEND(layerx) = ((layer_struct->layer_acf2)|(layer_struct->layer_acf1));
  321. /* configure layer frame buffer base address */
  322. TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
  323. TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
  324. /* configure layer frame line length */
  325. TLI_LxFLLEN(layerx) &= ~(TLI_LxFLLEN_FLL|(TLI_LxFLLEN_STDOFF));
  326. TLI_LxFLLEN(layerx) = (layer_struct->layer_frame_line_length|(layer_struct->layer_frame_buf_stride_offset<<16U));
  327. /* configure layer frame buffer base address */
  328. TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
  329. TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
  330. /* configure layer frame total line number */
  331. TLI_LxFTLN(layerx) &= ~(TLI_LxFTLN_FTLN);
  332. TLI_LxFTLN(layerx) = (layer_struct->layer_frame_total_line_number);
  333. }
  334. /*!
  335. \brief reconfigure window position
  336. \param[in] layerx: LAYERx(x=0,1).
  337. \param[in] offset_x: new horizontal offset .
  338. \param[in] offset_y: new vertical offset.
  339. \param[out] none
  340. \retval none
  341. */
  342. void tli_layer_window_offset_modify(uint32_t layerx,uint32_t offset_x,uint32_t offset_y)
  343. {
  344. /* configure window start position */
  345. uint32_t layer_ppf,line_length,line_num,hstart,vstart;
  346. TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
  347. TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
  348. hstart = offset_x+(((TLI_BPSZ & TLI_BPSZ_HBPSZ)>>16U)+1U);
  349. vstart = offset_y+((TLI_BPSZ & TLI_BPSZ_VBPSZ)+1U);
  350. line_num = (TLI_LxFTLN(layerx) & TLI_LxFTLN_FTLN);
  351. layer_ppf = (TLI_LxPPF(layerx) & TLI_LxPPF_PPF);
  352. /* the bytes of a line equal TLI_LxFLLEN_FLL bits value minus 3 */
  353. switch(layer_ppf){
  354. case LAYER_PPF_ARGB8888:
  355. /* each pixel includes 4bytes,when pixel format is ARGB8888 */
  356. line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/4U);
  357. break;
  358. case LAYER_PPF_RGB888:
  359. /* each pixel includes 3bytes,when pixel format is RGB888 */
  360. line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/3U);
  361. break;
  362. case LAYER_PPF_RGB565:
  363. case LAYER_PPF_ARGB1555:
  364. case LAYER_PPF_ARGB4444:
  365. case LAYER_PPF_AL88:
  366. /* each pixel includes 2bytes,when pixel format is RGB565,ARG1555,ARGB4444 or AL88 */
  367. line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/2U);
  368. break;
  369. case LAYER_PPF_L8:
  370. case LAYER_PPF_AL44:
  371. /* each pixel includes 1byte,when pixel format is L8 or AL44 */
  372. line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U));
  373. break;
  374. default:
  375. break;
  376. }
  377. /* reconfigure window position */
  378. TLI_LxHPOS(layerx) = (hstart|((hstart+line_length-1U)<<16U));
  379. TLI_LxVPOS(layerx) = (vstart|((vstart+line_num-1U)<<16U));
  380. }
  381. /*!
  382. \brief TLI layer lut initialize
  383. \param[in] layerx: LAYERx(x=0,1)
  384. \param[in] lut_struct: TLI layer LUT parameter struct
  385. layer_table_addr: window right position
  386. layer_lut_channel_red: window left position
  387. layer_window_bottompos: window bottom position
  388. layer_window_toppos: window top position
  389. \param[out] none
  390. \retval none
  391. */
  392. void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct)
  393. {
  394. TLI_LxLUT(layerx) &= ~(TLI_LxLUT_TB|TLI_LxLUT_TG|TLI_LxLUT_TR|TLI_LxLUT_TADD);
  395. TLI_LxLUT(layerx) = ((lut_struct->layer_lut_channel_blue)|(lut_struct->layer_lut_channel_green<<8)
  396. |(lut_struct->layer_lut_channel_red<<16
  397. |(lut_struct->layer_table_addr<<24)));
  398. }
  399. /*!
  400. \brief TLI layer key initialize
  401. \param[in] layerx: LAYERx(x=0,1).
  402. \param[in] redkey: color key red.
  403. \param[in] greenkey: color key green
  404. \param[in] bluekey: color key blue.
  405. \param[out] none
  406. \retval none
  407. */
  408. void tli_ckey_init(uint32_t layerx,uint32_t redkey,uint32_t greenkey,uint32_t bluekey)
  409. {
  410. TLI_LxCKEY(layerx) = ((bluekey)|(greenkey<<8U)|(redkey<<16U));
  411. }