Line data Source code
1 1 : /*
2 : * Copyright (c) 2025 Andreas Klinger
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief Header file for extended sensor API of VEML6031 sensor
10 : * @ingroup veml6031_interface
11 : */
12 :
13 : #ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_VEML6031_H_
14 : #define ZEPHYR_INCLUDE_DRIVERS_SENSOR_VEML6031_H_
15 :
16 : /**
17 : * @defgroup veml6031_interface VEML6031
18 : * @ingroup sensor_interface_ext
19 : * @brief Vishay VEML6031 High Accuracy Ambient Light Sensor
20 : * @{
21 : */
22 :
23 : #ifdef __cplusplus
24 : extern "C" {
25 : #endif
26 :
27 : /**
28 : * @brief VEML6031 integration time options for ambient light measurements.
29 : *
30 : * Possible values for @ref SENSOR_ATTR_VEML6031_IT custom attribute.
31 : */
32 1 : enum veml6031_it {
33 : VEML6031_IT_3_125, /**< 3.125 ms */
34 : VEML6031_IT_6_25, /**< 6.25 ms */
35 : VEML6031_IT_12_5, /**< 12.5 ms */
36 : VEML6031_IT_25, /**< 25 ms */
37 : VEML6031_IT_50, /**< 50 ms */
38 : VEML6031_IT_100, /**< 100 ms */
39 : VEML6031_IT_200, /**< 200 ms */
40 : VEML6031_IT_400, /**< 400 ms */
41 : /** @cond INTERNAL_HIDDEN */
42 : VEML6031_IT_COUNT,
43 : /** @endcond */
44 : };
45 :
46 : /**
47 : * @brief VEML6031 size options for ambient light measurements.
48 : *
49 : * Possible values for @ref SENSOR_ATTR_VEML6031_DIV4 custom attribute.
50 : */
51 1 : enum veml6031_div4 {
52 : VEML6031_SIZE_4_4 = 0x00, /**< 4/4 photodiode size */
53 : VEML6031_SIZE_1_4 = 0x01, /**< 1/4 photodiode size */
54 : /** @cond INTERNAL_HIDDEN */
55 : VEML6031_DIV4_COUNT = 2,
56 : /** @endcond */
57 : };
58 :
59 : /**
60 : * @brief VEML6031 gain options for ambient light measurements.
61 : */
62 1 : enum veml6031_gain {
63 : VEML6031_GAIN_1 = 0x00, /**< 1x gain */
64 : VEML6031_GAIN_2 = 0x01, /**< 2x gain */
65 : VEML6031_GAIN_0_66 = 0x02, /**< 0.66x gain */
66 : VEML6031_GAIN_0_5 = 0x03, /**< 0.5x gain */
67 : /** @cond INTERNAL_HIDDEN */
68 : VEML6031_GAIN_COUNT = 4,
69 : /** @endcond */
70 : };
71 :
72 : /**
73 : * @brief VEML6031 ALS interrupt persistence protect number options.
74 : *
75 : * Possible values for @ref SENSOR_ATTR_VEML6031_PERS custom attribute.
76 : */
77 1 : enum veml6031_pers {
78 : VEML6031_PERS_1 = 0x00, /**< 1 measurement */
79 : VEML6031_PERS_2 = 0x01, /**< 2 measurements */
80 : VEML6031_PERS_4 = 0x02, /**< 4 measurements */
81 : VEML6031_PERS_8 = 0x03, /**< 8 measurements */
82 : };
83 :
84 : /**
85 : * @brief Custom sensor attributes for VEML6031 sensor.
86 : *
87 : * For high and low threshold window settings (ALS_WH_L, ALS_WH_H, ALS_WL_L and
88 : * ALS_WL_H) use the generic attributes @ref SENSOR_ATTR_UPPER_THRESH and
89 : * @ref SENSOR_ATTR_LOWER_THRESH with 16-bit unsigned integer values. Both
90 : * threshold settings are in lux and converted by the driver to a value
91 : * compatible with the sensor. This conversion depends on the current gain,
92 : * integration time and effective photodiode size settings. So a change in
93 : * gain, integration time or effective photodiode size usually requires an
94 : * update of threshold window settings. To get the correct threshold values
95 : * into the sensor update the thresholds -after- a change of gain or
96 : * integration time.
97 : *
98 : * All attributes must be set for the @ref SENSOR_CHAN_LIGHT channel.
99 : *
100 : * When the sensor goes into saturation @c -E2BIG is returned. This
101 : * happens when the maximum value <tt>0xFFFF</tt> is returned as raw ALS value.
102 : * In this case it's up to the user to reduce one or more of the following
103 : * attributes to come back into the optimal measurement range of the sensor:
104 : * - @ref SENSOR_ATTR_VEML6031_GAIN (gain)
105 : * - @ref SENSOR_ATTR_VEML6031_IT (integration time)
106 : * - @ref SENSOR_ATTR_VEML6031_DIV4 (effective photodiode size)
107 : */
108 1 : enum sensor_attribute_veml6031 {
109 : /**
110 : * @brief Integration time setting for ALS measurements (IT).
111 : *
112 : * Use enum veml6031_it for attribute values.
113 : */
114 : SENSOR_ATTR_VEML6031_IT = SENSOR_ATTR_PRIV_START,
115 : /**
116 : * @brief Effective photodiode size (DIV4)
117 : *
118 : * Use enum veml6031_div4 for attribute values.
119 : */
120 : SENSOR_ATTR_VEML6031_DIV4,
121 : /**
122 : * @brief Gain setting for ALS measurements (GAIN).
123 : *
124 : * Use enum veml6031_gain for attribute values.
125 : */
126 : SENSOR_ATTR_VEML6031_GAIN,
127 : /**
128 : * @brief ALS persistence protect number setting (PERS).
129 : *
130 : * Use enum veml6031_pers for attribute values.
131 : */
132 : SENSOR_ATTR_VEML6031_PERS,
133 : };
134 :
135 : /**
136 : * @brief Custom sensor channels for VEML6031 sensor.
137 : */
138 1 : enum sensor_channel_veml6031 {
139 : /**
140 : * @brief Channel for raw ALS sensor values.
141 : *
142 : * This channel represents the raw measurement counts provided by the
143 : * sensor ALS register. It is useful for estimating good values for
144 : * integration time, effective photodiode size and gain attributes in
145 : * fetch and get mode.
146 : *
147 : * For future implementations with triggers it can also be used to
148 : * estimate the threshold window attributes for the sensor interrupt
149 : * handling.
150 : *
151 : * It cannot be fetched directly. Instead, this channel's value is
152 : * fetched implicitly using @ref SENSOR_CHAN_LIGHT. Trying to call
153 : * @ref sensor_sample_fetch_chan with this enumerator as an
154 : * argument will result in a @c -ENOTSUP.
155 : */
156 : SENSOR_CHAN_VEML6031_ALS_RAW_COUNTS = SENSOR_CHAN_PRIV_START,
157 :
158 : /**
159 : * @brief Channel for IR sensor values.
160 : *
161 : * This channel is the raw IR Channel count output of the sensor. About
162 : * fetching the same as for
163 : * @ref SENSOR_CHAN_VEML6031_ALS_RAW_COUNTS applies.
164 : */
165 : SENSOR_CHAN_VEML6031_IR_RAW_COUNTS,
166 : };
167 :
168 : #ifdef __cplusplus
169 : }
170 : #endif
171 :
172 : /**
173 : * @}
174 : */
175 :
176 : #endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_VEML6031_H_ */
|