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

📄 tlg1100app.c

📁 泰景的模拟电视全部驱动及MTK平台界面代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
* FILENAME
* tlg1100App.c
*
*
* ABSTRACT
* This file contains example procedures for initializing and managing the
* TLG1100. Note: This example code assumes that TLG_EMBEDDED_TIMERS is
* enabled.
*
* $Revision: 1.19 $
*
* (c) 2007 Telegent Systems
*****************************************************************************/

/* INCLUDE SECTION ************************************************************
*******************************************************************************
*******************************************************************************
******************************************************************************/
#include "tlgConfig.h"
#if TLG_CHIP_TYPE == TLG_CHIP_TYPE_TLG1100_1
#include "tlg1100Hal.h"
#include "tlg1100Api.h"
#include "tlgi2c.h"
#include "tlg1100App.h"

#include "Tv_Platform.h"
/* DECLARE SECTION ************************************************************
*******************************************************************************
*******************************************************************************
******************************************************************************/

p_tlg_channel_t(p_tlg_cur_map)      = NULL; /* Current Default Channel Map    */
int              tlg_cur_bw         = TLG_BW_NONE;   /* Current Bandwidth     */
int              tlg_cur_mode       = TLG_MODE_NONE; /* Current Mode          */
int              tlg_cur_std        = TLG_VSTD_NONE; /* Current Video Std     */
int              tlg_cur_chn_cnt    = 0;             /* Current Channel Count */
int32            tlg_slope          = 0;             /* Current FM Slope      */
int32            tlg_offset         = 0;             /* Current FM Offset     */
int              tlg_init_done      = 0;             /* Flag Init called      */
int              tlg_cur_lna        = TLG_LNA_NONE;  /* LNA Setting           */
uint16           tlg_cur_gain       = 0;             /* audio gain            */
uint16           tlg_cur_aud_mode   = 0;             /* audio mode            */
uint32           tlg_i2c_addr       = TLGI2C_DEFAULT_BASE_ADDR;
tlg_statep       tlg_power_state    = {TLG_STATE0};

/* FUNCTION SECTION ***********************************************************
*******************************************************************************
*******************************************************************************
******************************************************************************/
TLGDLL_API void TLGAPP_Restart(void) {
    p_tlg_cur_map = NULL;                       /* Current Default Channel Map*/
    tlg_cur_bw    = TLG_BW_NONE;                /* Current Bandwidth          */
    tlg_cur_mode  = TLG_MODE_NONE;              /* Current Mode               */
    tlg_cur_std   = TLG_VSTD_NONE;              /* Current Video Std          */
    tlg_slope     = 0;                          /* Current FM Slope           */
    tlg_offset    = 0;                          /* Current FM Offset          */
    tlg_init_done = 0;                          /* Flag Init called           */
    tlg_cur_lna   = TLG_LNA_NONE;               /* LNA Setting                */
    tlg_cur_gain  = 0;                          /* Audio Gain                 */
    tlg_cur_aud_mode = 0;                       /* Audio Mode                 */
    TLG_ClearRegShadow(tlg_i2c_addr);           /* Clear Shadow Register      */
}

int TLGAPP_Ini_WriteReg(int start, uint32 i2c_addr, uint16 reg_addr, uint16 val) {
    if (start == TLG_INIT_DEEP_SLEEP && (reg_addr >= 0x180))
        return TLG_ERR_SUCCESS;
    return TLG_WriteReg(i2c_addr, reg_addr, val);
}

