ESPHome 2026.2.1
Loading...
Searching...
No Matches
as7341.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome {
8namespace as7341 {
9
10static const uint8_t AS7341_CHIP_ID = 0x09;
11
12static const uint8_t AS7341_CONFIG = 0x70;
13static const uint8_t AS7341_LED = 0x74;
14
15static const uint8_t AS7341_ENABLE = 0x80;
16static const uint8_t AS7341_ATIME = 0x81;
17
18static const uint8_t AS7341_WTIME = 0x83;
19
20static const uint8_t AS7341_AUXID = 0x90;
21static const uint8_t AS7341_REVID = 0x91;
22static const uint8_t AS7341_ID = 0x92;
23static const uint8_t AS7341_STATUS = 0x93;
24
25static const uint8_t AS7341_CH0_DATA_L = 0x95;
26static const uint8_t AS7341_CH0_DATA_H = 0x96;
27static const uint8_t AS7341_CH1_DATA_L = 0x97;
28static const uint8_t AS7341_CH1_DATA_H = 0x98;
29static const uint8_t AS7341_CH2_DATA_L = 0x99;
30static const uint8_t AS7341_CH2_DATA_H = 0x9A;
31static const uint8_t AS7341_CH3_DATA_L = 0x9B;
32static const uint8_t AS7341_CH3_DATA_H = 0x9C;
33static const uint8_t AS7341_CH4_DATA_L = 0x9D;
34static const uint8_t AS7341_CH4_DATA_H = 0x9E;
35static const uint8_t AS7341_CH5_DATA_L = 0x9F;
36static const uint8_t AS7341_CH5_DATA_H = 0xA0;
37
38static const uint8_t AS7341_STATUS2 = 0xA3;
39
40static const uint8_t AS7341_CFG1 = 0xAA;
41
42static const uint8_t AS7341_CFG6 = 0xAF; // Stores SMUX command
43static const uint8_t AS7341_CFG9 = 0xB2; // Config for system interrupts (SMUX, Flicker detection)
44
45static const uint8_t AS7341_ASTEP = 0xCA; // LSB
46static const uint8_t AS7341_ASTEP_MSB = 0xCB; // MSB
47
56
62
76
78 public:
79 void setup() override;
80 void dump_config() override;
81 void update() override;
82
83 void set_f1_sensor(sensor::Sensor *f1_sensor) { this->f1_ = f1_sensor; }
84 void set_f2_sensor(sensor::Sensor *f2_sensor) { f2_ = f2_sensor; }
85 void set_f3_sensor(sensor::Sensor *f3_sensor) { f3_ = f3_sensor; }
86 void set_f4_sensor(sensor::Sensor *f4_sensor) { f4_ = f4_sensor; }
87 void set_f5_sensor(sensor::Sensor *f5_sensor) { f5_ = f5_sensor; }
88 void set_f6_sensor(sensor::Sensor *f6_sensor) { f6_ = f6_sensor; }
89 void set_f7_sensor(sensor::Sensor *f7_sensor) { f7_ = f7_sensor; }
90 void set_f8_sensor(sensor::Sensor *f8_sensor) { f8_ = f8_sensor; }
91 void set_clear_sensor(sensor::Sensor *clear_sensor) { clear_ = clear_sensor; }
92 void set_nir_sensor(sensor::Sensor *nir_sensor) { nir_ = nir_sensor; }
93
95 void set_atime(uint8_t atime) { atime_ = atime; }
96 void set_astep(uint16_t astep) { astep_ = astep; }
97
99 uint8_t get_atime();
100 uint16_t get_astep();
102 bool setup_atime(uint8_t atime);
103 bool setup_astep(uint16_t astep);
104
106 bool read_channels(uint16_t *data);
107 void set_smux_low_channels(bool enable);
111 bool enable_smux();
112
113 bool wait_for_data();
114 bool is_data_ready();
115 bool enable_power(bool enable);
116 bool enable_spectral_measurement(bool enable);
117
118 bool read_register_bit(uint8_t address, uint8_t bit_position);
119 bool write_register_bit(uint8_t address, bool value, uint8_t bit_position);
120 bool set_register_bit(uint8_t address, uint8_t bit_position);
121 bool clear_register_bit(uint8_t address, uint8_t bit_position);
122 uint16_t swap_bytes(uint16_t data);
123
124 protected:
135
136 uint16_t astep_;
138 uint8_t atime_;
139 uint16_t channel_readings_[12];
140};
141
142} // namespace as7341
143} // namespace esphome
uint8_t address
Definition bl0906.h:4
This class simplifies creating components that periodically check a state.
Definition component.h:512
void set_clear_sensor(sensor::Sensor *clear_sensor)
Definition as7341.h:91
bool setup_atime(uint8_t atime)
Definition as7341.cpp:116
void set_f5_sensor(sensor::Sensor *f5_sensor)
Definition as7341.h:87
void set_nir_sensor(sensor::Sensor *nir_sensor)
Definition as7341.h:92
void set_astep(uint16_t astep)
Definition as7341.h:96
bool setup_gain(AS7341Gain gain)
Definition as7341.cpp:114
void set_f6_sensor(sensor::Sensor *f6_sensor)
Definition as7341.h:88
void set_gain(AS7341Gain gain)
Definition as7341.h:94
bool read_register_bit(uint8_t address, uint8_t bit_position)
Definition as7341.cpp:238
void set_f1_sensor(sensor::Sensor *f1_sensor)
Definition as7341.h:83
void set_f8_sensor(sensor::Sensor *f8_sensor)
Definition as7341.h:90
bool clear_register_bit(uint8_t address, uint8_t bit_position)
Definition as7341.cpp:260
bool enable_power(bool enable)
Definition as7341.cpp:232
uint16_t read_channel(AS7341AdcChannel channel)
bool read_channels(uint16_t *data)
Definition as7341.cpp:120
bool set_smux_command(AS7341SmuxCommand command)
Definition as7341.cpp:147
void set_f3_sensor(sensor::Sensor *f3_sensor)
Definition as7341.h:85
void set_f2_sensor(sensor::Sensor *f2_sensor)
Definition as7341.h:84
bool setup_astep(uint16_t astep)
Definition as7341.cpp:118
void set_smux_low_channels(bool enable)
Definition as7341.cpp:134
void set_f7_sensor(sensor::Sensor *f7_sensor)
Definition as7341.h:89
uint16_t swap_bytes(uint16_t data)
Definition as7341.cpp:267
bool enable_spectral_measurement(bool enable)
Definition as7341.cpp:234
bool set_register_bit(uint8_t address, uint8_t bit_position)
Definition as7341.cpp:253
void set_atime(uint8_t atime)
Definition as7341.h:95
void set_f4_sensor(sensor::Sensor *f4_sensor)
Definition as7341.h:86
bool write_register_bit(uint8_t address, bool value, uint8_t bit_position)
Definition as7341.cpp:245
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
Base-class for all sensors.
Definition sensor.h:43
AlsGain501 gain
@ AS7341_SMUX_CMD_READ
Read SMUX configuration to RAM from SMUX chain.
Definition as7341.h:59
@ AS7341_SMUX_CMD_WRITE
Write SMUX configuration from RAM to SMUX chain.
Definition as7341.h:60
@ AS7341_SMUX_CMD_ROM_RESET
ROM code initialization of SMUX.
Definition as7341.h:58
@ AS7341_ADC_CHANNEL_5
Definition as7341.h:54
@ AS7341_ADC_CHANNEL_0
Definition as7341.h:49
@ AS7341_ADC_CHANNEL_3
Definition as7341.h:52
@ AS7341_ADC_CHANNEL_1
Definition as7341.h:50
@ AS7341_ADC_CHANNEL_4
Definition as7341.h:53
@ AS7341_ADC_CHANNEL_2
Definition as7341.h:51
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7