LibDriver APDS9960
Loading...
Searching...
No Matches
driver_apds9960.c
Go to the documentation of this file.
1
36
37#include "driver_apds9960.h"
38#include <stdlib.h>
39
43#define CHIP_NAME "Broadcom APDS9960"
44#define MANUFACTURER_NAME "Broadcom"
45#define SUPPLY_VOLTAGE_MIN 2.4f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 100.0f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 1000
51
55#define APDS9960_ADDRESS 0x72
56
60#define APDS9960_REG_ENABLE 0x80
61#define APDS9960_REG_ATIME 0x81
62#define APDS9960_REG_WTIME 0x83
63#define APDS9960_REG_AILTL 0x84
64#define APDS9960_REG_AILTH 0x85
65#define APDS9960_REG_AIHTL 0x86
66#define APDS9960_REG_AIHTH 0x87
67#define APDS9960_REG_PILT 0x89
68#define APDS9960_REG_PIHT 0x8B
69#define APDS9960_REG_PERS 0x8C
70#define APDS9960_REG_CONFIG1 0x8D
71#define APDS9960_REG_PPULSE 0x8E
72#define APDS9960_REG_CONTROL 0x8F
73#define APDS9960_REG_CONFIG2 0x90
74#define APDS9960_REG_ID 0x92
75#define APDS9960_REG_STATUS 0x93
76#define APDS9960_REG_CDATAL 0x94
77#define APDS9960_REG_CDATAH 0x95
78#define APDS9960_REG_RDATAL 0x96
79#define APDS9960_REG_RDATAH 0x97
80#define APDS9960_REG_GDATAL 0x98
81#define APDS9960_REG_GDATAH 0x99
82#define APDS9960_REG_BDATAL 0x9A
83#define APDS9960_REG_BDATAH 0x9B
84#define APDS9960_REG_PDATA 0x9C
85#define APDS9960_REG_POFFSET_UR 0x9D
86#define APDS9960_REG_POFFSET_DL 0x9E
87#define APDS9960_REG_CONFIG3 0x9F
88#define APDS9960_REG_GPENTH 0xA0
89#define APDS9960_REG_GEXTH 0xA1
90#define APDS9960_REG_GCONF1 0xA2
91#define APDS9960_REG_GCONF2 0xA3
92#define APDS9960_REG_GOFFSET_U 0xA4
93#define APDS9960_REG_GOFFSET_D 0xA5
94#define APDS9960_REG_GOFFSET_L 0xA7
95#define APDS9960_REG_GOFFSET_R 0xA9
96#define APDS9960_REG_GPULSE 0xA6
97#define APDS9960_REG_GCONF3 0xAA
98#define APDS9960_REG_GCONF4 0xAB
99#define APDS9960_REG_GFLVL 0xAE
100#define APDS9960_REG_GSTATUS 0xAF
101#define APDS9960_REG_IFORCE 0xE4
102#define APDS9960_REG_PICLEAR 0xE5
103#define APDS9960_REG_CICLEAR 0xE6
104#define APDS9960_REG_AICLEAR 0xE7
105#define APDS9960_REG_GFIFO_U 0xFC
106#define APDS9960_REG_GFIFO_D 0xFD
107#define APDS9960_REG_GFIFO_L 0xFE
108#define APDS9960_REG_GFIFO_R 0xFF
109
121static uint8_t a_apds9960_iic_read(apds9960_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
122{
123 if (handle->iic_read(APDS9960_ADDRESS, reg, data, len) != 0) /* read the register */
124 {
125 return 1; /* return error */
126 }
127 else
128 {
129 return 0; /* success return 0 */
130 }
131}
132
144static uint8_t a_apds9960_iic_write(apds9960_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
145{
146 if (handle->iic_write(APDS9960_ADDRESS, reg, data, len) != 0) /* write the register */
147 {
148 return 1; /* return error */
149 }
150 else
151 {
152 return 0; /* success return 0 */
153 }
154}
155
169{
170 uint8_t id;
171
172 if (handle == NULL) /* check handle */
173 {
174 return 2; /* return error */
175 }
176 if (handle->debug_print == NULL) /* check debug_print */
177 {
178 return 3; /* return error */
179 }
180 if (handle->iic_init == NULL) /* check iic_init */
181 {
182 handle->debug_print("apds9960: iic_init is null.\n"); /* iic_init is null */
183
184 return 3; /* return error */
185 }
186 if (handle->iic_deinit == NULL) /* check iic_deinit */
187 {
188 handle->debug_print("apds9960: iic_deinit is null.\n"); /* iic_deinit is null */
189
190 return 3; /* return error */
191 }
192 if (handle->iic_read == NULL) /* check iic_read */
193 {
194 handle->debug_print("apds9960: iic_read is null.\n"); /* iic_read is null */
195
196 return 3; /* return error */
197 }
198 if (handle->iic_write == NULL) /* check iic_write */
199 {
200 handle->debug_print("apds9960: iic_write is null.\n"); /* iic_write is null */
201
202 return 3; /* return error */
203 }
204 if (handle->delay_ms == NULL) /* check delay_ms */
205 {
206 handle->debug_print("apds9960: delay_ms is null.\n"); /* delay_ms is null */
207
208 return 3; /* return error */
209 }
210 if (handle->receive_callback == NULL) /* check receive_callback */
211 {
212 handle->debug_print("apds9960: receive_callback is null.\n"); /* receive_callback is null */
213
214 return 3; /* return error */
215 }
216
217 if (handle->iic_init() != 0) /* iic init */
218 {
219 handle->debug_print("apds9960: iic init failed.\n"); /* iic init failed */
220
221 return 1; /* return error */
222 }
223 if (a_apds9960_iic_read(handle, APDS9960_REG_ID, (uint8_t *)&id, 1) != 0)/* read id */
224 {
225 handle->debug_print("apds9960: read id failed.\n"); /* read id failed */
226 (void)handle->iic_deinit(); /* iic deinit */
227
228 return 4; /* return error */
229 }
230 if (id != 0xAB) /* check id */
231 {
232 handle->debug_print("apds9960: id is invalid.\n"); /* id is invalid */
233 (void)handle->iic_deinit(); /* iic deinit */
234
235 return 5; /* return error */
236 }
237 handle->gesture_status = 0; /* clear the gesture status */
238 handle->gesture_threshold = APDS9960_GESTURE_THRESHOLD; /* set the default gesture threshold */
239 handle->gesture_sensitivity_1 = APDS9960_GESTURE_SENSITIVITY_1; /* set the default gesture sensitivity 1 */
240 handle->gesture_sensitivity_2 = APDS9960_GESTURE_SENSITIVITY_2; /* set the default gesture sensitivity 2 */
241 handle->gesture_ud_delta = 0; /* set gesture_ud_delta 0 */
242 handle->gesture_lr_delta = 0; /* set gesture_lr_delta 0 */
243 handle->gesture_ud_count = 0; /* set gesture_ud_count 0 */
244 handle->gesture_lr_count = 0; /* set gesture_lr_count 0 */
245 handle->gesture_near_count = 0; /* set gesture_near_count 0 */
246 handle->gesture_far_count = 0; /* set gesture_far_count 0 */
247 handle->inited = 1; /* flag inited */
248
249 return 0; /* success return 0 */
250}
251
264{
265 uint8_t res, prev;
266
267 if (handle == NULL) /* check handle */
268 {
269 return 2; /* return error */
270 }
271 if (handle->inited != 1) /* check handle initialization */
272 {
273 return 3; /* return error */
274 }
275
276 res = a_apds9960_iic_read(handle, APDS9960_REG_ENABLE, (uint8_t *)&prev, 1); /* read enable register */
277 if (res != 0) /* check the result */
278 {
279 handle->debug_print("apds9960: read enable register failed.\n"); /* read enable register failed */
280
281 return 4; /* return error */
282 }
283 prev &= ~(1 << 0); /* set power down */
284 res = a_apds9960_iic_write(handle, APDS9960_REG_ENABLE, (uint8_t *)&prev, 1); /* write enable register */
285 if (res != 0) /* check the result */
286 {
287 handle->debug_print("apds9960: write enable register failed.\n"); /* write enable register failed */
288
289 return 4; /* return error */
290 }
291 res = handle->iic_deinit(); /* iic deinit */
292 if (res != 0) /* check the result */
293 {
294 handle->debug_print("apds9960: iic deinit failed.\n"); /* iic deinit failed */
295
296 return 1; /* return error */
297 }
298 else
299 {
300 handle->inited = 0; /* flag closed */
301
302 return 0; /* success return 0 */
303 }
304}
305
317{
318 uint8_t res, prev, prev1;
319 uint8_t times;
320
321 if (handle == NULL) /* check handle */
322 {
323 return 2; /* return error */
324 }
325 if (handle->inited != 1) /* check handle initialization */
326 {
327 return 3; /* return error */
328 }
329
330 res = a_apds9960_iic_read(handle, APDS9960_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
331 if (res != 0) /* check the result */
332 {
333 handle->debug_print("apds9960: read status failed.\n"); /* read status failed */
334
335 return 1; /* return error */
336 }
337 res = a_apds9960_iic_read(handle, APDS9960_REG_GSTATUS, (uint8_t *)&prev1, 1); /* read gesture status */
338 if (res != 0) /* check the result */
339 {
340 handle->debug_print("apds9960: read gesture status failed.\n"); /* read gesture status failed */
341
342 return 1; /* return error */
343 }
344
345 if ((prev & (1 << APDS9960_STATUS_CPSAT)) != 0) /* check clear photo diode saturation */
346 {
347 if (handle->receive_callback != NULL) /* if valid */
348 {
349 handle->receive_callback(APDS9960_INTERRUPT_STATUS_CPSAT); /* run the callback */
350 }
351 }
352 if ((prev & (1 << APDS9960_STATUS_PGSAT)) != 0) /* check analog saturation */
353 {
354 if (handle->receive_callback != NULL) /* if valid */
355 {
356 handle->receive_callback(APDS9960_INTERRUPT_STATUS_PGSAT); /* run the callback */
357 }
358 }
359 if ((prev & (1 << APDS9960_STATUS_PINT)) != 0) /* check proximity interrupt */
360 {
361 if (handle->receive_callback != NULL) /* if valid */
362 {
363 handle->receive_callback(APDS9960_INTERRUPT_STATUS_PINT); /* run the callback */
364 }
365 }
366 if ((prev & (1 << APDS9960_STATUS_AINT)) != 0) /* check als interrupt */
367 {
368 if (handle->receive_callback != NULL) /* if valid */
369 {
370 handle->receive_callback(APDS9960_INTERRUPT_STATUS_AINT); /* run the callback */
371 }
372 }
373 if ((prev & (1 << APDS9960_STATUS_GINT)) != 0) /* gesture interrupt */
374 {
375 if (handle->receive_callback != NULL) /* if valid */
376 {
377 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GINT); /* run the callback */
378 }
379 }
380 if ((prev & (1 << APDS9960_STATUS_PVALID)) != 0) /* check proximity valid */
381 {
382 if (handle->receive_callback != NULL) /* if valid */
383 {
384 handle->receive_callback(APDS9960_INTERRUPT_STATUS_PVALID); /* run the callback */
385 }
386 }
387 if ((prev & (1 << APDS9960_STATUS_AVALID)) != 0) /* check als valid */
388 {
389 if (handle->receive_callback != NULL) /* if valid */
390 {
391 handle->receive_callback(APDS9960_INTERRUPT_STATUS_AVALID); /* run the callback */
392 }
393 }
394 if ((prev1 & (1 << APDS9960_GESTURE_STATUS_FIFO_OVERFLOW)) != 0) /* check gesture fifo overflow */
395 {
396 if (handle->receive_callback != NULL) /* if valid */
397 {
398 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GFOV); /* run the callback */
399 }
400 }
401 if ((prev1 & (1 << APDS9960_GESTURE_STATUS_FIFO_VALID)) != 0) /* check gesture fifo data */
402 {
403 if (handle->receive_callback != NULL) /* if valid */
404 {
405 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GVALID); /* run the callback */
406 }
407 }
408
409 times = 3; /* set retry times */
410 while (1) /* retry label */
411 {
412 prev = 0xFF; /* set 0xFF */
413 res = a_apds9960_iic_write(handle, APDS9960_REG_AICLEAR, (uint8_t *)&prev, 1); /* clear all non-gesture interrupts */
414 if (res != 0) /* check result */
415 {
416 if (times != 0) /* check retry times */
417 {
418 times--; /* times-- */
419
420 continue; /* continue */
421 }
422
423 handle->debug_print("apds9960: clear all non-gesture interrupts failed.\n"); /* clear all non-gesture interrupts failed */
424
425 return 1; /* return error */
426 }
427
428 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* get gesture conf 4 register */
429 if (res != 0) /* check result */
430 {
431 if (times != 0) /* check retry times */
432 {
433 times--; /* times-- */
434
435 continue; /* continue */
436 }
437
438 handle->debug_print("apds9960: get gesture conf 4 register failed.\n"); /* get gesture conf 4 register failed */
439
440 return 1; /* return error */
441 }
442 prev &= ~(1 << 2); /* clear config */
443 prev |= 1 << 2; /* set config */
444 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* set gesture conf 4 register */
445 if (res != 0) /* check result */
446 {
447 if (times != 0) /* check retry times */
448 {
449 times--; /* times-- */
450
451 continue; /* continue */
452 }
453
454 handle->debug_print("apds9960: set gesture conf 4 register failed.\n"); /* set gesture conf 4 register failed */
455
456 return 1; /* return error */
457 }
458
459 break; /* break */
460 }
461
462 prev = handle->gesture_status; /* get the gesture status */
463 if ((prev & (1 << 0)) != 0) /* check far */
464 {
465 if (handle->receive_callback != NULL) /* if valid */
466 {
467 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GESTURE_FAR); /* run the callback */
468 }
469 }
470 if ((prev & (1 << 1)) != 0) /* check near */
471 {
472 if (handle->receive_callback != NULL) /* if valid */
473 {
474 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GESTURE_NEAR); /* run the callback */
475 }
476 }
477 if ((prev & (1 << 2)) != 0) /* check down */
478 {
479 if (handle->receive_callback != NULL) /* if valid */
480 {
481 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GESTURE_DOWN); /* run the callback */
482 }
483 }
484 if ((prev & (1 << 3)) != 0) /* check up */
485 {
486 if (handle->receive_callback != NULL) /* if valid */
487 {
488 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GESTURE_UP); /* run the callback */
489 }
490 }
491 if ((prev & (1 << 4)) != 0) /* check right */
492 {
493 if (handle->receive_callback != NULL) /* if valid */
494 {
495 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GESTURE_RIGHT); /* run the callback */
496 }
497 }
498 if ((prev & (1 << 5)) != 0) /* check left */
499 {
500 if (handle->receive_callback != NULL) /* if valid */
501 {
502 handle->receive_callback(APDS9960_INTERRUPT_STATUS_GESTURE_LEFT); /* run the callback */
503 }
504 }
505 handle->gesture_status = 0; /* clear the gesture status */
506 if (prev != 0) /* if we find gesture */
507 {
508 handle->gesture_ud_delta = 0; /* set gesture_ud_delta 0 */
509 handle->gesture_lr_delta = 0; /* set gesture_lr_delta 0 */
510 handle->gesture_ud_count = 0; /* set gesture_ud_count 0 */
511 handle->gesture_lr_count = 0; /* set gesture_lr_count 0 */
512 handle->gesture_near_count = 0; /* set gesture_near_count 0 */
513 handle->gesture_far_count = 0; /* set gesture_far_count 0 */
514 }
515
516 return 0; /* success return 0 */
517}
518
532uint8_t apds9960_gesture_decode(apds9960_handle_t *handle, uint8_t (*data)[4], uint8_t len)
533{
534 int8_t i;
535 uint8_t u_first, d_first, l_first, r_first;
536 uint8_t u_last, d_last, l_last, r_last;
537 int32_t ud_ratio_first, lr_ratio_first, ud_ratio_last, lr_ratio_last;
538 int32_t ud_delta, lr_delta;
539
540 if (handle == NULL) /* check handle */
541 {
542 return 2; /* return error */
543 }
544 if (handle->inited != 1) /* check handle initialization */
545 {
546 return 3; /* return error */
547 }
548 if (len < 4) /* check len */
549 {
550 handle->debug_print("apds9960: fifo level must be over 4.\n"); /* fifo level must be over 4 */
551
552 return 4; /* return error */
553 }
554
555 u_first = 0; /* clear up first */
556 d_first = 0; /* clear down first */
557 l_first = 0; /* clear left first */
558 r_first = 0; /* clear right first */
559 u_last = 0; /* clear up last */
560 d_last = 0; /* clear down last */
561 l_last = 0; /* clear left last */
562 r_last = 0; /* clear right last */
563 for (i = 0; i < len; i++) /* run len times */
564 {
565 if ((data[i][0] > handle->gesture_threshold) && /* check gesture threshold */
566 (data[i][1] > handle->gesture_threshold) && /* check gesture threshold */
567 (data[i][2] > handle->gesture_threshold) && /* check gesture threshold */
568 (data[i][3] > handle->gesture_threshold) /* check gesture threshold */
569 )
570 {
571 u_first = data[i][0]; /* set up first */
572 d_first = data[i][1]; /* set down first */
573 l_first = data[i][2]; /* set left first */
574 r_first = data[i][3]; /* set right first */
575
576 break; /* break */
577 }
578 }
579 if ((u_first == 0) || /* check up first */
580 (d_first == 0) || /* check down first */
581 (l_first == 0) || /* check left first */
582 (r_first == 0) /* check right first */
583 )
584 {
585 goto decode; /* go to decode */
586 }
587 for (i = len - 1; i >= 0; i--) /* run len times */
588 {
589 if ((data[i][0] > handle->gesture_threshold) && /* check gesture threshold */
590 (data[i][1] > handle->gesture_threshold) && /* check gesture threshold */
591 (data[i][2] > handle->gesture_threshold) && /* check gesture threshold */
592 (data[i][3] > handle->gesture_threshold) /* check gesture threshold */
593 )
594 {
595 u_last = data[i][0]; /* set up last */
596 d_last = data[i][1]; /* set down last */
597 l_last = data[i][2]; /* set left last */
598 r_last = data[i][3]; /* set right last */
599
600 break; /* break */
601 }
602 }
603 ud_ratio_first = ((u_first - d_first) * 100) / (u_first + d_first); /* get ud ratio first */
604 lr_ratio_first = ((l_first - r_first) * 100) / (l_first + r_first); /* get lr ratio first */
605 ud_ratio_last = ((u_last - d_last) * 100) / (u_last + d_last); /* get ud ratio last */
606 lr_ratio_last = ((l_last - r_last) * 100) / (l_last + r_last); /* get lr ratio last */
607 ud_delta = ud_ratio_last - ud_ratio_first; /* get ud delta */
608 lr_delta = lr_ratio_last - lr_ratio_first; /* get lr delta */
609 handle->gesture_ud_delta += ud_delta; /* gesture_ud_delta++ */
610 handle->gesture_lr_delta += lr_delta; /* gesture_lr_delta++ */
611
612 if (handle->gesture_ud_delta >= handle->gesture_sensitivity_1) /* check gesture_ud_delta */
613 {
614 handle->gesture_ud_count = 1; /* set gesture_ud_count 1 */
615 }
616 else if (handle->gesture_ud_delta <= -handle->gesture_sensitivity_1) /* check gesture_ud_delta */
617 {
618 handle->gesture_ud_count = -1; /* set gesture_ud_count -1 */
619 }
620 else
621 {
622 handle->gesture_ud_count = 0; /* set gesture_ud_count 0 */
623 }
624 if (handle->gesture_lr_delta >= handle->gesture_sensitivity_1) /* check gesture_lr_delta */
625 {
626 handle->gesture_lr_count = 1; /* set gesture_lr_count 1 */
627 }
628 else if (handle->gesture_lr_delta <= -handle->gesture_sensitivity_1) /* check gesture_lr_delta */
629 {
630 handle->gesture_lr_count = -1; /* set gesture_lr_count -1 */
631 }
632 else
633 {
634 handle->gesture_lr_count = 0; /* set gesture_lr_count 0 */
635 }
636
637 if ((handle->gesture_ud_count == 0) && (handle->gesture_lr_count == 0)) /* check gesture_ud_count && gesture_lr_count */
638 {
639 if ((abs(ud_delta) < handle->gesture_sensitivity_2) && /* check ud_delta */
640 (abs(lr_delta) < handle->gesture_sensitivity_2)) /* check lr_delta */
641 {
642 if ((ud_delta == 0) && (lr_delta == 0)) /* if ud_delta == 0 && lr_delta == 0 */
643 {
644 handle->gesture_near_count++; /* gesture_near_count++ */
645 }
646 else if ((ud_delta != 0) || (lr_delta != 0)) /* if ud_delta != 0 && lr_delta != 0 */
647 {
648 handle->gesture_far_count++; /* gesture_far_count++ */
649 }
650 else
651 {
652
653 }
654 if ((handle->gesture_near_count >= 10) && /* check gesture_near_count */
655 (handle->gesture_far_count >= 2)) /* check gesture_far_count */
656 {
657 if ((ud_delta == 0) && (lr_delta == 0)) /* if ud_delta == 0 && lr_delta == 0 */
658 {
659 handle->gesture_status |= 1 << 1; /* near */
660 }
661 else if ((ud_delta != 0) && (lr_delta != 0)) /* if ud_delta != 0 && lr_delta != 0 */
662 {
663 handle->gesture_status |= 1 << 0; /* far */
664 }
665 else
666 {
667 /* do nothing */
668 }
669 }
670 }
671 }
672 else
673 {
674 if ((abs(ud_delta) < handle->gesture_sensitivity_2) && /* check ud_delta */
675 (abs(lr_delta) < handle->gesture_sensitivity_2)) /* check lr_delta */
676 {
677 if ((ud_delta == 0) && (lr_delta == 0)) /* if ud_delta == 0 && lr_delta == 0 */
678 {
679 handle->gesture_near_count++; /* gesture_near_count++ */
680 }
681 if (handle->gesture_near_count >= 10) /* if gesture_near_count >= 10 */
682 {
683 handle->gesture_ud_count = 0; /* set gesture_ud_count 0 */
684 handle->gesture_lr_count = 0; /* set gesture_lr_count 0 */
685 handle->gesture_ud_delta = 0; /* set gesture_ud_delta 0 */
686 handle->gesture_lr_delta = 0; /* set gesture_lr_delta 0 */
687 }
688 }
689 }
690
691 decode:
692
693 if ((handle->gesture_ud_count == -1) && (handle->gesture_lr_count == 0)) /* if gesture_ud_count == -1 && gesture_lr_count == 0 */
694 {
695 handle->gesture_status |= 1 << 4; /* right */
696 }
697 else if ((handle->gesture_ud_count == 1) && (handle->gesture_lr_count == 0)) /* if gesture_ud_count == 1 && gesture_lr_count == 0 */
698 {
699 handle->gesture_status |= 1 << 5; /* left */
700 }
701 else if ((handle->gesture_ud_count == 0) && (handle->gesture_lr_count == 1)) /* if gesture_ud_count == 0 && gesture_lr_count == 1 */
702 {
703 handle->gesture_status |= 1 << 2; /* down */
704 }
705 else if ((handle->gesture_ud_count == 0) && (handle->gesture_lr_count == -1)) /* if gesture_ud_count == 0 && gesture_lr_count == -1 */
706 {
707 handle->gesture_status |= 1 << 3; /* up */
708 }
709 else if ((handle->gesture_ud_count == -1) && (handle->gesture_lr_count == 1)) /* if gesture_ud_count == -1 && gesture_lr_count == 1 */
710 {
711 if (abs(handle->gesture_ud_delta) > abs(handle->gesture_lr_delta)) /* check gesture_ud_delta && gesture_lr_delta */
712 {
713 handle->gesture_status |= 1 << 4; /* right */
714 }
715 else
716 {
717 handle->gesture_status |= 1 << 2; /* down */
718 }
719 }
720 else if ((handle->gesture_ud_count == 1) && (handle->gesture_lr_count == -1)) /* if gesture_ud_count == 1 && gesture_lr_count == -1 */
721 {
722 if (abs(handle->gesture_ud_delta) > abs(handle->gesture_lr_delta)) /* check gesture_ud_delta && gesture_lr_delta */
723 {
724 handle->gesture_status |= 1 << 5; /* left */
725 }
726 else
727 {
728 handle->gesture_status |= 1 << 3; /* up */
729 }
730 }
731 else if ((handle->gesture_ud_count == -1) && (handle->gesture_lr_count == -1)) /* if gesture_ud_count == -1 && gesture_lr_count == -1 */
732 {
733 if (abs(handle->gesture_ud_delta) > abs(handle->gesture_lr_delta)) /* check gesture_ud_delta && gesture_lr_delta */
734 {
735 handle->gesture_status |= 1 << 4; /* right */
736 }
737 else
738 {
739 handle->gesture_status |= 1 << 3; /* up */
740 }
741 }
742 else if ((handle->gesture_ud_count == 1) && (handle->gesture_lr_count == 1)) /* if gesture_ud_count == 1 && gesture_lr_count == 1 */
743 {
744 if (abs(handle->gesture_ud_delta) > abs(handle->gesture_lr_delta)) /* check gesture_ud_delta && gesture_lr_delta */
745 {
746 handle->gesture_status |= 1 << 5; /* left */
747 }
748 else
749 {
750 handle->gesture_status |= 1 << 2; /* down */
751 }
752 }
753 else
754 {
755
756 }
757
758 return 0; /* success return 0 */
759}
760
773{
774 if (handle == NULL) /* check handle */
775 {
776 return 2; /* return error */
777 }
778 if (handle->inited != 1) /* check handle initialization */
779 {
780 return 3; /* return error */
781 }
782
783 handle->gesture_threshold = threshold; /* set threshold */
784
785 return 0; /* success return 0 */
786}
787
800{
801 if (handle == NULL) /* check handle */
802 {
803 return 2; /* return error */
804 }
805 if (handle->inited != 1) /* check handle initialization */
806 {
807 return 3; /* return error */
808 }
809
810 *threshold = handle->gesture_threshold; /* get threshold */
811
812 return 0; /* success return 0 */
813}
814
827{
828 if (handle == NULL) /* check handle */
829 {
830 return 2; /* return error */
831 }
832 if (handle->inited != 1) /* check handle initialization */
833 {
834 return 3; /* return error */
835 }
836
837 handle->gesture_sensitivity_1 = sensitivity; /* set sensitivity */
838
839 return 0; /* success return 0 */
840}
841
854{
855 if (handle == NULL) /* check handle */
856 {
857 return 2; /* return error */
858 }
859 if (handle->inited != 1) /* check handle initialization */
860 {
861 return 3; /* return error */
862 }
863
864 *sensitivity = handle->gesture_sensitivity_1; /* get sensitivity */
865
866 return 0; /* success return 0 */
867}
868
881{
882 if (handle == NULL) /* check handle */
883 {
884 return 2; /* return error */
885 }
886 if (handle->inited != 1) /* check handle initialization */
887 {
888 return 3; /* return error */
889 }
890
891 handle->gesture_sensitivity_2 = sensitivity; /* set sensitivity */
892
893 return 0; /* success return 0 */
894}
895
908{
909 if (handle == NULL) /* check handle */
910 {
911 return 2; /* return error */
912 }
913 if (handle->inited != 1) /* check handle initialization */
914 {
915 return 3; /* return error */
916 }
917
918 *sensitivity = handle->gesture_sensitivity_2; /* get sensitivity */
919
920 return 0; /* success return 0 */
921}
922
936{
937 uint8_t res;
938 uint8_t prev;
939
940 if (handle == NULL) /* check handle */
941 {
942 return 2; /* return error */
943 }
944 if (handle->inited != 1) /* check handle initialization */
945 {
946 return 3; /* return error */
947 }
948
949 res = a_apds9960_iic_read(handle, APDS9960_REG_ENABLE, (uint8_t *)&prev, 1); /* get enable */
950 if (res != 0) /* check result */
951 {
952 handle->debug_print("apds9960: get enable failed.\n"); /* get enable failed */
953
954 return 1; /* return error */
955 }
956 prev &= ~(1 << conf); /* clear conf */
957 prev |= enable << conf; /* set conf */
958 res = a_apds9960_iic_write(handle, APDS9960_REG_ENABLE, (uint8_t *)&prev, 1); /* set enable */
959 if (res != 0) /* check result */
960 {
961 handle->debug_print("apds9960: set enable failed.\n"); /* set enable failed */
962
963 return 1; /* return error */
964 }
965
966 return 0; /* success return 0 */
967}
968
982{
983 uint8_t res;
984 uint8_t prev;
985
986 if (handle == NULL) /* check handle */
987 {
988 return 2; /* return error */
989 }
990 if (handle->inited != 1) /* check handle initialization */
991 {
992 return 3; /* return error */
993 }
994
995 res = a_apds9960_iic_read(handle, APDS9960_REG_ENABLE, (uint8_t *)&prev, 1); /* get enable */
996 if (res != 0) /* check result */
997 {
998 handle->debug_print("apds9960: get enable failed.\n"); /* get enable failed */
999
1000 return 1; /* return error */
1001 }
1002 *enable = (apds9960_bool_t)((prev >> conf) & 0x01); /* get bool */
1003
1004 return 0; /* success return 0 */
1005}
1006
1018uint8_t apds9960_set_adc_integration_time(apds9960_handle_t *handle, uint8_t integration_time)
1019{
1020 uint8_t res;
1021 uint8_t prev;
1022
1023 if (handle == NULL) /* check handle */
1024 {
1025 return 2; /* return error */
1026 }
1027 if (handle->inited != 1) /* check handle initialization */
1028 {
1029 return 3; /* return error */
1030 }
1031
1032 prev = integration_time; /* set integration time */
1033 res = a_apds9960_iic_write(handle, APDS9960_REG_ATIME, (uint8_t *)&prev, 1); /* set atime */
1034 if (res != 0) /* check result */
1035 {
1036 handle->debug_print("apds9960: set atime failed.\n"); /* set atime failed */
1037
1038 return 1; /* return error */
1039 }
1040
1041 return 0; /* success return 0 */
1042}
1043
1055uint8_t apds9960_get_adc_integration_time(apds9960_handle_t *handle, uint8_t *integration_time)
1056{
1057 uint8_t res;
1058 uint8_t prev;
1059
1060 if (handle == NULL) /* check handle */
1061 {
1062 return 2; /* return error */
1063 }
1064 if (handle->inited != 1) /* check handle initialization */
1065 {
1066 return 3; /* return error */
1067 }
1068
1069 res = a_apds9960_iic_read(handle, APDS9960_REG_ATIME, (uint8_t *)&prev, 1); /* get atime */
1070 if (res != 0) /* check result */
1071 {
1072 handle->debug_print("apds9960: get atime failed.\n"); /* get atime failed */
1073
1074 return 1; /* return error */
1075 }
1076 *integration_time = prev; /* get integration time */
1077
1078 return 0; /* success return 0 */
1079}
1080
1093{
1094 if (handle == NULL) /* check handle */
1095 {
1096 return 2; /* return error */
1097 }
1098 if (handle->inited != 1) /* check handle initialization */
1099 {
1100 return 3; /* return error */
1101 }
1102
1103 *reg = (uint8_t)(256.0f - ms / 2.78f); /* convert real data to register data */
1104
1105 return 0; /* success return 0 */
1106}
1107
1120{
1121 if (handle == NULL) /* check handle */
1122 {
1123 return 2; /* return error */
1124 }
1125 if (handle->inited != 1) /* check handle initialization */
1126 {
1127 return 3; /* return error */
1128 }
1129
1130 *ms = (float)(256 - reg) * 2.78f; /* convert raw data to real data */
1131
1132 return 0; /* success return 0 */
1133}
1134
1146uint8_t apds9960_set_wait_time(apds9960_handle_t *handle, uint8_t wait_time)
1147{
1148 uint8_t res;
1149 uint8_t prev;
1150
1151 if (handle == NULL) /* check handle */
1152 {
1153 return 2; /* return error */
1154 }
1155 if (handle->inited != 1) /* check handle initialization */
1156 {
1157 return 3; /* return error */
1158 }
1159
1160 prev = wait_time; /* set wait time */
1161 res = a_apds9960_iic_write(handle, APDS9960_REG_WTIME, (uint8_t *)&prev, 1); /* set wtime */
1162 if (res != 0) /* check result */
1163 {
1164 handle->debug_print("apds9960: set wtime failed.\n"); /* set wtime failed */
1165
1166 return 1; /* return error */
1167 }
1168
1169 return 0; /* success return 0 */
1170}
1171
1183uint8_t apds9960_get_wait_time(apds9960_handle_t *handle, uint8_t *wait_time)
1184{
1185 uint8_t res;
1186 uint8_t prev;
1187
1188 if (handle == NULL) /* check handle */
1189 {
1190 return 2; /* return error */
1191 }
1192 if (handle->inited != 1) /* check handle initialization */
1193 {
1194 return 3; /* return error */
1195 }
1196
1197 res = a_apds9960_iic_read(handle, APDS9960_REG_WTIME, (uint8_t *)&prev, 1); /* get wtime */
1198 if (res != 0) /* check result */
1199 {
1200 handle->debug_print("apds9960: get wtime failed.\n"); /* get wtime failed */
1201
1202 return 1; /* return error */
1203 }
1204 *wait_time = prev; /* get wait time */
1205
1206 return 0; /* success return 0 */
1207}
1208
1221uint8_t apds9960_wait_time_convert_to_register(apds9960_handle_t *handle, float ms, uint8_t *reg)
1222{
1223 uint8_t res;
1224 uint8_t prev;
1225
1226 if (handle == NULL) /* check handle */
1227 {
1228 return 2; /* return error */
1229 }
1230 if (handle->inited != 1) /* check handle initialization */
1231 {
1232 return 3; /* return error */
1233 }
1234
1235 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG1, (uint8_t *)&prev, 1); /* get configuration register 1 */
1236 if (res != 0) /* check result */
1237 {
1238 handle->debug_print("apds9960: get configuration register 1 failed.\n"); /* get configuration register 1 failed */
1239
1240 return 1; /* return error */
1241 }
1242
1243 if ((prev & (1 << 1)) != 0) /* check wait long */
1244 {
1245 *reg = (uint8_t)(256.0f - ms / (2.78f * 12.0f)); /* convert real data to register data */
1246 }
1247 else
1248 {
1249 *reg = (uint8_t)(256.0f - ms / 2.78f); /* convert real data to register data */
1250 }
1251
1252 return 0; /* success return 0 */
1253}
1254
1267uint8_t apds9960_wait_time_convert_to_data(apds9960_handle_t *handle, uint8_t reg, float *ms)
1268{
1269 uint8_t res;
1270 uint8_t prev;
1271
1272 if (handle == NULL) /* check handle */
1273 {
1274 return 2; /* return error */
1275 }
1276 if (handle->inited != 1) /* check handle initialization */
1277 {
1278 return 3; /* return error */
1279 }
1280
1281 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG1, (uint8_t *)&prev, 1); /* get configuration register 1 */
1282 if (res != 0) /* check result */
1283 {
1284 handle->debug_print("apds9960: get configuration register 1 failed.\n"); /* get configuration register 1 failed */
1285
1286 return 1; /* return error */
1287 }
1288
1289 if ((prev & (1 << 1)) != 0) /* check wait long */
1290 {
1291 *ms = (float)(256 - reg) * 2.78f * 12.0f; /* convert raw data to real data */
1292 }
1293 else
1294 {
1295 *ms = (float)(256 - reg) * 2.78f; /* convert raw data to real data */
1296 }
1297
1298 return 0; /* success return 0 */
1299}
1300
1313{
1314 uint8_t res;
1315 uint8_t buf[2];
1316
1317 if (handle == NULL) /* check handle */
1318 {
1319 return 2; /* return error */
1320 }
1321 if (handle->inited != 1) /* check handle initialization */
1322 {
1323 return 3; /* return error */
1324 }
1325
1326 buf[0] = (threshold >> 0) & 0xFF; /* set lsb */
1327 buf[1] = (threshold >> 8) & 0xFF; /* set msb */
1328 res = a_apds9960_iic_write(handle, APDS9960_REG_AILTL, (uint8_t *)buf, 2); /* set ailtl */
1329 if (res != 0) /* check result */
1330 {
1331 handle->debug_print("apds9960: set ailtl failed.\n"); /* set ailtl failed */
1332
1333 return 1; /* return error */
1334 }
1335
1336 return 0; /* success return 0 */
1337}
1338
1351{
1352 uint8_t res;
1353 uint8_t buf[2];
1354
1355 if (handle == NULL) /* check handle */
1356 {
1357 return 2; /* return error */
1358 }
1359 if (handle->inited != 1) /* check handle initialization */
1360 {
1361 return 3; /* return error */
1362 }
1363
1364 res = a_apds9960_iic_read(handle, APDS9960_REG_AILTL, (uint8_t *)buf, 2); /* get ailtl */
1365 if (res != 0) /* check result */
1366 {
1367 handle->debug_print("apds9960: get ailtl failed.\n"); /* get ailtl failed */
1368
1369 return 1; /* return error */
1370 }
1371 *threshold = (uint16_t)(((uint16_t)buf[1] << 8) | buf[0]); /* set threshold */
1372
1373 return 0; /* success return 0 */
1374}
1375
1388{
1389 uint8_t res;
1390 uint8_t buf[2];
1391
1392 if (handle == NULL) /* check handle */
1393 {
1394 return 2; /* return error */
1395 }
1396 if (handle->inited != 1) /* check handle initialization */
1397 {
1398 return 3; /* return error */
1399 }
1400
1401 buf[0] = (threshold >> 0) & 0xFF; /* set lsb */
1402 buf[1] = (threshold >> 8) & 0xFF; /* set msb */
1403 res = a_apds9960_iic_write(handle, APDS9960_REG_AIHTL, (uint8_t *)buf, 2); /* set aihtl */
1404 if (res != 0) /* check result */
1405 {
1406 handle->debug_print("apds9960: set aihtl failed.\n"); /* set aihtl failed */
1407
1408 return 1; /* return error */
1409 }
1410
1411 return 0; /* success return 0 */
1412}
1413
1426{
1427 uint8_t res;
1428 uint8_t buf[2];
1429
1430 if (handle == NULL) /* check handle */
1431 {
1432 return 2; /* return error */
1433 }
1434 if (handle->inited != 1) /* check handle initialization */
1435 {
1436 return 3; /* return error */
1437 }
1438
1439 res = a_apds9960_iic_read(handle, APDS9960_REG_AIHTL, (uint8_t *)buf, 2); /* get aihtl */
1440 if (res != 0) /* check result */
1441 {
1442 handle->debug_print("apds9960: get aihtl failed.\n"); /* get aihtl failed */
1443
1444 return 1; /* return error */
1445 }
1446 *threshold = (uint16_t)(((uint16_t)buf[1] << 8) | buf[0]); /* set threshold */
1447
1448 return 0; /* success return 0 */
1449}
1450
1463{
1464 uint8_t res;
1465 uint8_t prev;
1466
1467 if (handle == NULL) /* check handle */
1468 {
1469 return 2; /* return error */
1470 }
1471 if (handle->inited != 1) /* check handle initialization */
1472 {
1473 return 3; /* return error */
1474 }
1475
1476 prev = threshold; /* set low threshold */
1477 res = a_apds9960_iic_write(handle, APDS9960_REG_PILT, (uint8_t *)&prev, 1); /* set pilt */
1478 if (res != 0) /* check result */
1479 {
1480 handle->debug_print("apds9960: set pilt failed.\n"); /* set pilt failed */
1481
1482 return 1; /* return error */
1483 }
1484
1485 return 0; /* success return 0 */
1486}
1487
1500{
1501 uint8_t res;
1502 uint8_t prev;
1503
1504 if (handle == NULL) /* check handle */
1505 {
1506 return 2; /* return error */
1507 }
1508 if (handle->inited != 1) /* check handle initialization */
1509 {
1510 return 3; /* return error */
1511 }
1512
1513 res = a_apds9960_iic_read(handle, APDS9960_REG_PILT, (uint8_t *)&prev, 1); /* get pilt */
1514 if (res != 0) /* check result */
1515 {
1516 handle->debug_print("apds9960: get pilt failed.\n"); /* get pilt failed */
1517
1518 return 1; /* return error */
1519 }
1520 *threshold = prev; /* get low threshold */
1521
1522 return 0; /* success return 0 */
1523}
1524
1537{
1538 uint8_t res;
1539 uint8_t prev;
1540
1541 if (handle == NULL) /* check handle */
1542 {
1543 return 2; /* return error */
1544 }
1545 if (handle->inited != 1) /* check handle initialization */
1546 {
1547 return 3; /* return error */
1548 }
1549
1550 prev = threshold; /* set high threshold */
1551 res = a_apds9960_iic_write(handle, APDS9960_REG_PIHT, (uint8_t *)&prev, 1); /* set piht */
1552 if (res != 0) /* check result */
1553 {
1554 handle->debug_print("apds9960: set piht failed.\n"); /* set piht failed */
1555
1556 return 1; /* return error */
1557 }
1558
1559 return 0; /* success return 0 */
1560}
1561
1574{
1575 uint8_t res;
1576 uint8_t prev;
1577
1578 if (handle == NULL) /* check handle */
1579 {
1580 return 2; /* return error */
1581 }
1582 if (handle->inited != 1) /* check handle initialization */
1583 {
1584 return 3; /* return error */
1585 }
1586
1587 res = a_apds9960_iic_read(handle, APDS9960_REG_PIHT, (uint8_t *)&prev, 1); /* get piht */
1588 if (res != 0) /* check result */
1589 {
1590 handle->debug_print("apds9960: get piht failed.\n"); /* get piht failed */
1591
1592 return 1; /* return error */
1593 }
1594 *threshold = prev; /* get high threshold */
1595
1596 return 0; /* success return 0 */
1597}
1598
1611{
1612 uint8_t res;
1613 uint8_t prev;
1614
1615 if (handle == NULL) /* check handle */
1616 {
1617 return 2; /* return error */
1618 }
1619 if (handle->inited != 1) /* check handle initialization */
1620 {
1621 return 3; /* return error */
1622 }
1623
1624 res = a_apds9960_iic_read(handle, APDS9960_REG_PERS, (uint8_t *)&prev, 1); /* get persistence register */
1625 if (res != 0) /* check result */
1626 {
1627 handle->debug_print("apds9960: get persistence register failed.\n"); /* get persistence register failed */
1628
1629 return 1; /* return error */
1630 }
1631 prev &= ~(0xF << 4); /* clear config */
1632 prev |= cycle << 4; /* set config */
1633 res = a_apds9960_iic_write(handle, APDS9960_REG_PERS, (uint8_t *)&prev, 1); /* set persistence register */
1634 if (res != 0) /* check result */
1635 {
1636 handle->debug_print("apds9960: set persistence register failed.\n"); /* set persistence register failed */
1637
1638 return 1; /* return error */
1639 }
1640
1641 return 0; /* success return 0 */
1642}
1643
1656{
1657 uint8_t res;
1658 uint8_t prev;
1659
1660 if (handle == NULL) /* check handle */
1661 {
1662 return 2; /* return error */
1663 }
1664 if (handle->inited != 1) /* check handle initialization */
1665 {
1666 return 3; /* return error */
1667 }
1668
1669 res = a_apds9960_iic_read(handle, APDS9960_REG_PERS, (uint8_t *)&prev, 1); /* get persistence register */
1670 if (res != 0) /* check result */
1671 {
1672 handle->debug_print("apds9960: get persistence register failed.\n"); /* get persistence register failed */
1673
1674 return 1; /* return error */
1675 }
1676 *cycle = (apds9960_proximity_interrupt_cycle_t)((prev >> 4) & 0xF); /* set cycle */
1677
1678 return 0; /* success return 0 */
1679}
1680
1693{
1694 uint8_t res;
1695 uint8_t prev;
1696
1697 if (handle == NULL) /* check handle */
1698 {
1699 return 2; /* return error */
1700 }
1701 if (handle->inited != 1) /* check handle initialization */
1702 {
1703 return 3; /* return error */
1704 }
1705
1706 res = a_apds9960_iic_read(handle, APDS9960_REG_PERS, (uint8_t *)&prev, 1); /* get persistence register */
1707 if (res != 0) /* check result */
1708 {
1709 handle->debug_print("apds9960: get persistence register failed.\n"); /* get persistence register failed */
1710
1711 return 1; /* return error */
1712 }
1713 prev &= ~(0xF << 0); /* clear config */
1714 prev |= cycle << 0; /* set config */
1715 res = a_apds9960_iic_write(handle, APDS9960_REG_PERS, (uint8_t *)&prev, 1); /* set persistence register */
1716 if (res != 0) /* check result */
1717 {
1718 handle->debug_print("apds9960: set persistence register failed.\n"); /* set persistence register failed */
1719
1720 return 1; /* return error */
1721 }
1722
1723 return 0; /* success return 0 */
1724}
1725
1738{
1739 uint8_t res;
1740 uint8_t prev;
1741
1742 if (handle == NULL) /* check handle */
1743 {
1744 return 2; /* return error */
1745 }
1746 if (handle->inited != 1) /* check handle initialization */
1747 {
1748 return 3; /* return error */
1749 }
1750
1751 res = a_apds9960_iic_read(handle, APDS9960_REG_PERS, (uint8_t *)&prev, 1); /* get persistence register */
1752 if (res != 0) /* check result */
1753 {
1754 handle->debug_print("apds9960: get persistence register failed.\n"); /* get persistence register failed */
1755
1756 return 1; /* return error */
1757 }
1758 *cycle = (apds9960_als_interrupt_cycle_t)((prev >> 0) & 0xF); /* get als interrupt cycle */
1759
1760 return 0; /* success return 0 */
1761}
1762
1775{
1776 uint8_t res;
1777 uint8_t prev;
1778
1779 if (handle == NULL) /* check handle */
1780 {
1781 return 2; /* return error */
1782 }
1783 if (handle->inited != 1) /* check handle initialization */
1784 {
1785 return 3; /* return error */
1786 }
1787
1788 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG1, (uint8_t *)&prev, 1); /* get configuration register 1 */
1789 if (res != 0) /* check result */
1790 {
1791 handle->debug_print("apds9960: get configuration register 1 failed.\n"); /* get configuration register 1 failed */
1792
1793 return 1; /* return error */
1794 }
1795 prev &= ~(1 << 1); /* clear config */
1796 prev |= enable << 1; /* set config */
1797 res = a_apds9960_iic_write(handle, APDS9960_REG_CONFIG1, (uint8_t *)&prev, 1); /* set configuration register 1 */
1798 if (res != 0) /* check result */
1799 {
1800 handle->debug_print("apds9960: set configuration register 1 failed.\n"); /* set configuration register 1 failed */
1801
1802 return 1; /* return error */
1803 }
1804
1805 return 0; /* success return 0 */
1806}
1807
1820{
1821 uint8_t res;
1822 uint8_t prev;
1823
1824 if (handle == NULL) /* check handle */
1825 {
1826 return 2; /* return error */
1827 }
1828 if (handle->inited != 1) /* check handle initialization */
1829 {
1830 return 3; /* return error */
1831 }
1832
1833 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG1, (uint8_t *)&prev, 1); /* get configuration register 1 */
1834 if (res != 0) /* check result */
1835 {
1836 handle->debug_print("apds9960: get configuration register 1 failed.\n"); /* get configuration register 1 failed */
1837
1838 return 1; /* return error */
1839 }
1840 *enable = (apds9960_bool_t)((prev >> 1) & 0x1); /* get bool */
1841
1842 return 0; /* success return 0 */
1843}
1844
1857{
1858 uint8_t res;
1859 uint8_t prev;
1860
1861 if (handle == NULL) /* check handle */
1862 {
1863 return 2; /* return error */
1864 }
1865 if (handle->inited != 1) /* check handle initialization */
1866 {
1867 return 3; /* return error */
1868 }
1869
1870 res = a_apds9960_iic_read(handle, APDS9960_REG_PPULSE, (uint8_t *)&prev, 1); /* get proximity pulse count register */
1871 if (res != 0) /* check result */
1872 {
1873 handle->debug_print("apds9960: get proximity pulse count register failed.\n"); /* get proximity pulse count register failed */
1874
1875 return 1; /* return error */
1876 }
1877 prev &= ~(3 << 6); /* clear config */
1878 prev |= len << 6; /* set config */
1879 res = a_apds9960_iic_write(handle, APDS9960_REG_PPULSE, (uint8_t *)&prev, 1); /* set proximity pulse count register */
1880 if (res != 0) /* check result */
1881 {
1882 handle->debug_print("apds9960: set proximity pulse count register failed.\n"); /* set proximity pulse count register failed */
1883
1884 return 1; /* return error */
1885 }
1886
1887 return 0; /* success return 0 */
1888}
1889
1902{
1903 uint8_t res;
1904 uint8_t prev;
1905
1906 if (handle == NULL) /* check handle */
1907 {
1908 return 2; /* return error */
1909 }
1910 if (handle->inited != 1) /* check handle initialization */
1911 {
1912 return 3; /* return error */
1913 }
1914
1915 res = a_apds9960_iic_read(handle, APDS9960_REG_PPULSE, (uint8_t *)&prev, 1); /* get proximity pulse count register */
1916 if (res != 0) /* check result */
1917 {
1918 handle->debug_print("apds9960: get proximity pulse count register failed.\n"); /* get proximity pulse count register failed */
1919
1920 return 1; /* return error */
1921 }
1922 *len = (apds9960_proximity_pulse_length_t)((prev >> 6) & 0x3); /* get length */
1923
1924 return 0; /* success return 0 */
1925}
1926
1940{
1941 uint8_t res;
1942 uint8_t prev;
1943
1944 if (handle == NULL) /* check handle */
1945 {
1946 return 2; /* return error */
1947 }
1948 if (handle->inited != 1) /* check handle initialization */
1949 {
1950 return 3; /* return error */
1951 }
1952 if (count > 0x3F) /* check count */
1953 {
1954 handle->debug_print("apds9960: count is over 63.\n"); /* count is over 63 */
1955
1956 return 4; /* return error */
1957 }
1958
1959 res = a_apds9960_iic_read(handle, APDS9960_REG_PPULSE, (uint8_t *)&prev, 1); /* get proximity pulse count register */
1960 if (res != 0) /* check result */
1961 {
1962 handle->debug_print("apds9960: get proximity pulse count register failed.\n"); /* get proximity pulse count register failed */
1963
1964 return 1; /* return error */
1965 }
1966 prev &= ~(0x3F << 0); /* clear config */
1967 prev |= (count & 0x3F) << 0; /* set config */
1968 res = a_apds9960_iic_write(handle, APDS9960_REG_PPULSE, (uint8_t *)&prev, 1); /* set proximity pulse count register */
1969 if (res != 0) /* check result */
1970 {
1971 handle->debug_print("apds9960: set proximity pulse count register failed.\n"); /* set proximity pulse count register failed */
1972
1973 return 1; /* return error */
1974 }
1975
1976 return 0; /* success return 0 */
1977}
1978
1991{
1992 uint8_t res;
1993 uint8_t prev;
1994
1995 if (handle == NULL) /* check handle */
1996 {
1997 return 2; /* return error */
1998 }
1999 if (handle->inited != 1) /* check handle initialization */
2000 {
2001 return 3; /* return error */
2002 }
2003
2004 res = a_apds9960_iic_read(handle, APDS9960_REG_PPULSE, (uint8_t *)&prev, 1); /* get proximity pulse count register */
2005 if (res != 0) /* check result */
2006 {
2007 handle->debug_print("apds9960: get proximity pulse count register failed.\n"); /* get proximity pulse count register failed */
2008
2009 return 1; /* return error */
2010 }
2011 *count = prev & 0x3F; /* get count */
2012
2013 return 0; /* success return 0 */
2014}
2015
2028{
2029 uint8_t res;
2030 uint8_t prev;
2031
2032 if (handle == NULL) /* check handle */
2033 {
2034 return 2; /* return error */
2035 }
2036 if (handle->inited != 1) /* check handle initialization */
2037 {
2038 return 3; /* return error */
2039 }
2040
2041 res = a_apds9960_iic_read(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* get control register */
2042 if (res != 0) /* check result */
2043 {
2044 handle->debug_print("apds9960: get control register failed.\n"); /* get control register failed */
2045
2046 return 1; /* return error */
2047 }
2048 prev &= ~(0x3 << 6); /* clear config */
2049 prev |= current << 6; /* set config */
2050 res = a_apds9960_iic_write(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* set control register register */
2051 if (res != 0) /* check result */
2052 {
2053 handle->debug_print("apds9960: set control register register failed.\n"); /* set control register failed */
2054
2055 return 1; /* return error */
2056 }
2057
2058 return 0; /* success return 0 */
2059}
2060
2073{
2074 uint8_t res;
2075 uint8_t prev;
2076
2077 if (handle == NULL) /* check handle */
2078 {
2079 return 2; /* return error */
2080 }
2081 if (handle->inited != 1) /* check handle initialization */
2082 {
2083 return 3; /* return error */
2084 }
2085
2086 res = a_apds9960_iic_read(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* get control register */
2087 if (res != 0) /* check result */
2088 {
2089 handle->debug_print("apds9960: get control register failed.\n"); /* get control register failed */
2090
2091 return 1; /* return error */
2092 }
2093 *current = (apds9960_led_current_t)((prev >> 6) & 0x3); /* get the current */
2094
2095 return 0; /* success return 0 */
2096}
2097
2110{
2111 uint8_t res;
2112 uint8_t prev;
2113
2114 if (handle == NULL) /* check handle */
2115 {
2116 return 2; /* return error */
2117 }
2118 if (handle->inited != 1) /* check handle initialization */
2119 {
2120 return 3; /* return error */
2121 }
2122
2123 res = a_apds9960_iic_read(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* get control register */
2124 if (res != 0) /* check result */
2125 {
2126 handle->debug_print("apds9960: get control register failed.\n"); /* get control register failed */
2127
2128 return 1; /* return error */
2129 }
2130 prev &= ~(0x3 << 2); /* clear config */
2131 prev |= gain << 2; /* set config */
2132 res = a_apds9960_iic_write(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* set control register register */
2133 if (res != 0) /* check result */
2134 {
2135 handle->debug_print("apds9960: set control register register failed.\n"); /* set control register failed */
2136
2137 return 1; /* return error */
2138 }
2139
2140 return 0; /* success return 0 */
2141}
2142
2155{
2156 uint8_t res;
2157 uint8_t prev;
2158
2159 if (handle == NULL) /* check handle */
2160 {
2161 return 2; /* return error */
2162 }
2163 if (handle->inited != 1) /* check handle initialization */
2164 {
2165 return 3; /* return error */
2166 }
2167
2168 res = a_apds9960_iic_read(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* get control register */
2169 if (res != 0) /* check result */
2170 {
2171 handle->debug_print("apds9960: get control register failed.\n"); /* get control register failed */
2172
2173 return 1; /* return error */
2174 }
2175 *gain = (apds9960_proximity_gain_t)((prev >> 2) & 0x3); /* get the gain */
2176
2177 return 0; /* success return 0 */
2178}
2179
2192{
2193 uint8_t res;
2194 uint8_t prev;
2195
2196 if (handle == NULL) /* check handle */
2197 {
2198 return 2; /* return error */
2199 }
2200 if (handle->inited != 1) /* check handle initialization */
2201 {
2202 return 3; /* return error */
2203 }
2204
2205 res = a_apds9960_iic_read(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* get control register */
2206 if (res != 0) /* check result */
2207 {
2208 handle->debug_print("apds9960: get control register failed.\n"); /* get control register failed */
2209
2210 return 1; /* return error */
2211 }
2212 prev &= ~(0x3 << 0); /* clear config */
2213 prev |= gain << 0; /* set config */
2214 res = a_apds9960_iic_write(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* set control register register */
2215 if (res != 0) /* check result */
2216 {
2217 handle->debug_print("apds9960: set control register register failed.\n"); /* set control register failed */
2218
2219 return 1; /* return error */
2220 }
2221
2222 return 0; /* success return 0 */
2223}
2224
2237{
2238 uint8_t res;
2239 uint8_t prev;
2240
2241 if (handle == NULL) /* check handle */
2242 {
2243 return 2; /* return error */
2244 }
2245 if (handle->inited != 1) /* check handle initialization */
2246 {
2247 return 3; /* return error */
2248 }
2249
2250 res = a_apds9960_iic_read(handle, APDS9960_REG_CONTROL, (uint8_t *)&prev, 1); /* get control register */
2251 if (res != 0) /* check result */
2252 {
2253 handle->debug_print("apds9960: get control register failed.\n"); /* get control register failed */
2254
2255 return 1; /* return error */
2256 }
2257 *gain = (apds9960_als_color_gain_t)((prev >> 0) & 0x3); /* get the gain */
2258
2259 return 0; /* success return 0 */
2260}
2261
2275{
2276 uint8_t res;
2277 uint8_t prev;
2278
2279 if (handle == NULL) /* check handle */
2280 {
2281 return 2; /* return error */
2282 }
2283 if (handle->inited != 1) /* check handle initialization */
2284 {
2285 return 3; /* return error */
2286 }
2287
2288 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG2, (uint8_t *)&prev, 1); /* get control 2 register */
2289 if (res != 0) /* check result */
2290 {
2291 handle->debug_print("apds9960: get control 2 register failed.\n"); /* get control 2 register failed */
2292
2293 return 1; /* return error */
2294 }
2295 prev &= ~(1 << saturation); /* clear config */
2296 prev |= enable << saturation; /* set config */
2297 res = a_apds9960_iic_write(handle, APDS9960_REG_CONFIG2, (uint8_t *)&prev, 1); /* set control register 2 register */
2298 if (res != 0) /* check result */
2299 {
2300 handle->debug_print("apds9960: set control 2 register register failed.\n"); /* set control 2 register failed */
2301
2302 return 1; /* return error */
2303 }
2304
2305 return 0; /* success return 0 */
2306}
2307
2321{
2322 uint8_t res;
2323 uint8_t prev;
2324
2325 if (handle == NULL) /* check handle */
2326 {
2327 return 2; /* return error */
2328 }
2329 if (handle->inited != 1) /* check handle initialization */
2330 {
2331 return 3; /* return error */
2332 }
2333
2334 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG2, (uint8_t *)&prev, 1); /* get control 2 register */
2335 if (res != 0) /* check result */
2336 {
2337 handle->debug_print("apds9960: get control 2 register failed.\n"); /* get control 2 register failed */
2338
2339 return 1; /* return error */
2340 }
2341 *enable = (apds9960_bool_t)((prev >> saturation) & 0x01); /* get the saturation */
2342
2343 return 0; /* success return 0 */
2344}
2345
2358{
2359 uint8_t res;
2360 uint8_t prev;
2361
2362 if (handle == NULL) /* check handle */
2363 {
2364 return 2; /* return error */
2365 }
2366 if (handle->inited != 1) /* check handle initialization */
2367 {
2368 return 3; /* return error */
2369 }
2370
2371 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG2, (uint8_t *)&prev, 1); /* get control 2 register */
2372 if (res != 0) /* check result */
2373 {
2374 handle->debug_print("apds9960: get control 2 register failed.\n"); /* get control 2 register failed */
2375
2376 return 1; /* return error */
2377 }
2378 prev &= ~(0x3 << 4); /* clear config */
2379 prev |= boost << 4; /* set config */
2380 res = a_apds9960_iic_write(handle, APDS9960_REG_CONFIG2, (uint8_t *)&prev, 1); /* set control register 2 register */
2381 if (res != 0) /* check result */
2382 {
2383 handle->debug_print("apds9960: set control 2 register register failed.\n"); /* set control 2 register failed */
2384
2385 return 1; /* return error */
2386 }
2387
2388 return 0; /* success return 0 */
2389}
2390
2403{
2404 uint8_t res;
2405 uint8_t prev;
2406
2407 if (handle == NULL) /* check handle */
2408 {
2409 return 2; /* return error */
2410 }
2411 if (handle->inited != 1) /* check handle initialization */
2412 {
2413 return 3; /* return error */
2414 }
2415
2416 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG2, (uint8_t *)&prev, 1); /* get control 2 register */
2417 if (res != 0) /* check result */
2418 {
2419 handle->debug_print("apds9960: get control 2 register failed.\n"); /* get control 2 register failed */
2420
2421 return 1; /* return error */
2422 }
2423 *boost = (apds9960_led_boost_t)((prev >> 4) & 0x3); /* set the LED boost */
2424
2425 return 0; /* success return 0 */
2426}
2427
2439uint8_t apds9960_get_status(apds9960_handle_t *handle, uint8_t *status)
2440{
2441 uint8_t res;
2442 uint8_t prev;
2443
2444 if (handle == NULL) /* check handle */
2445 {
2446 return 2; /* return error */
2447 }
2448 if (handle->inited != 1) /* check handle initialization */
2449 {
2450 return 3; /* return error */
2451 }
2452
2453 res = a_apds9960_iic_read(handle, APDS9960_REG_STATUS, (uint8_t *)&prev, 1); /* get status register */
2454 if (res != 0) /* check result */
2455 {
2456 handle->debug_print("apds9960: get status register failed.\n"); /* get status register failed */
2457
2458 return 1; /* return error */
2459 }
2460 *status = prev; /* set the status */
2461
2462 return 0; /* success return 0 */
2463}
2464
2479uint8_t apds9960_read_rgbc(apds9960_handle_t *handle, uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *clear)
2480{
2481 uint8_t res;
2482 uint8_t buf[8];
2483
2484 if (handle == NULL) /* check handle */
2485 {
2486 return 2; /* return error */
2487 }
2488 if (handle->inited != 1) /* check handle initialization */
2489 {
2490 return 3; /* return error */
2491 }
2492
2493 res = a_apds9960_iic_read(handle, APDS9960_REG_CDATAL, (uint8_t *)&buf[0], 2); /* get cdatal register */
2494 if (res != 0) /* check result */
2495 {
2496 handle->debug_print("apds9960: get cdatal register failed.\n"); /* get cdatal register failed */
2497
2498 return 1; /* return error */
2499 }
2500 res = a_apds9960_iic_read(handle, APDS9960_REG_RDATAL, (uint8_t *)&buf[2], 2); /* get rdatal register */
2501 if (res != 0) /* check result */
2502 {
2503 handle->debug_print("apds9960: get rdatal register failed.\n"); /* get rdatal register failed */
2504
2505 return 1; /* return error */
2506 }
2507 res = a_apds9960_iic_read(handle, APDS9960_REG_GDATAL, (uint8_t *)&buf[4], 2); /* get gdatal register */
2508 if (res != 0) /* check result */
2509 {
2510 handle->debug_print("apds9960: get gdatal register failed.\n"); /* get gdatal register failed */
2511
2512 return 1; /* return error */
2513 }
2514 res = a_apds9960_iic_read(handle, APDS9960_REG_BDATAL, (uint8_t *)&buf[6], 2); /* get bdatal register */
2515 if (res != 0) /* check result */
2516 {
2517 handle->debug_print("apds9960: get bdatal register failed.\n"); /* get bdatal register failed */
2518
2519 return 1; /* return error */
2520 }
2521 *red = (uint16_t)(((uint16_t)buf[3] << 0) | buf[2]); /* set the red */
2522 *green = (uint16_t)(((uint16_t)buf[5] << 0) | buf[4]); /* set the green */
2523 *blue = (uint16_t)(((uint16_t)buf[7] << 0) | buf[6]); /* set the blue */
2524 *clear = (uint16_t)(((uint16_t)buf[1] << 0) | buf[0]); /* set the clear */
2525
2526 return 0; /* success return 0 */
2527}
2528
2540uint8_t apds9960_read_proximity(apds9960_handle_t *handle, uint8_t *proximity)
2541{
2542 uint8_t res;
2543 uint8_t prev;
2544
2545 if (handle == NULL) /* check handle */
2546 {
2547 return 2; /* return error */
2548 }
2549 if (handle->inited != 1) /* check handle initialization */
2550 {
2551 return 3; /* return error */
2552 }
2553
2554 res = a_apds9960_iic_read(handle, APDS9960_REG_PDATA, (uint8_t *)&prev, 1); /* get proximity data register */
2555 if (res != 0) /* check result */
2556 {
2557 handle->debug_print("apds9960: get proximity data register failed.\n"); /* get proximity data register failed */
2558
2559 return 1; /* return error */
2560 }
2561 *proximity = prev; /* set the proximity */
2562
2563 return 0; /* success return 0 */
2564}
2565
2578{
2579 uint8_t res;
2580 uint8_t prev;
2581
2582 if (handle == NULL) /* check handle */
2583 {
2584 return 2; /* return error */
2585 }
2586 if (handle->inited != 1) /* check handle initialization */
2587 {
2588 return 3; /* return error */
2589 }
2590
2591 if (offset >= 0) /* if >= 0 */
2592 {
2593 prev = offset; /* set the positive */
2594 }
2595 else /* < 0 */
2596 {
2597 prev = 0x80; /* set the 0x80 */
2598 prev |= (-offset); /* set the negative */
2599 }
2600 res = a_apds9960_iic_write(handle, APDS9960_REG_POFFSET_UR, (uint8_t *)&prev, 1); /* set proximity offset up right register */
2601 if (res != 0) /* check result */
2602 {
2603 handle->debug_print("apds9960: set proximity offset up right register failed.\n"); /* set proximity offset up right register failed */
2604
2605 return 1; /* return error */
2606 }
2607
2608 return 0; /* success return 0 */
2609}
2610
2623{
2624 uint8_t res;
2625 uint8_t prev;
2626
2627 if (handle == NULL) /* check handle */
2628 {
2629 return 2; /* return error */
2630 }
2631 if (handle->inited != 1) /* check handle initialization */
2632 {
2633 return 3; /* return error */
2634 }
2635
2636 res = a_apds9960_iic_read(handle, APDS9960_REG_POFFSET_UR, (uint8_t *)&prev, 1); /* get proximity offset up right register */
2637 if (res != 0) /* check result */
2638 {
2639 handle->debug_print("apds9960: get proximity offset up right register failed.\n"); /* get proximity offset up right register failed */
2640
2641 return 1; /* return error */
2642 }
2643 if ((prev & 0x80) != 0) /* if < 0 */
2644 {
2645 prev &= ~0x80; /* clear 0x80 */
2646 *offset = -(int8_t)(prev); /* set the offset */
2647 }
2648 else /* >= 0 */
2649 {
2650 *offset = (int8_t)(prev); /* set the offset */
2651 }
2652
2653 return 0; /* success return 0 */
2654}
2655
2668{
2669 uint8_t res;
2670 uint8_t prev;
2671
2672 if (handle == NULL) /* check handle */
2673 {
2674 return 2; /* return error */
2675 }
2676 if (handle->inited != 1) /* check handle initialization */
2677 {
2678 return 3; /* return error */
2679 }
2680
2681 if (offset >= 0) /* if >= 0 */
2682 {
2683 prev = offset; /* set the positive */
2684 }
2685 else /* <0 */
2686 {
2687 prev = 0x80; /* set the 0x80 */
2688 prev |= (-offset); /* set the negative */
2689 }
2690 res = a_apds9960_iic_write(handle, APDS9960_REG_POFFSET_DL, (uint8_t *)&prev, 1); /* set proximity offset down left register */
2691 if (res != 0) /* check result */
2692 {
2693 handle->debug_print("apds9960: set proximity offset down left register failed.\n"); /* set proximity offset down left register failed */
2694
2695 return 1; /* return error */
2696 }
2697
2698 return 0; /* success return 0 */
2699}
2700
2713{
2714 uint8_t res;
2715 uint8_t prev;
2716
2717 if (handle == NULL) /* check handle */
2718 {
2719 return 2; /* return error */
2720 }
2721 if (handle->inited != 1) /* check handle initialization */
2722 {
2723 return 3; /* return error */
2724 }
2725
2726 res = a_apds9960_iic_read(handle, APDS9960_REG_POFFSET_DL, (uint8_t *)&prev, 1); /* get proximity offset down left register */
2727 if (res != 0) /* check result */
2728 {
2729 handle->debug_print("apds9960: get proximity offset down left register failed.\n"); /* get proximity offset down left register failed */
2730
2731 return 1; /* return error */
2732 }
2733 if ((prev & 0x80) != 0) /* if < 0 */
2734 {
2735 prev &= ~0x80; /* clear 0x80 */
2736 *offset = -(int8_t)(prev); /* set the offset */
2737 }
2738 else /* >= 0 */
2739 {
2740 *offset = (int8_t)(prev); /* set the offset */
2741 }
2742
2743 return 0; /* success return 0 */
2744}
2745
2758{
2759 uint8_t res;
2760 uint8_t prev;
2761
2762 if (handle == NULL) /* check handle */
2763 {
2764 return 2; /* return error */
2765 }
2766 if (handle->inited != 1) /* check handle initialization */
2767 {
2768 return 3; /* return error */
2769 }
2770
2771 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* get control 3 register */
2772 if (res != 0) /* check result */
2773 {
2774 handle->debug_print("apds9960: get control 3 register failed.\n"); /* get control 3 register failed */
2775
2776 return 1; /* return error */
2777 }
2778 prev &= ~(1 << 5); /* clear config */
2779 prev |= enable << 5; /* set config */
2780 res = a_apds9960_iic_write(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* set control register 3 register */
2781 if (res != 0) /* check result */
2782 {
2783 handle->debug_print("apds9960: set control 3 register register failed.\n"); /* set control 3 register failed */
2784
2785 return 1; /* return error */
2786 }
2787
2788 return 0; /* success return 0 */
2789}
2790
2803{
2804 uint8_t res;
2805 uint8_t prev;
2806
2807 if (handle == NULL) /* check handle */
2808 {
2809 return 2; /* return error */
2810 }
2811 if (handle->inited != 1) /* check handle initialization */
2812 {
2813 return 3; /* return error */
2814 }
2815
2816 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* get control 3 register */
2817 if (res != 0) /* check result */
2818 {
2819 handle->debug_print("apds9960: get control 3 register failed.\n"); /* get control 3 register failed */
2820
2821 return 1; /* return error */
2822 }
2823 *enable = (apds9960_bool_t)((prev >> 5) & 0x01); /* get bool */
2824
2825 return 0; /* success return 0 */
2826}
2827
2840{
2841 uint8_t res;
2842 uint8_t prev;
2843
2844 if (handle == NULL) /* check handle */
2845 {
2846 return 2; /* return error */
2847 }
2848 if (handle->inited != 1) /* check handle initialization */
2849 {
2850 return 3; /* return error */
2851 }
2852
2853 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* get control 3 register */
2854 if (res != 0) /* check result */
2855 {
2856 handle->debug_print("apds9960: get control 3 register failed.\n"); /* get control 3 register failed */
2857
2858 return 1; /* return error */
2859 }
2860 prev &= ~(1 << 4); /* clear config */
2861 prev |= enable << 4; /* set config */
2862 res = a_apds9960_iic_write(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* set control register 3 register */
2863 if (res != 0) /* check result */
2864 {
2865 handle->debug_print("apds9960: set control 3 register register failed.\n"); /* set control 3 register failed */
2866
2867 return 1; /* return error */
2868 }
2869
2870 return 0; /* success return 0 */
2871}
2872
2885{
2886 uint8_t res;
2887 uint8_t prev;
2888
2889 if (handle == NULL) /* check handle */
2890 {
2891 return 2; /* return error */
2892 }
2893 if (handle->inited != 1) /* check handle initialization */
2894 {
2895 return 3; /* return error */
2896 }
2897
2898 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* get control 3 register */
2899 if (res != 0) /* check result */
2900 {
2901 handle->debug_print("apds9960: get control 3 register failed.\n"); /* get control 3 register failed */
2902
2903 return 1; /* return error */
2904 }
2905 *enable = (apds9960_bool_t)((prev >> 4) & 0x01); /* get bool */
2906
2907 return 0; /* success return 0 */
2908}
2909
2923{
2924 uint8_t res;
2925 uint8_t prev;
2926
2927 if (handle == NULL) /* check handle */
2928 {
2929 return 2; /* return error */
2930 }
2931 if (handle->inited != 1) /* check handle initialization */
2932 {
2933 return 3; /* return error */
2934 }
2935
2936 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* get control 3 register */
2937 if (res != 0) /* check result */
2938 {
2939 handle->debug_print("apds9960: get control 3 register failed.\n"); /* get control 3 register failed */
2940
2941 return 1; /* return error */
2942 }
2943 prev &= ~(1 << mask); /* clear config */
2944 prev |= enable << mask; /* set config */
2945 res = a_apds9960_iic_write(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* set control register 3 register */
2946 if (res != 0) /* check result */
2947 {
2948 handle->debug_print("apds9960: set control 3 register register failed.\n"); /* set control 3 register failed */
2949
2950 return 1; /* return error */
2951 }
2952
2953 return 0; /* success return 0 */
2954}
2955
2969{
2970 uint8_t res;
2971 uint8_t prev;
2972
2973 if (handle == NULL) /* check handle */
2974 {
2975 return 2; /* return error */
2976 }
2977 if (handle->inited != 1) /* check handle initialization */
2978 {
2979 return 3; /* return error */
2980 }
2981
2982 res = a_apds9960_iic_read(handle, APDS9960_REG_CONFIG3, (uint8_t *)&prev, 1); /* get control 3 register */
2983 if (res != 0) /* check result */
2984 {
2985 handle->debug_print("apds9960: get control 3 register failed.\n"); /* get control 3 register failed */
2986
2987 return 1; /* return error */
2988 }
2989 *enable = (apds9960_bool_t)((prev >> mask) & 0x01); /* get bool */
2990
2991 return 0; /* success return 0 */
2992}
2993
3006{
3007 uint8_t res;
3008 uint8_t prev;
3009
3010 if (handle == NULL) /* check handle */
3011 {
3012 return 2; /* return error */
3013 }
3014 if (handle->inited != 1) /* check handle initialization */
3015 {
3016 return 3; /* return error */
3017 }
3018
3019 prev = threshold; /* set threshold */
3020 res = a_apds9960_iic_write(handle, APDS9960_REG_GPENTH, (uint8_t *)&prev, 1); /* set gesture proximity enter threshold register */
3021 if (res != 0) /* check result */
3022 {
3023 handle->debug_print("apds9960: set gesture proximity enter threshold register failed.\n"); /* set gesture proximity enter threshold register failed */
3024
3025 return 1; /* return error */
3026 }
3027
3028 return 0; /* success return 0 */
3029}
3030
3043{
3044 uint8_t res;
3045 uint8_t prev;
3046
3047 if (handle == NULL) /* check handle */
3048 {
3049 return 2; /* return error */
3050 }
3051 if (handle->inited != 1) /* check handle initialization */
3052 {
3053 return 3; /* return error */
3054 }
3055
3056 res = a_apds9960_iic_read(handle, APDS9960_REG_GPENTH, (uint8_t *)&prev, 1); /* get gesture proximity enter threshold register */
3057 if (res != 0) /* check result */
3058 {
3059 handle->debug_print("apds9960: get gesture proximity enter threshold register failed.\n"); /* get gesture proximity enter threshold register failed */
3060
3061 return 1; /* return error */
3062 }
3063 *threshold = prev; /* set threshold */
3064
3065 return 0; /* success return 0 */
3066}
3067
3080{
3081 uint8_t res;
3082 uint8_t prev;
3083
3084 if (handle == NULL) /* check handle */
3085 {
3086 return 2; /* return error */
3087 }
3088 if (handle->inited != 1) /* check handle initialization */
3089 {
3090 return 3; /* return error */
3091 }
3092
3093 prev = threshold; /* set threshold */
3094 res = a_apds9960_iic_write(handle, APDS9960_REG_GEXTH, (uint8_t *)&prev, 1); /* set gesture proximity exit threshold register */
3095 if (res != 0) /* check result */
3096 {
3097 handle->debug_print("apds9960: set gesture proximity exit threshold register failed.\n"); /* set gesture proximity exit threshold register failed */
3098
3099 return 1; /* return error */
3100 }
3101
3102 return 0; /* success return 0 */
3103}
3104
3117{
3118 uint8_t res;
3119 uint8_t prev;
3120
3121 if (handle == NULL) /* check handle */
3122 {
3123 return 2; /* return error */
3124 }
3125 if (handle->inited != 1) /* check handle initialization */
3126 {
3127 return 3; /* return error */
3128 }
3129
3130 res = a_apds9960_iic_read(handle, APDS9960_REG_GEXTH, (uint8_t *)&prev, 1); /* get gesture proximity exit threshold register */
3131 if (res != 0) /* check result */
3132 {
3133 handle->debug_print("apds9960: get gesture proximity exit threshold register failed.\n"); /* get gesture proximity exit threshold register failed */
3134
3135 return 1; /* return error */
3136 }
3137 *threshold = prev; /* set the threshold */
3138
3139 return 0; /* success return 0 */
3140}
3141
3154{
3155 uint8_t res;
3156 uint8_t prev;
3157
3158 if (handle == NULL) /* check handle */
3159 {
3160 return 2; /* return error */
3161 }
3162 if (handle->inited != 1) /* check handle initialization */
3163 {
3164 return 3; /* return error */
3165 }
3166
3167 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* get gesture control 1 register */
3168 if (res != 0) /* check result */
3169 {
3170 handle->debug_print("apds9960: get gesture control 1 register failed.\n"); /* get gesture control 1 register failed */
3171
3172 return 1; /* return error */
3173 }
3174 prev &= ~(3 << 6); /* clear config */
3175 prev |= threshold << 6; /* set config */
3176 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* set gesture control 1 register */
3177 if (res != 0) /* check result */
3178 {
3179 handle->debug_print("apds9960: set gesture control 1 register failed.\n"); /* set gesture control 1 register failed */
3180
3181 return 1; /* return error */
3182 }
3183
3184 return 0; /* success return 0 */
3185}
3186
3199{
3200 uint8_t res;
3201 uint8_t prev;
3202
3203 if (handle == NULL) /* check handle */
3204 {
3205 return 2; /* return error */
3206 }
3207 if (handle->inited != 1) /* check handle initialization */
3208 {
3209 return 3; /* return error */
3210 }
3211
3212 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* get gesture control 1 register */
3213 if (res != 0) /* check result */
3214 {
3215 handle->debug_print("apds9960: get gesture control 1 register failed.\n"); /* get gesture control 1 register failed */
3216
3217 return 1; /* return error */
3218 }
3219 *threshold = (apds9960_gesture_fifo_threshold_t)((prev >> 6) & 0x3); /* set the threshold */
3220
3221 return 0; /* success return 0 */
3222}
3223
3236{
3237 uint8_t res;
3238 uint8_t prev;
3239
3240 if (handle == NULL) /* check handle */
3241 {
3242 return 2; /* return error */
3243 }
3244 if (handle->inited != 1) /* check handle initialization */
3245 {
3246 return 3; /* return error */
3247 }
3248
3249 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* get gesture control 1 register */
3250 if (res != 0) /* check result */
3251 {
3252 handle->debug_print("apds9960: get gesture control 1 register failed.\n"); /* get gesture control 1 register failed */
3253
3254 return 1; /* return error */
3255 }
3256 prev &= ~(3 << 0); /* clear config */
3257 prev |= persistence << 0; /* set config */
3258 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* set gesture control 1 register */
3259 if (res != 0) /* check result */
3260 {
3261 handle->debug_print("apds9960: set gesture control 1 register failed.\n"); /* set gesture control 1 register failed */
3262
3263 return 1; /* return error */
3264 }
3265
3266 return 0; /* success return 0 */
3267}
3268
3281{
3282 uint8_t res;
3283 uint8_t prev;
3284
3285 if (handle == NULL) /* check handle */
3286 {
3287 return 2; /* return error */
3288 }
3289 if (handle->inited != 1) /* check handle initialization */
3290 {
3291 return 3; /* return error */
3292 }
3293
3294 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* get gesture control 1 register */
3295 if (res != 0) /* check result */
3296 {
3297 handle->debug_print("apds9960: get gesture control 1 register failed.\n"); /* get gesture control 1 register failed */
3298
3299 return 1; /* return error */
3300 }
3301 *persistence = (apds9960_gesture_exit_persistence_t)((prev >> 0) & 0x3); /* set the persistence */
3302
3303 return 0; /* success return 0 */
3304}
3305
3319{
3320 uint8_t res;
3321 uint8_t prev;
3322
3323 if (handle == NULL) /* check handle */
3324 {
3325 return 2; /* return error */
3326 }
3327 if (handle->inited != 1) /* check handle initialization */
3328 {
3329 return 3; /* return error */
3330 }
3331 if (mask > 0xF) /* check result */
3332 {
3333 handle->debug_print("apds9960: mask is over 0xF.\n"); /* mask is over 0xF */
3334
3335 return 4; /* return error */
3336 }
3337
3338 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* get gesture control 1 register */
3339 if (res != 0) /* check result */
3340 {
3341 handle->debug_print("apds9960: get gesture control 1 register failed.\n"); /* get gesture control 1 register failed */
3342
3343 return 1; /* return error */
3344 }
3345 prev &= ~(0xF << 2); /* clear config */
3346 prev |= (mask & 0xF) << 2; /* set config */
3347 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* set gesture control 1 register */
3348 if (res != 0) /* check result */
3349 {
3350 handle->debug_print("apds9960: set gesture control 1 register failed.\n"); /* set gesture control 1 register failed */
3351
3352 return 1; /* return error */
3353 }
3354
3355 return 0; /* success return 0 */
3356}
3357
3370{
3371 uint8_t res;
3372 uint8_t prev;
3373
3374 if (handle == NULL) /* check handle */
3375 {
3376 return 2; /* return error */
3377 }
3378 if (handle->inited != 1) /* check handle initialization */
3379 {
3380 return 3; /* return error */
3381 }
3382
3383 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF1, (uint8_t *)&prev, 1); /* get gesture control 1 register */
3384 if (res != 0) /* check result */
3385 {
3386 handle->debug_print("apds9960: get gesture control 1 register failed.\n"); /* get gesture control 1 register failed */
3387
3388 return 1; /* return error */
3389 }
3390 *mask = (prev >> 2) & 0xF; /* set the mask */
3391
3392 return 0; /* success return 0 */
3393}
3394
3407{
3408 uint8_t res;
3409 uint8_t prev;
3410
3411 if (handle == NULL) /* check handle */
3412 {
3413 return 2; /* return error */
3414 }
3415 if (handle->inited != 1) /* check handle initialization */
3416 {
3417 return 3; /* return error */
3418 }
3419
3420 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* get gesture control 2 register */
3421 if (res != 0) /* check result */
3422 {
3423 handle->debug_print("apds9960: get gesture control 2 register failed.\n"); /* get gesture control 2 register failed */
3424
3425 return 1; /* return error */
3426 }
3427 prev &= ~(0x3 << 5); /* clear config */
3428 prev |= gain << 5; /* set config */
3429 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* set gesture control 2 register */
3430 if (res != 0) /* check result */
3431 {
3432 handle->debug_print("apds9960: set gesture control 2 register failed.\n"); /* set gesture control 2 register failed */
3433
3434 return 1; /* return error */
3435 }
3436
3437 return 0; /* success return 0 */
3438}
3439
3452{
3453 uint8_t res;
3454 uint8_t prev;
3455
3456 if (handle == NULL) /* check handle */
3457 {
3458 return 2; /* return error */
3459 }
3460 if (handle->inited != 1) /* check handle initialization */
3461 {
3462 return 3; /* return error */
3463 }
3464
3465 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* get gesture control 2 register */
3466 if (res != 0) /* check result */
3467 {
3468 handle->debug_print("apds9960: get gesture control 2 register failed.\n"); /* get gesture control 2 register failed */
3469
3470 return 1; /* return error */
3471 }
3472 *gain = (apds9960_gesture_gain_control_t)((prev >> 5) & 0x3); /* set the gain */
3473
3474 return 0; /* success return 0 */
3475}
3476
3489{
3490 uint8_t res;
3491 uint8_t prev;
3492
3493 if (handle == NULL) /* check handle */
3494 {
3495 return 2; /* return error */
3496 }
3497 if (handle->inited != 1) /* check handle initialization */
3498 {
3499 return 3; /* return error */
3500 }
3501
3502 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* get gesture control 2 register */
3503 if (res != 0) /* check result */
3504 {
3505 handle->debug_print("apds9960: get gesture control 2 register failed.\n"); /* get gesture control 2 register failed */
3506
3507 return 1; /* return error */
3508 }
3509 prev &= ~(0x3 << 3); /* clear config */
3510 prev |= current << 3; /* set config */
3511 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* set gesture control 2 register */
3512 if (res != 0) /* check result */
3513 {
3514 handle->debug_print("apds9960: set gesture control 2 register failed.\n"); /* set gesture control 2 register failed */
3515
3516 return 1; /* return error */
3517 }
3518
3519 return 0; /* success return 0 */
3520}
3521
3534{
3535 uint8_t res;
3536 uint8_t prev;
3537
3538 if (handle == NULL) /* check handle */
3539 {
3540 return 2; /* return error */
3541 }
3542 if (handle->inited != 1) /* check handle initialization */
3543 {
3544 return 3; /* return error */
3545 }
3546
3547 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* get gesture control 2 register */
3548 if (res != 0) /* check result */
3549 {
3550 handle->debug_print("apds9960: get gesture control 2 register failed.\n"); /* get gesture control 2 register failed */
3551
3552 return 1; /* return error */
3553 }
3554 *current = (apds9960_gesture_led_current_t)((prev >> 3) & 0x3); /* set the current */
3555
3556 return 0; /* success return 0 */
3557}
3558
3571{
3572 uint8_t res;
3573 uint8_t prev;
3574
3575 if (handle == NULL) /* check handle */
3576 {
3577 return 2; /* return error */
3578 }
3579 if (handle->inited != 1) /* check handle initialization */
3580 {
3581 return 3; /* return error */
3582 }
3583
3584 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* get gesture control 2 register */
3585 if (res != 0) /* check result */
3586 {
3587 handle->debug_print("apds9960: get gesture control 2 register failed.\n"); /* get gesture control 2 register failed */
3588
3589 return 1; /* return error */
3590 }
3591 prev &= ~(0x7 << 0); /* clear config */
3592 prev |= t << 0; /* set config */
3593 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* set gesture control 2 register */
3594 if (res != 0) /* check result */
3595 {
3596 handle->debug_print("apds9960: set gesture control 2 register failed.\n"); /* set gesture control 2 register failed */
3597
3598 return 1; /* return error */
3599 }
3600
3601 return 0; /* success return 0 */
3602}
3603
3616{
3617 uint8_t res;
3618 uint8_t prev;
3619
3620 if (handle == NULL) /* check handle */
3621 {
3622 return 2; /* return error */
3623 }
3624 if (handle->inited != 1) /* check handle initialization */
3625 {
3626 return 3; /* return error */
3627 }
3628
3629 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF2, (uint8_t *)&prev, 1); /* get gesture control 2 register */
3630 if (res != 0) /* check result */
3631 {
3632 handle->debug_print("apds9960: get gesture control 2 register failed.\n"); /* get gesture control 2 register failed */
3633
3634 return 1; /* return error */
3635 }
3636 *t = (apds9960_gesture_wait_time_t)((prev >> 0) & 0x7); /* set the wait time */
3637
3638 return 0; /* success return 0 */
3639}
3640
3653{
3654 uint8_t res;
3655 uint8_t prev;
3656
3657 if (handle == NULL) /* check handle */
3658 {
3659 return 2; /* return error */
3660 }
3661 if (handle->inited != 1) /* check handle initialization */
3662 {
3663 return 3; /* return error */
3664 }
3665
3666 if (offset >= 0) /* if >= 0 */
3667 {
3668 prev = offset; /* set the positive */
3669 }
3670 else /* <0 */
3671 {
3672 prev = 0x80; /* set the 0x80 */
3673 prev |= (-offset); /* set the negative */
3674 }
3675 res = a_apds9960_iic_write(handle, APDS9960_REG_GOFFSET_U, (uint8_t *)&prev, 1); /* set gesture up offset register */
3676 if (res != 0) /* check result */
3677 {
3678 handle->debug_print("apds9960: set gesture up offset register failed.\n"); /* set gesture up offset register failed */
3679
3680 return 1; /* return error */
3681 }
3682
3683 return 0; /* success return 0 */
3684}
3685
3698{
3699 uint8_t res;
3700 uint8_t prev;
3701
3702 if (handle == NULL) /* check handle */
3703 {
3704 return 2; /* return error */
3705 }
3706 if (handle->inited != 1) /* check handle initialization */
3707 {
3708 return 3; /* return error */
3709 }
3710
3711 res = a_apds9960_iic_read(handle, APDS9960_REG_GOFFSET_U, (uint8_t *)&prev, 1); /* get gesture up offset register */
3712 if (res != 0) /* check result */
3713 {
3714 handle->debug_print("apds9960: get gesture up offset register failed.\n"); /* get gesture up offset register failed */
3715
3716 return 1; /* return error */
3717 }
3718 if ((prev & 0x80) != 0) /* if < 0 */
3719 {
3720 prev &= ~0x80; /* clear 0x80 */
3721 *offset = -(int8_t)(prev); /* set the offset */
3722 }
3723 else /* >= 0 */
3724 {
3725 *offset = (int8_t)(prev); /* set the offset */
3726 }
3727
3728 return 0; /* success return 0 */
3729}
3730
3743{
3744 uint8_t res;
3745 uint8_t prev;
3746
3747 if (handle == NULL) /* check handle */
3748 {
3749 return 2; /* return error */
3750 }
3751 if (handle->inited != 1) /* check handle initialization */
3752 {
3753 return 3; /* return error */
3754 }
3755
3756 if (offset >= 0) /* if >= 0 */
3757 {
3758 prev = offset; /* set the positive */
3759 }
3760 else /* <0 */
3761 {
3762 prev = 0x80; /* set the 0x80 */
3763 prev |= (-offset); /* set the negative */
3764 }
3765 res = a_apds9960_iic_write(handle, APDS9960_REG_GOFFSET_D, (uint8_t *)&prev, 1); /* set gesture down offset register */
3766 if (res != 0) /* check result */
3767 {
3768 handle->debug_print("apds9960: set gesture down offset register failed.\n"); /* set gesture down offset register failed */
3769
3770 return 1; /* return error */
3771 }
3772
3773 return 0; /* success return 0 */
3774}
3775
3788{
3789 uint8_t res;
3790 uint8_t prev;
3791
3792 if (handle == NULL) /* check handle */
3793 {
3794 return 2; /* return error */
3795 }
3796 if (handle->inited != 1) /* check handle initialization */
3797 {
3798 return 3; /* return error */
3799 }
3800
3801 res = a_apds9960_iic_read(handle, APDS9960_REG_GOFFSET_D, (uint8_t *)&prev, 1); /* get gesture down offset register */
3802 if (res != 0) /* check result */
3803 {
3804 handle->debug_print("apds9960: get gesture down offset register failed.\n"); /* get gesture down offset register failed */
3805
3806 return 1; /* return error */
3807 }
3808 if ((prev & 0x80) != 0) /* if < 0 */
3809 {
3810 prev &= ~0x80; /* clear 0x80 */
3811 *offset = -(int8_t)(prev); /* set the offset */
3812 }
3813 else /* >= 0 */
3814 {
3815 *offset = (int8_t)(prev); /* set the offset */
3816 }
3817
3818 return 0; /* success return 0 */
3819}
3820
3833{
3834 uint8_t res;
3835 uint8_t prev;
3836
3837 if (handle == NULL) /* check handle */
3838 {
3839 return 2; /* return error */
3840 }
3841 if (handle->inited != 1) /* check handle initialization */
3842 {
3843 return 3; /* return error */
3844 }
3845
3846 if (offset >= 0) /* if >= 0 */
3847 {
3848 prev = offset; /* set the positive */
3849 }
3850 else /* <0 */
3851 {
3852 prev = 0x80; /* set the 0x80 */
3853 prev |= (-offset); /* set the negative */
3854 }
3855 res = a_apds9960_iic_write(handle, APDS9960_REG_GOFFSET_L, (uint8_t *)&prev, 1); /* set gesture left offset register */
3856 if (res != 0) /* check result */
3857 {
3858 handle->debug_print("apds9960: set gesture left offset register failed.\n"); /* set gesture left offset register failed */
3859
3860 return 1; /* return error */
3861 }
3862
3863 return 0; /* success return 0 */
3864}
3865
3878{
3879 uint8_t res;
3880 uint8_t prev;
3881
3882 if (handle == NULL) /* check handle */
3883 {
3884 return 2; /* return error */
3885 }
3886 if (handle->inited != 1) /* check handle initialization */
3887 {
3888 return 3; /* return error */
3889 }
3890
3891 res = a_apds9960_iic_read(handle, APDS9960_REG_GOFFSET_L, (uint8_t *)&prev, 1); /* get gesture left offset register */
3892 if (res != 0) /* check result */
3893 {
3894 handle->debug_print("apds9960: get gesture left offset register failed.\n"); /* get gesture left offset register failed */
3895
3896 return 1; /* return error */
3897 }
3898 if ((prev & 0x80) != 0) /* if < 0 */
3899 {
3900 prev &= ~0x80; /* clear 0x80 */
3901 *offset = -(int8_t)(prev); /* set the offset */
3902 }
3903 else /* >= 0 */
3904 {
3905 *offset = (int8_t)(prev); /* set the offset */
3906 }
3907
3908 return 0; /* success return 0 */
3909}
3910
3923{
3924 uint8_t res;
3925 uint8_t prev;
3926
3927 if (handle == NULL) /* check handle */
3928 {
3929 return 2; /* return error */
3930 }
3931 if (handle->inited != 1) /* check handle initialization */
3932 {
3933 return 3; /* return error */
3934 }
3935
3936 if (offset >= 0) /* if >= 0 */
3937 {
3938 prev = offset; /* set the positive */
3939 }
3940 else /* <0 */
3941 {
3942 prev = 0x80; /* set the 0x80 */
3943 prev |= (-offset); /* set the negative */
3944 }
3945 res = a_apds9960_iic_write(handle, APDS9960_REG_GOFFSET_R, (uint8_t *)&prev, 1); /* set gesture right offset register */
3946 if (res != 0) /* check result */
3947 {
3948 handle->debug_print("apds9960: set gesture right offset register failed.\n"); /* set gesture right offset register failed */
3949
3950 return 1; /* return error */
3951 }
3952
3953 return 0; /* success return 0 */
3954}
3955
3968{
3969 uint8_t res;
3970 uint8_t prev;
3971
3972 if (handle == NULL) /* check handle */
3973 {
3974 return 2; /* return error */
3975 }
3976 if (handle->inited != 1) /* check handle initialization */
3977 {
3978 return 3; /* return error */
3979 }
3980
3981 res = a_apds9960_iic_read(handle, APDS9960_REG_GOFFSET_R, (uint8_t *)&prev, 1); /* get gesture right offset register */
3982 if (res != 0) /* check result */
3983 {
3984 handle->debug_print("apds9960: get gesture right offset register failed.\n"); /* get gesture right offset register failed */
3985
3986 return 1; /* return error */
3987 }
3988 if ((prev & 0x80) != 0) /* if < 0 */
3989 {
3990 prev &= ~0x80; /* clear 0x80 */
3991 *offset = -(int8_t)(prev); /* set the offset */
3992 }
3993 else /* >= 0 */
3994 {
3995 *offset = (int8_t)(prev); /* set the offset */
3996 }
3997
3998 return 0; /* success return 0 */
3999}
4000
4013{
4014 uint8_t res;
4015 uint8_t prev;
4016
4017 if (handle == NULL) /* check handle */
4018 {
4019 return 2; /* return error */
4020 }
4021 if (handle->inited != 1) /* check handle initialization */
4022 {
4023 return 3; /* return error */
4024 }
4025
4026 res = a_apds9960_iic_read(handle, APDS9960_REG_GPULSE, (uint8_t *)&prev, 1); /* get gesture pulse count register */
4027 if (res != 0) /* check result */
4028 {
4029 handle->debug_print("apds9960: get gesture pulse count register failed.\n"); /* get gesture pulse count register failed */
4030
4031 return 1; /* return error */
4032 }
4033 prev &= ~(3 << 6); /* clear config */
4034 prev |= len << 6; /* set config */
4035 res = a_apds9960_iic_write(handle, APDS9960_REG_GPULSE, (uint8_t *)&prev, 1); /* set gesture pulse count register */
4036 if (res != 0) /* check result */
4037 {
4038 handle->debug_print("apds9960: set gesture pulse count register failed.\n"); /* set gesture pulse count register failed */
4039
4040 return 1; /* return error */
4041 }
4042
4043 return 0; /* success return 0 */
4044}
4045
4058{
4059 uint8_t res;
4060 uint8_t prev;
4061
4062 if (handle == NULL) /* check handle */
4063 {
4064 return 2; /* return error */
4065 }
4066 if (handle->inited != 1) /* check handle initialization */
4067 {
4068 return 3; /* return error */
4069 }
4070
4071 res = a_apds9960_iic_read(handle, APDS9960_REG_GPULSE, (uint8_t *)&prev, 1); /* get gesture pulse count register */
4072 if (res != 0) /* check result */
4073 {
4074 handle->debug_print("apds9960: get gesture pulse count register failed.\n"); /* get gesture pulse count register failed */
4075
4076 return 1; /* return error */
4077 }
4078 *len = (apds9960_gesture_pulse_length_t)((prev >> 6) & 0x3); /* get length */
4079
4080 return 0; /* success return 0 */
4081}
4082
4096{
4097 uint8_t res;
4098 uint8_t prev;
4099
4100 if (handle == NULL) /* check handle */
4101 {
4102 return 2; /* return error */
4103 }
4104 if (handle->inited != 1) /* check handle initialization */
4105 {
4106 return 3; /* return error */
4107 }
4108 if (count > 0x3F) /* check count */
4109 {
4110 handle->debug_print("apds9960: count is over 63.\n"); /* count is over 63 */
4111
4112 return 4; /* return error */
4113 }
4114
4115 res = a_apds9960_iic_read(handle, APDS9960_REG_GPULSE, (uint8_t *)&prev, 1); /* get gesture pulse count register */
4116 if (res != 0) /* check result */
4117 {
4118 handle->debug_print("apds9960: get gesture pulse count register failed.\n"); /* get gesture pulse count register failed */
4119
4120 return 1; /* return error */
4121 }
4122 prev &= ~(0x3F << 0); /* clear config */
4123 prev |= (count & 0x3F) << 0; /* set config */
4124 res = a_apds9960_iic_write(handle, APDS9960_REG_GPULSE, (uint8_t *)&prev, 1); /* set gesture pulse count register */
4125 if (res != 0) /* check result */
4126 {
4127 handle->debug_print("apds9960: set gesture pulse count register failed.\n"); /* set gesture pulse count register failed */
4128
4129 return 1; /* return error */
4130 }
4131
4132 return 0; /* success return 0 */
4133}
4134
4147{
4148 uint8_t res;
4149 uint8_t prev;
4150
4151 if (handle == NULL) /* check handle */
4152 {
4153 return 2; /* return error */
4154 }
4155 if (handle->inited != 1) /* check handle initialization */
4156 {
4157 return 3; /* return error */
4158 }
4159
4160 res = a_apds9960_iic_read(handle, APDS9960_REG_GPULSE, (uint8_t *)&prev, 1); /* get gesture pulse count register */
4161 if (res != 0) /* check result */
4162 {
4163 handle->debug_print("apds9960: get gesture pulse count register failed.\n"); /* get gesture pulse count register failed */
4164
4165 return 1; /* return error */
4166 }
4167 *count = prev & 0x3F; /* get count */
4168
4169 return 0; /* success return 0 */
4170}
4171
4184{
4185 uint8_t res;
4186 uint8_t prev;
4187
4188 if (handle == NULL) /* check handle */
4189 {
4190 return 2; /* return error */
4191 }
4192 if (handle->inited != 1) /* check handle initialization */
4193 {
4194 return 3; /* return error */
4195 }
4196
4197 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF3, (uint8_t *)&prev, 1); /* get gesture conf 3 register */
4198 if (res != 0) /* check result */
4199 {
4200 handle->debug_print("apds9960: get gesture conf 3 register failed.\n"); /* get gesture conf 3 register failed */
4201
4202 return 1; /* return error */
4203 }
4204 prev &= ~(3 << 0); /* clear config */
4205 prev |= s << 0; /* set config */
4206 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF3, (uint8_t *)&prev, 1); /* set gesture conf 3 register */
4207 if (res != 0) /* check result */
4208 {
4209 handle->debug_print("apds9960: set gesture conf 3 register failed.\n"); /* set gesture conf 3 register failed */
4210
4211 return 1; /* return error */
4212 }
4213
4214 return 0; /* success return 0 */
4215}
4216
4229{
4230 uint8_t res;
4231 uint8_t prev;
4232
4233 if (handle == NULL) /* check handle */
4234 {
4235 return 2; /* return error */
4236 }
4237 if (handle->inited != 1) /* check handle initialization */
4238 {
4239 return 3; /* return error */
4240 }
4241
4242 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF3, (uint8_t *)&prev, 1); /* get gesture conf 3 register */
4243 if (res != 0) /* check result */
4244 {
4245 handle->debug_print("apds9960: get gesture conf 3 register failed.\n"); /* get gesture conf 3 register failed */
4246
4247 return 1; /* return error */
4248 }
4249 *s = (apds9960_gesture_dimension_select_t)(prev & 0x3); /* get the select */
4250
4251 return 0; /* success return 0 */
4252}
4253
4265{
4266 uint8_t res;
4267 uint8_t prev;
4268
4269 if (handle == NULL) /* check handle */
4270 {
4271 return 2; /* return error */
4272 }
4273 if (handle->inited != 1) /* check handle initialization */
4274 {
4275 return 3; /* return error */
4276 }
4277
4278 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* get gesture conf 4 register */
4279 if (res != 0) /* check result */
4280 {
4281 handle->debug_print("apds9960: get gesture conf 4 register failed.\n"); /* get gesture conf 4 register failed */
4282
4283 return 1; /* return error */
4284 }
4285 prev &= ~(1 << 2); /* clear config */
4286 prev |= 1 << 2; /* set config */
4287 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* set gesture conf 4 register */
4288 if (res != 0) /* check result */
4289 {
4290 handle->debug_print("apds9960: set gesture conf 4 register failed.\n"); /* set gesture conf 4 register failed */
4291
4292 return 1; /* return error */
4293 }
4294
4295 return 0; /* success return 0 */
4296}
4297
4310{
4311 uint8_t res;
4312 uint8_t prev;
4313
4314 if (handle == NULL) /* check handle */
4315 {
4316 return 2; /* return error */
4317 }
4318 if (handle->inited != 1) /* check handle initialization */
4319 {
4320 return 3; /* return error */
4321 }
4322
4323 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* get gesture conf 4 register */
4324 if (res != 0) /* check result */
4325 {
4326 handle->debug_print("apds9960: get gesture conf 4 register failed.\n"); /* get gesture conf 4 register failed */
4327
4328 return 1; /* return error */
4329 }
4330 prev &= ~(1 << 1); /* clear config */
4331 prev |= enable << 1; /* set config */
4332 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* set gesture conf 4 register */
4333 if (res != 0) /* check result */
4334 {
4335 handle->debug_print("apds9960: set gesture conf 4 register failed.\n"); /* set gesture conf 4 register failed */
4336
4337 return 1; /* return error */
4338 }
4339
4340 return 0; /* success return 0 */
4341}
4342
4355{
4356 uint8_t res;
4357 uint8_t prev;
4358
4359 if (handle == NULL) /* check handle */
4360 {
4361 return 2; /* return error */
4362 }
4363 if (handle->inited != 1) /* check handle initialization */
4364 {
4365 return 3; /* return error */
4366 }
4367
4368 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* get gesture conf 4 register */
4369 if (res != 0) /* check result */
4370 {
4371 handle->debug_print("apds9960: get gesture conf 4 register failed.\n"); /* get gesture conf 4 register failed */
4372
4373 return 1; /* return error */
4374 }
4375 *enable = (apds9960_bool_t)((prev >> 1) & 0x1); /* set bool */
4376
4377 return 0; /* success return 0 */
4378}
4379
4392{
4393 uint8_t res;
4394 uint8_t prev;
4395
4396 if (handle == NULL) /* check handle */
4397 {
4398 return 2; /* return error */
4399 }
4400 if (handle->inited != 1) /* check handle initialization */
4401 {
4402 return 3; /* return error */
4403 }
4404
4405 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* get gesture conf 4 register */
4406 if (res != 0) /* check result */
4407 {
4408 handle->debug_print("apds9960: get gesture conf 4 register failed.\n"); /* get gesture conf 4 register failed */
4409
4410 return 1; /* return error */
4411 }
4412 prev &= ~(1 << 0); /* clear config */
4413 prev |= enable << 0; /* set config */
4414 res = a_apds9960_iic_write(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* set gesture conf 4 register */
4415 if (res != 0) /* check result */
4416 {
4417 handle->debug_print("apds9960: set gesture conf 4 register failed.\n"); /* set gesture conf 4 register failed */
4418
4419 return 1; /* return error */
4420 }
4421
4422 return 0; /* success return 0 */
4423}
4424
4437{
4438 uint8_t res;
4439 uint8_t prev;
4440
4441 if (handle == NULL) /* check handle */
4442 {
4443 return 2; /* return error */
4444 }
4445 if (handle->inited != 1) /* check handle initialization */
4446 {
4447 return 3; /* return error */
4448 }
4449
4450 res = a_apds9960_iic_read(handle, APDS9960_REG_GCONF4, (uint8_t *)&prev, 1); /* get gesture conf 4 register */
4451 if (res != 0) /* check result */
4452 {
4453 handle->debug_print("apds9960: get gesture conf 4 register failed.\n"); /* get gesture conf 4 register failed */
4454
4455 return 1; /* return error */
4456 }
4457 *enable = (apds9960_bool_t)((prev >> 0) & 0x1); /* set bool */
4458
4459 return 0; /* success return 0 */
4460}
4461
4474{
4475 uint8_t res;
4476 uint8_t prev;
4477
4478 if (handle == NULL) /* check handle */
4479 {
4480 return 2; /* return error */
4481 }
4482 if (handle->inited != 1) /* check handle initialization */
4483 {
4484 return 3; /* return error */
4485 }
4486
4487 res = a_apds9960_iic_read(handle, APDS9960_REG_GFLVL, (uint8_t *)&prev, 1); /* get gesture fifo level register */
4488 if (res != 0) /* check result */
4489 {
4490 handle->debug_print("apds9960: get gesture fifo level register failed.\n"); /* get gesture fifo level register failed */
4491
4492 return 1; /* return error */
4493 }
4494 *level = prev; /* set fifo level */
4495
4496 return 0; /* success return 0 */
4497}
4498
4510uint8_t apds9960_get_gesture_status(apds9960_handle_t *handle, uint8_t *status)
4511{
4512 uint8_t res;
4513 uint8_t prev;
4514
4515 if (handle == NULL) /* check handle */
4516 {
4517 return 2; /* return error */
4518 }
4519 if (handle->inited != 1) /* check handle initialization */
4520 {
4521 return 3; /* return error */
4522 }
4523
4524 res = a_apds9960_iic_read(handle, APDS9960_REG_GSTATUS, (uint8_t *)&prev, 1); /* get gesture status register */
4525 if (res != 0) /* check result */
4526 {
4527 handle->debug_print("apds9960: get gesture status register failed.\n"); /* get gesture status register failed */
4528
4529 return 1; /* return error */
4530 }
4531 *status = prev; /* set status */
4532
4533 return 0; /* success return 0 */
4534}
4535
4547{
4548 uint8_t res;
4549 uint8_t prev;
4550
4551 if (handle == NULL) /* check handle */
4552 {
4553 return 2; /* return error */
4554 }
4555 if (handle->inited != 1) /* check handle initialization */
4556 {
4557 return 3; /* return error */
4558 }
4559
4560 prev = 0xFF; /* set 0xFF */
4561 res = a_apds9960_iic_write(handle, APDS9960_REG_IFORCE, (uint8_t *)&prev, 1); /* forces an interrupt */
4562 if (res != 0) /* check result */
4563 {
4564 handle->debug_print("apds9960: forces an interrupt failed.\n"); /* forces an interrupt failed */
4565
4566 return 1; /* return error */
4567 }
4568
4569 return 0; /* success return 0 */
4570}
4571
4583{
4584 uint8_t res;
4585 uint8_t prev;
4586
4587 if (handle == NULL) /* check handle */
4588 {
4589 return 2; /* return error */
4590 }
4591 if (handle->inited != 1) /* check handle initialization */
4592 {
4593 return 3; /* return error */
4594 }
4595
4596 prev = 0xFF; /* set 0xFF */
4597 res = a_apds9960_iic_write(handle, APDS9960_REG_PICLEAR, (uint8_t *)&prev, 1); /* proximity interrupt clear */
4598 if (res != 0) /* check result */
4599 {
4600 handle->debug_print("apds9960: proximity interrupt clear failed.\n"); /* proximity interrupt clear failed */
4601
4602 return 1; /* return error */
4603 }
4604
4605 return 0; /* success return 0 */
4606}
4607
4619{
4620 uint8_t res;
4621 uint8_t prev;
4622
4623 if (handle == NULL) /* check handle */
4624 {
4625 return 2; /* return error */
4626 }
4627 if (handle->inited != 1) /* check handle initialization */
4628 {
4629 return 3; /* return error */
4630 }
4631
4632 prev = 0xFF; /* set 0xFF */
4633 res = a_apds9960_iic_write(handle, APDS9960_REG_CICLEAR, (uint8_t *)&prev, 1); /* als interrupt clear */
4634 if (res != 0) /* check result */
4635 {
4636 handle->debug_print("apds9960: als interrupt clear failed.\n"); /* als interrupt clear failed */
4637
4638 return 1; /* return error */
4639 }
4640
4641 return 0; /* success return 0 */
4642}
4643
4655{
4656 uint8_t res;
4657 uint8_t prev;
4658
4659 if (handle == NULL) /* check handle */
4660 {
4661 return 2; /* return error */
4662 }
4663 if (handle->inited != 1) /* check handle initialization */
4664 {
4665 return 3; /* return error */
4666 }
4667
4668 prev = 0xFF; /* set 0xFF */
4669 res = a_apds9960_iic_write(handle, APDS9960_REG_AICLEAR, (uint8_t *)&prev, 1); /* clear all non-gesture interrupts */
4670 if (res != 0) /* check result */
4671 {
4672 handle->debug_print("apds9960: clear all non-gesture interrupts failed.\n"); /* clear all non-gesture interrupts failed */
4673
4674 return 1; /* return error */
4675 }
4676
4677 return 0; /* success return 0 */
4678}
4679
4692uint8_t apds9960_read_gesture_fifo(apds9960_handle_t *handle, uint8_t (*data)[4], uint8_t *len)
4693{
4694 uint8_t res;
4695 uint8_t level;
4696
4697 if (handle == NULL) /* check handle */
4698 {
4699 return 2; /* return error */
4700 }
4701 if (handle->inited != 1) /* check handle initialization */
4702 {
4703 return 3; /* return error */
4704 }
4705
4706 res = a_apds9960_iic_read(handle, APDS9960_REG_GFLVL, (uint8_t *)&level, 1); /* get gesture fifo level register */
4707 if (res != 0) /* check result */
4708 {
4709 handle->debug_print("apds9960: get gesture fifo level register failed.\n"); /* get gesture fifo level register failed */
4710
4711 return 1; /* return error */
4712 }
4713
4714 *len = level < (*len) ? level : (*len);
4715 res = a_apds9960_iic_read(handle, APDS9960_REG_GFIFO_U, (uint8_t *)data, (*len) * 4); /* read gesture fifo */
4716 if (res != 0) /* check result */
4717 {
4718 handle->debug_print("apds9960: read gesture fifo failed.\n"); /* read gesture fifo failed */
4719
4720 return 1; /* return error */
4721 }
4722
4723 return 0; /* success return 0 */
4724}
4725
4739uint8_t apds9960_set_reg(apds9960_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
4740{
4741 if (handle == NULL) /* check handle */
4742 {
4743 return 2; /* return error */
4744 }
4745 if (handle->inited != 1) /* check handle initialization */
4746 {
4747 return 3; /* return error */
4748 }
4749
4750 if (a_apds9960_iic_write(handle, reg, buf, len) != 0) /* write data */
4751 {
4752 return 1; /* return error */
4753 }
4754 else
4755 {
4756 return 0; /* success return 0 */
4757 }
4758}
4759
4773uint8_t apds9960_get_reg(apds9960_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
4774{
4775 if (handle == NULL) /* check handle */
4776 {
4777 return 2; /* return error */
4778 }
4779 if (handle->inited != 1) /* check handle initialization */
4780 {
4781 return 3; /* return error */
4782 }
4783
4784 if (a_apds9960_iic_read(handle, reg, buf, len) != 0) /* read data */
4785 {
4786 return 1; /* return error */
4787 }
4788 else
4789 {
4790 return 0; /* success return 0 */
4791 }
4792}
4793
4803{
4804 if (info == NULL) /* check handle */
4805 {
4806 return 2; /* return error */
4807 }
4808
4809 memset(info, 0, sizeof(apds9960_info_t)); /* initialize apds9960 info structure */
4810 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
4811 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
4812 strncpy(info->interface, "IIC", 8); /* copy interface name */
4813 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
4814 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
4815 info->max_current_ma = MAX_CURRENT; /* set maximum current */
4816 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
4817 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
4818 info->driver_version = DRIVER_VERSION; /* set driver version */
4819
4820 return 0; /* success return 0 */
4821}
#define APDS9960_REG_GCONF4
#define APDS9960_REG_CONFIG2
#define APDS9960_REG_GCONF3
#define APDS9960_REG_PIHT
#define APDS9960_ADDRESS
iic address definition
#define MAX_CURRENT
#define APDS9960_REG_PPULSE
#define APDS9960_REG_GPENTH
#define APDS9960_REG_CONFIG1
#define APDS9960_REG_RDATAL
#define APDS9960_REG_AILTL
#define APDS9960_REG_ATIME
#define APDS9960_REG_GPULSE
#define APDS9960_REG_BDATAL
#define APDS9960_REG_PERS
#define APDS9960_REG_WTIME
#define APDS9960_REG_CONFIG3
#define APDS9960_REG_GOFFSET_R
#define APDS9960_REG_GSTATUS
#define SUPPLY_VOLTAGE_MAX
#define APDS9960_REG_PICLEAR
#define APDS9960_REG_IFORCE
#define APDS9960_REG_GFLVL
#define APDS9960_REG_GOFFSET_L
#define APDS9960_REG_AIHTL
#define APDS9960_REG_PDATA
#define APDS9960_REG_GOFFSET_D
#define APDS9960_REG_CDATAL
#define APDS9960_REG_PILT
#define TEMPERATURE_MAX
#define APDS9960_REG_ID
#define APDS9960_REG_GOFFSET_U
#define APDS9960_REG_GFIFO_U
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define APDS9960_REG_CONTROL
#define SUPPLY_VOLTAGE_MIN
#define APDS9960_REG_GDATAL
#define APDS9960_REG_STATUS
#define APDS9960_REG_POFFSET_UR
#define APDS9960_REG_GCONF2
#define APDS9960_REG_CICLEAR
#define APDS9960_REG_GEXTH
#define APDS9960_REG_ENABLE
chip register definition
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define APDS9960_REG_GCONF1
#define APDS9960_REG_POFFSET_DL
#define APDS9960_REG_AICLEAR
driver apds9960 header file
uint8_t apds9960_get_proximity_interrupt_high_threshold(apds9960_handle_t *handle, uint8_t *threshold)
get the proximity interrupt high threshold
uint8_t apds9960_set_gesture_dimension(apds9960_handle_t *handle, apds9960_gesture_dimension_select_t s)
set the gesture dimension
apds9960_led_boost_t
apds9960 led boost enumeration definition
uint8_t apds9960_set_gesture_gain(apds9960_handle_t *handle, apds9960_gesture_gain_control_t gain)
set the gesture gain
uint8_t apds9960_set_gesture_decode_sensitivity_2(apds9960_handle_t *handle, int32_t sensitivity)
set the gesture decode sensitivity 2
uint8_t apds9960_read_gesture_fifo(apds9960_handle_t *handle, uint8_t(*data)[4], uint8_t *len)
read data from the gesture fifo
uint8_t apds9960_get_als_interrupt_high_threshold(apds9960_handle_t *handle, uint16_t *threshold)
get the als interrupt high threshold
uint8_t apds9960_set_als_interrupt_high_threshold(apds9960_handle_t *handle, uint16_t threshold)
set the als interrupt high threshold
uint8_t apds9960_deinit(apds9960_handle_t *handle)
close the chip
uint8_t apds9960_set_gesture_wait_time(apds9960_handle_t *handle, apds9960_gesture_wait_time_t t)
set the gesture wait time
apds9960_gesture_led_current_t
apds9960 gesture led current enumeration definition
uint8_t apds9960_get_led_current(apds9960_handle_t *handle, apds9960_led_current_t *current)
get the led current
uint8_t apds9960_set_gesture_exit_persistence(apds9960_handle_t *handle, apds9960_gesture_exit_persistence_t persistence)
set the gesture exit persistence
uint8_t apds9960_get_gesture_led_current(apds9960_handle_t *handle, apds9960_gesture_led_current_t *current)
get the gesture led current
uint8_t apds9960_gesture_decode(apds9960_handle_t *handle, uint8_t(*data)[4], uint8_t len)
decode gestures from the fifo data
uint8_t apds9960_get_conf(apds9960_handle_t *handle, apds9960_conf_t conf, apds9960_bool_t *enable)
get the configuration
uint8_t apds9960_set_proximity_pulse_length(apds9960_handle_t *handle, apds9960_proximity_pulse_length_t len)
set the proximity pulse length
uint8_t apds9960_adc_integration_time_convert_to_data(apds9960_handle_t *handle, uint8_t reg, float *ms)
convert the register raw data to the integration time
uint8_t apds9960_get_gesture_up_offset(apds9960_handle_t *handle, int8_t *offset)
get the gesture up offset
uint8_t apds9960_get_proximity_pulse_count(apds9960_handle_t *handle, uint16_t *count)
get the proximity pulse count
uint8_t apds9960_get_gesture_exit_mask(apds9960_handle_t *handle, uint8_t *mask)
get the gesture exit mask
uint8_t apds9960_get_gesture_decode_threshold(apds9960_handle_t *handle, uint8_t *threshold)
get the gesture decode threshold
uint8_t apds9960_get_proximity_down_left_offset(apds9960_handle_t *handle, int8_t *offset)
get the proximity down left offset
apds9960_proximity_interrupt_cycle_t
apds9960 proximity interrupt cycle enumeration definition
uint8_t apds9960_set_saturation_interrupt(apds9960_handle_t *handle, apds9960_saturation_interrupt_t saturation, apds9960_bool_t enable)
set the saturation interrupt
uint8_t apds9960_set_proximity_down_left_offset(apds9960_handle_t *handle, int8_t offset)
set the proximity down left offset
uint8_t apds9960_set_als_interrupt_cycle(apds9960_handle_t *handle, apds9960_als_interrupt_cycle_t cycle)
set the als interrupt cycle
uint8_t apds9960_get_gesture_gain(apds9960_handle_t *handle, apds9960_gesture_gain_control_t *gain)
get the gesture gain
uint8_t apds9960_get_gesture_status(apds9960_handle_t *handle, uint8_t *status)
get the gesture status
uint8_t apds9960_gesture_fifo_clear(apds9960_handle_t *handle)
clear the gesture fifo status
apds9960_proximity_gain_t
apds9960 proximity gain enumeration definition
uint8_t apds9960_get_proximity_interrupt_cycle(apds9960_handle_t *handle, apds9960_proximity_interrupt_cycle_t *cycle)
get the proximity interrupt cycle
uint8_t apds9960_wait_time_convert_to_register(apds9960_handle_t *handle, float ms, uint8_t *reg)
convert the wait time to the register raw data
uint8_t apds9960_get_proximity_gain(apds9960_handle_t *handle, apds9960_proximity_gain_t *gain)
get the proximity gain
apds9960_gesture_dimension_select_t
apds9960 gesture dimension select enumeration definition
uint8_t apds9960_read_proximity(apds9960_handle_t *handle, uint8_t *proximity)
read the proximity data
uint8_t apds9960_set_proximity_gain(apds9960_handle_t *handle, apds9960_proximity_gain_t gain)
set the proximity gain
uint8_t apds9960_adc_integration_time_convert_to_register(apds9960_handle_t *handle, float ms, uint8_t *reg)
convert the adc integration time to the register raw data
uint8_t apds9960_init(apds9960_handle_t *handle)
initialize the chip
uint8_t apds9960_set_proximity_interrupt_cycle(apds9960_handle_t *handle, apds9960_proximity_interrupt_cycle_t cycle)
set the proximity interrupt cycle
uint8_t apds9960_set_gesture_right_offset(apds9960_handle_t *handle, int8_t offset)
set the gesture right offset
uint8_t apds9960_get_saturation_interrupt(apds9960_handle_t *handle, apds9960_saturation_interrupt_t saturation, apds9960_bool_t *enable)
get the saturation interrupt
uint8_t apds9960_set_gesture_fifo_threshold(apds9960_handle_t *handle, apds9960_gesture_fifo_threshold_t threshold)
set the gesture fifo threshold
uint8_t apds9960_set_proximity_pulse_count(apds9960_handle_t *handle, uint16_t count)
set the proximity pulse count
uint8_t apds9960_set_proximity_up_right_offset(apds9960_handle_t *handle, int8_t offset)
set the proximity up right offset
uint8_t apds9960_set_gesture_pulse_length(apds9960_handle_t *handle, apds9960_gesture_pulse_length_t len)
set the gesture pulse length
uint8_t apds9960_irq_handler(apds9960_handle_t *handle)
irq handler
uint8_t apds9960_set_proximity_gain_compensation(apds9960_handle_t *handle, apds9960_bool_t enable)
enable or disable the proximity gain compensation
uint8_t apds9960_get_als_interrupt_cycle(apds9960_handle_t *handle, apds9960_als_interrupt_cycle_t *cycle)
get the als interrupt cycle
uint8_t apds9960_set_gesture_led_current(apds9960_handle_t *handle, apds9960_gesture_led_current_t current)
set the gesture led current
uint8_t apds9960_get_gesture_pulse_length(apds9960_handle_t *handle, apds9960_gesture_pulse_length_t *len)
get the gesture pulse length
uint8_t apds9960_force_interrupt(apds9960_handle_t *handle)
force an interrupt
uint8_t apds9960_get_gesture_dimension_select(apds9960_handle_t *handle, apds9960_gesture_dimension_select_t *s)
get the gesture dimension
apds9960_gesture_pulse_length_t
apds9960 gesture pulse length enumeration definition
uint8_t apds9960_get_proximity_pulse_length(apds9960_handle_t *handle, apds9960_proximity_pulse_length_t *len)
get the proximity pulse length
uint8_t apds9960_get_gesture_proximity_exit_threshold(apds9960_handle_t *handle, uint8_t *threshold)
get the gesture proximity exit threshold
uint8_t apds9960_get_als_interrupt_low_threshold(apds9960_handle_t *handle, uint16_t *threshold)
get the als interrupt low threshold
uint8_t apds9960_set_gesture_pulse_count(apds9960_handle_t *handle, uint16_t count)
set the gesture pulse count
uint8_t apds9960_wait_time_convert_to_data(apds9960_handle_t *handle, uint8_t reg, float *ms)
convert the register raw data to the wait time
uint8_t apds9960_get_gesture_exit_persistence(apds9960_handle_t *handle, apds9960_gesture_exit_persistence_t *persistence)
get the gesture exit persistence
uint8_t apds9960_set_wait_long(apds9960_handle_t *handle, apds9960_bool_t enable)
enable or disable the wait long
apds9960_gesture_wait_time_t
apds9960 gesture wait time enumeration definition
uint8_t apds9960_set_gesture_exit_mask(apds9960_handle_t *handle, uint8_t mask)
set the gesture exit mask
apds9960_bool_t
apds9960 bool enumeration definition
uint8_t apds9960_set_als_color_gain(apds9960_handle_t *handle, apds9960_als_color_gain_t gain)
set the als color gain
uint8_t apds9960_get_status(apds9960_handle_t *handle, uint8_t *status)
get the status
uint8_t apds9960_set_gesture_proximity_enter_threshold(apds9960_handle_t *handle, uint8_t threshold)
set the gesture proximity enter threshold
struct apds9960_info_s apds9960_info_t
apds9960 information structure definition
uint8_t apds9960_get_gesture_down_offset(apds9960_handle_t *handle, int8_t *offset)
get the gesture down offset
uint8_t apds9960_get_proximity_up_right_offset(apds9960_handle_t *handle, int8_t *offset)
get the proximity up right offset
uint8_t apds9960_set_gesture_mode(apds9960_handle_t *handle, apds9960_bool_t enable)
enable or disable the gesture mode
uint8_t apds9960_get_led_boost(apds9960_handle_t *handle, apds9960_led_boost_t *boost)
get the led boost
uint8_t apds9960_set_led_boost(apds9960_handle_t *handle, apds9960_led_boost_t boost)
set the led boost
struct apds9960_handle_s apds9960_handle_t
apds9960 handle structure definition
uint8_t apds9960_get_wait_long(apds9960_handle_t *handle, apds9960_bool_t *enable)
get the wait long status
uint8_t apds9960_get_gesture_right_offset(apds9960_handle_t *handle, int8_t *offset)
get the gesture right offset
uint8_t apds9960_set_sleep_after_interrupt(apds9960_handle_t *handle, apds9960_bool_t enable)
enable or disable sleeping after interrupt
uint8_t apds9960_get_wait_time(apds9960_handle_t *handle, uint8_t *wait_time)
get the wait time
uint8_t apds9960_read_rgbc(apds9960_handle_t *handle, uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *clear)
read the rgbc data
uint8_t apds9960_all_non_gesture_interrupt_clear(apds9960_handle_t *handle)
clear the all not gesture interrupt
uint8_t apds9960_als_interrupt_clear(apds9960_handle_t *handle)
clear the als interrupt
uint8_t apds9960_set_conf(apds9960_handle_t *handle, apds9960_conf_t conf, apds9960_bool_t enable)
set the configuration
#define APDS9960_GESTURE_SENSITIVITY_2
uint8_t apds9960_set_als_interrupt_low_threshold(apds9960_handle_t *handle, uint16_t threshold)
set the als interrupt low threshold
uint8_t apds9960_get_als_color_gain(apds9960_handle_t *handle, apds9960_als_color_gain_t *gain)
get the als color gain
uint8_t apds9960_set_gesture_up_offset(apds9960_handle_t *handle, int8_t offset)
set the gesture up offset
apds9960_proximity_mask_t
apds9960 proximity mask enumeration definition
uint8_t apds9960_set_gesture_interrupt(apds9960_handle_t *handle, apds9960_bool_t enable)
enable or disable the gesture interrupt
apds9960_gesture_exit_persistence_t
apds9960 gesture exit persistence enumeration definition
uint8_t apds9960_get_adc_integration_time(apds9960_handle_t *handle, uint8_t *integration_time)
get the adc integration time
uint8_t apds9960_set_proximity_interrupt_low_threshold(apds9960_handle_t *handle, uint8_t threshold)
set the proximity interrupt low threshold
uint8_t apds9960_get_gesture_mode(apds9960_handle_t *handle, apds9960_bool_t *enable)
get the gesture mode status
apds9960_als_interrupt_cycle_t
apds9960 als interrupt cycle enumeration definition
uint8_t apds9960_get_proximity_gain_compensation(apds9960_handle_t *handle, apds9960_bool_t *enable)
get the proximity gain compensation status
apds9960_gesture_gain_control_t
apds9960 gesture gain control enumeration definition
uint8_t apds9960_set_gesture_left_offset(apds9960_handle_t *handle, int8_t offset)
set the gesture left offset
uint8_t apds9960_set_adc_integration_time(apds9960_handle_t *handle, uint8_t integration_time)
set the adc integration time
uint8_t apds9960_get_proximity_mask(apds9960_handle_t *handle, apds9960_proximity_mask_t mask, apds9960_bool_t *enable)
get the proximity mask status
uint8_t apds9960_get_proximity_interrupt_low_threshold(apds9960_handle_t *handle, uint8_t *threshold)
get the proximity interrupt low threshold
uint8_t apds9960_set_gesture_decode_threshold(apds9960_handle_t *handle, uint8_t threshold)
set the gesture decode threshold
uint8_t apds9960_get_gesture_decode_sensitivity_2(apds9960_handle_t *handle, int32_t *sensitivity)
get the gesture decode sensitivity 2
uint8_t apds9960_set_led_current(apds9960_handle_t *handle, apds9960_led_current_t current)
set the led current
uint8_t apds9960_get_gesture_fifo_threshold(apds9960_handle_t *handle, apds9960_gesture_fifo_threshold_t *threshold)
get the gesture fifo threshold
apds9960_saturation_interrupt_t
apds9960 saturation interrupt enumeration definition
uint8_t apds9960_get_gesture_decode_sensitivity_1(apds9960_handle_t *handle, int32_t *sensitivity)
get the gesture decode sensitivity 1
uint8_t apds9960_set_proximity_interrupt_high_threshold(apds9960_handle_t *handle, uint8_t threshold)
set the proximity interrupt high threshold
#define APDS9960_GESTURE_THRESHOLD
apds9960 gesture algorithm params definition
uint8_t apds9960_get_gesture_proximity_enter_threshold(apds9960_handle_t *handle, uint8_t *threshold)
get the gesture proximity enter threshold
apds9960_conf_t
apds9960 conf enumeration definition
uint8_t apds9960_proximity_interrupt_clear(apds9960_handle_t *handle)
clear the proximity interrupt
uint8_t apds9960_get_gesture_left_offset(apds9960_handle_t *handle, int8_t *offset)
get the gesture left offset
uint8_t apds9960_set_wait_time(apds9960_handle_t *handle, uint8_t wait_time)
set the wait time
uint8_t apds9960_set_gesture_proximity_exit_threshold(apds9960_handle_t *handle, uint8_t threshold)
set the gesture proximity exit threshold
apds9960_proximity_pulse_length_t
apds9960 proximity pulse length enumeration definition
uint8_t apds9960_get_gesture_wait_time(apds9960_handle_t *handle, apds9960_gesture_wait_time_t *t)
get the gesture wait time
apds9960_led_current_t
apds9960 led current enumeration definition
uint8_t apds9960_set_proximity_mask(apds9960_handle_t *handle, apds9960_proximity_mask_t mask, apds9960_bool_t enable)
enable or disable the proximity mask
uint8_t apds9960_info(apds9960_info_t *info)
get chip's information
apds9960_als_color_gain_t
apds9960 als and color gain enumeration definition
uint8_t apds9960_get_gesture_fifo_level(apds9960_handle_t *handle, uint8_t *level)
get the gesture fifo level
apds9960_gesture_fifo_threshold_t
apds9960 gesture fifo threshold enumeration definition
uint8_t apds9960_get_gesture_pulse_count(apds9960_handle_t *handle, uint16_t *count)
get the gesture pulse count
uint8_t apds9960_set_gesture_decode_sensitivity_1(apds9960_handle_t *handle, int32_t sensitivity)
set the gesture decode sensitivity 1
#define APDS9960_GESTURE_SENSITIVITY_1
uint8_t apds9960_get_sleep_after_interrupt(apds9960_handle_t *handle, apds9960_bool_t *enable)
get the sleeping after interrupt status
uint8_t apds9960_set_gesture_down_offset(apds9960_handle_t *handle, int8_t offset)
set the gesture down offset
uint8_t apds9960_get_gesture_interrupt(apds9960_handle_t *handle, apds9960_bool_t *enable)
get the gesture interrupt status
@ APDS9960_INTERRUPT_STATUS_CPSAT
@ APDS9960_INTERRUPT_STATUS_GESTURE_NEAR
@ APDS9960_INTERRUPT_STATUS_AVALID
@ APDS9960_INTERRUPT_STATUS_GVALID
@ APDS9960_INTERRUPT_STATUS_GESTURE_RIGHT
@ APDS9960_INTERRUPT_STATUS_GESTURE_LEFT
@ APDS9960_INTERRUPT_STATUS_GESTURE_DOWN
@ APDS9960_INTERRUPT_STATUS_AINT
@ APDS9960_INTERRUPT_STATUS_GINT
@ APDS9960_INTERRUPT_STATUS_PGSAT
@ APDS9960_INTERRUPT_STATUS_GESTURE_FAR
@ APDS9960_INTERRUPT_STATUS_PVALID
@ APDS9960_INTERRUPT_STATUS_GESTURE_UP
@ APDS9960_INTERRUPT_STATUS_PINT
@ APDS9960_INTERRUPT_STATUS_GFOV
@ APDS9960_GESTURE_STATUS_FIFO_VALID
@ APDS9960_GESTURE_STATUS_FIFO_OVERFLOW
@ APDS9960_STATUS_PVALID
@ APDS9960_STATUS_CPSAT
@ APDS9960_STATUS_PINT
@ APDS9960_STATUS_AVALID
@ APDS9960_STATUS_GINT
@ APDS9960_STATUS_PGSAT
@ APDS9960_STATUS_AINT
uint8_t apds9960_set_reg(apds9960_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t apds9960_get_reg(apds9960_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(uint8_t type)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
char manufacturer_name[32]