Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display: add display_flush #79936

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 11 additions & 2 deletions modules/lvgl/lvgl_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ void lvgl_flush_thread_entry(void *arg1, void *arg2, void *arg3)
while (1) {
k_msgq_get(&flush_queue, &flush, K_FOREVER);
data = (struct lvgl_disp_data *)flush.disp_drv->user_data;
const bool is_last = lv_disp_flush_is_last(flush.disp_drv);

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

lv_disp_flush_ready(flush.disp_drv);
k_sem_give(&flush_complete);

if (is_last) {
display_flush(data->display_dev);
}
}
}

Expand Down Expand Up @@ -129,11 +134,15 @@ void lvgl_flush_display(struct lvgl_display_flush *request)
k_yield();
#else
/* Write directly to the display */
struct lvgl_disp_data *data =
(struct lvgl_disp_data *)request->disp_drv->user_data;
struct lvgl_disp_data *data = (struct lvgl_disp_data *)request->disp_drv->user_data;
const bool is_last = lv_disp_flush_is_last(request->disp_drv);

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

if (is_last) {
display_flush(data->display_dev);
}
#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 @@ -48,6 +48,10 @@ void lvgl_flush_cb_mono(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color
}

lv_disp_flush_ready(disp_drv);

if (is_last) {
display_flush(display_dev);
}
}

void lvgl_set_px_cb_mono(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
Expand Down
Loading