现在的位置: 首页 > 综合 > 正文

如何在TP里面添加距离传感器

2013年05月11日 ⁄ 综合 ⁄ 共 4151字 ⁄ 字号 评论关闭

#define TP_PROXIMITY_SENSOR             //WIGO_ADD for ft6206 psensor 

设置TP支持psensor的宏。

struct ft5x0x_ts_data {
 struct input_dev *input_dev;
 struct i2c_client *client;
 struct ts_event event;
 struct work_struct pen_event_work;
 struct workqueue_struct *ts_workqueue;
 struct early_suspend early_suspend;
 struct ft5x0x_ts_platform_data *platform_data;
// struct timer_list touch_timer;
#ifdef TP_PROXIMITY_SENSOR
    struct input_dev *input_dev_ps;
   unsigned int enable;
   unsigned int control;
#endif

static int ft5x0x_read_data(void)
{
 struct ft5x0x_ts_data *data = i2c_get_clientdata(this_client);
 struct ts_event *event = &data->event;
 u8 buf[32] = {0};
 int ret = -1;
#ifdef TP_PROXIMITY_SENSOR
 u8 buf_ps[2] = {0};
 if(ps_switch_mode == true)
 {
  ret=ft5x0x_i2c_rxdata(buf_ps, 2);
                if(ret < 0){      
        printk("%s read_data i2c_rxdata failed: %d\n", __func__, ret);
                      return ret;
                }
  if(buf_ps[1]==0xc0)//close
  {
          input_report_abs(data->input_dev_ps, ABS_DISTANCE, 1);
   input_sync(data->input_dev_ps);
  }
  else if(buf_ps[1]==0xe0)//far away
  {
   input_report_abs(data->input_dev_ps, ABS_DISTANCE, 0);
   input_sync(data->input_dev_ps);
  }
 }
#endif

static void ft5x0x_ts_suspend(struct early_suspend *handler)
{

#ifdef TP_PROXIMITY_SENSOR
    if(ps_switch_mode==true)

  return -1;
#endif
 printk("==ft5x0x_ts_suspend=\n");
 ft5x0x_write_reg(FT5X0X_REG_PMODE, PMODE_HIBERNATE);

}

static void ft5x0x_ts_resume(struct early_suspend *handler)
{

#ifdef TP_PROXIMITY_SENSOR
        msleep(300);
 ft5x0x_read_reg(FT5X0X_REG_CIPHER, &uc_reg_value);
 printk("FT5X0X_REG_FT5201ID = 0x%x\n",uc_reg_value);//NO 5306 6206 6306 is a3
        if(ps_switch_mode==true && (uc_reg_value == 0x55 || uc_reg_value == 0x06) )

  return -1;
 printk("==%s==\n", __FUNCTION__);
#endif
 ft5x0x_ts_reset();
}

#ifdef TP_PROXIMITY_SENSOR
static ssize_t ft5306_show_enable_ps_sensor(struct device *dev,
    struct device_attribute *attr, char *buf)
{
 struct i2c_client *client = to_i2c_client(dev);
 return sprintf(buf, "%d\n", ps_enable);
}

static ssize_t ft5306_store_enable_ps_sensor(struct device *dev,
    struct device_attribute *attr, const char *buf, size_t count)
{
 struct i2c_client *client = to_i2c_client(dev);
 struct ft5x0x_ts_data *data = i2c_get_clientdata(client);
 unsigned long val = simple_strtoul(buf, NULL, 10);
  unsigned long flags;
 int err;
 char data_cmd[2]={0, 0};
 printk("%s: enable ps senosr ( %ld)\n", __func__, val);
 if ((val != 0) && (val != 1)) {
  printk("%s:store unvalid value=%ld\n", __func__, val);
  return count;
 }
 if(val == 1) {
  ps_switch_mode = true;
  //turn on p sensor
  err = ft5x0x_write_reg(0xB0, 0x01);
  if(err==0) printk("tp_ps: i2c write sucess, err:%d\n", err); 
  else    printk("tp_ps: i2c write fail, err:%d\n", err);
 }
 else {
//turn off p sensor - kk 25 Apr 2011 we can't turn off the entire sensor, the light sensor may be needed by HAL
  ps_switch_mode=false;
  err=ft5x0x_write_reg(0xB0, 0x00);//out ps mode
  if(err==0) printk("tp_ps: i2c write sucess\n");
  else       printk("tp_ps: i2c write fail\n");
 }
 return count;
}

static DEVICE_ATTR(enable_ps_sensor, S_IWUGO | S_IRUGO,
       ft5306_show_enable_ps_sensor, ft5306_store_enable_ps_sensor);

static struct attribute *ft5306_attributes[] = {
 &dev_attr_enable_ps_sensor.attr,
 NULL
};

static const struct attribute_group ft5306_attr_group = {
 .attrs = ft5306_attributes,
};
#endif

 

 

 

static int ft5x0x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
 struct ft5x0x_ts_data *ft5x0x_ts;
 struct input_dev *input_dev;
 struct input_dev *ps_input;
 struct ft5x0x_ts_platform_data *pdata = client->dev.platform_data;
 int err = 0;
 printk(KERN_INFO "%s: probe\n",__func__);

。。。。。

#ifdef TP_PROXIMITY_SENSOR
 ps_input = input_allocate_device();
#endif

#ifdef TP_PROXIMITY_SENSOR
 ft5x0x_ts->input_dev_ps = ps_input;
#endif

#ifdef TP_PROXIMITY_SENSOR
 __set_bit(EV_ABS, ps_input->evbit);
#endif

#ifdef TP_PROXIMITY_SENSOR
 __set_bit(EV_ABS, ps_input->evbit);
#endif

#ifdef TP_PROXIMITY_SENSOR
 input_set_abs_params(ps_input, ABS_DISTANCE, 0, 1, 0, 0);
#endif

 

#ifdef TP_PROXIMITY_SENSOR
 ps_input->name = "FTPS";
 ps_input->id.bustype = BUS_I2C;
#endif

#ifdef TP_PROXIMITY_SENSOR
 err = input_register_device(ps_input);
 if (err)
  goto exit_input_register_device_failed;
#endif

#ifdef TP_PROXIMITY_SENSOR
 err = sysfs_create_group(&client->dev.kobj, &ft5306_attr_group); 
 if (err){
                printk("wigo_ft5306 creat_group is error/n");
  input_unregister_device(ps_input);
        }
#endif

 

 

 

抱歉!评论已关闭.