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