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.
pull/41/head
Michael Hanselmann 4 years ago committed by M-A
parent 5179e40adf
commit 347b4e237c

@ -45,8 +45,8 @@ func (eh *errorHandler) csOut(l gpio.Level) {
} }
func (eh *errorHandler) waitUntilIdle() { func (eh *errorHandler) waitUntilIdle() {
for eh.d.busy.Read() == gpio.High { for busy := eh.d.busy; busy.Read() == gpio.High; {
time.Sleep(100 * time.Millisecond) busy.WaitForEdge(100 * time.Millisecond)
} }
} }

@ -60,7 +60,7 @@ type Dev struct {
dc gpio.PinOut dc gpio.PinOut
cs gpio.PinOut cs gpio.PinOut
rst gpio.PinOut rst gpio.PinOut
busy gpio.PinIO busy gpio.PinIn
opts *Opts opts *Opts
} }
@ -123,12 +123,16 @@ var EPD2in13v2 = Opts{
} }
// New creates new handler which is used to access the display. // 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) c, err := p.Connect(5*physic.MegaHertz, spi.Mode0, 8)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := busy.In(gpio.Float, gpio.FallingEdge); err != nil {
return nil, err
}
d := &Dev{ d := &Dev{
c: c, c: c,
dc: dc, dc: dc,

Loading…
Cancel
Save