Loading...
Searching...
No Matches
LCD display driver

Driver for the LCD display. More...

Detailed Description

Driver for the LCD display.

The LCD is a generic display driver for small RGB displays. It communicates with the device either via an

Usually the device driver is used either for a single display with SPI serial interface or for a display with parallel MCU 8080 8-/16-bit parallel interface. However, the device driver can also be used simultaneously for multiple displays with different interfaces if several of the lcd_spi, lcd_parallel and lcd_parallel_16bit modules are enabled at the same time. In this case, please refer to the notes in lcd_params_t.

The device requires colors to be send in big endian RGB-565 format. The CONFIG_LCD_LE_MODE compile time option can switch this, but only use this when strictly necessary. This option will slow down the driver as it certainly can't use DMA anymore, every short has to be converted before transfer.

Files

file  lcd.h
 
file  lcd_disp_dev.h
 Definition of the driver for the disp_dev generic interface.
 
file  lcd_internal.h
 Device driver implementation for the lcd display controller.
 

Data Structures

struct  lcd_params_t
 Device initialization parameters. More...
 
struct  lcd_t
 Device descriptor for a lcd. More...
 
struct  lcd_driver
 LCD driver interface. More...
 
struct  lcd_ll_par_driver_t
 Low-level MCU 8080 8-/16-bit parallel interface driver. More...
 

Macros

#define CONFIG_LCD_LE_MODE
 Convert little endian colors to big endian.
 

Typedefs

typedef struct lcd_driver lcd_driver_t
 LCD driver interface.
 

Enumerations

enum  lcd_if_mode_t { LCD_IF_SPI , LCD_IF_PARALLEL_8BIT , LCD_IF_PARALLEL_16BIT }
 Display interface modi. More...
 

Low-level MCU 8080 8-/16-bit parallel interface

The low-level MCU 8080 8-/16-bit parallel interface (low-level parallel interface for short) is used when the LCD device is connected via a parallel interface.

Either the GPIO-driven low-level parallel interface provided by this LCD driver or a low-level parallel interface implemented by the MCU, such as the STM32 FMC peripheral, can be used. If the MCU provides its own implementation of the low-level parallel interface, it can be used by implementing the following low-level parallel interface driver functions, enabling the lcd_parallel_ll_mcu module and defining the lcd_ll_par_driver variable of type lcd_ll_par_driver_t.

const lcd_ll_par_driver_t lcd_ll_par_driver
 Low-level parallel interface driver instance.
 

Low-level LCD API

Low-level functions are used to acquire a device, write commands with data to the device, or read data from the device and release it when it is no longer needed.

They are usually called by the high-level functions such as lcd_init, lcd_fill, lcd_pixmap, etc., but can also be used by the application to implement low-level operations if needed.

void lcd_ll_acquire (lcd_t *dev)
 Low-level function to acquire the device.
 
void lcd_ll_release (lcd_t *dev)
 Low-level function to release the device.
 
void lcd_ll_write_cmd (lcd_t *dev, uint8_t cmd, const uint8_t *data, size_t len)
 Low-level function to write a command.
 
void lcd_ll_read_cmd (lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len)
 Low-level function for read command.
 
void lcd_ll_set_area (lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2)
 Set the LCD work area.
 

High-level LCD API

The functions of the high-level LCD API are used by the application.

They use the low-level LCD API to implement more complex operations.

int lcd_init (lcd_t *dev, const lcd_params_t *params)
 Setup an LCD display device.
 
void lcd_fill (lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, uint16_t color)
 Fill a rectangular area with a single pixel color.
 
void lcd_pixmap (lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, const uint16_t *color)
 Fill a rectangular area with an array of pixels.
 
void lcd_write_cmd (lcd_t *dev, uint8_t cmd, const uint8_t *data, size_t len)
 Raw write command.
 
void lcd_read_cmd (lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len)
 Raw read command.
 
void lcd_invert_on (lcd_t *dev)
 Invert the display colors.
 
void lcd_invert_off (lcd_t *dev)
 Disable color inversion.
 

Memory access control bits

#define LCD_MADCTL_MY   0x80
 Row address order.
 
#define LCD_MADCTL_MX   0x40
 Column access order.
 
#define LCD_MADCTL_MV   0x20
 Row column exchange.
 
#define LCD_MADCTL_ML   0x10
 Vertical refresh order.
 
#define LCD_MADCTL_BGR   0x08
 Color selector switch control.
 
#define LCD_MADCTL_MH   0x04
 Horizontal refresh direction.
 

Macro Definition Documentation

◆ CONFIG_LCD_LE_MODE

#define CONFIG_LCD_LE_MODE

Convert little endian colors to big endian.

Compile time switch to change the driver to convert little endian colors to big endian.

Definition at line 70 of file lcd.h.

◆ LCD_MADCTL_BGR

#define LCD_MADCTL_BGR   0x08

Color selector switch control.

Definition at line 81 of file lcd.h.

◆ LCD_MADCTL_MH

#define LCD_MADCTL_MH   0x04

Horizontal refresh direction.

Definition at line 82 of file lcd.h.

◆ LCD_MADCTL_ML

#define LCD_MADCTL_ML   0x10

Vertical refresh order.

Definition at line 80 of file lcd.h.

◆ LCD_MADCTL_MV

#define LCD_MADCTL_MV   0x20

Row column exchange.

Definition at line 79 of file lcd.h.

◆ LCD_MADCTL_MX

#define LCD_MADCTL_MX   0x40

Column access order.

Definition at line 78 of file lcd.h.

