Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 #ifndef _INPUT_MT_H
0003 #define _INPUT_MT_H
0004 
0005 /*
0006  * Input Multitouch Library
0007  *
0008  * Copyright (c) 2010 Henrik Rydberg
0009  */
0010 
0011 #include <linux/input.h>
0012 
0013 #define TRKID_MAX   0xffff
0014 
0015 #define INPUT_MT_POINTER    0x0001  /* pointer device, e.g. trackpad */
0016 #define INPUT_MT_DIRECT     0x0002  /* direct device, e.g. touchscreen */
0017 #define INPUT_MT_DROP_UNUSED    0x0004  /* drop contacts not seen in frame */
0018 #define INPUT_MT_TRACK      0x0008  /* use in-kernel tracking */
0019 #define INPUT_MT_SEMI_MT    0x0010  /* semi-mt device, finger count handled manually */
0020 
0021 /**
0022  * struct input_mt_slot - represents the state of an input MT slot
0023  * @abs: holds current values of ABS_MT axes for this slot
0024  * @frame: last frame at which input_mt_report_slot_state() was called
0025  * @key: optional driver designation of this slot
0026  */
0027 struct input_mt_slot {
0028     int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
0029     unsigned int frame;
0030     unsigned int key;
0031 };
0032 
0033 /**
0034  * struct input_mt - state of tracked contacts
0035  * @trkid: stores MT tracking ID for the next contact
0036  * @num_slots: number of MT slots the device uses
0037  * @slot: MT slot currently being transmitted
0038  * @flags: input_mt operation flags
0039  * @frame: increases every time input_mt_sync_frame() is called
0040  * @red: reduced cost matrix for in-kernel tracking
0041  * @slots: array of slots holding current values of tracked contacts
0042  */
0043 struct input_mt {
0044     int trkid;
0045     int num_slots;
0046     int slot;
0047     unsigned int flags;
0048     unsigned int frame;
0049     int *red;
0050     struct input_mt_slot slots[];
0051 };
0052 
0053 static inline void input_mt_set_value(struct input_mt_slot *slot,
0054                       unsigned code, int value)
0055 {
0056     slot->abs[code - ABS_MT_FIRST] = value;
0057 }
0058 
0059 static inline int input_mt_get_value(const struct input_mt_slot *slot,
0060                      unsigned code)
0061 {
0062     return slot->abs[code - ABS_MT_FIRST];
0063 }
0064 
0065 static inline bool input_mt_is_active(const struct input_mt_slot *slot)
0066 {
0067     return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0;
0068 }
0069 
0070 static inline bool input_mt_is_used(const struct input_mt *mt,
0071                     const struct input_mt_slot *slot)
0072 {
0073     return slot->frame == mt->frame;
0074 }
0075 
0076 int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
0077             unsigned int flags);
0078 void input_mt_destroy_slots(struct input_dev *dev);
0079 
0080 static inline int input_mt_new_trkid(struct input_mt *mt)
0081 {
0082     return mt->trkid++ & TRKID_MAX;
0083 }
0084 
0085 static inline void input_mt_slot(struct input_dev *dev, int slot)
0086 {
0087     input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
0088 }
0089 
0090 static inline bool input_is_mt_value(int axis)
0091 {
0092     return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
0093 }
0094 
0095 static inline bool input_is_mt_axis(int axis)
0096 {
0097     return axis == ABS_MT_SLOT || input_is_mt_value(axis);
0098 }
0099 
0100 bool input_mt_report_slot_state(struct input_dev *dev,
0101                 unsigned int tool_type, bool active);
0102 
0103 static inline void input_mt_report_slot_inactive(struct input_dev *dev)
0104 {
0105     input_mt_report_slot_state(dev, 0, false);
0106 }
0107 
0108 void input_mt_report_finger_count(struct input_dev *dev, int count);
0109 void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
0110 void input_mt_drop_unused(struct input_dev *dev);
0111 
0112 void input_mt_sync_frame(struct input_dev *dev);
0113 
0114 /**
0115  * struct input_mt_pos - contact position
0116  * @x: horizontal coordinate
0117  * @y: vertical coordinate
0118  */
0119 struct input_mt_pos {
0120     s16 x, y;
0121 };
0122 
0123 int input_mt_assign_slots(struct input_dev *dev, int *slots,
0124               const struct input_mt_pos *pos, int num_pos,
0125               int dmax);
0126 
0127 int input_mt_get_slot_by_key(struct input_dev *dev, int key);
0128 
0129 #endif