Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev HEAD → Rev 4156

/branches/dd/uspace/srv/kbd/ctl/pl050.c
File deleted
/branches/dd/uspace/srv/kbd/ctl/pc.c
32,12 → 32,12
*/
/**
* @file
* @brief PC keyboard controller driver.
* @brief PC keyboard controller driver.
*/
 
#include <kbd.h>
#include <io/console.h>
#include <io/keycode.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
#include <gsp.h>
 
188,7 → 188,7
 
void kbd_ctl_parse_scancode(int scancode)
{
console_ev_type_t type;
kbd_ev_type_t type;
unsigned int key;
int *map;
size_t map_length;
207,9 → 207,6
map = scanmap_e0;
map_length = sizeof(scanmap_e0) / sizeof(int);
break;
default:
map = NULL;
map_length = 0;
}
 
ds = ds_s;
216,12 → 213,12
 
if (scancode & 0x80) {
scancode &= ~0x80;
type = KEY_RELEASE;
type = KE_RELEASE;
} else {
type = KEY_PRESS;
type = KE_PRESS;
}
 
if ((scancode < 0) || ((size_t) scancode >= map_length))
if (scancode < 0 || scancode >= map_length)
return;
 
key = map[scancode];
/branches/dd/uspace/srv/kbd/ctl/stty.c
36,7 → 36,8
*/
 
#include <kbd.h>
#include <io/keycode.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
#include <gsp.h>
#include <stroke.h>
/branches/dd/uspace/srv/kbd/ctl/sun.c
36,8 → 36,8
*/
 
#include <kbd.h>
#include <io/console.h>
#include <io/keycode.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
 
#define KBD_KEY_RELEASE 0x80
52,7 → 52,7
 