/*****************************************************************************
* TLGAPP_Ini_Reg
* BEGIN CUSTOM SECTION: These are the recommended set of default register
* settings for startup of the TLG1100. However, additional register writes may
* be added by customers as desired.
*****************************************************************************/
TLGDLL_API void TLGAPP_Ini_Reg(int start) {
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0010, 0x16c8);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0011, 0x4605);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0012, 0xc810);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0015, 0x0640);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0016, 0x0640);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0017, 0x0001);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0018, 0x0001);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0019, 0x0005);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x001a, 0x0010);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x001f, 0x6640);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0025, 0x03f0);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0026, 0x03FF);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x002b, 0x000c);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x002c, 0x0009);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x002d, 0x000a);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0031, 0x0001);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0032, 0x0001);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0033, 0x0d01);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x004a, 0x0041);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0052, 0x0FFF);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0053, 0x7100);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0054, 0x90c8);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0059, 0x8046);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x006d, 0x160c);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0077, 0x1028);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x008b, 0x0009);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0097, 0x0000);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x009e, 0x0080);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0185, 0x0292);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0188, 0x0292);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x018b, 0x0292);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0193, 0x8080);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0198, 0x0003);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x01a4, 0x0282);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x01b3, 0x29F8);
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x01b4, 0x0261); 
    TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x01b7, 0x0641);
    #ifdef TLG_SUPPORT_RUNTIME_CHECK
        {uint32 version; TLG_GetChipVersion(tlg_i2c_addr, &version);}
    #endif /* TLG_SUPPORT_RUNTIME_CHECK */
    TLG_CHIP_VERS_1_3_BEGIN
        #if defined(TLG_CMP_CHIP_1_3)
    	TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0010, 0x26c8);
    	TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0025, 0x000c);
    	TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0026, 0x0200);
    	TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0030, 0x0000);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0056, 0x0490);
    	TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x005e, 0x810f);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0061, 0x4104);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x006f, 0x40c0);
        #endif /* TLG_CMP_CHIP_1_3 */
    TLG_CHIP_VERS_ELSE
        #if defined(TLG_CMP_CHIP_1_2) || defined(TLG_CMP_CHIP_1_1)
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x005e, 0x81ff);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0061, 0x4108);
        #endif /* !TLG_CMP_CHIP_1_3 */
    TLG_CHIP_VERS_END
    TLG_CHIP_VERS_1_2_BEGIN
        #if defined(TLG_CMP_CHIP_1_3) || defined(TLG_CMP_CHIP_1_2)
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x002e, 0x0600);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0027, 0x0200);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0030, 0x8000);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x001e, 0x0029);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x01a3, 0x0700);
        #endif /* TLG_CMP_CHIP_1_2 */
     TLG_CHIP_VERS_1_1_ELSE
        #ifdef TLG_CMP_CHIP_1_1
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x0027, 0x03FF);
        TLGAPP_Ini_WriteReg(start, tlg_i2c_addr, 0x001e, 0x003c);
        #endif /* TLG_CMP_CHIP_1_1 */
     TLG_CHIP_VERS_END
/**
 ** BEGIN CUSTOM SECTION: any additional register writes should go here.
 **/
}

/*****************************************************************************
* TLGAPP_Init
******************************************************************************/
TLGDLL_API int TLGAPP_Init(uint32 base_addr) {
    return TLGAPP_Init_Aux(base_addr, TLG_NEW_INIT);
}

/*****************************************************************************
* TLGAPP_Init_Aux
******************************************************************************/
TLGDLL_API int TLGAPP_Init_Aux(uint32 base_addr, int start) {
    tlg_i2c_addr = base_addr;

    TLGAPP_Ini_Reg(start);
    if (start == TLG_NEW_INIT)
        TLG_Init(tlg_i2c_addr);
    else
        TLG_ReInitFromDeepSleep(tlg_i2c_addr);

    TLGAPP_InitVideoAndAudio();
    tlg_init_done = 1;
    return TLG_ERR_SUCCESS;
}

/*****************************************************************************
* TLGAPP_PowerDown
******************************************************************************/
TLGDLL_API int TLGAPP_PowerDown(void) {
    tlg_power_state[0] = TLG_STATE0;
    TLG_DeepSleep(tlg_i2c_addr, tlg_power_state);
    return TLG_ERR_SUCCESS;
}

/*****************************************************************************
* TLGAPP_ReInitFromPowerDown
******************************************************************************/
TLGDLL_API int TLGAPP_ReInitFromPowerDown(void) {
    if (TLG_ReturnFromDeepSleep(tlg_i2c_addr, tlg_power_state) == TLG_ERR_SUCCESS) {
        TLGAPP_Restart();
        return TLGAPP_Init_Aux(tlg_i2c_addr, TLG_INIT_DEEP_SLEEP);
    } else
        return TLG_ERR_FAIL;
}

