From 1d0ed6b8602228d940d70e731ca88155ad15b65a Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Sat, 26 Sep 2009 09:53:23 +0200 Subject: [PATCH] added set_rate for HID devices; keyboard driver works fine at proper rate now, but console output still sucks a bit ;) --- main.c | 32 ++++++++++++++++++++++++++------ usb/core/core.c | 2 +- usb/drivers/class/hid.c | 15 +++++++++++++-- usb/drivers/class/hid.h | 1 + 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 133d998..530d9e8 100644 --- a/main.c +++ b/main.c @@ -145,17 +145,33 @@ int main(void) #define TABSIZE 4 /* you are welcome to make this nice :) */ char str[7]; - u16 i, j, y=STDOUT_BORDER_TOP, x=STDOUT_BORDER_LEFT; + u16 i, j, ret=0, y=STDOUT_BORDER_TOP, x=STDOUT_BORDER_LEFT; u16 old_x, old_y; - struct kbrep *k; + struct kbrep *k, *old=NULL; while(1) { memset(str, '\0', 7); - j=0; k = usb_hidkb_getChars(); + j=0; old_x = x; /* save actual x and y position for printing after the loop */ old_y = y; for(i=0; k->keys[i]>0; i++) { + + /* dropping char's if necessary */ + if(old) { + for(j=0; j < 6; j++) { + if(old->keys[j] == k->keys[i]) { + ret = 1; + break; + } + } + } + if(ret) { + ret = 0; + continue; + } + j = 0; + unsigned char key = usb_hidkb_get_char_from_keycode(k->keys[i], (k->mod & MOD_lshift) || (k->mod & MOD_rshift)); /* no key or key not relevant? next, please. */ @@ -166,9 +182,11 @@ int main(void) if (key == '\n') { x = STDOUT_BORDER_LEFT; y += FONT_HEIGHT; + printf("\n"); /* TAB pressed? */ } else if (key == '\t') { x += (TABSIZE*FONT_WIDTH); + printf("\t"); /* BACKSPACE pressed? */ } else if (key == '\r') { @@ -191,12 +209,14 @@ int main(void) y = STDOUT_BORDER_TOP; } } - free(k); + if(old) { + free(old); + } + old = k; if(j > 0) { /* when there was any printable stuff, show it */ print_str_noscroll(old_x, old_y, str); - printf("y: %d\n", y); + printf("%s", str); } - } #if 0 diff --git a/usb/core/core.c b/usb/core/core.c index 54cfb97..0b38e77 100644 --- a/usb/core/core.c +++ b/usb/core/core.c @@ -121,7 +121,7 @@ struct usb_device *usb_add_device(u8 lowspeed, u32 reg) return (void*) -1; } -//#define WTF +#define WTF #ifdef WTF volatile u8 wzf = 11; if(0 == wzf) { diff --git a/usb/drivers/class/hid.c b/usb/drivers/class/hid.c index c8c9dfe..b79bcd3 100644 --- a/usb/drivers/class/hid.c +++ b/usb/drivers/class/hid.c @@ -66,12 +66,21 @@ void usb_hidkb_probe() dev->conf->intf->bInterfaceSubClass == 1 && /* keyboard support boot protocol? */ dev->conf->intf->bInterfaceProtocol == 1) { /* keyboard? */ hidkb.data = (void*) dev; + usb_hidkb_set_idle(dev, 1); } iterator=iterator->next; } } +void usb_hidkb_set_idle(struct usb_device *dev, u8 duration) { +#define SET_IDLE 0x0A + u8 buf[8]; + memset(buf, 0, 8); + usb_control_msg(dev, 0x21, SET_IDLE, (duration << 8), 0, 0, buf, 0); + hexdump((void*) buf, 8); +} + void usb_hidkb_check() { } @@ -88,16 +97,18 @@ struct kbrep *usb_hidkb_getChars() { memset(ret, 0, 8); s8 epnum = dev->conf->intf->endp->bEndpointAddress & 0xf; (void) usb_interrupt_read(dev, epnum, (u8*) ret, 8, 0); +#if 0 printf("============\nusb_interrupt_read:\n"); hexdump((void*)ret, 8); - +#endif return ret; } unsigned char usb_hidkb_get_char_from_keycode(u8 keycode, int shifted) { unsigned char result = 0; - if (keycode < 57) + if (keycode >= 0x3 && keycode < 57) { result = code_translation_table[!!shifted][keycode]; + } return result; } diff --git a/usb/drivers/class/hid.h b/usb/drivers/class/hid.h index 85ce3a8..e8218ad 100644 --- a/usb/drivers/class/hid.h +++ b/usb/drivers/class/hid.h @@ -35,6 +35,7 @@ u8 usb_hidkb_inuse(); struct kbrep *usb_hidkb_getChars(); unsigned char usb_hidkb_get_char_from_keycode(u8 keycode, int shifted); +void usb_hidkb_set_idle(struct usb_device *dev, u8 duration); #endif /* __HID_H */ -- 2.25.1