⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isp_if.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
#include "isp_flashlight.h"
#endif
#if (!defined(__MTK_TARGET__))
kal_uint8 current_lcd_rotate_value;
#endif

kal_bool ae_counting_flag=KAL_TRUE;

#if (defined(WEBCAM_SUPPORT))
#include "usbvideo_cam_if.h"
#endif  // END_OF_WEBCAM_SUPPORT
extern kal_uint32 SaveAndSetIRQMask(void);
extern void RestoreIRQMask(kal_uint32);
extern kal_eventgrpid lcd_event_id;
extern kal_uint8 L1SM_GetHandle(void);
extern void L1SM_SleepEnable(kal_uint8 handle);
extern void L1SM_SleepDisable(kal_uint8 handle);
extern void video_enc_reset_buffer_counter(void);
extern void isp_ibw2_cb(void);
kal_uint8	isp_sleep_mode_handler=0xFF;
#if ((!defined(MT6219))&&defined(ISP_SUPPORT))
extern ae_lut_info_struct lut_info;
#endif

kal_uint8 ae_count=0;
kal_uint8 hist_idx=0;
kal_uint8	camera_system_operation_mode=CAMERA_SYSTEM_NORMAL_MODE;

camera_preview_process_struct isp_preview_config_data;
camera_capture_jpeg_struct isp_capture_jpeg_data;
camera_capture_barcode_struct isp_capture_barcode_data;
camera_capture_mem_struct isp_capture_mem_data;
mpeg4_encode_process_struct mpeg4_encode_data;
MP4ENC_SETUP_STRUCT mpeg4_encode_config_data;
kal_bool MPEG4_RECODE_START=KAL_FALSE;

#if (defined(MT6228)||defined(MT6229)||defined(MT6230))
camera_preview_data_path_struct			ipp_preview_data;
camera_capture_jpeg_data_path_struct 	ipp_capture_jpeg_data;
camera_capture_barcode_data_path_struct ipp_capture_barcode_data;
camera_capture_mem_data_path_struct    ipp_capture_mem_data;
video_encode_data_path_struct				ipp_video_encode_data;
volatile kal_bool wait_last_capture_frame=KAL_FALSE;
volatile kal_bool sensor_vd_done=KAL_FALSE;
#endif
#if (!defined(MT6219))
void (*cam_preview_cb) (kal_uint8 return_code);
void (*cam_focus_cb) (kal_uint8 return_code);
#endif

kal_bool isp_digital_zoom_flag=KAL_FALSE;
volatile kal_uint8 isp_digital_zoom_factor=10;
kal_uint8 preview_hue_level,preview_saturation_level;
ISP_OPERATION_STATE_ENUM isp_operation_state=ISP_IDLE_STATE;
kal_uint16 isp_grab_width,isp_grab_height,isp_grab_start_x,isp_grab_start_y;
kal_uint8 isp_sub_sample_mode;
kal_bool isp_enter_exit_process_flag=KAL_FALSE;
volatile kal_bool isp_idle_done_flag=KAL_FALSE;
kal_uint16 exif_isp_target_width=0, exif_isp_target_height=0;

kal_eventgrpid camera_isp_event_id=NULL;
volatile kal_uint32 isp_int_status;
kal_uint16 isp_tg_delay_lines=0;
kal_bool tg_interrupt_flag=KAL_FALSE;

kal_bool wait_first_frame_flag=KAL_TRUE;
kal_bool isp_first_preview_frame=KAL_TRUE;
volatile kal_uint8 isp_preview_2a_enable=0;
kal_uint8 isp_preview_frame=0;
kal_uint16 isp_frame_period;
kal_uint16 image_setting_index=0;
kal_bool awb_enable_flag_backup=KAL_TRUE;
kal_bool ae_enable_flag_backup=KAL_TRUE;
kal_uint8 ae_hw_frame_count_backup[2]={1,1};
image_sensor_func_struct *image_sensor_func;
kal_uint16 image_sensor_width,image_sensor_height;
image_sensor_exposure_window_struct exposure_window;
image_sensor_config_struct sensor_config_data;
kal_int8 sensor_err_check=1;
isp_fast_zoom_struct isp_fast_zoom_data={KAL_FALSE,KAL_TRUE,40,2,3};
kal_uint8 fast_zoom_count=0;
#if (defined(AF_SUPPORT))
#if (defined(YUV_SENSOR_SUPPORT))
kal_uint8 yuv_af_status;
kal_uint8 yuv_af_check_count=0;
#else
lens_func_struct *lens_func;
kal_int8 lens_err_check=1;
kal_uint8 af_next_step_idx=0;
kal_uint8 af_count=0;
kal_uint16 af_next_detail_pos;
#endif
#endif
kal_uint32	vd_blanking_lines = 0;

