From c9660bd69f12d12fc1428259d273741fc6d29724 Mon Sep 17 00:00:00 2001 From: martinberlin Date: Sun, 30 May 2021 19:51:59 +0200 Subject: [PATCH] #3 Start adding L58: Find a way to instantiate existing class or refactor it to C --- CMakeLists.txt | 2 ++ lvgl_helpers.c | 8 ++++-- lvgl_touch/Kconfig | 39 +++++++++++++++++++++++++- lvgl_touch/l58.cpp | 55 +++++++++++++++++++++++++++++++++++++ lvgl_touch/l58.h | 58 +++++++++++++++++++++++++++++++++++++++ lvgl_touch/touch_driver.c | 8 +++++- 6 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 lvgl_touch/l58.cpp create mode 100644 lvgl_touch/l58.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ffd2871..bd01af9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,8 @@ if(CONFIG_LV_TOUCH_CONTROLLER) 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_L58) + list(APPEND SOURCES "lvgl_touch/l58.cpp") elseif(CONFIG_LV_TOUCH_CONTROLLER_STMPE610) list(APPEND SOURCES "lvgl_touch/stmpe610.c") elseif(CONFIG_LV_TOUCH_CONTROLLER_ADCRAW) diff --git a/lvgl_helpers.c b/lvgl_helpers.c index dc83c99..b611e9f 100644 --- a/lvgl_helpers.c +++ b/lvgl_helpers.c @@ -147,19 +147,21 @@ void lvgl_driver_init(void) touch_driver_init(); #elif defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C) + // Why initializing this when I said is only CONFIG_LV_TOUCH_DRIVER_DISPLAY 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_I2C_SPEED_HZ); touch_driver_init(); #elif defined (CONFIG_LV_TOUCH_DRIVER_ADC) touch_driver_init(); - #elif defined (CONFIG_LV_TOUCH_DRIVER_DISPLAY) + #elif defined (CONFIG_LV_TOUCH_DRIVER_DISPLAY) || defined (CONFIG_LV_TOUCH_CONTROLLER_L58) touch_driver_init(); #else - #error "No protocol defined for touch controller" + #error "No protocol defined for touch controller" + #endif #else #endif diff --git a/lvgl_touch/Kconfig b/lvgl_touch/Kconfig index edd1dab..ad6f4f3 100644 --- a/lvgl_touch/Kconfig +++ b/lvgl_touch/Kconfig @@ -9,7 +9,7 @@ menu "LVGL Touch controller" default 4 if LV_TOUCH_CONTROLLER_ADCRAW default 5 if LV_TOUCH_CONTROLLER_FT81X default 6 if LV_TOUCH_CONTROLLER_RA8875 - + default 7 if LV_TOUCH_CONTROLLER_L58 choice prompt "Select a touch panel controller model." default LV_TOUCH_CONTROLLER_NONE @@ -24,6 +24,12 @@ menu "LVGL Touch controller" config LV_TOUCH_CONTROLLER_FT6X06 select LV_TOUCH_DRIVER_PROTOCOL_I2C bool "FT6X06" + + config LV_TOUCH_CONTROLLER_L58 + # Start only touch without protocol: + select CONFIG_LV_TOUCH_DRIVER_DISPLAY + bool "L58" + config LV_TOUCH_CONTROLLER_STMPE610 select LV_TOUCH_DRIVER_PROTOCOL_SPI bool "STMPE610" @@ -90,6 +96,37 @@ menu "LVGL Touch controller" bool "FSPI" if IDF_TARGET_ESP32S2 endchoice + menu "Touchpanel (L58) Lilygo Pin Assignments" + depends on LV_TOUCH_CONTROLLER_L58 + + config LV_TOUCH_I2C_SDA + int + prompt "GPIO for SDA (I2C)" + range 0 39 if IDF_TARGET_ESP32 + range 0 43 if IDF_TARGET_ESP32S2 + + default 15 + help + Configure the I2C touchpanel SDA pin here. + + config LV_TOUCH_I2C_SCL + int "GPIO for clock signal SCL (I2C)" + range 0 39 if IDF_TARGET_ESP32 + range 0 43 if IDF_TARGET_ESP32S2 + + default 14 + help + Configure the I2C touchpanel SCL pin here. + config LV_TOUCH_INT + int "GPIO for Interrupt pin (INT)" + range 0 39 if IDF_TARGET_ESP32 + range 0 43 if IDF_TARGET_ESP32S2 + + default 13 + help + Configure the INT Pin (Low on event) + endmenu + menu "Touchpanel (XPT2046) Pin Assignments" depends on LV_TOUCH_CONTROLLER_XPT2046 diff --git a/lvgl_touch/l58.cpp b/lvgl_touch/l58.cpp new file mode 100644 index 0000000..875fe74 --- /dev/null +++ b/lvgl_touch/l58.cpp @@ -0,0 +1,55 @@ +/* +* Copyright © 2020 Martin Fasani +* 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 +#include +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include +#else +#include +#endif +#include "l58.h" +#include "tp_i2c.h" +#include "../lvgl_i2c_conf.h" + +#define TAG "L58" + + + +/** + * @brief Initialize for FT6x36 communication via I2C + * @param dev_addr: Device address on communication Bus (I2C slave address of FT6X36). + * @retval None + */ +void l58_init(uint16_t dev_addr) { + ESP_LOGI(TAG, "l58_init()"); + +} + +/** + * @brief Get the touch screen X and Y positions values. Ignores multi touch + * @param drv: + * @param data: Store data here + * @retval Always false + */ +bool l58_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { + //printf("Touch event %d\n", gpio_get_level(CONFIG_LV_TOUCH_INT)); // Working + + return false; +} diff --git a/lvgl_touch/l58.h b/lvgl_touch/l58.h new file mode 100644 index 0000000..4d5897e --- /dev/null +++ b/lvgl_touch/l58.h @@ -0,0 +1,58 @@ +#ifndef __L58_H +/* +* Copyright © 2020 Martin Fasani. Refectored from original driver in https://github.com/martinberlin/FT6X36-IDF (C++) +* +* 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 __L58_H + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" + +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include "lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialize for FT6x36 communication via I2C + * @param dev_addr: Device address on communication Bus (I2C slave address of FT6X36). + * @retval None + */ +void l58_init(uint16_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 l58_read(lv_indev_drv_t *drv, lv_indev_data_t *data); + +#ifdef __cplusplus +} +#endif +#endif /* __FT6X06_H */ diff --git a/lvgl_touch/touch_driver.c b/lvgl_touch/touch_driver.c index b0aed88..d22c1d6 100644 --- a/lvgl_touch/touch_driver.c +++ b/lvgl_touch/touch_driver.c @@ -5,7 +5,8 @@ #include "touch_driver.h" #include "tp_spi.h" #include "tp_i2c.h" - +// Is not being included in CMakeLists.txt (Research why) +#include "l58.cpp" void touch_driver_init(void) { @@ -13,6 +14,8 @@ void touch_driver_init(void) xpt2046_init(); #elif defined (CONFIG_LV_TOUCH_CONTROLLER_FT6X06) ft6x06_init(FT6236_I2C_SLAVE_ADDR); +#elif defined (CONFIG_LV_TOUCH_CONTROLLER_L58) + // Do nothing for now #elif defined (CONFIG_LV_TOUCH_CONTROLLER_STMPE610) stmpe610_init(); #elif defined (CONFIG_LV_TOUCH_CONTROLLER_ADCRAW) @@ -32,6 +35,9 @@ bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data) res = xpt2046_read(drv, data); #elif defined (CONFIG_LV_TOUCH_CONTROLLER_FT6X06) res = ft6x36_read(drv, data); +#elif defined (CONFIG_LV_TOUCH_CONTROLLER_L58) + res = l58_read(drv, data); + #elif defined (CONFIG_LV_TOUCH_CONTROLLER_STMPE610) res = stmpe610_read(drv, data); #elif defined (CONFIG_LV_TOUCH_CONTROLLER_ADCRAW)