[3a2f8aa] | 1 | /*
|
---|
[9be360ee] | 2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[3a2f8aa] | 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 kbd_port
|
---|
| 30 | * @ingroup kbd
|
---|
| 31 | * @{
|
---|
[79ae36dd] | 32 | */
|
---|
[3a2f8aa] | 33 | /** @file
|
---|
| 34 | * @brief ADB keyboard port driver.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <ipc/adb.h>
|
---|
| 38 | #include <async.h>
|
---|
| 39 | #include <vfs/vfs.h>
|
---|
| 40 | #include <errno.h>
|
---|
[15f3c3f] | 41 | #include <loc.h>
|
---|
[b6a088f] | 42 | #include "../input.h"
|
---|
| 43 | #include "../kbd_port.h"
|
---|
| 44 | #include "../kbd.h"
|
---|
[3a2f8aa] | 45 |
|
---|
[9934f7d] | 46 | static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
|
---|
[3a2f8aa] | 47 | static void adb_kbd_reg0_data(uint16_t data);
|
---|
| 48 |
|
---|
[9be360ee] | 49 | static int adb_port_init(kbd_dev_t *);
|
---|
[593e023] | 50 | static void adb_port_write(uint8_t);
|
---|
[b1bdc7a4] | 51 |
|
---|
| 52 | kbd_port_ops_t adb_port = {
|
---|
| 53 | .init = adb_port_init,
|
---|
| 54 | .write = adb_port_write
|
---|
| 55 | };
|
---|
| 56 |
|
---|
[9be360ee] | 57 | static kbd_dev_t *kbd_dev;
|
---|
[a40dea3] | 58 | static async_sess_t *dev_sess;
|
---|
[3a2f8aa] | 59 |
|
---|
[9be360ee] | 60 | static int adb_port_init(kbd_dev_t *kdev)
|
---|
[3a2f8aa] | 61 | {
|
---|
[9be360ee] | 62 | kbd_dev = kdev;
|
---|
[79ae36dd] | 63 |
|
---|
[3123d2a] | 64 | const char *dev = "adb/kbd";
|
---|
| 65 | service_id_t service_id;
|
---|
| 66 | int rc = loc_service_get_id(dev, &service_id, 0);
|
---|
[a40dea3] | 67 | if (rc != EOK)
|
---|
[79ae36dd] | 68 | return rc;
|
---|
| 69 |
|
---|
[f9b2cb4c] | 70 | dev_sess = loc_service_connect(service_id, INTERFACE_DDF, 0);
|
---|
[a40dea3] | 71 | if (dev_sess == NULL) {
|
---|
| 72 | printf("%s: Failed to connect to device\n", NAME);
|
---|
| 73 | return ENOENT;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[3123d2a] | 76 | async_exch_t *exch = async_exchange_begin(dev_sess);
|
---|
[a40dea3] | 77 | if (exch == NULL) {
|
---|
| 78 | printf("%s: Failed starting exchange with device\n", NAME);
|
---|
| 79 | async_hangup(dev_sess);
|
---|
| 80 | return ENOMEM;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[f9b2cb4c] | 83 | port_id_t port;
|
---|
| 84 | rc = async_create_callback_port(exch, INTERFACE_ADB_CB, 0, 0,
|
---|
| 85 | kbd_port_events, NULL, &port);
|
---|
| 86 |
|
---|
[a40dea3] | 87 | async_exchange_end(exch);
|
---|
[79ae36dd] | 88 | if (rc != EOK) {
|
---|
[1875a0c] | 89 | printf("%s: Failed to create callback from device\n", NAME);
|
---|
[a40dea3] | 90 | async_hangup(dev_sess);
|
---|
[79ae36dd] | 91 | return rc;
|
---|
[3a2f8aa] | 92 | }
|
---|
[79ae36dd] | 93 |
|
---|
| 94 | return EOK;
|
---|
[3a2f8aa] | 95 | }
|
---|
| 96 |
|
---|
[b1bdc7a4] | 97 | static void adb_port_write(uint8_t data)
|
---|
[3a2f8aa] | 98 | {
|
---|
| 99 | /*async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);*/
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[9934f7d] | 102 | static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
[3a2f8aa] | 103 | {
|
---|
| 104 | /* Ignore parameters, the connection is already opened */
|
---|
| 105 | while (true) {
|
---|
| 106 |
|
---|
| 107 | ipc_call_t call;
|
---|
| 108 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 109 |
|
---|
[f81498d] | 110 | int retval = EOK;
|
---|
[79ae36dd] | 111 |
|
---|
| 112 | if (!IPC_GET_IMETHOD(call)) {
|
---|
[3a2f8aa] | 113 | /* TODO: Handle hangup */
|
---|
| 114 | return;
|
---|
[79ae36dd] | 115 | }
|
---|
| 116 |
|
---|
| 117 | switch (IPC_GET_IMETHOD(call)) {
|
---|
[3a2f8aa] | 118 | case ADB_REG_NOTIF:
|
---|
| 119 | adb_kbd_reg0_data(IPC_GET_ARG1(call));
|
---|
| 120 | break;
|
---|
| 121 | default:
|
---|
| 122 | retval = ENOENT;
|
---|
| 123 | }
|
---|
[4f14e1f8] | 124 | async_answer_0(callid, retval);
|
---|
[3a2f8aa] | 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | static void adb_kbd_reg0_data(uint16_t data)
|
---|
| 129 | {
|
---|
[1875a0c] | 130 | uint8_t b0 = (data >> 8) & 0xff;
|
---|
| 131 | uint8_t b1 = data & 0xff;
|
---|
| 132 |
|
---|
[3a2f8aa] | 133 | if (b0 != 0xff)
|
---|
[1875a0c] | 134 | kbd_push_data(kbd_dev, b0);
|
---|
| 135 |
|
---|
[3a2f8aa] | 136 | if (b1 != 0xff)
|
---|
[1875a0c] | 137 | kbd_push_data(kbd_dev, b1);
|
---|
[3a2f8aa] | 138 | }
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * @}
|
---|
| 142 | */
|
---|