drivers: ili9340: convert to new GPIO API

Convert ILI9340 display driver to new GPIO API.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This commit is contained in:
Johann Fischer 2020-01-23 18:48:32 +01:00 committed by Carles Cufí
commit 64f5e23b47
2 changed files with 17 additions and 13 deletions

View file

@ -14,6 +14,6 @@
label = "ILI9340"; label = "ILI9340";
spi-max-frequency = <15151515>; spi-max-frequency = <15151515>;
reg = <0>; reg = <0>;
cmd-data-gpios = <&arduino_header 15 0>; /* D9 */ cmd-data-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */
}; };
}; };

View file

@ -29,8 +29,8 @@ struct ili9340_data {
#endif #endif
}; };
#define ILI9340_CMD_DATA_PIN_COMMAND 0 #define ILI9340_CMD_DATA_PIN_COMMAND 1
#define ILI9340_CMD_DATA_PIN_DATA 1 #define ILI9340_CMD_DATA_PIN_DATA 0
/* The number of bytes taken by a RGB pixel */ /* The number of bytes taken by a RGB pixel */
#ifdef CONFIG_ILI9340_RGB565 #ifdef CONFIG_ILI9340_RGB565
@ -80,7 +80,8 @@ static int ili9340_init(struct device *dev)
} }
gpio_pin_configure(data->reset_gpio, DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, gpio_pin_configure(data->reset_gpio, DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN,
GPIO_DIR_OUT); GPIO_OUTPUT_INACTIVE |
DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_FLAGS);
#endif #endif
data->command_data_gpio = data->command_data_gpio =
@ -91,15 +92,17 @@ static int ili9340_init(struct device *dev)
} }
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_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN,
GPIO_DIR_OUT); GPIO_OUTPUT |
DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_FLAGS);
#ifdef DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_CONTROLLER #ifdef DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_CONTROLLER
LOG_DBG("Resetting display driver"); LOG_DBG("Resetting display driver");
gpio_pin_write(data->reset_gpio, DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, 1);
k_sleep(K_MSEC(1)); k_sleep(K_MSEC(1));
gpio_pin_write(data->reset_gpio, DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, 0); gpio_pin_set(data->reset_gpio,
DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, 1);
k_sleep(K_MSEC(1)); k_sleep(K_MSEC(1));
gpio_pin_write(data->reset_gpio, DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, 1); gpio_pin_set(data->reset_gpio,
DT_INST_0_ILITEK_ILI9340_RESET_GPIOS_PIN, 0);
k_sleep(K_MSEC(5)); k_sleep(K_MSEC(5));
#endif #endif
@ -266,16 +269,17 @@ void ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data,
struct spi_buf tx_buf = { .buf = &cmd, .len = 1 }; struct spi_buf tx_buf = { .buf = &cmd, .len = 1 };
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 }; struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 };
gpio_pin_write(data->command_data_gpio, DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN, gpio_pin_set(data->command_data_gpio,
ILI9340_CMD_DATA_PIN_COMMAND); DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_COMMAND);
spi_write(data->spi_dev, &data->spi_config, &tx_bufs); spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
if (tx_data != NULL) { if (tx_data != NULL) {
tx_buf.buf = tx_data; tx_buf.buf = tx_data;
tx_buf.len = tx_len; tx_buf.len = tx_len;
gpio_pin_write(data->command_data_gpio, gpio_pin_set(data->command_data_gpio,
DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN, DT_INST_0_ILITEK_ILI9340_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_DATA); ILI9340_CMD_DATA_PIN_DATA);
spi_write(data->spi_dev, &data->spi_config, &tx_bufs); spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
} }
} }