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

📄 hwdriver.c

📁 手写识别芯片EPH1100的驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		unsigned char buf[8],ptr[8];
	
		memcpy(buf,RotateMode,8);
		buf[3]=0x20;
		buf[7]=GenerateCRC(buf,8);

		memcpy(ptr,buf,8);
		ptr[3]=0xff;
		ptr[7]=GenerateCRC(ptr,8);
		WriteAndWait(buf,ptr);
	}*/
	return 0;
}
#if 1
unsigned char SetAbortInking(void)
{
	unsigned char buf[8],ptr[8];
	
	memcpy(buf,AbortInking,8);
	buf[7]=GenerateCRC(buf,8);
	
	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}
#endif

#if 0
unsigned char SetRotateMode(void)
{
	unsigned char buf[8],ptr[8];
	
	memcpy(buf,RotateMode,8);
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}
#endif

#if 0
unsigned char SetCalibration(void)
{
	unsigned char buf[8],ptr[8];
	
	memcpy(buf,Calibration,8);
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,8);
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}
#endif
#if 0
void TakeInkingxy(void)
{
	unsigned char x,y;
	if(g_eph.RecBuf[3]!=0xff||g_eph.RecBuf[4]!=0xff)
	{		
		g_nTouchPanelY =g_eph.RecBuf[4]; 
		g_nTouchPanelX =g_eph.RecBuf[3];
		if((g_eph.RecBuf[4])>=g_nTouchPanelYBase)
			y = (g_eph.RecBuf[4])-g_nTouchPanelYBase;
		else
			y = 0;
		if((g_eph.RecBuf[3])>=g_nTouchPanelXBase)			
			x = (g_eph.RecBuf[3])-g_nTouchPanelXBase;
		else
			x = 0;	
		x = x*132/g_nTouchPanelXDiv;
		y = y*132/g_nTouchPanelYDiv;
		g_nTouchKeyY = y;
		g_nTouchKeyX = x;
	}
}
#endif
#if 0
void TakeCharAray(void)
{
	ReceiveCommannd();
}
#endif
unsigned char SetHostReady(void)		//use wakeup g_eph
{
	unsigned char buf[8];
	
	memcpy(buf,HostReady,8);
	buf[7]=GenerateCRC(buf,8);
	return WriteAndWait(buf,buf);
}
#if 1
unsigned char SetWakeup(void)		//use wakeup g_eph
{
	unsigned char buf[8];
	
	memcpy(buf,AckWakeup,8);
	buf[7]=GenerateCRC(buf,8);

	SendCommand(buf);
	SysDeadDelay(12);
	return 1;
}
#endif
unsigned char WaitingInkData(void)
{
  	unsigned char PacketType,rec;

	if(g_eph.RecLen==0)
		return 0;
	rec = ReceiveCommannd();
	if(g_eph.RecBuf[0]==0)
	{
		SetHostReady();
		return 0;
	}
	if(g_eph.RecBuf[0]==0)
		return 0;
	if(rec){
	PacketType = g_eph.RecBuf[1];
	switch(PacketType)
	{ 
		case PACKET_COMMAND_POINT://在屏上移动RecBuf[1] = 0x16
		{ 
			g_eph.wmID=UDM_INK_DATA;
		}
		break;
		case PACKET_COMMAND_CALIBRATE://校正数据RecBuf[1] = 0x44
			g_eph.wmID=UDM_CALIBRATE_DATA;
	  		break;
		case PACKET_COMMAND_TOUCH://点击了一下屏RecBuf[1] = 0x17
		    g_eph.wmID=UDM_TOUCH_DATA;
			break; 
		case PACKET_COMMAND_CANDIDATES://手写识别RecBuf[1] = 0x18
			g_eph.wmID=UDM_RECOG_RESULT;
			break;
	}
		return 1;
	}
	return 0;	
}

