Loading...
Searching...
No Matches
sm_pwm_01c.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 Inria
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
36
37#include <inttypes.h>
38
39#include "timex.h"
40#include "ztimer.h"
41#include "periph/gpio.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
53
59#ifndef CONFIG_SM_PWM_01C_SAMPLE_TIME
60#define CONFIG_SM_PWM_01C_SAMPLE_TIME (100 * US_PER_MS)
61#endif
62
68#ifndef CONFIG_SM_PWM_01C_WINDOW_TIME
69#define CONFIG_SM_PWM_01C_WINDOW_TIME (10 * US_PER_SEC)
70#endif
71
72#if defined(MODULE_SM_PWM_01C_MA) || defined(DOXYGEN)
78#define SM_PWM_01C_BUFFER_LEN (CONFIG_SM_PWM_01C_WINDOW_TIME / \
79 CONFIG_SM_PWM_01C_SAMPLE_TIME)
80#else
81
91#ifndef CONFIG_SM_PWM_01C_EXP_WEIGHT
92#define CONFIG_SM_PWM_01C_EXP_WEIGHT (5)
93#endif
94#endif
95
97
98#if defined(MODULE_SM_PWM_01C_MA) || defined(DOXYGEN)
104typedef struct {
106 size_t head;
107} circ_buf_t;
108#endif
109
115typedef struct {
116 gpio_t tsp_pin;
118 gpio_t tlp_pin;
121
129typedef struct {
130 uint16_t mc_pm_2p5;
131 uint16_t mc_pm_10;
133
138typedef struct {
139 uint32_t tsp_lpo;
140 uint32_t tlp_lpo;
141 uint32_t tlp_start_time;
142 uint32_t tsp_start_time;
143#ifdef MODULE_SM_PWM_01C_MA
144 circ_buf_t tsp_circ_buf;
145 circ_buf_t tlp_circ_buf;
146#else
149#endif
151
161
172
180
188
197
198#ifdef __cplusplus
199}
200#endif
201
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:78
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:104
uint16_t buf[SM_PWM_01C_BUFFER_LEN]
circular buffer memory
Definition sm_pwm_01c.h:105
size_t head
current buffer head
Definition sm_pwm_01c.h:106
LPO and concentration (ug/m3) values for small and large particles.
Definition sm_pwm_01c.h:129
uint16_t mc_pm_10
Large particle concentration ug/m3.
Definition sm_pwm_01c.h:131
uint16_t mc_pm_2p5
Small particle concentration ug/m3.
Definition sm_pwm_01c.h:130
Parameters for the SM_PWM_01c sensor.
Definition sm_pwm_01c.h:115
gpio_t tlp_pin
Low Pulse Signal Output (P2) of large Particle, active low, PM10 equivalent.
Definition sm_pwm_01c.h:118
gpio_t tsp_pin
Low Pulse Signal Output (P1) of small Particle, active low, PM2.5 equivalent.
Definition sm_pwm_01c.h:116
Device descriptor for the SM_PWM_01c sensor.
Definition sm_pwm_01c.h:155
sm_pwm_01c_values_t _values
Internal data to calculate concentration from tsl/tsp low Pulse Output Occupancy.
Definition sm_pwm_01c.h:157
sm_pwm_01c_params_t params
Device driver parameters.
Definition sm_pwm_01c.h:156
ztimer_t _sampler
internal sampling timer
Definition sm_pwm_01c.h:159
LPO and concentration (ug/m3) values for small and large particles.
Definition sm_pwm_01c.h:138
uint32_t tsp_lpo
Small particle low Pulse active time us.
Definition sm_pwm_01c.h:139
uint32_t tlp_start_time
Last time tlp pin went low.
Definition sm_pwm_01c.h:141
sm_pwm_01c_data_t data
Current value for the exponentially averaged particle concentration values.
Definition sm_pwm_01c.h:147
uint32_t tsp_start_time
Last time tsp pin went low.
Definition sm_pwm_01c.h:142
uint32_t tlp_lpo
Large Particle low Pulse active time us.
Definition sm_pwm_01c.h:140
ztimer structure
Definition ztimer.h:319
Utility library for comparing and computing timestamps.
ztimer API