dvp.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* Copyright 2018 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _DRIVER_DVP_H
  16. #define _DRIVER_DVP_H
  17. #include <stdint.h>
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* clang-format off */
  22. /**
  23. * @brief DVP object
  24. */
  25. typedef struct _dvp
  26. {
  27. uint32_t dvp_cfg;
  28. uint32_t r_addr;
  29. uint32_t g_addr;
  30. uint32_t b_addr;
  31. uint32_t cmos_cfg;
  32. uint32_t sccb_cfg;
  33. uint32_t sccb_ctl;
  34. uint32_t axi;
  35. uint32_t sts;
  36. uint32_t reverse;
  37. uint32_t rgb_addr;
  38. } __attribute__((packed, aligned(4))) dvp_t;
  39. /* DVP Config Register */
  40. #define DVP_CFG_START_INT_ENABLE 0x00000001U
  41. #define DVP_CFG_FINISH_INT_ENABLE 0x00000002U
  42. #define DVP_CFG_AI_OUTPUT_ENABLE 0x00000004U
  43. #define DVP_CFG_DISPLAY_OUTPUT_ENABLE 0x00000008U
  44. #define DVP_CFG_AUTO_ENABLE 0x00000010U
  45. #define DVP_CFG_BURST_SIZE_4BEATS 0x00000100U
  46. #define DVP_CFG_FORMAT_MASK 0x00000600U
  47. #define DVP_CFG_RGB_FORMAT 0x00000000U
  48. #define DVP_CFG_YUV_FORMAT 0x00000200U
  49. #define DVP_CFG_Y_FORMAT 0x00000600U
  50. #define DVP_CFG_HREF_BURST_NUM_MASK 0x000FF000U
  51. #define DVP_CFG_HREF_BURST_NUM(x) ((x) << 12)
  52. #define DVP_CFG_LINE_NUM_MASK 0x3FF00000U
  53. #define DVP_CFG_LINE_NUM(x) ((x) << 20)
  54. /* DVP CMOS Config Register */
  55. #define DVP_CMOS_CLK_DIV_MASK 0x000000FFU
  56. #define DVP_CMOS_CLK_DIV(x) ((x) << 0)
  57. #define DVP_CMOS_CLK_ENABLE 0x00000100U
  58. #define DVP_CMOS_RESET 0x00010000U
  59. #define DVP_CMOS_POWER_DOWN 0x01000000U
  60. /* DVP SCCB Config Register */
  61. #define DVP_SCCB_BYTE_NUM_MASK 0x00000003U
  62. #define DVP_SCCB_BYTE_NUM_2 0x00000001U
  63. #define DVP_SCCB_BYTE_NUM_3 0x00000002U
  64. #define DVP_SCCB_BYTE_NUM_4 0x00000003U
  65. #define DVP_SCCB_SCL_LCNT_MASK 0x0000FF00U
  66. #define DVP_SCCB_SCL_LCNT(x) ((x) << 8)
  67. #define DVP_SCCB_SCL_HCNT_MASK 0x00FF0000U
  68. #define DVP_SCCB_SCL_HCNT(x) ((x) << 16)
  69. #define DVP_SCCB_RDATA_BYTE(x) ((x) >> 24)
  70. /* DVP SCCB Control Register */
  71. #define DVP_SCCB_WRITE_DATA_ENABLE 0x00000001U
  72. #define DVP_SCCB_DEVICE_ADDRESS(x) ((x) << 0)
  73. #define DVP_SCCB_REG_ADDRESS(x) ((x) << 8)
  74. #define DVP_SCCB_WDATA_BYTE0(x) ((x) << 16)
  75. #define DVP_SCCB_WDATA_BYTE1(x) ((x) << 24)
  76. /* DVP AXI Register */
  77. #define DVP_AXI_GM_MLEN_MASK 0x000000FFU
  78. #define DVP_AXI_GM_MLEN_1BYTE 0x00000000U
  79. #define DVP_AXI_GM_MLEN_4BYTE 0x00000003U
  80. /* DVP STS Register */
  81. #define DVP_STS_FRAME_START 0x00000001U
  82. #define DVP_STS_FRAME_START_WE 0x00000002U
  83. #define DVP_STS_FRAME_FINISH 0x00000100U
  84. #define DVP_STS_FRAME_FINISH_WE 0x00000200U
  85. #define DVP_STS_DVP_EN 0x00010000U
  86. #define DVP_STS_DVP_EN_WE 0x00020000U
  87. #define DVP_STS_SCCB_EN 0x01000000U
  88. #define DVP_STS_SCCB_EN_WE 0x02000000U
  89. /* clang-format on */
  90. typedef enum _dvp_output_mode
  91. {
  92. DVP_OUTPUT_AI,
  93. DVP_OUTPUT_DISPLAY,
  94. } dvp_output_mode_t;
  95. /**
  96. * @brief DVP object instance
  97. */
  98. extern volatile dvp_t *const dvp;
  99. /**
  100. * @brief Initialize DVP
  101. */
  102. void dvp_init(uint8_t reg_len);
  103. /**
  104. * @brief Set image format
  105. *
  106. * @param[in] format The image format
  107. */
  108. void dvp_set_image_format(uint32_t format);
  109. /**
  110. * @brief Set image size
  111. *
  112. * @param[in] width The width of image
  113. * @param[in] height The height of image
  114. */
  115. void dvp_set_image_size(uint32_t width, uint32_t height);
  116. /**
  117. * @brief Set the address of RGB for AI
  118. *
  119. * @param[in] r_addr The R address of RGB
  120. * @param[in] g_addr The G address of RGB
  121. * @param[in] b_addr The B address of RGB
  122. */
  123. void dvp_set_ai_addr(uint32_t r_addr, uint32_t g_addr, uint32_t b_addr);
  124. /**
  125. * @brief Set the address of RGB for display
  126. *
  127. * @param[in] r_addr The R address of RGB
  128. * @param[in] g_addr The G address of RGB
  129. * @param[in] b_addr The B address of RGB
  130. */
  131. void dvp_set_display_addr(uint32_t addr);
  132. /**
  133. * @brief The frame start transfer
  134. */
  135. void dvp_start_frame(void);
  136. /**
  137. * @brief The DVP convert start
  138. */
  139. void dvp_start_convert(void);
  140. /**
  141. * @brief The DVP convert finish
  142. */
  143. void dvp_finish_convert(void);
  144. /**
  145. * @brief Get the image data
  146. *
  147. * @note The image data stored in the address of RGB
  148. */
  149. void dvp_get_image(void);
  150. /**
  151. * @brief Use SCCB write register
  152. *
  153. * @param[in] dev_addr The device address
  154. * @param[in] reg_addr The register address
  155. * @param[in] reg_data The register data
  156. */
  157. void dvp_sccb_send_data(uint8_t dev_addr, uint16_t reg_addr, uint8_t reg_data);
  158. /**
  159. * @brief Use SCCB read register
  160. *
  161. * @param[in] dev_addr The device address
  162. * @param[in] reg_addr The register address
  163. *
  164. * @return The register value
  165. */
  166. uint8_t dvp_sccb_receive_data(uint8_t dev_addr, uint16_t reg_addr);
  167. /**
  168. * @brief Enable dvp burst
  169. */
  170. void dvp_enable_burst(void);
  171. /**
  172. * @brief Disable dvp burst
  173. */
  174. void dvp_disable_burst(void);
  175. /**
  176. * @brief Enable or disable dvp interrupt
  177. *
  178. * @param[in] interrupt Dvp interrupt
  179. * @param[in] status 0:disable 1:enable
  180. *
  181. */
  182. void dvp_config_interrupt(uint32_t interrupt, uint8_t enable);
  183. /**
  184. * @brief Get dvp interrupt status
  185. *
  186. * @param[in] interrupt Dvp interrupt
  187. *
  188. *
  189. * @return Interrupt status
  190. * - 0 false
  191. * - 1 true
  192. */
  193. int dvp_get_interrupt(uint32_t interrupt);
  194. /**
  195. * @brief Clear dvp interrupt status
  196. *
  197. * @param[in] interrupt Dvp interrupt
  198. *
  199. */
  200. void dvp_clear_interrupt(uint32_t interrupt);
  201. /**
  202. * @brief Enable dvp auto mode
  203. */
  204. void dvp_enable_auto(void);
  205. /**
  206. * @brief Disable dvp auto mode
  207. */
  208. void dvp_disable_auto(void);
  209. /**
  210. * @brief Dvp ouput data enable or not
  211. *
  212. * @param[in] index 0:AI, 1:display
  213. * @param[in] enable 0:disable, 1:enable
  214. *
  215. */
  216. void dvp_set_output_enable(dvp_output_mode_t index, int enable);
  217. /**
  218. * @brief Set sccb clock rate
  219. *
  220. * @param[in] clk_rate Sccb clock rate
  221. *
  222. * @return The real sccb clock rate
  223. */
  224. uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate);
  225. /**
  226. * @brief Set xclk rate
  227. *
  228. * @param[in] clk_rate xclk rate
  229. *
  230. * @return The real xclk rate
  231. */
  232. uint32_t dvp_set_xclk_rate(uint32_t xclk_rate);
  233. #ifdef __cplusplus
  234. }
  235. #endif
  236. #endif /* _DRIVER_DVP_H */