static int ReadDataxy[2] = {0,0};
static void tp_handler ()
{

	ReceiveCommannd();
	if(g_eph.RecBuf[0]==0)
	{
		SetHostReady();
		return ;
	}

#ifdef PVR_PLATFORM
	if (!quasar_irq_pending(0))
		return;	
	quasar_clear_irq(0);
#else
	*PIO_1_INT_STATUS_REG = ((1 << 1 ) <<16) | 0xffff;
#endif

	return;
	
}

void init_irq(void)
{

	quasar_enable_irq(0,0);

}

void tp_enable()
{
	int status;
#ifdef PVR_PLATFORM
	quasar_enable_irq(0,0);
#else
	status = *INT_TYPE_REG;     
	*INT_TYPE_REG = status | (PIO1_INT);
#endif	

}

void tp_disable()
{
	int status;
	// disable
#ifdef PVR_PLATFORM
	quasar_disable_irq(0);
#else
	status = *INT_TYPE_REG;     
	*INT_TYPE_REG = status & ~(PIO1_INT);
#endif
}
static int tp_open(struct inode *inode, struct file *filp)
{
	MOD_INC_USE_COUNT;
	return 0;
}

static int tp_release(struct inode *inode, struct file *filp)
{
	MOD_DEC_USE_COUNT;
	return 0;
}

unsigned long tp_read_scancode(void)
{
	unsigned long ReceivedData = 0;
	unsigned char i;
	if (g_eph.RecBuf[0] == 0)
		return 0;
	
	ReceivedData = g_eph.RecBuf[0];
	for (i=1; i<8; ==i)
		ReceivedData = (ReceivedData << 8) |g_eph.RecBuf[i];

	return ReceivedData;
}
	
static int tp_ioctl(struct inode *i_node, struct file *filp,unsigned int cmd, unsigned long arg)
{
	unsigned long rc=0;
	switch (cmd) 
	{
/*	
	case TP_EN:
		TP_Touch_enable();
		break;
	case TP_DIS:
		TP_Touch_Disable();
		break;		
*/	case READ_TP_VALUE:
		rc=tp_read_scancode();
		break;
	default:
		printk("tp_ioctl: unknow cmd = %d\n",cmd);
		break;
	}
	
	return rc;
}

struct file_operations tp_fops = {		
	open:    tp_open,
	ioctl:   tp_ioctl,
	release: tp_release
};
static void tpff_release (){
	free_irq (22, NULL);
}
devfs_handle_t tp_register(void)
{
	devfs_handle_t de;
	unsigned int maj,min;

	// register char driver.
	// Try devfs first - if kernel doesnt support devfs, devfs_register
	// returns NULL

#ifdef CONFIG_DEVFS_FS
	if((de=devfs_register(NULL, RMTP_DEVICE_NAME,
			      DEVFS_FL_DEFAULT, RMTP_MAJOR, 0,
			      S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
			      &tp_fops, NULL)))
	{
		devfs_get_maj_min(de, &maj, &min);
		printk("init_module: device (%d:%d) registered in devfs\n",
			  maj, min);
	} 
	
#else
	
#error You must enable devfs in your kernel
#endif
#ifdef PVR_PLATFORM
	if (request_irq (22,tp_handler, 0,"Touchpanel", NULL)!= 0) 
   	{
		printk ("request interrupt %d failed", 22);
		tpff_release ();
	//	return 0;
  	}
#else
	if (request_irq (UART1_INT,tp_handler, 0,"Touchpanel", NULL )!= 0) 
   	{
		printk ("request interrupt %d failed", 22);
		tpff_release ();
	//	return 0;
  	}
#endif
	return de;
}


// use the PIO interrupt to change the state in the state machine
int init_module ()
{
	EXPORT_NO_SYMBOLS;
	printk("******************************\n");
	printk ("tp: init_TouchPenel_module\n");
	printk("******************************\n");
	InitUart();
	InitEph1100();
	
	// Set type to FIQ (pio0 irq used for remote control)
#ifdef PVR_PLATFORM
	init_irq();
#else
	status = *INT_TYPE_REG;       
	*INT_TYPE_REG = status | PIO1_INT;		
#endif	

	printk("TIMER0_CNTL_REG = %x,TIMER0_LOAD_REG = %x\n ",*TIMER0_CNTL_REG,*TIMER0_LOAD_REG);
		
	if(tp_register())
		printk("Touchpanel:  sucessfully registered\n");
	else 
		printk("Touchpanel: Unable to register device\n");

	printk("Touchpanel: init_module done\n");
	return 0;
}


