diff --git a/bsp/mini2440/SConscript b/bsp/mini2440/SConscript index 4830a8530f..fc891e53e0 100644 --- a/bsp/mini2440/SConscript +++ b/bsp/mini2440/SConscript @@ -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'] diff --git a/bsp/mini2440/application.c b/bsp/mini2440/application.c index 35e1515720..946b30ac89 100644 --- a/bsp/mini2440/application.c +++ b/bsp/mini2440/application.c @@ -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 diff --git a/bsp/mini2440/touch.c b/bsp/mini2440/touch.c index e23a7e1ddd..bbd5f952e4 100644 --- a/bsp/mini2440/touch.c +++ b/bsp/mini2440/touch.c @@ -1,9 +1,13 @@ + #include #include #include + +#ifdef RT_USING_RTGUI #include #include #include +#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); } - diff --git a/bsp/mini2440/touch.h b/bsp/mini2440/touch.h index 2a1296bbef..3617e4a24f 100644 --- a/bsp/mini2440/touch.h +++ b/bsp/mini2440/touch.h @@ -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