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

📄 touchpanel.c

📁 最常用的嵌入式LINUX字符设备驱动:触摸屏和小键盘驱动。触摸屏使用SPI接口
💻 C
📖 第 1 页 / 共 2 页
字号:
		flag = PEN_UP;printk("collateflag = %d\n",collateflag);		break;	case 2:		// 结束校验		collateflag = 0;		collatepos = 0;		SCX = 320.0f / (float)(DX1 - DX);		SCY = 240.0f / (float)(DY1 - DY);		pre_pos.x = 160;		pre_pos.y = 120;		cur_pos.x = 160;		cur_pos.y = 120;/*				// 将DX,DY,SCX,SCY 保存到FLASH中		save = kmalloc(LENGTH,GFP_KERNEL);		if (NULL == save)			break;		p = save;		*p++ = 'F';		*p++ = 'L';		*p++ = 'A';		*p++ = 'S';		*p++ = 'H';		q = (unsigned char*)&DX;		for (i=0;i<INTLEN;i++)			*p++ = *q++;		q = (unsigned char*)&DY;		for (i=0;i<INTLEN;i++)			*p++ = *q++;		q = (unsigned char*)&SCX;		for (i=0;i<FLOATLEN;i++)			*p++ = *q++;		q = (unsigned char*)&SCY;		for (i=0;i<FLOATLEN;i++)			*p++ = *q++;		if (fwriteflash(FLASHBLKID,OFFSET,save,LENGTH))			printk("write flash error!\n");		else		{			printk("write flast -- DX = %d\n",DX);			printk("write flast -- DY = %d\n",DY);			printk("write flast -- SCX = %d\n",(unsigned int)(SCX*1000));			printk("write flast -- SCY = %d\n",(unsigned int)(SCY*1000));		}		kfree(save);*/		break;	case 3:		// 进入手写输入		collateflag = 2;		writedelay = 0;		flag = PEN_UP;		keyflag = 0;		// 关闭笔中断,打开时间中断		memset(&pointbuf,0,sizeof(struct trackbuf));		sendtrack = 1;		printk("enable the time interrupt!\n");		cli();			disable_irq(17|0x10000000);		// Set the irq6 bit to the input port			PDDIR = PDDIR & 0xdf;//0x7f;			PDSEL = PDSEL | 0x20;//0x80;			enable_irq(5|0x10000000);		*((unsigned short*)0xfffff610) = 0x0019;		*((unsigned short*)0xFFFFF61A) = 0;			sti();		break;	case 4:		// 退出手写输入		collateflag = 0;		memcpy(videobuf,videobackup,VIDEOLEN);		printk("disable the time interrupt!\n");		// 关闭时间中断,打开笔中断		cli();		disable_irq(5|0x10000000);		*((unsigned short*)0xfffff610) = 0x0018;		enable_irq(17|0x10000000);		PDSEL = PDSEL & 0xdf;		sti();		break;	case 5:		// 送手写轨迹给应用程序		pbuf = (struct trackbuf*)arg;		if (resourchflag == 1)		{			pbuf->flag = 1;			break;		}		resourchflag = 1;		if (pointbuf.flag == 1)		{			memcpy(pbuf->track,pointbuf.track,20000);			pbuf->endpos = pointbuf.endpos;			pbuf->pointcount = pointbuf.pointcount;			pbuf->flag = pointbuf.flag;			memset(&pointbuf,0,sizeof(struct trackbuf));			memcpy(videobuf,videobackup,VIDEOLEN);		}		else		{			// 如果一个字的轨迹还未结束,则不返回			pbuf->flag = 0;		}		resourchflag = 0;		break;	case 6:		// 设置手写键盘的参数(位置信息)		prect = (struct keyboard*)arg;		boardrect.x = prect->x;		boardrect.y = prect->y;		boardrect.x1 = prect->x1;		boardrect.y1 = prect->y1;		break;	case 7:		// Save the LCD interface		memcpy(videobackup,videobuf,VIDEOLEN);		break;	case 8:		// resume the LCD interface		memcpy(videobuf,videobackup,VIDEOLEN);		break;	}	return 1;}struct file_operations touch_fops = {	NULL,	touch_read,	NULL,	NULL,	touch_select,	touch_ioctl,	NULL,	touch_open,	touch_close,	NULL,	NULL,	NULL,	NULL};/************************************************************函数原型: void Get_Coordinate(int* xpos, int* ypos);功    能: this function communicate with ADS7846 and get the touch		panel data.输入参数: int* xpos:the x value.	  int* ypos:the y value.返 回 值: return NULL.************************************************************/int Get_Coordinate(){	PFDATA = PFDATA & 0xfe;    	//Select ADS7846 CS = 0;	SPIMCONT = SPIMCONT | 0x0200;	//0x0200;	// get the 1st coordinate	SPIMDATA = 0xd3;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.y[0]=(SPIMDATA & 0x0fff);	SPIMDATA = 0x93;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.x[0]=(SPIMDATA & 0x0fff);	// get the 2nd coordinate	SPIMDATA = 0xd3;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.y[1]=(SPIMDATA & 0x0fff);	SPIMDATA = 0x93;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.x[1]=(SPIMDATA & 0x0fff);	// get the 3rd coordinate	SPIMDATA = 0xd3;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.y[2]=(SPIMDATA & 0x0fff);	SPIMDATA = 0x93;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.x[2]=(SPIMDATA & 0x0fff);	// get the 4th coordinate/*	SPIMDATA = 0xd3;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.y[3]=(SPIMDATA & 0x0fff);	SPIMDATA = 0x93;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.x[3]=(SPIMDATA & 0x0fff);	// get the 5th coordinate	SPIMDATA = 0xd3;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.y[4]=(SPIMDATA & 0x0fff);	SPIMDATA = 0x93;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);	filter.x[4]=(SPIMDATA & 0x0fff);*/	//	SPIMDATA = 0x80;	SPIMCONT = SPIMCONT | 0x0100;	while(SPIMCONT & 0x0100);		PFDATA = PFDATA | 0x01;		//ADS7846 CS = 1	SPIMCONT = SPIMCONT & 0xfdff;	return 0;}// [Added++] by Aavan, 2002/09/04/*intGetMidVal(int *pnVals, short sCount){	int tempVal;	short i, j, max;	for (i = 0; i < 3; i++) {		max = i;		for (j = i; j < sCount; j++) {			if (pnVals[j] > pnVals[max])				max = j;		}		if (max != i) {			tempVal = pnVals[max];			pnVals[max] = pnVals[i];			pnVals[i] = tempVal;		}	}	return (pnVals[(sCount >> 1) + (sCount & 1)]);}*/intGetMidVal(int val1, int val2, int val3, int ref){	int r1, r2, r3;	r1 = (val1 > ref ? val1 - ref : ref - val1);	r2 = (val2 > ref ? val2 - ref : ref - val2);	r3 = (val3 > ref ? val3 - ref : ref - val3);	if (r1 <= r2 && r1 <= r3)		return (val1);	else if (r3 <= r1 && r3 <= r2)		return (val3);	else		return (val2);}// [Added--]static int x,y;static float fx,fy;static int xtmp,ytmp; //,i;/************************************************************函数原型: void touch_irq_handler(int irq, void* dev_id, struct pt_regs* regs);功    能: this function process the pen interrupt(when pen down).输入参数: all arguments not used.返 回 值: return NULL.************************************************************/void touch_irq_handler(int irq, void* dev_id, struct pt_regs* regs){	cli();	disable_irq(17|0x10000000);	// Set the irq6 bit to the input port		PDDIR = PDDIR & 0xdf;//0x7f;		PDSEL = PDSEL | 0x20;//0x80;	enable_irq(5|0x10000000);	*((unsigned short*)0xfffff610) = 0x0019;	//Enable Timer2 Added by zhangjz	*((unsigned short*)0xFFFFF61A) = 0;	//pen down	//	cli();		Get_Coordinate();		sti();		gX = GetMidVal(filter.x[0], filter.x[1], filter.x[2], gOldX);		gY = GetMidVal(filter.y[0], filter.y[1], filter.y[2], gOldY);		gOldX = gX;		gOldY = gY;//	sti();}//static int sx,sy;/************************************************************

⌨️ 快捷键说明

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