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
109 bool Write(uint8_t *data, uint16_t size)
116 bool Read(uint8_t *data, uint16_t size)
131template <
typename Transport>
185 transport_error_ =
false;
215 gpulse_.GPLEN = 0x03;
226 return GetTransportErr();
270 control_.AGAIN = aGain;
283 uint8_t offset_right)
304 gconf1_.GFIFOTH = thresh;
313 gconf2_.GGAIN = gain;
391 SetTransportErr(transport_.Write(&val, 1));
406 uint8_t buff[2] = {reg, data};
407 SetTransportErr(transport_.Write(buff, 2));
412 uint8_t buff[1] = {reg};
413 SetTransportErr(transport_.Write(buff, 1));
414 SetTransportErr(transport_.Read(buff, 1));
421 SetTransportErr(transport_.Write(®, 1));
422 SetTransportErr(transport_.Read(ret, 2));
424 return (ret[1] << 8) | ret[0];
437 control_.PGAIN = pGain;
460 ppulse_.PPLEN = pLen;
461 ppulse_.PPULSE = pulses;
472 return gstatus_.GVALID;
483 uint8_t gestureReceived;
486 int up_down_diff = 0;
487 int left_right_diff = 0;
497 SetTransportErr(transport_.Write(®, 1));
498 SetTransportErr(transport_.Read(buf, toRead));
500 if(abs((
int)buf[0] - (
int)buf[1]) > 13)
501 up_down_diff += (int)buf[0] - (
int)buf[1];
503 if(abs((
int)buf[2] - (
int)buf[3]) > 13)
504 left_right_diff += (
int)buf[2] - (int)buf[3];
506 if(up_down_diff != 0)
517 else if(up_down_diff > 0)
528 if(left_right_diff != 0)
530 if(left_right_diff < 0)
539 else if(left_right_diff > 0)
550 if(up_down_diff != 0 || left_right_diff != 0)
556 return gestureReceived;
565 void SetLED(uint8_t drive, uint8_t boost)
567 config2_.LED_BOOST = boost;
570 control_.LDRIVE = drive;
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);
597 xc = (X) / (X + Y + Z);
598 yc = (Y) / (X + Y + Z);
601 n = (xc - 0.3320F) / (0.1858F - yc);
604 cct = (449.0F * powf(n, 3)) + (3525.0F * powf(n, 2)) + (6823.3F * n)
608 return (uint16_t)cct;
623 illuminance = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
625 return (uint16_t)illuminance;
647 return status_.AVALID;
690 uint8_t gestCnt_, UCount_, DCount_, LCount_, RCount_;
691 uint8_t gestureReceived_;
692 bool transport_error_;
695 Transport transport_;
698 void SetTransportErr(
bool err) { transport_error_ |= err; }
704 transport_error_ =
false;
714 uint8_t get() {
return (GFIFOTH << 6) | (GEXMSK << 2) | GEXPERS; }
725 uint8_t get() {
return (GGAIN << 5) | (GLDRIVE << 3) | GWTIME; }
733 uint8_t get() {
return (GIEN << 1) | GMODE; }
734 void set(uint8_t data)
736 GIEN = (data >> 1) & 0x01;
748 uint8_t get() {
return (LDRIVE << 6) | (PGAIN << 2) | AGAIN; }
757 uint8_t get() {
return (PPLEN << 6) | PPULSE; }
773 return (GEN << 6) | (PIEN << 5) | (AIEN << 4) | (WEN << 3)
774 | (PEN << 2) | (AEN << 1) | PON;
784 uint8_t get() {
return (GPLEN << 6) | GPULSE; }
793 void set(uint8_t data)
795 GFOV = (data >> 1) & 0x01;
796 GVALID = data & 0x01;
806 uint8_t LED_BOOST : 2;
812 return (PSIEN << 7) | (CPSIEN << 6) | (LED_BOOST << 4) | 1;
839 void set(uint8_t data)
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;
#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
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
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 void Delay(uint32_t delay_ms)
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ PORTB
Definition daisy_core.h:178
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
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
struct daisy::I2CHandle::Config::@15 pin_config
Mode mode
Definition i2c.h:65
Pin scl
Definition i2c.h:60
Speed speed
Definition i2c.h:64
Peripheral periph
Definition i2c.h:57
Peripheral
Definition i2c.h:40
Pin sda
Definition i2c.h:61
representation of hardware port/pin combination
Definition daisy_core.h:193