SatCat5
satcat5::device::spi::Ili9341 Class Reference

Detailed Description

Display device driver for the ILI9341.

The ILI9341 is an ASIC for driving 320x240 TFT LCD displays. It uses an SPI interface to update an internal frame buffer. Other interface options are not supported by this driver.

The ILI9341 ASIC is used in several off-the-shelf display modules:

This driver supports all API methods, including scrolling viewports. Due to the limited SPI bandwidth, a complete screen refresh takes at least 122 msec. As a result, this gui::Display driver must always be used with a buffered gui::Canvas object.

The SPI controller is required to drive the "DCX" pin. The ILI9341 uses this to distinguish commands from data, deasserting DCX for the first byte in each SPI transaction.

The complete ISI9341 datasheet can be found on the Adafruit website.

Startup sequence and color definitions are adapted from the Adafruit ILI9341 Arduino Library, which uses the MIT license.

Definition at line 42 of file spi_ili9341.h.

#include <spi_ili9341.h>

Inheritance diagram for satcat5::device::spi::Ili9341:
[legend]
Collaboration diagram for satcat5::device::spi::Ili9341:
[legend]

Public Member Functions

 Ili9341 (satcat5::cfg::SpiGeneric *spi, u8 devidx, u8 madctl=ADAFRUIT_ROT0)
 Constructor links to the specified SPI interface. More...
 
bool busy () const
 Busy with initialization or a previous command?
 
bool invert (bool inv)
 Invert entire display. More...
 
void reset ()
 Initiate software reset.
 
u16 scroll_pos () const
 Current scroll position.
 
bool viewport (u16 top, u16 size)
 Configure the scrolling viewport: More...
 
void timer_once (unsigned msec)
 Configure a one-time notification after X milliseconds.
 
void timer_every (unsigned msec)
 Configure a repeating notification every X milliseconds.
 
void timer_stop ()
 Stop all future notifications.
 
unsigned timer_interval () const
 Accessor for recurring timer interval, if one is set.
 
unsigned timer_remaining () const
 Accessor for time to next event, if one is set.
 
u16 height () const
 Total size of the display, in pixels.
 
u16 width () const
 Total size of the display, in pixels.
 

Static Public Member Functions

static unsigned count_timer ()
 Count all objects of this type, including idle timers.
 

Static Public Attributes

static constexpr satcat5::gui::LogColors DARK_THEME
 Recommended colors for dark theme (white text on black). More...
 
static constexpr satcat5::gui::LogColors LIGHT_THEME
 Recommended colors for light theme (black text on white). More...
 
static constexpr u8 MADCTL_MY = 0x80
 Constants for the MADCTL register (Section 8.2.29). More...
 
static constexpr u8 MADCTL_MX = 0x40
 Constants for the MADCTL register (Section 8.2.29). More...
 
static constexpr u8 MADCTL_MV = 0x20
 Constants for the MADCTL register (Section 8.2.29). More...
 
static constexpr u8 MADCTL_ML = 0x10
 Constants for the MADCTL register (Section 8.2.29). More...
 
static constexpr u8 MADCTL_BGR = 0x08
 Constants for the MADCTL register (Section 8.2.29). More...
 
static constexpr u8 MADCTL_MH = 0x04
 Constants for the MADCTL register (Section 8.2.29). More...
 
static constexpr u8 ADAFRUIT_ROT0 = MADCTL_BGR | MADCTL_MX
 Adafruit panels all use BGR mode with MH = 0. More...
 
static constexpr u8 ADAFRUIT_ROT90 = MADCTL_BGR | MADCTL_MV
 Adafruit panels all use BGR mode with MH = 0. More...
 
static constexpr u8 ADAFRUIT_ROT180 = MADCTL_BGR | MADCTL_MY
 Adafruit panels all use BGR mode with MH = 0. More...
 
static constexpr u8 ADAFRUIT_ROT270 = MADCTL_BGR | MADCTL_MX | MADCTL_MY | MADCTL_MV
 Adafruit panels all use BGR mode with MH = 0. More...
 
static constexpr u16 COLOR_BLACK = 0x0000
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_NAVY = 0x000F
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_DARKGREEN = 0x03E0
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_DARKCYAN = 0x03EF
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_MAROON = 0x7800
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_PURPLE = 0x780F
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_OLIVE = 0x7BE0
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_LIGHTGREY = 0xC618
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_DARKGREY = 0x7BEF
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_BLUE = 0x001F
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_GREEN = 0x07E0
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_CYAN = 0x07FF
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_RED = 0xF800
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_MAGENTA = 0xF81F
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_YELLOW = 0xFFE0
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_WHITE = 0xFFFF
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_ORANGE = 0xFD20
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_GRELLOW = 0xAFE5
 Constant definitions for 16-bit color mode.
 
static constexpr u16 COLOR_PINK = 0xFC18
 Constant definitions for 16-bit color mode.
 

Protected Member Functions

bool draw (const satcat5::gui::Cursor &cursor, const satcat5::gui::DrawCmd &cmd) override
 Draw pixels to the screen at the designated location. More...
 
bool scroll (s16 rows) override
 Optional: Advance the predefined viewport by N pixels. More...
 
void spi_done (unsigned nread, const u8 *rbytes) override
 
void timer_event () override
 Child class MUST override this method.
 
bool in_viewport (u16 row) const
 
void draw_next ()
 
void init_next ()
 
bool spi_cmd (u8 len, const u8 *cmd, Ili9341 *callback)
 
bool spi_madctl ()
 
bool spi_vscrdef ()
 
void try_twidth (u16 width)
 

Protected Attributes

satcat5::cfg::SpiGeneric *const m_spi
 
satcat5::gui::Cursor m_cursor
 
satcat5::gui::DrawCmd m_draw_cmd
 
const u8 m_devidx
 
const u8 m_madctl
 
u16 m_init_step
 
u16 m_scroll
 
u16 m_viewtop
 
u16 m_viewsize
 
u16 m_draw_step
 
u16 m_draw_done
 
u16 m_tile_col
 
u16 m_tile_row
 
u16 m_tile_width
 
u16 m_tile_height
 
const u16 m_height
 Total size of the display, in pixels. More...
 
const u16 m_width
 

Private Member Functions

void query (unsigned elapsed_msec)
 

Private Attributes

satcat5::poll::Timerm_next
 
unsigned m_trem
 
unsigned m_tnext
 

Constructor & Destructor Documentation

◆ Ili9341()

Ili9341::Ili9341 ( satcat5::cfg::SpiGeneric spi,
u8  devidx,
u8  madctl = ADAFRUIT_ROT0 
)

Constructor links to the specified SPI interface.

SPI rate is controlled by parent, recommend 10 Mbps. A separate GPO pin is required for the D/CX signal.

Definition at line 112 of file spi_ili9341.cc.

Member Function Documentation

◆ draw()

bool Ili9341::draw ( const satcat5::gui::Cursor cursor,
const satcat5::gui::DrawCmd cmd 
)
overrideprotectedvirtual

Draw pixels to the screen at the designated location.

Child class MUST implement this method. Returns false if the command should be repeated.

Implements satcat5::gui::Display.

Definition at line 162 of file spi_ili9341.cc.

◆ invert()

bool Ili9341::invert ( bool  inv)

Invert entire display.

Returns
True if command was accepted.

Definition at line 138 of file spi_ili9341.cc.

◆ scroll()

bool Ili9341::scroll ( s16  rows)
overrideprotectedvirtual

Optional: Advance the predefined viewport by N pixels.

Positive values scroll down, wrapping upper rows to the bottom of viewport. Negative values scroll up. Child class MAY implement this method if applicable. Returns false if the command should be repeated.

Reimplemented from satcat5::gui::Display.

Definition at line 194 of file spi_ili9341.cc.

◆ viewport()

bool Ili9341::viewport ( u16  top,
u16  size 
)

Configure the scrolling viewport:

  • Rows above above "top" are fixed.
  • Next "size" rows enable scrolling.
  • Any remaining rows are also fixed. Note: This feature can only be used if MADCTL_MV = 0.

Definition at line 150 of file spi_ili9341.cc.

Member Data Documentation

◆ ADAFRUIT_ROT0

constexpr u8 satcat5::device::spi::Ili9341::ADAFRUIT_ROT0 = MADCTL_BGR | MADCTL_MX
staticconstexpr