void kbd_ctl_parse_scancode(int scancode)
{
console_ev_type_t type;
kbd_ev_type_t type;
unsigned int key;
 
if (scancode < 0 || scancode >= 0x100)
63,9 → 63,9
 
if (scancode & KBD_KEY_RELEASE) {
scancode &= ~KBD_KEY_RELEASE;
type = KEY_RELEASE;
type = KE_RELEASE;
} else {
type = KEY_PRESS;
type = KE_PRESS;
}
 
key = scanmap_simple[scancode];
/branches/dd/uspace/srv/kbd/ctl/gxe_fb.c
36,8 → 36,8
*/
 
#include <kbd.h>
#include <io/console.h>
#include <io/keycode.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <kbd_ctl.h>
#include <gsp.h>
#include <stroke.h>
/branches/dd/uspace/srv/kbd/include/sun.h
File deleted
/branches/dd/uspace/srv/kbd/include/keybuffer.h
File deleted
/branches/dd/uspace/srv/kbd/include/gsp.h
37,7 → 37,7
#ifndef KBD_GSP_H_
#define KBD_GSP_H_
 
#include <adt/hash_table.h>
#include <libadt/hash_table.h>
 
enum {
GSP_END = -1, /**< Terminates a sequence. */
/branches/dd/uspace/srv/kbd/include/layout.h
27,10 → 27,10
*/
 
/** @addtogroup kbdgen generic
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
*/
/** @file
*/
 
37,20 → 37,13
#ifndef KBD_LAYOUT_H_
#define KBD_LAYOUT_H_
 
#include <sys/types.h>
#include <io/console.h>
#include <kbd/kbd.h>
 
typedef struct {
void (*reset)(void);
wchar_t (*parse_ev)(console_event_t *);
} layout_op_t;
extern char layout_parse_ev(kbd_event_t *);
 
extern layout_op_t us_qwerty_op;
extern layout_op_t us_dvorak_op;
extern layout_op_t cz_op;
 
#endif
 
/**
* @}
*/
*/
 
/branches/dd/uspace/srv/kbd/include/kbd.h
27,10 → 27,10
*/
 
/** @addtogroup kbdgen generic
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
*/
/** @file
*/
 
37,20 → 37,14
#ifndef KBD_KBD_H_
#define KBD_KBD_H_
 
#include <keybuffer.h>
#include <ipc/ipc.h>
#include <key_buffer.h>
 
#define KBD_EVENT 1024
#define KBD_MS_LEFT 1025
#define KBD_MS_RIGHT 1026
#define KBD_MS_MIDDLE 1027
#define KBD_MS_MOVE 1028
#define KBD_EVENT 1024
#define KBD_MS_LEFT 1025
#define KBD_MS_RIGHT 1026
#define KBD_MS_MIDDLE 1027
#define KBD_MS_MOVE 1028
 
typedef enum {
KBD_YIELD = IPC_FIRST_USER_METHOD,
KBD_RECLAIM
} kbd_request_t;
 
extern int cir_service;
extern int cir_phone;
 
61,4 → 55,5
 
/**
* @}
*/
*/
 
/branches/dd/uspace/srv/kbd/include/key_buffer.h
0,0 → 1,66
/*
* Copyright (c) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdgen
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#ifndef __KEY_BUFFER_H__
#define __KEY_BUFFER_H__
 
#include <sys/types.h>
#include <kbd/kbd.h>
 
/** Size of buffer for pressed keys */
#define KEYBUFFER_SIZE 128
 
typedef struct {
kbd_event_t fifo[KEYBUFFER_SIZE];
unsigned long head;
unsigned long tail;
unsigned long items;
} keybuffer_t;
 
extern void keybuffer_free(keybuffer_t *);
extern void keybuffer_init(keybuffer_t *);
extern int keybuffer_available(keybuffer_t *);
extern int keybuffer_empty(keybuffer_t *);
extern void keybuffer_push(keybuffer_t *, const kbd_event_t *);
extern void keybuffer_push0(keybuffer_t *, int c);
extern int keybuffer_pop(keybuffer_t *, kbd_event_t *);
 
#endif
 
/**
* @}
*/
 
/branches/dd/uspace/srv/kbd/include/kbd_port.h
38,8 → 38,6
#define KBD_PORT_H_
 
extern int kbd_port_init(void);
extern void kbd_port_yield(void);
extern void kbd_port_reclaim(void);
 
#endif
 
/branches/dd/uspace/srv/kbd/port/pl050.c
File deleted
/branches/dd/uspace/srv/kbd/port/sun.c
File deleted
/branches/dd/uspace/srv/kbd/port/gxemul.c
69,14 → 69,6
return 0;
}
 
void kbd_port_yield(void)
{
}
 
void kbd_port_reclaim(void)
{
}
 
/** Process data sent when a key is pressed.
*
* @param keybuffer Buffer of pressed keys.
/branches/dd/uspace/srv/kbd/port/ns16550.c
35,12 → 35,10
*/
 
#include <ipc/ipc.h>
#include <ipc/bus.h>
#include <async.h>
#include <sysinfo.h>
#include <kbd.h>
#include <kbd_port.h>
#include <sun.h>
#include <ddi.h>
 
/* NS16550 registers */
91,7 → 89,7
static uintptr_t ns16550_physical;
static uintptr_t ns16550_kernel;
 
int ns16550_port_init(void)
int kbd_port_init(void)
{
void *vaddr;
 
102,26 → 100,14
ns16550_kbd.cmds[0].addr = (void *) (ns16550_kernel + LSR_REG);
ns16550_kbd.cmds[3].addr = (void *) (ns16550_kernel + RBR_REG);
ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(),
sysinfo_value("kbd.inr"), &ns16550_kbd);
0, &ns16550_kbd);
return pio_enable((void *) ns16550_physical, 8, &vaddr);
}
 
void ns16550_port_yield(void)
{
}
 
void ns16550_port_reclaim(void)
{
}
 
static void ns16550_irq_handler(ipc_callid_t iid, ipc_call_t *call)
{
int scan_code = IPC_GET_ARG2(*call);
kbd_push_scancode(scan_code);
if (cir_service)
async_msg_1(cir_phone, BUS_CLEAR_INTERRUPT,
IPC_GET_METHOD(*call));
}
 
