Browse Source

drivers: sensor: Removed apds9960 interrupt pin

Made interrupt pin on apds9960 optional

Signed-off-by: Thomas Lang <thomaslang2003@me.com>
pull/89380/head
Thomas Lang 3 months ago committed by Benjamin Cabé
parent
commit
999b8f85c6
  1. 20
      drivers/sensor/apds9960/Kconfig
  2. 21
      drivers/sensor/apds9960/apds9960.c
  3. 6
      drivers/sensor/apds9960/apds9960.h
  4. 1
      dts/bindings/sensor/avago,apds9960.yaml

20
drivers/sensor/apds9960/Kconfig

@ -32,6 +32,26 @@ endchoice @@ -32,6 +32,26 @@ endchoice
config APDS9960_TRIGGER
bool
choice APDS9960_FETCH_MODE
prompt "Fetching Mode"
default APDS9960_FETCH_MODE_INTERRUPT
help
Specify whether to wait for interrupt
config APDS9960_FETCH_MODE_POLL
bool "Poll without interrupt pin"
help
Uses I2C to check sample
config APDS9960_FETCH_MODE_INTERRUPT
bool "Wait for interrupt"
depends on GPIO
depends on $(dt_compat_any_has_prop,$(DT_COMPAT_AVAGO_APDS9960),int-gpios)
help
Wait for interrupt before reading
endchoice
config APDS9960_ENABLE_ALS
bool "Ambient Light Sense"
default y

21
drivers/sensor/apds9960/apds9960.c

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
LOG_MODULE_REGISTER(APDS9960, CONFIG_SENSOR_LOG_LEVEL);
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
static void apds9960_handle_cb(struct apds9960_data *drv_data)
{
apds9960_setup_int(drv_data->dev->config, false);
@ -45,6 +46,7 @@ static void apds9960_gpio_callback(const struct device *dev, @@ -45,6 +46,7 @@ static void apds9960_gpio_callback(const struct device *dev,
apds9960_handle_cb(drv_data);
}
#endif
static int apds9960_sample_fetch(const struct device *dev,
enum sensor_channel chan)
@ -59,6 +61,7 @@ static int apds9960_sample_fetch(const struct device *dev, @@ -59,6 +61,7 @@ static int apds9960_sample_fetch(const struct device *dev,
}
#ifndef CONFIG_APDS9960_TRIGGER
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
apds9960_setup_int(config, true);
#ifdef CONFIG_APDS9960_ENABLE_ALS
@ -71,8 +74,8 @@ static int apds9960_sample_fetch(const struct device *dev, @@ -71,8 +74,8 @@ static int apds9960_sample_fetch(const struct device *dev,
LOG_ERR("Power on bit not set.");
return -EIO;
}
k_sem_take(&data->data_sem, K_FOREVER);
#endif
#endif
if (i2c_reg_read_byte_dt(&config->i2c,
@ -99,12 +102,14 @@ static int apds9960_sample_fetch(const struct device *dev, @@ -99,12 +102,14 @@ static int apds9960_sample_fetch(const struct device *dev,
}
#ifndef CONFIG_APDS9960_TRIGGER
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
if (i2c_reg_update_byte_dt(&config->i2c,
APDS9960_ENABLE_REG,
APDS9960_ENABLE_PON,
0)) {
return -EIO;
}
#endif
#endif
if (i2c_reg_write_byte_dt(&config->i2c,
@ -352,9 +357,18 @@ static int apds9960_sensor_setup(const struct device *dev) @@ -352,9 +357,18 @@ static int apds9960_sensor_setup(const struct device *dev)
}
#endif
#ifdef CONFIG_APDS9960_FETCH_MODE_POLL
if (i2c_reg_update_byte_dt(&config->i2c, APDS9960_ENABLE_REG, APDS9960_ENABLE_PON,
APDS9960_ENABLE_PON)) {
LOG_ERR("Power on bit not set.");
return -EIO;
}
#endif
return 0;
}
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
static int apds9960_init_interrupt(const struct device *dev)
{
const struct apds9960_config *config = dev->config;
@ -400,6 +414,7 @@ static int apds9960_init_interrupt(const struct device *dev) @@ -400,6 +414,7 @@ static int apds9960_init_interrupt(const struct device *dev)
return 0;
}
#endif
#ifdef CONFIG_PM_DEVICE
static int apds9960_pm_action(const struct device *dev,
@ -458,10 +473,12 @@ static int apds9960_init(const struct device *dev) @@ -458,10 +473,12 @@ static int apds9960_init(const struct device *dev)
return -EIO;
}
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
if (apds9960_init_interrupt(dev) < 0) {
LOG_ERR("Failed to initialize interrupt!");
return -EIO;
}
#endif
return 0;
}
@ -477,7 +494,9 @@ static DEVICE_API(sensor, apds9960_driver_api) = { @@ -477,7 +494,9 @@ static DEVICE_API(sensor, apds9960_driver_api) = {
static const struct apds9960_config apds9960_config = {
.i2c = I2C_DT_SPEC_INST_GET(0),
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
.int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios),
#endif
#if CONFIG_APDS9960_PGAIN_8X
.pgain = APDS9960_PGAIN_8X,
#elif CONFIG_APDS9960_PGAIN_4X

6
drivers/sensor/apds9960/apds9960.h

@ -214,7 +214,9 @@ @@ -214,7 +214,9 @@
struct apds9960_config {
struct i2c_dt_spec i2c;
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
struct gpio_dt_spec int_gpio;
#endif
uint8_t pgain;
uint8_t again;
uint8_t ppcount;
@ -231,11 +233,12 @@ struct apds9960_data { @@ -231,11 +233,12 @@ struct apds9960_data {
#ifdef CONFIG_APDS9960_TRIGGER
sensor_trigger_handler_t p_th_handler;
const struct sensor_trigger *p_th_trigger;
#else
#elif CONFIG_APDS9960_FETCH_MODE_INTERRUPT
struct k_sem data_sem;
#endif
};
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
static inline void apds9960_setup_int(const struct apds9960_config *cfg,
bool enable)
{
@ -245,6 +248,7 @@ static inline void apds9960_setup_int(const struct apds9960_config *cfg, @@ -245,6 +248,7 @@ static inline void apds9960_setup_int(const struct apds9960_config *cfg,
gpio_pin_interrupt_configure_dt(&cfg->int_gpio, flags);
}
#endif
#ifdef CONFIG_APDS9960_TRIGGER
void apds9960_work_cb(struct k_work *work);

1
dts/bindings/sensor/avago,apds9960.yaml

@ -10,7 +10,6 @@ include: [sensor-device.yaml, i2c-device.yaml] @@ -10,7 +10,6 @@ include: [sensor-device.yaml, i2c-device.yaml]
properties:
int-gpios:
type: phandle-array
required: true
description: Interrupt pin.
The interrupt pin of APDS9960 is open-drain, active low.

Loading…
Cancel
Save