This article describes how to switch to 2bpp grayscale color mode. In this color mode, TouchGFX uses two bits per pixel, yielding a grayscale color space of four colors. In this mode, the frame buffer size in bytes is width * height / 4. Correspondingly, the size of bitmap images in flash is also width * height / 4.
- This article applies only to TouchGFX release 4.6.0 and later
The drag_example when TouchGFX is configured in 2bpp grayscale.
Supported hardware platforms
2bpp 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 2bpp frame buffers. This means that 2bpp 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 2bpp 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 2bpp mode
To enable 2bpp 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=2 # Settings for image converter output format opaque_image_format := GRAY2 non_opaque_image_format := GRAY2
If you use Visual Studio, modify the following:
<UseBPP>2</UseBPP> <OpaqueImageOutputFormat>GRAY2</OpaqueImageOutputFormat> <NonOpaqueImageOutputFormat>GRAY2</NonOpaqueImageOutputFormat>
By doing the above you should now be able to recompile the application and see the simulator running in 2bpp mode.
In order to run in 2bpp on target, you will need to also make some adjustments to your BoardConfiguration:
#include <platform/driver/lcd/LCD2bpp.hpp> #include <touchgfx/hal/NoDMA.hpp> NoDMA dma; //dma not supported for 2bpp LCD2bpp lcd; //Change type of LCD driver to 2bpp hal.setFrameBufferStartAddress(adr, 2, ...); //change bitdepth = 2
Transferring frame buffer to the display
As mentioned, there are to our knowledge no on-chip TFT controllers that support 2bpp 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. 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.