gd32f4xx_ipa.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /*!
  2. \file gd32f4xx_ipa.c
  3. \brief IPA driver
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #include "gd32f4xx_ipa.h"
  10. /*!
  11. \brief deinitialize IPA registers
  12. \param[in] none
  13. \param[out] none
  14. \retval none
  15. */
  16. void ipa_deinit(void)
  17. {
  18. rcu_periph_reset_enable(RCU_IPAENRST);
  19. rcu_periph_reset_disable(RCU_IPAENRST);
  20. }
  21. /*!
  22. \brief IPA transfer enable
  23. \param[in] none
  24. \param[out] none
  25. \retval none
  26. */
  27. void ipa_transfer_enable(void)
  28. {
  29. IPA_CTL |= IPA_CTL_TEN;
  30. }
  31. /*!
  32. \brief IPA transfer hang up enable
  33. \param[in] none.
  34. \param[out] none
  35. \retval none
  36. */
  37. void ipa_transfer_hangup_enable(void)
  38. {
  39. IPA_CTL |= IPA_CTL_THU;
  40. }
  41. /*!
  42. \brief IPA transfer hang up disable
  43. \param[in] none.
  44. \param[out] none
  45. \retval none
  46. */
  47. void ipa_transfer_hangup_disable(void)
  48. {
  49. IPA_CTL &= ~(IPA_CTL_THU);
  50. }
  51. /*!
  52. \brief IPA transfer stop enable
  53. \param[in] none.
  54. \param[out] none
  55. \retval none
  56. */
  57. void ipa_transfer_stop_enable(void)
  58. {
  59. IPA_CTL |= IPA_CTL_TST;
  60. }
  61. /*!
  62. \brief IPA transfer stop disable
  63. \param[in] none.
  64. \param[out] none
  65. \retval none
  66. */
  67. void ipa_transfer_stop_disable(void)
  68. {
  69. IPA_CTL &= ~(IPA_CTL_TST);
  70. }
  71. /*!
  72. \brief IPA foreground LUT loading enable
  73. \param[in] none.
  74. \param[out] none
  75. \retval none
  76. */
  77. void ipa_foreground_lut_loading_enable(void)
  78. {
  79. IPA_FPCTL |= IPA_FPCTL_FLLEN;
  80. }
  81. /*!
  82. \brief IPA background LUT loading enable
  83. \param[in] none.
  84. \param[out] none
  85. \retval none
  86. */
  87. void ipa_background_lut_loading_enable(void)
  88. {
  89. IPA_BPCTL |= IPA_BPCTL_BLLEN;
  90. }
  91. /*!
  92. \brief Pixel format convert mode
  93. \param[in] pfcm:
  94. \arg IPA_FGTODE: foreground memory to destination memory without pixel format convert
  95. \arg IPA_FGTODE_PF_CONVERT: foreground memory to destination memory with pixel format convert
  96. \arg IPA_FGBGTODE: blending foreground and background memory to destination memory
  97. \arg IPA_FILL_UP_DE: fill up destination memory with specific color
  98. \param[out] none
  99. \retval none
  100. */
  101. void ipa_pixel_format_convert_mod(uint32_t pfcm)
  102. {
  103. IPA_CTL |= pfcm;
  104. }
  105. /*!
  106. \brief initialize foreground parameters
  107. \param[in] foreground_struct: the data needed to initialize fore.
  108. foreground_memaddr: foreground memory base address
  109. foreground_lineoff: foreground line offset
  110. foreground_prealpha: foreground pre-defined alpha value
  111. foreground_alpha_algorithm: IPA_FG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
  112. foreground_pf: foreground pixel format
  113. foreground_prered: foreground pre-defined red value
  114. foreground_pregreen: foreground pre-defined green value
  115. foreground_preblue: foreground pre-defined blue value
  116. \param[out] none
  117. \retval none
  118. */
  119. void ipa_foreground_init(ipa_foreground_parameter_struct* foreground_struct)
  120. {
  121. /* foreground memory base address configuration */
  122. IPA_FMADDR &= ~(IPA_FMADDR_FMADDR);
  123. IPA_FMADDR = foreground_struct->foreground_memaddr;
  124. /* foreground line offset configuration */
  125. IPA_FLOFF &= ~(IPA_FLOFF_FLOFF);
  126. IPA_FLOFF = foreground_struct->foreground_lineoff;
  127. /* foreground pixel format pre-defined alpha, alpha calculation algorithm configuration */
  128. IPA_FPCTL &= ~(IPA_FPCTL_FAVCA|IPA_FPCTL_FAVCA|IPA_FPCTL_FPF);
  129. IPA_FPCTL |= (foreground_struct->foreground_prealpha<<24U);
  130. IPA_FPCTL |= foreground_struct->foreground_alpha_algorithm;
  131. IPA_FPCTL |= foreground_struct->foreground_pf;
  132. /* foreground pre-defined red green blue configuration */
  133. IPA_FPV &= ~(IPA_FPV_FPDRV|IPA_FPV_FPDGV|IPA_FPV_FPDBV);
  134. IPA_FPV |= ((foreground_struct->foreground_prered<<16U)|(foreground_struct->foreground_pregreen<<8U)|(foreground_struct->foreground_preblue));
  135. }
  136. /*!
  137. \brief initialize background parameters
  138. \param[in] background_struct: the data needed to initialize fore.
  139. background_memaddr: background memory base address
  140. background_lineoff: background line offset
  141. background_prealpha: background pre-defined alpha value
  142. background_alpha_algorithm: IPA_BG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
  143. background_pf: background pixel format
  144. background_prered: background pre-defined red value
  145. background_pregreen: background pre-defined green value
  146. background_preblue: background pre-defined blue value
  147. \param[out] none
  148. \retval none
  149. */
  150. void ipa_background_init(ipa_background_parameter_struct* background_struct)
  151. {
  152. /* background memory base address configuration */
  153. IPA_BMADDR &= ~(IPA_BMADDR_BMADDR);
  154. IPA_BMADDR = background_struct->background_memaddr;
  155. /* background line offset configuration */
  156. IPA_BLOFF &= ~(IPA_BLOFF_BLOFF);
  157. IPA_BLOFF =background_struct->background_lineoff;
  158. /* background pixel format pre-defined alpha, alpha calculation algorithm configuration */
  159. IPA_BPCTL &= ~(IPA_BPCTL_BAVCA|IPA_BPCTL_BAVCA|IPA_BPCTL_BPF);
  160. IPA_BPCTL |= (background_struct->background_prealpha<<24U);
  161. IPA_BPCTL |= background_struct->background_alpha_algorithm;
  162. IPA_BPCTL |= background_struct->background_pf;
  163. /* background pre-defined red green blue configuration */
  164. IPA_BPV &= ~(IPA_BPV_BPDRV|IPA_BPV_BPDGV|IPA_BPV_BPDBV);
  165. IPA_BPV |= ((background_struct->background_prered<<16U)|(background_struct->background_pregreen<<8U)|(background_struct->background_preblue));
  166. }
  167. /*!
  168. \brief initialize destination parameters
  169. \param[in] destination_struct: the data needed to initialize tli.
  170. destination_pf: refer to ipa_dpf_enum
  171. destination_lineoff: destination line offset
  172. destination_prealpha: destination pre-defined alpha value
  173. destination_prered: destination pre-defined red value
  174. destination_pregreen: destination pre-defined green value
  175. destination_preblue: destination pre-defined blue value
  176. destination_memaddr: destination memory base address
  177. image_width: width of the image to be processed
  178. image_height: height of the image to be processed
  179. \param[out] none
  180. \retval none
  181. */
  182. void ipa_destination_init(ipa_destination_parameter_struct* destination_struct)
  183. {
  184. uint32_t destination_pixelformat;
  185. /* destination pixel format configuration */
  186. IPA_DPCTL &= ~(IPA_DPCTL_DPF);
  187. IPA_DPCTL = destination_struct->destination_pf;
  188. destination_pixelformat = destination_struct->destination_pf;
  189. /* destination pixel format ARGB8888 */
  190. switch(destination_pixelformat){
  191. case IPA_DPF_ARGB8888:
  192. IPA_DPV &= ~(IPA_DPV_DPDBV_0|(IPA_DPV_DPDGV_0)|(IPA_DPV_DPDRV_0)|(IPA_DPV_DPDAV_0));
  193. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<8U)
  194. |(destination_struct->destination_prered<<16U)
  195. |(destination_struct->destination_prealpha<<24U));
  196. break;
  197. /* destination pixel format RGB888 */
  198. case IPA_DPF_RGB888:
  199. IPA_DPV &= ~(IPA_DPV_DPDBV_1|(IPA_DPV_DPDGV_1)|(IPA_DPV_DPDRV_1));
  200. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<8U)
  201. |(destination_struct->destination_prered<<16U));
  202. break;
  203. /* destination pixel format RGB565 */
  204. case IPA_DPF_RGB565:
  205. IPA_DPV &= ~(IPA_DPV_DPDBV_2|(IPA_DPV_DPDGV_2)|(IPA_DPV_DPDRV_2));
  206. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<5U)
  207. |(destination_struct->destination_prered<<11U));
  208. break;
  209. /* destination pixel format ARGB1555 */
  210. case IPA_DPF_ARGB1555:
  211. IPA_DPV &= ~(IPA_DPV_DPDBV_3|(IPA_DPV_DPDGV_3)|(IPA_DPV_DPDRV_3)|(IPA_DPV_DPDAV_3));
  212. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<5U)
  213. |(destination_struct->destination_prered<<10U)
  214. |(destination_struct->destination_prealpha<<15U));
  215. break;
  216. /* destination pixel format ARGB4444 */
  217. case IPA_DPF_ARGB4444:
  218. IPA_DPV &= ~(IPA_DPV_DPDBV_4|(IPA_DPV_DPDGV_4)|(IPA_DPV_DPDRV_4)|(IPA_DPV_DPDAV_4));
  219. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<5U)
  220. |(destination_struct->destination_prered<<10U)
  221. |(destination_struct->destination_prealpha<<15U));
  222. break;
  223. default:
  224. break;
  225. }
  226. /* destination memory base address configuration */
  227. IPA_DMADDR &= ~(IPA_DMADDR_DMADDR);
  228. IPA_DMADDR =destination_struct->destination_memaddr;
  229. /* destination line offset configuration */
  230. IPA_DLOFF &= ~(IPA_DLOFF_DLOFF);
  231. IPA_DLOFF =destination_struct->destination_lineoff;
  232. /* image size configuration */
  233. IPA_IMS &= ~(IPA_IMS_HEIGHT|IPA_IMS_WIDTH);
  234. IPA_IMS |= ((destination_struct->image_width<<16)|(destination_struct->image_height));
  235. }
  236. /*!
  237. \brief initialize IPA foreground LUT parameters
  238. \param[in] fg_lut_num: foreground LUT number of pixel.
  239. \param[in] fg_lut_pf: foreground LUT pixel format,IPA_LUT_PF_ARGB8888,IPA_LUT_PF_RGB888.
  240. \param[in] fg_lut_addr: foreground LUT memory base address.
  241. \param[out] none
  242. \retval none
  243. */
  244. void ipa_foreground_lut_init(uint32_t fg_lut_num,uint8_t fg_lut_pf, uint32_t fg_lut_addr)
  245. {
  246. /* foreground LUT number of pixel configuration */
  247. IPA_FPCTL |= (fg_lut_num<<8U);
  248. /* foreground LUT pixel format configuration */
  249. if(IPA_LUT_PF_RGB888 == fg_lut_pf){
  250. IPA_FPCTL |= IPA_FPCTL_FLPF;
  251. }else{
  252. IPA_FPCTL &= ~(IPA_FPCTL_FLPF);
  253. }
  254. /* foreground LUT memory base address configuration */
  255. IPA_FLMADDR &= ~(IPA_FLMADDR_FLMADDR);
  256. IPA_FLMADDR = fg_lut_addr;
  257. }
  258. /*!
  259. \brief initialize IPA background LUT parameters
  260. \param[in] bg_lut_num: background LUT number of pixel.
  261. \param[in] bg_lut_pf: background LUT pixel format, IPA_LUT_PF_ARGB8888,IPA_LUT_PF_RGB888.
  262. \param[in] bg_lut_addr: background LUT memory base address.
  263. \param[out] none
  264. \retval none
  265. */
  266. void ipa_background_lut_init(uint32_t bg_lut_num,uint8_t bg_lut_pf, uint32_t bg_lut_addr)
  267. {
  268. /* background LUT number of pixel configuration */
  269. IPA_BPCTL|=(bg_lut_num<<8U);
  270. /* background LUT pixel format configuration */
  271. if(IPA_LUT_PF_RGB888 == bg_lut_pf){
  272. IPA_BPCTL |= IPA_BPCTL_BLPF;
  273. }else{
  274. IPA_BPCTL &= ~(IPA_BPCTL_BLPF);
  275. }
  276. /* background LUT memory base address configuration */
  277. IPA_BLMADDR &= ~(IPA_BLMADDR_BLMADDR);
  278. IPA_BLMADDR = bg_lut_addr;
  279. }
  280. /*!
  281. \brief configure line mark
  282. \param[in] linenum: line number.
  283. \param[out] none
  284. \retval none
  285. */
  286. void ipa_line_mark_config(uint32_t linenum)
  287. {
  288. IPA_LM &= ~(IPA_LM_LM);
  289. IPA_LM = linenum;
  290. }
  291. /*!
  292. \brief Inter-timer enable or disable
  293. \param[in] timercfg: IPA_INTER_TIMER_ENABLE,IPA_INTER_TIMER_DISABLE
  294. \param[out] none
  295. \retval none
  296. */
  297. void ipa_inter_timer_config(uint8_t timercfg)
  298. {
  299. if(IPA_INTER_TIMER_ENABLE == timercfg){
  300. IPA_ITCTL |= IPA_ITCTL_ITEN;
  301. }else{
  302. IPA_ITCTL &= ~(IPA_ITCTL_ITEN);
  303. }
  304. }
  305. /*!
  306. \brief number of clock cycles interval set
  307. \param[in] clk_num: the number of clock cycles.
  308. \param[out] none
  309. \retval none
  310. */
  311. void ipa_interval_clock_num_config(uint32_t clk_num )
  312. {
  313. IPA_ITCTL &= ~(IPA_ITCTL_NCCI);
  314. IPA_ITCTL |= (clk_num<<8U);
  315. }
  316. /*!
  317. \brief IPA interrupt enable
  318. \param[in] inttype: IPA interrupt bits.
  319. \arg IPA_CTL_TAEIE: transfer access error interrupt
  320. \arg IPA_CTL_FTFIE: full transfer finish interrupt
  321. \arg IPA_CTL_TLMIE: transfer line mark interrupt
  322. \arg IPA_CTL_LACIE: LUT access conflict interrupt
  323. \arg IPA_CTL_LLFIE: LUT loading finish interrupt
  324. \arg IPA_CTL_WCFIE: wrong configuration interrupt
  325. \param[out] none
  326. \retval none
  327. */
  328. void ipa_interrupt_enable(uint32_t inttype)
  329. {
  330. IPA_CTL |= (inttype);
  331. }
  332. /*!
  333. \brief IPA interrupt disable
  334. \param[in] inttype: IPA interrupt bits.
  335. \arg IPA_CTL_TAEIE: transfer access error interrupt
  336. \arg IPA_CTL_FTFIE: full transfer finish interrupt
  337. \arg IPA_CTL_TLMIE: transfer line mark interrupt
  338. \arg IPA_CTL_LACIE: LUT access conflict interrupt
  339. \arg IPA_CTL_LLFIE: LUT loading finish interrupt
  340. \arg IPA_CTL_WCFIE: wrong configuration interrupt
  341. \param[out] none
  342. \retval none
  343. */
  344. void ipa_interrupt_disable(uint32_t inttype)
  345. {
  346. IPA_CTL &= ~(inttype);
  347. }
  348. /*!
  349. \brief get IPA interrupt flag
  350. \param[in] intflag: tli interrupt flag bits.
  351. \arg IPA_INTF_TAEIF: transfer access error interrupt flag
  352. \arg IPA_INTF_FTFIF: full transfer finish interrupt flag
  353. \arg IPA_INTF_TLMIF: transfer line mark interrupt flag
  354. \arg IPA_INTF_LACIF: LUT access conflict interrupt flag
  355. \arg IPA_INTF_LLFIF: LUT loading finish interrupt flag
  356. \arg IPA_INTF_WCFIF: wrong configuration interrupt flag
  357. \param[out] none
  358. \retval none
  359. */
  360. FlagStatus ipa_interrupt_flag_get(uint32_t intflag)
  361. {
  362. uint32_t state;
  363. state = IPA_INTF;
  364. if(state & intflag){
  365. return SET;
  366. }else{
  367. return RESET;
  368. }
  369. }
  370. /*!
  371. \brief clear IPA interrupt flag
  372. \param[in] intflag: tli interrupt flag bits.
  373. \arg IPA_INTC_TAEIFC: transfer access error interrupt flag
  374. \arg IPA_INTC_FTFIFC: full transfer finish interrupt flag
  375. \arg IPA_INTC_TLMIFC: transfer line mark interrupt flag
  376. \arg IPA_INTC_LACIFC: LUT access conflict interrupt flag
  377. \arg IPA_INTC_LLFIFC: LUT loading finish interrupt flag
  378. \arg IPA_INTC_WCFIFC: wrong configuration interrupt flag
  379. \param[out] none
  380. \retval none
  381. */
  382. void ipa_interrupt_flag_clear(uint32_t intflag)
  383. {
  384. IPA_INTC |= (intflag);
  385. }