mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 18:13:49 +01:00
drivers/sen5x: SAUL functionality imlemented
This commit is contained in:
parent
fadeafdf85
commit
3aa960ea01
@ -1,11 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) 2023 TUÚ Braunschweig Institut für Betriebssysteme und Rechnerverbund
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef SEN5X_H
|
||||
#define SEN5X_H
|
||||
|
||||
/**
|
||||
* @defgroup drivers_sen5x Sensirion Embedded I2C SEN5x Driver
|
||||
* @ingroup drivers_sensors
|
||||
@ -16,7 +19,7 @@
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* @author Daniel Prigoshij <d.prigoshij@tu-braunschweig.de>
|
||||
* @author Daniel Prigoshij <prigoshi@ibr.cs.tu-bs.de>
|
||||
*/
|
||||
|
||||
#ifndef SEN5X_H
|
||||
@ -38,20 +41,34 @@ extern "C" {
|
||||
* @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 */
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -74,15 +91,21 @@ typedef struct {
|
||||
*
|
||||
* @param[inout] dev Device descriptor of the driver
|
||||
* @param[in] params Initialization parameters
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return < 0 on error
|
||||
*/
|
||||
void sen5x_init(sen5x_t *dev, const sen5x_params_t *params);
|
||||
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
|
||||
*/
|
||||
void sen5x_reset(const sen5x_t *dev);
|
||||
int sen5x_reset(const sen5x_t *dev);
|
||||
|
||||
/**
|
||||
* @brief Starts a continuous measurement
|
||||
@ -92,7 +115,8 @@ void sen5x_reset(const sen5x_t *dev);
|
||||
void sen5x_wake(const sen5x_t *dev);
|
||||
|
||||
/**
|
||||
* @brief Starts a continuous measurement without PM. Only humidity, temperature, VOC and NOx are measured.
|
||||
* @brief Starts a continuous measurement without PM. Only humidity,
|
||||
* temperature, VOC and NOx are measured.
|
||||
*
|
||||
* @param[inout] dev Device descriptor of the driver
|
||||
*/
|
||||
@ -146,7 +170,8 @@ void sen5x_read_pm_values(const sen5x_t *dev, sen5x_measurement_t *values);
|
||||
* @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);
|
||||
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
|
||||
@ -159,7 +184,8 @@ void sen5x_set_temperature_offset(const sen5x_t *dev, int16_t temp_offset, int16
|
||||
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
|
||||
* @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
|
||||
@ -168,7 +194,7 @@ void sen5x_get_temperature_offset(const sen5x_t *dev, int16_t *temp_offset, int1
|
||||
void sen5x_set_warm_start(const sen5x_t *dev, uint16_t warm_start);
|
||||
|
||||
/**
|
||||
* @brief Get the warm start paramater
|
||||
* @brief Get the warm start parameter
|
||||
*
|
||||
* @param[inout] dev Device descriptor of the driver
|
||||
* @param[out] warm_start Warm start behavior as a value in the range from
|
||||
@ -181,13 +207,14 @@ void sen5x_get_warm_start(const sen5x_t *dev, uint16_t *warm_start);
|
||||
*
|
||||
* @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] 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
|
||||
* @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,
|
||||
@ -195,17 +222,19 @@ void sen5x_set_voc_algorithm_tuning(
|
||||
int16_t std_initial, int16_t gain_factor);
|
||||
|
||||
/**
|
||||
* @brief Get the VOC Algortihm tuning parameters
|
||||
* @brief Get the VOC Algorithm 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] 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
|
||||
* @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,
|
||||
@ -217,15 +246,18 @@ void sen5x_get_voc_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.
|
||||
* @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
|
||||
* @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,
|
||||
@ -233,19 +265,22 @@ void sen5x_set_nox_algorithm_tuning(
|
||||
int16_t std_initial, int16_t gain_factor);
|
||||
|
||||
/**
|
||||
* @brief Get the NOx Algortihm tuning parameters
|
||||
* @brief Get the NOx Algorithm 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.
|
||||
* @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
|
||||
* @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,
|
||||
@ -256,7 +291,7 @@ void sen5x_get_nox_algorithm_tuning(
|
||||
* @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:
|
||||
* @param[in] mode RH/T acceleration mode:
|
||||
* = 0: Low Acceleration
|
||||
* = 1: High Acceleration
|
||||
* = 2: Medium Acceleration
|
||||
@ -267,7 +302,7 @@ 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:
|
||||
* @param[out] mode RH/T acceleration mode:
|
||||
* = 0: Low Acceleration
|
||||
* = 1: High Acceleration
|
||||
* = 2: Medium Acceleration
|
||||
|
||||
@ -283,6 +283,10 @@ void saul_init_devs(void)
|
||||
extern void auto_init_seesaw_soil(void);
|
||||
auto_init_seesaw_soil();
|
||||
}
|
||||
if (IS_USED(MODULE_SEN5X)) {
|
||||
extern void auto_init_sen5x(void);
|
||||
auto_init_sen5x();
|
||||
}
|
||||
if (IS_USED(MODULE_SGP30)) {
|
||||
extern void auto_init_sgp30(void);
|
||||
auto_init_sgp30();
|
||||
|
||||
@ -1 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
include $(RIOTMAKE)/driver_with_saul.mk
|
||||
|
||||
@ -6,6 +6,9 @@
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef SEN5X_CONSTANTS_H
|
||||
#define SEN5X_CONSTANTS_H
|
||||
|
||||
/**
|
||||
* @ingroup drivers_sen5x
|
||||
* @{
|
||||
@ -13,7 +16,7 @@
|
||||
* @file
|
||||
* @brief Internal addresses, registers and constants
|
||||
*
|
||||
* @author Daniel Prigoshij <d.prigoshij@tu-braunschweig.de>
|
||||
* @author Daniel Prigoshij <prigoshi@ibr.cs.tu-bs.de>
|
||||
*/
|
||||
|
||||
#ifndef SEN5X_CONSTANTS_H
|
||||
@ -25,8 +28,8 @@ extern "C" {
|
||||
|
||||
/* define here the addresses, register and constants of the driver */
|
||||
|
||||
#ifndef SEN5X_I2C_ADDRESS
|
||||
#define SEN5X_I2C_ADDRESS (0x69)
|
||||
#ifndef SEN5X_ADRESS_I2C
|
||||
#define SEN5X_ADRESS_I2C (0x69)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -6,14 +6,17 @@
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef SEN5X_PARAMS_H
|
||||
#define SEN5X_PARAMS_H
|
||||
|
||||
/**
|
||||
* @ingroup drivers_sen5x
|
||||
*
|
||||
* @{
|
||||
* @file
|
||||
* @brief Default configuration
|
||||
* @brief Default configuration for SEN50/54/55
|
||||
*
|
||||
* @author Daniel Prigoshij <d.prigoshij@tu-braunschweig.de>
|
||||
* @author Daniel Prigoshij <prigoshi@ibr.cs.tu-bs.de>
|
||||
*/
|
||||
|
||||
#ifndef SEN5X_PARAMS_H
|
||||
@ -21,6 +24,7 @@
|
||||
|
||||
#include "board.h"
|
||||
#include "sen5x.h"
|
||||
#include "saul_reg.h"
|
||||
#include "sen5x_constants.h"
|
||||
#include "periph/i2c.h"
|
||||
|
||||
@ -36,14 +40,16 @@ extern "C" {
|
||||
#define SEN5X_PARAM_I2C_DEV I2C_DEV(0)
|
||||
#endif
|
||||
#ifndef SEN5X_PARAM_ADDR
|
||||
#define SEN5X_PARAM_ADDR SEN5X_I2C_ADDRESS
|
||||
#define SEN5X_PARAM_ADDR SEN5X_ADRESS_I2C
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SEN5X_PARAMS
|
||||
#define SEN5X_PARAMS { .i2c_dev = SEN5X_PARAM_I2C_DEV, \
|
||||
.i2c_addr = SEN5X_PARAM_ADDR }
|
||||
#endif
|
||||
#ifndef SEN5X_SAUL_INFO
|
||||
#define SEN5X_SAUL_INFO { .name = "sen5x" }
|
||||
#endif
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
|
||||
#include "sensirion_config.h"
|
||||
#include "sen5x_params.h"
|
||||
#include "sen5x_constants.h"
|
||||
#include "xtimer.h"
|
||||
#include "periph/i2c.h"
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
* @file
|
||||
* @brief Device driver implementation for the Sensirion Embedded I2C SEN5x Driver
|
||||
*
|
||||
* @author Daniel Prigoshij <d.prigoshij@tu-braunschweig.de>
|
||||
* @author Daniel Prigoshij <prigoshi@ibr.cs.tu-bs.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -24,7 +24,7 @@
|
||||
#include "sensirion_i2c_hal.h"
|
||||
#include "sen5x_i2c.h"
|
||||
|
||||
void sen5x_init(sen5x_t *dev, const sen5x_params_t *params)
|
||||
int sen5x_init(sen5x_t *dev, const sen5x_params_t *params)
|
||||
{
|
||||
/* check parameters */
|
||||
assert(dev && params);
|
||||
@ -32,17 +32,18 @@ void sen5x_init(sen5x_t *dev, const sen5x_params_t *params)
|
||||
dev->params = *params;
|
||||
|
||||
i2c_init(dev->params.i2c_dev);
|
||||
sen5x_reset(dev);
|
||||
return sen5x_reset(dev);
|
||||
}
|
||||
|
||||
void sen5x_reset(const sen5x_t *dev)
|
||||
int sen5x_reset(const sen5x_t *dev)
|
||||
{
|
||||
assert(dev);
|
||||
i2c_acquire(dev->params.i2c_dev);
|
||||
|
||||
sen5x_device_reset();
|
||||
int result = sen5x_device_reset();
|
||||
|
||||
i2c_release(dev->params.i2c_dev);
|
||||
return result;
|
||||
}
|
||||
|
||||
void sen5x_wake(const sen5x_t *dev)
|
||||
@ -87,7 +88,7 @@ bool sen5x_data_ready_flag(const sen5x_t *dev)
|
||||
return status;
|
||||
}
|
||||
|
||||
void sen5x_read_values(sen5x_t *dev ,sen5x_measurement_t *values)
|
||||
void sen5x_read_values(const sen5x_t *dev ,sen5x_measurement_t *values)
|
||||
{
|
||||
assert(dev && values);
|
||||
i2c_acquire(dev->params.i2c_dev);
|
||||
|
||||
@ -23,116 +23,126 @@
|
||||
|
||||
static int read_mass_concentration_pm1p0(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.mass_concentration_pm1p0;
|
||||
res->val[0] = (int16_t)values.mass_concentration_pm1p0;
|
||||
res->unit = UNIT_GPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_mass_concentration_pm2p5(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.mass_concentration_pm2p5;
|
||||
res->val[0] = (int16_t)values.mass_concentration_pm2p5;
|
||||
res->unit = UNIT_GPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_mass_concentration_pm4p0(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.mass_concentration_pm4p0;
|
||||
res->val[0] = (int16_t)values.mass_concentration_pm4p0;
|
||||
res->unit = UNIT_GPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_mass_concentration_pm10p0(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.mass_concentration_pm10p0;
|
||||
res->val[0] = (int16_t)values.mass_concentration_pm10p0;
|
||||
res->unit = UNIT_GPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_number_concentration_pm0p5(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.number_concentration_pm0p5;
|
||||
res->val[0] = (int16_t)values.number_concentration_pm0p5;
|
||||
res->unit = UNIT_CPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_number_concentration_pm1p0(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.number_concentration_pm1p0;
|
||||
res->val[0] = (int16_t)values.number_concentration_pm1p0;
|
||||
res->unit = UNIT_CPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_number_concentration_pm2p5(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.number_concentration_pm2p5;
|
||||
res->val[0] = (int16_t)values.number_concentration_pm2p5;
|
||||
res->unit = UNIT_CPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_number_concentration_pm4p0(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.number_concentration_pm4p0;
|
||||
res->val[0] = (int16_t)values.number_concentration_pm4p0;
|
||||
res->unit = UNIT_CPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_number_concentration_pm10p0(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.number_concentration_pm10p0;
|
||||
res->val[0] = (int16_t)values.number_concentration_pm10p0;
|
||||
res->unit = UNIT_CPM3;
|
||||
res->scale = -5;
|
||||
res->scale = -7;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_typical_particle_size(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_pm_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.typical_particle_size;
|
||||
res->val[0] = (int16_t)values.typical_particle_size;
|
||||
res->unit = UNIT_M;
|
||||
res->scale = -3;
|
||||
|
||||
@ -141,24 +151,26 @@ static int read_typical_particle_size(const void *dev, phydat_t *res) {
|
||||
|
||||
static int read_ambient_humidity(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_values(d, &values);
|
||||
|
||||
res->val[0] = (int16_t)d->values.ambient_humidity;
|
||||
res->val[0] = (int16_t)values.ambient_humidity;
|
||||
res->unit = UNIT_PERCENT;
|
||||
res->scale = 2;
|
||||
res->scale = -2;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_ambient_temperature(const void *dev, phydat_t *res) {
|
||||
sen5x_t *d = (sen5x_t *)dev;
|
||||
sen5x_measurement_t values;
|
||||
|
||||
sen5x_read_pm_values(d, &d->values);
|
||||
sen5x_read_values(d, &values);
|
||||
|
||||
res->val[0] = ((int16_t)d->values.ambient_temperature) / 2;
|
||||
res->val[0] = ((int16_t)values.ambient_temperature) / 2;
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = 2;
|
||||
res->scale = -2;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -40,17 +40,17 @@
|
||||
void sensirion_i2c_hal_init(void) {
|
||||
|
||||
// initialize the bus
|
||||
i2c_init(I2C_DEVICE);
|
||||
i2c_init(SEN5X_PARAM_I2C_DEV);
|
||||
|
||||
// first, acquire the shared bus again
|
||||
i2c_acquire(I2C_DEVICE);
|
||||
i2c_acquire(SEN5X_PARAM_I2C_DEV);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release all resources initialized by sensirion_i2c_hal_init().
|
||||
*/
|
||||
void sensirion_i2c_hal_free(void) {
|
||||
i2c_release(I2C_DEVICE);
|
||||
i2c_release(SEN5X_PARAM_I2C_DEV);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +64,7 @@ void sensirion_i2c_hal_free(void) {
|
||||
* @returns 0 on success, error code otherwise
|
||||
*/
|
||||
int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count) {
|
||||
return i2c_read_bytes(I2C_DEVICE, address, data, count, 0);
|
||||
return i2c_read_bytes(SEN5X_PARAM_I2C_DEV, address, data, count, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +79,7 @@ int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count) {
|
||||
* @returns 0 on success, error code otherwise
|
||||
*/
|
||||
int8_t sensirion_i2c_hal_write(uint8_t address, const uint8_t* data, uint16_t count) {
|
||||
return i2c_write_bytes(I2C_DEVICE, address, data, count, 0);
|
||||
return i2c_write_bytes(SEN5X_PARAM_I2C_DEV, address, data, count, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
4
pkg/driver_sen5x/driver_sen5x.mk
Normal file
4
pkg/driver_sen5x/driver_sen5x.mk
Normal file
@ -0,0 +1,4 @@
|
||||
MODULE = driver_sen5x
|
||||
|
||||
# $(shell rm sensirion_i2c_hal.c sensirion_i2c_hal.h sen5x_i2c_example_usage.c)
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
9
tests/drivers/sen5x/Makefile
Normal file
9
tests/drivers/sen5x/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
include ../Makefile.drivers_common
|
||||
|
||||
DRIVER ?= sen5x
|
||||
|
||||
USEMODULE += $(DRIVER)
|
||||
USEMODULE += printf_float
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
Loading…
x
Reference in New Issue
Block a user