tv_out.c

来自「最新MTK手机软件源码」· C语言 代码 · 共 1,369 行 · 第 1/5 页

C
1,369
字号
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}};

 /* for engineering mode */

extern MMDI_SCENERIO_ID current_image_data_path_owner;
tv_output_para_struct tv_output_config_data;
kal_uint8 tv_operation_state=TV_IDLE_STATE;

kal_uint8 tv_out_current_fb=0;
kal_uint8 tv_output_owner=TV_OUT_OWNER_NONE;

extern kal_uint8 L1SM_GetHandle(void);
extern void L1SM_SleepEnable(kal_uint8 handle);
extern void L1SM_SleepDisable(kal_uint8 handle);
kal_uint8 tv_sleep_mode_handler=0xFF;

void tv_power_on(void)
{
	kal_uint32 save_irq_mask;

	save_irq_mask=SaveAndSetIRQMask();
	DRV_Reg(DRVPDN_CON0) &= (~DRVPDN_CON0_TPLL);	/* Turn off TV PLL clock */
	DRV_Reg(DRVPDN_CON3) &= (~DRVPDN_CON3_TV);	/* Power on TV module */
	UPLL_Enable(UPLL_OWNER_TV);
	RestoreIRQMask(save_irq_mask);
	tv_operation_state=TV_DETECTION_STATE;

	/* turn on TV DAC */
	ENABLE_TV_HALF_BIAS_POWER;
	ENABLE_TV_DAC2_POWER;
	ENABLE_TV_DAC1_POWER;
	ENABLE_TV_DAC0_POWER;
	ENABLE_TV_BGVREF_POWER;
	ENABLE_TV_DAC_POWER;
	ENABLE_TV_ENCODER;
}	/* tv_power_on() */

void tv_power_off(void)
{
	kal_uint32 save_irq_mask;

	/* turn off TV DAC */
	DISABLE_TV_HALF_BIAS_POWER;
	DISABLE_TV_DAC2_POWER;
	DISABLE_TV_DAC1_POWER;
	DISABLE_TV_DAC0_POWER;
	DISABLE_TV_BGVREF_POWER;
	DISABLE_TV_DAC_POWER;

	DISABLE_TV_ENCODER;
	DISABLE_TV_CONTROLLER;
	RESET_TV_CONTROLLER;
	tv_src_width=0;
	tv_src_height=0;
	save_irq_mask=SaveAndSetIRQMask();
	DRV_Reg(DRVPDN_CON0) |= (DRVPDN_CON0_TPLL);	/* Turn off TV PLL clock */
	DRV_Reg(DRVPDN_CON3) |= (DRVPDN_CON3_TV);	/* Power off TV module */
	UPLL_Disable(UPLL_OWNER_TV);
	RestoreIRQMask(save_irq_mask);
	tv_operation_state=TV_IDLE_STATE;
}	/* tv_power_off() */

kal_bool init_tv(void)
{
	tv_power_on();
	tv_output_owner=TV_OUT_OWNER_MMI;
	tv_output_config_data.tv_output_mode=0;
	tv_output_config_data.tv_output_format=0;
	tv_output_config_data.tv_output_offset_x=0;
	tv_output_config_data.tv_output_offset_y=0;

	/* configure TV encoder mode */
	DISABLE_TV_UV_SWAP;
	DISABLE_TV_BLACKER_MODE;
	DISABLE_TV_HORIZONTAL_SLEW;
	SET_TV_SYDELAY_BIT;
	SET_TV_Y_DELAY(2);
	DISABLE_TV_CHROMA_UP_SAMPLE;
	DISABLE_TV_LUMA_LPF;
	ENABLE_TV_CHROMA_LPF;
	SET_TV_CHROMA_LPF0;

	SET_TV_ENC_SCALE_BLANK(4);

	/* configure TV controller contorl register */
	SET_TV_CON_WRITE_SINGLE_BUFFER;
	DISABLE_TV_CON_BURST_MODE;
	ENABLE_TV_CON_DEEPER_BUFFER;
	ENABLE_TV_CON_FILL_BLACK_PIXEL;
	ENABLE_TV_CON_VERTICAL_INTERPOLATION;
	SET_TV_CON_READ_WRITE_BUFFER;
	*((volatile unsigned int *) 0x806D0050) = 1;

	*((volatile unsigned int *) TV_CON_CTRL_REG) |= 0x40;
	*((volatile unsigned int *) 0x806C0034) = 0x180D0000;

   if (tv_sleep_mode_handler==0xFF)
   	tv_sleep_mode_handler=L1SM_GetHandle();
   L1SM_SleepDisable(tv_sleep_mode_handler);

   return KAL_TRUE;
}	/* init_tv() */

void deinit_tv(void)
{
	tv_power_off();
   L1SM_SleepEnable(tv_sleep_mode_handler);
}	/* deinit_tv() */

kal_bool tv_set_detection(void)
{
	tv_operation_state=TV_STANDBY_STATE;
	return KAL_TRUE;
#if 0	
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif	
}	/* tv_set_detection() */

