at v6.18 3.6 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2#ifndef _INPUT_MT_H 3#define _INPUT_MT_H 4 5/* 6 * Input Multitouch Library 7 * 8 * Copyright (c) 2010 Henrik Rydberg 9 */ 10 11#include <linux/input.h> 12 13#define TRKID_MAX 0xffff 14 15#define INPUT_MT_POINTER 0x0001 /* pointer device, e.g. trackpad */ 16#define INPUT_MT_DIRECT 0x0002 /* direct device, e.g. touchscreen */ 17#define INPUT_MT_DROP_UNUSED 0x0004 /* drop contacts not seen in frame */ 18#define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */ 19#define INPUT_MT_SEMI_MT 0x0010 /* semi-mt device, finger count handled manually */ 20#define INPUT_MT_TOTAL_FORCE 0x0020 /* calculate total force from slots pressure */ 21 22/** 23 * struct input_mt_slot - represents the state of an input MT slot 24 * @abs: holds current values of ABS_MT axes for this slot 25 * @frame: last frame at which input_mt_report_slot_state() was called 26 * @key: optional driver designation of this slot 27 */ 28struct input_mt_slot { 29 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; 30 unsigned int frame; 31 unsigned int key; 32}; 33 34/** 35 * struct input_mt - state of tracked contacts 36 * @trkid: stores MT tracking ID for the next contact 37 * @num_slots: number of MT slots the device uses 38 * @slot: MT slot currently being transmitted 39 * @flags: input_mt operation flags 40 * @frame: increases every time input_mt_sync_frame() is called 41 * @red: reduced cost matrix for in-kernel tracking 42 * @slots: array of slots holding current values of tracked contacts 43 */ 44struct input_mt { 45 int trkid; 46 int num_slots; 47 int slot; 48 unsigned int flags; 49 unsigned int frame; 50 int *red; 51 struct input_mt_slot slots[] __counted_by(num_slots); 52}; 53 54static inline void input_mt_set_value(struct input_mt_slot *slot, 55 unsigned code, int value) 56{ 57 slot->abs[code - ABS_MT_FIRST] = value; 58} 59 60static inline int input_mt_get_value(const struct input_mt_slot *slot, 61 unsigned code) 62{ 63 return slot->abs[code - ABS_MT_FIRST]; 64} 65 66static inline bool input_mt_is_active(const struct input_mt_slot *slot) 67{ 68 return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0; 69} 70 71static inline bool input_mt_is_used(const struct input_mt *mt, 72 const struct input_mt_slot *slot) 73{ 74 return slot->frame == mt->frame; 75} 76 77int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, 78 unsigned int flags); 79void input_mt_destroy_slots(struct input_dev *dev); 80 81static inline int input_mt_new_trkid(struct input_mt *mt) 82{ 83 return mt->trkid++ & TRKID_MAX; 84} 85 86static inline void input_mt_slot(struct input_dev *dev, int slot) 87{ 88 input_event(dev, EV_ABS, ABS_MT_SLOT, slot); 89} 90 91static inline bool input_is_mt_value(int axis) 92{ 93 return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST; 94} 95 96static inline bool input_is_mt_axis(int axis) 97{ 98 return axis == ABS_MT_SLOT || input_is_mt_value(axis); 99} 100 101bool input_mt_report_slot_state(struct input_dev *dev, 102 unsigned int tool_type, bool active); 103 104static inline void input_mt_report_slot_inactive(struct input_dev *dev) 105{ 106 input_mt_report_slot_state(dev, 0, false); 107} 108 109void input_mt_report_finger_count(struct input_dev *dev, int count); 110void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count); 111void input_mt_drop_unused(struct input_dev *dev); 112 113void input_mt_sync_frame(struct input_dev *dev); 114 115/** 116 * struct input_mt_pos - contact position 117 * @x: horizontal coordinate 118 * @y: vertical coordinate 119 */ 120struct input_mt_pos { 121 s16 x, y; 122}; 123 124int input_mt_assign_slots(struct input_dev *dev, int *slots, 125 const struct input_mt_pos *pos, int num_pos, 126 int dmax); 127 128int input_mt_get_slot_by_key(struct input_dev *dev, int key); 129 130#endif