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

📄 saa7113.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
            GetReg(pVD, DR, &ucStatus);

            *pState = 0;                        /* Clear all */

            if (ucStatus & 0x04)                /* Closed caption found */
                *pState |=
                    (vdsEuroClosedCaption | vdsUSClosedCaption);
            if (ucStatus & 0x08)                /* Widescreen signal found */
                *pState |= vdsWSS;
            if (ucStatus & 0x10)                /* VPS found */
                *pState |= vdsVPS;
            if (ucStatus & 0x60)                /* others found */
                *pState |= (vdsEuroTeleText |
                            vdsUSTeleText |
                            vdsTeleText |
                            vdsVITC_EBU |
                            vdsVITC_SMPTE |
                            vdsUSNABTS |
                            vdsMoji |
                            vdsJapFormatSwitch);
            break;
        case vstFidText:
            GetReg(pVD, LN1, &ucStatus);
            *pState = (ucStatus & 0x20) ? 1 : 2;
            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    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 */
    UInt 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 */

    UInt8 ucVal;
    UInt8 ucValHOff;

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

    switch (standard)
    {
        case vasPAL:                            /* 50 Hz standards */
        case vasSECAM:
                SetReg(pVD, AC1, ucVal & ~0x80 | 0x00);
                SetReg(pVD, VOFF, 7);
                SetReg(pVD, HOFF, 0x54);       
                SetReg(pVD, HVOFF, ucValHOff & ~0x07 | 0x03);
            break;
        case vasNTSC:                           /* 60 Hz standards */
                SetReg(pVD, AC1, ucVal & ~0x80 | 0x80);
                SetReg(pVD, VOFF, 10);
                SetReg(pVD, HOFF, 0x54);         
                SetReg(pVD, HVOFF, ucValHOff & ~0x07 | 0x03);
            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    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, UInt 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, UInt *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, UInt 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, UInt *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, UInt num)
{
    /* Similar to Video DecHAL VideoDecSetVideoSource */

    UInt8 ucVal;

/* Set Input mode -------------------------------------------------------------- */
                                                /* Check only first access */
    if (!GetReg(pVD, AnalogInputControl1, &ucVal))
        return (tmLibdevErr_t) lastI2cError;               /* Switch input mode (line) */
    SetReg(pVD, AnalogInputControl1, ucVal & ~0x0f | (num & 0x0f));

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetAnalogInput(pboardVIDec_t pVD, UInt *num)
{ 
    /* Similar to Video DecHAL VideoDecGetVideoSource */

    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
saa7113SetStandard(pboardVIDec_t pVD, tmVideoAnalogStandard_t standard)
{ 
    /* Equivalent to Video DecHAL SetVideoStandard */

    UInt8 ucVal;
                                                 /* Only check first access */
    if (GetReg(pVD, ChromaControl, &ucVal))      /* Read old value */
    {

⌨️ 快捷键说明

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