| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
|---|
| 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 | /** @addtogroup drvkbd
|
|---|
| 29 | * @{
|
|---|
| 30 | */
|
|---|
| 31 | /** @file
|
|---|
| 32 | * @brief XT keyboard driver;
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #include <errno.h>
|
|---|
| 36 | #include <devman.h>
|
|---|
| 37 | #include <device/char_dev.h>
|
|---|
| 38 | #include <ddf/log.h>
|
|---|
| 39 |
|
|---|
| 40 | #include "xtkbd.h"
|
|---|
| 41 |
|
|---|
| 42 | static int polling(void *);
|
|---|
| 43 |
|
|---|
| 44 | int xt_kbd_init(xt_kbd_t *kbd, ddf_dev_t *dev)
|
|---|
| 45 | {
|
|---|
| 46 | assert(kbd);
|
|---|
| 47 | assert(dev);
|
|---|
| 48 | kbd->input_sess = NULL;
|
|---|
| 49 | kbd->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
|
|---|
| 50 | dev->handle, IPC_FLAG_BLOCKING);
|
|---|
| 51 | if (!kbd->parent_sess)
|
|---|
| 52 | return ENOMEM;
|
|---|
| 53 |
|
|---|
| 54 | kbd->kbd_fun = ddf_fun_create(dev, fun_exposed, "kbd");
|
|---|
| 55 | if (!kbd->kbd_fun) {
|
|---|
| 56 | async_hangup(kbd->parent_sess);
|
|---|
| 57 | return ENOMEM;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | const int ret = ddf_fun_bind(kbd->kbd_fun);
|
|---|
| 61 | if (ret != EOK) {
|
|---|
| 62 | async_hangup(kbd->parent_sess);
|
|---|
| 63 | ddf_fun_destroy(kbd->kbd_fun);
|
|---|
| 64 | return ENOMEM;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | kbd->polling_fibril = fibril_create(polling, kbd);
|
|---|
| 68 | if (!kbd->polling_fibril) {
|
|---|
| 69 | async_hangup(kbd->parent_sess);
|
|---|
| 70 | ddf_fun_unbind(kbd->kbd_fun);
|
|---|
| 71 | ddf_fun_destroy(kbd->kbd_fun);
|
|---|
| 72 | return ENOMEM;
|
|---|
| 73 | }
|
|---|
| 74 | fibril_add_ready(kbd->polling_fibril);
|
|---|
| 75 | return EOK;
|
|---|
| 76 | }
|
|---|
| 77 | /*----------------------------------------------------------------------------*/
|
|---|
| 78 | int polling(void *arg)
|
|---|
| 79 | {
|
|---|
| 80 | assert(arg);
|
|---|
| 81 | xt_kbd_t *kbd = arg;
|
|---|
| 82 |
|
|---|
| 83 | assert(kbd->parent_sess);
|
|---|
| 84 | while (1) {
|
|---|
| 85 | uint8_t code = 0;
|
|---|
| 86 | ssize_t size = char_dev_read(kbd->parent_sess, &code, 1);
|
|---|
| 87 | ddf_msg(LVL_DEBUG, "Got scancode: %hhx, size: %zd", code, size);
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|