◆ LCD_MADCTL_MY

#define LCD_MADCTL_MY   0x80

Row address order.

Definition at line 77 of file lcd.h.

Typedef Documentation

◆ lcd_driver_t

typedef struct lcd_driver lcd_driver_t

LCD driver interface.

This define the functions to access a LCD.

Definition at line 171 of file lcd.h.

Enumeration Type Documentation

◆ lcd_if_mode_t

Display interface modi.

This enumeration is only needed if the MCU 8080 8-/16-bit interfaces are enabled by lcd_parallel or lcd_parallel_16bit. Otherwise the serial SPI interface is implicitly assumed.

Enumerator
LCD_IF_SPI 

SPI serial interface mode.

LCD_IF_PARALLEL_8BIT 

MCU 8080 8-bit parallel interface mode.

LCD_IF_PARALLEL_16BIT 

MCU 8080 16-bit parallel interface mode.

Definition at line 93 of file lcd.h.

Function Documentation

◆ lcd_fill()

void lcd_fill ( lcd_t dev,
uint16_t  x1,
uint16_t  x2,
uint16_t  y1,
uint16_t  y2,
uint16_t  color 
)

Fill a rectangular area with a single pixel color.

the rectangular area is defined as x1 being the first column of pixels and x2 being the last column of pixels to fill. similar to that, y1 is the first row to fill and y2 is the last row to fill.

Parameters
[in]devdevice descriptor
[in]x1x coordinate of the first corner
[in]x2x coordinate of the opposite corner
[in]y1y coordinate of the first corner
[in]y2y coordinate of the opposite corner
[in]colorsingle color to fill the area with

◆ lcd_init()

int lcd_init ( lcd_t dev,
const lcd_params_t params 
)

Setup an LCD display device.

Parameters
[in]devdevice descriptor
[in]paramsparameters for device initialization

◆ lcd_invert_off()

void lcd_invert_off ( lcd_t dev)

Disable color inversion.

Parameters
[in]devdevice descriptor

◆ lcd_invert_on()

void lcd_invert_on ( lcd_t dev)

Invert the display colors.

Parameters
[in]devdevice descriptor

◆ lcd_ll_acquire()

void lcd_ll_acquire ( lcd_t dev)

Low-level function to acquire the device.

Parameters
[out]devdevice descriptor

◆ lcd_ll_read_cmd()

void lcd_ll_read_cmd ( lcd_t dev,
uint8_t  cmd,
uint8_t *  data,
size_t  len 
)

Low-level function for read command.

Note
Very often the SPI MISO signal of the serial interface or the RDX signal of the MCU 8080 parallel interface are not connected to the display. In this case the read command does not provide valid data.
Precondition
The device must have already been acquired with lcd_ll_acquire before this function can be called.
len > 0
Parameters
[in]devdevice descriptor
[in]cmdcommand
[out]datadata from the device
[in]lenlength of the returned data

◆ lcd_ll_release()

void lcd_ll_release ( lcd_t dev)

Low-level function to release the device.

Parameters
[out]devdevice descriptor

◆ lcd_ll_set_area()

void lcd_ll_set_area ( lcd_t dev,
uint16_t  x1,
uint16_t  x2,
uint16_t  y1,
uint16_t  y2 
)

Set the LCD work area.

Parameters
[in]devPointer to the selected driver
[in]x1x coordinate of the first corner
[in]x2x coordinate of the opposite corner
[in]y1y coordinate of the first corner
[in]y2y coordinate of the opposite corner

◆ lcd_ll_write_cmd()

void lcd_ll_write_cmd ( lcd_t dev,
uint8_t  cmd,
const uint8_t *  data,
size_t  len 
)

Low-level function to write a command.

Precondition
The device must have already been acquired with lcd_ll_acquire before this function can be called.
Parameters
[in]devdevice descriptor
[in]cmdcommand code
[in]datacommand data to the device or NULL for commands without data
[in]lenlength of the command data or 0 for commands without data

◆ lcd_pixmap()

void lcd_pixmap ( lcd_t dev,
uint16_t  x1,
uint16_t  x2,
uint16_t  y1,
uint16_t  y2,
const uint16_t *  color 
)

Fill a rectangular area with an array of pixels.

the rectangular area is defined as x1 being the first column of pixels and x2 being the last column of pixels to fill. similar to that, y1 is the first row to fill and y2 is the last row to fill.

Note
color must have a length equal to (x2 - x1 + 1) * (y2 - y1 + 1)
Parameters
[in]devdevice descriptor
[in]x1x coordinate of the first corner
[in]x2x coordinate of the opposite corner
[in]y1y coordinate of the first corner
[in]y2y coordinate of the opposite corner
[in]colorarray of colors to fill the area with

◆ lcd_read_cmd()

void lcd_read_cmd ( lcd_t dev,
uint8_t  cmd,
uint8_t *  data,
size_t  len 
)

Raw read command.

Note
Very often the SPI MISO signal of the serial interface or the RDX signal of the MCU 8080 parallel interface are not connected to the display. In this case the read command does not provide valid data.
Precondition
len > 0
Parameters
[in]devdevice descriptor
[in]cmdcommand
[out]datadata from the device
[in]lenlength of the returned data

◆ lcd_write_cmd()

void lcd_write_cmd ( lcd_t dev,
uint8_t  cmd,
const uint8_t *  data,
size_t  len 
)

Raw write command.

Parameters
[in]devdevice descriptor
[in]cmdcommand code
[in]datacommand data to the device or NULL for commands without data
[in]lenlength of the command data or 0 for commands without data