📄
字号:
_iicDataCount = 1;
//while (rIICSTAT & 0x20);
rIICDS = slvAddr;
rIICSTAT = 0xf0; //MasTx,Start
//rIICCON = 0xaf;
//Clearing the pending bit isn't needed because the pending bit has been cleared.
// timeout = 0;
// while(_iicDataCount!=-1) {
// Run_IicPoll();
// if (timeout++ > TIMEOUT) break;
// }
timeout = get_timer(0);
while(_iicDataCount!=-1) {
Run_IicPoll();
if (get_timer(0)-timeout > TIMEOUT) break;
}
_iicMode = RDDATA;
_iicPt = 0;
_iicDataCount = 1;
rIICDS = slvAddr;
rIICSTAT = 0xb0; //Master Rx,Start
rIICCON = 0xaf; //Resumes IIC operation.
// timeout = 0;
// while(_iicDataCount!=-1) {
// Run_IicPoll();
// if (timeout++ > TIMEOUT) break;
// }
timeout = get_timer(0);
while(_iicDataCount!=-1) {
Run_IicPoll();
if (get_timer(0)-timeout > TIMEOUT) break;
}
*data = _iicData[1];
//rIICSTAT = 0xd0; //Master Tx condition, Stop(Write), Output Enable
//rIICCON = 0xaf; //Resumes IIC operation.
Delay(DELAYTIME);
#endif
}
//**********************[ Run_IicPoll ]*********************************
void Run_IicPoll(void)
{
if(rIICCON & 0x10) { //Tx/Rx Interrupt Enable
//udelay (100);
IicPoll();
}
}
//**********************[IicPoll ]**************************************
void IicPoll(void)
{
U32 iicSt,i;
iicSt = rIICSTAT;
if(iicSt & 0x8){} //When bus arbitration is failed.
if(iicSt & 0x4){} //When a slave address is matched with IICADD
if(iicSt & 0x2){} //When a slave address is 0000000b
if(iicSt & 0x1){} //When ACK isn't received
//_iicStatus = iicSt;
//printk(">");
switch(_iicMode)
{
case POLLACK:
_iicStatus = iicSt;
break;
case RDDATA:
if((_iicDataCount--)==0)
{
_iicData[_iicPt++] = rIICDS;
rIICSTAT = 0x90; //Stop MasRx condition
rIICCON = 0xaf; //Resumes IIC operation.
//while (rIICSTAT & 0x20);
Delay(10); //Wait until stop condtion is in effect.
//Too long time...
//The pending bit will not be set after issuing stop condition.
break;
}
_iicData[_iicPt++] = rIICDS;
//The last data has to be read with no ack.
if((_iicDataCount)==0)
rIICCON = 0x2f; //Resumes IIC operation with NOACK.
else
rIICCON = 0xaf; //Resumes IIC operation with ACK
break;
case WRDATA:
if((_iicDataCount--)==0)
{
rIICSTAT = 0xd0; //stop MasTx condition
rIICCON = 0xaf; //resumes IIC operation.
//while (rIICSTAT & 0x20);
Delay(10); //wait until stop condtion is in effect.
//The pending bit will not be set after issuing stop condition.
break;
}
rIICDS = _iicData[_iicPt++]; //_iicData[0] has dummy.
for(i=0;i<100;i++); //for setup time until rising edge of IICSCL
rIICCON = 0xaf; //resumes IIC operation.
break;
case SETRDADDR:
// Uart_Printf("[S%d]",_iicDataCount);
if((_iicDataCount--)==0)
{
Delay(10);
break; //IIC operation is stopped because of IICCON[4]
}
rIICDS = _iicData[_iicPt++];
for(i=0;i<100;i++); //for setup time until rising edge of IICSCL
rIICCON = 0xaf; //resumes IIC operation.
break;
default:
break;
}
}
int VGA_init(void)
{
//int var0,var1;
//var1 = GPECON;
//var0 = GPEUP;
BANKCON6 = BANKCON7 = 0x18001;
//REFRESH = 0x008e01e9;
MRSRB6 = MRSRB7 = 0x20;
rGPEUP |= 0xc000; //Pull-up disable
rGPEDAT |= 0xc000;
rGPECON = (rGPECON&~0xf0000000) | 0x50000000; //GPE15:IICSDA , GPE14:IICSCL
//Enable ACK, Prescaler IICCLK=PCLK/16, Enable interrupt, Transmit clock value Tx clock=IICCLK/16
//IICCON = 0xaf; /* PCLK/512 */
//IICCON = 0xe1; /* PCLK/512 */
//rIICCON = (1<<7) | (0<<6) | (1<<5) | (0xf);
//rIICADD = 0x10; //2410 slave address = [7:1]
//rIICSTAT = 0x10; //IIC bus data output enable(Rx/Tx)
//rIICADD = 0x9f;
//rIICSTAT = 0x9f;
//printk("write iic\n");
iic_wr(0xec,4,0x20);
//printk("2.\n");
iic_wr(0xec,7,0x8c);
//printk("3.\n");
iic_wr(0xec,14,0x1b);
//printk("4.\n");
iic_wr(0xec,13,0x03);
//printk("read back from iic\n");
iic_rd(0xec,4,&iic_data);
if (iic_data != 0x20) return -1;
//printk("6.\n");
iic_rd(0xec,7,&iic_data);
if (iic_data != 0x8c) return -1;
//printk("7.\n");
iic_rd(0xec,14,&iic_data);
if (iic_data != 0x1b) return -1;
//GPEUP = var0;
//GPECON = var1;
return 0;
}
int TV_init(int mode)
{
int var0,var1;
var1 = GPECON;
var0 = GPEUP;
GPEUP = GPEUP | 0xc000; //IIC 上拉
GPECON = GPECON | 0xa00000; //IIC
rIICCON = 0xaf;
rIICADD = rIICSTAT = 0x10;
if (mode == 1)
{
printk("initial tv mode 640480.\n");
iic_wr(0xec,0,0x42);
}
if (mode == 2)
{
printk("initial tv mode 640400.\n");
iic_wr(0xec,0,0x61);
}
iic_wr(0xec,4,0x00);
iic_wr(0xec,7,0x64);
iic_wr(0xec,8,0x01);
iic_wr(0xec,10,0x30);
iic_wr(0xec,11,0x20);
iic_wr(0xec,9,0x69);
iic_wr(0xec,14,0x0a);
iic_wr(0xec,16,0x00);
iic_wr(0xec,61,0x00);
iic_wr(0xec,1,0x08);
iic_rd(0xec,9,&iic_data);
if (iic_data != 0x69)
return -1;
iic_rd(0xec,14,&iic_data);
if (iic_data != 0x0a)
return -1;
iic_rd(0xec,16,&iic_data);
if (iic_data != 0x00)
return -1;
iic_rd(0xec,61,&iic_data);
if (iic_data != 0x00)
return -1;
iic_rd(0xec,0,&iic_data);
if (iic_data != 0x42)
return -1;
iic_rd(0xec,4,&iic_data);
if (iic_data != 0x00)
return -1;
iic_rd(0xec,7,&iic_data);
if (iic_data != 0x64)
return -1;
iic_rd(0xec,8,&iic_data);
if (iic_data != 0x01)
return -1;
iic_rd(0xec,10,&iic_data);
if (iic_data != 0x30)
return -1;
iic_rd(0xec,11,&iic_data);
if (iic_data != 0x20)
return -1;
GPEUP = var0;
GPECON = var1;
return 0;
}
static void
vga(int argc, const char* argv[])
{
/*if (chech_id()<0)
{
printk("error!\n");
return;
}*/
Lcd_ClearDisplayBuff();
Lcd_Init();
if (VGA_init()!=0)
{
printk("vga initialize error!\n");
return;
}
printk("vga initialized ok!\n");
}
static void
tv(int argc, const char* argv[])
{
int ret;
/*if (chech_id()<0)
{
printk("");
return;
}*/
ret = 0;
if (argc==1)
ret = TV_init(1);
if (argc<=2) {
if (!strcmp("640400",argv[1]))
ret = TV_init(1);
if (!strcmp("640480",argv[1]))
ret = TV_init(2);
}
if (ret) {
printk("error!\n");
return;
}
printk("ok!\n");
}
user_command_t vga_cmd = { "vga", vga, NULL, "vga \t\t-- init vga output."};
user_command_t tv_cmd = { "tv", tv, NULL, "tv <mode>\t\t-- init tv output."};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -