usb: make usb_create_simple catch and pass up errors.
[qemu.git] / hw / hid.h
blob9ce03b118c9db127a8397fc728922f95f8c80b3f
1 #ifndef QEMU_HID_H
2 #define QEMU_HID_H
4 #define HID_MOUSE 1
5 #define HID_TABLET 2
6 #define HID_KEYBOARD 3
8 typedef struct HIDPointerEvent {
9 int32_t xdx, ydy; /* relative iff it's a mouse, otherwise absolute */
10 int32_t dz, buttons_state;
11 } HIDPointerEvent;
13 #define QUEUE_LENGTH 16 /* should be enough for a triple-click */
14 #define QUEUE_MASK (QUEUE_LENGTH-1u)
15 #define QUEUE_INCR(v) ((v)++, (v) &= QUEUE_MASK)
17 typedef struct HIDState HIDState;
18 typedef void (*HIDEventFunc)(HIDState *s);
20 typedef struct HIDMouseState {
21 HIDPointerEvent queue[QUEUE_LENGTH];
22 int mouse_grabbed;
23 QEMUPutMouseEntry *eh_entry;
24 } HIDMouseState;
26 typedef struct HIDKeyboardState {
27 uint32_t keycodes[QUEUE_LENGTH];
28 uint16_t modifiers;
29 uint8_t leds;
30 uint8_t key[16];
31 int32_t keys;
32 } HIDKeyboardState;
34 struct HIDState {
35 union {
36 HIDMouseState ptr;
37 HIDKeyboardState kbd;
39 uint32_t head; /* index into circular queue */
40 uint32_t n;
41 int kind;
42 int32_t protocol;
43 uint8_t idle;
44 int64_t next_idle_clock;
45 HIDEventFunc event;
48 void hid_init(HIDState *hs, int kind, HIDEventFunc event);
49 void hid_reset(HIDState *hs);
50 void hid_free(HIDState *hs);
52 bool hid_has_events(HIDState *hs);
53 void hid_set_next_idle(HIDState *hs, int64_t curtime);
54 void hid_pointer_activate(HIDState *hs);
55 int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len);
56 int hid_keyboard_poll(HIDState *hs, uint8_t *buf, int len);
57 int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len);
59 #endif /* QEMU_HID_H */