epd

package
v3.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package epd controls Waveshare e-paper series displays.

More details

Datasheets

https://www.waveshare.com/w/upload/e/e6/2.13inch_e-Paper_Datasheet.pdf

Product page:

2.13 Inch version: https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT

1.54 inch version: https://www.waveshare.com/wiki/1.54inch_e-Paper_Module

Example
package main

import (
	"image"
	"log"

	"periph.io/x/periph/experimental/devices/epd"

	"periph.io/x/periph/conn/spi/spireg"

	"periph.io/x/periph/devices/ssd1306/image1bit"
	"periph.io/x/periph/host"
)

func main() {
	// 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 := epd.NewSPIHat(b, &epd.EPD2in13) // Display config and size
	if err != nil {
		log.Fatalf("failed to initialize epd: %v", err)
	}

	// Draw on it.
	img := image1bit.NewVerticalLSB(dev.Bounds())
	// Note: this code is commented out so periph does not depend on:
	//    "golang.org/x/image/font"
	//    "golang.org/x/image/font/basicfont"
	//    "golang.org/x/image/math/fixed"
	//
	// f := basicfont.Face7x13
	// drawer := font.Drawer{
	// 	Dst:  img,
	// 	Src:  &image.Uniform{image1bit.On},
	// 	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)
	}
	dev.DisplayFrame() // After drawing on the display, you have to show the frame
}
Output:

Example (Other)
package main

import (
	"image"
	"log"

	"periph.io/x/periph/experimental/devices/epd"

	"periph.io/x/periph/conn/spi/spireg"

	"periph.io/x/periph/host"
)

func main() {
	// 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 := epd.NewSPIHat(b, &epd.EPD2in13) // Display config and size
	if err != nil {
		log.Fatalf("failed to initialize epd: %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)
	}
	dev.DisplayFrame() // After drawing on the display, you have to show the frame
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var EPD1in54 = Opts{
	W: 200,
	H: 200,
	FullUpdate: LUT{
		0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22,
		0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88,
		0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51,
		0x35, 0x51, 0x51, 0x19, 0x01, 0x00,
	},
	PartialUpdate: LUT{
		0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	},
}

EPD1in54 is the config for the 1.54 inch display.

View Source
var EPD2in13 = Opts{
	W: 128,
	H: 250,
	FullUpdate: LUT{
		0x22, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x11,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,
		0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
	},
	PartialUpdate: LUT{
		0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	},
}

EPD2in13 is the config for the 2.13 inch display.

Functions

This section is empty.

Types

type Dev

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

Dev is an open handle to the display controller.

func NewSPI

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

NewSPI returns a Dev object that communicates over SPI to a E-Paper display controller.

func NewSPIHat

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

NewSPIHat returns a Dev object that communicates over SPI and have the default config for the e-paper hat for raspberry pi

func (*Dev) Bounds

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

Bounds implements display.Drawer. Min is guaranteed to be {0, 0}.

func (*Dev) ClearFrameMemory

func (d *Dev) ClearFrameMemory(color byte) error

ClearFrameMemory clear the frame memory with the specified color. this won't update the display.

func (*Dev) ColorModel

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

ColorModel implements display.Drawer. It is a one bit color model, as implemented by image1bit.Bit.

func (*Dev) DisplayFrame

func (d *Dev) DisplayFrame() error

DisplayFrame update the display.

There are 2 memory areas embedded in the e-paper display but once this function is called, the next action of SetFrameMemory or ClearFrame will set the other memory area.

func (*Dev) Draw

func (d *Dev) Draw(r image.Rectangle, src image.Image, sp image.Point) error

Draw implements display.Drawer.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt turns off the display.

func (*Dev) Init

func (d *Dev) Init() error

Init initialize the display config. This method is already called when creating a device using NewSPI and NewSPIHat methods.

It should be only used when you put the device to sleep and need to re-init the device.

func (*Dev) Reset

func (d *Dev) Reset()

Reset can be also used to awaken the device

func (*Dev) Sleep

func (d *Dev) Sleep() error

Sleep after this command is transmitted, the chip would enter the deep-sleep mode to save power.

The deep sleep mode would return to standby by hardware reset. You can use Reset() to awaken and Init to re-initialize the device.

func (*Dev) String

func (d *Dev) String() string

type LUT

type LUT []byte

LUT contains the display specific waveform for the pixel programming of the display.

type Opts

type Opts struct {
	W             int
	H             int
	FullUpdate    LUT
	PartialUpdate LUT
}

Opts defines the options for the ePaper Device.

type PartialUpdate

type PartialUpdate bool

PartialUpdate represents if updates to the display should be full or partial.

const (
	// Full LUT config to update all the display
	Full PartialUpdate = false
	// Partial LUT config only a part of the display
	Partial PartialUpdate = true
)

Jump to

Keyboard shortcuts

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