Skip to content
Permalink
Browse files

drivers: apds9960: make proximity pulse length configurable

Make proximity pulse length and pulse count 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 67ae508 commit df3796a724889f639c90bd8dd9ce6d0ebac9d85b
Showing with 42 additions and 5 deletions.
  1. +23 −0 drivers/sensor/apds9960/Kconfig
  2. +14 −1 drivers/sensor/apds9960/apds9960.c
  3. +5 −4 drivers/sensor/apds9960/apds9960.h
@@ -74,4 +74,27 @@ config APDS9960_AGAIN_64X

endchoice

choice
prompt "Proximity Pulse Length"
default APDS9960_PPULSE_LENGTH_8US

config APDS9960_PPULSE_LENGTH_4US
bool "4us"

config APDS9960_PPULSE_LENGTH_8US
bool "8us"

config APDS9960_PPULSE_LENGTH_16US
bool "16us"

config APDS9960_PPULSE_LENGTH_32US
bool "32us"

endchoice

config APDS9960_PPULSE_COUNT
int "Proximity Pulse Count"
range 1 64
default 8

endif # APDS9960
@@ -164,7 +164,7 @@ static int apds9960_proxy_setup(struct device *dev)

if (i2c_reg_write_byte(data->i2c, config->i2c_address,
APDS9960_PPULSE_REG,
APDS9960_DEFAULT_PROX_PPULSE)) {
config->ppcount)) {
LOG_ERR("Default pulse count not set ");
return -EIO;
}
@@ -496,6 +496,19 @@ static const struct apds9960_config apds9960_config = {
#else
.again = APDS9960_AGAIN_1X,
#endif
#if CONFIG_APDS9960_PPULSE_LENGTH_32US
.ppcount = APDS9960_PPULSE_LENGTH_32US |
(CONFIG_APDS9960_PPULSE_COUNT - 1),
#elif CONFIG_APDS9960_PPULSE_LENGTH_16US
.ppcount = APDS9960_PPULSE_LENGTH_16US |
(CONFIG_APDS9960_PPULSE_COUNT - 1),
#elif CONFIG_APDS9960_PPULSE_LENGTH_8US
.ppcount = APDS9960_PPULSE_LENGTH_8US |
(CONFIG_APDS9960_PPULSE_COUNT - 1),
#else
.ppcount = APDS9960_PPULSE_LENGTH_4US |
(CONFIG_APDS9960_PPULSE_COUNT - 1),
#endif
};

static struct apds9960_data apds9960_data;
@@ -36,9 +36,10 @@
#define APDS9960_CONFIG1_WLONG BIT(1)

#define APDS9960_PPULSE_REG 0x8E
#define APDS9960_PPULSE_PLEN (BIT(7) | BIT(6))
#define APDS9960_PPULSE_PULSE (BIT(5) | BIT(4) | BIT(3) |\
BIT(2) | BIT(1) | BIT(0))
#define APDS9960_PPULSE_LENGTH_4US 0
#define APDS9960_PPULSE_LENGTH_8US BIT(6)
#define APDS9960_PPULSE_LENGTH_16US BIT(7)
#define APDS9960_PPULSE_LENGTH_32US (BIT(7) | BIT(6))

#define APDS9960_CONTROL_REG 0x8F
#define APDS9960_CONTROL_LDRIVE (BIT(6) | BIT(7))
@@ -183,7 +184,6 @@
#define APDS9960_DEFAULT_CONFIG1 0x60
#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
@@ -220,6 +220,7 @@ struct apds9960_config {
u8_t i2c_address;
u8_t pgain;
u8_t again;
u8_t ppcount;
};

struct apds9960_data {

0 comments on commit df3796a

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