ILI9486 (ili9486_elixir v0.1.6)

View Source

ILI9486 Elixir driver

Summary

Types

Supported source color formats

Parallel data bus mode

Display mode

Division ratio for internal clocks (0=focs, 1=focs/2, 2=focs/4, 3=focs/8)

Supported frame rates (Hz)

Image data buffer accepted by display functions

MADCTL orientation / RGB mode

Supported pixel formats

Screen rotation in degrees

RTNA timing value (0b10000=16 .. 0b11111=31)

t()

Display struct

Callback invoked on touch IRQ

Functions

Returns a specification to start this module under a supervisor.

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 BGR888/RGB888 image to the hardware.

Write the provided 16bit BGR565/RGB565 image to the hardware.

Write the provided 18bit BGR666/RGB666 image to the hardware.

new(opts \\ []) deprecated
new!(opts \\ []) deprecated

Get display pixel format

Reset the display, if reset pin is connected.

Send bytes to the ILI9486

Turn on/off display

Set display pixel format

Set touch panel callback function

Get screen size

Start a new connection to an ILI9486.

Closes all SPI and GPIO resources on shutdown.

Constants

k16BIT_PIX()

k18BIT_PIX()

kCASET()

kDFUNCTR()

kDGCTR1()

kDGCTR2()

kDISPOFF()

kDISPON()

kFRMCTR1()

kFRMCTR2()

kFRMCTR3()

kGAMMASET()

kGMCTRN1()

kGMCTRP1()

kHISPEEDF1()

kHISPEEDF2()

kHISPEEDF8()

kHISPEEDF9()

kIDLEOFF()

kIDLEON()

kINVCTR()

kINVOFF()

kINVON()

kMAD_BGR()

kMAD_RGB()

kMAD_VERTICAL()

kMAD_X_LEFT()

kMAD_X_RIGHT()

kMAD_Y_DOWN()

kMAD_Y_UP()

kMADCTL()

kNOP()

kNORON()

kPASET()

kPIXFMT()

kPTLAR()

kPTLON()

kPWCTR1()

kPWCTR2()

kPWCTR3()

kPWCTR4()

kPWCTR5()

kRAMRD()

kRAMWR()

kRDDID()

kRDDST()

kRDID1()

kRDID2()

kRDID3()

kRDID4()

kRDIMGFMT()

kRDMADCTL()

kRDMODE()

kRDPIXFMT()

kRDSELFDIAG()

kRGB_INTERFACE()

kSLPIN()

kSLPOUT()

kSWRESET()

kVMCTR1()

kVMCTR2()

kVSCRDEF()

kVSCRSADD()

Types

color_format()

@type color_format() :: :rgb888 | :bgr888

Supported source color formats

data_bus()

@type data_bus() :: :parallel_8bit | :parallel_16bit

Parallel data bus mode

display_mode()

@type display_mode() :: :normal | :partial | :idle

Display mode

diva()

@type diva() :: 0..3

Division ratio for internal clocks (0=focs, 1=focs/2, 2=focs/4, 3=focs/8)

frame_rate()

@type frame_rate() ::
  28 | 30 | 32 | 34 | 36 | 39 | 42 | 46 | 50 | 56 | 62 | 70 | 81 | 96 | 117

Supported frame rates (Hz)

ili9486_option()

@type ili9486_option() ::
  {:port, non_neg_integer()}
  | {:lcd_cs, non_neg_integer()}
  | {:touch_cs, non_neg_integer() | nil}
  | {:touch_irq, non_neg_integer() | nil}
  | {:touch_speed_hz, pos_integer()}
  | {:dc, non_neg_integer()}
  | {:rst, non_neg_integer() | nil}
  | {:width, pos_integer()}
  | {:height, pos_integer()}
  | {:offset_top, non_neg_integer()}
  | {:offset_left, non_neg_integer()}
  | {:speed_hz, pos_integer()}
  | {:pix_fmt, pixel_format()}
  | {:rotation, rotation()}
  | {:mad_mode, mad_mode()}
  | {:display_mode, display_mode()}
  | {:frame_rate, frame_rate()}
  | {:diva, diva()}
  | {:rtna, rtna()}
  | {:is_high_speed, boolean()}
  | {:chunk_size, pos_integer()}
  | {:spi_lcd, any()}
  | {:spi_touch, any()}
  | {:gpio_dc, any()}
  | {:gpio_rst, any()}
  | {:name, GenServer.name()}

