Skip to content

Commit 2b40aff

Browse files
committed
speed up code when autodetected too.
1 parent dcacac5 commit 2b40aff

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/AutoOLEDWire.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
#define _min min
4040
#define _max max
4141
#endif
42+
#if defined(ARDUINO_ARCH_ESP32)
43+
#define I2C_MAX_TRANSFER_BYTE 128 /** ESP32 can Transfer 128 bytes */
44+
#define I2C_OLED_TRANSFER_BYTE 64
45+
#else
46+
#define I2C_MAX_TRANSFER_BYTE 17
47+
#define I2C_OLED_TRANSFER_BYTE 16
48+
#endif
4249

4350
#define SSD1306_DETECTED 1
4451
#define SH1106_DETECTED 2
@@ -85,7 +92,7 @@ class AutoOLEDWire : public OLEDDisplay {
8592
this->_address = _address;
8693
this->_sda = _sda;
8794
this->_scl = _scl;
88-
#if !defined(ARDUINO_ARCH_ESP32)
95+
#if !defined(ARDUINO_ARCH_ESP32) && !defined(ARCH_RP2040)
8996
this->_wire = &Wire;
9097
#else
9198
this->_wire = (_i2cBus==I2C_ONE) ? &Wire : &Wire1;
@@ -114,7 +121,7 @@ class AutoOLEDWire : public OLEDDisplay {
114121
if (this->_detected == SSD1306_DETECTED) {
115122
x_offset = (128 - this->width()) / 2;
116123
}
117-
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
124+
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
118125
uint8_t minBoundY = UINT8_MAX;
119126
uint8_t maxBoundY = 0;
120127

@@ -160,7 +167,7 @@ class AutoOLEDWire : public OLEDDisplay {
160167

161168
if (minBoundY == UINT8_MAX) return;
162169

163-
byte k = 0;
170+
uint8_t k = 0;
164171

165172
if (this->_detected == SSD1306_DETECTED) {
166173
sendCommand(COLUMNADDR);
@@ -180,7 +187,7 @@ class AutoOLEDWire : public OLEDDisplay {
180187

181188
_wire->write(buffer[x + y * this->width()]);
182189
k++;
183-
if (k == 16) {
190+
if (k == (I2C_MAX_TRANSFER_BYTE - 1)) {
184191
_wire->endTransmission();
185192
k = 0;
186193
}
@@ -209,7 +216,7 @@ class AutoOLEDWire : public OLEDDisplay {
209216
}
210217
_wire->write(buffer[x + y * displayWidth]);
211218
k++;
212-
if (k == 16) {
219+
if (k == I2C_OLED_TRANSFER_BYTE) {
213220
_wire->endTransmission();
214221
k = 0;
215222
}
@@ -225,7 +232,7 @@ class AutoOLEDWire : public OLEDDisplay {
225232
if (k != 0) {
226233
_wire->endTransmission();
227234
}
228-
#else
235+
#else
229236
if (this->_detected == SSD1306_DETECTED) {
230237
sendCommand(COLUMNADDR);
231238
sendCommand(x_offset);
@@ -237,7 +244,7 @@ class AutoOLEDWire : public OLEDDisplay {
237244
for (uint16_t i=0; i < displayBufferSize; i++) {
238245
_wire->beginTransmission(this->_address);
239246
_wire->write(0x40);
240-
for (uint8_t x = 0; x < 16; x++) {
247+
for (uint8_t x = 0; x < (I2C_MAX_TRANSFER_BYTE - 1); x++) {
241248
_wire->write(buffer[i]);
242249
i++;
243250
}
@@ -250,17 +257,17 @@ class AutoOLEDWire : public OLEDDisplay {
250257
sendCommand(0xB0+y);
251258
sendCommand(0x02);
252259
sendCommand(0x10);
253-
for( uint8_t x=0; x<8; x++) {
260+
for( uint8_t x=0; x<(128/I2C_OLED_TRANSFER_BYTE); x++) {
254261
_wire->beginTransmission(_address);
255262
_wire->write(0x40);
256-
for (uint8_t k = 0; k < 16; k++) {
263+
for (uint8_t k = 0; k < I2C_OLED_TRANSFER_BYTE; k++) {
257264
_wire->write(*p++);
258265
}
259266
_wire->endTransmission();
260267
}
261268
}
262269
}
263-
#endif
270+
#endif
264271
}
265272

266273
void setI2cAutoInit(bool doI2cAutoInit) {

0 commit comments

Comments
 (0)