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 )
77#define SPECTRAL_OK 0x00
78#define SPECTRAL_ERROR 0xFF
85#define DRV_RX_BUFFER_SIZE 200
86#define DRV_TX_BUFFER_SIZE 100
89 // End group macro
90// --------------------------------------------------------------- PUBLIC TYPES
98typedef 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
117typedef 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
136 // End types group
137// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138
144#ifdef __cplusplus
145extern "C"{
146#endif
147
157
167
174
182void spectral_uart_write ( spectral_t *ctx, uint8_t *data_buf, uint16_t len );
183
192int32_t spectral_uart_read ( spectral_t *ctx, uint8_t *data_buf, uint16_t max_len );
193
199void spectral_send_command ( spectral_t *ctx, uint8_t *command );
200
208void spectral_get_color_data ( uint8_t *rsp, uint8_t *xyz_data );
209
216void spectral_get_xyz_data ( uint8_t *rsp, uint8_t *xyzr_data );
217
224void spectral_get_xy_small_data ( uint8_t *rsp, uint8_t *xy_data );
225
233uint8_t spectral_get_lux_data ( uint8_t *rsp );
234
242uint8_t spectral_get_cct_data ( uint8_t *rsp );
243
250void spectral_get_uv_data ( uint8_t *rsp, uint16_t *uv_data);
251
258void spectral_get_data ( uint8_t *rsp, uint16_t *c_data );
259
267uint8_t spectral_get_duv_data ( uint8_t *rsp );
268
269#ifdef __cplusplus
270}
271#endif
272#endif // _SPECTRAL_H_
273
274 // End public_function group
276
277// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition spectral.h:85
#define DRV_TX_BUFFER_SIZE
Definition spectral.h:86
void spectral_cfg_setup(spectral_cfg_t *cfg)
Config Object Initialization function.
int32_t spectral_uart_read(spectral_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
void spectral_uart_write(spectral_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
uint8_t spectral_get_cct_data(uint8_t *rsp)
Read the calibrated CCT value from the sensor.
void spectral_get_xyz_data(uint8_t *rsp, uint8_t *xyzr_data)
Read raw X, Y, and Z data.
uint8_t spectral_get_duv_data(uint8_t *rsp)
Read calibrated Duv for CIE 1976-color gamut.
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.
void spectral_module_reset(spectral_t *ctx)
Reset module.
uint8_t spectral_get_lux_data(uint8_t *rsp)
Read the calibrated LUX value from the sensor.
void spectral_send_command(spectral_t *ctx, uint8_t *command)
Send Command.
void spectral_get_color_data(uint8_t *rsp, uint8_t *xyz_data)
Read calibrated X, Y, and Z color data.
void spectral_get_xy_small_data(uint8_t *rsp, uint8_t *xy_data)
Read calibrated x and y for CIE 1931 color gamut.
void spectral_get_uv_data(uint8_t *rsp, uint16_t *uv_data)
Read calibrated u�, v� and u, v for CIE 1976 color gamut.
err_t spectral_init(spectral_t *ctx, spectral_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition spectral.h:118
uint32_t baud_rate
Definition spectral.h:128
bool uart_blocking
Definition spectral.h:129
uart_data_bits_t data_bit
Definition spectral.h:130
pin_name_t tx_pin
Definition spectral.h:121
pin_name_t rx_pin
Definition spectral.h:120
uart_stop_bits_t stop_bit
Definition spectral.h:132
pin_name_t int_pin
Definition spectral.h:125
uart_parity_t parity_bit
Definition spectral.h:131
pin_name_t rst
Definition spectral.h:124
Click ctx object definition.
Definition spectral.h:99
uart_t uart
Definition spectral.h:107
digital_in_t int_pin
Definition spectral.h:104
digital_out_t rst
Definition spectral.h:101