summaryrefslogtreecommitdiff
path: root/nuttx/drivers
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-01-20 00:46:56 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-01-20 00:46:56 +0000
commit279d5d3d5b47a96c7fad63f7cd21b2af79adee2b (patch)
tree23a058364456ee18ca7b3c49b00292be10c702c6 /nuttx/drivers
parenta6755a8af06d2602b771e41aab8db262fd3184ec (diff)
downloadpx4-nuttx-279d5d3d5b47a96c7fad63f7cd21b2af79adee2b.tar.gz
px4-nuttx-279d5d3d5b47a96c7fad63f7cd21b2af79adee2b.tar.bz2
px4-nuttx-279d5d3d5b47a96c7fad63f7cd21b2af79adee2b.zip
Add USH HID keyboard debouncing
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3265 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers')
-rw-r--r--nuttx/drivers/usbhost/usbhost_hidkbd.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/nuttx/drivers/usbhost/usbhost_hidkbd.c b/nuttx/drivers/usbhost/usbhost_hidkbd.c
index e6db0c8f7..74adff7ba 100644
--- a/nuttx/drivers/usbhost/usbhost_hidkbd.c
+++ b/nuttx/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? */
-
- if (rpt->key[i] != USBHID_KBDUSE_NONE)
+ /* 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
+#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? */