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
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// -------------------------------------------------------------- PUBLIC MACROS
66#define PROXIMITY5_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define PROXIMITY5_RETVAL uint8_t
77
78#define PROXIMITY5_OK 0x00
79#define PROXIMITY5_INIT_ERROR 0xFF
86#define ALS_SD_ON 0
87#define ALS_SD_OFF 1
88#define ALS_INTEN 1
89#define ALS_INT_DIS 0
90#define ALS_PERS_1 1
91#define ALS_PERS_2 2
92#define ALS_PERS_4 4
93#define ALS_PERS_8 8
94#define ALS_IT_50_ms 0
95#define ALS_IT_100_ms 1
96#define ALS_IT_200_ms 2
97#define ALS_IT_400_ms 3
98#define ALS_IT_800_ms 7
105#define ALS_WHITE_SD_ON 0
106#define ALS_WHITE_SD_OFF 1
113#define PS_DUTY_1_40 0
114#define PS_DUTY_1_80 1
115#define PS_DUTY_1_160 2
116#define PS_DUTY_1_320 3
117#define PS_PERS_1 0
118#define PS_PERS_2 1
119#define PS_PERS_3 2
120#define PS_PERS_4 3
121#define PS_IT_1T 0
122#define PS_IT_1T5 1
123#define PS_IT_2T 2
124#define PS_IT_2T5 3
125#define PS_IT_3T 4
126#define PS_IT_3T5 5
127#define PS_IT_4T 6
128#define PS_IT_8T 7
129#define PS_SD_ON 0
130#define PS_SD_OFF 1
137#define GEST_INT_EN 1
138#define GEST_INT_DIS 0
139#define GEST_MODE_EN 1
140#define GEST_MODE_DIS 0
141#define PS_GAIN_TWO_STEP 1
142#define PS_GAIN_SINGLX8 2
143#define PS_GAIN_SINGLX1 3
144#define PS_HD_12BIT 0
145#define PS_HD_16BIT 1
146#define PS_NS_TWO_STEPX4 0
147#define PS_NS_TWO_STEP 1
148#define PS_INT_DIS 0
149#define PS_INT_CLOS 1
150#define PS_INT_AWAY 2
151#define PS_INT_CLOS_AWAY 3
158#define LED_I_LOW_DIS 0
159#define LED_I_LOW_EN 1
160#define IRED_SEL_IRED1 0
161#define IRED_SEL_IRED2 1
162#define IRED_SEL_IRED3 2
163#define PS_SMART_PERS_DIS 0
164#define PS_SMART_PERS_EN 1
165#define PS_AF_DIS 0
166#define PS_AF_EN 1
167#define PS_TRIG_DIS 0
168#define PS_TRIG_EN 1
169#define PS_MS_INT 0
170#define PS_MS_LOG_OUT 1
171#define PS_SC_EN_ON 1
172#define PS_SC_EN_OFF 0
179#define PS_SC_CUR_1X 0
180#define PS_SC_CUR_2X 1
181#define PS_SC_CUR_4X 2
182#define PS_SC_CUR_8X 3
183#define PS_SP_TYP 0
184#define PS_SP_TYPX1_5 1
185#define PS_SPO_00h 0
186#define PS_SPO_FFh 1
187#define LED_I_50MA 0
188#define LED_I_75MA 1
189#define LED_I_100MA 2
190#define LED_I_120MA 3
191#define LED_I_140MA 4
192#define LED_I_160MA 5
193#define LED_I_180MA 6
194#define LED_I_200MA 7
201#define CMD_ALS_CONF1 0x00
202#define CMD_ALS_CONF2 0x00
203#define CMD_ALS_CONF1_2 0x00
204#define CMD_ALS_THDH_L 0x01
205#define CMD_ALS_THDH_H 0x01
206#define CMD_ALS_THDH_L_M 0x01
207#define CMD_ALS_THDL_L 0x02
208#define CMD_ALS_THDL_H 0x02
209#define CMD_ALS_THDL_L_M 0x02
210#define CMD_PS_CONF1 0x03
211#define CMD_PS_CONF2 0x03
212#define CMD_PS_CONF1_2 0x03
213#define CMD_PS_CONF3 0x04
214#define CMD_PS_MS 0x04
215#define CMD_PS_CONF3_MS 0x04
216#define CMD_PS_CANC_L 0x05
217#define CMD_PS_CANC_M 0x05
218#define CMD_PS_CANC_L_M 0x05
219#define CMD_PS_THDH_L 0x06
220#define CMD_PS_THDH_M 0x06
221#define CMD_PS_THDH_L_M 0x06
222#define CMD_PS_THDL_L 0x07
223#define CMD_PS_THDL_M 0x07
224#define CMD_PS_THDL_L_M 0x07
225#define CMD_PS1_DATA_L 0x08
226#define CMD_PS1_DATA_M 0x08
227#define CMD_PS1_DATA_L_M 0x08
228#define CMD_PS2_DATA_L 0x09
229#define CMD_PS2_DATA_M 0x09
230#define CMD_PS2_DATA_L_M 0x09
231#define CMD_PS3_DATA_L 0x0A
232#define CMD_PS3_DATA_M 0x0A
233#define CMD_PS3_DATA_L_M 0x0A
234#define CMD_ALS_DATA_L 0x0B
235#define CMD_ALS_DATA_M 0x0B
236#define CMD_ALS_DATA_L_M 0x0B
237#define CMD_WHITE_DATA_L 0x0C
238#define CMD_WHITE_DATA_M 0x0C
239#define CMD_WHITE_DATA_L_M 0x0C
240#define RESERVED 0x0D
241#define CMD_INT_FLAG 0x0D
242#define CMD_ID_L 0x0E
243#define CMD_ID_M 0x0E
244#define CMD_ID_L_M 0x0E
251#define PROXIMITY5_ADDR 0x60
255 // End group macro
256// --------------------------------------------------------------- PUBLIC TYPES
265typedef struct
266{
267 // Input pins
268
269 digital_in_t int_pin;
270
271 // Modules
272
273 i2c_master_t i2c;
274
275 // ctx variable
276
278
280
284typedef struct
285{
286 // Communication gpio pins
287
288 pin_name_t scl;
289 pin_name_t sda;
290
291 // Additional gpio pins
292
293 pin_name_t int_pin;
294
295 // static variable
296
297 uint32_t i2c_speed;
298 uint8_t i2c_address;
299
301
305typedef union
306{
307 unsigned char ALL;
308 struct
309 {
310
311 unsigned char ALS_SD : 1;
312 unsigned char ALS_INT_EN : 1;
313 unsigned char ALS_PERS : 2;
314 unsigned char RES : 1;
315 unsigned char ALS_IT : 3;
316 };
317
319
320typedef union
321{
322 unsigned char ALL;
323 struct
324 {
325
326 unsigned char WHITE_SD : 1;
327 unsigned char RES : 7;
328 };
329
331
332typedef union
333{
334 uint16_t ALL;
335 struct
336 {
337
338 uint16_t ALS_THDH_L : 8;
339 uint16_t ALS_THDH_M : 8;
340 };
341
343
344typedef union
345{
346 uint16_t ALL;
347 struct
348 {
349
350 uint16_t LS_THDL_L : 8;
351 uint16_t LS_THDL_M : 8;
352 };
353
355
356typedef union
357{
358 uint16_t ALL;
359 struct
360 {
361
362 uint16_t ALS_DATA_L : 8;
363 uint16_t ALS_DATA_M : 8;
364 };
365
367
368typedef union
369{
370 uint8_t ALL;
371 struct
372 {
373 uint8_t PS_SD : 1;
374 uint8_t PS_IT : 3;
375 uint8_t PS_PERS : 2;
376 uint8_t PS_DUTY : 2;
377 };
378
379} ps_conf1_t;
380
381typedef union
382{
383 uint8_t ALL;
384 struct {
385
386 uint8_t PS_INT_EN : 2;
387 uint8_t PS_NS : 1;
388 uint8_t PS_HD : 1;
389 uint8_t PS_GAIN : 2;
390 uint8_t GEST_MODE : 1;
391 uint8_t GEST_INTEN : 1;
392 };
393
394} ps_conf2_t;
395
396typedef union
397{
398 uint8_t ALL;
399 struct
400 {
401
402 uint8_t PS_SC_EN : 1;
403 uint8_t PS_MS : 1;
404 uint8_t PS_TRIG : 1;
405 uint8_t PS_AF : 1;
406 uint8_t PS_SMART_PERS : 1;
407 uint8_t IRED_SEL : 2;
408 uint8_t LED_I_LOW : 1;
409 };
410
411} ps_conf3_t;
412
413typedef union
414{
415 uint8_t ALL;
416 struct
417 {
418
419 uint8_t LED_I : 3;
420 uint8_t PS_SPO : 1;
421 uint8_t PS_SP : 1;
422 uint8_t PS_SC_CUR : 2;
423 uint8_t RES : 1;
424
425 };
426
427} ps_ms_t;
428
429typedef union
430{
431 uint16_t ALL;
432 struct
433 {
434
435 uint16_t PS_CANC_L : 8;
436 uint16_t PS_CANC_M : 8;
437 };
438
440
441typedef union
442{
443 uint16_t ALL;
444 struct
445 {
446
447 uint16_t PS_THDL_L : 8;
448 uint16_t PS_THDL_M : 8;
449 };
450
452
453typedef union
454{
455 uint16_t ALL;
456 struct
457 {
458
459 uint16_t PS_THDH_L : 8;
460 uint16_t PS_THDH_M : 8;
461 };
462
464
465typedef union
466{
467 uint16_t ALL;
468 struct
469 {
470
471 uint16_t PS1_DATA_L : 8;
472 uint16_t PS1_DATA_M : 8;
473 };
474
476
477typedef union
478{
479 uint16_t ALL;
480 struct {
481
482 uint16_t PS2_DATA_L : 8;
483 uint16_t PS2_DATA_M : 8;
484 };
485
487
488typedef union
489{
490 uint16_t ALL;
491 struct
492 {
493
494 uint16_t PS3_DATA_L : 8;
495 uint16_t PS3_DATA_M : 8;
496 };
497
499
500typedef union
501{
502 uint16_t ALL;
503 struct
504 {
505
506 uint16_t WHITE_DATA_L : 8;
507 uint16_t WHITE_DATA_M : 8;
508 };
509
511
512
513typedef union
514{
515 uint8_t ALL;
516 struct
517 {
518
519 uint8_t PS_IF_AWAY : 1;
520 uint8_t PS_IF_CLOSE : 1;
521 uint8_t RES1 : 1;
522 uint8_t RES0 : 1;
523 uint8_t ALS_IF_H : 1;
524 uint8_t ALS_IF_L : 1;
525 uint8_t PS_SPFLAG : 1;
526 uint8_t GEST_DATA_RDY_FLG : 1;
527 };
528
529} int_flag_t;
530
531
532typedef union
533{
534 uint16_t ALL;
535 struct
536 {
537
538 uint16_t ID_L : 8;
539 uint16_t ID_M : 8;
540
541 };
542
543} id_l_m_t;
544
545 // End types group
546// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
547
553#ifdef __cplusplus
554extern "C"{
555#endif
556
566
576
585
596void proximity5_generic_write ( proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
597
608void proximity5_generic_read ( proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
609
621uint16_t proximity5_read_reg ( proximity5_t *ctx, uint8_t addr );
622
634
645void proximity5_get_values ( proximity5_t *ctx, uint16_t *prox_val );
646
647
648#ifdef __cplusplus
649}
650#endif
651#endif // _PROXIMITY5_H_
652
653 // End public_function group
655
656// ------------------------------------------------------------------------- END
#define PROXIMITY5_RETVAL
Definition proximity5.h:76
uint16_t proximity5_read_reg(proximity5_t *ctx, uint8_t addr)
16bit read function.
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.
void proximity5_generic_write(proximity5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
PROXIMITY5_RETVAL proximity5_init(proximity5_t *ctx, proximity5_cfg_t *cfg)
Initialization function.
void proximity5_get_values(proximity5_t *ctx, uint16_t *prox_val)
Proximity value get function.
uint16_t proximity5_get_id(proximity5_t *ctx)
16bit read function.
void proximity5_cfg_setup(proximity5_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition proximity5.h:285
uint32_t i2c_speed
Definition proximity5.h:297
pin_name_t scl
Definition proximity5.h:288
pin_name_t int_pin
Definition proximity5.h:293
pin_name_t sda
Definition proximity5.h:289
uint8_t i2c_address
Definition proximity5.h:298
Click ctx object definition.
Definition proximity5.h:266
digital_in_t int_pin
Definition proximity5.h:269
i2c_master_t i2c
Definition proximity5.h:273
uint8_t slave_address
Definition proximity5.h:277
Click calibration unions.
Definition proximity5.h:306
unsigned char ALL
Definition proximity5.h:307
unsigned char ALS_IT
Definition proximity5.h:315
unsigned char ALS_PERS
Definition proximity5.h:313
unsigned char ALS_INT_EN
Definition proximity5.h:312
unsigned char RES
Definition proximity5.h:314
unsigned char ALS_SD
Definition proximity5.h:311
Definition proximity5.h:321
unsigned char ALL
Definition proximity5.h:322
unsigned char WHITE_SD
Definition proximity5.h:326
unsigned char RES
Definition proximity5.h:327
Definition proximity5.h:357
uint16_t ALS_DATA_M
Definition proximity5.h:363
uint16_t ALL
Definition proximity5.h:358
uint16_t ALS_DATA_L
Definition proximity5.h:362
Definition proximity5.h:333
uint16_t ALS_THDH_L
Definition proximity5.h:338
uint16_t ALS_THDH_M
Definition proximity5.h:339
uint16_t ALL
Definition proximity5.h:334
Definition proximity5.h:345
uint16_t LS_THDL_M
Definition proximity5.h:351
uint16_t ALL
Definition proximity5.h:346
uint16_t LS_THDL_L
Definition proximity5.h:350
Definition proximity5.h:533
uint16_t ID_M
Definition proximity5.h:539
uint16_t ALL
Definition proximity5.h:534
uint16_t ID_L
Definition proximity5.h:538
Definition proximity5.h:514
uint8_t PS_IF_CLOSE
Definition proximity5.h:520
uint8_t ALS_IF_H
Definition proximity5.h:523
uint8_t ALS_IF_L
Definition proximity5.h:524
uint8_t PS_SPFLAG
Definition proximity5.h:525
uint8_t ALL
Definition proximity5.h:515
uint8_t RES1
Definition proximity5.h:521
uint8_t RES0
Definition proximity5.h:522
uint8_t PS_IF_AWAY
Definition proximity5.h:519
uint8_t GEST_DATA_RDY_FLG
Definition proximity5.h:526
Definition proximity5.h:466
uint16_t PS1_DATA_L
Definition proximity5.h:471
uint16_t PS1_DATA_M
Definition proximity5.h:472
uint16_t ALL
Definition proximity5.h:467
Definition proximity5.h:478
uint16_t PS2_DATA_M
Definition proximity5.h:483
uint16_t ALL
Definition proximity5.h:479
uint16_t PS2_DATA_L
Definition proximity5.h:482
Definition proximity5.h:489
uint16_t PS3_DATA_L
Definition proximity5.h:494
uint16_t PS3_DATA_M
Definition proximity5.h:495
uint16_t ALL
Definition proximity5.h:490
Definition proximity5.h:430
uint16_t PS_CANC_L
Definition proximity5.h:435
uint16_t ALL
Definition proximity5.h:431
uint16_t PS_CANC_M
Definition proximity5.h:436
Definition proximity5.h:369
uint8_t PS_SD
Definition proximity5.h:373
uint8_t PS_DUTY
Definition proximity5.h:376
uint8_t ALL
Definition proximity5.h:370
uint8_t PS_IT
Definition proximity5.h:374
uint8_t PS_PERS
Definition proximity5.h:375
Definition proximity5.h:382
uint8_t PS_GAIN
Definition proximity5.h:389
uint8_t PS_HD
Definition proximity5.h:388
uint8_t PS_NS
Definition proximity5.h:387
uint8_t ALL
Definition proximity5.h:383
uint8_t GEST_INTEN
Definition proximity5.h:391
uint8_t PS_INT_EN
Definition proximity5.h:386
uint8_t GEST_MODE
Definition proximity5.h:390
Definition proximity5.h:397
uint8_t LED_I_LOW
Definition proximity5.h:408
uint8_t PS_SC_EN
Definition proximity5.h:402
uint8_t PS_MS
Definition proximity5.h:403
uint8_t PS_AF
Definition proximity5.h:405
uint8_t IRED_SEL
Definition proximity5.h:407
uint8_t ALL
Definition proximity5.h:398
uint8_t PS_TRIG
Definition proximity5.h:404
uint8_t PS_SMART_PERS
Definition proximity5.h:406
Definition proximity5.h:414
uint8_t LED_I
Definition proximity5.h:419
uint8_t ALL
Definition proximity5.h:415
uint8_t RES
Definition proximity5.h:423
uint8_t PS_SC_CUR
Definition proximity5.h:422
uint8_t PS_SP
Definition proximity5.h:421
uint8_t PS_SPO
Definition proximity5.h:420
Definition proximity5.h:454
uint16_t PS_THDH_L
Definition proximity5.h:459
uint16_t ALL
Definition proximity5.h:455
uint16_t PS_THDH_M
Definition proximity5.h:460
Definition proximity5.h:442
uint16_t PS_THDL_M
Definition proximity5.h:448
uint16_t ALL
Definition proximity5.h:443
uint16_t PS_THDL_L
Definition proximity5.h:447
Definition proximity5.h:501
uint16_t ALL
Definition proximity5.h:502
uint16_t WHITE_DATA_M
Definition proximity5.h:507
uint16_t WHITE_DATA_L
Definition proximity5.h:506