saa7113.c

来自「SAA7113在psos下的驱动程序,及7113的硬件datasheet」· C语言 代码 · 共 1,308 行 · 第 1/3 页

C
1,308
字号
    return iicWriteReg(pVD->slaveAddr, ChromaSaturation, val);
}

extern      tmLibdevErr_t
saa7113SetSaturation(unsigned int val)
{
    return saa7113SetSaturationM(&defaultVD[0], val);
}

/******************************************************************************/

extern      tmLibdevErr_t
saa7113GetHueM(pboardVIDec_t pVD, unsigned int * val)
{
    return iicReadReg(pVD->slaveAddr, ChromaHueControl, val);
}

extern      tmLibdevErr_t
saa7113GetHue(unsigned int * val)
{
    return saa7113GetHueM(&defaultVD[0], val);
}

/******************************************************************************/

extern      tmLibdevErr_t
saa7113SetHueM(pboardVIDec_t pVD, unsigned int val)
{
    if (val > 255)
        return BOARD_ERR_VAL_OUT_OF_RANGE;

    return iicWriteReg(pVD->slaveAddr, ChromaHueControl, val);
}

extern      tmLibdevErr_t
saa7113SetHue(unsigned int val)
{
    return saa7113SetHueM(&defaultVD[0], val);
}

/******************************************************************************/
/* Helper functions for video decoder HAL functionality  */

static Bool                         /* Successful or not */
SetReg(                             /* Set a register value */
    pboardVIDec_t pVD,              /* Pointer to I2C access structure */
    UInt8 bReg,                     /* Subaddress of the register */
    UInt8 bData)                    /* Value to be written */
{
    lastI2cError = 0;
    return ((lastI2cError = iicWriteReg(pVD->slaveAddr, bReg, bData)) == TMLIBDEV_OK);
}

static Bool                         /* Successful or not */
GetReg(                             /* Get a register value */
    pboardVIDec_t pVD,              /* Pointer to I2C access structure */
    UInt8 bReg,                     /* Subaddress of the register */
    UInt8 * pbData)                 /* Pointer to variable to recieve value */
{
    unsigned int data;
    Bool retVal;

    lastI2cError = 0;
    if (retVal = ((lastI2cError = iicReadReg (pVD->slaveAddr, bReg, &data)) == TMLIBDEV_OK))
        *pbData = data;
    else
        *pbData = 0;
    
    return retVal;
}

/********************************************************************************************/
extern tmLibdevErr_t
saa7113GetVSyncFallingEdge(pboardVIDec_t pVD, unsigned int *lineNumber)
{
 //   tmVideoAnalogStandard_t std;
 //   tmLibdevErr_t rval;

    /* Equivalent to Video DecHAL VideoDecGetDefaultAcquisitionWnd */

    switch (pVD->curVideoStandard)
    {
    case vasNTSC:
            /* First line seen by TM */
        *lineNumber = 20;
        break;
    case vasPAL:
        *lineNumber = 23;
        break;
    default:
        return BOARD_ERR_COLOR_STANDARD_NOT_DETECTED;
        }

    return TMLIBDEV_OK;
}

/* Get a byte number index from planar buffer */
static UInt8 GetDataByte(UInt8 *Y, UInt8 *U, UInt8 *V, UInt8 index)
{
    if (index & 0x1)
        return Y [index >> 1];
    else if (index & 0x2)
        return V [index >> 2];
    else 
        return U [index >> 2];
} 

