irsense2  2.0.0.0
irsense2.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 IRSENSE2_H
36 #define IRSENSE2_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 IRSENSE2_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
71 
77 #define IRSENSE2_RETVAL uint8_t
78 
79 #define IRSENSE2_OK 0x00
80 #define IRSENSE2_INIT_ERROR 0xFF
81 
87 #define IRS
88 #define COMPANY_CODE_WIA1 0x00
89 #define DEVICE_ID_WIA2 0x01
90 #define INFO_1 0x02
91 #define INFO_2 0x03
92 #define STATUS_1_ST1 0x04
93 #define STATUS_2_ST2 0x0A
94 #define INTCAUSE 0x05
95 #define IR_SENSOR_LSB 0x06
96 #define IR_SENSOR_MSB 0x07
97 #define TMP_SENSOR_LSB 0x08
98 #define TMP_SENSOR_MSB 0x09
99 #define THIRH_IR_THRESHOLD_LVL_LSB 0x0B
100 #define THIRH_IR_THRESHOLD_LVL_MSB 0x0C
101 #define THIRL_IR_THRESHOLD_LVL_LSB 0x0D
102 #define THIRL_IR_THRESHOLD_LVL_MSB 0x0E
103 #define THTMPH_TEMP_SENS_THRESHOLD_LV_LSB 0x0F
104 #define THTMPH_TEMP_SENS_THRESHOLD_LV_MSB 0x10
105 #define THTMPL_TEMP_SENS_THRESHOLD_LV_LSB 0x11
106 #define THTMPL_TEMP_SENS_THRESHOLD_LV_MSB 0x12
107 #define INTEN_INTERRUPT_FACTOR_SETTING 0x13
108 #define CNTL1_CUT_OFF_FREQ_SETTING 0x14
109 #define CNTL2_OPERATING_MODE_SETTING 0x15
110 #define CNTL3_SOFT_RESET 0x16
111 
117 #define ST1_RST 0xFE
118 #define INTCAUSE_RST 0xE0
119 #define IR_RST 0x00
120 #define TMP_RST 0x00
121 #define ST2_RST 0xFE
122 #define THIRH_THIRL_THTMPH_THTMPL_RST 0x00
123 #define INTEN_RST 0xE0
124 #define CNTL1_RST 0xE0
125 #define CNTL2_RST 0xFC
126 #define CNTL3_RST 0xFE
127 
133 #define INTEN_MODE_MASK_DATARDY_INT_VALID 0xE1
134 #define CNTL1_IR__MODE_MASK_NO_FILTER 0xE0
135 #define CNTL1_IR__MODE_MASK_FC_2_5HZ 0xE8
136 #define CNTL1_IR_MODE_MASK_FC_0_9HZ 0xF0
137 #define CNTL1_IR_MODE_MASK_FC_0_45HZ 0xF8
138 #define CNTL1_TMP_MODE_MASK_NO_FILTER 0xE0
139 #define CNTL1_TMP_MODE_MASK_FC_2_5HZ 0xE1
140 #define CNTL1_TMP_MODE_MASK_FC_0_9HZ 0xE2
141 #define CNTL1_TMP_MODE_MASK_FC_0_45HZ 0xE3
142 #define CNTL1_TMP_MODE_MASK_FC_0_22HZ 0xE4
143 #define CNTL2_STANDBY_MODE 0xFC
144 #define CNTL2_CONTINUOUS_MODE 0xFD
145 #define CNTL2_SINGLE_SHOT_MODE 0xFE
146 #define CNTL3_RESET_MODE 0xFF
147  // End group macro
150 // --------------------------------------------------------------- PUBLIC TYPES
159 typedef struct
160 {
161  // Input pins
162 
163  digital_in_t int_pin;
164 
165  // Modules
166 
167  i2c_master_t i2c;
168 
169  // ctx variable
170 
171  uint8_t slave_address;
172 
173  uint8_t data_flag;
176 
177 } irsense2_t;
178 
182 typedef struct
183 {
184  // Communication gpio pins
185 
186  pin_name_t scl;
187  pin_name_t sda;
188 
189  // Additional gpio pins
190 
191  pin_name_t int_pin;
192 
193  // static variable
194 
195  uint32_t i2c_speed;
196  uint8_t i2c_address;
197  uint8_t data_flag_cfg;
200 
202  // End types group
204 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
205 
211 #ifdef __cplusplus
212 extern "C"{
213 #endif
214 
224 
233 
242 
253 void irsense2_generic_write ( irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
254 
266 void irsense2_generic_read ( irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
267 
278 void irsense2_data_read ( irsense2_t *ctx, float *ir_data, float *temp_data );
279 
291 
303 
313 
324 uint8_t irsense_human_detected ( irsense2_t *ctx, float ir_data );
325 
335 
336 #ifdef __cplusplus
337 }
338 #endif
339 #endif // _IRSENSE2_H_
340  // End public_function group
343 
344 // ------------------------------------------------------------------------- END
irsense2_get_ir_data
int16_t irsense2_get_ir_data(irsense2_t *ctx)
IR Data read function.
irsense2_cfg_t
Click configuration structure definition.
Definition: irsense2.h:183
irsense2_t::int_pin
digital_in_t int_pin
Definition: irsense2.h:163
irsense2_t::i2c
i2c_master_t i2c
Definition: irsense2.h:167
irsense2_t::prev_ir_data
float prev_ir_data
Definition: irsense2.h:174
irsense2_cfg_t::prev_ir_data_cfg
int8_t prev_ir_data_cfg
Definition: irsense2.h:198
irsense2_t::data_flag
uint8_t data_flag
Definition: irsense2.h:173
IRSENSE2_RETVAL
#define IRSENSE2_RETVAL
Definition: irsense2.h:77
irsense2_cfg_t::i2c_address
uint8_t i2c_address
Definition: irsense2.h:196
irsense2_get_temperature_data
int16_t irsense2_get_temperature_data(irsense2_t *ctx)
Temperatire Data read function.
irsense2_init
IRSENSE2_RETVAL irsense2_init(irsense2_t *ctx, irsense2_cfg_t *cfg)
Initialization function.
irsense2_t::prev_ir_data2
float prev_ir_data2
Definition: irsense2.h:175
irsense2_data_read
void irsense2_data_read(irsense2_t *ctx, float *ir_data, float *temp_data)
Data function.
irsense2_t
Click ctx object definition.
Definition: irsense2.h:160
irsense2_generic_write
void irsense2_generic_write(irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
irsense2_generic_read
void irsense2_generic_read(irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
irsense2_cfg_t::prev_ir_data_cfg2
int8_t prev_ir_data_cfg2
Definition: irsense2.h:199
irsense2_cfg_t::data_flag_cfg
uint8_t data_flag_cfg
Definition: irsense2.h:197
irsense2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: irsense2.h:195
irsense2_cfg_t::int_pin
pin_name_t int_pin
Definition: irsense2.h:191
irsense2_cfg_t::scl
pin_name_t scl
Definition: irsense2.h:186
irsense2_get_int_pin
void irsense2_get_int_pin(irsense2_t *ctx)
Int_pin state function.
irsense2_t::slave_address
uint8_t slave_address
Definition: irsense2.h:171
irsense2_get_int
void irsense2_get_int(irsense2_t *ctx)
Interrupt factor function.
irsense2_cfg_t::sda
pin_name_t sda
Definition: irsense2.h:187
irsense_human_detected
uint8_t irsense_human_detected(irsense2_t *ctx, float ir_data)
Human detection function.
irsense2_cfg_setup
void irsense2_cfg_setup(irsense2_cfg_t *cfg)
Config Object Initialization function.
irsense2_default_cfg
void irsense2_default_cfg(irsense2_t *ctx)
Click Default Configuration function.