diff options
-rw-r--r-- | board/samus/board.c | 2 | ||||
-rw-r--r-- | common/als.c | 3 | ||||
-rw-r--r-- | driver/als_isl29035.c | 15 | ||||
-rw-r--r-- | driver/als_isl29035.h | 2 | ||||
-rw-r--r-- | include/als.h | 3 |
5 files changed, 16 insertions, 9 deletions
diff --git a/board/samus/board.c b/board/samus/board.c index a3d68c6a5b..7f5d3be034 100644 --- a/board/samus/board.c +++ b/board/samus/board.c @@ -166,7 +166,7 @@ BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); /* ALS instances. Must be in same order as enum als_id. */ struct als_t als[] = { - {"ISL", isl29035_read_lux}, + {"ISL", isl29035_read_lux, 5}, }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); diff --git a/common/als.c b/common/als.c index 8c6ba9c5f1..e67eb03777 100644 --- a/common/als.c +++ b/common/als.c @@ -17,7 +17,8 @@ int als_read(enum als_id id, int *lux) { - return als[id].read(lux); + int af = als[id].attenuation_factor; + return als[id].read(lux, af); } void als_task(void) diff --git a/driver/als_isl29035.c b/driver/als_isl29035.c index 3eef3a170e..f908e443bd 100644 --- a/driver/als_isl29035.c +++ b/driver/als_isl29035.c @@ -35,7 +35,7 @@ static void isl29035_init(void) } DECLARE_HOOK(HOOK_CHIPSET_RESUME, isl29035_init, HOOK_PRIO_DEFAULT); -int isl29035_read_lux(int *lux) +int isl29035_read_lux(int *lux, int af) { int rv, lsb, msb, data; @@ -62,11 +62,16 @@ int isl29035_read_lux(int *lux) /* * The default power-on values will give 16 bits of precision: - * 0x0000-0xffff indicates 0-1000 lux. If you change the defaults, - * you'll need to change the scale factor accordingly (and maybe this - * expression, to avoid rounding errors). + * 0x0000-0xffff indicates 0-1000 lux. We multiply the sensor value by + * a scaling factor to account for attentuation by glass, tinting, etc. + * + * Caution: Don't go nuts with the attentuation factor. If it's + * greater than 32, the signed int math will roll over and you'll get + * very wrong results. Of course, if you have that much attenuation and + * are still getting useful readings, you probably have your sensor + * pointed directly into the sun. */ - *lux = data * 1000 / 0xffff; + *lux = data * af * 1000 / 0xffff; return EC_SUCCESS; } diff --git a/driver/als_isl29035.h b/driver/als_isl29035.h index 8d3a4ac0f5..212af7a50f 100644 --- a/driver/als_isl29035.h +++ b/driver/als_isl29035.h @@ -8,6 +8,6 @@ #ifndef __CROS_EC_ALS_ILS29035_H #define __CROS_EC_ALS_ILS29035_H -int isl29035_read_lux(int *lux); +int isl29035_read_lux(int *lux, int af); #endif /* __CROS_EC_ALS_ILS29035_H */ diff --git a/include/als.h b/include/als.h index e229a3791f..c2a4e3a01e 100644 --- a/include/als.h +++ b/include/als.h @@ -14,7 +14,8 @@ enum als_id; /* Initialized in board.c */ struct als_t { const char const *name; - int (*read)(int *lux); + int (*read)(int *lux, int af); + int attenuation_factor; }; extern struct als_t als[]; |