/** * @brief Initializes the OV9655 CAMERA component. * @param DeviceAddr: Device address on communication Bus. * @param resolution: Camera resolution * @retval None */ void ov9655_Init(uint16_t DeviceAddr, uint32_t resolution) { uint32_t index; /* Initialize I2C */ CAMERA_IO_Init(); /* Prepare the camera to be configured by resetting all its registers */ CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_COM7, 0x80); CAMERA_Delay(200); /* Initialize OV9655 */ switch (resolution) { case CAMERA_R160x120: { for(index=0; index<(sizeof(OV9655_QQVGA)/2); index++) { CAMERA_IO_Write(DeviceAddr, OV9655_QQVGA[index][0], OV9655_QQVGA[index][1]); CAMERA_Delay(2); } break; } case CAMERA_R320x240: { for(index=0; index<(sizeof(OV9655_QVGA)/2); index++) { CAMERA_IO_Write(DeviceAddr, OV9655_QVGA[index][0], OV9655_QVGA[index][1]); CAMERA_Delay(2); } break; } case CAMERA_R480x272: { /* Not supported resolution */ break; } case CAMERA_R640x480: { for(index=0; index<(sizeof(OV9655_VGA)/2); index++) { CAMERA_IO_Write(DeviceAddr, OV9655_VGA[index][0], OV9655_VGA[index][1]); CAMERA_Delay(2); } break; } default: { break; } } }
/** * @brief Configures the OV9655 camera feature. * @param DeviceAddr: Device address on communication Bus. * @param feature: Camera feature to be configured * @param value: Value to be configured * @param brightness_value: Brightness value to be configured * @retval None */ void ov9655_Config(uint16_t DeviceAddr, uint32_t feature, uint32_t value, uint32_t brightness_value) { uint8_t tslb, mtx1, mtx2, mtx3, mtx4, mtx5, mtx6; uint64_t value_tmp; uint32_t br_value; /* Convert the input value into ov9655 parameters */ value_tmp = ov9655_ConvertValue(feature, value); br_value = (uint32_t)ov9655_ConvertValue(CAMERA_CONTRAST_BRIGHTNESS, brightness_value); switch(feature) { case CAMERA_CONTRAST_BRIGHTNESS: { CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_BRTN, br_value); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_CNST1, value_tmp); break; } case CAMERA_BLACK_WHITE: case CAMERA_COLOR_EFFECT: { tslb = (uint8_t)(value_tmp >> 48); mtx1 = (uint8_t)(value_tmp >> 40); mtx2 = (uint8_t)(value_tmp >> 32); mtx3 = (uint8_t)(value_tmp >> 24); mtx4 = (uint8_t)(value_tmp >> 16); mtx5 = (uint8_t)(value_tmp >> 8); mtx6 = (uint8_t)(value_tmp); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_TSLB, tslb); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX1, mtx1); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX2, mtx2); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX3, mtx3); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX4, mtx4); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX5, mtx5); CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX6, mtx6); break; } default: { break; } } }
/** * @brief Read the OV2640 Camera identity. * @param DeviceAddr: Device address on communication Bus. * @retval the OV2640 ID */ uint16_t ov2640_ReadID(uint16_t DeviceAddr) { if(Is_I2C_Initialized == 0) { /* Initialize I2C */ CAMERA_IO_Init(); Is_I2C_Initialized = 1; } /* Prepare the sensor to read the Camera ID */ CAMERA_IO_Write(DeviceAddr, OV2640_DSP_RA_DLMT, 0x01); /* Get the camera ID */ return (CAMERA_IO_Read(DeviceAddr, OV2640_SENSOR_PIDH)); }
/** * @brief Configures the OV2640 camera feature. * @param DeviceAddr: Device address on communication Bus. * @param feature: the camera feature to be configured * @param value: the value to be configured * @param brightness_value: the brightness value to be configured * @retval None */ void ov2640_Config(uint16_t DeviceAddr, uint32_t feature, uint32_t value, uint32_t brightness_value) { uint8_t value1, value2; uint32_t value_tmp; uint32_t br_value; /* Convert the input value into ov2640 parameters */ value_tmp = ov2640_ConvertValue(feature, value); br_value = ov2640_ConvertValue(CAMERA_CONTRAST_BRIGHTNESS, brightness_value); switch(feature) { case CAMERA_BLACK_WHITE: { CAMERA_IO_Write(DeviceAddr, 0xff, 0x00); CAMERA_IO_Write(DeviceAddr, 0x7c, 0x00); CAMERA_IO_Write(DeviceAddr, 0x7d, value_tmp); CAMERA_IO_Write(DeviceAddr, 0x7c, 0x05); CAMERA_IO_Write(DeviceAddr, 0x7d, 0x80); CAMERA_IO_Write(DeviceAddr, 0x7d, 0x80); break; } case CAMERA_CONTRAST_BRIGHTNESS: { value1 = (uint8_t)(value_tmp); value2 = (uint8_t)(value_tmp >> 8); CAMERA_IO_Write(DeviceAddr, 0xff, 0x00); CAMERA_IO_Write(DeviceAddr, 0x7c, 0x00); CAMERA_IO_Write(DeviceAddr, 0x7d, 0x04); CAMERA_IO_Write(DeviceAddr, 0x7c, 0x07); CAMERA_IO_Write(DeviceAddr, 0x7d, br_value); CAMERA_IO_Write(DeviceAddr, 0x7d, value1); CAMERA_IO_Write(DeviceAddr, 0x7d, value2); CAMERA_IO_Write(DeviceAddr, 0x7d, 0x06); break; } case CAMERA_COLOR_EFFECT: { value1 = (uint8_t)(value_tmp); value2 = (uint8_t)(value_tmp >> 8); CAMERA_IO_Write(DeviceAddr, 0xff, 0x00); CAMERA_IO_Write(DeviceAddr, 0x7c, 0x00); CAMERA_IO_Write(DeviceAddr, 0x7d, 0x18); CAMERA_IO_Write(DeviceAddr, 0x7c, 0x05); CAMERA_IO_Write(DeviceAddr, 0x7d, value1); CAMERA_IO_Write(DeviceAddr, 0x7d, value2); break; } default: { break; } } }
/** * @brief Initializes the OV2640 CAMERA component. * @param DeviceAddr: Device address on communication Bus. * @param resolution: the Camera resolution * @retval None */ void ov2640_Init(uint16_t DeviceAddr, uint32_t resolution) { uint32_t index; if(Is_I2C_Initialized == 0) { Is_I2C_Initialized = 1; /* Initialize I2C */ CAMERA_IO_Init(); } /* Prepare the camera to be configured */ CAMERA_IO_Write(DeviceAddr, OV2640_DSP_RA_DLMT, 0x01); CAMERA_IO_Write(DeviceAddr, OV2640_SENSOR_COM7, 0x80); CAMERA_Delay(200); /* Initialize OV2640 */ switch (resolution) { case CAMERA_R160x120: { for(index=0; index<(sizeof(OV2640_QQVGA)/2); index++) { CAMERA_IO_Write(DeviceAddr, OV2640_QQVGA[index][0], OV2640_QQVGA[index][1]); CAMERA_Delay(1); } break; } case CAMERA_R320x240: { for(index=0; index<(sizeof(OV2640_QVGA)/2); index++) { CAMERA_IO_Write(DeviceAddr, OV2640_QVGA[index][0], OV2640_QVGA[index][1]); CAMERA_Delay(1); } break; } case CAMERA_R480x272: { for(index=0; index<(sizeof(OV2640_480x272)/2); index++) { CAMERA_IO_Write(DeviceAddr, OV2640_480x272[index][0], OV2640_480x272[index][1]); CAMERA_Delay(2); } break; } case CAMERA_R640x480: { for(index=0; index<(sizeof(OV2640_VGA)/2); index++) { CAMERA_IO_Write(DeviceAddr, OV2640_VGA[index][0], OV2640_VGA[index][1]); CAMERA_Delay(2); } break; } default: { break; } } }