xref: /haiku/src/add-ons/kernel/bus_managers/ps2/ps2_synaptics.h (revision b289aaf66bbf6e173aa90fa194fc256965f1b34d)
1 /*
2  * Copyright 2008-2009, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors (in chronological order):
6  *		Clemens Zeidler (haiku@Clemens-Zeidler.de)
7  */
8 #ifndef PS2_SYNAPTICS_H
9 #define PS2_SYNAPTICS_H
10 
11 
12 #include <KernelExport.h>
13 
14 #include "kb_mouse_driver.h"
15 #include "movement_maker.h"
16 #include "packet_buffer.h"
17 #include "ps2_service.h"
18 #include "touchpad_settings.h"
19 
20 
21 #define SYN_TOUCHPAD			0x47
22 // Synaptics modes
23 #define SYN_ABSOLUTE_MODE		0x80
24 // Absolute plus w mode
25 #define SYN_ABSOLUTE_W_MODE		0x81
26 #define SYN_FOUR_BYTE_CHILD		(1 << 1)
27 // Low power sleep mode
28 #define SYN_SLEEP_MODE			0x0C
29 // Synaptics Passthrough port
30 #define SYN_CHANGE_MODE			0x14
31 #define SYN_PASSTHROUGH_CMD		0x28
32 
33 
34 // synaptics touchpad proportions
35 #define SYN_EDGE_MOTION_WIDTH	50
36 #define SYN_EDGE_MOTION_SPEED	5
37 #define SYN_AREA_OFFSET			40
38 // increase the touchpad size a little bit
39 #define SYN_AREA_TOP_LEFT_OFFSET	40
40 #define SYN_AREA_BOTTOM_RIGHT_OFFSET	60
41 #define SYN_AREA_START_X		(1472 - SYN_AREA_TOP_LEFT_OFFSET)
42 #define SYN_AREA_END_X			(5472 + SYN_AREA_BOTTOM_RIGHT_OFFSET)
43 #define SYN_AREA_WIDTH_X		(SYN_AREA_END_X - SYN_AREA_START_X)
44 #define SYN_AREA_START_Y		(1408 - SYN_AREA_TOP_LEFT_OFFSET)
45 #define SYN_AREA_END_Y			(4448 + SYN_AREA_BOTTOM_RIGHT_OFFSET)
46 #define SYN_AREA_WIDTH_Y		(SYN_AREA_END_Y - SYN_AREA_START_Y)
47 
48 #define SYN_TAP_TIMEOUT			200000
49 
50 #define MIN_PRESSURE			30
51 #define MAX_PRESSURE			200
52 
53 #define SYNAPTICS_HISTORY_SIZE	256
54 
55 // no touchpad / left / right button pressed
56 #define IS_SYN_PT_PACKAGE(val) ((val[0] & 0xFC) == 0x84 \
57 	&& (val[3] & 0xCC) == 0xc4)
58 
59 
60 typedef struct {
61 	uint8 majorVersion;
62 	uint8 minorVersion;
63 
64 	bool capExtended;
65 	bool capSleep;
66 	bool capFourButtons;
67 	bool capMultiFinger;
68 	bool capPalmDetection;
69 	bool capPassThrough;
70 } touchpad_info;
71 
72 
73 enum button_ids
74 {
75 	kLeftButton = 0x01,
76 	kRightButton = 0x02
77 };
78 
79 
80 typedef struct {
81 	uint8		buttons;
82 	uint32		xPosition;
83 	uint32		yPosition;
84 	uint8		zPressure;
85 	// absolut mode
86 	bool		finger;
87 	bool		gesture;
88 	// absolut w mode
89 	uint8		wValue;
90 } touch_event;
91 
92 
93 typedef struct {
94 	ps2_dev*			dev;
95 
96 	sem_id				synaptics_sem;
97 	packet_buffer*		synaptics_ring_buffer;
98 	size_t				packet_index;
99 	uint8				packet_buffer[PS2_PACKET_SYNAPTICS];
100 	uint8				mode;
101 
102 	movement_maker		movement_maker;
103 	bool				movement_started;
104 	bool				scrolling_started;
105 	bool				tap_started;
106 	bigtime_t			tap_time;
107 	int32				tap_delta_x;
108 	int32				tap_delta_y;
109 	int32				tap_clicks;
110 	bool				tapdrag_started;
111 	bool				valid_edge_motion;
112 	bool				double_click;
113 
114 	bigtime_t			click_last_time;
115 	bigtime_t			click_speed;
116 	int32				click_count;
117 	uint32				buttons_state;
118 
119 	touchpad_settings	settings;
120 } synaptics_cookie;
121 
122 
123 
124 status_t synaptics_pass_through_set_packet_size(ps2_dev *dev, uint8 size);
125 status_t passthrough_command(ps2_dev *dev, uint8 cmd, const uint8 *out,
126 	int out_count, uint8 *in, int in_count, bigtime_t timeout);
127 status_t probe_synaptics(ps2_dev *dev);
128 
129 status_t synaptics_open(const char *name, uint32 flags, void **_cookie);
130 status_t synaptics_close(void *_cookie);
131 status_t synaptics_freecookie(void *_cookie);
132 status_t synaptics_ioctl(void *_cookie, uint32 op, void *buffer, size_t length);
133 
134 int32 synaptics_handle_int(ps2_dev *dev);
135 void synaptics_disconnect(ps2_dev *dev);
136 
137 device_hooks gSynapticsDeviceHooks;
138 
139 #endif	// PS2_SYNAPTICS_H
140