rzeldent / esp32-smartdisplay

PlatformIO library LVGL Drivers for Sunton Smart display boards (CYD Cheap Yellow Display). This library supports these boards without any effort. ESP32-2432S024N/R/C, ESP32-2432S028R/C, ESP32-3248S035R/C, ESP32_8048S070N/C
https://github.com/rzeldent/platformio-espressif32-sunton
GNU General Public License v3.0
431 stars 75 forks source link

esp32-8048S070C glitch when writing to EEPROM #109

Closed IanSC closed 10 months ago

IanSC commented 10 months ago

Horizontal sections of the screen jumps a bit from left to right randomly when saving to EEPROM.

It does not happen all the time. Sometimes it's the whole screen, but usually just a horizontal slice at the bottom. In case it's a hardware conflict, is there a way to time the eeprom save operation? eg. save right after the end of a full screen update

https://github.com/rzeldent/esp32-smartdisplay/assets/8453489/c92b2a22-b2e5-4eb4-9cca-70fa3f7c489a

Code for the glitch:

#include <esp32_smartdisplay.h>
#include <Preferences.h>

void screenGlitch() {

    lv_obj_t * bg = lv_obj_create( lv_scr_act() );
    lv_obj_center( bg );
    lv_obj_set_size( bg, lv_pct(90), lv_pct(90) );
    lv_obj_set_style_bg_color( bg, lv_palette_main( LV_PALETTE_BLUE ), 0 );

    lv_obj_t * label = lv_label_create( bg );
    lv_obj_center( label );

    unsigned long next_update = millis();
    uint8_t counter = 0;

    while( 1 ) { // SIMULATE LOOP

        lv_timer_handler();

        // every 0.5 to 1 seconds
        auto t = rand() % 1000 + 500;
        if ( millis() - next_update > t ) {

            Preferences p;
            if ( p.begin( "myFile", false ) ) {
                // must save different data to get glitch
                p.putUChar( "key", counter );
                p.end();
                counter++;
                lv_label_set_text_fmt( label, "%d", counter++ );
                // log_i();
            }
            next_update = millis();
        }
    }
}
void setup() {
    smartdisplay_init();
    screenGlitch();
}
void loop() {}

None of what I tried worked:

auto disp = lv_disp_get_default();
lv_timer_del( disp->refr_timer );
disp->refr_timer = nullptr;
... save to eeprom
disp->refr_timer = lv_timer_create( _lv_disp_refr_timer, LV_DISP_DEF_REFR_PERIOD, disp );
LV_ASSERT_MALLOC( disp->refr_timer );
auto disp = lv_disp_get_default();
lv_timer_pause( disp->refr_timer );
... save to eeprom
lv_timer_resume( disp->refr_timer );
rzeldent commented 10 months ago

Hi Ian,

Yes, this is because the screen is refreshed continuously and think saving to the EEPROM might cause these glitches. Haven't tried it yet but maybe setting ST7262_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE to 1 might help? Maybe?

IanSC commented 10 months ago

Hi @rzeldent ,

The example I made is to get the glitch continuously for video. It also happens if the time is changed to 10 sec interval or in a regular app.

Any tips on where I can find / where to set the flag? I ran:

grep -r 'FLAGS_RELAX_ON_IDLE' .

in: ~/.platformio, esp32_smartdisplay, lvgl could not find any terms close to ST7262_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE

Thanks,

rzeldent commented 10 months ago

Oh yea, it is in de json of the board, in the boards directory

IanSC commented 10 months ago

In File: esp32-8048S070C.json Section: extra_flags Added: "-DST7262_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE=1", still same glitch.

I also tried:

"-DST7262_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE=1",
"-DST7796_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE=1",
"-DST7789_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE=1",
"-DRGB_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE=1",

Just in case, since it's most similar to the driver's name in your library. Still got the glitch.

rzeldent commented 10 months ago

Hi Ian,

Thanks for the code to reproduce it. I looked at it and think the PCLK was a bit on the edge. I updated the boards to have a PCLK of 12M instead of 16M.

Take a look at the develop branch. No glitching anymore. Thanks for bringing this up!

IanSC commented 10 months ago

Hi @rzeldent,

Tried it and it works now. Even the colors and text are working.

However the screen is 180 degrees flipped, so I changed TOUCH_SWAP_X and TOUCH_SWAP_Y

I'll do some futher tests and close this issue in a few days.

Thanks again.

For other noobs like me:

My .gitmodules is not properly configured. So just downloaded: https://github.com/rzeldent/platformio-espressif32-sunton and placed the files in boards folder.

After I compiled, I got missing lvgl_touch_init() not linked error.

I thought the touch was not working, so I touched all over the screen. Turns out it was just flipped.

To fix:

So guys, again, let's support or buy this guy a beer, without his efforts these boards will be useless or extremely difficult to use. Looking at you Sunton.