irsense 2.0.0.0
irsense.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 IRSENSE_H
36#define IRSENSE_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 IRSENSE_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 cfg.pdn = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
64#define IRSENSE_RETVAL uint8_t
65
66#define IRSENSE_OK 0x00
67#define IRSENSE_INIT_ERROR 0xFF
74#define IRSENSE_I2C_ADDRESS_0 0x64
75#define IRSENSE_I2C_ADDRESS_1 0x65
76#define IRSENSE_I2C_ADDRESS_2 0x66
83#define IRSENSE_REG_WIA1 0x00
84#define IRSENSE_REG_WIA2 0x01
85#define IRSENSE_REG_INFO1 0x02
86#define IRSENSE_REG_INFO2 0x03
87#define IRSENSE_REG_INTST 0x04
88#define IRSENSE_REG_ST1 0x05
89#define IRSENSE_REG_IR1_LOW 0x06
90#define IRSENSE_REG_IR1_HIGH 0x07
91#define IRSENSE_REG_IR2_LOW 0x08
92#define IRSENSE_REG_IR2_HIGH 0x09
93#define IRSENSE_REG_IR3_LOW 0x0A
94#define IRSENSE_REG_IR3_HIGH 0x0B
95#define IRSENSE_REG_IR4_LOW 0x0C
96#define IRSENSE_REG_IR4_HIGH 0x0D
97#define IRSENSE_REG_TMP_LOW 0x0E
98#define IRSENSE_REG_TMP_HIGH 0x0F
99#define IRSENSE_REG_ST2 0x10
100#define IRSENSE_REG_ETH13H_LOW 0x11
101#define IRSENSE_REG_ETH13H_HIGH 0x12
102#define IRSENSE_REG_ETH13L_LOW 0x13
103#define IRSENSE_REG_ETH13L_HIGH 0x14
104#define IRSENSE_REG_ETH24H_LOW 0x15
105#define IRSENSE_REG_ETH24H_HIGH 0x16
106#define IRSENSE_REG_ETH24L_LOW 0x17
107#define IRSENSE_REG_ETH24L_HIGH 0x18
108#define IRSENSE_REG_EHYS13 0x19
109#define IRSENSE_REG_EHYS24 0x1A
110#define IRSENSE_REG_EINTEN 0x1B
111#define IRSENSE_REG_ECNTL1 0x1C
112#define IRSENSE_REG_CNTL2 0x1D
119#define IRSENSE_EEPROM_MAP_EKEY 0x50
120#define IRSENSE_EEPROM_MAP_ETH13H_LOW 0x51
121#define IRSENSE_EEPROM_MAP_ETH13H_HIGH 0x52
122#define IRSENSE_EEPROM_MAP_ETH13L_LOW 0x53
123#define IRSENSE_EEPROM_MAP_ETH13L_HIGH 0x54
124#define IRSENSE_EEPROM_MAP_ETH24H_LOW 0x55
125#define IRSENSE_EEPROM_MAP_ETH24H_HIGH 0x56
126#define IRSENSE_EEPROM_MAP_ETH24L_LOW 0x57
127#define IRSENSE_EEPROM_MAP_ETH24L_HIGH 0x58
128#define IRSENSE_EEPROM_MAP_EHYS13 0x59
129#define IRSENSE_EEPROM_MAP_EHYS24 0x5A
130#define IRSENSE_EEPROM_MAP_EINTEN 0x5B
131#define IRSENSE_EEPROM_MAP_ECNTL1 0x5C
138#define IRSENSE_ECNTL1_MODE_STAND_BY 0x00
139#define IRSENSE_ECNTL1_MODE_EEPROM_ACCESS 0x01
140#define IRSENSE_ECNTL1_MODE_SINGLE_SHOT 0x02
141#define IRSENSE_ECNTL1_MODE_BE_PROHIBITED 0x03
142#define IRSENSE_ECNTL1_MODE_CONTINUOUS_0 0x04
143#define IRSENSE_ECNTL1_MODE_CONTINUOUS_1 0x05
144#define IRSENSE_ECNTL1_MODE_CONTINUOUS_2 0x06
145#define IRSENSE_ECNTL1_MODE_CONTINUOUS_3 0x07
146#define IRSENSE_ECNTL1_CUTOFF_FREQUENCY_0_3_Hz 0x00
147#define IRSENSE_ECNTL1_CUTOFF_FREQUENCY_0_6_Hz 0x08
148#define IRSENSE_ECNTL1_CUTOFF_FREQUENCY_1_1_Hz 0x10
149#define IRSENSE_ECNTL1_CUTOFF_FREQUENCY_2_2_Hz 0x18
150#define IRSENSE_ECNTL1_CUTOFF_FREQUENCY_4_4_Hz 0x20
151#define IRSENSE_ECNTL1_CUTOFF_FREQUENCY_8_8_Hz 0x28
158#define IRSENSE_EINTEN_IR13_HIGH_INT_DISABLE 0x00
159#define IRSENSE_EINTEN_IR13_HIGH_INT_ENABLE 0x01
160#define IRSENSE_EINTEN_IR13_LOW_INT_DISABLE 0x00
161#define IRSENSE_EINTEN_IR13_LOW_INT_ENABLE 0x01
162#define IRSENSE_EINTEN_IR24_HIGH_INT_DISABLE 0x00
163#define IRSENSE_EINTEN_IR24_HIGH_INT_ENABLE 0x01
164#define IRSENSE_EINTEN_IR24_LOW_INT_DISABLE 0x00
165#define IRSENSE_EINTEN_IR24_LOW_INT_ENABLE 0x01
166#define IRSENSE_EINTEN_DRI_INT_DISABLE 0x00
167#define IRSENSE_EINTEN_DRI_INT_ENABLE 0x01
168
169#define IRSENSE_CNTL2_SOFT_RESET 0x01
170#define IRSENSE_EEPROM_MAP_VAL_EKEY 0xA5
171#define IRSENSE_ENABLE_SETTINGS_EEPROM_MODE 0x38
172#define IRSENSE_ENABLE_EEPROM_MODE 0xC1
173#define IRSENSE_EINTEN_RESET_VALUE 0xC0 // End group macro
177// --------------------------------------------------------------- PUBLIC TYPES
186typedef struct
187{
188 // Output pins
189
190 digital_out_t pdn;
191
192 // Input pins
193
194 digital_in_t int_pin;
195
196 // Modules
197
198 i2c_master_t i2c;
199
200 // ctx variable
201
203
204} irsense_t;
205
209typedef struct
210{
211 int16_t bottom_area;
212 int16_t left_area;
213 int16_t right_area;
214 int16_t top_area;
215
217
221typedef struct
222{
223 uint8_t ir13h;
224 uint8_t ir13l;
225 uint8_t ir24h;
226 uint8_t ir24l;
227 uint8_t dr;
229
233 typedef struct
234{
235 uint16_t eth24h;
236 uint16_t eth24l;
237 uint16_t eth13h;
238 uint16_t eth13l;
240
244 typedef struct
245{
246 uint16_t eeth24h;
247 uint16_t eeth24l;
248 uint16_t eeth13h;
249 uint16_t eeth13l;
251
255typedef struct
256{
257 // Communication gpio pins
258
259 pin_name_t scl;
260 pin_name_t sda;
261
262 // Additional gpio pins
263
264 pin_name_t pdn;
265 pin_name_t int_pin;
266
267 // static variable
268
269 uint32_t i2c_speed;
270 uint8_t i2c_address;
271
273 // End types group
275// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
276
282#ifdef __cplusplus
283extern "C"{
284#endif
285
295
304
315void irsense_generic_write ( irsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
316
328void irsense_generic_read ( irsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
329
341 void irsense_write_byte ( irsense_t *ctx, uint8_t reg_address, uint8_t write_data );
342
353 uint8_t irsense_read_byte ( irsense_t *ctx, uint8_t reg_address );
354
365 uint16_t irsense_read_data ( irsense_t *ctx, uint8_t reg_address_low );
366
377
388
399
410
441
461
494 void irsense_set_configuration ( irsense_t *ctx, uint8_t register_value );
495
514 void irsense_set_mode ( irsense_t *ctx, uint8_t mode );
515
534 void irsense_set_cutoff_frequency ( irsense_t *ctx, uint8_t frequency );
535
551
568
579
590
604 int16_t irsense_get_ir1 ( irsense_t *ctx );
605
619 int16_t irsense_get_ir2 ( irsense_t *ctx );
620
634 int16_t irsense_get_ir3 ( irsense_t *ctx );
635
649 int16_t irsense_get_ir4 ( irsense_t *ctx );
650
667
683
699
711 void irsense_set_threshold_ir2_ir4 ( irsense_t *ctx, uint8_t value );
712
728
741
753 void irsense_set_threshold_ir1_ir3 ( irsense_t *ctx, uint8_t value );
754
769
782
795
812
824 void irsense_set_hysteresis_ir2_ir4 ( irsense_t *ctx, uint8_t value );
825
838
850 void irsense_set_hysteresis_ir1_ir3 ( irsense_t *ctx, uint8_t value );
851
864
877 void irsense_read_hysteresis ( irsense_t *ctx, uint8_t *ehys24, uint8_t *ehys13 );
878
891 void irsense_read_hysteresis_eeprom ( irsense_t *ctx, uint8_t *eehys24, uint8_t *eehys13 );
892
905
917
933
934
935#ifdef __cplusplus
936}
937#endif
938#endif // _IRSENSE_H_
939 // End public_function group
942
943// ------------------------------------------------------------------------- END
#define IRSENSE_RETVAL
Definition: irsense.h:64
uint8_t irsense_read_interrupt_status(irsense_t *ctx)
Get interrupts activate or inactivate corresponding status value function.
void irsense_set_configuration(irsense_t *ctx, uint8_t register_value)
Set configuration function.
uint8_t irsense_read_byte(irsense_t *ctx, uint8_t reg_address)
Generic read the byte of data function.
uint16_t irsense_get_threshold_ir1_ir3(irsense_t *ctx)
Get threshold value for channel 1 and channel 3 ( Ir1-Ir3 ) function.
void irsense_read_threshold(irsense_t *ctx, irsense_reg_t *reg)
Get threshold value for all channels function.
void irsense_write_byte(irsense_t *ctx, uint8_t reg_address, uint8_t write_data)
Generic write the byte of data function.
void irsense_set_threshold_eeprom_ir2_ir4(irsense_t *ctx, uint8_t value)
Set high or low EEPROM threshold for channel 2 and channel 4 ( Ir2-Ir4 ) function.
void irsense_get_ir_sense(irsense_t *ctx, irsense_ir_data_t *ir_data)
Get value of sensor all channels function.
int16_t irsense_get_ir3(irsense_t *ctx)
Get value of sensor channel 3 function.
void irsense_set_hysteresis_eeprom_ir1_ir3(irsense_t *ctx, uint8_t value)
Set hysteresis EEPROM setting of threshold level for channel 1 and channel 3 ( Ir1-Ir3 ) function.
uint16_t irsense_get_threshold_ir2_ir4(irsense_t *ctx)
Get threshold value for channel 2 and channel 4 ( Ir2-Ir4 ) function.
void irsense_set_threshold_eeprom_ir1_ir3(irsense_t *ctx, uint8_t value)
Set high or low EEPROM threshold for channel 1 and channel 3 ( Ir1-Ir3 ) function.
uint8_t irsense_get_status(irsense_t *ctx)
Get status value function.
void irsense_generic_read(irsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void irsense_set_threshold_ir1_ir3(irsense_t *ctx, uint8_t value)
Set high or low threshold for channel 1 and channel 3 ( Ir1-Ir3 ) function.
void irsense_soft_reset(irsense_t *ctx)
Soft reset function.
void irsense_generic_write(irsense_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t irsense_check_int_states(irsense_t *ctx)
Check state of INT pin function.
int16_t irsense_get_ir4(irsense_t *ctx)
Get value of sensor channel 4 function.
void irsense_cfg_setup(irsense_cfg_t *cfg)
Config Object Initialization function.
void irsense_set_hysteresis_ir1_ir3(irsense_t *ctx, uint8_t value)
Set hysteresis setting of threshold level for channel 1 and channel 3 ( Ir1-Ir3 ) function.
void irsense_set_hysteresis_ir2_ir4(irsense_t *ctx, uint8_t value)
Set hysteresis setting of threshold level for channel 2 and channel 4 ( Ir2-Ir4 ) function.
void irsense_set_threshold_ir2_ir4(irsense_t *ctx, uint8_t value)
Set high or low threshold for channel 2 and channel 4 ( Ir2-Ir4 ) function.
void irsense_set_cutoff_frequency(irsense_t *ctx, uint8_t frequency)
Set the cutoff frequency function.
int16_t irsense_get_ir1(irsense_t *ctx)
Get value of sensor channel 1 function.
uint16_t irsense_read_data(irsense_t *ctx, uint8_t reg_address_low)
Generic read 16-bit of data function.
void irsense_enable_data_ready_interrupt(irsense_t *ctx)
Sets interrupts source settings function.
void irsense_set_interrupts_reg(irsense_t *ctx, irsense_eint_t *eint)
Sets interrupts activate or inactivate corresponding function.
void irsense_set_mode(irsense_t *ctx, uint8_t mode)
Set the mode function.
uint8_t irsense_get_company_code(irsense_t *ctx)
Get company code function.
int16_t irsense_get_ir2(irsense_t *ctx)
Get value of sensor channel 2 function.
void irsense_read_threshold_eeprom(irsense_t *ctx, irsense_eeprom_t *eeprom)
Get threshold EEPROM value for all channels function.
uint8_t irsense_check_overrun(irsense_t *ctx)
Checks to see if data overrun flag is set in the status register function.
void irsense_read_hysteresis(irsense_t *ctx, uint8_t *ehys24, uint8_t *ehys13)
Get Hysteresis value for all channes function.
IRSENSE_RETVAL irsense_init(irsense_t *ctx, irsense_cfg_t *cfg)
Initialization function.
float irsense_get_temperature(irsense_t *ctx)
Get the temperature in degrees Celsius function.
float irsense_get_temperature_f(irsense_t *ctx)
Get the temperature in Fahrenheit degrees function.
uint8_t irsense_get_device_id(irsense_t *ctx)
Get device ID function.
void irsense_set_hysteresis_eeprom_ir2_ir4(irsense_t *ctx, uint8_t value)
Set hysteresis EEPROM setting of threshold level for channel 2 and channel 4 ( Ir2-Ir4 ) function.
void irsense_read_hysteresis_eeprom(irsense_t *ctx, uint8_t *eehys24, uint8_t *eehys13)
Get Hysteresis EEPROM value for all channes function.
void irsense_refresh(irsense_t *ctx)
Refresh by read dummy data function.
void irsense_power_on(irsense_t *ctx)
Enable the sensor function.
void irsense_power_off(irsense_t *ctx)
Disable the sensor function.
uint8_t irsense_check_available(irsense_t *ctx)
Checks to see if DRDY flag is set in the status register function.
Click configuration structure definition.
Definition: irsense.h:256
uint32_t i2c_speed
Definition: irsense.h:269
pin_name_t pdn
Definition: irsense.h:264
pin_name_t scl
Definition: irsense.h:259
pin_name_t int_pin
Definition: irsense.h:265
pin_name_t sda
Definition: irsense.h:260
uint8_t i2c_address
Definition: irsense.h:270
EEPROM map structure definition.
Definition: irsense.h:245
uint16_t eeth13l
Definition: irsense.h:249
uint16_t eeth13h
Definition: irsense.h:248
uint16_t eeth24h
Definition: irsense.h:246
uint16_t eeth24l
Definition: irsense.h:247
Enable interrupt structure definition.
Definition: irsense.h:222
uint8_t ir24l
Definition: irsense.h:226
uint8_t ir24h
Definition: irsense.h:225
uint8_t dr
Definition: irsense.h:227
uint8_t ir13h
Definition: irsense.h:223
uint8_t ir13l
Definition: irsense.h:224
IR data structure definition.
Definition: irsense.h:210
int16_t top_area
Definition: irsense.h:214
int16_t left_area
Definition: irsense.h:212
int16_t right_area
Definition: irsense.h:213
int16_t bottom_area
Definition: irsense.h:211
Register address structure definition.
Definition: irsense.h:234
uint16_t eth13l
Definition: irsense.h:238
uint16_t eth13h
Definition: irsense.h:237
uint16_t eth24h
Definition: irsense.h:235
uint16_t eth24l
Definition: irsense.h:236
Click ctx object definition.
Definition: irsense.h:187
digital_out_t pdn
Definition: irsense.h:190
digital_in_t int_pin
Definition: irsense.h:194
i2c_master_t i2c
Definition: irsense.h:198
uint8_t slave_address
Definition: irsense.h:202