Pinconfig für Endbadge.
[hackover2013-badge-firmware.git] / drivers / sensors / tcs3414 / tcs3414.h
1 /**************************************************************************/
2 /*!
3 @file tcs3414.h
4 @author K. Townsend (microBuilder.eu)
5
6 @section LICENSE
7
8 Software License Agreement (BSD License)
9
10 Copyright (c) 2010, microBuilder SARL
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 3. Neither the name of the copyright holders nor the
21 names of its contributors may be used to endorse or promote products
22 derived from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 /**************************************************************************/
36
37 #ifndef _TCS3414_H_
38 #define _TCS3414_H_
39
40 #include "projectconfig.h"
41 #include "core/i2c/i2c.h"
42
43 #define TCS3414_ADDRESS (0x72) // 0111001 shifted left 1 bit = 0x72 (ADDR = GND or floating)
44 #define TCS3414_READBIT (0x01)
45
46 #define TCS3414_COMMAND_BIT (0x80) // Must be 1
47 #define TCS3414_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
48
49 #define TCS3414_REGISTER_CONTROL (0x00)
50 #define TCS3414_REGISTER_TIMING (0x01)
51 #define TCS3414_REGISTER_INTERRUPT (0x02)
52 #define TCS3414_REGISTER_INTSOURCE (0x03)
53 #define TCS3414_REGISTER_PARTNO_REVID (0x04)
54 #define TCS3414_REGISTER_GAIN (0x07)
55 #define TCS3414_REGISTER_LOWTHRESHOLD_LOWBYTE (0x08)
56 #define TCS3414_REGISTER_LOWTHRESHOLD_HIGHBYTE (0x09)
57 #define TCS3414_REGISTER_HIGHTHRESHOLD_LOWBYTE (0x0A)
58 #define TCS3414_REGISTER_HIGHTHRESHOLD_HIGHBYTE (0x0B)
59 #define TCS3414_REGISTER_GREENLOW (0x10)
60 #define TCS3414_REGISTER_GREENHIGH (0x11)
61 #define TCS3414_REGISTER_REDLOW (0x12)
62 #define TCS3414_REGISTER_REDHIGH (0x13)
63 #define TCS3414_REGISTER_BLUELOW (0x14)
64 #define TCS3414_REGISTER_BLUEHIGH (0x15)
65 #define TCS3414_REGISTER_CLEARLOW (0x16)
66 #define TCS3414_REGISTER_CLEARHIGH (0x17)
67
68 #define TCS3414_CONTROL_POWERON (0x03)
69 #define TCS3414_CONTROL_POWEROFF (0x00)
70
71 #define TCS3414_GAIN_GAINMASK (0x30)
72 #define TCS3414_GAIN_PRESCALARMASK (0x07)
73
74 /**************************************************************************/
75 /*!
76 The Gain setting (bit [5:4] in the GAIN register) multiplies the output
77 by the specified amount, allowing you to adjust it's sensitivity and
78 dynamic range.
79 */
80 /**************************************************************************/
81 typedef enum
82 {
83 tcs3414Gain_1 = 0x00,
84 tcs3414Gain_4 = 0x10,
85 tcs3414Gain_16 = 0x20,
86 tcs3414Gain_64 = 0x30
87 }
88 tcs3414Gain_t;
89
90 /**************************************************************************/
91 /*!
92 The Prescalar (bits [2:0] in the GAIN register) divides down the
93 output by the specified amount, allowing you to adjust it's
94 sensitivity and dynamic range.
95 */
96 /**************************************************************************/
97 typedef enum
98 {
99 tcs3414Prescalar_1 = 0x00,
100 tcs3414Prescalar_2 = 0x01,
101 tcs3414Prescalar_4 = 0x02,
102 tcs3414Prescalar_8 = 0x03,
103 tcs3414Prescalar_16 = 0x04,
104 tcs3414Prescalar_32 = 0x05,
105 tcs3414Prescalar_64 = 0x06
106 }
107 tcs3414Prescalar_t;
108
109 /**************************************************************************/
110 /*!
111 Possible I2C error messages
112 */
113 /**************************************************************************/
114 typedef enum
115 {
116 TCS3414_ERROR_OK = 0, // Everything executed normally
117 TCS3414_ERROR_I2CINIT, // Unable to initialise I2C
118 TCS3414_ERROR_I2CBUSY, // I2C already in use
119 TCS3414_ERROR_LAST
120 }
121 tcs3414Error_e;
122
123 tcs3414Error_e tcs3414Init(void);
124 tcs3414Error_e tcs3414SetSensitivity(tcs3414Gain_t gain, tcs3414Prescalar_t prescalar);
125 tcs3414Error_e tcs3414GetRGBL (uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *clear);
126 uint32_t tcs3414CalculateCCT (uint16_t red, uint16_t green, uint16_t blue);
127
128 #endif
129
130
This page took 0.052029 seconds and 5 git commands to generate.