const kal_uint8 sine_lut[91]={	 0, 1, 2, 3, 4, 6, 7, 8, 9,10,
											11,12,13,14,15,17,18,19,20,21,
											22,23,24,25,26,27,28,29,30,31,
											32,33,34,35,36,37,38,39,39,40,
											41,42,43,44,44,45,46,47,48,48,
											49,50,50,51,52,52,53,54,54,55,
											55,56,57,57,58,58,58,59,59,60,
											60,61,61,61,62,62,62,62,63,63,
											63,63,63,64,64,64,64,64,64,64,
											64};

/*************************************************************************
* FUNCTION
*	camera_isp_LISR
*
* DESCRIPTION
*	Entry function of ISP LISR
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void camera_isp_LISR(void)
{
#if (defined(ISP_SUPPORT))
	kal_uint32 int_status;
	kal_uint32 save_irq_mask;

	save_irq_mask=SaveAndSetIRQMask();
	IRQMask(IRQ_CAMERA_CODE);
	int_status=DRV_Reg32(ISP_INT_STATUS_REG);
	isp_int_status=0;
	if (int_status & REG_CAMERA_INT_FRAME_READY_ENABLE_BIT)
	{
#if (defined(MT6228))
		if(tg_interrupt_flag==KAL_TRUE)
			ENABLE_CAMERA_TG_DONE_INT;	
#endif		
		/* Accumulation for AWB */
		Acc_R=REG_ISP_OPD_Y_RESULT;
		Acc_G=REG_ISP_OPD_MG_RESULT;
		Acc_B=REG_ISP_OPD_RB_RESULT;
		Acc_Cnt=REG_ISP_OPD_PIXEL_COUNT;
		
#if (defined(AF_SUPPORT)&&(!defined(YUV_SENSOR_SUPPORT)))		
		/* Focus Value for AF */
#if (defined(MT6226)||defined(MT6226M)||defined(MT6227)||defined(MT6229)||defined(MT6230))		
		AF_Result0=REG_ISP_ATF_RESULT1;
		AF_Result1=REG_ISP_ATF_RESULT2;
		AF_Result2=REG_ISP_ATF_RESULT3;
		AF_Result3=REG_ISP_ATF_RESULT4;
		AF_Result4=REG_ISP_ATF_RESULT5;
#elif (defined(MT6228))
		AF_Result0=REG_ISP_AF_RESULT1;
		AF_Result1=REG_ISP_AF_RESULT2;
		AF_Result2=REG_ISP_AF_RESULT3;
		AF_Result3=REG_ISP_AF_RESULT4;
		AF_Result4=REG_ISP_AF_RESULT5;
#endif	
		AF_frame_VD_log();		
#endif
		
#if (defined(MT6219))
		/* Luminance for AE */
		lum[0]=REG_ISP_AE_WINDOW1_RESULT;
		lum[1]=REG_ISP_AE_WINDOW2_RESULT;
		lum[2]=REG_ISP_AE_WINDOW3_RESULT;
		lum[3]=REG_ISP_AE_WINDOW4_RESULT;
		lum[4]=REG_ISP_AE_WINDOW5_RESULT;
		lum[5]=REG_ISP_AE_WINDOW6_RESULT;
		lum[6]=REG_ISP_AE_WINDOW7_RESULT;
		lum[7]=REG_ISP_AE_WINDOW8_RESULT;
		lum[8]=REG_ISP_AE_WINDOW9_RESULT;
	
		/* Histogram for Flare */
		histogram[0]=REG_ISP_AE_A_NUMBER_RESULT;
		histogram[1]=REG_ISP_AE_B_NUMBER_RESULT;
		histogram[2]=REG_ISP_AE_C_NUMBER_RESULT;
		histogram[3]=REG_ISP_AE_D_NUMBER_RESULT;
		histogram[4]=REG_ISP_AE_E_NUMBER_RESULT;
