on behalf of Stefano Ceccherini on holidays !

keyboard driver started to work (I was able to type something), though it needs more work, as keyup events for extended keys are screwed. The specs I got don't seem to apply to my keyboard.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9171 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2004-10-03 22:39:45 +00:00
parent 96008894d9
commit 297f444091
1 changed files with 28 additions and 15 deletions

View File

@ -9,15 +9,15 @@
#include <OS.h>
#include <ISA.h>
#include <cbuf.h>
#include "cbuf_adapter.h"
#include <string.h>
#include <lock.h>
//#include <lock.h>
#include <kb_mouse_driver.h>
#include "kb_mouse_driver.h"
#define DEVICE_NAME "input/keyboard/at/0"
#define TRACE_KEYBOARD 0
#define TRACE_KEYBOARD 1
#if TRACE_KEYBOARD
# define TRACE(x) dprintf x
#else
@ -32,7 +32,7 @@
int32 api_version = B_CUR_DRIVER_API_VERSION;
static sem_id keyboard_sem;
static mutex keyboard_read_mutex;
//static mutex keyboard_read_mutex;
static cbuf *keyboard_buf;
static isa_module_info *sIsa;
static at_kbd_io sKeyInfo;
@ -78,16 +78,16 @@ handle_keyboard_interrupt(void *data)
return B_HANDLED_INTERRUPT;
}
if (key == 0xF0) {
if (key & 0x80) {
sKeyInfo.is_keydown = false;
return B_HANDLED_INTERRUPT;
}
sKeyInfo.timestamp = system_time();
sKeyInfo.scancode = key;
// TODO: Check return value
cbuf_memcpy_to_chain(keyboard_buf, 0, &sKeyInfo, sizeof(sKeyInfo));
cbuf_memcpy_to_chain(keyboard_buf, 0, (void *)&sKeyInfo, sizeof(sKeyInfo));
release_sem_etc(keyboard_sem, 1, B_DO_NOT_RESCHEDULE);
// Reset this so the next event defaults to keydown
@ -105,10 +105,11 @@ read_keyboard_packet(at_kbd_io *buffer)
if (status < B_OK)
return status;
status = cbuf_memcpy_from_chain(buffer, keyboard_buf, 0, sizeof(at_kbd_io));
status = cbuf_memcpy_from_chain((void *)buffer, keyboard_buf, 0, sizeof(at_kbd_io));
if (status < B_OK)
TRACE(("read_keyboard_packet(): error reading packet: %s\n", strerror(status)));
TRACE(("scancode: %x, keydown: %s\n", buffer->scancode, buffer->is_keydown ? "true" : "false"));
return status;
}
@ -119,6 +120,7 @@ read_keyboard_packet(at_kbd_io *buffer)
static status_t
keyboard_open(const char *name, uint32 flags, void **cookie)
{
TRACE(("keyboard open()\n"));
if (atomic_or(&sOpenMask, 1) != 0)
return B_BUSY;
@ -130,7 +132,7 @@ keyboard_open(const char *name, uint32 flags, void **cookie)
static status_t
keyboard_close(void *cookie)
{
atomic_and(&sOpenMask);
atomic_and(&sOpenMask, 0);
return B_OK;
}
@ -145,6 +147,7 @@ keyboard_freecookie(void *cookie)
static status_t
keyboard_read(void *cookie, off_t pos, void *buffer, size_t *_length)
{
TRACE(("keyboard read()\n"));
*_length = 0;
return EROFS;
}
@ -153,6 +156,7 @@ keyboard_read(void *cookie, off_t pos, void *buffer, size_t *_length)
static status_t
keyboard_write(void *cookie, off_t pos, const void *buf, size_t *len)
{
TRACE(("keyboard write()\n"));
*len = 0;
return EROFS;
}
@ -161,13 +165,21 @@ keyboard_write(void *cookie, off_t pos, const void *buf, size_t *len)
static status_t
keyboard_ioctl(void *cookie, uint32 op, void *buf, size_t len)
{
TRACE(("keyboard ioctl()\n"));
switch (op) {
case KB_READ:
TRACE(("KB_READ\n"));
return read_keyboard_packet((at_kbd_io *)buf);
case KB_SET_LEDS:
set_leds((led_info *)buf);
TRACE(("KB_SET_LEDS\n"));
return B_OK;
case KB_SET_KEY_REPEATING:
case KB_SET_KEY_NONREPEATING:
TRACE(("ioctl 0x%x not implemented yet, returning B_OK\n", op));
return B_OK;
default:
TRACE(("invalid ioctl 0x%x\n", op));
return EINVAL;
}
}
@ -223,6 +235,7 @@ find_device(const char *name)
status_t
init_driver()
{
TRACE(("keyboard: init_driver()\n"));
if (get_module(B_ISA_MODULE_NAME, (module_info **)&sIsa) < B_OK)
panic("could not get ISA module\n");
@ -230,14 +243,14 @@ init_driver()
if (keyboard_sem < 0)
panic("could not create keyboard sem!\n");
if (mutex_init(&keyboard_read_mutex, "keyboard_read_mutex") < 0)
panic("could not create keyboard read mutex!\n");
//if (mutex_init(&keyboard_read_mutex, "keyboard_read_mutex") < 0)
// panic("could not create keyboard read mutex!\n");
keyboard_buf = cbuf_get_chain(1024);
if (keyboard_buf == NULL)
panic("could not create keyboard cbuf chain!\n");
install_io_interrupt_handler(0x01, &handle_keyboard_interrupt, NULL, 0);
install_io_interrupt_handler(1, &handle_keyboard_interrupt, NULL, 0);
sKeyInfo.is_keydown = true;
@ -250,11 +263,11 @@ init_driver()
void
uninit_driver()
{
remove_io_interrupt_handler(0x01, &handle_keyboard_interrupt, NULL);
remove_io_interrupt_handler(1, &handle_keyboard_interrupt, NULL);
cbuf_free_chain(keyboard_buf);
delete_sem(keyboard_sem);
mutex_destroy(&keyboard_read_mutex);
//mutex_destroy(&keyboard_read_mutex);
put_module(B_ISA_MODULE_NAME);
}