ST7789 (st7789_elixir v0.1.1) View Source

ST7789 Elixir driver

Link to this section Summary

API

Write a byte to the display as command data.

Write a byte or array of bytes to the display as display data.

Write the provided 24bit RGB888 image to the hardware.

Write the provided 16bit RGB565 image to the hardware.

New connection to an ST7789

Reset the display, if reset pin is connected.

Set backlight status

Link to this section API

Write a byte to the display as command data.

  • self: %ST7789{}
  • cmd: command data

return: self

Write a byte or array of bytes to the display as display data.

  • self: %ST7789{}
  • data: display data

return: self

Link to this function

display(self, image_data)

View Source

Write the provided 24bit RGB888 image to the hardware.

  • self: %ST7789{}
  • image_data: Should be 24bit RGB888 format and the same dimensions (width x height x 3) as the display hardware.

return: self

Link to this function

display_565(self, image_data)

View Source

Write the provided 16bit RGB565 image to the hardware.

  • self: %ST7789{}
  • image_data: Should be 16bit RGB565 format and the same dimensions (width x height x 3) as the display hardware.

return: self

New connection to an ST7789

  • port: SPI port number

    Default value: 0

  • cs: SPI chip-select number (0 or 1 for BCM).

    Default value: 0.

  • backlight: Pin for controlling backlight

    Default value: nil.

  • rst: Reset pin for ST7789

    Default value: nil.

  • width: Width of display connected to ST7789

    Default value: 240.

  • height: Height of display connected to ST7789

    Default value: 240.

  • offset_top: Offset to top row

    Default value: 0.

  • offset_left: Offset to left column

    Default value: 0.

  • invert: Invert display

    Default value: true.

  • speed_hz: SPI speed (in Hz)

    Default value: 400_0000.

return: %ST7789{}

Example

# default
# assuming device at /dev/spidev0.0
# DC connects to BCM 9
# BL not connected
# RST not connected
# SPI speed: 4MHz
disp = ST7789.new()
# specify init arguments
port = 0                      # spi bus 0
cs = 0                        # BCM 8 / CE 0
dc = 9                        # BCM 9
backlight = 17                # BCM 17
speed_hz = 80 * 1000 * 1000   # 80MHz
disp = ST7789.new(port: port, cs: cs, dc: dc, backlight: backlight, speed_hz: speed_hz)

Reset the display, if reset pin is connected.

  • self: %ST7789{}

return: self

Link to this function

send(self, bytes, is_data, chunk_size \\ 4096)

View Source

Send bytes to the ST7789

  • self: %ST7789{}

  • bytes: The bytes to be sent to self

    • when is_integer(bytes), sent will take the 8 least-significant bits [band(bytes, 0xFF)] and send it to self
    • when is_list(bytes), bytes will be casting to bitstring and then sent to self
  • is_data:

    • true: bytes will be sent as data
    • false: bytes will be sent as commands
  • chunk_size: Indicates how many bytes will be send in a single write call

return: self

Link to this function

set_backlight(self, atom)

View Source

Set backlight status

  • self: %ST7789{}
  • status: either :on or :off

return: self

Link to this section Constants