2014-10-06 18:50:24 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-11-19 17:13:33 +01:00
|
|
|
* @defgroup drivers_isl29020 ISL29020 light sensor
|
2015-09-25 21:06:17 +02:00
|
|
|
* @ingroup drivers_sensors
|
2018-06-12 10:35:56 +02:00
|
|
|
* @ingroup drivers_saul
|
2014-10-06 18:50:24 +02:00
|
|
|
* @brief Device driver for the ISL29020 light sensor
|
2018-06-12 10:35:56 +02:00
|
|
|
*
|
|
|
|
* This driver provides @ref drivers_saul capabilities.
|
2014-10-06 18:50:24 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Device driver interface for the ISL29020 light sensor
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
2015-03-30 15:58:12 +02:00
|
|
|
#ifndef ISL29020_H
|
|
|
|
#define ISL29020_H
|
2014-10-06 18:50:24 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "periph/i2c.h"
|
|
|
|
|
2014-10-22 07:47:04 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-04-07 19:09:51 +02:00
|
|
|
/**
|
|
|
|
* @defgroup drivers_isl29020_config ISL29020 light sensor driver compile configuration
|
|
|
|
* @ingroup config_drivers_sensors
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Default address
|
|
|
|
*
|
2020-04-30 19:31:55 +02:00
|
|
|
* The address depends on the status of A0 Pin. Default address corresponds to
|
|
|
|
* A0 connected to GND. For more information refer to the section 'I2C
|
|
|
|
* Interface' in the datasheet.
|
2020-04-07 19:09:51 +02:00
|
|
|
*/
|
2020-04-30 19:21:52 +02:00
|
|
|
#ifndef CONFIG_ISL29020_DEFAULT_ADDRESS
|
|
|
|
#define CONFIG_ISL29020_DEFAULT_ADDRESS 0x44
|
2020-04-07 19:09:51 +02:00
|
|
|
#endif
|
|
|
|
/** @} */
|
2014-10-06 18:50:24 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Possible modes for the ISL29020 sensor
|
2014-10-06 18:50:24 +02:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Possible range values for the ISL29020 sensor
|
2014-10-06 18:50:24 +02:00
|
|
|
*/
|
|
|
|
typedef enum {
|
2015-05-02 08:33:15 +02:00
|
|
|
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 */
|
2014-10-06 18:50:24 +02:00
|
|
|
} isl29020_range_t;
|
|
|
|
|
2015-11-18 16:14:42 +01:00
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Data structure holding the full set of configuration parameters
|
2015-11-18 16:14:42 +01:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2018-02-28 18:03:43 +01:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
|
2014-10-06 18:50:24 +02:00
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Initialize a new ISL29020 device
|
2014-10-06 18:50:24 +02:00
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor of an ISL29020 device
|
2018-02-28 18:03:43 +01:00
|
|
|
* @param[in] params initialization parameters
|
2014-10-06 18:50:24 +02:00
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return -1 on error
|
|
|
|
*/
|
2018-02-28 18:03:43 +01:00
|
|
|
int isl29020_init(isl29020_t *dev, const isl29020_params_t *params);
|
2014-10-06 18:50:24 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Read a lighting value from the sensor, the result is given in lux
|
2014-10-06 18:50:24 +02:00
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor of an ISL29020 device
|
|
|
|
*
|
2015-05-02 08:33:15 +02:00
|
|
|
* @return the measured brightness in lux
|
2014-10-06 18:50:24 +02:00
|
|
|
* @return -1 on error
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
int isl29020_read(const isl29020_t *dev);
|
2014-10-06 18:50:24 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Enable the given sensor
|
2014-10-06 18:50:24 +02:00
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor of an ISL29020 device
|
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return -1 on error
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
int isl29020_enable(const isl29020_t *dev);
|
2014-10-06 18:50:24 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Disable the given sensor
|
2014-10-06 18:50:24 +02:00
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor of an ISL29020 device
|
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return -1 on error
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
int isl29020_disable(const isl29020_t *dev);
|
2014-10-06 18:50:24 +02:00
|
|
|
|
2014-10-22 07:47:04 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-30 15:58:12 +02:00
|
|
|
#endif /* ISL29020_H */
|
2014-10-06 18:50:24 +02:00
|
|
|
/** @} */
|