static int dcmi_config() { /* DCMI configuration */ DCMIHandle.Instance = DCMI; DCMIHandle.Init.VSPolarity = sensor.vsync_pol; /* VSYNC clock polarity */ DCMIHandle.Init.HSPolarity = sensor.hsync_pol; /* HSYNC clock polarity */ DCMIHandle.Init.PCKPolarity = sensor.pixck_pol; /* PXCLK clock polarity */ DCMIHandle.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; /* Enable Hardware synchronization */ DCMIHandle.Init.CaptureRate = DCMI_CR_ALL_FRAME; /* Capture rate all frames */ DCMIHandle.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; /* Capture 8 bits on every pixel clock */ DCMIHandle.Init.JPEGMode = DCMI_JPEG_DISABLE; /* Disable JPEG Mode */ /* Associate the DMA handle to the DCMI handle */ __HAL_LINKDMA(&DCMIHandle, DMA_Handle, DMAHandle); /* Configure and enable DCMI IRQ Channel */ HAL_NVIC_SetPriority(DCMI_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DCMI_IRQn); /* Init DCMI */ if (HAL_DCMI_Init(&DCMIHandle) != HAL_OK) { /* Initialization Error */ return -1; } __HAL_DCMI_DISABLE_IT(&DCMIHandle, DCMI_IT_LINE); __HAL_DCMI_DISABLE_IT(&DCMIHandle, DCMI_IT_VSYNC); __HAL_DCMI_DISABLE_IT(&DCMIHandle, DCMI_IT_ERR); __HAL_DCMI_DISABLE_IT(&DCMIHandle, DCMI_IT_OVF); return 0; }
/** * @brief Initializes the camera. * @param uint32_t Resolution : camera sensor requested resolution (x, y) : standard resolution * naming QQVGA, QVGA, VGA ... * * @retval Camera status */ uint8_t BSP_CAMERA_Init(uint32_t Resolution) { DCMI_HandleTypeDef *phdcmi; uint8_t status = CAMERA_ERROR; /* Get the DCMI handle structure */ phdcmi = &hDcmiEval; /*** Configures the DCMI to interface with the camera module ***/ /* DCMI configuration */ phdcmi->Init.CaptureRate = DCMI_CR_ALL_FRAME; phdcmi->Init.HSPolarity = DCMI_HSPOLARITY_HIGH; phdcmi->Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; phdcmi->Init.VSPolarity = DCMI_VSPOLARITY_HIGH; phdcmi->Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; phdcmi->Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; phdcmi->Instance = DCMI; /* Configure IO functionalities for CAMERA detect pin */ BSP_IO_Init(); /* Apply Camera Module hardware reset */ BSP_CAMERA_HwReset(); /* Check if the CAMERA Module is plugged on board */ if(BSP_IO_ReadPin(CAM_PLUG_PIN) == BSP_IO_PIN_SET) { status = CAMERA_NOT_DETECTED; return status; /* Exit with error */ } /* Read ID of Camera module via I2C */ if (s5k5cag_ReadID(CAMERA_I2C_ADDRESS) == S5K5CAG_ID) { /* Initialize the camera driver structure */ camera_drv = &s5k5cag_drv; CameraHwAddress = CAMERA_I2C_ADDRESS; /* DCMI Initialization */ BSP_CAMERA_MspInit(&hDcmiEval, NULL); HAL_DCMI_Init(phdcmi); /* Camera Module Initialization via I2C to the wanted 'Resolution' */ camera_drv->Init(CameraHwAddress, Resolution); CameraCurrentResolution = Resolution; /* Return CAMERA_OK status */ status = CAMERA_OK; } else { /* Return CAMERA_NOT_SUPPORTED status */ status = CAMERA_NOT_SUPPORTED; } return status; }
/** * @brief Initializes the camera. * @param Camera: Pointer to the camera configuration structure * @retval Camera status */ uint8_t BSP_CAMERA_Init(uint32_t Resolution) { DCMI_HandleTypeDef *phdcmi; uint8_t ret = CAMERA_ERROR; /* Get the DCMI handle structure */ phdcmi = &hdcmi_eval; /*** Configures the DCMI to interface with the camera module ***/ /* DCMI configuration */ phdcmi->Init.CaptureRate = DCMI_CR_ALL_FRAME; phdcmi->Init.HSPolarity = DCMI_HSPOLARITY_LOW; phdcmi->Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; phdcmi->Init.VSPolarity = DCMI_VSPOLARITY_LOW; phdcmi->Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; phdcmi->Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; phdcmi->Instance = DCMI; /* Configure IO functionalities for camera detect pin */ BSP_IO_Init(); /* Set the camera STANDBY pin */ BSP_IO_ConfigPin(XSDN_PIN, IO_MODE_OUTPUT); BSP_IO_WritePin(XSDN_PIN, SET); /* Check if the camera is plugged */ if(BSP_IO_ReadPin(CAM_PLUG_PIN)) { return CAMERA_ERROR; } /* DCMI Initialization */ DCMI_MspInit(); HAL_DCMI_Init(phdcmi); if(ov2640_ReadID(CAMERA_I2C_ADDRESS) == OV2640_ID) { /* Initialize the camera driver structure */ camera_drv = &ov2640_drv; /* Camera Init */ camera_drv->Init(CAMERA_I2C_ADDRESS, Resolution); /* Return CAMERA_OK status */ ret = CAMERA_OK; } current_resolution = Resolution; return ret; }
/* DCMI init function */ void MX_DCMI_Init(void) { hdcmi.Instance = DCMI; hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_HIGH; hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW; hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME; hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE; HAL_DCMI_Init(&hdcmi); }
int sensor_set_pixformat(enum sensor_pixformat pixformat) { if (sensor.pixformat == pixformat) { /* no change */ return 0; } mutex_lock(&fb->lock); fb->ready = 0; mutex_unlock(&fb->lock); if (sensor.set_pixformat == NULL || sensor.set_pixformat(pixformat) != 0) { /* operation not supported */ return -1; } /* set pixel format */ sensor.pixformat = pixformat; /* set bytes per pixel */ switch (pixformat) { case PIXFORMAT_GRAYSCALE: fb->bpp = 1; break; case PIXFORMAT_RGB565: case PIXFORMAT_YUV422: fb->bpp = 2; break; case PIXFORMAT_JPEG: fb->bpp = 0; break; default: return -1; } if (pixformat == PIXFORMAT_JPEG) { DCMIHandle.Init.JPEGMode = DCMI_JPEG_ENABLE; } else { DCMIHandle.Init.JPEGMode = DCMI_JPEG_DISABLE; } /* Init DCMI */ if (HAL_DCMI_Init(&DCMIHandle) != HAL_OK) { /* Initialization Error */ return -1; } return 0; }
/* DCMI init function */ void MX_DCMI_Init(void) { hdcmi.Instance = DCMI; hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING; hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW; hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW; hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME; hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE; hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL; hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD; hdcmi.Init.LineSelectMode = DCMI_LSM_ALL; hdcmi.Init.LineSelectStart = DCMI_OELS_ODD; HAL_DCMI_Init(&hdcmi); }
/** * @brief Initializes the Camera. * @param Camera: Pointer to the Camera configuration structure * @retval Camera status */ uint8_t BSP_CAMERA_Init(uint32_t Resolution) { DCMI_HandleTypeDef *phdcmi; uint8_t ret = CAMERA_ERROR; /* Get the DCMI handle structure */ phdcmi = &hdcmi_eval; /*** Configures the DCMI to interface with the Camera module ***/ /* DCMI configuration */ phdcmi->Init.CaptureRate = DCMI_CR_ALL_FRAME; phdcmi->Init.HSPolarity = DCMI_HSPOLARITY_LOW; phdcmi->Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; phdcmi->Init.VSPolarity = DCMI_VSPOLARITY_LOW; phdcmi->Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; phdcmi->Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; phdcmi->Instance = DCMI; /* DCMI Initialization */ DCMI_MspInit(); HAL_DCMI_Init(phdcmi); if(ov2640_drv.ReadID(CAMERA_I2C_ADDRESS) == OV2640_ID) { /* Initialize the Camera driver structure */ camera_drv = &ov2640_drv; /* Camera Init */ camera_drv->Init(CAMERA_I2C_ADDRESS, Resolution); /* Return CAMERA_OK status */ ret = CAMERA_OK; } current_resolution = Resolution; return ret; }
/** * @brief Initializes the camera. * @param Camera: Pointer to the camera configuration structure * @retval Camera status */ uint8_t BSP_CAMERA_Init(uint32_t Resolution) { DCMI_HandleTypeDef *phdcmi; uint8_t ret = CAMERA_ERROR; /* Get the DCMI handle structure */ phdcmi = &hDcmiEval; /*** Configures the DCMI to interface with the camera module ***/ /* DCMI configuration */ phdcmi->Init.CaptureRate = DCMI_CR_ALL_FRAME; phdcmi->Init.HSPolarity = DCMI_HSPOLARITY_HIGH; phdcmi->Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; phdcmi->Init.VSPolarity = DCMI_VSPOLARITY_HIGH; phdcmi->Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; phdcmi->Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; phdcmi->Init.ByteSelectMode = DCMI_BSM_ALL; phdcmi->Init.ByteSelectStart = DCMI_OEBS_ODD; phdcmi->Init.LineSelectMode = DCMI_LSM_ALL; phdcmi->Init.LineSelectStart = DCMI_OELS_ODD; phdcmi->Instance = DCMI; /* Configure IO functionalities for CAMERA detect pin */ BSP_IO_Init(); /* Apply Camera hardware reset */ BSP_CAMERA_HwReset(); /* Check if the CAMERA is plugged */ if(BSP_IO_ReadPin(CAM_PLUG_PIN)) { return CAMERA_ERROR; } if (s5k5cag_ReadID(CAMERA_I2C_ADDRESS) == S5K5CAG_ID) { /* Initialize the camera driver structure */ camera_drv = &s5k5cag_drv; cameraHwAddress = CAMERA_I2C_ADDRESS; /* DCMI Initialization */ BSP_CAMERA_MspInit(&hDcmiEval, NULL); HAL_DCMI_Init(phdcmi); /* Camera Init */ camera_drv->Init(cameraHwAddress, Resolution); currentResolution = Resolution; /* Return CAMERA_OK status */ ret = CAMERA_OK; } else { /* No supported camera sensor found */ ret = CAMERA_ERROR; } return ret; }