stm32f2xx_dcmi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. ******************************************************************************
  3. * @file stm32f2xx_dcmi.h
  4. * @author MCD Application Team
  5. * @version V1.1.3
  6. * @date 31-December-2021
  7. * @brief This file contains all the functions prototypes for the DCMI firmware library.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * Copyright (c) 2012 STMicroelectronics.
  12. * All rights reserved.
  13. *
  14. * This software is licensed under terms that can be found in the LICENSE file
  15. * in the root directory of this software component.
  16. * If no LICENSE file comes with this software, it is provided AS-IS.
  17. *
  18. ******************************************************************************
  19. */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef __STM32F2xx_DCMI_H
  22. #define __STM32F2xx_DCMI_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "stm32f2xx.h"
  28. /** @addtogroup STM32F2xx_StdPeriph_Driver
  29. * @{
  30. */
  31. /** @addtogroup DCMI
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /**
  36. * @brief DCMI Init structure definition
  37. */
  38. typedef struct
  39. {
  40. uint16_t DCMI_CaptureMode; /*!< Specifies the Capture Mode: Continuous or Snapshot.
  41. This parameter can be a value of @ref DCMI_Capture_Mode */
  42. uint16_t DCMI_SynchroMode; /*!< Specifies the Synchronization Mode: Hardware or Embedded.
  43. This parameter can be a value of @ref DCMI_Synchronization_Mode */
  44. uint16_t DCMI_PCKPolarity; /*!< Specifies the Pixel clock polarity: Falling or Rising.
  45. This parameter can be a value of @ref DCMI_PIXCK_Polarity */
  46. uint16_t DCMI_VSPolarity; /*!< Specifies the Vertical synchronization polarity: High or Low.
  47. This parameter can be a value of @ref DCMI_VSYNC_Polarity */
  48. uint16_t DCMI_HSPolarity; /*!< Specifies the Horizontal synchronization polarity: High or Low.
  49. This parameter can be a value of @ref DCMI_HSYNC_Polarity */
  50. uint16_t DCMI_CaptureRate; /*!< Specifies the frequency of frame capture: All, 1/2 or 1/4.
  51. This parameter can be a value of @ref DCMI_Capture_Rate */
  52. uint16_t DCMI_ExtendedDataMode; /*!< Specifies the data width: 8-bit, 10-bit, 12-bit or 14-bit.
  53. This parameter can be a value of @ref DCMI_Extended_Data_Mode */
  54. } DCMI_InitTypeDef;
  55. /**
  56. * @brief DCMI CROP Init structure definition
  57. */
  58. typedef struct
  59. {
  60. uint16_t DCMI_VerticalStartLine; /*!< Specifies the Vertical start line count from which the image capture
  61. will start. This parameter can be a value between 0x00 and 0x1FFF */
  62. uint16_t DCMI_HorizontalOffsetCount; /*!< Specifies the number of pixel clocks to count before starting a capture.
  63. This parameter can be a value between 0x00 and 0x3FFF */
  64. uint16_t DCMI_VerticalLineCount; /*!< Specifies the number of lines to be captured from the starting point.
  65. This parameter can be a value between 0x00 and 0x3FFF */
  66. uint16_t DCMI_CaptureCount; /*!< Specifies the number of pixel clocks to be captured from the starting
  67. point on the same line.
  68. This parameter can be a value between 0x00 and 0x3FFF */
  69. } DCMI_CROPInitTypeDef;
  70. /**
  71. * @brief DCMI Embedded Synchronisation CODE Init structure definition
  72. */
  73. typedef struct
  74. {
  75. uint8_t DCMI_FrameStartCode; /*!< Specifies the code of the frame start delimiter. */
  76. uint8_t DCMI_LineStartCode; /*!< Specifies the code of the line start delimiter. */
  77. uint8_t DCMI_LineEndCode; /*!< Specifies the code of the line end delimiter. */
  78. uint8_t DCMI_FrameEndCode; /*!< Specifies the code of the frame end delimiter. */
  79. } DCMI_CodesInitTypeDef;
  80. /* Exported constants --------------------------------------------------------*/
  81. /** @defgroup DCMI_Exported_Constants
  82. * @{
  83. */
  84. /** @defgroup DCMI_Capture_Mode
  85. * @{
  86. */
  87. #define DCMI_CaptureMode_Continuous ((uint16_t)0x0000) /*!< The received data are transferred continuously
  88. into the destination memory through the DMA */
  89. #define DCMI_CaptureMode_SnapShot ((uint16_t)0x0002) /*!< Once activated, the interface waits for the start of
  90. frame and then transfers a single frame through the DMA */
  91. #define IS_DCMI_CAPTURE_MODE(MODE)(((MODE) == DCMI_CaptureMode_Continuous) || \
  92. ((MODE) == DCMI_CaptureMode_SnapShot))
  93. /**
  94. * @}
  95. */
  96. /** @defgroup DCMI_Synchronization_Mode
  97. * @{
  98. */
  99. #define DCMI_SynchroMode_Hardware ((uint16_t)0x0000) /*!< Hardware synchronization data capture (frame/line start/stop)
  100. is synchronized with the HSYNC/VSYNC signals */
  101. #define DCMI_SynchroMode_Embedded ((uint16_t)0x0010) /*!< Embedded synchronization data capture is synchronized with
  102. synchronization codes embedded in the data flow */
  103. #define IS_DCMI_SYNCHRO(MODE)(((MODE) == DCMI_SynchroMode_Hardware) || \
  104. ((MODE) == DCMI_SynchroMode_Embedded))
  105. /**
  106. * @}
  107. */
  108. /** @defgroup DCMI_PIXCK_Polarity
  109. * @{
  110. */
  111. #define DCMI_PCKPolarity_Falling ((uint16_t)0x0000) /*!< Pixel clock active on Falling edge */
  112. #define DCMI_PCKPolarity_Rising ((uint16_t)0x0020) /*!< Pixel clock active on Rising edge */
  113. #define IS_DCMI_PCKPOLARITY(POLARITY)(((POLARITY) == DCMI_PCKPolarity_Falling) || \
  114. ((POLARITY) == DCMI_PCKPolarity_Rising))
  115. /**
  116. * @}
  117. */
  118. /** @defgroup DCMI_VSYNC_Polarity
  119. * @{
  120. */
  121. #define DCMI_VSPolarity_Low ((uint16_t)0x0000) /*!< Vertical synchronization active Low */
  122. #define DCMI_VSPolarity_High ((uint16_t)0x0080) /*!< Vertical synchronization active High */
  123. #define IS_DCMI_VSPOLARITY(POLARITY)(((POLARITY) == DCMI_VSPolarity_Low) || \
  124. ((POLARITY) == DCMI_VSPolarity_High))
  125. /**
  126. * @}
  127. */
  128. /** @defgroup DCMI_HSYNC_Polarity
  129. * @{
  130. */
  131. #define DCMI_HSPolarity_Low ((uint16_t)0x0000) /*!< Horizontal synchronization active Low */
  132. #define DCMI_HSPolarity_High ((uint16_t)0x0040) /*!< Horizontal synchronization active High */
  133. #define IS_DCMI_HSPOLARITY(POLARITY)(((POLARITY) == DCMI_HSPolarity_Low) || \
  134. ((POLARITY) == DCMI_HSPolarity_High))
  135. /**
  136. * @}
  137. */
  138. /** @defgroup DCMI_Capture_Rate
  139. * @{
  140. */
  141. #define DCMI_CaptureRate_All_Frame ((uint16_t)0x0000) /*!< All frames are captured */
  142. #define DCMI_CaptureRate_1of2_Frame ((uint16_t)0x0100) /*!< Every alternate frame captured */
  143. #define DCMI_CaptureRate_1of4_Frame ((uint16_t)0x0200) /*!< One frame in 4 frames captured */
  144. #define IS_DCMI_CAPTURE_RATE(RATE) (((RATE) == DCMI_CaptureRate_All_Frame) || \
  145. ((RATE) == DCMI_CaptureRate_1of2_Frame) ||\
  146. ((RATE) == DCMI_CaptureRate_1of4_Frame))
  147. /**
  148. * @}
  149. */
  150. /** @defgroup DCMI_Extended_Data_Mode
  151. * @{
  152. */
  153. #define DCMI_ExtendedDataMode_8b ((uint16_t)0x0000) /*!< Interface captures 8-bit data on every pixel clock */
  154. #define DCMI_ExtendedDataMode_10b ((uint16_t)0x0400) /*!< Interface captures 10-bit data on every pixel clock */
  155. #define DCMI_ExtendedDataMode_12b ((uint16_t)0x0800) /*!< Interface captures 12-bit data on every pixel clock */
  156. #define DCMI_ExtendedDataMode_14b ((uint16_t)0x0C00) /*!< Interface captures 14-bit data on every pixel clock */
  157. #define IS_DCMI_EXTENDED_DATA(DATA)(((DATA) == DCMI_ExtendedDataMode_8b) || \
  158. ((DATA) == DCMI_ExtendedDataMode_10b) ||\
  159. ((DATA) == DCMI_ExtendedDataMode_12b) ||\
  160. ((DATA) == DCMI_ExtendedDataMode_14b))
  161. /**
  162. * @}
  163. */
  164. /** @defgroup DCMI_interrupt_sources
  165. * @{
  166. */
  167. #define DCMI_IT_FRAME ((uint16_t)0x0001)
  168. #define DCMI_IT_OVF ((uint16_t)0x0002)
  169. #define DCMI_IT_ERR ((uint16_t)0x0004)
  170. #define DCMI_IT_VSYNC ((uint16_t)0x0008)
  171. #define DCMI_IT_LINE ((uint16_t)0x0010)
  172. #define IS_DCMI_CONFIG_IT(IT) ((((IT) & (uint16_t)0xFFE0) == 0x0000) && ((IT) != 0x0000))
  173. #define IS_DCMI_GET_IT(IT) (((IT) == DCMI_IT_FRAME) || \
  174. ((IT) == DCMI_IT_OVF) || \
  175. ((IT) == DCMI_IT_ERR) || \
  176. ((IT) == DCMI_IT_VSYNC) || \
  177. ((IT) == DCMI_IT_LINE))
  178. /**
  179. * @}
  180. */
  181. /** @defgroup DCMI_Flags
  182. * @{
  183. */
  184. /**
  185. * @brief DCMI SR register
  186. */
  187. #define DCMI_FLAG_HSYNC ((uint16_t)0x2001)
  188. #define DCMI_FLAG_VSYNC ((uint16_t)0x2002)
  189. #define DCMI_FLAG_FNE ((uint16_t)0x2004)
  190. /**
  191. * @brief DCMI RISR register
  192. */
  193. #define DCMI_FLAG_FRAMERI ((uint16_t)0x0001)
  194. #define DCMI_FLAG_OVFRI ((uint16_t)0x0002)
  195. #define DCMI_FLAG_ERRRI ((uint16_t)0x0004)
  196. #define DCMI_FLAG_VSYNCRI ((uint16_t)0x0008)
  197. #define DCMI_FLAG_LINERI ((uint16_t)0x0010)
  198. /**
  199. * @brief DCMI MISR register
  200. */
  201. #define DCMI_FLAG_FRAMEMI ((uint16_t)0x1001)
  202. #define DCMI_FLAG_OVFMI ((uint16_t)0x1002)
  203. #define DCMI_FLAG_ERRMI ((uint16_t)0x1004)
  204. #define DCMI_FLAG_VSYNCMI ((uint16_t)0x1008)
  205. #define DCMI_FLAG_LINEMI ((uint16_t)0x1010)
  206. #define IS_DCMI_GET_FLAG(FLAG) (((FLAG) == DCMI_FLAG_HSYNC) || \
  207. ((FLAG) == DCMI_FLAG_VSYNC) || \
  208. ((FLAG) == DCMI_FLAG_FNE) || \
  209. ((FLAG) == DCMI_FLAG_FRAMERI) || \
  210. ((FLAG) == DCMI_FLAG_OVFRI) || \
  211. ((FLAG) == DCMI_FLAG_ERRRI) || \
  212. ((FLAG) == DCMI_FLAG_VSYNCRI) || \
  213. ((FLAG) == DCMI_FLAG_LINERI) || \
  214. ((FLAG) == DCMI_FLAG_FRAMEMI) || \
  215. ((FLAG) == DCMI_FLAG_OVFMI) || \
  216. ((FLAG) == DCMI_FLAG_ERRMI) || \
  217. ((FLAG) == DCMI_FLAG_VSYNCMI) || \
  218. ((FLAG) == DCMI_FLAG_LINEMI))
  219. #define IS_DCMI_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFE0) == 0x0000) && ((FLAG) != 0x0000))
  220. /**
  221. * @}
  222. */
  223. /**
  224. * @}
  225. */
  226. /* Exported macro ------------------------------------------------------------*/
  227. /* Exported functions --------------------------------------------------------*/
  228. /* Function used to set the DCMI configuration to the default reset state ****/
  229. void DCMI_DeInit(void);
  230. /* Initialization and Configuration functions *********************************/
  231. void DCMI_Init(DCMI_InitTypeDef* DCMI_InitStruct);
  232. void DCMI_StructInit(DCMI_InitTypeDef* DCMI_InitStruct);
  233. void DCMI_CROPConfig(DCMI_CROPInitTypeDef* DCMI_CROPInitStruct);
  234. void DCMI_CROPCmd(FunctionalState NewState);
  235. void DCMI_SetEmbeddedSynchroCodes(DCMI_CodesInitTypeDef* DCMI_CodesInitStruct);
  236. void DCMI_JPEGCmd(FunctionalState NewState);
  237. /* Image capture functions ****************************************************/
  238. void DCMI_Cmd(FunctionalState NewState);
  239. void DCMI_CaptureCmd(FunctionalState NewState);
  240. uint32_t DCMI_ReadData(void);
  241. /* Interrupts and flags management functions **********************************/
  242. void DCMI_ITConfig(uint16_t DCMI_IT, FunctionalState NewState);
  243. FlagStatus DCMI_GetFlagStatus(uint16_t DCMI_FLAG);
  244. void DCMI_ClearFlag(uint16_t DCMI_FLAG);
  245. ITStatus DCMI_GetITStatus(uint16_t DCMI_IT);
  246. void DCMI_ClearITPendingBit(uint16_t DCMI_IT);
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250. #endif /*__STM32F2xx_DCMI_H */
  251. /**
  252. * @}
  253. */
  254. /**
  255. * @}
  256. */