Options for start_link/1.

  • :port - SPI port number (default: 0).
  • :lcd_cs - LCD chip select (default: 0).
  • :touch_cs - Touch panel chip select, optional (default: nil).
  • :touch_irq - Touch panel IRQ pin (active low), optional (default: nil).
  • :touch_speed_hz - SPI speed for touch panel (default: 50_000).
  • :dc - D/C pin (default: 24).
  • :rst - Reset pin for ILI9486, optional (default: nil).
  • :width - Display width in pixels (default: 480).
  • :height - Display height in pixels (default: 320).
  • :offset_top - Vertical offset (default: 0).
  • :offset_left - Horizontal offset (default: 0).
  • :speed_hz - SPI speed for LCD (default: 16_000_000).
  • :pix_fmt - Pixel format, one of :bgr565 | :rgb565 | :bgr666 | :rgb666 (default: :bgr565).

  • :rotation - Rotation, one of 0 | 90 | 180 | 270 (default: 90).

  • :mad_mode - MAD mode, one of :right_down | :right_up | :rgb_mode (default: :right_down).

  • :display_mode - Display mode, one of :normal | :partial | :idle (default: :normal).

  • :frame_rate - Frame rate (Hz), one of 28, 30, 32, 34, 36, 39, 42, 46, 50, 56, 62, 70, 81, 96, 117 (default: 70).
  • :diva - Clock division (0 = focs, 1 = focs/2, 2 = focs/4, 3 = focs/8) (default: 0).
  • :rtna - Line period RTNA[4:0], 0b10000 (16) to 0b11111 (31), default 0b10001 (17); each step increases clocks by 1.
  • :is_high_speed - Use high-speed variant (125 MHz SPI) (default: false).
  • :chunk_size - Batch transfer size; default 4096 (lo-speed) or 0x8000 (hi-speed).
  • :spi_lcd - Pre-opened SPI handle for LCD; overrides :port/:lcd_cs when set.
  • :spi_touch - Pre-opened SPI handle for touch; overrides :port/:touch_cs when set.
  • :gpio_dc - Pre-opened GPIO for D/C; overrides :dc when set.
  • :gpio_rst - Pre-opened GPIO for reset; overrides :rst when set.
  • :name - Registered name for the GenServer.

image_data()

@type image_data() :: binary() | [byte() | [byte()]]

Image data buffer accepted by display functions

mad_mode()

@type mad_mode() :: :right_down | :right_up | :rgb_mode

MADCTL orientation / RGB mode

pixel_format()

@type pixel_format() :: :rgb565 | :bgr565 | :rgb666 | :bgr666

Supported pixel formats

rotation()

@type rotation() :: 0 | 90 | 180 | 270

Screen rotation in degrees

rtna()

@type rtna() :: 16..31

RTNA timing value (0b10000=16 .. 0b11111=31)

t()

@type t() :: %ILI9486{
  chunk_size: pos_integer(),
  data_bus: data_bus(),
  display_mode: display_mode(),
  diva: diva(),
  frame_rate: pos_integer(),
  gpio: keyword(),
  lcd_spi: any(),
  mad_mode: mad_mode(),
  opts: keyword(),
  pix_fmt: pixel_format(),
  rotation: rotation(),
  rtna: rtna(),
  touch_pid: pid() | nil,
  touch_spi: any()
}

Display struct

touch_callback()

@type touch_callback() :: GPIOIRQDevice.irq_callback()

Callback invoked on touch IRQ

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

command(self_pid, cmd, opts \\ [])

@spec command(pid(), byte(), Keyword.t()) :: :ok

Write a byte to the display as command data.

  • display: %ILI9486{}
  • cmd: command data
  • opts:
    • cmd_data: cmd data to be sent. Default value: []. (no data will be sent)
    • delay: wait delay ms after the cmd data is sent Default value: 0. (no wait)

return: display

data(self_pid, data)

@spec data(pid(), iodata()) :: :ok

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

  • display: %ILI9486{}
  • data: display data

return: display

display(self_pid, image_data, source_color)

@spec display(pid(), image_data(), color_format()) :: :ok

Write the provided 24bit BGR888/RGB888 image to the hardware.

  • display: %ILI9486{}
  • image_data: Should be 24bit format and the same dimensions (width x height x 3) as the display hardware.
  • pix_fmt: Either :rgb888 or :bgr888. Indicates the channel order of the provided image_data.

return: display

display_565(self_pid, image_data)

@spec display_565(pid(), image_data()) :: :ok

Write the provided 16bit BGR565/RGB565 image to the hardware.

  • display: %ILI9486{}
  • image_data: Should be 16bit BGR565/RGB565 format (same channel order as in display) and the same dimensions (width x height x 3) as the display hardware.

return: display

display_666(self_pid, image_data)

@spec display_666(pid(), image_data()) :: :ok

