drivers: display: st7789v: 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
ee4026baba
commit
09b1cd90d8
1 changed files with 41 additions and 39 deletions
|
@ -7,6 +7,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT sitronix_st7789v
|
||||
|
||||
#include "display_st7789v.h"
|
||||
|
||||
#include <device.h>
|
||||
|
@ -19,28 +21,28 @@
|
|||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(display_st7789v);
|
||||
|
||||
#define ST7789V_CS_PIN DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_PIN
|
||||
#define ST7789V_CMD_DATA_PIN DT_INST_0_SITRONIX_ST7789V_CMD_DATA_GPIOS_PIN
|
||||
#define ST7789V_CMD_DATA_FLAGS DT_INST_0_SITRONIX_ST7789V_CMD_DATA_GPIOS_FLAGS
|
||||
#define ST7789V_RESET_PIN DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_PIN
|
||||
#define ST7789V_RESET_FLAGS DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_FLAGS
|
||||
#define ST7789V_CS_PIN DT_INST_SPI_DEV_CS_GPIOS_PIN(0)
|
||||
#define ST7789V_CMD_DATA_PIN DT_INST_GPIO_PIN(0, cmd_data_gpios)
|
||||
#define ST7789V_CMD_DATA_FLAGS DT_INST_GPIO_FLAGS(0, cmd_data_gpios)
|
||||
#define ST7789V_RESET_PIN DT_INST_GPIO_PIN(0, reset_gpios)
|
||||
#define ST7789V_RESET_FLAGS DT_INST_GPIO_FLAGS(0, reset_gpios)
|
||||
|
||||
static u8_t st7789v_porch_param[] = DT_INST_0_SITRONIX_ST7789V_PORCH_PARAM;
|
||||
static u8_t st7789v_cmd2en_param[] = DT_INST_0_SITRONIX_ST7789V_CMD2EN_PARAM;
|
||||
static u8_t st7789v_pwctrl1_param[] = DT_INST_0_SITRONIX_ST7789V_PWCTRL1_PARAM;
|
||||
static u8_t st7789v_pvgam_param[] = DT_INST_0_SITRONIX_ST7789V_PVGAM_PARAM;
|
||||
static u8_t st7789v_nvgam_param[] = DT_INST_0_SITRONIX_ST7789V_NVGAM_PARAM;
|
||||
static u8_t st7789v_ram_param[] = DT_INST_0_SITRONIX_ST7789V_RAM_PARAM;
|
||||
static u8_t st7789v_rgb_param[] = DT_INST_0_SITRONIX_ST7789V_RGB_PARAM;
|
||||
static u8_t st7789v_porch_param[] = DT_INST_PROP(0, porch_param);
|
||||
static u8_t st7789v_cmd2en_param[] = DT_INST_PROP(0, cmd2en_param);
|
||||
static u8_t st7789v_pwctrl1_param[] = DT_INST_PROP(0, pwctrl1_param);
|
||||
static u8_t st7789v_pvgam_param[] = DT_INST_PROP(0, pvgam_param);
|
||||
static u8_t st7789v_nvgam_param[] = DT_INST_PROP(0, nvgam_param);
|
||||
static u8_t st7789v_ram_param[] = DT_INST_PROP(0, ram_param);
|
||||
static u8_t st7789v_rgb_param[] = DT_INST_PROP(0, rgb_param);
|
||||
|
||||
struct st7789v_data {
|
||||
struct device *spi_dev;
|
||||
struct spi_config spi_config;
|
||||
#ifdef DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_CONTROLLER
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
struct spi_cs_control cs_ctrl;
|
||||
#endif
|
||||
|
||||
#ifdef DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER
|
||||
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||
struct device *reset_gpio;
|
||||
#endif
|
||||
struct device *cmd_data_gpio;
|
||||
|
@ -95,7 +97,7 @@ static void st7789v_exit_sleep(struct st7789v_data *data)
|
|||
static void st7789v_reset_display(struct st7789v_data *data)
|
||||
{
|
||||
LOG_DBG("Resetting display");
|
||||
#ifdef DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER
|
||||
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||
k_sleep(K_MSEC(1));
|
||||
gpio_pin_set(data->reset_gpio, ST7789V_RESET_PIN, 1);
|
||||
k_sleep(K_MSEC(6));
|
||||
|
@ -277,21 +279,21 @@ static void st7789v_lcd_init(struct st7789v_data *p_st7789v)
|
|||
tmp = 0x0f;
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_FRCTRL2, &tmp, 1);
|
||||
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_GCTRL;
|
||||
tmp = DT_INST_PROP(0, gctrl);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_GCTRL, &tmp, 1);
|
||||
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_VCOM;
|
||||
tmp = DT_INST_PROP(0, vcom);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_VCOMS, &tmp, 1);
|
||||
|
||||
#if (defined(DT_INST_0_SITRONIX_ST7789V_VRHS) && \
|
||||
defined(DT_INST_0_SITRONIX_ST7789V_VDVS))
|
||||
#if (DT_INST_NODE_HAS_PROP(0, vrhs) && \
|
||||
DT_INST_NODE_HAS_PROP(0, vdvs))
|
||||
tmp = 0x01;
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_VDVVRHEN, &tmp, 1);
|
||||
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_VRHS;
|
||||
tmp = DT_INST_PROP(0, vrhs);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_VRH, &tmp, 1);
|
||||
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_VDVS;
|
||||
tmp = DT_INST_PROP(0, vdvs);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_VDS, &tmp, 1);
|
||||
#endif
|
||||
|
||||
|
@ -299,17 +301,17 @@ static void st7789v_lcd_init(struct st7789v_data *p_st7789v)
|
|||
sizeof(st7789v_pwctrl1_param));
|
||||
|
||||
/* Memory Data Access Control */
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_MDAC;
|
||||
tmp = DT_INST_PROP(0, mdac);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_MADCTL, &tmp, 1);
|
||||
|
||||
/* Interface Pixel Format */
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_COLMOD;
|
||||
tmp = DT_INST_PROP(0, colmod);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_COLMOD, &tmp, 1);
|
||||
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_LCM;
|
||||
tmp = DT_INST_PROP(0, lcm);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_LCMCTRL, &tmp, 1);
|
||||
|
||||
tmp = DT_INST_0_SITRONIX_ST7789V_GAMMA;
|
||||
tmp = DT_INST_PROP(0, gamma);
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_GAMSET, &tmp, 1);
|
||||
|
||||
st7789v_transmit(p_st7789v, ST7789V_CMD_INV_ON, NULL, 0);
|
||||
|
@ -331,30 +333,30 @@ static int st7789v_init(struct device *dev)
|
|||
{
|
||||
struct st7789v_data *data = (struct st7789v_data *)dev->driver_data;
|
||||
|
||||
data->spi_dev = device_get_binding(DT_INST_0_SITRONIX_ST7789V_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 LCD");
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
data->spi_config.frequency =
|
||||
DT_INST_0_SITRONIX_ST7789V_SPI_MAX_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_SITRONIX_ST7789V_BASE_ADDRESS;
|
||||
data->spi_config.slave = DT_INST_REG_ADDR(0);
|
||||
|
||||
#ifdef DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_CONTROLLER
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
data->cs_ctrl.gpio_dev = device_get_binding(
|
||||
DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_CONTROLLER);
|
||||
data->cs_ctrl.gpio_pin = DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_PIN;
|
||||
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_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER
|
||||
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||
data->reset_gpio = device_get_binding(
|
||||
DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER);
|
||||
DT_INST_GPIO_LABEL(0, reset_gpios));
|
||||
if (data->reset_gpio == NULL) {
|
||||
LOG_ERR("Could not get GPIO port for display reset");
|
||||
return -EPERM;
|
||||
|
@ -368,7 +370,7 @@ static int st7789v_init(struct device *dev)
|
|||
#endif
|
||||
|
||||
data->cmd_data_gpio = device_get_binding(
|
||||
DT_INST_0_SITRONIX_ST7789V_CMD_DATA_GPIOS_CONTROLLER);
|
||||
DT_INST_GPIO_LABEL(0, cmd_data_gpios));
|
||||
if (data->cmd_data_gpio == NULL) {
|
||||
LOG_ERR("Could not get GPIO port for cmd/DATA port");
|
||||
return -EPERM;
|
||||
|
@ -404,12 +406,12 @@ static const struct display_driver_api st7789v_api = {
|
|||
};
|
||||
|
||||
static struct st7789v_data st7789v_data = {
|
||||
.width = DT_INST_0_SITRONIX_ST7789V_WIDTH,
|
||||
.height = DT_INST_0_SITRONIX_ST7789V_HEIGHT,
|
||||
.x_offset = DT_INST_0_SITRONIX_ST7789V_X_OFFSET,
|
||||
.y_offset = DT_INST_0_SITRONIX_ST7789V_Y_OFFSET,
|
||||
.width = DT_INST_PROP(0, width),
|
||||
.height = DT_INST_PROP(0, height),
|
||||
.x_offset = DT_INST_PROP(0, x_offset),
|
||||
.y_offset = DT_INST_PROP(0, y_offset),
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(st7789v, DT_INST_0_SITRONIX_ST7789V_LABEL, &st7789v_init,
|
||||
DEVICE_AND_API_INIT(st7789v, DT_INST_LABEL(0), &st7789v_init,
|
||||
&st7789v_data, NULL, APPLICATION,
|
||||
CONFIG_APPLICATION_INIT_PRIORITY, &st7789v_api);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue