Skip to content

Commit 25b2de3

Browse files
WinteriWangcfriedt
authored andcommitted
driver: display: add waveshare dsi panel driver support
Added waveshare dsi panel driver. It is on I2C bus. Signed-off-by: Winteri Wang <[email protected]> Signed-off-by: Jiafei Pan <[email protected]> Signed-off-by: Ruoshan Shi <[email protected]>
1 parent 66e878b commit 25b2de3

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

drivers/display/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ zephyr_library_sources_ifdef(CONFIG_ST7789V display_st7789v.c)
3333
zephyr_library_sources_ifdef(CONFIG_ST7735R display_st7735r.c)
3434
zephyr_library_sources_ifdef(CONFIG_ST7796S display_st7796s.c)
3535
zephyr_library_sources_ifdef(CONFIG_STM32_LTDC display_stm32_ltdc.c)
36+
zephyr_library_sources_ifdef(CONFIG_WAVESHARE_7INCH_DSI_LCD_C display_waveshare_dsi_lcd.c)
3637
zephyr_library_sources_ifdef(CONFIG_RM68200 display_rm68200.c)
3738
zephyr_library_sources_ifdef(CONFIG_RM67162 display_rm67162.c)
3839
zephyr_library_sources_ifdef(CONFIG_HUB12 display_hub12.c)