Adafruit panels all use BGR mode with MH = 0.

Use the MX, MY, and MV bits to set orientation.

Definition at line 64 of file spi_ili9341.h.

◆ ADAFRUIT_ROT180

constexpr u8 satcat5::device::spi::Ili9341::ADAFRUIT_ROT180 = MADCTL_BGR | MADCTL_MY
static

Adafruit panels all use BGR mode with MH = 0.

Use the MX, MY, and MV bits to set orientation.

Definition at line 66 of file spi_ili9341.h.

◆ ADAFRUIT_ROT270

constexpr u8 satcat5::device::spi::Ili9341::ADAFRUIT_ROT270 = MADCTL_BGR | MADCTL_MX | MADCTL_MY | MADCTL_MV
static

Adafruit panels all use BGR mode with MH = 0.

Use the MX, MY, and MV bits to set orientation.

Definition at line 67 of file spi_ili9341.h.

◆ ADAFRUIT_ROT90

constexpr u8 satcat5::device::spi::Ili9341::ADAFRUIT_ROT90 = MADCTL_BGR | MADCTL_MV
static

Adafruit panels all use BGR mode with MH = 0.

Use the MX, MY, and MV bits to set orientation.

Definition at line 65 of file spi_ili9341.h.

◆ DARK_THEME

constexpr satcat5::gui::LogColors Ili9341::DARK_THEME
staticconstexpr
Initial value:
= {
static constexpr u16 COLOR_CYAN
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:111
static constexpr u16 COLOR_LIGHTGREY
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:107
static constexpr u16 COLOR_BLUE
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:109
static constexpr u16 COLOR_RED
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:112
static constexpr u16 COLOR_ORANGE
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:116
static constexpr u16 COLOR_BLACK
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:100

Recommended colors for dark theme (white text on black).

See also
gui::LogToDisplay

Definition at line 123 of file spi_ili9341.h.

◆ LIGHT_THEME

constexpr satcat5::gui::LogColors Ili9341::LIGHT_THEME
staticconstexpr
Initial value:
= {
static constexpr u16 COLOR_WHITE
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:115
static constexpr u16 COLOR_DARKGREY
Constant definitions for 16-bit color mode.
Definition: spi_ili9341.h:108

Recommended colors for light theme (black text on white).

See also
gui::LogToDisplay

Definition at line 132 of file spi_ili9341.h.

◆ m_height

const u16 satcat5::gui::Display::m_height
protectedinherited

Total size of the display, in pixels.

The child must set these parameters in the constructor.

Definition at line 135 of file gui_display.h.

◆ MADCTL_BGR

constexpr u8 satcat5::device::spi::Ili9341::MADCTL_BGR = 0x08
static

Constants for the MADCTL register (Section 8.2.29).

This sets the panel type and panel rotation.

Definition at line 56 of file spi_ili9341.h.

◆ MADCTL_MH

constexpr u8 satcat5::device::spi::Ili9341::MADCTL_MH = 0x04
static

Constants for the MADCTL register (Section 8.2.29).

This sets the panel type and panel rotation.

Definition at line 57 of file spi_ili9341.h.

◆ MADCTL_ML

constexpr u8 satcat5::device::spi::Ili9341::MADCTL_ML = 0x10
static

Constants for the MADCTL register (Section 8.2.29).

This sets the panel type and panel rotation.

Definition at line 55 of file spi_ili9341.h.

◆ MADCTL_MV

constexpr u8 satcat5::device::spi::Ili9341::MADCTL_MV = 0x20
static

Constants for the MADCTL register (Section 8.2.29).

This sets the panel type and panel rotation.

Definition at line 54 of file spi_ili9341.h.

◆ MADCTL_MX

constexpr u8 satcat5::device::spi::Ili9341::MADCTL_MX = 0x40
static

Constants for the MADCTL register (Section 8.2.29).

This sets the panel type and panel rotation.

Definition at line 53 of file spi_ili9341.h.

◆ MADCTL_MY

constexpr u8 satcat5::device::spi::Ili9341::MADCTL_MY = 0x80
staticconstexpr

Constants for the MADCTL register (Section 8.2.29).

This sets the panel type and panel rotation.

Definition at line 52 of file spi_ili9341.h.


The documentation for this class was generated from the following files: