lcd.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Koen Zandberg
3  * 2021 Francisco Molina
4  * 2023 Gunar Schorcht
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
11 #pragma once
12 
49 #include "board.h"
50 #include "mutex.h"
51 #include "periph/spi.h"
52 #include "periph/gpio.h"
53 
54 #ifdef MODULE_DISP_DEV
55 #include "disp_dev.h"
56 #endif
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
68 #ifdef DOXYGEN
69 #define CONFIG_LCD_LE_MODE
70 #endif
71 
76 #define LCD_MADCTL_MY 0x80
77 #define LCD_MADCTL_MX 0x40
78 #define LCD_MADCTL_MV 0x20
79 #define LCD_MADCTL_ML 0x10
80 #define LCD_MADCTL_BGR 0x08
81 #define LCD_MADCTL_MH 0x04
84 #if MODULE_LCD_PARALLEL || DOXYGEN
92 typedef enum {
97 #endif
98 
112 typedef struct {
113 #if MODULE_LCD_SPI || DOXYGEN
114  /* Interface parameters used for serial interface */
115  spi_t spi;
118 #endif
119 #if MODULE_LCD_PARALLEL || DOXYGEN
121  /* Interface parameters used for MCU 8080 8-bit parallel interface */
122  gpio_t wrx_pin;
123  gpio_t rdx_pin;
124  gpio_t d0_pin;
125  gpio_t d1_pin;
126  gpio_t d2_pin;
127  gpio_t d3_pin;
128  gpio_t d4_pin;
129  gpio_t d5_pin;
130  gpio_t d6_pin;
131  gpio_t d7_pin;
132 #if MODULE_LCD_PARALLEL_16BIT || DOXYGEN
133  /* Interface parameters used for MCU 8080 16-bit parallel interface */
134  gpio_t d8_pin;
135  gpio_t d9_pin;
136  gpio_t d10_pin;
137  gpio_t d11_pin;
138  gpio_t d12_pin;
139  gpio_t d13_pin;
140  gpio_t d14_pin;
141  gpio_t d15_pin;
142 #endif /* MODULE_LCD_PARALLEL_16BIT */
143 #endif /* MODULE_LCD_PARALLEL */
144  /* Common interface parameters */
145  gpio_t cs_pin;
146  gpio_t dcx_pin;
147  gpio_t rst_pin;
148  bool rgb;
150  bool inverted;
151  uint16_t lines;
154  uint16_t rgb_channels;
155  uint8_t rotation;
156  uint8_t offset_x;
157  uint8_t offset_y;
158 #if MODULE_LCD_MULTI_CNTRL || DOXYGEN
159  uint8_t cntrl;
162 #endif
163 } lcd_params_t;
164 
170 typedef struct lcd_driver lcd_driver_t;
171 
175 typedef struct {
176 #if MODULE_DISP_DEV || DOXYGEN
178 #endif
181 #if MODULE_LCD_PARALLEL || DOXYGEN
184 #endif
185 #if MODULE_LCD_PARALLEL_16BIT || DOXYGEN
186  bool word_access;
187 #endif
188 } lcd_t;
189 
195 struct lcd_driver {
204  int (*init)(lcd_t *dev, const lcd_params_t *params);
205 
221  void (*set_area)(lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1,
222  uint16_t y2);
223 };
224 
242 
249 
261 void lcd_ll_write_cmd(lcd_t *dev, uint8_t cmd, const uint8_t *data,
262  size_t len);
263 
280 void lcd_ll_read_cmd(lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len);
281 
292 void lcd_ll_set_area(lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2);
309 int lcd_init(lcd_t *dev, const lcd_params_t *params);
310 
325 void lcd_fill(lcd_t *dev, uint16_t x1, uint16_t x2,
326  uint16_t y1, uint16_t y2, uint16_t color);
327 
344 void lcd_pixmap(lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1,
345  uint16_t y2, const uint16_t *color);
346 
355 void lcd_write_cmd(lcd_t *dev, uint8_t cmd, const uint8_t *data,
356  size_t len);
357 
372 void lcd_read_cmd(lcd_t *dev, uint8_t cmd, uint8_t *data, size_t len);
373 
379 void lcd_invert_on(lcd_t *dev);
380 
389 #if MODULE_LCD_PARALLEL || DOXYGEN
418 typedef struct {
424  void (*init)(lcd_t *dev);
425 
432  void (*set_data_dir)(lcd_t *dev, bool output);
433 
441  void (*cmd_start)(lcd_t *dev, uint8_t cmd, bool cont);
442 
450  void (*write_byte)(lcd_t *dev, bool cont, uint8_t out);
451 
460  uint8_t (*read_byte)(lcd_t *dev, bool cont);
461 
462 #if MODULE_LCD_PARALLEL_16BIT || DOXYGEN
470  void (*write_word)(lcd_t *dev, bool cont, uint16_t out);
471 
480  uint16_t (*read_word)(lcd_t *dev, bool cont);
481 #endif
483 
488 
490 #endif
491 
492 #ifdef __cplusplus
493 }
494 #endif
spi_clk_t
Definition: periph_cpu.h:351
Low-level GPIO peripheral driver interface definitions.
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.
lcd_if_mode_t
Display interface modi.
Definition: lcd.h:92
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:95
@ LCD_IF_SPI
SPI serial interface mode.
Definition: lcd.h:93
@ LCD_IF_PARALLEL_8BIT
MCU 8080 8-bit parallel interface mode.
Definition: lcd.h:94
spi_mode_t
Support SPI modes.
Definition: periph_cpu.h:42
Mutex for thread synchronization.
Low-level SPI peripheral driver interface definition.
Generic type for a display device.
Definition: disp_dev.h:106
LCD driver interface.
Definition: lcd.h:195
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:221
int(* init)(lcd_t *dev, const lcd_params_t *params)
Initialize LCD controller.
Definition: lcd.h:204
Low-level MCU 8080 8-/16-bit parallel interface driver.
Definition: lcd.h:418
Device initialization parameters.
Definition: lcd.h:112
spi_clk_t spi_clk
SPI clock speed to use.
Definition: lcd.h:116
gpio_t d15_pin
pin connected to the D15 line
Definition: lcd.h:141
gpio_t d14_pin
pin connected to the D14 line
Definition: lcd.h:140
gpio_t d9_pin
pin connected to the D9 line
Definition: lcd.h:135
gpio_t rst_pin
pin connected to the RESET line
Definition: lcd.h:147
bool rgb
True when display is connected in RGB mode False when display is connected in BGR mode.
Definition: lcd.h:148
gpio_t dcx_pin
pin connected to the DC line
Definition: lcd.h:146
uint8_t offset_y
LCD offset to apply on y axis.
Definition: lcd.h:157
lcd_if_mode_t mode
LCD driver interface mode.
Definition: lcd.h:120
uint16_t rgb_channels
Display rgb channels.
Definition: lcd.h:154
uint8_t offset_x
LCD offset to apply on x axis.
Definition: lcd.h:156
uint8_t cntrl
controller variant used, if the controller- specific driver supports multiple controller variants
Definition: lcd.h:159
gpio_t d12_pin
pin connected to the D12 line
Definition: lcd.h:138
gpio_t d11_pin
pin connected to the D11 line
Definition: lcd.h:137
uint8_t rotation
Display rotation mode.
Definition: lcd.h:155
gpio_t d13_pin
pin connected to the D13 line
Definition: lcd.h:139
gpio_t wrx_pin
pin connected to the WRITE ENABLE line
Definition: lcd.h:122
spi_mode_t spi_mode
SPI mode.
Definition: lcd.h:117
gpio_t d10_pin
pin connected to the D10 line
Definition: lcd.h:136
gpio_t rdx_pin
pin connected to the READ ENABLE line
Definition: lcd.h:123
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:151
gpio_t d4_pin
pin connected to the D4 line
Definition: lcd.h:128
spi_t spi
SPI device that the display is connected to.
Definition: lcd.h:115
gpio_t d5_pin
pin connected to the D5 line
Definition: lcd.h:129
gpio_t d2_pin
pin connected to the D2 line
Definition: lcd.h:126
gpio_t d3_pin
pin connected to the D3 line
Definition: lcd.h:127
bool inverted
Display works in inverted color mode.
Definition: lcd.h:150
gpio_t d0_pin
pin connected to the D0 line
Definition: lcd.h:124
gpio_t d6_pin
pin connected to the D6 line
Definition: lcd.h:130
gpio_t d8_pin
pin connected to the D8 line
Definition: lcd.h:134
gpio_t cs_pin
pin connected to the CHIP SELECT line
Definition: lcd.h:145
gpio_t d7_pin
pin connected to the D7 line
Definition: lcd.h:131
gpio_t d1_pin
pin connected to the D1 line
Definition: lcd.h:125
Device descriptor for a lcd.
Definition: lcd.h:175
const lcd_params_t * params
Device initialization parameters.
Definition: lcd.h:180
disp_dev_t * dev
Pointer to the generic display device.
Definition: lcd.h:177
mutex_t lock
Mutex used to lock the device in MCU 8080 parallel interface mode.
Definition: lcd.h:182
const lcd_driver_t * driver
LCD driver.
Definition: lcd.h:179
bool word_access
indicates that a word access is active
Definition: lcd.h:186
Mutex structure.
Definition: mutex.h:39