From 45561a7a3cbeb5e1ae2c737c4dbf1ca00ba00cbc Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Wed, 22 Dec 2021 22:34:40 +0100 Subject: [PATCH] waveshare213v2: Make busy a PinIn, use WaitForEdge The busy pin from the e-paper display is only used to read, not to write, and thus there's no need for the PinIO interface. PinIn is enough. In addition the WaitForEdge function can be used to shorten the delays when waiting for the display to become idle. Spurious or missed edges are acceptable: the delay isn't very long. --- waveshare2in13v2/errorhandler.go | 4 ++-- waveshare2in13v2/waveshare213v2.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/waveshare2in13v2/errorhandler.go b/waveshare2in13v2/errorhandler.go index 8f0f88e..b7c8671 100644 --- a/waveshare2in13v2/errorhandler.go +++ b/waveshare2in13v2/errorhandler.go @@ -45,8 +45,8 @@ func (eh *errorHandler) csOut(l gpio.Level) { } func (eh *errorHandler) waitUntilIdle() { - for eh.d.busy.Read() == gpio.High { - time.Sleep(100 * time.Millisecond) + for busy := eh.d.busy; busy.Read() == gpio.High; { + busy.WaitForEdge(100 * time.Millisecond) } } diff --git a/waveshare2in13v2/waveshare213v2.go b/waveshare2in13v2/waveshare213v2.go index fafd78c..79b37ba 100644 --- a/waveshare2in13v2/waveshare213v2.go +++ b/waveshare2in13v2/waveshare213v2.go @@ -60,7 +60,7 @@ type Dev struct { dc gpio.PinOut cs gpio.PinOut rst gpio.PinOut - busy gpio.PinIO + busy gpio.PinIn opts *Opts } @@ -123,12 +123,16 @@ var EPD2in13v2 = Opts{ } // New creates new handler which is used to access the display. -func New(p spi.Port, dc, cs, rst gpio.PinOut, busy gpio.PinIO, opts *Opts) (*Dev, error) { +func New(p spi.Port, dc, cs, rst gpio.PinOut, busy gpio.PinIn, opts *Opts) (*Dev, error) { c, err := p.Connect(5*physic.MegaHertz, spi.Mode0, 8) if err != nil { return nil, err } + if err := busy.In(gpio.Float, gpio.FallingEdge); err != nil { + return nil, err + } + d := &Dev{ c: c, dc: dc,