Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:41 +01:00
1 parent b8a493b93d
commit 85a9ec684c
54 files changed
+6855 -526

No files matched your search

+6
View File
@@ -10,12 +10,18 @@ import (
type Display interface {
Driver
// PowerSave puts the display to sleep.
PowerSave(on bool) error
// Draw an image on the display.
Draw(r image.Rectangle, src image.Image, sp image.Point) error
// Size of the display.
Size() image.Point
// Clear the display buffer.
Clear()
// Fill with one color.
Fill(color.Color) error
+3
View File
@@ -3,4 +3,7 @@ package all
import (
_ "go.maze.io/harmon/hardware/display/ssd1306" // SSD1306
_ "go.maze.io/harmon/hardware/display/ssd1322" // SSD1322
//_ "go.maze.io/harmon/hardware/display/st7735" // ST7735
//_ "go.maze.io/harmon/hardware/display/st7789" // ST7789
)
+113
View File
@@ -0,0 +1,113 @@
package display
import (
"image"
"image/color"
"image/draw"
"go.maze.io/harmon/hardware"
)
type Combined struct {
displays []hardware.Display
size image.Point
stride int
}
func NewCombined(displays ...hardware.Display) hardware.Display {
d := &Combined{
displays: displays,
size: displays[0].Size(),
stride: displays[0].Size().X,
}
return d
}
func (d *Combined) At(x, y int) color.Color {
if x < 0 || y < 0 || y >= d.size.Y {
return color.Black
}
for _, display := range d.displays {
if x < d.size.X {
return display.At(x, y)
}
x -= d.stride
}
return color.Black
}
func (d *Combined) PowerSave(on bool) error {
for _, p := range d.displays {
if err := p.PowerSave(on); err != nil {
return err
}
}
return nil
}
func (d *Combined) Bounds() image.Rectangle {
return image.Rectangle{Max: d.Size()}
}
func (d *Combined) ColorModel() color.Model {
return d.displays[0].ColorModel()
}
func (d *Combined) Clear() {
for _, p := range d.displays {
p.Clear()
}
}
func (d *Combined) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
draw.Draw(d, r, src, sp, draw.Src)
return d.Refresh()
}
func (d *Combined) Fill(c color.Color) error {
for _, p := range d.displays {
if err := p.Fill(c); err != nil {
return err
}
}
return nil
}
func (d *Combined) Halt() error {
for _, p := range d.displays {
if err := p.Halt(); err != nil {
return err
}
}
return nil
}
func (d *Combined) Refresh() error {
for _, p := range d.displays {
if err := p.Refresh(); err != nil {
return err
}
}
return nil
}
func (d *Combined) Set(x, y int, c color.Color) {
if x < 0 || y < 0 || y >= d.size.Y {
return
}
for _, p := range d.displays {
if x < d.size.X {
p.Set(x, y, c)
return
}
x -= d.stride
}
}
func (d *Combined) Size() image.Point {
return image.Point{X: d.stride * len(d.displays), Y: d.size.Y}
}
func (Combined) Type() string {
return "combined"
}
+22
View File
@@ -167,6 +167,9 @@ func InvalidMode(mode string) error {
type Conn interface {
// Tx transfers data over the bus.
Tx(data []byte, isCommand bool) error
// Rx receives data over the bus.
Rx(command byte, data []byte) error
}
type i2cConn struct {
@@ -181,6 +184,10 @@ func (c i2cConn) Tx(data []byte, isCommand bool) error {
}
}
func (c i2cConn) Rx(command byte, data []byte) error {
return errors.New("not implemented")
}
// OpenI2C opens the named I²C bus and connects to the device at addr.
func OpenI2C(name, addr string) (Conn, error) {
log := logrus.WithFields(logrus.Fields{
@@ -228,6 +235,21 @@ func (c spiConn) Tx(data []byte, isCommand bool) (err error) {
return c.conn.Tx(data, nil)
}
func (c spiConn) Rx(command byte, data []byte) (err error) {
if c.dc == nil {
return errors.New("3-wire SPI mode is not implemented")
}
if err := c.Tx([]byte{command}, true); err != nil {
return err
}
if err := c.dc.Out(gpio.High); err != nil {
return err
}
return nil
}
// OpenSPI opens the named SPI port and connects to the device.
func OpenSPI(name, resetPin, dcPin string) (Conn, error) {
log := logrus.WithFields(logrus.Fields{
+252 -9
View File
@@ -2,23 +2,266 @@ package display
import (
"image"
"image/color"
"image/draw"
"os"
"go.maze.io/harmon/internal/pixel"
"golang.org/x/image/font"
"golang.org/x/image/font/basicfont"
"golang.org/x/image/font/inconsolata"
"golang.org/x/image/math/fixed"
"go.maze.io/harmon/internal/pixel"
_ "image/gif" // GIF codec
_ "image/jpeg" // JPEG codec
_ "image/png" // PNG codec
)
func DrawText(d draw.Image, x, y int, text string) {
var (
point = fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)}
drawer = &font.Drawer{
Dst: d,
Src: &image.Uniform{pixel.On},
Face: basicfont.Face7x13,
Dot: point,
var (
Font7x13 = basicfont.Face7x13
Font8x16 = inconsolata.Regular8x16
)
type Drawer interface {
Draw(r image.Rectangle, src image.Image, sp image.Point) error
}
func DrawRectangle(d draw.Image, x, y, w, h int, c color.Color) {
for i, l := y, y+h; i < l; i++ {
DrawLine(d, x, i, x+w, i, c)
}
}
func DrawLine(p draw.Image, x1, y1, x2, y2 int, c color.Color) {
var dx, dy, e, slope int
// Because drawing p1 -> p2 is equivalent to draw p2 -> p1,
// I sort points in x-axis order to handle only half of possible cases.
if x1 > x2 {
x1, y1, x2, y2 = x2, y2, x1, y1
}
dx, dy = x2-x1, y2-y1
// Because point is x-axis ordered, dx cannot be negative
if dy < 0 {
dy = -dy
}
switch {
// Is line a point ?
case x1 == x2 && y1 == y2:
p.Set(x1, y1, c)
// Is line an horizontal ?
case y1 == y2:
for ; dx != 0; dx-- {
p.Set(x1, y1, c)
x1++
}
p.Set(x1, y1, c)
// Is line a vertical ?
case x1 == x2:
if y1 > y2 {
y1, y2 = y2, y1
}
for ; dy != 0; dy-- {
p.Set(x1, y1, c)
y1++
}
p.Set(x1, y1, c)
// Is line a diagonal ?
case dx == dy:
if y1 < y2 {
for ; dx != 0; dx-- {
p.Set(x1, y1, c)
x1++
y1++
}
} else {
for ; dx != 0; dx-- {
p.Set(x1, y1, c)
x1++
y1--
}
}
p.Set(x1, y1, c)
// wider than high ?
case dx > dy:
if y1 < y2 {
// BresenhamDxXRYD(img, x1, y1, x2, y2, col)
dy, e, slope = 2*dy, dx, 2*dx
for ; dx != 0; dx-- {
p.Set(x1, y1, c)
x1++
e -= dy
if e < 0 {
y1++
e += slope
}
}
} else {
// BresenhamDxXRYU(img, x1, y1, x2, y2, col)
dy, e, slope = 2*dy, dx, 2*dx
for ; dx != 0; dx-- {
p.Set(x1, y1, c)
x1++
e -= dy
if e < 0 {
y1--
e += slope
}
}
}
p.Set(x2, y2, c)
// higher than wide.
default:
if y1 < y2 {
// BresenhamDyXRYD(img, x1, y1, x2, y2, col)
dx, e, slope = 2*dx, dy, 2*dy
for ; dy != 0; dy-- {
p.Set(x1, y1, c)
y1++
e -= dx
if e < 0 {
x1++
e += slope
}
}
} else {
// BresenhamDyXRYU(img, x1, y1, x2, y2, col)
dx, e, slope = 2*dx, dy, 2*dy
for ; dy != 0; dy-- {
p.Set(x1, y1, c)
y1--
e -= dx
if e < 0 {
x1++
e += slope
}
}
}
p.Set(x2, y2, c)
}
}
func DrawText(d draw.Image, x, y int, face font.Face, text string) {
var (
fontHeight int
fontWidth int
)
if f, ok := face.(*basicfont.Face); ok {
fontWidth = f.Advance
fontHeight = f.Height
} else {
metrics := face.Metrics()
if advance, ok := face.GlyphAdvance('X'); ok {
fontWidth = advance.Round()
}
fontHeight = metrics.Height.Ceil()
}
drawer := &font.Drawer{
Dst: d,
Src: &image.Uniform{pixel.On},
Face: face,
}
drawer.Dot = fixed.P(x*fontWidth, y*fontHeight)
drawer.DrawString(text)
}
func drawCircle(d draw.Image, xc, yc, x, y int, c color.Color) {
d.Set(xc+x, yc+y, c)
d.Set(xc-x, yc+y, c)
d.Set(xc+x, yc-y, c)
d.Set(xc-x, yc-y, c)
d.Set(xc+y, yc+x, c)
d.Set(xc-y, yc+x, c)
d.Set(xc+y, yc-x, c)
d.Set(xc-y, yc-x, c)
}
func DrawCircle(i draw.Image, xc, yc, r int, c color.Color) {
var (
x int
y = r
d = 3 - 2*r
)
drawCircle(i, xc, yc, x, y, c)
for y >= x {
if d > 0 {
y--
d = d + 4*(x-y) + 10
} else {
d = d + 4*x + 6
}
x++
drawCircle(i, xc, yc, x, y, c)
}
}
func DrawImage(d draw.Image, x, y int, name string) error {
f, err := os.Open(name)
if err != nil {
return err
}
i, _, err := image.Decode(f)
if err != nil {
_ = f.Close()
return err
}
r := d.Bounds()
if d, ok := d.(Drawer); ok {
r.Min = image.Pt(x, y)
return d.Draw(r, i, image.Point{})
}
draw.Draw(d, r, i, image.Point{}, draw.Src)
return nil
}
func Scroll(d draw.Image, xstep, ystep int) {
var (
sx, y, xend, yend, dx, dy int
r = d.Bounds()
)
if xstep < 0 {
xend = r.Max.X + xstep
if xend <= 0 {
return
}
dx = 1
} else {
sx = r.Max.X - 1
xend = xstep - 1
if xend >= sx {
return
}
}
if ystep < 0 {
yend = r.Max.Y + ystep
if yend <= 0 {
return
}
dy = 1
} else {
y = r.Max.Y - 1
yend = ystep - 1
if yend >= y {
return
}
dy = -1
}
for ; y != yend; y += dy {
for x := sx; x != xend; x += dx {
d.Set(x, y, d.At(x, y))
}
}
}
+466
View File
@@ -0,0 +1,466 @@
package display
import (
"go.maze.io/harmon/hardware"
"go.maze.io/harmon/internal/pixel"
)
// Font types
const (
FONT_6x8 = 0x00
FONT_7x10 = 0x01
FONT_11x18 = 0x02
FONT_16x26 = 0x03
)
// Configure initializes the display with default configuration
func Print(d hardware.Display, font int, x, y int, text string) {
fontWidth, _ := fontSize(font)
for _, char := range text {
PrintChar(d, font, x, y, byte(char))
x += fontWidth
}
}
func PrintChar(d hardware.Display, font int, x, y int, char byte) {
fontWidth, fontHeight := fontSize(font)
glyph := int(char-32) * fontHeight
for i := 0; i < fontHeight; i++ {
for j := 0; j < fontWidth; j++ {
var bit uint16 = 0
switch font {
case FONT_6x8:
bit = (Font6x8[i+glyph])
case FONT_7x10:
bit = (Font7x10[i+glyph])
case FONT_11x18:
bit = (Font11x18[i+glyph])
case FONT_16x26:
bit = (Font16x26[i+glyph])
default:
break
}
bit = bit & (0x8000 >> j)
if bit != 0 {
d.Set(j+x, i+y, pixel.On)
} else {
d.Set(j+x, i+y, pixel.Off)
}
}
}
}
func fontSize(font int) (fontWidth, fontHeight int) {
switch font {
case FONT_6x8:
fontWidth = 6
fontHeight = 8
case FONT_7x10:
fontWidth = 7
fontHeight = 10
case FONT_11x18:
fontWidth = 11
fontHeight = 18
case FONT_16x26:
fontWidth = 16
fontHeight = 26
}
return
}
var Font6x8 = [...]uint16{
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // sp
0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, 0x2000, 0x0000, // !
0x5000, 0x5000, 0x5000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // "
0x5000, 0x5000, 0xf800, 0x5000, 0xf800, 0x5000, 0x5000, 0x0000, // #
0x2000, 0x7800, 0xa000, 0x7000, 0x2800, 0xf000, 0x2000, 0x0000, // $
0xc000, 0xc800, 0x1000, 0x2000, 0x4000, 0x9800, 0x1800, 0x0000, // %
0x4000, 0xa000, 0xa000, 0x4000, 0xa800, 0x9000, 0x6800, 0x0000, // &
0x3000, 0x3000, 0x2000, 0x4000, 0x0000, 0x0000, 0x0000, 0x0000, // '
0x1000, 0x2000, 0x4000, 0x4000, 0x4000, 0x2000, 0x1000, 0x0000, // (
0x4000, 0x2000, 0x1000, 0x1000, 0x1000, 0x2000, 0x4000, 0x0000, // )
0x2000, 0xa800, 0x7000, 0xf800, 0x7000, 0xa800, 0x2000, 0x0000, // *
0x0000, 0x2000, 0x2000, 0xf800, 0x2000, 0x2000, 0x0000, 0x0000, // +
0x0000, 0x0000, 0x0000, 0x0000, 0x3000, 0x3000, 0x2000, 0x0000, // ,
0x0000, 0x0000, 0x0000, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, // -
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3000, 0x3000, 0x0000, // .
0x0000, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0x0000, 0x0000, // /
0x7000, 0x8800, 0x9800, 0xa800, 0xc800, 0x8800, 0x7000, 0x0000, // 0
0x2000, 0x6000, 0x2000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // 1
0x7000, 0x8800, 0x0800, 0x7000, 0x8000, 0x8000, 0xf800, 0x0000, // 2
0xf800, 0x0800, 0x1000, 0x3000, 0x0800, 0x8800, 0x7000, 0x0000, // 3
0x1000, 0x3000, 0x5000, 0x9000, 0xf800, 0x1000, 0x1000, 0x0000, // 4
0xf800, 0x8000, 0xf000, 0x0800, 0x0800, 0x8800, 0x7000, 0x0000, // 5
0x3800, 0x4000, 0x8000, 0xf000, 0x8800, 0x8800, 0x7000, 0x0000, // 6
0xf800, 0x0800, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0x0000, // 7
0x7000, 0x8800, 0x8800, 0x7000, 0x8800, 0x8800, 0x7000, 0x0000, // 8
0x7000, 0x8800, 0x8800, 0x7800, 0x0800, 0x1000, 0xe000, 0x0000, // 9
0x0000, 0x0000, 0x2000, 0x0000, 0x2000, 0x0000, 0x0000, 0x0000, // :
0x0000, 0x0000, 0x2000, 0x0000, 0x2000, 0x2000, 0x4000, 0x0000, // ;
0x0800, 0x1000, 0x2000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0000, // <
0x0000, 0x0000, 0xf800, 0x0000, 0xf800, 0x0000, 0x0000, 0x0000, // =
0x4000, 0x2000, 0x1000, 0x0800, 0x1000, 0x2000, 0x4000, 0x0000, // >
0x7000, 0x8800, 0x0800, 0x3000, 0x2000, 0x0000, 0x2000, 0x0000, // ?
0x7000, 0x8800, 0xa800, 0xb800, 0xb000, 0x8000, 0x7800, 0x0000, // @
0x2000, 0x5000, 0x8800, 0x8800, 0xf800, 0x8800, 0x8800, 0x0000, // A
0xf000, 0x8800, 0x8800, 0xf000, 0x8800, 0x8800, 0xf000, 0x0000, // B
0x7000, 0x8800, 0x8000, 0x8000, 0x8000, 0x8800, 0x7000, 0x0000, // C
0xf000, 0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0xf000, 0x0000, // D
0xf800, 0x8000, 0x8000, 0xf000, 0x8000, 0x8000, 0xf800, 0x0000, // E
0xf800, 0x8000, 0x8000, 0xf000, 0x8000, 0x8000, 0x8000, 0x0000, // F
0x7800, 0x8800, 0x8000, 0x8000, 0x9800, 0x8800, 0x7800, 0x0000, // G
0x8800, 0x8800, 0x8800, 0xf800, 0x8800, 0x8800, 0x8800, 0x0000, // H
0x7000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // I
0x3800, 0x1000, 0x1000, 0x1000, 0x1000, 0x9000, 0x6000, 0x0000, // J
0x8800, 0x9000, 0xa000, 0xc000, 0xa000, 0x9000, 0x8800, 0x0000, // K
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0xf800, 0x0000, // L
0x8800, 0xd800, 0xa800, 0xa800, 0xa800, 0x8800, 0x8800, 0x0000, // M
0x8800, 0x8800, 0xc800, 0xa800, 0x9800, 0x8800, 0x8800, 0x0000, // N
0x7000, 0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x7000, 0x0000, // O
0xf000, 0x8800, 0x8800, 0xf000, 0x8000, 0x8000, 0x8000, 0x0000, // P
0x7000, 0x8800, 0x8800, 0x8800, 0xa800, 0x9000, 0x6800, 0x0000, // Q
0xf000, 0x8800, 0x8800, 0xf000, 0xa000, 0x9000, 0x8800, 0x0000, // R
0x7000, 0x8800, 0x8000, 0x7000, 0x0800, 0x8800, 0x7000, 0x0000, // S
0xf800, 0xa800, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, // T
0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x7000, 0x0000, // U
0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x5000, 0x2000, 0x0000, // V
0x8800, 0x8800, 0x8800, 0xa800, 0xa800, 0xa800, 0x5000, 0x0000, // W
0x8800, 0x8800, 0x5000, 0x2000, 0x5000, 0x8800, 0x8800, 0x0000, // X
0x8800, 0x8800, 0x5000, 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, // Y
0xf800, 0x0800, 0x1000, 0x7000, 0x4000, 0x8000, 0xf800, 0x0000, // Z
0x7800, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x7800, 0x0000, // [
0x0000, 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0000, 0x0000, /* \ */
0x7800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x7800, 0x0000, // ]
0x2000, 0x5000, 0x8800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ^
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf800, 0x0000, // _
0x6000, 0x6000, 0x2000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, // `
0x0000, 0x0000, 0x6000, 0x1000, 0x7000, 0x9000, 0x7800, 0x0000, // a
0x8000, 0x8000, 0xb000, 0xc800, 0x8800, 0xc800, 0xb000, 0x0000, // b
0x0000, 0x0000, 0x7000, 0x8800, 0x8000, 0x8800, 0x7000, 0x0000, // c
0x0800, 0x0800, 0x6800, 0x9800, 0x8800, 0x9800, 0x6800, 0x0000, // d
0x0000, 0x0000, 0x7000, 0x8800, 0xf800, 0x8000, 0x7000, 0x0000, // e
0x1000, 0x2800, 0x2000, 0x7000, 0x2000, 0x2000, 0x2000, 0x0000, // f
0x0000, 0x0000, 0x7000, 0x9800, 0x9800, 0x6800, 0x0800, 0x0000, // g
0x8000, 0x8000, 0xb000, 0xc800, 0x8800, 0x8800, 0x8800, 0x0000, // h
0x2000, 0x0000, 0x6000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // i
0x1000, 0x0000, 0x1000, 0x1000, 0x1000, 0x9000, 0x6000, 0x0000, // j
0x8000, 0x8000, 0x9000, 0xa000, 0xc000, 0xa000, 0x9000, 0x0000, // k
0x6000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // l
0x0000, 0x0000, 0xd000, 0xa800, 0xa800, 0xa800, 0xa800, 0x0000, // m
0x0000, 0x0000, 0xb000, 0xc800, 0x8800, 0x8800, 0x8800, 0x0000, // n
0x0000, 0x0000, 0x7000, 0x8800, 0x8800, 0x8800, 0x7000, 0x0000, // o
0x0000, 0x0000, 0xb000, 0xc800, 0xc800, 0xb000, 0x8000, 0x0000, // p
0x0000, 0x0000, 0x6800, 0x9800, 0x9800, 0x6800, 0x0800, 0x0000, // q
0x0000, 0x0000, 0xb000, 0xc800, 0x8000, 0x8000, 0x8000, 0x0000, // r
0x0000, 0x0000, 0x7800, 0x8000, 0x7000, 0x0800, 0xf000, 0x0000, // s
0x2000, 0x2000, 0xf800, 0x2000, 0x2000, 0x2800, 0x1000, 0x0000, // t
0x0000, 0x0000, 0x8800, 0x8800, 0x8800, 0x9800, 0x6800, 0x0000, // u
0x0000, 0x0000, 0x8800, 0x8800, 0x8800, 0x5000, 0x2000, 0x0000, // v
0x0000, 0x0000, 0x8800, 0x8800, 0xa800, 0xa800, 0x5000, 0x0000, // w
0x0000, 0x0000, 0x8800, 0x5000, 0x2000, 0x5000, 0x8800, 0x0000, // x
0x0000, 0x0000, 0x8800, 0x8800, 0x7800, 0x0800, 0x8800, 0x0000, // y
0x0000, 0x0000, 0xf800, 0x1000, 0x2000, 0x4000, 0xf800, 0x0000, // z
0x1000, 0x2000, 0x2000, 0x4000, 0x2000, 0x2000, 0x1000, 0x0000, // {
0x2000, 0x2000, 0x2000, 0x0000, 0x2000, 0x2000, 0x2000, 0x0000, // |
0x4000, 0x2000, 0x2000, 0x1000, 0x2000, 0x2000, 0x4000, 0x0000, // }
0x4000, 0xa800, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ~
}
// start from 32[space] up to 126[~] = offset -32
var Font7x10 = [...]uint16{
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // space
0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000, // !
0x2800, 0x2800, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // "
0x2400, 0x2400, 0x7C00, 0x2400, 0x4800, 0x7C00, 0x4800, 0x4800, 0x0000, 0x0000, // #
0x3800, 0x5400, 0x5000, 0x3800, 0x1400, 0x5400, 0x5400, 0x3800, 0x1000, 0x0000, // $
0x2000, 0x5400, 0x5800, 0x3000, 0x2800, 0x5400, 0x1400, 0x0800, 0x0000, 0x0000, // %
0x1000, 0x2800, 0x2800, 0x1000, 0x3400, 0x4800, 0x4800, 0x3400, 0x0000, 0x0000, // &
0x1000, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // '
0x0800, 0x1000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x1000, 0x0800, // (
0x2000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x1000, 0x2000, // )
0x1000, 0x3800, 0x1000, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // *
0x0000, 0x0000, 0x1000, 0x1000, 0x7C00, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000, // +
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000, // ,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3800, 0x0000, 0x0000, 0x0000, 0x0000, // -
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, // .
0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x0000, 0x0000, // /
0x3800, 0x4400, 0x4400, 0x5400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 0
0x1000, 0x3000, 0x5000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // 1
0x3800, 0x4400, 0x4400, 0x0400, 0x0800, 0x1000, 0x2000, 0x7C00, 0x0000, 0x0000, // 2
0x3800, 0x4400, 0x0400, 0x1800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 3
0x0800, 0x1800, 0x2800, 0x2800, 0x4800, 0x7C00, 0x0800, 0x0800, 0x0000, 0x0000, // 4
0x7C00, 0x4000, 0x4000, 0x7800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 5
0x3800, 0x4400, 0x4000, 0x7800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 6
0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x2000, 0x2000, 0x0000, 0x0000, // 7
0x3800, 0x4400, 0x4400, 0x3800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 8
0x3800, 0x4400, 0x4400, 0x4400, 0x3C00, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 9
0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, // :
0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000, // ;
0x0000, 0x0000, 0x0C00, 0x3000, 0x4000, 0x3000, 0x0C00, 0x0000, 0x0000, 0x0000, // <
0x0000, 0x0000, 0x0000, 0x7C00, 0x0000, 0x7C00, 0x0000, 0x0000, 0x0000, 0x0000, // =
0x0000, 0x0000, 0x6000, 0x1800, 0x0400, 0x1800, 0x6000, 0x0000, 0x0000, 0x0000, // >
0x3800, 0x4400, 0x0400, 0x0800, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000, // ?
0x3800, 0x4400, 0x4C00, 0x5400, 0x5C00, 0x4000, 0x4000, 0x3800, 0x0000, 0x0000, // @
0x1000, 0x2800, 0x2800, 0x2800, 0x2800, 0x7C00, 0x4400, 0x4400, 0x0000, 0x0000, // A
0x7800, 0x4400, 0x4400, 0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x0000, 0x0000, // B
0x3800, 0x4400, 0x4000, 0x4000, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // C
0x7000, 0x4800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4800, 0x7000, 0x0000, 0x0000, // D
0x7C00, 0x4000, 0x4000, 0x7C00, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000, // E
0x7C00, 0x4000, 0x4000, 0x7800, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // F
0x3800, 0x4400, 0x4000, 0x4000, 0x5C00, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // G
0x4400, 0x4400, 0x4400, 0x7C00, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // H
0x3800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3800, 0x0000, 0x0000, // I
0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // J
0x4400, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000, // K
0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000, // L
0x4400, 0x6C00, 0x6C00, 0x5400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // M
0x4400, 0x6400, 0x6400, 0x5400, 0x5400, 0x4C00, 0x4C00, 0x4400, 0x0000, 0x0000, // N
0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // O
0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // P
0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x5400, 0x3800, 0x0400, 0x0000, // Q
0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000, // R
0x3800, 0x4400, 0x4000, 0x3000, 0x0800, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // S
0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // T
0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // U
0x4400, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x1000, 0x0000, 0x0000, // V
0x4400, 0x4400, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000, // W
0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000, // X
0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // Y
0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000, // Z
0x1800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1800, // [
0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0000, 0x0000, /* \ */
0x3000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3000, // ]
0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ^
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFE00, // _
0x2000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // `
0x0000, 0x0000, 0x3800, 0x4400, 0x3C00, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // a
0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x0000, 0x0000, // b
0x0000, 0x0000, 0x3800, 0x4400, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // c
0x0400, 0x0400, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // d
0x0000, 0x0000, 0x3800, 0x4400, 0x7C00, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // e
0x0C00, 0x1000, 0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // f
0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x7800, // g
0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // h
0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // i
0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0xE000, // j
0x4000, 0x4000, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4400, 0x0000, 0x0000, // k
0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // l
0x0000, 0x0000, 0x7800, 0x5400, 0x5400, 0x5400, 0x5400, 0x5400, 0x0000, 0x0000, // m
0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // n
0x0000, 0x0000, 0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // o
0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x4000, 0x4000, // p
0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x0400, // q
0x0000, 0x0000, 0x5800, 0x6400, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // r
0x0000, 0x0000, 0x3800, 0x4400, 0x3000, 0x0800, 0x4400, 0x3800, 0x0000, 0x0000, // s
0x2000, 0x2000, 0x7800, 0x2000, 0x2000, 0x2000, 0x2000, 0x1800, 0x0000, 0x0000, // t
0x0000, 0x0000, 0x4400, 0x4400, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // u
0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x0000, 0x0000, // v
0x0000, 0x0000, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000, // w
0x0000, 0x0000, 0x4400, 0x2800, 0x1000, 0x1000, 0x2800, 0x4400, 0x0000, 0x0000, // x
0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x6000, // y
0x0000, 0x0000, 0x7C00, 0x0800, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000, // z
0x1800, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1800, // {
0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, // |
0x3000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x3000, // }
0x0000, 0x0000, 0x0000, 0x7400, 0x4C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ~
}
var Font11x18 = [...]uint16{
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // sp
0x0000, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // !
0x0000, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // "
0x0000, 0x1980, 0x1980, 0x1980, 0x1980, 0x7FC0, 0x7FC0, 0x1980, 0x3300, 0x7FC0, 0x7FC0, 0x3300, 0x3300, 0x3300, 0x3300, 0x0000, 0x0000, 0x0000, // #
0x0000, 0x1E00, 0x3F00, 0x7580, 0x6580, 0x7400, 0x3C00, 0x1E00, 0x0700, 0x0580, 0x6580, 0x6580, 0x7580, 0x3F00, 0x1E00, 0x0400, 0x0400, 0x0000, // $
0x0000, 0x7000, 0xD800, 0xD840, 0xD8C0, 0xD980, 0x7300, 0x0600, 0x0C00, 0x1B80, 0x36C0, 0x66C0, 0x46C0, 0x06C0, 0x0380, 0x0000, 0x0000, 0x0000, // %
0x0000, 0x1E00, 0x3F00, 0x3300, 0x3300, 0x3300, 0x1E00, 0x0C00, 0x3CC0, 0x66C0, 0x6380, 0x6180, 0x6380, 0x3EC0, 0x1C80, 0x0000, 0x0000, 0x0000, // &
0x0000, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // '
0x0080, 0x0100, 0x0300, 0x0600, 0x0600, 0x0400, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0400, 0x0600, 0x0600, 0x0300, 0x0100, 0x0080, // (
0x2000, 0x1000, 0x1800, 0x0C00, 0x0C00, 0x0400, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0400, 0x0C00, 0x0C00, 0x1800, 0x1000, 0x2000, // )
0x0000, 0x0C00, 0x2D00, 0x3F00, 0x1E00, 0x3300, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // *
0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0xFFC0, 0xFFC0, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // +
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0400, 0x0400, 0x0800, // ,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x1E00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // -
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // .
0x0000, 0x0300, 0x0300, 0x0300, 0x0600, 0x0600, 0x0600, 0x0600, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x1800, 0x1800, 0x1800, 0x0000, 0x0000, 0x0000, // /
0x0000, 0x1E00, 0x3F00, 0x3300, 0x6180, 0x6180, 0x6180, 0x6D80, 0x6D80, 0x6180, 0x6180, 0x6180, 0x3300, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 0
0x0000, 0x0600, 0x0E00, 0x1E00, 0x3600, 0x2600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // 1
0x0000, 0x1E00, 0x3F00, 0x7380, 0x6180, 0x6180, 0x0180, 0x0300, 0x0600, 0x0C00, 0x1800, 0x3000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // 2
0x0000, 0x1C00, 0x3E00, 0x6300, 0x6300, 0x0300, 0x0E00, 0x0E00, 0x0300, 0x0180, 0x0180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 3
0x0000, 0x0600, 0x0E00, 0x0E00, 0x1E00, 0x1E00, 0x1600, 0x3600, 0x3600, 0x6600, 0x7F80, 0x7F80, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // 4
0x0000, 0x7F00, 0x7F00, 0x6000, 0x6000, 0x6000, 0x6E00, 0x7F00, 0x6380, 0x0180, 0x0180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 5
0x0000, 0x1E00, 0x3F00, 0x3380, 0x6180, 0x6000, 0x6E00, 0x7F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x3380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 6
0x0000, 0x7F80, 0x7F80, 0x0180, 0x0300, 0x0300, 0x0600, 0x0600, 0x0C00, 0x0C00, 0x0C00, 0x0800, 0x1800, 0x1800, 0x1800, 0x0000, 0x0000, 0x0000, // 7
0x0000, 0x1E00, 0x3F00, 0x6380, 0x6180, 0x6180, 0x2100, 0x1E00, 0x3F00, 0x6180, 0x6180, 0x6180, 0x6180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 8
0x0000, 0x1E00, 0x3F00, 0x7300, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0180, 0x6180, 0x7300, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 9
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // :
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0400, 0x0400, 0x0800, // ;
0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0380, 0x0E00, 0x3800, 0x6000, 0x3800, 0x0E00, 0x0380, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // <
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // =
0x0000, 0x0000, 0x0000, 0x0000, 0x4000, 0x7000, 0x1C00, 0x0700, 0x0180, 0x0700, 0x1C00, 0x7000, 0x4000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // >
0x0000, 0x1F00, 0x3F80, 0x71C0, 0x60C0, 0x00C0, 0x01C0, 0x0380, 0x0700, 0x0E00, 0x0C00, 0x0C00, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // ?
0x0000, 0x1E00, 0x3F00, 0x3180, 0x7180, 0x6380, 0x6F80, 0x6D80, 0x6D80, 0x6F80, 0x6780, 0x6000, 0x3200, 0x3E00, 0x1C00, 0x0000, 0x0000, 0x0000, // @
0x0000, 0x0E00, 0x0E00, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x3180, 0x3180, 0x3F80, 0x3F80, 0x3180, 0x60C0, 0x60C0, 0x60C0, 0x0000, 0x0000, 0x0000, // A
0x0000, 0x7C00, 0x7E00, 0x6300, 0x6300, 0x6300, 0x6300, 0x7E00, 0x7E00, 0x6300, 0x6180, 0x6180, 0x6380, 0x7F00, 0x7E00, 0x0000, 0x0000, 0x0000, // B
0x0000, 0x1E00, 0x3F00, 0x3180, 0x6180, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6180, 0x3180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // C
0x0000, 0x7C00, 0x7F00, 0x6300, 0x6380, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6300, 0x6300, 0x7E00, 0x7C00, 0x0000, 0x0000, 0x0000, // D
0x0000, 0x7F80, 0x7F80, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F00, 0x7F00, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // E
0x0000, 0x7F80, 0x7F80, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F00, 0x7F00, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x0000, 0x0000, 0x0000, // F
0x0000, 0x1E00, 0x3F00, 0x3180, 0x6180, 0x6000, 0x6000, 0x6000, 0x6380, 0x6380, 0x6180, 0x6180, 0x3180, 0x3F80, 0x1E00, 0x0000, 0x0000, 0x0000, // G
0x0000, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x7F80, 0x7F80, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // H
0x0000, 0x3F00, 0x3F00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x3F00, 0x3F00, 0x0000, 0x0000, 0x0000, // I
0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x6180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // J
0x0000, 0x60C0, 0x6180, 0x6300, 0x6600, 0x6600, 0x6C00, 0x7800, 0x7C00, 0x6600, 0x6600, 0x6300, 0x6180, 0x6180, 0x60C0, 0x0000, 0x0000, 0x0000, // K
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // L
0x0000, 0x71C0, 0x71C0, 0x7BC0, 0x7AC0, 0x6AC0, 0x6AC0, 0x6EC0, 0x64C0, 0x60C0, 0x60C0, 0x60C0, 0x60C0, 0x60C0, 0x60C0, 0x0000, 0x0000, 0x0000, // M
0x0000, 0x7180, 0x7180, 0x7980, 0x7980, 0x7980, 0x6D80, 0x6D80, 0x6D80, 0x6580, 0x6780, 0x6780, 0x6780, 0x6380, 0x6380, 0x0000, 0x0000, 0x0000, // N
0x0000, 0x1E00, 0x3F00, 0x3300, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x3300, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // O
0x0000, 0x7E00, 0x7F00, 0x6380, 0x6180, 0x6180, 0x6180, 0x6380, 0x7F00, 0x7E00, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x0000, 0x0000, 0x0000, // P
0x0000, 0x1E00, 0x3F00, 0x3300, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6580, 0x6780, 0x3300, 0x3F80, 0x1E40, 0x0000, 0x0000, 0x0000, // Q
0x0000, 0x7E00, 0x7F00, 0x6380, 0x6180, 0x6180, 0x6380, 0x7F00, 0x7E00, 0x6600, 0x6300, 0x6300, 0x6180, 0x6180, 0x60C0, 0x0000, 0x0000, 0x0000, // R
0x0000, 0x0E00, 0x1F00, 0x3180, 0x3180, 0x3000, 0x3800, 0x1E00, 0x0700, 0x0380, 0x6180, 0x6180, 0x3180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // S
0x0000, 0xFFC0, 0xFFC0, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // T
0x0000, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // U
0x0000, 0x60C0, 0x60C0, 0x60C0, 0x3180, 0x3180, 0x3180, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x0E00, 0x0E00, 0x0E00, 0x0400, 0x0000, 0x0000, 0x0000, // V
0x0000, 0xC0C0, 0xC0C0, 0xC0C0, 0xC0C0, 0xC0C0, 0xCCC0, 0x4C80, 0x4C80, 0x5E80, 0x5280, 0x5280, 0x7380, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // W
0x0000, 0xC0C0, 0x6080, 0x6180, 0x3300, 0x3B00, 0x1E00, 0x0C00, 0x0C00, 0x1E00, 0x1F00, 0x3B00, 0x7180, 0x6180, 0xC0C0, 0x0000, 0x0000, 0x0000, // X
0x0000, 0xC0C0, 0x6180, 0x6180, 0x3300, 0x3300, 0x1E00, 0x1E00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // Y
0x0000, 0x3F80, 0x3F80, 0x0180, 0x0300, 0x0300, 0x0600, 0x0C00, 0x0C00, 0x1800, 0x1800, 0x3000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // Z
0x0F00, 0x0F00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0F00, 0x0F00, // [
0x0000, 0x1800, 0x1800, 0x1800, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0300, 0x0300, 0x0300, 0x0000, 0x0000, 0x0000, /* \ */
0x1E00, 0x1E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x1E00, 0x1E00, // ]
0x0000, 0x0C00, 0x0C00, 0x1E00, 0x1200, 0x3300, 0x3300, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ^
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFE0, 0x0000, // _
0x0000, 0x3800, 0x1800, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // `
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1F00, 0x3F80, 0x6180, 0x0180, 0x1F80, 0x3F80, 0x6180, 0x6380, 0x7F80, 0x38C0, 0x0000, 0x0000, 0x0000, // a
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6E00, 0x7F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x7F00, 0x6E00, 0x0000, 0x0000, 0x0000, // b
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F00, 0x7380, 0x6180, 0x6000, 0x6000, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // c
0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x1D80, 0x3F80, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0000, 0x0000, 0x0000, // d
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F00, 0x7300, 0x6180, 0x7F80, 0x7F80, 0x6000, 0x7180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // e
0x0000, 0x07C0, 0x0FC0, 0x0C00, 0x0C00, 0x7F80, 0x7F80, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // f
0x0000, 0x0000, 0x0000, 0x0000, 0x1D80, 0x3F80, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0180, 0x6380, 0x7F00, 0x3E00, // g
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6F00, 0x7F80, 0x7180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // h
0x0000, 0x0600, 0x0600, 0x0000, 0x0000, 0x3E00, 0x3E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // i
0x0600, 0x0600, 0x0000, 0x0000, 0x3E00, 0x3E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x4600, 0x7E00, 0x3C00, // j
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6180, 0x6300, 0x6600, 0x6C00, 0x7C00, 0x7600, 0x6300, 0x6300, 0x6180, 0x60C0, 0x0000, 0x0000, 0x0000, // k
0x0000, 0x3E00, 0x3E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // l
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xDD80, 0xFFC0, 0xCEC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0x0000, 0x0000, 0x0000, // m
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6F00, 0x7F80, 0x7180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // n
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // o
0x0000, 0x0000, 0x0000, 0x0000, 0x6E00, 0x7F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x7F00, 0x6E00, 0x6000, 0x6000, 0x6000, 0x6000, // p
0x0000, 0x0000, 0x0000, 0x0000, 0x1D80, 0x3F80, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0180, 0x0180, 0x0180, 0x0180, // q
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6700, 0x3F80, 0x3900, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x0000, 0x0000, 0x0000, // r
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F80, 0x6180, 0x6000, 0x7F00, 0x3F80, 0x0180, 0x6180, 0x7F00, 0x1E00, 0x0000, 0x0000, 0x0000, // s
0x0000, 0x0000, 0x0800, 0x1800, 0x1800, 0x7F00, 0x7F00, 0x1800, 0x1800, 0x1800, 0x1800, 0x1800, 0x1800, 0x1F80, 0x0F80, 0x0000, 0x0000, 0x0000, // t
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6380, 0x7F80, 0x3D80, 0x0000, 0x0000, 0x0000, // u
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x60C0, 0x3180, 0x3180, 0x3180, 0x1B00, 0x1B00, 0x1B00, 0x0E00, 0x0E00, 0x0600, 0x0000, 0x0000, 0x0000, // v
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xDD80, 0xDD80, 0xDD80, 0x5500, 0x5500, 0x5500, 0x7700, 0x7700, 0x2200, 0x2200, 0x0000, 0x0000, 0x0000, // w
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6180, 0x3300, 0x3300, 0x1E00, 0x0C00, 0x0C00, 0x1E00, 0x3300, 0x3300, 0x6180, 0x0000, 0x0000, 0x0000, // x
0x0000, 0x0000, 0x0000, 0x0000, 0x6180, 0x6180, 0x3180, 0x3300, 0x3300, 0x1B00, 0x1B00, 0x1B00, 0x0E00, 0x0E00, 0x0E00, 0x1C00, 0x7C00, 0x7000, // y
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FC0, 0x7FC0, 0x0180, 0x0300, 0x0600, 0x0C00, 0x1800, 0x3000, 0x7FC0, 0x7FC0, 0x0000, 0x0000, 0x0000, // z
0x0380, 0x0780, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0E00, 0x1C00, 0x1C00, 0x0E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0780, 0x0380, // {
0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, // |
0x3800, 0x3C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0E00, 0x0700, 0x0700, 0x0E00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x3C00, 0x3800, // }
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3880, 0x7F80, 0x4700, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ~
}
var Font16x26 = [...]uint16{
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [ ]
0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03C0, 0x03C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [!]
0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = ["]
0x01CE, 0x03CE, 0x03DE, 0x039E, 0x039C, 0x079C, 0x3FFF, 0x7FFF, 0x0738, 0x0F38, 0x0F78, 0x0F78, 0x0E78, 0xFFFF, 0xFFFF, 0x1EF0, 0x1CF0, 0x1CE0, 0x3CE0, 0x3DE0, 0x39E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [#]
0x03FC, 0x0FFE, 0x1FEE, 0x1EE0, 0x1EE0, 0x1EE0, 0x1EE0, 0x1FE0, 0x0FE0, 0x07E0, 0x03F0, 0x01FC, 0x01FE, 0x01FE, 0x01FE, 0x01FE, 0x01FE, 0x01FE, 0x3DFE, 0x3FFC, 0x0FF0, 0x01E0, 0x01E0, 0x0000, 0x0000, 0x0000, // Ascii = [$]
0x3E03, 0xF707, 0xE78F, 0xE78E, 0xE39E, 0xE3BC, 0xE7B8, 0xE7F8, 0xF7F0, 0x3FE0, 0x01C0, 0x03FF, 0x07FF, 0x07F3, 0x0FF3, 0x1EF3, 0x3CF3, 0x38F3, 0x78F3, 0xF07F, 0xE03F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [%]
0x07E0, 0x0FF8, 0x0F78, 0x1F78, 0x1F78, 0x1F78, 0x0F78, 0x0FF0, 0x0FE0, 0x1F80, 0x7FC3, 0xFBC3, 0xF3E7, 0xF1F7, 0xF0F7, 0xF0FF, 0xF07F, 0xF83E, 0x7C7F, 0x3FFF, 0x1FEF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [&]
0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [']
0x003F, 0x007C, 0x01F0, 0x01E0, 0x03C0, 0x07C0, 0x0780, 0x0780, 0x0F80, 0x0F00, 0x0F00, 0x0F00, 0x0F00, 0x0F00, 0x0F00, 0x0F80, 0x0780, 0x0780, 0x07C0, 0x03C0, 0x01E0, 0x01F0, 0x007C, 0x003F, 0x000F, 0x0000, // Ascii = [(]
0x7E00, 0x1F00, 0x07C0, 0x03C0, 0x01E0, 0x01F0, 0x00F0, 0x00F0, 0x00F8, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x00F8, 0x00F0, 0x00F0, 0x01F0, 0x01E0, 0x03C0, 0x07C0, 0x1F00, 0x7E00, 0x7800, 0x0000, // Ascii = [)]
0x03E0, 0x03C0, 0x01C0, 0x39CE, 0x3FFF, 0x3F7F, 0x0320, 0x0370, 0x07F8, 0x0F78, 0x1F3C, 0x0638, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [*]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0xFFFF, 0xFFFF, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [+]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x01E0, 0x01E0, 0x01E0, 0x01C0, 0x0380, // Ascii = [,]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3FFE, 0x3FFE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [-]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [.]
0x000F, 0x000F, 0x001E, 0x001E, 0x003C, 0x003C, 0x0078, 0x0078, 0x00F0, 0x00F0, 0x01E0, 0x01E0, 0x03C0, 0x03C0, 0x0780, 0x0780, 0x0F00, 0x0F00, 0x1E00, 0x1E00, 0x3C00, 0x3C00, 0x7800, 0x7800, 0xF000, 0x0000, // Ascii = [/]
0x07F0, 0x0FF8, 0x1F7C, 0x3E3E, 0x3C1E, 0x7C1F, 0x7C1F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x7C1F, 0x7C1F, 0x3C1E, 0x3E3E, 0x1F7C, 0x0FF8, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [0]
0x00F0, 0x07F0, 0x3FF0, 0x3FF0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [1]
0x0FE0, 0x3FF8, 0x3C7C, 0x003C, 0x003E, 0x003E, 0x003E, 0x003C, 0x003C, 0x007C, 0x00F8, 0x01F0, 0x03E0, 0x07C0, 0x0780, 0x0F00, 0x1E00, 0x3E00, 0x3C00, 0x3FFE, 0x3FFE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [2]
0x0FF0, 0x1FF8, 0x1C7C, 0x003E, 0x003E, 0x003E, 0x003C, 0x003C, 0x00F8, 0x0FF0, 0x0FF8, 0x007C, 0x003E, 0x001E, 0x001E, 0x001E, 0x001E, 0x003E, 0x1C7C, 0x1FF8, 0x1FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [3]
0x0078, 0x00F8, 0x00F8, 0x01F8, 0x03F8, 0x07F8, 0x07F8, 0x0F78, 0x1E78, 0x1E78, 0x3C78, 0x7878, 0x7878, 0xFFFF, 0xFFFF, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [4]
0x1FFC, 0x1FFC, 0x1FFC, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1FE0, 0x1FF8, 0x00FC, 0x007C, 0x003E, 0x003E, 0x001E, 0x003E, 0x003E, 0x003C, 0x1C7C, 0x1FF8, 0x1FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [5]
0x01FC, 0x07FE, 0x0F8E, 0x1F00, 0x1E00, 0x3E00, 0x3C00, 0x3C00, 0x3DF8, 0x3FFC, 0x7F3E, 0x7E1F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3E0F, 0x1E1F, 0x1F3E, 0x0FFC, 0x03F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [6]
0x3FFF, 0x3FFF, 0x3FFF, 0x000F, 0x001E, 0x001E, 0x003C, 0x0038, 0x0078, 0x00F0, 0x00F0, 0x01E0, 0x01E0, 0x03C0, 0x03C0, 0x0780, 0x0F80, 0x0F80, 0x0F00, 0x1F00, 0x1F00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [7]
0x07F8, 0x0FFC, 0x1F3E, 0x1E1E, 0x3E1E, 0x3E1E, 0x1E1E, 0x1F3C, 0x0FF8, 0x07F0, 0x0FF8, 0x1EFC, 0x3E3E, 0x3C1F, 0x7C1F, 0x7C0F, 0x7C0F, 0x3C1F, 0x3F3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [8]
0x07F0, 0x0FF8, 0x1E7C, 0x3C3E, 0x3C1E, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x3C1F, 0x3E3F, 0x1FFF, 0x07EF, 0x001F, 0x001E, 0x001E, 0x003E, 0x003C, 0x38F8, 0x3FF0, 0x1FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [9]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [:]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x01E0, 0x01E0, 0x01E0, 0x03C0, 0x0380, // Ascii = [;]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x000F, 0x003F, 0x00FC, 0x03F0, 0x0FC0, 0x3F00, 0xFE00, 0x3F00, 0x0FC0, 0x03F0, 0x00FC, 0x003F, 0x000F, 0x0003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [<]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [=]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xE000, 0xF800, 0x7E00, 0x1F80, 0x07E0, 0x01F8, 0x007E, 0x001F, 0x007E, 0x01F8, 0x07E0, 0x1F80, 0x7E00, 0xF800, 0xE000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [>]
0x1FF0, 0x3FFC, 0x383E, 0x381F, 0x381F, 0x001E, 0x001E, 0x003C, 0x0078, 0x00F0, 0x01E0, 0x03C0, 0x03C0, 0x07C0, 0x07C0, 0x0000, 0x0000, 0x0000, 0x07C0, 0x07C0, 0x07C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [?]
0x03F8, 0x0FFE, 0x1F1E, 0x3E0F, 0x3C7F, 0x78FF, 0x79EF, 0x73C7, 0xF3C7, 0xF38F, 0xF38F, 0xF38F, 0xF39F, 0xF39F, 0x73FF, 0x7BFF, 0x79F7, 0x3C00, 0x1F1C, 0x0FFC, 0x03F8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [@]
0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x07F0, 0x07F0, 0x07F0, 0x0F78, 0x0F78, 0x0E7C, 0x1E3C, 0x1E3C, 0x3C3E, 0x3FFE, 0x3FFF, 0x781F, 0x780F, 0xF00F, 0xF007, 0xF007, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [A]
0x0000, 0x0000, 0x0000, 0x3FF8, 0x3FFC, 0x3C3E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C3E, 0x3C7C, 0x3FF0, 0x3FF8, 0x3C7E, 0x3C1F, 0x3C1F, 0x3C0F, 0x3C0F, 0x3C1F, 0x3FFE, 0x3FF8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [B]
0x0000, 0x0000, 0x0000, 0x01FF, 0x07FF, 0x1F87, 0x3E00, 0x3C00, 0x7C00, 0x7800, 0x7800, 0x7800, 0x7800, 0x7800, 0x7C00, 0x7C00, 0x3E00, 0x3F00, 0x1F83, 0x07FF, 0x01FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [C]
0x0000, 0x0000, 0x0000, 0x7FF0, 0x7FFC, 0x787E, 0x781F, 0x781F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x781F, 0x781E, 0x787E, 0x7FF8, 0x7FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [D]
0x0000, 0x0000, 0x0000, 0x3FFF, 0x3FFF, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3FFE, 0x3FFE, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [E]
0x0000, 0x0000, 0x0000, 0x1FFF, 0x1FFF, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1FFF, 0x1FFF, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [F]
0x0000, 0x0000, 0x0000, 0x03FE, 0x0FFF, 0x1F87, 0x3E00, 0x7C00, 0x7C00, 0x7800, 0xF800, 0xF800, 0xF87F, 0xF87F, 0x780F, 0x7C0F, 0x7C0F, 0x3E0F, 0x1F8F, 0x0FFF, 0x03FE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [G]
0x0000, 0x0000, 0x0000, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7FFF, 0x7FFF, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [H]
0x0000, 0x0000, 0x0000, 0x3FFF, 0x3FFF, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [I]
0x0000, 0x0000, 0x0000, 0x1FFC, 0x1FFC, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x0078, 0x0078, 0x38F8, 0x3FF0, 0x3FC0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [J]
0x0000, 0x0000, 0x0000, 0x3C1F, 0x3C1E, 0x3C3C, 0x3C78, 0x3CF0, 0x3DE0, 0x3FE0, 0x3FC0, 0x3F80, 0x3FC0, 0x3FE0, 0x3DF0, 0x3CF0, 0x3C78, 0x3C7C, 0x3C3E, 0x3C1F, 0x3C0F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [K]
0x0000, 0x0000, 0x0000, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [L]
0x0000, 0x0000, 0x0000, 0xF81F, 0xFC1F, 0xFC1F, 0xFE3F, 0xFE3F, 0xFE3F, 0xFF7F, 0xFF77, 0xFF77, 0xF7F7, 0xF7E7, 0xF3E7, 0xF3E7, 0xF3C7, 0xF007, 0xF007, 0xF007, 0xF007, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [M]
0x0000, 0x0000, 0x0000, 0x7C0F, 0x7C0F, 0x7E0F, 0x7F0F, 0x7F0F, 0x7F8F, 0x7F8F, 0x7FCF, 0x7BEF, 0x79EF, 0x79FF, 0x78FF, 0x78FF, 0x787F, 0x783F, 0x783F, 0x781F, 0x781F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [N]
0x0000, 0x0000, 0x0000, 0x07F0, 0x1FFC, 0x3E3E, 0x7C1F, 0x780F, 0x780F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0x780F, 0x780F, 0x7C1F, 0x3E3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [O]
0x0000, 0x0000, 0x0000, 0x3FFC, 0x3FFF, 0x3E1F, 0x3E0F, 0x3E0F, 0x3E0F, 0x3E0F, 0x3E1F, 0x3E3F, 0x3FFC, 0x3FF0, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [P]
0x0000, 0x0000, 0x0000, 0x07F0, 0x1FFC, 0x3E3E, 0x7C1F, 0x780F, 0x780F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0x780F, 0x780F, 0x7C1F, 0x3E3E, 0x1FFC, 0x07F8, 0x007C, 0x003F, 0x000F, 0x0003, 0x0000, // Ascii = [Q]
0x0000, 0x0000, 0x0000, 0x3FF0, 0x3FFC, 0x3C7E, 0x3C3E, 0x3C1E, 0x3C1E, 0x3C3E, 0x3C3C, 0x3CFC, 0x3FF0, 0x3FE0, 0x3DF0, 0x3CF8, 0x3C7C, 0x3C3E, 0x3C1E, 0x3C1F, 0x3C0F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [R]
0x0000, 0x0000, 0x0000, 0x07FC, 0x1FFE, 0x3E0E, 0x3C00, 0x3C00, 0x3C00, 0x3E00, 0x1FC0, 0x0FF8, 0x03FE, 0x007F, 0x001F, 0x000F, 0x000F, 0x201F, 0x3C3E, 0x3FFC, 0x1FF0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [S]
0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [T]
0x0000, 0x0000, 0x0000, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x3C1E, 0x3C1E, 0x3E3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [U]
0x0000, 0x0000, 0x0000, 0xF007, 0xF007, 0xF807, 0x780F, 0x7C0F, 0x3C1E, 0x3C1E, 0x3E1E, 0x1E3C, 0x1F3C, 0x1F78, 0x0F78, 0x0FF8, 0x07F0, 0x07F0, 0x07F0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [V]
0x0000, 0x0000, 0x0000, 0xE003, 0xF003, 0xF003, 0xF007, 0xF3E7, 0xF3E7, 0xF3E7, 0x73E7, 0x7BF7, 0x7FF7, 0x7FFF, 0x7F7F, 0x7F7F, 0x7F7E, 0x3F7E, 0x3E3E, 0x3E3E, 0x3E3E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [W]
0x0000, 0x0000, 0x0000, 0xF807, 0x7C0F, 0x3E1E, 0x3E3E, 0x1F3C, 0x0FF8, 0x07F0, 0x07E0, 0x03E0, 0x03E0, 0x07F0, 0x0FF8, 0x0F7C, 0x1E7C, 0x3C3E, 0x781F, 0x780F, 0xF00F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [X]
0x0000, 0x0000, 0x0000, 0xF807, 0x7807, 0x7C0F, 0x3C1E, 0x3E1E, 0x1F3C, 0x0F78, 0x0FF8, 0x07F0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [Y]
0x0000, 0x0000, 0x0000, 0x7FFF, 0x7FFF, 0x000F, 0x001F, 0x003E, 0x007C, 0x00F8, 0x00F0, 0x01E0, 0x03E0, 0x07C0, 0x0F80, 0x0F00, 0x1E00, 0x3E00, 0x7C00, 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [Z]
0x07FF, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x07FF, 0x07FF, 0x0000, // Ascii = [[]
0x7800, 0x7800, 0x3C00, 0x3C00, 0x1E00, 0x1E00, 0x0F00, 0x0F00, 0x0780, 0x0780, 0x03C0, 0x03C0, 0x01E0, 0x01E0, 0x00F0, 0x00F0, 0x0078, 0x0078, 0x003C, 0x003C, 0x001E, 0x001E, 0x000F, 0x000F, 0x0007, 0x0000, // Ascii = [\]
0x7FF0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x7FF0, 0x7FF0, 0x0000, // Ascii = []]
0x00C0, 0x01C0, 0x01C0, 0x03E0, 0x03E0, 0x07F0, 0x07F0, 0x0778, 0x0F78, 0x0F38, 0x1E3C, 0x1E3C, 0x3C1E, 0x3C1E, 0x380F, 0x780F, 0x7807, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [^]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, // Ascii = [_]
0x00F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [`]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0FF8, 0x3FFC, 0x3C7C, 0x003E, 0x003E, 0x003E, 0x07FE, 0x1FFE, 0x3E3E, 0x7C3E, 0x783E, 0x7C3E, 0x7C7E, 0x3FFF, 0x1FCF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [a]
0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3DF8, 0x3FFE, 0x3F3E, 0x3E1F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C1F, 0x3C1E, 0x3F3E, 0x3FFC, 0x3BF0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [b]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03FE, 0x0FFF, 0x1F87, 0x3E00, 0x3E00, 0x3C00, 0x7C00, 0x7C00, 0x7C00, 0x3C00, 0x3E00, 0x3E00, 0x1F87, 0x0FFF, 0x03FE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [c]
0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x07FF, 0x1FFF, 0x3E3F, 0x3C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x781F, 0x781F, 0x7C1F, 0x7C1F, 0x3C3F, 0x3E7F, 0x1FFF, 0x0FDF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [d]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03F8, 0x0FFC, 0x1F3E, 0x3E1E, 0x3C1F, 0x7C1F, 0x7FFF, 0x7FFF, 0x7C00, 0x7C00, 0x3C00, 0x3E00, 0x1F07, 0x0FFF, 0x03FE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [e]
0x01FF, 0x03E1, 0x03C0, 0x07C0, 0x07C0, 0x07C0, 0x7FFF, 0x7FFF, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [f]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07EF, 0x1FFF, 0x3E7F, 0x3C1F, 0x7C1F, 0x7C1F, 0x781F, 0x781F, 0x781F, 0x7C1F, 0x7C1F, 0x3C3F, 0x3E7F, 0x1FFF, 0x0FDF, 0x001E, 0x001E, 0x001E, 0x387C, 0x3FF8, // Ascii = [g]
0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3DFC, 0x3FFE, 0x3F9E, 0x3F1F, 0x3E1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [h]
0x01F0, 0x01F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FE0, 0x7FE0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [i]
0x00F8, 0x00F8, 0x0000, 0x0000, 0x0000, 0x0000, 0x3FF8, 0x3FF8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F0, 0x71F0, 0x7FE0, // Ascii = [j]
0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C1F, 0x3C3E, 0x3C7C, 0x3CF8, 0x3DF0, 0x3DE0, 0x3FC0, 0x3FC0, 0x3FE0, 0x3DF0, 0x3CF8, 0x3C7C, 0x3C3E, 0x3C1F, 0x3C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [k]
0x7FF0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [l]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF79E, 0xFFFF, 0xFFFF, 0xFFFF, 0xFBE7, 0xF9E7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [m]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3DFC, 0x3FFE, 0x3F9E, 0x3F1F, 0x3E1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [n]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07F0, 0x1FFC, 0x3E3E, 0x3C1F, 0x7C1F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x7C1F, 0x3C1F, 0x3E3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [o]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3DF8, 0x3FFE, 0x3F3E, 0x3E1F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C1F, 0x3E1E, 0x3F3E, 0x3FFC, 0x3FF8, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, // Ascii = [p]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07EE, 0x1FFE, 0x3E7E, 0x3C1E, 0x7C1E, 0x781E, 0x781E, 0x781E, 0x781E, 0x781E, 0x7C1E, 0x7C3E, 0x3E7E, 0x1FFE, 0x0FDE, 0x001E, 0x001E, 0x001E, 0x001E, 0x001E, // Ascii = [q]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1F7F, 0x1FFF, 0x1FE7, 0x1FC7, 0x1F87, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [r]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07FC, 0x1FFE, 0x1E0E, 0x3E00, 0x3E00, 0x3F00, 0x1FE0, 0x07FC, 0x00FE, 0x003E, 0x001E, 0x001E, 0x3C3E, 0x3FFC, 0x1FF0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [s]
0x0000, 0x0000, 0x0000, 0x0780, 0x0780, 0x0780, 0x7FFF, 0x7FFF, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x07C0, 0x03FF, 0x01FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [t]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C3E, 0x3C7E, 0x3EFE, 0x1FFE, 0x0FDE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [u]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF007, 0x780F, 0x780F, 0x3C1E, 0x3C1E, 0x3E1E, 0x1E3C, 0x1E3C, 0x0F78, 0x0F78, 0x0FF0, 0x07F0, 0x07F0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [v]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF003, 0xF1E3, 0xF3E3, 0xF3E7, 0xF3F7, 0xF3F7, 0x7FF7, 0x7F77, 0x7F7F, 0x7F7F, 0x7F7F, 0x3E3E, 0x3E3E, 0x3E3E, 0x3E3E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [w]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7C0F, 0x3E1E, 0x3E3C, 0x1F3C, 0x0FF8, 0x07F0, 0x07F0, 0x03E0, 0x07F0, 0x07F8, 0x0FF8, 0x1E7C, 0x3E3E, 0x3C1F, 0x781F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [x]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF807, 0x780F, 0x7C0F, 0x3C1E, 0x3C1E, 0x1E3C, 0x1E3C, 0x1F3C, 0x0F78, 0x0FF8, 0x07F0, 0x07F0, 0x03E0, 0x03E0, 0x03C0, 0x03C0, 0x03C0, 0x0780, 0x0F80, 0x7F00, // Ascii = [y]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3FFF, 0x3FFF, 0x001F, 0x003E, 0x007C, 0x00F8, 0x01F0, 0x03E0, 0x07C0, 0x0F80, 0x1F00, 0x1E00, 0x3C00, 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [z]
0x01FE, 0x03E0, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x01E0, 0x01E0, 0x01E0, 0x01C0, 0x03C0, 0x3F80, 0x3F80, 0x03C0, 0x01C0, 0x01E0, 0x01E0, 0x01E0, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x03E0, 0x01FE, 0x007E, 0x0000, // Ascii = [{]
0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x0000, // Ascii = [|]
0x3FC0, 0x03E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01C0, 0x03C0, 0x03C0, 0x01C0, 0x01E0, 0x00FE, 0x00FE, 0x01E0, 0x01C0, 0x03C0, 0x03C0, 0x01C0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x03E0, 0x3FC0, 0x3F00, 0x0000, // Ascii = [}]
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3F07, 0x7FC7, 0x73E7, 0xF1FF, 0xF07E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [~]
}
+12 -4
View File
@@ -2,10 +2,18 @@ package display
import (
"image/color"
"go.maze.io/harmon/hardware"
"image/draw"
)
func DrawSprite(display hardware.Display, x, y int, sprite []byte, c color.Color) error {
return nil
func DrawSprite(p draw.Image, x, y int, sprite []uint8, c color.Color) {
w, h, data := sprite[0], sprite[1], sprite[2:]
for dy := 0; dy < int(h); dy++ {
for dx := 0; dx < int(w); dx++ {
byteOffset := int(dy/8)*int(w) + dx
bitOffset := dy % 8
if data[byteOffset]&(1<<bitOffset) != 0 {
p.Set(x+dx, y+dy, c)
}
}
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ type VCCMode uint8
// Registers
const (
setcontrast = 0x81
setContrast = 0x81
displayAllOnResume = 0xA4
displayAllOn = 0xA5
normalDisplay = 0xA6
+163 -207
View File
@@ -2,14 +2,13 @@
package ssd1306
import (
"bytes"
"fmt"
"image"
"image/color"
"image/draw"
"time"
"periph.io/x/conn/v3/gpio"
"github.com/sirupsen/logrus"
"go.maze.io/harmon/config"
"go.maze.io/harmon/hardware"
"go.maze.io/harmon/hardware/display"
@@ -25,17 +24,21 @@ func init() {
display.Register("ssd1306", newDriver)
}
type ResetValue [2]byte
type Display struct {
conn display.Conn
rect image.Rectangle
rotate display.Rotation
bl gpio.PinOut
buffer []byte
next *pixel.VerticalLSB
startPage, endPage int
startCol, endCol int
scrolled bool
halted bool
conn display.Conn
buffer []byte
width int16
height int16
bufferSize int16
vccState VCCMode
canReset bool
resetCol ResetValue
resetPage ResetValue
rotation display.Rotation
scrolled bool
halted bool
}
func (Display) Type() string { return "ssd1306" }
@@ -57,11 +60,21 @@ func newDriver(config config.DisplayConfig) (hardware.Display, error) {
opts.Mirror = true
}
log := logrus.WithFields(logrus.Fields{
"type": "ssd1306",
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
"mode": config.Mode,
"rotate": opts.Rotate,
})
log.Debug("new driver")
var isSPI bool
switch config.Mode {
case "", "i2c":
conn, err = display.OpenI2C(config.Bus, config.Address)
case "spi":
conn, err = display.OpenSPI(config.Port, config.Reset, config.DC)
isSPI = true
default:
return nil, display.InvalidMode(config.Mode)
}
@@ -70,10 +83,10 @@ func newDriver(config config.DisplayConfig) (hardware.Display, error) {
return nil, err
}
return newDisplay(conn, opts)
return newDisplay(conn, opts, isSPI)
}
func newDisplay(conn display.Conn, opts *display.Options) (*Display, error) {
func newDisplay(conn display.Conn, opts *display.Options, isSPI bool) (d *Display, err error) {
if opts.W < 8 || opts.W > 128 || opts.W&7 != 0 {
return nil, fmt.Errorf("invalid width %d", opts.W)
}
@@ -81,27 +94,48 @@ func newDisplay(conn display.Conn, opts *display.Options) (*Display, error) {
return nil, fmt.Errorf("invalid height %d", opts.H)
}
nbPages := opts.H / 8
pageSize := opts.W
d := &Display{
conn: conn,
bl: opts.Backlight,
rect: image.Rect(0, 0, opts.W, opts.H),
rotate: opts.Rotate,
buffer: make([]byte, nbPages*pageSize),
startPage: 0,
endPage: nbPages,
startCol: 0,
endCol: opts.W,
scrolled: true, // Signal that the screen must be redrawn on first draw().
d = &Display{
conn: conn,
width: int16(opts.W),
height: int16(opts.H),
}
if err := d.sendCommand(getInitCmd(opts)); err != nil {
return nil, err
//var zeroReset ResetValue
d.vccState = SwitchCapVCC
d.resetCol = ResetValue{0, uint8(d.width - 1)}
d.resetPage = ResetValue{0, uint8(d.height/8) - 1}
d.bufferSize = d.width * d.height / 8
d.buffer = make([]byte, d.bufferSize)
d.canReset = !isSPI || d.width != 128 || d.height != 64 // I2C or not 128x64
logrus.Infof("%d bytes buffer for %d pixels", d.bufferSize, d.width*d.height)
time.Sleep(100 * time.Nanosecond)
muxr := byte(d.height - 1)
if err = d.sendCommand([]byte{
0xAE, // display off
0xA8, muxr, // multiplex ratio (height - 1)
0xD3, 0x00, // display offset 0
0x40, // display start line 0
0xA1, // segment remap a0/a1
0xC8, // scan dir reverse (C0 normal)
0xD5, 0x80, // clock divide ration (0x00=1) and osc. frequency (0x8)
0xDA, 0x12, // com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5)
0x81, 0xFF, // contrast
0xA4, // output RAM to display
0xDB, 0x40, // vcom deselect level
0x20, 0x02, // set memory addressing mode
0x00, 0x10, // set lower column start address for page addressing mode: no offset
0x8D, 0x14, // [2] charge pump setting (p62): 0x014 enable, 0x010 disable
0xD9, 0x22, // set pre-charge
0x2E, // scroll off
0xA6, // none inverted normal display mode
0xAF, // display on
}); err != nil {
return
}
return d, nil
return
}
func (d *Display) sendData(data []byte) error {
@@ -123,99 +157,14 @@ func (d *Display) sendCommand(data []byte) error {
return d.conn.Tx(data, true)
}
func (d *Display) calculateSubset(next []byte) (int, int, int, int, bool) {
w := d.rect.Dx()
h := d.rect.Dy()
startPage := 0
endPage := h / 8
startCol := 0
endCol := w
if d.scrolled {
// Painting disable scrolling but if scrolling was enabled, this requires a
// full screen redraw.
d.scrolled = false
func (d *Display) PowerSave(on bool) error {
var cmd byte
if on {
cmd = 0xAF
} else {
// Calculate the smallest square that need to be sent.
pageSize := w
// Top.
for ; startPage < endPage; startPage++ {
x := pageSize * startPage
y := pageSize * (startPage + 1)
if !bytes.Equal(d.buffer[x:y], next[x:y]) {
break
}
}
// Bottom.
for ; endPage > startPage; endPage-- {
x := pageSize * (endPage - 1)
y := pageSize * endPage
if !bytes.Equal(d.buffer[x:y], next[x:y]) {
break
}
}
if startPage == endPage {
// Early exit, the image is exactly the same.
return 0, 0, 0, 0, true
}
// Left.
for ; startCol < endCol; startCol++ {
for i := startPage; i < endPage; i++ {
x := i*pageSize + startCol
if d.buffer[x] != next[x] {
goto breakLeft
}
}
}
breakLeft:
// Right.
for ; endCol > startCol; endCol-- {
for i := startPage; i < endPage; i++ {
x := i*pageSize + endCol - 1
if d.buffer[x] != next[x] {
goto breakRight
}
}
}
breakRight:
cmd = 0xAE
}
return startPage, endPage, startCol, endCol, false
}
// drawInternal sends image data to the controller.
func (d *Display) drawInternal(next []byte) error {
startPage, endPage, startCol, endCol, skip := d.calculateSubset(next)
if skip {
return nil
}
copy(d.buffer, next)
if d.startPage != startPage || d.endPage != endPage || d.startCol != startCol || d.endCol != endCol {
d.startPage = startPage
d.endPage = endPage
d.startCol = startCol
d.endCol = endCol
}
pageSize := d.rect.Dx()
for page := d.startPage; page < d.endPage; page++ {
err := d.sendCommand([]byte{
pageAddr | byte(page),
setLowColumn | (byte(d.startCol) & 0x0F),
setHighColumn | (byte(d.startCol) >> 4),
})
if err != nil {
return err
}
pageStart := page * pageSize
err = d.sendData(d.buffer[pageStart+d.startCol : pageStart+d.endCol])
if err != nil {
return err
}
}
return nil
return d.sendCommand([]byte{cmd})
}
// Halt turns off the display.
@@ -223,7 +172,7 @@ func (d *Display) drawInternal(next []byte) error {
// Sending any other command afterward reenables the display.
func (d *Display) Halt() error {
d.halted = false
err := d.sendCommand([]byte{0xAE})
err := d.PowerSave(true)
if err == nil {
d.halted = true
}
@@ -232,10 +181,7 @@ func (d *Display) Halt() error {
// Size of the display.
func (d *Display) Size() image.Point {
if d.rotate == display.Rotate90 || d.rotate == display.Rotate270 {
return image.Pt(d.rect.Max.Y, d.rect.Max.X)
}
return d.rect.Max
return image.Pt(int(d.width), int(d.height))
}
// Draw implements display.Drawer.
@@ -244,74 +190,9 @@ func (d *Display) Size() image.Point {
// It means that on slow bus (I²C), it may be preferable to defer Draw() calls
// to a background goroutine.
func (d *Display) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
var next []byte
if img, ok := src.(*pixel.VerticalLSB); ok && r.Eq(d.rect) && img.Rect.Eq(d.rect) && sp.X == 0 && sp.Y == 0 {
// Exact size, full frame, image1bit encoding: fast path!
next = img.Pix
} else {
// Double buffering.
if d.next == nil {
d.next = pixel.NewVerticalLSB(d.rect)
}
next = d.next.Pix
draw.Src.Draw(d.next, r, src, sp)
}
return d.drawInternal(next)
}
func getInitCmd(opts *display.Options) []byte {
// Set COM output scan direction; C0 means normal; C8 means reversed
comScan := byte(0xC8)
// See page 40.
columnAddr := byte(0xA1)
if opts.Rotate == display.Rotate180 {
// Change order both horizontally and vertically.
comScan = 0xC0
columnAddr = byte(0xA0)
}
if opts.Flip {
comScan = byte(0xC0)
}
if opts.Mirror {
columnAddr = byte(0xA0)
}
// See page 40.
hwLayout := byte(0x02)
if !opts.Sequential {
hwLayout |= 0x10
}
if opts.SwapTopBottom {
hwLayout |= 0x20
}
// Set the max frequency. The problem with I²C is that it creates visible
// tear down. On SPI at high speed this is not visible. Page 23 pictures how
// to avoid tear down. For now default to max frequency.
freq := byte(0xF0)
// Initialize the device by fully resetting all values.
// Page 64 has the full recommended flow.
// Page 28 lists all the commands.
return []byte{
0xAE, // Display off
0xD3, 0x00, // Set display offset; 0
0x40, // Start display start line; 0
columnAddr, // Set segment remap; RESET is column 127.
comScan, //
0xDA, hwLayout, // Set COM pins hardware configuration; see page 40
0x81, 0xFF, // Set max contrast
0xA4, // Set display to use GDDRAM content
0xA6, // Set normal display (0xA7 for inverted 0=lit, 1=dark)
0xD5, freq, // Set osc frequency and divide ratio; power on reset value is 0x80.
0x8D, 0x14, // Enable charge pump regulator; page 62
0xD9, 0xF1, // Set pre-charge period; from adafruit driver
0xDB, 0x40, // Set Vcomh deselect level; page 32
0x2E, // Deactivate scroll
0xA8, byte(opts.H - 1), // Set multiplex ratio (number of lines to display)
0x20, 0x00, // Set memory addressing mode to horizontal
0x21, 0, uint8(opts.W - 1), // Set column address (Width)
0x22, 0, uint8(opts.H/8 - 1), // Set page address (Pages)
0xAF, // Display on
}
logrus.Debug("draw image")
draw.Draw(d, r, src, sp, draw.Src)
return d.Refresh()
}
func (d *Display) Invert(on bool) error {
@@ -323,29 +204,98 @@ func (d *Display) Invert(on bool) error {
/* hardware.Display interface methods */
func (d *Display) Clear() {
for i := range d.buffer {
d.buffer[i] = 0x00
}
}
func (d *Display) Fill(c color.Color) error {
//return d.Draw(d.rect, &image.Uniform{c}, image.Point{})
return d.sendCommand([]byte{0xa7}) // invert :D
return d.Draw(d.Bounds(), &image.Uniform{c}, image.Point{})
}
func (d *Display) Refresh() error {
if d.next == nil {
return nil
// Displaying pixels on SSD1306 is peculiar, because the pixels are stored in columns
// of 8-bits (1 byte). Each column is sent out on a page.
for page := 0; page < int(d.height)>>3; page++ {
if err := d.sendCommand([]byte{
0x40 | 0, // Set display start line
0x10 | 0, // Set Higher Column Start Address for Page Addressing Mode
0xb0 | byte(page&0x0f), // Define start page address
}); err != nil {
return err
}
var (
off = page * int(d.width)
end = off + int(d.width)
)
if err := d.sendData(d.buffer[off:end]); err != nil {
return err
}
}
return d.drawInternal(d.next.Pix)
return nil
}
// SetRotation changes the rotation of the device (clock-wise).
func (d *Display) SetRotation(rotation display.Rotation) error {
d.rotation = rotation
var command []byte
switch d.rotation {
case display.NoRotation:
command = []byte{
segRemap | 0x1, // Reverse horizontal mapping
comScanDec, // Reverse vertical mapping
}
case display.Rotate180:
command = []byte{
segRemap, // Normal horizontal mapping
comScanInc, // Normal vertical mapping
}
// nothing to do
default:
command = []byte{
segRemap | 0x1, // Reverse horizontal mapping
comScanDec, // Reverse vertical mapping
}
}
return d.sendCommand(command)
}
/* draw.Image interface methods */
func (d *Display) rotate(x, y int) (int, int) {
switch d.rotation {
case display.Rotate90:
x, y = y, x
x = int(d.width) - x - 1
case display.Rotate180:
x = int(d.width) - x - 1
y = int(d.height) - y - 1
case display.Rotate270:
x, y = y, x
y = int(d.height) - y - 1
}
return x, y
}
func (d *Display) At(x, y int) color.Color {
if d.next == nil {
x, y = d.rotate(x, y)
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
return pixel.Off
}
return d.next.At(x, y)
byteIndex := int16(x) + int16(y/8)*d.width
if d.buffer[byteIndex]>>uint8(y%8)&0x1 == 1 {
return pixel.On
}
return pixel.Off
}
func (d *Display) Bounds() image.Rectangle {
return d.rect
return image.Rect(0, 0, int(d.width), int(d.height))
}
func (d *Display) ColorModel() color.Model {
@@ -353,8 +303,14 @@ func (d *Display) ColorModel() color.Model {
}
func (d *Display) Set(x, y int, c color.Color) {
if d.next == nil {
d.next = pixel.NewVerticalLSB(d.rect)
x, y = d.rotate(x, y)
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
return
}
byteIndex := int16(x) + int16(y>>3)*d.width
if pixel.IsOn(c) {
d.buffer[byteIndex] |= 1 << uint8(y%8)
} else {
d.buffer[byteIndex] &^= 1 << uint8(y%8)
}
d.next.Set(x, y, c)
}
+42
View File
@@ -0,0 +1,42 @@
package ssd1322
type VCCMode uint8
// Registers
const (
setContrast = 0x81
displayAllOnResume = 0xA4
displayAllOn = 0xA5
normalDisplay = 0xA6
invertDisplay = 0xA7
displayOff = 0xAE
displayOn = 0xAF
setDisplayOffset = 0xD3
setComPins = 0xDA
setVComDetect = 0xDB
setDisplayClockDiv = 0xD5
setPrecharge = 0xD9
setMultiplex = 0xA8
setLowColumn = 0x00
setHighColumn = 0x10
setStartLine = 0x40
memoryMode = 0x20
columnAddr = 0x21
pageAddr = 0x22
comScanInc = 0xC0
comScanDec = 0xC8
segRemap = 0xA0
chargePump = 0x8D
activateScroll = 0x2F
deactivateScroll = 0x2E
setVerticalScrollArea = 0xA3
rightHorizontalScroll = 0x26
leftHorizontalScroll = 0x27
verticalAndRightHorizontalScroll = 0x29
verticalAndLeftHorizontalScroll = 0x2A
)
const (
ExternalVCC VCCMode = iota + 0x1
SwitchCapVCC
)
+317
View File
@@ -0,0 +1,317 @@
// Package ssd1322 implements SSD1322 (monochrome) OLED displays.
package ssd1322
import (
"fmt"
"image"
"image/color"
"image/draw"
"time"
"github.com/sirupsen/logrus"
"go.maze.io/harmon/config"
"go.maze.io/harmon/hardware"
"go.maze.io/harmon/hardware/display"
"go.maze.io/harmon/internal/pixel"
)
const (
defaultWidth = 256
defaultHeight = 64
)
func init() {
display.Register("ssd1322", newDriver)
}
type ResetValue [2]byte
type Display struct {
conn display.Conn
buffer []byte
width int16
height int16
bufferSize int16
vccState VCCMode
canReset bool
resetCol ResetValue
resetPage ResetValue
rotation display.Rotation
scrolled bool
halted bool
}
func (Display) Type() string { return "ssd1322" }
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
var (
opts *display.Options
conn display.Conn
err error
)
if opts, err = display.ParseOptions(config, defaultWidth, defaultHeight); err != nil {
return nil, err
}
if opts.Rotate == display.Rotate180 {
// Let the hardware handle this rotation.
opts.Flip = true
opts.Mirror = true
}
log := logrus.WithFields(logrus.Fields{
"type": "ssd1322",
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
"mode": config.Mode,
"rotate": opts.Rotate,
})
log.Debug("new driver")
var isSPI bool
switch config.Mode {
case "", "i2c":
conn, err = display.OpenI2C(config.Bus, config.Address)
case "spi":
conn, err = display.OpenSPI(config.Port, config.Reset, config.DC)
isSPI = true
default:
return nil, display.InvalidMode(config.Mode)
}
if err != nil {
return nil, err
}
return newDisplay(conn, opts, isSPI)
}
func newDisplay(conn display.Conn, opts *display.Options, isSPI bool) (d *Display, err error) {
if opts.W < 8 || opts.W > 256 || opts.W&7 != 0 {
return nil, fmt.Errorf("invalid width %d", opts.W)
}
if opts.H < 8 || opts.H > 64 || opts.H&7 != 0 {
return nil, fmt.Errorf("invalid height %d", opts.H)
}
d = &Display{
conn: conn,
width: int16(opts.W),
height: int16(opts.H),
}
//var zeroReset ResetValue
d.vccState = SwitchCapVCC
d.resetCol = ResetValue{0, uint8(d.width - 1)}
d.resetPage = ResetValue{0, uint8(d.height/8) - 1}
d.bufferSize = d.width * d.height / 8
d.buffer = make([]byte, d.bufferSize)
d.canReset = !isSPI || d.width != 128 || d.height != 64 // I2C or not 128x64
logrus.Infof("%d bytes buffer for %d pixels", d.bufferSize, d.width*d.height)
time.Sleep(100 * time.Nanosecond)
muxr := byte(d.height - 1)
if err = d.sendCommand([]byte{
0xFD, 0x12, // set command lock: unlock
0xA4, // display off
0xB3, 0x91, // set front clock divider to 80fps (default is 0xD0)
0xCA, muxr, // multiplex ratio (height - 1)
0xA2, 0x00, // display offset 0
0xA1, 0x00, // display start line 0
0xA0, 0x14, 0x11, // set remap and dual COM line mode
0xB5, 0x00, // set GPIO input disabled
0xAB, 0x01, // enable internal VDD regulator
0xB4, 0xA0, 0xB5, // display enhancement A: enable external VSL, normal GS display quality
0xC1, 0x7F, // set contrast current
0xC7, 0x0f, // set master contrast current control
0xB8, 0x00, 0x02, 0x08, 0x0d, 0x14, 0x1a, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x60, 0x80, 0x80, // custom gray scale table
0xB1, 0xE2, // set phase length (period 1: 5 DCLKs, period 2: 14 DCLKs)
0xD1, 0xA2, 0x20, // display enhancement B: normal, as-is
0xBB, 0x1F, // set pre-charge voltage 0.60*VCC
0xB6, 0x08, // set second pre-charge period (8 DCLKs)
0xBE, 0x07, // set VCOMH: 0x07 = 0.86*VCC
0xA6, // set display mode normal
0xA9, // exit partial display
0xAF, // display on
}); err != nil {
return
}
return
}
func (d *Display) sendData(data []byte) error {
if d.halted {
// Transparently enable the display.
if err := d.sendCommand(nil); err != nil {
return err
}
}
return d.conn.Tx(data, false)
}
func (d *Display) sendCommand(data []byte) error {
if d.halted {
// Transparently enable the display.
data = append([]byte{0xAF}, data...)
d.halted = false
}
return d.conn.Tx(data, true)
}
func (d *Display) PowerSave(on bool) error {
var cmd []byte
if on {
cmd = []byte{
0xAB, 0x01, // enable internal VDD regulator
0xAF, // display on
}
} else {
cmd = []byte{
0xAB, 0x00, // disable internal VDD regulator
0xAE, // display off
}
}
return d.sendCommand(cmd)
}
// Halt turns off the display.
//
// Sending any other command afterward reenables the display.
func (d *Display) Halt() error {
d.halted = false
err := d.PowerSave(true)
if err == nil {
d.halted = true
}
return err
}
// Size of the display.
func (d *Display) Size() image.Point {
return image.Pt(int(d.width), int(d.height))
}
// Draw implements display.Drawer.
//
// It draws synchronously, once this function returns, the display is updated.
// It means that on slow bus (I²C), it may be preferable to defer Draw() calls
// to a background goroutine.
func (d *Display) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
logrus.Debug("draw image")
draw.Draw(d, r, src, sp, draw.Src)
return d.Refresh()
}
func (d *Display) Invert(on bool) error {
if on {
return d.sendCommand([]byte{0xA7})
}
return d.sendCommand([]byte{0xA6})
}
/* hardware.Display interface methods */
func (d *Display) Clear() {
for i := range d.buffer {
d.buffer[i] = 0x00
}
}
func (d *Display) Fill(c color.Color) error {
return d.Draw(d.Bounds(), &image.Uniform{c}, image.Point{})
}
func (d *Display) Refresh() error {
var (
offset = (480 - d.width) / 2
colStart = offset / 4
colEnd = colStart + d.width/4 - 1
)
if err := d.sendCommand([]byte{
0x15, byte(colStart), byte(colEnd),
0x75, 0, byte(d.height - 1),
0x5c,
}); err != nil {
return err
}
return d.sendData(d.buffer)
}
// SetRotation changes the rotation of the device (clock-wise).
func (d *Display) SetRotation(rotation display.Rotation) error {
d.rotation = rotation
var command []byte
switch d.rotation {
case display.NoRotation:
command = []byte{
segRemap | 0x1, // Reverse horizontal mapping
comScanDec, // Reverse vertical mapping
}
case display.Rotate180:
command = []byte{
segRemap, // Normal horizontal mapping
comScanInc, // Normal vertical mapping
}
// nothing to do
default:
command = []byte{
segRemap | 0x1, // Reverse horizontal mapping
comScanDec, // Reverse vertical mapping
}
}
return d.sendCommand(command)
}
/* draw.Image interface methods */
func (d *Display) rotate(x, y int) (int, int) {
switch d.rotation {
case display.Rotate90:
x, y = y, x
x = int(d.width) - x - 1
case display.Rotate180:
x = int(d.width) - x - 1
y = int(d.height) - y - 1
case display.Rotate270:
x, y = y, x
y = int(d.height) - y - 1
}
return x, y
}
func (d *Display) At(x, y int) color.Color {
x, y = d.rotate(x, y)
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
return pixel.Off
}
byteIndex := int16(x) + int16(y/8)*d.width
if d.buffer[byteIndex]>>uint8(y%8)&0x1 == 1 {
return pixel.On
}
return pixel.Off
}
func (d *Display) Bounds() image.Rectangle {
return image.Rect(0, 0, int(d.width), int(d.height))
}
func (d *Display) ColorModel() color.Model {
return pixel.MonochromeModel
}
func (d *Display) Set(x, y int, c color.Color) {
x, y = d.rotate(x, y)
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
return
}
byteIndex := int16(x) + int16(y>>3)*d.width
if pixel.IsOn(c) {
d.buffer[byteIndex] |= 1 << uint8(y%8)
} else {
d.buffer[byteIndex] &^= 1 << uint8(y%8)
}
}
+37
View File
@@ -0,0 +1,37 @@
package ssd1xxx
// Config describes the OLED configuration.
type Config struct {
Width int
Height int
ExternalVCC bool
Init []Command
Suspend []Command
Resume []Command
}
// Command is one or more command bytes.
type Command interface {
Bytes() []byte
}
type Register byte
func (r Register) Bytes() []byte { return []byte{byte(r)} }
type RegisterArgs struct {
Register Register
Args []byte
}
func (r RegisterArgs) Bytes() []byte { return append([]byte{byte(r.Register)}, r.Args...) }
type RegisterFunc struct {
Register Register
Func func() []byte
}
func (r RegisterFunc) Bytes() []byte {
args := r.Func()
return append([]byte{byte(r.Register)}, args...)
}
+61
View File
@@ -0,0 +1,61 @@
package st7735
import "go.maze.io/harmon/hardware/display"
// Registers
const (
NOP = 0x00
SWRESET = 0x01
RDDID = 0x04
RDDST = 0x09
SLPIN = 0x10
SLPOUT = 0x11
PTLON = 0x12
NORON = 0x13
INVOFF = 0x20
INVON = 0x21
DISPOFF = 0x28
DISPON = 0x29
CASET = 0x2A
RASET = 0x2B
RAMWR = 0x2C
RAMRD = 0x2E
PTLAR = 0x30
COLMOD = 0x3A
MADCTL = 0x36
MADCTL_MY = 0x80
MADCTL_MX = 0x40
MADCTL_MV = 0x20
MADCTL_ML = 0x10
MADCTL_RGB = 0x00
MADCTL_BGR = 0x08
MADCTL_MH = 0x04
RDID1 = 0xDA
RDID2 = 0xDB
RDID3 = 0xDC
RDID4 = 0xDD
FRMCTR1 = 0xB1
FRMCTR2 = 0xB2
FRMCTR3 = 0xB3
INVCTR = 0xB4
DISSET5 = 0xB6
PWCTR1 = 0xC0
PWCTR2 = 0xC1
PWCTR3 = 0xC2
PWCTR4 = 0xC3
PWCTR5 = 0xC4
VMCTR1 = 0xC5
PWCTR6 = 0xFC
GMCTRP1 = 0xE0
GMCTRN1 = 0xE1
VSCRDEF = 0x33
VSCRSADD = 0x37
GREENTAB Model = 0
MINI80x160 Model = 1
NO_ROTATION display.Rotation = 0
ROTATION_90 display.Rotation = 1 // 90 degrees clock-wise rotation
ROTATION_180 display.Rotation = 2
ROTATION_270 display.Rotation = 3
)
+836
View File
@@ -0,0 +1,836 @@
package st7735
import (
"errors"
"fmt"
"image"
"image/color"
"image/draw"
"time"
"github.com/sirupsen/logrus"
"go.maze.io/harmon/config"
"go.maze.io/harmon/hardware"
"go.maze.io/harmon/hardware/display"
"go.maze.io/harmon/internal/spidev"
"periph.io/x/conn/v3/gpio"
"periph.io/x/conn/v3/physic"
//"periph.io/x/conn/v3/spi"
//"periph.io/x/conn/v3/spi/spireg"
)
const (
ST7735_SWRESET = 0x01
ST7735_SLPIN = 0x10
ST7735_SLPOUT = 0x11
ST7735_FRMCTR1 = 0xB1
ST7735_FRMCTR2 = 0xB2
ST7735_FRMCTR3 = 0xB3
ST7735_INVCTR = 0xB4
ST7735_INVOFF = 0x20
ST7735_INVON = 0x21
ST7735_PWCTR1 = 0xC0
ST7735_PWCTR2 = 0xC1
ST7735_PWCTR4 = 0xC3
ST7735_PWCTR5 = 0xC4
ST7735_VMCTR1 = 0xC5
ST7735_MADCTL = 0x36
ST7735_COLMOD = 0x3A
ST7735_CASET = 0x2A
ST7735_RASET = 0x2B
ST7735_RAMWR = 0x2C
ST7735_GMCTRP1 = 0xE0
ST7735_GMCTRN1 = 0xE1
ST7735_NORON = 0x13
ST7735_DISPON = 0x29
ST7735_TFTWIDTH = 80
ST7735_TFTHEIGHT = 160
ST7735_COLS = 132
ST7735_ROWS = 162
ChunkSize = 4096
)
func init() {
display.Register("st7735", newDriver)
}
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
var (
opts *display.Options
//port spi.PortCloser
//conn spi.Conn
conn *spidev.SPI
reset, dc, bl gpio.PinOut
err error
)
if opts, err = display.ParseOptions(config, 240, 240); err != nil {
return nil, err
}
log := logrus.WithFields(logrus.Fields{
"type": "st7735",
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
"rotate": opts.Rotate,
})
log.Debug("new driver")
if reset, err = hardware.LookupPin(config.Reset); err != nil {
return nil, err
}
if dc, err = hardware.LookupPin(config.DC); err != nil {
return nil, err
}
if bl, err = hardware.LookupPin(config.BL); err != nil {
return nil, err
}
const speed = 40000000 * physic.Hertz
log.WithFields(logrus.Fields{
"port": config.Port,
"pin_reset": reset,
"pin_dc": dc,
"pin_bl": bl,
"speed": speed,
"bits": 8,
//"mode": spi.Mode0,
}).Debug("opening SPI port")
/*
if port, err = spireg.Open(config.Port); err != nil {
return nil, err
}
if conn, err = port.Connect(speed, spi.Mode0, 8); err != nil {
_ = port.Close()
return nil, err
}
*/
if conn, err = spidev.Open("/dev/spidev0.0"); err != nil {
return nil, err
}
conn.SetMode(0)
conn.SetBitsPerWord(8)
//conn.SetLSBFirst(false)
conn.SetSpeedHz(uint32(speed / physic.Hertz))
/*
d := &Dev{
c: conn,
dc: dc,
rst: reset,
backlight: bl,
opts: Opts{
Width: byte(opts.W),
Height: byte(opts.H),
OffsetLeft: byte(ST7735_COLS-opts.W) / 2,
OffsetTop: byte(ST7735_ROWS-opts.H) / 2,
},
}
return d, nil
*/
d := newDevice(conn, reset, dc, bl)
d.Configure(Config{
Width: int16(opts.W),
Height: int16(opts.H),
Rotation: opts.Rotate,
})
return d, nil
}
type Model uint8
// Device wraps an SPI connection.
type Device struct {
bus *spidev.SPI
dcPin gpio.PinOut
resetPin gpio.PinOut
blPin gpio.PinOut
width int16
height int16
columnOffset int16
rowOffset int16
rotation display.Rotation
batchLength int16
model Model
isBGR bool
batchData []uint8
}
// Config is the configuration for the display
type Config struct {
Width int16
Height int16
Rotation display.Rotation
Model Model
RowOffset int16
ColumnOffset int16
}
// New creates a new ST7735 connection. The SPI wire must already be configured.
// func newDevice(bus spi.Conn, resetPin, dcPin, blPin gpio.PinOut) *Device {
func newDevice(bus *spidev.SPI, resetPin, dcPin, blPin gpio.PinOut) *Device {
return &Device{
bus: bus,
dcPin: dcPin,
resetPin: resetPin,
blPin: blPin,
}
}
// Configure initializes the display with default configuration
func (d *Device) Configure(cfg Config) {
d.model = cfg.Model
if cfg.Width != 0 {
d.width = cfg.Width
} else {
if d.model == MINI80x160 {
d.width = 80
} else {
d.width = 128
}
}
if cfg.Height != 0 {
d.height = cfg.Height
} else {
d.height = 160
}
d.rotation = cfg.Rotation
d.rowOffset = cfg.RowOffset
d.columnOffset = cfg.ColumnOffset
d.batchLength = d.width
if d.height > d.width {
d.batchLength = d.height
}
d.batchLength += d.batchLength & 1
d.batchData = make([]uint8, d.batchLength*2)
// reset the device
d.resetPin.Out(gpio.High)
time.Sleep(5 * time.Millisecond)
d.resetPin.Out(gpio.Low)
time.Sleep(20 * time.Millisecond)
d.resetPin.Out(gpio.High)
time.Sleep(150 * time.Millisecond)
println("display reset done")
// Common initialization
d.Command(SWRESET)
time.Sleep(150 * time.Millisecond)
d.Command(SLPOUT)
time.Sleep(500 * time.Millisecond)
d.Command(FRMCTR1)
d.Data(0x01)
d.Data(0x2C)
d.Data(0x2D)
d.Command(FRMCTR2)
d.Data(0x01)
d.Data(0x2C)
d.Data(0x2D)
d.Command(FRMCTR3)
d.Data(0x01)
d.Data(0x2C)
d.Data(0x2D)
d.Data(0x01)
d.Data(0x2C)
d.Data(0x2D)
d.Command(INVCTR)
d.Data(0x07)
d.Command(PWCTR1)
d.Data(0xA2)
d.Data(0x02)
d.Data(0x84)
d.Command(PWCTR2)
d.Data(0xC5)
d.Command(PWCTR3)
d.Data(0x0A)
d.Data(0x00)
d.Command(PWCTR4)
d.Data(0x8A)
d.Data(0x2A)
d.Command(PWCTR5)
d.Data(0x8A)
d.Data(0xEE)
d.Command(VMCTR1)
d.Data(0x0E)
d.Command(COLMOD)
d.Data(0x05)
if d.model == GREENTAB {
d.InvertColors(false)
} else if d.model == MINI80x160 {
d.isBGR = true
d.InvertColors(true)
}
println("display config done")
// common color adjustment
d.Command(GMCTRP1)
d.Data(0x02)
d.Data(0x1C)
d.Data(0x07)
d.Data(0x12)
d.Data(0x37)
d.Data(0x32)
d.Data(0x29)
d.Data(0x2D)
d.Data(0x29)
d.Data(0x25)
d.Data(0x2B)
d.Data(0x39)
d.Data(0x00)
d.Data(0x01)
d.Data(0x03)
d.Data(0x10)
d.Command(GMCTRN1)
d.Data(0x03)
d.Data(0x1D)
d.Data(0x07)
d.Data(0x06)
d.Data(0x2E)
d.Data(0x2C)
d.Data(0x29)
d.Data(0x2D)
d.Data(0x2E)
d.Data(0x2E)
d.Data(0x37)
d.Data(0x3F)
d.Data(0x00)
d.Data(0x00)
d.Data(0x02)
d.Data(0x10)
println("display color correction done")
d.Command(NORON)
time.Sleep(10 * time.Millisecond)
d.Command(DISPON)
time.Sleep(500 * time.Millisecond)
if cfg.Model == MINI80x160 {
d.Command(MADCTL)
d.Data(0xC0)
}
d.SetRotation(d.rotation)
println("display rotation set")
d.blPin.Out(gpio.High)
}
// Display does nothing, there's no buffer as it might be too big for some boards
func (d *Device) Display() error {
return nil
}
// SetPixel sets a pixel in the screen
func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
w, h := d.size()
if x < 0 || y < 0 || x >= w || y >= h {
return
}
d.FillRectangle(x, y, 1, 1, c)
}
// setWindow prepares the screen to be modified at a given rectangle
func (d *Device) setWindow(x, y, w, h int16) {
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
x += d.columnOffset
y += d.rowOffset
} else {
x += d.rowOffset
y += d.columnOffset
}
d.Tx([]uint8{CASET}, true)
d.Tx([]uint8{uint8(x >> 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1)}, false)
d.Tx([]uint8{RASET}, true)
d.Tx([]uint8{uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1)}, false)
d.Command(RAMWR)
}
// SetScrollWindow sets an area to scroll with fixed top and bottom parts of the display
func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) {
d.Command(VSCRDEF)
d.Tx([]uint8{
uint8(topFixedArea >> 8), uint8(topFixedArea),
uint8(d.height - topFixedArea - bottomFixedArea>>8), uint8(d.height - topFixedArea - bottomFixedArea),
uint8(bottomFixedArea >> 8), uint8(bottomFixedArea)},
false)
}
// SetScroll sets the vertical scroll address of the display.
func (d *Device) SetScroll(line int16) {
d.Command(VSCRSADD)
d.Tx([]uint8{uint8(line >> 8), uint8(line)}, false)
}
// SpotScroll returns the display to its normal state
func (d *Device) StopScroll() {
d.Command(NORON)
}
// FillRectangle fills a rectangle at a given coordinates with a color
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
k, i := d.size()
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= k || (x+width) > k || y >= i || (y+height) > i {
return errors.New("rectangle coordinates outside display area")
}
d.setWindow(x, y, width, height)
c565 := 65535
c1 := uint8(c565 >> 8)
c2 := uint8(c565)
for i = 0; i < d.batchLength; i++ {
d.batchData[i*2] = c1
d.batchData[i*2+1] = c2
}
i = width * height
for i > 0 {
if i >= d.batchLength {
d.Tx(d.batchData, false)
} else {
d.Tx(d.batchData[:i*2], false)
}
i -= d.batchLength
}
return nil
}
// FillRectangle fills a rectangle at a given coordinates with a buffer
func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
k, l := d.size()
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= k || (x+width) > k || y >= l || (y+height) > l {
//return errors.New("rectangle coordinates outside display area")
return fmt.Errorf("rectangle [%d %d %d %d] outside of [0 0 %d %d]", x, y, width, height, k, l)
}
k = width * height
l = int16(len(buffer))
if k != l {
return errors.New("buffer length does not match with rectangle size")
}
d.setWindow(x, y, width, height)
offset := int16(0)
for k > 0 {
for i := int16(0); i < d.batchLength; i++ {
if offset+i < l {
c565 := 65535
c1 := uint8(c565 >> 8)
c2 := uint8(c565)
d.batchData[i*2] = c1
d.batchData[i*2+1] = c2
}
}
if k >= d.batchLength {
d.Tx(d.batchData, false)
} else {
d.Tx(d.batchData[:k*2], false)
}
k -= d.batchLength
offset += d.batchLength
}
return nil
}
// DrawFastVLine draws a vertical line faster than using SetPixel
func (d *Device) DrawFastVLine(x, y0, y1 int16, c color.RGBA) {
if y0 > y1 {
y0, y1 = y1, y0
}
d.FillRectangle(x, y0, 1, y1-y0+1, c)
}
// DrawFastHLine draws a horizontal line faster than using SetPixel
func (d *Device) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
if x0 > x1 {
x0, x1 = x1, x0
}
d.FillRectangle(x0, y, x1-x0+1, 1, c)
}
// FillScreen fills the screen with a given color
func (d *Device) FillScreen(c color.RGBA) {
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
d.FillRectangle(0, 0, d.width, d.height, c)
} else {
d.FillRectangle(0, 0, d.height, d.width, c)
}
}
// SetRotation changes the rotation of the device (clock-wise)
func (d *Device) SetRotation(rotation display.Rotation) {
madctl := uint8(0)
switch rotation % 4 {
case 0:
madctl = MADCTL_MX | MADCTL_MY
break
case 1:
madctl = MADCTL_MY | MADCTL_MV
break
case 2:
break
case 3:
madctl = MADCTL_MX | MADCTL_MV
break
}
if d.isBGR {
madctl |= MADCTL_BGR
}
d.Command(MADCTL)
d.Data(madctl)
}
// Command sends a command to the display
func (d *Device) Command(command uint8) {
d.Tx([]byte{command}, true)
}
// Command sends a data to the display
func (d *Device) Data(data uint8) {
d.Tx([]byte{data}, false)
}
// Tx sends data to the display
func (d *Device) Tx(data []byte, isCommand bool) {
d.dcPin.Out(gpio.Level(!isCommand))
//d.bus.Tx(data, nil)
d.bus.Transfer([]spidev.Transfer{{Tx: data}})
}
// Size returns the current size of the display.
func (d *Device) size() (w, h int16) {
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
return d.width, d.height
}
return d.height, d.width
}
// EnableBacklight enables or disables the backlight
func (d *Device) EnableBacklight(enable bool) {
if enable {
d.blPin.Out(gpio.High)
} else {
d.blPin.Out(gpio.Low)
}
}
// InverColors inverts the colors of the screen
func (d *Device) InvertColors(invert bool) {
if invert {
d.Command(INVON)
} else {
d.Command(INVOFF)
}
}
// IsBGR changes the color mode (RGB/BGR)
func (d *Device) IsBGR(bgr bool) {
d.isBGR = bgr
}
/*
// Dev is a handle to a ST7735
type Dev struct {
c conn.Conn
// dc low when sending a command, high when sending data.
dc gpio.PinOut
// rst reset pin, active low.
rst gpio.PinOut
// backlight pin
backlight gpio.PinOut
opts Opts
}
// Opts contains the configuration fot the ST7735 device
type Opts struct {
Width byte
Height byte
OffsetLeft byte
OffsetTop byte
}
var DefaultOpts = Opts{
Width: ST7735_TFTWIDTH,
Height: ST7735_TFTHEIGHT,
OffsetLeft: (ST7735_COLS - ST7735_TFTWIDTH) / 2, // (132-80)/2 = 26
OffsetTop: (ST7735_ROWS - ST7735_TFTHEIGHT) / 2, // (162-160)/2 = 1
}
// New opens a handle to a ST7735
func New(p spi.Port, dc gpio.PinOut, rst gpio.PinOut, backlight gpio.PinOut, o *Opts) (*Dev, error) {
c, err := p.Connect(4000*physic.KiloHertz, spi.Mode0, 8)
if err != nil {
return nil, errors.New("could not connect to device")
}
d := &Dev{
c: c,
dc: dc,
rst: rst,
backlight: backlight,
opts: *o,
}
return d, nil
}
func (d *Dev) Init() error {
if err := d.Backlight(true); err != nil {
return err
}
invert := commandAndData{[]byte{ST7735_INVON}, nil, 0} // don't invert
if false {
invert = commandAndData{[]byte{ST7735_INVOFF}, nil, 0} // invert
}
width := d.opts.Width
height := d.opts.Height
offsetLeft := d.opts.OffsetLeft
offsetTop := d.opts.OffsetTop
init := []commandAndData{
{[]byte{ST7735_SWRESET}, nil, 150 * time.Millisecond}, // software reset
{[]byte{ST7735_SLPOUT}, nil, 500 * time.Millisecond}, // out of sleep mode
{[]byte{ST7735_FRMCTR1}, []byte{0x01, 0x2C, 0x2D}, 0}, // frame rate ctrl - normal mode, rate = fosc/(1x2+40) * (LINE+2C+2D)
{[]byte{ST7735_FRMCTR2}, []byte{0x01, 0x2C, 0x2D}, 0}, // frame rate crtl - idle mode, rate = fosc(1x2+40) * (LINE+2C+2D)
{[]byte{ST7735_FRMCTR3}, []byte{0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D}, 0}, // frame rate ctrl - partial mode
{[]byte{ST7735_INVCTR}, []byte{0x07}, 0}, // display inversion ctrl - no inversion
{[]byte{ST7735_PWCTR1}, []byte{0xA2, 0x02, 0x84}, 0}, // power control, -4.6V, auto mode
{[]byte{ST7735_PWCTR2}, []byte{0x0A, 0x00}, 0}, // power control, Opamp current small, boost frequency
{[]byte{ST7735_PWCTR4}, []byte{0x8A, 0x2A}, 0}, // power control, BCLK/2, Opamp current small & Medium low
{[]byte{ST7735_PWCTR5}, []byte{0x8A, 0xEE}, 0}, // power control
{[]byte{ST7735_VMCTR1}, []byte{0x0E}, 0}, // power control
invert,
{[]byte{ST7735_MADCTL}, []byte{0xC8}, 0}, // memory access control (directions), row addr/col addr, bottom to top refresh
{[]byte{ST7735_COLMOD}, []byte{0x05}, 0}, // set color mode, 16-bit color
{[]byte{ST7735_CASET}, []byte{0x00, offsetLeft, 0x00, width + offsetLeft - 1}, 0}, // Column addr set, XSTART = 0, XEND = ROWS-height
{[]byte{ST7735_RASET}, []byte{0x00, offsetTop, 0x00, height + offsetTop - 1}, 0}, // Row addr set, XSTART = 0, XEND = COLS-width
{[]byte{ST7735_GMCTRP1}, []byte{0x02, 0x1c, 0x07, 0x12, // set gamma
0x37, 0x32, 0x29, 0x2d, 0x29, 0x25, 0x2B, 0x39, 0x00,
0x01, 0x03, 0x10}, 0},
{[]byte{ST7735_GMCTRN1}, []byte{0x03, 0x1d, 0x07, 0x06, // set gamma
0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00,
0x00, 0x02, 0x10}, 0},
{[]byte{ST7735_NORON}, nil, 100 * time.Millisecond}, // normal display on
{[]byte{ST7735_DISPON}, nil, 100 * time.Millisecond}, // display on
}
return d.sendBatch(init)
}
func (d *Dev) Powersave() error {
return d.sendCommand([]byte{ST7735_SLPIN})
}
func (d *Dev) SetBacklight(value bool) {
if d.backlight == nil {
return
}
if value {
d.backlight.Out(gpio.High)
} else {
d.backlight.Out(gpio.Low)
}
}
func (d *Dev) SetWindow(x0, y0, x1, y1 int) error {
y0 += int(d.opts.OffsetTop)
y1 += int(d.opts.OffsetTop)
x0 += int(d.opts.OffsetLeft)
x1 += int(d.opts.OffsetLeft)
commands := []commandAndData{
{[]byte{ST7735_CASET}, []byte{byte(x0 >> 8), byte(x0), byte(x1 >> 8), byte(x1)}, 0}, // column addr set
{[]byte{ST7735_RASET}, []byte{byte(y0 >> 8), byte(y0), byte(y1 >> 8), byte(y1)}, 0}, // row addr set
{[]byte{ST7735_RAMWR}, nil, 0}, // write to RAM
}
return d.sendBatch(commands)
}
func (d *Dev) DisplayImage(x, y int, img *image.RGBA) error {
offsetBounds := img.Bounds().Add(image.Point{X: x, Y: y})
maxBounds := image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{int(d.opts.Width), int(d.opts.Height)}}
offsetBounds = offsetBounds.Intersect(maxBounds)
bounds := offsetBounds.Sub(image.Point{X: x, Y: y})
err := d.SetWindow(offsetBounds.Min.X, offsetBounds.Min.Y, offsetBounds.Max.X-1, offsetBounds.Max.Y-1)
if err != nil {
return err
}
subImg := img.SubImage(bounds)
buf := []byte{}
for x := bounds.Min.X; x < bounds.Max.X; x++ {
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
c := subImg.At(x, y)
cd := RGBATo565(c.(color.RGBA))
buf = append(buf, byte(cd>>8), byte(cd))
}
}
return d.sendData(buf)
}
func (d *Dev) Display(data []byte) error {
err := d.SetWindow(0, 0, int(d.opts.Width-1), int(d.opts.Height-1))
if err != nil {
return err
}
return d.sendData(data)
}
func (d *Dev) Halt() error {
d.SetBacklight(false)
return d.Powersave()
}
func (d *Dev) sendCommand(c []byte) error {
if err := d.dc.Out(gpio.Low); err != nil {
return err
}
return d.c.Tx(c, nil)
}
func (d *Dev) sendData(c []byte) error {
if err := d.dc.Out(gpio.High); err != nil {
return err
}
for offset := 0; offset < len(c); offset += ChunkSize {
end := offset + ChunkSize
if end > len(c) {
end = len(c)
}
if err := d.c.Tx(c[offset:end], nil); err != nil {
return err
}
}
return nil
}
func (d *Dev) sendBatch(commands []commandAndData) error {
for _, cad := range commands {
if err := d.sendCommand(cad.cmd); err != nil {
return err
}
if len(cad.data) == 0 {
continue
}
if err := d.sendData(cad.data); err != nil {
return err
}
if cad.sleep > 0 {
time.Sleep(cad.sleep)
}
}
return nil
}
type commandAndData struct {
cmd []byte
data []byte
sleep time.Duration
}
// RGBATo565 converts a color.RGBA to uint16 used in the display
func RGBATo565(c color.RGBA) uint16 {
r, g, b, _ := c.RGBA()
return uint16((r & 0xF800) +
((g & 0xFC00) >> 5) +
((b & 0xF800) >> 11))
}
*/
func (d *Device) At(i, j int) color.Color {
return color.Black
}
func (d *Device) Backlight(on bool) error {
return d.blPin.Out(gpio.Level(!on))
}
func (d *Device) Bounds() image.Rectangle {
return image.Rect(0, 0, int(d.width), int(d.height))
}
func (Device) Clear() {}
func (d *Device) Fill(c color.Color) error {
img := image.NewRGBA(d.Bounds())
draw.Draw(img, img.Rect, &image.Uniform{c}, image.Point{}, draw.Src)
//d.DisplayImage(0, 0, img)
return nil
}
func (d *Device) ColorModel() color.Model {
return color.RGBAModel
}
func (d *Device) Set(x, y int, c color.Color) {
/*
d.SetWindow(x, y, x, y)
var buf []byte
cd := RGBATo565(color.RGBAModel.Convert(c).(color.RGBA))
buf = append(buf, byte(cd>>8), byte(cd))
d.sendData(buf)
*/
d.SetPixel(int16(x), int16(y), color.RGBAModel.Convert(c).(color.RGBA))
}
func (Device) Type() string {
return "st7735"
}
func (Device) Refresh() error {
return nil
}
func (d *Device) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
buffer := make([]color.RGBA, 0, int(d.width)*int(d.height))
for y := 0; y < int(d.height); y++ {
for x := 0; x < int(d.width); x++ {
r, g, b, _ := src.At(x, y).RGBA()
buffer = append(buffer, color.RGBA{
R: uint8(r >> 8),
G: uint8(g >> 8),
B: uint8(b >> 8),
A: 0xff,
})
}
}
return d.FillRectangleWithBuffer(0, 0, d.width, d.height, buffer)
}
func (d *Device) Size() image.Point {
return image.Pt(int(d.width), int(d.height))
}
func (Device) Halt() error {
return nil
}
+146
View File
@@ -0,0 +1,146 @@
package st7789
import "go.maze.io/harmon/hardware/display"
const (
ST7789_TFTWIDTH = 240
ST7789_TFTHEIGHT = 240
ST7789_NOP = 0x00
ST7789_SWRESET = 0x01
ST7789_RDDID = 0x04
ST7789_RDDST = 0x09
ST7789_RDDPM = 0x0A
ST7789_RDDMADCTL = 0x0B
ST7789_RDDCOLMOD = 0x0C
ST7789_RDDIM = 0x0D
ST7789_RDDSM = 0x0E
ST7789_RDDSDR = 0x0F
ST7789_SLPIN = 0x10
ST7789_SLPOUT = 0x11
ST7789_PTLON = 0x12
ST7789_NORON = 0x13
ST7789_INVOFF = 0x20
ST7789_INVON = 0x21
ST7789_GAMSET = 0x26
ST7789_DISPOFF = 0x28
ST7789_DISPON = 0x29
ST7789_CASET = 0x2A
ST7789_RASET = 0x2B
ST7789_RAMWR = 0x2C
ST7789_RAMRD = 0x2E
ST7789_PTLAR = 0x30
ST7789_VSCRDEF = 0x33
ST7789_TEOFF = 0x34
ST7789_TEON = 0x35
ST7789_MADCTL = 0x36
ST7789_VSCRSADD = 0x37
ST7789_IDMOFF = 0x38
ST7789_IDMON = 0x39
ST7789_COLMOD = 0x3A
ST7789_RAMWRC = 0x3C
ST7789_RAMRDC = 0x3E
ST7789_TESCAN = 0x44
ST7789_RDTESCAN = 0x45
ST7789_WRDISBV = 0x51
ST7789_RDDISBV = 0x52
ST7789_WRCTRLD = 0x53
ST7789_RDCTRLD = 0x54
ST7789_WRCACE = 0x55
ST7789_RDCABC = 0x56
ST7789_WRCABCMB = 0x5E
ST7789_RDCABCMB = 0x5F
ST7789_RDABCSDR = 0x68
ST7789_RDID1 = 0xDA
ST7789_RDID2 = 0xDB
ST7789_RDID3 = 0xDC
ST7789_RAMCTRL = 0xB0
ST7789_RGBCTRL = 0xB1
ST7789_PORCTRL = 0xB2
ST7789_FRCTRL1 = 0xB3
ST7789_GCTRL = 0xB7
ST7789_DGMEN = 0xBA
ST7789_VCOMS = 0xBB
ST7789_LCMCTRL = 0xC0
ST7789_IDSET = 0xC1
ST7789_VDVVRHEN = 0xC2
ST7789_VRHS = 0xC3
ST7789_VDVSET = 0xC4
ST7789_VCMOFSET = 0xC5
ST7789_FRCTR2 = 0xC6
ST7789_CABCCTRL = 0xC7
ST7789_REGSEL1 = 0xC8
ST7789_REGSEL2 = 0xCA
ST7789_PWMFRSEL = 0xCC
ST7789_PWCTRL1 = 0xD0
ST7789_VAPVANEN = 0xD2
ST7789_CMD2EN = 0xDF5A6902
ST7789_PVGAMCTRL = 0xE0
ST7789_NVGAMCTRL = 0xE1
ST7789_DGMLUTR = 0xE2
ST7789_DGMLUTB = 0xE3
ST7789_GATECTRL = 0xE4
ST7789_PWCTRL2 = 0xE8
ST7789_EQCTRL = 0xE9
ST7789_PROMCTRL = 0xEC
ST7789_PROMEN = 0xFA
ST7789_NVMSET = 0xFC
ST7789_PROMACT = 0xFE
)
const (
NO_ROTATION display.Rotation = 0
ROTATION_90 display.Rotation = 1 // 90 degrees clock-wise rotation
ROTATION_180 display.Rotation = 2
ROTATION_270 display.Rotation = 3
)
const (
FRAMERATE_111 FrameRate = 0x01
FRAMERATE_105 FrameRate = 0x02
FRAMERATE_99 FrameRate = 0x03
FRAMERATE_94 FrameRate = 0x04
FRAMERATE_90 FrameRate = 0x05
FRAMERATE_86 FrameRate = 0x06
FRAMERATE_82 FrameRate = 0x07
FRAMERATE_78 FrameRate = 0x08
FRAMERATE_75 FrameRate = 0x09
FRAMERATE_72 FrameRate = 0x0A
FRAMERATE_69 FrameRate = 0x0B
FRAMERATE_67 FrameRate = 0x0C
FRAMERATE_64 FrameRate = 0x0D
FRAMERATE_62 FrameRate = 0x0E
FRAMERATE_60 FrameRate = 0x0F // 60 is default
FRAMERATE_58 FrameRate = 0x10
FRAMERATE_57 FrameRate = 0x11
FRAMERATE_55 FrameRate = 0x12
FRAMERATE_53 FrameRate = 0x13
FRAMERATE_52 FrameRate = 0x14
FRAMERATE_50 FrameRate = 0x15
FRAMERATE_49 FrameRate = 0x16
FRAMERATE_48 FrameRate = 0x17
FRAMERATE_46 FrameRate = 0x18
FRAMERATE_45 FrameRate = 0x19
FRAMERATE_44 FrameRate = 0x1A
FRAMERATE_43 FrameRate = 0x1B
FRAMERATE_42 FrameRate = 0x1C
FRAMERATE_41 FrameRate = 0x1D
FRAMERATE_40 FrameRate = 0x1E
FRAMERATE_39 FrameRate = 0x1F
)
const (
MAX_VSYNC_SCANLINES = 254
)
+611
View File
@@ -0,0 +1,611 @@
// Package st7789 implements a driver for the ST7789 TFT displays, it comes in various screen sizes.
//
// Datasheets: https://cdn-shop.adafruit.com/product-files/3787/3787_tft_QT154H2201__________20190228182902.pdf
//
// http://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf
package st7789
import (
"errors"
"fmt"
"image"
"image/color"
"math"
"time"
"github.com/sirupsen/logrus"
"periph.io/x/conn/v3/gpio"
"periph.io/x/conn/v3/physic"
"periph.io/x/conn/v3/spi"
"periph.io/x/conn/v3/spi/spireg"
"go.maze.io/harmon/config"
"go.maze.io/harmon/hardware"
"go.maze.io/harmon/hardware/display"
)
func init() {
display.Register("st7789", newDriver)
}
var (
errOutOfBounds = errors.New("rectangle coordinates outside display area")
)
// FrameRate controls the frame rate used by the display.
type FrameRate uint8
type Device struct {
conn spi.Conn
reset gpio.PinOut
dcPin gpio.PinOut
resetPin gpio.PinOut
blPin gpio.PinOut
width int16
height int16
columnOffsetCfg int16
rowOffsetCfg int16
columnOffset int16
rowOffset int16
rotation display.Rotation
frameRate FrameRate
batchLength int32
isBGR bool
vSyncLines int16
}
// Config is the configuration for the display
type Config struct {
Width int16
Height int16
Rotation display.Rotation
RowOffset int16
ColumnOffset int16
FrameRate FrameRate
VSyncLines int16
}
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
var (
opts *display.Options
port spi.PortCloser
conn spi.Conn
reset, dc, bl gpio.PinOut
err error
)
if opts, err = display.ParseOptions(config, 240, 240); err != nil {
return nil, err
}
log := logrus.WithFields(logrus.Fields{
"type": "st7789",
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
"rotate": opts.Rotate,
})
log.Debug("new driver")
if reset, err = hardware.LookupPin(config.Reset); err != nil {
return nil, err
}
if dc, err = hardware.LookupPin(config.DC); err != nil {
return nil, err
}
if bl, err = hardware.LookupPin(config.BL); err != nil {
return nil, err
}
const speed = 40000000 * physic.Hertz
log.WithFields(logrus.Fields{
"port": config.Port,
"pin_reset": reset,
"pin_dc": dc,
"pin_bl": bl,
"speed": speed,
"bits": 8,
"mode": spi.Mode0,
}).Debug("opening SPI port")
if port, err = spireg.Open(config.Port); err != nil {
return nil, err
}
if conn, err = port.Connect(speed, spi.Mode0, 8); err != nil {
_ = port.Close()
return nil, err
}
return newDisplay(conn, reset, dc, bl, opts)
}
func newDisplay(conn spi.Conn, reset, dc, bl gpio.PinOut, opts *display.Options) (d *Device, err error) {
d = &Device{
conn: conn,
resetPin: reset,
dcPin: dc,
blPin: bl,
}
d.Configure(Config{
Width: int16(opts.W),
Height: int16(opts.H),
Rotation: opts.Rotate,
FrameRate: FRAMERATE_60,
})
return d, nil
}
// Configure initializes the display with default configuration
func (d *Device) Configure(cfg Config) {
if cfg.Width != 0 {
d.width = cfg.Width
} else {
d.width = 240
}
if cfg.Height != 0 {
d.height = cfg.Height
} else {
d.height = 240
}
logrus.WithFields(logrus.Fields{
"driver": "st7789",
"width": d.width,
"height": d.height,
}).Warn("yello!")
d.rotation = cfg.Rotation
d.rowOffsetCfg = cfg.RowOffset
d.columnOffsetCfg = cfg.ColumnOffset
if cfg.FrameRate != 0 {
d.frameRate = cfg.FrameRate
} else {
d.frameRate = FRAMERATE_60
}
if cfg.VSyncLines >= 2 && cfg.VSyncLines <= 254 {
d.vSyncLines = cfg.VSyncLines
} else {
d.vSyncLines = 16
}
d.batchLength = int32(d.width)
if d.height > d.width {
d.batchLength = int32(d.height)
}
d.batchLength += d.batchLength & 1
// Reset the device
d.resetPin.Out(gpio.High)
time.Sleep(500 * time.Millisecond)
d.resetPin.Out(gpio.Low)
time.Sleep(500 * time.Millisecond)
d.resetPin.Out(gpio.High)
time.Sleep(500 * time.Millisecond)
// Common initialization
d.sendCommand(0x11)
time.Sleep(150 * time.Millisecond)
d.sendCommand(0x36, 0x00)
d.sendCommand(0x3A, 0x05)
d.sendCommand(0xB2, 0x0C, 0x0C)
d.sendCommand(0xB7, 0x35)
d.sendCommand(0xBB, 0x1A)
d.sendCommand(0xC0, 0x2C)
d.sendCommand(0xC2, 0x01)
d.sendCommand(0xC3, 0x0B)
d.sendCommand(0xC4, 0x20)
d.sendCommand(0xC6, 0x0F)
d.sendCommand(0xD0, 0xA4, 0xA1)
d.sendCommand(0x21)
d.sendCommand(ST7789_MADCTL, 0x78)
d.sendCommand(0xE0, 0x00, 0x19, 0x1E, 0x0A, 0x09, 0x15, 0x3D, 0x44, 0x51, 0x12, 0x03, 0x00, 0x3F, 0x3F)
d.sendCommand(0xE1, 0x00,
0x18,
0x1E,
0x0A,
0x09,
0x25,
0x3F,
0x43,
0x52,
0x33,
0x03,
0x00,
0x3F,
0x3F)
d.sendCommand(0x29)
time.Sleep(100 * time.Millisecond)
d.blPin.Out(gpio.High) // Backlight ON
}
// Sync waits for the display to hit the next VSYNC pause
func (d *Device) Sync() {
d.SyncToScanLine(0)
}
// SyncToScanLine waits for the display to hit a specific scanline
//
// A scanline value of 0 will forward to the beginning of the next VSYNC,
// even if the display is currently in a VSYNC pause.
//
// Syncline values appear to increment once for every two vertical
// lines on the display.
//
// NOTE: Use GetHighestScanLine and GetLowestScanLine to obtain the highest
// and lowest useful values. Values are affected by front and back porch
// vsync settings (derived from VSyncLines configuration option).
func (d *Device) SyncToScanLine(scanline uint16) {
scan := d.GetScanLine()
// Sometimes GetScanLine returns erroneous 0 on first call after draw, so double check
if scan == 0 {
scan = d.GetScanLine()
}
if scanline == 0 {
// we dont know where we are in an ongoing vsync so go around
for scan < 1 {
time.Sleep(1 * time.Millisecond)
scan = d.GetScanLine()
}
for scan > 0 {
scan = d.GetScanLine()
}
} else {
// go around unless we're very close to the target
for scan > scanline+4 {
time.Sleep(1 * time.Millisecond)
scan = d.GetScanLine()
}
for scan < scanline {
scan = d.GetScanLine()
}
}
}
func (d *Device) Backlight(on bool) error {
return d.blPin.Out(gpio.Level(on))
}
// GetScanLine reads the current scanline value from the display
func (d *Device) GetScanLine() uint16 {
data := []uint8{0x00, 0x00}
//d.Rx(GSCAN, data)
return uint16(data[0])<<8 + uint16(data[1])
}
// GetHighestScanLine calculates the last scanline id in the frame before VSYNC pause
func (d *Device) GetHighestScanLine() uint16 {
// Last scanline id appears to be backporch/2 + 320/2
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 160
}
// GetLowestScanLine calculate the first scanline id to appear after VSYNC pause
func (d *Device) GetLowestScanLine() uint16 {
// First scanline id appears to be backporch/2 + 1
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 1
}
// Display does nothing, there's no buffer as it might be too big for some boards
func (d *Device) Display() error {
return nil
}
// SetPixel sets a pixel in the screen
func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
if x < 0 || y < 0 ||
(((d.rotation == NO_ROTATION || d.rotation == ROTATION_180) && (x >= d.width || y >= d.height)) ||
((d.rotation == ROTATION_90 || d.rotation == ROTATION_270) && (x >= d.height || y >= d.width))) {
return
}
d.FillRectangle(x, y, 1, 1, c)
}
// setWindow prepares the screen to be modified at a given rectangle
func (d *Device) setWindow(x, y, w, h int16) {
x0 := x + d.columnOffset
y0 := y + d.rowOffset
x1 := x + w - 1
y1 := y + h - 1
d.sendCommand(ST7789_CASET, byte(x0>>8), byte(x0), byte(x1>>8), byte(x1))
d.sendCommand(ST7789_RASET, byte(y0>>8), byte(y0), byte(y1>>8), byte(y1))
d.sendCommand(ST7789_RAMWR)
}
// FillRectangle fills a rectangle at a given coordinates with a color
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
k, i := d.size()
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= k || (x+width) > k || y >= i || (y+height) > i {
return errors.New("rectangle coordinates outside display area")
}
d.setWindow(x, y, width, height)
c565 := RGBATo565(c)
c1 := uint8(c565 >> 8)
c2 := uint8(c565)
data := make([]uint8, d.batchLength*2)
for i := int32(0); i < d.batchLength; i++ {
data[i*2] = c1
data[i*2+1] = c2
}
j := int32(width) * int32(height)
for j > 0 {
if j >= d.batchLength {
d.sendData(data)
} else {
d.sendData(data[:j*2])
}
j -= d.batchLength
}
return nil
}
// FillRectangleWithBuffer fills buffer with a rectangle at a given coordinates.
func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
i, j := d.size()
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= i || (x+width) > i || y >= j || (y+height) > j {
return errors.New("rectangle coordinates outside display area")
}
if int32(width)*int32(height) != int32(len(buffer)) {
return errors.New("buffer length does not match with rectangle size")
}
d.setWindow(x, y, width, height)
k := int32(width) * int32(height)
data := make([]uint8, d.batchLength*2)
offset := int32(0)
for k > 0 {
for i := int32(0); i < d.batchLength; i++ {
if offset+i < int32(len(buffer)) {
c565 := RGBATo565(buffer[offset+i])
c1 := uint8(c565 >> 8)
c2 := uint8(c565)
data[i*2] = c1
data[i*2+1] = c2
}
}
if k >= d.batchLength {
d.sendData(data)
} else {
d.sendData(data[:k*2])
}
k -= d.batchLength
offset += d.batchLength
}
return nil
}
// DrawFastVLine draws a vertical line faster than using SetPixel
func (d *Device) DrawFastVLine(x, y0, y1 int16, c color.RGBA) {
if y0 > y1 {
y0, y1 = y1, y0
}
d.FillRectangle(x, y0, 1, y1-y0+1, c)
}
// DrawFastHLine draws a horizontal line faster than using SetPixel
func (d *Device) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
if x0 > x1 {
x0, x1 = x1, x0
}
d.FillRectangle(x0, y, x1-x0+1, 1, c)
}
// FillScreen fills the screen with a given color
func (d *Device) FillScreen(c color.RGBA) {
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
d.FillRectangle(0, 0, d.width, d.height, c)
} else {
d.FillRectangle(0, 0, d.height, d.width, c)
}
}
// SetRotation changes the rotation of the device (clock-wise)
func (d *Device) SetRotation(rotation display.Rotation) {
/*
madctl := uint8(0)
switch rotation % 4 {
case 0:
madctl = MADCTL_MX | MADCTL_MY
d.rowOffset = d.rowOffsetCfg
d.columnOffset = d.columnOffsetCfg
break
case 1:
madctl = MADCTL_MY | MADCTL_MV
d.rowOffset = d.columnOffsetCfg
d.columnOffset = d.rowOffsetCfg
break
case 2:
d.rowOffset = 0
d.columnOffset = 0
break
case 3:
madctl = MADCTL_MX | MADCTL_MV
d.rowOffset = 0
d.columnOffset = 0
break
}
if d.isBGR {
madctl |= MADCTL_BGR
}
d.sendCommand(ST7789_MADCTL, madctl)
*/
}
// Rx reads data from the display
func (d *Device) Rx(command uint8, data []byte) {
d.dcPin.Out(gpio.Low)
sendCommand(d.conn, command)
d.dcPin.Out(gpio.High)
for i := range data {
data[i], _ = sendCommand(d.conn, 0xFF)
}
}
func sendCommand(bus spi.Conn, command byte) (byte, error) {
answer := []byte{0}
err := bus.Tx(
[]byte{command},
[]byte(""),
)
if err != nil {
return 0, err
}
return answer[0], nil
}
// Size returns the current size of the display.
func (d *Device) size() (w, h int16) {
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
return d.width, d.height
}
return d.height, d.width
}
// EnableBacklight enables or disables the backlight
func (d *Device) EnableBacklight(enable bool) {
if enable {
d.blPin.Out(gpio.High)
} else {
d.blPin.Out(gpio.Low)
}
}
// InvertColors inverts the colors of the screen
func (d *Device) InvertColors(invert bool) {
if invert {
d.sendCommand(ST7789_INVON)
} else {
d.sendCommand(ST7789_INVOFF)
}
}
// IsBGR changes the color mode (RGB/BGR)
func (d *Device) IsBGR(bgr bool) {
d.isBGR = bgr
}
// SetScrollArea sets an area to scroll with fixed top and bottom parts of the display.
func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) {
d.sendCommand(ST7789_VSCRDEF,
uint8(topFixedArea>>8), uint8(topFixedArea),
uint8(d.height-topFixedArea-bottomFixedArea>>8), uint8(d.height-topFixedArea-bottomFixedArea),
uint8(bottomFixedArea>>8), uint8(bottomFixedArea))
}
// SetScroll sets the vertical scroll address of the display.
func (d *Device) SetScroll(line int16) {
d.sendCommand(ST7789_VSCRSADD, uint8(line>>8), uint8(line))
}
// StopScroll returns the display to its normal state.
func (d *Device) StopScroll() {
d.sendCommand(ST7789_NORON)
}
// RGBATo565 converts a color.RGBA to uint16 used in the display
func RGBATo565(c color.RGBA) uint16 {
r, g, b, _ := c.RGBA()
return uint16((r & 0xF800) +
((g & 0xFC00) >> 5) +
((b & 0xF800) >> 11))
}
func (d *Device) At(x, y int) color.Color {
return color.Black
}
func (d *Device) Bounds() image.Rectangle {
if d.rotation == display.Rotate90 || d.rotation == display.Rotate270 {
return image.Rect(0, 0, int(d.height), int(d.width))
}
return image.Rect(0, 0, int(d.width), int(d.height))
}
func (d *Device) Clear() {
d.FillRectangle(0, 0, d.width, d.height, color.RGBA{A: 0xff})
}
func (Device) ColorModel() color.Model {
return color.RGBAModel
}
func (d *Device) Fill(c color.Color) error {
rgba := color.RGBAModel.Convert(c).(color.RGBA)
d.FillRectangle(0, 0, d.width, d.height, rgba)
return nil
}
func (d *Device) sendData(data []byte) (err error) {
if err = d.dcPin.Out(gpio.High); err != nil {
return
}
return d.conn.Tx(data, nil)
}
func (d *Device) sendCommand(cmd byte, args ...byte) (err error) {
if err = d.dcPin.Out(gpio.Low); err != nil {
return
}
if err = d.conn.Tx([]byte{cmd}, nil); err != nil {
return
}
if len(args) > 0 {
return d.sendData(args)
}
return
}
func (d *Device) Set(x, y int, c color.Color) {
var (
rc = RGBATo565(color.RGBAModel.Convert(c).(color.RGBA))
xo = x + int(d.columnOffset)
yo = y + int(d.rowOffset)
)
d.sendCommand(0x2A, byte(xo>>8), byte(xo), byte(xo>>8), byte(xo)) // column addr
d.sendCommand(0x2B, byte(yo>>8), byte(yo), byte(yo>>8), byte(yo)) // row addr
d.sendCommand(0x2C, byte(rc>>8), byte(rc)) // pixel
}
func (d *Device) Size() image.Point {
if d.rotation == display.Rotate90 || d.rotation == display.Rotate270 {
return image.Pt(int(d.height), int(d.width))
}
return image.Pt(int(d.width), int(d.height))
}
func (Device) Type() string {
return "st7789"
}
func (d *Device) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
//draw.Draw(d, r, src, sp, draw.Src)
logrus.Warnf("make slice %d (%dx%d)", d.height*d.width, d.height, d.width)
var (
buffer = make([]color.RGBA, int(d.height)*int(d.width))
bounds = src.Bounds()
)
for y := 0; y < bounds.Max.Y && y < int(d.height); y++ {
for x := 0; x < bounds.Max.X && x < int(d.width); x++ {
r, g, b, a := src.At(x, y).RGBA()
buffer[y*int(d.width)+x] = color.RGBA{R: uint8(r / 0x100), G: uint8(g / 0x100), B: uint8(b / 0x100), A: uint8(a / 0x100)}
}
}
return d.FillRectangleWithBuffer(0, 0, d.width, d.height, buffer)
}
func (Device) Halt() error {
return nil
}
func (Device) Refresh() error {
return nil
}
+96
View File
@@ -0,0 +1,96 @@
package st7789
// Registers
const (
NOP = 0x00
SWRESET = 0x01
RDDID = 0x04
RDDST = 0x09
SLPIN = 0x10
SLPOUT = 0x11
PTLON = 0x12
NORON = 0x13
INVOFF = 0x20
INVON = 0x21
DISPOFF = 0x28
DISPON = 0x29
CASET = 0x2A
RASET = 0x2B
RAMWR = 0x2C
RAMRD = 0x2E
PTLAR = 0x30
COLMOD = 0x3A
MADCTL = 0x36
MADCTL_MY = 0x80
MADCTL_MX = 0x40
MADCTL_MV = 0x20
MADCTL_ML = 0x10
MADCTL_RGB = 0x00
MADCTL_BGR = 0x08
MADCTL_MH = 0x04
RDID1 = 0xDA
RDID2 = 0xDB
RDID3 = 0xDC
RDID4 = 0xDD
FRMCTR1 = 0xB1
RGBCTRL = 0xB1
FRMCTR2 = 0xB2
PORCTRL = 0xB2
FRMCTR3 = 0xB3
INVCTR = 0xB4
DISSET5 = 0xB6
PWCTR1 = 0xC0
PWCTR2 = 0xC1
PWCTR3 = 0xC2
PWCTR4 = 0xC3
PWCTR5 = 0xC4
VMCTR1 = 0xC5
FRCTRL2 = 0xC6
PWCTR6 = 0xFC
GMCTRP1 = 0xE0
GMCTRN1 = 0xE1
GSCAN = 0x45
VSCRDEF = 0x33
VSCRSADD = 0x37
)
const (
MAX_VSYNC_SCANLINES = 254
defaultWidth = 240
defaultHeight = 240
)
const (
// Allowable frame rate codes for FRCTRL2 (Identifier is in Hz)
FrameRate111 FrameRate = 0x01
FrameRate105 FrameRate = 0x02
FrameRate99 FrameRate = 0x03
FrameRate94 FrameRate = 0x04
FrameRate90 FrameRate = 0x05
FrameRate86 FrameRate = 0x06
FrameRate82 FrameRate = 0x07
FrameRate78 FrameRate = 0x08
FrameRate75 FrameRate = 0x09
FrameRate72 FrameRate = 0x0A
FrameRate69 FrameRate = 0x0B
FrameRate67 FrameRate = 0x0C
FrameRate64 FrameRate = 0x0D
FrameRate62 FrameRate = 0x0E
FrameRate60 FrameRate = 0x0F // 60 is default
FrameRate58 FrameRate = 0x10
FrameRate57 FrameRate = 0x11
FrameRate55 FrameRate = 0x12
FrameRate53 FrameRate = 0x13
FrameRate52 FrameRate = 0x14
FrameRate50 FrameRate = 0x15
FrameRate49 FrameRate = 0x16
FrameRate48 FrameRate = 0x17
FrameRate46 FrameRate = 0x18
FrameRate45 FrameRate = 0x19
FrameRate44 FrameRate = 0x1A
FrameRate43 FrameRate = 0x1B
FrameRate42 FrameRate = 0x1C
FrameRate41 FrameRate = 0x1D
FrameRate40 FrameRate = 0x1E
FrameRate39 FrameRate = 0x1F
)
+586
View File
@@ -0,0 +1,586 @@
// Package st7789 provides a driver for Sitronix ST7789 IPS TFT displays.
package st7789
import (
"errors"
"fmt"
"image"
"image/color"
"time"
"github.com/sirupsen/logrus"
"go.maze.io/harmon/config"
"go.maze.io/harmon/hardware"
"go.maze.io/harmon/hardware/display"
"periph.io/x/conn/v3/gpio"
)
func init() {
display.Register("st7789", newDriver)
}
// FrameRate controls the frame rate used by the display.
type FrameRate uint8
// Driver wraps an SPI connection.
type Driver struct {
conn display.Conn
//dcPin gpio.PinOut
//csPin gpio.PinOut
resetPin gpio.PinOut
blPin gpio.PinOut
width int16
height int16
columnOffsetCfg int16
rowOffsetCfg int16
columnOffset int16
rowOffset int16
rotation display.Rotation
frameRate FrameRate
batchLength int32
isBGR bool
vSyncLines int16
}
// Config is the configuration for the display
type Config struct {
Width int16
Height int16
Rotation display.Rotation
RowOffset int16
ColumnOffset int16
FrameRate FrameRate
VSyncLines int16
}
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
var (
opts *display.Options
conn display.Conn
err error
)
if opts, err = display.ParseOptions(config, defaultWidth, defaultHeight); err != nil {
return nil, err
}
var reset, bl gpio.PinOut
if bl, err = hardware.LookupPin(config.BL); err != nil {
return nil, err
}
if reset, err = hardware.LookupPin(config.Reset); err != nil {
return nil, err
}
log := logrus.WithFields(logrus.Fields{
"type": "st7789",
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
"rotate": opts.Rotate,
})
log.Debug("new driver")
if conn, err = display.OpenSPI(config.Port, config.Reset, config.DC); err != nil {
return nil, err
}
d := &Driver{
conn: conn,
blPin: bl,
resetPin: reset,
}
if err = d.Configure(Config{
Width: int16(opts.W),
Height: int16(opts.H),
Rotation: opts.Rotate,
}); err != nil {
return nil, err
}
return d, nil
}
// New creates a new ST7789 connection. The SPI wire must already be configured.
func New(conn display.Conn, resetPin, blPin gpio.PinOut) Driver {
return Driver{
conn: conn,
resetPin: resetPin,
blPin: blPin,
}
}
// Configure initializes the display with default configuration
func (d *Driver) Configure(cfg Config) error {
if cfg.Width != 0 {
d.width = cfg.Width
} else {
d.width = 240
}
if cfg.Height != 0 {
d.height = cfg.Height
} else {
d.height = 240
}
d.rotation = cfg.Rotation
d.rowOffsetCfg = cfg.RowOffset
d.columnOffsetCfg = cfg.ColumnOffset
if cfg.FrameRate != 0 {
d.frameRate = cfg.FrameRate
} else {
d.frameRate = FrameRate60
}
if cfg.VSyncLines >= 2 && cfg.VSyncLines <= 254 {
d.vSyncLines = cfg.VSyncLines
} else {
d.vSyncLines = 16
}
d.batchLength = int32(d.width)
if d.height > d.width {
d.batchLength = int32(d.height)
}
d.batchLength += d.batchLength & 1
// Reset the device
d.resetPin.Out(gpio.High)
time.Sleep(500 * time.Millisecond)
d.resetPin.Out(gpio.Low)
time.Sleep(500 * time.Millisecond)
d.resetPin.Out(gpio.High)
time.Sleep(500 * time.Millisecond)
// Common initialization
d.Command(SWRESET) // Soft reset
time.Sleep(150 * time.Millisecond) //
d.Command(SLPOUT) // Exit sleep mode
time.Sleep(500 * time.Millisecond) //
// Memory initialization
d.Command(COLMOD) // Set color mode
d.Data(0x55) // 16-bit color
time.Sleep(10 * time.Millisecond) //
d.SetRotation(d.rotation) // Memory orientation
d.setWindow(0, 0, d.width, d.height) // Full draw window
d.FillScreen(color.RGBA{0, 0, 0, 255}) // Clear screen
// Framerate
d.Command(FRCTRL2) // Frame rate for normal mode
d.Data(uint8(d.frameRate)) // Default is 60Hz
// Frame vertical sync and "porch"
//
// Front and back porch controls vertical scanline sync time before and after
// a frame, where memory can be safely written without tearing.
//
fp := uint8(d.vSyncLines / 2) // Split the desired pause half and half
bp := uint8(d.vSyncLines - int16(fp)) // between front and back porch.
d.Command(PORCTRL)
d.Data(bp) // Back porch 5bit (0x7F max 0x08 default)
d.Data(fp) // Front porch 5bit (0x7F max 0x08 default)
d.Data(0x00) // Seprarate porch (TODO: what is this?)
d.Data(0x22) // Idle mode porch (4bit-back 4bit-front 0x22 default)
d.Data(0x22) // Partial mode porch (4bit-back 4bit-front 0x22 default)
// Ready to display
d.Command(INVON) // Inversion ON
time.Sleep(10 * time.Millisecond) //
d.Command(NORON) // Normal mode ON
time.Sleep(10 * time.Millisecond) //
d.Command(DISPON) // Screen ON
time.Sleep(10 * time.Millisecond) //
d.blPin.Out(gpio.High) // Backlight ON
return nil
}
/*
// Sync waits for the display to hit the next VSYNC pause
func (d *Driver) Sync() {
d.SyncToScanLine(0)
}
// SyncToScanLine waits for the display to hit a specific scanline
//
// A scanline value of 0 will forward to the beginning of the next VSYNC,
// even if the display is currently in a VSYNC pause.
//
// Syncline values appear to increment once for every two vertical
// lines on the display.
//
// NOTE: Use GetHighestScanLine and GetLowestScanLine to obtain the highest
// and lowest useful values. Values are affected by front and back porch
// vsync settings (derived from VSyncLines configuration option).
func (d *Driver) SyncToScanLine(scanline uint16) {
scan := d.GetScanLine()
// Sometimes GetScanLine returns erroneous 0 on first call after draw, so double check
if scan == 0 {
scan = d.GetScanLine()
}
if scanline == 0 {
// we dont know where we are in an ongoing vsync so go around
for scan < 1 {
time.Sleep(1 * time.Millisecond)
scan = d.GetScanLine()
}
for scan > 0 {
scan = d.GetScanLine()
}
} else {
// go around unless we're very close to the target
for scan > scanline+4 {
time.Sleep(1 * time.Millisecond)
scan = d.GetScanLine()
}
for scan < scanline {
scan = d.GetScanLine()
}
}
}
// GetScanLine reads the current scanline value from the display
func (d *Driver) GetScanLine() uint16 {
data := []uint8{0x00, 0x00}
d.conn.Rx(GSCAN, data)
return uint16(data[0])<<8 + uint16(data[1])
}
// GetHighestScanLine calculates the last scanline id in the frame before VSYNC pause
func (d *Driver) GetHighestScanLine() uint16 {
// Last scanline id appears to be backporch/2 + 320/2
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 160
}
// GetLowestScanLine calculate the first scanline id to appear after VSYNC pause
func (d *Driver) GetLowestScanLine() uint16 {
// First scanline id appears to be backporch/2 + 1
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 1
}
*/
// Refresh does nothing, there's no buffer as it might be too big for some boards
func (d *Driver) Refresh() error {
return nil
}
// SetPixel sets a pixel in the screen
func (d *Driver) SetPixel(x int16, y int16, c color.RGBA) {
if x < 0 || y < 0 ||
(((d.rotation == display.NoRotation || d.rotation == display.Rotate180) && (x >= d.width || y >= d.height)) ||
((d.rotation == display.Rotate90 || d.rotation == display.Rotate270) && (x >= d.height || y >= d.width))) {
return
}
d.FillRectangle(x, y, 1, 1, c)
}
// setWindow prepares the screen to be modified at a given rectangle
func (d *Driver) setWindow(x, y, w, h int16) {
x += d.columnOffset
y += d.rowOffset
d.conn.Tx([]uint8{CASET}, true)
d.conn.Tx([]uint8{uint8(x >> 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1)}, false)
d.conn.Tx([]uint8{RASET}, true)
d.conn.Tx([]uint8{uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1)}, false)
d.Command(RAMWR)
}
func (d *Driver) Clear() {
d.FillRectangle(0, 0, d.width, d.height, color.RGBA{})
}
// FillRectangle fills a rectangle at a given coordinates with a color
func (d *Driver) FillRectangle(x, y, width, height int16, c color.RGBA) error {
k, i := int16(d.Size().X), int16(d.Size().Y)
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= k || (x+width) > k || y >= i || (y+height) > i {
return errors.New("rectangle coordinates outside display area")
}
d.setWindow(x, y, width, height)
c565 := RGBATo565(c)
c1 := uint8(c565 >> 8)
c2 := uint8(c565)
data := make([]uint8, d.batchLength*2)
for i := int32(0); i < d.batchLength; i++ {
data[i*2] = c1
data[i*2+1] = c2
}
j := int32(width) * int32(height)
for j > 0 {
if j >= d.batchLength {
d.conn.Tx(data, false)
} else {
d.conn.Tx(data[:j*2], false)
}
j -= d.batchLength
}
return nil
}
// FillRectangleWithBuffer fills buffer with a rectangle at a given coordinates.
func (d *Driver) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
i, j := int16(d.Size().X), int16(d.Size().Y)
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= i || (x+width) > i || y >= j || (y+height) > j {
return errors.New("rectangle coordinates outside display area")
}
if int32(width)*int32(height) != int32(len(buffer)) {
return errors.New("buffer length does not match with rectangle size")
}
d.setWindow(x, y, width, height)
k := int32(width) * int32(height)
data := make([]uint8, d.batchLength*2)
offset := int32(0)
for k > 0 {
for i := int32(0); i < d.batchLength; i++ {
if offset+i < int32(len(buffer)) {
c565 := RGBATo565(buffer[offset+i])
c1 := uint8(c565 >> 8)
c2 := uint8(c565)
data[i*2] = c1
data[i*2+1] = c2
}
}
if k >= d.batchLength {
d.conn.Tx(data, false)
//d.Tx(data, false)
} else {
d.conn.Tx(data[:k*2], false)
//d.Tx(data[:k*2], false)
}
k -= d.batchLength
offset += d.batchLength
}
return nil
}
// DrawFastVLine draws a vertical line faster than using SetPixel
func (d *Driver) DrawFastVLine(x, y0, y1 int16, c color.RGBA) {
if y0 > y1 {
y0, y1 = y1, y0
}
d.FillRectangle(x, y0, 1, y1-y0+1, c)
}
// DrawFastHLine draws a horizontal line faster than using SetPixel
func (d *Driver) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
if x0 > x1 {
x0, x1 = x1, x0
}
d.FillRectangle(x0, y, x1-x0+1, 1, c)
}
// FillScreen fills the screen with a given color
func (d *Driver) FillScreen(c color.RGBA) {
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
d.FillRectangle(0, 0, d.width, d.height, c)
} else {
d.FillRectangle(0, 0, d.height, d.width, c)
}
}
// SetRotation changes the rotation of the device (clock-wise)
func (d *Driver) SetRotation(rotation display.Rotation) {
madctl := uint8(0)
switch rotation % 4 {
case display.NoRotation:
madctl = MADCTL_MX | MADCTL_MY
d.rowOffset = d.rowOffsetCfg
d.columnOffset = d.columnOffsetCfg
break
case display.Rotate90:
madctl = MADCTL_MY | MADCTL_MV
d.rowOffset = d.columnOffsetCfg
d.columnOffset = d.rowOffsetCfg
break
case display.Rotate180:
d.rowOffset = 0
d.columnOffset = 0
break
case display.Rotate270:
madctl = MADCTL_MX | MADCTL_MV
d.rowOffset = 0
d.columnOffset = 0
break
}
if d.isBGR {
madctl |= MADCTL_BGR
}
d.Command(MADCTL)
d.Data(madctl)
}
// Command sends a command to the display.
func (d *Driver) Command(command uint8) error {
//d.Tx([]byte{command}, true)
return d.conn.Tx([]byte{command}, true)
}
// Data sends data to the display.
func (d *Driver) Data(data uint8) error {
//d.Tx([]byte{data}, false)
return d.conn.Tx([]byte{data}, false)
}
// Tx sends data to the display
/*
func (d *Driver) Tx(data []byte, isCommand bool) {
if isCommand {
d.dcPin.Out(gpio.Low)
} else {
d.dcPin.Out(gpio.High)
}
d.csPin.Out(gpio.Low)
d.bus.Tx(data, nil)
d.csPin.Out(gpio.High)
}
// Rx reads data from the display
func (d *Driver) Rx(command uint8, data []byte) {
d.dcPin.Out(gpio.Low)
d.csPin.Out(gpio.Low)
sendCommand(d.bus, command)
d.dcPin.Out(gpio.High)
for i := range data {
data[i], _ = sendCommand(d.bus, 0xFF)
}
d.csPin.Out(gpio.High)
}
func sendCommand(bus spi.Conn, command byte) (byte, error) {
answer := []byte{0}
err := bus.Tx(
[]byte{command},
[]byte(""),
)
if err != nil {
return 0, err
}
return answer[0], nil
}
*/
// Size returns the current size of the display.
/*
func (d *Driver) Size() (w, h int16) {
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
return d.width, d.height
}
return d.height, d.width
}
*/
// EnableBacklight enables or disables the backlight
func (d *Driver) EnableBacklight(enable bool) {
if enable {
d.blPin.Out(gpio.High)
} else {
d.blPin.Out(gpio.Low)
}
}
// InvertColors inverts the colors of the screen
func (d *Driver) InvertColors(invert bool) {
if invert {
d.Command(INVON)
} else {
d.Command(INVOFF)
}
}
// IsBGR changes the color mode (RGB/BGR)
func (d *Driver) IsBGR(bgr bool) {
d.isBGR = bgr
}
// SetScrollArea sets an area to scroll with fixed top and bottom parts of the display.
func (d *Driver) SetScrollArea(topFixedArea, bottomFixedArea int16) {
d.Command(VSCRDEF)
d.conn.Tx([]uint8{
uint8(topFixedArea >> 8), uint8(topFixedArea),
uint8(d.height - topFixedArea - bottomFixedArea>>8), uint8(d.height - topFixedArea - bottomFixedArea),
uint8(bottomFixedArea >> 8), uint8(bottomFixedArea)},
false)
}
// SetScroll sets the vertical scroll address of the display.
func (d *Driver) SetScroll(line int16) {
d.Command(VSCRSADD)
d.conn.Tx([]uint8{uint8(line >> 8), uint8(line)}, false)
}
// StopScroll returns the display to its normal state.
func (d *Driver) StopScroll() {
d.Command(NORON)
}
// RGBATo565 converts a color.RGBA to uint16 used in the display
func RGBATo565(c color.RGBA) uint16 {
r, g, b, _ := c.RGBA()
return uint16((r & 0xF800) +
((g & 0xFC00) >> 5) +
((b & 0xF800) >> 11))
}
/* hardware.Display interface methods */
func (Driver) Type() string {
return "st7789"
}
func (d *Driver) At(x, y int) color.Color {
return color.Black // not supported!
}
func (d *Driver) Bounds() image.Rectangle {
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
return image.Rect(0, 0, int(d.width), int(d.height))
}
return image.Rect(0, 0, int(d.height), int(d.width))
}
func (d *Driver) ColorModel() color.Model {
return color.RGBAModel
}
func (d *Driver) Fill(c color.Color) error {
return d.FillRectangle(0, 0, d.width, d.height, color.RGBAModel.Convert(c).(color.RGBA))
}
func (d *Driver) Halt() error {
return nil
}
func (d *Driver) Set(x, y int, c color.Color) {
d.SetPixel(int16(x), int16(y), color.RGBAModel.Convert(c).(color.RGBA))
}
func (d *Driver) Size() image.Point {
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
return image.Pt(int(d.width), int(d.height))
}
return image.Pt(int(d.height), int(d.width))
}
func (d *Driver) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
var buffer []color.RGBA
for y := r.Min.Y; y < r.Max.Y; y++ {
for x := r.Min.X; x < r.Max.X; x++ {
buffer = append(buffer, color.RGBAModel.Convert(src.At(x, y)).(color.RGBA))
}
}
return d.FillRectangleWithBuffer(int16(sp.X), int16(sp.Y), int16(r.Dx()), int16(r.Dy()), buffer)
}
+48
View File
@@ -0,0 +1,48 @@
package display
import (
"fmt"
"image"
"image/color"
"go.maze.io/harmon/hardware"
)
// View is a (partial) view on the display.
type View struct {
hardware.Display
Window image.Rectangle
}
func MakeView(display hardware.Display, window image.Rectangle) View {
return View{
Display: display,
Window: window,
}
}
func (d View) Type() string {
return fmt.Sprintf("view:%s:%s", d.Display.Type(), d.Window)
}
func (d View) Size() image.Point {
return d.Window.Size()
}
func (d View) At(x, y int) color.Color {
if x < 0 || y < 0 || x >= d.Window.Dx() || y >= d.Window.Dy() {
return d.Display.ColorModel().Convert(color.Black)
}
x -= d.Window.Min.X
y -= d.Window.Min.Y
return d.Display.At(x, y)
}
func (d View) Set(x, y int, c color.Color) {
if x < 0 || y < 0 || x >= d.Window.Dx() || y >= d.Window.Dy() {
return
}
x -= d.Window.Min.X
y -= d.Window.Min.Y
d.Display.Set(x, y, c)
}
+28
View File
@@ -0,0 +1,28 @@
package hardware
import "time"
type Input interface {
Events() <-chan InputEvent
}
type InputEvent interface {
}
type (
RotaryEvent struct {
Time time.Time
Input Input
Delta int
}
RotaryPressEvent struct {
Time time.Time
Input Input
}
RotaryLongPressEvent struct {
Time time.Time
Input Input
}
)
+46
View File
@@ -0,0 +1,46 @@
package input
import (
"fmt"
"go.maze.io/harmon/config"
"go.maze.io/harmon/hardware"
"periph.io/x/conn/v3/gpio"
)
type Encoder interface {
hardware.Driver
Events() (<-chan hardware.InputEvent, error)
}
func NewEncoder(config config.Encoder) (Encoder, error) {
switch config.Type {
case "input":
return newDevInputEncoder(config.Switch)
case "gpio":
return newGPIOEncoder(config.CW, config.CCW, config.Switch)
default:
return nil, fmt.Errorf("unsupported encoder type %q", config.Type)
}
}
type gpioEncoder struct {
cw, ccw, click gpio.PinIn
}
func newGPIOEncoder(cw, ccw, click string) (enc Encoder, err error) {
e := new(gpioEncoder)
if e.cw, err = hardware.LookupPin(cw); err != nil {
return
}
if e.ccw, err = hardware.LookupPin(ccw); err != nil {
return
}
if e.click, err = hardware.LookupPin(click); err != nil {
return
}
return
}
+270
View File
@@ -0,0 +1,270 @@
package input
import (
"encoding/binary"
"errors"
"os"
"path/filepath"
"strings"
"time"
"github.com/sirupsen/logrus"
"go.maze.io/harmon/hardware"
"periph.io/x/conn/v3/gpio"
)
const (
devfsPath = "/dev"
procfsPath = "/proc"
procInputDevices = procfsPath + "/bus/input/devices"
)
type devInputEncoder struct {
path string
click gpio.PinIn
}
func newDevInputEncoder(click string) (enc Encoder, err error) {
e := new(devInputEncoder)
if e.click, err = hardware.LookupPin(click); err != nil {
return
}
var ps []*linuxPheripheral
if ps, err = linuxPheripherals(); err != nil {
return
}
for _, p := range ps {
if strings.HasPrefix(p.name, "rotary@") {
e.path = p.path
return e, nil
}
}
return nil, errors.New("no rotary encoders found in " + procInputDevices)
}
type linuxPheripheral struct {
name string
bus string
vendor string
product string
version string
phys string
path string
}
/*
I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="button@10"
P: Phys=gpio-keys/input0
S: Sysfs=/devices/platform/button@10/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=3
B: KEY=20000 0 0 0
I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="rotary@14"
P: Phys=
S: Sysfs=/devices/platform/rotary@14/input/input1
U: Uniq=
H: Handlers=event1
B: PROP=0
B: EV=5
B: REL=1
*/
func linuxPheripherals() (ps []*linuxPheripheral, err error) {
log := logrus.WithField("input", "linux")
log.Trace("detecting peripherals")
b, err := os.ReadFile(procInputDevices)
if err != nil {
return nil, err
}
for _, segment := range strings.Split(string(b), "\n\n") {
lines := strings.Split(segment, "\n")
perip := new(linuxPheripheral)
for _, line := range lines {
if line == "" {
continue
}
log.WithField("line", line).Trace("parsing line")
switch {
case strings.HasPrefix(line, "I: "):
for _, kv := range strings.Split(strings.TrimPrefix(line, "I: "), " ") {
kv := strings.SplitN(kv, "=", 2)
switch kv[0] {
case "Bus":
case "Vendor":
perip.vendor = kv[1]
case "Product":
perip.product = kv[1]
case "Version":
perip.version = kv[1]
}
}
case strings.HasPrefix(line, "N: Name="):
perip.name = strings.TrimFunc(strings.TrimPrefix(line, "N: Name="), func(r rune) bool { return r == '"' || r == '@' })
case strings.HasPrefix(line, "P: Phys="):
perip.phys = strings.TrimPrefix(line, "P: Phys=")
//case strings.HasPrefix(line, "S: Sysfs="):
// perip.sysfs = filepath.Join(sysfsPath, strings.TrimPrefix(line, "S: Sysfs="), "device")
case strings.HasPrefix(line, "H: Handlers="):
for _, handler := range strings.Split(strings.TrimPrefix(line, "H: Handlers="), " ") {
if strings.HasPrefix(handler, "event") {
perip.path = filepath.Join(devfsPath, "input", handler)
break
}
}
}
}
if perip.path != "" {
log.WithFields(logrus.Fields{
"name": perip.name,
"bus": perip.bus,
"vendor": perip.vendor,
"product": perip.product,
"version": perip.version,
"phys": perip.phys,
"path": perip.path,
}).Trace("found peripheral")
ps = append(ps, perip)
}
}
return ps, nil
}
type linuxInputEvent struct {
Secs uint32
USecs uint32
Type uint16
Code uint16
Value int32
}
func (e linuxInputEvent) Time() time.Time {
return time.Unix(int64(e.Secs), int64(e.USecs))
}
func readLinuxInputEvents(name string, cb func(linuxInputEvent) error) error {
f, err := os.Open(name)
if err != nil {
return err
}
var raw linuxInputEvent
for {
if err := binary.Read(f, binary.LittleEndian, &raw); err != nil {
_ = f.Close()
return err
}
if err := cb(raw); err != nil {
return err
}
}
}
type linuxButton struct {
p *linuxPheripheral
}
func newLinuxButton(p *linuxPheripheral) *linuxButton {
return &linuxButton{p: p}
}
func (s *linuxButton) Name() string {
return s.p.name
}
func (s *linuxButton) Events() (<-chan Event, error) {
log := logrus.
WithField("input", "button").
WithField("path", s.p.path)
log.Debug("opening linux button source")
events := make(chan Event)
go s.readEvents(events)
return events, nil
}
func (s *linuxButton) readEvents(events chan<- Event) {
defer close(events)
log := logrus.
WithField("input", "button").
WithField("path", s.p.path)
err := readLinuxInputEvents(s.p.path, func(ev linuxInputEvent) error {
log.WithField("data", ev).Debug("button event")
if ev.Code == 0 {
return nil // not sure what this is
}
var pressed bool
if ev.Value == 1 {
pressed = true
}
select {
case events <- NewButtonEvent(s, pressed):
default:
log.Warn("dropping event")
}
return nil
})
if err != nil {
log.WithError(err).Error("failed to read events")
}
}
type linuxRotary struct {
p *linuxPheripheral
}
func newLinuxRotary(p *linuxPheripheral) *linuxRotary {
return &linuxRotary{p: p}
}
func (s *linuxRotary) Name() string {
return s.p.name
}
func (s *linuxRotary) Events() (<-chan Event, error) {
log := logrus.
WithField("input", "rotary").
WithField("path", s.p.path)
log.Debug("opening linux rotary source")
events := make(chan Event)
go s.readEvents(events)
return events, nil
}
func (s *linuxRotary) readEvents(events chan<- Event) {
defer close(events)
log := logrus.
WithField("input", "rotary").
WithField("path", s.p.path)
err := readLinuxInputEvents(s.p.path, func(ev linuxInputEvent) error {
log.WithField("data", ev).Debug("rotary event")
select {
case events <- NewRotaryEvent(s, int(ev.Value), ev.Value == 0):
default:
log.Warn("dropping event")
}
return nil
})
if err != nil {
log.WithError(err).Error("failed to read events")
}
}
+9
View File
@@ -0,0 +1,9 @@
//go:build !linux
package input
import "errors"
func newDevInputEncoder(string) (Encoder, error) {
return nil, errors.New("input encoders are only supported in Linux")
}