blob: cc5cca774bab14590e544f682c96a4ab72cd89c4 [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 Rydberg7c1a8782012-08-12 20:47:05 +020021#define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */
22
Henrik Rydberg47c78e82010-11-27 09:16:48 +010023/**
24 * struct input_mt_slot - represents the state of an input MT slot
25 * @abs: holds current values of ABS_MT axes for this slot
Henrik Rydberg55e49082012-08-22 20:43:22 +020026 * @frame: last frame at which input_mt_report_slot_state() was called
Henrik Rydberg17a465a2012-09-01 09:27:20 +020027 * @key: optional driver designation of this slot
Henrik Rydberg47c78e82010-11-27 09:16:48 +010028 */
29struct input_mt_slot {
30 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
Henrik Rydberg55e49082012-08-22 20:43:22 +020031 unsigned int frame;
Henrik Rydberg17a465a2012-09-01 09:27:20 +020032 unsigned int key;
Henrik Rydberg47c78e82010-11-27 09:16:48 +010033};
34
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020035/**
36 * struct input_mt - state of tracked contacts
37 * @trkid: stores MT tracking ID for the next contact
38 * @num_slots: number of MT slots the device uses
39 * @slot: MT slot currently being transmitted
Henrik Rydbergb4adbbe2012-08-11 22:07:55 +020040 * @flags: input_mt operation flags
Henrik Rydberg55e49082012-08-22 20:43:22 +020041 * @frame: increases every time input_mt_sync_frame() is called
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020042 * @red: reduced cost matrix for in-kernel tracking
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020043 * @slots: array of slots holding current values of tracked contacts
44 */
45struct input_mt {
46 int trkid;
47 int num_slots;
48 int slot;
Henrik Rydbergb4adbbe2012-08-11 22:07:55 +020049 unsigned int flags;
Henrik Rydberg55e49082012-08-22 20:43:22 +020050 unsigned int frame;
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020051 int *red;
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020052 struct input_mt_slot slots[];
53};
54
Henrik Rydberg47c78e82010-11-27 09:16:48 +010055static inline void input_mt_set_value(struct input_mt_slot *slot,
56 unsigned code, int value)
57{
58 slot->abs[code - ABS_MT_FIRST] = value;
59}
60
61static inline int input_mt_get_value(const struct input_mt_slot *slot,
62 unsigned code)
63{
64 return slot->abs[code - ABS_MT_FIRST];
65}
66
Henrik Rydberg7c1a8782012-08-12 20:47:05 +020067static inline bool input_mt_is_active(const struct input_mt_slot *slot)
68{
69 return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0;
70}
71
Henrik Rydbergb4adbbe2012-08-11 22:07:55 +020072int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
73 unsigned int flags);
Henrik Rydberg47c78e82010-11-27 09:16:48 +010074void input_mt_destroy_slots(struct input_dev *dev);
75
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020076static inline int input_mt_new_trkid(struct input_mt *mt)
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010077{
Henrik Rydberg8d18fba2012-09-15 15:15:58 +020078 return mt->trkid++ & TRKID_MAX;
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010079}
80
Henrik Rydberg47c78e82010-11-27 09:16:48 +010081static inline void input_mt_slot(struct input_dev *dev, int slot)
82{
83 input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
84}
85
Henrik Rydbergb89529a2012-01-12 19:40:34 +010086static inline bool input_is_mt_value(int axis)
87{
88 return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
89}
90
Jeff Brown80b48952011-04-18 10:08:02 -070091static inline bool input_is_mt_axis(int axis)
92{
Henrik Rydbergb89529a2012-01-12 19:40:34 +010093 return axis == ABS_MT_SLOT || input_is_mt_value(axis);
Jeff Brown80b48952011-04-18 10:08:02 -070094}
95
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +010096void input_mt_report_slot_state(struct input_dev *dev,
97 unsigned int tool_type, bool active);
98
99void input_mt_report_finger_count(struct input_dev *dev, int count);
100void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
101
Henrik Rydberg55e49082012-08-22 20:43:22 +0200102void input_mt_sync_frame(struct input_dev *dev);
103
Henrik Rydberg7c1a8782012-08-12 20:47:05 +0200104/**
105 * struct input_mt_pos - contact position
106 * @x: horizontal coordinate
107 * @y: vertical coordinate
108 */
109struct input_mt_pos {
110 s16 x, y;
111};
112
113int input_mt_assign_slots(struct input_dev *dev, int *slots,
114 const struct input_mt_pos *pos, int num_pos);
115
Henrik Rydberg17a465a2012-09-01 09:27:20 +0200116int input_mt_get_slot_by_key(struct input_dev *dev, int key);
117
Henrik Rydberg47c78e82010-11-27 09:16:48 +0100118#endif