diff --git a/waveshare2in13v2/errorhandler.go b/waveshare2in13v2/errorhandler.go new file mode 100644 index 0000000..c3c9fab --- /dev/null +++ b/waveshare2in13v2/errorhandler.go @@ -0,0 +1,55 @@ +// Copyright 2021 The Periph Authors. All rights reserved. +// Use of this source code is governed under the Apache License, Version 2.0 +// that can be found in the LICENSE file. + +package waveshare2in13v2 + +import "periph.io/x/conn/v3/gpio" + +// errorHandler is a wrapper for error management. +type errorHandler struct { + d Dev + err error +} + +func (eh *errorHandler) rstOut(l gpio.Level) { + if eh.err != nil { + return + } + eh.err = eh.d.rst.Out(l) +} + +func (eh *errorHandler) cTx(w []byte, r []byte) { + if eh.err != nil { + return + } + eh.err = eh.d.c.Tx(w, r) +} + +func (eh *errorHandler) dcOut(l gpio.Level) { + if eh.err != nil { + return + } + eh.err = eh.d.dc.Out(l) +} + +func (eh *errorHandler) csOut(l gpio.Level) { + if eh.err != nil { + return + } + eh.err = eh.d.cs.Out(l) +} + +func (eh *errorHandler) sendCommand(cmd byte) { + if eh.err != nil { + return + } + eh.err = eh.d.sendCommand(cmd) +} + +func (eh *errorHandler) sendData(d []byte) { + if eh.err != nil { + return + } + eh.err = eh.d.sendData(d) +} diff --git a/waveshare2in13v2/waveshare213v2.go b/waveshare2in13v2/waveshare213v2.go index fa6d0e7..2018f6e 100644 --- a/waveshare2in13v2/waveshare213v2.go +++ b/waveshare2in13v2/waveshare213v2.go @@ -81,12 +81,6 @@ type Opts struct { // PartialUpdate defines if the display should do a full update or just a partial update. type PartialUpdate bool -// errorHandler is a wrapper for error management. -type errorHandler struct { - d Dev - err error -} - const ( // Full should update the complete display. Full PartialUpdate = false @@ -136,48 +130,6 @@ func dataDimensions(opts *Opts) (int, int) { return opts.Height, (opts.Width + 7) / 8 } -func (eh *errorHandler) rstOut(l gpio.Level) { - if eh.err != nil { - return - } - eh.err = eh.d.rst.Out(l) -} - -func (eh *errorHandler) cTx(w []byte, r []byte) { - if eh.err != nil { - return - } - eh.err = eh.d.c.Tx(w, r) -} - -func (eh *errorHandler) dcOut(l gpio.Level) { - if eh.err != nil { - return - } - eh.err = eh.d.dc.Out(l) -} - -func (eh *errorHandler) csOut(l gpio.Level) { - if eh.err != nil { - return - } - eh.err = eh.d.cs.Out(l) -} - -func (eh *errorHandler) sendCommand(cmd byte) { - if eh.err != nil { - return - } - eh.err = eh.d.sendCommand(cmd) -} - -func (eh *errorHandler) sendData(d []byte) { - if eh.err != nil { - return - } - eh.err = eh.d.sendData(d) -} - // 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) { c, err := p.Connect(5*physic.MegaHertz, spi.Mode0, 8)