waveshare2in13v2

package
v3.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package waveshare2in13v2 controls Waveshare 2.13 v2 e-paper displays.

Datasheet: https://www.waveshare.com/w/upload/d/d5/2.13inch_e-Paper_Specification.pdf

Product page: 2.13 inch version 2: https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT

The Waveshare 2.13in v2 display is a GoodDisplay GDEH0213B72. Its IL3897 controller is compatible with the SSD1675A (sometimes also referred to as SSD1675). The SSD1675A should not be mixed up with the SSD1675B. They have different LUT formats (70 bytes for SSD1675A, 100 bytes for SSD1675B).

Example
// Make sure periph is initialized.
if _, err := host.Init(); err != nil {
	log.Fatal(err)
}

// Use spireg SPI bus registry to find the first available SPI bus.
b, err := spireg.Open("")
if err != nil {
	log.Fatal(err)
}
defer b.Close()

dev, err := waveshare2in13v2.NewHat(b, &waveshare2in13v2.EPD2in13v2) // Display config and size
if err != nil {
	log.Fatalf("Failed to initialize driver: %v", err)
}

err = dev.Init()
if err != nil {
	log.Fatalf("Failed to initialize display: %v", err)
}

// Draw on it. Black text on a white background.
img := image1bit.NewVerticalLSB(dev.Bounds())
draw.Draw(img, img.Bounds(), &image.Uniform{image1bit.On}, image.Point{}, draw.Src)
f := basicfont.Face7x13
drawer := font.Drawer{
	Dst:  img,
	Src:  &image.Uniform{image1bit.Off},
	Face: f,
	Dot:  fixed.P(0, img.Bounds().Dy()-1-f.Descent),
}
drawer.DrawString("Hello from periph!")

if err := dev.Draw(dev.Bounds(), img, image.Point{}); err != nil {
	log.Fatal(err)
}
Output:

Example (Other)
// Make sure periph is initialized.
if _, err := host.Init(); err != nil {
	log.Fatal(err)
}

// Use spireg SPI bus registry to find the first available SPI bus.
b, err := spireg.Open("")
if err != nil {
	log.Fatal(err)
}
defer b.Close()

dev, err := waveshare2in13v2.NewHat(b, &waveshare2in13v2.EPD2in13v2) // Display config and size
if err != nil {
	log.Fatalf("Failed to initialize driver: %v", err)
}

err = dev.Init()
if err != nil {
	log.Fatalf("Failed to initialize display: %v", err)
}

var img image.Image
// Note: this code is commented out so periph does not depend on:
//    "github.com/fogleman/gg"
//    "github.com/golang/freetype/truetype"
//    "golang.org/x/image/font/gofont/goregular"
// bounds := dev.Bounds()
// w := bounds.Dx()
// h := bounds.Dy()
// dc := gg.NewContext(w, h)
// im, err := gg.LoadPNG("gopher.png")
// if err != nil {
// 	panic(err)
// }
// dc.SetRGB(1, 1, 1)
// dc.Clear()
// dc.SetRGB(0, 0, 0)
// dc.Rotate(gg.Radians(90))
// dc.Translate(0.0, -float64(h/2))
// font, err := truetype.Parse(goregular.TTF)
// if err != nil {
// 	panic(err)
// }
// face := truetype.NewFace(font, &truetype.Options{
// 	Size: 16,
// })
// dc.SetFontFace(face)
// text := "Hello from periph!"
// tw, th := dc.MeasureString(text)
// dc.DrawImage(im, 120, 30)
// padding := 8.0
// dc.DrawRoundedRectangle(padding*2, padding*2, tw+padding*2, th+padding, 10)
// dc.Stroke()
// dc.DrawString(text, padding*3, padding*2+th)
// for i := 0; i < 10; i++ {
// 	dc.DrawCircle(float64(30+(10*i)), 100, 5)
// }
// for i := 0; i < 10; i++ {
// 	dc.DrawRectangle(float64(30+(10*i)), 80, 5, 5)
// }
// dc.Fill()
// img = dc.Image()

