class RGBDisplay – RGB Display Driver¶
The RGBDisplay class drives 24-bit parallel RGB LCDs via the LTDC controller.
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 display. PassFalsewhen the 24-bit parallel LCD output is shared by multiple devices (e.g. the TFP410 chip for driving HDMI displays) to keep the display off while still driving the data bus.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).