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