Skip to content

Commit edd9d1e

Browse files
authored
Merge pull request #78 from squix78/improve-sh1106-drivers
Improve display performance of SH* drivers
2 parents 00af4d5 + 555d56f commit edd9d1e

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

SH1106Brzo.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class SH1106Brzo : public OLEDDisplay {
6060
uint8_t minBoundY = ~0;
6161
uint8_t maxBoundY = 0;
6262

63+
uint8_t minBoundX = ~0;
64+
uint8_t maxBoundX = 0;
6365
uint8_t x, y;
6466

6567
// Calculate the Y bounding box of changes
@@ -70,6 +72,8 @@ class SH1106Brzo : public OLEDDisplay {
7072
if (buffer[pos] != buffer_back[pos]) {
7173
minBoundY = _min(minBoundY, y);
7274
maxBoundY = _max(maxBoundY, y);
75+
minBoundX = _min(minBoundX, x);
76+
maxBoundX = _max(maxBoundX, x);
7377
}
7478
buffer_back[pos] = buffer[pos];
7579
}
@@ -84,22 +88,34 @@ class SH1106Brzo : public OLEDDisplay {
8488
byte k = 0;
8589
uint8_t sendBuffer[17];
8690
sendBuffer[0] = 0x40;
91+
92+
// Calculate the colum offset
93+
uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F;
94+
uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 );
95+
8796
brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED);
97+
8898
for (y = minBoundY; y <= maxBoundY; y++) {
8999
sendCommand(0xB0 + y);
90-
sendCommand(0x02);
91-
sendCommand(0x10);
92-
for (x = 0; x < DISPLAY_WIDTH; x++) {
100+
sendCommand(minBoundXp2H);
101+
sendCommand(minBoundXp2L);
102+
for (x = minBoundX; x <= maxBoundX; x++) {
93103
k++;
94104
sendBuffer[k] = buffer[x + y * DISPLAY_WIDTH];
95105
if (k == 16) {
96106
brzo_i2c_write(sendBuffer, 17, true);
97107
k = 0;
98108
}
99109
}
110+
if (k != 0) {
111+
brzo_i2c_write(sendBuffer, k + 1, true);
112+
k = 0;
113+
}
100114
yield();
101115
}
102-
brzo_i2c_write(sendBuffer, k + 1, true);
116+
if (k != 0) {
117+
brzo_i2c_write(sendBuffer, k + 1, true);
118+
}
103119
brzo_i2c_end_transaction();
104120
#else
105121
#endif

SH1106Wire.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class SH1106Wire : public OLEDDisplay {
6262
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
6363
uint8_t minBoundY = ~0;
6464
uint8_t maxBoundY = 0;
65+
66+
uint8_t minBoundX = ~0;
67+
uint8_t maxBoundX = 0;
68+
6569
uint8_t x, y;
6670

6771
// Calculate the Y bounding box of changes
@@ -72,6 +76,8 @@ class SH1106Wire : public OLEDDisplay {
7276
if (buffer[pos] != buffer_back[pos]) {
7377
minBoundY = _min(minBoundY, y);
7478
maxBoundY = _max(maxBoundY, y);
79+
minBoundX = _min(minBoundX, x);
80+
maxBoundX = _max(maxBoundX, x);
7581
}
7682
buffer_back[pos] = buffer[pos];
7783
}
@@ -83,12 +89,16 @@ class SH1106Wire : public OLEDDisplay {
8389
// holdes true for all values of pos
8490
if (minBoundY == ~0) return;
8591

92+
// Calculate the colum offset
93+
uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F;
94+
uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 );
95+
8696
byte k = 0;
8797
for (y = minBoundY; y <= maxBoundY; y++) {
8898
sendCommand(0xB0 + y);
89-
sendCommand(0x02);
90-
sendCommand(0x10);
91-
for (x = 0; x < DISPLAY_WIDTH; x++) {
99+
sendCommand(minBoundXp2H);
100+
sendCommand(minBoundXp2L);
101+
for (x = minBoundX; x <= maxBoundX; x++) {
92102
if (k == 0) {
93103
Wire.beginTransmission(_address);
94104
Wire.write(0x40);
@@ -100,6 +110,10 @@ class SH1106Wire : public OLEDDisplay {
100110
k = 0;
101111
}
102112
}
113+
if (k != 0) {
114+
Wire.endTransmission();
115+
k = 0;
116+
}
103117
yield();
104118
}
105119

0 commit comments

Comments
 (0)