#endif		
		if (isp_digital_zoom_flag==KAL_TRUE)
		{
			ENABLE_CAMERA_IDLE_INT;
#if (defined(MT6219))
			if (isp_operation_state==ISP_MPEG4_ENCODE_STATE)
				ENABLE_IBW2_INT;
#endif
			DISABLE_VIEW_FINDER_MODE;
#if (defined(MT6219))
			if(ae_count==camera_oper_data.ae_setting_cal_delay_frame)
			{
				ae_count++;
				ae_count%=camera_oper_data.ae_awb_cal_period;
			}
#endif
		}
		isp_int_status |= ISP_INT_FRAME_READY;
	}

	if (int_status & REG_CAMERA_INT_IDLE_ENABLE_BIT)
	{
		isp_idle_done_flag=KAL_TRUE;
		isp_int_status |= ISP_INT_IDLE;
		if (isp_digital_zoom_flag==KAL_TRUE)
		{
			DISABLE_CMOS_SESNOR;
#if (!defined(MT6219))
			if (isp_operation_state==ISP_MPEG4_ENCODE_STATE)
			{
#if (defined(MT6226)||defined(MT6226M)||defined(MT6227))
        	    kal_uint16 pixel_count,line_count;	    
        		pixel_count=*(volatile unsigned int *) 0x80690428;
        		line_count=*(volatile unsigned int *) 0x8069042C;			    
				ENABLE_IBW2_INT;				
				if((!IMGDMA_IBW2_IS_BUSY)||((pixel_count==0)&&(line_count==0)))
#elif (defined(MT6228)||defined(MT6229)||defined(MT6230))
				ENABLE_IBW2_INT;
				if(!IMGDMA_IBW2_IS_BUSY)
#endif				
				{
					isp_ibw2_cb();		/* for zoom setting */		
				}
			}
#endif				
		}
	}
