gd32f4xx_tli.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*!
  2. \file gd32f4xx_tli.h
  3. \brief definitions for the TLI
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.1, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_TLI_H
  10. #define GD32F4XX_TLI_H
  11. #include "gd32f4xx.h"
  12. /* TLI definitions */
  13. #define TLI TLI_BASE /*!< TLI base address */
  14. /* TLI layer definitions */
  15. #define LAYER0 TLI_BASE /*!< Layer0 base address */
  16. #define LAYER1 (TLI_BASE+0x80) /*!< Layer1 base address */
  17. /* registers definitions */
  18. #define TLI_SPSZ REG32(TLI + 0x08U) /*!< TLI synchronous pulse size register */
  19. #define TLI_BPSZ REG32(TLI + 0x0CU) /*!< TLI back-porch size register */
  20. #define TLI_ASZ REG32(TLI + 0x10U) /*!< TLI active size register */
  21. #define TLI_TSZ REG32(TLI + 0x14U) /*!< TLI total size register */
  22. #define TLI_CTL REG32(TLI + 0x18U) /*!< TLI control register */
  23. #define TLI_RL REG32(TLI + 0x24U) /*!< TLI reload Layer register */
  24. #define TLI_BGC REG32(TLI + 0x2CU) /*!< TLI background color register */
  25. #define TLI_INTEN REG32(TLI + 0x34U) /*!< TLI interrupt enable register */
  26. #define TLI_INTF REG32(TLI + 0x38U) /*!< TLI interrupt flag register */
  27. #define TLI_INTC REG32(TLI + 0x3CU) /*!< TLI interrupt flag clear register */
  28. #define TLI_LM REG32(TLI + 0x40U) /*!< TLI line mark register */
  29. #define TLI_CPPOS REG32(TLI + 0x44U) /*!< TLI current pixel position register */
  30. #define TLI_STAT REG32(TLI + 0x48U) /*!< TLI status register */
  31. #define TLI_LxCTL(layerx) REG32((layerx) + 0x84U) /*!< TLI layer x control register */
  32. #define TLI_LxHPOS(layerx) REG32((layerx) + 0x88U) /*!< TLI layer x horizontal position parameters register */
  33. #define TLI_LxVPOS(layerx) REG32((layerx) + 0x8CU) /*!< TLI layer x vertical position parameters register */
  34. #define TLI_LxCKEY(layerx) REG32((layerx) + 0x90U) /*!< TLI layer x color key register */
  35. #define TLI_LxPPF(layerx) REG32((layerx) + 0x94U) /*!< TLI layer x packeted pixel format register */
  36. #define TLI_LxSA(layerx) REG32((layerx) + 0x98U) /*!< TLI layer x specified alpha register */
  37. #define TLI_LxDC(layerx) REG32((layerx) + 0x9CU) /*!< TLI layer x default color register */
  38. #define TLI_LxBLEND(layerx) REG32((layerx) + 0xA0U) /*!< TLI layer x blending register */
  39. #define TLI_LxFBADDR(layerx) REG32((layerx) + 0xACU) /*!< TLI layer x frame base address register */
  40. #define TLI_LxFLLEN(layerx) REG32((layerx) + 0xB0U) /*!< TLI layer x frame line length register */
  41. #define TLI_LxFTLN(layerx) REG32((layerx) + 0xB4U) /*!< TLI layer x frame total line number register */
  42. #define TLI_LxLUT(layerx) REG32((layerx) + 0xC4U) /*!< TLI ayer x Look Up Table register */
  43. /* bits definitions */
  44. /* TLI_SPSZ */
  45. #define TLI_SPSZ_VPSZ BITS(0,11) /*!< size of the vertical synchronous pulse */
  46. #define TLI_SPSZ_HPSZ BITS(16,27) /*!< size of the horizontal synchronous pulse */
  47. /* TLI_BPSZ */
  48. #define TLI_BPSZ_VBPSZ BITS(0,11) /*!< size of the vertical back porch plus synchronous pulse */
  49. #define TLI_BPSZ_HBPSZ BITS(16,27) /*!< size of the horizontal back porch plus synchronous pulse */
  50. /* TLI_ASZ */
  51. #define TLI_ASZ_VASZ BITS(0,11) /*!< size of the vertical active area width plus back porch and synchronous pulse */
  52. #define TLI_ASZ_HASZ BITS(16,27) /*!< size of the horizontal active area width plus back porch and synchronous pulse */
  53. /* TLI_SPSZ */
  54. #define TLI_TSZ_VTSZ BITS(0,11) /*!< vertical total size of the display, including active area, back porch, synchronous pulse and front porch */
  55. #define TLI_TSZ_HTSZ BITS(16,27) /*!< horizontal total size of the display, including active area, back porch, synchronous pulse and front porch */
  56. /* TLI_CTL */
  57. #define TLI_CTL_TLIEN BIT(0) /*!< TLI enable bit */
  58. #define TLI_CTL_BDB BITS(4,6) /*!< blue channel dither bits number */
  59. #define TLI_CTL_GDB BITS(8,10) /*!< green channel dither bits number */
  60. #define TLI_CTL_RDB BITS(12,14) /*!< red channel dither bits number */
  61. #define TLI_CTL_DFEN BIT(16) /*!< dither function enable */
  62. #define TLI_CTL_CLKPS BIT(28) /*!< pixel clock polarity selection */
  63. #define TLI_CTL_DEPS BIT(29) /*!< data enable polarity selection */
  64. #define TLI_CTL_VPPS BIT(30) /*!< vertical pulse polarity selection */
  65. #define TLI_CTL_HPPS BIT(31) /*!< horizontal pulse polarity selection */
  66. /* TLI_RL */
  67. #define TLI_RL_RQR BIT(0) /*!< request reload */
  68. #define TLI_RL_FBR BIT(1) /*!< frame blank reload */
  69. /* TLI_BGC */
  70. #define TLI_BGC_BVB BITS(0,7) /*!< background value blue */
  71. #define TLI_BGC_BVG BITS(8,15) /*!< background value green */
  72. #define TLI_BGC_BVR BITS(16,23) /*!< background value red */
  73. /* TLI_INTEN */
  74. #define TLI_INTEN_LMIE BIT(0) /*!< line mark interrupt enable */
  75. #define TLI_INTEN_FEIE BIT(1) /*!< FIFO error interrupt enable */
  76. #define TLI_INTEN_TEIE BIT(2) /*!< transaction error interrupt enable */
  77. #define TLI_INTEN_LCRIE BIT(3) /*!< layer configuration reloaded interrupt enable */
  78. /* TLI_INTF */
  79. #define TLI_INTF_LMF BIT(0) /*!< line mark flag */
  80. #define TLI_INTF_FEF BIT(1) /*!< FIFO error flag */
  81. #define TLI_INTF_TEF BIT(2) /*!< transaction error flag */
  82. #define TLI_INTF_LCRF BIT(3) /*!< layer configuration reloaded flag */
  83. /* TLI_INTC */
  84. #define TLI_INTC_LMC BIT(0) /*!< line mark flag clear */
  85. #define TLI_INTC_FEC BIT(1) /*!< FIFO error flag clear */
  86. #define TLI_INTC_TEC BIT(2) /*!< transaction error flag clear */
  87. #define TLI_INTC_LCRC BIT(3) /*!< layer configuration reloaded flag clear */
  88. /* TLI_LM */
  89. #define TLI_LM_LM BITS(0,10) /*!< line mark value */
  90. /* TLI_CPPOS */
  91. #define TLI_CPPOS_VPOS BITS(0,15) /*!< vertical position */
  92. #define TLI_CPPOS_HPOS BITS(16,31) /*!< horizontal position */
  93. /* TLI_STAT */
  94. #define TLI_STAT_VDE BIT(0) /*!< current VDE status */
  95. #define TLI_STAT_HDE BIT(1) /*!< current HDE status */
  96. #define TLI_STAT_VS BIT(2) /*!< current VS status of the TLI */
  97. #define TLI_STAT_HS BIT(3) /*!< current HS status of the TLI */
  98. /* TLI_LxCTL */
  99. #define TLI_LxCTL_LEN BIT(0) /*!< layer enable */
  100. #define TLI_LxCTL_CKEYEN BIT(1) /*!< color keying enable */
  101. #define TLI_LxCTL_LUTEN BIT(4) /*!< LUT enable */
  102. /* TLI_LxHPOS */
  103. #define TLI_LxHPOS_WLP BITS(0,11) /*!< window left position */
  104. #define TLI_LxHPOS_WRP BITS(16,27) /*!< window right position */
  105. /* TLI_LxVPOS */
  106. #define TLI_LxVPOS_WTP BITS(0,11) /*!< window top position */
  107. #define TLI_LxVPOS_WBP BITS(16,27) /*!< window bottom position */
  108. /* TLI_LxCKEY */
  109. #define TLI_LxCKEY_CKEYB BITS(0,7) /*!< color key blue */
  110. #define TLI_LxCKEY_CKEYG BITS(8,15) /*!< color key green */
  111. #define TLI_LxCKEY_CKEYR BITS(16,23) /*!< color key red */
  112. /* TLI_LxPPF */
  113. #define TLI_LxPPF_PPF BITS(0,2) /*!< packeted pixel format */
  114. /* TLI_LxSA */
  115. #define TLI_LxSA_SA BITS(0,7) /*!< specified alpha */
  116. /* TLI_LxDC */
  117. #define TLI_LxDC_DCB BITS(0,7) /*!< the default color blue */
  118. #define TLI_LxDC_DCG BITS(8,15) /*!< the default color green */
  119. #define TLI_LxDC_DCR BITS(16,23) /*!< the default color red */
  120. #define TLI_LxDC_DCA BITS(24,31) /*!< the default color alpha */
  121. /* TLI_LxBLEND */
  122. #define TLI_LxBLEND_ACF2 BITS(0,2) /*!< alpha calculation factor 2 of blending method */
  123. #define TLI_LxBLEND_ACF1 BITS(8,10) /*!< alpha calculation factor 1 of blending method */
  124. /* TLI_LxFBADDR */
  125. #define TLI_LxFBADDR_FBADD BITS(0,31) /*!< frame buffer base address */
  126. /* TLI_LxFLLEN */
  127. #define TLI_LxFLLEN_FLL BITS(0,12) /*!< frame line length */
  128. #define TLI_LxFLLEN_STDOFF BITS(16,28) /*!< frame buffer stride offset */
  129. /* TLI_LxFTLN */
  130. #define TLI_LxFTLN_FTLN BITS(0,10) /*!< frame total line number */
  131. /* TLI_LxLUT */
  132. #define TLI_LxLUT_TB BITS(0,7) /*!< blue channel of a LUT entry */
  133. #define TLI_LxLUT_TG BITS(8,15) /*!< green channel of a LUT entry */
  134. #define TLI_LxLUT_TR BITS(16,23) /*!< red channel of a LUT entry */
  135. #define TLI_LxLUT_TADD BITS(24,31) /*!< look up table write address */
  136. /* constants definitions */
  137. /* TLI parameter struct definitions */
  138. typedef struct
  139. {
  140. uint32_t synpsz_vpsz; /*!< size of the vertical synchronous pulse */
  141. uint32_t synpsz_hpsz; /*!< size of the horizontal synchronous pulse */
  142. uint32_t backpsz_vbpsz; /*!< size of the vertical back porch plus synchronous pulse */
  143. uint32_t backpsz_hbpsz; /*!< size of the horizontal back porch plus synchronous pulse */
  144. uint32_t activesz_vasz; /*!< size of the vertical active area width plus back porch and synchronous pulse */
  145. uint32_t activesz_hasz; /*!< size of the horizontal active area width plus back porch and synchronous pulse */
  146. uint32_t totalsz_vtsz; /*!< vertical total size of the display */
  147. uint32_t totalsz_htsz; /*!< horizontal total size of the display */
  148. uint32_t backcolor_red; /*!< background value red */
  149. uint32_t backcolor_green; /*!< background value green */
  150. uint32_t backcolor_blue; /*!< background value blue */
  151. uint32_t signalpolarity_hs; /*!< horizontal pulse polarity selection */
  152. uint32_t signalpolarity_vs; /*!< vertical pulse polarity selection */
  153. uint32_t signalpolarity_de; /*!< data enable polarity selection */
  154. uint32_t signalpolarity_pixelck; /*!< pixel clock polarity selection */
  155. }tli_parameter_struct;
  156. /* TLI Layer parameter struct definitions */
  157. typedef struct
  158. {
  159. uint32_t layer_window_rightpos; /*!< window right position */
  160. uint32_t layer_window_leftpos; /*!< window left position */
  161. uint32_t layer_window_bottompos; /*!< window bottom position */
  162. uint32_t layer_window_toppos; /*!< window top position */
  163. uint32_t layer_ppf; /*!< packeted pixel format */
  164. uint32_t layer_sa; /*!< specified alpha */
  165. uint32_t layer_default_alpha; /*!< the default color alpha */
  166. uint32_t layer_default_red; /*!< the default color red */
  167. uint32_t layer_default_green; /*!< the default color green */
  168. uint32_t layer_default_blue; /*!< the default color blue */
  169. uint32_t layer_acf1; /*!< alpha calculation factor 1 of blending method */
  170. uint32_t layer_acf2; /*!< alpha calculation factor 2 of blending method */
  171. uint32_t layer_frame_bufaddr; /*!< frame buffer base address */
  172. uint32_t layer_frame_buf_stride_offset; /*!< frame buffer stride offset */
  173. uint32_t layer_frame_line_length; /*!< frame line length */
  174. uint32_t layer_frame_total_line_number; /*!< frame total line number */
  175. }tli_layer_parameter_struct;
  176. /* TLI layer LUT parameter struct definitions */
  177. typedef struct
  178. {
  179. uint32_t layer_table_addr; /*!< look up table write address */
  180. uint32_t layer_lut_channel_red; /*!< red channel of a LUT entry */
  181. uint32_t layer_lut_channel_green; /*!< green channel of a LUT entry */
  182. uint32_t layer_lut_channel_blue; /*!< blue channel of a LUT entry */
  183. }tli_layer_lut_parameter_struct;
  184. /* packeted pixel format */
  185. typedef enum
  186. {
  187. LAYER_PPF_ARGB8888, /*!< layerx pixel format ARGB8888 */
  188. LAYER_PPF_RGB888, /*!< layerx pixel format RGB888 */
  189. LAYER_PPF_RGB565, /*!< layerx pixel format RGB565 */
  190. LAYER_PPF_ARGB1555, /*!< layerx pixel format ARGB1555 */
  191. LAYER_PPF_ARGB4444, /*!< layerx pixel format ARGB4444 */
  192. LAYER_PPF_L8, /*!< layerx pixel format L8 */
  193. LAYER_PPF_AL44, /*!< layerx pixel format AL44 */
  194. LAYER_PPF_AL88 /*!< layerx pixel format AL88 */
  195. } tli_layer_ppf_enum;
  196. /* layer reload configure */
  197. #define TLI_FRAME_BLANK_RELOAD_EN ((uint8_t)0x00U) /*!< the layer configuration will be reloaded at frame blank */
  198. #define TLI_REQUEST_RELOAD_EN ((uint8_t)0x01U) /*!< the layer configuration will be reloaded after this bit sets */
  199. /* dither Function */
  200. #define TLI_DITHER_DISABLE ((uint8_t)0x00U) /*!< dither function disable */
  201. #define TLI_DITHER_ENABLE ((uint8_t)0x01U) /*!< dither function enable */
  202. /* horizontal pulse polarity selection */
  203. #define TLI_HSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< horizontal synchronous pulse active low */
  204. #define TLI_HSYN_ACTLIVE_HIGHT TLI_CTL_HPPS /*!< horizontal synchronous pulse active high */
  205. /* vertical pulse polarity selection */
  206. #define TLI_VSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< vertical synchronous pulse active low */
  207. #define TLI_VSYN_ACTLIVE_HIGHT TLI_CTL_VPPS /*!< vertical synchronous pulse active high */
  208. /* pixel Clock Polarity Selection */
  209. #define TLI_PIXEL_CLOCK_TLI ((uint32_t)0x00000000U) /*!< pixel clock is TLI clock */
  210. #define TLI_PIXEL_CLOCK_INVERTEDTLI TLI_CTL_CLKPS /*!< pixel clock is inverted TLI clock */
  211. /* data Enable Polarity Selection */
  212. #define TLI_DE_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< data enable active low */
  213. #define TLI_DE_ACTLIVE_HIGHT TLI_CTL_DEPS /*!< data enable active high */
  214. /* alpha calculation factor 1 of blending method */
  215. #define LxBLEND_ACF1(regval) (BITS(8,10) & ((regval)<<8))
  216. #define LAYER_ACF1_SA LxBLEND_ACF1(4) /*!< normalization specified alpha */
  217. #define LAYER_ACF1_PASA LxBLEND_ACF1(6) /*!< normalization pixel alpha * normalization specified alpha */
  218. /* alpha calculation factor 2 of blending method*/
  219. #define LxBLEND_ACF2(regval) (BITS(0,2) & ((regval)))
  220. #define LAYER_ACF2_SA LxBLEND_ACF2(5) /*!< normalization specified alpha */
  221. #define LAYER_ACF2_PASA LxBLEND_ACF2(7) /*!< normalization pixel alpha x normalization specified alpha */
  222. /* function declarations */
  223. /* deinitialize TLI */
  224. void tli_deinit(void);
  225. /* initialize TLI */
  226. void tli_init(tli_parameter_struct *tli_struct);
  227. /* TLI dither function enable */
  228. void tli_dither_config(uint8_t ditherstat);
  229. /* enable TLI */
  230. void tli_enable(void);
  231. /* disable TLI */
  232. void tli_disable(void);
  233. /* TLI reload mode config*/
  234. void tli_reload_config(uint8_t reloadmod);
  235. /* TLI interrupt enable */
  236. void tli_interrupt_enable(uint32_t inttype);
  237. /* TLI interrupt disable */
  238. void tli_interrupt_disable(uint32_t inttype);
  239. /* get TLI interrupt flag */
  240. FlagStatus tli_interrupt_flag_get(uint32_t intflag);
  241. /* clear TLI interrupt flag */
  242. void tli_interrupt_flag_clear(uint32_t intflag);
  243. /* set line mark value */
  244. void tli_line_mark_set(uint32_t linenum);
  245. /* get current displayed position */
  246. uint32_t tli_current_pos_get(void);
  247. /* get TLI state */
  248. FlagStatus tli_flag_get(uint32_t state);
  249. /* TLI layer enable */
  250. void tli_layer_enable(uint32_t layerx);
  251. /* TLI layer disable */
  252. void tli_layer_disable(uint32_t layerx);
  253. /* TLI layer color keying enable */
  254. void tli_color_key_enable(uint32_t layerx);
  255. /* TLI layer color keying disable */
  256. void tli_color_key_disable(uint32_t layerx);
  257. /* TLI layer LUT enable */
  258. void tli_lut_enable(uint32_t layerx);
  259. /* TLI layer LUT disable */
  260. void tli_lut_disable(uint32_t layerx);
  261. /* TLI layer initialize */
  262. void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct);
  263. /* TLI layer initialize */
  264. void tli_layer_window_offset_modify(uint32_t layerx,uint32_t offset_x,uint32_t offset_y);
  265. /* TLI layer lut initialize */
  266. void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct);
  267. /* TLI layer key initialize */
  268. void tli_ckey_init(uint32_t layerx,uint32_t redkey,uint32_t greenkey,uint32_t bluekey);
  269. #endif /* GD32F4XX_TLI_H */