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

📄 saa7114.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
saa7114SetSourceType(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
saa7114GetSourceType(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
saa7114SetOutputFormat(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;
    }

    /* Set output format for task A */
    if (GetReg(pVD, AIPortFormat, &ucVal))
        SetReg(pVD, AIPortFormat, (ucVal & ~0xc7) | (ucFormat & 0xc7));
    else
        return (tmLibdevErr_t) lastI2cError;

  return TMLIBDEV_OK;
}

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

    *format = vdfYUV422Sequence; 
    return TMLIBDEV_OK;
}

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

    /* Scaling not yet supported by this implementation -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

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

    /* Scaling not yet supported by this implementation -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

extern tmLibdevErr_t
saa7114GetDefaultAcquisitionWnd(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
saa7114SetOutputSize(pboardVIDec_t pVD, UInt width, UInt height)
{
    /* Equivalent to Video DecHAL VideoDecSetOutputVideoSize */

    /* Scaling not yet supported by this implementation -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

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

    /* Scaling not yet supported by this implementation -> return error */
    return BOARD_ERR_UNSUPPORTED_FUNCTION;
}

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

    UInt8 ucValue;

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

    SetReg(pVD, IPortIODelay, (ucValue & ~0x03) | (disable ? 0x00 : 0x01));

    return TMLIBDEV_OK;
}

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

    UInt8 ucValue;

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

    SetReg(pVD, PowerSaveControl, (ucValue & ~0xe3) | (enable ? 0x03 : 0xe0));

    return TMLIBDEV_OK;
}

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

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

    return TMLIBDEV_OK;
}

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

    UInt  ucNum;
    UInt8 ucValue;
    UInt8 ucMSBValue;
    saa7114GetGPIOCount(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, RTSignalControl, &ucValue))
                return (tmLibdevErr_t) lastI2cError;

            SetReg(pVD, RTSignalControl, ucValue & ~0x0f | 0x01);/* constant LOW */

            GetReg(pVD, ModeDelayControl, &ucValue);   /* Polarity */
            SetReg(pVD, ModeDelayControl, ucValue & ~0x08 | (state ? 0x08 :0x00));
            break;
        case 1:                                 /* RTS1 */
                                                /* Check only first access */
            if (!GetReg(pVD, RTSignalControl, &ucValue))
                return (tmLibdevErr_t) lastI2cError;

            SetReg(pVD, RTSignalControl, ucValue & ~0xf0 | 0x10);/* constant LOW */

            GetReg(pVD, ModeDelayControl, &ucValue);   /* Polarity */
            SetReg(pVD, ModeDelayControl, ucValue & ~0x40 | (state ? 0x40 :0x00));
            break;
        case 2:                                 /* IGP0 */
                                                /* Check only first access */
            if (!GetReg(pVD, IPortSignalDef, &ucValue))
                return (tmLibdevErr_t) lastI2cError;

            SetReg(pVD, IPortSignalDef, ucValue & ~0x30 | 0x30);/* constant LOW */
            GetReg(pVD, IPortFIFOFlag, &ucMSBValue);
            SetReg(pVD, IPortFIFOFlag, ucMSBValue & ~0x10 | 0x00);/* constant LOW */

            GetReg(pVD, IPortSignalPol, &ucValue);   /* Polarity */
            SetReg(pVD, IPortSignalPol, ucValue & ~0x08 | (state ? 0x01 :0x00));
            break;
        case 3:                                 /* IGP1 */
                                                /* Check only first access */
            if (!GetReg(pVD, IPortSignalDef, &ucValue))
                return (tmLibdevErr_t) lastI2cError;

            SetReg(pVD, IPortSignalDef, ucValue & ~0xc0 | 0xc0);/* constant LOW */
            GetReg(pVD, IPortFIFOFlag, &ucMSBValue);
            SetReg(pVD, IPortFIFOFlag, ucMSBValue & ~0x20 | 0x00);/* constant LOW */

            GetReg(pVD, IPortSignalPol, &ucValue);   /* Polarity */
            SetReg(pVD, IPortSignalPol, ucValue & ~0x10 | (state ? 0x01 :0x00));
            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    return TMLIBDEV_OK;
}

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

    UInt  ucNum;
    UInt8 ucValue;
    UInt8 ucMSBValue;
    UInt8 ucPolValue;

    saa7114GetGPIOCount(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, RTSignalControl, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            GetReg(pVD, ModeDelayControl, &ucPolValue);

            if (((ucValue & 0x0f) ==  0x01) &&  /* constant LOW */
                ((ucPolValue & 0x08) == 0x08))  /* invert polarity */
                *state = True;                  /* Overwrite FALSE */
            break;
        case 1:                                 /* RTS1 */
                                                /* Check only first access */
            if (!GetReg(pVD, RTSignalControl, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            GetReg(pVD, ModeDelayControl, &ucPolValue);

            if (((ucValue & 0xf0) ==  0x10) &&  /* constant LOW */
                ((ucPolValue & 0x40) == 0x40))  /* invert polarity */
                *state = True;                  /* Overwrite FALSE */

            break;
        case 2:                                 /* IGP0 */
                                                /* Check only first access */
            if (!GetReg(pVD, IPortSignalDef, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            GetReg(pVD, IPortSignalDef, &ucMSBValue);

            GetReg(pVD, IPortSignalPol, &ucPolValue);/* Signal polarity */

            if ( ((ucMSBValue & 0x10) == 0x00) &&
                 ((ucValue & 0x30) == 0x30) &&
                 ((ucPolValue & 0x08) == 0x08) )
                *state = True;                  /* Overwrite FALSE */

            break;
        case 3:                                 /* IGP1 */
                                                /* Check only first access */
            if (!GetReg(pVD, IPortSignalDef, &ucValue))
                return (tmLibdevErr_t) lastI2cError;
            GetReg(pVD, IPortSignalDef, &ucMSBValue);

            GetReg(pVD, IPortSignalPol, &ucPolValue);/* Signal polarity */

            if ( ((ucMSBValue & 0x20) == 0x00) &&
                 ((ucValue & 0xc0) == 0xc0) &&
                 ((ucPolValue & 0x10) == 0x10) )
                *state = True;                  /* Overwrite FALSE */

            break;
        default:
            return BOARD_ERR_VAL_OUT_OF_RANGE;
    }

    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7114OpenVBI(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 */
        saa7114GetStandardM (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
saa7114EnableVBI(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++)
        {
           

⌨️ 快捷键说明

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