承接 dept-of-scrapyard-robotics/st77xx 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dept-of-scrapyard-robotics/st77xx

Composer 安装命令:

composer require dept-of-scrapyard-robotics/st77xx

包简介

Drive ST77xx family of TFT LCD displays over SPI with PHP

README 文档

README

PHP Package for the ST77xx family of full-color TFT displays. Three controllers are supported, each with its own driver class:

  • ST7735 — 128x160 color TFT
  • ST7789 — 240x320 color TFT
  • ST7796 — 480x320 color TFT

All three drive 16-bit (RGB565) color by default and share an identical connection and usage surface; only the class name and default resolution differ.

Compatible SPI Interfaces

The ST77xx displays communicate with your device over SPI, the Serial Peripheral Interface.

You can interface with displays such as the ST77xx with this package the following ways:

  • A Linux Single-Board Computer's exposed GPIO pins using the dedicated SPI MOSI/SCK and CS pins as well as 2 GPIO pins for DC and RST.
  • An MPSSE-enabled USB-to-Serial device such as an FT232H generally using D0 and SCK, D1 for MOSI, D2 for MISO and D3 for CS, D4 and D5 for RST/DC and connected to nearly any Linux or MacOS USB port.

Dependencies

This package makes use of modules within:

This package also requires one of the following extensions in order to interface with SPI

In addition, an extension wrapper package is needed

For ext-posi

For ext-ftdi

Installing from Composer

Inside the root of your PHP Project, simply require the ST77xx package from composer

composer require dept-of-scrapyard-robotics/st77xx

Framework Configuration

If you would like to use the ScrapyardIO Framework to bootstrap your display without wasting lines configuring your display right in the script you can add your desired configuration to scrapyard-io.php, such as in this example:

SPI

use DeptOfScrapyardRobotics\Displays\ST77xx\ST7789\ST7789;

return [
    'displays' => [
        // For Native Configurations 
        'st7789-native' => [
            'class_name' => ST7789::class,
            'connection' => ['driver' => 'native'],
            'startup' => [
                'spi' => [0, 0],
                'gpiochip' => [0],
                'rst' => [24],
                'dc' => [22],
            ],
        ],
        // For USB Configurations
        'st7789-usb' => [
            'class_name' => ST7789::class,
            'connection' => ['driver' => 'usb'],
            'startup' => [
                'spi' => ['ft232h', 0],
                'gpiochip' => ['ft232h'],
                'rst' => [0],
                'dc' => [1],
            ],
        ],        
    ]
];

Basic Usage

The examples below use the ST7789. Swap the class for ST7735 or ST7796 (under the same DeptOfScrapyardRobotics\Displays\ST77xx\... namespace) to drive those controllers — the builder chain is identical.

Native (POSIX) SPI driver. (Single Board Computers)

use DeptOfScrapyardRobotics\Displays\ST77xx\ST7789\ST7789;

$native_spi_display = ST7789::connection('native')
    ->spi(0, 0)
    ->gpiochip(0)
    ->rst(24)
    ->dc(22)
    ->create()

USB (MPSSE) driver using SPI. (Linux and MacOS)

use DeptOfScrapyardRobotics\Displays\ST77xx\ST7789\ST7789;

$usb_spi_display = ST7789::connection('usb')
    ->spi('ft232h', 0)
    ->gpiochip('ft232h')
    ->rst(0)
    ->dc(1)
    ->create()

Other controllers

use DeptOfScrapyardRobotics\Displays\ST77xx\ST7735\ST7735;
use DeptOfScrapyardRobotics\Displays\ST77xx\ST7796\ST7796;

$st7735 = ST7735::connection('usb')->spi('ft232h', 0)->gpiochip('ft232h')->rst(0)->dc(1)->create();
$st7796 = ST7796::connection('usb')->spi('ft232h', 0)->gpiochip('ft232h')->rst(0)->dc(1)->create();

Alternative Usage

Using Through the Display Library (as a ColorTFTDisplay)

use DeptOfScrapyardRobotics\Displays\ST77xx\ST7789\ST7789;
use RealityInterface\Displays\Applied\FullColorTFT\ColorTFTDisplay;

$st7789 = ST7789::connection('usb')
    ->spi('ft232h', 0)
    ->gpiochip('ft232h')
    ->rst(0)
    ->dc(1)
    ->create()
    
$display = ColorTFTDisplay::as($st7789);

Using Through the Display Framework (with an autoloaded config) (as a ColorTFTDisplay)

use RealityInterface\Displays\Applied\FullColorTFT\ColorTFTDisplay;

$display = ColorTFTDisplay::using('st7789-usb');

Display API

The setters in this API interface with the device directly (register writes), so you can use property access while still working against the panel itself. The three controllers share most properties but each exposes its own register set.

ST7735

Readable Properties (Getters)

  • $display->display_on — Returns whether the panel is on.
  • $display->sleep_mode_enabled — Returns whether sleep mode is active.
  • $display->color_mode (ST7735ColorMode) — Returns the current pixel format.

