Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/sen5x: Add device driver for SEN5x #19955

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
afbb88e
Driver folder and header generated.
May 11, 2023
21c70f7
finished params-file, SAUL part still missing.
May 12, 2023
e271642
Removed unnescessary code.
May 12, 2023
f0e5884
Updated header files.
May 30, 2023
b60398b
Finished first test version.
May 30, 2023
ff8880e
Adjusted Makefiles.
May 30, 2023
ec54df7
Started SAUL implementation.
May 30, 2023
a294225
Updated comments.
Jun 2, 2023
472e92b
SAUL implementation WiP
Jun 2, 2023
ddc4dea
SAUL source code finished.
Jun 8, 2023
dc93aef
Debugging progress.
Jun 12, 2023
5ea582c
sen5x entry fixed
Jun 16, 2023
36927eb
Value scaling fixed.
Jun 16, 2023
fc6e502
Additional driver information.
Jun 16, 2023
3e2e361
reverted one fix
Jun 16, 2023
0a6a3c6
Formatted some code.
Jun 16, 2023
ec528fa
small modification to accomodate RIOT codestyle
Jun 29, 2023
03a8d38
Starting the package build
Jul 6, 2023
9897452
drivers/sen5x: Uncrustified driver files
Jul 6, 2023
a2e28d7
pkg/driver_sen5x: Uncrustified package files
Jul 6, 2023
7aa2057
pkg/driver_sen5x: Uncrustified another file
Jul 6, 2023
f633d10
drivers/sen5x: Fixed a name conflict, changed makefile to be usbale f…
Jul 17, 2023
e9f2872
drivers/saul: created auto_init file for sen5x
Jul 17, 2023
03cb4fa
drivers/sen5x: Fixed Makefile for SAUL usage
Aug 16, 2023
18a4930
tests/driver_sen5x: Added a test file for the SEN5X driver
Aug 18, 2023
22af1d0
drivers/sen5x: Adjusted the config files for the use of the driver_se…
Aug 21, 2023
8e9f0a3
drivers/sen5x: Deleted redundant files, that will be provided by the …
Aug 21, 2023
1d5040a
pkg/driver_sen5x: fixed a makefile error
Aug 21, 2023
09b035d
pkg/driver_sen5x: Package should work as intended, might be an unclea…
Sep 4, 2023
6e1f923
tests/drivers/sen5x: Moved the testfiles into the right directory.
Sep 18, 2023
c2a9198
drivers/sen5x: Fixed some things concerning SAUL, included sen5x auto…
Sep 19, 2023
5daefe7
pkg/drivers_sen5x: Removed an unnescesary line from a Makefile
Sep 19, 2023
ac6be2f
drivers/sen5x: Fixed bugs regarding the SAUL part of this driver.
Sep 21, 2023
d5565a7
Merge branch 'RIOT-OS:master' into sen5x
dprigoshij Dec 20, 2023
a62b8c2
divers/sen5x: Started adding more functionality
Apr 4, 2024
ab3e8d3
drivers/sen5x: Fixed Codestyle
Apr 8, 2024
86d0dd3
drivers/sen5x: Added missing semicolon
Apr 8, 2024
93dfaa8
drivers/sen5x: Fixed missing semicolons and declarations
Apr 8, 2024
29a4130
pkg/driver_sen5x: Removed old faulty way of structuring a pakage, inc…
Apr 8, 2024
d504dd7
pkg/driver_sen5x: Changed Configs and Makefiles to make up for the ne…
Apr 8, 2024
6b226e3
tests/drivers/sen5x: Exchanged the deprecated xtimer library for the …
Apr 19, 2024
8f28e6b
pkg/driver_sen5x: Exchanged the deprecated xtimer library for the zti…
Apr 19, 2024
38e7390
drivers/sen5x: Moved a #define into its right place.
May 21, 2024
ac78544
drivers/include: Added comments to the measurement struct, for a more…
May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ rsource "sdp3x/Kconfig"
rsource "sgp30/Kconfig"
rsource "sds011/Kconfig"
rsource "seesaw_soil/Kconfig"
rsource "sen5x/Kconfig"
rsource "sht1x/Kconfig"
rsource "sht2x/Kconfig"
rsource "sht3x/Kconfig"
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ ifneq (,$(filter sdp3x_%,$(USEMODULE)))
USEMODULE += sdp3x
endif

