summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-01-27 21:13:04 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-01-27 21:13:04 +0000
commit0efdd7a5f74c955d0eb604cd3fef9069be57bcbb (patch)
tree3da7c91ca05c154a31564c0045308256c206b1fd
parent637e26e8e4c87e25bcdc5f6793b86d34061e7aae (diff)
downloadrockbox-0efdd7a5f74c955d0eb604cd3fef9069be57bcbb.zip
rockbox-0efdd7a5f74c955d0eb604cd3fef9069be57bcbb.tar.gz
rockbox-0efdd7a5f74c955d0eb604cd3fef9069be57bcbb.tar.bz2
rockbox-0efdd7a5f74c955d0eb604cd3fef9069be57bcbb.tar.xz
Use the timeout API as a oneshot for headphone plug debouncing. Set at 1s for now which seems comfortable and was good for meg-fx but target-specific adjustment is easy enough (my 3G hp jack is dead so I can't check that one :( ). Do some minor rearrangements for init safety and consistency.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16178 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/button.c52
-rw-r--r--firmware/export/config.h7
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c19
3 files changed, 48 insertions, 30 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 33b708e..b9473be 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -61,7 +61,7 @@ static bool remote_filter_first_keypress;
#endif
#endif /* HAVE_BACKLIGHT */
#ifdef HAVE_HEADPHONE_DETECTION
-bool phones_present = false;
+static bool phones_present = false;
#endif
/* how long until repeat kicks in, in ticks */
@@ -79,6 +79,20 @@ static int button_read(int *data);
static int button_read(void);
#endif
+#if defined(HAVE_HEADPHONE_DETECTION)
+static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */
+/* This callback can be used for many different functions if needed -
+ just check to which object tmo points */
+static bool btn_detect_callback(struct timeout *tmo)
+{
+ /* Try to post only transistions */
+ const long id = tmo->data ? SYS_PHONE_PLUGGED : SYS_PHONE_UNPLUGGED;
+ queue_remove_from_head(&button_queue, id);
+ queue_post(&button_queue, id, 0);
+ return false;
+}
+#endif
+
static void button_tick(void)
{
static int count = 0;
@@ -109,29 +123,22 @@ static void button_tick(void)
}
#endif
-#ifdef HAVE_HEADPHONE_DETECTION
- if ( headphones_inserted() )
- {
- if (! phones_present )
- {
- queue_post(&button_queue, SYS_PHONE_PLUGGED, 0);
- phones_present = true;
- }
- } else {
- if ( phones_present )
- {
- queue_post(&button_queue, SYS_PHONE_UNPLUGGED, 0);
- phones_present = false;
- }
- }
-#endif
-
#ifdef HAVE_BUTTON_DATA
btn = button_read(&data);
#else
btn = button_read();
#endif
+#if defined(HAVE_HEADPHONE_DETECTION)
+ if (headphones_inserted() != phones_present)
+ {
+ /* Use the autoresetting oneshot to debounce the detection signal */
+ phones_present = !phones_present;
+ timeout_register(&hp_detect_timeout, btn_detect_callback,
+ HZ, phones_present);
+ }
+#endif
+
/* Find out if a key has been released */
diff = btn ^ lastbtn;
if(diff && (btn & diff) == 0)
@@ -369,14 +376,15 @@ intptr_t button_get_data(void)
void button_init(void)
{
+ /* Init used objects first */
+ queue_init(&button_queue, true);
+
#ifdef HAVE_BUTTON_DATA
int temp;
#endif
/* hardware inits */
button_init_device();
- queue_init(&button_queue, true);
-
#ifdef HAVE_BUTTON_DATA
button_read(&temp);
lastbtn = button_read(&temp);
@@ -385,7 +393,6 @@ void button_init(void)
lastbtn = button_read();
#endif
- tick_add_task(button_tick);
reset_poweroff_timer();
#ifdef HAVE_LCD_BITMAP
@@ -397,6 +404,9 @@ void button_init(void)
remote_filter_first_keypress = false;
#endif
#endif
+
+ /* Start polling last */
+ tick_add_task(button_tick);
}
#ifdef HAVE_LCD_BITMAP /* only bitmap displays can be flipped */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index cf75d67..1f29a4f 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -489,4 +489,11 @@
#endif /* NUM_CORES */
+#ifdef HAVE_HEADPHONE_DETECTION
+/* Timeout objects required if headphone detection is enabled */
+#ifndef INCLUDE_TIMEOUT_API
+#define INCLUDE_TIMEOUT_API
+#endif
+#endif /* HAVE_HEADPHONE_DETECTION */
+
#endif /* __CONFIG_H__ */
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c
index 4a818d6..a80663d 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c
@@ -76,6 +76,16 @@ int button_read_device(void)
/* Only one button can be sensed at a time on the remote. */
/* Need to filter the remote button because the ADC is so fast */
remote_adc = adc_read(ADC_HPREMOTE);
+
+ if (remote_adc != ADC_READ_ERROR)
+ {
+ /* If there is nothing in the headphone socket, the ADC reads high */
+ if (remote_adc < 940)
+ headphones_detect = true;
+ else
+ headphones_detect = false;
+ }
+
btn = remote_buttons[(remote_adc + 64) / 128];
if (btn != lastbutton)
{
@@ -136,14 +146,5 @@ int button_read_device(void)
bool headphones_inserted(void)
{
- unsigned short remote_adc = adc_read(ADC_HPREMOTE);
- if (remote_adc != ADC_READ_ERROR)
- {
- /* If there is nothing in the headphone socket, the ADC reads high */
- if (remote_adc < 940)
- headphones_detect = true;
- else
- headphones_detect = false;
- }
return headphones_detect;
}