forked from xuos/xiuos
				
			fixed touchscreen x y wrong value and optimize codes
This commit is contained in:
		
							parent
							
								
									7ea3b595c2
								
							
						
					
					
						commit
						7be59f8417
					
				| 
						 | 
					@ -287,10 +287,10 @@ static int gt9xx_read_reg(FAR struct gt9xx_dev_s *priv, uint8_t *reg_addr, uint8
 | 
				
			||||||
        retries ++;
 | 
					        retries ++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (ret < 0)
 | 
					    if (ret < 0)
 | 
				
			||||||
      {
 | 
					    {
 | 
				
			||||||
        ierr("gt: [%s] failed freq %ld addr %x ret %d\n", __func__, priv->frequency, config->address, ret);
 | 
					        ierr("gt: [%s] failed freq %ld addr %x ret %d\n", __func__, priv->frequency, config->address, ret);
 | 
				
			||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
      }
 | 
					    }
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -302,7 +302,7 @@ static int gt9xx_write_config(FAR struct gt9xx_dev_s *priv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i, ret = -1;
 | 
					    int i, ret = -1;
 | 
				
			||||||
    uint8_t check_sum = 0;
 | 
					    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;
 | 
					    const uint8_t* cfg_info = gt9xx_cfg_data;
 | 
				
			||||||
    uint8_t cfg_info_len = sizeof(gt9xx_cfg_data) / sizeof(gt9xx_cfg_data[0]);
 | 
					    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);
 | 
					    memset(®_data[GT9XX_ADDR_LENGTH], 0, GT9XX_CONFIG_MAX_LENGTH);
 | 
				
			||||||
    memcpy(®_data[GT9XX_ADDR_LENGTH], cfg_info, cfg_info_len);
 | 
					    memcpy(®_data[GT9XX_ADDR_LENGTH], cfg_info, cfg_info_len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    check_sum = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (i = GT9XX_ADDR_LENGTH; i < offet + GT9XX_ADDR_LENGTH; i++)
 | 
					    for (i = GT9XX_ADDR_LENGTH; i < offet + GT9XX_ADDR_LENGTH; i++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        check_sum += reg_data[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] = (~check_sum) + 1; //checksum
 | 
				
			||||||
    reg_data[offet + GT9XX_ADDR_LENGTH + 1] =  1; //refresh
 | 
					    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);
 | 
					    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)
 | 
					      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);
 | 
					          gt_print("get i2c %x reg %x %x ret %d ", config->address, regaddr[0], regaddr[1], ret);
 | 
				
			||||||
        for(int i = 0; i < 10; i ++)
 | 
					          for(int i = 0; i < GT9XX_TOUCH_DATA_LEN; i ++)
 | 
				
			||||||
          {
 | 
					            {
 | 
				
			||||||
              gt_print("%x ", priv->touchbuf[i]);
 | 
					                gt_print("%x ", priv->touchbuf[i]);
 | 
				
			||||||
          }
 | 
					            }
 | 
				
			||||||
        gt_print("\n");
 | 
					          gt_print("\n");
 | 
				
			||||||
      }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      sample = (FAR struct gt9xx_touch_data_s *)priv->touchbuf;
 | 
					      sample = (FAR struct gt9xx_touch_data_s *)priv->touchbuf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,12 +40,14 @@
 | 
				
			||||||
#define GT9XX_CONFIG_MAX_LENGTH  240
 | 
					#define GT9XX_CONFIG_MAX_LENGTH  240
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define GT9XX_REG_BAK_REF        0x99D0
 | 
					#define GT9XX_REG_BAK_REF        0x99D0
 | 
				
			||||||
#define GT9XX_REG_MAIN_CLK       0x8020
 | 
					 | 
				
			||||||
#define GT9XX_REG_CHIP_TYPE      0x8000
 | 
					#define GT9XX_REG_CHIP_TYPE      0x8000
 | 
				
			||||||
