diff --git a/README.md b/README.md index 3de4c2c..13b2dcb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/devices/apa102/apa102.go b/devices/apa102/apa102.go index 2f5eb11..c97a911 100644 --- a/devices/apa102/apa102.go +++ b/devices/apa102/apa102.go @@ -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{} diff --git a/devices/bme280/bme280.go b/devices/bme280/bme280.go index 7d85825..df77a5a 100644 --- a/devices/bme280/bme280.go +++ b/devices/bme280/bme280.go @@ -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 diff --git a/devices/devicestest/display.go b/devices/devicestest/display.go index 7f177ae..7cbfa81 100644 --- a/devices/devicestest/display.go +++ b/devices/devicestest/display.go @@ -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 diff --git a/devices/ssd1306/image1bit/image1bit.go b/devices/ssd1306/image1bit/image1bit.go index 6ddf1ca..baa5b85 100644 --- a/devices/ssd1306/image1bit/image1bit.go +++ b/devices/ssd1306/image1bit/image1bit.go @@ -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 } diff --git a/devices/ssd1306/ssd1306.go b/devices/ssd1306/ssd1306.go index 503a51d..798fb8c 100644 --- a/devices/ssd1306/ssd1306.go +++ b/devices/ssd1306/ssd1306.go @@ -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 diff --git a/experimental/devices/bitbang/i2c.go b/experimental/devices/bitbang/i2c.go index b49aeec..725b8a1 100644 --- a/experimental/devices/bitbang/i2c.go +++ b/experimental/devices/bitbang/i2c.go @@ -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 { diff --git a/experimental/devices/bitbang/spi.go b/experimental/devices/bitbang/spi.go index 3dd13e2..a1591d6 100644 --- a/experimental/devices/bitbang/spi.go +++ b/experimental/devices/bitbang/spi.go @@ -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() diff --git a/experimental/devices/piblaster/piblaster.go b/experimental/devices/piblaster/piblaster.go index e784ee7..d82bac4 100644 --- a/experimental/devices/piblaster/piblaster.go +++ b/experimental/devices/piblaster/piblaster.go @@ -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 {