From 7f5c5cf31734eeff2a5ba0d4c08b3696108da7ea Mon Sep 17 00:00:00 2001 From: Casper Meijn Date: Sun, 4 Jul 2021 16:30:30 +0200 Subject: [PATCH] drivers: display: st7789v: Move params to `struct config` Move the const configuration parameters to `struct st7789v_config`. Signed-off-by: Casper Meijn --- drivers/display/display_st7789v.c | 119 +++++++++++++++++++----------- 1 file changed, 75 insertions(+), 44 deletions(-) diff --git a/drivers/display/display_st7789v.c b/drivers/display/display_st7789v.c index 52cbce614eb..0fc0058cd1c 100644 --- a/drivers/display/display_st7789v.c +++ b/drivers/display/display_st7789v.c @@ -23,25 +23,33 @@ #include LOG_MODULE_REGISTER(display_st7789v); -static uint8_t st7789v_porch_param[] = DT_INST_PROP(0, porch_param); -static uint8_t st7789v_cmd2en_param[] = DT_INST_PROP(0, cmd2en_param); -static uint8_t st7789v_pwctrl1_param[] = DT_INST_PROP(0, pwctrl1_param); -static uint8_t st7789v_pvgam_param[] = DT_INST_PROP(0, pvgam_param); -static uint8_t st7789v_nvgam_param[] = DT_INST_PROP(0, nvgam_param); -static uint8_t st7789v_ram_param[] = DT_INST_PROP(0, ram_param); -static uint8_t st7789v_rgb_param[] = DT_INST_PROP(0, rgb_param); - struct st7789v_config { struct spi_dt_spec bus; struct gpio_dt_spec cmd_data_gpio; #if DT_INST_NODE_HAS_PROP(0, reset_gpios) struct gpio_dt_spec reset_gpio; #endif + uint8_t vcom; + uint8_t gctrl; + bool vdv_vrh_enable; + uint8_t vrh_value; + uint8_t vdv_value; + uint8_t mdac; + uint8_t gamma; + uint8_t colmod; + uint8_t lcm; + uint8_t porch_param[5]; + uint8_t cmd2en_param[4]; + uint8_t pwctrl1_param[2]; + uint8_t pvgam_param[14]; + uint8_t nvgam_param[14]; + uint8_t ram_param[2]; + uint8_t rgb_param[3]; + uint16_t height; + uint16_t width; }; struct st7789v_data { - uint16_t height; - uint16_t width; uint16_t x_offset; uint16_t y_offset; }; @@ -218,11 +226,11 @@ static int st7789v_set_contrast(const struct device *dev, static void st7789v_get_capabilities(const struct device *dev, struct display_capabilities *capabilities) { - struct st7789v_data *data = dev->data; + const struct st7789v_config *config = dev->config; memset(capabilities, 0, sizeof(struct display_capabilities)); - capabilities->x_resolution = data->width; - capabilities->y_resolution = data->height; + capabilities->x_resolution = config->width; + capabilities->y_resolution = config->height; #ifdef CONFIG_ST7789V_RGB565 capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_565; @@ -261,16 +269,19 @@ static int st7789v_set_orientation(const struct device *dev, static void st7789v_lcd_init(const struct device *dev) { struct st7789v_data *data = dev->data; + const struct st7789v_config *config = dev->config; uint8_t tmp; st7789v_set_lcd_margins(dev, data->x_offset, data->y_offset); - st7789v_transmit(dev, ST7789V_CMD_CMD2EN, st7789v_cmd2en_param, - sizeof(st7789v_cmd2en_param)); + st7789v_transmit(dev, ST7789V_CMD_CMD2EN, + (uint8_t *)config->cmd2en_param, + sizeof(config->cmd2en_param)); - st7789v_transmit(dev, ST7789V_CMD_PORCTRL, st7789v_porch_param, - sizeof(st7789v_porch_param)); + st7789v_transmit(dev, ST7789V_CMD_PORCTRL, + (uint8_t *)config->porch_param, + sizeof(config->porch_param)); /* Digital Gamma Enable, default disabled */ tmp = 0x00; @@ -280,54 +291,58 @@ static void st7789v_lcd_init(const struct device *dev) tmp = 0x0f; st7789v_transmit(dev, ST7789V_CMD_FRCTRL2, &tmp, 1); - tmp = DT_INST_PROP(0, gctrl); + tmp = config->gctrl; st7789v_transmit(dev, ST7789V_CMD_GCTRL, &tmp, 1); - tmp = DT_INST_PROP(0, vcom); + tmp = config->vcom; st7789v_transmit(dev, ST7789V_CMD_VCOMS, &tmp, 1); -#if (DT_INST_NODE_HAS_PROP(0, vrhs) && \ - DT_INST_NODE_HAS_PROP(0, vdvs)) - tmp = 0x01; - st7789v_transmit(dev, ST7789V_CMD_VDVVRHEN, &tmp, 1); + if (config->vdv_vrh_enable) { + tmp = 0x01; + st7789v_transmit(dev, ST7789V_CMD_VDVVRHEN, &tmp, 1); - tmp = DT_INST_PROP(0, vrhs); - st7789v_transmit(dev, ST7789V_CMD_VRH, &tmp, 1); + tmp = config->vrh_value; + st7789v_transmit(dev, ST7789V_CMD_VRH, &tmp, 1); - tmp = DT_INST_PROP(0, vdvs); - st7789v_transmit(dev, ST7789V_CMD_VDS, &tmp, 1); -#endif + tmp = config->vdv_value; + st7789v_transmit(dev, ST7789V_CMD_VDS, &tmp, 1); + } - st7789v_transmit(dev, ST7789V_CMD_PWCTRL1, st7789v_pwctrl1_param, - sizeof(st7789v_pwctrl1_param)); + st7789v_transmit(dev, ST7789V_CMD_PWCTRL1, + (uint8_t *)config->pwctrl1_param, + sizeof(config->pwctrl1_param)); /* Memory Data Access Control */ - tmp = DT_INST_PROP(0, mdac); + tmp = config->mdac; st7789v_transmit(dev, ST7789V_CMD_MADCTL, &tmp, 1); /* Interface Pixel Format */ - tmp = DT_INST_PROP(0, colmod); + tmp = config->colmod; st7789v_transmit(dev, ST7789V_CMD_COLMOD, &tmp, 1); - tmp = DT_INST_PROP(0, lcm); + tmp = config->lcm; st7789v_transmit(dev, ST7789V_CMD_LCMCTRL, &tmp, 1); - tmp = DT_INST_PROP(0, gamma); + tmp = config->gamma; st7789v_transmit(dev, ST7789V_CMD_GAMSET, &tmp, 1); st7789v_transmit(dev, ST7789V_CMD_INV_ON, NULL, 0); - st7789v_transmit(dev, ST7789V_CMD_PVGAMCTRL, st7789v_pvgam_param, - sizeof(st7789v_pvgam_param)); + st7789v_transmit(dev, ST7789V_CMD_PVGAMCTRL, + (uint8_t *)config->pvgam_param, + sizeof(config->pvgam_param)); - st7789v_transmit(dev, ST7789V_CMD_NVGAMCTRL, st7789v_nvgam_param, - sizeof(st7789v_nvgam_param)); + st7789v_transmit(dev, ST7789V_CMD_NVGAMCTRL, + (uint8_t *)config->nvgam_param, + sizeof(config->nvgam_param)); - st7789v_transmit(dev, ST7789V_CMD_RAMCTRL, st7789v_ram_param, - sizeof(st7789v_ram_param)); + st7789v_transmit(dev, ST7789V_CMD_RAMCTRL, + (uint8_t *)config->ram_param, + sizeof(config->ram_param)); - st7789v_transmit(dev, ST7789V_CMD_RGBCTRL, st7789v_rgb_param, - sizeof(st7789v_rgb_param)); + st7789v_transmit(dev, ST7789V_CMD_RGBCTRL, + (uint8_t *)config->rgb_param, + sizeof(config->rgb_param)); } static int st7789v_init(const struct device *dev) @@ -413,11 +428,27 @@ static const struct st7789v_config st7789v_config = { #if DT_INST_NODE_HAS_PROP(0, reset_gpios) .reset_gpio = GPIO_DT_SPEC_INST_GET(0, reset_gpios), #endif + .vcom = DT_INST_PROP(0, vcom), + .gctrl = DT_INST_PROP(0, gctrl), + .vdv_vrh_enable = (DT_INST_NODE_HAS_PROP(0, vrhs) && DT_INST_NODE_HAS_PROP(0, vdvs)), + .vrh_value = DT_INST_PROP_OR(0, vrhs, 0), + .vdv_value = DT_INST_PROP_OR(0, vdvs, 0), + .mdac = DT_INST_PROP(0, mdac), + .gamma = DT_INST_PROP(0, gamma), + .colmod = DT_INST_PROP(0, colmod), + .lcm = DT_INST_PROP(0, lcm), + .porch_param = DT_INST_PROP(0, porch_param), + .cmd2en_param = DT_INST_PROP(0, cmd2en_param), + .pwctrl1_param = DT_INST_PROP(0, pwctrl1_param), + .pvgam_param = DT_INST_PROP(0, pvgam_param), + .nvgam_param = DT_INST_PROP(0, nvgam_param), + .ram_param = DT_INST_PROP(0, ram_param), + .rgb_param = DT_INST_PROP(0, rgb_param), + .width = DT_INST_PROP(0, width), + .height = DT_INST_PROP(0, height), }; static struct st7789v_data st7789v_data = { - .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), };