ifneq (,$(filter sen5%,$(USEMODULE)))
USEMODULE += sen5x
endif

ifneq (,$(filter servo_%,$(USEMODULE)))
USEMODULE += servo
endif
Expand Down
306 changes: 306 additions & 0 deletions drivers/include/sen5x.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
/*
* Copyright (C) 2023 TU Braunschweig Institut für Betriebssysteme und Rechnerverbund
*
* 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_sen5x Sensirion Embedded I2C SEN5x Driver
* @ingroup drivers_sensors
* @ingroup drivers_saul
* @brief Driver for I2C communication to SEN5x devices.
*
* @{
*
* @file
*
* @author Daniel Prigoshij <[email protected]>
*/

#ifndef SEN5X_H
#define SEN5X_H

/* Add header includes here */

#include "periph/i2c.h"
#include <stdint.h>
#include "saul.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Declare the API of the driver */

/**
* @brief Wrapper for measured values
*/
typedef struct {
uint16_t mass_concentration_pm1p0; /** raw value is scaled with factor 10: PM1.0 [µg/m³] = value / 10 */
uint16_t mass_concentration_pm2p5; /** raw value is scaled with factor 10: PM2.5 [µg/m³] = value / 10 */
uint16_t mass_concentration_pm4p0; /** raw value is scaled with factor 10: PM4.0 [µg/m³] = value / 10 */
uint16_t mass_concentration_pm10p0; /** raw value is scaled with factor 10: PM10.0 [µg/m³] = value / 10 */
uint16_t number_concentration_pm0p5; /** raw value is scaled with factor 10: PM0.5 [#/cm³] = value / 10 */
uint16_t number_concentration_pm1p0; /** raw value is scaled with factor 10: PM1.0 [#/cm³] = value / 10 */
uint16_t number_concentration_pm2p5; /** raw value is scaled with factor 10: PM2.5 [#/cm³] = value / 10 */
uint16_t number_concentration_pm4p0; /** raw value is scaled with factor 10: PM4.0 [#/cm³] = value / 10 */
uint16_t number_concentration_pm10p0; /** raw value is scaled with factor 10: PM10.0 [#/cm³] = value / 10 */
uint16_t typical_particle_size; /** raw value is scaled with factor 1000: Size [µm] = value / 1000*/
int16_t ambient_humidity; /** raw value is scaled with factor 100: RH [%] = value / 100 */
int16_t ambient_temperature; /** raw value is scaled with factor 200: T [°C] = value / 200 */
int16_t voc_index; /** raw value is scaled with factor 10: VOC Index = value / 10 */
int16_t nox_index; /** raw value is scaled with factor 10: NOx Index = value / 10 */
} sen5x_measurement_t;

/**
* @brief Device initialization parameters
*/
typedef struct {
i2c_t i2c_dev; /**< I2C device which is used */
uint8_t i2c_addr; /**< I2C address */
} sen5x_params_t;

/**
* @brief Device descriptor for the driver
*/
typedef struct {
sen5x_params_t params; /**< Device initialization parameters */
} sen5x_t;

/**
* @brief Initialize the given device
*
* @param[inout] dev Device descriptor of the driver
* @param[in] params Initialization parameters
*
* @return 0 on success
* @return < 0 on error
*/
int sen5x_init(sen5x_t *dev, const sen5x_params_t *params);

/**
* @brief Execute a reset on the given device
*
* @param[inout] dev Device descriptor of the driver
*
* @return 0 on success
* @return < 0 on error
*/
int sen5x_reset(const sen5x_t *dev);

/**
* @brief Starts a continuous measurement
*
* @param[inout] dev Device descriptor of the driver
*/
void sen5x_wake(const sen5x_t *dev);

