Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
opt4048.h File Reference

Public header for TI OPT4048 XYZ tristimulus color sensor. More...

#include <stdint.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>

Go to the source code of this file.

Macros

OPT4048 status register flags

Bit masks of the flags returned by opt4048_get_flags().

#define OPT4048_FLAG_L   0x01
 Measurement below the low threshold.
#define OPT4048_FLAG_H   0x02
 Measurement above the high threshold.
#define OPT4048_FLAG_CONVERSION_READY   0x04
 Conversion completed.
#define OPT4048_FLAG_OVERLOAD   0x08
 Signal exceeded the full-scale range.

Enumerations

enum  opt4048_range {
  OPT4048_RANGE_2K_LUX = 0 , OPT4048_RANGE_4K_LUX = 1 , OPT4048_RANGE_9K_LUX = 2 , OPT4048_RANGE_18K_LUX = 3 ,
  OPT4048_RANGE_36K_LUX = 4 , OPT4048_RANGE_72K_LUX = 5 , OPT4048_RANGE_144K_LUX = 6 , OPT4048_RANGE_AUTO = 12
}
 Full-scale light range of the OPT4048. More...
enum  opt4048_conversion_time {
  OPT4048_CONVERSION_TIME_600US = 0 , OPT4048_CONVERSION_TIME_1MS = 1 , OPT4048_CONVERSION_TIME_1_8MS = 2 , OPT4048_CONVERSION_TIME_3_4MS = 3 ,
  OPT4048_CONVERSION_TIME_6_5MS = 4 , OPT4048_CONVERSION_TIME_12_7MS = 5 , OPT4048_CONVERSION_TIME_25MS = 6 , OPT4048_CONVERSION_TIME_50MS = 7 ,
  OPT4048_CONVERSION_TIME_100MS = 8 , OPT4048_CONVERSION_TIME_200MS = 9 , OPT4048_CONVERSION_TIME_400MS = 10 , OPT4048_CONVERSION_TIME_800MS = 11
}
 Conversion time per channel of the OPT4048. More...
enum  opt4048_mode { OPT4048_MODE_POWERDOWN = 0 , OPT4048_MODE_AUTO_ONESHOT = 1 , OPT4048_MODE_ONESHOT = 2 , OPT4048_MODE_CONTINUOUS = 3 }
 Operating mode of the OPT4048. More...
enum  opt4048_fault_count { OPT4048_FAULT_COUNT_1 = 0 , OPT4048_FAULT_COUNT_2 = 1 , OPT4048_FAULT_COUNT_4 = 2 , OPT4048_FAULT_COUNT_8 = 3 }
 Number of consecutive faults required to set the threshold flags. More...
enum  opt4048_int_cfg { OPT4048_INT_CFG_SMBUS_ALERT = 0 , OPT4048_INT_CFG_DATA_READY_NEXT = 1 , OPT4048_INT_CFG_DATA_READY_ALL = 3 }
 Function of the INT pin of the OPT4048. More...
enum  sensor_channel_opt4048 {
  SENSOR_CHAN_OPT4048_RAW_CH0 = SENSOR_CHAN_PRIV_START , SENSOR_CHAN_OPT4048_RAW_CH1 , SENSOR_CHAN_OPT4048_RAW_CH2 , SENSOR_CHAN_OPT4048_RAW_CH3 ,
  SENSOR_CHAN_OPT4048_X , SENSOR_CHAN_OPT4048_Y , SENSOR_CHAN_OPT4048_Z , SENSOR_CHAN_OPT4048_CIE_X ,
  SENSOR_CHAN_OPT4048_CIE_Y , SENSOR_CHAN_OPT4048_CCT
}
 Driver-specific sensor channel identifiers for the OPT4048. More...
enum  sensor_attribute_opt4048 {
  SENSOR_ATTR_OPT4048_RANGE = SENSOR_ATTR_PRIV_START , SENSOR_ATTR_OPT4048_CONVERSION_TIME , SENSOR_ATTR_OPT4048_MODE , SENSOR_ATTR_OPT4048_FAULT_COUNT ,
  SENSOR_ATTR_OPT4048_INT_LATCH , SENSOR_ATTR_OPT4048_INT_POLARITY , SENSOR_ATTR_OPT4048_INT_DIRECTION , SENSOR_ATTR_OPT4048_INT_CONFIG ,
  SENSOR_ATTR_OPT4048_THRESHOLD_CHANNEL , SENSOR_ATTR_OPT4048_QUICK_WAKE
}
 Driver-specific sensor attribute identifiers for the OPT4048. More...

