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
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef 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 
106  uint8_t slave_address;
107 
108 } pir_t;
109 
113 typedef 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  // End types group
132 
133 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
152 void pir_cfg_setup ( pir_cfg_t *cfg );
153 
163 
174 void pir_generic_write ( pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
175 
187 void pir_generic_read ( pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
188 
196 uint16_t pir_get_adc ( pir_t *ctx );
197 
205 uint16_t pir_reg_read ( pir_t *ctx );
206 
215 float pir_get_mili_volt ( pir_t *ctx, uint16_t ref_voltage );
216 
227 float 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  // End public_function group
236 
237 // ------------------------------------------------------------------------- END
pir_t::an
digital_in_t an
Definition: pir.h:98
pir_t
Click ctx object definition.
Definition: pir.h:95
pir_cfg_t::scl
pin_name_t scl
Definition: pir.h:117
PIR_RETVAL
#define PIR_RETVAL
Definition: pir.h:78
pir_cfg_t
Click configuration structure definition.
Definition: pir.h:114
pir_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pir.h:126
pir_generic_read
void pir_generic_read(pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pir_cfg_setup
void pir_cfg_setup(pir_cfg_t *cfg)
Config Object Initialization function.
pir_generic_write
void pir_generic_write(pir_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pir_cfg_t::sda
pin_name_t sda
Definition: pir.h:118
pir_reg_read
uint16_t pir_reg_read(pir_t *ctx)
Reading register.
pir_t::i2c
i2c_master_t i2c
Definition: pir.h:102
pir_get_mili_volt
float pir_get_mili_volt(pir_t *ctx, uint16_t ref_voltage)
Reading ADC data in mili Volts.
pir_cfg_t::i2c_address
uint8_t i2c_address
Definition: pir.h:127
pir_get_adc
uint16_t pir_get_adc(pir_t *ctx)
Reading 12bit ADC value.
pir_scale_results
float pir_scale_results(pir_t *ctx, uint16_t in_val, uint16_t out_min, uint16_t out_max)
Scaling ADC results.
pir_init
PIR_RETVAL pir_init(pir_t *ctx, pir_cfg_t *cfg)
Initialization function.
pir_cfg_t::an
pin_name_t an
Definition: pir.h:122
pir_t::slave_address
uint8_t slave_address
Definition: pir.h:106