|
retroPy's glitchi
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                     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_ST7735
  • disp.TYPE_ST7789_240
  • disp.TYPE_ST7789_320

Aliases are also provided:

  • disp.TYPE_160
  • disp.TYPE_240
  • disp.TYPE_320

๐Ÿงท Board constants

The module exposes these board constants:

  • disp.BD_WPCB
  • disp.BD_WPCBW
  • disp.BD_BPCB
  • disp.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():

  1. stores the screen type
  2. applies board defaults or manual pin setup
  3. resets global camera state
  4. sets logical size and framebuffer size
  5. allocates the global framebuffer
  6. clears the framebuffer
  7. resets the color palette
  8. calls the lower-level RGB init routine
  9. 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 framebuffer
  • disp.showBuff(buf) to show a buffer on screen
  • canvas.copy_from_screen(...), canvas.copy_from_canvas(...), and canvas.copy_from_obj(...) for composition and region copying
  • disp.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)