Mtk Camera Hal to drive process

(1) Camera imaging principle

(A) Imaging principle

  • The optical image generated by the lens is projected onto the image sensor (CMOS/CCD integrated circuit) to convert the optical signal into electrical signal;
  • Then it is converted into digital image signal (processed by image processor ISP) after A/D (analog-to-digital conversion);
  • It is sent to the digital signal processor for processing (DSP) and converted into standard GRB, YUV and other image signals;


(B) The camera consists of four parts

Lens, sensor, ISP, DSP

  • Lens is the soul of the camera. Lens plays a very important role in imaging effect. It uses the refraction principle of lens to form a clear image on the focusing plane through the lens, and records the image of the scene through the photosensitive material CMOS or CCD photoreceptor;
  • Image sensor is a semiconductor chip. Its surface contains hundreds of thousands to millions of photodiodes. When the diode is illuminated, it will generate electric charge. At present, there are two kinds of CCD, one is the widely used CCD (charge coupled) element, the other is CMOS (complementary metal oxide conductor) device;
  • The performance of ISP is the key to decide whether it is smooth or not;
  • Digital signal processor (DSP) transfers the data obtained by the photosensitive chip to the central processing unit in time and quickly and refreshes the photosensitive chip. Therefore, the quality of DSP chip directly affects the picture quality (such as color saturation, clarity, etc.);

(C) Image output format

Common output formats: YUV format, RGB format and Rawdata format

  • YUV format: "Y" indicates brightness, "U" and "V" indicate chroma and concentration. Generally, the sensor supports YUV422 format, that is, the data format is output in Y-U-Y-V order;
  • RGB format: traditional red, green and blue formats, such as RGB565/RGB8888, use this coding method. Each color can use three variables to represent the intensity of red, green and blue. Each pixel is composed of three primary colors R red, G green and B blue;
  • The image sensor converts the captured light source signal into the original data of digital signal. RAW file is a file that records the original information of the digital camera sensor and some original data (Metadata, such as ISO setting, shutter speed, aperture value, white balance, etc.) generated by the camera;

(2) Sensor Drv structure


First, let's take a look at the struct related to Sensor Drv, which is gc8034_mipi_raw as an example.

(A) Control Flip + Mirror effect

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.h

#define  GC8034_MIRROR_NORMAL
#undef  GC8034_MIRROR_H
#undef  GC8034_MIRROR_V
#undef GC8034_MIRROR_HV

#if defined(GC8034_MIRROR_NORMAL)
	#define GC8034_MIRROR         0xc0
	#define GC8034_BinStartY      0x04
	#define GC8034_BinStartX      0x05
	#define GC8034_FullStartY     0x08
	#define GC8034_FullStartX     0x09
#elif defined(GC8034_MIRROR_H)
	#define GC8034_MIRROR         0xc1
	#define GC8034_BinStartY      0x04
	#define GC8034_BinStartX      0x05
	#define GC8034_FullStartY     0x08
	#define GC8034_FullStartX     0x0b
#elif defined(GC8034_MIRROR_V)
	#define GC8034_MIRROR         0xc2
	#define GC8034_BinStartY      0x04
	#define GC8034_BinStartX      0x05
	#define GC8034_FullStartY     0x08
	#define GC8034_FullStartX     0x09
#elif defined(GC8034_MIRROR_HV)
	#define GC8034_MIRROR         0xc3
	#define GC8034_BinStartY      0x04
	#define GC8034_BinStartX      0x05
	#define GC8034_FullStartY     0x08
	#define GC8034_FullStartX     0x0b
#else
	#define GC8034_MIRROR         0xc0
	#define GC8034_BinStartY      0x04
	#define GC8034_BinStartX      0x05
	#define GC8034_FullStartY     0x08
	#define GC8034_FullStartX     0x09
#endif

(B)struct imgsensor_mode_struct structure with different pattern characteristics: this structure describes pclk/linelength/framelength, etc. in each pattern.

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.h

