2 * Copyright © 2013 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 #include "litest-int.h"
29 #include "libinput-util.h"
31 static void litest_bcm5974_setup(void)
33 struct litest_device *d = litest_create_device(LITEST_BCM5974);
34 litest_set_current_device(d);
38 litest_bcm5974_touch_down(struct litest_device *d,
42 static int tracking_id;
43 struct input_event *ev;
44 struct input_event down[] = {
45 { .type = EV_ABS, .code = ABS_X, .value = x },
46 { .type = EV_ABS, .code = ABS_Y, .value = y },
47 { .type = EV_ABS, .code = ABS_PRESSURE, .value = 30 },
48 { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot },
49 { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = ++tracking_id },
50 { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = x },
51 { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = y },
52 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
55 down[0].value = litest_scale(d, ABS_X, x);
56 down[1].value = litest_scale(d, ABS_Y, y);
57 down[5].value = litest_scale(d, ABS_X, x);
58 down[6].value = litest_scale(d, ABS_Y, y);
60 ARRAY_FOR_EACH(down, ev)
61 litest_event(d, ev->type, ev->code, ev->value);
65 litest_bcm5974_move(struct litest_device *d, unsigned int slot, int x, int y)
67 struct input_event *ev;
68 struct input_event move[] = {
69 { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot },
70 { .type = EV_ABS, .code = ABS_X, .value = x },
71 { .type = EV_ABS, .code = ABS_Y, .value = y },
72 { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = x },
73 { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = y },
74 { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = 1 },
75 { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
76 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
79 move[1].value = litest_scale(d, ABS_X, x);
80 move[2].value = litest_scale(d, ABS_Y, y);
81 move[3].value = litest_scale(d, ABS_X, x);
82 move[4].value = litest_scale(d, ABS_Y, y);
84 ARRAY_FOR_EACH(move, ev)
85 litest_event(d, ev->type, ev->code, ev->value);
88 static struct litest_device_interface interface = {
89 .touch_down = litest_bcm5974_touch_down,
90 .touch_move = litest_bcm5974_move,
94 litest_create_bcm5974(struct litest_device *d)
97 struct input_absinfo abs[] = {
98 { ABS_X, 1472, 5472, 75 },
99 { ABS_Y, 1408, 4448, 129 },
100 { ABS_PRESSURE, 0, 255, 0 },
101 { ABS_TOOL_WIDTH, 0, 15, 0 },
102 { ABS_MT_SLOT, 0, 1, 0 },
103 { ABS_MT_POSITION_X, 1472, 5472, 75 },
104 { ABS_MT_POSITION_Y, 1408, 4448, 129 },
105 { ABS_MT_TRACKING_ID, 0, 65535, 0 },
106 { ABS_MT_PRESSURE, 0, 255, 0 }
108 struct input_absinfo *a;
111 d->interface = &interface;
113 dev = libevdev_new();
114 ck_assert(dev != NULL);
116 libevdev_set_name(dev, "bcm5974");
117 libevdev_set_id_bustype(dev, 0x3);
118 libevdev_set_id_vendor(dev, 0x5ac);
119 libevdev_set_id_product(dev, 0x249);
120 libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
121 libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_FINGER, NULL);
122 libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_QUINTTAP, NULL);
123 libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
124 libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_DOUBLETAP, NULL);
125 libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_TRIPLETAP, NULL);
126 libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_QUADTAP, NULL);
128 ARRAY_FOR_EACH(abs, a)
129 libevdev_enable_event_code(dev, EV_ABS, a->value, a);
131 rc = libevdev_uinput_create_from_device(dev,
132 LIBEVDEV_UINPUT_OPEN_MANAGED,
134 ck_assert_int_eq(rc, 0);
138 struct litest_test_device litest_bcm5974_device = {
139 .type = LITEST_BCM5974,
140 .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON,
141 .shortname = "bcm5974",
142 .setup = litest_bcm5974_setup,
143 .teardown = litest_generic_device_teardown,
144 .create = litest_create_bcm5974,