@@ -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
0 commit comments