esp32-tsl2561
ESP32-compatible C library for TSL2561 Light to Digital Converter.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator
tsl2561.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2017 David Antliff
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
36 #ifndef TSL2561_H
37 #define TSL2561_H
38 
39 #include <stdbool.h>
40 #include "smbus.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
49 typedef enum
50 {
57 
62 typedef enum
63 {
68 
72 typedef enum
73 {
74  TSL2561_GAIN_1X = 0x00,
75  TSL2561_GAIN_16X = 0x10,
77 
78 typedef uint8_t tsl2561_revision_t;
79 typedef uint16_t tsl2561_visible_t;
80 typedef uint16_t tsl2561_infrared_t;
81 
85 typedef struct
86 {
87  bool init;
88  bool powered;
89  smbus_info_t * smbus_info;
94 
101 
106 void tsl2561_free(tsl2561_info_t ** tsl2561_info);
107 
113 esp_err_t tsl2561_init(tsl2561_info_t * tsl2561_info, smbus_info_t * smbus_info);
114 
122 esp_err_t tsl2561_device_id(const tsl2561_info_t * tsl2561_info, tsl2561_device_type_t * device, tsl2561_revision_t * revision);
123 
133 
142 esp_err_t tsl2561_read(tsl2561_info_t * tsl2561_info, tsl2561_visible_t * visible, tsl2561_infrared_t * infrared);
143 
152 uint32_t tsl2561_compute_lux(const tsl2561_info_t * tsl2561_info, tsl2561_visible_t visible, tsl2561_infrared_t infrared);
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #endif // TSL2561_H
Structure containing information related to the SMBus protocol.
Definition: tsl2561.h:85
Integrate over 402 milliseconds.
Definition: tsl2561.h:66
Invalid device.
Definition: tsl2561.h:51
tsl2561_gain_t gain
Current gain for measurements.
Definition: tsl2561.h:92
TSL2561CS (Chipscale)
Definition: tsl2561.h:53
void tsl2561_free(tsl2561_info_t **tsl2561_info)
Delete an existing TSL2561 info instance.
Definition: tsl2561.c:247
TSL2560CS (Chipscale)
Definition: tsl2561.h:52
bool init
True if struct has been initialised, otherwise false.
Definition: tsl2561.h:87
esp_err_t tsl2561_set_integration_time_and_gain(tsl2561_info_t *tsl2561_info, tsl2561_integration_time_t integration_time, tsl2561_gain_t gain)
Set the integration time and gain. These values are set together as they are programmed via the same ...
Definition: tsl2561.c:366
TSL2560T/FN/CL (TMB-6 or Dual Flat No-Lead-6 or ChipLED-6)
Definition: tsl2561.h:54
uint16_t tsl2561_infrared_t
The type of an infrared light measurement value.
Definition: tsl2561.h:80
tsl2561_device_type_t device_type
Detected type of device (Chipscale vs T/FN/CL)
Definition: tsl2561.h:90
smbus_info_t * smbus_info
Pointer to associated SMBus info.
Definition: tsl2561.h:89
esp_err_t tsl2561_device_id(const tsl2561_info_t *tsl2561_info, tsl2561_device_type_t *device, tsl2561_revision_t *revision)
Retrieve the Device Type ID and Revision number from the device.
Definition: tsl2561.c:300
tsl2561_info_t * tsl2561_malloc(void)
Construct a new TSL2561 info instance. New instance should be initialised before calling other functi...
Definition: tsl2561.c:232
uint32_t tsl2561_compute_lux(const tsl2561_info_t *tsl2561_info, tsl2561_visible_t visible, tsl2561_infrared_t infrared)
Compute the Lux approximation from a visible and infrared light measurement. The calculation is perfo...
Definition: tsl2561.c:386
tsl2561_device_type_t
Enum for recognised TSL256x devices.
Definition: tsl2561.h:49
esp_err_t tsl2561_read(tsl2561_info_t *tsl2561_info, tsl2561_visible_t *visible, tsl2561_infrared_t *infrared)
Retrieve a visible and infrared light measurement from the device. This function will sleep until the...
Definition: tsl2561.c:320
uint8_t tsl2561_revision_t
The type of the IC's revision value.
Definition: tsl2561.h:78
uint16_t tsl2561_visible_t
The type of a visible light measurement value.
Definition: tsl2561.h:79
Integrate over 13.7 milliseconds.
Definition: tsl2561.h:64
tsl2561_gain_t
Enum for supported gain values.
Definition: tsl2561.h:72
TSL2561T/FN/CL (TMB-6 or Dual Flat No-Lead-6 or ChipLED-6)
Definition: tsl2561.h:55
bool powered
True if the device has been powered up.
Definition: tsl2561.h:88
esp_err_t tsl2561_init(tsl2561_info_t *tsl2561_info, smbus_info_t *smbus_info)
Initialise a TSL2561 info instance with the specified SMBus information.
Definition: tsl2561.c:261
tsl2561_integration_time_t integration_time
Current integration time for measurements.
Definition: tsl2561.h:91
Integrate over 101 milliseconds.
Definition: tsl2561.h:65
tsl2561_integration_time_t
Enum for supported integration durations. These durations assume the default internal oscillator freq...
Definition: tsl2561.h:62