irsense3  2.0.0.0
irsense3.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 IRSENSE3_H
36 #define IRSENSE3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define IRSENSE3_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
65 
71 #define IRSENSE3_RETVAL uint8_t
72 
73 #define IRSENSE3_OK 0x00
74 #define IRSENSE3_INIT_ERROR 0xFF
75 
81 #define IRSENSE3_REG_COMPANY_CODE 0x00
82 #define IRSENSE3_REG_DEVICE_ID 0x01
83 #define IRSENSE3_REG_INFO_1 0x02
84 #define IRSENSE3_REG_INFO_2 0x03
85 #define IRSENSE3_REG_STATUS_1 0x04
86 #define IRSENSE3_REG_IR_LSB 0x05
87 #define IRSENSE3_REG_IR_MSB 0x06
88 #define IRSENSE3_REG_TEMP_LSB 0x07
89 #define IRSENSE3_REG_TEMP_MSB 0x08
90 #define IRSENSE3_REG_STATUS_2 0x09
91 #define IRSENSE3_REG_STATUS_3 0x0A
92 #define IRSENSE3_REG_STATUS_4 0x1F
93 #define IRSENSE3_REG_CTRL_1 0x20
94 #define IRSENSE3_REG_CTRL_2 0x21
95 #define IRSENSE3_REG_CTRL_3 0x22
96 #define IRSENSE3_REG_CTRL_4 0x23
97 #define IRSENSE3_REG_CTRL_5 0x24
98 #define IRSENSE3_REG_CTRL_6 0x25
99 #define IRSENSE3_REG_CTRL_7 0x26
100 #define IRSENSE3_REG_CTRL_8 0x27
101 #define IRSENSE3_REG_CTRL_9 0x28
102 #define IRSENSE3_REG_CTRL_10 0x29
103 #define IRSENSE3_REG_CTRL_11 0x2A
104 #define IRSENSE3_REG_CTRL_12 0x2B
105 
111 #define IRSENSE3_DEVICE_ID 0x15
112 #define IRSENSE3_COMPANY_CODE 0x48
113 
119 #define IRSENSE3_CTRL1_NORMAL_STATE 0xFE
120 #define IRSENSE3_CTRL1_SOFTWARE_RESET 0xFF
121 
127 #define IRSENSE3_CTRL2_NO_SYNC 0xFC
128 #define IRSENSE3_CTRL2_MASTER_SYNC 0xFD
129 #define IRSENSE3_CTRL2_SLAVE_SYNC 0xFE
130 
136 #define IRSENSE3_CTRL3_LOW_NOISE_DISABLE 0x80
137 #define IRSENSE3_CTRL3_LOW_NOISE_ENABLE 0xC0
138 #define IRSENSE3_CTRL3_ODR_1Hz 0x80
139 #define IRSENSE3_CTRL3_ODR_2Hz 0x90
140 #define IRSENSE3_CTRL3_ODR_10Hz 0xA0
141 #define IRSENSE3_CTRL3_ODR_50Hz 0xB0
142 #define IRSENSE3_CTRL3_NO_TEMP_FILTER 0x80
143 #define IRSENSE3_CTRL3_TEMP_FILTER_0p9Hz 0x84
144 #define IRSENSE3_CTRL3_TEMP_FILTER_0p445Hz 0x88
145 #define IRSENSE3_CTRL3_NO_IR_FILTER 0x80
146 #define IRSENSE3_CTRL3_IR_FILTER_0p9Hz 0x81
147 #define IRSENSE3_CTRL3_IR_FILTER_0p445Hz 0x82
148 
154 #define IRSENSE3_CTRL4_TOPT_THR_DISABLE 0xF8
155 #define IRSENSE3_CTRL4_TOPT_THR_ENABLE 0xFC
156 #define IRSENSE3_CTRL4_TOPT_NOISE_DISABLE 0xF8
157 #define IRSENSE3_CTRL4_TOPT_NOISE_ENABLE 0xFB
158 
164 #define IRSENSE3_CTRL7_HUMAN_DETECT_NORMAL 0xF0
165 #define IRSENSE3_CTRL7_HUMAN_DETECT_INVERT 0xF8
166 #define IRSENSE3_CTRL7_HUMAN_DETECT_TIME_0sec 0xF0
167 #define IRSENSE3_CTRL7_HUMAN_DETECT_TIME_5sec 0xF1
168 #define IRSENSE3_CTRL7_HUMAN_DETECT_TIME_10sec 0xF2
169 #define IRSENSE3_CTRL7_HUMAN_DETECT_TIME_30sec 0xF3
170 #define IRSENSE3_CTRL7_HUMAN_DETECT_TIME_300sec 0xF4
171 
177 #define IRSENSE3_CTRL11_HBDEN_OFF 0xE0
178 #define IRSENSE3_CTRL11_HBDEN_ON 0xF0
179 #define IRSENSE3_CTRL11_DO_NOT_STOP_UPDATING_SB 0xE0
180 #define IRSENSE3_CTRL11_STOP_UPDATING_SB 0xE8
181 #define IRSENSE3_CTRL11_STREAMING_BUFFER_OFF 0xE0
182 #define IRSENSE3_CTRL11_STREAMING_BUFFER_ON 0xE4
183 #define IRSENSE3_CTRL11_INT_HUMAN_DISABLE 0xE0
184 #define IRSENSE3_CTRL11_INT_HUMAN_ENABLE 0xE2
185 #define IRSENSE3_CTRL11_INT_DRDY_DISABLE 0xE0
186 #define IRSENSE3_CTRL11_INT_DRDY_ENABLE 0xE1
187 
193 #define IRSENSE3_CTRL12_STANDBY_MODE 0xFE
194 #define IRSENSE3_CTRL12_CONTINUOUS_MODE 0xFF
195 
201 #define IRSENSE3_PRESENCE_IS_DETECTED 0x01
202 #define IRSENSE3_PRESENCE_IS_NOT_DETECTED 0x00
203  // End group macro
206 // --------------------------------------------------------------- PUBLIC TYPES
215 typedef struct
216 {
217  // Input pins
218 
219  digital_in_t int_pin;
220 
221  // Modules
222 
223  i2c_master_t i2c;
224 
225  // ctx variable
226 
227  uint8_t slave_address;
228 
229 } irsense3_t;
230 
234 typedef struct
235 {
236  // Communication gpio pins
237 
238  pin_name_t scl;
239  pin_name_t sda;
240 
241  // Additional gpio pins
242 
243  pin_name_t int_pin;
244 
245  // static variable
246 
247  uint32_t i2c_speed;
248  uint8_t i2c_address;
249 
251  // End types group
253 
254 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
255 
261 #ifdef __cplusplus
262 extern "C"{
263 #endif
264 
274 
283 
284 
293 
304 void irsense3_generic_write ( irsense3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
305 
317 void irsense3_generic_read ( irsense3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
318 
327 
336 
345 
354 
361 
372 void irsense3_generic_write ( irsense3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
373 
385 void irsense3_generic_read ( irsense3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 #endif // _IRSENSE3_H_
391  // End public_function group
394 
395 // ------------------------------------------------------------------------- END
irsense3_default_cfg
void irsense3_default_cfg(irsense3_t *ctx)
Click Default Configuration function.
irsense3_t::i2c
i2c_master_t i2c
Definition: irsense3.h:223
irsense3_cfg_t::int_pin
pin_name_t int_pin
Definition: irsense3.h:243
irsense3_get_interrupt_state
uint8_t irsense3_get_interrupt_state(irsense3_t *ctx)
Get Interrupt state.
irsense3_generic_read
void irsense3_generic_read(irsense3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
irsense3_t
Click ctx object definition.
Definition: irsense3.h:216
irsense3_cfg_setup
void irsense3_cfg_setup(irsense3_cfg_t *cfg)
Config Object Initialization function.
irsense3_t::int_pin
digital_in_t int_pin
Definition: irsense3.h:219
irsense3_cfg_t::scl
pin_name_t scl
Definition: irsense3.h:238
irsense3_generic_write
void irsense3_generic_write(irsense3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
irsense3_init
IRSENSE3_RETVAL irsense3_init(irsense3_t *ctx, irsense3_cfg_t *cfg)
Initialization function.
irsense3_human_approach_detect
uint8_t irsense3_human_approach_detect(irsense3_t *ctx)
Human approach detection.
irsense3_software_reset
void irsense3_software_reset(irsense3_t *ctx)
Software reset.
irsense3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: irsense3.h:247
irsense3_get_temperature_data
float irsense3_get_temperature_data(irsense3_t *ctx)
Temperature data.
irsense3_t::slave_address
uint8_t slave_address
Definition: irsense3.h:227
irsense3_cfg_t::sda
pin_name_t sda
Definition: irsense3.h:239
irsense3_get_ir_sensor_data
float irsense3_get_ir_sensor_data(irsense3_t *ctx)
Output current of IR sensor.
irsense3_cfg_t
Click configuration structure definition.
Definition: irsense3.h:235
IRSENSE3_RETVAL
#define IRSENSE3_RETVAL
Definition: irsense3.h:71
irsense3_cfg_t::i2c_address
uint8_t i2c_address
Definition: irsense3.h:248