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,
24 .remove = usb_hidkb_remove,
29 * just using two very simple US layout code translation tables that
30 * are sufficient for providing a getc() C standard library call;
31 * the only non-printable character here in this table is ESCAPE which
32 * has index 0x29 and is zero
34 unsigned char code_translation_table[2][57] = {
36 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
37 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2',
38 '3', '4', '5', '6', '7', '8', '9', '0', '\n', 0, '\r','\t',' ', '-', '=', '[',
39 ']', '\\','\\',';', '\'','`', ',', '.', '/'
42 0, 0, 0, 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
43 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@',
44 '#', '$', '%', '^', '&', '*', '(', ')', '\n', 0, '\r','\t',' ', '_', '+', '{',
45 '}', '|', '|', ':', '\"','~', '<', '>', '?'
52 usb_register_driver(&hidkb);
55 void usb_hidkb_probe()
57 struct usb_device *dev;
58 struct element *iterator = core.devices->head;
60 while(iterator != NULL) {
61 dev = (struct usb_device*)iterator->data;
66 if(dev->conf->intf->bInterfaceClass == HID_CLASSCODE &&
67 dev->conf->intf->bInterfaceSubClass == 1 && /* keyboard support boot protocol? */
68 dev->conf->intf->bInterfaceProtocol == 1) { /* keyboard? */
69 hidkb.data = (void*) dev;
70 usb_hidkb_set_idle(dev, 1);
73 iterator=iterator->next;
77 void usb_hidkb_set_idle(struct usb_device *dev, u8 duration) {
81 usb_control_msg(dev, 0x21, SET_IDLE, (duration << 8), 0, 0, buf, 0);
82 hexdump((void*) buf, 8);
85 void usb_hidkb_check()
91 return hidkb.data ? 1 : 0;
94 void usb_hidkb_remove() {
98 struct kbrep *usb_hidkb_getChars() {
99 struct usb_device *dev = (struct usb_device*) hidkb.data;
100 struct kbrep *ret = (struct kbrep*) malloc(sizeof(struct kbrep));
103 s8 epnum = dev->conf->intf->endp->bEndpointAddress & 0xf;
104 (void) usb_interrupt_read(dev, epnum, (u8*) ret, 8, 0);
106 printf("============\nusb_interrupt_read:\n");
107 hexdump((void*)ret, 8);
112 unsigned char usb_hidkb_get_char_from_keycode(u8 keycode, int shifted)
114 unsigned char result = 0;
115 if (keycode >= 0x3 && keycode < 57) {
116 result = code_translation_table[!!shifted][keycode];