irsense4 2.1.0.0
irsense4.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef IRSENSE4_H
29#define IRSENSE4_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
76#define IRSENSE4_REG_LPF1 0x0C
77#define IRSENSE4_REG_LPF2 0x0D
78#define IRSENSE4_REG_WHO_AM_I 0x0F
79#define IRSENSE4_REG_AVG_TRIM 0x10
80#define IRSENSE4_REG_CTRL0 0x17
81#define IRSENSE4_REG_SENS_DATA 0x1D
82#define IRSENSE4_REG_CTRL1 0x20
83#define IRSENSE4_REG_CTRL2 0x21
84#define IRSENSE4_REG_CTRL3 0x22
85#define IRSENSE4_REG_STATUS 0x23
86#define IRSENSE4_REG_FUNC_STATUS 0x25
87#define IRSENSE4_REG_TOBJECT_L 0x26
88#define IRSENSE4_REG_TOBJECT_H 0x27
89#define IRSENSE4_REG_TAMBIENT_L 0x28
90#define IRSENSE4_REG_TAMBIENT_H 0x29
91#define IRSENSE4_REG_TOBJ_COMP_L 0x38
92#define IRSENSE4_REG_TOBJ_COMP_H 0x39
93#define IRSENSE4_REG_TPRESENCE_L 0x3A
94#define IRSENSE4_REG_TPRESENCE_H 0x3B
95#define IRSENSE4_REG_TMOTION_L 0x3C
96#define IRSENSE4_REG_TMOTION_H 0x3D
97#define IRSENSE4_REG_TAMB_SHOCK_L 0x3E
98#define IRSENSE4_REG_TAMB_SHOCK_H 0x3F
99
104#define IRSENSE4_REG_EMB_FUNC_CFG_ADDR 0x08
105#define IRSENSE4_REG_EMB_FUNC_CFG_DATA 0x09
106#define IRSENSE4_REG_EMB_PAGE_RW 0x11
107#define IRSENSE4_REG_EMB_PRESENCE_THS_L 0x20
108#define IRSENSE4_REG_EMB_PRESENCE_THS_H 0x21
109#define IRSENSE4_REG_EMB_MOTION_THS_L 0x22
110#define IRSENSE4_REG_EMB_MOTION_THS_H 0x23
111#define IRSENSE4_REG_EMB_TAMB_SHOCK_THS_L 0x24
112#define IRSENSE4_REG_EMB_TAMB_SHOCK_THS_H 0x25
113#define IRSENSE4_REG_EMB_HYST_MOTION 0x26
114#define IRSENSE4_REG_EMB_HYST_PRESENCE 0x27
115#define IRSENSE4_REG_EMB_ALGO_CONFIG 0x28
116#define IRSENSE4_REG_EMB_HYST_TAMB_SHOCK 0x29
117#define IRSENSE4_REG_EMB_RESET_ALGO 0x2A
118
119 // irsense4_reg
120
136#define IRSENSE4_LPF1_M_ODR_9 0x00
137#define IRSENSE4_LPF1_M_ODR_20 0x01
138#define IRSENSE4_LPF1_M_ODR_50 0x02
139#define IRSENSE4_LPF1_M_ODR_100 0x03
140#define IRSENSE4_LPF1_M_ODR_200 0x04
141#define IRSENSE4_LPF1_M_ODR_400 0x05
142#define IRSENSE4_LPF1_M_ODR_800 0x06
143#define IRSENSE4_LPF1_M_BIT_MASK 0x07
144#define IRSENSE4_LPF1_P_M_ODR_9 0x00
145#define IRSENSE4_LPF1_P_M_ODR_20 0x08
146#define IRSENSE4_LPF1_P_M_ODR_50 0x10
147#define IRSENSE4_LPF1_P_M_ODR_100 0x18
148#define IRSENSE4_LPF1_P_M_ODR_200 0x20
149#define IRSENSE4_LPF1_P_M_ODR_400 0x28
150#define IRSENSE4_LPF1_P_M_ODR_800 0x30
151
158#define IRSENSE4_LPF2_A_T_ODR_9 0x00
159#define IRSENSE4_LPF2_A_T_ODR_20 0x01
160#define IRSENSE4_LPF2_A_T_ODR_50 0x02
161#define IRSENSE4_LPF2_A_T_ODR_100 0x03
162#define IRSENSE4_LPF2_A_T_ODR_200 0x04
163#define IRSENSE4_LPF2_A_T_ODR_400 0x05
164#define IRSENSE4_LPF2_A_T_ODR_800 0x06
165#define IRSENSE4_LPF2_A_T_BIT_MASK 0x07
166#define IRSENSE4_LPF2_P_ODR_9 0x00
167#define IRSENSE4_LPF2_P_ODR_20 0x08
168#define IRSENSE4_LPF2_P_ODR_50 0x10
169#define IRSENSE4_LPF2_P_ODR_100 0x18
170#define IRSENSE4_LPF2_P_ODR_200 0x20
171#define IRSENSE4_LPF2_P_ODR_400 0x28
172#define IRSENSE4_LPF2_P_ODR_800 0x30
173#define IRSENSE4_LPF2_P_BIT_MASK 0x38
174
180#define IRSENSE4_DEVICE_ID 0xD3
181
188#define IRSENSE4_AVG_TRIM_TMOS_2 0x00
189#define IRSENSE4_AVG_TRIM_TMOS_8 0x01
190#define IRSENSE4_AVG_TRIM_TMOS_32 0x02
191#define IRSENSE4_AVG_TRIM_TMOS_128 0x03
192#define IRSENSE4_AVG_TRIM_TMOS_256 0x04
193#define IRSENSE4_AVG_TRIM_TMOS_512 0x05
194#define IRSENSE4_AVG_TRIM_TMOS_1024 0x06
195#define IRSENSE4_AVG_TRIM_TMOS_2048 0x07
196#define IRSENSE4_AVG_TRIM_TMOS_BIT_MASK 0x07
197#define IRSENSE4_AVG_TRIM_T_8 0x00
198#define IRSENSE4_AVG_TRIM_T_4 0x10
199#define IRSENSE4_AVG_TRIM_T_2 0x20
200#define IRSENSE4_AVG_TRIM_T_1 0x30
201#define IRSENSE4_AVG_TRIM_T_BIT_MASK 0x30
202
207#define IRSENSE4_CTRL0_GAIN_1 0x00
208#define IRSENSE4_CTRL0_GAIN_2 0x10
209#define IRSENSE4_CTRL0_GAIN_3 0x20
210#define IRSENSE4_CTRL0_GAIN_4 0x30
211#define IRSENSE4_CTRL0_GAIN_5 0x40
212#define IRSENSE4_CTRL0_GAIN_6 0x50
213#define IRSENSE4_CTRL0_GAIN_7 0x60
214#define IRSENSE4_CTRL0_GAIN_8 0x70
215#define IRSENSE4_CTRL0_DEFAULT 0x81
216
222#define IRSENSE4_SENS_DATA_CALC_DEV 16u
223#define IRSENSE4_SENS_DATA_MIN 2048u
224#define IRSENSE4_SENS_DATA_MAX 6128u
225
231#define IRSENSE4_CTRL1_ODR_POWER_DOWN 0x00
232#define IRSENSE4_CTRL1_ODR_0_25 0x01
233#define IRSENSE4_CTRL1_ODR_0_5 0x02
234#define IRSENSE4_CTRL1_ODR_1 0x03
235#define IRSENSE4_CTRL1_ODR_2 0x04
236#define IRSENSE4_CTRL1_ODR_4 0x05
237#define IRSENSE4_CTRL1_ODR_8 0x06
238#define IRSENSE4_CTRL1_ODR_15 0x07
239#define IRSENSE4_CTRL1_ODR_30 0x08
240#define IRSENSE4_CTRL1_ODR_BIT_MASK 0x0F
241#define IRSENSE4_CTRL1_BDU_DIS 0x00
242#define IRSENSE4_CTRL1_BDU_EN 0x01
243
248#define IRSENSE4_CTRL2_ONE_SHOT_DIS 0x00
249#define IRSENSE4_CTRL2_ONE_SHOT_EN 0x01
250#define IRSENSE4_CTRL2_F_CFG_ACCESS_DIS 0x00
251#define IRSENSE4_CTRL2_F_CFG_ACCESS_EN 0x10
252
257#define IRSENSE4_CTRL3_IEN_HIGH_Z 0x00
258#define IRSENSE4_CTRL3_IEN_DRDY 0x01
259#define IRSENSE4_CTRL3_IEN_INT_OR 0x02
260#define IRSENSE4_CTRL3_IEN_BIT_MASK 0x03
261#define IRSENSE4_CTRL3_INT_LATCHED_PLS 0x00
262#define IRSENSE4_CTRL3_INT_LATCHED_LAT 0x04
263#define IRSENSE4_CTRL3_INT_MSK_T_SHOCK 0x08
264#define IRSENSE4_CTRL3_INT_MSK_MOT 0x10
265#define IRSENSE4_CTRL3_INT_MSK_PRES 0x20
266#define IRSENSE4_CTRL3_PP_OD_PUSH_PULL 0x00
267#define IRSENSE4_CTRL3_PP_OD_OPEN_DRAIN 0x04
268#define IRSENSE4_CTRL3_INT_H_L_HIGH 0x00
269#define IRSENSE4_CTRL3_INT_H_L_LOW 0x80
270#define IRSENSE4_CTRL3_BIT_MASK 0x38
271
276#define IRSENSE4_STATUS_TAMB_SHOCK_FLAG 0x01
277#define IRSENSE4_STATUS_MOT_FLAG 0x02
278#define IRSENSE4_STATUS_PRES_FLAG 0x04
279#define IRSENSE4_STATUS_DETECT_FLAG 0x07
280#define IRSENSE4_STATUS_NOT_DRDY 0x00
281#define IRSENSE4_STATUS_DRDY 0x04
282
288#define IRSENSE4_SET_THS_PRESENCE_DEFAULT 5000u
289#define IRSENSE4_SET_THS_MOTION_DEFAULT 3000u
290#define IRSENSE4_SET_THS_T_SHOCK_DEFAULT 2000u
291#define IRSENSE4_SET_THS_MAX 0x7FFFu
292
298#define IRSENSE4_SENS_TOBJECT 2000.0f
299#define IRSENSE4_SENS_TAMBIENT 100.0f
300#define IRSENSE4_SENS_TOBJ_COMP 2000.0f
301
307#define IRSENSE4_EMB_PAGE_RW_READ_DIS 0x00
308#define IRSENSE4_EMB_PAGE_RW_READ_EN 0x20
309#define IRSENSE4_EMB_PAGE_RW_WRITE_DIS 0x00
310#define IRSENSE4_EMB_PAGE_RW_WRITE_EN 0x40
311
317#define IRSENSE4_DEVICE_ADDRESS 0x5A
318
327#define IRSENSE4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
328#define IRSENSE4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
329
330 // irsense4_set
331
346#define IRSENSE4_MAP_MIKROBUS( cfg, mikrobus ) \
347 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
348 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
349 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
350 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
351 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
352 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
353 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
354
355 // irsense4_map
356 // irsense4
357
368
373typedef err_t ( *irsense4_master_io_t )( struct irsense4_s*, uint8_t, uint8_t*, uint8_t );
394
399typedef struct
400{
401 pin_name_t scl;
402 pin_name_t sda;
403 pin_name_t miso;
404 pin_name_t mosi;
405 pin_name_t sck;
406 pin_name_t cs;
407 pin_name_t int_pin;
409 uint32_t i2c_speed;
410 uint8_t i2c_address;
412 uint32_t spi_speed;
413 spi_master_mode_t spi_mode;
414 spi_master_chip_select_polarity_t cs_polarity;
419
424typedef enum
425{
427 IRSENSE4_ERROR = -1
428
430
442
459
475
490
504
519err_t irsense4_generic_write ( irsense4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
520
535err_t irsense4_generic_read ( irsense4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
536
551err_t irsense4_write_reg ( irsense4_t *ctx, uint8_t reg, uint8_t data_in );
552
567err_t irsense4_read_reg ( irsense4_t *ctx, uint8_t reg, uint8_t *data_out );
568
583err_t irsense4_read_word ( irsense4_t *ctx, uint8_t reg, int16_t *data_out );
584
598err_t irsense4_set_lp_filter_motion ( irsense4_t *ctx, uint8_t lpf_m );
599
613err_t irsense4_set_lp_filter_presence ( irsense4_t *ctx, uint8_t lpf_p );
614
628err_t irsense4_set_lp_filter_amb_temp ( irsense4_t *ctx, uint8_t lpf_at );
629
643err_t irsense4_get_device_id ( irsense4_t *ctx, uint8_t *device_id );
644
659err_t irsense4_set_avr_temp ( irsense4_t *ctx, uint8_t avr_amp_temp, uint8_t avr_obj_temp );
660
674err_t irsense4_set_gain_mode ( irsense4_t *ctx, uint8_t gain_mode );
675
690err_t irsense4_set_sens_data ( irsense4_t *ctx, uint16_t sens );
691
705err_t irsense4_config_odr ( irsense4_t *ctx, uint8_t odr );
706
720
734err_t irsense4_set_int_mask ( irsense4_t *ctx, uint8_t int_mask );
735
749err_t irsense4_config_int_signal ( irsense4_t *ctx, uint8_t int_sr );
750
764
779err_t irsense4_get_status ( irsense4_t *ctx, uint8_t *status );
780
794err_t irsense4_get_obj_temperature ( irsense4_t *ctx, float *temperature );
795
809err_t irsense4_get_amb_temperature ( irsense4_t *ctx, float *temperature );
810
824err_t irsense4_get_comp_temperature ( irsense4_t *ctx, float *temperature );
825
839err_t irsense4_get_presence_data ( irsense4_t *ctx, int16_t *presence );
840
854err_t irsense4_get_motion_data ( irsense4_t *ctx, int16_t *motion );
855
869err_t irsense4_get_amb_shock_data ( irsense4_t *ctx, int16_t *shock );
870
885err_t irsense4_write_emb_reg ( irsense4_t *ctx, uint8_t reg_emb, uint8_t data_in );
886
901err_t irsense4_read_emb_reg ( irsense4_t *ctx, uint8_t reg_emb, uint8_t *data_out );
902
918err_t irsense4_set_threshold ( irsense4_t *ctx, irsense4_ths_sel_t ths_sel, uint16_t threshold );
919
935err_t irsense4_get_threshold ( irsense4_t *ctx, irsense4_ths_sel_t ths_sel, uint16_t *threshold );
936
937#ifdef __cplusplus
938}
939#endif
940#endif // IRSENSE4_H
941
942 // irsense4
943
944// ------------------------------------------------------------------------ END
err_t irsense4_set_lp_filter_amb_temp(irsense4_t *ctx, uint8_t lpf_at)
IR Sense 4 set low-pass filter for ambient temperature function.
err_t irsense4_get_threshold(irsense4_t *ctx, irsense4_ths_sel_t ths_sel, uint16_t *threshold)
IR Sense 4 get the threshold data function.
err_t irsense4_get_device_id(irsense4_t *ctx, uint8_t *device_id)
IR Sense 4 get device ID function.
err_t irsense4_set_lp_filter_motion(irsense4_t *ctx, uint8_t lpf_m)
IR Sense 4 set low-pass filter for motion function.
err_t irsense4_write_reg(irsense4_t *ctx, uint8_t reg, uint8_t data_in)
IR Sense 4 write register function.
err_t irsense4_init(irsense4_t *ctx, irsense4_cfg_t *cfg)
IR Sense 4 initialization function.
err_t irsense4_set_threshold(irsense4_t *ctx, irsense4_ths_sel_t ths_sel, uint16_t threshold)
IR Sense 4 set threshold data function.
err_t irsense4_generic_read(irsense4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
IR Sense 4 data reading function.
err_t irsense4_set_gain_mode(irsense4_t *ctx, uint8_t gain_mode)
IR Sense 4 set gain mode function.
err_t irsense4_get_amb_shock_data(irsense4_t *ctx, int16_t *shock)
IR Sense 4 get the ambient shock detection data function.
err_t irsense4_config_odr(irsense4_t *ctx, uint8_t odr)
IR Sense 4 set output data rate function.
err_t irsense4_read_emb_reg(irsense4_t *ctx, uint8_t reg_emb, uint8_t *data_out)
IR Sense 4 write register function.
err_t irsense4_set_sens_data(irsense4_t *ctx, uint16_t sens)
IR Sense 4 set sensitivity data function.
err_t irsense4_enable_one_shot(irsense4_t *ctx)
IR Sense 4 enable one-shot mode function.
err_t irsense4_set_lp_filter_presence(irsense4_t *ctx, uint8_t lpf_p)
IR Sense 4 set low-pass filter for presence function.
err_t irsense4_set_avr_temp(irsense4_t *ctx, uint8_t avr_amp_temp, uint8_t avr_obj_temp)
IR Sense 4 set averages for temperature function.
err_t irsense4_set_int_mask(irsense4_t *ctx, uint8_t int_mask)
IR Sense 4 set interrupt masks for flag function.
err_t irsense4_get_motion_data(irsense4_t *ctx, int16_t *motion)
IR Sense 4 get the motion detection data function.
err_t irsense4_get_comp_temperature(irsense4_t *ctx, float *temperature)
IR Sense 4 get the compensated temperature function.
err_t irsense4_default_cfg(irsense4_t *ctx)
IR Sense 4 default configuration function.
err_t irsense4_read_word(irsense4_t *ctx, uint8_t reg, int16_t *data_out)
IR Sense 4 read word function.
err_t irsense4_read_reg(irsense4_t *ctx, uint8_t reg, uint8_t *data_out)
IR Sense 4 read register function.
void irsense4_cfg_setup(irsense4_cfg_t *cfg)
IR Sense 4 configuration object setup function.
err_t irsense4_get_obj_temperature(irsense4_t *ctx, float *temperature)
IR Sense 4 get the object temperature function.
void irsense4_drv_interface_selection(irsense4_cfg_t *cfg, irsense4_drv_t drv_sel)
IR Sense 4 driver interface setup function.
err_t irsense4_config_int_signal(irsense4_t *ctx, uint8_t int_sr)
IR Sense 4 configur interrupt the signal function.
err_t irsense4_generic_write(irsense4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
IR Sense 4 data writing function.
err_t irsense4_get_status(irsense4_t *ctx, uint8_t *status)
IR Sense 4 get status function.
err_t irsense4_wait_new_data_ready(irsense4_t *ctx)
IR Sense 4 wait new data ready function.
err_t irsense4_write_emb_reg(irsense4_t *ctx, uint8_t reg_emb, uint8_t data_in)
IR Sense 4 write the embedded register function.
err_t irsense4_get_amb_temperature(irsense4_t *ctx, float *temperature)
IR Sense 4 get the ambient temperature function.
err_t irsense4_get_presence_data(irsense4_t *ctx, int16_t *presence)
IR Sense 4 get the presence detection data function.
struct irsense4_s irsense4_t
IR Sense 4 Click context object.
irsense4_return_value_t
IR Sense 4 Click return value data.
Definition irsense4.h:425
@ IRSENSE4_OK
Definition irsense4.h:426
@ IRSENSE4_ERROR
Definition irsense4.h:427
irsense4_ths_sel_t
IR Sense 4 Click threshold selection data value for detection algorithm.
Definition irsense4.h:436
@ IRSENSE4_THS_PRESENCE
Definition irsense4.h:437
@ IRSENSE4_THS_MOTION
Definition irsense4.h:438
@ IRSENSE4_THS_TAMB_SHOCK
Definition irsense4.h:439
err_t(* irsense4_master_io_t)(struct irsense4_s *, uint8_t, uint8_t *, uint8_t)
IR Sense 4 Click driver interface.
Definition irsense4.h:373
irsense4_drv_t
IR Sense 4 Click driver selector.
Definition irsense4.h:363
@ IRSENSE4_DRV_SEL_SPI
Definition irsense4.h:364
@ IRSENSE4_DRV_SEL_I2C
Definition irsense4.h:365
This file contains SPI specific macros, functions, etc.
IR Sense 4 Click configuration object.
Definition irsense4.h:400
uint32_t i2c_speed
Definition irsense4.h:409
spi_master_chip_select_polarity_t cs_polarity
Definition irsense4.h:414
pin_name_t sck
Definition irsense4.h:405
spi_master_mode_t spi_mode
Definition irsense4.h:413
irsense4_drv_t drv_sel
Definition irsense4.h:416
pin_name_t mosi
Definition irsense4.h:404
uint32_t spi_speed
Definition irsense4.h:412
pin_name_t scl
Definition irsense4.h:401
pin_name_t int_pin
Definition irsense4.h:407
pin_name_t miso
Definition irsense4.h:403
pin_name_t sda
Definition irsense4.h:402
pin_name_t cs
Definition irsense4.h:406
uint8_t i2c_address
Definition irsense4.h:410
IR Sense 4 Click context object.
Definition irsense4.h:380
irsense4_master_io_t read_f
Definition irsense4.h:391
spi_master_t spi
Definition irsense4.h:384
irsense4_master_io_t write_f
Definition irsense4.h:390
digital_in_t int_pin
Definition irsense4.h:381
i2c_master_t i2c
Definition irsense4.h:383
irsense4_drv_t drv_sel
Definition irsense4.h:388
uint8_t slave_address
Definition irsense4.h:386
pin_name_t chip_select
Definition irsense4.h:387