Contiki-NG
Loading...
Searching...
No Matches
tsl256x.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-tsl256x-sensor TSL256X Sensor
38 *
39 * Driver for the TSL256X sensor
40 *
41 * The TSL256X driver returns the converted light value value in lux
42 * @{
43 *
44 * \file
45 * Header file for the external TSL256X Sensor Driver
46 *
47 * \author
48 * Antonio Lignan <alinan@zolertia.com>
49 * Toni Lozano <tlozano@zolertia.com>
50 */
51/*---------------------------------------------------------------------------*/
52#ifndef TSL256X_H_
53#define TSL256X_H_
54#include <stdio.h>
55#include "lib/sensors.h"
56#include "dev/zoul-sensors.h"
57#include "i2c.h"
58/* -------------------------------------------------------------------------- */
59/**
60 * \name TSL256x digital Light sensor specific model information
61 * @{
62 */
63/* This driver supports the TSL2563 (Zolertia) and the TSL2561 (Grove) */
64#define TSL2561_SENSOR_REF 0
65#define TSL2563_SENSOR_REF 1
66
67/* The TSL2563 (from Zolertia) has a different part number than the TSL2561 from
68 * Grove (digital light sensor)
69 */
70#define TSL2563_EXPECTED_PARTNO 0x30
71#define TSL2561_EXPECTED_PARTNO 0x50
72
73#ifndef TSL256X_CONF_REF
74#define TSL256X_REF TSL2561_SENSOR_REF
75#else
76#define TSL256X_REF TSL256X_CONF_REF
77#endif
78
79#if TSL256X_CONF_REF == TSL2561_SENSOR
80#define TSL256X_ADDR 0x29
81#define TSL256X_EXPECTED_PARTNO TSL2561_EXPECTED_PARTNO
82#else
83#define TSL256X_ADDR 0x39
84#define TSL256X_EXPECTED_PARTNO TSL2563_EXPECTED_PARTNO
85#endif
86
87/** @} */
88/* -------------------------------------------------------------------------- */
89/**
90 * \name TSL256X digital Light registers
91 * @{
92 */
93/* -------------------------------------------------------------------------- */
94#define TSL256X_CONTROL 0x00
95#define TSL256X_TIMMING 0x01
96#define TSL256X_THRLOWLOW 0x02
97#define TSL256X_THRLOWHIGH 0x03
98#define TSL256X_THRHIGHLOW 0x04
99#define TSL256X_THRHIGHHIGH 0x05
100#define TSL256X_INTERRUPT 0x06
101#define TSL256X_CRC 0x08
102#define TSL256X_ID_REG 0x0A
103#define TSL256X_D0LOW 0x0C
104#define TSL256X_D0HIGH 0x0D
105#define TSL256X_D1LOW 0x0E
106#define TSL256X_D1HIGH 0x0F
107/* -------------------------------------------------------------------------- */
108/* Uses the word read/write operation protocol */
109#define TSL256X_COMMAND 0xA0
110#define TSL256X_CLEAR_INTERRUPT 0x40
111/* -------------------------------------------------------------------------- */
112#define TSL256X_CONTROL_POWER_ON 0x03
113#define TSL256X_CONTROL_POWER_OFF 0x00
114#define TSL256X_TIMMING_GAIN 0x10
115#define TSL256X_TIMMING_MANUAL 0x08
116#define TSL256X_TIMMING_INTEG_MANUAL 0x03
117#define TSL256X_TIMMING_INTEG_402MS 0x02
118#define TSL256X_TIMMING_INTEG_101MS 0x01
119#define TSL256X_TIMMING_INTEG_13_7MS 0x00
120#define TSL256X_TIMMING_INTEG_MASK 0x03
121
122#define TSL256X_G16X_402MS (TSL256X_TIMMING_INTEG_402MS + TSL256X_TIMMING_GAIN)
123#define TSL256X_G1X_402MS TSL256X_TIMMING_INTEG_402MS
124#define TSL256X_G1X_101MS TSL256X_TIMMING_INTEG_101MS
125#define TSL256X_G1X_13_7MS TSL256X_TIMMING_INTEG_13_7MS
126
127#define TSL256X_INTR_SHIFT 0x04
128#define TSL256X_INTR_DISABLED 0x00
129#define TSL256X_INTR_LEVEL 0x01
130#define TSL256X_INTR_SMB_ALERT 0x02
131#define TSL256X_INTR_TEST 0x03
132
133#define TSL256X_INT_PERSIST_EVERY 0x00
134#define TSL256X_INT_PERSIST_ANY 0x01
135#define TSL256X_INT_PERSIST_2_CYCLES 0x02
136#define TSL256X_INT_PERSIST_3_CYCLES 0x03
137#define TSL256X_INT_PERSIST_4_CYCLES 0x04
138#define TSL256X_INT_PERSIST_5_CYCLES 0x05
139#define TSL256X_INT_PERSIST_6_CYCLES 0x06
140#define TSL256X_INT_PERSIST_7_CYCLES 0x07
141#define TSL256X_INT_PERSIST_8_CYCLES 0x08
142#define TSL256X_INT_PERSIST_9_CYCLES 0x09
143#define TSL256X_INT_PERSIST_10_CYCLES 0x0A
144#define TSL256X_INT_PERSIST_11_CYCLES 0x0B
145#define TSL256X_INT_PERSIST_12_CYCLES 0x0C
146#define TSL256X_INT_PERSIST_13_CYCLES 0x0D
147#define TSL256X_INT_PERSIST_14_CYCLES 0x0E
148#define TSL256X_INT_PERSIST_15_CYCLES 0x0F
149
150#define TSL256X_ID_PARTNO_MASK 0xF0
151#define TSL256X_ID_REV_MASK 0x0F
152/** @} */
153/* -------------------------------------------------------------------------- */
154/**
155 * \name TSL256X convertion and calibration values
156 * @{
157 */
158
159#define LUX_SCALE 14 /**< scale by 2^14 */
160#define RATIO_SCALE 9 /**< scale ratio */
161#define CH_SCALE 10 /**< scale channel values by 2^10 */
162#define CHSCALE_TINT0 0x7517 /**< 322/11 * 2^CH_SCALE */
163#define CHSCALE_TINT1 0x0fe7 /**< 322/81 * 2^CH_SCALE */
164
165/* T/FN/CL package coefficients (hardcoded) */
166#define K1T 0X0040
167#define B1T 0x01f2
168#define M1T 0x01b2
169#define K2T 0x0080
170#define B2T 0x0214
171#define M2T 0x02d1
172#define K3T 0x00c0
173#define B3T 0x023f
174#define M3T 0x037b
175#define K4T 0x0100
176#define B4T 0x0270
177#define M4T 0x03fe
178#define K5T 0x0138
179#define B5T 0x016f
180#define M5T 0x01fc
181#define K6T 0x019a
182#define B6T 0x00d2
183#define M6T 0x00fb
184#define K7T 0x029a
185#define B7T 0x0018
186#define M7T 0x0012
187#define K8T 0x029a
188#define B8T 0x0000
189#define M8T 0x0000
190/** @} */
191/* -------------------------------------------------------------------------- */
192/**
193 * \name Callback function to handle the TSL256X alarm interrupt and macro
194 * @{
195 */
196#define TSL256X_REGISTER_INT(ptr) tsl256x_int_callback = ptr;
197extern void (*tsl256x_int_callback)(uint8_t value);
198/** @} */
199/* -------------------------------------------------------------------------- */
200/**
201 * \name TSL256X return and command values
202 * @{
203 */
204#define TSL256X_SUCCESS 0x00
205#define TSL256X_LIGHT 0x01
206#define TSL256X_ERROR -1
207
208#define TSL256X_ACTIVE SENSORS_ACTIVE
209#define TSL256X_INT_OVER HW_INT_OVER_THRS
210#define TSL256X_INT_BELOW HW_INT_BELOW_THRS
211#define TSL256X_INT_DISABLE HW_INT_DISABLE
212#define TSL256X_TIMMING_CFG (HW_INT_DISABLE + 1)
213
214#define TSL256X_VAL_READ 0x01
215/** @} */
216/* -------------------------------------------------------------------------- */
217#define TSL256X_SENSOR "TSL256X Light Sensor"
218/* -------------------------------------------------------------------------- */
219extern const struct sensors_sensor tsl256x;
220/* -------------------------------------------------------------------------- */
221#endif
222/* -------------------------------------------------------------------------- */
223/**
224 * @}
225 * @}
226 */
227
Header file with declarations for the I2C Control module.
Implementation of a generic module controlling Zoul sensors.