Metal Detector
 
Loading...
Searching...
No Matches
ili9341.h File Reference

Header file for the ILI9341 LCD driver. More...

#include "main.h"

Go to the source code of this file.

Data Structures

struct  ILI9341CurrentBuffer_t
 

Macros

#define ILI9341_HOR_RES   240
 
#define ILI9341_VER_RES   320
 
#define MY_DISP_HOR_RES   ILI9341_HOR_RES
 
#define MY_DISP_VER_RES   ILI9341_VER_RES
 
#define ILI9341_BGR   1
 
#define ILI9341_RGB   0
 
#define ILI9341_GAMMA   1
 
#define ILI9341_NOP   0x00
 
#define ILI9341_SWRESET   0x01
 
#define ILI9341_RDDIDIF   0x04
 
#define ILI9341_RDDST   0x09
 
#define ILI9341_RDDPM   0x0A
 
#define ILI9341_RDDMADCTL   0x0B
 
#define ILI9341_RDDCOLMOD   0x0C
 
#define ILI9341_RDDIM   0x0D
 
#define ILI9341_RDDSM   0x0E
 
#define ILI9341_RDDSDR   0x0F
 
#define ILI9341_SLPIN   0x10
 
#define ILI9341_SLPOUT   0x11
 
#define ILI9341_PTLON   0x12
 
#define ILI9341_NORON   0x13
 
#define ILI9341_DINVOFF   0x20
 
#define ILI9341_DINVON   0x21
 
#define ILI9341_GAMSET   0x26
 
#define ILI9341_DISPOFF   0x28
 
#define ILI9341_DISPON   0x29
 
#define ILI9341_CASET   0x2A
 
#define ILI9341_PASET   0x2B
 
#define ILI9341_RAMWR   0x2C
 
#define ILI9341_RGBSET   0x2D
 
#define ILI9341_RAMRD   0x2E
 
#define ILI9341_PTLAR   0x30
 
#define ILI9341_VSCRDEF   0x33
 
#define ILI9341_TEOFF   0x34
 
#define ILI9341_TEON   0x35
 
#define ILI9341_MADCTL   0x36
 
#define MADCTL_MY   0x80
 
#define MADCTL_MX   0x40
 
#define MADCTL_MV   0x20
 
#define MADCTL_ML   0x10
 
#define MADCTL_MH   0x04
 
#define MADCTL_RGB   0x00
 
#define MADCTL_BGR   0x08
 
#define ILI9341_VSCRSADD   0x37
 
#define ILI9341_IDMOFF   0x38
 
#define ILI9341_IDMON   0x39
 
#define ILI9341_PIXSET   0x3A
 
#define ILI9341_WRMEMCONT   0x3C
 
#define ILI9341_RDMEMCONT   0x3E
 
#define ILI9341_SETSCANTE   0x44
 
#define ILI9341_GETSCAN   0x45
 
#define ILI9341_WRDISBV   0x51
 
#define ILI9341_RDDISBV   0x52
 
#define ILI9341_WRCTRLD   0x53
 
#define ILI9341_RDCTRLD   0x54
 
#define ILI9341_WRCABC   0x55
 
#define ILI9341_RDCABC   0x56
 
#define ILI9341_WRCABCMIN   0x5E
 
#define ILI9341_RDCABCMIN   0x5F
 
#define ILI9341_RDID1   0xDA
 
#define ILI9341_RDID2   0xDB
 
#define ILI9341_RDID3   0xDC
 
#define ILI9341_IFMODE   0xB0 /* [8.3.1 ] Interface Mode Control */
 
#define ILI9341_FRMCTR1   0xB1 /* [8.3.2 ] Frame Rate Control (In Normal Mode/Full Colors) */
 
#define ILI9341_FRMCTR2   0xB2 /* [8.3.3 ] Frame Rate Control (In Idle Mode/8 colors) */
 
#define ILI9341_FRMCTR3   0xB3 /* [8.3.4 ] Frame Rate control (In Partial Mode/Full Colors) */
 
#define ILI9341_INVTR   0xB4 /* [8.3.5 ] Display Inversion Control */
 
#define ILI9341_PRCTR   0xB5 /* [8.3.6 ] Blanking Porch Control */
 
