blob: 63458bced77d8338963af873978e0a3feae0988f [file] [log] [blame]
Henrik Rydberg47c78e82010-11-27 09:16:48 +01001#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 Rydbergc5f4dec2010-12-15 13:50:34 +010016#define TRKID_MAX 0xffff
17
Henrik Rydberg47c78e82010-11-27 09:16:48 +010018/**
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 */
22struct input_mt_slot {
23 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
24};
25
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020026/**
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
31 * @slots: array of slots holding current values of tracked contacts
32 */
33struct input_mt {
34 int trkid;
35 int num_slots;
36 int slot;
37 struct input_mt_slot slots[];
38};
39
Henrik Rydberg47c78e82010-11-27 09:16:48 +010040static inline void input_mt_set_value(struct input_mt_slot *slot,
41 unsigned code, int value)
42{
43 slot->abs[code - ABS_MT_FIRST] = value;
44}
45
46static inline int input_mt_get_value(const struct input_mt_slot *slot,
47 unsigned code)
48{
49 return slot->abs[code - ABS_MT_FIRST];
50}
51
Henrik Rydberg8cde8102010-11-27 10:50:54 +010052int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots);
Henrik Rydberg47c78e82010-11-27 09:16:48 +010053void input_mt_destroy_slots(struct input_dev *dev);
54
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020055static inline int input_mt_new_trkid(struct input_mt *mt)
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010056{
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020057 return mt->trkid++ & TRKID_MAX;
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010058}
59
Henrik Rydberg47c78e82010-11-27 09:16:48 +010060static inline void input_mt_slot(struct input_dev *dev, int slot)
61{
62 input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
63}
64
Henrik Rydbergb89529a2012-01-12 19:40:34 +010065static inline bool input_is_mt_value(int axis)
66{
67 return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
68}
69
Jeff Brown80b48952011-04-18 10:08:02 -070070static inline bool input_is_mt_axis(int axis)
71{
Henrik Rydbergb89529a2012-01-12 19:40:34 +010072 return axis == ABS_MT_SLOT || input_is_mt_value(axis);
Jeff Brown80b48952011-04-18 10:08:02 -070073}
74
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010075void input_mt_report_slot_state(struct input_dev *dev,
76 unsigned int tool_type, bool active);
77
78void input_mt_report_finger_count(struct input_dev *dev, int count);
79void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
80
Henrik Rydberg47c78e82010-11-27 09:16:48 +010081#endif