#if (defined(MT6226)||defined(MT6226M)||defined(MT6227)||defined(MT6229)||defined(MT6230))
	if (int_status & REG_CAMERA_INT_ISP_DONE_ENABLE_BIT)
	{
		isp_int_status |= ISP_INT_ISP_DONE;
	}

	if (int_status & REG_CAMERA_INT_AE_DONE_ENABLE_BIT)
	{
		isp_int_status |= ISP_INT_AE_DONE;
	}

	if (int_status & REG_CAMERA_INT_ATF_DONE_ENABLE_BIT)
	{
		isp_int_status |= ISP_INT_ATF_DONE;
	}

	if (((int_status & REG_CAMERA_INT_FLASH_DONE_ENABLE_BIT)!= 0)
		&&((REG_ISP_INT_ENABLE & REG_CAMERA_INT_FLASH_SEL_ENABLE_BIT)== 0))
	{
#if (defined(MT6226)||defined(MT6226M)||defined(MT6227))
		//Avoid ae get accumulation frame
		if(AE_FRAME_COUNT==1)
		{						
		/* Luminance for AE */
		lum[0]=REG_ISP_AE_WINDOW1_RESULT;
		lum[1]=REG_ISP_AE_WINDOW2_RESULT;
		lum[2]=REG_ISP_AE_WINDOW3_RESULT;
		lum[3]=REG_ISP_AE_WINDOW4_RESULT;
		lum[4]=REG_ISP_AE_WINDOW5_RESULT;
		lum[5]=REG_ISP_AE_WINDOW6_RESULT;
		lum[6]=REG_ISP_AE_WINDOW7_RESULT;
		lum[7]=REG_ISP_AE_WINDOW8_RESULT;
		lum[8]=REG_ISP_AE_WINDOW9_RESULT;
	
		/* Histogram for Flare */
		histogram[0]=REG_ISP_AE_A_NUMBER_RESULT;
		histogram[1]=REG_ISP_AE_B_NUMBER_RESULT;
		histogram[2]=REG_ISP_AE_C_NUMBER_RESULT;
		histogram[3]=REG_ISP_AE_D_NUMBER_RESULT;
		histogram[4]=REG_ISP_AE_E_NUMBER_RESULT;
			ae_counting_flag=KAL_TRUE;
		}
		else
			ae_counting_flag=KAL_FALSE;
#endif			
		ae_hw_frame_count_backup[1]=ae_hw_frame_count_backup[0];
		ae_hw_frame_count_backup[0]=AE_FRAME_COUNT;
		isp_int_status |= ISP_INT_TG_DONE;
	}

	if (((int_status & REG_CAMERA_INT_FLASH_DONE_ENABLE_BIT)!= 0)
		&&((REG_ISP_INT_ENABLE & REG_CAMERA_INT_FLASH_SEL_ENABLE_BIT)!= 0))
	{
#if (defined(MT6226)||defined(MT6226M)||defined(MT6227))
		//Avoid ae get accumulation frame
		if(AE_FRAME_COUNT==1)
		{						
		/* Luminance for AE */
		lum[0]=REG_ISP_AE_WINDOW1_RESULT;
		lum[1]=REG_ISP_AE_WINDOW2_RESULT;
		lum[2]=REG_ISP_AE_WINDOW3_RESULT;
		lum[3]=REG_ISP_AE_WINDOW4_RESULT;
		lum[4]=REG_ISP_AE_WINDOW5_RESULT;
		lum[5]=REG_ISP_AE_WINDOW6_RESULT;
		lum[6]=REG_ISP_AE_WINDOW7_RESULT;
		lum[7]=REG_ISP_AE_WINDOW8_RESULT;
		lum[8]=REG_ISP_AE_WINDOW9_RESULT;
	
		/* Histogram for Flare */
		histogram[0]=REG_ISP_AE_A_NUMBER_RESULT;
		histogram[1]=REG_ISP_AE_B_NUMBER_RESULT;
		histogram[2]=REG_ISP_AE_C_NUMBER_RESULT;
		histogram[3]=REG_ISP_AE_D_NUMBER_RESULT;
		histogram[4]=REG_ISP_AE_E_NUMBER_RESULT;
			ae_counting_flag=KAL_TRUE;
		}
		else
			ae_counting_flag=KAL_FALSE;
#endif
		ae_hw_frame_count_backup[1]=ae_hw_frame_count_backup[0];
		ae_hw_frame_count_backup[0]=AE_FRAME_COUNT;
		isp_int_status |= ISP_INT_VD_DONE;
	}
#elif (defined(MT6228))
	if (int_status & REG_CAMERA_INT_ISP_DONE_ENABLE_BIT)
	{
		isp_int_status |= ISP_INT_ISP_DONE;
	}

	if (int_status & REG_CAMERA_INT_AE_DONE_ENABLE_BIT)
	{
		isp_int_status |= ISP_INT_AE_DONE;
	}

	if (int_status & REG_CAMERA_INT_ATF_DONE_ENABLE_BIT)
	{
		isp_int_status |= ISP_INT_ATF_DONE;
	}

	if (((int_status & REG_CAMERA_INT_TG_DONE_ENABLE_BIT)!= 0)
		&&((REG_ISP_INT_ENABLE & REG_CAMERA_INT_VSYNC_ENABLE_BIT)== 0))
	{
		DISABLE_CAMERA_TG_DONE_INT;  // Turn off TG interrupt to prevent continous trigger in specific line period
		
		ae_hw_frame_count_backup[1]=ae_hw_frame_count_backup[0];
		ae_hw_frame_count_backup[0]=AE_FRAME_COUNT;
		isp_int_status |= ISP_INT_TG_DONE;
	}

	if (((int_status & REG_CAMERA_INT_TG_DONE_ENABLE_BIT)!= 0)
		&&((REG_ISP_INT_ENABLE & REG_CAMERA_INT_VSYNC_ENABLE_BIT)!= 0))
	{
		ae_hw_frame_count_backup[1]=ae_hw_frame_count_backup[0];
		ae_hw_frame_count_backup[0]=AE_FRAME_COUNT;
		isp_int_status |= ISP_INT_VD_DONE;
	}
