2016-02-09 23:07:51 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Bas Stottelaar <basstottelaar@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-04-18 21:52:54 +02:00
|
|
|
* @defgroup drivers_si70xx Si7006/13/20/21/5x temperature and humidity sensors
|
2016-05-26 12:53:51 +02:00
|
|
|
* @ingroup drivers_sensors
|
2018-06-12 10:35:56 +02:00
|
|
|
* @ingroup drivers_saul
|
2020-04-18 21:52:54 +02:00
|
|
|
* @brief Driver for the Si7006/13/20/21/5x temperature and humidity sensor
|
|
|
|
*
|
|
|
|
* The Si70xx driver supports a range of similar temperature and humidity
|
|
|
|
* sensors from Silicon Labs.
|
|
|
|
*
|
|
|
|
* The Si7006/13/20/21 sensors support both temperature and relative humidity
|
|
|
|
* reading, while the Si7050/1/3/4/5 sensors only provide a temperature reading
|
|
|
|
* varying in accuracy between +/- 0.1 C to +/- 1.0 C depending on the model.
|
|
|
|
*
|
|
|
|
* For any of the Si705x models, use the pseudo module @p si705x.
|
2018-06-12 10:35:56 +02:00
|
|
|
*
|
|
|
|
* This driver provides @ref drivers_saul capabilities.
|
2016-02-09 23:07:51 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Interface definition of the Si70xx driver.
|
|
|
|
*
|
|
|
|
* @author Bas Stottelaar <basstottelaar@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2017-01-18 13:00:05 +01:00
|
|
|
#ifndef SI70XX_H
|
|
|
|
#define SI70XX_H
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
#include "periph/i2c.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-04-18 21:52:54 +02:00
|
|
|
/**
|
|
|
|
* @brief Compile time macro telling whether the chip has a humidity sensor.
|
|
|
|
*/
|
|
|
|
#if MODULE_SI7050 || MODULE_SI7051 || MODULE_SI7053 || MODULE_SI7054 || \
|
|
|
|
MODULE_SI7055
|
|
|
|
/* Si705x sensors don't have a humidity sensor hardware, only temperature. */
|
|
|
|
#define SI70XX_HAS_HUMIDITY_SENSOR 0
|
|
|
|
#else
|
|
|
|
#define SI70XX_HAS_HUMIDITY_SENSOR 1
|
|
|
|
#endif
|
|
|
|
|
2016-02-09 23:07:51 +01:00
|
|
|
/**
|
2017-07-03 00:00:47 +02:00
|
|
|
* @brief Driver return codes
|
2016-02-09 23:07:51 +01:00
|
|
|
*/
|
2017-07-03 00:00:47 +02:00
|
|
|
enum {
|
|
|
|
SI70XX_OK, /**< All OK */
|
|
|
|
SI70XX_ERR_NODEV, /**< No valid device found on I2C bus */
|
2019-09-14 15:47:10 +02:00
|
|
|
SI70XX_ERR_I2C, /**< An error occurred when reading/writing on I2C bus */
|
2017-07-03 00:00:47 +02:00
|
|
|
};
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
/**
|
2017-07-03 00:00:47 +02:00
|
|
|
* @brief Device initialization parameters.
|
2016-07-18 23:05:17 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
i2c_t i2c_dev; /**< I2C bus the sensor is connected to */
|
|
|
|
uint8_t address; /**< sensor address */
|
|
|
|
} si70xx_params_t;
|
|
|
|
|
2016-02-09 23:07:51 +01:00
|
|
|
/**
|
2017-07-03 00:00:47 +02:00
|
|
|
* @brief Si70xx device descriptor.
|
2016-02-09 23:07:51 +01:00
|
|
|
*/
|
2017-07-03 00:00:47 +02:00
|
|
|
typedef struct {
|
|
|
|
si70xx_params_t params; /**< Device parameters */
|
|
|
|
} si70xx_t;
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize and reset the sensor.
|
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor
|
2017-07-03 00:00:47 +02:00
|
|
|
* @param[in] params initialization parameters
|
|
|
|
*
|
|
|
|
* @return SI70XX_OK on successful initialization
|
|
|
|
* @return -SI70XX_ERR_NOI2C on I2C initialization error
|
|
|
|
* @return -SI70XX_ERR_NODEV on device test error
|
|
|
|
* @return -SI70XX_ERR_I2C on I2C bus error
|
2016-02-09 23:07:51 +01:00
|
|
|
*/
|
2017-07-03 00:00:47 +02:00
|
|
|
int si70xx_init(si70xx_t *dev, const si70xx_params_t *params);
|
2016-02-09 23:07:51 +01:00
|
|
|
|
2020-04-18 21:52:54 +02:00
|
|
|
#if SI70XX_HAS_HUMIDITY_SENSOR || DOXYGEN
|
2016-02-09 23:07:51 +01:00
|
|
|
/**
|
2019-10-23 21:25:51 +02:00
|
|
|
* @brief Read the relative humidity from the sensor. Uses clock stretching.
|
2016-02-09 23:07:51 +01:00
|
|
|
*
|
2020-04-18 21:52:54 +02:00
|
|
|
* This function is only available in models that have a humidity sensor.
|
|
|
|
*
|
2016-02-09 23:07:51 +01:00
|
|
|
* @param[in] dev device descriptor
|
|
|
|
* @return relative humidity in centi-percent (times 100)
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
uint16_t si70xx_get_relative_humidity(const si70xx_t *dev);
|
2020-04-18 21:52:54 +02:00
|
|
|
#endif /* SI70XX_HAS_HUMIDITY_SENSOR || DOXYGEN */
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-23 21:25:51 +02:00
|
|
|
* @brief Read the current temperature from the sensor. Uses clock stretching.
|
2016-02-09 23:07:51 +01:00
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor
|
|
|
|
* @return current temperature in centi-degrees Celsius
|
|
|
|
* (times 100)
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
int16_t si70xx_get_temperature(const si70xx_t *dev);
|
2016-02-09 23:07:51 +01:00
|
|
|
|
2020-04-18 21:52:54 +02:00
|
|
|
#if SI70XX_HAS_HUMIDITY_SENSOR || DOXYGEN
|
2016-02-09 23:07:51 +01:00
|
|
|
/**
|
|
|
|
* @brief Read the relative humidity and temperature from the sensor. Uses
|
|
|
|
* clock stretching.
|
|
|
|
*
|
2020-04-18 21:52:54 +02:00
|
|
|
* This function is only available in models that have a humidity sensor.
|
|
|
|
*
|
2016-02-09 23:07:51 +01:00
|
|
|
* @param[in] dev device descriptor
|
|
|
|
* @param[out] humidity pointer to relative humidity (in centi-percent)
|
|
|
|
* @param[out] temperature pointer to temperature (in centi-degrees Celsius)
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
void si70xx_get_both(const si70xx_t *dev, uint16_t *humidity, int16_t *temperature);
|
2020-04-18 21:52:54 +02:00
|
|
|
#endif /* SI70XX_HAS_HUMIDITY_SENSOR || DOXYGEN */
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read the sensor serial number.
|
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor
|
|
|
|
* @return sensor serial number
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
uint64_t si70xx_get_serial(const si70xx_t *dev);
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read the sensor id, to identifier the sensor variant.
|
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor
|
|
|
|
* @return device id
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
uint8_t si70xx_get_id(const si70xx_t *dev);
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read the firmware revision of the sensor.
|
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor
|
|
|
|
* @return sensor firmware revision number
|
|
|
|
*/
|
2017-06-20 17:32:45 +02:00
|
|
|
uint8_t si70xx_get_revision(const si70xx_t *dev);
|
2016-02-09 23:07:51 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-18 13:00:05 +01:00
|
|
|
#endif /* SI70XX_H */
|
2016-02-09 23:07:51 +01:00
|
|
|
/** @} */
|