Increase polish. (#75)

- Make error more consistent and more helpful. Not all errors are wrapped yet
  but a fair part is now.
- Remove the 'first' pattern in i2c, spi, uart and make it work.
- Add allwinner.Pin.wrap() for coherence with PinPL and bcm283x.Pin.
- headers.All() return a copy.
pull/1/head
M-A 10 years ago committed by Thorsten von Eicken
parent 5cddc1641d
commit 0075d9e849

@ -83,10 +83,10 @@ your platform.
**Every commit is [tested on real hardware](doc/drivers/CONTRIBUTING.md#testing)
via [gohci](https://github.com/maruel/gohci) workers.**
We gladly accept contributions from device driver developers via GitHub pull
requests, as long as the author has signed the Google Contributor License.
Please see [doc/drivers/CONTRIBUTING.md](doc/drivers/CONTRIBUTING.md) for more
details.
We gladly accept contributions for documentation improvements and from device
driver developers via GitHub pull requests, as long as the author has signed the
Google Contributor License. Please see
[doc/drivers/CONTRIBUTING.md](doc/drivers/CONTRIBUTING.md) for more details.
## Philosophy

@ -300,6 +300,6 @@ func New(s spi.Conn, numLights int, intensity uint8, temperature uint16) (*Dev,
//
var errLength = errors.New("invalid RGB stream length")
var errLength = errors.New("apa102: invalid RGB stream length")
var _ devices.Display = &Dev{}

@ -146,7 +146,7 @@ func NewI2C(b i2c.Bus, opts *Opts) (*Dev, error) {
case 0x00:
// do not do anything
default:
return nil, errors.New("given address not supported by device")
return nil, errors.New("bme280: given address not supported by device")
}
}
d := &Dev{d: &i2c.Dev{Bus: b, Addr: addr}, isSPI: false}
@ -232,7 +232,7 @@ func (d *Dev) makeDev(opts *Opts) error {
return err
}
if chipID[0] != 0x60 {
return errors.New("unexpected chip id; is this a BME280?")
return errors.New("bme280: unexpected chip id; is this a BME280?")
}
// Read calibration data t1~3, p1~9, 8bits padding, h1.
var tph [0xA2 - 0x88]byte

@ -21,7 +21,7 @@ type Display struct {
// Write implements devices.Display.
func (d *Display) Write(pixels []byte) (int, error) {
if len(pixels)%3 != 0 {
return 0, errors.New("invalid RGB stream length")
return 0, errors.New("devicetest: invalid RGB stream length")
}
copy(d.Img.Pix, pixels)
return len(pixels), nil

@ -56,7 +56,7 @@ func New(r image.Rectangle) (*Image, error) {
h := r.Dy()
w := r.Dx()
if h&7 != 0 {
return nil, errors.New("height must be multiple of 8")
return nil, errors.New("image1bit: height must be multiple of 8")
}
return &Image{w, h, make([]byte, w*h/8)}, nil
}

@ -20,6 +20,7 @@ package ssd1306
import (
"errors"
"fmt"
"image"
"image/color"
"io"
@ -95,16 +96,12 @@ func NewI2C(i i2c.Bus, w, h int, rotated bool) (*Dev, error) {
// newDev is the common initialization code that is independent of the bus
// being used.
func newDev(dev io.Writer, w, h int, rotated bool) (*Dev, error) {
if w&7 != 0 || h&7 != 0 {
return nil, errors.New("height and width must be multiple of 8")
if w < 8 || w > 128 || w&7 != 0 {
return nil, fmt.Errorf("ssd1306: invalid width %d", w)
}
if w < 8 || w > 128 {
return nil, errors.New("invalid height")
if h < 8 || h > 64 || h&7 != 0 {
return nil, fmt.Errorf("ssd1306: invalid height %d", h)
}
if h < 8 || h > 64 {
return nil, errors.New("invalid width")
}
d := &Dev{w: dev, W: w, H: h}
contrast := byte(0x7F) // (default value)
@ -226,7 +223,7 @@ func (d *Dev) Draw(r image.Rectangle, src image.Image, sp image.Point) {
// the memory is effectively horizontal bands of 8 pixels high.
func (d *Dev) Write(pixels []byte) (int, error) {
if len(pixels) != d.H*d.W/8 {
return 0, errors.New("invalid pixel stream")
return 0, errors.New("ssd1306: invalid pixel stream")
}
// Run as 2 big transactions to reduce downtime on the bus. Doing with one

@ -54,7 +54,7 @@ func (i *I2C) Tx(addr uint16, w, r []byte) error {
if addr > 0xFF {
// Page 15, section 3.1.11 10-bit addressing
// TOOD(maruel): Implement if desired; prefix 0b11110xx.
return errors.New("invalid address")
return errors.New("bitbang-i2c: invalid address")
}
// Page 13, section 3.1.10 The slave address and R/W bit
addr <<= 1
@ -66,7 +66,7 @@ func (i *I2C) Tx(addr uint16, w, r []byte) error {
return err
}
if !ack {
return errors.New("i2c: got NACK")
return errors.New("bitbang-i2c: got NACK")
}
}
for _, b := range w {
@ -75,7 +75,7 @@ func (i *I2C) Tx(addr uint16, w, r []byte) error {
return err
}
if !ack {
return errors.New("i2c: got NACK")
return errors.New("bitbang-i2c: got NACK")
}
}
for x := range r {

@ -71,7 +71,7 @@ func (s *SPI) Configure(mode spi.Mode, bits int) error {
// BUG(maruel): Test if read works.
func (s *SPI) Tx(w, r []byte) error {
if len(r) != 0 && len(w) != len(r) {
return errors.New("write and read buffers must be the same length")
return errors.New("bitbang-spi: write and read buffers must be the same length")
}
s.mu.Lock()
defer s.mu.Unlock()

@ -29,7 +29,7 @@ import (
// duty must be [0, 1].
func SetPWM(p gpio.PinIO, duty float32) error {
if duty < 0 || duty > 1 {
return fmt.Errorf("duty %f is invalid for blaster", duty)
return fmt.Errorf("piblaster: duty %f is invalid for blaster", duty)
}
err := openPiblaster()
if err == nil {

Loading…
Cancel
Save