├── .gitmodules ├── Kconfig.projbuild ├── LICENSE ├── README.md ├── component.mk ├── disp_spi.c ├── disp_spi.h ├── docs └── ST7789.pdf ├── ili9341.c ├── ili9341.h ├── lv_conf.h ├── st7789.c └── st7789.h /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lvgl"] 2 | path = lvgl 3 | url = git@github.com:littlevgl/lvgl.git 4 | -------------------------------------------------------------------------------- /Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "LittlevGL" 2 | 3 | config DISP_HOR_RES 4 | int "Display Horizontal Resolution" 5 | range 0 2000 6 | default 240 7 | help 8 | The horizontal resolution of the display. 9 | 10 | config DISP_VER_RES 11 | int "Display Vertical Resolution" 12 | range 0 2000 13 | default 240 14 | help 15 | The vertical resolution of the display. 16 | 17 | config DISP_SPI_SPEED 18 | int "Display SPI Speed in MHz" 19 | range 0 80 20 | default 40 21 | help 22 | SPI clock speed 23 | 24 | config DISP_SPI_MOSI 25 | int "Display SPI MOSI GPIO" 26 | range 0 34 27 | default 23 28 | help 29 | GPIO used for display SPI MOSI 30 | 31 | config DISP_SPI_CLK 32 | int "Display SPI CLK GPIO" 33 | range 0 34 34 | default 19 35 | help 36 | GPIO used for display SPI CLK 37 | 38 | config DISP_SPI_CS 39 | int "Display SPI CS" 40 | range -1 34 41 | default -1 42 | help 43 | GPIO used for SPI CS. 44 | 45 | On some st7789 modules, the CS is hard wired. On such modules set to -1. 46 | 47 | config DISP_DC 48 | int "Display DC GPIO" 49 | range 0 34 50 | default 21 51 | help 52 | GPIO used for display DC 53 | 54 | config DISP_RST 55 | int "Display Reset GPIO" 56 | range 0 34 57 | default 18 58 | help 59 | GPIO used for display Reset 60 | 61 | config DISP_BCKL 62 | int "Display Backlight GPIO" 63 | range 0 34 64 | default 5 65 | help 66 | GPIO used to control display Backlight 67 | 68 | config DISP_BCKL_ACTIVE_LVL 69 | int "Display Backlight Active Level" 70 | range 0 1 71 | default 1 72 | help 73 | Which level turn on the backlight 74 | 75 | endmenu 76 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Lars Boegild Thomsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp-idf-littlevgl 2 | ESP-IDF Port of littlevgl supporting st7789 3 | 4 | For example of how to use this in your esp-idf project, see: 5 | 6 | https://github.com/lbthomsen/esp-idf-littlevgl-demo 7 | 8 | ## Display Support 9 | 10 | The module currently supports the ST7789. 11 | 12 | ## Acknowledgements 13 | 14 | The foundation for this port was the esp32_ili9341 port by littlevgl (see https://github.com/littlevgl/esp32_ili9341). 15 | 16 | Some st7789 code was lifted from https://github.com/Bodmer/TFT_eSPI. -------------------------------------------------------------------------------- /component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | 5 | CFLAGS += -DLV_CONF_INCLUDE_SIMPLE 6 | CFLAGS += -DILI9341_BCKL_ACTIVE_LVL=1 7 | 8 | # Set to 1 if your display have touch support, otherwise set it to 0. 9 | CFLAGS += -DTOUCH_SUPPORT=0 10 | 11 | COMPONENT_SRCDIRS := . \ 12 | lvgl \ 13 | lvgl/src \ 14 | lvgl/src/lv_core \ 15 | lvgl/src/lv_draw \ 16 | lvgl/src/lv_font \ 17 | lvgl/src/lv_hal \ 18 | lvgl/src/lv_misc \ 19 | lvgl/src/lv_objx \ 20 | lvgl/src/lv_themes 21 | 22 | 23 | COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) .. ../ 24 | -------------------------------------------------------------------------------- /disp_spi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file disp_spi.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "disp_spi.h" 10 | #include "esp_system.h" 11 | #include "driver/gpio.h" 12 | #include "driver/spi_master.h" 13 | #include 14 | #include 15 | #include 16 | #include "freertos/task.h" 17 | #include "lvgl/lvgl.h" 18 | #include "st7789.h" 19 | #include "sdkconfig.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /********************** 30 | * STATIC PROTOTYPES 31 | **********************/ 32 | static void IRAM_ATTR spi_ready (spi_transaction_t *trans); 33 | 34 | /********************** 35 | * STATIC VARIABLES 36 | **********************/ 37 | static spi_device_handle_t spi; 38 | static volatile bool spi_trans_in_progress; 39 | static volatile bool spi_color_sent; 40 | 41 | /********************** 42 | * MACROS 43 | **********************/ 44 | 45 | /********************** 46 | * GLOBAL FUNCTIONS 47 | **********************/ 48 | void disp_spi_init(void) 49 | { 50 | 51 | esp_err_t ret; 52 | 53 | spi_bus_config_t buscfg={ 54 | .miso_io_num=-1, 55 | .mosi_io_num=DISP_SPI_MOSI, 56 | .sclk_io_num=DISP_SPI_CLK, 57 | .quadwp_io_num=-1, 58 | .quadhd_io_num=-1, 59 | .max_transfer_sz = DISP_BUF_SIZE * 2, // defined currently in st7789 - which is silly! 60 | }; 61 | 62 | spi_device_interface_config_t devcfg={ 63 | .clock_speed_hz=CONFIG_DISP_SPI_SPEED*1000*1000, //Clock out at 40 MHz 64 | .mode=0, //SPI mode 0 65 | .spics_io_num=DISP_SPI_CS, //CS pin 66 | .queue_size=1, 67 | .pre_cb=NULL, 68 | .post_cb=spi_ready, 69 | .flags = SPI_DEVICE_HALFDUPLEX 70 | }; 71 | 72 | //Initialize the SPI bus 73 | ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1); 74 | assert(ret==ESP_OK); 75 | 76 | //Attach the LCD to the SPI bus 77 | ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi); 78 | assert(ret==ESP_OK); 79 | } 80 | 81 | void disp_spi_send_data(uint8_t * data, uint16_t length) 82 | { 83 | if (length == 0) return; //no need to send anything 84 | 85 | while(spi_trans_in_progress); 86 | 87 | spi_transaction_t t = { 88 | .length = length * 8, // transaction length is in bits 89 | .tx_buffer = data 90 | }; 91 | 92 | spi_trans_in_progress = true; 93 | spi_color_sent = false; //Mark the "lv_flush_ready" NOT needs to be called in "spi_ready" 94 | spi_device_queue_trans(spi, &t, portMAX_DELAY); 95 | 96 | } 97 | 98 | void disp_spi_send_colors(uint8_t * data, uint16_t length) 99 | { 100 | if (length == 0) return; //no need to send anything 101 | 102 | while(spi_trans_in_progress); 103 | 104 | spi_transaction_t t = { 105 | .length = length * 8, // transaction length is in bits 106 | .tx_buffer = data 107 | }; 108 | 109 | spi_trans_in_progress = true; 110 | spi_color_sent = true; //Mark the "lv_flush_ready" needs to be called in "spi_ready" 111 | spi_device_queue_trans(spi, &t, portMAX_DELAY); 112 | } 113 | 114 | 115 | /********************** 116 | * STATIC FUNCTIONS 117 | **********************/ 118 | 119 | static void IRAM_ATTR spi_ready (spi_transaction_t *trans) 120 | { 121 | spi_trans_in_progress = false; 122 | 123 | lv_disp_t * disp = lv_refr_get_disp_refreshing(); 124 | if(spi_color_sent) lv_disp_flush_ready(&disp->driver); 125 | } 126 | -------------------------------------------------------------------------------- /disp_spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file disp_spi.h 3 | * 4 | */ 5 | 6 | #ifndef DISP_SPI_H 7 | #define DISP_SPI_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | #include "sdkconfig.h" 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | #define DISP_SPI_MOSI CONFIG_DISP_SPI_MOSI 24 | #define DISP_SPI_CLK CONFIG_DISP_SPI_CLK 25 | #define DISP_SPI_CS CONFIG_DISP_SPI_CS 26 | 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | void disp_spi_init(void); 36 | void disp_spi_send_data(uint8_t * data, uint16_t length); 37 | void disp_spi_send_colors(uint8_t * data, uint16_t length); 38 | 39 | /********************** 40 | * MACROS 41 | **********************/ 42 | 43 | 44 | #ifdef __cplusplus 45 | } /* extern "C" */ 46 | #endif 47 | 48 | #endif /*DISP_SPI_H*/ 49 | -------------------------------------------------------------------------------- /docs/ST7789.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbthomsen/esp-idf-littlevgl/3d461fa959d85ac69bd79bb11a4ccd98c87ed363/docs/ST7789.pdf -------------------------------------------------------------------------------- /ili9341.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ili9341.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "ili9341.h" 10 | #include "disp_spi.h" 11 | #include "driver/gpio.h" 12 | #include "freertos/FreeRTOS.h" 13 | #include "freertos/task.h" 14 | 15 | /********************* 16 | * DEFINES 17 | *********************/ 18 | 19 | /********************** 20 | * TYPEDEFS 21 | **********************/ 22 | 23 | /*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */ 24 | typedef struct { 25 | uint8_t cmd; 26 | uint8_t data[16]; 27 | uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds. 28 | } lcd_init_cmd_t; 29 | 30 | /********************** 31 | * STATIC PROTOTYPES 32 | **********************/ 33 | static void ili9341_send_cmd(uint8_t cmd); 34 | static void ili9341_send_data(void * data, uint16_t length); 35 | static void ili9341_send_color(void * data, uint16_t length); 36 | 37 | /********************** 38 | * STATIC VARIABLES 39 | **********************/ 40 | 41 | /********************** 42 | * MACROS 43 | **********************/ 44 | 45 | /********************** 46 | * GLOBAL FUNCTIONS 47 | **********************/ 48 | 49 | void ili9341_init(void) 50 | { 51 | lcd_init_cmd_t ili_init_cmds[]={ 52 | {0xCF, {0x00, 0x83, 0X30}, 3}, 53 | {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, 54 | {0xE8, {0x85, 0x01, 0x79}, 3}, 55 | {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, 56 | {0xF7, {0x20}, 1}, 57 | {0xEA, {0x00, 0x00}, 2}, 58 | {0xC0, {0x26}, 1}, /*Power control*/ 59 | {0xC1, {0x11}, 1}, /*Power control */ 60 | {0xC5, {0x35, 0x3E}, 2}, /*VCOM control*/ 61 | {0xC7, {0xBE}, 1}, /*VCOM control*/ 62 | {0x36, {0x28}, 1}, /*Memory Access Control*/ 63 | {0x3A, {0x55}, 1}, /*Pixel Format Set*/ 64 | {0xB1, {0x00, 0x1B}, 2}, 65 | {0xF2, {0x08}, 1}, 66 | {0x26, {0x01}, 1}, 67 | {0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15}, 68 | {0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15}, 69 | {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, 70 | {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4}, 71 | {0x2C, {0}, 0}, 72 | {0xB7, {0x07}, 1}, 73 | {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, 74 | {0x11, {0}, 0x80}, 75 | {0x29, {0}, 0x80}, 76 | {0, {0}, 0xff}, 77 | }; 78 | 79 | //Initialize non-SPI GPIOs 80 | gpio_set_direction(ILI9341_DC, GPIO_MODE_OUTPUT); 81 | gpio_set_direction(ILI9341_RST, GPIO_MODE_OUTPUT); 82 | gpio_set_direction(ILI9341_BCKL, GPIO_MODE_OUTPUT); 83 | 84 | //Reset the display 85 | gpio_set_level(ILI9341_RST, 0); 86 | vTaskDelay(100 / portTICK_RATE_MS); 87 | gpio_set_level(ILI9341_RST, 1); 88 | vTaskDelay(100 / portTICK_RATE_MS); 89 | 90 | 91 | printf("ILI9341 initialization.\n"); 92 | 93 | 94 | //Send all the commands 95 | uint16_t cmd = 0; 96 | while (ili_init_cmds[cmd].databytes!=0xff) { 97 | ili9341_send_cmd(ili_init_cmds[cmd].cmd); 98 | ili9341_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); 99 | if (ili_init_cmds[cmd].databytes & 0x80) { 100 | vTaskDelay(100 / portTICK_RATE_MS); 101 | } 102 | cmd++; 103 | } 104 | 105 | ///Enable backlight 106 | printf("Enable backlight.\n"); 107 | gpio_set_level(ILI9341_BCKL, ILI9341_BCKL_ACTIVE_LVL); 108 | } 109 | 110 | 111 | void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map) 112 | { 113 | uint8_t data[4]; 114 | 115 | /*Column addresses*/ 116 | ili9341_send_cmd(0x2A); 117 | data[0] = (area->x1 >> 8) & 0xFF; 118 | data[1] = area->x1 & 0xFF; 119 | data[2] = (area->x2 >> 8) & 0xFF; 120 | data[3] = area->x2 & 0xFF; 121 | ili9341_send_data(data, 4); 122 | 123 | /*Page addresses*/ 124 | ili9341_send_cmd(0x2B); 125 | data[0] = (area->y1 >> 8) & 0xFF; 126 | data[1] = area->y1 & 0xFF; 127 | data[2] = (area->y2 >> 8) & 0xFF; 128 | data[3] = area->y2 & 0xFF; 129 | ili9341_send_data(data, 4); 130 | 131 | /*Memory write*/ 132 | ili9341_send_cmd(0x2C); 133 | 134 | 135 | uint32_t size = lv_area_get_width(area) * lv_area_get_height(area); 136 | 137 | ili9341_send_color((void*)color_map, size * 2); 138 | 139 | } 140 | 141 | /********************** 142 | * STATIC FUNCTIONS 143 | **********************/ 144 | 145 | 146 | static void ili9341_send_cmd(uint8_t cmd) 147 | { 148 | gpio_set_level(ILI9341_DC, 0); /*Command mode*/ 149 | disp_spi_send_data(&cmd, 1); 150 | } 151 | 152 | static void ili9341_send_data(void * data, uint16_t length) 153 | { 154 | gpio_set_level(ILI9341_DC, 1); /*Data mode*/ 155 | disp_spi_send_data(data, length); 156 | } 157 | 158 | static void ili9341_send_color(void * data, uint16_t length) 159 | { 160 | gpio_set_level(ILI9341_DC, 1); /*Data mode*/ 161 | disp_spi_send_colors(data, length); 162 | } 163 | -------------------------------------------------------------------------------- /ili9341.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | #ifndef ILI9341_H 7 | #define ILI9341_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lvgl/lvgl.h" 17 | #include "sdkconfig.h" 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | #define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40) 23 | #define ILI9341_DC CONFIG_DISP_DC 24 | #define ILI9341_RST CONFIG_DISP_RST 25 | #define ILI9341_BCKL CONFIG_DISP_BCKL 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | /********************** 32 | * GLOBAL PROTOTYPES 33 | **********************/ 34 | 35 | void ili9341_init(void); 36 | void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map); 37 | 38 | /********************** 39 | * MACROS 40 | **********************/ 41 | 42 | 43 | #ifdef __cplusplus 44 | } /* extern "C" */ 45 | #endif 46 | 47 | #endif /*ILI9341_H*/ 48 | -------------------------------------------------------------------------------- /lv_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_conf.h 3 | * 4 | */ 5 | 6 | /* 7 | * COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER 8 | */ 9 | 10 | #if 1 /*Set it to "1" to enable content*/ 11 | 12 | #ifndef LV_CONF_H 13 | #define LV_CONF_H 14 | /* clang-format off */ 15 | 16 | #include 17 | #include "esp_attr.h" 18 | #include "sdkconfig.h" 19 | 20 | /*==================== 21 | Graphical settings 22 | *====================*/ 23 | 24 | /* Maximal horizontal and vertical resolution to support by the library.*/ 25 | #define LV_HOR_RES_MAX (CONFIG_DISP_HOR_RES) 26 | #define LV_VER_RES_MAX (CONFIG_DISP_VER_RES) 27 | 28 | /* Color depth: 29 | * - 1: 1 byte per pixel 30 | * - 8: RGB233 31 | * - 16: RGB565 32 | * - 32: ARGB8888 33 | */ 34 | #define LV_COLOR_DEPTH 16 35 | 36 | /* Swap the 2 bytes of RGB565 color. 37 | * Useful if the display has a 8 bit interface (e.g. SPI)*/ 38 | #define LV_COLOR_16_SWAP 1 39 | 40 | /* 1: Enable screen transparency. 41 | * Useful for OSD or other overlapping GUIs. 42 | * Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/ 43 | #define LV_COLOR_SCREEN_TRANSP 0 44 | 45 | /*Images pixels with this color will not be drawn (with chroma keying)*/ 46 | #define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/ 47 | 48 | /* Enable anti-aliasing (lines, and radiuses will be smoothed) */ 49 | #define LV_ANTIALIAS 1 50 | 51 | /* Default display refresh period. 52 | * Can be changed in the display driver (`lv_disp_drv_t`).*/ 53 | #define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/ 54 | 55 | /* Dot Per Inch: used to initialize default sizes. 56 | * E.g. a button with width = LV_DPI / 2 -> half inch wide 57 | * (Not so important, you can adjust it to modify default sizes and spaces)*/ 58 | #define LV_DPI 100 /*[px]*/ 59 | 60 | /* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ 61 | typedef int16_t lv_coord_t; 62 | 63 | /*========================= 64 | Memory manager settings 65 | *=========================*/ 66 | 67 | /* LittelvGL's internal memory manager's settings. 68 | * The graphical objects and other related data are stored here. */ 69 | 70 | /* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */ 71 | #define LV_MEM_CUSTOM 0 72 | #if LV_MEM_CUSTOM == 0 73 | /* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ 74 | # define LV_MEM_SIZE (32U * 1024U) 75 | 76 | /* Complier prefix for a big array declaration */ 77 | # define LV_MEM_ATTR 78 | 79 | /* Set an address for the memory pool instead of allocating it as an array. 80 | * Can be in external SRAM too. */ 81 | # define LV_MEM_ADR 0 82 | 83 | /* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */ 84 | # define LV_MEM_AUTO_DEFRAG 1 85 | #else /*LV_MEM_CUSTOM*/ 86 | # define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ 87 | # define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ 88 | # define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ 89 | #endif /*LV_MEM_CUSTOM*/ 90 | 91 | /* Garbage Collector settings 92 | * Used if lvgl is binded to higher level language and the memory is managed by that language */ 93 | #define LV_ENABLE_GC 0 94 | #if LV_ENABLE_GC != 0 95 | # define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ 96 | # define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ 97 | # define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ 98 | #endif /* LV_ENABLE_GC */ 99 | 100 | /*======================= 101 | Input device settings 102 | *=======================*/ 103 | 104 | /* Input device default settings. 105 | * Can be changed in the Input device driver (`lv_indev_drv_t`)*/ 106 | 107 | /* Input device read period in milliseconds */ 108 | #define LV_INDEV_DEF_READ_PERIOD 30 109 | 110 | /* Drag threshold in pixels */ 111 | #define LV_INDEV_DEF_DRAG_LIMIT 10 112 | 113 | /* Drag throw slow-down in [%]. Greater value -> faster slow-down */ 114 | #define LV_INDEV_DEF_DRAG_THROW 20 115 | 116 | /* Long press time in milliseconds. 117 | * Time to send `LV_EVENT_LONG_PRESSSED`) */ 118 | #define LV_INDEV_DEF_LONG_PRESS_TIME 400 119 | 120 | /* Repeated trigger period in long press [ms] 121 | * Time between `LV_EVENT_LONG_PRESSED_REPEAT */ 122 | #define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100 123 | 124 | /*================== 125 | * Feature usage 126 | *==================*/ 127 | 128 | /*1: Enable the Animations */ 129 | #define LV_USE_ANIMATION 1 130 | #if LV_USE_ANIMATION 131 | 132 | /*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/ 133 | typedef void * lv_anim_user_data_t; 134 | 135 | #endif 136 | 137 | /* 1: Enable shadow drawing*/ 138 | #define LV_USE_SHADOW 1 139 | 140 | /* 1: Enable object groups (for keyboard/encoder navigation) */ 141 | #define LV_USE_GROUP 1 142 | #if LV_USE_GROUP 143 | typedef void * lv_group_user_data_t; 144 | #endif /*LV_USE_GROUP*/ 145 | 146 | /* 1: Enable GPU interface*/ 147 | #define LV_USE_GPU 1 148 | 149 | /* 1: Enable file system (might be required for images */ 150 | #define LV_USE_FILESYSTEM 1 151 | #if LV_USE_FILESYSTEM 152 | /*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/ 153 | typedef void * lv_fs_drv_user_data_t; 154 | #endif 155 | 156 | /*1: Add a `user_data` to drivers and objects*/ 157 | #define LV_USE_USER_DATA 0 158 | 159 | /*======================== 160 | * Image decoder and cache 161 | *========================*/ 162 | 163 | /* 1: Enable indexed (palette) images */ 164 | #define LV_IMG_CF_INDEXED 1 165 | 166 | /* 1: Enable alpha indexed images */ 167 | #define LV_IMG_CF_ALPHA 1 168 | 169 | /* Default image cache size. Image caching keeps the images opened. 170 | * If only the built-in image formats are used there is no real advantage of caching. 171 | * (I.e. no new image decoder is added) 172 | * With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images. 173 | * However the opened images might consume additional RAM. 174 | * LV_IMG_CACHE_DEF_SIZE must be >= 1 */ 175 | #define LV_IMG_CACHE_DEF_SIZE 1 176 | 177 | /*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/ 178 | typedef void * lv_img_decoder_user_data_t; 179 | 180 | /*===================== 181 | * Compiler settings 182 | *====================*/ 183 | /* Define a custom attribute to `lv_tick_inc` function */ 184 | #define LV_ATTRIBUTE_TICK_INC IRAM_ATTR 185 | 186 | /* Define a custom attribute to `lv_task_handler` function */ 187 | #define LV_ATTRIBUTE_TASK_HANDLER 188 | 189 | /* With size optimization (-Os) the compiler might not align data to 190 | * 4 or 8 byte boundary. This alignment will be explicitly applied where needed. 191 | * E.g. __attribute__((aligned(4))) */ 192 | #define LV_ATTRIBUTE_MEM_ALIGN 193 | 194 | /* Attribute to mark large constant arrays for example 195 | * font's bitmaps */ 196 | #define LV_ATTRIBUTE_LARGE_CONST 197 | 198 | /*=================== 199 | * HAL settings 200 | *==================*/ 201 | 202 | /* 1: use a custom tick source. 203 | * It removes the need to manually update the tick with `lv_tick_inc`) */ 204 | #define LV_TICK_CUSTOM 0 205 | #if LV_TICK_CUSTOM == 1 206 | #define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/ 207 | #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ 208 | #endif /*LV_TICK_CUSTOM*/ 209 | 210 | typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ 211 | typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ 212 | 213 | /*================ 214 | * Log settings 215 | *===============*/ 216 | 217 | /*1: Enable the log module*/ 218 | #define LV_USE_LOG 1 219 | #if LV_USE_LOG 220 | /* How important log should be added: 221 | * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information 222 | * LV_LOG_LEVEL_INFO Log important events 223 | * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem 224 | * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail 225 | * LV_LOG_LEVEL_NONE Do not log anything 226 | */ 227 | # define LV_LOG_LEVEL LV_LOG_LEVEL_WARN 228 | 229 | /* 1: Print the log with 'printf'; 230 | * 0: user need to register a callback with `lv_log_register_print`*/ 231 | # define LV_LOG_PRINTF 1 232 | #endif /*LV_USE_LOG*/ 233 | 234 | /*================ 235 | * THEME USAGE 236 | *================*/ 237 | #define LV_THEME_LIVE_UPDATE 0 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/ 238 | 239 | #define LV_USE_THEME_TEMPL 0 /*Just for test*/ 240 | #define LV_USE_THEME_DEFAULT 0 /*Built mainly from the built-in styles. Consumes very few RAM*/ 241 | #define LV_USE_THEME_ALIEN 0 /*Dark futuristic theme*/ 242 | #define LV_USE_THEME_NIGHT 0 /*Dark elegant theme*/ 243 | #define LV_USE_THEME_MONO 0 /*Mono color theme for monochrome displays*/ 244 | #define LV_USE_THEME_MATERIAL 0 /*Flat theme with bold colors and light shadows*/ 245 | #define LV_USE_THEME_ZEN 0 /*Peaceful, mainly light theme */ 246 | #define LV_USE_THEME_NEMO 0 /*Water-like theme based on the movie "Finding Nemo"*/ 247 | 248 | /*================== 249 | * FONT USAGE 250 | *===================*/ 251 | 252 | /* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel. 253 | * The symbols are available via `LV_SYMBOL_...` defines 254 | * More info about fonts: https://docs.littlevgl.com/#Fonts 255 | * To create a new font go to: https://littlevgl.com/ttf-font-to-c-array 256 | */ 257 | 258 | /* Robot fonts with bpp = 4 259 | * https://fonts.google.com/specimen/Roboto */ 260 | #define LV_FONT_ROBOTO_12 0 261 | #define LV_FONT_ROBOTO_16 1 262 | #define LV_FONT_ROBOTO_22 0 263 | #define LV_FONT_ROBOTO_28 0 264 | 265 | /*Pixel perfect monospace font 266 | * http://pelulamu.net/unscii/ */ 267 | #define LV_FONT_UNSCII_8 0 268 | 269 | /* Optionally declare your custom fonts here. 270 | * You can use these fonts as default font too 271 | * and they will be available globally. E.g. 272 | * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ 273 | * LV_FONT_DECLARE(my_font_2) 274 | */ 275 | #define LV_FONT_CUSTOM_DECLARE 276 | 277 | /*Always set a default font from the built-in fonts*/ 278 | #define LV_FONT_DEFAULT &lv_font_roboto_16 279 | 280 | /* Enable it if you have fonts with a lot of characters. 281 | * The limit depends on the font size, font face and bpp 282 | * but with > 10,000 characters if you see issues probably you need to enable it.*/ 283 | #define LV_FONT_FMT_TXT_LARGE 0 284 | 285 | /*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/ 286 | typedef void * lv_font_user_data_t; 287 | 288 | /*================= 289 | * Text settings 290 | *=================*/ 291 | 292 | /* Select a character encoding for strings. 293 | * Your IDE or editor should have the same character encoding 294 | * - LV_TXT_ENC_UTF8 295 | * - LV_TXT_ENC_ASCII 296 | * */ 297 | #define LV_TXT_ENC LV_TXT_ENC_UTF8 298 | 299 | /*Can break (wrap) texts on these chars*/ 300 | #define LV_TXT_BREAK_CHARS " ,.;:-_" 301 | 302 | /*=================== 303 | * LV_OBJ SETTINGS 304 | *==================*/ 305 | 306 | /*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/ 307 | typedef void * lv_obj_user_data_t; 308 | 309 | /*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ 310 | #define LV_USE_OBJ_REALIGN 1 311 | 312 | /* Enable to make the object clickable on a larger area. 313 | * LV_EXT_CLICK_AREA_OFF or 0: Disable this feature 314 | * LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px) 315 | * LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px) 316 | */ 317 | #define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_OFF 318 | 319 | /*================== 320 | * LV OBJ X USAGE 321 | *================*/ 322 | /* 323 | * Documentation of the object types: https://docs.littlevgl.com/#Object-types 324 | */ 325 | 326 | /*Arc (dependencies: -)*/ 327 | #define LV_USE_ARC 1 328 | 329 | /*Bar (dependencies: -)*/ 330 | #define LV_USE_BAR 1 331 | 332 | /*Button (dependencies: lv_cont*/ 333 | #define LV_USE_BTN 1 334 | #if LV_USE_BTN != 0 335 | /*Enable button-state animations - draw a circle on click (dependencies: LV_USE_ANIMATION)*/ 336 | # define LV_BTN_INK_EFFECT 0 337 | #endif 338 | 339 | /*Button matrix (dependencies: -)*/ 340 | #define LV_USE_BTNM 1 341 | 342 | /*Calendar (dependencies: -)*/ 343 | #define LV_USE_CALENDAR 1 344 | 345 | /*Canvas (dependencies: lv_img)*/ 346 | #define LV_USE_CANVAS 1 347 | 348 | /*Check box (dependencies: lv_btn, lv_label)*/ 349 | #define LV_USE_CB 1 350 | 351 | /*Chart (dependencies: -)*/ 352 | #define LV_USE_CHART 1 353 | #if LV_USE_CHART 354 | # define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 20 355 | #endif 356 | 357 | /*Container (dependencies: -*/ 358 | #define LV_USE_CONT 1 359 | 360 | /*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ 361 | #define LV_USE_DDLIST 1 362 | #if LV_USE_DDLIST != 0 363 | /*Open and close default animation time [ms] (0: no animation)*/ 364 | # define LV_DDLIST_DEF_ANIM_TIME 200 365 | #endif 366 | 367 | /*Gauge (dependencies:lv_bar, lv_lmeter)*/ 368 | #define LV_USE_GAUGE 1 369 | 370 | /*Image (dependencies: lv_label*/ 371 | #define LV_USE_IMG 1 372 | 373 | /*Image Button (dependencies: lv_btn*/ 374 | #define LV_USE_IMGBTN 1 375 | #if LV_USE_IMGBTN 376 | /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ 377 | # define LV_IMGBTN_TILED 0 378 | #endif 379 | 380 | /*Keyboard (dependencies: lv_btnm)*/ 381 | #define LV_USE_KB 1 382 | 383 | /*Label (dependencies: -*/ 384 | #define LV_USE_LABEL 1 385 | #if LV_USE_LABEL != 0 386 | /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/ 387 | # define LV_LABEL_DEF_SCROLL_SPEED 25 388 | 389 | /* Waiting period at beginning/end of animation cycle */ 390 | # define LV_LABEL_WAIT_CHAR_COUNT 3 391 | 392 | /*Enable selecting text of the label */ 393 | # define LV_LABEL_TEXT_SEL 0 394 | 395 | /*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/ 396 | # define LV_LABEL_LONG_TXT_HINT 0 397 | #endif 398 | 399 | /*LED (dependencies: -)*/ 400 | #define LV_USE_LED 1 401 | 402 | /*Line (dependencies: -*/ 403 | #define LV_USE_LINE 1 404 | 405 | /*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ 406 | #define LV_USE_LIST 1 407 | #if LV_USE_LIST != 0 408 | /*Default animation time of focusing to a list element [ms] (0: no animation) */ 409 | # define LV_LIST_DEF_ANIM_TIME 100 410 | #endif 411 | 412 | /*Line meter (dependencies: *;)*/ 413 | #define LV_USE_LMETER 1 414 | 415 | /*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ 416 | #define LV_USE_MBOX 1 417 | 418 | /*Page (dependencies: lv_cont)*/ 419 | #define LV_USE_PAGE 1 420 | #if LV_USE_PAGE != 0 421 | /*Focus default animation time [ms] (0: no animation)*/ 422 | # define LV_PAGE_DEF_ANIM_TIME 400 423 | #endif 424 | 425 | /*Preload (dependencies: lv_arc, lv_anim)*/ 426 | #define LV_USE_PRELOAD 1 427 | #if LV_USE_PRELOAD != 0 428 | # define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ 429 | # define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/ 430 | # define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC 431 | #endif 432 | 433 | /*Roller (dependencies: lv_ddlist)*/ 434 | #define LV_USE_ROLLER 1 435 | #if LV_USE_ROLLER != 0 436 | /*Focus animation time [ms] (0: no animation)*/ 437 | # define LV_ROLLER_DEF_ANIM_TIME 200 438 | 439 | /*Number of extra "pages" when the roller is infinite*/ 440 | # define LV_ROLLER_INF_PAGES 7 441 | #endif 442 | 443 | /*Slider (dependencies: lv_bar)*/ 444 | #define LV_USE_SLIDER 1 445 | 446 | /*Spinbox (dependencies: lv_ta)*/ 447 | #define LV_USE_SPINBOX 1 448 | 449 | /*Switch (dependencies: lv_slider)*/ 450 | #define LV_USE_SW 1 451 | 452 | /*Text area (dependencies: lv_label, lv_page)*/ 453 | #define LV_USE_TA 1 454 | #if LV_USE_TA != 0 455 | # define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/ 456 | # define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/ 457 | #endif 458 | 459 | /*Table (dependencies: lv_label)*/ 460 | #define LV_USE_TABLE 1 461 | #if LV_USE_TABLE 462 | # define LV_TABLE_COL_MAX 12 463 | #endif 464 | 465 | /*Tab (dependencies: lv_page, lv_btnm)*/ 466 | #define LV_USE_TABVIEW 1 467 | # if LV_USE_TABVIEW != 0 468 | /*Time of slide animation [ms] (0: no animation)*/ 469 | # define LV_TABVIEW_DEF_ANIM_TIME 300 470 | #endif 471 | 472 | /*Tileview (dependencies: lv_page) */ 473 | #define LV_USE_TILEVIEW 1 474 | #if LV_USE_TILEVIEW 475 | /*Time of slide animation [ms] (0: no animation)*/ 476 | # define LV_TILEVIEW_DEF_ANIM_TIME 300 477 | #endif 478 | 479 | /*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ 480 | #define LV_USE_WIN 1 481 | 482 | /*================== 483 | * Non-user section 484 | *==================*/ 485 | 486 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ 487 | # define _CRT_SECURE_NO_WARNINGS 488 | #endif 489 | 490 | /*--END OF LV_CONF_H--*/ 491 | 492 | /*Be sure every define has a default value*/ 493 | #include "lvgl/src/lv_conf_checker.h" 494 | 495 | #endif /*LV_CONF_H*/ 496 | 497 | #endif /*End of "Content enable"*/ 498 | 499 | -------------------------------------------------------------------------------- /st7789.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ili9341.c 3 | * 4 | */ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include "st7789.h" 10 | #include "disp_spi.h" 11 | #include "driver/gpio.h" 12 | #include "freertos/FreeRTOS.h" 13 | #include "freertos/task.h" 14 | #include "sdkconfig.h" 15 | 16 | /********************* 17 | * DEFINES 18 | *********************/ 19 | 20 | /********************** 21 | * TYPEDEFS 22 | **********************/ 23 | 24 | /*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */ 25 | typedef struct { 26 | uint8_t cmd; 27 | uint8_t data[16]; 28 | uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds. 29 | } lcd_init_cmd_t; 30 | 31 | /********************** 32 | * STATIC PROTOTYPES 33 | **********************/ 34 | static void st7789_send_cmd(uint8_t cmd); 35 | static void st7789_send_data(void * data, uint16_t length); 36 | static void st7789_send_color(void * data, uint16_t length); 37 | 38 | /********************** 39 | * STATIC VARIABLES 40 | **********************/ 41 | 42 | /********************** 43 | * MACROS 44 | **********************/ 45 | 46 | /********************** 47 | * GLOBAL FUNCTIONS 48 | **********************/ 49 | 50 | void st7789_init(void) 51 | { 52 | lcd_init_cmd_t st7789_init_cmds[]={ 53 | {0xCF, {0x00, 0x83, 0X30}, 3}, 54 | {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, 55 | {0xE8, {0x85, 0x01, 0x79}, 3}, 56 | {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, 57 | {0xF7, {0x20}, 1}, 58 | {0xEA, {0x00, 0x00}, 2}, 59 | {0xC0, {0x26}, 1}, /*Power control*/ 60 | {0xC1, {0x11}, 1}, /*Power control */ 61 | {0xC5, {0x35, 0x3E}, 2}, /*VCOM control*/ 62 | {0xC7, {0xBE}, 1}, /*VCOM control*/ 63 | {0x36, {0x28}, 1}, /*Memory Access Control*/ 64 | {0x3A, {0x55}, 1}, /*Pixel Format Set*/ 65 | {0xB1, {0x00, 0x1B}, 2}, 66 | {0xF2, {0x08}, 1}, 67 | {0x26, {0x01}, 1}, 68 | {0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15}, 69 | {0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15}, 70 | {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, 71 | {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4}, 72 | {0x2C, {0}, 0}, 73 | {0xB7, {0x07}, 1}, 74 | {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, 75 | {0x11, {0}, 0x80}, 76 | {0x29, {0}, 0x80}, 77 | {0, {0}, 0xff}, 78 | }; 79 | 80 | //Initialize non-SPI GPIOs 81 | gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT); 82 | gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT); 83 | gpio_set_direction(ST7789_BCKL, GPIO_MODE_OUTPUT); 84 | 85 | //Reset the display 86 | gpio_set_level(ST7789_RST, 0); 87 | vTaskDelay(100 / portTICK_RATE_MS); 88 | gpio_set_level(ST7789_RST, 1); 89 | vTaskDelay(100 / portTICK_RATE_MS); 90 | 91 | 92 | printf("ST7789 initialization.\n"); 93 | 94 | 95 | //Send all the commands 96 | uint16_t cmd = 0; 97 | while (st7789_init_cmds[cmd].databytes!=0xff) { 98 | st7789_send_cmd(st7789_init_cmds[cmd].cmd); 99 | st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F); 100 | if (st7789_init_cmds[cmd].databytes & 0x80) { 101 | vTaskDelay(100 / portTICK_RATE_MS); 102 | } 103 | cmd++; 104 | } 105 | 106 | ///Enable backlight 107 | printf("Enable backlight.\n"); 108 | gpio_set_level(ST7789_BCKL, CONFIG_DISP_BCKL_ACTIVE_LVL); 109 | } 110 | 111 | 112 | void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map) 113 | { 114 | uint8_t data[4]; 115 | 116 | /*Column addresses*/ 117 | st7789_send_cmd(0x2A); 118 | data[0] = (area->x1 >> 8) & 0xFF; 119 | data[1] = area->x1 & 0xFF; 120 | data[2] = (area->x2 >> 8) & 0xFF; 121 | data[3] = area->x2 & 0xFF; 122 | st7789_send_data(data, 4); 123 | 124 | /*Page addresses*/ 125 | st7789_send_cmd(0x2B); 126 | data[0] = (area->y1 >> 8) & 0xFF; 127 | data[1] = area->y1 & 0xFF; 128 | data[2] = (area->y2 >> 8) & 0xFF; 129 | data[3] = area->y2 & 0xFF; 130 | st7789_send_data(data, 4); 131 | 132 | /*Memory write*/ 133 | st7789_send_cmd(0x2C); 134 | 135 | 136 | uint32_t size = lv_area_get_width(area) * lv_area_get_height(area); 137 | 138 | st7789_send_color((void*)color_map, size * 2); 139 | 140 | } 141 | 142 | /********************** 143 | * STATIC FUNCTIONS 144 | **********************/ 145 | 146 | 147 | static void st7789_send_cmd(uint8_t cmd) 148 | { 149 | gpio_set_level(ST7789_DC, 0); /*Command mode*/ 150 | disp_spi_send_data(&cmd, 1); 151 | } 152 | 153 | static void st7789_send_data(void * data, uint16_t length) 154 | { 155 | gpio_set_level(ST7789_DC, 1); /*Data mode*/ 156 | disp_spi_send_data(data, length); 157 | } 158 | 159 | static void st7789_send_color(void * data, uint16_t length) 160 | { 161 | gpio_set_level(ST7789_DC, 1); /*Data mode*/ 162 | disp_spi_send_colors(data, length); 163 | } 164 | -------------------------------------------------------------------------------- /st7789.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | #ifndef ST7789_H 7 | #define ST7789_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include "lvgl/lvgl.h" 18 | #include "sdkconfig.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | #define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40) 24 | #define ST7789_DC CONFIG_DISP_DC 25 | #define ST7789_RST CONFIG_DISP_RST 26 | #define ST7789_BCKL CONFIG_DISP_BCKL 27 | 28 | // ST7789 specific commands used in init 29 | #define ST7789_NOP 0x00 30 | #define ST7789_SWRESET 0x01 31 | #define ST7789_RDDID 0x04 32 | #define ST7789_RDDST 0x09 33 | 34 | #define ST7789_RDDPM 0x0A // Read display power mode 35 | #define ST7789_RDD_MADCTL 0x0B // Read display MADCTL 36 | #define ST7789_RDD_COLMOD 0x0C // Read display pixel format 37 | #define ST7789_RDDIM 0x0D // Read display image mode 38 | #define ST7789_RDDSM 0x0E // Read display signal mode 39 | #define ST7789_RDDSR 0x0F // Read display self-diagnostic result (ST7789V) 40 | 41 | #define ST7789_SLPIN 0x10 42 | #define ST7789_SLPOUT 0x11 43 | #define ST7789_PTLON 0x12 44 | #define ST7789_NORON 0x13 45 | 46 | #define ST7789_INVOFF 0x20 47 | #define ST7789_INVON 0x21 48 | #define ST7789_GAMSET 0x26 // Gamma set 49 | #define ST7789_DISPOFF 0x28 50 | #define ST7789_DISPON 0x29 51 | #define ST7789_CASET 0x2A 52 | #define ST7789_RASET 0x2B 53 | #define ST7789_RAMWR 0x2C 54 | #define ST7789_RGBSET 0x2D // Color setting for 4096, 64K and 262K colors 55 | #define ST7789_RAMRD 0x2E 56 | 57 | #define ST7789_PTLAR 0x30 58 | #define ST7789_VSCRDEF 0x33 // Vertical scrolling definition (ST7789V) 59 | #define ST7789_TEOFF 0x34 // Tearing effect line off 60 | #define ST7789_TEON 0x35 // Tearing effect line on 61 | #define ST7789_MADCTL 0x36 // Memory data access control 62 | #define ST7789_IDMOFF 0x38 // Idle mode off 63 | #define ST7789_IDMON 0x39 // Idle mode on 64 | #define ST7789_RAMWRC 0x3C // Memory write continue (ST7789V) 65 | #define ST7789_RAMRDC 0x3E // Memory read continue (ST7789V) 66 | #define ST7789_COLMOD 0x3A 67 | 68 | #define ST7789_RAMCTRL 0xB0 // RAM control 69 | #define ST7789_RGBCTRL 0xB1 // RGB control 70 | #define ST7789_PORCTRL 0xB2 // Porch control 71 | #define ST7789_FRCTRL1 0xB3 // Frame rate control 72 | #define ST7789_PARCTRL 0xB5 // Partial mode control 73 | #define ST7789_GCTRL 0xB7 // Gate control 74 | #define ST7789_GTADJ 0xB8 // Gate on timing adjustment 75 | #define ST7789_DGMEN 0xBA // Digital gamma enable 76 | #define ST7789_VCOMS 0xBB // VCOMS setting 77 | #define ST7789_LCMCTRL 0xC0 // LCM control 78 | #define ST7789_IDSET 0xC1 // ID setting 79 | #define ST7789_VDVVRHEN 0xC2 // VDV and VRH command enable 80 | #define ST7789_VRHS 0xC3 // VRH set 81 | #define ST7789_VDVSET 0xC4 // VDV setting 82 | #define ST7789_VCMOFSET 0xC5 // VCOMS offset set 83 | #define ST7789_FRCTR2 0xC6 // FR Control 2 84 | #define ST7789_CABCCTRL 0xC7 // CABC control 85 | #define ST7789_REGSEL1 0xC8 // Register value section 1 86 | #define ST7789_REGSEL2 0xCA // Register value section 2 87 | #define ST7789_PWMFRSEL 0xCC // PWM frequency selection 88 | #define ST7789_PWCTRL1 0xD0 // Power control 1 89 | #define ST7789_VAPVANEN 0xD2 // Enable VAP/VAN signal output 90 | #define ST7789_CMD2EN 0xDF // Command 2 enable 91 | #define ST7789_PVGAMCTRL 0xE0 // Positive voltage gamma control 92 | #define ST7789_NVGAMCTRL 0xE1 // Negative voltage gamma control 93 | #define ST7789_DGMLUTR 0xE2 // Digital gamma look-up table for red 94 | #define ST7789_DGMLUTB 0xE3 // Digital gamma look-up table for blue 95 | #define ST7789_GATECTRL 0xE4 // Gate control 96 | #define ST7789_SPI2EN 0xE7 // SPI2 enable 97 | #define ST7789_PWCTRL2 0xE8 // Power control 2 98 | #define ST7789_EQCTRL 0xE9 // Equalize time control 99 | #define ST7789_PROMCTRL 0xEC // Program control 100 | #define ST7789_PROMEN 0xFA // Program mode enable 101 | #define ST7789_NVMSET 0xFC // NVM setting 102 | #define ST7789_PROMACT 0xFE // Program action 103 | 104 | /********************** 105 | * TYPEDEFS 106 | **********************/ 107 | 108 | /********************** 109 | * GLOBAL PROTOTYPES 110 | **********************/ 111 | 112 | void st7789_init(void); 113 | void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map); 114 | 115 | /********************** 116 | * MACROS 117 | **********************/ 118 | 119 | #ifdef __cplusplus 120 | } /* extern "C" */ 121 | #endif 122 | 123 | #endif /* ST7789_H */ 124 | --------------------------------------------------------------------------------