Ambient light sensor (ALS) class.
More...
|
| static const uint32_t | AMBIENT_LIGHT_LEVEL_MAX = (1U << CONFIG_AMBIENT_LIGHT_BITS) |
| | Upper bound of the raw light level scale (CONFIG_AMBIENT_LIGHT_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 AMBIENT_LIGHT_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_state
Ambient light sensor runtime state.
| Data Fields |
|
struct pbl_mutex |
lock |
Device lock. |
|
uint16_t |
prime_count |
Prime references. |
|
uint16_t |
suspend_count |
Suspend references. |
◆ pbl_als
◆ PBL_ALS_INIT
| #define PBL_ALS_INIT |
( |
|
sym, |
|
|
|
_name, |
|
|
|
_parent, |
|
|
|
_ops, |
|
|
|
_scale |
|
) |
| |
Value: { \
.ops = (_ops), \
.state = &sym##_als_state, \
.scale = (_scale), \
}
#define PBL_DEVICE_INIT(sym, _name, _init, _parent, _deps)
Initializer for the struct pbl_device of device instance sym.
Definition device.h:142
Initialize a struct pbl_als.
- Parameters
-
| sym | Symbol of the instance, as passed to PBL_ALS_STATE_DEFINE(). |
| _name | Device name. |
| _parent | Parent device. |
| _ops | Driver operations. |
| _scale | Lux calibration, or NULL. |
◆ PBL_ALS_STATE_DEFINE
| #define PBL_ALS_STATE_DEFINE |
( |
|
sym | ) |
|
Value:
struct pbl_mutex lock
Device lock.
Definition als.h:82
Ambient light sensor runtime state.
Definition als.h:80
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:109
#define PBL_MUTEX_INITIALIZER
Static initializer for an unlocked mutex.
Definition mutex.h:50
Define the class state of an ambient light sensor.
- Parameters
-
| sym | Symbol of the instance. |
◆ 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_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.
◆ AMBIENT_LIGHT_LEVEL_MAX
| const uint32_t AMBIENT_LIGHT_LEVEL_MAX = (1U << CONFIG_AMBIENT_LIGHT_BITS) |
|
static |
Upper bound of the raw light level scale (CONFIG_AMBIENT_LIGHT_BITS bits).