Writable Properties (Setters)

  • $display->display_on = true; — Turns the panel on or off.
  • $display->sleep_mode_enabled = false; — Enters or exits sleep mode.
  • $display->frctl_normal = ...; — Frame-rate control for normal mode.
  • $display->frctl_idle = ...; — Frame-rate control for idle mode.
  • $display->frctl_partial = ...; — Frame-rate control for partial mode.
  • $display->power_control1 = ...; through power_control5 — Power control registers.
  • $display->v_com_control = ...; — VCOM control.
  • $display->display_inversion_enabled = false; — Enables/disables color inversion.
  • $display->mad_control = ...; — Memory access control (orientation / RGB-BGR).
  • $display->color_mode = ST7735ColorMode::COLOR16; — Sets the pixel format.
  • $display->color_gamma_positive = ...; — Positive gamma curve.
  • $display->color_gamma_negative = ...; — Negative gamma curve.
  • $display->normal_mode_on = true; — Returns to normal display mode.

ST7789

Readable Properties (Getters)

There are no readable magic properties exposed for the ST7789 in this package.

Writable Properties (Setters)

  • $display->display_on = true; — Turns the panel on or off.
  • $display->sleep_mode_enabled = false; — Enters or exits sleep mode.
  • $display->porch_control = ...; — Porch setting.
  • $display->gate_control = ...; — Gate driver control.
  • $display->v_com_control = ...; — VCOM setting.
  • $display->lcm_control = ...; — LCM control.
  • $display->vdv_vrh_enabled = ...; — Enables VDV/VRH command-write control.
  • $display->vrh = ...; — VRH (VAP/VAN) set.
  • $display->vdv = ...; — VDV set.
  • $display->frctl_normal = ...; — Frame-rate control for normal mode.
  • $display->power_control1 = ...; — Power control register 1.
  • $display->display_inversion_enabled = false; — Enables/disables color inversion.
  • $display->mad_control = ...; — Memory access control (orientation / RGB-BGR).
  • $display->pixel_format = ST7789ColorMode::COLOR16; — Sets the pixel format.
  • $display->color_gamma_positive = ...; — Positive gamma curve.
  • $display->color_gamma_negative = ...; — Negative gamma curve.
  • $display->normal_mode_on = true; — Returns to normal display mode.

ST7796

Readable Properties (Getters)

There are no readable magic properties exposed for the ST7796 in this package.

Writable Properties (Setters)

  • $display->display_on = true; — Turns the panel on or off.
  • $display->sleep_mode_enabled = false; — Enters or exits sleep mode.
  • $display->mad_control = ...; — Memory access control (orientation / RGB-BGR).
  • $display->pixel_format = ST7796ColorMode::COLOR16; — Sets the pixel format.
  • $display->inversion_control = ...; — Display inversion control.
  • $display->display_function_control = ...; — Display function control.
  • $display->display_output_ctrl_adjust = ...; — Display output control adjustment.
  • $display->power_control2 = ...; — Power control register 2.
  • $display->power_control3 = ...; — Power control register 3.
  • $display->v_com_control = ...; — VCOM control.
  • $display->display_inversion_enabled = false; — Enables/disables color inversion.
  • $display->color_gamma_positive = ...; — Positive gamma curve.
  • $display->color_gamma_negative = ...; — Negative gamma curve.
  • $display->normal_mode_on = true; — Returns to normal display mode.

Drawing on the Display

Draw with a Screen, which wraps a GFXRenderer over a frame buffer matched to the panel's FormatSpec, then ships the bytes on render(). A colour TFT uses a DirtyRegionsBuffer (coalesces changed rectangles, one update per region). Colors are 16-bit RGB565 integers (e.g. 0xF800 red, 0x07E0 green, 0x001F blue).

use DeptOfScrapyardRobotics\Displays\ST77xx\ST7789\ST7789;
use Microscrap\GFX\PhpdaFruit\Buffers\DirtyRegionsBuffer;
use Microscrap\GFX\PhpdaFruit\GFXRenderer;
use RealityInterface\Displays\Applied\FullColorTFT\ColorTFTDisplay;
use RealityInterface\Displays\Screen;

$st7789 = ST7789::connection('usb')
    ->spi('ft232h', 0)
    ->gpiochip('ft232h')
    ->rst(0)
    ->dc(1)
    ->create();

$display = ColorTFTDisplay::as($st7789);

$buffer = new DirtyRegionsBuffer($display->width(), $display->height(), $display->getFormatSpec());
$screen = new Screen($display, new GFXRenderer($buffer));

$screen
    ->fill(0x0000)
    ->drawRoundRect(0, 0, $display->width(), $display->height(), 12, 0xFFFF)
    ->fillCircle(intdiv($display->width(), 2), 80, 24, 0xF800)
    ->setTextColor(0x07E0)
    ->setTextSize(3)
    ->setCursor(20, 40)
    ->print('Hello')
    ->render();

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固