enum{
	IMGSENSOR_MODE_INIT,
	IMGSENSOR_MODE_PREVIEW,
	IMGSENSOR_MODE_CAPTURE,
	IMGSENSOR_MODE_VIDEO,
	IMGSENSOR_MODE_HIGH_SPEED_VIDEO,
	IMGSENSOR_MODE_SLIM_VIDEO,
};

struct imgsensor_mode_struct {
	kal_uint32 pclk;                    /*record different mode's pclk*/
	kal_uint32 linelength;              /*record different mode's linelength*/
	kal_uint32 framelength;             /*record different mode's framelength*/
	kal_uint8  startx;                  /*record different mode's startx of grabwindow*/
	kal_uint8  starty;                  /*record different mode's startx of grabwindow*/
	kal_uint16 grabwindow_width;        /*record different mode's width of grabwindow*/
	kal_uint16 grabwindow_height;       /*record different mode's height of grabwindow*/
	/* following for MIPIDataLowPwr2HighSpeedSettleDelayCount by different scenario */
	kal_uint8  mipi_data_lp2hs_settle_dc;
	/* following for GetDefaultFramerateByScenario() */
	kal_uint32 mipi_pixel_rate;
	kal_uint16 max_framerate;
};

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.c
static struct imgsensor_info_struct imgsensor_info = {
	.sensor_id = GC8034_SENSOR_ID,       /*record sensor id defined in Kd_imgsensor.h*/
	.checksum_value = 0x1b375588,		//0xa11f4e23,            /*checksum value for Camera Auto Test*/

	.pre = {
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,                /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 3264,
		.grabwindow_height = 2448,
		.mipi_data_lp2hs_settle_dc = 85, /*unit, ns*/
		.mipi_pixel_rate = 268800000,	//672000000,
		.max_framerate = 300,
	},

	.cap = {
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,               /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 3264,
		.grabwindow_height = 2448,
		.mipi_data_lp2hs_settle_dc = 85, /*unit, ns*/
		.mipi_pixel_rate = 268800000,	//672000000,
		.max_framerate = 300,
	},
	//...
};

The corresponding description information is as follows: pclk ≈ linelength * frame_length * framerate.

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.c

