This article describes how to switch to 4bpp grayscale color mode. In this color mode, TouchGFX uses four bits per pixel, yielding a grayscale color space of 16 colors. In this mode, the frame buffer size in bytes is width * height / 2. Correspondingly, the size of bitmap images in flash is also width * height / 2.
- This article applies only to TouchGFX release 4.6.0 and later
See for yourself: Check out the drag_example_4bit in the TouchGFX distribution.
The drag_example when TouchGFX is configured in 4bpp grayscale.
Supported hardware platforms
4bpp color format is in principle supported on all hardware platforms, but with the very important distinction that the on-chip TFT controllers of the microcontrollers supported by TouchGFX do not support 4bpp frame buffers. This means that 4bpp colors can only be used with displays that have an integrated LCD controller (and frame buffer). In such a setup, the frame buffer is manually transferred to the display, typically using a 8080 or SPI-based interface. See this article for details on using 8080/SPI displays with TouchGFX.
Frame buffer format
Note that internal frame buffer format in 4bpp mode is such that the first pixel is placed in the least significant bits of a byte:
This is in accordance with Sitronix grayscale display controllers. You should examine whether your display controller uses the same format. If it does not, then you will need to either:
- Manually swap the pixels when transferring frame buffer data to display (eliminating the possibility of using DMA for this operation), or
- In case of 8080-mode, wire the data pins to the display differently such that the pixels show up at the expected position in a byte.
Enabling 4bpp mode
To enable 4bpp mode, you need to make some adjustments in the TouchGFX configuration, in order to make TouchGFX output images in the correct format.
Image format and simulator configuration changes
If you use GCC and make to generate images and compiling the simulator, modify the following:
# Optional additional compiler flags user_cflags := -DUSE_BPP=4 # Settings for image converter output format opaque_image_format := GRAY4 non_opaque_image_format := GRAY4
If you use Visual Studio, modify the following:
<UseBPP>4</UseBPP> <OpaqueImageOutputFormat>GRAY4</OpaqueImageOutputFormat> <NonOpaqueImageOutputFormat>GRAY4</NonOpaqueImageOutputFormat>
By doing the above you should now be able to recompile the application and see the simulator running in 4bpp mode.
In order to run in 4bpp on target, you will need to also make some adjustments to your BoardConfiguration:
#include <platform/driver/lcd/LCD4bpp.hpp> #include <touchgfx/hal/NoDMA.hpp> NoDMA dma; //dma not supported for 4bpp LCD4bpp lcd; //Change type of LCD driver to 4bpp hal.setFrameBufferStartAddress(adr, 4, ...); //change bitdepth = 4
Transferring frame buffer to the display
As mentioned, there are to our knowledge no on-chip TFT controllers that support 4bpp frame buffers. Therefore you need to manually transfer the frame buffer to the display. How to do this is described here.
There is currently no built-in support for using the DMA to draw images or solid color rectangles in 4bpp mode. This will likely be added in the future, but in the meantime you can add it yourself if you need to bring down the MCU load. To do this you need to create your own DMA component and use that instead of NoDMA in your BoardConfiguration. You can add support for BLIT_OP_COPY (transfer of solid bitmaps) and BLIT_OP_FILL (solid color rectangles). If such a DMA component is present, TouchGFX will delegate drawing to this component. Because the number of bits per pixel is less than 8 and it is usually not possible to use a DMA to transfer only some bits of a byte, TouchGFX will take into account the alignment of the data. TouchGFX will only delegate byte-aligned transfers to the DMA. In case of unaligned transfers, TouchGFX will, if possible, draw the first and trailing pixels of a line in order to get aligned, and then delegate the aligned part to the DMA.