Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Created February 20, 2026 22:18
Show Gist options
  • Select an option

  • Save akhenakh/49abc3714771ef3b342d85dea44c275c to your computer and use it in GitHub Desktop.

Select an option

Save akhenakh/49abc3714771ef3b342d85dea44c275c to your computer and use it in GitHub Desktop.
Waveshare rp2350 touch screen support for tinygo
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)
}
}
//go:build waveshare_rp2350_touch_lcd_2
// This file contains the pin mappings for the Waveshare RP2350-Touch-LCD-2 board.
//
// - https://www.waveshare.com/wiki/RP2350-Touch-LCD-2
package machine
// GPIO pins
const (
GP0 Pin = GPIO0
GP1 Pin = GPIO1
GP2 Pin = GPIO2
GP3 Pin = GPIO3
GP4 Pin = GPIO4
GP5 Pin = GPIO5
GP6 Pin = GPIO6
GP7 Pin = GPIO7
GP8 Pin = GPIO8
GP9 Pin = GPIO9
GP10 Pin = GPIO10
GP11 Pin = GPIO11
GP12 Pin = GPIO12
GP13 Pin = GPIO13
GP14 Pin = GPIO14
GP15 Pin = GPIO15
GP16 Pin = GPIO16
GP17 Pin = GPIO17
GP18 Pin = GPIO18
GP19 Pin = GPIO19
GP20 Pin = GPIO20
GP21 Pin = GPIO21
GP22 Pin = GPIO22
GP26 Pin = GPIO26
GP27 Pin = GPIO27
GP28 Pin = GPIO28
GP29 Pin = GPIO29
// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)
// LCD pins (SPI0)
const (
LCD_RST_PIN Pin = GPIO20
LCD_DC_PIN Pin = GPIO16
LCD_BL_PIN Pin = GPIO15
LCD_CS_PIN Pin = GPIO17
LCD_CLK_PIN Pin = GPIO18
LCD_MOSI_PIN Pin = GPIO19
LCD_MISO_PIN Pin = GPIO4
)
// Touch panel pins (CST816D)
const (
TOUCH_RST_PIN Pin = GPIO20
TOUCH_INT_PIN Pin = GPIO29
)
// IMU pins (QMI8658)
const (
IMU_INT1_PIN Pin = GPIO14
)
// Analog pins
const (
A0 Pin = GPIO26
A1 Pin = GPIO27
A2 Pin = GPIO28
A3 Pin = GPIO29
BATTERY Pin = GPIO28
)
// I2C Default pins
const (
I2C0_SDA_PIN Pin = GPIO12
I2C0_SCL_PIN Pin = GPIO13
I2C1_SDA_PIN Pin = GPIO2
I2C1_SCL_PIN Pin = GPIO3
SDA_PIN = I2C0_SDA_PIN
SCL_PIN = I2C0_SCL_PIN
)
// SPI default pins
const (
// Default Serial Clock Bus 0 for SPI communications (Shared with LCD)
SPI0_SCK_PIN = LCD_CLK_PIN
// Default Serial Out Bus 0 for SPI communications
SPI0_SDO_PIN = LCD_MOSI_PIN // Tx
// Default Serial In Bus 0 for SPI communications
SPI0_SDI_PIN = LCD_MISO_PIN // Rx
// Default Serial Clock Bus 1 for SPI communications
SPI1_SCK_PIN = GPIO10
// Default Serial Out Bus 1 for SPI communications
SPI1_SDO_PIN = GPIO11 // Tx
// Default Serial In Bus 1 for SPI communications
SPI1_SDI_PIN = GPIO12 // Rx
)
// UART pins
const (
UART0_TX_PIN = GPIO0
UART0_RX_PIN = GPIO1
UART1_TX_PIN = GPIO8
UART1_RX_PIN = GPIO9
UART_TX_PIN = UART0_TX_PIN
UART_RX_PIN = UART0_RX_PIN
)
var DefaultUART = UART0
// USB identifiers
const (
usb_STRING_PRODUCT = "RP2350-Touch-LCD-2"
usb_STRING_MANUFACTURER = "Waveshare"
)
var (
usb_VID uint16 = 0x2E8A
usb_PID uint16 = 0x000F // Raspberry Pi RP2350 generic PID
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment