ILI9486 (ili9486_elixir v0.1.6)
View SourceILI9486 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)
Options for start_link/1.
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)
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.
Get display pixel format
Reset the display, if reset pin is connected.
Send bytes to the ILI9486
Turn on/off display
Set display mode
Set frame rate
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
Types
@type color_format() :: :rgb888 | :bgr888
Supported source color formats
@type data_bus() :: :parallel_8bit | :parallel_16bit
Parallel data bus mode
@type display_mode() :: :normal | :partial | :idle
Display mode
@type diva() :: 0..3
Division ratio for internal clocks (0=focs, 1=focs/2, 2=focs/4, 3=focs/8)
@type frame_rate() ::
28 | 30 | 32 | 34 | 36 | 39 | 42 | 46 | 50 | 56 | 62 | 70 | 81 | 96 | 117
Supported frame rates (Hz)
@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 of0 | 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 of28, 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 periodRTNA[4:0],0b10000(16) to0b11111(31), default0b10001(17); each step increases clocks by 1.:is_high_speed- Use high-speed variant (125 MHz SPI) (default:false).:chunk_size- Batch transfer size; default4096(lo-speed) or0x8000(hi-speed).:spi_lcd- Pre-opened SPI handle for LCD; overrides:port/:lcd_cswhen set.:spi_touch- Pre-opened SPI handle for touch; overrides:port/:touch_cswhen set.:gpio_dc- Pre-opened GPIO for D/C; overrides:dcwhen set.:gpio_rst- Pre-opened GPIO for reset; overrides:rstwhen set.:name- Registered name for the GenServer.
Image data buffer accepted by display functions
@type mad_mode() :: :right_down | :right_up | :rgb_mode
MADCTL orientation / RGB mode
@type pixel_format() :: :rgb565 | :bgr565 | :rgb666 | :bgr666
Supported pixel formats
@type rotation() :: 0 | 90 | 180 | 270
Screen rotation in degrees
@type rtna() :: 16..31
RTNA timing value (0b10000=16 .. 0b11111=31)
@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
@type touch_callback() :: GPIOIRQDevice.irq_callback()
Callback invoked on touch IRQ
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
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
delayms after the cmd data is sent Default value:0. (no wait)
- cmd_data: cmd data to be sent.
Default value:
return: display
Write a byte or array of bytes to the display as display data.
- display:
%ILI9486{} - data: display data
return: display
@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
:rgb888or:bgr888. Indicates the channel order of the providedimage_data.
return: display
@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
@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
@spec new([ili9486_option()]) :: GenServer.on_start()
@spec new!([ili9486_option()]) :: pid()
@spec pix_fmt(pid()) :: pixel_format()
Get display pixel format
- display:
%ILI9486{}
return: one of :bgr565, :rgb565, :bgr666, :rgb666
@spec reset(pid()) :: :ok
Reset the display, if reset pin is connected.
- display:
%ILI9486{}
return: display
Send bytes to the ILI9486
display:
%ILI9486{}bytes: The bytes to be sent to
displaywhen is_integer(bytes),sentwill take the 8 least-significant bits[band(bytes, 0xFF)]and send it todisplaywhen is_list(bytes),byteswill be casting to bitstring and then sent todisplay
is_data:
true:byteswill be sent as datafalse:byteswill be sent as commands
return: display
@spec set_display(pid(), :on | :off) :: :ok
Turn on/off display
- display:
%ILI9486{} - status: either
:onor:off
return: display
@spec set_display_mode(pid(), display_mode()) :: :ok
Set display mode
- display:
%ILI9486{} - display_mode: Valid values:
:normal,:partial,:idle
return: display
@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
@spec set_pix_fmt(pid(), pixel_format()) :: :ok
Set display pixel format
- display:
%ILI9486{} - pix_fmt: one of
:bgr565,:rgb565,:bgr666,:rgb666
return: display
@spec set_touch_callback(pid(), touch_callback()) :: :ok
Set touch panel callback function
- display:
%ILI9486{} - callback: callback function. 3 arguments:
pin,timestamp,status
@spec size(pid()) :: %{height: pos_integer(), width: pos_integer()}
Get screen size
- display:
%ILI9486{}
return: %{height: height, width: width}
@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
)
Closes all SPI and GPIO resources on shutdown.