drivers: display: ili9340: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h DT_INST macro APIs. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
70a0063b69
commit
ee4026baba
1 changed files with 23 additions and 21 deletions
|
@ -5,6 +5,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT ilitek_ili9340
|
||||
|
||||
#include "display_ili9340.h"
|
||||
#include <drivers/display.h>
|
||||
|
||||
|
@ -18,13 +20,13 @@ LOG_MODULE_REGISTER(display_ili9340);
|
|||
#include <string.h>
|
||||
|
||||
struct ili9340_data {
|
||||
#ifdef DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_CONTROLLER
|
||||
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||
struct device *reset_gpio;
|
||||
#endif
|
||||
struct device *command_data_gpio;
|
||||
struct device *spi_dev;
|
||||
struct spi_config spi_config;
|
||||
#ifdef DT_INST_0_ILITEK_ILI9340_CS_GPIOS_CONTROLLER
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
struct spi_cs_control cs_ctrl;
|
||||
#endif
|
||||
};
|
||||
|
@ -51,58 +53,58 @@ static int ili9340_init(struct device *dev)
|
|||
|
||||
LOG_DBG("Initializing display driver");
|
||||
|
||||
data->spi_dev = device_get_binding(DT_INST_0_ILITEK_ILI9340_BUS_NAME);
|
||||
data->spi_dev = device_get_binding(DT_INST_BUS_LABEL(0));
|
||||
if (data->spi_dev == NULL) {
|
||||
LOG_ERR("Could not get SPI device for ILI9340");
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
data->spi_config.frequency = DT_INST_0_ILITEK_ILI9340_SPI_MAX_FREQUENCY;
|
||||
data->spi_config.frequency = DT_INST_PROP(0, spi_max_frequency);
|
||||
data->spi_config.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
|
||||
data->spi_config.slave = DT_INST_0_ILITEK_ILI9340_BASE_ADDRESS;
|
||||
data->spi_config.slave = DT_INST_REG_ADDR(0);
|
||||
|
||||
#ifdef DT_INST_0_ILITEK_ILI9340_CS_GPIOS_CONTROLLER
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
data->cs_ctrl.gpio_dev =
|
||||
device_get_binding(DT_INST_0_ILITEK_ILI9340_CS_GPIOS_CONTROLLER);
|
||||
data->cs_ctrl.gpio_pin = DT_INST_0_ILITEK_ILI9340_CS_GPIOS_PIN;
|
||||
device_get_binding(DT_INST_SPI_DEV_CS_GPIOS_LABEL(0));
|
||||
data->cs_ctrl.gpio_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(0);
|
||||
data->cs_ctrl.delay = 0U;
|
||||
data->spi_config.cs = &(data->cs_ctrl);
|
||||
#else
|
||||
data->spi_config.cs = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_CONTROLLER
|
||||
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||
data->reset_gpio =
|
||||
device_get_binding(DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_CONTROLLER);
|
||||
device_get_binding(DT_INST_GPIO_LABEL(0, reset_gpios));
|
||||
if (data->reset_gpio == NULL) {
|
||||
LOG_ERR("Could not get GPIO port for ILI9340 reset");
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
gpio_pin_configure(data->reset_gpio, DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN,
|
||||
gpio_pin_configure(data->reset_gpio, DT_INST_GPIO_PIN(0, reset_gpios),
|
||||
GPIO_OUTPUT_INACTIVE |
|
||||
DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_FLAGS);
|
||||
DT_INST_GPIO_FLAGS(0, reset_gpios));
|
||||
#endif
|
||||
|
||||
data->command_data_gpio =
|
||||
device_get_binding(DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_CONTROLLER);
|
||||
device_get_binding(DT_INST_GPIO_LABEL(0, cmd_data_gpios));
|
||||
if (data->command_data_gpio == NULL) {
|
||||
LOG_ERR("Could not get GPIO port for ILI9340 command/data");
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
gpio_pin_configure(data->command_data_gpio, DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN,
|
||||
gpio_pin_configure(data->command_data_gpio, DT_INST_GPIO_PIN(0, cmd_data_gpios),
|
||||
GPIO_OUTPUT |
|
||||
DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_FLAGS);
|
||||
DT_INST_GPIO_FLAGS(0, cmd_data_gpios));
|
||||
|
||||
#ifdef DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_CONTROLLER
|
||||
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||
LOG_DBG("Resetting display driver");
|
||||
k_sleep(K_MSEC(1));
|
||||
gpio_pin_set(data->reset_gpio,
|
||||
DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, 1);
|
||||
DT_INST_GPIO_PIN(0, reset_gpios), 1);
|
||||
k_sleep(K_MSEC(1));
|
||||
gpio_pin_set(data->reset_gpio,
|
||||
DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, 0);
|
||||
DT_INST_GPIO_PIN(0, reset_gpios), 0);
|
||||
k_sleep(K_MSEC(5));
|
||||
#endif
|
||||
|
||||
|
@ -270,7 +272,7 @@ void ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data,
|
|||
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 };
|
||||
|
||||
gpio_pin_set(data->command_data_gpio,
|
||||
DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN,
|
||||
DT_INST_GPIO_PIN(0, cmd_data_gpios),
|
||||
ILI9340_CMD_DATA_PIN_COMMAND);
|
||||
spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
|
||||
|
||||
|
@ -278,7 +280,7 @@ void ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data,
|
|||
tx_buf.buf = tx_data;
|
||||
tx_buf.len = tx_len;
|
||||
gpio_pin_set(data->command_data_gpio,
|
||||
DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN,
|
||||
DT_INST_GPIO_PIN(0, cmd_data_gpios),
|
||||
ILI9340_CMD_DATA_PIN_DATA);
|
||||
spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
|
||||
}
|
||||
|
@ -299,6 +301,6 @@ static const struct display_driver_api ili9340_api = {
|
|||
|
||||
static struct ili9340_data ili9340_data;
|
||||
|
||||
DEVICE_AND_API_INIT(ili9340, DT_INST_0_ILITEK_ILI9340_LABEL, &ili9340_init,
|
||||
DEVICE_AND_API_INIT(ili9340, DT_INST_LABEL(0), &ili9340_init,
|
||||
&ili9340_data, NULL, APPLICATION,
|
||||
CONFIG_APPLICATION_INIT_PRIORITY, &ili9340_api);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue