Skip to content

Commit

Permalink
uc8151: improvements to speed and also add flicker-free mode based on @…
Browse files Browse the repository at this point in the history
…antirez code example

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed May 10, 2024
1 parent 7dbca2a commit 13cb370
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 319 deletions.
51 changes: 39 additions & 12 deletions examples/uc8151/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"image/color"
"machine"
"time"

"tinygo.org/x/drivers"
"tinygo.org/x/drivers/uc8151"
Expand All @@ -15,30 +16,56 @@ func main() {
led = machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.SPI0.Configure(machine.SPIConfig{
Frequency: 12000000,
Frequency: 12 * machine.MHz,
SCK: machine.EPD_SCK_PIN,
SDO: machine.EPD_SDO_PIN,
})

display = uc8151.New(machine.SPI0, machine.EPD_CS_PIN, machine.EPD_DC_PIN, machine.EPD_RESET_PIN, machine.EPD_BUSY_PIN)
display.Configure(uc8151.Config{
Rotation: drivers.Rotation270,
Speed: uc8151.MEDIUM,
Blocking: true,
Rotation: drivers.Rotation270,
Speed: uc8151.TURBO,
FlickerFree: true,
Blocking: false,
})
black := color.RGBA{1, 1, 1, 255}

display.ClearBuffer()
display.Display()
for i := int16(0); i < 37; i++ {
for j := int16(0); j < 16; j++ {
if (i+j)%2 == 0 {
showRect(i*8, j*8, 8, 8, black)
display.ClearDisplay()

mod := int16(1)
for {
// checkerboard
for i := int16(0); i < 11; i++ {
if mod == 1 {
mod = 0
} else {
mod = 1
}

display.ClearBuffer()
for i := int16(0); i < 37; i++ {
for j := int16(0); j < 16; j++ {
if (i+j)%2 == mod {
showRect(i*8, j*8, 8, 8, black)
}
}
}
display.Display()
time.Sleep(500 * time.Millisecond)
}
}

display.Display()
// moving line
for i := int16(16); i < 21; i++ {
display.ClearBuffer()
for j := int16(0); j < 16; j++ {
if (i+j)%2 == 0 {
showRect(i*8, j*8, 8, 8, black)
}
display.Display()
time.Sleep(250 * time.Millisecond)
}
}
}
}

func showRect(x int16, y int16, w int16, h int16, c color.RGBA) {
Expand Down
30 changes: 30 additions & 0 deletions uc8151/lut.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uc8151

// LUTType is the look-up table for the display
type LUTType [42]uint8

type LUTSet struct {
VCOM LUTType
WW LUTType
BW LUTType
WB LUTType
BB LUTType
}

func (lut *LUTType) Clear() {
for i := range lut {
lut[i] = 0
}
}

func (lut *LUTType) SetRow(row int, pat uint8, dur [4]uint8, rep uint8) error {
index := row * 6
lut[index] = pat
lut[index+1] = dur[0]
lut[index+2] = dur[1]
lut[index+3] = dur[2]
lut[index+4] = dur[3]
lut[index+5] = rep

return nil
}
8 changes: 5 additions & 3 deletions uc8151/registers.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ const (
ROTATION_270 = drivers.Rotation270

DEFAULT Speed = 0
MEDIUM Speed = 1
FAST Speed = 2
TURBO Speed = 3
SLOW Speed = 1
MEDIUM Speed = 2
FAST Speed = 3
FASTER Speed = 4
TURBO Speed = 5
)
Loading

0 comments on commit 13cb370

Please sign in to comment.