Created
February 20, 2026 22:18
-
-
Save akhenakh/49abc3714771ef3b342d85dea44c275c to your computer and use it in GitHub Desktop.
Waveshare rp2350 touch screen support for tinygo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "image/color" | |
| "machine" | |
| "time" | |
| "tinygo.org/x/drivers/st7789" | |
| ) | |
| func main() { | |
| // Give the board a moment to stabilize after power-up | |
| time.Sleep(time.Millisecond * 500) | |
| // Configure the SPI0 bus for the LCD | |
| // The C++ driver uses ~66.5MHz, but 40MHz is generally very stable | |
| // and fast enough for most TinyGo applications. | |
| machine.SPI0.Configure(machine.SPIConfig{ | |
| Frequency: 40_000_000, | |
| SCK: machine.LCD_CLK_PIN, | |
| SDO: machine.LCD_MOSI_PIN, | |
| SDI: machine.LCD_MISO_PIN, | |
| Mode: 0, | |
| }) | |
| // Initialize the ST7789 display | |
| display := st7789.New( | |
| machine.SPI0, | |
| machine.LCD_RST_PIN, | |
| machine.LCD_DC_PIN, | |
| machine.LCD_CS_PIN, | |
| machine.LCD_BL_PIN, | |
| ) | |
| // Configure the display resolution and rotation. | |
| // The native resolution is 240x320. We use ROTATION_90 to match | |
| // the "HORIZONTAL" orientation from your C++ example. | |
| display.Configure(st7789.Config{ | |
| Width: 240, | |
| Height: 320, | |
| Rotation: st7789.ROTATION_90, | |
| }) | |
| // Define some basic colors | |
| black := color.RGBA{R: 0, G: 0, B: 0, A: 255} | |
| red := color.RGBA{R: 255, G: 0, B: 0, A: 255} | |
| green := color.RGBA{R: 0, G: 255, B: 0, A: 255} | |
| blue := color.RGBA{R: 0, G: 0, B: 255, A: 255} | |
| white := color.RGBA{R: 255, G: 255, B: 255, A: 255} | |
| // Fill the screen with black to clear it | |
| display.FillScreen(black) | |
| // Get the current dimensions (should be 320x240 due to Rotation 90) | |
| width, height := display.Size() | |
| // Draw a 4-quadrant test pattern | |
| display.FillRectangle(0, 0, width/2, height/2, white) | |
| display.FillRectangle(width/2, 0, width/2, height/2, red) | |
| display.FillRectangle(0, height/2, width/2, height/2, green) | |
| display.FillRectangle(width/2, height/2, width/2, height/2, blue) | |
| // Draw a central black rectangle | |
| display.FillRectangle(width/4, height/4, width/2, height/2, black) | |
| // Keep the microcontroller running | |
| for { | |
| time.Sleep(time.Second) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment