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

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

#include <string.h>
#include <stdint.h>
#include "ili9341.h"

Macros

#define DMA_CHUNK_MAX_LEN   (uint16_t)0xFFFFFF
 

Functions

static void ConvHL (uint8_t *s, int32_t l)
 Converts high and low bytes.
 
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_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_FillWindowDMA (uint8_t *buff, uint32_t buff_len)
 Fills the window area of the ILI9341 LCD using DMA.
 
void ILI9341_FillWindow (uint8_t *buff, uint32_t buff_len)
 Fills the window area of the ILI9341 LCD.
 
void ILI9341_SPICmpltHandler (void)
 Handles SPI DMA transfer completion.
 
void ILI9341_Rotate (uint16_t degrees, uint8_t bgr)
 Rotates the ILI9341 LCD display.
 
 __attribute__ ((weak))
 Weak callback function for window fill completion.
 

Variables

SPI_HandleTypeDef * ili9341_spi
 
static ILI9341CurrentBuffer_t _gILI9341CurrentBuffer = {0}
 

Detailed Description

Implementation file for the ILI9341 LCD driver.

This file contains the implementation of the ILI9341 LCD driver. It includes functions 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

Function Documentation

◆ __attribute__()

__attribute__ ( (weak) )

Weak callback function for window fill completion.

This function is a weakly defined callback that can be overridden by the user. It is called when the window fill operation is completed.

◆ ConvHL()

static void ConvHL ( uint8_t * s,
int32_t l )
static

Converts high and low bytes.

This function swaps the high and low bytes in the given buffer. It is used to convert the byte order of pixel data before sending it to the LCD.

Parameters
sPointer to the buffer.
lLength of the buffer.

◆ ILI9341_FillWindow()

void ILI9341_FillWindow ( uint8_t * buff,
uint32_t buff_len )

Fills the window area of the ILI9341 LCD.

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

void ILI9341_FillWindowDMA ( uint8_t * buff,
uint32_t buff_len )

Fills the window area of the ILI9341 LCD using DMA.

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.

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.

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.

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.

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.

Variable Documentation

◆ ili9341_spi

SPI_HandleTypeDef* ili9341_spi
extern

SPI handle for the ILI9341 display