drivers/display/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ source "drivers/display/Kconfig.nt35510"
6262
source "drivers/display/Kconfig.renesas_ra"
6363
source "drivers/display/Kconfig.ili9806e_dsi"
6464
source "drivers/display/Kconfig.st7701"
65+
source "drivers/display/Kconfig.waveshare_dsi_lcd"
6566
source "drivers/display/Kconfig.lpm013m126"
6667
source "drivers/display/Kconfig.co5300"
6768

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2025 NXP
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config WAVESHARE_7INCH_DSI_LCD_C
6+
bool "waveshare 7inch DSI LCD(C) driver"
7+
default y
8+
select MIPI_DSI
9+
select I2C
10+
depends on DT_HAS_WAVESHARE_7INCH_DSI_LCD_C_ENABLED
11+
help
12+
Enable driver for waveshare 7inch DSI LCD(C).
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright 2025 NXP
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <string.h>
7+
#include <zephyr/device.h>
8+
#include <zephyr/init.h>
9+
#include <zephyr/drivers/display.h>
10+
#include <zephyr/drivers/mipi_dsi.h>
11+
#include <zephyr/drivers/i2c.h>
12+
#include <zephyr/kernel.h>
13+
#include <zephyr/logging/log.h>
14+
15+
LOG_MODULE_REGISTER(waveshare_dsi_lcd, CONFIG_DISPLAY_LOG_LEVEL);
16+
17+
#if DT_HAS_COMPAT_STATUS_OKAY(waveshare_7inch_dsi_lcd_c)
18+
#define DT_DRV_COMPAT waveshare_7inch_dsi_lcd_c
19+
#endif
20+
21+
struct waveshare_dsi_lcd_bus {
22+
struct i2c_dt_spec i2c;
23+
};
24+
25+
typedef bool (*waveshare_dsi_lcd_bus_ready_fn)(const struct device *dev);
26+
typedef int (*waveshare_dsi_lcd_write_bus_fn)(const struct device *dev, uint8_t reg, uint8_t val);
27+
typedef const char *(*waveshare_dsi_lcd_bus_name_fn)(const struct device *dev);
28+
29+
struct waveshare_dsi_lcd_config {
30+
const struct device *mipi_dsi;
31+
uint8_t channel;
32+
uint8_t num_of_lanes;
33+
struct waveshare_dsi_lcd_bus bus;
34+
waveshare_dsi_lcd_bus_ready_fn bus_ready;
35+
waveshare_dsi_lcd_write_bus_fn write_bus;
36+
waveshare_dsi_lcd_bus_name_fn bus_name;
37+
};
38+
39+
struct waveshare_dsi_lcd_data {
40+
uint8_t pixel_format;
41+
};
42+
43+
static bool waveshare_dsi_lcd_bus_ready_i2c(const struct device *dev)
44+
{
45+
const struct waveshare_dsi_lcd_config *config = dev->config;
46+
47+
return i2c_is_ready_dt(&config->bus.i2c);
48+
}
49+
50+
static int waveshare_dsi_lcd_write_bus_i2c(const struct device *dev, uint8_t reg, uint8_t val)
51+
{
52+
const struct waveshare_dsi_lcd_config *config = dev->config;
53+
uint8_t buf[2];
54+
55+
buf[0] = reg;
56+
buf[1] = val;
57+
58+
return i2c_write_dt(&config->bus.i2c, buf, 2);
59+
}
60+
61+
static const char *waveshare_dsi_lcd_bus_name_i2c(const struct device *dev)
62+
{
63+
const struct waveshare_dsi_lcd_config *config = dev->config;
64+
65+
return config->bus.i2c.bus->name;
66+
}
67+
68+
static int waveshare_dsi_lcd_enable(const struct device *dev, bool enable)
69+
{
70+
const struct waveshare_dsi_lcd_config *config = dev->config;
71+
72+
config->write_bus(dev, 0xad, enable ? 0x01 : 0x00);
73+
74+
return 0;
75+
}
76+
77+
static int waveshare_dsi_lcd_bl_update_status(const struct device *dev, uint8_t brightness)
78+
{
79+
const struct waveshare_dsi_lcd_config *config = dev->config;
80+
81+
config->write_bus(dev, 0xab, 0xff - brightness);
82+
config->write_bus(dev, 0xaa, 0x01);
83+
84+
return 0;
85+
}
86+
87+
static int waveshare_dsi_lcd_init(const struct device *dev)
88+
{
89+
const struct waveshare_dsi_lcd_config *config = dev->config;
90+
struct waveshare_dsi_lcd_data *data = dev->data;
91+
int ret;
92+
struct mipi_dsi_device mdev = {0};
93+
94+
if (!config->bus_ready(dev)) {
95+
LOG_ERR("Bus device %s not ready!", config->bus_name(dev));
96+
return -EINVAL;
97+
}
98+
99+
config->write_bus(dev, 0xc0, 0x01);
100+
config->write_bus(dev, 0xc2, 0x01);
101+
config->write_bus(dev, 0xac, 0x01);
102+
103+
waveshare_dsi_lcd_bl_update_status(dev, 0xff);
104+
waveshare_dsi_lcd_enable(dev, true);
105+
106+
/* Attach to MIPI DSI host */
107+
mdev.data_lanes = config->num_of_lanes;
108+
mdev.pixfmt = data->pixel_format;
109+
mdev.mode_flags =
110+
MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS;
111+
112+
ret = mipi_dsi_attach(config->mipi_dsi, config->channel, &mdev);
113+
if (ret < 0) {
114+
LOG_ERR("Could not attach to MIPI-DSI host");
115+
return ret;
116+
}
117+
118+
LOG_INF("waveshare_dsi_lcd init succeeded");
119+
120+
return 0;
121+
}
122+
123+
#define WAVESHARE_DSI_LCD_DEFINE(id) \
124+
static const struct waveshare_dsi_lcd_config config_##id = { \
125+
.mipi_dsi = DEVICE_DT_GET(DT_INST_PHANDLE(id, mipi_dsi)), \
126+
.channel = DT_INST_REG_ADDR(id), \
127+
.num_of_lanes = DT_INST_PROP_BY_IDX(id, data_lanes, 0), \
128+
.bus = {.i2c = I2C_DT_SPEC_INST_GET(id)}, \
129+
.bus_ready = waveshare_dsi_lcd_bus_ready_i2c, \
130+
.write_bus = waveshare_dsi_lcd_write_bus_i2c, \
131+
.bus_name = waveshare_dsi_lcd_bus_name_i2c, \
132+
}; \
133+
static struct waveshare_dsi_lcd_data data_##id = { \
134+
.pixel_format = DT_INST_PROP(id, pixel_format), \
135+
}; \
136+
DEVICE_DT_INST_DEFINE(id, waveshare_dsi_lcd_init, NULL, &data_##id, &config_##id, \
137+
POST_KERNEL, CONFIG_DISPLAY_INIT_PRIORITY, NULL);
138+
139+
DT_INST_FOREACH_STATUS_OKAY(WAVESHARE_DSI_LCD_DEFINE)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright 2025 NXP
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: Waveshare 7INCH DSI LCD(C)
8+
9+
compatible: "waveshare,7inch-dsi-lcd-c"
10+
11+
include: base.yaml
12+
13+
properties:
14+
reg:
15+
required: true
16+
17+
data-lanes:
18+
type: array
19+
required: true
20+
description:
21+
Number of data lanes.
22+
23+
pixel-format:
24+
type: int
25+
required: true
26+
description:
27+
Pixel format. Available formats in dt-bindings/mipi_dsi/mipi_dsi.h.
28+
29+
mipi-dsi:
30+
type: phandle
31+
required: true
32+
description:
33+
Instance of the MIPI DSI peripheral.

0 commit comments

Comments
 (0)