Skip to content
Permalink
Browse files

drivers: apds9960: make ALS and proximity gain configurable

Make ALS and proximity gain configurable.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
  • Loading branch information...
jfischer-phytec-iot authored and MaureenHelm committed May 13, 2019
1 parent 3bbd102 commit 67ae5084596e09ef48dec4473ef0d849fd9791b2
Showing with 62 additions and 8 deletions.
  1. +36 −0 drivers/sensor/apds9960/Kconfig
  2. +24 −6 drivers/sensor/apds9960/apds9960.c
  3. +2 −2 drivers/sensor/apds9960/apds9960.h
@@ -38,4 +38,40 @@ config APDS9960_ENABLE_ALS
help
Enable Ambient Light Sense (ALS).

choice
prompt "Proximity Gain"
default APDS9960_PGAIN_4X

config APDS9960_PGAIN_1X
bool "1x"

config APDS9960_PGAIN_2X
bool "2x"

config APDS9960_PGAIN_4X
bool "4x"

config APDS9960_PGAIN_8X
bool "8x"

endchoice

choice
prompt "ALS and Color Gain"
default APDS9960_AGAIN_4X

config APDS9960_AGAIN_1X
bool "1x"

config APDS9960_AGAIN_4X
bool "4x"

config APDS9960_AGAIN_16X
bool "16x"

config APDS9960_AGAIN_64X
bool "64x"

endchoice

endif # APDS9960
@@ -143,7 +143,7 @@ static int apds9960_channel_get(struct device *dev,
return 0;
}

static int apds9960_proxy_setup(struct device *dev, int gain)
static int apds9960_proxy_setup(struct device *dev)
{
const struct apds9960_config *config = dev->config->config_info;
struct apds9960_data *data = dev->driver_data;
@@ -179,7 +179,7 @@ static int apds9960_proxy_setup(struct device *dev, int gain)

if (i2c_reg_update_byte(data->i2c, config->i2c_address,
APDS9960_CONTROL_REG, APDS9960_CONTROL_PGAIN,
(gain & APDS9960_PGAIN_8X))) {
(config->pgain & APDS9960_PGAIN_8X))) {
LOG_ERR("Gain is not set");
return -EIO;
}
@@ -207,7 +207,7 @@ static int apds9960_proxy_setup(struct device *dev, int gain)
}

#ifdef CONFIG_APDS9960_ENABLE_ALS
static int apds9960_ambient_setup(struct device *dev, int gain)
static int apds9960_ambient_setup(struct device *dev)
{
const struct apds9960_config *config = dev->config->config_info;
struct apds9960_data *data = dev->driver_data;
@@ -224,7 +224,7 @@ static int apds9960_ambient_setup(struct device *dev, int gain)
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
APDS9960_CONTROL_REG,
APDS9960_CONTROL_AGAIN,
(gain & APDS9960_AGAIN_64X))) {
(config->again & APDS9960_AGAIN_64X))) {
LOG_ERR("Ambient Gain is not set");
return -EIO;
}
@@ -327,13 +327,13 @@ static int apds9960_sensor_setup(struct device *dev)
return -EIO;
}

if (apds9960_proxy_setup(dev, APDS9960_DEFAULT_PGAIN)) {
if (apds9960_proxy_setup(dev)) {
LOG_ERR("Failed to setup proximity functionality");
return -EIO;
}

#ifdef CONFIG_APDS9960_ENABLE_ALS
if (apds9960_ambient_setup(dev, APDS9960_DEFAULT_AGAIN)) {
if (apds9960_ambient_setup(dev)) {
LOG_ERR("Failed to setup ambient light functionality");
return -EIO;
}
@@ -478,6 +478,24 @@ static const struct apds9960_config apds9960_config = {
.i2c_address = DT_AVAGO_APDS9960_0_BASE_ADDRESS,
.gpio_name = DT_AVAGO_APDS9960_0_INT_GPIOS_CONTROLLER,
.gpio_pin = DT_AVAGO_APDS9960_0_INT_GPIOS_PIN,
#if CONFIG_APDS9960_PGAIN_8X
.pgain = APDS9960_PGAIN_8X,
#elif CONFIG_APDS9960_PGAIN_4X
.pgain = APDS9960_PGAIN_4X,
#elif CONFIG_APDS9960_PGAIN_2X
.pgain = APDS9960_PGAIN_2X,
#else
.pgain = APDS9960_PGAIN_1X,
#endif
#if CONFIG_APDS9960_AGAIN_64X
.again = APDS9960_AGAIN_64X,
#elif CONFIG_APDS9960_AGAIN_16X
.again = APDS9960_AGAIN_16X,
#elif CONFIG_APDS9960_AGAIN_4X
.again = APDS9960_AGAIN_4X,
#else
.again = APDS9960_AGAIN_1X,
#endif
};

static struct apds9960_data apds9960_data;
@@ -181,15 +181,13 @@
#define APDS9960_DEFAULT_ATIME 219
#define APDS9960_DEFAULT_WTIME 255
#define APDS9960_DEFAULT_CONFIG1 0x60
#define APDS9960_DEFAULT_AGAIN APDS9960_AGAIN_4X
#define APDS9960_DEFAULT_PERS BIT(4)
#define APDS9960_DEFAULT_CONFIG2 (BIT(6) | BIT(0))
#define APDS9960_DEFAULT_PROX_PPULSE 0x87
#define APDS9960_DEFAULT_GESTURE_PPULSE 0x89
#define APDS9960_DEFAULT_POFFSET_UR 0
#define APDS9960_DEFAULT_POFFSET_DL 0
#define APDS9960_DEFAULT_LDRIVE APDS9960_LED_DRIVE_100MA
#define APDS9960_DEFAULT_PGAIN APDS9960_PGAIN_4X

#ifdef CONFIG_APDS9960_TRIGGER
#define APDS9960_DEFAULT_PILT 0
@@ -220,6 +218,8 @@ struct apds9960_config {
char *gpio_name;
u8_t gpio_pin;
u8_t i2c_address;
u8_t pgain;
u8_t again;
};

struct apds9960_data {

0 comments on commit 67ae508

Please sign in to comment.
You can’t perform that action at this time.