📄 tda9851.c
字号:
/*
* Copyright (c) 1999 by TriMedia Technologies.
*
* +-------------------------------------------------------------------+
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*
*
* Module name : tda9851.c 1.2
*
* Last update : 18:43:50 - 00/11/09
*
* Description :
*
*/
#include <ops/custom_defs.h>
#include <tmlib/tmtypes.h>
#include <tm1/tmBoardDef.h>
#include <tm1/tsaTvAudDem.h>
#include <tm1/tmIIC.h>
#include <tm1/tmBoard.h>
#include <tm1/tmAvFormats.h>
#include <tm1/tmAssert.h>
#include <tmlib/dprintf.h> /* for debugging with DP(()) */
#include <tm1/tmLibdevErr.h>
#include "tda9851.h"
#include "iicDirection.h"
#define TDA9851_DEFAULT_IIC_REG 0x03 /* mute on, stereo enabled */
typedef struct
{
Bool used;
unitSelect_t id;
UInt iicDirection;
UInt8 iicReg;
}tda9851UnitVars_t, *ptda9851UnitVars_t;
static tda9851UnitVars_t unitVars0 = {False, unit0, 0, TDA9851_DEFAULT_IIC_REG};
static tda9851UnitVars_t unitVars1 = {False, unit1, 0, TDA9851_DEFAULT_IIC_REG};
extern tmLibdevErr_t tda9851Init(unitSelect_t unitID, ptda9851Param_t params)
{
ptda9851UnitVars_t uv;
tmLibdevErr_t err = TMLIBDEV_OK;
Int i;
if (unitVars0.used)
{
if (unitVars1.used)
return -1;
else
uv = &unitVars1;
}
else
uv = &unitVars0;
uv->id = unitID;
uv->used = True;
/* initialize unit variables */
uv->iicDirection = params->iicDirection;
err = iicDirectionSelect(uv->iicDirection);
if (err != TMLIBDEV_OK)
return err;
/* setup for the audio demodulator */
uv->iicReg = TDA9851_DEFAULT_IIC_REG;
err = iicWriteReg(TDA9851_IIC_ADDRESS, -1, uv->iicReg);
if (err != TMLIBDEV_OK)
goto tda9851InitExit;
tda9851InitExit:
iicDirectionUnSelect(uv->iicDirection);
return err;
}
extern tmLibdevErr_t tda9851Term(unitSelect_t unitID)
{
ptda9851UnitVars_t uv;
if (unitID == unitVars0.id)
uv = &unitVars0;
else
uv = &unitVars1;
uv->used = False;
return TMLIBDEV_OK;
}
extern tmLibdevErr_t tda9851Start(unitSelect_t unitID)
{
ptda9851UnitVars_t uv;
UInt iicd;
tmLibdevErr_t err;
if (unitID == unitVars0.id)
uv = &unitVars0;
else
uv = &unitVars1;
err = iicDirectionSelect(uv->iicDirection);
if (err != TMLIBDEV_OK)
return err;
iicd = uv->iicReg & 0xfd;
err = iicWriteReg(TDA9851_IIC_ADDRESS, -1, iicd);
if (err == TMLIBDEV_OK)
uv->iicReg = iicd;
iicDirectionUnSelect(uv->iicDirection);
return err;
}
extern tmLibdevErr_t tda9851Stop(unitSelect_t unitID)
{
ptda9851UnitVars_t uv;
UInt iicd;
tmLibdevErr_t err;
if (unitID == unitVars0.id)
uv = &unitVars0;
else
uv = &unitVars1;
err = iicDirectionSelect(uv->iicDirection);
if (err != TMLIBDEV_OK)
return err;
iicd = uv->iicReg | 0x02;
err = iicWriteReg(TDA9851_IIC_ADDRESS, -1, iicd);
if (err == TMLIBDEV_OK)
uv->iicReg = iicd;
iicDirectionUnSelect(uv->iicDirection);
return err;
}
extern tmLibdevErr_t tda9851MuteStereo(unitSelect_t unitID)
{
return TMLIBDEV_OK;
}
extern tmLibdevErr_t tda9851SetStereo(unitSelect_t unitID, Bool enable)
{
ptda9851UnitVars_t uv;
UInt iicd;
tmLibdevErr_t err;
if (unitID == unitVars0.id)
uv = &unitVars0;
else
uv = &unitVars1;
err = iicDirectionSelect(uv->iicDirection);
if (err != TMLIBDEV_OK)
return err;
iicd = uv->iicReg & 0xfe;
if (enable)
iicd |= 0x01;
err = iicWriteReg(TDA9851_IIC_ADDRESS, -1, iicd);
if (err == TMLIBDEV_OK)
uv->iicReg = iicd;
iicDirectionUnSelect(uv->iicDirection);
return err;
}
extern tmLibdevErr_t tda9851GetStatus(unitSelect_t unitID, ptsaTvAudDemStatus_t status)
{
ptda9851UnitVars_t uv;
UInt iicd;
tmLibdevErr_t err = TMLIBDEV_OK;
status->stereoPresent = False;
status->sapPresent = False;
if (unitID == unitVars0.id)
uv = &unitVars0;
else
uv = &unitVars1;
err = iicDirectionSelect(uv->iicDirection);
if (err != TMLIBDEV_OK)
return err;
err = iicReadReg(TDA9851_IIC_ADDRESS, -1, &iicd);
if (err != TMLIBDEV_OK)
goto tda9851GetStatusExit;
if (iicd & 0x01)
status->stereoPresent = True;
tda9851GetStatusExit:
iicDirectionUnSelect(uv->iicDirection);
return err;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -