ESPHome  2024.12.2
ltr_definitions.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstdint>
4 
5 namespace esphome {
6 namespace ltr_als_ps {
7 
8 enum 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
43 enum AlsGain : uint8_t {
44  GAIN_1 = 0, // default
45  GAIN_2 = 1,
46  GAIN_4 = 2,
47  GAIN_8 = 3,
48  GAIN_48 = 6,
49  GAIN_96 = 7,
50 };
51 static const uint8_t GAINS_COUNT = 6;
52 
53 // ALS Sensor integration times
54 enum IntegrationTime : uint8_t {
55  INTEGRATION_TIME_100MS = 0, // default
63 };
64 static const uint8_t TIMES_COUNT = 8;
65 
66 // ALS Sensor measurement repeat rate
71  REPEAT_RATE_500MS = 3, // default
74 };
75 
76 // PS Sensor gain levels
77 enum PsGain : uint8_t {
78  PS_GAIN_16 = 0, // default
81 };
82 
83 // PS Mode
84 enum PsMode : uint8_t {
85  PS_MODE_STANDBY_00 = 0, // default
89 };
90 
91 // LED Pulse Modulation Frequency
92 enum PsLedFreq : uint8_t {
96  PS_LED_FREQ_60KHZ = 3, // default
101 };
102 
103 // LED current duty
104 enum PsLedDuty : uint8_t {
108  PS_LED_DUTY_100 = 3, // default
109 };
110 
111 // LED pulsed current level
112 enum PsLedCurrent : uint8_t {
117  PS_LED_CURRENT_100MA = 4, // default
121 };
122 
123 // PS measurement rate
124 enum PsMeasurementRate : uint8_t {
129  PS_MEAS_RATE_500MS = 4, // default
134 };
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;
156  bool ps_mode_active : 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 //
169  uint8_t raw;
170  struct {
174  } __attribute__((packed));
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 //
203  uint8_t raw;
204  struct {
207  bool reserved_6 : 1;
208  bool reserved_7 : 1;
209  } __attribute__((packed));
210 };
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;
257  bool als_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
bool als_new_data
bool ps_mode_xxx
MeasurementRepeatRate measurement_repeat_rate
PsLedCurrent ps_led_current
bool ps_interrupt
PsGain ps_gain
bool reserved_6
bool reserved_4
bool active_mode
uint8_t reserved
bool als_interrupt
AlsGain gain
uint8_t part_number_id
PsLedDuty ps_led_duty
uint8_t als_persist
enum esphome::ltr_als_ps::DataAvail __attribute__
bool ps_mode_active
bool ps_saturation_indicator_enable
bool ps_new_data
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool sw_reset