PHP code example of dept-of-scrapyard-robotics / st77xx

1. Go to this page and download the library: Download dept-of-scrapyard-robotics/st77xx library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dept-of-scrapyard-robotics / st77xx example snippets



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],
            ],
        ],        
    ]
];


use DeptOfScrapyardRobotics\Displays\ST77xx\ST7789\ST7789;

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


use DeptOfScrapyardRobotics\Displays\ST77xx\ST7789\ST7789;

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


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();

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);



use RealityInterface\Displays\Applied\FullColorTFT\ColorTFTDisplay;

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


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();