From 7be59f84177fa00eb55fa91b3e3944885c4b5dfd Mon Sep 17 00:00:00 2001 From: wlyu Date: Thu, 2 Jun 2022 19:00:51 +0800 Subject: [PATCH] fixed touchscreen x y wrong value and optimize codes --- .../nuttx/drivers/input/gt9xx.c | 26 +- .../nuttx/include/nuttx/input/gt9xx.h | 250 +++++++----------- 2 files changed, 111 insertions(+), 165 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/input/gt9xx.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/input/gt9xx.c index 77496d9cf..6d97db654 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/input/gt9xx.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/drivers/input/gt9xx.c @@ -287,10 +287,10 @@ static int gt9xx_read_reg(FAR struct gt9xx_dev_s *priv, uint8_t *reg_addr, uint8 retries ++; } if (ret < 0) - { + { ierr("gt: [%s] failed freq %ld addr %x ret %d\n", __func__, priv->frequency, config->address, ret); return ret; - } + } return ret; } @@ -302,7 +302,7 @@ static int gt9xx_write_config(FAR struct gt9xx_dev_s *priv) { int i, ret = -1; uint8_t check_sum = 0; - uint8_t offet = 0x80FE - 0x8047 + 1 ; + uint8_t offet = GT9XX_REG_CONFIG_CHKSUM - GT9XX_REG_CONFIG_DATA; const uint8_t* cfg_info = gt9xx_cfg_data; uint8_t cfg_info_len = sizeof(gt9xx_cfg_data) / sizeof(gt9xx_cfg_data[0]); @@ -313,8 +313,6 @@ static int gt9xx_write_config(FAR struct gt9xx_dev_s *priv) memset(®_data[GT9XX_ADDR_LENGTH], 0, GT9XX_CONFIG_MAX_LENGTH); memcpy(®_data[GT9XX_ADDR_LENGTH], cfg_info, cfg_info_len); - check_sum = 0; - for (i = GT9XX_ADDR_LENGTH; i < offet + GT9XX_ADDR_LENGTH; i++) { check_sum += reg_data[i]; @@ -323,7 +321,7 @@ static int gt9xx_write_config(FAR struct gt9xx_dev_s *priv) reg_data[offet + GT9XX_ADDR_LENGTH] = (~check_sum) + 1; //checksum reg_data[offet + GT9XX_ADDR_LENGTH + 1] = 1; //refresh - gt_print("Driver send config."); + gt_print("Driver send config.\n"); ret = gt9xx_write_reg(priv, reg_data, offet + GT9XX_ADDR_LENGTH + 2); @@ -420,14 +418,14 @@ static void gt9xx_data_worker(FAR void *arg) */ if(priv->touchbuf[0] & 0xf) - { - gt_print("gt: [%s] get i2c %x reg %x %x ret %d\n", __func__, config->address, regaddr[0], regaddr[1], ret); - for(int i = 0; i < 10; i ++) - { - gt_print("%x ", priv->touchbuf[i]); - } - gt_print("\n"); - } + { + gt_print("get i2c %x reg %x %x ret %d ", config->address, regaddr[0], regaddr[1], ret); + for(int i = 0; i < GT9XX_TOUCH_DATA_LEN; i ++) + { + gt_print("%x ", priv->touchbuf[i]); + } + gt_print("\n"); + } sample = (FAR struct gt9xx_touch_data_s *)priv->touchbuf; diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/input/gt9xx.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/input/gt9xx.h index 1d723fa53..7a518c8c0 100755 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/input/gt9xx.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/include/nuttx/input/gt9xx.h @@ -1,165 +1,113 @@ -/* - * Copyright (c) 2022 AIIT XUOS Lab - * XiUOS is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -/** - * @file gt9xx.h - * @brief API for gt9xx. - * @version 1.0 - * @author AIIT XUOS Lab - * @date 2022.5.31 - */ - - -#ifndef __GT9XX_H_ -#define __GT9XX_H_ - -#define GT9XX_MAX_TOUCHES (1) -#define GT9XX_TOUCH_DATA_LEN (8 * GT9XX_MAX_TOUCHES + 4) - -#define TOUCH_POINT_GET_EVENT(t) ((t).xh >> 6) -#define TOUCH_POINT_GET_ID(t) ((t).yh >> 4) -#define TOUCH_POINT_GET_X(t) ((((t).xh & 0x0f) << 8) | (t).xl) -#define TOUCH_POINT_GET_Y(t) ((((t).yh & 0x0f) << 8) | (t).yl) - - -#define GT9XX_MAX_HEIGHT 272 -#define GT9XX_MAX_WIDTH 480 -#define GT9XX_INT_TRIGGER 0 - -#define GT9XX_ADDR_LENGTH 2 -#define GT9XX_CONFIG_MIN_LENGTH 186 -#define GT9XX_CONFIG_MAX_LENGTH 240 - -#define GT9XX_REG_BAK_REF 0x99D0 -#define GT9XX_REG_MAIN_CLK 0x8020 -#define GT9XX_REG_CHIP_TYPE 0x8000 -#define GT9XX_REG_HAVE_KEY 0x804E -#define GT9XX_REG_MATRIX_DRVNUM 0x8069 -#define GT9XX_REG_MATRIX_SENNUM 0x806A -#define GT9XX_REG_COMMAND 0x8040 - -#define GT9XX_COMMAND_READSTATUS 0 -#define GT9XX_COMMAND_DIFFERENCE 1 -#define GT9XX_COMMAND_SOFTRESET 2 -#define GT9XX_COMMAND_UPDATE 3 -#define GT9XX_COMMAND_CALCULATE 4 -#define GT9XX_COMMAND_TURNOFF 5 - -#define GT9XX_REG_READ_COOR 0x814E -#define GT9XX_REG_SLEEP 0x8040 -#define GT9XX_REG_SENSOR_ID 0x814A -#define GT9XX_REG_CONFIG_DATA 0x8047 -#define GT9XX_REG_VERSION 0x8140 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -enum touch_event_e -{ - GT9XX_DOWN = 0, /* The state changed to touched */ - GT9XX_UP = 1, /* The state changed to not touched */ - GT9XX_CONTACT = 2, /* There is a continuous touch being detected */ - GT9XX_INVALID = 3 /* No touch information available */ -}; - -/* Describes on touchpoint returned by the GT9xx */ - -struct gt9xx_touch_point_s -{ - uint8_t xl; - uint8_t xh; - uint8_t yl; - uint8_t yh; - uint8_t weight; - uint8_t area; -}; - -/* Describes all touch data returned by the GT9xx */ - -struct gt9xx_touch_data_s -{ - uint8_t tdstatus; /* Touch status */ - struct gt9xx_touch_point_s touch[GT9XX_MAX_TOUCHES]; -}; - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ -/* Configuration ************************************************************/ +/** + * @file gt9xx.h + * @brief API for gt9xx. + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2022.5.31 + */ + + +#ifndef __GT9XX_H_ +#define __GT9XX_H_ + +#define GT9XX_MAX_TOUCHES (1) +#define GT9XX_TOUCH_DATA_LEN (8 * GT9XX_MAX_TOUCHES + 4) + +#define TOUCH_POINT_GET_EVENT(t) ((t).xh >> 6) +#define TOUCH_POINT_GET_ID(t) ((t).yh >> 4) +#define TOUCH_POINT_GET_X(t) ((((t).xh & 0x0f) << 8) | (t).xl) +#define TOUCH_POINT_GET_Y(t) ((((t).yh & 0x0f) << 8) | (t).yl) + + +#define GT9XX_MAX_HEIGHT 272 +#define GT9XX_MAX_WIDTH 480 +#define GT9XX_INT_TRIGGER 0 + +#define GT9XX_ADDR_LENGTH 2 +#define GT9XX_CONFIG_MIN_LENGTH 186 +#define GT9XX_CONFIG_MAX_LENGTH 240 + +#define GT9XX_REG_BAK_REF 0x99D0 +#define GT9XX_REG_CHIP_TYPE 0x8000 +#define GT9XX_REG_MAIN_CLK 0x8020 +#define GT9XX_REG_COMMAND 0x8040 +#define GT9XX_REG_CONFIG_DATA 0x8047 +#define GT9XX_REG_CONFIG_CHKSUM 0x80FF +#define GT9XX_REG_VERSION 0x8140 +#define GT9XX_REG_SENSOR_ID 0x814A +#define GT9XX_REG_READ_COOR 0x814E + +#define GT9XX_COMMAND_READSTATUS 0 +#define GT9XX_COMMAND_DIFFERENCE 1 +#define GT9XX_COMMAND_SOFTRESET 2 +#define GT9XX_COMMAND_UPDATE 3 +#define GT9XX_COMMAND_CALCULATE 4 +#define GT9XX_COMMAND_TURNOFF 5 + +enum touch_event_e +{ + GT9XX_DOWN = 0, /* The state changed to touched */ + GT9XX_UP = 1, /* The state changed to not touched */ + GT9XX_CONTACT = 2, /* There is a continuous touch being detected */ + GT9XX_INVALID = 3 /* No touch information available */ +}; + +/* Describes on touchpoint returned by the GT9xx */ + +struct gt9xx_touch_point_s +{ + uint8_t xh; + uint8_t xl; + uint8_t yh; + uint8_t yl; + uint8_t weight; + uint8_t area; +}; + +/* Describes all touch data returned by the GT9xx */ + +struct gt9xx_touch_data_s +{ + uint8_t tdstatus; /* Touch status */ + struct gt9xx_touch_point_s touch[GT9XX_MAX_TOUCHES]; +}; /* Maximum number of threads than can be waiting for POLL events */ -#ifndef CONFIG_GT9XX_NPOLLWAITERS -# define CONFIG_GT9XX_NPOLLWAITERS 2 +#ifndef CONFIG_GT9XX_NPOLLWAITERS +# define CONFIG_GT9XX_NPOLLWAITERS 2 #endif -/* Check for some required settings. This can save the user a lot of time - * in getting the right configuration. - */ - -#ifndef CONFIG_SCHED_WORKQUEUE -# error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected." -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* A reference to a structure of this type must be passed to the GT9XX - * driver. This structure provides information about the configuration - * of the FT5x06 and provides some board-specific hooks. - * - * Memory for this structure is provided by the caller. It is not copied - * by the driver and is presumed to persist while the driver is active. The - * memory must be writeable because, under certain circumstances, the driver - * may modify frequency or X plate resistance values. - */ - -struct gt9xx_config_s +struct gt9xx_config_s { - /* Device characterization */ - uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */ uint32_t frequency; /* Default I2C frequency */ - /* IRQ/GPIO access callbacks. These operations all hidden behind - * callbacks to isolate the GT9XX driver from differences in GPIO - * interrupt handling by varying boards and MCUs. - * - * attach - Attach an FT5x06 interrupt handler to a GPIO interrupt - * enable - Enable or disable a GPIO interrupt - * clear - Acknowledge/clear any pending GPIO interrupt - * wakeup - Issue WAKE interrupt to FT5x06 to change the FT5x06 from - * Hibernate to Active mode. - * nreset - Control the chip reset pin (active low) - - */ - -#ifndef CONFIG_GT9XX_POLLMODE - int (*attach)(FAR const struct gt9xx_config_s *config, xcpt_t isr, +#ifndef CONFIG_GT9XX_POLLMODE + int (*attach)(FAR const struct gt9xx_config_s *config, xcpt_t isr, FAR void *arg); - void (*enable)(FAR const struct gt9xx_config_s *config, bool enable); - void (*clear)(FAR const struct gt9xx_config_s *config); + void (*enable)(FAR const struct gt9xx_config_s *config, bool enable); + void (*clear)(FAR const struct gt9xx_config_s *config); #endif - void (*wakeup)(FAR const struct gt9xx_config_s *config); - void (*nreset)(FAR const struct gt9xx_config_s *config, + void (*wakeup)(FAR const struct gt9xx_config_s *config); + void (*nreset)(FAR const struct gt9xx_config_s *config, bool state); -}; - +}; -int gt9xx_register(FAR struct i2c_master_s *i2c, - FAR const struct gt9xx_config_s *config, int minor); - - -#endif /* __GT9XX_H__ */ +int gt9xx_register(FAR struct i2c_master_s *i2c, + FAR const struct gt9xx_config_s *config, int minor); + + +#endif /* __GT9XX_H__ */