1 /*! 2 * @file apm32f4xx_dci.c 3 * 4 * @brief This file provides all the DCI firmware functions 5 * 6 * @version V1.0.2 7 * 8 * @date 2022-06-23 9 * 10 * @attention 11 * 12 * Copyright (C) 2021-2022 Geehy Semiconductor 13 * 14 * You may not use this file except in compliance with the 15 * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE). 16 * 17 * The program is only for reference, which is distributed in the hope 18 * that it will be usefull and instructional for customers to develop 19 * their software. Unless required by applicable law or agreed to in 20 * writing, the program is distributed on an "AS IS" BASIS, WITHOUT 21 * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions 23 * and limitations under the License. 24 */ 25 26 #include "apm32f4xx_dci.h" 27 #include "apm32f4xx_rcm.h" 28 29 /** @addtogroup APM32F4xx_StdPeriphDriver 30 @{ 31 */ 32 33 /** @defgroup DCI_Driver 34 * @brief DCI driver modules 35 @{ 36 */ 37 38 /** @defgroup DCI_Functions 39 @{ 40 */ 41 42 /*! 43 * @brief Reast the DCI registers to their default reset values. 44 * 45 * @param None 46 * 47 * @retval None 48 */ DCI_Rest(void)49void DCI_Rest(void) 50 { 51 DCI->CTRL = 0x00; 52 DCI->INTEN = 0x00; 53 DCI->INTCLR = 0x1F; 54 DCI->ESYNCC = 0x00; 55 DCI->ESYNCUM = 0x00; 56 DCI->CROPWSTAT = 0x00; 57 DCI->CROPWSIZE = 0x00; 58 } 59 60 /*! 61 * @brief Configure DCI by configuring the structure 62 * 63 * @param dciConfig: pointer to a DCI_Config_T structure 64 * 65 * @retval None 66 */ DCI_Config(DCI_Config_T * dciConfig)67void DCI_Config(DCI_Config_T *dciConfig) 68 { 69 DCI->CTRL_B.CMODE = dciConfig->captureMode; 70 DCI->CTRL_B.ESYNCSEL = dciConfig->synchroMode; 71 DCI->CTRL_B.PXCLKPOL = dciConfig->pckPolarity; 72 DCI->CTRL_B.VSYNCPOL = dciConfig->vsyncPolarity; 73 DCI->CTRL_B.HSYNCPOL = dciConfig->hsyncPolarity; 74 DCI->CTRL_B.FCRCFG = dciConfig->capturerate; 75 DCI->CTRL_B.EXDMOD = dciConfig->extendedDataMode; 76 } 77 78 /*! 79 * @brief Fills each DCI InitStruct member with its default value. 80 * 81 * @param dciConfig : pointer to a DCI_Config_T structure 82 * 83 * @retval None 84 */ DCI_ConfigStructInit(DCI_Config_T * dciConfig)85void DCI_ConfigStructInit(DCI_Config_T *dciConfig) 86 { 87 dciConfig->captureMode = DCI_CAPTURE_MODE_CONTINUOUS; 88 dciConfig->synchroMode = DCI_SYNCHRO_MODE_HARDWARE; 89 dciConfig->pckPolarity = DCI_PCK_POL_FALLING; 90 dciConfig->vsyncPolarity = DCI_VSYNC_POL_LOW; 91 dciConfig->hsyncPolarity = DCI_HSYNC_POL_LOW; 92 dciConfig->capturerate = DCI_CAPTURE_RATE_ALL_FRAME; 93 dciConfig->extendedDataMode = DCI_EXTENDED_DATA_MODE_8B; 94 } 95 96 /*! 97 * @brief Configure DCI CROP mode by configuring the structure 98 * 99 * @param cropConfig: pointer to a DCI_CropConfig_T structure 100 * 101 * @retval None 102 */ DCI_ConfigCROP(DCI_CropConfig_T * cropConfig)103void DCI_ConfigCROP(DCI_CropConfig_T *cropConfig) 104 { 105 DCI->CROPWSTAT_B.HOFSCNT = (uint16_t)cropConfig->horizontalOffsetCount; 106 DCI->CROPWSTAT_B.VSLINECNT = (uint16_t)cropConfig->verticalStartLine; 107 108 DCI->CROPWSIZE_B.CCNT = (uint16_t)cropConfig->captureCount; 109 DCI->CROPWSIZE_B.VLINECNT = (uint16_t)cropConfig->verticalLineCount; 110 } 111 112 /*! 113 * @brief Enable the DCI Crop. 114 * 115 * @param None 116 * 117 * @retval None 118 */ DCI_EnableCROP(void)119void DCI_EnableCROP(void) 120 { 121 DCI->CTRL_B.CROPF = SET; 122 } 123 124 /*! 125 * @brief Disable the DCI Crop. 126 * 127 * @param None 128 * 129 * @retval None 130 */ DCI_DisableCROP(void)131void DCI_DisableCROP(void) 132 { 133 DCI->CTRL_B.CROPF = RESET; 134 } 135 136 /*! 137 * @brief Sets the embedded synchronization codes 138 * 139 * @param CodeConfig: pointer to a DCI_CodeConfig_T structure 140 * 141 * @retval None 142 */ DCI_ConfigSynchroCode(DCI_CodeConfig_T * codeConfig)143void DCI_ConfigSynchroCode(DCI_CodeConfig_T *codeConfig) 144 { 145 DCI->ESYNCC_B.FSDC = (uint8_t)codeConfig->frameStartCode; 146 DCI->ESYNCC_B.LSDC = (uint8_t)codeConfig->lineStartCode; 147 DCI->ESYNCC_B.LEDC = (uint8_t)codeConfig->lineEndCode; 148 DCI->ESYNCC_B.FEDC = (uint8_t)codeConfig->frameEndCode; 149 } 150 151 /*! 152 * @brief Enable the DCI JPEG. 153 * 154 * @param None 155 * 156 * @retval None 157 */ DCI_EnableJPEG(void)158void DCI_EnableJPEG(void) 159 { 160 DCI->CTRL_B.JPGFM = SET; 161 } 162 163 /*! 164 * @brief Disable the DCI JPEG. 165 * 166 * @param None 167 * 168 * @retval None 169 */ DCI_DisableJPEG(void)170void DCI_DisableJPEG(void) 171 { 172 173 DCI->CTRL_B.JPGFM = RESET; 174 } 175 176 /*! 177 * @brief Enable the DCI interface. 178 * 179 * @param None 180 * 181 * @retval None 182 */ DCI_Enable(void)183void DCI_Enable(void) 184 { 185 DCI->CTRL_B.DCIEN = SET; 186 } 187 188 /*! 189 * @brief Disable the DCI interface. 190 * 191 * @param None 192 * 193 * @retval None 194 */ DCI_Disable(void)195void DCI_Disable(void) 196 { 197 DCI->CTRL_B.DCIEN = RESET; 198 } 199 200 /*! 201 * @brief Enable the DCI Capture. 202 * 203 * @param None 204 * 205 * @retval None 206 */ DCI_EnableCapture(void)207void DCI_EnableCapture(void) 208 { 209 DCI->CTRL_B.CEN = SET; 210 } 211 212 /*! 213 * @brief Disable the DCI Capture. 214 * 215 * @param None 216 * 217 * @retval None 218 */ DCI_DisableCapture(void)219void DCI_DisableCapture(void) 220 { 221 DCI->CTRL_B.CEN = RESET; 222 } 223 224 /*! 225 * @brief Read the data stored in the DATA register. 226 * 227 * @param None 228 * 229 * @retval Data register value 230 */ DCI_ReadData(void)231uint32_t DCI_ReadData(void) 232 { 233 return DCI->DATA; 234 } 235 236 /*! 237 * @brief Enable the DCI interface interrupts. 238 * 239 * @param interrupt: specifies the DCI interrupt sources 240 * This parameter can be any combination of the following values: 241 * @arg DCI_INT_CC: Frame capture complete interrupt mask 242 * @arg DCI_INT_OVR: Overflow interrupt mask 243 * @arg DCI_INT_ERR: Synchronization error interrupt mask 244 * @arg DCI_INT_VSYNC: VSYNC interrupt mask 245 * @arg DCI_INT_LINE: Line interrupt mask 246 * 247 * @retval None 248 */ DCI_EnableInterrupt(uint32_t interrupt)249void DCI_EnableInterrupt(uint32_t interrupt) 250 { 251 DCI->INTEN |= (uint32_t)interrupt; 252 } 253 254 /*! 255 * @brief Disable the DCI interface interrupts. 256 * 257 * @param interrupt: specifies the DCI interrupt sources 258 * This parameter can be any combination of the following values: 259 * @arg DCI_INT_CC: Frame capture complete interrupt mask 260 * @arg DCI_INT_OVR: Overflow interrupt mask 261 * @arg DCI_INT_ERR: Synchronization error interrupt mask 262 * @arg DCI_INT_VSYNC: VSYNC interrupt mask 263 * @arg DCI_INT_LINE: Line interrupt mask 264 * 265 * @retval None 266 */ DCI_DisableInterrupt(uint32_t interrupt)267void DCI_DisableInterrupt(uint32_t interrupt) 268 { 269 DCI->INTEN &= ~(uint32_t)interrupt; 270 } 271 272 /*! 273 * @brief Reads the DCI flag. 274 * 275 * @param flag: specifies the flag to check. 276 * This parameter can be one of the following values: 277 * @arg DCI_FLAG_CCI: Frame capture complete Raw flag mask 278 * @arg DCI_FLAG_OVRI: Overflow Raw flag mask 279 * @arg DCI_FLAG_ERRI: Synchronization error Raw flag mask 280 * @arg DCI_FLAG_VSYNCI: VSYNC Raw flag mask 281 * @arg DCI_FLAG_LINEI: Line Raw flag mask 282 * @arg DCI_FLAG_CCMI: Frame capture complete Masked flag mask 283 * @arg DCI_FLAG_OVRMI: Overflow Masked flag mask 284 * @arg DCI_FLAG_ERRMI: Synchronization error Masked flag mask 285 * @arg DCI_FLAG_VSYNCMI: VSYNC Masked flag mask 286 * @arg DCI_FLAG_LINEMI: Line Masked flag mask 287 * @arg DCI_FLAG_HSYNC: HSYNC flag mask 288 * @arg DCI_FLAG_VSYNC: VSYNC flag mask 289 * @arg DCI_FLAG_FNE: Fifo not empty flag mask 290 * 291 * @retval SET or RESET. 292 */ DCI_ReadStatusFlag(DCI_FLAG_T flag)293uint16_t DCI_ReadStatusFlag(DCI_FLAG_T flag) 294 { 295 uint32_t offset, temp = 0; 296 offset = (flag >> 12); 297 298 if (offset == 0x00) 299 { 300 temp = DCI->RINTSTS; 301 } 302 else if (offset == 0x01) 303 { 304 temp = DCI->MINTSTS; 305 } 306 else 307 { 308 temp = DCI->STS; 309 } 310 return (temp & flag) ? SET : RESET; 311 } 312 313 /*! 314 * @brief Clears the DCI flag. 315 * 316 * @param flag: specifies the flag to clear. 317 * This parameter can be any combination of the following values: 318 * @arg DCI_FLAG_CCI: Frame capture complete Raw flag mask 319 * @arg DCI_FLAG_OVRI: Overflow Raw flag mask 320 * @arg DCI_FLAG_ERRI: Synchronization error Raw flag mask 321 * @arg DCI_FLAG_VSYNCI: VSYNC Raw flag mask 322 * @arg DCI_FLAG_LINEI: Line Raw flag mask 323 324 * @retval None 325 */ DCI_ClearStatusFlag(uint16_t flag)326void DCI_ClearStatusFlag(uint16_t flag) 327 { 328 DCI->INTCLR = (uint16_t)flag; 329 } 330 331 /*! 332 * @brief Read the DCI interrupt flag. 333 * 334 * @param flag: specifies the DCI interrupt source to check. 335 * This parameter can be one of the following values: 336 * @arg DCI_INT_CC: Frame capture complete interrupt mask 337 * @arg DCI_INT_OVR: Overflow interrupt mask 338 * @arg DCI_INT_ERR: Synchronization error interrupt mask 339 * @arg DCI_INT_VSYNC: VSYNC interrupt mask 340 * @arg DCI_INT_LINE: Line interrupt mask 341 * 342 * @retval None 343 */ DCI_ReadIntFlag(DCI_INT_T flag)344uint16_t DCI_ReadIntFlag(DCI_INT_T flag) 345 { 346 return (DCI->MINTSTS & flag) ? SET : RESET; 347 } 348 349 /*! 350 * @brief Clear the DCI interrupt flag. 351 * 352 * @param flag: specifies the DCI interrupt pending bit to clear. 353 * This parameter can be any combination of the following values: 354 * @arg DCI_INT_CC: Frame capture complete interrupt mask 355 * @arg DCI_INT_OVR: Overflow interrupt mask 356 * @arg DCI_INT_ERR: Synchronization error interrupt mask 357 * @arg DCI_INT_VSYNC: VSYNC interrupt mask 358 * @arg DCI_INT_LINE: Line interrupt mask 359 * 360 * @retval None 361 */ DCI_ClearIntFlag(uint16_t flag)362void DCI_ClearIntFlag(uint16_t flag) 363 { 364 DCI->INTCLR = (uint16_t)flag; 365 } 366 367 /**@} end of group DCI_Functions */ 368 /**@} end of group DCI_Driver */ 369 /**@} end of group APM32F4xx_StdPeriphDriver */ 370