Loading...
Searching...
No Matches
apds99xx.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 Gunar Schorcht
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
202#ifndef APDS99XX_H
203#define APDS99XX_H
204
205#ifdef __cplusplus
206extern "C"
207{
208#endif
209
210#include <stdbool.h>
211#include <stdint.h>
212
213#include "periph/gpio.h"
214#include "periph/i2c.h"
215
223#if MODULE_APDS9900
224#define APDS99XX_ID (0x29)
225#define APDS99XX_T_PRX_PULSE (16)
226#define APDS99XX_T_PRX_CNV (2720)
227#define APDS99XX_T_WAIT_STEP (2720)
228#define APDS99XX_T_ALS_STEP (2720)
229#define APDS99XX_CNTS_P_STEP (1023)
231#elif MODULE_APDS9901
232#define APDS99XX_ID (0x20)
233#define APDS99XX_T_PRX_PULSE (16)
234#define APDS99XX_T_PRX_CNV (2720)
235#define APDS99XX_T_WAIT_STEP (2720)
236#define APDS99XX_T_ALS_STEP (2720)
237#define APDS99XX_CNTS_P_STEP (1023)
239#elif MODULE_APDS9930
240#define APDS99XX_ID (0x39)
241#define APDS99XX_T_PRX_PULSE (16)
242#define APDS99XX_T_PRX_CNV (2730)
243#define APDS99XX_T_WAIT_STEP (2730)
244#define APDS99XX_T_ALS_STEP (2730)
245#define APDS99XX_CNTS_P_STEP (1023)
247#elif MODULE_APDS9950
248#define APDS99XX_ID (0x69)
249#define APDS99XX_T_PRX_PULSE (14)
250#define APDS99XX_T_PRX_CNV (2400)
251#define APDS99XX_T_WAIT_STEP (2400)
252#define APDS99XX_T_ALS_STEP (2400)
253#define APDS99XX_CNTS_P_STEP (1024)
255#elif MODULE_APDS9960 || DOXYGEN
256#define APDS99XX_ID (0xab)
257#define APDS99XX_T_PRX_PULSE (36)
259#define APDS99XX_T_PRX_CNV (841)
261#define APDS99XX_T_WAIT_STEP (2780)
262#define APDS99XX_T_ALS_STEP (2780)
263#define APDS99XX_CNTS_P_STEP (1025)
265#else
266#error "Please provide a valid aps99xx variant (apds9900, apds9901, adps9930, apds9950, apds9960)"
267#endif
273#define APDS99XX_I2C_ADDRESS (0x39)
274
285
289typedef enum {
293 #if MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN
295 #endif /* MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN */
296 #if MODULE_APDS9900 || MODULE_APDS9901 || APDS9930 || DOXYGEN
298 #endif /* MODULE_APDS9900 || MODULE_APDS9901 || APDS9930 || DOXYGEN */
300
304typedef enum {
306 #if MODULE_APDS9930 || MODULE_APDS9960 || DOXYGEN
310 #endif /* MODULE_APDS9930 || MODULE_APDS9960 || DOXYGEN */
312
322
351
352#if MODULE_APDS99XX_FULL || DOXYGEN
353
374typedef struct {
376 uint8_t als_pers;
382 uint16_t als_thresh_low;
386 uint8_t prx_pers;
395 uint16_t prx_thresh_low;
401
407typedef struct {
408 bool als_int;
409 bool prx_int;
411
415typedef void (*apds99xx_isr_t)(void *arg);
416
417#endif /* MODULE_APDS99XX_FULL */
418
422typedef struct {
423
426#if MODULE_APDS99XX_FULL || DOXYGEN
428 void* isr_arg;
431#endif /* MODULE_APDS99XX_FULL */
432
433} apds99xx_t;
434
435#if MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN
439typedef union {
440
441 struct {
442 uint16_t red;
443 uint16_t green;
444 uint16_t blue;
445 };
446 uint16_t val[3];
449#endif
450
465
480
502int apds99xx_read_als_raw(const apds99xx_t *dev, uint16_t *raw);
503
504#if MODULE_APDS9900 || MODULE_APDS9901 || MODULE_APDS9930 || DOXYGEN
523int apds99xx_read_illuminance(const apds99xx_t *dev, uint16_t *lux);
524
525#endif /* MODULE_APDS9900 || MODULE_APDS9901 || MODULE_APDS9930 || DOXYGEN */
526
527#if MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN
556
557#endif /* MODULE_APDS9950 || MODULE_APDS9960 || DOXYGEN */
558
573
598int apds99xx_read_prx_raw(const apds99xx_t *dev, uint16_t *prx);
599
614
627
628#if MODULE_APDS99XX_FULL || DOXYGEN
629
658 apds99xx_isr_t isr, void *isr_arg);
659
679
680#endif /* MODULE_APDS99XX_FULL */
681
682#ifdef __cplusplus
683}
684#endif
685
686#endif /* APDS99XX_H */
Low-level GPIO peripheral driver interface definitions.
void(* apds99xx_isr_t)(void *arg)
Interrupt service routine function prototype.
Definition apds99xx.h:415
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:304
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:316
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:278
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:289
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:308
@ APDS99XX_PRX_GAIN_8
8 x gain (APDS9930, APDS9960 only)
Definition apds99xx.h:309
@ APDS99XX_PRX_GAIN_1
1 x gain (default)
Definition apds99xx.h:305
@ APDS99XX_PRX_GAIN_2
2 x gain (APDS9930, APDS9960 only)
Definition apds99xx.h:307
@ APDS99XX_PRX_DRIVE_25
25.0 mA
Definition apds99xx.h:319
@ APDS99XX_PRX_DRIVE_12_5
12.5 mA
Definition apds99xx.h:320
@ APDS99XX_PRX_DRIVE_100
100.0 mA (default)
Definition apds99xx.h:317
@ APDS99XX_PRX_DRIVE_50
50.0 mA
Definition apds99xx.h:318
@ APDS99XX_ERROR_NO_DATA
no data are available
Definition apds99xx.h:282
@ APDS99XX_ERROR_I2C
I2C communication error.
Definition apds99xx.h:280
@ APDS99XX_ERROR_RAW_DATA
reading raw data failed
Definition apds99xx.h:283
@ APDS99XX_ERROR_WRONG_ID
wrong id read
Definition apds99xx.h:281
@ APDS99XX_OK
success
Definition apds99xx.h:279
@ APDS99XX_ALS_GAIN_120
120 x gain (APDS9900, APDS9901, APDS9930 only)
Definition apds99xx.h:297
@ APDS99XX_ALS_GAIN_16
16 x gain
Definition apds99xx.h:292
@ APDS99XX_ALS_GAIN_64
64 x gain (APDS9950, APDS9960 only)
Definition apds99xx.h:294
@ APDS99XX_ALS_GAIN_8
8 x gain
Definition apds99xx.h:291
@ APDS99XX_ALS_GAIN_1
1 x gain (default)
Definition apds99xx.h:290
Low-level I2C peripheral driver interface definition.
Interrupt configuration.
Definition apds99xx.h:374
uint16_t als_thresh_high
High threshold value for ALS interrupts.
Definition apds99xx.h:383
uint8_t prx_pers
Number of consecutive proximity values that have to be outside the thresholds to generate an interrup...
Definition apds99xx.h:386
uint16_t als_thresh_low
Low threshold value for ALS interrupts.
Definition apds99xx.h:382
uint16_t prx_thresh_low
Low threshold for proximity values (only the low byte is used for APDS9960)
Definition apds99xx.h:395
bool als_int_en
ALS interrupt enabled.
Definition apds99xx.h:375
bool prx_int_en
Proximity interrupt enabled.
Definition apds99xx.h:385
uint8_t als_pers
Number of consecutive ALS values that have to be outside the thresholds to generate an interrupt:
Definition apds99xx.h:376
uint16_t prx_thresh_high
High threshold for proximity values (only the low byte is used for APDS9960)
Definition apds99xx.h:397
Interrupt source.
Definition apds99xx.h:407
bool prx_int
Proximity interrupt happened.
Definition apds99xx.h:409
bool als_int
ALS interrupt happened.
Definition apds99xx.h:408
APDS99XX device initialization parameters.
Definition apds99xx.h:326
unsigned dev
I2C device (default I2C_DEV(0))
Definition apds99xx.h:328
gpio_t int_pin
interrupt pin: GPIO_UNDEF if not used
Definition apds99xx.h:348
apds99xx_als_gain_t als_gain
Gain used for ALS.
Definition apds99xx.h:332
uint16_t wait_steps
Waiting time in steps.
Definition apds99xx.h:343
apds99xx_prx_gain_t prx_gain
Gain used for proximity sensing.
Definition apds99xx.h:340
uint8_t prx_pulses
IR LED pulses for proximity sensing.
Definition apds99xx.h:335
apds99xx_prx_drive_t prx_drive
IR LED current for proximity sensing (default APDS99XX_PRX_DRIVE_100)
Definition apds99xx.h:338
uint16_t als_steps
ALS integration time in steps.
Definition apds99xx.h:330
bool wait_long
Long waiting time.
Definition apds99xx.h:345
APDS99XX sensor device data structure type.
Definition apds99xx.h:422
apds99xx_params_t params
device initialization parameters
Definition apds99xx.h:424
void * isr_arg
user ISR argument
Definition apds99xx.h:428
bool gpio_init
GPIO is already initialized.
Definition apds99xx.h:430
apds99xx_isr_t isr
user ISR
Definition apds99xx.h:427
RGB count value data structure (APDS9950 and APDS9960 only)
Definition apds99xx.h:439
uint16_t green
G photodiode count value (green)
Definition apds99xx.h:443
uint16_t blue
B photodiode count value (blue)
Definition apds99xx.h:444
uint16_t red
R photodiode count value (red)
Definition apds99xx.h:442