📄 ad9887.c
字号:
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* ad9887.c - AD9887 driver
*
* description:
* ------------
* Includes all interface functions rquired for AD9887 operation
*
*
* Functions:
* ----------
*
*
* AD9887_Init
* AD9887_SetHSYNCPolarity
* AD9887_SetCoastPolarity
* AD9887_SetGain
* AD9887_SetOffset
* AD9887_SetPhase
* AD9887_GetPhase
* AD9887_SetClamp
* AD9887_SetPLL
* AD9887_Read
* AD9887_Write
*
* history:
* $History: $
*
* who when what
* --- ---------- ----
* ori 21/10/2001 creation
* $NoKeywords :$
*/
#include <stdio.h>
#include "types.h"
#include "fp.h"
#include "i2c.h"
#include "a2d.h"
#include "ad9887.h"
#include "evb.h"
#include "logic.h"
/*defines */
#define MAX_PIXEL_CLOCK 140000000L // 140 MSPS
/******************************************************************************/
/* static function */
static void AD9887_InitHdtv(void);
static void AD9887_InitGraphic(void);
static void AD9887_InitDVI(void);
/******************************************************************************/
/* AD9884A registers access functions */
static TA2D_Result AD9887_Read(TAD9887_Registers Reg, TBYTE *Data);
static TA2D_Result AD9887_Write(TAD9887_Registers Reg, TBYTE Data);
/******************************************************************************/
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* AD9884A_Init- A2D module init
*
*
* description:
* ------------
*
* Verify device exists - get its id
* Get input format (graphics/hdtv/dvi)
* Set registers values according to input format
*
* Protoype:
* ----------
* TA2D_ResultAD9884A_Init(void)
* Where:
* Returns:
* A2D_OK or A2D_DeviceNotSupported
*
* history:
*
* who when what
* --- ---------- ----
* Ori 18/12/2001 creation
*
*/
TA2D_Result AD9887_Init(void)
{
TA2D_Result rc = A2D_OK;
TBYTE ChipRevision;
/* Verify device exists - get its revision id */
rc = AD9887_Read(AD9887_CHREV, &ChipRevision);
/*
if (rc == A2D_OK)
{
// set registers to required values
//rc = AD9887_Write(AD9887_TEST3, 0x10); // 00010000
//rc = AD9887_Write(AD9887_TEST2, 0x41); // 01000001
AD9887_SetInputFormat(LOGIC_GetGraphicsSource());
}
*/
return (rc);
} /* AD9887_Init */
/******************************************************************************/
/******************************************************************************/
TA2D_Result AD9887_GetInputVSYNCPolarity(Boolean *Polarity)
{
TA2D_Result rc;
union {
TAD9887_PolStatus bits;
TBYTE byte;
} PolStatus;
rc = AD9887_Read(AD9887_POL_STATUS, &PolStatus.byte);
*Polarity = !PolStatus.bits.vsyncoutpol;
return (rc);
}
/******************************************************************************/
/******************************************************************************/
TA2D_Result AD9887_GetInputHSYNCPolarity(Boolean *Polarity)
{
TA2D_Result rc;
union {
TAD9887_PolStatus bits;
TBYTE byte;
} PolStatus;
rc = AD9887_Read(AD9887_POL_STATUS, &PolStatus.byte);
*Polarity = PolStatus.bits.hsyncinpol;
return (rc);
}
/******************************************************************************/
/******************************************************************************/
TA2D_Result AD9887_SetPLLInHSYNCPolarity(Boolean Polarity)
{
TA2D_Result rc;
union {
TAD9887_PllClampControl bits;
TBYTE byte;
} PLLControl;
AD9887_Read(AD9887_PLLCLCO, &PLLControl.byte);
PLLControl.bits.hsyncpol = Polarity;
rc = AD9887_Write(AD9887_PLLCLCO, PLLControl.byte);
return(rc);
}
/******************************************************************************/
/******************************************************************************/
TA2D_Result AD9887_GetPLLInHSYNCPolarity(Boolean *Polarity)
{
TA2D_Result rc;
union {
TAD9887_PllClampControl bits;
TBYTE byte;
} PLLControl;
rc = AD9887_Read(AD9887_PLLCLCO, &PLLControl.byte);
*Polarity = PLLControl.bits.hsyncpol;
return(rc);
}
/******************************************************************************/
/******************************************************************************/
TA2D_Result AD9887_SetOutHSYNCPolarity(Boolean Polarity)
{
TA2D_Result rc = A2D_OK;
union {
TAD9887_ModeControl1 bits;
TBYTE byte;
} ModeControl1Val;
AD9887_Read(AD9887_MODCONTROL1, &ModeControl1Val.byte);
ModeControl1Val.bits.hsyncpol = Polarity;
rc = AD9887_Write(AD9887_MODCONTROL1, ModeControl1Val.byte);
return(rc);
}
/******************************************************************************/
/******************************************************************************/
TA2D_Result AD9887_GetOutHSYNCPolarity(Boolean *Polarity)
{
TA2D_Result rc = A2D_OK;
union {
TAD9887_ModeControl1 bits;
TBYTE byte;
} ModeControl1Val;
rc = AD9887_Read(AD9887_MODCONTROL1, &ModeControl1Val.byte);
*Polarity = ModeControl1Val.bits.hsyncpol;
return(rc);
}
/******************************************************************************/
/******************************************************************************/
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* AD9887_SetCoastPolarity- Set Coast polarity
*
*
* description:
* ------------
* Set the polarity of the coast signal that is applied to the COAST input.
*
*
* Protoype:
* ----------
* TA2D_Result AD9887_SetCoastPolarity(TA2D_SignalPolarity Polarity)
* Where:
* Polarity - required COAST signal polarity
* Returns:
* A2D_OK
*
* history:
*
* who when what
* --- ---------- ----
* Ori 21/10/2001 creation
*
*/
#define COAST_INPUT 0
#define VSYNC_COAST 1
TA2D_Result AD9887_SetCoastPolarity(Boolean Polarity)
{
TA2D_Result rc = A2D_OK;
union {
TAD9887_PllClampControl bits;
TBYTE byte;
} Control1Val;
union {
TAD9887_ActiveInterface bits;
TBYTE byte;
} ActiveInterface;
union {
TAD9887_ControlBits1 bits;
TBYTE byte;
} ControlBits;
rc = AD9887_Read(AD9887_PLLCLCO, &Control1Val.byte);
rc = AD9887_Read(AD9887_ACIN, &ActiveInterface.byte);
rc = AD9887_Read(AD9887_CONTROL1, &ControlBits.byte);
ActiveInterface.bits.coastsel = COAST_INPUT;
ControlBits.bits.coastpol = True;
Control1Val.bits.coastpol = Polarity;
rc = AD9887_Write(AD9887_PLLCLCO, Control1Val.byte);
rc = AD9887_Write(AD9887_ACIN, ActiveInterface.byte);
rc = AD9887_Write(AD9887_CONTROL1, ControlBits.byte);
return (rc);
} /* AD9887_SetCoastPolarity */
/******************************************************************************/
/******************************************************************************/
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* AD9887_SetGain- Set color channel gain
*
*
* description:
* ------------
* Set the gain for the specific color channel (R/G/B).
* The function actually calls to the on-board A2D function.
*
*
* Protoype:
* ----------
* TA2D_Result AD9887_SetGain (TA2D_Channel Channel, signed char Val)
* Where:
* Channel - required channel: R/G/B
* Val - Gain value
* Returns:
* A2D_OK
*
* history:
*
* who when what
* --- ---------- ----
* Ori 21/10/2001 creation
*
*/
TA2D_Result AD9887_SetGain (TA2D_Channel Channel, TBYTE Val)
{
TA2D_Result rc = A2D_OK;
switch (Channel)
{
case A2D_Red:
rc = AD9887_Write(AD9887_REDGAIN, Val);
break;
case A2D_Green:
rc = AD9887_Write(AD9887_GRNGAIN, Val);
break;
case A2D_Blue:
rc = AD9887_Write(AD9887_BLUGAIN, Val);
break;
default:
rc = A2D_NoSuchChannel;
break;
}
return (rc);
} /* AD9887_SetGain */
/******************************************************************************/
/******************************************************************************/
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* AD9887_SetOffset- Set color channel DC offset
*
*
* description:
* ------------
* Set the color channel DC offset.
*
*
* Protoype:
* ----------
* TA2D_Result AD9884A_SetOffset (TA2D_Channel Channel, signed char Val)
* Where:
* Channel - required channel: R/G/B
* Val - Offset value
* Returns:
* A2D_OK
*
* history:
*
* who when what
* --- ---------- ----
* Ori 21/10/2001 creation
*
*/
TA2D_Result AD9887_SetOffset (TA2D_Channel Channel, TBYTE Val)
{
TA2D_Result rc = A2D_OK;
switch (Channel)
{
case A2D_Red:
rc = AD9887_Write(AD9887_REDOFST, Val);
break;
case A2D_Green:
rc = AD9887_Write(AD9887_GRNOFST, Val);
break;
case A2D_Blue:
rc = AD9887_Write(AD9887_BLUOFST, Val);
break;
default:
rc = A2D_NoSuchChannel;
break;
}
return (rc);
} /* AD9887_SetOffset */
/******************************************************************************/
/******************************************************************************/
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* AD9887_SetPhase- Set clock phase
*
*
* description:
* ------------
* Adjust the sampling phase. Range is 0 to 349.75 (32*11.25) degrees.
*
*
* Protoype:
* ----------
* TA2D_Result AD9887_SetPhase (TBYTE Phase)
* Where:
* Phase - Phase value in degrees
* Returns:
* A2D_OK
*
* history:
*
* who when what
* --- ---------- ----
* Ori 21/02/2000 creation
*
*/
TA2D_Result AD9887_SetPhase (TBYTE Phase)
{
union {
TAD9887_Phase bits;
TBYTE byte;
} PhaseReg;
TA2D_Result rc;
if (Phase <= A2D_PHASEMAX)
{
PhaseReg.bits.phase = Phase;
rc = AD9887_Write(AD9887_PHASE, PhaseReg.byte);
}
else
rc = A2D_IllegalValue;
return (rc);
} /* AD9887_SetPhase */
/******************************************************************************/
/******************************************************************************/
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* AD9887_GetPhase- Returns clock phase
*
*
* description:
* ------------
* Returns the sampling phase. Range is 0 to 349.75 (32*11.25) degrees.
*
*
* Protoype:
* ----------
* TBYTE AD9884A_GetPhase (void)
* Where:
* Returns:
* Phase - Phase value in degrees
*
* history:
*
* who when what
* --- ---------- ----
* Ori 21/10/2001 creation
*
*/
TBYTE AD9887_GetPhase (void)
{
TAD9887_Phase PhaseReg;
AD9887_Read(AD9887_PHASE, (TBYTE *)&PhaseReg);
return (PhaseReg.phase);
} /* AD9887_GetPhase */
/******************************************************************************/
/******************************************************************************/
/*
* Copyright (c) 1999-2000 Oplus Technologies INC. All Rights resreved.
*
* AD9887_SetPLL- Set PLL parameters
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -