drivers: display: ili9340: move gamma parameters to DT

Move gamma curve and correction registers GAMSET, PGAMCTRL and NGAMCTRL
to DT.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2020-09-15 14:44:46 +02:00 committed by Maureen Helm
commit a1ce0c851d
8 changed files with 89 additions and 100 deletions

View file

@ -36,8 +36,11 @@ struct ili9340_config {
gpio_dt_flags_t reset_flags;
uint8_t pixel_format;
uint16_t rotation;
uint8_t gamset[ILI9340_GAMSET_LEN];
uint8_t pwctrl1[ILI9340_PWCTRL1_LEN];
uint8_t pwctrl2[ILI9340_PWCTRL2_LEN];
uint8_t pgamctrl[ILI9340_PGAMCTRL_LEN];
uint8_t ngamctrl[ILI9340_NGAMCTRL_LEN];
};
struct ili9340_data {
@ -363,6 +366,14 @@ static int ili9340_configure(const struct device *dev)
return r;
}
LOG_HEXDUMP_DBG(config->gamset, ILI9340_GAMSET_LEN, "GAMSET");
memcpy(tx_data, config->gamset, ILI9340_GAMSET_LEN);
r = ili9340_transmit(dev, ILI9340_CMD_GAMMA_SET, tx_data,
ILI9340_GAMSET_LEN);
if (r < 0) {
return r;
}
LOG_HEXDUMP_DBG(config->pwctrl1, ILI9340_PWCTRL1_LEN, "PWCTRL1");
memcpy(tx_data, config->pwctrl1, ILI9340_PWCTRL1_LEN);
r = ili9340_transmit(dev, ILI9340_CMD_POWER_CTRL_1, tx_data,
@ -379,6 +390,22 @@ static int ili9340_configure(const struct device *dev)
return r;
}
LOG_HEXDUMP_DBG(config->pgamctrl, ILI9340_PGAMCTRL_LEN, "PGAMCTRL");
memcpy(tx_data, config->pgamctrl, ILI9340_PGAMCTRL_LEN);
r = ili9340_transmit(dev, ILI9340_CMD_POSITIVE_GAMMA_CORRECTION,
tx_data, ILI9340_PGAMCTRL_LEN);
if (r < 0) {
return r;
}
LOG_HEXDUMP_DBG(config->ngamctrl, ILI9340_NGAMCTRL_LEN, "NGAMCTRL");
memcpy(tx_data, config->ngamctrl, ILI9340_NGAMCTRL_LEN);
r = ili9340_transmit(dev, ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION,
tx_data, ILI9340_NGAMCTRL_LEN);
if (r < 0) {
return r;
}
return 0;
}
@ -497,8 +524,11 @@ static const struct display_driver_api ili9340_api = {
DT_INST_GPIO_FLAGS(index, reset_gpios)), \
.pixel_format = DT_INST_PROP(index, pixel_format), \
.rotation = DT_INST_PROP(index, rotation), \
.gamset = DT_INST_PROP(index, gamset), \
.pwctrl1 = DT_INST_PROP(index, pwctrl1), \
.pwctrl2 = DT_INST_PROP(index, pwctrl2), \
.pgamctrl = DT_INST_PROP(index, pgamctrl), \
.ngamctrl = DT_INST_PROP(index, ngamctrl), \
}; \
\
static struct ili9340_data ili9340_data_##index; \

View file

@ -39,8 +39,11 @@
#define ILI9341_CMD_ENABLE_3G 0xF2
#define ILI9341_CMD_PUMP_RATIO_CTRL 0xF7
#define ILI9340_GAMSET_LEN 1U
#define ILI9340_PWCTRL1_LEN 2U
#define ILI9340_PWCTRL2_LEN 1U
#define ILI9340_PGAMCTRL_LEN 15U
#define ILI9340_NGAMCTRL_LEN 15U
#define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80
#define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40

View file

@ -39,53 +39,5 @@ int ili9340_lcd_init(const struct device *dev)
return r;
}
tx_data[0] = 0x01;
r = ili9340_transmit(dev, ILI9340_CMD_GAMMA_SET, tx_data, 1);
if (r < 0) {
return r;
}
tx_data[0] = 0x0F;
tx_data[1] = 0x31;
tx_data[2] = 0x2B;
tx_data[3] = 0x0C;
tx_data[4] = 0x0E;
tx_data[5] = 0x08;
tx_data[6] = 0x4E;
tx_data[7] = 0xF1;
tx_data[8] = 0x37;
tx_data[9] = 0x07;
tx_data[10] = 0x10;
tx_data[11] = 0x03;
tx_data[12] = 0x0E;
tx_data[13] = 0x09;
tx_data[14] = 0x00;
r = ili9340_transmit(dev, ILI9340_CMD_POSITIVE_GAMMA_CORRECTION, tx_data,
15);
if (r < 0) {
return r;
}
tx_data[0] = 0x00;
tx_data[1] = 0x0E;
tx_data[2] = 0x14;
tx_data[3] = 0x03;
tx_data[4] = 0x11;
tx_data[5] = 0x07;
tx_data[6] = 0x31;
tx_data[7] = 0xC1;
tx_data[8] = 0x48;
tx_data[9] = 0x08;
tx_data[10] = 0x0F;
tx_data[11] = 0x0C;
tx_data[12] = 0x31;
tx_data[13] = 0x36;
tx_data[14] = 0x0F;
r = ili9340_transmit(dev, ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION, tx_data,
15);
if (r < 0) {
return r;
}
return 0;
}

View file

@ -125,57 +125,5 @@ int ili9340_lcd_init(const struct device *dev)
return r;
}
/* Gamma curve selected */
cmd = ILI9340_CMD_GAMMA_SET;
data[0] = 0x01U;
r = ili9340_transmit(dev, cmd, data, 1);
if (r < 0) {
return r;
}
/* Positive Gamma Correction */
cmd = ILI9340_CMD_POSITIVE_GAMMA_CORRECTION;
data[0] = 0x0FU;
data[1] = 0x2AU;
data[2] = 0x28U;
data[3] = 0x08U;
data[4] = 0x0EU;
data[5] = 0x08U;
data[6] = 0x54U;
data[7] = 0xA9U;
data[8] = 0x43U;
data[9] = 0x0AU;
data[10] = 0x0FU;
data[11] = 0x00U;
data[12] = 0x00U;
data[13] = 0x00U;
data[14] = 0x00U;
r = ili9340_transmit(dev, cmd, data, 15);
if (r < 0) {
return r;
}
/* Negative Gamma Correction */
cmd = ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION;
data[0] = 0x00U;
data[1] = 0x15U;
data[2] = 0x17U;
data[3] = 0x07U;
data[4] = 0x11U;
data[5] = 0x06U;
data[6] = 0x2BU;
data[7] = 0x56U;
data[8] = 0x3CU;
data[9] = 0x05U;
data[10] = 0x10U;
data[11] = 0x0FU;
data[12] = 0x3FU;
data[13] = 0x3FU;
data[14] = 0x0FU;
r = ili9340_transmit(dev, cmd, data, 15);
if (r < 0) {
return r;
}
return 0;
}