#define GT9XX_REG_HAVE_KEY       0x804E
 | 
					#define GT9XX_REG_MAIN_CLK       0x8020
 | 
				
			||||||
#define GT9XX_REG_MATRIX_DRVNUM  0x8069
 | 
					 | 
				
			||||||
#define GT9XX_REG_MATRIX_SENNUM  0x806A
 | 
					 | 
				
			||||||
#define GT9XX_REG_COMMAND        0x8040
 | 
					#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_READSTATUS 0
 | 
				
			||||||
#define GT9XX_COMMAND_DIFFERENCE 1
 | 
					#define GT9XX_COMMAND_DIFFERENCE 1
 | 
				
			||||||
| 
						 | 
					@ -54,16 +56,6 @@
 | 
				
			||||||
#define GT9XX_COMMAND_CALCULATE  4
 | 
					#define GT9XX_COMMAND_CALCULATE  4
 | 
				
			||||||
#define GT9XX_COMMAND_TURNOFF    5
 | 
					#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
 | 
					enum touch_event_e
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GT9XX_DOWN    = 0,  /* The state changed to touched */
 | 
					  GT9XX_DOWN    = 0,  /* The state changed to touched */
 | 
				
			||||||
| 
						 | 
					@ -76,10 +68,10 @@ enum touch_event_e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct gt9xx_touch_point_s
 | 
					struct gt9xx_touch_point_s
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  uint8_t xl;
 | 
					 | 
				
			||||||
  uint8_t xh;
 | 
					  uint8_t xh;
 | 
				
			||||||
  uint8_t yl;
 | 
					  uint8_t xl;
 | 
				
			||||||
  uint8_t yh;
 | 
					  uint8_t yh;
 | 
				
			||||||
 | 
					  uint8_t yl;
 | 
				
			||||||
  uint8_t weight;
 | 
					  uint8_t weight;
 | 
				
			||||||
  uint8_t area;
 | 
					  uint8_t area;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -92,60 +84,17 @@ struct gt9xx_touch_data_s
 | 
				
			||||||
  struct gt9xx_touch_point_s touch[GT9XX_MAX_TOUCHES];
 | 
					  struct gt9xx_touch_point_s touch[GT9XX_MAX_TOUCHES];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/****************************************************************************
 | 
					 | 
				
			||||||
 * Pre-processor Definitions
 | 
					 | 
				
			||||||
 ****************************************************************************/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Configuration ************************************************************/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Maximum number of threads than can be waiting for POLL events */
 | 
					/* Maximum number of threads than can be waiting for POLL events */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef CONFIG_GT9XX_NPOLLWAITERS
 | 
					#ifndef CONFIG_GT9XX_NPOLLWAITERS
 | 
				
			||||||
#  define CONFIG_GT9XX_NPOLLWAITERS 2
 | 
					#  define CONFIG_GT9XX_NPOLLWAITERS 2
 | 
				
			||||||
#endif
 | 
					#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) */
 | 
					  uint8_t  address;    /* 7-bit I2C address (only bits 0-6 used) */
 | 
				
			||||||
  uint32_t frequency;  /* Default I2C frequency */
 | 
					  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
 | 
					#ifndef CONFIG_GT9XX_POLLMODE
 | 
				
			||||||
  int  (*attach)(FAR const struct gt9xx_config_s *config, xcpt_t isr,
 | 
					  int  (*attach)(FAR const struct gt9xx_config_s *config, xcpt_t isr,
 | 
				
			||||||
                 FAR void *arg);
 | 
					                 FAR void *arg);
 | 
				
			||||||
| 
						 | 
					@ -157,7 +106,6 @@ struct gt9xx_config_s
 | 
				
			||||||
                 bool state);
 | 
					                 bool state);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
int gt9xx_register(FAR struct i2c_master_s *i2c,
 | 
					int gt9xx_register(FAR struct i2c_master_s *i2c,
 | 
				
			||||||
                    FAR const struct gt9xx_config_s *config, int minor);
 | 
					                    FAR const struct gt9xx_config_s *config, int minor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue