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

📄 saa7113.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    } /* 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
saa7113GetStandard(tmVideoAnalogStandard_t * std)
{
    return saa7113GetStandardM (&defaultVD[0], std);
}

tmLibdevErr_t 
saa7113GetAdapterVideoStandard(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, &param, &inputMode) != TMLIBDEV_OK)
        return BOARD_ERR_INVALID_ADAPTER_INSTANCE;

    /* Set input of video accordingly */
    saa7113SetAnalogInput (pVD, inputMode);

    return saa7113GetStandardM (pVD, std);
}

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

tmLibdevErr_t 
saa7113ConfigureM(pboardVIDec_t pVD, UInt32 subaddr, UInt32 value)
{
    tmLibdevErr_t rval = TMLIBDEV_OK;

    rval |= iicWriteReg(pVD->slaveAddr, subaddr, value);
    return (tmLibdevErr_t) rval;
}

tmLibdevErr_t 
saa7113Configure(UInt32 subaddr, UInt32 value)
{
    return saa7113ConfigureM(&defaultVD[0], subaddr, value);
}

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

extern      tmLibdevErr_t
saa7113GetBrightnessM(pboardVIDec_t pVD, UInt * val)
{
    return iicReadReg(pVD->slaveAddr, LuminanceBrightness, val);
}

extern      tmLibdevErr_t
saa7113GetBrightness(UInt * val)
{
    return saa7113GetBrightnessM(&defaultVD[0], val);
}

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

