drivers: sensor: apds9960: Update driver to use i2c_dt_spec
Move driver to use i2c_dt_spec for I2C bus access. Signed-off-by: Kumar Gala <galak@kernel.org>
This commit is contained in:
parent
fa74cadbf0
commit
cf947c5b13
3 changed files with 47 additions and 60 deletions
|
@ -66,7 +66,7 @@ static int apds9960_sample_fetch(const struct device *dev,
|
||||||
#else
|
#else
|
||||||
tmp = APDS9960_ENABLE_PON | APDS9960_ENABLE_PIEN;
|
tmp = APDS9960_ENABLE_PON | APDS9960_ENABLE_PIEN;
|
||||||
#endif
|
#endif
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG, tmp, tmp)) {
|
APDS9960_ENABLE_REG, tmp, tmp)) {
|
||||||
LOG_ERR("Power on bit not set.");
|
LOG_ERR("Power on bit not set.");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -75,21 +75,21 @@ static int apds9960_sample_fetch(const struct device *dev,
|
||||||
k_sem_take(&data->data_sem, K_FOREVER);
|
k_sem_take(&data->data_sem, K_FOREVER);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte_dt(&config->i2c,
|
||||||
APDS9960_STATUS_REG, &tmp)) {
|
APDS9960_STATUS_REG, &tmp)) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("status: 0x%x", tmp);
|
LOG_DBG("status: 0x%x", tmp);
|
||||||
if (tmp & APDS9960_STATUS_PINT) {
|
if (tmp & APDS9960_STATUS_PINT) {
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte_dt(&config->i2c,
|
||||||
APDS9960_PDATA_REG, &data->pdata)) {
|
APDS9960_PDATA_REG, &data->pdata)) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp & APDS9960_STATUS_AINT) {
|
if (tmp & APDS9960_STATUS_AINT) {
|
||||||
if (i2c_burst_read(data->i2c, config->i2c_address,
|
if (i2c_burst_read_dt(&config->i2c,
|
||||||
APDS9960_CDATAL_REG,
|
APDS9960_CDATAL_REG,
|
||||||
(uint8_t *)&data->sample_crgb,
|
(uint8_t *)&data->sample_crgb,
|
||||||
sizeof(data->sample_crgb))) {
|
sizeof(data->sample_crgb))) {
|
||||||
|
@ -99,7 +99,7 @@ static int apds9960_sample_fetch(const struct device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_APDS9960_TRIGGER
|
#ifndef CONFIG_APDS9960_TRIGGER
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG,
|
APDS9960_ENABLE_REG,
|
||||||
APDS9960_ENABLE_PON,
|
APDS9960_ENABLE_PON,
|
||||||
0)) {
|
0)) {
|
||||||
|
@ -107,7 +107,7 @@ static int apds9960_sample_fetch(const struct device *dev,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_AICLEAR_REG, 0)) {
|
APDS9960_AICLEAR_REG, 0)) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -154,30 +154,29 @@ static int apds9960_channel_get(const struct device *dev,
|
||||||
static int apds9960_proxy_setup(const struct device *dev)
|
static int apds9960_proxy_setup(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct apds9960_config *config = dev->config;
|
const struct apds9960_config *config = dev->config;
|
||||||
struct apds9960_data *data = dev->data;
|
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_POFFSET_UR_REG,
|
APDS9960_POFFSET_UR_REG,
|
||||||
APDS9960_DEFAULT_POFFSET_UR)) {
|
APDS9960_DEFAULT_POFFSET_UR)) {
|
||||||
LOG_ERR("Default offset UR not set ");
|
LOG_ERR("Default offset UR not set ");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_POFFSET_DL_REG,
|
APDS9960_POFFSET_DL_REG,
|
||||||
APDS9960_DEFAULT_POFFSET_DL)) {
|
APDS9960_DEFAULT_POFFSET_DL)) {
|
||||||
LOG_ERR("Default offset DL not set ");
|
LOG_ERR("Default offset DL not set ");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_PPULSE_REG,
|
APDS9960_PPULSE_REG,
|
||||||
config->ppcount)) {
|
config->ppcount)) {
|
||||||
LOG_ERR("Default pulse count not set ");
|
LOG_ERR("Default pulse count not set ");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_CONTROL_REG,
|
APDS9960_CONTROL_REG,
|
||||||
APDS9960_CONTROL_LDRIVE,
|
APDS9960_CONTROL_LDRIVE,
|
||||||
APDS9960_DEFAULT_LDRIVE)) {
|
APDS9960_DEFAULT_LDRIVE)) {
|
||||||
|
@ -185,7 +184,7 @@ static int apds9960_proxy_setup(const struct device *dev)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_CONFIG2_REG,
|
APDS9960_CONFIG2_REG,
|
||||||
APDS9960_PLED_BOOST_300,
|
APDS9960_PLED_BOOST_300,
|
||||||
config->pled_boost)) {
|
config->pled_boost)) {
|
||||||
|
@ -193,26 +192,26 @@ static int apds9960_proxy_setup(const struct device *dev)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_CONTROL_REG, APDS9960_CONTROL_PGAIN,
|
APDS9960_CONTROL_REG, APDS9960_CONTROL_PGAIN,
|
||||||
(config->pgain & APDS9960_PGAIN_8X))) {
|
(config->pgain & APDS9960_PGAIN_8X))) {
|
||||||
LOG_ERR("Gain is not set");
|
LOG_ERR("Gain is not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_PILT_REG, APDS9960_DEFAULT_PILT)) {
|
APDS9960_PILT_REG, APDS9960_DEFAULT_PILT)) {
|
||||||
LOG_ERR("Low threshold not set");
|
LOG_ERR("Low threshold not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_PIHT_REG, APDS9960_DEFAULT_PIHT)) {
|
APDS9960_PIHT_REG, APDS9960_DEFAULT_PIHT)) {
|
||||||
LOG_ERR("High threshold not set");
|
LOG_ERR("High threshold not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG, APDS9960_ENABLE_PEN,
|
APDS9960_ENABLE_REG, APDS9960_ENABLE_PEN,
|
||||||
APDS9960_ENABLE_PEN)) {
|
APDS9960_ENABLE_PEN)) {
|
||||||
LOG_ERR("Proximity mode is not enabled");
|
LOG_ERR("Proximity mode is not enabled");
|
||||||
|
@ -226,18 +225,17 @@ static int apds9960_proxy_setup(const struct device *dev)
|
||||||
static int apds9960_ambient_setup(const struct device *dev)
|
static int apds9960_ambient_setup(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct apds9960_config *config = dev->config;
|
const struct apds9960_config *config = dev->config;
|
||||||
struct apds9960_data *data = dev->data;
|
|
||||||
uint16_t th;
|
uint16_t th;
|
||||||
|
|
||||||
/* ADC value */
|
/* ADC value */
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_ATIME_REG, APDS9960_DEFAULT_ATIME)) {
|
APDS9960_ATIME_REG, APDS9960_DEFAULT_ATIME)) {
|
||||||
LOG_ERR("Default integration time not set for ADC");
|
LOG_ERR("Default integration time not set for ADC");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ALS Gain */
|
/* ALS Gain */
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_CONTROL_REG,
|
APDS9960_CONTROL_REG,
|
||||||
APDS9960_CONTROL_AGAIN,
|
APDS9960_CONTROL_AGAIN,
|
||||||
(config->again & APDS9960_AGAIN_64X))) {
|
(config->again & APDS9960_AGAIN_64X))) {
|
||||||
|
@ -246,7 +244,7 @@ static int apds9960_ambient_setup(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
th = sys_cpu_to_le16(APDS9960_DEFAULT_AILT);
|
th = sys_cpu_to_le16(APDS9960_DEFAULT_AILT);
|
||||||
if (i2c_burst_write(data->i2c, config->i2c_address,
|
if (i2c_burst_write_dt(&config->i2c,
|
||||||
APDS9960_INT_AILTL_REG,
|
APDS9960_INT_AILTL_REG,
|
||||||
(uint8_t *)&th, sizeof(th))) {
|
(uint8_t *)&th, sizeof(th))) {
|
||||||
LOG_ERR("ALS low threshold not set");
|
LOG_ERR("ALS low threshold not set");
|
||||||
|
@ -254,7 +252,7 @@ static int apds9960_ambient_setup(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
th = sys_cpu_to_le16(APDS9960_DEFAULT_AIHT);
|
th = sys_cpu_to_le16(APDS9960_DEFAULT_AIHT);
|
||||||
if (i2c_burst_write(data->i2c, config->i2c_address,
|
if (i2c_burst_write_dt(&config->i2c,
|
||||||
APDS9960_INT_AIHTL_REG,
|
APDS9960_INT_AIHTL_REG,
|
||||||
(uint8_t *)&th, sizeof(th))) {
|
(uint8_t *)&th, sizeof(th))) {
|
||||||
LOG_ERR("ALS low threshold not set");
|
LOG_ERR("ALS low threshold not set");
|
||||||
|
@ -262,7 +260,7 @@ static int apds9960_ambient_setup(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable ALS */
|
/* Enable ALS */
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG, APDS9960_ENABLE_AEN,
|
APDS9960_ENABLE_REG, APDS9960_ENABLE_AEN,
|
||||||
APDS9960_ENABLE_AEN)) {
|
APDS9960_ENABLE_AEN)) {
|
||||||
LOG_ERR("ALS is not enabled");
|
LOG_ERR("ALS is not enabled");
|
||||||
|
@ -276,10 +274,9 @@ static int apds9960_ambient_setup(const struct device *dev)
|
||||||
static int apds9960_sensor_setup(const struct device *dev)
|
static int apds9960_sensor_setup(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct apds9960_config *config = dev->config;
|
const struct apds9960_config *config = dev->config;
|
||||||
struct apds9960_data *data = dev->data;
|
|
||||||
uint8_t chip_id;
|
uint8_t chip_id;
|
||||||
|
|
||||||
if (i2c_reg_read_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_read_byte_dt(&config->i2c,
|
||||||
APDS9960_ID_REG, &chip_id)) {
|
APDS9960_ID_REG, &chip_id)) {
|
||||||
LOG_ERR("Failed reading chip id");
|
LOG_ERR("Failed reading chip id");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -291,52 +288,52 @@ static int apds9960_sensor_setup(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable all functions and interrupts */
|
/* Disable all functions and interrupts */
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG, 0)) {
|
APDS9960_ENABLE_REG, 0)) {
|
||||||
LOG_ERR("ENABLE register is not cleared");
|
LOG_ERR("ENABLE register is not cleared");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_AICLEAR_REG, 0)) {
|
APDS9960_AICLEAR_REG, 0)) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable gesture interrupt */
|
/* Disable gesture interrupt */
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_GCONFIG4_REG, 0)) {
|
APDS9960_GCONFIG4_REG, 0)) {
|
||||||
LOG_ERR("GCONFIG4 register is not cleared");
|
LOG_ERR("GCONFIG4 register is not cleared");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_WTIME_REG, APDS9960_DEFAULT_WTIME)) {
|
APDS9960_WTIME_REG, APDS9960_DEFAULT_WTIME)) {
|
||||||
LOG_ERR("Default wait time not set");
|
LOG_ERR("Default wait time not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_CONFIG1_REG,
|
APDS9960_CONFIG1_REG,
|
||||||
APDS9960_DEFAULT_CONFIG1)) {
|
APDS9960_DEFAULT_CONFIG1)) {
|
||||||
LOG_ERR("Default WLONG not set");
|
LOG_ERR("Default WLONG not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_CONFIG2_REG,
|
APDS9960_CONFIG2_REG,
|
||||||
APDS9960_DEFAULT_CONFIG2)) {
|
APDS9960_DEFAULT_CONFIG2)) {
|
||||||
LOG_ERR("Configuration Register Two not set");
|
LOG_ERR("Configuration Register Two not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_CONFIG3_REG,
|
APDS9960_CONFIG3_REG,
|
||||||
APDS9960_DEFAULT_CONFIG3)) {
|
APDS9960_DEFAULT_CONFIG3)) {
|
||||||
LOG_ERR("Configuration Register Three not set");
|
LOG_ERR("Configuration Register Three not set");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_PERS_REG,
|
APDS9960_PERS_REG,
|
||||||
APDS9960_DEFAULT_PERS)) {
|
APDS9960_DEFAULT_PERS)) {
|
||||||
LOG_ERR("Interrupt persistence not set");
|
LOG_ERR("Interrupt persistence not set");
|
||||||
|
@ -388,7 +385,7 @@ static int apds9960_init_interrupt(const struct device *dev)
|
||||||
#ifdef CONFIG_APDS9960_TRIGGER
|
#ifdef CONFIG_APDS9960_TRIGGER
|
||||||
drv_data->work.handler = apds9960_work_cb;
|
drv_data->work.handler = apds9960_work_cb;
|
||||||
drv_data->dev = dev;
|
drv_data->dev = dev;
|
||||||
if (i2c_reg_update_byte(drv_data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG,
|
APDS9960_ENABLE_REG,
|
||||||
APDS9960_ENABLE_PON,
|
APDS9960_ENABLE_PON,
|
||||||
APDS9960_ENABLE_PON)) {
|
APDS9960_ENABLE_PON)) {
|
||||||
|
@ -413,12 +410,11 @@ static int apds9960_pm_action(const struct device *dev,
|
||||||
enum pm_device_action action)
|
enum pm_device_action action)
|
||||||
{
|
{
|
||||||
const struct apds9960_config *config = dev->config;
|
const struct apds9960_config *config = dev->config;
|
||||||
struct apds9960_data *data = dev->data;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case PM_DEVICE_ACTION_RESUME:
|
case PM_DEVICE_ACTION_RESUME:
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG,
|
APDS9960_ENABLE_REG,
|
||||||
APDS9960_ENABLE_PON,
|
APDS9960_ENABLE_PON,
|
||||||
APDS9960_ENABLE_PON)) {
|
APDS9960_ENABLE_PON)) {
|
||||||
|
@ -426,13 +422,13 @@ static int apds9960_pm_action(const struct device *dev,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PM_DEVICE_ACTION_SUSPEND:
|
case PM_DEVICE_ACTION_SUSPEND:
|
||||||
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
APDS9960_ENABLE_REG,
|
APDS9960_ENABLE_REG,
|
||||||
APDS9960_ENABLE_PON, 0)) {
|
APDS9960_ENABLE_PON, 0)) {
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
APDS9960_AICLEAR_REG, 0)) {
|
APDS9960_AICLEAR_REG, 0)) {
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
}
|
}
|
||||||
|
@ -452,11 +448,9 @@ static int apds9960_init(const struct device *dev)
|
||||||
|
|
||||||
/* Initialize time 5.7ms */
|
/* Initialize time 5.7ms */
|
||||||
k_sleep(K_MSEC(6));
|
k_sleep(K_MSEC(6));
|
||||||
data->i2c = device_get_binding(config->i2c_name);
|
|
||||||
|
|
||||||
if (data->i2c == NULL) {
|
if (!device_is_ready(config->i2c.bus)) {
|
||||||
LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Bus device is not ready");
|
||||||
config->i2c_name);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,8 +480,7 @@ static const struct sensor_driver_api apds9960_driver_api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct apds9960_config apds9960_config = {
|
static const struct apds9960_config apds9960_config = {
|
||||||
.i2c_name = DT_INST_BUS_LABEL(0),
|
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||||
.i2c_address = DT_INST_REG_ADDR(0),
|
|
||||||
.gpio_name = DT_INST_GPIO_LABEL(0, int_gpios),
|
.gpio_name = DT_INST_GPIO_LABEL(0, int_gpios),
|
||||||
.gpio_pin = DT_INST_GPIO_PIN(0, int_gpios),
|
.gpio_pin = DT_INST_GPIO_PIN(0, int_gpios),
|
||||||
.gpio_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
|
.gpio_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
|
||||||
|
|
|
@ -213,11 +213,10 @@
|
||||||
#define APDS9960_DEFAULT_GCONF3 0
|
#define APDS9960_DEFAULT_GCONF3 0
|
||||||
|
|
||||||
struct apds9960_config {
|
struct apds9960_config {
|
||||||
char *i2c_name;
|
struct i2c_dt_spec i2c;
|
||||||
char *gpio_name;
|
char *gpio_name;
|
||||||
uint8_t gpio_pin;
|
uint8_t gpio_pin;
|
||||||
unsigned int gpio_flags;
|
unsigned int gpio_flags;
|
||||||
uint8_t i2c_address;
|
|
||||||
uint8_t pgain;
|
uint8_t pgain;
|
||||||
uint8_t again;
|
uint8_t again;
|
||||||
uint8_t ppcount;
|
uint8_t ppcount;
|
||||||
|
@ -225,7 +224,6 @@ struct apds9960_config {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct apds9960_data {
|
struct apds9960_data {
|
||||||
const struct device *i2c;
|
|
||||||
const struct device *gpio;
|
const struct device *gpio;
|
||||||
struct gpio_callback gpio_cb;
|
struct gpio_callback gpio_cb;
|
||||||
struct k_work work;
|
struct k_work work;
|
||||||
|
|
|
@ -37,24 +37,21 @@ int apds9960_attr_set(const struct device *dev,
|
||||||
const struct sensor_value *val)
|
const struct sensor_value *val)
|
||||||
{
|
{
|
||||||
const struct apds9960_config *config = dev->config;
|
const struct apds9960_config *config = dev->config;
|
||||||
struct apds9960_data *data = dev->data;
|
|
||||||
|
|
||||||
if (chan == SENSOR_CHAN_PROX) {
|
if (chan == SENSOR_CHAN_PROX) {
|
||||||
if (attr == SENSOR_ATTR_UPPER_THRESH) {
|
if (attr == SENSOR_ATTR_UPPER_THRESH) {
|
||||||
if (i2c_reg_write_byte(data->i2c,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
config->i2c_address,
|
APDS9960_PIHT_REG,
|
||||||
APDS9960_PIHT_REG,
|
(uint8_t)val->val1)) {
|
||||||
(uint8_t)val->val1)) {
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (attr == SENSOR_ATTR_LOWER_THRESH) {
|
if (attr == SENSOR_ATTR_LOWER_THRESH) {
|
||||||
if (i2c_reg_write_byte(data->i2c,
|
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||||
config->i2c_address,
|
APDS9960_PILT_REG,
|
||||||
APDS9960_PILT_REG,
|
(uint8_t)val->val1)) {
|
||||||
(uint8_t)val->val1)) {
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +75,10 @@ int apds9960_trigger_set(const struct device *dev,
|
||||||
case SENSOR_TRIG_THRESHOLD:
|
case SENSOR_TRIG_THRESHOLD:
|
||||||
if (trig->chan == SENSOR_CHAN_PROX) {
|
if (trig->chan == SENSOR_CHAN_PROX) {
|
||||||
data->p_th_handler = handler;
|
data->p_th_handler = handler;
|
||||||
if (i2c_reg_update_byte(data->i2c,
|
if (i2c_reg_update_byte_dt(&config->i2c,
|
||||||
config->i2c_address,
|
APDS9960_ENABLE_REG,
|
||||||
APDS9960_ENABLE_REG,
|
APDS9960_ENABLE_PIEN,
|
||||||
APDS9960_ENABLE_PIEN,
|
APDS9960_ENABLE_PIEN)) {
|
||||||
APDS9960_ENABLE_PIEN)) {
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue