ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
ltr_definitions.h
Go to the documentation of this file.
1#pragma once
3#include <cstdint>
7enum class CommandRegisters : uint8_t {
8 ALS_CONTR = 0x80, // ALS operation mode control and SW reset
9 PS_CONTR = 0x81, // PS operation mode control
10 PS_LED = 0x82, // PS LED pulse frequency control
11 PS_N_PULSES = 0x83, // PS number of pulses control
12 PS_MEAS_RATE = 0x84, // PS measurement rate in active mode
13 MEAS_RATE = 0x85, // ALS measurement rate in active mode
14 PART_ID = 0x86, // Part Number ID and Revision ID
15 MANUFAC_ID = 0x87, // Manufacturer ID
16 ALS_DATA_CH1_0 = 0x88, // ALS measurement CH1 data, lower byte - infrared only
17 ALS_DATA_CH1_1 = 0x89, // ALS measurement CH1 data, upper byte - infrared only
18 ALS_DATA_CH0_0 = 0x8A, // ALS measurement CH0 data, lower byte - visible + infrared
19 ALS_DATA_CH0_1 = 0x8B, // ALS measurement CH0 data, upper byte - visible + infrared
20 ALS_PS_STATUS = 0x8C, // ALS PS new data status
21 PS_DATA_0 = 0x8D, // PS measurement data, lower byte
22 PS_DATA_1 = 0x8E, // PS measurement data, upper byte
23 ALS_PS_INTERRUPT = 0x8F, // Interrupt status
24 PS_THRES_UP_0 = 0x90, // PS interrupt upper threshold, lower byte
25 PS_THRES_UP_1 = 0x91, // PS interrupt upper threshold, upper byte
26 PS_THRES_LOW_0 = 0x92, // PS interrupt lower threshold, lower byte
27 PS_THRES_LOW_1 = 0x93, // PS interrupt lower threshold, upper byte
28 PS_OFFSET_1 = 0x94, // PS offset, upper byte
29 PS_OFFSET_0 = 0x95, // PS offset, lower byte
30 // 0x96 - reserved
31 ALS_THRES_UP_0 = 0x97, // ALS interrupt upper threshold, lower byte
32 ALS_THRES_UP_1 = 0x98, // ALS interrupt upper threshold, upper byte
33 ALS_THRES_LOW_0 = 0x99, // ALS interrupt lower threshold, lower byte
34 ALS_THRES_LOW_1 = 0x9A, // ALS interrupt lower threshold, upper byte
35 // 0x9B - reserved
36 // 0x9C - reserved
37 // 0x9D - reserved
38 INTERRUPT_PERSIST = 0x9E // Interrupt persistence filter
39};
40
41// ALS Sensor gain levels
42enum AlsGain : uint8_t {
43 GAIN_1 = 0, // default
44 GAIN_2 = 1,
45 GAIN_4 = 2,
46 GAIN_8 = 3,
49};
50static const uint8_t GAINS_COUNT = 6;
51
52// ALS Sensor integration times
63static const uint8_t TIMES_COUNT = 8;
64
65// ALS Sensor measurement repeat rate
74
75// PS Sensor gain levels
76enum PsGain : uint8_t {
77 PS_GAIN_16 = 0, // default
80};
81
82// PS Mode
89
90// LED Pulse Modulation Frequency
101
102// LED current duty
103enum PsLedDuty : uint8_t {
107 PS_LED_DUTY_100 = 3, // default
108};
109
110// LED pulsed current level
121
122// PS measurement rate
134
135//
136// ALS_CONTR Register (0x80)
137//
139 uint8_t raw;
140 struct {
141 bool active_mode : 1;
142 bool sw_reset : 1;
144 uint8_t reserved : 3;
145 } __attribute__((packed));
146};
147
148//
149// PS_CONTR Register (0x81)
150//
152 uint8_t raw;
153 struct {
154 bool ps_mode_xxx : 1;
156 PsGain ps_gain : 2; // only LTR-659/558
157 bool reserved_4 : 1;
159 bool reserved_6 : 1;
160 bool reserved_7 : 1;
161 } __attribute__((packed));
162};
163
164//
165// PS_LED Register (0x82)
166//
174};
175
176//
177// PS_N_PULSES Register (0x83)
178//
180 uint8_t raw;
181 struct {
182 uint8_t number_of_pulses : 4;
183 uint8_t reserved : 4;
184 } __attribute__((packed));
185};
186
187//
188// PS_MEAS_RATE Register (0x84)
189//
191 uint8_t raw;
192 struct {
194 uint8_t reserved : 4;
195 } __attribute__((packed));
196};
197
198//
199// ALS_MEAS_RATE Register (0x85)
200//
210
211//
212// PART_ID Register (0x86) (Read Only)
213//
215 uint8_t raw;
216 struct {
217 uint8_t part_number_id : 4;
218 uint8_t revision_id : 4;
219 } __attribute__((packed));
220};
221
222//
223// ALS_PS_STATUS Register (0x8C) (Read Only)
224//
226 uint8_t raw;
227 struct {
228 bool ps_new_data : 1; // 0 - old data, 1 - new data
229 bool ps_interrupt : 1; // 0 - interrupt signal not active, 1 - interrupt signal active
230 bool als_new_data : 1; // 0 - old data, 1 - new data
231 bool als_interrupt : 1; // 0 - interrupt signal not active, 1 - interrupt signal active
232 AlsGain gain : 3; // current ALS gain
233 bool data_invalid : 1;
234 } __attribute__((packed));
235};
236
237//
238// PS_DATA_1 Register (0x8E) (Read Only)
239//
241 uint8_t raw;
242 struct {
243 uint8_t ps_data_high : 3;
244 uint8_t reserved : 4;
246 } __attribute__((packed));
247};
248
249//
250// INTERRUPT Register (0x8F) (Read Only)
251//
253 uint8_t raw;
254 struct {
255 bool ps_interrupt : 1;
257 bool interrupt_polarity : 1; // 0 - active low (default), 1 - active high
258 uint8_t reserved : 5;
259 } __attribute__((packed));
260};
261
262//
263// INTERRUPT_PERSIST Register (0x9E)
264//
266 uint8_t raw;
267 struct {
268 uint8_t als_persist : 4; // 0 - every ALS cycle, 1 - every 2 ALS cycles, ... 15 - every 16 ALS cycles
269 uint8_t ps_persist : 4; // 0 - every PS cycle, 1 - every 2 PS cycles, ... 15 - every 16 PS cycles
270 } __attribute__((packed));
271};
272
273} // namespace esphome::ltr_als_ps
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32