2015-05-31 15:11:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 PHYTEC Messtechnik GmbH
|
2017-02-16 12:38:29 +01:00
|
|
|
* 2017 Freie Universität Berlin
|
2015-05-31 15:11:40 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-02-16 12:38:29 +01:00
|
|
|
* @defgroup drivers_tcs37727 TCS37727 RGB Light Sensor
|
2015-11-19 17:13:33 +01:00
|
|
|
* @ingroup drivers_sensors
|
2018-06-12 10:35:56 +02:00
|
|
|
* @ingroup drivers_saul
|
2015-05-31 15:11:40 +02:00
|
|
|
* @brief Driver for the AMS TCS37727 Color Light-To-Digital Converter
|
|
|
|
*
|
2018-06-12 10:35:56 +02:00
|
|
|
* This driver provides @ref drivers_saul capabilities.
|
2015-05-31 15:11:40 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Interface definition for the TCS37727 sensor driver.
|
|
|
|
*
|
|
|
|
* @author Felix Siebel <f.siebel@phytec.de>
|
|
|
|
* @author Johann Fischer <j.fischer@phytec.de>
|
2017-02-16 12:38:29 +01:00
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2015-05-31 15:11:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TCS37727_H
|
|
|
|
#define TCS37727_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2017-02-16 12:38:29 +01:00
|
|
|
|
2015-05-31 15:11:40 +02:00
|
|
|
#include "periph/i2c.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2020-04-07 19:55:11 +02:00
|
|
|
/**
|
|
|
|
* @brief Default Device Address
|
|
|
|
*/
|
|
|
|
#define TCS37727_I2C_ADDRESS 0x29
|
2015-05-31 15:11:40 +02:00
|
|
|
|
2020-04-06 08:52:08 +02:00
|
|
|
/**
|
|
|
|
* @defgroup drivers_tcs37727_config TCS37727 RGB Light Sensor driver compile configuration
|
|
|
|
* @ingroup config_drivers_sensors
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
2020-04-28 18:51:30 +02:00
|
|
|
* @brief Default RGBC integration time in microseconds.
|
|
|
|
*
|
2020-04-29 05:49:05 +02:00
|
|
|
* RGBC integration time impacts both the resolution and the sensitivity of the
|
|
|
|
* RGBC reading. Refer to the section "RGBC Time Register" in the datasheet for
|
|
|
|
* more information.
|
2020-04-06 08:52:08 +02:00
|
|
|
*/
|
2020-04-28 18:51:30 +02:00
|
|
|
#ifndef CONFIG_TCS37727_ATIME_DEFAULT
|
|
|
|
#define CONFIG_TCS37727_ATIME_DEFAULT 200000
|
2015-05-31 15:11:40 +02:00
|
|
|
#endif
|
2020-04-06 08:52:08 +02:00
|
|
|
/** @} */
|
2015-05-31 15:11:40 +02:00
|
|
|
|
|
|
|
/**
|
2017-02-16 12:38:29 +01:00
|
|
|
* @brief Struct for storing TCS37727 sensor data
|
2015-05-31 15:11:40 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint32_t red; /**< IR compensated channels red */
|
|
|
|
uint32_t green; /**< IR compensated channels green */
|
|
|
|
uint32_t blue; /**< IR compensated channels blue */
|
|
|
|
uint32_t clear; /**< channels clear */
|
|
|
|
uint32_t lux; /**< Lux */
|
|
|
|
uint32_t ct; /**< Color temperature */
|
|
|
|
} tcs37727_data_t;
|
|
|
|
|
|
|
|
/**
|
2017-02-16 12:38:29 +01:00
|
|
|
* @brief TCS37727 configuration parameters
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
i2c_t i2c; /**< I2C bus the sensor is connected to */
|
|
|
|
uint8_t addr; /**< the sensors address on the I2C bus */
|
|
|
|
uint32_t atime; /**< conversion time in microseconds */
|
|
|
|
} tcs37727_params_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Device descriptor for TCS37727 sensors
|
2015-05-31 15:11:40 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2017-02-16 12:38:29 +01:00
|
|
|
tcs37727_params_t p; /**< device configuration */
|
2015-05-31 15:11:40 +02:00
|
|
|
int again; /**< amount of gain */
|
|
|
|
} tcs37727_t;
|
|
|
|
|
|
|
|
/**
|
2017-02-16 12:38:29 +01:00
|
|
|
* @brief Possible TCS27737 return values
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
TCS37727_OK = 0, /**< everything worked as expected */
|
|
|
|
TCS37727_NOBUS = -1, /**< access to the configured I2C bus failed */
|
|
|
|
TCS37727_NODEV = -2 /**< no TCS37727 device found on the bus */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the given TCS37727 sensor
|
|
|
|
*
|
|
|
|
* The sensor is initialized in RGBC only mode with proximity detection turned
|
|
|
|
* off.
|
|
|
|
*
|
|
|
|
* The gain will be initially set to 4x, but it will be adjusted
|
|
|
|
*
|
|
|
|
* The gain value will be initially set to 4x, but it will be automatically
|
|
|
|
* adjusted during runtime.
|
2015-05-31 15:11:40 +02:00
|
|
|
*
|
|
|
|
* @param[out] dev device descriptor of sensor to initialize
|
2017-02-16 12:38:29 +01:00
|
|
|
* @param[in] params static configuration parameters
|
2015-05-31 15:11:40 +02:00
|
|
|
*
|
2017-02-16 12:38:29 +01:00
|
|
|
* @return TCS27737_OK on success
|
|
|
|
* @return TCS37727_NOBUS if initialization of I2C bus fails
|
|
|
|
* @return TCS37727_NODEV if no sensor can be found
|
2015-05-31 15:11:40 +02:00
|
|
|
*/
|
2017-02-16 12:38:29 +01:00
|
|
|
int tcs37727_init(tcs37727_t *dev, const tcs37727_params_t *params);
|
2015-05-31 15:11:40 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Set RGBC enable, this activates periodic RGBC measurements.
|
2015-05-31 15:11:40 +02:00
|
|
|
*
|
|
|
|
* @param[out] dev device descriptor of sensor
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
void tcs37727_set_rgbc_active(const tcs37727_t *dev);
|
2015-05-31 15:11:40 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Set RGBC disable, this deactivates periodic RGBC measurements
|
2017-02-16 12:38:29 +01:00
|
|
|
*
|
2015-05-31 15:11:40 +02:00
|
|
|
* Also turns off the sensor when proximity measurement is disabled.
|
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor of sensor
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
void tcs37727_set_rgbc_standby(const tcs37727_t *dev);
|
2015-05-31 15:11:40 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-29 18:00:46 +02:00
|
|
|
* @brief Read sensor's data
|
2017-02-16 12:38:29 +01:00
|
|
|
*
|
2015-05-31 15:11:40 +02:00
|
|
|
* Besides an Autogain routine is called. If a maximum or minimum threshold
|
|
|
|
* value of the channel clear is reached, then the gain will be changed
|
|
|
|
* correspond to max or min threshold.
|
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor of sensor
|
2017-02-16 12:38:29 +01:00
|
|
|
* @param[out] data device sensor data, MUST not be NULL
|
2015-05-31 15:11:40 +02:00
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
void tcs37727_read(const tcs37727_t *dev, tcs37727_data_t *data);
|
2015-05-31 15:11:40 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#endif /* TCS37727_H */
|
2015-05-31 15:11:40 +02:00
|
|
|
/** @} */
|