void set_tv_output_data_format(kal_uint8 data_format)
{
	if (data_format==TV_DATA_YUV420)
	{
		SET_TV_CON_SRC_YUV420;
		tv_output_config_data.tv_output_data_format=TV_DATA_YUV420;
	}
	else if (data_format==TV_DATA_RGB565)
	{
		SET_TV_CON_SRC_RGB565;
		tv_output_config_data.tv_output_data_format=TV_DATA_RGB565;
	}
}	/* set_tv_output_data_format() */

void set_tv_output_mode(tv_output_para_struct *tv_para)
{
	volatile kal_uint32 i;
   kal_uint16 target_width,target_height,offset_x,offset_y;

	if (tv_output_config_data.tv_output_format==tv_para->tv_output_format)
		tv_out_format_change_flag=KAL_FALSE;
	else
		tv_out_format_change_flag=KAL_TRUE;
	tv_output_config_data.tv_output_mode=tv_para->tv_output_mode;
	tv_output_config_data.tv_output_format=tv_para->tv_output_format;
	tv_output_config_data.tv_output_offset_x=tv_para->tv_output_offset_x;
	tv_output_config_data.tv_output_offset_y=tv_para->tv_output_offset_y;

	SET_TV_TYPE(tv_output_config_data.tv_output_format);

	/* configure TV encoder gamma table */
	SET_TV_ENC_GAMMA0_COEFF(tv_gamma_table[tv_gamma_table_sel][0]);
	SET_TV_ENC_GAMMA1_COEFF(tv_gamma_table[tv_gamma_table_sel][1]);
	SET_TV_ENC_GAMMA2_COEFF(tv_gamma_table[tv_gamma_table_sel][2]);
	SET_TV_ENC_GAMMA3_COEFF(tv_gamma_table[tv_gamma_table_sel][3]);
	SET_TV_ENC_GAMMA4_COEFF(tv_gamma_table[tv_gamma_table_sel][4]);
	SET_TV_ENC_GAMMA5_COEFF(tv_gamma_table[tv_gamma_table_sel][5]);
	SET_TV_ENC_GAMMA6_COEFF(tv_gamma_table[tv_gamma_table_sel][6]);
	SET_TV_ENC_GAMMA7_COEFF(tv_gamma_table[tv_gamma_table_sel][7]);
	SET_TV_ENC_GAMMA8_COEFF(tv_gamma_table[tv_gamma_table_sel][8]);

	if (tv_output_config_data.tv_output_format==TV_FORMAT_NTSC)
	{
		DISABLE_TV_7_5_IRE_SETUP;
		target_width=TV_OUTPUT_NTSC_WIDTH;
		target_height=TV_OUTPUT_NTSC_HEIGHT;
		offset_x=TV_OUTPUT_NTSC_OFFSET_X;
		offset_y=TV_OUTPUT_NTSC_OFFSET_Y;
		DRV_WriteReg32(TV_ENC_COLOR_FREQ_CTRL_REG,((3535<<16)|271));
		if (tv_eng_mode==KAL_FALSE)
		{
			SET_TV_ENC_V_SCALE(tv_v_scale_ntsc);
			SET_TV_ENC_U_SCALE(tv_u_scale_ntsc);
		}
		else
		{
			SET_TV_ENC_V_SCALE(tv_engmode_v_scale);
			SET_TV_ENC_U_SCALE(tv_engmode_u_scale);
		}
		REG_TV_ENC_BURST_LEVEL_CTRL=0x3d;
	}
	else
	{
		DISABLE_TV_7_5_IRE_SETUP;
		target_width=TV_OUTPUT_PAL_WIDTH;
		target_height=TV_OUTPUT_PAL_HEIGHT;
		offset_x=TV_OUTPUT_PAL_OFFSET_X;
		offset_y=TV_OUTPUT_PAL_OFFSET_Y;
		DRV_WriteReg32(TV_ENC_COLOR_FREQ_CTRL_REG,((2061<<16)|336));
		if (tv_eng_mode==KAL_FALSE)
		{
			SET_TV_ENC_V_SCALE(tv_v_scale_pal);
			SET_TV_ENC_U_SCALE(tv_u_scale_pal);
		}
		else
		{
			SET_TV_ENC_V_SCALE(tv_engmode_v_scale);
			SET_TV_ENC_U_SCALE(tv_engmode_u_scale);
		}
		REG_TV_ENC_BURST_LEVEL_CTRL=0x3d;
	}
	for (i=0;i<0x60000;i++);
}	/* set_tv_output_mode() */

kal_uint32 get_current_tv_output_buffer(void)
{
	return DRV_Reg32(TV_CON_Y_DATA_ADDR_REG);
}	/* get_current_tv_output_buffer() */

void enable_tv_output(kal_uint8 tv_on)
{
	if (tv_on==KAL_TRUE)
	{	/* start TV output */
		ENABLE_TV_CONTROLLER;
		tv_operation_state=TV_UPDATE_STATE;
	}
	else if (tv_on==KAL_FALSE)
	{	/* stop TV output */
		DISABLE_TV_CONTROLLER;
		tv_operation_state=TV_STANDBY_STATE;

⌨️ 快捷键说明

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