xref: /haiku/src/add-ons/kernel/bus_managers/ps2/ps2_dev.h (revision 819b454750bfac97f44c156e7e0fdb9683406ab8)
1 /*
2  * Copyright 2005-2014 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors (in chronological order):
6  *		Marcus Overhagen (marcus@overhagen.de)
7  *		Clemens Zeidler (haiku@clemens-zeidler.de)
8  */
9 #ifndef __PS2_DEV_H
10 #define __PS2_DEV_H
11 
12 
13 struct ps2_dev;
14 typedef struct ps2_dev ps2_dev;
15 
16 #include "ps2_common.h"
17 
18 
19 typedef struct {
20 	bigtime_t		time;
21 	uint8			data;
22 	bool			error;
23 } data_history;
24 
25 struct ps2_dev {
26 	const char*		name;
27 	bool			active;
28 	uint8           idx;
29 	sem_id			result_sem;
30 	int32			flags;
31 	uint8*			result_buf;
32 	int				result_buf_idx;
33 	int				result_buf_cnt;
34 	void*			cookie;
35 	data_history	history[2];
36 	ps2_dev*		parent_dev;
37 	size_t			packet_size;
38 
39 // functions
40 	void			(*disconnect)(ps2_dev *);
41 	int32			(*handle_int)(ps2_dev *);
42 	status_t		(*command)(ps2_dev *dev, uint8 cmd, const uint8 *out,
43 						int out_count, uint8 *in, int in_count, bigtime_t timeout);
44 };
45 
46 #define PS2_DEVICE_COUNT 6
47 
48 extern ps2_dev ps2_device[PS2_DEVICE_COUNT];
49 
50 #define PS2_DEVICE_MOUSE 0
51 #define PS2_DEVICE_SYN_PASSTHROUGH 4
52 #define PS2_DEVICE_KEYB  5
53 
54 #define PS2_FLAG_KEYB		(1 << 0)
55 #define PS2_FLAG_OPEN		(1 << 1)
56 #define PS2_FLAG_ENABLED	(1 << 2)
57 #define PS2_FLAG_CMD		(1 << 3)
58 #define PS2_FLAG_ACK		(1 << 4)
59 #define PS2_FLAG_NACK		(1 << 5)
60 #define PS2_FLAG_GETID		(1 << 6)
61 #define PS2_FLAG_RESEND		(1 << 7)
62 
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 void 		ps2_dev_send(ps2_dev *dev, uint8 data);
69 
70 status_t	ps2_dev_detect_pointing(ps2_dev *dev, device_hooks **hooks);
71 
72 status_t	ps2_dev_init(void);
73 void		ps2_dev_exit(void);
74 
75 status_t	standard_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out,
76 				int out_count, uint8 *in, int in_count, bigtime_t timeout);
77 
78 status_t	ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out = NULL,
79 				int out_count = 0, uint8 *in = NULL, int in_count = 0);
80 status_t	ps2_dev_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out,
81 				int out_count, uint8 *in, int in_count, bigtime_t timeout);
82 status_t	ps2_dev_sliced_command(ps2_dev *dev, uint8 cmd);
83 
84 status_t	ps2_reset_mouse(ps2_dev *dev);
85 
86 void		ps2_dev_publish(ps2_dev *dev);
87 void		ps2_dev_unpublish(ps2_dev *dev);
88 
89 int32		ps2_dev_handle_int(ps2_dev *dev);
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 
96 #endif	/* __PS2_DEV_H */
97