📄 saa7114.c
字号:
{AVertPhaseChroma11, 0x00},
{AVertPhaseLuma00, 0x00},
{AVertPhaseLuma01, 0x00},
{AVertPhaseLuma10, 0x00},
{AVertPhaseLuma11, 0x00},
/* task B */
{BTaskHandlingControl, 0x03},
{BXPortFormat, 0x08},
{BXPortInputRef, 0x00},
{BIPortFormat, 0x80},
{BHorzInputStart, 0x03},
{BHorzInputStartMSB, 0x00},
{BHorzInputLength, 0xd0},
{BHorzInputLengthMSB, 0x02},
{BVertInputStart, 0x18},
{BVertInputStartMSB, 0x00},
{BVertInputLength, 0x18},
{BVertInputLengthMSB, 0x01},
{BHorzOutputLength, 0xce},
{BHorzOutputLengthMSB, 0x02},
{BVertOutputLength, 0x18},
{BVertOutputLengthMSB, 0x01},
{BHorzPrescale, 0x02},
{BAcl, 0x01},
{BDCGain, 0x01},
{BLuminanceBrightness, 0x80},
{BLuminanceContrast, 0x20},
{BChromaSaturation, 0x20},
{BHorzScalingLuma, 0x00},
{BHorzScalingLumaMSB, 0x04},
{BHorzPhaseLuma, 0x00},
{BHorzScalingChroma, 0x00},
{BHorzScalingChromaMSB, 0x02},
{BHorzPhaseChroma, 0x00},
{BVertScalingLuma, 0xf8},
{BVertScalingLumaMSB, 0x07},
{BVertScalingChroma, 0xf8},
{BVertScalingChromaMSB, 0x07},
{BVertScalingMode, 0x01},
{BVertPhaseChroma00, 0x07},
{BVertPhaseChroma01, 0x07},
{BVertPhaseChroma10, 0x07},
{BVertPhaseChroma11, 0x07},
{BVertPhaseLuma00, 0x07},
{BVertPhaseLuma01, 0x07},
{BVertPhaseLuma10, 0x07},
{BVertPhaseLuma11, 0x07},
{-1,-1} /* End of array */
};
/******************************************************************************/
/* Static variables: */
static UInt m_nNumVBILines;
static UInt m_nStartVBILine;
static UInt lastI2cError = 0;
/******************************************************************************/
#define MAX_TT 14
/* Teletext translation table to convert bit masks into */
/* teletext program nibbles quickly. */
typedef struct
{
Int nBitMask;
Int nNibble;
} viDataServiceMapping_t;
static viDataServiceMapping_t Convert7114TT[MAX_TT] =
{
{vdsEuroTeleText, 0x0},
{vdsEuroClosedCaption, 0x1},
{vdsVPS, 0x2},
{vdsWSS, 0x3},
{vdsUSTeleText, 0x4},
{vdsUSClosedCaption, 0x5},
{vdsUpsampledRaw, 0x7},
{vdsTeleText, 0x8},
{vdsVITC_EBU, 0x9},
{vdsVITC_SMPTE, 0xA},
{vdsUSNABTS, 0xC},
{vdsMoji, 0xD},
{vdsJapFormatSwitch, 0xE},
{vdsNone, 0xF},
};
/*-----------------------------------------------------------------------------*/
/* Array to get the sharpness settings quickly */
static int LUFI[16] =
{
0x0f, /* low pass filter 3dB at 1,7Mz */
0x0e, /* low pass filter 3dB at 1,9Mz */
0x0d, /* low pass filter 3dB at 2,2Mz */
0x0c, /* low pass filter 3dB at 2,4Mz */
0x0b, /* low pass filter 3dB at 2,6Mz */
0x0a, /* low pass filter 3dB at 3,3Mz */
0x09, /* low pass filter 3dB at 4,1Mz */
0x08, /* low pass filter 2dB at 4,1Mz */
0x00, /* plain */
0x07, /* res. enh. filter 1,6dB at 4,1MHz */
0x06, /* res. enh. filter 2,3dB at 4,1MHz */
0x05, /* res. enh. filter 3,0dB at 4,1MHz */
0x04, /* res. enh. filter 4,1dB at 4,1MHz */
0x03, /* res. enh. filter 5,1dB at 4,1MHz */
0x02, /* res. enh. filter 6,8dB at 4,1MHz */
0x01 /* res. enh. filter 8,0dB at 4,1MHz */
};
/******************************************************************************/
static tmLibdevErr_t
mapAdapterInput (pboardVIDec_t pVD, pboardVIParam_t param, UInt *mode)
{
UInt i;
/* If this is vaaNone then use the default adapter */
if (param->adapterType == vaaNone)
{
*mode = pVD->adapterTable[0].decInput;
return TMLIBDEV_OK;
}
for (i = 0; i < pVD->numAdapters; i++)
{
/* Find the right instance of the adapter */
if ((pVD->adapterTable[i].instNum == param->adapterInstance) &&
(pVD->adapterTable[i].adapterType == param->adapterType))
{
*mode = pVD->adapterTable[i].decInput;
return TMLIBDEV_OK;
}
}
/* No adapter instance found. If it's unqual to zero */
/* -> try with instance zero... */
if (param->adapterInstance != 0)
{
param->adapterInstance = 0;
return mapAdapterInput (pVD, param, mode);
}
/* Right adapter was not found -> return error */
return BOARD_ERR_UNSUPPORTED_ADAPTER;
}
/******************************************************************************/
tmLibdevErr_t
saa7114InitM (pboardVIDec_t pVD, pboardVIParam_t param)
{
UInt i, rval = 0;
UInt inputMode;
viSetSELFCLOCKM(param->mmioBase, 0);
/* Copy video standard to internal variable */
pVD->curVideoStandard = param->videoStandard;
/* Setup default setting in SAA7114 */
for (i = 0; saa7114_defRegs[i].nSubAddr >= 0; i++)
{
rval |= iicWriteReg (pVD->slaveAddr, saa7114_defRegs[i].nSubAddr, saa7114_defRegs[i].nValue);
}
if (! ( (param->adapterType == vaaNone)
|| (param->adapterType & (vaaCVBS|vaaSvideo))) )
return BOARD_ERR_UNSUPPORTED_ADAPTER;
/* Make sure the adapter's instance is valid on this board and we get a valid mode */
if (mapAdapterInput (pVD, param, &inputMode) != TMLIBDEV_OK)
return BOARD_ERR_INVALID_ADAPTER_INSTANCE;
/* Start saa7112 task */
rval |= iicWriteReg(pVD->slaveAddr, 0x80, 0x90);
/* Set input of video accordingly */
rval |= saa7114SetAnalogInput (pVD, inputMode);
if (param->videoStandard == vasNone)
return TMLIBDEV_OK;
if ( !(param->videoStandard & (vasNTSC | vasPAL)) )
return BOARD_ERR_UNSUPPORTED_STANDARD;
/* from here on : supported videoStandard is specified */
return (tmLibdevErr_t) rval;
}
tmLibdevErr_t
saa7114Init (pboardVIParam_t param)
{
return saa7114InitM(&defaultVD[0], param);
}
/******************************************************************************/
tmLibdevErr_t
saa7114GetStandardM(pboardVIDec_t pVD, tmVideoAnalogStandard_t * std)
{
unsigned int stat, chroma;
int notDetected = True;
int err = 0;
int i, j;
unsigned char colorStandard[5] = {0x01, 0x11, 0x21, 0x31, 0x51};
microsleep(40000); /* This stupid routine need to sleep a lot. */
for (j = 0; ( (j<2) && notDetected ); j++) {
for ( *std = vasNone, i = 0; ( (i<5) && notDetected); i++) {
err |= iicWriteReg (pVD->slaveAddr, ChromaControl1, colorStandard[i]);
microsleep(100000);
err |= iicReadReg (pVD->slaveAddr, ChromaControl1, &chroma);
err |= iicReadReg (pVD->slaveAddr, StatusByte, &stat);
if (err) {
/* iic read write err */
return ( (tmLibdevErr_t) err);
}
if (stat & A_HLCK) {
microsleep(500000); /* not in sync err, give it a long nap */
}
if (stat & A_CODE) { /* color videoStandard detected */
if (stat & A_FIDT) { /* 60 Hz */
switch (i) {
case 0: /* NTSC M */
*std = vasNTSC;
break;
case 1: /* PAL 4.43 */
*std = vasPAL;
break;
case 2: /* NTSC 4.43 */
*std = vasNTSC;
break;
case 3: /* NTSC N */
*std = vasNTSC;
break;
case 4: /* PAL 4.43 */
*std = vasPAL;
break;
default:
*std = vasNone; /* should not come here */
break;
} /* end of switch */
} else { /* 50Hz */
switch (i) {
case 0: /* PAL BGHI */
*std = vasPAL;
break;
case 1: /* NTSC 4.43 */
*std = vasNTSC;
break;
case 2: /* PAL N */
*std = vasPAL;
break;
case 3: /* PAL M */
*std = vasPAL;
break;
case 4: /* SECAM */
*std = vasSECAM;
break;
default:
*std = vasNone; /* should not come here */
break;
} /* end of switch */
}
notDetected = False;
}
} /* end of i for loop */
} /* end of j for loop */
if (stat & A_HLCK) {
/* not in sync err, message may be obscure */
return BOARD_ERR_VAL_OUT_OF_RANGE;
}
if (notDetected) {
return BOARD_ERR_COLOR_STANDARD_NOT_DETECTED;
}
/* Store detected standard in internal variable */
pVD->curVideoStandard = *std;
return TMLIBDEV_OK;
}
tmLibdevErr_t
saa7114GetStandard(tmVideoAnalogStandard_t * std)
{
return saa7114GetStandardM (&defaultVD[0], std);
}
tmLibdevErr_t
saa7114GetAdapterVideoStandard(pboardVIDec_t pVD, tmVideoAnalogAdapter_t adapter, UInt adapterNum, tmVideoAnalogStandard_t *std)
{
UInt inputMode;
/* Build up fake param structure to use available map function */
boardVIParam_t param;
param.adapterInstance = adapterNum;
param.adapterType = adapter;
/* Map the adapter's instance to a valid mode */
if (mapAdapterInput (pVD, ¶m, &inputMode) != TMLIBDEV_OK)
return BOARD_ERR_INVALID_ADAPTER_INSTANCE;
/* Set input of video accordingly */
saa7114SetAnalogInput (pVD, inputMode);
return saa7114GetStandardM (pVD, std);
}
/******************************************************************************/
tmLibdevErr_t
saa7114ConfigureM(pboardVIDec_t pVD, UInt32 subaddr, UInt32 value)
{
tmLibdevErr_t rval = TMLIBDEV_OK;
rval |= iicWriteReg(pVD->slaveAddr, subaddr, value);
return (tmLibdevErr_t) rval;
}
tmLibdevErr_t
saa7114Configure(UInt32 subaddr, UInt32 value)
{
return saa7114ConfigureM(&defaultVD[0], subaddr, value);
}
/******************************************************************************/
extern tmLibdevErr_t
saa7114GetBrightnessM(pboardVIDec_t pVD, UInt * val)
{
return iicReadReg(pVD->slaveAddr, LuminanceBrightness, val);
}
extern tmLibdevErr_t
saa7114GetBrightness(UInt * val)
{
return saa7114GetBrightnessM(&defaultVD[0], val);
}
/******************************************************************************/
extern tmLibdevErr_t
saa7114SetBrightnessM(pboardVIDec_t pVD, UInt val)
{
if (val > 255)
return BOARD_ERR_VAL_OUT_OF_RANGE;
return iicWriteReg(pVD->slaveAddr, LuminanceBrightness, val);
}
extern tmLibdevErr_t
saa7114SetBrightness(UInt val)
{
return saa7114SetBrightnessM(&defaultVD[0], val);
}
/******************************************************************************/
extern tmLibdevErr_t
saa7114GetContrastM(pboardVIDec_t pVD, UInt * val)
{
return iicReadReg(pVD->slaveAddr, LuminanceContrast, val);
}
extern tmLibdevErr_t
saa7114GetContrast(UInt * val)
{
return saa7114GetContrastM(&defaultVD[0], val);
}
/******************************************************************************/
extern tmLibdevErr_t
saa7114SetContrastM(pboardVIDec_t pVD, UInt val)
{
if (val > 127)
return BOARD_ERR_VAL_OUT_OF_RANGE;
return iicWriteReg(pVD->slaveAddr, LuminanceContrast, val);
}
extern tmLibdevErr_t
saa7114SetContrast(UInt val)
{
return saa7114SetContrastM(&defaultVD[0], val);
}
/******************************************************************************/
extern tmLibdevErr_t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -