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

📄 touchpanel.c

📁 东芯IVSEP3203F50移动终端应用处理器触摸屏驱动
💻 C
字号:
/*************************************************************************************
*	Copyright (c) 2005 by National ASIC System Engineering Research Center.
*	PROPRIETARY RIGHTS of ASIC are involved in the subject matter of this 
*	material.  All manufacturing, reproduction, use, and sales rights 
*	pertaining to this subject matter are governed by the license agreement.
*	The recipient of this software implicitly accepts the terms of the license.
*
*	File Name: touchpanel.c
*
*	File Description:
*			The file includes three functions to initialize the touchpanel and server it.
*
*	Created by Michael <yuyu_zh@seu.edu.cn>, 2005-04-02
**************************************************************************************/

#include "garfield.h"

int main(void)
{
	if(E_OK != ModuleTouchpanel())
		printf("error in Touchpanel lab\n");
		
	while(1);

	return 1;
}

STATUS	ModuleTouchpanel(void)
{
	/* system initialized */
	system_init();
	
	/* initialize touchpanel */
	init_Pen();

	return E_OK;
}

void touchinit(void)                                          
{
	
	*(RP)PORTH_DIR |=0x08;
	*(RP)PORTH_SEL |=0x08;
	*(RP)PORTH_INTRCTL |=0X80;
	*(RP)PORTH_INCTL |=0X08;
	*(RP)PORTH_INTRCLR =0x3f ;
	
}

void ResetUCB(void)
{
//**********Enable TMXP Negative INT,ADDR: 60H
	*(RP)AC97_CRAC=WRITE + 0x600000 + 0x2000;  
	do{}while(!OVER_WRITE);

//**********Touch Screen Control register,ADDR: 64H
	*(RP)AC97_CRAC=WRITE + 0x640000 + 0x00C3;          //D9-D8=00 interupt mode
	do{}while(!OVER_WRITE);
}

/*******************************
void wucb(U32 addr,U32 val)
{
	*(RP)AC97_CRAC=WRITE+ (addr<<16) + val;				// 0-15bit value, 16-22 bit address, 31 bit -read or write    
	do{}while(!OVER_WRITE);								// 向ucb1400寄存器写数据
}		
********************************/

void InitAC97(void)
{
//*********Reset AC97
    *(RP)AC97_ENABLE=0x1;
	*(RP)AC97_CONR=0X03;	

//*********Reset Codec ,ADDR: 00H
	 *(RP)AC97_CRAC=WRITE+ 0x0 + 0x0;	
	do{}while(!OVER_WRITE);

//************configure Codec,	
//**********Enable TMXP Negative INT,ADDR: 60H
	*(RP)AC97_CRAC=WRITE + 0x600000 + 0x2000;  
	do{}while(!OVER_WRITE);

//**********Touch Screen Control register,ADDR: 64H
	*(RP)AC97_CRAC=WRITE + 0x640000 + 0x00C3;          //D9-D8=00 interupt mode
	do{}while(!OVER_WRITE);

//*********clear INT Clear/Status register,ADDR:62H 
	      *(RP)AC97_CRAC=WRITE + 0x620000+0xf800;
	      do{}while(!OVER_WRITE);

//remove do while after debug;	      

}



U32 CheckPenUp()
{  
      //*********Touch Screen Control register; ADDR:64H 
	          *(RP)AC97_CRAC=WRITE + 0x640000+0x00C3;      //Interupt mode
	           do{}while(!OVER_WRITE);
      //_________________________________________________  

      //*********Touch Screen Control register; ADDR:64H 
	          *(RP)AC97_CRAC=READ + 0x640000+0x00C3;      //Interupt mode
	          do{}while(!OVER_READ);
      //_________________________________________________  
      if(*(RP)AC97_CRAC & (0x00003000))
          return 0;
      else
          return 1;  //没有up
}
 
void clrcodecint()
{	
   //*********Touch Screen Control register; ADDR:64H 
	      *(RP)AC97_CRAC=WRITE + 0x640000+0x00C3;      //Interupt mode
	      do{}while(!OVER_WRITE);
   //_________________________________________________  

   //*********clear INT Clear/Status register,ADDR:62H 
	      *(RP)AC97_CRAC=WRITE + 0x620000+0x2000;
	      do{}while(!OVER_WRITE);
   
   //**********Enable TMXP Negative INT,ADDR: 60H
	      *(RP)AC97_CRAC=WRITE + 0x600000 + 0x2000;  
	       do{}while(!OVER_WRITE); 
  //**********clr H PORT
  //        *(RP)PORTH_INTRCLR=0x3f;
}

