diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2008-01-27 21:13:04 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2008-01-27 21:13:04 +0000 |
commit | 0efdd7a5f74c955d0eb604cd3fef9069be57bcbb (patch) | |
tree | 3da7c91ca05c154a31564c0045308256c206b1fd | |
parent | 637e26e8e4c87e25bcdc5f6793b86d34061e7aae (diff) | |
download | rockbox-0efdd7a5f74c955d0eb604cd3fef9069be57bcbb.tar.gz rockbox-0efdd7a5f74c955d0eb604cd3fef9069be57bcbb.zip |
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.c | 52 | ||||
-rw-r--r-- | firmware/export/config.h | 7 | ||||
-rw-r--r-- | firmware/target/arm/s3c2440/gigabeat-fx/button-meg-fx.c | 19 |
3 files changed, 48 insertions, 30 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 33b708ea5c..b9473bec24 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -61,7 +61,7 @@ static bool remote_filter_first_keypress; | |||
61 | #endif | 61 | #endif |
62 | #endif /* HAVE_BACKLIGHT */ | 62 | #endif /* HAVE_BACKLIGHT */ |
63 | #ifdef HAVE_HEADPHONE_DETECTION | 63 | #ifdef HAVE_HEADPHONE_DETECTION |
64 | bool phones_present = false; | 64 | static bool phones_present = false; |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | /* how long until repeat kicks in, in ticks */ | 67 | /* how long until repeat kicks in, in ticks */ |
@@ -79,6 +79,20 @@ static int button_read(int *data); | |||
79 | static int button_read(void); | 79 | static int button_read(void); |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | #if defined(HAVE_HEADPHONE_DETECTION) | ||
83 | static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */ | ||
84 | /* This callback can be used for many different functions if needed - | ||
85 | just check to which object tmo points */ | ||
86 | static bool btn_detect_callback(struct timeout *tmo) | ||
87 | { | ||
88 | /* Try to post only transistions */ | ||
89 | const long id = tmo->data ? SYS_PHONE_PLUGGED : SYS_PHONE_UNPLUGGED; | ||
90 | queue_remove_from_head(&button_queue, id); | ||
91 | queue_post(&button_queue, id, 0); | ||
92 | return false; | ||
93 | } | ||
94 | #endif | ||
95 | |||
82 | static void button_tick(void) | 96 | static void button_tick(void) |
83 | { | 97 | { |
84 | static int count = 0; | 98 | static int count = 0; |
@@ -109,29 +123,22 @@ static void button_tick(void) | |||
109 | } | 123 | } |
110 | #endif | 124 | #endif |
111 | 125 | ||
112 | #ifdef HAVE_HEADPHONE_DETECTION | ||
113 | if ( headphones_inserted() ) | ||
114 | { | ||
115 | if (! phones_present ) | ||
116 | { | ||
117 | queue_post(&button_queue, SYS_PHONE_PLUGGED, 0); | ||
118 | phones_present = true; | ||
119 | } | ||
120 | } else { | ||
121 | if ( phones_present ) | ||
122 | { | ||
123 | queue_post(&button_queue, SYS_PHONE_UNPLUGGED, 0); | ||
124 | phones_present = false; | ||
125 | } | ||
126 | } | ||
127 | #endif | ||
128 | |||
129 | #ifdef HAVE_BUTTON_DATA | 126 | #ifdef HAVE_BUTTON_DATA |
130 | btn = button_read(&data); | 127 | btn = button_read(&data); |
131 | #else | 128 | #else |
132 | btn = button_read(); | 129 | btn = button_read(); |
133 | #endif | 130 | #endif |
134 | 131 | ||
132 | #if defined(HAVE_HEADPHONE_DETECTION) | ||
133 | if (headphones_inserted() != phones_present) | ||
134 | { | ||
135 | /* Use the autoresetting oneshot to debounce the detection signal */ | ||
136 | phones_present = !phones_present; | ||
137 | timeout_register(&hp_detect_timeout, btn_detect_callback, | ||
138 | HZ, phones_present); | ||
139 | } | ||
140 | #endif | ||
141 | |||
135 | /* Find out if a key has been released */ | 142 | /* Find out if a key has been released */ |
136 | diff = btn ^ lastbtn; | 143 | diff = btn ^ lastbtn; |
137 | if(diff && (btn & diff) == 0) | 144 | if(diff && (btn & diff) == 0) |
@@ -369,14 +376,15 @@ intptr_t button_get_data(void) | |||
369 | 376 | ||
370 | void button_init(void) | 377 | void button_init(void) |
371 | { | 378 | { |
379 | /* Init used objects first */ | ||
380 | queue_init(&button_queue, true); | ||
381 | |||
372 | #ifdef HAVE_BUTTON_DATA | 382 | #ifdef HAVE_BUTTON_DATA |
373 | int temp; | 383 | int temp; |
374 | #endif | 384 | #endif |
375 | /* hardware inits */ | 385 | /* hardware inits */ |
376 | button_init_device(); | 386 | button_init_device(); |
377 | 387 | ||
378 | queue_init(&button_queue, true); | ||
379 | |||
380 | #ifdef HAVE_BUTTON_DATA | 388 | #ifdef HAVE_BUTTON_DATA |
381 | button_read(&temp); | 389 | button_read(&temp); |
382 | lastbtn = button_read(&temp); | 390 | lastbtn = button_read(&temp); |
@@ -385,7 +393,6 @@ void button_init(void) | |||
385 | lastbtn = button_read(); | 393 | lastbtn = button_read(); |
386 | #endif | 394 | #endif |
387 | 395 | ||
388 | tick_add_task(button_tick); | ||
389 | reset_poweroff_timer(); | 396 | reset_poweroff_timer(); |
390 | 397 | ||
391 | #ifdef HAVE_LCD_BITMAP | 398 | #ifdef HAVE_LCD_BITMAP |
@@ -397,6 +404,9 @@ void button_init(void) | |||
397 | remote_filter_first_keypress = false; | 404 | remote_filter_first_keypress = false; |
398 | #endif | 405 | #endif |
399 | #endif | 406 | #endif |
407 | |||
408 | /* Start polling last */ | ||
409 | tick_add_task(button_tick); | ||
400 | } | 410 | } |
401 | 411 | ||
402 | #ifdef HAVE_LCD_BITMAP /* only bitmap displays can be flipped */ | 412 | #ifdef HAVE_LCD_BITMAP /* only bitmap displays can be flipped */ |
diff --git a/firmware/export/config.h b/firmware/export/config.h index cf75d67aa5..1f29a4f207 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -489,4 +489,11 @@ | |||
489 | 489 | ||
490 | #endif /* NUM_CORES */ | 490 | #endif /* NUM_CORES */ |
491 | 491 | ||
492 | #ifdef HAVE_HEADPHONE_DETECTION | ||
493 | /* Timeout objects required if headphone detection is enabled */ | ||
494 | #ifndef INCLUDE_TIMEOUT_API | ||
495 | #define INCLUDE_TIMEOUT_API | ||
496 | #endif | ||
497 | #endif /* HAVE_HEADPHONE_DETECTION */ | ||
498 | |||
492 | #endif /* __CONFIG_H__ */ | 499 | #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 4a818d6bfc..a80663d0d6 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) | |||
76 | /* Only one button can be sensed at a time on the remote. */ | 76 | /* Only one button can be sensed at a time on the remote. */ |
77 | /* Need to filter the remote button because the ADC is so fast */ | 77 | /* Need to filter the remote button because the ADC is so fast */ |
78 | remote_adc = adc_read(ADC_HPREMOTE); | 78 | remote_adc = adc_read(ADC_HPREMOTE); |
79 | |||
80 | if (remote_adc != ADC_READ_ERROR) | ||
81 | { | ||
82 | /* If there is nothing in the headphone socket, the ADC reads high */ | ||
83 | if (remote_adc < 940) | ||
84 | headphones_detect = true; | ||
85 | else | ||
86 | headphones_detect = false; | ||
87 | } | ||
88 | |||
79 | btn = remote_buttons[(remote_adc + 64) / 128]; | 89 | btn = remote_buttons[(remote_adc + 64) / 128]; |
80 | if (btn != lastbutton) | 90 | if (btn != lastbutton) |
81 | { | 91 | { |
@@ -136,14 +146,5 @@ int button_read_device(void) | |||
136 | 146 | ||
137 | bool headphones_inserted(void) | 147 | bool headphones_inserted(void) |
138 | { | 148 | { |
139 | unsigned short remote_adc = adc_read(ADC_HPREMOTE); | ||
140 | if (remote_adc != ADC_READ_ERROR) | ||
141 | { | ||
142 | /* If there is nothing in the headphone socket, the ADC reads high */ | ||
143 | if (remote_adc < 940) | ||
144 | headphones_detect = true; | ||
145 | else | ||
146 | headphones_detect = false; | ||
147 | } | ||
148 | return headphones_detect; | 149 | return headphones_detect; |
149 | } | 150 | } |