1d61a52a7SMarcus Overhagen /* 2*819b4547SJohn Scipione * Copyright 2005-2014 Haiku, Inc. All rights reserved. 3d61a52a7SMarcus Overhagen * Distributed under the terms of the MIT License. 4d61a52a7SMarcus Overhagen * 5d61a52a7SMarcus Overhagen * Authors (in chronological order): 6d61a52a7SMarcus Overhagen * Marcus Overhagen (marcus@overhagen.de) 7*819b4547SJohn Scipione * Clemens Zeidler (haiku@clemens-zeidler.de) 8d61a52a7SMarcus Overhagen */ 9d61a52a7SMarcus Overhagen #ifndef __PS2_DEV_H 10d61a52a7SMarcus Overhagen #define __PS2_DEV_H 11d61a52a7SMarcus Overhagen 123856867bSAxel Dörfler 13dfd5628dSMarcus Overhagen struct ps2_dev; 14dfd5628dSMarcus Overhagen typedef struct ps2_dev ps2_dev; 15dfd5628dSMarcus Overhagen 16487f6591SMarcus Overhagen #include "ps2_common.h" 17d61a52a7SMarcus Overhagen 186849a228SStephan Aßmus 19802b6330SStephan Aßmus typedef struct { 20f9ff1193SMarcus Overhagen bigtime_t time; 21f9ff1193SMarcus Overhagen uint8 data; 2245d3c4ecSMarcus Overhagen bool error; 23f9ff1193SMarcus Overhagen } data_history; 24dfd5628dSMarcus Overhagen 25802b6330SStephan Aßmus struct ps2_dev { 26d61a52a7SMarcus Overhagen const char* name; 27d61a52a7SMarcus Overhagen bool active; 2803d0d41aSMarcus Overhagen uint8 idx; 29d61a52a7SMarcus Overhagen sem_id result_sem; 30077c84ebSPawel Dziepak int32 flags; 31d61a52a7SMarcus Overhagen uint8* result_buf; 32d61a52a7SMarcus Overhagen int result_buf_idx; 33d61a52a7SMarcus Overhagen int result_buf_cnt; 34dfd5628dSMarcus Overhagen void* cookie; 3545d3c4ecSMarcus Overhagen data_history history[2]; 366849a228SStephan Aßmus ps2_dev* parent_dev; 376849a228SStephan Aßmus size_t packet_size; 38130a1761SMarcus Overhagen 39130a1761SMarcus Overhagen // functions 40130a1761SMarcus Overhagen void (*disconnect)(ps2_dev *); 41f9ff1193SMarcus Overhagen int32 (*handle_int)(ps2_dev *); 425bb8f085SStephan Aßmus status_t (*command)(ps2_dev *dev, uint8 cmd, const uint8 *out, 435bb8f085SStephan Aßmus int out_count, uint8 *in, int in_count, bigtime_t timeout); 44dfd5628dSMarcus Overhagen }; 45d61a52a7SMarcus Overhagen 466849a228SStephan Aßmus #define PS2_DEVICE_COUNT 6 47395817e3SMarcus Overhagen 48395817e3SMarcus Overhagen extern ps2_dev ps2_device[PS2_DEVICE_COUNT]; 49d61a52a7SMarcus Overhagen 50d61a52a7SMarcus Overhagen #define PS2_DEVICE_MOUSE 0 516849a228SStephan Aßmus #define PS2_DEVICE_SYN_PASSTHROUGH 4 526849a228SStephan Aßmus #define PS2_DEVICE_KEYB 5 53d61a52a7SMarcus Overhagen 54dfd5628dSMarcus Overhagen #define PS2_FLAG_KEYB (1 << 0) 55dfd5628dSMarcus Overhagen #define PS2_FLAG_OPEN (1 << 1) 56dfd5628dSMarcus Overhagen #define PS2_FLAG_ENABLED (1 << 2) 57dfd5628dSMarcus Overhagen #define PS2_FLAG_CMD (1 << 3) 58dfd5628dSMarcus Overhagen #define PS2_FLAG_ACK (1 << 4) 59dfd5628dSMarcus Overhagen #define PS2_FLAG_NACK (1 << 5) 60a9e8a72aSMarcus Overhagen #define PS2_FLAG_GETID (1 << 6) 617f4deb44SSiarzhuk Zharski #define PS2_FLAG_RESEND (1 << 7) 62d61a52a7SMarcus Overhagen 633856867bSAxel Dörfler 643856867bSAxel Dörfler #ifdef __cplusplus 653856867bSAxel Dörfler extern "C" { 663856867bSAxel Dörfler #endif 673856867bSAxel Dörfler 686849a228SStephan Aßmus void ps2_dev_send(ps2_dev *dev, uint8 data); 696849a228SStephan Aßmus 706849a228SStephan Aßmus status_t ps2_dev_detect_pointing(ps2_dev *dev, device_hooks **hooks); 716849a228SStephan Aßmus 72d61a52a7SMarcus Overhagen status_t ps2_dev_init(void); 73d61a52a7SMarcus Overhagen void ps2_dev_exit(void); 74d61a52a7SMarcus Overhagen 755bb8f085SStephan Aßmus status_t standard_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out, 765bb8f085SStephan Aßmus int out_count, uint8 *in, int in_count, bigtime_t timeout); 776849a228SStephan Aßmus 784c78b73bSJérôme Duval status_t ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out = NULL, 794c78b73bSJérôme Duval int out_count = 0, uint8 *in = NULL, int in_count = 0); 805bb8f085SStephan Aßmus status_t ps2_dev_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out, 815bb8f085SStephan Aßmus int out_count, uint8 *in, int in_count, bigtime_t timeout); 824c78b73bSJérôme Duval status_t ps2_dev_sliced_command(ps2_dev *dev, uint8 cmd); 834c78b73bSJérôme Duval 84ab89b2f0SStephan Aßmus status_t ps2_reset_mouse(ps2_dev *dev); 85ab89b2f0SStephan Aßmus 86d61a52a7SMarcus Overhagen void ps2_dev_publish(ps2_dev *dev); 87d61a52a7SMarcus Overhagen void ps2_dev_unpublish(ps2_dev *dev); 88d61a52a7SMarcus Overhagen 8945d3c4ecSMarcus Overhagen int32 ps2_dev_handle_int(ps2_dev *dev); 90d61a52a7SMarcus Overhagen 913856867bSAxel Dörfler #ifdef __cplusplus 923856867bSAxel Dörfler } 93d61a52a7SMarcus Overhagen #endif 943856867bSAxel Dörfler 953856867bSAxel Dörfler 963856867bSAxel Dörfler #endif /* __PS2_DEV_H */ 97