Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop/lvgl 7.11.0 idf 5.0 #225

Open
wants to merge 104 commits into
base: develop/lvgl_7.11.0_idf_5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
b58a41e
Merge pull request #3 from tore-espressif/feature/color-inversion
tore-espressif Feb 12, 2021
2cc9d49
Merge pull request #4 from lvgl/master
tore-espressif Feb 15, 2021
84c9465
Merge pull request #5 from lvgl/master
tore-espressif Mar 2, 2021
82b738e
ili9341: display inversion
tore-espressif Mar 2, 2021
0442ebe
SSD1306: Fix orientation symbol names
C47D Mar 14, 2021
3e1c6f3
Merge pull request #49 from lvgl/fix-ssd1306_orientation
C47D Mar 19, 2021
147cacc
Merge pull request #46 from tore-espressif/fix/wrover-kit-display-inv…
C47D Mar 29, 2021
63cfe0f
Fix contrast and display mode initialisation
Alnef Apr 10, 2021
94c4800
Merge pull request #1 from Alnef/Alnef-patch-ssd1306
Alnef Apr 10, 2021
7b571a7
LV_DISP_USE_RST
ropg Apr 28, 2021
00dd150
Removed white space at EOL, added some EOLs at EOF
ropg Apr 28, 2021
4ba7c76
Added support for M5Core2 screen (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2)
ropg Apr 28, 2021
21f81d1
Support ILI9163c (Sparkfun LCD-15143)
mam-pascal Apr 29, 2021
2390771
ST7789: Expose send_cmd and send_data to the user
C47D May 10, 2021
db51c38
Merge pull request #55 from Alnef/master
C47D May 10, 2021
c3e8f49
Update Kconfig
abraaocsantana May 28, 2021
f4be773
Merge branch 'lvgl:master' into master
ropg Jun 6, 2021
5424362
Merge pull request #58 from ropg/master
kisvegabor Jun 7, 2021
8f4ba03
Merge pull request #63 from abraaocsantana/fix-inverted-colors-gc9a01
C47D Jun 8, 2021
7aef151
Merge pull request #67 from lvgl/st7789_expose_cmd_api
C47D Jun 8, 2021
06e52d6
Merge branch 'master' into ili9163c
C47D Jun 8, 2021
cccb932
Merge pull request #59 from melmdk/ili9163c
C47D Jun 8, 2021
a387e79
Print LV_HOR_RES_MAX and LV_VER_RES_MAX only when using LVGL v7 or below
C47D Jun 8, 2021
8b65d35
Fix path when using LVGL v8
C47D Jun 8, 2021
1af2997
Add support for ESP32C3 SPI hosts
C47D Jun 8, 2021
696b6ff
lvgl_helpers: Set spi dma channel to SPI_DMA_CH_AUTO when using ESP32C3
C47D Jun 11, 2021
d09fd59
Add ESP32C3 support on Kconfig files
C47D Jun 11, 2021
d379a4e
Handle ESP32C3 when using ESP32C3
C47D Jun 11, 2021
f726311
Indev: Add support for GT911 touch driver by @dastarling
C47D Jun 11, 2021
0d32432
touch driver: Add LVGL v8 compatibility
C47D Jun 13, 2021
b9cccc3
Include lv_refr more easily
C47D Jun 16, 2021
a17a77b
st7735s: Added brightness control though LED pin
Rajssss Jun 20, 2021
aff7d1f
Merge pull request #69 from lvgl/feature/esp32c3_support
C47D Jun 21, 2021
b70d2dc
lvgl_helpers: Fix compilation error when using ESP-IDF v4.3 or below
C47D Jun 22, 2021
5d4334a
Created separate component for backlight control
Rajssss Jun 26, 2021
35a005a
esp_lcd_backlight: do not build if not enabled
Rajssss Jun 26, 2021
55dd527
Update KConfig to remove LV_ prefix on orientation checks
jsmestad Jun 26, 2021
19087ae
Remove SPI guard for TTGO configuration
jsmestad Jun 26, 2021
82ba726
Revert lvgl_tft/Kconfig
jsmestad Jun 26, 2021
fb66f45
Merge pull request #78 from jsmestad/patch-1
C47D Jun 27, 2021
613787b
enable the X and Y offset options whith TTGO TDisplay
Jun 27, 2021
7d0bbe8
Merge pull request #80 from abouillot/master
C47D Jun 28, 2021
fa86e1d
Remove & operator when passing display driver to lv_disp_flush_ready
C47D Jul 1, 2021
557679a
Merge pull request #83 from lvgl/fix/disp_driver_pointer
C47D Jul 1, 2021
f32a6f5
FT6X36 touch: fixed axis-swap, Kconfig defaults.
ropg Jul 7, 2021
8f1370d
Merge pull request #84 from ropg/fix_ft6x36
C47D Jul 7, 2021
e521123
Replace allLVGL driver I2C code with I2C Manager
ropg Jul 8, 2021
8f66127
Make it work with v7 and v8
ropg Jul 8, 2021
b3515c4
Merge pull request #86 from ropg/fix_for_v7
C47D Jul 8, 2021
0484387
Things noted by @tore-espressif
ropg Jul 12, 2021
ef76fd1
I2C Manager Kconfig now generic
ropg Jul 12, 2021
6f2ce13
Better LVGL I2C README
ropg Jul 12, 2021
5739934
Fix README render on GitHub
ropg Jul 12, 2021
f7b7c99
timeout duplicate division removed
ropg Jul 12, 2021
2a34dec
typo
ropg Jul 12, 2021
93125f3
another typo
ropg Jul 13, 2021
befa5d0
directory i2c_manager -> lvgl_i2c
ropg Jul 14, 2021
93a4449
Things suggested by @tore-espressif
ropg Jul 14, 2021
a68ce89
Merge pull request #70 from ropg/I2C_Manager
C47D Jul 14, 2021
779bf4e
Remove remaining IDF_TARGET-dependent GPIO ranges.
ropg Jul 15, 2021
4006495
Merge branch 'master' into master
C47D Jul 29, 2021
7a05cb1
Merge pull request #74 from Rajssss/master
C47D Jul 29, 2021
678779c
Merge pull request #89 from ropg/range_remove
C47D Jul 30, 2021
a0e933c
Fix orientation config define
sidwarkd Jul 30, 2021
fa042b0
Carve out backlight control to separate component
tore-espressif Aug 3, 2021
3c4399d
Update TFT drivers for new backligh control
tore-espressif Aug 3, 2021
11c240d
Support IDF version < v4.3
tore-espressif Aug 3, 2021
2d6ea13
Provide README section about backlight control
tore-espressif Aug 4, 2021
1801416
Merge pull request #95 from lvgl/feature/esp_lcd_backlight
tore-espressif Aug 5, 2021
607df9a
Don't call backlight function when backlight is disabled
tore-espressif Aug 11, 2021
5043946
Fix build on idf v4.1 and v4.2
tore-espressif Aug 11, 2021
ee36378
Change config naming for ssd1306 to use LV_ prefix
sidwarkd Aug 13, 2021
171cd53
fix data length overflow
chenghongyao Aug 15, 2021
82583ce
Merge pull request #101 from chenghongyao/fix_data_length_overflow
C47D Aug 17, 2021
6a3e46e
Merge pull request #99 from lvgl/fix/backlight-off
tore-espressif Aug 23, 2021
dd09b4d
Merge pull request #93 from sidwarkd/patch-1
C47D Aug 25, 2021
8862804
FT6X36: Fix coordinates invesion
C47D Sep 29, 2021
4d3f23a
Merge pull request #119 from lvgl/fix/ft6x36_coordinates
C47D Sep 29, 2021
83eba9b
Fixes potential ESP-IDF config editor crash (#115)
ropg Oct 15, 2021
db3d00e
Addresses confusion: I2C manager component install only when others n…
ropg Oct 15, 2021
617e6a4
Merge pull request #132 from ropg/fix_115
C47D Oct 15, 2021
bd445ea
Add touch input values to a FreeRTOS queue
Oct 20, 2021
a56b80b
Add kconfig symbol for optional coordinates queue
Oct 25, 2021
37548ad
Extern the queue handle and add definition in source file. Add macro …
Oct 27, 2021
b674d2d
Merge pull request #136 from rashedtalukder/master
C47D Oct 27, 2021
37a4d3a
Add PCD8544 driver
mringwal Nov 14, 2021
f3f6ba6
Added PCD8544 to readme, addressed PR comments
mringwal Nov 18, 2021
31a5733
Fix SPI configuration for ESP32-C3 and ESP32-S2
arktrin Dec 5, 2021
23ee5be
replace all specific SPI names with SPIx_HOST
arktrin Dec 13, 2021
4afc03a
Merge pull request #145 from arktrin/fix-spi-conf
tore-espressif Dec 14, 2021
22ba416
fix spi names
tore-espressif Dec 16, 2021
02d351f
Merge pull request #151 from lvgl/fix/spi-names
tore-espressif Dec 16, 2021
d44b7e8
Revert "fix spi names"
tore-espressif Dec 17, 2021
762bb35
Merge pull request #152 from lvgl/revert-151-fix/spi-names
tore-espressif Dec 17, 2021
8cbbc29
fix SPI names for touch
arktrin Dec 18, 2021
8d1fbcf
replace hardcoded SPI DMA parameter
arktrin Dec 20, 2021
c4cd524
add offset for 240x135 displays based on ST7789
arktrin Dec 22, 2021
26fe6e7
clarify the 52/53 px offset oddity
arktrin Dec 23, 2021
a73c429
Marge branch 'master' into lvgl_7.11.0_idf_5.0
controlol May 17, 2023
799e2d7
backlight fixup
controlol May 17, 2023
2978b21
REQUIRED driver component
controlol May 17, 2023
f9b9d6e
fix print lines
controlol Aug 2, 2023
ab61a65
portTICK_RATE_MS has been renamed
controlol Aug 2, 2023
2da44d8
automatically select DMA channel
controlol Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

# MacOS
.DS_Store

# ESP-IDF build dir
build

# Kconfig files
sdkconfig
sdkconfig.old
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ if(ESP_PLATFORM)
file(GLOB SOURCES *.c)
set(LVGL_INCLUDE_DIRS . lvgl_tft)
list(APPEND SOURCES "lvgl_tft/disp_driver.c")

#@todo add SimleInclude macro here
list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c")

# Include only the source file of the selected
# display controller.
Expand Down Expand Up @@ -41,6 +40,10 @@ 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")
else()
message(WARNING "LVGL ESP32 drivers: Display controller not defined.")
endif()
Expand Down Expand Up @@ -68,19 +71,23 @@ if(CONFIG_LV_TOUCH_CONTROLLER)
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")
elseif(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)
list(APPEND SOURCES "lvgl_touch/tp_i2c.c")
endif()
endif()

if(CONFIG_LV_I2C)
list(APPEND SOURCES "lvgl_i2c/i2c_manager.c")
endif()

idf_component_register(SRCS ${SOURCES}
INCLUDE_DIRS ${LVGL_INCLUDE_DIRS}
REQUIRES lvgl)
REQUIRES lvgl driver)