extern      tmLibdevErr_t
saa7113SetBrightnessM(pboardVIDec_t pVD, UInt val)
{
    if (val > 255)
        return BOARD_ERR_VAL_OUT_OF_RANGE;

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

extern      tmLibdevErr_t
saa7113SetBrightness(UInt val)
{
    return saa7113SetBrightnessM(&defaultVD[0], val);
}

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

extern      tmLibdevErr_t
saa7113GetContrastM(pboardVIDec_t pVD, UInt * val)
{
    return iicReadReg(pVD->slaveAddr, LuminanceContrast, val);
}

extern      tmLibdevErr_t
saa7113GetContrast(UInt * val)
{
    return saa7113GetContrastM(&defaultVD[0], val);
}

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

extern      tmLibdevErr_t
saa7113SetContrastM(pboardVIDec_t pVD, UInt val)
{
    if (val > 127)
        return BOARD_ERR_VAL_OUT_OF_RANGE;

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

extern      tmLibdevErr_t
saa7113SetContrast(UInt val)
{
    return saa7113SetContrastM(&defaultVD[0], val);
}

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

extern      tmLibdevErr_t
saa7113GetSaturationM(pboardVIDec_t pVD, UInt * val)
{
    return iicReadReg(pVD->slaveAddr, ChromaSaturation, val);
}

extern      tmLibdevErr_t
saa7113GetSaturation(UInt * val)
{
    return saa7113GetSaturationM(&defaultVD[0], val);
}

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

extern      tmLibdevErr_t
saa7113SetSaturationM(pboardVIDec_t pVD, UInt val)
{
    if (val > 127)
        return BOARD_ERR_VAL_OUT_OF_RANGE;

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

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

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

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

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

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

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

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

extern      tmLibdevErr_t
saa7113SetHue(UInt 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 */
{
    UInt 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, UInt *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, 
                     UInt size, UInt8 *data, UInt8 *dataSize)
{
    UInt index = 0;
    UInt bytesToFind;
    UInt byteNr;

    /* - Search video buffer for sliced data */
    /* - Extract and copy sliced data from planar buffers into output buffer */
    /* - Code not optimized for performance */

    /* Assume no data will be found  */
    *dataSize = 0;

    /* First implementation does support Closed Caption, only */
    switch (service)
    {
    case vdsUSClosedCaption:
    case vdsEuroClosedCaption:
        bytesToFind = 2;
        break;

        case vdsVPS:
        case vdsJapFormatSwitch:
        bytesToFind = 26;
        break;

        case vdsWSS:
        bytesToFind = 14;
        break;

        case vdsTeleText:
        case vdsEuroTeleText:
        bytesToFind = 42;
        break;

        case vdsUSNABTS:
        bytesToFind = 33;
        break;

        case vdsUSTeleText:
        bytesToFind = 34;
        break;

        case vdsVITC_EBU:
        case vdsVITC_SMPTE:
        bytesToFind = 11;
        break;

        case vdsMoji:
        bytesToFind = 35;
        break;

    default:
            // Not supported, yet
        return BOARD_ERR_VAL_OUT_OF_RANGE;
        }
 
    /* Search for data header 0x53 */
    while (GetDataByte(Y, U, V, index++) != 0x53)
        if (index > size)
            return TMLIBDEV_OK;
           
    /* Skip next three bytes */
    index += 3;

    /* Find up to maximum number of data bytes */
    for (byteNr = 0; byteNr < bytesToFind; byteNr++)
        {
        UInt8 nibble1;
        UInt8 nibble2;
                
        /* Skip zeroes in data stream */
        while ((nibble1 = GetDataByte(Y, U, V, index++)) == 0)
            if (index > size)
                return TMLIBDEV_OK;

        while ((nibble2 = GetDataByte(Y, U, V, index++)) == 0)
            if (index > size)
                return TMLIBDEV_OK;
                
        data [byteNr] = (nibble1 >> 2) & 0xF;
        data [byteNr] |= ((nibble2 << 2) & 0xF0);
                 
        *dataSize = byteNr + 1;
        }
    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
saa7113GetStatus(pboardVIDec_t pVD, tmVideoStatusType_t type, UInt *pState)
{
    /* Equivalent to Video DecHAL VideoDecGetStatus */

    UInt8 ucStatus;
    UInt8 ucValue;

    switch (type)
    {
        case vstLocked:                         /* HIGH unlocked, LOW locked */
            if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=1 */
                return IIC_ERR_TIMEOUT;
            SetReg(pVD, OutputControl3, ucValue & ~0x10 | 0x10);

            GetReg(pVD, StatusByte, &ucStatus);

            *pState = (ucStatus & 0x40) ? False : True;
            break;
        case vstReady:                          /* HIGH locked, LOW unlocked */
            if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=0 */
                return IIC_ERR_TIMEOUT;
            SetReg(pVD, OutputControl3, ucValue & ~0x10 | 0x00);

            GetReg(pVD, StatusByte, &ucStatus);

            *pState = (ucStatus & 0x01) ? True : False;
            break;
        case vstSyncLock:                       /* HIGH unlocked, LOW locked */
            if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=0 */
                return IIC_ERR_TIMEOUT;
            SetReg(pVD, OutputControl3, ucValue & ~0x10 | 0x00);

            GetReg(pVD, StatusByte, &ucStatus);

            *pState = (ucStatus & 0x40) ? False : True;
            break;
        case vstCopy:                           /* HIGH copy protected, */
                                                /* LOW not copy protected */
            if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=0 */
                return IIC_ERR_TIMEOUT;
            SetReg(pVD, OutputControl3, ucValue & ~0x10 | 0x00);

            GetReg(pVD, StatusByte, &ucStatus);

            *pState = (ucStatus & 0x02) ? True : False;
            break;
        case vstColorSignal:                    /* HIGH color, LOW no color */

            if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=1 */
                return IIC_ERR_TIMEOUT;
            SetReg(pVD, OutputControl3, ucValue & ~0x10 | 0x10);

            GetReg(pVD, StatusByte, &ucStatus);

            *pState = (ucStatus & 0x01) ? True : False;
            break;
        case vstFrequency:                      /* HIGH 60Hz, LOW 50Hz */
            if(!GetReg(pVD, OutputControl3, &ucValue)) /* Set OLDSB=1 */
                return IIC_ERR_TIMEOUT;
            SetReg(pVD, OutputControl3, ucValue & ~0x10 | 0x10);

            GetReg(pVD, StatusByte, &ucStatus);

            *pState = (ucStatus & 0x20) ? 60 : 50;
            break;
        case vstPowerUp:

⌨️ 快捷键说明

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