#define ILI9341_DISCTRL   0xB6 /* [8.3.7 ] Display Function Control */
 
#define ILI9341_ETMOD   0xB7 /* [8.3.8 ] Entry Mode Set */
 
#define ILI9341_BLCTRL1   0xB8 /* [8.3.9 ] Backlight Control 1 - Grayscale Histogram UI mode */
 
#define ILI9341_BLCTRL2   0xB9 /* [8.3.10] Backlight Control 2 - Grayscale Histogram still picture mode */
 
#define ILI9341_BLCTRL3   0xBA /* [8.3.11] Backlight Control 3 - Grayscale Thresholds UI mode */
 
#define ILI9341_BLCTRL4   0xBB /* [8.3.12] Backlight Control 4 - Grayscale Thresholds still picture mode */
 
#define ILI9341_BLCTRL5   0xBC /* [8.3.13] Backlight Control 5 - Brightness Transition time */
 
#define ILI9341_BLCTRL7   0xBE /* [8.3.14] Backlight Control 7 - PWM Frequency */
 
#define ILI9341_BLCTRL8   0xBF /* [8.3.15] Backlight Control 8 - ON/OFF + PWM Polarity*/
 
#define ILI9341_PWCTRL1   0xC0 /* [8.3.16] Power Control 1 - GVDD */
 
#define ILI9341_PWCTRL2   0xC1 /* [8.3.17] Power Control 2 - step-up factor for operating voltage */
 
#define ILI9341_VMCTRL1   0xC5 /* [8.3.18] VCOM Control 1 - Set VCOMH and VCOML */
 
#define ILI9341_VMCTRL2   0xC7 /* [8.3.19] VCOM Control 2 - VCOM offset voltage */
 
#define ILI9341_NVMWR   0xD0 /* [8.3.20] NV Memory Write */
 
#define ILI9341_NVMPKEY   0xD1 /* [8.3.21] NV Memory Protection Key */
 
#define ILI9341_RDNVM   0xD2 /* [8.3.22] NV Memory Status Read */
 
#define ILI9341_RDID4   0xD3 /* [8.3.23] Read ID4 - IC Device Code */
 
#define ILI9341_PGAMCTRL   0xE0 /* [8.3.24] Positive Gamma Control */
 
#define ILI9341_NGAMCTRL   0xE1 /* [8.3.25] Negative Gamma Correction */
 
#define ILI9341_DGAMCTRL1   0xE2 /* [8.3.26] Digital Gamma Control 1 */
 
#define ILI9341_DGAMCTRL2   0xE3 /* [8.3.27] Digital Gamma Control 2 */
 
#define ILI9341_IFCTL   0xF6 /* [8.3.28] 16bits Data Format Selection */
 
#define ILI9341_PWCTRLA   0xCB /* [8.4.1] Power control A */
 
#define ILI9341_PWCTRLB   0xCF /* [8.4.2] Power control B */
 
#define ILI9341_TIMECTRLA_INT   0xE8 /* [8.4.3] Internal Clock Driver timing control A */
 
#define ILI9341_TIMECTRLA_EXT   0xE9 /* [8.4.4] External Clock Driver timing control A */
 
#define ILI9341_TIMECTRLB   0xEA /* [8.4.5] Driver timing control B (gate driver timing control) */
 
#define ILI9341_PWSEQCTRL   0xED /* [8.4.6] Power on sequence control */
 
#define ILI9341_GAM3CTRL   0xF2 /* [8.4.7] Enable 3 gamma control */
 
#define ILI9341_PUMPRATIO   0xF7 /* [8.4.8] Pump ratio control */
 
#define ILI9341_DELAY(__DELAY__)   HAL_Delay(__DELAY__)
 Macro to introduce a delay.
 

Functions

void ILI9341_Init (void)
 Initializes the ILI9341 LCD.
 
void ILI9341_WriteCommand (uint8_t cmd)
 Writes a command to the ILI9341 LCD.
 
void ILI9341_WriteData (uint8_t *data_buff, uint32_t data_len)
 Writes data to the ILI9341 LCD.
 
void ILI9341_Rotate (uint16_t degrees, uint8_t bgr)
 Rotates the ILI9341 LCD display.
 