/**
* @brief Starts a continuous measurement without PM. Only humidity, temperature, VOC and NOx are measured.
*
* @param[inout] dev Device descriptor of the driver
*/
void sen5x_wake_no_pm(const sen5x_t *dev);

/**
* @brief Stops the measurement and returns to idle mode
*
* @param[inout] dev Device descriptor of the driver
*/
void sen5x_sleep(const sen5x_t *dev);

/**
* @brief Sets the fan to maximum speed, to clean it within 10 seconds
*
* @param[inout] dev Device descriptor of the driver
*/
void sen5x_clean_fan(const sen5x_t *dev);

/**
* @brief Sets the fan to maximum speed, to clean it within 10 seconds
*
* @param[inout] dev Device descriptor of the driver
*
* @return 0 if no new measurements are available
* @return 1 if new measuremtns are ready to be read
*/
bool sen5x_data_ready_flag(const sen5x_t *dev);

/**
* @brief Read measured mass concentration, humidity and temperature values
*
* @param[inout] dev Device descriptor of the driver
* @param[out] values Pointer to wrapper containing all measured values
*/
void sen5x_read_values(const sen5x_t *dev, sen5x_measurement_t *values);

/**
* @brief Read measured particle matter values
*
* @param[inout] dev Device descriptor of the driver
* @param[out] values Pointer to wrapper containing all measured values
*/
void sen5x_read_pm_values(const sen5x_t *dev, sen5x_measurement_t *values);

/**
* @brief Set a custom temperature offset to the ambient temperature
*
* @param[inout] dev Device descriptor of the driver
* @param[in] temp_offset Temperature offset in °C
* @param[in] slope Normalized temperature offset slope
* @param[in] time_constant Time constant in seconds
*/
void sen5x_set_temperature_offset(const sen5x_t *dev, int16_t temp_offset, int16_t slope, uint16_t time_constant);

/**
* @brief Set a custom temperature offset to the ambient temperature
*
* @param[inout] dev Device descriptor of the driver
* @param[out] temp_offset Temperature offset in °C
* @param[out] slope Normalized temperature offset slope
* @param[out] time_constant Time constant in seconds
*/
void sen5x_get_temperature_offset(const sen5x_t *dev, int16_t *temp_offset, int16_t *slope, uint16_t *time_constant);

/**
* @brief Set the parameter for a warm start on the device, to improve initial accuracy of the ambient temperature output
*
* @param[inout] dev Device descriptor of the driver
* @param[in] warm_start Warm start behavior as a value in the range from
* 0 (cold start, default) to 65535 (warm start).
*/
void sen5x_set_warm_start(const sen5x_t *dev, uint16_t warm_start);

/**
* @brief Get the warm start paramater
*
* @param[inout] dev Device descriptor of the driver
* @param[out] warm_start Warm start behavior as a value in the range from
* 0 (cold start, default) to 65535 (warm start).
*/
void sen5x_get_warm_start(const sen5x_t *dev, uint16_t *warm_start);

/**
* @brief Set the parameters for the VOC Algorithm tuning
*
* @param[inout] dev Device descriptor of the driver
* @param[in] index_offset VOC index representing typical (average) conditions
* @param[in] learning_time_offset_hours Time constant to estimate the VOC algorithm offset from the
* history in hours
* @param[in] learning_time_gain_hours Time constant to estimate the VOC algorithm gain from the history
* in hours
* @param[in] gating_max_duration_minutes Maximum duration of gating in minutes
* @param[in] std_initial Initial estimate for standard deviation
* @param[in] gain_factor Gain factor to amplify or to attenuate the VOC index output
*/
void sen5x_set_voc_algorithm_tuning(
const sen5x_t *dev, int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor);

