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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define COLOR6_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
66 
72 #define COLOR6_RETVAL uint8_t
73 
74 #define COLOR6_OK 0x00
75 #define COLOR6_INIT_ERROR 0xFF
76 
82 #define COLOR6_REG_OPERATIONAL_STATE 0x00
83 #define COLOR6_REG_API_GENERATION 0x02
84 #define COLOR6_REG_CONFIGURATION_REGISTER_1 0x06
85 #define COLOR6_REG_CONFIGURATION_REGISTER_2 0x07
86 #define COLOR6_REG_CONFIGURATION_REGISTER_3 0x08
87 #define COLOR6_REG_BREAK_TIME 0x09
88 #define COLOR6_REG_EDGE_COUNT_VALUE 0x0A
89 #define COLOR6_REG_OPTIONS_REGISTER 0x0B
90 
96 #define COLOR6_OSR_STOP_MEASUREMENT 0x00
97 #define COLOR6_OSR_START_MEASUREMENT 0x80
98 #define COLOR6_OSR_POWER_DOWN_SWITCHED_OFF 0x00
99 #define COLOR6_OSR_POWER_DOWN_SWITCHED_ON 0x40
100 #define COLOR6_OSR_SOFTWARE_RESET 0x08
101 #define COLOR6_OSR_DOS_CONFIGURATION 0x02
102 #define COLOR6_OSR_DOS_MEASUREMENT 0x03
103 
109 #define COLOR6_AGEN_DEVICE_ID 0x01
110 #define COLOR6_AGEN_MUTATION_NUMBER 0x02
111 
117 #define COLOR6_CREG1_GAIN_XYZ_2048 0x00
118 #define COLOR6_CREG1_GAIN_XYZ_1024 0x10
119 #define COLOR6_CREG1_GAIN_XYZ_512 0x20
120 #define COLOR6_CREG1_GAIN_XYZ_256 0x30
121 #define COLOR6_CREG1_GAIN_XYZ_128 0x40
122 #define COLOR6_CREG1_GAIN_XYZ_64 0x50
123 #define COLOR6_CREG1_GAIN_XYZ_32 0x60
124 #define COLOR6_CREG1_GAIN_XYZ_16 0x70
125 #define COLOR6_CREG1_GAIN_XYZ_8 0x80
126 #define COLOR6_CREG1_GAIN_XYZ_4 0x90
127 #define COLOR6_CREG1_GAIN_XYZ_2 0xA0
128 #define COLOR6_CREG1_GAIN_XYZ_1 0xB0
129 
135 #define COLOR6_CREG1_TIME_1ms 0x00
136 #define COLOR6_CREG1_TIME_2ms 0x01
137 #define COLOR6_CREG1_TIME_4ms 0x02
138 #define COLOR6_CREG1_TIME_8ms 0x03
139 #define COLOR6_CREG1_TIME_16ms 0x04
140 #define COLOR6_CREG1_TIME_32ms 0x05
141 #define COLOR6_CREG1_TIME_64ms 0x06
142 #define COLOR6_CREG1_TIME_128ms 0x07
143 #define COLOR6_CREG1_TIME_256ms 0x08
144 #define COLOR6_CREG1_TIME_512ms 0x09
145 #define COLOR6_CREG1_TIME_1024ms 0x0A
146 #define COLOR6_CREG1_TIME_2048ms 0x0B
147 #define COLOR6_CREG1_TIME_4096ms 0x0C
148 #define COLOR6_CREG1_TIME_8192ms 0x0D
149 #define COLOR6_CREG1_TIME_16384ms 0x0E
150 
156 #define COLOR6_CREG2_EN_TM_DISABLE 0x00
157 #define COLOR6_CREG2_EN_TM_ENABLE 0x40
158 #define COLOR6_CREG2_DIGITAL_DIVIDER_DISABLE 0x00
159 #define COLOR6_CREG2_DIGITAL_DIVIDER_ENABLE 0x08
160 #define COLOR6_CREG2_DIVIDER_2 0x00
161 #define COLOR6_CREG2_DIVIDER_4 0x01
162 #define COLOR6_CREG2_DIVIDER_8 0x02
163 #define COLOR6_CREG2_DIVIDER_16 0x03
164 #define COLOR6_CREG2_DIVIDER_32 0x04
165 #define COLOR6_CREG2_DIVIDER_64 0x05
166 #define COLOR6_CREG2_DIVIDER_128 0x06
167 #define COLOR6_CREG2_DIVIDER_256 0x07
168 
174 #define COLOR6_CREG3_MMODE_CONT_MODE 0x00
175 #define COLOR6_CREG3_MMODE_CMD_MODE 0x40
176 #define COLOR6_CREG3_MMODE_SYNS_MODE 0x80
177 #define COLOR6_CREG3_MMODE_SIND_MODE 0xC0
178 #define COLOR6_CREG3_SB_STANDBY_SWITCHED_OFF 0x00
179 #define COLOR6_CREG3_SB_STANDBY_SWITCHED_ON 0x10
180 #define COLOR6_CREG3_READY_PUSH_PULL_OUT 0x00
181 #define COLOR6_CREG3_READY_OPEN_DRAIN_OUT 0x08
182 #define COLOR6_CREG3_INTERNAL_CLOCK_1024MHZ 0x00
183 #define COLOR6_CREG3_INTERNAL_CLOCK_2048MHZ 0x01
184 #define COLOR6_CREG3_INTERNAL_CLOCK_4096MHZ 0x02
185 #define COLOR6_CREG3_INTERNAL_CLOCK_8192MHZ 0x03
186 
192 #define COLOR6_MREG_STATUS_REGISTER 0x00
193 #define COLOR6_MREG_TEMPERATURE_MEASUREMENT 0x01
194 #define COLOR6_MREG_MEASUREMENT_X_CHANNEL 0x02
195 #define COLOR6_MREG_MEASUREMENT_Y_CHANNEL 0x03
196 #define COLOR6_MREG_MEASUREMENT_Z_CHANNEL 0x04
197 #define COLOR6_MREG_OUT_CONVERSION_LSB 0x05
198 #define COLOR6_MREG_OUT_CONVERSION_MSB 0x06
199 
205 #define COLOR6_STATUS_OUTCONVOF 0x80
206 #define COLOR6_STATUS_MRESOF 0x40
207 #define COLOR6_STATUS_ADCOF 0x20
208 #define COLOR6_STATUS_LDATA 0x10
209 #define COLOR6_STATUS_NDATA 0x08
210 #define COLOR6_STATUS_NOTREADY 0x04
211 #define COLOR6_STATUS_STANDBY 0x02
212 #define COLOR6_STATUS_POWER 0x01
213 
219 #define COLOR6_X_FSR_OF_GAIN_2048 0.866
220 #define COLOR6_Y_FSR_OF_GAIN_2048 0.932
221 #define COLOR6_Z_FSR_OF_GAIN_2048 0.501
222 #define COLOR6_X_FSR_OF_GAIN_1024 1.732
223 #define COLOR6_Y_FSR_OF_GAIN_1024 1.865
224 #define COLOR6_Z_FSR_OF_GAIN_1024 1.002
225 #define COLOR6_X_FSR_OF_GAIN_512 3.463
226 #define COLOR6_Y_FSR_OF_GAIN_512 3.730
227 #define COLOR6_Z_FSR_OF_GAIN_512 2.003
228 #define COLOR6_X_FSR_OF_GAIN_256 6.927
229 #define COLOR6_Y_FSR_OF_GAIN_256 7.460
230 #define COLOR6_Z_FSR_OF_GAIN_256 4.006
231 #define COLOR6_X_FSR_OF_GAIN_128 13.854
232 #define COLOR6_Y_FSR_OF_GAIN_128 14.919
233 #define COLOR6_Z_FSR_OF_GAIN_128 8.012
234 #define COLOR6_X_FSR_OF_GAIN_64 27.707
235 #define COLOR6_Y_FSR_OF_GAIN_64 29.838
236 #define COLOR6_Z_FSR_OF_GAIN_64 16.024
237 #define COLOR6_X_FSR_OF_GAIN_32 55.414
238 #define COLOR6_Y_FSR_OF_GAIN_32 59.677
239 #define COLOR6_Z_FSR_OF_GAIN_32 32.048
240 #define COLOR6_X_FSR_OF_GAIN_16 110.828
241 #define COLOR6_Y_FSR_OF_GAIN_16 119.354
242 #define COLOR6_Z_FSR_OF_GAIN_16 64.097
243 #define COLOR6_X_FSR_OF_GAIN_8 221.657
244 #define COLOR6_Y_FSR_OF_GAIN_8 238.707
245 #define COLOR6_Z_FSR_OF_GAIN_8 128.194
246 #define COLOR6_X_FSR_OF_GAIN_4 443.314
247 #define COLOR6_Y_FSR_OF_GAIN_4 477.415
248 #define COLOR6_Z_FSR_OF_GAIN_4 256.387
249 #define COLOR6_X_FSR_OF_GAIN_2 886.628
250 #define COLOR6_Y_FSR_OF_GAIN_2 954.830
251 #define COLOR6_Z_FSR_OF_GAIN_2 512.774
252 #define COLOR6_X_FSR_OF_GAIN_1 1773.255
253 #define COLOR6_Y_FSR_OF_GAIN_1 1909.659
254 #define COLOR6_Z_FSR_OF_GAIN_1 1025.548
255 
261 #define COLOR6_NUMBER_OF_CLK_TIME_1ms 1024
262 #define COLOR6_NUMBER_OF_CLK_TIME_2ms 2048
263 #define COLOR6_NUMBER_OF_CLK_TIME_4ms 4096
264 #define COLOR6_NUMBER_OF_CLK_TIME_8ms 8192
265 #define COLOR6_NUMBER_OF_CLK_TIME_16ms 16384
266 #define COLOR6_NUMBER_OF_CLK_TIME_32ms 32768
267 #define COLOR6_NUMBER_OF_CLK_TIME_64ms 65536
268 #define COLOR6_NUMBER_OF_CLK_TIME_128ms 131072
269 #define COLOR6_NUMBER_OF_CLK_TIME_256ms 262144
270 #define COLOR6_NUMBER_OF_CLK_TIME_512ms 524288
271 #define COLOR6_NUMBER_OF_CLK_TIME_1024ms 1048576
272 #define COLOR6_NUMBER_OF_CLK_TIME_2048ms 2097152
273 #define COLOR6_NUMBER_OF_CLK_TIME_4096ms 4194304
274 #define COLOR6_NUMBER_OF_CLK_TIME_8192ms 8388608
275 #define COLOR6_NUMBER_OF_CLK_TIME_16384ms 16777216
276  // End group macro
280 // --------------------------------------------------------------- PUBLIC TYPES
289 typedef struct
290 {
291  // Modules
292 
293  i2c_master_t i2c;
294 
295  // ctx variable
296 
297  uint8_t slave_address;
298 
299  uint8_t set_gain;
300  uint8_t set_time;
301  float fsr;
302  uint32_t num_of_clk;
303 
304 
305 } color6_t;
306 
310 typedef struct
311 {
312  // Communication gpio pins
313 
314  pin_name_t scl;
315  pin_name_t sda;
316 
317  // static variable
318 
319  uint32_t i2c_speed;
320  uint8_t i2c_address;
321 
322 } color6_cfg_t;
323  // End types group
325 
326 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
327 
333 #ifdef __cplusplus
334 extern "C"{
335 #endif
336 
346 
355 
364 
375 void color6_generic_write ( color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
376 
387 void color6_generic_read ( color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
388 
398 void color6_write_byte ( color6_t *ctx, uint8_t reg, uint8_t r_data );
399 
408 uint8_t color6_read_byte ( color6_t *ctx, uint8_t reg );
409 
418 uint16_t color6_read_data ( color6_t *ctx, uint8_t reg );
419 
428 
437 
446 
456 float color6_converting_to_ee ( color6_t *ctx, uint8_t channel, uint16_t mres_data );
457 #ifdef __cplusplus
458 }
459 #endif
460 #endif // _COLOR6_H_
461  // End public_function group
464 
465 // ------------------------------------------------------------------------- END
COLOR6_RETVAL
#define COLOR6_RETVAL
Definition: color6.h:72
color6_cfg_t
Click configuration structure definition.
Definition: color6.h:311
color6_t::fsr
float fsr
Definition: color6.h:301
color6_t::set_time
uint8_t set_time
Definition: color6.h:300
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:315
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:319
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:314
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:320
color6_t
Click ctx object definition.
Definition: color6.h:290
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:299
color6_t::i2c
i2c_master_t i2c
Definition: color6.h:293
color6_t::num_of_clk
uint32_t num_of_clk
Definition: color6.h:302
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:297
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.