color6  2.0.0.0
color6.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef COLOR6_H
36 #define COLOR6_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define COLOR6_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
56 
62 #define COLOR6_RETVAL uint8_t
63 
64 #define COLOR6_OK 0x00
65 #define COLOR6_INIT_ERROR 0xFF
66 
72 #define COLOR6_REG_OPERATIONAL_STATE 0x00
73 #define COLOR6_REG_API_GENERATION 0x02
74 #define COLOR6_REG_CONFIGURATION_REGISTER_1 0x06
75 #define COLOR6_REG_CONFIGURATION_REGISTER_2 0x07
76 #define COLOR6_REG_CONFIGURATION_REGISTER_3 0x08
77 #define COLOR6_REG_BREAK_TIME 0x09
78 #define COLOR6_REG_EDGE_COUNT_VALUE 0x0A
79 #define COLOR6_REG_OPTIONS_REGISTER 0x0B
80 
86 #define COLOR6_OSR_STOP_MEASUREMENT 0x00
87 #define COLOR6_OSR_START_MEASUREMENT 0x80
88 #define COLOR6_OSR_POWER_DOWN_SWITCHED_OFF 0x00
89 #define COLOR6_OSR_POWER_DOWN_SWITCHED_ON 0x40
90 #define COLOR6_OSR_SOFTWARE_RESET 0x08
91 #define COLOR6_OSR_DOS_CONFIGURATION 0x02
92 #define COLOR6_OSR_DOS_MEASUREMENT 0x03
93 
99 #define COLOR6_AGEN_DEVICE_ID 0x01
100 #define COLOR6_AGEN_MUTATION_NUMBER 0x02
101 
107 #define COLOR6_CREG1_GAIN_XYZ_2048 0x00
108 #define COLOR6_CREG1_GAIN_XYZ_1024 0x10
109 #define COLOR6_CREG1_GAIN_XYZ_512 0x20
110 #define COLOR6_CREG1_GAIN_XYZ_256 0x30
111 #define COLOR6_CREG1_GAIN_XYZ_128 0x40
112 #define COLOR6_CREG1_GAIN_XYZ_64 0x50
113 #define COLOR6_CREG1_GAIN_XYZ_32 0x60
114 #define COLOR6_CREG1_GAIN_XYZ_16 0x70
115 #define COLOR6_CREG1_GAIN_XYZ_8 0x80
116 #define COLOR6_CREG1_GAIN_XYZ_4 0x90
117 #define COLOR6_CREG1_GAIN_XYZ_2 0xA0
118 #define COLOR6_CREG1_GAIN_XYZ_1 0xB0
119 
125 #define COLOR6_CREG1_TIME_1ms 0x00
126 #define COLOR6_CREG1_TIME_2ms 0x01
127 #define COLOR6_CREG1_TIME_4ms 0x02
128 #define COLOR6_CREG1_TIME_8ms 0x03
129 #define COLOR6_CREG1_TIME_16ms 0x04
130 #define COLOR6_CREG1_TIME_32ms 0x05
131 #define COLOR6_CREG1_TIME_64ms 0x06
132 #define COLOR6_CREG1_TIME_128ms 0x07
133 #define COLOR6_CREG1_TIME_256ms 0x08
134 #define COLOR6_CREG1_TIME_512ms 0x09
135 #define COLOR6_CREG1_TIME_1024ms 0x0A
136 #define COLOR6_CREG1_TIME_2048ms 0x0B
137 #define COLOR6_CREG1_TIME_4096ms 0x0C
138 #define COLOR6_CREG1_TIME_8192ms 0x0D
139 #define COLOR6_CREG1_TIME_16384ms 0x0E
140 
146 #define COLOR6_CREG2_EN_TM_DISABLE 0x00
147 #define COLOR6_CREG2_EN_TM_ENABLE 0x40
148 #define COLOR6_CREG2_DIGITAL_DIVIDER_DISABLE 0x00
149 #define COLOR6_CREG2_DIGITAL_DIVIDER_ENABLE 0x08
150 #define COLOR6_CREG2_DIVIDER_2 0x00
151 #define COLOR6_CREG2_DIVIDER_4 0x01
152 #define COLOR6_CREG2_DIVIDER_8 0x02
153 #define COLOR6_CREG2_DIVIDER_16 0x03
154 #define COLOR6_CREG2_DIVIDER_32 0x04
155 #define COLOR6_CREG2_DIVIDER_64 0x05
156 #define COLOR6_CREG2_DIVIDER_128 0x06
157 #define COLOR6_CREG2_DIVIDER_256 0x07
158 
164 #define COLOR6_CREG3_MMODE_CONT_MODE 0x00
165 #define COLOR6_CREG3_MMODE_CMD_MODE 0x40
166 #define COLOR6_CREG3_MMODE_SYNS_MODE 0x80
167 #define COLOR6_CREG3_MMODE_SIND_MODE 0xC0
168 #define COLOR6_CREG3_SB_STANDBY_SWITCHED_OFF 0x00
169 #define COLOR6_CREG3_SB_STANDBY_SWITCHED_ON 0x10
170 #define COLOR6_CREG3_READY_PUSH_PULL_OUT 0x00
171 #define COLOR6_CREG3_READY_OPEN_DRAIN_OUT 0x08
172 #define COLOR6_CREG3_INTERNAL_CLOCK_1024MHZ 0x00
173 #define COLOR6_CREG3_INTERNAL_CLOCK_2048MHZ 0x01
174 #define COLOR6_CREG3_INTERNAL_CLOCK_4096MHZ 0x02
175 #define COLOR6_CREG3_INTERNAL_CLOCK_8192MHZ 0x03
176 
182 #define COLOR6_MREG_STATUS_REGISTER 0x00
183 #define COLOR6_MREG_TEMPERATURE_MEASUREMENT 0x01
184 #define COLOR6_MREG_MEASUREMENT_X_CHANNEL 0x02
185 #define COLOR6_MREG_MEASUREMENT_Y_CHANNEL 0x03
186 #define COLOR6_MREG_MEASUREMENT_Z_CHANNEL 0x04
187 #define COLOR6_MREG_OUT_CONVERSION_LSB 0x05
188 #define COLOR6_MREG_OUT_CONVERSION_MSB 0x06
189 
195 #define COLOR6_STATUS_OUTCONVOF 0x80
196 #define COLOR6_STATUS_MRESOF 0x40
197 #define COLOR6_STATUS_ADCOF 0x20
198 #define COLOR6_STATUS_LDATA 0x10
199 #define COLOR6_STATUS_NDATA 0x08
200 #define COLOR6_STATUS_NOTREADY 0x04
201 #define COLOR6_STATUS_STANDBY 0x02
202 #define COLOR6_STATUS_POWER 0x01
203 
209 #define COLOR6_X_FSR_OF_GAIN_2048 0.866
210 #define COLOR6_Y_FSR_OF_GAIN_2048 0.932
211 #define COLOR6_Z_FSR_OF_GAIN_2048 0.501
212 #define COLOR6_X_FSR_OF_GAIN_1024 1.732
213 #define COLOR6_Y_FSR_OF_GAIN_1024 1.865
214 #define COLOR6_Z_FSR_OF_GAIN_1024 1.002
215 #define COLOR6_X_FSR_OF_GAIN_512 3.463
216 #define COLOR6_Y_FSR_OF_GAIN_512 3.730
217 #define COLOR6_Z_FSR_OF_GAIN_512 2.003
218 #define COLOR6_X_FSR_OF_GAIN_256 6.927
219 #define COLOR6_Y_FSR_OF_GAIN_256 7.460
220 #define COLOR6_Z_FSR_OF_GAIN_256 4.006
221 #define COLOR6_X_FSR_OF_GAIN_128 13.854
222 #define COLOR6_Y_FSR_OF_GAIN_128 14.919
223 #define COLOR6_Z_FSR_OF_GAIN_128 8.012
224 #define COLOR6_X_FSR_OF_GAIN_64 27.707
225 #define COLOR6_Y_FSR_OF_GAIN_64 29.838
226 #define COLOR6_Z_FSR_OF_GAIN_64 16.024
227 #define COLOR6_X_FSR_OF_GAIN_32 55.414
228 #define COLOR6_Y_FSR_OF_GAIN_32 59.677
229 #define COLOR6_Z_FSR_OF_GAIN_32 32.048
230 #define COLOR6_X_FSR_OF_GAIN_16 110.828
231 #define COLOR6_Y_FSR_OF_GAIN_16 119.354
232 #define COLOR6_Z_FSR_OF_GAIN_16 64.097
233 #define COLOR6_X_FSR_OF_GAIN_8 221.657
234 #define COLOR6_Y_FSR_OF_GAIN_8 238.707
235 #define COLOR6_Z_FSR_OF_GAIN_8 128.194
236 #define COLOR6_X_FSR_OF_GAIN_4 443.314
237 #define COLOR6_Y_FSR_OF_GAIN_4 477.415
238 #define COLOR6_Z_FSR_OF_GAIN_4 256.387
239 #define COLOR6_X_FSR_OF_GAIN_2 886.628
240 #define COLOR6_Y_FSR_OF_GAIN_2 954.830
241 #define COLOR6_Z_FSR_OF_GAIN_2 512.774
242 #define COLOR6_X_FSR_OF_GAIN_1 1773.255
243 #define COLOR6_Y_FSR_OF_GAIN_1 1909.659
244 #define COLOR6_Z_FSR_OF_GAIN_1 1025.548
245 
251 #define COLOR6_NUMBER_OF_CLK_TIME_1ms 1024
252 #define COLOR6_NUMBER_OF_CLK_TIME_2ms 2048
253 #define COLOR6_NUMBER_OF_CLK_TIME_4ms 4096
254 #define COLOR6_NUMBER_OF_CLK_TIME_8ms 8192
255 #define COLOR6_NUMBER_OF_CLK_TIME_16ms 16384
256 #define COLOR6_NUMBER_OF_CLK_TIME_32ms 32768
257 #define COLOR6_NUMBER_OF_CLK_TIME_64ms 65536
258 #define COLOR6_NUMBER_OF_CLK_TIME_128ms 131072
259 #define COLOR6_NUMBER_OF_CLK_TIME_256ms 262144
260 #define COLOR6_NUMBER_OF_CLK_TIME_512ms 524288
261 #define COLOR6_NUMBER_OF_CLK_TIME_1024ms 1048576
262 #define COLOR6_NUMBER_OF_CLK_TIME_2048ms 2097152
263 #define COLOR6_NUMBER_OF_CLK_TIME_4096ms 4194304
264 #define COLOR6_NUMBER_OF_CLK_TIME_8192ms 8388608
265 #define COLOR6_NUMBER_OF_CLK_TIME_16384ms 16777216
266  // End group macro
270 // --------------------------------------------------------------- PUBLIC TYPES
279 typedef struct
280 {
281  // Modules
282 
283  i2c_master_t i2c;
284 
285  // ctx variable
286 
287  uint8_t slave_address;
288 
289  uint8_t set_gain;
290  uint8_t set_time;
291  float fsr;
292  uint32_t num_of_clk;
293 
294 
295 } color6_t;
296 
300 typedef struct
301 {
302  // Communication gpio pins
303 
304  pin_name_t scl;
305  pin_name_t sda;
306 
307  // static variable
308 
309  uint32_t i2c_speed;
310  uint8_t i2c_address;
311 
312 } color6_cfg_t;
313  // End types group
315 
316 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
317 
323 #ifdef __cplusplus
324 extern "C"{
325 #endif
326 
335 void color6_cfg_setup ( color6_cfg_t *cfg );
336 
345 
353 void color6_default_cfg ( color6_t *ctx );
354 
365 void color6_generic_write ( color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
366 
377 void color6_generic_read ( color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
378 
388 void color6_write_byte ( color6_t *ctx, uint8_t reg, uint8_t r_data );
389 
398 uint8_t color6_read_byte ( color6_t *ctx, uint8_t reg );
399 
408 uint16_t color6_read_data ( color6_t *ctx, uint8_t reg );
409 
417 float color6_get_temperature ( color6_t *ctx );
418 
426 void color6_software_reset ( color6_t *ctx );
427 
436 
446 float color6_converting_to_ee ( color6_t *ctx, uint8_t channel, uint16_t mres_data );
447 #ifdef __cplusplus
448 }
449 #endif
450 #endif // _COLOR6_H_
451  // End public_function group
454 
455 // ------------------------------------------------------------------------- END
COLOR6_RETVAL
#define COLOR6_RETVAL
Definition: color6.h:62
color6_cfg_t
Click configuration structure definition.
Definition: color6.h:300
color6_t::fsr
float fsr
Definition: color6.h:291
color6_t::set_time
uint8_t set_time
Definition: color6.h:290
color6_cfg_setup
void color6_cfg_setup(color6_cfg_t *cfg)
Config Object Initialization function.
color6_read_data
uint16_t color6_read_data(color6_t *ctx, uint8_t reg)
Functions for read data from register.
color6_go_to_measurement_mode
void color6_go_to_measurement_mode(color6_t *ctx)
Functions for go to measurement mode.
color6_converting_to_ee
float color6_converting_to_ee(color6_t *ctx, uint8_t channel, uint16_t mres_data)
Functions for go to measurement mode.
color6_cfg_t::sda
pin_name_t sda
Definition: color6.h:305
color6_default_cfg
void color6_default_cfg(color6_t *ctx)
Click Default Configuration function.
color6_generic_read
void color6_generic_read(color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
color6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color6.h:309
color6_get_temperature
float color6_get_temperature(color6_t *ctx)
Functions for read temperature.
color6_cfg_t::scl
pin_name_t scl
Definition: color6.h:304
color6_write_byte
void color6_write_byte(color6_t *ctx, uint8_t reg, uint8_t r_data)
Functions for write one byte in register.
color6_cfg_t::i2c_address
uint8_t i2c_address
Definition: color6.h:310
color6_t
Click ctx object definition.
Definition: color6.h:279
color6_software_reset
void color6_software_reset(color6_t *ctx)
Functions for software reset.
color6_t::set_gain
uint8_t set_gain
Definition: color6.h:289
color6_t::i2c
i2c_master_t i2c
Definition: color6.h:283
color6_t::num_of_clk
uint32_t num_of_clk
Definition: color6.h:292
color6_generic_write
void color6_generic_write(color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
color6_t::slave_address
uint8_t slave_address
Definition: color6.h:287
color6_read_byte
uint8_t color6_read_byte(color6_t *ctx, uint8_t reg)
Functions for read one byte data from register.
color6_init
COLOR6_RETVAL color6_init(color6_t *ctx, color6_cfg_t *cfg)
Initialization function.