From a1ce0c851d358997bfef84bb12d98a4d8014a052 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 15 Sep 2020 14:44:46 +0200 Subject: [PATCH] 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 --- boards/arc/hsdk/hsdk.dtsi | 2 + .../adafruit_2_8_tft_touch_v2.overlay | 2 + .../buydisplay_2_8_tft_touch_arduino.overlay | 2 + drivers/display/display_ili9340.c | 30 +++++++++++ drivers/display/display_ili9340.h | 3 ++ .../display/display_ili9340_adafruit_1480.c | 48 ----------------- drivers/display/display_ili9340_seeed_tftv2.c | 52 ------------------- dts/bindings/display/ilitek,ili9340.yaml | 50 ++++++++++++++++++ 8 files changed, 89 insertions(+), 100 deletions(-) diff --git a/boards/arc/hsdk/hsdk.dtsi b/boards/arc/hsdk/hsdk.dtsi index 65b4ecd4977..e9fec4bceb7 100644 --- a/boards/arc/hsdk/hsdk.dtsi +++ b/boards/arc/hsdk/hsdk.dtsi @@ -53,5 +53,7 @@ spi-max-frequency = <12000000>; label = "DISPLAY"; pwctrl1 = [1b 00]; + pgamctrl = [0f 2a 28 08 0e 08 54 a9 43 0a 0f 00 00 00 00]; + ngamctrl = [00 15 17 07 11 06 2b 56 3c 05 10 0f 3f 3f 0f]; }; }; diff --git a/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay b/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay index d4648fbe829..00d59959a96 100644 --- a/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay +++ b/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay @@ -20,6 +20,8 @@ pixel-format = ; rotation = <90>; pwctrl1 = [23 00]; + pgamctrl = [0f 31 2b 0c 0e 08 4e f1 37 07 10 03 0e 09 00]; + ngamctrl = [00 0e 14 03 11 07 31 c1 48 08 0f 0c 31 36 0f]; }; }; diff --git a/boards/shields/buydisplay_2_8_tft_touch_arduino/buydisplay_2_8_tft_touch_arduino.overlay b/boards/shields/buydisplay_2_8_tft_touch_arduino/buydisplay_2_8_tft_touch_arduino.overlay index dbba4aa2b30..98d55b055ff 100644 --- a/boards/shields/buydisplay_2_8_tft_touch_arduino/buydisplay_2_8_tft_touch_arduino.overlay +++ b/boards/shields/buydisplay_2_8_tft_touch_arduino/buydisplay_2_8_tft_touch_arduino.overlay @@ -20,6 +20,8 @@ pixel-format = ; rotation = <0>; pwctrl1 = [23 00]; + pgamctrl = [0f 31 2b 0c 0e 08 4e f1 37 07 10 03 0e 09 00]; + ngamctrl = [00 0e 14 03 11 07 31 c1 48 08 0f 0c 31 36 0f]; }; }; diff --git a/drivers/display/display_ili9340.c b/drivers/display/display_ili9340.c index 9e4f6d63180..ecdd9d36235 100644 --- a/drivers/display/display_ili9340.c +++ b/drivers/display/display_ili9340.c @@ -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; \ diff --git a/drivers/display/display_ili9340.h b/drivers/display/display_ili9340.h index 970c3ea7d72..185bcaf1404 100644 --- a/drivers/display/display_ili9340.h +++ b/drivers/display/display_ili9340.h @@ -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 diff --git a/drivers/display/display_ili9340_adafruit_1480.c b/drivers/display/display_ili9340_adafruit_1480.c index 56f239be759..949cfbc7e08 100644 --- a/drivers/display/display_ili9340_adafruit_1480.c +++ b/drivers/display/display_ili9340_adafruit_1480.c @@ -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; } diff --git a/drivers/display/display_ili9340_seeed_tftv2.c b/drivers/display/display_ili9340_seeed_tftv2.c index c13bd21b08a..05ee3d28276 100644 --- a/drivers/display/display_ili9340_seeed_tftv2.c +++ b/drivers/display/display_ili9340_seeed_tftv2.c @@ -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; } diff --git a/dts/bindings/display/ilitek,ili9340.yaml b/dts/bindings/display/ilitek,ili9340.yaml index 6fb52554318..b2ddbfdf345 100644 --- a/dts/bindings/display/ilitek,ili9340.yaml +++ b/dts/bindings/display/ilitek,ili9340.yaml @@ -48,6 +48,12 @@ properties: description: Display rotation (CW) in degrees. + gamset: + type: uint8-array + default: [0x01] + description: + Gamma set (GAMSET) register value. + pwctrl1: type: uint8-array default: [0x26, 0x00] @@ -59,3 +65,47 @@ properties: default: [0x00] description: Power control 2 (PWCTRL2) register values. + + pgamctrl: + type: uint8-array + default: [ + 0x0f, + 0x22, + 0x1f, + 0x0a, + 0x0e, + 0x06, + 0x4d, + 0x76, + 0x3b, + 0x03, + 0x0e, + 0x04, + 0x13, + 0x0e, + 0x0c + ] + description: + Positive gamma correction (PGAMCTRL) register values. + + ngamctrl: + type: uint8-array + default: [ + 0x0c, + 0x23, + 0x26, + 0x04, + 0x10, + 0x04, + 0x39, + 0x24, + 0x4b, + 0x03, + 0x0b, + 0x0b, + 0x33, + 0x37, + 0x0f + ] + description: + Negative gamma correction (NGAMCTRL) register values.