blob: 94989189878d64a06a440d4a5f5b7f5cd0b6dd47 [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 Rydberg55e49082012-08-22 20:43:22 +020018#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 Rydberg47c78e82010-11-27 09:16:48 +010021/**
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 Rydberg55e49082012-08-22 20:43:22 +020024 * @frame: last frame at which input_mt_report_slot_state() was called
Henrik Rydberg47c78e82010-11-27 09:16:48 +010025 */
26struct input_mt_slot {
27 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
Henrik Rydberg55e49082012-08-22 20:43:22 +020028 unsigned int frame;
Henrik Rydberg47c78e82010-11-27 09:16:48 +010029};
30
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020031/**
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 Rydbergb4adbbe2012-08-11 22:07:55 +020036 * @flags: input_mt operation flags
Henrik Rydberg55e49082012-08-22 20:43:22 +020037 * @frame: increases every time input_mt_sync_frame() is called
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020038 * @slots: array of slots holding current values of tracked contacts
39 */
40struct input_mt {
41 int trkid;
42 int num_slots;
43 int slot;
Henrik Rydbergb4adbbe2012-08-11 22:07:55 +020044 unsigned int flags;
Henrik Rydberg55e49082012-08-22 20:43:22 +020045 unsigned int frame;
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020046 struct input_mt_slot slots[];
47};
48
Henrik Rydberg47c78e82010-11-27 09:16:48 +010049static 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
55static 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 Rydbergb4adbbe2012-08-11 22:07:55 +020061int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
62 unsigned int flags);
Henrik Rydberg47c78e82010-11-27 09:16:48 +010063void input_mt_destroy_slots(struct input_dev *dev);
64
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020065static inline int input_mt_new_trkid(struct input_mt *mt)
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010066{
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020067 return mt->trkid++ & TRKID_MAX;
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010068}
69
Henrik Rydberg47c78e82010-11-27 09:16:48 +010070static 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 Rydbergb89529a2012-01-12 19:40:34 +010075static inline bool input_is_mt_value(int axis)
76{
77 return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
78}
79
Jeff Brown80b48952011-04-18 10:08:02 -070080static inline bool input_is_mt_axis(int axis)
81{
Henrik Rydbergb89529a2012-01-12 19:40:34 +010082 return axis == ABS_MT_SLOT || input_is_mt_value(axis);
Jeff Brown80b48952011-04-18 10:08:02 -070083}
84
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010085void input_mt_report_slot_state(struct input_dev *dev,
86 unsigned int tool_type, bool active);
87
88void input_mt_report_finger_count(struct input_dev *dev, int count);
89void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
90
Henrik Rydberg55e49082012-08-22 20:43:22 +020091void input_mt_sync_frame(struct input_dev *dev);
92
Henrik Rydberg47c78e82010-11-27 09:16:48 +010093#endif