mhz19.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Koen Zandberg <koen@bergzand.net>
3  * Copyright (C) 2018 Beduino Master Projekt - University of Bremen
4  * Copyright (C) 2020 Bas Stottelaar <basstottelaar@gmail.com>
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
11 #pragma once
12 
40 #include <stdbool.h>
41 
42 #include "saul.h"
43 
44 #ifdef MODULE_MHZ19_UART
45 #include "periph/uart.h"
46 #include "mhz19_internals.h"
47 #include "mutex.h"
48 #endif /* MODULE_MHZ19_UART */
49 
50 #ifdef MODULE_MHZ19_PWM
51 #include "periph/gpio.h"
52 #endif /* MODULE_MHZ19_PWM */
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
61 enum {
62  MHZ19_OK = 0,
66 };
67 
68 #ifdef MODULE_MHZ19_UART
72 typedef struct {
73  uart_t uart;
74  bool auto_calibration;
75 } mhz19_params_t;
76 
80 typedef struct {
81  const mhz19_params_t *params;
82  mutex_t mutex;
83  mutex_t sync;
84  uint8_t idx;
85  uint8_t rxmem[MHZ19_BUF_SIZE];
86 } mhz19_t;
87 #endif /* MODULE_MHZ19_UART */
88 
89 #ifdef MODULE_MHZ19_PWM
93 typedef struct {
94  gpio_t pin;
95 } mhz19_params_t;
96 
100 typedef struct {
101  gpio_t pin;
102 } mhz19_t;
103 #endif /* MODULE_MHZ19_PWM */
104 
109 
119 int mhz19_init(mhz19_t *dev, const mhz19_params_t *params);
120 
132 int mhz19_get_ppm(mhz19_t *dev, int16_t *ppm);
133 
134 #ifdef MODULE_MHZ19_UART
141 void mhz19_set_auto_calibration(mhz19_t *dev, bool enable);
142 
148 void mhz19_calibrate_zero_point(mhz19_t *dev);
149 #endif
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
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:65
@ MHZ19_ERR_INIT
error initializing the device
Definition: mhz19.h:63
@ MHZ19_OK
everything was fine
Definition: mhz19.h:62
@ MHZ19_ERR_TIMEOUT
timeout on retrieving sensor data
Definition: mhz19.h:64
uint_fast8_t uart_t
Define default UART type identifier.
Definition: uart.h:84
Internal addresses, registers, constants for the MH-Z19 CO2 sensor.
Mutex for thread synchronization.
Mutex structure.
Definition: mutex.h:39
Definition of the RIOT actuator/sensor interface.
Definition: saul.h:283
Functionality for reading [S]ensor [A]ctuator [U]ber [L]ayer sensors as SenML.
Low-level UART peripheral driver interface definition.