Demonstration of SSD1308 OLED driver library

Dependencies:   mbed SSD1308_128x64_I2C

Revision:
1:00053cb70ac5
Parent:
0:2ded56b8407d
Child:
2:d86478c0f5da
--- a/SSD1308.h	Tue Jun 19 20:00:10 2012 +0000
+++ b/SSD1308.h	Sat Jun 30 14:44:39 2012 +0000
@@ -1,16 +1,15 @@
-// I2Cdev library collection - SSD1308 I2C device class header file
-// Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
-//  8/25/2011 by Andrew Schamp <schamp@gmail.com>
-// 19/06/2012 Ported to mbed (WH)
+// SSD1308 I2C device class header file
+//   Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
+//   The SSD1308 is used for example in the Seeed 128x64 OLED Display
+//   http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167
 //
-// This I2C device library is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library,
+// The original code is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library,
 // which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
-// Note WH: I2Cdevlib not used for mbed port
 //
 // Changelog:
-//     2011-08-25 - initial release
-//     2012-06-19 - Ported to mbed (WH)
-        
+//   2011-08-25 - initial release by Andrew Schamp <schamp@gmail.com>
+//   2012-06-19 - Ported to mbed and optimised (WH)
+//             
 /* ============================================
 I2Cdev device library code is placed under the MIT license
 Copyright (c) 2011 Andrew Schamp
@@ -40,22 +39,20 @@
 #define SSD1308_H
 
 // This is the I2C address (8 bit)
-//  which one is used is determined by the D/C# pin.
-//  with D/C# (pin 13) grounded, address is 0x78
-//  with D/C# tied high it is 0x7A
-//  assume grounded by default.
-#define SSD1308_SA0 0x78
-#define SSD1308_SA1 0x7A
-#define SSD1308_DEF_SA SSD1308_SA0
+//  There are two possible addresses: with D/C# (pin 13) grounded, the address is 0x78,
+//  with D/C# tied high it is 0x7A. Assume grounded by default.
+#define SSD1308_SA0                0x78
+#define SSD1308_SA1                0x7A
+#define SSD1308_DEF_SA             SSD1308_SA0
 
-#define ROWS        64
-#define COLUMNS     128
-#define PAGES       8
-#define PAGE_WIDTH  (ROWS / 8)
-#define FONT_WIDTH  8
-#define CHARS       (COLUMNS / FONT_WIDTH)
-#define MAX_PAGE    (PAGES - 1)
-#define MAX_COL     (COLUMNS - 1)
+#define ROWS                       64
+#define COLUMNS                    128
+#define PAGES                      (ROWS / 8)
+#define MAX_PAGE                   (PAGES - 1)
+#define MAX_COL                    (COLUMNS - 1)
+
+#define FONT_WIDTH                 8
+#define CHARS                      (COLUMNS / FONT_WIDTH)
 
 #define HORIZONTAL_ADDRESSING_MODE 0x00
 #define VERTICAL_ADDRESSING_MODE   0x01
@@ -86,7 +83,7 @@
 #define SET_DISPLAY_POWER_OFF      0xAE
 #define SET_DISPLAY_POWER_ON       0xAF
 
-#define COMMAND_MODE               0x80
+#define COMMAND_MODE               0x80 // continuation bit is set!
 #define DATA_MODE                  0x40
 
 #define PAGE0                      0x00
@@ -129,7 +126,9 @@
 
     void initialize();
     void clearDisplay();
-    void fillDisplay(); // crosshatches    
+    void fillDisplay(uint8_t pattern); // pattern     
+    
+    void writeBitmap(int len, uint8_t* data);
     
     // x, y is position (x is row (i.e., page), y is character (0-15), starting at top-left)
     // text will wrap around until it is done.
@@ -167,8 +166,6 @@
     void setEntireDisplayOn();
     void setEntireDisplayRAM();
     void setEntireDisplay(bool on);
-    void setNormalDisplay();
-    void setInverseDisplay();
     
     // setMultiplexRatio
     
@@ -178,6 +175,9 @@
     void setDisplayOn();
     void setDisplayOff();
     void setDisplayPower(bool on);
+
+    void setDisplayNormal();
+    void setDisplayInverse();
     
     // Set vertical shift by COM from 0 - 63 (0x00 - 0x3F)
     // set to 0x00 after RESET
@@ -221,16 +221,16 @@
 
     void sendData(uint8_t data);
     void sendData(uint8_t len, uint8_t* data);
-    // write the configuration registers in accordance with the datasheet and app note 3944
-//    void initialize();
+    
   
-
   private:
     // sends a single-byte command (given) to device
     void sendCommand(uint8_t command);
     void sendCommands(uint8_t len, uint8_t* buf);
+    void writeChar(char chr);
 
-    void writeChar(char chr);
+    // Init the configuration registers in accordance with the datasheet
+    void _init();
     
     I2C _i2c;          // I2C bus
 //    uint8_t m_devAddr; // contains the I2C address of the device