17
17
LOG_MODULE_REGISTER (display_ili9xxx , CONFIG_DISPLAY_LOG_LEVEL );
18
18
19
19
struct ili9xxx_data {
20
- const struct device * reset_gpio ;
21
- const struct device * command_data_gpio ;
22
20
const struct device * spi_dev ;
23
21
struct spi_config spi_config ;
24
22
struct spi_cs_control cs_ctrl ;
@@ -42,8 +40,7 @@ int ili9xxx_transmit(const struct device *dev, uint8_t cmd, const void *tx_data,
42
40
tx_buf .buf = & cmd ;
43
41
tx_buf .len = 1U ;
44
42
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 );
47
44
r = spi_write (data -> spi_dev , & data -> spi_config , & tx_bufs );
48
45
if (r < 0 ) {
49
46
return r ;
@@ -54,8 +51,7 @@ int ili9xxx_transmit(const struct device *dev, uint8_t cmd, const void *tx_data,
54
51
tx_buf .buf = (void * )tx_data ;
55
52
tx_buf .len = tx_len ;
56
53
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 );
59
55
r = spi_write (data -> spi_dev , & data -> spi_config , & tx_bufs );
60
56
if (r < 0 ) {
61
57
return r ;
@@ -83,15 +79,14 @@ static void ili9xxx_hw_reset(const struct device *dev)
83
79
{
84
80
const struct ili9xxx_config * config =
85
81
(struct ili9xxx_config * )dev -> config ;
86
- struct ili9xxx_data * data = (struct ili9xxx_data * )dev -> data ;
87
82
88
- if (data -> reset_gpio == NULL ) {
83
+ if (config -> reset . port == NULL ) {
89
84
return ;
90
85
}
91
86
92
- gpio_pin_set ( data -> reset_gpio , config -> reset_pin , 1 );
87
+ gpio_pin_set_dt ( & config -> reset , 1 );
93
88
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 );
95
90
96
91
k_sleep (K_MSEC (ILI9XXX_RESET_WAIT_TIME ));
97
92
}
@@ -384,25 +379,24 @@ static int ili9xxx_init(const struct device *dev)
384
379
data -> spi_config .cs = & data -> cs_ctrl ;
385
380
}
386
381
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" );
391
384
return - ENODEV ;
392
385
}
393
386
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 );
396
388
if (r < 0 ) {
397
389
LOG_ERR ("Could not configure command/data GPIO (%d)" , r );
398
390
return r ;
399
391
}
400
392
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 );
406
400
if (r < 0 ) {
407
401
LOG_ERR ("Could not configure reset GPIO (%d)" , r );
408
402
return r ;
@@ -469,21 +463,10 @@ static const struct display_driver_api ili9xxx_api = {
469
463
.spi_cs_flags = UTIL_AND( \
470
464
DT_SPI_DEV_HAS_CS_GPIOS(INST_DT_ILI9XXX(n, t)), \
471
465
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}), \
487
470
.pixel_format = DT_PROP(INST_DT_ILI9XXX(n, t), pixel_format), \
488
471
.rotation = DT_PROP(INST_DT_ILI9XXX(n, t), rotation), \
489
472
.x_resolution = ILI##t##_X_RES, \
0 commit comments