Skip to content

Commit f57b5ec

Browse files
authored
Add sharpmem (#724)
sharpmem: add implementation of sharpmem display driver * Implement Configure, Clear and ClearBuffer, add some tests, add documentation/comments * Reverse white * Inverted bits, fix and improve ClearBuffer, cleanup * Refine doc comment * Driver refactor, optimizations toggle, additional tests & support for all SKUs * Fix address overflow padding, add wire-level tests for assumed address encoding * Minor rename * Cleanup and doc fixes * Add device configs * Bounds check * Add example and smoketest entry * Use uf2 output file format * Refine example
1 parent 4869496 commit f57b5ec

File tree

5 files changed

+720
-0
lines changed

5 files changed

+720
-0
lines changed

examples/sharpmem/main.go

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package main
2+
3+
import (
4+
"image/color"
5+
"machine"
6+
"math/rand/v2"
7+
"time"
8+
9+
"tinygo.org/x/drivers/sharpmem"
10+
)
11+
12+
var (
13+
// example wiring using a nice!view and nice!nano:
14+
// (view) (nano)
15+
// MOSI --> P0.24
16+
// SCK ---> P0.22
17+
// GND ---> GND
18+
// VCC ---> 3.3V
19+
// CS ----> P0.06
20+
21+
spi = machine.SPI0
22+
23+
sckPin = machine.SPI0_SCK_PIN // SCK
24+
sdoPin = machine.SPI0_SDO_PIN // MOSI
25+
sdiPin = machine.SPI0_SDI_PIN // (any pin)
26+
27+
csPin = machine.P0_06 // CS
28+
)
29+
30+
func main() {
31+
time.Sleep(time.Second)
32+
33+
err := spi.Configure(machine.SPIConfig{
34+
Frequency: 2000000,
35+
SCK: sckPin,
36+
SDO: sdoPin,
37+
SDI: sdiPin,
38+
Mode: 0,
39+
LSBFirst: true,
40+
})
41+
if err != nil {
42+
println("spi.Configure() failed, error:", err.Error())
43+
return
44+
}
45+
46+
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
47+
48+
display := sharpmem.New(spi, csPin)
49+
50+
cfg := sharpmem.ConfigLS011B7DH03
51+
display.Configure(cfg)
52+
53+
// clear the display before first use
54+
err = display.Clear()
55+
if err != nil {
56+
println("display.Clear() failed, error:", err.Error())
57+
return
58+
}
59+
60+
// random boxes pop into and out of existence
61+
for {
62+
x0 := int16(rand.IntN(int(cfg.Width - 7)))
63+
y0 := int16(rand.IntN(int(cfg.Height - 7)))
64+
65+
for x2 := int16(0); x2 < 16; x2++ {
66+
x2 := x2
67+
c := color.RGBA{R: 255, G: 255, B: 255, A: 255}
68+
69+
if x2 >= 8 {
70+
// effectively erases the box after it showed up
71+
x2 = x2 - 8
72+
c = color.RGBA{R: 0, G: 0, B: 0, A: 255}
73+
}
74+
75+
for x := int16(0); x < x2; x++ {
76+
for y := int16(0); y < 8; y++ {
77+
display.SetPixel(x0+x, y0+y, c)
78+
}
79+
}
80+
81+
err = display.Display()
82+
if err != nil {
83+
println("display.Display() failed, error:", err.Error())
84+
continue
85+
}
86+
87+
time.Sleep(33 * time.Millisecond)
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)