提交 3f33f036 编写于 作者: qiuyiuestc's avatar qiuyiuestc

[mini2440]fix bugs in touch driver

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@709 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 ca81f820
...@@ -177,7 +177,7 @@ void rt_hw_lcd_update(rtgui_rect_t *rect) ...@@ -177,7 +177,7 @@ void rt_hw_lcd_update(rtgui_rect_t *rect)
pitch = 2 * (rect->x2 - rect->x1); pitch = 2 * (rect->x2 - rect->x1);
rt_kprintf("update (%d,%d - %d,%d)\n", rect->x1, rect->y1, rect->x2, rect->y2); /* rt_kprintf("update (%d,%d - %d,%d)\n", rect->x1, rect->y1, rect->x2, rect->y2); */
/* copy from framebuffer to physical framebuffer */ /* copy from framebuffer to physical framebuffer */
src_ptr = &_rt_framebuffer[rect->x1][rect->y1]; src_ptr = &_rt_framebuffer[rect->x1][rect->y1];
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <s3c24x0.h> #include <s3c24x0.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_server.h> #include <rtgui/rtgui_server.h>
#include <rtgui/event.h>
#include "touch.h" #include "touch.h"
...@@ -82,13 +83,12 @@ struct rtgui_touch_device ...@@ -82,13 +83,12 @@ struct rtgui_touch_device
static struct rtgui_touch_device *touch = RT_NULL; static struct rtgui_touch_device *touch = RT_NULL;
static int first_down_report; static int first_down_report;
#include <rtgui/event.h>
static void report_touch_input(int updown) static void report_touch_input(int updown)
{ {
struct rtgui_event_mouse emouse; struct rtgui_event_mouse emouse;
/* set emouse button */ /* set emouse button */
emouse.button |= RTGUI_MOUSE_BUTTON_LEFT; emouse.button = RTGUI_MOUSE_BUTTON_LEFT;
emouse.parent.sender = RT_NULL; emouse.parent.sender = RT_NULL;
if (updown) if (updown)
...@@ -96,15 +96,19 @@ static void report_touch_input(int updown) ...@@ -96,15 +96,19 @@ static void report_touch_input(int updown)
ts.xp = ts.xp / ts.count; ts.xp = ts.xp / ts.count;
ts.yp = ts.yp / ts.count;; ts.yp = ts.yp / ts.count;;
ts.xp = 240 * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x); if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
ts.yp = 320 - (320*(ts.yp-touch->min_y)/(touch->max_y-touch->min_y)); {
touch->x = ts.xp;
touch->x = ts.xp; touch->y = ts.yp;
touch->y = ts.yp; }
else
{
touch->x = 240 * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
touch->y = 320 - (320*(ts.yp-touch->min_y)/(touch->max_y-touch->min_y));
}
emouse.x = touch->x; emouse.x = touch->x;
emouse.y = touch->y; emouse.y = touch->y;
if(first_down_report == 1) if(first_down_report == 1)
{ {
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
...@@ -291,59 +295,64 @@ static rt_err_t rtgui_touch_init (rt_device_t dev) ...@@ -291,59 +295,64 @@ static rt_err_t rtgui_touch_init (rt_device_t dev)
static rt_err_t rtgui_touch_control (rt_device_t dev, rt_uint8_t cmd, void *args) static rt_err_t rtgui_touch_control (rt_device_t dev, rt_uint8_t cmd, void *args)
{ {
switch (cmd) switch (cmd)
{ {
case RT_TOUCH_CALIBRATION: case RT_TOUCH_CALIBRATION:
touch->calibrating = RT_TRUE; touch->calibrating = RT_TRUE;
touch->calibration_func = (rt_touch_calibration_func_t)args; touch->calibration_func = (rt_touch_calibration_func_t)args;
break; break;
case RT_TOUCH_NORMAL: case RT_TOUCH_NORMAL:
touch->calibrating = RT_FALSE; touch->calibrating = RT_FALSE;
break; break;
case RT_TOUCH_CALIBRATION_DATA: case RT_TOUCH_CALIBRATION_DATA:
{ {
struct calibration_data* data; struct calibration_data* data;
data = (struct calibration_data*) args; data = (struct calibration_data*) args;
//update //update
touch->min_x = data->min_x; touch->min_x = data->min_x;
touch->max_x = data->max_x; touch->max_x = data->max_x;
touch->min_y = data->min_y; touch->min_y = data->max_y;
touch->max_y = data->max_y; touch->max_y = data->min_y;
}
break; /*
} 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);
return RT_EOK; */
}
break;
}
return RT_EOK;
} }
void rtgui_touch_hw_init(void) void rtgui_touch_hw_init(void)
{ {
touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device)); touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device));
if (touch == RT_NULL) return; /* no memory yet */ if (touch == RT_NULL) return; /* no memory yet */
/* clear device structure */ /* clear device structure */
rt_memset(&(touch->parent), 0, sizeof(struct rt_device)); rt_memset(&(touch->parent), 0, sizeof(struct rt_device));
touch->calibrating = RT_FALSE; touch->calibrating = RT_FALSE;
touch->min_x = X_MIN; touch->min_x = X_MIN;
touch->max_x = X_MAX; touch->max_x = X_MAX;
touch->min_y = Y_MIN; touch->min_y = Y_MIN;
touch->max_y = X_MAX; touch->max_y = X_MAX;
/* init device structure */ /* init device structure */
touch->parent.type = RT_Device_Class_Unknown; touch->parent.type = RT_Device_Class_Unknown;
touch->parent.init = rtgui_touch_init; touch->parent.init = rtgui_touch_init;
touch->parent.control = rtgui_touch_control; touch->parent.control = rtgui_touch_control;
touch->parent.private = RT_NULL; touch->parent.private = RT_NULL;
/* create 1/8 second timer */ /* create 1/8 second timer */
touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL, touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL,
RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC); RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC);
/* register touch device to RT-Thread */ /* register touch device to RT-Thread */
rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR); rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册