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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
53#define IRSENSE2_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
63#define IRSENSE2_RETVAL uint8_t
64
65#define IRSENSE2_OK 0x00
66#define IRSENSE2_INIT_ERROR 0xFF
73#define IRS
74#define COMPANY_CODE_WIA1 0x00
75#define DEVICE_ID_WIA2 0x01
76#define INFO_1 0x02
77#define INFO_2 0x03
78#define STATUS_1_ST1 0x04
79#define STATUS_2_ST2 0x0A
80#define INTCAUSE 0x05
81#define IR_SENSOR_LSB 0x06
82#define IR_SENSOR_MSB 0x07
83#define TMP_SENSOR_LSB 0x08
84#define TMP_SENSOR_MSB 0x09
85#define THIRH_IR_THRESHOLD_LVL_LSB 0x0B
86#define THIRH_IR_THRESHOLD_LVL_MSB 0x0C
87#define THIRL_IR_THRESHOLD_LVL_LSB 0x0D
88#define THIRL_IR_THRESHOLD_LVL_MSB 0x0E
89#define THTMPH_TEMP_SENS_THRESHOLD_LV_LSB 0x0F
90#define THTMPH_TEMP_SENS_THRESHOLD_LV_MSB 0x10
91#define THTMPL_TEMP_SENS_THRESHOLD_LV_LSB 0x11
92#define THTMPL_TEMP_SENS_THRESHOLD_LV_MSB 0x12
93#define INTEN_INTERRUPT_FACTOR_SETTING 0x13
94#define CNTL1_CUT_OFF_FREQ_SETTING 0x14
95#define CNTL2_OPERATING_MODE_SETTING 0x15
96#define CNTL3_SOFT_RESET 0x16
103#define ST1_RST 0xFE
104#define INTCAUSE_RST 0xE0
105#define IR_RST 0x00
106#define TMP_RST 0x00
107#define ST2_RST 0xFE
108#define THIRH_THIRL_THTMPH_THTMPL_RST 0x00
109#define INTEN_RST 0xE0
110#define CNTL1_RST 0xE0
111#define CNTL2_RST 0xFC
112#define CNTL3_RST 0xFE
119#define INTEN_MODE_MASK_DATARDY_INT_VALID 0xE1
120#define CNTL1_IR__MODE_MASK_NO_FILTER 0xE0
121#define CNTL1_IR__MODE_MASK_FC_2_5HZ 0xE8
122#define CNTL1_IR_MODE_MASK_FC_0_9HZ 0xF0
123#define CNTL1_IR_MODE_MASK_FC_0_45HZ 0xF8
124#define CNTL1_TMP_MODE_MASK_NO_FILTER 0xE0
125#define CNTL1_TMP_MODE_MASK_FC_2_5HZ 0xE1
126#define CNTL1_TMP_MODE_MASK_FC_0_9HZ 0xE2
127#define CNTL1_TMP_MODE_MASK_FC_0_45HZ 0xE3
128#define CNTL1_TMP_MODE_MASK_FC_0_22HZ 0xE4
129#define CNTL2_STANDBY_MODE 0xFC
130#define CNTL2_CONTINUOUS_MODE 0xFD
131#define CNTL2_SINGLE_SHOT_MODE 0xFE
132#define CNTL3_RESET_MODE 0xFF // End group macro
136// --------------------------------------------------------------- PUBLIC TYPES
145typedef struct
146{
147 // Input pins
148
149 digital_in_t int_pin;
150
151 // Modules
152
153 i2c_master_t i2c;
154
155 // ctx variable
156
158
159 uint8_t data_flag;
162
163} irsense2_t;
164
168typedef struct
169{
170 // Communication gpio pins
171
172 pin_name_t scl;
173 pin_name_t sda;
174
175 // Additional gpio pins
176
177 pin_name_t int_pin;
178
179 // static variable
180
181 uint32_t i2c_speed;
182 uint8_t i2c_address;
186
188 // End types group
190// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
191
197#ifdef __cplusplus
198extern "C"{
199#endif
200
210
219
228
239void irsense2_generic_write ( irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
240
252void irsense2_generic_read ( irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
253
264void irsense2_data_read ( irsense2_t *ctx, float *ir_data, float *temp_data );
265
277
289
299
310uint8_t irsense_human_detected ( irsense2_t *ctx, float ir_data );
311
321
322#ifdef __cplusplus
323}
324#endif
325#endif // _IRSENSE2_H_
326 // End public_function group
329
330// ------------------------------------------------------------------------- END
#define IRSENSE2_RETVAL
Definition: irsense2.h:63
void irsense2_cfg_setup(irsense2_cfg_t *cfg)
Config Object Initialization function.
int16_t irsense2_get_temperature_data(irsense2_t *ctx)
Temperatire Data read function.
void irsense2_default_cfg(irsense2_t *ctx)
Click Default Configuration function.
void irsense2_data_read(irsense2_t *ctx, float *ir_data, float *temp_data)
Data function.
void irsense2_generic_write(irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void irsense2_get_int_pin(irsense2_t *ctx)
Int_pin state function.
int16_t irsense2_get_ir_data(irsense2_t *ctx)
IR Data read function.
IRSENSE2_RETVAL irsense2_init(irsense2_t *ctx, irsense2_cfg_t *cfg)
Initialization function.
uint8_t irsense_human_detected(irsense2_t *ctx, float ir_data)
Human detection function.
void irsense2_get_int(irsense2_t *ctx)
Interrupt factor function.
void irsense2_generic_read(irsense2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click configuration structure definition.
Definition: irsense2.h:169
int8_t prev_ir_data_cfg
Definition: irsense2.h:184
uint8_t data_flag_cfg
Definition: irsense2.h:183
uint32_t i2c_speed
Definition: irsense2.h:181
int8_t prev_ir_data_cfg2
Definition: irsense2.h:185
pin_name_t scl
Definition: irsense2.h:172
pin_name_t int_pin
Definition: irsense2.h:177
pin_name_t sda
Definition: irsense2.h:173
uint8_t i2c_address
Definition: irsense2.h:182
Click ctx object definition.
Definition: irsense2.h:146
uint8_t data_flag
Definition: irsense2.h:159
float prev_ir_data
Definition: irsense2.h:160
digital_in_t int_pin
Definition: irsense2.h:149
i2c_master_t i2c
Definition: irsense2.h:153
uint8_t slave_address
Definition: irsense2.h:157
float prev_ir_data2
Definition: irsense2.h:161