Skip to content

DisplayConfig

Configuration settings for initializing the display.

Description

DisplayConfig holds display parameters used by the renderer and camera to draw correctly on the target device. It defines the display type, dimensions, rotation, and creates the appropriate DrawSurface implementation for the platform.

Namespace

namespace pixelroot32::graphics {
    struct DisplayConfig {
        // ...
    };
}

DisplayType Enum

Supported display types:

  • DisplayType::ST7789: 240x240 TFT display
  • DisplayType::ST7735: 128x128 TFT display
  • DisplayType::NONE: For SDL2 native (no driver needed)

Structure

DisplayType type

The type of display.

Type: DisplayType enum

Access: Read-write

Notes: - Determines which driver to use (ESP32) - NONE for Native/SDL2 platform

int rotation

Display rotation in degrees.

Type: int

Access: Read-write

Default: 0

Notes: - Common values: 0, 90, 180, 270 - Rotation is applied during initialization - Some displays may not support all rotations

uint16_t width

Display width in pixels.

Type: uint16_t

Access: Read-write

Default: 240

Notes: - Should match actual display width - Used for viewport and camera calculations

uint16_t height

Display height in pixels.

Type: uint16_t

Access: Read-write

Default: 240

Notes: - Should match actual display height - Used for viewport and camera calculations

int xOffset

X offset for display alignment.

Type: int

Access: Read-write

Default: 0

Notes: - Used to adjust display position - Some displays need offset for proper alignment

int yOffset

Y offset for display alignment.

Type: int

Access: Read-write

Default: 0

Notes: - Used to adjust display position - Some displays need offset for proper alignment

DrawSurface& getDrawSurface() const

Gets the underlying DrawSurface implementation.

Returns: - DrawSurface&: Reference to the DrawSurface

Notes: - Advanced usage: typically not needed - Provides access to low-level display driver - Platform-specific implementation

Constructors

DisplayConfig(DisplayType type, const int rot = 0, uint16_t w = 240, uint16_t h = 240, const int xOffset = 0, const int yOffset = 0)

Constructs a DisplayConfig with specified parameters.

Parameters: - type (DisplayType): The display type - rot (int, optional): Rotation in degrees. Default: 0 - w (uint16_t, optional): Width in pixels. Default: 240 - h (uint16_t, optional): Height in pixels. Default: 240 - xOffset (int, optional): X offset. Default: 0 - yOffset (int, optional): Y offset. Default: 0

Notes: - Automatically creates the appropriate DrawSurface for the platform - ESP32: Creates TFT_eSPI_Drawer based on display type - Native: Creates SDL2_Drawer

Example:

// ST7789 display, 240x240, no rotation
pixelroot32::graphics::DisplayConfig config(
    pixelroot32::graphics::DisplayType::ST7789
);

// ST7735 display, 128x128, rotated 90 degrees
pixelroot32::graphics::DisplayConfig config(
    pixelroot32::graphics::DisplayType::ST7735,
    90,   // rotation
    128,  // width
    128   // height
);

// Native/SDL2 (no specific display type)
pixelroot32::graphics::DisplayConfig config(
    pixelroot32::graphics::DisplayType::NONE,
    0,    // rotation
    128,  // width
    128   // height
);

Usage Examples

ESP32 with ST7789

#ifdef PLATFORM_ESP32
#include "graphics/DisplayConfig.h"

void setup() {
    // Configure ST7789 display (240x240)
    pixelroot32::graphics::DisplayConfig displayConfig(
        pixelroot32::graphics::DisplayType::ST7789,
        0,    // rotation
        240,  // width
        240   // height
    );

    // Use with Engine
    pixelroot32::core::Engine engine(displayConfig);
    engine.init();
    engine.run();
}
#endif

ESP32 with ST7735

#ifdef PLATFORM_ESP32
    // Configure ST7735 display (128x128)
    pixelroot32::graphics::DisplayConfig displayConfig(
        pixelroot32::graphics::DisplayType::ST7735,
        0,    // rotation
        128,  // width
        128   // height
    );
#endif

Native/SDL2

#ifdef PLATFORM_NATIVE
    // Native display (SDL2 window)
    pixelroot32::graphics::DisplayConfig displayConfig(
        pixelroot32::graphics::DisplayType::NONE,
        0,    // rotation
        128,  // width
        128   // height
    );
#endif

Platform-Agnostic Setup

#include "graphics/DisplayConfig.h"
#include "core/Engine.h"

void setup() {
    pixelroot32::graphics::DisplayConfig displayConfig;

    #ifdef PLATFORM_ESP32
        displayConfig.type = pixelroot32::graphics::DisplayType::ST7789;
        displayConfig.width = 240;
        displayConfig.height = 240;
    #elif PLATFORM_NATIVE
        displayConfig.type = pixelroot32::graphics::DisplayType::NONE;
        displayConfig.width = 128;
        displayConfig.height = 128;
    #endif

    displayConfig.rotation = 0;

    pixelroot32::core::Engine engine(displayConfig);
    engine.init();
    engine.run();
}

Display Type Details

ST7789

  • Resolution: Typically 240x240 or 240x320
  • Interface: SPI
  • Driver: TFT_eSPI
  • Common sizes: 240x240, 240x320

ST7735

  • Resolution: Typically 128x128 or 128x160
  • Interface: SPI
  • Driver: TFT_eSPI
  • Common sizes: 128x128, 128x160

NONE (Native)

  • Platform: Native/SDL2
  • Driver: SDL2_Drawer
  • Resolution: Configurable (any size)
  • Window: Creates SDL2 window

Rotation

Display rotation values:

  • 0: Normal orientation
  • 90: Rotated 90 degrees clockwise
  • 180: Rotated 180 degrees
  • 270: Rotated 90 degrees counter-clockwise

Notes: - Rotation affects coordinate system - Some displays may not support all rotations - Test rotation on your specific hardware

Performance Considerations

  • Initialization: Display initialization happens once at startup
  • Driver selection: Automatic based on platform and type
  • Memory: DisplayConfig is small (few fields)

ESP32 Considerations

TFT_eSPI Configuration

DisplayConfig uses TFT_eSPI driver. Additional configuration may be needed in platformio.ini:

build_flags =
    -DUSER_SETUP_LOADED=1
    -DST7789_DRIVER=1
    -DTFT_WIDTH=240
    -DTFT_HEIGHT=240
    # ... pin configuration

Pin Configuration

GPIO pins must be configured separately (not in DisplayConfig):

  • MOSI: Data pin
  • SCLK: Clock pin
  • DC: Data/Command pin
  • RST: Reset pin
  • CS: Chip select pin (optional)

See Also