Loading...
Searching...
No Matches
lcd.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Koen Zandberg
3 * SPDX-FileCopyrightText: 2021 Francisco Molina
4 * SPDX-FileCopyrightText: 2023 Gunar Schorcht
5 * SPDX-License-Identifier: LGPL-2.1-only
6 */
7
8#pragma once
9
45
46#include "board.h"
47#include "mutex.h"
48#include "periph/spi.h"
49#include "periph/gpio.h"
50
51#ifdef MODULE_DISP_DEV
52#include "disp_dev.h"
53#endif
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
65#ifdef DOXYGEN
66#define CONFIG_LCD_LE_MODE
67#endif
68
73#define LCD_MADCTL_MY 0x80
74#define LCD_MADCTL_MX 0x40
75#define LCD_MADCTL_MV 0x20
76#define LCD_MADCTL_ML 0x10
77#define LCD_MADCTL_BGR 0x08
78#define LCD_MADCTL_MH 0x04
80
81#if MODULE_LCD_PARALLEL || DOXYGEN
94#endif
95
109typedef struct {
110#if MODULE_LCD_SPI || DOXYGEN
111 /* Interface parameters used for serial interface */
112 spi_t spi;
115#endif
116#if MODULE_LCD_PARALLEL || DOXYGEN
118 /* Interface parameters used for MCU 8080 8-bit parallel interface */
119 gpio_t wrx_pin;
120 gpio_t rdx_pin;
121 gpio_t d0_pin;
122 gpio_t d1_pin;
123 gpio_t d2_pin;
124 gpio_t d3_pin;
125 gpio_t d4_pin;
126 gpio_t d5_pin;
127 gpio_t d6_pin;
128 gpio_t d7_pin;
129#if MODULE_LCD_PARALLEL_16BIT || DOXYGEN
130 /* Interface parameters used for MCU 8080 16-bit parallel interface */
131 gpio_t d8_pin;
132 gpio_t d9_pin;
133 gpio_t d10_pin;
134 gpio_t d11_pin;
135 gpio_t d12_pin;
136 gpio_t d13_pin;
137 gpio_t d14_pin;
138 gpio_t d15_pin;
139#endif /* MODULE_LCD_PARALLEL_16BIT */
140#endif /* MODULE_LCD_PARALLEL */
141 /* Common interface parameters */
142 gpio_t cs_pin;
143 gpio_t dcx_pin;
144 gpio_t rst_pin;
145 bool rgb;
147 bool inverted;
148 uint16_t lines;
151 uint16_t rgb_channels;
152 uint8_t rotation;
153 uint8_t offset_x;
154 uint8_t offset_y;
155#if MODULE_LCD_MULTI_CNTRL || DOXYGEN
156 uint8_t cntrl;
159#endif
161
168
172typedef struct {
173#if MODULE_DISP_DEV || DOXYGEN
175#endif
178#if MODULE_LCD_PARALLEL || DOXYGEN
181#endif
182#if MODULE_LCD_PARALLEL_16BIT || DOXYGEN
184#endif
185} lcd_t;
186
201 int (*init)(lcd_t *dev, const lcd_params_t *params);
202
218 void (*set_area)(lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1,
219 uint16_t y2);
220};
221
239
246
258void lcd_ll_write_cmd(lcd_t *dev, uint8_t cmd, const uint8_t *data,
259 size_t len);
260
277void lcd_ll_read_cmd(lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len);
278
289void lcd_ll_set_area(lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2);
291
306int lcd_init(lcd_t *dev, const lcd_params_t *params);
307
322void lcd_fill(lcd_t *dev, uint16_t x1, uint16_t x2,
323 uint16_t y1, uint16_t y2, uint16_t color);
324
341void lcd_pixmap(lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1,
342 uint16_t y2, const uint16_t *color);
343
352void lcd_write_cmd(lcd_t *dev, uint8_t cmd, const uint8_t *data,
353 size_t len);
354
369void lcd_read_cmd(lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len);
370
377
385
386#if MODULE_LCD_PARALLEL || DOXYGEN
402
415typedef struct {
421 void (*init)(lcd_t *dev);
422
429 void (*set_data_dir)(lcd_t *dev, bool output);
430
438 void (*cmd_start)(lcd_t *dev, uint8_t cmd, bool cont);
439
447 void (*write_byte)(lcd_t *dev, bool cont, uint8_t out);
448
457 uint8_t (*read_byte)(lcd_t *dev, bool cont);
458
459#if MODULE_LCD_PARALLEL_16BIT || DOXYGEN
467 void (*write_word)(lcd_t *dev, bool cont, uint16_t out);
468
477 uint16_t (*read_word)(lcd_t *dev, bool cont);
478#endif
480
485
487#endif
488
489#ifdef __cplusplus
490}
491#endif
spi_clk_t
Definition periph_cpu.h:348
Low-level GPIO peripheral driver interface definitions.
struct disp_dev disp_dev_t
Forward declaration for display device struct.
Definition disp_dev.h:39
void lcd_ll_release(lcd_t *dev)
Low-level function to release the device.
void lcd_invert_off(lcd_t *dev)
Disable color inversion.
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.
const lcd_ll_par_driver_t lcd_ll_par_driver
Low-level parallel interface driver instance.
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.
void lcd_read_cmd(lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len)
Raw read command.
struct lcd_driver lcd_driver_t
LCD driver interface.
Definition lcd.h:167
lcd_if_mode_t
Display interface modi.
Definition lcd.h:89
void lcd_ll_acquire(lcd_t *dev)
Low-level function to acquire 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_invert_on(lcd_t *dev)
Invert the display colors.
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.
int lcd_init(lcd_t *dev, const lcd_params_t *params)
Setup an LCD display device.
void lcd_write_cmd(lcd_t *dev, uint8_t cmd, const uint8_t *data, size_t len)
Raw write command.
void lcd_ll_read_cmd(lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len)
Low-level function for read command.
@ LCD_IF_PARALLEL_16BIT
MCU 8080 16-bit parallel interface mode.
Definition lcd.h:92
@ LCD_IF_SPI
SPI serial interface mode.
Definition lcd.h:90
@ LCD_IF_PARALLEL_8BIT
MCU 8080 8-bit parallel interface mode.
Definition lcd.h:91
spi_mode_t
Support SPI modes.
Definition periph_cpu.h:39
Mutex for thread synchronization.
Low-level SPI peripheral driver interface definition.
LCD driver interface.
Definition lcd.h:192
void(* set_area)(lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2)
Set the LCD work area.
Definition lcd.h:218
int(* init)(lcd_t *dev, const lcd_params_t *params)
Initialize LCD controller.
Definition lcd.h:201
Low-level MCU 8080 8-/16-bit parallel interface driver.
Definition lcd.h:415
void(* write_word)(lcd_t *dev, bool cont, uint16_t out)
Write a word using the MCU-driven low-level parallel interface.
Definition lcd.h:467
uint8_t(* read_byte)(lcd_t *dev, bool cont)
Read a byte using the MCU-driven low-level parallel interface.
Definition lcd.h:457
void(* write_byte)(lcd_t *dev, bool cont, uint8_t out)
Write a byte using the MCU-driven low-level parallel interface.
Definition lcd.h:447
void(* set_data_dir)(lcd_t *dev, bool output)
Set the data direction of the low-level parallel interface.
Definition lcd.h:429
void(* init)(lcd_t *dev)
Initialize the MCU-driven low-level parallel interface.
Definition lcd.h:421
uint16_t(* read_word)(lcd_t *dev, bool cont)
Read a word using the MCU-driven low-level parallel interface.
Definition lcd.h:477
void(* cmd_start)(lcd_t *dev, uint8_t cmd, bool cont)
Write command using the MCU-driven low-level parallel interface.
Definition lcd.h:438
Device initialization parameters.
Definition lcd.h:109
spi_clk_t spi_clk
SPI clock speed to use.
Definition lcd.h:113
gpio_t d15_pin
pin connected to the D15 line
Definition lcd.h:138
gpio_t d14_pin
pin connected to the D14 line
Definition lcd.h:137
gpio_t d9_pin
pin connected to the D9 line
Definition lcd.h:132
gpio_t rst_pin
pin connected to the RESET line
Definition lcd.h:144
bool rgb
True when display is connected in RGB mode False when display is connected in BGR mode.
Definition lcd.h:145
gpio_t dcx_pin
pin connected to the DC line
Definition lcd.h:143
uint8_t offset_y
LCD offset to apply on y axis.
Definition lcd.h:154
lcd_if_mode_t mode
LCD driver interface mode.
Definition lcd.h:117
uint16_t rgb_channels
Display rgb channels.
Definition lcd.h:151
uint8_t offset_x
LCD offset to apply on x axis.
Definition lcd.h:153
uint8_t cntrl
controller variant used, if the controller- specific driver supports multiple controller variants
Definition lcd.h:156
gpio_t d12_pin
pin connected to the D12 line
Definition lcd.h:135
gpio_t d11_pin
pin connected to the D11 line
Definition lcd.h:134
uint8_t rotation
Display rotation mode.
Definition lcd.h:152
gpio_t d13_pin
pin connected to the D13 line
Definition lcd.h:136
gpio_t wrx_pin
pin connected to the WRITE ENABLE line
Definition lcd.h:119
spi_mode_t spi_mode
SPI mode.
Definition lcd.h:114
gpio_t d10_pin
pin connected to the D10 line
Definition lcd.h:133
gpio_t rdx_pin
pin connected to the READ ENABLE line
Definition lcd.h:120
uint16_t lines
Number of lines, from 16 to the number of lines supported by the driver IC in 8 line steps.
Definition lcd.h:148
gpio_t d4_pin
pin connected to the D4 line
Definition lcd.h:125
spi_t spi
SPI device that the display is connected to.
Definition lcd.h:112
gpio_t d5_pin
pin connected to the D5 line
Definition lcd.h:126
gpio_t d2_pin
pin connected to the D2 line
Definition lcd.h:123
gpio_t d3_pin
pin connected to the D3 line
Definition lcd.h:124
bool inverted
Display works in inverted color mode.
Definition lcd.h:147
gpio_t d0_pin
pin connected to the D0 line
Definition lcd.h:121
gpio_t d6_pin
pin connected to the D6 line
Definition lcd.h:127
gpio_t d8_pin
pin connected to the D8 line
Definition lcd.h:131
gpio_t cs_pin
pin connected to the CHIP SELECT line
Definition lcd.h:142
gpio_t d7_pin
pin connected to the D7 line
Definition lcd.h:128
gpio_t d1_pin
pin connected to the D1 line
Definition lcd.h:122
Device descriptor for a lcd.
Definition lcd.h:172
const lcd_params_t * params
Device initialization parameters.
Definition lcd.h:177
disp_dev_t * dev
Pointer to the generic display device.
Definition lcd.h:174
mutex_t lock
Mutex used to lock the device in MCU 8080 parallel interface mode.
Definition lcd.h:179
const lcd_driver_t * driver
LCD driver.
Definition lcd.h:176
bool word_access
indicates that a word access is active
Definition lcd.h:183
Mutex structure.
Definition mutex.h:36