static kal_uint32 set_max_framerate_by_scenario(enum MSDK_SCENARIO_ID_ENUM scenario_id, MUINT32 framerate) 
{
	kal_uint32 frame_length;

	LOG_INF("scenario_id = %d, framerate = %d\n", scenario_id, framerate);

	switch (scenario_id) {
	case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
		frame_length = imgsensor_info.pre.pclk / framerate * 10 / imgsensor_info.pre.linelength;
		spin_lock(&imgsensor_drv_lock);
		imgsensor.dummy_line = (frame_length > imgsensor_info.pre.framelength) ?
			(frame_length - imgsensor_info.pre.framelength) : 0;
		imgsensor.frame_length = imgsensor_info.pre.framelength + imgsensor.dummy_line;
		imgsensor.min_frame_length = imgsensor.frame_length;
		spin_unlock(&imgsensor_drv_lock);
    	if(imgsensor.frame_length > imgsensor.shutter)
		{
			set_dummy();
		}
		break;
	case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
		if (framerate == 0)
			return ERROR_NONE;
		frame_length = imgsensor_info.normal_video.pclk / framerate * 10 /
			imgsensor_info.normal_video.linelength;
		spin_lock(&imgsensor_drv_lock);
		imgsensor.dummy_line = (frame_length > imgsensor_info.normal_video.framelength) ?
			(frame_length - imgsensor_info.normal_video.framelength) : 0;
		imgsensor.frame_length = imgsensor_info.normal_video.framelength + imgsensor.dummy_line;
		imgsensor.min_frame_length = imgsensor.frame_length;
		spin_unlock(&imgsensor_drv_lock);
    	if(imgsensor.frame_length > imgsensor.shutter)
		{
			set_dummy();
		}
		break;
		//...
}

The linelength of the sensor is fixed, and the pclk of each mode is also not adjustable. Therefore, to adjust the frame rate, you can only adjust the frame_length. set_dummy immediately changes the current frame rate to the set frame rate.

(C)struct imgsensor_info_struct describes the structure of the sensor info constant.

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.h

struct imgsensor_info_struct {
   	kal_uint32 sensor_id;                      /*record sensor id defined in Kd_imgsensor.h*/
   	kal_uint32 checksum_value;                 /*checksum value for Camera Auto Test*/
   //Information of different mode s
   	struct imgsensor_mode_struct pre;          /*preview scenario relative information*/
   	struct imgsensor_mode_struct cap;          /*capture scenario relative information*/
   	struct imgsensor_mode_struct cap1;
   	struct imgsensor_mode_struct cap2;
   	struct imgsensor_mode_struct normal_video; /*normal video  scenario relative information*/
   	struct imgsensor_mode_struct hs_video;     /*high speed video scenario relative information*/
   	struct imgsensor_mode_struct slim_video;   /*slim video for VT scenario relative information*/
    //Supported features
   	kal_uint8  ae_shut_delay_frame;            /*shutter delay frame for AE cycle*/
   	kal_uint8  ae_sensor_gain_delay_frame;     /*sensor gain delay frame for AE cycle*/
   	kal_uint8  ae_ispGain_delay_frame;         /*isp gain delay frame for AE cycle*/
   	kal_uint8  ihdr_support;                   /*1, support; 0,not support*/
   	kal_uint8  ihdr_le_firstline;              /*1,le first ; 0, se first*/
   	kal_uint8  sensor_mode_num;                /*support sensor mode num*/
    //Frame loss processing (losing data of unstable frames)
   	kal_uint8  cap_delay_frame;                /*enter capture delay frame num*/
   	kal_uint8  pre_delay_frame;                /*enter preview delay frame num*/
   	kal_uint8  video_delay_frame;              /*enter video delay frame num*/
   	kal_uint8  hs_video_delay_frame;           /*enter high speed video  delay frame num*/
   	kal_uint8  slim_video_delay_frame;         /*enter slim video delay frame num*/
   	kal_uint8  margin;                         /*sensor framelength & shutter margin*/
   	kal_uint32 min_shutter;                    /*min shutter*/
   	kal_uint32 max_frame_length;               /*max framelength by sensor register's limitation*/
    //isp drive current. Excessive current may cause RF interference
   	kal_uint8  isp_driving_current;            /*mclk driving current*/
   	kal_uint8  sensor_interface_type;          /*sensor_interface_type*/
   	kal_uint8  mipi_sensor_type;
   	/*0,MIPI_OPHY_NCSI2; 1,MIPI_OPHY_CSI2, default is NCSI2, don't modify this para*/
   	/*don't modify this para*/
   	kal_uint8  mipi_settle_delay_mode;
   	/*0, high speed signal auto detect; 1, use settle delay,unit is ns, */
   	kal_uint8  sensor_output_dataformat;       /*sensor output first pixel color*/
   	kal_uint8  mclk;                           /*mclk value, suggest 24 or 26 for 24Mhz or 26Mhz*/
   	kal_uint8  mipi_lane_num;                  /*mipi lane num*/
   	kal_uint8  i2c_addr_table[5];
   	/*record sensor support all write id addr, only supprt 4must end with 0xff*/
};
//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.c

static struct imgsensor_info_struct imgsensor_info = {
	.sensor_id = GC8034_SENSOR_ID,       /*record sensor id defined in Kd_imgsensor.h*/
	.checksum_value = 0x1b375588,		//0xa11f4e23,            /*checksum value for Camera Auto Test*/

	.pre = {
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,                /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 3264,
		.grabwindow_height = 2448,
		.mipi_data_lp2hs_settle_dc = 85, /*unit, ns*/
		.mipi_pixel_rate = 268800000,	//672000000,
		.max_framerate = 300,
	},

	.cap = {
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,               /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 3264,
		.grabwindow_height = 2448,
		.mipi_data_lp2hs_settle_dc = 85, /*unit, ns*/
		.mipi_pixel_rate = 268800000,	//672000000,
		.max_framerate = 300,
	},
	.cap1 = {
		/* capture for PIP 24fps relative information */
		/* capture1 mode must use same framelength */
		/* linelength with Capture mode for shutter calculate */
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,               /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 3264,
		.grabwindow_height = 2448,
		.mipi_data_lp2hs_settle_dc = 85,/*unit , ns*/
		/* less than 13M(include 13M),cap1 max framerate is 24fps */
		/* 16M max framerate is 20fps, 20M max framerate is 15fps */
		.mipi_pixel_rate = 215040000,	//672000000,
		.max_framerate = 240,
	},
	.normal_video = {
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,               /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 3264,
		.grabwindow_height = 2448,
		.mipi_data_lp2hs_settle_dc = 85,/*unit , ns*/
		.mipi_pixel_rate = 268800000,	//672000000,
		.max_framerate = 300,
	},
	.hs_video = {
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,               /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 1632,
		.grabwindow_height = 1224,
		.mipi_data_lp2hs_settle_dc = 85,/*unit , ns*/
		.mipi_pixel_rate = 268800000,	//672000000,
		.max_framerate = 300,
	},
	.slim_video = {
		.pclk = 320000000,                /*record different mode's pclk*/
		.linelength = 4272,               /*record different mode's linelength*/
		.framelength = 2500,
		.startx = 0,
		.starty = 0,
		.grabwindow_width = 1280,
		.grabwindow_height = 720,
		.mipi_data_lp2hs_settle_dc = 85,/*unit , ns*/
		.mipi_pixel_rate = 268800000,	//672000000,
		.max_framerate = 300,
	},
	.margin = 4,                          /* sensor framelength & shutter margin */
	.min_shutter = 4,                     /* min shutter */
	.max_frame_length =0x7fff,           /* 0xffff 0x29b3max framelength by sensor register's limitation */
	.ae_shut_delay_frame = 0,
	/* shutter delay frame for AE cycle, 2 frame with ispGain_delay-shut_delay=2-0=2 */
	.ae_sensor_gain_delay_frame = 0,
	/* sensor gain delay frame for AE cycle, */
	/* 2 frame with ispGain_delay-sensor_gain_delay=2-0=2 */
	.ae_ispGain_delay_frame = 2,          /* isp gain delay frame for AE cycle */
	.frame_time_delay_frame = 2,
	.ihdr_support = 0,                    /* 1, support; 0,not support */
	.ihdr_le_firstline = 0,               /* 1,le first ; 0, se first */
	.sensor_mode_num = 5,                 /* support sensor mode num */
	.cap_delay_frame = 2,                 /* enter capture delay frame num */
	.pre_delay_frame = 2,                 /* enter preview delay frame num */
	.video_delay_frame = 2,               /* enter video delay frame num */
	.hs_video_delay_frame = 2,            /* enter high speed video  delay frame num */
	.slim_video_delay_frame = 2,          /* enter slim video delay frame num */

	.isp_driving_current = ISP_DRIVING_8MA,                 /* mclk driving current */
	.sensor_interface_type = SENSOR_INTERFACE_TYPE_MIPI,    /* sensor_interface_type */
	.mipi_sensor_type = MIPI_OPHY_NCSI2,                    /* 0,MIPI_OPHY_NCSI2;  1,MIPI_OPHY_CSI2 */
	.mipi_settle_delay_mode = MIPI_SETTLEDELAY_AUTO,
	/* 0,MIPI_SETTLEDELAY_AUTO; 1,MIPI_SETTLEDELAY_MANNUAL */
#if defined(GC8034_MIRROR_NORMAL)
	.sensor_output_dataformat = SENSOR_OUTPUT_FORMAT_RAW_R, /*sensor output first pixel color*/
#elif defined(GC8034_MIRROR_H)
	.sensor_output_dataformat = SENSOR_OUTPUT_FORMAT_RAW_Gr,/*sensor output first pixel color*/
#elif defined(GC8034_MIRROR_V)
	.sensor_output_dataformat = SENSOR_OUTPUT_FORMAT_RAW_Gb,/*sensor output first pixel color*/
#elif defined(GC8034_MIRROR_HV)
	.sensor_output_dataformat = SENSOR_OUTPUT_FORMAT_RAW_B, /*sensor output first pixel color*/
#else
	.sensor_output_dataformat = SENSOR_OUTPUT_FORMAT_RAW_R, /*sensor output first pixel color*/
#endif
	.mclk = 24,                                             /* mclk value, suggest 24 or 26 for 24Mhz or 26Mhz */
	.mipi_lane_num = SENSOR_MIPI_4_LANE,                    /* mipi lane num */
	.i2c_addr_table = { 0x6e, 0xff },
	/* record sensor support all write id addr, only supprt 4must end with 0xff */
};

(D)struct imgsensor_struct records the structure of sensor info variable: it is used to dynamically save the key information of sensor.

struct imgsensor_struct {
//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.h

    //The current record is normal, or H mirror, or V flip, or both H & v
   	kal_uint8  mirror;                        /*mirrorflip information*/
    //Record the current mode(init/preview/capture/video)
   	kal_uint8  sensor_mode;                   /*record IMGSENSOR_MODE enum value*/
    //Record the current shutter value
   	kal_uint32 shutter;                       /*current shutter*/
    //Record the current sensor gain value
   	kal_uint16 gain;                          /*current gain*/
   	kal_uint32 pclk;                          /*current pclk*/
   	kal_uint32 frame_length;                  /*current framelength*/
   	kal_uint32 line_length;                   /*current linelength*/
   	kal_uint32 min_frame_length;              /*current min  framelength to max framerate*/
    //Record the current value of dummy pixel and dummy line
    kal_uint16 dummy_pixel;                   /*current dummypixel*/
    kal_uint16 dummy_line;                    /*current dummline*/
    kal_uint16 current_fps;                   /*current max fps*/
    kal_bool   autoflicker_en;                /*record autoflicker enable or disable*/
    kal_bool   test_pattern;                  /*record test pattern mode or not*/
    //Record the current scenario (preview/capture/video)
    enum MSDK_SCENARIO_ID_ENUM current_scenario_id;/*current scenario id*/
    kal_bool   ihdr_en;                       /*ihdr enable or disable*/
    //Record the address currently i2c used
    kal_uint8  i2c_write_id;                  /*record current sensor's i2c write id*/
};

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.c

static struct imgsensor_struct imgsensor = {
	.mirror = IMAGE_HV_MIRROR,            /* IMAGE_NORMAL, mirrorflip information */
	.sensor_mode = IMGSENSOR_MODE_INIT,
	/* IMGSENSOR_MODE enum value,record current sensor mode */
	/* such as: INIT, Preview, Capture, Video,High Speed Video, Slim Video */
	.shutter = 0x3ED,                     /* current shutter */
	.gain = 0x40,                         /* current gain */
	.dummy_pixel = 0,                     /* current dummypixel */
	.dummy_line = 0,                      /* current dummyline */
	.current_fps = 300,                   /* full size current fps : 24fps for PIP, 30fps for Normal or ZSD */
	.autoflicker_en = KAL_FALSE,
	/* auto flicker enable: KAL_FALSE for disable auto flicker, KAL_TRUE for enable auto flicker */
	.test_pattern = KAL_FALSE,
	/* test pattern mode or not. KAL_FALSE for in test pattern mode, KAL_TRUE for normal output */
	.current_scenario_id = MSDK_SCENARIO_ID_CAMERA_PREVIEW,	/* current scenario id */
	.ihdr_en = 0,                         /* sensor need support LE, SE with HDR feature */
	.i2c_write_id = 0x6e,                 /* record current sensor's i2c write id */
};

(E)Sensor output window information

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.c

static struct SENSOR_WINSIZE_INFO_STRUCT imgsensor_winsize_info[5] = {
	{ 3264, 2448,   0,   0, 3264, 2448, 3264, 2448, 0, 0, 3264, 2448, 0, 0, 3264, 2448}, /* Preview */
	{ 3264, 2448,   0,   0, 3264, 2448, 3264, 2448, 0, 0, 3264, 2448, 0, 0, 3264, 2448}, /* capture */
	{ 3264, 2448,   0,   0, 3264, 2448, 3264, 2448, 0, 0, 3264, 2448, 0, 0, 3264, 2448}, /* video */
	{ 3264, 2448,   0,   0, 3264, 2448, 3264, 2448, 0, 0, 1632, 1224, 0, 0, 1632, 1224}, /* hight speed video */
	{ 3264, 2448, 252, 504, 2560, 1440, 1280,  720, 0, 0, 1280,  720, 0, 0, 1280,  720}  /* slim video */
};

(3) Drive entry function xxxx_MIPI_RAW_SensorInit

(A) Drive entry function GC8034_MIPI_RAW_SensorInit

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/common/v1/imgsensor_sensor_list.c

struct IMGSENSOR_INIT_FUNC_LIST kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR] = {