Functions

int opt4048_get_flags (const struct device *dev, uint8_t *flags)
 Read the status flags of the OPT4048.

Detailed Description

Public header for TI OPT4048 XYZ tristimulus color sensor.

Defines the sensor channels, attributes and value enumerations specific to the OPT4048 for use with the generic Zephyr sensor API.

Macro Definition Documentation

◆ OPT4048_FLAG_CONVERSION_READY

#define OPT4048_FLAG_CONVERSION_READY   0x04

Conversion completed.

◆ OPT4048_FLAG_H

#define OPT4048_FLAG_H   0x02

Measurement above the high threshold.

◆ OPT4048_FLAG_L

#define OPT4048_FLAG_L   0x01

Measurement below the low threshold.

◆ OPT4048_FLAG_OVERLOAD

#define OPT4048_FLAG_OVERLOAD   0x08

Signal exceeded the full-scale range.

Enumeration Type Documentation

◆ opt4048_conversion_time

Conversion time per channel of the OPT4048.

Use with SENSOR_ATTR_OPT4048_CONVERSION_TIME.

Note
A full measurement cycle converts all four channels, so it takes four times the selected conversion time.
Enumerator
OPT4048_CONVERSION_TIME_600US 

600 microseconds.

OPT4048_CONVERSION_TIME_1MS 

1 millisecond.

OPT4048_CONVERSION_TIME_1_8MS 

1.8 milliseconds.

OPT4048_CONVERSION_TIME_3_4MS 

3.4 milliseconds.

OPT4048_CONVERSION_TIME_6_5MS 

6.5 milliseconds.

OPT4048_CONVERSION_TIME_12_7MS 

12.7 milliseconds.

OPT4048_CONVERSION_TIME_25MS 

25 milliseconds.

OPT4048_CONVERSION_TIME_50MS 

50 milliseconds.

OPT4048_CONVERSION_TIME_100MS 

100 milliseconds.

OPT4048_CONVERSION_TIME_200MS 

200 milliseconds.

OPT4048_CONVERSION_TIME_400MS 

400 milliseconds.

OPT4048_CONVERSION_TIME_800MS 

800 milliseconds.

◆ opt4048_fault_count

Number of consecutive faults required to set the threshold flags.

Use with SENSOR_ATTR_OPT4048_FAULT_COUNT.

Enumerator
OPT4048_FAULT_COUNT_1 

1 fault.

OPT4048_FAULT_COUNT_2 

2 consecutive faults.

OPT4048_FAULT_COUNT_4 

4 consecutive faults.

OPT4048_FAULT_COUNT_8 

8 consecutive faults.

◆ opt4048_int_cfg

Function of the INT pin of the OPT4048.

Use with SENSOR_ATTR_OPT4048_INT_CONFIG.

Enumerator
OPT4048_INT_CFG_SMBUS_ALERT 

Threshold interrupt / SMBus alert.

OPT4048_INT_CFG_DATA_READY_NEXT 

Pulse after every channel conversion.

OPT4048_INT_CFG_DATA_READY_ALL 

Pulse after all four channels were converted.

◆ opt4048_mode

Operating mode of the OPT4048.

Use with SENSOR_ATTR_OPT4048_MODE.

Note
In the one-shot modes the driver starts a conversion on every sensor_sample_fetch() call and waits for it to finish. In continuous mode the latest result registers are read.
Enumerator
OPT4048_MODE_POWERDOWN 

Power-down, no measurements.

OPT4048_MODE_AUTO_ONESHOT 

Forced auto-range one-shot.

OPT4048_MODE_ONESHOT 

One-shot.

OPT4048_MODE_CONTINUOUS 

Continuous.

◆ opt4048_range

Full-scale light range of the OPT4048.

Use with SENSOR_ATTR_OPT4048_RANGE. A fixed range trades measurable illuminance against resolution; OPT4048_RANGE_AUTO lets the device pick the range for every conversion.

Enumerator
OPT4048_RANGE_2K_LUX 

2.2 klux full-scale range.

OPT4048_RANGE_4K_LUX 

4.5 klux full-scale range.

OPT4048_RANGE_9K_LUX 

9 klux full-scale range.

OPT4048_RANGE_18K_LUX 

