1 /////////////////////////////////////////////////////////////////////////
2 // $Id: usb_hid.h 14150 2021-02-17 16:22:55Z vruppert $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // USB HID emulation support (mouse and tablet) ported from QEMU
6 // USB keypad emulation based on code by Benjamin D Lunt (fys [at] fysnet [dot] net)
7 // USB keyboard emulation is an extension to the keypad based on the specs
8 //
9 // Copyright (c) 2005       Fabrice Bellard
10 // Copyright (c) 2007       OpenMoko, Inc.  (andrew@openedhand.com)
11 // Copyright (C) 2009-2021  The Bochs Project
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a copy
14 // of this software and associated documentation files (the "Software"), to deal
15 // in the Software without restriction, including without limitation the rights
16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 // copies of the Software, and to permit persons to whom the Software is
18 // furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included in
21 // all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 // THE SOFTWARE.
30 /////////////////////////////////////////////////////////////////////////
31 
32 #ifndef BX_IODEV_USB_HID_H
33 #define BX_IODEV_USB_HID_H
34 
35 
36 class usb_hid_device_c : public usb_device_c {
37 public:
38   usb_hid_device_c(const char *devname);
39   virtual ~usb_hid_device_c(void);
40 
41   virtual bool init();
42   virtual const char* get_info();
43   virtual void handle_reset();
44   virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
45   virtual int handle_data(USBPacket *p);
46   virtual void register_state_specific(bx_list_c *parent);
47 
48 private:
49   struct {
50     bool has_events;
51     Bit8u idle;
52     int mouse_delayed_dx;
53     int mouse_delayed_dy;
54     Bit16s mouse_x;
55     Bit16s mouse_y;
56     Bit8s mouse_z;
57     Bit8u b_state;
58     Bit8u mouse_event_count;
59     Bit8u mouse_event_buf[BX_KBD_ELEMENTS][6];
60     Bit8u kbd_packet[8];
61     Bit8u indicators;
62     Bit8u kbd_event_count;
63     Bit32u kbd_event_buf[BX_KBD_ELEMENTS];
64   } s;
65 
66   int timer_index;
67 
68   static bool gen_scancode_static(void *dev, Bit32u key);
69   bool gen_scancode(Bit32u key);
70   static Bit8u kbd_get_elements_static(void *dev);
71   Bit8u kbd_get_elements(void);
72   static void mouse_enabled_changed(void *dev, bool enabled);
73   static void mouse_enq_static(void *dev, int delta_x, int delta_y, int delta_z, unsigned button_state, bool absxy);
74   void mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state, bool absxy);
75   int mouse_poll(Bit8u *buf, int len, bool force);
76   int create_mouse_packet(Bit8u *buf, int len);
77   int get_mouse_packet(Bit8u *buf, int len);
78   int keyboard_poll(Bit8u *buf, int len, bool force);
79 
80   static void hid_timer_handler(void *);
81   void start_idle_timer(void);
82   void hid_idle_timer(void);
83 };
84 
85 #endif
86