sps30.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
61 #ifndef SPS30_H
62 #define SPS30_H
63 
64 #include <stdbool.h>
65 #include "periph/gpio.h"
66 #include "periph/i2c.h"
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
75 typedef struct {
78 
82 typedef struct {
84 } sps30_t;
85 
93 typedef struct {
94  float mc_pm1;
95  float mc_pm2_5;
96  float mc_pm4;
97  float mc_pm10;
98  float nc_pm0_5;
99  float nc_pm1;
100  float nc_pm2_5;
101  float nc_pm4;
102  float nc_pm10;
103  float ps;
104 } sps30_data_t;
105 
109 typedef enum {
110  SPS30_OK = 0,
114 
118 #define SPS30_FAN_CLEAN_S (10U)
119 
123 #define SPS30_SER_ART_LEN (32U)
124 
128 #define SPS30_DEFAULT_ACI_S (604800UL)
129 
147 #ifndef CONFIG_SPS30_ERROR_RETRY
148 #define CONFIG_SPS30_ERROR_RETRY (500U)
149 #endif
150 
161 int sps30_init(sps30_t *dev, const sps30_params_t *params);
162 
178 int sps30_start_measurement(const sps30_t *dev);
179 
189 int sps30_stop_measurement(const sps30_t *dev);
190 
201 bool sps30_data_ready(const sps30_t *dev, int *error);
202 
211 int sps30_read_measurement(const sps30_t *dev, sps30_data_t *data);
212 
225 int sps30_read_ac_interval(const sps30_t *dev, uint32_t *seconds);
226 
244 int sps30_write_ac_interval(const sps30_t *dev, uint32_t seconds);
245 
257 int sps30_start_fan_clean(const sps30_t *dev);
258 
268 int sps30_read_article_code(const sps30_t *dev, char *str, size_t len);
269 
279 int sps30_read_serial_number(const sps30_t *dev, char *str, size_t len);
280 
288 int sps30_reset(const sps30_t *dev);
289 
297 int sps30_sleep(const sps30_t *dev);
298 
306 int sps30_wakeup(const sps30_t *dev);
307 
308 #ifdef __cplusplus
309 }
310 #endif
311 #endif /* SPS30_H */
312 
sps30_read_ac_interval
int sps30_read_ac_interval(const sps30_t *dev, uint32_t *seconds)
Read the fan auto-clean interval.
sps30_reset
int sps30_reset(const sps30_t *dev)
Reset the sensor.
sps30_stop_measurement
int sps30_stop_measurement(const sps30_t *dev)
Stops the measurement action.
sps30_data_t::mc_pm2_5
float mc_pm2_5
Mass concentration of all particles <= 2.5µm [µg/m^3].
Definition: sps30.h:95
sps30_read_measurement
int sps30_read_measurement(const sps30_t *dev, sps30_data_t *data)
Read a set of particulate matter measurements.
sps30_params_t
SPS30 device parameters.
Definition: sps30.h:75
sps30_data_ready
bool sps30_data_ready(const sps30_t *dev, int *error)
Ask the device if a measurement is ready for reading.
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
sps30_data_t::nc_pm1
float nc_pm1
Number concentration of all particles <= 1µm [#/cm^3].
Definition: sps30.h:99
SPS30_CRC_ERROR
@ SPS30_CRC_ERROR
The CRC check of received data failed.
Definition: sps30.h:111
sps30_data_t::mc_pm4
float mc_pm4
Mass concentration of all particles <= 4µm [µg/m^3].
Definition: sps30.h:96
sps30_t
SPS30 device instance.
Definition: sps30.h:82
sps30_init
int sps30_init(sps30_t *dev, const sps30_params_t *params)
Initialize SPS30 sensor driver.
sps30_data_t::mc_pm1
float mc_pm1
Mass concentration of all particles <= 1µm [µg/m^3].
Definition: sps30.h:94
sps30_params_t::i2c_dev
i2c_t i2c_dev
I2C dev the sensor is connected to.
Definition: sps30.h:76
sps30_error_code_t
sps30_error_code_t
SPS30 error codes (returned as negative values)
Definition: sps30.h:109
SPS30_OK
@ SPS30_OK
Everything went fine.
Definition: sps30.h:110
sps30_data_t::nc_pm10
float nc_pm10
Number concentration of all particles <= 10µm [#/cm^3].
Definition: sps30.h:102
sps30_start_fan_clean
int sps30_start_fan_clean(const sps30_t *dev)
Run a fan cleaning cycle manually.
sps30_data_t::nc_pm4
float nc_pm4
Number concentration of all particles <= 4µm [#/cm^3].
Definition: sps30.h:101
sps30_t::p
sps30_params_t p
parameters of the sensor device
Definition: sps30.h:83
sps30_wakeup
int sps30_wakeup(const sps30_t *dev)
Wake up sensor from sleep mode (returns sensor to Idle mode)
sps30_start_measurement
int sps30_start_measurement(const sps30_t *dev)
Enable the measurement action.
sps30_read_article_code
int sps30_read_article_code(const sps30_t *dev, char *str, size_t len)
Read the article code from the sensor as string.
sps30_sleep
int sps30_sleep(const sps30_t *dev)
Put the sensor in sleep mode.
sps30_read_serial_number
int sps30_read_serial_number(const sps30_t *dev, char *str, size_t len)
Read the serial number from the sensor as string.
gpio.h
Low-level GPIO peripheral driver interface definitions.
sps30_data_t::mc_pm10
float mc_pm10
Mass concentration of all particles <= 10µm [µg/m^3].
Definition: sps30.h:97
sps30_data_t::ps
float ps
Typical particle size [µm].
Definition: sps30.h:103
sps30_data_t
Set of measured particulate matter values.
Definition: sps30.h:93
sps30_data_t::nc_pm0_5
float nc_pm0_5
Number concentration of all particles <= 0.5µm [#/cm^3].
Definition: sps30.h:98
sps30_data_t::nc_pm2_5
float nc_pm2_5
Number concentration of all particles <= 2.5µm [#/cm^3].
Definition: sps30.h:100
sps30_write_ac_interval
int sps30_write_ac_interval(const sps30_t *dev, uint32_t seconds)
Write the fan auto-clean interval.
SPS30_I2C_ERROR
@ SPS30_I2C_ERROR
Some I2C operation failed.
Definition: sps30.h:112
i2c.h
Low-level I2C peripheral driver interface definition.