[61257f4] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Lubos Slovak
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup drvusbhid
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * USB HID keyboard device structure and API.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[ba358ed] | 36 | #ifndef USB_HID_KBDDEV_H_
|
---|
| 37 | #define USB_HID_KBDDEV_H_
|
---|
[61257f4] | 38 |
|
---|
| 39 | #include <stdint.h>
|
---|
[5da7199] | 40 | #include <async.h>
|
---|
[61257f4] | 41 | #include <fibril_synch.h>
|
---|
[faa44e58] | 42 | #include <usb/hid/hid.h>
|
---|
| 43 | #include <usb/hid/hidparser.h>
|
---|
[61257f4] | 44 | #include <ddf/driver.h>
|
---|
[7d521e24] | 45 | #include <usb/dev/pipes.h>
|
---|
| 46 | #include <usb/dev/driver.h>
|
---|
[378bf85] | 47 | #include "../usbhid.h"
|
---|
[61257f4] | 48 | #include "kbdrepeat.h"
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * USB/HID keyboard device type.
|
---|
| 52 | *
|
---|
| 53 | * Holds a reference to generic USB/HID device structure and keyboard-specific
|
---|
| 54 | * data, such as currently pressed keys, modifiers and lock keys.
|
---|
| 55 | *
|
---|
[5da7199] | 56 | * Also holds a IPC session to the console (since there is now no other way to
|
---|
[61257f4] | 57 | * communicate with it).
|
---|
| 58 | *
|
---|
| 59 | * @note Storing active lock keys in this structure results in their setting
|
---|
| 60 | * being device-specific.
|
---|
| 61 | */
|
---|
| 62 | typedef struct usb_kbd_t {
|
---|
[60e5a856] | 63 | /** Link to HID device structure */
|
---|
[378bf85] | 64 | usb_hid_dev_t *hid_dev;
|
---|
| 65 |
|
---|
[e60436b] | 66 | /** Previously pressed keys (not translated to key codes). */
|
---|
| 67 | int32_t *keys_old;
|
---|
[61257f4] | 68 | /** Currently pressed keys (not translated to key codes). */
|
---|
[e60436b] | 69 | int32_t *keys;
|
---|
[61257f4] | 70 | /** Count of stored keys (i.e. number of keys in the report). */
|
---|
| 71 | size_t key_count;
|
---|
| 72 | /** Currently pressed modifiers (bitmap). */
|
---|
| 73 | uint8_t modifiers;
|
---|
[378bf85] | 74 |
|
---|
[61257f4] | 75 | /** Currently active modifiers including locks. Sent to the console. */
|
---|
[378bf85] | 76 | unsigned int mods;
|
---|
| 77 |
|
---|
[61257f4] | 78 | /** Currently active lock keys. */
|
---|
[378bf85] | 79 | unsigned int lock_keys;
|
---|
| 80 |
|
---|
[2b621cb] | 81 | /** IPC session to client (for sending key events). */
|
---|
| 82 | async_sess_t *client_sess;
|
---|
[378bf85] | 83 |
|
---|
[61257f4] | 84 | /** Information for auto-repeat of keys. */
|
---|
| 85 | usb_kbd_repeat_t repeat;
|
---|
[378bf85] | 86 |
|
---|
[61257f4] | 87 | /** Mutex for accessing the information about auto-repeat. */
|
---|
[cddd151] | 88 | fibril_mutex_t repeat_mtx;
|
---|
[378bf85] | 89 |
|
---|
[61257f4] | 90 | uint8_t *output_buffer;
|
---|
[378bf85] | 91 |
|
---|
[61257f4] | 92 | size_t output_size;
|
---|
[378bf85] | 93 |
|
---|
[61257f4] | 94 | size_t led_output_size;
|
---|
[378bf85] | 95 |
|
---|
[61257f4] | 96 | usb_hid_report_path_t *led_path;
|
---|
[378bf85] | 97 |
|
---|
[61257f4] | 98 | int32_t *led_data;
|
---|
[378bf85] | 99 |
|
---|
[61257f4] | 100 | /** State of the structure (for checking before use).
|
---|
[378bf85] | 101 | *
|
---|
[61257f4] | 102 | * 0 - not initialized
|
---|
| 103 | * 1 - initialized
|
---|
| 104 | * -1 - ready for destroying
|
---|
| 105 | */
|
---|
| 106 | int initialized;
|
---|
[378bf85] | 107 |
|
---|
[cddd151] | 108 | /** DDF function */
|
---|
| 109 | ddf_fun_t *fun;
|
---|
[61257f4] | 110 | } usb_kbd_t;
|
---|
| 111 |
|
---|
[b803845] | 112 | extern const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description;
|
---|
[61257f4] | 113 |
|
---|
[378bf85] | 114 | extern const char *HID_KBD_FUN_NAME;
|
---|
| 115 | extern const char *HID_KBD_CATEGORY;
|
---|
| 116 |
|
---|
| 117 | extern int usb_kbd_init(usb_hid_dev_t *, void **);
|
---|
| 118 | extern bool usb_kbd_polling_callback(usb_hid_dev_t *, void *);
|
---|
| 119 | extern int usb_kbd_is_initialized(const usb_kbd_t *);
|
---|
| 120 | extern int usb_kbd_is_ready_to_destroy(const usb_kbd_t *);
|
---|
| 121 | extern void usb_kbd_destroy(usb_kbd_t *);
|
---|
| 122 | extern void usb_kbd_push_ev(usb_kbd_t *, int, unsigned int);
|
---|
| 123 | extern void usb_kbd_deinit(usb_hid_dev_t *, void *);
|
---|
| 124 | extern int usb_kbd_set_boot_protocol(usb_hid_dev_t *);
|
---|
[61257f4] | 125 |
|
---|
[ba358ed] | 126 | #endif /* USB_HID_KBDDEV_H_ */
|
---|
[61257f4] | 127 |
|
---|
| 128 | /**
|
---|
| 129 | * @}
|
---|
| 130 | */
|
---|