@@ -187,7 +187,7 @@ void Screen_::setCurrentRotation(int rotation, bool shouldPersist)
187187#endif
188188}
189189
190- uint8_t *Screen_::getRotatedRenderBuffer ()
190+ IRAM_ATTR uint8_t *Screen_::getRotatedRenderBuffer ()
191191{
192192 // No rotation needed - return original buffer directly
193193 if (currentRotation == 0 )
@@ -206,7 +206,7 @@ uint8_t *Screen_::getRotatedRenderBuffer()
206206 return rotatedRenderBuffer_;
207207}
208208
209- void Screen_::rotate ()
209+ IRAM_ATTR void Screen_::rotate ()
210210{
211211 if (currentRotation == 1 )
212212 {
@@ -244,14 +244,14 @@ void Screen_::rotate()
244244 }
245245}
246246
247- void Screen_::onScreenTimer ()
247+ IRAM_ATTR void Screen_::onScreenTimer ()
248248{
249249 Screen._render ();
250250}
251251
252- ICACHE_RAM_ATTR void Screen_::_render ()
252+ IRAM_ATTR void Screen_::_render ()
253253{
254- const auto buf = getRotatedRenderBuffer ();
254+ const auto buf = (currentStatus == UPDATE) ? renderBuffer_ : getRotatedRenderBuffer ();
255255
256256 // SPI data needs to be 32-bit aligned, round up before divide
257257 static unsigned long
@@ -261,13 +261,26 @@ ICACHE_RAM_ATTR void Screen_::_render()
261261
262262 static unsigned char counter = 0 ;
263263
264- for ( int idx = 0 ; idx < ROWS * COLS; idx++ )
264+ if (currentStatus == UPDATE )
265265 {
266- uint16_t scaledValue = ((uint16_t )buf[positions[idx]] * brightness_) / MAX_BRIGHTNESS;
267- bits[idx >> 3 ] |= (scaledValue > counter ? 0x80 : 0 ) >> (idx & 7 );
266+ for (int idx = 0 ; idx < ROWS * COLS; idx++)
267+ {
268+ if (buf[positions[idx]] > 0 )
269+ {
270+ bits[idx >> 3 ] |= (0x80 >> (idx & 7 ));
271+ }
272+ }
273+ }
274+ else
275+ {
276+ // Normal rendering with PWM for grayscale
277+ for (int idx = 0 ; idx < ROWS * COLS; idx++)
278+ {
279+ uint16_t scaledValue = ((uint16_t )buf[positions[idx]] * brightness_) / MAX_BRIGHTNESS;
280+ bits[idx >> 3 ] |= (scaledValue > counter ? 0x80 : 0 ) >> (idx & 7 );
281+ }
282+ counter += ((MAX_BRIGHTNESS + 1 ) / GRAY_LEVELS);
268283 }
269-
270- counter += ((MAX_BRIGHTNESS + 1 ) / GRAY_LEVELS);
271284
272285 digitalWrite (PIN_LATCH, LOW);
273286 SPI.writeBytes (bits, sizeof (spi_bits));
0 commit comments