ILI9486 (ili9486_elixir v0.1.4)

View Source

ILI9486 Elixir driver

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 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 connection to an ILI9486

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

Functions

Returns a specification to start this module under a supervisor.

Closes all SPI and GPIO resources on shutdown.

API

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

Write a byte to the display as command data.

  • self: %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: self

data(self_pid, data)

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

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

return: self

display(self_pid, image_data, source_color)

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

  • self: %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: self

display_565(self_pid, image_data)

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

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

return: self

display_666(self_pid, image_data)

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

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

return: self

new(opts \\ [])

New connection to an ILI9486

  • port: SPI port number

    Default value: 0

  • lcd_cs: LCD chip-selection number

    Default value: 0.

  • touch_cs: (Optional) Touch panel chip-selection number

    Default value: nil.

  • touch_irq: (Optional) Touch panel interrupt. Low level while the Touch Panel detects touching

    Default value: nil.

  • touch_speed_hz: SPI Speed for the touch panel

    Default value: 50000.

  • dc: Command/data register selection

    Default value: 24.

  • rst: Reset pin for ILI9486

    Default value: nil.

  • width: Width of display connected to ILI9486

    Default value: 480.

  • height: Height of display connected to ILI9486

    Default value: 320.

  • offset_top: Offset to top row

    Default value: 0.

  • offset_left: Offset to left column

    Default value: 0.

  • speed_hz: SPI speed (in Hz)

    Default value: 16_000_000.

  • pix_fmt: either :bgr565, :rgb565, :bgr666 or :rgb666

    Default value: :bgr565.

  • rotation: Screen rotation.

    Default value: 90. Only 0, 90, 180 and 270 are valid.

  • mad_mode: MAD mode.

    Default value: :right_down. Valid values: :right_down, :right_up and :rgb_mode

  • display_mode: Display mode.

    Default value: :normal. Enters normal display mode after initialization.

  • frame_rate: Frame rate.

    Default value: 70. Valid frame rate should be one of the following:

    • 28
    • 30
    • 32
    • 34
    • 36
    • 39
    • 42
    • 46
    • 50
    • 56
    • 62
    • 70
    • 81
    • 96
    • 117
  • diva: Division ratio for internal clocks.

    Default value: 0b00.

    • 0b00: focs
    • 0b01: focs/2
    • 0b10: focs/4
    • 0b11: focs/8
  • rtna: RTNA[4:0] is used to set 1H (line) period of Normal mode at CPU interface.

    Default value: 0b10001. Valid value starts from 0b10000 (16 clocks) to 0b11111 (31 clocks), i.e., clocks increases by 1 as rtna increasing by 1.

  • is_high_speed: Is the high speed variant?

    Default value: false. Set true to make it compatible with the high speed variant. (125MHz SPI).

  • chunk_size: batch transfer size.

    Default value: 4096 for the lo-speed variant. 0x8000 for the hi-speed variant.

  • spi_lcd: pre-opened SPI handle for the LCD bus.

    Default value: nil. If provided, overrides :port and :lcd_cs.

  • spi_touch: pre-opened SPI handle for the touch panel bus.

    Default value: nil. If provided, overrides :port and :touch_cs.

  • gpio_dc: pre-opened GPIO pin for the D/C line.

    Default value: nil. If provided, overrides :dc.

  • gpio_rst: pre-opened GPIO pin for the reset line.

    Default value: nil. If provided, overrides :rst.

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.new()
# 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.new(
  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.new(
  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.new(
  is_high_speed: true,
  speed_hz: 125_000_000,
  pix_fmt: :bgr666,
  rst: 25,
  touch_cs: 1,
  touch_irq: 17
)

pix_fmt(self_pid)

Get display pixel format

  • self: %ILI9486{}

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

reset(self_pid)

Reset the display, if reset pin is connected.

  • self: %ILI9486{}

return: self

send(self_pid, bytes, is_data)

Send bytes to the ILI9486

  • self: %ILI9486{}

  • 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

return: self

set_display(self_pid, status)

Turn on/off display

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

return: self

set_display_mode(self_pid, display_mode)

Set display mode

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

return: self

set_frame_rate(self_pid, frame_rate)

Set frame rate

  • self: %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 | {:error, reason}

set_pix_fmt(self_pid, pix_fmt)

Set display pixel format

  • self: %ILI9486{}
  • pix_fmt: one of :bgr565, :rgb565, :bgr666,:rgb666**return**:self`

set_touch_callback(self_pid, callback)

Set touch panel callback function

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

size(self_pid)

Get screen size

  • self: %ILI9486{}

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

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()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

new!(opts \\ [])

terminate(reason, arg2)

Closes all SPI and GPIO resources on shutdown.