Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README_GEOMETRY_64_48.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# GEOMETRY_64_48

The 64x48 geometry setting are working with the `Wire.h` and `brzo_i2c` libraries.

I've tested it successfully with a WEMOS D1 mini Lite and a WEMOS OLED shield

Initialization code:

- Wire
```
#include <Wire.h>
#include <SSD1306Wire.h>
SSD1306Wire display(0x3c, D2, D1, GEOMETRY_64_48 ); // WEMOS OLED shield
```

- BRZO i2c
```
#include <SSD1306Brzo.h>
SSD1306Brzo display(0x3c, D2, D1, GEOMETRY_64_48 ); // WEMOS OLED Shield
```
17 changes: 14 additions & 3 deletions src/OLEDDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* https://thingpulse.com
*
*/

#include "OLEDDisplay.h"

OLEDDisplay::~OLEDDisplay() {
Expand Down Expand Up @@ -471,6 +470,15 @@ void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, String strUser) {
free(text);
}

void OLEDDisplay::drawStringf( int16_t x, int16_t y, char* buffer, String format, ... )
{
va_list myargs;
va_start(myargs, format);
vsprintf(buffer, format.c_str(), myargs);
va_end(myargs);
drawString( x, y, buffer );
}

void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, String strUser) {
uint16_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS);
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);
Expand Down Expand Up @@ -743,6 +751,9 @@ void OLEDDisplay::setGeometry(OLEDDISPLAY_GEOMETRY g) {
} else if (g == GEOMETRY_128_32) {
this->displayWidth = 128;
this->displayHeight = 32;
} else if (g == GEOMETRY_64_48) {
this->displayWidth = 64;
this->displayHeight = 48;
}
this->displayBufferSize = displayWidth*displayHeight/8;
}
Expand All @@ -764,15 +775,15 @@ void OLEDDisplay::sendInitCommands(void) {
sendCommand(COMSCANINC);
sendCommand(SETCOMPINS);

if (geometry == GEOMETRY_128_64) {
if (geometry == GEOMETRY_128_64 || geometry == GEOMETRY_64_48) {
sendCommand(0x12);
} else if (geometry == GEOMETRY_128_32) {
sendCommand(0x02);
}

sendCommand(SETCONTRAST);

if (geometry == GEOMETRY_128_64) {
if (geometry == GEOMETRY_128_64 || geometry == GEOMETRY_64_48) {
sendCommand(0xCF);
} else if (geometry == GEOMETRY_128_32) {
sendCommand(0x8F);
Expand Down
10 changes: 7 additions & 3 deletions src/OLEDDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ enum OLEDDISPLAY_TEXT_ALIGNMENT {

enum OLEDDISPLAY_GEOMETRY {
GEOMETRY_128_64 = 0,
GEOMETRY_128_32 = 1
GEOMETRY_128_32 = 1,
GEOMETRY_64_48 = 2
};

typedef byte (*FontTableLookupFunction)(const byte ch);
Expand Down Expand Up @@ -177,7 +178,10 @@ class OLEDDisplay : public Print {
/* Text functions */

// Draws a string at the given location
void drawString(int16_t x, int16_t y, String text);
void drawString( int16_t x, int16_t y, String text);

// Draws a formatted string (like printf) at the given location
void drawStringf( int16_t x, int16_t y, char* buffer, String format, ... );

// Draws a String with a maximum width at the given location.
// If the given String is wider than the specified width
Expand Down Expand Up @@ -222,7 +226,7 @@ class OLEDDisplay : public Print {
// normal brightness & contrast: contrast = 100
void setContrast(uint8_t contrast, uint8_t precharge = 241, uint8_t comdetect = 64);

// Convenience method to access
// Convenience method to access
void setBrightness(uint8_t);

// Reset display rotation or mirroring
Expand Down
43 changes: 24 additions & 19 deletions src/SSD1306Brzo.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class SSD1306Brzo : public OLEDDisplay {
}

void display(void) {
const int x_offset = (128 - this->width()) / 2;

#ifdef OLEDDISPLAY_DOUBLE_BUFFER
uint8_t minBoundY = UINT8_MAX;
uint8_t maxBoundY = 0;
Expand All @@ -72,9 +74,9 @@ class SSD1306Brzo : public OLEDDisplay {

// Calculate the Y bounding box of changes
// and copy buffer[pos] to buffer_back[pos];
for (y = 0; y < (displayHeight / 8); y++) {
for (x = 0; x < displayWidth; x++) {
uint16_t pos = x + y * displayWidth;
for (y = 0; y < (this->height() / 8); y++) {
for (x = 0; x < this->width(); x++) {
uint16_t pos = x + y * this->width();
if (buffer[pos] != buffer_back[pos]) {
minBoundY = _min(minBoundY, y);
maxBoundY = _max(maxBoundY, y);
Expand All @@ -92,23 +94,26 @@ class SSD1306Brzo : public OLEDDisplay {
if (minBoundY == UINT8_MAX) return;

sendCommand(COLUMNADDR);
sendCommand(minBoundX);
sendCommand(maxBoundX);
sendCommand(x_offset + minBoundX);
sendCommand(x_offset + maxBoundX);

sendCommand(PAGEADDR);
sendCommand(minBoundY);
sendCommand(maxBoundY);

byte k = 0;
uint8_t sendBuffer[17];

int buflen = ( this->width() / 8 ) + 1;

uint8_t sendBuffer[buflen];
sendBuffer[0] = 0x40;
brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED);
for (y = minBoundY; y <= maxBoundY; y++) {
for (x = minBoundX; x <= maxBoundX; x++) {
k++;
sendBuffer[k] = buffer[x + y * displayWidth];
if (k == 16) {
brzo_i2c_write(sendBuffer, 17, true);
sendBuffer[k] = buffer[x + y * this->width()];
if (k == (buflen-1)) {
brzo_i2c_write(sendBuffer, buflen, true);
k = 0;
}
}
Expand All @@ -119,28 +124,28 @@ class SSD1306Brzo : public OLEDDisplay {
#else
// No double buffering
sendCommand(COLUMNADDR);
sendCommand(0x0);
sendCommand(0x7F);

sendCommand(x_offset);
sendCommand(x_offset + (this->width() - 1));

sendCommand(PAGEADDR);
sendCommand(0x0);
sendCommand((this->height() / 8) - 1);

if (geometry == GEOMETRY_128_64) {
sendCommand(0x7);
} else if (geometry == GEOMETRY_128_32) {
sendCommand(0x3);
}
int buflen = ( this->width() / 8 ) + 1;

uint8_t sendBuffer[17];
uint8_t sendBuffer[buflen];
sendBuffer[0] = 0x40;

brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED);

for (uint16_t i=0; i<displayBufferSize; i++) {
for (uint8_t x=1; x<17; x++) {
for (uint8_t x=1; x<buflen; x++) {
sendBuffer[x] = buffer[i];
i++;
}
i--;
brzo_i2c_write(sendBuffer, 17, true);
brzo_i2c_write(sendBuffer, buflen, true);
yield();
}
brzo_i2c_end_transaction();
Expand Down
2 changes: 1 addition & 1 deletion src/SSD1306Spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SSD1306Spi : public OLEDDisplay {
sendCommand(PAGEADDR);
sendCommand(0x0);

if (geometry == GEOMETRY_128_64) {
if (geometry == GEOMETRY_128_64 || geometry == GEOMETRY_64_48) {
sendCommand(0x7);
} else if (geometry == GEOMETRY_128_32) {
sendCommand(0x3);
Expand Down
6 changes: 0 additions & 6 deletions src/SSD1306Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ class SSD1306Wire : public OLEDDisplay {
sendCommand(0x0);
sendCommand((this->height() / 8) - 1);

if (geometry == GEOMETRY_128_64) {
sendCommand(0x7);
} else if (geometry == GEOMETRY_128_32) {
sendCommand(0x3);
}

for (uint16_t i=0; i < displayBufferSize; i++) {
Wire.beginTransmission(this->_address);
Wire.write(0x40);
Expand Down