1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_hal_dcmi.h
4   * @author  MCD Application Team
5   * @brief   Header file of DCMI HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35 
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32L4xx_HAL_DCMI_H
38 #define __STM32L4xx_HAL_DCMI_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32l4xx_hal_def.h"
46 
47 #if defined (DCMI)
48 
49 /** @addtogroup STM32L4xx_HAL_Driver
50   * @{
51   */
52 
53 /** @addtogroup DCMI DCMI
54   * @brief DCMI HAL module driver
55   * @{
56   */
57 
58 /* Exported types ------------------------------------------------------------*/
59 /** @defgroup DCMI_Exported_Types DCMI Exported Types
60   * @{
61   */
62 
63 /**
64   * @brief   DCMI Embedded Synchronisation CODE Init structure definition
65   */
66 typedef struct
67 {
68   uint8_t FrameStartCode; /*!< Specifies the code of the frame start delimiter. */
69   uint8_t LineStartCode;  /*!< Specifies the code of the line start delimiter.  */
70   uint8_t LineEndCode;    /*!< Specifies the code of the line end delimiter.    */
71   uint8_t FrameEndCode;   /*!< Specifies the code of the frame end delimiter.   */
72 }DCMI_CodesInitTypeDef;
73 
74 
75 /**
76   * @brief   DCMI Embedded Synchronisation CODE Init structure definition
77   */
78 typedef struct
79 {
80   uint8_t FrameStartUnmask; /*!< Specifies the frame start delimiter unmask. */
81   uint8_t LineStartUnmask;  /*!< Specifies the line start delimiter unmask.  */
82   uint8_t LineEndUnmask;    /*!< Specifies the line end delimiter unmask.    */
83   uint8_t FrameEndUnmask;   /*!< Specifies the frame end delimiter unmask.   */
84 }DCMI_SyncUnmaskTypeDef;
85 
86 
87 /**
88   * @brief   DCMI Init structure definition
89   */
90 typedef struct
91 {
92   uint32_t  SynchroMode;                /*!< Specifies the Synchronization Mode: Hardware or Embedded.
93                                              This parameter can be a value of @ref DCMI_Synchronization_Mode */
94 
95   uint32_t  PCKPolarity;                /*!< Specifies the Pixel clock polarity: Falling or Rising.
96                                              This parameter can be a value of @ref DCMI_PIXCK_Polarity       */
97 
98   uint32_t  VSPolarity;                 /*!< Specifies the Vertical synchronization polarity: High or Low.
99                                              This parameter can be a value of @ref DCMI_VSYNC_Polarity       */
100 
101   uint32_t  HSPolarity;                 /*!< Specifies the Horizontal synchronization polarity: High or Low.
102                                              This parameter can be a value of @ref DCMI_HSYNC_Polarity       */
103 
104   uint32_t  CaptureRate;                /*!< Specifies the frequency of frame capture: All, 1/2 or 1/4.
105                                              This parameter can be a value of @ref DCMI_Capture_Rate         */
106 
107   uint32_t  ExtendedDataMode;           /*!< Specifies the data width: 8-bit, 10-bit, 12-bit or 14-bit.
108                                              This parameter can be a value of @ref DCMI_Extended_Data_Mode   */
109 
110   DCMI_CodesInitTypeDef SynchroCode;    /*!< Specifies the frame start delimiter codes.                       */
111 
112   uint32_t JPEGMode;                    /*!< Enable or Disable the JPEG mode.
113                                              This parameter can be a value of @ref DCMI_MODE_JPEG            */
114 
115   uint32_t ByteSelectMode;              /*!< Specifies the data to be captured by the interface
116                                             This parameter can be a value of @ref DCMI_Byte_Select_Mode      */
117 
118   uint32_t ByteSelectStart;             /*!< Specifies if the data to be captured by the interface is even or odd
119                                             This parameter can be a value of @ref DCMI_Byte_Select_Start     */
120 
121   uint32_t LineSelectMode;              /*!< Specifies the line of data to be captured by the interface
122                                             This parameter can be a value of @ref DCMI_Line_Select_Mode      */
123 
124   uint32_t LineSelectStart;             /*!< Specifies if the line of data to be captured by the interface is even or odd
125                                             This parameter can be a value of @ref DCMI_Line_Select_Start     */
126 }DCMI_InitTypeDef;
127 
128 
129 /**
130   * @brief  HAL DCMI State structures definition
131   */
132 typedef enum
133 {
134   HAL_DCMI_STATE_RESET             = 0x00U,  /*!< DCMI not yet initialized or disabled  */
135   HAL_DCMI_STATE_READY             = 0x01U,  /*!< DCMI initialized and ready for use    */
136   HAL_DCMI_STATE_BUSY              = 0x02U,  /*!< DCMI internal processing is ongoing   */
137   HAL_DCMI_STATE_TIMEOUT           = 0x03U,  /*!< DCMI timeout state                    */
138   HAL_DCMI_STATE_ERROR             = 0x04U,  /*!< DCMI error state                      */
139   HAL_DCMI_STATE_SUSPENDED         = 0x05U   /*!< DCMI suspend state                    */
140 }HAL_DCMI_StateTypeDef;
141 
142 
143 /**
144   * @brief  DCMI handle Structure definition
145   */
146 typedef struct __DCMI_HandleTypeDef
147 {
148   DCMI_TypeDef                  *Instance;           /*!< DCMI Register base address   */
149 
150   DCMI_InitTypeDef              Init;                /*!< DCMI init parameters         */
151 
152   HAL_LockTypeDef               Lock;                /*!< DCMI locking object          */
153 
154   __IO HAL_DCMI_StateTypeDef    State;               /*!< DCMI state                   */
155 
156   __IO uint32_t                 XferCount;           /*!< DMA transfers counter        */
157 
158   __IO uint32_t                 XferSize;            /*!< DMA transfer size            */
159 
160   uint32_t                      pBuffPtr;            /*!< Pointer to DMA output buffer */
161 
162   DMA_HandleTypeDef             *DMA_Handle;         /*!< Pointer to DMA handler       */
163 
164   DMA_HandleTypeDef             *DMAM2M_Handle;      /*!< Pointer to DMA handler for memory to memory copy
165                                                         (case picture size >  maximum DMA transfer length) */
166 
167   __IO uint32_t                 ErrorCode;           /*!< DCMI Error code              */
168 
169   uint32_t                      pCircularBuffer;     /*!< Pointer to intermediate copy buffer
170                                                         (case picture size >  maximum DMA transfer length) */
171 
172   uint32_t                      HalfCopyLength;      /*!< Intermediate copies length
173                                                         (case picture size >  maximum DMA transfer length) */
174 
175 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
176   void    (* FrameEventCallback) ( struct __DCMI_HandleTypeDef *hdcmi);  /*!< DCMI Frame Event Callback */
177   void    (* VsyncEventCallback) ( struct __DCMI_HandleTypeDef *hdcmi);  /*!< DCMI Vsync Event Callback */
178   void    (* LineEventCallback ) ( struct __DCMI_HandleTypeDef *hdcmi);  /*!< DCMI Line Event Callback  */
179   void    (* ErrorCallback)      ( struct __DCMI_HandleTypeDef *hdcmi);  /*!< DCMI Error Callback       */
180   void    (* MspInitCallback)    ( struct __DCMI_HandleTypeDef *hdcmi);  /*!< DCMI Msp Init callback    */
181   void    (* MspDeInitCallback)  ( struct __DCMI_HandleTypeDef *hdcmi);  /*!< DCMI Msp DeInit callback  */
182 #endif  /* USE_HAL_DCMI_REGISTER_CALLBACKS */
183 
184 }DCMI_HandleTypeDef;
185 
186 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
187 typedef enum
188 {
189   HAL_DCMI_FRAME_EVENT_CB_ID    = 0x00U,    /*!< DCMI Frame Event Callback ID */
190   HAL_DCMI_VSYNC_EVENT_CB_ID    = 0x01U,    /*!< DCMI Vsync Event Callback ID */
191   HAL_DCMI_LINE_EVENT_CB_ID     = 0x02U,    /*!< DCMI Line Event Callback ID  */
192   HAL_DCMI_ERROR_CB_ID          = 0x03U,    /*!< DCMI Error Callback ID       */
193   HAL_DCMI_MSPINIT_CB_ID        = 0x04U,    /*!< DCMI MspInit callback ID     */
194   HAL_DCMI_MSPDEINIT_CB_ID      = 0x05U     /*!< DCMI MspDeInit callback ID   */
195 
196 }HAL_DCMI_CallbackIDTypeDef;
197 
198 typedef void (*pDCMI_CallbackTypeDef)(DCMI_HandleTypeDef *hdcmi);
199 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
200 
201 /**
202   * @}
203   */
204 
205 /* Exported constants --------------------------------------------------------*/
206 /** @defgroup DCMI_Exported_Constants DCMI Exported Constants
207   * @{
208   */
209 
210 /** @defgroup DCMI_Error_Code DCMI Error Code
211   * @{
212   */
213 #define HAL_DCMI_ERROR_NONE             ((uint32_t)0x00000000U)  /*!< No error              */
214 #define HAL_DCMI_ERROR_OVR              ((uint32_t)0x00000001U)  /*!< Overrun error         */
215 #define HAL_DCMI_ERROR_SYNC             ((uint32_t)0x00000002U)  /*!< Synchronization error */
216 #define HAL_DCMI_ERROR_TIMEOUT          ((uint32_t)0x00000020U)  /*!< Timeout error         */
217 #define HAL_DCMI_ERROR_DMA              ((uint32_t)0x00000040U)  /*!< DMA error             */
218 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
219 #define HAL_DCMI_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U)  /*!< Invalid callback error */
220 #endif
221 /**
222   * @}
223   */
224 
225 /** @defgroup DCMI_Capture_Mode DCMI Capture Mode
226   * @{
227   */
228 #define DCMI_MODE_CONTINUOUS           ((uint32_t)0x00000000U) /*!< The received data are transferred continuously
229                                                                     into the destination memory through the DMA             */
230 #define DCMI_MODE_SNAPSHOT             ((uint32_t)DCMI_CR_CM)  /*!< Once activated, the interface waits for the start of
231                                                                     frame and then transfers a single frame through the DMA */
232 /**
233   * @}
234   */
235 
236 /** @defgroup DCMI_Synchronization_Mode DCMI Synchronization Mode
237   * @{
238   */
239 #define DCMI_SYNCHRO_HARDWARE        ((uint32_t)0x00000000U)  /*!< Hardware synchronization data capture (frame/line start/stop)
240                                                                    is synchronized with the HSYNC/VSYNC signals                  */
241 #define DCMI_SYNCHRO_EMBEDDED        ((uint32_t)DCMI_CR_ESS)  /*!< Embedded synchronization data capture is synchronized with
242                                                                    synchronization codes embedded in the data flow               */
243 
244 /**
245   * @}
246   */
247 
248 /** @defgroup DCMI_PIXCK_Polarity DCMI Pixel Clock Polarity
249   * @{
250   */
251 #define DCMI_PCKPOLARITY_FALLING    ((uint32_t)0x00000000U)     /*!< Pixel clock active on Falling edge */
252 #define DCMI_PCKPOLARITY_RISING     ((uint32_t)DCMI_CR_PCKPOL)  /*!< Pixel clock active on Rising edge  */
253 
254 /**
255   * @}
256   */
257 
258 /** @defgroup DCMI_VSYNC_Polarity DCMI VSYNC Polarity
259   * @{
260   */
261 #define DCMI_VSPOLARITY_LOW     ((uint32_t)0x00000000U)    /*!< Vertical synchronization active Low  */
262 #define DCMI_VSPOLARITY_HIGH    ((uint32_t)DCMI_CR_VSPOL)  /*!< Vertical synchronization active High */
263 
264 /**
265   * @}
266   */
267 
268 /** @defgroup DCMI_HSYNC_Polarity DCMI HSYNC Polarity
269   * @{
270   */
271 #define DCMI_HSPOLARITY_LOW     ((uint32_t)0x00000000U)    /*!< Horizontal synchronization active Low  */
272 #define DCMI_HSPOLARITY_HIGH    ((uint32_t)DCMI_CR_HSPOL)  /*!< Horizontal synchronization active High */
273 
274 /**
275   * @}
276   */
277 
278 /** @defgroup DCMI_JPEG_Mode DCMI JPEG Mode
279   * @{
280   */
281 #define DCMI_JPEG_DISABLE   ((uint32_t)0x00000000U)   /*!< JPEG mode disabled  */
282 #define DCMI_JPEG_ENABLE    ((uint32_t)DCMI_CR_JPEG)  /*!< JPEG mode enabled   */
283 
284 /**
285   * @}
286   */
287 
288 /** @defgroup DCMI_Capture_Rate DCMI Capture Rate
289   * @{
290   */
291 #define DCMI_CR_ALL_FRAME            ((uint32_t)0x00000000U)     /*!< All frames are captured        */
292 #define DCMI_CR_ALTERNATE_2_FRAME    ((uint32_t)DCMI_CR_FCRC_0)  /*!< Every alternate frame captured */
293 #define DCMI_CR_ALTERNATE_4_FRAME    ((uint32_t)DCMI_CR_FCRC_1)  /*!< One frame in 4 frames captured */
294 
295 /**
296   * @}
297   */
298 
299 /** @defgroup DCMI_Extended_Data_Mode DCMI Extended Data Mode
300   * @{
301   */
302 #define DCMI_EXTEND_DATA_8B     ((uint32_t)0x00000000U)                      /*!< Interface captures 8-bit data on every pixel clock  */
303 #define DCMI_EXTEND_DATA_10B    ((uint32_t)DCMI_CR_EDM_0)                    /*!< Interface captures 10-bit data on every pixel clock */
304 #define DCMI_EXTEND_DATA_12B    ((uint32_t)DCMI_CR_EDM_1)                    /*!< Interface captures 12-bit data on every pixel clock */
305 #define DCMI_EXTEND_DATA_14B    ((uint32_t)(DCMI_CR_EDM_0 | DCMI_CR_EDM_1))  /*!< Interface captures 14-bit data on every pixel clock */
306 
307 /**
308   * @}
309   */
310 
311 /** @defgroup DCMI_Byte_Select_Mode DCMI Byte Select Mode
312   * @{
313   */
314 #define DCMI_BSM_ALL                 ((uint32_t)0x00000000U) /*!< Interface captures all received data */
315 #define DCMI_BSM_OTHER               ((uint32_t)DCMI_CR_BSM_0) /*!< Interface captures every other byte from the received data */
316 #define DCMI_BSM_ALTERNATE_4         ((uint32_t)DCMI_CR_BSM_1) /*!< Interface captures one byte out of four */
317 #define DCMI_BSM_ALTERNATE_2         ((uint32_t)(DCMI_CR_BSM_0 | DCMI_CR_BSM_1)) /*!< Interface captures two bytes out of four */
318 
319 /**
320   * @}
321   */
322 
323 /** @defgroup DCMI_Byte_Select_Start DCMI Byte Select Start
324   * @{
325   */
326 #define DCMI_OEBS_ODD               ((uint32_t)0x00000000U)  /*!< Interface captures first data from the frame/line start, second one being dropped */
327 #define DCMI_OEBS_EVEN              ((uint32_t)DCMI_CR_OEBS) /*!< Interface captures second data from the frame/line start, first one being dropped */
328 
329 /**
330   * @}
331   */
332 
333 /** @defgroup DCMI_Line_Select_Mode DCMI Line Select Mode
334   * @{
335   */
336 #define DCMI_LSM_ALL                 ((uint32_t)0x00000000U) /*!< Interface captures all received lines */
337 #define DCMI_LSM_ALTERNATE_2         ((uint32_t)DCMI_CR_LSM) /*!< Interface captures one line out of two */
338 
339 /**
340   * @}
341   */
342 
343 /** @defgroup DCMI_Line_Select_Start DCMI Line Select Start
344   * @{
345   */
346 #define DCMI_OELS_ODD               ((uint32_t)0x00000000U) /*!< Interface captures first line from the frame start, second one being dropped */
347 #define DCMI_OELS_EVEN              ((uint32_t)DCMI_CR_OELS) /*!< Interface captures second line from the frame start, first one being dropped */
348 
349 /**
350   * @}
351   */
352 
353 
354 /** @defgroup DCMI_interrupt_sources  DCMI Interrupt Sources
355   * @{
356   */
357 #define DCMI_IT_FRAME    ((uint32_t)DCMI_IER_FRAME_IE)    /*!< Capture complete interrupt      */
358 #define DCMI_IT_OVR      ((uint32_t)DCMI_IER_OVR_IE)      /*!< Overrun interrupt               */
359 #define DCMI_IT_ERR      ((uint32_t)DCMI_IER_ERR_IE)      /*!< Synchronization error interrupt */
360 #define DCMI_IT_VSYNC    ((uint32_t)DCMI_IER_VSYNC_IE)    /*!< VSYNC interrupt                 */
361 #define DCMI_IT_LINE     ((uint32_t)DCMI_IER_LINE_IE)     /*!< Line interrupt                  */
362 /**
363   * @}
364   */
365 
366 /** @defgroup DCMI_Flags DCMI Flags
367   * @{
368   */
369 
370 /**
371   * @brief   DCMI SR register
372   */
373 #define DCMI_FLAG_HSYNC     ((uint32_t)DCMI_SR_INDEX|DCMI_SR_HSYNC) /*!< HSYNC pin state (active line / synchronization between lines)   */
374 #define DCMI_FLAG_VSYNC     ((uint32_t)DCMI_SR_INDEX|DCMI_SR_VSYNC) /*!< VSYNC pin state (active frame / synchronization between frames) */
375 #define DCMI_FLAG_FNE       ((uint32_t)DCMI_SR_INDEX|DCMI_SR_FNE)   /*!< FIFO not empty flag                                                 */
376 /**
377   * @brief   DCMI RIS register
378   */
379 #define DCMI_FLAG_FRAMERI    ((uint32_t)DCMI_RIS_FRAME_RIS)  /*!< Capture complete interrupt flag      */
380 #define DCMI_FLAG_OVRRI      ((uint32_t)DCMI_RIS_OVR_RIS)    /*!< Overrun interrupt flag               */
381 #define DCMI_FLAG_ERRRI      ((uint32_t)DCMI_RIS_ERR_RIS)    /*!< Synchronization error interrupt flag */
382 #define DCMI_FLAG_VSYNCRI    ((uint32_t)DCMI_RIS_VSYNC_RIS)  /*!< VSYNC interrupt flag                 */
383 #define DCMI_FLAG_LINERI     ((uint32_t)DCMI_RIS_LINE_RIS)   /*!< Line interrupt flag                  */
384 /**
385   * @brief   DCMI MIS register
386   */
387 #define DCMI_FLAG_FRAMEMI    ((uint32_t)DCMI_MIS_INDEX|DCMI_MIS_FRAME_MIS)  /*!< DCMI Capture complete masked interrupt status      */
388 #define DCMI_FLAG_OVRMI      ((uint32_t)DCMI_MIS_INDEX|DCMI_MIS_OVR_MIS  )  /*!< DCMI Overrun masked interrupt status               */
389 #define DCMI_FLAG_ERRMI      ((uint32_t)DCMI_MIS_INDEX|DCMI_MIS_ERR_MIS  )  /*!< DCMI Synchronization error masked interrupt status */
390 #define DCMI_FLAG_VSYNCMI    ((uint32_t)DCMI_MIS_INDEX|DCMI_MIS_VSYNC_MIS)  /*!< DCMI VSYNC masked interrupt status                 */
391 #define DCMI_FLAG_LINEMI     ((uint32_t)DCMI_MIS_INDEX|DCMI_MIS_LINE_MIS )  /*!< DCMI Line masked interrupt status                  */
392 /**
393   * @}
394   */
395 
396 /**
397   * @}
398   */
399 
400 /* Exported macro ------------------------------------------------------------*/
401 /** @defgroup DCMI_Exported_Macros DCMI Exported Macros
402   * @{
403   */
404 
405 /** @brief Reset DCMI handle state
406   * @param  __HANDLE__ specifies the DCMI handle.
407   * @retval None
408   */
409 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
410 #define __HAL_DCMI_RESET_HANDLE_STATE(__HANDLE__) do{                                            \
411                                                      (__HANDLE__)->State = HAL_DCMI_STATE_RESET; \
412                                                      (__HANDLE__)->MspInitCallback = NULL;      \
413                                                      (__HANDLE__)->MspDeInitCallback = NULL;    \
414                                                    } while(0)
415 #else
416 #define __HAL_DCMI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DCMI_STATE_RESET)
417 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
418 
419 /**
420   * @brief  Enable the DCMI.
421   * @param  __HANDLE__ DCMI handle
422   * @retval None
423   */
424 #define __HAL_DCMI_ENABLE(__HANDLE__)    ((__HANDLE__)->Instance->CR |= DCMI_CR_ENABLE)
425 
426 /**
427   * @brief  Disable the DCMI.
428   * @param  __HANDLE__ DCMI handle
429   * @retval None
430   */
431 #define __HAL_DCMI_DISABLE(__HANDLE__)   ((__HANDLE__)->Instance->CR &= ~(DCMI_CR_ENABLE))
432 
433 /* Interrupt & Flag management */
434 /**
435   * @brief  Get the DCMI pending flag.
436   * @param  __HANDLE__ DCMI handle
437   * @param  __FLAG__ Get the specified flag.
438   *         This parameter can be one of the following values (no combination allowed)
439   *            @arg DCMI_FLAG_HSYNC: HSYNC pin state (active line / synchronization between lines)
440   *            @arg DCMI_FLAG_VSYNC: VSYNC pin state (active frame / synchronization between frames)
441   *            @arg DCMI_FLAG_FNE: FIFO empty flag
442   *            @arg DCMI_FLAG_FRAMERI: Frame capture complete flag
443   *            @arg DCMI_FLAG_OVRRI: Overrun flag
444   *            @arg DCMI_FLAG_ERRRI: Synchronization error flag
445   *            @arg DCMI_FLAG_VSYNCRI: VSYNC flag
446   *            @arg DCMI_FLAG_LINERI: Line flag
447   *            @arg DCMI_FLAG_FRAMEMI: DCMI Capture complete masked interrupt status
448   *            @arg DCMI_FLAG_OVRMI: DCMI Overrun masked interrupt status
449   *            @arg DCMI_FLAG_ERRMI: DCMI Synchronization error masked interrupt status
450   *            @arg DCMI_FLAG_VSYNCMI: DCMI VSYNC masked interrupt status
451   *            @arg DCMI_FLAG_LINEMI: DCMI Line masked interrupt status
452   * @retval The state of FLAG.
453   */
454 #define __HAL_DCMI_GET_FLAG(__HANDLE__, __FLAG__)\
455  ((((__FLAG__) & (DCMI_SR_INDEX|DCMI_MIS_INDEX)) == 0x0U)? ((__HANDLE__)->Instance->RISR & (__FLAG__)) :\
456  (((__FLAG__) & DCMI_SR_INDEX) == 0x0U)? ((__HANDLE__)->Instance->MISR & (__FLAG__)) : ((__HANDLE__)->Instance->SR & (__FLAG__)))
457 
458 /**
459   * @brief  Clear the DCMI pending flag.
460   * @param  __HANDLE__ DCMI handle
461   * @param  __FLAG__ specifies the flag to clear.
462   *         This parameter can be any combination of the following values:
463   *            @arg DCMI_FLAG_FRAMERI: Frame capture complete flag
464   *            @arg DCMI_FLAG_OVRRI: Overrun flag
465   *            @arg DCMI_FLAG_ERRRI: Synchronization error flag
466   *            @arg DCMI_FLAG_VSYNCRI: VSYNC flag
467   *            @arg DCMI_FLAG_LINERI: Line flag
468   * @retval None
469   */
470 #define __HAL_DCMI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
471 
472 /**
473   * @brief  Enable the specified DCMI interrupts.
474   * @param  __HANDLE__ DCMI handle
475   * @param  __INTERRUPT__ specifies the DCMI interrupt sources to be enabled.
476   *         This parameter can be any combination of the following values:
477   *            @arg DCMI_IT_FRAME: Frame capture complete interrupt
478   *            @arg DCMI_IT_OVR: Overrun interrupt
479   *            @arg DCMI_IT_ERR: Synchronization error interrupt
480   *            @arg DCMI_IT_VSYNC: VSYNC interrupt
481   *            @arg DCMI_IT_LINE: Line interrupt
482   * @retval None
483   */
484 #define __HAL_DCMI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
485 
486 /**
487   * @brief  Disable the specified DCMI interrupts.
488   * @param  __HANDLE__ DCMI handle
489   * @param  __INTERRUPT__ specifies the DCMI interrupt sources to be enabled.
490   *         This parameter can be any combination of the following values:
491   *            @arg DCMI_IT_FRAME: Frame capture complete interrupt
492   *            @arg DCMI_IT_OVR: Overrun interrupt
493   *            @arg DCMI_IT_ERR: Synchronization error interrupt
494   *            @arg DCMI_IT_VSYNC: VSYNC interrupt
495   *            @arg DCMI_IT_LINE: Line interrupt
496   * @retval None
497   */
498 #define __HAL_DCMI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= ~(__INTERRUPT__))
499 
500 /**
501   * @brief  Check whether the specified DCMI interrupt has occurred or not.
502   * @note   A bit in MIS register is set if the corresponding enable bit in
503   *         DCMI_IER is set and the corresponding bit in DCMI_RIS is set.
504   * @param  __HANDLE__ DCMI handle
505   * @param  __INTERRUPT__ specifies the DCMI interrupt flag and source to check.
506   *         This parameter can be one of the following values:
507   *            @arg DCMI_IT_FRAME: Frame capture complete interrupt mask
508   *            @arg DCMI_IT_OVR: Overrun interrupt mask
509   *            @arg DCMI_IT_ERR: Synchronization error interrupt mask
510   *            @arg DCMI_IT_VSYNC: VSYNC interrupt mask
511   *            @arg DCMI_IT_LINE: Line interrupt mask
512   * @retval The state of INTERRUPT.
513   */
514 #define __HAL_DCMI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->MIS & (__INTERRUPT__))
515 
516 /**
517   * @}
518   */
519 
520 /* Exported functions --------------------------------------------------------*/
521 /** @addtogroup DCMI_Exported_Functions
522   * @{
523   */
524 
525 /** @addtogroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
526  * @{
527  */
528 
529 /* Initialization and de-initialization functions *****************************/
530 HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi);
531 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi);
532 void       HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi);
533 void       HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi);
534 
535 /* Callbacks Register/UnRegister functions  ***********************************/
536 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
537 HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback);
538 HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID);
539 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
540 /**
541   * @}
542   */
543 
544 /** @addtogroup DCMI_Exported_Functions_Group2 IO operation functions
545  * @{
546  */
547 
548 /* IO operation functions *****************************************************/
549 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length);
550 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi);
551 HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi);
552 HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef* hdcmi);
553 void              HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi);
554 void              HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi);
555 void              HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi);
556 void              HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi);
557 void              HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi);
558 /**
559   * @}
560   */
561 
562 /** @addtogroup DCMI_Exported_Functions_Group3 Peripheral Control functions
563  * @{
564  */
565 /* Peripheral Control functions ***********************************************/
566 HAL_StatusTypeDef     HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize);
567 HAL_StatusTypeDef     HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi);
568 HAL_StatusTypeDef     HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi);
569 HAL_StatusTypeDef     HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask);
570 /**
571   * @}
572   */
573 
574 /** @addtogroup DCMI_Exported_Functions_Group4 Peripheral State functions
575  * @{
576  */
577 /* Peripheral State functions *************************************************/
578 HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi);
579 uint32_t              HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi);
580 /**
581   * @}
582   */
583 
584 /**
585   * @}
586   */
587 
588 /* Private types -------------------------------------------------------------*/
589 /* Private variables ---------------------------------------------------------*/
590 /* Private constants ---------------------------------------------------------*/
591 /** @addtogroup DCMI_Private_Constants DCMI Private Constants
592   * @{
593   */
594 
595 /** @defgroup DCMI_Registers_Indices DCMI Registers Indices
596   * @{
597   */
598 #define DCMI_MIS_INDEX        (0x1000U)         /*!< DCMI MIS register index */
599 #define DCMI_SR_INDEX         (0x2000U)         /*!< DCMI SR register index */
600 /**
601   * @}
602   */
603 
604 /** @defgroup DCMI_Window_Coordinate DCMI Window Coordinate
605   * @{
606   */
607 #define DCMI_WINDOW_COORDINATE    ((uint32_t)0x3FFFU)  /*!< Window coordinate */
608 /**
609   * @}
610   */
611 
612 /** @defgroup DCMI_Window_Height DCMI Window Height
613   * @{
614   */
615 #define DCMI_WINDOW_HEIGHT    ((uint32_t)0x1FFFU)  /*!< Window Height */
616 /**
617   * @}
618   */
619 
620 /**
621   * @}
622   */
623 
624 /* Private macro -------------------------------------------------------------*/
625 /** @defgroup DCMI_Private_Macros DCMI Private Macros
626   * @{
627   */
628 #define IS_DCMI_CAPTURE_MODE(MODE)(((MODE) == DCMI_MODE_CONTINUOUS) || \
629                                    ((MODE) == DCMI_MODE_SNAPSHOT))
630 
631 #define IS_DCMI_SYNCHRO(MODE)(((MODE) == DCMI_SYNCHRO_HARDWARE) || \
632                               ((MODE) == DCMI_SYNCHRO_EMBEDDED))
633 
634 #define IS_DCMI_PCKPOLARITY(POLARITY)(((POLARITY) == DCMI_PCKPOLARITY_FALLING) || \
635                                       ((POLARITY) == DCMI_PCKPOLARITY_RISING))
636 
637 #define IS_DCMI_VSPOLARITY(POLARITY)(((POLARITY) == DCMI_VSPOLARITY_LOW) || \
638                                      ((POLARITY) == DCMI_VSPOLARITY_HIGH))
639 
640 #define IS_DCMI_HSPOLARITY(POLARITY)(((POLARITY) == DCMI_HSPOLARITY_LOW) || \
641                                      ((POLARITY) == DCMI_HSPOLARITY_HIGH))
642 
643 #define IS_DCMI_MODE_JPEG(JPEG_MODE)(((JPEG_MODE) == DCMI_JPEG_DISABLE) || \
644                                      ((JPEG_MODE) == DCMI_JPEG_ENABLE))
645 
646 #define IS_DCMI_CAPTURE_RATE(RATE) (((RATE) == DCMI_CR_ALL_FRAME)         || \
647                                     ((RATE) == DCMI_CR_ALTERNATE_2_FRAME) || \
648                                     ((RATE) == DCMI_CR_ALTERNATE_4_FRAME))
649 
650 #define IS_DCMI_EXTENDED_DATA(DATA)(((DATA) == DCMI_EXTEND_DATA_8B)  || \
651                                     ((DATA) == DCMI_EXTEND_DATA_10B) || \
652                                     ((DATA) == DCMI_EXTEND_DATA_12B) || \
653                                     ((DATA) == DCMI_EXTEND_DATA_14B))
654 
655 #define IS_DCMI_WINDOW_COORDINATE(COORDINATE) ((COORDINATE) <= DCMI_WINDOW_COORDINATE)
656 
657 #define IS_DCMI_WINDOW_HEIGHT(HEIGHT) ((HEIGHT) <= DCMI_WINDOW_HEIGHT)
658 
659 #define IS_DCMI_BYTE_SELECT_MODE(MODE)(((MODE) == DCMI_BSM_ALL) || \
660                                        ((MODE) == DCMI_BSM_OTHER) || \
661                                        ((MODE) == DCMI_BSM_ALTERNATE_4) || \
662                                        ((MODE) == DCMI_BSM_ALTERNATE_2))
663 
664 #define IS_DCMI_BYTE_SELECT_START(POLARITY)(((POLARITY) == DCMI_OEBS_ODD) || \
665                                             ((POLARITY) == DCMI_OEBS_EVEN))
666 
667 #define IS_DCMI_LINE_SELECT_MODE(MODE)(((MODE) == DCMI_LSM_ALL) || \
668                                        ((MODE) == DCMI_LSM_ALTERNATE_2))
669 
670 #define IS_DCMI_LINE_SELECT_START(POLARITY)(((POLARITY) == DCMI_OELS_ODD) || \
671                                             ((POLARITY) == DCMI_OELS_EVEN))
672 
673 /**
674   * @}
675   */
676 
677 /**
678   * @}
679   */
680 
681 /**
682   * @}
683   */
684 
685 #endif /* DCMI */
686 
687 #ifdef __cplusplus
688 }
689 #endif
690 
691 #endif /* __STM32L4xx_HAL_DCMI_H */
692 
693 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
694