From 9347d62332eb7ff43725021c773fd9251d67d6ba Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Wed, 15 Jan 2014 20:46:57 -0800 Subject: [PATCH] Fixed double writes; tested on 128x64 and 128x32 SPI displays --- Adafruit_SSD1306.cpp | 31 +++++++------------------------ Adafruit_SSD1306.h | 5 ++--- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/Adafruit_SSD1306.cpp b/Adafruit_SSD1306.cpp index bdae4e9..4fd6599 100644 --- a/Adafruit_SSD1306.cpp +++ b/Adafruit_SSD1306.cpp @@ -383,9 +383,13 @@ void Adafruit_SSD1306::ssd1306_data(uint8_t c) { } void Adafruit_SSD1306::display(void) { - ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 - ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 - ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 + ssd1306_command(SSD1306_COLUMNADDR); + ssd1306_command(0); // Column start address (0 = reset) + ssd1306_command(127); // Column end address (127 = reset) + + ssd1306_command(SSD1306_PAGEADDR); + ssd1306_command(0); // Page start address (0 = reset) + ssd1306_command((SSD1306_LCDHEIGHT == 64) ? 7 : 3); // Page end address if (sid != -1) { @@ -398,13 +402,6 @@ void Adafruit_SSD1306::display(void) { fastSPIwrite(buffer[i]); //ssd1306_data(buffer[i]); } - // i wonder why we have to do this (check datasheet) - if (SSD1306_LCDHEIGHT == 32) { - for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { - //ssd1306_data(0); - fastSPIwrite(0); - } - } *csport |= cspinmask; } else @@ -428,20 +425,6 @@ void Adafruit_SSD1306::display(void) { i--; Wire.endTransmission(); } - // i wonder why we have to do this (check datasheet) - if (SSD1306_LCDHEIGHT == 32) { - for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { - // send a bunch of data in one xmission - Wire.beginTransmission(_i2caddr); - Wire.write(0x40); - for (uint8_t x=0; x<16; x++) { - Wire.write((uint8_t)0x00); - i++; - } - i--; - Wire.endTransmission(); - } - } TWBR = twbrbackup; } } diff --git a/Adafruit_SSD1306.h b/Adafruit_SSD1306.h index ae57ddc..126e36f 100644 --- a/Adafruit_SSD1306.h +++ b/Adafruit_SSD1306.h @@ -42,9 +42,6 @@ All text above, and the splash screen must be included in any redistribution SSD1306_128_32 128x32 pixel display - You also need to set the LCDWIDTH and LCDHEIGHT defines to an - appropriate size - -----------------------------------------------------------------------*/ #define SSD1306_128_64 // #define SSD1306_128_32 @@ -90,6 +87,8 @@ All text above, and the splash screen must be included in any redistribution #define SSD1306_SETSTARTLINE 0x40 #define SSD1306_MEMORYMODE 0x20 +#define SSD1306_COLUMNADDR 0x21 +#define SSD1306_PAGEADDR 0x22 #define SSD1306_COMSCANINC 0xC0 #define SSD1306_COMSCANDEC 0xC8