void ILI9341_SetWindow (uint16_t x_axis_start, uint16_t x_axis_end, uint16_t y_axis_start, uint16_t y_axis_end)
 Sets the window area for the ILI9341 LCD.
 
void ILI9341_FillWindow (uint8_t *buff, uint32_t buff_len)
 Fills the window area of the ILI9341 LCD.
 
void ILI9341_FillWindowDMA (uint8_t *buff, uint32_t buff_len)
 Fills the window area of the ILI9341 LCD using DMA.
 
void ILI9341_SPICmpltHandler (void)
 Handles SPI DMA transfer completion.
 
void ILI9341_FillWindowCmpltCallBack (void)
 Weak callback function for window fill completion.
 

Detailed Description

Header file for the ILI9341 LCD driver.

This file contains the declarations for the ILI9341 LCD driver. It includes function prototypes for initialization, command and data transmission, setting window areas, filling windows, and handling DMA completion. The driver is designed to interface with the ILI9341 LCD controller using SPI.

Created on: Apr 5, 2024 Author: Viktor

Macro Definition Documentation

◆ ILI9341_BGR

#define ILI9341_BGR   1

Use BGR color order.

◆ ILI9341_CASET

#define ILI9341_CASET   0x2A

Column Address Set.

◆ ILI9341_DELAY

#define ILI9341_DELAY ( __DELAY__)    HAL_Delay(__DELAY__)

Macro to introduce a delay.

This macro uses the HAL_Delay function to introduce a delay in milliseconds.

Parameters
__DELAY__Duration of the delay in milliseconds.

◆ ILI9341_DINVOFF

#define ILI9341_DINVOFF   0x20

Display Inversion OFF.

◆ ILI9341_DINVON

#define ILI9341_DINVON   0x21

Display Inversion ON.

◆ ILI9341_DISPOFF

#define ILI9341_DISPOFF   0x28

Display OFF.

◆ ILI9341_DISPON

#define ILI9341_DISPON   0x29

Display ON.

◆ ILI9341_GAMMA

#define ILI9341_GAMMA   1

Enable gamma correction.

◆ ILI9341_GAMSET

#define ILI9341_GAMSET   0x26

Gamma Set.

◆ ILI9341_GETSCAN

#define ILI9341_GETSCAN   0x45

Get Scanline.

◆ ILI9341_HOR_RES

#define ILI9341_HOR_RES   240

Horizontal resolution of the ILI9341 LCD.

◆ ILI9341_IDMOFF

#define ILI9341_IDMOFF   0x38

Idle Mode OFF.

◆ ILI9341_IDMON

#define ILI9341_IDMON   0x39

Idle Mode ON.

◆ ILI9341_MADCTL

#define ILI9341_MADCTL   0x36

Memory Access Control.

◆ ILI9341_NOP

#define ILI9341_NOP   0x00

No Operation / Terminate Frame Memory Write.

◆ ILI9341_NORON

#define ILI9341_NORON   0x13

Normal Display Mode ON.

◆ ILI9341_PASET

#define ILI9341_PASET   0x2B

Page Address Set.

◆ ILI9341_PIXSET

#define ILI9341_PIXSET   0x3A

Pixel Format Set.

◆ ILI9341_PTLAR

#define ILI9341_PTLAR   0x30

Partial Area.

◆ ILI9341_PTLON

#define ILI9341_PTLON   0x12

Partial Display Mode ON.

◆ ILI9341_RAMRD

#define ILI9341_RAMRD   0x2E

Memory Read.

◆ ILI9341_RAMWR

#define ILI9341_RAMWR   0x2C

Memory Write.

◆ ILI9341_RDCABC

#define ILI9341_RDCABC   0x56

Read Content Adaptive Brightness Control Value.

◆ ILI9341_RDCABCMIN

#define ILI9341_RDCABCMIN   0x5F

Read CABC Minimum Brightness.

◆ ILI9341_RDCTRLD

#define ILI9341_RDCTRLD   0x54

Read Control Display.

◆ ILI9341_RDDCOLMOD

#define ILI9341_RDDCOLMOD   0x0C

Read Display Pixel Format.

◆ ILI9341_RDDIDIF

#define ILI9341_RDDIDIF   0x04

Read Display Identification Information.

◆ ILI9341_RDDIM

