From 8029789ac24f6cec17c99b62226ceece79175d29 Mon Sep 17 00:00:00 2001 From: Chester Date: Mon, 10 Oct 2016 21:38:38 -1000 Subject: [PATCH] Add support for 64x32 displays + higher speed I2C com New define has been setup for 64x32 displays that need an additional starting offset value of 0x20 + the other usual changes.. Only currently tested on 64x32 and 128x64 displays on a SAMD core board. --- Adafruit_SSD1306.cpp | 24 +++++++++++++++++++++--- Adafruit_SSD1306.h | 9 +++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Adafruit_SSD1306.cpp b/Adafruit_SSD1306.cpp index e972656..133c80f 100644 --- a/Adafruit_SSD1306.cpp +++ b/Adafruit_SSD1306.cpp @@ -55,6 +55,7 @@ static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = { 0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, 0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +#if (SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH > 64*32) // added for 64x32 display option 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, @@ -106,6 +107,7 @@ static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 #endif #endif +#endif }; #define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; } @@ -208,6 +210,8 @@ void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { // Force 400 KHz I2C, rawr! (Uses pins 20, 21 for SDA, SCL) TWI1->TWI_CWGR = 0; TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101; +#elif ARDUINO >= 157 // Send data MUCH faster to display + Wire.setClock(400000UL); // Set I2C frequency to 400kHz #endif } if ((reset) && (rst >= 0)) { @@ -269,7 +273,16 @@ void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { { ssd1306_command(0x10); } else { ssd1306_command(0xAF); } - +#elif defined SSD1306_64_32 + ssd1306_command(SSD1306_SETCOMPINS); // 0xDA + ssd1306_command(0x12); + ssd1306_command(SSD1306_SETCONTRAST); // 0x81 + ssd1306_command(0xcf); + ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 + if (vccstate == SSD1306_EXTERNALVCC) + { ssd1306_command(0x22); } + else + { ssd1306_command(0xF1); } #endif ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 @@ -418,8 +431,13 @@ void Adafruit_SSD1306::dim(boolean dim) { void Adafruit_SSD1306::display(void) { ssd1306_command(SSD1306_COLUMNADDR); - ssd1306_command(0); // Column start address (0 = reset) - ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset) + #if defined SSD1306_64_32 // Added by CL 2016-9-10 + ssd1306_command(0x20); // Column start address (0x20 = reset) - 64 pixel wide displays have starting values offset + ssd1306_command(0x20 + (SSD1306_LCDWIDTH-1)); // Column end address (127 = reset) - 64 pixel wide displays have starting values offset - could use static 0x5F here + #else + ssd1306_command(0); // Column start address (0 = reset) + ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset) + #endif ssd1306_command(SSD1306_PAGEADDR); ssd1306_command(0); // Page start address (0 = reset) diff --git a/Adafruit_SSD1306.h b/Adafruit_SSD1306.h index 983f277..a4f1193 100644 --- a/Adafruit_SSD1306.h +++ b/Adafruit_SSD1306.h @@ -67,14 +67,15 @@ All text above, and the splash screen must be included in any redistribution -----------------------------------------------------------------------*/ // #define SSD1306_128_64 - #define SSD1306_128_32 +// #define SSD1306_128_32 // #define SSD1306_96_16 + #define SSD1306_64_32 /*=========================================================================*/ #if defined SSD1306_128_64 && defined SSD1306_128_32 #error "Only one SSD1306 display can be specified at once in SSD1306.h" #endif -#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 +#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 && !defined SSD1306_64_32 #error "At least one SSD1306 display must be specified in SSD1306.h" #endif @@ -90,6 +91,10 @@ All text above, and the splash screen must be included in any redistribution #define SSD1306_LCDWIDTH 96 #define SSD1306_LCDHEIGHT 16 #endif +#if defined SSD1306_64_32 + #define SSD1306_LCDWIDTH 64 + #define SSD1306_LCDHEIGHT 32 +#endif #define SSD1306_SETCONTRAST 0x81 #define SSD1306_DISPLAYALLON_RESUME 0xA4