28#ifndef SPECTROMETER2_H
29#define SPECTROMETER2_H
39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
73#define SPECTROMETER2_REG_DEVICE_ID 0x00
74#define SPECTROMETER2_REG_REVISION_ID 0x01
75#define SPECTROMETER2_REG_INTERRUPT_CTRL 0x02
76#define SPECTROMETER2_REG_ALS_CTRL 0x03
77#define SPECTROMETER2_REG_ALS_PERIOD 0x04
78#define SPECTROMETER2_REG_ALS_CH1_DATA_H 0x06
79#define SPECTROMETER2_REG_ALS_CH1_DATA_M 0x07
80#define SPECTROMETER2_REG_ALS_CH1_DATA_L 0x08
81#define SPECTROMETER2_REG_ALS_CH2_DATA_H 0x0A
82#define SPECTROMETER2_REG_ALS_CH2_DATA_M 0x0B
83#define SPECTROMETER2_REG_ALS_CH2_DATA_L 0x0C
84#define SPECTROMETER2_REG_ALS_CH3_DATA_H 0x0E
85#define SPECTROMETER2_REG_ALS_CH3_DATA_M 0x0F
86#define SPECTROMETER2_REG_ALS_CH3_DATA_L 0x10
87#define SPECTROMETER2_REG_ALS_CH4_DATA_H 0x12
88#define SPECTROMETER2_REG_ALS_CH4_DATA_M 0x13
89#define SPECTROMETER2_REG_ALS_CH4_DATA_L 0x14
90#define SPECTROMETER2_REG_ALS_CH5_DATA_H 0x16
91#define SPECTROMETER2_REG_ALS_CH5_DATA_M 0x17
92#define SPECTROMETER2_REG_ALS_CH5_DATA_L 0x18
93#define SPECTROMETER2_REG_ALS_CH6_DATA_H 0x1A
94#define SPECTROMETER2_REG_ALS_CH6_DATA_M 0x1B
95#define SPECTROMETER2_REG_ALS_CH6_DATA_L 0x1C
96#define SPECTROMETER2_REG_ALS_EXPOSURE_M 0x1D
97#define SPECTROMETER2_REG_ALS_EXPOSURE_L 0x1E
98#define SPECTROMETER2_REG_ALS_GAIN_CH1 0x25
99#define SPECTROMETER2_REG_ALS_GAIN_CH2 0x26
100#define SPECTROMETER2_REG_ALS_GAIN_CH3 0x27
101#define SPECTROMETER2_REG_ALS_GAIN_CH4 0x28
102#define SPECTROMETER2_REG_ALS_GAIN_CH5 0x29
103#define SPECTROMETER2_REG_ALS_GAIN_CH6 0x2A
104#define SPECTROMETER2_REG_CHANNEL6_ENABLE 0x2D
105#define SPECTROMETER2_REG_ALS_CHANNEL_ENABLE 0x2E
106#define SPECTROMETER2_REG_AC_MODE_CTRL 0x31
107#define SPECTROMETER2_REG_PEDESTAL_VALUE 0x32
108#define SPECTROMETER2_REG_SDA_DRV_CFG 0x3C
109#define SPECTROMETER2_REG_GPIO1_DRV_CFG 0x41
127#define SPECTROMETER2_INTR_STATUS 0x02
128#define SPECTROMETER2_CLR_INTR_SET 0x01
129#define SPECTROMETER2_CLR_INTR_CLEAR 0x00
135#define SPECTROMETER2_EXPOSURE_TIME_MS_MAX 1638.4
136#define SPECTROMETER2_EXPOSURE_TIME_MS_DEFAULT 160.0
137#define SPECTROMETER2_EXPOSURE_TIME_MS_MIN 1.6
138#define SPECTROMETER2_EXPOSURE_TIME_MS_LSB 1.6
139#define SPECTROMETER2_EXPOSURE_TIME_RES 0x03FF
145#define SPECTROMETER2_IM_PERIOD_MS_MAX 5227.5
146#define SPECTROMETER2_IM_PERIOD_MS_DEFAULT 200.0
147#define SPECTROMETER2_IM_PERIOD_MS_MIN 0.0
148#define SPECTROMETER2_IM_PERIOD_MS_LSB 20.5
149#define SPECTROMETER2_IM_PERIOD_RES 0xFF
155#define SPECTROMETER2_AGAIN_66p6X 0x01
156#define SPECTROMETER2_AGAIN_50X 0x02
157#define SPECTROMETER2_AGAIN_33X 0x03
158#define SPECTROMETER2_AGAIN_25X 0x04
159#define SPECTROMETER2_AGAIN_16X 0x05
160#define SPECTROMETER2_AGAIN_10X 0x06
161#define SPECTROMETER2_AGAIN_7p1X 0x07
162#define SPECTROMETER2_AGAIN_5X 0x08
163#define SPECTROMETER2_AGAIN_3p33X 0x09
164#define SPECTROMETER2_AGAIN_2p5X 0x0A
165#define SPECTROMETER2_AGAIN_1p67X 0x0B
166#define SPECTROMETER2_AGAIN_1p25X 0x0C
167#define SPECTROMETER2_AGAIN_1X 0x0D
168#define SPECTROMETER2_AGAIN_0p83X 0x0E
169#define SPECTROMETER2_AGAIN_0p71X 0x0F
170#define SPECTROMETER2_AGAIN_BIT_MASK 0x0F
176#define SPECTROMETER2_CHANNEL6_DISABLE 0x00
177#define SPECTROMETER2_CHANNEL6_ENABLE 0x01
183#define SPECTROMETER2_NO_CHANNEL_ENABLED 0x00
184#define SPECTROMETER2_CHANNEL1_ENABLE 0x01
185#define SPECTROMETER2_CHANNEL2_ENABLE 0x02
186#define SPECTROMETER2_CHANNEL3_ENABLE 0x04
187#define SPECTROMETER2_CHANNEL4_ENABLE 0x08
188#define SPECTROMETER2_CHANNEL5_ENABLE 0x10
189#define SPECTROMETER2_ALL_CHANNELS_ENABLE 0x1F
195#define SPECTROMETER2_ALS_MODE_SINGLE 0x00
196#define SPECTROMETER2_ALS_MODE_CONTINUOUS 0x06
197#define SPECTROMETER2_ALS_STOP 0x00
198#define SPECTROMETER2_ALS_START 0x01
204#define SPECTROMETER2_UNKNOWN_COLOR 0
205#define SPECTROMETER2_RED_COLOR 1
206#define SPECTROMETER2_YELLOW_COLOR 2
207#define SPECTROMETER2_GREEN_COLOR 3
208#define SPECTROMETER2_CYAN_COLOR 4
209#define SPECTROMETER2_BLUE_COLOR 5
210#define SPECTROMETER2_MAGENTA_COLOR 6
211#define SPECTROMETER2_WHITE_COLOR 7
212#define SPECTROMETER2_BLACK_COLOR 8
218#define SPECTROMETER2_WHITE_COLOR_LIGHTNESS 95
219#define SPECTROMETER2_BLACK_COLOR_LIGHTNESS 5
220#define SPECTROMETER2_YELLOW_COLOR_HUE_ANGLE 30
221#define SPECTROMETER2_GREEN_COLOR_HUE_ANGLE 90
222#define SPECTROMETER2_CYAN_COLOR_HUE_ANGLE 150
223#define SPECTROMETER2_BLUE_COLOR_HUE_ANGLE 210
224#define SPECTROMETER2_MAGENTA_COLOR_HUE_ANGLE 270
225#define SPECTROMETER2_RED_COLOR_HUE_ANGLE 330
231#define SPECTROMETER2_HSL_HUE_RESOLUTION 360
232#define SPECTROMETER2_HSL_SATURATION_RESOLUTION 100
233#define SPECTROMETER2_HSL_LIGHTNESS_RESOLUTION 100
239#define SPECTROMETER2_DEVICE_ID 0x70
246#define SPECTROMETER2_DEVICE_ADDRESS 0x20
264#define SPECTROMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
265 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
266 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
267 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
268 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
uint8_t spectrometer2_get_int_pin(spectrometer2_t *ctx)
Spectrometer 2 get int pin function.
err_t spectrometer2_generic_read(spectrometer2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Spectrometer 2 I2C reading function.
err_t spectrometer2_write_register(spectrometer2_t *ctx, uint8_t reg, uint8_t data_in)
Spectrometer 2 write register function.
err_t spectrometer2_set_inter_measurement_period(spectrometer2_t *ctx, float im_period)
Spectrometer 2 set inter measurement period function.
err_t spectrometer2_default_cfg(spectrometer2_t *ctx)
Spectrometer 2 default configuration function.
err_t spectrometer2_init(spectrometer2_t *ctx, spectrometer2_cfg_t *cfg)
Spectrometer 2 initialization function.
void spectrometer2_cfg_setup(spectrometer2_cfg_t *cfg)
Spectrometer 2 configuration object setup function.
uint8_t spectrometer2_get_an_pin(spectrometer2_t *ctx)
Spectrometer 2 get an pin function.
err_t spectrometer2_check_communication(spectrometer2_t *ctx)
Spectrometer 2 check communication function.
err_t spectrometer2_get_data(spectrometer2_t *ctx, spectrometer2_als_channels_t *als_channels)
Spectrometer 2 get data function.
err_t spectrometer2_set_exposure_time(spectrometer2_t *ctx, float exp_time)
Spectrometer 2 set exposure time function.
uint8_t spectrometer2_get_color(spectrometer2_hsl_t *hsl)
Spectrometer 2 get color function.
void spectrometer2_rgbc_to_hsl(spectrometer2_als_channels_t *rgbc, spectrometer2_hsl_t *hsl)
Spectrometer 2 rgbc to hsl function.
err_t spectrometer2_clear_interrupt(spectrometer2_t *ctx)
Spectrometer 2 clear interrupt function.
err_t spectrometer2_read_register(spectrometer2_t *ctx, uint8_t reg, uint8_t *data_out)
Spectrometer 2 read register function.
err_t spectrometer2_generic_write(spectrometer2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Spectrometer 2 I2C writing function.
spectrometer2_return_value_t
Spectrometer 2 Click return value data.
Definition spectrometer2.h:340
@ SPECTROMETER2_ERROR
Definition spectrometer2.h:342
@ SPECTROMETER2_OK
Definition spectrometer2.h:341
Spectrometer 2 ALS channels data object.
Definition spectrometer2.h:313
uint32_t red
Definition spectrometer2.h:314
uint32_t blue
Definition spectrometer2.h:316
uint32_t clear
Definition spectrometer2.h:319
uint32_t ir
Definition spectrometer2.h:318
uint32_t green
Definition spectrometer2.h:317
uint32_t visible
Definition spectrometer2.h:315
Spectrometer 2 Click configuration object.
Definition spectrometer2.h:296
uint32_t i2c_speed
Definition spectrometer2.h:303
pin_name_t scl
Definition spectrometer2.h:297
pin_name_t int_pin
Definition spectrometer2.h:301
pin_name_t sda
Definition spectrometer2.h:298
pin_name_t an
Definition spectrometer2.h:300
uint8_t i2c_address
Definition spectrometer2.h:304
Spectrometer 2 HSL color data object.
Definition spectrometer2.h:328
float hue
Definition spectrometer2.h:329
float saturation
Definition spectrometer2.h:330
float lightness
Definition spectrometer2.h:331
Spectrometer 2 Click context object.
Definition spectrometer2.h:278
digital_in_t int_pin
Definition spectrometer2.h:281
i2c_master_t i2c
Definition spectrometer2.h:284
digital_in_t an
Definition spectrometer2.h:280
uint8_t slave_address
Definition spectrometer2.h:287