gd32f4xx_dci.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*!
  2. \file gd32f4xx_dci.c
  3. \brief DCI driver
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #include "gd32f4xx_dci.h"
  10. /*!
  11. \brief DCI deinit
  12. \param[in] none
  13. \param[out] none
  14. \retval none
  15. */
  16. void dci_deinit(void)
  17. {
  18. rcu_periph_reset_enable(RCU_DCIRST);
  19. rcu_periph_reset_disable(RCU_DCIRST);
  20. }
  21. /*!
  22. \brief initialize DCI registers
  23. \param[in] dci_struct: DCI parameter initialization stuct
  24. members of the structure and the member values are shown as below:
  25. capture_mode : DCI_CAPTURE_MODE_CONTINUOUS, DCI_CAPTURE_MODE_SNAPSHOT
  26. colck_polarity : DCI_CK_POLARITY_FALLING, DCI_CK_POLARITY_RISING
  27. hsync_polarity : DCI_HSYNC_POLARITY_LOW, DCI_HSYNC_POLARITY_HIGH
  28. vsync_polarity : DCI_VSYNC_POLARITY_LOW, DCI_VSYNC_POLARITY_HIGH
  29. frame_rate : DCI_FRAME_RATE_ALL, DCI_FRAME_RATE_1_2, DCI_FRAME_RATE_1_4
  30. interface_format: DCI_INTERFACE_FORMAT_8BITS, DCI_INTERFACE_FORMAT_10BITS,
  31. DCI_INTERFACE_FORMAT_12BITS, DCI_INTERFACE_FORMAT_14BITS
  32. \param[out] none
  33. \retval none
  34. */
  35. void dci_init(dci_parameter_struct* dci_struct)
  36. {
  37. uint32_t reg =0U;
  38. /* disable capture function and DCI */
  39. DCI_CTL &= ~(DCI_CTL_CAP | DCI_CTL_DCIEN);
  40. /* config DCI parameter */
  41. reg |= dci_struct->capture_mode;
  42. reg |= dci_struct->clock_polarity;
  43. reg |= dci_struct->hsync_polarity;
  44. reg |= dci_struct->vsync_polarity;
  45. reg |= dci_struct->frame_rate;
  46. reg |= dci_struct->interface_format;
  47. DCI_CTL = reg;
  48. }
  49. /*!
  50. \brief enable DCI function
  51. \param[in] none
  52. \param[out] none
  53. \retval none
  54. */
  55. void dci_enable(void)
  56. {
  57. DCI_CTL |= DCI_CTL_DCIEN;
  58. }
  59. /*!
  60. \brief disable DCI function
  61. \param[in] none
  62. \param[out] none
  63. \retval none
  64. */
  65. void dci_disable(void)
  66. {
  67. DCI_CTL &= ~DCI_CTL_DCIEN;
  68. }
  69. /*!
  70. \brief enable DCI capture
  71. \param[in] none
  72. \param[out] none
  73. \retval none
  74. */
  75. void dci_capture_enable(void)
  76. {
  77. DCI_CTL |= DCI_CTL_CAP;
  78. }
  79. /*!
  80. \brief disable DCI capture
  81. \param[in] none
  82. \param[out] none
  83. \retval none
  84. */
  85. void dci_capture_disable(void)
  86. {
  87. DCI_CTL &= ~DCI_CTL_CAP;
  88. }
  89. /*!
  90. \brief enable DCI jpeg mode
  91. \param[in] none
  92. \param[out] none
  93. \retval none
  94. */
  95. void dci_jpeg_enable(void)
  96. {
  97. DCI_CTL |= DCI_CTL_JM;
  98. }
  99. /*!
  100. \brief disable DCI jpeg mode
  101. \param[in] none
  102. \param[out] none
  103. \retval none
  104. */
  105. void dci_jpeg_disable(void)
  106. {
  107. DCI_CTL &= ~DCI_CTL_JM;
  108. }
  109. /*!
  110. \brief enable cropping window function
  111. \param[in] none
  112. \param[out] none
  113. \retval none
  114. */
  115. void dci_crop_window_enable(void)
  116. {
  117. DCI_CTL |= DCI_CTL_WDEN;
  118. }
  119. /*!
  120. \brief disable cropping window function
  121. \param[in] none
  122. \param[out] none
  123. \retval none
  124. */
  125. void dci_crop_window_disable(void)
  126. {
  127. DCI_CTL &= ~DCI_CTL_WDEN;
  128. }
  129. /*!
  130. \brief config DCI cropping window
  131. \param[in] start_x: window horizontal start position
  132. \param[in] start_y: window vertical start position
  133. \param[in] size_height: window horizontal size
  134. \param[in] size_width: window vertical size
  135. \param[out] none
  136. \retval none
  137. */
  138. void dci_crop_window_config(uint16_t start_x, uint16_t start_y, uint16_t size_width, uint16_t size_height)
  139. {
  140. DCI_CWSPOS = ((uint32_t)start_x | ((uint32_t)start_y<<16));
  141. DCI_CWSZ = ((uint32_t)size_width | ((uint32_t)size_height<<16));
  142. }
  143. /*!
  144. \brief enable sync codes function
  145. \param[in] none
  146. \param[out] none
  147. \retval none
  148. */
  149. void dci_sync_codes_enable(void)
  150. {
  151. DCI_CTL |= DCI_CTL_ESM;
  152. }
  153. /*!
  154. \brief disable sync codes function
  155. \param[in] none
  156. \param[out] none
  157. \retval none
  158. */
  159. void dci_sync_codes_disable(void)
  160. {
  161. DCI_CTL &= ~DCI_CTL_ESM;
  162. }
  163. /*!
  164. \brief config sync codes
  165. \param[in] frame_start: frame start code in embedded synchronous mode
  166. \param[in] line_start: line start code in embedded synchronous mode
  167. \param[in] line_end: line end code in embedded synchronous mode
  168. \param[in] frame_end: frame end code in embedded synchronous mode
  169. \param[out] none
  170. \retval none
  171. */
  172. void dci_sync_codes_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end)
  173. {
  174. DCI_SC = ((uint32_t)frame_start | ((uint32_t)line_start<<8) | ((uint32_t)line_end<<16) | ((uint32_t)frame_end<<24));
  175. }
  176. /*!
  177. \brief config sync codes unmask
  178. \param[in] frame_start: frame start code unmask bits in embedded synchronous mode
  179. \param[in] line_start: line start code unmask bits in embedded synchronous mode
  180. \param[in] line_end: line end code unmask bits in embedded synchronous mode
  181. \param[in] frame_end: frame end code unmask bits in embedded synchronous mode
  182. \param[out] none
  183. \retval none
  184. */
  185. void dci_sync_codes_unmask_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end)
  186. {
  187. DCI_SCUMSK = ((uint32_t)frame_start | ((uint32_t)line_start<<8) | ((uint32_t)line_end<<16) | ((uint32_t)frame_end<<24));
  188. }
  189. /*!
  190. \brief read DCI data register
  191. \param[in] none
  192. \param[out] none
  193. \retval data
  194. */
  195. uint32_t dci_data_read(void)
  196. {
  197. return DCI_DATA;
  198. }
  199. /*!
  200. \brief enable specified DCI interrupt
  201. \param[in] interrupt:
  202. \arg DCI_INT_EF: end of frame interrupt
  203. \arg DCI_INT_OVR: FIFO overrun interrupt
  204. \arg DCI_INT_ESE: embedded synchronous error interrupt
  205. \arg DCI_INT_VS: vsync interrupt
  206. \arg DCI_INT_EL: end of line interrupt
  207. \param[out] none
  208. \retval none
  209. */
  210. void dci_interrupt_enable(uint32_t interrupt)
  211. {
  212. DCI_INTEN |= interrupt;
  213. }
  214. /*!
  215. \brief disable specified DCI interrupt
  216. \param[in] interrupt:
  217. \arg DCI_INT_EF: end of frame interrupt
  218. \arg DCI_INT_OVR: FIFO overrun interrupt
  219. \arg DCI_INT_ESE: embedded synchronous error interrupt
  220. \arg DCI_INT_VS: vsync interrupt
  221. \arg DCI_INT_EL: end of line interrupt
  222. \param[out] none
  223. \retval none
  224. */
  225. void dci_interrupt_disable(uint32_t interrupt)
  226. {
  227. DCI_INTEN &= ~interrupt;
  228. }
  229. /*!
  230. \brief clear specified interrupt
  231. \param[in] interrupt:
  232. \arg DCI_INT_EF: end of frame interrupt
  233. \arg DCI_INT_OVR: FIFO overrun interrupt
  234. \arg DCI_INT_ESE: embedded synchronous error interrupt
  235. \arg DCI_INT_VS: vsync interrupt
  236. \arg DCI_INT_EL: end of line interrupt
  237. \param[out] none
  238. \retval none
  239. */
  240. void dci_interrupt_clear(uint32_t interrupt)
  241. {
  242. DCI_INTC |= interrupt;
  243. }
  244. /*!
  245. \brief get specified flag
  246. \param[in] flag:
  247. \arg DCI_FLAG_HS: HS line status
  248. \arg DCI_FLAG_VS: VS line status
  249. \arg DCI_FLAG_FV:FIFO valid
  250. \arg DCI_FLAG_EFF: end of frame flag
  251. \arg DCI_FLAG_OVRF: FIFO overrun flag
  252. \arg DCI_FLAG_ESEF: embedded synchronous error flag
  253. \arg DCI_FLAG_VSF: vsync flag
  254. \arg DCI_FLAG_ELF: end of line flag
  255. \param[out] none
  256. \retval FlagStatus: SET or RESET
  257. */
  258. FlagStatus dci_flag_get(uint32_t flag)
  259. {
  260. uint32_t ret = 0U;
  261. switch(flag){
  262. /* get flag status from DCI_STAT0 register */
  263. case DCI_FLAG_HS:
  264. ret = (DCI_STAT0 & DCI_STAT0_HS);
  265. break;
  266. case DCI_FLAG_VS:
  267. ret = (DCI_STAT0 & DCI_STAT0_VS);
  268. break;
  269. case DCI_FLAG_FV:
  270. ret = (DCI_STAT0 & DCI_STAT0_FV);
  271. break;
  272. /* get flag status from DCI_STAT1 register */
  273. case DCI_FLAG_EFF:
  274. ret = (DCI_STAT1 & DCI_STAT1_EFF);
  275. break;
  276. case DCI_FLAG_OVRF:
  277. ret = (DCI_STAT1 & DCI_STAT1_OVRF);
  278. break;
  279. case DCI_FLAG_ESEF:
  280. ret = (DCI_STAT1 & DCI_STAT1_ESEF);
  281. break;
  282. case DCI_FLAG_VSF:
  283. ret = (DCI_STAT1 & DCI_STAT1_VSF);
  284. break;
  285. case DCI_FLAG_ELF:
  286. ret = (DCI_STAT1 & DCI_STAT1_ELF);
  287. break;
  288. default :
  289. break;
  290. }
  291. if(RESET == ret){
  292. return RESET;
  293. }else{
  294. return SET;
  295. }
  296. }
  297. /*!
  298. \brief get specified interrupt flag
  299. \param[in] interrupt:
  300. \arg DCI_INT_EF: end of frame interrupt
  301. \arg DCI_INT_OVR: FIFO overrun interrupt
  302. \arg DCI_INT_ESE: embedded synchronous error interrupt
  303. \arg DCI_INT_VS: vsync interrupt
  304. \arg DCI_INT_EL: end of line interrupt
  305. \param[out] none
  306. \retval FlagStatus: SET or RESET
  307. */
  308. FlagStatus dci_interrupt_flag_get(uint32_t interrupt)
  309. {
  310. if(RESET == (DCI_INTF & interrupt)){
  311. return RESET;
  312. }else{
  313. return SET;
  314. }
  315. }