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 
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_uart.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define SPECTRAL_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define SPECTRAL_OK 0x00
78 #define SPECTRAL_ERROR 0xFF
79 
85 #define DRV_RX_BUFFER_SIZE 200
86 #define DRV_TX_BUFFER_SIZE 100
87  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
98 typedef struct
99 {
100  // Output pins
101  digital_out_t rst;
102 
103  // Input pins
104  digital_in_t int_pin;
105 
106  // Modules
107  uart_t uart;
108 
109  uint8_t uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
110  uint8_t uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
111 
112 } spectral_t;
113 
117 typedef struct
118 {
119  // Communication gpio pins
120  pin_name_t rx_pin;
121  pin_name_t tx_pin;
122 
123  // Additional gpio pins
124  pin_name_t rst;
125  pin_name_t int_pin;
126 
127  // static variable
128  uint32_t baud_rate; // Clock speed.
130  uart_data_bits_t data_bit; // Data bits.
131  uart_parity_t parity_bit; // Parity bit.
132  uart_stop_bits_t stop_bit; // Stop bits.
133 
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
144 #ifdef __cplusplus
145 extern "C"{
146 #endif
147 
157 
167 
174 
182 void spectral_uart_write ( spectral_t *ctx, uint8_t *data_buf, uint16_t len );
183 
192 int32_t spectral_uart_read ( spectral_t *ctx, uint8_t *data_buf, uint16_t max_len );
193 
199 void spectral_send_command ( spectral_t *ctx, uint8_t *command );
200 
208 void spectral_get_color_data ( uint8_t *rsp, uint8_t *xyz_data );
209 
216 void spectral_get_xyz_data ( uint8_t *rsp, uint8_t *xyzr_data );
217 
224 void spectral_get_xy_small_data ( uint8_t *rsp, uint8_t *xy_data );
225 
233 uint8_t spectral_get_lux_data ( uint8_t *rsp );
234 
242 uint8_t spectral_get_cct_data ( uint8_t *rsp );
243 
250 void spectral_get_uv_data ( uint8_t *rsp, uint16_t *uv_data);
251 
258 void spectral_get_data ( uint8_t *rsp, uint16_t *c_data );
259 
267 uint8_t spectral_get_duv_data ( uint8_t *rsp );
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 #endif // _SPECTRAL_H_
273  // End public_function group
276 
277 // ------------------------------------------------------------------------- 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:85
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:125
spectral_cfg_t
Click configuration structure definition.
Definition: spectral.h:118
spectral_t::int_pin
digital_in_t int_pin
Definition: spectral.h:104
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:107
spectral_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: spectral.h:131
spectral_t
Click ctx object definition.
Definition: spectral.h:99
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:130
spectral_cfg_t::uart_blocking
bool uart_blocking
Definition: spectral.h:129
spectral_cfg_t::baud_rate
uint32_t baud_rate
Definition: spectral.h:128
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:124
spectral_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: spectral.h:132
spectral_t::rst
digital_out_t rst
Definition: spectral.h:101
spectral_cfg_t::tx_pin
pin_name_t tx_pin
Definition: spectral.h:121
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: spectral.h:86
spectral_cfg_t::rx_pin
pin_name_t rx_pin
Definition: spectral.h:120
spectral_uart_write
void spectral_uart_write(spectral_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.