9101c08e61cd8e39ca9c5c82b424e997a48ed1b2
[ppcskel.git] / usb / drivers / class / hid.c
1 #include "../../core/core.h"
2 #include "../../core/usb.h"
3 #include "../../usbspec/usb11spec.h"
4 #include "../../../malloc.h"
5 #include "../../../string.h"
6
7 #include "hid.h"
8
9 struct usb_driver hidkb = {
10         .name     = "hidkb",
11         .probe  = usb_hidkb_probe,
12         .check  = usb_hidkb_check,
13         .data     = NULL
14 };
15
16 void usb_hidkb_init()
17 {
18         usb_register_driver(&hidkb);
19 }
20
21
22 void usb_hidkb_probe()
23 {
24         struct usb_device *dev;
25         struct element *iterator = core.devices->head;
26         
27         while(iterator != NULL) {
28                 dev = (struct usb_device*)iterator->data;
29
30                 if(dev->conf->intf->bInterfaceClass == HID_CLASSCODE &&
31                                 dev->conf->intf->bInterfaceSubClass == 1 && /* keyboard support boot protocol? */
32                                 dev->conf->intf->bInterfaceProtocol == 1) { /* keyboard? */
33
34
35                         hidkb.data = (void*) dev;
36                 }
37
38                 iterator=iterator->next;
39         }
40 }
41
42
43 void usb_hidkb_check()
44 {
45 }
46
47 struct kbrep *usb_hidkb_getChars() {
48         struct usb_device *dev = (struct usb_device*) hidkb.data;
49         struct kbrep *ret = (struct kbrep*) malloc(sizeof(struct kbrep));
50
51         memset(ret, 0, 8);
52         s8 epnum = dev->conf->intf->endp->bEndpointAddress & 0xf;
53         (void) usb_interrupt_read(dev, epnum, (u8*) ret, 8, 0);
54         printf("============\nusb_interrupt_read:\n");
55         hexdump((void*)ret, 8);
56
57         return ret;
58 }
59