Loading...
Searching...
No Matches
sm_pwm_01c.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Inria
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
38#ifndef SM_PWM_01C_H
39#define SM_PWM_01C_H
40
41#include <inttypes.h>
42
43#include "timex.h"
44#include "ztimer.h"
45#include "periph/gpio.h"
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
63#ifndef CONFIG_SM_PWM_01C_SAMPLE_TIME
64#define CONFIG_SM_PWM_01C_SAMPLE_TIME (100 * US_PER_MS)
65#endif
66
72#ifndef CONFIG_SM_PWM_01C_WINDOW_TIME
73#define CONFIG_SM_PWM_01C_WINDOW_TIME (10 * US_PER_SEC)
74#endif
75
76#if defined(MODULE_SM_PWM_01C_MA) || defined(DOXYGEN)
82#define SM_PWM_01C_BUFFER_LEN (CONFIG_SM_PWM_01C_WINDOW_TIME / \
83 CONFIG_SM_PWM_01C_SAMPLE_TIME)
84#else
85
95#ifndef CONFIG_SM_PWM_01C_EXP_WEIGHT
96#define CONFIG_SM_PWM_01C_EXP_WEIGHT (5)
97#endif
98#endif
99
102#if defined(MODULE_SM_PWM_01C_MA) || defined(DOXYGEN)
108typedef struct {
109 uint16_t buf[SM_PWM_01C_BUFFER_LEN];
110 size_t head;
111} circ_buf_t;
112#endif
113
119typedef struct {
120 gpio_t tsp_pin;
122 gpio_t tlp_pin;
125
133typedef struct {
134 uint16_t mc_pm_2p5;
135 uint16_t mc_pm_10;
137
142typedef struct {
143 uint32_t tsp_lpo;
144 uint32_t tlp_lpo;
145 uint32_t tlp_start_time;
146 uint32_t tsp_start_time;
147#ifdef MODULE_SM_PWM_01C_MA
148 circ_buf_t tsp_circ_buf;
149 circ_buf_t tlp_circ_buf;
150#else
153#endif
155
165
176
184
192
201
202#ifdef __cplusplus
203}
204#endif
205
206#endif /* SM_PWM_01C_H */
Low-level GPIO peripheral driver interface definitions.
#define SM_PWM_01C_BUFFER_LEN
Length in time of the measuring window.
Definition sm_pwm_01c.h:82
void sm_pwm_01c_read_data(sm_pwm_01c_t *dev, sm_pwm_01c_data_t *data)
Reads particle concentration values.
void sm_pwm_01c_start(sm_pwm_01c_t *dev)
Start continuous measurement of Large and Small particle concentrations.
int sm_pwm_01c_init(sm_pwm_01c_t *dev, const sm_pwm_01c_params_t *params)
Initialize the given SM_PWM_01C device.
void sm_pwm_01c_stop(sm_pwm_01c_t *dev)
Stops continuous measurement of Large and Small particle concentration.
Adds include for missing inttype definitions.
Circular buffer holding moving average values.
Definition sm_pwm_01c.h:108
size_t head
current buffer head
Definition sm_pwm_01c.h:110
LPO and concentration (ug/m3) values for small and large particles.
Definition sm_pwm_01c.h:133
uint16_t mc_pm_10
Large particle concentration ug/m3.
Definition sm_pwm_01c.h:135
uint16_t mc_pm_2p5
Small particle concentration ug/m3.
Definition sm_pwm_01c.h:134
Parameters for the SM_PWM_01c sensor.
Definition sm_pwm_01c.h:119
gpio_t tlp_pin
Low Pulse Signal Output (P2) of large Particle, active low, PM10 equivalent.
Definition sm_pwm_01c.h:122
gpio_t tsp_pin
Low Pulse Signal Output (P1) of small Particle, active low, PM2.5 equivalent.
Definition sm_pwm_01c.h:120
Device descriptor for the SM_PWM_01c sensor.
Definition sm_pwm_01c.h:159
sm_pwm_01c_values_t _values
Internal data to calculate concentration from tsl/tsp low Pulse Output Occupancy.
Definition sm_pwm_01c.h:161
sm_pwm_01c_params_t params
Device driver parameters.
Definition sm_pwm_01c.h:160
ztimer_t _sampler
internal sampling timer
Definition sm_pwm_01c.h:163
LPO and concentration (ug/m3) values for small and large particles.
Definition sm_pwm_01c.h:142
uint32_t tsp_lpo
Small particle low Pulse active time us.
Definition sm_pwm_01c.h:143
uint32_t tlp_start_time
Last time tlp pin went low.
Definition sm_pwm_01c.h:145
sm_pwm_01c_data_t data
Current value for the exponentially averaged particle concentration values.
Definition sm_pwm_01c.h:151
uint32_t tsp_start_time
Last time tsp pin went low.
Definition sm_pwm_01c.h:146
uint32_t tlp_lpo
Large Particle low Pulse active time us.
Definition sm_pwm_01c.h:144
ztimer structure
Definition ztimer.h:318
Utility library for comparing and computing timestamps.
ztimer API