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