📄 si2c.c
字号:
/******************************************************************************
Copyright (c) 2005 MStar Semiconductor, Inc.
All rights reserved.
[Module Name]: SI2C.c
[Date]: 13-Mar-2005
[Comment]:
For Slave I2C functions.
[Reversion History]:
Registers read and write command list:
DATA WRITE : START + 0x6E + 0x10 + addrh + addrl + data + STOP
DATA READ : START + 0x6E + 0x10 + addrh + addrl + START + 0x6F + data +STOP
Functions read and write command list:
write contrast : START + 0x6E + 0x20 + 01 + xxh + data + STOP
read contrast : START + 0x6E + 0x20 + 01 + xxh + START + 0x6F + (data) + STOP
write Brightness : START + 0x6E + 0x20 + 02 + xxh + data + STOP
read Brightness : START + 0x6E + 0x20 + 02 + xxh + START + 0x6F + (data) + STOP
ON/OFF Panel set : START + 0x6E + 0x20 + 10 + xxh + 0:OFF 1:ON + STOP
ON/OFF Panel Rd : START + 0x6E + 0x20 + 10 + xxh + START + 0x6F + (data) + STOP
*******************************************************************************/
#define _SI2C_C_
/********************
* INCLUDE FILES *
*********************/
#include "Project.h"
#include "TypeDef.h"
#include "Ms7X_reg.h"
#include "Global.h"
#include "Mcu.h"
#include "Mcu_reg.h"
#include "Ms_Rwreg.h"
#include "Misc.h"
#include "Sync.h"
#include "OSDMenu.h"
#include "Ms_Func.h"
#include "msACE.h"
#include "SI2C.h"
#include "Debug.h"
#if SI2C_ENABLE
/**********************
* FUNCTION PROTOTYPES *
***********************/
void sysSlaveI2CInitial(void)
{
mstWriteByte(GEN_00_REGBK, REGBANKSCALER); // Register bank switch to Scaler
mstWriteByte(BK0_1B_INTENB, 0x00); // Enable Scaler interrupt (datr & datw)
mstWriteByte(BK0_1D_INTENC, 0x00); // Enable Scaler interrupt (star & stop)
mstWriteByte(BK0_1A_INTSTB, 0x00);
mstWriteByte(BK0_1C_INTSTC, 0x00);
g_bSI2CCommandFlag = 0;
g_bSI2CDebugModeFlag = 0;
g_ucSI2CBuffIndex = 0;
MCUXFR_19_DDC2BI_ID = 0x80 + (0x6E>>1); // Set SI2C slave address 0x6E , bit7:Enable SI2C
MCUXFR_18_DDC2BI_CTRL = 0x02; // Enable SI2C no_ack
MCUXFR_11_DDC2BI_FLAG = 0x00; // Clear all interrupt flag
PX0 = 1; // Set to high priority interrupt
IT0 = 1; // set INT0 level trigger
EX0 = 1; //enable MCU INT0
MCUXFR_10_DDC2BI_INT_EN = 0x3E; // Enable SI2C interrupt
}
void sysSlaveI2CCommand(void)
{
WORD uwAddress;
BYTE ucTemp;
do
{
if(g_bSI2CCommandFlag)
{
if(SI2C_CATEGORY == SI2C_CMD_BASIC)
{
if(g_ucSI2CBuffIndex==SI2C_WRITE_CMD_LEN)
{
// enter debug mode
if((SI2C_FUNCTION==SI2C_BAS_DEBUG)&&(SI2C_CONTROL==0x01))
g_bSI2CDebugModeFlag=1;
// exit debug mode
if((SI2C_FUNCTION==SI2C_BAS_DEBUG)&&(SI2C_CONTROL==0x00))
g_bSI2CDebugModeFlag=0;
}
else if(g_ucSI2CBuffIndex==SI2C_READ_CMD_LEN)
{
if((SI2C_FUNCTION==SI2C_BAS_VERSION)&&(SI2C_CONTROL==0x0F))//Feedback Bias version
SI2C_DATA=Display.ucVersion;
MCUXFR_13_DDC2BI_R_BUF=SI2C_DATA;
}
}
// Functions read and write
else if(SI2C_CATEGORY==SI2C_CMD_FUNC)
{
if(g_ucSI2CBuffIndex==SI2C_READ_CMD_LEN)
{
if(SI2C_FUNCTION==SI2C_FUNC_BRIGHTNESS)
SI2C_DATA=Display.ucBrightness;
else if(SI2C_FUNCTION==SI2C_FUNC_CONTRAST)
SI2C_DATA=Display.ucVedioContrast;
else if(SI2C_FUNCTION==SI2C_FUNC_HUE)
SI2C_DATA=Display.ucHue;
else if(SI2C_FUNCTION==SI2C_FUNC_SATURATION)
SI2C_DATA=Display.ucSaturation;
else if(SI2C_FUNCTION==SI2C_FUNC_GAMMA)
SI2C_DATA=Display.ucGamma;
else if(SI2C_FUNCTION==SI2C_FUNC_SCALING)
SI2C_DATA=Display.ucScalingMode;
else if(SI2C_FUNCTION==SI2C_FUNC_SOURCE)
SI2C_DATA=tOSDSourcSELSequence[Display.ucSourceSEL];
else if(SI2C_FUNCTION==SI2C_FUNC_VCOM_DC)
SI2C_DATA=Display.ucVCOMdc;
else if(SI2C_FUNCTION==SI2C_FUNC_VCOM_AC)
SI2C_DATA=Display.ucVCOMac;
else if(SI2C_FUNCTION==SI2C_FUNC_GPIO)
{
if(SI2C_CONTROL==SI2C_GPIO_0_7)
SI2C_DATA=P0;
else if(SI2C_CONTROL==SI2C_GPIO_8_15)
SI2C_DATA=P1;
else if(SI2C_CONTROL==SI2C_GPIO_16_23)
SI2C_DATA=P2;
else if(SI2C_CONTROL==SI2C_GPIO_24_29)
SI2C_DATA=P4;
}
MCUXFR_13_DDC2BI_R_BUF=SI2C_DATA;
}
else if(g_ucSI2CBuffIndex==SI2C_WRITE_CMD_LEN)
{
if(SI2C_FUNCTION==SI2C_FUNC_BRIGHTNESS)
{
if((SI2C_DATA<=100)&&(SI2C_DATA>=0))
{
Display.ucBrightness=SI2C_DATA;
mstSetBrightness(SI2C_DATA);
}
}
else if(SI2C_FUNCTION==SI2C_FUNC_CONTRAST)
{
if((SI2C_DATA<=MAX_CONTRAST)&&(SI2C_DATA>=MIN_CONTRAST))
{
Display.ucVedioContrast=SI2C_DATA;
mstSetContrast(SI2C_DATA);
}
}
else if(SI2C_FUNCTION==SI2C_FUNC_HUE)
{
if((SI2C_DATA<=MAX_HUE)&&(SI2C_DATA>=MIN_HUE))
{
Display.ucHue=SI2C_DATA;
mstSetHue(SI2C_DATA);
}
}
else if(SI2C_FUNCTION==SI2C_FUNC_SATURATION)
{
if((SI2C_DATA<=MAX_SATURATION)&&(SI2C_DATA>=MIN_SATURATION))
{
Display.ucSaturation=SI2C_DATA;
mstSetSaturation(SI2C_DATA);
}
}
else if(SI2C_FUNCTION==SI2C_FUNC_GAMMA)
{
if((SI2C_DATA<=MAX_GAMMA)&&(SI2C_DATA>=MIN_GAMMA))
{
Display.ucGamma=SI2C_DATA;
mstSetGamma(SI2C_DATA);
}
}
else if(SI2C_FUNCTION==SI2C_FUNC_SCALING)
{
if(SI2C_DATA<Scaling_TypeNumbers)
{
Display.ucScalingMode=SI2C_DATA;
mstSetScalingMode(SI2C_DATA);
}
}
#if !USE_ALLMACEOSD
else if(SI2C_FUNCTION==SI2C_FUNC_COLOR)
{
if(SI2C_DATA<2)
{
Display.ucMACE=SI2C_DATA;
mstSetMACE(SI2C_DATA);
}
}
#endif // USE_ALLMACEOSD
else if(SI2C_FUNCTION==SI2C_FUNC_SOURCE)
{
if(SI2C_DATA<INPUTSOURCE_END)
{
for(ucTemp=0; ucTemp<= MAX_SOURCE_NUM; ucTemp++)
{
if(tOSDSourcSELSequence[ucTemp] == SI2C_DATA)
{
Display.ucSourceSEL=ucTemp;
mstSyncSourceSwitch();
break;
}
}
}
}
else if(SI2C_FUNCTION==SI2C_FUNC_PANEL_ON)
{
if(SI2C_DATA == 0)
miscTurnOffPanel();
else
miscTurnOnPanel();
}
else if(SI2C_FUNCTION==SI2C_FUNC_VCOM_DC)
{
mstSetVcomDC(SI2C_DATA);
Display.ucVCOMdc=SI2C_DATA;
}
else if(SI2C_FUNCTION==SI2C_FUNC_VCOM_AC)
{
mstSetVcomAC(SI2C_DATA);
Display.ucVCOMac=SI2C_DATA;
}
else if(SI2C_FUNCTION==SI2C_FUNC_GPIO)
{
if(SI2C_CONTROL==SI2C_GPIO_0_7)
P0=SI2C_DATA;
else if(SI2C_CONTROL==SI2C_GPIO_8_15)
P1=SI2C_DATA;
else if(SI2C_CONTROL==SI2C_GPIO_16_23)
P2=SI2C_DATA;
else if(SI2C_CONTROL==SI2C_GPIO_24_29)
P4=SI2C_DATA;
}
else if(SI2C_FUNCTION==SI2C_FUNC_POWER_DOWN)
{
if(SI2C_DATA == 0)
{
Display.ucSystemStauts &= ~POWER_STATUS_FLAG;
miscTurnOffPanel();
mstPowerManagement(PM_POWER_OFF);
}
else
{
mstPowerManagement(PM_POWER_ON);
Display.ucSystemStauts |= POWER_STATUS_FLAG;
g_ucSystemFlag |= INPUT_TIMING_CHANGE_FLAG;
g_ucSystemFlag &= ~INPUT_SIGNAL_STABLE_FLAG;
mstSyncSourceSwitch();
}
}
else if(SI2C_FUNCTION==SI2C_FUNC_SVAE_DATA)
{
if((SI2C_CONTROL == 0x10) && (SI2C_DATA == 01))
g_ucSystemFlag |= SAVE_SETTING_FLAG;
}
}
}
// Registers read and write
if(g_bSI2CDebugModeFlag)
{
if(SI2C_CATEGORY==SI2C_CMD_REG)
{
if(g_ucSI2CBuffIndex==SI2C_READ_CMD_LEN)
{
uwAddress = ((WORD) SI2C_HI_ADDR << 8) + SI2C_LOW_ADDR;
if(uwAddress >= 0x0100)
SI2C_DATA = *((BYTE xdata*)uwAddress);
else
SI2C_DATA = *((BYTE pdata*)uwAddress);
MCUXFR_13_DDC2BI_R_BUF = SI2C_DATA;
}
else if(g_ucSI2CBuffIndex==SI2C_WRITE_CMD_LEN)
{
uwAddress = ((WORD) SI2C_HI_ADDR << 8) + SI2C_LOW_ADDR;
if(uwAddress >= 0x0100)
*((BYTE xdata*) uwAddress)= SI2C_DATA;
else
*((BYTE pdata*) uwAddress)= SI2C_DATA;
}
}
}
g_ucSI2CBuffIndex=0;
g_bSI2CCommandFlag=0;
}
}while(g_bSI2CDebugModeFlag);
}
#endif // SI2C_ENABLE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -