📄 drv_touch.c
字号:
#include "sysMCU.h"
#include "sysGUI.h"
extern unsigned short x_avrg;
extern unsigned short y_avrg;
extern unsigned short x_add[AD_DATA_NUM]; // A/D data of T/P x axes
extern unsigned short y_add[AD_DATA_NUM]; // A/D data of T/P y axes
extern unsigned char x_tp_map[256];//814
extern unsigned char y_tp_map[512];//814
extern unsigned char keytemp,k5_data;// define in drv_key.c
extern unsigned short bKeyStatus; // Key status 0: up 1:down define in drv_key.c
int times;
unsigned short get_avrg(unsigned short *);
/****************************************
* init_io
* Type : void
* Ret val : none
* Argument : void
* Function : Initialize TouchPanel,AD I/O port;
* Initialize Interrupt K63 port interrupt FPT3.
****************************************/
void init_io(void)
{
// set p02(BXH),p03(BXL),p15(BYH),p16(BYL) as touch panel control IO PORT
*(volatile unsigned char *)IO_CFP0_ADDR &= 0x03;
*(volatile unsigned char *)IO_CFP1_ADDR &= 0x90;
//set p02,p03,p15,p16 output
*(volatile unsigned char *)IO_IOC0_ADDR |= 0x0c;
*(volatile unsigned char *)IO_IOC1_ADDR |= 0x60;
// set P15(BYH)=1,P02(BXH)=1,P16(BYL)=1,P03(BXL)=0
*(volatile unsigned char *)IO_P0D_ADDR &= 0xf7;
*(volatile unsigned char *)IO_P0D_ADDR |= 0xf4;
*(volatile unsigned char *)IO_P1D_ADDR |= 0x60;
//select k62 as interrupt factor FPT2 input port
*(volatile unsigned char *)IN_SPT0_SPT3_ADDR &=0xcf;
*(volatile unsigned char *)IN_SPT0_SPT3_ADDR |=IN_SPT2_K62;
//select input signal polarity for port interrupt generation,low level
*(volatile unsigned char *)IN_SPP_ADDR &=0x0fb;
//select an edge trigger for port interrupt generation
*(volatile unsigned char *)IN_SEP_ADDR |=0x04;
//set FPT2 interrupt priority
*(volatile unsigned char *)INT_PP2_PP3_ADDR &=0xf0;
*(volatile unsigned char *)INT_PP2_PP3_ADDR |=INT_PRIL_LVL4;
//set k60,k61 as touch panel ad input port
*(volatile unsigned char *)IN_CFK6_ADDR |=0x03;
//[0x40181], select perscaler clock source : OCS3
*(volatile unsigned char *)OSC_PSCDT0_ADDR = OSC_PSCDT0_OSC3;
// set input clock :recommended maximum clock is 2M and ad convert time is 10us
//fpscin/32 is set and selected clock is output from prescale to ad convert
*(volatile unsigned char *)PRESC_PSAD_ADDR = 0x0c;
//select A/D start AD0 and end chanel AD0
*(volatile unsigned char *)AD_CS_ADDR = AD_CE_0 | AD_CS_0;
//A/D converter enable, A/D converter stop, A/D converter over write error clear
*(volatile unsigned char *)AD_OWE_ADDR = AD_ADE_ENA | AD_ADST_STOP | AD_OWE_NOERR;
//select A/D normal mode & trigger by software
*(volatile unsigned char *)AD_CH_ADDR = AD_TS_SOFT;
//select the sampling time x9 clock
*(volatile unsigned char *)AD_ST_ADDR = AD_ST_9;
//set AD Interrupt request on,not IDMA request on
*(volatile unsigned char *)INT_RS1_RADE_RP4_ADDR &=0xFD;
//set AD interrupt level 7
*(volatile unsigned char *)INT_PSIO1_PAD_ADDR &= 0x0f;
*(volatile unsigned char *)INT_PSIO1_PAD_ADDR |= INT_PRIH_LVL4;
//Reset A/D converter interrupt factor flag
*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR |= INT_FADE;
//set AD interrupt enable
//*(volatile unsigned char *)INT_EADE_ECTM_EP4_ADDR |= INT_EADE;
// [0x40270]
//set FPT2 interrupt enable
// *(volatile unsigned char *)INT_EP0_EK_ADDR |= 0x04;
}
void enable_tp_int(void)
{
*(volatile unsigned char *)0x40280 |= 0x04;
//set FPT2 interrupt enable
*(volatile unsigned char *)INT_EP0_EK_ADDR |= 0x04;
}
/*******************************************************************************
* int_TP
* Type : void
* Ret val : none
* Argument : void
* Function : touch panel interrupt fuction
* k63 used as touch panel hardware interrupt input port
*******************************************************************************/
void int_TP(void)
{
asm("pushn %r15");
// [0x40270]
//set FPT2 interrupt disable
*(volatile unsigned char *)INT_EP0_EK_ADDR &= 0x0fb;
// reset k62 interrupt flag
*(volatile unsigned char *)INT_FP0_FK_ADDR |= 0x04;
iset_flg(GUI_EVENTID,0x001);//added for Upper layer indication
asm("popn %r15");
asm("reti");
}
/*******************************************************************************
* get_adjust_point
* Type : void
* out put : x,y ad data value
* Argument : void
* Function : get pendown point coordinate value when adjust touch panel
*******************************************************************************/
void get_adjust_point(void)
{
*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR |= 0x01; /* Reset A/D interrupt factor flag*/
times = 0;
while (times<AD_DATA_NUM)
{
{ int i;
for (i = 0;i< 100;i++)
asm("nop");
}
// Sample Rx:BXH(P02)=0;BXL(P03)=1;BYH(P15)=1;BYL(P16)=0
*(volatile unsigned char *)IO_P0D_ADDR &= 0xfb;
*(volatile unsigned char *)IO_P1D_ADDR &= 0xbf;
*(volatile unsigned char *)IO_P0D_ADDR |= 0x08;
*(volatile unsigned char *)IO_P1D_ADDR |= 0x20;
*(volatile unsigned char *)AD_CS_ADDR = (AD_CE_1 | AD_CS_1); /* AD1 for Rx sampling */
*(volatile unsigned char *)AD_OWE_ADDR |= AD_ADST_RUN; // start run AD
// waiting Rx coordinate got
//cIntFlag = *(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR;
while ( !( *(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR & 0x01))
{
//cIntFlag = *(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR;
}
*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR |= 0x01; /* Reset A/D interrupt factor flag*/
x_add[times] = *(volatile unsigned short *)AD_ADD_ADDR; // got Rx data
times++;
}
times = 0;
while (times<AD_DATA_NUM)
{
// waiting when the voltage stable
{ int i;
for (i = 0;i< 100;i++)
asm("nop");
}
// Sample Ry:BXH(P02)=1;BXL(P03)=0;BYH(P15)=0;BYL(P16)=1
*(volatile unsigned char *)IO_P0D_ADDR &= 0xf7;
*(volatile unsigned char *)IO_P1D_ADDR &= 0xdf;
*(volatile unsigned char *)IO_P0D_ADDR |= 0x04;
*(volatile unsigned char *)IO_P1D_ADDR |= 0x40;
// waiting when the voltage stable
*(volatile unsigned char *)AD_CS_ADDR = (AD_CE_0 | AD_CS_0); /* AD0 for Ry sampling*/
*(volatile unsigned char *)AD_OWE_ADDR |= AD_ADST_RUN; // start run AD
//cIntFlag = *(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR;
while ( !(*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR & 0x01))
{
//cIntFlag = *(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR;
}
*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR |= 0x01; /* Reset A/D interrupt factor flag*/
y_add[times] = *(volatile unsigned short *)AD_ADD_ADDR; // got Ry data
times++;
}
x_avrg = get_avrg(x_add);
y_avrg = get_avrg(y_add);
// set P15(BYH)=1,P02(BXH)=1,P16(BYL)=1,P03(BXL)=0
*(volatile unsigned char *)IO_P0D_ADDR &= 0xf7;
*(volatile unsigned char *)IO_P0D_ADDR |= 0xf4;
*(volatile unsigned char *)IO_P1D_ADDR |= 0x60;
}
/******************************************************************
* FUNCTION: fnIHL_GetPenPoint
*
* PURPOSE:
* get the coordinate of touch point
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
void fnIHL_GetPenPoint(unsigned short *xposition, unsigned short *yposition)
{
unsigned short num;
get_adjust_point();
//convert ad data to lcd coordinate value
num=x_avrg/4;
*yposition = x_tp_map[num];
num=y_avrg/2;
*xposition = y_tp_map[num];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -