Parallel to I2C for Intelligent LED Display module PD2435~7 / PD3535~7 / PD4435~7 (OSRAM)

Dependents:   i2cleddisp_sample WeatherPlatform_20110408 WeatherPlatform WeatherStation

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Thu Oct 21 11:51:14 2010 +0000
Commit message:

Changed in this revision

I2CLEDDisp.cpp Show annotated file Show diff for this revision Revisions of this file
I2CLEDDisp.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r eae10b76cd72 I2CLEDDisp.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2CLEDDisp.cpp	Thu Oct 21 11:51:14 2010 +0000
@@ -0,0 +1,133 @@
+/*
+ * mbed library for I2C LED Display
+ * Copyright (c) 2010 Hiroshi Suga
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ * This product includes:
+ * mbed TextLCD Library, for a 4-bit LCD based on HD44780
+ * Copyright (c) 2007-2010, sford
+ */
+
+#include "mbed.h"
+#include "I2CLEDDisp.h"
+
+
+int I2CLEDDisp::_putc (int value) {
+
+    if (value == '\n') {
+		locate(0, 0);
+
+    } else {
+
+        disp_out(value, address(x, y));
+        x ++;
+        if (x >= cols()) {
+            x = 0;
+        }
+
+		if (ctrl & LEDDISP_CONTROL_ATTRIB && (ctrl & 0x03) != LEDDISP_CONTROL_AB) {
+	        disp_out(0x80 | disp_in(address(x, y)), address(x, y));
+		}
+
+    }
+
+    return value;
+}
+
+int I2CLEDDisp::_getc() {
+	int i;
+
+	i = disp_in(x);
+    x ++;
+    if (x >= cols()) {
+        x = 0;
+    }
+    return i;
+}
+
+
+I2CLEDDisp::I2CLEDDisp (PinName p_sda, PinName p_scl, int p_i2caddr, I2CLEDDispType p_type, I2CLEDDispControl p_ctrl) : i2c(p_sda, p_scl) {
+    init(p_i2caddr, p_type, p_ctrl);
+}
+
+I2CLEDDisp::I2CLEDDisp (I2C& p_i2c, int p_i2caddr, I2CLEDDispType p_type, I2CLEDDispControl p_ctrl) : i2c(p_i2c) {
+    init(p_i2caddr, p_type, p_ctrl);
+}
+
+void I2CLEDDisp::init (int p_i2caddr, I2CLEDDispType p_type, I2CLEDDispControl p_ctrl) {
+
+	i2caddr = p_i2caddr;
+    type = p_type;
+    ctrl = p_ctrl;
+
+    cls();
+}
+
+void I2CLEDDisp::cls() {
+	int i;
+	
+	for (i = 0; i < type; i ++) {
+	    disp_out(LEDDISP_CONTROL_CLEAR, i << 4);
+	    disp_out(ctrl, i << 4);
+	}
+    locate(0, 0);
+}
+
+void I2CLEDDisp::locate(int col, int row) {
+	if (ctrl & LEDDISP_CONTROL_ATTRIB && (ctrl & 0x03) != LEDDISP_CONTROL_AB) {
+        disp_out(~0x80 & disp_in(address(x, y)), address(x, y));
+	    x = col;
+	    y = row;
+        disp_out(0x80 | disp_in(address(x, y)), address(x, y));
+	} else {
+	    x = col;
+	    y = row;
+	}
+}
+
+int I2CLEDDisp::address(int col, int row) {
+	return ((col & 0x0c) << 2) | 0x04 | (~col & 0x03);
+}
+
+int I2CLEDDisp::cols() {
+	return 4 * type;
+}
+
+int I2CLEDDisp::rows() {
+	return 1;
+}
+
+void I2CLEDDisp::disp_cfg (I2CLEDDispConfig cfg) {
+	int i;
+	
+	for (i = 0; i < type; i ++) {
+    	i2c.start();
+    	i2c.write(i2caddr + (i << 1));
+    	i2c.write(LEDDISPCFG_ENABLE | (cfg & 0x71));
+    	i2c.stop();
+	}
+}
+
+void I2CLEDDisp::disp_out (int dat, int addr) {
+    i2c.start();
+    i2c.write(i2caddr | (addr >> 3));
+    i2c.write(addr & 0x07);
+    i2c.write(dat);
+    i2c.stop();
+}
+
+int I2CLEDDisp::disp_in (int rs) {
+    int i;
+
+    i2c.start();
+    i2c.write(i2caddr | (addr >> 3));
+    i2c.write(addr & 0x07);
+
+    i2c.start();
+    i2c.write(i2caddr | (addr >> 3) | 0x01);
+    i = i2c.read(0);
+    i2c.stop();
+
+    return i;
+}
+
diff -r 000000000000 -r eae10b76cd72 I2CLEDDisp.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2CLEDDisp.h	Thu Oct 21 11:51:14 2010 +0000
@@ -0,0 +1,75 @@
+/*
+ * mbed library for I2C LED Display
+ * Copyright (c) 2010 Hiroshi Suga
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ * This product includes:
+ * mbed TextLCD Library, for a 4-bit LCD based on HD44780
+ * Copyright (c) 2007-2010, sford
+ */
+ 
+#ifndef I2CLEDDisp_H
+#define I2CLEDDisp_H
+
+#include "mbed.h"
+
+#define I2CLEDDisp_ADDR 0x78
+
+enum I2CLEDDispType {
+    LEDDISP4x1		= 1,
+    LEDDISP4x1x2	= 2,
+    LEDDISP4x1x3	= 3,
+    LEDDISP4x1x4	= 4
+};
+
+enum I2CLEDDispConfig {
+    LEDDISPCFG_ENABLE   = 0x80,
+    LEDDISPCFG_SPEED    = 0x40,
+    LEDDISPCFG_ADDR1    = 0x20,
+    LEDDISPCFG_ADDR0    = 0x10,
+    LEDDISPCFG_INIT     = 0x08
+};
+
+enum I2CLEDDispControl {
+	LEDDISP_CONTROL_B0      = 0x00,
+	LEDDISP_CONTROL_B25     = 0x01,
+	LEDDISP_CONTROL_B50     = 0x02,
+	LEDDISP_CONTROL_B100    = 0x03,
+	LEDDISP_CONTROL_AC	    = 0x00,
+	LEDDISP_CONTROL_AB	    = 0x04,
+	LEDDISP_CONTROL_ABC	    = 0x08,
+	LEDDISP_CONTROL_ACC     = 0x0c,
+	LEDDISP_CONTROL_ATTRIB  = 0x10,
+	LEDDISP_CONTROL_BLINK	= 0x20,
+	LEDDISP_CONTROL_TEST	= 0x40,
+	LEDDISP_CONTROL_CLEAR	= 0x80
+};
+
+class I2CLEDDisp : public Stream {
+public:
+    I2CLEDDisp (PinName p_sda, PinName p_scl, int p_i2caddr = I2CLEDDisp_ADDR, I2CLEDDispType p_type = LEDDISP4x1, I2CLEDDispControl p_ctrl = LEDDISP_CONTROL_B100);
+    I2CLEDDisp (I2C& p_i2c, int p_i2caddr = I2CLEDDisp_ADDR, I2CLEDDispType p_type = LEDDISP4x1, I2CLEDDispControl p_ctrl = LEDDISP_CONTROL_B100);
+
+    void locate (int, int);
+    void cls ();
+    void disp_cfg (I2CLEDDispConfig);
+
+protected:
+    virtual int _putc (int);
+    virtual int _getc ();
+
+    int address (int, int);
+    int rows ();
+    int cols ();
+    void init (int, I2CLEDDispType, I2CLEDDispControl);
+    void disp_out (int, int);
+    int disp_in (int);
+
+    I2C i2c;
+    int i2caddr, addr;
+    I2CLEDDispType type;
+    I2CLEDDispControl ctrl;
+    int x, y;
+};
+
+#endif