mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
Luminary board input support.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3689 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
f090c9d4ad
commit
cf0dbb2115
5 changed files with 102 additions and 7 deletions
66
hw/stellaris_input.c
Normal file
66
hw/stellaris_input.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Gamepad style buttons connected to IRQ/GPIO lines
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
* Written by Paul Brook
|
||||
*
|
||||
* This code is licenced under the GPL.
|
||||
*/
|
||||
#include "hw.h"
|
||||
#include "devices.h"
|
||||
#include "console.h"
|
||||
|
||||
typedef struct {
|
||||
qemu_irq irq;
|
||||
int keycode;
|
||||
int pressed;
|
||||
} gamepad_button;
|
||||
|
||||
typedef struct {
|
||||
gamepad_button *buttons;
|
||||
int num_buttons;
|
||||
int extension;
|
||||
} gamepad_state;
|
||||
|
||||
static void stellaris_gamepad_put_key(void * opaque, int keycode)
|
||||
{
|
||||
gamepad_state *s = (gamepad_state *)opaque;
|
||||
int i;
|
||||
int down;
|
||||
|
||||
if (keycode == 0xe0 && !s->extension) {
|
||||
s->extension = 0x80;
|
||||
return;
|
||||
}
|
||||
|
||||
down = (keycode & 0x80) == 0;
|
||||
keycode = (keycode & 0x7f) | s->extension;
|
||||
|
||||
for (i = 0; i < s->num_buttons; i++) {
|
||||
if (s->buttons[i].keycode == keycode
|
||||
&& s->buttons[i].pressed != down) {
|
||||
s->buttons[i].pressed = down;
|
||||
qemu_set_irq(s->buttons[i].irq, down);
|
||||
}
|
||||
}
|
||||
|
||||
s->extension = 0;
|
||||
}
|
||||
|
||||
/* Returns an array 5 ouput slots. */
|
||||
void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)
|
||||
{
|
||||
gamepad_state *s;
|
||||
int i;
|
||||
|
||||
s = (gamepad_state *)qemu_mallocz(sizeof (gamepad_state));
|
||||
s->buttons = (gamepad_button *)qemu_mallocz(n * sizeof (gamepad_button));
|
||||
for (i = 0; i < n; i++) {
|
||||
s->buttons[i].irq = irq[i];
|
||||
s->buttons[i].keycode = keycode[i];
|
||||
}
|
||||
s->num_buttons = n;
|
||||
qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s);
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue