53 #ifndef _ADAFRUIT_AS7341_H 54 #define _ADAFRUIT_AS7341_H 57 #include <Adafruit_BusIO_Register.h> 58 #include <Adafruit_I2CDevice.h> 60 #define AS7341_I2CADDR_DEFAULT 0x39 61 #define AS7341_CHIP_ID 0x09 63 #define AS7341_WHOAMI 0x92 65 #define AS7341_ASTATUS 0x60 66 #define AS7341_CH0_DATA_L_ 0x61 67 #define AS7341_CH0_DATA_H_ 0x62 68 #define AS7341_ITIME_L 0x63 69 #define AS7341_ITIME_M 0x64 70 #define AS7341_ITIME_H 0x65 71 #define AS7341_CONFIG 0x70 72 #define AS7341_STAT 0x71 73 #define AS7341_EDGE 0x72 74 #define AS7341_GPIO 0x73 75 #define AS7341_LED 0x74 76 #define AS7341_ENABLE \ 78 #define AS7341_ATIME 0x81 80 #define AS7341_WTIME 0x83 81 #define AS7341_SP_LOW_TH_L 0x84 82 #define AS7341_SP_LOW_TH_H \ 84 #define AS7341_SP_HIGH_TH_L \ 86 #define AS7341_SP_HIGH_TH_H \ 88 #define AS7341_AUXID 0x90 89 #define AS7341_REVID 0x91 90 #define AS7341_ID 0x92 91 #define AS7341_STATUS \ 93 #define AS7341_ASTATUS_ 0x94 94 #define AS7341_CH0_DATA_L 0x95 95 #define AS7341_CH0_DATA_H 0x96 96 #define AS7341_CH1_DATA_L 0x97 97 #define AS7341_CH1_DATA_H 0x98 98 #define AS7341_CH2_DATA_L 0x99 99 #define AS7341_CH2_DATA_H 0x9A 100 #define AS7341_CH3_DATA_L 0x9B 101 #define AS7341_CH3_DATA_H 0x9C 102 #define AS7341_CH4_DATA_L 0x9D 103 #define AS7341_CH4_DATA_H 0x9E 104 #define AS7341_CH5_DATA_L 0x9F 105 #define AS7341_CH5_DATA_H 0xA0 106 #define AS7341_STATUS2 0xA3 107 #define AS7341_STATUS3 \ 109 #define AS7341_STATUS5 0xA6 110 #define AS7341_STATUS6 0xA7 111 #define AS7341_CFG0 \ 113 #define AS7341_CFG1 0xAA 114 #define AS7341_CFG3 0xAC 115 #define AS7341_CFG6 0xAF 116 #define AS7341_CFG8 0xB1 117 #define AS7341_CFG9 \ 119 #define AS7341_CFG10 0xB3 121 #define AS7341_CFG12 \ 123 #define AS7341_PERS \ 125 #define AS7341_GPIO2 \ 128 #define AS7341_ASTEP_L 0xCA 130 #define AS7341_ASTEP_H 0xCB 131 #define AS7341_AGC_GAIN_MAX 0xCF 132 #define AS7341_AZ_CONFIG 0xD6 133 #define AS7341_FD_TIME1 0xD8 134 #define AS7341_FD_TIME2 0xDA 135 #define AS7341_FD_CFG0 0xD7 136 #define AS7341_FD_STATUS \ 138 #define AS7341_INTENAB 0xF9 140 #define AS7341_CONTROL 0xFA 141 #define AS7341_FIFO_MAP 0xFC 142 #define AS7341_FIFO_LVL 0xFD 143 #define AS7341_FDATA_L 0xFE 144 #define AS7341_FDATA_H 0xFF 146 #define AS7341_SPECTRAL_INT_HIGH_MSK \ 148 #define AS7341_SPECTRAL_INT_LOW_MSK \ 183 AS7341_ADC_CHANNEL_0,
184 AS7341_ADC_CHANNEL_1,
185 AS7341_ADC_CHANNEL_2,
186 AS7341_ADC_CHANNEL_3,
187 AS7341_ADC_CHANNEL_4,
188 AS7341_ADC_CHANNEL_5,
195 AS7341_CHANNEL_415nm_F1,
196 AS7341_CHANNEL_445nm_F2,
197 AS7341_CHANNEL_480nm_F3,
198 AS7341_CHANNEL_515nm_F4,
199 AS7341_CHANNEL_CLEAR_0,
200 AS7341_CHANNEL_NIR_0,
201 AS7341_CHANNEL_555nm_F5,
202 AS7341_CHANNEL_590nm_F6,
203 AS7341_CHANNEL_630nm_F7,
204 AS7341_CHANNEL_680nm_F8,
205 AS7341_CHANNEL_CLEAR,
246 AS7341_WAITING_START,
264 int32_t sensor_id = 0);
266 bool setASTEP(uint16_t astep_value);
332 virtual bool _init(int32_t sensor_id);
340 bool enableSMUX(
void);
341 bool enableFlickerDetection(
bool enable_fd);
343 int8_t getFlickerDetectStatus(
void);
345 void writeRegister(byte addr, byte val);
346 void setSMUXLowChannels(
bool f1_f4);
347 uint16_t _channel_readings[12];
uint8_t getInterruptStatus(void)
Returns the current value of the Interupt status register.
Definition: Adafruit_AS7341.cpp:678
bool checkReadingProgress()
runs the process of getting readings from all channels without using delays. Should be called regular...
Definition: Adafruit_AS7341.cpp:172
as7341_color_channel_t
Spectral Channel specifiers for configuration and reading.
Definition: Adafruit_AS7341.h:194
uint16_t getHighThreshold(void)
Returns the current high thighreshold for spectral measurements.
Definition: Adafruit_AS7341.cpp:595
as7341_waiting_t
Wait states for async reading.
Definition: Adafruit_AS7341.h:245
bool enableSystemInterrupt(bool enable_int)
Enabled system interrupts.
Definition: Adafruit_AS7341.cpp:621
12
Definition: Adafruit_AS7341.h:227
13
Definition: Adafruit_AS7341.h:228
Adafruit_AS7341()
Construct a new Adafruit_AS7341::Adafruit_AS7341 object.
Definition: Adafruit_AS7341.cpp:27
as7341_adc_channel_t
ADC Channel specifiers for configuration.
Definition: Adafruit_AS7341.h:182
bool setASTEP(uint16_t astep_value)
Sets the integration time step size.
Definition: Adafruit_AS7341.cpp:882
The GPIO Pin is set as a high-impedence input.
Definition: Adafruit_AS7341.h:239
bool setLEDCurrent(uint16_t led_current_ma)
Set the current limit for the LED.
Definition: Adafruit_AS7341.cpp:483
8
Definition: Adafruit_AS7341.h:223
uint8_t getATIME()
Returns the integration time step count.
Definition: Adafruit_AS7341.cpp:869
0
Definition: Adafruit_AS7341.h:215
4
Definition: Adafruit_AS7341.h:219
virtual bool _init(int32_t sensor_id)
Initializer for post i2c/spi init.
Definition: Adafruit_AS7341.cpp:69
Read SMUX configuration to RAM from SMUX chain.
Definition: Adafruit_AS7341.h:175
uint16_t detectFlickerHz(void)
Detect a flickering light.
Definition: Adafruit_AS7341.cpp:994
bool setLowThreshold(uint16_t low_threshold)
Sets the threshold below which spectral measurements will trigger interrupts when the APERS count is ...
Definition: Adafruit_AS7341.cpp:560
bool getGPIOValue(void)
Read the digital level of the GPIO pin, high or low.
Definition: Adafruit_AS7341.cpp:413
long getTINT()
Returns the integration time.
Definition: Adafruit_AS7341.cpp:932
bool readAllChannels(void)
Take readings for F1-8, Clear and NIR and store them in a buffer.
Definition: Adafruit_AS7341.cpp:263
bool setAPERS(as7341_int_cycle_count_t cycle_count)
Sets the number of times an interrupt threshold must be exceeded before an interrupt is triggered...
Definition: Adafruit_AS7341.cpp:645
9
Definition: Adafruit_AS7341.h:224
bool enableSpectralInterrupt(bool enable_int)
Enable Interrupts based on spectral measurements.
Definition: Adafruit_AS7341.cpp:607
14
Definition: Adafruit_AS7341.h:229
bool setBank(bool low)
Sets the active register bank.
Definition: Adafruit_AS7341.cpp:542
5
Definition: Adafruit_AS7341.h:220
as7341_gpio_dir_t getGPIODirection(void)
Get the GPIO pin direction setting.
Definition: Adafruit_AS7341.cpp:353
bool getGPIOInverted(void)
Get the output inversion setting for the GPIO pin.
Definition: Adafruit_AS7341.cpp:382
float toBasicCounts(uint16_t raw)
Converts raw ADC values to basic counts.
Definition: Adafruit_AS7341.cpp:948
uint8_t spectralInterruptSource(void)
The current state of the spectral measurement interrupt status register.
Definition: Adafruit_AS7341.cpp:716
7
Definition: Adafruit_AS7341.h:222
6
Definition: Adafruit_AS7341.h:221
bool setATIME(uint8_t atime_value)
Sets the integration time step count.
Definition: Adafruit_AS7341.cpp:856
Write SMUX configuration from RAM to SMUX chain.
Definition: Adafruit_AS7341.h:176
as7341_gain_t getGain()
Returns the ADC gain multiplier.
Definition: Adafruit_AS7341.cpp:919
bool getIsDataReady()
Definition: Adafruit_AS7341.cpp:748
1
Definition: Adafruit_AS7341.h:216
uint16_t getLowThreshold(void)
Returns the current low thighreshold for spectral measurements.
Definition: Adafruit_AS7341.cpp:571
bool setSpectralThresholdChannel(as7341_adc_channel_t channel)
Set the ADC channel to use for spectral thresholds including interrupts, automatic gain control...
Definition: Adafruit_AS7341.cpp:661
uint16_t getASTEP()
Returns the integration time step size.
Definition: Adafruit_AS7341.cpp:895
bool enableSpectralMeasurement(bool enable_measurement)
Enables measurement of spectral data.
Definition: Adafruit_AS7341.cpp:308
void disableAll(void)
Disable Spectral reading, flicker detection, and power.
Definition: Adafruit_AS7341.cpp:295
~Adafruit_AS7341()
Destroy the Adafruit_AS7341::Adafruit_AS7341 object.
Definition: Adafruit_AS7341.cpp:33
2
Definition: Adafruit_AS7341.h:217
uint16_t readChannel(as7341_adc_channel_t channel)
Returns the ADC data for a given channel.
Definition: Adafruit_AS7341.cpp:105
bool setGPIOInverted(bool gpio_inverted)
Invert the logic of then GPIO pin when used as an output.
Definition: Adafruit_AS7341.cpp:399
bool setGain(as7341_gain_t gain_value)
Sets the ADC gain multiplier.
Definition: Adafruit_AS7341.cpp:907
Class that stores state and functions for interacting with the AS7341 11-Channel Spectral Sensor...
Definition: Adafruit_AS7341.h:258
bool startReading(void)
starts the process of getting readings from all channels without using delays
Definition: Adafruit_AS7341.cpp:158
bool spectralHighTriggered(void)
The status of the high threshold interrupt.
Definition: Adafruit_AS7341.cpp:739
void powerEnable(bool enable_power)
Sets the power state of the sensor.
Definition: Adafruit_AS7341.cpp:283
void delayForData(int waitTime=0)
Delay while waiting for data, with option to time out and recover.
Definition: Adafruit_AS7341.cpp:235
bool setGPIODirection(as7341_gpio_dir_t gpio_direction)
Set the GPIO pin to be used as an input or output.
Definition: Adafruit_AS7341.cpp:368
as7341_int_cycle_count_t
The number of measurement cycles with spectral data outside of a threshold required to trigger an int...
Definition: Adafruit_AS7341.h:214
uint16_t getLEDCurrent(void)
Get the current limit for the LED.
Definition: Adafruit_AS7341.cpp:511
as7341_gpio_dir_t
Pin directions to set how the GPIO pin is to be used.
Definition: Adafruit_AS7341.h:237
bool setHighThreshold(uint16_t high_threshold)
Sets the threshold above which spectral measurements will trigger interrupts when the APERS count is ...
Definition: Adafruit_AS7341.cpp:584
bool spectralLowTriggered(void)
The status of the low threshold interrupt.
Definition: Adafruit_AS7341.cpp:730
THhe GPIO pin is configured as an open drain output.
Definition: Adafruit_AS7341.h:238
ROM code initialization of SMUX.
Definition: Adafruit_AS7341.h:174
3
Definition: Adafruit_AS7341.h:218
#define AS7341_I2CADDR_DEFAULT
AS7341 default i2c address.
Definition: Adafruit_AS7341.h:60
uint16_t getChannel(as7341_color_channel_t channel)
Returns the reading data for the specified color channel.
Definition: Adafruit_AS7341.cpp:121
Adafruit_I2CDevice * i2c_dev
Pointer to I2C bus interface.
Definition: Adafruit_AS7341.h:337
void setup_F1F4_Clear_NIR(void)
Configure SMUX for sensors F1-4, Clear and NIR.
Definition: Adafruit_AS7341.cpp:761
bool spectralInterruptTriggered(void)
Returns the status of the spectral measurement threshold interrupts.
Definition: Adafruit_AS7341.cpp:689
10
Definition: Adafruit_AS7341.h:225
bool getAllChannels(uint16_t *readings_buffer)
transfer all the values from the private result buffer into one nominated
Definition: Adafruit_AS7341.cpp:223
void setup_F5F8_Clear_NIR(void)
Configure SMUX for sensors F5-8, Clear and NIR.
Definition: Adafruit_AS7341.cpp:791
as7341_smux_cmd_t
Available SMUX configuration commands.
Definition: Adafruit_AS7341.h:173
11
Definition: Adafruit_AS7341.h:226
uint8_t last_spectral_int_source
Definition: Adafruit_AS7341.h:333
as7341_gain_t
Allowable gain multipliers for setGain
Definition: Adafruit_AS7341.h:155
bool enableLED(bool enable_led)
Enable control of an attached LED on the LDR pin.
Definition: Adafruit_AS7341.cpp:454
15
Definition: Adafruit_AS7341.h:230
bool clearInterruptStatus(void)
Clear the interrupt status register.
Definition: Adafruit_AS7341.cpp:703
bool begin(uint8_t i2c_addr=AS7341_I2CADDR_DEFAULT, TwoWire *wire=&Wire, int32_t sensor_id=0)
Sets up the hardware and initializes I2C.
Definition: Adafruit_AS7341.cpp:50
bool setGPIOValue(bool)
Set the digital level of the GPIO pin, high or low.
Definition: Adafruit_AS7341.cpp:430