2 ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
5 Copyright (C) 2009 Bernhard Urban <lewurm@gmx.net>
6 Copyright (C) 2009 Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
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
12 #include "../../core/core.h"
13 #include "../../core/usb.h"
14 #include "../../usbspec/usb11spec.h"
15 #include "../../../malloc.h"
16 #include "../../../string.h"
20 struct usb_driver hidkb = {
22 .probe = usb_hidkb_probe,
23 .check = usb_hidkb_check,
28 * just using two very simple US layout code translation tables that
29 * are sufficient for providing a getc() C standard library call;
30 * the only non-printable character here in this table is ESCAPE which
31 * has index 0x29 and is zero
33 unsigned char code_translation_table[2][57] = {
35 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
36 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2',
37 '3', '4', '5', '6', '7', '8', '9', '0', '\n', 0, '\r','\t',' ', '-', '=', '[',
38 ']', '\\','\\',';', '\'','`', ',', '.', '/'
41 0, 0, 0, 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
42 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@',
43 '#', '$', '%', '^', '&', '*', '(', ')', '\n', 0, '\r','\t',' ', '_', '+', '{',
44 '}', '|', '|', ':', '\"','~', '<', '>', '?'
51 usb_register_driver(&hidkb);
54 void usb_hidkb_probe()
56 struct usb_device *dev;
57 struct element *iterator = core.devices->head;
59 while(iterator != NULL) {
60 dev = (struct usb_device*)iterator->data;
65 if(dev->conf->intf->bInterfaceClass == HID_CLASSCODE &&
66 dev->conf->intf->bInterfaceSubClass == 1 && /* keyboard support boot protocol? */
67 dev->conf->intf->bInterfaceProtocol == 1) { /* keyboard? */
68 hidkb.data = (void*) dev;
71 iterator=iterator->next;
75 void usb_hidkb_check()
81 return hidkb.data ? 1 : 0;
84 struct kbrep *usb_hidkb_getChars() {
85 struct usb_device *dev = (struct usb_device*) hidkb.data;
86 struct kbrep *ret = (struct kbrep*) malloc(sizeof(struct kbrep));
89 s8 epnum = dev->conf->intf->endp->bEndpointAddress & 0xf;
90 (void) usb_interrupt_read(dev, epnum, (u8*) ret, 8, 0);
91 printf("============\nusb_interrupt_read:\n");
92 hexdump((void*)ret, 8);
97 unsigned char usb_hidkb_get_char_from_keycode(u8 keycode, int shifted)
99 unsigned char result = 0;
101 result = code_translation_table[!!shifted][keycode];