#endif
	if (isp_int_status!=0)
	{
		visual_active_hisr(VISUAL_CAMERA_HISR_ID);
	}
	else
	{
		IRQUnmask(IRQ_CAMERA_CODE);
	}
	RestoreIRQMask(save_irq_mask);
#endif
}	/* isp_LISR() */

/*************************************************************************
* FUNCTION
*	camera_isp_HISR
*
* DESCRIPTION
*	Entry function of ISP HISR
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void camera_isp_HISR(void)
{
#if (defined(ISP_SUPPORT))
	if (isp_int_status & ISP_INT_IDLE)
	{
		if (isp_digital_zoom_flag==KAL_TRUE)
		{
	   	if (isp_operation_state==ISP_PREVIEW_STATE)
			{
#if (defined(YUV_SENSOR_SUPPORT))
				SET_YUV_TG_GRAB_PIXEL(isp_grab_start_x,isp_grab_width);
				SET_YUV_TG_GRAB_LINE(isp_grab_start_y,isp_grab_height);
#else
				SET_TG_GRAB_PIXEL(isp_grab_start_x,isp_grab_width);
				SET_TG_GRAB_LINE(isp_grab_start_y,isp_grab_height);
#endif /* YUV_SENSOR_SUPPORT */

				ae_config(isp_grab_width,isp_grab_height);
#if (defined(MT6219))
				SET_SUB_SAMPLE_MODE(isp_sub_sample_mode);
				RESZ_Stop(SCENARIO_CAMERA_PREVIEW_ID);
				stop_image_dma(SCENARIO_CAMERA_PREVIEW_ID);
				IMGDMA_Close(SCENARIO_CAMERA_PREVIEW_ID);
   			STOP_LCD_TRANSFER;
   			START_LCD_TRANSFER;
				config_image_dma(SCENARIO_CAMERA_PREVIEW_ID,isp_preview_config_data.target_width,
									  isp_preview_config_data.target_height);
				RESZ_SetSize(isp_preview_config_data.source_width,isp_preview_config_data.source_height,
								 isp_preview_config_data.target_width,isp_preview_config_data.target_height,
								 SCENARIO_CAMERA_PREVIEW_ID);
				RESZ_Start(SCENARIO_CAMERA_PREVIEW_ID);
#elif (defined(MT6226)||defined(MT6226M)||defined(MT6227))
				ENABLE_VERTICAL_SUB_SAMPLE;
				ENABLE_HORIZONTAL_SUB_SAMPLE;
				SET_HSUB_SRC_SIZE(isp_grab_width);
				SET_VSUB_SRC_SIZE(isp_grab_height);
				SET_HSUB_DST_SIZE(isp_preview_config_data.source_width);
				SET_VSUB_DST_SIZE(isp_preview_config_data.source_height);
#if (defined(AF_SUPPORT)&&(!defined(YUV_SENSOR_SUPPORT)))	
				af_zone_setting(dsc_status.af.metering);
#endif
				RESZ_Stop(SCENARIO_CAMERA_PREVIEW_ID);
				stop_image_dma(SCENARIO_CAMERA_PREVIEW_ID);
				IMGDMA_Close(SCENARIO_CAMERA_PREVIEW_ID);
   			STOP_LCD_TRANSFER;
   			START_LCD_TRANSFER;
				config_image_dma(SCENARIO_CAMERA_PREVIEW_ID,isp_preview_config_data.target_width,
									  isp_preview_config_data.target_height);
				RESZ_SetSize(isp_preview_config_data.source_width,isp_preview_config_data.source_height,
								 isp_preview_config_data.target_width,isp_preview_config_data.target_height,
								 SCENARIO_CAMERA_PREVIEW_ID);
				RESZ_Start(SCENARIO_CAMERA_PREVIEW_ID);
