gd32f4xx_ipa.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*!
  2. \file gd32f4xx_ipa.c
  3. \brief IPA 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_ipa.h"
  32. #define IPA_DEFAULT_VALUE 0x00000000U
  33. /*!
  34. \brief deinitialize IPA registers
  35. \param[in] none
  36. \param[out] none
  37. \retval none
  38. */
  39. void ipa_deinit(void)
  40. {
  41. rcu_periph_reset_enable(RCU_IPARST);
  42. rcu_periph_reset_disable(RCU_IPARST);
  43. }
  44. /*!
  45. \brief enable IPA transfer
  46. \param[in] none
  47. \param[out] none
  48. \retval none
  49. */
  50. void ipa_transfer_enable(void)
  51. {
  52. IPA_CTL |= IPA_CTL_TEN;
  53. }
  54. /*!
  55. \brief enable IPA transfer hang up
  56. \param[in] none
  57. \param[out] none
  58. \retval none
  59. */
  60. void ipa_transfer_hangup_enable(void)
  61. {
  62. IPA_CTL |= IPA_CTL_THU;
  63. }
  64. /*!
  65. \brief disable IPA transfer hang up
  66. \param[in] none
  67. \param[out] none
  68. \retval none
  69. */
  70. void ipa_transfer_hangup_disable(void)
  71. {
  72. IPA_CTL &= ~(IPA_CTL_THU);
  73. }
  74. /*!
  75. \brief enable IPA transfer stop
  76. \param[in] none
  77. \param[out] none
  78. \retval none
  79. */
  80. void ipa_transfer_stop_enable(void)
  81. {
  82. IPA_CTL |= IPA_CTL_TST;
  83. }
  84. /*!
  85. \brief disable IPA transfer stop
  86. \param[in] none
  87. \param[out] none
  88. \retval none
  89. */
  90. void ipa_transfer_stop_disable(void)
  91. {
  92. IPA_CTL &= ~(IPA_CTL_TST);
  93. }
  94. /*!
  95. \brief enable IPA foreground LUT loading
  96. \param[in] none
  97. \param[out] none
  98. \retval none
  99. */
  100. void ipa_foreground_lut_loading_enable(void)
  101. {
  102. IPA_FPCTL |= IPA_FPCTL_FLLEN;
  103. }
  104. /*!
  105. \brief enable IPA background LUT loading
  106. \param[in] none
  107. \param[out] none
  108. \retval none
  109. */
  110. void ipa_background_lut_loading_enable(void)
  111. {
  112. IPA_BPCTL |= IPA_BPCTL_BLLEN;
  113. }
  114. /*!
  115. \brief set pixel format convert mode, the function is invalid when the IPA transfer is enabled
  116. \param[in] pfcm: pixel format convert mode
  117. only one parameter can be selected which is shown as below:
  118. \arg IPA_FGTODE: foreground memory to destination memory without pixel format convert
  119. \arg IPA_FGTODE_PF_CONVERT: foreground memory to destination memory with pixel format convert
  120. \arg IPA_FGBGTODE: blending foreground and background memory to destination memory
  121. \arg IPA_FILL_UP_DE: fill up destination memory with specific color
  122. \param[out] none
  123. \retval none
  124. */
  125. void ipa_pixel_format_convert_mode_set(uint32_t pfcm)
  126. {
  127. IPA_CTL |= pfcm;
  128. }
  129. /*!
  130. \brief initialize the structure of IPA foreground parameter struct with the default values, it is
  131. suggested that call this function after an ipa_foreground_parameter_struct structure is defined
  132. \param[in] none
  133. \param[out] foreground_struct: the data needed to initialize foreground
  134. foreground_memaddr: foreground memory base address
  135. foreground_lineoff: foreground line offset
  136. foreground_prealpha: foreground pre-defined alpha value
  137. foreground_alpha_algorithm: IPA_FG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
  138. foreground_pf: foreground pixel format(FOREGROUND_PPF_ARGB8888,FOREGROUND_PPF_RGB888,FOREGROUND_PPF_RGB565,
  139. FOREGROUND_PPF_ARG1555,FOREGROUND_PPF_ARGB4444,FOREGROUND_PPF_L8,FOREGROUND_PPF_AL44,
  140. FOREGROUND_PPF_AL88,FOREGROUND_PPF_L4,FOREGROUND_PPF_A8,FOREGROUND_PPF_A4)
  141. foreground_prered: foreground pre-defined red value
  142. foreground_pregreen: foreground pre-defined green value
  143. foreground_preblue: foreground pre-defined blue value
  144. \retval none
  145. */
  146. void ipa_foreground_struct_para_init(ipa_foreground_parameter_struct* foreground_struct)
  147. {
  148. /* initialize the struct parameters with default values */
  149. foreground_struct->foreground_memaddr = IPA_DEFAULT_VALUE;
  150. foreground_struct->foreground_lineoff = IPA_DEFAULT_VALUE;
  151. foreground_struct->foreground_prealpha = IPA_DEFAULT_VALUE;
  152. foreground_struct->foreground_alpha_algorithm = IPA_FG_ALPHA_MODE_0;
  153. foreground_struct->foreground_pf = FOREGROUND_PPF_ARGB8888;
  154. foreground_struct->foreground_prered = IPA_DEFAULT_VALUE;
  155. foreground_struct->foreground_pregreen = IPA_DEFAULT_VALUE;
  156. foreground_struct->foreground_preblue = IPA_DEFAULT_VALUE;
  157. }
  158. /*!
  159. \brief initialize foreground parameters
  160. \param[in] foreground_struct: the data needed to initialize foreground
  161. foreground_memaddr: foreground memory base address
  162. foreground_lineoff: foreground line offset
  163. foreground_prealpha: foreground pre-defined alpha value
  164. foreground_alpha_algorithm: IPA_FG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
  165. foreground_pf: foreground pixel format(FOREGROUND_PPF_ARGB8888,FOREGROUND_PPF_RGB888,FOREGROUND_PPF_RGB565,
  166. FOREGROUND_PPF_ARG1555,FOREGROUND_PPF_ARGB4444,FOREGROUND_PPF_L8,FOREGROUND_PPF_AL44,
  167. FOREGROUND_PPF_AL88,FOREGROUND_PPF_L4,FOREGROUND_PPF_A8,FOREGROUND_PPF_A4)
  168. foreground_prered: foreground pre-defined red value
  169. foreground_pregreen: foreground pre-defined green value
  170. foreground_preblue: foreground pre-defined blue value
  171. \param[out] none
  172. \retval none
  173. */
  174. void ipa_foreground_init(ipa_foreground_parameter_struct* foreground_struct)
  175. {
  176. FlagStatus tempflag = RESET;
  177. if(RESET != (IPA_CTL & IPA_CTL_TEN)){
  178. tempflag = SET;
  179. /* reset the TEN in order to configure the following bits */
  180. IPA_CTL &= ~IPA_CTL_TEN;
  181. }
  182. /* foreground memory base address configuration */
  183. IPA_FMADDR &= ~(IPA_FMADDR_FMADDR);
  184. IPA_FMADDR = foreground_struct->foreground_memaddr;
  185. /* foreground line offset configuration */
  186. IPA_FLOFF &= ~(IPA_FLOFF_FLOFF);
  187. IPA_FLOFF = foreground_struct->foreground_lineoff;
  188. /* foreground pixel format pre-defined alpha, alpha calculation algorithm configuration */
  189. IPA_FPCTL &= ~(IPA_FPCTL_FPDAV|IPA_FPCTL_FAVCA|IPA_FPCTL_FPF);
  190. IPA_FPCTL |= (foreground_struct->foreground_prealpha<<24U);
  191. IPA_FPCTL |= foreground_struct->foreground_alpha_algorithm;
  192. IPA_FPCTL |= foreground_struct->foreground_pf;
  193. /* foreground pre-defined red green blue configuration */
  194. IPA_FPV &= ~(IPA_FPV_FPDRV|IPA_FPV_FPDGV|IPA_FPV_FPDBV);
  195. IPA_FPV |= ((foreground_struct->foreground_prered<<16U)|(foreground_struct->foreground_pregreen<<8U)
  196. |(foreground_struct->foreground_preblue));
  197. if(SET == tempflag){
  198. /* restore the state of TEN */
  199. IPA_CTL |= IPA_CTL_TEN;
  200. }
  201. }
  202. /*!
  203. \brief initialize the structure of IPA background parameter struct with the default values, it is
  204. suggested that call this function after an ipa_background_parameter_struct structure is defined
  205. \param[in] none
  206. \param[out] background_struct: the data needed to initialize background
  207. background_memaddr: background memory base address
  208. background_lineoff: background line offset
  209. background_prealpha: background pre-defined alpha value
  210. background_alpha_algorithm: IPA_BG_ALPHA_MODE_0,IPA_BG_ALPHA_MODE_1,IPA_BG_ALPHA_MODE_2
  211. background_pf: background pixel format(BACKGROUND_PPF_ARGB8888,BACKGROUND_PPF_RGB888,BACKGROUND_PPF_RGB565,
  212. BACKGROUND_PPF_ARG1555,BACKGROUND_PPF_ARGB4444,BACKGROUND_PPF_L8,BACKGROUND_PPF_AL44,
  213. BACKGROUND_PPF_AL88,BACKGROUND_PPF_L4,BACKGROUND_PPF_A8,BACKGROUND_PPF_A4)
  214. background_prered: background pre-defined red value
  215. background_pregreen: background pre-defined green value
  216. background_preblue: background pre-defined blue value
  217. \retval none
  218. */
  219. void ipa_background_struct_para_init(ipa_background_parameter_struct* background_struct)
  220. {
  221. /* initialize the struct parameters with default values */
  222. background_struct->background_memaddr = IPA_DEFAULT_VALUE;
  223. background_struct->background_lineoff = IPA_DEFAULT_VALUE;
  224. background_struct->background_prealpha = IPA_DEFAULT_VALUE;
  225. background_struct->background_alpha_algorithm = IPA_BG_ALPHA_MODE_0;
  226. background_struct->background_pf = BACKGROUND_PPF_ARGB8888;
  227. background_struct->background_prered = IPA_DEFAULT_VALUE;
  228. background_struct->background_pregreen = IPA_DEFAULT_VALUE;
  229. background_struct->background_preblue = IPA_DEFAULT_VALUE;
  230. }
  231. /*!
  232. \brief initialize background parameters
  233. \param[in] background_struct: the data needed to initialize background
  234. background_memaddr: background memory base address
  235. background_lineoff: background line offset
  236. background_prealpha: background pre-defined alpha value
  237. background_alpha_algorithm: IPA_BG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
  238. background_pf: background pixel format(BACKGROUND_PPF_ARGB8888,BACKGROUND_PPF_RGB888,BACKGROUND_PPF_RGB565,
  239. BACKGROUND_PPF_ARG1555,BACKGROUND_PPF_ARGB4444,BACKGROUND_PPF_L8,BACKGROUND_PPF_AL44,
  240. BACKGROUND_PPF_AL88,BACKGROUND_PPF_L4,BACKGROUND_PPF_A8,BACKGROUND_PPF_A4)
  241. background_prered: background pre-defined red value
  242. background_pregreen: background pre-defined green value
  243. background_preblue: background pre-defined blue value
  244. \param[out] none
  245. \retval none
  246. */
  247. void ipa_background_init(ipa_background_parameter_struct* background_struct)
  248. {
  249. FlagStatus tempflag = RESET;
  250. if(RESET != (IPA_CTL & IPA_CTL_TEN)){
  251. tempflag = SET;
  252. /* reset the TEN in order to configure the following bits */
  253. IPA_CTL &= ~IPA_CTL_TEN;
  254. }
  255. /* background memory base address configuration */
  256. IPA_BMADDR &= ~(IPA_BMADDR_BMADDR);
  257. IPA_BMADDR = background_struct->background_memaddr;
  258. /* background line offset configuration */
  259. IPA_BLOFF &= ~(IPA_BLOFF_BLOFF);
  260. IPA_BLOFF = background_struct->background_lineoff;
  261. /* background pixel format pre-defined alpha, alpha calculation algorithm configuration */
  262. IPA_BPCTL &= ~(IPA_BPCTL_BPDAV|IPA_BPCTL_BAVCA|IPA_BPCTL_BPF);
  263. IPA_BPCTL |= (background_struct->background_prealpha<<24U);
  264. IPA_BPCTL |= background_struct->background_alpha_algorithm;
  265. IPA_BPCTL |= background_struct->background_pf;
  266. /* background pre-defined red green blue configuration */
  267. IPA_BPV &= ~(IPA_BPV_BPDRV|IPA_BPV_BPDGV|IPA_BPV_BPDBV);
  268. IPA_BPV |= ((background_struct->background_prered<<16U)|(background_struct->background_pregreen<<8U)
  269. |(background_struct->background_preblue));
  270. if(SET == tempflag){
  271. /* restore the state of TEN */
  272. IPA_CTL |= IPA_CTL_TEN;
  273. }
  274. }
  275. /*!
  276. \brief initialize the structure of IPA destination parameter struct with the default values, it is
  277. suggested that call this function after an ipa_destination_parameter_struct structure is defined
  278. \param[in] none
  279. \param[out] destination_struct: the data needed to initialize destination parameter
  280. destination_pf: IPA_DPF_ARGB8888,IPA_DPF_RGB888,IPA_DPF_RGB565,IPA_DPF_ARGB1555,
  281. IPA_DPF_ARGB4444,refer to ipa_dpf_enum
  282. destination_lineoff: destination line offset
  283. destination_prealpha: destination pre-defined alpha value
  284. destination_prered: destination pre-defined red value
  285. destination_pregreen: destination pre-defined green value
  286. destination_preblue: destination pre-defined blue value
  287. destination_memaddr: destination memory base address
  288. image_width: width of the image to be processed
  289. image_height: height of the image to be processed
  290. \retval none
  291. */
  292. void ipa_destination_struct_para_init(ipa_destination_parameter_struct* destination_struct)
  293. {
  294. /* initialize the struct parameters with default values */
  295. destination_struct->destination_pf = IPA_DPF_ARGB8888;
  296. destination_struct->destination_lineoff = IPA_DEFAULT_VALUE;
  297. destination_struct->destination_prealpha = IPA_DEFAULT_VALUE;
  298. destination_struct->destination_prered = IPA_DEFAULT_VALUE;
  299. destination_struct->destination_pregreen = IPA_DEFAULT_VALUE;
  300. destination_struct->destination_preblue = IPA_DEFAULT_VALUE;
  301. destination_struct->destination_memaddr = IPA_DEFAULT_VALUE;
  302. destination_struct->image_width = IPA_DEFAULT_VALUE;
  303. destination_struct->image_height = IPA_DEFAULT_VALUE;
  304. }
  305. /*!
  306. \brief initialize destination parameters
  307. \param[in] destination_struct: the data needed to initialize destination parameters
  308. destination_pf: IPA_DPF_ARGB8888,IPA_DPF_RGB888,IPA_DPF_RGB565,IPA_DPF_ARGB1555,
  309. IPA_DPF_ARGB4444,refer to ipa_dpf_enum
  310. destination_lineoff: destination line offset
  311. destination_prealpha: destination pre-defined alpha value
  312. destination_prered: destination pre-defined red value
  313. destination_pregreen: destination pre-defined green value
  314. destination_preblue: destination pre-defined blue value
  315. destination_memaddr: destination memory base address
  316. image_width: width of the image to be processed
  317. image_height: height of the image to be processed
  318. \param[out] none
  319. \retval none
  320. */
  321. void ipa_destination_init(ipa_destination_parameter_struct* destination_struct)
  322. {
  323. uint32_t destination_pixelformat;
  324. FlagStatus tempflag = RESET;
  325. if(RESET != (IPA_CTL & IPA_CTL_TEN)){
  326. tempflag = SET;
  327. /* reset the TEN in order to configure the following bits */
  328. IPA_CTL &= ~IPA_CTL_TEN;
  329. }
  330. /* destination pixel format configuration */
  331. IPA_DPCTL &= ~(IPA_DPCTL_DPF);
  332. IPA_DPCTL = destination_struct->destination_pf;
  333. destination_pixelformat = destination_struct->destination_pf;
  334. /* destination pixel format ARGB8888 */
  335. switch(destination_pixelformat){
  336. case IPA_DPF_ARGB8888:
  337. IPA_DPV &= ~(IPA_DPV_DPDBV_0|(IPA_DPV_DPDGV_0)|(IPA_DPV_DPDRV_0)|(IPA_DPV_DPDAV_0));
  338. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<8U)
  339. |(destination_struct->destination_prered<<16U)
  340. |(destination_struct->destination_prealpha<<24U));
  341. break;
  342. /* destination pixel format RGB888 */
  343. case IPA_DPF_RGB888:
  344. IPA_DPV &= ~(IPA_DPV_DPDBV_1|(IPA_DPV_DPDGV_1)|(IPA_DPV_DPDRV_1));
  345. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<8U)
  346. |(destination_struct->destination_prered<<16U));
  347. break;
  348. /* destination pixel format RGB565 */
  349. case IPA_DPF_RGB565:
  350. IPA_DPV &= ~(IPA_DPV_DPDBV_2|(IPA_DPV_DPDGV_2)|(IPA_DPV_DPDRV_2));
  351. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<5U)
  352. |(destination_struct->destination_prered<<11U));
  353. break;
  354. /* destination pixel format ARGB1555 */
  355. case IPA_DPF_ARGB1555:
  356. IPA_DPV &= ~(IPA_DPV_DPDBV_3|(IPA_DPV_DPDGV_3)|(IPA_DPV_DPDRV_3)|(IPA_DPV_DPDAV_3));
  357. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<5U)
  358. |(destination_struct->destination_prered<<10U)
  359. |(destination_struct->destination_prealpha<<15U));
  360. break;
  361. /* destination pixel format ARGB4444 */
  362. case IPA_DPF_ARGB4444:
  363. IPA_DPV &= ~(IPA_DPV_DPDBV_4|(IPA_DPV_DPDGV_4)|(IPA_DPV_DPDRV_4)|(IPA_DPV_DPDAV_4));
  364. IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<4U)
  365. |(destination_struct->destination_prered<<8U)
  366. |(destination_struct->destination_prealpha<<12U));
  367. break;
  368. default:
  369. break;
  370. }
  371. /* destination memory base address configuration */
  372. IPA_DMADDR &= ~(IPA_DMADDR_DMADDR);
  373. IPA_DMADDR = destination_struct->destination_memaddr;
  374. /* destination line offset configuration */
  375. IPA_DLOFF &= ~(IPA_DLOFF_DLOFF);
  376. IPA_DLOFF =destination_struct->destination_lineoff;
  377. /* image size configuration */
  378. IPA_IMS &= ~(IPA_IMS_HEIGHT|IPA_IMS_WIDTH);
  379. IPA_IMS |= ((destination_struct->image_width<<16U)|(destination_struct->image_height));
  380. if(SET == tempflag){
  381. /* restore the state of TEN */
  382. IPA_CTL |= IPA_CTL_TEN;
  383. }
  384. }
  385. /*!
  386. \brief initialize IPA foreground LUT parameters
  387. \param[in] fg_lut_num: foreground LUT number of pixel
  388. \param[in] fg_lut_pf: foreground LUT pixel format(IPA_LUT_PF_ARGB8888, IPA_LUT_PF_RGB888)
  389. \param[in] fg_lut_addr: foreground LUT memory base address
  390. \param[out] none
  391. \retval none
  392. */
  393. void ipa_foreground_lut_init(uint8_t fg_lut_num, uint8_t fg_lut_pf, uint32_t fg_lut_addr)
  394. {
  395. FlagStatus tempflag = RESET;
  396. if(RESET != (IPA_FPCTL & IPA_FPCTL_FLLEN)){
  397. tempflag = SET;
  398. /* reset the FLLEN in order to configure the following bits */
  399. IPA_FPCTL &= ~IPA_FPCTL_FLLEN;
  400. }
  401. /* foreground LUT number of pixel configuration */
  402. IPA_FPCTL |= ((uint32_t)fg_lut_num<<8U);
  403. /* foreground LUT pixel format configuration */
  404. if(IPA_LUT_PF_RGB888 == fg_lut_pf){
  405. IPA_FPCTL |= IPA_FPCTL_FLPF;
  406. }else{
  407. IPA_FPCTL &= ~(IPA_FPCTL_FLPF);
  408. }
  409. /* foreground LUT memory base address configuration */
  410. IPA_FLMADDR &= ~(IPA_FLMADDR_FLMADDR);
  411. IPA_FLMADDR = fg_lut_addr;
  412. if(SET == tempflag){
  413. /* restore the state of FLLEN */
  414. IPA_FPCTL |= IPA_FPCTL_FLLEN;
  415. }
  416. }
  417. /*!
  418. \brief initialize IPA background LUT parameters
  419. \param[in] bg_lut_num: background LUT number of pixel
  420. \param[in] bg_lut_pf: background LUT pixel format(IPA_LUT_PF_ARGB8888, IPA_LUT_PF_RGB888)
  421. \param[in] bg_lut_addr: background LUT memory base address
  422. \param[out] none
  423. \retval none
  424. */
  425. void ipa_background_lut_init(uint8_t bg_lut_num, uint8_t bg_lut_pf, uint32_t bg_lut_addr)
  426. {
  427. FlagStatus tempflag = RESET;
  428. if(RESET != (IPA_BPCTL & IPA_BPCTL_BLLEN)){
  429. tempflag = SET;
  430. /* reset the BLLEN in order to configure the following bits */
  431. IPA_BPCTL &= ~IPA_BPCTL_BLLEN;
  432. }
  433. /* background LUT number of pixel configuration */
  434. IPA_BPCTL |= ((uint32_t)bg_lut_num<<8U);
  435. /* background LUT pixel format configuration */
  436. if(IPA_LUT_PF_RGB888 == bg_lut_pf){
  437. IPA_BPCTL |= IPA_BPCTL_BLPF;
  438. }else{
  439. IPA_BPCTL &= ~(IPA_BPCTL_BLPF);
  440. }
  441. /* background LUT memory base address configuration */
  442. IPA_BLMADDR &= ~(IPA_BLMADDR_BLMADDR);
  443. IPA_BLMADDR = bg_lut_addr;
  444. if(SET == tempflag){
  445. /* restore the state of BLLEN */
  446. IPA_BPCTL |= IPA_BPCTL_BLLEN;
  447. }
  448. }
  449. /*!
  450. \brief configure IPA line mark
  451. \param[in] line_num: line number
  452. \param[out] none
  453. \retval none
  454. */
  455. void ipa_line_mark_config(uint16_t line_num)
  456. {
  457. IPA_LM &= ~(IPA_LM_LM);
  458. IPA_LM = line_num;
  459. }
  460. /*!
  461. \brief inter-timer enable or disable
  462. \param[in] timer_cfg: IPA_INTER_TIMER_ENABLE,IPA_INTER_TIMER_DISABLE
  463. \param[out] none
  464. \retval none
  465. */
  466. void ipa_inter_timer_config(uint8_t timer_cfg)
  467. {
  468. if(IPA_INTER_TIMER_ENABLE == timer_cfg){
  469. IPA_ITCTL |= IPA_ITCTL_ITEN;
  470. }else{
  471. IPA_ITCTL &= ~(IPA_ITCTL_ITEN);
  472. }
  473. }
  474. /*!
  475. \brief configure the number of clock cycles interval
  476. \param[in] clk_num: the number of clock cycles
  477. \param[out] none
  478. \retval none
  479. */
  480. void ipa_interval_clock_num_config(uint8_t clk_num)
  481. {
  482. /* NCCI[7:0] bits have no meaning if ITEN is '0' */
  483. IPA_ITCTL &= ~(IPA_ITCTL_NCCI);
  484. IPA_ITCTL |= ((uint32_t)clk_num<<8U);
  485. }
  486. /*!
  487. \brief get IPA flag status in IPA_INTF register
  488. \param[in] flag: IPA flags
  489. one or more parameters can be selected which are shown as below:
  490. \arg IPA_FLAG_TAE: transfer access error interrupt flag
  491. \arg IPA_FLAG_FTF: full transfer finish interrupt flag
  492. \arg IPA_FLAG_TLM: transfer line mark interrupt flag
  493. \arg IPA_FLAG_LAC: LUT access conflict interrupt flag
  494. \arg IPA_FLAG_LLF: LUT loading finish interrupt flag
  495. \arg IPA_FLAG_WCF: wrong configuration interrupt flag
  496. \param[out] none
  497. \retval none
  498. */
  499. FlagStatus ipa_flag_get(uint32_t flag)
  500. {
  501. if(RESET != (IPA_INTF & flag)){
  502. return SET;
  503. }else{
  504. return RESET;
  505. }
  506. }
  507. /*!
  508. \brief clear IPA flag in IPA_INTF register
  509. \param[in] flag: IPA flags
  510. one or more parameters can be selected which are shown as below:
  511. \arg IPA_FLAG_TAE: transfer access error interrupt flag
  512. \arg IPA_FLAG_FTF: full transfer finish interrupt flag
  513. \arg IPA_FLAG_TLM: transfer line mark interrupt flag
  514. \arg IPA_FLAG_LAC: LUT access conflict interrupt flag
  515. \arg IPA_FLAG_LLF: LUT loading finish interrupt flag
  516. \arg IPA_FLAG_WCF: wrong configuration interrupt flag
  517. \param[out] none
  518. \retval none
  519. */
  520. void ipa_flag_clear(uint32_t flag)
  521. {
  522. IPA_INTC |= (flag);
  523. }
  524. /*!
  525. \brief enable IPA interrupt
  526. \param[in] int_flag: IPA interrupt flags
  527. one or more parameters can be selected which are shown as below:
  528. \arg IPA_INT_TAE: transfer access error interrupt
  529. \arg IPA_INT_FTF: full transfer finish interrupt
  530. \arg IPA_INT_TLM: transfer line mark interrupt
  531. \arg IPA_INT_LAC: LUT access conflict interrupt
  532. \arg IPA_INT_LLF: LUT loading finish interrupt
  533. \arg IPA_INT_WCF: wrong configuration interrupt
  534. \param[out] none
  535. \retval none
  536. */
  537. void ipa_interrupt_enable(uint32_t int_flag)
  538. {
  539. IPA_CTL |= (int_flag);
  540. }
  541. /*!
  542. \brief disable IPA interrupt
  543. \param[in] int_flag: IPA interrupt flags
  544. one or more parameters can be selected which are shown as below:
  545. \arg IPA_INT_TAE: transfer access error interrupt
  546. \arg IPA_INT_FTF: full transfer finish interrupt
  547. \arg IPA_INT_TLM: transfer line mark interrupt
  548. \arg IPA_INT_LAC: LUT access conflict interrupt
  549. \arg IPA_INT_LLF: LUT loading finish interrupt
  550. \arg IPA_INT_WCF: wrong configuration interrupt
  551. \param[out] none
  552. \retval none
  553. */
  554. void ipa_interrupt_disable(uint32_t int_flag)
  555. {
  556. IPA_CTL &= ~(int_flag);
  557. }
  558. /*!
  559. \brief get IPA interrupt flag
  560. \param[in] int_flag: IPA interrupt flag flags
  561. one or more parameters can be selected which are shown as below:
  562. \arg IPA_INT_FLAG_TAE: transfer access error interrupt flag
  563. \arg IPA_INT_FLAG_FTF: full transfer finish interrupt flag
  564. \arg IPA_INT_FLAG_TLM: transfer line mark interrupt flag
  565. \arg IPA_INT_FLAG_LAC: LUT access conflict interrupt flag
  566. \arg IPA_INT_FLAG_LLF: LUT loading finish interrupt flag
  567. \arg IPA_INT_FLAG_WCF: wrong configuration interrupt flag
  568. \param[out] none
  569. \retval none
  570. */
  571. FlagStatus ipa_interrupt_flag_get(uint32_t int_flag)
  572. {
  573. if(0U != (IPA_INTF & int_flag)){
  574. return SET;
  575. }else{
  576. return RESET;
  577. }
  578. }
  579. /*!
  580. \brief clear IPA interrupt flag
  581. \param[in] int_flag: IPA interrupt flag flags
  582. one or more parameters can be selected which are shown as below:
  583. \arg IPA_INT_FLAG_TAE: transfer access error interrupt flag
  584. \arg IPA_INT_FLAG_FTF: full transfer finish interrupt flag
  585. \arg IPA_INT_FLAG_TLM: transfer line mark interrupt flag
  586. \arg IPA_INT_FLAG_LAC: LUT access conflict interrupt flag
  587. \arg IPA_INT_FLAG_LLF: LUT loading finish interrupt flag
  588. \arg IPA_INT_FLAG_WCF: wrong configuration interrupt flag
  589. \param[out] none
  590. \retval none
  591. */
  592. void ipa_interrupt_flag_clear(uint32_t int_flag)
  593. {
  594. IPA_INTC |= (int_flag);
  595. }