18 klux full-scale range.

OPT4048_RANGE_36K_LUX 

36 klux full-scale range.

OPT4048_RANGE_72K_LUX 

72 klux full-scale range.

OPT4048_RANGE_144K_LUX 

144 klux full-scale range.

OPT4048_RANGE_AUTO 

Automatic range selection.

◆ sensor_attribute_opt4048

Driver-specific sensor attribute identifiers for the OPT4048.

The attribute value is passed in sensor_value.val1.

Note
THRESHOLDS: SENSOR_ATTR_LOWER_THRESH and SENSOR_ATTR_UPPER_THRESH take linear ADC codes, the same unit as SENSOR_CHAN_OPT4048_RAW_CHx. The channel they are compared against is selected with SENSOR_ATTR_OPT4048_THRESHOLD_CHANNEL.

Use these identifiers with sensor_attr_set() and sensor_attr_get().

Enumerator
SENSOR_ATTR_OPT4048_RANGE 

Full-scale range, see opt4048_range.

SENSOR_ATTR_OPT4048_CONVERSION_TIME 

Conversion time per channel, see opt4048_conversion_time.

SENSOR_ATTR_OPT4048_MODE 

Operating mode, see opt4048_mode.

SENSOR_ATTR_OPT4048_FAULT_COUNT 

Consecutive fault count, see opt4048_fault_count.

SENSOR_ATTR_OPT4048_INT_LATCH 

Interrupt latch: 1 = latched window mode, 0 = transparent hysteresis.

SENSOR_ATTR_OPT4048_INT_POLARITY 

INT pin polarity: 0 = active low, 1 = active high.

SENSOR_ATTR_OPT4048_INT_DIRECTION 

INT pin direction: 1 = output, 0 = input (hardware one-shot trigger).

SENSOR_ATTR_OPT4048_INT_CONFIG 

INT pin function, see opt4048_int_cfg.

SENSOR_ATTR_OPT4048_THRESHOLD_CHANNEL 

Channel (0 to 3) used by the threshold logic.

SENSOR_ATTR_OPT4048_QUICK_WAKE 

Quick wake-up from standby in one-shot modes: 1 = enabled.

◆ sensor_channel_opt4048

Driver-specific sensor channel identifiers for the OPT4048.

Exposes the raw ADC codes of the four device channels and values derived from them (CIE tristimulus, chromaticity and CCT). SENSOR_CHAN_LIGHT returns the illuminance in lux.

Note
The derived channels return -ENODATA when there is no light and -ERANGE when the result is outside the valid range.
Enumerator
SENSOR_CHAN_OPT4048_RAW_CH0 

CH0 (X filter, peak 600 nm), linearised ADC codes.

SENSOR_CHAN_OPT4048_RAW_CH1 

CH1 (Y filter, peak 550 nm), linearised ADC codes.

SENSOR_CHAN_OPT4048_RAW_CH2 

CH2 (Z filter, peak 460 nm), linearised ADC codes.

SENSOR_CHAN_OPT4048_RAW_CH3 

CH3 (W wide band channel), linearised ADC codes.

SENSOR_CHAN_OPT4048_X 

CIE tristimulus X, computed with the conversion matrix.

SENSOR_CHAN_OPT4048_Y 

CIE tristimulus Y, computed with the conversion matrix.

SENSOR_CHAN_OPT4048_Z 

CIE tristimulus Z, computed with the conversion matrix.

SENSOR_CHAN_OPT4048_CIE_X 

CIE 1931 chromaticity coordinate x (0 to 1).

SENSOR_CHAN_OPT4048_CIE_Y 

CIE 1931 chromaticity coordinate y (0 to 1).

SENSOR_CHAN_OPT4048_CCT 

Correlated color temperature (CCT), in Kelvin.

Function Documentation

◆ opt4048_get_flags()

int opt4048_get_flags ( const struct device * dev,
uint8_t * flags )

Read the status flags of the OPT4048.

Reads the STATUS register of the device and returns the flag bits as a bitmask of OPT4048_FLAG_L, OPT4048_FLAG_H, OPT4048_FLAG_CONVERSION_READY and OPT4048_FLAG_OVERLOAD.

Parameters
[in]devPointer to the device structure for the driver instance.
[out]flagsPointer to store the status flags bitmask.
Return values
0Success.
-EINVALflags is NULL.
-errnoNegative error code from the I2C API.