#elif (defined(MT6228)||defined(MT6229)||defined(MT6230))
				ENABLE_VERTICAL_SUB_SAMPLE;
				ENABLE_HORIZONTAL_SUB_SAMPLE;
				SET_HSUB_SRC_SIZE(isp_grab_width);
				SET_VSUB_SRC_SIZE(isp_grab_height);
				SET_HSUB_DST_SIZE(isp_preview_config_data.source_width);
				SET_VSUB_DST_SIZE(isp_preview_config_data.source_height);
				reconfig_camera_preview_data_path(SCENARIO_CAMERA_PREVIEW_ID,&ipp_preview_data);
#if (defined(AF_SUPPORT)&&(!defined(YUV_SENSOR_SUPPORT)))	
				af_zone_setting(dsc_status.af.metering);
#endif
#endif	
				if(isp_fast_zoom_data.start==KAL_FALSE)
				{
					isp_digital_zoom_flag=KAL_FALSE;
#if (!defined(MT6219))
//					DISABLE_CAMERA_FRAME_READY_INT;
#endif
				}
				ENABLE_CMOS_SESNOR;
				DISABLE_CAMERA_IDLE_INT;
				ENABLE_VIEW_FINDER_MODE;
			}
		}
#if (!defined(MT6219))		
      else if(flashlight_operation_state == FLASHLIGHT_TRIGGER_STATE)
      {   // Flash Light Control        
         flashlight_hisr();
      }    					
#endif      	
	   kal_set_eg_events(camera_isp_event_id,CAMERA_ISP_IDLE_EVENT,KAL_OR);
		IRQUnmask(IRQ_CAMERA_CODE);
	
		/* Fast Zoom In Config */
		if(isp_fast_zoom_data.start==KAL_TRUE)
		{
			if(fast_zoom_count==isp_fast_zoom_data.zoom_speed+1)
			{
				if(isp_fast_zoom_data.zoom_in==KAL_TRUE)
				{
					if((isp_digital_zoom_factor+isp_fast_zoom_data.zoom_step)<=isp_fast_zoom_data.zoom_limit)
					{
						isp_digital_zoom((kal_uint8)(isp_digital_zoom_factor+isp_fast_zoom_data.zoom_step));
						fast_zoom_count=0;
					}
				}
				else
				{
					if((isp_digital_zoom_factor-isp_fast_zoom_data.zoom_step)>=10)
					{
						isp_digital_zoom((kal_uint8)(isp_digital_zoom_factor-isp_fast_zoom_data.zoom_step));
						fast_zoom_count=0;
					}
					else
					{
						isp_fast_zoom_data.start=KAL_FALSE;
						isp_fast_zoom_setting(isp_fast_zoom_data);
					}
				}
			}		
			fast_zoom_count++;
		}
	}

#if (defined(YUV_SENSOR_SUPPORT))
	if ((isp_int_status & ISP_INT_VD_DONE)||(isp_int_status & ISP_INT_TG_DONE))
	{
#if (defined(WEBCAM_SUPPORT))
        if(usbvideo_cam_operation_state==USBVIDEO_CAM_PREVIEW_CHECK_STATE)
        {
            if(usbvideo_attr_setting_PU_index!=0)
                usbvideo_camera_effect_background_setting_attr();		
        }
#endif
#if (defined(AF_SUPPORT))
		if(isp_operation_state==ISP_PREVIEW_STATE)
		{
			if(af_operation_state==AF_SEARCH_STATE)
			{
				yuv_af_status=image_sensor_func->yuv_sensor_setting(CAM_PARAM_YUV_AF_STATUS,0);
				if(yuv_af_status==AF_BUSY)
					yuv_af_check_count++;
				else
				{
					if(yuv_af_status==AF_SEARCH_SUCCESS)
						isp_preview_config_data.cam_focus_cb(1);	/* Inform MMI AF Success Zone */
					else
						isp_preview_config_data.cam_focus_cb(0xFF);	/* Inform MMI AF Fail */
					af_operation_state=AF_FREEZE_STATE;
				}
				if(yuv_af_check_count>camera_oper_data.yuv_af_timeout_frame)
				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -