Skip to content

Commit 51e53ee

Browse files
gmarullgalak
authored andcommitted
drivers: display: ili9xxx: use gpio_dt_spec
Use the recently introduced struct gpio_dt_spec to store GPIO information and operate with them. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 0500ec2 commit 51e53ee

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

drivers/display/display_ili9xxx.c

+19-36
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
LOG_MODULE_REGISTER(display_ili9xxx, CONFIG_DISPLAY_LOG_LEVEL);
1818

1919
struct ili9xxx_data {
20-
const struct device *reset_gpio;
21-
const struct device *command_data_gpio;
2220
const struct device *spi_dev;
2321
struct spi_config spi_config;
2422
struct spi_cs_control cs_ctrl;
@@ -42,8 +40,7 @@ int ili9xxx_transmit(const struct device *dev, uint8_t cmd, const void *tx_data,
4240
tx_buf.buf = &cmd;
4341
tx_buf.len = 1U;
4442

45-
gpio_pin_set(data->command_data_gpio, config->cmd_data_pin,
46-
ILI9XXX_CMD);
43+
gpio_pin_set_dt(&config->cmd_data, ILI9XXX_CMD);
4744
r = spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
4845
if (r < 0) {
4946
return r;
@@ -54,8 +51,7 @@ int ili9xxx_transmit(const struct device *dev, uint8_t cmd, const void *tx_data,
5451
tx_buf.buf = (void *)tx_data;
5552
tx_buf.len = tx_len;
5653

57-
gpio_pin_set(data->command_data_gpio, config->cmd_data_pin,
58-
ILI9XXX_DATA);
54+
gpio_pin_set_dt(&config->cmd_data, ILI9XXX_DATA);
5955
r = spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
6056
if (r < 0) {
6157
return r;
@@ -83,15 +79,14 @@ static void ili9xxx_hw_reset(const struct device *dev)
8379
{
8480
const struct ili9xxx_config *config =
8581
(struct ili9xxx_config *)dev->config;
86-
struct ili9xxx_data *data = (struct ili9xxx_data *)dev->data;
8782

88-
if (data->reset_gpio == NULL) {
83+
if (config->reset.port == NULL) {
8984
return;
9085
}
9186

92-
gpio_pin_set(data->reset_gpio, config->reset_pin, 1);
87+
gpio_pin_set_dt(&config->reset, 1);
9388
k_sleep(K_MSEC(ILI9XXX_RESET_PULSE_TIME));
94-
gpio_pin_set(data->reset_gpio, config->reset_pin, 0);
89+
gpio_pin_set_dt(&config->reset, 0);
9590

9691
k_sleep(K_MSEC(ILI9XXX_RESET_WAIT_TIME));
9792
}
@@ -384,25 +379,24 @@ static int ili9xxx_init(const struct device *dev)
384379
data->spi_config.cs = &data->cs_ctrl;
385380
}
386381

387-
data->command_data_gpio = device_get_binding(config->cmd_data_label);
388-
if (data->command_data_gpio == NULL) {
389-
LOG_ERR("Could not get command/data GPIO port %s",
390-
config->cmd_data_label);
382+
if (!device_is_ready(config->cmd_data.port)) {
383+
LOG_ERR("Command/Data GPIO device not ready");
391384
return -ENODEV;
392385
}
393386

394-
r = gpio_pin_configure(data->command_data_gpio, config->cmd_data_pin,
395-
GPIO_OUTPUT | config->cmd_data_flags);
387+
r = gpio_pin_configure_dt(&config->cmd_data, GPIO_OUTPUT);
396388
if (r < 0) {
397389
LOG_ERR("Could not configure command/data GPIO (%d)", r);
398390
return r;
399391
}
400392

401-
data->reset_gpio = device_get_binding(config->reset_label);
402-
if (data->reset_gpio != NULL) {
403-
r = gpio_pin_configure(data->reset_gpio, config->reset_pin,
404-
GPIO_OUTPUT_INACTIVE |
405-
config->reset_flags);
393+
if (config->reset.port != NULL) {
394+
if (!device_is_ready(config->reset.port)) {
395+
LOG_ERR("Reset GPIO device not ready");
396+
return -ENODEV;
397+
}
398+
399+
r = gpio_pin_configure_dt(&config->reset, GPIO_OUTPUT_INACTIVE);
406400
if (r < 0) {
407401
LOG_ERR("Could not configure reset GPIO (%d)", r);
408402
return r;
@@ -469,21 +463,10 @@ static const struct display_driver_api ili9xxx_api = {
469463
.spi_cs_flags = UTIL_AND( \
470464
DT_SPI_DEV_HAS_CS_GPIOS(INST_DT_ILI9XXX(n, t)), \
471465
DT_SPI_DEV_CS_GPIOS_FLAGS(INST_DT_ILI9XXX(n, t))), \
472-
.cmd_data_label = \
473-
DT_GPIO_LABEL(INST_DT_ILI9XXX(n, t), cmd_data_gpios), \
474-
.cmd_data_pin = \
475-
DT_GPIO_PIN(INST_DT_ILI9XXX(n, t), cmd_data_gpios), \
476-
.cmd_data_flags = \
477-
DT_GPIO_FLAGS(INST_DT_ILI9XXX(n, t), cmd_data_gpios), \
478-
.reset_label = UTIL_AND( \
479-
DT_NODE_HAS_PROP(INST_DT_ILI9XXX(n, t), reset_gpios), \
480-
DT_GPIO_LABEL(INST_DT_ILI9XXX(n, t), reset_gpios)), \
481-
.reset_pin = UTIL_AND( \
482-
DT_NODE_HAS_PROP(INST_DT_ILI9XXX(n, t), reset_gpios), \
483-
DT_GPIO_PIN(INST_DT_ILI9XXX(n, t), reset_gpios)), \
484-
.reset_flags = UTIL_AND( \
485-
DT_NODE_HAS_PROP(INST_DT_ILI9XXX(n, t), reset_gpios), \
486-
DT_GPIO_FLAGS(INST_DT_ILI9XXX(n, t), reset_gpios)), \
466+
.cmd_data = GPIO_DT_SPEC_GET(INST_DT_ILI9XXX(n, t), \
467+
cmd_data_gpios), \
468+
.reset = GPIO_DT_SPEC_GET_OR(INST_DT_ILI9XXX(n, t), \
469+
reset_gpios, {0}), \
487470
.pixel_format = DT_PROP(INST_DT_ILI9XXX(n, t), pixel_format), \
488471
.rotation = DT_PROP(INST_DT_ILI9XXX(n, t), rotation), \
489472
.x_resolution = ILI##t##_X_RES, \

drivers/display/display_ili9xxx.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ struct ili9xxx_config {
6060
const char *spi_cs_label;
6161
gpio_pin_t spi_cs_pin;
6262
gpio_dt_flags_t spi_cs_flags;
63-
const char *cmd_data_label;
64-
gpio_pin_t cmd_data_pin;
65-
gpio_dt_flags_t cmd_data_flags;
66-
const char *reset_label;
67-
gpio_pin_t reset_pin;
68-
gpio_dt_flags_t reset_flags;
63+
struct gpio_dt_spec cmd_data;
64+
struct gpio_dt_spec reset;
6965
uint8_t pixel_format;
7066
uint16_t rotation;
7167
uint16_t x_resolution;

0 commit comments

Comments
 (0)