| 1 | /*
|
|---|
| 2 | * Copyright (c) 2009 Jiri Svoboda
|
|---|
| 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 mouse
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <ipc/char.h>
|
|---|
| 37 | #include <async.h>
|
|---|
| 38 | #include <vfs/vfs.h>
|
|---|
| 39 | #include <fcntl.h>
|
|---|
| 40 | #include <errno.h>
|
|---|
| 41 |
|
|---|
| 42 | #include <char_mouse.h>
|
|---|
| 43 | #include <mouse_port.h>
|
|---|
| 44 |
|
|---|
| 45 | static void chardev_events(ipc_callid_t iid, ipc_call_t *icall);
|
|---|
| 46 |
|
|---|
| 47 | static int dev_phone;
|
|---|
| 48 |
|
|---|
| 49 | #define NAME "char_mouse"
|
|---|
| 50 |
|
|---|
| 51 | int mouse_port_init(void)
|
|---|
| 52 | {
|
|---|
| 53 | const char *input = "/dev/char/ps2b";
|
|---|
| 54 | int input_fd;
|
|---|
| 55 |
|
|---|
| 56 | printf(NAME ": open %s\n", input);
|
|---|
| 57 |
|
|---|
| 58 | input_fd = open(input, O_RDONLY);
|
|---|
| 59 | if (input_fd < 0) {
|
|---|
| 60 | printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
|
|---|
| 61 | return false;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | dev_phone = fd_phone(input_fd);
|
|---|
| 65 | if (dev_phone < 0) {
|
|---|
| 66 | printf(NAME ": Failed to connect to device\n");
|
|---|
| 67 | return false;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /* NB: The callback connection is slotted for removal */
|
|---|
| 71 | if (async_connect_to_me(dev_phone, 0, 0, 0, chardev_events) != 0) {
|
|---|
| 72 | printf(NAME ": Failed to create callback from device\n");
|
|---|
| 73 | return false;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | return 0;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | void mouse_port_yield(void)
|
|---|
| 80 | {
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | void mouse_port_reclaim(void)
|
|---|
| 84 | {
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void mouse_port_write(uint8_t data)
|
|---|
| 88 | {
|
|---|
| 89 | async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | static void chardev_events(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 93 | {
|
|---|
| 94 | /* Ignore parameters, the connection is already opened */
|
|---|
| 95 | while (true) {
|
|---|
| 96 |
|
|---|
| 97 | ipc_call_t call;
|
|---|
| 98 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 99 |
|
|---|
| 100 | int retval;
|
|---|
| 101 |
|
|---|
| 102 | switch (IPC_GET_IMETHOD(call)) {
|
|---|
| 103 | case IPC_M_PHONE_HUNGUP:
|
|---|
| 104 | /* TODO: Handle hangup */
|
|---|
| 105 | return;
|
|---|
| 106 | case IPC_FIRST_USER_METHOD:
|
|---|
| 107 | mouse_handle_byte(IPC_GET_ARG1(call));
|
|---|
| 108 | break;
|
|---|
| 109 | default:
|
|---|
| 110 | retval = ENOENT;
|
|---|
| 111 | }
|
|---|
| 112 | async_answer_0(callid, retval);
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /**
|
|---|
| 117 | * @}
|
|---|
| 118 | */
|
|---|