Marge branch 'master' into lvgl_7.11.0_idf_5.0
This commit is contained in:
commit
a73c429954
62 changed files with 2427 additions and 1270 deletions
|
@ -1,55 +1,45 @@
|
|||
/*
|
||||
* 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 "lvgl_i2c/i2c_manager.h"
|
||||
|
||||
#define TAG "FT6X36"
|
||||
#define FT6X36_TOUCH_QUEUE_ELEMENTS 1
|
||||
|
||||
|
||||
ft6x36_status_t ft6x36_status;
|
||||
uint8_t current_dev_addr; // set during init
|
||||
static ft6x36_status_t ft6x36_status;
|
||||
static uint8_t current_dev_addr; // set during init
|
||||
static ft6x36_touch_t touch_inputs = { -1, -1, LV_INDEV_STATE_REL }; // -1 coordinates to designate it was never touched
|
||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
||||
QueueHandle_t ft6x36_touch_queue_handle;
|
||||
#endif
|
||||
|
||||
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_PERIOD_MS);
|
||||
i2c_cmd_link_delete(i2c_cmd);
|
||||
return ret;
|
||||
static esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf) {
|
||||
return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr, data_buf, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,42 +65,38 @@ 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);
|
||||
}
|
||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
||||
ft6x36_touch_queue_handle = xQueueCreate( FT6X36_TOUCH_QUEUE_ELEMENTS, sizeof( ft6x36_touch_t ) );
|
||||
if( ft6x36_touch_queue_handle == NULL )
|
||||
{
|
||||
ESP_LOGE( TAG, "\tError creating touch input FreeRTOS queue" );
|
||||
return;
|
||||
}
|
||||
xQueueSend( ft6x36_touch_queue_handle, &touch_inputs, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,82 +106,55 @@ 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
|
||||
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
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
return false;
|
||||
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
|
||||
|
||||
// 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_PERIOD_MS);
|
||||
i2c_cmd_link_delete(i2c_cmd);
|
||||
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 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
|
||||
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
|
||||
if ( touch_inputs.current_state != LV_INDEV_STATE_REL)
|
||||
{
|
||||
touch_inputs.current_state = LV_INDEV_STATE_REL;
|
||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
||||
xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs );
|
||||
#endif
|
||||
}
|
||||
data->point.x = touch_inputs.last_x;
|
||||
data->point.y = touch_inputs.last_y;
|
||||
data->state = touch_inputs.current_state;
|
||||
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_PERIOD_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);
|
||||
touch_inputs.current_state = LV_INDEV_STATE_PR;
|
||||
touch_inputs.last_x = ((data_buf[1] & FT6X36_MSB_MASK) << 8) | (data_buf[2] & FT6X36_LSB_MASK);
|
||||
touch_inputs.last_y = ((data_buf[3] & FT6X36_MSB_MASK) << 8) | (data_buf[4] & FT6X36_LSB_MASK);
|
||||
|
||||
#if CONFIG_LV_FT6X36_SWAPXY
|
||||
int16_t swap_buf = last_x;
|
||||
last_x = last_y;
|
||||
last_y = swap_buf;
|
||||
int16_t swap_buf = touch_inputs.last_x;
|
||||
touch_inputs.last_x = touch_inputs.last_y;
|
||||
touch_inputs.last_y = swap_buf;
|
||||
#endif
|
||||
#if CONFIG_LV_FT6X36_INVERT_X
|
||||
last_x = LV_HOR_RES - last_x;
|
||||
touch_inputs.last_x = LV_HOR_RES - touch_inputs.last_x;
|
||||
#endif
|
||||
#if CONFIG_LV_FT6X36_INVERT_Y
|
||||
last_y = LV_VER_RES - last_y;
|
||||
touch_inputs.last_y = LV_VER_RES - touch_inputs.last_y;
|
||||
#endif
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y);
|
||||
data->point.x = touch_inputs.last_x;
|
||||
data->point.y = touch_inputs.last_y;
|
||||
data->state = touch_inputs.current_state;
|
||||
ESP_LOGD(TAG, "X=%u Y=%u", data->point.x, data->point.y);
|
||||
|
||||
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE
|
||||
xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs );
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue