目录
1.apds9960_driver_api接口函数实现说明
1.1sample_fetch
static int apds9960_sample_fetch(struct device *dev, enum sensor_channel chan)
{
const struct apds9960_config *config = dev->config->config_info;
struct apds9960_data *data = dev->driver_data;
u8_t status;
if (chan != SENSOR_CHAN_ALL) {
LOG_ERR("Unsupported sensor channel");
return -ENOTSUP;
}
//设置中断回调函数 函数
#ifndef CONFIG_APDS9960_TRIGGER
gpio_pin_enable_callback(data->gpio, config->gpio_pin);
//打开ADPS 接近和光感器 中断 寄存器
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
APDS9960_ENABLE_REG,
APDS9960_ENABLE_PON | APDS9960_ENABLE_AIEN,
APDS9960_ENABLE_PON | APDS9960_ENABLE_AIEN)) {
LOG_ERR("Power on bit not set.");
return -EIO;
}
//信号量等待
k_sem_take(&data->data_sem, K_FOREVER);
#endif
//读取传感器当前 接近还是光感
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
APDS9960_STATUS_REG, &status)) {
return -EIO;
}
//接近传感器 读取
LOG_DBG("status: 0x%x", status);
if (status & APDS9960_STATUS_PINT) {
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
APDS9960_PDATA_REG, &data->pdata)) {
return -EIO;
}
}
//环境光 CRGB 读取
if (status & APDS9960_STATUS_AINT) {
if (i2c_burst_read(data->i2c, config->i2c_address,
APDS9960_CDATAL_REG,
(u8_t *)&data->sample_crgb,
sizeof(data->sample_crgb))) {
return -EIO;
}