โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ disp API Contents โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ฆ disp โโ ๐ฅ Import โโ ๐ Overview โโ ๐บ Screen constants โโ ๐งท Board constants โโ โ๏ธ disp.init(...) โโ ๐ Logical framebuffer sizes โโ ๐งฑ Board presets โโ ๐ผ๏ธ Showing the framebuffer โโ ๐จ Filling the screen โโ ๐ Palette helpers โโ ๐ฅ Camera helpers โโ ๐ Screen info โโ ๐งต Buffer access โโ ๐ Buffer copy helpers โโ ๐ Orientation
๐ฆ API Reference: disp
The disp module manages display initialization, the global framebuffer, palette state, camera state, and screen presentation.
๐ฅ Import
from retroPy import disp
๐ Overview
The current implementation uses global display state, including:
- a global 8-bit framebuffer
- global logical width and height
- a global palette lookup table
- global camera position and mode
This makes disp the foundation of screen setup and presentation.
๐บ Screen constants
The module exposes these screen type constants:
disp.TYPE_ST7735disp.TYPE_ST7789_240disp.TYPE_ST7789_320
Aliases are also provided:
disp.TYPE_160disp.TYPE_240disp.TYPE_320
๐งท Board constants
The module exposes these board constants:
disp.BD_WPCBdisp.BD_WPCBWdisp.BD_BPCBdisp.BD_CRE
These select preset LCD and button layouts.
โ๏ธ disp.init(...)
Initializes display state, allocates the framebuffer, resets the palette, initializes the lower-level RGB driver, and applies screen and board settings.
Signature
disp.init(
spi,
reset=0,
dc=0,
cs=0,
backlight=0,
rotation=0,
board=0,
screen=0,
ff=180,
)
Arguments
spi
The SPI object used by the display driver on hardware platforms.
reset, dc, cs, backlight
Manual pin assignments when not using a board preset.
rotation
Initial rotation value.
board
Board preset selector.
screen
Screen type selector.
ff
Requested CPU frequency multiplier in MHz for hardware builds.
Example: typical 240x240 init
from retroPy import *
import machine
disp.init(
machine.SPI(0, 24_000_000, sck=6, mosi=7, polarity=1, phase=1),
screen=disp.TYPE_240,
board=disp.BD_CRE,
)
What init() does
In the current implementation, disp.init():
- stores the screen type
- applies board defaults or manual pin setup
- resets global camera state
- sets logical size and framebuffer size
- allocates the global framebuffer
- clears the framebuffer
- resets the color palette
- calls the lower-level RGB init routine
- performs some platform-specific startup work
๐ Logical framebuffer sizes
disp.TYPE_160
Uses a logical framebuffer of 160 x 80.
disp.TYPE_240
Uses a logical framebuffer of 240 x 240.
disp.TYPE_320
Uses a logical framebuffer of 320 x 240 or 240 x 320, depending on rotation.
๐งฑ Board presets
disp.BD_WPCB
White console preset.
disp.BD_WPCBW
Another white console preset variant.
disp.BD_BPCB
Black PCB preset.
disp.BD_CRE
Creatures board preset.
๐ผ๏ธ Showing the framebuffer
disp.show()
Flushes the active global framebuffer to the display.
disp.show()
disp.showBuff(buffer)
Flushes a supplied buffer instead of the default global framebuffer.
disp.showBuff(buf)
๐จ Filling the screen
disp.fill(color)
Fills the framebuffer with a palette index.
disp.fill(0)
๐ Palette helpers
disp.color_ndx(index)
Returns the RGB565 color currently stored at a palette index.
value = disp.color_ndx(3)
disp.color_ndx(index, value)
Sets the RGB565 value for a palette index.
disp.color_ndx(3, 0xFFFF)
disp.color_palette(buffer)
Copies a full 256-entry palette into the active palette table.
disp.color_palette(palette_buf)
disp.color_reset()
Restores the palette to the built-in default.
disp.color_reset()
๐ฅ Camera helpers
disp.cam_pos_x() / disp.cam_pos_x(value)
Gets or sets camera X.
disp.cam_pos_y() / disp.cam_pos_y(value)
Gets or sets camera Y.
disp.cam_mode() / disp.cam_mode(value)
Gets or sets camera mode.
disp.cam_pos(x, y)
Sets both camera coordinates.
disp.cam_mode(1)
disp.cam_pos(12, 20)
๐ Screen info
disp.type()
Returns the current screen type constant.
disp.width()
Returns the current logical width.
disp.height()
Returns the current logical height.
print(disp.type())
print(disp.width(), disp.height())
๐งต Buffer access
disp.get_buffer()
Returns a bytearray by reference to the global framebuffer.
buf = disp.get_buffer()
buf[0] = 8
Because the return value is by reference, changes to this bytearray affect the active framebuffer directly.
๐ Buffer copy helpers
disp.copyB2B(dest, src)
Copies one buffer to another.
Buffer copy note
The old helpers disp.copy2B, disp.copyB, disp.copy2BEx, and disp.copyBEx were removed.
Use these instead:
disp.get_buffer()for direct access to the main framebufferdisp.showBuff(buf)to show a buffer on screencanvas.copy_from_screen(...),canvas.copy_from_canvas(...), andcanvas.copy_from_obj(...)for composition and region copyingdisp.copyB2B(dest, src)only when you need a low-level full-buffer memcpy between two buffers
๐ Orientation
disp.orientation(value)
Sets display orientation.
disp.orientation(1)