17
17
18
18
#include < stdint.h>
19
19
#include < modm/architecture/interface/i2c_device.hpp>
20
- #include < modm/math/utils/endianness .hpp>
20
+ #include < modm/math/utils.hpp>
21
21
#include < modm/ui/color.hpp>
22
22
23
23
namespace modm
@@ -30,28 +30,52 @@ class Tcs3472;
30
30
// / @ingroup modm_driver_tcs3472
31
31
struct tcs3472
32
32
{
33
- /* * Device Address depends on version TCS3472x
34
- *
35
- * - 1 = 0x39 (with IR filter)
36
- * - 3 = 0x39 (without IR filter)
37
- * - 5 = 0x29 (with IR filter)
38
- * - 7 = 0x29 (without IR filter)
39
- */
40
- static constexpr uint8_t
41
- addr (uint8_t version=5 )
42
- { return version < 5 ? 0x39 : 0x29 ; }
33
+ // / Register addresses
34
+ enum class
35
+ RegisterAddress : uint8_t
36
+ {
37
+ ENABLE = 0x00 , // /< Power up the device, Enable features
38
+ ID = 0x12 , // /< Read part-ID
39
+
40
+ // Shutter configuration
41
+ INTEGRATION_TIME = 0x01 , // /< Shutter integration time
42
+ GAIN = 0x0F , // /< Shutter gain control
43
+
44
+ // Waittime configuration
45
+ WAIT_TIME = 0x03 , // /< Waittime between samples. Conceived for power savings
46
+ CONFIGURATION = 0x0D , // /< Setting WAITLONG multiplies WAIT_TIME by 12
47
+
48
+ // Interrupt configuration
49
+ LOW_THRESH_LOW_BYTE = 0x04 , // /< Low byte of low interrupt threshold
50
+ LOW_THRESH_HIGH_BYTE = 0x05 , // /< High byte of low interrupt threshold
51
+ HIGH_THRESH_LOW_BYTE = 0x06 , // /< Low byte of high interrupt threshold
52
+ HIGH_THRESH_HIGH_BYTE = 0x07 , // /< High byte of high interrupt threshold
53
+ INTERRUPT_PERSIST_FILTER = 0x0C ,// /< Set how much threshold-passing cycles are required, to trigger the interrupt
54
+ RELOAD_INTERRUPT = 0x66 , // /< Reset Interrupt special command
55
+
56
+ // Data results
57
+ CDATALOW = 0x14 , // /< Low byte of ADC clear channel
58
+ CDATAHIGH = 0x15 , // /< High byte of ADC clear channel
59
+ RDATALOW = 0x16 , // /< Low byte of ADC red channel
60
+ RDATAHIGH = 0x17 , // /< High byte of ADC red channel
61
+ GDATALOW = 0x18 , // /< Low byte of ADC green channel
62
+ GDATAHIGH = 0x19 , // /< High byte of ADC green channel
63
+ BDATALOW = 0x1A , // /< Low byte of ADC blue channel
64
+ BDATAHIGH = 0x1B // /< High byte of ADC blue channel
65
+ };
43
66
67
+ public:
44
68
// / Analog rgbc gain control
45
69
enum class
46
70
Gain : uint8_t
47
71
{
48
- X1 = 0b00 , // /< x1 gain
49
- X4 = 0b01 , // /< x4 gain
50
- X16 = 0b10 , // /< x16 gain
51
- X60 = 0b11 , // /< x60 gain
72
+ X1 = 0 , // /< x1 gain
73
+ X4 = 1 , // /< x4 gain
74
+ X16 = 2 , // /< x16 gain
75
+ X60 = 3 , // /< x60 gain
52
76
};
53
77
54
- // / Integration for a fixed time
78
+ // / Light integration time in ms
55
79
enum class
56
80
IntegrationTime : uint8_t
57
81
{
@@ -62,6 +86,7 @@ struct tcs3472
62
86
MSEC_700 = 0x00 , // /< integrate over 700 ms
63
87
};
64
88
89
+ // / Time to wait between samples in ms
65
90
enum class
66
91
WaitTime : uint8_t
67
92
{
@@ -74,10 +99,10 @@ struct tcs3472
74
99
enum class
75
100
InterruptPersistence : uint8_t
76
101
{
77
- EVERY = 0 , // Interrupt for every new sample independent of thresholds
78
- CNT_1 = 1 , // Interrupt after 1 cycle being below or above thresholds
79
- CNT_2 = 2 , // Interrupt after 2 cycles being below or above thresholds
80
- CNT_3 = 3 , // ...
102
+ EVERY = 0 , // /< Interrupt for every new sample independent of thresholds
103
+ CNT_1 = 1 , // /< Interrupt after 1 cycle being below or above thresholds
104
+ CNT_2 = 2 , // /< Interrupt after 2 cycles being below or above thresholds
105
+ CNT_3 = 3 , // /< ...
81
106
CNT_5 = 4 ,
82
107
CNT_10 = 5 ,
83
108
CNT_15 = 6 ,
@@ -96,48 +121,23 @@ struct tcs3472
96
121
enum class
97
122
Enable : uint8_t
98
123
{
99
- POWER_ON = 1 ,
100
- ADC_ENABLE = 1 << 1 ,
101
- WAIT_ENABLE = 1 << 3 ,
102
- INTERRUPT_ENABLE = 1 << 4 ,
103
- POWER_ON_POLLING = POWER_ON | ADC_ENABLE,
104
- POWER_ON_INTERRUPT = POWER_ON | ADC_ENABLE | INTERRUPT_ENABLE,
105
- POWER_ON_INTERRUPT_AND_WAITTIME = POWER_ON | ADC_ENABLE | WAIT_ENABLE | INTERRUPT_ENABLE
124
+ POWER_ON = Bit0,
125
+ ADC_ENABLE = Bit1,
126
+ WAIT_ENABLE = Bit3,
127
+ INTERRUPT_ENABLE = Bit4
106
128
};
129
+ MODM_FLAGS8 (Enable);
107
130
108
- // / Register addresses
109
- enum class
110
- RegisterAddress : uint8_t
111
- {
112
- ENABLE = 0x00 , // /< Power up the device, Enable features
113
- ID = 0x12 , // /< Read part-ID
114
-
115
- // Shutter configuration
116
- INTEGRATION_TIME = 0x01 , // /< Shutter integration time
117
- GAIN = 0x0F , // /< Shutter gain control
118
-
119
- // Waittime configuration
120
- WAIT_TIME = 0x03 , // /< Waittime between samples. Conceived for power savings
121
- CONFIGURATION = 0x0D , // /< Setting WAITLONG multiplies WAIT_TIME by 12
122
-
123
- // Interrupt configuration
124
- LOW_THRESH_LOW_BYTE = 0x04 , // /< Low byte of low interrupt threshold
125
- LOW_THRESH_HIGH_BYTE = 0x05 , // /< High byte of low interrupt threshold
126
- HIGH_THRESH_LOW_BYTE = 0x06 , // /< Low byte of high interrupt threshold
127
- HIGH_THRESH_HIGH_BYTE = 0x07 , // /< High byte of high interrupt threshold
128
- INTERRUPT_PERSIST_FILTER = 0x0C ,// /< Set how much threshold-passing cycles are required, to trigger the interrupt
129
- RELOAD_INTERRUPT = 0x66 , // /< Reset Interrupt special command
130
-
131
- // Data results
132
- CDATALOW = 0x14 , // /< Low byte of ADC clear channel
133
- CDATAHIGH = 0x15 , // /< High byte of ADC clear channel
134
- RDATALOW = 0x16 , // /< Low byte of ADC red channel
135
- RDATAHIGH = 0x17 , // /< High byte of ADC red channel
136
- GDATALOW = 0x18 , // /< Low byte of ADC green channel
137
- GDATAHIGH = 0x19 , // /< High byte of ADC green channel
138
- BDATALOW = 0x1A , // /< Low byte of ADC blue channel
139
- BDATAHIGH = 0x1B // /< High byte of ADC blue channel
140
- };
131
+ /* * Device Address depends on version TCS3472x
132
+ *
133
+ * - 1 = 0x39 (with IR filter)
134
+ * - 3 = 0x39 (without IR filter)
135
+ * - 5 = 0x29 (with IR filter)
136
+ * - 7 = 0x29 (without IR filter)
137
+ */
138
+ static constexpr uint8_t
139
+ addr (uint8_t version=5 )
140
+ { return version < 5 ? 0x39 : 0x29 ; }
141
141
142
142
using Rgb = color::RgbT<uint16_t >;
143
143
@@ -205,10 +205,15 @@ class Tcs3472 : public tcs3472, public modm::I2cDevice<I2cMaster, 2>
205
205
public:
206
206
Tcs3472 (Data &data, uint8_t address = addr());
207
207
208
+ // Typical Runmodes
209
+ static constexpr Enable_t Enable_PollingMode = Enable::POWER_ON | Enable::ADC_ENABLE;
210
+ static constexpr Enable_t Enable_InterruptMode = Enable_PollingMode | Enable::INTERRUPT_ENABLE;
211
+ static constexpr Enable_t Enable_InterruptMode_Waittime = Enable_InterruptMode | Enable::INTERRUPT_ENABLE;
212
+
208
213
// / Power up sensor and start conversions
209
214
modm::ResumableResult<bool >
210
- initialize (Enable flags = Enable::POWER_ON_POLLING )
211
- { return writeRegister (RegisterAddress::ENABLE, uint8_t ( flags) ); }
215
+ initialize (Enable_t flags = Enable_PollingMode )
216
+ { return writeRegister (RegisterAddress::ENABLE, flags. value ); }
212
217
213
218
modm::ResumableResult<bool >
214
219
configure (Gain gain = Gain::X1,
0 commit comments