Files
espidf_i2c/sgp40/include/sgp40.h
Julien Lazarewicz e940c767a6 Add bh1750, aht20, sgp40 drivers unified on native i2c_master API
Forked from managed_components (espressif/bh1750, espressif/aht20,
esp-idf-lib/sgp40) and rewrote aht20/sgp40 internals to use
driver/i2c_master.h directly instead of the i2c_bus and i2cdev
wrapper components, so all three sensors share one create/delete
handle pattern over a single i2c_master_bus_handle_t.
2026-07-05 23:27:50 +02:00

107 lines
2.9 KiB
C

/**
* @file sgp40.h
* @defgroup sgp40 sgp40
* @{
*
* ESP-IDF driver for SGP40 Indoor Air Quality Sensor for VOC Measurements
*
* Copyright (c) 2020 Ruslan V. Uss <unclerus@gmail.com>
*
* BSD Licensed as described in the file LICENSE
*/
#ifndef __SGP40_H__
#define __SGP40_H__
#include <stdbool.h>
#include <esp_err.h>
#include "driver/i2c_master.h"
#include "sensirion_voc_algorithm.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SGP40_ADDR 0x59 //!< I2C address
/**
* @brief Type of SGP40 device handle
*/
typedef void *sgp40_handle_t;
/**
* @brief Create and init sensor object, read device information, initialize the VOC algorithm
*
* @param[in] bus_handle I2C bus handle. Obtained from i2c_new_master_bus().
* @param[in] dev_addr I2C address of sensor. Use SGP40_ADDR for default address.
* @param[out] handle_ret Handle to created SGP40 driver object.
* @return `ESP_OK` on success
*/
esp_err_t sgp40_create(i2c_master_bus_handle_t bus_handle, const uint8_t dev_addr, sgp40_handle_t *handle_ret);
/**
* @brief Delete and release a sensor object
*
* @param sensor object handle of sgp40
* @return `ESP_OK` on success
*/
esp_err_t sgp40_delete(sgp40_handle_t sensor);
/**
* @brief Reset device, than put it to idle mode
*
* @param sensor object handle of sgp40
* @return `ESP_OK` on success
*/
esp_err_t sgp40_soft_reset(sgp40_handle_t sensor);
/**
* @brief Perform a self-test
*
* @param sensor object handle of sgp40
* @return `ESP_OK` on success
*/
esp_err_t sgp40_self_test(sgp40_handle_t sensor);
/**
* @brief Turn hotplate off, stop measurement and put device to idle mode
*
* @param sensor object handle of sgp40
* @return `ESP_OK` on success
*/
esp_err_t sgp40_heater_off(sgp40_handle_t sensor);
/**
* @brief Perform a measurement
*
* @param sensor object handle of sgp40
* @param humidity Relative humidity, percents. Use NaN if
* you want uncompensated measurement
* @param temperature Temperature, degrees Celsius. Use NaN if
* you want uncompensated measurement
* @param[out] raw Raw value, proportional to the logarithm
* of the resistance of the sensing element
* @return `ESP_OK` on success
*/
esp_err_t sgp40_measure_raw(sgp40_handle_t sensor, float humidity, float temperature, uint16_t *raw);
/**
* @brief Perform a measurement and update VOC index
*
* @param sensor object handle of sgp40
* @param humidity Relative humidity, percents. Use NaN if
* you want uncompensated measurement
* @param temperature Temperature, degrees Celsius. Use NaN if
* you want uncompensated measurement
* @param[out] voc_index Calculated VOC index
* @return `ESP_OK` on success
*/
esp_err_t sgp40_measure_voc(sgp40_handle_t sensor, float humidity, float temperature, int32_t *voc_index);
#ifdef __cplusplus
}
#endif
/**@}*/
#endif /* __SGP40_H__ */