Contiki 3.x
tsl2563.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Zolertia - http://www.zolertia.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 /*---------------------------------------------------------------------------*/
33 /**
34  * \addtogroup zoul-sensors
35  * @{
36  *
37  * \defgroup zoul-tsl2563-sensor TSL2563 Sensor
38  *
39  * Driver for the TSL2563 sensor
40  *
41  * The TSL2563 driver returns the converted light value value in lux
42  * @{
43  *
44  * \file
45  * Header file for the external TSL2563 Sensor Driver
46  *
47  * \author
48  * Antonio Lignan <alinan@zolertia.com>
49  * Toni Lozano <tlozano@zolertia.com>
50  */
51 /*---------------------------------------------------------------------------*/
52 #ifndef TSL2563_H_
53 #define TSL2563_H_
54 #include <stdio.h>
55 #include "lib/sensors.h"
56 #include "dev/zoul-sensors.h"
57 #include "i2c.h"
58 /* -------------------------------------------------------------------------- */
59 /**
60  * \name TSL2563 digital Light sensor address and registers
61  * @{
62  */
63 /* -------------------------------------------------------------------------- */
64 #define TSL2563_ADDR 0x39
65 /* -------------------------------------------------------------------------- */
66 #define TSL2563_CONTROL 0x00
67 #define TSL2563_TIMMING 0x01
68 #define TSL2563_THRLOWLOW 0x02
69 #define TSL2563_THRLOWHIGH 0x03
70 #define TSL2563_THRHIGHLOW 0x04
71 #define TSL2563_THRHIGHHIGH 0x05
72 #define TSL2563_INTERRUPT 0x06
73 #define TSL2563_CRC 0x08
74 #define TSL2563_ID_REG 0x0A
75 #define TSL2563_D0LOW 0x0C
76 #define TSL2563_D0HIGH 0x0D
77 #define TSL2563_D1LOW 0x0E
78 #define TSL2563_D1HIGH 0x0F
79 /* -------------------------------------------------------------------------- */
80 /* Uses the word read/write operation protocol */
81 #define TSL2563_COMMAND 0xA0
82 #define TSL2563_CLEAR_INTERRUPT 0x40
83 /* -------------------------------------------------------------------------- */
84 #define TSL2563_CONTROL_POWER_ON 0x03
85 #define TSL2563_CONTROL_POWER_OFF 0x00
86 #define TSL2563_TIMMING_GAIN 0x10
87 #define TSL2563_TIMMING_MANUAL 0x08
88 #define TSL2563_TIMMING_INTEG_MANUAL 0x03
89 #define TSL2563_TIMMING_INTEG_402MS 0x02
90 #define TSL2563_TIMMING_INTEG_101MS 0x01
91 #define TSL2563_TIMMING_INTEG_13_7MS 0x00
92 #define TSL2563_TIMMING_INTEG_MASK 0x03
93 
94 #define TSL2563_G16X_402MS (TSL2563_TIMMING_INTEG_402MS + TSL2563_TIMMING_GAIN)
95 #define TSL2563_G1X_402MS TSL2563_TIMMING_INTEG_402MS
96 #define TSL2563_G1X_101MS TSL2563_TIMMING_INTEG_101MS
97 #define TSL2563_G1X_13_7MS TSL2563_TIMMING_INTEG_13_7MS
98 
99 #define TSL2563_INTR_SHIFT 0x04
100 #define TSL2563_INTR_DISABLED 0x00
101 #define TSL2563_INTR_LEVEL 0x01
102 #define TSL2563_INTR_SMB_ALERT 0x02
103 #define TSL2563_INTR_TEST 0x03
104 
105 #define TSL2563_INT_PERSIST_EVERY 0x00
106 #define TSL2563_INT_PERSIST_ANY 0x01
107 #define TSL2563_INT_PERSIST_2_CYCLES 0x02
108 #define TSL2563_INT_PERSIST_3_CYCLES 0x03
109 #define TSL2563_INT_PERSIST_4_CYCLES 0x04
110 #define TSL2563_INT_PERSIST_5_CYCLES 0x05
111 #define TSL2563_INT_PERSIST_6_CYCLES 0x06
112 #define TSL2563_INT_PERSIST_7_CYCLES 0x07
113 #define TSL2563_INT_PERSIST_8_CYCLES 0x08
114 #define TSL2563_INT_PERSIST_9_CYCLES 0x09
115 #define TSL2563_INT_PERSIST_10_CYCLES 0x0A
116 #define TSL2563_INT_PERSIST_11_CYCLES 0x0B
117 #define TSL2563_INT_PERSIST_12_CYCLES 0x0C
118 #define TSL2563_INT_PERSIST_13_CYCLES 0x0D
119 #define TSL2563_INT_PERSIST_14_CYCLES 0x0E
120 #define TSL2563_INT_PERSIST_15_CYCLES 0x0F
121 
122 #define TSL2563_ID_PARTNO_MASK 0xF0
123 #define TSL2563_ID_REV_MASK 0x0F
124 #define TSL2563_EXPECTED_PARTNO 0x30
125 /** @} */
126 /* -------------------------------------------------------------------------- */
127 /**
128  * \name TSL2563 convertion and calibration values
129  * @{
130  */
131 
132 #define LUX_SCALE 14 /**< scale by 2^14 */
133 #define RATIO_SCALE 9 /**< scale ratio */
134 #define CH_SCALE 10 /**< scale channel values by 2^10 */
135 #define CHSCALE_TINT0 0x7517 /**< 322/11 * 2^CH_SCALE */
136 #define CHSCALE_TINT1 0x0fe7 /**< 322/81 * 2^CH_SCALE */
137 
138 /* T/FN/CL package coefficients (hardcoded) */
139 #define K1T 0X0040
140 #define B1T 0x01f2
141 #define M1T 0x01b2
142 #define K2T 0x0080
143 #define B2T 0x0214
144 #define M2T 0x02d1
145 #define K3T 0x00c0
146 #define B3T 0x023f
147 #define M3T 0x037b
148 #define K4T 0x0100
149 #define B4T 0x0270
150 #define M4T 0x03fe
151 #define K5T 0x0138
152 #define B5T 0x016f
153 #define M5T 0x01fc
154 #define K6T 0x019a
155 #define B6T 0x00d2
156 #define M6T 0x00fb
157 #define K7T 0x029a
158 #define B7T 0x0018
159 #define M7T 0x0012
160 #define K8T 0x029a
161 #define B8T 0x0000
162 #define M8T 0x0000
163 /** @} */
164 /* -------------------------------------------------------------------------- */
165 /**
166  * \name Callback function to handle the TSL2563 alarm interrupt and macro
167  * @{
168  */
169 #define TSL2563_REGISTER_INT(ptr) tsl2563_int_callback = ptr;
170 extern void (*tsl2563_int_callback)(uint8_t value);
171 /** @} */
172 /* -------------------------------------------------------------------------- */
173 /**
174  * \name TSL2563 return and command values
175  * @{
176  */
177 #define TSL2563_SUCCESS 0x00
178 #define TSL2563_LIGHT 0x01
179 #define TSL2563_ERROR -1
180 
181 #define TSL2563_ACTIVE SENSORS_ACTIVE
182 #define TSL2563_INT_OVER HW_INT_OVER_THRS
183 #define TSL2563_INT_BELOW HW_INT_BELOW_THRS
184 #define TSL2563_INT_DISABLE HW_INT_DISABLE
185 #define TSL2563_TIMMING_CFG (HW_INT_DISABLE + 1)
186 
187 #define TSL2563_VAL_READ 0x01
188 /** @} */
189 /* -------------------------------------------------------------------------- */
190 #define TSL2563_SENSOR "TSL2563 Light Sensor"
191 /* -------------------------------------------------------------------------- */
192 extern const struct sensors_sensor tsl2563;
193 /* -------------------------------------------------------------------------- */
194 #endif
195 /* -------------------------------------------------------------------------- */
196 /**
197  * @}
198  * @}
199  */
200 
Implementation of a generic module controlling Zoul sensors.