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
9#pragma once
10
39
40#include <inttypes.h>
41
42#include "timex.h"
43#include "ztimer.h"
44#include "periph/gpio.h"
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
56
62#ifndef CONFIG_SM_PWM_01C_SAMPLE_TIME
63#define CONFIG_SM_PWM_01C_SAMPLE_TIME (100 * US_PER_MS)
64#endif
65
71#ifndef CONFIG_SM_PWM_01C_WINDOW_TIME
72#define CONFIG_SM_PWM_01C_WINDOW_TIME (10 * US_PER_SEC)
73#endif
74
75#if defined(MODULE_SM_PWM_01C_MA) || defined(DOXYGEN)
81#define SM_PWM_01C_BUFFER_LEN (CONFIG_SM_PWM_01C_WINDOW_TIME / \
82 CONFIG_SM_PWM_01C_SAMPLE_TIME)
83#else
84
94#ifndef CONFIG_SM_PWM_01C_EXP_WEIGHT
95#define CONFIG_SM_PWM_01C_EXP_WEIGHT (5)
96#endif
97#endif
98
100
101#if defined(MODULE_SM_PWM_01C_MA) || defined(DOXYGEN)
107typedef struct {
109 size_t head;
110} circ_buf_t;
111#endif
112
118typedef struct {
119 gpio_t tsp_pin;
121 gpio_t tlp_pin;
124
132typedef struct {
133 uint16_t mc_pm_2p5;
134 uint16_t mc_pm_10;
136
141typedef struct {
142 uint32_t tsp_lpo;
143 uint32_t tlp_lpo;
144 uint32_t tlp_start_time;
145 uint32_t tsp_start_time;
146#ifdef MODULE_SM_PWM_01C_MA
147 circ_buf_t tsp_circ_buf;
148 circ_buf_t tlp_circ_buf;
149#else
152#endif
154
164
175
183
191
200
201#ifdef __cplusplus
202}
203#endif
204
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:81
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:107
uint16_t buf[SM_PWM_01C_BUFFER_LEN]
circular buffer memory
Definition sm_pwm_01c.h:108
size_t head
current buffer head
Definition sm_pwm_01c.h:109
LPO and concentration (ug/m3) values for small and large particles.
Definition sm_pwm_01c.h:132
uint16_t mc_pm_10
Large particle concentration ug/m3.
Definition sm_pwm_01c.h:134
uint16_t mc_pm_2p5
Small particle concentration ug/m3.
Definition sm_pwm_01c.h:133
Parameters for the SM_PWM_01c sensor.
Definition sm_pwm_01c.h:118
gpio_t tlp_pin
Low Pulse Signal Output (P2) of large Particle, active low, PM10 equivalent.
Definition sm_pwm_01c.h:121
gpio_t tsp_pin
Low Pulse Signal Output (P1) of small Particle, active low, PM2.5 equivalent.
Definition sm_pwm_01c.h:119
Device descriptor for the SM_PWM_01c sensor.
Definition sm_pwm_01c.h:158
sm_pwm_01c_values_t _values
Internal data to calculate concentration from tsl/tsp low Pulse Output Occupancy.
Definition sm_pwm_01c.h:160
sm_pwm_01c_params_t params
Device driver parameters.
Definition sm_pwm_01c.h:159
ztimer_t _sampler
internal sampling timer
Definition sm_pwm_01c.h:162
LPO and concentration (ug/m3) values for small and large particles.
Definition sm_pwm_01c.h:141
uint32_t tsp_lpo
Small particle low Pulse active time us.
Definition sm_pwm_01c.h:142
uint32_t tlp_start_time
Last time tlp pin went low.
Definition sm_pwm_01c.h:144
sm_pwm_01c_data_t data
Current value for the exponentially averaged particle concentration values.
Definition sm_pwm_01c.h:150
uint32_t tsp_start_time
Last time tsp pin went low.
Definition sm_pwm_01c.h:145
uint32_t tlp_lpo
Large Particle low Pulse active time us.
Definition sm_pwm_01c.h:143
ztimer structure
Definition ztimer.h:319
Utility library for comparing and computing timestamps.
ztimer API