页次: 1
有朋友把这触摸改成电阻屏么如NS2009
经过2天努力终于把NS2009搞通了。 为了简单直接在gt911里面修改的!
共享一下代码:
修改GT911.C的GT911_Read_XY
void GT911_Read_XY(tp_dev_t * tp_devx)
{
#ifdef USE_NS2009 //NS2009 电阻屏
uint16_t x, y, z1;
   z1=ns2009_read(NS2009_READ_Z1_LOW_POWER_12BIT);    
    //if ((z1 >= NS2009_PEN_UP_Z1_ERR) &&(z1 <2000))
  if ((z1 >= NS2009_PEN_UP_Z1_ERR))  
    {
    x=ns2009_read(NS2009_READ_X_LOW_POWER_12BIT);
    y=ns2009_read(NS2009_READ_Y_LOW_POWER_12BIT);    
        tp_devx->status = 1;
      tp_devx->x=(x-X_Origin)*X_Adapt_Width/X_Width;
    tp_devx->y=(y-Y_Origin)*Y_Adapt_Heigth/Y_Heigth;    
    }
  else                   
  {
    tp_devx->status = 0;
  }
#else//gt911 电容屏
   uint8_t touch_status, touch_num, temp, buf[5];
  GT911_Read_Reg(GT_GSTID_REG, &touch_status, 1);
  touch_num = touch_status & 0x0F;
  if(touch_status)
  {
    if(touch_num)
    {
      tp_devx->status = 1;
      GT911_Read_Reg(GT9x_TP1, buf, 4); //读取XY坐标值
      tp_devx->x = (((uint16_t)buf[1] << 8) + buf[0]);
      tp_devx->y = (((uint16_t)buf[3] << 8) + buf[2]);
    }
    else
    {
      tp_devx->status = 0;
    }
    temp = 0;
    GT911_Write_Reg(GT_GSTID_REG, &temp, 1); // 清除READY标志
  }
#endif
}
在gt911.h
增加
#define USE_NS2009 1
#ifdef USE_NS2009
#define POLL_INTERVAL 30
/* this driver uses 12-bit readout */
#define MAX_12BIT    0xfff
#define TOUCH_I2C_NAME            "i2c0"
#define NS2009_Device_ID        "ns2009"
#define NS2009_READ_X_LOW_POWER_12BIT      0xc0
#define NS2009_READ_Y_LOW_POWER_12BIT      0xd0
#define NS2009_READ_Z1_LOW_POWER_12BIT    0xe0
#define NS2009_READ_Z2_LOW_POWER_12BIT    0xf0
#define NS2009_DEF_X_FUZZ    32
#define NS2009_DEF_Y_FUZZ    16
#define NS2009_PEN_UP_Z1_ERR 60
#define NS2009_Addr (0x90>>1)
#define TP_THREAD_PRIORITY 25
#define TP_THREAD_STACK_SIZE 512
#define TP_THREAD_TIMESLICE 5
#define X_Origin         300
#define X_Width            (3870-300)
#define X_Adapt_Width    800
#define Y_Origin        380
#define Y_Heigth        (3900-380)
#define Y_Adapt_Heigth    480
#endif
在f1cx00s_i2c.c增加一个 ns2009_read
uint16_t ns2009_read(uint8_t _cmd)
{
    uint8_t Data[2];
  uint16_t tp_adc;
  I2C_Start(I2C0);
  I2C_Send_Data(I2C0, NS2009_ADDR_WRITE);
  I2C_Send_Data(I2C0, _cmd);
    I2C_Stop(I2C0);
  I2C_Start(I2C0);
  I2C_Send_Data(I2C0, NS2009_ADDR_READ);
  I2C_Receive_Data(I2C0, &Data, 2);  
  I2C_Stop(I2C0);
  tp_adc=((uint16_t)Data[0]<<8)+Data[1];
  tp_adc=(tp_adc>>4)&0xfff;  
    return tp_adc;
}
通过这个 #define USE_NS2009 1 控制使用NS2009 还是GT911
页次: 1