TouchScreen.c
资源名称:mmi.rar [点击查看]
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:207k
源码类别:
MTK
开发平台:
C/C++
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_clear_screen
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_clear_screen(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memset(mmi_pen_draw_buffer, 0, sizeof(mmi_pen_draw_buffer));
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_draw_point
- * DESCRIPTION
- *
- * PARAMETERS
- * x [IN]
- * y [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_draw_point(S32 x, S32 y)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 offset;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (x < 0 || x >= LCD_WIDTH || y < 0 || y >= LCD_HEIGHT)
- {
- return;
- }
- offset = y * LCD_WIDTH + x;
- mmi_pen_draw_buffer[offset >> 3] |= (1 << (offset & 0x07));
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_draw_from_buffer
- * DESCRIPTION
- *
- * PARAMETERS
- * x1 [IN]
- * y1 [IN]
- * x2 [IN]
- * y2 [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_draw_from_buffer(S32 x1, S32 y1, S32 x2, S32 y2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 x, y;
- S32 offset;
- color c;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- c.r = 255;
- c.g = c.b = 0;
- c.alpha = 255;
- gui_push_clip();
- gui_set_clip(x1, y1, x2, y2);
- for (y = y1; y <= y2; y++)
- {
- offset = y * LCD_WIDTH;
- for (x = x1; x <= x2; x++)
- {
- if (mmi_pen_draw_buffer[offset >> 3] & (1 << (offset & 0x07)))
- {
- gui_putpixel(x, y, c);
- }
- offset++;
- }
- }
- gui_pop_clip();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_refresh_screen
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_refresh_screen(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- gui_lock_double_buffer();
- mmi_pen_test_draw_from_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
- gui_unlock_double_buffer();
- gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_draw_line
- * DESCRIPTION
- *
- * PARAMETERS
- * x1 [IN]
- * y1 [IN]
- * x2 [IN]
- * y2 [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_draw_line(S16 x1, S16 y1, S16 x2, S16 y2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 x_diff = abs(x2 - x1);
- S16 y_diff = abs(y2 - y1);
- S16 x_incr, y_incr;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (x1 > x2)
- {
- x_incr = -1;
- }
- else
- {
- x_incr = 1;
- }
- if (y1 > y2)
- {
- y_incr = -1;
- }
- else
- {
- y_incr = 1;
- }
- if (x_diff >= y_diff)
- {
- S16 pr_diff = y_diff << 1;
- S16 pru_diff = pr_diff - (x_diff << 1);
- S16 p = pr_diff - x_diff;
- for (; x_diff >= 0; x_diff--)
- {
- mmi_pen_test_draw_point(x1, y1);
- if (p > 0)
- {
- x1 += x_incr;
- y1 += y_incr;
- p += pru_diff;
- }
- else
- {
- x1 += x_incr;
- p += pr_diff;
- }
- }
- }
- else
- {
- S16 pr_diff = x_diff << 1;
- S16 pru_diff = pr_diff - (y_diff << 1);
- S16 p = pr_diff - y_diff;
- for (; y_diff >= 0; y_diff--)
- {
- mmi_pen_test_draw_point(x1, y1);
- if (p > 0)
- {
- x1 += x_incr;
- y1 += y_incr;
- p += pru_diff;
- }
- else
- {
- y1 += y_incr;
- p += pr_diff;
- }
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_draw_rectangle
- * DESCRIPTION
- *
- * PARAMETERS
- * x1 [IN]
- * y1 [IN]
- * x2 [IN]
- * y2 [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_draw_rectangle(S16 x1, S16 y1, S16 x2, S16 y2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_test_draw_line(x1, y1, x1, y2);
- mmi_pen_test_draw_line(x1, y2, x2, y2);
- mmi_pen_test_draw_line(x2, y2, x2, y1);
- mmi_pen_test_draw_line(x2, y1, x1, y1);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_draw_filled_rectangle
- * DESCRIPTION
- *
- * PARAMETERS
- * x1 [IN]
- * y1 [IN]
- * x2 [IN]
- * y2 [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_draw_filled_rectangle(S16 x1, S16 y1, S16 x2, S16 y2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 x, y;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (x = x1; x <= x2; x++)
- {
- for (y = y1; y <= y2; y++)
- {
- mmi_pen_test_draw_point(x, y);
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_down
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_down(mmi_pen_point_struct pos)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_test_last_pos = pos;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_move
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_move(mmi_pen_point_struct pos)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_test_draw_line(mmi_pen_test_last_pos.x, mmi_pen_test_last_pos.y, pos.x, pos.y);
- mmi_pen_test_last_pos = pos;
- mmi_pen_test_refresh_screen();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_up
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_up(mmi_pen_point_struct pos)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_long_tap
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_long_tap(mmi_pen_point_struct pos)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_test_draw_filled_rectangle((S16) (pos.x - 2), (S16) (pos.y - 2), (S16) (pos.x + 2), (S16) (pos.y + 2));
- mmi_pen_test_refresh_screen();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_test_repeat
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_test_repeat(mmi_pen_point_struct pos)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_test_draw_rectangle((S16) (pos.x - 4), (S16) (pos.y - 4), (S16) (pos.x + 4), (S16) (pos.y + 4));
- mmi_pen_test_refresh_screen();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_exit_pen_test_screen
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_exit_pen_test_screen(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_reset();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_redraw_pen_test_screen
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_redraw_pen_test_screen(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- gui_lock_double_buffer();
- RedrawCategoryFunction();
- mmi_pen_test_draw_from_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
- gui_unlock_double_buffer();
- gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_entry_pen_test_screen
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_entry_pen_test_screen(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- EntryNewScreen(0, NULL, mmi_exit_pen_test_screen, NULL);
- ShowCategory66Screen(STR_GLOBAL_UNFINISHED, 0, 0, 0, STR_GLOBAL_BACK, 0, (U8*) L"", 0, NULL);
- RedrawCategoryFunction = mmi_redraw_pen_test_screen; /* For PC simulator architecture */
- mmi_pen_test_clear_screen();
- mmi_pen_register_down_handler(mmi_pen_test_down);
- mmi_pen_register_move_handler(mmi_pen_test_move);
- mmi_pen_register_up_handler(mmi_pen_test_up);
- mmi_pen_register_long_tap_handler(mmi_pen_test_long_tap);
- mmi_pen_register_repeat_handler(mmi_pen_test_repeat);
- SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_unit_test
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_unit_test(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_entry_pen_test_screen();
- }
- #endif /* MMI_PEN_UNIT_TEST */
- #elif ( !defined(__MMI_TOUCH_SCREEN__) || !defined(__MMI_HANDWRITING_PAD__) ) && !defined(__MTK_TARGET__) && !defined(MMI_ON_WIN32)
- #include "PixtelDataTypes.h"
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_MODIS_enqueue_down
- * DESCRIPTION
- *
- * PARAMETERS
- * x [IN]
- * y [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_MODIS_enqueue_down(S16 x, S16 y)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_MODIS_enqueue_move
- * DESCRIPTION
- *
- * PARAMETERS
- * x [IN]
- * y [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_MODIS_enqueue_move(S16 x, S16 y)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_MODIS_enqueue_up
- * DESCRIPTION
- *
- * PARAMETERS
- * x [IN]
- * y [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_MODIS_enqueue_up(S16 x, S16 y)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- }
- #elif ( defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__) ) && defined(__MTK_TARGET__)
- /*****************************************************************************
- *
- * Target integration
- *
- ****************************************************************************/
- #include "stdC.h"
- #include "PixtelDataTypes.h"
- #include "TimerEvents.h"
- #include "KeyBrd.h"
- #include "TaskInit.h"
- #include "MMITaskProt.h"
- #include "FrameworkStruct.h"
- #include "EventsGprot.h"
- #include "EventsDcl.h"
- #include "EventsDef.h"
- #include "gui_data_types.h"
- #include "gui.h"
- #include "GpioInc.h"
- #include "IdleAppProt.h"
- #include "TouchScreenGprot.h"
- #include "DebugInitDef.h"
- #include "Touch_Panel.h"
- #include "Drv_Comm.h" /* mmi_pen_touch_panel_sendilm() */
- #include "gdi_include.h"
- #include "ScreenRotationGprot.h"
- #include "touch_panel_custom.h" /* get handwriting pad setting */
- // TODO: make ext_region as NULL
- /*****************************************************************************
- * Define
- *****************************************************************************/
- /* Time between Pen Long-tap and Pen Repeat */
- #define MMI_PEN_POLLING_PERIOD (4 * 10) /* ms */
- /* Size of look-ahead buffer */
- #define MMI_PEN_LOOKAHEAD_BUFFER_SIZE (25)
- /*
- * Delayed polling period time. (We allow only 5 Pen Down event per sec)
- * We restrict the frequency of incoming Pen Down events in MMI framework instead of
- * driver debounce time because driver debounce time needs to be smaller than sampling period.
- */
- #define MMI_PEN_DEBOUNCE_POLLING_DELAY (1000 / 5 - MMI_PEN_POLLING_PERIOD)
- /*****************************************************************************
- * Typedef
- *****************************************************************************/
- typedef struct
- {
- /* mmi_pen_block() & mmi_pen_unblock() */
- U32 is_blocked:1;
- /* mmi_pen_enable() & mmi_pen_disable() */
- U32 is_enabled:1;
- /* After PEN_DOWN, mmi_pen_reset() set 'is_pen_down' to 0 */
- U32 is_pen_down:1;
- /* Debug only. After STROKE_DOWN, mmi_pen_reset() set 'is_stroke_down' to 0 */
- U32 is_stroke_down:1;
- /* Pen down in hand-writing area, but we still do not know if it is a stroke */
- U32 is_pending_stroke_event:1;
- /*
- * Set by mmi_pen_change_handwriting_area() and mmi_pen_stop_capture_strokes().
- * Close stroke and reset touch screen when pen is up.
- */
- U32 reset_stroke_on_pen_up:1;
- /*
- * Reset sampling rate when pen is reset.
- * This is used when we change the sampling rate temporarily.
- */
- U32 restore_sampling_rate_on_reset:1;
- /* Pen down position */
- mmi_pen_point_struct pen_down_pos;
- /* The current pen position */
- mmi_pen_point_struct pen_current_pos;
- /* Block index of handwriting area */
- S32 stroke_down_block_index;
- /* For stroke */
- S32 num_points_queued;
- /* Number of events in look-ahead buffer */
- S32 num_lookahead_events;
- } mmi_pen_context_struct;
- /*****************************************************************************
- * Local Variable
- *****************************************************************************/
- /* Global pen context that is reset in mmi_pen_reset() and mmi_pen_disable() */
- static mmi_pen_context_struct g_pen_cntx;
- /* Only normal poweron initialize touch screen. Otherwise, touch screen is not initialized */
- static kal_bool g_pen_initialized;
- /*
- * Whether the timer for mmi_pen_poll_hdlr() is started
- *
- * 'g_pen_polling_timer_started' is not put inside g_pen_cntx because
- * 1. We want to restrict the frequency of incoming pen events
- * 2. When polling timer is started, we do not stop it.
- * 3. 'g_pen_polling_timer_started' should not be cleared in mmi_pen_reset() or mmi_pen_disable()
- */
- MMI_BOOL g_pen_polling_timer_started;
- /* Whether MSG_ID_TP_EVENT_IND is already en-queued in MMI external queue */
- /* It is not put inside g_pen_cntx for similar reason like g_pen_polling_timer_started */
- U32 g_pen_is_driver_indication_in_queue;
- static mmi_pen_hdlr g_pen_event_table[MMI_PEN_EVENT_TYPE_MAX];
- static mmi_pen_hdlr g_pen_stroke_table[MMI_PEN_STROKE_TYPE_MAX];
- static void (*g_pen_stroke_pre_move) (void);
- static void (*g_pen_stroke_post_move) (void);
- /*
- * Stroke buffer
- */
- static S32 g_pen_stroke_max_points;
- static mmi_pen_point_struct *g_pen_stroke_points;
- /* Used for the new multi-block feature.
- Note: the data can be put into driver, but we do not want to change driver interface
- because customers may port their driver */
- static mmi_pen_handwriting_area_struct g_pen_stroke_areas[HAND_WRITING_AREA_NUM];
- static S32 g_pen_num_stroke_area;
- /* Minimum square distance (diff_x^2 + diff_y^2) */
- static S16 g_pen_stroke_min_offset_square;
- /*
- * Lookahead buffer
- */
- static TouchPanelEventStruct g_pen_lookahead_buffer[MMI_PEN_LOOKAHEAD_BUFFER_SIZE];
- /*****************************************************************************
- * Local Function
- *****************************************************************************/
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_get_distance_square
- * DESCRIPTION
- *
- * PARAMETERS
- * pos1 [IN]
- * pos2 [IN]
- * RETURNS
- *
- *****************************************************************************/
- static S16 mmi_pen_get_distance_square(mmi_pen_point_struct pos1, mmi_pen_point_struct pos2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 diff_x = pos1.x - pos2.x;
- S16 diff_y = pos1.y - pos2.y;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (diff_x < 0)
- {
- diff_x = -diff_x;
- }
- if (diff_y < 0)
- {
- diff_y = -diff_y;
- }
- return (diff_x * diff_x) + (diff_y * diff_y);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_push_stroke_point
- * DESCRIPTION
- *
- * PARAMETERS
- * x [IN]
- * y [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_push_stroke_point(S16 x, S16 y)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_pen_cntx.num_points_queued >= g_pen_stroke_max_points - 2)
- {
- /* Leave the last two slots for (-1, 0) and (-1, -1) */
- return;
- }
- g_pen_stroke_points[g_pen_cntx.num_points_queued].x = x;
- g_pen_stroke_points[g_pen_cntx.num_points_queued].y = y;
- g_pen_cntx.num_points_queued++;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_push_stroke_end
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_push_stroke_end(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_pen_cntx.num_points_queued >= g_pen_stroke_max_points - 1)
- {
- return;
- }
- #if defined(__MMI_HANWANG__)
- g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
- g_pen_stroke_points[g_pen_cntx.num_points_queued].y = 0;
- #elif defined(__MMI_PENPOWER__)
- g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
- g_pen_stroke_points[g_pen_cntx.num_points_queued].y = -1;
- #else
- g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
- g_pen_stroke_points[g_pen_cntx.num_points_queued].y = 0;
- #endif
- g_pen_cntx.num_points_queued++;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_push_char_end
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_push_char_end(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_pen_cntx.num_points_queued >= g_pen_stroke_max_points)
- {
- MMI_DBG_ASSERT(0); /* queue full */
- return;
- }
- #if defined(__MMI_HANWANG__)
- g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
- g_pen_stroke_points[g_pen_cntx.num_points_queued].y = -1;
- #elif defined(__MMI_PENPOWER__)
- g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
- g_pen_stroke_points[g_pen_cntx.num_points_queued].y = 0;
- #else
- g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
- g_pen_stroke_points[g_pen_cntx.num_points_queued].y = -1;
- #endif
- g_pen_cntx.num_points_queued++;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_lookup_handwriting_block
- * DESCRIPTION
- * Search which handwriting block contains a point (multi-block mode)
- * PARAMETERS
- * x [IN]
- * y [IN]
- * RETURNS
- * The index of handwriting block. 0 for block-0 or extended area, -1 if not found.
- *****************************************************************************/
- static S32 mmi_pen_lookup_handwriting_block(S32 x, S32 y)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- int i;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = 0; i < g_pen_num_stroke_area; i++)
- {
- if (x >= g_pen_stroke_areas[i].x1 && x <= g_pen_stroke_areas[i].x2 &&
- y >= g_pen_stroke_areas[i].y1 && y <= g_pen_stroke_areas[i].y2)
- {
- return i;
- }
- }
- return -1;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_fix_multi_block_pen_position
- * DESCRIPTION
- * Restrict stroke position to the current handwriting block
- * PARAMETERS
- * pos [IN/OUT]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_fix_multi_block_pen_position(mmi_pen_point_struct *pos)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- mmi_pen_handwriting_area_struct *block;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_ASSERT(g_pen_cntx.stroke_down_block_index >= 0 &&
- g_pen_cntx.stroke_down_block_index < g_pen_num_stroke_area);
- block = &g_pen_stroke_areas[g_pen_cntx.stroke_down_block_index];
- if (pos->x < block->x1)
- {
- pos->x = block->x1;
- }
- else if (pos->x > block->x2)
- {
- pos->x = block->x2;
- }
- if (pos->y < block->y1)
- {
- pos->y = block->y1;
- }
- else if (pos->y > block->y2)
- {
- pos->y = block->y2;
- }
- }
- /*
- * Look-ahead buffer of pen events (used in mmi_pen_poll_hdlr())
- *
- * If our MMI is blocked and fails to process incoming pen events fast enough,
- * it may have unexpected results (e.g. extq full) unless we drop certain pending events.
- */
- /*
- * Fill the data in lookahead buffer.
- *
- * The sampling rate of pen events (MMI_PEN_SAMPLING_PERIOD_1) is very high,
- * If we find paired Pen Down/Up, it means that MMI is blocked.
- *
- * 1. If there are consecutive Pen Move events, keep the last one.
- * 2. If there are paired "Pen Down ~ Pen Up", drop it.
- *
- * We do not drop stroke events because it is used by handwriting engine.
- */
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_lookahead_buffer_fill_data
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_lookahead_buffer_fill_data(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 rindex, windex;
- S32 first_down_index, last_up_index;
- TouchPanelEventStruct touch_data;
- #ifdef __MMI_SCREEN_ROTATE__
- /* U8 gdi_rotate_value; */
- MMI_BOOL screen_rotated = MMI_FALSE;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (mmi_frm_get_screen_rotate() != MMI_FRM_SCREEN_ROTATE_0)
- {
- /* Even if GDI base layer is rotated, we do not translate pen coordinates
- unless mmi_frm_screen_rotate() is invoked. */
- screen_rotated = MMI_TRUE;
- }
- /* gdi_rotate_value = gdi_layer_get_base_layer_rotation(); */
- #endif /* __MMI_SCREEN_ROTATE__ */
- for (windex = g_pen_cntx.num_lookahead_events; windex < MMI_PEN_LOOKAHEAD_BUFFER_SIZE; windex++)
- {
- if (!touch_panel_get_event(&touch_data))
- {
- break;
- }
- #ifdef __MMI_SCREEN_ROTATE__
- if (screen_rotated)
- {
- S32 tmp_x = touch_data.x_adc, tmp_y = touch_data.y_adc;
- /* W06.04 Replace functions for GDI LCD Rotate */
- gdi_rotate_map_absolute_hw_to_lcd(&tmp_x, &tmp_y);
- /* gdi_layer_map_rotated_coordinates(gdi_rotate_value, &tmp_x, &tmp_y); */
- touch_data.x_adc = (kal_int16) tmp_x;
- touch_data.y_adc = (kal_int16) tmp_y;
- }
- #endif /* __MMI_SCREEN_ROTATE__ */
- g_pen_lookahead_buffer[windex] = touch_data;
- }
- g_pen_cntx.num_lookahead_events = windex;
- if (g_pen_cntx.num_lookahead_events == 0)
- {
- return; /* Exit point */
- }
- /* Remove paired Pen Down/Up */
- first_down_index = -1;
- last_up_index = -1;
- for (rindex = 1 /* not including the first event */ ; rindex < g_pen_cntx.num_lookahead_events; rindex++)
- {
- switch (g_pen_lookahead_buffer[rindex].event)
- {
- case PEN_DOWN:
- if (first_down_index < 0)
- {
- first_down_index = rindex;
- }
- break;
- case PEN_UP:
- last_up_index = rindex;
- break;
- case PEN_MOVE:
- case PEN_LONGTAP:
- case PEN_REPEAT:
- break;
- default:
- /* Some events can not be dropped */
- first_down_index = -1;
- }
- }
- if (first_down_index > 0 && last_up_index > first_down_index)
- {
- if (last_up_index < g_pen_cntx.num_lookahead_events - 1)
- {
- Trace2(MMI_TRACE_G1_FRM, "[Pen] Drop lookahead buffer (%d - %d) n", first_down_index, last_up_index);
- memmove(
- &g_pen_lookahead_buffer[first_down_index],
- &g_pen_lookahead_buffer[last_up_index + 1],
- sizeof(TouchPanelEventStruct) * (g_pen_cntx.num_lookahead_events - 1 - last_up_index));
- }
- g_pen_cntx.num_lookahead_events -= (last_up_index - first_down_index + 1);
- }
- /*
- * If there are multiple Pen Move events queued, it means that pen handler can not
- * process the events fast enough. We should drop Pen Move events before the last one in queue.
- */
- for (windex = 0, rindex = 0; rindex < g_pen_cntx.num_lookahead_events; rindex++)
- {
- if (g_pen_lookahead_buffer[rindex].event == PEN_MOVE &&
- rindex < g_pen_cntx.num_lookahead_events - 1 && g_pen_lookahead_buffer[rindex + 1].event == PEN_MOVE)
- {
- /* Drop this Pen Move event. */
- continue;
- }
- if (windex != rindex)
- {
- g_pen_lookahead_buffer[windex] = g_pen_lookahead_buffer[rindex];
- }
- windex++;
- }
- g_pen_cntx.num_lookahead_events = windex;
- }
- /* Buffered version of touch_panel_peek_event() */
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_lookahead_buffer_peek_event
- * DESCRIPTION
- *
- * PARAMETERS
- * touch_data [OUT]
- * RETURNS
- *
- *****************************************************************************/
- static kal_bool mmi_pen_lookahead_buffer_peek_event(TouchPanelEventStruct *touch_data)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (!g_pen_cntx.num_lookahead_events)
- {
- mmi_pen_lookahead_buffer_fill_data();
- }
- if (g_pen_cntx.num_lookahead_events)
- {
- *touch_data = g_pen_lookahead_buffer[0];
- return KAL_TRUE;
- }
- else
- {
- return KAL_FALSE;
- }
- }
- /* Buffered version of touch_panel_get_event() */
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_lookahead_buffer_get_event
- * DESCRIPTION
- *
- * PARAMETERS
- * touch_data [OUT]
- * RETURNS
- *
- *****************************************************************************/
- static kal_bool mmi_pen_lookahead_buffer_get_event(TouchPanelEventStruct *touch_data)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 i;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_lookahead_buffer_fill_data();
- if (g_pen_cntx.num_lookahead_events > 0)
- {
- *touch_data = g_pen_lookahead_buffer[0];
- g_pen_cntx.num_lookahead_events--;
- for (i = 0; i < g_pen_cntx.num_lookahead_events; i++)
- {
- g_pen_lookahead_buffer[i] = g_pen_lookahead_buffer[i + 1];
- }
- return KAL_TRUE;
- }
- else
- {
- return KAL_FALSE;
- }
- }
- /*
- * Core polling loop for pen events
- */
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_poll_hdlr
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_poll_hdlr(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- TouchPanelEventStruct data;
- MMI_BOOL is_stroke_move = MMI_FALSE;
- MMI_BOOL has_incoming_event = MMI_FALSE;
- MMI_BOOL delay_polling_timer = MMI_FALSE;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_polling_timer_started = MMI_FALSE;
- Trace2(
- MMI_TRACE_G1_FRM,
- "[Pen] mmi_pen_poll_hdlr() - %d %d n",
- (int)g_pen_cntx.is_enabled,
- (int)g_pen_cntx.num_lookahead_events);
- if (!g_pen_cntx.is_enabled)
- {
- /* Note: We do not stop polling timer even in mmi_pen_disable() */
- return;
- }
- /* Although pen events (move, repeat) should keep backlight on,
- Playing i-melody may turn on/off backlight actively.
- We do not call mmi_pen_reset() when pen is down because some apps
- may not handle Pen Abort event. */
- if (!IsBacklightOn() && !g_pen_cntx.is_pen_down)
- {
- Trace2(MMI_TRACE_G1_FRM, "[Pen] mmi_pen_poll_hdlr() - no backlightn");
- TurnOnBacklight(MMI_TRUE);
- mmi_pen_reset(); /* flush queue */
- return;
- }
- while (!delay_polling_timer && mmi_pen_lookahead_buffer_get_event(&data))
- {
- mmi_pen_point_struct pos;
- if (!g_pen_cntx.is_enabled)
- {
- /* Previous pen handlers might call mmi_pen_disable(), but
- we should already flush driver pen queue on mmi_pen_disable() */
- MMI_DBG_ASSERT(0);
- break;
- }
- pos.x = (S16) data.x_adc;
- pos.y = (S16) data.y_adc;
- #if 0
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- #endif /* 0 */
- has_incoming_event = MMI_TRUE;
- if (is_stroke_move && (data.event != STROKE_MOVE))
- {
- is_stroke_move = MMI_FALSE;
- if (g_pen_stroke_post_move)
- {
- g_pen_stroke_post_move();
- }
- }
- g_pen_cntx.pen_current_pos = pos;
- switch (data.event)
- {
- /* Call pen handler after setting context variables because pen handler might invoke mmi_pen_reset() */
- case PEN_DOWN:
- MMI_DBG_ASSERT(!g_pen_cntx.is_pen_down);
- g_pen_cntx.is_pen_down = 1;
- g_pen_cntx.pen_down_pos = pos;
- if (g_pen_event_table[MMI_PEN_EVENT_DOWN])
- {
- (g_pen_event_table[MMI_PEN_EVENT_DOWN]) (pos);
- }
- break;
- case PEN_UP:
- MMI_DBG_ASSERT(g_pen_cntx.is_pen_down);
- g_pen_cntx.is_pen_down = 0;
- if (g_pen_event_table[MMI_PEN_EVENT_UP])
- {
- (g_pen_event_table[MMI_PEN_EVENT_UP]) (pos);
- }
- if (g_pen_cntx.reset_stroke_on_pen_up)
- {
- if (g_pen_stroke_max_points > 0)
- {
- mmi_pen_end_strokes_of_character();
- mmi_pen_reset();
- mmi_pen_begin_strokes_of_character();
- }
- else
- {
- mmi_pen_reset();
- }
- }
- /* Delay processing futher events */
- delay_polling_timer = MMI_TRUE;
- break;
- case PEN_MOVE:
- MMI_DBG_ASSERT(g_pen_cntx.is_pen_down);
- if (g_pen_event_table[MMI_PEN_EVENT_MOVE])
- {
- (g_pen_event_table[MMI_PEN_EVENT_MOVE]) (pos);
- }
- break;
- case PEN_LONGTAP:
- MMI_DBG_ASSERT(g_pen_cntx.is_pen_down);
- if (g_pen_event_table[MMI_PEN_EVENT_LONG_TAP])
- {
- (g_pen_event_table[MMI_PEN_EVENT_LONG_TAP]) (pos);
- }
- break;
- case PEN_REPEAT:
- MMI_DBG_ASSERT(g_pen_cntx.is_pen_down);
- if (g_pen_event_table[MMI_PEN_EVENT_REPEAT])
- {
- (g_pen_event_table[MMI_PEN_EVENT_REPEAT]) (pos);
- }
- break;
- case PEN_ABORT:
- /* Driver queue full */
- mmi_pen_reset();
- break;
- case TP_UNKNOWN_EVENT:
- MMI_ASSERT(0);
- break;
- case STROKE_MOVE:
- MMI_DBG_ASSERT(g_pen_cntx.is_stroke_down && g_pen_cntx.is_pen_down);
- /* mmi_pen_reset() should be used after mmi_pen_stop_capture_strokes() such that enqueued stroke events are flushed. */
- MMI_DBG_ASSERT(g_pen_stroke_max_points > 0);
- if (g_pen_cntx.is_pending_stroke_event)
- {
- if (mmi_pen_get_distance_square(g_pen_cntx.pen_down_pos, pos) > g_pen_stroke_min_offset_square)
- {
- g_pen_cntx.is_pending_stroke_event = 0;
- g_pen_stroke_min_offset_square = 0; /* The next stroke does not have minimum offset */
- /* Pen Down -> Pen Move -> Pen Abort -> Stroke Down -> Stroke Move -> Stroke Up
- There is no stroke points queued before the first stroke is created
- If we set 'reset_stroke_on_pen_up' in previous Pen Down handler and invoke mmi_pen_reset() in Stroke Up,
- all stroke points in between are discarded */
- g_pen_cntx.reset_stroke_on_pen_up = 0;
- /* Abort previous Pen Down event */
- if (g_pen_event_table[MMI_PEN_EVENT_ABORT])
- {
- (g_pen_event_table[MMI_PEN_EVENT_ABORT]) (g_pen_cntx.pen_down_pos);
- }
- /* Handle Stroke Down */
- mmi_pen_push_stroke_point(g_pen_cntx.pen_down_pos.x, g_pen_cntx.pen_down_pos.y);
- if (g_pen_stroke_table[MMI_PEN_STROKE_DOWN])
- {
- (g_pen_stroke_table[MMI_PEN_STROKE_DOWN]) (g_pen_cntx.pen_down_pos);
- }
- /* Pre-Stroke-Move */
- MMI_DBG_ASSERT(!is_stroke_move);
- is_stroke_move = MMI_TRUE;
- if (g_pen_stroke_pre_move)
- {
- g_pen_stroke_pre_move();
- }
- /* Stroke Move */
- mmi_pen_push_stroke_point(pos.x, pos.y);
- if (g_pen_stroke_table[MMI_PEN_STROKE_MOVE])
- {
- (g_pen_stroke_table[MMI_PEN_STROKE_MOVE]) (pos);
- }
- }
- }
- else
- {
- if (g_pen_num_stroke_area > 1)
- {
- mmi_pen_fix_multi_block_pen_position(&pos);
- }
- if (!is_stroke_move)
- {
- is_stroke_move = MMI_TRUE;
- if (g_pen_stroke_pre_move)
- {
- g_pen_stroke_pre_move();
- }
- }
- mmi_pen_push_stroke_point(pos.x, pos.y);
- if (g_pen_stroke_table[MMI_PEN_STROKE_MOVE])
- {
- (g_pen_stroke_table[MMI_PEN_STROKE_MOVE]) (pos);
- }
- }
- break;
- case STROKE_DOWN:
- MMI_DBG_ASSERT(!g_pen_cntx.is_stroke_down && !g_pen_cntx.is_pen_down);
- /* mmi_pen_reset() should be used after mmi_pen_stop_capture_strokes() such that enqueued stroke events are flushed. */
- MMI_DBG_ASSERT(g_pen_stroke_max_points > 0);
- g_pen_cntx.is_stroke_down = 1;
- g_pen_cntx.is_pen_down = 1;
- g_pen_cntx.pen_down_pos = pos;
- g_pen_cntx.stroke_down_block_index = mmi_pen_lookup_handwriting_block(pos.x, pos.y);
- if (g_pen_num_stroke_area > 1 && g_pen_cntx.stroke_down_block_index < 0)
- {
- /* MMI framework and driver have intergration problem.
- Maybe the current driver does not support multi-block,
- or driver does not disable extended handwriting area properly in
- multi-block mode. */
- MMI_ASSERT(0);
- }
- if (g_pen_stroke_min_offset_square > 0)
- {
- g_pen_cntx.is_pending_stroke_event = 1;
- /* Fire pen down event. For example, it will display key down on virtual keyboard. */
- if (g_pen_event_table[MMI_PEN_EVENT_DOWN])
- {
- (g_pen_event_table[MMI_PEN_EVENT_DOWN]) (g_pen_cntx.pen_down_pos);
- }
- }
- else
- {
- g_pen_cntx.is_pending_stroke_event = 0;
- if (g_pen_stroke_table[MMI_PEN_STROKE_DOWN])
- {
- (g_pen_stroke_table[MMI_PEN_STROKE_DOWN]) (pos);
- }
- /* Put stroke point after stroke down handler because multi-block handwriting may invoke
- * mmi_pen_begin_strokes_of_character() and mmi_pen_end_strokes_of_character() in
- * Stroke Down handler.
- */
- if (g_pen_cntx.is_enabled && g_pen_cntx.is_pen_down && g_pen_stroke_max_points > 0)
- {
- mmi_pen_push_stroke_point(pos.x, pos.y);
- }
- }
- break;
- case STROKE_UP:
- MMI_DBG_ASSERT(g_pen_cntx.is_stroke_down && g_pen_cntx.is_pen_down);
- /* mmi_pen_reset() should be used after mmi_pen_stop_capture_strokes() such that enqueued stroke events are flushed. */
- MMI_DBG_ASSERT(g_pen_stroke_max_points > 0);
- g_pen_cntx.is_stroke_down = 0;
- g_pen_cntx.is_pen_down = 0;
- if (g_pen_cntx.is_pending_stroke_event)
- {
- g_pen_cntx.is_pending_stroke_event = 0;
- /*
- * Flush driver queue and lookahead buffer:
- * Otherwise, it might restore handwriting area (touch_panel_reset_handwriting)
- * while stroke-based mode is already entered.
- */
- g_pen_cntx.reset_stroke_on_pen_up = 1;
- /* Note: if pen up handler invokes mmi_pen_reset(), g_pen_cntx.reset_stroke_on_pen_up is cleared */
- if (g_pen_event_table[MMI_PEN_EVENT_UP])
- {
- (g_pen_event_table[MMI_PEN_EVENT_UP]) (g_pen_cntx.pen_down_pos);
- }
- /* Delay processing further events */
- delay_polling_timer = MMI_TRUE;
- }
- else
- {
- /*
- * Because touch panel can not detect pen position in Stroke Up event,
- * we do not put the point into stroke queue
- */
- if (g_pen_num_stroke_area > 1)
- {
- mmi_pen_fix_multi_block_pen_position(&pos);
- }
- mmi_pen_push_stroke_end();
- if (g_pen_stroke_table[MMI_PEN_STROKE_UP])
- {
- (g_pen_stroke_table[MMI_PEN_STROKE_UP]) (pos);
- }
- }
- /* Clear strokes and reset handwriting area */
- if (g_pen_cntx.reset_stroke_on_pen_up)
- {
- if (g_pen_stroke_max_points > 0)
- {
- mmi_pen_end_strokes_of_character();
- mmi_pen_reset();
- mmi_pen_begin_strokes_of_character();
- }
- else
- {
- mmi_pen_reset();
- }
- }
- break;
- #ifdef MMI_PEN_SUPPORT_STROKE_LONGTAP
- case STROKE_LONGTAP:
- /*
- * 1. degrade sampling rate
- * 2. reset strokes on pen on
- */
- mmi_pen_config_sampling_period(MMI_PEN_SAMPLING_PERIOD_1, MMI_PEN_SAMPLING_PERIOD_1);
- g_pen_cntx.reset_stroke_on_pen_up = 1;
- g_pen_cntx.restore_sampling_rate_on_reset = 1;
- if (g_pen_stroke_table[MMI_PEN_STROKE_LONGTAP])
- {
- (g_pen_stroke_table[MMI_PEN_STROKE_LONGTAP]) (pos);
- }
- break;
- #else /* MMI_PEN_SUPPORT_STROKE_LONGTAP */
- case STROKE_LONGTAP:
- break;
- #endif /* MMI_PEN_SUPPORT_STROKE_LONGTAP */
- default:
- MMI_ASSERT(0);
- }
- mmi_frm_fetch_msg_from_extQ_to_circularQ();
- }
- if (is_stroke_move)
- {
- if (g_pen_stroke_post_move)
- {
- g_pen_stroke_post_move();
- }
- }
- if (has_incoming_event)
- {
- TurnOnBacklight(MMI_TRUE);
- #ifdef __MMI_LCD_PARTIAL_ON__
- /* Switch screen and flush pen events */
- LeavePartialOnScreenSaverIfOk();
- #endif /* __MMI_LCD_PARTIAL_ON__ */
- }
- /* Either look-ahead buffer is empty or we need to skip the polling */
- MMI_ASSERT(g_pen_cntx.num_lookahead_events == 0 || delay_polling_timer);
- if (delay_polling_timer)
- {
- /* Start a timer even if !g_pen_cntx.is_enabled && !g_pen_cntx.is_pen_down && g_pen_cntx.num_lookahead_events == 0 */
- StartTimer(PEN_POLLING_TIMER, MMI_PEN_DEBOUNCE_POLLING_DELAY, mmi_pen_poll_hdlr);
- g_pen_polling_timer_started = MMI_TRUE;
- Trace2(MMI_TRACE_G1_FRM, "[Pen] mmi_pen_poll_hdlr() - delay polling timer n");
- }
- else if (g_pen_cntx.is_pen_down)
- {
- /* Previous pen handlers might call mmi_pen_disable(), then g_pen_cntx.is_pen_down = 0. */
- MMI_DBG_ASSERT(g_pen_cntx.is_enabled);
- StartTimer(PEN_POLLING_TIMER, MMI_PEN_POLLING_PERIOD, mmi_pen_poll_hdlr);
- g_pen_polling_timer_started = MMI_TRUE;
- }
- }
- /*
- * Refernece: touch_panel_sendilm()
- * THIS FUNCTION IS EXECUTED IN DRIVER CONTEXT
- */
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_touch_panel_sendilm
- * DESCRIPTION
- *
- * PARAMETERS
- * param [IN] unused
- * state [IN]
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_touch_panel_sendilm(void *param /* unused */ , Touch_Panel_Event_enum state)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- ilm_struct *tp_ilm;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Dummy function */
- if (state == PEN_DOWN || state == STROKE_DOWN)
- {
- if (!g_pen_is_driver_indication_in_queue)
- {
- g_pen_is_driver_indication_in_queue = 1;
- DRV_BuildPrimitive(tp_ilm, MOD_TP_TASK, MOD_MMI, MSG_ID_TP_EVENT_IND, NULL);
- msg_send_ext_queue(tp_ilm);
- }
- }
- }
- /* Protocol event handler of MSG_ID_TP_EVENT_IND */
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_touch_panel_event_ind
- * DESCRIPTION
- *
- * PARAMETERS
- * param [IN] unused
- * RETURNS
- * void
- *****************************************************************************/
- static void mmi_pen_touch_panel_event_ind(void *param /* unused */ )
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- Trace2(
- MMI_TRACE_G1_FRM,
- "[Pen] mmi_pen_touch_panel_event_in - %d, %dn",
- (int)g_pen_polling_timer_started,
- (int)g_pen_cntx.is_enabled);
- g_pen_is_driver_indication_in_queue = 0;
- if (!g_pen_polling_timer_started && g_pen_cntx.is_enabled)
- {
- mmi_pen_poll_hdlr();
- }
- }
- /*****************************************************************************
- * Global Variable
- *****************************************************************************/
- /*****************************************************************************
- * Global Function
- *****************************************************************************/
- /* Dummy pen handler */
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_dummy_hdlr
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_dummy_hdlr(mmi_pen_point_struct pos)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- UI_UNUSED_PARAMETER(pos);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_init
- * DESCRIPTION
- * Initialize pen system
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_init(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef __MMI_HANDWRITING_PAD__
- mmi_frm_setup_default_pen_handler();
- #endif
- g_pen_initialized = KAL_TRUE;
- mmi_pen_stop_capture_strokes();
- mmi_pen_config_sampling_period(MMI_PEN_SAMPLING_PERIOD_1, MMI_PEN_SAMPLING_PERIOD_2);
- mmi_pen_config_timeout_period(MMI_PEN_LONGTAP_TIME, MMI_PEN_REPEAT_TIME, MMI_PEN_STROKE_LONGTAP_TIME);
- mmi_pen_config_move_offset(
- MMI_PEN_SKIP_MOVE_OFFSET,
- MMI_PEN_SKIP_STROKE_MOVE_OFFSET,
- MMI_PEN_SKIP_LONGTAP_OFFSET,
- MMI_PEN_SKIP_STROKE_LONGTAP_OFFSET);
- touch_panel_cb_registration(mmi_pen_touch_panel_sendilm, NULL);
- SetProtocolEventHandler(mmi_pen_touch_panel_event_ind, MSG_ID_TP_EVENT_IND);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_block
- * DESCRIPTION
- * Block pen system
- *
- * Note: typically used for keypad lock in idle screen
- * mmi_pen_enable()/mmi_pen_disable() are ignored when pen is blocked.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_block(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_disable();
- g_pen_cntx.is_blocked = 1;
- }
- //KP Jerry add on 2007-4-11 start
- #ifdef __MMI_PEN_BLOCK_WHEN_KAYPAD_LOCKED__
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_forced_block
- * DESCRIPTION
- * Block pen system forced
- *
- * Note: typically used for keypad lock in idle screen
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_forced_block(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_pen_forced_disable();
- g_pen_cntx.is_blocked = 1;
- }
- #endif/*__MMI_PEN_BLOCK_WHEN_KAYPAD_LOCKED__*/
- //KP Jerry add on 2007-4-11 end
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_unblock
- * DESCRIPTION
- * Unblock pen system
- *
- * Note: typically used for keypad lock in idle screen
- * mmi_pen_enable()/mmi_pen_disable() are ignored when pen is blocked.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_unblock(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_cntx.is_blocked = 0;
- mmi_pen_enable();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_config_sampling_period
- * DESCRIPTION
- * Config sampling period of Event-based and Stroke-Based
- * PARAMETERS
- * low [IN] Sampling period in non-handwriting area (multiple of 10ms)
- * high [IN] Sampling period in handwriting area (multiple of 10ms)
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_config_sampling_period(kal_uint32 low, kal_uint32 high)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- touch_panle_conf_sample_period(low, high);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_config_timeout_period
- * DESCRIPTION
- * Config timeout period for LongTap and Repeat
- * PARAMETERS
- * longtap [IN] Timeout period for Pen LongTap event (multiple of 10ms).
- * repeat [IN] Timeout period for Pen Repeat event (multiple of 10ms).
- * stroke_longtap [IN] Timeout period for Stroke LongTap event (multiple of 10ms).
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_config_timeout_period(kal_uint32 longtap, kal_uint32 repeat, kal_uint32 stroke_longtap)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- touch_panle_conf_timeout_period(longtap, repeat, stroke_longtap);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_config_move_offset
- * DESCRIPTION
- * Config
- * PARAMETERS
- * event_based [IN] Minimum move offset for Pen Move event
- * stroke_based [IN] Minimum move offset for Stroke Move event
- * long_tap [IN] Maximum move offset for Pen LongTap event
- * stroke_long_tap [IN] Maximum move offset for Stroke LongTap event
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_config_move_offset(
- kal_uint32 event_based,
- kal_uint32 stroke_based,
- kal_uint32 long_tap,
- kal_uint32 stroke_long_tap)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- touch_panel_conf_move_offset(
- (kal_uint16) event_based,
- (kal_uint16) stroke_based,
- (kal_uint16) long_tap,
- (kal_uint16) stroke_long_tap);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_enable
- * DESCRIPTION
- * Enable pen system
- *
- * Note: typically on Keypad Up
- * PARAMETERS
- * void
- * RETURNS
- * void
- * REMARKS
- * If g_pen_initialized is not true, we do not enable touch screen because
- * TP task might not be running
- *****************************************************************************/
- void mmi_pen_enable(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- Trace2(MMI_TRACE_G1_FRM, "[Pen] mmi_pen_enable()n");
- if (!g_pen_initialized || g_pen_cntx.is_blocked || g_pen_cntx.is_enabled)
- {
- return;
- }
- memset(&g_pen_cntx, 0, sizeof(g_pen_cntx));
- g_pen_cntx.is_enabled = 1;
- touch_panel_enable(KAL_TRUE);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_disable
- * DESCRIPTION
- * Disable pen system
- *
- * Note: typically on Keypad Down because we don't want to use keypad and touch screen
- * at the same time
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_disable(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- Trace2(MMI_TRACE_G1_FRM, "[Pen] mmi_pen_disable()n");
- if (!g_pen_initialized || g_pen_cntx.is_blocked || !g_pen_cntx.is_enabled)
- {
- return;
- }
- touch_panel_enable(KAL_FALSE);
- touch_panel_flush();
- if (g_pen_cntx.is_pen_down)
- {
- /* For both stroke-based and event-based */
- if (g_pen_event_table[MMI_PEN_EVENT_ABORT])
- {
- (g_pen_event_table[MMI_PEN_EVENT_ABORT]) (g_pen_cntx.pen_current_pos);
- }
- }
- memset(&g_pen_cntx, 0, sizeof(g_pen_cntx));
- }
- //KP Jerry add on 2007-4-11 start
- #ifdef __MMI_PEN_BLOCK_WHEN_KAYPAD_LOCKED__
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_forced_disable
- * DESCRIPTION
- * Disable pen system
- *
- * Note: typically on Keypad Down because we don't want to use keypad and touch screen
- * at the same time
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_forced_disable(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- Trace2(MMI_TRACE_G1_FRM, "[Pen] mmi_pen_forced_disable()n");
- if (!g_pen_initialized || g_pen_cntx.is_blocked || !g_pen_cntx.is_enabled)
- {
- return;
- }
- touch_panel_enable(KAL_FALSE);
- touch_panel_flush();
- if (g_pen_cntx.is_pen_down)
- {
- /* For both stroke-based and event-based */
- if (g_pen_event_table[MMI_PEN_EVENT_ABORT])
- {
- (g_pen_event_table[MMI_PEN_EVENT_ABORT]) (g_pen_cntx.pen_current_pos);
- }
- }
- }
- #endif/*__MMI_PEN_BLOCK_WHEN_KAYPAD_LOCKED__*/
- //KP Jerry add on 2007-4-11 end
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_reset
- * DESCRIPTION
- * Reset the status of touch screen
- * - Flush event queue
- * - If the pen is currently tapped down, ignore all subsequent pen events until the pen is up.
- *
- * Note: typically on MMI screen switching
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_reset(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- Trace2(MMI_TRACE_G1_FRM, "[Pen] mmi_pen_reset()n");
- if (!g_pen_initialized || g_pen_cntx.is_blocked || !g_pen_cntx.is_enabled)
- {
- return;
- }
- if (g_pen_cntx.restore_sampling_rate_on_reset)
- {
- mmi_pen_config_sampling_period(MMI_PEN_SAMPLING_PERIOD_1, MMI_PEN_SAMPLING_PERIOD_2);
- }
- if (g_pen_cntx.is_pen_down)
- {
- /* For both stroke-based and event-based */
- if (g_pen_event_table[MMI_PEN_EVENT_ABORT])
- {
- (g_pen_event_table[MMI_PEN_EVENT_ABORT]) (g_pen_cntx.pen_current_pos);
- }
- }
- touch_panel_reset(KAL_TRUE);
- memset(&g_pen_cntx, 0, sizeof(g_pen_cntx));
- g_pen_cntx.is_enabled = 1;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_get_state
- * DESCRIPTION
- * Get the current state of touch screen
- * PARAMETERS
- * is_enabled [OUT]
- * is_pen_down [OUT]
- * RETURNS
- * void
- * REMARKS
- * It returns the current state *inside MMI task*, real pen state might be changed, but
- * the driver indication might not be processed yet.
- *****************************************************************************/
- void mmi_pen_get_state(kal_bool *is_enabled, kal_bool *is_pen_down)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_pen_cntx.is_enabled)
- {
- *is_enabled = KAL_TRUE;
- if (g_pen_cntx.is_pen_down)
- {
- *is_pen_down = KAL_TRUE;
- }
- else
- {
- *is_pen_down = KAL_FALSE;
- }
- }
- else
- {
- *is_enabled = KAL_FALSE;
- *is_pen_down = KAL_FALSE;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_start_calibration
- * DESCRIPTION
- * Start pen calibration
- * PARAMETERS
- * num [IN] Number of calibration points
- * points [IN] Calibration points
- * RETURNS
- * void
- * REMARKS
- * After mmi_pen_reset(), the calibration process is terminated.
- *****************************************************************************/
- void mmi_pen_start_calibration(kal_uint16 num, const mmi_pen_point_struct *points)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- Trace2(MMI_TRACE_G1_FRM, "[Pen] mmi_pen_start_calibration()n");
- MMI_ASSERT(g_pen_initialized);
- touch_panel_start_cali((TouchPanelCoordStruct*) points, num);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_set_calibration_data
- * DESCRIPTION
- * Assign driver calibration data
- * PARAMETERS
- * data [IN]
- * RETURNS
- * void
- * REMARKS
- *
- *****************************************************************************/
- void mmi_pen_set_calibration_data(const mmi_pen_calibration_struct *data)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- TouchPanelCaliStruct cali;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_DBG_ASSERT(sizeof(mmi_pen_calibration_struct) == sizeof(TouchPanelCaliStruct));
- memcpy(&cali, data, sizeof(TouchPanelCaliStruct));
- touch_panel_set_cali(cali);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_read_calibration_data
- * DESCRIPTION
- * Read the current value of driver calibration data
- * PARAMETERS
- * data [OUT]
- * RETURNS
- * void
- * REMARKS
- *
- *****************************************************************************/
- void mmi_pen_read_calibration_data(mmi_pen_calibration_struct *data)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- TouchPanelCaliStruct cali;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_DBG_ASSERT(sizeof(mmi_pen_calibration_struct) == sizeof(TouchPanelCaliStruct));
- touch_panel_read_cali(&cali);
- memcpy(data, &cali, sizeof(TouchPanelCaliStruct));
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_register_down_handler
- * DESCRIPTION
- * Register the Pen Down handler
- * PARAMETERS
- * pen_fp [IN] Callback handler
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_register_down_handler(mmi_pen_hdlr pen_fp)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_event_table[MMI_PEN_EVENT_DOWN] = pen_fp;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_register_long_tap_handler
- * DESCRIPTION
- * Register the Pen LongTap handler
- *
- * LongTap handler is invoked when the pen is tapped for a period of time
- * and stays at the same place where it is tapped down.
- *
- * It is invoked atmost one time before pen up.
- * PARAMETERS
- * pen_fp [IN] Callback handler
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_register_long_tap_handler(mmi_pen_hdlr pen_fp)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_event_table[MMI_PEN_EVENT_LONG_TAP] = pen_fp;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_register_repeat_handler
- * DESCRIPTION
- * Register the Pen Repeat handler.
- *
- * Repeat handler is invoked after LongTap handler.
- * However, unlike LongTap handler, Repeat handler is invoked even if
- * it does not stays at the same place as Pen Down.
- *
- * it might be invoked more than one times before pen up.
- * PARAMETERS
- * pen_fp [IN] Callback handler
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_register_repeat_handler(mmi_pen_hdlr pen_fp)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_event_table[MMI_PEN_EVENT_REPEAT] = pen_fp;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_register_move_handler
- * DESCRIPTION
- * Register the Pen Move handler.
- *
- * The invocation frequency of Pen Move handler is typically less than driver sampling rate.
- * PARAMETERS
- * pen_fp [IN] Callback handler
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_register_move_handler(mmi_pen_hdlr pen_fp)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_event_table[MMI_PEN_EVENT_MOVE] = pen_fp;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_register_up_handler
- * DESCRIPTION
- * Register the Pen Up handler.
- * PARAMETERS
- * pen_fp [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_register_up_handler(mmi_pen_hdlr pen_fp)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_event_table[MMI_PEN_EVENT_UP] = pen_fp;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_register_abort_handler
- * DESCRIPTION
- * Register the Pen Abort handler.
- * PARAMETERS
- * pen_fp [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_pen_register_abort_handler(mmi_pen_hdlr pen_fp)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_pen_event_table[MMI_PEN_EVENT_ABORT] = pen_fp;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_pen_start_capture_strokes
- * DESCRIPTION
- * Start to capture stroke inside the handwriting area.
- *
- * This API is typically used in entry function of editor screen.
- *
- * The points are en-queued in 'point_array' in the following format:
- *
- * Each point contains two 16-bit integers for x, y coordinates. Two strokes are separated with
- * marker (0xffff, 0), and all strokes of one character are ended with (0xffff, 0xffff) by
- * mmi_pen_end_strokes_of_character(). The parameter 'max_points' should also include the memory
- * used by markers.
- * (x0, y0) (x1, y1)