OV5640 MIPI camera on a iMX6 set exposure and gain

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

OV5640 MIPI camera on a iMX6 set exposure and gain

7,141 Views
sreekanthm
Contributor II

Hi,

 

I am trying to implement the Camera Exposure parameter on OV5640 over MIPI but change in Camera Exposure via user interface has no effect on the display.

 

I followed below article as a base to my changes:

https://community.freescale.com/message/503821#503821

 

Below are the changes I made:

  1. In ov5640_mipi.c routine, in ioctl_s_ctrl function:

static int ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *vc)

{

 

     switch (vc->id) {

     case V4L2_CID_EXPOSURE:

     /* turn off AE/AG */

      OV5640_turn_on_AE_AG(0);

      OV5640_set_shutter((__s32)vc->value);

      break;

     case V4L2_CID_GAIN:

      OV5640_set_gain16((__s32)vc->value);

      break;

}

}

2. In ov5640Mipi.cpp, below changes are introduced in setparameter() function

status_t Ov5640Mipi::setCameraExposureParams(int32_t expparams)

{

    FLOGI("Start of Ov5640Mipi.cpp - Exposure Value: %d", expparams);

    struct v4l2_control int_control_exp;

    int_control_exp.id = V4L2_CID_EXPOSURE;

    int_control_exp.value = expparams;

    int ret_exp = ioctl(mCameraHandle, VIDIOC_S_CTRL, &int_control_exp);

    FLOGI("The Returned exposure setting status: %d", ret_exp);

 

    return NO_ERROR;

}

 

3. DeviceAdapter.cpp

status_t DeviceAdapter::startDeviceLocked()

{

....

....

....

setCameraExposureCompensation();

}

 

void DeviceAdapter::setCameraExposureCompensation()

{

    FLOGE("DeviceAdapter: Inside setCameraExposureCompensation");

    int32_t expComp;

    status_t ret1 = NO_ERROR;

 

    ret1 = mMetadaManager->getExposureCompensation(expComp);

    if (ret1 != NO_ERROR) {

        FLOGE("DeviceAdapter: getExposureCompensation failed");

        expComp = 0;

        return;

    }

    FLOGE("DeviceAdapter: Exposure Compensation: %d", expComp);

    ret1 = setCameraExposureParams(expComp);

    if (ret1 != NO_ERROR) {

        FLOGE("DeviceAdapter: setCameraExposureParams failed");

        return;

    }

    FLOGE("DeviceAdapter: End of setCameraExposureCompensation");

}

 

status_t DeviceAdapter::setCameraExposureParams(int32_t expparams)

{

    FLOGE("DeviceAdapter: setCameraExposureParams: %d",expparams);   

    return NO_ERROR;

}

 

4. MetadaManager.cpp

 

status_t MetadaManager::getExposureCompensation(int32_t &expComp)

{

    ALOGE("MetadaManager: Executing getExposureCompensation");   

    camera_metadata_entry_t streams;

    int res = find_camera_metadata_entry(mCurrentRequest,

                ANDROID_CONTROL_AE_EXP_COMPENSATION, &streams);

    if (res != NO_ERROR) {

        ALOGE("%s: error reading jpeg Rotation tag", __FUNCTION__);

        return BAD_VALUE;

    }

    expComp = streams.data.i32[0];

    ALOGE("MetadaManager: Exposure Compensation value: %d",expComp);

    return NO_ERROR;

}

MetadaManager always returns 0 as exposure value, camera does not display continuously and no impact on change in Exposure.

Attached is logcat and routines changed.

Please share your thoughts on what's is missing in my implementation. Let me know if you need further details about the issue / implementation.

0 Kudos
3 Replies

1,174 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hi Sreekanth,

    In android, OV5640_MIPI's HAL is Ov5440Mipi.cpp & Ov5640Mipi.h, not ov5640.cpp, so if you use ov5640.cpp to be camera HAL, your settings is invalidate.

    In addtion, all configuration data for ov5640 is set through I2C bus, not MIPI-CSI2 interface, what MIPI transimits is only video data.

Regards,

Weidong

0 Kudos

1,174 Views
sreekanthm
Contributor II

Hi Weidong,

Thanks for your time.

I have implemented below changes based on your suggestion but of no luck, can you please review and suggest what I am missing

Ov5640Mipi.h

class Ov5640Mipi : public OvDevice {
public:
virtual status_t initSensorInfo(const CameraInfo& info);
virtual status_t setParameters(CameraParameters& params);
};

Ov5640Mipi.cpp

status_t Ov5640Mipi::setParameters(CameraParameters& params)
{
int max_exp, min_exp, new_exp, ret_exp, new_gain, ret_gain;
Mutex::Autolock lock(mLock);
max_exp = params.getInt(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION);
min_exp = params.getInt(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION);
new_exp = params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION);
FLOGI("ov5640Mipi.cpp Exposure settings Max %d, Min %d, Current %d", max_exp,min_exp,new_exp);
  if ((new_exp > max_exp) || (new_exp < min_exp)){
FLOGE("Invalid exposure setting, valid range from %d, to %d", min_exp, max_exp);
return BAD_VALUE;
}
struct v4l2_control int_control_exp;
int_control_exp.id = V4L2_CID_EXPOSURE;
int_control_exp.value = new_exp;
ret_exp = ioctl(mCameraHandle, VIDIOC_S_CTRL, &int_control_exp);
FLOGI("The exposure setting status%d", ret_exp);

new_gain = params.getInt(CameraParameters::KEY_EXPOSURE_GAIN);
if (new_gain != -1)
{
struct v4l2_control int_control_gain;
int_control_gain.id = V4L2_CID_GAIN;
int_control_gain.value = new_gain;
ret_gain = ioctl(mCameraHandle, VIDIOC_S_CTRL, &int_control_gain);
FLOGI("The gain setting status%d", ret_gain);
}

//mParams = params;
return NO_ERROR;
}

Thanks,

Sreekanth

0 Kudos

1,174 Views
sreekanthm
Contributor II

Thanks Weidong for information.

I don't see a place/way in Ov5640Mipi.cpp to implement exposure, can you please advise how to implement exposure & gain properties.

Thanks,
Sreekanth

0 Kudos