[U-Boot] [PATCH 6/8] nhk8815: added keypad

Alessandro Rubini rubini-list at gnudd.com
Fri Oct 9 13:17:41 CEST 2009


From: Alessandro Rubini <rubini at unipv.it>

Signed-off-by: Alessandro Rubini <rubini at unipv.it>
Acked-by: Andrea Gallo <andrea.gallo at stericsson.com>
---
 board/st/nhk8815/Makefile  |    5 ++-
 board/st/nhk8815/keypad.c  |  100 ++++++++++++++++++++++++++++++++++++++++++++
 board/st/nhk8815/nhk8815.c |    5 ++
 include/configs/nhk8815.h  |    3 +
 4 files changed, 112 insertions(+), 1 deletions(-)
 create mode 100644 board/st/nhk8815/keypad.c

diff --git a/board/st/nhk8815/Makefile b/board/st/nhk8815/Makefile
index b37fe53..1bb1d2c 100644
--- a/board/st/nhk8815/Makefile
+++ b/board/st/nhk8815/Makefile
@@ -29,7 +29,10 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(BOARD).a
 
-COBJS	:= nhk8815.o
+COBJS-y	:= nhk8815.o
+COBJS-$(CONFIG_NHK8815_KEYPAD) += keypad.o
+
+COBJS	:= $(COBJS-y)
 SOBJS	:= platform.o
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
diff --git a/board/st/nhk8815/keypad.c b/board/st/nhk8815/keypad.c
new file mode 100644
index 0000000..1753cd1
--- /dev/null
+++ b/board/st/nhk8815/keypad.c
@@ -0,0 +1,100 @@
+/*
+ * board/st/nhk8815/keypad.c: keypad on nhk8815 board, based on STMPE2401
+ *
+ * Copyright 2009 Alessandro Rubini <rubini at unipv.it>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+#include <stdio_dev.h>
+#include <i2c.h>
+#include <stmpe2401.h>
+
+/*
+ * Keymap for our 4x4 matrix: since we have just
+ * a few keys, use a string for each of the keys.
+ */
+static char *keymap[4][4] = {
+	{"", "back", "ffw", "left"},
+	{"", "tvout", "playpause", "right"},
+	{"vol-", "lock", "rew", "up"},
+	{"vol+", "start", "ok", "down"}
+};
+
+/* this keeps track of the string being returned */
+static char *nextchar = "";
+
+/* This getc can return failure, not permitted in the caller */
+static int __nhk8815_getc(void)
+{
+    int row, col, res;
+
+    res = pe_kpc_getkey(STMPE0, &row, &col);
+    if (res < 0) return res; /* invalid */
+    nextchar = keymap[row][col];
+    return 0;
+}
+
+/* This is low level: may not report a valid key (a release, for example) */
+static int __nhk8815_tstc(void)
+{
+	/* the interrupt is active low */
+	int gpio = nmk_gpio_get(76);
+	return !gpio;
+}
+
+/* This is the one that is being called, it reads the pending string */
+static int nhk8815_tstc(void)
+{
+	if (*nextchar) /* there's already data */
+		return 1;
+	if (!__nhk8815_tstc()) /* no new data? */
+		return 0;
+	__nhk8815_getc(); /* get (or not) new data */
+	return (nextchar[0] != '\0');
+}
+
+/* So this is only called when there is data in the currenct string */
+static int nhk8815_getc(void)
+{
+	return *(nextchar++);
+}
+
+/* called from late init */
+int nhk8815_keypad_init(void)
+{
+        struct stdio_dev dev;
+
+	printf("%s:%s\n", __FILE__, __func__);
+
+	/* The keypad is on EXP0, columns 0..3, rows 0..3 */
+	pe_kpc_init(STMPE0, 0x0f, 0x0f, 30 /* ms */);
+
+	/* Keypad interrupt: GPIO76 */
+	nmk_gpio_af(76, GPIO_GPIO);
+	nmk_gpio_dir(76, 0);
+
+        memset (&dev, 0, sizeof (dev));
+	dev.flags = DEV_FLAGS_INPUT;
+        dev.getc = nhk8815_getc;
+        dev.tstc = nhk8815_tstc;
+	strcpy(dev.name, "keypad");
+	stdio_register(&dev);
+	return 0;
+}
diff --git a/board/st/nhk8815/nhk8815.c b/board/st/nhk8815/nhk8815.c
index eadce40..efeb0d2 100644
--- a/board/st/nhk8815/nhk8815.c
+++ b/board/st/nhk8815/nhk8815.c
@@ -106,9 +106,14 @@ int board_eth_init(bd_t *bis)
 }
 #endif
 
+extern int nhk8815_keypad_init(void);		/* ./keypad.c */
+
 /* Initialization callback, from lib_arm/board.c */
 int board_late_init(void)
 {
+#ifdef CONFIG_NHK8815_KEYPAD
+	nhk8815_keypad_init();
+#endif
 	return 0;
 }
 
diff --git a/include/configs/nhk8815.h b/include/configs/nhk8815.h
index e1be45b..f9dbd7a 100644
--- a/include/configs/nhk8815.h
+++ b/include/configs/nhk8815.h
@@ -131,6 +131,9 @@
 #define STMPE0  0x43
 #define STMPE1  0x44
 
+/* Keypad using stmpe2401 */
+#define CONFIG_NHK8815_KEYPAD
+
 /* Ethernet */
 #define PCI_MEMORY_VADDR	0xe8000000
 #define PCI_IO_VADDR		0xee000000
-- 
1.6.0.2


More information about the U-Boot mailing list