/************************** Copyright (c) **********************************
|
** FUZHOU FUGUANG ELECTRONICS Co.,LTD.
|
** ¸£Öݸ£¹âµç×ÓÓÐÏÞ¹«Ë¾
|
** http://www.fuguang.com
|
**
|
**-------------- File Info -------------------------------------------------
|
** File name: AD7843_Driver.c
|
** Last modified Date: 2008-11-16
|
** Last Version: 1.0
|
** Descriptions: AD7843 Drivers lib
|
**
|
**--------------------------------------------------------------------------
|
** Created by: mxpopstar
|
** Created date: 2008-11-16
|
** Version: 1.0
|
** Descriptions: The original version
|
**
|
**--------------------------------------------------------------------------
|
** Modified by: mxpopstar
|
** Modified date: 2008-11-20
|
** Version:
|
** Descriptions: AD7843 Drivers lib
|
**
|
***************************************************************************/
|
//
|
#include "AD7843_Driver.h"
|
#include "Define.h"
|
#include "MainMenu.h"
|
#include "AdjustValuePage.h"
|
#include "KeyBoard_Driver.h"
|
#include "TFT_Driver.h"
|
#include "MessageBox.h"
|
#include "LogoPage.h"
|
#include "SYSSetPage.h"
|
#include "SelectForm.h"
|
|
extern SYS_State GB_SYS_State;
|
|
#if(SoftLanguage == CN)
|
const prog_uchar KeySelText[3][6] =
|
{
|
{213, 208, 114, 209, 210, 211},//°´¼ü+´¥ÃþÆÁ
|
{213, 208, 101, 101, 101, 101},//°´¼ü
|
{209, 210, 211, 101, 101, 101},//´¥ÃþÆÁ
|
};
|
//
|
#else
|
const prog_uchar KeySelText[3][16] =
|
{
|
{103,73,74,75,70,68,0,68,0,110,64,73,77,74,76},//°´¼ü+´¥Ãþ15
|
{103,73,74,75,70,68,0,0,0,0,0,0,0,0,0},//°´¼ü
|
{110,64,73,77,74,76,0,0,0,0,0,0,0,0,0},//´¥ÃþÆÁ
|
};
|
//
|
#endif
|
//
|
|
static unsigned char KeySelIndex = 2;
|
static unsigned char CustomInputOFF = 0;
|
|
void InitIo_AD7843(void)
|
{
|
AD7843_CS_DDR |= (1<<AD7843_CS_PIN);
|
AD7843_SCK_DDR |= (1<<AD7843_SCK_PIN);
|
AD7843_MOSI_DDR |= (1<<AD7843_MOSI_PIN);
|
AD7843_MISO_DDR &= ~(1<<AD7843_MISO_PIN);
|
AD7843_PENIRQ_DDR &= ~(1<<AD7843_PENIRQ_PIN);
|
AD7843_PENIRQ_1;
|
|
AD7843_CS_1;
|
AD7843_SCK_0;
|
}
|
//----------------------------------------------------------------------------------
|
//function SpiWrite();
|
/**************************************************************************/
|
void SpiWrite_AD7843(const unsigned char byte)
|
{
|
unsigned char i;
|
for (i=0;i<8;i++) // Setup byte circulation bits
|
{
|
if (0x80 & (byte<<i)) // Put DATA_BUF.7 on data line
|
AD7843_MOSI_1;
|
else
|
AD7843_MOSI_0;
|
AD7843_SCK_1; // Set clock line high
|
AD7843_SCK_0; // Set clock line low
|
}
|
|
//_delay_us(1);
|
AD7843_SCK_1;
|
//_delay_us(1);
|
AD7843_SCK_0;
|
}
|
/**************************************************************************/
|
|
//function SpiRead();
|
/**************************************************************************/
|
unsigned char SpiRead_AD7843(void)
|
{
|
unsigned char i;
|
unsigned char data = 0;
|
for(i=0; i<8; i++) // Setup byte circulation bits
|
{
|
AD7843_SCK_1; // Set clock line high
|
if (AD7843_MISO_1)
|
data+=1; // Read data
|
if(i<7)
|
data<<=1;
|
AD7843_SCK_0; // Set clock line low
|
}
|
|
for(i=0; i<7; i++)
|
{
|
AD7843_SCK_1;
|
AD7843_SCK_0;
|
}
|
|
return data; // Return function parameter
|
}
|
/**************************************************************************/
|
//----------------------------------------------------------------------------------
|
unsigned char CompareValueEqual(const unsigned char x1, const unsigned char y1,
|
const unsigned char x2, const unsigned char y2)
|
{
|
unsigned char resx,resy;
|
if(x1 >= x2)
|
resx = x1-x2;
|
else resx = x2-x1;
|
|
if(y1 >= y2)
|
resy = y1-y2;
|
else resy = y2-y1;
|
|
if((resx <= 3) && (resy <= 3))
|
return 1;
|
else return 0;
|
}
|
//----------------------------------------------------------------------------------
|
|
void EnableCustomInput(void)
|
{
|
CustomInputOFF = 0;
|
}
|
void DisableCustomInput(void)
|
{
|
CustomInputOFF = 1;
|
}
|
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
void GetAndDSPKeyboardSel(void)
|
{
|
if(GB_SYS_State.CurrentPage == DSPSYSSetPage)
|
{
|
//DSP16x24Str(KeySelText[KeySelIndex], 15, 14, 276, 144, blue, white);
|
}
|
}
|
void SetKeyboardSel(const unsigned char settype)
|
{
|
if(settype == 0)
|
{
|
if(KeySelIndex++ >= 2)
|
{
|
KeySelIndex = 0;
|
}
|
}
|
else
|
{
|
if(KeySelIndex-- <= 0)
|
{
|
KeySelIndex = 2;
|
}
|
}
|
}
|
//----------------------------------------------------------------------------------
|
unsigned char GetTouchLocal(void)
|
{
|
static unsigned char lastpoint = ButtonNull;
|
|
unsigned int X1,Y1,X2,Y2;
|
unsigned char point1 = ButtonNull;
|
unsigned char point2 = ButtonNull;
|
unsigned char count = 0;
|
|
//-------------- ÊäÈ빦ÄܽûÓà ---------------
|
if( (CustomInputOFF==1) && (!(NO_AD7843_PENIRQ)) )
|
{
|
return ButtonNull;
|
}
|
else
|
{
|
EnableCustomInput();
|
}
|
|
//-------------- ÊäÈ뷽ʽѡÔñ ---------------
|
if(KeySelIndex != 2)
|
{
|
point2 = GetKeyPress();
|
if(point2 != ButtonNull)
|
return point2;
|
}
|
if(KeySelIndex == 1)
|
{
|
return ButtonNull;
|
}
|
|
//---------- ¼ì²â´¥ÃþÆÁÊÇ·ñ±»´¥Ãþ -----------
|
if(NO_AD7843_PENIRQ)
|
{
|
lastpoint = ButtonNull;
|
return ButtonNull;
|
}
|
|
//========== ¿ªÊ¼²âÁ¿´¥ÃþÆÁ´¥µç,Í˳öÇÐÎðÍü¼Ç¹Ø±ÕAD7843Ƭѡ =============
|
DDRD |= 0x02;
|
PORTD &= (~0x02); //PENirq¶Ë¿ÚÖõØ
|
AD7843_CS_0; //ѡͨAD7843
|
|
_delay_us(5);
|
|
//----------- ´ò¿ªXͨµÀ²¢²É¼¯XÖáÖµ ----------
|
Y1 = 0;
|
for(count=0; count<10; count++)
|
{
|
SpiWrite_AD7843(0x90);
|
Y1 += SpiRead_AD7843();
|
}
|
Y1 /= 10;
|
|
_delay_us(50);
|
|
//----------- ´ò¿ªYͨµÀ²¢²É¼¯YÖáÖµ ----------
|
X1 = 0;
|
for(count=0; count<10; count++)
|
{
|
SpiWrite_AD7843(0xd0);
|
X1 += SpiRead_AD7843();
|
}
|
X1 /= 10;
|
|
point1 = GetButtonDown(X1, Y1);
|
|
if((point1 != ButtonNull) && (point1 != lastpoint))
|
{
|
lastpoint = point1;
|
|
_delay_ms(30); //ÑÓʱ30msÒÔÈ¥¶¶;
|
|
//----------- ´ò¿ªXͨµÀ²¢²É¼¯XÖáÖµ ----------
|
Y2 = 0;
|
for(count=0; count<10; count++)
|
{
|
SpiWrite_AD7843(0x90);
|
Y2 += SpiRead_AD7843();
|
}
|
Y2 /= 10;
|
|
_delay_us(50);
|
|
//----------- ´ò¿ªYͨµÀ²¢²É¼¯YÖáÖµ ----------
|
X2 = 0;
|
for(count=0; count<10; count++)
|
{
|
SpiWrite_AD7843(0xd0);
|
X2 += SpiRead_AD7843();
|
}
|
X2 /= 10;
|
|
point2 = GetButtonDown(X2, Y2);
|
//----------- Èç¹û²ÉÑùÖµÕýÈ· -------------
|
if(point2 != point1)
|
{
|
//AD7843_CS_1;//¹Ø±ÕAD7843
|
point1 = ButtonNull;
|
}
|
}
|
|
AD7843_CS_1;//¹Ø±ÕAD7843
|
DDRD &= (~0x02);
|
PORTD |= 0x02;
|
//--------- È·±£Óû§µÄ´¥Ãþ»¹±£³Ö×Å ---------
|
_delay_us(10);
|
if(NO_AD7843_PENIRQ)
|
{
|
point1 = ButtonNull;
|
}
|
|
return point1;
|
}
|
//----------------------------------------------------------------------------------
|
unsigned char GetButtonDown(const unsigned char x, const unsigned char y)
|
{
|
if(GB_SYS_State.CurrentPage == DSPAdjVPage)
|
{
|
PrintValue(2, 0, x, "X", 16, 200, 16, blue, gray2);//´¥ÃþÆÁXÖáÖµ
|
PrintValue(2, 0, y, "Y", 16, 290, 16, blue, gray2);//´¥ÃþÆÁYÖáÖµ
|
}
|
|
if(GB_SYS_State.CurrentPage == DSPLogoPage)
|
{
|
if(((x>20)&&(x<220))&&((y>20)&&(y<220)))//
|
{
|
return MenuItem0;
|
}
|
}
|
|
else if((GB_SYS_State.CurrentPage==DSPMainMenu)
|
||(GB_SYS_State.CurrentPage==DSPSelectForm))
|
{
|
if(((x>153)&&(x<216)) && ((y>175)&&(y<200))) //·Åµç²âÊÔ
|
{
|
return MenuItem0;
|
}
|
|
else if(((x>42)&&(x<106))&&((y>175)&&(y<200))) //³äµç²âÊÔ
|
{
|
return MenuItem1;
|
}
|
|
else if(((x>153)&&(x<216))&&((y>128)&&(y<152))) //"Êý¾Ý¹ÜÀí"
|
{
|
return MenuItem2;
|
}
|
|
else if(((x>42)&&(x<106))&&((y>128)&&(y<152))) //"²ÎÊýÉèÖÃ"
|
{
|
return MenuItem3;
|
}
|
|
else if(((x>153)&&(x<216))&&((y>79)&&(y<105))) //"²é¿´µ¥Ìå"
|
{
|
return MenuItem4;
|
}
|
|
else if(((x>42)&&(x<106))&&((y>79)&&(y<105))) //"²ÎÊýÔ¤ÖÃ"
|
{
|
return MenuItem5;
|
}
|
else if(((y>=25)&&(y<=57)) && ((x>=155)&&(x<=189))) //Ñ¡Ôñ
|
{
|
return Button1;
|
}
|
else if(((y>=25)&&(y<=57)) && ((x>=62)&&(x<=98))) //È·¶¨
|
{
|
return Button3;
|
}
|
}
|
|
else if(GB_SYS_State.CurrentPage == DSPMessageBoxNull)
|
{
|
if(((y>=90)&&(y<=116)) && ((x>=156)&&(x<=190))) //È·¶¨
|
{
|
return Button1;
|
}
|
else if(((y>=90)&&(y<=116)) && ((x>=60)&&(x<=92))) //È¡Ïû
|
{
|
return Button3;
|
}
|
else if(((y>=90)&&(y<=116)) && ((x>=110)&&(x<=145)))//µ¥¸öÈ·¶¨
|
{
|
return Button2;
|
}
|
}
|
|
else
|
{
|
if(((y>=25)&&(y<=57)) && ((x>=202)&&(x<=235))) //·Åµç
|
{
|
return Button0;
|
}
|
else if(((y>=25)&&(y<=57)) && ((x>=156)&&(x<=189))) //Í£Ö¹
|
{
|
return Button1;
|
}
|
else if(((y>=25)&&(y<=57)) && ((x>=110)&&(x<=144))) //µ¥Ìå
|
{
|
return Button2;
|
}
|
else if(((y>=25)&&(y<=57)) && ((x>=64)&&(x<=97))) //Ô¤ÖÃ
|
{
|
return Button3;
|
}
|
else if(((y>=25)&&(y<=57)) && ((x>=17)&&(x<=50))) //Í˳ö
|
{
|
return Button4;
|
}
|
else if(((y>=78)&&(y<=100)) && ((x>=17)&&(x<=50))) //È¡Ïû
|
{
|
return Button5;
|
}
|
else if(((y>=118)&&(y<=141)) && ((x>=17)&&(x<=50))) //-
|
{
|
return Button6;
|
}
|
else if(((y>=160)&&(y<=181)) && ((x>=17)&&(x<=50))) //+
|
{
|
return Button7;
|
}
|
else if(((y>=198)&&(y<=221)) && ((x>=17)&&(x<=50)))//ÐÞ¸Ä
|
{
|
return Button8;
|
}
|
}
|
|
return ButtonNull;
|
}
|
//
|