proximity5  2.0.0.0
proximity5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef PROXIMITY5_H
36 #define PROXIMITY5_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 PROXIMITY5_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 PROXIMITY5_RETVAL uint8_t
64 
65 #define PROXIMITY5_OK 0x00
66 #define PROXIMITY5_INIT_ERROR 0xFF
67 
73 #define ALS_SD_ON 0
74 #define ALS_SD_OFF 1
75 #define ALS_INTEN 1
76 #define ALS_INT_DIS 0
77 #define ALS_PERS_1 1
78 #define ALS_PERS_2 2
79 #define ALS_PERS_4 4
80 #define ALS_PERS_8 8
81 #define ALS_IT_50_ms 0
82 #define ALS_IT_100_ms 1
83 #define ALS_IT_200_ms 2
84 #define ALS_IT_400_ms 3
85 #define ALS_IT_800_ms 7
86 
92 #define ALS_WHITE_SD_ON 0
93 #define ALS_WHITE_SD_OFF 1
94 
100 #define PS_DUTY_1_40 0
101 #define PS_DUTY_1_80 1
102 #define PS_DUTY_1_160 2
103 #define PS_DUTY_1_320 3
104 #define PS_PERS_1 0
105 #define PS_PERS_2 1
106 #define PS_PERS_3 2
107 #define PS_PERS_4 3
108 #define PS_IT_1T 0
109 #define PS_IT_1T5 1
110 #define PS_IT_2T 2
111 #define PS_IT_2T5 3
112 #define PS_IT_3T 4
113 #define PS_IT_3T5 5
114 #define PS_IT_4T 6
115 #define PS_IT_8T 7
116 #define PS_SD_ON 0
117 #define PS_SD_OFF 1
118 
124 #define GEST_INT_EN 1
125 #define GEST_INT_DIS 0
126 #define GEST_MODE_EN 1
127 #define GEST_MODE_DIS 0
128 #define PS_GAIN_TWO_STEP 1
129 #define PS_GAIN_SINGLX8 2
130 #define PS_GAIN_SINGLX1 3
131 #define PS_HD_12BIT 0
132 #define PS_HD_16BIT 1
133 #define PS_NS_TWO_STEPX4 0
134 #define PS_NS_TWO_STEP 1
135 #define PS_INT_DIS 0
136 #define PS_INT_CLOS 1
137 #define PS_INT_AWAY 2
138 #define PS_INT_CLOS_AWAY 3
139 
145 #define LED_I_LOW_DIS 0
146 #define LED_I_LOW_EN 1
147 #define IRED_SEL_IRED1 0
148 #define IRED_SEL_IRED2 1
149 #define IRED_SEL_IRED3 2
150 #define PS_SMART_PERS_DIS 0
151 #define PS_SMART_PERS_EN 1
152 #define PS_AF_DIS 0
153 #define PS_AF_EN 1
154 #define PS_TRIG_DIS 0
155 #define PS_TRIG_EN 1
156 #define PS_MS_INT 0
157 #define PS_MS_LOG_OUT 1
158 #define PS_SC_EN_ON 1
159 #define PS_SC_EN_OFF 0
160 
166 #define PS_SC_CUR_1X 0
167 #define PS_SC_CUR_2X 1
168 #define PS_SC_CUR_4X 2
169 #define PS_SC_CUR_8X 3
170 #define PS_SP_TYP 0
171 #define PS_SP_TYPX1_5 1
172 #define PS_SPO_00h 0
173 #define PS_SPO_FFh 1
174 #define LED_I_50MA 0
175 #define LED_I_75MA 1
176 #define LED_I_100MA 2
177 #define LED_I_120MA 3
178 #define LED_I_140MA 4
179 #define LED_I_160MA 5
180 #define LED_I_180MA 6
181 #define LED_I_200MA 7
182 
188 #define CMD_ALS_CONF1 0x00
189 #define CMD_ALS_CONF2 0x00
190 #define CMD_ALS_CONF1_2 0x00
191 #define CMD_ALS_THDH_L 0x01
192 #define CMD_ALS_THDH_H 0x01
193 #define CMD_ALS_THDH_L_M 0x01
194 #define CMD_ALS_THDL_L 0x02
195 #define CMD_ALS_THDL_H 0x02
196 #define CMD_ALS_THDL_L_M 0x02
197 #define CMD_PS_CONF1 0x03
198 #define CMD_PS_CONF2 0x03
199 #define CMD_PS_CONF1_2 0x03
200 #define CMD_PS_CONF3 0x04
201 #define CMD_PS_MS 0x04
202 #define CMD_PS_CONF3_MS 0x04
203 #define CMD_PS_CANC_L 0x05
204 #define CMD_PS_CANC_M 0x05
205 #define CMD_PS_CANC_L_M 0x05
206 #define CMD_PS_THDH_L 0x06
207 #define CMD_PS_THDH_M 0x06
208 #define CMD_PS_THDH_L_M 0x06
209 #define CMD_PS_THDL_L 0x07
210 #define CMD_PS_THDL_M 0x07
211 #define CMD_PS_THDL_L_M 0x07
212 #define CMD_PS1_DATA_L 0x08
213 #define CMD_PS1_DATA_M 0x08
214 #define CMD_PS1_DATA_L_M 0x08
215 #define CMD_PS2_DATA_L 0x09
216 #define CMD_PS2_DATA_M 0x09
217 #define CMD_PS2_DATA_L_M 0x09
218 #define CMD_PS3_DATA_L 0x0A
219 #define CMD_PS3_DATA_M 0x0A
220 #define CMD_PS3_DATA_L_M 0x0A
221 #define CMD_ALS_DATA_L 0x0B
222 #define CMD_ALS_DATA_M 0x0B
223 #define CMD_ALS_DATA_L_M 0x0B
224 #define CMD_WHITE_DATA_L 0x0C
225 #define CMD_WHITE_DATA_M 0x0C
226 #define CMD_WHITE_DATA_L_M 0x0C
227 #define RESERVED 0x0D
228 #define CMD_INT_FLAG 0x0D
229 #define CMD_ID_L 0x0E
230 #define CMD_ID_M 0x0E
231 #define CMD_ID_L_M 0x0E
232 
238 #define PROXIMITY5_ADDR 0x60
239  // End group macro
243 // --------------------------------------------------------------- PUBLIC TYPES
252 typedef struct
253 {
254  // Input pins
255 
256  digital_in_t int_pin;
257 
258  // Modules
259 
260  i2c_master_t i2c;
261 
262  // ctx variable
263 
264  hal_i2c_address_t slave_address;
265 
266 } proximity5_t;
267 
271 typedef struct
272 {
273  // Communication gpio pins
274 
275  pin_name_t scl;
276  pin_name_t sda;
277 
278  // Additional gpio pins
279 
280  pin_name_t int_pin;
281 
282  // static variable
283 
284  hal_i2c_speed_t i2c_speed;
285  hal_i2c_address_t i2c_address;
286 
288 
292 typedef union
293 {
294  unsigned char ALL;
295  struct
296  {
297 
298  unsigned char ALS_SD : 1;
299  unsigned char ALS_INT_EN : 1;
300  unsigned char ALS_PERS : 2;
301  unsigned char RES : 1;
302  unsigned char ALS_IT : 3;
303  };
304 
305 } als_conf1_t;
306 
307 typedef union
308 {
309  unsigned char ALL;
310  struct
311  {
312 
313  unsigned char WHITE_SD : 1;
314  unsigned char RES : 7;
315  };
316 
317 } als_conf2_t;
318 
319 typedef union
320 {
321  uint16_t ALL;
322  struct
323  {
324 
325  uint16_t ALS_THDH_L : 8;
326  uint16_t ALS_THDH_M : 8;
327  };
328 
330 
331 typedef union
332 {
333  uint16_t ALL;
334  struct
335  {
336 
337  uint16_t LS_THDL_L : 8;
338  uint16_t LS_THDL_M : 8;
339  };
340 
342 
343 typedef union
344 {
345  uint16_t ALL;
346  struct
347  {
348 
349  uint16_t ALS_DATA_L : 8;
350  uint16_t ALS_DATA_M : 8;
351  };
352 
354 
355 typedef union
356 {
357  uint8_t ALL;
358  struct
359  {
360  uint8_t PS_SD : 1;
361  uint8_t PS_IT : 3;
362  uint8_t PS_PERS : 2;
363  uint8_t PS_DUTY : 2;
364  };
365 
366 } ps_conf1_t;
367 
368 typedef union
369 {
370  uint8_t ALL;
371  struct {
372 
373  uint8_t PS_INT_EN : 2;
374  uint8_t PS_NS : 1;
375  uint8_t PS_HD : 1;
376  uint8_t PS_GAIN : 2;
377  uint8_t GEST_MODE : 1;
378  uint8_t GEST_INTEN : 1;
379  };
380 
381 } ps_conf2_t;
382 
383 typedef union
384 {
385  uint8_t ALL;
386  struct
387  {
388 
389  uint8_t PS_SC_EN : 1;
390  uint8_t PS_MS : 1;
391  uint8_t PS_TRIG : 1;
392  uint8_t PS_AF : 1;
393  uint8_t PS_SMART_PERS : 1;
394  uint8_t IRED_SEL : 2;
395  uint8_t LED_I_LOW : 1;
396  };
397 
398 } ps_conf3_t;
399 
400 typedef union
401 {
402  uint8_t ALL;
403  struct
404  {
405 
406  uint8_t LED_I : 3;
407  uint8_t PS_SPO : 1;
408  uint8_t PS_SP : 1;
409  uint8_t PS_SC_CUR : 2;
410  uint8_t RES : 1;
411 
412  };
413 
414 } ps_ms_t;
415 
416 typedef union
417 {
418  uint16_t ALL;
419  struct
420  {
421 
422  uint16_t PS_CANC_L : 8;
423  uint16_t PS_CANC_M : 8;
424  };
425 
426 } ps_canc_l_m_t;
427 
428 typedef union
429 {
430  uint16_t ALL;
431  struct
432  {
433 
434  uint16_t PS_THDL_L : 8;
435  uint16_t PS_THDL_M : 8;
436  };
437 
438 } ps_thdl_l_m_t;
439 
440 typedef union
441 {
442  uint16_t ALL;
443  struct
444  {
445 
446  uint16_t PS_THDH_L : 8;
447  uint16_t PS_THDH_M : 8;
448  };
449 
450 } ps_thdh_l_m_t;
451 
452 typedef union
453 {
454  uint16_t ALL;
455  struct
456  {
457 
458  uint16_t PS1_DATA_L : 8;
459  uint16_t PS1_DATA_M : 8;
460  };
461 
463 
464 typedef union
465 {
466  uint16_t ALL;
467  struct {
468 
469  uint16_t PS2_DATA_L : 8;
470  uint16_t PS2_DATA_M : 8;
471  };
472 
474 
475 typedef union
476 {
477  uint16_t ALL;
478  struct
479  {
480 
481  uint16_t PS3_DATA_L : 8;
482  uint16_t PS3_DATA_M : 8;
483  };
484 
486 
487 typedef union
488 {
489  uint16_t ALL;
490  struct
491  {
492 
493  uint16_t WHITE_DATA_L : 8;
494  uint16_t WHITE_DATA_M : 8;
495  };
496 
498 
499 
500 typedef union
501 {
502  uint8_t ALL;
503  struct
504  {
505 
506  uint8_t PS_IF_AWAY : 1;
507  uint8_t PS_IF_CLOSE : 1;
508  uint8_t RES1 : 1;
509  uint8_t RES0 : 1;
510  uint8_t ALS_IF_H : 1;
511  uint8_t ALS_IF_L : 1;
512  uint8_t PS_SPFLAG : 1;
513  uint8_t GEST_DATA_RDY_FLG : 1;
514  };
515 
516 } int_flag_t;
517 
518 
519 typedef union
520 {
521  uint16_t ALL;
522  struct
523  {
524 
525  uint16_t ID_L : 8;
526  uint16_t ID_M : 8;
527 
528  };
529 
530 } id_l_m_t;
531  // End types group
533 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
534 
540 #ifdef __cplusplus
541 extern "C"{
542 #endif
543 
553 
562 
571 
582 void proximity5_generic_write ( proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
583 
595 void proximity5_generic_read ( proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
596 
609 uint16_t proximity5_read_reg ( proximity5_t *ctx, uint8_t addr );
610 
611  //Read the ID from the ID register of the sensor.
612 
624 uint16_t proximity5_get_id ( proximity5_t *ctx );
625 
626 
627 
640 void proximity5_get_values ( proximity5_t *ctx, uint16_t *prox_val );
641 
642 
643 
644 #ifdef __cplusplus
645 }
646 #endif
647 #endif // _PROXIMITY5_H_
648  // End public_function group
651 
652 // ------------------------------------------------------------------------- END
Definition: proximity5.h:416
uint8_t PS_SC_CUR
Definition: proximity5.h:409
uint16_t ALS_DATA_L
Definition: proximity5.h:349
uint8_t LED_I
Definition: proximity5.h:406
uint8_t PS_PERS
Definition: proximity5.h:362
uint8_t PS_INT_EN
Definition: proximity5.h:373
uint8_t PS_AF
Definition: proximity5.h:392
uint8_t PS_HD
Definition: proximity5.h:375
uint16_t LS_THDL_L
Definition: proximity5.h:337
uint8_t ALL
Definition: proximity5.h:402
uint8_t PS_GAIN
Definition: proximity5.h:376
Definition: proximity5.h:440
uint16_t ALL
Definition: proximity5.h:521
uint8_t PS_SC_EN
Definition: proximity5.h:389
uint16_t PS3_DATA_L
Definition: proximity5.h:481
uint16_t ID_M
Definition: proximity5.h:526
uint16_t ALS_THDH_L
Definition: proximity5.h:325
uint16_t ALL
Definition: proximity5.h:418
void proximity5_cfg_setup(proximity5_cfg_t *cfg)
Config Object Initialization function.
Definition: proximity5.h:400
Definition: proximity5.h:383
uint8_t PS_SPFLAG
Definition: proximity5.h:512
uint16_t PS1_DATA_M
Definition: proximity5.h:459
uint16_t ID_L
Definition: proximity5.h:525
uint8_t LED_I_LOW
Definition: proximity5.h:395
uint8_t PS_MS
Definition: proximity5.h:390
uint16_t PS_CANC_L
Definition: proximity5.h:422
uint16_t ALL
Definition: proximity5.h:430
Definition: proximity5.h:475
uint8_t PS_SMART_PERS
Definition: proximity5.h:393
uint16_t ALL
Definition: proximity5.h:333
uint8_t GEST_MODE
Definition: proximity5.h:377
uint8_t ALL
Definition: proximity5.h:357
unsigned char ALS_PERS
Definition: proximity5.h:300
hal_i2c_speed_t i2c_speed
Definition: proximity5.h:284
Definition: proximity5.h:452
uint8_t ALL
Definition: proximity5.h:502
uint8_t IRED_SEL
Definition: proximity5.h:394
unsigned char ALL
Definition: proximity5.h:294
Definition: proximity5.h:428
Definition: proximity5.h:319
unsigned char ALS_INT_EN
Definition: proximity5.h:299
uint8_t ALL
Definition: proximity5.h:385
PROXIMITY5_RETVAL proximity5_init(proximity5_t *ctx, proximity5_cfg_t *cfg)
Initialization function.
uint16_t PS_THDL_M
Definition: proximity5.h:435
Definition: proximity5.h:368
Definition: proximity5.h:343
uint16_t ALL
Definition: proximity5.h:345
uint16_t PS_THDH_M
Definition: proximity5.h:447
uint8_t GEST_INTEN
Definition: proximity5.h:378
unsigned char RES
Definition: proximity5.h:314
uint16_t ALL
Definition: proximity5.h:477
uint16_t PS1_DATA_L
Definition: proximity5.h:458
uint16_t ALL
Definition: proximity5.h:321
Click ctx object definition.
Definition: proximity5.h:252
uint8_t PS_SP
Definition: proximity5.h:408
Definition: proximity5.h:331
uint16_t ALS_THDH_M
Definition: proximity5.h:326
uint8_t ALS_IF_L
Definition: proximity5.h:511
void proximity5_generic_write(proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t ALL
Definition: proximity5.h:442
unsigned char ALS_IT
Definition: proximity5.h:302
uint16_t proximity5_get_id(proximity5_t *ctx)
16bit read function.
Definition: proximity5.h:464
Definition: proximity5.h:355
uint16_t PS_THDH_L
Definition: proximity5.h:446
uint16_t PS_CANC_M
Definition: proximity5.h:423
void proximity5_default_cfg(proximity5_t *ctx)
Click Default Configuration function.
void proximity5_generic_read(proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
digital_in_t int_pin
Definition: proximity5.h:256
uint8_t PS_IF_AWAY
Definition: proximity5.h:506
uint16_t LS_THDL_M
Definition: proximity5.h:338
Definition: proximity5.h:519
hal_i2c_address_t slave_address
Definition: proximity5.h:264
uint16_t proximity5_read_reg(proximity5_t *ctx, uint8_t addr)
16bit read function.
uint16_t ALL
Definition: proximity5.h:466
uint8_t PS_SPO
Definition: proximity5.h:407
uint8_t RES0
Definition: proximity5.h:509
uint16_t PS2_DATA_M
Definition: proximity5.h:470
uint16_t WHITE_DATA_L
Definition: proximity5.h:493
uint8_t ALL
Definition: proximity5.h:370
pin_name_t int_pin
Definition: proximity5.h:280
unsigned char WHITE_SD
Definition: proximity5.h:313
hal_i2c_address_t i2c_address
Definition: proximity5.h:285
uint8_t ALS_IF_H
Definition: proximity5.h:510
uint16_t ALS_DATA_M
Definition: proximity5.h:350
unsigned char ALS_SD
Definition: proximity5.h:298
uint8_t GEST_DATA_RDY_FLG
Definition: proximity5.h:513
i2c_master_t i2c
Definition: proximity5.h:260
uint8_t PS_TRIG
Definition: proximity5.h:391
uint16_t PS3_DATA_M
Definition: proximity5.h:482
unsigned char ALL
Definition: proximity5.h:309
uint8_t PS_NS
Definition: proximity5.h:374
uint16_t PS2_DATA_L
Definition: proximity5.h:469
Definition: proximity5.h:307
uint8_t RES1
Definition: proximity5.h:508
uint16_t ALL
Definition: proximity5.h:454
uint8_t PS_IT
Definition: proximity5.h:361
unsigned char RES
Definition: proximity5.h:301
Definition: proximity5.h:500
uint16_t ALL
Definition: proximity5.h:489
Click configuration structure definition.
Definition: proximity5.h:271
uint16_t PS_THDL_L
Definition: proximity5.h:434
uint8_t RES
Definition: proximity5.h:410
pin_name_t sda
Definition: proximity5.h:276
pin_name_t scl
Definition: proximity5.h:275
void proximity5_get_values(proximity5_t *ctx, uint16_t *prox_val)
Proximity value get function.
#define PROXIMITY5_RETVAL
Definition: proximity5.h:63
Click calibration unions.
Definition: proximity5.h:292
uint8_t PS_SD
Definition: proximity5.h:360
uint8_t PS_DUTY
Definition: proximity5.h:363
uint16_t WHITE_DATA_M
Definition: proximity5.h:494
uint8_t PS_IF_CLOSE
Definition: proximity5.h:507
Definition: proximity5.h:487