Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/ili9325/itdb02/bus_atsamd21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build atsamd21

package main

import "tinygo.org/x/drivers/ili9325"

func newBus() ili9325.Bus {
bus, err := ili9325.NewPortBus(data, wr)
if err != nil {
panic(err)
}
return bus
}
9 changes: 9 additions & 0 deletions examples/ili9325/itdb02/bus_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !atsamd21

package main

import "tinygo.org/x/drivers/ili9325"

func newBus() ili9325.Bus {
return ili9325.NewPinBus(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], wr)
}
63 changes: 63 additions & 0 deletions examples/ili9325/itdb02/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Draws a test pattern on the ITead ITDB02-2.8 shield in landscape, with the
// red square in the top left corner.
package main

import (
"image/color"
"machine"
"time"

"tinygo.org/x/drivers"
"tinygo.org/x/drivers/ili9325"
)

var (
data = [8]machine.Pin{machine.D0, machine.D1, machine.D2, machine.D3, machine.D4, machine.D5, machine.D6, machine.D7}
rs = machine.ADC5
wr = machine.ADC4
cs = machine.ADC3
rst = machine.ADC2
)

var (
black = color.RGBA{0, 0, 0, 255}
white = color.RGBA{255, 255, 255, 255}
red = color.RGBA{255, 0, 0, 255}
green = color.RGBA{0, 255, 0, 255}
blue = color.RGBA{0, 0, 255, 255}
)

func main() {
out := machine.PinConfig{Mode: machine.PinOutput}
for _, p := range append(data[:], rs, wr, cs, rst) {
p.Configure(out)
}

display := ili9325.New(newBus(), rs, cs, rst)
display.Configure(ili9325.Config{Rotation: drivers.Rotation90})

w, h := display.Size()
display.FillScreen(black)
display.FillRectangle(0, 0, 40, 40, red)
display.FillRectangle(w-40, 0, 40, 40, green)
display.FillRectangle(0, h-40, 40, 40, blue)
display.FillRectangle(w-40, h-40, 40, 40, white)

// Only redraw the strips that change, so the square doesn't flicker.
x, y, dx := int16(40), h/2-20, int16(4)
display.FillRectangle(x, y, 40, 40, green)
for {
if x+dx < 40 || x+dx > w-80 {
dx = -dx
}
if dx > 0 {
display.FillRectangle(x, y, dx, 40, black)
display.FillRectangle(x+40, y, dx, 40, green)
} else {
display.FillRectangle(x+40+dx, y, -dx, 40, black)
display.FillRectangle(x+dx, y, -dx, 40, green)
}
x += dx
time.Sleep(10 * time.Millisecond)
}
}
13 changes: 13 additions & 0 deletions examples/ili9325/lorenz/bus_atsamd21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build atsamd21

package main

import "tinygo.org/x/drivers/ili9325"

func newBus() ili9325.Bus {
bus, err := ili9325.NewPortBus(data, wr)
if err != nil {
panic(err)
}
return bus
}
9 changes: 9 additions & 0 deletions examples/ili9325/lorenz/bus_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !atsamd21

package main

import "tinygo.org/x/drivers/ili9325"

func newBus() ili9325.Bus {
return ili9325.NewPinBus(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], wr)
}
106 changes: 106 additions & 0 deletions examples/ili9325/lorenz/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Draws the Lorenz attractor on the ITead ITDB02-2.8 shield. A 3000 point
// trail traces the attractor while the view slowly rotates around the z axis.
package main

import (
"image/color"
"machine"
"math"

"tinygo.org/x/drivers"
"tinygo.org/x/drivers/ili9325"
)

var (
data = [8]machine.Pin{machine.D0, machine.D1, machine.D2, machine.D3, machine.D4, machine.D5, machine.D6, machine.D7}
rs = machine.ADC5
wr = machine.ADC4
cs = machine.ADC3
rst = machine.ADC2
)

const (
trail = 3000
sigma = 10
rho = 28
beta = 8.0 / 3
dt = 0.006
scale = 5.2
)

var (
black = color.RGBA{0, 0, 0, 255}
palette [64]color.RGBA
px, py [trail]int16
)

func main() {
out := machine.PinConfig{Mode: machine.PinOutput}
for _, p := range append(data[:], rs, wr, cs, rst) {
p.Configure(out)
}

display := ili9325.New(newBus(), rs, cs, rst)
display.Configure(ili9325.Config{Rotation: drivers.Rotation90})
display.FillScreen(black)

for i := range palette {
palette[i] = hue(float32(i) / float32(len(palette)))
}
for i := range px {
px[i] = -1
}

w, h := display.Size()
cx, cy := float32(w/2), float32(h-6)
x, y, z := float32(0.1), float32(0), float32(0)
theta := float64(0)
cos, sin := float32(1), float32(0)
for i := 0; ; i++ {
dx := sigma * (y - x)
dy := x*(rho-z) - y
dz := x*y - beta*z
x += dx * dt
y += dy * dt
z += dz * dt

if i%64 == 0 {
theta += 0.004
cos, sin = float32(math.Cos(theta)), float32(math.Sin(theta))
}
sx := int16(cx + (x*cos-y*sin)*scale)
sy := int16(cy - z*4.4)

j := i % trail
if px[j] >= 0 {
display.SetPixel(px[j], py[j], black)
}
zi := int(z * 1.3)
if zi < 0 {
zi = 0
}
display.SetPixel(sx, sy, palette[zi%len(palette)])
px[j], py[j] = sx, sy
}
}

// hue returns a fully saturated colour for h in [0, 1).
func hue(h float32) color.RGBA {
h6 := h * 6
f := h6 - float32(int(h6))
up, down := uint8(255*f), uint8(255*(1-f))
switch int(h6) % 6 {
case 0:
return color.RGBA{255, up, 0, 255}
case 1:
return color.RGBA{down, 255, 0, 255}
case 2:
return color.RGBA{0, 255, up, 255}
case 3:
return color.RGBA{0, down, 255, 255}
case 4:
return color.RGBA{up, 0, 255, 255}
default:
return color.RGBA{255, 0, down, 255}
}
}
Loading
Loading