Skip to content

Commit ada1b6f

Browse files
jfischer-novanwinkeljan
authored andcommitted
drivers: display_st7789v: obtain panel settings and parameters from DT
Obtain panel settings and parameters from DT. Signed-off-by: Johann Fischer <[email protected]>
1 parent 0fe85fe commit ada1b6f

File tree

3 files changed

+159
-14
lines changed

3 files changed

+159
-14
lines changed

drivers/display/display_st7789v.c

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2017 Jan Van Winkel <[email protected]>
33
* Copyright (c) 2019 Nordic Semiconductor ASA
44
* Copyright (c) 2019 Marc Reilly
5+
* Copyright (c) 2019 PHYTEC Messtechnik GmbH
56
*
67
* SPDX-License-Identifier: Apache-2.0
78
*/
@@ -22,6 +23,14 @@ LOG_MODULE_REGISTER(display_st7789v);
2223
#define ST7789V_CMD_DATA_PIN DT_INST_0_SITRONIX_ST7789V_CMD_DATA_GPIOS_PIN
2324
#define ST7789V_RESET_PIN DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_PIN
2425

26+
static u8_t st7789v_porch_param[] = DT_INST_0_SITRONIX_ST7789V_PORCH_PARAM;
27+
static u8_t st7789v_cmd2en_param[] = DT_INST_0_SITRONIX_ST7789V_CMD2EN_PARAM;
28+
static u8_t st7789v_pwctrl1_param[] = DT_INST_0_SITRONIX_ST7789V_PWCTRL1_PARAM;
29+
static u8_t st7789v_pvgam_param[] = DT_INST_0_SITRONIX_ST7789V_PVGAM_PARAM;
30+
static u8_t st7789v_nvgam_param[] = DT_INST_0_SITRONIX_ST7789V_NVGAM_PARAM;
31+
static u8_t st7789v_ram_param[] = DT_INST_0_SITRONIX_ST7789V_RAM_PARAM;
32+
static u8_t st7789v_rgb_param[] = DT_INST_0_SITRONIX_ST7789V_RGB_PARAM;
33+
2534
struct st7789v_data {
2635
struct device *spi_dev;
2736
struct spi_config spi_config;
@@ -46,7 +55,7 @@ struct st7789v_data {
4655
#define ST7789V_PIXEL_SIZE 3u
4756
#endif
4857

49-
void st7789v_set_lcd_margins(struct st7789v_data *data,
58+
static void st7789v_set_lcd_margins(struct st7789v_data *data,
5059
u16_t x_offset, u16_t y_offset)
5160
{
5261
data->x_offset = x_offset;
@@ -58,7 +67,7 @@ static void st7789v_set_cmd(struct st7789v_data *data, int is_cmd)
5867
gpio_pin_write(data->cmd_data_gpio, ST7789V_CMD_DATA_PIN, !is_cmd);
5968
}
6069

61-
void st7789v_transmit(struct st7789v_data *data, u8_t cmd,
70+
static void st7789v_transmit(struct st7789v_data *data, u8_t cmd,
6271
u8_t *tx_data, size_t tx_count)
6372
{
6473
struct spi_buf tx_buf = { .buf = &cmd, .len = 1 };
@@ -247,6 +256,76 @@ static int st7789v_set_orientation(const struct device *dev,
247256
return -ENOTSUP;
248257
}
249258

259+
static void st7789v_lcd_init(struct st7789v_data *p_st7789v)
260+
{
261+
u8_t tmp;
262+
263+
st7789v_set_lcd_margins(p_st7789v, 0, 0);
264+
265+
st7789v_transmit(p_st7789v, ST7789V_CMD_PORCTRL, st7789v_porch_param,
266+
sizeof(st7789v_porch_param));
267+
268+
st7789v_transmit(p_st7789v, ST7789V_CMD_CMD2EN, st7789v_cmd2en_param,
269+
sizeof(st7789v_cmd2en_param));
270+
271+
/* Digital Gamma Enable, default disabled */
272+
tmp = 0x00;
273+
st7789v_transmit(p_st7789v, ST7789V_CMD_DGMEN, &tmp, 1);
274+
275+
/* Frame Rate Control in Normal Mode, default value */
276+
tmp = 0x0f;
277+
st7789v_transmit(p_st7789v, ST7789V_CMD_FRCTRL2, &tmp, 1);
278+
279+
tmp = DT_INST_0_SITRONIX_ST7789V_GCTRL;
280+
st7789v_transmit(p_st7789v, ST7789V_CMD_GCTRL, &tmp, 1);
281+
282+
tmp = DT_INST_0_SITRONIX_ST7789V_VCOM;
283+
st7789v_transmit(p_st7789v, ST7789V_CMD_VCOMS, &tmp, 1);
284+
285+
#if (defined(DT_INST_0_SITRONIX_ST7789V_VRHS) && \
286+
defined(DT_INST_0_SITRONIX_ST7789V_VDVS))
287+
tmp = 0x01;
288+
st7789v_transmit(p_st7789v, ST7789V_CMD_VDVVRHEN, &tmp, 1);
289+
290+
tmp = DT_INST_0_SITRONIX_ST7789V_VRHS;
291+
st7789v_transmit(p_st7789v, ST7789V_CMD_VRH, &tmp, 1);
292+
293+
tmp = DT_INST_0_SITRONIX_ST7789V_VDVS;
294+
st7789v_transmit(p_st7789v, ST7789V_CMD_VDS, &tmp, 1);
295+
#endif
296+
297+
st7789v_transmit(p_st7789v, ST7789V_CMD_PWCTRL1, st7789v_pwctrl1_param,
298+
sizeof(st7789v_pwctrl1_param));
299+
300+
/* Memory Data Access Control */
301+
tmp = DT_INST_0_SITRONIX_ST7789V_MDAC;
302+
st7789v_transmit(p_st7789v, ST7789V_CMD_MADCTL, &tmp, 1);
303+
304+
/* Interface Pixel Format */
305+
tmp = DT_INST_0_SITRONIX_ST7789V_COLMOD;
306+
st7789v_transmit(p_st7789v, ST7789V_CMD_COLMOD, &tmp, 1);
307+
308+
tmp = DT_INST_0_SITRONIX_ST7789V_LCM;
309+
st7789v_transmit(p_st7789v, ST7789V_CMD_LCMCTRL, &tmp, 1);
310+
311+
tmp = DT_INST_0_SITRONIX_ST7789V_GAMMA;
312+
st7789v_transmit(p_st7789v, ST7789V_CMD_GAMSET, &tmp, 1);
313+
314+
st7789v_transmit(p_st7789v, ST7789V_CMD_INV_ON, NULL, 0);
315+
316+
st7789v_transmit(p_st7789v, ST7789V_CMD_PVGAMCTRL, st7789v_pvgam_param,
317+
sizeof(st7789v_pvgam_param));
318+
319+
st7789v_transmit(p_st7789v, ST7789V_CMD_NVGAMCTRL, st7789v_nvgam_param,
320+
sizeof(st7789v_nvgam_param));
321+
322+
st7789v_transmit(p_st7789v, ST7789V_CMD_RAMCTRL, st7789v_ram_param,
323+
sizeof(st7789v_ram_param));
324+
325+
st7789v_transmit(p_st7789v, ST7789V_CMD_RGBCTRL, st7789v_rgb_param,
326+
sizeof(st7789v_rgb_param));
327+
}
328+
250329
static int st7789v_init(struct device *dev)
251330
{
252331
struct st7789v_data *data = (struct st7789v_data *)dev->driver_data;

drivers/display/display_st7789v.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,4 @@
6767
#define ST7789V_CMD_PVGAMCTRL 0xe0
6868
#define ST7789V_CMD_NVGAMCTRL 0xe1
6969

70-
struct st7789v_data;
71-
72-
void st7789v_set_lcd_margins(struct st7789v_data *data,
73-
u16_t x_offset, u16_t y_offset);
74-
75-
void st7789v_lcd_init(struct st7789v_data *data);
76-
77-
void st7789v_transmit(struct st7789v_data *data, u8_t cmd,
78-
u8_t *tx_data, size_t tx_count);
79-
8070
#endif

dts/bindings/display/sitronix,st7789v.yaml

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2019, Marc Reilly <[email protected]>
2+
# Copyright (c) 2019, PHYTEC Messtechnik GmbH
23
# SPDX-License-Identifier: Apache-2.0
34

45
title: ST7789V 320x240 Display Controller
@@ -31,10 +32,85 @@ properties:
3132

3233
x-offset:
3334
type: int
34-
required: false
35+
required: true
3536
description: The column offset in pixels of the LCD to the controller memory
3637

3738
y-offset:
3839
type: int
39-
required: false
40+
required: true
4041
description: The row offset in pixels of the LCD to the controller memory
42+
43+
vcom:
44+
type: int
45+
required: true
46+
description: VCOM Setting
47+
48+
gctrl:
49+
type: int
50+
required: true
51+
description: Gate Control
52+
53+
vrhs:
54+
type: int
55+
required: false
56+
description: VRH Setting
57+
58+
vdvs:
59+
type: int
60+
required: false
61+
description: VDV Setting
62+
63+
mdac:
64+
type: int
65+
required: true
66+
description: Memory Data Access Control
67+
68+
lcm:
69+
type: int
70+
required: true
71+
description: LCM Setting
72+
73+
colmod:
74+
type: int
75+
required: true
76+
description: Interface Pixel Format
77+
78+
gamma:
79+
type: int
80+
required: true
81+
description: Gamma Setting
82+
83+
porch-param:
84+
type: uint8-array
85+
required: true
86+
description: Porch Setting
87+
88+
cmd2en-param:
89+
type: uint8-array
90+
required: true
91+
description: Command 2 Enable Parameter
92+
93+
pwctrl1-param:
94+
type: uint8-array
95+
required: true
96+
description: Power Control 1 Parameter
97+
98+
pvgam-param:
99+
type: uint8-array
100+
required: true
101+
description: Positive Voltage Gamma Control Parameter
102+
103+
nvgam-param:
104+
type: uint8-array
105+
required: true
106+
description: Negative Voltage Gamma Control Parameter
107+
108+
ram-param:
109+
type: uint8-array
110+
required: true
111+
description: RAM Control Parameter
112+
113+
rgb-param:
114+
type: uint8-array
115+
required: true
116+
description: RGB Interface Control Parameter

0 commit comments

Comments
 (0)