Loading...
Searching...
No Matches
apds99xx.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Gunar Schorcht
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
200
201#ifdef __cplusplus
202extern "C"
203{
204#endif
205
206#include <stdbool.h>
207#include <stdint.h>
208
209#include "periph/gpio.h"
210#include "periph/i2c.h"
211
219#if MODULE_APDS9900
220#define APDS99XX_ID (0x29)
221#define APDS99XX_T_PRX_PULSE (16)
222#define APDS99XX_T_PRX_CNV (2720)
223#define APDS99XX_T_WAIT_STEP (2720)
224#define APDS99XX_T_ALS_STEP (2720)
225#define APDS99XX_CNTS_P_STEP (1023)
226
227#elif MODULE_APDS9901
228#define APDS99XX_ID (0x20)
229#define APDS99XX_T_PRX_PULSE (16)
230#define APDS99XX_T_PRX_CNV (2720)
231#define APDS99XX_T_WAIT_STEP (2720)
232#define APDS99XX_T_ALS_STEP (2720)
233#define APDS99XX_CNTS_P_STEP (1023)
234
235#elif MODULE_APDS9930
236#define APDS99XX_ID (0x39)
237#define APDS99XX_T_PRX_PULSE (16)
238#define APDS99XX_T_PRX_CNV (2730)
239#define APDS99XX_T_WAIT_STEP (2730)
240#define APDS99XX_T_ALS_STEP (2730)
241#define APDS99XX_CNTS_P_STEP (1023)
242
243#elif MODULE_APDS9950
244#define APDS99XX_ID (0x69)
245#define APDS99XX_T_PRX_PULSE (14)
246#define APDS99XX_T_PRX_CNV (2400)
247#define APDS99XX_T_WAIT_STEP (2400)
248#define APDS99XX_T_ALS_STEP (2400)
249#define APDS99XX_CNTS_P_STEP (1024)
250
251#elif MODULE_APDS9960 || DOXYGEN
252#define APDS99XX_ID (0xab)
253#define APDS99XX_T_PRX_PULSE (36)
255#define APDS99XX_T_PRX_CNV (841)
257#define APDS99XX_T_WAIT_STEP (2780)
258#define APDS99XX_T_ALS_STEP (2780)
259#define APDS99XX_CNTS_P_STEP (1025)
260
261#else
262#error "Please provide a valid aps99xx variant (apds9900, apds9901, adps9930, apds9950, apds9960)"
263#endif
265
269#define APDS99XX_I2C_ADDRESS (0x39)
270
281
285typedef enum {
289 #if MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN
291 #endif /* MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN */
292 #if MODULE_APDS9900 || MODULE_APDS9901 || APDS9930 || DOXYGEN
294 #endif /* MODULE_APDS9900 || MODULE_APDS9901 || APDS9930 || DOXYGEN */
296
300typedef enum {
302 #if MODULE_APDS9930 || MODULE_APDS9960 || DOXYGEN
306 #endif /* MODULE_APDS9930 || MODULE_APDS9960 || DOXYGEN */
308
318
347
348#if MODULE_APDS99XX_FULL || DOXYGEN
349
370typedef struct {
372 uint8_t als_pers;
378 uint16_t als_thresh_low;
380
382 uint8_t prx_pers;
390
391 uint16_t prx_thresh_low;
395
397
403typedef struct {
404 bool als_int;
405 bool prx_int;
407
411typedef void (*apds99xx_isr_t)(void *arg);
412
413#endif /* MODULE_APDS99XX_FULL */
414
418typedef struct {
419
421
422#if MODULE_APDS99XX_FULL || DOXYGEN
424 void* isr_arg;
425
427#endif /* MODULE_APDS99XX_FULL */
428
429} apds99xx_t;
430
431#if MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN
435typedef union {
436
437 struct {
438 uint16_t red;
439 uint16_t green;
440 uint16_t blue;
441 };
442 uint16_t val[3];
443
445#endif
446
461
476
498int apds99xx_read_als_raw(const apds99xx_t *dev, uint16_t *raw);
499
500#if MODULE_APDS9900 || MODULE_APDS9901 || MODULE_APDS9930 || DOXYGEN
519int apds99xx_read_illuminance(const apds99xx_t *dev, uint16_t *lux);
520
521#endif /* MODULE_APDS9900 || MODULE_APDS9901 || MODULE_APDS9930 || DOXYGEN */
522
523#if MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN
552
553#endif /* MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN */
554
569
594int apds99xx_read_prx_raw(const apds99xx_t *dev, uint16_t *prx);
595
610
623
624#if MODULE_APDS99XX_FULL || DOXYGEN
625
654 apds99xx_isr_t isr, void *isr_arg);
655
675
676#endif /* MODULE_APDS99XX_FULL */
677
678#ifdef __cplusplus
679}
680#endif
681
Low-level GPIO peripheral driver interface definitions.
void(* apds99xx_isr_t)(void *arg)
Interrupt service routine function prototype.
Definition apds99xx.h:411
int apds99xx_power_down(const apds99xx_t *dev)
Power down the sensor.
int apds99xx_data_ready_prx(const apds99xx_t *dev)
Proximity sensing (PRX) data-ready status function.
apds99xx_prx_gain_t
Proximity sensing (PRX) gain.
Definition apds99xx.h:300
int apds99xx_int_source(apds99xx_t *dev, apds99xx_int_source_t *src)
Get the source of an interrupt.
int apds99xx_int_config(apds99xx_t *dev, apds99xx_int_config_t *cfg, apds99xx_isr_t isr, void *isr_arg)
Configure the interrupts of the sensor.
apds99xx_prx_drive_t
Proximity sensing (PRX) LED drive strength.
Definition apds99xx.h:312
int apds99xx_data_ready_als(const apds99xx_t *dev)
Ambient light sensing (ALS) data-ready status function.
int apds99xx_read_illuminance(const apds99xx_t *dev, uint16_t *lux)
Read one data sample of illuminance in lux.
int apds99xx_read_prx_raw(const apds99xx_t *dev, uint16_t *prx)
Read one data sample of proximity sensing (PRX)
int apds99xx_read_als_raw(const apds99xx_t *dev, uint16_t *raw)
Read one raw data sample of ambient light sensing (ALS)
int apds99xx_power_up(const apds99xx_t *dev)
Power up the sensor.
apds99xx_error_codes_t
Definition of error codes.
Definition apds99xx.h:274
int apds99xx_read_rgb_raw(const apds99xx_t *dev, apds99xx_rgb_t *rgb)
Read one raw RGB color data sample (APDS9950 and APDS9960 only)
apds99xx_als_gain_t
Ambient light sensing (ALS) gain.
Definition apds99xx.h:285
int apds99xx_init(apds99xx_t *dev, const apds99xx_params_t *params)
Initialize the APDS99XX sensor device.
@ APDS99XX_PRX_GAIN_4
4 x gain (APDS9930, APDS9960 only)
Definition apds99xx.h:304
@ APDS99XX_PRX_GAIN_8
8 x gain (APDS9930, APDS9960 only)
Definition apds99xx.h:305
@ APDS99XX_PRX_GAIN_1
1 x gain (default)
Definition apds99xx.h:301
@ APDS99XX_PRX_GAIN_2
2 x gain (APDS9930, APDS9960 only)
Definition apds99xx.h:303
@ APDS99XX_PRX_DRIVE_25
25.0 mA
Definition apds99xx.h:315
@ APDS99XX_PRX_DRIVE_12_5
12.5 mA
Definition apds99xx.h:316
@ APDS99XX_PRX_DRIVE_100
100.0 mA (default)
Definition apds99xx.h:313
@ APDS99XX_PRX_DRIVE_50
50.0 mA
Definition apds99xx.h:314
@ APDS99XX_ERROR_NO_DATA
no data are available
Definition apds99xx.h:278
@ APDS99XX_ERROR_I2C
I2C communication error.
Definition apds99xx.h:276
@ APDS99XX_ERROR_RAW_DATA
reading raw data failed
Definition apds99xx.h:279
@ APDS99XX_ERROR_WRONG_ID
wrong id read
Definition apds99xx.h:277
@ APDS99XX_OK
success
Definition apds99xx.h:275
@ APDS99XX_ALS_GAIN_120
120 x gain (APDS9900, APDS9901, APDS9930 only)
Definition apds99xx.h:293
@ APDS99XX_ALS_GAIN_16
16 x gain
Definition apds99xx.h:288
@ APDS99XX_ALS_GAIN_64
64 x gain (APDS9950, APDS9960 only)
Definition apds99xx.h:290
@ APDS99XX_ALS_GAIN_8
8 x gain
Definition apds99xx.h:287
@ APDS99XX_ALS_GAIN_1
1 x gain (default)
Definition apds99xx.h:286
Low-level I2C peripheral driver interface definition.
Interrupt configuration.
Definition apds99xx.h:370
uint16_t als_thresh_high
High threshold value for ALS interrupts.
Definition apds99xx.h:379
uint8_t prx_pers
Number of consecutive proximity values that have to be outside the thresholds to generate an interrup...
Definition apds99xx.h:382
uint16_t als_thresh_low
Low threshold value for ALS interrupts.
Definition apds99xx.h:378
uint16_t prx_thresh_low
Low threshold for proximity values (only the low byte is used for APDS9960)
Definition apds99xx.h:391
bool als_int_en
ALS interrupt enabled.
Definition apds99xx.h:371
bool prx_int_en
Proximity interrupt enabled.
Definition apds99xx.h:381
uint8_t als_pers
Number of consecutive ALS values that have to be outside the thresholds to generate an interrupt:
Definition apds99xx.h:372
uint16_t prx_thresh_high
High threshold for proximity values (only the low byte is used for APDS9960)
Definition apds99xx.h:393
Interrupt source.
Definition apds99xx.h:403
bool prx_int
Proximity interrupt happened.
Definition apds99xx.h:405
bool als_int
ALS interrupt happened.
Definition apds99xx.h:404
APDS99XX device initialization parameters.
Definition apds99xx.h:322
unsigned dev
I2C device (default I2C_DEV(0))
Definition apds99xx.h:324
gpio_t int_pin
interrupt pin: GPIO_UNDEF if not used
Definition apds99xx.h:344
apds99xx_als_gain_t als_gain
Gain used for ALS.
Definition apds99xx.h:328
uint16_t wait_steps
Waiting time in steps.
Definition apds99xx.h:339
apds99xx_prx_gain_t prx_gain
Gain used for proximity sensing.
Definition apds99xx.h:336
uint8_t prx_pulses
IR LED pulses for proximity sensing.
Definition apds99xx.h:331
apds99xx_prx_drive_t prx_drive
IR LED current for proximity sensing (default APDS99XX_PRX_DRIVE_100)
Definition apds99xx.h:334
uint16_t als_steps
ALS integration time in steps.
Definition apds99xx.h:326
bool wait_long
Long waiting time.
Definition apds99xx.h:341
APDS99XX sensor device data structure type.
Definition apds99xx.h:418
apds99xx_params_t params
device initialization parameters
Definition apds99xx.h:420
void * isr_arg
user ISR argument
Definition apds99xx.h:424
bool gpio_init
GPIO is already initialized.
Definition apds99xx.h:426
apds99xx_isr_t isr
user ISR
Definition apds99xx.h:423
RGB count value data structure (APDS9950 and APDS9960 only)
Definition apds99xx.h:435
uint16_t green
G photodiode count value (green)
Definition apds99xx.h:439
uint16_t blue
B photodiode count value (blue)
Definition apds99xx.h:440
uint16_t red
R photodiode count value (red)
Definition apds99xx.h:438
uint16_t val[3]
RGB count values as array.
Definition apds99xx.h:442