Skip to content

displaybuf

displaybuf

displaybuf

FrameBuffer wrapper for using framebuf based GUIs with displaysys. Works with MicroPython Nano-GUI, Micro-GUI and MicroPython-Touch from Peter Hinch, but may also be used without them.

Usage

'color_setup.py' from displaybuf import DisplayBuffer as SSD from board_config import display_drv

format = SSD.RGB565  # or .GS8 or .GS4_HMSB

ssd = SSD(display_drv, format)

'main.py' from color_setup import ssd

Classes

DisplayBuffer

DisplayBuffer(display_drv, format=framebuf.RGB565, stride=8)

Wrap a displaysys driver with a framebuf-compatible logical framebuffer.

Call show() to copy the buffer to the physical display. Supported formats: DisplayBuffer.RGB565, DisplayBuffer.GS8, DisplayBuffer.GS4_HMSB.

Allocate a logical framebuffer backed by display_drv.

Parameters:

Name Type Description Default
display_drv

A displaysys driver (BusDisplay, SDL2Display, etc.).

required
format

One of RGB565, GS8, or GS4_HMSB.

RGB565
stride

Lines per chunk for GS8/GS4 bounce buffers (MicroPython viper).

8

Attributes:

Name Type Description
show

Bound to _show16, _show8, or _show4 — call to flush buffer to panel.

Methods:
color staticmethod
color(r, g, b, idx=None)

Get an RGB565 or RGB332 value for a color and optionally register it in the display's LUT. This is a convenience function for using this framework WITHOUT Nano-GUI or Micro-GUI. Those packages have their own methods of registering colors.

Parameters:

Name Type Description Default
r int

Red component (0-255)

required
g int

Green component (0-255)

required
b int

Blue component (0-255)

required
idx int

Optional index to register the color in the display's LUT (0-15); ignored if the display doesn't use a LUT in its current format

None

Raises:

Type Description
ValueError

If 16 colors have already been registered or if the index is out of range

Returns:

Type Description
int

RGB565 color value in RG565 format; RGB332 color value in GS8 format; the index of the registered color in the LUT in GS4_HMSB format