spectral  2.0.0.0
spectral.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 SPECTRAL_H
36 #define SPECTRAL_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define SPECTRAL_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define SPECTRAL_OK 0x00
64 #define SPECTRAL_ERROR 0xFF
65 
71 #define DRV_RX_BUFFER_SIZE 200
72 #define DRV_TX_BUFFER_SIZE 100
73  // End group macro
76 // --------------------------------------------------------------- PUBLIC TYPES
84 typedef struct
85 {
86  // Output pins
87  digital_out_t rst;
88 
89  // Input pins
90  digital_in_t int_pin;
91 
92  // Modules
93  uart_t uart;
94 
95  uint8_t uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
96  uint8_t uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
97 
98 } spectral_t;
99 
103 typedef struct
104 {
105  // Communication gpio pins
106  pin_name_t rx_pin;
107  pin_name_t tx_pin;
108 
109  // Additional gpio pins
110  pin_name_t rst;
111  pin_name_t int_pin;
112 
113  // static variable
114  uint32_t baud_rate; // Clock speed.
116  uart_data_bits_t data_bit; // Data bits.
117  uart_parity_t parity_bit; // Parity bit.
118  uart_stop_bits_t stop_bit; // Stop bits.
119 
121  // End types group
123 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
124 
130 #ifdef __cplusplus
131 extern "C"{
132 #endif
133 
143 
153 
160 
168 void spectral_uart_write ( spectral_t *ctx, uint8_t *data_buf, uint16_t len );
169 
178 int32_t spectral_uart_read ( spectral_t *ctx, uint8_t *data_buf, uint16_t max_len );
179 
185 void spectral_send_command ( spectral_t *ctx, uint8_t *command );
186 
194 void spectral_get_color_data ( uint8_t *rsp, uint8_t *xyz_data );
195 
202 void spectral_get_xyz_data ( uint8_t *rsp, uint8_t *xyzr_data );
203 
210 void spectral_get_xy_small_data ( uint8_t *rsp, uint8_t *xy_data );
211 
219 uint8_t spectral_get_lux_data ( uint8_t *rsp );
220 
228 uint8_t spectral_get_cct_data ( uint8_t *rsp );
229 
236 void spectral_get_uv_data ( uint8_t *rsp, uint16_t *uv_data);
237 
244 void spectral_get_data ( uint8_t *rsp, uint16_t *c_data );
245 
253 uint8_t spectral_get_duv_data ( uint8_t *rsp );
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 #endif // _SPECTRAL_H_
259  // End public_function group
262 
263 // ------------------------------------------------------------------------- END
spectral_get_duv_data
uint8_t spectral_get_duv_data(uint8_t *rsp)
Read calibrated Duv for CIE 1976-color gamut.
spectral_get_cct_data
uint8_t spectral_get_cct_data(uint8_t *rsp)
Read the calibrated CCT value from the sensor.
spectral_init
err_t spectral_init(spectral_t *ctx, spectral_cfg_t *cfg)
Initialization function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: spectral.h:71
spectral_cfg_setup
void spectral_cfg_setup(spectral_cfg_t *cfg)
Config Object Initialization function.
spectral_get_uv_data
void spectral_get_uv_data(uint8_t *rsp, uint16_t *uv_data)
Read calibrated u�, v� and u, v for CIE 1976 color gamut.
spectral_module_reset
void spectral_module_reset(spectral_t *ctx)
Reset module.
spectral_get_data
void spectral_get_data(uint8_t *rsp, uint16_t *c_data)
Read raw X, Y, Z and NIR data as well as two special internal registers D, & C.
spectral_send_command
void spectral_send_command(spectral_t *ctx, uint8_t *command)
Send Command.
spectral_get_xy_small_data
void spectral_get_xy_small_data(uint8_t *rsp, uint8_t *xy_data)
Read calibrated x and y for CIE 1931 color gamut.
spectral_get_lux_data
uint8_t spectral_get_lux_data(uint8_t *rsp)
Read the calibrated LUX value from the sensor.
spectral_cfg_t::int_pin
pin_name_t int_pin
Definition: spectral.h:111
spectral_cfg_t
Click configuration structure definition.
Definition: spectral.h:104
spectral_t::int_pin
digital_in_t int_pin
Definition: spectral.h:90
spectral_uart_read
int32_t spectral_uart_read(spectral_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
spectral_t::uart
uart_t uart
Definition: spectral.h:93
spectral_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: spectral.h:117
spectral_t
Click ctx object definition.
Definition: spectral.h:85
spectral_get_color_data
void spectral_get_color_data(uint8_t *rsp, uint8_t *xyz_data)
Read calibrated X, Y, and Z color data.
spectral_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: spectral.h:116
spectral_cfg_t::uart_blocking
bool uart_blocking
Definition: spectral.h:115
spectral_cfg_t::baud_rate
uint32_t baud_rate
Definition: spectral.h:114
spectral_get_xyz_data
void spectral_get_xyz_data(uint8_t *rsp, uint8_t *xyzr_data)
Read raw X, Y, and Z data.
spectral_cfg_t::rst
pin_name_t rst
Definition: spectral.h:110
spectral_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: spectral.h:118
spectral_t::rst
digital_out_t rst
Definition: spectral.h:87
spectral_cfg_t::tx_pin
pin_name_t tx_pin
Definition: spectral.h:107
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: spectral.h:72
spectral_cfg_t::rx_pin
pin_name_t rx_pin
Definition: spectral.h:106
spectral_uart_write
void spectral_uart_write(spectral_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.