Merge pull request #69 from lvgl/feature/esp32c3_support

Feature/esp32c3 support
This commit is contained in:
Carlos Diaz 2021-06-21 13:47:15 -05:00 committed by GitHub
commit aff7d1fd18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 387 additions and 7 deletions

View file

@ -70,6 +70,8 @@ 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)

View file

@ -19,9 +19,9 @@
#include "driver/i2c.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
/*********************
@ -53,7 +53,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)
@ -204,16 +209,31 @@ bool lvgl_spi_driver_init(int host,
int dma_channel,
int quadwp_pin, int quadhd_pin)
{
spi_dma_chan_t dma_chan = SPI_DMA_DISABLED;
#if defined (CONFIG_IDF_TARGET_ESP32)
assert((SPI_HOST <= host) && (VSPI_HOST >= host));
const char *spi_names[] = {
"SPI_HOST", "HSPI_HOST", "VSPI_HOST"
};
dma_chan = dma_channel;
#elif defined (CONFIG_IDF_TARGET_ESP32S2)
assert((SPI_HOST <= host) && (HSPI_HOST >= host));
const char *spi_names[] = {
"SPI_HOST", "", ""
};
dma_chan = dma_channel;
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
assert((SPI1_HOST <= host) && (SPI3_HOST >= host));
const char *spi_names[] = {
"SPI1_HOST", "SPI2_HOST", "SPI3_HOST"
};
dma_chan = SPI_DMA_CH_AUTO;
#else
#error "Target chip not selected"
#endif
ESP_LOGI(TAG, "Configuring SPI host %s (%d)", spi_names[host], host);
@ -232,7 +252,7 @@ bool lvgl_spi_driver_init(int host,
};
ESP_LOGI(TAG, "Initializing SPI bus...");
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_channel);
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_chan);
assert(ret == ESP_OK);
return ESP_OK != ret;

View file

@ -65,11 +65,15 @@ extern "C" {
#define ENABLE_TOUCH_INPUT CONFIG_LV_ENABLE_TOUCH
#if defined (CONFIG_LV_TFT_DISPLAY_SPI_HSPI)
#define TFT_SPI_HOST HSPI_HOST
#if defined (CONFIG_IDF_TARGET_ESP32C3)
#define TFT_SPI_HOST SPI2_HOST
#else
#define TFT_SPI_HOST HSPI_HOST
#endif
#elif defined (CONFIG_LV_TFT_DISPLAY_SPI_VSPI)
#define TFT_SPI_HOST VSPI_HOST
#define TFT_SPI_HOST VSPI_HOST
#elif defined (CONFIG_LV_TFT_DISPLAY_SPI_FSPI)
#define TFT_SPI_HOST FSPI_HOST
#define TFT_SPI_HOST FSPI_HOST
#endif
#if defined (CONFIG_LV_TFT_DISPLAY_SPI_HALF_DUPLEX)

View file

@ -772,6 +772,7 @@ menu "LVGL TFT Display controller"
int "GPIO for MOSI (Master Out Slave In)" if LV_TFT_DISPLAY_PROTOCOL_SPI
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 23 if LV_PREDEFINED_DISPLAY_WROVER4
default 23 if LV_PREDEFINED_DISPLAY_ATAG
@ -801,6 +802,7 @@ menu "LVGL TFT Display controller"
depends on LV_DISPLAY_USE_SPI_MISO
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 19 if LV_PREDEFINED_PINS_TKOALA
default 38 if LV_PREDEFINED_DISPLAY_M5CORE2
@ -823,6 +825,7 @@ menu "LVGL TFT Display controller"
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
range -1 39 if IDF_TARGET_ESP32
range -1 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 22 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
default -1
@ -834,6 +837,7 @@ menu "LVGL TFT Display controller"
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
range -1 39 if IDF_TARGET_ESP32
range -1 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 21 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
default -1
@ -844,6 +848,7 @@ menu "LVGL TFT Display controller"
int "GPIO for CLK (SCK / Serial Clock)" if LV_TFT_DISPLAY_PROTOCOL_SPI
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 18 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
default 18 if LV_PREDEFINED_DISPLAY_M5CORE2
@ -872,6 +877,7 @@ menu "LVGL TFT Display controller"
depends on LV_DISPLAY_USE_SPI_CS
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 5 if LV_PREDEFINED_PINS_38V1
default 14 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
@ -900,6 +906,7 @@ menu "LVGL TFT Display controller"
int "GPIO for DC (Data / Command)" if LV_TFT_DISPLAY_PROTOCOL_SPI
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
depends on LV_DISPLAY_USE_DC
default 19 if LV_PREDEFINED_PINS_38V1
@ -937,6 +944,7 @@ menu "LVGL TFT Display controller"
depends on LV_DISP_USE_RST
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 18 if LV_PREDEFINED_PINS_38V1
default 25 if LV_PREDEFINED_PINS_38V4
@ -958,9 +966,11 @@ menu "LVGL TFT Display controller"
int "GPIO for Busy" if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 35 if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
default 35
default 35 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2
default 21 if IDF_TARGET_ESP32C3
help
Configure the display Busy pin here.
@ -997,6 +1007,7 @@ menu "LVGL TFT Display controller"
depends on LV_ENABLE_BACKLIGHT_CONTROL
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 23 if LV_PREDEFINED_PINS_38V1
default 26 if LV_PREDEFINED_PINS_38V4
@ -1017,6 +1028,7 @@ menu "LVGL TFT Display controller"
int "GPIO for I2C SDA" if LV_TFT_DISPLAY_PROTOCOL_I2C
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 5 if LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
default 5
@ -1028,6 +1040,7 @@ menu "LVGL TFT Display controller"
int "GPIO for I2C SCL" if LV_TFT_DISPLAY_PROTOCOL_I2C
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 4 if LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
default 4

View file

@ -9,6 +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_GT911
choice
prompt "Select a touch panel controller model."
@ -36,6 +37,9 @@ menu "LVGL Touch controller"
config LV_TOUCH_CONTROLLER_RA8875
select LV_TOUCH_DRIVER_DISPLAY
bool "RA8875"
config LV_TOUCH_CONTROLLER_GT911
select LV_TOUCH_DRIVER_PROTOCOL_I2C
bool "GT911"
endchoice
config LV_TOUCH_DRIVER_PROTOCOL_SPI
@ -98,6 +102,7 @@ menu "LVGL Touch controller"
prompt "GPIO for MISO (Master In Slave Out)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 35 if LV_PREDEFINED_PINS_38V1
default 19
@ -109,6 +114,7 @@ menu "LVGL Touch controller"
prompt "GPIO for MOSI (Master Out Slave In)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 32 if LV_PREDEFINED_PINS_38V1
default 23
@ -119,6 +125,7 @@ menu "LVGL Touch controller"
int "GPIO for CLK (SCK / Serial Clock)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 26 if LV_PREDEFINED_PINS_38V1
default 18
@ -139,6 +146,7 @@ menu "LVGL Touch controller"
int "GPIO for IRQ (Interrupt Request)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 27 if LV_PREDEFINED_PINS_38V4
default 25
@ -211,6 +219,7 @@ menu "LVGL Touch controller"
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
@ -220,6 +229,7 @@ menu "LVGL Touch controller"
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
@ -254,6 +264,7 @@ menu "LVGL Touch controller"
prompt "GPIO for MISO (Master In Slave Out)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 35 if LV_PREDEFINED_PINS_38V1
default 19 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
@ -263,10 +274,12 @@ menu "LVGL Touch controller"
Configure the touchpanel MISO pin here.
config LV_TOUCH_SPI_MOSI
# TODO Fix default for ESP32C3
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 21 if IDF_TARGET_ESP32C3
default 32 if LV_PREDEFINED_PINS_38V1
default 18 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
@ -279,6 +292,7 @@ menu "LVGL Touch controller"
int "GPIO for CLK (SCK / Serial Clock)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 26 if LV_PREDEFINED_PINS_38V1
default 5 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
@ -290,6 +304,7 @@ menu "LVGL Touch controller"
int "GPIO for CS (Slave Select)"
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
range 0 21 if IDF_TARGET_ESP32C3
default 33 if LV_PREDEFINED_PINS_38V1
default 32 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
@ -488,4 +503,49 @@ menu "LVGL Touch controller"
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
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
endmenu

168
lvgl_touch/gt911.c Normal file
View file

@ -0,0 +1,168 @@
/*
* 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>
#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"
#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) {
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;
}
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;
}
/**
* @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;
}

94
lvgl_touch/gt911.h Normal file
View file

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

View file

@ -21,10 +21,16 @@ void touch_driver_init(void)
/* nothing to do */
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
ra8875_touch_init();
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911)
gt911_init(GT911_I2C_SLAVE_ADDR);
#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)
#endif
{
bool res = false;
@ -40,8 +46,14 @@ bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
res = FT81x_read(drv, data);
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
res = ra8875_touch_read(drv, data);
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911)
res = gt911_read(drv, data);
#endif
#if LVGL_VERSION_MAJOR >= 8
data->continue_reading = res;
#else
return res;
#endif
}

View file

@ -32,6 +32,8 @@ extern "C" {
#include "FT81x.h"
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_RA8875)
#include "ra8875_touch.h"
#elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911)
#include "gt911.h"
#endif
/*********************
@ -42,7 +44,12 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/
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);
#endif
#ifdef __cplusplus
} /* extern "C" */