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)¶
framesizeOne of the standard supported resolutions (see thedisplaymodule constants).refreshSets the screen refresh rate in hertz (30-120). This controls the RGB LCD pixel clock.display_onEnables the local LCD output. PassFalseon 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_bufferIfTrue, makes updates to the screen non-blocking at the cost of 3x the display size in RAM.portraitSwaps the framesize width and height.controllerPass a controller chip class instance to initialize it along with the display.backlightPass 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.
- clear(display_off: bool = False) None¶
Clears the LCD screen to black.
display_offifTrue, 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
DACBacklightorPWMBacklightcontroller 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
imagewhose top-left corner starts at locationx,y. A path string may also be passed instead of an image object to automatically load the image from disk.x_scalecontrols how much the displayed image is scaled by in the x direction. If this value is negative the image will be flipped horizontally. Ify_scaleis not specified it will matchx_scaleto maintain the aspect ratio.y_scalecontrols 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). Ifx_scaleis not specified it will matchy_scaleto maintain the aspect ratio.roiis the region-of-interest rectangle tuple(x, y, w, h)of the image to display.rgb_channelis the RGB channel (0=R, 1=G, 2=B) to extract from an RGB565 image and render in grayscale.-1disables channel extraction.alphacontrols how opaque the image is, from 0 (fully transparent / black) to 255 (opaque).color_palettean RGB565 image of 256 pixels total used as a color lookup table on the grayscale value of the input image. Applied afterrgb_channelextraction. May also be a palette enum (e.g.image.PALETTE_RAINBOW).alpha_palettea GRAYSCALE image of 256 pixels total used as a per-pixel alpha lookup table on the grayscale value of the input image. Applied afterrgb_channelextraction.hintis a logical OR of the flags:image.AREA: Use area scaling when downscaling instead of nearest neighbor.image.BILINEAR: Use bilinear scaling instead of nearest neighbor.image.BICUBIC: Use bicubic scaling instead of nearest neighbor.image.CENTER: Center the image on the display (applied after scaling).image.HMIRROR: Horizontally mirror the image.image.VFLIP: Vertically flip the image.image.TRANSPOSE: Transpose the image (swap x/y).image.EXTRACT_RGB_CHANNEL_FIRST: Dorgb_channelextraction before scaling.image.APPLY_COLOR_PALETTE_FIRST: Applycolor_palettebefore scaling.image.SCALE_ASPECT_KEEP: Scale the image to fit inside the display.image.SCALE_ASPECT_EXPAND: Scale the image to fill the display (cropping).image.SCALE_ASPECT_IGNORE: Scale the image to fill the display (stretching).image.ROTATE_90: Rotate by 90 degrees (VFLIP | TRANSPOSE).image.ROTATE_180: Rotate by 180 degrees (HMIRROR | VFLIP).image.ROTATE_270: Rotate by 270 degrees (HMIRROR | TRANSPOSE).