-
Notifications
You must be signed in to change notification settings - Fork 992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated support for 64x48 displays #188
Open
dok-net
wants to merge
9
commits into
adafruit:master
Choose a base branch
from
dok-net:esp8266-64x48
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d4bea37
Add support for 64x48 OLED
mcauser 9ea6e58
Created proper Adafruit splash screen image for 64x48 screen size.
dok-net c660551
Fix for random uninitialized data in display RAM for displays less th…
dok-net 1607dd7
Fix what appears to be a rebasing error.
dok-net d4c41c3
Reverted added override to avoid requiring C++11.
dok-net f5fd32f
Curb whitespace changes for diff
dok-net dc8967e
Compile and fix syntax errors
dok-net 989e6d5
splash3 was manually created, make_splash.py is more recent, adding s…
dok-net 4ad7715
sources restyled by CI
dok-net File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -463,16 +463,20 @@ void Adafruit_SSD1306::ssd1306_command(uint8_t c) { | |
bool Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, bool reset, | ||
bool periphBegin) { | ||
|
||
if ((!buffer) && !(buffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8)))) | ||
if ((!buffer) && | ||
!(buffer = (uint8_t *)malloc(SSD1306_SEGMENTS * ((HEIGHT + 7) / 8)))) | ||
return false; | ||
|
||
clearDisplay(); | ||
if (HEIGHT > 32) { | ||
if (WIDTH > 64 && HEIGHT > 32) { | ||
drawBitmap((WIDTH - splash1_width) / 2, (HEIGHT - splash1_height) / 2, | ||
splash1_data, splash1_width, splash1_height, 1); | ||
} else { | ||
} else if (WIDTH > 64) { | ||
drawBitmap((WIDTH - splash2_width) / 2, (HEIGHT - splash2_height) / 2, | ||
splash2_data, splash2_width, splash2_height, 1); | ||
} else { | ||
drawBitmap((WIDTH - splash3_width) / 2, (HEIGHT - splash3_height) / 2, | ||
splash3_data, splash3_width, splash3_height, 1); | ||
} | ||
|
||
vccstate = vcs; | ||
|
@@ -538,11 +542,17 @@ bool Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, bool reset, | |
ssd1306_command1(HEIGHT - 1); | ||
|
||
static const uint8_t PROGMEM init2[] = {SSD1306_SETDISPLAYOFFSET, // 0xD3 | ||
0x0, // no offset | ||
SSD1306_SETSTARTLINE | 0x0, // line #0 | ||
SSD1306_CHARGEPUMP}; // 0x8D | ||
0x0}; // no offset | ||
ssd1306_commandList(init2, sizeof(init2)); | ||
|
||
if ((WIDTH == 64) && (HEIGHT == 32)) { | ||
ssd1306_command1(0x00); // line #0 | ||
} else { | ||
ssd1306_command1(SSD1306_SETSTARTLINE); // 0x40 | ||
} | ||
|
||
ssd1306_command1(SSD1306_CHARGEPUMP); // 0x8D | ||
|
||
ssd1306_command1((vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0x14); | ||
|
||
static const uint8_t PROGMEM init3[] = {SSD1306_MEMORYMODE, // 0x20 | ||
|
@@ -563,6 +573,9 @@ bool Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, bool reset, | |
} else if ((WIDTH == 96) && (HEIGHT == 16)) { | ||
comPins = 0x2; // ada x12 | ||
contrast = (vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0xAF; | ||
} else if ((WIDTH == 64) && ((HEIGHT == 48) || (HEIGHT == 32))) { | ||
comPins = 0x12; | ||
contrast = (vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF; | ||
} else { | ||
// Other screen varieties -- TBD | ||
} | ||
|
@@ -622,15 +635,17 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) { | |
y = HEIGHT - y - 1; | ||
break; | ||
} | ||
if ((WIDTH == 64) && (HEIGHT == 48)) | ||
x += 32; | ||
switch (color) { | ||
case SSD1306_WHITE: | ||
buffer[x + (y / 8) * WIDTH] |= (1 << (y & 7)); | ||
buffer[x + (y / 8) * SSD1306_SEGMENTS] |= (1 << (y & 7)); | ||
break; | ||
case SSD1306_BLACK: | ||
buffer[x + (y / 8) * WIDTH] &= ~(1 << (y & 7)); | ||
buffer[x + (y / 8) * SSD1306_SEGMENTS] &= ~(1 << (y & 7)); | ||
break; | ||
case SSD1306_INVERSE: | ||
buffer[x + (y / 8) * WIDTH] ^= (1 << (y & 7)); | ||
buffer[x + (y / 8) * SSD1306_SEGMENTS] ^= (1 << (y & 7)); | ||
break; | ||
} | ||
} | ||
|
@@ -644,7 +659,7 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) { | |
commands as needed by one's own application. | ||
*/ | ||
void Adafruit_SSD1306::clearDisplay(void) { | ||
memset(buffer, 0, WIDTH * ((HEIGHT + 7) / 8)); | ||
memset(buffer, 0, SSD1306_SEGMENTS * ((HEIGHT + 7) / 8)); | ||
} | ||
|
||
/*! | ||
|
@@ -707,7 +722,10 @@ void Adafruit_SSD1306::drawFastHLineInternal(int16_t x, int16_t y, int16_t w, | |
w = (WIDTH - x); | ||
} | ||
if (w > 0) { // Proceed only if width is positive | ||
uint8_t *pBuf = &buffer[(y / 8) * WIDTH + x], mask = 1 << (y & 7); | ||
if ((WIDTH == 64) && (HEIGHT == 48)) | ||
x += 32; | ||
uint8_t *pBuf = &buffer[x + (y / 8) * SSD1306_SEGMENTS]; | ||
uint8_t mask = 1 << (y & 7); | ||
switch (color) { | ||
case SSD1306_WHITE: | ||
while (w--) { | ||
|
@@ -793,7 +811,9 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, | |
// this display doesn't need ints for coordinates, | ||
// use local byte registers for faster juggling | ||
uint8_t y = __y, h = __h; | ||
uint8_t *pBuf = &buffer[(y / 8) * WIDTH + x]; | ||
if ((WIDTH == 64) && (HEIGHT == 48)) | ||
x += 32; | ||
uint8_t *pBuf = &buffer[x + (y / 8) * SSD1306_SEGMENTS]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only s/WIDTH/SSD1306_SEGMENTS/ needed to change on this line. |
||
|
||
// do the first partial byte, if necessary - this requires some masking | ||
uint8_t mod = (y & 7); | ||
|
@@ -821,7 +841,7 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, | |
*pBuf ^= mask; | ||
break; | ||
} | ||
pBuf += WIDTH; | ||
pBuf += SSD1306_SEGMENTS; | ||
} | ||
|
||
if (h >= mod) { // More to go? | ||
|
@@ -832,17 +852,17 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, | |
// separate copy of the code so we don't impact performance of | ||
// black/white write version with an extra comparison per loop | ||
do { | ||
*pBuf ^= 0xFF; // Invert byte | ||
pBuf += WIDTH; // Advance pointer 8 rows | ||
h -= 8; // Subtract 8 rows from height | ||
*pBuf ^= 0xFF; // Invert byte | ||
pBuf += SSD1306_SEGMENTS; // Advance pointer 8 rows | ||
h -= 8; // Subtract 8 rows from height | ||
} while (h >= 8); | ||
} else { | ||
// store a local value to work with | ||
uint8_t val = (color != SSD1306_BLACK) ? 255 : 0; | ||
do { | ||
*pBuf = val; // Set byte | ||
pBuf += WIDTH; // Advance pointer 8 rows | ||
h -= 8; // Subtract 8 rows from height | ||
*pBuf = val; // Set byte | ||
pBuf += SSD1306_SEGMENTS; // Advance pointer 8 rows | ||
h -= 8; // Subtract 8 rows from height | ||
} while (h >= 8); | ||
} | ||
} | ||
|
@@ -902,7 +922,9 @@ bool Adafruit_SSD1306::getPixel(int16_t x, int16_t y) { | |
y = HEIGHT - y - 1; | ||
break; | ||
} | ||
return (buffer[x + (y / 8) * WIDTH] & (1 << (y & 7))); | ||
if ((WIDTH == 64) && (HEIGHT == 48)) | ||
x += 32; | ||
return (buffer[x + (y / 8) * SSD1306_SEGMENTS] & (1 << (y & 7))); | ||
} | ||
return false; // Pixel out of bounds | ||
} | ||
|
@@ -925,13 +947,14 @@ uint8_t *Adafruit_SSD1306::getBuffer(void) { return buffer; } | |
*/ | ||
void Adafruit_SSD1306::display(void) { | ||
TRANSACTION_START | ||
static const uint8_t PROGMEM dlist1[] = { | ||
SSD1306_PAGEADDR, | ||
0, // Page start address | ||
0xFF, // Page end (not really, but works here) | ||
SSD1306_COLUMNADDR, 0}; // Column start address | ||
static const uint8_t PROGMEM dlist1[] = {SSD1306_PAGEADDR, | ||
0}; // Page start address | ||
ssd1306_commandList(dlist1, sizeof(dlist1)); | ||
ssd1306_command1(WIDTH - 1); // Column end address | ||
ssd1306_command1((HEIGHT + 7) / 8 - 1); // Page end address | ||
static const uint8_t PROGMEM dlist2[] = {SSD1306_COLUMNADDR, | ||
0}; // Column start address | ||
ssd1306_commandList(dlist2, sizeof(dlist2)); | ||
ssd1306_command1(SSD1306_SEGMENTS - 1); // Column end address | ||
|
||
#if defined(ESP8266) | ||
// ESP8266 needs a periodic yield() call to avoid watchdog reset. | ||
|
@@ -942,7 +965,7 @@ void Adafruit_SSD1306::display(void) { | |
// 32-byte transfer condition below. | ||
yield(); | ||
#endif | ||
uint16_t count = WIDTH * ((HEIGHT + 7) / 8); | ||
uint16_t count = SSD1306_SEGMENTS * ((HEIGHT + 7) / 8); | ||
uint8_t *ptr = buffer; | ||
if (wire) { // I2C | ||
wire->beginTransmission(i2caddr); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only s/WIDTH/SSD1306_SEGMENTS/ needed to change on this line.