Skip to content

Commit

Permalink
display: add display_finalize_frame
Browse files Browse the repository at this point in the history
Propagates the `lv_disp_flush_is_last` to the `display` subsystem.
Can be used to combine multiple `writes` to a single page-flip.

Signed-off-by: Martin Stumpf <martin.stumpf@vected.de>
  • Loading branch information
mstumpf-vected committed Oct 17, 2024
1 parent 8c705ca commit 0937b71
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/display/display_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ static int dummy_display_write(const struct device *dev, const uint16_t x,
return 0;
}

static int dummy_display_flush(const struct device *dev)
{
return 0;
}

static int dummy_display_blanking_off(const struct device *dev)
{
return 0;
Expand Down Expand Up @@ -110,6 +115,7 @@ static const struct display_driver_api dummy_display_api = {
.blanking_on = dummy_display_blanking_on,
.blanking_off = dummy_display_blanking_off,
.write = dummy_display_write,
.flush = dummy_display_flush,
.set_brightness = dummy_display_set_brightness,
.set_contrast = dummy_display_set_contrast,
.get_capabilities = dummy_display_get_capabilities,
Expand Down
29 changes: 29 additions & 0 deletions include/zephyr/drivers/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ typedef int (*display_read_api)(const struct device *dev, const uint16_t x,
const struct display_buffer_descriptor *desc,
void *buf);

/**
* @typedef display_flush_api
* @brief Callback API to indicate that all previous writes should be flushed to the display
* See display_flush() for argument description
*/
typedef int (*display_flush_api)(const struct device *dev);

/**
* @typedef display_get_framebuffer_api
* @brief Callback API to get framebuffer pointer
Expand Down Expand Up @@ -222,6 +229,7 @@ __subsystem struct display_driver_api {
display_blanking_off_api blanking_off;
display_write_api write;
display_read_api read;
display_flush_api flush;
display_get_framebuffer_api get_framebuffer;
display_set_brightness_api set_brightness;
display_set_contrast_api set_contrast;
Expand Down Expand Up @@ -279,6 +287,27 @@ static inline int display_read(const struct device *dev, const uint16_t x,
return api->read(dev, x, y, desc, buf);
}

/**
* @brief Indicates that all previous writes should be flushed to the display
*
* Can be used to present all previous writes simultaneously, for
* double buffered or latched displays.
*
* @param dev Pointer to device structure
*
* @retval 0 on success else negative errno code.
*/
static inline int display_flush(const struct device *dev)
{
struct display_driver_api *api = (struct display_driver_api *)dev->api;

if (api->flush == NULL) {
return -ENOSYS;
}

return api->flush(dev);
}

/**
* @brief Get pointer to framebuffer for direct access
*
Expand Down
1 change: 1 addition & 0 deletions modules/lvgl/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ config LV_Z_FLUSH_THREAD_STACK_SIZE
default 1024
help
Stack size for LVGL flush thread, which will call display_write
and display_flush

config LV_Z_FLUSH_THREAD_PRIO
int "LVGL flush thread priority"
Expand Down
9 changes: 9 additions & 0 deletions modules/lvgl/lvgl_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ void lvgl_flush_thread_entry(void *arg1, void *arg2, void *arg3)
display_write(data->display_dev, flush.x, flush.y, &flush.desc,
flush.buf);

if (lv_disp_flush_is_last(flush.disp_drv)) {
display_flush(data->display_dev);
}

lv_disp_flush_ready(flush.disp_drv);
k_sem_give(&flush_complete);
}
Expand Down Expand Up @@ -134,6 +138,11 @@ void lvgl_flush_display(struct lvgl_display_flush *request)

display_write(data->display_dev, request->x, request->y,
&request->desc, request->buf);

if (lv_disp_flush_is_last(request->disp_drv)) {
display_flush(data->display_dev);
}

lv_disp_flush_ready(request->disp_drv);
#endif
}
4 changes: 4 additions & 0 deletions modules/lvgl/lvgl_display_mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void lvgl_flush_cb_mono(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color
display_write(display_dev, area->x1, area->y1, &desc, (void *)color_p);
}

if (is_last) {
display_flush(display_dev);
}

if (is_epd && is_last && data->blanking_on) {
/*
* The entire screen has now been rendered. Update the
Expand Down

0 comments on commit 0937b71

Please sign in to comment.