Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 1 | #ifndef _INPUT_MT_H |
| 2 | #define _INPUT_MT_H |
| 3 | |
| 4 | /* |
| 5 | * Input Multitouch Library |
| 6 | * |
| 7 | * Copyright (c) 2010 Henrik Rydberg |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 2 as published by |
| 11 | * the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/input.h> |
| 15 | |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 16 | #define TRKID_MAX 0xffff |
| 17 | |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame] | 18 | #define INPUT_MT_POINTER 0x0001 /* pointer device, e.g. trackpad */ |
| 19 | #define INPUT_MT_DIRECT 0x0002 /* direct device, e.g. touchscreen */ |
| 20 | #define INPUT_MT_DROP_UNUSED 0x0004 /* drop contacts not seen in frame */ |
Henrik Rydberg | 7c1a878 | 2012-08-12 20:47:05 +0200 | [diff] [blame] | 21 | #define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */ |
Henrik Rydberg | a0ef6a3 | 2013-04-07 20:52:22 -0700 | [diff] [blame] | 22 | #define INPUT_MT_SEMI_MT 0x0010 /* semi-mt device, finger count handled manually */ |
Henrik Rydberg | 7c1a878 | 2012-08-12 20:47:05 +0200 | [diff] [blame] | 23 | |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 24 | /** |
| 25 | * struct input_mt_slot - represents the state of an input MT slot |
| 26 | * @abs: holds current values of ABS_MT axes for this slot |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame] | 27 | * @frame: last frame at which input_mt_report_slot_state() was called |
Henrik Rydberg | 17a465a | 2012-09-01 09:27:20 +0200 | [diff] [blame] | 28 | * @key: optional driver designation of this slot |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 29 | */ |
| 30 | struct input_mt_slot { |
| 31 | int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame] | 32 | unsigned int frame; |
Henrik Rydberg | 17a465a | 2012-09-01 09:27:20 +0200 | [diff] [blame] | 33 | unsigned int key; |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 34 | }; |
| 35 | |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 36 | /** |
| 37 | * struct input_mt - state of tracked contacts |
| 38 | * @trkid: stores MT tracking ID for the next contact |
| 39 | * @num_slots: number of MT slots the device uses |
| 40 | * @slot: MT slot currently being transmitted |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 41 | * @flags: input_mt operation flags |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame] | 42 | * @frame: increases every time input_mt_sync_frame() is called |
Henrik Rydberg | 7c1a878 | 2012-08-12 20:47:05 +0200 | [diff] [blame] | 43 | * @red: reduced cost matrix for in-kernel tracking |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 44 | * @slots: array of slots holding current values of tracked contacts |
| 45 | */ |
| 46 | struct input_mt { |
| 47 | int trkid; |
| 48 | int num_slots; |
| 49 | int slot; |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 50 | unsigned int flags; |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame] | 51 | unsigned int frame; |
Henrik Rydberg | 7c1a878 | 2012-08-12 20:47:05 +0200 | [diff] [blame] | 52 | int *red; |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 53 | struct input_mt_slot slots[]; |
| 54 | }; |
| 55 | |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 56 | static inline void input_mt_set_value(struct input_mt_slot *slot, |
| 57 | unsigned code, int value) |
| 58 | { |
| 59 | slot->abs[code - ABS_MT_FIRST] = value; |
| 60 | } |
| 61 | |
| 62 | static inline int input_mt_get_value(const struct input_mt_slot *slot, |
| 63 | unsigned code) |
| 64 | { |
| 65 | return slot->abs[code - ABS_MT_FIRST]; |
| 66 | } |
| 67 | |
Henrik Rydberg | 7c1a878 | 2012-08-12 20:47:05 +0200 | [diff] [blame] | 68 | static inline bool input_mt_is_active(const struct input_mt_slot *slot) |
| 69 | { |
| 70 | return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0; |
| 71 | } |
| 72 | |
Benjamin Tissoires | 29807d1 | 2012-11-14 16:59:22 +0100 | [diff] [blame] | 73 | static inline bool input_mt_is_used(const struct input_mt *mt, |
| 74 | const struct input_mt_slot *slot) |
| 75 | { |
| 76 | return slot->frame == mt->frame; |
| 77 | } |
| 78 | |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 79 | int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, |
| 80 | unsigned int flags); |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 81 | void input_mt_destroy_slots(struct input_dev *dev); |
| 82 | |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 83 | static inline int input_mt_new_trkid(struct input_mt *mt) |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 84 | { |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 85 | return mt->trkid++ & TRKID_MAX; |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 88 | static inline void input_mt_slot(struct input_dev *dev, int slot) |
| 89 | { |
| 90 | input_event(dev, EV_ABS, ABS_MT_SLOT, slot); |
| 91 | } |
| 92 | |
Henrik Rydberg | b89529a | 2012-01-12 19:40:34 +0100 | [diff] [blame] | 93 | static inline bool input_is_mt_value(int axis) |
| 94 | { |
| 95 | return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST; |
| 96 | } |
| 97 | |
Jeff Brown | 80b4895 | 2011-04-18 10:08:02 -0700 | [diff] [blame] | 98 | static inline bool input_is_mt_axis(int axis) |
| 99 | { |
Henrik Rydberg | b89529a | 2012-01-12 19:40:34 +0100 | [diff] [blame] | 100 | return axis == ABS_MT_SLOT || input_is_mt_value(axis); |
Jeff Brown | 80b4895 | 2011-04-18 10:08:02 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 103 | void input_mt_report_slot_state(struct input_dev *dev, |
| 104 | unsigned int tool_type, bool active); |
| 105 | |
| 106 | void input_mt_report_finger_count(struct input_dev *dev, int count); |
| 107 | void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count); |
Henrik Rydberg | f8ec894 | 2014-07-25 17:16:42 -0700 | [diff] [blame] | 108 | void input_mt_drop_unused(struct input_dev *dev); |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 109 | |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame] | 110 | void input_mt_sync_frame(struct input_dev *dev); |
| 111 | |
Henrik Rydberg | 7c1a878 | 2012-08-12 20:47:05 +0200 | [diff] [blame] | 112 | /** |
| 113 | * struct input_mt_pos - contact position |
| 114 | * @x: horizontal coordinate |
| 115 | * @y: vertical coordinate |
| 116 | */ |
| 117 | struct input_mt_pos { |
| 118 | s16 x, y; |
| 119 | }; |
| 120 | |
| 121 | int input_mt_assign_slots(struct input_dev *dev, int *slots, |
| 122 | const struct input_mt_pos *pos, int num_pos); |
| 123 | |
Henrik Rydberg | 17a465a | 2012-09-01 09:27:20 +0200 | [diff] [blame] | 124 | int input_mt_get_slot_by_key(struct input_dev *dev, int key); |
| 125 | |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 126 | #endif |