From 0481a8fcaf185c880194d7085fb93800fc360573 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Fri, 8 Jul 2022 10:41:48 +0200 Subject: [PATCH 1/8] Add ILI9341 and GC9A01 LCD controllers into components. --- components/lcd/esp_lcd_gc9a01/CMakeLists.txt | 1 + components/lcd/esp_lcd_gc9a01/README.md | 21 ++ .../lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c | 323 ++++++++++++++++ .../lcd/esp_lcd_gc9a01/idf_component.yml | 5 + .../esp_lcd_gc9a01/include/esp_lcd_gc9a01.h | 29 ++ components/lcd/esp_lcd_gc9a01/license.txt | 202 ++++++++++ components/lcd/esp_lcd_ili9341/CMakeLists.txt | 1 + components/lcd/esp_lcd_ili9341/README.md | 21 ++ .../lcd/esp_lcd_ili9341/esp_lcd_ili9341.c | 349 ++++++++++++++++++ .../lcd/esp_lcd_ili9341/idf_component.yml | 5 + .../esp_lcd_ili9341/include/esp_lcd_ili9341.h | 29 ++ components/lcd/esp_lcd_ili9341/license.txt | 202 ++++++++++ 12 files changed, 1188 insertions(+) create mode 100644 components/lcd/esp_lcd_gc9a01/CMakeLists.txt create mode 100644 components/lcd/esp_lcd_gc9a01/README.md create mode 100644 components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c create mode 100644 components/lcd/esp_lcd_gc9a01/idf_component.yml create mode 100644 components/lcd/esp_lcd_gc9a01/include/esp_lcd_gc9a01.h create mode 100644 components/lcd/esp_lcd_gc9a01/license.txt create mode 100644 components/lcd/esp_lcd_ili9341/CMakeLists.txt create mode 100644 components/lcd/esp_lcd_ili9341/README.md create mode 100644 components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c create mode 100644 components/lcd/esp_lcd_ili9341/idf_component.yml create mode 100644 components/lcd/esp_lcd_ili9341/include/esp_lcd_ili9341.h create mode 100644 components/lcd/esp_lcd_ili9341/license.txt diff --git a/components/lcd/esp_lcd_gc9a01/CMakeLists.txt b/components/lcd/esp_lcd_gc9a01/CMakeLists.txt new file mode 100644 index 00000000..8ef4df91 --- /dev/null +++ b/components/lcd/esp_lcd_gc9a01/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register(SRCS "esp_lcd_gc9a01.c" INCLUDE_DIRS "include" REQUIRES "driver" "esp_lcd") diff --git a/components/lcd/esp_lcd_gc9a01/README.md b/components/lcd/esp_lcd_gc9a01/README.md new file mode 100644 index 00000000..8c1d5dfe --- /dev/null +++ b/components/lcd/esp_lcd_gc9a01/README.md @@ -0,0 +1,21 @@ +# ESP LCD GC9A01 + +Implementation of the GC9A01 LCD controller with esp_lcd component. + +| LCD controller | Communication interface | Component name | Link to datasheet | +| :------------: | :---------------------: | :------------: | :---------------: | +| GC9A01 | SPI | esp_lcd_gc9a01 | [WIKI](https://www.waveshare.com/wiki/1.28inch_LCD_Module) | + +## Add to project + +Packages from this repository are uploaded to [Espressif's component service](https://components.espressif.com/). +You can add them to your project via `idf.py add-dependancy`, e.g. +``` + idf.py add-dependency esp_lcd_gc9a01==1.0.0 +``` + +Alternatively, you can create `idf_component.yml`. More is in [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html). + +## Example use + +There is an example in ESP-IDF with this LCD controller. Please follow this [link](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/lcd/spi). diff --git a/components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c b/components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c new file mode 100644 index 00000000..dd63de01 --- /dev/null +++ b/components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c @@ -0,0 +1,323 @@ +/* + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_lcd_panel_interface.h" +#include "esp_lcd_panel_io.h" +#include "esp_lcd_panel_vendor.h" +#include "esp_lcd_panel_ops.h" +#include "esp_lcd_panel_commands.h" +#include "driver/gpio.h" +#include "esp_log.h" +#include "esp_check.h" + +static const char *TAG = "gc9a01"; + +static esp_err_t panel_gc9a01_del(esp_lcd_panel_t *panel); +static esp_err_t panel_gc9a01_reset(esp_lcd_panel_t *panel); +static esp_err_t panel_gc9a01_init(esp_lcd_panel_t *panel); +static esp_err_t panel_gc9a01_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data); +static esp_err_t panel_gc9a01_invert_color(esp_lcd_panel_t *panel, bool invert_color_data); +static esp_err_t panel_gc9a01_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y); +static esp_err_t panel_gc9a01_swap_xy(esp_lcd_panel_t *panel, bool swap_axes); +static esp_err_t panel_gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap); +static esp_err_t panel_gc9a01_disp_on_off(esp_lcd_panel_t *panel, bool off); + +typedef struct { + esp_lcd_panel_t base; + esp_lcd_panel_io_handle_t io; + int reset_gpio_num; + bool reset_level; + int x_gap; + int y_gap; + unsigned int bits_per_pixel; + uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register + uint8_t colmod_cal; // save surrent value of LCD_CMD_COLMOD register +} gc9a01_panel_t; + +esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel) +{ + esp_err_t ret = ESP_OK; + gc9a01_panel_t *gc9a01 = NULL; + ESP_GOTO_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); + gc9a01 = calloc(1, sizeof(gc9a01_panel_t)); + ESP_GOTO_ON_FALSE(gc9a01, ESP_ERR_NO_MEM, err, TAG, "no mem for gc9a01 panel"); + + if (panel_dev_config->reset_gpio_num >= 0) { + gpio_config_t io_conf = { + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num, + }; + ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed"); + } + + switch (panel_dev_config->color_space) { + case ESP_LCD_COLOR_SPACE_RGB: + gc9a01->madctl_val = 0; + break; + case ESP_LCD_COLOR_SPACE_BGR: + gc9a01->madctl_val |= LCD_CMD_BGR_BIT; + break; + default: + ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color space"); + break; + } + + switch (panel_dev_config->bits_per_pixel) { + case 16: + gc9a01->colmod_cal = 0x55; + break; + case 18: + gc9a01->colmod_cal = 0x66; + break; + default: + ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width"); + break; + } + + gc9a01->io = io; + gc9a01->bits_per_pixel = panel_dev_config->bits_per_pixel; + gc9a01->reset_gpio_num = panel_dev_config->reset_gpio_num; + gc9a01->reset_level = panel_dev_config->flags.reset_active_high; + gc9a01->base.del = panel_gc9a01_del; + gc9a01->base.reset = panel_gc9a01_reset; + gc9a01->base.init = panel_gc9a01_init; + gc9a01->base.draw_bitmap = panel_gc9a01_draw_bitmap; + gc9a01->base.invert_color = panel_gc9a01_invert_color; + gc9a01->base.set_gap = panel_gc9a01_set_gap; + gc9a01->base.mirror = panel_gc9a01_mirror; + gc9a01->base.swap_xy = panel_gc9a01_swap_xy; + gc9a01->base.disp_on_off = panel_gc9a01_disp_on_off; + *ret_panel = &(gc9a01->base); + ESP_LOGD(TAG, "new gc9a01 panel @%p", gc9a01); + + return ESP_OK; + +err: + if (gc9a01) { + if (panel_dev_config->reset_gpio_num >= 0) { + gpio_reset_pin(panel_dev_config->reset_gpio_num); + } + free(gc9a01); + } + return ret; +} + +static esp_err_t panel_gc9a01_del(esp_lcd_panel_t *panel) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + + if (gc9a01->reset_gpio_num >= 0) { + gpio_reset_pin(gc9a01->reset_gpio_num); + } + ESP_LOGD(TAG, "del gc9a01 panel @%p", gc9a01); + free(gc9a01); + return ESP_OK; +} + +static esp_err_t panel_gc9a01_reset(esp_lcd_panel_t *panel) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + esp_lcd_panel_io_handle_t io = gc9a01->io; + + // perform hardware reset + if (gc9a01->reset_gpio_num >= 0) { + gpio_set_level(gc9a01->reset_gpio_num, gc9a01->reset_level); + vTaskDelay(pdMS_TO_TICKS(10)); + gpio_set_level(gc9a01->reset_gpio_num, !gc9a01->reset_level); + vTaskDelay(pdMS_TO_TICKS(10)); + } else { // perform software reset + esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0); + vTaskDelay(pdMS_TO_TICKS(20)); // spec, wait at least 5ms before sending new command + } + + return ESP_OK; +} + +typedef struct { + uint8_t cmd; + uint8_t data[16]; + uint8_t data_bytes; // Length of data in above data array; 0xFF = end of cmds. +} lcd_init_cmd_t; + +static const lcd_init_cmd_t vendor_specific_init[] = { + // Enable Inter Register + {0xfe, {0}, 0}, + {0xef, {0}, 0}, + {0xeb, {0x14}, 1}, + {0x84, {0x60}, 1}, + {0x85, {0xff}, 1}, + {0x86, {0xff}, 1}, + {0x87, {0xff}, 1}, + {0x8e, {0xff}, 1}, + {0x8f, {0xff}, 1}, + {0x88, {0x0a}, 1}, + {0x89, {0x23}, 1}, + {0x8a, {0x00}, 1}, + {0x8b, {0x80}, 1}, + {0x8c, {0x01}, 1}, + {0x8d, {0x03}, 1}, + {0x90, {0x08, 0x08, 0x08, 0x08}, 4}, + {0xff, {0x60, 0x01, 0x04}, 3}, + {0xC3, {0x13}, 1}, + {0xC4, {0x13}, 1}, + {0xC9, {0x30}, 1}, + {0xbe, {0x11}, 1}, + {0xe1, {0x10, 0x0e}, 2}, + {0xdf, {0x21, 0x0c, 0x02}, 3}, + // Set gamma + {0xF0, {0x45, 0x09, 0x08, 0x08, 0x26, 0x2a}, 6}, + {0xF1, {0x43, 0x70, 0x72, 0x36, 0x37, 0x6f}, 6}, + {0xF2, {0x45, 0x09, 0x08, 0x08, 0x26, 0x2a}, 6}, + {0xF3, {0x43, 0x70, 0x72, 0x36, 0x37, 0x6f}, 6}, + {0xed, {0x1b, 0x0b}, 2}, + {0xae, {0x77}, 1}, + {0xcd, {0x63}, 1}, + {0x70, {0x07, 0x07, 0x04, 0x0e, 0x0f, 0x09, 0x07, 0x08, 0x03}, 9}, + {0xE8, {0x34}, 1}, // 4 dot inversion + {0x60, {0x38, 0x0b, 0x6D, 0x6D, 0x39, 0xf0, 0x6D, 0x6D}, 8}, + {0x61, {0x38, 0xf4, 0x6D, 0x6D, 0x38, 0xf7, 0x6D, 0x6D}, 8}, + {0x62, {0x38, 0x0D, 0x71, 0xED, 0x70, 0x70, 0x38, 0x0F, 0x71, 0xEF, 0x70, 0x70}, 12}, + {0x63, {0x38, 0x11, 0x71, 0xF1, 0x70, 0x70, 0x38, 0x13, 0x71, 0xF3, 0x70, 0x70}, 12}, + {0x64, {0x28, 0x29, 0xF1, 0x01, 0xF1, 0x00, 0x07}, 7}, + {0x66, {0x3C, 0x00, 0xCD, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00}, 10}, + {0x67, {0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98}, 10}, + {0x74, {0x10, 0x45, 0x80, 0x00, 0x00, 0x4E, 0x00}, 7}, + {0x98, {0x3e, 0x07}, 2}, + {0x99, {0x3e, 0x07}, 2}, + {0, {0}, 0xff}, +}; + +static esp_err_t panel_gc9a01_init(esp_lcd_panel_t *panel) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + esp_lcd_panel_io_handle_t io = gc9a01->io; + + // LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first + esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { + gc9a01->madctl_val, + }, 1); + esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) { + gc9a01->colmod_cal, + }, 1); + + // vendor specific initialization, it can be different between manufacturers + // should consult the LCD supplier for initialization sequence code + int cmd = 0; + while (vendor_specific_init[cmd].data_bytes != 0xff) { + esp_lcd_panel_io_tx_param(io, vendor_specific_init[cmd].cmd, vendor_specific_init[cmd].data, vendor_specific_init[cmd].data_bytes & 0x1F); + cmd++; + } + + return ESP_OK; +} + +static esp_err_t panel_gc9a01_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + assert((x_start < x_end) && (y_start < y_end) && "start position must be smaller than end position"); + esp_lcd_panel_io_handle_t io = gc9a01->io; + + x_start += gc9a01->x_gap; + x_end += gc9a01->x_gap; + y_start += gc9a01->y_gap; + y_end += gc9a01->y_gap; + + // define an area of frame memory where MCU can access + esp_lcd_panel_io_tx_param(io, LCD_CMD_CASET, (uint8_t[]) { + (x_start >> 8) & 0xFF, + x_start & 0xFF, + ((x_end - 1) >> 8) & 0xFF, + (x_end - 1) & 0xFF, + }, 4); + esp_lcd_panel_io_tx_param(io, LCD_CMD_RASET, (uint8_t[]) { + (y_start >> 8) & 0xFF, + y_start & 0xFF, + ((y_end - 1) >> 8) & 0xFF, + (y_end - 1) & 0xFF, + }, 4); + // transfer frame buffer + size_t len = (x_end - x_start) * (y_end - y_start) * gc9a01->bits_per_pixel / 8; + esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR, color_data, len); + + return ESP_OK; +} + +static esp_err_t panel_gc9a01_invert_color(esp_lcd_panel_t *panel, bool invert_color_data) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + esp_lcd_panel_io_handle_t io = gc9a01->io; + int command = 0; + if (invert_color_data) { + command = LCD_CMD_INVON; + } else { + command = LCD_CMD_INVOFF; + } + esp_lcd_panel_io_tx_param(io, command, NULL, 0); + return ESP_OK; +} + +static esp_err_t panel_gc9a01_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + esp_lcd_panel_io_handle_t io = gc9a01->io; + if (mirror_x) { + gc9a01->madctl_val |= LCD_CMD_MX_BIT; + } else { + gc9a01->madctl_val &= ~LCD_CMD_MX_BIT; + } + if (mirror_y) { + gc9a01->madctl_val |= LCD_CMD_MY_BIT; + } else { + gc9a01->madctl_val &= ~LCD_CMD_MY_BIT; + } + esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { + gc9a01->madctl_val + }, 1); + return ESP_OK; +} + +static esp_err_t panel_gc9a01_swap_xy(esp_lcd_panel_t *panel, bool swap_axes) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + esp_lcd_panel_io_handle_t io = gc9a01->io; + if (swap_axes) { + gc9a01->madctl_val |= LCD_CMD_MV_BIT; + } else { + gc9a01->madctl_val &= ~LCD_CMD_MV_BIT; + } + esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { + gc9a01->madctl_val + }, 1); + return ESP_OK; +} + +static esp_err_t panel_gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + gc9a01->x_gap = x_gap; + gc9a01->y_gap = y_gap; + return ESP_OK; +} + +static esp_err_t panel_gc9a01_disp_on_off(esp_lcd_panel_t *panel, bool on_off) +{ + gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); + esp_lcd_panel_io_handle_t io = gc9a01->io; + int command = 0; + if (on_off) { + command = LCD_CMD_DISPON; + } else { + command = LCD_CMD_DISPOFF; + } + esp_lcd_panel_io_tx_param(io, command, NULL, 0); + return ESP_OK; +} diff --git a/components/lcd/esp_lcd_gc9a01/idf_component.yml b/components/lcd/esp_lcd_gc9a01/idf_component.yml new file mode 100644 index 00000000..07c35185 --- /dev/null +++ b/components/lcd/esp_lcd_gc9a01/idf_component.yml @@ -0,0 +1,5 @@ +version: "1.0.0" +description: ESP LCD GC9A01 +url: https://github.com/espressif/esp-bsp/tree/master/components/lcd/esp_lcd_gc9a01 +dependencies: + idf: ">=4.4" diff --git a/components/lcd/esp_lcd_gc9a01/include/esp_lcd_gc9a01.h b/components/lcd/esp_lcd_gc9a01/include/esp_lcd_gc9a01.h new file mode 100644 index 00000000..3d0c5a0e --- /dev/null +++ b/components/lcd/esp_lcd_gc9a01/include/esp_lcd_gc9a01.h @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#include "esp_lcd_panel_vendor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create LCD panel for model GC9A01 + * + * @param[in] io LCD panel IO handle + * @param[in] panel_dev_config general panel device configuration + * @param[out] ret_panel Returned LCD panel handle + * @return + * - ESP_ERR_INVALID_ARG if parameter is invalid + * - ESP_ERR_NO_MEM if out of memory + * - ESP_OK on success + */ +esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel); + +#ifdef __cplusplus +} +#endif diff --git a/components/lcd/esp_lcd_gc9a01/license.txt b/components/lcd/esp_lcd_gc9a01/license.txt new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/components/lcd/esp_lcd_gc9a01/license.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/components/lcd/esp_lcd_ili9341/CMakeLists.txt b/components/lcd/esp_lcd_ili9341/CMakeLists.txt new file mode 100644 index 00000000..1a3db6e3 --- /dev/null +++ b/components/lcd/esp_lcd_ili9341/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register(SRCS "esp_lcd_ili9341.c" INCLUDE_DIRS "include" REQUIRES "driver" "esp_lcd") diff --git a/components/lcd/esp_lcd_ili9341/README.md b/components/lcd/esp_lcd_ili9341/README.md new file mode 100644 index 00000000..56a07eff --- /dev/null +++ b/components/lcd/esp_lcd_ili9341/README.md @@ -0,0 +1,21 @@ +# ESP LCD ILI9341 + +Implementation of the ILI9341 LCD controller with esp_lcd component. + +| LCD controller | Communication interface | Component name | Link to datasheet | +| :------------: | :---------------------: | :------------: | :---------------: | +| ILI9341 | SPI | esp_lcd_ili9341 | [Specification](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf) | + +## Add to project + +Packages from this repository are uploaded to [Espressif's component service](https://components.espressif.com/). +You can add them to your project via `idf.py add-dependancy`, e.g. +``` + idf.py add-dependency esp_lcd_ili9341==1.0.0 +``` + +Alternatively, you can create `idf_component.yml`. More is in [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html). + +## Example use + +There is an example in ESP-IDF with this LCD controller. Please follow this [link](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/lcd/spi). diff --git a/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c b/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c new file mode 100644 index 00000000..37c49d76 --- /dev/null +++ b/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c @@ -0,0 +1,349 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_lcd_panel_interface.h" +#include "esp_lcd_panel_io.h" +#include "esp_lcd_panel_vendor.h" +#include "esp_lcd_panel_ops.h" +#include "esp_lcd_panel_commands.h" +#include "driver/gpio.h" +#include "esp_log.h" +#include "esp_check.h" + +static const char *TAG = "ili9341"; + +static esp_err_t panel_ili9341_del(esp_lcd_panel_t *panel); +static esp_err_t panel_ili9341_reset(esp_lcd_panel_t *panel); +static esp_err_t panel_ili9341_init(esp_lcd_panel_t *panel); +static esp_err_t panel_ili9341_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data); +static esp_err_t panel_ili9341_invert_color(esp_lcd_panel_t *panel, bool invert_color_data); +static esp_err_t panel_ili9341_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y); +static esp_err_t panel_ili9341_swap_xy(esp_lcd_panel_t *panel, bool swap_axes); +static esp_err_t panel_ili9341_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap); +static esp_err_t panel_ili9341_disp_on_off(esp_lcd_panel_t *panel, bool off); + +typedef struct { + esp_lcd_panel_t base; + esp_lcd_panel_io_handle_t io; + int reset_gpio_num; + bool reset_level; + int x_gap; + int y_gap; + unsigned int bits_per_pixel; + uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register + uint8_t colmod_cal; // save surrent value of LCD_CMD_COLMOD register +} ili9341_panel_t; + +esp_err_t esp_lcd_new_panel_ili9341(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel) +{ + esp_err_t ret = ESP_OK; + ili9341_panel_t *ili9341 = NULL; + ESP_GOTO_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); + ili9341 = calloc(1, sizeof(ili9341_panel_t)); + ESP_GOTO_ON_FALSE(ili9341, ESP_ERR_NO_MEM, err, TAG, "no mem for ili9341 panel"); + + if (panel_dev_config->reset_gpio_num >= 0) { + gpio_config_t io_conf = { + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num, + }; + ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed"); + } + + switch (panel_dev_config->color_space) { + case ESP_LCD_COLOR_SPACE_RGB: + ili9341->madctl_val = 0; + break; + case ESP_LCD_COLOR_SPACE_BGR: + ili9341->madctl_val |= LCD_CMD_BGR_BIT; + break; + default: + ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color space"); + break; + } + + switch (panel_dev_config->bits_per_pixel) { + case 16: + ili9341->colmod_cal = 0x55; + break; + case 18: + ili9341->colmod_cal = 0x66; + break; + default: + ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width"); + break; + } + + ili9341->io = io; + ili9341->bits_per_pixel = panel_dev_config->bits_per_pixel; + ili9341->reset_gpio_num = panel_dev_config->reset_gpio_num; + ili9341->reset_level = panel_dev_config->flags.reset_active_high; + ili9341->base.del = panel_ili9341_del; + ili9341->base.reset = panel_ili9341_reset; + ili9341->base.init = panel_ili9341_init; + ili9341->base.draw_bitmap = panel_ili9341_draw_bitmap; + ili9341->base.invert_color = panel_ili9341_invert_color; + ili9341->base.set_gap = panel_ili9341_set_gap; + ili9341->base.mirror = panel_ili9341_mirror; + ili9341->base.swap_xy = panel_ili9341_swap_xy; + ili9341->base.disp_on_off = panel_ili9341_disp_on_off; + *ret_panel = &(ili9341->base); + ESP_LOGD(TAG, "new ili9341 panel @%p", ili9341); + + return ESP_OK; + +err: + if (ili9341) { + if (panel_dev_config->reset_gpio_num >= 0) { + gpio_reset_pin(panel_dev_config->reset_gpio_num); + } + free(ili9341); + } + return ret; +} + +static esp_err_t panel_ili9341_del(esp_lcd_panel_t *panel) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + + if (ili9341->reset_gpio_num >= 0) { + gpio_reset_pin(ili9341->reset_gpio_num); + } + ESP_LOGD(TAG, "del ili9341 panel @%p", ili9341); + free(ili9341); + return ESP_OK; +} + +static esp_err_t panel_ili9341_reset(esp_lcd_panel_t *panel) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + esp_lcd_panel_io_handle_t io = ili9341->io; + + // perform hardware reset + if (ili9341->reset_gpio_num >= 0) { + gpio_set_level(ili9341->reset_gpio_num, ili9341->reset_level); + vTaskDelay(pdMS_TO_TICKS(10)); + gpio_set_level(ili9341->reset_gpio_num, !ili9341->reset_level); + vTaskDelay(pdMS_TO_TICKS(10)); + } else { // perform software reset + esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0); + vTaskDelay(pdMS_TO_TICKS(20)); // spec, wait at least 5ms before sending new command + } + + return ESP_OK; +} + +typedef struct { + uint8_t cmd; + uint8_t data[16]; + uint8_t data_bytes; // Length of data in above data array; 0xFF = end of cmds. +} lcd_init_cmd_t; + +static const lcd_init_cmd_t vendor_specific_init[] = { + /* SW reset */ + {LCD_CMD_SWRESET, {0}, 0}, + /* 200 ms delay */ + {0x80, {250}, 1}, + /* Power contorl B, power control = 0, DC_ENA = 1 */ + {0xCF, {0x00, 0xAA, 0XE0}, 3}, + /* Power on sequence control, + * cp1 keeps 1 frame, 1st frame enable + * vcl = 0, ddvdh=3, vgh=1, vgl=2 + * DDVDH_ENH=1 + */ + {0xED, {0x67, 0x03, 0X12, 0X81}, 4}, + /* Driver timing control A, + * non-overlap=default +1 + * EQ=default - 1, CR=default + * pre-charge=default - 1 + */ + {0xE8, {0x8A, 0x01, 0x78}, 3}, + /* Power control A, Vcore=1.6V, DDVDH=5.6V */ + {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, + /* Pump ratio control, DDVDH=2xVCl */ + {0xF7, {0x20}, 1}, + + {0xF7, {0x20}, 1}, + /* Driver timing control, all=0 unit */ + {0xEA, {0x00, 0x00}, 2}, + /* Power control 1, GVDD=4.75V */ + {0xC0, {0x23}, 1}, + /* Power control 2, DDVDH=VCl*2, VGH=VCl*7, VGL=-VCl*3 */ + {0xC1, {0x11}, 1}, + /* VCOM control 1, VCOMH=4.025V, VCOML=-0.950V */ + {0xC5, {0x43, 0x4C}, 2}, + /* VCOM control 2, VCOMH=VMH-2, VCOML=VML-2 */ + {0xC7, {0xA0}, 1}, + /* Memory access contorl, MX=MY=0, MV=1, ML=0, BGR=1, MH=0 */ + {LCD_CMD_MADCTL, {(LCD_CMD_MV_BIT | 0x08)}, 1}, + /* Pixel format, 16bits/pixel for RGB/MCU interface */ + {0x3A, {0x55}, 1}, //*** INTERFACE PIXEL FORMAT: 0x66 -> 18 bit; 0x55 -> 16 bit + /* Frame rate control, f=fosc, 70Hz fps */ + {0xB1, {0x00, 0x1B}, 2}, + /* Enable 3G, disabled */ + {0xF2, {0x00}, 1}, + /* Gamma set, curve 1 */ + {0x26, {0x01}, 1}, + /* Positive gamma correction */ + {0xE0, {0x1F, 0x36, 0x36, 0x3A, 0x0C, 0x05, 0x4F, 0X87, 0x3C, 0x08, 0x11, 0x35, 0x19, 0x13, 0x00}, 15}, + /* Negative gamma correction */ + {0xE1, {0x00, 0x09, 0x09, 0x05, 0x13, 0x0A, 0x30, 0x78, 0x43, 0x07, 0x0E, 0x0A, 0x26, 0x2C, 0x1F}, 15}, + /* Positive Voltage Gamma Control */ + //{LCD_CMD_GMCTRP1, {0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19}, 14}, + /* Negative Voltage Gamma Control */ + //{LCD_CMD_GMCTRN1, {0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19}, 14}, + /* Column address set, SC=0, EC=0xEF */ + {LCD_CMD_CASET, {0x00, 0x00, 0x00, 0xEF}, 4}, + /* Page address set, SP=0, EP=0x013F */ + {LCD_CMD_RASET, {0x00, 0x00, 0x01, 0x3f}, 4}, + /* Memory write */ + {LCD_CMD_RAMWR, {0}, 0}, + /* Entry mode set, Low vol detect disabled, normal display */ + {0xB7, {0x07}, 1}, + /* Display function control */ + {0xB6, {0x0A, 0x02}, 2}, + /* Sleep out */ + {LCD_CMD_SLPOUT, {0}, 0x80}, + /* Display on */ + {LCD_CMD_DISPON, {0}, 0x80}, + /* Invert colors (The TFT is inverted, the IPS is not inverted!!!) */ + //{LCD_CMD_INVONN, {0x00}, 0}, + /* 200 ms delay */ + //{LCD_CMD_DELAY, {200}, 1}, + {0, {0}, 0xff}, +}; + +static esp_err_t panel_ili9341_init(esp_lcd_panel_t *panel) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + esp_lcd_panel_io_handle_t io = ili9341->io; + + // LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first + esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { + ili9341->madctl_val, + }, 1); + esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) { + ili9341->colmod_cal, + }, 1); + + // vendor specific initialization, it can be different between manufacturers + // should consult the LCD supplier for initialization sequence code + int cmd = 0; + while (vendor_specific_init[cmd].data_bytes != 0xff) { + esp_lcd_panel_io_tx_param(io, vendor_specific_init[cmd].cmd, vendor_specific_init[cmd].data, vendor_specific_init[cmd].data_bytes & 0x1F); + cmd++; + } + + return ESP_OK; +} + +static esp_err_t panel_ili9341_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + assert((x_start < x_end) && (y_start < y_end) && "start position must be smaller than end position"); + esp_lcd_panel_io_handle_t io = ili9341->io; + + x_start += ili9341->x_gap; + x_end += ili9341->x_gap; + y_start += ili9341->y_gap; + y_end += ili9341->y_gap; + + // define an area of frame memory where MCU can access + esp_lcd_panel_io_tx_param(io, LCD_CMD_CASET, (uint8_t[]) { + (x_start >> 8) & 0xFF, + x_start & 0xFF, + ((x_end - 1) >> 8) & 0xFF, + (x_end - 1) & 0xFF, + }, 4); + esp_lcd_panel_io_tx_param(io, LCD_CMD_RASET, (uint8_t[]) { + (y_start >> 8) & 0xFF, + y_start & 0xFF, + ((y_end - 1) >> 8) & 0xFF, + (y_end - 1) & 0xFF, + }, 4); + // transfer frame buffer + size_t len = (x_end - x_start) * (y_end - y_start) * ili9341->bits_per_pixel / 8; + esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR, color_data, len); + + return ESP_OK; +} + +static esp_err_t panel_ili9341_invert_color(esp_lcd_panel_t *panel, bool invert_color_data) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + esp_lcd_panel_io_handle_t io = ili9341->io; + int command = 0; + if (invert_color_data) { + command = LCD_CMD_INVON; + } else { + command = LCD_CMD_INVOFF; + } + esp_lcd_panel_io_tx_param(io, command, NULL, 0); + return ESP_OK; +} + +static esp_err_t panel_ili9341_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + esp_lcd_panel_io_handle_t io = ili9341->io; + if (mirror_x) { + ili9341->madctl_val |= LCD_CMD_MX_BIT; + } else { + ili9341->madctl_val &= ~LCD_CMD_MX_BIT; + } + if (mirror_y) { + ili9341->madctl_val |= LCD_CMD_MY_BIT; + } else { + ili9341->madctl_val &= ~LCD_CMD_MY_BIT; + } + esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { + ili9341->madctl_val + }, 1); + return ESP_OK; +} + +static esp_err_t panel_ili9341_swap_xy(esp_lcd_panel_t *panel, bool swap_axes) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + esp_lcd_panel_io_handle_t io = ili9341->io; + if (swap_axes) { + ili9341->madctl_val |= LCD_CMD_MV_BIT; + } else { + ili9341->madctl_val &= ~LCD_CMD_MV_BIT; + } + esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { + ili9341->madctl_val + }, 1); + return ESP_OK; +} + +static esp_err_t panel_ili9341_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + ili9341->x_gap = x_gap; + ili9341->y_gap = y_gap; + return ESP_OK; +} + +static esp_err_t panel_ili9341_disp_on_off(esp_lcd_panel_t *panel, bool on_off) +{ + ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); + esp_lcd_panel_io_handle_t io = ili9341->io; + int command = 0; + if (on_off) { + command = LCD_CMD_DISPON; + } else { + command = LCD_CMD_DISPOFF; + } + esp_lcd_panel_io_tx_param(io, command, NULL, 0); + return ESP_OK; +} diff --git a/components/lcd/esp_lcd_ili9341/idf_component.yml b/components/lcd/esp_lcd_ili9341/idf_component.yml new file mode 100644 index 00000000..e11cbf94 --- /dev/null +++ b/components/lcd/esp_lcd_ili9341/idf_component.yml @@ -0,0 +1,5 @@ +version: "1.0.0" +description: ESP LCD ILI9341 +url: https://github.com/espressif/esp-bsp/tree/master/components/lcd/esp_lcd_ili9341 +dependencies: + idf: ">=4.4" diff --git a/components/lcd/esp_lcd_ili9341/include/esp_lcd_ili9341.h b/components/lcd/esp_lcd_ili9341/include/esp_lcd_ili9341.h new file mode 100644 index 00000000..f3582ff6 --- /dev/null +++ b/components/lcd/esp_lcd_ili9341/include/esp_lcd_ili9341.h @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#include "esp_lcd_panel_vendor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create LCD panel for model ILI9341 + * + * @param[in] io LCD panel IO handle + * @param[in] panel_dev_config general panel device configuration + * @param[out] ret_panel Returned LCD panel handle + * @return + * - ESP_ERR_INVALID_ARG if parameter is invalid + * - ESP_ERR_NO_MEM if out of memory + * - ESP_OK on success + */ +esp_err_t esp_lcd_new_panel_ili9341(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel); + +#ifdef __cplusplus +} +#endif diff --git a/components/lcd/esp_lcd_ili9341/license.txt b/components/lcd/esp_lcd_ili9341/license.txt new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/components/lcd/esp_lcd_ili9341/license.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. From 44018a015d48af21a124725086801dbb4267d09b Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Fri, 8 Jul 2022 11:08:57 +0200 Subject: [PATCH 2/8] Fixed IOT button register after button component update. --- examples/display_audio/main/bsp_kaluga_disp_audio_example.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/display_audio/main/bsp_kaluga_disp_audio_example.c b/examples/display_audio/main/bsp_kaluga_disp_audio_example.c index 836638ca..acf8e2ca 100644 --- a/examples/display_audio/main/bsp_kaluga_disp_audio_example.c +++ b/examples/display_audio/main/bsp_kaluga_disp_audio_example.c @@ -280,7 +280,7 @@ void app_main(void) for (int i = 0; i < BSP_BUTTON_NUM; i++) { audio_button[i] = iot_button_create(&bsp_button_config[i]); assert(audio_button[i] != NULL); - ESP_ERROR_CHECK(iot_button_register_cb(audio_button[i], BUTTON_PRESS_DOWN, btn_handler)); + ESP_ERROR_CHECK(iot_button_register_cb(audio_button[i], BUTTON_PRESS_DOWN, btn_handler, NULL)); } bsp_display_start(); // Start LVGL and LCD driver From d1418ec73f2abe50d20cb4695e5a0c3d88e0c9c3 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Fri, 8 Jul 2022 15:32:59 +0200 Subject: [PATCH 3/8] Clean init. --- components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c b/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c index 37c49d76..445ff127 100644 --- a/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c +++ b/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c @@ -195,10 +195,6 @@ static const lcd_init_cmd_t vendor_specific_init[] = { {0xE0, {0x1F, 0x36, 0x36, 0x3A, 0x0C, 0x05, 0x4F, 0X87, 0x3C, 0x08, 0x11, 0x35, 0x19, 0x13, 0x00}, 15}, /* Negative gamma correction */ {0xE1, {0x00, 0x09, 0x09, 0x05, 0x13, 0x0A, 0x30, 0x78, 0x43, 0x07, 0x0E, 0x0A, 0x26, 0x2C, 0x1F}, 15}, - /* Positive Voltage Gamma Control */ - //{LCD_CMD_GMCTRP1, {0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19}, 14}, - /* Negative Voltage Gamma Control */ - //{LCD_CMD_GMCTRN1, {0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19}, 14}, /* Column address set, SC=0, EC=0xEF */ {LCD_CMD_CASET, {0x00, 0x00, 0x00, 0xEF}, 4}, /* Page address set, SP=0, EP=0x013F */ @@ -213,10 +209,9 @@ static const lcd_init_cmd_t vendor_specific_init[] = { {LCD_CMD_SLPOUT, {0}, 0x80}, /* Display on */ {LCD_CMD_DISPON, {0}, 0x80}, - /* Invert colors (The TFT is inverted, the IPS is not inverted!!!) */ - //{LCD_CMD_INVONN, {0x00}, 0}, - /* 200 ms delay */ - //{LCD_CMD_DELAY, {200}, 1}, + /* Invert colors */ + {LCD_CMD_INVOFF, {0}, 0}, + {0, {0}, 0xff}, }; From 90de190fb66965e7585299ce682f4077ee3f38cd Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Tue, 12 Jul 2022 14:12:25 +0200 Subject: [PATCH 4/8] Fixed esp_rainmaker. --- examples/rainmaker_example/esp-rainmaker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rainmaker_example/esp-rainmaker b/examples/rainmaker_example/esp-rainmaker index 677a244f..2f0f5e08 160000 --- a/examples/rainmaker_example/esp-rainmaker +++ b/examples/rainmaker_example/esp-rainmaker @@ -1 +1 @@ -Subproject commit 677a244fe178981b4b13508c92f219a1b61f2898 +Subproject commit 2f0f5e0893c30a12034d68f56b69e734519ae015 From 0156fa1a725b18a121b357a2047b2da48046d912 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Tue, 12 Jul 2022 15:04:21 +0200 Subject: [PATCH 5/8] Upload component into components manager. --- .github/workflows/upload_component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upload_component.yml b/.github/workflows/upload_component.yml index e6c1711c..a838e8dc 100644 --- a/.github/workflows/upload_component.yml +++ b/.github/workflows/upload_component.yml @@ -14,6 +14,6 @@ jobs: - name: Upload components to component service uses: espressif/github-actions/upload_components@master with: - directories: "esp32_azure_iot_kit;esp32_s2_kaluga_kit;esp_wrover_kit;esp-box;esp32_s3_usb_otg;components/bh1750;components/es8311;components/fbm320;components/hts221;components/mag3110;components/mpu6050;components/ssd1306;components/esp_lcd_touch;components/esp_lcd_touch_ft5x06;components/esp_lcd_touch_gt911;components/esp_lcd_touch_tt21100;components/esp_jpeg" + directories: "esp32_azure_iot_kit;esp32_s2_kaluga_kit;esp_wrover_kit;esp-box;esp32_s3_usb_otg;components/bh1750;components/es8311;components/fbm320;components/hts221;components/mag3110;components/mpu6050;components/ssd1306;components/esp_lcd_touch;components/esp_lcd_touch_ft5x06;components/esp_lcd_touch_gt911;components/esp_lcd_touch_tt21100;components/esp_jpeg;components/lcd/esp_lcd_gc9a01;components/lcd/esp_lcd_ili9341;" namespace: "espressif" api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} From db1e393ea912ec46ed43d219863e1e71606fbcf1 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Fri, 15 Jul 2022 09:04:23 +0200 Subject: [PATCH 6/8] Set components/lcd folder into component dirs. --- .github/workflows/upload_component.yml | 2 +- test_app/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/upload_component.yml b/.github/workflows/upload_component.yml index a838e8dc..8a113900 100644 --- a/.github/workflows/upload_component.yml +++ b/.github/workflows/upload_component.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@master - name: Upload components to component service - uses: espressif/github-actions/upload_components@master + uses: espressif/upload-components-ci-action@v1 with: directories: "esp32_azure_iot_kit;esp32_s2_kaluga_kit;esp_wrover_kit;esp-box;esp32_s3_usb_otg;components/bh1750;components/es8311;components/fbm320;components/hts221;components/mag3110;components/mpu6050;components/ssd1306;components/esp_lcd_touch;components/esp_lcd_touch_ft5x06;components/esp_lcd_touch_gt911;components/esp_lcd_touch_tt21100;components/esp_jpeg;components/lcd/esp_lcd_gc9a01;components/lcd/esp_lcd_ili9341;" namespace: "espressif" diff --git a/test_app/CMakeLists.txt b/test_app/CMakeLists.txt index 76eeca46..f577f9e4 100644 --- a/test_app/CMakeLists.txt +++ b/test_app/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "../components") +set(EXTRA_COMPONENT_DIRS "../components/lcd") include($ENV{IDF_PATH}/tools/cmake/version.cmake) # $ENV{IDF_VERSION} was added after v4.3... if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "4.4") From 500524dcb902a6541ddc84b3e8c7e33547350443 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Fri, 15 Jul 2022 09:29:16 +0200 Subject: [PATCH 7/8] Exclude lcd components from testing on IDF 4.3 --- test_app/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_app/CMakeLists.txt b/test_app/CMakeLists.txt index f577f9e4..ef71f572 100644 --- a/test_app/CMakeLists.txt +++ b/test_app/CMakeLists.txt @@ -7,7 +7,7 @@ set(EXTRA_COMPONENT_DIRS "../components/lcd") include($ENV{IDF_PATH}/tools/cmake/version.cmake) # $ENV{IDF_VERSION} was added after v4.3... if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "4.4") - set(EXCLUDE_COMPONENTS "es8311" "esp_jpeg" "esp_lcd_touch" "esp_lcd_touch_ft5x06" "esp_lcd_touch_gt911" "esp_lcd_touch_tt21100") + set(EXCLUDE_COMPONENTS "es8311" "esp_jpeg" "esp_lcd_touch" "esp_lcd_touch_ft5x06" "esp_lcd_touch_gt911" "esp_lcd_touch_tt21100" "esp_lcd_gc9a01" "esp_lcd_ili9341") endif() # Set the components to include the tests for. From cb7960c229ceea5fa1f8de0e41ada252ff799d65 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Fri, 15 Jul 2022 12:19:37 +0200 Subject: [PATCH 8/8] Suport lcd components in IDF 4.4 --- components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c | 9 +++++++++ components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c b/components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c index dd63de01..c42c14a8 100644 --- a/components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c +++ b/components/lcd/esp_lcd_gc9a01/esp_lcd_gc9a01.c @@ -93,7 +93,11 @@ esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp gc9a01->base.set_gap = panel_gc9a01_set_gap; gc9a01->base.mirror = panel_gc9a01_mirror; gc9a01->base.swap_xy = panel_gc9a01_swap_xy; +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + gc9a01->base.disp_off = panel_gc9a01_disp_on_off; +#else gc9a01->base.disp_on_off = panel_gc9a01_disp_on_off; +#endif *ret_panel = &(gc9a01->base); ESP_LOGD(TAG, "new gc9a01 panel @%p", gc9a01); @@ -313,6 +317,11 @@ static esp_err_t panel_gc9a01_disp_on_off(esp_lcd_panel_t *panel, bool on_off) gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base); esp_lcd_panel_io_handle_t io = gc9a01->io; int command = 0; + +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + on_off = !on_off; +#endif + if (on_off) { command = LCD_CMD_DISPON; } else { diff --git a/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c b/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c index 445ff127..53d20f17 100644 --- a/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c +++ b/components/lcd/esp_lcd_ili9341/esp_lcd_ili9341.c @@ -93,7 +93,11 @@ esp_err_t esp_lcd_new_panel_ili9341(const esp_lcd_panel_io_handle_t io, const es ili9341->base.set_gap = panel_ili9341_set_gap; ili9341->base.mirror = panel_ili9341_mirror; ili9341->base.swap_xy = panel_ili9341_swap_xy; +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + ili9341->base.disp_off = panel_ili9341_disp_on_off; +#else ili9341->base.disp_on_off = panel_ili9341_disp_on_off; +#endif *ret_panel = &(ili9341->base); ESP_LOGD(TAG, "new ili9341 panel @%p", ili9341); @@ -334,6 +338,11 @@ static esp_err_t panel_ili9341_disp_on_off(esp_lcd_panel_t *panel, bool on_off) ili9341_panel_t *ili9341 = __containerof(panel, ili9341_panel_t, base); esp_lcd_panel_io_handle_t io = ili9341->io; int command = 0; + +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + on_off = !on_off; +#endif + if (on_off) { command = LCD_CMD_DISPON; } else {