proximity5  2.0.0.0
proximity5.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 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 // -------------------------------------------------------------- PUBLIC MACROS
52 #define PROXIMITY5_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define PROXIMITY5_RETVAL uint8_t
63 
64 #define PROXIMITY5_OK 0x00
65 #define PROXIMITY5_INIT_ERROR 0xFF
66 
72 #define ALS_SD_ON 0
73 #define ALS_SD_OFF 1
74 #define ALS_INTEN 1
75 #define ALS_INT_DIS 0
76 #define ALS_PERS_1 1
77 #define ALS_PERS_2 2
78 #define ALS_PERS_4 4
79 #define ALS_PERS_8 8
80 #define ALS_IT_50_ms 0
81 #define ALS_IT_100_ms 1
82 #define ALS_IT_200_ms 2
83 #define ALS_IT_400_ms 3
84 #define ALS_IT_800_ms 7
85 
91 #define ALS_WHITE_SD_ON 0
92 #define ALS_WHITE_SD_OFF 1
93 
99 #define PS_DUTY_1_40 0
100 #define PS_DUTY_1_80 1
101 #define PS_DUTY_1_160 2
102 #define PS_DUTY_1_320 3
103 #define PS_PERS_1 0
104 #define PS_PERS_2 1
105 #define PS_PERS_3 2
106 #define PS_PERS_4 3
107 #define PS_IT_1T 0
108 #define PS_IT_1T5 1
109 #define PS_IT_2T 2
110 #define PS_IT_2T5 3
111 #define PS_IT_3T 4
112 #define PS_IT_3T5 5
113 #define PS_IT_4T 6
114 #define PS_IT_8T 7
115 #define PS_SD_ON 0
116 #define PS_SD_OFF 1
117 
123 #define GEST_INT_EN 1
124 #define GEST_INT_DIS 0
125 #define GEST_MODE_EN 1
126 #define GEST_MODE_DIS 0
127 #define PS_GAIN_TWO_STEP 1
128 #define PS_GAIN_SINGLX8 2
129 #define PS_GAIN_SINGLX1 3
130 #define PS_HD_12BIT 0
131 #define PS_HD_16BIT 1
132 #define PS_NS_TWO_STEPX4 0
133 #define PS_NS_TWO_STEP 1
134 #define PS_INT_DIS 0
135 #define PS_INT_CLOS 1
136 #define PS_INT_AWAY 2
137 #define PS_INT_CLOS_AWAY 3
138 
144 #define LED_I_LOW_DIS 0
145 #define LED_I_LOW_EN 1
146 #define IRED_SEL_IRED1 0
147 #define IRED_SEL_IRED2 1
148 #define IRED_SEL_IRED3 2
149 #define PS_SMART_PERS_DIS 0
150 #define PS_SMART_PERS_EN 1
151 #define PS_AF_DIS 0
152 #define PS_AF_EN 1
153 #define PS_TRIG_DIS 0
154 #define PS_TRIG_EN 1
155 #define PS_MS_INT 0
156 #define PS_MS_LOG_OUT 1
157 #define PS_SC_EN_ON 1
158 #define PS_SC_EN_OFF 0
159 
165 #define PS_SC_CUR_1X 0
166 #define PS_SC_CUR_2X 1
167 #define PS_SC_CUR_4X 2
168 #define PS_SC_CUR_8X 3
169 #define PS_SP_TYP 0
170 #define PS_SP_TYPX1_5 1
171 #define PS_SPO_00h 0
172 #define PS_SPO_FFh 1
173 #define LED_I_50MA 0
174 #define LED_I_75MA 1
175 #define LED_I_100MA 2
176 #define LED_I_120MA 3
177 #define LED_I_140MA 4
178 #define LED_I_160MA 5
179 #define LED_I_180MA 6
180 #define LED_I_200MA 7
181 
187 #define CMD_ALS_CONF1 0x00
188 #define CMD_ALS_CONF2 0x00
189 #define CMD_ALS_CONF1_2 0x00
190 #define CMD_ALS_THDH_L 0x01
191 #define CMD_ALS_THDH_H 0x01
192 #define CMD_ALS_THDH_L_M 0x01
193 #define CMD_ALS_THDL_L 0x02
194 #define CMD_ALS_THDL_H 0x02
195 #define CMD_ALS_THDL_L_M 0x02
196 #define CMD_PS_CONF1 0x03
197 #define CMD_PS_CONF2 0x03
198 #define CMD_PS_CONF1_2 0x03
199 #define CMD_PS_CONF3 0x04
200 #define CMD_PS_MS 0x04
201 #define CMD_PS_CONF3_MS 0x04
202 #define CMD_PS_CANC_L 0x05
203 #define CMD_PS_CANC_M 0x05
204 #define CMD_PS_CANC_L_M 0x05
205 #define CMD_PS_THDH_L 0x06
206 #define CMD_PS_THDH_M 0x06
207 #define CMD_PS_THDH_L_M 0x06
208 #define CMD_PS_THDL_L 0x07
209 #define CMD_PS_THDL_M 0x07
210 #define CMD_PS_THDL_L_M 0x07
211 #define CMD_PS1_DATA_L 0x08
212 #define CMD_PS1_DATA_M 0x08
213 #define CMD_PS1_DATA_L_M 0x08
214 #define CMD_PS2_DATA_L 0x09
215 #define CMD_PS2_DATA_M 0x09
216 #define CMD_PS2_DATA_L_M 0x09
217 #define CMD_PS3_DATA_L 0x0A
218 #define CMD_PS3_DATA_M 0x0A
219 #define CMD_PS3_DATA_L_M 0x0A
220 #define CMD_ALS_DATA_L 0x0B
221 #define CMD_ALS_DATA_M 0x0B
222 #define CMD_ALS_DATA_L_M 0x0B
223 #define CMD_WHITE_DATA_L 0x0C
224 #define CMD_WHITE_DATA_M 0x0C
225 #define CMD_WHITE_DATA_L_M 0x0C
226 #define RESERVED 0x0D
227 #define CMD_INT_FLAG 0x0D
228 #define CMD_ID_L 0x0E
229 #define CMD_ID_M 0x0E
230 #define CMD_ID_L_M 0x0E
231 
237 #define PROXIMITY5_ADDR 0x60
238  // End group macro
242 // --------------------------------------------------------------- PUBLIC TYPES
251 typedef struct
252 {
253  // Input pins
254 
255  digital_in_t int_pin;
256 
257  // Modules
258 
259  i2c_master_t i2c;
260 
261  // ctx variable
262 
263  uint8_t slave_address;
264 
265 } proximity5_t;
266 
270 typedef struct
271 {
272  // Communication gpio pins
273 
274  pin_name_t scl;
275  pin_name_t sda;
276 
277  // Additional gpio pins
278 
279  pin_name_t int_pin;
280 
281  // static variable
282 
283  uint32_t i2c_speed;
284  uint8_t i2c_address;
285 
287 
291 typedef union
292 {
293  unsigned char ALL;
294  struct
295  {
296 
297  unsigned char ALS_SD : 1;
298  unsigned char ALS_INT_EN : 1;
299  unsigned char ALS_PERS : 2;
300  unsigned char RES : 1;
301  unsigned char ALS_IT : 3;
302  };
303 
304 } als_conf1_t;
305 
306 typedef union
307 {
308  unsigned char ALL;
309  struct
310  {
311 
312  unsigned char WHITE_SD : 1;
313  unsigned char RES : 7;
314  };
315 
316 } als_conf2_t;
317 
318 typedef union
319 {
320  uint16_t ALL;
321  struct
322  {
323 
324  uint16_t ALS_THDH_L : 8;
325  uint16_t ALS_THDH_M : 8;
326  };
327 
329 
330 typedef union
331 {
332  uint16_t ALL;
333  struct
334  {
335 
336  uint16_t LS_THDL_L : 8;
337  uint16_t LS_THDL_M : 8;
338  };
339 
341 
342 typedef union
343 {
344  uint16_t ALL;
345  struct
346  {
347 
348  uint16_t ALS_DATA_L : 8;
349  uint16_t ALS_DATA_M : 8;
350  };
351 
353 
354 typedef union
355 {
356  uint8_t ALL;
357  struct
358  {
359  uint8_t PS_SD : 1;
360  uint8_t PS_IT : 3;
361  uint8_t PS_PERS : 2;
362  uint8_t PS_DUTY : 2;
363  };
364 
365 } ps_conf1_t;
366 
367 typedef union
368 {
369  uint8_t ALL;
370  struct {
371 
372  uint8_t PS_INT_EN : 2;
373  uint8_t PS_NS : 1;
374  uint8_t PS_HD : 1;
375  uint8_t PS_GAIN : 2;
376  uint8_t GEST_MODE : 1;
377  uint8_t GEST_INTEN : 1;
378  };
379 
380 } ps_conf2_t;
381 
382 typedef union
383 {
384  uint8_t ALL;
385  struct
386  {
387 
388  uint8_t PS_SC_EN : 1;
389  uint8_t PS_MS : 1;
390  uint8_t PS_TRIG : 1;
391  uint8_t PS_AF : 1;
392  uint8_t PS_SMART_PERS : 1;
393  uint8_t IRED_SEL : 2;
394  uint8_t LED_I_LOW : 1;
395  };
396 
397 } ps_conf3_t;
398 
399 typedef union
400 {
401  uint8_t ALL;
402  struct
403  {
404 
405  uint8_t LED_I : 3;
406  uint8_t PS_SPO : 1;
407  uint8_t PS_SP : 1;
408  uint8_t PS_SC_CUR : 2;
409  uint8_t RES : 1;
410 
411  };
412 
413 } ps_ms_t;
414 
415 typedef union
416 {
417  uint16_t ALL;
418  struct
419  {
420 
421  uint16_t PS_CANC_L : 8;
422  uint16_t PS_CANC_M : 8;
423  };
424 
425 } ps_canc_l_m_t;
426 
427 typedef union
428 {
429  uint16_t ALL;
430  struct
431  {
432 
433  uint16_t PS_THDL_L : 8;
434  uint16_t PS_THDL_M : 8;
435  };
436 
437 } ps_thdl_l_m_t;
438 
439 typedef union
440 {
441  uint16_t ALL;
442  struct
443  {
444 
445  uint16_t PS_THDH_L : 8;
446  uint16_t PS_THDH_M : 8;
447  };
448 
449 } ps_thdh_l_m_t;
450 
451 typedef union
452 {
453  uint16_t ALL;
454  struct
455  {
456 
457  uint16_t PS1_DATA_L : 8;
458  uint16_t PS1_DATA_M : 8;
459  };
460 
462 
463 typedef union
464 {
465  uint16_t ALL;
466  struct {
467 
468  uint16_t PS2_DATA_L : 8;
469  uint16_t PS2_DATA_M : 8;
470  };
471 
473 
474 typedef union
475 {
476  uint16_t ALL;
477  struct
478  {
479 
480  uint16_t PS3_DATA_L : 8;
481  uint16_t PS3_DATA_M : 8;
482  };
483 
485 
486 typedef union
487 {
488  uint16_t ALL;
489  struct
490  {
491 
492  uint16_t WHITE_DATA_L : 8;
493  uint16_t WHITE_DATA_M : 8;
494  };
495 
497 
498 
499 typedef union
500 {
501  uint8_t ALL;
502  struct
503  {
504 
505  uint8_t PS_IF_AWAY : 1;
506  uint8_t PS_IF_CLOSE : 1;
507  uint8_t RES1 : 1;
508  uint8_t RES0 : 1;
509  uint8_t ALS_IF_H : 1;
510  uint8_t ALS_IF_L : 1;
511  uint8_t PS_SPFLAG : 1;
512  uint8_t GEST_DATA_RDY_FLG : 1;
513  };
514 
515 } int_flag_t;
516 
517 
518 typedef union
519 {
520  uint16_t ALL;
521  struct
522  {
523 
524  uint16_t ID_L : 8;
525  uint16_t ID_M : 8;
526 
527  };
528 
529 } id_l_m_t;
530  // End types group
532 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
533 
539 #ifdef __cplusplus
540 extern "C"{
541 #endif
542 
552 
562 
571 
582 void proximity5_generic_write ( proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
583 
594 void proximity5_generic_read ( proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
595 
607 uint16_t proximity5_read_reg ( proximity5_t *ctx, uint8_t addr );
608 
619 uint16_t proximity5_get_id ( proximity5_t *ctx );
620 
631 void proximity5_get_values ( proximity5_t *ctx, uint16_t *prox_val );
632 
633 
634 #ifdef __cplusplus
635 }
636 #endif
637 #endif // _PROXIMITY5_H_
638  // End public_function group
641 
642 // ------------------------------------------------------------------------- END
Definition: proximity5.h:415
uint8_t PS_SC_CUR
Definition: proximity5.h:408
uint16_t ALS_DATA_L
Definition: proximity5.h:348
uint8_t LED_I
Definition: proximity5.h:405
uint8_t PS_PERS
Definition: proximity5.h:361
uint8_t PS_INT_EN
Definition: proximity5.h:372
uint8_t PS_AF
Definition: proximity5.h:391
uint8_t PS_HD
Definition: proximity5.h:374
uint16_t LS_THDL_L
Definition: proximity5.h:336
uint8_t ALL
Definition: proximity5.h:401
uint8_t PS_GAIN
Definition: proximity5.h:375
Definition: proximity5.h:439
uint16_t ALL
Definition: proximity5.h:520
uint8_t PS_SC_EN
Definition: proximity5.h:388
uint16_t PS3_DATA_L
Definition: proximity5.h:480
uint16_t ID_M
Definition: proximity5.h:525
uint16_t ALS_THDH_L
Definition: proximity5.h:324
uint16_t ALL
Definition: proximity5.h:417
void proximity5_cfg_setup(proximity5_cfg_t *cfg)
Config Object Initialization function.
Definition: proximity5.h:399
Definition: proximity5.h:382
uint8_t PS_SPFLAG
Definition: proximity5.h:511
uint16_t PS1_DATA_M
Definition: proximity5.h:458
uint16_t ID_L
Definition: proximity5.h:524
uint8_t LED_I_LOW
Definition: proximity5.h:394
uint8_t PS_MS
Definition: proximity5.h:389
uint16_t PS_CANC_L
Definition: proximity5.h:421
uint16_t ALL
Definition: proximity5.h:429
Definition: proximity5.h:474
uint8_t PS_SMART_PERS
Definition: proximity5.h:392
uint16_t ALL
Definition: proximity5.h:332
uint8_t GEST_MODE
Definition: proximity5.h:376
uint8_t ALL
Definition: proximity5.h:356
unsigned char ALS_PERS
Definition: proximity5.h:299
Definition: proximity5.h:451
uint8_t ALL
Definition: proximity5.h:501
uint8_t IRED_SEL
Definition: proximity5.h:393
unsigned char ALL
Definition: proximity5.h:293
uint8_t i2c_address
Definition: proximity5.h:284
Definition: proximity5.h:427
Definition: proximity5.h:318
unsigned char ALS_INT_EN
Definition: proximity5.h:298
uint8_t ALL
Definition: proximity5.h:384
PROXIMITY5_RETVAL proximity5_init(proximity5_t *ctx, proximity5_cfg_t *cfg)
Initialization function.
uint16_t PS_THDL_M
Definition: proximity5.h:434
Definition: proximity5.h:367
Definition: proximity5.h:342
uint16_t ALL
Definition: proximity5.h:344
uint16_t PS_THDH_M
Definition: proximity5.h:446
uint8_t GEST_INTEN
Definition: proximity5.h:377
unsigned char RES
Definition: proximity5.h:313
uint16_t ALL
Definition: proximity5.h:476
uint16_t PS1_DATA_L
Definition: proximity5.h:457
uint16_t ALL
Definition: proximity5.h:320
Click ctx object definition.
Definition: proximity5.h:251
uint8_t PS_SP
Definition: proximity5.h:407
Definition: proximity5.h:330
uint16_t ALS_THDH_M
Definition: proximity5.h:325
uint8_t ALS_IF_L
Definition: proximity5.h:510
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:441
unsigned char ALS_IT
Definition: proximity5.h:301
uint16_t proximity5_get_id(proximity5_t *ctx)
16bit read function.
Definition: proximity5.h:463
Definition: proximity5.h:354
uint16_t PS_THDH_L
Definition: proximity5.h:445
uint16_t PS_CANC_M
Definition: proximity5.h:422
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:255
uint32_t i2c_speed
Definition: proximity5.h:283
uint8_t PS_IF_AWAY
Definition: proximity5.h:505
uint16_t LS_THDL_M
Definition: proximity5.h:337
Definition: proximity5.h:518
uint16_t proximity5_read_reg(proximity5_t *ctx, uint8_t addr)
16bit read function.
uint16_t ALL
Definition: proximity5.h:465
uint8_t PS_SPO
Definition: proximity5.h:406
uint8_t RES0
Definition: proximity5.h:508
uint16_t PS2_DATA_M
Definition: proximity5.h:469
uint16_t WHITE_DATA_L
Definition: proximity5.h:492
uint8_t ALL
Definition: proximity5.h:369
pin_name_t int_pin
Definition: proximity5.h:279
unsigned char WHITE_SD
Definition: proximity5.h:312
uint8_t ALS_IF_H
Definition: proximity5.h:509
uint16_t ALS_DATA_M
Definition: proximity5.h:349
unsigned char ALS_SD
Definition: proximity5.h:297
uint8_t GEST_DATA_RDY_FLG
Definition: proximity5.h:512
i2c_master_t i2c
Definition: proximity5.h:259
uint8_t PS_TRIG
Definition: proximity5.h:390
uint16_t PS3_DATA_M
Definition: proximity5.h:481
unsigned char ALL
Definition: proximity5.h:308
uint8_t PS_NS
Definition: proximity5.h:373
uint16_t PS2_DATA_L
Definition: proximity5.h:468
Definition: proximity5.h:306
uint8_t RES1
Definition: proximity5.h:507
uint16_t ALL
Definition: proximity5.h:453
uint8_t PS_IT
Definition: proximity5.h:360
unsigned char RES
Definition: proximity5.h:300
Definition: proximity5.h:499
uint16_t ALL
Definition: proximity5.h:488
Click configuration structure definition.
Definition: proximity5.h:270
uint8_t slave_address
Definition: proximity5.h:263
uint16_t PS_THDL_L
Definition: proximity5.h:433
uint8_t RES
Definition: proximity5.h:409
pin_name_t sda
Definition: proximity5.h:275
pin_name_t scl
Definition: proximity5.h:274
void proximity5_get_values(proximity5_t *ctx, uint16_t *prox_val)
Proximity value get function.
#define PROXIMITY5_RETVAL
Definition: proximity5.h:62
Click calibration unions.
Definition: proximity5.h:291
uint8_t PS_SD
Definition: proximity5.h:359
uint8_t PS_DUTY
Definition: proximity5.h:362
uint16_t WHITE_DATA_M
Definition: proximity5.h:493
uint8_t PS_IF_CLOSE
Definition: proximity5.h:506
Definition: proximity5.h:486