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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define COLOR6_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
76#define COLOR6_RETVAL uint8_t
77
78#define COLOR6_OK 0x00
79#define COLOR6_INIT_ERROR 0xFF
86#define COLOR6_REG_OPERATIONAL_STATE 0x00
87#define COLOR6_REG_API_GENERATION 0x02
88#define COLOR6_REG_CONFIGURATION_REGISTER_1 0x06
89#define COLOR6_REG_CONFIGURATION_REGISTER_2 0x07
90#define COLOR6_REG_CONFIGURATION_REGISTER_3 0x08
91#define COLOR6_REG_BREAK_TIME 0x09
92#define COLOR6_REG_EDGE_COUNT_VALUE 0x0A
93#define COLOR6_REG_OPTIONS_REGISTER 0x0B
100#define COLOR6_OSR_STOP_MEASUREMENT 0x00
101#define COLOR6_OSR_START_MEASUREMENT 0x80
102#define COLOR6_OSR_POWER_DOWN_SWITCHED_OFF 0x00
103#define COLOR6_OSR_POWER_DOWN_SWITCHED_ON 0x40
104#define COLOR6_OSR_SOFTWARE_RESET 0x08
105#define COLOR6_OSR_DOS_CONFIGURATION 0x02
106#define COLOR6_OSR_DOS_MEASUREMENT 0x03
113#define COLOR6_AGEN_DEVICE_ID 0x01
114#define COLOR6_AGEN_MUTATION_NUMBER 0x02
121#define COLOR6_CREG1_GAIN_XYZ_2048 0x00
122#define COLOR6_CREG1_GAIN_XYZ_1024 0x10
123#define COLOR6_CREG1_GAIN_XYZ_512 0x20
124#define COLOR6_CREG1_GAIN_XYZ_256 0x30
125#define COLOR6_CREG1_GAIN_XYZ_128 0x40
126#define COLOR6_CREG1_GAIN_XYZ_64 0x50
127#define COLOR6_CREG1_GAIN_XYZ_32 0x60
128#define COLOR6_CREG1_GAIN_XYZ_16 0x70
129#define COLOR6_CREG1_GAIN_XYZ_8 0x80
130#define COLOR6_CREG1_GAIN_XYZ_4 0x90
131#define COLOR6_CREG1_GAIN_XYZ_2 0xA0
132#define COLOR6_CREG1_GAIN_XYZ_1 0xB0
139#define COLOR6_CREG1_TIME_1ms 0x00
140#define COLOR6_CREG1_TIME_2ms 0x01
141#define COLOR6_CREG1_TIME_4ms 0x02
142#define COLOR6_CREG1_TIME_8ms 0x03
143#define COLOR6_CREG1_TIME_16ms 0x04
144#define COLOR6_CREG1_TIME_32ms 0x05
145#define COLOR6_CREG1_TIME_64ms 0x06
146#define COLOR6_CREG1_TIME_128ms 0x07
147#define COLOR6_CREG1_TIME_256ms 0x08
148#define COLOR6_CREG1_TIME_512ms 0x09
149#define COLOR6_CREG1_TIME_1024ms 0x0A
150#define COLOR6_CREG1_TIME_2048ms 0x0B
151#define COLOR6_CREG1_TIME_4096ms 0x0C
152#define COLOR6_CREG1_TIME_8192ms 0x0D
153#define COLOR6_CREG1_TIME_16384ms 0x0E
160#define COLOR6_CREG2_EN_TM_DISABLE 0x00
161#define COLOR6_CREG2_EN_TM_ENABLE 0x40
162#define COLOR6_CREG2_DIGITAL_DIVIDER_DISABLE 0x00
163#define COLOR6_CREG2_DIGITAL_DIVIDER_ENABLE 0x08
164#define COLOR6_CREG2_DIVIDER_2 0x00
165#define COLOR6_CREG2_DIVIDER_4 0x01
166#define COLOR6_CREG2_DIVIDER_8 0x02
167#define COLOR6_CREG2_DIVIDER_16 0x03
168#define COLOR6_CREG2_DIVIDER_32 0x04
169#define COLOR6_CREG2_DIVIDER_64 0x05
170#define COLOR6_CREG2_DIVIDER_128 0x06
171#define COLOR6_CREG2_DIVIDER_256 0x07
178#define COLOR6_CREG3_MMODE_CONT_MODE 0x00
179#define COLOR6_CREG3_MMODE_CMD_MODE 0x40
180#define COLOR6_CREG3_MMODE_SYNS_MODE 0x80
181#define COLOR6_CREG3_MMODE_SIND_MODE 0xC0
182#define COLOR6_CREG3_SB_STANDBY_SWITCHED_OFF 0x00
183#define COLOR6_CREG3_SB_STANDBY_SWITCHED_ON 0x10
184#define COLOR6_CREG3_READY_PUSH_PULL_OUT 0x00
185#define COLOR6_CREG3_READY_OPEN_DRAIN_OUT 0x08
186#define COLOR6_CREG3_INTERNAL_CLOCK_1024MHZ 0x00
187#define COLOR6_CREG3_INTERNAL_CLOCK_2048MHZ 0x01
188#define COLOR6_CREG3_INTERNAL_CLOCK_4096MHZ 0x02
189#define COLOR6_CREG3_INTERNAL_CLOCK_8192MHZ 0x03
196#define COLOR6_MREG_STATUS_REGISTER 0x00
197#define COLOR6_MREG_TEMPERATURE_MEASUREMENT 0x01
198#define COLOR6_MREG_MEASUREMENT_X_CHANNEL 0x02
199#define COLOR6_MREG_MEASUREMENT_Y_CHANNEL 0x03
200#define COLOR6_MREG_MEASUREMENT_Z_CHANNEL 0x04
201#define COLOR6_MREG_OUT_CONVERSION_LSB 0x05
202#define COLOR6_MREG_OUT_CONVERSION_MSB 0x06
209#define COLOR6_STATUS_OUTCONVOF 0x80
210#define COLOR6_STATUS_MRESOF 0x40
211#define COLOR6_STATUS_ADCOF 0x20
212#define COLOR6_STATUS_LDATA 0x10
213#define COLOR6_STATUS_NDATA 0x08
214#define COLOR6_STATUS_NOTREADY 0x04
215#define COLOR6_STATUS_STANDBY 0x02
216#define COLOR6_STATUS_POWER 0x01
223#define COLOR6_X_FSR_OF_GAIN_2048 0.866
224#define COLOR6_Y_FSR_OF_GAIN_2048 0.932
225#define COLOR6_Z_FSR_OF_GAIN_2048 0.501
226#define COLOR6_X_FSR_OF_GAIN_1024 1.732
227#define COLOR6_Y_FSR_OF_GAIN_1024 1.865
228#define COLOR6_Z_FSR_OF_GAIN_1024 1.002
229#define COLOR6_X_FSR_OF_GAIN_512 3.463
230#define COLOR6_Y_FSR_OF_GAIN_512 3.730
231#define COLOR6_Z_FSR_OF_GAIN_512 2.003
232#define COLOR6_X_FSR_OF_GAIN_256 6.927
233#define COLOR6_Y_FSR_OF_GAIN_256 7.460
234#define COLOR6_Z_FSR_OF_GAIN_256 4.006
235#define COLOR6_X_FSR_OF_GAIN_128 13.854
236#define COLOR6_Y_FSR_OF_GAIN_128 14.919
237#define COLOR6_Z_FSR_OF_GAIN_128 8.012
238#define COLOR6_X_FSR_OF_GAIN_64 27.707
239#define COLOR6_Y_FSR_OF_GAIN_64 29.838
240#define COLOR6_Z_FSR_OF_GAIN_64 16.024
241#define COLOR6_X_FSR_OF_GAIN_32 55.414
242#define COLOR6_Y_FSR_OF_GAIN_32 59.677
243#define COLOR6_Z_FSR_OF_GAIN_32 32.048
244#define COLOR6_X_FSR_OF_GAIN_16 110.828
245#define COLOR6_Y_FSR_OF_GAIN_16 119.354
246#define COLOR6_Z_FSR_OF_GAIN_16 64.097
247#define COLOR6_X_FSR_OF_GAIN_8 221.657
248#define COLOR6_Y_FSR_OF_GAIN_8 238.707
249#define COLOR6_Z_FSR_OF_GAIN_8 128.194
250#define COLOR6_X_FSR_OF_GAIN_4 443.314
251#define COLOR6_Y_FSR_OF_GAIN_4 477.415
252#define COLOR6_Z_FSR_OF_GAIN_4 256.387
253#define COLOR6_X_FSR_OF_GAIN_2 886.628
254#define COLOR6_Y_FSR_OF_GAIN_2 954.830
255#define COLOR6_Z_FSR_OF_GAIN_2 512.774
256#define COLOR6_X_FSR_OF_GAIN_1 1773.255
257#define COLOR6_Y_FSR_OF_GAIN_1 1909.659
258#define COLOR6_Z_FSR_OF_GAIN_1 1025.548
265#define COLOR6_NUMBER_OF_CLK_TIME_1ms 1024
266#define COLOR6_NUMBER_OF_CLK_TIME_2ms 2048
267#define COLOR6_NUMBER_OF_CLK_TIME_4ms 4096
268#define COLOR6_NUMBER_OF_CLK_TIME_8ms 8192
269#define COLOR6_NUMBER_OF_CLK_TIME_16ms 16384
270#define COLOR6_NUMBER_OF_CLK_TIME_32ms 32768
271#define COLOR6_NUMBER_OF_CLK_TIME_64ms 65536
272#define COLOR6_NUMBER_OF_CLK_TIME_128ms 131072
273#define COLOR6_NUMBER_OF_CLK_TIME_256ms 262144
274#define COLOR6_NUMBER_OF_CLK_TIME_512ms 524288
275#define COLOR6_NUMBER_OF_CLK_TIME_1024ms 1048576
276#define COLOR6_NUMBER_OF_CLK_TIME_2048ms 2097152
277#define COLOR6_NUMBER_OF_CLK_TIME_4096ms 4194304
278#define COLOR6_NUMBER_OF_CLK_TIME_8192ms 8388608
279#define COLOR6_NUMBER_OF_CLK_TIME_16384ms 16777216
280
283 // End group macro
284// --------------------------------------------------------------- PUBLIC TYPES
293typedef struct
294{
295 // Modules
296
297 i2c_master_t i2c;
298
299 // ctx variable
300
302
303 uint8_t set_gain;
304 uint8_t set_time;
305 float fsr;
306 uint32_t num_of_clk;
307
308
309} color6_t;
310
314typedef struct
315{
316 // Communication gpio pins
317
318 pin_name_t scl;
319 pin_name_t sda;
320
321 // static variable
322
323 uint32_t i2c_speed;
324 uint8_t i2c_address;
325
327
328 // End types group
329
330// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
331
337#ifdef __cplusplus
338extern "C"{
339#endif
340
350
359
368
379void color6_generic_write ( color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
380
391void color6_generic_read ( color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
392
402void color6_write_byte ( color6_t *ctx, uint8_t reg, uint8_t r_data );
403
412uint8_t color6_read_byte ( color6_t *ctx, uint8_t reg );
413
422uint16_t color6_read_data ( color6_t *ctx, uint8_t reg );
423
432
441
450
460float color6_converting_to_ee ( color6_t *ctx, uint8_t channel, uint16_t mres_data );
461#ifdef __cplusplus
462}
463#endif
464#endif // _COLOR6_H_
465
466 // End public_function group
468
469// ------------------------------------------------------------------------- END
#define COLOR6_RETVAL
Definition color6.h:76
void color6_write_byte(color6_t *ctx, uint8_t reg, uint8_t r_data)
Functions for write one byte in register.
uint8_t color6_read_byte(color6_t *ctx, uint8_t reg)
Functions for read one byte data from register.
void color6_software_reset(color6_t *ctx)
Functions for software reset.
void color6_cfg_setup(color6_cfg_t *cfg)
Config Object Initialization function.
float color6_converting_to_ee(color6_t *ctx, uint8_t channel, uint16_t mres_data)
Functions for go to measurement mode.
float color6_get_temperature(color6_t *ctx)
Functions for read temperature.
void color6_generic_read(color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void color6_go_to_measurement_mode(color6_t *ctx)
Functions for go to measurement mode.
void color6_default_cfg(color6_t *ctx)
Click Default Configuration function.
COLOR6_RETVAL color6_init(color6_t *ctx, color6_cfg_t *cfg)
Initialization function.
void color6_generic_write(color6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t color6_read_data(color6_t *ctx, uint8_t reg)
Functions for read data from register.
Click configuration structure definition.
Definition color6.h:315
uint32_t i2c_speed
Definition color6.h:323
pin_name_t scl
Definition color6.h:318
pin_name_t sda
Definition color6.h:319
uint8_t i2c_address
Definition color6.h:324
Click ctx object definition.
Definition color6.h:294
uint8_t set_time
Definition color6.h:304
i2c_master_t i2c
Definition color6.h:297
float fsr
Definition color6.h:305
uint8_t slave_address
Definition color6.h:301
uint32_t num_of_clk
Definition color6.h:306
uint8_t set_gain
Definition color6.h:303