gd32f4xx_ipa.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*!
  2. \file gd32f4xx_ipa.h
  3. \brief definitions for the IPA
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_IPA_H
  10. #define GD32F4XX_IPA_H
  11. #include "gd32f4xx.h"
  12. /* TLI definitions */
  13. #define IPA IPA_BASE /*!< IPA base address */
  14. /* bits definitions */
  15. /* registers definitions */
  16. #define IPA_CTL REG32(IPA + 0x00U) /*!< IPA control register */
  17. #define IPA_INTF REG32(IPA + 0x04U) /*!< IPA interrupt flag register */
  18. #define IPA_INTC REG32(IPA + 0x08U) /*!< IPA interrupt flag clear register */
  19. #define IPA_FMADDR REG32(IPA + 0x0CU) /*!< IPA foreground memory base address register */
  20. #define IPA_FLOFF REG32(IPA + 0x10U) /*!< IPA foreground line offset register */
  21. #define IPA_BMADDR REG32(IPA + 0x14U) /*!< IPA background memory base address register */
  22. #define IPA_BLOFF REG32(IPA + 0x18U) /*!< IPA background line offset register */
  23. #define IPA_FPCTL REG32(IPA + 0x1CU) /*!< IPA foreground pixel control register */
  24. #define IPA_FPV REG32(IPA + 0x20U) /*!< IPA foreground pixel value register */
  25. #define IPA_BPCTL REG32(IPA + 0x24U) /*!< IPA background pixel control register */
  26. #define IPA_BPV REG32(IPA + 0x28U) /*!< IPA background pixel value register */
  27. #define IPA_FLMADDR REG32(IPA + 0x2CU) /*!< IPA foreground LUT memory base address register */
  28. #define IPA_BLMADDR REG32(IPA + 0x30U) /*!< IPA background LUT memory base address register */
  29. #define IPA_DPCTL REG32(IPA + 0x34U) /*!< IPA destination pixel control register */
  30. #define IPA_DPV REG32(IPA + 0x38U) /*!< IPA destination pixel value register */
  31. #define IPA_DMADDR REG32(IPA + 0x3CU) /*!< IPA destination memory base address register */
  32. #define IPA_DLOFF REG32(IPA + 0x40U) /*!< IPA destination line offset register */
  33. #define IPA_IMS REG32(IPA + 0x44U) /*!< IPA image size register */
  34. #define IPA_LM REG32(IPA + 0x48U) /*!< IPA line mark register */
  35. #define IPA_ITCTL REG32(IPA + 0x4CU) /*!< IPA inter-timer control register */
  36. /* IPA_CTL */
  37. #define IPA_CTL_TEN BIT(0) /*!< transfer enable */
  38. #define IPA_CTL_THU BIT(1) /*!< transfer hang up */
  39. #define IPA_CTL_TST BIT(2) /*!< transfer stop */
  40. #define IPA_CTL_TAEIE BIT(8) /*!< enable bit for transfer access error interrupt */
  41. #define IPA_CTL_FTFIE BIT(9) /*!< enable bit for full transfer finish interrup */
  42. #define IPA_CTL_TLMIE BIT(10) /*!< enable bit for transfer line mark interrupt */
  43. #define IPA_CTL_LACIE BIT(11) /*!< enable bit for LUT access conflict interrupt */
  44. #define IPA_CTL_LLFIE BIT(12) /*!< enable bit for LUT loading finish interrupt */
  45. #define IPA_CTL_WCFIE BIT(13) /*!< enable bit for wrong configuration interrupt */
  46. #define IPA_CTL_PFCM BITS(16,17) /*!< pixel format convert mode */
  47. /* IPA_INTF */
  48. #define IPA_INTF_TAEIF BIT(0) /*!< transfer access error interrupt flag */
  49. #define IPA_INTF_FTFIF BIT(1) /*!< full transfer finish interrupt flag */
  50. #define IPA_INTF_TLMIF BIT(2) /*!< transfer line mark interrupt flag */
  51. #define IPA_INTF_LACIF BIT(3) /*!< LUT access conflict interrupt flag */
  52. #define IPA_INTF_LLFIF BIT(4) /*!< LUT loading finish interrupt flag */
  53. #define IPA_INTF_WCFIF BIT(5) /*!< wrong configuration interrupt flag */
  54. /* IPA_INTC */
  55. #define IPA_INTC_TAEIFC BIT(0) /*!< clear bit for transfer access error interrupt flag */
  56. #define IPA_INTC_FTFIFC BIT(1) /*!< clear bit for full transfer finish interrupt flag */
  57. #define IPA_INTC_TLMIFC BIT(2) /*!< clear bit for transfer line mark interrupt flag */
  58. #define IPA_INTC_LACIFC BIT(3) /*!< clear bit for LUT access conflict interrupt flag */
  59. #define IPA_INTC_LLFIFC BIT(4) /*!< clear bit for LUT loading finish interrupt flag */
  60. #define IPA_INTC_WCFIFC BIT(5) /*!< clear bit for wrong configuration interrupt flag */
  61. /* IPA_FMADDR */
  62. #define IPA_FMADDR_FMADDR BITS(0,31) /*!< foreground memory base address */
  63. /* IPA_FLOFF */
  64. #define IPA_FLOFF_FLOFF BITS(0,13) /*!< foreground line offset */
  65. /* IPA_BMADDR */
  66. #define IPA_BMADDR_BMADDR BITS(0,31) /*!< background memory base address */
  67. /* IPA_BLOFF */
  68. #define IPA_BLOFF_BLOFF BITS(0,13) /*!< background line offset */
  69. /* IPA_FPCTL */
  70. #define IPA_FPCTL_FPF BITS(0,3) /*!< foreground pixel format */
  71. #define IPA_FPCTL_FLPF BIT(4) /*!< foreground LUT pixel format */
  72. #define IPA_FPCTL_FLLEN BIT(5) /*!< foreground LUT loading enable */
  73. #define IPA_FPCTL_FCNP BITS(8,15) /*!< foreground LUT number of pixel */
  74. #define IPA_FPCTL_FAVCA BITS(16,17) /*!< foreground alpha value calculation algorithm */
  75. #define IPA_FPCTL_FPDAV BITS(24,31) /*!< foreground pre- defined alpha value */
  76. /* IPA_FPV */
  77. #define IPA_FPV_FPDBV BITS(0,7) /*!< foreground pre-defined red value */
  78. #define IPA_FPV_FPDGV BITS(8,15) /*!< foreground pre-defined green value */
  79. #define IPA_FPV_FPDRV BITS(16,23) /*!< foreground pre-defined red value */
  80. /* IPA_BPCTL */
  81. #define IPA_BPCTL_BPF BITS(0,3) /*!< background pixel format */
  82. #define IPA_BPCTL_BLPF BIT(4) /*!< background LUT pixel format */
  83. #define IPA_BPCTL_BLLEN BIT(5) /*!< background LUT loading enable */
  84. #define IPA_BPCTL_BCNP BITS(8,15) /*!< background LUT number of pixel */
  85. #define IPA_BPCTL_BAVCA BITS(16,17) /*!< background alpha value calculation algorithm */
  86. #define IPA_BPCTL_BPDAV BITS(24,31) /*!< background pre- defined alpha value */
  87. /* IPA_BPV */
  88. #define IPA_BPV_BPDBV BITS(0,7) /*!< background pre-defined blue value */
  89. #define IPA_BPV_BPDGV BITS(8,15) /*!< background pre-defined green value */
  90. #define IPA_BPV_BPDRV BITS(16,23) /*!< background pre-defined red value */
  91. /* IPA_FLMADDR */
  92. #define IPA_FLMADDR_FLMADDR BITS(0,31) /*!< foreground LUT memory base address */
  93. /* IPA_BLMADDR */
  94. #define IPA_BLMADDR_BLMADDR BITS(0,31) /*!< background LUT memory base address */
  95. /* IPA_DPCTL */
  96. #define IPA_DPCTL_DPF BITS(0,2) /*!< destination pixel control register */
  97. /* IPA_DPV */
  98. /* destination pixel format ARGB8888 */
  99. #define IPA_DPV_DPDBV_0 BITS(0,7) /*!< destination pre-defined blue value */
  100. #define IPA_DPV_DPDGV_0 BITS(8,15) /*!< destination pre-defined green value */
  101. #define IPA_DPV_DPDRV_0 BITS(16,23) /*!< destination pre-defined red value */
  102. #define IPA_DPV_DPDAV_0 BITS(24,31) /*!< destination pre-defined alpha value */
  103. /* destination pixel format RGB8888 */
  104. #define IPA_DPV_DPDBV_1 BITS(0,7) /*!< destination pre-defined blue value */
  105. #define IPA_DPV_DPDGV_1 BITS(8,15) /*!< destination pre-defined green value */
  106. #define IPA_DPV_DPDRV_1 BITS(16,23) /*!< destination pre-defined red value */
  107. /* destination pixel format RGB565 */
  108. #define IPA_DPV_DPDBV_2 BITS(0,4) /*!< destination pre-defined blue value */
  109. #define IPA_DPV_DPDGV_2 BITS(5,10) /*!< destination pre-defined green value */
  110. #define IPA_DPV_DPDRV_2 BITS(11,15) /*!< destination pre-defined red value */
  111. /* destination pixel format ARGB1555 */
  112. #define IPA_DPV_DPDBV_3 BITS(0,4) /*!< destination pre-defined blue value */
  113. #define IPA_DPV_DPDGV_3 BITS(5,9) /*!< destination pre-defined green value */
  114. #define IPA_DPV_DPDRV_3 BITS(10,14) /*!< destination pre-defined red value */
  115. #define IPA_DPV_DPDAV_3 BIT(15) /*!< destination pre-defined alpha value */
  116. /* destination pixel format ARGB4444 */
  117. #define IPA_DPV_DPDBV_4 BITS(0,3) /*!< destination pre-defined blue value */
  118. #define IPA_DPV_DPDGV_4 BITS(4,7) /*!< destination pre-defined green value */
  119. #define IPA_DPV_DPDRV_4 BITS(8,11) /*!< destination pre-defined red value */
  120. #define IPA_DPV_DPDAV_4 BITS(12,15) /*!< destination pre-defined alpha value */
  121. /* IPA_DMADDR */
  122. #define IPA_DMADDR_DMADDR BITS(0,31) /*!< destination memory base address */
  123. /* IPA_DLOFF */
  124. #define IPA_DLOFF_DLOFF BITS(0,13) /*!< destination line offset */
  125. /* IPA_IMS */
  126. #define IPA_IMS_HEIGHT BITS(0,15) /*!< height of the image to be processed */
  127. #define IPA_IMS_WIDTH BITS(16,29) /*!< width of the image to be processed */
  128. /* IPA_LM */
  129. #define IPA_LM_LM BITS(0,15) /*!< line mark */
  130. /* IPA_ITCTL */
  131. #define IPA_ITCTL_ITEN BIT(0) /*!< inter-timer enable */
  132. #define IPA_ITCTL_NCCI BITS(8,15) /*!< number of clock cycles interval */
  133. /* constants definitions */
  134. /* IPA foreground parameter struct definitions */
  135. typedef struct
  136. {
  137. uint32_t foreground_memaddr; /*!< foreground memory base address */
  138. uint32_t foreground_lineoff; /*!< foreground line offset */
  139. uint32_t foreground_prealpha; /*!< foreground pre-defined alpha value */
  140. uint32_t foreground_alpha_algorithm; /*!< foreground alpha value calculation algorithm */
  141. uint32_t foreground_pf; /*!< foreground pixel format */
  142. uint32_t foreground_prered; /*!< foreground pre-defined red value */
  143. uint32_t foreground_pregreen; /*!< foreground pre-defined green value */
  144. uint32_t foreground_preblue; /*!< foreground pre-defined blue value */
  145. }ipa_foreground_parameter_struct;
  146. /* IPA background parameter struct definitions */
  147. typedef struct
  148. {
  149. uint32_t background_memaddr; /*!< background memory base address */
  150. uint32_t background_lineoff; /*!< background line offset */
  151. uint32_t background_prealpha; /*!< background pre-defined alpha value */
  152. uint32_t background_alpha_algorithm; /*!< background alpha value calculation algorithm */
  153. uint32_t background_pf; /*!< background pixel format */
  154. uint32_t background_prered; /*!< background pre-defined red value */
  155. uint32_t background_pregreen; /*!< background pre-defined green value */
  156. uint32_t background_preblue; /*!< background pre-defined blue value */
  157. }ipa_background_parameter_struct;
  158. /* IPA destination parameter struct definitions */
  159. typedef struct
  160. {
  161. uint32_t destination_memaddr; /*!< destination memory base address */
  162. uint32_t destination_lineoff; /*!< destination line offset */
  163. uint32_t destination_prealpha; /*!< destination pre-defined alpha value */
  164. uint32_t destination_pf; /*!< destination pixel format */
  165. uint32_t destination_prered; /*!< destination pre-defined red value */
  166. uint32_t destination_pregreen; /*!< destination pre-defined green value */
  167. uint32_t destination_preblue; /*!< destination pre-defined blue value */
  168. uint32_t image_width; /*!< width of the image to be processed */
  169. uint32_t image_height; /*!< height of the image to be processed */
  170. }ipa_destination_parameter_struct;
  171. /* destination pixel format */
  172. typedef enum
  173. {
  174. IPA_DPF_ARGB8888, /*!< destination pixel format ARGB8888 */
  175. IPA_DPF_RGB888, /*!< destination pixel format RGB888 */
  176. IPA_DPF_RGB565, /*!< destination pixel format RGB565 */
  177. IPA_DPF_ARGB1555, /*!< destination pixel format ARGB1555 */
  178. IPA_DPF_ARGB4444 /*!< destination pixel format ARGB4444 */
  179. } ipa_dpf_enum;
  180. /* LUT pixel format */
  181. #define IPA_LUT_PF_ARGB8888 ((uint8_t)0x00U) /*!< LUT pixel format ARGB8888 */
  182. #define IPA_LUT_PF_RGB888 ((uint8_t)0x01U) /*!< LUT pixel format RGB888 */
  183. /* Inter-timer */
  184. #define IPA_INTER_TIMER_DISABLE ((uint8_t)0x00U) /*!< Inter-timer disable */
  185. #define IPA_INTER_TIMER_ENABLE ((uint8_t)0x01U) /*!< Inter-timer enable */
  186. /* IPA pixel format convert mode */
  187. #define CTL_PFCM(regval) (BITS(16,17) & ((regval) << 16))
  188. #define IPA_FGTODE CTL_PFCM(0) /*!< foreground memory to destination memory without pixel format convert */
  189. #define IPA_FGTODE_PF_CONVERT CTL_PFCM(1) /*!< foreground memory to destination memory with pixel format convert */
  190. #define IPA_FGBGTODE CTL_PFCM(2) /*!< blending foreground and background memory to destination memory */
  191. #define IPA_FILL_UP_DE CTL_PFCM(3) /*!< fill up destination memory with specific color */
  192. /* foreground alpha value calculation algorithm */
  193. #define FPCTL_FAVCA(regval) (BITS(16,17) & ((regval) << 16))
  194. #define IPA_FG_ALPHA_MODE_0 FPCTL_FAVCA(0) /*!< no effect */
  195. #define IPA_FG_ALPHA_MODE_1 FPCTL_FAVCA(1) /*!< FPDAV[7:0] is selected as the foreground alpha value */
  196. #define IPA_FG_ALPHA_MODE_2 FPCTL_FAVCA(2) /*!< FPDAV[7:0] multiplied by read alpha value */
  197. /* background alpha value calculation algorithm */
  198. #define BPCTL_BAVCA(regval) (BITS(16,17) & ((regval) << 16))
  199. #define IPA_BG_ALPHA_MODE_0 BPCTL_BAVCA(0) /*!< no effect */
  200. #define IPA_BG_ALPHA_MODE_1 BPCTL_BAVCA(1) /*!< BPDAV[7:0] is selected as the background alpha value */
  201. #define IPA_BG_ALPHA_MODE_2 BPCTL_BAVCA(2) /*!< BPDAV[7:0] multiplied by read alpha value */
  202. /* foreground pixel format */
  203. #define FPCTL_PPF(regval) (BITS(0,3) & ((regval)))
  204. #define FOREGROUND_PPF_ARGB8888 FPCTL_PPF(0) /*!< foreground pixel format ARGB8888 */
  205. #define FOREGROUND_PPF_RGB888 FPCTL_PPF(1) /*!< foreground pixel format RGB888 */
  206. #define FOREGROUND_PPF_RGB565 FPCTL_PPF(2) /*!< foreground pixel format RGB565 */
  207. #define FOREGROUND_PPF_ARG1555 FPCTL_PPF(3) /*!< foreground pixel format ARGB1555 */
  208. #define FOREGROUND_PPF_ARGB4444 FPCTL_PPF(4) /*!< foreground pixel format ARGB4444 */
  209. #define FOREGROUND_PPF_L8 FPCTL_PPF(5) /*!< foreground pixel format L8 */
  210. #define FOREGROUND_PPF_AL44 FPCTL_PPF(6) /*!< foreground pixel format AL44 */
  211. #define FOREGROUND_PPF_AL88 FPCTL_PPF(7) /*!< foreground pixel format AL88 */
  212. #define FOREGROUND_PPF_L4 FPCTL_PPF(8) /*!< foreground pixel format L4 */
  213. #define FOREGROUND_PPF_A8 FPCTL_PPF(9) /*!< foreground pixel format A8 */
  214. #define FOREGROUND_PPF_A4 FPCTL_PPF(10) /*!< foreground pixel format A4 */
  215. /* background pixel format */
  216. #define BPCTL_PPF(regval) (BITS(0,3) & ((regval)))
  217. #define BACKGROUND_PPF_ARGB8888 BPCTL_PPF(0) /*!< background pixel format ARGB8888 */
  218. #define BACKGROUND_PPF_RGB888 BPCTL_PPF(1) /*!< background pixel format RGB888 */
  219. #define BACKGROUND_PPF_RGB565 BPCTL_PPF(2) /*!< background pixel format RGB565 */
  220. #define BACKGROUND_PPF_ARG1555 BPCTL_PPF(3) /*!< background pixel format ARGB1555 */
  221. #define BACKGROUND_PPF_ARGB4444 BPCTL_PPF(4) /*!< background pixel format ARGB4444 */
  222. #define BACKGROUND_PPF_L8 BPCTL_PPF(5) /*!< background pixel format L8 */
  223. #define BACKGROUND_PPF_AL44 BPCTL_PPF(6) /*!< background pixel format AL44 */
  224. #define BACKGROUND_PPF_AL88 BPCTL_PPF(7) /*!< background pixel format AL88 */
  225. #define BACKGROUND_PPF_L4 BPCTL_PPF(8) /*!< background pixel format L4 */
  226. #define BACKGROUND_PPF_A8 BPCTL_PPF(9) /*!< background pixel format A8 */
  227. #define BACKGROUND_PPF_A4 BPCTL_PPF(10) /*!< background pixel format A4 */
  228. /* function declarations */
  229. /* deinitialize IPA */
  230. void ipa_deinit(void);
  231. /* IPA transfer enable */
  232. void ipa_transfer_enable(void);
  233. /* IPA transfer hang up enable */
  234. void ipa_transfer_hangup_enable(void);
  235. /* IPA transfer hang up disable */
  236. void ipa_transfer_hangup_disable(void);
  237. /* IPA transfer stop enable */
  238. void ipa_transfer_stop_enable(void);
  239. /* IPA transfer stop disable */
  240. void ipa_transfer_stop_disable(void);
  241. /* IPA foreground LUT loading enable */
  242. void ipa_foreground_lut_loading_enable(void);
  243. /* IPA background LUT loading enable */
  244. void ipa_background_lut_loading_enable(void);
  245. /* IPA transfer enable */
  246. void ipa_pixel_format_convert_mod(uint32_t pfcm);
  247. /* initialize foreground parameters */
  248. void ipa_foreground_init(ipa_foreground_parameter_struct* foreground_struct);
  249. /* initialize background parameters */
  250. void ipa_background_init(ipa_background_parameter_struct* background_struct);
  251. /* initialize destination parameters */
  252. void ipa_destination_init(ipa_destination_parameter_struct* destination_struct);
  253. /* initialize IPA foreground LUT parameters */
  254. void ipa_foreground_lut_init(uint32_t fg_lut_num,uint8_t fg_lut_pf, uint32_t fg_lut_addr);
  255. /* initialize IPA background LUT parameters */
  256. void ipa_background_lut_init(uint32_t bg_lut_num,uint8_t bg_lut_pf, uint32_t bg_lut_addr);
  257. /* configure line mark */
  258. void ipa_line_mark_config(uint32_t linenum);
  259. /* Inter-timer enable or disable */
  260. void ipa_inter_timer_config(uint8_t timercfg);
  261. /* number of clock cycles interval set */
  262. void ipa_interval_clock_num_config(uint32_t clk_num );
  263. /* IPA interrupt enable */
  264. void ipa_interrupt_enable(uint32_t inttype);
  265. /* IPA interrupt disable */
  266. void ipa_interrupt_disable(uint32_t inttype);
  267. /* get IPA interrupt flag */
  268. FlagStatus ipa_interrupt_flag_get(uint32_t intflag);
  269. /* clear IPA interrupt flag */
  270. void ipa_interrupt_flag_clear(uint32_t intflag);
  271. #endif /* GD32F4XX_IPA_H */