gd32f4xx_dci.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*!
  2. \file gd32f4xx_dci.h
  3. \brief definitions for the DCI
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_DCI_H
  10. #define GD32F4XX_DCI_H
  11. #include "gd32f4xx.h"
  12. /* DCI definitions */
  13. #define DCI DCI_BASE
  14. /* registers definitions */
  15. #define DCI_CTL REG32(DCI + 0x00U) /*!< DCI control register */
  16. #define DCI_STAT0 REG32(DCI + 0x04U) /*!< DCI status register 0 */
  17. #define DCI_STAT1 REG32(DCI + 0x08U) /*!< DCI status register 1 */
  18. #define DCI_INTEN REG32(DCI + 0x0CU) /*!< DCI interrupt enable register */
  19. #define DCI_INTF REG32(DCI + 0x10U) /*!< DCI interrupt flag register */
  20. #define DCI_INTC REG32(DCI + 0x14U) /*!< DCI interrupt clear register */
  21. #define DCI_SC REG32(DCI + 0x18U) /*!< DCI synchronization codes register */
  22. #define DCI_SCUMSK REG32(DCI + 0x1CU) /*!< DCI synchronization codes unmask register */
  23. #define DCI_CWSPOS REG32(DCI + 0x20U) /*!< DCI cropping window start position register */
  24. #define DCI_CWSZ REG32(DCI + 0x24U) /*!< DCI cropping window size register */
  25. #define DCI_DATA REG32(DCI + 0x28U) /*!< DCI data register */
  26. /* bits definitions */
  27. /* DCI_CTL */
  28. #define DCI_CTL_CAP BIT(0) /*!< capture enable */
  29. #define DCI_CTL_SNAP BIT(1) /*!< snapshot mode */
  30. #define DCI_CTL_WDEN BIT(2) /*!< window enable */
  31. #define DCI_CTL_JM BIT(3) /*!< jpeg mode */
  32. #define DCI_CTL_ESM BIT(4) /*!< embedded synchronous mode */
  33. #define DCI_CTL_CKS BIT(5) /*!< clock polarity selection */
  34. #define DCI_CTL_HPS BIT(6) /*!< horizontal polarity selection */
  35. #define DCI_CTL_VPS BIT(7) /*!< vertical polarity selection */
  36. #define DCI_CTL_FR BITS(8,9) /*!< frame rate */
  37. #define DCI_CTL_DCIF BITS(10,11) /*!< digital camera interface format */
  38. #define DCI_CTL_DCIEN BIT(14) /*!< dci enable */
  39. /* DCI_STAT0 */
  40. #define DCI_STAT0_HS BIT(0) /*!< HS line status */
  41. #define DCI_STAT0_VS BIT(1) /*!< VS line status */
  42. #define DCI_STAT0_FV BIT(2) /*!< FIFO valid */
  43. /* DCI_STAT1 */
  44. #define DCI_STAT1_EFF BIT(0) /*!< end of frame flag */
  45. #define DCI_STAT1_OVRF BIT(1) /*!< FIFO overrun flag */
  46. #define DCI_STAT1_ESEF BIT(2) /*!< embedded synchronous error flag */
  47. #define DCI_STAT1_VSF BIT(3) /*!< vsync flag */
  48. #define DCI_STAT1_ELF BIT(4) /*!< end of line flag */
  49. /* DCI_INTEN */
  50. #define DCI_INTEN_EFIE BIT(0) /*!< end of frame interrupt enable */
  51. #define DCI_INTEN_OVRIE BIT(1) /*!< FIFO overrun interrupt enable */
  52. #define DCI_INTEN_ESEIE BIT(2) /*!< embedded synchronous error interrupt enable */
  53. #define DCI_INTEN_VSIE BIT(3) /*!< vsync interrupt enable */
  54. #define DCI_INTEN_ELIE BIT(4) /*!< end of line interrupt enable */
  55. /* DCI_INTF */
  56. #define DCI_INTF_EFIF BIT(0) /*!< end of frame interrupt flag */
  57. #define DCI_INTF_OVRIF BIT(1) /*!< FIFO overrun interrupt flag */
  58. #define DCI_INTF_ESEIF BIT(2) /*!< embedded synchronous error interrupt flag */
  59. #define DCI_INTF_VSIF BIT(3) /*!< vsync interrupt flag */
  60. #define DCI_INTF_ELIF BIT(4) /*!< end of line interrupt flag */
  61. /* DCI_INTC */
  62. #define DCI_INTC_EFFC BIT(0) /*!< clear end of frame flag */
  63. #define DCI_INTC_OVRFC BIT(1) /*!< clear FIFO overrun flag */
  64. #define DCI_INTC_ESEFC BIT(2) /*!< clear embedded synchronous error flag */
  65. #define DCI_INTC_VSFC BIT(3) /*!< vsync flag clear */
  66. #define DCI_INTC_ELFC BIT(4) /*!< end of line flag clear */
  67. /* DCI_SC */
  68. #define DCI_SC_FS BITS(0,7) /*!< frame start code in embedded synchronous mode */
  69. #define DCI_SC_LS BITS(8,15) /*!< line start code in embedded synchronous mode */
  70. #define DCI_SC_LE BITS(16,23) /*!< line end code in embedded synchronous mode */
  71. #define DCI_SC_FE BITS(24,31) /*!< frame end code in embedded synchronous mode */
  72. /* DCI_SCUNMSK */
  73. #define DCI_SCUMSK_FSM BITS(0,7) /*!< frame start code unmask bits in embedded synchronous mode */
  74. #define DCI_SCUMSK_LSM BITS(8,15) /*!< line start code unmask bits in embedded synchronous mode */
  75. #define DCI_SCUMSK_LEM BITS(16,23) /*!< line end code unmask bits in embedded synchronous mode */
  76. #define DCI_SCUMSK_FEM BITS(24,31) /*!< frame end code unmask bits in embedded synchronous mode */
  77. /* DCI_CWSPOS */
  78. #define DCI_CWSPOS_WHSP BITS(0,13) /*!< window horizontal start position */
  79. #define DCI_CWSPOS_WVSP BITS(16,28) /*!< window vertical start position */
  80. /* DCI_CWSZ */
  81. #define DCI_CWSZ_WHSZ BITS(0,13) /*!< window horizontal size */
  82. #define DCI_CWSZ_WVSZ BITS(16,29) /*!< window vertical size */
  83. /* constants definitions */
  84. /* DCI parameter struct definitions */
  85. typedef struct
  86. {
  87. uint32_t capture_mode; /*!< DCI capture mode: continuous or snapshot */
  88. uint32_t clock_polarity; /*!< clock polarity selection */
  89. uint32_t hsync_polarity; /*!< horizontal polarity selection */
  90. uint32_t vsync_polarity; /*!< vertical polarity selection */
  91. uint32_t frame_rate; /*!< frame capture rate */
  92. uint32_t interface_format; /*!< digital camera interface format */
  93. }dci_parameter_struct;
  94. #define DCI_CAPTURE_MODE_CONTINUOUS ((uint32_t)0x00000000U) /*!< continuous capture mode */
  95. #define DCI_CAPTURE_MODE_SNAPSHOT DCI_CTL_SNAP /*!< snapshot capture mode */
  96. #define DCI_CK_POLARITY_FALLING ((uint32_t)0x00000000U) /*!< capture at falling edge */
  97. #define DCI_CK_POLARITY_RISING DCI_CTL_CKS /*!< capture at rising edge */
  98. #define DCI_HSYNC_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level during blanking period */
  99. #define DCI_HSYNC_POLARITY_HIGH DCI_CTL_HPS /*!< high level during blanking period */
  100. #define DCI_VSYNC_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level during blanking period */
  101. #define DCI_VSYNC_POLARITY_HIGH DCI_CTL_VPS /*!< high level during blanking period*/
  102. #define CTL_FR(regval) (BITS(8,9)&((uint32_t)(regval) << 8U))
  103. #define DCI_FRAME_RATE_ALL CTL_FR(0) /*!< capture all frames */
  104. #define DCI_FRAME_RATE_1_2 CTL_FR(1) /*!< capture one in 2 frames */
  105. #define DCI_FRAME_RATE_1_4 CTL_FR(2) /*!< capture one in 4 frames */
  106. #define CTL_DCIF(regval) (BITS(10,11)&((uint32_t)(regval) << 10U))
  107. #define DCI_INTERFACE_FORMAT_8BITS CTL_DCIF(0) /*!< 8-bit data on every pixel clock */
  108. #define DCI_INTERFACE_FORMAT_10BITS CTL_DCIF(1) /*!< 10-bit data on every pixel clock */
  109. #define DCI_INTERFACE_FORMAT_12BITS CTL_DCIF(2) /*!< 12-bit data on every pixel clock */
  110. #define DCI_INTERFACE_FORMAT_14BITS CTL_DCIF(3) /*!< 14-bit data on every pixel clock */
  111. /* DCI interrupt constants definitions */
  112. #define DCI_INT_EF ((uint32_t)0x00000001U) /*!< end of frame interrupt */
  113. #define DCI_INT_OVR ((uint32_t)0x00000002U) /*!< FIFO overrun interrupt */
  114. #define DCI_INT_ESE ((uint32_t)0x00000004U) /*!< embedded synchronous error interrupt */
  115. #define DCI_INT_VS ((uint32_t)0x00000008U) /*!< vsync interrupt */
  116. #define DCI_INT_EL ((uint32_t)0x00000010U) /*!< end of line interrupt */
  117. /* DCI flag definitions */
  118. #define DCI_FLAG_HS ((uint8_t)0x01U) /*!< HS line status */
  119. #define DCI_FLAG_VS ((uint8_t)0x02U) /*!< VS line status */
  120. #define DCI_FLAG_FV ((uint8_t)0x03U) /*!< FIFO valid */
  121. #define DCI_FLAG_EFF ((uint8_t)0x04U) /*!< end of frame flag */
  122. #define DCI_FLAG_OVRF ((uint8_t)0x05U) /*!< FIFO overrun flag */
  123. #define DCI_FLAG_ESEF ((uint8_t)0x06U) /*!< embedded synchronous error flag */
  124. #define DCI_FLAG_VSF ((uint8_t)0x07U) /*!< vsync flag */
  125. #define DCI_FLAG_ELF ((uint8_t)0x08U) /*!< end of line flag */
  126. /* function declarations */
  127. /* DCI deinit */
  128. void dci_deinit(void);
  129. /* initialize DCI registers */
  130. void dci_init(dci_parameter_struct* dci_struct);
  131. /* enable DCI function */
  132. void dci_enable(void);
  133. /* disble DCI function */
  134. void dci_disable(void);
  135. /* enable DCI capture */
  136. void dci_capture_enable(void);
  137. /* disble DCI capture */
  138. void dci_capture_disable(void);
  139. /* enable DCI jpeg mode */
  140. void dci_jpeg_enable(void);
  141. /* disble DCI jpeg mode */
  142. void dci_jpeg_disable(void);
  143. /* enable cropping window function */
  144. void dci_crop_window_enable(void);
  145. /* disble cropping window function */
  146. void dci_crop_window_disable(void);
  147. /* config DCI cropping window */
  148. void dci_crop_window_config(uint16_t start_x, uint16_t start_y, uint16_t size_width, uint16_t size_height);
  149. /* enable sync codes function */
  150. void dci_sync_codes_enable(void);
  151. /* disble sync codes function */
  152. void dci_sync_codes_disable(void);
  153. /* config sync codes */
  154. void dci_sync_codes_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end);
  155. /* config sync codes unmask */
  156. void dci_sync_codes_unmask_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end);
  157. /* read DCI data register */
  158. uint32_t dci_data_read(void);
  159. /* enable specified DCI interrupt */
  160. void dci_interrupt_enable(uint32_t interrupt);
  161. /* disble specified DCI interrupt */
  162. void dci_interrupt_disable(uint32_t interrupt);
  163. /* clear specified interrupt */
  164. void dci_interrupt_clear(uint32_t interrupt);
  165. /* get specified flag */
  166. FlagStatus dci_flag_get(uint32_t flag);
  167. /* get specified interrupt flag */
  168. FlagStatus dci_interrupt_flag_get(uint32_t interrupt);
  169. #endif /* GD32F4XX_DCI_H */