Forked from Neal Horman: Adafruit_GFX, a derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C. Now it is adopted also for the SH1106 I2C 128x64 display as well...

Dependents:   Lab06_oled_i2c Lab06_BME280_oled Lab06_oled_clock I2C_SSD1306andSH1106_nucleo_F446RE

Revision:
20:da33cca77ce5
Parent:
19:1b773847a04b
diff -r 1b773847a04b -r da33cca77ce5 Adafruit_SSD1306.h
--- a/Adafruit_SSD1306.h	Tue Feb 01 15:20:21 2022 +0000
+++ b/Adafruit_SSD1306.h	Wed Feb 02 17:55:38 2022 +0000
@@ -18,53 +18,15 @@
 
 /*
  *  Modified by Neal Horman 7/14/2012 for use in mbed
- * 
+ *
  *  Further modified by Istvan Cserny, January 31, 2022
  *  so that it could be used for the SH1106 I2C display as well
  *  The memory mode for the SSD1306 I2C display was changed to
- *  Page mode (0x10) and the virtual void sendDisplayBuffer()
+ *  Page addressing mode (0x10) and the virtual void sendDisplayBuffer()
  *  function has been rewritten accordingly.
  *
- *  To do: initialization of the SH1106 should be modified
- *  althogh also work with the default initialization.
  *
- * 
- * Example:
- * @code
- * #include "mbed.h"
- * #include "Adafruit_SSD1306.h"
- * 
- * I2C i2c(D14,D15);
- * Adafruit_SH1106_I2c oled(i2c, NC, 0x78, 64, 128);     // SH1106  I2C 128x64, with no reset pin
- * // Adafruit_SSD1306_I2c oled(i2c, NC, 0x78, 64, 128); // SSD1306 I2C 128x64, with no reset pin
- * // Adafruit_SSD1306_I2c oled(i2c, NC, 0x78, 32, 128); // SSD1306 I2C 128x32, with no reset pin
- *  
- *  
- * int main()
- * {
- *     uint16_t x=0;
- *     i2c.frequency(400000);
- *     oled.setRotation(0);
- *     oled.clearDisplay();
- *     oled.drawRect(0,0,oled.width(),oled.height(),1); 
- *     oled.display();
- *     oled.setTextColor(1);
- *     oled.setTextSize(1);
- *     oled.setTextCursor(10,8);
- *     oled.printf("SH1106 %ux%u",oled.width(),oled.height());
- *     oled.display();
- *     wait(2.0);
- *     oled.setTextSize(2);
- *     while(1) {
- *         oled.clearDisplay();
- *         oled.drawRect(0,0,oled.width(),oled.height(),1);
- *         oled.setTextCursor(10,8);
- *         oled.printf("x = %u",x++);
- *         oled.display();
- *         wait(1.0);
- *     }
- * }
- * @endcode 
+ *
  */
 
 #ifndef _ADAFRUIT_SSD1306_H_
@@ -236,6 +198,8 @@
         , mi2cAddress(i2cAddress)
     {
         begin();
+        command(0x20);       // SSD1306_MEMORYMODE
+        command(0x10);       // Page addressing mode (compatible with SG1106)
         splash();
         display();
     };
@@ -300,7 +264,7 @@
         , mi2c(i2c)
         , mi2cAddress(i2cAddress)
     {
-        begin();
+        begin2();
         splash();
         display();
     };
@@ -322,6 +286,34 @@
     };
 
 protected:
+    void begin2(void)
+    {
+        command(0xAE); //--display off
+        command(0xA1); //--set segment re-map 127 to 0
+        command(0xC8); //--Set COM Out Scan Dir 63 to 0
+        command(0x32); //--set pump voltage value to 8.0V (SH1106 only)
+        command(0x40); //--set start line address
+        command(0x81); //--set contrast control register
+        command(0x80); // POR value = 80
+        command(0xA4); //--set normal mode (A5: test mode)
+        command(0xA6); //--set normal display (i.e non-inverted mode)
+        command(0xA8); //--set multiplex ratio(1 to 64)
+        command(0x3F); //
+        command(0xAD); //--set DC-DC mode
+        command(0x8B); // DC-DC converter ON
+        command(0xD3); //--set display offset
+        command(0x00); // no offset
+        command(0xD5); //--set display clock divide ratio/oscillator frequency
+        command(0x50); // set frequency and divide ratio
+        command(0xD9); //--set dis-charge/pre-charge period
+        command(0x22); //
+        command(0xDA); //--set com pins hardware configuration
+        command(0x12);
+        command(0xDB); //--set vcomh
+        command(0x35); // SH1106: 0x35, SSD1306: 0x20 0.77xVcc
+        command(0xAF); //--turn on SSD1306 panel
+    };
+
     virtual void sendDisplayBuffer()
     {