-
Notifications
You must be signed in to change notification settings - Fork 2k
/
isl29020.h
134 lines (119 loc) · 3.51 KB
/
isl29020.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup drivers_isl29020 ISL29020 light sensor
* @ingroup drivers_sensors
* @ingroup drivers_saul
* @brief Device driver for the ISL29020 light sensor
*
* This driver provides @ref drivers_saul capabilities.
* @{
*
* @file
* @brief Device driver interface for the ISL29020 light sensor
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef ISL29020_H
#define ISL29020_H
#include <stdint.h>
#include "periph/i2c.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup drivers_isl29020_config ISL29020 light sensor driver compile configuration
* @ingroup config_drivers_sensors
* @{
*/
/**
* @brief Default address
*
* The address depends on the status of A0 Pin.
* Default address corresponds to A0 connected to GND.
* For more information on SerialBus Address, refer Section I2C
* Interface on Page 3 of datasheet.
*/
#ifndef ISL29020_DEFAULT_ADDRESS
#define ISL29020_DEFAULT_ADDRESS 0x44
#endif
/** @} */
/**
* @brief Possible modes for the ISL29020 sensor
*/
typedef enum {
ISL29020_MODE_AMBIENT = 0, /**< set sensor to detect ambient light */
ISL29020_MODE_IR = 1 /**< set sensor to detect infrared light */
} isl29020_mode_t;
/**
* @brief Possible range values for the ISL29020 sensor
*/
typedef enum {
ISL29020_RANGE_1K = 0, /**< set range to 0-1000 lux */
ISL29020_RANGE_4K = 1, /**< set range to 0-4000 lux */
ISL29020_RANGE_16K = 2, /**< set range to 0-16000 lux */
ISL29020_RANGE_64K = 3 /**< set range to 0-64000 lux */
} isl29020_range_t;
/**
* @brief Data structure holding the full set of configuration parameters
*/
typedef struct {
i2c_t i2c; /**< I2C bus the device is connected to */
uint8_t addr; /**< address on that bus */
isl29020_range_t range; /**< range setting to use */
isl29020_mode_t mode; /**< measurement mode to use */
} isl29020_params_t;
/**
* @brief Device descriptor for ISL29020 sensors
*/
typedef struct {
isl29020_params_t params; /**< device initialization parameters */
float lux_fac; /**< factor to calculate actual lux value */
} isl29020_t;
/**
* @brief Initialize a new ISL29020 device
*
* @param[in] dev device descriptor of an ISL29020 device
* @param[in] params initialization parameters
*
* @return 0 on success
* @return -1 on error
*/
int isl29020_init(isl29020_t *dev, const isl29020_params_t *params);
/**
* @brief Read a lighting value from the sensor, the result is given in lux
*
* @param[in] dev device descriptor of an ISL29020 device
*
* @return the measured brightness in lux
* @return -1 on error
*/
int isl29020_read(const isl29020_t *dev);
/**
* @brief Enable the given sensor
*
* @param[in] dev device descriptor of an ISL29020 device
*
* @return 0 on success
* @return -1 on error
*/
int isl29020_enable(const isl29020_t *dev);
/**
* @brief Disable the given sensor
*
* @param[in] dev device descriptor of an ISL29020 device
*
* @return 0 on success
* @return -1 on error
*/
int isl29020_disable(const isl29020_t *dev);
#ifdef __cplusplus
}
#endif
#endif /* ISL29020_H */
/** @} */