void cleanup_module (void)
{
	printk ("tp: cleanup\n");
	install_fiq_handler(NULL);

}

unsigned char Eph100Main(void)
{
//	unsigned char ephtime = 0;
	while(1){
	if(WaitingInkData())
	{
		if(g_eph.wmID != UDM_TOUCH_DATA)
			QuickTouch = 0;
		switch(g_eph.wmID)
		{
			case UDM_INK_DATA:
				g_eph.wmID=UDM_THD_NULL;
				if((g_eph.RecBuf[3]!=0xff&&g_eph.RecBuf[4]!=0)||(g_eph.RecBuf[3]!=0xff&&g_eph.RecBuf[4]!=0xff))
				{	
					unsigned char x,y;
					y = (g_eph.RecBuf[4])-g_nTouchPanelYBase;
					x = (g_eph.RecBuf[3])-g_nTouchPanelXBase;
					x = x*132/g_nTouchPanelXDiv;
					y = y*132/g_nTouchPanelYDiv;
					g_nTouchKeyX = x;
					g_nTouchKeyY = y;		
				}
				else
				{
					g_nTouchKeyX = 0;
					g_nTouchKeyY = 0;
				}
				break;
			case UDM_TOUCH_DATA:		//select result and key button只点了一下屏
				g_eph.wmID = UDM_THD_NULL;
				if(g_eph.RecBuf[3]==0xff&&g_eph.RecBuf[4]==0xff)
				{
					if(!QuickTouch)
						return 0;
					QuickTouch = 0;
					return PEN_UP;
				}
				else
				{
					unsigned char x,y;
//					if(g_eph.RecBuf[3]>(g_nTouchPanelX-3)&&g_eph.RecBuf[3]<(g_nTouchPanelX+3)&&g_eph.RecBuf[4]>(g_nTouchPanelY-3)&&g_eph.RecBuf[4]<(g_nTouchPanelY+3))
//						return PEN_MOVE;
//					else
					{		
						if(QuickTouch)
						{	
//							QuickTouch = 0;
//							return PEN_UP;
							return 0;
						}	
						QuickTouch = 1;
						g_nTouchPanelY =g_eph.RecBuf[4]; 
						g_nTouchPanelX =g_eph.RecBuf[3];
						if((g_eph.RecBuf[4])>=g_nTouchPanelYBase)
							y = (g_eph.RecBuf[4])-g_nTouchPanelYBase;
						else
							y = 0;
						if((g_eph.RecBuf[3])>=g_nTouchPanelXBase)			
							x = (g_eph.RecBuf[3])-g_nTouchPanelXBase;
						else
							x = 0;	
						x = x*132/g_nTouchPanelXDiv;
						y = y*132/g_nTouchPanelYDiv;
						g_nTouchKeyY = y;
						g_nTouchKeyX = x;
						return 	PEN_DOWN;
					}
				}	
				break;	
			case UDM_CALIBRATE_DATA://校正数据
				g_eph.wmID = UDM_THD_NULL;
				if(g_eph.RecBuf[3]==0xff&&g_eph.RecBuf[4]==0xff&&g_eph.RecBuf[5]!=0xff&&g_eph.RecBuf[6]!=0xff)
				{	
					g_nTouchPanelY = (g_eph.RecBuf[6]);
					g_nTouchPanelX = (g_eph.RecBuf[5]);
					if((g_eph.RecBuf[6])>=g_nTouchPanelYBase)
						g_nTouchKeyY = (g_eph.RecBuf[6])-g_nTouchPanelYBase;
					else
						g_nTouchKeyY = 0;	
					if(	(g_eph.RecBuf[5])>=g_nTouchPanelXBase)
						g_nTouchKeyX = (g_eph.RecBuf[5])-g_nTouchPanelXBase;
					else
						g_nTouchKeyX = 0;
					g_nTouchKeyX =(unsigned char)g_nTouchKeyX*132/g_nTouchPanelXDiv;
					g_nTouchKeyY =(unsigned char)g_nTouchKeyY*132/g_nTouchPanelYDiv;
					return 	PEN_UP;
				}
				else if(g_eph.RecBuf[3]!=0xff&&g_eph.RecBuf[4]!=0xff&&g_eph.RecBuf[5]==0xff&&g_eph.RecBuf[6]==0xff)
				{
					g_nTouchPanelY = (g_eph.RecBuf[4]);
					g_nTouchPanelX = (g_eph.RecBuf[3]);
					if((g_eph.RecBuf[4])>=g_nTouchPanelYBase)						
						g_nTouchKeyY = (g_eph.RecBuf[4])-g_nTouchPanelYBase;
					else
						g_nTouchKeyY = 0;
					if(	(g_eph.RecBuf[3])>=g_nTouchPanelXBase)
						g_nTouchKeyX = (g_eph.RecBuf[3])-g_nTouchPanelXBase;
					else	
						g_nTouchKeyX = 0;
					g_nTouchKeyX =(unsigned char)g_nTouchKeyX*132/g_nTouchPanelXDiv;
					g_nTouchKeyY =(unsigned char)g_nTouchKeyY*132/g_nTouchPanelYDiv;
					return 	PEN_UP;
				}
				break;
			case UDM_RECOG_RESULT://手写识别结果
				g_eph.wmID = UDM_THD_NULL;
		  		if(!bWndGetResult)
		  		{
			  		unsigned char i,j;
					unsigned char str[26];
					unsigned char buf[12];
						
		  			EA = 0;
//					g_eph.wmID=UDM_THD_READING;
			  		ClearRect(1,66,63,14);
			  		ClearRect(1,81,63,14);
			  		memset(g_Ime.ImeBuf,0,20);
			  		if(g_eph.RecBuf[3])
			  		{	
					  	j=0;
					  	for(i=0;i<g_eph.RecBuf[3]*2;i+=2)
					  	{
	  						if(g_eph.RecBuf[i+5] == 0)
	  						{	
		  						str[j] = g_eph.RecBuf[i+5];
	  							str[j] = 0x20;
	  							j++;
		  						str[j++] = g_eph.RecBuf[i+4];
	  						}
	  						else
	  						{
	  							if(g_eph.RecBuf[i+5]>0xa0&&g_eph.RecBuf[i+4]>=0xa0)
	  							{
			  						str[j] = g_eph.RecBuf[i+5];
	  								j++;
		  							str[j++] = g_eph.RecBuf[i+4];
	  							}	
	  						}	
			  			}
				  		str[j] =0;
				  		memcpy(g_Ime.ImeBuf,str,j);
				  		memcpy(buf,&g_Ime.ImeBuf[10],10);
				  		buf[10] = 0;
			  			str[10] = 0;
			  			for(i=0;i<10;i+=2)
			  			{
			  				if(str[i]==0)
			  					break;
			  				if(str[i]==0x20)
			  					DrawTextChar(FONT12,2+6*i+3,67,str[i+1]);
			  				else
					  			DrawTextLine(FONT12,2+6*i,67,&str[i],2);
			  			}
				  		if(j>=10)
				  		{	
				  			for(i=0;i<10;i+=2)
				  			{
				  				if(buf[i]==0)
				  					break;
				  				if(buf[i]==0x20)
				  					DrawTextChar(FONT12,2+6*i+3,82,buf[i+1]);
			  					else
						  			DrawTextLine(FONT12,2+6*i,82,&buf[i],2);
			  				}
		  				}	
	  				}
	  				bWndGetResult=1;
//	  				g_eph.RecLen = 0;
	  				g_Input.Len = 2;
	  				return KEY_ENTER;
	  			}
				break;
//			case UDM_THD_READING:
//				break;
			default:
				return 0;
				break;	
		}
	}
	else
		return 0;
	}
}









⌨️ 快捷键说明

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