(1)Hal流程的代码
(A)updateAEInfo2ISP(ae_mgr.cpp)
//vendor/mediatek/proprietary/hardware/mtkcam/aaa/source
MRESULT AeMgr::updateAEInfo2ISP(AE_STATE_T eNewAEState, MUINT32 u4ISPGain)
{
//...
switch (eNewAEState)
{
case AE_SENSOR_PER_FRAME_STATE :
rAEInfo2ISP.u4Eposuretime = m_u4UpdateShutterValue;
rAEInfo2ISP.u4AfeGain = m_u4UpdateGainValue;
if (u4ISPGain != 0x00)
{
rAEInfo2ISP.u4IspGain = u4ISPGain;
AE_LOG_IF(m_3ALogEnable, "[%s()] Smooth ISP Gain:%d avgY:%d\n", __FUNCTION__, rAEInfo2ISP.u4IspGain, m_pIAeAlgo->getBrightnessAverageValue());
}
else
{
rAEInfo2ISP.u4IspGain = 1024;
AE_LOG("[%s()] No Smooth ISP Gain:%d avgY:%d\n", __FUNCTION__, rAEInfo2ISP.u4IspGain, m_pIAeAlgo->getBrightnessAverageValue());
}
u4FinalGain = (rAEInfo2ISP.u4AfeGain * rAEInfo2ISP.u4IspGain) >> 10;
rAEInfo2ISP.u4RealISOValue = (u4PreviewBaseISO * u4FinalGain + (u4PreviewBaseGain - 1)) / u4PreviewBaseGain;
u2FrameRate = m_u4UpdateFrameRate_x10;
rAEInfo2ISP.bAEScenarioChange = MTRUE; //AE2AF info, avoid scenario(index) change mis-trigger AF
break;
}
//...
AE_LOG("[%s()] State:%d eAEstate:%d VDNum:%d Exp/Afe/Isp/ISO:%d/%d/%d/%d CurrentidxF:%d DisableOBC:%d FrameRate:%6.3f FrameDuration:%lld Flare offset/gain:%d/%d ExpRatio:%d\n",
__FUNCTION__, eNewAEState, m_eAEState, m_i4WaitVDNum,
rAEInfo2ISP.u4Eposuretime, rAEInfo2ISP.u4AfeGain, rAEInfo2ISP.u4IspGain, rAEInfo2ISP.u4RealISOValue, rAEInfo2ISP.u4AEidxCurrentF, rAEInfo2ISP.bDisableOBC,
u2FrameRate, (long long)m_rSensorCurrentInfo.u8FrameDuration, rAEInfo2ISP.i2FlareOffset, i2FlareGain, rAEInfo2ISP.u4EISExpRatio);
}
(B)configure(HalSensor.control.cpp)
//vendor/mediatek/proprietary/hardware/mtkcam/drv/src/sensor/common
MBOOL HalSensor::configure(
MUINT const uCountOfParam,
ConfigParam const *pArrayOfParam
)
{
//...
if (pArrayOfParam->HDRMode != 0) { // vHDR mode
//...
} else { // normal mode
MUINT exposureTime = pArrayOfParam->exposureTime;
MUINT gain = pArrayOfParam->gain;
if (exposureTime > 0 && gain > 0) {
ret = pSensorDrv->sendCommand(sensorIdx, CMD_SENSOR_SET_SENSOR_EXP_TIME, (MUINTPTR)&(exposureTime));
ret = pSensorDrv->sendCommand(sensorIdx, CMD_SENSOR_SET_SENSOR_GAIN, (MUINTPTR)&(gain));
}
}
}
(C)sendCommand(imgsensor_drv.cpp)
MINT32 ImgSensorDrv::sendCommand(
IMGSENSOR_SENSOR_IDX sensorIdx,
MUINT32 cmd,
MUINTPTR arg1,
MUINTPTR arg2,
MUINTPTR arg3
)
{
switch (cmd) {
case CMD_SENSOR_SET_SENSOR_EXP_TIME:
u8temp = *parg1;/*64bit extend */
FeatureId = SENSOR_FEATURE_SET_ESHUTTER;
LineTimeInus = m_LineTimeInus[sensorIdx];
FeaturePara[0] = ((1000 * (u8temp)) / LineTimeInus);
if(FeaturePara[0] == 0) { // avoid the line number to zero
LOG_MSG("[CMD_SENSOR_SET_EXP_TIME] m_LineTime = %llu %d", (long long)FeaturePara[0], LineTimeInus);
FeaturePara[0] = 1;
}
FeatureParaLen = sizeof(MUINT64);
pFeaturePara = (MUINT8*)FeaturePara;
LOG_MSG("[CMD_SENSOR_SET_EXP_TIME] FeaturePara[0] = %llu, FeaturePara[1] = %llu, FeaturePara[2] = %llu, FeaturePara[3] = %llu", FeaturePara[0], FeaturePara[1], FeaturePara[2], FeaturePara[3]);
break;
case CMD_SENSOR_SET_SENSOR_GAIN:
FeatureId = SENSOR_FEATURE_SET_GAIN;
FeaturePara[0] = *parg1; //from 10b to 6b base
FeaturePara[0] >>= 4;
FeatureParaLen = sizeof(MUINT64);
pFeaturePara = (MUINT8*)FeaturePara;
LOG_MSG("[CMD_SENSOR_SET_SENSOR_GAIN] FeaturePara[0] = %llu, FeaturePara[1] = %llu, FeaturePara[2] = %llu, FeaturePara[3] = %llu", FeaturePara[0], FeaturePara[1], FeaturePara[2], FeaturePara[3]);
break;
}
//...
err= featureControl(sensorIdx, FeatureId, (MUINT8*)pFeaturePara,(MUINT32*)&FeatureParaLen);
}
ImgSensorDrv::featureControl(
IMGSENSOR_SENSOR_IDX sensorIdx,
ACDK_SENSOR_FEATURE_ENUM FeatureId,
MUINT8 *pFeaturePara,
MUINT32 *pFeatureParaLen
)
{
ACDK_SENSOR_FEATURECONTROL_STRUCT featureCtrl;
if (m_fdSensor == -1) {
LOG_ERR("[sendCommand]m_fdSensor fail, sendCommand must be called after init()!");
return SENSOR_UNKNOWN_ERROR;
}
if (pFeaturePara == NULL || pFeatureParaLen == NULL) {
return SENSOR_INVALID_PARA;
}
featureCtrl.InvokeCamera = sensorIdx;
featureCtrl.FeatureId = FeatureId;
featureCtrl.pFeaturePara = pFeaturePara;
featureCtrl.pFeatureParaLen = pFeatureParaLen;
if (ioctl(m_fdSensor, KDIMGSENSORIOC_X_FEATURECONCTROL , &featureCtrl) < 0) {
LOG_ERR("[featureControl] Err-ctrlCode (%s)", strerror(errno));
return -errno;
}
return SENSOR_NO_ERROR;
}
通过featureControl最终调用到ioctl控制函数,进而调用到Camera Drv驱动。
(2)Drv流程的代码
static struct SENSOR_FUNCTION_STRUCT sensor_func = {
open,
get_info,
get_resolution,
feature_control,
control,
close
};
UINT32 XXXX_MIPI_RAW_SensorInit(struct SENSOR_FUNCTION_STRUCT **pfFunc)
{
/* Check Sensor status here */
if (pfFunc != NULL)
*pfFunc = &sensor_func;
return ERROR_NONE;
}
static kal_uint32 feature_control(MSDK_SENSOR_FEATURE_ENUM feature_id,
UINT8 *feature_para, UINT32 *feature_para_len)
{
//...
LOG_INF("feature_id = %d\n", feature_id);
switch (feature_id) {
case SENSOR_FEATURE_SET_ESHUTTER:
set_shutter(*feature_data);
break;
case SENSOR_FEATURE_SET_GAIN:
set_gain((UINT16)*feature_data);
break;
}
//...
}
而set_gain和set_shutter函数如下:
static kal_uint16 gain2reg(kal_uint16 gain)
{
kal_uint16 reg_gain = gain << 4;
reg_gain = (reg_gain < SENSOR_BASE_GAIN) ? SENSOR_BASE_GAIN : reg_gain;
reg_gain = (reg_gain > SENSOR_MAX_GAIN) ? SENSOR_MAX_GAIN : reg_gain;
return reg_gain;
}
static kal_uint16 set_gain(kal_uint16 gain)
{
kal_uint32 reg_gain = 0;
reg_gain = gain2reg(gain);
write_cmos_sensor(0x0204, reg_gain & 0xffff);
return gain;
}
static void set_shutter(kal_uint32 shutter)
{
//...
shutter = (shutter < imgsensor_info.min_shutter) ? imgsensor_info.min_shutter : shutter;
shutter = (shutter > (imgsensor_info.max_frame_length - imgsensor_info.margin)) ?
(imgsensor_info.max_frame_length - imgsensor_info.margin) : shutter;
write_cmos_sensor(0x0202, shutter & 0xffff);
LOG_INF("shutter = %d, framelength = %d\n",
shutter, imgsensor.frame_length);
}
最终通过Drv驱动设置到寄存器中。
(3)Log示例显示
(A)ITS测试Log
//python tests/scene1_1/test_param_exposure_time.py camera=0 scenes=1_1
fmt = {'width': 320, 'height': 240, 'format': 'yuv'} ,s = 219 ,e = 150050000
e_mult = 0.8 ,e * e_mult = 120040000.0
Capturing 1 frame with 1 format [yuv]
e_mult = 0.9 ,e * e_mult = 135045000.0
Capturing 1 frame with 1 format [yuv]
e_mult = 1.0 ,e * e_mult = 150050000.0
Capturing 1 frame with 1 format [yuv]
e_mult = 1.1 ,e * e_mult = 165055000.0
Capturing 1 frame with 1 format [yuv]
e_mult = 1.2 ,e * e_mult = 180060000.0
Capturing 1 frame with 1 format [yuv]
(B)Main Log
D ae_mgr : [updateAEInfo2ISP()] State:10 eAEstate:0 VDNum:0 Exp/Afe/Isp/ISO:120040/2242/1024/219 CurrentidxF:102 DisableOBC:0 FrameRate:83.306 FrameDuration:120100024 Flare offset/gain:0/512 ExpRatio:100
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_EXP_TIME] FeaturePara[0] = 12004, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_SENSOR_GAIN] FeaturePara[0] = 140, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ae_mgr : [updateAEInfo2ISP()] State:10 eAEstate:0 VDNum:0 Exp/Afe/Isp/ISO:135045/2242/1024/219 CurrentidxF:102 DisableOBC:0 FrameRate:74.049 FrameDuration:135112528 Flare offset/gain:0/512 ExpRatio:100
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_EXP_TIME] FeaturePara[0] = 13504, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_SENSOR_GAIN] FeaturePara[0] = 140, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ae_mgr : [updateAEInfo2ISP()] State:10 eAEstate:0 VDNum:0 Exp/Afe/Isp/ISO:150050/2242/1024/219 CurrentidxF:102 DisableOBC:0 FrameRate:66.644 FrameDuration:150125024 Flare offset/gain:0/512 ExpRatio:100
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_EXP_TIME] FeaturePara[0] = 15005, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_SENSOR_GAIN] FeaturePara[0] = 140, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ae_mgr : [updateAEInfo2ISP()] State:10 eAEstate:0 VDNum:0 Exp/Afe/Isp/ISO:165055/2242/1024/219 CurrentidxF:102 DisableOBC:0 FrameRate:60.586 FrameDuration:165137536 Flare offset/gain:0/512 ExpRatio:100
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_EXP_TIME] FeaturePara[0] = 16505, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_SENSOR_GAIN] FeaturePara[0] = 140, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ae_mgr : [updateAEInfo2ISP()] State:10 eAEstate:0 VDNum:0 Exp/Afe/Isp/ISO:180060/2242/1024/219 CurrentidxF:102 DisableOBC:0 FrameRate:55.537 FrameDuration:180150032 Flare offset/gain:0/512 ExpRatio:100
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_EXP_TIME] FeaturePara[0] = 18006, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
D ImgSensorDrv: [sendCommand][CMD_SENSOR_SET_SENSOR_GAIN] FeaturePara[0] = 140, FeaturePara[1] = 0, FeaturePara[2] = 0, FeaturePara[3] = 0
(C)Kernel Log
(2)[11558:3AEventThd]OV13853_camera_sensor[set_shutter] Enter! shutter =12004
(0)[11558:3AEventThd]OV13853_camera_sensor[set_shutter] Exit! shutter =12004, framelength =12012
(0)[338:init]OV13853_camera_sensor[set_gain] gain = 140 , reg_gain = 0x23
(3)[11623:3AEventThd]OV13853_camera_sensor[set_shutter] Enter! shutter =13504
(1)[11623:3AEventThd]OV13853_camera_sensor[set_shutter] Exit! shutter =13504, framelength =13512
(3)[0:swapper/3]OV13853_camera_sensor[set_gain] gain = 140 , reg_gain = 0x23
(1)[11689:3AEventThd]OV13853_camera_sensor[set_shutter] Enter! shutter =15005
(0)[11689:3AEventThd]OV13853_camera_sensor[set_shutter] Exit! shutter =15004, framelength =15012
(1)[0:swapper/1]OV13853_camera_sensor[set_gain] gain = 140 , reg_gain = 0x23
(1)[11754:3AEventThd]OV13853_camera_sensor[set_shutter] Enter! shutter =16505
(1)[11754:3AEventThd]OV13853_camera_sensor[set_shutter] Exit! shutter =16504, framelength =16512
(1)[0:swapper/1]OV13853_camera_sensor[set_gain] gain = 140 , reg_gain = 0x23
(3)[11819:3AEventThd]OV13853_camera_sensor[set_shutter] Enter! shutter =18006
(0)[11819:3AEventThd]OV13853_camera_sensor[set_shutter] Exit! shutter =18006, framelength =18014
(3)[0:swapper/3]OV13853_camera_sensor[set_gain] gain = 140 , reg_gain = 0x23
具体可以gain/shutter相关的测试可参考链接当中的几个测试项Camera ITS当中的部分测试项文档。