From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JxLJJ-00007b-RP for qemu-devel@nongnu.org; Sat, 17 May 2008 08:14:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JxLJI-000078-Ge for qemu-devel@nongnu.org; Sat, 17 May 2008 08:14:49 -0400 Received: from [199.232.76.173] (port=45399 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JxLJI-000070-8p for qemu-devel@nongnu.org; Sat, 17 May 2008 08:14:48 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:42172) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JxLJH-00088l-TN for qemu-devel@nongnu.org; Sat, 17 May 2008 08:14:48 -0400 Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate02.web.de (Postfix) with ESMTP id 2A025DCE4BEA for ; Sat, 17 May 2008 14:14:47 +0200 (CEST) Received: from [88.64.29.150] (helo=[192.168.1.198]) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1JxLJH-0001CP-00 for qemu-devel@nongnu.org; Sat, 17 May 2008 14:14:47 +0200 Message-ID: <482ECC36.9080501@web.de> Date: Sat, 17 May 2008 14:14:46 +0200 From: Jan Kiszka MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Sender: jan.kiszka@web.de Subject: [Qemu-devel] [PATCH] musicpal: Improve button handling Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Looking at the hold-button-on-powerup thing, I came across some improvable parts in the MusicPal's button handling. This patch allows for repeated wheel events by keying the arrow keys pressed, corrects some constant name, and introduces an explicitly maintained GPIO_ISR state. Signed-off-by: Jan Kiszka --- hw/musicpal.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) Index: b/hw/musicpal.c =================================================================== --- a/hw/musicpal.c +++ b/hw/musicpal.c @@ -59,6 +59,7 @@ #define MP_AUDIO_IRQ 30 static uint32_t gpio_in_state = 0xffffffff; +static uint32_t gpio_isr; static uint32_t gpio_out_state; static ram_addr_t sram_off; @@ -1280,11 +1281,10 @@ static uint32_t musicpal_read(void *opaq (i2c_get_data(mixer_i2c) << MP_GPIO_I2C_DATA_BIT); return gpio_in_state >> 16; - /* This is a simplification of reality */ case MP_GPIO_ISR_LO: - return ~gpio_in_state & 0xFFFF; + return gpio_isr & 0xFFFF; case MP_GPIO_ISR_HI: - return ~gpio_in_state >> 16; + return gpio_isr >> 16; /* Workaround to allow loading the binary-only wlandrv.ko crap * from the original Freecom firmware. */ @@ -1324,7 +1324,7 @@ static void musicpal_write(void *opaque, } /* Keyboard codes & masks */ -#define KEY_PRESSED 0x80 +#define KEY_RELEASED 0x80 #define KEY_CODE 0x7f #define KEYCODE_TAB 0x0f @@ -1367,7 +1367,7 @@ static void musicpal_key_event(void *opa event = MP_GPIO_WHEEL_VOL; break; } - else + else { switch (keycode & KEY_CODE) { case KEYCODE_F: event = MP_GPIO_BTN_FAVORITS; @@ -1385,12 +1385,19 @@ static void musicpal_key_event(void *opa event = MP_GPIO_BTN_MENU; break; } + /* Do not repeat already pressed buttons */ + if (!(keycode & KEY_RELEASED) && !(gpio_in_state & event)) + event = 0; + } - if (keycode & KEY_PRESSED) - gpio_in_state |= event; - else if (gpio_in_state & event) { - gpio_in_state &= ~event; - qemu_irq_raise(irq); + if (event) { + if (keycode & KEY_RELEASED) { + gpio_in_state |= event; + } else { + gpio_in_state &= ~event; + gpio_isr = event; + qemu_irq_raise(irq); + } } kbd_extended = 0;