From ef756438e0f275bc12552adb4b565195deda2f00 Mon Sep 17 00:00:00 2001 From: Martin Stumpf Date: Wed, 16 Oct 2024 16:42:15 +0200 Subject: [PATCH] display: add display_flush Introduces support for double-buffered/latched displays. Currently, every write has to be presented to the user immediately, which negates the advantage of latched displays to negate frame tearing. Signed-off-by: Martin Stumpf --- include/zephyr/drivers/display.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/zephyr/drivers/display.h b/include/zephyr/drivers/display.h index 067d441d4551b4e..4ee8e66733c002e 100644 --- a/include/zephyr/drivers/display.h +++ b/include/zephyr/drivers/display.h @@ -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 @@ -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; @@ -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 *