source: mainline/uspace/drv/usbkbd/main.c@ 91db50ac

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 91db50ac was 91db50ac, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

USB driver to HC communication uses DDF interfaces

Started work on using interfaces on the background of communication
between HC and USB driver. However, for driver developers, this will
be hidden completely.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
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#include <usb/usbdrv.h>
29#include <driver.h>
30#include <errno.h>
31
32#define BUFFER_SIZE 32
33
34/* Call this periodically to check keyboard status changes. */
35static void poll_keyboard(device_t *dev)
36{
37 int rc;
38 usb_handle_t handle;
39 char buffer[BUFFER_SIZE];
40 size_t actual_size;
41 usb_endpoint_t poll_endpoint = 1;
42
43 rc = usb_drv_async_interrupt_in(dev->parent_phone, poll_endpoint,
44 buffer, BUFFER_SIZE, &actual_size, &handle);
45 if (rc != EOK) {
46 return;
47 }
48
49 rc = usb_drv_async_wait_for(handle);
50 if (rc != EOK) {
51 return;
52 }
53
54 /*
55 * If the keyboard answered with NAK, it returned no data.
56 * This implies that no change happened since last query.
57 */
58 if (actual_size == 0) {
59 return;
60 }
61
62 /*
63 * Process pressed keys.
64 */
65}
66
67static int add_kbd_device(device_t *dev)
68{
69 /* For now, fail immediately. */
70 return ENOTSUP;
71
72 /*
73 * When everything is okay, connect to "our" HC.
74 */
75 int phone = usb_drv_hc_connect(dev, 0);
76 if (phone < 0) {
77 /*
78 * Connecting to HC failed, roll-back and announce
79 * failure.
80 */
81 return phone;
82 }
83
84 dev->parent_phone = phone;
85
86 /*
87 * Just for fun ;-).
88 */
89 poll_keyboard(dev);
90
91 /*
92 * Hurrah, device is initialized.
93 */
94 return EOK;
95}
96
97static driver_ops_t kbd_driver_ops = {
98 .add_device = add_kbd_device,
99};
100
101static driver_t kbd_driver = {
102 .name = "usbkbd",
103 .driver_ops = &kbd_driver_ops
104};
105
106int main(int argc, char *argv[])
107{
108 return driver_main(&kbd_driver);
109}
Note: See TracBrowser for help on using the repository browser.