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 | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 21 | /** |
| 22 | * struct input_mt_slot - represents the state of an input MT slot |
| 23 | * @abs: holds current values of ABS_MT axes for this slot |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame^] | 24 | * @frame: last frame at which input_mt_report_slot_state() was called |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 25 | */ |
| 26 | struct input_mt_slot { |
| 27 | int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame^] | 28 | unsigned int frame; |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 29 | }; |
| 30 | |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 31 | /** |
| 32 | * struct input_mt - state of tracked contacts |
| 33 | * @trkid: stores MT tracking ID for the next contact |
| 34 | * @num_slots: number of MT slots the device uses |
| 35 | * @slot: MT slot currently being transmitted |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 36 | * @flags: input_mt operation flags |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame^] | 37 | * @frame: increases every time input_mt_sync_frame() is called |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 38 | * @slots: array of slots holding current values of tracked contacts |
| 39 | */ |
| 40 | struct input_mt { |
| 41 | int trkid; |
| 42 | int num_slots; |
| 43 | int slot; |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 44 | unsigned int flags; |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame^] | 45 | unsigned int frame; |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 46 | struct input_mt_slot slots[]; |
| 47 | }; |
| 48 | |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 49 | static inline void input_mt_set_value(struct input_mt_slot *slot, |
| 50 | unsigned code, int value) |
| 51 | { |
| 52 | slot->abs[code - ABS_MT_FIRST] = value; |
| 53 | } |
| 54 | |
| 55 | static inline int input_mt_get_value(const struct input_mt_slot *slot, |
| 56 | unsigned code) |
| 57 | { |
| 58 | return slot->abs[code - ABS_MT_FIRST]; |
| 59 | } |
| 60 | |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 61 | int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, |
| 62 | unsigned int flags); |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 63 | void input_mt_destroy_slots(struct input_dev *dev); |
| 64 | |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 65 | static inline int input_mt_new_trkid(struct input_mt *mt) |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 66 | { |
Henrik Rydberg | 8d18fba | 2012-09-15 15:15:58 +0200 | [diff] [blame] | 67 | return mt->trkid++ & TRKID_MAX; |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 70 | static inline void input_mt_slot(struct input_dev *dev, int slot) |
| 71 | { |
| 72 | input_event(dev, EV_ABS, ABS_MT_SLOT, slot); |
| 73 | } |
| 74 | |
Henrik Rydberg | b89529a | 2012-01-12 19:40:34 +0100 | [diff] [blame] | 75 | static inline bool input_is_mt_value(int axis) |
| 76 | { |
| 77 | return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST; |
| 78 | } |
| 79 | |
Jeff Brown | 80b4895 | 2011-04-18 10:08:02 -0700 | [diff] [blame] | 80 | static inline bool input_is_mt_axis(int axis) |
| 81 | { |
Henrik Rydberg | b89529a | 2012-01-12 19:40:34 +0100 | [diff] [blame] | 82 | return axis == ABS_MT_SLOT || input_is_mt_value(axis); |
Jeff Brown | 80b4895 | 2011-04-18 10:08:02 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Henrik Rydberg | c5f4dec | 2010-12-15 13:50:34 +0100 | [diff] [blame] | 85 | void input_mt_report_slot_state(struct input_dev *dev, |
| 86 | unsigned int tool_type, bool active); |
| 87 | |
| 88 | void input_mt_report_finger_count(struct input_dev *dev, int count); |
| 89 | void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count); |
| 90 | |
Henrik Rydberg | 55e4908 | 2012-08-22 20:43:22 +0200 | [diff] [blame^] | 91 | void input_mt_sync_frame(struct input_dev *dev); |
| 92 | |
Henrik Rydberg | 47c78e8 | 2010-11-27 09:16:48 +0100 | [diff] [blame] | 93 | #endif |