/*
* Copyright (c) 2001-2004 Jakub Jermar
* Copyright (c) 2006 Josef Cejka
* Copyright (c) 2009 Vineeth Pillai
* 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 kbdarm32 arm32
* @brief HelenOS arm32/integratorcp arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
* @ingroup kbdarm32
*/
#include <stdio.h>
#include <arch/kbd.h>
#include <ipc/ipc.h>
#include <unistd.h>
#include <kbd.h>
#include <arch/pl050.h>
#include <keys.h>
#include <genarch/kbd.h>
#include <sysinfo.h>
#include <as.h>
#include <ipc/ipc.h>
#include <ipc/ns.h>
#include <ipc/services.h>
#include <ddi.h>
#include <align.h>
#define PL050_KEY_RELEASE 0xF0
#define PL050_ESC_KEY 0xE0
#define PL050_CAPS_SCAN_CODE 0x58
irq_cmd_t pl050_cmds[] = {
{ CMD_MEM_READ_1, (void *) 0, 0, 1 },
{ CMD_MEM_READ_1, (void *) 0, 0, 2}
};
irq_code_t pl050_kbd = {
2,
pl050_cmds
};
static void *kbd_physaddr;
static void *kbd_addr;
/** Register uspace irq handler
* @return
*/
int kbd_arch_init(void)
{
kbd_physaddr = (void *)sysinfo_value("kbd.pbase");
kbd_addr = (void*)sysinfo_value("kbd.vbase");
pl050_cmds[0].addr = (void *)(kbd_addr+PL050_DATA);
pl050_cmds[1].addr = (void *)(kbd_addr+PL050_STAT);
/* Enable kbd */
ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &pl050_kbd);
return 0;
}
/** Process keyboard & mouse events */
int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
{
static int key_released_flag = 0;
static int caps_locked = 0;
int scan_code = IPC_GET_ARG1(*call);
if (scan_code == PL050_KEY_RELEASE) {
key_released_flag = 1;
} else {
if (key_released_flag) {
key_released_flag = 0;
if (scan_code == PL050_CAPS_SCAN_CODE) {
if (caps_locked) {
caps_locked = 0;
return 1;
} else
caps_locked = 1;
}
key_released(keybuffer, scan_code);
} else {
if (scan_code == PL050_CAPS_SCAN_CODE && caps_locked)
return 1;
key_pressed(keybuffer, scan_code);
}
}
return 1;
}
/**
* @}
*/