target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE")

else()
Expand Down
16 changes: 14 additions & 2 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
rsource "lvgl_tft/Kconfig"
rsource "lvgl_touch/Kconfig"
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 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ For a ready to use ESP32 project take look at the [lv_port_esp32](https://github
- [Supported display controllers](#supported-display-controllers)
- [Supported indev controllers](#supported-indev-controllers)
- [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
swap of RGB565 color on the LVGL configuration menuconfig (it's not handled automatically).
Expand All @@ -17,6 +19,7 @@ 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) |
|---------------------------------------------|------------|------------------------|------------------------------|----------------------------------------|
| ILI9341 | TFT | SPI | 16: RGB565 | Yes |
| ILI9163C | TFT | SPI | 16: RGB565 | Yes |
| ILI9486 | TFT | SPI | 16: RGB565 | Yes |
| ILI9488 | TFT | SPI | 16: RGB565 | No |
| HX8357B/HX8357D | TFT | SPI | 16: RGB565 | Yes |
Expand All @@ -27,15 +30,16 @@ swap of RGB565 color on the LVGL configuration menuconfig (it's not handled auto
| RA8875 | TFT | SPI | 16: RGB565 | Yes |
| SH1107 | Monochrome | SPI | 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 |
| UC8151D/ GoodDisplay GDEW0154M10 DES | e-Paper | SPI | 1: 1byte per pixel | No |
| FitiPower JD79653A/ GoodDisplay GDEW0154M09 | e-Paper | SPI | 1: 1byte per pixel | No |

## Supported indev controllers

- XPT2046
- FT3236
- other FT6X36 or the FT6206 controllers should work as well (not tested)
- FT3236, FT6X36
- FT6206 controllers should work as well (not tested)
- STMPE610
- FT81x (Single, Dual, and Quad SPI)

Expand All @@ -51,6 +55,7 @@ and sets the gpio numbers for the interface.
|---------------------------|-----------------------|-----------|-----------|-----------|
| ESP Wrover Kit v4.1 | ILI9341 | SPI | 240 | 320 |
| M5Stack | ILI9341 | SPI | 240 | 320 |
| M5Stack Core2 | ILI9341 | SPI | 240 | 320 |
| M5Stick | SH1107 | SPI | - | - |
| M5StickC | ST7735S | SPI | 80 | 160 |
| Adafruit 3.5 Featherwing | HX8357 | SPI | 480 | 320 |
Expand All @@ -63,3 +68,27 @@ 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 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)
6 changes: 4 additions & 2 deletions component.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LVGL ESP32 drivers

# Define sources and include dirs
COMPONENT_SRCDIRS := . lvgl_tft lvgl_touch
COMPONENT_SRCDIRS := . lvgl_tft lvgl_touch lvgl_i2c
COMPONENT_ADD_INCLUDEDIRS := .

# LVGL is supposed to be used as a ESP-IDF component
Expand Down Expand Up @@ -44,4 +44,6 @@ $(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CON
$(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)
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)), lvgl_touch/tp_i2c.o)

# I2C Manager
$(call compile_only_if,$(CONFIG_LV_I2C), lvgl_i2c/i2c_manager.o)
131 changes: 38 additions & 93 deletions lvgl_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
#include "lvgl_touch/tp_spi.h"

#include "lvgl_spi_conf.h"
#include "lvgl_i2c_conf.h"

#include "driver/i2c.h"
#include "lvgl_i2c/i2c_manager.h"

#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "src/lv_core/lv_refr.h"
#include "lvgl.h"
#else
#include "lvgl/src/lv_core/lv_refr.h"
#include "lvgl/lvgl.h"
#endif

/*********************
Expand Down Expand Up @@ -53,7 +52,12 @@
/* Interface and driver initialization */
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);
#endif

ESP_LOGI(TAG, "Display buffer size: %d", DISP_BUF_SIZE);

#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
Expand All @@ -63,7 +67,7 @@ void lvgl_driver_init(void)
DISP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
SPI_BUS_MAX_TRANSFER_SZ, 1,
DISP_SPI_IO2, DISP_SPI_IO3);

disp_spi_add_device(TFT_SPI_HOST);
disp_driver_init();

Expand All @@ -81,48 +85,29 @@ void lvgl_driver_init(void)
TP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
SPI_BUS_MAX_TRANSFER_SZ, 1,
-1, -1);

disp_spi_add_device(TFT_SPI_HOST);
tp_spi_add_device(TOUCH_SPI_HOST);

disp_driver_init();
touch_driver_init();

return;
#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 */
#if defined CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI
ESP_LOGI(TAG, "Initializing SPI master for display");

lvgl_spi_driver_init(TFT_SPI_HOST,
DISP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
SPI_BUS_MAX_TRANSFER_SZ, 1,
SPI_BUS_MAX_TRANSFER_SZ, SPI_DMA_CH_AUTO,
DISP_SPI_IO2, DISP_SPI_IO3);

disp_spi_add_device(TFT_SPI_HOST);

disp_driver_init();
#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);

#elif defined (CONFIG_LV_I2C_DISPLAY)
disp_driver_init();
#else
#error "No protocol defined for display controller"
Expand All @@ -132,22 +117,16 @@ void lvgl_driver_init(void)
#if CONFIG_LV_TOUCH_CONTROLLER != TOUCH_CONTROLLER_NONE
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)
ESP_LOGI(TAG, "Initializing SPI master for touch");

