mirror of https://github.com/periph/devices
[inky] Add Inky Impression 5.7" and 4" support (#55)
It is a 7 colour ePaper/eInk HAT that comes with 5.7" (600 x 448 pixel) or 4" (640 x 400 pixel). Refactors the existing 3 color Inky and adds additional fields to auto-detect via EEPROM. Tested with 5.7" version.pull/57/head
parent
ae3205944c
commit
e271f7c07b
@ -0,0 +1,120 @@
|
|||||||
|
// Copyright 2023 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 inky
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"periph.io/x/conn/v3/i2c"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
displayVariantMap = [...]string{
|
||||||
|
"",
|
||||||
|
"Red pHAT (High-Temp)",
|
||||||
|
"Yellow wHAT",
|
||||||
|
"Black wHAT",
|
||||||
|
"Black pHAT",
|
||||||
|
"Yellow pHAT",
|
||||||
|
"Red wHAT",
|
||||||
|
"Red wHAT (High-Temp)",
|
||||||
|
"Red wHAT",
|
||||||
|
"",
|
||||||
|
"Black pHAT (SSD1608)",
|
||||||
|
"Red pHAT (SSD1608)",
|
||||||
|
"Yellow pHAT (SSD1608)",
|
||||||
|
"",
|
||||||
|
"7-Colour (UC8159)",
|
||||||
|
"7-Colour 640x400 (UC8159)",
|
||||||
|
"7-Colour 640x400 (UC8159)",
|
||||||
|
"Black wHAT (SSD1683)",
|
||||||
|
"Red wHAT (SSD1683)",
|
||||||
|
"Yellow wHAT (SSD1683)",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Opts is the options to specify which device is being controlled and its
|
||||||
|
// default settings.
|
||||||
|
type Opts struct {
|
||||||
|
// Boards's width and height.
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
|
|
||||||
|
// Model being used.
|
||||||
|
Model Model
|
||||||
|
// Model color.
|
||||||
|
ModelColor Color
|
||||||
|
// Initial border color. Will be set on the first Draw().
|
||||||
|
BorderColor Color
|
||||||
|
|
||||||
|
// Board information.
|
||||||
|
PCBVariant uint
|
||||||
|
DisplayVariant uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// DetectOpts tries to read the device opts from EEPROM.
|
||||||
|
func DetectOpts(bus i2c.Bus) (*Opts, error) {
|
||||||
|
// Read data from EEPROM
|
||||||
|
data, err := readEep(bus)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to detect Inky board: %v", err)
|
||||||
|
}
|
||||||
|
options := new(Opts)
|
||||||
|
|
||||||
|
options.Width = int(binary.LittleEndian.Uint16(data[0:]))
|
||||||
|
options.Height = int(binary.LittleEndian.Uint16(data[2:]))
|
||||||
|
|
||||||
|
switch data[4] {
|
||||||
|
case 1:
|
||||||
|
options.ModelColor = Black
|
||||||
|
options.BorderColor = Black
|
||||||
|
case 2:
|
||||||
|
options.ModelColor = Red
|
||||||
|
options.BorderColor = Red
|
||||||
|
case 3:
|
||||||
|
options.ModelColor = Yellow
|
||||||
|
options.BorderColor = Yellow
|
||||||
|
case 4:
|
||||||
|
options.ModelColor = Multi
|
||||||
|
options.BorderColor = Color(WhiteImpression)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("failed to get ops: color %v not supported", data[4])
|
||||||
|
}
|
||||||
|
// PCB Variant is stored as a number in the eeprom but is actually corresponds a version string (12 -> 1.2)
|
||||||
|
options.PCBVariant = uint(data[5])
|
||||||
|
|
||||||
|
switch data[6] {
|
||||||
|
case 1, 4, 5:
|
||||||
|
options.Model = PHAT
|
||||||
|
case 10, 11, 12:
|
||||||
|
options.Model = PHAT2
|
||||||
|
case 2, 3, 6, 7, 8:
|
||||||
|
options.Model = WHAT
|
||||||
|
case 14:
|
||||||
|
options.Model = IMPRESSION57
|
||||||
|
case 15, 16:
|
||||||
|
options.Model = IMPRESSION4
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("failed to get ops: display type %v not supported", data[6])
|
||||||
|
}
|
||||||
|
|
||||||
|
options.DisplayVariant = uint(data[6])
|
||||||
|
|
||||||
|
return options, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readEep(bus i2c.Bus) ([]byte, error) {
|
||||||
|
// Inky uses SMBus, specify read registry with data
|
||||||
|
write := []byte{0x00, 0x00}
|
||||||
|
|
||||||
|
data := make([]byte, 29)
|
||||||
|
|
||||||
|
if err := bus.Tx(0x50, write, data); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
// Copyright 2023 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 inky
|
||||||
|
|
||||||
|
//go:generate stringer -type=Model,Color,ImpressionColor -output types_string.go
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Model lists the supported e-ink display models.
|
||||||
|
type Model int
|
||||||
|
|
||||||
|
// Supported Model.
|
||||||
|
const (
|
||||||
|
PHAT Model = iota
|
||||||
|
WHAT
|
||||||
|
PHAT2
|
||||||
|
IMPRESSION4
|
||||||
|
IMPRESSION57
|
||||||
|
)
|
||||||
|
|
||||||
|
// Set sets the Model to a value represented by the string s. Set implements the flag.Value interface.
|
||||||
|
func (m *Model) Set(s string) error {
|
||||||
|
switch s {
|
||||||
|
case "PHAT":
|
||||||
|
*m = PHAT
|
||||||
|
case "PHAT2":
|
||||||
|
*m = PHAT2
|
||||||
|
case "WHAT":
|
||||||
|
*m = WHAT
|
||||||
|
case "IMPRESSION4":
|
||||||
|
*m = IMPRESSION4
|
||||||
|
case "IMPRESSION57":
|
||||||
|
*m = IMPRESSION57
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown model %q: expected PHAT, PHAT2, WHAT, IMPRESSION4 or IMPRESSION57", s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Color is used to define which model of inky is being used, and also for
|
||||||
|
// setting the border color.
|
||||||
|
type Color int
|
||||||
|
|
||||||
|
// Valid Color.
|
||||||
|
const (
|
||||||
|
Black Color = iota
|
||||||
|
Red
|
||||||
|
Yellow
|
||||||
|
White
|
||||||
|
Multi
|
||||||
|
)
|
||||||
|
|
||||||
|
// Set sets the Color to a value represented by the string s. Set implements the flag.Value interface.
|
||||||
|
func (c *Color) Set(s string) error {
|
||||||
|
switch s {
|
||||||
|
case "black":
|
||||||
|
*c = Black
|
||||||
|
case "red":
|
||||||
|
*c = Red
|
||||||
|
case "yellow":
|
||||||
|
*c = Yellow
|
||||||
|
case "white":
|
||||||
|
*c = White
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown color %q: expected either black, red, yellow or white", s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImpressionColor is used to define colors used by Inky Impression models.
|
||||||
|
type ImpressionColor uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
BlackImpression ImpressionColor = iota
|
||||||
|
WhiteImpression
|
||||||
|
GreenImpression
|
||||||
|
BlueImpression
|
||||||
|
RedImpression
|
||||||
|
YellowImpression
|
||||||
|
OrangeImpression
|
||||||
|
CleanImpression
|
||||||
|
)
|
||||||
|
|
||||||
|
// Set sets the ImpressionColor to a value represented by the string s. Set implements the flag.Value interface.
|
||||||
|
func (c *ImpressionColor) Set(s string) error {
|
||||||
|
switch s {
|
||||||
|
case "black":
|
||||||
|
*c = BlackImpression
|
||||||
|
case "white":
|
||||||
|
*c = WhiteImpression
|
||||||
|
case "green":
|
||||||
|
*c = GreenImpression
|
||||||
|
case "blue":
|
||||||
|
*c = BlueImpression
|
||||||
|
case "red":
|
||||||
|
*c = RedImpression
|
||||||
|
case "yellow":
|
||||||
|
*c = YellowImpression
|
||||||
|
case "orange":
|
||||||
|
*c = OrangeImpression
|
||||||
|
case "clean":
|
||||||
|
*c = CleanImpression
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown color %q: expected either black, white. green, blue, red, yellow, orange or clean", s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
// Code generated by "stringer -type=Model,Color,ImpressionColor -output types_string.go"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package inky
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[PHAT-0]
|
||||||
|
_ = x[WHAT-1]
|
||||||
|
_ = x[PHAT2-2]
|
||||||
|
_ = x[IMPRESSION4-3]
|
||||||
|
_ = x[IMPRESSION57-4]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _Model_name = "PHATWHATPHAT2IMPRESSION4IMPRESSION57"
|
||||||
|
|
||||||
|
var _Model_index = [...]uint8{0, 4, 8, 13, 24, 36}
|
||||||
|
|
||||||
|
func (i Model) String() string {
|
||||||
|
if i < 0 || i >= Model(len(_Model_index)-1) {
|
||||||
|
return "Model(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _Model_name[_Model_index[i]:_Model_index[i+1]]
|
||||||
|
}
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[Black-0]
|
||||||
|
_ = x[Red-1]
|
||||||
|
_ = x[Yellow-2]
|
||||||
|
_ = x[White-3]
|
||||||
|
_ = x[Multi-4]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _Color_name = "BlackRedYellowWhiteMulti"
|
||||||
|
|
||||||
|
var _Color_index = [...]uint8{0, 5, 8, 14, 19, 24}
|
||||||
|
|
||||||
|
func (i Color) String() string {
|
||||||
|
if i < 0 || i >= Color(len(_Color_index)-1) {
|
||||||
|
return "Color(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _Color_name[_Color_index[i]:_Color_index[i+1]]
|
||||||
|
}
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[BlackImpression-0]
|
||||||
|
_ = x[WhiteImpression-1]
|
||||||
|
_ = x[GreenImpression-2]
|
||||||
|
_ = x[BlueImpression-3]
|
||||||
|
_ = x[RedImpression-4]
|
||||||
|
_ = x[YellowImpression-5]
|
||||||
|
_ = x[OrangeImpression-6]
|
||||||
|
_ = x[CleanImpression-7]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _ImpressionColor_name = "BlackImpressionWhiteImpressionGreenImpressionBlueImpressionRedImpressionYellowImpressionOrangeImpressionCleanImpression"
|
||||||
|
|
||||||
|
var _ImpressionColor_index = [...]uint8{0, 15, 30, 45, 59, 72, 88, 104, 119}
|
||||||
|
|
||||||
|
func (i ImpressionColor) String() string {
|
||||||
|
if i >= ImpressionColor(len(_ImpressionColor_index)-1) {
|
||||||
|
return "ImpressionColor(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _ImpressionColor_name[_ImpressionColor_index[i]:_ImpressionColor_index[i+1]]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue