Merge branch 'master' into feature/add_st7796s
This commit is contained in:
commit
fbdc247c25
18 changed files with 272 additions and 176 deletions
|
@ -99,7 +99,6 @@ menu "LVGL Touch controller"
|
|||
range 0 39
|
||||
default 35 if LV_PREDEFINED_PINS_38V1
|
||||
default 19
|
||||
|
||||
help
|
||||
Configure the touchpanel MISO pin here.
|
||||
|
||||
|
@ -109,7 +108,6 @@ menu "LVGL Touch controller"
|
|||
range 0 39
|
||||
default 32 if LV_PREDEFINED_PINS_38V1
|
||||
default 23
|
||||
|
||||
help
|
||||
Configure the touchpanel MOSI pin here.
|
||||
|
||||
|
@ -135,7 +133,7 @@ menu "LVGL Touch controller"
|
|||
default 27 if LV_PREDEFINED_PINS_38V4
|
||||
default 25
|
||||
help
|
||||
Configure the touchpanel CS pin here.
|
||||
Configure the touchpanel IRQ pin here.
|
||||
endmenu
|
||||
|
||||
menu "Touchpanel Configuration (XPT2046)"
|
||||
|
@ -180,6 +178,19 @@ menu "LVGL Touch controller"
|
|||
prompt "Invert Y coordinate value."
|
||||
default y
|
||||
|
||||
choice
|
||||
prompt "Select touch detection method."
|
||||
default LV_TOUCH_DETECT_IRQ
|
||||
help
|
||||
Select the controller for your touch panel.
|
||||
|
||||
config LV_TOUCH_DETECT_IRQ
|
||||
bool "IRQ pin only"
|
||||
config LV_TOUCH_DETECT_IRQ_PRESSURE
|
||||
bool "IRQ pin and pressure"
|
||||
config LV_TOUCH_DETECT_PRESSURE
|
||||
bool "Pressure only"
|
||||
endchoice
|
||||
endmenu
|
||||
|
||||
menu "Touchpanel (FT6X06) Pin Assignments"
|
||||
|
|
|
@ -38,16 +38,16 @@ extern "C" {
|
|||
|
||||
/*GetMaxX Macro*/
|
||||
#if CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
|
||||
#define GetMaxX() (CONFIG_LV_DISPLAY_WIDTH - 1)
|
||||
#define GetMaxX() (LV_HOR_RES_MAX - 1)
|
||||
#else
|
||||
#define GetMaxX() (CONFIG_LV_DISPLAY_HEIGHT - 1)
|
||||
#define GetMaxX() (LV_VER_RES_MAX - 1)
|
||||
#endif
|
||||
|
||||
/*GetMaxY Macro*/
|
||||
#if CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
|
||||
#define GetMaxY() (CONFIG_LV_DISPLAY_HEIGHT - 1)
|
||||
#define GetMaxY() (LV_VER_RES_MAX - 1)
|
||||
#else
|
||||
#define GetMaxY() (CONFIG_LV_DISPLAY_WIDTH - 1)
|
||||
#define GetMaxY() (LV_HOR_RES_MAX - 1)
|
||||
#endif
|
||||
|
||||
#ifndef CONCAT3
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
#include "ft6x36.h"
|
||||
#include "tp_i2c.h"
|
||||
#include "../lvgl_i2c_conf.h"
|
||||
|
||||
#define TAG "FT6X36"
|
||||
|
||||
|
@ -46,7 +47,7 @@ esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *d
|
|||
|
||||
i2c_master_read_byte(i2c_cmd, data_buf, I2C_MASTER_NACK);
|
||||
i2c_master_stop(i2c_cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_0, i2c_cmd, 1000 / portTICK_RATE_MS);
|
||||
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;
|
||||
}
|
||||
|
@ -145,7 +146,7 @@ bool ft6x36_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
|||
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(I2C_NUM_0, i2c_cmd, 1000 / portTICK_RATE_MS);
|
||||
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));
|
||||
|
@ -168,7 +169,7 @@ bool ft6x36_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
|||
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(I2C_NUM_0, i2c_cmd, 1000 / portTICK_RATE_MS);
|
||||
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));
|
||||
|
|
|
@ -18,18 +18,26 @@
|
|||
*********************/
|
||||
#define TAG "XPT2046"
|
||||
|
||||
#define CMD_X_READ 0b10010000
|
||||
#define CMD_Y_READ 0b11010000
|
||||
#define CMD_X_READ 0b10010000 // NOTE: XPT2046 data sheet says this is actually Y
|
||||
#define CMD_Y_READ 0b11010000 // NOTE: XPT2046 data sheet says this is actually X
|
||||
#define CMD_Z1_READ 0b10110000
|
||||
#define CMD_Z2_READ 0b11000000
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef enum {
|
||||
TOUCH_NOT_DETECTED = 0,
|
||||
TOUCH_DETECTED = 1,
|
||||
} xpt2046_touch_detect_t;
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void xpt2046_corr(int16_t * x, int16_t * y);
|
||||
static void xpt2046_avg(int16_t * x, int16_t * y);
|
||||
static int16_t xpt2046_cmd(uint8_t cmd);
|
||||
static xpt2046_touch_detect_t xpt2048_is_touch_detected();
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
|
@ -51,6 +59,9 @@ uint8_t avg_last;
|
|||
*/
|
||||
void xpt2046_init(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "XPT2046 Initialization");
|
||||
|
||||
#if XPT2046_TOUCH_IRQ || XPT2046_TOUCH_IRQ_PRESS
|
||||
gpio_config_t irq_config = {
|
||||
.pin_bit_mask = BIT64(XPT2046_IRQ),
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
|
@ -59,10 +70,9 @@ void xpt2046_init(void)
|
|||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "XPT2046 Initialization");
|
||||
|
||||
esp_err_t ret = gpio_config(&irq_config);
|
||||
assert(ret == ESP_OK);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,39 +84,33 @@ bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
|
|||
{
|
||||
static int16_t last_x = 0;
|
||||
static int16_t last_y = 0;
|
||||
bool valid = true;
|
||||
bool valid = false;
|
||||
|
||||
int16_t x = 0;
|
||||
int16_t y = 0;
|
||||
int16_t x = last_x;
|
||||
int16_t y = last_y;
|
||||
if (xpt2048_is_touch_detected() == TOUCH_DETECTED)
|
||||
{
|
||||
valid = true;
|
||||
|
||||
uint8_t irq = gpio_get_level(XPT2046_IRQ);
|
||||
x = xpt2046_cmd(CMD_X_READ);
|
||||
y = xpt2046_cmd(CMD_Y_READ);
|
||||
ESP_LOGI(TAG, "P(%d,%d)", x, y);
|
||||
|
||||
if (irq == 0) {
|
||||
uint8_t data[2];
|
||||
|
||||
tp_spi_read_reg(CMD_X_READ, data, 2);
|
||||
x = (data[0] << 8) | data[1];
|
||||
|
||||
tp_spi_read_reg(CMD_Y_READ, data, 2);
|
||||
y = (data[0] << 8) | data[1];
|
||||
ESP_LOGI(TAG, "P(%d,%d)", x, y);
|
||||
|
||||
/*Normalize Data back to 12-bits*/
|
||||
x = x >> 4;
|
||||
y = y >> 4;
|
||||
ESP_LOGI(TAG, "P_norm(%d,%d)", x, y);
|
||||
|
||||
|
||||
xpt2046_corr(&x, &y);
|
||||
xpt2046_avg(&x, &y);
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
|
||||
ESP_LOGI(TAG, "x = %d, y = %d", x, y);
|
||||
} else {
|
||||
x = last_x;
|
||||
y = last_y;
|
||||
ESP_LOGI(TAG, "x = %d, y = %d", x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
avg_last = 0;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
data->point.x = x;
|
||||
|
@ -119,6 +123,42 @@ bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
|
|||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
static xpt2046_touch_detect_t xpt2048_is_touch_detected()
|
||||
{
|
||||
// check IRQ pin if we IRQ or IRQ and preessure
|
||||
#if XPT2046_TOUCH_IRQ || XPT2046_TOUCH_IRQ_PRESS
|
||||
uint8_t irq = gpio_get_level(XPT2046_IRQ);
|
||||
|
||||
if (irq != 0) {
|
||||
return TOUCH_NOT_DETECTED;
|
||||
}
|
||||
#endif
|
||||
// check pressure if we are pressure or IRQ and pressure
|
||||
#if XPT2046_TOUCH_PRESS || XPT2046_TOUCH_IRQ_PRESS
|
||||
int16_t z1 = xpt2046_cmd(CMD_Z1_READ) >> 3;
|
||||
int16_t z2 = xpt2046_cmd(CMD_Z2_READ) >> 3;
|
||||
|
||||
// this is not what the confusing datasheet says but it seems to
|
||||
// be enough to detect real touches on the panel
|
||||
int16_t z = z1 + 4096 - z2;
|
||||
|
||||
if (z < XPT2046_TOUCH_THRESHOLD)
|
||||
{
|
||||
return TOUCH_NOT_DETECTED;
|
||||
}
|
||||
#endif
|
||||
|
||||
return TOUCH_DETECTED;
|
||||
}
|
||||
|
||||
static int16_t xpt2046_cmd(uint8_t cmd)
|
||||
{
|
||||
uint8_t data[2];
|
||||
tp_spi_read_reg(cmd, data, 2);
|
||||
int16_t val = (data[0] << 8) | data[1];
|
||||
return val;
|
||||
}
|
||||
|
||||
static void xpt2046_corr(int16_t * x, int16_t * y)
|
||||
{
|
||||
#if XPT2046_XY_SWAP != 0
|
||||
|
|
|
@ -27,14 +27,18 @@ extern "C" {
|
|||
*********************/
|
||||
#define XPT2046_IRQ CONFIG_LV_TOUCH_PIN_IRQ
|
||||
|
||||
#define XPT2046_AVG 4
|
||||
#define XPT2046_X_MIN CONFIG_LV_TOUCH_X_MIN
|
||||
#define XPT2046_Y_MIN CONFIG_LV_TOUCH_Y_MIN
|
||||
#define XPT2046_X_MAX CONFIG_LV_TOUCH_X_MAX
|
||||
#define XPT2046_Y_MAX CONFIG_LV_TOUCH_Y_MAX
|
||||
#define XPT2046_X_INV CONFIG_LV_TOUCH_INVERT_X
|
||||
#define XPT2046_Y_INV CONFIG_LV_TOUCH_INVERT_Y
|
||||
#define XPT2046_XY_SWAP CONFIG_LV_TOUCH_XY_SWAP
|
||||
#define XPT2046_AVG 4
|
||||
#define XPT2046_X_MIN CONFIG_LV_TOUCH_X_MIN
|
||||
#define XPT2046_Y_MIN CONFIG_LV_TOUCH_Y_MIN
|
||||
#define XPT2046_X_MAX CONFIG_LV_TOUCH_X_MAX
|
||||
#define XPT2046_Y_MAX CONFIG_LV_TOUCH_Y_MAX
|
||||
#define XPT2046_X_INV CONFIG_LV_TOUCH_INVERT_X
|
||||
#define XPT2046_Y_INV CONFIG_LV_TOUCH_INVERT_Y
|
||||
#define XPT2046_XY_SWAP CONFIG_LV_TOUCH_XY_SWAP
|
||||
#define XPT2046_TOUCH_THRESHOLD 400 // Threshold for touch detection
|
||||
#define XPT2046_TOUCH_IRQ CONFIG_LV_TOUCH_DETECT_IRQ
|
||||
#define XPT2046_TOUCH_IRQ_PRESS CONFIG_LV_TOUCH_DETECT_IRQ_PRESSURE
|
||||
#define XPT2046_TOUCH_PRESS CONFIG_LV_TOUCH_DETECT_PRESSURE
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue