2009-12-11 17:42:01 +08:00
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtthread.h>
|
2009-12-18 13:25:41 +08:00
|
|
|
#include <s3c24x0.h>
|
2009-12-29 23:08:26 +08:00
|
|
|
#include <rtgui/event.h>
|
|
|
|
#include <rtgui/rtgui_server.h>
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
/* ADCCON Register Bits */
|
|
|
|
#define S3C2410_ADCCON_ECFLG (1<<15)
|
|
|
|
#define S3C2410_ADCCON_PRSCEN (1<<14)
|
|
|
|
#define S3C2410_ADCCON_PRSCVL(x) (((x)&0xFF)<<6)
|
|
|
|
#define S3C2410_ADCCON_PRSCVLMASK (0xFF<<6)
|
|
|
|
#define S3C2410_ADCCON_SELMUX(x) (((x)&0x7)<<3)
|
|
|
|
#define S3C2410_ADCCON_MUXMASK (0x7<<3)
|
|
|
|
#define S3C2410_ADCCON_STDBM (1<<2)
|
|
|
|
#define S3C2410_ADCCON_READ_START (1<<1)
|
|
|
|
#define S3C2410_ADCCON_ENABLE_START (1<<0)
|
|
|
|
#define S3C2410_ADCCON_STARTMASK (0x3<<0)
|
|
|
|
|
|
|
|
|
|
|
|
/* ADCTSC Register Bits */
|
|
|
|
#define S3C2410_ADCTSC_UD_SEN (1<<8) /* ghcstop add for s3c2440a */
|
|
|
|
#define S3C2410_ADCTSC_YM_SEN (1<<7)
|
|
|
|
#define S3C2410_ADCTSC_YP_SEN (1<<6)
|
|
|
|
#define S3C2410_ADCTSC_XM_SEN (1<<5)
|
|
|
|
#define S3C2410_ADCTSC_XP_SEN (1<<4)
|
|
|
|
#define S3C2410_ADCTSC_PULL_UP_DISABLE (1<<3)
|
|
|
|
#define S3C2410_ADCTSC_AUTO_PST (1<<2)
|
|
|
|
#define S3C2410_ADCTSC_XY_PST(x) (((x)&0x3)<<0)
|
|
|
|
|
|
|
|
/* ADCDAT0 Bits */
|
|
|
|
#define S3C2410_ADCDAT0_UPDOWN (1<<15)
|
|
|
|
#define S3C2410_ADCDAT0_AUTO_PST (1<<14)
|
|
|
|
#define S3C2410_ADCDAT0_XY_PST (0x3<<12)
|
|
|
|
#define S3C2410_ADCDAT0_XPDATA_MASK (0x03FF)
|
|
|
|
|
|
|
|
/* ADCDAT1 Bits */
|
|
|
|
#define S3C2410_ADCDAT1_UPDOWN (1<<15)
|
|
|
|
#define S3C2410_ADCDAT1_AUTO_PST (1<<14)
|
|
|
|
#define S3C2410_ADCDAT1_XY_PST (0x3<<12)
|
|
|
|
#define S3C2410_ADCDAT1_YPDATA_MASK (0x03FF)
|
|
|
|
|
|
|
|
#define WAIT4INT(x) (((x)<<8) | \
|
|
|
|
S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
|
|
|
S3C2410_ADCTSC_XY_PST(3))
|
|
|
|
|
|
|
|
#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
|
|
|
S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
|
|
|
|
|
|
|
|
struct s3c2410ts
|
|
|
|
{
|
|
|
|
long xp;
|
|
|
|
long yp;
|
|
|
|
int count;
|
|
|
|
int shift;
|
|
|
|
|
|
|
|
int delay;
|
|
|
|
int presc;
|
|
|
|
|
|
|
|
char phys[32];
|
|
|
|
};
|
|
|
|
static struct s3c2410ts ts;
|
|
|
|
|
|
|
|
#define X_MIN 74
|
|
|
|
#define X_MAX 934
|
2010-01-29 08:32:32 +08:00
|
|
|
#define Y_MIN 89
|
|
|
|
#define Y_MAX 920
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_RTGUI
|
|
|
|
#include <rtgui/event.h>
|
|
|
|
void report_touch_input(int updown)
|
|
|
|
{
|
2010-03-25 09:15:28 +08:00
|
|
|
long xp, yp;
|
2009-12-11 17:42:01 +08:00
|
|
|
struct rtgui_event_mouse emouse;
|
|
|
|
|
2010-03-25 09:15:28 +08:00
|
|
|
xp = ts.xp >> ts.shift;
|
|
|
|
yp = ts.yp >> ts.shift;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2010-03-25 09:15:28 +08:00
|
|
|
xp = 240 * (xp-X_MIN)/(X_MAX-X_MIN);
|
|
|
|
yp = 320 - (320*(yp-Y_MIN)/(Y_MAX-Y_MIN));
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
|
|
|
emouse.parent.sender = RT_NULL;
|
|
|
|
|
2010-03-25 09:15:28 +08:00
|
|
|
emouse.x = xp;
|
|
|
|
emouse.y = yp;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
/* set emouse button */
|
|
|
|
if (updown)
|
|
|
|
{
|
|
|
|
emouse.button = RTGUI_MOUSE_BUTTON_DOWN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emouse.button = RTGUI_MOUSE_BUTTON_UP;
|
|
|
|
}
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
/* rt_kprintf("touch %s: ts.x: %d, ts.y: %d, count:%d\n", updown? "down" : "up",
|
2010-03-25 09:15:28 +08:00
|
|
|
xp, yp, ts.count); */
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
emouse.button |= RTGUI_MOUSE_BUTTON_LEFT;
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
rtgui_server_post_event((&emouse.parent), sizeof(emouse));
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int first_down_report;
|
2010-01-29 08:32:32 +08:00
|
|
|
/* fixed me, use timer to support move action */
|
|
|
|
static void touch_timer_fire(void)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
2010-01-29 08:32:32 +08:00
|
|
|
if (ts.count == 3)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
2010-01-29 08:32:32 +08:00
|
|
|
if (first_down_report)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
|
|
|
#ifdef RT_USING_RTGUI
|
2010-01-29 08:32:32 +08:00
|
|
|
report_touch_input(1);
|
|
|
|
first_down_report = 0;
|
2009-12-11 17:42:01 +08:00
|
|
|
#endif
|
|
|
|
}
|
2010-01-29 08:32:32 +08:00
|
|
|
}
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
|
|
|
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void s3c2410_adc_stylus_action()
|
|
|
|
{
|
|
|
|
rt_uint32_t data0;
|
|
|
|
rt_uint32_t data1;
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
SUBSRCPND |= BIT_SUB_ADC;
|
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
data0 = ADCDAT0;
|
|
|
|
data1 = ADCDAT1;
|
2010-01-29 08:32:32 +08:00
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
ts.xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK;
|
|
|
|
ts.yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK;
|
|
|
|
ts.count++;
|
|
|
|
|
|
|
|
if (ts.count < (1<<ts.shift))
|
|
|
|
{
|
|
|
|
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
|
|
|
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-29 08:32:32 +08:00
|
|
|
//touch_timer_fire();
|
2009-12-11 17:42:01 +08:00
|
|
|
ADCTSC = WAIT4INT(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void s3c2410_intc_stylus_updown()
|
|
|
|
{
|
|
|
|
rt_uint32_t data0;
|
|
|
|
rt_uint32_t data1;
|
|
|
|
int updown;
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
SUBSRCPND |= BIT_SUB_TC;
|
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
data0 = ADCDAT0;
|
|
|
|
data1 = ADCDAT1;
|
|
|
|
|
|
|
|
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
if (updown)
|
|
|
|
{
|
|
|
|
touch_timer_fire();
|
|
|
|
}
|
2009-12-11 17:42:01 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ts.xp >= 0 && ts.yp >= 0)
|
|
|
|
{
|
|
|
|
#ifdef RT_USING_RTGUI
|
2010-03-25 09:15:28 +08:00
|
|
|
report_touch_input(1);
|
2010-01-29 08:32:32 +08:00
|
|
|
report_touch_input(0);
|
2009-12-11 17:42:01 +08:00
|
|
|
first_down_report = 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
ts.xp = 0;
|
|
|
|
ts.yp = 0;
|
|
|
|
ts.count = 0;
|
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
ADCTSC = WAIT4INT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_touch_handler(int irqno)
|
|
|
|
{
|
|
|
|
if (SUBSRCPND & (1 << 10))
|
|
|
|
{
|
|
|
|
/* INT_SUB_ADC */
|
|
|
|
s3c2410_adc_stylus_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUBSRCPND & (1 << 9))
|
|
|
|
{
|
|
|
|
/* INT_SUB_TC */
|
|
|
|
s3c2410_intc_stylus_updown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear interrupt */
|
2009-12-29 23:08:26 +08:00
|
|
|
INTPND |= (rt_uint32_t)(1 << INTADC);
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_touch_init()
|
|
|
|
{
|
|
|
|
/* init touch screen structure */
|
|
|
|
rt_memset(&ts, 0, sizeof(struct s3c2410ts));
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
ts.delay = 50000;
|
|
|
|
ts.presc = 9;
|
2009-12-11 17:42:01 +08:00
|
|
|
ts.shift = 2;
|
2010-01-29 08:32:32 +08:00
|
|
|
ts.count = 0;
|
|
|
|
ts.xp = ts.yp = 0;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
ADCCON = S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(ts.presc);
|
|
|
|
ADCDLY = ts.delay;
|
|
|
|
|
|
|
|
ADCTSC = WAIT4INT(0);
|
|
|
|
|
|
|
|
rt_hw_interrupt_install(INTADC, rt_touch_handler, RT_NULL);
|
|
|
|
rt_hw_interrupt_umask(INTADC);
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
/* clear interrupt */
|
|
|
|
INTPND |= (rt_uint32_t)(1 << INTADC);
|
|
|
|
|
|
|
|
SUBSRCPND |= BIT_SUB_TC;
|
|
|
|
SUBSRCPND |= BIT_SUB_ADC;
|
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
/* install interrupt handler */
|
|
|
|
INTSUBMSK &= ~BIT_SUB_ADC;
|
|
|
|
INTSUBMSK &= ~BIT_SUB_TC;
|
|
|
|
|
|
|
|
first_down_report = 1;
|
|
|
|
}
|