📄 drvhdmi_mst3383m.c
字号:
/******************************************************************************
Copyright (c) 2006 MStar Semiconductor, Inc.
All rights reserved.
[Module Name]: DrvHDMI_Mst3383M.c
[Date]: 2007/10/08
[Comment]:
HDMI subroutines.
[Reversion History]:
*******************************************************************************/
#include "board.h"
#include "mreg51.h"
#include "hwreg.h"
#include "i2c.h"
#include <intrins.h>
#include "DataType.h"
#include "DrvHDMI_Mst3383M.h"
#include "DrvTimer.h"
extern BOOLEAN MDrv_IIC_WriteBytes(U8 u8SlaveID, U8 AddrCnt, U8* pu8addr, U16 u16size, U8* pBuf);
extern BOOLEAN MDrv_IIC_ReadBytes(U8 ucSlaveAdr, U8 ucSubAdr, U8* paddr, U16 ucBufLen, U8* pBuf);
#define _DRVHDMI_C_
//=====================================================================
void Write_MST3xxx_Byte(BYTE ucRegIndex, BYTE ucValue)
{
BYTE addr[2];
addr[0] = ucRegIndex;
addr[1] = ucValue;
MDrv_IIC_WriteBytes(MST3XXX_I2C_ADDR, sizeof(addr), addr, 0, addr);
}
//=====================================================================
BYTE Read_MST3xxx_Byte(BYTE ucRegIndex)
{
BYTE ucData;
MDrv_IIC_ReadBytes(0x9C, 1, &ucRegIndex, 1, &ucData);
return ucData;
}
//=====================================================================
void SetAudioOutput(BOOL Enable)
{
Write_MST3xxx_Byte(0x00,0x01);
if(Enable)
Write_MST3xxx_Byte(0xD1,0x00);
else
Write_MST3xxx_Byte(0xD1,0xFF);
Write_MST3xxx_Byte(0x00,0x00);
}
//=====================================================================
void SetBlackScreen(BOOL Enable)
{
if(Enable)
Write_MST3xxx_Byte(0xAB,Read_MST3xxx_Byte(0xAB)|0x80);
else
Write_MST3xxx_Byte(0xAB,Read_MST3xxx_Byte(0xAB)&~0x80);
}
//=====================================================================
void Write_MST3xxx_RegTbl(RegUnitType code *pTable)
{
BYTE ucIndex; // register index
while (1)
{
ucIndex = pTable->ucIndex; // get register index
if (ucIndex == _END_OF_TBL_) // check end of table
break;
Write_MST3xxx_Byte(ucIndex, pTable->ucValue); // write register
pTable++; // next
} // while
}
//=====================================================================
code RegUnitType tHDCPInit[]=
{
{0x00,0x00},
{0xB8,0x20}, // HDMI Reset, must done when mode change
{0xB8,0x00}, // Clear HDMI Reset
{0x00,0x01},
{0x24,0x40}, // Enable HDCP
{0x25,0x00}, // Indirect addressed register write enable
{0x26,0x40}, // Support HDCP1.1
{0x27,0x82},
/*{0x25,0x00},*/
{0x26,0x64}, // Set vtotal tolerance
{0x27,0x04},
{0x00,0x00},
{_END_OF_TBL_,0x00}
};
//=====================================================================
code RegUnitType tHDMIInit[]=
{
{0x00,0x01},
{0x5C,0x10}, // 0x11 // Set HDMI audio MCLK output to 256fs and I2S output left justified
{0x5D,0x01}, // AV_Mute alwayes enable
//{0x5F,0x78}, // when error, disable audio automaticly by H/W
{0x5F,0x70}, // when error, disable audio automaticly by H/W (Invert AUMUTE)
// av_mute pin,inverse event.
{0xD2,0x1A}, // audio PLL power down disable
{0x00,0x00}, // switch to bank0
{0xAB,0x40}, // video blank out when receive AV_Mute packet
//{0xAB,0xC0}, // video blank out when receive AV_Mute packet
{_END_OF_TBL_,0x00}
};
//=====================================================================
code RegUnitType tTMDSInit[]=
{
{0x00,0x01},
{0x0F,0x02}, // DVI bit error tolerance threshold, recommend set to 2
{0x16,0x30}, // 20050824 add
{0x28,0x00}, // Cable Setting, for default
{0x17,0xA0},
{0x18,0x00},
{0x1A,0x50}, //
{0x00,0x00},
{_END_OF_TBL_,0x00}
};
//=====================================================================
code RegUnitType tCommonInit[]=
{
{0x92,0x00}, // csc
{0xB4,0xD4}, // drive strength 94 TONY
#if (INPUT_DIGITAL_TYPE == DIGITAL_CCIR601)
{0xB0,0x20}, // 0x00 // output set to CCIR601
#else
{0xB0,0x30}, // 0x00 // output set to CCIR656
#endif
{0xB1,0x02}, // 0x00 // output set, depend on layout
{0xB2,0x08},
//{0xB5,0x08}, // output set, depend on layout TONY 0C
{0xB5,0x0C}, // kevin 070215
{_END_OF_TBL_,0x00}
};
//=====================================================================
code RegUnitType tCSC[]=
{
{0x93,0x01},
{0x94,0xC2},
{0x95,0x01},
{0x96,0x07},
{0x97,0x1F},
{0x98,0x68},
{0x99,0x1E},
{0x9A,0x87},
{0x9B,0x02},
{0x9C,0x04},
{0x9D,0x1E},
{0x9E,0xD6},
{0x9F,0x1F},
{0xA0,0xB7},
{0xA1,0x00},
{0xA2,0x64},
{0xA3,0x01},
{0xA4,0xC2},
{0xA5,0x08},
{0xA6,0x00},
{0xA7,0x01},
{0xA8,0x00},
{0xA9,0x08},
{0xAA,0x00},
//{0x92,0x40}, // csc enable
{0x92,0x00}, // csc disable
{_END_OF_TBL_,0x00}
};
//=====================================================================
void HardWareReset(void)
{
//HWRESET(1);
MDrv_Timer_Delayms(10);
//HWRESET(0);
}
//=====================================================================
void HotPlugSetHigh(BOOL On)
{
if(On)
{ // bank0 b7 for disable Rx detect signal
Write_MST3xxx_Byte(0xb7,0x00);
//HPD(1);
}
else
{
Write_MST3xxx_Byte(0xb7,0x04); // 0x06 for Dual Hdmi
//HPD(0);
}
}
//=====================================================================
void HDCP_Reinit(void)
{
BYTE TempValue;
Write_MST3xxx_Byte(0x00,0x01); // Switch to bank 1
Write_MST3xxx_Byte(0x25,0x08);
Write_MST3xxx_Byte(0x26,0x14);
TempValue=Read_MST3xxx_Byte(0x27);
Write_MST3xxx_Byte(0x25,0x00);
Write_MST3xxx_Byte(0x26,0x14);
Write_MST3xxx_Byte(0x27,TempValue);
Write_MST3xxx_Byte(0x00,0x00); // Switch to bank 0
}
//=====================================================================
void HDMI_Reset(void)
{
Write_MST3xxx_Byte(0xb8,0x20);
Write_MST3xxx_Byte(0xb8,0x00);
}
//=====================================================================
BYTE IsAviPackageReady(void)
{
BYTE RegValue = FALSE, Count = MAXCOUNT;
Write_MST3xxx_Byte(0x00,0x01); // Switch to bank 1
while(--Count)
{
RegValue = Read_MST3xxx_Byte(0x50);
MDrv_Timer_Delayms(50);
if ((RegValue&0x08)&&(Count<MAXCOUNT-10))
break;
}
RegValue = Read_MST3xxx_Byte(0x77)&0x60;
printf("\r\nAVI pack CS=%d", RegValue);
Write_MST3xxx_Byte(0x00,0x00); // Switch to bank 0
return RegValue;
}
//=====================================================================
#define CheckHDMICounter 10
#define MANUAL 0x40
#define SIG_HDMI 0x80
#define HDCPDisable 0x01
#define DVI_STATUS 0x01
#define bDVI_HDMI10 0x01
#define bDVI_HDMI_In 0x04
/*void CheckHDMISignalAndHDCP(void)
{
BYTE RegValue,count=CheckHDMICounter;
BYTE SiganlType=MANUAL;
Write_MST3xxx_Byte(0x00,0x01); // Switch to bank 1
//check HDMI
while(--count)
{
RegValue=Read_MST3xxx_Byte(DVI_STATUS)&bDVI_HDMI_In;
if(RegValue)
{
MDrv_Timer_Delayms(10);
SiganlType|=SIG_HDMI;
break;
}
} //detect input signal is HDMI or DVI
//check HDCP
count=CheckHDMICounter; //reset counter
while(--count)
{
RegValue=Read_MST3xxx_Byte(DVI_STATUS)&bDVI_HDMI10;
if(RegValue)
{
MDrv_Timer_Delayms(10);
break;
}
} //detect input signal is with HDCP or not
if(!RegValue) //nohdcp
SiganlType|=HDCPDisable;
Write_MST3xxx_Byte(0x24,SiganlType); //force input signal format
Write_MST3xxx_Byte(0x00,0x00); // Switch to bank0
}*/
//=====================================================================
void SourceChange(BYTE Source)
{
if(Source==HDMI)
{
HDCP_Reinit();
HDMI_Reset();
}
if(Source!=HDMI)
{
HotPlugSetHigh(FALSE);
Write_MST3xxx_Byte(0x51,Read_MST3xxx_Byte(0x51)&~0x80);
}
else
{
Write_MST3xxx_Byte(0x51, 0x8B); // select source HDMI
HotPlugSetHigh(TRUE);
}
}
//=====================================================================
void devHDMIInitialize(void)
{
HardWareReset();
SetAudioOutput(FALSE);
HotPlugSetHigh(FALSE);
MDrv_Timer_Delayms(100);
Write_MST3xxx_RegTbl(tCommonInit);
Write_MST3xxx_RegTbl(tHDCPInit);
Write_MST3xxx_RegTbl(tHDMIInit);
Write_MST3xxx_RegTbl(tTMDSInit);
Write_MST3xxx_RegTbl(tCSC);
SourceChange(HDMI);
}
//=====================================================================
void SetUpHDMIMode(void)
{
// BYTE RegValue=0,count=CheckHDMICounter;
// Step1 in msMonitorInputTiming()~ mode change in 1st time
// Step2 detect valid timing & setup mode
Write_MST3xxx_Byte(0x00,0x01); // Switch to bank 1
if (Read_MST3xxx_Byte(DVI_STATUS)&_BIT2)// HDMI
{
printf("\r\n HDMI mode");
/*while (--count)
{
if (IsAviPackageReady())
{
RegValue = (Read_MST3xxx_Byte(0x77)&0x60);
printf("\r\nHDMI CS=%d", RegValue);
break;
}
}*/
Write_MST3xxx_Byte(0x00,0x00); // Switch to bank 0
//if (RegValue)// YUV
if (IsAviPackageReady())
{
//Write_MST3xxx_Byte(0x92, 0x66); //enable CSC
Write_MST3xxx_Byte(0x92, 0x00);
}
else// RGB
{
//Write_MST3xxx_Byte(0x92, 0x00); // disable CSC
Write_MST3xxx_Byte(0x92, 0x40);
}
SetAudioOutput(TRUE);
}
else// DVI
{
printf("\r\n DVI mode");
Write_MST3xxx_Byte(0x00,0x00); // Switch to bank 0
//Write_MST3xxx_Byte(0x92, 0x00); // disable CSC
Write_MST3xxx_Byte(0x92, 0x40); // disable CSC
SetAudioOutput(FALSE);
}
SetBlackScreen(FALSE);
}
//=====================================================================
/*void Detect_TMDS(void)// test kk
{
Write_MST3xxx_Byte(0x00,0x00); // Switch to bank 0
if ((Read_MST3xxx_Byte(0x55)&0x3C) == 0)
{
SetAudioOutput(FALSE);
putstr("\r\nLost TMDS signal");
}
}*/
//=====================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -