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

📄 tvp7001.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 5 页
字号:
	status = ADC_GetLimits(ADC_OFFSET_LIMITS, &field_limits);
	if (status != PASS) return status;

    if (red   > field_limits.Limits.UpperLimit) return ADC_VALUE_OOR_MAX;
    if (red   < field_limits.Limits.LowerLimit) return ADC_VALUE_OOR_MIN;
    if (green > field_limits.Limits.UpperLimit) return ADC_VALUE_OOR_MAX;
    if (green < field_limits.Limits.LowerLimit) return ADC_VALUE_OOR_MIN;
    if (blue  > field_limits.Limits.UpperLimit) return ADC_VALUE_OOR_MAX;
    if (blue  < field_limits.Limits.LowerLimit) return ADC_VALUE_OOR_MIN;

	data[0] = (uint08)ADC_BLUE_OFFSET_REG;
    data[1] = (uint08)blue;
    data[2] = (uint08)green;
    data[3] = (uint08)red;

	return ADC_Write (4, data);        
}

int08 ADC_GetOffset(uint16 *red, uint16 *green, uint16 *blue)
/**
 * Gets the ADC offset adjustment value.
 *
 * NOTE:														<BR>
 * This function is called by the AutoLock API, ALC_GetOffset().
 * OEM supplied ADC drivers must implement this function.
 * For the devices supported by this driver, the address 
 * arguments are populated with the maximum register values 
 * minus the values read from the ADC. Hence the reference 
 * to non-inverted values.
 *
 * @param  *red   - I - storage for non-inverted value of red offset
 * @param  *green - I - storage for non-inverted value of green offst
 * @param  *blue  - I - storage for non-inverted value of blue offset
 *
 * @return PASS													<BR>
 *   	   ADC_FIELD_LIMITS_UNSPECIFIED							<BR>
 *		   ADC_I2C_DRIVER_ERROR									<BR>
 * 		   ADC_I2C_DRIVER_TERMINAL_ERROR  						<BR> 
 *		   ADC_RTA_SEM_IN_USE									<BR>
 *		   ADC_RTA_ERROR
 */
 
{ 
 	int08 status;
    uint08 data[3];
 	ADC_FieldLimitsStruct field_limits;      

	status = ADC_GetLimits(ADC_OFFSET_LIMITS, &field_limits);
	if (status != PASS) return status;
	
	status = ADC_Read((uint08)ADC_BLUE_OFFSET_REG, 3, data);
	if (status == PASS)
	{
		*blue  = data[0];
		*green = data[1];
		*red   = data[2];
	}

	return status;	
}

int08 ADC_SetCoarseOffset(uint16 red, uint16 green, uint16 blue)
/**
 * Sets the ADC coarse offset adjustment.
 *
 * NOTE:														<BR>
 * This function is called by the AutoLock API, ALC_SetOffset(). 
 * OEM supplied ADC drivers must implement this function.
 * For the devices supported by this driver, the input offset 
 * values are subtracted from the maximum register setting 
 * before application to the ADC. Hence the reference to
 * non-inverted values. 
 *
 * @param  red   - I - non-inverted value of red offset
 * @param  green - I - non-inverted value of green offset
 * @param  blue  - I - non-inverted value of blue offset
 *
 * @return PASS													<BR>
 *   	   ADC_FIELD_LIMITS_UNSPECIFIED							<BR>
 *         ADC_VALUE_OOR_MIN									<BR>
 *         ADC_VALUE_OOR_MAX									<BR>
 *         ADC_I2C_DRIVER_ERROR									<BR>
 * 		   ADC_I2C_DRIVER_TERMINAL_ERROR  						<BR> 
 *         ADC_RTA_SEM_IN_USE									<BR> 
 *         ADC_RTA_ERROR	 	   		    
 */
{ 
 	int08 status;
    uint08 data[4];
 	ADC_FieldLimitsStruct field_limits;      

	status = ADC_GetLimits(ADC_COARSE_OFFSET_LIMITS, &field_limits);
	if (status != PASS) return status;

    if (red   > field_limits.Limits.UpperLimit) return ADC_VALUE_OOR_MAX;
    if (red   < field_limits.Limits.LowerLimit) return ADC_VALUE_OOR_MIN;
    if (green > field_limits.Limits.UpperLimit) return ADC_VALUE_OOR_MAX;
    if (green < field_limits.Limits.LowerLimit) return ADC_VALUE_OOR_MIN;
    if (blue  > field_limits.Limits.UpperLimit) return ADC_VALUE_OOR_MAX;
    if (blue  < field_limits.Limits.LowerLimit) return ADC_VALUE_OOR_MIN;

	data[0] = (uint08)ADC_BLUE_COARSE_OFFSET_REG;
    data[1] = (uint08)blue;
    data[2] = (uint08)green;
    data[3] = (uint08)red;

	return ADC_Write (4, data);        
}

int08 ADC_GetCoarseOffset(uint16 *red, uint16 *green, uint16 *blue)
/**
 * Gets the ADC offset adjustment value.
 *
 * NOTE:														<BR>
 * This function is called by the AutoLock API, ALC_GetOffset().
 * OEM supplied ADC drivers must implement this function.
 * For the devices supported by this driver, the address 
 * arguments are populated with the maximum register values 
 * minus the values read from the ADC. Hence the reference 
 * to non-inverted values.
 *
 * @param  *red   - I - storage for non-inverted value of red offset
 * @param  *green - I - storage for non-inverted value of green offst
 * @param  *blue  - I - storage for non-inverted value of blue offset
 *
 * @return PASS													<BR>
 *   	   ADC_FIELD_LIMITS_UNSPECIFIED							<BR>
 *		   ADC_I2C_DRIVER_ERROR									<BR>
 * 		   ADC_I2C_DRIVER_TERMINAL_ERROR  						<BR> 
 *		   ADC_RTA_SEM_IN_USE									<BR>
 *		   ADC_RTA_ERROR
 */
 
{ 
 	int08 status;
    uint08 data[3];
 	ADC_FieldLimitsStruct field_limits;      

	status = ADC_GetLimits(ADC_COARSE_OFFSET_LIMITS, &field_limits);
	if (status != PASS) return status;
	
	status = ADC_Read((uint08)ADC_BLUE_COARSE_OFFSET_REG, 3, data);
	if (status == PASS)
	{
		*blue  = data[0];
		*green = data[1];
		*red   = data[2];
	}

	return status;	
}

int08 ADC_SetGainAndOffset(uint16 red_gain,
                           uint16 green_gain,
                           uint16 blue_gain,
                           uint16 red_offset,
                           uint16 green_offset,
                           uint16 blue_offset)
/**
 * Sets ADC gain and offset adjustment for all colors.
 *
 * NOTE: 														<BR>
 * This function is called by the AutoLock function. OEM 
 * supplied ADC drivers must implement this function. 
 * For the devices supported by this driver, the input 
 * gain and offset values are subtracted from their 
 * respective maximum levels before application to the ADC.
 * 
 * @param  red_gain     - I - non-inverted value of red gain
 * @param  green_gain   - I - non-inverted value of green gain
 * @param  blue_gain    - I - non-inverted value of blue gain
 * @param  red_offset   - I - non-inverted value of red offset
 * @param  green_offset - I - non-inverted value of green offset
 * @param  blue_offset  - I - non-inverted value of blue offset
 *
 * @return void
 */
 {
 	int08 status;
    uint08 data[7];
 	ADC_FieldLimitsStruct field_limits;      

	status = ADC_GetLimits(ADC_GAIN_LIMITS, &field_limits);
	if (status != PASS) return status;

    if (red_gain > field_limits.Limits.UpperLimit)
    {
        red_gain = field_limits.Limits.UpperLimit;
    }   
    
    if (green_gain > field_limits.Limits.UpperLimit)
    {
        green_gain = field_limits.Limits.UpperLimit;
    }   

    if (blue_gain > field_limits.Limits.UpperLimit)
    {
        blue_gain = field_limits.Limits.UpperLimit;
    }   

	data[0] = (uint08)ADC_BLUE_GAIN_REG;
    data[1] = (uint08)blue_gain;
    data[2] = (uint08)green_gain;
    data[3] = (uint08)red_gain;
	
	status = ADC_GetLimits(ADC_OFFSET_LIMITS, &field_limits);
	if (status != PASS) return status;

    if (red_offset > field_limits.Limits.UpperLimit)
    {
        red_offset = field_limits.Limits.UpperLimit;
    }   
    
    if (green_offset > field_limits.Limits.UpperLimit)
    {
        green_offset = field_limits.Limits.UpperLimit;
    }   

    if (blue_offset > field_limits.Limits.UpperLimit)
    {
        blue_offset = field_limits.Limits.UpperLimit;
    }   

    data[4] = (uint08)blue_offset;
    data[5] = (uint08)green_offset;
    data[6] = (uint08)red_offset;

	return ADC_Write (7, data);
} 

