drivers: display: ili9340: add support for pwctrl in DT

Add support for setting PWRCTRL1/2 registers via DT.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2020-09-15 12:23:07 +02:00 committed by Maureen Helm
commit c02e50a09d
8 changed files with 39 additions and 30 deletions

View file

@ -52,5 +52,6 @@
reg = <0>; reg = <0>;
spi-max-frequency = <12000000>; spi-max-frequency = <12000000>;
label = "DISPLAY"; label = "DISPLAY";
pwctrl1 = [1b 00];
}; };
}; };

View file

@ -19,6 +19,7 @@
cmd-data-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */ cmd-data-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */
pixel-format = <ILI9340_PIXEL_FORMAT_RGB888>; pixel-format = <ILI9340_PIXEL_FORMAT_RGB888>;
rotation = <90>; rotation = <90>;
pwctrl1 = [23 00];
}; };
}; };

View file

@ -19,6 +19,7 @@
reset-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>; /* D10 */ reset-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>; /* D10 */
pixel-format = <ILI9340_PIXEL_FORMAT_RGB565>; pixel-format = <ILI9340_PIXEL_FORMAT_RGB565>;
rotation = <0>; rotation = <0>;
pwctrl1 = [23 00];
}; };
}; };

View file

@ -36,6 +36,8 @@ struct ili9340_config {
gpio_dt_flags_t reset_flags; gpio_dt_flags_t reset_flags;
uint8_t pixel_format; uint8_t pixel_format;
uint16_t rotation; uint16_t rotation;
uint8_t pwctrl1[ILI9340_PWCTRL1_LEN];
uint8_t pwctrl2[ILI9340_PWCTRL2_LEN];
}; };
struct ili9340_data { struct ili9340_data {
@ -331,6 +333,7 @@ static int ili9340_configure(const struct device *dev)
int r; int r;
enum display_pixel_format pixel_format; enum display_pixel_format pixel_format;
enum display_orientation orientation; enum display_orientation orientation;
uint8_t tx_data[15];
/* pixel format */ /* pixel format */
if (config->pixel_format == ILI9340_PIXEL_FORMAT_RGB565) { if (config->pixel_format == ILI9340_PIXEL_FORMAT_RGB565) {
@ -360,6 +363,22 @@ static int ili9340_configure(const struct device *dev)
return r; 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,
ILI9340_PWCTRL1_LEN);
if (r < 0) {
return r;
}
LOG_HEXDUMP_DBG(config->pwctrl2, ILI9340_PWCTRL2_LEN, "PWCTRL2");
memcpy(tx_data, config->pwctrl2, ILI9340_PWCTRL2_LEN);
r = ili9340_transmit(dev, ILI9340_CMD_POWER_CTRL_2, tx_data,
ILI9340_PWCTRL2_LEN);
if (r < 0) {
return r;
}
return 0; return 0;
} }
@ -478,6 +497,8 @@ static const struct display_driver_api ili9340_api = {
DT_INST_GPIO_FLAGS(index, reset_gpios)), \ DT_INST_GPIO_FLAGS(index, reset_gpios)), \
.pixel_format = DT_INST_PROP(index, pixel_format), \ .pixel_format = DT_INST_PROP(index, pixel_format), \
.rotation = DT_INST_PROP(index, rotation), \ .rotation = DT_INST_PROP(index, rotation), \
.pwctrl1 = DT_INST_PROP(index, pwctrl1), \
.pwctrl2 = DT_INST_PROP(index, pwctrl2), \
}; \ }; \
\ \
static struct ili9340_data ili9340_data_##index; \ static struct ili9340_data ili9340_data_##index; \

View file

@ -39,6 +39,9 @@
#define ILI9341_CMD_ENABLE_3G 0xF2 #define ILI9341_CMD_ENABLE_3G 0xF2
#define ILI9341_CMD_PUMP_RATIO_CTRL 0xF7 #define ILI9341_CMD_PUMP_RATIO_CTRL 0xF7
#define ILI9340_PWCTRL1_LEN 2U
#define ILI9340_PWCTRL2_LEN 1U
#define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80 #define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80
#define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40 #define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40
#define ILI9340_DATA_MEM_ACCESS_CTRL_MV 0x20 #define ILI9340_DATA_MEM_ACCESS_CTRL_MV 0x20

View file

@ -11,18 +11,6 @@ int ili9340_lcd_init(const struct device *dev)
int r; int r;
uint8_t tx_data[15]; uint8_t tx_data[15];
tx_data[0] = 0x23;
r = ili9340_transmit(dev, ILI9340_CMD_POWER_CTRL_1, tx_data, 1);
if (r < 0) {
return r;
}
tx_data[0] = 0x10;
r = ili9340_transmit(dev, ILI9340_CMD_POWER_CTRL_2, tx_data, 1);
if (r < 0) {
return r;
}
tx_data[0] = 0x3e; tx_data[0] = 0x3e;
tx_data[1] = 0x28; tx_data[1] = 0x28;
r = ili9340_transmit(dev, ILI9340_CMD_VCOM_CTRL_1, tx_data, 2); r = ili9340_transmit(dev, ILI9340_CMD_VCOM_CTRL_1, tx_data, 2);

View file

@ -82,24 +82,6 @@ int ili9340_lcd_init(const struct device *dev)
return r; return r;
} }
/* Power control */
/* VRH[5:0] */
cmd = ILI9340_CMD_POWER_CTRL_1;
data[0] = 0x1BU;
r = ili9340_transmit(dev, cmd, data, 1);
if (r < 0) {
return r;
}
/* Power control */
/* SAP[2:0];BT[3:0] */
cmd = ILI9340_CMD_POWER_CTRL_2;
data[0] = 0x10U;
r = ili9340_transmit(dev, cmd, data, 1);
if (r < 0) {
return r;
}
/* VCM control */ /* VCM control */
cmd = ILI9340_CMD_VCOM_CTRL_1; cmd = ILI9340_CMD_VCOM_CTRL_1;
data[0] = 0x3FU; data[0] = 0x3FU;

View file

@ -47,3 +47,15 @@ properties:
- 270 - 270
description: description:
Display rotation (CW) in degrees. Display rotation (CW) in degrees.
pwctrl1:
type: uint8-array
default: [0x26, 0x00]
description:
Power control 1 (PWCTRL1) register values.
pwctrl2:
type: uint8-array
default: [0x00]
description:
Power control 2 (PWCTRL2) register values.