forked from len0rd/rockbox
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
This commit is contained in:
parent
637e26e8e4
commit
0efdd7a5f7
3 changed files with 48 additions and 30 deletions
|
@ -61,7 +61,7 @@ static bool remote_filter_first_keypress;
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_BACKLIGHT */
|
#endif /* HAVE_BACKLIGHT */
|
||||||
#ifdef HAVE_HEADPHONE_DETECTION
|
#ifdef HAVE_HEADPHONE_DETECTION
|
||||||
bool phones_present = false;
|
static bool phones_present = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* how long until repeat kicks in, in ticks */
|
/* how long until repeat kicks in, in ticks */
|
||||||
|
@ -79,6 +79,20 @@ static int button_read(int *data);
|
||||||
static int button_read(void);
|
static int button_read(void);
|
||||||
#endif
|
#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 void button_tick(void)
|
||||||
{
|
{
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
|
@ -109,29 +123,22 @@ static void button_tick(void)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
#ifdef HAVE_BUTTON_DATA
|
||||||
btn = button_read(&data);
|
btn = button_read(&data);
|
||||||
#else
|
#else
|
||||||
btn = button_read();
|
btn = button_read();
|
||||||
#endif
|
#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 */
|
/* Find out if a key has been released */
|
||||||
diff = btn ^ lastbtn;
|
diff = btn ^ lastbtn;
|
||||||
if(diff && (btn & diff) == 0)
|
if(diff && (btn & diff) == 0)
|
||||||
|
@ -369,14 +376,15 @@ intptr_t button_get_data(void)
|
||||||
|
|
||||||
void button_init(void)
|
void button_init(void)
|
||||||
{
|
{
|
||||||
|
/* Init used objects first */
|
||||||
|
queue_init(&button_queue, true);
|
||||||
|
|
||||||
#ifdef HAVE_BUTTON_DATA
|
#ifdef HAVE_BUTTON_DATA
|
||||||
int temp;
|
int temp;
|
||||||
#endif
|
#endif
|
||||||
/* hardware inits */
|
/* hardware inits */
|
||||||
button_init_device();
|
button_init_device();
|
||||||
|
|
||||||
queue_init(&button_queue, true);
|
|
||||||
|
|
||||||
#ifdef HAVE_BUTTON_DATA
|
#ifdef HAVE_BUTTON_DATA
|
||||||
button_read(&temp);
|
button_read(&temp);
|
||||||
lastbtn = button_read(&temp);
|
lastbtn = button_read(&temp);
|
||||||
|
@ -385,7 +393,6 @@ void button_init(void)
|
||||||
lastbtn = button_read();
|
lastbtn = button_read();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tick_add_task(button_tick);
|
|
||||||
reset_poweroff_timer();
|
reset_poweroff_timer();
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
@ -397,6 +404,9 @@ void button_init(void)
|
||||||
remote_filter_first_keypress = false;
|
remote_filter_first_keypress = false;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Start polling last */
|
||||||
|
tick_add_task(button_tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP /* only bitmap displays can be flipped */
|
#ifdef HAVE_LCD_BITMAP /* only bitmap displays can be flipped */
|
||||||
|
|
|
@ -489,4 +489,11 @@
|
||||||
|
|
||||||
#endif /* NUM_CORES */
|
#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__ */
|
#endif /* __CONFIG_H__ */
|
||||||
|
|
|
@ -76,6 +76,16 @@ int button_read_device(void)
|
||||||
/* Only one button can be sensed at a time on the remote. */
|
/* Only one button can be sensed at a time on the remote. */
|
||||||
/* Need to filter the remote button because the ADC is so fast */
|
/* Need to filter the remote button because the ADC is so fast */
|
||||||
remote_adc = adc_read(ADC_HPREMOTE);
|
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];
|
btn = remote_buttons[(remote_adc + 64) / 128];
|
||||||
if (btn != lastbutton)
|
if (btn != lastbutton)
|
||||||
{
|
{
|
||||||
|
@ -136,14 +146,5 @@ int button_read_device(void)
|
||||||
|
|
||||||
bool headphones_inserted(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;
|
return headphones_detect;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue