pir 2.0.0.0
pir.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef PIR_H
36#define PIR_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define PIR_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
71
78#define PIR_RETVAL uint8_t
79
80#define PIR_OK 0x00
81#define PIR_INIT_ERROR 0xFF
84 // End group macro
85// --------------------------------------------------------------- PUBLIC TYPES
94typedef struct
95{
96 // Input pins
97
98 digital_in_t an;
99
100 // Modules
101
102 i2c_master_t i2c;
103
104 // ctx variable
105
107
108} pir_t;
109
113typedef struct
114{
115 // Communication gpio pins
116
117 pin_name_t scl;
118 pin_name_t sda;
119
120 // Additional gpio pins
121
122 pin_name_t an;
123
124 // static variable
125
126 uint32_t i2c_speed;
127 uint8_t i2c_address;
128
129} pir_cfg_t;
130
131 // End types group
132
133// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134
140#ifdef __cplusplus
141extern "C"{
142#endif
143
153
163
174void pir_generic_write ( pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
175
187void pir_generic_read ( pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
188
196uint16_t pir_get_adc ( pir_t *ctx );
197
205uint16_t pir_reg_read ( pir_t *ctx );
206
215float pir_get_mili_volt ( pir_t *ctx, uint16_t ref_voltage );
216
227float pir_scale_results ( pir_t *ctx, uint16_t in_val, uint16_t out_min, uint16_t out_max );
228
229#ifdef __cplusplus
230}
231#endif
232#endif // _PIR_H_
233
234 // End public_function group
236
237// ------------------------------------------------------------------------- END
#define PIR_RETVAL
Definition pir.h:78
PIR_RETVAL pir_init(pir_t *ctx, pir_cfg_t *cfg)
Initialization function.
float pir_get_mili_volt(pir_t *ctx, uint16_t ref_voltage)
Reading ADC data in mili Volts.
void pir_generic_write(pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t pir_get_adc(pir_t *ctx)
Reading 12bit ADC value.
float pir_scale_results(pir_t *ctx, uint16_t in_val, uint16_t out_min, uint16_t out_max)
Scaling ADC results.
void pir_generic_read(pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void pir_cfg_setup(pir_cfg_t *cfg)
Config Object Initialization function.
uint16_t pir_reg_read(pir_t *ctx)
Reading register.
Click configuration structure definition.
Definition pir.h:114
uint32_t i2c_speed
Definition pir.h:126
pin_name_t scl
Definition pir.h:117
pin_name_t sda
Definition pir.h:118
pin_name_t an
Definition pir.h:122
uint8_t i2c_address
Definition pir.h:127
Click ctx object definition.
Definition pir.h:95
i2c_master_t i2c
Definition pir.h:102
digital_in_t an
Definition pir.h:98
uint8_t slave_address
Definition pir.h:106