Replace allLVGL driver I2C code with I2C Manager

For discussion see #70
This commit is contained in:
Rop Gonggrijp 2021-07-08 11:04:07 +02:00
parent 8f1370d1c4
commit e52112376f
24 changed files with 896 additions and 679 deletions

View file

@ -23,7 +23,7 @@ menu "LVGL Touch controller"
select LV_TOUCH_DRIVER_PROTOCOL_SPI
bool "XPT2046"
config LV_TOUCH_CONTROLLER_FT6X06
select LV_TOUCH_DRIVER_PROTOCOL_I2C
select LV_I2C_TOUCH
bool "FT6X06"
config LV_TOUCH_CONTROLLER_STMPE610
select LV_TOUCH_DRIVER_PROTOCOL_SPI
@ -38,16 +38,16 @@ menu "LVGL Touch controller"
select LV_TOUCH_DRIVER_DISPLAY
bool "RA8875"
config LV_TOUCH_CONTROLLER_GT911
select LV_TOUCH_DRIVER_PROTOCOL_I2C
select LV_I2C_TOUCH
bool "GT911"
endchoice
config LV_TOUCH_DRIVER_PROTOCOL_SPI
bool
help
Touch controller protocol SPI
config LV_TOUCH_DRIVER_PROTOCOL_I2C
config LV_I2C_TOUCH
bool
help
Touch controller protocol I2C
@ -62,30 +62,16 @@ menu "LVGL Touch controller"
help
Touch controller uses same interface/device as display
(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
prompt "Touch Controller SPI Bus."
depends on LV_TOUCH_DRIVER_PROTOCOL_SPI
default LV_TOUCH_CONTROLLER_SPI_VSPI if !IDF_TARGET_ESP32S2
default LV_TOUCH_CONTROLLER_SPI_FSPI if IDF_TARGET_ESP32S2
help
Select the SPI Bus the TFT Display is attached to.
config LV_TOUCH_CONTROLLER_SPI_HSPI
bool "HSPI"
config LV_TOUCH_CONTROLLER_SPI_VSPI
@ -93,7 +79,7 @@ menu "LVGL Touch controller"
config LV_TOUCH_CONTROLLER_SPI_FSPI
bool "FSPI" if IDF_TARGET_ESP32S2
endchoice
menu "Touchpanel (XPT2046) Pin Assignments"
depends on LV_TOUCH_CONTROLLER_XPT2046
@ -101,7 +87,7 @@ menu "LVGL Touch controller"
int
prompt "GPIO for MISO (Master In Slave Out)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 35 if LV_PREDEFINED_PINS_38V1
@ -113,7 +99,7 @@ menu "LVGL Touch controller"
int
prompt "GPIO for MOSI (Master Out Slave In)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 32 if LV_PREDEFINED_PINS_38V1
@ -124,7 +110,7 @@ menu "LVGL Touch controller"
config LV_TOUCH_SPI_CLK
int "GPIO for CLK (SCK / Serial Clock)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 26 if LV_PREDEFINED_PINS_38V1
@ -135,8 +121,8 @@ menu "LVGL Touch controller"
config LV_TOUCH_SPI_CS
int "GPIO for CS (Slave Select)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
default 33 if LV_PREDEFINED_PINS_38V1
default 5
help
@ -145,7 +131,7 @@ menu "LVGL Touch controller"
config LV_TOUCH_PIN_IRQ
int "GPIO for IRQ (Interrupt Request)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 27 if LV_PREDEFINED_PINS_38V4
@ -153,7 +139,7 @@ menu "LVGL Touch controller"
help
Configure the touchpanel IRQ pin here.
endmenu
menu "Touchpanel Configuration (XPT2046)"
depends on LV_TOUCH_CONTROLLER_XPT2046
@ -180,7 +166,7 @@ menu "LVGL Touch controller"
prompt "Maximum Y coordinate value."
default 4095 if LV_PREDEFINED_PINS_38V4
default 1900
config LV_TOUCH_XY_SWAP
bool
prompt "Swap XY."
@ -211,31 +197,6 @@ menu "LVGL Touch controller"
endchoice
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 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
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 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 22
help
Configure the I2C touchpanel SCL pin here.
endmenu
menu "Touchpanel Configuration (FT6X06)"
depends on LV_TOUCH_CONTROLLER_FT6X06
@ -249,13 +210,13 @@ menu "LVGL Touch controller"
prompt "Invert X coordinate value."
default n
config LV_FT6X36_INVERT_Y
bool
prompt "Invert Y coordinate value."
default n
config LV_FT6X36_INVERT_Y
bool
prompt "Invert Y coordinate value."
default n
endmenu
menu "Touchpanel (STMPE610) Pin Assignments"
depends on LV_TOUCH_CONTROLLER_STMPE610
@ -263,7 +224,7 @@ menu "LVGL Touch controller"
int
prompt "GPIO for MISO (Master In Slave Out)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 35 if LV_PREDEFINED_PINS_38V1
@ -278,7 +239,7 @@ menu "LVGL Touch controller"
int
prompt "GPIO for MOSI (Master Out Slave In)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 32 if LV_PREDEFINED_PINS_38V1
@ -291,7 +252,7 @@ menu "LVGL Touch controller"
config LV_TOUCH_SPI_CLK
int "GPIO for CLK (SCK / Serial Clock)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 26 if LV_PREDEFINED_PINS_38V1
@ -303,7 +264,7 @@ menu "LVGL Touch controller"
config LV_TOUCH_SPI_CS
int "GPIO for CS (Slave Select)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 46 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 33 if LV_PREDEFINED_PINS_38V1
@ -335,7 +296,7 @@ menu "LVGL Touch controller"
int
prompt "Maximum Y coordinate value."
default 3800
config LV_TOUCH_XY_SWAP
bool
prompt "Swap XY."
@ -351,7 +312,7 @@ menu "LVGL Touch controller"
prompt "Invert Y coordinate value."
default y
endmenu
menu "Touchpanel (ADCRAW) Pin Assignments"
depends on LV_TOUCH_CONTROLLER_ADCRAW
@ -372,7 +333,7 @@ menu "LVGL Touch controller"
help
Configure the touchpanel Y- pin. Must be ADC input.
config LV_TOUCHSCREEN_RESISTIVE_PIN_XL
int
prompt "GPIO X-"
@ -502,31 +463,6 @@ menu "LVGL Touch controller"
default y
endmenu
menu "Touchpanel (GT911) Pin Assignments"
depends on LV_TOUCH_CONTROLLER_GT911
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
range 0 21 if IDF_TARGET_ESP32C3
default 2
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
range 0 21 if IDF_TARGET_ESP32C3
default 3
help
Configure the I2C touchpanel SCL pin here.
endmenu
menu "Touchpanel Configuration (GT911)"
depends on LV_TOUCH_CONTROLLER_GT911
@ -548,4 +484,31 @@ menu "LVGL Touch controller"
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"
config LV_I2C_TOUCH_PORT_1
bool
prompt "I2C port 1"
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

View file

@ -1,33 +1,32 @@
/*
* 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
* 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
* 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
*
* 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>
#include <driver/i2c.h>
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include <lvgl.h>
#else
#include <lvgl/lvgl.h>
#endif
#include "ft6x36.h"
#include "tp_i2c.h"
#include "../lvgl_i2c_conf.h"
#include "i2c_manager/i2c_manager.h"
#define TAG "FT6X36"
@ -36,22 +35,10 @@ ft6x36_status_t ft6x36_status;
uint8_t current_dev_addr; // set during init
esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf) {
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;
return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr, data_buf, 1);
}
/**
* @brief Read the FT6x36 gesture ID. Initialize first!
* @param dev_addr: I2C FT6x36 Slave address.
@ -75,42 +62,29 @@ uint8_t ft6x36_get_gesture_id() {
* @retval None
*/
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
ft6x36_status.inited = true;
current_dev_addr = dev_addr;
uint8_t data_buf;
esp_err_t ret;
ESP_LOGI(TAG, "Found touch panel controller");
if ((ret = ft6x06_i2c_read8(dev_addr, FT6X36_PANEL_ID_REG, &data_buf) != ESP_OK))
ESP_LOGE(TAG, "Error reading from device: %s",
esp_err_to_name(ret)); // Only show error the first time
ESP_LOGI(TAG, "\tDevice ID: 0x%02x", data_buf);
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;
current_dev_addr = dev_addr;
uint8_t data_buf;
esp_err_t ret;
ESP_LOGI(TAG, "Found touch panel controller");
if ((ret = ft6x06_i2c_read8(dev_addr, FT6X36_PANEL_ID_REG, &data_buf) != ESP_OK))
ESP_LOGE(TAG, "Error reading from device: %s",
esp_err_to_name(ret)); // Only show error the first time
ESP_LOGI(TAG, "\tDevice ID: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_CHIPSELECT_REG, &data_buf);
ESP_LOGI(TAG, "\tChip ID: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_CHIPSELECT_REG, &data_buf);
ESP_LOGI(TAG, "\tChip ID: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_DEV_MODE_REG, &data_buf);
ESP_LOGI(TAG, "\tDevice mode: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_DEV_MODE_REG, &data_buf);
ESP_LOGI(TAG, "\tDevice mode: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_FIRMWARE_ID_REG, &data_buf);
ESP_LOGI(TAG, "\tFirmware ID: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_FIRMWARE_ID_REG, &data_buf);
ESP_LOGI(TAG, "\tFirmware ID: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_RELEASECODE_REG, &data_buf);
ESP_LOGI(TAG, "\tRelease code: 0x%02x", data_buf);
ft6x06_i2c_read8(dev_addr, FT6X36_RELEASECODE_REG, &data_buf);
ESP_LOGI(TAG, "\tRelease code: 0x%02x", data_buf);
}
}
}
/**
@ -120,67 +94,29 @@ void ft6x06_init(uint16_t dev_addr) {
* @retval Always false
*/
bool ft6x36_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
uint8_t data_xy[4]; // 2 bytes X | 2 bytes Y
uint8_t touch_pnt_cnt; // Number of detected touch points
if (!ft6x36_status.inited) {
ESP_LOGE(TAG, "Init first!");
return 0x00;
}
uint8_t data_buf[5]; // 1 byte status, 2 bytes X, 2 bytes Y
static int16_t last_x = 0; // 12bit pixel value
static int16_t last_y = 0; // 12bit pixel value
ft6x06_i2c_read8(current_dev_addr, FT6X36_TD_STAT_REG, &touch_pnt_cnt);
if (touch_pnt_cnt != 1) { // ignore no touch & multi touch
esp_err_t ret = lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, current_dev_addr, FT6X36_TD_STAT_REG, &data_buf[0], 5);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Error talking to touch IC: %s", esp_err_to_name(ret));
}
uint8_t touch_pnt_cnt = data_buf[0]; // Number of detected touch points
if (ret != ESP_OK || 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;
}
// Read X value
i2c_cmd_handle_t 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_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);
last_x = ((data_buf[1] & FT6X36_MSB_MASK) << 8) | (data_buf[2] & FT6X36_LSB_MASK);
last_y = ((data_buf[3] & FT6X36_MSB_MASK) << 8) | (data_buf[4] & FT6X36_LSB_MASK);
#if CONFIG_LV_FT6X36_INVERT_X
last_x = LV_HOR_RES - last_x;

View file

@ -2,20 +2,20 @@
/*
* 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
* 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
* 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
*
* 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.
*/

View file

@ -19,15 +19,14 @@
*/
#include <esp_log.h>
#include <driver/i2c.h>
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include <lvgl.h>
#else
#include <lvgl/lvgl.h>
#endif
#include "gt911.h"
#include "tp_i2c.h"
#include "../lvgl_i2c_conf.h"
#include "i2c_manager/i2c_manager.h"
#define TAG "GT911"
@ -35,35 +34,12 @@ 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) {
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 >> 8), I2C_MASTER_ACK);
i2c_master_write_byte(i2c_cmd, (register_addr & 0xFF), 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;
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) {
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 >> 8), I2C_MASTER_ACK);
i2c_master_write_byte(i2c_cmd, (register_addr & 0xFF), I2C_MASTER_ACK);
i2c_master_write_byte(i2c_cmd, data, I2C_MASTER_ACK);
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;
uint8_t buffer = data;
return lvgl_i2c_write(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, &buffer, 1);
}
/**

View file

@ -4,7 +4,6 @@
#include "touch_driver.h"
#include "tp_spi.h"
#include "tp_i2c.h"
void touch_driver_init(void)

View file

@ -1,43 +0,0 @@
/*
* 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);
}

View file

@ -1,36 +0,0 @@
/*
* 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 */