class RGBDisplay – RGB Display Driver

The RGBDisplay class drives 24-bit parallel RGB LCDs through the STM32 LTDC (LCD-TFT) controller. The LTDC streams pixels directly out of an SDRAM-backed framebuffer at the chosen pixel clock, so high refresh rates (up to 120 Hz) are possible without CPU involvement.

On the OpenMV Cam Pure Thermal the same 24-bit parallel bus also feeds an on-board TFP410 HDMI encoder, so its HDMI output is driven through this class too – use display_on=False to blank the on-board LCD while still clocking pixels to the encoder.

Panel resolution is selected through framesize using the constants defined in the display module (QVGA, VGA, WVGA, HD, FHD, …). Panel-specific initialisation sequences are plugged in via the controller keyword argument (for example ST7701 for ST7701-based panels). Backlight brightness is driven as a simple GPIO by default, or by DACBacklight / PWMBacklight if one is passed as backlight.

Frames are presented by calling write() with an image.Image. The driver handles RGB conversion, scaling, ROI, palette and orientation transforms internally.

Example – mirror the camera onto a 480x272 panel at 60 Hz:

import csi
import display
import image

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)

lcd = display.RGBDisplay(framesize=display.FHVGA, refresh=60)

while True:
    lcd.write(csi0.snapshot(), hint=image.SCALE_ASPECT_KEEP)

Constructors

class display.RGBDisplay(framesize: int = display.FWVGA, refresh: int = 60, display_on: bool = True, triple_buffer: bool = True, portrait: bool = False, controller: object | None = None, backlight: object | None = None)

framesize One of the standard supported resolutions (see the display module constants).

refresh Sets the screen refresh rate in hertz (30-120). This controls the RGB LCD pixel clock.

display_on Enables the local LCD output. Pass False on the OpenMV Cam Pure Thermal, whose 24-bit parallel bus drives both the on-board LCD and the TFP410 HDMI encoder – this keeps the on-board LCD blanked while still feeding the HDMI encoder. On other OpenMV Cams there is no shared sink and this can be left at its default.

triple_buffer If True, makes updates to the screen non-blocking at the cost of 3x the display size in RAM.

portrait Swaps the framesize width and height.

controller Pass a controller chip class instance to initialize it along with the display.

backlight Pass a backlight controller module instance to use. By default the backlight will be controlled via a GPIO pin.

deinit() None

Releases the I/O pins and RAM used by the class. This is called automatically on destruction.

width() int

Returns the width of the screen.

height() int

Returns the height of the screen.

triple_buffer() bool

Returns whether triple buffering is enabled.

bgr() bool

Returns whether the red and blue channels are swapped.

byte_swap() bool

Returns whether the RGB565 pixel bytes are swapped on output.

framesize() int

Returns the framesize constant the display was configured with.

refresh() int

Returns the refresh rate.

clear(display_off: bool = False) None

Clears the LCD screen to black.

display_off if True, turns off the display logic instead of clearing the framebuffer to black. You should also turn off the backlight after this to ensure the screen goes black, as many displays are white when only the backlight is on.

backlight(value: int | None = None) int

Sets the LCD backlight dimming value, from 0 (off) to 100 (on). Pass no arguments to get the current backlight value.

Unless a DACBacklight or PWMBacklight controller was passed to the constructor, the backlight is controlled as a GPIO pin and will only go from 0 (off) to non-zero (on).

write(image: image.Image, x: int = 0, y: int = 0, x_scale: float = 1.0, y_scale: float = 1.0, roi: Tuple[int, int, int, int] | None = None, rgb_channel: int = -1, alpha: int = 255, color_palette: image.Image | None = None, alpha_palette: image.Image | None = None, hint: int = 0) None

Displays an image whose top-left corner starts at location x, y. A path string may also be passed instead of an image object to automatically load the image from disk.

x_scale controls how much the displayed image is scaled by in the x direction. If this value is negative the image will be flipped horizontally. If y_scale is not specified it will match x_scale to maintain the aspect ratio.

y_scale controls how much the displayed image is scaled by in the y direction. If this value is negative the image will be flipped vertically (requires triple buffering). If x_scale is not specified it will match y_scale to maintain the aspect ratio.

roi is the region-of-interest rectangle tuple (x, y, w, h) of the image to display.

rgb_channel is the RGB channel (0=R, 1=G, 2=B) to extract from an RGB565 image and render in grayscale. -1 disables channel extraction.

alpha controls how opaque the image is, from 0 (fully transparent / black) to 255 (opaque).

color_palette an RGB565 image of 256 pixels total used as a color lookup table on the grayscale value of the input image. Applied after rgb_channel extraction. May also be a palette enum (e.g. image.PALETTE_RAINBOW).

alpha_palette a GRAYSCALE image of 256 pixels total used as a per-pixel alpha lookup table on the grayscale value of the input image. Applied after rgb_channel extraction.

hint is a logical OR of the flags: