?? touchpanel.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"
#include "config.h"
extern ReadC(void);
int main(void)
{
if(E_OK != ModuleTouchpanel())
DBG_Printf("error in Touchpanel lab\n");
while(1);
return 1;
}
STATUS ModuleTouchpanel(void)
{
/* system initialized */
system_init();
/* initialize touchpanel */
init_Pen();
DBG_Printf("Touch Panel Initialization Succeed!\n You can Touch the Panel.\n");
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()
{
int i;
//*********Touch Screen Control register; ADDR:64H
*(RP)AC97_CRAC=WRITE + 0x640000+0x00C3; //Interupt mode
do{}while(!OVER_WRITE);
//_________________________________________________
for(i = 0; i < 100000; i++);
//*********Touch Screen Control register; ADDR:64H
*(RP)AC97_CRAC=READ + 0x640000; //Interupt mode
do{}while(!OVER_READ);
//_________________________________________________
if(*(RP)AC97_CRAC & (0x00003000))
return 0;
else
return 1;
}
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)
{
#ifdef GE00
*(RP)PORTE_DIR |= (0X1<<8);
*(RP)PORTE_SEL |= 0X1<<8;
*(RP)PORTE_INTRCTL |= 0X30000;
*(RP)PORTE_INCTL |= (0X1<<8);
*(RP)PORTE_INTRCLR |= (0X1<<8);
SPISetup();
PenRead();
irq_enable(INT_EXT8); //enable AD interrupt
unmask_irq(INT_EXT8);
#else
irq_enable(INT_EXT15); // 中斷控制器使能
touchinit();
InitAC97();
init_LCD();
unmask_irq(INT_EXT15); // 中斷unmask
#endif
}
U16 PenSPIXfer(U16 ADCommd)
{
U16 data;
/* set the command through the spi that let AD exchange data */
*(RP)SPITR = ADCommd;
*(RP)SPICR |= transenable;
while(!(( (*(RP)SPISR)) & 0x01));// wait for the data from spi
data = *(RP)SPIRR;
return data;
}
void SPISetup(void)
{
*(RP)SPICR = ctrlw;
*(RP)SPIBR = bt256;
TurnOnADS7843();
}
void TurnOnADS7843(void)
{
/* turn on Pen AD chip selected */
*(RP)PORTE_SEL |= 0X1<<9;
*(RP)PORTE_DATA &=~( 0X1 << 9);
}
void TurnOFFADS7843(void)
{
/* turn off Pen AD chip selected */
*(RP)PORTE_SEL |= 0X1<<9;
*(RP)PORTE_DATA |=( 0X1 << 9);
}
void PenEnable(void)
{
#ifdef GE00
unmask_irq(INT_EXT8);
#else
clrcodecint(); //change mode into int; clear int source and clear GPIO int.
unmask_irq(INT_EXT15);
#endif
}
void PenDisable(void)
{
#ifdef GE00
mask_irq(INT_EXT8);
#else
mask_irq(INT_EXT15);
#endif
}
STATUS PenRead(void)
{
#ifdef GE00
U16 TempX,TempY;
U16 x_upper, x_lower, y_upper, y_lower;
U16 retcmd, i;
U32 penflag;
READXY:
/* read x location */
retcmd = PenSPIXfer(x_location);
x_upper= PenSPIXfer(val_upper); // read the data from the external device
x_lower= PenSPIXfer(val_lower);
/*
TempX = ((((x_upper&0x00FF)<<8)|(x_lower&0x00FF))&0x7ff8)>>3; //AD 的精度是12位
TempX = 0xfff-TempX;
*/
TempX = ((((x_upper&0x00FF)<<8)|(x_lower&0x00FF))&0x7ff8)>>4; //AD 的精度是11位
TempX = 0x7ff-TempX;
/* read y location */
retcmd = PenSPIXfer(y_location);
y_upper= PenSPIXfer(val_upper); // read the data from the external device
y_lower= PenSPIXfer(val_lower);
/*
TempY = ((((y_upper&0x00FF)<<8)|(y_lower&0x00FF))&0x7ff8)>>3; //AD 的精度是12位
TempY = 0xfff-TempY;
*/
TempY = ((((y_upper&0x00FF)<<8)|(y_lower&0x00FF))&0x7ff8)>>4; //AD 的精度是11位
TempY = 0x7ff-TempY;
/* end conversion */
DBG_Printf("Coordinate X=%d\tY=%d\n\n",TempX,TempY);
for(i=0; i<10000; i++);
penflag = *(RP)(INTC_IRSTAT);
if((penflag&0x200) != 0)goto READXY;
return 1;
#else
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);
}
DBG_Printf("Coordinate X=%d\tY=%d\n\n",ValueX,ValueY);
for(i=0; i<10000; i++);
if((CheckPenUp()))goto READXY;
return 1;
#endif
}
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 + -