# Display - ILI9341 Hardware Configuratoin

The debugging board incorporates a graphical display based on the ILI9341 controller. This display serves as the primary local interface for presenting system state, diagnostics, and user feedback.

<span style="white-space: pre-wrap;">The ILI9341 is a widely used TFT LCD controller that integrates display driving logic, internal GRAM (Graphics RAM), and a command-based interface over serial or parallel buses. In this system, it is used in </span>**SPI mode**, which aligns with the board’s pin constraints and simplifies integration with the MCU.

## Functional Role in the System

Within the debugging board, the display is responsible for:

- Rendering system status (connectivity, subsystem health, etc.)
- Displaying structured debugging information
- Providing immediate visual feedback to user input (button interactions)
- Supporting simple UI constructs (menus, indicators, overlays)

<p class="callout warning"><span style="white-space: pre-wrap;">The display is not intended for high-throughput graphics or complex rendering. Its role is </span>**informational and interactive**, not graphical-intensive.</p>

## Features of the ILI9341

The ILI9341 controller provides a set of features well suited for embedded applications.

### Resolution and Color Depth

- <span style="white-space: pre-wrap;">Resolution: </span>**240 × 320 pixels**
- <span style="white-space: pre-wrap;">Color depth: </span>**16-bit RGB (RGB565)**

This provides sufficient resolution for:

- text rendering
- simple UI layouts
- basic graphical elements (icons, shapes)

### Internal GRAM (Frame Buffer)

<p class="callout info"><span style="white-space: pre-wrap;">The controller includes internal </span>**Graphics RAM (GRAM)**, which stores pixel data.</p>

- <span style="white-space: pre-wrap;">The MCU does </span>**not**<span style="white-space: pre-wrap;"> need to maintain a full framebuffer</span>
- Pixel data is written directly to the display over SPI
- The display retains the image until overwritten

This significantly reduces RAM requirements on the MCU, which is critical in embedded systems.

### Command-Based Interface

The display is controlled through a command/data protocol:

- Commands configure behavior (e.g., orientation, pixel format)
- Data writes update pixel values in GRAM

Typical operations include:

- setting an address window
- writing pixel data
- issuing initialization sequences

### Display Orientation and Addressing

The controller supports:

- configurable screen rotation (portrait / landscape)
- programmable address windows

This allows:

- flexible UI layout
- efficient partial updates (writing only specific regions)

### Hardware Reset and Initialization

The display requires:

- a hardware reset sequence
- a series of configuration commands during initialization

These typically configure:

- power control
- gamma curves
- pixel format
- memory access control

<p class="callout danger"><span style="white-space: pre-wrap;">ILI9341 is a relatively complex and if you want to do anything with the internal library of it you need more than what can be written here. </span>**Read the** [official documentation](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf)</p>

## MCU Configuration

The SPI peripheral must be configured with:

- <span style="white-space: pre-wrap;">Mode: </span>**Full-Duplex Master**
- <span style="white-space: pre-wrap;">Data size: </span>**8-bit**
- <span style="white-space: pre-wrap;">First bit: </span>**MSB-first**
- <span style="white-space: pre-wrap;">Clock polarity: </span>**Low**
- <span style="white-space: pre-wrap;">Clock phase: </span>**1st edge**
- <span style="white-space: pre-wrap;">NSS: </span>**Software**
- Baud rate prescaler: selected based on display stability

These settings must match the display’s timing requirements.

<p class="callout info">For the baud rate, you want it to be as high as possible without it being unstable. For debugging and testing, it's good practice to lower it first, get it working there (as it is a lot more stable) and then increase it again.</p>