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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define IRGESTURE_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define IRGESTURE_RETVAL uint8_t
78
79#define IRGESTURE_OK 0x00
80#define IRGESTURE_INIT_ERROR 0xFF
87#define IRGESTURE_I2C_ADDR 0x39
94#define IRGESTURE_ENABLE 0x80
95#define IRGESTURE_ATIME 0x81
96#define IRGESTURE_WTIME 0x83
97#define IRGESTURE_AILTL 0x84
98#define IRGESTURE_AILTH 0x85
99#define IRGESTURE_AIHTL 0x86
100#define IRGESTURE_AIHTH 0x87
101#define IRGESTURE_PILT 0x89
102#define IRGESTURE_PIHT 0x8B
103#define IRGESTURE_PERS 0x8C
104#define IRGESTURE_CONFIG1 0x8D
105#define IRGESTURE_PPULSE 0x8E
106#define IRGESTURE_CONTROL 0x8F
107#define IRGESTURE_CONFIG2 0x90
108#define IRGESTURE_ID 0x92
109#define IRGESTURE_STATUS 0x93
110#define IRGESTURE_CDATAL 0x94
111#define IRGESTURE_CDATAH 0x95
112#define IRGESTURE_RDATAL 0x96
113#define IRGESTURE_RDATAH 0x97
114#define IRGESTURE_GDATAL 0x98
115#define IRGESTURE_GDATAH 0x99
116#define IRGESTURE_BDATAL 0x9A
117#define IRGESTURE_BDATAH 0x9B
118#define IRGESTURE_PDATA 0x9C
119#define IRGESTURE_POFFSET_UR 0x9D
120#define IRGESTURE_POFFSET_DL 0x9E
121#define IRGESTURE_CONFIG3 0x9F
122#define IRGESTURE_GPENTH 0xA0
123#define IRGESTURE_GEXTH 0xA1
124#define IRGESTURE_GCONF1 0xA2
125#define IRGESTURE_GCONF2 0xA3
126#define IRGESTURE_GOFFSET_U 0xA4
127#define IRGESTURE_GOFFSET_D 0xA5
128#define IRGESTURE_GOFFSET_L 0xA7
129#define IRGESTURE_GOFFSET_R 0xA9
130#define IRGESTURE_GPULSE 0xA6
131#define IRGESTURE_GCONF3 0xAA
132#define IRGESTURE_GCONF4 0xAB
133#define IRGESTURE_GFLVL 0xAE
134#define IRGESTURE_GSTATUS 0xAF
135#define IRGESTURE_IFORCE 0xE4
136#define IRGESTURE_PICLEAR 0xE5
137#define IRGESTURE_CICLEAR 0xE6
138#define IRGESTURE_AICLEAR 0xE7
139#define IRGESTURE_GFIFO_U 0xFC
140#define IRGESTURE_GFIFO_D 0xFD
141#define IRGESTURE_GFIFO_L 0xFE
142#define IRGESTURE_GFIFO_R 0xFF
149#define DEFAULT_ATIME 219
150#define DEFAULT_WTIME 246
151#define DEFAULT_PROX_PPULSE 0x87
152#define DEFAULT_GESTURE_PPULSE 0x89
153#define DEFAULT_POFFSET_UR 0
154#define DEFAULT_POFFSET_DL 0
155#define DEFAULT_CONFIG1 0x60
156#define DEFAULT_LDRIVE 0
157#define DEFAULT_PGAIN 2
158#define DEFAULT_AGAIN 1
159#define DEFAULT_PILT 0
160#define DEFAULT_PIHT 50
161#define DEFAULT_AILT 0xFFFF
162#define DEFAULT_AIHT 0
163#define DEFAULT_PERS 0x11
164#define DEFAULT_CONFIG2 0x01
165#define DEFAULT_CONFIG3 0
166#define DEFAULT_GPENTH 40
167#define DEFAULT_GEXTH 30
168#define DEFAULT_GCONF1 0x40
169#define DEFAULT_GGAIN 2
170#define DEFAULT_GLDRIVE 0
171#define DEFAULT_GWTIME 1
172#define DEFAULT_GOFFSET 0
173#define DEFAULT_GPULSE 0xC9
174#define DEFAULT_GCONF3 0
175#define DEFAULT_GIEN 0
182#define IRGESTURE_PON 0b00000001
183#define IRGESTURE_AEN 0b00000010
184#define IRGESTURE_PEN 0b00000100
185#define IRGESTURE_WEN 0b00001000
186#define IRGESTURE_AIEN 0b00010000
187#define IRGESTURE_PIEN 0b00100000
188#define IRGESTURE_GEN 0b01000000
189#define IRGESTURE_GVALID 0b00000001
196#define IRGESTURE_FAR 0x00
197#define IRGESTURE_RIGHT 0x01
198#define IRGESTURE_LEFT 0x02
199#define IRGESTURE_UP 0x03
200#define IRGESTURE_DOWN 0x04
201#define IRGESTURE_NEAR 0x05
203 // End group macro
204// --------------------------------------------------------------- PUBLIC TYPES
213typedef struct
214{
215 // Input pins
216
217 digital_in_t int_pin;
218
219 // Modules
220
221 i2c_master_t i2c;
222
223 // ctx variable
224
226
228
232typedef struct
233{
234 // Communication gpio pins
235
236 pin_name_t scl;
237 pin_name_t sda;
238
239 // Additional gpio pins
240
241 pin_name_t int_pin;
242
243 // static variable
244
245 uint32_t i2c_speed;
246 uint8_t i2c_address;
247
249
258
274
278typedef struct
279{
280 uint8_t u_data[ 32 ];
281 uint8_t d_data[ 32 ];
282 uint8_t l_data[ 32 ];
283 uint8_t r_data[ 32 ];
284 uint8_t index;
288 uint16_t ud_delta;
289 uint16_t lr_delta;
290 uint16_t ud_count;
291 uint16_t lr_count;
292 uint16_t near_count;
293 uint16_t far_count;
296
298
299 // End types group
300// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
301
307#ifdef __cplusplus
308extern "C"{
309#endif
310
320
329
338
348void irgesture_write_data ( irgesture_t *ctx, uint8_t reg_addr, uint8_t write_data );
349
361uint8_t irgesture_read_data ( irgesture_t *ctx, uint8_t reg_addr );
362
373
389
399
409
419
429void irgesture_set_ambient_light_gain ( irgesture_t *ctx, uint8_t gain_val );
430
442
453
463
475
487
499
511
529void irgesture_set_led_boost ( irgesture_t *ctx, uint8_t boost );
530
547
560
570void irgesture_set_gesture_gain ( irgesture_t *ctx, uint8_t gain_val );
571
583
593
603
615
625void irgesture_set_proximity_gain ( irgesture_t *ctx, uint8_t gain_val );
626
638
648
658
678
697void irgesture_set_proxy_photo_mask ( irgesture_t *ctx, uint8_t mask );
698
709
710
711#ifdef __cplusplus
712}
713#endif
714#endif // _IRGESTURE_H_
715
716 // End public_function group
718
719// ------------------------------------------------------------------------- END
#define IRGESTURE_RETVAL
Definition irgesture.h:77
uint8_t irgesture_get_proxy_photo_mask(irgesture_t *ctx)
Get the current mask for enabled/disabled proximity photodiodes function.
uint16_t irgesture_read_red_light(irgesture_t *ctx)
Read RED light data function.
uint8_t irgesture_read_proximity_data(irgesture_t *ctx)
Read proximity data function.
void irgesture_cfg_setup(irgesture_cfg_t *cfg)
Config Object Initialization function.
void irgesture_enable_gesture_sensor(irgesture_t *ctx)
Starts the gesture recognition engine function.
void irgesture_write_data(irgesture_t *ctx, uint8_t reg_addr, uint8_t write_data)
Write function.
uint16_t irgesture_read_ambient_light(irgesture_t *ctx)
Read ambient light data function.
uint8_t irgesture_available(irgesture_t *ctx)
Determines if there is a gesture available function.
void irgesture_set_proxy_photo_mask(irgesture_t *ctx, uint8_t mask)
Get the current mask for enabled/disabled proximity photodiodes function.
uint16_t irgesture_read_green_light(irgesture_t *ctx)
Read GREEN light data function.
void irgesture_disable_power(irgesture_t *ctx)
Disable power sensor function.
uint8_t irgesture_get_proximity_gain(irgesture_t *ctx)
Get gain for proximity function.
void irgesture_enable_power(irgesture_t *ctx)
Enable power sensor function.
void irgesture_set_proximity_gain(irgesture_t *ctx, uint8_t gain_val)
Set gain for proximity function.
uint8_t irgesture_detect_gesture(irgesture_t *ctx)
Function decode a gesture event function.
uint8_t irgesture_get_led_boost(irgesture_t *ctx)
Gets the LED current boost value function.
void irgesture_disable_light_sensor(irgesture_t *ctx)
Disable specific ambient light sensors function.
void irgesture_disable_proximity_sensor(irgesture_t *ctx)
Disable specific proximity sensors function.
uint8_t irgesture_get_gesture_gain(irgesture_t *ctx)
Get gain for gesture function.
void irgesture_set_led_boost(irgesture_t *ctx, uint8_t boost)
Sets the LED current boost value function.
void irgesture_set_gesture_mode(irgesture_t *ctx)
Sets the gesture mode function.
void irgesture_set_ambient_light_gain(irgesture_t *ctx, uint8_t gain_val)
Set gain for ambient light function.
void irgesture_default_cfg(irgesture_t *ctx)
Click Default Configuration function.
void irgesture_enable_proximity_sensor(irgesture_t *ctx)
Enable specific proximity sensors function.
void irgesture_set_gesture_gain(irgesture_t *ctx, uint8_t gain_val)
Set gain for gesture function.
uint8_t irgesture_get_ambient_light_gain(irgesture_t *ctx)
Get gain for ambient light function.
uint16_t irgesture_read_blue_light(irgesture_t *ctx)
Read BLUE light data function.
void irgesture_disable_gesture_sensor(irgesture_t *ctx)
Disable the gesture recognition engine function.
gesture_dir_t irgesture_gesture_read_gesture(irgesture_t *ctx)
Processes a gesture event function.
void irgesture_enable_light_sensor(irgesture_t *ctx)
Enable specific ambient light sensors function.
uint8_t irgesture_get_interrupt(irgesture_t *ctx)
Get state of interrupt pin function.
IRGESTURE_RETVAL irgesture_init(irgesture_t *ctx, irgesture_cfg_t *cfg)
Initialization function.
uint8_t irgesture_read_data(irgesture_t *ctx, uint8_t reg_addr)
Read function.
gesture_prox_t
Definition irgesture.h:251
gesture_dir_t
Direction definitions.
Definition irgesture.h:263
@ NA_STATE
Definition irgesture.h:252
@ FAR_STATE
Definition irgesture.h:254
@ NEAR_STATE
Definition irgesture.h:253
@ ALL_STATE
Definition irgesture.h:255
@ DIR_UP
Definition irgesture.h:267
@ DIR_LEFT
Definition irgesture.h:265
@ DIR_NONE
Definition irgesture.h:264
@ DIR_NEAR
Definition irgesture.h:269
@ DIR_RIGHT
Definition irgesture.h:266
@ DIR_FAR
Definition irgesture.h:270
@ DIR_DOWN
Definition irgesture.h:268
@ DIR_ALL
Definition irgesture.h:271
Container for gesture data.
Definition irgesture.h:279
uint8_t total_gestures
Definition irgesture.h:285
uint16_t lr_delta
Definition irgesture.h:289
uint16_t ud_delta
Definition irgesture.h:288
uint16_t lr_count
Definition irgesture.h:291
uint16_t far_count
Definition irgesture.h:293
uint8_t out_threshold
Definition irgesture.h:287
uint16_t ud_count
Definition irgesture.h:290
uint16_t near_count
Definition irgesture.h:292
uint8_t in_threshold
Definition irgesture.h:286
gesture_prox_t state
Definition irgesture.h:294
uint8_t index
Definition irgesture.h:284
gesture_dir_t motion
Definition irgesture.h:295
Click configuration structure definition.
Definition irgesture.h:233
uint32_t i2c_speed
Definition irgesture.h:245
pin_name_t scl
Definition irgesture.h:236
pin_name_t int_pin
Definition irgesture.h:241
pin_name_t sda
Definition irgesture.h:237
uint8_t i2c_address
Definition irgesture.h:246
Click ctx object definition.
Definition irgesture.h:214
digital_in_t int_pin
Definition irgesture.h:217
i2c_master_t i2c
Definition irgesture.h:221
uint8_t slave_address
Definition irgesture.h:225