Compare commits
1 commit
master
...
feat/add_c
Author | SHA1 | Date | |
---|---|---|---|
732e76418d |
|
@ -1,29 +0,0 @@
|
||||||
# EditorConfig helps developers define and maintain consistent
|
|
||||||
# coding styles between different editors and IDEs
|
|
||||||
# http://editorconfig.org
|
|
||||||
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
end_of_line = lf
|
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[{*.md,*.rst}]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
||||||
[{Makefile,*.mk,*.bat}]
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
[{*.cmake,CMakeLists.txt}]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
max_line_length = 120
|
|
||||||
|
|
||||||
[{*.sh,*.yml}]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
10
.gitignore
vendored
10
.gitignore
vendored
|
@ -50,13 +50,3 @@ modules.order
|
||||||
Module.symvers
|
Module.symvers
|
||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
# MacOS
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# ESP-IDF build dir
|
|
||||||
build
|
|
||||||
|
|
||||||
# Kconfig files
|
|
||||||
sdkconfig
|
|
||||||
sdkconfig.old
|
|
|
@ -1,97 +1,9 @@
|
||||||
if(ESP_PLATFORM)
|
if(ESP_PLATFORM)
|
||||||
|
|
||||||
file(GLOB SOURCES *.c)
|
file(GLOB SOURCES *.c)
|
||||||
set(LVGL_INCLUDE_DIRS . lvgl_tft)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/disp_driver.c")
|
|
||||||
list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c")
|
|
||||||
|
|
||||||
# Include only the source file of the selected
|
|
||||||
# display controller.
|
|
||||||
if(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/ili9341.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/ili9481.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9486)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/ili9486.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/ili9488.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/st7789.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/st7735s.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/st7796s.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/hx8357.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/sh1107.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/ssd1306.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/EVE_commands.c")
|
|
||||||
list(APPEND SOURCES "lvgl_tft/FT81x.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/il3820.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/jd79653a.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/uc8151d.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/ra8875.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_GC9A01)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/GC9A01.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/ili9163c.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/pcd8544.c")
|
|
||||||
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SCHMITT)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/schmitt.c")
|
|
||||||
else()
|
|
||||||
message(WARNING "LVGL ESP32 drivers: Display controller not defined.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI)
|
|
||||||
list(APPEND SOURCES "lvgl_tft/disp_spi.c")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Add touch driver to compilation only if it is selected in menuconfig
|
|
||||||
if(CONFIG_LV_TOUCH_CONTROLLER)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/touch_driver.c")
|
|
||||||
list(APPEND LVGL_INCLUDE_DIRS lvgl_touch)
|
|
||||||
|
|
||||||
# Include only the source file of the selected
|
|
||||||
# touch controller.
|
|
||||||
if(CONFIG_LV_TOUCH_CONTROLLER_XPT2046)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/xpt2046.c")
|
|
||||||
elseif(CONFIG_LV_TOUCH_CONTROLLER_FT6X06)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/ft6x36.c")
|
|
||||||
elseif(CONFIG_LV_TOUCH_CONTROLLER_STMPE610)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/stmpe610.c")
|
|
||||||
elseif(CONFIG_LV_TOUCH_CONTROLLER_ADCRAW)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/adcraw.c")
|
|
||||||
elseif(CONFIG_LV_TOUCH_CONTROLLER_FT81X)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/FT81x.c")
|
|
||||||
elseif(CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/ra8875_touch.c")
|
|
||||||
elseif(CONFIG_LV_TOUCH_CONTROLLER_GT911)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/gt911.c")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)
|
|
||||||
list(APPEND SOURCES "lvgl_touch/tp_spi.c")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CONFIG_LV_I2C)
|
|
||||||
list(APPEND SOURCES "lvgl_i2c/i2c_manager.c")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
idf_component_register(SRCS ${SOURCES}
|
idf_component_register(SRCS ${SOURCES}
|
||||||
INCLUDE_DIRS ${LVGL_INCLUDE_DIRS}
|
INCLUDE_DIRS .
|
||||||
REQUIRES lvgl driver esp_common log freertos esp_rom soc)
|
REQUIRES lvgl)
|
||||||
|
|
||||||
target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE")
|
|
||||||
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "LVGL ESP32 drivers: ESP_PLATFORM is not defined. Try reinstalling ESP-IDF.")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
14
Kconfig
14
Kconfig
|
@ -1,14 +0,0 @@
|
||||||
menu "LVGL ESP Drivers"
|
|
||||||
|
|
||||||
rsource "lvgl_tft/Kconfig"
|
|
||||||
|
|
||||||
rsource "lvgl_touch/Kconfig"
|
|
||||||
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "I2C Port Settings"
|
|
||||||
depends on LV_I2C && !HAVE_I2C_MANAGER
|
|
||||||
|
|
||||||
rsource "lvgl_i2c/Kconfig"
|
|
||||||
|
|
||||||
endmenu
|
|
33
README.md
33
README.md
|
@ -6,8 +6,6 @@ For a ready to use ESP32 project take look at the [lv_port_esp32](https://github
|
||||||
- [Supported display controllers](#supported-display-controllers)
|
- [Supported display controllers](#supported-display-controllers)
|
||||||
- [Supported indev controllers](#supported-indev-controllers)
|
- [Supported indev controllers](#supported-indev-controllers)
|
||||||
- [Support for predefined development kits](#support-for-predefined-development-kits)
|
- [Support for predefined development kits](#support-for-predefined-development-kits)
|
||||||
- [Thread-safe I2C with I2C Manager](#thread-safe-i2c-with-i2c-manager)
|
|
||||||
- [Backlight control](#backlight-control)
|
|
||||||
|
|
||||||
**NOTE:** You need to set the display horizontal and vertical size, color depth and
|
**NOTE:** You need to set the display horizontal and vertical size, color depth and
|
||||||
swap of RGB565 color on the LVGL configuration menuconfig (it's not handled automatically).
|
swap of RGB565 color on the LVGL configuration menuconfig (it's not handled automatically).
|
||||||
|
@ -19,7 +17,6 @@ swap of RGB565 color on the LVGL configuration menuconfig (it's not handled auto
|
||||||
| Display Controller | Type | Interface | Color depth (LV_COLOR_DEPTH) | Swap RGB565 color (LV_COLOR_16_SWAP) |
|
| Display Controller | Type | Interface | Color depth (LV_COLOR_DEPTH) | Swap RGB565 color (LV_COLOR_16_SWAP) |
|
||||||
|---------------------------------------------|------------|------------------------|------------------------------|----------------------------------------|
|
|---------------------------------------------|------------|------------------------|------------------------------|----------------------------------------|
|
||||||
| ILI9341 | TFT | SPI | 16: RGB565 | Yes |
|
| ILI9341 | TFT | SPI | 16: RGB565 | Yes |
|
||||||
| ILI9163C | TFT | SPI | 16: RGB565 | Yes |
|
|
||||||
| ILI9486 | TFT | SPI | 16: RGB565 | Yes |
|
| ILI9486 | TFT | SPI | 16: RGB565 | Yes |
|
||||||
| ILI9488 | TFT | SPI | 16: RGB565 | No |
|
| ILI9488 | TFT | SPI | 16: RGB565 | No |
|
||||||
| HX8357B/HX8357D | TFT | SPI | 16: RGB565 | Yes |
|
| HX8357B/HX8357D | TFT | SPI | 16: RGB565 | Yes |
|
||||||
|
@ -30,7 +27,6 @@ swap of RGB565 color on the LVGL configuration menuconfig (it's not handled auto
|
||||||
| RA8875 | TFT | SPI | 16: RGB565 | Yes |
|
| RA8875 | TFT | SPI | 16: RGB565 | Yes |
|
||||||
| SH1107 | Monochrome | SPI | 1: 1byte per pixel | No |
|
| SH1107 | Monochrome | SPI | 1: 1byte per pixel | No |
|
||||||
| SSD1306 | Monochrome | I2C | 1: 1byte per pixel | No |
|
| SSD1306 | Monochrome | I2C | 1: 1byte per pixel | No |
|
||||||
| PCD8544 | Monochrome | SPI | 1: 1byte per pixel | No |
|
|
||||||
| IL3820 | e-Paper | SPI | 1: 1byte per pixel | No |
|
| IL3820 | e-Paper | SPI | 1: 1byte per pixel | No |
|
||||||
| UC8151D/ GoodDisplay GDEW0154M10 DES | e-Paper | SPI | 1: 1byte per pixel | No |
|
| UC8151D/ GoodDisplay GDEW0154M10 DES | e-Paper | SPI | 1: 1byte per pixel | No |
|
||||||
| FitiPower JD79653A/ GoodDisplay GDEW0154M09 | e-Paper | SPI | 1: 1byte per pixel | No |
|
| FitiPower JD79653A/ GoodDisplay GDEW0154M09 | e-Paper | SPI | 1: 1byte per pixel | No |
|
||||||
|
@ -38,8 +34,8 @@ swap of RGB565 color on the LVGL configuration menuconfig (it's not handled auto
|
||||||
## Supported indev controllers
|
## Supported indev controllers
|
||||||
|
|
||||||
- XPT2046
|
- XPT2046
|
||||||
- FT3236, FT6X36
|
- FT3236
|
||||||
- FT6206 controllers should work as well (not tested)
|
- other FT6X36 or the FT6206 controllers should work as well (not tested)
|
||||||
- STMPE610
|
- STMPE610
|
||||||
- FT81x (Single, Dual, and Quad SPI)
|
- FT81x (Single, Dual, and Quad SPI)
|
||||||
|
|
||||||
|
@ -55,7 +51,6 @@ and sets the gpio numbers for the interface.
|
||||||
|---------------------------|-----------------------|-----------|-----------|-----------|
|
|---------------------------|-----------------------|-----------|-----------|-----------|
|
||||||
| ESP Wrover Kit v4.1 | ILI9341 | SPI | 240 | 320 |
|
| ESP Wrover Kit v4.1 | ILI9341 | SPI | 240 | 320 |
|
||||||
| M5Stack | ILI9341 | SPI | 240 | 320 |
|
| M5Stack | ILI9341 | SPI | 240 | 320 |
|
||||||
| M5Stack Core2 | ILI9341 | SPI | 240 | 320 |
|
|
||||||
| M5Stick | SH1107 | SPI | - | - |
|
| M5Stick | SH1107 | SPI | - | - |
|
||||||
| M5StickC | ST7735S | SPI | 80 | 160 |
|
| M5StickC | ST7735S | SPI | 80 | 160 |
|
||||||
| Adafruit 3.5 Featherwing | HX8357 | SPI | 480 | 320 |
|
| Adafruit 3.5 Featherwing | HX8357 | SPI | 480 | 320 |
|
||||||
|
@ -68,27 +63,3 @@ and sets the gpio numbers for the interface.
|
||||||
|
|
||||||
**NOTE:** See [Supported display controllers](#supported-display-controllers) for more information on display configuration.
|
**NOTE:** See [Supported display controllers](#supported-display-controllers) for more information on display configuration.
|
||||||
**NOTE:** See [Supported indev controllers](#supported-indev-controllers) for more information about indev configuration.
|
**NOTE:** See [Supported indev controllers](#supported-indev-controllers) for more information about indev configuration.
|
||||||
|
|
||||||
|
|
||||||
## Thread-safe I2C with I2C Manager
|
|
||||||
|
|
||||||
LVGL can use I2C to read from a touch sensor or write to a display, possibly
|
|
||||||
many times a second. Meanwhile, other tasks may also want to read from i2c
|
|
||||||
devices on the same bus. I2C using the ESP-IDF is not thread-safe.
|
|
||||||
|
|
||||||
I2C Manager (`i2c_manager`) is a component that will let code in multiple threads
|
|
||||||
talk to devices on the I2C ports without getting in each other's way. These drivers
|
|
||||||
use a built-in copy of I2C Manager to talk to the I2C port, but you can also use
|
|
||||||
the I2C Manager component itself and have others play nice with LVGL and vice-versa.
|
|
||||||
[Click here](i2c_manager/README.md) for details.
|
|
||||||
|
|
||||||
|
|
||||||
## Backlight control
|
|
||||||
|
|
||||||
Control of LCD's backlight is provided by separate module that is independent from the display driver.
|
|
||||||
Configuration of the backlight controller can be found in menuconfig `LVGL ESP Drivers -> LVGL TFT Display controller`.
|
|
||||||
|
|
||||||
There are three modes of operation:
|
|
||||||
1. Off - No backlight control
|
|
||||||
2. Switch - Allows ON/OFF control
|
|
||||||
3. PWM - Allows brightness control (by Pulse-Width-Modulated signal)
|
|
||||||
|
|
49
component.mk
49
component.mk
|
@ -1,49 +1,4 @@
|
||||||
# LVGL ESP32 drivers
|
# LVGL esp32 drivers
|
||||||
|
|
||||||
# Define sources and include dirs
|
COMPONENT_SRCDIRS := .
|
||||||
COMPONENT_SRCDIRS := . lvgl_tft lvgl_touch lvgl_i2c
|
|
||||||
COMPONENT_ADD_INCLUDEDIRS := .
|
COMPONENT_ADD_INCLUDEDIRS := .
|
||||||
|
|
||||||
# LVGL is supposed to be used as a ESP-IDF component
|
|
||||||
# -> lvlg is already in the include path
|
|
||||||
# -> we use simple include
|
|
||||||
CFLAGS += -DLV_LVGL_H_INCLUDE_SIMPLE
|
|
||||||
|
|
||||||
# TFT display drivers
|
|
||||||
COMPONENT_ADD_INCLUDEDIRS += lvgl_tft
|
|
||||||
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341),lvgl_tft/ili9341.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481),lvgl_tft/ili9481.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9486),lvgl_tft/ili9486.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488),lvgl_tft/ili9488.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789),lvgl_tft/st7789.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S),lvgl_tft/st7735s.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S),lvgl_tft/st7796s.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357),lvgl_tft/hx8357.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107),lvgl_tft/sh1107.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306),lvgl_tft/ssd1306.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X),lvgl_tft/EVE_commands.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X),lvgl_tft/FT81x.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820),lvgl_tft/il3820.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A),lvgl_tft/jd79653a.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D),lvgl_tft/uc8151d.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875),lvgl_tft/ra8875.o)
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_CONTROLLER_GC9A01),lvgl_tft/GC9A01.o)
|
|
||||||
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI),lvgl_tft/disp_spi.o)
|
|
||||||
|
|
||||||
# Touch controller drivers
|
|
||||||
COMPONENT_ADD_INCLUDEDIRS += lvgl_touch
|
|
||||||
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_TOUCH_CONTROLLER),lvgl_touch/touch_driver.o)
|
|
||||||
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CONTROLLER_XPT2046)), lvgl_touch/xpt2046.o)
|
|
||||||
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CONTROLLER_FT6X06)), lvgl_touch/ft6x36.o)
|
|
||||||
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CONTROLLER_STMPE610)), lvgl_touch/stmpe610.o)
|
|
||||||
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CONTROLLER_ADCRAW)), lvgl_touch/adcraw.o)
|
|
||||||
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CONTROLLER_FT81X)), lvgl_touch/FT81x.o)
|
|
||||||
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CONTROLLER_RA8875)), lvgl_touch/ra8875_touch.o)
|
|
||||||
|
|
||||||
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)), lvgl_touch/tp_spi.o)
|
|
||||||
|
|
||||||
# I2C Manager
|
|
||||||
$(call compile_only_if,$(CONFIG_LV_I2C), lvgl_i2c/i2c_manager.o)
|
|
||||||
|
|
31
lv_esp32_drivers_conf.h
Normal file
31
lv_esp32_drivers_conf.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef LV_ESP32_DRIVERS_CONF_H
|
||||||
|
#define LV_ESP32_DRIVERS_CONF_H
|
||||||
|
|
||||||
|
/* Enable display drivers */
|
||||||
|
#define LV_DISPLAY_EVE 0
|
||||||
|
#define LV_DISPLAY_FT81X 0
|
||||||
|
#define LV_DISPLAY_GC9A01 0
|
||||||
|
#define LV_DISPLAY_HX8357 0
|
||||||
|
#define LV_DISPLAY_IL3820 0
|
||||||
|
#define LV_DISPLAY_ILI9341 0
|
||||||
|
#define LV_DISPLAY_ILI9481 0
|
||||||
|
#define LV_DISPLAY_ILI9486 0
|
||||||
|
#define LV_DISPLAY_ILI9488 0
|
||||||
|
#define LV_DISPLAY_JD79653A 0
|
||||||
|
#define LV_DISPLAY_RA8875 0
|
||||||
|
#define LV_DISPLAY_SH1107 0
|
||||||
|
#define LV_DISPLAY_SSD1306 0
|
||||||
|
#define LV_DISPLAY_ST7735S 0
|
||||||
|
#define LV_DISPLAY_ST7789 0
|
||||||
|
#define LV_DISPLAY_ST7796S 0
|
||||||
|
#define LV_DISPLAY_UC8151D 0
|
||||||
|
|
||||||
|
/* Enable indev drivers */
|
||||||
|
#define LV_INDEV_FT81X 0
|
||||||
|
#define LV_INDEV_ADCRAW 0
|
||||||
|
#define LV_INDEV_FT6X36 0
|
||||||
|
#define LV_INDEV_RA8875 0
|
||||||
|
#define LV_INDEV_STMPE610 0
|
||||||
|
#define LV_INDEV_XPT2046 0
|
||||||
|
|
||||||
|
#endif /* LV_ESP32_DRIVERS_CONF_H */
|
103
lvgl_helpers.c
103
lvgl_helpers.c
|
@ -14,13 +14,14 @@
|
||||||
#include "lvgl_touch/tp_spi.h"
|
#include "lvgl_touch/tp_spi.h"
|
||||||
|
|
||||||
#include "lvgl_spi_conf.h"
|
#include "lvgl_spi_conf.h"
|
||||||
|
#include "lvgl_i2c_conf.h"
|
||||||
|
|
||||||
#include "lvgl_i2c/i2c_manager.h"
|
#include "driver/i2c.h"
|
||||||
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||||
#include "lvgl.h"
|
#include "src/lv_core/lv_refr.h"
|
||||||
#else
|
#else
|
||||||
#include "lvgl/lvgl.h"
|
#include "lvgl/src/lv_core/lv_refr.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
|
@ -52,12 +53,7 @@
|
||||||
/* Interface and driver initialization */
|
/* Interface and driver initialization */
|
||||||
void lvgl_driver_init(void)
|
void lvgl_driver_init(void)
|
||||||
{
|
{
|
||||||
/* Since LVGL v8 LV_HOR_RES_MAX and LV_VER_RES_MAX are not defined, so
|
|
||||||
* print it only if they are defined. */
|
|
||||||
#if (LVGL_VERSION_MAJOR < 8)
|
|
||||||
ESP_LOGI(TAG, "Display hor size: %d, ver size: %d", LV_HOR_RES_MAX, LV_VER_RES_MAX);
|
ESP_LOGI(TAG, "Display hor size: %d, ver size: %d", LV_HOR_RES_MAX, LV_VER_RES_MAX);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Display buffer size: %d", DISP_BUF_SIZE);
|
ESP_LOGI(TAG, "Display buffer size: %d", DISP_BUF_SIZE);
|
||||||
|
|
||||||
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
||||||
|
@ -95,6 +91,19 @@ void lvgl_driver_init(void)
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined (SHARED_I2C_BUS)
|
||||||
|
ESP_LOGI(TAG, "Initializing shared I2C master");
|
||||||
|
|
||||||
|
lvgl_i2c_driver_init(DISP_I2C_PORT,
|
||||||
|
DISP_I2C_SDA, DISP_I2C_SCL,
|
||||||
|
DISP_I2C_SPEED_HZ);
|
||||||
|
|
||||||
|
disp_driver_init();
|
||||||
|
touch_driver_init();
|
||||||
|
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Display controller initialization */
|
/* Display controller initialization */
|
||||||
#if defined CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI
|
#if defined CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
ESP_LOGI(TAG, "Initializing SPI master for display");
|
ESP_LOGI(TAG, "Initializing SPI master for display");
|
||||||
|
@ -107,7 +116,13 @@ void lvgl_driver_init(void)
|
||||||
disp_spi_add_device(TFT_SPI_HOST);
|
disp_spi_add_device(TFT_SPI_HOST);
|
||||||
|
|
||||||
disp_driver_init();
|
disp_driver_init();
|
||||||
#elif defined (CONFIG_LV_I2C_DISPLAY)
|
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
|
||||||
|
ESP_LOGI(TAG, "Initializing I2C master for display");
|
||||||
|
/* Init the i2c master on the display driver code */
|
||||||
|
lvgl_i2c_driver_init(DISP_I2C_PORT,
|
||||||
|
DISP_I2C_SDA, DISP_I2C_SCL,
|
||||||
|
DISP_I2C_SPEED_HZ);
|
||||||
|
|
||||||
disp_driver_init();
|
disp_driver_init();
|
||||||
#else
|
#else
|
||||||
#error "No protocol defined for display controller"
|
#error "No protocol defined for display controller"
|
||||||
|
@ -126,7 +141,13 @@ void lvgl_driver_init(void)
|
||||||
tp_spi_add_device(TOUCH_SPI_HOST);
|
tp_spi_add_device(TOUCH_SPI_HOST);
|
||||||
|
|
||||||
touch_driver_init();
|
touch_driver_init();
|
||||||
#elif defined (CONFIG_LV_I2C_TOUCH)
|
#elif defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)
|
||||||
|
ESP_LOGI(TAG, "Initializing I2C master for touch");
|
||||||
|
|
||||||
|
lvgl_i2c_driver_init(TOUCH_I2C_PORT,
|
||||||
|
TOUCH_I2C_SDA, TOUCH_I2C_SCL,
|
||||||
|
TOUCH_I2C_SPEED_HZ);
|
||||||
|
|
||||||
touch_driver_init();
|
touch_driver_init();
|
||||||
#elif defined (CONFIG_LV_TOUCH_DRIVER_ADC)
|
#elif defined (CONFIG_LV_TOUCH_DRIVER_ADC)
|
||||||
touch_driver_init();
|
touch_driver_init();
|
||||||
|
@ -139,27 +160,63 @@ void lvgl_driver_init(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Config the i2c master
|
||||||
/* Initialize spi bus master
|
|
||||||
*
|
*
|
||||||
* NOTE: dma_chan type and value changed to int instead of spi_dma_chan_t
|
* This should init the i2c master to be used on display and touch controllers.
|
||||||
* for backwards compatibility with ESP-IDF versions prior v4.3.
|
* So we should be able to know if the display and touch controllers shares the
|
||||||
*
|
* same i2c master.
|
||||||
* We could use the ESP_IDF_VERSION_VAL macro available in the "esp_idf_version.h"
|
|
||||||
* header available since ESP-IDF v4.
|
|
||||||
*/
|
*/
|
||||||
|
bool lvgl_i2c_driver_init(int port, int sda_pin, int scl_pin, int speed_hz)
|
||||||
|
{
|
||||||
|
esp_err_t err;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Initializing I2C master port %d...", port);
|
||||||
|
ESP_LOGI(TAG, "SDA pin: %d, SCL pin: %d, Speed: %d (Hz)",
|
||||||
|
sda_pin, scl_pin, speed_hz);
|
||||||
|
|
||||||
|
i2c_config_t conf = {
|
||||||
|
.mode = I2C_MODE_MASTER,
|
||||||
|
.sda_io_num = sda_pin,
|
||||||
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.scl_io_num = scl_pin,
|
||||||
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.master.clk_speed = speed_hz,
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Setting I2C master configuration...");
|
||||||
|
err = i2c_param_config(port, &conf);
|
||||||
|
assert(ESP_OK == err);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Installing I2C master driver...");
|
||||||
|
err = i2c_driver_install(port,
|
||||||
|
I2C_MODE_MASTER,
|
||||||
|
0, 0 /*I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE */,
|
||||||
|
0 /* intr_alloc_flags */);
|
||||||
|
assert(ESP_OK == err);
|
||||||
|
|
||||||
|
return ESP_OK != err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize spi bus master */
|
||||||
bool lvgl_spi_driver_init(int host,
|
bool lvgl_spi_driver_init(int host,
|
||||||
int miso_pin, int mosi_pin, int sclk_pin,
|
int miso_pin, int mosi_pin, int sclk_pin,
|
||||||
int max_transfer_sz,
|
int max_transfer_sz,
|
||||||
int dma_channel,
|
int dma_channel,
|
||||||
int quadwp_pin, int quadhd_pin)
|
int quadwp_pin, int quadhd_pin)
|
||||||
{
|
{
|
||||||
assert((0 <= host) && (3 > host));
|
#if defined (CONFIG_IDF_TARGET_ESP32)
|
||||||
|
assert((SPI_HOST <= host) && (VSPI_HOST >= host));
|
||||||
const char *spi_names[] = {
|
const char *spi_names[] = {
|
||||||
"SPI1_HOST", "SPI2_HOST", "SPI3_HOST"
|
"SPI_HOST", "HSPI_HOST", "VSPI_HOST"
|
||||||
};
|
};
|
||||||
|
#elif defined (CONFIG_IDF_TARGET_ESP32S2)
|
||||||
|
assert((SPI_HOST <= host) && (HSPI_HOST >= host));
|
||||||
|
const char *spi_names[] = {
|
||||||
|
"SPI_HOST", "", ""
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Configuring SPI host %s", spi_names[host]);
|
ESP_LOGI(TAG, "Configuring SPI host %s (%d)", spi_names[host], host);
|
||||||
ESP_LOGI(TAG, "MISO pin: %d, MOSI pin: %d, SCLK pin: %d, IO2/WP pin: %d, IO3/HD pin: %d",
|
ESP_LOGI(TAG, "MISO pin: %d, MOSI pin: %d, SCLK pin: %d, IO2/WP pin: %d, IO3/HD pin: %d",
|
||||||
miso_pin, mosi_pin, sclk_pin, quadwp_pin, quadhd_pin);
|
miso_pin, mosi_pin, sclk_pin, quadwp_pin, quadhd_pin);
|
||||||
|
|
||||||
|
@ -175,11 +232,9 @@ bool lvgl_spi_driver_init(int host,
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initializing SPI bus...");
|
ESP_LOGI(TAG, "Initializing SPI bus...");
|
||||||
#if defined (CONFIG_IDF_TARGET_ESP32C3)
|
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_channel);
|
||||||
dma_channel = SPI_DMA_CH_AUTO;
|
|
||||||
#endif
|
|
||||||
esp_err_t ret = spi_bus_initialize(host, &buscfg, (spi_dma_chan_t)dma_channel);
|
|
||||||
assert(ret == ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
|
|
||||||
return ESP_OK != ret;
|
return ESP_OK != ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,27 +16,11 @@ extern "C" {
|
||||||
|
|
||||||
#include "lvgl_spi_conf.h"
|
#include "lvgl_spi_conf.h"
|
||||||
#include "lvgl_tft/disp_driver.h"
|
#include "lvgl_tft/disp_driver.h"
|
||||||
#include "lvgl_tft/esp_lcd_backlight.h"
|
|
||||||
#include "lvgl_touch/touch_driver.h"
|
#include "lvgl_touch/touch_driver.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
|
||||||
/* DISP_BUF_SIZE value doesn't have an special meaning, but it's the size
|
|
||||||
* of the buffer(s) passed to LVGL as display buffers. The default values used
|
|
||||||
* were the values working for the contributor of the display controller.
|
|
||||||
*
|
|
||||||
* As LVGL supports partial display updates the DISP_BUF_SIZE doesn't
|
|
||||||
* necessarily need to be equal to the display size.
|
|
||||||
*
|
|
||||||
* When using RGB displays the display buffer size will also depends on the
|
|
||||||
* color format being used, for RGB565 each pixel needs 2 bytes.
|
|
||||||
* When using the mono theme, the display pixels can be represented in one bit,
|
|
||||||
* so the buffer size can be divided by 8, e.g. see SSD1306 display size. */
|
|
||||||
#if defined (CONFIG_CUSTOM_DISPLAY_BUFFER_SIZE)
|
|
||||||
#define DISP_BUF_SIZE CONFIG_CUSTOM_DISPLAY_BUFFER_BYTES
|
|
||||||
#else
|
|
||||||
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789)
|
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789)
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S
|
||||||
|
@ -54,13 +38,9 @@ extern "C" {
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 64)
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
||||||
#if defined (CONFIG_LV_THEME_MONO)
|
#define DISP_BUF_SIZE (LV_HOR_RES_MAX*LV_VER_RES_MAX)
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8))
|
|
||||||
#else
|
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
|
|
||||||
#endif
|
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
||||||
#define DISP_BUF_LINES 40
|
#define DISP_BUF_LINES 40
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * DISP_BUF_LINES)
|
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * DISP_BUF_LINES)
|
||||||
|
@ -74,16 +54,9 @@ extern "C" {
|
||||||
#define DISP_BUF_SIZE ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8) // 5KB
|
#define DISP_BUF_SIZE ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8) // 5KB
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D)
|
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D)
|
||||||
#define DISP_BUF_SIZE ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8) // 2888 bytes
|
#define DISP_BUF_SIZE ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8) // 2888 bytes
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C
|
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544)
|
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8))
|
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_SCHMITT)
|
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
|
|
||||||
#else
|
#else
|
||||||
#error "No display controller selected"
|
#error "No display controller selected"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
|
@ -93,14 +66,14 @@ extern "C" {
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
void lvgl_i2c_locking(void* leader);
|
|
||||||
|
|
||||||
/* Initialize detected SPI and I2C bus and devices */
|
/* Initialize detected SPI and I2C bus and devices */
|
||||||
void lvgl_driver_init(void);
|
void lvgl_driver_init(void);
|
||||||
|
|
||||||
/* Initialize SPI master */
|
/* Initialize SPI master */
|
||||||
bool lvgl_spi_driver_init(int host, int miso_pin, int mosi_pin, int sclk_pin,
|
bool lvgl_spi_driver_init(int host, int miso_pin, int mosi_pin, int sclk_pin,
|
||||||
int max_transfer_sz, int dma_channel, int quadwp_pin, int quadhd_pin);
|
int max_transfer_sz, int dma_channel, int quadwp_pin, int quadhd_pin);
|
||||||
|
/* Initialize I2C master */
|
||||||
|
bool lvgl_i2c_driver_init(int port, int sda_pin, int scl_pin, int speed);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
|
@ -1,98 +0,0 @@
|
||||||
menu "I2C Port 0"
|
|
||||||
|
|
||||||
config I2C_MANAGER_0_ENABLED
|
|
||||||
bool "Enable I2C port 0"
|
|
||||||
|
|
||||||
if I2C_MANAGER_0_ENABLED
|
|
||||||
config I2C_MANAGER_0_SDA
|
|
||||||
int "SDA (GPIO pin)"
|
|
||||||
default 0
|
|
||||||
config I2C_MANAGER_0_SCL
|
|
||||||
int "SCL (GPIO pin)"
|
|
||||||
default 0
|
|
||||||
config I2C_MANAGER_0_FREQ_HZ
|
|
||||||
int "Frequency (Hz)"
|
|
||||||
default 400000
|
|
||||||
range 100000 5000000
|
|
||||||
help
|
|
||||||
The clock speed in Hz. Ranges from 100000 (100 kHz) to
|
|
||||||
5000000 (5 Mhz). I2C busses that involve external wires may
|
|
||||||
have to be slower, and the real maximum speed the bus will
|
|
||||||
support depends on the value of the pullup resistors and the
|
|
||||||
design of the overall circuit.
|
|
||||||
config I2C_MANAGER_0_TIMEOUT
|
|
||||||
int "R/W timeout (ms)"
|
|
||||||
default 20
|
|
||||||
range 10 1000
|
|
||||||
help
|
|
||||||
Timeout for I2C read and write operations. This does not
|
|
||||||
include the time waiting for a lock.
|
|
||||||
config I2C_MANAGER_0_LOCK_TIMEOUT
|
|
||||||
int "Stale lock override (ms)"
|
|
||||||
default 50
|
|
||||||
range 10 1000
|
|
||||||
help
|
|
||||||
Timeout at which point an operation waiting for its turn on
|
|
||||||
the port will assume that whatever set the lock has died and
|
|
||||||
overrides it. Set this somewhat larger than the previous
|
|
||||||
timeout.
|
|
||||||
config I2C_MANAGER_0_PULLUPS
|
|
||||||
bool "Use ESP32 built-in bus pull-up resistors"
|
|
||||||
help
|
|
||||||
The I2C bus needs resistors to make sure it's in a defined
|
|
||||||
state when nobody is talking. Many circuits have external
|
|
||||||
pullup resistors already and turning these on will increase
|
|
||||||
power consumption slightly and may limit the speed your bus
|
|
||||||
can attain. Try with these off first if you don't know.
|
|
||||||
endif
|
|
||||||
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
|
|
||||||
menu "I2C Port 1"
|
|
||||||
|
|
||||||
config I2C_MANAGER_1_ENABLED
|
|
||||||
bool "Enable I2C port 1"
|
|
||||||
|
|
||||||
if I2C_MANAGER_1_ENABLED
|
|
||||||
config I2C_MANAGER_1_SDA
|
|
||||||
int "SDA (GPIO pin)"
|
|
||||||
config I2C_MANAGER_1_SCL
|
|
||||||
int "SCL (GPIO pin)"
|
|
||||||
config I2C_MANAGER_1_FREQ_HZ
|
|
||||||
int "Frequency (Hz)"
|
|
||||||
default 1000000
|
|
||||||
range 100000 5000000
|
|
||||||
help
|
|
||||||
The clock speed in Hz. Ranges from 100000 (100 kHz) to
|
|
||||||
5000000 (5 Mhz). I2C busses that involve external wires may
|
|
||||||
have to be slower, and the real maximum speed the bus will
|
|
||||||
support depends on the value of the pullup resistors and the
|
|
||||||
design of the overall circuit.
|
|
||||||
config I2C_MANAGER_1_TIMEOUT
|
|
||||||
int "R/W timeout (ms)"
|
|
||||||
default 20
|
|
||||||
range 10 1000
|
|
||||||
help
|
|
||||||
Timeout for I2C read and write operations. This does not
|
|
||||||
include the time waiting for a lock. Default should be fine.
|
|
||||||
config I2C_MANAGER_1_LOCK_TIMEOUT
|
|
||||||
int "Stale lock override (ms)"
|
|
||||||
default 50
|
|
||||||
help
|
|
||||||
Timeout at which point an operation waiting for its turn on
|
|
||||||
the port will assume that whatever set the lock has died and
|
|
||||||
overrides it. Set this somewhat larger than the previous
|
|
||||||
timeout. Default should be fine.
|
|
||||||
range 30 1000
|
|
||||||
config I2C_MANAGER_1_PULLUPS
|
|
||||||
bool "Use ESP32 built-in bus pull-up resistors"
|
|
||||||
help
|
|
||||||
The I2C bus needs resistors to make sure it's in a defined
|
|
||||||
state when nobody is talking. Many circuits have external
|
|
||||||
pullup resistors already and turning these on will increase
|
|
||||||
power consumption slightly and may limit the speed your bus
|
|
||||||
can attain. Try with these off first if you don't know.
|
|
||||||
endif
|
|
||||||
|
|
||||||
endmenu
|
|
|
@ -1,90 +0,0 @@
|
||||||
# I2C in `lvgl_esp32_drivers`
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Information for users
|
|
||||||
|
|
||||||
### I2C Manager support
|
|
||||||
|
|
||||||
`lvgl_esp32_drivers` integrates [I2C Manager](https://github.com/ropg/i2c_manager), which is used in case you select a touch sensor or screen that uses the I2C bus.
|
|
||||||
|
|
||||||
I2C Manager is also available as a separate ESP-IDF component and can help if you are in a situation where you want to avoid "bus conflicts" on the I2C bus. **If in your application nothing outside of LVGL needs to talk to the I2C bus, you can stop reading here.**
|
|
||||||
|
|
||||||
Suppose you use LVGL with a touch sensor that uses I2C, and your device also has another I2C device that needs to be read frequently, such as a 3D-accelerometer. ESP-IDF is not inherently "thread-safe". So if you read that from another task than the one LVGL uses to read the touch data, you need some kind of mechanism to keep these communications from interfering.
|
|
||||||
|
|
||||||
If you have (or write) a driver for that 3D-accelerometer that can use I2C Manager (or the I2C HAL and i2cdev abstraction layers that I2C Manager is compatible with) then put I2C Manager in your components directory by cloning the repository from below and in your main program do:
|
|
||||||
|
|
||||||
```c
|
|
||||||
#include "i2c_manager.h"
|
|
||||||
#include "lvgl_helpers.h"
|
|
||||||
|
|
||||||
[...]
|
|
||||||
|
|
||||||
lvgl_i2c_locking(i2c_manager_locking());
|
|
||||||
lv_init();
|
|
||||||
lvgl_driver_init();
|
|
||||||
```
|
|
||||||
|
|
||||||
The `lvgl_i2c_locking` part will cause the LVGL I2C driver to play nice with anything else that uses the I2C port(s) through I2C Manager.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Information for LVGL driver developers
|
|
||||||
|
|
||||||
I2C support in the LVGL ESP drivers is provided exclusively by the files in this directory. Driver code that uses I2C communicates through the functions provided in `i2c_manager.h`.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Using I2C in an LVGL driver, a multi-step guide
|
|
||||||
|
|
||||||
<dl>
|
|
||||||
|
|
||||||
<dt>Step 1</dt>
|
|
||||||
|
|
||||||
<dd>
|
|
||||||
The Kconfig entries for your driver only need to specify that you will be using I2C. This is done by adding `select LV_I2C_DISPLAY` or `select LV_I2C_TOUCH`.
|
|
||||||
</dd>
|
|
||||||
|
|
||||||
|
|
||||||
<dt>Step 2</dt>
|
|
||||||
|
|
||||||
<dd>
|
|
||||||
To use the I2C port in your code you would do something like:
|
|
||||||
|
|
||||||
|
|
||||||
```c
|
|
||||||
#include "lvgl_i2c/i2c_manager.h"
|
|
||||||
|
|
||||||
uint8_t data[2];
|
|
||||||
lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, 0x23, 0x42, &data, 2);
|
|
||||||
```
|
|
||||||
|
|
||||||
This causes a touch driver to read two bytes at register `0x42` from the IC at address `0x23`. Replace `CONFIG_LV_I2C_TOUCH_PORT` by `CONFIG_LV_I2C_DISPLAY_PORT` when this is a display instead of a touch driver. `lvgl_i2c_write` works much the same way, except it writes the bytes from the buffer instead of reading them. _(It's ignored above but these functions return `esp_err_t` so you can check if the I2C communication worked.)_
|
|
||||||
</dd>
|
|
||||||
|
|
||||||
<dt>Step 3</dt>
|
|
||||||
|
|
||||||
<dd>
|
|
||||||
There is no step 3, you are already done.
|
|
||||||
</dd>
|
|
||||||
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
|
|
||||||
### Meanwhile, behind the scenes ...
|
|
||||||
|
|
||||||
If any of the drivers selected by the user uses I2C, the menuconfig system will show an extra menu to select I2C port(s) for screen and/or touch sensor. An additional menu allows for setting of GPIO pins and bus speed of any port selected for use with LVGL. It's perfectly fine for a display and a touch sensor to be on the same I2C port or different ones.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## More information
|
|
||||||
|
|
||||||
If you need more documentation, please refer to the [I2C Manager GitHub repository](https://github.com/ropg/i2c_manager) for more detailed information on how I2C manager works. There are features not in the simple example above, such as reads and writes without specifying a register, 16-bit registers, 10-bit I2C addressing and more.
|
|
|
@ -1,368 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2021 Rop Gonggrijp. Based on esp_i2c_helper by Mika Tuupola.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include <esp_log.h>
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include <driver/i2c.h>
|
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
#include "i2c_manager.h"
|
|
||||||
|
|
||||||
|
|
||||||
#if defined __has_include
|
|
||||||
#if __has_include ("esp_idf_version.h")
|
|
||||||
#include "esp_idf_version.h"
|
|
||||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
|
|
||||||
#define HAS_CLK_FLAGS
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static const char* TAG = I2C_TAG;
|
|
||||||
|
|
||||||
static SemaphoreHandle_t I2C_FN(_local_mutex)[2] = { NULL, NULL };
|
|
||||||
static SemaphoreHandle_t* I2C_FN(_mutex) = &I2C_FN(_local_mutex)[0];
|
|
||||||
|
|
||||||
static const uint8_t ACK_CHECK_EN = 1;
|
|
||||||
|
|
||||||
#if defined (I2C_NUM_0) && defined (CONFIG_I2C_MANAGER_0_ENABLED)
|
|
||||||
#define I2C_ZERO I2C_NUM_0
|
|
||||||
#if defined (CONFIG_I2C_MANAGER_0_PULLUPS)
|
|
||||||
#define I2C_MANAGER_0_PULLUPS true
|
|
||||||
#else
|
|
||||||
#define I2C_MANAGER_0_PULLUPS false
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define I2C_MANAGER_0_TIMEOUT ( CONFIG_I2C_MANAGER_0_TIMEOUT / portTICK_RATE_MS )
|
|
||||||
#define I2C_MANAGER_0_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT / portTICK_RATE_MS )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined (I2C_NUM_1) && defined (CONFIG_I2C_MANAGER_1_ENABLED)
|
|
||||||
#define I2C_ONE I2C_NUM_1
|
|
||||||
#if defined (CONFIG_I2C_MANAGER_1_PULLUPS)
|
|
||||||
#define I2C_MANAGER_1_PULLUPS true
|
|
||||||
#else
|
|
||||||
#define I2C_MANAGER_1_PULLUPS false
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define I2C_MANAGER_1_TIMEOUT ( CONFIG_I2C_MANAGER_1_TIMEOUT / portTICK_RATE_MS )
|
|
||||||
#define I2C_MANAGER_1_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT / portTICK_RATE_MS )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ERROR_PORT(port, fail) { \
|
|
||||||
ESP_LOGE(TAG, "Invalid port or not configured for I2C Manager: %d", (int)port); \
|
|
||||||
return fail; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(I2C_ZERO) && defined (I2C_ONE)
|
|
||||||
#define I2C_PORT_CHECK(port, fail) \
|
|
||||||
if (port != I2C_NUM_0 && port != I2C_NUM_1) ERROR_PORT(port, fail);
|
|
||||||
#else
|
|
||||||
#if defined(I2C_ZERO)
|
|
||||||
#define I2C_PORT_CHECK(port, fail) \
|
|
||||||
if (port != I2C_NUM_0) ERROR_PORT(port, fail);
|
|
||||||
#elif defined(I2C_ONE)
|
|
||||||
#define I2C_PORT_CHECK(port, fail) \
|
|
||||||
if (port != I2C_NUM_1) ERROR_PORT(port, fail);
|
|
||||||
#else
|
|
||||||
#define I2C_PORT_CHECK(port, fail) \
|
|
||||||
ERROR_PORT(port, fail);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void i2c_send_address(i2c_cmd_handle_t cmd, uint16_t addr, i2c_rw_t rw) {
|
|
||||||
if (addr & I2C_ADDR_10) {
|
|
||||||
i2c_master_write_byte(cmd, 0xF0 | ((addr & 0x3FF) >> 7) | rw, ACK_CHECK_EN);
|
|
||||||
i2c_master_write_byte(cmd, addr & 0xFF, ACK_CHECK_EN);
|
|
||||||
} else {
|
|
||||||
i2c_master_write_byte(cmd, (addr << 1) | rw, ACK_CHECK_EN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void i2c_send_register(i2c_cmd_handle_t cmd, uint32_t reg) {
|
|
||||||
if (reg & I2C_REG_16) {
|
|
||||||
i2c_master_write_byte(cmd, (reg & 0xFF00) >> 8, ACK_CHECK_EN);
|
|
||||||
}
|
|
||||||
i2c_master_write_byte(cmd, reg & 0xFF, ACK_CHECK_EN);
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_init)(i2c_port_t port) {
|
|
||||||
|
|
||||||
I2C_PORT_CHECK(port, ESP_FAIL);
|
|
||||||
|
|
||||||
esp_err_t ret = ESP_OK;
|
|
||||||
|
|
||||||
if (I2C_FN(_mutex)[port] == 0) {
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Starting I2C master at port %d.", (int)port);
|
|
||||||
|
|
||||||
I2C_FN(_mutex)[port] = xSemaphoreCreateMutex();
|
|
||||||
|
|
||||||
i2c_config_t conf = {0};
|
|
||||||
|
|
||||||
#ifdef HAS_CLK_FLAGS
|
|
||||||
conf.clk_flags = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (I2C_ZERO)
|
|
||||||
if (port == I2C_NUM_0) {
|
|
||||||
conf.sda_io_num = CONFIG_I2C_MANAGER_0_SDA;
|
|
||||||
conf.scl_io_num = CONFIG_I2C_MANAGER_0_SCL;
|
|
||||||
conf.sda_pullup_en = I2C_MANAGER_0_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
|
|
||||||
conf.scl_pullup_en = conf.sda_pullup_en;
|
|
||||||
conf.master.clk_speed = CONFIG_I2C_MANAGER_0_FREQ_HZ;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (I2C_ONE)
|
|
||||||
if (port == I2C_NUM_1) {
|
|
||||||
conf.sda_io_num = CONFIG_I2C_MANAGER_1_SDA;
|
|
||||||
conf.scl_io_num = CONFIG_I2C_MANAGER_1_SCL;
|
|
||||||
conf.sda_pullup_en = I2C_MANAGER_1_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
|
|
||||||
conf.scl_pullup_en = conf.sda_pullup_en;
|
|
||||||
conf.master.clk_speed = CONFIG_I2C_MANAGER_1_FREQ_HZ;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
conf.mode = I2C_MODE_MASTER;
|
|
||||||
|
|
||||||
ret = i2c_param_config(port, &conf);
|
|
||||||
ret |= i2c_driver_install(port, conf.mode, 0, 0, 0);
|
|
||||||
|
|
||||||
if (ret != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to initialise I2C port %d.", (int)port);
|
|
||||||
ESP_LOGW(TAG, "If it was already open, we'll use it with whatever settings were used "
|
|
||||||
"to open it. See I2C Manager README for details.");
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %d Hz.)",
|
|
||||||
port, conf.sda_io_num, conf.scl_io_num, conf.master.clk_speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_read)(i2c_port_t port, uint16_t addr, uint32_t reg, uint8_t *buffer, uint16_t size) {
|
|
||||||
|
|
||||||
I2C_PORT_CHECK(port, ESP_FAIL);
|
|
||||||
|
|
||||||
esp_err_t result;
|
|
||||||
|
|
||||||
// May seem weird, but init starts with a check if it's needed, no need for that check twice.
|
|
||||||
I2C_FN(_init)(port);
|
|
||||||
|
|
||||||
ESP_LOGV(TAG, "Reading port %d, addr 0x%03x, reg 0x%04x", port, addr, reg);
|
|
||||||
|
|
||||||
TickType_t timeout = 0;
|
|
||||||
#if defined (I2C_ZERO)
|
|
||||||
if (port == I2C_NUM_0) {
|
|
||||||
timeout = I2C_MANAGER_0_TIMEOUT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if defined (I2C_ONE)
|
|
||||||
if (port == I2C_NUM_1) {
|
|
||||||
timeout = I2C_MANAGER_1_TIMEOUT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (I2C_FN(_lock)((int)port) == ESP_OK) {
|
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
|
||||||
if (!(reg & I2C_NO_REG)) {
|
|
||||||
/* When reading specific register set the addr pointer first. */
|
|
||||||
i2c_master_start(cmd);
|
|
||||||
i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
|
|
||||||
i2c_send_register(cmd, reg);
|
|
||||||
}
|
|
||||||
/* Read size bytes from the current pointer. */
|
|
||||||
i2c_master_start(cmd);
|
|
||||||
i2c_send_address(cmd, addr, I2C_MASTER_READ);
|
|
||||||
i2c_master_read(cmd, buffer, size, I2C_MASTER_LAST_NACK);
|
|
||||||
i2c_master_stop(cmd);
|
|
||||||
result = i2c_master_cmd_begin(port, cmd, timeout);
|
|
||||||
i2c_cmd_link_delete(cmd);
|
|
||||||
I2C_FN(_unlock)((int)port);
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "Error: %d", result);
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_write)(i2c_port_t port, uint16_t addr, uint32_t reg, const uint8_t *buffer, uint16_t size) {
|
|
||||||
|
|
||||||
I2C_PORT_CHECK(port, ESP_FAIL);
|
|
||||||
|
|
||||||
esp_err_t result;
|
|
||||||
|
|
||||||
// May seem weird, but init starts with a check if it's needed, no need for that check twice.
|
|
||||||
I2C_FN(_init)(port);
|
|
||||||
|
|
||||||
ESP_LOGV(TAG, "Writing port %d, addr 0x%03x, reg 0x%04x", port, addr, reg);
|
|
||||||
|
|
||||||
TickType_t timeout = 0;
|
|
||||||
#if defined (I2C_ZERO)
|
|
||||||
if (port == I2C_NUM_0) {
|
|
||||||
timeout = (CONFIG_I2C_MANAGER_0_TIMEOUT) / portTICK_RATE_MS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if defined (I2C_ONE)
|
|
||||||
if (port == I2C_NUM_1) {
|
|
||||||
timeout = (CONFIG_I2C_MANAGER_1_TIMEOUT) / portTICK_RATE_MS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (I2C_FN(_lock)((int)port) == ESP_OK) {
|
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
|
||||||
i2c_master_start(cmd);
|
|
||||||
i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
|
|
||||||
if (!(reg & I2C_NO_REG)) {
|
|
||||||
i2c_send_register(cmd, reg);
|
|
||||||
}
|
|
||||||
i2c_master_write(cmd, (uint8_t *)buffer, size, ACK_CHECK_EN);
|
|
||||||
i2c_master_stop(cmd);
|
|
||||||
result = i2c_master_cmd_begin( port, cmd, timeout);
|
|
||||||
i2c_cmd_link_delete(cmd);
|
|
||||||
I2C_FN(_unlock)((int)port);
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "Error: %d", result);
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_close)(i2c_port_t port) {
|
|
||||||
I2C_PORT_CHECK(port, ESP_FAIL);
|
|
||||||
vSemaphoreDelete(I2C_FN(_mutex)[port]);
|
|
||||||
I2C_FN(_mutex)[port] = NULL;
|
|
||||||
ESP_LOGI(TAG, "Closing I2C master at port %d", port);
|
|
||||||
return i2c_driver_delete(port);
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_lock)(i2c_port_t port) {
|
|
||||||
I2C_PORT_CHECK(port, ESP_FAIL);
|
|
||||||
ESP_LOGV(TAG, "Mutex lock set for %d.", (int)port);
|
|
||||||
|
|
||||||
TickType_t timeout;
|
|
||||||
#if defined (I2C_ZERO)
|
|
||||||
if (port == I2C_NUM_0) {
|
|
||||||
timeout = (CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT) / portTICK_RATE_MS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if defined (I2C_ONE)
|
|
||||||
if (port == I2C_NUM_1) {
|
|
||||||
timeout = (CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT) / portTICK_RATE_MS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE) {
|
|
||||||
return ESP_OK;
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Removing stale mutex lock from port %d.", (int)port);
|
|
||||||
I2C_FN(_force_unlock)(port);
|
|
||||||
return (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE ? ESP_OK : ESP_FAIL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_unlock)(i2c_port_t port) {
|
|
||||||
I2C_PORT_CHECK(port, ESP_FAIL);
|
|
||||||
ESP_LOGV(TAG, "Mutex lock removed for %d.", (int)port);
|
|
||||||
return (xSemaphoreGive(I2C_FN(_mutex)[port]) == pdTRUE) ? ESP_OK : ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_force_unlock)(i2c_port_t port) {
|
|
||||||
I2C_PORT_CHECK(port, ESP_FAIL);
|
|
||||||
if (I2C_FN(_mutex)[port]) {
|
|
||||||
vSemaphoreDelete(I2C_FN(_mutex)[port]);
|
|
||||||
}
|
|
||||||
I2C_FN(_mutex)[port] = xSemaphoreCreateMutex();
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef I2C_OEM
|
|
||||||
|
|
||||||
void I2C_FN(_locking)(void* leader) {
|
|
||||||
if (leader) {
|
|
||||||
ESP_LOGI(TAG, "Now following I2C Manager for locking");
|
|
||||||
I2C_FN(_mutex) = (SemaphoreHandle_t*)leader;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void* i2c_manager_locking() {
|
|
||||||
return (void*)i2c_manager_mutex;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t i2c_hal_read(void *handle, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size) {
|
|
||||||
return i2c_manager_read(*(i2c_port_t*)handle, address, reg, buffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t i2c_hal_write(void *handle, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size) {
|
|
||||||
return i2c_manager_write(*(i2c_port_t*)handle, address, reg, buffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static i2c_port_t port_zero = (i2c_port_t)0;
|
|
||||||
static i2c_port_t port_one = (i2c_port_t)1;
|
|
||||||
|
|
||||||
static i2c_hal_t _i2c_hal[2] = {
|
|
||||||
{&i2c_hal_read, &i2c_hal_write, &port_zero},
|
|
||||||
{&i2c_hal_read, &i2c_hal_write, &port_one}
|
|
||||||
};
|
|
||||||
|
|
||||||
void* i2c_hal(i2c_port_t port) {
|
|
||||||
I2C_PORT_CHECK(port, NULL);
|
|
||||||
return (void*)&_i2c_hal[port];
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,76 +0,0 @@
|
||||||
#ifndef _I2C_MANAGER_H
|
|
||||||
#define _I2C_MANAGER_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
If you copy the i2c_manager files to your own component instead of
|
|
||||||
depending on i2c_manager, you MUST uncomment the define below
|
|
||||||
and put in some short string that identifies your component (such
|
|
||||||
as 'xyz'). This will cause i2c_manager to create functions named
|
|
||||||
xyz_i2c_* instead of i2c_manager_*. See README.md for details.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define I2C_OEM lvgl
|
|
||||||
|
|
||||||
|
|
||||||
// Only here to get the I2C_NUM_0 and I2C_NUM_1 defines.
|
|
||||||
#include <driver/i2c.h>
|
|
||||||
|
|
||||||
#define CONCATX(A, B) A ## B
|
|
||||||
#define CONCAT(A, B) CONCATX(A, B)
|
|
||||||
#define STR_LITERAL(s) # s
|
|
||||||
#define STR_EXPAND(s) STR_LITERAL(s)
|
|
||||||
#define STR_QUOTE(s) STR_EXPAND(STR_EXPAND(s))
|
|
||||||
|
|
||||||
#ifdef I2C_OEM
|
|
||||||
#define I2C_NAME_PREFIX CONCAT(I2C_OEM, _i2c)
|
|
||||||
#else
|
|
||||||
#define I2C_NAME_PREFIX i2c_manager
|
|
||||||
#endif
|
|
||||||
#define I2C_TAG STR_EXPAND(I2C_NAME_PREFIX)
|
|
||||||
|
|
||||||
#define I2C_FN(s) CONCAT(I2C_NAME_PREFIX, s)
|
|
||||||
|
|
||||||
|
|
||||||
#define I2C_ADDR_10 ( 1 << 15 )
|
|
||||||
#define I2C_REG_16 ( 1 << 31 )
|
|
||||||
#define I2C_NO_REG ( 1 << 30 )
|
|
||||||
|
|
||||||
esp_err_t I2C_FN(_init)(i2c_port_t port);
|
|
||||||
esp_err_t I2C_FN(_read)(i2c_port_t port, uint16_t addr, uint32_t reg, uint8_t *buffer, uint16_t size);
|
|
||||||
esp_err_t I2C_FN(_write)(i2c_port_t port, uint16_t addr, uint32_t reg, const uint8_t *buffer, uint16_t size);
|
|
||||||
esp_err_t I2C_FN(_close)(i2c_port_t port);
|
|
||||||
esp_err_t I2C_FN(_lock)(i2c_port_t port);
|
|
||||||
esp_err_t I2C_FN(_unlock)(i2c_port_t port);
|
|
||||||
esp_err_t I2C_FN(_force_unlock)(i2c_port_t port);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef I2C_OEM
|
|
||||||
|
|
||||||
void I2C_FN(_locking)(void* leader);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void* i2c_manager_locking();
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t (* read)(void *handle, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size);
|
|
||||||
int32_t (* write)(void *handle, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size);
|
|
||||||
void *handle;
|
|
||||||
} i2c_hal_t;
|
|
||||||
|
|
||||||
void* i2c_hal(i2c_port_t port);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
116
lvgl_i2c_conf.h
Normal file
116
lvgl_i2c_conf.h
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
/**
|
||||||
|
* @file lvgl_i2c_config.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LVGL_I2C_CONF_H
|
||||||
|
#define LVGL_I2C_CONF_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* INCLUDES
|
||||||
|
*********************/
|
||||||
|
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||||
|
#include "lvgl.h"
|
||||||
|
#else
|
||||||
|
#include "lvgl/lvgl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* DEFINES
|
||||||
|
*********************/
|
||||||
|
|
||||||
|
/* TODO: Define the I2C bus clock based on the selected display or touch
|
||||||
|
* controllers. */
|
||||||
|
|
||||||
|
/* Do both display and touch controllers uses I2C? */
|
||||||
|
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C) && \
|
||||||
|
defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
|
||||||
|
|
||||||
|
#if defined (CONFIG_LV_DISPLAY_I2C_PORT_0) && \
|
||||||
|
defined (CONFIG_LV_TOUCH_I2C_PORT_0)
|
||||||
|
#define SHARED_I2C_PORT
|
||||||
|
#define DISP_I2C_PORT I2C_NUM_0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (CONFIG_LV_DISPLAY_I2C_PORT_1) && \
|
||||||
|
defined (CONFIG_LV_TOUCH_I2C_PORT_1)
|
||||||
|
#define SHARED_I2C_PORT
|
||||||
|
#define DISP_I2C_PORT I2C_NUM_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined (SHARED_I2C_PORT)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (SHARED_I2C_PORT)
|
||||||
|
/* If the port is shared the display and touch controllers must use the same
|
||||||
|
* SCL and SDA pins, otherwise let the user know with an error. */
|
||||||
|
#if (CONFIG_LV_DISP_PIN_SDA != CONFIG_LV_TOUCH_I2C_SDA) || \
|
||||||
|
(CONFIG_LV_DISP_PIN_SCL != CONFIG_LV_TOUCH_I2C_SCL)
|
||||||
|
#error "To share I2C port you need to choose the same SDA and SCL pins on both display and touch configurations"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DISP_I2C_SDA CONFIG_LV_DISP_PIN_SDA
|
||||||
|
#define DISP_I2C_SCL CONFIG_LV_DISP_PIN_SCL
|
||||||
|
#define DISP_I2C_ORIENTATION TFT_ORIENTATION_LANDSCAPE
|
||||||
|
|
||||||
|
/* Setting the I2C speed to the slowest one */
|
||||||
|
#if DISP_I2C_SPEED_HZ < TOUCH_I2C_SPEED_HZ
|
||||||
|
#define DISP_I2C_SPEED_HZ 400000 /* DISP_I2C_SPEED_HZ */
|
||||||
|
#else
|
||||||
|
#define DISP_I2C_SPEED_HZ 400000 /* DISP_I2C_SPEED_HZ */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* lets check if the touch controller uses I2C... */
|
||||||
|
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)
|
||||||
|
#if defined (CONFIG_LV_TOUCH_I2C_PORT_0)
|
||||||
|
#define TOUCH_I2C_PORT I2C_NUM_0
|
||||||
|
#else
|
||||||
|
#define TOUCH_I2C_PORT I2C_NUM_1
|
||||||
|
#endif
|
||||||
|
#define TOUCH_I2C_SDA CONFIG_LV_TOUCH_I2C_SDA
|
||||||
|
#define TOUCH_I2C_SCL CONFIG_LV_TOUCH_I2C_SCL
|
||||||
|
#define TOUCH_I2C_SPEED_HZ 400000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* lets check if the display controller uses I2C... */
|
||||||
|
#if defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
|
||||||
|
#if defined (CONFIG_LV_DISPLAY_I2C_PORT_0)
|
||||||
|
#define DISP_I2C_PORT I2C_NUM_0
|
||||||
|
#else
|
||||||
|
#define DISP_I2C_PORT I2C_NUM_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DISP_I2C_SDA CONFIG_LV_DISP_PIN_SDA
|
||||||
|
#define DISP_I2C_SCL CONFIG_LV_DISP_PIN_SCL
|
||||||
|
#define DISP_I2C_ORIENTATION TFT_ORIENTATION_LANDSCAPE
|
||||||
|
#define DISP_I2C_SPEED_HZ 400000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* TYPEDEFS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* GLOBAL PROTOTYPES
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* MACROS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*LVGL_I2C_CONF_H*/
|
|
@ -64,10 +64,12 @@ extern "C" {
|
||||||
|
|
||||||
#define ENABLE_TOUCH_INPUT CONFIG_LV_ENABLE_TOUCH
|
#define ENABLE_TOUCH_INPUT CONFIG_LV_ENABLE_TOUCH
|
||||||
|
|
||||||
#if defined (CONFIG_LV_TFT_DISPLAY_SPI2_HOST)
|
#if defined (CONFIG_LV_TFT_DISPLAY_SPI_HSPI)
|
||||||
#define TFT_SPI_HOST SPI2_HOST
|
#define TFT_SPI_HOST HSPI_HOST
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_SPI3_HOST)
|
#elif defined (CONFIG_LV_TFT_DISPLAY_SPI_VSPI)
|
||||||
#define TFT_SPI_HOST SPI3_HOST
|
#define TFT_SPI_HOST VSPI_HOST
|
||||||
|
#elif defined (CONFIG_LV_TFT_DISPLAY_SPI_FSPI)
|
||||||
|
#define TFT_SPI_HOST FSPI_HOST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (CONFIG_LV_TFT_DISPLAY_SPI_HALF_DUPLEX)
|
#if defined (CONFIG_LV_TFT_DISPLAY_SPI_HALF_DUPLEX)
|
||||||
|
@ -84,10 +86,12 @@ extern "C" {
|
||||||
#define DISP_SPI_TRANS_MODE_SIO
|
#define DISP_SPI_TRANS_MODE_SIO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (CONFIG_LV_TOUCH_CONTROLLER_SPI2_HOST)
|
#if defined (CONFIG_LV_TOUCH_CONTROLLER_SPI_HSPI)
|
||||||
#define TOUCH_SPI_HOST SPI2_HOST
|
#define TOUCH_SPI_HOST HSPI_HOST
|
||||||
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_SPI3_HOST)
|
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_SPI_VSPI)
|
||||||
#define TOUCH_SPI_HOST SPI3_HOST
|
#define TOUCH_SPI_HOST VSPI_HOST
|
||||||
|
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_SPI_FSPI)
|
||||||
|
#define TOUCH_SPI_HOST FSPI_HOST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Handle the FT81X Special case */
|
/* Handle the FT81X Special case */
|
||||||
|
@ -103,7 +107,7 @@ extern "C" {
|
||||||
// Detect the use of a shared SPI Bus and verify the user specified the same SPI bus for both touch and tft
|
// Detect the use of a shared SPI Bus and verify the user specified the same SPI bus for both touch and tft
|
||||||
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI) && TP_SPI_MOSI == DISP_SPI_MOSI && TP_SPI_CLK == DISP_SPI_CLK
|
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI) && TP_SPI_MOSI == DISP_SPI_MOSI && TP_SPI_CLK == DISP_SPI_CLK
|
||||||
#if TFT_SPI_HOST != TOUCH_SPI_HOST
|
#if TFT_SPI_HOST != TOUCH_SPI_HOST
|
||||||
#error You must specify the same SPI host (SPIx_HOST) for both display and touch driver
|
#error You must specify the same SPI host (HSPI, VSPI or FSPI) for both display and touch driver
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SHARED_SPI_BUS
|
#define SHARED_SPI_BUS
|
||||||
|
@ -114,11 +118,7 @@ extern "C" {
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_SCHMITT)
|
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481) || \
|
||||||
|
|
||||||
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 4)
|
|
||||||
|
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481) || \
|
|
||||||
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488)
|
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488)
|
||||||
|
|
||||||
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 3)
|
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 3)
|
||||||
|
@ -130,8 +130,7 @@ extern "C" {
|
||||||
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107) || \
|
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107) || \
|
||||||
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X) || \
|
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X) || \
|
||||||
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820) || \
|
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820) || \
|
||||||
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A) || \
|
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A)
|
||||||
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C)
|
|
||||||
|
|
||||||
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 2)
|
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 2)
|
||||||
|
|
||||||
|
@ -158,14 +157,10 @@ extern "C" {
|
||||||
#define SPI_TFT_CLOCK_SPEED_HZ (40*1000*1000)
|
#define SPI_TFT_CLOCK_SPEED_HZ (40*1000*1000)
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341)
|
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341)
|
||||||
#define SPI_TFT_CLOCK_SPEED_HZ (40*1000*1000)
|
#define SPI_TFT_CLOCK_SPEED_HZ (40*1000*1000)
|
||||||
#elif defined(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C)
|
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
||||||
#define SPI_TFT_CLOCK_SPEED_HZ (40 * 1000 * 1000)
|
|
||||||
#elif defined(CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
|
||||||
#define SPI_TFT_CLOCK_SPEED_HZ (32*1000*1000)
|
#define SPI_TFT_CLOCK_SPEED_HZ (32*1000*1000)
|
||||||
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544)
|
|
||||||
#define SPI_TFT_CLOCK_SPEED_HZ (4*1000*1000)
|
|
||||||
#else
|
#else
|
||||||
#define SPI_TFT_CLOCK_SPEED_HZ (5*1000*1000) // Set to 40 later
|
#define SPI_TFT_CLOCK_SPEED_HZ (40*1000*1000)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
55
lvgl_tft/CMakeLists.txt
Normal file
55
lvgl_tft/CMakeLists.txt
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
if(ESP_PLATFORM)
|
||||||
|
|
||||||
|
set(SOURCES "disp_driver.c")
|
||||||
|
|
||||||
|
# Include only the source file of the selected
|
||||||
|
# display controller.
|
||||||
|
if(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341)
|
||||||
|
list(APPEND SOURCES "ili9341.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481)
|
||||||
|
list(APPEND SOURCES "ili9481.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9486)
|
||||||
|
list(APPEND SOURCES "ili9486.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488)
|
||||||
|
list(APPEND SOURCES "ili9488.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789)
|
||||||
|
list(APPEND SOURCES "st7789.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S)
|
||||||
|
list(APPEND SOURCES "st7735s.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S)
|
||||||
|
list(APPEND SOURCES "st7796s.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357)
|
||||||
|
list(APPEND SOURCES "hx8357.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107)
|
||||||
|
list(APPEND SOURCES "sh1107.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306)
|
||||||
|
list(APPEND SOURCES "ssd1306.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
||||||
|
list(APPEND SOURCES "EVE_commands.c")
|
||||||
|
list(APPEND SOURCES "FT81x.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820)
|
||||||
|
list(APPEND SOURCES "il3820.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A)
|
||||||
|
list(APPEND SOURCES "jd79653a.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D)
|
||||||
|
list(APPEND SOURCES "uc8151d.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875)
|
||||||
|
list(APPEND SOURCES "ra8875.c")
|
||||||
|
elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_GC9A01)
|
||||||
|
list(APPEND SOURCES "GC9A01.c")
|
||||||
|
else()
|
||||||
|
message("DISPLAY CONTROLLER NOT DEFINED")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI)
|
||||||
|
list(APPEND SOURCES "disp_spi.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Print the included source files
|
||||||
|
message("SOURCES contents: " "${SOURCES}")
|
||||||
|
|
||||||
|
idf_component_register(SRCS ${SOURCES}
|
||||||
|
INCLUDE_DIRS .
|
||||||
|
REQUIRES lvgl)
|
||||||
|
|
||||||
|
endif()
|
|
@ -61,7 +61,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TAG_LOG "FT81X"
|
#define TAG "FT81X"
|
||||||
|
|
||||||
/* data structure for SPI reading that has (optional) space for inserted dummy byte */
|
/* data structure for SPI reading that has (optional) space for inserted dummy byte */
|
||||||
typedef struct _spi_read_data {
|
typedef struct _spi_read_data {
|
||||||
|
@ -144,7 +144,7 @@ void DELAY_MS(uint16_t ms)
|
||||||
vTaskDelay(ms / portTICK_PERIOD_MS);
|
vTaskDelay(ms / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EVE_USE_PDN
|
|
||||||
void EVE_pdn_set(void)
|
void EVE_pdn_set(void)
|
||||||
{
|
{
|
||||||
gpio_set_level(EVE_PDN, 0); /* Power-Down low */
|
gpio_set_level(EVE_PDN, 0); /* Power-Down low */
|
||||||
|
@ -155,7 +155,7 @@ void EVE_pdn_clear(void)
|
||||||
{
|
{
|
||||||
gpio_set_level(EVE_PDN, 1); /* Power-Down high */
|
gpio_set_level(EVE_PDN, 1); /* Power-Down high */
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void spi_acquire()
|
void spi_acquire()
|
||||||
{
|
{
|
||||||
|
@ -841,13 +841,11 @@ uint8_t EVE_init(void)
|
||||||
uint8_t chipid = 0;
|
uint8_t chipid = 0;
|
||||||
uint16_t timeout = 0;
|
uint16_t timeout = 0;
|
||||||
|
|
||||||
#if EVE_USE_PDN
|
|
||||||
EVE_pdn_set();
|
EVE_pdn_set();
|
||||||
DELAY_MS(6); /* minimum time for power-down is 5ms */
|
DELAY_MS(6); /* minimum time for power-down is 5ms */
|
||||||
|
|
||||||
EVE_pdn_clear();
|
EVE_pdn_clear();
|
||||||
DELAY_MS(21); /* minimum time to allow from rising PD_N to first access is 20ms */
|
DELAY_MS(21); /* minimum time to allow from rising PD_N to first access is 20ms */
|
||||||
#endif
|
|
||||||
|
|
||||||
/* EVE_cmdWrite(EVE_CORERST,0); */ /* reset, only required for warm-start if PowerDown line is not used */
|
/* EVE_cmdWrite(EVE_CORERST,0); */ /* reset, only required for warm-start if PowerDown line is not used */
|
||||||
|
|
||||||
|
@ -875,13 +873,13 @@ uint8_t EVE_init(void)
|
||||||
|
|
||||||
/* The most reliable DIO/QIO switching point is after EVE start up but before reading the ChipID. */
|
/* The most reliable DIO/QIO switching point is after EVE start up but before reading the ChipID. */
|
||||||
#if defined(DISP_SPI_TRANS_MODE_DIO)
|
#if defined(DISP_SPI_TRANS_MODE_DIO)
|
||||||
ESP_LOGI(TAG_LOG, "Switching to DIO mode");
|
ESP_LOGI(TAG, "Switching to DIO mode");
|
||||||
DELAY_MS(20); /* different boards may take a different delay but this generally seems to work */
|
DELAY_MS(20); /* different boards may take a different delay but this generally seems to work */
|
||||||
EVE_memWrite16(REG_SPI_WIDTH, SPI_WIDTH_DIO);
|
EVE_memWrite16(REG_SPI_WIDTH, SPI_WIDTH_DIO);
|
||||||
SPIInherentSendFlags = DISP_SPI_MODE_DIO | DISP_SPI_MODE_DIOQIO_ADDR;
|
SPIInherentSendFlags = DISP_SPI_MODE_DIO | DISP_SPI_MODE_DIOQIO_ADDR;
|
||||||
SPIDummyReadBits = 4; /* Esp32 DMA SPI transaction dummy_bits works more like clock cycles, so in DIO 4 dummy_bits == 8 total bits */
|
SPIDummyReadBits = 4; /* Esp32 DMA SPI transaction dummy_bits works more like clock cycles, so in DIO 4 dummy_bits == 8 total bits */
|
||||||
#elif defined(DISP_SPI_TRANS_MODE_QIO)
|
#elif defined(DISP_SPI_TRANS_MODE_QIO)
|
||||||
ESP_LOGI(TAG_LOG, "Switching to QIO mode");
|
ESP_LOGI(TAG, "Switching to QIO mode");
|
||||||
DELAY_MS(20); /* different boards may take a different delay but this generally seems to work */
|
DELAY_MS(20); /* different boards may take a different delay but this generally seems to work */
|
||||||
EVE_memWrite16(REG_SPI_WIDTH, SPI_WIDTH_QIO);
|
EVE_memWrite16(REG_SPI_WIDTH, SPI_WIDTH_QIO);
|
||||||
SPIInherentSendFlags = DISP_SPI_MODE_QIO | DISP_SPI_MODE_DIOQIO_ADDR;
|
SPIInherentSendFlags = DISP_SPI_MODE_QIO | DISP_SPI_MODE_DIOQIO_ADDR;
|
||||||
|
@ -897,7 +895,7 @@ uint8_t EVE_init(void)
|
||||||
timeout++;
|
timeout++;
|
||||||
if(timeout > 400)
|
if(timeout > 400)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG_LOG, "Failed to read ChipID...aborting initialization.");
|
ESP_LOGI(TAG, "Failed to read ChipID...aborting initialization.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -909,7 +907,7 @@ uint8_t EVE_init(void)
|
||||||
timeout++;
|
timeout++;
|
||||||
if(timeout > 50) /* experimental, 10 was the lowest value to get the BT815 started with, the touch-controller was the last to get out of reset */
|
if(timeout > 50) /* experimental, 10 was the lowest value to get the BT815 started with, the touch-controller was the last to get out of reset */
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG_LOG, "Failed to read CPU status...aborting initialization.");
|
ESP_LOGI(TAG, "Failed to read CPU status...aborting initialization.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,8 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
|
||||||
#define BLOCK_TRANSFER_SIZE 3840 // block transfer size when write data to CMD buffer
|
#define BLOCK_TRANSFER_SIZE 3840 // block transfer size when write data to CMD buffer
|
||||||
|
|
||||||
void DELAY_MS(uint16_t ms);
|
void DELAY_MS(uint16_t ms);
|
||||||
|
|
||||||
#if EVE_USE_PDN
|
|
||||||
void EVE_pdn_set(void);
|
void EVE_pdn_set(void);
|
||||||
void EVE_pdn_clear(void);
|
void EVE_pdn_clear(void);
|
||||||
#endif
|
|
||||||
|
|
||||||
void spi_acquire();
|
void spi_acquire();
|
||||||
void spi_release();
|
void spi_release();
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
|
||||||
#ifndef EVE_CONFIG_H_
|
#ifndef EVE_CONFIG_H_
|
||||||
#define EVE_CONFIG_H_
|
#define EVE_CONFIG_H_
|
||||||
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
#ifdef LV_CONFIG_INCLUDE_SIMPLE
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#else
|
#else
|
||||||
#include "lvgl/lvgl.h"
|
#include "lvgl/lvgl.h"
|
||||||
|
@ -49,7 +49,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
|
||||||
#define EVE_MOSI DISP_SPI_MOSI // green
|
#define EVE_MOSI DISP_SPI_MOSI // green
|
||||||
#define EVE_CS DISP_SPI_CS // blue
|
#define EVE_CS DISP_SPI_CS // blue
|
||||||
#define EVE_PDN CONFIG_LV_DISP_PIN_RST // grey
|
#define EVE_PDN CONFIG_LV_DISP_PIN_RST // grey
|
||||||
#define EVE_USE_PDN CONFIG_LV_DISP_USE_RST
|
|
||||||
|
|
||||||
#define SPI_TRANSER_SIZE (DISP_BUF_SIZE * (LV_COLOR_DEPTH / 8))
|
#define SPI_TRANSER_SIZE (DISP_BUF_SIZE * (LV_COLOR_DEPTH / 8))
|
||||||
|
|
||||||
|
|
|
@ -262,15 +262,9 @@ void TFT_bitmap_display(void)
|
||||||
|
|
||||||
void FT81x_init(void)
|
void FT81x_init(void)
|
||||||
{
|
{
|
||||||
#if EVE_USE_PDN
|
|
||||||
gpio_pad_select_gpio(EVE_PDN);
|
gpio_pad_select_gpio(EVE_PDN);
|
||||||
#endif
|
|
||||||
|
|
||||||
gpio_set_level(EVE_CS, 1);
|
gpio_set_level(EVE_CS, 1);
|
||||||
|
|
||||||
#if EVE_USE_PDN
|
|
||||||
gpio_set_direction(EVE_PDN, GPIO_MODE_OUTPUT);
|
gpio_set_direction(EVE_PDN, GPIO_MODE_OUTPUT);
|
||||||
#endif
|
|
||||||
|
|
||||||
spi_acquire();
|
spi_acquire();
|
||||||
|
|
||||||
|
|
|
@ -111,20 +111,31 @@ void GC9A01_init(void)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if GC9A01_BCKL == 15
|
||||||
|
gpio_config_t io_conf;
|
||||||
|
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||||
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||||
|
io_conf.pin_bit_mask = GPIO_SEL_15;
|
||||||
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(GC9A01_DC);
|
gpio_pad_select_gpio(GC9A01_DC);
|
||||||
gpio_set_direction(GC9A01_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(GC9A01_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if GC9A01_USE_RST
|
|
||||||
gpio_pad_select_gpio(GC9A01_RST);
|
gpio_pad_select_gpio(GC9A01_RST);
|
||||||
gpio_set_direction(GC9A01_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(GC9A01_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if GC9A01_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(GC9A01_BCKL);
|
||||||
|
gpio_set_direction(GC9A01_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
//Reset the display
|
//Reset the display
|
||||||
gpio_set_level(GC9A01_RST, 0);
|
gpio_set_level(GC9A01_RST, 0);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(GC9A01_RST, 1);
|
gpio_set_level(GC9A01_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initialization.");
|
ESP_LOGI(TAG, "Initialization.");
|
||||||
|
|
||||||
|
@ -139,6 +150,8 @@ void GC9A01_init(void)
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GC9A01_enable_backlight(true);
|
||||||
|
|
||||||
GC9A01_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
GC9A01_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
||||||
|
|
||||||
#if GC9A01_INVERT_COLORS == 1
|
#if GC9A01_INVERT_COLORS == 1
|
||||||
|
@ -178,6 +191,22 @@ void GC9A01_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
|
||||||
GC9A01_send_color((void*)color_map, size * 2);
|
GC9A01_send_color((void*)color_map, size * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GC9A01_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if GC9A01_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (GC9A01_BCKL_ACTIVE_LVL==1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(GC9A01_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void GC9A01_sleep_in()
|
void GC9A01_sleep_in()
|
||||||
{
|
{
|
||||||
uint8_t data[] = {0x08};
|
uint8_t data[] = {0x08};
|
||||||
|
|
|
@ -27,7 +27,16 @@ extern "C" {
|
||||||
*********************/
|
*********************/
|
||||||
#define GC9A01_DC CONFIG_LV_DISP_PIN_DC
|
#define GC9A01_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define GC9A01_RST CONFIG_LV_DISP_PIN_RST
|
#define GC9A01_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define GC9A01_USE_RST CONFIG_LV_DISP_USE_RST
|
#define GC9A01_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
|
||||||
|
#define GC9A01_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
#define GC9A01_BCKL_ACTIVE_LVL 1
|
||||||
|
#else
|
||||||
|
#define GC9A01_BCKL_ACTIVE_LVL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#define GC9A01_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
#define GC9A01_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
@ -40,6 +49,7 @@ extern "C" {
|
||||||
|
|
||||||
void GC9A01_init(void);
|
void GC9A01_init(void);
|
||||||
void GC9A01_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void GC9A01_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
void GC9A01_enable_backlight(bool backlight);
|
||||||
void GC9A01_sleep_in(void);
|
void GC9A01_sleep_in(void);
|
||||||
void GC9A01_sleep_out(void);
|
void GC9A01_sleep_out(void);
|
||||||
|
|
||||||
|
|
291
lvgl_tft/Kconfig
291
lvgl_tft/Kconfig
|
@ -21,10 +21,6 @@ menu "LVGL TFT Display controller"
|
||||||
bool "M5Stack"
|
bool "M5Stack"
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
select LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
||||||
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
config LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
bool "M5Core2"
|
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
|
||||||
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
|
||||||
config LV_PREDEFINED_DISPLAY_M5STICK
|
config LV_PREDEFINED_DISPLAY_M5STICK
|
||||||
bool "M5Stick"
|
bool "M5Stick"
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_SH1107
|
select LV_TFT_DISPLAY_CONTROLLER_SH1107
|
||||||
|
@ -50,7 +46,7 @@ menu "LVGL TFT Display controller"
|
||||||
config LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
|
config LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
|
||||||
bool "Wemos Lolin OLED"
|
bool "Wemos Lolin OLED"
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
select LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
||||||
select LV_I2C_DISPLAY
|
select LV_TFT_DISPLAY_PROTOCOL_I2C
|
||||||
select LV_TFT_DISPLAY_MONOCHROME
|
select LV_TFT_DISPLAY_MONOCHROME
|
||||||
select LV_THEME_MONO
|
select LV_THEME_MONO
|
||||||
config LV_PREDEFINED_DISPLAY_ATAG
|
config LV_PREDEFINED_DISPLAY_ATAG
|
||||||
|
@ -169,19 +165,6 @@ menu "LVGL TFT Display controller"
|
||||||
help
|
help
|
||||||
ST7796S display controller.
|
ST7796S display controller.
|
||||||
|
|
||||||
config LV_TFT_DISPLAY_CONTROLLER_ILI9163C
|
|
||||||
bool
|
|
||||||
help
|
|
||||||
ILI9163C display controller.
|
|
||||||
|
|
||||||
config LV_TFT_DISPLAY_CONTROLLER_PCD8544
|
|
||||||
bool
|
|
||||||
help
|
|
||||||
PCD8544 display controller (Nokia 3110/5110)
|
|
||||||
config LV_TFT_DISPLAY_CONTROLLER_SCHMITT
|
|
||||||
bool
|
|
||||||
help
|
|
||||||
Schmitt's display controller
|
|
||||||
# Display controller communication protocol
|
# Display controller communication protocol
|
||||||
#
|
#
|
||||||
# This symbols define the communication protocol used by the
|
# This symbols define the communication protocol used by the
|
||||||
|
@ -195,7 +178,7 @@ menu "LVGL TFT Display controller"
|
||||||
help
|
help
|
||||||
Display controller protocol SPI
|
Display controller protocol SPI
|
||||||
|
|
||||||
config LV_I2C_DISPLAY
|
config LV_TFT_DISPLAY_PROTOCOL_I2C
|
||||||
bool
|
bool
|
||||||
help
|
help
|
||||||
Display controller protocol I2C
|
Display controller protocol I2C
|
||||||
|
@ -203,24 +186,23 @@ menu "LVGL TFT Display controller"
|
||||||
# Used in display init function to send display orientation commands
|
# Used in display init function to send display orientation commands
|
||||||
choice DISPLAY_ORIENTATION
|
choice DISPLAY_ORIENTATION
|
||||||
prompt "Display orientation"
|
prompt "Display orientation"
|
||||||
default LV_DISPLAY_ORIENTATION_PORTRAIT if !LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
default DISPLAY_ORIENTATION_PORTRAIT
|
||||||
default LV_DISPLAY_ORIENTATION_LANDSCAPE if LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
config DISPLAY_ORIENTATION_PORTRAIT
|
||||||
config LV_DISPLAY_ORIENTATION_PORTRAIT
|
bool "Portrait"
|
||||||
bool "Portrait" if !LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
config DISPLAY_ORIENTATION_PORTRAIT_INVERTED
|
||||||
config LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED
|
bool "Portrait inverted"
|
||||||
bool "Portrait inverted" if !LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
config DISPLAY_ORIENTATION_LANDSCAPE
|
||||||
config LV_DISPLAY_ORIENTATION_LANDSCAPE
|
|
||||||
bool "Landscape"
|
bool "Landscape"
|
||||||
config LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED
|
config DISPLAY_ORIENTATION_LANDSCAPE_INVERTED
|
||||||
bool "Landscape inverted"
|
bool "Landscape inverted"
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config LV_DISPLAY_ORIENTATION
|
config LV_DISPLAY_ORIENTATION
|
||||||
int
|
int
|
||||||
default 0 if LV_DISPLAY_ORIENTATION_PORTRAIT
|
default 0 if DISPLAY_ORIENTATION_PORTRAIT
|
||||||
default 1 if LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED
|
default 1 if DISPLAY_ORIENTATION_PORTRAIT_INVERTED
|
||||||
default 2 if LV_DISPLAY_ORIENTATION_LANDSCAPE
|
default 2 if DISPLAY_ORIENTATION_LANDSCAPE
|
||||||
default 3 if LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED
|
default 3 if DISPLAY_ORIENTATION_LANDSCAPE_INVERTED
|
||||||
|
|
||||||
config LV_TFT_DISPLAY_OFFSETS
|
config LV_TFT_DISPLAY_OFFSETS
|
||||||
bool
|
bool
|
||||||
|
@ -229,14 +211,14 @@ menu "LVGL TFT Display controller"
|
||||||
|
|
||||||
config LV_TFT_DISPLAY_X_OFFSET
|
config LV_TFT_DISPLAY_X_OFFSET
|
||||||
depends on LV_TFT_DISPLAY_OFFSETS
|
depends on LV_TFT_DISPLAY_OFFSETS
|
||||||
int "X offset"
|
int
|
||||||
default 40 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_LANDSCAPE || LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
default 40 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_LANDSCAPE || LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
||||||
default 53 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_PORTRAIT || LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
|
default 53 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_PORTRAIT || LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
|
||||||
default 0
|
default 0
|
||||||
|
|
||||||
config LV_TFT_DISPLAY_Y_OFFSET
|
config LV_TFT_DISPLAY_Y_OFFSET
|
||||||
depends on LV_TFT_DISPLAY_OFFSETS
|
depends on LV_TFT_DISPLAY_OFFSETS
|
||||||
int "Y offset"
|
int
|
||||||
default 53 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_LANDSCAPE || LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
default 53 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_LANDSCAPE || LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
||||||
default 40 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_PORTRAIT || LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
|
default 40 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_PORTRAIT || LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
|
||||||
default 0
|
default 0
|
||||||
|
@ -319,7 +301,7 @@ menu "LVGL TFT Display controller"
|
||||||
config LV_TFT_DISPLAY_USER_CONTROLLER_SSD1306
|
config LV_TFT_DISPLAY_USER_CONTROLLER_SSD1306
|
||||||
bool "SSD1306"
|
bool "SSD1306"
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
select LV_TFT_DISPLAY_CONTROLLER_SSD1306
|
||||||
select LV_I2C_DISPLAY
|
select LV_TFT_DISPLAY_PROTOCOL_I2C
|
||||||
select LV_TFT_DISPLAY_MONOCHROME
|
select LV_TFT_DISPLAY_MONOCHROME
|
||||||
config LV_TFT_DISPLAY_USER_CONTROLLER_FT81X
|
config LV_TFT_DISPLAY_USER_CONTROLLER_FT81X
|
||||||
bool "FT81X"
|
bool "FT81X"
|
||||||
|
@ -344,33 +326,8 @@ menu "LVGL TFT Display controller"
|
||||||
bool "RA8875"
|
bool "RA8875"
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_RA8875
|
select LV_TFT_DISPLAY_CONTROLLER_RA8875
|
||||||
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
config LV_TFT_DISPLAY_USER_CONTROLLER_ILI9163C
|
|
||||||
bool "ILI9163C"
|
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_ILI9163C
|
|
||||||
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
|
||||||
config LV_TFT_DISPLAY_USER_CONTROLLER_PCD8544
|
|
||||||
bool "PCD8544"
|
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_PCD8544
|
|
||||||
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
|
||||||
select LV_TFT_DISPLAY_MONOCHROME
|
|
||||||
config LV_TFT_DISPLAY_USER_CONTROLLER_SCHMITT
|
|
||||||
bool "SCHMITT"
|
|
||||||
select LV_TFT_DISPLAY_CONTROLLER_SCHMITT
|
|
||||||
select LV_TFT_DISPLAY_PROTOCOL_SPI
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config CUSTOM_DISPLAY_BUFFER_SIZE
|
|
||||||
bool "Use custom display buffer size (bytes)"
|
|
||||||
help
|
|
||||||
Enable to use a custom display buffer size.
|
|
||||||
|
|
||||||
config CUSTOM_DISPLAY_BUFFER_BYTES
|
|
||||||
int "Custom buffer size (bytes)"
|
|
||||||
depends on CUSTOM_DISPLAY_BUFFER_SIZE
|
|
||||||
default 1024
|
|
||||||
help
|
|
||||||
See Display buffer on LVGL docs for more information.
|
|
||||||
|
|
||||||
# Select one of the available FT81x configurations.
|
# Select one of the available FT81x configurations.
|
||||||
choice
|
choice
|
||||||
prompt "Select a FT81x configuration." if LV_TFT_DISPLAY_USER_CONTROLLER_FT81X
|
prompt "Select a FT81x configuration." if LV_TFT_DISPLAY_USER_CONTROLLER_FT81X
|
||||||
|
@ -476,15 +433,20 @@ menu "LVGL TFT Display controller"
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "TFT SPI Bus." if LV_TFT_DISPLAY_PROTOCOL_SPI
|
prompt "TFT SPI Bus." if LV_TFT_DISPLAY_PROTOCOL_SPI && \
|
||||||
default LV_TFT_DISPLAY_SPI2_HOST
|
!LV_PREDEFINED_DISPLAY_TTGO
|
||||||
|
default LV_TFT_DISPLAY_SPI_VSPI if LV_PREDEFINED_DISPLAY_TTGO && \
|
||||||
|
!IDF_TARGET_ESP32S2
|
||||||
|
default LV_TFT_DISPLAY_SPI_FSPI if IDF_TARGET_ESP32S2
|
||||||
help
|
help
|
||||||
Select the SPI Bus the TFT Display is attached to.
|
Select the SPI Bus the TFT Display is attached to.
|
||||||
|
|
||||||
config LV_TFT_DISPLAY_SPI2_HOST
|
config LV_TFT_DISPLAY_SPI_HSPI
|
||||||
bool "SPI2_HOST"
|
bool "HSPI"
|
||||||
config LV_TFT_DISPLAY_SPI3_HOST
|
config LV_TFT_DISPLAY_SPI_VSPI
|
||||||
bool "SPI3_HOST"
|
bool "VSPI" if !IDF_TARGET_ESP32S2
|
||||||
|
config LV_TFT_DISPLAY_SPI_FSPI
|
||||||
|
bool "FSPI" if IDF_TARGET_ESP32S2
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
choice
|
choice
|
||||||
|
@ -515,6 +477,18 @@ menu "LVGL TFT Display controller"
|
||||||
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_SIO
|
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_SIO
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "Display I2C port" if LV_TFT_DISPLAY_PROTOCOL_I2C
|
||||||
|
default LV_DISPLAY_I2C_PORT_0
|
||||||
|
help
|
||||||
|
Select the I2C port used by the display controller.
|
||||||
|
|
||||||
|
config LV_DISPLAY_I2C_PORT_0
|
||||||
|
bool "I2C PORT 0"
|
||||||
|
config LV_DISPLAY_I2C_PORT_1
|
||||||
|
bool "I2C PORT 1"
|
||||||
|
endchoice
|
||||||
|
|
||||||
config LV_TFT_USE_CUSTOM_SPI_CLK_DIVIDER
|
config LV_TFT_USE_CUSTOM_SPI_CLK_DIVIDER
|
||||||
bool "Use custom SPI clock frequency." if LV_TFT_DISPLAY_PROTOCOL_SPI
|
bool "Use custom SPI clock frequency." if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
default n
|
default n
|
||||||
|
@ -592,29 +566,41 @@ menu "LVGL TFT Display controller"
|
||||||
default 80 if LV_TFT_SPI_CLK_DIVIDER_80
|
default 80 if LV_TFT_SPI_CLK_DIVIDER_80
|
||||||
default 2
|
default 2
|
||||||
|
|
||||||
config LV_M5STICKC_HANDLE_AXP192
|
|
||||||
bool "Handle Backlight and TFT power for M5StickC using AXP192." if LV_PREDEFINED_DISPLAY_M5STICKC || LV_TFT_DISPLAY_CONTROLLER_ST7735S
|
|
||||||
default y if LV_PREDEFINED_DISPLAY_M5STICKC
|
|
||||||
select LV_I2C_DISPLAY
|
|
||||||
help
|
|
||||||
Display and TFT power supply on M5StickC is controlled using an
|
|
||||||
AXP192 Power Mangerment IC. Select yes if you want to enable TFT IC
|
|
||||||
(LDO3) and backlight power using AXP192 by LVGL, or select no if you
|
|
||||||
want to take care of power management in your own code.
|
|
||||||
|
|
||||||
config LV_INVERT_DISPLAY
|
config LV_INVERT_DISPLAY
|
||||||
bool "IN DEPRECATION - Invert display." if LV_TFT_DISPLAY_CONTROLLER_RA8875
|
bool "IN DEPRECATION - Invert display."
|
||||||
default n
|
default y if LV_PREDEFINED_DISPLAY_M5STACK
|
||||||
help
|
help
|
||||||
If text is backwards on your display, try enabling this.
|
If text is backwards on your display, try enabling this.
|
||||||
|
|
||||||
config LV_INVERT_COLORS
|
config LV_INVERT_COLORS
|
||||||
bool "Invert colors in display" if LV_TFT_DISPLAY_CONTROLLER_ILI9341 || LV_TFT_DISPLAY_CONTROLLER_ST7735S || LV_TFT_DISPLAY_CONTROLLER_ILI9481 || LV_TFT_DISPLAY_CONTROLLER_ST7789 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 || LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_HX8357 || LV_TFT_DISPLAY_CONTROLLER_GC9A01 || LV_TFT_DISPLAY_CONTROLLER_ILI9163C
|
bool "Invert colors in display" if LV_TFT_DISPLAY_CONTROLLER_ILI9341 || LV_TFT_DISPLAY_CONTROLLER_ST7735S || LV_TFT_DISPLAY_CONTROLLER_ILI9481
|
||||||
default y if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICKC
|
default y if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
help
|
help
|
||||||
If the colors look inverted on your display, try enabling this.
|
If the colors look inverted on your display, try enabling this.
|
||||||
If it didn't help try LVGL configuration -> Swap the 2 bytes of RGB565 color.
|
|
||||||
|
|
||||||
|
config LV_M5STICKC_HANDLE_AXP192
|
||||||
|
bool "Handle Backlight and TFT power for M5StickC using AXP192." if LV_PREDEFINED_DISPLAY_M5STICKC || LV_TFT_DISPLAY_CONTROLLER_ST7735S
|
||||||
|
default y if LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
|
help
|
||||||
|
Display and TFT power supply on M5StickC is controlled using an AXP192 Power Mangerment IC.
|
||||||
|
Select yes if you want to enable TFT IC (LDO3) and backlight power using AXP192 by LVGL, or select no if you want to take care of
|
||||||
|
power management in your own code.
|
||||||
|
|
||||||
|
config LV_AXP192_PIN_SDA
|
||||||
|
int "GPIO for AXP192 I2C SDA" if LV_M5STICKC_HANDLE_AXP192
|
||||||
|
range 0 39
|
||||||
|
default 21 if LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
|
default 21
|
||||||
|
help
|
||||||
|
Configure the AXP192 I2C SDA pin here.
|
||||||
|
|
||||||
|
config LV_AXP192_PIN_SCL
|
||||||
|
int "GPIO for AXP192 I2C SCL" if LV_M5STICKC_HANDLE_AXP192
|
||||||
|
range 0 39
|
||||||
|
default 22 if LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
|
default 22
|
||||||
|
help
|
||||||
|
Configure the AXP192 I2C SDA pin here.
|
||||||
|
|
||||||
# menu will be visible only when LV_PREDEFINED_DISPLAY_NONE is y
|
# menu will be visible only when LV_PREDEFINED_DISPLAY_NONE is y
|
||||||
menu "Display RA8875 Configuration"
|
menu "Display RA8875 Configuration"
|
||||||
|
@ -736,29 +722,16 @@ menu "LVGL TFT Display controller"
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
# menu will be visible only when LV_PREDEFINED_DISPLAY_NONE is y
|
|
||||||
menu "Display ST7789 Configuration"
|
|
||||||
visible if LV_TFT_DISPLAY_CONTROLLER_ST7789
|
|
||||||
|
|
||||||
config LV_DISP_ST7789_SOFT_RESET
|
|
||||||
bool "Soft reset - use software reset instead of reset pin"
|
|
||||||
depends on LV_TFT_DISPLAY_CONTROLLER_ST7789
|
|
||||||
default n
|
|
||||||
help
|
|
||||||
Use software reset and ignores configured reset pin (some hardware does not use a reset pin).
|
|
||||||
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
# menu will be visible only when LV_PREDEFINED_DISPLAY_NONE is y
|
# menu will be visible only when LV_PREDEFINED_DISPLAY_NONE is y
|
||||||
menu "Display Pin Assignments"
|
menu "Display Pin Assignments"
|
||||||
visible if LV_PREDEFINED_DISPLAY_NONE || LV_PREDEFINED_DISPLAY_RPI_MPI3501 || LV_PREDEFINED_PINS_TKOALA
|
visible if LV_PREDEFINED_DISPLAY_NONE || LV_PREDEFINED_DISPLAY_RPI_MPI3501 || LV_PREDEFINED_PINS_TKOALA
|
||||||
|
|
||||||
config LV_DISP_SPI_MOSI
|
config LV_DISP_SPI_MOSI
|
||||||
int "GPIO for MOSI (Master Out Slave In)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
int "GPIO for MOSI (Master Out Slave In)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
|
range 0 39
|
||||||
default 23 if LV_PREDEFINED_DISPLAY_WROVER4
|
default 23 if LV_PREDEFINED_DISPLAY_WROVER4
|
||||||
default 23 if LV_PREDEFINED_DISPLAY_ATAG
|
default 23 if LV_PREDEFINED_DISPLAY_ATAG
|
||||||
default 23 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
default 23 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
||||||
default 23 if LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
default 15 if LV_PREDEFINED_DISPLAY_M5STICKC
|
default 15 if LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
default 18 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
default 18 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
||||||
default 23 if LV_PREDEFINED_PINS_TKOALA
|
default 23 if LV_PREDEFINED_PINS_TKOALA
|
||||||
|
@ -766,13 +739,13 @@ menu "LVGL TFT Display controller"
|
||||||
default 19 if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
|
default 19 if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
|
||||||
default 13 if LV_PREDEFINED_DISPLAY_WT32_SC01
|
default 13 if LV_PREDEFINED_DISPLAY_WT32_SC01
|
||||||
default 13
|
default 13
|
||||||
|
|
||||||
help
|
help
|
||||||
Configure the display MOSI pin here.
|
Configure the display MOSI pin here.
|
||||||
|
|
||||||
config LV_DISPLAY_USE_SPI_MISO
|
config LV_DISPLAY_USE_SPI_MISO
|
||||||
bool "GPIO for MISO (Master In Slave Out)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
bool "GPIO for MISO (Master In Slave Out)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
default y if LV_PREDEFINED_PINS_TKOALA
|
default y if LV_PREDEFINED_PINS_TKOALA
|
||||||
default y if LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
help
|
help
|
||||||
Enable the MISO signal to control the display. You can disable
|
Enable the MISO signal to control the display. You can disable
|
||||||
it when the display does not need MISO signal to be controlled.
|
it when the display does not need MISO signal to be controlled.
|
||||||
|
@ -780,8 +753,8 @@ menu "LVGL TFT Display controller"
|
||||||
config LV_DISP_SPI_MISO
|
config LV_DISP_SPI_MISO
|
||||||
int "GPIO for MISO (Master In Slave Out)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
int "GPIO for MISO (Master In Slave Out)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
depends on LV_DISPLAY_USE_SPI_MISO
|
depends on LV_DISPLAY_USE_SPI_MISO
|
||||||
|
range 0 39
|
||||||
default 19 if LV_PREDEFINED_PINS_TKOALA
|
default 19 if LV_PREDEFINED_PINS_TKOALA
|
||||||
default 38 if LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
default 0
|
default 0
|
||||||
|
|
||||||
help
|
help
|
||||||
|
@ -799,6 +772,7 @@ menu "LVGL TFT Display controller"
|
||||||
config LV_DISP_SPI_IO2
|
config LV_DISP_SPI_IO2
|
||||||
int "GPIO for Quad SPI IO2/WP" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
int "GPIO for Quad SPI IO2/WP" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
||||||
|
range -1 39
|
||||||
default 22 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
default 22 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
||||||
default -1
|
default -1
|
||||||
help
|
help
|
||||||
|
@ -807,6 +781,7 @@ menu "LVGL TFT Display controller"
|
||||||
config LV_DISP_SPI_IO3
|
config LV_DISP_SPI_IO3
|
||||||
int "GPIO for Quad SPI IO3/HD" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
int "GPIO for Quad SPI IO3/HD" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
||||||
|
range -1 39
|
||||||
default 21 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
default 21 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
|
||||||
default -1
|
default -1
|
||||||
help
|
help
|
||||||
|
@ -814,8 +789,8 @@ menu "LVGL TFT Display controller"
|
||||||
|
|
||||||
config LV_DISP_SPI_CLK
|
config LV_DISP_SPI_CLK
|
||||||
int "GPIO for CLK (SCK / Serial Clock)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
int "GPIO for CLK (SCK / Serial Clock)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
|
range 0 39
|
||||||
default 18 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
default 18 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
||||||
default 18 if LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
default 13 if LV_PREDEFINED_DISPLAY_M5STICKC
|
default 13 if LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
default 18 if LV_PREDEFINED_DISPLAY_ATAG
|
default 18 if LV_PREDEFINED_DISPLAY_ATAG
|
||||||
default 19 if LV_PREDEFINED_DISPLAY_WROVER4
|
default 19 if LV_PREDEFINED_DISPLAY_WROVER4
|
||||||
|
@ -839,9 +814,9 @@ menu "LVGL TFT Display controller"
|
||||||
config LV_DISP_SPI_CS
|
config LV_DISP_SPI_CS
|
||||||
int "GPIO for CS (Slave Select)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
int "GPIO for CS (Slave Select)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
depends on LV_DISPLAY_USE_SPI_CS
|
depends on LV_DISPLAY_USE_SPI_CS
|
||||||
|
range 0 39
|
||||||
default 5 if LV_PREDEFINED_PINS_38V1
|
default 5 if LV_PREDEFINED_PINS_38V1
|
||||||
default 14 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
default 14 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
||||||
default 5 if LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
default 5 if LV_PREDEFINED_DISPLAY_M5STICKC
|
default 5 if LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
default 22 if LV_PREDEFINED_DISPLAY_WROVER4
|
default 22 if LV_PREDEFINED_DISPLAY_WROVER4
|
||||||
default 15 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
default 15 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
||||||
|
@ -864,11 +839,11 @@ menu "LVGL TFT Display controller"
|
||||||
|
|
||||||
config LV_DISP_PIN_DC
|
config LV_DISP_PIN_DC
|
||||||
int "GPIO for DC (Data / Command)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
int "GPIO for DC (Data / Command)" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
|
range 0 39
|
||||||
depends on LV_DISPLAY_USE_DC
|
depends on LV_DISPLAY_USE_DC
|
||||||
default 19 if LV_PREDEFINED_PINS_38V1
|
default 19 if LV_PREDEFINED_PINS_38V1
|
||||||
default 17 if LV_PREDEFINED_PINS_38V4
|
default 17 if LV_PREDEFINED_PINS_38V4
|
||||||
default 27 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
default 27 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
||||||
default 15 if LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
default 23 if LV_PREDEFINED_DISPLAY_M5STICKC
|
default 23 if LV_PREDEFINED_DISPLAY_M5STICKC
|
||||||
default 21 if LV_PREDEFINED_DISPLAY_WROVER4
|
default 21 if LV_PREDEFINED_DISPLAY_WROVER4
|
||||||
default 21 if LV_PREDEFINED_DISPLAY_WT32_SC01
|
default 21 if LV_PREDEFINED_DISPLAY_WT32_SC01
|
||||||
|
@ -882,22 +857,9 @@ menu "LVGL TFT Display controller"
|
||||||
help
|
help
|
||||||
Configure the display DC pin here.
|
Configure the display DC pin here.
|
||||||
|
|
||||||
config LV_DISP_USE_RST
|
|
||||||
bool "Use a GPIO for resetting the display" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
|
||||||
default n if LV_PREDEFINED_DISPLAY_M5CORE2
|
|
||||||
default y
|
|
||||||
help
|
|
||||||
Enable display reset control. Set this if the reset pin of the
|
|
||||||
display is connected to the host. If this is not set, then it is
|
|
||||||
the user's responsibility to ensure that the display is reset
|
|
||||||
before initialisation.
|
|
||||||
You may want to disable this option because the reset pin is not
|
|
||||||
connected, or is connected to an external component such as the
|
|
||||||
power management IC.
|
|
||||||
|
|
||||||
config LV_DISP_PIN_RST
|
config LV_DISP_PIN_RST
|
||||||
int "GPIO for Reset" if LV_TFT_DISPLAY_PROTOCOL_SPI && !LV_DISP_ST7789_SOFT_RESET
|
int "GPIO for Reset" if LV_TFT_DISPLAY_PROTOCOL_SPI
|
||||||
depends on LV_DISP_USE_RST
|
range 0 39
|
||||||
default 18 if LV_PREDEFINED_PINS_38V1
|
default 18 if LV_PREDEFINED_PINS_38V1
|
||||||
default 25 if LV_PREDEFINED_PINS_38V4
|
default 25 if LV_PREDEFINED_PINS_38V4
|
||||||
default 33 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
default 33 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
|
||||||
|
@ -916,66 +878,29 @@ menu "LVGL TFT Display controller"
|
||||||
|
|
||||||
config LV_DISP_PIN_BUSY
|
config LV_DISP_PIN_BUSY
|
||||||
int "GPIO for Busy" if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
int "GPIO for Busy" if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
||||||
|
range 0 39
|
||||||
default 35 if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
default 35 if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
||||||
default 35 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2
|
default 35
|
||||||
default 21 if IDF_TARGET_ESP32C3
|
|
||||||
|
|
||||||
help
|
help
|
||||||
Configure the display Busy pin here.
|
Configure the display Busy pin here.
|
||||||
|
|
||||||
endmenu
|
config LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
bool "Enable control of the display backlight by using an GPIO." if \
|
||||||
choice
|
|
||||||
prompt "Select an I2C port for the display"
|
|
||||||
default LV_I2C_DISPLAY_PORT_0
|
|
||||||
depends on LV_I2C_DISPLAY
|
|
||||||
|
|
||||||
config LV_I2C_DISPLAY_PORT_0
|
|
||||||
bool
|
|
||||||
prompt "I2C port 0"
|
|
||||||
help
|
|
||||||
I2C is shared peripheral managed by I2C Manager. In order to configure I2C Manager (pinout, etc.) see menu
|
|
||||||
Component config->I2C Port Settings.
|
|
||||||
|
|
||||||
config LV_I2C_DISPLAY_PORT_1
|
|
||||||
bool
|
|
||||||
prompt "I2C port 1"
|
|
||||||
help
|
|
||||||
I2C is shared peripheral managed by I2C Manager. In order to configure I2C Manager (pinout, etc.) see menu
|
|
||||||
Component config->I2C Port Settings.
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
choice
|
|
||||||
default LV_DISP_BACKLIGHT_SWITCH
|
|
||||||
prompt "Backlight Control" if \
|
|
||||||
(! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) )
|
|
||||||
|
|
||||||
config LV_DISP_BACKLIGHT_OFF
|
|
||||||
bool
|
|
||||||
prompt "Not Used"
|
|
||||||
help
|
|
||||||
Display backlight is not controlled by this driver, must be hardwired in hardware.
|
|
||||||
|
|
||||||
config LV_DISP_BACKLIGHT_SWITCH
|
|
||||||
bool
|
|
||||||
prompt "Switch control"
|
|
||||||
help
|
|
||||||
Display backlight can be switched on or off.
|
|
||||||
|
|
||||||
config LV_DISP_BACKLIGHT_PWM
|
|
||||||
bool
|
|
||||||
prompt "PWM control"
|
|
||||||
help
|
|
||||||
Display backlight is controlled by pulse-width modulation, allowing brightness settings.
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config LV_BACKLIGHT_ACTIVE_LVL
|
|
||||||
bool "Is backlight turn on with a HIGH (1) logic level?" if \
|
|
||||||
( LV_PREDEFINED_DISPLAY_NONE && ! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) ) \
|
( LV_PREDEFINED_DISPLAY_NONE && ! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) ) \
|
||||||
|| LV_PREDEFINED_DISPLAY_RPI_MPI3501
|
|| LV_PREDEFINED_DISPLAY_RPI_MPI3501
|
||||||
depends on !LV_DISP_BACKLIGHT_OFF
|
default y if LV_PREDEFINED_DISPLAY_M5STACK
|
||||||
|
default y if LV_PREDEFINED_DISPLAY_WROVER4
|
||||||
|
default y if LV_PREDEFINED_DISPLAY_ERTFT0356
|
||||||
|
default y if LV_PREDEFINED_DISPLAY_TTGO
|
||||||
|
default y if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
|
||||||
|
default y if LV_PREDEFINED_DISPLAY_WT32_SC01
|
||||||
|
help
|
||||||
|
Enable controlling the display backlight using an GPIO
|
||||||
|
|
||||||
|
config LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
bool "Is backlight turn on with a HIGH (1) logic level?"
|
||||||
|
depends on LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
default y if LV_PREDEFINED_DISPLAY_M5STACK
|
default y if LV_PREDEFINED_DISPLAY_M5STACK
|
||||||
default y if LV_PREDEFINED_DISPLAY_ERTFT0356
|
default y if LV_PREDEFINED_DISPLAY_ERTFT0356
|
||||||
default y if LV_PREDEFINED_DISPLAY_TTGO
|
default y if LV_PREDEFINED_DISPLAY_TTGO
|
||||||
|
@ -987,10 +912,9 @@ menu "LVGL TFT Display controller"
|
||||||
otherwise a 0 will be expected to enable it.
|
otherwise a 0 will be expected to enable it.
|
||||||
|
|
||||||
config LV_DISP_PIN_BCKL
|
config LV_DISP_PIN_BCKL
|
||||||
int "GPIO for Backlight Control" if \
|
int "GPIO for Backlight Control"
|
||||||
( LV_PREDEFINED_DISPLAY_NONE && ! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) ) \
|
depends on LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|| LV_PREDEFINED_DISPLAY_RPI_MPI3501
|
range 0 39
|
||||||
depends on !LV_DISP_BACKLIGHT_OFF
|
|
||||||
default 23 if LV_PREDEFINED_PINS_38V1
|
default 23 if LV_PREDEFINED_PINS_38V1
|
||||||
default 26 if LV_PREDEFINED_PINS_38V4
|
default 26 if LV_PREDEFINED_PINS_38V4
|
||||||
default 32 if LV_PREDEFINED_DISPLAY_M5STACK
|
default 32 if LV_PREDEFINED_DISPLAY_M5STACK
|
||||||
|
@ -1001,18 +925,29 @@ menu "LVGL TFT Display controller"
|
||||||
default 4 if LV_PREDEFINED_DISPLAY_TTGO
|
default 4 if LV_PREDEFINED_DISPLAY_TTGO
|
||||||
default 2 if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
|
default 2 if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
|
||||||
default 23 if LV_PREDEFINED_DISPLAY_WT32_SC01
|
default 23 if LV_PREDEFINED_DISPLAY_WT32_SC01
|
||||||
default -1
|
default 27
|
||||||
|
|
||||||
help
|
help
|
||||||
Configure the display BCLK (LED) pin here.
|
Configure the display BCLK (LED) pin here.
|
||||||
|
|
||||||
config LV_I2C
|
config LV_DISP_PIN_SDA
|
||||||
bool
|
int "GPIO for I2C SDA" if LV_TFT_DISPLAY_PROTOCOL_I2C
|
||||||
default y if LV_I2C_DISPLAY
|
range 0 39
|
||||||
|
default 5 if LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
|
||||||
|
default 5
|
||||||
|
|
||||||
config LV_I2C_DISPLAY_PORT
|
help
|
||||||
int
|
Configure the I2C SDA pin here.
|
||||||
default 1 if LV_I2C_DISPLAY_PORT_1
|
|
||||||
default 0
|
config LV_DISP_PIN_SCL
|
||||||
|
int "GPIO for I2C SCL" if LV_TFT_DISPLAY_PROTOCOL_I2C
|
||||||
|
range 0 39
|
||||||
|
default 4 if LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
|
||||||
|
default 4
|
||||||
|
|
||||||
|
help
|
||||||
|
Configure the I2C SCL pin here.
|
||||||
|
|
||||||
|
endmenu
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
4
lvgl_tft/component.mk
Normal file
4
lvgl_tft/component.mk
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# TFT drivers
|
||||||
|
|
||||||
|
COMPONENT_SRCDIRS := .
|
||||||
|
COMPONENT_ADD_INCLUDEDIRS := .
|
|
@ -4,10 +4,8 @@
|
||||||
|
|
||||||
#include "disp_driver.h"
|
#include "disp_driver.h"
|
||||||
#include "disp_spi.h"
|
#include "disp_spi.h"
|
||||||
#include "esp_lcd_backlight.h"
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
void *disp_driver_init(void)
|
void disp_driver_init(void)
|
||||||
{
|
{
|
||||||
#if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
#if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
||||||
ili9341_init();
|
ili9341_init();
|
||||||
|
@ -41,37 +39,6 @@ void *disp_driver_init(void)
|
||||||
jd79653a_init();
|
jd79653a_init();
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
||||||
uc8151d_init();
|
uc8151d_init();
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C
|
|
||||||
ili9163c_init();
|
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544
|
|
||||||
pcd8544_init();
|
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SCHMITT
|
|
||||||
schmitt_init();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// We still use menuconfig for these settings
|
|
||||||
// It will be set up during runtime in the future
|
|
||||||
#if (defined(CONFIG_LV_DISP_BACKLIGHT_SWITCH) || defined(CONFIG_LV_DISP_BACKLIGHT_PWM))
|
|
||||||
const disp_backlight_config_t bckl_config = {
|
|
||||||
.gpio_num = CONFIG_LV_DISP_PIN_BCKL,
|
|
||||||
#if defined CONFIG_LV_DISP_BACKLIGHT_PWM
|
|
||||||
.pwm_control = true,
|
|
||||||
#else
|
|
||||||
.pwm_control = false,
|
|
||||||
#endif
|
|
||||||
#if defined CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
|
||||||
.output_invert = false, // Backlight on high
|
|
||||||
#else
|
|
||||||
.output_invert = true, // Backlight on low
|
|
||||||
#endif
|
|
||||||
.timer_idx = 0,
|
|
||||||
.channel_idx = 0 // @todo this prevents us from having two PWM controlled displays
|
|
||||||
};
|
|
||||||
disp_backlight_h bckl_handle = disp_backlight_new(&bckl_config);
|
|
||||||
disp_backlight_set(bckl_handle, 100);
|
|
||||||
return bckl_handle;
|
|
||||||
#else
|
|
||||||
return NULL;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,12 +76,6 @@ void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t *
|
||||||
jd79653a_lv_fb_flush(drv, area, color_map);
|
jd79653a_lv_fb_flush(drv, area, color_map);
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
||||||
uc8151d_lv_fb_flush(drv, area, color_map);
|
uc8151d_lv_fb_flush(drv, area, color_map);
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C
|
|
||||||
ili9163c_flush(drv, area, color_map);
|
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544
|
|
||||||
pcd8544_flush(drv, area, color_map);
|
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SCHMITT
|
|
||||||
schmitt_flush(drv, area, color_map);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,8 +91,6 @@ void disp_driver_rounder(lv_disp_drv_t * disp_drv, lv_area_t * area)
|
||||||
jd79653a_lv_rounder_cb(disp_drv, area);
|
jd79653a_lv_rounder_cb(disp_drv, area);
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
||||||
uc8151d_lv_rounder_cb(disp_drv, area);
|
uc8151d_lv_rounder_cb(disp_drv, area);
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544
|
|
||||||
pcd8544_rounder(disp_drv, area);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +107,5 @@ void disp_driver_set_px(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_
|
||||||
jd79653a_lv_set_fb_cb(disp_drv, buf, buf_w, x, y, color, opa);
|
jd79653a_lv_set_fb_cb(disp_drv, buf, buf_w, x, y, color, opa);
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
||||||
uc8151d_lv_set_fb_cb(disp_drv, buf, buf_w, x, y, color, opa);
|
uc8151d_lv_set_fb_cb(disp_drv, buf, buf_w, x, y, color, opa);
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544
|
|
||||||
pcd8544_set_px_cb(disp_drv, buf, buf_w, x, y, color, opa);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,6 @@ extern "C" {
|
||||||
#include "jd79653a.h"
|
#include "jd79653a.h"
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
|
||||||
#include "uc8151d.h"
|
#include "uc8151d.h"
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C
|
|
||||||
#include "ili9163c.h"
|
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544
|
|
||||||
#include "pcd8544.h"
|
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SCHMITT
|
|
||||||
#include "schmitt.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
|
@ -71,7 +65,7 @@ extern "C" {
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
/* Initialize display */
|
/* Initialize display */
|
||||||
void *disp_driver_init(void);
|
void disp_driver_init(void);
|
||||||
|
|
||||||
/* Display flush callback */
|
/* Display flush callback */
|
||||||
void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
|
|
@ -310,12 +310,7 @@ static void IRAM_ATTR spi_ready(spi_transaction_t *trans)
|
||||||
disp = lv_refr_get_disp_refreshing();
|
disp = lv_refr_get_disp_refreshing();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LVGL_VERSION_MAJOR < 8
|
|
||||||
lv_disp_flush_ready(&disp->driver);
|
lv_disp_flush_ready(&disp->driver);
|
||||||
#else
|
|
||||||
lv_disp_flush_ready(disp->driver);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chained_post_cb) {
|
if (chained_post_cb) {
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
/**
|
|
||||||
* @file esp_lcd_backlight.c
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* INCLUDES
|
|
||||||
*********************/
|
|
||||||
#include "esp_lcd_backlight.h"
|
|
||||||
#include "driver/ledc.h"
|
|
||||||
#include "rom/gpio.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "soc/ledc_periph.h" // to invert LEDC output on IDF version < v4.3
|
|
||||||
|
|
||||||
#define SIG_GPIO_OUT_IDX 128
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool pwm_control; // true: LEDC is used, false: GPIO is used
|
|
||||||
int index; // Either GPIO or LEDC channel
|
|
||||||
} disp_backlight_t;
|
|
||||||
|
|
||||||
static const char *TAG = "disp_backlight";
|
|
||||||
|
|
||||||
disp_backlight_h disp_backlight_new(const disp_backlight_config_t *config)
|
|
||||||
{
|
|
||||||
// Check input parameters
|
|
||||||
if (config == NULL)
|
|
||||||
return NULL;
|
|
||||||
if (!GPIO_IS_VALID_OUTPUT_GPIO(config->gpio_num)) {
|
|
||||||
ESP_LOGW(TAG, "Invalid GPIO number");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
disp_backlight_t *bckl_dev = calloc(1, sizeof(disp_backlight_t));
|
|
||||||
if (bckl_dev == NULL){
|
|
||||||
ESP_LOGW(TAG, "Not enough memory");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->pwm_control){
|
|
||||||
// Configure LED (Backlight) pin as PWM for Brightness control.
|
|
||||||
bckl_dev->pwm_control = true;
|
|
||||||
bckl_dev->index = config->channel_idx;
|
|
||||||
const ledc_channel_config_t LCD_backlight_channel = {
|
|
||||||
.gpio_num = config->gpio_num,
|
|
||||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
|
||||||
.channel = config->channel_idx,
|
|
||||||
.intr_type = LEDC_INTR_DISABLE,
|
|
||||||
.timer_sel = config->timer_idx,
|
|
||||||
.duty = 0,
|
|
||||||
.hpoint = 0
|
|
||||||
};
|
|
||||||
const ledc_timer_config_t LCD_backlight_timer = {
|
|
||||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
|
||||||
.duty_resolution = LEDC_TIMER_10_BIT,
|
|
||||||
.timer_num = config->timer_idx,
|
|
||||||
.freq_hz = 5000,
|
|
||||||
.clk_cfg = LEDC_AUTO_CLK};
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(ledc_timer_config(&LCD_backlight_timer));
|
|
||||||
ESP_ERROR_CHECK(ledc_channel_config(&LCD_backlight_channel));
|
|
||||||
gpio_matrix_out(config->gpio_num, ledc_periph_signal[LEDC_LOW_SPEED_MODE].sig_out0_idx + config->channel_idx, config->output_invert, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Configure GPIO for output
|
|
||||||
bckl_dev->index = config->gpio_num;
|
|
||||||
gpio_pad_select_gpio(config->gpio_num);
|
|
||||||
ESP_ERROR_CHECK(gpio_set_direction(config->gpio_num, GPIO_MODE_OUTPUT));
|
|
||||||
gpio_matrix_out(config->gpio_num, SIG_GPIO_OUT_IDX, config->output_invert, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (disp_backlight_h)bckl_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
void disp_backlight_set(disp_backlight_h bckl, int brightness_percent)
|
|
||||||
{
|
|
||||||
// Check input paramters
|
|
||||||
if (bckl == NULL)
|
|
||||||
return;
|
|
||||||
if (brightness_percent > 100)
|
|
||||||
brightness_percent = 100;
|
|
||||||
if (brightness_percent < 0)
|
|
||||||
brightness_percent = 0;
|
|
||||||
|
|
||||||
disp_backlight_t *bckl_dev = (disp_backlight_t *) bckl;
|
|
||||||
ESP_LOGI(TAG, "Setting LCD backlight: %d%%", brightness_percent);
|
|
||||||
|
|
||||||
if (bckl_dev->pwm_control) {
|
|
||||||
uint32_t duty_cycle = (1023 * brightness_percent) / 100; // LEDC resolution set to 10bits, thus: 100% = 1023
|
|
||||||
ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, bckl_dev->index, duty_cycle));
|
|
||||||
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, bckl_dev->index));
|
|
||||||
} else {
|
|
||||||
ESP_ERROR_CHECK(gpio_set_level(bckl_dev->index, brightness_percent));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void disp_backlight_delete(disp_backlight_h bckl)
|
|
||||||
{
|
|
||||||
if (bckl == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
disp_backlight_t *bckl_dev = (disp_backlight_t *) bckl;
|
|
||||||
if (bckl_dev->pwm_control) {
|
|
||||||
ledc_stop(LEDC_LOW_SPEED_MODE, bckl_dev->index, 0);
|
|
||||||
} else {
|
|
||||||
gpio_reset_pin(bckl_dev->index);
|
|
||||||
}
|
|
||||||
free (bckl);
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/**
|
|
||||||
* @file esp_lcd_backlight.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ESP_LCD_BACKLIGHT_H
|
|
||||||
#define ESP_LCD_BACKLIGHT_H
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* INCLUDES
|
|
||||||
*********************/
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" { /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* GLOBAL PROTOTYPES
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Display backlight controller handle
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
typedef void * disp_backlight_h;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configuration structure of backlight controller
|
|
||||||
*
|
|
||||||
* Must be passed to disp_backlight_new() for correct configuration
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
bool pwm_control;
|
|
||||||
bool output_invert;
|
|
||||||
int gpio_num; // see gpio_num_t
|
|
||||||
|
|
||||||
// Relevant only for PWM controlled backlight
|
|
||||||
// Ignored for switch (ON/OFF) backlight control
|
|
||||||
int timer_idx; // ledc_timer_t
|
|
||||||
int channel_idx; // ledc_channel_t
|
|
||||||
} disp_backlight_config_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create new backlight controller
|
|
||||||
*
|
|
||||||
* @param[in] config Configuration structure of backlight controller
|
|
||||||
* @return Display backlight controller handle
|
|
||||||
*/
|
|
||||||
disp_backlight_h disp_backlight_new(const disp_backlight_config_t *config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set backlight
|
|
||||||
*
|
|
||||||
* Brightness parameter can be 0-100 for PWM controlled backlight.
|
|
||||||
* GPIO controlled backlight (ON/OFF) is turned off witch value 0 and turned on with any positive value.
|
|
||||||
*
|
|
||||||
* @param bckl Backlight controller handle
|
|
||||||
* @param[in] brightness_percent Brightness in [%]
|
|
||||||
*/
|
|
||||||
void disp_backlight_set(disp_backlight_h bckl, int brightness_percent);
|
|
||||||
void disp_backlight_delete(disp_backlight_h bckl);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*ESP_LCD_BACKLIGHT_H*/
|
|
|
@ -162,17 +162,19 @@ void hx8357_init(void)
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(HX8357_DC);
|
gpio_pad_select_gpio(HX8357_DC);
|
||||||
gpio_set_direction(HX8357_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(HX8357_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if HX8357_USE_RST
|
|
||||||
gpio_pad_select_gpio(HX8357_RST);
|
gpio_pad_select_gpio(HX8357_RST);
|
||||||
gpio_set_direction(HX8357_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(HX8357_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if HX8357_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(HX8357_BCKL);
|
||||||
|
gpio_set_direction(HX8357_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Reset the display
|
//Reset the display
|
||||||
gpio_set_level(HX8357_RST, 0);
|
gpio_set_level(HX8357_RST, 0);
|
||||||
vTaskDelay(10 / portTICK_RATE_MS);
|
vTaskDelay(10 / portTICK_RATE_MS);
|
||||||
gpio_set_level(HX8357_RST, 1);
|
gpio_set_level(HX8357_RST, 1);
|
||||||
vTaskDelay(120 / portTICK_RATE_MS);
|
vTaskDelay(120 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initialization.");
|
ESP_LOGI(TAG, "Initialization.");
|
||||||
|
|
||||||
|
@ -198,11 +200,11 @@ void hx8357_init(void)
|
||||||
|
|
||||||
hx8357_set_rotation(1);
|
hx8357_set_rotation(1);
|
||||||
|
|
||||||
#if HX8357_INVERT_COLORS
|
#if HX8357_INVERT_DISPLAY
|
||||||
hx8357_send_cmd(HX8357_INVON);
|
hx8357_send_cmd(HX8357_INVON);;
|
||||||
#else
|
|
||||||
hx8357_send_cmd(HX8357_INVOFF);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
hx8357_enable_backlight(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,6 +241,23 @@ void hx8357_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
|
||||||
hx8357_send_color((void*)color_map, size * 2);
|
hx8357_send_color((void*)color_map, size * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hx8357_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if HX8357_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGD(TAG, "%s backlight.\n", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (HX8357_BCKL_ACTIVE_LVL==1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(HX8357_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void hx8357_set_rotation(uint8_t r)
|
void hx8357_set_rotation(uint8_t r)
|
||||||
{
|
{
|
||||||
r = r & 3; // can't be higher than 3
|
r = r & 3; // can't be higher than 3
|
||||||
|
|
|
@ -37,8 +37,18 @@ extern "C" {
|
||||||
*********************/
|
*********************/
|
||||||
#define HX8357_DC CONFIG_LV_DISP_PIN_DC
|
#define HX8357_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define HX8357_RST CONFIG_LV_DISP_PIN_RST
|
#define HX8357_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define HX8357_USE_RST CONFIG_LV_DISP_USE_RST
|
#define HX8357_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
#define HX8357_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
|
||||||
|
#define HX8357_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
#define HX8357_BCKL_ACTIVE_LVL 1
|
||||||
|
#else
|
||||||
|
#define HX8357_BCKL_ACTIVE_LVL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// if text/images are backwards, try setting this to 1
|
||||||
|
#define HX8357_INVERT_DISPLAY CONFIG_LV_INVERT_DISPLAY
|
||||||
|
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
|
@ -127,6 +137,7 @@ extern "C" {
|
||||||
|
|
||||||
void hx8357_init(void);
|
void hx8357_init(void);
|
||||||
void hx8357_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void hx8357_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
void hx8357_enable_backlight(bool backlight);
|
||||||
void hx8357_set_rotation(uint8_t r);
|
void hx8357_set_rotation(uint8_t r);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
|
|
@ -153,7 +153,7 @@ void il3820_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_m
|
||||||
* the display buffer.
|
* the display buffer.
|
||||||
* BIT_CLEAR(byte_index, bit_index) sets the bit_index pixel at the byte_index
|
* BIT_CLEAR(byte_index, bit_index) sets the bit_index pixel at the byte_index
|
||||||
* of the display buffer. */
|
* of the display buffer. */
|
||||||
void il3820_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t* buf,
|
void il3820_set_px_cb(struct _disp_drv_t * disp_drv, uint8_t* buf,
|
||||||
lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
||||||
lv_color_t color, lv_opa_t opa)
|
lv_color_t color, lv_opa_t opa)
|
||||||
{
|
{
|
||||||
|
@ -185,7 +185,7 @@ void il3820_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t* buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Required by LVGL */
|
/* Required by LVGL */
|
||||||
void il3820_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area) {
|
void il3820_rounder(struct _disp_drv_t * disp_drv, lv_area_t *area) {
|
||||||
area->x1 = area->x1 & ~(0x7);
|
area->x1 = area->x1 & ~(0x7);
|
||||||
area->x2 = area->x2 | (0x7);
|
area->x2 = area->x2 | (0x7);
|
||||||
}
|
}
|
||||||
|
@ -198,20 +198,16 @@ void il3820_init(void)
|
||||||
/* Initialize non-SPI GPIOs */
|
/* Initialize non-SPI GPIOs */
|
||||||
gpio_pad_select_gpio(IL3820_DC_PIN);
|
gpio_pad_select_gpio(IL3820_DC_PIN);
|
||||||
gpio_set_direction(IL3820_DC_PIN, GPIO_MODE_OUTPUT);
|
gpio_set_direction(IL3820_DC_PIN, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
gpio_pad_select_gpio(IL3820_BUSY_PIN);
|
|
||||||
gpio_set_direction(IL3820_BUSY_PIN, GPIO_MODE_INPUT);
|
|
||||||
|
|
||||||
#if IL3820_USE_RST
|
|
||||||
gpio_pad_select_gpio(IL3820_RST_PIN);
|
gpio_pad_select_gpio(IL3820_RST_PIN);
|
||||||
gpio_set_direction(IL3820_RST_PIN, GPIO_MODE_OUTPUT);
|
gpio_set_direction(IL3820_RST_PIN, GPIO_MODE_OUTPUT);
|
||||||
|
gpio_pad_select_gpio(IL3820_BUSY_PIN);
|
||||||
|
gpio_set_direction(IL3820_BUSY_PIN, GPIO_MODE_INPUT);
|
||||||
|
|
||||||
/* Harware reset */
|
/* Harware reset */
|
||||||
gpio_set_level( IL3820_RST_PIN, 0);
|
gpio_set_level( IL3820_RST_PIN, 0);
|
||||||
vTaskDelay(IL3820_RESET_DELAY / portTICK_RATE_MS);
|
vTaskDelay(IL3820_RESET_DELAY / portTICK_RATE_MS);
|
||||||
gpio_set_level( IL3820_RST_PIN, 1);
|
gpio_set_level( IL3820_RST_PIN, 1);
|
||||||
vTaskDelay(IL3820_RESET_DELAY / portTICK_RATE_MS);
|
vTaskDelay(IL3820_RESET_DELAY / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Software reset */
|
/* Software reset */
|
||||||
il3820_write_cmd(IL3820_CMD_SW_RESET, NULL, 0);
|
il3820_write_cmd(IL3820_CMD_SW_RESET, NULL, 0);
|
||||||
|
|
|
@ -28,7 +28,6 @@ extern "C"
|
||||||
|
|
||||||
#define IL3820_DC_PIN CONFIG_LV_DISP_PIN_DC
|
#define IL3820_DC_PIN CONFIG_LV_DISP_PIN_DC
|
||||||
#define IL3820_RST_PIN CONFIG_LV_DISP_PIN_RST
|
#define IL3820_RST_PIN CONFIG_LV_DISP_PIN_RST
|
||||||
#define IL3820_USE_RST CONFIG_LV_DISP_USE_RST
|
|
||||||
#define IL3820_BUSY_PIN CONFIG_LV_DISP_PIN_BUSY
|
#define IL3820_BUSY_PIN CONFIG_LV_DISP_PIN_BUSY
|
||||||
#define IL3820_BUSY_LEVEL 1
|
#define IL3820_BUSY_LEVEL 1
|
||||||
|
|
||||||
|
@ -101,8 +100,8 @@ extern "C"
|
||||||
void il3820_init(void);
|
void il3820_init(void);
|
||||||
void il3820_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
void il3820_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
||||||
void il3820_fullflush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
void il3820_fullflush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
||||||
void il3820_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area);
|
void il3820_rounder(struct _disp_drv_t * disp_drv, lv_area_t *area);
|
||||||
void il3820_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa);
|
void il3820_set_px_cb(struct _disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa);
|
||||||
void il3820_sleep_in(void);
|
void il3820_sleep_in(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,248 +0,0 @@
|
||||||
/**
|
|
||||||
* @file ILI9163C.c
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* INCLUDES
|
|
||||||
*********************/
|
|
||||||
#include "ili9163c.h"
|
|
||||||
#include "disp_spi.h"
|
|
||||||
#include "driver/gpio.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "assert.h"
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* DEFINES
|
|
||||||
*********************/
|
|
||||||
#define TAG "ILI9163C"
|
|
||||||
|
|
||||||
// ILI9163C specific commands used in init
|
|
||||||
#define ILI9163C_NOP 0x00
|
|
||||||
#define ILI9163C_SWRESET 0x01
|
|
||||||
#define ILI9163C_RDDID 0x04
|
|
||||||
#define ILI9163C_RDDST 0x09
|
|
||||||
|
|
||||||
#define ILI9163C_SLPIN 0x10
|
|
||||||
#define ILI9163C_SLPOUT 0x11
|
|
||||||
#define ILI9163C_PTLON 0x12
|
|
||||||
#define ILI9163C_NORON 0x13
|
|
||||||
|
|
||||||
#define ILI9163C_INVOFF 0x20
|
|
||||||
#define ILI9163C_INVON 0x21
|
|
||||||
#define ILI9163C_CMD_GAMST 0x26
|
|
||||||
#define ILI9163C_DISPOFF 0x28
|
|
||||||
#define ILI9163C_DISPON 0x29
|
|
||||||
#define ILI9163C_CASET 0x2A
|
|
||||||
#define ILI9163C_RASET 0x2B
|
|
||||||
#define ILI9163C_RAMWR 0x2C
|
|
||||||
#define ILI9163C_COLORSET 0x2D
|
|
||||||
#define ILI9163C_RAMRD 0x2E
|
|
||||||
|
|
||||||
#define ILI9163C_PTLAR 0x30
|
|
||||||
#define ILI9163C_VSCRDEF 0x33
|
|
||||||
#define ILI9163C_COLMOD 0x3A
|
|
||||||
#define ILI9163C_MADCTL 0x36
|
|
||||||
#define ILI9163C_VSCRSADD 0x37
|
|
||||||
|
|
||||||
#define ILI9163C_FRMCTR1 0xB1
|
|
||||||
#define ILI9163C_FRMCTR2 0xB2
|
|
||||||
#define ILI9163C_FRMCTR3 0xB3
|
|
||||||
#define ILI9163C_INVCTR 0xB4
|
|
||||||
#define ILI9163C_DISSET5 0xB6
|
|
||||||
#define ILI9163C_SDDC 0xB7
|
|
||||||
|
|
||||||
#define ILI9163C_PWCTR1 0xC0
|
|
||||||
#define ILI9163C_PWCTR2 0xC1
|
|
||||||
#define ILI9163C_PWCTR3 0xC2
|
|
||||||
#define ILI9163C_PWCTR4 0xC3
|
|
||||||
#define ILI9163C_PWCTR5 0xC4
|
|
||||||
#define ILI9163C_VMCTR1 0xC5
|
|
||||||
#define ILI9163C_VMCOFFS 0xC7
|
|
||||||
|
|
||||||
#define ILI9163C_GAMCTL 0xF2
|
|
||||||
|
|
||||||
#define ILI9163C_GMCTRP1 0xE0
|
|
||||||
#define ILI9163C_GMCTRN1 0xE1
|
|
||||||
|
|
||||||
#define ST77XX_MADCTL_MY 0x80
|
|
||||||
#define ST77XX_MADCTL_MX 0x40
|
|
||||||
#define ST77XX_MADCTL_MV 0x20 #define
|
|
||||||
#define ST77XX_MADCTL_ML 0x10
|
|
||||||
#define ST77XX_MADCTL_RGB 0x00
|
|
||||||
#define ST77XX_MADCTL_BGR 0x08
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* TYPEDEFS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
/*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint8_t cmd;
|
|
||||||
uint8_t data[16];
|
|
||||||
uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
|
|
||||||
} lcd_init_cmd_t;
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* STATIC PROTOTYPES
|
|
||||||
**********************/
|
|
||||||
static void ili9163c_set_orientation(uint8_t orientation);
|
|
||||||
|
|
||||||
static void ili9163c_send_cmd(uint8_t cmd);
|
|
||||||
static void ili9163c_send_data(void *data, uint16_t length);
|
|
||||||
static void ili9163c_send_color(void *data, uint16_t length);
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* STATIC VARIABLES
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* MACROS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* GLOBAL FUNCTIONS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
void ili9163c_init(void)
|
|
||||||
{
|
|
||||||
ESP_LOGD(TAG, "Init");
|
|
||||||
|
|
||||||
lcd_init_cmd_t ili_init_cmds[] = {
|
|
||||||
{ILI9163C_SWRESET, {0}, 0x80}, // Software reset, 0 args, w/delay 120ms
|
|
||||||
{ILI9163C_SLPOUT, {0}, 0x80}, // Out of sleep mode, 0 args, w/delay 5ms
|
|
||||||
{ILI9163C_CMD_GAMST, {0x04}, 1}, // Gamma Curve
|
|
||||||
{ILI9163C_FRMCTR1, {0x0C, 0x14}, 2}, // Frame rate ctrl - normal mode
|
|
||||||
{ILI9163C_INVCTR, {0x07}, 1}, // Display inversion ctrl, 1 arg, no delay:No inversion
|
|
||||||
{ILI9163C_PWCTR1, {0x0C, 0x05}, 2}, // Power control, 2 args, no delay
|
|
||||||
{ILI9163C_PWCTR2, {0x02}, 1}, // Power control, 1 arg
|
|
||||||
{ILI9163C_PWCTR3, {0x02}, 1}, // Power control, 1 arg
|
|
||||||
{ILI9163C_VMCTR1, {0x20, 0x55}, 2}, // Power control, 1 arg, no delay:
|
|
||||||
{ILI9163C_VMCOFFS, {0x40}, 1}, // VCOM Offset
|
|
||||||
#if ILI9163C_INVERT_COLORS == 1
|
|
||||||
{ILI9163C_INVON, {0}, 0}, // set inverted mode
|
|
||||||
#else
|
|
||||||
{ILI9163C_INVOFF, {0}, 0}, // set non-inverted mode
|
|
||||||
#endif
|
|
||||||
{ILI9163C_COLMOD, {0x5}, 1}, // set color mode, 1 arg, no delay: 16-bit color
|
|
||||||
{ILI9163C_SDDC, {0}, 1}, // set source driver direction control
|
|
||||||
{ILI9163C_GAMCTL, {0x01}, 1}, // set source driver direction control
|
|
||||||
{ILI9163C_GMCTRP1, {0x36, 0x29, 0x12, 0x22, 0x1C, 0x15, 0x42, 0xB7, 0x2F, 0x13, 0x12, 0x0A, 0x11, 0x0B, 0x06}, 16}, // 16 args, no delay:
|
|
||||||
{ILI9163C_GMCTRN1, {0x09, 0x16, 0x2D, 0x0D, 0x13, 0x15, 0x40, 0x48, 0x53, 0x0C, 0x1D, 0x25, 0x2E, 0x34, 0x39}, 16}, // 16 args, no delay:
|
|
||||||
{ILI9163C_NORON, {0}, 0x80}, // Normal display on, no args, w/delay 10 ms delay
|
|
||||||
{ILI9163C_DISPON, {0}, 0x80}, // Main screen turn on, no args w/delay 100 ms delay
|
|
||||||
{0, {0}, 0xff}
|
|
||||||
};
|
|
||||||
|
|
||||||
//Initialize non-SPI GPIOs
|
|
||||||
gpio_pad_select_gpio(ILI9163C_DC);
|
|
||||||
gpio_set_direction(ILI9163C_DC, GPIO_MODE_OUTPUT);
|
|
||||||
gpio_pad_select_gpio(ILI9163C_RST);
|
|
||||||
gpio_set_direction(ILI9163C_RST, GPIO_MODE_OUTPUT);
|
|
||||||
|
|
||||||
//Reset the display
|
|
||||||
gpio_set_level(ILI9163C_RST, 0);
|
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
|
||||||
gpio_set_level(ILI9163C_RST, 1);
|
|
||||||
vTaskDelay(150 / portTICK_RATE_MS);
|
|
||||||
|
|
||||||
//Send all the commands
|
|
||||||
uint16_t cmd = 0;
|
|
||||||
while (ili_init_cmds[cmd].databytes != 0xff)
|
|
||||||
{
|
|
||||||
ili9163c_send_cmd(ili_init_cmds[cmd].cmd);
|
|
||||||
ili9163c_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes & 0x1F);
|
|
||||||
if (ili_init_cmds[cmd].databytes & 0x80)
|
|
||||||
{
|
|
||||||
vTaskDelay(150 / portTICK_RATE_MS);
|
|
||||||
}
|
|
||||||
cmd++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ili9163c_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ili9163c_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
|
|
||||||
{
|
|
||||||
uint8_t data[4];
|
|
||||||
|
|
||||||
/*Column addresses*/
|
|
||||||
ili9163c_send_cmd(ILI9163C_CASET);
|
|
||||||
data[0] = (area->x1 >> 8) & 0xFF;
|
|
||||||
data[1] = area->x1 & 0xFF;
|
|
||||||
data[2] = (area->x2 >> 8) & 0xFF;
|
|
||||||
data[3] = area->x2 & 0xFF;
|
|
||||||
ili9163c_send_data(data, 4);
|
|
||||||
|
|
||||||
/*Page addresses*/
|
|
||||||
ili9163c_send_cmd(ILI9163C_RASET);
|
|
||||||
data[0] = (area->y1 >> 8) & 0xFF;
|
|
||||||
data[1] = area->y1 & 0xFF;
|
|
||||||
data[2] = (area->y2 >> 8) & 0xFF;
|
|
||||||
data[3] = area->y2 & 0xFF;
|
|
||||||
ili9163c_send_data(data, 4);
|
|
||||||
|
|
||||||
/*Memory write*/
|
|
||||||
ili9163c_send_cmd(ILI9163C_RAMWR);
|
|
||||||
|
|
||||||
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
|
||||||
|
|
||||||
ili9163c_send_color((void *)color_map, size * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ili9163c_sleep_in()
|
|
||||||
{
|
|
||||||
uint8_t data[] = {0x08};
|
|
||||||
ili9163c_send_cmd(ILI9163C_SLPIN);
|
|
||||||
ili9163c_send_data(&data, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ili9163c_sleep_out()
|
|
||||||
{
|
|
||||||
uint8_t data[] = {0x08};
|
|
||||||
ili9163c_send_cmd(ILI9163C_SLPOUT);
|
|
||||||
ili9163c_send_data(&data, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* STATIC FUNCTIONS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
static void ili9163c_send_cmd(uint8_t cmd)
|
|
||||||
{
|
|
||||||
disp_wait_for_pending_transactions();
|
|
||||||
gpio_set_level(ILI9163C_DC, 0); /*Command mode*/
|
|
||||||
disp_spi_send_data(&cmd, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ili9163c_send_data(void *data, uint16_t length)
|
|
||||||
{
|
|
||||||
disp_wait_for_pending_transactions();
|
|
||||||
gpio_set_level(ILI9163C_DC, 1); /*Data mode*/
|
|
||||||
disp_spi_send_data(data, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ili9163c_send_color(void *data, uint16_t length)
|
|
||||||
{
|
|
||||||
disp_wait_for_pending_transactions();
|
|
||||||
gpio_set_level(ILI9163C_DC, 1); /*Data mode*/
|
|
||||||
disp_spi_send_colors(data, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ili9163c_set_orientation(uint8_t orientation)
|
|
||||||
{
|
|
||||||
assert(orientation < 4);
|
|
||||||
|
|
||||||
const char *orientation_str[] = {
|
|
||||||
"PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED"};
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Display orientation: %s", orientation_str[orientation]);
|
|
||||||
|
|
||||||
uint8_t data[] = {0x48, 0x88, 0xA8, 0x68};
|
|
||||||
|
|
||||||
ili9163c_send_cmd(ILI9163C_MADCTL);
|
|
||||||
ili9163c_send_data((void *)&data[orientation], 1);
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
/**
|
|
||||||
* @file lv_templ.h
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ILI9163C_H
|
|
||||||
#define ILI9163C_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* INCLUDES
|
|
||||||
*********************/
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
|
||||||
#include "lvgl.h"
|
|
||||||
#else
|
|
||||||
#include "lvgl/lvgl.h"
|
|
||||||
#endif
|
|
||||||
#include "../lvgl_helpers.h"
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* DEFINES
|
|
||||||
*********************/
|
|
||||||
#define ILI9163C_DC CONFIG_LV_DISP_PIN_DC
|
|
||||||
#define ILI9163C_RST CONFIG_LV_DISP_PIN_RST
|
|
||||||
#define ILI9163C_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* TYPEDEFS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* GLOBAL PROTOTYPES
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
void ili9163c_init(void);
|
|
||||||
void ili9163c_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
|
||||||
void ili9163c_sleep_in(void);
|
|
||||||
void ili9163c_sleep_out(void);
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* MACROS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*ILI9163C_H*/
|
|
|
@ -80,20 +80,31 @@ void ili9341_init(void)
|
||||||
{0, {0}, 0xff},
|
{0, {0}, 0xff},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if ILI9341_BCKL == 15
|
||||||
|
gpio_config_t io_conf;
|
||||||
|
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||||
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||||
|
io_conf.pin_bit_mask = GPIO_SEL_15;
|
||||||
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(ILI9341_DC);
|
gpio_pad_select_gpio(ILI9341_DC);
|
||||||
gpio_set_direction(ILI9341_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9341_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if ILI9341_USE_RST
|
|
||||||
gpio_pad_select_gpio(ILI9341_RST);
|
gpio_pad_select_gpio(ILI9341_RST);
|
||||||
gpio_set_direction(ILI9341_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9341_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if ILI9341_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(ILI9341_BCKL);
|
||||||
|
gpio_set_direction(ILI9341_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
//Reset the display
|
//Reset the display
|
||||||
gpio_set_level(ILI9341_RST, 0);
|
gpio_set_level(ILI9341_RST, 0);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(ILI9341_RST, 1);
|
gpio_set_level(ILI9341_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initialization.");
|
ESP_LOGI(TAG, "Initialization.");
|
||||||
|
|
||||||
|
@ -108,6 +119,8 @@ void ili9341_init(void)
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ili9341_enable_backlight(true);
|
||||||
|
|
||||||
ili9341_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
ili9341_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
||||||
|
|
||||||
#if ILI9341_INVERT_COLORS == 1
|
#if ILI9341_INVERT_COLORS == 1
|
||||||
|
@ -140,10 +153,29 @@ void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
|
||||||
|
|
||||||
/*Memory write*/
|
/*Memory write*/
|
||||||
ili9341_send_cmd(0x2C);
|
ili9341_send_cmd(0x2C);
|
||||||
|
|
||||||
|
|
||||||
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
||||||
|
|
||||||
ili9341_send_color((void*)color_map, size * 2);
|
ili9341_send_color((void*)color_map, size * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ili9341_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if ILI9341_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (ILI9341_BCKL_ACTIVE_LVL==1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(ILI9341_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void ili9341_sleep_in()
|
void ili9341_sleep_in()
|
||||||
{
|
{
|
||||||
uint8_t data[] = {0x08};
|
uint8_t data[] = {0x08};
|
||||||
|
@ -196,10 +228,8 @@ static void ili9341_set_orientation(uint8_t orientation)
|
||||||
|
|
||||||
#if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK
|
#if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK
|
||||||
uint8_t data[] = {0x68, 0x68, 0x08, 0x08};
|
uint8_t data[] = {0x68, 0x68, 0x08, 0x08};
|
||||||
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2)
|
|
||||||
uint8_t data[] = {0x08, 0x88, 0x28, 0xE8};
|
|
||||||
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_WROVER4)
|
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_WROVER4)
|
||||||
uint8_t data[] = {0x6C, 0xEC, 0xCC, 0x4C};
|
uint8_t data[] = {0x4C, 0x88, 0x28, 0xE8};
|
||||||
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_NONE)
|
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_NONE)
|
||||||
uint8_t data[] = {0x48, 0x88, 0x28, 0xE8};
|
uint8_t data[] = {0x48, 0x88, 0x28, 0xE8};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,15 +20,23 @@ extern "C" {
|
||||||
#else
|
#else
|
||||||
#include "lvgl/lvgl.h"
|
#include "lvgl/lvgl.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "../lvgl_helpers.h"
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
#define ILI9341_DC CONFIG_LV_DISP_PIN_DC
|
#define ILI9341_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define ILI9341_USE_RST CONFIG_LV_DISP_USE_RST
|
|
||||||
#define ILI9341_RST CONFIG_LV_DISP_PIN_RST
|
#define ILI9341_RST CONFIG_LV_DISP_PIN_RST
|
||||||
|
#define ILI9341_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
|
||||||
|
#define ILI9341_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
#define ILI9341_BCKL_ACTIVE_LVL 1
|
||||||
|
#else
|
||||||
|
#define ILI9341_BCKL_ACTIVE_LVL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ILI9341_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
#define ILI9341_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
@ -41,6 +49,7 @@ extern "C" {
|
||||||
|
|
||||||
void ili9341_init(void);
|
void ili9341_init(void);
|
||||||
void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
void ili9341_enable_backlight(bool backlight);
|
||||||
void ili9341_sleep_in(void);
|
void ili9341_sleep_in(void);
|
||||||
void ili9341_sleep_out(void);
|
void ili9341_sleep_out(void);
|
||||||
|
|
||||||
|
|
|
@ -76,17 +76,19 @@ void ili9481_init(void)
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(ILI9481_DC);
|
gpio_pad_select_gpio(ILI9481_DC);
|
||||||
gpio_set_direction(ILI9481_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9481_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if ILI9481_USE_RST
|
|
||||||
gpio_pad_select_gpio(ILI9481_RST);
|
gpio_pad_select_gpio(ILI9481_RST);
|
||||||
gpio_set_direction(ILI9481_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9481_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if ILI9481_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(ILI9481_BCKL);
|
||||||
|
gpio_set_direction(ILI9481_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Reset the display
|
//Reset the display
|
||||||
gpio_set_level(ILI9481_RST, 0);
|
gpio_set_level(ILI9481_RST, 0);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(ILI9481_RST, 1);
|
gpio_set_level(ILI9481_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "ILI9481 initialization.");
|
ESP_LOGI(TAG, "ILI9481 initialization.");
|
||||||
|
|
||||||
|
@ -105,6 +107,8 @@ void ili9481_init(void)
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ili9481_enable_backlight(true);
|
||||||
|
|
||||||
ili9481_set_orientation(ILI9481_DISPLAY_ORIENTATION);
|
ili9481_set_orientation(ILI9481_DISPLAY_ORIENTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +168,22 @@ void ili9481_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
|
||||||
heap_caps_free(mybuf);
|
heap_caps_free(mybuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ili9481_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if ILI9481_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (ILI9481_BCKL_ACTIVE_LVL==1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(ILI9481_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
|
@ -27,10 +27,17 @@ extern "C" {
|
||||||
*********************/
|
*********************/
|
||||||
#define ILI9481_DC CONFIG_LV_DISP_PIN_DC
|
#define ILI9481_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define ILI9481_RST CONFIG_LV_DISP_PIN_RST
|
#define ILI9481_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define ILI9481_USE_RST CONFIG_LV_DISP_USE_RST
|
#define ILI9481_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
|
||||||
|
#define ILI9481_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
#define ILI9481_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
#define ILI9481_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
||||||
#define ILI9481_DISPLAY_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION
|
#define ILI9481_DISPLAY_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
#define ILI9481_BCKL_ACTIVE_LVL 1
|
||||||
|
#else
|
||||||
|
#define ILI9481_BCKL_ACTIVE_LVL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
* ILI9481 REGS
|
* ILI9481 REGS
|
||||||
|
@ -110,6 +117,7 @@ extern "C" {
|
||||||
|
|
||||||
void ili9481_init(void);
|
void ili9481_init(void);
|
||||||
void ili9481_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void ili9481_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
void ili9481_enable_backlight(bool backlight);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
|
@ -65,20 +65,32 @@ void ili9486_init(void)
|
||||||
{0x00, {0}, 0xff},
|
{0x00, {0}, 0xff},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if ILI9486_BCKL == 15
|
||||||
|
gpio_config_t io_conf;
|
||||||
|
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||||
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||||
|
io_conf.pin_bit_mask = GPIO_SEL_15;
|
||||||
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(ILI9486_DC);
|
gpio_pad_select_gpio(ILI9486_DC);
|
||||||
gpio_set_direction(ILI9486_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9486_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if ILI9486_USE_RST
|
|
||||||
gpio_pad_select_gpio(ILI9486_RST);
|
gpio_pad_select_gpio(ILI9486_RST);
|
||||||
gpio_set_direction(ILI9486_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9486_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if ILI9486_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(ILI9486_BCKL);
|
||||||
|
gpio_set_direction(ILI9486_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Reset the display
|
//Reset the display
|
||||||
gpio_set_level(ILI9486_RST, 0);
|
gpio_set_level(ILI9486_RST, 0);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(ILI9486_RST, 1);
|
gpio_set_level(ILI9486_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "ILI9486 Initialization.");
|
ESP_LOGI(TAG, "ILI9486 Initialization.");
|
||||||
|
|
||||||
|
@ -93,6 +105,8 @@ void ili9486_init(void)
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ili9486_enable_backlight(true);
|
||||||
|
|
||||||
ili9486_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
ili9486_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +139,22 @@ void ili9486_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
|
||||||
ili9486_send_color((void*) color_map, size * 2);
|
ili9486_send_color((void*) color_map, size * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ili9486_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if ILI9486_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (ILI9486_BCKL_ACTIVE_LVL==1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(ILI9486_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
|
@ -27,8 +27,15 @@ extern "C" {
|
||||||
*********************/
|
*********************/
|
||||||
#define ILI9486_DC CONFIG_LV_DISP_PIN_DC
|
#define ILI9486_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define ILI9486_RST CONFIG_LV_DISP_PIN_RST
|
#define ILI9486_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define ILI9486_USE_RST CONFIG_LV_DISP_USE_RST
|
#define ILI9486_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
|
||||||
|
#define ILI9486_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
#define ILI9486_BCKL_ACTIVE_LVL 1
|
||||||
|
#else
|
||||||
|
#define ILI9486_BCKL_ACTIVE_LVL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
|
@ -40,6 +47,7 @@ extern "C" {
|
||||||
|
|
||||||
void ili9486_init(void);
|
void ili9486_init(void);
|
||||||
void ili9486_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void ili9486_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
void ili9486_enable_backlight(bool backlight);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
|
@ -78,17 +78,19 @@ void ili9488_init(void)
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(ILI9488_DC);
|
gpio_pad_select_gpio(ILI9488_DC);
|
||||||
gpio_set_direction(ILI9488_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9488_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if ILI9488_USE_RST
|
|
||||||
gpio_pad_select_gpio(ILI9488_RST);
|
gpio_pad_select_gpio(ILI9488_RST);
|
||||||
gpio_set_direction(ILI9488_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ILI9488_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if ILI9488_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(ILI9488_BCKL);
|
||||||
|
gpio_set_direction(ILI9488_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Reset the display
|
//Reset the display
|
||||||
gpio_set_level(ILI9488_RST, 0);
|
gpio_set_level(ILI9488_RST, 0);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(ILI9488_RST, 1);
|
gpio_set_level(ILI9488_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "ILI9488 initialization.");
|
ESP_LOGI(TAG, "ILI9488 initialization.");
|
||||||
|
|
||||||
|
@ -107,6 +109,8 @@ void ili9488_init(void)
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ili9488_enable_backlight(true);
|
||||||
|
|
||||||
ili9488_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
ili9488_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +170,22 @@ void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
|
||||||
heap_caps_free(mybuf);
|
heap_caps_free(mybuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ili9488_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if ILI9488_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (ILI9488_BCKL_ACTIVE_LVL==1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(ILI9488_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
|
@ -27,7 +27,15 @@ extern "C" {
|
||||||
*********************/
|
*********************/
|
||||||
#define ILI9488_DC CONFIG_LV_DISP_PIN_DC
|
#define ILI9488_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define ILI9488_RST CONFIG_LV_DISP_PIN_RST
|
#define ILI9488_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define ILI9488_USE_RST CONFIG_LV_DISP_USE_RSTS
|
#define ILI9488_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
|
||||||
|
#define ILI9488_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
#define ILI9488_BCKL_ACTIVE_LVL 1
|
||||||
|
#else
|
||||||
|
#define ILI9488_BCKL_ACTIVE_LVL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
* ILI9488 REGS
|
* ILI9488 REGS
|
||||||
|
@ -146,6 +154,7 @@ typedef struct {
|
||||||
|
|
||||||
void ili9488_init(void);
|
void ili9488_init(void);
|
||||||
void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
void ili9488_enable_backlight(bool backlight);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
|
@ -1,148 +0,0 @@
|
||||||
/**
|
|
||||||
* @file pcd8544.c
|
|
||||||
*
|
|
||||||
* Roughly based on:
|
|
||||||
* https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
|
|
||||||
* https://github.com/olikraus/u8g2
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "disp_spi.h"
|
|
||||||
#include "driver/gpio.h"
|
|
||||||
|
|
||||||
#include <esp_log.h>
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
|
|
||||||
#include "pcd8544.h"
|
|
||||||
|
|
||||||
#define TAG "lv_pcd8544"
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* MACROS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
#define BIT_SET(a,b) ((a) |= (1U<<(b)))
|
|
||||||
#define BIT_CLEAR(a,b) ((a) &= ~(1U<<(b)))
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* STATIC FUNCTIONS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
static void pcd8544_send_cmd(uint8_t cmd)
|
|
||||||
{
|
|
||||||
disp_wait_for_pending_transactions();
|
|
||||||
gpio_set_level(PCD8544_DC, 0); /*Command mode*/
|
|
||||||
disp_spi_send_data(&cmd, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pcd8544_send_data(void * data, uint16_t length)
|
|
||||||
{
|
|
||||||
disp_wait_for_pending_transactions();
|
|
||||||
gpio_set_level(PCD8544_DC, 1); /*Data mode*/
|
|
||||||
disp_spi_send_data(data, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pcd8544_send_colors(void * data, uint16_t length)
|
|
||||||
{
|
|
||||||
gpio_set_level(PCD8544_DC, 1); /*Data mode*/
|
|
||||||
disp_spi_send_colors(data, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* GLOBAL FUNCTIONS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
void pcd8544_init(void){
|
|
||||||
|
|
||||||
// TODO: orientation
|
|
||||||
|
|
||||||
// Initialize non-SPI GPIOs
|
|
||||||
gpio_pad_select_gpio(PCD8544_DC);
|
|
||||||
gpio_set_direction(PCD8544_DC, GPIO_MODE_OUTPUT);
|
|
||||||
gpio_pad_select_gpio(PCD8544_RST);
|
|
||||||
gpio_set_direction(PCD8544_RST, GPIO_MODE_OUTPUT);
|
|
||||||
|
|
||||||
// Reset the display
|
|
||||||
gpio_set_level(PCD8544_RST, 0);
|
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
|
||||||
gpio_set_level(PCD8544_RST, 1);
|
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
|
||||||
|
|
||||||
pcd8544_send_cmd(0x21); /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
|
|
||||||
pcd8544_send_cmd(0x06); /* temp. control: b10 = 2 */
|
|
||||||
pcd8544_send_cmd(0x13); /* bias system 1:48 */
|
|
||||||
pcd8544_send_cmd(0xc0); /* medium Vop = Contrast 0x40 = 64 */
|
|
||||||
|
|
||||||
pcd8544_send_cmd(0x20); /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=0) */
|
|
||||||
pcd8544_send_cmd(0x0c); /* display mode normal */
|
|
||||||
}
|
|
||||||
|
|
||||||
void pcd8544_set_contrast (uint8_t contrast){
|
|
||||||
if (contrast > 0x7f){
|
|
||||||
contrast = 0x7f;
|
|
||||||
}
|
|
||||||
pcd8544_send_cmd(0x21); /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
|
|
||||||
pcd8544_send_cmd(0x80 | contrast); /* medium Vop = Contrast */
|
|
||||||
}
|
|
||||||
|
|
||||||
void pcd8544_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area){
|
|
||||||
uint8_t hor_max = disp_drv->hor_res;
|
|
||||||
uint8_t ver_max = disp_drv->ver_res;
|
|
||||||
|
|
||||||
area->x1 = 0;
|
|
||||||
area->y1 = 0;
|
|
||||||
area->x2 = hor_max - 1;
|
|
||||||
area->y2 = ver_max - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pcd8544_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
|
||||||
lv_color_t color, lv_opa_t opa){
|
|
||||||
|
|
||||||
uint8_t set = (color.full == 0) && (LV_OPA_TRANSP != opa);
|
|
||||||
|
|
||||||
uint16_t byte_index = x + (( y>>3 ) * buf_w);
|
|
||||||
uint8_t bit_index = y & 0x7;
|
|
||||||
|
|
||||||
if (set) {
|
|
||||||
BIT_SET(buf[byte_index], bit_index);
|
|
||||||
} else {
|
|
||||||
BIT_CLEAR(buf[byte_index], bit_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pcd8544_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_map){
|
|
||||||
|
|
||||||
pcd8544_send_cmd(0x20); /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=0) */
|
|
||||||
|
|
||||||
uint8_t * buf = (uint8_t *) color_map;
|
|
||||||
|
|
||||||
// Check if the whole frame buffer can be sent in a single SPI transaction
|
|
||||||
|
|
||||||
if ((area->x1 == 0) && (area->y1 == 0) && (area->x2 == (disp_drv->hor_res - 1)) && (area->y2 == (disp_drv->ver_res - 1))){
|
|
||||||
|
|
||||||
// send complete frame buffer at once.
|
|
||||||
// NOTE: disp_spi_send_colors triggers lv_disp_flush_ready
|
|
||||||
|
|
||||||
pcd8544_send_cmd(0x40); /* set Y address */
|
|
||||||
pcd8544_send_cmd(0x80); /* set X address */
|
|
||||||
pcd8544_send_colors(buf, disp_drv->hor_res * disp_drv->ver_res / 8);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// send horizontal tiles
|
|
||||||
|
|
||||||
uint16_t bank_start = area->y1 / 8;
|
|
||||||
uint16_t bank_end = area->y2 / 8;
|
|
||||||
|
|
||||||
uint16_t bank;
|
|
||||||
uint16_t cols_to_update = area->x2 - area->x1 + 1;
|
|
||||||
for (bank = bank_start ; bank <= bank_end ; bank++ ){
|
|
||||||
pcd8544_send_cmd(0x40 | bank ); /* set Y address */
|
|
||||||
pcd8544_send_cmd(0x80 | area->x1 ); /* set X address */
|
|
||||||
uint16_t offset = bank * disp_drv->hor_res + area->x1;
|
|
||||||
pcd8544_send_data(&buf[offset], cols_to_update);
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_disp_flush_ready(disp_drv);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
|
|
||||||
/**
|
|
||||||
* @file pcd8544.h
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PCD8544_H
|
|
||||||
#define PCD8544_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* INCLUDES
|
|
||||||
*********************/
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
|
||||||
#include "lvgl.h"
|
|
||||||
#else
|
|
||||||
#include "lvgl/lvgl.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* DEFINES
|
|
||||||
*********************/
|
|
||||||
|
|
||||||
#define PCD8544_DC CONFIG_LV_DISP_PIN_DC
|
|
||||||
#define PCD8544_RST CONFIG_LV_DISP_PIN_RST
|
|
||||||
#define PCD8544_BCKL CONFIG_LV_DISP_PIN_BCKL
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* TYPEDEFS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* GLOBAL PROTOTYPES
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
void pcd8544_init(void);
|
|
||||||
void pcd8544_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
|
||||||
void pcd8544_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area);
|
|
||||||
void pcd8544_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
|
||||||
lv_color_t color, lv_opa_t opa);
|
|
||||||
void pcd8544_set_contrast(uint8_t contrast);
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* MACROS
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*PCD8544_H*/
|
|
|
@ -148,18 +148,29 @@ void ra8875_init(void)
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initializing RA8875...");
|
ESP_LOGI(TAG, "Initializing RA8875...");
|
||||||
|
|
||||||
// Initialize non-SPI GPIOs
|
#if (CONFIG_LV_DISP_PIN_BCKL == 15)
|
||||||
|
gpio_config_t io_conf;
|
||||||
|
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||||
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||||
|
io_conf.pin_bit_mask = GPIO_SEL_15;
|
||||||
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if RA8875_USE_RST
|
// Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(RA8875_RST);
|
gpio_pad_select_gpio(RA8875_RST);
|
||||||
gpio_set_direction(RA8875_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(RA8875_RST, GPIO_MODE_OUTPUT);
|
||||||
|
#ifdef CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
gpio_pad_select_gpio(CONFIG_LV_DISP_PIN_BCKL);
|
||||||
|
gpio_set_direction(CONFIG_LV_DISP_PIN_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Reset the RA8875
|
// Reset the RA8875
|
||||||
gpio_set_level(RA8875_RST, 0);
|
gpio_set_level(RA8875_RST, 0);
|
||||||
vTaskDelay(DIV_ROUND_UP(100, portTICK_RATE_MS));
|
vTaskDelay(DIV_ROUND_UP(100, portTICK_RATE_MS));
|
||||||
gpio_set_level(RA8875_RST, 1);
|
gpio_set_level(RA8875_RST, 1);
|
||||||
vTaskDelay(DIV_ROUND_UP(100, portTICK_RATE_MS));
|
vTaskDelay(DIV_ROUND_UP(100, portTICK_RATE_MS));
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initalize RA8875 clocks (SPI must be decelerated before initializing clocks)
|
// Initalize RA8875 clocks (SPI must be decelerated before initializing clocks)
|
||||||
disp_spi_change_device_speed(SPI_CLOCK_SPEED_SLOW_HZ);
|
disp_spi_change_device_speed(SPI_CLOCK_SPEED_SLOW_HZ);
|
||||||
|
@ -183,8 +194,28 @@ void ra8875_init(void)
|
||||||
ESP_LOGW(TAG, "WARNING: Memory clear timed out; RA8875 may be unresponsive.");
|
ESP_LOGW(TAG, "WARNING: Memory clear timed out; RA8875 may be unresponsive.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable the display
|
// Enable the display and backlight
|
||||||
ra8875_enable_display(true);
|
ra8875_enable_display(true);
|
||||||
|
ra8875_enable_backlight(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ra8875_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
gpio_set_level(CONFIG_LV_DISP_PIN_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ra8875_enable_display(bool enable)
|
void ra8875_enable_display(bool enable)
|
||||||
|
|
|
@ -25,7 +25,6 @@ extern "C" {
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
#define RA8875_RST CONFIG_LV_DISP_PIN_RST
|
#define RA8875_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define RA8875_USE_RST CONFIG_LV_DISP_USE_RST
|
|
||||||
|
|
||||||
// System & Configuration Registers
|
// System & Configuration Registers
|
||||||
#define RA8875_REG_PWRR (0x01) // Power and Display Control Register (PWRR)
|
#define RA8875_REG_PWRR (0x01) // Power and Display Control Register (PWRR)
|
||||||
|
@ -97,6 +96,7 @@ extern "C" {
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
void ra8875_init(void);
|
void ra8875_init(void);
|
||||||
|
void ra8875_enable_backlight(bool backlight);
|
||||||
void ra8875_enable_display(bool enable);
|
void ra8875_enable_display(bool enable);
|
||||||
void ra8875_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void ra8875_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "schmitt.h"
|
|
||||||
#include "disp_spi.h"
|
|
||||||
|
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
static const char* TAG = "SCHMITT_DIS";
|
|
||||||
|
|
||||||
void schmitt_init(void)
|
|
||||||
{
|
|
||||||
disp_spi_acquire();
|
|
||||||
// Do things
|
|
||||||
ESP_LOGI(TAG, "schmitt_init() called");
|
|
||||||
disp_spi_release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void schmitt_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
|
|
||||||
{
|
|
||||||
disp_spi_acquire();
|
|
||||||
// Do things
|
|
||||||
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
|
||||||
disp_spi_send_colors(color_map, size * 4);
|
|
||||||
ESP_LOGI(TAG, "schmitt_flush() called");
|
|
||||||
disp_spi_release();
|
|
||||||
lv_disp_flush_ready(drv);
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
#ifndef SCHMITT_H_
|
|
||||||
#define SCHMITT_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
|
||||||
#include "lvgl.h"
|
|
||||||
#else
|
|
||||||
#include "lvgl/lvgl.h"
|
|
||||||
#endif
|
|
||||||
#include "../lvgl_helpers.h"
|
|
||||||
|
|
||||||
#define LV_HOR_RES_MAX 64
|
|
||||||
#define LV_VER_RES_MAX 64
|
|
||||||
|
|
||||||
void schmitt_init(void);
|
|
||||||
|
|
||||||
void schmitt_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
|
||||||
|
|
||||||
#endif /* SCHMITT_H_ */
|
|
|
@ -82,7 +82,7 @@ void sh1107_init(void)
|
||||||
{0xDA, {0}, 0}, // Set com pins
|
{0xDA, {0}, 0}, // Set com pins
|
||||||
{0x12, {0}, 0}, // ...value
|
{0x12, {0}, 0}, // ...value
|
||||||
{0xA4, {0}, 0}, // output ram to display
|
{0xA4, {0}, 0}, // output ram to display
|
||||||
#if defined CONFIG_LV_INVERT_COLORS
|
#if defined CONFIG_LV_INVERT_DISPLAY
|
||||||
{0xA7, {0}, 0}, // inverted display
|
{0xA7, {0}, 0}, // inverted display
|
||||||
#else
|
#else
|
||||||
{0xA6, {0}, 0}, // Non-inverted display
|
{0xA6, {0}, 0}, // Non-inverted display
|
||||||
|
@ -94,8 +94,6 @@ void sh1107_init(void)
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(SH1107_DC);
|
gpio_pad_select_gpio(SH1107_DC);
|
||||||
gpio_set_direction(SH1107_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(SH1107_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if SH1107_USE_RST
|
|
||||||
gpio_pad_select_gpio(SH1107_RST);
|
gpio_pad_select_gpio(SH1107_RST);
|
||||||
gpio_set_direction(SH1107_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(SH1107_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
@ -104,7 +102,6 @@ void sh1107_init(void)
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(SH1107_RST, 1);
|
gpio_set_level(SH1107_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
//Send all the commands
|
//Send all the commands
|
||||||
uint16_t cmd = 0;
|
uint16_t cmd = 0;
|
||||||
|
|
|
@ -27,7 +27,6 @@ extern "C" {
|
||||||
*********************/
|
*********************/
|
||||||
#define SH1107_DC CONFIG_LV_DISP_PIN_DC
|
#define SH1107_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define SH1107_RST CONFIG_LV_DISP_PIN_RST
|
#define SH1107_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define SH1107_USE_RST CONFIG_LV_DISP_USE_RST
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
/**
|
/**
|
||||||
* @file ssd1306.c
|
* @file ssd1306.c
|
||||||
*
|
*
|
||||||
* Code from https://github.com/yanbe/ssd1306-esp-idf-i2c.git is used as a starting point,
|
|
||||||
* in addition to code from https://github.com/espressif/esp-iot-solution.
|
|
||||||
*
|
|
||||||
* Definitions are borrowed from:
|
|
||||||
* http://robotcantalk.blogspot.com/2015/03/interfacing-arduino-with-ssd1306-driven.html
|
|
||||||
*
|
|
||||||
* For LVGL the forum has been used, in particular: https://blog.littlevgl.com/2019-05-06/oled
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "assert.h"
|
|
||||||
|
|
||||||
#include "lvgl_i2c/i2c_manager.h"
|
|
||||||
|
|
||||||
#include "ssd1306.h"
|
#include "ssd1306.h"
|
||||||
|
#include "driver/i2c.h"
|
||||||
|
#include "disp_spi.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
#define TAG "SSD1306"
|
#define TAG "SSD1306"
|
||||||
|
|
||||||
#define OLED_I2C_PORT (CONFIG_LV_I2C_DISPLAY_PORT)
|
// Code from https://github.com/yanbe/ssd1306-esp-idf-i2c.git is used as a starting point,
|
||||||
|
// in addition to code from https://github.com/espressif/esp-iot-solution.
|
||||||
|
// Following definitions are borrowed from
|
||||||
|
// http://robotcantalk.blogspot.com/2015/03/interfacing-arduino-with-ssd1306-driven.html
|
||||||
|
// For LittlevGL the forum has been used, in particular: https://blog.littlevgl.com/2019-05-06/oled
|
||||||
|
|
||||||
// SLA (0x3C) + WRITE_MODE (0x00) = 0x78 (0b01111000)
|
// SLA (0x3C) + WRITE_MODE (0x00) = 0x78 (0b01111000)
|
||||||
#define OLED_I2C_ADDRESS 0x3C
|
#define OLED_I2C_ADDRESS 0x3C
|
||||||
#define OLED_WIDTH 128
|
#define OLED_WIDTH 128
|
||||||
|
@ -70,6 +70,8 @@
|
||||||
// Charge Pump (pg.62)
|
// Charge Pump (pg.62)
|
||||||
#define OLED_CMD_SET_CHARGE_PUMP 0x8D // follow with 0x14
|
#define OLED_CMD_SET_CHARGE_PUMP 0x8D // follow with 0x14
|
||||||
|
|
||||||
|
#define OLED_IIC_FREQ_HZ 400000 // I2C colock frequency
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
|
@ -77,8 +79,6 @@
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len);
|
|
||||||
static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t buffer_len);
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
|
@ -94,48 +94,53 @@ static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t b
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL FUNCTIONS
|
* GLOBAL FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
void ssd1306_init(void)
|
void ssd1306_init()
|
||||||
{
|
{
|
||||||
uint8_t orientation_1 = 0;
|
esp_err_t ret;
|
||||||
uint8_t orientation_2 = 0;
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
|
|
||||||
#if defined (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE)
|
i2c_master_start(cmd);
|
||||||
orientation_1 = OLED_CMD_SET_SEGMENT_REMAP;
|
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||||
orientation_2 = OLED_CMD_SET_COM_SCAN_MODE_REMAP;
|
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||||
#elif defined (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
|
||||||
orientation_1 = 0xA0;
|
i2c_master_write_byte(cmd, OLED_CMD_SET_CHARGE_PUMP, true);
|
||||||
orientation_2 = OLED_CMD_SET_COM_SCAN_MODE_NORMAL;
|
i2c_master_write_byte(cmd, 0x14, true);
|
||||||
|
|
||||||
|
#if defined (CONFIG_DISPLAY_ORIENTATION_PORTRAIT)
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_SET_COM_SCAN_MODE_REMAP, true);
|
||||||
|
#elif defined (CONFIG_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
|
||||||
|
i2c_master_write_byte(cmd, 0xA0, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_SET_COM_SCAN_MODE_NORMAL, true);
|
||||||
#else
|
#else
|
||||||
#error "Unsupported orientation"
|
#error "Unsopported orientation"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t display_mode = 0;
|
i2c_master_write_byte(cmd, OLED_CMD_SET_CONTRAST, true);
|
||||||
|
|
||||||
#if defined CONFIG_LV_INVERT_COLORS
|
#if defined CONFIG_LV_INVERT_DISPLAY
|
||||||
display_mode = OLED_CMD_DISPLAY_INVERTED;
|
i2c_master_write_byte(cmd, OLED_CMD_DISPLAY_INVERTED, true); // Inverted display
|
||||||
#else
|
#else
|
||||||
display_mode = OLED_CMD_DISPLAY_NORMAL;
|
i2c_master_write_byte(cmd, OLED_CMD_DISPLAY_NORMAL, true); // Non-inverted display
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t conf[] = {
|
|
||||||
OLED_CONTROL_BYTE_CMD_STREAM,
|
|
||||||
OLED_CMD_SET_CHARGE_PUMP,
|
|
||||||
0x14,
|
|
||||||
orientation_1,
|
|
||||||
orientation_2,
|
|
||||||
OLED_CMD_SET_CONTRAST,
|
|
||||||
0xFF,
|
|
||||||
display_mode,
|
|
||||||
OLED_CMD_DISPLAY_ON
|
|
||||||
};
|
|
||||||
|
|
||||||
uint8_t err = send_data(NULL, conf, sizeof(conf));
|
i2c_master_write_byte(cmd, 0xFF, true);
|
||||||
assert(0 == err);
|
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_DISPLAY_ON, true);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
|
||||||
|
ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG, "OLED configured successfully");
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "OLED configuration failed. code: 0x%.2X", ret);
|
||||||
|
}
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
||||||
lv_color_t color, lv_opa_t opa)
|
lv_color_t color, lv_opa_t opa) {
|
||||||
{
|
|
||||||
uint16_t byte_index = x + (( y>>3 ) * buf_w);
|
uint16_t byte_index = x + (( y>>3 ) * buf_w);
|
||||||
uint8_t bit_index = y & 0x7;
|
uint8_t bit_index = y & 0x7;
|
||||||
|
|
||||||
|
@ -148,32 +153,49 @@ void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w
|
||||||
|
|
||||||
void ssd1306_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
|
void ssd1306_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
|
||||||
{
|
{
|
||||||
/* Divide by 8 */
|
uint8_t row1 = 0, row2 = 0;
|
||||||
uint8_t row1 = area->y1 >> 3;
|
i2c_cmd_handle_t cmd;
|
||||||
uint8_t row2 = area->y2 >> 3;
|
|
||||||
|
|
||||||
uint8_t conf[] = {
|
// Divide by 8
|
||||||
OLED_CONTROL_BYTE_CMD_STREAM,
|
row1 = area->y1 >> 3;
|
||||||
OLED_CMD_SET_MEMORY_ADDR_MODE,
|
row2 = area->y2 >> 3;
|
||||||
0x00,
|
|
||||||
OLED_CMD_SET_COLUMN_RANGE,
|
|
||||||
(uint8_t) area->x1,
|
|
||||||
(uint8_t) area->x2,
|
|
||||||
OLED_CMD_SET_PAGE_RANGE,
|
|
||||||
row1,
|
|
||||||
row2,
|
|
||||||
};
|
|
||||||
|
|
||||||
uint8_t err = send_data(disp_drv, conf, sizeof(conf));
|
cmd = i2c_cmd_link_create();
|
||||||
assert(0 == err);
|
i2c_master_start(cmd);
|
||||||
err = send_pixels(disp_drv, color_p, OLED_COLUMNS * (1 + row2 - row1));
|
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||||
assert(0 == err);
|
|
||||||
|
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_SET_MEMORY_ADDR_MODE, true);
|
||||||
|
i2c_master_write_byte(cmd, 0x00, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_SET_COLUMN_RANGE, true);
|
||||||
|
i2c_master_write_byte(cmd, area->x1, true);
|
||||||
|
i2c_master_write_byte(cmd, area->x2, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_SET_PAGE_RANGE, true);
|
||||||
|
i2c_master_write_byte(cmd, row1, true);
|
||||||
|
i2c_master_write_byte(cmd, row2, true);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
|
||||||
|
cmd = i2c_cmd_link_create();
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
|
||||||
|
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);
|
||||||
|
i2c_master_write(cmd, (uint8_t *)color_p, OLED_COLUMNS * (1+row2-row1), true);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
|
||||||
lv_disp_flush_ready(disp_drv);
|
lv_disp_flush_ready(disp_drv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// workaround: always send complete size display buffer, no partial update
|
||||||
void ssd1306_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area)
|
void ssd1306_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area)
|
||||||
{
|
{
|
||||||
|
// area->y1 = (area->y1 & (~0x7));
|
||||||
|
// area->y2 = (area->y2 & (~0x7)) + 7;
|
||||||
|
|
||||||
uint8_t hor_max = disp_drv->hor_res;
|
uint8_t hor_max = disp_drv->hor_res;
|
||||||
uint8_t ver_max = disp_drv->ver_res;
|
uint8_t ver_max = disp_drv->ver_res;
|
||||||
|
|
||||||
|
@ -183,43 +205,44 @@ void ssd1306_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area)
|
||||||
area->y2 = ver_max - 1;
|
area->y2 = ver_max - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssd1306_sleep_in(void)
|
void ssd1306_sleep_in()
|
||||||
{
|
{
|
||||||
uint8_t conf[] = {
|
esp_err_t ret;
|
||||||
OLED_CONTROL_BYTE_CMD_STREAM,
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
OLED_CMD_DISPLAY_OFF
|
|
||||||
};
|
|
||||||
|
|
||||||
uint8_t err = send_data(NULL, conf, sizeof(conf));
|
i2c_master_start(cmd);
|
||||||
assert(0 == err);
|
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||||
|
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_DISPLAY_OFF, true);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
|
||||||
|
ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "ssd1306_display_off configuration failed. code: 0x%.2X", ret);
|
||||||
|
}
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssd1306_sleep_out(void)
|
void ssd1306_sleep_out()
|
||||||
{
|
{
|
||||||
uint8_t conf[] = {
|
esp_err_t ret;
|
||||||
OLED_CONTROL_BYTE_CMD_STREAM,
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
OLED_CMD_DISPLAY_ON
|
|
||||||
};
|
|
||||||
|
|
||||||
uint8_t err = send_data(NULL, conf, sizeof(conf));
|
i2c_master_start(cmd);
|
||||||
assert(0 == err);
|
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||||
|
i2c_master_write_byte(cmd, OLED_CMD_DISPLAY_ON, true);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
|
||||||
|
ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "ssd1306_display_on configuration failed. code: 0x%.2X", ret);
|
||||||
|
}
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len)
|
|
||||||
{
|
|
||||||
(void) disp_drv;
|
|
||||||
|
|
||||||
uint8_t *data = (uint8_t *) bytes;
|
|
||||||
|
|
||||||
return lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, data[0], data + 1, bytes_len - 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t buffer_len)
|
|
||||||
{
|
|
||||||
(void) disp_drv;
|
|
||||||
|
|
||||||
return lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, color_buffer, buffer_len);
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ extern "C" {
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
#define SSD1306_SDA CONFIG_LV_DISP_PIN_SDA
|
||||||
|
#define SSD1306_SCL CONFIG_LV_DISP_PIN_SCL
|
||||||
#define SSD1306_DISPLAY_ORIENTATION TFT_ORIENTATION_LANDSCAPE
|
#define SSD1306_DISPLAY_ORIENTATION TFT_ORIENTATION_LANDSCAPE
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
|
|
@ -8,15 +8,12 @@
|
||||||
*********************/
|
*********************/
|
||||||
#include "st7735s.h"
|
#include "st7735s.h"
|
||||||
#include "disp_spi.h"
|
#include "disp_spi.h"
|
||||||
|
#include "driver/i2c.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
|
|
||||||
#include "lvgl_i2c/i2c_manager.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
@ -41,6 +38,7 @@ static void st7735s_send_cmd(uint8_t cmd);
|
||||||
static void st7735s_send_data(void * data, uint16_t length);
|
static void st7735s_send_data(void * data, uint16_t length);
|
||||||
static void st7735s_send_color(void * data, uint16_t length);
|
static void st7735s_send_color(void * data, uint16_t length);
|
||||||
static void st7735s_set_orientation(uint8_t orientation);
|
static void st7735s_set_orientation(uint8_t orientation);
|
||||||
|
static void i2c_master_init();
|
||||||
static void axp192_write_byte(uint8_t addr, uint8_t data);
|
static void axp192_write_byte(uint8_t addr, uint8_t data);
|
||||||
static void axp192_init();
|
static void axp192_init();
|
||||||
static void axp192_sleep_in();
|
static void axp192_sleep_in();
|
||||||
|
@ -62,6 +60,7 @@ uint8_t st7735s_portrait_mode = 0;
|
||||||
void st7735s_init(void)
|
void st7735s_init(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
|
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
|
||||||
|
i2c_master_init();
|
||||||
axp192_init();
|
axp192_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -100,8 +99,6 @@ void st7735s_init(void)
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(ST7735S_DC);
|
gpio_pad_select_gpio(ST7735S_DC);
|
||||||
gpio_set_direction(ST7735S_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ST7735S_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if ST7735S_USE_RST
|
|
||||||
gpio_pad_select_gpio(ST7735S_RST);
|
gpio_pad_select_gpio(ST7735S_RST);
|
||||||
gpio_set_direction(ST7735S_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ST7735S_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
@ -110,7 +107,6 @@ void st7735s_init(void)
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(ST7735S_RST, 1);
|
gpio_set_level(ST7735S_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "ST7735S initialization.");
|
ESP_LOGI(TAG, "ST7735S initialization.");
|
||||||
|
|
||||||
|
@ -164,16 +160,12 @@ void st7735s_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
|
||||||
void st7735s_sleep_in()
|
void st7735s_sleep_in()
|
||||||
{
|
{
|
||||||
st7735s_send_cmd(0x10);
|
st7735s_send_cmd(0x10);
|
||||||
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
|
|
||||||
axp192_sleep_in();
|
axp192_sleep_in();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void st7735s_sleep_out()
|
void st7735s_sleep_out()
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
|
|
||||||
axp192_sleep_out();
|
axp192_sleep_out();
|
||||||
#endif
|
|
||||||
st7735s_send_cmd(0x11);
|
st7735s_send_cmd(0x11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,18 +215,40 @@ static void st7735s_set_orientation(uint8_t orientation)
|
||||||
st7735s_send_data((void *) &data[orientation], 1);
|
st7735s_send_data((void *) &data[orientation], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
|
static void i2c_master_init()
|
||||||
|
{
|
||||||
|
i2c_config_t i2c_config = {
|
||||||
|
.mode = I2C_MODE_MASTER,
|
||||||
|
.sda_io_num = AXP192_SDA,
|
||||||
|
.scl_io_num = AXP192_SCL,
|
||||||
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.master.clk_speed = 400000
|
||||||
|
};
|
||||||
|
i2c_param_config(I2C_NUM_0, &i2c_config);
|
||||||
|
i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static void axp192_write_byte(uint8_t addr, uint8_t data)
|
static void axp192_write_byte(uint8_t addr, uint8_t data)
|
||||||
{
|
{
|
||||||
err = lvgl_i2c_write(CONFIG_LV_I2C_DISPLAY_PORT, AXP192_I2C_ADDRESS, addr, &data, 1);
|
esp_err_t ret;
|
||||||
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
|
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
i2c_master_write_byte(cmd, (AXP192_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
i2c_master_write_byte(cmd, addr, true);
|
||||||
|
i2c_master_write_byte(cmd, data, true);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
|
||||||
|
ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "AXP192 send failed. code: 0x%.2X", ret);
|
ESP_LOGE(TAG, "AXP192 send failed. code: 0x%.2X", ret);
|
||||||
}
|
}
|
||||||
}
|
i2c_cmd_link_delete(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
static void axp192_init()
|
static void axp192_init()
|
||||||
{
|
{
|
||||||
// information on how to init and use AXP192 ifor M5StickC taken from
|
// information on how to init and use AXP192 ifor M5StickC taken from
|
||||||
// https://forum.m5stack.com/topic/1025/m5stickc-turn-off-screen-completely
|
// https://forum.m5stack.com/topic/1025/m5stickc-turn-off-screen-completely
|
||||||
|
|
||||||
|
@ -242,16 +256,14 @@ static void st7735s_set_orientation(uint8_t orientation)
|
||||||
axp192_write_byte(0x28, 0xCC); // Enable LDO2&LDO3, LED&TFT 3.0V
|
axp192_write_byte(0x28, 0xCC); // Enable LDO2&LDO3, LED&TFT 3.0V
|
||||||
axp192_sleep_out();
|
axp192_sleep_out();
|
||||||
ESP_LOGI(TAG, "AXP192 initialized, power enabled for LDO2 and LDO3");
|
ESP_LOGI(TAG, "AXP192 initialized, power enabled for LDO2 and LDO3");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void axp192_sleep_in()
|
static void axp192_sleep_in()
|
||||||
{
|
{
|
||||||
axp192_write_byte(0x12, 0x4b);
|
axp192_write_byte(0x12, 0x4b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void axp192_sleep_out()
|
static void axp192_sleep_out()
|
||||||
{
|
{
|
||||||
axp192_write_byte(0x12, 0x4d);
|
axp192_write_byte(0x12, 0x4d);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -27,7 +27,9 @@ extern "C" {
|
||||||
|
|
||||||
#define ST7735S_DC CONFIG_LV_DISP_PIN_DC
|
#define ST7735S_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define ST7735S_RST CONFIG_LV_DISP_PIN_RST
|
#define ST7735S_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define ST7735S_USE_RST CONFIG_LV_DISP_USE_RST
|
|
||||||
|
#define AXP192_SDA CONFIG_LV_AXP192_PIN_SDA
|
||||||
|
#define AXP192_SCL CONFIG_LV_AXP192_PIN_SCL
|
||||||
|
|
||||||
#define ST7735S_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
#define ST7735S_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
||||||
|
|
||||||
|
@ -131,6 +133,7 @@ extern "C" {
|
||||||
|
|
||||||
void st7735s_init(void);
|
void st7735s_init(void);
|
||||||
void st7735s_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void st7735s_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
|
void st7735s_enable_backlight(bool backlight);
|
||||||
void st7735s_sleep_in(void);
|
void st7735s_sleep_in(void);
|
||||||
void st7735s_sleep_out(void);
|
void st7735s_sleep_out(void);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,9 @@ typedef struct {
|
||||||
**********************/
|
**********************/
|
||||||
static void st7789_set_orientation(uint8_t orientation);
|
static void st7789_set_orientation(uint8_t orientation);
|
||||||
|
|
||||||
static void st7789_send_color(void *data, size_t length);
|
static void st7789_send_cmd(uint8_t cmd);
|
||||||
|
static void st7789_send_data(void *data, uint16_t length);
|
||||||
|
static void st7789_send_color(void *data, uint16_t length);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
|
@ -63,13 +65,7 @@ void st7789_init(void)
|
||||||
{ST7789_CABCCTRL, {0xBE}, 1},
|
{ST7789_CABCCTRL, {0xBE}, 1},
|
||||||
{ST7789_MADCTL, {0x00}, 1}, // Set to 0x28 if your display is flipped
|
{ST7789_MADCTL, {0x00}, 1}, // Set to 0x28 if your display is flipped
|
||||||
{ST7789_COLMOD, {0x55}, 1},
|
{ST7789_COLMOD, {0x55}, 1},
|
||||||
|
{ST7789_INVON, {0}, 0},
|
||||||
#if ST7789_INVERT_COLORS == 1
|
|
||||||
{ST7789_INVON, {0}, 0}, // set inverted mode
|
|
||||||
#else
|
|
||||||
{ST7789_INVOFF, {0}, 0}, // set non-inverted mode
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{ST7789_RGBCTRL, {0x00, 0x1B}, 2},
|
{ST7789_RGBCTRL, {0x00, 0x1B}, 2},
|
||||||
{0xF2, {0x08}, 1},
|
{0xF2, {0x08}, 1},
|
||||||
{ST7789_GAMSET, {0x01}, 1},
|
{ST7789_GAMSET, {0x01}, 1},
|
||||||
|
@ -88,21 +84,19 @@ void st7789_init(void)
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(ST7789_DC);
|
gpio_pad_select_gpio(ST7789_DC);
|
||||||
gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if !defined(ST7789_SOFT_RST)
|
|
||||||
gpio_pad_select_gpio(ST7789_RST);
|
gpio_pad_select_gpio(ST7789_RST);
|
||||||
gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if ST7789_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(ST7789_BCKL);
|
||||||
|
gpio_set_direction(ST7789_BCKL, GPIO_MODE_OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Reset the display
|
//Reset the display
|
||||||
#if !defined(ST7789_SOFT_RST)
|
|
||||||
gpio_set_level(ST7789_RST, 0);
|
gpio_set_level(ST7789_RST, 0);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(ST7789_RST, 1);
|
gpio_set_level(ST7789_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#else
|
|
||||||
st7789_send_cmd(ST7789_SWRESET);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("ST7789 initialization.\n");
|
printf("ST7789 initialization.\n");
|
||||||
|
|
||||||
|
@ -117,12 +111,30 @@ void st7789_init(void)
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st7789_enable_backlight(true);
|
||||||
|
|
||||||
st7789_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
st7789_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The ST7789 display controller can drive up to 320*240 displays, when using a 240*240 or 240*135
|
void st7789_enable_backlight(bool backlight)
|
||||||
* displays there's a gap of 80px or 40/52/53px respectively. 52px or 53x offset depends on display orientation.
|
{
|
||||||
* We need to edit the coordinates to take into account those gaps, this is not necessary in all orientations. */
|
#if ST7789_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
printf("%s backlight.\n", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (ST7789_BCKL_ACTIVE_LVL==1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(ST7789_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The ST7789 display controller can drive 320*240 displays, when using a 240*240
|
||||||
|
* display there's a gap of 80px, we need to edit the coordinates to take into
|
||||||
|
* account that gap, this is not necessary in all orientations. */
|
||||||
void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
|
void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
|
||||||
{
|
{
|
||||||
uint8_t data[4] = {0};
|
uint8_t data[4] = {0};
|
||||||
|
@ -139,29 +151,13 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
|
||||||
offsety2 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET;
|
offsety2 += CONFIG_LV_TFT_DISPLAY_Y_OFFSET;
|
||||||
|
|
||||||
#elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 240)
|
#elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 240)
|
||||||
#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT)
|
#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT)
|
||||||
offsetx1 += 80;
|
offsetx1 += 80;
|
||||||
offsetx2 += 80;
|
offsetx2 += 80;
|
||||||
#elif (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
#elif (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
||||||
offsety1 += 80;
|
offsety1 += 80;
|
||||||
offsety2 += 80;
|
offsety2 += 80;
|
||||||
#endif
|
#endif
|
||||||
#elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 135)
|
|
||||||
#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) || \
|
|
||||||
(CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
|
|
||||||
offsetx1 += 40;
|
|
||||||
offsetx2 += 40;
|
|
||||||
offsety1 += 53;
|
|
||||||
offsety2 += 53;
|
|
||||||
#endif
|
|
||||||
#elif (LV_HOR_RES_MAX == 135) && (LV_VER_RES_MAX == 240)
|
|
||||||
#if (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE) || \
|
|
||||||
(CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
|
|
||||||
offsetx1 += 52;
|
|
||||||
offsetx2 += 52;
|
|
||||||
offsety1 += 40;
|
|
||||||
offsety2 += 40;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*Column addresses*/
|
/*Column addresses*/
|
||||||
|
@ -183,7 +179,7 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
|
||||||
/*Memory write*/
|
/*Memory write*/
|
||||||
st7789_send_cmd(ST7789_RAMWR);
|
st7789_send_cmd(ST7789_RAMWR);
|
||||||
|
|
||||||
size_t size = (size_t)lv_area_get_width(area) * (size_t)lv_area_get_height(area);
|
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
||||||
|
|
||||||
st7789_send_color((void*)color_map, size * 2);
|
st7789_send_color((void*)color_map, size * 2);
|
||||||
|
|
||||||
|
@ -192,21 +188,21 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
void st7789_send_cmd(uint8_t cmd)
|
static void st7789_send_cmd(uint8_t cmd)
|
||||||
{
|
{
|
||||||
disp_wait_for_pending_transactions();
|
disp_wait_for_pending_transactions();
|
||||||
gpio_set_level(ST7789_DC, 0);
|
gpio_set_level(ST7789_DC, 0);
|
||||||
disp_spi_send_data(&cmd, 1);
|
disp_spi_send_data(&cmd, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void st7789_send_data(void * data, uint16_t length)
|
static void st7789_send_data(void * data, uint16_t length)
|
||||||
{
|
{
|
||||||
disp_wait_for_pending_transactions();
|
disp_wait_for_pending_transactions();
|
||||||
gpio_set_level(ST7789_DC, 1);
|
gpio_set_level(ST7789_DC, 1);
|
||||||
disp_spi_send_data(data, length);
|
disp_spi_send_data(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void st7789_send_color(void * data, size_t length)
|
static void st7789_send_color(void * data, uint16_t length)
|
||||||
{
|
{
|
||||||
disp_wait_for_pending_transactions();
|
disp_wait_for_pending_transactions();
|
||||||
gpio_set_level(ST7789_DC, 1);
|
gpio_set_level(ST7789_DC, 1);
|
||||||
|
|
|
@ -23,17 +23,16 @@ extern "C"
|
||||||
|
|
||||||
#define ST7789_DC CONFIG_LV_DISP_PIN_DC
|
#define ST7789_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define ST7789_RST CONFIG_LV_DISP_PIN_RST
|
#define ST7789_RST CONFIG_LV_DISP_PIN_RST
|
||||||
|
#define ST7789_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
|
||||||
#if CONFIG_LV_DISP_USE_RST
|
#define ST7789_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
#if CONFIG_LV_DISP_ST7789_SOFT_RESET
|
|
||||||
#define ST7789_SOFT_RST
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
#endif
|
#define ST7789_BCKL_ACTIVE_LVL 1
|
||||||
#else
|
#else
|
||||||
#define ST7789_SOFT_RST
|
#define ST7789_BCKL_ACTIVE_LVL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ST7789_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
|
||||||
|
|
||||||
/* ST7789 commands */
|
/* ST7789 commands */
|
||||||
#define ST7789_NOP 0x00
|
#define ST7789_NOP 0x00
|
||||||
#define ST7789_SWRESET 0x01
|
#define ST7789_SWRESET 0x01
|
||||||
|
@ -112,9 +111,7 @@ extern "C"
|
||||||
|
|
||||||
void st7789_init(void);
|
void st7789_init(void);
|
||||||
void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
||||||
|
void st7789_enable_backlight(bool backlight);
|
||||||
void st7789_send_cmd(uint8_t cmd);
|
|
||||||
void st7789_send_data(void *data, uint16_t length);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
@ -81,20 +81,31 @@ void st7796s_init(void)
|
||||||
{0, {0}, 0xff},
|
{0, {0}, 0xff},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if ST7796S_BCKL == 15
|
||||||
|
gpio_config_t io_conf;
|
||||||
|
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
|
||||||
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||||
|
io_conf.pin_bit_mask = GPIO_SEL_15;
|
||||||
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
#endif
|
||||||
|
|
||||||
//Initialize non-SPI GPIOs
|
//Initialize non-SPI GPIOs
|
||||||
gpio_pad_select_gpio(ST7796S_DC);
|
gpio_pad_select_gpio(ST7796S_DC);
|
||||||
gpio_set_direction(ST7796S_DC, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ST7796S_DC, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
#if ST7796S_USE_RST
|
|
||||||
gpio_pad_select_gpio(ST7796S_RST);
|
gpio_pad_select_gpio(ST7796S_RST);
|
||||||
gpio_set_direction(ST7796S_RST, GPIO_MODE_OUTPUT);
|
gpio_set_direction(ST7796S_RST, GPIO_MODE_OUTPUT);
|
||||||
|
|
||||||
|
#if ST7796S_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
gpio_pad_select_gpio(ST7796S_BCKL);
|
||||||
|
gpio_set_direction(ST7796S_BCKL, GPIO_MODE_OUTPUT);
|
||||||
|
#endif
|
||||||
//Reset the display
|
//Reset the display
|
||||||
gpio_set_level(ST7796S_RST, 0);
|
gpio_set_level(ST7796S_RST, 0);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
gpio_set_level(ST7796S_RST, 1);
|
gpio_set_level(ST7796S_RST, 1);
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
vTaskDelay(100 / portTICK_RATE_MS);
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initialization.");
|
ESP_LOGI(TAG, "Initialization.");
|
||||||
|
|
||||||
|
@ -111,6 +122,8 @@ void st7796s_init(void)
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st7796s_enable_backlight(true);
|
||||||
|
|
||||||
st7796s_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
st7796s_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
||||||
|
|
||||||
#if ST7796S_INVERT_COLORS == 1
|
#if ST7796S_INVERT_COLORS == 1
|
||||||
|
@ -148,6 +161,22 @@ void st7796s_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_
|
||||||
st7796s_send_color((void *)color_map, size * 2);
|
st7796s_send_color((void *)color_map, size * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void st7796s_enable_backlight(bool backlight)
|
||||||
|
{
|
||||||
|
#if ST7796S_ENABLE_BACKLIGHT_CONTROL
|
||||||
|
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
|
||||||
|
uint32_t tmp = 0;
|
||||||
|
|
||||||
|
#if (ST7796S_BCKL_ACTIVE_LVL == 1)
|
||||||
|
tmp = backlight ? 1 : 0;
|
||||||
|
#else
|
||||||
|
tmp = backlight ? 0 : 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gpio_set_level(ST7796S_BCKL, tmp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void st7796s_sleep_in()
|
void st7796s_sleep_in()
|
||||||
{
|
{
|
||||||
uint8_t data[] = {0x08};
|
uint8_t data[] = {0x08};
|
||||||
|
|
|
@ -28,10 +28,17 @@ extern "C"
|
||||||
*********************/
|
*********************/
|
||||||
#define ST7796S_DC CONFIG_LV_DISP_PIN_DC
|
#define ST7796S_DC CONFIG_LV_DISP_PIN_DC
|
||||||
#define ST7796S_RST CONFIG_LV_DISP_PIN_RST
|
#define ST7796S_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define ST7796S_USE_RST CONFIG_LV_DISP_USE_RST
|
#define ST7796S_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
|
|
||||||
|
#define ST7796S_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
|
||||||
#define ST7796S_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
#define ST7796S_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
||||||
#define ST7796S_DISPLAY_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION
|
#define ST7796S_DISPLAY_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION
|
||||||
|
|
||||||
|
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
|
||||||
|
#define ST7796S_BCKL_ACTIVE_LVL 1
|
||||||
|
#else
|
||||||
|
#define ST7796S_BCKL_ACTIVE_LVL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
* ST7796S REGS
|
* ST7796S REGS
|
||||||
|
@ -111,6 +118,7 @@ extern "C"
|
||||||
|
|
||||||
void st7796s_init(void);
|
void st7796s_init(void);
|
||||||
void st7796s_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
void st7796s_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
|
||||||
|
void st7796s_enable_backlight(bool backlight);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
34
lvgl_touch/CMakeLists.txt
Normal file
34
lvgl_touch/CMakeLists.txt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
if(ESP_PLATFORM)
|
||||||
|
|
||||||
|
set(SOURCES "touch_driver.c")
|
||||||
|
|
||||||
|
# Include only the source file of the selected
|
||||||
|
# display controller.
|
||||||
|
if(CONFIG_LV_TOUCH_CONTROLLER_XPT2046)
|
||||||
|
list(APPEND SOURCES "xpt2046.c")
|
||||||
|
elseif(CONFIG_LV_TOUCH_CONTROLLER_FT6X06)
|
||||||
|
list(APPEND SOURCES "ft6x36.c")
|
||||||
|
elseif(CONFIG_LV_TOUCH_CONTROLLER_STMPE610)
|
||||||
|
list(APPEND SOURCES "stmpe610")
|
||||||
|
elseif(CONFIG_LV_TOUCH_CONTROLLER_ADCRAW)
|
||||||
|
list(APPEND SOURCES "adcraw.c")
|
||||||
|
elseif(CONFIG_LV_TOUCH_CONTROLLER_FT81X)
|
||||||
|
list(APPEND SOURCES "FT81x.c")
|
||||||
|
elseif(CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
||||||
|
list(APPEND SOURCES "ra8875_touch.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)
|
||||||
|
list(APPEND SOURCES "tp_spi.c")
|
||||||
|
elseif(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)
|
||||||
|
list(APPEND SOURCES "tp_i2c.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Print the included source files
|
||||||
|
message("SOURCES contents: " "${SOURCES}")
|
||||||
|
|
||||||
|
idf_component_register(SRCS ${SOURCES}
|
||||||
|
INCLUDE_DIRS .
|
||||||
|
REQUIRES lvgl)
|
||||||
|
|
||||||
|
endif()
|
|
@ -9,7 +9,6 @@ menu "LVGL Touch controller"
|
||||||
default 4 if LV_TOUCH_CONTROLLER_ADCRAW
|
default 4 if LV_TOUCH_CONTROLLER_ADCRAW
|
||||||
default 5 if LV_TOUCH_CONTROLLER_FT81X
|
default 5 if LV_TOUCH_CONTROLLER_FT81X
|
||||||
default 6 if LV_TOUCH_CONTROLLER_RA8875
|
default 6 if LV_TOUCH_CONTROLLER_RA8875
|
||||||
default 7 if LV_TOUCH_CONTROLLER_GT911
|
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "Select a touch panel controller model."
|
prompt "Select a touch panel controller model."
|
||||||
|
@ -23,7 +22,7 @@ menu "LVGL Touch controller"
|
||||||
select LV_TOUCH_DRIVER_PROTOCOL_SPI
|
select LV_TOUCH_DRIVER_PROTOCOL_SPI
|
||||||
bool "XPT2046"
|
bool "XPT2046"
|
||||||
config LV_TOUCH_CONTROLLER_FT6X06
|
config LV_TOUCH_CONTROLLER_FT6X06
|
||||||
select LV_I2C_TOUCH
|
select LV_TOUCH_DRIVER_PROTOCOL_I2C
|
||||||
bool "FT6X06"
|
bool "FT6X06"
|
||||||
config LV_TOUCH_CONTROLLER_STMPE610
|
config LV_TOUCH_CONTROLLER_STMPE610
|
||||||
select LV_TOUCH_DRIVER_PROTOCOL_SPI
|
select LV_TOUCH_DRIVER_PROTOCOL_SPI
|
||||||
|
@ -37,9 +36,6 @@ menu "LVGL Touch controller"
|
||||||
config LV_TOUCH_CONTROLLER_RA8875
|
config LV_TOUCH_CONTROLLER_RA8875
|
||||||
select LV_TOUCH_DRIVER_DISPLAY
|
select LV_TOUCH_DRIVER_DISPLAY
|
||||||
bool "RA8875"
|
bool "RA8875"
|
||||||
config LV_TOUCH_CONTROLLER_GT911
|
|
||||||
select LV_I2C_TOUCH
|
|
||||||
bool "GT911"
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config LV_TOUCH_DRIVER_PROTOCOL_SPI
|
config LV_TOUCH_DRIVER_PROTOCOL_SPI
|
||||||
|
@ -47,7 +43,7 @@ menu "LVGL Touch controller"
|
||||||
help
|
help
|
||||||
Touch controller protocol SPI
|
Touch controller protocol SPI
|
||||||
|
|
||||||
config LV_I2C_TOUCH
|
config LV_TOUCH_DRIVER_PROTOCOL_I2C
|
||||||
bool
|
bool
|
||||||
help
|
help
|
||||||
Touch controller protocol I2C
|
Touch controller protocol I2C
|
||||||
|
@ -63,18 +59,35 @@ menu "LVGL Touch controller"
|
||||||
Touch controller uses same interface/device as display
|
Touch controller uses same interface/device as display
|
||||||
(Note: Display must be initialized before touch)
|
(Note: Display must be initialized before touch)
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "Touch I2C port"
|
||||||
|
depends on LV_TOUCH_DRIVER_PROTOCOL_I2C
|
||||||
|
|
||||||
|
default LV_TOUCH_I2C_PORT_0
|
||||||
|
help
|
||||||
|
Select the I2C port used by the touch controller.
|
||||||
|
|
||||||
|
config LV_TOUCH_I2C_PORT_0
|
||||||
|
bool "I2C PORT 0"
|
||||||
|
config LV_TOUCH_I2C_PORT_1
|
||||||
|
bool "I2C PORT 1"
|
||||||
|
endchoice
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "Touch Controller SPI Bus."
|
prompt "Touch Controller SPI Bus."
|
||||||
depends on LV_TOUCH_DRIVER_PROTOCOL_SPI
|
depends on LV_TOUCH_DRIVER_PROTOCOL_SPI
|
||||||
|
|
||||||
default LV_TOUCH_CONTROLLER_SPI2_HOST
|
default LV_TOUCH_CONTROLLER_SPI_VSPI if !IDF_TARGET_ESP32S2
|
||||||
|
default LV_TOUCH_CONTROLLER_SPI_FSPI if IDF_TARGET_ESP32S2
|
||||||
help
|
help
|
||||||
Select the SPI Bus the touch controller is attached to.
|
Select the SPI Bus the TFT Display is attached to.
|
||||||
|
|
||||||
config LV_TOUCH_CONTROLLER_SPI2_HOST
|
config LV_TOUCH_CONTROLLER_SPI_HSPI
|
||||||
bool "SPI2_HOST"
|
bool "HSPI"
|
||||||
config LV_TOUCH_CONTROLLER_SPI3_HOST
|
config LV_TOUCH_CONTROLLER_SPI_VSPI
|
||||||
bool "SPI3_HOST"
|
bool "VSPI" if !IDF_TARGET_ESP32S2
|
||||||
|
config LV_TOUCH_CONTROLLER_SPI_FSPI
|
||||||
|
bool "FSPI" if IDF_TARGET_ESP32S2
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
menu "Touchpanel (XPT2046) Pin Assignments"
|
menu "Touchpanel (XPT2046) Pin Assignments"
|
||||||
|
@ -83,7 +96,7 @@ menu "LVGL Touch controller"
|
||||||
config LV_TOUCH_SPI_MISO
|
config LV_TOUCH_SPI_MISO
|
||||||
int
|
int
|
||||||
prompt "GPIO for MISO (Master In Slave Out)"
|
prompt "GPIO for MISO (Master In Slave Out)"
|
||||||
|
range 0 39
|
||||||
default 35 if LV_PREDEFINED_PINS_38V1
|
default 35 if LV_PREDEFINED_PINS_38V1
|
||||||
default 19
|
default 19
|
||||||
help
|
help
|
||||||
|
@ -92,7 +105,7 @@ menu "LVGL Touch controller"
|
||||||
config LV_TOUCH_SPI_MOSI
|
config LV_TOUCH_SPI_MOSI
|
||||||
int
|
int
|
||||||
prompt "GPIO for MOSI (Master Out Slave In)"
|
prompt "GPIO for MOSI (Master Out Slave In)"
|
||||||
|
range 0 39
|
||||||
default 32 if LV_PREDEFINED_PINS_38V1
|
default 32 if LV_PREDEFINED_PINS_38V1
|
||||||
default 23
|
default 23
|
||||||
help
|
help
|
||||||
|
@ -100,7 +113,7 @@ menu "LVGL Touch controller"
|
||||||
|
|
||||||
config LV_TOUCH_SPI_CLK
|
config LV_TOUCH_SPI_CLK
|
||||||
int "GPIO for CLK (SCK / Serial Clock)"
|
int "GPIO for CLK (SCK / Serial Clock)"
|
||||||
|
range 0 39
|
||||||
default 26 if LV_PREDEFINED_PINS_38V1
|
default 26 if LV_PREDEFINED_PINS_38V1
|
||||||
default 18
|
default 18
|
||||||
help
|
help
|
||||||
|
@ -108,7 +121,7 @@ menu "LVGL Touch controller"
|
||||||
|
|
||||||
config LV_TOUCH_SPI_CS
|
config LV_TOUCH_SPI_CS
|
||||||
int "GPIO for CS (Slave Select)"
|
int "GPIO for CS (Slave Select)"
|
||||||
|
range 0 39
|
||||||
default 33 if LV_PREDEFINED_PINS_38V1
|
default 33 if LV_PREDEFINED_PINS_38V1
|
||||||
default 5
|
default 5
|
||||||
help
|
help
|
||||||
|
@ -116,7 +129,7 @@ menu "LVGL Touch controller"
|
||||||
|
|
||||||
config LV_TOUCH_PIN_IRQ
|
config LV_TOUCH_PIN_IRQ
|
||||||
int "GPIO for IRQ (Interrupt Request)"
|
int "GPIO for IRQ (Interrupt Request)"
|
||||||
|
range 0 39
|
||||||
default 27 if LV_PREDEFINED_PINS_38V4
|
default 27 if LV_PREDEFINED_PINS_38V4
|
||||||
default 25
|
default 25
|
||||||
help
|
help
|
||||||
|
@ -180,13 +193,32 @@ menu "LVGL Touch controller"
|
||||||
endchoice
|
endchoice
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
menu "Touchpanel (FT6X06) Pin Assignments"
|
||||||
|
depends on LV_TOUCH_CONTROLLER_FT6X06
|
||||||
|
|
||||||
|
config LV_TOUCH_I2C_SDA
|
||||||
|
int
|
||||||
|
prompt "GPIO for SDA (I2C)"
|
||||||
|
range 0 39
|
||||||
|
default 21
|
||||||
|
help
|
||||||
|
Configure the I2C touchpanel SDA pin here.
|
||||||
|
|
||||||
|
config LV_TOUCH_I2C_SCL
|
||||||
|
int "GPIO for clock signal SCL (I2C)"
|
||||||
|
range 0 39
|
||||||
|
default 22
|
||||||
|
help
|
||||||
|
Configure the I2C touchpanel SCL pin here.
|
||||||
|
endmenu
|
||||||
|
|
||||||
menu "Touchpanel Configuration (FT6X06)"
|
menu "Touchpanel Configuration (FT6X06)"
|
||||||
depends on LV_TOUCH_CONTROLLER_FT6X06
|
depends on LV_TOUCH_CONTROLLER_FT6X06
|
||||||
|
|
||||||
config LV_FT6X36_SWAPXY
|
config LV_FT6X36_SWAPXY
|
||||||
bool
|
bool
|
||||||
prompt "Swap X with Y coordinate."
|
prompt "Swap X with Y coordinate."
|
||||||
default n
|
default y
|
||||||
|
|
||||||
config LV_FT6X36_INVERT_X
|
config LV_FT6X36_INVERT_X
|
||||||
bool
|
bool
|
||||||
|
@ -196,14 +228,7 @@ menu "LVGL Touch controller"
|
||||||
config LV_FT6X36_INVERT_Y
|
config LV_FT6X36_INVERT_Y
|
||||||
bool
|
bool
|
||||||
prompt "Invert Y coordinate value."
|
prompt "Invert Y coordinate value."
|
||||||
default n
|
default y
|
||||||
|
|
||||||
config LV_FT6X36_COORDINATES_QUEUE
|
|
||||||
bool
|
|
||||||
prompt "Send coordinates to FreeRTOS queue."
|
|
||||||
default n
|
|
||||||
help
|
|
||||||
Receive from the FreeRTOS queue using the handle 'ft6x36_touch_queue_handle'.
|
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
@ -213,7 +238,7 @@ menu "LVGL Touch controller"
|
||||||
config LV_TOUCH_SPI_MISO
|
config LV_TOUCH_SPI_MISO
|
||||||
int
|
int
|
||||||
prompt "GPIO for MISO (Master In Slave Out)"
|
prompt "GPIO for MISO (Master In Slave Out)"
|
||||||
|
range 0 39
|
||||||
default 35 if LV_PREDEFINED_PINS_38V1
|
default 35 if LV_PREDEFINED_PINS_38V1
|
||||||
default 19 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
default 19 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
||||||
default 19
|
default 19
|
||||||
|
@ -222,10 +247,9 @@ menu "LVGL Touch controller"
|
||||||
Configure the touchpanel MISO pin here.
|
Configure the touchpanel MISO pin here.
|
||||||
|
|
||||||
config LV_TOUCH_SPI_MOSI
|
config LV_TOUCH_SPI_MOSI
|
||||||
# TODO Fix default for ESP32C3
|
|
||||||
int
|
int
|
||||||
prompt "GPIO for MOSI (Master Out Slave In)"
|
prompt "GPIO for MOSI (Master Out Slave In)"
|
||||||
|
range 0 39
|
||||||
default 32 if LV_PREDEFINED_PINS_38V1
|
default 32 if LV_PREDEFINED_PINS_38V1
|
||||||
default 18 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
default 18 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
||||||
default 23
|
default 23
|
||||||
|
@ -235,7 +259,7 @@ menu "LVGL Touch controller"
|
||||||
|
|
||||||
config LV_TOUCH_SPI_CLK
|
config LV_TOUCH_SPI_CLK
|
||||||
int "GPIO for CLK (SCK / Serial Clock)"
|
int "GPIO for CLK (SCK / Serial Clock)"
|
||||||
|
range 0 39
|
||||||
default 26 if LV_PREDEFINED_PINS_38V1
|
default 26 if LV_PREDEFINED_PINS_38V1
|
||||||
default 5 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
default 5 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
||||||
default 18
|
default 18
|
||||||
|
@ -244,6 +268,7 @@ menu "LVGL Touch controller"
|
||||||
|
|
||||||
config LV_TOUCH_SPI_CS
|
config LV_TOUCH_SPI_CS
|
||||||
int "GPIO for CS (Slave Select)"
|
int "GPIO for CS (Slave Select)"
|
||||||
|
range 0 39
|
||||||
default 33 if LV_PREDEFINED_PINS_38V1
|
default 33 if LV_PREDEFINED_PINS_38V1
|
||||||
default 32 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
default 32 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
|
||||||
default 5
|
default 5
|
||||||
|
@ -441,57 +466,4 @@ menu "LVGL Touch controller"
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Touchpanel Configuration (GT911)"
|
|
||||||
depends on LV_TOUCH_CONTROLLER_GT911
|
|
||||||
|
|
||||||
config LV_GT911_SWAPXY
|
|
||||||
bool
|
|
||||||
prompt "Swap X with Y coordinate."
|
|
||||||
default y
|
|
||||||
|
|
||||||
config LV_GT911_INVERT_X
|
|
||||||
bool
|
|
||||||
prompt "Invert X coordinate value."
|
|
||||||
default n
|
|
||||||
|
|
||||||
config LV_GT911_INVERT_Y
|
|
||||||
bool
|
|
||||||
prompt "Invert Y coordinate value."
|
|
||||||
default y
|
|
||||||
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
choice
|
|
||||||
prompt "Select an I2C port for the touch panel"
|
|
||||||
default LV_I2C_TOUCH_PORT_0
|
|
||||||
depends on LV_I2C_TOUCH
|
|
||||||
|
|
||||||
config LV_I2C_TOUCH_PORT_0
|
|
||||||
bool
|
|
||||||
prompt "I2C port 0"
|
|
||||||
help
|
|
||||||
I2C is shared peripheral managed by I2C Manager. In order to configure I2C Manager (pinout, etc.) see menu
|
|
||||||
Component config->I2C Port Settings.
|
|
||||||
|
|
||||||
config LV_I2C_TOUCH_PORT_1
|
|
||||||
bool
|
|
||||||
prompt "I2C port 1"
|
|
||||||
help
|
|
||||||
I2C is shared peripheral managed by I2C Manager. In order to configure I2C Manager (pinout, etc.) see menu
|
|
||||||
Component config->I2C Port Settings.
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config LV_I2C
|
|
||||||
bool
|
|
||||||
default y if LV_I2C_TOUCH
|
|
||||||
|
|
||||||
config LV_I2C_TOUCH_PORT
|
|
||||||
int
|
|
||||||
default 1 if LV_I2C_TOUCH_PORT_1
|
|
||||||
default 0
|
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
4
lvgl_touch/component.mk
Normal file
4
lvgl_touch/component.mk
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Touch drivers
|
||||||
|
|
||||||
|
COMPONENT_SRCDIRS := .
|
||||||
|
COMPONENT_ADD_INCLUDEDIRS := .
|
|
@ -19,27 +19,37 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
#include <driver/i2c.h>
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
#else
|
#else
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
#endif
|
#endif
|
||||||
#include "ft6x36.h"
|
#include "ft6x36.h"
|
||||||
#include "lvgl_i2c/i2c_manager.h"
|
#include "tp_i2c.h"
|
||||||
|
#include "../lvgl_i2c_conf.h"
|
||||||
|
|
||||||
#define TAG "FT6X36"
|
#define TAG "FT6X36"
|
||||||
#define FT6X36_TOUCH_QUEUE_ELEMENTS 1
|
|
||||||
|
|
||||||
|
|
||||||
static ft6x36_status_t ft6x36_status;
|
ft6x36_status_t ft6x36_status;
|
||||||
static uint8_t current_dev_addr; // set during init
|
uint8_t current_dev_addr; // set during init
|
||||||
static ft6x36_touch_t touch_inputs = { -1, -1, LV_INDEV_STATE_REL }; // -1 coordinates to designate it was never touched
|
|
||||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
|
||||||
QueueHandle_t ft6x36_touch_queue_handle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf) {
|
esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf) {
|
||||||
return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr, data_buf, 1);
|
i2c_cmd_handle_t i2c_cmd = i2c_cmd_link_create();
|
||||||
|
|
||||||
|
i2c_master_start(i2c_cmd);
|
||||||
|
i2c_master_write_byte(i2c_cmd, (slave_addr << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
i2c_master_write_byte(i2c_cmd, register_addr, I2C_MASTER_ACK);
|
||||||
|
|
||||||
|
i2c_master_start(i2c_cmd);
|
||||||
|
i2c_master_write_byte(i2c_cmd, (slave_addr << 1) | I2C_MASTER_READ, true);
|
||||||
|
|
||||||
|
i2c_master_read_byte(i2c_cmd, data_buf, I2C_MASTER_NACK);
|
||||||
|
i2c_master_stop(i2c_cmd);
|
||||||
|
esp_err_t ret = i2c_master_cmd_begin(TOUCH_I2C_PORT, i2c_cmd, 1000 / portTICK_RATE_MS);
|
||||||
|
i2c_cmd_link_delete(i2c_cmd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +75,19 @@ uint8_t ft6x36_get_gesture_id() {
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void ft6x06_init(uint16_t dev_addr) {
|
void ft6x06_init(uint16_t dev_addr) {
|
||||||
|
if (!ft6x36_status.inited) {
|
||||||
|
|
||||||
|
/* I2C master is initialized before calling this function */
|
||||||
|
#if 0
|
||||||
|
esp_err_t code = i2c_master_init();
|
||||||
|
#else
|
||||||
|
esp_err_t code = ESP_OK;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (code != ESP_OK) {
|
||||||
|
ft6x36_status.inited = false;
|
||||||
|
ESP_LOGE(TAG, "Error during I2C init %s", esp_err_to_name(code));
|
||||||
|
} else {
|
||||||
ft6x36_status.inited = true;
|
ft6x36_status.inited = true;
|
||||||
current_dev_addr = dev_addr;
|
current_dev_addr = dev_addr;
|
||||||
uint8_t data_buf;
|
uint8_t data_buf;
|
||||||
|
@ -87,16 +109,8 @@ void ft6x06_init(uint16_t dev_addr) {
|
||||||
|
|
||||||
ft6x06_i2c_read8(dev_addr, FT6X36_RELEASECODE_REG, &data_buf);
|
ft6x06_i2c_read8(dev_addr, FT6X36_RELEASECODE_REG, &data_buf);
|
||||||
ESP_LOGI(TAG, "\tRelease code: 0x%02x", data_buf);
|
ESP_LOGI(TAG, "\tRelease code: 0x%02x", data_buf);
|
||||||
|
|
||||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
|
||||||
ft6x36_touch_queue_handle = xQueueCreate( FT6X36_TOUCH_QUEUE_ELEMENTS, sizeof( ft6x36_touch_t ) );
|
|
||||||
if( ft6x36_touch_queue_handle == NULL )
|
|
||||||
{
|
|
||||||
ESP_LOGE( TAG, "\tError creating touch input FreeRTOS queue" );
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
xQueueSend( ft6x36_touch_queue_handle, &touch_inputs, 0 );
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,55 +120,82 @@ void ft6x06_init(uint16_t dev_addr) {
|
||||||
* @retval Always false
|
* @retval Always false
|
||||||
*/
|
*/
|
||||||
bool ft6x36_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
bool ft6x36_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
||||||
if (!ft6x36_status.inited) {
|
uint8_t data_xy[4]; // 2 bytes X | 2 bytes Y
|
||||||
ESP_LOGE(TAG, "Init first!");
|
uint8_t touch_pnt_cnt; // Number of detected touch points
|
||||||
return 0x00;
|
static int16_t last_x = 0; // 12bit pixel value
|
||||||
}
|
static int16_t last_y = 0; // 12bit pixel value
|
||||||
uint8_t data_buf[5]; // 1 byte status, 2 bytes X, 2 bytes Y
|
|
||||||
|
|
||||||
esp_err_t ret = lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, current_dev_addr, FT6X36_TD_STAT_REG, &data_buf[0], 5);
|
ft6x06_i2c_read8(current_dev_addr, FT6X36_TD_STAT_REG, &touch_pnt_cnt);
|
||||||
if (ret != ESP_OK) {
|
if (touch_pnt_cnt != 1) { // ignore no touch & multi touch
|
||||||
ESP_LOGE(TAG, "Error talking to touch IC: %s", esp_err_to_name(ret));
|
data->point.x = last_x;
|
||||||
}
|
data->point.y = last_y;
|
||||||
uint8_t touch_pnt_cnt = data_buf[0]; // Number of detected touch points
|
data->state = LV_INDEV_STATE_REL;
|
||||||
|
|
||||||
if (ret != ESP_OK || touch_pnt_cnt != 1) { // ignore no touch & multi touch
|
|
||||||
if ( touch_inputs.current_state != LV_INDEV_STATE_REL)
|
|
||||||
{
|
|
||||||
touch_inputs.current_state = LV_INDEV_STATE_REL;
|
|
||||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
|
||||||
xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
data->point.x = touch_inputs.last_x;
|
|
||||||
data->point.y = touch_inputs.last_y;
|
|
||||||
data->state = touch_inputs.current_state;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
touch_inputs.current_state = LV_INDEV_STATE_PR;
|
// Read X value
|
||||||
touch_inputs.last_x = ((data_buf[1] & FT6X36_MSB_MASK) << 8) | (data_buf[2] & FT6X36_LSB_MASK);
|
i2c_cmd_handle_t i2c_cmd = i2c_cmd_link_create();
|
||||||
touch_inputs.last_y = ((data_buf[3] & FT6X36_MSB_MASK) << 8) | (data_buf[4] & FT6X36_LSB_MASK);
|
|
||||||
|
i2c_master_start(i2c_cmd);
|
||||||
|
i2c_master_write_byte(i2c_cmd, (current_dev_addr << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
i2c_master_write_byte(i2c_cmd, FT6X36_P1_XH_REG, I2C_MASTER_ACK);
|
||||||
|
|
||||||
|
i2c_master_start(i2c_cmd);
|
||||||
|
i2c_master_write_byte(i2c_cmd, (current_dev_addr << 1) | I2C_MASTER_READ, true);
|
||||||
|
|
||||||
|
i2c_master_read_byte(i2c_cmd, &data_xy[0], I2C_MASTER_ACK); // reads FT6X36_P1_XH_REG
|
||||||
|
i2c_master_read_byte(i2c_cmd, &data_xy[1], I2C_MASTER_NACK); // reads FT6X36_P1_XL_REG
|
||||||
|
i2c_master_stop(i2c_cmd);
|
||||||
|
esp_err_t ret = i2c_master_cmd_begin(TOUCH_I2C_PORT, i2c_cmd, 1000 / portTICK_RATE_MS);
|
||||||
|
i2c_cmd_link_delete(i2c_cmd);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Error getting X coordinates: %s", esp_err_to_name(ret));
|
||||||
|
data->point.x = last_x;
|
||||||
|
data->point.y = last_y;
|
||||||
|
data->state = LV_INDEV_STATE_REL; // no touch detected
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read Y value
|
||||||
|
i2c_cmd = i2c_cmd_link_create();
|
||||||
|
|
||||||
|
i2c_master_start(i2c_cmd);
|
||||||
|
i2c_master_write_byte(i2c_cmd, (current_dev_addr << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
i2c_master_write_byte(i2c_cmd, FT6X36_P1_YH_REG, I2C_MASTER_ACK);
|
||||||
|
|
||||||
|
i2c_master_start(i2c_cmd);
|
||||||
|
i2c_master_write_byte(i2c_cmd, (current_dev_addr << 1) | I2C_MASTER_READ, true);
|
||||||
|
|
||||||
|
i2c_master_read_byte(i2c_cmd, &data_xy[2], I2C_MASTER_ACK); // reads FT6X36_P1_YH_REG
|
||||||
|
i2c_master_read_byte(i2c_cmd, &data_xy[3], I2C_MASTER_NACK); // reads FT6X36_P1_YL_REG
|
||||||
|
i2c_master_stop(i2c_cmd);
|
||||||
|
ret = i2c_master_cmd_begin(TOUCH_I2C_PORT, i2c_cmd, 1000 / portTICK_RATE_MS);
|
||||||
|
i2c_cmd_link_delete(i2c_cmd);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Error getting Y coordinates: %s", esp_err_to_name(ret));
|
||||||
|
data->point.x = last_x;
|
||||||
|
data->point.y = last_y;
|
||||||
|
data->state = LV_INDEV_STATE_REL; // no touch detected
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
last_x = ((data_xy[0] & FT6X36_MSB_MASK) << 8) | (data_xy[1] & FT6X36_LSB_MASK);
|
||||||
|
last_y = ((data_xy[2] & FT6X36_MSB_MASK) << 8) | (data_xy[3] & FT6X36_LSB_MASK);
|
||||||
|
|
||||||
#if CONFIG_LV_FT6X36_SWAPXY
|
#if CONFIG_LV_FT6X36_SWAPXY
|
||||||
int16_t swap_buf = touch_inputs.last_x;
|
int16_t swap_buf = last_x;
|
||||||
touch_inputs.last_x = touch_inputs.last_y;
|
last_x = last_y;
|
||||||
touch_inputs.last_y = swap_buf;
|
last_y = swap_buf;
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_LV_FT6X36_INVERT_X
|
#if CONFIG_LV_FT6X36_INVERT_X
|
||||||
touch_inputs.last_x = LV_HOR_RES - touch_inputs.last_x;
|
last_x = LV_HOR_RES - last_x;
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_LV_FT6X36_INVERT_Y
|
#if CONFIG_LV_FT6X36_INVERT_Y
|
||||||
touch_inputs.last_y = LV_VER_RES - touch_inputs.last_y;
|
last_y = LV_VER_RES - last_y;
|
||||||
#endif
|
#endif
|
||||||
data->point.x = touch_inputs.last_x;
|
data->point.x = last_x;
|
||||||
data->point.y = touch_inputs.last_y;
|
data->point.y = last_y;
|
||||||
data->state = touch_inputs.current_state;
|
data->state = LV_INDEV_STATE_PR;
|
||||||
ESP_LOGD(TAG, "X=%u Y=%u", data->point.x, data->point.y);
|
ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y);
|
||||||
|
|
||||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
|
||||||
xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,6 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/queue.h"
|
|
||||||
#endif
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#else
|
#else
|
||||||
|
@ -149,16 +145,6 @@ typedef struct {
|
||||||
bool inited;
|
bool inited;
|
||||||
} ft6x36_status_t;
|
} ft6x36_status_t;
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int16_t last_x;
|
|
||||||
int16_t last_y;
|
|
||||||
lv_indev_state_t current_state;
|
|
||||||
} ft6x36_touch_t;
|
|
||||||
|
|
||||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
|
||||||
extern QueueHandle_t ft6x36_touch_queue_handle;
|
|
||||||
#endif
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize for FT6x36 communication via I2C
|
* @brief Initialize for FT6x36 communication via I2C
|
||||||
* @param dev_addr: Device address on communication Bus (I2C slave address of FT6X36).
|
* @param dev_addr: Device address on communication Bus (I2C slave address of FT6X36).
|
||||||
|
|
|
@ -1,144 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2021 Sturnus Inc.
|
|
||||||
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
* software and associated documentation files (the “Software”), to deal in the Software
|
|
||||||
* without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
* to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
* substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
||||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <esp_log.h>
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
|
||||||
#include <lvgl.h>
|
|
||||||
#else
|
|
||||||
#include <lvgl/lvgl.h>
|
|
||||||
#endif
|
|
||||||
#include "gt911.h"
|
|
||||||
|
|
||||||
#include "lvgl_i2c/i2c_manager.h"
|
|
||||||
|
|
||||||
#define TAG "GT911"
|
|
||||||
|
|
||||||
gt911_status_t gt911_status;
|
|
||||||
|
|
||||||
//TODO: handle multibyte read and refactor to just one read transaction
|
|
||||||
esp_err_t gt911_i2c_read(uint8_t slave_addr, uint16_t register_addr, uint8_t *data_buf, uint8_t len) {
|
|
||||||
return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, data_buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t gt911_i2c_write8(uint8_t slave_addr, uint16_t register_addr, uint8_t data) {
|
|
||||||
uint8_t buffer = data;
|
|
||||||
return lvgl_i2c_write(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, &buffer, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialize for GT911 communication via I2C
|
|
||||||
* @param dev_addr: Device address on communication Bus (I2C slave address of GT911).
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void gt911_init(uint8_t dev_addr) {
|
|
||||||
if (!gt911_status.inited) {
|
|
||||||
gt911_status.i2c_dev_addr = dev_addr;
|
|
||||||
uint8_t data_buf;
|
|
||||||
esp_err_t ret;
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Checking for GT911 Touch Controller");
|
|
||||||
if ((ret = gt911_i2c_read(dev_addr, GT911_PRODUCT_ID1, &data_buf, 1) != ESP_OK)) {
|
|
||||||
ESP_LOGE(TAG, "Error reading from device: %s",
|
|
||||||
esp_err_to_name(ret)); // Only show error the first time
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read 4 bytes for Product ID in ASCII
|
|
||||||
for (int i = 0; i < GT911_PRODUCT_ID_LEN; i++) {
|
|
||||||
gt911_i2c_read(dev_addr, (GT911_PRODUCT_ID1 + i), (uint8_t *)&(gt911_status.product_id[i]), 1);
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "\tProduct ID: %s", gt911_status.product_id);
|
|
||||||
|
|
||||||
gt911_i2c_read(dev_addr, GT911_VENDOR_ID, &data_buf, 1);
|
|
||||||
ESP_LOGI(TAG, "\tVendor ID: 0x%02x", data_buf);
|
|
||||||
|
|
||||||
gt911_i2c_read(dev_addr, GT911_X_COORD_RES_L, &data_buf, 1);
|
|
||||||
gt911_status.max_x_coord = data_buf;
|
|
||||||
gt911_i2c_read(dev_addr, GT911_X_COORD_RES_H, &data_buf, 1);
|
|
||||||
gt911_status.max_x_coord |= ((uint16_t)data_buf << 8);
|
|
||||||
ESP_LOGI(TAG, "\tX Resolution: %d", gt911_status.max_x_coord);
|
|
||||||
|
|
||||||
gt911_i2c_read(dev_addr, GT911_Y_COORD_RES_L, &data_buf, 1);
|
|
||||||
gt911_status.max_y_coord = data_buf;
|
|
||||||
gt911_i2c_read(dev_addr, GT911_Y_COORD_RES_H, &data_buf, 1);
|
|
||||||
gt911_status.max_y_coord |= ((uint16_t)data_buf << 8);
|
|
||||||
ESP_LOGI(TAG, "\tY Resolution: %d", gt911_status.max_y_coord);
|
|
||||||
gt911_status.inited = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the touch screen X and Y positions values. Ignores multi touch
|
|
||||||
* @param drv:
|
|
||||||
* @param data: Store data here
|
|
||||||
* @retval Always false
|
|
||||||
*/
|
|
||||||
bool gt911_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
|
||||||
uint8_t touch_pnt_cnt; // Number of detected touch points
|
|
||||||
static int16_t last_x = 0; // 12bit pixel value
|
|
||||||
static int16_t last_y = 0; // 12bit pixel value
|
|
||||||
uint8_t data_buf;
|
|
||||||
uint8_t status_reg;
|
|
||||||
|
|
||||||
gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_STATUS_REG, &status_reg, 1);
|
|
||||||
// ESP_LOGI(TAG, "\tstatus: 0x%02x", status_reg);
|
|
||||||
touch_pnt_cnt = status_reg & 0x0F;
|
|
||||||
if ((status_reg & 0x80) || (touch_pnt_cnt < 6)) {
|
|
||||||
//Reset Status Reg Value
|
|
||||||
gt911_i2c_write8(gt911_status.i2c_dev_addr, GT911_STATUS_REG, 0x00);
|
|
||||||
}
|
|
||||||
if (touch_pnt_cnt != 1) { // ignore no touch & multi touch
|
|
||||||
data->point.x = last_x;
|
|
||||||
data->point.y = last_y;
|
|
||||||
data->state = LV_INDEV_STATE_REL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_TRACK_ID1, &data_buf, 1);
|
|
||||||
// ESP_LOGI(TAG, "\ttrack_id: %d", data_buf);
|
|
||||||
|
|
||||||
gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_PT1_X_COORD_L, &data_buf, 1);
|
|
||||||
last_x = data_buf;
|
|
||||||
gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_PT1_X_COORD_H, &data_buf, 1);
|
|
||||||
last_x |= ((uint16_t)data_buf << 8);
|
|
||||||
|
|
||||||
gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_PT1_Y_COORD_L, &data_buf, 1);
|
|
||||||
last_y = data_buf;
|
|
||||||
gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_PT1_Y_COORD_H, &data_buf, 1);
|
|
||||||
last_y |= ((uint16_t)data_buf << 8);
|
|
||||||
|
|
||||||
#if CONFIG_LV_GT911_INVERT_X
|
|
||||||
last_x = gt911_status.max_x_coord - last_x;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_LV_GT911_INVERT_Y
|
|
||||||
last_y = gt911_status.max_y_coord - last_y;
|
|
||||||
#endif
|
|
||||||
#if CONFIG_LV_GT911_SWAPXY
|
|
||||||
int16_t swap_buf = last_x;
|
|
||||||
last_x = last_y;
|
|
||||||
last_y = swap_buf;
|
|
||||||
#endif
|
|
||||||
data->point.x = last_x;
|
|
||||||
data->point.y = last_y;
|
|
||||||
data->state = LV_INDEV_STATE_PR;
|
|
||||||
ESP_LOGI(TAG, "X=%u Y=%u", data->point.x, data->point.y);
|
|
||||||
ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y);
|
|
||||||
return false;
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
#ifndef __GT911_H
|
|
||||||
/*
|
|
||||||
* Copyright © 2021 Sturnus Inc.
|
|
||||||
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
* software and associated documentation files (the “Software”), to deal in the Software
|
|
||||||
* without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
* to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
* substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
||||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define __GT911_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
|
||||||
#include "lvgl.h"
|
|
||||||
#else
|
|
||||||
#include "lvgl/lvgl.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define GT911_I2C_SLAVE_ADDR 0x5D
|
|
||||||
|
|
||||||
#define GT911_PRODUCT_ID_LEN 4
|
|
||||||
|
|
||||||
/* Register Map of GT911 */
|
|
||||||
#define GT911_PRODUCT_ID1 0x8140
|
|
||||||
#define GT911_PRODUCT_ID2 0x8141
|
|
||||||
#define GT911_PRODUCT_ID3 0x8142
|
|
||||||
#define GT911_PRODUCT_ID4 0x8143
|
|
||||||
#define GT911_FIRMWARE_VER_L 0x8144
|
|
||||||
#define GT911_FIRMWARE_VER_H 0x8145
|
|
||||||
#define GT911_X_COORD_RES_L 0x8146
|
|
||||||
#define GT911_X_COORD_RES_H 0x8147
|
|
||||||
#define GT911_Y_COORD_RES_L 0x8148
|
|
||||||
#define GT911_Y_COORD_RES_H 0x8149
|
|
||||||
#define GT911_VENDOR_ID 0x814A
|
|
||||||
|
|
||||||
#define GT911_STATUS_REG 0x814E
|
|
||||||
#define GT911_STATUS_REG_BUF 0x80
|
|
||||||
#define GT911_STATUS_REG_LARGE 0x40
|
|
||||||
#define GT911_STATUS_REG_PROX_VALID 0x20
|
|
||||||
#define GT911_STATUS_REG_HAVEKEY 0x10
|
|
||||||
#define GT911_STATUS_REG_PT_MASK 0x0F
|
|
||||||
|
|
||||||
#define GT911_TRACK_ID1 0x814F
|
|
||||||
#define GT911_PT1_X_COORD_L 0x8150
|
|
||||||
#define GT911_PT1_X_COORD_H 0x8151
|
|
||||||
#define GT911_PT1_Y_COORD_L 0x8152
|
|
||||||
#define GT911_PT1_Y_COORD_H 0x8153
|
|
||||||
#define GT911_PT1_X_SIZE_L 0x8154
|
|
||||||
#define GT911_PT1_X_SIZE_H 0x8155
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool inited;
|
|
||||||
char product_id[GT911_PRODUCT_ID_LEN];
|
|
||||||
uint16_t max_x_coord;
|
|
||||||
uint16_t max_y_coord;
|
|
||||||
uint8_t i2c_dev_addr;
|
|
||||||
} gt911_status_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialize for GT911 communication via I2C
|
|
||||||
* @param dev_addr: Device address on communication Bus (I2C slave address of GT911).
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void gt911_init(uint8_t dev_addr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the touch screen X and Y positions values. Ignores multi touch
|
|
||||||
* @param drv:
|
|
||||||
* @param data: Store data here
|
|
||||||
* @retval Always false
|
|
||||||
*/
|
|
||||||
bool gt911_read(lv_indev_drv_t *drv, lv_indev_data_t *data);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif /* __GT911_H */
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "touch_driver.h"
|
#include "touch_driver.h"
|
||||||
#include "tp_spi.h"
|
#include "tp_spi.h"
|
||||||
|
#include "tp_i2c.h"
|
||||||
|
|
||||||
|
|
||||||
void touch_driver_init(void)
|
void touch_driver_init(void)
|
||||||
|
@ -20,16 +21,10 @@ void touch_driver_init(void)
|
||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
||||||
ra8875_touch_init();
|
ra8875_touch_init();
|
||||||
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911)
|
|
||||||
gt911_init(GT911_I2C_SLAVE_ADDR);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LVGL_VERSION_MAJOR >= 8
|
|
||||||
void touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
|
|
||||||
#else
|
|
||||||
bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
|
bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
|
@ -45,14 +40,8 @@ bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
|
||||||
res = FT81x_read(drv, data);
|
res = FT81x_read(drv, data);
|
||||||
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
||||||
res = ra8875_touch_read(drv, data);
|
res = ra8875_touch_read(drv, data);
|
||||||
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911)
|
|
||||||
res = gt911_read(drv, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LVGL_VERSION_MAJOR >= 8
|
|
||||||
data->continue_reading = res;
|
|
||||||
#else
|
|
||||||
return res;
|
return res;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,6 @@ extern "C" {
|
||||||
#include "FT81x.h"
|
#include "FT81x.h"
|
||||||
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
|
||||||
#include "ra8875_touch.h"
|
#include "ra8875_touch.h"
|
||||||
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911)
|
|
||||||
#include "gt911.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
|
@ -44,12 +42,7 @@ extern "C" {
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
void touch_driver_init(void);
|
void touch_driver_init(void);
|
||||||
|
|
||||||
#if LVGL_VERSION_MAJOR >= 8
|
|
||||||
void touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data);
|
|
||||||
#else
|
|
||||||
bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data);
|
bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
43
lvgl_touch/tp_i2c.c
Normal file
43
lvgl_touch/tp_i2c.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2020 Wolfgang Christl
|
||||||
|
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
* software and associated documentation files (the “Software”), to deal in the Software
|
||||||
|
* without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||||
|
* to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
* substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <driver/i2c.h>
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
#define I2C_MASTER_FREQ_HZ 100000 /* 100kHz*/
|
||||||
|
#define I2C_MASTER_TX_BUF_DISABLE 0 /* I2C master doesn't need buffer */
|
||||||
|
#define I2C_MASTER_RX_BUF_DISABLE 0 /* I2C master doesn't need buffer */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ESP32 I2C init as master
|
||||||
|
* @ret ESP32 error code
|
||||||
|
*/
|
||||||
|
esp_err_t i2c_master_init(void) {
|
||||||
|
int i2c_master_port = I2C_NUM_0;
|
||||||
|
i2c_config_t conf;
|
||||||
|
conf.mode = I2C_MODE_MASTER;
|
||||||
|
conf.sda_io_num = CONFIG_LV_TOUCH_I2C_SDA;
|
||||||
|
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
||||||
|
conf.scl_io_num = CONFIG_LV_TOUCH_I2C_SCL;
|
||||||
|
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
||||||
|
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
|
||||||
|
i2c_param_config(i2c_master_port, &conf);
|
||||||
|
return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
||||||
|
}
|
36
lvgl_touch/tp_i2c.h
Normal file
36
lvgl_touch/tp_i2c.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2020 Wolfgang Christl
|
||||||
|
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
* software and associated documentation files (the “Software”), to deal in the Software
|
||||||
|
* without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||||
|
* to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
* substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TS_H
|
||||||
|
#define __TS_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
esp_err_t i2c_master_init(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __TS_H */
|
Loading…
Reference in a new issue