extern tmLibdevErr_t
saa7113GetSlicedData(pboardVIDec_t pVD, UInt8 *Y, UInt8 *U, UInt8 *V, tmVideoDataService_t service, 
                     unsigned int size, UInt8 *data, UInt8 *dataSize)
{  	

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetSupportedDataServices(tmVideoDataService_t fieldOne[], tmVideoDataService_t fieldTwo[], UInt8 tblSize)
{
    int i;

        /* Write supported data services into arrays */
        for (i = 0; i < tblSize; i++)
    {
        if (i < 2)
        {
                    /* No data slicing allowed in first two lines  */
            fieldOne [i] = fieldTwo [i] = vdsNone; 
        }
        else
        {
                    /* Allow all kind of data services   */
            fieldOne [i] = fieldTwo [i] = (tmVideoDataService_t) (vdsEuroTeleText | vdsEuroClosedCaption | vdsVPS | vdsWSS |
                                          vdsUSTeleText | vdsUSClosedCaption | vdsTeleText | vdsVITC_EBU |
                                          vdsVITC_SMPTE | vdsUSNABTS | vdsMoji | vdsJapFormatSwitch);
        }
        }
                                                                                                        
    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetDataServices(pboardVIDec_t pVD, tmVideoDataService_t fieldOne[], tmVideoDataService_t fieldTwo[], UInt8 tblSize)
{
    /* Equivalent to Video DecHAL VideoDecOpenTT */

    tmLibdevErr_t nReturn = TMLIBDEV_OK;

    int nCount;                                 /* Counter */
    int nLoop;                                  /* Counter */
    UInt8 ucReg;                                /* Value to program */

    int nProgrammableTextDataType;              /* Programmable text data type */
    int nAllowedDataTypes;

    if (tblSize > 25)                           /* Check upper bound */
    {
        tblSize = 25;
    }

    nProgrammableTextDataType = 0;
    nAllowedDataTypes         = vdsEuroTeleText | vdsEuroClosedCaption | vdsVPS | vdsWSS |
                                vdsUSTeleText | vdsUSClosedCaption | vdsTeleText | vdsVITC_EBU |
                                vdsVITC_SMPTE | vdsUSNABTS | vdsMoji | vdsJapFormatSwitch;

    /* Collect all teletext standards to be used */
    for (nCount = 0; nCount < tblSize; nCount++)
        nProgrammableTextDataType |= (fieldOne[nCount] | fieldTwo[nCount]);

    if (nProgrammableTextDataType & ~nAllowedDataTypes)
            return BOARD_ERR_VAL_OUT_OF_RANGE;  /* Illegal standard requested */

    for (nCount = 2; nCount < tblSize; nCount++)
    {
        ucReg = 0xff;                           /* Standard value.*/
                                                /* Do not acquire. */
        for(nLoop = 0;                          /* Search for programm value. */
            (nLoop < MAX_TT) &&                 /* Search odd table */
            (Convert7113TT[nLoop].nBitMask != fieldOne[nCount]);
            nLoop++);

        if (nLoop < MAX_TT)                     /* Found ! */
            ucReg = ucReg & ~0xf0 | (Convert7113TT[nLoop].nNibble << 4);

        for(nLoop = 0;                          /* Search for programm value. */
            (nLoop < MAX_TT) &&                 /* Search even table */
            (Convert7113TT[nLoop].nBitMask != fieldTwo[nCount]);
            nLoop++);

        if (nLoop < MAX_TT)                     /* Found ! */
            ucReg = ucReg & ~0x0f | Convert7113TT[nLoop].nNibble;

        if (!SetReg(pVD, LCR2 + nCount - 2, ucReg))  /* Check device access */
            return (tmLibdevErr_t) lastI2cError;
    }

    SetReg(pVD, FC, 0);                              /* Set framing code */

    return nReturn;
}

extern tmLibdevErr_t   
saa7113GetSlicerLineFlags(pboardVIDec_t pVD, Bool fieldOne[], Bool fieldTwo[], UInt8 tblSize)
{
    /* Equivalent to Video DecHAL VideoDecGetTTLineFlags */

    /* Line status is not supported by SAA7113 -> indicate error */

    return BOARD_ERR_UNSUPPORTED_STANDARD;
}

extern tmLibdevErr_t
saa7113EnableSlicing(pboardVIDec_t pVD, Bool enable)
{
    /* Equivalent to Video DecHAL VideoDecEnableTT */
    unsigned int sStatus;

    /* There's no way to turn on/off the 7113 slicer specificly */
    /* Just ignore this command */

    /* Check if copy protected source connected. If so -> switch source type */
    saa7113GetStatus(pVD, vstCopy, &sStatus);
 
    if (sStatus)
        saa7113SetSourceType(pVD, vsoTV);
    else
        saa7113SetSourceType(pVD, vsoVCR);

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetSlicerVideoStandard(pboardVIDec_t pVD, tmVideoAnalogStandard_t standard)
{
    /* Equivalent to Video DecHAL VideoDecSetTTVideoStandard */

  

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetSlicerVideoStandard(pboardVIDec_t pVD, tmVideoAnalogStandard_t *standard)
{
    /* Equivalent to Video DecHAL VideoDecGetTTVideoStandard */

    UInt8 ucVal;

    if (!GetReg(pVD, AC1, &ucVal))                   /* Read old value, check only */
        return (tmLibdevErr_t) lastI2cError;               /* first access */

    if (ucVal & 0x80)
    {
        /* 60 Hz standards */
        *standard = vasNTSC;
    }
    else
    {
        /* 50 Hz standards */
        *standard = vasPAL;
    }

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113ToggleFieldID(pboardVIDec_t pVD, Bool toggle)
{ 
    /* Equivalent to Video DecHAL VideoDecHalToggleTTFieldID */

    UInt8 ucValue;

    if (!GetReg(pVD, HVOFF, &ucValue))               /* check only first access */
        return (tmLibdevErr_t) lastI2cError;

    SetReg(pVD, HVOFF, ucValue & ~0x80 | (toggle ? 0x80 : 0x00));

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetSlicerInput(pboardVIDec_t pVD, unsigned int num)
{
    /* Equivalent to Video DecHAL VideoDecSetTTVideoSource */

    UInt8 ucVal;

    /* Slicer input on 7113 cannot differ from basic video source */
    /*  -> make sure they are identical */

    if (!GetReg(pVD, AnalogInputControl1, &ucVal))
        return (tmLibdevErr_t) lastI2cError;               

    /* Return error if the argument does not match current video source */
    if ((ucVal & 0x0f) != num)
        return BOARD_ERR_VAL_OUT_OF_RANGE;
    else
        return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetSlicerInput(pboardVIDec_t pVD, unsigned int *num)
{ 
    /* Equivalent to Video DecHAL VideoDecGetTTVideoSource */

    UInt8 ucVal;

    /* Read video input source from decoder */
    if (!GetReg(pVD, AnalogInputControl1, &ucVal))
        return (tmLibdevErr_t) lastI2cError;               

    *num = ucVal & 0x0F;
    
    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetVideoColor(pboardVIDec_t pVD, tmVideoColor_t color, unsigned int val)
{
    /* Equivalent to Video DecHAL VideoDecSetVideoColor */

    UInt8 ucVal;

    switch (color)
    {
        case vctBrightness:
            if (val > 255)
                return BOARD_ERR_VAL_OUT_OF_RANGE;
            else
            {                                   /* Check only first access */
                if (!SetReg(pVD, LuminanceBrightness, (UInt8)val))
                    return (tmLibdevErr_t) lastI2cError;
            }
            break;
        case vctContrast:
            if (val > 127)
                return BOARD_ERR_VAL_OUT_OF_RANGE;
            else
            {                                   /* Check only first access */
                if (!SetReg(pVD, LuminanceContrast, (UInt8)val))
                    return (tmLibdevErr_t) lastI2cError;
            }
            break;
        case vctSaturation:
            if (val > 127)
                return BOARD_ERR_VAL_OUT_OF_RANGE;
            else
            {                                   /* Check only first access */
                if (!SetReg(pVD, ChromaSaturation, (UInt8)val))
                    return (tmLibdevErr_t) lastI2cError;
            }
            break;
        case vctHue:
            if (val > 255)
                return BOARD_ERR_VAL_OUT_OF_RANGE;
            else
            {                                   /* Check only first access */
                if (!SetReg(pVD, ChromaHueControl, (UInt8)val))
                    return (tmLibdevErr_t) lastI2cError;
            }
            break;
        case vctSharpness:
            if (val > 3)
                return BOARD_ERR_VAL_OUT_OF_RANGE;
            else
            {                                   /* Check only first access */
                if (!GetReg(pVD, LuminanceControl, &ucVal))
                    return (tmLibdevErr_t) lastI2cError;
                SetReg(pVD, LuminanceControl,
                       (UInt8)(ucVal & ~0x03 | (val & 0x03)));
            }
            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetVideoColor(pboardVIDec_t pVD, tmVideoColor_t color, unsigned int *val)
{
    /* No equivalent in Video DecHAL */

    UInt8 ucVal;
    UInt8 ucMask;
    UInt8 subAddr;

    switch (color)
    {
        case vctBrightness:
            subAddr = LuminanceBrightness;
            ucMask  = 0xFF;
            break;

        case vctContrast:
            subAddr = LuminanceContrast;
            ucMask  = 0x7F;
            break;

        case vctSaturation:
            ucMask  = 0x7F;
            subAddr = ChromaSaturation;
            break;

        case vctHue:
            subAddr = ChromaHueControl;
            ucMask  = 0xFF;
            break;

        case vctSharpness:
            subAddr = LuminanceControl;
            ucMask  = 0x03;
            break;

        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    if (!GetReg (pVD, subAddr, &ucVal))
        return (tmLibdevErr_t) lastI2cError;

    *val = ucVal & ucMask;

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetAnalogInput(pboardVIDec_t pVD, unsigned int num)
{
    /* Similar to Video DecHAL VideoDecSetVideoSource */

    UInt8 ucVal;

/* Set Input mode -------------------------------------------------------------- */
                                                /* Check only first access */
    if (!GetReg(pVD, AnalogInputControl1, &ucVal))

⌨️ 快捷键说明

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