Go to the documentation of this file.
35 #include "mikrosdk_version.h"
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
72 #define IRSENSE4_REG_LPF1 0x0C
73 #define IRSENSE4_REG_LPF2 0x0D
74 #define IRSENSE4_REG_WHO_AM_I 0x0F
75 #define IRSENSE4_REG_AVG_TRIM 0x10
76 #define IRSENSE4_REG_CTRL0 0x17
77 #define IRSENSE4_REG_SENS_DATA 0x1D
78 #define IRSENSE4_REG_CTRL1 0x20
79 #define IRSENSE4_REG_CTRL2 0x21
80 #define IRSENSE4_REG_CTRL3 0x22
81 #define IRSENSE4_REG_STATUS 0x23
82 #define IRSENSE4_REG_FUNC_STATUS 0x25
83 #define IRSENSE4_REG_TOBJECT_L 0x26
84 #define IRSENSE4_REG_TOBJECT_H 0x27
85 #define IRSENSE4_REG_TAMBIENT_L 0x28
86 #define IRSENSE4_REG_TAMBIENT_H 0x29
87 #define IRSENSE4_REG_TOBJ_COMP_L 0x38
88 #define IRSENSE4_REG_TOBJ_COMP_H 0x39
89 #define IRSENSE4_REG_TPRESENCE_L 0x3A
90 #define IRSENSE4_REG_TPRESENCE_H 0x3B
91 #define IRSENSE4_REG_TMOTION_L 0x3C
92 #define IRSENSE4_REG_TMOTION_H 0x3D
93 #define IRSENSE4_REG_TAMB_SHOCK_L 0x3E
94 #define IRSENSE4_REG_TAMB_SHOCK_H 0x3F
100 #define IRSENSE4_REG_EMB_FUNC_CFG_ADDR 0x08
101 #define IRSENSE4_REG_EMB_FUNC_CFG_DATA 0x09
102 #define IRSENSE4_REG_EMB_PAGE_RW 0x11
103 #define IRSENSE4_REG_EMB_PRESENCE_THS_L 0x20
104 #define IRSENSE4_REG_EMB_PRESENCE_THS_H 0x21
105 #define IRSENSE4_REG_EMB_MOTION_THS_L 0x22
106 #define IRSENSE4_REG_EMB_MOTION_THS_H 0x23
107 #define IRSENSE4_REG_EMB_TAMB_SHOCK_THS_L 0x24
108 #define IRSENSE4_REG_EMB_TAMB_SHOCK_THS_H 0x25
109 #define IRSENSE4_REG_EMB_HYST_MOTION 0x26
110 #define IRSENSE4_REG_EMB_HYST_PRESENCE 0x27
111 #define IRSENSE4_REG_EMB_ALGO_CONFIG 0x28
112 #define IRSENSE4_REG_EMB_HYST_TAMB_SHOCK 0x29
113 #define IRSENSE4_REG_EMB_RESET_ALGO 0x2A
132 #define IRSENSE4_LPF1_M_ODR_9 0x00
133 #define IRSENSE4_LPF1_M_ODR_20 0x01
134 #define IRSENSE4_LPF1_M_ODR_50 0x02
135 #define IRSENSE4_LPF1_M_ODR_100 0x03
136 #define IRSENSE4_LPF1_M_ODR_200 0x04
137 #define IRSENSE4_LPF1_M_ODR_400 0x05
138 #define IRSENSE4_LPF1_M_ODR_800 0x06
139 #define IRSENSE4_LPF1_M_BIT_MASK 0x07
140 #define IRSENSE4_LPF1_P_M_ODR_9 0x00
141 #define IRSENSE4_LPF1_P_M_ODR_20 0x08
142 #define IRSENSE4_LPF1_P_M_ODR_50 0x10
143 #define IRSENSE4_LPF1_P_M_ODR_100 0x18
144 #define IRSENSE4_LPF1_P_M_ODR_200 0x20
145 #define IRSENSE4_LPF1_P_M_ODR_400 0x28
146 #define IRSENSE4_LPF1_P_M_ODR_800 0x30
154 #define IRSENSE4_LPF2_A_T_ODR_9 0x00
155 #define IRSENSE4_LPF2_A_T_ODR_20 0x01
156 #define IRSENSE4_LPF2_A_T_ODR_50 0x02
157 #define IRSENSE4_LPF2_A_T_ODR_100 0x03
158 #define IRSENSE4_LPF2_A_T_ODR_200 0x04
159 #define IRSENSE4_LPF2_A_T_ODR_400 0x05
160 #define IRSENSE4_LPF2_A_T_ODR_800 0x06
161 #define IRSENSE4_LPF2_A_T_BIT_MASK 0x07
162 #define IRSENSE4_LPF2_P_ODR_9 0x00
163 #define IRSENSE4_LPF2_P_ODR_20 0x08
164 #define IRSENSE4_LPF2_P_ODR_50 0x10
165 #define IRSENSE4_LPF2_P_ODR_100 0x18
166 #define IRSENSE4_LPF2_P_ODR_200 0x20
167 #define IRSENSE4_LPF2_P_ODR_400 0x28
168 #define IRSENSE4_LPF2_P_ODR_800 0x30
169 #define IRSENSE4_LPF2_P_BIT_MASK 0x38
176 #define IRSENSE4_DEVICE_ID 0xD3
184 #define IRSENSE4_AVG_TRIM_TMOS_2 0x00
185 #define IRSENSE4_AVG_TRIM_TMOS_8 0x01
186 #define IRSENSE4_AVG_TRIM_TMOS_32 0x02
187 #define IRSENSE4_AVG_TRIM_TMOS_128 0x03
188 #define IRSENSE4_AVG_TRIM_TMOS_256 0x04
189 #define IRSENSE4_AVG_TRIM_TMOS_512 0x05
190 #define IRSENSE4_AVG_TRIM_TMOS_1024 0x06
191 #define IRSENSE4_AVG_TRIM_TMOS_2048 0x07
192 #define IRSENSE4_AVG_TRIM_TMOS_BIT_MASK 0x07
193 #define IRSENSE4_AVG_TRIM_T_8 0x00
194 #define IRSENSE4_AVG_TRIM_T_4 0x10
195 #define IRSENSE4_AVG_TRIM_T_2 0x20
196 #define IRSENSE4_AVG_TRIM_T_1 0x30
197 #define IRSENSE4_AVG_TRIM_T_BIT_MASK 0x30
203 #define IRSENSE4_CTRL0_GAIN_1 0x00
204 #define IRSENSE4_CTRL0_GAIN_2 0x10
205 #define IRSENSE4_CTRL0_GAIN_3 0x20
206 #define IRSENSE4_CTRL0_GAIN_4 0x30
207 #define IRSENSE4_CTRL0_GAIN_5 0x40
208 #define IRSENSE4_CTRL0_GAIN_6 0x50
209 #define IRSENSE4_CTRL0_GAIN_7 0x60
210 #define IRSENSE4_CTRL0_GAIN_8 0x70
211 #define IRSENSE4_CTRL0_DEFAULT 0x81
218 #define IRSENSE4_SENS_DATA_CALC_DEV 16u
219 #define IRSENSE4_SENS_DATA_MIN 2048u
220 #define IRSENSE4_SENS_DATA_MAX 6128u
227 #define IRSENSE4_CTRL1_ODR_POWER_DOWN 0x00
228 #define IRSENSE4_CTRL1_ODR_0_25 0x01
229 #define IRSENSE4_CTRL1_ODR_0_5 0x02
230 #define IRSENSE4_CTRL1_ODR_1 0x03
231 #define IRSENSE4_CTRL1_ODR_2 0x04
232 #define IRSENSE4_CTRL1_ODR_4 0x05
233 #define IRSENSE4_CTRL1_ODR_8 0x06
234 #define IRSENSE4_CTRL1_ODR_15 0x07
235 #define IRSENSE4_CTRL1_ODR_30 0x08
236 #define IRSENSE4_CTRL1_ODR_BIT_MASK 0x0F
237 #define IRSENSE4_CTRL1_BDU_DIS 0x00
238 #define IRSENSE4_CTRL1_BDU_EN 0x01
244 #define IRSENSE4_CTRL2_ONE_SHOT_DIS 0x00
245 #define IRSENSE4_CTRL2_ONE_SHOT_EN 0x01
246 #define IRSENSE4_CTRL2_F_CFG_ACCESS_DIS 0x00
247 #define IRSENSE4_CTRL2_F_CFG_ACCESS_EN 0x10
253 #define IRSENSE4_CTRL3_IEN_HIGH_Z 0x00
254 #define IRSENSE4_CTRL3_IEN_DRDY 0x01
255 #define IRSENSE4_CTRL3_IEN_INT_OR 0x02
256 #define IRSENSE4_CTRL3_IEN_BIT_MASK 0x03
257 #define IRSENSE4_CTRL3_INT_LATCHED_PLS 0x00
258 #define IRSENSE4_CTRL3_INT_LATCHED_LAT 0x04
259 #define IRSENSE4_CTRL3_INT_MSK_T_SHOCK 0x08
260 #define IRSENSE4_CTRL3_INT_MSK_MOT 0x10
261 #define IRSENSE4_CTRL3_INT_MSK_PRES 0x20
262 #define IRSENSE4_CTRL3_PP_OD_PUSH_PULL 0x00
263 #define IRSENSE4_CTRL3_PP_OD_OPEN_DRAIN 0x04
264 #define IRSENSE4_CTRL3_INT_H_L_HIGH 0x00
265 #define IRSENSE4_CTRL3_INT_H_L_LOW 0x80
266 #define IRSENSE4_CTRL3_BIT_MASK 0x38
272 #define IRSENSE4_STATUS_TAMB_SHOCK_FLAG 0x01
273 #define IRSENSE4_STATUS_MOT_FLAG 0x02
274 #define IRSENSE4_STATUS_PRES_FLAG 0x04
275 #define IRSENSE4_STATUS_DETECT_FLAG 0x07
276 #define IRSENSE4_STATUS_NOT_DRDY 0x00
277 #define IRSENSE4_STATUS_DRDY 0x04
284 #define IRSENSE4_SET_THS_PRESENCE_DEFAULT 5000u
285 #define IRSENSE4_SET_THS_MOTION_DEFAULT 3000u
286 #define IRSENSE4_SET_THS_T_SHOCK_DEFAULT 2000u
287 #define IRSENSE4_SET_THS_MAX 0x7FFFu
294 #define IRSENSE4_SENS_TOBJECT 2000.0f
295 #define IRSENSE4_SENS_TAMBIENT 100.0f
296 #define IRSENSE4_SENS_TOBJ_COMP 2000.0f
303 #define IRSENSE4_EMB_PAGE_RW_READ_DIS 0x00
304 #define IRSENSE4_EMB_PAGE_RW_READ_EN 0x20
305 #define IRSENSE4_EMB_PAGE_RW_WRITE_DIS 0x00
306 #define IRSENSE4_EMB_PAGE_RW_WRITE_EN 0x40
313 #define IRSENSE4_DEVICE_ADDRESS 0x5A
323 #define IRSENSE4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
324 #define IRSENSE4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
342 #define IRSENSE4_MAP_MIKROBUS( cfg, mikrobus ) \
343 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
344 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
345 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
346 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
347 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
348 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
349 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
@ IRSENSE4_THS_TAMB_SHOCK
Definition: irsense4.h:435
err_t irsense4_set_lp_filter_presence(irsense4_t *ctx, uint8_t lpf_p)
IR Sense 4 set low-pass filter for presence function.
spi_master_chip_select_polarity_t cs_polarity
Definition: irsense4.h:410
uint8_t i2c_address
Definition: irsense4.h:406
err_t irsense4_set_sens_data(irsense4_t *ctx, uint16_t sens)
IR Sense 4 set sensitivity data function.
err_t irsense4_get_presence_data(irsense4_t *ctx, int16_t *presence)
IR Sense 4 get the presence detection data function.
pin_name_t sda
Definition: irsense4.h:398
err_t irsense4_init(irsense4_t *ctx, irsense4_cfg_t *cfg)
IR Sense 4 initialization function.
@ IRSENSE4_OK
Definition: irsense4.h:422
err_t irsense4_config_odr(irsense4_t *ctx, uint8_t odr)
IR Sense 4 set output data rate function.
pin_name_t scl
Definition: irsense4.h:397
irsense4_drv_t
IR Sense 4 Click driver selector.
Definition: irsense4.h:359
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_generic_write(irsense4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
IR Sense 4 data writing function.
IR Sense 4 Click context object.
Definition: irsense4.h:376
This file contains SPI specific macros, functions, etc.
irsense4_drv_t drv_sel
Definition: irsense4.h:384
err_t irsense4_read_emb_reg(irsense4_t *ctx, uint8_t reg_emb, uint8_t *data_out)
IR Sense 4 write register function.
irsense4_master_io_t read_f
Definition: irsense4.h:387
err_t irsense4_wait_new_data_ready(irsense4_t *ctx)
IR Sense 4 wait new data ready function.
IR Sense 4 Click configuration object.
Definition: irsense4.h:396
err_t irsense4_get_amb_temperature(irsense4_t *ctx, float *temperature)
IR Sense 4 get the ambient temperature 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_default_cfg(irsense4_t *ctx)
IR Sense 4 default configuration function.
@ IRSENSE4_ERROR
Definition: irsense4.h:423
irsense4_drv_t drv_sel
Definition: irsense4.h:412
@ IRSENSE4_DRV_SEL_SPI
Definition: irsense4.h:360
err_t irsense4_write_reg(irsense4_t *ctx, uint8_t reg, uint8_t data_in)
IR Sense 4 write register function.
err_t irsense4_get_obj_temperature(irsense4_t *ctx, float *temperature)
IR Sense 4 get the object 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_threshold(irsense4_t *ctx, irsense4_ths_sel_t ths_sel, uint16_t *threshold)
IR Sense 4 get the threshold data function.
pin_name_t chip_select
Definition: irsense4.h:383
pin_name_t sck
Definition: irsense4.h:401
void irsense4_cfg_setup(irsense4_cfg_t *cfg)
IR Sense 4 configuration object setup function.
err_t irsense4_set_gain_mode(irsense4_t *ctx, uint8_t gain_mode)
IR Sense 4 set gain mode function.
pin_name_t int_pin
Definition: irsense4.h:403
spi_master_t spi
Definition: irsense4.h:380
irsense4_master_io_t write_f
Definition: irsense4.h:386
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_get_comp_temperature(irsense4_t *ctx, float *temperature)
IR Sense 4 get the compensated temperature function.
spi_master_mode_t spi_mode
Definition: irsense4.h:409
i2c_master_t i2c
Definition: irsense4.h:379
err_t irsense4_generic_read(irsense4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
IR Sense 4 data reading function.
pin_name_t miso
Definition: irsense4.h:399
err_t irsense4_read_word(irsense4_t *ctx, uint8_t reg, int16_t *data_out)
IR Sense 4 read word function.
uint32_t i2c_speed
Definition: irsense4.h:405
uint32_t spi_speed
Definition: irsense4.h:408
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_get_status(irsense4_t *ctx, uint8_t *status)
IR Sense 4 get status function.
err_t irsense4_enable_one_shot(irsense4_t *ctx)
IR Sense 4 enable one-shot mode function.
irsense4_ths_sel_t
IR Sense 4 Click threshold selection data value for detection algorithm.
Definition: irsense4.h:432
err_t(* irsense4_master_io_t)(struct irsense4_s *, uint8_t, uint8_t *, uint8_t)
IR Sense 4 Click driver interface.
Definition: irsense4.h:369
digital_in_t int_pin
Definition: irsense4.h:377
uint8_t slave_address
Definition: irsense4.h:382
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.
@ IRSENSE4_THS_PRESENCE
Definition: irsense4.h:433
irsense4_return_value_t
IR Sense 4 Click return value data.
Definition: irsense4.h:421
err_t irsense4_get_device_id(irsense4_t *ctx, uint8_t *device_id)
IR Sense 4 get device ID function.
err_t irsense4_read_reg(irsense4_t *ctx, uint8_t reg, uint8_t *data_out)
IR Sense 4 read register function.
void irsense4_drv_interface_selection(irsense4_cfg_t *cfg, irsense4_drv_t drv_sel)
IR Sense 4 driver interface setup function.
@ IRSENSE4_DRV_SEL_I2C
Definition: irsense4.h:361
struct irsense4_s irsense4_t
IR Sense 4 Click context object.
pin_name_t mosi
Definition: irsense4.h:400
pin_name_t cs
Definition: irsense4.h:402
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_write_emb_reg(irsense4_t *ctx, uint8_t reg_emb, uint8_t data_in)
IR Sense 4 write the embedded register function.
@ IRSENSE4_THS_MOTION
Definition: irsense4.h:434
err_t irsense4_config_int_signal(irsense4_t *ctx, uint8_t int_sr)
IR Sense 4 configur interrupt the signal function.