/**
/branches/dd/uspace/srv/kbd/port/msim.c
69,17 → 69,22
return 0;
}
 
void kbd_port_yield(void)
static void msim_irq_handler(ipc_callid_t iid, ipc_call_t *call)
{
}
int scan_code = IPC_GET_ARG2(*call);
// static int esc_count=0;
 
void kbd_port_reclaim(void)
{
}
// if (scan_code == 0x1b) {
// esc_count++;
// if (esc_count == 3)
// __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
// } else {
// esc_count=0;
// }
 
static void msim_irq_handler(ipc_callid_t iid, ipc_call_t *call)
{
int scan_code = IPC_GET_ARG2(*call);
// if (fb_fb)
// return kbd_arch_process_fb(keybuffer, scan_code);
 
kbd_push_scancode(scan_code);
}
 
/branches/dd/uspace/srv/kbd/port/i8042.c
135,8 → 135,8
(void) pio_read_8(&i8042->data);
/* Enable kbd */
i8042_kbd.cmds[0].addr = (void *) &((i8042_t *) i8042_kernel)->status;
i8042_kbd.cmds[3].addr = (void *) &((i8042_t *) i8042_kernel)->data;
i8042_kbd.cmds[0].addr = &((i8042_t *) i8042_kernel)->status;
i8042_kbd.cmds[3].addr = &((i8042_t *) i8042_kernel)->data;
ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(), 0, &i8042_kbd);
 
int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE;
151,14 → 151,6
return 0;
}
 
void kbd_port_yield(void)
{
}
 
void kbd_port_reclaim(void)
{
}
 