#define ILI9341_RDDIM   0x0D

Read Display Image Mode.

◆ ILI9341_RDDISBV

#define ILI9341_RDDISBV   0x52

Read Display Brightness Value.

◆ ILI9341_RDDMADCTL

#define ILI9341_RDDMADCTL   0x0B

Read Display MADCTL.

◆ ILI9341_RDDPM

#define ILI9341_RDDPM   0x0A

Read Display Power Mode.

◆ ILI9341_RDDSDR

#define ILI9341_RDDSDR   0x0F

Read Display Self-Diagnostic Result.

◆ ILI9341_RDDSM

#define ILI9341_RDDSM   0x0E

Read Display Signal Mode.

◆ ILI9341_RDDST

#define ILI9341_RDDST   0x09

Read Display Status.

◆ ILI9341_RDID1

#define ILI9341_RDID1   0xDA

Read ID1 - Manufacturer ID (user).

◆ ILI9341_RDID2

#define ILI9341_RDID2   0xDB

Read ID2 - Module/Driver version (supplier).

◆ ILI9341_RDID3

#define ILI9341_RDID3   0xDC

Read ID3 - Module/Driver version (user).

◆ ILI9341_RDMEMCONT

#define ILI9341_RDMEMCONT   0x3E

Read Memory Continue.

◆ ILI9341_RGB

#define ILI9341_RGB   0

Use RGB color order.

◆ ILI9341_RGBSET

#define ILI9341_RGBSET   0x2D

Color Set (LUT for 16-bit to 18-bit color depth conversion).

◆ ILI9341_SETSCANTE

#define ILI9341_SETSCANTE   0x44

Set Tear Scanline.

◆ ILI9341_SLPIN

#define ILI9341_SLPIN   0x10

Enter Sleep Mode.

◆ ILI9341_SLPOUT

#define ILI9341_SLPOUT   0x11

Leave Sleep Mode.

◆ ILI9341_SWRESET

#define ILI9341_SWRESET   0x01

Software Reset.

◆ ILI9341_TEOFF

#define ILI9341_TEOFF   0x34

Tearing Effect Line OFF.

◆ ILI9341_TEON

#define ILI9341_TEON   0x35

Tearing Effect Line ON.

◆ ILI9341_VER_RES

#define ILI9341_VER_RES   320

Vertical resolution of the ILI9341 LCD.

◆ ILI9341_VSCRDEF

#define ILI9341_VSCRDEF   0x33

Vertical Scrolling Definition.

◆ ILI9341_VSCRSADD

#define ILI9341_VSCRSADD   0x37

Vertical Scrolling Start Address.

◆ ILI9341_WRCABC

#define ILI9341_WRCABC   0x55

Write Content Adaptive Brightness Control Value.

◆ ILI9341_WRCABCMIN

#define ILI9341_WRCABCMIN   0x5E

Write CABC Minimum Brightness.

◆ ILI9341_WRCTRLD

#define ILI9341_WRCTRLD   0x53

Write Control Display.

◆ ILI9341_WRDISBV

#define ILI9341_WRDISBV   0x51

Write Display Brightness Value.

◆ ILI9341_WRMEMCONT

#define ILI9341_WRMEMCONT   0x3C

Write Memory Continue.

◆ MADCTL_BGR

#define MADCTL_BGR   0x08

BGR Order.

◆ MADCTL_MH

#define MADCTL_MH   0x04

MH horizontal refresh order.

◆ MADCTL_ML

#define MADCTL_ML   0x10

ML vertical refresh order.

◆ MADCTL_MV

#define MADCTL_MV   0x20

MV row / column exchange.

◆ MADCTL_MX

#define MADCTL_MX   0x40

MX column address order.

◆ MADCTL_MY

#define MADCTL_MY   0x80

MY row address order.

◆ MADCTL_RGB

#define MADCTL_RGB   0x00

RGB Order [default].

Function Documentation

◆ ILI9341_FillWindow()

void ILI9341_FillWindow ( uint8_t * buff,
uint32_t buff_len )

Fills the window area of the ILI9341 LCD.

Parameters
buffPointer to the buffer containing the data to be written to the LCD.
buff_lenLength of the data buffer.

