irgesture  2.0.0.0
irgesture.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 IRGESTURE_H
36 #define IRGESTURE_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 IRGESTURE_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 )
57 
63 #define IRGESTURE_RETVAL uint8_t
64 
65 #define IRGESTURE_OK 0x00
66 #define IRGESTURE_INIT_ERROR 0xFF
67 
73 #define IRGESTURE_I2C_ADDR 0x39
74 
80 #define IRGESTURE_ENABLE 0x80
81 #define IRGESTURE_ATIME 0x81
82 #define IRGESTURE_WTIME 0x83
83 #define IRGESTURE_AILTL 0x84
84 #define IRGESTURE_AILTH 0x85
85 #define IRGESTURE_AIHTL 0x86
86 #define IRGESTURE_AIHTH 0x87
87 #define IRGESTURE_PILT 0x89
88 #define IRGESTURE_PIHT 0x8B
89 #define IRGESTURE_PERS 0x8C
90 #define IRGESTURE_CONFIG1 0x8D
91 #define IRGESTURE_PPULSE 0x8E
92 #define IRGESTURE_CONTROL 0x8F
93 #define IRGESTURE_CONFIG2 0x90
94 #define IRGESTURE_ID 0x92
95 #define IRGESTURE_STATUS 0x93
96 #define IRGESTURE_CDATAL 0x94
97 #define IRGESTURE_CDATAH 0x95
98 #define IRGESTURE_RDATAL 0x96
99 #define IRGESTURE_RDATAH 0x97
100 #define IRGESTURE_GDATAL 0x98
101 #define IRGESTURE_GDATAH 0x99
102 #define IRGESTURE_BDATAL 0x9A
103 #define IRGESTURE_BDATAH 0x9B
104 #define IRGESTURE_PDATA 0x9C
105 #define IRGESTURE_POFFSET_UR 0x9D
106 #define IRGESTURE_POFFSET_DL 0x9E
107 #define IRGESTURE_CONFIG3 0x9F
108 #define IRGESTURE_GPENTH 0xA0
109 #define IRGESTURE_GEXTH 0xA1
110 #define IRGESTURE_GCONF1 0xA2
111 #define IRGESTURE_GCONF2 0xA3
112 #define IRGESTURE_GOFFSET_U 0xA4
113 #define IRGESTURE_GOFFSET_D 0xA5
114 #define IRGESTURE_GOFFSET_L 0xA7
115 #define IRGESTURE_GOFFSET_R 0xA9
116 #define IRGESTURE_GPULSE 0xA6
117 #define IRGESTURE_GCONF3 0xAA
118 #define IRGESTURE_GCONF4 0xAB
119 #define IRGESTURE_GFLVL 0xAE
120 #define IRGESTURE_GSTATUS 0xAF
121 #define IRGESTURE_IFORCE 0xE4
122 #define IRGESTURE_PICLEAR 0xE5
123 #define IRGESTURE_CICLEAR 0xE6
124 #define IRGESTURE_AICLEAR 0xE7
125 #define IRGESTURE_GFIFO_U 0xFC
126 #define IRGESTURE_GFIFO_D 0xFD
127 #define IRGESTURE_GFIFO_L 0xFE
128 #define IRGESTURE_GFIFO_R 0xFF
129 
135 #define DEFAULT_ATIME 219
136 #define DEFAULT_WTIME 246
137 #define DEFAULT_PROX_PPULSE 0x87
138 #define DEFAULT_GESTURE_PPULSE 0x89
139 #define DEFAULT_POFFSET_UR 0
140 #define DEFAULT_POFFSET_DL 0
141 #define DEFAULT_CONFIG1 0x60
142 #define DEFAULT_LDRIVE 0
143 #define DEFAULT_PGAIN 2
144 #define DEFAULT_AGAIN 1
145 #define DEFAULT_PILT 0
146 #define DEFAULT_PIHT 50
147 #define DEFAULT_AILT 0xFFFF
148 #define DEFAULT_AIHT 0
149 #define DEFAULT_PERS 0x11
150 #define DEFAULT_CONFIG2 0x01
151 #define DEFAULT_CONFIG3 0
152 #define DEFAULT_GPENTH 40
153 #define DEFAULT_GEXTH 30
154 #define DEFAULT_GCONF1 0x40
155 #define DEFAULT_GGAIN 2
156 #define DEFAULT_GLDRIVE 0
157 #define DEFAULT_GWTIME 1
158 #define DEFAULT_GOFFSET 0
159 #define DEFAULT_GPULSE 0xC9
160 #define DEFAULT_GCONF3 0
161 #define DEFAULT_GIEN 0
162 
168 #define IRGESTURE_PON 0b00000001
169 #define IRGESTURE_AEN 0b00000010
170 #define IRGESTURE_PEN 0b00000100
171 #define IRGESTURE_WEN 0b00001000
172 #define IRGESTURE_AIEN 0b00010000
173 #define IRGESTURE_PIEN 0b00100000
174 #define IRGESTURE_GEN 0b01000000
175 #define IRGESTURE_GVALID 0b00000001
176 
182 #define IRGESTURE_FAR 0x00
183 #define IRGESTURE_RIGHT 0x01
184 #define IRGESTURE_LEFT 0x02
185 #define IRGESTURE_UP 0x03
186 #define IRGESTURE_DOWN 0x04
187 #define IRGESTURE_NEAR 0x05
188  // End group macro
190 // --------------------------------------------------------------- PUBLIC TYPES
199 typedef struct
200 {
201  // Input pins
202 
203  digital_in_t int_pin;
204 
205  // Modules
206 
207  i2c_master_t i2c;
208 
209  // ctx variable
210 
211  uint8_t slave_address;
212 
213 } irgesture_t;
214 
218 typedef struct
219 {
220  // Communication gpio pins
221 
222  pin_name_t scl;
223  pin_name_t sda;
224 
225  // Additional gpio pins
226 
227  pin_name_t int_pin;
228 
229  // static variable
230 
231  uint32_t i2c_speed;
232  uint8_t i2c_address;
233 
235 
236 typedef enum
237 {
241  ALL_STATE
242 
244 
248 typedef enum
249 {
257  DIR_ALL
258 
260 
264 typedef struct
265 {
266  uint8_t u_data[ 32 ];
267  uint8_t d_data[ 32 ];
268  uint8_t l_data[ 32 ];
269  uint8_t r_data[ 32 ];
270  uint8_t index;
271  uint8_t total_gestures;
272  uint8_t in_threshold;
273  uint8_t out_threshold;
274  uint16_t ud_delta;
275  uint16_t lr_delta;
276  uint16_t ud_count;
277  uint16_t lr_count;
278  uint16_t near_count;
279  uint16_t far_count;
282 
284  // End types group
286 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
287 
293 #ifdef __cplusplus
294 extern "C"{
295 #endif
296 
306 
315 
324 
334 void irgesture_write_data ( irgesture_t *ctx, uint8_t reg_addr, uint8_t write_data );
335 
347 uint8_t irgesture_read_data ( irgesture_t *ctx, uint8_t reg_addr );
348 
359 
375 
385 
395 
405 
415 void irgesture_set_ambient_light_gain ( irgesture_t *ctx, uint8_t gain_val );
416 
428 
439 
449 
461 
473 
485 
497 
515 void irgesture_set_led_boost ( irgesture_t *ctx, uint8_t boost );
516 
533 
546 
556 void irgesture_set_gesture_gain ( irgesture_t *ctx, uint8_t gain_val );
557 
569 
579 
589 
601 
611 void irgesture_set_proximity_gain ( irgesture_t *ctx, uint8_t gain_val );
612 
624 
634 
644 
664 
683 void irgesture_set_proxy_photo_mask ( irgesture_t *ctx, uint8_t mask );
684 
695 
696 
697 #ifdef __cplusplus
698 }
699 #endif
700 #endif // _IRGESTURE_H_
701  // End public_function group
704 
705 // ------------------------------------------------------------------------- END
irgesture_init
IRGESTURE_RETVAL irgesture_init(irgesture_t *ctx, irgesture_cfg_t *cfg)
Initialization function.
gesture_data_t::lr_delta
uint16_t lr_delta
Definition: irgesture.h:275
irgesture_t
Click ctx object definition.
Definition: irgesture.h:200
gesture_dir_t
gesture_dir_t
Direction definitions.
Definition: irgesture.h:249
irgesture_cfg_t
Click configuration structure definition.
Definition: irgesture.h:219
gesture_data_t::near_count
uint16_t near_count
Definition: irgesture.h:278
DIR_NONE
@ DIR_NONE
Definition: irgesture.h:250
irgesture_cfg_t::sda
pin_name_t sda
Definition: irgesture.h:223
gesture_data_t::motion
gesture_dir_t motion
Definition: irgesture.h:281
irgesture_set_proxy_photo_mask
void irgesture_set_proxy_photo_mask(irgesture_t *ctx, uint8_t mask)
Get the current mask for enabled/disabled proximity photodiodes function.
gesture_data_t::lr_count
uint16_t lr_count
Definition: irgesture.h:277
irgesture_disable_power
void irgesture_disable_power(irgesture_t *ctx)
Disable power sensor function.
gesture_data_t::ud_count
uint16_t ud_count
Definition: irgesture.h:276
irgesture_disable_proximity_sensor
void irgesture_disable_proximity_sensor(irgesture_t *ctx)
Disable specific proximity sensors function.
irgesture_get_proximity_gain
uint8_t irgesture_get_proximity_gain(irgesture_t *ctx)
Get gain for proximity function.
irgesture_disable_gesture_sensor
void irgesture_disable_gesture_sensor(irgesture_t *ctx)
Disable the gesture recognition engine function.
DIR_LEFT
@ DIR_LEFT
Definition: irgesture.h:251
DIR_NEAR
@ DIR_NEAR
Definition: irgesture.h:255
irgesture_read_red_light
uint16_t irgesture_read_red_light(irgesture_t *ctx)
Read RED light data function.
irgesture_get_ambient_light_gain
uint8_t irgesture_get_ambient_light_gain(irgesture_t *ctx)
Get gain for ambient light function.
DIR_DOWN
@ DIR_DOWN
Definition: irgesture.h:254
irgesture_read_blue_light
uint16_t irgesture_read_blue_light(irgesture_t *ctx)
Read BLUE light data function.
irgesture_set_proximity_gain
void irgesture_set_proximity_gain(irgesture_t *ctx, uint8_t gain_val)
Set gain for proximity function.
irgesture_default_cfg
void irgesture_default_cfg(irgesture_t *ctx)
Click Default Configuration function.
irgesture_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: irgesture.h:231
irgesture_set_led_boost
void irgesture_set_led_boost(irgesture_t *ctx, uint8_t boost)
Sets the LED current boost value function.
ALL_STATE
@ ALL_STATE
Definition: irgesture.h:241
gesture_data_t::far_count
uint16_t far_count
Definition: irgesture.h:279
irgesture_enable_power
void irgesture_enable_power(irgesture_t *ctx)
Enable power sensor function.
FAR_STATE
@ FAR_STATE
Definition: irgesture.h:240
NEAR_STATE
@ NEAR_STATE
Definition: irgesture.h:239
DIR_ALL
@ DIR_ALL
Definition: irgesture.h:257
irgesture_read_ambient_light
uint16_t irgesture_read_ambient_light(irgesture_t *ctx)
Read ambient light data function.
gesture_data_t
Container for gesture data.
Definition: irgesture.h:265
irgesture_cfg_t::scl
pin_name_t scl
Definition: irgesture.h:222
irgesture_t::int_pin
digital_in_t int_pin
Definition: irgesture.h:203
irgesture_set_gesture_mode
void irgesture_set_gesture_mode(irgesture_t *ctx)
Sets the gesture mode function.
irgesture_get_gesture_gain
uint8_t irgesture_get_gesture_gain(irgesture_t *ctx)
Get gain for gesture function.
irgesture_enable_gesture_sensor
void irgesture_enable_gesture_sensor(irgesture_t *ctx)
Starts the gesture recognition engine function.
irgesture_disable_light_sensor
void irgesture_disable_light_sensor(irgesture_t *ctx)
Disable specific ambient light sensors function.
DIR_RIGHT
@ DIR_RIGHT
Definition: irgesture.h:252
gesture_data_t::out_threshold
uint8_t out_threshold
Definition: irgesture.h:273
gesture_data_t::state
gesture_prox_t state
Definition: irgesture.h:280
gesture_data_t::in_threshold
uint8_t in_threshold
Definition: irgesture.h:272
irgesture_get_proxy_photo_mask
uint8_t irgesture_get_proxy_photo_mask(irgesture_t *ctx)
Get the current mask for enabled/disabled proximity photodiodes function.
gesture_data_t::index
uint8_t index
Definition: irgesture.h:270
irgesture_t::i2c
i2c_master_t i2c
Definition: irgesture.h:207
irgesture_cfg_t::int_pin
pin_name_t int_pin
Definition: irgesture.h:227
irgesture_write_data
void irgesture_write_data(irgesture_t *ctx, uint8_t reg_addr, uint8_t write_data)
Write function.
IRGESTURE_RETVAL
#define IRGESTURE_RETVAL
Definition: irgesture.h:63
gesture_data_t::total_gestures
uint8_t total_gestures
Definition: irgesture.h:271
irgesture_enable_light_sensor
void irgesture_enable_light_sensor(irgesture_t *ctx)
Enable specific ambient light sensors function.
irgesture_t::slave_address
uint8_t slave_address
Definition: irgesture.h:211
irgesture_enable_proximity_sensor
void irgesture_enable_proximity_sensor(irgesture_t *ctx)
Enable specific proximity sensors function.
DIR_FAR
@ DIR_FAR
Definition: irgesture.h:256
irgesture_get_led_boost
uint8_t irgesture_get_led_boost(irgesture_t *ctx)
Gets the LED current boost value function.
irgesture_read_proximity_data
uint8_t irgesture_read_proximity_data(irgesture_t *ctx)
Read proximity data function.
irgesture_get_interrupt
uint8_t irgesture_get_interrupt(irgesture_t *ctx)
Get state of interrupt pin function.
irgesture_read_green_light
uint16_t irgesture_read_green_light(irgesture_t *ctx)
Read GREEN light data function.
DIR_UP
@ DIR_UP
Definition: irgesture.h:253
irgesture_set_gesture_gain
void irgesture_set_gesture_gain(irgesture_t *ctx, uint8_t gain_val)
Set gain for gesture function.
gesture_prox_t
gesture_prox_t
Definition: irgesture.h:237
NA_STATE
@ NA_STATE
Definition: irgesture.h:238
irgesture_cfg_setup
void irgesture_cfg_setup(irgesture_cfg_t *cfg)
Config Object Initialization function.
gesture_data_t::ud_delta
uint16_t ud_delta
Definition: irgesture.h:274
irgesture_detect_gesture
uint8_t irgesture_detect_gesture(irgesture_t *ctx)
Function decode a gesture event function.
irgesture_gesture_read_gesture
gesture_dir_t irgesture_gesture_read_gesture(irgesture_t *ctx)
Processes a gesture event function.
irgesture_set_ambient_light_gain
void irgesture_set_ambient_light_gain(irgesture_t *ctx, uint8_t gain_val)
Set gain for ambient light function.
irgesture_available
uint8_t irgesture_available(irgesture_t *ctx)
Determines if there is a gesture available function.
irgesture_read_data
uint8_t irgesture_read_data(irgesture_t *ctx, uint8_t reg_addr)
Read function.
irgesture_cfg_t::i2c_address
uint8_t i2c_address
Definition: irgesture.h:232