Loading...
Searching...
No Matches
mhz19.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Koen Zandberg <koen@bergzand.net>
3 * SPDX-FileCopyrightText: 2018 Beduino Master Projekt - University of Bremen
4 * SPDX-FileCopyrightText: 2020 Bas Stottelaar <basstottelaar@gmail.com>
5 * SPDX-License-Identifier: LGPL-2.1-only
6 */
7
8#pragma once
9
36
37#include <stdbool.h>
38
39#include "saul.h"
40
41#ifdef MODULE_MHZ19_UART
42#include "periph/uart.h"
43#include "mhz19_internals.h"
44#include "mutex.h"
45#endif /* MODULE_MHZ19_UART */
46
47#ifdef MODULE_MHZ19_PWM
48#include "periph/gpio.h"
49#endif /* MODULE_MHZ19_PWM */
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
58enum {
63};
64
65#ifdef MODULE_MHZ19_UART
69typedef struct {
70 uart_t uart;
71 bool auto_calibration;
72} mhz19_params_t;
73
77typedef struct {
78 const mhz19_params_t *params;
79 mutex_t mutex;
80 mutex_t sync;
81 uint8_t idx;
82 uint8_t rxmem[MHZ19_BUF_SIZE];
83} mhz19_t;
84#endif /* MODULE_MHZ19_UART */
85
86#ifdef MODULE_MHZ19_PWM
90typedef struct {
91 gpio_t pin;
92} mhz19_params_t;
93
97typedef struct {
98 gpio_t pin;
99} mhz19_t;
100#endif /* MODULE_MHZ19_PWM */
101
106
116int mhz19_init(mhz19_t *dev, const mhz19_params_t *params);
117
129int mhz19_get_ppm(mhz19_t *dev, int16_t *ppm);
130
131#ifdef MODULE_MHZ19_UART
138void mhz19_set_auto_calibration(mhz19_t *dev, bool enable);
139
145void mhz19_calibrate_zero_point(mhz19_t *dev);
146#endif
147
148#ifdef __cplusplus
149}
150#endif
151
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
Low-level GPIO peripheral driver interface definitions.
int mhz19_init(mhz19_t *dev, const mhz19_params_t *params)
Initialize a MH-Z19 device.
int mhz19_get_ppm(mhz19_t *dev, int16_t *ppm)
Get measured CO2 ppm value.
const saul_driver_t mhz19_ppm_saul_driver
Export SAUL endpoint.
@ MHZ19_ERR_CHECKSUM
checksum failure on received data
Definition mhz19.h:62
@ MHZ19_ERR_INIT
error initializing the device
Definition mhz19.h:60
@ MHZ19_OK
everything was fine
Definition mhz19.h:59
@ MHZ19_ERR_TIMEOUT
timeout on retrieving sensor data
Definition mhz19.h:61
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:109
Internal addresses, registers, constants for the MH-Z19 CO2 sensor.
Mutex for thread synchronization.
Mutex structure.
Definition mutex.h:36
Definition of the RIOT actuator/sensor interface.
Definition saul.h:286
Low-level UART peripheral driver interface definition.