From 892eca9008deed2138d090aa16ce5dd1b5a73af2 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 7 Dec 2023 20:14:18 +0100 Subject: [PATCH] docs(disp): describe how to swap the bytes with RGB565 format --- docs/porting/disp.rst | 24 ++++++++++++++++++++++++ src/display/lv_display.h | 12 +++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/docs/porting/disp.rst b/docs/porting/disp.rst index 6216fef6c..52dcd3532 100644 --- a/docs/porting/disp.rst +++ b/docs/porting/disp.rst @@ -136,6 +136,7 @@ or anything else to optimize while the waiting for flush. If ``flush_wait_cb`` is not set, LVGL assume that `lv_display_flush_ready` is used. + Rotation -------- @@ -170,6 +171,29 @@ used as a well. It's very important that draw buffer(s) should be large enough for any selected color format. + +Swap endianness +-------------- + +In case of RGB565 color format it might be required to swap the 2 bytes +because the SPI, I2C or 8 bit parallel port periphery sends them in the wrong order. + +The ideal solution is configure the hardware to handle the 16 bit data with different byte order, +however if it's not possible `:cpp:expr:`lv_draw_sw_rgb565_swap(buf, buf_size_in_px)` +can be called in the ``flush_cb`` to swap the bytes. + +If you wish you can also write your own function, or use assembly instructions for +the fastest possible byte swapping. + +Note that this is not about swapping the Red and Blue channel but converting + +``RRRRR GGG | GGG BBBBB`` + +to + +``GGG BBBBB | RRRRR GGG``. + + User data --------- diff --git a/src/display/lv_display.h b/src/display/lv_display.h index d092a167a..78fc559b3 100644 --- a/src/display/lv_display.h +++ b/src/display/lv_display.h @@ -259,12 +259,14 @@ void lv_display_set_flush_wait_cb(lv_display_t * disp, lv_display_flush_wait_cb_ /** * Set the color format of the display. - * If set to other than `LV_COLOR_FORMAT_NATIVE` the layer's `buffer_convert` function will be used - * to convert the rendered content to the desired color format. * @param disp pointer to a display - * @param color_format By default `LV_COLOR_FORMAT_NATIVE` to render with L8, RGB565, RGB888 or ARGB8888. - * `LV_COLOR_FORMAT_NATIVE_REVERSE` to change endianness. - * + * @param color_format Possible values are + * - LV_COLOR_FORMAT_RGB565 + * - LV_COLOR_FORMAT_RGB888 + * - LV_COLOR_FORMAT_XRGB888 + * - LV_COLOR_FORMAT_ARGB888 + *@note To change the endianness of the rendered image in case of RGB565 format + * (i.e. swap the 2 bytes) call `lv_draw_sw_rgb565_swap` in the flush_cb */ void lv_display_set_color_format(lv_display_t * disp, lv_color_format_t color_format);