/*****************************************************************************
* TLGAPP_ChannelSetup
*****************************************************************************/
TLGDLL_API int TLGAPP_ChannelSetup(int mode, int standard, int bw) {
    if (!tlg_init_done) TLGAPP_Init(tlg_i2c_addr);
    if (mode != tlg_cur_mode) {
        TLG_SetChnMode(tlg_i2c_addr, (uint16) mode);
        tlg_cur_mode = mode;
    }
    if (standard != tlg_cur_std) {
        TLG_SetChnStandard(tlg_i2c_addr, (uint16) standard);
        tlg_cur_std = standard;
    }
    if (bw != tlg_cur_bw) {
        TLG_SetChnBandwidth(tlg_i2c_addr, (uint16) bw);
        tlg_cur_bw = bw;
    }
    return(TLG_ERR_SUCCESS);
}

/*****************************************************************************
* TLGAPP_SetChannelMap
******************************************************************************/
TLGDLL_API int TLGAPP_SetChannelMap(p_tlg_channel_t(map), int mode, int vidstd, int bw) {
    int i;
    TLGAPP_ChannelSetup(mode, vidstd, bw);
    p_tlg_cur_map   = map;
    tlg_slope       = 0;
    tlg_offset      = 0;
    tlg_cur_chn_cnt = 0;
    for(i=0; p_tlg_cur_map[i] CHN_S != 0; i++) {
        tlg_cur_chn_cnt++;
    }
    return(TLG_ERR_SUCCESS);
}

/*****************************************************************************
* TLGAPP_SetChannelMapPALD
******************************************************************************/
TLGDLL_API int TLGAPP_SetChannelMapPALD(void) {
    return TLGAPP_SetChannelMap((uint32 (*)[4])tlg_china_pald_chn_map, TLG_MODE_ANALOG_TV,
                         TLG_VSTD_PAL_D, TLG_BW_8);
}

/*****************************************************************************
* TLGAPP_SetChannelMapNTSC
******************************************************************************/
TLGDLL_API int TLGAPP_SetChannelMapNTSC(void) {
    return TLGAPP_SetChannelMap((uint32 (*)[4])tlg_ntsc_chn_map, TLG_MODE_ANALOG_TV,
                         TLG_VSTD_NTSC_M, TLG_BW_6);
}

/*****************************************************************************
* TLGAPP_SetChannelMapFM
******************************************************************************/
TLGDLL_API int TLGAPP_SetChannelMapFM(void) {
    int    i;
    uint32 minhz = 999999999;
    uint32 maxhz = 0;

    /* Always use NTSC, 6MHz setttings for FM Radio */
    TLGAPP_ChannelSetup(TLG_MODE_FM_RADIO, TLG_VSTD_NTSC_M, TLG_BW_6);
    p_tlg_cur_map = (uint32 (*)[4])tlg_fm_chn_map;

    /* get min and max hz */
    tlg_cur_chn_cnt = 0;	/* By Paul */
    for (i=0; p_tlg_cur_map[i] CHN_S != 0; i++) {
        tlg_cur_chn_cnt++;	/* By Paul */
        if (p_tlg_cur_map[i] HZ_S < minhz) minhz = p_tlg_cur_map[i] HZ_S;
        if (p_tlg_cur_map[i] HZ_S > maxhz) maxhz = p_tlg_cur_map[i] HZ_S;
    }
    return TLG_InitScanFMChn(tlg_i2c_addr, minhz, maxhz, &tlg_slope, &tlg_offset);
}

/*****************************************************************************
* TLGAPP_SwitchChannelMap
******************************************************************************/
TLGDLL_API int TLGAPP_SwitchChannelMap(p_tlg_channel_t(map)) {
    int i;
    TLG_NULLPTR_CHECK(map);
    p_tlg_cur_map = map;
    tlg_cur_chn_cnt = 0;
    for(i=0; p_tlg_cur_map[i] CHN_S != 0; i++) {
        tlg_cur_chn_cnt++;
    }
    return(TLG_ERR_SUCCESS);

⌨️ 快捷键说明

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