Write the provided 18bit BGR666/RGB666 image to the hardware.

  • display: %ILI9486{}
  • image_data: Should be 18bit BGR666/RGB666 format (same channel order as in display) and the same dimensions (width x height x 3) as the display hardware.

return: display

new(opts \\ [])

This function is deprecated. Use start_link/1 instead.
@spec new([ili9486_option()]) :: GenServer.on_start()

new!(opts \\ [])

This function is deprecated. Use start_link/1 instead.
@spec new!([ili9486_option()]) :: pid()

pix_fmt(self_pid)

@spec pix_fmt(pid()) :: pixel_format()

Get display pixel format

  • display: %ILI9486{}

return: one of :bgr565, :rgb565, :bgr666, :rgb666

reset(self_pid)

@spec reset(pid()) :: :ok

Reset the display, if reset pin is connected.

  • display: %ILI9486{}

return: display

send(self_pid, bytes, is_data)

@spec send(pid(), integer() | iodata(), boolean()) :: :ok

Send bytes to the ILI9486

  • display: %ILI9486{}

  • bytes: The bytes to be sent to display

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

    • true: bytes will be sent as data
    • false: bytes will be sent as commands

return: display

set_display(self_pid, status)

@spec set_display(pid(), :on | :off) :: :ok

Turn on/off display

  • display: %ILI9486{}
  • status: either :on or :off

return: display

set_display_mode(self_pid, display_mode)

@spec set_display_mode(pid(), display_mode()) :: :ok

Set display mode

  • display: %ILI9486{}
  • display_mode: Valid values: :normal, :partial, :idle

return: display

set_frame_rate(self_pid, frame_rate)

@spec set_frame_rate(pid(), frame_rate()) :: :ok

Set frame rate

  • display: %ILI9486{}
  • frame_rate: Valid value should be one of the following
    • 28
    • 30
    • 32
    • 34
    • 36
    • 39
    • 42
    • 46
    • 50
    • 56
    • 62
    • 70
    • 81
    • 96
    • 117

return: :ok

set_pix_fmt(self_pid, pix_fmt)

@spec set_pix_fmt(pid(), pixel_format()) :: :ok

Set display pixel format

  • display: %ILI9486{}
  • pix_fmt: one of :bgr565, :rgb565, :bgr666, :rgb666

return: display

set_touch_callback(self_pid, callback)

@spec set_touch_callback(pid(), touch_callback()) :: :ok

Set touch panel callback function

  • display: %ILI9486{}
  • callback: callback function. 3 arguments: pin, timestamp, status

size(self_pid)

@spec size(pid()) :: %{height: pos_integer(), width: pos_integer()}

Get screen size

  • display: %ILI9486{}

return: %{height: height, width: width}

start_link(opts \\ [])

@spec start_link([ili9486_option()]) :: GenServer.on_start()

Start a new connection to an ILI9486.

return: %ILI9486{}

Example

# default
# assuming LCD device at /dev/spidev0.0
# DC connects to PIN 24
# RST not connected
# SPI speed: 16MHz
# Pixel Format: BGR565
{:ok, disp} = ILI9486.start_link()
# default with touch panel
# DC connects to PIN 24
# RST connects to PIN 25
# SPI speed: 16MHz
# Pixel Format: RGB666 (for demo only, not necessary)
# Touch panel device at /dev/spidev0.1
# Touch panel IRQ PIN 17
{:ok, disp} = ILI9486.start_link(
  speed_hz: 16_000_000,
  pix_fmt: :bgr666,
  rst: 25,
  touch_cs: 1,
  touch_irq: 17
)

high-speed variant (125MHz SPI)

# assuming LCD device at /dev/spidev0.0
# DC connects to PIN 24
# RST connects to PIN 25 (for demo only, not necessary)
# SPI speed: 125MHz
# Pixel Format: BGR666 (for demo only, not necessary)
{:ok, disp} = ILI9486.start_link(
  is_high_speed: true,
  speed_hz: 125_000_000,
  pix_fmt: :bgr666,
  rst: 25
)

high-speed variant (125MHz SPI) with touch panel

# assuming LCD device at /dev/spidev0.0
# DC connects to PIN 24
# RST connects to PIN 25 (for demo only, not necessary)
# SPI speed: 125MHz
# Pixel Format: BGR666 (for demo only, not necessary)
# Touch panel device at /dev/spidev0.1
# Touch panel IRQ PIN 17
{:ok, disp} = ILI9486.start_link(
  is_high_speed: true,
  speed_hz: 125_000_000,
  pix_fmt: :bgr666,
  rst: 25,
  touch_cs: 1,
  touch_irq: 17
)

terminate(reason, arg2)

@spec terminate(any(), t()) :: :ok

Closes all SPI and GPIO resources on shutdown.