8#ifndef ZEPHYR_DRIVERS_SENSOR_APDS9960_APDS9960_H_
9#define ZEPHYR_DRIVERS_SENSOR_APDS9960_APDS9960_H_
14#define APDS9960_ENABLE_REG 0x80
15#define APDS9960_ENABLE_GEN BIT(6)
16#define APDS9960_ENABLE_PIEN BIT(5)
17#define APDS9960_ENABLE_AIEN BIT(4)
18#define APDS9960_ENABLE_WEN BIT(3)
19#define APDS9960_ENABLE_PEN BIT(2)
20#define APDS9960_ENABLE_AEN BIT(1)
21#define APDS9960_ENABLE_PON BIT(0)
23#define APDS9960_ATIME_REG 0x81
24#define APDS9960_WTIME_REG 0x83
25#define APDS9960_INT_AILTL_REG 0x84
26#define APDS9960_INT_AILTH_REG 0x85
27#define APDS9960_INT_AIHTL_REG 0x86
28#define APDS9960_INT_AIHTH_REG 0x87
29#define APDS9960_PILT_REG 0x89
30#define APDS9960_PIHT_REG 0x8B
32#define APDS9960_PERS_REG 0x8C
33#define APDS9960_PERS_PPERS (BIT(4) | BIT(5) | BIT(6) | BIT(7))
34#define APDS9960_APERS_MASK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
36#define APDS9960_CONFIG1_REG 0x8D
37#define APDS9960_CONFIG1_WLONG BIT(1)
39#define APDS9960_PPULSE_REG 0x8E
40#define APDS9960_PPULSE_LENGTH_4US 0
41#define APDS9960_PPULSE_LENGTH_8US BIT(6)
42#define APDS9960_PPULSE_LENGTH_16US BIT(7)
43#define APDS9960_PPULSE_LENGTH_32US (BIT(7) | BIT(6))
45#define APDS9960_CONTROL_REG 0x8F
46#define APDS9960_CONTROL_LDRIVE (BIT(6) | BIT(7))
47#define APDS9960_CONTROL_PGAIN (BIT(3) | BIT(2))
48#define APDS9960_CONTROL_AGAIN (BIT(0) | BIT(1))
50#define APDS9960_LED_DRIVE_100MA 0
51#define APDS9960_LED_DRIVE_50MA BIT(6)
52#define APDS9960_LED_DRIVE_25MA BIT(7)
53#define APDS9960_LED_DRIVE_12_5MA (BIT(6) | BIT(7))
55#define APDS9960_PGAIN_1X 0
56#define APDS9960_PGAIN_2X BIT(2)
57#define APDS9960_PGAIN_4X BIT(3)
58#define APDS9960_PGAIN_8X (BIT(2) | BIT(3))
60#define APDS9960_AGAIN_1X 0
61#define APDS9960_AGAIN_4X BIT(0)
62#define APDS9960_AGAIN_16X BIT(1)
63#define APDS9960_AGAIN_64X (BIT(0) | BIT(1))
65#define APDS9960_CONFIG2_REG 0x90
66#define APDS9960_CONFIG2_CPSIEN BIT(6)
67#define APDS9960_CONFIG2_PSIEN BIT(7)
69#define APDS9960_PLED_BOOST_100 0
70#define APDS9960_PLED_BOOST_150 BIT(4)
71#define APDS9960_PLED_BOOST_200 BIT(5)
72#define APDS9960_PLED_BOOST_300 (BIT(5) | BIT(4))
74#define APDS9960_ID_REG 0x92
76#define APDS9960_ID_1 0xAB
77#define APDS9960_ID_2 0x9C
79#define APDS9960_STATUS_REG 0x93
80#define APDS9960_STATUS_CPSAT BIT(7)
81#define APDS9960_STATUS_PGSAT BIT(6)
82#define APDS9960_STATUS_PINT BIT(5)
83#define APDS9960_STATUS_AINT BIT(4)
84#define APDS9960_STATUS_GINT BIT(2)
85#define APDS9960_STATUS_PVALID BIT(1)
86#define APDS9960_STATUS_AVALID BIT(0)
88#define APDS9960_CDATAL_REG 0x94
89#define APDS9960_CDATAH_REG 0x95
90#define APDS9960_RDATAL_REG 0x96
91#define APDS9960_RDATAH_REG 0x97
92#define APDS9960_GDATAL_REG 0x98
93#define APDS9960_GDATAH_REG 0x99
94#define APDS9960_BDATAL_REG 0x9A
95#define APDS9960_BDATAH_REG 0x9B
96#define APDS9960_PDATA_REG 0x9C
98#define APDS9960_POFFSET_UR_REG 0x9D
99#define APDS9960_POFFSET_DL_REG 0x9E
101#define APDS9960_CONFIG3_REG 0x9F
102#define APDS9960_CONFIG3_PCMP BIT(5)
103#define APDS9960_CONFIG3_SAI BIT(4)
104#define APDS9960_CONFIG3_PMSK_U BIT(3)
105#define APDS9960_CONFIG3_PMSK_D BIT(2)
106#define APDS9960_CONFIG3_PMSK_L BIT(1)
107#define APDS9960_CONFIG3_PMSK_R BIT(0)
109#define APDS9960_GPENTH_REG 0xA0
110#define APDS9960_GEXTH_REG 0xA1
112#define APDS9960_GCONFIG1_REG 0xA2
113#define APDS9960_GCONFIG1_GFIFOTH (BIT(7) | BIT(6))
114#define APDS9960_GCONFIG1_GEXMSK (BIT(5) | BIT(4) | BIT(3) | BIT(2))
115#define APDS9960_GCONFIG1_GEXPERS (BIT(1) | BIT(0))
117#define APDS9960_GCONFIG2_REG 0xA3
118#define APDS9960_GCONFIG2_GGAIN (BIT(6) | BIT(5))
119#define APDS9960_GCONFIG2_GLDRIVE (BIT(4) | BIT(3))
120#define APDS9960_GCONFIG2_WTIME (BIT(2) | BIT(1) | BIT(0))
122#define APDS9960_GGAIN_1X 0
123#define APDS9960_GGAIN_2X BIT(5)
124#define APDS9960_GGAIN_4X BIT(6)
125#define APDS9960_GGAIN_8X (BIT(6) | BIT(5))
127#define APDS9960_LED_GDRIVE_100MA 0
128#define APDS9960_LED_GDRIVE_50MA BIT(3)
129#define APDS9960_LED_GDRIVE_25MA BIT(4)
130#define APDS9960_LED_GDRIVE_12_5MA (BIT(4) | BIT(3))
132#define APDS9960_GWTIME_0MS 0
133#define APDS9960_GWTIME_2_8MS 1
134#define APDS9960_GWTIME_5_6MS 2
135#define APDS9960_GWTIME_8_4MS 3
136#define APDS9960_GWTIME_14_0MS 4
137#define APDS9960_GWTIME_22_4MS 5
138#define APDS9960_GWTIME_30_8MS 6
139#define APDS9960_GWTIME_39_2MS 7
141#define APDS9960_GOFFSET_U_REG 0xA4
142#define APDS9960_GOFFSET_D_REG 0xA5
143#define APDS9960_GOFFSET_L_REG 0xA7
144#define APDS9960_GOFFSET_R_REG 0xA9
146#define APDS9960_GPULSE_REG 0xA6
147#define APDS9960_GPULSE_GPLEN (BIT(7) | BIT(6))
148#define APDS9960_GPULSE_GPULSE (BIT(5) | BIT(4) | BIT(3) |\
149 BIT(2) | BIT(1) | BIT(0))
151#define APDS9960_GPLEN_0US 0
152#define APDS9960_GPLEN_8US BIT(6)
153#define APDS9960_GPLEN_16US BIT(7)
154#define APDS9960_GPLEN_32US (BIT(7) | BIT(6))
156#define APDS9960_GCONFIG3_REG 0xAA
157#define APDS9960_GCONFIG3_GDIMS (BIT(1) | BIT(0))
160#define APDS9960_GCONFIG4_REG 0xAB
161#define APDS9960_GCONFIG4_GFIFO_CLR BIT(2)
162#define APDS9960_GCONFIG4_GIEN BIT(1)
163#define APDS9960_GCONFIG4_GMODE BIT(0)
165#define APDS9960_GFLVL_REG 0xAE
167#define APDS9960_GSTATUS_REG 0xAF
168#define APDS9960_GSTATUS_GFOV BIT(1)
169#define APDS9960_GSTATUS_GVALID BIT(0)
171#define APDS9960_IFORCE_REG 0xE4
172#define APDS9960_PICLEAR_REG 0xE5
173#define APDS9960_CICLEAR_REG 0xE6
174#define APDS9960_AICLEAR_REG 0xE7
176#define APDS9960_GFIFO_U_REG 0xFC
177#define APDS9960_GFIFO_D_REG 0xFD
178#define APDS9960_GFIFO_L_REG 0xFE
179#define APDS9960_GFIFO_R_REG 0xFF
182#define APDS9960_DEFAULT_ATIME 219
183#define APDS9960_DEFAULT_WTIME 255
184#define APDS9960_DEFAULT_CONFIG1 0x60
185#define APDS9960_DEFAULT_PERS BIT(4)
186#define APDS9960_DEFAULT_CONFIG2 (BIT(6) | BIT(0))
187#define APDS9960_DEFAULT_GESTURE_PPULSE 0x89
188#define APDS9960_DEFAULT_POFFSET_UR 0
189#define APDS9960_DEFAULT_POFFSET_DL 0
190#define APDS9960_DEFAULT_LDRIVE APDS9960_LED_DRIVE_100MA
192#ifdef CONFIG_APDS9960_TRIGGER
193#define APDS9960_DEFAULT_PILT 0
194#define APDS9960_DEFAULT_PIHT 50
195#define APDS9960_DEFAULT_AILT 10
196#define APDS9960_DEFAULT_AIHT 1000
197#define APDS9960_DEFAULT_CONFIG3 0
199#define APDS9960_DEFAULT_PILT 0
200#define APDS9960_DEFAULT_PIHT 1
201#define APDS9960_DEFAULT_AILT 0xFFFF
202#define APDS9960_DEFAULT_AIHT 0
203#define APDS9960_DEFAULT_CONFIG3 APDS9960_CONFIG3_SAI
206#define APDS9960_DEFAULT_GPENTH 40
207#define APDS9960_DEFAULT_GEXTH 30
208#define APDS9960_DEFAULT_GCONF1 0x40
209#define APDS9960_DEFAULT_GGAIN APDS9960_GGAIN_4X
210#define APDS9960_DEFAULT_GLDRIVE APDS9960_LED_DRIVE_100MA
211#define APDS9960_DEFAULT_GWTIME APDS9960_GWTIME_2_8MS
212#define APDS9960_DEFAULT_GOFFSET 0
213#define APDS9960_DEFAULT_GPULSE 0xC9
214#define APDS9960_DEFAULT_GCONF3 0
217#define APDS9960_DEFAULT_WAIT_TIME 2.78
218#define APDS9960_MAX_WAIT_TIME 10000
227#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
234#ifdef CONFIG_APDS9960_ENABLE_GESTURE
260#ifdef CONFIG_APDS9960_TRIGGER
263#elif CONFIG_APDS9960_FETCH_MODE_INTERRUPT
264 struct k_sem data_sem;
268#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
269static inline void apds9960_setup_int(
const struct apds9960_config *cfg,
272 unsigned int flags = enable
280#ifdef CONFIG_APDS9960_TRIGGER
281void apds9960_work_cb(
struct k_work *work);
283int apds9960_attr_set(
const struct device *dev,
288int apds9960_trigger_set(
const struct device *dev,
apds9960_gesture
Definition apds9960.h:244
@ APDS9960_GESTURE_UP
Definition apds9960.h:246
@ APDS9960_GESTURE_DOWN
Definition apds9960.h:247
@ APDS9960_GESTURE_LEFT
Definition apds9960.h:248
@ APDS9960_GESTURE_NONE
Definition apds9960.h:245
@ APDS9960_GESTURE_RIGHT
Definition apds9960.h:249
sensor_channel_apds9960
Definition apds9960.h:240
@ SENSOR_CHAN_APDS9960_GESTURE
Definition apds9960.h:241
Main header file for GPIO driver API.
Main header file for I2C (Inter-Integrated Circuit) driver API.
static int gpio_pin_interrupt_configure_dt(const struct gpio_dt_spec *spec, gpio_flags_t flags)
Configure pin interrupts from a gpio_dt_spec.
Definition gpio.h:972
#define GPIO_INT_EDGE_TO_ACTIVE
Configures GPIO interrupt to be triggered on pin state change to logical level 1 and enables it.
Definition gpio.h:210
#define GPIO_INT_DISABLE
Disables GPIO pin interrupt.
Definition gpio.h:108
sensor_attribute
Sensor attribute types.
Definition sensor.h:342
void(* sensor_trigger_handler_t)(const struct device *dev, const struct sensor_trigger *trigger)
Callback API upon firing of a trigger.
Definition sensor.h:422
sensor_channel
Sensor channels.
Definition sensor.h:65
@ SENSOR_CHAN_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:247
flags
Definition parser.h:97
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Definition apds9960.h:225
uint8_t pgain
Definition apds9960.h:230
uint8_t again
Definition apds9960.h:231
struct i2c_dt_spec i2c
Definition apds9960.h:226
uint8_t pled_boost
Definition apds9960.h:233
uint8_t ppcount
Definition apds9960.h:232
Definition apds9960.h:252
const struct device * dev
Definition apds9960.h:255
struct k_work work
Definition apds9960.h:254
enum apds9960_gesture gesture
Definition apds9960.h:258
uint8_t pdata
Definition apds9960.h:257
struct gpio_callback gpio_cb
Definition apds9960.h:253
uint16_t sample_crgb[4]
Definition apds9960.h:256
Definition apds9960.h:220
int proximity
Definition apds9960.h:221
int ir_difference
Definition apds9960.h:222
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
GPIO callback structure.
Definition gpio.h:748
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Complete I2C DT information.
Definition i2c.h:78
Semaphore structure.
Definition kernel.h:3609
A structure used to submit work.
Definition kernel.h:4505
Sensor trigger spec.
Definition sensor.h:332
Representation of a sensor readout value.
Definition sensor.h:55