-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
720 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package main | ||
|
||
import ( | ||
"image/color" | ||
"machine" | ||
"math/rand/v2" | ||
"time" | ||
|
||
"tinygo.org/x/drivers/sharpmem" | ||
) | ||
|
||
var ( | ||
// example wiring using a nice!view and nice!nano: | ||
// (view) (nano) | ||
// MOSI --> P0.24 | ||
// SCK ---> P0.22 | ||
// GND ---> GND | ||
// VCC ---> 3.3V | ||
// CS ----> P0.06 | ||
|
||
spi = machine.SPI0 | ||
|
||
sckPin = machine.SPI0_SCK_PIN // SCK | ||
sdoPin = machine.SPI0_SDO_PIN // MOSI | ||
sdiPin = machine.SPI0_SDI_PIN // (any pin) | ||
|
||
csPin = machine.P0_06 // CS | ||
) | ||
|
||
func main() { | ||
time.Sleep(time.Second) | ||
|
||
err := spi.Configure(machine.SPIConfig{ | ||
Frequency: 2000000, | ||
SCK: sckPin, | ||
SDO: sdoPin, | ||
SDI: sdiPin, | ||
Mode: 0, | ||
LSBFirst: true, | ||
}) | ||
if err != nil { | ||
println("spi.Configure() failed, error:", err.Error()) | ||
return | ||
} | ||
|
||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
|
||
display := sharpmem.New(spi, csPin) | ||
|
||
cfg := sharpmem.ConfigLS011B7DH03 | ||
display.Configure(cfg) | ||
|
||
// clear the display before first use | ||
err = display.Clear() | ||
if err != nil { | ||
println("display.Clear() failed, error:", err.Error()) | ||
return | ||
} | ||
|
||
// random boxes pop into and out of existence | ||
for { | ||
x0 := int16(rand.IntN(int(cfg.Width - 7))) | ||
y0 := int16(rand.IntN(int(cfg.Height - 7))) | ||
|
||
for x2 := int16(0); x2 < 16; x2++ { | ||
x2 := x2 | ||
c := color.RGBA{R: 255, G: 255, B: 255, A: 255} | ||
|
||
if x2 >= 8 { | ||
// effectively erases the box after it showed up | ||
x2 = x2 - 8 | ||
c = color.RGBA{R: 0, G: 0, B: 0, A: 255} | ||
} | ||
|
||
for x := int16(0); x < x2; x++ { | ||
for y := int16(0); y < 8; y++ { | ||
display.SetPixel(x0+x, y0+y, c) | ||
} | ||
} | ||
|
||
err = display.Display() | ||
if err != nil { | ||
println("display.Display() failed, error:", err.Error()) | ||
continue | ||
} | ||
|
||
time.Sleep(33 * time.Millisecond) | ||
} | ||
} | ||
} |
Oops, something went wrong.