if err := dev.Draw(dev.Bounds(), img, image.Point{}); err != nil {
	log.Fatal(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var EPD2in13v2 = Opts{
	Width:  122,
	Height: 250,
	FullUpdate: LUT{
		0x80, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00,
		0x10, 0x60, 0x20, 0x00, 0x00, 0x00, 0x00,
		0x80, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00,
		0x10, 0x60, 0x20, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

		0x03, 0x03, 0x00, 0x00, 0x02,
		0x09, 0x09, 0x00, 0x00, 0x02,
		0x03, 0x03, 0x00, 0x00, 0x02,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
	},
	PartialUpdate: LUT{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

		0x0A, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
	},
}

EPD2in13v2 cointains display configuration for the Waveshare 2in13v2.

Functions

This section is empty.

Types

type Corner added in v3.6.14

type Corner uint8

Corner describes a corner on the physical device and is used to define the origin for drawing operations.

const (
	TopLeft Corner = iota
	TopRight
	BottomRight
	BottomLeft
)

type Dev

type Dev struct {
	// contains filtered or unexported fields
}

Dev defines the handler which is used to access the display.

func New

func New(p spi.Port, dc, cs, rst gpio.PinOut, busy gpio.PinIn, opts *Opts) (*Dev, error)

New creates new handler which is used to access the display.

func NewHat

func NewHat(p spi.Port, opts *Opts) (*Dev, error)

NewHat creates new handler which is used to access the display. Default Waveshare Hat configuration is used.

func (*Dev) Bounds

func (d *Dev) Bounds() image.Rectangle

Bounds returns the bounds for the configurated display.

func (*Dev) Clear

func (d *Dev) Clear(color color.Color) error

Clear clears the display.

func (*Dev) ColorModel

func (d *Dev) ColorModel() color.Model

ColorModel returns a 1Bit color model.

func (*Dev) Draw

func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPts image.Point) error

Draw draws the given image to the display. Only the destination area is uploaded. Depending on the update mode the whole display or the destination area is refreshed.

func (*Dev) DrawPartial deprecated

func (d *Dev) DrawPartial(dstRect image.Rectangle, src image.Image, srcPts image.Point) error

DrawPartial draws the given image to the display.

Deprecated: Use Draw instead. DrawPartial merely forwards all calls.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt clears the display.

func (*Dev) Init

func (d *Dev) Init() error

Init configures the display for usage through the other functions.

func (*Dev) SetUpdateMode added in v3.6.14

func (d *Dev) SetUpdateMode(mode PartialUpdate) error

SetUpdateMode changes the way updates to the displayed image are applied. In Full mode (the default) a full refresh is done with all pixels cleared and re-applied. In Partial mode only the changed pixels are updated (aligned to multiples of 8 on the horizontal axis), potentially leaving behind small optical artifacts due to the way e-paper displays work.

The vendor datasheet recommends a full update at least once every 24 hours. When using partial updates the Clear function can be used for the purpose, followed by re-drawing.

func (*Dev) Sleep added in v3.6.14

func (d *Dev) Sleep() error

Sleep makes the controller enter deep sleep mode. It can be woken up by calling Init again.

func (*Dev) String

func (d *Dev) String() string

String returns a string containing configuration information.

type LUT

type LUT []byte

LUT contains the waveform that is used to program the display.

type Opts

type Opts struct {
	Width         int
	Height        int
	Origin        Corner
	FullUpdate    LUT
	PartialUpdate LUT
}

Opts definies the structure of the display configuration.

type PartialUpdate

type PartialUpdate bool

PartialUpdate defines if the display should do a full update or just a partial update.

const (
	// Full should update the complete display.
	Full PartialUpdate = false
	// Partial should update only partial parts of the display.
	Partial PartialUpdate = true
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL