📄 touch.c
字号:
/*************************************************************************/
/* */
/* Copyright Shenzhen Watertek S.&T. Co.,Ltd 2002 */
/* All Rights Reserved. */
/* */
/* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS */
/* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS */
/* SUBJECT TO LICENSE TERMS. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* usbmain.c S3c2410 USB device 1.0*/
/* */
/* */
/* DESCRIPTION */
/* */
/* This file contains macro and main routines */
/* */
/* AUTHOR */
/* Zhi-gang yang shenzhen watertek */
/* */
/* */
/* DATA STRUCTURES */
/* */
/* Ep3Handler EP3 interrupt handler */
/* PrintEpoPkt print ep out packet for debug */
/* RdPktEp3_CheckSum No use */
/* IsrDma2 DMA interrupt handler,No use in this*/
/* case */
/* ClearEp3OutPktReady clear endpoint 3 packet out tag */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 2004-12-27 Created initial version 1.0 */
/*************************************************************************/
#include <string.h>
#include <stdarg.h>
#include "2410addr.h"
#include "def.h"
void Led1_On_or_Off(int flag);
void Led2_On_or_Off(int flag);
void Led4_On_or_Off(int flag);
void clrsrc(void);
int setpixel(int x,int y,unsigned short pencolor);
void INT_ADC_Enable(int flag);
void tp_rewaite_int(void);
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* C_Entry */
/* */
/* DESCRIPTION */
/* */
/* C entry function */
/* */
/* AUTHOR */
/* */
/* Zhi-gang Yang shenzhen watertek */
/* */
/* INPUTS */
/* None */
/* */
/* OUTPUTS */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 2004-12-28 Created initial version 1.0 */
/*************************************************************************/
void C_Entry()
{
INT_ADC_Enable(TRUE);
while(10);
;
}
void adcdly(int number)
{
int i,t;
/*delaying the time*/
for (i=0;i<number;i++)
{
for (t=0;t<0x100;t++);
}
}
void tp_rewaite_int(void)
{
/*define the pointer varible point to the register*/
int *p_adctsc;
p_adctsc=(int *)ADCTSC;
*p_adctsc=0xd3; /*confingure the register ADCTSC renable the touchpanel interrupt*/
}
int adc_x_position()
{
/*define the pointer varible and point to the register*/
volatile int *p_adccon;
int *p_adctsc;
int *p_adcdat1;
int adc_xdata,x_data;
p_adccon=(int *)ADCCON;
p_adctsc=(int *)ADCTSC;
p_adcdat1=(int *)ADCDAT1;
/*confingure the ADCTSC register and begin the X axis covision*/
*p_adctsc=0x9a;
*p_adccon=0x7ff9;
while(!(*p_adccon & 0x8000)); /*if the covision is end?*/
adcdly(1); /*delay little time for more nicety */
adc_xdata=(*p_adcdat1)&0x3ff; /*get the value from register ADCADT0*/
x_data=(0x3c8-adc_xdata)*320/TP_XRAGE;/*covert the alue to coordinate*/
return x_data;
}
int adc_y_position()
{
/*define the pointer varible and point to the register*/
volatile int *p_adccon;
int *p_adctsc;
int *p_adcdat0;
int adc_ydata,y_data;
p_adccon=(int *)ADCCON;
p_adctsc=(int *)ADCTSC;
p_adcdat0=(int *)ADCDAT0;
*p_adctsc=0x69; /*confingure the ADCTSC register and begin the Y axis covision*/
*p_adccon=0x7FE9;
while(!(*p_adccon & 0x8000)); /*if the covision is end?*/
adcdly(1); /*delay little time for more nicety */
adc_ydata=(*p_adcdat0)&0x3ff; /*get the value from register ADCADT0*/
y_data=(0x3c8-adc_ydata)*240/TP_YRAGE;/*covert the alue to coordinate*/
return y_data;
}
void TouchPanel_LISR(void)
{
volatile int xPosition;
volatile int yPosition;
yPosition = adc_y_position();
xPosition = adc_x_position();
tp_rewaite_int();
}
int setpixel(int x,int y,unsigned short pencolor)
{
int movetop; /*THE PIXEL ADDRESS*/
short *p;
if (x<0||x>(int)x_limit) return ERROR;
if (y<0||y>(int)y_limit) return ERROR;
/*指向所要显示的像素偏移地址*/
movetop=(x*x_size+y)*2;//一个像素占两个字节
p=(short *)(VideoAddrStart+movetop);
*p=pencolor;
return 1;
}
void clrsrc(void)
{
short *p;
for(p=(short*)VideoAddrStart;p<(short*)VideoAddrEnd;p++) *p=0;
return ;
}
void Led1_On_or_Off(int flag)
{
int temp;
if(flag ==TRUE) //led1 on
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<8);
temp = rGPFDAT;
rGPFDAT = temp&(0<<4);
}
else //led1 off
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<8);
temp = rGPFDAT;
rGPFDAT = temp|(1<<4);
}
}
void Led2_On_or_Off(int flag)
{
int temp;
if(flag ==TRUE) //led1 on
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<10);
temp = rGPFDAT;
rGPFDAT = temp&(0<<5);
}
else //led1 off
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<10);
temp = rGPFDAT;
rGPFDAT = temp|(1<<5);
}
}
void Led3_On_or_Off(int flag)
{
int temp;
if(flag ==TRUE) //led1 on
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<12);
temp = rGPFDAT;
rGPFDAT = temp&(0<<6);
}
else //led1 off
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<12);
temp = rGPFDAT;
rGPFDAT = temp|(1<<6);
}
}
void Led4_On_or_Off(int flag)
{
int temp;
if(flag ==TRUE) //led1 on
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<14);
temp = rGPFDAT;
rGPFDAT = temp&(0<<7);
}
else //led1 off
{
//set GPF4
temp = rGPFCON;
rGPFCON = temp |(1<<14);
temp = rGPFDAT;
rGPFDAT = temp|(1<<7);
}
}
void INT_ADC_Enable(int flag)
{
int temp;
if(flag == FALSE)
{
temp = rINTSUBMSK;
temp |=(1<<10);
rINTSUBMSK = temp;
temp = rINTMSK;
temp |=0x80000000;
rINTMSK = temp;
}
else
{
temp = rINTSUBMSK;
temp = 0x5ff;
rINTSUBMSK = temp;
temp = rINTMSK;
temp &= ~(0x80000000) ;
rINTMSK = temp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -