Sensorian  1.0
C API Reference Guide Library
APDS9300.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
28 #ifndef __APDS9300_H__
29 #define __APDS9300_H__
30 
31 #include "bcm2835.h"
32 #include <stdlib.h>
33 
37 #define APDS9300ADDR 0x29
38 
39 /******************Register definitions************************/
40 #define CONTROL 0x00
41 #define TIMING 0x01
42 #define THRESHLOWLOW 0x02
43 #define THRESHLOWHIGH 0x03
44 #define THRESHHIGHLOW 0x04
45 #define THRESHHIGHHIGH 0x05
46 #define INTERRUPT 0x06
47 #define CRC 0x08
48 #define ID 0x0A
49 #define DATA0LOW 0x0C
50 #define DATA0HIGH 0x0D
51 #define DATA1LOW 0x0E
52 #define DATA1HIGH 0x0F
53 
54 /**************************************************************/
55 
56 /***********************COMMAND REG*****************************/
57 #define COMMAND 0x80
58 #define CMD_CLEAR_INT 0x40
59 #define CMD_WORD 0x20
60 
61 
62 /**********************CONTROL REG******************************/
63 #define POWERON 0x03
64 #define POWEROFF 0x00
65 
66 /*********************Timing Reg********************************/
67 #define GAIN 0x10
68 #define MANUAL 0x08
69 
70 #define INTEG13_7MS 0x00
71 #define INTEG101MS 0x01
72 #define INTEG402MS 0x02
73 #define MANUAL_INTEG 0x03
74 
75 /*********************INTERRUPT REG*****************************/
76 
77 #define INTERR_DISMASK 0xCF //INTR bits zero
78 #define INTERR_ENA 0x10 //Level interrupts
79 
80 #define EVERYCYCLE 0x00
81 #define OUTSIDE_THRESH 0x01
82 #define PER2_OUT_RANGE 0x02
83 #define PER4_OUT_RANGE 0x04
84 #define PER10_OUT_RANGE 0x0A
85 #define PER15_OUT_RANGE 0x0F
86 
87 /***************************************************************/
88 
90 typedef enum{CH0,
92 
94 typedef enum{GAIN_1=0,
96 
98 typedef enum{POWER_ON=0x03,
100 
101 typedef enum{
105  }sampTime_t;
106 
107 
108 unsigned char AL_Initialize(void);
109 void AL_PowerState(powerState state);
110 unsigned char AL_ChipID(void);
111 
112 unsigned int AL_ReadChannel(channel chan);
113 float AL_Lux(unsigned int ch0, unsigned int ch1);
114 
115 unsigned char AL_SetGain(gain val);
116 void AL_SetSamplingTime(sampTime_t sampling_time);
117 void AL_SetIntLowThreshold(unsigned int lowthreshvalue);
118 void AL_SetIntHighThreshold(unsigned int highthreshvalue);
119 void AL_Clear_Interrupt(void);
120 void AL_ConfigureInterrupt(unsigned char enable, unsigned char persistence);
121 
122 void APDS9300_WriteRegister(unsigned char reg,unsigned char data);
123 void APDS9300_WriteByte(unsigned char data);
124 void APDS9300_WriteWord(unsigned char reg, unsigned int data);
125 char APDS9300_ReadByte(char reg);
126 unsigned int APDS9300_ReadWordReg(char reg);
127 unsigned int APDS9300_ReadWord(void);
128 
129 #endif
void AL_SetSamplingTime(sampTime_t sampling_time)
Sets the sampling time for the sensor,can be one of three predetermined values.
Definition: APDS9300.c:153
void APDS9300_WriteByte(unsigned char data)
Writes a single byte of data to the current sensor register. Function assumes that I2C peripheral is ...
Definition: APDS9300.c:219
void AL_SetIntHighThreshold(unsigned int highthreshvalue)
Sets the high threshold value for the interrupt.
Definition: APDS9300.c:174
unsigned int APDS9300_ReadWordReg(char reg)
Read word from register.
Definition: APDS9300.c:264
char APDS9300_ReadByte(char reg)
Reads a single byte from the given sensor register.
Definition: APDS9300.c:254
unsigned int APDS9300_ReadWord(void)
Read a single word from the sensor. Assumes register pointer is preset.
Definition: APDS9300.c:273
unsigned char AL_ChipID(void)
Returns the CHIP id.
Definition: APDS9300.c:65
Definition: APDS9300.h:90
void APDS9300_WriteWord(unsigned char reg, unsigned int data)
Writes a word to the specific register.
Definition: APDS9300.c:241
unsigned char AL_Initialize(void)
Powers on the sensor , sets sensor gain to 1x and clears any existing interrupts. ...
Definition: APDS9300.c:42
void AL_SetIntLowThreshold(unsigned int lowthreshvalue)
Sets the low threshold value for the interrupt.
Definition: APDS9300.c:164
unsigned char AL_SetGain(gain val)
Set sensor gain. Default gain value is GAIN_1 or 1x.
Definition: APDS9300.c:126
#define INTEG13_7MS
Definition: APDS9300.h:70
void AL_PowerState(powerState state)
Set the sensor power state to either POWER_ON or POWER_OFF.
Definition: APDS9300.c:54
Definition: APDS9300.h:102
void AL_ConfigureInterrupt(unsigned char enable, unsigned char persistence)
Enables or disables the interrupt and sets the persistence of interrupt occurences The interrupt will...
Definition: APDS9300.c:196
Definition: APDS9300.h:91
Definition: APDS9300.h:104
channel
Definition: APDS9300.h:90
void AL_Clear_Interrupt(void)
Clear any existing interrupts.
Definition: APDS9300.c:183
#define INTEG402MS
Definition: APDS9300.h:72
void APDS9300_WriteRegister(unsigned char reg, unsigned char data)
Writes a byte to the specific register.
Definition: APDS9300.c:230
gain
Definition: APDS9300.h:94
unsigned int AL_ReadChannel(channel chan)
Reads the value from one of the two photodiode channels.
Definition: APDS9300.c:77
Definition: APDS9300.h:103
#define INTEG101MS
Definition: APDS9300.h:71
float AL_Lux(unsigned int ch0, unsigned int ch1)
Computes LUX ambient light value from sensor data.
Definition: APDS9300.c:103
sampTime_t
Definition: APDS9300.h:101
powerState
Definition: APDS9300.h:98