mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 21:03:23 +00:00
ili9341: refactor examples/ili9341
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
//go:build atsamd21
|
|
||||||
// +build atsamd21
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI0,
|
|
||||||
machine.D0,
|
|
||||||
machine.D1,
|
|
||||||
machine.D2,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.D3
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{
|
|
||||||
SCK: machine.SPI0_SCK_PIN,
|
|
||||||
SDO: machine.SPI0_SDO_PIN,
|
|
||||||
SDI: machine.SPI0_SDI_PIN,
|
|
||||||
Frequency: 24000000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -2,9 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"machine"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||||
"tinygo.org/x/drivers/ili9341"
|
"tinygo.org/x/drivers/ili9341"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,16 +16,15 @@ var (
|
|||||||
green = color.RGBA{0, 255, 0, 255}
|
green = color.RGBA{0, 255, 0, 255}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
display *ili9341.Device
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
display = initdisplay.InitDisplay()
|
||||||
|
|
||||||
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
|
||||||
|
|
||||||
display.Configure(ili9341.Config{})
|
|
||||||
width, height := display.Size()
|
width, height := display.Size()
|
||||||
|
|
||||||
display.FillScreen(black)
|
|
||||||
backlight.High()
|
|
||||||
|
|
||||||
display.FillRectangle(0, 0, width/2, height/2, white)
|
display.FillRectangle(0, 0, width/2, height/2, white)
|
||||||
display.FillRectangle(width/2, 0, width/2, height/2, red)
|
display.FillRectangle(width/2, 0, width/2, height/2, red)
|
||||||
display.FillRectangle(0, height/2, width/2, height/2, green)
|
display.FillRectangle(0, height/2, width/2, height/2, green)
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
//go:build pyportal
|
|
||||||
// +build pyportal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewParallel(
|
|
||||||
machine.LCD_DATA0,
|
|
||||||
machine.TFT_WR,
|
|
||||||
machine.TFT_DC,
|
|
||||||
machine.TFT_CS,
|
|
||||||
machine.TFT_RESET,
|
|
||||||
machine.TFT_RD,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.TFT_BACKLIGHT
|
|
||||||
)
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI3,
|
|
||||||
machine.LCD_DC,
|
|
||||||
machine.LCD_SS_PIN,
|
|
||||||
machine.LCD_RESET,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.LCD_BACKLIGHT
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI3.Configure(machine.SPIConfig{
|
|
||||||
SCK: machine.LCD_SCK_PIN,
|
|
||||||
SDO: machine.LCD_SDO_PIN,
|
|
||||||
SDI: machine.LCD_SDI_PIN,
|
|
||||||
Frequency: 40000000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
//go:build atsamd21
|
||||||
|
// +build atsamd21
|
||||||
|
|
||||||
|
package initdisplay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/ili9341"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ()
|
||||||
|
|
||||||
|
func InitDisplay() *ili9341.Device {
|
||||||
|
machine.SPI0.Configure(machine.SPIConfig{
|
||||||
|
SCK: machine.SPI0_SCK_PIN,
|
||||||
|
SDO: machine.SPI0_SDO_PIN,
|
||||||
|
SDI: machine.SPI0_SDI_PIN,
|
||||||
|
Frequency: 24000000,
|
||||||
|
})
|
||||||
|
|
||||||
|
// configure backlight
|
||||||
|
backlight := machine.D3
|
||||||
|
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
||||||
|
|
||||||
|
display := ili9341.NewSPI(
|
||||||
|
machine.SPI0,
|
||||||
|
machine.D0,
|
||||||
|
machine.D1,
|
||||||
|
machine.D2,
|
||||||
|
)
|
||||||
|
|
||||||
|
// configure display
|
||||||
|
display.Configure(ili9341.Config{})
|
||||||
|
|
||||||
|
backlight.High()
|
||||||
|
|
||||||
|
display.SetRotation(ili9341.Rotation270)
|
||||||
|
|
||||||
|
return display
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
//go:build pyportal
|
||||||
|
// +build pyportal
|
||||||
|
|
||||||
|
package initdisplay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/ili9341"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitDisplay() *ili9341.Device {
|
||||||
|
display := ili9341.NewParallel(
|
||||||
|
machine.LCD_DATA0,
|
||||||
|
machine.TFT_WR,
|
||||||
|
machine.TFT_DC,
|
||||||
|
machine.TFT_CS,
|
||||||
|
machine.TFT_RESET,
|
||||||
|
machine.TFT_RD,
|
||||||
|
)
|
||||||
|
|
||||||
|
// configure backlight
|
||||||
|
backlight := machine.TFT_BACKLIGHT
|
||||||
|
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
||||||
|
|
||||||
|
// configure display
|
||||||
|
display.Configure(ili9341.Config{})
|
||||||
|
|
||||||
|
backlight.High()
|
||||||
|
|
||||||
|
display.SetRotation(ili9341.Rotation270)
|
||||||
|
|
||||||
|
return display
|
||||||
|
}
|
||||||
+22
-13
@@ -1,7 +1,7 @@
|
|||||||
//go:build wioterminal
|
//go:build wioterminal
|
||||||
// +build wioterminal
|
// +build wioterminal
|
||||||
|
|
||||||
package main
|
package initdisplay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
"machine"
|
||||||
@@ -9,22 +9,31 @@ import (
|
|||||||
"tinygo.org/x/drivers/ili9341"
|
"tinygo.org/x/drivers/ili9341"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func InitDisplay() *ili9341.Device {
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI3,
|
|
||||||
machine.LCD_DC,
|
|
||||||
machine.LCD_SS_PIN,
|
|
||||||
machine.LCD_RESET,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.LCD_BACKLIGHT
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI3.Configure(machine.SPIConfig{
|
machine.SPI3.Configure(machine.SPIConfig{
|
||||||
SCK: machine.LCD_SCK_PIN,
|
SCK: machine.LCD_SCK_PIN,
|
||||||
SDO: machine.LCD_SDO_PIN,
|
SDO: machine.LCD_SDO_PIN,
|
||||||
SDI: machine.LCD_SDI_PIN,
|
SDI: machine.LCD_SDI_PIN,
|
||||||
Frequency: 40000000,
|
Frequency: 40000000,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// configure backlight
|
||||||
|
backlight := machine.LCD_BACKLIGHT
|
||||||
|
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
||||||
|
|
||||||
|
display := ili9341.NewSPI(
|
||||||
|
machine.SPI3,
|
||||||
|
machine.LCD_DC,
|
||||||
|
machine.LCD_SS_PIN,
|
||||||
|
machine.LCD_RESET,
|
||||||
|
)
|
||||||
|
|
||||||
|
// configure display
|
||||||
|
display.Configure(ili9341.Config{})
|
||||||
|
|
||||||
|
backlight.High()
|
||||||
|
|
||||||
|
display.SetRotation(ili9341.Rotation270)
|
||||||
|
|
||||||
|
return display
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||||
"tinygo.org/x/drivers/examples/ili9341/pyportal_boing/graphics"
|
"tinygo.org/x/drivers/examples/ili9341/pyportal_boing/graphics"
|
||||||
"tinygo.org/x/drivers/ili9341"
|
"tinygo.org/x/drivers/ili9341"
|
||||||
)
|
)
|
||||||
@@ -44,20 +44,17 @@ var (
|
|||||||
palette [16]uint16
|
palette [16]uint16
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
display *ili9341.Device
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
display = initdisplay.InitDisplay()
|
||||||
|
|
||||||
// configure backlight
|
|
||||||
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
|
||||||
|
|
||||||
// configure display
|
|
||||||
display.Configure(ili9341.Config{})
|
|
||||||
print("width, height == ")
|
print("width, height == ")
|
||||||
width, height := display.Size()
|
width, height := display.Size()
|
||||||
println(width, height)
|
println(width, height)
|
||||||
|
|
||||||
backlight.High()
|
|
||||||
|
|
||||||
display.SetRotation(ili9341.Rotation270)
|
|
||||||
DrawBackground()
|
DrawBackground()
|
||||||
|
|
||||||
startTime = time.Now().UnixNano()
|
startTime = time.Now().UnixNano()
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
//go:build pyportal
|
|
||||||
// +build pyportal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewParallel(
|
|
||||||
machine.LCD_DATA0,
|
|
||||||
machine.TFT_WR,
|
|
||||||
machine.TFT_DC,
|
|
||||||
machine.TFT_CS,
|
|
||||||
machine.TFT_RESET,
|
|
||||||
machine.TFT_RD,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.TFT_BACKLIGHT
|
|
||||||
)
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI3,
|
|
||||||
machine.LCD_DC,
|
|
||||||
machine.LCD_SS_PIN,
|
|
||||||
machine.LCD_RESET,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.LCD_BACKLIGHT
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI3.Configure(machine.SPIConfig{
|
|
||||||
SCK: machine.LCD_SCK_PIN,
|
|
||||||
SDO: machine.LCD_SDO_PIN,
|
|
||||||
SDI: machine.LCD_SDI_PIN,
|
|
||||||
Frequency: 40000000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//go:build atsamd21
|
|
||||||
// +build atsamd21
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI0,
|
|
||||||
machine.D0,
|
|
||||||
machine.D1,
|
|
||||||
machine.D2,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.D3
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{
|
|
||||||
SCK: machine.SPI0_SCK_PIN,
|
|
||||||
SDO: machine.SPI0_SDO_PIN,
|
|
||||||
SDI: machine.SPI0_SDI_PIN,
|
|
||||||
Frequency: 24000000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -2,9 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"machine"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||||
"tinygo.org/x/drivers/ili9341"
|
"tinygo.org/x/drivers/ili9341"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,16 +16,15 @@ var (
|
|||||||
white = color.RGBA{255, 255, 255, 255}
|
white = color.RGBA{255, 255, 255, 255}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
display *ili9341.Device
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
display := initdisplay.InitDisplay()
|
||||||
|
|
||||||
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
|
||||||
|
|
||||||
display.Configure(ili9341.Config{})
|
|
||||||
width, height := display.Size()
|
width, height := display.Size()
|
||||||
|
|
||||||
display.FillScreen(black)
|
|
||||||
backlight.High()
|
|
||||||
|
|
||||||
display.FillRectangle(0, 0, width/2, height/2, white)
|
display.FillRectangle(0, 0, width/2, height/2, white)
|
||||||
display.FillRectangle(width/2, 0, width/2, height/2, red)
|
display.FillRectangle(width/2, 0, width/2, height/2, red)
|
||||||
display.FillRectangle(0, height/2, width/2, height/2, green)
|
display.FillRectangle(0, height/2, width/2, height/2, green)
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
//go:build pyportal
|
|
||||||
// +build pyportal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewParallel(
|
|
||||||
machine.LCD_DATA0,
|
|
||||||
machine.TFT_WR,
|
|
||||||
machine.TFT_DC,
|
|
||||||
machine.TFT_CS,
|
|
||||||
machine.TFT_RESET,
|
|
||||||
machine.TFT_RD,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.TFT_BACKLIGHT
|
|
||||||
)
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//go:build atsamd21
|
|
||||||
// +build atsamd21
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI0,
|
|
||||||
machine.D0,
|
|
||||||
machine.D1,
|
|
||||||
machine.D2,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.D3
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{
|
|
||||||
SCK: machine.SPI0_SCK_PIN,
|
|
||||||
SDO: machine.SPI0_SDO_PIN,
|
|
||||||
SDI: machine.SPI0_SDI_PIN,
|
|
||||||
Frequency: 24000000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,10 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"machine"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||||
"tinygo.org/x/drivers/ili9341"
|
"tinygo.org/x/drivers/ili9341"
|
||||||
"tinygo.org/x/drivers/image/jpeg"
|
"tinygo.org/x/drivers/image/jpeg"
|
||||||
"tinygo.org/x/drivers/image/png"
|
"tinygo.org/x/drivers/image/png"
|
||||||
@@ -20,6 +20,10 @@ var (
|
|||||||
green = color.RGBA{0, 255, 0, 255}
|
green = color.RGBA{0, 255, 0, 255}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
display *ili9341.Device
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := run()
|
err := run()
|
||||||
for err != nil {
|
for err != nil {
|
||||||
@@ -28,9 +32,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
display = initdisplay.InitDisplay()
|
||||||
|
|
||||||
display.Configure(ili9341.Config{})
|
|
||||||
|
|
||||||
width, height := display.Size()
|
width, height := display.Size()
|
||||||
if width < 320 || height < 240 {
|
if width < 320 || height < 240 {
|
||||||
@@ -38,7 +40,6 @@ func run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
display.FillScreen(black)
|
display.FillScreen(black)
|
||||||
backlight.High()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
err := drawJpeg(display)
|
err := drawJpeg(display)
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
//go:build pyportal
|
|
||||||
// +build pyportal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewParallel(
|
|
||||||
machine.LCD_DATA0,
|
|
||||||
machine.TFT_WR,
|
|
||||||
machine.TFT_DC,
|
|
||||||
machine.TFT_CS,
|
|
||||||
machine.TFT_RESET,
|
|
||||||
machine.TFT_RD,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.TFT_BACKLIGHT
|
|
||||||
)
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI3,
|
|
||||||
machine.LCD_DC,
|
|
||||||
machine.LCD_SS_PIN,
|
|
||||||
machine.LCD_RESET,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.LCD_BACKLIGHT
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI3.Configure(machine.SPIConfig{
|
|
||||||
SCK: machine.LCD_SCK_PIN,
|
|
||||||
SDO: machine.LCD_SDO_PIN,
|
|
||||||
SDI: machine.LCD_SDI_PIN,
|
|
||||||
Frequency: 40000000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user