Skip to content

Commit 7ea638f

Browse files
authored
feature: add support for Badger2040 (#12)
* feature: add badger2040 board to supported examples Signed-off-by: deadprogram <ron@hybridgroup.com> * modules: update to dev branch of tinygo drivers Signed-off-by: deadprogram <ron@hybridgroup.com> --------- Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 6842651 commit 7ea638f

File tree

10 files changed

+72
-15
lines changed

10 files changed

+72
-15
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ TARGET = build/examples_basic.hex \
2525
build/examples_basic_gopher_badge.hex \
2626
build/examples_basic_pybadge.hex \
2727
build/examples_basic_wioterminal.hex \
28+
build/examples_basic_badger2040.hex \
2829
build/examples_colors.hex \
2930
build/examples_httpclient.hex
3031
.PHONY: smoketest $(TARGET)
@@ -50,6 +51,10 @@ build/examples_basic_wioterminal.hex:
5051
$(TINYGO) build -size short -o $@ -target=wioterminal ./examples/basic
5152
@$(MD5SUM) $@
5253

54+
build/examples_basic_badger2040.hex:
55+
$(TINYGO) build -size short -o $@ -target=badger2040 ./examples/basic
56+
@$(MD5SUM) $@
57+
5358
build/examples_colors.hex:
5459
$(TINYGO) build -size short -o $@ -target=pyportal ./examples/colors
5560
@$(MD5SUM) $@

examples/basic/main.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"image/color"
65
"time"
76

87
"tinygo.org/x/tinyfont/proggy"
@@ -11,12 +10,6 @@ import (
1110
)
1211

1312
var (
14-
black = color.RGBA{0, 0, 0, 255}
15-
white = color.RGBA{255, 255, 255, 255}
16-
red = color.RGBA{255, 0, 0, 255}
17-
blue = color.RGBA{0, 0, 255, 255}
18-
green = color.RGBA{0, 255, 0, 255}
19-
2013
font = &proggy.TinySZ8pt7b
2114
)
2215

@@ -25,13 +18,15 @@ func main() {
2518
terminal := tinyterm.NewTerminal(display)
2619

2720
terminal.Configure(&tinyterm.Config{
28-
Font: font,
29-
FontHeight: 10,
30-
FontOffset: 6,
21+
Font: font,
22+
FontHeight: 10,
23+
FontOffset: 6,
24+
UseSoftwareScroll: initdisplay.NeedsSoftwareScroll(),
3125
})
3226
for {
33-
time.Sleep(50 * time.Millisecond)
27+
time.Sleep(time.Second)
28+
3429
fmt.Fprintf(terminal, "\ntime: %d", time.Now().UnixNano())
30+
display.Display()
3531
}
36-
3732
}

examples/initdisplay/badger2040.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build badger2040 || badger2040_w
2+
3+
package initdisplay
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/uc8151"
9+
"tinygo.org/x/tinyterm"
10+
)
11+
12+
func InitDisplay() tinyterm.Displayer {
13+
led3v3 := machine.ENABLE_3V3
14+
led3v3.Configure(machine.PinConfig{Mode: machine.PinOutput})
15+
led3v3.High()
16+
17+
machine.SPI0.Configure(machine.SPIConfig{
18+
Frequency: 12000000,
19+
SCK: machine.EPD_SCK_PIN,
20+
SDO: machine.EPD_SDO_PIN,
21+
})
22+
23+
display := uc8151.New(machine.SPI0, machine.EPD_CS_PIN, machine.EPD_DC_PIN, machine.EPD_RESET_PIN, machine.EPD_BUSY_PIN)
24+
display.Configure(uc8151.Config{
25+
Speed: uc8151.TURBO,
26+
FlickerFree: true,
27+
Rotation: uc8151.ROTATION_270,
28+
})
29+
30+
display.ClearDisplay()
31+
32+
return &display
33+
}
34+
35+
func NeedsSoftwareScroll() bool {
36+
return true
37+
}

examples/initdisplay/clue.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ func InitDisplay() tinyterm.Displayer {
3636

3737
return &display
3838
}
39+
40+
func NeedsSoftwareScroll() bool {
41+
return false
42+
}

examples/initdisplay/gopher-badge.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ func InitDisplay() tinyterm.Displayer {
3030

3131
return &display
3232
}
33+
34+
func NeedsSoftwareScroll() bool {
35+
return false
36+
}

examples/initdisplay/pybadge.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ func InitDisplay() tinyterm.Displayer {
2626

2727
return &display
2828
}
29+
30+
func NeedsSoftwareScroll() bool {
31+
return false
32+
}

examples/initdisplay/pyportal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ func InitDisplay() tinyterm.Displayer {
3333

3434
return display
3535
}
36+
37+
func NeedsSoftwareScroll() bool {
38+
return false
39+
}

examples/initdisplay/wioterminal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ func InitDisplay() tinyterm.Displayer {
3838

3939
return display
4040
}
41+
42+
func NeedsSoftwareScroll() bool {
43+
return false
44+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module tinygo.org/x/tinyterm
33
go 1.18
44

55
require (
6-
tinygo.org/x/drivers v0.26.1-0.20231206190939-3fabdc5c9680
6+
tinygo.org/x/drivers v0.28.1-0.20241027232331-f12454d4f7be
77
tinygo.org/x/tinyfont v0.4.0
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
22
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
3-
tinygo.org/x/drivers v0.26.1-0.20231206190939-3fabdc5c9680 h1:S7FwtuTMSkyEjF1cgl3AFlnBR940GYgCMSADm0U8e7o=
4-
tinygo.org/x/drivers v0.26.1-0.20231206190939-3fabdc5c9680/go.mod h1:q/mU8G/wz821p8xXqbkBACOlmZFDHXd//DnYnCW+dDQ=
3+
tinygo.org/x/drivers v0.28.1-0.20241027232331-f12454d4f7be h1:cIDFZYnZQSjzvw1LEht5Av1YZ2Aw6mJuNH31l+uIAv0=
4+
tinygo.org/x/drivers v0.28.1-0.20241027232331-f12454d4f7be/go.mod h1:q/mU8G/wz821p8xXqbkBACOlmZFDHXd//DnYnCW+dDQ=
55
tinygo.org/x/tinyfont v0.4.0 h1:XexPKEKiHInf6p4CMCJwsIheVPY0T46HUs6ictYyZfE=
66
tinygo.org/x/tinyfont v0.4.0/go.mod h1:7nVj3j3geqBoPDzpFukAhF1C8AP9YocMsZy0HSAcGCA=

0 commit comments

Comments
 (0)