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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define SPECTRAL2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define SPECTRAL2_RETVAL uint8_t
64 
65 #define SPECTRAL2_OK 0x00
66 #define SPECTRAL2_INIT_ERROR 0xFF
67 
74 #define SPECTRAL2_SOFT_RESET 0x01 << 6
75 #define SPECTRAL2_NORMAL_OPERATION 0x00 << 6
76 #define SPECTRAL2_INT_ENABLE 0x01 << 5
77 #define SPECTRAL2_INT_DISABLE 0x00 << 5
78 #define SPECTRAL2_GAIN_1X 0x00 << 4
79 #define SPECTRAL2_GAIN_3_7X 0x01 << 4
80 #define SPECTRAL2_GAIN_16X 0x02 << 4
81 #define SPECTRAL2_GAIN_64X 0x03 << 4
82 #define SPECTRAL2_MODE_0 0x00 << 2
83 #define SPECTRAL2_MODE_1 0x01 << 2
84 #define SPECTRAL2_MODE_2 0x02 << 2
85 #define SPECTRAL2_MODE_3 0x03 << 2
86 
93 #define SPECTRAL2_LED_DRV_CURRENT_12_5mA 0x00 << 4
94 #define SPECTRAL2_LED_DRV_CURRENT_25mA 0x01 << 4
95 #define SPECTRAL2_LED_DRV_CURRENT_50mA 0x02 << 4
96 #define SPECTRAL2_LED_DRV_CURRENT_100mA 0x03 << 4
97 #define SPECTRAL2_LED_DRV_ENABLE 0x01 << 2
98 #define SPECTRAL2_LED_DRV_DISABLE 0x00 << 2
99 #define SPECTRAL2_LED_IND_CURRENT_1mA 0x00 << 1
100 #define SPECTRAL2_LED_IND_CURRENT_2mA 0x01 << 1
101 #define SPECTRAL2_LED_IND_CURRENT_4mA 0x02 << 1
102 #define SPECTRAL2_LED_IND_CURRENT_8mA 0x03 << 1
103 #define SPECTRAL2_LED_IND_ENABLE 0x01
104 #define SPECTRAL2_LED_IND_DISABLE 0x00
105 
111 #define SPECTRAL2_CALIBRATED_DATA_V 0x14
112 #define SPECTRAL2_CALIBRATED_DATA_B 0x18
113 #define SPECTRAL2_CALIBRATED_DATA_G 0x1C
114 #define SPECTRAL2_CALIBRATED_DATA_Y 0x20
115 #define SPECTRAL2_CALIBRATED_DATA_O 0x24
116 #define SPECTRAL2_CALIBRATED_DATA_R 0x28
117 
119 // Sensor Data
124 #define SPECTRAL2_DATA_V 0x08
125 #define SPECTRAL2_DATA_B 0x0A
126 #define SPECTRAL2_DATA_G 0x0C
127 #define SPECTRAL2_DATA_Y 0x0E
128 #define SPECTRAL2_DATA_O 0x10
129 #define SPECTRAL2_DATA_R 0x12
130  // End group macro
133 // --------------------------------------------------------------- PUBLIC TYPES
142 typedef struct
143 {
144  // Output pins
145 
146  digital_out_t rst;
147 
148  // Input pins
149 
150  digital_in_t int_pin;
151 
152  // Modules
153 
154  i2c_master_t i2c;
155 
156  // ctx variable
157 
158  uint8_t slave_address;
159 
160 } spectral2_t;
161 
165 typedef struct
166 {
167  // Communication gpio pins
168 
169  pin_name_t scl;
170  pin_name_t sda;
171 
172  // Additional gpio pins
173 
174  pin_name_t rst;
175  pin_name_t int_pin;
176 
177  // static variable
178 
179  uint32_t i2c_speed;
180  uint8_t i2c_address;
181 
183  // End types group
185 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
186 
192 #ifdef __cplusplus
193 extern "C"{
194 #endif
195 
205 
215 
243 void spectral2_default_cfg ( spectral2_t *ctx );
244 
254 void spectral2_generic_write ( spectral2_t *ctx, uint8_t reg, uint8_t data_buf );
255 
265 uint8_t spectral2_generic_read ( spectral2_t *ctx, uint8_t reg );
266 
274 void spectral2_reset ( spectral2_t *ctx );
275 
286 void spectral2_set_integration_time ( spectral2_t *ctx, uint8_t cur_time );
287 
297 uint8_t spectral2_get_temperature ( spectral2_t *ctx );
298 
315 void spectral2_led_control ( spectral2_t *ctx, uint8_t led_data );
316 
327 int16_t spectral2_get_data ( spectral2_t *ctx, uint8_t data_reg );
328 
339 int32_t spectral2_get_calibrated_data ( spectral2_t *ctx, uint8_t data_reg );
340 
341 #ifdef __cplusplus
342 }
343 #endif
344 #endif // SPECTRAL2_H
345  // End public_function group
348 
349 // ------------------------------------------------------------------------ END
spectral2_cfg_t
Click configuration structure definition.
Definition: spectral2.h:165
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:146
spectral2_reset
void spectral2_reset(spectral2_t *ctx)
Reset function.
spectral2_cfg_t::rst
pin_name_t rst
Definition: spectral2.h:174
spectral2_t::slave_address
uint8_t slave_address
Definition: spectral2.h:158
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:169
spectral2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: spectral2.h:179
spectral2_cfg_t::int_pin
pin_name_t int_pin
Definition: spectral2.h:175
spectral2_t::int_pin
digital_in_t int_pin
Definition: spectral2.h:150
spectral2_t
Click ctx object definition.
Definition: spectral2.h:142
spectral2_cfg_t::sda
pin_name_t sda
Definition: spectral2.h:170
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:180
SPECTRAL2_RETVAL
#define SPECTRAL2_RETVAL
Definition: spectral2.h:63
spectral2_t::i2c
i2c_master_t i2c
Definition: spectral2.h:154