saa7113.c

来自「SAA7113在psos下的驱动程序,及7113的硬件datasheet」· C语言 代码 · 共 1,308 行 · 第 1/3 页

C
1,308
字号
/*
 * Copyright (c) 1995 - 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              : saa7113.c    1.9
 *
 *  Last update              : 11:58:38 - 99/06/23
 *
 *  Description              :
 *
 *  Initialize and control routines for saa7113
 *
 *
 *  Revision                 :
 *        Built for the TCS 2.0 release
 *
 *
 */


#include <stdio.h>
#include <tm1/tmIIC.h>
#include <tm1/tmAvFormats.h>
#include <tm1/tmVImmio.h>
#include <tm1/tmVIboard.h>
#include <tmlib/dprintf.h>
#include <saa7113.h>
#include <unistd.h>

/* OLDSB = 0, so the masks are slightly different and not compatible with */
/* old versions */

#define A_HLCK          0x40 /* OLDSB = 1. Horizontal freq locked */
#define A_HLVLN         0x40 /* OLDSB = 0  Horizontal/Vertical freq locked */
#define A_FIDT          0x20 /* LOW = 50Hz, HIGH = 60 Hz */
#define A_RDCAP         0x01 /* OLDSB = 0. Ready for capture */
#define A_CODE          0x01 /* OLDSB = 1. Colour Signal in accordance w/ selected standard */

/******************************************************************************/
/* Default structures for video decoder configuration (supports 1 default instance) */
#define NUM_OF_DEF_ADAPTER 2

static boardVIAdapterEntry_t defAdapters[NUM_OF_DEF_ADAPTER] = {
  { vaaCVBS,   0, 1 },
  { vaaSvideo, 0, 9 }
};

static boardVIDec_t defaultVD [1] = 
{
    { 0x4A,                /* I2C slave address of first decoder  */
      NUM_OF_DEF_ADAPTER,  /* Number of adapters                  */
      defAdapters }        /* mapping of adapters to inputs       */
};

/******************************************************************************/
/* Definitions and structures used by the video DecHAL implementation         */

typedef enum 
{
    ChipVersion=            0x00,   
    IncrementDelay=         0x01,   
    AnalogInputControl1=    0x02,   
    AnalogInputControl2=    0x03,   
    AnalogInputControl3=    0x04,   
    AnalogInputControl4=    0x05,   
    HorzSyncStart=          0x06,   
    HorzSyncStop=           0x07,   
    SyncControl=            0x08,   
    LuminanceControl=       0x09,   
    LuminanceBrightness=    0x0A,   
    LuminanceContrast=      0x0B,   
    ChromaSaturation=       0x0C,   
    ChromaHueControl=       0x0D,   
    ChromaControl=          0x0E,   
    ChromaGainControl=      0x0F,   

    FormatDelayControl=     0x10,   
    OutputControl1=         0x11,   
    OutputControl2=         0x12,   
    OutputControl3=         0x13,   

    VGateStart=             0x15,   
    VGateStop=              0x16,   
    VGateMSB=               0x17,   

    StatusByte=             0x1F,   

    AC1=                    0x40,   
    LCR2=                   0x41,   
    LCR3=                   0x42,   
    LCR4=                   0x43,   
    LCR5=                   0x44,   
    LCR6=                   0x45,   
    LCR7=                   0x46,   
    LCR8=                   0x47,   
    LCR9=                   0x48,   
    LCR10=                  0x49,   
    LCR11=                  0x4A,   
    LCR12=                  0x4B,   
    LCR13=                  0x4C,   
    LCR14=                  0x4D,   
    LCR15=                  0x4E,   
    LCR16=                  0x4F,   
    LCR17=                  0x50,   
    LCR18=                  0x51,   
    LCR19=                  0x52,   
    LCR20=                  0x53,   
    LCR21=                  0x54,   
    LCR22=                  0x55,   
    LCR23=                  0x56,   
    LCR24=                  0x57,   
    FC=                     0x58,   
    HOFF=                   0x59,   
    VOFF=                   0x5A,   
    HVOFF=                  0x5B,   

    DID=                    0x5D,   
    SDID=                   0x5E,   

    DR=                     0x60,   
    LN1=                    0x61,   
    LN2=                    0x62    
} decoderRegs_t;

typedef struct 
{
    int     nSubAddr;
    int     nValue;
} viRegValue;

