diff --git a/boards/shields/st7789v_generic/doc/index.rst b/boards/shields/st7789v_generic/doc/index.rst new file mode 100644 index 0000000000000..4e149c0567239 --- /dev/null +++ b/boards/shields/st7789v_generic/doc/index.rst @@ -0,0 +1,71 @@ +.. _st7789v_generic: + +Generic ST7789V Display Shield +############################## + +Overview +******** + +This is a generic shield for display shields based on ST7789V display +controller. More information about the controller can be found in +`ST7789V Datasheet`_. + +Pins Assignment of the Generic ST7789V Display Shield +===================================================== + ++-----------------------+---------------------------------------------+ +| Arduino Connector Pin | Function | ++=======================+=============================================+ +| D8 | ST7789V Reset | ++-----------------------+---------------------------------------------+ +| D9 | ST7789V DC (Data/Command) | ++-----------------------+---------------------------------------------+ +| D10 | SPI SS (Serial Slave Select) | ++-----------------------+---------------------------------------------+ +| D11 | SPI MOSI (Serial Data Input) | ++-----------------------+---------------------------------------------+ +| D12 | SPI MISO (Serial Data Out) | ++-----------------------+---------------------------------------------+ +| D13 | SPI SCK (Serial Clock Input) | ++-----------------------+---------------------------------------------+ + +Current supported displays +========================== + ++----------------------+------------------------------+ +| Display | Shield Designation | +| | | ++======================+==============================+ +| TL019FQV01 | st7789v_tl019fqv01 | +| | | ++----------------------+------------------------------+ +| Waveshare 240x240 | st7789v_waveshare_240x240 | +| 1.3inch IPS LCD | | ++----------------------+------------------------------+ + +Requirements +************ + +This shield can only be used with a board that provides a configuration +for Arduino connectors and defines node aliases for SPI and GPIO interfaces +(see :ref:`shields` for more details). + +Programming +*********** + +Set ``-DSHIELD=st7789v_tl019fqv01`` when you invoke ``west build``. For example: + +.. zephyr-app-commands:: + :zephyr-app: samples/gui/lvgl + :board: nrf52840_pca10056 + :shield: st7789v_tl019fqv01 + :goals: build + +References +********** + +.. target-notes:: + +.. _ST7789V Datasheet: + https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf + diff --git a/boards/shields/st7789v_generic/st7789v_tl019fqv01.conf b/boards/shields/st7789v_generic/st7789v_tl019fqv01.conf new file mode 100644 index 0000000000000..ba88e1f0d2a83 --- /dev/null +++ b/boards/shields/st7789v_generic/st7789v_tl019fqv01.conf @@ -0,0 +1,10 @@ +CONFIG_SPI=y +CONFIG_DISPLAY=y +CONFIG_ST7789V=y + +CONFIG_ST7789V_RGB888=y +CONFIG_LVGL_BITS_PER_PIXEL=24 +CONFIG_LVGL_HOR_RES=320 +CONFIG_LVGL_VER_RES=170 + +CONFIG_LVGL_DISPLAY_DEV_NAME="ST7789V" diff --git a/boards/shields/st7789v_generic/st7789v_tl019fqv01.overlay b/boards/shields/st7789v_generic/st7789v_tl019fqv01.overlay new file mode 100644 index 0000000000000..78c3bca73efba --- /dev/null +++ b/boards/shields/st7789v_generic/st7789v_tl019fqv01.overlay @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&arduino_spi { + status = "okay"; + cs-gpios = <&arduino_header 16 0>; /* D10 */ + + st7789v@0 { + compatible = "sitronix,st7789v"; + label = "ST7789V"; + spi-max-frequency = <20000000>; + reg = <0>; + cmd-data-gpios = <&arduino_header 15 0>; /* D9 */ + reset-gpios = <&arduino_header 14 0>; /* D8 */ + width = <320>; + height = <170>; + x-offset = <0>; + y-offset = <35>; + vcom = <0x2b>; + gctrl = <0x35>; + vrhs = <0x0f>; + vdvs = <0x20>; + mdac = <0x20>; + gamma = <0x01>; + colmod = <0x66>; + lcm = <0x2c>; + porch-param = [0c 0c 00 33 33]; + cmd2en-param = [5a 69 02 01]; + pwctrl1-param = [52 a1]; + pvgam-param = [D0 00 02 07 0B 1A 31 54 40 29 12 12 12 17]; + nvgam-param = [D0 00 02 07 05 15 2D 44 44 1C 18 16 1C 1D]; + ram-param = [00 F0]; + rgb-param = [CD 08 14]; + }; +}; diff --git a/boards/shields/st7789v_generic/st7789v_waveshare_240x240.conf b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.conf new file mode 100644 index 0000000000000..b2fa7e39656f2 --- /dev/null +++ b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.conf @@ -0,0 +1,10 @@ +CONFIG_SPI=y +CONFIG_DISPLAY=y +CONFIG_ST7789V=y + +CONFIG_ST7789V_RGB565=y +CONFIG_LVGL_BITS_PER_PIXEL=16 +CONFIG_LVGL_HOR_RES=240 +CONFIG_LVGL_VER_RES=240 + +CONFIG_LVGL_DISPLAY_DEV_NAME="ST7789V" diff --git a/boards/shields/st7789v_generic/st7789v_waveshare_240x240.overlay b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.overlay new file mode 100644 index 0000000000000..cddeb0a0f3527 --- /dev/null +++ b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.overlay @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019 Jan Van Winkel + * Copyright (c) 2019 PHYTEC Messtechnik GmbH + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&arduino_spi { + status = "okay"; + cs-gpios = <&arduino_header 16 0>; /* D10 */ + + st7789v@0 { + compatible = "sitronix,st7789v"; + label = "ST7789V"; + spi-max-frequency = <20000000>; + reg = <0>; + cmd-data-gpios = <&arduino_header 15 0>; /* D9 */ + reset-gpios = <&arduino_header 14 0>; /* D8 */ + width = <240>; + height = <240>; + x-offset = <0>; + y-offset = <0>; + vcom = <0x19>; + gctrl = <0x35>; + vrhs = <0x12>; + vdvs = <0x20>; + mdac = <0x00>; + gamma = <0x01>; + colmod = <0x05>; + lcm = <0x2c>; + porch-param = [0c 0c 00 33 33]; + cmd2en-param = [5a 69 02 01]; + pwctrl1-param = [a4 a1]; + pvgam-param = [D0 04 0D 11 13 2B 3F 54 4C 18 0D 0B 1F 23]; + nvgam-param = [D0 04 0C 11 13 2C 3F 44 51 2F 1F 1F 20 23]; + ram-param = [00 F0]; + rgb-param = [CD 08 14]; + }; +}; diff --git a/drivers/display/CMakeLists.txt b/drivers/display/CMakeLists.txt index b17d667031130..c1db6b3183659 100644 --- a/drivers/display/CMakeLists.txt +++ b/drivers/display/CMakeLists.txt @@ -21,7 +21,3 @@ zephyr_sources_ifdef(CONFIG_ILI9340_LCD_ADAFRUIT_1480 zephyr_sources_ifdef(CONFIG_ILI9340_LCD_SEEED_TFTV2 display_ili9340_seeed_tftv2.c ) - -zephyr_sources_ifdef(CONFIG_ST7789V_LCD_TL019FQV01 - display_st7789v_tl019fqv01.c -) diff --git a/drivers/display/Kconfig.st7789v b/drivers/display/Kconfig.st7789v index 42e843ef1e84e..3887f518990ac 100644 --- a/drivers/display/Kconfig.st7789v +++ b/drivers/display/Kconfig.st7789v @@ -11,16 +11,6 @@ menuconfig ST7789V if ST7789V -choice - prompt "LCD" - help - Specify the type of LCD connected to the ST7789V display controller. - -config ST7789V_LCD_TL019FQV01 - bool "TDO TL019FQV01" - -endchoice - choice prompt "Color pixel format" default ST7789V_RGB565 @@ -35,31 +25,4 @@ config ST7789V_RGB565 endchoice -if ST7789V_RGB565 -config ST7789V_SWAP_PIXEL_LCD_ENDIANNESS - bool "Swap pixel endianness at LCD" - help - Pixel data bytes are swapped when being blitted to the LCD. - Note that this isn't just a swap of RGB <--> BGR, (if the endianness is - swapped then the 3 lowest bits of G are sent first/last). - You may want to enable this if you are using lvgl and your colors - don't look right. - -config ST7789V_REVERSE_LCD_RGB_ORDER - bool "Reverse draw order of controller ram to LCD" - help - This reverses the order that the controller draws RGB to the LCD. - -config ST7789V_REVERSE_X - bool "Reverse X axis" - help - Address pixels from right to left. - -config ST7789V_REVERSE_Y - bool "Reverse Y axis" - help - Address pixels from bottom to top. - -endif # ST7789V_RGB565 - endif # ST7789V diff --git a/drivers/display/display_st7789v.c b/drivers/display/display_st7789v.c index c3254387335f7..980872c4cd14b 100644 --- a/drivers/display/display_st7789v.c +++ b/drivers/display/display_st7789v.c @@ -2,6 +2,7 @@ * Copyright (c) 2017 Jan Van Winkel * Copyright (c) 2019 Nordic Semiconductor ASA * Copyright (c) 2019 Marc Reilly + * Copyright (c) 2019 PHYTEC Messtechnik GmbH * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,6 +23,14 @@ LOG_MODULE_REGISTER(display_st7789v); #define ST7789V_CMD_DATA_PIN DT_INST_0_SITRONIX_ST7789V_CMD_DATA_GPIOS_PIN #define ST7789V_RESET_PIN DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_PIN +static u8_t st7789v_porch_param[] = DT_INST_0_SITRONIX_ST7789V_PORCH_PARAM; +static u8_t st7789v_cmd2en_param[] = DT_INST_0_SITRONIX_ST7789V_CMD2EN_PARAM; +static u8_t st7789v_pwctrl1_param[] = DT_INST_0_SITRONIX_ST7789V_PWCTRL1_PARAM; +static u8_t st7789v_pvgam_param[] = DT_INST_0_SITRONIX_ST7789V_PVGAM_PARAM; +static u8_t st7789v_nvgam_param[] = DT_INST_0_SITRONIX_ST7789V_NVGAM_PARAM; +static u8_t st7789v_ram_param[] = DT_INST_0_SITRONIX_ST7789V_RAM_PARAM; +static u8_t st7789v_rgb_param[] = DT_INST_0_SITRONIX_ST7789V_RGB_PARAM; + struct st7789v_data { struct device *spi_dev; struct spi_config spi_config; @@ -46,10 +55,7 @@ struct st7789v_data { #define ST7789V_PIXEL_SIZE 3u #endif -static int st7789v_blanking_off(const struct device *dev); -static int st7789v_blanking_on(const struct device *dev); - -void st7789v_set_lcd_margins(struct st7789v_data *data, +static void st7789v_set_lcd_margins(struct st7789v_data *data, u16_t x_offset, u16_t y_offset) { data->x_offset = x_offset; @@ -61,7 +67,7 @@ static void st7789v_set_cmd(struct st7789v_data *data, int is_cmd) gpio_pin_write(data->cmd_data_gpio, ST7789V_CMD_DATA_PIN, !is_cmd); } -void st7789v_transmit(struct st7789v_data *data, u8_t cmd, +static void st7789v_transmit(struct st7789v_data *data, u8_t cmd, u8_t *tx_data, size_t tx_count) { struct spi_buf tx_buf = { .buf = &cmd, .len = 1 }; @@ -100,104 +106,6 @@ static void st7789v_reset_display(struct st7789v_data *data) #endif } -int st7789v_init(struct device *dev) -{ - struct st7789v_data *data = (struct st7789v_data *)dev->driver_data; - - data->spi_dev = device_get_binding(DT_INST_0_SITRONIX_ST7789V_BUS_NAME); - if (data->spi_dev == NULL) { - LOG_ERR("Could not get SPI device for LCD"); - return -EPERM; - } - - data->spi_config.frequency = DT_INST_0_SITRONIX_ST7789V_SPI_MAX_FREQUENCY; - data->spi_config.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8); - data->spi_config.slave = DT_INST_0_SITRONIX_ST7789V_BASE_ADDRESS; - -#ifdef DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_CONTROLLER - data->cs_ctrl.gpio_dev = - device_get_binding(DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_CONTROLLER); - data->cs_ctrl.gpio_pin = DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_PIN; - data->cs_ctrl.delay = 0U; - data->spi_config.cs = &(data->cs_ctrl); -#else - data->spi_config.cs = NULL; -#endif - -#ifdef DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER - data->reset_gpio = - device_get_binding(DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER); - if (data->reset_gpio == NULL) { - LOG_ERR("Could not get GPIO port for display reset"); - return -EPERM; - } - - if (gpio_pin_configure(data->reset_gpio, ST7789V_RESET_PIN, GPIO_DIR_OUT)) { - LOG_ERR("Couldn't configure reset pin"); - return -EIO; - } -#endif - - data->cmd_data_gpio = - device_get_binding(DT_INST_0_SITRONIX_ST7789V_CMD_DATA_GPIOS_CONTROLLER); - if (data->cmd_data_gpio == NULL) { - LOG_ERR("Could not get GPIO port for cmd/DATA port"); - return -EPERM; - } - if (gpio_pin_configure(data->cmd_data_gpio, ST7789V_CMD_DATA_PIN, - GPIO_DIR_OUT)) { - LOG_ERR("Couldn't configure cmd/DATA pin"); - return -EIO; - } - - data->width = 240; - data->height = 320; - data->x_offset = 0; - data->y_offset = 0; - -#ifdef DT_INST_0_SITRONIX_ST7789V_WIDTH - data->width = DT_INST_0_SITRONIX_ST7789V_WIDTH; -#endif -#ifdef DT_INST_0_SITRONIX_ST7789V_HEIGHT - data->height = DT_INST_0_SITRONIX_ST7789V_HEIGHT; -#endif - - st7789v_reset_display(data); - - st7789v_blanking_on(dev); - - st7789v_lcd_init(data); - - st7789v_exit_sleep(data); - - return 0; -} - -int st7789v_cmd_read8(struct st7789v_data *data, int cmd, u8_t *pRet) -{ - u8_t sendbuff[4]; - - sendbuff[0] = cmd; - - const struct spi_buf tx_buf[2] = { - { .buf = sendbuff, .len = 1 }, - { .buf = 0, .len = 1 }, - }; - const struct spi_buf rx_buf[2] = { - { .buf = 0, .len = 1 }, - { .buf = pRet, .len = 1 } - }; - struct spi_buf_set tx_bufs = { .buffers = tx_buf, .count = 2 }; - struct spi_buf_set rx_bufs = { .buffers = rx_buf, .count = 2 }; - - st7789v_set_cmd(data, 1); - int ret = spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, - &rx_bufs); - st7789v_set_cmd(data, 0); - - return ret; -} - static int st7789v_blanking_on(const struct device *dev) { struct st7789v_data *driver = (struct st7789v_data *)dev->driver_data; @@ -288,24 +196,24 @@ static int st7789v_write(const struct device *dev, return 0; } -void *st7789v_get_framebuffer(const struct device *dev) +static void *st7789v_get_framebuffer(const struct device *dev) { return NULL; } -int st7789v_set_brightness(const struct device *dev, +static int st7789v_set_brightness(const struct device *dev, const u8_t brightness) { return -ENOTSUP; } -int st7789v_set_contrast(const struct device *dev, +static int st7789v_set_contrast(const struct device *dev, const u8_t contrast) { return -ENOTSUP; } -void st7789v_get_capabilities(const struct device *dev, +static void st7789v_get_capabilities(const struct device *dev, struct display_capabilities *capabilities) { struct st7789v_data *data = (struct st7789v_data *)dev->driver_data; @@ -324,7 +232,7 @@ void st7789v_get_capabilities(const struct device *dev, capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL; } -int st7789v_set_pixel_format(const struct device *dev, +static int st7789v_set_pixel_format(const struct device *dev, const enum display_pixel_format pixel_format) { #ifdef CONFIG_ST7789V_RGB565 @@ -338,7 +246,7 @@ int st7789v_set_pixel_format(const struct device *dev, return -ENOTSUP; } -int st7789v_set_orientation(const struct device *dev, +static int st7789v_set_orientation(const struct device *dev, const enum display_orientation orientation) { if (orientation == DISPLAY_ORIENTATION_NORMAL) { @@ -348,6 +256,139 @@ int st7789v_set_orientation(const struct device *dev, return -ENOTSUP; } +static void st7789v_lcd_init(struct st7789v_data *p_st7789v) +{ + u8_t tmp; + + st7789v_set_lcd_margins(p_st7789v, 0, 0); + + st7789v_transmit(p_st7789v, ST7789V_CMD_PORCTRL, st7789v_porch_param, + sizeof(st7789v_porch_param)); + + st7789v_transmit(p_st7789v, ST7789V_CMD_CMD2EN, st7789v_cmd2en_param, + sizeof(st7789v_cmd2en_param)); + + /* Digital Gamma Enable, default disabled */ + tmp = 0x00; + st7789v_transmit(p_st7789v, ST7789V_CMD_DGMEN, &tmp, 1); + + /* Frame Rate Control in Normal Mode, default value */ + tmp = 0x0f; + st7789v_transmit(p_st7789v, ST7789V_CMD_FRCTRL2, &tmp, 1); + + tmp = DT_INST_0_SITRONIX_ST7789V_GCTRL; + st7789v_transmit(p_st7789v, ST7789V_CMD_GCTRL, &tmp, 1); + + tmp = DT_INST_0_SITRONIX_ST7789V_VCOM; + st7789v_transmit(p_st7789v, ST7789V_CMD_VCOMS, &tmp, 1); + +#if (defined(DT_INST_0_SITRONIX_ST7789V_VRHS) && \ + defined(DT_INST_0_SITRONIX_ST7789V_VDVS)) + tmp = 0x01; + st7789v_transmit(p_st7789v, ST7789V_CMD_VDVVRHEN, &tmp, 1); + + tmp = DT_INST_0_SITRONIX_ST7789V_VRHS; + st7789v_transmit(p_st7789v, ST7789V_CMD_VRH, &tmp, 1); + + tmp = DT_INST_0_SITRONIX_ST7789V_VDVS; + st7789v_transmit(p_st7789v, ST7789V_CMD_VDS, &tmp, 1); +#endif + + st7789v_transmit(p_st7789v, ST7789V_CMD_PWCTRL1, st7789v_pwctrl1_param, + sizeof(st7789v_pwctrl1_param)); + + /* Memory Data Access Control */ + tmp = DT_INST_0_SITRONIX_ST7789V_MDAC; + st7789v_transmit(p_st7789v, ST7789V_CMD_MADCTL, &tmp, 1); + + /* Interface Pixel Format */ + tmp = DT_INST_0_SITRONIX_ST7789V_COLMOD; + st7789v_transmit(p_st7789v, ST7789V_CMD_COLMOD, &tmp, 1); + + tmp = DT_INST_0_SITRONIX_ST7789V_LCM; + st7789v_transmit(p_st7789v, ST7789V_CMD_LCMCTRL, &tmp, 1); + + tmp = DT_INST_0_SITRONIX_ST7789V_GAMMA; + st7789v_transmit(p_st7789v, ST7789V_CMD_GAMSET, &tmp, 1); + + st7789v_transmit(p_st7789v, ST7789V_CMD_INV_ON, NULL, 0); + + st7789v_transmit(p_st7789v, ST7789V_CMD_PVGAMCTRL, st7789v_pvgam_param, + sizeof(st7789v_pvgam_param)); + + st7789v_transmit(p_st7789v, ST7789V_CMD_NVGAMCTRL, st7789v_nvgam_param, + sizeof(st7789v_nvgam_param)); + + st7789v_transmit(p_st7789v, ST7789V_CMD_RAMCTRL, st7789v_ram_param, + sizeof(st7789v_ram_param)); + + st7789v_transmit(p_st7789v, ST7789V_CMD_RGBCTRL, st7789v_rgb_param, + sizeof(st7789v_rgb_param)); +} + +static int st7789v_init(struct device *dev) +{ + struct st7789v_data *data = (struct st7789v_data *)dev->driver_data; + + data->spi_dev = device_get_binding(DT_INST_0_SITRONIX_ST7789V_BUS_NAME); + if (data->spi_dev == NULL) { + LOG_ERR("Could not get SPI device for LCD"); + return -EPERM; + } + + data->spi_config.frequency = + DT_INST_0_SITRONIX_ST7789V_SPI_MAX_FREQUENCY; + data->spi_config.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8); + data->spi_config.slave = DT_INST_0_SITRONIX_ST7789V_BASE_ADDRESS; + +#ifdef DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_CONTROLLER + data->cs_ctrl.gpio_dev = device_get_binding( + DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_CONTROLLER); + data->cs_ctrl.gpio_pin = DT_INST_0_SITRONIX_ST7789V_CS_GPIOS_PIN; + data->cs_ctrl.delay = 0U; + data->spi_config.cs = &(data->cs_ctrl); +#else + data->spi_config.cs = NULL; +#endif + +#ifdef DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER + data->reset_gpio = device_get_binding( + DT_INST_0_SITRONIX_ST7789V_RESET_GPIOS_CONTROLLER); + if (data->reset_gpio == NULL) { + LOG_ERR("Could not get GPIO port for display reset"); + return -EPERM; + } + + if (gpio_pin_configure(data->reset_gpio, ST7789V_RESET_PIN, + GPIO_DIR_OUT)) { + LOG_ERR("Couldn't configure reset pin"); + return -EIO; + } +#endif + + data->cmd_data_gpio = device_get_binding( + DT_INST_0_SITRONIX_ST7789V_CMD_DATA_GPIOS_CONTROLLER); + if (data->cmd_data_gpio == NULL) { + LOG_ERR("Could not get GPIO port for cmd/DATA port"); + return -EPERM; + } + if (gpio_pin_configure(data->cmd_data_gpio, ST7789V_CMD_DATA_PIN, + GPIO_DIR_OUT)) { + LOG_ERR("Couldn't configure cmd/DATA pin"); + return -EIO; + } + + st7789v_reset_display(data); + + st7789v_blanking_on(dev); + + st7789v_lcd_init(data); + + st7789v_exit_sleep(data); + + return 0; +} + static const struct display_driver_api st7789v_api = { .blanking_on = st7789v_blanking_on, .blanking_off = st7789v_blanking_off, @@ -361,7 +402,12 @@ static const struct display_driver_api st7789v_api = { .set_orientation = st7789v_set_orientation, }; -static struct st7789v_data st7789v_data; +static struct st7789v_data st7789v_data = { + .width = DT_INST_0_SITRONIX_ST7789V_WIDTH, + .height = DT_INST_0_SITRONIX_ST7789V_HEIGHT, + .x_offset = DT_INST_0_SITRONIX_ST7789V_X_OFFSET, + .y_offset = DT_INST_0_SITRONIX_ST7789V_Y_OFFSET, +}; DEVICE_AND_API_INIT(st7789v, DT_INST_0_SITRONIX_ST7789V_LABEL, &st7789v_init, &st7789v_data, NULL, APPLICATION, diff --git a/drivers/display/display_st7789v.h b/drivers/display/display_st7789v.h index 610d4c4c1d8d1..1e881d2b0cf3a 100644 --- a/drivers/display/display_st7789v.h +++ b/drivers/display/display_st7789v.h @@ -67,14 +67,4 @@ #define ST7789V_CMD_PVGAMCTRL 0xe0 #define ST7789V_CMD_NVGAMCTRL 0xe1 -struct st7789v_data; - -void st7789v_set_lcd_margins(struct st7789v_data *data, - u16_t x_offset, u16_t y_offset); - -void st7789v_lcd_init(struct st7789v_data *data); - -void st7789v_transmit(struct st7789v_data *data, u8_t cmd, - u8_t *tx_data, size_t tx_count); - #endif diff --git a/drivers/display/display_st7789v_tl019fqv01.c b/drivers/display/display_st7789v_tl019fqv01.c deleted file mode 100644 index 9ca61dfcf481e..0000000000000 --- a/drivers/display/display_st7789v_tl019fqv01.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2019 Marc Reilly - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "display_st7789v.h" -#include -#include - -void st7789v_lcd_init(struct st7789v_data *p_st7789v) -{ - /* the LCD itself is smaller than the area of the ram on - * the controller. In its 'natural' orientation the LCD is - * 170 columns and 320 rows which is centered in the controller - * RAM area (so the LCD actually starts at column 35). - * We switch the rows/column addressing around so that the - * display is 320x170, and so the effective LCD is offset - * by 35 "rows". - */ - st7789v_set_lcd_margins(p_st7789v, 0, 35); - - u8_t cmd; - u8_t data[14]; - - cmd = ST7789V_CMD_PORCTRL; - data[0] = 0x0c; - data[1] = 0x0c; - data[2] = 0x00; - data[3] = 0x33; - data[4] = 0x33; - st7789v_transmit(p_st7789v, cmd, data, 5); - - cmd = ST7789V_CMD_CMD2EN; - data[0] = 0x5a; - data[1] = 0x69; - data[2] = 0x02; - data[3] = 0x01; - st7789v_transmit(p_st7789v, cmd, data, 4); - - cmd = ST7789V_CMD_DGMEN; - data[0] = 0x00; - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_GCTRL; - data[0] = 0x35; - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_VCOMS; - data[0] = 0x2b; - st7789v_transmit(p_st7789v, cmd, data, 1); - -#if CONFIG_ST7789V_REVERSE_LCD_RGB_ORDER - cmd = ST7789V_CMD_LCMCTRL; - data[0] = ST7789V_LCMCTRL_XBGR; - st7789v_transmit(p_st7789v, cmd, data, 1); -#endif - - cmd = ST7789V_CMD_VDVVRHEN; - data[0] = 0x01; - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_VRH; - data[0] = 0x0f; - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_VDS; - data[0] = 0x20; - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_FRCTRL2; - data[0] = 0x0f; - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_PWCTRL1; - data[0] = 0x52; - data[1] = (0x2 << 6) | (0x2 << 4) | 0x01; - st7789v_transmit(p_st7789v, cmd, data, 2); - - cmd = ST7789V_CMD_MADCTL; - data[0] = ST7789V_MADCTL_MV_REVERSE_MODE; -#ifdef CONFIG_ST7789V_REVERSE_X - data[0] |= ST7789V_MADCTL_MX_RIGHT_TO_LEFT; -#endif -#ifdef CONFIG_ST7789V_REVERSE_Y - data[0] |= ST7789V_MADCTL_MY_BOTTOM_TO_TOP; -#endif - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_COLMOD; -#ifdef CONFIG_ST7789V_RGB565 - data[0] = ST7789V_COLMOD_RGB_65K - | ST7789V_COLMOD_FMT_16bit; -#else - data[0] = ST7789V_COLMOD_RGB_262K - | ST7789V_COLMOD_FMT_18bit; -#endif - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_INV_ON; - st7789v_transmit(p_st7789v, cmd, NULL, 0); - - cmd = ST7789V_CMD_GAMSET; - data[0] = 0x01U; - st7789v_transmit(p_st7789v, cmd, data, 1); - - cmd = ST7789V_CMD_PVGAMCTRL; - data[0] = 0xD0 | 0x00; /* v63 | V0 */ - data[1] = 0x00; /* v1 */ - data[2] = 0x02; /* v2 */ - data[3] = 0x07; /* v4 */ - data[4] = 0x0B; /* V6 */ - data[5] = (0x01 << 4) | 0x0a; /* J0 | V13 */ - data[6] = 0x31; /* V2 */ - data[7] = (0x5 << 4) | 0x4; /* V36 | V27 */ - data[8] = 0x40; /* V43 */ - data[9] = (0x02 << 4) | 0x09; /* J1 | V50 */ - data[10] = 0x12; /* V57 */ - data[11] = 0x12; /* V59 */ - data[12] = 0x12; /* V61 */ - data[13] = 0x17; /* V62 */ - st7789v_transmit(p_st7789v, cmd, data, 14); - - cmd = ST7789V_CMD_NVGAMCTRL; - data[0] = (0xd << 4) | 0x00; /* V63 | V0 */ - data[1] = 0x00; /* v1 */ - data[2] = 0x02; /* v2 */ - data[3] = 0x07; /* v4 */ - data[4] = 0x05; /* V6 */ - data[5] = (0x01 << 4) | 0x05; /* J0 | V13 */ - data[6] = 0x2D; /* V20 */ - data[7] = (0x4 << 4) | 0x4; /* V36 | V27 */ - data[8] = 0x44; /* V43 */ - data[9] = (0x01 << 4) | 0x0c; /* J1 | V50 */ - data[10] = 0x18; /* V57 */ - data[11] = 0x16; /* V59 */ - data[12] = 0x1c; /* V61 */ - data[13] = 0x1d; /* V62 */ - st7789v_transmit(p_st7789v, cmd, data, 14); - - cmd = ST7789V_CMD_RAMCTRL; - data[0] = 0x00; - data[1] = (0x3 << 6) | (0x3u << 4); -#if CONFIG_ST7789V_SWAP_PIXEL_LCD_ENDIANNESS - data[1] |= 0x08; -#endif - st7789v_transmit(p_st7789v, cmd, data, 2); - - cmd = ST7789V_CMD_RGBCTRL; - data[0] = 0x80 | (0x2 << 5) | 0xd; - data[1] = 0x08; - data[2] = 0x14; - st7789v_transmit(p_st7789v, cmd, data, 3); -} diff --git a/dts/bindings/display/sitronix,st7789v.yaml b/dts/bindings/display/sitronix,st7789v.yaml index 34a6a74270c8f..9ff2fd4fe8059 100644 --- a/dts/bindings/display/sitronix,st7789v.yaml +++ b/dts/bindings/display/sitronix,st7789v.yaml @@ -1,4 +1,5 @@ # Copyright (c) 2019, Marc Reilly +# Copyright (c) 2019, PHYTEC Messtechnik GmbH # SPDX-License-Identifier: Apache-2.0 title: ST7789V 320x240 Display Controller @@ -31,10 +32,85 @@ properties: x-offset: type: int - required: false + required: true description: The column offset in pixels of the LCD to the controller memory y-offset: type: int - required: false + required: true description: The row offset in pixels of the LCD to the controller memory + + vcom: + type: int + required: true + description: VCOM Setting + + gctrl: + type: int + required: true + description: Gate Control + + vrhs: + type: int + required: false + description: VRH Setting + + vdvs: + type: int + required: false + description: VDV Setting + + mdac: + type: int + required: true + description: Memory Data Access Control + + lcm: + type: int + required: true + description: LCM Setting + + colmod: + type: int + required: true + description: Interface Pixel Format + + gamma: + type: int + required: true + description: Gamma Setting + + porch-param: + type: uint8-array + required: true + description: Porch Setting + + cmd2en-param: + type: uint8-array + required: true + description: Command 2 Enable Parameter + + pwctrl1-param: + type: uint8-array + required: true + description: Power Control 1 Parameter + + pvgam-param: + type: uint8-array + required: true + description: Positive Voltage Gamma Control Parameter + + nvgam-param: + type: uint8-array + required: true + description: Negative Voltage Gamma Control Parameter + + ram-param: + type: uint8-array + required: true + description: RAM Control Parameter + + rgb-param: + type: uint8-array + required: true + description: RGB Interface Control Parameter diff --git a/samples/display/st7789v/README.rst b/samples/display/st7789v/README.rst index 2ae96d293ac1d..39c9438d84743 100644 --- a/samples/display/st7789v/README.rst +++ b/samples/display/st7789v/README.rst @@ -18,25 +18,26 @@ controller orientation. Building and Running ******************** -The sample has a board overlay for a nrf52832 based board with the following -pin assignments: - -+-------------+-------------+ -| | nRF52832 | | LCD module| -| | Pin | | signal | -+=============+=============+ -| P0.03 | SPI_SCK | -+-------------+-------------+ -| P0.05 | SPI_MOSI | -+-------------+-------------+ -| P0.26 | SPI_MISO | -+-------------+-------------+ -| P0.27 | CS | -+-------------+-------------+ -| P0.25 | DATA/CMD | -+-------------+-------------+ -| P0.02 | RESET | -+-------------+-------------+ + +The sample uses the :ref:`st7789v_generic` and the pin assignments on a +:ref:`nrf52_pca10040` are as follows: + ++-------------------+-------------+ +| | NRF52 PCA10040 | | LCD module| +| | Pin | | signal | ++===================+=============+ +| P1.15 (D13) | SPI_SCK | ++-------------------+-------------+ +| P1.14 (D12) | SPI_MISO | ++-------------------+-------------+ +| P1.13 (D11) | SPI_MOSI | ++-------------------+-------------+ +| P1.12 (D10) | CS | ++-------------------+-------------+ +| P1.11 (D9) | DATA/CMD | ++-------------------+-------------+ +| P1.10 (D8) | RESET | ++-------------------+-------------+ You might need to alter these according to your specific board/LCD configuration. @@ -45,6 +46,7 @@ For :ref:`nrf52_pca10040`, build this sample application with the following comm .. zephyr-app-commands:: :zephyr-app: samples/display/st7789v :board: nrf52_pca10040 + :shield: st7789v_generic :goals: build :compact: diff --git a/samples/display/st7789v/nrf52_pca10040.overlay b/samples/display/st7789v/nrf52_pca10040.overlay deleted file mode 100644 index 83ac964706630..0000000000000 --- a/samples/display/st7789v/nrf52_pca10040.overlay +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2019 Creative Product Design - * - * SPDX-License-Identifier: Apache-2.0 - */ - -&spi0 { - status = "okay"; - sck-pin = <3>; - mosi-pin = <5>; - miso-pin = <26>; - cs-gpios = <&gpio0 27 0>; - - st7789v@0 { - compatible = "sitronix,st7789v"; - label = "DISPLAY"; - spi-max-frequency = <20000000>; - reg = <0>; - cmd-data-gpios = <&gpio0 25 0>; - reset-gpios = <&gpio0 2 0>; - width = <320>; - height = <170>; - y-offset = <35>; - }; -}; diff --git a/samples/display/st7789v/prj.conf b/samples/display/st7789v/prj.conf index ba0d9d4d91dda..c4d6caa789f86 100644 --- a/samples/display/st7789v/prj.conf +++ b/samples/display/st7789v/prj.conf @@ -1,15 +1,4 @@ CONFIG_PRINTK=y - CONFIG_HEAP_MEM_POOL_SIZE=16384 - -CONFIG_GPIO=y -CONFIG_SPI=y - -CONFIG_DISPLAY=y -CONFIG_ST7789V=y -CONFIG_ST7789V_LCD_TL019FQV01=y -CONFIG_ST7789V_RGB565=y - -CONFIG_DISPLAY_LOG_LEVEL_DBG=y - CONFIG_LOG=y +CONFIG_DISPLAY_LOG_LEVEL_DBG=y diff --git a/samples/display/st7789v/sample.yaml b/samples/display/st7789v/sample.yaml index a555591b24a78..f254cfcc85da0 100644 --- a/samples/display/st7789v/sample.yaml +++ b/samples/display/st7789v/sample.yaml @@ -5,4 +5,5 @@ tests: sample.display.st7789v: build_only: true platform_whitelist: nrf52_pca10040 - tags: display \ No newline at end of file + extra_args: SHIELD=st7789v_tl019fqv01 + tags: display shield diff --git a/samples/display/st7789v/src/main.c b/samples/display/st7789v/src/main.c index 1a7704356135d..ee5f2d87defb4 100644 --- a/samples/display/st7789v/src/main.c +++ b/samples/display/st7789v/src/main.c @@ -121,6 +121,7 @@ void main(void) *(buf + idx + 1) = (color_rgb >> 0) & 0xFFU; } #else + int color = cnt % 4; u32_t color_rgb; u32_t c = grey_count & 0xff;