	#if defined(GC8034_MIPI_RAW)
	{GC8034_SENSOR_ID,
	SENSOR_DRVNAME_GC8034_MIPI_RAW,
	GC8034_MIPI_RAW_SensorInit},
#endif

//...
{0, {0}, NULL}
};

//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.c

UINT32 GC8034_MIPI_RAW_SensorInit(struct SENSOR_FUNCTION_STRUCT **pfFunc)
{
	/* Check Sensor status here */
	if (pfFunc != NULL)
		*pfFunc = &sensor_func;
	return ERROR_NONE;
}

(B)SENSOR_ FUNCTION_ The struct structure contains the operation interfaces of all sensor driver s

//kernel-4.19/drivers/misc/mediatek/imgsensor/inc/kd_imgsensor_define.h

struct SENSOR_FUNCTION_STRUCT {
   	MUINT32 (*SensorOpen)(void);
   	MUINT32 (*SensorGetInfo)(enum MSDK_SCENARIO_ID_ENUM ScenarioId,
   	    MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
   	    MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
     
   	MUINT32 (*SensorGetResolution)(
   	    MSDK_SENSOR_RESOLUTION_INFO_STRUCT * pSensorResolution);
    
   	MUINT32 (*SensorFeatureControl)(MSDK_SENSOR_FEATURE_ENUM FeatureId,
   	    MUINT8 *pFeaturePara,
   	    MUINT32 *pFeatureParaLen);
    
   	MUINT32 (*SensorControl)(enum MSDK_SCENARIO_ID_ENUM ScenarioId,
   	    MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
   	    MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
     
   	MUINT32 (*SensorClose)(void);
    
   	MUINT8  arch;
   	void   *psensor_inst; /* IMGSENSOR_SENSOR_INST */
};

The information filled in the corresponding drive is as follows:

static struct SENSOR_FUNCTION_STRUCT sensor_func = {
   	open,//Called when camera is opened
   	get_info,// Get the dynamic information of sensor
   	get_resolution,//Gets the size of the sensor in a specific mode
   	feature_control,
   	control,
   	close
};

(C) open function

//gc8034mipi_Sensor.c

//This function is called every time you open camera
static kal_uint32 open(void)
{
	  //sensor initialization parameter settings
	sensor_init();

	gc8034_gcore_identify_otp();
	spin_lock(&imgsensor_drv_lock);
	
	  //Initialize imgsensor structure
	imgsensor.autoflicker_en = KAL_FALSE;
	imgsensor.sensor_mode = IMGSENSOR_MODE_INIT;
	imgsensor.pclk = imgsensor_info.pre.pclk;
	imgsensor.frame_length = imgsensor_info.pre.framelength;
	imgsensor.line_length = imgsensor_info.pre.linelength;
	imgsensor.min_frame_length = imgsensor_info.pre.framelength;
	imgsensor.dummy_pixel = 0;
	imgsensor.dummy_line = 0;
	imgsensor.ihdr_en = 0;
	imgsensor.test_pattern = KAL_FALSE;
	imgsensor.current_fps = imgsensor_info.pre.max_framerate;
	spin_unlock(&imgsensor_drv_lock);
}

(D)feature_control function

//Get linelength and pclk
   	case SENSOR_FEATURE_GET_PERIOD:
   		*feature_return_para_16++ = imgsensor.line_length;
   		*feature_return_para_16 = imgsensor.frame_length;
   		*feature_para_len = 4;
   		break;
   	case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
   		*feature_return_para_32 = imgsensor.pclk;
   		*feature_para_len = 4;
   		break;

//set_shutter set exposure line
    case SENSOR_FEATURE_SET_ESHUTTER:
    	set_shutter(*feature_data);
    	break;

//streaming_control sensor output data
   case SENSOR_FEATURE_SET_STREAMING_SUSPEND:
    	pr_info("SENSOR_FEATURE_SET_STREAMING_SUSPEND\n");
    	streaming_control(KAL_FALSE);
    	break;

Set the exposure line, which is physically smaller than the frame_length, so the exposure line is larger than the current frame_ When length, frame_length will be extended automatically,
The frame rate decreases, so when the brightness is low, the frame rate will decrease because the shutter is large.

(E) control mode switching function

static kal_uint32 control(enum MSDK_SCENARIO_ID_ENUM scenario_id, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
	MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
{
	LOG_INF("Enter control!\n");
	LOG_INF("scenario_id = %d\n", scenario_id);
	spin_lock(&imgsensor_drv_lock);
	imgsensor.current_scenario_id = scenario_id;
	spin_unlock(&imgsensor_drv_lock);
	switch (scenario_id) {
	case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
		preview(image_window, sensor_config_data);
		break;
	case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
		capture(image_window, sensor_config_data);
		break;
	case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
		normal_video(image_window, sensor_config_data);
		break;
	case MSDK_SCENARIO_ID_HIGH_SPEED_VIDEO:
		hs_video(image_window, sensor_config_data);
		break;
	case MSDK_SCENARIO_ID_SLIM_VIDEO:
		slim_video(image_window, sensor_config_data);
		break;
	default:
		LOG_INF("Error ScenarioId setting");
		preview(image_window, sensor_config_data);
		return ERROR_INVALID_SCENARIO_ID;
	}
	return ERROR_NONE;
}

Here, take preview as an example to illustrate the process:

static kal_uint32 preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
	MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
{
	//Update imgsensor structure information
	spin_lock(&imgsensor_drv_lock);
	imgsensor.sensor_mode = IMGSENSOR_MODE_PREVIEW;
	imgsensor.pclk = imgsensor_info.pre.pclk;
	/* imgsensor.video_mode = KAL_FALSE; */
	imgsensor.line_length = imgsensor_info.pre.linelength;
	imgsensor.frame_length = imgsensor_info.pre.framelength;
	imgsensor.min_frame_length = imgsensor_info.pre.framelength;
	imgsensor.autoflicker_en = KAL_TRUE;
	spin_unlock(&imgsensor_drv_lock);
	 //Update register
	preview_setting();
	return ERROR_NONE;
}

Posted by savingc on Tue, 23 Nov 2021 02:11:22 -0800