diff options
-rw-r--r-- | firmware/drivers/button.c | 232 |
1 files changed, 108 insertions, 124 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 00b9dc4e50..e3998ae8a5 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -58,16 +58,13 @@ static bool remote_filter_first_keypress; | |||
58 | #endif | 58 | #endif |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | /* how often we check to see if a button is pressed */ | 61 | /* how long until repeat kicks in, in ticks */ |
62 | #define POLL_FREQUENCY HZ/100 | ||
63 | |||
64 | /* how long until repeat kicks in */ | ||
65 | #define REPEAT_START 30 | 62 | #define REPEAT_START 30 |
66 | 63 | ||
67 | /* the speed repeat starts at */ | 64 | /* the speed repeat starts at, in ticks */ |
68 | #define REPEAT_INTERVAL_START 16 | 65 | #define REPEAT_INTERVAL_START 16 |
69 | 66 | ||
70 | /* speed repeat finishes at */ | 67 | /* speed repeat finishes at, in ticks */ |
71 | #define REPEAT_INTERVAL_FINISH 5 | 68 | #define REPEAT_INTERVAL_FINISH 5 |
72 | 69 | ||
73 | /* the power-off button and number of repeated keys before shutting off */ | 70 | /* the power-off button and number of repeated keys before shutting off */ |
@@ -397,7 +394,6 @@ static int ipod_3g_button_read(void) | |||
397 | 394 | ||
398 | static void button_tick(void) | 395 | static void button_tick(void) |
399 | { | 396 | { |
400 | static int tick = 0; | ||
401 | static int count = 0; | 397 | static int count = 0; |
402 | static int repeat_speed = REPEAT_INTERVAL_START; | 398 | static int repeat_speed = REPEAT_INTERVAL_START; |
403 | static int repeat_count = 0; | 399 | static int repeat_count = 0; |
@@ -422,165 +418,153 @@ static void button_tick(void) | |||
422 | } | 418 | } |
423 | #endif | 419 | #endif |
424 | 420 | ||
425 | /* only poll every X ticks */ | 421 | btn = button_read(); |
426 | if ( ++tick >= POLL_FREQUENCY ) | ||
427 | { | ||
428 | btn = button_read(); | ||
429 | 422 | ||
430 | /* Find out if a key has been released */ | 423 | /* Find out if a key has been released */ |
431 | diff = btn ^ lastbtn; | 424 | diff = btn ^ lastbtn; |
432 | if(diff && (btn & diff) == 0) | 425 | if(diff && (btn & diff) == 0) |
433 | { | 426 | { |
434 | #ifdef CONFIG_BACKLIGHT | 427 | #ifdef CONFIG_BACKLIGHT |
435 | #ifdef HAVE_REMOTE_LCD | 428 | #ifdef HAVE_REMOTE_LCD |
436 | if(diff & BUTTON_REMOTE) | 429 | if(diff & BUTTON_REMOTE) |
437 | if(!skip_remote_release) | 430 | if(!skip_remote_release) |
438 | queue_post(&button_queue, BUTTON_REL | diff, NULL); | 431 | queue_post(&button_queue, BUTTON_REL | diff, NULL); |
439 | else | ||
440 | skip_remote_release = false; | ||
441 | else | 432 | else |
433 | skip_remote_release = false; | ||
434 | else | ||
442 | #endif | 435 | #endif |
443 | if(!skip_release) | 436 | if(!skip_release) |
444 | queue_post(&button_queue, BUTTON_REL | diff, NULL); | 437 | queue_post(&button_queue, BUTTON_REL | diff, NULL); |
445 | else | 438 | else |
446 | skip_release = false; | 439 | skip_release = false; |
447 | #else | 440 | #else |
448 | queue_post(&button_queue, BUTTON_REL | diff, NULL); | 441 | queue_post(&button_queue, BUTTON_REL | diff, NULL); |
449 | #endif | 442 | #endif |
450 | } | 443 | } |
451 | else | 444 | else |
445 | { | ||
446 | if ( btn ) | ||
452 | { | 447 | { |
453 | if ( btn ) | 448 | /* normal keypress */ |
449 | if ( btn != lastbtn ) | ||
454 | { | 450 | { |
455 | /* normal keypress */ | 451 | post = true; |
456 | if ( btn != lastbtn ) | 452 | repeat = false; |
457 | { | 453 | repeat_speed = REPEAT_INTERVAL_START; |
458 | post = true; | 454 | } |
459 | repeat = false; | 455 | else /* repeat? */ |
460 | repeat_speed = REPEAT_INTERVAL_START; | 456 | { |
461 | 457 | if ( repeat ) | |
462 | } | ||
463 | else /* repeat? */ | ||
464 | { | 458 | { |
465 | if ( repeat ) | 459 | if (!post) |
466 | { | 460 | count--; |
467 | if (!post) | 461 | if (count == 0) { |
468 | count--; | 462 | post = true; |
469 | if (count == 0) { | 463 | /* yes we have repeat */ |
470 | post = true; | 464 | if (repeat_speed > REPEAT_INTERVAL_FINISH) |
471 | /* yes we have repeat */ | ||
472 | repeat_speed--; | 465 | repeat_speed--; |
473 | if (repeat_speed < REPEAT_INTERVAL_FINISH) | 466 | count = repeat_speed; |
474 | repeat_speed = REPEAT_INTERVAL_FINISH; | ||
475 | count = repeat_speed; | ||
476 | 467 | ||
477 | repeat_count++; | 468 | repeat_count++; |
478 | 469 | ||
479 | /* Send a SYS_POWEROFF event if we have a device | 470 | /* Send a SYS_POWEROFF event if we have a device |
480 | which doesn't shut down easily with the OFF | 471 | which doesn't shut down easily with the OFF |
481 | key */ | 472 | key */ |
482 | #ifdef HAVE_SW_POWEROFF | 473 | #ifdef HAVE_SW_POWEROFF |
483 | if ((btn == POWEROFF_BUTTON | 474 | if ((btn == POWEROFF_BUTTON |
484 | #ifdef BUTTON_RC_STOP | 475 | #ifdef BUTTON_RC_STOP |
485 | || btn == BUTTON_RC_STOP | 476 | || btn == BUTTON_RC_STOP |
486 | #endif | 477 | #endif |
487 | ) && | 478 | ) && |
488 | #if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) | 479 | #if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) |
489 | !charger_inserted() && | 480 | !charger_inserted() && |
490 | #endif | ||
491 | repeat_count > POWEROFF_COUNT) | ||
492 | { | ||
493 | /* Tell the main thread that it's time to | ||
494 | power off */ | ||
495 | sys_poweroff(); | ||
496 | |||
497 | /* Safety net for players without hardware | ||
498 | poweroff */ | ||
499 | if(repeat_count > POWEROFF_COUNT * 10) | ||
500 | power_off(); | ||
501 | } | ||
502 | #endif | 481 | #endif |
482 | repeat_count > POWEROFF_COUNT) | ||
483 | { | ||
484 | /* Tell the main thread that it's time to | ||
485 | power off */ | ||
486 | sys_poweroff(); | ||
487 | |||
488 | /* Safety net for players without hardware | ||
489 | poweroff */ | ||
490 | if(repeat_count > POWEROFF_COUNT * 10) | ||
491 | power_off(); | ||
503 | } | 492 | } |
493 | #endif | ||
504 | } | 494 | } |
505 | else | 495 | } |
496 | else | ||
497 | { | ||
498 | if (count++ > REPEAT_START) | ||
506 | { | 499 | { |
507 | if (count++ > REPEAT_START) | 500 | post = true; |
508 | { | 501 | repeat = true; |
509 | post = true; | 502 | repeat_count = 0; |
510 | repeat = true; | 503 | /* initial repeat */ |
511 | repeat_count = 0; | 504 | count = REPEAT_INTERVAL_START; |
512 | /* initial repeat */ | ||
513 | count = REPEAT_INTERVAL_START; | ||
514 | } | ||
515 | } | 505 | } |
516 | } | 506 | } |
517 | if ( post ) | 507 | } |
508 | if ( post ) | ||
509 | { | ||
510 | if (repeat) | ||
518 | { | 511 | { |
519 | if (repeat) | 512 | /* Only post repeat events if the queue is empty, |
513 | * to avoid afterscroll effects. */ | ||
514 | if (queue_empty(&button_queue)) | ||
520 | { | 515 | { |
521 | if (queue_empty(&button_queue)) | 516 | queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); |
522 | { | ||
523 | queue_post( | ||
524 | &button_queue, BUTTON_REPEAT | btn, NULL); | ||
525 | #ifdef CONFIG_BACKLIGHT | 517 | #ifdef CONFIG_BACKLIGHT |
526 | #ifdef HAVE_REMOTE_LCD | 518 | #ifdef HAVE_REMOTE_LCD |
527 | if(btn & BUTTON_REMOTE) | 519 | skip_remote_release = false; |
528 | { | ||
529 | if(skip_remote_release) | ||
530 | skip_remote_release = false; | ||
531 | } | ||
532 | else | ||
533 | #endif | ||
534 | if(skip_release) | ||
535 | skip_release = false; | ||
536 | #endif | 520 | #endif |
537 | post = false; | 521 | skip_release = false; |
538 | } | 522 | #endif |
523 | post = false; | ||
539 | } | 524 | } |
540 | else | 525 | } |
541 | { | 526 | else |
527 | { | ||
542 | #ifdef CONFIG_BACKLIGHT | 528 | #ifdef CONFIG_BACKLIGHT |
543 | #ifdef HAVE_REMOTE_LCD | 529 | #ifdef HAVE_REMOTE_LCD |
544 | if (btn & BUTTON_REMOTE) { | 530 | if (btn & BUTTON_REMOTE) { |
545 | if (!remote_filter_first_keypress || is_remote_backlight_on() | 531 | if (!remote_filter_first_keypress || is_remote_backlight_on() |
546 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | 532 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) |
547 | ||(remote_type()==REMOTETYPE_H300_NONLCD) | 533 | || (remote_type()==REMOTETYPE_H300_NONLCD) |
548 | #endif | 534 | #endif |
549 | ) | 535 | ) |
550 | queue_post(&button_queue, btn, NULL); | 536 | queue_post(&button_queue, btn, NULL); |
551 | else | ||
552 | skip_remote_release = true; | ||
553 | } | ||
554 | else | 537 | else |
555 | #endif | 538 | skip_remote_release = true; |
556 | if (!filter_first_keypress || is_backlight_on()) | 539 | } |
557 | queue_post(&button_queue, btn, NULL); | 540 | else |
558 | else | 541 | #endif |
559 | skip_release = true; | 542 | if (!filter_first_keypress || is_backlight_on()) |
543 | queue_post(&button_queue, btn, NULL); | ||
544 | else | ||
545 | skip_release = true; | ||
560 | #else /* no backlight, nothing to skip */ | 546 | #else /* no backlight, nothing to skip */ |
561 | queue_post(&button_queue, btn, NULL); | 547 | queue_post(&button_queue, btn, NULL); |
562 | #endif | 548 | #endif |
563 | post = false; | 549 | post = false; |
564 | } | 550 | } |
565 | #ifdef HAVE_REMOTE_LCD | 551 | #ifdef HAVE_REMOTE_LCD |
566 | if(btn & BUTTON_REMOTE) | 552 | if(btn & BUTTON_REMOTE) |
567 | remote_backlight_on(); | 553 | remote_backlight_on(); |
568 | else | 554 | else |
569 | #endif | 555 | #endif |
570 | backlight_on(); | 556 | backlight_on(); |
571 | 557 | ||
572 | reset_poweroff_timer(); | 558 | reset_poweroff_timer(); |
573 | } | ||
574 | } | ||
575 | else | ||
576 | { | ||
577 | repeat = false; | ||
578 | count = 0; | ||
579 | } | 559 | } |
580 | } | 560 | } |
581 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); | 561 | else |
582 | tick = 0; | 562 | { |
563 | repeat = false; | ||
564 | count = 0; | ||
565 | } | ||
583 | } | 566 | } |
567 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); | ||
584 | } | 568 | } |
585 | 569 | ||
586 | long button_get(bool block) | 570 | long button_get(bool block) |