ESPHome  2024.9.2
ltr_definitions_501.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstdint>
4 
5 namespace esphome {
6 namespace ltr501 {
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 AlsGain501 : uint8_t {
44  GAIN_1 = 0, // GAIN_RANGE_2 // default
45  GAIN_150 = 1, // GAIN_RANGE_1
46 };
47 static const uint8_t GAINS_COUNT = 2;
48 
49 // ALS Sensor integration times
50 enum IntegrationTime501 : uint8_t {
51  INTEGRATION_TIME_100MS = 0, // default
52  INTEGRATION_TIME_50MS = 1, // only in Dynamic GAIN_RANGE_2
53  INTEGRATION_TIME_200MS = 2, // only in Dynamic GAIN_RANGE_1
54  INTEGRATION_TIME_400MS = 3, // only in Dynamic GAIN_RANGE_1
55 };
56 static const uint8_t TIMES_COUNT = 4;
57 
58 // ALS Sensor measurement repeat rate
63  REPEAT_RATE_500MS = 3, // default
66 };
67 
68 // PS Sensor gain levels
69 enum PsGain501 : uint8_t {
70  PS_GAIN_1 = 0, // default
71  PS_GAIN_4 = 1,
72  PS_GAIN_8 = 2,
74 };
75 
76 // LED Pulse Modulation Frequency
77 enum PsLedFreq : uint8_t {
81  PS_LED_FREQ_60KHZ = 3, // default
86 };
87 
88 // LED current duty
89 enum PsLedDuty : uint8_t {
91  PS_LED_DUTY_50 = 1, // default
94 };
95 
96 // LED pulsed current level
97 enum PsLedCurrent : uint8_t {
101  PS_LED_CURRENT_50MA = 3, // default
106 };
107 
108 // PS measurement rate
109 enum PsMeasurementRate : uint8_t {
112  PS_MEAS_RATE_100MS = 2, // default
118 };
119 
120 //
121 // ALS_CONTR Register (0x80)
122 //
124  uint8_t raw;
125  struct {
126  bool asl_mode_xxx : 1;
127  bool als_mode_active : 1;
128  bool sw_reset : 1;
130  uint8_t reserved : 4;
131  } __attribute__((packed));
132 };
133 
134 //
135 // PS_CONTR Register (0x81)
136 //
138  uint8_t raw;
139  struct {
140  bool ps_mode_xxx : 1;
141  bool ps_mode_active : 1;
143  bool reserved_4 : 1;
144  bool reserved_5 : 1;
145  bool reserved_6 : 1;
146  bool reserved_7 : 1;
147  } __attribute__((packed));
148 };
149 
150 //
151 // PS_LED Register (0x82)
152 //
154  uint8_t raw;
155  struct {
159  } __attribute__((packed));
160 };
161 
162 //
163 // PS_N_PULSES Register (0x83)
164 //
166  uint8_t raw;
168 };
169 
170 //
171 // PS_MEAS_RATE Register (0x84)
172 //
174  uint8_t raw;
175  struct {
177  uint8_t reserved : 4;
178  } __attribute__((packed));
179 };
180 
181 //
182 // ALS_MEAS_RATE Register (0x85)
183 //
185  uint8_t raw;
186  struct {
189  bool reserved_5 : 1;
190  bool reserved_6 : 1;
191  bool reserved_7 : 1;
192  } __attribute__((packed));
193 };
194 
195 //
196 // PART_ID Register (0x86) (Read Only)
197 //
199  uint8_t raw;
200  struct {
201  uint8_t part_number_id : 4;
202  uint8_t revision_id : 4;
203  } __attribute__((packed));
204 };
205 
206 //
207 // ALS_PS_STATUS Register (0x8C) (Read Only)
208 //
210  uint8_t raw;
211  struct {
212  bool ps_new_data : 1; // 0 - old data, 1 - new data
213  bool ps_interrupt : 1; // 0 - interrupt signal not active, 1 - interrupt signal active
214  bool als_new_data : 1; // 0 - old data, 1 - new data
215  bool als_interrupt : 1; // 0 - interrupt signal not active, 1 - interrupt signal active
216  AlsGain501 gain : 1; // current ALS gain
217  bool reserved_5 : 1;
218  bool reserved_6 : 1;
219  bool reserved_7 : 1;
220  } __attribute__((packed));
221 };
222 
223 //
224 // PS_DATA_1 Register (0x8E) (Read Only)
225 //
227  uint8_t raw;
228  struct {
229  uint8_t ps_data_high : 3;
230  uint8_t reserved : 4;
232  } __attribute__((packed));
233 };
234 
235 //
236 // INTERRUPT Register (0x8F) (Read Only)
237 //
239  uint8_t raw;
240  struct {
241  bool ps_interrupt : 1;
242  bool als_interrupt : 1;
243  bool interrupt_polarity : 1; // 0 - active low (default), 1 - active high
244  uint8_t reserved : 5;
245  } __attribute__((packed));
246 };
247 
248 //
249 // INTERRUPT_PERSIST Register (0x9E)
250 //
252  uint8_t raw;
253  struct {
254  uint8_t als_persist : 4; // 0 - every ALS cycle, 1 - every 2 ALS cycles, ... 15 - every 16 ALS cycles
255  uint8_t ps_persist : 4; // 0 - every PS cycle, 1 - every 2 PS cycles, ... 15 - every 16 PS cycles
256  } __attribute__((packed));
257 };
258 
259 } // namespace ltr501
260 } // namespace esphome
bool reserved_4
PsGain501 ps_gain
PsLedCurrent ps_led_current
uint8_t part_number_id
bool asl_mode_xxx
bool ps_new_data
bool reserved_6
bool als_new_data
AlsGain501 gain
bool als_interrupt
MeasurementRepeatRate measurement_repeat_rate
uint8_t als_persist
uint8_t reserved
bool ps_interrupt
enum esphome::EntityCategory __attribute__
PsLedDuty ps_led_duty
bool sw_reset
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool ps_mode_active
bool ps_mode_xxx
bool als_mode_active
bool reserved_5