pir2 2.1.0.0
pir2.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 PIR2_H
29#define PIR2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "mikrosdk_version.h"
36
37#ifdef __GNUC__
38#if mikroSDK_GET_VERSION < 20800ul
39#include "rcu_delays.h"
40#else
41#include "delays.h"
42#endif
43#endif
44
45#include "drv_digital_out.h"
46#include "drv_digital_in.h"
47#include "drv_analog_in.h"
48#include "drv_i2c_master.h"
49
70#define PIR2_ADC_RESOLUTION 0x0FFF
71#define PIR2_VREF_3V3 3.3
72#define PIR2_VREF_5V 5.0
73
79#define PIR2_SET_DEV_ADDR 0x4D
80 // pir2_set
82
97#define PIR2_MAP_MIKROBUS( cfg, mikrobus ) \
98 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
99 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
100 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
101 // pir2_map // pir2
104
109typedef enum
110{
115
120typedef struct
121{
122 analog_in_t adc;
123 i2c_master_t i2c;
126 float vref;
129} pir2_t;
130
135typedef struct
136{
137 pin_name_t an;
138 pin_name_t scl;
139 pin_name_t sda;
141 analog_in_resolution_t resolution;
142 float vref;
144 uint32_t i2c_speed;
145 uint8_t i2c_address;
149} pir2_cfg_t;
150
155typedef enum
156{
158 PIR2_ERROR = -1
159
161
178
194
208err_t pir2_init ( pir2_t *ctx, pir2_cfg_t *cfg );
209
221err_t pir2_read_raw_adc ( pir2_t *ctx, uint16_t *raw_adc );
222
234err_t pir2_read_voltage ( pir2_t *ctx, float *voltage );
235
247err_t pir2_set_vref ( pir2_t *ctx, float vref );
248
249#ifdef __cplusplus
250}
251#endif
252#endif // PIR2_H
253 // pir2
255
256// ------------------------------------------------------------------------ END
err_t pir2_init(pir2_t *ctx, pir2_cfg_t *cfg)
PIR 2 initialization function.
err_t pir2_read_voltage(pir2_t *ctx, float *voltage)
PIR 2 read voltage level function.
err_t pir2_read_raw_adc(pir2_t *ctx, uint16_t *raw_adc)
PIR 2 read raw ADC value function.
void pir2_drv_interface_sel(pir2_cfg_t *cfg, pir2_drv_t drv_sel)
PIR 2 driver interface setup function.
void pir2_cfg_setup(pir2_cfg_t *cfg)
PIR 2 configuration object setup function.
err_t pir2_set_vref(pir2_t *ctx, float vref)
PIR 2 set vref function.
pir2_drv_t
PIR 2 Click driver selector.
Definition: pir2.h:110
@ PIR2_DRV_SEL_ADC
Definition: pir2.h:111
@ PIR2_DRV_SEL_I2C
Definition: pir2.h:112
pir2_return_value_t
PIR 2 Click return value data.
Definition: pir2.h:156
@ PIR2_OK
Definition: pir2.h:157
@ PIR2_ERROR
Definition: pir2.h:158
PIR 2 Click configuration object.
Definition: pir2.h:136
analog_in_resolution_t resolution
Definition: pir2.h:141
float vref
Definition: pir2.h:142
pir2_drv_t drv_sel
Definition: pir2.h:147
uint32_t i2c_speed
Definition: pir2.h:144
pin_name_t scl
Definition: pir2.h:138
pin_name_t sda
Definition: pir2.h:139
pin_name_t an
Definition: pir2.h:137
uint8_t i2c_address
Definition: pir2.h:145
PIR 2 Click context object.
Definition: pir2.h:121
float vref
Definition: pir2.h:126
pir2_drv_t drv_sel
Definition: pir2.h:127
i2c_master_t i2c
Definition: pir2.h:123
uint8_t slave_address
Definition: pir2.h:125
analog_in_t adc
Definition: pir2.h:122