drivers: display: st7789v: Move params to struct config

Move the const configuration parameters to `struct st7789v_config`.

Signed-off-by: Casper Meijn <casper@meijn.net>
This commit is contained in:
Casper Meijn 2021-07-04 16:30:30 +02:00 committed by Carles Cufí
commit 7f5c5cf317

View file

@ -23,25 +23,33 @@
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_REGISTER(display_st7789v); 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 st7789v_config {
struct spi_dt_spec bus; struct spi_dt_spec bus;
struct gpio_dt_spec cmd_data_gpio; struct gpio_dt_spec cmd_data_gpio;
#if DT_INST_NODE_HAS_PROP(0, reset_gpios) #if DT_INST_NODE_HAS_PROP(0, reset_gpios)
struct gpio_dt_spec reset_gpio; struct gpio_dt_spec reset_gpio;
#endif #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 { struct st7789v_data {
uint16_t height;
uint16_t width;
uint16_t x_offset; uint16_t x_offset;
uint16_t y_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, static void st7789v_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities) struct display_capabilities *capabilities)
{ {
struct st7789v_data *data = dev->data; const struct st7789v_config *config = dev->config;
memset(capabilities, 0, sizeof(struct display_capabilities)); memset(capabilities, 0, sizeof(struct display_capabilities));
capabilities->x_resolution = data->width; capabilities->x_resolution = config->width;
capabilities->y_resolution = data->height; capabilities->y_resolution = config->height;
#ifdef CONFIG_ST7789V_RGB565 #ifdef CONFIG_ST7789V_RGB565
capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_565; 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) static void st7789v_lcd_init(const struct device *dev)
{ {
struct st7789v_data *data = dev->data; struct st7789v_data *data = dev->data;
const struct st7789v_config *config = dev->config;
uint8_t tmp; uint8_t tmp;
st7789v_set_lcd_margins(dev, data->x_offset, st7789v_set_lcd_margins(dev, data->x_offset,
data->y_offset); data->y_offset);
st7789v_transmit(dev, ST7789V_CMD_CMD2EN, st7789v_cmd2en_param, st7789v_transmit(dev, ST7789V_CMD_CMD2EN,
sizeof(st7789v_cmd2en_param)); (uint8_t *)config->cmd2en_param,
sizeof(config->cmd2en_param));
st7789v_transmit(dev, ST7789V_CMD_PORCTRL, st7789v_porch_param, st7789v_transmit(dev, ST7789V_CMD_PORCTRL,
sizeof(st7789v_porch_param)); (uint8_t *)config->porch_param,
sizeof(config->porch_param));
/* Digital Gamma Enable, default disabled */ /* Digital Gamma Enable, default disabled */
tmp = 0x00; tmp = 0x00;
@ -280,54 +291,58 @@ static void st7789v_lcd_init(const struct device *dev)
tmp = 0x0f; tmp = 0x0f;
st7789v_transmit(dev, ST7789V_CMD_FRCTRL2, &tmp, 1); 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); 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); st7789v_transmit(dev, ST7789V_CMD_VCOMS, &tmp, 1);
#if (DT_INST_NODE_HAS_PROP(0, vrhs) && \ if (config->vdv_vrh_enable) {
DT_INST_NODE_HAS_PROP(0, vdvs)) tmp = 0x01;
tmp = 0x01; st7789v_transmit(dev, ST7789V_CMD_VDVVRHEN, &tmp, 1);
st7789v_transmit(dev, ST7789V_CMD_VDVVRHEN, &tmp, 1);
tmp = DT_INST_PROP(0, vrhs); tmp = config->vrh_value;
st7789v_transmit(dev, ST7789V_CMD_VRH, &tmp, 1); st7789v_transmit(dev, ST7789V_CMD_VRH, &tmp, 1);
tmp = DT_INST_PROP(0, vdvs); tmp = config->vdv_value;
st7789v_transmit(dev, ST7789V_CMD_VDS, &tmp, 1); st7789v_transmit(dev, ST7789V_CMD_VDS, &tmp, 1);
#endif }
st7789v_transmit(dev, ST7789V_CMD_PWCTRL1, st7789v_pwctrl1_param, st7789v_transmit(dev, ST7789V_CMD_PWCTRL1,
sizeof(st7789v_pwctrl1_param)); (uint8_t *)config->pwctrl1_param,
sizeof(config->pwctrl1_param));
/* Memory Data Access Control */ /* Memory Data Access Control */
tmp = DT_INST_PROP(0, mdac); tmp = config->mdac;
st7789v_transmit(dev, ST7789V_CMD_MADCTL, &tmp, 1); st7789v_transmit(dev, ST7789V_CMD_MADCTL, &tmp, 1);
/* Interface Pixel Format */ /* Interface Pixel Format */
tmp = DT_INST_PROP(0, colmod); tmp = config->colmod;
st7789v_transmit(dev, ST7789V_CMD_COLMOD, &tmp, 1); 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); 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_GAMSET, &tmp, 1);
st7789v_transmit(dev, ST7789V_CMD_INV_ON, NULL, 0); st7789v_transmit(dev, ST7789V_CMD_INV_ON, NULL, 0);
st7789v_transmit(dev, ST7789V_CMD_PVGAMCTRL, st7789v_pvgam_param, st7789v_transmit(dev, ST7789V_CMD_PVGAMCTRL,
sizeof(st7789v_pvgam_param)); (uint8_t *)config->pvgam_param,
sizeof(config->pvgam_param));
st7789v_transmit(dev, ST7789V_CMD_NVGAMCTRL, st7789v_nvgam_param, st7789v_transmit(dev, ST7789V_CMD_NVGAMCTRL,
sizeof(st7789v_nvgam_param)); (uint8_t *)config->nvgam_param,
sizeof(config->nvgam_param));
st7789v_transmit(dev, ST7789V_CMD_RAMCTRL, st7789v_ram_param, st7789v_transmit(dev, ST7789V_CMD_RAMCTRL,
sizeof(st7789v_ram_param)); (uint8_t *)config->ram_param,
sizeof(config->ram_param));
st7789v_transmit(dev, ST7789V_CMD_RGBCTRL, st7789v_rgb_param, st7789v_transmit(dev, ST7789V_CMD_RGBCTRL,
sizeof(st7789v_rgb_param)); (uint8_t *)config->rgb_param,
sizeof(config->rgb_param));
} }
static int st7789v_init(const struct device *dev) 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) #if DT_INST_NODE_HAS_PROP(0, reset_gpios)
.reset_gpio = GPIO_DT_SPEC_INST_GET(0, reset_gpios), .reset_gpio = GPIO_DT_SPEC_INST_GET(0, reset_gpios),
#endif #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 = { 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), .x_offset = DT_INST_PROP(0, x_offset),
.y_offset = DT_INST_PROP(0, y_offset), .y_offset = DT_INST_PROP(0, y_offset),
}; };