ESPHome 2025.5.0
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 float get_setup_priority() const override;
82 void update() override;
83
84 void set_f1_sensor(sensor::Sensor *f1_sensor) { this->f1_ = f1_sensor; }
85 void set_f2_sensor(sensor::Sensor *f2_sensor) { f2_ = f2_sensor; }
86 void set_f3_sensor(sensor::Sensor *f3_sensor) { f3_ = f3_sensor; }
87 void set_f4_sensor(sensor::Sensor *f4_sensor) { f4_ = f4_sensor; }
88 void set_f5_sensor(sensor::Sensor *f5_sensor) { f5_ = f5_sensor; }
89 void set_f6_sensor(sensor::Sensor *f6_sensor) { f6_ = f6_sensor; }
90 void set_f7_sensor(sensor::Sensor *f7_sensor) { f7_ = f7_sensor; }
91 void set_f8_sensor(sensor::Sensor *f8_sensor) { f8_ = f8_sensor; }
92 void set_clear_sensor(sensor::Sensor *clear_sensor) { clear_ = clear_sensor; }
93 void set_nir_sensor(sensor::Sensor *nir_sensor) { nir_ = nir_sensor; }
94
96 void set_atime(uint8_t atime) { atime_ = atime; }
97 void set_astep(uint16_t astep) { astep_ = astep; }
98
100 uint8_t get_atime();
101 uint16_t get_astep();
103 bool setup_atime(uint8_t atime);
104 bool setup_astep(uint16_t astep);
105
107 bool read_channels(uint16_t *data);
108 void set_smux_low_channels(bool enable);
112 bool enable_smux();
113
114 bool wait_for_data();
115 bool is_data_ready();
116 bool enable_power(bool enable);
117 bool enable_spectral_measurement(bool enable);
118
119 bool read_register_bit(uint8_t address, uint8_t bit_position);
120 bool write_register_bit(uint8_t address, bool value, uint8_t bit_position);
121 bool set_register_bit(uint8_t address, uint8_t bit_position);
122 bool clear_register_bit(uint8_t address, uint8_t bit_position);
123 uint16_t swap_bytes(uint16_t data);
124
125 protected:
136
137 uint16_t astep_;
139 uint8_t atime_;
140 uint16_t channel_readings_[12];
141};
142
143} // namespace as7341
144} // namespace esphome
uint8_t address
Definition bl0906.h:4
This class simplifies creating components that periodically check a state.
Definition component.h:301
float get_setup_priority() const override
Definition as7341.cpp:60
void set_clear_sensor(sensor::Sensor *clear_sensor)
Definition as7341.h:92
bool setup_atime(uint8_t atime)
Definition as7341.cpp:117
void set_f5_sensor(sensor::Sensor *f5_sensor)
Definition as7341.h:88
void set_nir_sensor(sensor::Sensor *nir_sensor)
Definition as7341.h:93
void set_astep(uint16_t astep)
Definition as7341.h:97
bool setup_gain(AS7341Gain gain)
Definition as7341.cpp:115
void set_f6_sensor(sensor::Sensor *f6_sensor)
Definition as7341.h:89
void set_gain(AS7341Gain gain)
Definition as7341.h:95
bool read_register_bit(uint8_t address, uint8_t bit_position)
Definition as7341.cpp:239
void set_f1_sensor(sensor::Sensor *f1_sensor)
Definition as7341.h:84
void set_f8_sensor(sensor::Sensor *f8_sensor)
Definition as7341.h:91
bool clear_register_bit(uint8_t address, uint8_t bit_position)
Definition as7341.cpp:261
bool enable_power(bool enable)
Definition as7341.cpp:233
uint16_t read_channel(AS7341AdcChannel channel)
bool read_channels(uint16_t *data)
Definition as7341.cpp:121
bool set_smux_command(AS7341SmuxCommand command)
Definition as7341.cpp:148
void set_f3_sensor(sensor::Sensor *f3_sensor)
Definition as7341.h:86
void set_f2_sensor(sensor::Sensor *f2_sensor)
Definition as7341.h:85
bool setup_astep(uint16_t astep)
Definition as7341.cpp:119
void set_smux_low_channels(bool enable)
Definition as7341.cpp:135
void set_f7_sensor(sensor::Sensor *f7_sensor)
Definition as7341.h:90
uint16_t swap_bytes(uint16_t data)
Definition as7341.cpp:268
bool enable_spectral_measurement(bool enable)
Definition as7341.cpp:235
bool set_register_bit(uint8_t address, uint8_t bit_position)
Definition as7341.cpp:254
void set_atime(uint8_t atime)
Definition as7341.h:96
void set_f4_sensor(sensor::Sensor *f4_sensor)
Definition as7341.h:87
bool write_register_bit(uint8_t address, bool value, uint8_t bit_position)
Definition as7341.cpp:246
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:57
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