From c38d1c1ec97972c87d8ac175ea21b2d64398a9d9 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 20 Jan 2011 00:46:56 +0000 Subject: [PATCH] Add USH HID keyboard debouncing git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3265 42af7a65-404d-4744-a932-0658087f49c3 --- drivers/usbhost/usbhost_hidkbd.c | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index e6db0c8f7f..74adff7ba9 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -696,6 +696,9 @@ static int usbhost_kbdpoll(int argc, char *argv[]) { FAR struct usbhost_state_s *priv; FAR struct usb_ctrlreq_s *ctrlreq; +#ifndef CONFIG_HIDKBD_NODEBOUNCE + uint8_t lastkey[6] = {0, 0, 0, 0, 0, 0}; +#endif #if defined(CONFIG_DEBUG_USB) && defined(CONFIG_DEBUG_VERBOSE) unsigned int npolls = 0; #endif @@ -793,9 +796,29 @@ static int usbhost_kbdpoll(int argc, char *argv[]) for (i = 0; i < 6; i++) { - /* Is this key pressed? */ + /* Is this key pressed? But not pressed last time? + * HID spec: "The order of keycodes in array fields has no + * significance. Order determination is done by the host + * software comparing the contents of the previous report to + * the current report. If two or more keys are reported in + * one report, their order is indeterminate. Keyboards may + * buffer events that would have otherwise resulted in + * multiple event in a single report. + * + * "'Repeat Rate' and 'Delay Before First Repeat' are + * implemented by the host and not in the keyboard (this + * means the BIOS in legacy mode). The host may use the + * device report rate and the number of reports to determine + * how long a key is being held down. Alternatively, the host + * may use its own clock or the idle request for the timing + * of these features." + */ - if (rpt->key[i] != USBHID_KBDUSE_NONE) + if (rpt->key[i] != USBHID_KBDUSE_NONE +#ifndef CONFIG_HIDKBD_NODEBOUNCE + && rpt->key[i] != lastkey[i] +#endif + ) { /* Yes.. Add it to the buffer. */ @@ -850,6 +873,13 @@ static int usbhost_kbdpoll(int argc, char *argv[]) } } } + /* Save the scancode (or lack thereof) for key debouncing on + * next keyboard report. + */ + +#ifndef CONFIG_HIDKBD_NODEBOUNCE + lastkey[i] = rpt->key[i]; +#endif } /* Did we just transition from no data available to data available? */