lvgl_spi_driver_init(TOUCH_SPI_HOST,
TP_SPI_MISO, TP_SPI_MOSI, TP_SPI_CLK,
0 /* Defaults to 4094 */, 2,
-1, -1);

tp_spi_add_device(TOUCH_SPI_HOST);

touch_driver_init();
#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);

#elif defined (CONFIG_LV_I2C_TOUCH)
touch_driver_init();
#elif defined (CONFIG_LV_TOUCH_DRIVER_ADC)
touch_driver_init();
Expand All @@ -160,81 +139,47 @@ void lvgl_driver_init(void)
#endif
}

/* Config the i2c master

/* Initialize spi bus master
*
* This should init the i2c master to be used on display and touch controllers.
* So we should be able to know if the display and touch controllers shares the
* same i2c master.
* NOTE: dma_chan type and value changed to int instead of spi_dma_chan_t
* for backwards compatibility with ESP-IDF versions prior v4.3.
*
* 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,
int miso_pin, int mosi_pin, int sclk_pin,
int max_transfer_sz,
int dma_channel,
int quadwp_pin, int quadhd_pin)
{
#if defined (CONFIG_IDF_TARGET_ESP32)
assert((SPI_HOST <= host) && (VSPI_HOST >= host));
const char *spi_names[] = {
"SPI_HOST", "HSPI_HOST", "VSPI_HOST"
};
#elif defined (CONFIG_IDF_TARGET_ESP32S2)
assert((SPI_HOST <= host) && (HSPI_HOST >= host));
assert((0 <= host) && (SPI_HOST_MAX > host));
const char *spi_names[] = {
"SPI_HOST", "", ""
"SPI1_HOST", "SPI2_HOST", "SPI3_HOST"
};
#endif

ESP_LOGI(TAG, "Configuring SPI host %s (%d)", spi_names[host], host);
ESP_LOGI(TAG, "Configuring SPI host %s", spi_names[host]);
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);

ESP_LOGI(TAG, "Max transfer size: %d (bytes)", max_transfer_sz);

spi_bus_config_t buscfg = {
.miso_io_num = miso_pin,
.mosi_io_num = mosi_pin,
.sclk_io_num = sclk_pin,
.quadwp_io_num = quadwp_pin,
.quadhd_io_num = quadhd_pin,
.mosi_io_num = mosi_pin,
.sclk_io_num = sclk_pin,
.quadwp_io_num = quadwp_pin,
.quadhd_io_num = quadhd_pin,
.max_transfer_sz = max_transfer_sz
};

ESP_LOGI(TAG, "Initializing SPI bus...");
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_channel);
#if defined (CONFIG_IDF_TARGET_ESP32C3)
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);

return ESP_OK != ret;
}

Loading