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