git-svn-id: https://rt-thread.googlecode.com/svn/trunk@995 bbd45198-f89e-11dd-88c7-29a3b14d5316

This commit is contained in:
jiaojinxing1987@gmail.com 2010-10-02 15:45:09 +00:00
parent e7211af8a7
commit be8406155b
4 changed files with 93 additions and 1 deletions

View File

@ -23,6 +23,9 @@ if rtconfig.RT_USING_LWIP:
if rtconfig.RT_USING_RTGUI:
src_drv += ['touch.c', 'key.c', 'calibration.c']
if rtconfig.RT_USING_FTK:
src_drv += ['touch.c']
if rtconfig.RT_USING_RTGUI:
if rtconfig.RT_USING_LCD_TYPE == 'PNL_A70':
src_drv += ['lcd_a70.c']

View File

@ -110,8 +110,16 @@ void rt_init_thread_entry(void* parameter)
void rt_hw_lcd_init();
int FTK_MAIN(int argc, char* argv[]);
/* init lcd */
rt_hw_lcd_init();
/* init touch panel */
rtgui_touch_hw_init();
/* re-init device driver */
rt_device_init_all();
/* enter ftk main */
FTK_MAIN(0, NULL);
}
#endif

View File

@ -1,9 +1,13 @@
#include <rthw.h>
#include <rtthread.h>
#include <s3c24x0.h>
#ifdef RT_USING_RTGUI
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/event.h>
#endif
#include "touch.h"
@ -77,12 +81,17 @@ struct rtgui_touch_device
rt_bool_t calibrating;
rt_touch_calibration_func_t calibration_func;
rt_touch_eventpost_func_t eventpost_func;
void *eventpost_param;
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;
#ifdef RT_USING_RTGUI
static void report_touch_input(int updown)
{
struct rtgui_event_mouse emouse;
@ -144,6 +153,58 @@ static void report_touch_input(int updown)
rtgui_server_post_event((&emouse.parent), sizeof(emouse));
}
}
#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
{
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));
}
touch_event.x = touch->x;
touch_event.y = touch->y;
touch_event.pressed = 1;
if(first_down_report == 1)
{
if (touch->calibrating != RT_TRUE && touch->eventpost_func)
{
touch->eventpost_func(touch->eventpost_param, &touch_event);
}
}
}
else
{
touch_event.x = touch->x;
touch_event.y = touch->y;
touch_event.pressed = 0;
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
static void touch_timer_fire(void* parameter)
{
@ -324,6 +385,14 @@ static rt_err_t rtgui_touch_control (rt_device_t dev, rt_uint8_t cmd, void *args
*/
}
break;
case RT_TOUCH_EVENTPOST:
touch->eventpost_func = (rt_touch_eventpost_func_t)args;
break;
case RT_TOUCH_EVENTPOST_PARAM:
touch->eventpost_param = args;
break;
}
return RT_EOK;
@ -341,6 +410,8 @@ void rtgui_touch_hw_init(void)
touch->max_x = X_MAX;
touch->min_y = Y_MIN;
touch->max_y = X_MAX;
touch->eventpost_func = RT_NULL;
touch->eventpost_param = RT_NULL;
/* init device structure */
touch->parent.type = RT_Device_Class_Unknown;
@ -355,4 +426,3 @@ void rtgui_touch_hw_init(void)
/* register touch device to RT-Thread */
rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
}

View File

@ -6,6 +6,8 @@
#define RT_TOUCH_NORMAL 0
#define RT_TOUCH_CALIBRATION_DATA 1
#define RT_TOUCH_CALIBRATION 2
#define RT_TOUCH_EVENTPOST 3
#define RT_TOUCH_EVENTPOST_PARAM 4
struct calibration_data
{
@ -13,8 +15,17 @@ struct calibration_data
rt_uint16_t min_y, max_y;
};
struct rt_touch_event
{
rt_uint16_t x;
rt_uint16_t y;
int pressed;
};
typedef void (*rt_touch_calibration_func_t)(rt_uint16_t x, rt_uint16_t y);
typedef void (*rt_touch_eventpost_func_t)(void *, struct rt_touch_event *);
void rtgui_touch_hw_init(void);
#endif