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 "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_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define SPECTRAL_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define SPECTRAL_OK 0x00
74 #define SPECTRAL_ERROR 0xFF
75 
81 #define DRV_RX_BUFFER_SIZE 200
82 #define DRV_TX_BUFFER_SIZE 100
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96  // Output pins
97  digital_out_t rst;
98 
99  // Input pins
100  digital_in_t int_pin;
101 
102  // Modules
103  uart_t uart;
104 
105  uint8_t uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
106  uint8_t uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
107 
108 } spectral_t;
109 
113 typedef struct
114 {
115  // Communication gpio pins
116  pin_name_t rx_pin;
117  pin_name_t tx_pin;
118 
119  // Additional gpio pins
120  pin_name_t rst;
121  pin_name_t int_pin;
122 
123  // static variable
124  uint32_t baud_rate; // Clock speed.
126  uart_data_bits_t data_bit; // Data bits.
127  uart_parity_t parity_bit; // Parity bit.
128  uart_stop_bits_t stop_bit; // Stop bits.
129 
131  // End types group
133 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
153 
163 
170 
178 void spectral_uart_write ( spectral_t *ctx, uint8_t *data_buf, uint16_t len );
179 
188 int32_t spectral_uart_read ( spectral_t *ctx, uint8_t *data_buf, uint16_t max_len );
189 
195 void spectral_send_command ( spectral_t *ctx, uint8_t *command );
196 
204 void spectral_get_color_data ( uint8_t *rsp, uint8_t *xyz_data );
205 
212 void spectral_get_xyz_data ( uint8_t *rsp, uint8_t *xyzr_data );
213 
220 void spectral_get_xy_small_data ( uint8_t *rsp, uint8_t *xy_data );
221 
229 uint8_t spectral_get_lux_data ( uint8_t *rsp );
230 
238 uint8_t spectral_get_cct_data ( uint8_t *rsp );
239 
246 void spectral_get_uv_data ( uint8_t *rsp, uint16_t *uv_data);
247 
254 void spectral_get_data ( uint8_t *rsp, uint16_t *c_data );
255 
263 uint8_t spectral_get_duv_data ( uint8_t *rsp );
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif // _SPECTRAL_H_
269  // End public_function group
272 
273 // ------------------------------------------------------------------------- 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:81
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:121
spectral_cfg_t
Click configuration structure definition.
Definition: spectral.h:114
spectral_t::int_pin
digital_in_t int_pin
Definition: spectral.h:100
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:103
spectral_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: spectral.h:127
spectral_t
Click ctx object definition.
Definition: spectral.h:95
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:126
spectral_cfg_t::uart_blocking
bool uart_blocking
Definition: spectral.h:125
spectral_cfg_t::baud_rate
uint32_t baud_rate
Definition: spectral.h:124
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:120
spectral_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: spectral.h:128
spectral_t::rst
digital_out_t rst
Definition: spectral.h:97
spectral_cfg_t::tx_pin
pin_name_t tx_pin
Definition: spectral.h:117
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: spectral.h:82
spectral_cfg_t::rx_pin
pin_name_t rx_pin
Definition: spectral.h:116
spectral_uart_write
void spectral_uart_write(spectral_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.