st7735

package
v0.0.0-...-2e22e3b Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

README

ST7735 driver

There are multiple devices using the ST7735 chip, and there are multiple versions ST7735B, ST7735R & ST7735S. Two apparently identical displays might have different configurations. The most common issues are:

  • Colors are inverted (black is white and viceversa), invert the colors with display.InvertColors(true)
  • Colors are not right (red is blue and viceversa, but green is ok), some displays uses BRG instead of RGB for defining colors, change the mode with display.IsBGR(true)
  • There is noise/snow/confetti in the screen, probably rows and columns offsets are wrong, configure them with st7735.Config{RowOffset:XX, ColumnOffset:YY}

If nothing of the above works, your device may need a different boot-up process.

Documentation

Overview

Package st7735 implements a driver for the ST7735 TFT displays, it comes in various screen sizes.

Datasheet: https://www.crystalfontz.com/controllers/Sitronix/ST7735R/319/

Index

Constants

View Source
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  = drivers.Rotation0
	ROTATION_90  = drivers.Rotation90 // 90 degrees clock-wise rotation
	ROTATION_180 = drivers.Rotation180
	ROTATION_270 = drivers.Rotation270
)

Registers

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color interface {
	pixel.RGB444BE | pixel.RGB565BE

	pixel.BaseColor
}

Pixel formats supported by the st7735 driver.

type Config

type Config struct {
	Width        int16
	Height       int16
	Rotation     drivers.Rotation
	Model        Model
	RowOffset    int16
	ColumnOffset int16
}

Config is the configuration for the display

type Device

type Device = DeviceOf[pixel.RGB565BE]

Device wraps an SPI connection.

func New

func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device

New creates a new ST7735 connection. The SPI wire must already be configured.

type DeviceOf

type DeviceOf[T Color] struct {
	// contains filtered or unexported fields
}

DeviceOf is a generic version of Device, which supports different pixel formats.

func NewOf

func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) DeviceOf[T]

NewOf creates a new ST7735 connection with a particular pixel format. The SPI wire must already be configured.

func (*DeviceOf[T]) Command

func (d *DeviceOf[T]) Command(command uint8)

Command sends a command to the display

func (*DeviceOf[T]) Configure

func (d *DeviceOf[T]) Configure(cfg Config)

Configure initializes the display with default configuration

func (*DeviceOf[T]) Data

func (d *DeviceOf[T]) Data(data uint8)

Command sends a data to the display

func (*DeviceOf[T]) Display

func (d *DeviceOf[T]) Display() error

Display does nothing, there's no buffer as it might be too big for some boards

func (*DeviceOf[T]) DrawBitmap

func (d *DeviceOf[T]) DrawBitmap(x, y int16, bitmap pixel.Image[T]) error

DrawBitmap copies the bitmap to the internal buffer on the screen at the given coordinates. It returns once the image data has been sent completely.

func (*DeviceOf[T]) DrawFastHLine

func (d *DeviceOf[T]) DrawFastHLine(x0, x1, y int16, c color.RGBA)

DrawFastHLine draws a horizontal line faster than using SetPixel

func (*DeviceOf[T]) DrawFastVLine

func (d *DeviceOf[T]) DrawFastVLine(x, y0, y1 int16, c color.RGBA)

DrawFastVLine draws a vertical line faster than using SetPixel

func (*DeviceOf[T]) DrawRGBBitmap8 deprecated

func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error

DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates

Deprecated: use DrawBitmap instead.

func (*DeviceOf[T]) EnableBacklight

func (d *DeviceOf[T]) EnableBacklight(enable bool)

EnableBacklight enables or disables the backlight

func (*DeviceOf[T]) FillRectangle

func (d *DeviceOf[T]) FillRectangle(x, y, width, height int16, c color.RGBA) error

FillRectangle fills a rectangle at a given coordinates with a color

func (*DeviceOf[T]) FillRectangleWithBuffer

func (d *DeviceOf[T]) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error

FillRectangle fills a rectangle at a given coordinates with a buffer

func (*DeviceOf[T]) FillScreen

func (d *DeviceOf[T]) FillScreen(c color.RGBA)

FillScreen fills the screen with a given color

func (*DeviceOf[T]) InvertColors

func (d *DeviceOf[T]) InvertColors(invert bool)

InverColors inverts the colors of the screen

func (*DeviceOf[T]) IsBGR

func (d *DeviceOf[T]) IsBGR(bgr bool)

IsBGR changes the color mode (RGB/BGR)

func (*DeviceOf[T]) Rotation

func (d *DeviceOf[T]) Rotation() drivers.Rotation

Rotation returns the currently configured rotation.

func (*DeviceOf[T]) SetPixel

func (d *DeviceOf[T]) SetPixel(x int16, y int16, c color.RGBA)

SetPixel sets a pixel in the screen

func (*DeviceOf[T]) SetRotation

func (d *DeviceOf[T]) SetRotation(rotation drivers.Rotation) error

SetRotation changes the rotation of the device (clock-wise)

func (*DeviceOf[T]) SetScroll

func (d *DeviceOf[T]) SetScroll(line int16)

SetScroll sets the vertical scroll address of the display.

func (*DeviceOf[T]) SetScrollArea

func (d *DeviceOf[T]) SetScrollArea(topFixedArea, bottomFixedArea int16)

SetScrollWindow sets an area to scroll with fixed top and bottom parts of the display

func (*DeviceOf[T]) Size

func (d *DeviceOf[T]) Size() (w, h int16)

Size returns the current size of the display.

func (*DeviceOf[T]) Sleep

func (d *DeviceOf[T]) Sleep(sleepEnabled bool) error

Set the sleep mode for this LCD panel. When sleeping, the panel uses a lot less power. The LCD won't display an image anymore, but the memory contents will be kept.

func (*DeviceOf[T]) StopScroll

func (d *DeviceOf[T]) StopScroll()

SpotScroll returns the display to its normal state

func (*DeviceOf[T]) Tx

func (d *DeviceOf[T]) Tx(data []byte, isCommand bool)

Tx sends data to the display

type Model

type Model uint8

type Rotation deprecated

type Rotation = drivers.Rotation

Rotation controls the rotation used by the display.

Deprecated: use drivers.Rotation instead.

Jump to

Keyboard shortcuts

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