int08 ADC_GetGainLimits(ADC_LimitStruct *limits)
/**
 * Gets the ADC limits of the gain value.
 *
 * NOTE: 														<BR>
 * The AutoLock algorithm will call this function to find the 
 * range of values allowed by the ADC driver target. All integer 
 * values, between and inclusive of the limit endpoints will be 
 * considered valid by the AutoLock algorithm. This function is 
 * also called by ALC_GetGainLimits(). OEM supplied ADC drivers 
 * must implement this function.
 *
 * @param  *limits - I - pointer to struct containing limit values.
 *
 * @return PASS													<BR>
 *         ADC_FIELD_LIMITS_UNSPECIFIED
 */    
{   
	int08 status;  
	ADC_FieldLimitsStruct field_limits;

    status = ADC_GetLimits(ADC_GAIN_LIMITS, &field_limits);
    if (status == PASS) *limits = field_limits.Limits;
    return status;
}

int08 ADC_GetOffsetLimits(ADC_LimitStruct *limits)
/**
 * Gets the ADC limits of the offset value.
 *
 * NOTE: 														<BR>
 * The AutoLock algorithm will call this function to find the 
 * range of values allowed by the ADC driver target. All integer 
 * values, between and inclusive of the limit endpoints will be 
 * considered valid by the AutoLock algorithm. This function is 
 * also called by ALC_GetOffsetLimits(). OEM supplied ADC drivers 
 * must implement this function.
 *
 * @param  *limits - I - pointer to struct containing limit values.
 *
 * @return PASS													<BR>
 *         ADC_FIELD_LIMITS_UNSPECIFIED
 */    
{     
	int08 status;
	ADC_FieldLimitsStruct field_limits;

    status = ADC_GetLimits(ADC_OFFSET_LIMITS, &field_limits);
    if (status == PASS) *limits = field_limits.Limits;
    return status;
}

/*****************************************************************************/
/* Clamp Timing Control ******************************************************/
/*****************************************************************************/

int08 ADC_SetClampPlacement(uint16 clamp_placement)
/**
 * Sets the ADC clamp placement value.
 *
 * This value defines the number of pixel periods after the
 * trailing edge of the HSYNC pulse to position the clamping
 * signal. This register is valid only when the ADC is
 * configured for internal clamping.
 *
 * NOTE:														<BR>
 * The AutoLock algorithm will sometimes call this function 
 * during source detection. OEM supplied ADC drivers must
 * implement this function and implement it so the argument
 * represents the number of pixel periods after the HSYNC 
 * trailing edge. 
 *
 * @param  clamp_placement - I - clamp placement
 *
 * @return PASS													<BR>
 *   	   ADC_FUNCTION_NOT_SUPPORTED							<BR>
 *   	   ADC_FIELD_LIMITS_UNSPECIFIED							<BR>
 *         ADC_VALUE_OOR_MIN									<BR>
 *         ADC_VALUE_OOR_MAX									<BR>
 *         ADC_I2C_DRIVER_ERROR									<BR>
 * 		   ADC_I2C_DRIVER_TERMINAL_ERROR  						<BR> 
 *         ADC_RTA_SEM_IN_USE									<BR>
 *         ADC_RTA_ERROR		   		    
 */
{
    int08 status;
    uint08 alc_placement;

	/* Do this because ADC_SetADCByte() will not range check 16 bit input */
	if (clamp_placement > 0xFF)
	{
		return ADC_VALUE_OOR_MAX;
	}	
	
	status = ADC_SetADCByte(ADC_CLAMP_PLACEMENT, (uint08)clamp_placement);
	
//	return status;
	
	if (status != PASS) return status;
	
    alc_placement = ADC_Registers[5] + ADC_Registers[6];
	return ADC_SetADCByte(ADC_ALC_PLACEMENT, alc_placement);                        		
}

int08 ADC_GetClampPlacement(uint16 *clamp_placement)
/**
 * Gets the ADC clamp placement value.
 *

⌨️ 快捷键说明

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