| 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 |
|
|---|
| 36 | #ifndef USB_KBDDEV_H_
|
|---|
| 37 | #define USB_KBDDEV_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <stdint.h>
|
|---|
| 40 |
|
|---|
| 41 | #include <fibril_synch.h>
|
|---|
| 42 |
|
|---|
| 43 | #include <usb/classes/hid.h>
|
|---|
| 44 | #include <usb/classes/hidparser.h>
|
|---|
| 45 | #include <ddf/driver.h>
|
|---|
| 46 | #include <usb/pipes.h>
|
|---|
| 47 | #include <usb/devdrv.h>
|
|---|
| 48 |
|
|---|
| 49 | #include "kbdrepeat.h"
|
|---|
| 50 |
|
|---|
| 51 | /*----------------------------------------------------------------------------*/
|
|---|
| 52 | /**
|
|---|
| 53 | * USB/HID keyboard device type.
|
|---|
| 54 | *
|
|---|
| 55 | * Holds a reference to generic USB/HID device structure and keyboard-specific
|
|---|
| 56 | * data, such as currently pressed keys, modifiers and lock keys.
|
|---|
| 57 | *
|
|---|
| 58 | * Also holds a IPC phone to the console (since there is now no other way to
|
|---|
| 59 | * communicate with it).
|
|---|
| 60 | *
|
|---|
| 61 | * @note Storing active lock keys in this structure results in their setting
|
|---|
| 62 | * being device-specific.
|
|---|
| 63 | */
|
|---|
| 64 | typedef struct usb_kbd_t {
|
|---|
| 65 | /** Structure holding generic USB device information. */
|
|---|
| 66 | //usbhid_dev_t *hid_dev;
|
|---|
| 67 | usb_device_t *usb_dev;
|
|---|
| 68 |
|
|---|
| 69 | /** Currently pressed keys (not translated to key codes). */
|
|---|
| 70 | uint8_t *keys;
|
|---|
| 71 | /** Count of stored keys (i.e. number of keys in the report). */
|
|---|
| 72 | size_t key_count;
|
|---|
| 73 | /** Currently pressed modifiers (bitmap). */
|
|---|
| 74 | uint8_t modifiers;
|
|---|
| 75 |
|
|---|
| 76 | /** Currently active modifiers including locks. Sent to the console. */
|
|---|
| 77 | unsigned mods;
|
|---|
| 78 |
|
|---|
| 79 | /** Currently active lock keys. */
|
|---|
| 80 | unsigned lock_keys;
|
|---|
| 81 |
|
|---|
| 82 | /** IPC phone to the console device (for sending key events). */
|
|---|
| 83 | int console_phone;
|
|---|
| 84 |
|
|---|
| 85 | /** Information for auto-repeat of keys. */
|
|---|
| 86 | usb_kbd_repeat_t repeat;
|
|---|
| 87 |
|
|---|
| 88 | /** Mutex for accessing the information about auto-repeat. */
|
|---|
| 89 | fibril_mutex_t *repeat_mtx;
|
|---|
| 90 |
|
|---|
| 91 | /** Report descriptor. */
|
|---|
| 92 | uint8_t *report_desc;
|
|---|
| 93 |
|
|---|
| 94 | /** Report descriptor size. */
|
|---|
| 95 | size_t report_desc_size;
|
|---|
| 96 |
|
|---|
| 97 | uint8_t *output_buffer;
|
|---|
| 98 |
|
|---|
| 99 | size_t output_size;
|
|---|
| 100 |
|
|---|
| 101 | size_t led_output_size;
|
|---|
| 102 |
|
|---|
| 103 | usb_hid_report_path_t *led_path;
|
|---|
| 104 |
|
|---|
| 105 | int32_t *led_data;
|
|---|
| 106 |
|
|---|
| 107 | /** HID Report parser. */
|
|---|
| 108 | usb_hid_report_parser_t *parser;
|
|---|
| 109 |
|
|---|
| 110 | /** State of the structure (for checking before use).
|
|---|
| 111 | *
|
|---|
| 112 | * 0 - not initialized
|
|---|
| 113 | * 1 - initialized
|
|---|
| 114 | * -1 - ready for destroying
|
|---|
| 115 | */
|
|---|
| 116 | int initialized;
|
|---|
| 117 | } usb_kbd_t;
|
|---|
| 118 |
|
|---|
| 119 | /*----------------------------------------------------------------------------*/
|
|---|
| 120 |
|
|---|
| 121 | enum {
|
|---|
| 122 | USB_KBD_POLL_EP_NO = 0,
|
|---|
| 123 | USB_KBD_POLL_EP_COUNT = 1
|
|---|
| 124 | };
|
|---|
| 125 |
|
|---|
| 126 | usb_endpoint_description_t *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1];
|
|---|
| 127 |
|
|---|
| 128 | ddf_dev_ops_t keyboard_ops;
|
|---|
| 129 |
|
|---|
| 130 | /*----------------------------------------------------------------------------*/
|
|---|
| 131 |
|
|---|
| 132 | usb_kbd_t *usb_kbd_new(void);
|
|---|
| 133 |
|
|---|
| 134 | int usb_kbd_init(usb_kbd_t *kbd_dev, usb_device_t *dev);
|
|---|
| 135 |
|
|---|
| 136 | bool usb_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,
|
|---|
| 137 | size_t buffer_size, void *arg);
|
|---|
| 138 |
|
|---|
| 139 | void usb_kbd_polling_ended_callback(usb_device_t *dev, bool reason,
|
|---|
| 140 | void *arg);
|
|---|
| 141 |
|
|---|
| 142 | int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev);
|
|---|
| 143 |
|
|---|
| 144 | int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev);
|
|---|
| 145 |
|
|---|
| 146 | void usb_kbd_free(usb_kbd_t **kbd_dev);
|
|---|
| 147 |
|
|---|
| 148 | void usb_kbd_push_ev(usb_kbd_t *kbd_dev, int type, unsigned int key);
|
|---|
| 149 |
|
|---|
| 150 | #endif /* USB_KBDDEV_H_ */
|
|---|
| 151 |
|
|---|
| 152 | /**
|
|---|
| 153 | * @}
|
|---|
| 154 | */
|
|---|