English
English
简体中文
日本語

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

CoreP4X Display

APIs and example programs related to the display of CoreP4X.

Note
CoreP4X uses the M5GFX library as the display driver. Refer to the API and example below for basic display operations. For more display APIs, refer to the M5GFX documentation.

Example Program

Compilation Requirements

  • M5Stack Board Manager version >= 3.3.10-a
  • Board selection = M5CoreP4X
  • M5Unified library version >= 0.3.1
  • M5GFX library version >= 0.3.1

The display reset is controlled by M5IOE1 IO11, the backlight by M5IOE1 IO9/PWM1, the display power by M5IOE1 IO10, and the touch reset by M5IOE1 IO8. After power-on, M5Unified automatically completes panel initialization and power enabling.

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#include <M5Unified.h>

M5Canvas canvas(&M5.Display);

static void drawBorder()
{
  const int screenW = M5.Display.width();
  const int screenH = M5.Display.height();

  canvas.drawRect(0, 0, screenW, screenH, TFT_BLACK);
  canvas.drawRect(4, 4, screenW - 8, screenH - 8, TFT_BLACK);
  canvas.drawRect(8, 8, screenW - 16, screenH - 16, TFT_BLACK);
}

static void drawMainDemo()
{
  const int screenW = M5.Display.width();
  const int centerX = screenW / 2;

  canvas.fillSprite(TFT_WHITE);
  drawBorder();

  canvas.setTextDatum(middle_center);
  canvas.setTextSize(1);

  canvas.setFont(&fonts::FreeSansBold24pt7b);
  canvas.setTextColor(TFT_BLACK);
  canvas.drawString("CORE", centerX, 150);

  canvas.setTextColor(TFT_BLUE);
  canvas.drawString("P4X", centerX, 214);

  canvas.setFont(&fonts::FreeSansBold12pt7b);
  canvas.setTextColor(TFT_BLACK);
  canvas.drawString("Panel: ST7102 + CST3530", centerX, 292);

  char resolutionText[32];
  snprintf(resolutionText, sizeof(resolutionText), "Resolution: %d x %d", screenW, M5.Display.height());
  canvas.setFont(&fonts::FreeSans18pt7b);
  canvas.setTextColor(TFT_BLUE);
  canvas.drawString(resolutionText, centerX, 338);

  canvas.setFont(&fonts::FreeSans12pt7b);
  canvas.setTextColor(TFT_BLACK);
  canvas.drawString("MIPI DSI 2-Lane", centerX, 382);

  const uint16_t colors[] = {
    TFT_RED, TFT_YELLOW, TFT_GREEN, TFT_CYAN, TFT_BLUE, TFT_MAGENTA
  };
  const int barX = 40;
  const int barY = 420;
  const int barW = screenW - 80;
  const int barH = 36;
  const int cellW = barW / 6;

  for (int i = 0; i < 6; ++i) {
    const int x = barX + i * cellW;
    const int w = (i == 5) ? (barX + barW - x) : cellW;
    canvas.fillRect(x, barY, w, barH, colors[i]);
    canvas.drawRect(x, barY, w, barH, TFT_BLACK);
  }

  canvas.pushSprite(0, 0);
}

void setup()
{
  auto cfg = M5.config();
  cfg.serial_baudrate = 115200;
  M5.begin(cfg);

  M5.Display.setRotation(0);
  M5.Display.setBrightness(160);
  canvas.createSprite(M5.Display.width(), M5.Display.height());
  drawMainDemo();

  Serial.printf("display: %d x %d\n", M5.Display.width(), M5.Display.height());
}

void loop()
{
  M5.update();
  delay(100);
}

After uploading, the screen displays the CoreP4X product name, ST7102 panel information, 480 x 480 resolution, MIPI DSI interface description, and a six-color test bar at the bottom on a white background.

Page Tools
PDF
On This Page