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 
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 SPECTRAL2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define SPECTRAL2_RETVAL uint8_t
78 
79 #define SPECTRAL2_OK 0x00
80 #define SPECTRAL2_INIT_ERROR 0xFF
81 
88 #define SPECTRAL2_SOFT_RESET 0x01 << 6
89 #define SPECTRAL2_NORMAL_OPERATION 0x00 << 6
90 #define SPECTRAL2_INT_ENABLE 0x01 << 5
91 #define SPECTRAL2_INT_DISABLE 0x00 << 5
92 #define SPECTRAL2_GAIN_1X 0x00 << 4
93 #define SPECTRAL2_GAIN_3_7X 0x01 << 4
94 #define SPECTRAL2_GAIN_16X 0x02 << 4
95 #define SPECTRAL2_GAIN_64X 0x03 << 4
96 #define SPECTRAL2_MODE_0 0x00 << 2
97 #define SPECTRAL2_MODE_1 0x01 << 2
98 #define SPECTRAL2_MODE_2 0x02 << 2
99 #define SPECTRAL2_MODE_3 0x03 << 2
100 
107 #define SPECTRAL2_LED_DRV_CURRENT_12_5mA 0x00 << 4
108 #define SPECTRAL2_LED_DRV_CURRENT_25mA 0x01 << 4
109 #define SPECTRAL2_LED_DRV_CURRENT_50mA 0x02 << 4
110 #define SPECTRAL2_LED_DRV_CURRENT_100mA 0x03 << 4
111 #define SPECTRAL2_LED_DRV_ENABLE 0x01 << 2
112 #define SPECTRAL2_LED_DRV_DISABLE 0x00 << 2
113 #define SPECTRAL2_LED_IND_CURRENT_1mA 0x00 << 1
114 #define SPECTRAL2_LED_IND_CURRENT_2mA 0x01 << 1
115 #define SPECTRAL2_LED_IND_CURRENT_4mA 0x02 << 1
116 #define SPECTRAL2_LED_IND_CURRENT_8mA 0x03 << 1
117 #define SPECTRAL2_LED_IND_ENABLE 0x01
118 #define SPECTRAL2_LED_IND_DISABLE 0x00
119 
125 #define SPECTRAL2_CALIBRATED_DATA_V 0x14
126 #define SPECTRAL2_CALIBRATED_DATA_B 0x18
127 #define SPECTRAL2_CALIBRATED_DATA_G 0x1C
128 #define SPECTRAL2_CALIBRATED_DATA_Y 0x20
129 #define SPECTRAL2_CALIBRATED_DATA_O 0x24
130 #define SPECTRAL2_CALIBRATED_DATA_R 0x28
131 
133 // Sensor Data
138 #define SPECTRAL2_DATA_V 0x08
139 #define SPECTRAL2_DATA_B 0x0A
140 #define SPECTRAL2_DATA_G 0x0C
141 #define SPECTRAL2_DATA_Y 0x0E
142 #define SPECTRAL2_DATA_O 0x10
143 #define SPECTRAL2_DATA_R 0x12
144  // End group macro
147 // --------------------------------------------------------------- PUBLIC TYPES
156 typedef struct
157 {
158  // Output pins
159 
160  digital_out_t rst;
161 
162  // Input pins
163 
164  digital_in_t int_pin;
165 
166  // Modules
167 
168  i2c_master_t i2c;
169 
170  // ctx variable
171 
172  uint8_t slave_address;
173 
174 } spectral2_t;
175 
179 typedef struct
180 {
181  // Communication gpio pins
182 
183  pin_name_t scl;
184  pin_name_t sda;
185 
186  // Additional gpio pins
187 
188  pin_name_t rst;
189  pin_name_t int_pin;
190 
191  // static variable
192 
193  uint32_t i2c_speed;
194  uint8_t i2c_address;
195 
197  // End types group
199 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
200 
206 #ifdef __cplusplus
207 extern "C"{
208 #endif
209 
219 
229 
258 
268 void spectral2_generic_write ( spectral2_t *ctx, uint8_t reg, uint8_t data_buf );
269 
279 uint8_t spectral2_generic_read ( spectral2_t *ctx, uint8_t reg );
280 
289 
300 void spectral2_set_integration_time ( spectral2_t *ctx, uint8_t cur_time );
301 
312 
329 void spectral2_led_control ( spectral2_t *ctx, uint8_t led_data );
330 
341 int16_t spectral2_get_data ( spectral2_t *ctx, uint8_t data_reg );
342 
353 int32_t spectral2_get_calibrated_data ( spectral2_t *ctx, uint8_t data_reg );
354 
355 #ifdef __cplusplus
356 }
357 #endif
358 #endif // SPECTRAL2_H
359  // End public_function group
362 
363 // ------------------------------------------------------------------------ END
spectral2_cfg_t
Click configuration structure definition.
Definition: spectral2.h:180
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:160
spectral2_reset
void spectral2_reset(spectral2_t *ctx)
Reset function.
spectral2_cfg_t::rst
pin_name_t rst
Definition: spectral2.h:188
spectral2_t::slave_address
uint8_t slave_address
Definition: spectral2.h:172
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:183
spectral2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: spectral2.h:193
spectral2_cfg_t::int_pin
pin_name_t int_pin
Definition: spectral2.h:189
spectral2_t::int_pin
digital_in_t int_pin
Definition: spectral2.h:164
spectral2_t
Click ctx object definition.
Definition: spectral2.h:157
spectral2_cfg_t::sda
pin_name_t sda
Definition: spectral2.h:184
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:194
SPECTRAL2_RETVAL
#define SPECTRAL2_RETVAL
Definition: spectral2.h:77
spectral2_t::i2c
i2c_master_t i2c
Definition: spectral2.h:168