/uspace/trunk/kbd/generic/kbd.c |
---|
48,25 → 48,25 |
ipcarg_t phonead; |
int phoneid; |
char connected = 0; |
keybuffer_t keybuffer; |
ipcarg_t retval, arg1, arg2; |
// printf("Uspace kbd service started.\n"); |
printf("Uspace kbd service started.\n"); |
/* Initialize arch dependent parts */ |
if (!(res = kbd_arch_init())) { |
// printf("Kbd registration failed with retval %d.\n", res); |
printf("Kbd registration failed with retval %d.\n", res); |
return -1; |
}; |
/* Initialize key buffer */ |
keybuffer_init(&keybuffer); |
key_buffer_init(); |
/* Register service at nameserver */ |
// printf("%s: Registering at naming service.\n", NAME); |
printf("%s: Registering at naming service.\n", NAME); |
if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) { |
// printf("%s: Error: Registering at naming service failed.\n", NAME); |
printf("%s: Error: Registering at naming service failed.\n", NAME); |
return -1; |
}; |
75,7 → 75,7 |
// printf("%s:Call phone=%lX..", NAME, call.in_phone_hash); |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
// printf("%s: Phone hung up.\n", NAME); |
printf("%s: Phone hung up.\n", NAME); |
connected = 0; |
retval = 0; |
break; |
97,7 → 97,7 |
case IPC_M_INTERRUPT: |
if (connected) { |
/* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */ |
kbd_arch_process(&keybuffer, IPC_GET_ARG2(call)); |
kbd_arch_process(IPC_GET_ARG2(call)); |
//printf("%s: GOT INTERRUPT: %c\n", NAME, key); |
106,20 → 106,20 |
retval = 0; |
while (!keybuffer_empty(&keybuffer)) { |
if (!keybuffer_pop(&keybuffer, (char *)&arg1)) { |
// printf("%s: KeyBuffer is empty but it should not be.\n"); |
while (!key_buffer_empty()) { |
if (!key_buffer_pop((char *)&arg1)) { |
printf("%s: KeyBuffer is empty but it should not be.\n"); |
break; |
} |
/*FIXME: detection of closed connection */ |
ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, NULL, NULL); |
ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, NULL); |
} |
} |
// printf("%s: Interrupt processed.\n", NAME); |
printf("%s: Interrupt processed.\n", NAME); |
break; |
default: |
// printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call)); |
printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call)); |
retval = ENOENT; |
break; |
} |
/uspace/trunk/kbd/generic/key_buffer.c |
---|
27,22 → 27,27 |
*/ |
#include <key_buffer.h> |
#include <libadt/fifo.h> |
#define KBD_BUFFER_SIZE 128 /**< Size of buffer for pressed keys */ |
FIFO_INITIALIZE_STATIC(buffer, char, KBD_BUFFER_SIZE); /**< Fifo for storing pressed keys */ |
fifo_count_t buffer_items; /**< Counter of used items for prevent fifo overflow */ |
/** Clear key buffer. |
*/ |
void keybuffer_free(keybuffer_t *keybuffer) |
void key_buffer_free(void) |
{ |
keybuffer->items = 0; |
keybuffer->head = keybuffer->tail = keybuffer->items = 0; |
buffer_items = 0; |
buffer.head = buffer.tail = 0; |
} |
/** Key buffer initialization. |
* |
*/ |
void keybuffer_init(keybuffer_t *keybuffer) |
void key_buffer_init(void) |
{ |
keybuffer_free(keybuffer); |
key_buffer_free(); |
} |
/** Get free space in buffer. |
50,17 → 55,17 |
* to more than one character. |
* @return empty buffer space |
*/ |
int keybuffer_available(keybuffer_t *keybuffer) |
int key_buffer_available(void) |
{ |
return KEYBUFFER_SIZE - keybuffer->items; |
return KBD_BUFFER_SIZE - buffer_items; |
} |
/** |
* @return nonzero, if buffer is not empty. |
*/ |
int keybuffer_empty(keybuffer_t *keybuffer) |
int key_buffer_empty(void) |
{ |
return (keybuffer->items == 0); |
return (buffer_items == 0); |
} |
/** Push key to key buffer. |
67,11 → 72,11 |
* If buffer is full, character is ignored. |
* @param key code of stored key |
*/ |
void keybuffer_push(keybuffer_t *keybuffer, char key) |
void key_buffer_push(char key) |
{ |
if (keybuffer->items < KEYBUFFER_SIZE) { |
keybuffer->fifo[keybuffer->tail = (keybuffer->tail + 1) < keybuffer->items ? (keybuffer->tail + 1) : 0] = (key); |
keybuffer->items++; |
if (buffer_items < KBD_BUFFER_SIZE) { |
fifo_push(buffer, key); |
buffer_items++; |
} |
} |
79,11 → 84,11 |
* @param c pointer to space where to store character from buffer. |
* @return zero on empty buffer, nonzero else |
*/ |
int keybuffer_pop(keybuffer_t *keybuffer, char *c) |
int key_buffer_pop(char *c) |
{ |
if (keybuffer->items > 0) { |
keybuffer->items--; |
*c = keybuffer->fifo[keybuffer->head = (keybuffer->head + 1) < keybuffer->items ? (keybuffer->head + 1) : 0]; |
if (buffer_items > 0) { |
buffer_items--; |
*c = fifo_pop(buffer); |
return 1; |
} |
return 0; |
/uspace/trunk/kbd/include/kbd.h |
---|
31,18 → 31,5 |
#define KBD_PUSHCHAR 1024 |
#define KBD_KEY_F1 0x3b |
#define KBD_KEY_F2 0x3c |
#define KBD_KEY_F3 0x3d |
#define KBD_KEY_F4 0x3e |
#define KBD_KEY_F5 0x3f |
#define KBD_KEY_F6 0x40 |
#define KBD_KEY_F7 0x41 |
#define KBD_KEY_F8 0x42 |
#define KBD_KEY_F9 0x43 |
#define KBD_KEY_F10 0x44 |
#define KBD_KEY_F11 0x45 |
#define KBD_KEY_F12 0x46 |
#endif |
/uspace/trunk/kbd/include/key_buffer.h |
---|
31,21 → 31,12 |
#include <types.h> |
#define KEYBUFFER_SIZE 128 /**< Size of buffer for pressed keys */ |
void key_buffer_free(void); |
void key_buffer_init(void); |
int key_buffer_available(void); |
int key_buffer_empty(void); |
void key_buffer_push(char key); |
int key_buffer_pop(char *c); |
typedef struct { |
char fifo[KEYBUFFER_SIZE]; |
unsigned long head; |
unsigned long tail; |
unsigned long items; |
} keybuffer_t; |
void keybuffer_free(keybuffer_t *keybuffer); |
void keybuffer_init(keybuffer_t *keybuffer); |
int keybuffer_available(keybuffer_t *keybuffer); |
int keybuffer_empty(keybuffer_t *keybuffer); |
void keybuffer_push(keybuffer_t *keybuffer, char key); |
int keybuffer_pop(keybuffer_t *keybuffer, char *c); |
#endif |
/uspace/trunk/kbd/Makefile |
---|
67,7 → 67,7 |
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend |
$(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS) |
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map |
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map |
disasm: |
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm |
/uspace/trunk/kbd/arch/mips32/src/kbd.c |
---|
28,6 → 28,7 |
#include <arch/kbd.h> |
#include <ipc/ipc.h> |
#include <key_buffer.h> |
irq_cmd_t msim_cmds[1] = { |
{ CMD_MEM_READ_1, (void *)0xB0000000, 0 } |
44,8 → 45,8 |
return 1; |
} |
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code) |
int kbd_arch_process(int scan_code) |
{ |
keybuffer_push(keybuffer, scan_code); |
key_buffer_push(scan_code); |
return 1; |
} |
/uspace/trunk/kbd/arch/mips32/include/kbd.h |
---|
29,10 → 29,8 |
#ifndef __mips32_KBD_H__ |
#define __mips32_KBD_H__ |
#include <key_buffer.h> |
int kbd_arch_init(void); |
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code); |
int kbd_arch_process(int scan_code); |
#endif |
/uspace/trunk/kbd/arch/ia32/src/kbd.c |
---|
28,6 → 28,7 |
*/ |
#include <arch/kbd.h> |
#include <key_buffer.h> |
#include <ipc/ipc.h> |
#define SPECIAL '?' |
78,26 → 79,16 |
SPECIAL, /* 0x38 - LAlt */ |
' ', |
SPECIAL, /* 0x3a - CapsLock */ |
0x3b, /* 0x3b - F1 */ |
// SPECIAL, /* 0x3b - F1 */ |
0x3c, /* 0x3c - F2 */ |
// SPECIAL, /* 0x3c - F2 */ |
0x3d, /* 0x3d - F3 */ |
// SPECIAL, /* 0x3d - F3 */ |
0x3e, /* 0x3e - F4 */ |
// SPECIAL, /* 0x3e - F4 */ |
// SPECIAL, /* 0x3f - F5 */ |
0x3f, /* 0x3f - F5 */ |
// SPECIAL, /* 0x40 - F6 */ |
0x40, /* 0x40 - F6 */ |
// SPECIAL, /* 0x41 - F7 */ |
0x41, /* 0x41 - F7 */ |
// SPECIAL, /* 0x42 - F8 */ |
0x42, /* 0x42 - F8 */ |
// SPECIAL, /* 0x43 - F9 */ |
0x43, /* 0x43 - F9 */ |
// SPECIAL, /* 0x44 - F10 */ |
0x44, /* 0x44 - F10 */ |
SPECIAL, /* 0x3b - F1 */ |
SPECIAL, /* 0x3c - F2 */ |
SPECIAL, /* 0x3d - F3 */ |
SPECIAL, /* 0x3e - F4 */ |
SPECIAL, /* 0x3f - F5 */ |
SPECIAL, /* 0x40 - F6 */ |
SPECIAL, /* 0x41 - F7 */ |
SPECIAL, /* 0x42 - F8 */ |
SPECIAL, /* 0x43 - F9 */ |
SPECIAL, /* 0x44 - F10 */ |
SPECIAL, /* 0x45 - NumLock */ |
SPECIAL, /* 0x46 - ScrollLock */ |
'7', '8', '9', '-', |
168,26 → 159,16 |
SPECIAL, /* 0x38 - LAlt */ |
' ', |
SPECIAL, /* 0x3a - CapsLock */ |
0x3b, /* 0x3b - F1 */ |
0x3c, /* 0x3c - F2 */ |
0x3d, /* 0x3d - F3 */ |
0x3e, /* 0x3e - F4 */ |
0x3f, /* 0x3f - F5 */ |
0x40, /* 0x40 - F6 */ |
0x41, /* 0x41 - F7 */ |
0x42, /* 0x42 - F8 */ |
0x43, /* 0x43 - F9 */ |
0x44, /* 0x44 - F10 */ |
// SPECIAL, /* 0x3b - F1 */ |
// SPECIAL, /* 0x3c - F2 */ |
// SPECIAL, /* 0x3d - F3 */ |
// SPECIAL, /* 0x3e - F4 */ |
// SPECIAL, /* 0x3f - F5 */ |
// SPECIAL, /* 0x40 - F6 */ |
// SPECIAL, /* 0x41 - F7 */ |
// SPECIAL, /* 0x42 - F8 */ |
// SPECIAL, /* 0x43 - F9 */ |
// SPECIAL, /* 0x44 - F10 */ |
SPECIAL, /* 0x3b - F1 */ |
SPECIAL, /* 0x3c - F2 */ |
SPECIAL, /* 0x3d - F3 */ |
SPECIAL, /* 0x3e - F4 */ |
SPECIAL, /* 0x3f - F5 */ |
SPECIAL, /* 0x40 - F6 */ |
SPECIAL, /* 0x41 - F7 */ |
SPECIAL, /* 0x42 - F8 */ |
SPECIAL, /* 0x43 - F9 */ |
SPECIAL, /* 0x44 - F10 */ |
SPECIAL, /* 0x45 - NumLock */ |
SPECIAL, /* 0x46 - ScrollLock */ |
'7', '8', '9', '-', |
249,7 → 230,7 |
i8042_cmds |
}; |
static int key_released(keybuffer_t *keybuffer, unsigned char key) |
static int key_released(unsigned char key) |
{ |
switch (key) { |
case SC_LSHIFT: |
268,7 → 249,7 |
} |
} |
static int key_pressed(keybuffer_t *keybuffer, unsigned char key) |
static int key_pressed(unsigned char key) |
{ |
char *map = sc_primary_map; |
char ascii = sc_primary_map[key]; |
286,53 → 267,53 |
case SC_SPEC_ESCAPE: |
break; |
case SC_LEFTARR: |
if (keybuffer_available(keybuffer) >= 3) { |
keybuffer_push(keybuffer, 0x1b); |
keybuffer_push(keybuffer, 0x5b); |
keybuffer_push(keybuffer, 0x44); |
if (key_buffer_available() >= 3) { |
key_buffer_push(0x1b); |
key_buffer_push(0x5b); |
key_buffer_push(0x44); |
} |
break; |
case SC_RIGHTARR: |
if (keybuffer_available(keybuffer) >= 3) { |
keybuffer_push(keybuffer, 0x1b); |
keybuffer_push(keybuffer, 0x5b); |
keybuffer_push(keybuffer, 0x43); |
if (key_buffer_available() >= 3) { |
key_buffer_push(0x1b); |
key_buffer_push(0x5b); |
key_buffer_push(0x43); |
} |
break; |
case SC_UPARR: |
if (keybuffer_available(keybuffer) >= 3) { |
keybuffer_push(keybuffer, 0x1b); |
keybuffer_push(keybuffer, 0x5b); |
keybuffer_push(keybuffer, 0x41); |
if (key_buffer_available() >= 3) { |
key_buffer_push(0x1b); |
key_buffer_push(0x5b); |
key_buffer_push(0x41); |
} |
break; |
case SC_DOWNARR: |
if (keybuffer_available(keybuffer) >= 3) { |
keybuffer_push(keybuffer, 0x1b); |
keybuffer_push(keybuffer, 0x5b); |
keybuffer_push(keybuffer, 0x42); |
if (key_buffer_available() >= 3) { |
key_buffer_push(0x1b); |
key_buffer_push(0x5b); |
key_buffer_push(0x42); |
} |
break; |
case SC_HOME: |
if (keybuffer_available(keybuffer) >= 3) { |
keybuffer_push(keybuffer, 0x1b); |
keybuffer_push(keybuffer, 0x4f); |
keybuffer_push(keybuffer, 0x48); |
if (key_buffer_available() >= 3) { |
key_buffer_push(0x1b); |
key_buffer_push(0x4f); |
key_buffer_push(0x48); |
} |
break; |
case SC_END: |
if (keybuffer_available(keybuffer) >= 3) { |
keybuffer_push(keybuffer, 0x1b); |
keybuffer_push(keybuffer, 0x4f); |
keybuffer_push(keybuffer, 0x46); |
if (key_buffer_available() >= 3) { |
key_buffer_push(0x1b); |
key_buffer_push(0x4f); |
key_buffer_push(0x46); |
} |
break; |
case SC_DELETE: |
if (keybuffer_available(keybuffer) >= 4) { |
keybuffer_push(keybuffer, 0x1b); |
keybuffer_push(keybuffer, 0x5b); |
keybuffer_push(keybuffer, 0x33); |
keybuffer_push(keybuffer, 0x7e); |
if (key_buffer_available() >= 4) { |
key_buffer_push(0x1b); |
key_buffer_push(0x5b); |
key_buffer_push(0x33); |
key_buffer_push(0x7e); |
} |
break; |
default: |
343,7 → 324,7 |
shift = !shift; |
if (shift) |
map = sc_secondary_map; |
keybuffer_push(keybuffer, map[key]); |
key_buffer_push(map[key]); |
break; |
} |
} |
356,13 → 337,13 |
return !(ipc_register_irq(1, &i8042_kbd)); |
} |
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code) |
int kbd_arch_process(int scan_code) |
{ |
if (scan_code != IGNORE_CODE) { |
if (scan_code & KEY_RELEASE) |
key_released(keybuffer, scan_code ^ KEY_RELEASE); |
key_released(scan_code ^ KEY_RELEASE); |
else |
key_pressed(keybuffer, scan_code); |
key_pressed(scan_code); |
} |
return 1; |
} |
/uspace/trunk/kbd/arch/ia32/include/kbd.h |
---|
29,9 → 29,7 |
#ifndef __ia32_KBD_H__ |
#define __ia32_KBD_H__ |
#include <key_buffer.h> |
int kbd_arch_init(void); |
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code); |
int kbd_arch_process(int scan_code); |
#endif |