static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call)
{
int status = IPC_GET_ARG1(*call);
/branches/dd/uspace/srv/kbd/port/ski.c
42,7 → 42,6
#include <kbd_port.h>
#include <sys/types.h>
#include <thread.h>
#include <bool.h>
 
#define SKI_GETCHAR 21
 
51,8 → 50,6
static void *ski_thread_impl(void *arg);
static int32_t ski_getchar(void);
 
static volatile bool polling_disabled = false;
 
/** Initialize Ski port driver. */
int kbd_port_init(void)
{
67,16 → 64,6
return 0;
}
 
void kbd_port_yield(void)
{
polling_disabled = true;
}
 
void kbd_port_reclaim(void)
{
polling_disabled = false;
}
 
/** Thread to poll Ski for keypresses. */
static void *ski_thread_impl(void *arg)
{
84,7 → 71,7
(void) arg;
 
while (1) {
while (polling_disabled == false) {
while (1) {
c = ski_getchar();
if (c == 0)
break;
/branches/dd/uspace/srv/kbd/port/z8530.c
40,7 → 40,6
#include <sysinfo.h>
#include <kbd.h>
#include <kbd_port.h>
#include <sun.h>
#include <sys/types.h>
#include <ddi.h>
 
83,7 → 82,7
 
static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call);
 
int z8530_port_init(void)
int kbd_port_init(void)
{
async_set_interrupt_received(z8530_irq_handler);
z8530_cmds[0].addr = (void *) sysinfo_value("kbd.address.kernel") +
95,14 → 94,6
return 0;
}
 
void z8530_port_yield(void)
{
}
 
void z8530_port_reclaim(void)
{
}
 
static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call)
{
int scan_code = IPC_GET_ARG2(*call);
/branches/dd/uspace/srv/kbd/port/sgcn.c
42,7 → 42,6
#include <sysinfo.h>
#include <stdio.h>
#include <thread.h>
#include <bool.h>
 
#define POLL_INTERVAL 10000
 
93,7 → 92,6
/* polling thread */
static void *sgcn_thread_impl(void *arg);
 
static volatile bool polling_disabled = false;
 
/**
* Initializes the SGCN driver.
122,16 → 120,6
return 0;
}
 
void kbd_port_yield(void)
{
polling_disabled = true;
}
 
void kbd_port_reclaim(void)
{
polling_disabled = false;
}
 
/**
* Handler of the "key pressed" event. Reads codes of all the pressed keys from
* the buffer.
166,11 → 154,11
(void) arg;
 
while (1) {
if (polling_disabled == false)
sgcn_key_pressed();
sgcn_key_pressed();
usleep(POLL_INTERVAL);
}
}
 
 
/** @}
*/
/branches/dd/uspace/srv/kbd/port/dummy.c
42,13 → 42,5
return 0;
}
 
void kbd_port_yield(void)
{
}
 
void kbd_port_reclaim(void)
{
}
 
/** @}
*/
/branches/dd/uspace/srv/kbd/genarch/stroke.c
31,18 → 31,17
*/
/**
* @file
* @brief Stroke simulator.
* @brief Stroke simulator.
*
* When simulating a keyboard using a serial TTY we need to convert the
* recognized strokes (such as Shift-A) to sequences of key presses and
* releases (such as 'press Shift, press A, release A, release Shift').
*
*/
 
#include <stroke.h>
#include <kbd.h>
#include <io/console.h>
#include <io/keycode.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
 
/** Correspondence between modifers and the modifier keycodes. */
static unsigned int mods_keys[][2] = {
59,7 → 58,7
i = 0;
while (mods_keys[i][0] != 0) {
if (mod & mods_keys[i][0]) {
kbd_push_ev(KEY_PRESS, mods_keys[i][1]);
kbd_push_ev(KE_PRESS, mods_keys[i][1]);
}
++i;
}
66,8 → 65,8
 
/* Simulate key press and release. */
if (key != 0) {
kbd_push_ev(KEY_PRESS, key);
kbd_push_ev(KEY_RELEASE, key);
kbd_push_ev(KE_PRESS, key);
kbd_push_ev(KE_RELEASE, key);
}
 
/* Simulate modifier releases. */
74,7 → 73,7
i = 0;
while (mods_keys[i][0] != 0) {
if (mod & mods_keys[i][0]) {
kbd_push_ev(KEY_RELEASE, mods_keys[i][1]);
kbd_push_ev(KE_RELEASE, mods_keys[i][1]);
}
++i;
}
82,4 → 81,4
 
/**
* @}
*/
*/
/branches/dd/uspace/srv/kbd/genarch/gsp.c
49,7 → 49,7
*/
 
#include <gsp.h>
#include <adt/hash_table.h>
#include <libadt/hash_table.h>
#include <stdlib.h>
#include <stdio.h>
 
244,7 → 244,7
key[0] = t->old_state;
key[1] = t->input;
 
hash_table_insert(&p->trans, key, &t->link);
hash_table_insert(&p->trans, &key, &t->link);
}
 
/** Allocate transition structure. */
276,8 → 276,7
gsp_trans_t *t;
 
t = hash_table_get_instance(item, gsp_trans_t, link);
return ((key[0] == (unsigned long) t->old_state)
&& (key[1] == (unsigned long) t->input));
return (key[0] == t->old_state && key[1] == t->input);
}
 
static void trans_op_remove_callback(link_t *item)
/branches/dd/uspace/srv/kbd/generic/keybuffer.c
File deleted
/branches/dd/uspace/srv/kbd/generic/kbd.c
28,10 → 28,10
 
/**
* @addtogroup kbdgen generic
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
*/
/** @file
*/
 
45,12 → 45,12
#include <ipc/ns.h>
#include <async.h>
#include <errno.h>
#include <adt/fifo.h>
#include <io/console.h>
#include <io/keycode.h>
#include <libadt/fifo.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
 
#include <kbd.h>
#include <keybuffer.h>
#include <key_buffer.h>
#include <kbd_port.h>
#include <kbd_ctl.h>
#include <layout.h>
70,16 → 70,6
int cir_service = 0;
int cir_phone = -1;
 
#define NUM_LAYOUTS 3
 
static layout_op_t *layout[NUM_LAYOUTS] = {
&us_qwerty_op,
&us_dvorak_op,
&cz_op
};
 
static int active_layout = 0;
 
void kbd_push_scancode(int scancode)
{
/* printf("scancode: 0x%x\n", scancode);*/
88,7 → 78,7
 
void kbd_push_ev(int type, unsigned int key)
{
console_event_t ev;
kbd_event_t ev;
unsigned mod_mask;
 
switch (key) {
102,7 → 92,7
}
 
if (mod_mask != 0) {
if (type == KEY_PRESS)
if (type == KE_PRESS)
mods = mods | mod_mask;
else
mods = mods & ~mod_mask;
116,7 → 106,7
}
 
if (mod_mask != 0) {
if (type == KEY_PRESS) {
if (type == KE_PRESS) {
/*
* Only change lock state on transition from released
* to pressed. This prevents autorepeat from messing
133,32 → 123,11
printf("mods: 0x%x\n", mods);
printf("keycode: %u\n", key);
*/
if (type == KEY_PRESS && (mods & KM_LCTRL) &&
key == KC_F1) {
active_layout = 0;
layout[active_layout]->reset();
return;
}
 
if (type == KEY_PRESS && (mods & KM_LCTRL) &&
key == KC_F2) {
active_layout = 1;
layout[active_layout]->reset();
return;
}
 
if (type == KEY_PRESS && (mods & KM_LCTRL) &&
key == KC_F3) {
active_layout = 2;
layout[active_layout]->reset();
return;
}
 
ev.type = type;
ev.key = key;
ev.mods = mods;
 
ev.c = layout[active_layout]->parse_ev(&ev);
ev.c = layout_parse_ev(&ev);
 
async_msg_4(phone2cons, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
}
193,14 → 162,6
phone2cons = IPC_GET_ARG5(call);
retval = 0;
break;
case KBD_YIELD:
kbd_port_yield();
retval = 0;
break;
case KBD_RECLAIM:
kbd_port_reclaim();
retval = 0;
break;
default:
retval = EINVAL;
}
234,9 → 195,6
/* Initialize controller driver. */
if (kbd_ctl_init() != 0)
return -1;
 
/* Initialize (reset) layout. */
layout[active_layout]->reset();
/* Initialize key buffer */
keybuffer_init(&keybuffer);
/branches/dd/uspace/srv/kbd/generic/key_buffer.c
0,0 → 1,125
/*
* Copyright (c) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdgen
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
#include <key_buffer.h>
#include <futex.h>
 
atomic_t keybuffer_futex = FUTEX_INITIALIZER;
 
/** Clear key buffer.
*/
void keybuffer_free(keybuffer_t *keybuffer)
{
futex_down(&keybuffer_futex);
keybuffer->head = 0;
keybuffer->tail = 0;
keybuffer->items = 0;
futex_up(&keybuffer_futex);
}
 
/** Key buffer initialization.
*
*/
void keybuffer_init(keybuffer_t *keybuffer)
{
keybuffer_free(keybuffer);
}
 
/** Get free space in buffer.
* This function is useful for processing some scancodes that are translated
* to more than one character.
* @return empty buffer space
*/
int keybuffer_available(keybuffer_t *keybuffer)
{
return KEYBUFFER_SIZE - keybuffer->items;
}
 
/**
* @return nonzero, if buffer is not empty.
*/
int keybuffer_empty(keybuffer_t *keybuffer)
{
return (keybuffer->items == 0);
}
 
/** Push key event to key buffer.
*
* If the buffer is full, the event is ignored.
*
* @param keybuffer The keybuffer.
* @param ev The event to push.
*/
void keybuffer_push(keybuffer_t *keybuffer, const kbd_event_t *ev)
{
futex_down(&keybuffer_futex);
if (keybuffer->items < KEYBUFFER_SIZE) {
keybuffer->fifo[keybuffer->tail] = *ev;
keybuffer->tail = (keybuffer->tail + 1) % KEYBUFFER_SIZE;
keybuffer->items++;
}
futex_up(&keybuffer_futex);
}
 
void keybuffer_push0(keybuffer_t *keybuffer, int c)
{
kbd_event_t ev;
 
ev.key = c; ev.mods = 0; ev.c = c;
keybuffer_push(keybuffer, &ev);
}
 
/** Pop event from buffer.
*
* @param edst Pointer to where the event should be saved.
* @return Zero on empty buffer, nonzero otherwise.
*/
int keybuffer_pop(keybuffer_t *keybuffer, kbd_event_t *edst)
{
futex_down(&keybuffer_futex);
if (keybuffer->items > 0) {
keybuffer->items--;
*edst = (keybuffer->fifo[keybuffer->head]) ;
keybuffer->head = (keybuffer->head + 1) % KEYBUFFER_SIZE;
futex_up(&keybuffer_futex);
return 1;
}
futex_up(&keybuffer_futex);
return 0;
}
 
/**
* @}
*/
/branches/dd/uspace/srv/kbd/Makefile
34,7 → 34,7
 
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -Iinclude
CFLAGS += -Iinclude -I../libadt/include
 
LIBS = $(LIBC_PREFIX)/libc.a
 
46,25 → 46,26
generic/kbd.c \
genarch/gsp.c \
genarch/stroke.c \
generic/keybuffer.c
generic/key_buffer.c
 
ARCH_SOURCES =
GENARCH_SOURCES = \
layout/cz.c \
layout/us_qwerty.c \
layout/us_dvorak.c
GENARCH_SOURCES =
 
ifeq ($(KBD_LAYOUT), us_qwerty)
GENARCH_SOURCES += layout/us_qwerty.c
endif
ifeq ($(KBD_LAYOUT), us_dvorak)
GENARCH_SOURCES += layout/us_dvorak.c
endif
 
ifeq ($(UARCH), amd64)
GENARCH_SOURCES += \
port/i8042.c \
ctl/pc.c
endif
 
ifeq ($(UARCH), arm32)
ifeq ($(MACHINE), testarm)
GENARCH_SOURCES += \
port/gxemul.c
ifeq ($(CONFIG_FB), y)
GENARCH_SOURCES += \
ctl/gxe_fb.c
73,41 → 74,29
ctl/stty.c
endif
endif
ifeq ($(MACHINE), integratorcp)
GENARCH_SOURCES += \
port/pl050.c \
ctl/pl050.c
endif
endif
 
ifeq ($(UARCH), ia32)
GENARCH_SOURCES += \
port/i8042.c \
ctl/pc.c
endif
 
ifeq ($(MACHINE), i460GX)
GENARCH_SOURCES += \
port/i8042.c \
ctl/pc.c
endif
 
ifeq ($(MACHINE), ski)
GENARCH_SOURCES += \
port/ski.c \
ctl/stty.c
endif
 
ifeq ($(MACHINE), msim)
GENARCH_SOURCES += \
port/msim.c \
ctl/stty.c
endif
 
ifeq ($(MACHINE), lgxemul)
GENARCH_SOURCES += \
port/gxemul.c
ifeq ($(CONFIG_FB), y)
GENARCH_SOURCES += \
ctl/gxe_fb.c
116,38 → 105,26
ctl/stty.c
endif
endif
 
ifeq ($(MACHINE), bgxemul)
GENARCH_SOURCES += \
port/gxemul.c
ifeq ($(CONFIG_FB), y)
GENARCH_SOURCES += \
ctl/gxe_fb.c
else
GENARCH_SOURCES += \
ctl/stty.c
endif
port/gxemul.c \
ctl/stty.c
endif
 
ifeq ($(UARCH), ppc32)
GENARCH_SOURCES += \
port/dummy.c \
ctl/stty.c
endif
 
ifeq ($(UARCH), sparc64)
ifeq ($(MACHINE),serengeti)
GENARCH_SOURCES += \
port/sgcn.c \
ctl/stty.c
else
GENARCH_SOURCES += \
port/sun.c \
port/z8530.c \
port/ns16550.c \
ctl/sun.c
endif
ifeq ($(MACHINE),serengeti)
GENARCH_SOURCES += \
port/sgcn.c \
ctl/stty.c
else
GENARCH_SOURCES += \
port/z8530.c \
ctl/sun.c
endif
endif
 
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
174,7 → 151,7
disasm: $(OUTPUT).disasm
 
$(OUTPUT).disasm: $(OUTPUT)
$(OBJDUMP) -d $< > $@
$(OBJDUMP) -d $< >$@
 
%.o: %.S
$(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
/branches/dd/uspace/srv/kbd/layout/cz.c
File deleted
/branches/dd/uspace/srv/kbd/layout/us_dvorak.c
32,19 → 32,11
*/
 
#include <kbd.h>
#include <io/console.h>
#include <io/keycode.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <layout.h>
 
static void layout_reset(void);
static wchar_t layout_parse_ev(console_event_t *ev);
 
layout_op_t us_dvorak_op = {
layout_reset,
layout_parse_ev
};
 
static wchar_t map_lcase[] = {
static char map_lcase[] = {
[KC_R] = 'p',
[KC_T] = 'y',
[KC_Y] = 'f',
77,7 → 69,7
[KC_SLASH] = 'z',
};
 
static wchar_t map_ucase[] = {
static char map_ucase[] = {
[KC_R] = 'P',
[KC_T] = 'Y',
[KC_Y] = 'F',
110,7 → 102,7
[KC_SLASH] = 'Z',
};
 
static wchar_t map_not_shifted[] = {
static char map_not_shifted[] = {
[KC_BACKTICK] = '`',
 
[KC_1] = '1',
140,7 → 132,7
[KC_Z] = ';',
};
 
static wchar_t map_shifted[] = {
static char map_shifted[] = {
[KC_BACKTICK] = '~',
 
[KC_1] = '!',
170,7 → 162,7
[KC_Z] = ':',
};
 
static wchar_t map_neutral[] = {
static char map_neutral[] = {
[KC_BACKSPACE] = '\b',
[KC_TAB] = '\t',
[KC_ENTER] = '\n',
183,7 → 175,7
[KC_NENTER] = '\n'
};
 
static wchar_t map_numeric[] = {
static char map_numeric[] = {
[KC_N7] = '7',
[KC_N8] = '8',
[KC_N9] = '9',
198,7 → 190,7
[KC_NPERIOD] = '.'
};
 
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
static int translate(unsigned int key, char *map, size_t map_length)
{
if (key >= map_length)
return 0;
205,40 → 197,36
return map[key];
}
 
static void layout_reset(void)
char layout_parse_ev(kbd_event_t *ev)
{
}
char c;
 
static wchar_t layout_parse_ev(console_event_t *ev)
{
wchar_t c;
 
/* Produce no characters when Ctrl or Alt is pressed. */
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
return 0;
 
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char));
if (c != 0)
return c;
 
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char));
else
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char));
 
if (c != 0)
return c;
 
if ((ev->mods & KM_SHIFT) != 0)
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char));
else
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char));
 
if (c != 0)
return c;
 
if ((ev->mods & KM_NUM_LOCK) != 0)
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char));
else
c = 0;
 
/branches/dd/uspace/srv/kbd/layout/us_qwerty.c
27,24 → 27,16
*/
 
/** @addtogroup kbd
* @brief US QWERTY layout.
* @brief US QWERTY leyout.
* @{
*/
 
#include <kbd.h>
#include <io/console.h>
#include <io/keycode.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <layout.h>
 
static void layout_reset(void);
static wchar_t layout_parse_ev(console_event_t *ev);
 
layout_op_t us_qwerty_op = {
layout_reset,
layout_parse_ev
};
 
static wchar_t map_lcase[] = {
static char map_lcase[] = {
[KC_Q] = 'q',
[KC_W] = 'w',
[KC_E] = 'e',
75,7 → 67,7
[KC_M] = 'm',
};
 
static wchar_t map_ucase[] = {
static char map_ucase[] = {
[KC_Q] = 'Q',
[KC_W] = 'W',
[KC_E] = 'E',
106,7 → 98,7
[KC_M] = 'M',
};
 
static wchar_t map_not_shifted[] = {
static char map_not_shifted[] = {
[KC_BACKTICK] = '`',
 
[KC_1] = '1',
135,7 → 127,7
[KC_SLASH] = '/',
};
 
static wchar_t map_shifted[] = {
static char map_shifted[] = {
[KC_BACKTICK] = '~',
 
[KC_1] = '!',
164,7 → 156,7
[KC_SLASH] = '?',
};
 
static wchar_t map_neutral[] = {
static char map_neutral[] = {
[KC_BACKSPACE] = '\b',
[KC_TAB] = '\t',
[KC_ENTER] = '\n',
177,7 → 169,7
[KC_NENTER] = '\n'
};
 
static wchar_t map_numeric[] = {
static char map_numeric[] = {
[KC_N7] = '7',
[KC_N8] = '8',
[KC_N9] = '9',
192,47 → 184,39
[KC_NPERIOD] = '.'
};
 
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
static int translate(unsigned int key, char *map, size_t map_length)
{
if (key >= map_length)
return 0;
return map[key];
if (key >= map_length) return 0;
return map[key];
}
 
static void layout_reset(void)
char layout_parse_ev(kbd_event_t *ev)
{
}
char c;
 
static wchar_t layout_parse_ev(console_event_t *ev)
{
wchar_t c;
 
/* Produce no characters when Ctrl or Alt is pressed. */
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
return 0;
 
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
if (c != 0)
return c;
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char));
if (c != 0) return c;
 
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char));
else
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char));
 
if (c != 0)
return c;
if (c != 0) return c;
 
if ((ev->mods & KM_SHIFT) != 0)
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char));
else
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char));
 
if (c != 0)
return c;
if (c != 0) return c;
 
if ((ev->mods & KM_NUM_LOCK) != 0)
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char));
else
c = 0;