123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- #include "stm32f4xx_dcmi.h"
- #include "stm32f4xx_rcc.h"
-
-
- void DCMI_DeInit(void)
- {
- DCMI->CR = 0x0;
- DCMI->IER = 0x0;
- DCMI->ICR = 0x1F;
- DCMI->ESCR = 0x0;
- DCMI->ESUR = 0x0;
- DCMI->CWSTRTR = 0x0;
- DCMI->CWSIZER = 0x0;
- }
- void DCMI_Init(DCMI_InitTypeDef* DCMI_InitStruct)
- {
- uint32_t temp = 0x0;
-
-
- assert_param(IS_DCMI_CAPTURE_MODE(DCMI_InitStruct->DCMI_CaptureMode));
- assert_param(IS_DCMI_SYNCHRO(DCMI_InitStruct->DCMI_SynchroMode));
- assert_param(IS_DCMI_PCKPOLARITY(DCMI_InitStruct->DCMI_PCKPolarity));
- assert_param(IS_DCMI_VSPOLARITY(DCMI_InitStruct->DCMI_VSPolarity));
- assert_param(IS_DCMI_HSPOLARITY(DCMI_InitStruct->DCMI_HSPolarity));
- assert_param(IS_DCMI_CAPTURE_RATE(DCMI_InitStruct->DCMI_CaptureRate));
- assert_param(IS_DCMI_EXTENDED_DATA(DCMI_InitStruct->DCMI_ExtendedDataMode));
-
- DCMI->CR &= ~(DCMI_CR_ENABLE | DCMI_CR_CAPTURE);
-
-
- temp = DCMI->CR;
-
- temp &= ~((uint32_t)DCMI_CR_CM | DCMI_CR_ESS | DCMI_CR_PCKPOL |
- DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_FCRC_0 |
- DCMI_CR_FCRC_1 | DCMI_CR_EDM_0 | DCMI_CR_EDM_1);
-
-
- temp |= ((uint32_t)DCMI_InitStruct->DCMI_CaptureMode |
- DCMI_InitStruct->DCMI_SynchroMode |
- DCMI_InitStruct->DCMI_PCKPolarity |
- DCMI_InitStruct->DCMI_VSPolarity |
- DCMI_InitStruct->DCMI_HSPolarity |
- DCMI_InitStruct->DCMI_CaptureRate |
- DCMI_InitStruct->DCMI_ExtendedDataMode);
- DCMI->CR = temp;
- }
- void DCMI_StructInit(DCMI_InitTypeDef* DCMI_InitStruct)
- {
-
- DCMI_InitStruct->DCMI_CaptureMode = DCMI_CaptureMode_Continuous;
- DCMI_InitStruct->DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
- DCMI_InitStruct->DCMI_PCKPolarity = DCMI_PCKPolarity_Falling;
- DCMI_InitStruct->DCMI_VSPolarity = DCMI_VSPolarity_Low;
- DCMI_InitStruct->DCMI_HSPolarity = DCMI_HSPolarity_Low;
- DCMI_InitStruct->DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
- DCMI_InitStruct->DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;
- }
- void DCMI_CROPConfig(DCMI_CROPInitTypeDef* DCMI_CROPInitStruct)
- {
-
- DCMI->CWSTRTR = (uint32_t)((uint32_t)DCMI_CROPInitStruct->DCMI_HorizontalOffsetCount |
- ((uint32_t)DCMI_CROPInitStruct->DCMI_VerticalStartLine << 16));
-
- DCMI->CWSIZER = (uint32_t)(DCMI_CROPInitStruct->DCMI_CaptureCount |
- ((uint32_t)DCMI_CROPInitStruct->DCMI_VerticalLineCount << 16));
- }
- void DCMI_CROPCmd(FunctionalState NewState)
- {
-
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
-
- DCMI->CR |= (uint32_t)DCMI_CR_CROP;
- }
- else
- {
-
- DCMI->CR &= ~(uint32_t)DCMI_CR_CROP;
- }
- }
- void DCMI_SetEmbeddedSynchroCodes(DCMI_CodesInitTypeDef* DCMI_CodesInitStruct)
- {
- DCMI->ESCR = (uint32_t)(DCMI_CodesInitStruct->DCMI_FrameStartCode |
- ((uint32_t)DCMI_CodesInitStruct->DCMI_LineStartCode << 8)|
- ((uint32_t)DCMI_CodesInitStruct->DCMI_LineEndCode << 16)|
- ((uint32_t)DCMI_CodesInitStruct->DCMI_FrameEndCode << 24));
- }
- void DCMI_JPEGCmd(FunctionalState NewState)
- {
-
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
-
- DCMI->CR |= (uint32_t)DCMI_CR_JPEG;
- }
- else
- {
-
- DCMI->CR &= ~(uint32_t)DCMI_CR_JPEG;
- }
- }
-
- void DCMI_Cmd(FunctionalState NewState)
- {
-
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
-
- DCMI->CR |= (uint32_t)DCMI_CR_ENABLE;
- }
- else
- {
-
- DCMI->CR &= ~(uint32_t)DCMI_CR_ENABLE;
- }
- }
- void DCMI_CaptureCmd(FunctionalState NewState)
- {
-
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
-
- DCMI->CR |= (uint32_t)DCMI_CR_CAPTURE;
- }
- else
- {
-
- DCMI->CR &= ~(uint32_t)DCMI_CR_CAPTURE;
- }
- }
- uint32_t DCMI_ReadData(void)
- {
- return DCMI->DR;
- }
- void DCMI_ITConfig(uint16_t DCMI_IT, FunctionalState NewState)
- {
-
- assert_param(IS_DCMI_CONFIG_IT(DCMI_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
-
- DCMI->IER |= DCMI_IT;
- }
- else
- {
-
- DCMI->IER &= (uint16_t)(~DCMI_IT);
- }
- }
- FlagStatus DCMI_GetFlagStatus(uint16_t DCMI_FLAG)
- {
- FlagStatus bitstatus = RESET;
- uint32_t dcmireg, tempreg = 0;
-
- assert_param(IS_DCMI_GET_FLAG(DCMI_FLAG));
-
-
- dcmireg = (((uint16_t)DCMI_FLAG) >> 12);
-
- if (dcmireg == 0x00)
- {
- tempreg= DCMI->RISR;
- }
- else if (dcmireg == 0x02)
- {
- tempreg = DCMI->SR;
- }
- else
- {
- tempreg = DCMI->MISR;
- }
-
- if ((tempreg & DCMI_FLAG) != (uint16_t)RESET )
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
-
- return bitstatus;
- }
- void DCMI_ClearFlag(uint16_t DCMI_FLAG)
- {
-
- assert_param(IS_DCMI_CLEAR_FLAG(DCMI_FLAG));
-
-
-
- DCMI->ICR = DCMI_FLAG;
- }
- ITStatus DCMI_GetITStatus(uint16_t DCMI_IT)
- {
- ITStatus bitstatus = RESET;
- uint32_t itstatus = 0;
-
-
- assert_param(IS_DCMI_GET_IT(DCMI_IT));
-
- itstatus = DCMI->MISR & DCMI_IT;
-
- if ((itstatus != (uint16_t)RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
- }
- void DCMI_ClearITPendingBit(uint16_t DCMI_IT)
- {
-
-
- DCMI->ICR = DCMI_IT;
- }
-
-
-
-
|