Skip to content

Commit

Permalink
Merge pull request #250 from pimoroni/patch_glitch_fixes
Browse files Browse the repository at this point in the history
Fix display buffer being trampled for #89
  • Loading branch information
Gadgetoid authored Feb 25, 2022
2 parents 9fafa3e + 4b96817 commit 9ea59fc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
8 changes: 7 additions & 1 deletion drivers/st7789/st7789.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace pimoroni {
pwm_set_wrap(pwm_gpio_to_slice_num(bl), 65535);
pwm_init(pwm_gpio_to_slice_num(bl), &cfg, true);
gpio_set_function(bl, GPIO_FUNC_PWM);
set_backlight(255); // Turn backlight on by default to avoid nasty surprises
set_backlight(0); // Turn backlight off initially to avoid nasty surprises
}

// if auto_init_sequence then send initialisation sequence
Expand Down Expand Up @@ -176,6 +176,12 @@ namespace pimoroni {
command(reg::CASET, 4, (char *)caset);
command(reg::RASET, 4, (char *)raset);
command(reg::MADCTL, 1, (char *)&madctl);

if(bl != PIN_UNUSED) {
update(); // Send the new buffer to the display to clear any previous content
sleep_ms(50); // Wait for the update to apply
set_backlight(255); // Turn backlight on now surprises have passed
}
}

// the dma transfer works but without vsync it's not that useful as you could
Expand Down
11 changes: 9 additions & 2 deletions micropython/modules/pico_display/pico_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ mp_obj_t picodisplay_init(mp_obj_t buf_obj) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_obj, &bufinfo, MP_BUFFER_RW);
picodisplay_buf_obj = buf_obj;
if(display == nullptr)
display = new PicoDisplay((uint16_t *)bufinfo.buf);

// If a display already exists, delete it
if(display != nullptr) {
delete display;
}

// Create a new display pointing to the newly provided buffer
display = new PicoDisplay((uint16_t *)bufinfo.buf);
display->init();

return mp_const_none;
}

Expand Down
11 changes: 9 additions & 2 deletions micropython/modules/pico_display_2/pico_display_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ mp_obj_t picodisplay2_init(mp_obj_t buf_obj) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_obj, &bufinfo, MP_BUFFER_RW);
picodisplay2_buf_obj = buf_obj;
if(display2 == nullptr)
display2 = new PicoDisplay2((uint16_t *)bufinfo.buf);

// If a display already exists, delete it
if(display2 != nullptr) {
delete display2;
}

// Create a new display pointing to the newly provided buffer
display2 = new PicoDisplay2((uint16_t *)bufinfo.buf);
display2->init();

return mp_const_none;
}

Expand Down
11 changes: 9 additions & 2 deletions micropython/modules/pico_explorer/pico_explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ mp_obj_t picoexplorer_init(mp_obj_t buf_obj) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_obj, &bufinfo, MP_BUFFER_RW);
picoexplorer_buf_obj = buf_obj;
if(explorer == nullptr)
explorer = new PicoExplorer((uint16_t *)bufinfo.buf);

// If a display already exists, delete it
if(explorer != nullptr) {
delete explorer;
}

// Create a new display pointing to the newly provided buffer
explorer = new PicoExplorer((uint16_t *)bufinfo.buf);
explorer->init();

return mp_const_none;
}

Expand Down

0 comments on commit 9ea59fc

Please sign in to comment.