color10  2.0.0.0
color10.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 COLOR10_H
36 #define COLOR10_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 // -------------------------------------------------------------- PUBLIC MACROS
66 #define COLOR10_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
69 
75 #define COLOR10_RETVAL uint8_t
76 
77 #define COLOR10_OK 0x00
78 #define COLOR10_INIT_ERROR 0xFF
79 
81 #define COLOR10_SLAVE_ADDR 0x10
82 
83 #define COLOR10_CMD_REG_CFG 0x00
84 #define COLOR10_CMD_REG_C 0x04
85 #define COLOR10_CMD_REG_R 0x05
86 #define COLOR10_CMD_REG_G 0x06
87 #define COLOR10_CMD_REG_B 0x07
88 #define COLOR10_CMD_REG_IR 0x08
89 #define COLOR10_CMD_REG_ID 0x0C
90 
91 #define COLOR10_DEVICE_ID 0x28
92 
93 #define COLOR10_COLOR_ORANGE 0x11
94 #define COLOR10_COLOR_RED 0x22
95 #define COLOR10_COLOR_PINK 0x33
96 #define COLOR10_COLOR_PURPLE 0x44
97 #define COLOR10_COLOR_BLUE 0x55
98 #define COLOR10_COLOR_CYAN 0x66
99 #define COLOR10_COLOR_GREEN 0x77
100 #define COLOR10_COLOR_YELLOW 0x88
101 #define COLOR10_COLOR_OTHER 0x99
102 
103 #define COLOR10_CFG_HIGH_DYNAMIC_RANGE_1_3 0x0040
104 #define COLOR10_CFG_HIGH_DYNAMIC_RANGE_1 0x0000
105 #define COLOR10_CFG_INTEGRATION_TIME_SETT_50_MS 0x0000
106 #define COLOR10_CFG_INTEGRATION_TIME_SETT_100_MS 0x0010
107 #define COLOR10_CFG_INTEGRATION_TIME_SETT_200_MS 0x0020
108 #define COLOR10_CFG_INTEGRATION_TIME_SETT_400_MS 0x0030
109 #define COLOR10_CFG_AUTO_MODE 0x0000
110 #define COLOR10_CFG_FORCE_MODE 0x0008
111 #define COLOR10_CFG_TRIGGER_NO 0x0000
112 #define COLOR10_CFG_TRIGGER_ONE_TIME 0x0004
113 #define COLOR10_CFG_POWER_ON 0x0000
114 #define COLOR10_CFG_SHUT_DOWN 0x8001
115 #define COLOR10_CFG_POWER_ON_G_C_IR 0x4000
116 #define COLOR10_CFG_GAIN_1_X1 0x0000
117 #define COLOR10_CFG_GAIN_1_X2 0x1000
118 #define COLOR10_CFG_GAIN_1_X4 0x2000
119 #define COLOR10_CFG_GAIN_2_X1_2 0x0C00
120 #define COLOR10_CFG_GAIN_2_X1 0x0000
121 #define COLOR10_CFG_GAIN_2_X2 0x0400
122 #define COLOR10_CFG_GAIN_2_X4 0x0800
123  // End group macro
125 // --------------------------------------------------------------- PUBLIC TYPES
134 typedef struct
135 {
136 
137  // Modules
138 
139  i2c_master_t i2c;
140 
141  // ctx variable
142 
143  uint8_t slave_address;
144 
145 } color10_t;
146 
150 typedef struct
151 {
152  // Communication gpio pins
153 
154  pin_name_t scl;
155  pin_name_t sda;
156 
157  // static variable
158 
159  uint32_t i2c_speed;
160  uint8_t i2c_address;
161 
162 } color10_cfg_t;
163  // End types group
165 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166 
172 #ifdef __cplusplus
173 extern "C"{
174 #endif
175 
185 
195 
206 void color10_generic_write ( color10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
207 
218 uint16_t color10_generic_read ( color10_t *ctx, uint8_t cmd_addr );
219 
228 void color10_config ( color10_t *ctx, uint16_t cfg_data );
229 
239 uint8_t color10_get_id ( color10_t *ctx );
240 
251 float color10_read_color_ratio ( color10_t *ctx, uint8_t color_cmd_reg );
252 
263 
273 uint8_t color10_get_color ( float color_value );
274 
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // _COLOR10_H_
280  // End public_function group
283 
284 // ------------------------------------------------------------------------- END
COLOR10_RETVAL
#define COLOR10_RETVAL
Definition: color10.h:75
color10_config
void color10_config(color10_t *ctx, uint16_t cfg_data)
Configuration function.
color10_cfg_t::i2c_address
uint8_t i2c_address
Definition: color10.h:160
color10_generic_write
void color10_generic_write(color10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
color10_init
COLOR10_RETVAL color10_init(color10_t *ctx, color10_cfg_t *cfg)
Initialization function.
color10_cfg_setup
void color10_cfg_setup(color10_cfg_t *cfg)
Config Object Initialization function.
color10_generic_read
uint16_t color10_generic_read(color10_t *ctx, uint8_t cmd_addr)
Generic read function.
color10_t::slave_address
uint8_t slave_address
Definition: color10.h:143
color10_get_id
uint8_t color10_get_id(color10_t *ctx)
ID retrieval function.
color10_cfg_t::sda
pin_name_t sda
Definition: color10.h:155
color10_get_color
uint8_t color10_get_color(float color_value)
Color retrieval function.
color10_get_color_value
float color10_get_color_value(color10_t *ctx)
Color value function.
color10_t::i2c
i2c_master_t i2c
Definition: color10.h:139
color10_read_color_ratio
float color10_read_color_ratio(color10_t *ctx, uint8_t color_cmd_reg)
Color ratio function.
color10_t
Click ctx object definition.
Definition: color10.h:135
color10_cfg_t
Click configuration structure definition.
Definition: color10.h:151
color10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color10.h:159
color10_cfg_t::scl
pin_name_t scl
Definition: color10.h:154