📄 tvp7001.c
字号:
* @param i2c_address - I - I2C address of ADC.
* @param max_sample_freq_in_mhz - I - maximum sample frequency in MHz.
* @param cap_in_nanofarads - I - loop filter cap in nanofarads
*
* @return void
*/
{
I2CPort = i2c_port;
I2CCfg = *i2c_cfg;
I2CAddress = i2c_address;
MaxSampleFreqInMHz = max_sample_freq_in_mhz;
LoopFilterCapInNF = cap_in_nanofarads;
NumTableEntries = sizeof(ADC_FunctionTable) / sizeof(ADC_TableEntryStruct);
}
int08 ADC_InitADC(void)
/**
* This function initializes the ADC for operation with the AutoLock
* implementation. OEM supplied ADC drivers must implement this function.
*
* NOTE: This function is called by the AutoLock function, ALC_AutoLockADCInit().
*
* @param void
*
* @return PASS <BR>
* ADC_I2C_DRIVER_ERROR <BR>
* ADC_I2C_DRIVER_TERMINAL_ERROR <BR>
* ADC_RTA_SEM_IN_USE <BR>
* ADC_RTA_ERROR
*/
{
uint08 i;
uint08 value;
uint08 byte_array[ADC_NUM_REGISTERS + 1];
NumTableEntries = sizeof(ADC_FunctionTable) / sizeof(ADC_TableEntryStruct);
/* Build the initialization array */
for (i = 0; i < NumTableEntries; i++)
{
if (ADC_FunctionTable[i].DoesExist)
{
value = ADC_FunctionTable[i].DefaultVal;
if (ADC_FunctionTable[i].IsInverted) value = !value;
ADC_SetADCArrayByte(ADC_FunctionTable[i].Reg,
ADC_FunctionTable[i].BitPosition,
ADC_FunctionTable[i].Mask,
value);
}
}
/**************************** LOOK HERE! *******************************/
/*****************************************************************************/
// write this register which is not one of the standard ones
ADC_SetADCArrayByte(0x16, 0, 0xFF, 0x25);
ADC_SetADCArrayByte(0x18, 0, 0xFF, 0x08);
ADC_SetADCArrayByte(0x26, 0, 0xFF, 0x80);
ADC_SetADCArrayByte(0x29, 0, 0xFF, 0x08);
ADC_SetADCArrayByte(0x2f, 0, 0xFF, 0x80);
byte_array[0] = 1;
/* set up to write to registers sequentially */
for (i = 1; i <= ADC_NUM_REGISTERS; i++)
{
byte_array[i] = ADC_Registers[i];
}
return ADC_Write (ADC_NUM_REGISTERS + 1, byte_array);
}
/*****************************************************************************/
/* Software Revision ********************************************************/
/*****************************************************************************/
int08 ADC_GetSoftwareRevision(uint08 *sw_rev)
/**
* Gets the ADC software revision.
*
* @param *sw_rev - I - storage for software revision
*
* @return PASS <BR>
* ADC_FUNCTION_NOT_SUPPORTED <BR>
* ADC_I2C_DRIVER_ERROR <BR>
* ADC_RTA_SEM_IN_USE <BR>
* ADC_RTA_ERROR
*/
{
return ADC_GetADCByte(ADC_CHIP_REVISION, sw_rev);
}
/*****************************************************************************/
/* Firmware Revision ********************************************************/
/*****************************************************************************/
int08 ADC_GetFirmwareRevision(uint08 *fw_rev)
/**
* Gets the ADC firmware revision.
*
* @param *fw_rev - I - storage for firmware revision
*
* @return PASS <BR>
* ADC_FUNCTION_NOT_SUPPORTED <BR>
* ADC_I2C_DRIVER_ERROR <BR>
* ADC_RTA_SEM_IN_USE <BR>
* ADC_RTA_ERROR
*/
{
return ADC_GetADCByte(ADC_CHIP_REVISION, fw_rev);
}
/*****************************************************************************/
/* PLL Divider Control ******************************************************/
/*****************************************************************************/
int08 ADC_SetPLLDivider(uint16 pll_divide_ratio)
/**
* Sets the ADC PLL divide ratio.
*
* The PLL divide ratio divides the HSYNC input frequency to create the
* sampling clock.
*
* @param pll_divide_ratio - I - PLL divide ratio value.
*
* @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_PLL_LIMITS, &field_limits);
if (status != PASS) return status;
if (pll_divide_ratio > field_limits.Limits.UpperLimit)
{
pll_divide_ratio = field_limits.Limits.UpperLimit;
}
else if (pll_divide_ratio < field_limits.Limits.LowerLimit)
{
pll_divide_ratio = field_limits.Limits.LowerLimit;
}
data[0] = (uint08)ADC_PLL_DIVIDER_MSB_REG;
data[1] = (uint08)((pll_divide_ratio >> 4) & 0x00ff);
data[2] = (uint08)((pll_divide_ratio << 4) & 0x00f0);
return ADC_Write(3, data);
}
int08 ADC_GetPLLDivider(uint16 *pll_divide_ratio)
/**
* Gets the ADC PLL divide ratio.
*
* NOTE: <BR>
* This function is called by the AutoLock API, ALC_GetSampleClock().
* OEM supplied ADC drivers must implement this function.
*
* @param *pll_divide_ratio - I - storage for PLL divide ratio value.
*
* @return PASS <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[2];
status = ADC_Read((uint08)ADC_PLL_DIVIDER_MSB_REG, 2, data);
if (status == PASS)
{
*pll_divide_ratio = (((uint16)data[0] << 4) | ((uint16)data[1] >> 4)) - 1;
}
return status;
}
int08 ADC_GetPLLLimits(ADC_LimitStruct *limits)
/**
* This function gets the allowable range of the PLL divide ratio
* register settings as specified by the ADC's data sheet. This is
* not the "samples per second" rating.
*
* NOTE: <BR>
* This function is called by the AutoLock function. It is used
* to ensure the calculated sample clock value does not exceed the
* range allowed by the ADC. 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_PLL_LIMITS, &field_limits);
if (status == PASS) *limits = field_limits.Limits;
return status;
}
/*****************************************************************************/
/* Input Gain & Offset Control **********************************************/
/*****************************************************************************/
int08 ADC_SetGain(uint16 red, uint16 green, uint16 blue)
/**
* Sets the ADC gain adjustment.
*
* NOTE: <BR>
* This function is called by the AutoLock API, ALC_SetGain().
* OEM supplied ADC drivers must implement this function.
* For the devices supported by this driver, the input gain
* 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 gain
* @param green - I - non-inverted value of green gain
* @param blue - I - non-inverted value of blue gain
*
* @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_GAIN_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_GAIN_REG;
data[1] = (uint08)blue;
data[2] = (uint08)green;
data[3] = (uint08)red;
return ADC_Write (4, data);
}
int08 ADC_GetGain(uint16 *red, uint16 *green, uint16 *blue)
/**
* Gets the ADC gain adjustment value.
*
* NOTE: <BR>
* This function is called by the AutoLock API, ALC_GetGain().
* 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 gain
* @param *green - I - storage for non-inverted value of green gain
* @param *blue - I - storage for non-inverted value of blue gain
*
* @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_GAIN_LIMITS, &field_limits);
if (status != PASS) return status;
status = ADC_Read((uint08)ADC_BLUE_GAIN_REG, 3, data);
if (status == PASS)
{
*blue = data[0];
*green = data[1];
*red = data[2];
}
return status;
}
int08 ADC_SetOffset(uint16 red, uint16 green, uint16 blue)
/**
* Sets the ADC 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -