Skip to content

Commit

Permalink
epd2in66b: add working driver
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrichner-oviva committed Apr 20, 2024
1 parent d8f3fcc commit 1b8aad1
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 368 deletions.
102 changes: 46 additions & 56 deletions examples/waveshare-epd/epd2in66b/main.go
Original file line number Diff line number Diff line change
@@ -1,84 +1,74 @@
package main

import (
"machine"

"image/color"

"machine"
"time"

"tinygo.org/x/drivers/waveshare-epd/epd2in9"
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/waveshare-epd/epd2in66b"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freemono"
)

var display epd2in9.Device

const (
width = 128
height = 296
var (
black = color.RGBA{0, 0, 0, 0xff}
white = color.RGBA{0xff, 0xff, 0xff, 0xff}
red = color.RGBA{0xff, 0, 0, 0xff}
)

func main() {
machine.SPI0.Configure(machine.SPIConfig{
Frequency: 8000000,
Mode: 0,
})
machine.Serial.Configure(machine.UARTConfig{})
time.Sleep(2 * time.Second)

display = epd2in9.New(machine.SPI0, machine.GPIO2, machine.GPIO3, machine.GPIO4, machine.GPIO5)
display.Configure(epd2in9.Config{
Width: width,
LogicalWidth: width,
Height: height,
machine.SPI1.Configure(machine.SPIConfig{
Frequency: epd2in66b.Baudrate,
})

black := color.RGBA{1, 1, 1, 255}
white := color.RGBA{0, 0, 0, 255}
println("started")

display.ClearBuffer()
println("Clear the display")
display.ClearDisplay()
display.WaitUntilIdle()
println("Waiting for 2 seconds")
time.Sleep(2 * time.Second)

// Show a checkered board
for i := int16(0); i < width/8; i++ {
for j := int16(0); j < height/8; j++ {
if (i+j)%2 == 0 {
showRect(i*8, j*8, 8, 8, black)
}
}
display := epd2in66b.New(machine.SPI1)
err := display.Configure(epd2in66b.Config{})
if err != nil {
panic(err)
}
println("Show checkered board")
display.Display()
display.WaitUntilIdle()
println("Waiting for 2 seconds")
time.Sleep(2 * time.Second)

println("Set partial lut")
display.SetLUT(false) // partial updates (faster, but with some ghosting)
println("Show smaller striped area")
for i := int16(40); i < 88; i++ {
for j := int16(83); j < 166; j++ {
if (i+j)%4 == 0 || (i+j)%4 == 1 {
display.SetPixel(i, j, black)
} else {
display.SetPixel(i, j, white)
}
}
err = display.Reset()
if err != nil {
panic(err)
}

display.Display()
display.WaitUntilIdle()
println("draw checkerboard")
drawCheckerBoard(&display)

println("draw 'hello'")
tinyfont.WriteLineRotated(&display, &freemono.Bold24pt7b, 40, 10, "Hello!", white, tinyfont.ROTATION_90)
tinyfont.WriteLineRotated(&display, &freemono.Bold12pt7b, 10, 10, "tinygo rocks", white, tinyfont.ROTATION_90)
err = display.Display()
if err != nil {
panic(err)
}
}

display.DeepSleep()
func drawCheckerBoard(display drivers.Displayer) {
s := 8
width, height := display.Size()
for x := 0; x <= int(width)-s; x += s {
for y := 0; y <= int(height)-s; y += s {
c := red
if (x/s)%2 == (y/s)%2 {
c = black
}

println("You could remove power now")
showRect(display, x, y, s, s, c)
}
}
}

func showRect(x int16, y int16, w int16, h int16, c color.RGBA) {
func showRect(display drivers.Displayer, x int, y int, w int, h int, c color.RGBA) {
for i := x; i < x+w; i++ {
for j := y; j < y+h; j++ {
display.SetPixel(i, j, c)
display.SetPixel(int16(i), int16(j), c)
}
}
}
1 change: 1 addition & 0 deletions smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go
tinygo build -size short -o ./build/test.hex -target=pico ./examples/waveshare-epd/epd4in66b/main.go
tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
tinygo build -size short -o ./build/test.bin -target=m5stamp-c3 ./examples/ws2812
tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
Expand Down
Binary file not shown.
Loading

0 comments on commit 1b8aad1

Please sign in to comment.