当前位置: 技术问答>linux和unix
重力感应驱动(afa750)-i2c问题
来源: 互联网 发布时间:2017-05-26
本文导语: static int sensor_active(struct i2c_client *client, int enable, int rate) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; int status = 0; sensor->ops->ctrl_data = sensor_read_reg(clie...
static int sensor_active(struct i2c_client *client, int enable, int rate)
{
struct sensor_private_data *sensor =
(struct sensor_private_data *) i2c_get_clientdata(client);
int result = 0;
int status = 0;
sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);
//sensor->ops->ctrl_data = sensor_read_reg(client, client->addr);
//register setting according to chip datasheet
if(enable)
{
status = AFA750_ENABLE; //afa750
sensor->ops->ctrl_data |= status;
}
else
{
status = ~AFA750_ENABLE; //afa750
sensor->ops->ctrl_data &= status;
}
DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%dn",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);
printk("%s:reg=0x%x, addr = 0x%x reg_ctrl_data=0x%x,enable=%dn",__func__,sensor->ops->ctrl_reg, client->addr,sensor->ops->ctrl_data, enable);
result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);
if(result){
printk("%s:fail to active sensor,result = %dn",__func__,result);
}
return result;
}
为什么result返回的会是负值,是不是ctrl_reg和ctrl_data的问题?求大神解答
{
struct sensor_private_data *sensor =
(struct sensor_private_data *) i2c_get_clientdata(client);
int result = 0;
int status = 0;
sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);
//sensor->ops->ctrl_data = sensor_read_reg(client, client->addr);
//register setting according to chip datasheet
if(enable)
{
status = AFA750_ENABLE; //afa750
sensor->ops->ctrl_data |= status;
}
else
{
status = ~AFA750_ENABLE; //afa750
sensor->ops->ctrl_data &= status;
}
DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%dn",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);
printk("%s:reg=0x%x, addr = 0x%x reg_ctrl_data=0x%x,enable=%dn",__func__,sensor->ops->ctrl_reg, client->addr,sensor->ops->ctrl_data, enable);
result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);
if(result){
printk("%s:fail to active sensor,result = %dn",__func__,result);
}
return result;
}
为什么result返回的会是负值,是不是ctrl_reg和ctrl_data的问题?求大神解答
|
sensor_write_reg() 看下这个函数返回值的错误码列表呗
一般出现问题也就是地址错了 看看是不是要chip_id 左移一位
或者外设不通
一般出现问题也就是地址错了 看看是不是要chip_id 左移一位
或者外设不通
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。