2010-12-23 11:13:14 +08:00
|
|
|
/*
|
|
|
|
* File : touch.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
2012-08-01 12:13:41 +08:00
|
|
|
* COPYRIGHT (C) 2010 - 2012, RT-Thread Develop Team
|
2010-12-23 11:13:14 +08:00
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
|
|
|
* http://www.rt-thread.org/license/LICENSE
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2010-01-01 Yi.Qiu first version
|
|
|
|
*/
|
|
|
|
|
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>
|
2010-10-02 23:45:09 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_RTGUI
|
2010-05-15 00:52:21 +08:00
|
|
|
#include <rtgui/rtgui_system.h>
|
2009-12-29 23:08:26 +08:00
|
|
|
#include <rtgui/rtgui_server.h>
|
2010-05-15 09:11:18 +08:00
|
|
|
#include <rtgui/event.h>
|
2010-10-02 23:45:09 +08:00
|
|
|
#endif
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
#include "lcd.h"
|
2010-05-15 00:52:21 +08:00
|
|
|
#include "touch.h"
|
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
/* ADCCON Register Bits */
|
2012-08-01 12:13:41 +08:00
|
|
|
#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)
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
/* ADCTSC Register Bits */
|
2012-08-01 12:13:41 +08:00
|
|
|
#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)
|
2009-12-11 17:42:01 +08:00
|
|
|
#define S3C2410_ADCTSC_PULL_UP_DISABLE (1<<3)
|
2012-08-01 12:13:41 +08:00
|
|
|
#define S3C2410_ADCTSC_AUTO_PST (1<<2)
|
|
|
|
#define S3C2410_ADCTSC_XY_PST(x) (((x)&0x3)<<0)
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
/* ADCDAT0 Bits */
|
2012-08-01 12:13:41 +08:00
|
|
|
#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)
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
/* ADCDAT1 Bits */
|
2012-08-01 12:13:41 +08:00
|
|
|
#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)
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
#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))
|
|
|
|
|
2010-05-15 00:52:21 +08:00
|
|
|
#define X_MIN 74
|
|
|
|
#define X_MAX 934
|
2011-07-20 11:17:18 +08:00
|
|
|
#define Y_MIN 920
|
|
|
|
#define Y_MAX 89
|
2010-05-15 00:52:21 +08:00
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
struct s3c2410ts
|
|
|
|
{
|
|
|
|
long xp;
|
|
|
|
long yp;
|
|
|
|
int count;
|
|
|
|
int shift;
|
|
|
|
|
|
|
|
int delay;
|
|
|
|
int presc;
|
|
|
|
|
|
|
|
char phys[32];
|
|
|
|
};
|
2010-12-23 11:24:17 +08:00
|
|
|
static struct s3c2410ts ts;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2010-05-15 00:52:21 +08:00
|
|
|
struct rtgui_touch_device
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
2010-12-23 11:13:14 +08:00
|
|
|
struct rt_device parent;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
rt_timer_t poll_timer;
|
|
|
|
rt_uint16_t x, y;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
rt_bool_t calibrating;
|
|
|
|
rt_touch_calibration_func_t calibration_func;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2010-10-02 23:45:09 +08:00
|
|
|
rt_touch_eventpost_func_t eventpost_func;
|
|
|
|
void *eventpost_param;
|
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
rt_uint16_t min_x, max_x;
|
|
|
|
rt_uint16_t min_y, max_y;
|
|
|
|
|
|
|
|
rt_uint16_t width;
|
|
|
|
rt_uint16_t height;
|
|
|
|
|
|
|
|
rt_bool_t first_down_report;
|
2010-05-15 00:52:21 +08:00
|
|
|
};
|
|
|
|
static struct rtgui_touch_device *touch = RT_NULL;
|
2010-10-02 23:45:09 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_RTGUI
|
2010-05-15 00:52:21 +08:00
|
|
|
static void report_touch_input(int updown)
|
|
|
|
{
|
|
|
|
struct rtgui_event_mouse emouse;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
RTGUI_EVENT_MOUSE_BUTTON_INIT(&emouse);
|
|
|
|
emouse.wid = RT_NULL;
|
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
/* set emouse button */
|
2010-05-15 09:11:18 +08:00
|
|
|
emouse.button = RTGUI_MOUSE_BUTTON_LEFT;
|
2010-05-15 00:52:21 +08:00
|
|
|
emouse.parent.sender = RT_NULL;
|
|
|
|
|
2009-12-11 17:42:01 +08:00
|
|
|
if (updown)
|
|
|
|
{
|
2010-05-15 00:52:21 +08:00
|
|
|
ts.xp = ts.xp / ts.count;
|
|
|
|
ts.yp = ts.yp / ts.count;;
|
|
|
|
|
2010-05-15 09:11:18 +08:00
|
|
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
|
|
|
{
|
|
|
|
touch->x = ts.xp;
|
|
|
|
touch->y = ts.yp;
|
|
|
|
}
|
|
|
|
else
|
2012-08-01 12:13:41 +08:00
|
|
|
{
|
|
|
|
if (touch->max_x > touch->min_x)
|
|
|
|
{
|
|
|
|
touch->x = touch->width * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (touch->max_y > touch->min_y)
|
|
|
|
{
|
|
|
|
touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y);
|
|
|
|
}
|
2010-05-15 09:11:18 +08:00
|
|
|
}
|
2010-05-15 00:52:21 +08:00
|
|
|
|
|
|
|
emouse.x = touch->x;
|
|
|
|
emouse.y = touch->y;
|
2012-08-01 12:13:41 +08:00
|
|
|
if (touch->first_down_report == RT_TRUE)
|
2010-05-15 00:52:21 +08:00
|
|
|
{
|
|
|
|
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
|
|
|
emouse.button |= RTGUI_MOUSE_BUTTON_DOWN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
|
|
|
|
emouse.button = 0;
|
2012-08-01 12:13:41 +08:00
|
|
|
}
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-15 00:52:21 +08:00
|
|
|
emouse.x = touch->x;
|
|
|
|
emouse.y = touch->y;
|
|
|
|
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
|
|
|
emouse.button |= RTGUI_MOUSE_BUTTON_UP;
|
|
|
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
|
|
|
{
|
|
|
|
/* callback function */
|
|
|
|
touch->calibration_func(emouse.x, emouse.y);
|
|
|
|
}
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
/* rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up",
|
|
|
|
touch->x, touch->y); */
|
2010-05-15 00:52:21 +08:00
|
|
|
|
|
|
|
/* send event to server */
|
|
|
|
if (touch->calibrating != RT_TRUE)
|
|
|
|
{
|
|
|
|
rtgui_server_post_event((&emouse.parent), sizeof(emouse));
|
2012-08-01 12:13:41 +08:00
|
|
|
}
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
2010-10-02 23:45:09 +08:00
|
|
|
#else
|
|
|
|
static void report_touch_input(int updown)
|
|
|
|
{
|
|
|
|
struct rt_touch_event touch_event;
|
|
|
|
|
|
|
|
if (updown)
|
|
|
|
{
|
|
|
|
ts.xp = ts.xp / ts.count;
|
|
|
|
ts.yp = ts.yp / ts.count;
|
|
|
|
|
|
|
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
|
|
|
{
|
|
|
|
touch->x = ts.xp;
|
|
|
|
touch->y = ts.yp;
|
|
|
|
}
|
|
|
|
else
|
2011-07-20 11:17:18 +08:00
|
|
|
{
|
2012-08-01 12:13:41 +08:00
|
|
|
if (touch->max_x > touch->min_x)
|
|
|
|
{
|
|
|
|
touch->x = touch->width * ( ts.xp - touch->min_x ) / (touch->max_x-touch->min_x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (touch->max_y > touch->min_y)
|
|
|
|
{
|
|
|
|
touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y);
|
|
|
|
}
|
2010-10-02 23:45:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
touch_event.x = touch->x;
|
|
|
|
touch_event.y = touch->y;
|
|
|
|
touch_event.pressed = 1;
|
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
if (touch->first_down_report == RT_TRUE)
|
2010-10-02 23:45:09 +08:00
|
|
|
{
|
|
|
|
if (touch->calibrating != RT_TRUE && touch->eventpost_func)
|
2012-08-01 12:13:41 +08:00
|
|
|
{
|
2010-10-02 23:45:09 +08:00
|
|
|
touch->eventpost_func(touch->eventpost_param, &touch_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
touch_event.x = touch->x;
|
|
|
|
touch_event.y = touch->y;
|
|
|
|
touch_event.pressed = 0;
|
2010-12-23 11:13:14 +08:00
|
|
|
|
2010-10-02 23:45:09 +08:00
|
|
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
|
|
|
{
|
|
|
|
/* callback function */
|
|
|
|
touch->calibration_func(touch_event.x, touch_event.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (touch->calibrating != RT_TRUE && touch->eventpost_func)
|
|
|
|
{
|
|
|
|
touch->eventpost_func(touch->eventpost_param, &touch_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
static void touch_timer_fire(void *parameter)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
2012-08-01 12:13:41 +08:00
|
|
|
rt_uint32_t data0;
|
|
|
|
rt_uint32_t data1;
|
2010-05-15 00:52:21 +08:00
|
|
|
int updown;
|
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
data0 = ADCDAT0;
|
|
|
|
data1 = ADCDAT1;
|
2010-05-15 00:52:21 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
2010-05-15 00:52:21 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
if (updown)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
2012-08-01 12:13:41 +08:00
|
|
|
if (ts.count != 0)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
2010-05-15 00:52:21 +08:00
|
|
|
report_touch_input(updown);
|
2012-08-01 12:13:41 +08:00
|
|
|
}
|
2010-05-15 00:52:21 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
ts.xp = 0;
|
|
|
|
ts.yp = 0;
|
|
|
|
ts.count = 0;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
|
|
|
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
|
|
|
}
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
|
2010-05-15 00:52:21 +08:00
|
|
|
static void s3c2410_adc_stylus_action(void)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
|
|
|
rt_uint32_t data0;
|
|
|
|
rt_uint32_t data1;
|
|
|
|
|
|
|
|
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;
|
2012-08-01 12:13:41 +08:00
|
|
|
ts.count ++;
|
2009-12-11 17:42:01 +08:00
|
|
|
|
|
|
|
if (ts.count < (1<<ts.shift))
|
|
|
|
{
|
|
|
|
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
|
|
|
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-23 11:13:14 +08:00
|
|
|
if (touch->first_down_report)
|
2010-05-15 00:52:21 +08:00
|
|
|
{
|
|
|
|
report_touch_input(1);
|
|
|
|
ts.xp = 0;
|
|
|
|
ts.yp = 0;
|
|
|
|
ts.count = 0;
|
2010-12-23 11:13:14 +08:00
|
|
|
touch->first_down_report = 0;
|
2010-05-15 00:52:21 +08:00
|
|
|
}
|
|
|
|
/* start timer */
|
|
|
|
rt_timer_start(touch->poll_timer);
|
2009-12-11 17:42:01 +08:00
|
|
|
ADCTSC = WAIT4INT(1);
|
|
|
|
}
|
2010-05-15 00:52:21 +08:00
|
|
|
|
|
|
|
SUBSRCPND |= BIT_SUB_ADC;
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
|
2010-05-15 00:52:21 +08:00
|
|
|
static void s3c2410_intc_stylus_updown(void)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
|
|
|
rt_uint32_t data0;
|
|
|
|
rt_uint32_t data1;
|
|
|
|
int updown;
|
|
|
|
|
|
|
|
data0 = ADCDAT0;
|
|
|
|
data1 = ADCDAT1;
|
|
|
|
|
|
|
|
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
|
|
|
|
2010-05-15 00:52:21 +08:00
|
|
|
/* rt_kprintf("stylus: %s\n", updown? "down" : "up"); */
|
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
if (updown)
|
|
|
|
{
|
2010-05-15 00:52:21 +08:00
|
|
|
touch_timer_fire(0);
|
|
|
|
}
|
2009-12-11 17:42:01 +08:00
|
|
|
else
|
|
|
|
{
|
2010-05-15 00:52:21 +08:00
|
|
|
/* stop timer */
|
|
|
|
rt_timer_stop(touch->poll_timer);
|
2010-12-23 11:13:14 +08:00
|
|
|
touch->first_down_report = RT_TRUE;
|
2009-12-11 17:42:01 +08:00
|
|
|
if (ts.xp >= 0 && ts.yp >= 0)
|
|
|
|
{
|
2010-05-15 00:52:21 +08:00
|
|
|
report_touch_input(updown);
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
2010-01-29 08:32:32 +08:00
|
|
|
ts.count = 0;
|
2009-12-11 17:42:01 +08:00
|
|
|
ADCTSC = WAIT4INT(0);
|
|
|
|
}
|
2010-05-15 00:52:21 +08:00
|
|
|
|
|
|
|
SUBSRCPND |= BIT_SUB_TC;
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
|
2010-05-15 00:52:21 +08:00
|
|
|
static void rt_touch_handler(int irqno)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
2010-04-13 01:37:37 +08:00
|
|
|
if (SUBSRCPND & BIT_SUB_ADC)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
|
|
|
/* INT_SUB_ADC */
|
|
|
|
s3c2410_adc_stylus_action();
|
|
|
|
}
|
|
|
|
|
2010-04-13 01:37:37 +08:00
|
|
|
if (SUBSRCPND & BIT_SUB_TC)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
|
|
|
/* INT_SUB_TC */
|
|
|
|
s3c2410_intc_stylus_updown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear interrupt */
|
2010-05-16 10:35:37 +08:00
|
|
|
INTPND |= (1ul << INTADC);
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|
|
|
|
|
2010-05-15 00:52:21 +08:00
|
|
|
/* RT-Thread Device Interface */
|
2012-08-01 12:13:41 +08:00
|
|
|
static rt_err_t rtgui_touch_init(rt_device_t dev)
|
2009-12-11 17:42:01 +08:00
|
|
|
{
|
|
|
|
/* 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 */
|
2010-05-16 10:35:37 +08:00
|
|
|
INTPND |= (1ul << INTADC);
|
2012-08-01 12:13:41 +08:00
|
|
|
|
2010-01-29 08:32:32 +08:00
|
|
|
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;
|
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
touch->first_down_report = RT_TRUE;
|
2010-05-15 00:52:21 +08:00
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
static rt_err_t rtgui_touch_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
2010-05-15 00:52:21 +08:00
|
|
|
{
|
2010-05-15 09:11:18 +08:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case RT_TOUCH_CALIBRATION:
|
|
|
|
touch->calibrating = RT_TRUE;
|
|
|
|
touch->calibration_func = (rt_touch_calibration_func_t)args;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RT_TOUCH_NORMAL:
|
|
|
|
touch->calibrating = RT_FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RT_TOUCH_CALIBRATION_DATA:
|
|
|
|
{
|
2012-08-01 12:13:41 +08:00
|
|
|
struct calibration_data *data;
|
2010-05-15 09:11:18 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
data = (struct calibration_data *)args;
|
2010-05-15 09:11:18 +08:00
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
/* update */
|
2010-05-15 09:11:18 +08:00
|
|
|
touch->min_x = data->min_x;
|
|
|
|
touch->max_x = data->max_x;
|
2011-07-20 11:17:18 +08:00
|
|
|
touch->min_y = data->min_y;
|
|
|
|
touch->max_y = data->max_y;
|
2010-05-15 09:11:18 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
rt_kprintf("min_x = %d, max_x = %d, min_y = %d, max_y = %d\n",
|
|
|
|
touch->min_x, touch->max_x, touch->min_y, touch->max_y);
|
|
|
|
*/
|
|
|
|
}
|
2012-08-01 12:13:41 +08:00
|
|
|
break;
|
2010-10-02 23:45:09 +08:00
|
|
|
|
|
|
|
case RT_TOUCH_EVENTPOST:
|
|
|
|
touch->eventpost_func = (rt_touch_eventpost_func_t)args;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RT_TOUCH_EVENTPOST_PARAM:
|
|
|
|
touch->eventpost_param = args;
|
|
|
|
break;
|
2010-05-15 09:11:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return RT_EOK;
|
2010-05-15 00:52:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtgui_touch_hw_init(void)
|
|
|
|
{
|
2011-06-08 08:50:04 +08:00
|
|
|
rt_err_t result = RT_FALSE;
|
2010-12-23 11:13:14 +08:00
|
|
|
rt_device_t device = RT_NULL;
|
2011-06-08 08:50:04 +08:00
|
|
|
struct rt_device_graphic_info info;
|
2010-12-23 11:13:14 +08:00
|
|
|
|
2012-08-01 12:13:41 +08:00
|
|
|
touch = (struct rtgui_touch_device *)rt_malloc(sizeof(struct rtgui_touch_device));
|
|
|
|
if (touch == RT_NULL)
|
|
|
|
return; /* no memory yet */
|
2010-05-15 09:11:18 +08:00
|
|
|
|
|
|
|
/* clear device structure */
|
|
|
|
rt_memset(&(touch->parent), 0, sizeof(struct rt_device));
|
|
|
|
touch->calibrating = RT_FALSE;
|
|
|
|
touch->min_x = X_MIN;
|
|
|
|
touch->max_x = X_MAX;
|
|
|
|
touch->min_y = Y_MIN;
|
2011-07-20 11:17:18 +08:00
|
|
|
touch->max_y = Y_MAX;
|
2010-10-02 23:45:09 +08:00
|
|
|
touch->eventpost_func = RT_NULL;
|
|
|
|
touch->eventpost_param = RT_NULL;
|
2010-05-15 09:11:18 +08:00
|
|
|
|
|
|
|
/* init device structure */
|
|
|
|
touch->parent.type = RT_Device_Class_Unknown;
|
|
|
|
touch->parent.init = rtgui_touch_init;
|
|
|
|
touch->parent.control = rtgui_touch_control;
|
2010-11-29 15:49:59 +08:00
|
|
|
touch->parent.user_data = RT_NULL;
|
2010-05-15 09:11:18 +08:00
|
|
|
|
2010-12-23 11:13:14 +08:00
|
|
|
device = rt_device_find("lcd");
|
2012-08-01 12:13:41 +08:00
|
|
|
if (device == RT_NULL)
|
|
|
|
return; /* no this device */
|
2010-12-23 11:13:14 +08:00
|
|
|
|
2011-06-08 08:50:04 +08:00
|
|
|
/* get graphic device info */
|
|
|
|
result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info);
|
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
2012-08-01 12:13:41 +08:00
|
|
|
|
2011-06-08 08:50:04 +08:00
|
|
|
/* get device information failed */
|
2012-08-01 12:13:41 +08:00
|
|
|
|
2011-06-08 08:50:04 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
touch->width = info.width;
|
|
|
|
touch->height = info.height;
|
2010-12-23 11:13:14 +08:00
|
|
|
|
2010-05-15 09:11:18 +08:00
|
|
|
/* create 1/8 second timer */
|
|
|
|
touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL,
|
|
|
|
RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC);
|
|
|
|
|
|
|
|
/* register touch device to RT-Thread */
|
|
|
|
rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
|
2009-12-11 17:42:01 +08:00
|
|
|
}
|