libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
apds9960.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_APDS9960_H
3#define DSY_APDS9960_H
4
5#define APDS9960_ADDRESS (0x39)
7#define APDS9960_UP 0x01
8#define APDS9960_DOWN 0x02
9#define APDS9960_LEFT 0x03
10#define APDS9960_RIGHT 0x04
13#define APDS9960_RAM 0x00
14#define APDS9960_ENABLE 0x80
15#define APDS9960_ATIME 0x81
16#define APDS9960_WTIME 0x83
17#define APDS9960_AILTIL 0x84
18#define APDS9960_AILTH 0x85
19#define APDS9960_AIHTL 0x86
20#define APDS9960_AIHTH 0x87
21#define APDS9960_PILT 0x89
22#define APDS9960_PIHT 0x8B
23#define APDS9960_PERS 0x8C
24#define APDS9960_CONFIG1 0x8D
25#define APDS9960_PPULSE 0x8E
26#define APDS9960_CONTROL 0x8F
27#define APDS9960_CONFIG2 0x90
28#define APDS9960_ID 0x92
29#define APDS9960_STATUS 0x93
30#define APDS9960_CDATAL 0x94
31#define APDS9960_CDATAH 0x95
32#define APDS9960_RDATAL 0x96
33#define APDS9960_RDATAH 0x97
34#define APDS9960_GDATAL 0x98
35#define APDS9960_GDATAH 0x99
36#define APDS9960_BDATAL 0x9A
37#define APDS9960_BDATAH 0x9B
38#define APDS9960_PDATA 0x9C
39#define APDS9960_POFFSET_UR 0x9D
40#define APDS9960_POFFSET_DL 0x9E
41#define APDS9960_CONFIG3 0x9F
42#define APDS9960_GPENTH 0xA0
43#define APDS9960_GEXTH 0xA1
44#define APDS9960_GCONF1 0xA2
45#define APDS9960_GCONF2 0xA3
46#define APDS9960_GOFFSET_U 0xA4
47#define APDS9960_GOFFSET_D 0xA5
48#define APDS9960_GOFFSET_L 0xA7
49#define APDS9960_GOFFSET_R 0xA9
50#define APDS9960_GPULSE 0xA6
51#define APDS9960_GCONF3 0xAA
52#define APDS9960_GCONF4 0xAB
53#define APDS9960_GFLVL 0xAE
54#define APDS9960_GSTATUS 0xAF
55#define APDS9960_IFORCE 0xE4
56#define APDS9960_PICLEAR 0xE5
57#define APDS9960_CICLEAR 0xE6
58#define APDS9960_AICLEAR 0xE7
59#define APDS9960_GFIFO_U 0xFC
60#define APDS9960_GFIFO_D 0xFD
61#define APDS9960_GFIFO_L 0xFE
62#define APDS9960_GFIFO_R 0xFF
63
64namespace daisy
65{
72{
73 public:
76
93
95 inline bool Init(Config config)
96 {
97 I2CHandle::Config i2c_config;
99 i2c_config.periph = config.periph;
100 i2c_config.speed = config.speed;
101
102 i2c_config.pin_config.scl = config.scl;
103 i2c_config.pin_config.sda = config.sda;
104
105 return I2CHandle::Result::OK != i2c_.Init(i2c_config);
106 }
107
109 bool Write(uint8_t *data, uint16_t size)
110 {
112 != i2c_.TransmitBlocking(APDS9960_ADDRESS, data, size, 10);
113 }
114
116 bool Read(uint8_t *data, uint16_t size)
117 {
119 != i2c_.ReceiveBlocking(APDS9960_ADDRESS, data, size, 10);
120 }
121
122 private:
123 I2CHandle i2c_;
124};
125
131template <typename Transport>
133{
134 public:
137
138 struct Config
139 {
141 uint8_t adcGain; // (0,3) -> {1x, 4x, 16x, 64x}
142
143 uint8_t gestureDimensions; // (0,2) -> {all, up/down, left/right}
144 uint8_t
145 gestureFifoThresh; // (0,3) -> interrupt after 1 dataset in fifo, 2, 3, 4
146 uint8_t gestureGain; // (0,3) -> {1x, 2x, 4x, 8x}
148
152
153 typename Transport::Config transport_config;
154
156 {
158 adcGain = 1; // 4x
159
160 gestureDimensions = 0; // gesture all
161 gestureFifoThresh = 1; // interrupt w/ 2 datasets in fifo
162 gestureGain = 2; // 4x gesture gain
164
165 color_mode = true;
166 prox_mode = true;
167 gesture_mode = false;
168 }
169 };
170
172 {
173 OK = 0,
174 ERR
175 };
176
177 // turn on/off elements
178 void enable(bool en = true);
183 {
184 config_ = config;
185 transport_error_ = false;
186
187 SetTransportErr(transport_.Init(config_.transport_config));
188
189 /* Set default integration time and gain */
191 SetADCGain(config.adcGain);
192
193 // disable everything to start
194 EnableGesture(false);
195 EnableProximity(false);
196 EnableColor(false);
197
198 SetColorInterrupt(false);
201
202 /* Note: by default, the device is in power down mode on bootup */
203 Enable(false);
204 System::Delay(10);
205 Enable(true);
206 System::Delay(10);
207
208 // default to all gesture dimensions
213 ResetCounts();
214
215 gpulse_.GPLEN = 0x03; // 32 us
216 gpulse_.GPULSE = 9; // 10 pulses
217 Write8(APDS9960_GPULSE, gpulse_.get());
218
219 // prox / color mode by default
220 // only one gesture or prox can be used at a time
221 // in gesture mode you should have prox mode on also, the data will just not be useful
223 EnableProximity(config_.prox_mode);
224 EnableColor(config_.color_mode);
225
226 return GetTransportErr();
227 }
228
232 void SetADCIntegrationTime(uint16_t iTimeMS)
233 {
234 float temp;
235
236 // convert ms into 2.78ms increments
237 temp = iTimeMS;
238 temp /= 2.78f;
239 temp = 256.f - temp;
240 if(temp > 255.f)
241 temp = 255.f;
242 if(temp < 0.f)
243 temp = 0.f;
244
245 /* Update the timing register */
246 Write8(APDS9960_ATIME, (uint8_t)temp);
247 }
248
254 {
255 float temp;
256
257 temp = Read8(APDS9960_ATIME);
258
259 // convert to units of 2.78 ms
260 temp = 256 - temp;
261 temp *= 2.78;
262 return temp;
263 }
264
268 void SetADCGain(uint8_t aGain)
269 {
270 control_.AGAIN = aGain;
271 Write8(APDS9960_CONTROL, control_.get());
272 }
273
280 void SetGestureOffset(uint8_t offset_up,
281 uint8_t offset_down,
282 uint8_t offset_left,
283 uint8_t offset_right)
284 {
285 Write8(APDS9960_GOFFSET_U, offset_up);
286 Write8(APDS9960_GOFFSET_D, offset_down);
287 Write8(APDS9960_GOFFSET_L, offset_left);
288 Write8(APDS9960_GOFFSET_R, offset_right);
289 }
290
294 void SetGestureDimensions(uint8_t dims)
295 {
296 Write8(APDS9960_GCONF3, dims & 0x03);
297 }
298
302 void SetGestureFIFOThreshold(uint8_t thresh)
303 {
304 gconf1_.GFIFOTH = thresh;
305 Write8(APDS9960_GCONF1, gconf1_.get());
306 }
307
311 void SetGestureGain(uint8_t gain)
312 {
313 gconf2_.GGAIN = gain;
314 Write8(APDS9960_GCONF2, gconf2_.get());
315 }
316
320 void SetGestureProximityThreshold(uint8_t thresh)
321 {
322 Write8(APDS9960_GPENTH, thresh);
323 }
324
329 void Enable(bool en)
330 {
331 enable_.PON = en;
332 Write8(APDS9960_ENABLE, enable_.get());
333 }
334
338 void EnableGesture(bool en)
339 {
340 if(!en)
341 {
342 gconf4_.GMODE = 0;
343 Write8(APDS9960_GCONF4, gconf4_.get());
344 }
345 enable_.GEN = en;
346 Write8(APDS9960_ENABLE, enable_.get());
347 ResetCounts();
348 }
349
353 void EnableProximity(bool en)
354 {
355 enable_.PEN = en;
356
357 Write8(APDS9960_ENABLE, enable_.get());
358 }
359
363 void EnableColor(bool en)
364 {
365 enable_.AEN = en;
366 Write8(APDS9960_ENABLE, enable_.get());
367 }
368
372 void SetColorInterrupt(bool en)
373 {
374 enable_.AIEN = en;
375 Write8(APDS9960_ENABLE, enable_.get());
376 }
377
382 {
383 enable_.PIEN = en;
384 Write8(APDS9960_ENABLE, enable_.get());
385 }
386
389 {
390 uint8_t val = APDS9960_AICLEAR;
391 SetTransportErr(transport_.Write(&val, 1));
392 }
393
396 {
397 gestCnt_ = 0;
398 UCount_ = 0;
399 DCount_ = 0;
400 LCount_ = 0;
401 RCount_ = 0;
402 }
403
404 void Write8(uint8_t reg, uint8_t data)
405 {
406 uint8_t buff[2] = {reg, data};
407 SetTransportErr(transport_.Write(buff, 2));
408 }
409
410 uint8_t Read8(uint8_t reg)
411 {
412 uint8_t buff[1] = {reg};
413 SetTransportErr(transport_.Write(buff, 1));
414 SetTransportErr(transport_.Read(buff, 1));
415 return buff[0];
416 }
417
418 uint16_t Read16R(uint8_t reg)
419 {
420 uint8_t ret[2];
421 SetTransportErr(transport_.Write(&reg, 1));
422 SetTransportErr(transport_.Read(ret, 2));
423
424 return (ret[1] << 8) | ret[0];
425 }
426
430 uint8_t ReadProximity() { return Read8(APDS9960_PDATA); }
431
435 void SetProxGain(uint8_t pGain)
436 {
437 control_.PGAIN = pGain;
438
439 /* Update the timing register */
440 Write8(APDS9960_CONTROL, control_.get());
441 }
442
446 uint8_t GetProxGain() { return ((Read8(APDS9960_CONTROL) & 0x0C) >> 2); }
447
452 void SetProxPulse(uint8_t pLen, uint8_t pulses)
453 {
454 if(pulses < 1)
455 pulses = 1;
456 if(pulses > 64)
457 pulses = 64;
458 pulses--;
459
460 ppulse_.PPLEN = pLen;
461 ppulse_.PPULSE = pulses;
462
463 Write8(APDS9960_PPULSE, ppulse_.get());
464 }
465
470 {
471 gstatus_.set(Read8(APDS9960_GSTATUS));
472 return gstatus_.GVALID;
473 }
474
478 uint8_t ReadGesture()
479 {
480 uint8_t toRead;
481 uint8_t buf[256];
482 unsigned long t = 0;
483 uint8_t gestureReceived;
484 while(true)
485 {
486 int up_down_diff = 0;
487 int left_right_diff = 0;
488 gestureReceived = 0;
489 if(!GestureValid())
490 return 0;
491
492 System::Delay(30);
493 toRead = Read8(APDS9960_GFLVL);
494
495 // produces sideffects needed for readGesture to work
496 uint8_t reg = APDS9960_GFIFO_U;
497 SetTransportErr(transport_.Write(&reg, 1));
498 SetTransportErr(transport_.Read(buf, toRead));
499
500 if(abs((int)buf[0] - (int)buf[1]) > 13)
501 up_down_diff += (int)buf[0] - (int)buf[1];
502
503 if(abs((int)buf[2] - (int)buf[3]) > 13)
504 left_right_diff += (int)buf[2] - (int)buf[3];
505
506 if(up_down_diff != 0)
507 {
508 if(up_down_diff < 0)
509 {
510 if(DCount_ > 0)
511 {
512 gestureReceived = APDS9960_UP;
513 }
514 else
515 UCount_++;
516 }
517 else if(up_down_diff > 0)
518 {
519 if(UCount_ > 0)
520 {
521 gestureReceived = APDS9960_DOWN;
522 }
523 else
524 DCount_++;
525 }
526 }
527
528 if(left_right_diff != 0)
529 {
530 if(left_right_diff < 0)
531 {
532 if(RCount_ > 0)
533 {
534 gestureReceived_ = APDS9960_LEFT;
535 }
536 else
537 LCount_++;
538 }
539 else if(left_right_diff > 0)
540 {
541 if(LCount_ > 0)
542 {
543 gestureReceived_ = APDS9960_RIGHT;
544 }
545 else
546 RCount_++;
547 }
548 }
549
550 if(up_down_diff != 0 || left_right_diff != 0)
551 t = System::GetNow();
552
553 if(gestureReceived || System::GetNow() - t > 300)
554 {
555 ResetCounts();
556 return gestureReceived;
557 }
558 }
559 }
560
565 void SetLED(uint8_t drive, uint8_t boost)
566 {
567 config2_.LED_BOOST = boost;
568 Write8(APDS9960_CONFIG2, config2_.get());
569
570 control_.LDRIVE = drive;
571 rite8(APDS9960_CONTROL, control_.get());
572 }
573
581 uint16_t CalculateColorTemperature(uint16_t r, uint16_t g, uint16_t b)
582 {
583 float X, Y, Z; /* RGB to XYZ correlation */
584 float xc, yc; /* Chromaticity co-ordinates */
585 float n; /* McCamy's formula */
586 float cct;
587
588 /* 1. Map RGB values to their XYZ counterparts. */
589 /* Based on 6500K fluorescent, 3000K fluorescent */
590 /* and 60W incandescent values for a wide range. */
591 /* Note: Y = Illuminance or lux */
592 X = (-0.14282F * r) + (1.54924F * g) + (-0.95641F * b);
593 Y = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
594 Z = (-0.68202F * r) + (0.77073F * g) + (0.56332F * b);
595
596 /* 2. Calculate the chromaticity co-ordinates */
597 xc = (X) / (X + Y + Z);
598 yc = (Y) / (X + Y + Z);
599
600 /* 3. Use McCamy's formula to determine the CCT */
601 n = (xc - 0.3320F) / (0.1858F - yc);
602
603 /* Calculate the final CCT */
604 cct = (449.0F * powf(n, 3)) + (3525.0F * powf(n, 2)) + (6823.3F * n)
605 + 5520.33F;
606
607 /* Return the results in degrees Kelvin */
608 return (uint16_t)cct;
609 }
610
617 uint16_t CalculateLux(uint16_t r, uint16_t g, uint16_t b)
618 {
619 float illuminance;
620
621 /* This only uses RGB ... how can we integrate clear or calculate lux */
622 /* based exclusively on clear since this might be more reliable? */
623 illuminance = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
624
625 return (uint16_t)illuminance;
626 }
627
632 void SetIntLimits(uint16_t low, uint16_t high)
633 {
634 Write8(APDS9960_AILTIL, low & 0xFF);
635 Write8(APDS9960_AILTH, low >> 8);
636 Write8(APDS9960_AIHTL, high & 0xFF);
637 Write8(APDS9960_AIHTH, high >> 8);
638 }
639
640
645 {
646 status_.set(Read8(APDS9960_STATUS));
647 return status_.AVALID;
648 }
649
650
655
656
661
662
667
668
673
674
681 void GetColorData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)
682 {
683 *c = GetColorDataClear();
684 *r = GetColorDataRed();
685 *g = GetColorDataGreen();
686 *b = GetColorDataBlue();
687 }
688
689 private:
690 uint8_t gestCnt_, UCount_, DCount_, LCount_, RCount_; // counters
691 uint8_t gestureReceived_;
692 bool transport_error_;
693
694 Config config_;
695 Transport transport_;
696
698 void SetTransportErr(bool err) { transport_error_ |= err; }
699
701 Result GetTransportErr()
702 {
703 Result ret = transport_error_ ? ERR : OK;
704 transport_error_ = false;
705 return ret;
706 }
707
708 struct gconf1
709 {
710 uint8_t GEXPERS : 2; // Gesture Exit Persistence
711 uint8_t GEXMSK : 4; // Gesture Exit Mask
712 uint8_t GFIFOTH : 2; // Gesture FIFO Threshold
713
714 uint8_t get() { return (GFIFOTH << 6) | (GEXMSK << 2) | GEXPERS; }
715 };
716
717 gconf1 gconf1_;
718
719 struct gconf2
720 {
721 uint8_t GWTIME : 3; // Gesture Wait Time
722 uint8_t GLDRIVE : 2; // Gesture LED Drive Strength
723 uint8_t GGAIN : 2; // Gesture Gain Control
724
725 uint8_t get() { return (GGAIN << 5) | (GLDRIVE << 3) | GWTIME; }
726 };
727 gconf2 gconf2_;
728
729 struct gconf4
730 {
731 uint8_t GMODE : 1; // Gesture mode
732 uint8_t GIEN : 2; // Gesture Interrupt Enable
733 uint8_t get() { return (GIEN << 1) | GMODE; }
734 void set(uint8_t data)
735 {
736 GIEN = (data >> 1) & 0x01;
737 GMODE = data & 0x01;
738 }
739 };
740 gconf4 gconf4_;
741
742 struct control
743 {
744 uint8_t AGAIN : 2; // ALS and Color gain control
745 uint8_t PGAIN : 2; // proximity gain control
746 uint8_t LDRIVE : 2; // led drive strength
747
748 uint8_t get() { return (LDRIVE << 6) | (PGAIN << 2) | AGAIN; }
749 };
750 control control_;
751
752 struct ppulse
753 {
754 uint8_t PPULSE : 6; //Proximity Pulse Count
755 uint8_t PPLEN : 2; // Proximity Pulse Length
756
757 uint8_t get() { return (PPLEN << 6) | PPULSE; }
758 };
759 ppulse ppulse_;
760
761 struct enable
762 {
763 uint8_t PON : 1; // power on
764 uint8_t AEN : 1; // ALS enable
765 uint8_t PEN : 1; // Proximity detect enable
766 uint8_t WEN : 1; // wait timer enable
767 uint8_t AIEN : 1; // ALS interrupt enable
768 uint8_t PIEN : 1; // proximity interrupt enable
769 uint8_t GEN : 1; // gesture enable
770
771 uint8_t get()
772 {
773 return (GEN << 6) | (PIEN << 5) | (AIEN << 4) | (WEN << 3)
774 | (PEN << 2) | (AEN << 1) | PON;
775 };
776 };
777 struct enable enable_;
778
779 struct gpulse
780 {
781 uint8_t GPULSE : 6; // Number of gesture pulses = GPULSE + 1
782 uint8_t GPLEN : 2; // Gesture Pulse Length
783
784 uint8_t get() { return (GPLEN << 6) | GPULSE; }
785 };
786 gpulse gpulse_;
787
788 struct gstatus
789 {
790 uint8_t GVALID : 1; // Gesture FIFO Data Are we OK to read FIFO?
791 uint8_t GFOV : 1; // Gesture FIFO Overflow Flag
792
793 void set(uint8_t data)
794 {
795 GFOV = (data >> 1) & 0x01;
796 GVALID = data & 0x01;
797 }
798 };
799 gstatus gstatus_;
800
801 struct config2
802 {
803 /* Additional LDR current during proximity and gesture LED pulses. Current
804 value, set by LDRIVE, is increased by the percentage of LED_BOOST.
805 */
806 uint8_t LED_BOOST : 2;
807 uint8_t CPSIEN : 1; // clear photodiode saturation int enable
808 uint8_t PSIEN : 1; // proximity saturation interrupt enable
809
810 uint8_t get()
811 {
812 return (PSIEN << 7) | (CPSIEN << 6) | (LED_BOOST << 4) | 1;
813 }
814 };
815 config2 config2_;
816
817 struct status
818 {
819 uint8_t AVALID : 1; // ALS Valid
820 uint8_t PVALID : 1; // Proximity Valid
821 uint8_t GINT : 1; // Gesture Interrupt
822 uint8_t AINT : 1; // ALS Interrupt
823 uint8_t PINT : 1; // Proximity Interrupt
824
825 /* Indicates that an analog saturation event occurred during a previous
826 proximity or gesture cycle. Once set, this bit remains set until cleared by
827 clear proximity interrupt special function command (0xE5 PICLEAR) or by
828 disabling Prox (PEN=0). This bit triggers an interrupt if PSIEN is set.
829 */
830 uint8_t PGSAT : 1;
831
832 /* Clear Photodiode Saturation. When asserted, the analog sensor was at the
833 upper end of its dynamic range. The bit can be de-asserted by sending a
834 Clear channel interrupt command (0xE6 CICLEAR) or by disabling the ADC
835 (AEN=0). This bit triggers an interrupt if CPSIEN is set.
836 */
837 uint8_t CPSAT : 1;
838
839 void set(uint8_t data)
840 {
841 AVALID = data & 0x01;
842 PVALID = (data >> 1) & 0x01;
843 GINT = (data >> 2) & 0x01;
844 AINT = (data >> 4) & 0x01;
845 PINT = (data >> 5) & 0x01;
846 PGSAT = (data >> 6) & 0x01;
847 CPSAT = (data >> 7) & 0x01;
848 }
849 };
850 status status_;
851};
852
856} // namespace daisy
857#endif
#define APDS9960_AICLEAR
Definition apds9960.h:58
#define APDS9960_AILTH
Definition apds9960.h:18
#define APDS9960_PPULSE
Definition apds9960.h:25
#define APDS9960_ENABLE
Definition apds9960.h:14
#define APDS9960_DOWN
Definition apds9960.h:8
#define APDS9960_CONFIG2
Definition apds9960.h:27
#define APDS9960_GCONF2
Definition apds9960.h:45
#define APDS9960_AIHTH
Definition apds9960.h:20
#define APDS9960_ADDRESS
Definition apds9960.h:5
#define APDS9960_GPULSE
Definition apds9960.h:50
#define APDS9960_RIGHT
Definition apds9960.h:10
#define APDS9960_STATUS
Definition apds9960.h:29
#define APDS9960_AIHTL
Definition apds9960.h:19
#define APDS9960_GOFFSET_D
Definition apds9960.h:47
#define APDS9960_UP
Definition apds9960.h:7
#define APDS9960_ATIME
Definition apds9960.h:15
#define APDS9960_GFLVL
Definition apds9960.h:53
#define APDS9960_GCONF3
Definition apds9960.h:51
#define APDS9960_GOFFSET_L
Definition apds9960.h:48
#define APDS9960_GOFFSET_U
Definition apds9960.h:46
#define APDS9960_GOFFSET_R
Definition apds9960.h:49
#define APDS9960_GDATAL
Definition apds9960.h:34
#define APDS9960_GPENTH
Definition apds9960.h:42
#define APDS9960_GCONF1
Definition apds9960.h:44
#define APDS9960_GCONF4
Definition apds9960.h:52
#define APDS9960_BDATAL
Definition apds9960.h:36
#define APDS9960_CDATAL
Definition apds9960.h:30
#define APDS9960_RDATAL
Definition apds9960.h:32
#define APDS9960_PDATA
Definition apds9960.h:38
#define APDS9960_LEFT
Definition apds9960.h:9
#define APDS9960_CONTROL
Definition apds9960.h:26
#define APDS9960_GSTATUS
Definition apds9960.h:54
#define APDS9960_GFIFO_U
Definition apds9960.h:59
#define APDS9960_AILTIL
Definition apds9960.h:17
Device support for APDS9960 gesture / RGB / proximity sensor.
Definition apds9960.h:133
uint16_t GetColorDataGreen()
Definition apds9960.h:660
uint16_t Read16R(uint8_t reg)
Definition apds9960.h:418
void SetGestureFIFOThreshold(uint8_t thresh)
Definition apds9960.h:302
void Write8(uint8_t reg, uint8_t data)
Definition apds9960.h:404
void SetADCIntegrationTime(uint16_t iTimeMS)
Definition apds9960.h:232
uint8_t ReadGesture()
Definition apds9960.h:478
void SetADCGain(uint8_t aGain)
Definition apds9960.h:268
void ResetCounts()
Definition apds9960.h:395
void SetColorInterrupt(bool en)
Definition apds9960.h:372
void SetProximityInterrupt(bool en)
Definition apds9960.h:381
void SetIntLimits(uint16_t low, uint16_t high)
Definition apds9960.h:632
Result Init(Config config)
Definition apds9960.h:182
void SetGestureDimensions(uint8_t dims)
Definition apds9960.h:294
Apds9960()
Definition apds9960.h:135
void EnableColor(bool en)
Definition apds9960.h:363
uint16_t CalculateLux(uint16_t r, uint16_t g, uint16_t b)
Definition apds9960.h:617
uint8_t Read8(uint8_t reg)
Definition apds9960.h:410
void Enable(bool en)
Definition apds9960.h:329
uint16_t GetColorDataBlue()
Definition apds9960.h:666
bool ColorDataReady()
Definition apds9960.h:644
void SetGestureProximityThreshold(uint8_t thresh)
Definition apds9960.h:320
void EnableProximity(bool en)
Definition apds9960.h:353
float GetADCIntegrationTime()
Definition apds9960.h:253
uint8_t ReadProximity()
Definition apds9960.h:430
void SetProxPulse(uint8_t pLen, uint8_t pulses)
Definition apds9960.h:452
void SetProxGain(uint8_t pGain)
Definition apds9960.h:435
uint16_t GetColorDataRed()
Definition apds9960.h:654
bool GestureValid()
Definition apds9960.h:469
void enable(bool en=true)
Result
Definition apds9960.h:172
@ OK
Definition apds9960.h:173
@ ERR
Definition apds9960.h:174
void EnableGesture(bool en)
Definition apds9960.h:338
void ClearInterrupt()
Definition apds9960.h:388
uint16_t CalculateColorTemperature(uint16_t r, uint16_t g, uint16_t b)
Definition apds9960.h:581
void SetGestureOffset(uint8_t offset_up, uint8_t offset_down, uint8_t offset_left, uint8_t offset_right)
Definition apds9960.h:280
~Apds9960()
Definition apds9960.h:136
uint16_t GetColorDataClear()
Definition apds9960.h:672
void SetGestureGain(uint8_t gain)
Definition apds9960.h:311
void SetLED(uint8_t drive, uint8_t boost)
Definition apds9960.h:565
uint8_t GetProxGain()
Definition apds9960.h:446
void GetColorData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)
Definition apds9960.h:681
Definition apds9960.h:72
bool Init(Config config)
Definition apds9960.h:95
bool Write(uint8_t *data, uint16_t size)
Definition apds9960.h:109
bool Read(uint8_t *data, uint16_t size)
Definition apds9960.h:116
~Apds9960I2CTransport()
Definition apds9960.h:75
Apds9960I2CTransport()
Definition apds9960.h:74
Definition i2c.h:25
Result Init(const Config &config)
Result ReceiveBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
Result TransmitBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
static uint32_t GetNow()
static void Delay(uint32_t delay_ms)
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ PORTB
Definition daisy_core.h:246
Definition apds9960.h:139
bool color_mode
Definition apds9960.h:149
uint16_t integrationTimeMs
Definition apds9960.h:140
uint8_t gestureGain
Definition apds9960.h:146
Config()
Definition apds9960.h:155
uint16_t gestureProximityThresh
Definition apds9960.h:147
bool prox_mode
Definition apds9960.h:150
Transport::Config transport_config
Definition apds9960.h:153
uint8_t gestureFifoThresh
Definition apds9960.h:145
uint8_t adcGain
Definition apds9960.h:141
bool gesture_mode
Definition apds9960.h:151
uint8_t gestureDimensions
Definition apds9960.h:143
Definition apds9960.h:78
Pin scl
Definition apds9960.h:81
I2CHandle::Config::Speed speed
Definition apds9960.h:80
Config()
Definition apds9960.h:84
Pin sda
Definition apds9960.h:82
I2CHandle::Config::Peripheral periph
Definition apds9960.h:79
Definition i2c.h:29
dsy_gpio_pin scl
Definition i2c.h:59
Mode mode
Definition i2c.h:64
Speed
Definition i2c.h:50
Speed speed
Definition i2c.h:63
dsy_gpio_pin sda
Definition i2c.h:60
struct daisy::I2CHandle::Config::@13 pin_config
Peripheral periph
Definition i2c.h:56
Peripheral
Definition i2c.h:39
representation of hardware port/pin combination
Definition daisy_core.h:261