[U-Boot] [PATCH v4 4/5] samsung: misc: keys: fix gpio key bouncing by adding 50 ms delay

Przemyslaw Marczak p.marczak at samsung.com
Wed Apr 30 12:10:27 CEST 2014


Hello Gerhard,

On 04/28/2014 03:44 PM, Gerhard Sittig wrote:
> On Fri, 2014-04-25 at 12:20 +0200, Przemyslaw Marczak wrote:
>>
>> This change prevents gpio keys bouncing by adding 50 ms delay
>> when key pressed condition met.
>>
>> [ ... ]
>> @@ -105,6 +105,10 @@ static int check_keys(void)
>>   	if (key_pressed(KEY_VOLUMEDOWN))
>>   		keys += KEY_VOLUMEDOWN;
>>
>> +	/* Avoids gpio keys debouncing */
>> +	if (keys)
>> +		mdelay(50);
>> +
>>   	return keys;
>>   }
>
> The approach might have helped in your case, since you tested it
> and found it's good.  I'm just wondering whether the code really
> does correct de-bouncing.
>
> The delay does decrease the polling frequency (assuming that the
> routine is called in a loop).  But you return data that was
> sampled before the delay.  You don't re-fetch samples after the
> delay.  And this would not necessarily help either, I'm afraid.
>
> In case the GPIO (or the key_pressed() call) does debouncing, you
> wouldn't need it here.  If the key_pressed() result still is
> bouncy, then the above logic would not debounce it.  What you
> need is some kind of "trigger" where you notice that the line
> levels are changing, and a delayed fetch of the lines' values
> after they have settled.  Without the first condition, you always
> have the risk of sampling arbitrary data that does not reflect
> the keys' status.
>
> nit: The comment still appears to be misleading, you don't want
> to avoid debouncing. :)
>
>
> virtually yours
> Gerhard Sittig
>

This is right notice. Actually the problem was not a key bouncing.
The right problem is about the menu loop where check_keys() is called 
too many times for a one second.
And changing menu position few times in a second is useless and hard to 
choose proper menu option.

Putting delay into check_keys() function was good enough to make this 
menu more useful but in fact this was not a solution for key bouncing.

Function check_keys() should be as fast as it could be.
So I think that I need only increase a delay in the menu loop which is 
now 100ms.

Increasing it to 200ms gives good results. It's a simple solution.

What do you think about this?

Thank you for comments.
-- 
Przemyslaw Marczak
Samsung R&D Institute Poland
Samsung Electronics
p.marczak at samsung.com


More information about the U-Boot mailing list