From mboxrd@z Thu Jan 1 00:00:00 1970 From: Przemyslaw Marczak Date: Wed, 30 Apr 2014 12:10:27 +0200 Subject: [U-Boot] [PATCH v4 4/5] samsung: misc: keys: fix gpio key bouncing by adding 50 ms delay In-Reply-To: <20140428134456.GA3006@book.gsilab.sittig.org> References: <1396513679-15377-1-git-send-email-p.marczak@samsung.com> <1398421254-5958-1-git-send-email-p.marczak@samsung.com> <1398421254-5958-4-git-send-email-p.marczak@samsung.com> <20140428134456.GA3006@book.gsilab.sittig.org> Message-ID: <5360CC13.40706@samsung.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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