license stuff
[ppcskel.git] / usb / drivers / class / hid.c
1 /*
2         ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
3         hid driver
4
5 Copyright (C) 2009     Bernhard Urban <lewurm@gmx.net>
6 Copyright (C) 2009     Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
7
8 # This code is licensed to you under the terms of the GNU GPL, version 2;
9 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10 */
11
12 #include "../../core/core.h"
13 #include "../../core/usb.h"
14 #include "../../usbspec/usb11spec.h"
15 #include "../../../malloc.h"
16 #include "../../../string.h"
17
18 #include "hid.h"
19
20 struct usb_driver hidkb = {
21         .name     = "hidkb",
22         .probe  = usb_hidkb_probe,
23         .check  = usb_hidkb_check,
24         .data     = NULL
25 };
26
27 void usb_hidkb_init()
28 {
29         usb_register_driver(&hidkb);
30 }
31
32
33 void usb_hidkb_probe()
34 {
35         struct usb_device *dev;
36         struct element *iterator = core.devices->head;
37         
38         while(iterator != NULL) {
39                 dev = (struct usb_device*)iterator->data;
40
41                 if(dev->conf->intf->bInterfaceClass == HID_CLASSCODE &&
42                                 dev->conf->intf->bInterfaceSubClass == 1 && /* keyboard support boot protocol? */
43                                 dev->conf->intf->bInterfaceProtocol == 1) { /* keyboard? */
44
45
46                         hidkb.data = (void*) dev;
47                 }
48
49                 iterator=iterator->next;
50         }
51 }
52
53
54 void usb_hidkb_check()
55 {
56 }
57
58 struct kbrep *usb_hidkb_getChars() {
59         struct usb_device *dev = (struct usb_device*) hidkb.data;
60         struct kbrep *ret = (struct kbrep*) malloc(sizeof(struct kbrep));
61
62         memset(ret, 0, 8);
63         s8 epnum = dev->conf->intf->endp->bEndpointAddress & 0xf;
64         (void) usb_interrupt_read(dev, epnum, (u8*) ret, 8, 0);
65         printf("============\nusb_interrupt_read:\n");
66         hexdump((void*)ret, 8);
67
68         return ret;
69 }
70