- #if defined SSD1306_128_64
- // Init sequence taken from datasheet for UG-2864HSWEG01 (128x64 OLED module)
- CMD(SSD1306_DISPLAYOFF); // 0xAE
- CMD(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
- CMD(0x80); // the suggested ratio 0x80
- CMD(SSD1306_SETMULTIPLEX); // 0xA8
- CMD(0x3F); // 63
- CMD(SSD1306_SETDISPLAYOFFSET); // 0xD3
- CMD(0x0); // no offset
- CMD(SSD1306_SETSTARTLINE | 0x0); // line #0
- CMD(SSD1306_CHARGEPUMP); // 0x8D
- if (vccstate == SSD1306_EXTERNALVCC)
- { CMD(0x10) }
- else
- { CMD(0x14) }
- CMD(SSD1306_MEMORYMODE); // 0x20
- CMD(0x00); // 0x0 act like ks0108
- CMD(SSD1306_SEGREMAP | 0x1);
- CMD(SSD1306_COMSCANDEC);
- CMD(SSD1306_SETCOMPINS); // 0xDA
- CMD(0x12);
- CMD(SSD1306_SETCONTRAST); // 0x81
- if (vccstate == SSD1306_EXTERNALVCC)
- { CMD(0x9F) }
- else
- { CMD(0xCF) }
- CMD(SSD1306_SETPRECHARGE); // 0xd9
- if (vccstate == SSD1306_EXTERNALVCC)
- { CMD(0x22) }
- else
- { CMD(0xF1) }
- CMD(SSD1306_SETVCOMDETECT); // 0xDB
- CMD(0x40);
- CMD(SSD1306_DISPLAYALLON_RESUME); // 0xA4
- CMD(SSD1306_NORMALDISPLAY); // 0xA6
+ // I2C Initialisation
+ #if defined SSD1306_BUS_I2C
+ #if defined SSD1306_128_32
+ // Init sequence taken from datasheet for UG-2832HSWEG04 (128x32 OLED module)
+ ssd1306SendCommand(SSD1306_DISPLAYOFF); // 0xAE
+ ssd1306SendCommand(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
+ ssd1306SendCommand(0x80); // the suggested ratio 0x80
+ ssd1306SendCommand(SSD1306_SETMULTIPLEX); // 0xA8
+ ssd1306SendCommand(0x1F); // 31
+ ssd1306SendCommand(SSD1306_SETDISPLAYOFFSET); // 0xD3
+ ssd1306SendCommand(0x0); // no offset
+ ssd1306SendCommand(SSD1306_SETSTARTLINE | 0x0); // line #0
+ ssd1306SendCommand(SSD1306_CHARGEPUMP); // 0x8D
+ if (vccstate == SSD1306_EXTERNALVCC)
+ { ssd1306SendCommand(0x10); }
+ else
+ { ssd1306SendCommand(0x14); }
+ ssd1306SendCommand(SSD1306_MEMORYMODE); // 0x20
+ ssd1306SendCommand(0x00); // 0x0 act like ks0108
+ ssd1306SendCommand(SSD1306_SEGREMAP | 0x1);
+ ssd1306SendCommand(SSD1306_COMSCANDEC);
+ ssd1306SendCommand(SSD1306_SETCOMPINS); // 0xDA
+ ssd1306SendCommand(0x02);
+ ssd1306SendCommand(SSD1306_SETCONTRAST); // 0x81
+ if (vccstate == SSD1306_EXTERNALVCC)
+ { ssd1306SendCommand(0x9F); }
+ else
+ { ssd1306SendCommand(0xCF); }
+ ssd1306SendCommand(SSD1306_SETPRECHARGE); // 0xd9
+ if (vccstate == SSD1306_EXTERNALVCC)
+ { ssd1306SendCommand(0x22); }
+ else
+ { ssd1306SendCommand(0xF1); }
+ ssd1306SendCommand(SSD1306_SETVCOMDETECT); // 0xDB
+ ssd1306SendCommand(0x40);
+ ssd1306SendCommand(SSD1306_DISPLAYALLON_RESUME); // 0xA4
+ ssd1306SendCommand(SSD1306_NORMALDISPLAY); // 0xA6
+ #endif
+
+ #if defined SSD1306_128_64
+ // Init sequence taken from datasheet for UG-2864HSWEG01 (128x64 OLED module)
+ ssd1306SendCommand(SSD1306_DISPLAYOFF); // 0xAE
+ ssd1306SendCommand(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
+ ssd1306SendCommand(0x80); // the suggested ratio 0x80
+ ssd1306SendCommand(SSD1306_SETMULTIPLEX); // 0xA8
+ ssd1306SendCommand(0x3F); // 63
+ ssd1306SendCommand(SSD1306_SETDISPLAYOFFSET); // 0xD3
+ ssd1306SendCommand(0x0); // no offset
+ ssd1306SendCommand(SSD1306_SETSTARTLINE | 0x0); // line #0
+ ssd1306SendCommand(SSD1306_CHARGEPUMP); // 0x8D
+ if (vccstate == SSD1306_EXTERNALVCC)
+ { ssd1306SendCommand(0x10); }
+ else
+ { ssd1306SendCommand(0x14); }
+ ssd1306SendCommand(SSD1306_MEMORYMODE); // 0x20
+ ssd1306SendCommand(0x00); // 0x0 act like ks0108
+ ssd1306SendCommand(SSD1306_SEGREMAP | 0x1);
+ ssd1306SendCommand(SSD1306_COMSCANDEC);
+ ssd1306SendCommand(SSD1306_SETCOMPINS); // 0xDA
+ ssd1306SendCommand(0x12);
+ ssd1306SendCommand(SSD1306_SETCONTRAST); // 0x81
+ if (vccstate == SSD1306_EXTERNALVCC)
+ { ssd1306SendCommand(0x9F); }
+ else
+ { ssd1306SendCommand(0xCF); }
+ ssd1306SendCommand(SSD1306_SETPRECHARGE); // 0xd9
+ if (vccstate == SSD1306_EXTERNALVCC)
+ { ssd1306SendCommand(0x22); }
+ else
+ { ssd1306SendCommand(0xF1); }
+ ssd1306SendCommand(SSD1306_SETVCOMDETECT); // 0xDB
+ ssd1306SendCommand(0x40);
+ ssd1306SendCommand(SSD1306_DISPLAYALLON_RESUME); // 0xA4
+ ssd1306SendCommand(SSD1306_NORMALDISPLAY); // 0xA6
+ #endif
+ // Enable the OLED panel
+ ssd1306SendCommand(SSD1306_DISPLAYON);