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