/**
* @brief Get the VOC Algortihm tuning parameters
*
* @param[inout] dev Device descriptor of the driver
* @param[out] index_offset VOC index representing typical (average) conditions
* @param[out] learning_time_offset_hours Time constant to estimate the VOC algorithm offset from the
* history in hours
* @param[out] learning_time_gain_hours Time constant to estimate the VOC algorithm gain from the history
* in hours
* @param[out] gating_max_duration_minutes Maximum duration of gating in minutes
* @param[out] std_initial Initial estimate for standard deviation
* @param[out] gain_factor Gain factor to amplify or to attenuate the VOC index output
*/
void sen5x_get_voc_algorithm_tuning(
const sen5x_t *dev, int16_t *index_offset, int16_t *learning_time_offset_hours,
int16_t *learning_time_gain_hours, int16_t *gating_max_duration_minutes,
int16_t *std_initial, int16_t *gain_factor);

/**
* @brief Set the parameters for the NOx Algorithm tuning
*
* @param[inout] dev Device descriptor of the driver
* @param[in] index_offset NOx index representing typical (average) conditions
* @param[in] learning_time_offset_hours Time constant to estimate the NOx algorithm offset from the
* history in hours
* @param[in] learning_time_gain_hours The time constant to estimate the NOx algorithm gain from the
* history has no impact for NOx. This parameter is still in place for
* consistency reasons with the VOC tuning parameters command.
* This parameter must always be set to 12 hours
* @param[in] gating_max_duration_minutes Maximum duration of gating in minutes
* @param[in] std_initial Initial estimate for standard deviation
* @param[in] gain_factor Gain factor to amplify or to attenuate the NOx index output
*/
void sen5x_set_nox_algorithm_tuning(
const sen5x_t *dev, int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor);

/**
* @brief Get the NOx Algortihm tuning parameters
*
* @param[inout] dev Device descriptor of the driver
* @param[out] index_offset NOx index representing typical (average) conditions
* @param[out] learning_time_offset_hours Time constant to estimate the NOx algorithm offset from the
* history in hours
* @param[out] learning_time_gain_hours The time constant to estimate the NOx algorithm gain from the
* history has no impact for NOx. This parameter is still in place for
* consistency reasons with the VOC tuning parameters command.
* This parameter must always be set to 12 hours
* @param[out] gating_max_duration_minutes Maximum duration of gating in minutes
* @param[out] std_initial Initial estimate for standard deviation
* @param[out] gain_factor Gain factor to amplify or to attenuate the NOx index output
*/
void sen5x_get_nox_algorithm_tuning(
const sen5x_t *dev, int16_t *index_offset, int16_t *learning_time_offset_hours,
int16_t *learning_time_gain_hours, int16_t *gating_max_duration_minutes,
int16_t *std_initial, int16_t *gain_factor);

/**
* @brief Set the mode for the RH/T acceleration algorithm
*
* @param[inout] dev Device descriptor of the driver
* @param[in] mode RH/T accelaration mode:
* = 0: Low Acceleration
* = 1: High Acceleration
* = 2: Medium Acceleration
*/
void sen5x_set_rht_acceleration(const sen5x_t *dev, uint16_t mode);

/**
* @brief Get the mode for the RH/T acceleration algorithm
*
* @param[inout] dev Device descriptor of the driver
* @param[out] mode RH/T accelaration mode:
* = 0: Low Acceleration
* = 1: High Acceleration
* = 2: Medium Acceleration
*/
void sen5x_get_rht_acceleration(const sen5x_t *dev, uint16_t *mode);

/**
* @brief Get the VOC Algorithm state
*
* @param[inout] dev Device descriptor of the driver
* @param[in] state VOC Algorithm state
* @param[in] state_size Size of the VOC Algorithm state
*/
void sen5x_set_voc_state(const sen5x_t *dev, const uint8_t *state, uint8_t state_size);

/**
* @brief Set the VOC Algorithm state
*
* @param[inout] dev Device descriptor of the driver
* @param[out] state VOC Algorithm state
* @param[in] state_size Size of the VOC Algorithm state
*/
void sen5x_get_voc_state(const sen5x_t *dev, uint8_t *state, uint8_t state_size);

#ifdef __cplusplus
}
#endif

#endif /* SEN5X_H */
/** @} */
Loading
Loading