tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/st7789/main.go (about)

     1  package main
     2  
     3  import (
     4  	"machine"
     5  
     6  	"image/color"
     7  
     8  	"tinygo.org/x/drivers/st7789"
     9  )
    10  
    11  func main() {
    12  
    13  	// Example configuration for Adafruit Clue
    14  	// machine.SPI1.Configure(machine.SPIConfig{
    15  	//	Frequency: 8000000,
    16  	//	SCK:       machine.TFT_SCK,
    17  	//	SDO:       machine.TFT_SDO,
    18  	//	SDI:       machine.TFT_SDO,
    19  	//	Mode:      0,
    20  	// })
    21  	// display := st7789.New(machine.SPI1,
    22  	//	machine.TFT_RESET,
    23  	//	machine.TFT_DC,
    24  	//	machine.TFT_CS,
    25  	//	machine.TFT_LITE)
    26  
    27  	machine.SPI0.Configure(machine.SPIConfig{
    28  		Frequency: 8000000,
    29  		Mode:      0,
    30  	})
    31  	display := st7789.New(machine.SPI0,
    32  		machine.P6, // TFT_RESET
    33  		machine.P7, // TFT_DC
    34  		machine.P8, // TFT_CS
    35  		machine.P9) // TFT_LITE
    36  
    37  	display.Configure(st7789.Config{
    38  		Rotation:   st7789.NO_ROTATION,
    39  		RowOffset:  80,
    40  		FrameRate:  st7789.FRAMERATE_111,
    41  		VSyncLines: st7789.MAX_VSYNC_SCANLINES,
    42  	})
    43  
    44  	width, height := display.Size()
    45  
    46  	white := color.RGBA{255, 255, 255, 255}
    47  	red := color.RGBA{255, 0, 0, 255}
    48  	blue := color.RGBA{0, 0, 255, 255}
    49  	green := color.RGBA{0, 255, 0, 255}
    50  	black := color.RGBA{0, 0, 0, 255}
    51  
    52  	display.FillScreen(black)
    53  
    54  	display.FillRectangle(0, 0, width/2, height/2, white)
    55  	display.FillRectangle(width/2, 0, width/2, height/2, red)
    56  	display.FillRectangle(0, height/2, width/2, height/2, green)
    57  	display.FillRectangle(width/2, height/2, width/2, height/2, blue)
    58  	display.FillRectangle(width/4, height/4, width/2, height/2, black)
    59  }