apc1sensor 2.1.0.0
apc1sensor.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef APC1SENSOR_H
29#define APC1SENSOR_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_uart.h"
53
74#define APC1SENSOR_ADDRESS_CMD 0x40
75#define APC1SENSOR_ADDRESS_RESPONSE 0x47
76#define APC1SENSOR_CMD_SET_MEAS_MODE 0xE1
77#define APC1SENSOR_CMD_REQ_MEASUREMENT 0xE2
78#define APC1SENSOR_CMD_SET_MODE 0xE4
79#define APC1SENSOR_CMD_GET_INFO 0xE9
80
81 // apc1sensor_cmd
82
97#define APC1SENSOR_HEADER_0 0x42
98#define APC1SENSOR_HEADER_1 0x4D
99
104#define APC1SENSOR_MEASUREMENT_PASSIVE 0x00
105#define APC1SENSOR_MEASUREMENT_ACTIVE 0x01
106
111#define APC1SENSOR_MODE_IDLE 0x00
112#define APC1SENSOR_MODE_MEASUREMENT 0x01
113#define APC1SENSOR_MODE_RESET 0x0F
114
119#define APC1SENSOR_OPMODE_NORMAL 0
120#define APC1SENSOR_OPMODE_DEEP_SLEEP 1
121#define APC1SENSOR_OPMODE_RESET 2
122
128#define APC1SENSOR_TX_DRV_BUFFER_SIZE 100
129#define APC1SENSOR_RX_DRV_BUFFER_SIZE 300
130
136#define APC1SENSOR_DEVICE_ADDRESS 0x12
137
138 // apc1sensor_set
139
154#define APC1SENSOR_MAP_MIKROBUS( cfg, mikrobus ) \
155 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
156 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
157 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
158 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
159 cfg.set = MIKROBUS( mikrobus, MIKROBUS_CS ); \
160 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
161
162 // apc1sensor_map
163 // apc1sensor
164
175
180typedef struct
181{
182 digital_out_t set;
183 digital_out_t rst;
185 i2c_master_t i2c;
186 uart_t uart;
190 uint8_t uart_rx_buffer[ APC1SENSOR_RX_DRV_BUFFER_SIZE ];
191 uint8_t uart_tx_buffer[ APC1SENSOR_TX_DRV_BUFFER_SIZE ];
195 uint8_t meas_mode;
198
203typedef struct
204{
205 pin_name_t scl;
206 pin_name_t sda;
207 pin_name_t rx_pin;
208 pin_name_t tx_pin;
210 pin_name_t set;
211 pin_name_t rst;
213 uint32_t i2c_speed;
214 uint8_t i2c_address;
216 uint32_t baud_rate;
218 uart_data_bits_t data_bit;
219 uart_parity_t parity_bit;
220 uart_stop_bits_t stop_bit;
225
230typedef struct
231{
232 uint16_t pm1_0;
233 uint16_t pm2_5;
234 uint16_t pm10;
235 uint16_t pm1_0_air;
236 uint16_t pm2_5_air;
237 uint16_t pm10_air;
243 uint16_t part_over_10um;
244 uint16_t tvoc;
245 uint16_t eco2;
246 float t_comp;
247 float rh_comp;
248 float t_raw;
249 float rh_raw;
250 uint32_t rs0;
251 uint32_t rs1;
252 uint32_t rs2;
253 uint32_t rs3;
254 uint8_t aqi;
255 uint8_t version;
256 uint8_t error_code;
259
264typedef struct
265{
266 uint8_t module_name[ 7 ];
267 uint8_t serial_num[ 8 ];
268 uint8_t fw_version[ 2 ];
271
282
299
315
330
344
356
368
380
393err_t apc1sensor_set_meas_mode ( apc1sensor_t *ctx, uint8_t mode );
394
406
420
434
446void apc1sensor_set_opmode ( apc1sensor_t *ctx, uint8_t opmode );
447
457
458#ifdef __cplusplus
459}
460#endif
461#endif // APC1SENSOR_H
462
463 // apc1sensor
464
465// ------------------------------------------------------------------------ END
apc1sensor_drv_t
APC1 Sensor Click driver selector.
Definition apc1sensor.h:170
@ APC1SENSOR_DRV_SEL_UART
Definition apc1sensor.h:172
@ APC1SENSOR_DRV_SEL_I2C
Definition apc1sensor.h:171
apc1sensor_return_value_t
APC1 Sensor Demo return value data.
Definition apc1sensor.h:277
@ APC1SENSOR_ERROR
Definition apc1sensor.h:279
@ APC1SENSOR_OK
Definition apc1sensor.h:278
#define APC1SENSOR_TX_DRV_BUFFER_SIZE
APC1 Sensor driver buffer size.
Definition apc1sensor.h:128
#define APC1SENSOR_RX_DRV_BUFFER_SIZE
Definition apc1sensor.h:129
void apc1sensor_cfg_setup(apc1sensor_cfg_t *cfg)
APC1 Sensor configuration object setup function.
err_t apc1sensor_init(apc1sensor_t *ctx, apc1sensor_cfg_t *cfg)
APC1 Sensor initialization function.
err_t apc1sensor_read_measurement(apc1sensor_t *ctx, apc1sensor_measurement_t *measurement)
APC1 Sensor read measurement function.
err_t apc1sensor_default_cfg(apc1sensor_t *ctx)
APC1 Sensor default configuration function.
err_t apc1sensor_set_idle_mode(apc1sensor_t *ctx)
APC1 Sensor set idle mode function.
err_t apc1sensor_sw_reset(apc1sensor_t *ctx)
APC1 Sensor sw reset function.
void apc1sensor_drv_interface_sel(apc1sensor_cfg_t *cfg, apc1sensor_drv_t drv_sel)
APC1 Sensor driver interface setup function.
err_t apc1sensor_start_measurement(apc1sensor_t *ctx)
APC1 Sensor start measurement function.
err_t apc1sensor_set_meas_mode(apc1sensor_t *ctx, uint8_t mode)
APC1 Sensor set meas mode function.
void apc1sensor_set_opmode(apc1sensor_t *ctx, uint8_t opmode)
APC1 Sensor set opmode function.
err_t apc1sensor_read_info(apc1sensor_t *ctx, apc1sensor_info_t *info)
APC1 Sensor read info function.
err_t apc1sensor_request_meas(apc1sensor_t *ctx)
APC1 Sensor request meas function.
void apc1sensor_reset_device(apc1sensor_t *ctx)
APC1 Sensor reset device function.
APC1 Sensor Demo configuration object.
Definition apc1sensor.h:204
uint32_t baud_rate
Definition apc1sensor.h:216
pin_name_t set
Definition apc1sensor.h:210
apc1sensor_drv_t drv_sel
Definition apc1sensor.h:222
uint32_t i2c_speed
Definition apc1sensor.h:213
bool uart_blocking
Definition apc1sensor.h:217
uart_data_bits_t data_bit
Definition apc1sensor.h:218
pin_name_t tx_pin
Definition apc1sensor.h:208
pin_name_t rx_pin
Definition apc1sensor.h:207
uart_stop_bits_t stop_bit
Definition apc1sensor.h:220
pin_name_t scl
Definition apc1sensor.h:205
uart_parity_t parity_bit
Definition apc1sensor.h:219
pin_name_t sda
Definition apc1sensor.h:206
pin_name_t rst
Definition apc1sensor.h:211
uint8_t i2c_address
Definition apc1sensor.h:214
APC1 Sensor Demo module type, ID and firmware version object.
Definition apc1sensor.h:265
APC1 Sensor Demo measurement data object.
Definition apc1sensor.h:231
uint16_t part_over_2_5um
Definition apc1sensor.h:241
uint16_t part_over_1_0um
Definition apc1sensor.h:240
uint16_t part_over_0_5um
Definition apc1sensor.h:239
uint16_t tvoc
Definition apc1sensor.h:244
uint8_t error_code
Definition apc1sensor.h:256
uint8_t aqi
Definition apc1sensor.h:254
uint16_t pm10
Definition apc1sensor.h:234
uint16_t eco2
Definition apc1sensor.h:245
float t_raw
Definition apc1sensor.h:248
float rh_raw
Definition apc1sensor.h:249
uint32_t rs1
Definition apc1sensor.h:251
uint16_t part_over_0_3um
Definition apc1sensor.h:238
uint32_t rs0
Definition apc1sensor.h:250
float rh_comp
Definition apc1sensor.h:247
float t_comp
Definition apc1sensor.h:246
uint16_t pm1_0_air
Definition apc1sensor.h:235
uint8_t version
Definition apc1sensor.h:255
uint16_t pm2_5_air
Definition apc1sensor.h:236
uint16_t part_over_10um
Definition apc1sensor.h:243
uint16_t pm2_5
Definition apc1sensor.h:233
uint32_t rs3
Definition apc1sensor.h:253
uint16_t pm1_0
Definition apc1sensor.h:232
uint32_t rs2
Definition apc1sensor.h:252
uint16_t pm10_air
Definition apc1sensor.h:237
uint16_t part_over_5_0um
Definition apc1sensor.h:242
APC1 Sensor Demo context object.
Definition apc1sensor.h:181
apc1sensor_drv_t drv_sel
Definition apc1sensor.h:193
uint8_t meas_mode
Definition apc1sensor.h:195
uart_t uart
Definition apc1sensor.h:186
i2c_master_t i2c
Definition apc1sensor.h:185
digital_out_t set
Definition apc1sensor.h:182
digital_out_t rst
Definition apc1sensor.h:183
uint8_t slave_address
Definition apc1sensor.h:188