Ambient light sensor (ALS) class.
More...
|
| #define | PBL_ALS_LEVEL_MAX 0U |
| | Upper bound of the raw light level scale (CONFIG_ALS_BITS bits).
|
| |
|
| const struct pbl_als *const | ALS |
| | The board's ambient light sensor.
|
| |
Ambient light sensor (ALS) class.
An ambient light sensor is a struct pbl_als device. Readings are raw counts between 0 and PBL_ALS_LEVEL_MAX; a calibrated instance converts them to lux with pbl_als_to_lux().
Sampling is controlled by two reference counts kept by the class: a consumer that will read the sensor soon primes it, and code that would disturb the reading (e.g. backlight bleed-through) suspends it. The driver is told whenever the resulting state changes, and samples while primed and not suspended.
Every call into the driver runs with the device lock held, a recursive mutex.
uint32_t level;
...
}
const struct pbl_als *const ALS
The board's ambient light sensor.
void pbl_als_prime(const struct pbl_als *als)
Announce that readings will be wanted soon.
int pbl_als_read(const struct pbl_als *als, uint32_t *level)
Read the light level.
void pbl_als_release(const struct pbl_als *als)
Drop a reference taken with pbl_als_prime().
uint32_t pbl_als_to_lux(const struct pbl_als *als, uint32_t level)
Convert a light level to lux.
◆ pbl_als_scale
Raw count to lux calibration: lux = (raw - offset) * num / den.
Covers the sensor and the optical path in front of it, so it belongs to the board.
| Data Fields |
|
uint32_t |
den |
Denominator. |
|
uint32_t |
num |
Numerator. |
|
uint32_t |
offset |
Dark offset, in raw counts. |
◆ PBL_ALS_LEVEL_MAX
| #define PBL_ALS_LEVEL_MAX 0U |
Upper bound of the raw light level scale (CONFIG_ALS_BITS bits).
◆ pbl_als_has_lux()
| bool pbl_als_has_lux |
( |
const struct pbl_als * |
als | ) |
|
Check whether the sensor is calibrated to lux.
- Parameters
-
- Returns
- true if pbl_als_to_lux() converts to lux.
◆ pbl_als_is_ready()
| bool pbl_als_is_ready |
( |
const struct pbl_als * |
als | ) |
|
Check whether the sensor is ready.
- Parameters
-
- Returns
- true if the sensor came up.
◆ pbl_als_prime()
| void pbl_als_prime |
( |
const struct pbl_als * |
als | ) |
|
Announce that readings will be wanted soon.
Reference counted; balance with pbl_als_release(). Lets drivers that sample continuously start ahead of the first read. Does nothing if the sensor is not ready.
- Parameters
-
◆ pbl_als_read()
| int pbl_als_read |
( |
const struct pbl_als * |
als, |
|
|
uint32_t * |
level |
|
) |
| |
Read the light level.
- Parameters
-
- Returns
- 0, -ENODEV if the sensor is not ready, or a negative errno.
◆ pbl_als_release()
| void pbl_als_release |
( |
const struct pbl_als * |
als | ) |
|
◆ pbl_als_resume()
| void pbl_als_resume |
( |
const struct pbl_als * |
als | ) |
|
◆ pbl_als_suspend()
| void pbl_als_suspend |
( |
const struct pbl_als * |
als | ) |
|
Stop sampling until the matching pbl_als_resume().
Reference counted. Used while something disturbs the sensor, e.g. backlight bleed-through. Does nothing if the sensor is not ready.
- Parameters
-
◆ pbl_als_to_lux()
| uint32_t pbl_als_to_lux |
( |
const struct pbl_als * |
als, |
|
|
uint32_t |
level |
|
) |
| |
Convert a light level to lux.
On uncalibrated sensors the level is returned unchanged, so callers can use the result unconditionally.
- Parameters
-
| als | Ambient light sensor. |
| level | Light level, after screen compensation if any. |
- Returns
- Light level in lux, or
level if uncalibrated.
◆ ALS
The board's ambient light sensor.