static viRegValue saa7113_defRegs[] = {
    {IncrementDelay,        0x08},
    {AnalogInputControl1,   0xC0},
    {AnalogInputControl2,   0x20},
    {AnalogInputControl3,   0x00},
    {AnalogInputControl4,   0x75},
    {HorzSyncStart,         0xEb},
    {HorzSyncStop,          0xe0},
    {SyncControl,           0xB8},
    {LuminanceControl,      0x01},//43
    {LuminanceBrightness,   0x45},//80
    {LuminanceContrast,     0x30},//0x46
    {ChromaSaturation,      0x60},//0x40
    {ChromaHueControl,      0x00},//0x00
    {ChromaControl,         0x01},
    {ChromaGainControl,     0xa8},

    {FormatDelayControl,    0x40},
    {OutputControl1,        0x0C},
    {OutputControl2,        0xba},//
    {OutputControl3,        0x00},

    {VGateStart,            0x00},
    {VGateStop,             0x00},
    {VGateMSB,              0x00},

    {StatusByte,            0x91},

    {AC1,                   0x02},
    {LCR2,                  0xFF},
    {LCR3,                  0xFF},
    {LCR4,                  0xFF},
    {LCR5,                  0xFF},
    {LCR6,                  0xFF},
    {LCR7,                  0xFF},
    {LCR8,                  0xFF},
    {LCR9,                  0xFF},
    {LCR10,                 0xFF},
    {LCR11,                 0xFF},
    {LCR12,                 0xFF},
    {LCR13,                 0xFF},
    {LCR14,                 0xFF},
    {LCR15,                 0xFF},
    {LCR16,                 0xFF},
    {LCR17,                 0xFF},
    {LCR18,                 0xFF},
    {LCR19,                 0xFF},
    {LCR20,                 0xFF},
    {LCR21,                 0xFF},
    {LCR22,                 0xFF},
    {LCR23,                 0xFF},
    {LCR24,                 0xFF},
    {FC,                    0x0 },
    {HOFF,                  0x0 },
    {VOFF,                  0x7 },
    {HVOFF,                 0x0 },

    {DID,                   0x00},
    {SDID,                  0x0},
    {DR,                    0x00},
    {LN1,                   0x2f},
    {LN2,                   0xeF},
    {-1,-1}                             /* End of array */
};


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

/* Static variables: */
static unsigned int m_nNumVBILines;
static unsigned int m_nStartVBILine;
static unsigned int lastI2cError = 0;

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

#define MAX_TT 14
                                                /* Teletext translation table */
                                                /* to convert bit masks into */
                                                /* teletext program nibbles */
                                                /* quickly. */
typedef struct 
{
    int               nBitMask;
    int               nNibble;
} viDataServiceMapping_t;

static viDataServiceMapping_t Convert7113TT[MAX_TT] =
{
    {vdsEuroTeleText,       0x0},
    {vdsEuroClosedCaption,  0x1},
    {vdsVPS,                0x2},
    {vdsWSS,                0x3},
    {vdsUSTeleText,         0x4},
    {vdsUSClosedCaption,    0x5},
    {vdsUpsampledRaw,       0x7},
    {vdsTeleText,           0x8},
    {vdsVITC_EBU,           0x9},
    {vdsVITC_SMPTE,         0xA},
    {vdsUSNABTS,            0xC},
    {vdsMoji,               0xD},
    {vdsJapFormatSwitch,    0xE},
    {vdsNone,               0xF},
};

/******************************************************************************/
static tmLibdevErr_t  
mapAdapterInput (pboardVIDec_t pVD, pboardVIParam_t param, unsigned int *mode)
{
    unsigned int i; 

    /* If this is vaaNone then use the default adapter */
    if (param->adapterType == vaaNone)
    {
        *mode = pVD->adapterTable[0].decInput;
        return TMLIBDEV_OK;
    }

    for (i = 0; i < pVD->numAdapters; i++)
    {
        /* Find the right instance of the adapter */
        if ((pVD->adapterTable[i].instNum == param->adapterInstance) &&
            (pVD->adapterTable[i].adapterType == param->adapterType))
        {
            *mode = pVD->adapterTable[i].decInput;
            return TMLIBDEV_OK;
        }
    }

    /* No adapter instance found. If it's unqual to zero */
    /*  -> try with instance zero... */
    if (param->adapterInstance != 0)
    {
        param->adapterInstance = 0;
        return mapAdapterInput (pVD, param, mode);
    }

    /* Right adapter was not found -> return error */
    return BOARD_ERR_UNSUPPORTED_ADAPTER;
}

/******************************************************************************/
tmLibdevErr_t 
saa7113InitM (pboardVIDec_t pVD, pboardVIParam_t param)
{
 	return;
}

tmLibdevErr_t 
saa7113Init (pboardVIParam_t param)
{
    return saa7113InitM(&defaultVD[0], param);
}

/******************************************************************************/
tmLibdevErr_t
saa7113GetStandardM(pboardVIDec_t pVD, tmVideoAnalogStandard_t * std)
{
  return;
}

tmLibdevErr_t
saa7113GetStandard(tmVideoAnalogStandard_t * std)
{
    return saa7113GetStandardM (&defaultVD[0], std);
}

tmLibdevErr_t 
saa7113GetAdapterVideoStandard(pboardVIDec_t pVD, tmVideoAnalogAdapter_t adapter, unsigned int adapterNum, tmVideoAnalogStandard_t *std)
{
    unsigned int 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, unsigned long subaddr, unsigned long value)
{
    tmLibdevErr_t rval = TMLIBDEV_OK;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

⌨️ 快捷键说明

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