|
@@ -1,9 +1,11 @@
|
|
#include <rthw.h>
|
|
#include <rthw.h>
|
|
#include <rtthread.h>
|
|
#include <rtthread.h>
|
|
#include <s3c24x0.h>
|
|
#include <s3c24x0.h>
|
|
-#include <rtgui/event.h>
|
|
|
|
|
|
+#include <rtgui/rtgui_system.h>
|
|
#include <rtgui/rtgui_server.h>
|
|
#include <rtgui/rtgui_server.h>
|
|
|
|
|
|
|
|
+#include "touch.h"
|
|
|
|
+
|
|
/* ADCCON Register Bits */
|
|
/* ADCCON Register Bits */
|
|
#define S3C2410_ADCCON_ECFLG (1<<15)
|
|
#define S3C2410_ADCCON_ECFLG (1<<15)
|
|
#define S3C2410_ADCCON_PRSCEN (1<<14)
|
|
#define S3C2410_ADCCON_PRSCEN (1<<14)
|
|
@@ -16,7 +18,6 @@
|
|
#define S3C2410_ADCCON_ENABLE_START (1<<0)
|
|
#define S3C2410_ADCCON_ENABLE_START (1<<0)
|
|
#define S3C2410_ADCCON_STARTMASK (0x3<<0)
|
|
#define S3C2410_ADCCON_STARTMASK (0x3<<0)
|
|
|
|
|
|
-
|
|
|
|
/* ADCTSC Register Bits */
|
|
/* ADCTSC Register Bits */
|
|
#define S3C2410_ADCTSC_UD_SEN (1<<8) /* ghcstop add for s3c2440a */
|
|
#define S3C2410_ADCTSC_UD_SEN (1<<8) /* ghcstop add for s3c2440a */
|
|
#define S3C2410_ADCTSC_YM_SEN (1<<7)
|
|
#define S3C2410_ADCTSC_YM_SEN (1<<7)
|
|
@@ -46,6 +47,11 @@
|
|
#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
|
#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
|
S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
|
|
S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
|
|
|
|
|
|
|
|
+#define X_MIN 74
|
|
|
|
+#define X_MAX 934
|
|
|
|
+#define Y_MIN 89
|
|
|
|
+#define Y_MAX 920
|
|
|
|
+
|
|
struct s3c2410ts
|
|
struct s3c2410ts
|
|
{
|
|
{
|
|
long xp;
|
|
long xp;
|
|
@@ -60,75 +66,113 @@ struct s3c2410ts
|
|
};
|
|
};
|
|
static struct s3c2410ts ts;
|
|
static struct s3c2410ts ts;
|
|
|
|
|
|
-#define X_MIN 74
|
|
|
|
-#define X_MAX 934
|
|
|
|
-#define Y_MIN 89
|
|
|
|
-#define Y_MAX 920
|
|
|
|
-
|
|
|
|
-#ifdef RT_USING_RTGUI
|
|
|
|
-#include <rtgui/event.h>
|
|
|
|
-void report_touch_input(int updown)
|
|
|
|
|
|
+struct rtgui_touch_device
|
|
{
|
|
{
|
|
- long xp, yp;
|
|
|
|
- struct rtgui_event_mouse emouse;
|
|
|
|
|
|
+ struct rt_device parent;
|
|
|
|
|
|
- xp = ts.xp >> ts.shift;
|
|
|
|
- yp = ts.yp >> ts.shift;
|
|
|
|
|
|
+ rt_timer_t poll_timer;
|
|
|
|
+ rt_uint16_t x, y;
|
|
|
|
|
|
- xp = 240 * (xp-X_MIN)/(X_MAX-X_MIN);
|
|
|
|
- yp = 320 - (320*(yp-Y_MIN)/(Y_MAX-Y_MIN));
|
|
|
|
|
|
+ rt_bool_t calibrating;
|
|
|
|
+ rt_touch_calibration_func_t calibration_func;
|
|
|
|
|
|
- emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
|
|
|
- emouse.parent.sender = RT_NULL;
|
|
|
|
|
|
+ rt_uint16_t min_x, max_x;
|
|
|
|
+ rt_uint16_t min_y, max_y;
|
|
|
|
+};
|
|
|
|
+static struct rtgui_touch_device *touch = RT_NULL;
|
|
|
|
+static int first_down_report;
|
|
|
|
|
|
- emouse.x = xp;
|
|
|
|
- emouse.y = yp;
|
|
|
|
|
|
+#include <rtgui/event.h>
|
|
|
|
+static void report_touch_input(int updown)
|
|
|
|
+{
|
|
|
|
+ struct rtgui_event_mouse emouse;
|
|
|
|
|
|
/* set emouse button */
|
|
/* set emouse button */
|
|
|
|
+ emouse.button |= RTGUI_MOUSE_BUTTON_LEFT;
|
|
|
|
+ emouse.parent.sender = RT_NULL;
|
|
|
|
+
|
|
if (updown)
|
|
if (updown)
|
|
{
|
|
{
|
|
- emouse.button = RTGUI_MOUSE_BUTTON_DOWN;
|
|
|
|
|
|
+ ts.xp = ts.xp / ts.count;
|
|
|
|
+ ts.yp = ts.yp / ts.count;;
|
|
|
|
+
|
|
|
|
+ ts.xp = 240 * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
|
|
|
|
+ ts.yp = 320 - (320*(ts.yp-touch->min_y)/(touch->max_y-touch->min_y));
|
|
|
|
+
|
|
|
|
+ touch->x = ts.xp;
|
|
|
|
+ touch->y = ts.yp;
|
|
|
|
+
|
|
|
|
+ emouse.x = touch->x;
|
|
|
|
+ emouse.y = touch->y;
|
|
|
|
+
|
|
|
|
+ if(first_down_report == 1)
|
|
|
|
+ {
|
|
|
|
+ emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
|
|
|
+ emouse.button |= RTGUI_MOUSE_BUTTON_DOWN;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
|
|
|
|
+ emouse.button = 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- emouse.button = RTGUI_MOUSE_BUTTON_UP;
|
|
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- /* rt_kprintf("touch %s: ts.x: %d, ts.y: %d, count:%d\n", updown? "down" : "up",
|
|
|
|
- xp, yp, ts.count); */
|
|
|
|
-
|
|
|
|
- emouse.button |= RTGUI_MOUSE_BUTTON_LEFT;
|
|
|
|
-
|
|
|
|
- rtgui_server_post_event((&emouse.parent), sizeof(emouse));
|
|
|
|
|
|
+ /*
|
|
|
|
+ rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up",
|
|
|
|
+ touch->x, touch->y);
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ /* send event to server */
|
|
|
|
+ if (touch->calibrating != RT_TRUE)
|
|
|
|
+ {
|
|
|
|
+ rtgui_server_post_event((&emouse.parent), sizeof(emouse));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-#endif
|
|
|
|
|
|
|
|
-static int first_down_report;
|
|
|
|
-/* fixed me, use timer to support move action */
|
|
|
|
-static void touch_timer_fire(void)
|
|
|
|
|
|
+static void touch_timer_fire(void* parameter)
|
|
{
|
|
{
|
|
- if (ts.count == 3)
|
|
|
|
|
|
+ rt_uint32_t data0;
|
|
|
|
+ rt_uint32_t data1;
|
|
|
|
+ int updown;
|
|
|
|
+
|
|
|
|
+ data0 = ADCDAT0;
|
|
|
|
+ data1 = ADCDAT1;
|
|
|
|
+
|
|
|
|
+ updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
|
|
|
+
|
|
|
|
+ if (updown)
|
|
{
|
|
{
|
|
- if (first_down_report)
|
|
|
|
|
|
+ if (ts.count != 0)
|
|
{
|
|
{
|
|
-#ifdef RT_USING_RTGUI
|
|
|
|
- report_touch_input(1);
|
|
|
|
- first_down_report = 0;
|
|
|
|
-#endif
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ report_touch_input(updown);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ts.xp = 0;
|
|
|
|
+ ts.yp = 0;
|
|
|
|
+ ts.count = 0;
|
|
|
|
|
|
- ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
|
|
|
- ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
|
|
|
|
|
+ ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
|
|
|
+ ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-void s3c2410_adc_stylus_action(void)
|
|
|
|
|
|
+static void s3c2410_adc_stylus_action(void)
|
|
{
|
|
{
|
|
rt_uint32_t data0;
|
|
rt_uint32_t data0;
|
|
rt_uint32_t data1;
|
|
rt_uint32_t data1;
|
|
|
|
|
|
- SUBSRCPND |= BIT_SUB_ADC;
|
|
|
|
-
|
|
|
|
data0 = ADCDAT0;
|
|
data0 = ADCDAT0;
|
|
data1 = ADCDAT1;
|
|
data1 = ADCDAT1;
|
|
|
|
|
|
@@ -143,48 +187,56 @@ void s3c2410_adc_stylus_action(void)
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- //touch_timer_fire();
|
|
|
|
|
|
+ if (first_down_report)
|
|
|
|
+ {
|
|
|
|
+ report_touch_input(1);
|
|
|
|
+ ts.xp = 0;
|
|
|
|
+ ts.yp = 0;
|
|
|
|
+ ts.count = 0;
|
|
|
|
+ first_down_report = 0;
|
|
|
|
+ }
|
|
|
|
+ /* start timer */
|
|
|
|
+ rt_timer_start(touch->poll_timer);
|
|
ADCTSC = WAIT4INT(1);
|
|
ADCTSC = WAIT4INT(1);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ SUBSRCPND |= BIT_SUB_ADC;
|
|
}
|
|
}
|
|
|
|
|
|
-void s3c2410_intc_stylus_updown(void)
|
|
|
|
|
|
+static void s3c2410_intc_stylus_updown(void)
|
|
{
|
|
{
|
|
rt_uint32_t data0;
|
|
rt_uint32_t data0;
|
|
rt_uint32_t data1;
|
|
rt_uint32_t data1;
|
|
int updown;
|
|
int updown;
|
|
|
|
|
|
- SUBSRCPND |= BIT_SUB_TC;
|
|
|
|
-
|
|
|
|
data0 = ADCDAT0;
|
|
data0 = ADCDAT0;
|
|
data1 = ADCDAT1;
|
|
data1 = ADCDAT1;
|
|
|
|
|
|
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
|
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
|
|
|
|
|
|
|
+ /* rt_kprintf("stylus: %s\n", updown? "down" : "up"); */
|
|
|
|
+
|
|
if (updown)
|
|
if (updown)
|
|
{
|
|
{
|
|
- touch_timer_fire();
|
|
|
|
- }
|
|
|
|
|
|
+ touch_timer_fire(0);
|
|
|
|
+ }
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+ /* stop timer */
|
|
|
|
+ rt_timer_stop(touch->poll_timer);
|
|
|
|
+ first_down_report = 1;
|
|
if (ts.xp >= 0 && ts.yp >= 0)
|
|
if (ts.xp >= 0 && ts.yp >= 0)
|
|
{
|
|
{
|
|
- #ifdef RT_USING_RTGUI
|
|
|
|
- report_touch_input(1);
|
|
|
|
- report_touch_input(0);
|
|
|
|
- first_down_report = 1;
|
|
|
|
- #endif
|
|
|
|
|
|
+ report_touch_input(updown);
|
|
}
|
|
}
|
|
-
|
|
|
|
- ts.xp = 0;
|
|
|
|
- ts.yp = 0;
|
|
|
|
ts.count = 0;
|
|
ts.count = 0;
|
|
-
|
|
|
|
ADCTSC = WAIT4INT(0);
|
|
ADCTSC = WAIT4INT(0);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ SUBSRCPND |= BIT_SUB_TC;
|
|
}
|
|
}
|
|
|
|
|
|
-void rt_touch_handler(int irqno)
|
|
|
|
|
|
+static void rt_touch_handler(int irqno)
|
|
{
|
|
{
|
|
if (SUBSRCPND & BIT_SUB_ADC)
|
|
if (SUBSRCPND & BIT_SUB_ADC)
|
|
{
|
|
{
|
|
@@ -202,7 +254,8 @@ void rt_touch_handler(int irqno)
|
|
INTPND |= (rt_uint32_t)(1 << INTADC);
|
|
INTPND |= (rt_uint32_t)(1 << INTADC);
|
|
}
|
|
}
|
|
|
|
|
|
-void rt_hw_touch_init(void)
|
|
|
|
|
|
+/* RT-Thread Device Interface */
|
|
|
|
+static rt_err_t rtgui_touch_init (rt_device_t dev)
|
|
{
|
|
{
|
|
/* init touch screen structure */
|
|
/* init touch screen structure */
|
|
rt_memset(&ts, 0, sizeof(struct s3c2410ts));
|
|
rt_memset(&ts, 0, sizeof(struct s3c2410ts));
|
|
@@ -232,5 +285,65 @@ void rt_hw_touch_init(void)
|
|
INTSUBMSK &= ~BIT_SUB_TC;
|
|
INTSUBMSK &= ~BIT_SUB_TC;
|
|
|
|
|
|
first_down_report = 1;
|
|
first_down_report = 1;
|
|
|
|
+
|
|
|
|
+ return RT_EOK;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static rt_err_t rtgui_touch_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
|
|
|
+{
|
|
|
|
+ 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:
|
|
|
|
+ {
|
|
|
|
+ struct calibration_data* data;
|
|
|
|
+
|
|
|
|
+ data = (struct calibration_data*) args;
|
|
|
|
+
|
|
|
|
+ //update
|
|
|
|
+ touch->min_x = data->min_x;
|
|
|
|
+ touch->max_x = data->max_x;
|
|
|
|
+ touch->min_y = data->min_y;
|
|
|
|
+ touch->max_y = data->max_y;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return RT_EOK;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void rtgui_touch_hw_init(void)
|
|
|
|
+{
|
|
|
|
+ touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device));
|
|
|
|
+ if (touch == RT_NULL) return; /* no memory yet */
|
|
|
|
+
|
|
|
|
+ /* 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;
|
|
|
|
+ touch->max_y = X_MAX;
|
|
|
|
+
|
|
|
|
+ /* init device structure */
|
|
|
|
+ touch->parent.type = RT_Device_Class_Unknown;
|
|
|
|
+ touch->parent.init = rtgui_touch_init;
|
|
|
|
+ touch->parent.control = rtgui_touch_control;
|
|
|
|
+ touch->parent.private = RT_NULL;
|
|
|
|
+
|
|
|
|
+ /* 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);
|
|
}
|
|
}
|
|
|
|
|