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

📄 philips_iref.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    
    __irefAiInitialized         = True;
    __irefAiCurrentPcmFormat    = (tmAudioPcmFormat_t)param->audioSubtypeFormat;
    __irefSampleRate            = param->sRate;

    return TMLIBDEV_OK;
}

/*******************************************************/
static tmLibdevErr_t iref_AI_term(void)
{
    /* reset static variables */
    __irefAiInitialized             = False;
    __irefAiRunning                 = False;
    __irefAiNeedToConfigureInput    = False;
    __irefAiCurrentPcmFormat        = apfNone;
    __irefAiInput                   = aaaLineInput;
    __irefAiAd1847Input             = AD1847_SRC_LINE1;
    __irefAiLGain                   = 0;
    __irefAiRGain                   = 0;
    
    /* reset audio in */
    aiRESET();

    return TMLIBDEV_OK;
}

/*******************************************************/
static tmLibdevErr_t iref_AI_start(void)
{
    if (!__irefAiRunning)
    {
        if (__irefAoRunning)
        {
            /* start audio in unit */
            aiEnableCAP_ENABLE();
            __irefAiRunning = True;
        }
        else
        {
            __irefNeedToStartAi = True;
        }
    }
    return TMLIBDEV_OK;
}    

/*******************************************************/
static tmLibdevErr_t iref_AI_stop(void)
{
    __irefAiRunning     = False;
    __irefNeedToStartAi = False;
    aiDisableCAP_ENABLE();

    return TMLIBDEV_OK;
}    

/*******************************************************/
static tmLibdevErr_t iref_AI_SetInput(tmAudioAnalogAdapter_t input)
{
    if (input == __irefAiInput)
    {
        /* the input did not change, no action required */
        return TMLIBDEV_OK;
    }
        
    switch (input)
    {
    case aaaLineInput:
        __irefAiAd1847Input = AD1847_SRC_LINE1;
        break;
    case aaaMicInput:
        __irefAiAd1847Input = AD1847_SRC_AUX1;
        break;
    case aaaAuxInput1:
        __irefAiAd1847Input = AD1847_SRC_LINE2;
        break;
    default:
        return AIO_ERR_UNSUPPORTED_INPUT;
        /* no break ... statement unreachable */
    }
    
    __irefAiInput = input;

    if (__irefAoRunning)
    {
        return ad1847ConfigureInput(__irefAiAd1847Input, __irefAiLGain, __irefAiRGain);
    }
    else
    {
        __irefAiNeedToConfigureInput = True;
    }
    return TMLIBDEV_OK;
}

/*******************************************************/
static tmLibdevErr_t iref_AI_GetInput(tmAudioAnalogAdapter_t * input)
{
    tmAssert(input, TMLIBDEV_ERR_NULL_PARAMETER);
    
    if (__irefAiCurrentPcmFormat == apfNone)
        return TMLIBDEV_OK;

    *input = __irefAiInput;

    return TMLIBDEV_OK;
}

/*******************************************************/
static tmLibdevErr_t iref_AI_SetVolume(Int lGain, Int rGain)
{
    Int     rval = TMLIBDEV_OK;
    Int     rvalConfig;
    
    if (lGain < AD1847_INPUT_MIN_VOLUME)
    {
        lGain = AD1847_INPUT_MIN_VOLUME;
        rval =  AIO_ERR_VOLUME_TOO_LOW;
    }
    if (rGain < AD1847_INPUT_MIN_VOLUME)
    {
        rGain = AD1847_INPUT_MIN_VOLUME;
        rval =  AIO_ERR_VOLUME_TOO_LOW;
    }
    
    if (lGain > AD1847_INPUT_MAX_VOLUME)
    {
        lGain = AD1847_INPUT_MAX_VOLUME;
        rval =  AIO_ERR_VOLUME_TOO_HIGH;
    }
    if (rGain > AD1847_INPUT_MAX_VOLUME)
    {
        rGain = AD1847_INPUT_MAX_VOLUME;
        rval = AIO_ERR_VOLUME_TOO_HIGH;
    }
    
    __irefAiLGain = lGain;
    __irefAiRGain = rGain;

    if (__irefAoRunning)
    {
        rvalConfig = ad1847ConfigureInput(__irefAiAd1847Input, lGain, rGain);
        if (rvalConfig)
        {
            return rvalConfig; 
        }
    }
    else
    {
        __irefAiNeedToConfigureInput = True;
    }
    
    return rval;
}

/*******************************************************/
static tmLibdevErr_t iref_AI_GetVolume(Int * lGain, Int * rGain)
{
    tmAssert(lGain, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(rGain, TMLIBDEV_ERR_NULL_PARAMETER);

    * lGain = __irefAiLGain;
    * rGain = __irefAiRGain;

    return TMLIBDEV_OK;
}

/***********************************************************************
 * Convert a floating point sample rate value
 * to a 32 bit frequency control value for the DDS.
 *
 * NOTE:  YOU MUST SET THE sckdiv and wsdiv FIELDS FOR THIS TO WORK!
 *
 * Accurate to .5 ppm.
 * The DDS can do better than this, but 64 bit math is
 *  required to use this interface.
 */
static tmLibdevErr_t iref_AI_SetSRate(Float sRate)
{
    Float               val;
    tmLibdevErr_t       rval;

    if (__irefSampleRate == sRate)
        return TMLIBDEV_OK;
        
    __irefSampleRate = sRate;    
    
    val = hertz2Control(sRate, 512, 1, 1); /* we are using the AD1847 at 512 fs */

    aoSetFREQ((UInt) val);
    aiSetFREQ((UInt) val);

    /* we have to reset the AD1847 after changing the audio clock */
    if (__irefAoRunning)
    {
        /*reset AD1847 */
        rval = ad1847Reset(sRate);
        if (rval != TMLIBDEV_OK)
            return rval;
    }
    else
    {
        __irefNeedAD1847Reset = True;
    }
    
    return TMLIBDEV_OK;
}

/* audio in runs at the same clock as audio out */
static tmLibdevErr_t iref_AI_GetSRate(Float * sRate)
{
    UInt        freq    = MMIO(AO_FREQ);
    Float       rate;

    tmAssert(sRate, TMLIBDEV_ERR_NULL_PARAMETER);
    
    rate = (Float) freq * __irefCPUClockFrequency / 1431655765.0;
    rate = rate / 512.0;  /* we use the AD1847 at 512 fs */

    *sRate = rate;

    return TMLIBDEV_OK;
}

/***********************************************************************
 * Convert a floating point sample rate value
 * to a 32 bit frequency control value for the DDS.
 *
 * Accurate to .5 ppm.
 * The DDS can do better than this, but 64 bit math is
 *  required to use this interface.
 */
static UInt hertz2Control(Float rate, Int sckdiv, Int wsdiv, Int sfdiv)
{
    /* workaround for bug # 3013 */
    if (__irefTMIsNot1S  && (sckdiv > 2.0) && (__irefAoCurrentPcmFormat == apfFiveDotOne16))
    {
        sckdiv -= 2.0;
    }
   
    rate = rate * (Float) sckdiv *(Float) wsdiv *(Float) sfdiv;
    /* clock freq is in hz.  Math is 32 bit- should be 64 bit! */
    return ((UInt) (0.5 + (1431655765.0 * (rate / __irefCPUClockFrequency))));
}


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

static tmLibdevErr_t 
iref_VI_Init (pboardVIParam_t param)
{
    tmLibdevErr_t err;
    if ((err = saa7111InitM(&iref_vi.vDec, param)) != TMLIBDEV_OK)
        return err;
    else
        Is7111Initialized = True;
    return TMLIBDEV_OK; 
}

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

static tmLibdevErr_t 
iref_VI_GetStandard(tmVideoAnalogStandard_t *standard)
{
    boardVIParam_t param; 
    tmLibdevErr_t  err;

    if (Is7111Initialized == False)
    {
        param.videoStandard = vasPAL; /* this parameter is ignored */
        /* 
         * the following implies that the detection function will not work
         * if the adapterType is not Svideo
         * Svideo is the default in this case, because HSDB have
         * only a Svideo connector (even if CVBS is available)
         */
        param.adapterType     = vaaSvideo; /* FIXME */
        param.adapterInstance = 0;
        param.adapterType   = vaaCVBS;
        param.mmioBase      = iref_vi.mmioBase;
        if ((err = iref_vi.init_func(&param)) != TMLIBDEV_OK)
        {
            return err;
        }
    }

    return saa7111AGetStandardM(&iref_vi.vDec, standard);
}

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

static tmLibdevErr_t 
iref_VI_GetAdapterStandard(pboardVIDec_t pVD, tmVideoAnalogAdapter_t adapter, UInt adapterNum, tmVideoAnalogStandard_t *standard)
{
    boardVIParam_t param;
    tmLibdevErr_t  err;

    if (Is7111Initialized == False)
    {
        param.videoStandard = vasPAL; /* this parameter is ignored */
        /* 
         * the following implies that the detection function will not work
         * if the adapterType is not Svideo
         * Svideo is the default in this case, because HSDB have
         * only a Svideo connector (even if CVBS is available)
         */
        param.adapterType     = adapter; 
        param.adapterInstance = 0;
        param.mmioBase      = iref_vi.mmioBase;
        if ((err = iref_vi.init_func(&param)) != TMLIBDEV_OK)
        {
            return err;
        }
    }

    return saa7111GetAdapterVideoStandard(pVD, adapter, adapterNum, standard);
}
/******************************************************************************/

static tmLibdevErr_t 
iref_VI_Configure(UInt32 subaddr, UInt32 value)
{
    return saa7111ConfigureM(&iref_vi.vDec, subaddr, value);
}

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

static      tmLibdevErr_t
iref_VI_SetBrightness(UInt val)
{
    return saa7111SetBrightnessM(&iref_vi.vDec, val);
}

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

static      tmLibdevErr_t
iref_VI_SetContrast(UInt val)
{
    return saa7111SetContrastM(&iref_vi.vDec, val);
}

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

static      tmLibdevErr_t
iref_VI_SetSaturation(UInt val)
{
    return saa7111SetSaturationM(&iref_vi.vDec, val);
}

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

static      tmLibdevErr_t
iref_VI_SetHue(UInt val)
{
    return saa7111SetHueM(&iref_vi.vDec, val);
}

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

TSA_COMP_DEF_O_COMPONENT( Philips_Iref, 
                          TSA_COMP_BUILD_ARG_LIST_1("bsp/boardID"), 
                          iref_board_activate);

⌨️ 快捷键说明

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