spectral2  2.0.0.0
spectral2.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 SPECTRAL2_H
36 #define SPECTRAL2_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 // -------------------------------------------------------------- PUBLIC MACROS
62 #define SPECTRAL2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define SPECTRAL2_RETVAL uint8_t
74 
75 #define SPECTRAL2_OK 0x00
76 #define SPECTRAL2_INIT_ERROR 0xFF
77 
84 #define SPECTRAL2_SOFT_RESET 0x01 << 6
85 #define SPECTRAL2_NORMAL_OPERATION 0x00 << 6
86 #define SPECTRAL2_INT_ENABLE 0x01 << 5
87 #define SPECTRAL2_INT_DISABLE 0x00 << 5
88 #define SPECTRAL2_GAIN_1X 0x00 << 4
89 #define SPECTRAL2_GAIN_3_7X 0x01 << 4
90 #define SPECTRAL2_GAIN_16X 0x02 << 4
91 #define SPECTRAL2_GAIN_64X 0x03 << 4
92 #define SPECTRAL2_MODE_0 0x00 << 2
93 #define SPECTRAL2_MODE_1 0x01 << 2
94 #define SPECTRAL2_MODE_2 0x02 << 2
95 #define SPECTRAL2_MODE_3 0x03 << 2
96 
103 #define SPECTRAL2_LED_DRV_CURRENT_12_5mA 0x00 << 4
104 #define SPECTRAL2_LED_DRV_CURRENT_25mA 0x01 << 4
105 #define SPECTRAL2_LED_DRV_CURRENT_50mA 0x02 << 4
106 #define SPECTRAL2_LED_DRV_CURRENT_100mA 0x03 << 4
107 #define SPECTRAL2_LED_DRV_ENABLE 0x01 << 2
108 #define SPECTRAL2_LED_DRV_DISABLE 0x00 << 2
109 #define SPECTRAL2_LED_IND_CURRENT_1mA 0x00 << 1
110 #define SPECTRAL2_LED_IND_CURRENT_2mA 0x01 << 1
111 #define SPECTRAL2_LED_IND_CURRENT_4mA 0x02 << 1
112 #define SPECTRAL2_LED_IND_CURRENT_8mA 0x03 << 1
113 #define SPECTRAL2_LED_IND_ENABLE 0x01
114 #define SPECTRAL2_LED_IND_DISABLE 0x00
115 
121 #define SPECTRAL2_CALIBRATED_DATA_V 0x14
122 #define SPECTRAL2_CALIBRATED_DATA_B 0x18
123 #define SPECTRAL2_CALIBRATED_DATA_G 0x1C
124 #define SPECTRAL2_CALIBRATED_DATA_Y 0x20
125 #define SPECTRAL2_CALIBRATED_DATA_O 0x24
126 #define SPECTRAL2_CALIBRATED_DATA_R 0x28
127 
129 // Sensor Data
134 #define SPECTRAL2_DATA_V 0x08
135 #define SPECTRAL2_DATA_B 0x0A
136 #define SPECTRAL2_DATA_G 0x0C
137 #define SPECTRAL2_DATA_Y 0x0E
138 #define SPECTRAL2_DATA_O 0x10
139 #define SPECTRAL2_DATA_R 0x12
140  // End group macro
143 // --------------------------------------------------------------- PUBLIC TYPES
152 typedef struct
153 {
154  // Output pins
155 
156  digital_out_t rst;
157 
158  // Input pins
159 
160  digital_in_t int_pin;
161 
162  // Modules
163 
164  i2c_master_t i2c;
165 
166  // ctx variable
167 
168  uint8_t slave_address;
169 
170 } spectral2_t;
171 
175 typedef struct
176 {
177  // Communication gpio pins
178 
179  pin_name_t scl;
180  pin_name_t sda;
181 
182  // Additional gpio pins
183 
184  pin_name_t rst;
185  pin_name_t int_pin;
186 
187  // static variable
188 
189  uint32_t i2c_speed;
190  uint8_t i2c_address;
191 
193  // End types group
195 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
196 
202 #ifdef __cplusplus
203 extern "C"{
204 #endif
205 
215 
225 
254 
264 void spectral2_generic_write ( spectral2_t *ctx, uint8_t reg, uint8_t data_buf );
265 
275 uint8_t spectral2_generic_read ( spectral2_t *ctx, uint8_t reg );
276 
285 
296 void spectral2_set_integration_time ( spectral2_t *ctx, uint8_t cur_time );
297 
308 
325 void spectral2_led_control ( spectral2_t *ctx, uint8_t led_data );
326 
337 int16_t spectral2_get_data ( spectral2_t *ctx, uint8_t data_reg );
338 
349 int32_t spectral2_get_calibrated_data ( spectral2_t *ctx, uint8_t data_reg );
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 #endif // SPECTRAL2_H
355  // End public_function group
358 
359 // ------------------------------------------------------------------------ END
spectral2_cfg_t
Click configuration structure definition.
Definition: spectral2.h:176
spectral2_set_integration_time
void spectral2_set_integration_time(spectral2_t *ctx, uint8_t cur_time)
Integration time function.
spectral2_generic_read
uint8_t spectral2_generic_read(spectral2_t *ctx, uint8_t reg)
Generic read function.
spectral2_cfg_setup
void spectral2_cfg_setup(spectral2_cfg_t *cfg)
Config Object Initialization function.
spectral2_led_control
void spectral2_led_control(spectral2_t *ctx, uint8_t led_data)
Led ctrl and setting function.
spectral2_t::rst
digital_out_t rst
Definition: spectral2.h:156
spectral2_reset
void spectral2_reset(spectral2_t *ctx)
Reset function.
spectral2_cfg_t::rst
pin_name_t rst
Definition: spectral2.h:184
spectral2_t::slave_address
uint8_t slave_address
Definition: spectral2.h:168
spectral2_default_cfg
void spectral2_default_cfg(spectral2_t *ctx)
Click Default Configuration function.
spectral2_cfg_t::scl
pin_name_t scl
Definition: spectral2.h:179
spectral2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: spectral2.h:189
spectral2_cfg_t::int_pin
pin_name_t int_pin
Definition: spectral2.h:185
spectral2_t::int_pin
digital_in_t int_pin
Definition: spectral2.h:160
spectral2_t
Click ctx object definition.
Definition: spectral2.h:153
spectral2_cfg_t::sda
pin_name_t sda
Definition: spectral2.h:180
spectral2_init
SPECTRAL2_RETVAL spectral2_init(spectral2_t *ctx, spectral2_cfg_t *cfg)
Initialization function.
spectral2_get_calibrated_data
int32_t spectral2_get_calibrated_data(spectral2_t *ctx, uint8_t data_reg)
Reads calibrated data function.
spectral2_generic_write
void spectral2_generic_write(spectral2_t *ctx, uint8_t reg, uint8_t data_buf)
Generic write function.
spectral2_get_data
int16_t spectral2_get_data(spectral2_t *ctx, uint8_t data_reg)
Read data function.
spectral2_get_temperature
uint8_t spectral2_get_temperature(spectral2_t *ctx)
Read temperature function.
spectral2_cfg_t::i2c_address
uint8_t i2c_address
Definition: spectral2.h:190
SPECTRAL2_RETVAL
#define SPECTRAL2_RETVAL
Definition: spectral2.h:73
spectral2_t::i2c
i2c_master_t i2c
Definition: spectral2.h:164