U32 readx(U32 tmp)
{  
   //*********Touch Screen Control register; ADDR:64H 
	      *(RP)AC97_CRAC=WRITE + 0x640000+0xA48;                     //X Position
	      do{}while(!OVER_WRITE);
   //_________________________________________________  
	
	
	
   //*********ADC Control register; ADDR:66H 
	      *(RP)AC97_CRAC=WRITE + 0x660000+0x8083;                     //Start X Position Convert
	      do{}while(!OVER_WRITE);
   //_________________________________________________ 
    
    
    
   //*********READ ADC Data register ,ADDR:68H                       // Check ADC Complete (First Time)
	      *(RP)AC97_CRAC=READ + 0x680000;
	      do{}while(!OVER_READ);
   //_________________________________________________
   
   
   
   while(!(*(RP)AC97_CRAC & (0x1 << 15 )))
   {
	 //*********READ ADC Data register ,ADDR:68H                       // Check ADC Complete
	      *(RP)AC97_CRAC=READ + 0x680000;
	      do{}while(!OVER_READ);
    }
	tmp = *(RP)AC97_CRAC;
	return tmp;
}


U32 ready(U32 tmp)
{
	//*********Touch Screen Control register; ADDR:64H 
	      *(RP)AC97_CRAC=WRITE + 0x640000+0xA12;                     //Y Position
	      do{}while(!OVER_WRITE);
   //_________________________________________________  
	
	
	
   //*********ADC Control register; ADDR:66H 
	      *(RP)AC97_CRAC=WRITE + 0x660000+0x808B;                     //Y Position Convert
	      do{}while(!OVER_WRITE);
   //_________________________________________________ 
    
    
    
   //*********READ ADC Data register ,ADDR:68H                       // Check ADC Complete (First Time)
	      *(RP)AC97_CRAC=READ + 0x680000;
	      do{}while(!OVER_READ);
   //_________________________________________________
   
   
   
   while(!(*(RP)AC97_CRAC & (0x1 << 15 )))
	{
	
	 //*********READ ADC Data register ,ADDR:68H                       // Check ADC Complete
	      *(RP)AC97_CRAC=READ + 0x680000;
	      do{}while(!OVER_READ);
     //_________________________________________________
	 }
	tmp = *(RP)AC97_CRAC;
	return tmp;
}

void init_Pen(void)
{
	irq_enable(INT_EXT15);    							// 中断控制器使能
	
	touchinit();
	InitAC97();
		init_LCD();
    unmask_irq(INT_EXT15);   							// 中断unmask

}

void PenEnable(void)
{
	clrcodecint();			//change mode into int; clear int source and clear GPIO int.
	
	unmask_irq(INT_EXT15);	
}

void PenDisable(void)
{
	mask_irq(INT_EXT15);	
}

STATUS PenRead(void)
{
	U32 tmpx,tmpy;
	U32 i;
	U16 ValueX;
	U16 ValueY;

	ValueY = (readx(tmpx) & 0x000003ff);
	ValueX = (ready(tmpy) & 0x000003ff);
	
READXY:
		/* check pen up? */
	 if(!(CheckPenUp()))
     {
     	ValueX=0;
        ValueY=0;
             return 0;
     }else{       
		ValueY = (readx(tmpx) & 0x000003ff);
		ValueX = (ready(tmpy) & 0x000003ff);
     }
     
     printf("Coordinate X=%d\tY=%d\n\n",ValueX,ValueY);

	/* To see if whether the touchpanel is still touched */
	for(i=0; i<10000; i++);
	if((CheckPenUp()))goto READXY;
	
    return 1;
}

void tp_handler(void)  //中断入口函数
{
	PenDisable();

	PenRead();

	PenEnable();

	return ;
}
void init_LCD(void)
{
		
	*(RP)LECR = 0x0000001;     //enable the LCDC	

}

⌨️ 快捷键说明

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