Commit 7c6ce4baedfcd0c39250f313926ef61dcb47d74c

Authored by balrog
1 parent 4aa9aca4

musicpal: Improve button handling (Jan Kiszka).

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 <jan.kiszka@web.de>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4476 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 17 additions and 10 deletions
hw/musicpal.c
@@ -59,6 +59,7 @@ @@ -59,6 +59,7 @@
59 #define MP_AUDIO_IRQ 30 59 #define MP_AUDIO_IRQ 30
60 60
61 static uint32_t gpio_in_state = 0xffffffff; 61 static uint32_t gpio_in_state = 0xffffffff;
  62 +static uint32_t gpio_isr;
62 static uint32_t gpio_out_state; 63 static uint32_t gpio_out_state;
63 static ram_addr_t sram_off; 64 static ram_addr_t sram_off;
64 65
@@ -1280,11 +1281,10 @@ static uint32_t musicpal_read(void *opaque, target_phys_addr_t offset) @@ -1280,11 +1281,10 @@ static uint32_t musicpal_read(void *opaque, target_phys_addr_t offset)
1280 (i2c_get_data(mixer_i2c) << MP_GPIO_I2C_DATA_BIT); 1281 (i2c_get_data(mixer_i2c) << MP_GPIO_I2C_DATA_BIT);
1281 return gpio_in_state >> 16; 1282 return gpio_in_state >> 16;
1282 1283
1283 - /* This is a simplification of reality */  
1284 case MP_GPIO_ISR_LO: 1284 case MP_GPIO_ISR_LO:
1285 - return ~gpio_in_state & 0xFFFF; 1285 + return gpio_isr & 0xFFFF;
1286 case MP_GPIO_ISR_HI: 1286 case MP_GPIO_ISR_HI:
1287 - return ~gpio_in_state >> 16; 1287 + return gpio_isr >> 16;
1288 1288
1289 /* Workaround to allow loading the binary-only wlandrv.ko crap 1289 /* Workaround to allow loading the binary-only wlandrv.ko crap
1290 * from the original Freecom firmware. */ 1290 * from the original Freecom firmware. */
@@ -1324,7 +1324,7 @@ static void musicpal_write(void *opaque, target_phys_addr_t offset, @@ -1324,7 +1324,7 @@ static void musicpal_write(void *opaque, target_phys_addr_t offset,
1324 } 1324 }
1325 1325
1326 /* Keyboard codes & masks */ 1326 /* Keyboard codes & masks */
1327 -#define KEY_PRESSED 0x80 1327 +#define KEY_RELEASED 0x80
1328 #define KEY_CODE 0x7f 1328 #define KEY_CODE 0x7f
1329 1329
1330 #define KEYCODE_TAB 0x0f 1330 #define KEYCODE_TAB 0x0f
@@ -1367,7 +1367,7 @@ static void musicpal_key_event(void *opaque, int keycode) @@ -1367,7 +1367,7 @@ static void musicpal_key_event(void *opaque, int keycode)
1367 event = MP_GPIO_WHEEL_VOL; 1367 event = MP_GPIO_WHEEL_VOL;
1368 break; 1368 break;
1369 } 1369 }
1370 - else 1370 + else {
1371 switch (keycode & KEY_CODE) { 1371 switch (keycode & KEY_CODE) {
1372 case KEYCODE_F: 1372 case KEYCODE_F:
1373 event = MP_GPIO_BTN_FAVORITS; 1373 event = MP_GPIO_BTN_FAVORITS;
@@ -1385,12 +1385,19 @@ static void musicpal_key_event(void *opaque, int keycode) @@ -1385,12 +1385,19 @@ static void musicpal_key_event(void *opaque, int keycode)
1385 event = MP_GPIO_BTN_MENU; 1385 event = MP_GPIO_BTN_MENU;
1386 break; 1386 break;
1387 } 1387 }
  1388 + /* Do not repeat already pressed buttons */
  1389 + if (!(keycode & KEY_RELEASED) && !(gpio_in_state & event))
  1390 + event = 0;
  1391 + }
1388 1392
1389 - if (keycode & KEY_PRESSED)  
1390 - gpio_in_state |= event;  
1391 - else if (gpio_in_state & event) {  
1392 - gpio_in_state &= ~event;  
1393 - qemu_irq_raise(irq); 1393 + if (event) {
  1394 + if (keycode & KEY_RELEASED) {
  1395 + gpio_in_state |= event;
  1396 + } else {
  1397 + gpio_in_state &= ~event;
  1398 + gpio_isr = event;
  1399 + qemu_irq_raise(irq);
  1400 + }
1394 } 1401 }
1395 1402
1396 kbd_extended = 0; 1403 kbd_extended = 0;