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

📄 saa7113.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
        ucVal &= ~0x73;                          /* Delete video standard bits; */
        switch (standard)
        {
            case vasNTSC:
            case vasPAL:
                SetReg(pVD, ChromaControl, ucVal | 0x01);
                
                GetReg(pVD, LuminanceControl, &ucVal);
                SetReg(pVD, LuminanceControl, (ucVal & ~0x03) | 0x01);  /* Aperture factor */
                
                break;
            case vasSECAM:
                SetReg(pVD, ChromaControl, ucVal | 0x50);    
        
                                GetReg(pVD, LuminanceControl, &ucVal);
                SetReg(pVD, LuminanceControl, (ucVal & ~0x03) | 0x00);  /* Aperture factor */
                
                GetReg(pVD, ChromaGainControl, &ucVal);
                SetReg(pVD, ChromaGainControl, (ucVal & ~0x80) | 0x80); /* Set ACGC=1                */
                break;
            default:
                return BOARD_ERR_VAL_OUT_OF_RANGE;
        }
    }
    else
        return (tmLibdevErr_t) lastI2cError;

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetSourceType(pboardVIDec_t pVD, tmVideoSourceType_t type)
{
    /* Equivalent to Video DecHAL VideoDecSetSourceType */

    UInt8 ucVal;
                                                /* Check only forst access */
    if (GetReg(pVD, SyncControl, &ucVal))       /* Read old value */
    {
        if (type == vsoVCR)
            SetReg(pVD, SyncControl, ucVal & ~0x18 | 0x18);/* Set bit, if VCR */
        else
            SetReg(pVD, SyncControl, ucVal & ~0x18 | 0x00);/* else, clear bit */
    }
    else
        return (tmLibdevErr_t) lastI2cError;

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetSourceType(pboardVIDec_t pVD, tmVideoSourceType_t *type)
{
    /* Equivalent to Video DecHAL VideoDecGetSourceType */

    UInt8 ucVal;
                                                /* Check only forst access */
    if (GetReg(pVD, SyncControl, &ucVal))            /* Read old value */
    {
        if (ucVal & 0x18 == 0x18)
            *type = vsoVCR;
        else     
            *type = vsoTV;
    }
    else
        return (tmLibdevErr_t) lastI2cError;

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetOutputFormat(pboardVIDec_t pVD, tmVideoRGBYUVFormat_t format)
{ 
    /* Equivalent to Video DecHAL VideoDecSetVideoFormat */

    UInt8 ucVal;                                 /* Old value */

    UInt8 ucFormat = 0;                          /* Format bits */

    switch (format)
    {
        case vdfYUV422Sequence : /* VD_D1_CCIR656: */
            ucFormat = 0x00;
            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    if (GetReg(pVD, FormatDelayControl, &ucVal))
        SetReg(pVD, FormatDelayControl, ucVal & ~0x80 | ucFormat);
    else
        return (tmLibdevErr_t) lastI2cError;

  return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetOutputFormat(pboardVIDec_t pVD, tmVideoRGBYUVFormat_t *format)
{
    /* Equivalent to Video DecHAL VideoDecGetVideoFormat */

    *format = vdfYUV422Sequence; 
    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetAcquisitionWnd(pboardVIDec_t pVD, UInt beginX, UInt beginY, UInt endX, UInt endY)
{ 
    /* Equivalent to Video DecHALSetAcquisitionWnd */

    /* Scaling not supported by SAA7113 -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

extern tmLibdevErr_t
saa7113GetAcquisitionWnd(pboardVIDec_t pVD, UInt *beginX, UInt *beginY, UInt *endX, UInt *endY)
{
    /* Equivalent to Video DecHALGetAcquisitionWnd  */

    /* Scaling not supported by SAA7113 -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

extern tmLibdevErr_t
saa7113GetDefaultAcquisitionWnd(pboardVIDec_t pVD, UInt *beginX, UInt *beginY, UInt *endX, UInt *endY)
{ 
    /* Equivalent to Video DecHAL VideoDecGetDefaultAcquisitionWnd */

    switch (pVD->curVideoStandard)
    {
    case vasNTSC:
        /* Set default acquisition window for NTSC */
        *beginX = 6;
        *beginY = 2;
        *endX   = *beginX + 719;
        *endY   = *beginY + 239;
        break;
    case vasPAL:
        /* Set default acquisition window for PAL */
        *beginX = 6;
        *beginY = 1;
        *endX   = *beginX + 719;
        *endY   = *beginY + 287;
        break;
    default:
        return BOARD_ERR_COLOR_STANDARD_NOT_DETECTED;
    }

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetOutputSize(pboardVIDec_t pVD, UInt width, UInt height)
{
    /* Equivalent to Video DecHAL VideoDecSetOutputVideoSize */

    /* Scaling not supported by SAA7113 -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

extern tmLibdevErr_t
saa7113SetInterlaceMode(pboardVIDec_t pVD, Bool interlace)
{
    /* Equivalent to Video DecHAL VideoDecSetInterlacedMode */

    /* Nothing to set for 7113 -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

extern tmLibdevErr_t
saa7113DisableDecoder(pboardVIDec_t pVD, Bool disable)
{
    /* Counterpart to Video DecHAL VideoDecEnableDecoder */

    UInt8 ucValue;

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

    SetReg(pVD, OutputControl1, (ucValue & ~0x0c) | (disable ? 0x00 : 0x0c));

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113EnablePowerSaveMode(pboardVIDec_t pVD, Bool enable)
{ 
    /* Equivalent to Video DecHAL VideoDecPowerSaveMode */

    /* Nothing to set for 7113 -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

extern tmLibdevErr_t
saa7113GetGPIOCount(pboardVIDec_t pVD, UInt *num)
{
    /* Equivalent to Video DecHAL VideoDecGetGPIOCount */

    *num = 3;       /* 3 GPIO pins available */

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetGPIOState(pboardVIDec_t pVD, UInt pin, Bool state)
{
    /* Equivalent to Video DecHAL VideoDecSetGPIOState */

    UInt  ucNum;
    UInt8 ucValue;
    saa7113GetGPIOCount(pVD, &ucNum);           /* Get number of GPIOs */

    if (pin >= ucNum)
        return BOARD_ERR_VAL_OUT_OF_RANGE;

    switch (pin)
    {
        case 0:                                 /* RTS0 */
                                                /* Check only first access */
            if (!GetReg(pVD, OutputControl2, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            SetReg(pVD, OutputControl2, ucValue & ~0x0f | (state ? 0x03 :0x02));
            break;
        case 1:                                 /* RTS1 */
                                                /* Check only first access */
            if (!GetReg(pVD, OutputControl2, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            SetReg(pVD, OutputControl2, ucValue & ~0xf0 | (state ? 0x30 :0x20));
            break;
        case 2:                                 /* GPSW */
                                                /* Check only first access */
            if (!GetReg(pVD, OutputControl1, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            SetReg(pVD, OutputControl1, ucValue & ~0x80 | (state ? 0x80 :0x00));
            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetGPIOState(pboardVIDec_t pVD, UInt pin, Bool *state)
{ 
    /* Equivalent to Video DecHAL VideoDecGetGPIOState */

    UInt  ucNum;
    UInt8 ucValue;
    saa7113GetGPIOCount(pVD, &ucNum);                /* Get number of GPIO's */

    if (pin >= ucNum)
        return BOARD_ERR_VAL_OUT_OF_RANGE;

    /* Assume pin is not set */
    *state = False;

    switch (pin)
    {
        case 0:                                 /* RTS0 */
                                                /* Check only first access */
            if (!GetReg(pVD, OutputControl2, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            if ((ucValue & 0x0f) ==  0x03)
                *state = True;                   /* Overwrite False */
            break;
        case 1:                                 /* RTS1 */
                                                /* Check only first access */
            if (!GetReg(pVD, OutputControl2, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            if ((ucValue & 0xf0) ==  0x30)
                *state = True;                   /* Overwrite False */
            break;
        case 2:                                 /* GPSW */
                                                /* Check only first access */
            if (!GetReg(pVD, OutputControl1, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            if (ucValue & 0x80)
                *state = True;                   /* Overwrite False */
            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113OpenVBI(pboardVIDec_t pVD, UInt sampleFreq, UInt startLine, UInt numLines)
{
    /* Equivalent to Video DecHAL VideoDecOpenVBI */

    tmVideoAnalogStandard_t videoStd;

    /* Only 13.5 MHz sample frequency allowed */
    if (sampleFreq != 0)
        if (sampleFreq != 13500000)
          return BOARD_ERR_VAL_OUT_OF_RANGE;    /* Not valid call */

    if (startLine || numLines)                  /* if not 0 */
    {
                                                /* Check for underflow */
        if ((startLine + numLines) < 2) return BOARD_ERR_VAL_OUT_OF_RANGE;

        /* Get current video standard */
        saa7113GetStandardM (pVD, &videoStd);

        switch (videoStd)
        {
            case vasPAL:                        /* 50 Hz standards */
            case vasSECAM:
                if ((startLine + numLines) > 312) 
                    return BOARD_ERR_VAL_OUT_OF_RANGE;
                break;
            case vasNTSC:                       /* 60 Hz standards */
                if ((startLine + numLines) > 262) 
                    return BOARD_ERR_VAL_OUT_OF_RANGE;
                break;
            default:
                return BOARD_ERR_VAL_OUT_OF_RANGE;
         }
    }

    m_nStartVBILine = startLine;
    m_nNumVBILines = numLines;

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113EnableVBI(pboardVIDec_t pVD, Bool enable)
{ 
    /* Equivalent to Video DecHAL VideoDecEnableVBI */

    UInt8 ucVal;

    int nCount, i;
    tmVideoDataService_t  ucTTMode;
    tmVideoDataService_t  oddTable[24];
    tmVideoDataService_t  evenTable[24];

    SetReg(pVD, VGateStart, 0);                      /* VBI off */
    SetReg(pVD, VGateStop, 0);
    SetReg(pVD, VGateMSB, 0);

    if(!GetReg(pVD, LuminanceControl, &ucVal))   /* Check only first access */
        return (tmLibdevErr_t) lastI2cError;     /* Clear VBLB bit */
    SetReg(pVD, LuminanceControl, ucVal & ~0x08 | 0x00);

    ucTTMode = vdsNone;

    for(i = 0; i < 24; i++)
    {
        oddTable[i] = vdsNone;
        evenTable[i] = vdsNone;
    }

    if(ucTTMode != (UInt8)vdsNone)
    {
        for(nCount = m_nStartVBILine;
            nCount<((int)m_nStartVBILine + (int)m_nNumVBILines);
            nCount++)
        {
            oddTable[nCount] = ucTTMode;
            evenTable[nCount] = ucTTMode;
        }
    }

    saa7113SetDataServices (pVD, oddTable, evenTable, 24);

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113SetVBIMode(pboardVIDec_t pVD, tmVideoVBIMode_t mode)
{ 
    /* Equivalent to Video DecHAL VideoDecSetCurrentVBIMode */

    if (mode == vvmBasebandYuv)
        return TMLIBDEV_OK;
    else
        return  BOARD_ERR_VAL_OUT_OF_RANGE;
}

extern tmLibdevErr_t 
saa7113SetSlicerMode(pboardVIDec_t pVD, tmVideoSlicerMode_t mode)
{ 
    /* Equivalent to Video DecHAL VideoDecSetTTMode */

    /* Only baseband YUV allowed */
    if (mode == vvmBasebandYuv)
        return TMLIBDEV_OK;
    else
        return BOARD_ERR_VAL_OUT_OF_RANGE;
}

extern tmLibdevErr_t
saa7113CloseVBI(pboardVIDec_t pVD)
{
    /* Equivalent to Video DecHAL VideoDecSetTTMode */

    /* Nothing to do here */
    return TMLIBDEV_OK;
}

⌨️ 快捷键说明

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