This function fills the defined window area on the LCD with pixel data from a buffer. It converts the high and low bytes of the buffer, writes the RAM write (RAMWR) command, and transmits the data via SPI.

Parameters
buffPointer to the buffer containing the data to be written to the LCD.
buff_lenLength of the data buffer.

◆ ILI9341_FillWindowCmpltCallBack()

void ILI9341_FillWindowCmpltCallBack ( void )

Weak callback function for window fill completion.

Weak callback function for window fill completion.

This function is called when the DMA transfer to fill the window on the ILI9341 display is complete. It signals LVGL that the flush operation is done and the display is ready for the next update.

◆ ILI9341_FillWindowDMA()

void ILI9341_FillWindowDMA ( uint8_t * buff,
uint32_t buff_len )

Fills the window area of the ILI9341 LCD using DMA.

Parameters
buffPointer to the buffer containing the data to be written to the LCD.
buff_lenLength of the data buffer.

This function fills the defined window area on the LCD with pixel data from a buffer using DMA. It converts the high and low bytes of the buffer, writes the RAM write (RAMWR) command, and initiates the DMA transfer.

Parameters
buffPointer to the buffer containing the data to be written to the LCD.
buff_lenLength of the data buffer.

◆ ILI9341_Init()

void ILI9341_Init ( void )

Initializes the ILI9341 LCD.

This function initializes the ILI9341 LCD by sending a sequence of commands and data to set up the display. It performs a software reset, sets up power control, VCOM control, pixel format, and display orientation. It also configures frame rate and gamma settings if enabled.

◆ ILI9341_Rotate()

void ILI9341_Rotate ( uint16_t degrees,
uint8_t bgr )

Rotates the ILI9341 LCD display.

Parameters
degreesRotation angle in degrees (0, 90, 180, 270).
bgrBGR color order flag (1 for BGR, 0 for RGB).

This function sets the memory access control (MADCTL) register to rotate the display by the specified angle. It can rotate the display by 0, 90, 180, or 270 degrees and optionally change the color order to BGR.

Parameters
degreesRotation angle in degrees (0, 90, 180, 270).
bgrBGR color order flag (1 for BGR, 0 for RGB).

◆ ILI9341_SetWindow()

void ILI9341_SetWindow ( uint16_t x_axis_start,
uint16_t x_axis_end,
uint16_t y_axis_start,
uint16_t y_axis_end )

Sets the window area for the ILI9341 LCD.

Parameters
x_axis_startStarting X-axis position.
x_axis_endEnding X-axis position.
y_axis_startStarting Y-axis position.
y_axis_endEnding Y-axis position.

This function defines the rectangular area on the LCD where subsequent pixel data will be written. It sends the column address set (CASET) and page address set (PASET) commands with the specified coordinates.

Parameters
x_axis_startStarting X-axis position.
x_axis_endEnding X-axis position.
y_axis_startStarting Y-axis position.
y_axis_endEnding Y-axis position.

◆ ILI9341_SPICmpltHandler()

void ILI9341_SPICmpltHandler ( void )

Handles SPI DMA transfer completion.

This function handles the completion of SPI DMA transfers by checking the remaining buffer length and continuing the transfer if needed, or finalizing it. If the entire buffer has been transferred, it resets the chip select pin, clears the current buffer structure, and calls the completion callback function.

◆ ILI9341_WriteCommand()

void ILI9341_WriteCommand ( uint8_t cmd)

Writes a command to the ILI9341 LCD.

Parameters
cmdCommand byte to be sent to the LCD.

This function sends a command byte to the ILI9341 LCD controller. It resets the chip select and data/command pins, transmits the command via SPI, and then sets the chip select and data/command pins back.

Parameters
cmdCommand byte to be sent to the LCD.

◆ ILI9341_WriteData()

void ILI9341_WriteData ( uint8_t * data_buff,
uint32_t data_len )

Writes data to the ILI9341 LCD.

Parameters
data_buffPointer to the data buffer to be sent to the LCD.
data_lenLength of the data buffer.

This function sends a data buffer to the ILI9341 LCD controller. It resets the chip select pin, transmits the data via SPI, and then sets the chip select pin back.

Parameters
data_buffPointer to the data buffer to be sent to the LCD.
data_lenLength of the data buffer.