esp-idf-lib/components/apds9930/apds9930.c

Mon, 03 Apr 2023 11:08:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 03 Apr 2023 11:08:09 +0200
changeset 11
bdc123ae7b49
child 12
bb72d448e282
permissions
-rw-r--r--

Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.

11
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file APDS-9930.cpp
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief Library for the SparkFun APDS-9930 breakout board
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * @author Shawn Hymel (SparkFun Electronics)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * @copyright This code is public domain but you buy me a beer if you use
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * this and we meet someday (Beerware license). Davide Depau Arduino version.
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * This library interfaces the Avago APDS-9930 to ESP-IDf over I2C.
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 *
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * APDS-9930 current draw tests (default parameters):
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * Off: 1mA
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * Waiting for gesture: 14mA
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * Gesture in progress: 35mA
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "apds9930.h"
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include <inttypes.h>
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include <esp_log.h>
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include <esp_idf_lib_helpers.h>
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 #define I2C_FREQ_HZ 1000000 // Max 1MHz for esp-idf
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 static const char *TAG = "apds9930";
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 /* Error code for returned values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #define APDS9930_ERROR 0xFF
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 /* Command register modes */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 #define APDS9930_REPEATED_BYTE 0x80
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 #define APDS9930_AUTO_INCREMENT 0xA0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 #define APDS9930_SPECIAL_FN 0xE0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 /* APDS-9930 register addresses */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #define APDS9930_ENABLE 0x00
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 #define APDS9930_ATIME 0x01
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #define APDS9930_PTIME 0x02
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 #define APDS9930_WTIME 0x03
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 #define APDS9930_AILTL 0x04
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 #define APDS9930_AILTH 0x05
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 #define APDS9930_AIHTL 0x06
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 #define APDS9930_AIHTH 0x07
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 #define APDS9930_PILTL 0x08
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 #define APDS9930_PILTH 0x09
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 #define APDS9930_PIHTL 0x0A
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 #define APDS9930_PIHTH 0x0B
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 #define APDS9930_PERS 0x0C
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 #define APDS9930_CONFIG 0x0D
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 #define APDS9930_PPULSE 0x0E
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 #define APDS9930_CONTROL 0x0F
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 #define APDS9930_ID 0x12
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 #define APDS9930_STATUS 0x13
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 #define APDS9930_Ch0DATAL 0x14
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 #define APDS9930_Ch0DATAH 0x15
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 #define APDS9930_Ch1DATAL 0x16
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 #define APDS9930_Ch1DATAH 0x17
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 #define APDS9930_PDATAL 0x18
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 #define APDS9930_PDATAH 0x19
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 #define APDS9930_POFFSET 0x1E
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 /* Bit fields */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 #define APDS9930_PON 0b00000001
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 #define APDS9930_AEN 0b00000010
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 #define APDS9930_PEN 0b00000100
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 #define APDS9930_WEN 0b00001000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 #define APSD9930_AIEN 0b00010000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 #define APDS9930_PIEN 0b00100000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 #define APDS9930_SAI 0b01000000
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 /* On/Off definitions */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 #define APDS9930_OFF 0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 #define APDS9930_ON 1
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 /* Default values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 #define APDS9930_DEFAULT_ATIME 0xED
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 #define APDS9930_DEFAULT_WTIME 0xFF
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 #define APDS9930_DEFAULT_PTIME 0xFF
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 #define APDS9930_DEFAULT_PPULSE 0x08
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 #define APDS9930_DEFAULT_POFFSET 0 // 0 offset
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 #define APDS9930_DEFAULT_CONFIG 0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 #define APDS9930_DEFAULT_PDRIVE APDS9930_LED_DRIVE_100MA
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 #define APDS9930_DEFAULT_PDIODE 2
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 #define APDS9930_DEFAULT_PGAIN APDS9930_PGAIN_8X
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 #define APDS9930_DEFAULT_AGAIN APDS9930_AGAIN_1X
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 #define APDS9930_DEFAULT_PILT 0 // Low proximity threshold
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 #define APDS9930_DEFAULT_PIHT 50 // High proximity threshold
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 #define APDS9930_DEFAULT_AILT 0xFFFF // Force interrupt for calibration
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 #define APDS9930_DEFAULT_AIHT 0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 #define APDS9930_DEFAULT_PERS 0x22 // 2 consecutive prox or ALS for int.
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 /* Acceptable parameters for setMode */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 #define APDS9930_MODE_POWER 0
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 #define APDS9930_MODE_AMBIENT_LIGHT 1
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 #define APDS9930_MODE_PROXIMITY 2
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 #define APDS9930_MODE_WAIT 3
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 #define APDS9930_MODE_AMBIENT_LIGHT_INT 4
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 #define APDS9930_MODE_PROXIMITY_INT 5
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 #define APDS9930_MODE_SLEEP_AFTER_INT 6
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 #define APDS9930_MODE_ALL 7
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 /* Interrupt clear values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 #define APDS9930_CLEAR_PROX_INT 0xE5
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 #define APDS9930_CLEAR_ALS_INT 0xE6
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 #define APDS9930_CLEAR_ALL_INTS 0xE7
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 /* ALS coefficients */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 #define APDS9930_DF 52
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 #define APDS9930_GA 0.49
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 #define APDS9930_ALS_B 1.862
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 #define APDS9930_ALS_C 0.746
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 #define APDS9930_ALS_D 1.291
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 #define CHECK(x) do { esp_err_t __; if ((__ = x) != ESP_OK) return __; } while (0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 #define CHECK_ARG(VAL) do { if (!(VAL)) return ESP_ERR_INVALID_ARG; } while (0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 #define CHECK_LOGE(dev, x, msg, ...) do { \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 esp_err_t __; \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 if ((__ = x) != ESP_OK) { \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 I2C_DEV_GIVE_MUTEX(dev); \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 ESP_LOGE(TAG, msg, ## __VA_ARGS__); \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 return __; \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 } \
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 } while (0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 inline static esp_err_t write_register8(i2c_dev_t *dev, uint8_t addr, uint8_t value)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 return i2c_dev_write_reg(dev, addr, &value, 1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 esp_err_t apds9930_init_desc(i2c_dev_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 CHECK_ARG(addr & 0x20);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 dev->port = port;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 dev->addr = addr;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 dev->cfg.sda_io_num = sda_gpio;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 dev->cfg.scl_io_num = scl_gpio;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 #if HELPER_TARGET_IS_ESP32
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 dev->cfg.master.clk_speed = I2C_FREQ_HZ;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 #endif
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 return i2c_dev_create_mutex(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 esp_err_t apds9930_free_desc(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 return i2c_dev_delete_mutex(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 esp_err_t apds9930_init(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 esp_err_t err = ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 uint8_t id;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_ID, &id, 1), "Sensor not found");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 if (id != APDS9930_ID_1 && id != APDS9930_ID_2 && id != APDS9930_ID_3) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 CHECK_LOGE(dev, ESP_ERR_INVALID_VERSION,
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 "Invalid chip ID: expected: 0x%x or 0x%x or 0x%x got: 0x%x",
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 APDS9930_ID_1, APDS9930_ID_2, APDS9930_ID_3, id);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 /* Set ENABLE register to 0 (disable all features) */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 if ( !apds9930_setMode(dev, APDS9930_MODE_ALL, APDS9930_OFF) ) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 ESP_LOGE(TAG, "Regs off");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 err = ESP_ERR_INVALID_ARG;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 /* Set default values for ambient light and proximity registers */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 CHECK_LOGE(dev, write_register8(dev, APDS9930_ATIME, APDS9930_DEFAULT_ATIME), "Default atime");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 CHECK_LOGE(dev, write_register8(dev, APDS9930_WTIME, APDS9930_DEFAULT_WTIME), "Default wtime");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 CHECK_LOGE(dev, write_register8(dev, APDS9930_PPULSE, APDS9930_DEFAULT_PPULSE), "Default ppulse");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 CHECK_LOGE(dev, write_register8(dev, APDS9930_POFFSET, APDS9930_DEFAULT_POFFSET), "Default poffset");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 CHECK_LOGE(dev, write_register8(dev, APDS9930_CONFIG, APDS9930_DEFAULT_CONFIG), "Default config");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 CHECK_LOGE(dev, apds9930_setLEDDrive(dev, APDS9930_DEFAULT_PDRIVE), "Default pdrive");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 CHECK_LOGE(dev, apds9930_setProximityGain(dev, APDS9930_DEFAULT_PGAIN), "Default pgain");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 CHECK_LOGE(dev, apds9930_setAmbientLightGain(dev, APDS9930_DEFAULT_AGAIN), "Default again");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 CHECK_LOGE(dev, apds9930_setProximityDiode(dev, APDS9930_DEFAULT_PDIODE), "Default pdiode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 CHECK_LOGE(dev, apds9930_setProximityIntLowThreshold(dev, APDS9930_DEFAULT_PILT), "Default PILT");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 CHECK_LOGE(dev, apds9930_setProximityIntHighThreshold(dev, APDS9930_DEFAULT_PIHT), "Default PIHT");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 CHECK_LOGE(dev, apds9930_setLightIntLowThreshold(dev, APDS9930_DEFAULT_AILT), "Default ailt");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 CHECK_LOGE(dev, apds9930_setLightIntHighThreshold(dev, APDS9930_DEFAULT_AIHT), "Default aiht");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 CHECK_LOGE(dev, write_register8(dev, APDS9930_PERS, APDS9930_DEFAULT_PERS), "Default pers");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 return err;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 * Public methods for controlling the APDS-9930
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 uint8_t apds9930_getMode(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 uint8_t enable_value;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 /* Read current ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 if (i2c_dev_read_reg(dev, APDS9930_ENABLE, &enable_value, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 return APDS9930_ERROR;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 return enable_value;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 esp_err_t apds9930_setMode(i2c_dev_t *dev, uint8_t mode, uint8_t enable)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 uint8_t reg_val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 /* Read current ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 reg_val = apds9930_getMode(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 if( reg_val == APDS9930_ERROR ) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 return ESP_ERR_INVALID_RESPONSE;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 /* Change bit(s) in ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 enable = enable & 0x01;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 if (mode <= 6) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 if (enable) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 reg_val |= (1 << mode);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 reg_val &= ~(1 << mode);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 } else if (mode == APDS9930_MODE_ALL) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 if (enable) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 reg_val = 0x7F;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 reg_val = 0x00;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 /* Write value back to ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 CHECK_LOGE(dev, write_register8(dev, APDS9930_ENABLE, reg_val), "Enable register");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 esp_err_t apds9930_enableLightSensor(i2c_dev_t *dev, bool interrupts)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 /* Set default gain, interrupts, enable power, and enable sensor */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 CHECK_LOGE(dev, apds9930_setAmbientLightGain(dev, APDS9930_DEFAULT_AGAIN), "setAmbientLightGain");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 if ( interrupts ) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 CHECK_LOGE(dev, apds9930_setAmbientLightIntEnable(dev, 1), "setAmbientLightIntEnable(1)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 CHECK_LOGE(dev, apds9930_setAmbientLightIntEnable(dev, 0), "setAmbientLightIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 CHECK_LOGE(dev, apds9930_enablePower(dev), "enablePower");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_AMBIENT_LIGHT, 1), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 esp_err_t apds9930_disableLightSensor(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 CHECK_LOGE(dev, apds9930_setAmbientLightIntEnable(dev, 0), "setAmbientLightIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_AMBIENT_LIGHT, 0), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 esp_err_t apds9930_enableProximitySensor(i2c_dev_t *dev, bool interrupts)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 /* Set default gain, LED, interrupts, enable power, and enable sensor */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 CHECK_LOGE(dev, apds9930_setProximityGain(dev, APDS9930_DEFAULT_PGAIN), "setProximityGain");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 CHECK_LOGE(dev, apds9930_setLEDDrive(dev, APDS9930_DEFAULT_PDRIVE), "setLEDDrive");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 if( interrupts ) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 CHECK_LOGE(dev, apds9930_setProximityIntEnable(dev, 1), "setProximityIntEnable(1)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 } else {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 CHECK_LOGE(dev, apds9930_setProximityIntEnable(dev, 0), "setProximityIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 CHECK_LOGE(dev, apds9930_enablePower(dev), "enablePower");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_PROXIMITY, 1), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 esp_err_t apds9930_disableProximitySensor(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 CHECK_LOGE(dev, apds9930_setProximityIntEnable(dev, 0), "setProximityIntEnable(0)");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 CHECK_LOGE(dev, apds9930_setMode(dev, APDS9930_MODE_PROXIMITY, 0), "setMode");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 esp_err_t apds9930_enablePower(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 return apds9930_setMode(dev, APDS9930_MODE_POWER, 1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 esp_err_t apds9930_disablePower(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 return apds9930_setMode(dev, APDS9930_MODE_POWER, 0);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 * Ambient light sensor controls
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 esp_err_t apds9930_readAmbientLightLux(i2c_dev_t *dev, float *val)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 uint16_t Ch0, Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 /* Read value from channels */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 CHECK_LOGE(dev, apds9930_readCh0Light(dev, &Ch0), "read ch0");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 CHECK_LOGE(dev, apds9930_readCh1Light(dev, &Ch1), "read ch1");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 *val = apds9930_floatAmbientToLux(dev, Ch0, Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 esp_err_t apds9930_readulAmbientLightLux(i2c_dev_t *dev, unsigned long *val)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 uint16_t Ch0, Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 /* Read value from channels */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 CHECK_LOGE(dev, apds9930_readCh0Light(dev, &Ch0), "read ch0");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 CHECK_LOGE(dev, apds9930_readCh1Light(dev, &Ch1), "read ch1");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 *val = apds9930_ulongAmbientToLux(dev, Ch0, Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 float apds9930_floatAmbientToLux(i2c_dev_t *dev, uint16_t Ch0, uint16_t Ch1)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 uint8_t x[4] = {1,8,16,120};
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 float iac;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 float ALSIT = 2.73 * (256 - APDS9930_DEFAULT_ATIME);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 if ((Ch0 - APDS9930_ALS_B * Ch1) > (APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1))
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 iac = Ch0 - APDS9930_ALS_B * Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365 else
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 iac = APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 //float iac = fmax(Ch0 - APDS9930_ALS_B * Ch1, APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368 if (iac < 0)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 iac = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370 float lpc = APDS9930_GA * APDS9930_DF / (ALSIT * x[apds9930_getAmbientLightGain(dev)]);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371 return iac * lpc;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375 unsigned long apds9930_ulongAmbientToLux(i2c_dev_t *dev, uint16_t Ch0, uint16_t Ch1)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 uint8_t x[4] = {1,8,16,120};
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 unsigned long iac;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 unsigned long ALSIT = 2.73 * (256 - APDS9930_DEFAULT_ATIME);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 if ((Ch0 - APDS9930_ALS_B * Ch1) > (APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1))
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 iac = Ch0 - APDS9930_ALS_B * Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 else
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 iac = APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 //unsigned long iac = max(Ch0 - APDS9930_ALS_B * Ch1, APDS9930_ALS_C * Ch0 - APDS9930_ALS_D * Ch1);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 // if (iac < 0) iac = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 unsigned long lpc = APDS9930_GA * APDS9930_DF / (ALSIT * x[apds9930_getAmbientLightGain(dev)]);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 return iac * lpc;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392 esp_err_t apds9930_readCh0Light(i2c_dev_t *dev, uint16_t *val)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 *val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 CHECK_ARG(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 /* Read value from channel 0 */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_Ch0DATAL, &val_byte, 1), "Read ch0 low");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 *val = val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_Ch0DATAH, &val_byte, 1), "Read ch0 high");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 *val += ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 esp_err_t apds9930_readCh1Light(i2c_dev_t *dev, uint16_t *val)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 *val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417 /* Read value from channel 1 */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_Ch1DATAL, &val_byte, 1), "Read ch1 low");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 *val = val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_Ch1DATAH, &val_byte, 1), "Read ch1 high");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 *val += ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 * Proximity sensor controls
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 esp_err_t apds9930_readProximity(i2c_dev_t *dev, uint16_t *val)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
432 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 *val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 /* Read value from proximity data register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_PDATAL, &val_byte, 1), "Read proximity low");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 *val = val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_PDATAH, &val_byte, 1), "Read proximity high");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 *val += ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 /*******************************************************************************
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 * Getters and setters for register values
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 ******************************************************************************/
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451 uint16_t apds9930_getProximityIntLowThreshold(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
452 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 uint16_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
454 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 /* Read value from PILT register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
457 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 if (i2c_dev_read_reg(dev, APDS9930_PILTL, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 val = val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 if (i2c_dev_read_reg(dev, APDS9930_PILTH, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
463 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466 val |= ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
469 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 esp_err_t apdsi9930_setProximityIntLowThreshold(i2c_dev_t *dev, uint16_t threshold)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 uint8_t lo;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 uint8_t hi;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 hi = threshold >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477 lo = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_PILTL, &lo, 1), "Write PILTL");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_PILTH, &hi, 1), "Write PILTH");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 uint16_t apds9930_getProximityIntHighThreshold(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490 uint16_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
492
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
493 /* Read value from PIHT register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
495 if (i2c_dev_read_reg(dev, APDS9930_PIHTL, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 val = val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499 if (i2c_dev_read_reg(dev, APDS9930_PIHTH, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 val = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 val |= ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 esp_err_t apds9930_setProximityIntHighThreshold(i2c_dev_t *dev, uint16_t threshold)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 uint8_t lo;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 uint8_t hi;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 hi = threshold >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514 lo = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_PIHTL, &lo, 1), "Write PIHTL");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_PIHTH, &hi, 1), "Write PIHTH");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
522 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 uint8_t apds9930_getLEDDrive(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
526 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
530 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531 if (i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
537 /* Shift and mask out LED drive bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 val = (val >> 6) & 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
542
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
543
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544 esp_err_t apds9930_setLEDDrive(i2c_dev_t *dev, uint8_t drive)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
547
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1), "Read control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554 drive = drive << 6;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555 val &= 0b00111111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 /* Write register value back into CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_CONTROL, &val, 1), "Write control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 uint8_t apds9930_getProximityGain(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 if (i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
578 /* Shift and mask out PDRIVE bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 val = (val >> 2) & 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 esp_err_t apds9930_setProximityGain(i2c_dev_t *dev, uint8_t drive)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
588
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1), "Read control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595 drive = drive << 2;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596 val &= 0b11110011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 /* Write register value back into CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_CONTROL, &val, 1), "Write control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
605
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 uint8_t apds9930_getProximityDiode(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
609 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
612 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
613 if (i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
614 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
615 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
618
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619 /* Shift and mask out PDRIVE bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620 val = (val >> 4) & 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
621
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
622 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
623 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
624
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
625
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
626 esp_err_t apds9930_setProximityDiode(i2c_dev_t *dev, uint8_t drive)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
627 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
628 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
629
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
630 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
631 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1), "Read control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
634 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
635 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
636 drive = drive << 4;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637 val &= 0b11001111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
638 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
639
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640 /* Write register value back into CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_CONTROL, &val, 1), "Write control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
644 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
646
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
647
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648 uint8_t apds9930_getAmbientLightGain(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
650 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
651
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
652 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
653 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
654 if (i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
656 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
657 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
660 /* Shift and mask out ADRIVE bits */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
661 val &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
662
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
663 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
664 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
665
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
666
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
667 esp_err_t apds9930_setAmbientLightGain(i2c_dev_t *dev, uint8_t drive)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
668 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
669 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
670
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
671 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
672 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
673 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1), "Read control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
674
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
675 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
676 drive &= 0b00000011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
677 val &= 0b11111100;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
678 val |= drive;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
679
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
680 /* Write register value back into CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
681 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_CONTROL, &val, 1), "Write control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
682 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
683
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
684 return true;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
685 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
686
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
687
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
688 uint8_t apds9930_getAmbientGainLevel(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
689 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
690 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
691
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
692 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
693 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
694 if (i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
695 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
696 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
697 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
698 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
699
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
700 /* Shift and mask out AGL bit */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
701 val = (val >> 2) & 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
702
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
703 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
704 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
705
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
706
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707 esp_err_t apds9930_setAmbientGainLevel(i2c_dev_t *dev, uint8_t enable)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
710
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711 /* Read value from CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
712 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_CONTROL, &val, 1), "Read control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
716 enable &= 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
717 enable = enable << 2;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718 val &= 0b11111011;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 val |= enable;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
720
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721 /* Write register value back into CONTROL register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_CONTROL, &val, 1), "Write control");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
726 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
728
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
729 esp_err_t apds9930_getLightIntLowThreshold(i2c_dev_t *dev, uint16_t *threshold)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
730 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
731 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
732 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
733
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
734 /* Read value from ambient light low threshold, low byte register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
736 if (i2c_dev_read_reg(dev, APDS9930_AILTL, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
737 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
738 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739 *threshold = val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
740 if (i2c_dev_read_reg(dev, APDS9930_AILTH, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
741 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
742 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 *threshold = *threshold + ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
747 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
748
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
749
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750 esp_err_t apds9930_setLightIntLowThreshold(i2c_dev_t *dev, uint16_t threshold)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 uint8_t val_low;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
753 uint8_t val_high;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
754
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
755 /* Break 16-bit threshold into 2 8-bit values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756 val_low = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757 val_high = (threshold & 0xFF00) >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
759 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_AILTL, &val_low, 1), "Write AILTL");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_AILTH, &val_high, 1), "Write AILTH");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
762 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
763
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
764 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
765 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 esp_err_t apds9930_getLightIntHighThreshold(i2c_dev_t *dev, uint16_t *threshold)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
769 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770 uint8_t val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
773 /* Read value from ambient light high threshold, low byte register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775 if (i2c_dev_read_reg(dev, APDS9930_AIHTL, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
778 *threshold = val_byte;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779 if (i2c_dev_read_reg(dev, APDS9930_AIHTH, &val_byte, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
780 *threshold = 0;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783 *threshold = *threshold + ((uint16_t)val_byte << 8);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
784
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
786 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
787
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
789 esp_err_t apds9930_setLightIntHighThreshold(i2c_dev_t *dev, uint16_t threshold)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
791 uint8_t val_low;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
792 uint8_t val_high;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
794 /* Break 16-bit threshold into 2 8-bit values */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795 val_low = threshold & 0x00FF;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
796 val_high = (threshold & 0xFF00) >> 8;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
797
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_AIHTL, &val_low, 1), "Write AIHTL");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_AIHTH, &val_high, 1), "Write AIHTH");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
801 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
804 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807 uint8_t apds9930_getAmbientLightIntEnable(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811 /* Read value from ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
813 if (i2c_dev_read_reg(dev, APDS9930_ENABLE, &val, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
818
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
819 /* Shift and mask out AIEN bit */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 val = (val >> 4) & 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
821
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
823 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826 esp_err_t apds9930_setAmbientLightIntEnable(i2c_dev_t *dev, uint8_t enable)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
829
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
830 /* Read value from ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
831 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
832 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_ENABLE, &val, 1), "Read enable");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
833
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
834 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
835 enable &= 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
836 enable = enable << 4;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
837 val &= 0b11101111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
838 val |= enable;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840 /* Write register value back into ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
841 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_ENABLE, &val, 1), "Write enable");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
842 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
843
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
844 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
848 uint8_t apds9930_getProximityIntEnable(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
849 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
850 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
851
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852 /* Read value from ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
853 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
854 if (i2c_dev_read_reg(dev, APDS9930_ENABLE, &val, 1) != ESP_OK) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
856 return APDS9930_ERROR;;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
857 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
858 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
859
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
860 /* Shift and mask out PIEN bit */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
861 val = (val >> 5) & 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
862
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
863 return val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
864 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
865
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
866
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
867 esp_err_t apds9930_setProximityIntEnable(i2c_dev_t *dev, uint8_t enable)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
868 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
869 uint8_t val;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
870
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
871 /* Read value from ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
872 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873 CHECK_LOGE(dev, i2c_dev_read_reg(dev, APDS9930_ENABLE, &val, 1), "Read enable");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
874
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
875 /* Set bits in register to given value */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876 enable &= 0b00000001;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
877 enable = enable << 5;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
878 val &= 0b11011111;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
879 val |= enable;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
880
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881 /* Write register value back into ENABLE register */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
882 CHECK_LOGE(dev, i2c_dev_write_reg(dev, APDS9930_ENABLE, &val, 1), "Write enable");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
883 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
886 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
887
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
888
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
889 esp_err_t apds9930_clearAmbientLightInt(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
890 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
891 uint8_t val = APDS9930_CLEAR_ALS_INT;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
892
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
893 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
894 /* This should write to the chip without register address */
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
895 CHECK_LOGE(dev, i2c_dev_write(dev, NULL, 0, &val, 1), "Clear ALS_INT");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
896 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
897
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
898 // if( !wireWriteByte(CLEAR_ALS_INT) ) {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
899 // return false;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
900 //}
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
901
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
902 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
903 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
904
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
905
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
906 esp_err_t apds9930_clearProximityInt(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
907 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
908 uint8_t val = APDS9930_CLEAR_PROX_INT;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
909
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
911 CHECK_LOGE(dev, i2c_dev_write(dev, NULL, 0, &val, 1), "Clear PROX_INT");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
912 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
913
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
914 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
915 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
916
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
917
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
918 esp_err_t apds9930_clearAllInts(i2c_dev_t *dev)
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
919 {
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
920 uint8_t val = APDS9930_CLEAR_ALL_INTS;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
921
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
922 I2C_DEV_TAKE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
923 CHECK_LOGE(dev, i2c_dev_write(dev, NULL, 0, &val, 1), "Clear ALL_INTS");
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924 I2C_DEV_GIVE_MUTEX(dev);
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
925
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
926 return ESP_OK;
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
927 }
bdc123ae7b49 Added untested port of the Arduino APDS9930 library as component into the esp-idf-lib.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
928

mercurial