Skip to content

Commit 941ea4e

Browse files
authored
ILI9341 TFT driver (SPI) (#153)
* ili9341: Add spidriver
1 parent 21ba939 commit 941ea4e

File tree

13 files changed

+296
-38
lines changed

13 files changed

+296
-38
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ smoke-test:
5757
@md5sum ./build/test.hex
5858
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
5959
@md5sum ./build/test.hex
60-
tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic/main.go
60+
tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
6161
@md5sum ./build/test.hex
62-
tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll/main.go
62+
tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
63+
@md5sum ./build/test.hex
64+
tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
6365
@md5sum ./build/test.hex
6466
tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go
6567
@md5sum ./build/test.hex

examples/ili9341/basic/main.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ import (
99
)
1010

1111
var (
12-
display = ili9341.NewParallel(
13-
machine.LCD_DATA0,
14-
machine.TFT_WR,
15-
machine.TFT_DC,
16-
machine.TFT_CS,
17-
machine.TFT_RESET,
18-
machine.TFT_RD,
19-
)
20-
2112
black = color.RGBA{0, 0, 0, 255}
2213
white = color.RGBA{255, 255, 255, 255}
2314
red = color.RGBA{255, 0, 0, 255}
@@ -27,13 +18,13 @@ var (
2718

2819
func main() {
2920

30-
machine.TFT_BACKLIGHT.Configure(machine.PinConfig{machine.PinOutput})
21+
backlight.Configure(machine.PinConfig{machine.PinOutput})
3122

3223
display.Configure(ili9341.Config{})
3324
width, height := display.Size()
3425

3526
display.FillScreen(black)
36-
machine.TFT_BACKLIGHT.High()
27+
backlight.High()
3728

3829
display.FillRectangle(0, 0, width/2, height/2, white)
3930
display.FillRectangle(width/2, 0, width/2, height/2, red)

examples/ili9341/basic/pyportal.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// +build pyportal
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/ili9341"
9+
)
10+
11+
var (
12+
display = ili9341.NewParallel(
13+
machine.LCD_DATA0,
14+
machine.TFT_WR,
15+
machine.TFT_DC,
16+
machine.TFT_CS,
17+
machine.TFT_RESET,
18+
machine.TFT_RD,
19+
)
20+
21+
backlight = machine.TFT_BACKLIGHT
22+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// +build wioterminal
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/ili9341"
9+
)
10+
11+
var (
12+
display = ili9341.NewSpi(
13+
machine.SPI3,
14+
machine.LCD_DC,
15+
machine.LCD_SS_PIN,
16+
machine.LCD_RESET,
17+
)
18+
19+
backlight = machine.LCD_BACKLIGHT
20+
)
21+
22+
func init() {
23+
machine.SPI3.Configure(machine.SPIConfig{
24+
SCK: machine.LCD_SCK_PIN,
25+
MOSI: machine.LCD_MOSI_PIN,
26+
MISO: machine.LCD_MISO_PIN,
27+
Frequency: 40000000,
28+
})
29+
}

examples/ili9341/pyportal_boing/main.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ const (
2525
)
2626

2727
var (
28-
display = ili9341.NewParallel(
29-
machine.LCD_DATA0,
30-
machine.TFT_WR,
31-
machine.TFT_DC,
32-
machine.TFT_CS,
33-
machine.TFT_RESET,
34-
machine.TFT_RD,
35-
)
36-
3728
frameBuffer = [(graphics.BALLHEIGHT + 8) * (graphics.BALLWIDTH + 8)]uint16{}
3829

3930
startTime int64
@@ -56,15 +47,15 @@ var (
5647
func main() {
5748

5849
// configure backlight
59-
machine.TFT_BACKLIGHT.Configure(machine.PinConfig{machine.PinOutput})
50+
backlight.Configure(machine.PinConfig{machine.PinOutput})
6051

6152
// configure display
6253
display.Configure(ili9341.Config{})
6354
print("width, height == ")
6455
width, height := display.Size()
6556
println(width, height)
6657

67-
machine.TFT_BACKLIGHT.High()
58+
backlight.High()
6859

6960
display.SetRotation(ili9341.Rotation270)
7061
DrawBackground()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// +build pyportal
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/ili9341"
9+
)
10+
11+
var (
12+
display = ili9341.NewParallel(
13+
machine.LCD_DATA0,
14+
machine.TFT_WR,
15+
machine.TFT_DC,
16+
machine.TFT_CS,
17+
machine.TFT_RESET,
18+
machine.TFT_RD,
19+
)
20+
21+
backlight = machine.TFT_BACKLIGHT
22+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// +build wioterminal
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/ili9341"
9+
)
10+
11+
var (
12+
display = ili9341.NewSpi(
13+
machine.SPI3,
14+
machine.LCD_DC,
15+
machine.LCD_SS_PIN,
16+
machine.LCD_RESET,
17+
)
18+
19+
backlight = machine.LCD_BACKLIGHT
20+
)
21+
22+
func init() {
23+
machine.SPI3.Configure(machine.SPIConfig{
24+
SCK: machine.LCD_SCK_PIN,
25+
MOSI: machine.LCD_MOSI_PIN,
26+
MISO: machine.LCD_MISO_PIN,
27+
Frequency: 40000000,
28+
})
29+
}

examples/ili9341/scroll/main.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ import (
99
)
1010

1111
var (
12-
display = ili9341.NewParallel(
13-
machine.LCD_DATA0,
14-
machine.TFT_WR,
15-
machine.TFT_DC,
16-
machine.TFT_CS,
17-
machine.TFT_RESET,
18-
machine.TFT_RD,
19-
)
20-
2112
red = color.RGBA{255, 0, 0, 255}
2213
blue = color.RGBA{0, 0, 255, 255}
2314
green = color.RGBA{0, 255, 0, 255}
@@ -27,13 +18,13 @@ var (
2718

2819
func main() {
2920

30-
machine.TFT_BACKLIGHT.Configure(machine.PinConfig{machine.PinOutput})
21+
backlight.Configure(machine.PinConfig{machine.PinOutput})
3122

3223
display.Configure(ili9341.Config{})
3324
width, height := display.Size()
3425

3526
display.FillScreen(black)
36-
machine.TFT_BACKLIGHT.High()
27+
backlight.High()
3728

3829
display.FillRectangle(0, 0, width/2, height/2, white)
3930
display.FillRectangle(width/2, 0, width/2, height/2, red)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// +build pyportal
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/ili9341"
9+
)
10+
11+
var (
12+
display = ili9341.NewParallel(
13+
machine.LCD_DATA0,
14+
machine.TFT_WR,
15+
machine.TFT_DC,
16+
machine.TFT_CS,
17+
machine.TFT_RESET,
18+
machine.TFT_RD,
19+
)
20+
21+
backlight = machine.TFT_BACKLIGHT
22+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// +build wioterminal
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/ili9341"
9+
)
10+
11+
var (
12+
display = ili9341.NewSpi(
13+
machine.SPI3,
14+
machine.LCD_DC,
15+
machine.LCD_SS_PIN,
16+
machine.LCD_RESET,
17+
)
18+
19+
backlight = machine.LCD_BACKLIGHT
20+
)
21+
22+
func init() {
23+
machine.SPI3.Configure(machine.SPIConfig{
24+
SCK: machine.LCD_SCK_PIN,
25+
MOSI: machine.LCD_MOSI_PIN,
26+
MISO: machine.LCD_MISO_PIN,
27+
Frequency: 40000000,
28+
})
29+
}

0 commit comments

Comments
 (0)