📄 tmbslsaa7104.c
字号:
/* Copyright (C) 2004 Koninklijke Philips Electronics N.V.
All Rights Reserved.
This source code and any compilation or derivative thereof is the
proprietary information of Koninklijke Philips Electronics N.V. and is
confidential in nature.
Under no circumstances is this software to be exposed to or placed under an
Open Source License of any type without the expressed written permission of
Koninklijke Philips Electronics N.V.
*//*
--------------------------------------------------------------------------------
%name: tmbslsaa7104.c %
%version: ds08#21.1.3.1.8 %
%date_created: Tue Oct 24 16:56:38 2006 %
--------------------------------------------------------------------------------
*/
/**
@file tmbslsaa7104.c
@brief bsp driver for the SAA7104 video encoder.
@b Component: tmbsl7104.
his source file contains the implementation
for the SAA7104 video output chip.
Its interface is designed according to the definition of the
board support library.
*/
/******************************************************************************
* STANDARD INCLUDE FILES *
*******************************************************************************/
#include <stdlib.h>
#include <string.h>
/******************************************************************************
* PROJECT INCLUDE FILES *
*******************************************************************************/
#include "tmosal.h"
#include "tmDbg.h"
#include "tmdlIic.h"
#include "tmbslVencAna.h"
#include "tmbslVencAnaExt.h"
#include "tmbsl7104.h"
#include "tmbslsaa7104local.h"
/******************************************************************************
* LOCAL MACROS *
*******************************************************************************/
#define SAA7104_BSL_COMP_NUM 1 // compatibility number
#define SAA7104_BSL_MAJOR_VER 1 // major version number
#define SAA7104_BSL_MINOR_VER 1 // minor version number
#define SAA7104_SIGNATURE ( ('7' << 24) | ('1' << 16) | ('0' << 8) | '4' )
#define SAA7104_MAGIC_NUMBER (0x10123456)
#define SAA7104_MAX_UNITS 1
#define SAA7104_IIC_SPEEDKHZ 100
#define SAA7104_IIC_RETRIES 10
#define CUR_BITMAP_ARRAY_SIZE 256
/******************************************************************************
* LOCAL TYPEDEFS *
*******************************************************************************/
/** @brief declares AV register offsets */
typedef enum
{
/** Video regs */
SAA7104_REG_VIDEO = 0x00,
/** Audio regs */
SAA7104_REG_AUDIO = 0x10,
/** Audio 2 regs */
SAA7104_REG_AUDIO2 = 0x18
} saa7104RegOffset_t;
/** @brief override _tmbslVencAna_t coming from public header file */
struct _tmbslVencAna_t
{
UInt32 magic;
tmUnitSelect_t unitNumber;
char currentVideoStandard[TM_VIDEOMODE_NAME_MAXSIZE];
tmVideoTypeFormat_t currentVideoType;
tmVideoOutFormat_t currentVideoSubType;
tmbslVencAna_EncodingType_t currentEncodingType;
tmbslVencAna_ColorSystem_t currentColorSystem;
tmbslVencAnaDesc_t encoderI2cSettings;
};
/** @brief SAA7104 instance */
typedef struct
{
/** structure signature */
UInt32 signature;
/** TM_TRUE: instance is initialized */
Bool init;
/** chip revision */
tmbslsaa7104Rev_t chipRev;
/** current video standard */
char videoStandard[TM_VIDEOMODE_NAME_MAXSIZE];
/** I2C Instance */
tmInstance_t iicInstance;
/** Encoder's I2C base address */
UInt8 slaveAddr;
tmbslVencAna_EncodingType_t encodingType;
tmVideoTypeFormat_t videoType;
tmVideoOutFormat_t videoSubtype;
/** Current brightness */
UInt32 brightness;
/** Current contrast */
UInt32 contrast;
/** Current saturation */
UInt32 saturation;
/** Current hue */
UInt32 hue;
/** current sharpness */
UInt32 sharpness;
/** mode uses both interfaces */
Bool dualInterfaceMode;
/** powerState of saa7104 as set by software */
tmPowerState_t powerState;
} saa7104Inst_t, *psaa7104Inst_t;
/** @brief Defines the current VBI setup.
need this in case copy protection setup changes */
typedef struct saa7104Data
{
/** AVO Unit number */
tmUnitSelect_t avoUnit;
/** Mask of used services for each line */
tmVideoDataService_t field1[PAL_VBI_LINES_FIELD1];
/** Mask of used services for each line */
tmVideoDataService_t field2[PAL_VBI_LINES_FIELD1];
/** Size of the VBI table */
UInt8 tblSize;
} saa7104Data_t, *psaa7104Data_t;
/** @brief Structure containing all parameters for AVO board setup */
typedef struct saa7104Param
{
char videoStandard[TM_VIDEOMODE_NAME_MAXSIZE];
tmbslVencAna_EncodingType_t encodingType;
tmVideoTypeFormat_t videoType;
tmVideoOutFormat_t videoSubtype;
tmbslVencAna_ColorSystem_t colorSystem;
} saa7104Param_t, *psaa7104Param_t;
/******************************************************************************
* STATIC DATA *
*******************************************************************************/
static UInt32 gSaa7104InstCnt = 0;
static ptmbslVencAna_t gpSaa7104VencAna = Null;
static saa7104Data_t gSaa7104VbiData[SAA7104_MAX_UNITS];
static saa7104Inst_t gSaa7104Inst[SAA7104_MAX_UNITS] =
{
{ // unit0
~SAA7104_SIGNATURE, // signature
TM_FALSE, // init
(tmbslsaa7104Rev_t)0, // chipRev
'\0', // videoStandard
0, // iicInstance
}
};
// The following table tells us what VBI lines are used by macrovision on a
// per field basis. This is updated every time tmbslDencSetupMacrovision()
// is called.
static UInt8 copyProtectVBITable[SAA7104_MAX_UNITS][PAL_VBI_LINES_FIELD1];
static tmdlIicRequest_t gSaa7104IicReq;
static UInt8 gSaa7104bData[CUR_BITMAP_ARRAY_SIZE + 1]; // Bit map array size + one byte of RAM start address
/******************************************************************************
* STATIC FUNCTION PROTOTYPES *
*******************************************************************************/
static tmErrorCode_t saa7104VoInit(
tmUnitSelect_t avoUnit,
ptmbslVencAnaDesc_t pEnc,
psaa7104Param_t pSetup
);
static tmErrorCode_t saa7104VoDeinit(
tmUnitSelect_t avoUnit
);
static tmErrorCode_t saa7104ProgramSyncEngine(
tmUnitSelect_t avoUnit,
char *videoStandard
);
static void saa7104InitCursorBitmap(
tmUnitSelect_t avoUnit
);
static tmErrorCode_t saa7104GetReg(
tmUnitSelect_t avoUnit,
UInt8 bReg,
UInt8 *pbData
);
static tmErrorCode_t saa7104SetReg(
tmUnitSelect_t avoUnit,
UInt8 bReg,
UInt8 bData
);
static tmErrorCode_t saa7104SetRegM(
tmUnitSelect_t avoUnit,
UInt8 bReg,
const UInt8 *pbData,
UInt8 bsize
);
static tmErrorCode_t saa7104WriteArray(
tmUnitSelect_t avoUnit,
saa7104RegOffset_t offset,
UInt8 *pData,
UInt32 dataSize
);
static psaa7104_HDSync_t saa7104GetHdSyncTab(
char *videoStandard
);
static void dumpTheseRegister (tmUnitSelect_t avoUnit);
/******************************************************************************
* FUNCTION IMPLEMENTATION *
*******************************************************************************/
/******************************************************************************
* EXPORTED FUNCTIONS *
*******************************************************************************/
/******************************************************************************
* EXPORTED FUNCTION PROTOTYPES serving ItmbslVencAna *
*******************************************************************************/
/******************************************************************************/
tmErrorCode_t tmbsl7104Open(
ptmbslVencAna_t *ppInstance,
tmUnitSelect_t unitSelect,
ptmbslVencAnaDesc_t pEnc
)
{
tmErrorCode_t error = TM_OK;
saa7104Param_t avoParam;
if(gpSaa7104VencAna == Null)
{
*ppInstance = (ptmbslVencAna_t)calloc( 1, sizeof(tmbslVencAna_t));
gpSaa7104VencAna = *ppInstance;
}
else
{
*ppInstance = gpSaa7104VencAna;
error = tmosalSystemMutexEnter();
DBG_ASSERT(error == TM_OK);
gSaa7104InstCnt++;
error = tmosalSystemMutexExit();
DBG_ASSERT(error == TM_OK);
return error;
}
if(ppInstance == Null)
return TMBSL_ERR_VENCANA_OUT_OF_MEMORY;
(*ppInstance)->magic = SAA7104_MAGIC_NUMBER;
(*ppInstance)->unitNumber = unitSelect;
(*ppInstance)->currentEncodingType = tmbslVencAna_Cvbs;
(*ppInstance)->currentVideoType = vtfYUV;
(*ppInstance)->currentVideoSubType = vof8bitYUV422;
(*ppInstance)->currentEncodingType = tmbslVencAna_Cvbs;
(*ppInstance)->currentColorSystem = tmbslVencAna_NtscM;
(*ppInstance)->encoderI2cSettings = *pEnc;
strcpy((*ppInstance)->currentVideoStandard, "ntsc");
avoParam.encodingType = (*ppInstance)->currentEncodingType;
avoParam.videoType = (*ppInstance)->currentVideoType;
avoParam.videoSubtype = (*ppInstance)->currentVideoSubType;
avoParam.colorSystem = (*ppInstance)->currentColorSystem;
strcpy(avoParam.videoStandard, (*ppInstance)->currentVideoStandard);
error = saa7104VoInit((*ppInstance)->unitNumber,pEnc, &avoParam);
if(error == TM_OK)
gSaa7104InstCnt++;
return error;
}
/******************************************************************************/
tmErrorCode_t tmbsl7104Close(
ptmbslVencAna_t pInstance
)
{
tmErrorCode_t error = TM_OK;
DBG_ASSERT(pInstance != Null);
DBG_ASSERT(pInstance->magic == SAA7104_MAGIC_NUMBER);
error = tmosalSystemMutexEnter();
DBG_ASSERT(error == TM_OK);
gSaa7104InstCnt--;
error = tmosalSystemMutexExit();
DBG_ASSERT(error == TM_OK);
if (gSaa7104InstCnt == 0)
{
error = saa7104VoDeinit(pInstance->unitNumber);
pInstance->magic = 0x0;
gpSaa7104VencAna = Null;
free(pInstance);
}
return error;
}
/******************************************************************************/
tmErrorCode_t tmbsl7104ApplyExtInterfaceSettings(
ptmbslVencAna_t pInstance
)
{
tmErrorCode_t error = TM_OK;
saa7104Param_t avoParam;
DBG_ASSERT(pInstance != Null);
DBG_ASSERT(pInstance->magic == SAA7104_MAGIC_NUMBER);
avoParam.encodingType = pInstance->currentEncodingType;
avoParam.videoType = pInstance->currentVideoType;
avoParam.videoSubtype = pInstance->currentVideoSubType;
avoParam.colorSystem = pInstance->currentColorSystem;
strcpy(avoParam.videoStandard, pInstance->currentVideoStandard);
error = saa7104VoInit(pInstance->unitNumber,&pInstance->encoderI2cSettings, &avoParam);
return error;
}
/******************************************************************************/
tmErrorCode_t tmbsl7104SetEncodingType(
ptmbslVencAna_t pInstance,
tmbslVencAna_EncodingType_t encType
)
{
tmErrorCode_t error = TM_OK;
DBG_ASSERT(pInstance != Null);
DBG_ASSERT(pInstance->magic == SAA7104_MAGIC_NUMBER);
pInstance->currentEncodingType = encType;
return error;
}
/******************************************************************************/
tmErrorCode_t tmbsl7104GetEncodingType(
ptmbslVencAna_t pInstance,
tmbslVencAna_EncodingType_t *pEncType
)
{
DBG_ASSERT(pInstance != Null);
DBG_ASSERT(pInstance->magic == SAA7104_MAGIC_NUMBER);
DBG_ASSERT(pEncType != NULL );
*pEncType = pInstance->currentEncodingType;
return TM_OK;
}
/******************************************************************************/
tmErrorCode_t tmbsl7104SetColorSystem(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -