CARME-M4 BSP  V1.5
stm32f4xx_dcmi.c
Go to the documentation of this file.
1 
85 /* Includes ------------------------------------------------------------------*/
86 #include "stm32f4xx_dcmi.h"
87 #include "stm32f4xx_rcc.h"
88 
98 /* Private typedef -----------------------------------------------------------*/
99 /* Private define ------------------------------------------------------------*/
100 /* Private macro -------------------------------------------------------------*/
101 /* Private variables ---------------------------------------------------------*/
102 /* Private function prototypes -----------------------------------------------*/
103 /* Private functions ---------------------------------------------------------*/
104 
126 void DCMI_DeInit(void)
127 {
128  DCMI->CR = 0x0;
129  DCMI->IER = 0x0;
130  DCMI->ICR = 0x1F;
131  DCMI->ESCR = 0x0;
132  DCMI->ESUR = 0x0;
133  DCMI->CWSTRTR = 0x0;
134  DCMI->CWSIZER = 0x0;
135 }
136 
143 void DCMI_Init(DCMI_InitTypeDef* DCMI_InitStruct)
144 {
145  uint32_t temp = 0x0;
146 
147  /* Check the parameters */
148  assert_param(IS_DCMI_CAPTURE_MODE(DCMI_InitStruct->DCMI_CaptureMode));
149  assert_param(IS_DCMI_SYNCHRO(DCMI_InitStruct->DCMI_SynchroMode));
150  assert_param(IS_DCMI_PCKPOLARITY(DCMI_InitStruct->DCMI_PCKPolarity));
151  assert_param(IS_DCMI_VSPOLARITY(DCMI_InitStruct->DCMI_VSPolarity));
152  assert_param(IS_DCMI_HSPOLARITY(DCMI_InitStruct->DCMI_HSPolarity));
153  assert_param(IS_DCMI_CAPTURE_RATE(DCMI_InitStruct->DCMI_CaptureRate));
154  assert_param(IS_DCMI_EXTENDED_DATA(DCMI_InitStruct->DCMI_ExtendedDataMode));
155 
156  /* The DCMI configuration registers should be programmed correctly before
157  enabling the CR_ENABLE Bit and the CR_CAPTURE Bit */
158  DCMI->CR &= ~(DCMI_CR_ENABLE | DCMI_CR_CAPTURE);
159 
160  /* Reset the old DCMI configuration */
161  temp = DCMI->CR;
162 
163  temp &= ~((uint32_t)DCMI_CR_CM | DCMI_CR_ESS | DCMI_CR_PCKPOL |
164  DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_FCRC_0 |
165  DCMI_CR_FCRC_1 | DCMI_CR_EDM_0 | DCMI_CR_EDM_1);
166 
167  /* Sets the new configuration of the DCMI peripheral */
168  temp |= ((uint32_t)DCMI_InitStruct->DCMI_CaptureMode |
169  DCMI_InitStruct->DCMI_SynchroMode |
170  DCMI_InitStruct->DCMI_PCKPolarity |
171  DCMI_InitStruct->DCMI_VSPolarity |
172  DCMI_InitStruct->DCMI_HSPolarity |
173  DCMI_InitStruct->DCMI_CaptureRate |
174  DCMI_InitStruct->DCMI_ExtendedDataMode);
175 
176  DCMI->CR = temp;
177 }
178 
185 void DCMI_StructInit(DCMI_InitTypeDef* DCMI_InitStruct)
186 {
187  /* Set the default configuration */
189  DCMI_InitStruct->DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
190  DCMI_InitStruct->DCMI_PCKPolarity = DCMI_PCKPolarity_Falling;
191  DCMI_InitStruct->DCMI_VSPolarity = DCMI_VSPolarity_Low;
192  DCMI_InitStruct->DCMI_HSPolarity = DCMI_HSPolarity_Low;
193  DCMI_InitStruct->DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
195 }
196 
205 void DCMI_CROPConfig(DCMI_CROPInitTypeDef* DCMI_CROPInitStruct)
206 {
207  /* Sets the CROP window coordinates */
208  DCMI->CWSTRTR = (uint32_t)((uint32_t)DCMI_CROPInitStruct->DCMI_HorizontalOffsetCount |
209  ((uint32_t)DCMI_CROPInitStruct->DCMI_VerticalStartLine << 16));
210 
211  /* Sets the CROP window size */
212  DCMI->CWSIZER = (uint32_t)(DCMI_CROPInitStruct->DCMI_CaptureCount |
213  ((uint32_t)DCMI_CROPInitStruct->DCMI_VerticalLineCount << 16));
214 }
215 
223 void DCMI_CROPCmd(FunctionalState NewState)
224 {
225  /* Check the parameters */
226  assert_param(IS_FUNCTIONAL_STATE(NewState));
227 
228  if (NewState != DISABLE)
229  {
230  /* Enable the DCMI Crop feature */
231  DCMI->CR |= (uint32_t)DCMI_CR_CROP;
232  }
233  else
234  {
235  /* Disable the DCMI Crop feature */
236  DCMI->CR &= ~(uint32_t)DCMI_CR_CROP;
237  }
238 }
239 
247 {
248  DCMI->ESCR = (uint32_t)(DCMI_CodesInitStruct->DCMI_FrameStartCode |
249  ((uint32_t)DCMI_CodesInitStruct->DCMI_LineStartCode << 8)|
250  ((uint32_t)DCMI_CodesInitStruct->DCMI_LineEndCode << 16)|
251  ((uint32_t)DCMI_CodesInitStruct->DCMI_FrameEndCode << 24));
252 }
253 
261 void DCMI_JPEGCmd(FunctionalState NewState)
262 {
263  /* Check the parameters */
264  assert_param(IS_FUNCTIONAL_STATE(NewState));
265 
266  if (NewState != DISABLE)
267  {
268  /* Enable the DCMI JPEG format */
269  DCMI->CR |= (uint32_t)DCMI_CR_JPEG;
270  }
271  else
272  {
273  /* Disable the DCMI JPEG format */
274  DCMI->CR &= ~(uint32_t)DCMI_CR_JPEG;
275  }
276 }
299 void DCMI_Cmd(FunctionalState NewState)
300 {
301  /* Check the parameters */
302  assert_param(IS_FUNCTIONAL_STATE(NewState));
303 
304  if (NewState != DISABLE)
305  {
306  /* Enable the DCMI by setting ENABLE bit */
307  DCMI->CR |= (uint32_t)DCMI_CR_ENABLE;
308  }
309  else
310  {
311  /* Disable the DCMI by clearing ENABLE bit */
312  DCMI->CR &= ~(uint32_t)DCMI_CR_ENABLE;
313  }
314 }
315 
322 void DCMI_CaptureCmd(FunctionalState NewState)
323 {
324  /* Check the parameters */
325  assert_param(IS_FUNCTIONAL_STATE(NewState));
326 
327  if (NewState != DISABLE)
328  {
329  /* Enable the DCMI Capture */
330  DCMI->CR |= (uint32_t)DCMI_CR_CAPTURE;
331  }
332  else
333  {
334  /* Disable the DCMI Capture */
335  DCMI->CR &= ~(uint32_t)DCMI_CR_CAPTURE;
336  }
337 }
338 
344 uint32_t DCMI_ReadData(void)
345 {
346  return DCMI->DR;
347 }
377 void DCMI_ITConfig(uint16_t DCMI_IT, FunctionalState NewState)
378 {
379  /* Check the parameters */
380  assert_param(IS_DCMI_CONFIG_IT(DCMI_IT));
381  assert_param(IS_FUNCTIONAL_STATE(NewState));
382 
383  if (NewState != DISABLE)
384  {
385  /* Enable the Interrupt sources */
386  DCMI->IER |= DCMI_IT;
387  }
388  else
389  {
390  /* Disable the Interrupt sources */
391  DCMI->IER &= (uint16_t)(~DCMI_IT);
392  }
393 }
394 
414 FlagStatus DCMI_GetFlagStatus(uint16_t DCMI_FLAG)
415 {
416  FlagStatus bitstatus = RESET;
417  uint32_t dcmireg, tempreg = 0;
418 
419  /* Check the parameters */
420  assert_param(IS_DCMI_GET_FLAG(DCMI_FLAG));
421 
422  /* Get the DCMI register index */
423  dcmireg = (((uint16_t)DCMI_FLAG) >> 12);
424 
425  if (dcmireg == 0x00) /* The FLAG is in RISR register */
426  {
427  tempreg= DCMI->RISR;
428  }
429  else if (dcmireg == 0x02) /* The FLAG is in SR register */
430  {
431  tempreg = DCMI->SR;
432  }
433  else /* The FLAG is in MISR register */
434  {
435  tempreg = DCMI->MISR;
436  }
437 
438  if ((tempreg & DCMI_FLAG) != (uint16_t)RESET )
439  {
440  bitstatus = SET;
441  }
442  else
443  {
444  bitstatus = RESET;
445  }
446  /* Return the DCMI_FLAG status */
447  return bitstatus;
448 }
449 
461 void DCMI_ClearFlag(uint16_t DCMI_FLAG)
462 {
463  /* Check the parameters */
464  assert_param(IS_DCMI_CLEAR_FLAG(DCMI_FLAG));
465 
466  /* Clear the flag by writing in the ICR register 1 in the corresponding
467  Flag position*/
468 
469  DCMI->ICR = DCMI_FLAG;
470 }
471 
483 ITStatus DCMI_GetITStatus(uint16_t DCMI_IT)
484 {
485  ITStatus bitstatus = RESET;
486  uint32_t itstatus = 0;
487 
488  /* Check the parameters */
489  assert_param(IS_DCMI_GET_IT(DCMI_IT));
490 
491  itstatus = DCMI->MISR & DCMI_IT; /* Only masked interrupts are checked */
492 
493  if ((itstatus != (uint16_t)RESET))
494  {
495  bitstatus = SET;
496  }
497  else
498  {
499  bitstatus = RESET;
500  }
501  return bitstatus;
502 }
503 
515 void DCMI_ClearITPendingBit(uint16_t DCMI_IT)
516 {
517  /* Clear the interrupt pending Bit by writing in the ICR register 1 in the
518  corresponding pending Bit position*/
519 
520  DCMI->ICR = DCMI_IT;
521 }
538 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This file contains all the functions prototypes for the RCC firmware library.
uint16_t DCMI_CaptureRate
void DCMI_JPEGCmd(FunctionalState NewState)
Enables or disables the DCMI JPEG format.
DCMI Init structure definition.
#define DCMI_PCKPolarity_Falling
uint16_t DCMI_VSPolarity
uint16_t DCMI_VerticalLineCount
uint16_t DCMI_SynchroMode
DCMI Embedded Synchronisation CODE Init structure definition.
#define DCMI_VSPolarity_Low
void DCMI_ITConfig(uint16_t DCMI_IT, FunctionalState NewState)
Enables or disables the DCMI interface interrupts.
void DCMI_CROPConfig(DCMI_CROPInitTypeDef *DCMI_CROPInitStruct)
Initializes the DCMI peripheral CROP mode according to the specified parameters in the DCMI_CROPInitS...
#define DCMI_ExtendedDataMode_8b
void DCMI_CaptureCmd(FunctionalState NewState)
Enables or disables the DCMI Capture.
uint16_t DCMI_PCKPolarity
uint32_t DCMI_ReadData(void)
Reads the data stored in the DR register.
#define DCMI_HSPolarity_Low
void DCMI_Init(DCMI_InitTypeDef *DCMI_InitStruct)
Initializes the DCMI according to the specified parameters in the DCMI_InitStruct.
uint16_t DCMI_HSPolarity
#define DCMI_CaptureRate_All_Frame
uint16_t DCMI_CaptureMode
This file contains all the functions prototypes for the DCMI firmware library.
uint16_t DCMI_HorizontalOffsetCount
void DCMI_CROPCmd(FunctionalState NewState)
Enables or disables the DCMI Crop feature.
uint16_t DCMI_ExtendedDataMode
#define DCMI_CaptureMode_Continuous
void DCMI_ClearFlag(uint16_t DCMI_FLAG)
Clears the DCMI's pending flags.
void DCMI_StructInit(DCMI_InitTypeDef *DCMI_InitStruct)
Fills each DCMI_InitStruct member with its default value.
#define DCMI_SynchroMode_Hardware
FlagStatus DCMI_GetFlagStatus(uint16_t DCMI_FLAG)
Checks whether the DCMI interface flag is set or not.
void DCMI_SetEmbeddedSynchroCodes(DCMI_CodesInitTypeDef *DCMI_CodesInitStruct)
Sets the embedded synchronization codes.
uint16_t DCMI_VerticalStartLine
DCMI CROP Init structure definition.
void DCMI_Cmd(FunctionalState NewState)
Enables or disables the DCMI interface.
void DCMI_ClearITPendingBit(uint16_t DCMI_IT)
Clears the DCMI's interrupt pending bits.
ITStatus DCMI_GetITStatus(uint16_t DCMI_IT)
Checks whether the DCMI interrupt has occurred or not.
void DCMI_DeInit(void)
Deinitializes the DCMI registers to their default reset values.