Skip to content

display: fix rgb565 / bgr565 displays and add documentation #93805

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ngphibang
Copy link
Contributor

@ngphibang ngphibang commented Jul 29, 2025

After #79996 merged, this PR continues to

  • fix the display_st7796s and st's ltdc display drivers affected by the changes and
  • add some more documentation for the rgb565/bgr565 display formats.

@zephyrbot zephyrbot added platform: STM32 ST Micro STM32 area: Display Release Notes To be mentioned in the release notes labels Jul 29, 2025
@ngphibang ngphibang changed the title Fix rgb565 boards display: fix rgb565 / bgr565 displays and add documentation Jul 29, 2025
@avolmat-st
Copy link

Thanks @ngphibang !!!
Regarding the LTDC commit, apparently I put also the migration-guide modification within the same commit but this shouldn't be reverted so sadly the commit cannot be reverted as is. Could you avoid reverting the migration guide ?

*
* @code{.unparsed}
* 15.....8 7......0
* | RrrrrGgg GggBbbbb | ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor typo: G bit7 should be g (small letter)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, done

@ngphibang ngphibang force-pushed the fix_rgb565_boards branch 2 times, most recently from f8abbe5 to 90bdb0b Compare July 29, 2025 08:13
* @code{.unparsed}
* 7......0 15.....8
* | gggBbbbb RrrrrGgg | ...
* @endcode

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if description for both Big and Little endian is necessary. Most important here is the order of the component, hence R G B (from MSB to LSB) or B G R (from MSB to LSB). How this is stored into memory on little or big endian is not really display specific This is common way to store 16bit values in big or little endian machines.

Copy link
Contributor Author

@ngphibang ngphibang Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a bit redundant but I see that we (people) still have some confusion when discussing about both RGB565/BGR565 and LE/BE at the same time so it seems help to give the most clarity possible.

If you still see it is not necessary, I will remove it then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the description for big-endian.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great, mentioning this as an example for little-endian gives a hint about how it is stored in memory as well, so great.

@ngphibang
Copy link
Contributor Author

Could you avoid reverting the migration guide ?

Yes, done.

Add more detailed documentation for RGB565 and BGR565 formats.

Signed-off-by: Phi Bang Nguyen <[email protected]>
This reverts the workaround made in the commit:

772fbfe

as the proper fix has now been merged upstream.

Signed-off-by: Phi Bang Nguyen <[email protected]>
Zephyr is swapping the definitions of RGB565 and BGR565. Swap the return
values provided by this driver for supported pixel formats to account
for this.

Signed-off-by: Daniel DeGrasse <[email protected]>
@ngphibang ngphibang force-pushed the fix_rgb565_boards branch from 90bdb0b to c80c77e Compare July 29, 2025 08:31
Copy link

@avolmat-st
Copy link

Sounds good to me, I will mark it as approved once tested on my board later today. Thanks @ngphibang.

Comment on lines 102 to +109
/*
* Invert the pixel format for 8-bit 8080 Parallel Interface.
*
* Zephyr uses big endian byte order when the pixel format has
* Zephyr uses little endian byte order when the pixel format has
* multiple bytes.
*
* For RGB565, Red is placed in byte 1 and Blue in byte 0.
* For BGR565, Red is placed in byte 0 and Blue in byte 1.
* For BGR565, Red is placed in byte 1 and Blue in byte 0.
* For RGB565, Red is placed in byte 0 and Blue in byte 1.
Copy link
Contributor Author

@ngphibang ngphibang Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danieldegrasse It seems confused when we say "Zephyr uses little endian byte order" ? ... I think endianness is determined by the target hardware, and Zephyr follows the HW architecture's endianess when it is compiled for that HW, no ? And for LE

  • RGB565:
	 * @code{.unparsed}
	 *   7......0 15.....8
	 * | gggBbbbb RrrrrGgg | ...
	 * @endcode
  • BGR565:
	 * @code{.unparsed}
	 *   7......0 15.....8
	 * | gggRrrrr BbbbbGgg | ...
	 * @endcode

So, the old comment is correct, no need to change, I think ?

	 * For RGB565, Red is placed in byte 1 and Blue in byte 0.
	 * For BGR565, Red is placed in byte 0 and Blue in byte 1.

Comment on lines 144 to 149
if (((bool)(config->madctl & ST7796S_MADCTL_BGR)) !=
config->rgb_is_inverted) {
return PIXEL_FORMAT_BGR_565;
} else {
return PIXEL_FORMAT_RGB_565;
} else {
return PIXEL_FORMAT_BGR_565;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need ST7796S_MADCTL_BGR and rgb_is_inverted anymore ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about that- I unfortunately don't have a board capable of 8 bit or 16 bit MIPI DBI (which is what this was needed for). @mmahadevan108 or @zejiang0jason, could you test this change and see if we need rgb_is_inverted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Display platform: STM32 ST Micro STM32 Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants