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:
19:1b773847a04b
Parent:
17:00a1379bd18a
Child:
20:da33cca77ce5
--- a/Adafruit_SSD1306.h	Tue Feb 01 14:21:30 2022 +0000
+++ b/Adafruit_SSD1306.h	Tue Feb 01 15:20:21 2022 +0000
@@ -18,6 +18,53 @@
 
 /*
  *  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()
+ *  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_
@@ -215,7 +262,7 @@
 
         char buff[256];
         char cmd[4] = {0, 0xB0, 0x00, 0x10};
-        for (uint8_t m = 0; m < 8; m++) {
+        for (uint8_t m = 0; m < _rawHeight/8; m++) {
             buff[0] = 0x40;
             cmd[1] = 0xB0 + m;
             for(int i=0; i<128; i++) {
@@ -280,7 +327,7 @@
 
         char buff[256];
         char cmd[4] = {0, 0xB0, 0x02, 0x10};
-        for (uint8_t m = 0; m < 8; m++) {
+        for (uint8_t m = 0; m < _rawHeight/8; m++) {
             buff[0] = 0x40;
             cmd[1] = 0xB0 + m;
             for(int i=0; i<128; i++) {