Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions waveshare-epd/epd1in54/epd1in54.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ type Device struct {
rst machine.Pin
busy machine.Pin

buffer []uint8
rotation Rotation
buffer []uint8
rotation Rotation
yDecrement bool
}

type Rotation uint8
Expand Down Expand Up @@ -91,6 +92,7 @@ func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
}

func (d *Device) LDirInit(cfg Config) {
d.yDecrement = false
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
Expand Down Expand Up @@ -142,14 +144,15 @@ func (d *Device) LDirInit(cfg Config) {
d.SendData(0x00)

d.SendCommand(0x4F)
d.SendData(0xC7)
d.SendData(0x00)
d.SendData(0x00)

d.WaitUntilIdle()
d.setLUT(fullRefresh)
}

func (d *Device) HDirInit(cfg Config) {
d.yDecrement = true
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
Expand Down Expand Up @@ -287,13 +290,15 @@ func (d *Device) DisplayImage(image []uint8) {
}
h = int(Height)

d.setCursor()
d.SendCommand(0x24)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
d.SendData(image[i+j*w])
}
}

d.setCursor()
d.SendCommand(0x26)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
Expand All @@ -313,6 +318,7 @@ func (d *Device) Display() error {
}
h = int(Height)

d.setCursor()
d.SendCommand(0x24)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
Expand All @@ -321,6 +327,7 @@ func (d *Device) Display() error {
}
}

d.setCursor()
d.SendCommand(0x26)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
Expand All @@ -334,6 +341,19 @@ func (d *Device) Display() error {
return nil
}

// setCursor moves the RAM address counter to the first byte of the frame.
func (d *Device) setCursor() {
d.SendCommand(0x4E)
d.SendData(0x00)
d.SendCommand(0x4F)
if d.yDecrement {
d.SendData(0xC7)
} else {
d.SendData(0x00)
}
d.SendData(0x00)
}

func (d *Device) displayFrame() {
d.SendCommand(0x22)
d.SendData(0xC7)
Expand All @@ -350,13 +370,15 @@ func (d *Device) Clear() {
}
h = int(Height)

d.setCursor()
d.SendCommand(0x24)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
d.SendData(0xff)
}
}

d.setCursor()
d.SendCommand(0x26)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
Expand Down
Loading