[U-Boot] [PATCH/RFC] Support Newhaven I2C character LCD modules

Hugo Vincent hugo.vincent at gmail.com
Sat Jun 27 08:05:02 CEST 2009


Updates the display command to work correctly with Newhaven character  
LCD modules on I2C bus 3. Tested with 20x2 module (part number  
NNHD-0220D3Z-FL-GBW) on Gumstix Overo.

Requires multi-bus I2C support from my previous patch.

To use this, you need to define CONFIG_CMD_DISPLAY and  
CONFIG_SYS_NEWHAVEN_CHAR_LCD in your board config.

Signed-off-by: Hugo Vincent <hugo.vincent at gmail.com>

diff --git a/common/cmd_display.c b/common/cmd_display.c
index 4102424..44b7bf7 100644
--- a/common/cmd_display.c
+++ b/common/cmd_display.c
@@ -23,15 +23,52 @@

  #include <common.h>
  #include <command.h>
+#include <i2c.h>

  #undef DEBUG_DISP

+#ifdef CONFIG_SYS_NEWHAVEN_CHAR_LCD
+#define DISP_SIZE 80
+#define CWORD_CLEAR 0x51
+#else
  #define DISP_SIZE	8
  #define CWORD_CLEAR	0x80
+#endif
  #define CLEAR_DELAY	(110 * 2)
+#define LCD_I2C_ADDR 0x28

  int do_display (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  {
+#ifdef CONFIG_SYS_NEWHAVEN_CHAR_LCD
+	int i;
+	int pos;
+	uchar buffer = CWORD_CLEAR;
+
+	i2c_set_bus_num(2);
+	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+
+	/* Clear display */
+	if (i2c_write(LCD_I2C_ADDR, 0xfe, 1, &buffer, 1) != 0)
+		goto error;
+
+	if (argc < 2)
+		return 0;
+
+	for (pos = 0, i = 1; i < argc && pos < DISP_SIZE; i++) {
+		if (i > 1) {
+			buffer = ' ';
+			if (i2c_write(LCD_I2C_ADDR, 0, 0, &buffer, 1) != 0)
+				goto error;
+		}
+		if (i2c_write(LCD_I2C_ADDR, 0, 0, argv[i], min(strlen(argv[i]),  
DISP_SIZE)) != 0)
+			goto error;
+	}
+
+	return 0;
+error:
+	printf("I2C LCD not responding\n");
+	return 1;
+#else
  	int i;
  	int pos;

@@ -65,6 +100,7 @@ int do_display (cmd_tbl_t *cmdtp, int flag, int  
argc, char *argv[])
  #endif

  	return (0);
+#endif
  }

  /***************************************************/



More information about the U-Boot mailing list